[Mlir-commits] [mlir] [mlir] Add support for broader range of input files in generate-test-checks.py (PR #134327)

Kevin Gleason llvmlistbot at llvm.org
Thu Apr 3 17:17:43 PDT 2025


https://github.com/GleasonK updated https://github.com/llvm/llvm-project/pull/134327

>From 7956172b9f924b72de0b4048c393964094142bbb Mon Sep 17 00:00:00 2001
From: Kevin Gleason <gleasonk at google.com>
Date: Fri, 4 Apr 2025 00:07:29 +0000
Subject: [PATCH 1/2] Add support for broader range of input files in
 generate-test-checks.py

---
 mlir/utils/generate-test-checks.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/mlir/utils/generate-test-checks.py b/mlir/utils/generate-test-checks.py
index 749bfa13fe734..7ec1314055fcd 100755
--- a/mlir/utils/generate-test-checks.py
+++ b/mlir/utils/generate-test-checks.py
@@ -227,7 +227,8 @@ def process_attribute_references(line, attribute_namer):
     components = ATTR_RE.split(line)
     for component in components:
         m = ATTR_RE.match(component)
-        if m:
+        # Only use attribute alias if one exists.
+        if m and attribute_namer.get_name(m.group(1)) != '?':
             output_line += '#[[' + attribute_namer.get_name(m.group(1)) + ']]'
             output_line += component[len(m.group()):]
         else:
@@ -237,9 +238,12 @@ def process_attribute_references(line, attribute_namer):
 # Pre-process a line of input to remove any character sequences that will be
 # problematic with FileCheck.
 def preprocess_line(line):
+    # If input line has `{{` i.e. in a StrAttr with serialized proto.
+    output_line = line.replace("{{", "{{\\{\\{}}")
+
     # Replace any double brackets, '[[' with escaped replacements. '[['
     # corresponds to variable names in FileCheck.
-    output_line = line.replace("[[", "{{\\[\\[}}")
+    output_line = output_line.replace("[[", "{{\\[\\[}}")
 
     # Replace any single brackets that are followed by an SSA identifier, the
     # identifier will be replace by a variable; Creating the same situation as
@@ -328,6 +332,11 @@ def main():
         if not input_line:
             continue
 
+        # When using `--starts_from_scope=0` to capture module lines, the file
+        # split needs to be skipped, otherwise a `CHECK: // -----` is inserted.
+        if input_line.startswith("// -----"):
+            continue
+
         # Check if this is an attribute definition and process it
         process_attribute_definition(input_line, attribute_namer, output)
 

>From dab3f26563a53f52a2f3bc90f8bfb5e3ae929fd5 Mon Sep 17 00:00:00 2001
From: Kevin Gleason <gleasonk at google.com>
Date: Fri, 4 Apr 2025 00:17:24 +0000
Subject: [PATCH 2/2] darker code formatter errors

---
 mlir/utils/generate-test-checks.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mlir/utils/generate-test-checks.py b/mlir/utils/generate-test-checks.py
index 7ec1314055fcd..ec00a7f1389d1 100755
--- a/mlir/utils/generate-test-checks.py
+++ b/mlir/utils/generate-test-checks.py
@@ -228,9 +228,9 @@ def process_attribute_references(line, attribute_namer):
     for component in components:
         m = ATTR_RE.match(component)
         # Only use attribute alias if one exists.
-        if m and attribute_namer.get_name(m.group(1)) != '?':
-            output_line += '#[[' + attribute_namer.get_name(m.group(1)) + ']]'
-            output_line += component[len(m.group()):]
+        if m and attribute_namer.get_name(m.group(1)) != "?":
+            output_line += "#[[" + attribute_namer.get_name(m.group(1)) + "]]"
+            output_line += component[len(m.group()) :]
         else:
             output_line += component
     return output_line



More information about the Mlir-commits mailing list