diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py --- a/llvm/utils/UpdateTestChecks/common.py +++ b/llvm/utils/UpdateTestChecks/common.py @@ -2,6 +2,7 @@ import copy import glob +import os import re import subprocess import sys @@ -127,11 +128,23 @@ return True # Invoke the tool that is being tested. -def invoke_tool(exe, cmd_args, ir): +def invoke_tool(exe, cmd_args, ir, preprocess_cmd=None, verbose=False): with open(ir) as ir_file: # TODO Remove the str form which is used by update_test_checks.py and # update_llc_test_checks.py # The safer list form is used by update_cc_test_checks.py + if preprocess_cmd: + # Allow pre-processing the IR file (e.g. using sed): + assert isinstance(preprocess_cmd, str) # TODO: use a list instead of using shell + preprocess_cmd = preprocess_cmd.replace('%s', ir).strip() + if verbose: + print('Pre-processing ir_file: ', ir, " with command '", + preprocess_cmd, "'", sep="", file=sys.stderr) + # Python 2.7 doesn't have subprocess.DEVNULL: + with open(os.devnull, 'w') as devnull: + pp = subprocess.Popen(preprocess_cmd, shell=True, stdin=devnull, + stdout=subprocess.PIPE) + ir_file = pp.stdout if isinstance(cmd_args, list): stdout = subprocess.check_output([exe] + cmd_args, stdin=ir_file) else: diff --git a/llvm/utils/update_test_checks.py b/llvm/utils/update_test_checks.py --- a/llvm/utils/update_test_checks.py +++ b/llvm/utils/update_test_checks.py @@ -78,7 +78,13 @@ common.warn('Skipping unparseable RUN line: ' + l) continue - (tool_cmd, filecheck_cmd) = tuple([cmd.strip() for cmd in l.split('|', 1)]) + commands = [cmd.strip() for cmd in l.split('|')] + assert len(commands) >= 2 + preprocess_cmd = None + if len(commands) > 2: + preprocess_cmd = " | ".join(commands[:-2]) + tool_cmd = commands[-2] + filecheck_cmd = commands[-1] common.verify_filecheck_prefixes(filecheck_cmd) if not tool_cmd.startswith(opt_basename + ' '): common.warn('Skipping non-%s RUN line: %s' % (opt_basename, l)) @@ -99,7 +105,7 @@ # 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)) + prefix_list.append((check_prefixes, tool_cmd_args, preprocess_cmd)) global_vars_seen_dict = {} builder = common.FunctionTestBuilder( @@ -107,19 +113,20 @@ flags=ti.args, scrubber_args=[]) - for prefixes, opt_args in prefix_list: + for prefixes, opt_args, preprocess_cmd in prefix_list: common.debug('Extracted opt cmd: ' + opt_basename + ' ' + opt_args) common.debug('Extracted FileCheck prefixes: ' + str(prefixes)) - raw_tool_output = common.invoke_tool(ti.args.opt_binary, opt_args, - ti.path) + raw_tool_output = common.invoke_tool(ti.args.opt_binary, opt_args, + ti.path, preprocess_cmd=preprocess_cmd, + verbose=ti.args.verbose) builder.process_run_line(common.OPT_FUNCTION_RE, common.scrub_body, raw_tool_output, prefixes) func_dict = builder.finish_and_get_func_dict() is_in_function = False is_in_function_start = False - prefix_set = set([prefix for prefixes, _ in prefix_list for prefix in prefixes]) + prefix_set = set([prefix for prefixes, _, _ in prefix_list for prefix in prefixes]) common.debug('Rewriting FileCheck prefixes:', str(prefix_set)) output_lines = []