@@ -77,13 +77,20 @@ def generate_in_parent_scope(self, n):
77
77
self .generate_in_parent_scope_left = n
78
78
79
79
# Generate a substitution name for the given ssa value name.
80
- def generate_name (self , source_variable_name ):
80
+ def generate_name (self , source_variable_name , use_ssa_name ):
81
81
82
82
# Compute variable name
83
83
variable_name = self .variable_names .pop (0 ) if len (self .variable_names ) > 0 else ''
84
84
if variable_name == '' :
85
- variable_name = "VAL_" + str (self .name_counter )
86
- self .name_counter += 1
85
+ # If `use_ssa_name` is set, use the MLIR SSA value name to generate
86
+ # a FileCHeck substation string. As FileCheck requires these
87
+ # strings to start with a character, skip MLIR variables starting
88
+ # with a digit (e.g. `%0`).
89
+ if use_ssa_name and source_variable_name [0 ].isalpha ():
90
+ variable_name = source_variable_name .upper ()
91
+ else :
92
+ variable_name = "VAL_" + str (self .name_counter )
93
+ self .name_counter += 1
87
94
88
95
# Scope where variable name is saved
89
96
scope = len (self .scopes ) - 1
@@ -158,7 +165,7 @@ def get_num_ssa_results(input_line):
158
165
159
166
160
167
# 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 ):
168
+ def process_line (line_chunks , variable_namer , use_ssa_name = False , strict_name_re = False ):
162
169
output_line = ""
163
170
164
171
# Process the rest that contained an SSA value name.
@@ -178,7 +185,7 @@ def process_line(line_chunks, variable_namer, strict_name_re=False):
178
185
output_line += "%[[" + variable + "]]"
179
186
else :
180
187
# Otherwise, generate a new variable.
181
- variable = variable_namer .generate_name (ssa_name )
188
+ variable = variable_namer .generate_name (ssa_name , use_ssa_name )
182
189
if strict_name_re :
183
190
# Use stricter regexp for the variable name, if requested.
184
191
# Greedy matching may cause issues with the generic '.*'
@@ -415,9 +422,11 @@ def main():
415
422
pad_depth = label_length if label_length < 21 else 4
416
423
output_line += " " * pad_depth
417
424
418
- # Process the rest of the line.
425
+ # Process the rest of the line. Use the original SSA name to generate the LIT
426
+ # variable names.
427
+ use_ssa_names = True
419
428
output_line += process_line (
420
- [argument ], variable_namer , args .strict_name_re
429
+ [argument ], variable_namer , use_ssa_names , args .strict_name_re
421
430
)
422
431
423
432
# Append the output line.
0 commit comments