https://github.com/xlauko updated https://github.com/llvm/llvm-project/pull/136604
>From 7790612aabf4a310328b16551620edf0704d5453 Mon Sep 17 00:00:00 2001 From: xlauko <xla...@mail.muni.cz> Date: Mon, 21 Apr 2025 21:51:06 +0200 Subject: [PATCH] [CIR] Make ZeroAttr use AttrBuilderWithInferredContext --- clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h | 8 ++------ clang/include/clang/CIR/Dialect/IR/CIRAttrs.td | 7 +++++++ clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h index ee8af62ede0da..b303aa07838ee 100644 --- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h +++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h @@ -83,21 +83,17 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { return getConstPtrAttr(t, 0); } - mlir::TypedAttr getZeroAttr(mlir::Type t) { - return cir::ZeroAttr::get(getContext(), t); - } - mlir::TypedAttr getZeroInitAttr(mlir::Type ty) { if (mlir::isa<cir::IntType>(ty)) return cir::IntAttr::get(ty, 0); if (cir::isAnyFloatingPointType(ty)) return cir::FPAttr::getZero(ty); if (auto arrTy = mlir::dyn_cast<cir::ArrayType>(ty)) - return getZeroAttr(arrTy); + return cir::ZeroAttr::get(arrTy); if (auto ptrTy = mlir::dyn_cast<cir::PointerType>(ty)) return getConstNullPtrAttr(ptrTy); if (auto recordTy = mlir::dyn_cast<cir::RecordType>(ty)) - return getZeroAttr(recordTy); + return cir::ZeroAttr::get(recordTy); if (mlir::isa<cir::BoolType>(ty)) { return getFalseAttr(); } diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td index 25ceded7e8a5b..214db1b1caeeb 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td @@ -71,6 +71,13 @@ def ZeroAttr : CIR_Attr<"Zero", "zero", [TypedAttrInterface]> { }]; let parameters = (ins AttributeSelfTypeParameter<"">:$type); + + let builders = [ + AttrBuilderWithInferredContext<(ins "mlir::Type":$type), [{ + return $_get(type.getContext(), type); + }]> + ]; + let assemblyFormat = [{}]; } diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp index 0caa8961ed0a6..b9a74e90a5960 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp @@ -183,7 +183,7 @@ emitArrayConstant(CIRGenModule &cgm, mlir::Type desiredType, } if (nonzeroLength == 0) - return cir::ZeroAttr::get(builder.getContext(), desiredType); + return cir::ZeroAttr::get(desiredType); const unsigned trailingZeroes = arrayBound - nonzeroLength; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits