https://github.com/xlauko updated https://github.com/llvm/llvm-project/pull/136606
>From ac40893c8429a57f11f1be3d60c326ac98de8282 Mon Sep 17 00:00:00 2001 From: xlauko <xla...@mail.muni.cz> Date: Mon, 21 Apr 2025 22:23:40 +0200 Subject: [PATCH] [CIR] Let ConstantOp builder infer its type automatically --- clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h | 4 ++-- clang/include/clang/CIR/Dialect/IR/CIROps.td | 9 --------- clang/lib/CIR/CodeGen/CIRGenBuilder.h | 2 +- clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp | 4 ++-- clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp | 2 +- 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h index b303aa07838ee..0385b4f476c3b 100644 --- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h +++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h @@ -61,11 +61,11 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { mlir::Value getConstAPInt(mlir::Location loc, mlir::Type typ, const llvm::APInt &val) { - return create<cir::ConstantOp>(loc, typ, getAttr<cir::IntAttr>(typ, val)); + return create<cir::ConstantOp>(loc, getAttr<cir::IntAttr>(typ, val)); } cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr) { - return create<cir::ConstantOp>(loc, attr.getType(), attr); + return create<cir::ConstantOp>(loc, attr); } cir::ConstantOp getConstantInt(mlir::Location loc, mlir::Type ty, diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index b526d077a910c..577cb8db41f57 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -288,18 +288,9 @@ def ConstantOp : CIR_Op<"const", ``` }]; - // The constant operation takes an attribute as the only input. let arguments = (ins TypedAttrInterface:$value); - - // The constant operation returns a single value of CIR_AnyType. let results = (outs CIR_AnyType:$res); - let builders = [ - OpBuilder<(ins "cir::BoolAttr":$value), [{ - build($_builder, $_state, value.getType(), value); - }]> - ]; - let assemblyFormat = "attr-dict $value"; let hasVerifier = 1; diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h b/clang/lib/CIR/CodeGen/CIRGenBuilder.h index 4f7ff5128d914..7d9988cc52c5a 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h +++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h @@ -185,7 +185,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { // Creates constant nullptr for pointer type ty. cir::ConstantOp getNullPtr(mlir::Type ty, mlir::Location loc) { assert(!cir::MissingFeatures::targetCodeGenInfoGetNullPointer()); - return create<cir::ConstantOp>(loc, ty, getConstPtrAttr(ty, 0)); + return create<cir::ConstantOp>(loc, getConstPtrAttr(ty, 0)); } mlir::Value createNeg(mlir::Value value) { diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index f1561d1b26fc0..1e69ecae831e9 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -138,7 +138,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { mlir::Value VisitIntegerLiteral(const IntegerLiteral *e) { mlir::Type type = cgf.convertType(e->getType()); return builder.create<cir::ConstantOp>( - cgf.getLoc(e->getExprLoc()), type, + cgf.getLoc(e->getExprLoc()), builder.getAttr<cir::IntAttr>(type, e->getValue())); } @@ -147,7 +147,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { assert(mlir::isa<cir::CIRFPTypeInterface>(type) && "expect floating-point type"); return builder.create<cir::ConstantOp>( - cgf.getLoc(e->getExprLoc()), type, + cgf.getLoc(e->getExprLoc()), builder.getAttr<cir::FPAttr>(type, e->getValue())); } diff --git a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp index fe8a5e7428a81..20b086ffdd850 100644 --- a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp @@ -34,7 +34,7 @@ llvm::SmallVector<MemorySlot> cir::AllocaOp::getPromotableSlots() { Value cir::AllocaOp::getDefaultValue(const MemorySlot &slot, OpBuilder &builder) { - return builder.create<cir::ConstantOp>(getLoc(), slot.elemType, + return builder.create<cir::ConstantOp>(getLoc(), cir::UndefAttr::get(slot.elemType)); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits