Skip to content

Commit b877f33

Browse files
committed
[MLIR] Add documentation for generate-check-lines.py
1 parent 91bec1d commit b877f33

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

mlir/utils/generate-test-checks.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@
99
Example usage:
1010
$ generate-test-checks.py foo.mlir
1111
$ mlir-opt foo.mlir -transformation | generate-test-checks.py
12+
$ mlir-opt foo.mlir -transformation | generate-test-checks.py --source foo.mlir
13+
$ mlir-opt foo.mlir -transformation | generate-test-checks.py --source foo.mlir -i
14+
$ mlir-opt foo.mlir -transformation | generate-test-checks.py --source foo.mlir -i --source_delim_regex='gpu.func @'
1215
13-
The script will heuristically insert CHECK/CHECK-LABEL commands for each line
16+
The script will heuristically generate CHECK/CHECK-LABEL commands for each line
1417
within the file. By default this script will also try to insert string
15-
substitution blocks for all SSA value names. The script is designed to make
16-
adding checks to a test case fast, it is *not* designed to be authoritative
17-
about what constitutes a good test!
18+
substitution blocks for all SSA value names. If --source file is specified, the
19+
script will attempt to insert the generated CHECKs to the source file by looking
20+
for line positions matched by --source_delim_regex.
21+
22+
The script is designed to make adding checks to a test case fast, it is *not*
23+
designed to be authoritative about what constitutes a good test!
1824
"""
1925

2026
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -56,9 +62,11 @@ def push_name_scope(self):
5662
def pop_name_scope(self):
5763
self.scopes.pop()
5864

65+
# Return the level of nesting (number of pushed scopes).
5966
def num_scopes(self):
6067
return len(self.scopes)
6168

69+
# Reset the counter.
6270
def clear_counter(self):
6371
self.name_counter = 0
6472

@@ -93,15 +101,19 @@ def process_line(line_chunks, variable_namer):
93101
return output_line.rstrip() + '\n'
94102

95103

104+
# Process the source file lines. The source file doesn't have to be .mlir.
96105
def process_source_lines(source_lines, note, args):
97106
source_split_re = re.compile(args.source_delim_regex)
98107

99108
source_segments = [[]]
100109
for line in source_lines:
110+
# Remove previous note.
101111
if line == note:
102112
continue
113+
# Remove previous CHECK lines.
103114
if line.find(args.check_prefix) != -1:
104115
continue
116+
# Segment the file based on --source_delim_regex.
105117
if source_split_re.search(line):
106118
source_segments.append([])
107119

0 commit comments

Comments
 (0)