@@ -77,13 +77,20 @@ def generate_in_parent_scope(self, n):
7777 self .generate_in_parent_scope_left = n
7878
7979 # 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 ):
8181
8282 # Compute variable name
8383 variable_name = self .variable_names .pop (0 ) if len (self .variable_names ) > 0 else ''
8484 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
8794
8895 # Scope where variable name is saved
8996 scope = len (self .scopes ) - 1
@@ -158,7 +165,7 @@ def get_num_ssa_results(input_line):
158165
159166
160167# 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 ):
162169 output_line = ""
163170
164171 # Process the rest that contained an SSA value name.
@@ -178,7 +185,7 @@ def process_line(line_chunks, variable_namer, strict_name_re=False):
178185 output_line += "%[[" + variable + "]]"
179186 else :
180187 # Otherwise, generate a new variable.
181- variable = variable_namer .generate_name (ssa_name )
188+ variable = variable_namer .generate_name (ssa_name , use_ssa_name )
182189 if strict_name_re :
183190 # Use stricter regexp for the variable name, if requested.
184191 # Greedy matching may cause issues with the generic '.*'
@@ -415,9 +422,11 @@ def main():
415422 pad_depth = label_length if label_length < 21 else 4
416423 output_line += " " * pad_depth
417424
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
419428 output_line += process_line (
420- [argument ], variable_namer , args .strict_name_re
429+ [argument ], variable_namer , use_ssa_names , args .strict_name_re
421430 )
422431
423432 # Append the output line.
0 commit comments