Skip to content

Commit

Permalink
add --xdsl-anonymize option mutually exclusive with --mlir-anonymize (#2
Browse files Browse the repository at this point in the history
)

Sometimes the names carry semantic meaning, so it's useful to check that
they are preserved.
  • Loading branch information
superlopuh committed Jul 2, 2024
1 parent e1f3d31 commit fce0f4e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
19 changes: 15 additions & 4 deletions filecheckize/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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$._-]*)")

Expand All @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions tests/filecheck/mlir.mlir
Original file line number Diff line number Diff line change
@@ -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: }

0 comments on commit fce0f4e

Please sign in to comment.