-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[TableGen] Use getValue instead of getInt for enum attributes #144030
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
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-mlir-ods @llvm/pr-subscribers-mlir Author: Mihir Patil (0xMihir) ChangesFixes #144005 Full diff: https://github.com/llvm/llvm-project/pull/144030.diff 4 Files Affected:
diff --git a/mlir/include/mlir/IR/EnumAttr.td b/mlir/include/mlir/IR/EnumAttr.td
index 3f7f747ac20d3..50e4e632109fc 100644
--- a/mlir/include/mlir/IR/EnumAttr.td
+++ b/mlir/include/mlir/IR/EnumAttr.td
@@ -39,8 +39,9 @@ class EnumCase<string sym, int intVal, string strVal, int widthVal> {
class IntEnumAttrCaseBase<I intType, string sym, string strVal, int intVal> :
EnumCase<sym, intVal, strVal, intType.bitwidth>,
SignlessIntegerAttrBase<intType, "case " # strVal> {
- let predicate =
- CPred<"::llvm::cast<::mlir::IntegerAttr>($_self).getInt() == " # intVal>;
+ let predicate = CPred<
+ "::llvm::cast<::mlir::IntegerAttr>($_self).getValue().eq(APInt("#intType
+ .bitwidth#", "#intVal#"))">;
}
// Cases of integer enums with a specific type. By default, the string
diff --git a/mlir/test/IR/attribute.mlir b/mlir/test/IR/attribute.mlir
index 4f280bde1aecc..edb7357e4e04b 100644
--- a/mlir/test/IR/attribute.mlir
+++ b/mlir/test/IR/attribute.mlir
@@ -454,6 +454,10 @@ func.func @allowed_cases_pass() {
%0 = "test.i32_enum_attr"() {attr = 5: i32} : () -> i32
// CHECK: test.i32_enum_attr
%1 = "test.i32_enum_attr"() {attr = 10: i32} : () -> i32
+ // CHECK: test.i32_enum_attr
+ %2 = "test.i32_enum_attr"() {attr = 2147483648: i32} : () -> i32
+ // CHECK: test.i32_enum_attr
+ %3 = "test.i32_enum_attr"() {attr = 4294967295: i32} : () -> i32
return
}
diff --git a/mlir/test/lib/Dialect/Test/TestEnumDefs.td b/mlir/test/lib/Dialect/Test/TestEnumDefs.td
index 5b785a600aad2..10e424a0f2523 100644
--- a/mlir/test/lib/Dialect/Test/TestEnumDefs.td
+++ b/mlir/test/lib/Dialect/Test/TestEnumDefs.td
@@ -17,9 +17,13 @@ include "mlir/IR/EnumAttr.td"
def I32Case5: I32EnumAttrCase<"case5", 5>;
def I32Case10: I32EnumAttrCase<"case10", 10>;
+def I32CaseSignedMaxPlusOne
+ : I32EnumAttrCase<"caseSignedMaxPlusOne", 2147483648>;
+def I32CaseUnsignedMax : I32EnumAttrCase<"caseUnsignedMax", 4294967295>;
-def SomeI32Enum: I32EnumAttr<
- "SomeI32Enum", "", [I32Case5, I32Case10]>;
+def SomeI32Enum : I32EnumAttr<"SomeI32Enum", "",
+ [I32Case5, I32Case10, I32CaseSignedMaxPlusOne,
+ I32CaseUnsignedMax]>;
def I64Case5: I64EnumAttrCase<"case5", 5>;
def I64Case10: I64EnumAttrCase<"case10", 10>;
diff --git a/mlir/tools/mlir-tblgen/EnumsGen.cpp b/mlir/tools/mlir-tblgen/EnumsGen.cpp
index 9941a203bc5cb..06dc588f90203 100644
--- a/mlir/tools/mlir-tblgen/EnumsGen.cpp
+++ b/mlir/tools/mlir-tblgen/EnumsGen.cpp
@@ -648,8 +648,10 @@ static void emitSpecializedAttrDef(const Record &enumDef, raw_ostream &os) {
os << formatv("{0} {1}::getValue() const {{\n", enumName, attrClassName);
- os << formatv(" return static_cast<{0}>(::mlir::IntegerAttr::getInt());\n",
- enumName);
+ os << formatv(
+ " return "
+ "static_cast<{0}>(::mlir::IntegerAttr::getValue().getZExtValue());\n",
+ enumName);
os << "}\n";
}
|
@llvm/pr-subscribers-mlir-core Author: Mihir Patil (0xMihir) ChangesFixes #144005 Full diff: https://github.com/llvm/llvm-project/pull/144030.diff 4 Files Affected:
diff --git a/mlir/include/mlir/IR/EnumAttr.td b/mlir/include/mlir/IR/EnumAttr.td
index 3f7f747ac20d3..50e4e632109fc 100644
--- a/mlir/include/mlir/IR/EnumAttr.td
+++ b/mlir/include/mlir/IR/EnumAttr.td
@@ -39,8 +39,9 @@ class EnumCase<string sym, int intVal, string strVal, int widthVal> {
class IntEnumAttrCaseBase<I intType, string sym, string strVal, int intVal> :
EnumCase<sym, intVal, strVal, intType.bitwidth>,
SignlessIntegerAttrBase<intType, "case " # strVal> {
- let predicate =
- CPred<"::llvm::cast<::mlir::IntegerAttr>($_self).getInt() == " # intVal>;
+ let predicate = CPred<
+ "::llvm::cast<::mlir::IntegerAttr>($_self).getValue().eq(APInt("#intType
+ .bitwidth#", "#intVal#"))">;
}
// Cases of integer enums with a specific type. By default, the string
diff --git a/mlir/test/IR/attribute.mlir b/mlir/test/IR/attribute.mlir
index 4f280bde1aecc..edb7357e4e04b 100644
--- a/mlir/test/IR/attribute.mlir
+++ b/mlir/test/IR/attribute.mlir
@@ -454,6 +454,10 @@ func.func @allowed_cases_pass() {
%0 = "test.i32_enum_attr"() {attr = 5: i32} : () -> i32
// CHECK: test.i32_enum_attr
%1 = "test.i32_enum_attr"() {attr = 10: i32} : () -> i32
+ // CHECK: test.i32_enum_attr
+ %2 = "test.i32_enum_attr"() {attr = 2147483648: i32} : () -> i32
+ // CHECK: test.i32_enum_attr
+ %3 = "test.i32_enum_attr"() {attr = 4294967295: i32} : () -> i32
return
}
diff --git a/mlir/test/lib/Dialect/Test/TestEnumDefs.td b/mlir/test/lib/Dialect/Test/TestEnumDefs.td
index 5b785a600aad2..10e424a0f2523 100644
--- a/mlir/test/lib/Dialect/Test/TestEnumDefs.td
+++ b/mlir/test/lib/Dialect/Test/TestEnumDefs.td
@@ -17,9 +17,13 @@ include "mlir/IR/EnumAttr.td"
def I32Case5: I32EnumAttrCase<"case5", 5>;
def I32Case10: I32EnumAttrCase<"case10", 10>;
+def I32CaseSignedMaxPlusOne
+ : I32EnumAttrCase<"caseSignedMaxPlusOne", 2147483648>;
+def I32CaseUnsignedMax : I32EnumAttrCase<"caseUnsignedMax", 4294967295>;
-def SomeI32Enum: I32EnumAttr<
- "SomeI32Enum", "", [I32Case5, I32Case10]>;
+def SomeI32Enum : I32EnumAttr<"SomeI32Enum", "",
+ [I32Case5, I32Case10, I32CaseSignedMaxPlusOne,
+ I32CaseUnsignedMax]>;
def I64Case5: I64EnumAttrCase<"case5", 5>;
def I64Case10: I64EnumAttrCase<"case10", 10>;
diff --git a/mlir/tools/mlir-tblgen/EnumsGen.cpp b/mlir/tools/mlir-tblgen/EnumsGen.cpp
index 9941a203bc5cb..06dc588f90203 100644
--- a/mlir/tools/mlir-tblgen/EnumsGen.cpp
+++ b/mlir/tools/mlir-tblgen/EnumsGen.cpp
@@ -648,8 +648,10 @@ static void emitSpecializedAttrDef(const Record &enumDef, raw_ostream &os) {
os << formatv("{0} {1}::getValue() const {{\n", enumName, attrClassName);
- os << formatv(" return static_cast<{0}>(::mlir::IntegerAttr::getInt());\n",
- enumName);
+ os << formatv(
+ " return "
+ "static_cast<{0}>(::mlir::IntegerAttr::getValue().getZExtValue());\n",
+ enumName);
os << "}\n";
}
|
0978e13
to
e07b743
Compare
getInt is deprecated. We can instead compare APInt for the predicate and getZExtValue to return the underlying data
e07b743
to
263ec5a
Compare
mlir/include/mlir/IR/EnumAttr.td
Outdated
let predicate = | ||
CPred<"::llvm::cast<::mlir::IntegerAttr>($_self).getInt() == " # intVal>; | ||
let predicate = CPred< | ||
"::llvm::cast<::mlir::IntegerAttr>($_self).getValue().eq(::llvm::APInt("#intType |
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.
can you explain why you use getValue()
here and getValue().getZExtValue()
in the enums gen?
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.
getValue returns the underlying APInt. These are not supported by standard enums.
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 with changes addressed.
@ftynse Hey, could you please run the CI workflow? I am unable to merge this or run the CI myself. |
@0xMihir Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
…44030) Fixes llvm#144005 getInt is deprecated. We can instead compare APInt for the predicate and getZExtValue to return the underlying data.
…44030) Fixes llvm#144005 getInt is deprecated. We can instead compare APInt for the predicate and getZExtValue to return the underlying data.
Fixes #144005
getInt is deprecated. We can instead compare APInt for the predicate and getZExtValue to return the underlying data.