Skip to content

Commit ae2f75e

Browse files
michaelmaitlandMichael Maitland
authored andcommitted
[mlir][generate-test-checks] Emit attributes with rest of CHECK lines (llvm#143759)
Prior to this patch, generating test checks in place put the ATTR definitions at the very top of the file, above the RUN lines and autogenerated note. All CHECK lines should below the RUN lines and autogenerated note. This change ensures that the attribute definitions are emitted with the rest of the CHECK lines. --------- Co-authored-by: Michael Maitland <[email protected]>
1 parent 7e73065 commit ae2f75e

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

mlir/utils/generate-test-checks.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,19 @@ def process_source_lines(source_lines, note, args):
220220
source_segments[-1].append(line + "\n")
221221
return source_segments
222222

223-
def process_attribute_definition(line, attribute_namer, output):
223+
224+
def process_attribute_definition(line, attribute_namer):
224225
m = ATTR_DEF_RE.match(line)
225226
if m:
226227
attribute_name = attribute_namer.generate_name(m.group(1))
227-
line = '// CHECK: #[[' + attribute_name + ':.+]] =' + line[len(m.group(0)):] + '\n'
228-
output.write(line)
228+
return (
229+
"// CHECK: #[["
230+
+ attribute_name
231+
+ ":.+]] ="
232+
+ line[len(m.group(0)) :]
233+
+ "\n"
234+
)
235+
return None
229236

230237
def process_attribute_references(line, attribute_namer):
231238

@@ -340,6 +347,9 @@ def main():
340347
variable_namer = VariableNamer(args.variable_names)
341348
attribute_namer = AttributeNamer(args.attribute_names)
342349

350+
# Store attribute definitions to emit at appropriate scope
351+
pending_attr_defs = []
352+
343353
# Process lines
344354
for input_line in input_lines:
345355
if not input_line:
@@ -350,8 +360,9 @@ def main():
350360
if input_line.startswith("// -----"):
351361
continue
352362

353-
# Check if this is an attribute definition and process it
354-
process_attribute_definition(input_line, attribute_namer, output)
363+
if ATTR_DEF_RE.match(input_line):
364+
pending_attr_defs.append(input_line)
365+
continue
355366

356367
# Lines with blocks begin with a ^. These lines have a trailing comment
357368
# that needs to be stripped.
@@ -407,6 +418,13 @@ def main():
407418
output_line += process_line(ssa_split[1:], variable_namer)
408419

409420
else:
421+
# Emit any pending attribute definitions at the start of this scope
422+
for attr in pending_attr_defs:
423+
attr_line = process_attribute_definition(attr, attribute_namer)
424+
if attr_line:
425+
output_segments[-1].append(attr_line)
426+
pending_attr_defs.clear()
427+
410428
# Output the first line chunk that does not contain an SSA name for the
411429
# label.
412430
output_line = "// " + args.check_prefix + "-LABEL: " + ssa_split[0] + "\n"

0 commit comments

Comments
 (0)