[clang] [CIR] Add binary operators (PR #132420)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 21 14:50:36 PDT 2025
================
@@ -143,6 +147,114 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
return createCast(loc, cir::CastKind::bitcast, src, newTy);
}
+ mlir::Value createBinop(mlir::Value lhs, cir::BinOpKind kind,
+ const llvm::APInt &rhs) {
+ return create<cir::BinOp>(lhs.getLoc(), lhs.getType(), kind, lhs,
+ getConstAPInt(lhs.getLoc(), lhs.getType(), rhs));
+ }
+
+ mlir::Value createBinop(mlir::Value lhs, cir::BinOpKind kind,
+ mlir::Value rhs) {
+ return create<cir::BinOp>(lhs.getLoc(), lhs.getType(), kind, lhs, rhs);
+ }
+
+ mlir::Value createBinop(mlir::Location loc, mlir::Value lhs,
+ cir::BinOpKind kind, mlir::Value rhs) {
+ return create<cir::BinOp>(loc, lhs.getType(), kind, lhs, rhs);
+ }
+
+ mlir::Value createLowBitsSet(mlir::Location loc, unsigned size,
+ unsigned bits) {
+ llvm::APInt val = llvm::APInt::getLowBitsSet(size, bits);
+ auto type = cir::IntType::get(getContext(), size, false);
+ return getConstAPInt(loc, type, val);
+ }
+
+ mlir::Value createAnd(mlir::Value lhs, const llvm::APInt &rhs) {
+ mlir::Value val = getConstAPInt(lhs.getLoc(), lhs.getType(), rhs);
+ return createBinop(lhs, cir::BinOpKind::And, val);
+ }
+
+ mlir::Value createAnd(mlir::Value lhs, mlir::Value rhs) {
+ return createBinop(lhs, cir::BinOpKind::And, rhs);
+ }
+
+ mlir::Value createAnd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
+ return createBinop(loc, lhs, cir::BinOpKind::And, rhs);
+ }
+
+ mlir::Value createOr(mlir::Value lhs, const llvm::APInt &rhs) {
+ mlir::Value val = getConstAPInt(lhs.getLoc(), lhs.getType(), rhs);
+ return createBinop(lhs, cir::BinOpKind::Or, val);
+ }
+
+ mlir::Value createOr(mlir::Value lhs, mlir::Value rhs) {
----------------
andykaylor wrote:
Why is there no `createOr` that takes a location argument?
https://github.com/llvm/llvm-project/pull/132420
More information about the cfe-commits
mailing list