Author: Henrich Lauko Date: 2025-04-22T09:15:59+02:00 New Revision: 56f5bcb0350b8af44aa5f65ccf865a464df2cc4a
URL: https://github.com/llvm/llvm-project/commit/56f5bcb0350b8af44aa5f65ccf865a464df2cc4a DIFF: https://github.com/llvm/llvm-project/commit/56f5bcb0350b8af44aa5f65ccf865a464df2cc4a.diff LOG: [CIR] Let ConstantOp builder infer its type automatically (#136606) This mirrors incubator changes from https://github.com/llvm/clangir/pull/1578 Added: Modified: clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h clang/include/clang/CIR/Dialect/IR/CIROps.td clang/lib/CIR/CodeGen/CIRGenBuilder.h clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp Removed: ################################################################################ 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