Index: llvm/trunk/utils/UpdateTestChecks/common.py =================================================================== --- llvm/trunk/utils/UpdateTestChecks/common.py +++ llvm/trunk/utils/UpdateTestChecks/common.py @@ -72,6 +72,17 @@ SCRUB_LOOP_COMMENT_RE = re.compile( r'# =>This Inner Loop Header:.*|# in Loop:.*', flags=re.M) + +def error(msg, test_file=None): + if test_file: + msg = '{}: {}'.format(msg, test_file) + print('ERROR: {}'.format(msg), file=sys.stderr) + +def warn(msg, test_file=None): + if test_file: + msg = '{}: {}'.format(msg, test_file) + print('WARNING: {}'.format(msg), file=sys.stderr) + def scrub_body(body): # Scrub runs of whitespace out of the assembly, but leave the leading # whitespace in place. @@ -108,7 +119,7 @@ if 'analysis' in m.groupdict(): analysis = m.group('analysis') if analysis.lower() != 'cost model analysis': - print('WARNING: Unsupported analysis mode: %r!' % (analysis,), file=sys.stderr) + warn('Unsupported analysis mode: %r!' % (analysis,)) if func.startswith('stress'): # We only use the last line of the function body for stress tests. scrubbed_body = '\n'.join(scrubbed_body.splitlines()[-1:]) @@ -123,8 +134,7 @@ continue else: if prefix == prefixes[-1]: - print('WARNING: Found conflicting asm under the ' - 'same prefix: %r!' % (prefix,), file=sys.stderr) + warn('Found conflicting asm under the same prefix: %r!' % (prefix,)) else: func_dict[prefix][func] = None continue @@ -272,8 +282,8 @@ hint = "" if ',' in prefix: hint = " Did you mean '--check-prefixes=" + prefix + "'?" - print(("WARNING: Supplied prefix '%s' is invalid. Prefix must contain only alphanumeric characters, hyphens and underscores." + hint) % - (prefix), file=sys.stderr) + warn(("Supplied prefix '%s' is invalid. Prefix must contain only alphanumeric characters, hyphens and underscores." + hint) % + (prefix)) def verify_filecheck_prefixes(fc_cmd): @@ -287,5 +297,4 @@ for prefix in prefixes: check_prefix(prefix) if prefixes.count(prefix) > 1: - print("WARNING: Supplied prefix '%s' is not unique in the prefix list." % - (prefix,), file=sys.stderr) + warn("Supplied prefix '%s' is not unique in the prefix list." % (prefix,)) Index: llvm/trunk/utils/update_analyze_test_checks.py =================================================================== --- llvm/trunk/utils/update_analyze_test_checks.py +++ llvm/trunk/utils/update_analyze_test_checks.py @@ -58,14 +58,17 @@ help='The opt binary used to generate the test case') parser.add_argument( '--function', help='The function in the test file to update') + parser.add_argument('-u', '--update-only', action='store_true', + help='Only update test if it was already autogened') parser.add_argument('tests', nargs='+') args = parser.parse_args() - autogenerated_note = (ADVERT + 'utils/' + os.path.basename(__file__)) + script_name = os.path.basename(__file__) + autogenerated_note = (ADVERT + 'utils/' + script_name) opt_basename = os.path.basename(args.opt_binary) if (opt_basename != "opt"): - print('ERROR: Unexpected opt name: ' + opt_basename, file=sys.stderr) + common.error('Unexpected opt name: ' + opt_basename) sys.exit(1) test_paths = [test for pattern in args.tests for test in glob.glob(pattern)] @@ -75,6 +78,16 @@ 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 + raw_lines = [m.group(1) for m in [common.RUN_LINE_RE.match(l) for l in input_lines] if m] run_lines = [raw_lines[0]] if len(raw_lines) > 0 else [] @@ -91,15 +104,19 @@ prefix_list = [] for l in run_lines: + if '|' not in l: + common.warn('Skipping unparseable RUN line: ' + l) + continue + (tool_cmd, filecheck_cmd) = tuple([cmd.strip() for cmd in l.split('|', 1)]) common.verify_filecheck_prefixes(filecheck_cmd) if not tool_cmd.startswith(opt_basename + ' '): - print('WARNING: Skipping non-%s RUN line: %s' % (opt_basename, l), file=sys.stderr) + common.warn('WSkipping non-%s RUN line: %s' % (opt_basename, l)) continue if not filecheck_cmd.startswith('FileCheck '): - print('WARNING: Skipping non-FileChecked RUN line: ' + l, file=sys.stderr) + common.warn('Skipping non-FileChecked RUN line: ' + l) continue tool_cmd_args = tool_cmd[len(opt_basename):].strip() Index: llvm/trunk/utils/update_cc_test_checks.py =================================================================== --- llvm/trunk/utils/update_cc_test_checks.py +++ llvm/trunk/utils/update_cc_test_checks.py @@ -86,6 +86,8 @@ parser.add_argument( '--x86_extra_scrub', action='store_true', help='Use more regex for x86 matching to reduce diffs between various subtargets') + parser.add_argument('-u', '--update-only', action='store_true', + help='Only update test if it was already autogened') parser.add_argument('tests', nargs='+') args = parser.parse_args() args.clang_args = shlex.split(args.clang_args or '') @@ -126,11 +128,22 @@ def main(): args = config() - autogenerated_note = (ADVERT + 'utils/' + os.path.basename(__file__)) + script_name = os.path.basename(__file__) + autogenerated_note = (ADVERT + 'utils/' + script_name) for filename in args.tests: with open(filename) 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, filename) + continue + + if args.update_only: + if not first_line or 'autogenerated' not in first_line: + common.warn("Skipping test which isn't autogenerated: " + filename) + continue # Extract RUN lines. raw_lines = [m.group(1) Index: llvm/trunk/utils/update_llc_test_checks.py =================================================================== --- llvm/trunk/utils/update_llc_test_checks.py +++ llvm/trunk/utils/update_llc_test_checks.py @@ -38,10 +38,13 @@ help='Use more regex for x86 matching to reduce diffs between various subtargets') parser.add_argument( '--no_x86_scrub_rip', action='store_false', dest='x86_scrub_rip') + parser.add_argument('-u', '--update-only', action='store_true', + help='Only update test if it was already autogened') parser.add_argument('tests', nargs='+') args = parser.parse_args() - autogenerated_note = (ADVERT + 'utils/' + os.path.basename(__file__)) + script_name = os.path.basename(__file__) + autogenerated_note = (ADVERT + 'utils/' + script_name) test_paths = [test for pattern in args.tests for test in glob.glob(pattern)] for test in test_paths: @@ -49,6 +52,16 @@ print('Scanning for RUN lines in test file: %s' % (test,), file=sys.stderr) 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 triple_in_ir = None for l in input_lines: @@ -73,6 +86,10 @@ run_list = [] for l in run_lines: + if '|' not in l: + common.warn('Skipping unparseable RUN line: ' + l) + continue + commands = [cmd.strip() for cmd in l.split('|', 1)] llc_cmd = commands[0] @@ -91,11 +108,11 @@ filecheck_cmd = commands[1] common.verify_filecheck_prefixes(filecheck_cmd) if not llc_cmd.startswith('llc '): - print('WARNING: Skipping non-llc RUN line: ' + l, file=sys.stderr) + common.warn('Skipping non-llc RUN line: ' + l) continue if not filecheck_cmd.startswith('FileCheck '): - print('WARNING: Skipping non-FileChecked RUN line: ' + l, file=sys.stderr) + common.warn('Skipping non-FileChecked RUN line: ' + l) continue llc_cmd_args = llc_cmd[len('llc'):].strip() Index: llvm/trunk/utils/update_mir_test_checks.py =================================================================== --- llvm/trunk/utils/update_mir_test_checks.py +++ llvm/trunk/utils/update_mir_test_checks.py @@ -85,12 +85,6 @@ print(msg, file=sys.stderr) -def warn(msg, test_file=None): - if test_file: - msg = '{}: {}'.format(test_file, msg) - print('WARNING: {}'.format(msg), file=sys.stderr) - - def find_triple_in_ir(lines, verbose=False): for l in lines: m = common.TRIPLE_IR_RE.match(l) @@ -119,16 +113,20 @@ run_list = [] all_prefixes = [] for l in run_lines: + if '|' not in l: + common.warn('Skipping unparseable RUN line: ' + l) + continue + commands = [cmd.strip() for cmd in l.split('|', 1)] llc_cmd = commands[0] filecheck_cmd = commands[1] if len(commands) > 1 else '' common.verify_filecheck_prefixes(filecheck_cmd) if not llc_cmd.startswith('llc '): - warn('Skipping non-llc RUN line: {}'.format(l), test_file=test) + common.warn('Skipping non-llc RUN line: {}'.format(l), test_file=test) continue if not filecheck_cmd.startswith('FileCheck '): - warn('Skipping non-FileChecked RUN line: {}'.format(l), + common.warn('Skipping non-FileChecked RUN line: {}'.format(l), test_file=test) continue @@ -193,7 +191,7 @@ log(' {}'.format(l)) for prefix in prefixes: if func in func_dict[prefix] and func_dict[prefix][func] != body: - warn('Found conflicting asm for prefix: {}'.format(prefix), + common.warn('Found conflicting asm for prefix: {}'.format(prefix), test_file=test) func_dict[prefix][func] = body @@ -225,7 +223,7 @@ func_body.pop(0) if not func_body: - warn('Function has no instructions to check: {}'.format(func_name), + common.warn('Function has no instructions to check: {}'.format(func_name), test_file=test) return @@ -294,49 +292,60 @@ return True -def update_test_file(llc, test, remove_common_prefixes=False, verbose=False): - log('Scanning for RUN lines in test file: {}'.format(test), verbose) +def update_test_file(args, test): + log('Scanning for RUN lines in test file: {}'.format(test), args.verbose) with open(test) as fd: input_lines = [l.rstrip() for l in fd] - triple_in_ir = find_triple_in_ir(input_lines, verbose) - run_lines = find_run_lines(test, input_lines, verbose) - run_list, common_prefixes = build_run_list(test, run_lines, verbose) + script_name = os.path.basename(__file__) + 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) + return + + if args.update_only: + if not first_line or 'autogenerated' not in first_line: + common.warn("Skipping test which isn't autogenerated: " + test) + return + + triple_in_ir = find_triple_in_ir(input_lines, args.verbose) + run_lines = find_run_lines(test, input_lines, args.verbose) + run_list, common_prefixes = build_run_list(test, run_lines, args.verbose) - simple_functions = find_functions_with_one_bb(input_lines, verbose) + simple_functions = find_functions_with_one_bb(input_lines, args.verbose) func_dict = {} for run in run_list: for prefix in run.prefixes: func_dict.update({prefix: dict()}) for prefixes, llc_args, triple_in_cmd in run_list: - log('Extracted LLC cmd: llc {}'.format(llc_args), verbose) - log('Extracted FileCheck prefixes: {}'.format(prefixes), verbose) + log('Extracted LLC cmd: llc {}'.format(llc_args), args.verbose) + log('Extracted FileCheck prefixes: {}'.format(prefixes), args.verbose) - raw_tool_output = llc(llc_args, test) + raw_tool_output = args.llc(llc_args, test) if not triple_in_cmd and not triple_in_ir: - warn('No triple found: skipping file', test_file=test) + common.warn('No triple found: skipping file', test_file=test) return build_function_body_dictionary(test, raw_tool_output, triple_in_cmd or triple_in_ir, - prefixes, func_dict, verbose) + prefixes, func_dict, args.verbose) state = 'toplevel' func_name = None prefix_set = set([prefix for run in run_list for prefix in run.prefixes]) - log('Rewriting FileCheck prefixes: {}'.format(prefix_set), verbose) + log('Rewriting FileCheck prefixes: {}'.format(prefix_set), args.verbose) - if remove_common_prefixes: + if args.remove_common_prefixes: prefix_set.update(common_prefixes) elif common_prefixes: - warn('Ignoring common prefixes: {}'.format(common_prefixes), + common.warn('Ignoring common prefixes: {}'.format(common_prefixes), test_file=test) comment_char = '#' if test.endswith('.mir') else ';' autogenerated_note = ('{} NOTE: Assertions have been autogenerated by ' - 'utils/{}'.format(comment_char, - os.path.basename(__file__))) + 'utils/{}'.format(comment_char, script_name)) output_lines = [] output_lines.append(autogenerated_note) @@ -374,14 +383,14 @@ state = 'mir function body' add_checks_for_function(test, output_lines, run_list, func_dict, func_name, single_bb=False, - verbose=verbose) + verbose=args.verbose) elif state == 'mir function prefix': m = MIR_PREFIX_DATA_RE.match(input_line) if not m: state = 'mir function body' add_checks_for_function(test, output_lines, run_list, func_dict, func_name, single_bb=True, - verbose=verbose) + verbose=args.verbose) if should_add_line_to_output(input_line, prefix_set): output_lines.append(input_line) @@ -397,7 +406,7 @@ state = 'ir function body' add_checks_for_function(test, output_lines, run_list, func_dict, func_name, single_bb=False, - verbose=verbose) + verbose=args.verbose) if should_add_line_to_output(input_line, prefix_set): output_lines.append(input_line) @@ -409,7 +418,7 @@ output_lines.append(input_line) - log('Writing {} lines to {}...'.format(len(output_lines), test), verbose) + log('Writing {} lines to {}...'.format(len(output_lines), test), args.verbose) with open(test, 'wb') as fd: fd.writelines(['{}\n'.format(l).encode('utf-8') for l in output_lines]) @@ -425,16 +434,17 @@ parser.add_argument('--remove-common-prefixes', action='store_true', help='Remove existing check lines whose prefixes are ' 'shared between multiple commands') + parser.add_argument('-u', '--update-only', action='store_true', + help='Only update test if it was already autogened') parser.add_argument('tests', nargs='+') args = parser.parse_args() test_paths = [test for pattern in args.tests for test in glob.glob(pattern)] for test in test_paths: try: - update_test_file(args.llc, test, args.remove_common_prefixes, - verbose=args.verbose) + update_test_file(args, test) except Exception: - warn('Error processing file', test_file=test) + common.warn('Error processing file', test_file=test) raise Index: llvm/trunk/utils/update_test_checks.py =================================================================== --- llvm/trunk/utils/update_test_checks.py +++ llvm/trunk/utils/update_test_checks.py @@ -62,23 +62,24 @@ help='The opt binary used to generate the test case') parser.add_argument( '--function', help='The function in the test file to update') - parser.add_argument('--update-only', action='store_true', + parser.add_argument('-u', '--update-only', action='store_true', help='Only update test if it was already autogened') parser.add_argument('tests', nargs='+') args = parser.parse_args() - autogenerated_note = (ADVERT + 'utils/' + os.path.basename(__file__)) + script_name = os.path.basename(__file__) + autogenerated_note = (ADVERT + 'utils/' + script_name) opt_basename = os.path.basename(args.opt_binary) if not re.match(r'^opt(-\d+)?$', opt_basename): - print('ERROR: Unexpected opt name: ' + opt_basename, file=sys.stderr) + common.error('Unexpected opt name: ' + opt_basename) sys.exit(1) opt_basename = 'opt' test_paths = [] for test in args.tests: if not glob.glob(test): - print("WARNING: Test file '%s' was not found. Ignoring it." % (test,), file=sys.stderr) + common.warn("Test file '%s' was not found. Ignoring it." % (test,)) continue test_paths.append(test) @@ -88,9 +89,14 @@ 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 len(input_lines) == 0 or 'autogenerated' not in input_lines[0]: - print("Skipping test which isn't autogenerated: " + test, file=sys.stderr) + if not first_line or 'autogenerated' not in first_line: + common.warn("Skipping test which isn't autogenerated: " + test) continue raw_lines = [m.group(1) @@ -110,17 +116,17 @@ prefix_list = [] for l in run_lines: if '|' not in l: - print('WARNING: Skipping unparseable RUN line: ' + l, file=sys.stderr) + common.warn('Skipping unparseable RUN line: ' + l) continue (tool_cmd, filecheck_cmd) = tuple([cmd.strip() for cmd in l.split('|', 1)]) common.verify_filecheck_prefixes(filecheck_cmd) if not tool_cmd.startswith(opt_basename + ' '): - print('WARNING: Skipping non-%s RUN line: %s' % (opt_basename, l), file=sys.stderr) + common.warn('Skipping non-%s RUN line: %s' % (opt_basename, l)) continue if not filecheck_cmd.startswith('FileCheck '): - print('WARNING: Skipping non-FileChecked RUN line: ' + l, file=sys.stderr) + common.warn('Skipping non-FileChecked RUN line: ' + l) continue tool_cmd_args = tool_cmd[len(opt_basename):].strip()