Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 41 additions & 43 deletions llvm/utils/update_mca_test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _showwarning(message, category, filename, lineno, file=None, line=None):
file.write(warnings.formatwarning(message, category, filename, lineno, line))


def _parse_args():
def _get_parser():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("-w", action="store_true", help="suppress warnings")
parser.add_argument(
Expand All @@ -65,18 +65,7 @@ def _parse_args():
help="the binary to use to generate the test case " "(default: llvm-mca)",
)
parser.add_argument("tests", metavar="<test-path>", nargs="+")
args = common.parse_commandline_args(parser)

_configure_warnings(args)

if not args.llvm_mca_binary:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also preserve the checks from line 72 to 76

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, but moved to main since parse_commandline_args is called in main.

raise Error("--llvm-mca-binary value cannot be empty string")

if "llvm-mca" not in os.path.basename(args.llvm_mca_binary):
_warn("unexpected binary name: {}".format(args.llvm_mca_binary))

return args

return parser

def _get_run_infos(run_lines, args):
run_infos = []
Expand Down Expand Up @@ -546,39 +535,48 @@ def _write_output(
f.writelines(["{}\n".format(l).encode("utf-8") for l in output_lines])


def update_test_file(args, test_path, autogenerated_note):
sys.stderr.write("Test: {}\n".format(test_path))

# Call this per test. By default each warning will only be written once
# per source location. Reset the warning filter so that now each warning
# will be written once per source location per test.
_configure_warnings(args)

with open(test_path) as f:
input_lines = [l.rstrip() for l in f]

run_lines = common.find_run_lines(test_path, input_lines)
run_infos = _get_run_infos(run_lines, args)
common_prefix, prefix_pad = _get_useful_prefix_info(run_infos)
block_infos = _get_block_infos(run_infos, test_path, args, common_prefix)
_write_output(
test_path,
input_lines,
run_infos,
block_infos,
args,
common_prefix,
prefix_pad,
)

def main():
args = _parse_args()
test_paths = [test for pattern in args.tests for test in glob.glob(pattern)]
for test_path in test_paths:
sys.stderr.write("Test: {}\n".format(test_path))

# Call this per test. By default each warning will only be written once
# per source location. Reset the warning filter so that now each warning
# will be written once per source location per test.
_configure_warnings(args)

if not os.path.isfile(test_path):
raise Error("could not find test file: {}".format(test_path))

with open(test_path) as f:
input_lines = [l.rstrip() for l in f]

run_lines = common.find_run_lines(test_path, input_lines)
run_infos = _get_run_infos(run_lines, args)
common_prefix, prefix_pad = _get_useful_prefix_info(run_infos)
block_infos = _get_block_infos(run_infos, test_path, args, common_prefix)
_write_output(
test_path,
input_lines,
run_infos,
block_infos,
args,
common_prefix,
prefix_pad,
)
script_name = "utils/" + os.path.basename(__file__)
parser = _get_parser()
args = common.parse_commandline_args(parser)
if not args.llvm_mca_binary:
raise Error("--llvm-mca-binary value cannot be empty string")

return 0
if "llvm-mca" not in os.path.basename(args.llvm_mca_binary):
_warn("unexpected binary name: {}".format(args.llvm_mca_binary))

for ti in common.itertests(args.tests, parser, script_name=script_name):
try:
update_test_file(ti.args, ti.path, ti.test_autogenerated_note)
except Exception:
common.warn("Error processing file", test_file=ti.path)
raise
return 0

if __name__ == "__main__":
try:
Expand Down