2019-11-26 10:40:52 -08:00
|
|
|
#!/usr/bin/env python3
|
2016-03-24 23:19:26 +00:00
|
|
|
|
2017-06-12 17:44:30 +00:00
|
|
|
"""A script to generate FileCheck statements for 'opt' regression tests.
|
2016-03-24 23:19:26 +00:00
|
|
|
|
2017-06-12 17:44:30 +00:00
|
|
|
This script is a utility to update LLVM opt test cases with new
|
2016-03-24 23:19:26 +00:00
|
|
|
FileCheck patterns. It can either update all of the tests in the file or
|
|
|
|
a single test function.
|
2016-04-05 18:00:47 +00:00
|
|
|
|
|
|
|
Example usage:
|
2022-10-20 11:33:49 +02:00
|
|
|
|
|
|
|
# Default to using `opt` as found in your PATH.
|
|
|
|
$ update_test_checks.py test/foo.ll
|
|
|
|
|
|
|
|
# Override the path lookup.
|
|
|
|
$ update_test_checks.py --tool-binary=../bin/opt test/foo.ll
|
|
|
|
|
|
|
|
# Use a custom tool instead of `opt`.
|
|
|
|
$ update_test_checks.py --tool=yourtool test/foo.ll
|
2016-04-05 18:00:47 +00:00
|
|
|
|
|
|
|
Workflow:
|
|
|
|
1. Make a compiler patch that requires updating some number of FileCheck lines
|
|
|
|
in regression test files.
|
|
|
|
2. Save the patch and revert it from your local work area.
|
|
|
|
3. Update the RUN-lines in the affected regression tests to look canonical.
|
|
|
|
Example: "; RUN: opt < %s -instcombine -S | FileCheck %s"
|
|
|
|
4. Refresh the FileCheck lines for either the entire file or select functions by
|
|
|
|
running this script.
|
|
|
|
5. Commit the fresh baseline of checks.
|
|
|
|
6. Apply your patch from step 1 and rebuild your local binaries.
|
|
|
|
7. Re-run this script on affected regression tests.
|
|
|
|
8. Check the diffs to ensure the script has done something reasonable.
|
|
|
|
9. Submit a patch including the regression test diffs for review.
|
2016-03-24 23:19:26 +00:00
|
|
|
"""
|
|
|
|
|
2019-01-03 14:11:33 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2016-03-24 23:19:26 +00:00
|
|
|
import argparse
|
2020-07-07 16:38:28 +01:00
|
|
|
import os # Used to advertise this file's name ("autogenerated_note").
|
2016-03-24 23:19:26 +00:00
|
|
|
import re
|
2020-07-07 16:38:28 +01:00
|
|
|
import sys
|
2016-03-24 23:19:26 +00:00
|
|
|
|
2018-01-30 00:40:05 +00:00
|
|
|
from UpdateTestChecks import common
|
|
|
|
|
2016-03-24 23:19:26 +00:00
|
|
|
|
|
|
|
def main():
|
2016-04-05 18:00:47 +00:00
|
|
|
from argparse import RawTextHelpFormatter
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2016-04-05 18:00:47 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description=__doc__, formatter_class=RawTextHelpFormatter
|
|
|
|
)
|
2022-10-20 11:33:49 +02:00
|
|
|
parser.add_argument(
|
|
|
|
"--tool",
|
|
|
|
default="opt",
|
|
|
|
help='The name of the tool used to generate the test case (defaults to "opt")',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--tool-binary",
|
|
|
|
"--opt-binary",
|
|
|
|
help="The tool binary used to generate the test case",
|
|
|
|
)
|
2016-03-24 23:19:26 +00:00
|
|
|
parser.add_argument("--function", help="The function in the test file to update")
|
2019-10-07 14:37:20 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"-p", "--preserve-names", action="store_true", help="Do not scrub IR names"
|
|
|
|
)
|
[Utils] Allow update_test_checks to check function information
Summary:
This adds a switch to the update_test_checks that triggers arguments and
other function annotations, e.g., personality, to be present in the
check line. If not set, the behavior should be the same as before.
If arguments are recorded, their names are scrubbed from the IR to allow
merging.
This patch includes D68153.
Reviewers: lebedev.ri, greened, spatel, xbolva00, RKSimon, mehdi_amini
Subscribers: bollu, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D68819
2019-10-10 12:08:21 -05:00
|
|
|
parser.add_argument(
|
|
|
|
"--function-signature",
|
2019-10-10 20:32:04 -05:00
|
|
|
action="store_true",
|
|
|
|
help="Keep function signature information around for the check line",
|
2020-07-11 21:53:50 +02:00
|
|
|
)
|
2021-01-14 21:13:23 -06:00
|
|
|
parser.add_argument(
|
|
|
|
"--scrub-attributes",
|
|
|
|
action="store_true",
|
|
|
|
help="Remove attribute annotations (#0) from the end of check line",
|
2022-10-20 11:33:49 +02:00
|
|
|
)
|
2020-07-07 16:38:28 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"--check-attributes",
|
|
|
|
action="store_true",
|
|
|
|
help='Check "Function Attributes" for functions',
|
2023-05-15 11:02:42 +02:00
|
|
|
)
|
2019-10-10 20:32:04 -05:00
|
|
|
parser.add_argument(
|
2021-01-14 21:13:23 -06:00
|
|
|
"--check-globals",
|
2023-11-13 14:45:27 +01:00
|
|
|
nargs="?",
|
|
|
|
const="all",
|
|
|
|
default="default",
|
|
|
|
choices=["none", "smart", "all"],
|
2019-10-10 20:32:04 -05:00
|
|
|
help="Check global entries (global variables, metadata, attribute sets, ...) for functions",
|
2023-05-15 11:02:42 +02:00
|
|
|
)
|
2023-11-23 06:46:07 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"--reset-variable-names",
|
|
|
|
action="store_true",
|
|
|
|
help="Reset all variable names to correspond closely to the variable names in IR. "
|
|
|
|
"This tends to result in larger diffs.",
|
|
|
|
)
|
2020-07-07 16:38:28 +01:00
|
|
|
parser.add_argument("tests", nargs="+")
|
2019-10-10 20:32:04 -05:00
|
|
|
initial_args = common.parse_commandline_args(parser)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2019-10-10 20:32:04 -05:00
|
|
|
script_name = os.path.basename(__file__)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2019-10-10 20:32:04 -05:00
|
|
|
if initial_args.tool_binary:
|
2023-01-23 10:38:53 +01:00
|
|
|
tool_basename = os.path.basename(initial_args.tool_binary)
|
2022-10-20 11:33:49 +02:00
|
|
|
if not re.match(r"^%s(-\d+)?(\.exe)?$" % (initial_args.tool), tool_basename):
|
|
|
|
common.error("Unexpected tool name: " + tool_basename)
|
|
|
|
sys.exit(1)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2016-03-24 23:19:26 +00:00
|
|
|
for ti in common.itertests(
|
|
|
|
initial_args.tests, parser, script_name="utils/" + script_name
|
|
|
|
):
|
|
|
|
# If requested we scrub trailing attribute annotations, e.g., '#0', together with whitespaces
|
2019-08-07 14:44:50 +00:00
|
|
|
if ti.args.scrub_attributes:
|
|
|
|
common.SCRUB_TRAILING_WHITESPACE_TEST_RE = (
|
|
|
|
common.SCRUB_TRAILING_WHITESPACE_AND_ATTRIBUTES_RE
|
|
|
|
)
|
|
|
|
else:
|
2019-10-10 20:32:04 -05:00
|
|
|
common.SCRUB_TRAILING_WHITESPACE_TEST_RE = (
|
2016-03-24 23:19:26 +00:00
|
|
|
common.SCRUB_TRAILING_WHITESPACE_RE
|
2022-10-20 11:33:49 +02:00
|
|
|
)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2022-10-20 11:33:49 +02:00
|
|
|
tool_basename = ti.args.tool
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2023-02-04 09:35:32 +08:00
|
|
|
prefix_list = []
|
2016-03-24 23:19:26 +00:00
|
|
|
for l in ti.run_lines:
|
2019-08-05 18:25:08 +00:00
|
|
|
if "|" not in l:
|
2016-03-24 23:19:26 +00:00
|
|
|
common.warn("Skipping unparsable RUN line: " + l)
|
|
|
|
continue
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2024-09-23 12:44:42 +01:00
|
|
|
cropped_content = l
|
|
|
|
if "%if" in l:
|
|
|
|
match = re.search(r"%{\s*(.*?)\s*%}", l)
|
|
|
|
if match:
|
|
|
|
cropped_content = match.group(1)
|
|
|
|
|
|
|
|
commands = [cmd.strip() for cmd in cropped_content.split("|")]
|
2016-03-24 23:19:26 +00:00
|
|
|
assert len(commands) >= 2
|
2021-04-21 12:19:08 +01:00
|
|
|
preprocess_cmd = None
|
|
|
|
if len(commands) > 2:
|
|
|
|
preprocess_cmd = " | ".join(commands[:-2])
|
|
|
|
tool_cmd = commands[-2]
|
2020-12-16 10:20:12 -08:00
|
|
|
filecheck_cmd = commands[-1]
|
|
|
|
common.verify_filecheck_prefixes(filecheck_cmd)
|
2022-10-20 11:33:49 +02:00
|
|
|
if not tool_cmd.startswith(tool_basename + " "):
|
|
|
|
common.warn("Skipping non-%s RUN line: %s" % (tool_basename, l))
|
2023-05-15 11:02:42 +02:00
|
|
|
continue
|
|
|
|
|
2022-10-20 11:33:49 +02:00
|
|
|
if not filecheck_cmd.startswith("FileCheck "):
|
|
|
|
common.warn("Skipping non-FileChecked RUN line: " + l)
|
|
|
|
continue
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2022-10-20 11:33:49 +02:00
|
|
|
tool_cmd_args = tool_cmd[len(tool_basename) :].strip()
|
2019-12-02 10:50:23 +00:00
|
|
|
tool_cmd_args = tool_cmd_args.replace("< %s", "").replace("%s", "").strip()
|
|
|
|
check_prefixes = common.get_check_prefixes(filecheck_cmd)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2019-12-02 10:50:23 +00:00
|
|
|
# FIXME: We should use multiple check prefixes to common check lines. For
|
|
|
|
# now, we just ignore all but the last.
|
|
|
|
prefix_list.append((check_prefixes, tool_cmd_args, preprocess_cmd))
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2025-02-19 20:29:51 -05:00
|
|
|
ginfo = common.make_ir_generalizer(
|
|
|
|
ti.args.version, ti.args.check_globals == "none"
|
|
|
|
)
|
2020-01-13 12:16:35 -06:00
|
|
|
global_vars_seen_dict = {}
|
|
|
|
builder = common.FunctionTestBuilder(
|
update_test_checks: match IR basic block labels (#88979)
Labels are matched using a regexp of the form '^(pattern):', which
requires the addition of a "suffix" concept to NamelessValue.
Aside from that, the key challenge is that block labels are values, and
we typically capture values including the prefix '%'. However, when
labels appear at the start of a basic block, the prefix '%' is not
included, so we must capture block label values *without* the prefix
'%'.
We don't know ahead of time whether an IR value is a label or not. In
most cases, they are prefixed by the word "label" (their type), but this
isn't the case in phi nodes. We solve this issue by leveraging the
two-phase nature of variable generalization: the first pass finds all
occurences of a variable and determines whether the '%' prefix can be
included or not. The second pass does the actual substitution.
This change also unifies the generalization path for assembly with that
for IR and analysis, in the hope that any future changes avoid diverging
those cases future.
I also considered the alternative of trying to detect the phi node case
using more regular expression special cases but ultimately decided
against that because it seemed more fragile, and perhaps the approach of
keeping a tentative prefix that may later be discarded could also be
eventually applied to some metadata and attribute cases.
Note that an early version of this change was reviewed as
https://reviews.llvm.org/D142452, before version numbers were
introduced. This is a substantially updated version of that change.
2024-05-19 01:39:47 +02:00
|
|
|
run_list=prefix_list,
|
|
|
|
flags=ti.args,
|
|
|
|
scrubber_args=[],
|
|
|
|
path=ti.path,
|
|
|
|
ginfo=ginfo,
|
2023-05-15 11:02:42 +02:00
|
|
|
)
|
|
|
|
|
2020-01-13 12:16:35 -06:00
|
|
|
tool_binary = ti.args.tool_binary
|
|
|
|
if not tool_binary:
|
|
|
|
tool_binary = tool_basename
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2020-01-13 12:16:35 -06:00
|
|
|
for prefixes, tool_args, preprocess_cmd in prefix_list:
|
|
|
|
common.debug("Extracted tool cmd: " + tool_basename + " " + tool_args)
|
|
|
|
common.debug("Extracted FileCheck prefixes: " + str(prefixes))
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2022-11-28 10:02:14 -08:00
|
|
|
raw_tool_output = common.invoke_tool(
|
|
|
|
tool_binary,
|
|
|
|
tool_args,
|
|
|
|
ti.path,
|
|
|
|
preprocess_cmd=preprocess_cmd,
|
|
|
|
verbose=ti.args.verbose,
|
|
|
|
)
|
|
|
|
builder.process_run_line(
|
2020-12-16 10:20:12 -08:00
|
|
|
common.OPT_FUNCTION_RE,
|
2022-11-28 10:02:14 -08:00
|
|
|
common.scrub_body,
|
|
|
|
raw_tool_output,
|
|
|
|
prefixes,
|
2023-05-15 11:02:42 +02:00
|
|
|
)
|
2022-07-19 09:43:58 +02:00
|
|
|
builder.processed_prefixes(prefixes)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2023-11-23 06:46:07 +01:00
|
|
|
prefix_set = set(
|
|
|
|
[prefix for prefixes, _, _ in prefix_list for prefix in prefixes]
|
|
|
|
)
|
|
|
|
|
|
|
|
if not ti.args.reset_variable_names:
|
|
|
|
original_check_lines = common.collect_original_check_lines(ti, prefix_set)
|
|
|
|
else:
|
|
|
|
original_check_lines = {}
|
|
|
|
|
2022-11-28 10:02:14 -08:00
|
|
|
func_dict = builder.finish_and_get_func_dict()
|
2016-03-24 23:19:26 +00:00
|
|
|
is_in_function = False
|
|
|
|
is_in_function_start = False
|
2021-01-14 21:13:23 -06:00
|
|
|
has_checked_pre_function_globals = False
|
2022-11-28 10:02:14 -08:00
|
|
|
common.debug("Rewriting FileCheck prefixes:", str(prefix_set))
|
|
|
|
output_lines = []
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2022-11-28 10:02:14 -08:00
|
|
|
include_generated_funcs = common.find_arg_in_test(
|
|
|
|
ti,
|
|
|
|
lambda args: ti.args.include_generated_funcs,
|
|
|
|
"--include-generated-funcs",
|
2023-05-15 11:02:42 +02:00
|
|
|
True,
|
2022-11-28 10:02:14 -08:00
|
|
|
)
|
|
|
|
generated_prefixes = []
|
2020-01-13 12:16:35 -06:00
|
|
|
if include_generated_funcs:
|
|
|
|
# Generate the appropriate checks for each function. We need to emit
|
|
|
|
# these in the order according to the generated output so that CHECK-LABEL
|
|
|
|
# works properly. func_order provides that.
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2020-01-13 12:16:35 -06:00
|
|
|
# We can't predict where various passes might insert functions so we can't
|
|
|
|
# be sure the input function order is maintained. Therefore, first spit
|
|
|
|
# out all the source lines.
|
2021-01-14 21:13:23 -06:00
|
|
|
common.dump_input_lines(output_lines, ti, prefix_set, ";")
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2021-01-14 21:13:23 -06:00
|
|
|
args = ti.args
|
2023-11-13 14:45:27 +01:00
|
|
|
if args.check_globals != 'none':
|
2022-11-28 10:02:14 -08:00
|
|
|
generated_prefixes.extend(
|
|
|
|
common.add_global_checks(
|
|
|
|
builder.global_var_dict(),
|
2023-05-15 11:02:42 +02:00
|
|
|
";",
|
2022-11-28 10:02:14 -08:00
|
|
|
prefix_list,
|
|
|
|
output_lines,
|
update_test_checks: match IR basic block labels (#88979)
Labels are matched using a regexp of the form '^(pattern):', which
requires the addition of a "suffix" concept to NamelessValue.
Aside from that, the key challenge is that block labels are values, and
we typically capture values including the prefix '%'. However, when
labels appear at the start of a basic block, the prefix '%' is not
included, so we must capture block label values *without* the prefix
'%'.
We don't know ahead of time whether an IR value is a label or not. In
most cases, they are prefixed by the word "label" (their type), but this
isn't the case in phi nodes. We solve this issue by leveraging the
two-phase nature of variable generalization: the first pass finds all
occurences of a variable and determines whether the '%' prefix can be
included or not. The second pass does the actual substitution.
This change also unifies the generalization path for assembly with that
for IR and analysis, in the hope that any future changes avoid diverging
those cases future.
I also considered the alternative of trying to detect the phi node case
using more regular expression special cases but ultimately decided
against that because it seemed more fragile, and perhaps the approach of
keeping a tentative prefix that may later be discarded could also be
eventually applied to some metadata and attribute cases.
Note that an early version of this change was reviewed as
https://reviews.llvm.org/D142452, before version numbers were
introduced. This is a substantially updated version of that change.
2024-05-19 01:39:47 +02:00
|
|
|
ginfo,
|
2022-11-28 10:02:14 -08:00
|
|
|
global_vars_seen_dict,
|
2021-01-14 21:13:23 -06:00
|
|
|
args.preserve_names,
|
2023-05-15 11:02:42 +02:00
|
|
|
True,
|
2023-11-13 14:45:27 +01:00
|
|
|
args.check_globals,
|
2023-05-15 11:02:42 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2021-01-14 21:13:23 -06:00
|
|
|
# Now generate all the checks.
|
2022-11-28 10:02:14 -08:00
|
|
|
generated_prefixes.extend(
|
|
|
|
common.add_checks_at_end(
|
|
|
|
output_lines,
|
|
|
|
prefix_list,
|
|
|
|
builder.func_order(),
|
2023-05-15 11:02:42 +02:00
|
|
|
";",
|
2021-01-14 21:13:23 -06:00
|
|
|
lambda my_output_lines, prefixes, func: common.add_ir_checks(
|
|
|
|
my_output_lines,
|
2023-05-15 11:02:42 +02:00
|
|
|
";",
|
2022-11-28 10:02:14 -08:00
|
|
|
prefixes,
|
|
|
|
func_dict,
|
2023-05-15 11:02:42 +02:00
|
|
|
func,
|
|
|
|
False,
|
2021-01-14 21:13:23 -06:00
|
|
|
args.function_signature,
|
update_test_checks: match IR basic block labels (#88979)
Labels are matched using a regexp of the form '^(pattern):', which
requires the addition of a "suffix" concept to NamelessValue.
Aside from that, the key challenge is that block labels are values, and
we typically capture values including the prefix '%'. However, when
labels appear at the start of a basic block, the prefix '%' is not
included, so we must capture block label values *without* the prefix
'%'.
We don't know ahead of time whether an IR value is a label or not. In
most cases, they are prefixed by the word "label" (their type), but this
isn't the case in phi nodes. We solve this issue by leveraging the
two-phase nature of variable generalization: the first pass finds all
occurences of a variable and determines whether the '%' prefix can be
included or not. The second pass does the actual substitution.
This change also unifies the generalization path for assembly with that
for IR and analysis, in the hope that any future changes avoid diverging
those cases future.
I also considered the alternative of trying to detect the phi node case
using more regular expression special cases but ultimately decided
against that because it seemed more fragile, and perhaps the approach of
keeping a tentative prefix that may later be discarded could also be
eventually applied to some metadata and attribute cases.
Note that an early version of this change was reviewed as
https://reviews.llvm.org/D142452, before version numbers were
introduced. This is a substantially updated version of that change.
2024-05-19 01:39:47 +02:00
|
|
|
ginfo,
|
2021-01-14 21:13:23 -06:00
|
|
|
global_vars_seen_dict,
|
|
|
|
is_filtered=builder.is_filtered(),
|
2023-11-23 06:46:07 +01:00
|
|
|
original_check_lines=original_check_lines.get(func, {}),
|
2023-05-15 11:02:42 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
2022-11-28 10:02:14 -08:00
|
|
|
# "Normal" mode.
|
2024-02-28 17:08:36 -08:00
|
|
|
dropped_previous_line = False
|
2022-11-28 10:02:14 -08:00
|
|
|
for input_line_info in ti.iterlines(output_lines):
|
|
|
|
input_line = input_line_info.line
|
2020-01-13 12:16:35 -06:00
|
|
|
args = input_line_info.args
|
|
|
|
if is_in_function_start:
|
|
|
|
if input_line == "":
|
2023-05-15 11:02:42 +02:00
|
|
|
continue
|
2022-11-28 10:02:14 -08:00
|
|
|
if input_line.lstrip().startswith(";"):
|
|
|
|
m = common.CHECK_RE.match(input_line)
|
2020-01-13 12:16:35 -06:00
|
|
|
if not m or m.group(1) not in prefix_set:
|
2022-11-28 10:02:14 -08:00
|
|
|
output_lines.append(input_line)
|
2023-05-15 11:02:42 +02:00
|
|
|
continue
|
|
|
|
|
2022-11-28 10:02:14 -08:00
|
|
|
# Print out the various check lines here.
|
|
|
|
generated_prefixes.extend(
|
|
|
|
common.add_ir_checks(
|
|
|
|
output_lines,
|
2023-05-15 11:02:42 +02:00
|
|
|
";",
|
2022-11-28 10:02:14 -08:00
|
|
|
prefix_list,
|
|
|
|
func_dict,
|
|
|
|
func_name,
|
|
|
|
args.preserve_names,
|
|
|
|
args.function_signature,
|
update_test_checks: match IR basic block labels (#88979)
Labels are matched using a regexp of the form '^(pattern):', which
requires the addition of a "suffix" concept to NamelessValue.
Aside from that, the key challenge is that block labels are values, and
we typically capture values including the prefix '%'. However, when
labels appear at the start of a basic block, the prefix '%' is not
included, so we must capture block label values *without* the prefix
'%'.
We don't know ahead of time whether an IR value is a label or not. In
most cases, they are prefixed by the word "label" (their type), but this
isn't the case in phi nodes. We solve this issue by leveraging the
two-phase nature of variable generalization: the first pass finds all
occurences of a variable and determines whether the '%' prefix can be
included or not. The second pass does the actual substitution.
This change also unifies the generalization path for assembly with that
for IR and analysis, in the hope that any future changes avoid diverging
those cases future.
I also considered the alternative of trying to detect the phi node case
using more regular expression special cases but ultimately decided
against that because it seemed more fragile, and perhaps the approach of
keeping a tentative prefix that may later be discarded could also be
eventually applied to some metadata and attribute cases.
Note that an early version of this change was reviewed as
https://reviews.llvm.org/D142452, before version numbers were
introduced. This is a substantially updated version of that change.
2024-05-19 01:39:47 +02:00
|
|
|
ginfo,
|
2022-11-28 10:02:14 -08:00
|
|
|
global_vars_seen_dict,
|
|
|
|
is_filtered=builder.is_filtered(),
|
2023-11-23 06:46:07 +01:00
|
|
|
original_check_lines=original_check_lines.get(
|
|
|
|
func_name, {}
|
|
|
|
),
|
2022-11-28 10:02:14 -08:00
|
|
|
)
|
2023-05-15 11:02:42 +02:00
|
|
|
)
|
2022-11-28 10:02:14 -08:00
|
|
|
is_in_function_start = False
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2020-01-13 12:16:35 -06:00
|
|
|
m = common.IR_FUNCTION_RE.match(input_line)
|
|
|
|
if m and not has_checked_pre_function_globals:
|
2022-11-28 10:02:14 -08:00
|
|
|
if args.check_globals:
|
|
|
|
generated_prefixes.extend(
|
|
|
|
common.add_global_checks(
|
|
|
|
builder.global_var_dict(),
|
2023-05-15 11:02:42 +02:00
|
|
|
";",
|
2022-11-28 10:02:14 -08:00
|
|
|
prefix_list,
|
|
|
|
output_lines,
|
update_test_checks: match IR basic block labels (#88979)
Labels are matched using a regexp of the form '^(pattern):', which
requires the addition of a "suffix" concept to NamelessValue.
Aside from that, the key challenge is that block labels are values, and
we typically capture values including the prefix '%'. However, when
labels appear at the start of a basic block, the prefix '%' is not
included, so we must capture block label values *without* the prefix
'%'.
We don't know ahead of time whether an IR value is a label or not. In
most cases, they are prefixed by the word "label" (their type), but this
isn't the case in phi nodes. We solve this issue by leveraging the
two-phase nature of variable generalization: the first pass finds all
occurences of a variable and determines whether the '%' prefix can be
included or not. The second pass does the actual substitution.
This change also unifies the generalization path for assembly with that
for IR and analysis, in the hope that any future changes avoid diverging
those cases future.
I also considered the alternative of trying to detect the phi node case
using more regular expression special cases but ultimately decided
against that because it seemed more fragile, and perhaps the approach of
keeping a tentative prefix that may later be discarded could also be
eventually applied to some metadata and attribute cases.
Note that an early version of this change was reviewed as
https://reviews.llvm.org/D142452, before version numbers were
introduced. This is a substantially updated version of that change.
2024-05-19 01:39:47 +02:00
|
|
|
ginfo,
|
2022-11-28 10:02:14 -08:00
|
|
|
global_vars_seen_dict,
|
|
|
|
args.preserve_names,
|
2023-05-15 11:02:42 +02:00
|
|
|
True,
|
2023-11-13 14:45:27 +01:00
|
|
|
args.check_globals,
|
2023-05-15 11:02:42 +02:00
|
|
|
)
|
|
|
|
)
|
2022-11-28 10:02:14 -08:00
|
|
|
has_checked_pre_function_globals = True
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2022-10-20 11:33:49 +02:00
|
|
|
if common.should_add_line_to_output(
|
2024-02-28 17:08:36 -08:00
|
|
|
input_line,
|
|
|
|
prefix_set,
|
|
|
|
skip_global_checks=not is_in_function,
|
|
|
|
skip_same_checks=dropped_previous_line,
|
2023-05-15 11:02:42 +02:00
|
|
|
):
|
2022-11-28 10:02:14 -08:00
|
|
|
# This input line of the function body will go as-is into the output.
|
2020-01-13 12:16:35 -06:00
|
|
|
# Except make leading whitespace uniform: 2 spaces.
|
2019-10-10 20:32:04 -05:00
|
|
|
input_line = common.SCRUB_LEADING_WHITESPACE_RE.sub(
|
2020-01-13 12:16:35 -06:00
|
|
|
r" ", input_line
|
2023-05-15 11:02:42 +02:00
|
|
|
)
|
2020-01-13 12:16:35 -06:00
|
|
|
output_lines.append(input_line)
|
2024-02-28 17:08:36 -08:00
|
|
|
dropped_previous_line = False
|
2020-01-13 12:16:35 -06:00
|
|
|
if input_line.strip() == "}":
|
2016-03-24 23:19:26 +00:00
|
|
|
is_in_function = False
|
2020-01-13 12:16:35 -06:00
|
|
|
continue
|
2024-02-28 17:08:36 -08:00
|
|
|
else:
|
|
|
|
# If we are removing a check line, and the next line is CHECK-SAME, it MUST also be removed
|
|
|
|
dropped_previous_line = True
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2021-01-14 21:13:23 -06:00
|
|
|
if is_in_function:
|
2023-05-15 11:02:42 +02:00
|
|
|
continue
|
|
|
|
|
2021-01-14 21:13:23 -06:00
|
|
|
m = common.IR_FUNCTION_RE.match(input_line)
|
2023-05-15 11:02:42 +02:00
|
|
|
if not m:
|
|
|
|
continue
|
2020-01-13 12:16:35 -06:00
|
|
|
func_name = m.group(1)
|
|
|
|
if args.function is not None and func_name != args.function:
|
|
|
|
# When filtering on a specific function, skip all others.
|
|
|
|
continue
|
|
|
|
is_in_function = is_in_function_start = True
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2023-11-13 14:45:27 +01:00
|
|
|
if args.check_globals != 'none':
|
2022-11-28 10:02:14 -08:00
|
|
|
generated_prefixes.extend(
|
|
|
|
common.add_global_checks(
|
|
|
|
builder.global_var_dict(),
|
|
|
|
";",
|
|
|
|
prefix_list,
|
|
|
|
output_lines,
|
update_test_checks: match IR basic block labels (#88979)
Labels are matched using a regexp of the form '^(pattern):', which
requires the addition of a "suffix" concept to NamelessValue.
Aside from that, the key challenge is that block labels are values, and
we typically capture values including the prefix '%'. However, when
labels appear at the start of a basic block, the prefix '%' is not
included, so we must capture block label values *without* the prefix
'%'.
We don't know ahead of time whether an IR value is a label or not. In
most cases, they are prefixed by the word "label" (their type), but this
isn't the case in phi nodes. We solve this issue by leveraging the
two-phase nature of variable generalization: the first pass finds all
occurences of a variable and determines whether the '%' prefix can be
included or not. The second pass does the actual substitution.
This change also unifies the generalization path for assembly with that
for IR and analysis, in the hope that any future changes avoid diverging
those cases future.
I also considered the alternative of trying to detect the phi node case
using more regular expression special cases but ultimately decided
against that because it seemed more fragile, and perhaps the approach of
keeping a tentative prefix that may later be discarded could also be
eventually applied to some metadata and attribute cases.
Note that an early version of this change was reviewed as
https://reviews.llvm.org/D142452, before version numbers were
introduced. This is a substantially updated version of that change.
2024-05-19 01:39:47 +02:00
|
|
|
ginfo,
|
2022-11-28 10:02:14 -08:00
|
|
|
global_vars_seen_dict,
|
|
|
|
args.preserve_names,
|
|
|
|
False,
|
2023-11-13 14:45:27 +01:00
|
|
|
args.check_globals,
|
2022-11-28 10:02:14 -08:00
|
|
|
)
|
2023-05-15 11:02:42 +02:00
|
|
|
)
|
2022-11-28 10:02:14 -08:00
|
|
|
if ti.args.gen_unused_prefix_body:
|
|
|
|
output_lines.extend(
|
|
|
|
ti.get_checks_for_unused_prefixes(prefix_list, generated_prefixes)
|
|
|
|
)
|
2020-07-07 16:38:28 +01:00
|
|
|
common.debug("Writing %d lines to %s..." % (len(output_lines), ti.path))
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2020-07-07 16:38:28 +01:00
|
|
|
with open(ti.path, "wb") as f:
|
2019-01-30 16:15:59 +00:00
|
|
|
f.writelines(["{}\n".format(l).encode("utf-8") for l in output_lines])
|
2023-05-15 11:02:42 +02:00
|
|
|
|
|
|
|
|
2016-03-24 23:19:26 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|