[Mlir-commits] [mlir] [mlir] Use MLIR op names when generating FileCheck variables in generate-test-checks.py (PR #160820)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Sep 26 00:27:25 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {darker}-->


:warning: Python code formatter, darker found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
darker --check --diff -r origin/main...HEAD mlir/utils/generate-test-checks.py
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from darker here.
</summary>

``````````diff
--- generate-test-checks.py	2025-09-26 07:22:16.000000 +0000
+++ generate-test-checks.py	2025-09-26 07:26:55.059993 +0000
@@ -50,11 +50,11 @@
 # dialect (e.g. `vector.transfer_read`).
 DIALECTS = "acc|affine|amdgpu|amx|arith|arm_neon|arm_sve|arm_sme|async|bufferization|cf|complex|dlti|emitc|\
     func|gpu|index|irdl|linalg|llvm|math|memref|ml_program|mpi|nvgpu|nvvm|omp|pdl_interp|pdl|ptr|quant|\
     rocdl|scf|shape|shard|smt|sparse_tensor|tensor|ub|vcix|vector|wasmssa|x86vector|xegpu|xevm|spirv|tosa|\
     transform"
-SSA_OP_NAME_RE = re.compile(rf'\b(?:{DIALECTS})[.]([a-z_]+)\b')
+SSA_OP_NAME_RE = re.compile(rf"\b(?:{DIALECTS})[.]([a-z_]+)\b")
 
 # Regex matching the left-hand side of an assignment
 SSA_RESULTS_STR = r'\s*(%' + SSA_RE_STR + r')(\s*,\s*(%' + SSA_RE_STR + r'))*\s*='
 SSA_RESULTS_RE = re.compile(SSA_RESULTS_STR)
 
@@ -89,12 +89,11 @@
     # Generate the following 'n' variable names in the parent scope.
     def generate_in_parent_scope(self, n):
         self.generate_in_parent_scope_left = n
 
     # Generate a substitution name for the given ssa value name.
-    def generate_name(self, source_variable_name, use_ssa_name, op_name = ""):
-
+    def generate_name(self, source_variable_name, use_ssa_name, op_name=""):
         # Compute variable name
         variable_name = self.variable_names.pop(0) if len(self.variable_names) > 0 else ''
         if variable_name == '':
             # If `use_ssa_name` is set, use the MLIR SSA value name to generate
             # a FileCHeck substation string. As FileCheck requires these
@@ -106,11 +105,13 @@
             #
             # If neither worked, use a generic name: `VAL_#N`.
             if use_ssa_name and source_variable_name[0].isalpha():
                 variable_name = source_variable_name.upper()
             elif op_name != "":
-                variable_name = op_name.upper() + "_" + str(self.op_name_counter[op_name])
+                variable_name = (
+                    op_name.upper() + "_" + str(self.op_name_counter[op_name])
+                )
                 self.op_name_counter[op_name] += 1
             else:
                 variable_name = "VAL_" + str(self.name_counter)
                 self.name_counter += 1
 
@@ -193,12 +194,14 @@
 
     # Process the rest that contained an SSA value name.
     for chunk in line_chunks:
         ssa = SSA_RE.match(chunk)
         op_name_with_dialect = SSA_OP_NAME_RE.search(chunk)
-        ssa_name = ssa.group(0) if ssa is not None else ''
-        op_name = op_name_with_dialect.group(1) if op_name_with_dialect is not None else ''
+        ssa_name = ssa.group(0) if ssa is not None else ""
+        op_name = (
+            op_name_with_dialect.group(1) if op_name_with_dialect is not None else ""
+        )
 
         # Check if an existing variable exists for this name.
         variable = None
         for scope in variable_namer.scopes:
             variable = scope.get(ssa_name)
@@ -208,12 +211,11 @@
         # If one exists, then output the existing name.
         if variable is not None:
             output_line += "%[[" + variable + "]]"
         else:
             # Otherwise, generate a new variable.
-            variable = variable_namer.generate_name(ssa_name, use_ssa_name,
-                                                    op_name)
+            variable = variable_namer.generate_name(ssa_name, use_ssa_name, op_name)
             if strict_name_re:
                 # Use stricter regexp for the variable name, if requested.
                 # Greedy matching may cause issues with the generic '.*'
                 # regexp when the checks are split across several
                 # lines (e.g. for CHECK-SAME).

``````````

</details>


https://github.com/llvm/llvm-project/pull/160820


More information about the Mlir-commits mailing list