[llvm] eadd166 - update_analyze_test_checks.py: fix UTC_ARGS handling
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 7 07:22:34 PST 2022
Author: Roman Lebedev
Date: 2022-03-07T18:22:19+03:00
New Revision: eadd1668d05df582281061460089562cfb6b3a90
URL: https://github.com/llvm/llvm-project/commit/eadd1668d05df582281061460089562cfb6b3a90
DIFF: https://github.com/llvm/llvm-project/commit/eadd1668d05df582281061460089562cfb6b3a90.diff
LOG: update_analyze_test_checks.py: fix UTC_ARGS handling
They should be both used if provided in the input test
and manifested in the updated test.
Added:
Modified:
llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-filter.ll
llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-filter.ll.filter.expected
llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/filter.test
llvm/utils/update_analyze_test_checks.py
Removed:
################################################################################
diff --git a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-filter.ll b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-filter.ll
index 24c5be28692d7..ff8e748e800ca 100644
--- a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-filter.ll
+++ b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-filter.ll
@@ -1,4 +1,3 @@
-; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
; RUN: opt < %s -passes='print<cost-model>' -mtriple=x86_64-pc-linux-gnu 2>&1 -disable-output -mattr=+sse2 | FileCheck %s --check-prefixes=SSE2
define void @replication_i64_stride2() nounwind {
diff --git a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-filter.ll.filter.expected b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-filter.ll.filter.expected
index fd0d0a47bd870..15f17b4420e94 100644
--- a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-filter.ll.filter.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-filter.ll.filter.expected
@@ -1,4 +1,4 @@
-; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --filter "(vf4|vf16)"
; RUN: opt < %s -passes='print<cost-model>' -mtriple=x86_64-pc-linux-gnu 2>&1 -disable-output -mattr=+sse2 | FileCheck %s --check-prefixes=SSE2
define void @replication_i64_stride2() nounwind {
diff --git a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/filter.test b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/filter.test
index 0be97d5d9e75d..7188090736a1e 100644
--- a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/filter.test
+++ b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/filter.test
@@ -7,3 +7,7 @@
## Check that running the script again does not change the result:
# RUN: %update_analyze_test_checks --filter="(vf4|vf16)" %t.ll
# RUN:
diff -u %t.ll %S/Inputs/x86-filter.ll.filter.expected
+
+## Check that running the script again, without arguments, does not change the result:
+# RUN: %update_analyze_test_checks %t.ll
+# RUN:
diff -u %t.ll %S/Inputs/x86-filter.ll.filter.expected
diff --git a/llvm/utils/update_analyze_test_checks.py b/llvm/utils/update_analyze_test_checks.py
index 15708e52c133c..4bdba7e8fbdde 100755
--- a/llvm/utils/update_analyze_test_checks.py
+++ b/llvm/utils/update_analyze_test_checks.py
@@ -32,19 +32,12 @@
from __future__ import print_function
import argparse
-import glob
-import itertools
import os # Used to advertise this file's name ("autogenerated_note").
-import string
-import subprocess
import sys
-import tempfile
import re
from UpdateTestChecks import common
-ADVERT = '; NOTE: Assertions have been autogenerated by '
-
def main():
from argparse import RawTextHelpFormatter
parser = argparse.ArgumentParser(description=__doc__, formatter_class=RawTextHelpFormatter)
@@ -53,34 +46,26 @@ def main():
parser.add_argument(
'--function', help='The function in the test file to update')
parser.add_argument('tests', nargs='+')
- args = common.parse_commandline_args(parser)
+ initial_args = common.parse_commandline_args(parser)
script_name = os.path.basename(__file__)
- autogenerated_note = (ADVERT + 'utils/' + script_name)
- opt_basename = os.path.basename(args.opt_binary)
+ opt_basename = os.path.basename(initial_args.opt_binary)
if (opt_basename != "opt"):
common.error('Unexpected opt name: ' + opt_basename)
sys.exit(1)
- test_paths = [test for pattern in args.tests for test in glob.glob(pattern)]
- for test in test_paths:
- with open(test) as f:
- input_lines = [l.rstrip() for l in f]
-
- first_line = input_lines[0] if input_lines else ""
- if 'autogenerated' in first_line and script_name not in first_line:
- common.warn("Skipping test which wasn't autogenerated by " + script_name + ": " + test)
- continue
-
- if args.update_only:
- if not first_line or 'autogenerated' not in first_line:
- common.warn("Skipping test which isn't autogenerated: " + test)
- continue
+ for ti in common.itertests(initial_args.tests, parser,
+ script_name='utils/' + script_name):
+ triple_in_ir = None
+ for l in ti.input_lines:
+ m = common.TRIPLE_IR_RE.match(l)
+ if m:
+ triple_in_ir = m.groups()[0]
+ break
- run_lines = common.find_run_lines(test, input_lines)
prefix_list = []
- for l in run_lines:
+ for l in ti.run_lines:
if '|' not in l:
common.warn('Skipping unparseable RUN line: ' + l)
continue
@@ -111,19 +96,19 @@ def main():
builder = common.FunctionTestBuilder(
run_list = prefix_list,
flags = type('', (object,), {
- 'verbose': args.verbose,
- 'filters': args.filters,
+ 'verbose': ti.args.verbose,
+ 'filters': ti.args.filters,
'function_signature': False,
'check_attributes': False,
'replace_value_regex': []}),
scrubber_args = [],
- path=test)
+ path=ti.path)
for prefixes, opt_args in prefix_list:
common.debug('Extracted opt cmd:', opt_basename, opt_args, file=sys.stderr)
common.debug('Extracted FileCheck prefixes:', str(prefixes), file=sys.stderr)
- raw_tool_outputs = common.invoke_tool(args.opt_binary, opt_args, test)
+ raw_tool_outputs = common.invoke_tool(ti.args.opt_binary, opt_args, ti.path)
# Split analysis outputs by "Printing analysis " declarations.
for raw_tool_output in re.split(r'Printing analysis ', raw_tool_outputs):
@@ -136,9 +121,10 @@ def main():
prefix_set = set([prefix for prefixes, _ in prefix_list for prefix in prefixes])
common.debug('Rewriting FileCheck prefixes:', str(prefix_set), file=sys.stderr)
output_lines = []
- output_lines.append(autogenerated_note)
- for input_line in input_lines:
+ for input_info in ti.iterlines(output_lines):
+ input_line = input_info.line
+ args = input_info.args
if is_in_function_start:
if input_line == '':
continue
@@ -165,10 +151,6 @@ def main():
is_in_function = False
continue
- # Discard any previous script advertising.
- if input_line.startswith(ADVERT):
- continue
-
# If it's outside a function, it just gets copied to the output.
output_lines.append(input_line)
@@ -176,14 +158,14 @@ def main():
if not m:
continue
func_name = m.group(1)
- if args.function is not None and func_name != args.function:
+ if ti.args.function is not None and func_name != ti.args.function:
# When filtering on a specific function, skip all others.
continue
is_in_function = is_in_function_start = True
- common.debug('Writing %d lines to %s...' % (len(output_lines), test))
+ common.debug('Writing %d lines to %s...' % (len(output_lines), ti.path))
- with open(test, 'wb') as f:
+ with open(ti.path, 'wb') as f:
f.writelines(['{}\n'.format(l).encode('utf-8') for l in output_lines])
More information about the llvm-commits
mailing list