Skip to content

Commit 0dd5709

Browse files
committed
[UTC] Support to check generated comments
1 parent 531fd45 commit 0dd5709

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

llvm/utils/UpdateTestChecks/common.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ def invoke_tool(exe, cmd_args, ir, preprocess_cmd=None, verbose=False):
607607
DEBUG_ONLY_ARG_RE = re.compile(r"-debug-only[= ]([^ ]+)")
608608

609609
IS_DEBUG_RECORD_RE = re.compile(r"^(\s+)#dbg_")
610-
IS_SWITCH_CASE_RE = re.compile(r"^\s+i\d+ \d+, label %\w+")
610+
IS_SWITCH_CASE_RE = re.compile(r"^\s+i\d+ \d+, label %\S+")
611611

612612
SCRUB_LEADING_WHITESPACE_RE = re.compile(r"^(\s+)")
613613
SCRUB_WHITESPACE_RE = re.compile(r"(?!^(| \w))[ \t]+", flags=re.M)
@@ -1123,6 +1123,8 @@ def processed_prefixes(self, prefixes):
11231123
##### Generator of LLVM IR CHECK lines
11241124

11251125
SCRUB_IR_COMMENT_RE = re.compile(r"\s*;.*")
1126+
# Comments to indicate the predecessors of a block in the IR.
1127+
SCRUB_PRED_COMMENT_RE = re.compile(r"\s*; preds = .*")
11261128
SCRUB_IR_FUNC_META_RE = re.compile(r"((?:\!(?!dbg\b)[a-zA-Z_]\w*(?:\s+![0-9]+)?)\s*)+")
11271129

11281130
# TODO: We should also derive check lines for global, debug, loop declarations, etc..
@@ -1877,6 +1879,7 @@ def generalize_check_lines(
18771879
*,
18781880
unstable_globals_only=False,
18791881
no_meta_details=False,
1882+
ignore_all_comments=True, # If False, only ignore comments of predecessors
18801883
):
18811884
if unstable_globals_only:
18821885
regexp = ginfo.get_unstable_globals_regexp()
@@ -1904,8 +1907,13 @@ def escape_braces(match_obj):
19041907
line,
19051908
)
19061909
break
1907-
# Ignore any comments, since the check lines will too.
1908-
scrubbed_line = SCRUB_IR_COMMENT_RE.sub(r"", line)
1910+
scrubbed_line = (
1911+
# Ignore any comments, since the check lines will too.
1912+
SCRUB_IR_COMMENT_RE.sub(r"", line)
1913+
if ignore_all_comments
1914+
# Ignore comments of predecessors only.
1915+
else SCRUB_PRED_COMMENT_RE.sub(r"", line)
1916+
)
19091917
# Ignore the metadata details if check global is none
19101918
if no_meta_details:
19111919
scrubbed_line = SCRUB_IR_FUNC_META_RE.sub(r"{{.*}}", scrubbed_line)
@@ -2083,6 +2091,7 @@ def add_checks(
20832091
global_tbaa_records_for_prefixes={},
20842092
preserve_names=False,
20852093
original_check_lines: Mapping[str, List[str]] = {},
2094+
check_comments=True,
20862095
):
20872096
# prefix_exclusions are prefixes we cannot use to print the function because it doesn't exist in run lines that use these prefixes as well.
20882097
prefix_exclusions = set()
@@ -2280,6 +2289,8 @@ def add_checks(
22802289
global_tbaa_records,
22812290
preserve_names,
22822291
original_check_lines=original_check_lines.get(checkprefix),
2292+
# IR output might require comments checks, e.g., predicate info, memssa
2293+
ignore_all_comments=not check_comments,
22832294
)
22842295

22852296
# This could be selectively enabled with an optional invocation argument.
@@ -2299,8 +2310,9 @@ def add_checks(
22992310
if func_line.strip() == "":
23002311
is_blank_line = True
23012312
continue
2302-
# Do not waste time checking IR comments.
2303-
func_line = SCRUB_IR_COMMENT_RE.sub(r"", func_line)
2313+
if not check_comments:
2314+
# Do not waste time checking IR comments unless necessary.
2315+
func_line = SCRUB_IR_COMMENT_RE.sub(r"", func_line)
23042316

23052317
# Skip blank lines instead of checking them.
23062318
if is_blank_line:
@@ -2342,6 +2354,7 @@ def add_ir_checks(
23422354
global_vars_seen_dict,
23432355
global_tbaa_records_for_prefixes,
23442356
is_filtered,
2357+
check_comments=False,
23452358
original_check_lines={},
23462359
):
23472360
assert ginfo.is_ir()
@@ -2368,6 +2381,7 @@ def add_ir_checks(
23682381
global_tbaa_records_for_prefixes,
23692382
preserve_names,
23702383
original_check_lines=original_check_lines,
2384+
check_comments=check_comments,
23712385
)
23722386

23732387

llvm/utils/update_test_checks.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ def update_test(ti: common.TestInfo):
197197
global_tbaa_records_for_prefixes,
198198
is_filtered=builder.is_filtered(),
199199
original_check_lines=original_check_lines.get(func, {}),
200+
check_comments=args.check_comments,
200201
),
201202
)
202203
)
@@ -230,6 +231,7 @@ def update_test(ti: common.TestInfo):
230231
global_tbaa_records_for_prefixes,
231232
is_filtered=builder.is_filtered(),
232233
original_check_lines=original_check_lines.get(func_name, {}),
234+
check_comments=args.check_comments,
233235
)
234236
)
235237
is_in_function_start = False
@@ -362,6 +364,12 @@ def main():
362364
choices=["none", "smart", "all"],
363365
help="Check global entries (global variables, metadata, attribute sets, ...) for functions",
364366
)
367+
parser.add_argument(
368+
"--check-comments",
369+
action="store_true",
370+
default=False,
371+
help="Check the generated comments (e.g., PredicateInfo/MemSSA) for functions",
372+
)
365373
parser.add_argument(
366374
"--reset-variable-names",
367375
action="store_true",

0 commit comments

Comments
 (0)