[Mlir-commits] [mlir] [mlir] Add def to `Properties.td` to help with enum properties (PR #89311)

Jeff Niu llvmlistbot at llvm.org
Thu Apr 18 14:08:13 PDT 2024


https://github.com/Mogball created https://github.com/llvm/llvm-project/pull/89311

This is useful for defining operation properties that are enums.

>From 86af99d1c7e9a7c95738927efafd59c0a321e043 Mon Sep 17 00:00:00 2001
From: Mogball <jeff at modular.com>
Date: Thu, 18 Apr 2024 20:25:26 +0000
Subject: [PATCH] [mlir] Add def to `Properties.td` to help with enum
 properties

This is useful for defining operation properties that are enums.
---
 mlir/include/mlir/IR/Properties.td | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/mlir/include/mlir/IR/Properties.td b/mlir/include/mlir/IR/Properties.td
index 99da1763524fa9..0babdbbfa05bc2 100644
--- a/mlir/include/mlir/IR/Properties.td
+++ b/mlir/include/mlir/IR/Properties.td
@@ -153,4 +153,17 @@ class ArrayProperty<string storageTypeParam = "", int n, string desc = ""> :
   let assignToStorage = "::llvm::copy($_value, $_storage)";
 }
 
+class EnumProperty<string storageTypeParam, string desc = ""> :
+    Property<storageTypeParam, desc> {
+  code writeToMlirBytecode = [{
+    $_writer.writeVarInt(static_cast<uint64_t>($_storage));
+  }];
+  code readFromMlirBytecode = [{
+    uint64_t val;
+    if (failed($_reader.readVarInt(val)))
+      return ::mlir::failure();
+    $_storage = static_cast<}] # storageTypeParam # [{>(val);
+  }];
+}
+
 #endif // PROPERTIES



More information about the Mlir-commits mailing list