Jlm
arithmetic.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011 2012 2014 Nico Reißmann <nico.reissmann@gmail.com>
3  * See COPYING for terms of redistribution.
4  */
5 
6 #ifndef JLM_RVSDG_BITSTRING_ARITHMETIC_HPP
7 #define JLM_RVSDG_BITSTRING_ARITHMETIC_HPP
8 
11 
12 namespace jlm::rvsdg
13 {
14 
15 template<typename reduction, const char * name>
17 {
18 public:
19  ~MakeBitUnaryOperation() noexcept override;
20 
21  explicit MakeBitUnaryOperation(std::size_t nbits) noexcept
23  {}
24 
25  bool
26  operator==(const Operation & other) const noexcept override;
27 
29  reduce_constant(const BitValueRepresentation & arg) const override;
30 
31  std::string
32  debug_string() const override;
33 
34  [[nodiscard]] std::unique_ptr<Operation>
35  copy() const override;
36 
37  std::unique_ptr<BitUnaryOperation>
38  create(size_t nbits) const override;
39 
40  static Output *
41  create(size_t nbits, Output * op)
42  {
43  return CreateOpNode<MakeBitUnaryOperation>({ op }, nbits).output(0);
44  }
45 };
46 
47 template<typename reduction, const char * name, enum BinaryOperation::flags opflags>
49 {
50 public:
51  ~MakeBitBinaryOperation() noexcept override;
52 
53  explicit MakeBitBinaryOperation(std::size_t nbits) noexcept
55  {}
56 
57  bool
58  operator==(const Operation & other) const noexcept override;
59 
61  flags() const noexcept override;
62 
65  const override;
66 
67  std::string
68  debug_string() const override;
69 
70  [[nodiscard]] std::unique_ptr<Operation>
71  copy() const override;
72 
73  std::unique_ptr<BitBinaryOperation>
74  create(size_t nbits) const override;
75 
76  static Output *
77  create(size_t nbits, Output * op1, Output * op2)
78  {
79  return CreateOpNode<MakeBitBinaryOperation>({ op1, op2 }, nbits).output(0);
80  }
81 };
82 
83 struct reduce_neg;
84 extern const char BitNegateLabel[];
87 
88 struct reduce_not;
89 extern const char BitNotLabel[];
92 
93 struct reduce_add;
94 extern const char BitAddLabel[];
96  reduce_add,
99 extern template class MakeBitBinaryOperation<
100  reduce_add,
101  BitAddLabel,
103 
104 struct reduce_and;
105 extern const char BitAndLabel[];
107  reduce_and,
108  BitAndLabel,
110 extern template class MakeBitBinaryOperation<
111  reduce_and,
112  BitAndLabel,
114 
115 struct reduce_ashr;
116 extern const char BitAShrLabel[];
118 extern template class MakeBitBinaryOperation<
119  reduce_ashr,
120  BitAShrLabel,
122 
123 struct reduce_mul;
124 extern const char BitMulLabel[];
126  reduce_mul,
127  BitMulLabel,
129 extern template class MakeBitBinaryOperation<
130  reduce_mul,
131  BitMulLabel,
133 
134 struct reduce_or;
135 extern const char BitOrLabel[];
137  reduce_or,
138  BitOrLabel,
140 extern template class MakeBitBinaryOperation<
141  reduce_or,
142  BitOrLabel,
144 
145 struct reduce_sdiv;
146 extern const char BitSDivLabel[];
148 extern template class MakeBitBinaryOperation<
149  reduce_sdiv,
150  BitSDivLabel,
152 
153 struct reduce_shl;
154 extern const char BitShlLabel[];
157 
158 struct reduce_shr;
159 extern const char BitShrLabel[];
162 
163 struct reduce_smod;
164 extern const char BitSModLabel[];
166 extern template class MakeBitBinaryOperation<
167  reduce_smod,
168  BitSModLabel,
170 
171 struct reduce_smulh;
172 extern const char BitSMulHLabel[];
173 using bitsmulh_op =
175 extern template class MakeBitBinaryOperation<
176  reduce_smulh,
179 
180 struct reduce_sub;
181 extern const char BitSubLabel[];
184 
185 struct reduce_udiv;
186 extern const char BitUDivLabel[];
188 extern template class MakeBitBinaryOperation<
189  reduce_udiv,
190  BitUDivLabel,
192 
193 struct reduce_umod;
194 extern const char BitUModLabel[];
196 extern template class MakeBitBinaryOperation<
197  reduce_umod,
198  BitUModLabel,
200 
201 struct reduce_umulh;
202 extern const char BitUMulHLabel[];
203 using bitumulh_op =
205 extern template class MakeBitBinaryOperation<
206  reduce_umulh,
209 
210 struct reduce_xor;
211 extern const char BitXorLabel[];
213  reduce_xor,
214  BitXorLabel,
216 extern template class MakeBitBinaryOperation<
217  reduce_xor,
218  BitXorLabel,
220 
221 }
222 
223 #endif
BitBinaryOperation(const std::shared_ptr< const BitType > type, size_t arity=2) noexcept
static std::shared_ptr< const BitType > Create(std::size_t nbits)
Creates bit type of specified width.
Definition: type.cpp:45
BitUnaryOperation(const std::shared_ptr< const BitType > &type) noexcept
MakeBitBinaryOperation(std::size_t nbits) noexcept
Definition: arithmetic.hpp:53
std::unique_ptr< Operation > copy() const override
std::string debug_string() const override
bool operator==(const Operation &other) const noexcept override
~MakeBitBinaryOperation() noexcept override
BitValueRepresentation reduce_constants(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const override
enum BinaryOperation::flags flags() const noexcept override
std::unique_ptr< BitBinaryOperation > create(size_t nbits) const override
~MakeBitUnaryOperation() noexcept override
MakeBitUnaryOperation(std::size_t nbits) noexcept
Definition: arithmetic.hpp:21
BitValueRepresentation reduce_constant(const BitValueRepresentation &arg) const override
std::unique_ptr< BitUnaryOperation > create(size_t nbits) const override
bool operator==(const Operation &other) const noexcept override
std::unique_ptr< Operation > copy() const override
std::string debug_string() const override
static Output * create(size_t nbits, Output *op)
Definition: arithmetic.hpp:41
const char BitOrLabel[]
Definition: arithmetic.cpp:111
const char BitNegateLabel[]
Definition: arithmetic.cpp:30
const char BitSMulHLabel[]
Definition: arithmetic.cpp:174
const char BitAndLabel[]
Definition: arithmetic.cpp:69
const char BitShrLabel[]
Definition: arithmetic.cpp:150
const char BitAShrLabel[]
Definition: arithmetic.cpp:84
const char BitSDivLabel[]
Definition: arithmetic.cpp:126
const char BitUDivLabel[]
Definition: arithmetic.cpp:201
const char BitShlLabel[]
Definition: arithmetic.cpp:138
const char BitUModLabel[]
Definition: arithmetic.cpp:213
const char BitNotLabel[]
Definition: arithmetic.cpp:42
const char BitMulLabel[]
Definition: arithmetic.cpp:96
const char BitXorLabel[]
Definition: arithmetic.cpp:240
const char BitUMulHLabel[]
Definition: arithmetic.cpp:225
const char BitSubLabel[]
Definition: arithmetic.cpp:189
const char BitAddLabel[]
Definition: arithmetic.cpp:54
const char BitSModLabel[]
Definition: arithmetic.cpp:162