[Mlir-commits] [mlir] [mlir] Allow specifying name for EnumAttr (PR #119788)

Shoaib Meenai llvmlistbot at llvm.org
Thu Dec 12 15:03:22 PST 2024


https://github.com/smeenai created https://github.com/llvm/llvm-project/pull/119788

The name of an EnumAttr is currently always based on the name of the
underlying enum, which is a good default, but users may wish to
customize it. Add a template argument to enable this, while preserving
the old default. This is changing the position of the existing `traits`
argument, but that has no in-tree uses (so nothing needs to be updated),
and any out-of-tree uses should see a type mismatch error instead of
silently getting an incorrect argument value.


>From e601bedc06ad3a8817dab71f1b59f02bfc272cbc Mon Sep 17 00:00:00 2001
From: Shoaib Meenai <smeenai at fb.com>
Date: Thu, 12 Dec 2024 12:20:53 -0800
Subject: [PATCH] [mlir] Allow specifying name for EnumAttr

The name of an EnumAttr is currently always based on the name of the
underlying enum, which is a good default, but users may wish to
customize it. Add a template argument to enable this, while preserving
the old default. This is changing the position of the existing `traits`
argument, but that has no in-tree uses (so nothing needs to be updated),
and any out-of-tree uses should see a type mismatch error instead of
silently getting an incorrect argument value.
---
 mlir/include/mlir/IR/EnumAttr.td | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mlir/include/mlir/IR/EnumAttr.td b/mlir/include/mlir/IR/EnumAttr.td
index 9fec28f03ec282..f7b5967437fb90 100644
--- a/mlir/include/mlir/IR/EnumAttr.td
+++ b/mlir/include/mlir/IR/EnumAttr.td
@@ -384,9 +384,9 @@ class EnumParameter<EnumAttrInfo enumInfo>
 // The op will appear in the IR as `my_dialect.my_op first`. However, the
 // generic format of the attribute will be `#my_dialect<"enum first">`. Override
 // the attribute's assembly format as required.
-class EnumAttr<Dialect dialect, EnumAttrInfo enumInfo, string name = "",
-               list <Trait> traits = []>
-    : AttrDef<dialect, enumInfo.className, traits> {
+class EnumAttr<Dialect dialect, EnumAttrInfo enumInfo, string mnemonicArg = "",
+               string name = "", list <Trait> traits = []>
+    : AttrDef<dialect, !if(!empty(name), enumInfo.className, name), traits> {
   let summary = enumInfo.summary;
   let description = enumInfo.description;
 
@@ -410,7 +410,7 @@ class EnumAttr<Dialect dialect, EnumAttrInfo enumInfo, string name = "",
   let parameters = (ins EnumParameter<enumInfo>:$value);
 
   // If a mnemonic was provided, use it to generate a custom assembly format.
-  let mnemonic = name;
+  let mnemonic = mnemonicArg;
 
   // The default assembly format for enum attributes. Selected to best work with
   // operation assembly formats.



More information about the Mlir-commits mailing list