Skip to content

Commit c76fa54

Browse files
committed
[utils][UpdateLLCTestChecks] Add MIR support to update_llc_test_checks.py
This change enables update_llc_test_checks.py to automatically generate MIR checks for RUN lines that use -stop-before or -stop-after flags. This allows tests to verify intermediate compilation stages (e.g., after instruction selection but before peephole optimizations) alongside the final assembly output.
1 parent a2f3811 commit c76fa54

File tree

1 file changed

+48
-7
lines changed

1 file changed

+48
-7
lines changed

llvm/utils/update_llc_test_checks.py

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,21 @@
1313
from traceback import print_exc
1414
import argparse
1515
import os # Used to advertise this file's name ("autogenerated_note").
16+
import re
1617
import sys
1718

1819
from UpdateTestChecks import common
20+
import update_mir_test_checks # Reuse MIR parsing code.
1921

2022
# llc is the only llc-like in the LLVM tree but downstream forks can add
2123
# additional ones here if they have them.
2224
LLC_LIKE_TOOLS = [
2325
"llc",
2426
]
2527

28+
def has_stop_pass_flag(llc_args):
29+
"""Check if llc arguments contain -stop-before or -stop-after flag."""
30+
return re.search(r'-stop-(?:before|after)=', llc_args) is not None
2631

2732
def update_test(ti: common.TestInfo):
2833
triple_in_ir = None
@@ -119,6 +124,10 @@ def update_test(ti: common.TestInfo):
119124
ginfo=ginfo,
120125
)
121126

127+
# Dictionary to store MIR function bodies separately
128+
mir_func_dict = {}
129+
mir_run_list = []
130+
122131
for (
123132
prefixes,
124133
llc_tool,
@@ -141,14 +150,31 @@ def update_test(ti: common.TestInfo):
141150
if not triple:
142151
triple = common.get_triple_from_march(march_in_cmd)
143152

144-
scrubber, function_re = output_type.get_run_handler(triple)
145-
if 0 == builder.process_run_line(
146-
function_re, scrubber, raw_tool_output, prefixes
147-
):
148-
common.warn(
149-
"Couldn't match any function. Possibly the wrong target triple has been provided"
153+
# Check if this run generates MIR output
154+
if has_stop_pass_flag(llc_args):
155+
common.debug("Detected MIR output mode for prefixes:", str(prefixes))
156+
# Initialize MIR func_dict for these prefixes.
157+
for prefix in prefixes:
158+
if prefix not in mir_func_dict:
159+
mir_func_dict[prefix] = {}
160+
161+
# Build MIR function dictionary using imported function.
162+
update_mir_test_checks.build_function_info_dictionary(
163+
ti.path, raw_tool_output, triple, prefixes, mir_func_dict, ti.args.verbose
150164
)
151-
builder.processed_prefixes(prefixes)
165+
166+
# Store this run info for later.
167+
mir_run_list.append((prefixes, llc_tool, llc_args, triple_in_cmd, march_in_cmd))
168+
else:
169+
# Regular assembly output.
170+
scrubber, function_re = output_type.get_run_handler(triple)
171+
if 0 == builder.process_run_line(
172+
function_re, scrubber, raw_tool_output, prefixes
173+
):
174+
common.warn(
175+
"Couldn't match any function. Possibly the wrong target triple has been provided"
176+
)
177+
builder.processed_prefixes(prefixes)
152178

153179
func_dict = builder.finish_and_get_func_dict()
154180
global_vars_seen_dict = {}
@@ -221,6 +247,21 @@ def update_test(ti: common.TestInfo):
221247
is_filtered=builder.is_filtered(),
222248
)
223249
)
250+
251+
# Also add MIR checks if we have them for this function
252+
if mir_run_list and func_name:
253+
common.add_mir_checks_for_function(
254+
ti.path,
255+
output_lines,
256+
mir_run_list,
257+
mir_func_dict,
258+
func_name,
259+
single_bb=False, # Don't skip basic block labels.
260+
print_fixed_stack=False, # Don't print fixed stack (ASM tests don't need it).
261+
first_check_is_next=False, # First check is LABEL, not NEXT.
262+
at_the_function_name=False, # Use "name:" not "@name".
263+
)
264+
224265
is_in_function_start = False
225266

226267
if is_in_function:

0 commit comments

Comments
 (0)