diff --git a/llvm/utils/update_mir_test_checks.py b/llvm/utils/update_mir_test_checks.py --- a/llvm/utils/update_mir_test_checks.py +++ b/llvm/utils/update_mir_test_checks.py @@ -96,7 +96,7 @@ return None -def build_run_list(test, run_lines, verbose=False): +def build_run_list(test, run_lines, args): run_list = [] all_prefixes = [] for l in run_lines: @@ -142,8 +142,23 @@ # Remove any common prefixes. We'll just leave those entirely alone. common_prefixes = set([prefix for prefix in all_prefixes if all_prefixes.count(prefix) > 1]) - for run in run_list: - run.prefixes = [p for p in run.prefixes if p not in common_prefixes] + + # ...unless we're told to use the first one we see, ignoring the rest. + used_prefixes = set() + if args.use_first_common_prefix: + for run in run_list: + filtered_prefixes = [] + for p in run.prefixes: + if p in common_prefixes: + if p not in used_prefixes: + filtered_prefixes.append(p) + used_prefixes.add(p) + else: + filtered_prefixes.append(p) + run.prefixes = filtered_prefixes + else: + for run in run_list: + run.prefixes = [p for p in run.prefixes if p not in common_prefixes] return run_list, common_prefixes @@ -297,7 +312,7 @@ triple_in_ir = find_triple_in_ir(input_lines, args.verbose) run_lines = common.find_run_lines(test, input_lines) - run_list, common_prefixes = build_run_list(test, run_lines, args.verbose) + run_list, common_prefixes = build_run_list(test, run_lines, args) simple_functions = find_functions_with_one_bb(input_lines, args.verbose) @@ -325,7 +340,7 @@ if args.remove_common_prefixes: prefix_set.update(common_prefixes) - elif common_prefixes: + elif common_prefixes and not args.use_first_common_prefix: common.warn('Ignoring common prefixes: {}'.format(common_prefixes), test_file=test) @@ -418,6 +433,9 @@ parser.add_argument('--remove-common-prefixes', action='store_true', help='Remove existing check lines whose prefixes are ' 'shared between multiple commands') + parser.add_argument('--use-first-common-prefix', action='store_true', + help='If there are common prefixes shared between run lines,' + ' use the first one instead of ignoring them all') parser.add_argument('tests', nargs='+') args = common.parse_commandline_args(parser)