Skip to content

Commit e601bed

Browse files
committed
[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.
1 parent 05137cc commit e601bed

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

mlir/include/mlir/IR/EnumAttr.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,9 @@ class EnumParameter<EnumAttrInfo enumInfo>
384384
// The op will appear in the IR as `my_dialect.my_op first`. However, the
385385
// generic format of the attribute will be `#my_dialect<"enum first">`. Override
386386
// the attribute's assembly format as required.
387-
class EnumAttr<Dialect dialect, EnumAttrInfo enumInfo, string name = "",
388-
list <Trait> traits = []>
389-
: AttrDef<dialect, enumInfo.className, traits> {
387+
class EnumAttr<Dialect dialect, EnumAttrInfo enumInfo, string mnemonicArg = "",
388+
string name = "", list <Trait> traits = []>
389+
: AttrDef<dialect, !if(!empty(name), enumInfo.className, name), traits> {
390390
let summary = enumInfo.summary;
391391
let description = enumInfo.description;
392392

@@ -410,7 +410,7 @@ class EnumAttr<Dialect dialect, EnumAttrInfo enumInfo, string name = "",
410410
let parameters = (ins EnumParameter<enumInfo>:$value);
411411

412412
// If a mnemonic was provided, use it to generate a custom assembly format.
413-
let mnemonic = name;
413+
let mnemonic = mnemonicArg;
414414

415415
// The default assembly format for enum attributes. Selected to best work with
416416
// operation assembly formats.

0 commit comments

Comments
 (0)