From 9c2551c9eecc867ea0ff1ad43389385bb8efedc2 Mon Sep 17 00:00:00 2001 From: Michael Maitland Date: Wed, 11 Jun 2025 10:49:11 -0700 Subject: [PATCH 1/3] [mlir][generate-test-checks] Emit attributes with rest of CHECK lines 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. --- mlir/utils/generate-test-checks.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/mlir/utils/generate-test-checks.py b/mlir/utils/generate-test-checks.py index 11fb4e40072e7..e84484b3e410c 100755 --- a/mlir/utils/generate-test-checks.py +++ b/mlir/utils/generate-test-checks.py @@ -220,12 +220,12 @@ def process_source_lines(source_lines, note, args): source_segments[-1].append(line + "\n") return source_segments -def process_attribute_definition(line, attribute_namer, output): +def process_attribute_definition(line, attribute_namer): m = ATTR_DEF_RE.match(line) if m: attribute_name = attribute_namer.generate_name(m.group(1)) - line = '// CHECK: #[[' + attribute_name + ':.+]] =' + line[len(m.group(0)):] + '\n' - output.write(line) + return '// CHECK: #[[' + attribute_name + ':.+]] =' + line[len(m.group(0)):] + '\n' + return None def process_attribute_references(line, attribute_namer): @@ -340,6 +340,9 @@ def main(): variable_namer = VariableNamer(args.variable_names) attribute_namer = AttributeNamer(args.attribute_names) + # Store attribute definitions to emit at appropriate scope + pending_attr_defs = [] + # Process lines for input_line in input_lines: if not input_line: @@ -350,8 +353,9 @@ def main(): if input_line.startswith("// -----"): continue - # Check if this is an attribute definition and process it - process_attribute_definition(input_line, attribute_namer, output) + if ATTR_DEF_RE.match(input_line): + pending_attr_defs.append(input_line) + continue # Lines with blocks begin with a ^. These lines have a trailing comment # that needs to be stripped. @@ -407,6 +411,13 @@ def main(): output_line += process_line(ssa_split[1:], variable_namer) else: + # Emit any pending attribute definitions at the start of this scope + for attr in pending_attr_defs: + attr_line = process_attribute_definition(attr, attribute_namer) + if (attr_line): + output_segments[-1].append(attr_line) + pending_attr_defs.clear() + # Output the first line chunk that does not contain an SSA name for the # label. output_line = "// " + args.check_prefix + "-LABEL: " + ssa_split[0] + "\n" From c622b91b7f7d851b24b37b27004496cc87154f10 Mon Sep 17 00:00:00 2001 From: Michael Maitland Date: Wed, 11 Jun 2025 11:26:13 -0700 Subject: [PATCH 2/3] clang-format --- mlir/utils/generate-test-checks.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mlir/utils/generate-test-checks.py b/mlir/utils/generate-test-checks.py index e84484b3e410c..36afa7d548684 100755 --- a/mlir/utils/generate-test-checks.py +++ b/mlir/utils/generate-test-checks.py @@ -224,7 +224,13 @@ def process_attribute_definition(line, attribute_namer): m = ATTR_DEF_RE.match(line) if m: attribute_name = attribute_namer.generate_name(m.group(1)) - return '// CHECK: #[[' + attribute_name + ':.+]] =' + line[len(m.group(0)):] + '\n' + return ( + "// CHECK: #[[" + + attribute_name + + ":.+]] =" + + line[len(m.group(0)) :] + + "\n" + ) return None def process_attribute_references(line, attribute_namer): @@ -414,7 +420,7 @@ def main(): # Emit any pending attribute definitions at the start of this scope for attr in pending_attr_defs: attr_line = process_attribute_definition(attr, attribute_namer) - if (attr_line): + if attr_line: output_segments[-1].append(attr_line) pending_attr_defs.clear() From cdf05cc5fbd459a1e8489f7566755d07e2aeaa40 Mon Sep 17 00:00:00 2001 From: Michael Maitland Date: Wed, 11 Jun 2025 13:15:44 -0700 Subject: [PATCH 3/3] clang-format --- mlir/utils/generate-test-checks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mlir/utils/generate-test-checks.py b/mlir/utils/generate-test-checks.py index 36afa7d548684..1d472f3ffcde1 100755 --- a/mlir/utils/generate-test-checks.py +++ b/mlir/utils/generate-test-checks.py @@ -220,6 +220,7 @@ def process_source_lines(source_lines, note, args): source_segments[-1].append(line + "\n") return source_segments + def process_attribute_definition(line, attribute_namer): m = ATTR_DEF_RE.match(line) if m: