[llvm] r374287 - [update_cc_test_checks] Support 'clang | opt | FileCheck'
Simon Tatham via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 10 01:25:35 PDT 2019
Author: statham
Date: Thu Oct 10 01:25:34 2019
New Revision: 374287
URL: http://llvm.org/viewvc/llvm-project?rev=374287&view=rev
Log:
[update_cc_test_checks] Support 'clang | opt | FileCheck'
Some clang lit tests use a pipeline of the form
// RUN: %clang [args] -O0 %s | opt [specific optimizations] | FileCheck %s
to make the expected test output depend on as few optimization phases
as possible, for stability. But when you write a RUN line of this
form, you lose the ability to use update_cc_test_checks.py to
automatically generate the expected output, because it only supports
two-stage pipelines consisting of '%clang | FileCheck' (or %clang_cc1).
This change extends the set of supported RUN lines so that pipelines
with an invocation of `opt` in the middle can still be automatically
handled.
To implement it, I've adjusted `get_function_body()` so that it can
cope with an arbitrary sequence of intermediate pipeline commands. But
the code that decides which RUN lines to consider is more
conservative: it only adds clang | opt | FileCheck to the set of
supported lines, because I didn't want to accidentally include some
other kind of line that doesn't output IR at all.
(Also in this commit is the minimal change to make this script work at
all, after r373912 added an extra parameter to `add_ir_checks`.)
Reviewers: MaskRay, xbolva00
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D68406
Modified:
llvm/trunk/utils/update_cc_test_checks.py
Modified: llvm/trunk/utils/update_cc_test_checks.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/update_cc_test_checks.py?rev=374287&r1=374286&r2=374287&view=diff
==============================================================================
--- llvm/trunk/utils/update_cc_test_checks.py (original)
+++ llvm/trunk/utils/update_cc_test_checks.py Thu Oct 10 01:25:34 2019
@@ -94,6 +94,8 @@ def config():
help='Space-separated extra args to clang, e.g. --clang-args=-v')
parser.add_argument('--c-index-test',
help='"c-index-test" executable, defaults to $llvm_bin/c-index-test')
+ parser.add_argument('--opt',
+ help='"opt" executable, defaults to $llvm_bin/opt')
parser.add_argument(
'--functions', nargs='+', help='A list of function name regexes. '
'If specified, update CHECK lines for functions matching at least one regex')
@@ -114,6 +116,18 @@ def config():
if not distutils.spawn.find_executable(args.clang):
print('Please specify --llvm-bin or --clang', file=sys.stderr)
sys.exit(1)
+
+ if args.opt is None:
+ if args.llvm_bin is None:
+ args.opt = 'opt'
+ else:
+ args.opt = os.path.join(args.llvm_bin, 'opt')
+ if not distutils.spawn.find_executable(args.opt):
+ # Many uses of this tool will not need an opt binary, because it's only
+ # needed for updating a test that runs clang | opt | FileCheck. So we
+ # defer this error message until we find that opt is actually needed.
+ args.opt = None
+
if args.c_index_test is None:
if args.llvm_bin is None:
args.c_index_test = 'c-index-test'
@@ -126,10 +140,23 @@ def config():
return args
-def get_function_body(args, filename, clang_args, prefixes, triple_in_cmd, func_dict):
+def get_function_body(args, filename, clang_args, extra_commands, prefixes, triple_in_cmd, func_dict):
# TODO Clean up duplication of asm/common build_function_body_dictionary
# Invoke external tool and extract function bodies.
raw_tool_output = common.invoke_tool(args.clang, clang_args, filename)
+ for extra_command in extra_commands:
+ extra_args = shlex.split(extra_command)
+ with tempfile.NamedTemporaryFile() as f:
+ f.write(raw_tool_output.encode())
+ f.flush()
+ if extra_args[0] == 'opt':
+ if args.opt is None:
+ print(filename, 'needs to run opt. '
+ 'Please specify --llvm-bin or --opt', file=sys.stderr)
+ sys.exit(1)
+ extra_args[0] = args.opt
+ raw_tool_output = common.invoke_tool(extra_args[0],
+ extra_args[1:], f.name)
if '-emit-llvm' in clang_args:
common.build_function_body_dictionary(
common.OPT_FUNCTION_RE, common.scrub_body, [],
@@ -178,7 +205,7 @@ def main():
run_list = []
line2spell_and_mangled_list = collections.defaultdict(list)
for l in run_lines:
- commands = [cmd.strip() for cmd in l.split('|', 1)]
+ commands = [cmd.strip() for cmd in l.split('|')]
triple_in_cmd = None
m = common.TRIPLE_ARG_RE.search(commands[0])
@@ -193,6 +220,11 @@ def main():
clang_args[0:1] = SUBST[clang_args[0]]
clang_args = [filename if i == '%s' else i for i in clang_args] + args.clang_args
+ # Permit piping the output through opt
+ if not (len(commands) == 2 or
+ (len(commands) == 3 and commands[1].startswith('opt'))):
+ print('WARNING: Skipping non-clang RUN line: ' + l, file=sys.stderr)
+
# Extract -check-prefix in FileCheck args
filecheck_cmd = commands[-1]
common.verify_filecheck_prefixes(filecheck_cmd)
@@ -203,7 +235,7 @@ def main():
for item in m.group(1).split(',')]
if not check_prefixes:
check_prefixes = ['CHECK']
- run_list.append((check_prefixes, clang_args, triple_in_cmd))
+ run_list.append((check_prefixes, clang_args, commands[1:-1], triple_in_cmd))
# Strip CHECK lines which are in `prefix_set`, update test file.
prefix_set = set([prefix for p in run_list for prefix in p[0]])
@@ -223,12 +255,12 @@ def main():
prefixes = p[0]
for prefix in prefixes:
func_dict.update({prefix: dict()})
- for prefixes, clang_args, triple_in_cmd in run_list:
+ for prefixes, clang_args, extra_commands, triple_in_cmd in run_list:
if args.verbose:
print('Extracted clang cmd: clang {}'.format(clang_args), file=sys.stderr)
print('Extracted FileCheck prefixes: {}'.format(prefixes), file=sys.stderr)
- get_function_body(args, filename, clang_args, prefixes, triple_in_cmd, func_dict)
+ get_function_body(args, filename, clang_args, extra_commands, prefixes, triple_in_cmd, func_dict)
# Invoke c-index-test to get mapping from start lines to mangled names.
# Forward all clang args for now.
@@ -254,7 +286,7 @@ def main():
if added:
output_lines.append('//')
added.add(mangled)
- common.add_ir_checks(output_lines, '//', run_list, func_dict, mangled)
+ common.add_ir_checks(output_lines, '//', run_list, func_dict, mangled, False)
output_lines.append(line.rstrip('\n'))
# Update the test file.
More information about the llvm-commits
mailing list