[Mlir-commits] [mlir] [MLIR] Add I{8, 16}Enum tablegen classes (PR #190825)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Apr 7 10:17:01 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Robert Konicar (Jezurko)
<details>
<summary>Changes</summary>
Add utility tablegen classes for creating 8 and 16 bit enums, simplifying defining enums that fit into smaller types.
---
Full diff: https://github.com/llvm/llvm-project/pull/190825.diff
2 Files Affected:
- (modified) mlir/include/mlir/IR/EnumAttr.td (+8)
- (modified) mlir/test/lib/Dialect/Test/TestEnumDefs.td (+14)
``````````diff
diff --git a/mlir/include/mlir/IR/EnumAttr.td b/mlir/include/mlir/IR/EnumAttr.td
index cfa2ac89350a1..6eef5075fe18a 100644
--- a/mlir/include/mlir/IR/EnumAttr.td
+++ b/mlir/include/mlir/IR/EnumAttr.td
@@ -48,6 +48,10 @@ class IntEnumAttrCaseBase<I intType, string sym, string strVal, int intVal> :
// Cases of integer enums with a specific type. By default, the string
// representation is the same as the C++ symbol name.
+class I8EnumCase<string sym, int val, string str = sym>
+ : EnumCase<sym, val, str, 8>;
+class I16EnumCase<string sym, int val, string str = sym>
+ : EnumCase<sym, val, str, 16>;
class I32EnumCase<string sym, int val, string str = sym>
: EnumCase<sym, val, str, 32>;
class I64EnumCase<string sym, int val, string str = sym>
@@ -292,6 +296,10 @@ class IntEnum<string name, string summary, list<EnumCase> cases, int width>
summary),
cases, width>;
+class I8Enum<string name, string summary, list<EnumCase> cases>
+ : IntEnum<name, summary, cases, 8>;
+class I16Enum<string name, string summary, list<EnumCase> cases>
+ : IntEnum<name, summary, cases, 16>;
class I32Enum<string name, string summary, list<EnumCase> cases>
: IntEnum<name, summary, cases, 32>;
class I64Enum<string name, string summary, list<EnumCase> cases>
diff --git a/mlir/test/lib/Dialect/Test/TestEnumDefs.td b/mlir/test/lib/Dialect/Test/TestEnumDefs.td
index bf805c4c54998..5d7c60d53c2c0 100644
--- a/mlir/test/lib/Dialect/Test/TestEnumDefs.td
+++ b/mlir/test/lib/Dialect/Test/TestEnumDefs.td
@@ -65,6 +65,20 @@ def TestSimpleEnum : I32Enum<"SimpleEnum", "", [
let cppNamespace = "::test";
}
+def TestSimpleEnum8: I8Enum<"SimpleEnum8", "", [
+ I8EnumCase<"a", 254>,
+ I8EnumCase<"b", 255>,
+ ]> {
+ let cppNamespace = "::test";
+}
+
+def TestSimpleEnum16: I16Enum<"SimpleEnum16", "", [
+ I16EnumCase<"a", 65534>,
+ I16EnumCase<"b", 65535>,
+ ]> {
+ let cppNamespace = "::test";
+}
+
def TestSimpleEnum64 : I64Enum<"SimpleEnum64", "", [
I64EnumCase<"a", 4294967296>,
I64EnumCase<"b", 4294967297>
``````````
</details>
https://github.com/llvm/llvm-project/pull/190825
More information about the Mlir-commits
mailing list