diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/basic.ll.funcsig.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/basic.ll.funcsig.expected --- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/basic.ll.funcsig.expected +++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/basic.ll.funcsig.expected @@ -1,4 +1,4 @@ -; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature ; Example input for update_llc_test_checks (taken from test/Transforms/InstSimplify/add.ll) ; RUN: opt < %s -instsimplify -S | FileCheck %s diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/on_the_fly_arg_change.ll b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/on_the_fly_arg_change.ll new file mode 100644 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/on_the_fly_arg_change.ll @@ -0,0 +1,28 @@ +; RUN: opt -S < %s | FileCheck %s + +declare void @foo() + +define void @check_lines_1() { + ret void +} + +; UTC_ARGS: --turn=off + +define void @no_check_lines() { + ret void +} + +; UTC_ARGS: --turn=on + +define void @check_lines_2() { + ret void +} + +define void @scrub() { + call void @foo() readnone + ret void +} + +define i32 @signature(i32 %arg) { + ret i32 %arg +} diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/on_the_fly_arg_change.ll.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/on_the_fly_arg_change.ll.expected new file mode 100644 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/on_the_fly_arg_change.ll.expected @@ -0,0 +1,43 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes +; RUN: opt -S < %s | FileCheck %s + +declare void @foo() + +define void @check_lines_1() { +; CHECK-LABEL: define {{[^@]+}}@check_lines_1() +; CHECK-NEXT: ret void +; + ret void +} + +; UTC_ARGS: --turn=off + +define void @no_check_lines() { + ret void +} + +; UTC_ARGS: --turn=on + +define void @check_lines_2() { +; CHECK-LABEL: define {{[^@]+}}@check_lines_2() +; CHECK-NEXT: ret void +; + ret void +} + +define void @scrub() { +; CHECK-LABEL: define {{[^@]+}}@scrub() +; CHECK-NEXT: call void @foo() +; CHECK-NEXT: ret void +; + call void @foo() readnone + ret void +} + +define i32 @signature(i32 %arg) { +; CHECK-LABEL: define {{[^@]+}}@signature +; CHECK-SAME: (i32 [[ARG:%.*]]) +; CHECK-NEXT: ret i32 [[ARG:%.*]] +; + ret i32 %arg +} diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll.scrub.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll.scrub.expected --- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll.scrub.expected +++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/scrub_attrs.ll.scrub.expected @@ -1,4 +1,4 @@ -; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --scrub-attributes ; RUN: opt -S < %s | FileCheck %s declare void @foo() diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/basic.test b/llvm/test/tools/UpdateTestChecks/update_test_checks/basic.test --- a/llvm/test/tools/UpdateTestChecks/update_test_checks/basic.test +++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/basic.test @@ -8,6 +8,6 @@ ## Also try the --function-signature flag # RUN: %update_test_checks %t.ll --function-signature # RUN: diff -u %t.ll %S/Inputs/basic.ll.funcsig.expected -## Verify that running without the --function-signature flag removes the -SAME: lines: +## Verify that running without the --function-signature flag does not removes the -SAME: lines: # RUN: %update_test_checks %t.ll -# RUN: diff -u %t.ll %S/Inputs/basic.ll.expected +# RUN: diff -u %t.ll %S/Inputs/basic.ll.funcsig.expected diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/on_the_fly_arg_change.test b/llvm/test/tools/UpdateTestChecks/update_test_checks/on_the_fly_arg_change.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/on_the_fly_arg_change.test @@ -0,0 +1,6 @@ +# RUN: cp -f %S/Inputs/on_the_fly_arg_change.ll %t.ll +# RUN: %update_test_checks %t.ll --function-signature --scrub-attributes +# RUN: diff -u %t.ll %S/Inputs/on_the_fly_arg_change.ll.expected +## Check that running the script again does not change the result: +# RUN: %update_test_checks %t.ll +# RUN: diff -u %t.ll %S/Inputs/on_the_fly_arg_change.ll.expected diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/scrub_attrs.test b/llvm/test/tools/UpdateTestChecks/update_test_checks/scrub_attrs.test --- a/llvm/test/tools/UpdateTestChecks/update_test_checks/scrub_attrs.test +++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/scrub_attrs.test @@ -1,9 +1,9 @@ ## scrub_attrs test checking that update_test_checks.py works correctly # RUN: cp -f %S/Inputs/scrub_attrs.ll %t.ll && %update_test_checks %t.ll # RUN: diff -u %t.ll %S/Inputs/scrub_attrs.ll.plain.expected -## Check that running the script again does not change the result: -# RUN: %update_test_checks %t.ll -# RUN: diff -u %t.ll %S/Inputs/scrub_attrs.ll.plain.expected ## Also try the --scrub-attributes flag # RUN: %update_test_checks %t.ll --scrub-attributes # RUN: diff -u %t.ll %S/Inputs/scrub_attrs.ll.scrub.expected +## Check that running the script again does not change the result: +# RUN: %update_test_checks %t.ll +# RUN: diff -u %t.ll %S/Inputs/scrub_attrs.ll.scrub.expected 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 @@ -62,6 +62,8 @@ CHECK_PREFIX_RE = re.compile(r'--?check-prefix(?:es)?[= ](\S+)') PREFIX_RE = re.compile('^[a-zA-Z0-9_-]+$') CHECK_RE = re.compile(r'^\s*(?://|[;#])\s*([^:]+?)(?:-NEXT|-NOT|-DAG|-LABEL|-SAME)?:') +UTC_ARGS_KEY = 'UTC_ARGS:' +UTC_ARGS_CMD = re.compile(r'.*' + UTC_ARGS_KEY + '\s*(?P.*)\s*$') OPT_FUNCTION_RE = re.compile( r'^\s*define\s+(?:internal\s+)?[^@]*@(?P[\w-]+?)\s*' @@ -396,3 +398,26 @@ check_prefix(prefix) if prefixes.count(prefix) > 1: warn("Supplied prefix '%s' is not unique in the prefix list." % (prefix,)) + +def get_autogennote_suffix(parser, args): + autogenerated_note_args = '' + for k, v in args._get_kwargs(): + if parser.get_default(k) == v or k == 'tests' or k == 'update_only' or k == 'opt_binary': + continue + k = k.replace('_', '-') + if type(v) is bool: + autogenerated_note_args += '--%s ' % (k) + else: + autogenerated_note_args += '--%s %s ' % (k, v) + if autogenerated_note_args: + autogenerated_note_args = ' %s %s' % (UTC_ARGS_KEY, autogenerated_note_args[:-1]) + return autogenerated_note_args + + +def check_for_command(line, parser, args, argv): + cmd_m = UTC_ARGS_CMD.match(line) + if cmd_m: + cmd = cmd_m.group('cmd').strip().split(' ') + argv = argv + cmd + args = parser.parse_args(filter(lambda arg: arg not in args.tests, argv)) + return args, argv 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 @@ -66,6 +66,8 @@ help='Keep function signature information around for the check line') parser.add_argument('--scrub-attributes', action='store_true', help='Remove attribute annotations (#0) from the end of check line') + parser.add_argument('--turn', choices=['on', 'off'], default='on', + help='Initial state, check lines are upded only in "on" state') parser.add_argument('tests', nargs='+') args = common.parse_commandline_args(parser) @@ -86,6 +88,8 @@ # On Windows we must expand the patterns ourselves. test_paths = [test for pattern in args.tests for test in glob.glob(pattern)] for test in test_paths: + argv = sys.argv[:] + args = parser.parse_args() with open(test) as f: input_lines = [l.rstrip() for l in f] @@ -93,6 +97,9 @@ 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 first_line and 'autogenerated' in first_line: + args, argv = common.check_for_command(first_line, parser, args, argv) + test_autogenerated_note = autogenerated_note + common.get_autogennote_suffix(parser, args) if args.update_only: if not first_line or 'autogenerated' not in first_line: @@ -154,9 +161,17 @@ prefix_set = set([prefix for prefixes, _ in prefix_list for prefix in prefixes]) common.debug('Rewriting FileCheck prefixes:', str(prefix_set)) output_lines = [] - output_lines.append(autogenerated_note) + output_lines.append(test_autogenerated_note) for input_line in input_lines: + # Discard any previous script advertising. + if input_line.startswith(ADVERT): + continue + + args, argv = common.check_for_command(input_line, parser, args, argv) + if args.turn == 'off': + output_lines.append(input_line) + continue if is_in_function_start: if input_line == '': continue @@ -183,10 +198,6 @@ is_in_function = False continue - # Discard any previous script advertising. - if input_line.startswith(ADVERT): - continue - # If it's outside a function, it just gets copied to the output. output_lines.append(input_line)