[llvm] be26bd5 - [Utils] Reuse argument variable names in the body

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 30 23:59:28 PST 2019


Author: Johannes Doerfert
Date: 2019-12-31T01:58:36-06:00
New Revision: be26bd55130b6b13c40d0cf0ba97bf5cf3197487

URL: https://github.com/llvm/llvm-project/commit/be26bd55130b6b13c40d0cf0ba97bf5cf3197487
DIFF: https://github.com/llvm/llvm-project/commit/be26bd55130b6b13c40d0cf0ba97bf5cf3197487.diff

LOG: [Utils] Reuse argument variable names in the body

If we have `int foo(int a) { return a; }` and we run with --function-signature
enabled, we want a single variable declaration for `a` which is reused
later.

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D69722

Added: 
    llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/argument_name_reuse.ll
    llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/argument_name_reuse.ll.expected
    llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/argument_name_reuse.ll.plain.expected
    llvm/test/tools/UpdateTestChecks/update_test_checks/argument_name_reuse.test

Modified: 
    llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/basic.ll.funcsig.expected
    llvm/utils/UpdateTestChecks/common.py

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/argument_name_reuse.ll b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/argument_name_reuse.ll
new file mode 100644
index 000000000000..c5bcee5ba1ee
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/argument_name_reuse.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -S | FileCheck %s
+
+define i32 @reuse_arg_names(i32 %X, i32 %Y) {
+  %Z = sub i32 %X, %Y
+  %Q = add i32 %Z, %Y
+  ret i32 %Q
+}

diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/argument_name_reuse.ll.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/argument_name_reuse.ll.expected
new file mode 100644
index 000000000000..461a8b6a5bf6
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/argument_name_reuse.ll.expected
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature
+; RUN: opt < %s -S | FileCheck %s
+
+define i32 @reuse_arg_names(i32 %X, i32 %Y) {
+; CHECK-LABEL: define {{[^@]+}}@reuse_arg_names
+; CHECK-SAME: (i32 [[X:%.*]], i32 [[Y:%.*]])
+; CHECK-NEXT:    [[Z:%.*]] = sub i32 [[X]], [[Y]]
+; CHECK-NEXT:    [[Q:%.*]] = add i32 [[Z]], [[Y]]
+; CHECK-NEXT:    ret i32 [[Q]]
+;
+  %Z = sub i32 %X, %Y
+  %Q = add i32 %Z, %Y
+  ret i32 %Q
+}

diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/argument_name_reuse.ll.plain.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/argument_name_reuse.ll.plain.expected
new file mode 100644
index 000000000000..e6cb25980a2f
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/argument_name_reuse.ll.plain.expected
@@ -0,0 +1,13 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -S | FileCheck %s
+
+define i32 @reuse_arg_names(i32 %X, i32 %Y) {
+; CHECK-LABEL: @reuse_arg_names(
+; CHECK-NEXT:    [[Z:%.*]] = sub i32 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[Q:%.*]] = add i32 [[Z]], [[Y]]
+; CHECK-NEXT:    ret i32 [[Q]]
+;
+  %Z = sub i32 %X, %Y
+  %Q = add i32 %Z, %Y
+  ret i32 %Q
+}

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
index 76f9f447c3fe..103b58115c19 100644
--- 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
@@ -5,7 +5,7 @@
 define i32 @common_sub_operand(i32 %X, i32 %Y) {
 ; CHECK-LABEL: define {{[^@]+}}@common_sub_operand
 ; CHECK-SAME: (i32 [[X:%.*]], i32 [[Y:%.*]])
-; CHECK-NEXT:    ret i32 [[X:%.*]]
+; CHECK-NEXT:    ret i32 [[X]]
 ;
   %Z = sub i32 %X, %Y
   %Q = add i32 %Z, %Y

diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/argument_name_reuse.test b/llvm/test/tools/UpdateTestChecks/update_test_checks/argument_name_reuse.test
new file mode 100644
index 000000000000..6bb44c52e5bb
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/argument_name_reuse.test
@@ -0,0 +1,6 @@
+# Verify we reuse the argument regexps with --function-signature
+# RUN: cp -f %S/Inputs/argument_name_reuse.ll %t.ll && %update_test_checks %t.ll --function-signature
+# RUN: 
diff  -u %t.ll %S/Inputs/argument_name_reuse.ll.expected
+# Verify we do not reuse the argument regexps, as there are none, without --function-signature
+# RUN: cp -f %S/Inputs/argument_name_reuse.ll %t.ll && %update_test_checks %t.ll
+# RUN: 
diff  -u %t.ll %S/Inputs/argument_name_reuse.ll.plain.expected

diff  --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index ccb6ba586de6..44e0186ae3af 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -233,7 +233,7 @@ def get_value_use(var):
   return '[[' + get_value_name(var) + ']]'
 
 # Replace IR value defs and uses with FileCheck variables.
-def genericize_check_lines(lines, is_analyze):
+def genericize_check_lines(lines, is_analyze, vars_seen):
   # This gets called for each match that occurs in
   # a line. We transform variables we haven't seen
   # into defs, and variables we have seen into uses.
@@ -250,7 +250,6 @@ def transform_line_vars(match):
     # including the commas and spaces.
     return match.group(1) + rv + match.group(3)
 
-  vars_seen = set()
   lines_with_def = []
 
   for i, line in enumerate(lines):
@@ -283,9 +282,10 @@ def add_checks(output_lines, comment_marker, prefix_list, func_dict, func_name,
         if len(printed_prefixes) != 0:
           output_lines.append(comment_marker)
 
+      vars_seen = set()
       printed_prefixes.append(checkprefix)
       args_and_sig = str(func_dict[checkprefix][func_name].args_and_sig)
-      args_and_sig = genericize_check_lines([args_and_sig], is_analyze)[0]
+      args_and_sig = genericize_check_lines([args_and_sig], is_analyze, vars_seen)[0]
       if '[[' in args_and_sig:
         output_lines.append(check_label_format % (checkprefix, func_name, ''))
         output_lines.append('%s %s-SAME: %s' % (comment_marker, checkprefix, args_and_sig))
@@ -305,7 +305,7 @@ def add_checks(output_lines, comment_marker, prefix_list, func_dict, func_name,
 
       # For IR output, change all defs to FileCheck variables, so we're immune
       # to variable naming fashions.
-      func_body = genericize_check_lines(func_body, is_analyze)
+      func_body = genericize_check_lines(func_body, is_analyze, vars_seen)
 
       # This could be selectively enabled with an optional invocation argument.
       # Disabled for now: better to check everything. Be safe rather than sorry.


        


More information about the llvm-commits mailing list