From fce0f4e95f65e06a44c1f37253163f5094cbf7eb Mon Sep 17 00:00:00 2001 From: Sasha Lopoukhine Date: Tue, 2 Jul 2024 16:49:15 +0100 Subject: [PATCH] add --xdsl-anonymize option mutually exclusive with --mlir-anonymize (#2) Sometimes the names carry semantic meaning, so it's useful to check that they are preserved. --- filecheckize/main.py | 19 +++++++++++++++---- tests/filecheck/mlir.mlir | 23 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/filecheckize/main.py b/filecheckize/main.py index ad8b181..6c5714e 100644 --- a/filecheckize/main.py +++ b/filecheckize/main.py @@ -18,11 +18,17 @@ def main(): nargs="?", help="Input file to read. Defaults to standard input.", ) - parser.add_argument( + group = parser.add_mutually_exclusive_group() + group.add_argument( "--mlir-anonymize", action="store_true", help="Anonymize MLIR SSA value names and basic block names.", ) + group.add_argument( + "--xdsl-anonymize", + action="store_true", + help="Anonymize MLIR unnamed SSA values and basic block names.", + ) parser.add_argument( "--check-empty-lines", action="store_true", @@ -49,6 +55,7 @@ def main(): args = parser.parse_args(sys.argv[1:]) comment_line = re.compile(rf"^\s*{re.escape(args.comments_prefix)}.*$") + unnamed_ssa_value = re.compile(r"%([\d]+)") ssa_value_name = re.compile(r"%([\d]+|[\w$._-][\w\d$._-]*)(:|#[\d]*)?") basic_block_name = re.compile(r"\^([\d]+|[\w$._-][\w\d$._-]*)") @@ -73,9 +80,13 @@ def main(): if re.match(comment_line, line): continue - if args.mlir_anonymize: - # Anonymize SSA value names - line = re.sub(ssa_value_name, r"%{{.*}}", line) + if args.mlir_anonymize or args.xdsl_anonymize: + if args.mlir_anonymize: + # Anonymize SSA value names + line = re.sub(ssa_value_name, r"%{{.*}}", line) + elif args.xdsl_anonymize: + # Anonymize unnamed SSA values + line = re.sub(unnamed_ssa_value, r"%{{.*}}", line) # Anonymize basic blocks names line = re.sub(basic_block_name, r"^{{.*}}", line) diff --git a/tests/filecheck/mlir.mlir b/tests/filecheck/mlir.mlir index 5c2e1c8..b739c86 100644 --- a/tests/filecheck/mlir.mlir +++ b/tests/filecheck/mlir.mlir @@ -1,26 +1,49 @@ // RUN: filecheckize %s --strip-comments | filecheck %s --match-full-lines --check-prefix STRIP // RUN: filecheckize %s --strip-comments --check-empty-lines | filecheck %s --check-prefix WITH-EMPTY --match-full-lines // RUN: filecheckize %s --strip-comments --mlir-anonymize | filecheck %s --check-prefix ANONYMIZE --match-full-lines +// RUN: filecheckize %s --strip-comments --xdsl-anonymize | filecheck %s --check-prefix XDSL-ANONYMIZE --match-full-lines func.func @arg_rec(%0 : !test.type<"int">) -> !test.type<"int"> { %1 = func.call @arg_rec(%0) : (!test.type<"int">) -> !test.type<"int"> + %name = arith.constant : i32 + %other_name = arith.constant : i32 + %2 = arith.addi %name, %other_name : i32 func.return %1 : !test.type<"int"> } // STRIP: // CHECK: func.func @arg_rec(%0 : !test.type<"int">) -> !test.type<"int"> { // STRIP-NEXT: // CHECK-NEXT: %1 = func.call @arg_rec(%0) : (!test.type<"int">) -> !test.type<"int"> +// STRIP-NEXT: // CHECK-NEXT: %name = arith.constant : i32 +// STRIP-NEXT: // CHECK-NEXT: %other_name = arith.constant : i32 +// STRIP-NEXT: // CHECK-NEXT: %2 = arith.addi %name, %other_name : i32 // STRIP-NEXT: // CHECK-NEXT: func.return %1 : !test.type<"int"> // STRIP-NEXT: // CHECK-NEXT: } // WITH-EMPTY: // CHECK-EMPTY: // WITH-EMPTY-NEXT: // CHECK-NEXT: func.func @arg_rec(%0 : !test.type<"int">) -> !test.type<"int"> { // WITH-EMPTY-NEXT: // CHECK-NEXT: %1 = func.call @arg_rec(%0) : (!test.type<"int">) -> !test.type<"int"> +// WITH-EMPTY-NEXT: // CHECK-NEXT: %name = arith.constant : i32 +// WITH-EMPTY-NEXT: // CHECK-NEXT: %other_name = arith.constant : i32 +// WITH-EMPTY-NEXT: // CHECK-NEXT: %2 = arith.addi %name, %other_name : i32 // WITH-EMPTY-NEXT: // CHECK-NEXT: func.return %1 : !test.type<"int"> // WITH-EMPTY-NEXT: // CHECK-NEXT: } // WITH-EMPTY-NEXT: // CHECK-EMPTY: // WITH-EMPTY-NEXT: // CHECK-EMPTY: +// WITH-EMPTY-NEXT: // CHECK-EMPTY: +// WITH-EMPTY-NEXT: // CHECK-EMPTY: // ANONYMIZE: // CHECK: func.func @arg_rec(%{{.*}} : !test.type<"int">) -> !test.type<"int"> { // ANONYMIZE-NEXT: // CHECK-NEXT: %{{.*}} = func.call @arg_rec(%{{.*}}) : (!test.type<"int">) -> !test.type<"int"> +// ANONYMIZE-NEXT: // CHECK-NEXT: %{{.*}} = arith.constant : i32 +// ANONYMIZE-NEXT: // CHECK-NEXT: %{{.*}} = arith.constant : i32 +// ANONYMIZE-NEXT: // CHECK-NEXT: %{{.*}} = arith.addi %{{.*}}, %{{.*}} : i32 // ANONYMIZE-NEXT: // CHECK-NEXT: func.return %{{.*}} : !test.type<"int"> // ANONYMIZE-NEXT: // CHECK-NEXT: } + +// XDSL-ANONYMIZE: // CHECK: func.func @arg_rec(%{{.*}} : !test.type<"int">) -> !test.type<"int"> { +// XDSL-ANONYMIZE-NEXT: // CHECK-NEXT: %{{.*}} = func.call @arg_rec(%{{.*}}) : (!test.type<"int">) -> !test.type<"int"> +// XDSL-ANONYMIZE-NEXT: // CHECK-NEXT: %name = arith.constant : i32 +// XDSL-ANONYMIZE-NEXT: // CHECK-NEXT: %other_name = arith.constant : i32 +// XDSL-ANONYMIZE-NEXT: // CHECK-NEXT: %{{.*}} = arith.addi %name, %other_name : i32 +// XDSL-ANONYMIZE-NEXT: // CHECK-NEXT: func.return %{{.*}} : !test.type<"int"> +// XDSL-ANONYMIZE-NEXT: // CHECK-NEXT: }