Skip to content

[CIR] Make ZeroAttr use AttrBuilderWithInferredContext #136604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [{}];
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading