Skip to content

Commit 263ec5a

Browse files
committed
[TableGen] Use getValue instead of getInt for enum attributes
getInt is deprecated. We can instead compare APInt for the predicate and getZExtValue to return the underlying data
1 parent e2c27fd commit 263ec5a

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

mlir/include/mlir/IR/EnumAttr.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ class EnumCase<string sym, int intVal, string strVal, int widthVal> {
3939
class IntEnumAttrCaseBase<I intType, string sym, string strVal, int intVal> :
4040
EnumCase<sym, intVal, strVal, intType.bitwidth>,
4141
SignlessIntegerAttrBase<intType, "case " # strVal> {
42-
let predicate =
43-
CPred<"::llvm::cast<::mlir::IntegerAttr>($_self).getInt() == " # intVal>;
42+
let predicate = CPred<
43+
"::llvm::cast<::mlir::IntegerAttr>($_self).getValue().eq(::llvm::APInt("#intType
44+
.bitwidth#", "#intVal#"))">;
4445
}
4546

4647
// Cases of integer enums with a specific type. By default, the string

mlir/test/IR/attribute.mlir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ func.func @allowed_cases_pass() {
454454
%0 = "test.i32_enum_attr"() {attr = 5: i32} : () -> i32
455455
// CHECK: test.i32_enum_attr
456456
%1 = "test.i32_enum_attr"() {attr = 10: i32} : () -> i32
457+
// CHECK: test.i32_enum_attr
458+
%2 = "test.i32_enum_attr"() {attr = 2147483648: i32} : () -> i32
459+
// CHECK: test.i32_enum_attr
460+
%3 = "test.i32_enum_attr"() {attr = 4294967295: i32} : () -> i32
457461
return
458462
}
459463

mlir/test/lib/Dialect/Test/TestEnumDefs.td

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ include "mlir/IR/EnumAttr.td"
1717

1818
def I32Case5: I32EnumAttrCase<"case5", 5>;
1919
def I32Case10: I32EnumAttrCase<"case10", 10>;
20+
def I32CaseSignedMaxPlusOne
21+
: I32EnumAttrCase<"caseSignedMaxPlusOne", 2147483648>;
22+
def I32CaseUnsignedMax : I32EnumAttrCase<"caseUnsignedMax", 4294967295>;
2023

21-
def SomeI32Enum: I32EnumAttr<
22-
"SomeI32Enum", "", [I32Case5, I32Case10]>;
24+
def SomeI32Enum : I32EnumAttr<"SomeI32Enum", "",
25+
[I32Case5, I32Case10, I32CaseSignedMaxPlusOne,
26+
I32CaseUnsignedMax]>;
2327

2428
def I64Case5: I64EnumAttrCase<"case5", 5>;
2529
def I64Case10: I64EnumAttrCase<"case10", 10>;

mlir/tools/mlir-tblgen/EnumsGen.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,10 @@ static void emitSpecializedAttrDef(const Record &enumDef, raw_ostream &os) {
648648

649649
os << formatv("{0} {1}::getValue() const {{\n", enumName, attrClassName);
650650

651-
os << formatv(" return static_cast<{0}>(::mlir::IntegerAttr::getInt());\n",
652-
enumName);
651+
os << formatv(
652+
" return "
653+
"static_cast<{0}>(::mlir::IntegerAttr::getValue().getZExtValue());\n",
654+
enumName);
653655

654656
os << "}\n";
655657
}

0 commit comments

Comments
 (0)