[clang] 53927ab - [CIR] Make ZeroAttr use AttrBuilderWithInferredContext (#136604)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 22 00:00:01 PDT 2025
Author: Henrich Lauko
Date: 2025-04-22T08:59:58+02:00
New Revision: 53927ab726e6d0dfb3255498b6d0b130adeafb8c
URL: https://github.com/llvm/llvm-project/commit/53927ab726e6d0dfb3255498b6d0b130adeafb8c
DIFF: https://github.com/llvm/llvm-project/commit/53927ab726e6d0dfb3255498b6d0b130adeafb8c.diff
LOG: [CIR] Make ZeroAttr use AttrBuilderWithInferredContext (#136604)
This mirrors incubator changes from https://github.com/llvm/clangir/pull/1576
Added:
Modified:
clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
Removed:
################################################################################
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;
More information about the cfe-commits
mailing list