Skip to content

Commit bc6834f

Browse files
authored
[mlir][spirv] Fix tablegen generator script's stripping of prefixes (#101378)
This script looks for existing definitions with the `SPIRV_` prefix, so that it can preserve them when updating the file. When the commit 2d62833 changed the prefix from `SPV_`, the number of characters to strip from matched names was not updated, which broke this feature. This commit fixes remaining cases that weren't fixed by 339c87a. The relationship of this script to the files it is meant to maintain is still bitrotten in other ways.
1 parent a1ba4fb commit bc6834f

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

mlir/utils/spirv/gen_spirv_dialect.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,10 @@ def gen_instr_coverage_report(path, instructions):
536536

537537
content = content.split(AUTOGEN_OPCODE_SECTION_MARKER)
538538

539-
existing_opcodes = [k[11:] for k in re.findall("def SPIRV_OC_\w+", content[1])]
539+
prefix = "def SPIRV_OC_"
540+
existing_opcodes = [
541+
k[len(prefix) :] for k in re.findall(prefix + "\w+", content[1])
542+
]
540543
existing_instructions = list(
541544
filter(lambda inst: (inst["opname"] in existing_opcodes), instructions)
542545
)
@@ -637,7 +640,12 @@ def update_td_enum_attrs(path, operand_kinds, filter_list):
637640
assert len(content) == 3
638641

639642
# Extend filter list with existing enum definitions
640-
existing_kinds = [k[8:-4] for k in re.findall("def SPIRV_\w+Attr", content[1])]
643+
prefix = "def SPIRV_"
644+
suffix = "Attr"
645+
existing_kinds = [
646+
k[len(prefix) : -len(suffix)]
647+
for k in re.findall(prefix + "\w+" + suffix, content[1])
648+
]
641649
filter_list.extend(existing_kinds)
642650

643651
capability_mapping = get_capability_mapping(operand_kinds)
@@ -959,12 +967,20 @@ def extract_td_op_info(op_def):
959967
- A dict containing potential manually specified sections
960968
"""
961969
# Get opname
962-
opname = [o[8:-2] for o in re.findall("def SPIRV_\w+Op", op_def)]
970+
prefix = "def SPIRV_"
971+
suffix = "Op"
972+
opname = [
973+
o[len(prefix) : -len(suffix)]
974+
for o in re.findall(prefix + "\w+" + suffix, op_def)
975+
]
963976
assert len(opname) == 1, "more than one ops in the same section!"
964977
opname = opname[0]
965978

966979
# Get instruction category
967-
inst_category = [o[4:] for o in re.findall("SPIRV_\w+Op", op_def.split(":", 1)[1])]
980+
prefix = "SPIRV_"
981+
inst_category = [
982+
o[len(prefix) :] for o in re.findall(prefix + "\w+Op", op_def.split(":", 1)[1])
983+
]
968984
assert len(inst_category) <= 1, "more than one ops in the same section!"
969985
inst_category = inst_category[0] if len(inst_category) == 1 else "Op"
970986

0 commit comments

Comments
 (0)