-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[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
[CIR] Make ZeroAttr use AttrBuilderWithInferredContext #136604
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@llvm/pr-subscribers-clang Author: Henrich Lauko (xlauko) ChangesThis mirrors incubator changes from llvm/clangir#1576 Full diff: https://github.com/llvm/llvm-project/pull/136604.diff 3 Files Affected:
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;
|
@llvm/pr-subscribers-clangir Author: Henrich Lauko (xlauko) ChangesThis mirrors incubator changes from llvm/clangir#1576 Full diff: https://github.com/llvm/llvm-project/pull/136604.diff 3 Files Affected:
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;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Merge activity
|
6f59c47
to
7790612
Compare
7790612
to
a715e75
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/59/builds/16412 Here is the relevant piece of the build log for the reference
|
This mirrors incubator changes from llvm/clangir#1576
This mirrors incubator changes from llvm/clangir#1576
This mirrors incubator changes from llvm/clangir#1576
This mirrors incubator changes from llvm/clangir#1576