[Mlir-commits] [mlir] [mlir][utils] Update generate-test-checks.py (PR #136721)

Andrzej WarzyƄski llvmlistbot at llvm.org
Tue Apr 22 08:59:27 PDT 2025


https://github.com/banach-space created https://github.com/llvm/llvm-project/pull/136721

Following #128083, all `CHECK-SAME` lines generated by
generate-test-checks.py use a strict regex:

```mlir
// CHECK-SAME:      %[[A:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]] = arith.constant 0 : index
```

However, in most cases this strict form is unnecessary and can obscure
readability. In such cases, the following would be sufficient:

```mlir
// CHECK-SAME:      %[[A:.*]] = arith.constant 0 : index
```

This patch adds a command-line flag to make the strict mode optional. To
enable strict regex matching, use:

```bash
generate-test-checks.py --strict_name_re=true file.mlir
```


>From 36d47e89f1d6aaa39a1d4f61747368577b68ba43 Mon Sep 17 00:00:00 2001
From: Andrzej Warzynski <andrzej.warzynski at arm.com>
Date: Tue, 22 Apr 2025 15:53:32 +0000
Subject: [PATCH] [mlir][utils] Update generate-test-checks.py

Following #128083, all `CHECK-SAME` lines generated by
generate-test-checks.py use a strict regex:

```mlir
// CHECK-SAME:      %[[A:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]] = arith.constant 0 : index
```

However, in most cases this strict form is unnecessary and can obscure
readability. In such cases, the following would be sufficient:

```mlir
// CHECK-SAME:      %[[A:.*]] = arith.constant 0 : index
```

This patch adds a command-line flag to make the strict mode optional. To
enable strict regex matching, use:

```bash
generate-test-checks.py --strict_name_re=true file.mlir
```
---
 mlir/utils/generate-test-checks.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/mlir/utils/generate-test-checks.py b/mlir/utils/generate-test-checks.py
index 394ef7e0f7da0..5e13e61865df3 100755
--- a/mlir/utils/generate-test-checks.py
+++ b/mlir/utils/generate-test-checks.py
@@ -295,6 +295,12 @@ def main():
         help="Names to be used in FileCheck regular expression to represent "
         "attributes in the order they are defined. Separate names with commas,"
         "commas, and leave empty entries for default names (e.g.: 'MAP0,,,MAP1')")
+    parser.add_argument(
+        "--strict_name_re",
+        type=bool,
+        default=False,
+        help="Set to true to use stricter regex for CHECK-SAME directives. "
+        "Use when Greedy matching causes issues with the generic '.*'")
 
     args = parser.parse_args()
 
@@ -406,7 +412,7 @@ def main():
 
                 # Process the rest of the line.
                 output_line += process_line(
-                    [argument], variable_namer, strict_name_re=True
+                    [argument], variable_namer, args.strict_name_re
                 )
 
         # Append the output line.



More information about the Mlir-commits mailing list