1
1
#!/usr/bin/env python3
2
2
"""A script to generate FileCheck statements for mlir unit tests.
3
-
4
3
This script is a utility to add FileCheck patterns to an mlir file.
5
4
6
5
NOTE: The input .mlir is expected to be the output from the parser, not a
@@ -77,13 +76,16 @@ def generate_in_parent_scope(self, n):
77
76
self .generate_in_parent_scope_left = n
78
77
79
78
# Generate a substitution name for the given ssa value name.
80
- def generate_name (self , source_variable_name ):
79
+ def generate_name (self , source_variable_name , use_ssa_name ):
81
80
82
81
# Compute variable name
83
82
variable_name = self .variable_names .pop (0 ) if len (self .variable_names ) > 0 else ''
84
83
if variable_name == '' :
85
- variable_name = "VAL_" + str (self .name_counter )
86
- self .name_counter += 1
84
+ if use_ssa_name :
85
+ variable_name = source_variable_name .upper ()
86
+ else :
87
+ variable_name = "VAL_" + str (self .name_counter )
88
+ self .name_counter += 1
87
89
88
90
# Scope where variable name is saved
89
91
scope = len (self .scopes ) - 1
@@ -158,7 +160,7 @@ def get_num_ssa_results(input_line):
158
160
159
161
160
162
# Process a line of input that has been split at each SSA identifier '%'.
161
- def process_line (line_chunks , variable_namer , strict_name_re = False ):
163
+ def process_line (line_chunks , variable_namer , use_ssa_name = False , strict_name_re = False ):
162
164
output_line = ""
163
165
164
166
# Process the rest that contained an SSA value name.
@@ -178,7 +180,7 @@ def process_line(line_chunks, variable_namer, strict_name_re=False):
178
180
output_line += "%[[" + variable + "]]"
179
181
else :
180
182
# Otherwise, generate a new variable.
181
- variable = variable_namer .generate_name (ssa_name )
183
+ variable = variable_namer .generate_name (ssa_name , use_ssa_name )
182
184
if strict_name_re :
183
185
# Use stricter regexp for the variable name, if requested.
184
186
# Greedy matching may cause issues with the generic '.*'
@@ -415,9 +417,11 @@ def main():
415
417
pad_depth = label_length if label_length < 21 else 4
416
418
output_line += " " * pad_depth
417
419
418
- # Process the rest of the line.
420
+ # Process the rest of the line. Use the original SSA name to generate the LIT
421
+ # variable names.
422
+ use_ssa_names = True
419
423
output_line += process_line (
420
- [argument ], variable_namer , args .strict_name_re
424
+ [argument ], variable_namer , use_ssa_names , args .strict_name_re
421
425
)
422
426
423
427
# Append the output line.
0 commit comments