Jlm
Loading...
Searching...
No Matches
BitManipulationIntrinsicOperations.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2026 Nico Reißmann <nico.reissmann@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
7
8namespace jlm::llvm
9{
10
11FShlOperation::~FShlOperation() noexcept = default;
12
13bool
14FShlOperation::operator==(const Operation & other) const noexcept
15{
16 const auto operation = dynamic_cast<const FShlOperation *>(&other);
17 return operation && *operation->getType() == *getType();
18}
19
20std::string
22{
23 return util::strfmt("FShl[", getType()->debug_string(), "]");
24}
25
26std::unique_ptr<rvsdg::Operation>
28{
29 return std::make_unique<FShlOperation>(*this);
30}
31
32void
33FShlOperation::checkType(const std::shared_ptr<const rvsdg::Type> & type)
34{
35 if (!is<const rvsdg::BitType>(type) && !isVectorOf<const rvsdg::BitType>(*type))
36 {
37 throw std::runtime_error("FShlOperation::checkType: Expected integer type.");
38 }
39}
40
41BSwapOperation::~BSwapOperation() noexcept = default;
42
43bool
44BSwapOperation::operator==(const Operation & other) const noexcept
45{
46 const auto operation = dynamic_cast<const BSwapOperation *>(&other);
47 return operation && *operation->getType() == *getType();
48}
49
50std::string
52{
53 return util::strfmt("BSwap[", getType()->debug_string(), "]");
54}
55
56std::unique_ptr<rvsdg::Operation>
58{
59 return std::make_unique<BSwapOperation>(*this);
60}
61
62void
63BSwapOperation::checkType(const std::shared_ptr<const rvsdg::Type> & type)
64{
65 auto scalarType = type.get();
66 if (const auto vectorType = dynamic_cast<const VectorType *>(scalarType))
67 {
68 scalarType = &vectorType->type();
69 }
70
71 const auto bitType = dynamic_cast<const rvsdg::BitType *>(scalarType);
72 if (!bitType)
73 {
74 throw std::runtime_error("BSwapOperation::checkType: Expected integer type.");
75 }
76
77 if (bitType->nbits() % 16 != 0)
78 {
79 throw std::runtime_error(
80 "BSwapOperation::checkType: Expected integer type with a multiple of 16 bits.");
81 }
82}
83
84CtlzOperation::~CtlzOperation() noexcept = default;
85
86bool
87CtlzOperation::operator==(const Operation & other) const noexcept
88{
89 const auto operation = dynamic_cast<const CtlzOperation *>(&other);
90 return operation && *operation->getType() == *getType();
91}
92
93std::string
95{
96 return util::strfmt("Ctlz[", getType()->debug_string(), "]");
97}
98
99std::unique_ptr<rvsdg::Operation>
101{
102 return std::make_unique<CtlzOperation>(*this);
103}
104
105void
106CtlzOperation::checkType(const std::shared_ptr<const rvsdg::Type> & type)
107{
108 if (!is<const rvsdg::BitType>(type) && !isVectorOf<const rvsdg::BitType>(*type))
109 {
110 throw std::runtime_error("CtlzOperation::checkType: Expected integer type.");
111 }
112}
113
114CttzOperation::~CttzOperation() noexcept = default;
115
116bool
117CttzOperation::operator==(const Operation & other) const noexcept
118{
119 const auto operation = dynamic_cast<const CttzOperation *>(&other);
120 return operation && *operation->getType() == *getType();
121}
122
123std::string
125{
126 return util::strfmt("Cttz[", getType()->debug_string(), "]");
127}
128
129std::unique_ptr<rvsdg::Operation>
131{
132 return std::make_unique<CttzOperation>(*this);
133}
134
135void
136CttzOperation::checkType(const std::shared_ptr<const rvsdg::Type> & type)
137{
138 if (!is<const rvsdg::BitType>(type) && !isVectorOf<const rvsdg::BitType>(*type))
139 {
140 throw std::runtime_error("CttzOperation::checkType: Expected integer type.");
141 }
142}
143
144CtpopOperation::~CtpopOperation() noexcept = default;
145
146bool
147CtpopOperation::operator==(const Operation & other) const noexcept
148{
149 const auto operation = dynamic_cast<const CtpopOperation *>(&other);
150 return operation && *operation->getType() == *getType();
151}
152
153std::string
155{
156 return util::strfmt("Ctpop[", getType()->debug_string(), "]");
157}
158
159std::unique_ptr<rvsdg::Operation>
161{
162 return std::make_unique<CtpopOperation>(*this);
163}
164
165void
166CtpopOperation::checkType(const std::shared_ptr<const rvsdg::Type> & type)
167{
168 if (!is<const rvsdg::BitType>(type) && !isVectorOf<const rvsdg::BitType>(*type))
169 {
170 throw std::runtime_error("CtpopOperation::checkType: Expected integer type.");
171 }
172}
173
174}
std::unique_ptr< Operation > copy() const override
~BSwapOperation() noexcept override
static void checkType(const std::shared_ptr< const rvsdg::Type > &type)
std::shared_ptr< const rvsdg::Type > getType() const noexcept
std::unique_ptr< Operation > copy() const override
static void checkType(const std::shared_ptr< const rvsdg::Type > &type)
~CtlzOperation() noexcept override
std::shared_ptr< const rvsdg::Type > getType() const noexcept
std::shared_ptr< const rvsdg::Type > getType() const noexcept
std::unique_ptr< Operation > copy() const override
~CtpopOperation() noexcept override
static void checkType(const std::shared_ptr< const rvsdg::Type > &type)
std::unique_ptr< Operation > copy() const override
std::shared_ptr< const rvsdg::Type > getType() const noexcept
static void checkType(const std::shared_ptr< const rvsdg::Type > &type)
~CttzOperation() noexcept override
~FShlOperation() noexcept override
std::unique_ptr< Operation > copy() const override
static void checkType(const std::shared_ptr< const rvsdg::Type > &type)
std::shared_ptr< const rvsdg::Type > getType() const noexcept
Global memory state passed between functions.
static std::string strfmt(Args... args)
Definition strfmt.hpp:35