[Mlir-commits] [mlir] [TableGen] Use getValue instead of getInt for enum attributes (PR #144030)

Mihir Patil llvmlistbot at llvm.org
Fri Jun 20 03:42:22 PDT 2025


================
@@ -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(::llvm::APInt("#intType
----------------
0xMihir wrote:

```
let predicate = CPred<[{
    ::llvm::cast<::mlir::IntegerAttr>($_self).getValue().eq(::llvm::APInt(}]
      # intType.bitwidth # ", "
      # intVal # 
    "))">;
```

I'm not sure the opinions on mixing `[{}]` and `""`, but I think this is more readable than:

```
let predicate = CPred<[{
    ::llvm::cast<::mlir::IntegerAttr>($_self).getValue().eq(::llvm::APInt(}]
      # intType.bitwidth # [{, }]
      # intVal # 
    [{))}]>;
```

especially the last line.


https://github.com/llvm/llvm-project/pull/144030


More information about the Mlir-commits mailing list