summaryrefslogtreecommitdiff
path: root/mlir/utils
diff options
context:
space:
mode:
authorLei Zhang <antiagainst@google.com>2022-08-09 14:03:54 -0400
committerLei Zhang <antiagainst@google.com>2022-08-09 14:14:54 -0400
commita29fffc4752a10494a74bb9f8db9b885c8aa5af1 (patch)
treeec774786586c179e21184d004d148e9e500e430d /mlir/utils
parentb09f6b471fd251d1827e9478b944ef15927e5526 (diff)
downloadllvm-a29fffc4752a10494a74bb9f8db9b885c8aa5af1.tar.gz
[mlir][spirv] Migrate to use specalized enum attributes
Previously we are using IntegerAttr to back all SPIR-V enum attributes. Therefore we all such attributes are showed like IntegerAttr in IRs, which is barely readable and breaks roundtripability of the IR. This commit changes to use `EnumAttr` as the base directly so that we can have separate attribute definitions and better IR printing. Reviewed By: kuhar Differential Revision: https://reviews.llvm.org/D131311
Diffstat (limited to 'mlir/utils')
-rwxr-xr-xmlir/utils/spirv/gen_spirv_dialect.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/mlir/utils/spirv/gen_spirv_dialect.py b/mlir/utils/spirv/gen_spirv_dialect.py
index 7b0a61c2379b..c0b145e17ced 100755
--- a/mlir/utils/spirv/gen_spirv_dialect.py
+++ b/mlir/utils/spirv/gen_spirv_dialect.py
@@ -437,10 +437,13 @@ def gen_operand_kind_enum_attr(operand_kind, capability_mapping):
# Generate the enum attribute definition
kind_category = 'Bit' if is_bit_enum else 'I32'
enum_attr = '''def SPV_{name}Attr :
- SPV_{category}EnumAttr<"{name}", "valid SPIR-V {name}", [
+ SPV_{category}EnumAttr<"{name}", "valid SPIR-V {name}", "{snake_name}", [
{cases}
]>;'''.format(
- name=kind_name, category=kind_category, cases=case_names)
+ name=kind_name,
+ snake_name=snake_casify(kind_name),
+ category=kind_category,
+ cases=case_names)
return kind_name, case_defs + '\n\n' + enum_attr
@@ -473,7 +476,8 @@ def gen_opcode(instructions):
]
opcode_list = ',\n'.join(opcode_list)
enum_attr = 'def SPV_OpcodeAttr :\n'\
- ' SPV_I32EnumAttr<"{name}", "valid SPIR-V instructions", [\n'\
+ ' SPV_I32EnumAttr<"{name}", "valid SPIR-V instructions", '\
+ '"opcode", [\n'\
'{lst}\n'\
' ]>;'.format(name='Opcode', lst=opcode_list)
return opcode_str + '\n\n' + enum_attr
@@ -630,9 +634,7 @@ def update_td_enum_attrs(path, operand_kinds, filter_list):
def snake_casify(name):
"""Turns the given name to follow snake_case convention."""
- name = re.sub('\W+', '', name).split()
- name = [s.lower() for s in name]
- return '_'.join(name)
+ return re.sub(r'(?<!^)(?=[A-Z])', '_', name).lower()
def map_spec_operand_to_ods_argument(operand):