-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[mlir][utils] Update generate-test-checks.py #136721
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
[mlir][utils] Update generate-test-checks.py #136721
Conversation
Following llvm#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 ```
@llvm/pr-subscribers-mlir Author: Andrzej Warzyński (banach-space) ChangesFollowing #128083, all // 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 // CHECK-SAME: %[[A:.*]] = arith.constant 0 : index This patch adds a command-line flag to make the strict mode optional. To generate-test-checks.py --strict_name_re=true file.mlir Full diff: https://github.com/llvm/llvm-project/pull/136721.diff 1 Files Affected:
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.
|
✅ With the latest revision this PR passed the Python code formatter. |
Thank you for the change! It makes sense to have an option. I am okay with either default value. Can you please show an example where such checks may be generated?
|
Try running the script on this example: module {
func.func @func(%arg0: memref<128x256x512xf32>, %arg1: memref<128x512x256xf32>, %arg2: memref<256x256xf32>) {
return
}
} I get this: // CHECK-LABEL: func.func @func(
// CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: memref<128x256x512xf32>,
// CHECK-SAME: %[[VAL_1:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: memref<128x512x256xf32>,
// CHECK-SAME: %[[VAL_2:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: memref<256x256xf32>) {
// CHECK: return
// CHECK: } There's also quite a few tests in this PR #130944 (that I find a bit obscured to the the strict regex). Btw, I've hit that issue with |
Fix formatting
Oh, okay :) yes, it is supposed to be applied mostly to the argument lists, I was just confused by the PR comment saying that it can generate something like this for SSA assignment, which would mean there is MLIR with something prepending the SSA assignment. LGTM |
I updated the summary. That example was generated using a file without an explicit module Op, so the script got confused. Thanks for the review! |
Following llvm#128083, all `CHECK-SAME` lines generated by generate-test-checks.py use a strict regex: ```mlir // CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: memref<128x256x512xf32>, ``` However, in most cases this strict form is unnecessary and can obscure readability. In such cases, the following would be sufficient: ```mlir // CHECK-SAME: %[[VAL_0:.*]]: memref<128x256x512xf32>, ``` 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 ```
Following llvm#128083, all `CHECK-SAME` lines generated by generate-test-checks.py use a strict regex: ```mlir // CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: memref<128x256x512xf32>, ``` However, in most cases this strict form is unnecessary and can obscure readability. In such cases, the following would be sufficient: ```mlir // CHECK-SAME: %[[VAL_0:.*]]: memref<128x256x512xf32>, ``` 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 ```
Following llvm#128083, all `CHECK-SAME` lines generated by generate-test-checks.py use a strict regex: ```mlir // CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: memref<128x256x512xf32>, ``` However, in most cases this strict form is unnecessary and can obscure readability. In such cases, the following would be sufficient: ```mlir // CHECK-SAME: %[[VAL_0:.*]]: memref<128x256x512xf32>, ``` 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 ```
Following #128083, all
CHECK-SAME
lines generated bygenerate-test-checks.py use a strict regex:
// CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: memref<128x256x512xf32>,
However, in most cases this strict form is unnecessary and can obscure
readability. In such cases, the following would be sufficient:
// CHECK-SAME: %[[VAL_0:.*]]: memref<128x256x512xf32>,
This patch adds a command-line flag to make the strict mode optional. To
enable strict regex matching, use: