[PATCH] D68406: [update_cc_test_checks] Support 'clang | opt | FileCheck'
Simon Tatham via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 3 09:37:45 PDT 2019
simon_tatham created this revision.
simon_tatham added reviewers: MaskRay, xbolva00.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D68406
Files:
llvm/utils/update_cc_test_checks.py
Index: llvm/utils/update_cc_test_checks.py
===================================================================
--- llvm/utils/update_cc_test_checks.py
+++ llvm/utils/update_cc_test_checks.py
@@ -112,10 +112,17 @@
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()
+ 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, [],
@@ -164,7 +171,7 @@
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])
@@ -179,6 +186,11 @@
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)
@@ -189,7 +201,7 @@
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]])
@@ -209,12 +221,12 @@
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68406.223044.patch
Type: text/x-patch
Size: 3151 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191003/7399b02f/attachment.bin>
More information about the llvm-commits
mailing list