Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 11, 2025

Conversation

GleasonK
Copy link
Contributor

@GleasonK GleasonK commented Apr 4, 2025

A few additions:

  • Lines with {{: These can show up if serializing non-MLIR info into string attrs my.attr = {{proto}, {...}}. String escape the opening {{, given that check lines are generated this has no effect on {{.*}} etc in generated lines.
  • File split line: Normally these are skipped because of their indent level, but if using --starts_from_scope=0 to generate checks for the module {...} { line, and since MLIR opt tools emit file split lines by default, some CHECK: // ----- lines were emit.
  • (edit removed this, fixed by [mlir] fix references of attributes which are not defined earlier #134364) AttrAliases: I'm not sure if I'm missing something for the attribute parser to work correctly, but I was getting many #[[?]] for all dialect attrs. Only use the attr aliasing if there's a match.

@llvmbot llvmbot added the mlir label Apr 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 4, 2025

@llvm/pr-subscribers-mlir

Author: Kevin Gleason (GleasonK)

Changes

A few additions:

  • AttrAliases: I'm not sure if I'm missing something for the attribute parser to work correctly, but I was getting many #[[?]] for all dialect attrs. Only use the attr aliasing if there's a match.
  • Lines with {{: These can show up if serializing non-MLIR info into string attrs my.attr = {{proto}, {...}}. String escape the opening {{, given that check lines are generated this has no effect on {{.*}} etc in generated lines.
  • File split line: Normally these are skipped because of their indent level, but if using --starts_from_scope=0 to generate checks for the module {...} { line, and since MLIR opt tools emit file split lines by default, some CHECK: // ----- lines were emit.

Full diff: https://github.com/llvm/llvm-project/pull/134327.diff

1 Files Affected:

  • (modified) mlir/utils/generate-test-checks.py (+11-2)
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)
 

@GleasonK GleasonK requested a review from River707 April 4, 2025 00:13
@GleasonK GleasonK changed the title Add support for broader range of input files in generate-test-checks.py [mlir] Add support for broader range of input files in generate-test-checks.py Apr 4, 2025
Copy link

github-actions bot commented Apr 4, 2025

✅ With the latest revision this PR passed the Python code formatter.

@GleasonK GleasonK requested a review from joker-eph April 10, 2025 15:25
@GleasonK GleasonK merged commit e911f90 into llvm:main Apr 11, 2025
11 checks passed
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
…checks.py (llvm#134327)

A few additions:

- Lines with `{{`: These can show up if serializing non-MLIR info into
string attrs `my.attr = {{proto}, {...}}`. String escape the opening
`{{`, given that check lines are generated this has no effect on
`{{.*}}` etc in generated lines.
- File split line: Normally these are skipped because of their indent
level, but if using `--starts_from_scope=0` to generate checks for the
`module {...} {` line, and since MLIR opt tools emit file split lines by
default, some `CHECK: // -----` lines were emit.
- (edit removed this, fixed by
llvm#134364) AttrAliases: I'm not
sure if I'm missing something for the attribute parser to work
correctly, but I was getting many `#[[?]]` for all dialect attrs. Only
use the attr aliasing if there's a match.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants