17
17
18
18
#include " mlir/IR/Builders.h"
19
19
#include " mlir/IR/BuiltinTypes.h"
20
+ #include " mlir/IR/Location.h"
20
21
#include " mlir/IR/Types.h"
21
22
22
23
namespace cir {
@@ -147,17 +148,6 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
147
148
return createCast (loc, cir::CastKind::bitcast, src, newTy);
148
149
}
149
150
150
- mlir::Value createBinOp (mlir::Value lhs, cir::BinOpKind kind,
151
- const llvm::APInt &rhs) {
152
- return create<cir::BinOp>(lhs.getLoc (), lhs.getType (), kind, lhs,
153
- getConstAPInt (lhs.getLoc (), lhs.getType (), rhs));
154
- }
155
-
156
- mlir::Value createBinop (mlir::Value lhs, cir::BinOpKind kind,
157
- mlir::Value rhs) {
158
- return create<cir::BinOp>(lhs.getLoc (), lhs.getType (), kind, lhs, rhs);
159
- }
160
-
161
151
mlir::Value createBinop (mlir::Location loc, mlir::Value lhs,
162
152
cir::BinOpKind kind, mlir::Value rhs) {
163
153
return create<cir::BinOp>(loc, lhs.getType (), kind, lhs, rhs);
@@ -166,93 +156,74 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
166
156
mlir::Value createLowBitsSet (mlir::Location loc, unsigned size,
167
157
unsigned bits) {
168
158
llvm::APInt val = llvm::APInt::getLowBitsSet (size, bits);
169
- auto type = cir::IntType::get (getContext (), size, false );
159
+ auto type = cir::IntType::get (getContext (), size, /* isSigned= */ false );
170
160
return getConstAPInt (loc, type, val);
171
161
}
172
162
173
- mlir::Value createAnd (mlir::Value lhs, const llvm::APInt &rhs) {
174
- mlir::Value val = getConstAPInt (lhs.getLoc (), lhs.getType (), rhs);
175
- return createBinop (lhs, cir::BinOpKind::And, val);
176
- }
177
-
178
- mlir::Value createAnd (mlir::Value lhs, mlir::Value rhs) {
179
- return createBinop (lhs, cir::BinOpKind::And, rhs);
180
- }
181
-
182
163
mlir::Value createAnd (mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
183
164
return createBinop (loc, lhs, cir::BinOpKind::And, rhs);
184
165
}
185
166
186
- mlir::Value createOr (mlir::Value lhs, const llvm::APInt &rhs) {
187
- mlir::Value val = getConstAPInt (lhs.getLoc (), lhs.getType (), rhs);
188
- return createBinop (lhs, cir::BinOpKind::Or, val);
189
- }
190
-
191
- mlir::Value createOr (mlir::Value lhs, mlir::Value rhs) {
192
- return createBinop (lhs, cir::BinOpKind::Or, rhs);
167
+ mlir::Value createOr (mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
168
+ return createBinop (loc, lhs, cir::BinOpKind::Or, rhs);
193
169
}
194
170
195
- mlir::Value createMul (mlir::Value lhs, mlir::Value rhs, bool hasNUW = false ,
196
- bool hasNSW = false ) {
197
- auto op = create<cir::BinOp>(lhs.getLoc (), lhs.getType (),
198
- cir::BinOpKind::Mul, lhs, rhs);
199
- if (hasNUW)
200
- op.setNoUnsignedWrap (true );
201
- if (hasNSW)
202
- op.setNoSignedWrap (true );
171
+ mlir::Value createMul (mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
172
+ bool hasNUW = false , bool hasNSW = false ) {
173
+ auto op =
174
+ create<cir::BinOp>(loc, lhs.getType (), cir::BinOpKind::Mul, lhs, rhs);
175
+ op.setNoUnsignedWrap (hasNUW);
176
+ op.setNoSignedWrap (hasNSW);
203
177
return op;
204
178
}
205
- mlir::Value createNSWMul (mlir::Value lhs, mlir::Value rhs) {
206
- return createMul (lhs, rhs, false , true );
207
- }
208
- mlir::Value createNUWAMul (mlir::Value lhs, mlir::Value rhs) {
209
- return createMul (lhs, rhs, true , false );
179
+ mlir::Value createNSWMul (mlir::Location loc, mlir::Value lhs,
180
+ mlir::Value rhs) {
181
+ return createMul (loc, lhs, rhs, false , true );
210
182
}
211
-
212
- mlir::Value createMul (mlir::Value lhs, const llvm::APInt &rhs) {
213
- mlir::Value val = getConstAPInt (lhs.getLoc (), lhs.getType (), rhs);
214
- return createBinop (lhs, cir::BinOpKind::Mul, val);
183
+ mlir::Value createNUWAMul (mlir::Location loc, mlir::Value lhs,
184
+ mlir::Value rhs) {
185
+ return createMul (loc, lhs, rhs, true , false );
215
186
}
216
187
217
- mlir::Value createSub (mlir::Value lhs, mlir::Value rhs, bool hasNUW = false ,
218
- bool hasNSW = false , bool saturated = false ) {
219
- auto op = create<cir::BinOp>(lhs.getLoc (), lhs.getType (),
220
- cir::BinOpKind::Sub, lhs, rhs);
221
- if (hasNUW)
222
- op.setNoUnsignedWrap (true );
223
- if (hasNSW)
224
- op.setNoSignedWrap (true );
225
- if (saturated)
226
- op.setSaturated (true );
188
+ mlir::Value createSub (mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
189
+ bool hasNUW = false , bool hasNSW = false ,
190
+ bool saturated = false ) {
191
+ auto op =
192
+ create<cir::BinOp>(loc, lhs.getType (), cir::BinOpKind::Sub, lhs, rhs);
193
+ op.setNoUnsignedWrap (hasNUW);
194
+ op.setNoSignedWrap (hasNSW);
195
+ op.setSaturated (saturated);
227
196
return op;
228
197
}
229
198
230
- mlir::Value createNSWSub (mlir::Value lhs, mlir::Value rhs) {
231
- return createSub (lhs, rhs, false , true );
199
+ mlir::Value createNSWSub (mlir::Location loc, mlir::Value lhs,
200
+ mlir::Value rhs) {
201
+ return createSub (loc, lhs, rhs, false , true );
232
202
}
233
203
234
- mlir::Value createNUWSub (mlir::Value lhs, mlir::Value rhs) {
235
- return createSub (lhs, rhs, true , false );
204
+ mlir::Value createNUWSub (mlir::Location loc, mlir::Value lhs,
205
+ mlir::Value rhs) {
206
+ return createSub (loc, lhs, rhs, true , false );
236
207
}
237
208
238
- mlir::Value createAdd (mlir::Value lhs, mlir::Value rhs, bool hasNUW = false ,
239
- bool hasNSW = false , bool saturated = false ) {
240
- auto op = create<cir::BinOp>(lhs.getLoc (), lhs.getType (),
241
- cir::BinOpKind::Add, lhs, rhs);
242
- if (hasNUW)
243
- op.setNoUnsignedWrap (true );
244
- if (hasNSW)
245
- op.setNoSignedWrap (true );
246
- if (saturated)
247
- op.setSaturated (true );
209
+ mlir::Value createAdd (mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
210
+ bool hasNUW = false , bool hasNSW = false ,
211
+ bool saturated = false ) {
212
+ auto op =
213
+ create<cir::BinOp>(loc, lhs.getType (), cir::BinOpKind::Add, lhs, rhs);
214
+ op.setNoUnsignedWrap (hasNUW);
215
+ op.setNoSignedWrap (hasNSW);
216
+ op.setSaturated (saturated);
248
217
return op;
249
218
}
250
219
251
- mlir::Value createNSWAdd (mlir::Value lhs, mlir::Value rhs) {
252
- return createAdd (lhs, rhs, false , true );
220
+ mlir::Value createNSWAdd (mlir::Location loc, mlir::Value lhs,
221
+ mlir::Value rhs) {
222
+ return createAdd (loc, lhs, rhs, false , true );
253
223
}
254
- mlir::Value createNUWAdd (mlir::Value lhs, mlir::Value rhs) {
255
- return createAdd (lhs, rhs, true , false );
224
+ mlir::Value createNUWAdd (mlir::Location loc, mlir::Value lhs,
225
+ mlir::Value rhs) {
226
+ return createAdd (loc, lhs, rhs, true , false );
256
227
}
257
228
258
229
//
0 commit comments