Skip to content

Commit 53927ab

Browse files
authored
[CIR] Make ZeroAttr use AttrBuilderWithInferredContext (#136604)
This mirrors incubator changes from llvm/clangir#1576
1 parent 784dc16 commit 53927ab

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,17 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
8383
return getConstPtrAttr(t, 0);
8484
}
8585

86-
mlir::TypedAttr getZeroAttr(mlir::Type t) {
87-
return cir::ZeroAttr::get(getContext(), t);
88-
}
89-
9086
mlir::TypedAttr getZeroInitAttr(mlir::Type ty) {
9187
if (mlir::isa<cir::IntType>(ty))
9288
return cir::IntAttr::get(ty, 0);
9389
if (cir::isAnyFloatingPointType(ty))
9490
return cir::FPAttr::getZero(ty);
9591
if (auto arrTy = mlir::dyn_cast<cir::ArrayType>(ty))
96-
return getZeroAttr(arrTy);
92+
return cir::ZeroAttr::get(arrTy);
9793
if (auto ptrTy = mlir::dyn_cast<cir::PointerType>(ty))
9894
return getConstNullPtrAttr(ptrTy);
9995
if (auto recordTy = mlir::dyn_cast<cir::RecordType>(ty))
100-
return getZeroAttr(recordTy);
96+
return cir::ZeroAttr::get(recordTy);
10197
if (mlir::isa<cir::BoolType>(ty)) {
10298
return getFalseAttr();
10399
}

clang/include/clang/CIR/Dialect/IR/CIRAttrs.td

+7
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ def ZeroAttr : CIR_Attr<"Zero", "zero", [TypedAttrInterface]> {
7171
}];
7272

7373
let parameters = (ins AttributeSelfTypeParameter<"">:$type);
74+
75+
let builders = [
76+
AttrBuilderWithInferredContext<(ins "mlir::Type":$type), [{
77+
return $_get(type.getContext(), type);
78+
}]>
79+
];
80+
7481
let assemblyFormat = [{}];
7582
}
7683

clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ emitArrayConstant(CIRGenModule &cgm, mlir::Type desiredType,
183183
}
184184

185185
if (nonzeroLength == 0)
186-
return cir::ZeroAttr::get(builder.getContext(), desiredType);
186+
return cir::ZeroAttr::get(desiredType);
187187

188188
const unsigned trailingZeroes = arrayBound - nonzeroLength;
189189

0 commit comments

Comments
 (0)