@@ -61,11 +61,11 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
6161
6262 mlir::Value getConstAPInt (mlir::Location loc, mlir::Type typ,
6363 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));
6565 }
6666
6767 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);
6969 }
7070
7171 cir::ConstantOp getConstantInt (mlir::Location loc, mlir::Type ty,
@@ -83,21 +83,17 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
8383 return getConstPtrAttr (t, 0 );
8484 }
8585
86- mlir::TypedAttr getZeroAttr (mlir::Type t) {
87- return cir::ZeroAttr::get (getContext (), t);
88- }
89-
9086 mlir::TypedAttr getZeroInitAttr (mlir::Type ty) {
9187 if (mlir::isa<cir::IntType>(ty))
9288 return cir::IntAttr::get (ty, 0 );
9389 if (cir::isAnyFloatingPointType (ty))
9490 return cir::FPAttr::getZero (ty);
9591 if (auto arrTy = mlir::dyn_cast<cir::ArrayType>(ty))
96- return getZeroAttr (arrTy);
92+ return cir::ZeroAttr::get (arrTy);
9793 if (auto ptrTy = mlir::dyn_cast<cir::PointerType>(ty))
9894 return getConstNullPtrAttr (ptrTy);
9995 if (auto recordTy = mlir::dyn_cast<cir::RecordType>(ty))
100- return getZeroAttr (recordTy);
96+ return cir::ZeroAttr::get (recordTy);
10197 if (mlir::isa<cir::BoolType>(ty)) {
10298 return getFalseAttr ();
10399 }
@@ -361,6 +357,44 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
361357 return create<cir::CmpOp>(loc, getBoolTy (), kind, lhs, rhs);
362358 }
363359
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+
364398 //
365399 // Block handling helpers
366400 // ----------------------
0 commit comments