@@ -61,11 +61,11 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
61
61
62
62
mlir::Value getConstAPInt (mlir::Location loc, mlir::Type typ,
63
63
const llvm::APInt &val) {
64
- return create<cir::ConstantOp>(loc, typ, getAttr<cir::IntAttr>(typ, val));
64
+ return create<cir::ConstantOp>(loc, getAttr<cir::IntAttr>(typ, val));
65
65
}
66
66
67
67
cir::ConstantOp getConstant (mlir::Location loc, mlir::TypedAttr attr) {
68
- return create<cir::ConstantOp>(loc, attr. getType (), attr );
68
+ return create<cir::ConstantOp>(loc, attr);
69
69
}
70
70
71
71
cir::ConstantOp getConstantInt (mlir::Location loc, mlir::Type ty,
@@ -83,21 +83,17 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
83
83
return getConstPtrAttr (t, 0 );
84
84
}
85
85
86
- mlir::TypedAttr getZeroAttr (mlir::Type t) {
87
- return cir::ZeroAttr::get (getContext (), t);
88
- }
89
-
90
86
mlir::TypedAttr getZeroInitAttr (mlir::Type ty) {
91
87
if (mlir::isa<cir::IntType>(ty))
92
88
return cir::IntAttr::get (ty, 0 );
93
89
if (cir::isAnyFloatingPointType (ty))
94
90
return cir::FPAttr::getZero (ty);
95
91
if (auto arrTy = mlir::dyn_cast<cir::ArrayType>(ty))
96
- return getZeroAttr (arrTy);
92
+ return cir::ZeroAttr::get (arrTy);
97
93
if (auto ptrTy = mlir::dyn_cast<cir::PointerType>(ty))
98
94
return getConstNullPtrAttr (ptrTy);
99
95
if (auto recordTy = mlir::dyn_cast<cir::RecordType>(ty))
100
- return getZeroAttr (recordTy);
96
+ return cir::ZeroAttr::get (recordTy);
101
97
if (mlir::isa<cir::BoolType>(ty)) {
102
98
return getFalseAttr ();
103
99
}
@@ -361,6 +357,44 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
361
357
return create<cir::CmpOp>(loc, getBoolTy (), kind, lhs, rhs);
362
358
}
363
359
360
+ mlir::Value createShift (mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
361
+ bool isShiftLeft) {
362
+ return create<cir::ShiftOp>(loc, lhs.getType (), lhs, rhs, isShiftLeft);
363
+ }
364
+
365
+ mlir::Value createShift (mlir::Location loc, mlir::Value lhs,
366
+ const llvm::APInt &rhs, bool isShiftLeft) {
367
+ return createShift (loc, lhs, getConstAPInt (loc, lhs.getType (), rhs),
368
+ isShiftLeft);
369
+ }
370
+
371
+ mlir::Value createShift (mlir::Location loc, mlir::Value lhs, unsigned bits,
372
+ bool isShiftLeft) {
373
+ auto width = mlir::dyn_cast<cir::IntType>(lhs.getType ()).getWidth ();
374
+ auto shift = llvm::APInt (width, bits);
375
+ return createShift (loc, lhs, shift, isShiftLeft);
376
+ }
377
+
378
+ mlir::Value createShiftLeft (mlir::Location loc, mlir::Value lhs,
379
+ unsigned bits) {
380
+ return createShift (loc, lhs, bits, true );
381
+ }
382
+
383
+ mlir::Value createShiftRight (mlir::Location loc, mlir::Value lhs,
384
+ unsigned bits) {
385
+ return createShift (loc, lhs, bits, false );
386
+ }
387
+
388
+ mlir::Value createShiftLeft (mlir::Location loc, mlir::Value lhs,
389
+ mlir::Value rhs) {
390
+ return createShift (loc, lhs, rhs, true );
391
+ }
392
+
393
+ mlir::Value createShiftRight (mlir::Location loc, mlir::Value lhs,
394
+ mlir::Value rhs) {
395
+ return createShift (loc, lhs, rhs, false );
396
+ }
397
+
364
398
//
365
399
// Block handling helpers
366
400
// ----------------------
0 commit comments