[PATCH] D71456: [UpdateTestChecks] Capture function signature variable definitions

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 13 02:57:04 PST 2019


arichardson created this revision.
arichardson added a reviewer: jdoerfert.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Currently, even when using --function-signature, the first use of an
argument will create a new FileCheck capture (e.g. [[X:%.*]]) even though
the value has already been captured in the CHECK-SAME line for the
function signature.
To fix this problem return the vars_seen set from genericize_check_lines()
and pass it to the second call so that it sees the variables captured
as part of the function signature.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71456

Files:
  llvm/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/mangled_names.c.funcsig.expected
  llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/basic.ll.funcsig.expected
  llvm/utils/UpdateTestChecks/common.py


Index: llvm/utils/UpdateTestChecks/common.py
===================================================================
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -231,7 +231,7 @@
   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=None):
   # 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.
@@ -248,7 +248,8 @@
     # including the commas and spaces.
     return match.group(1) + rv + match.group(3)
 
-  vars_seen = set()
+  if vars_seen is None:
+    vars_seen = set()
   lines_with_def = []
 
   for i, line in enumerate(lines):
@@ -260,7 +261,7 @@
       lines[i] = scrubbed_line
     else:
       lines[i] = IR_VALUE_RE.sub(transform_line_vars, scrubbed_line)
-  return lines
+  return lines, vars_seen
 
 
 def add_checks(output_lines, comment_marker, prefix_list, func_dict, func_name, check_label_format, is_asm, is_analyze):
@@ -283,7 +284,9 @@
 
       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, vars_seen = genericize_check_lines([args_and_sig], is_analyze)
+      assert len(args_and_sig) == 1
+      args_and_sig = args_and_sig[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))
@@ -303,7 +306,7 @@
 
       # 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, vars_seen = 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.
Index: llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/basic.ll.funcsig.expected
===================================================================
--- llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/basic.ll.funcsig.expected
+++ 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
Index: llvm/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/mangled_names.c.funcsig.expected
===================================================================
--- llvm/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/mangled_names.c.funcsig.expected
+++ llvm/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/mangled_names.c.funcsig.expected
@@ -7,8 +7,8 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:    [[A_ADDR:%.*]] = alloca i64, align 8
 // CHECK-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
-// CHECK-NEXT:    store i64 [[A:%.*]], i64* [[A_ADDR]], align 8
-// CHECK-NEXT:    store i32 [[B:%.*]], i32* [[B_ADDR]], align 4
+// CHECK-NEXT:    store i64 [[A]], i64* [[A_ADDR]], align 8
+// CHECK-NEXT:    store i32 [[B]], i32* [[B_ADDR]], align 4
 // CHECK-NEXT:    [[TMP0:%.*]] = load i64, i64* [[A_ADDR]], align 8
 // CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[B_ADDR]], align 4
 // CHECK-NEXT:    [[CONV:%.*]] = sext i32 [[TMP1]] to i64
@@ -26,9 +26,9 @@
 // CHECK-NEXT:    [[A_ADDR:%.*]] = alloca i64, align 8
 // CHECK-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:    [[C_ADDR:%.*]] = alloca i32, align 4
-// CHECK-NEXT:    store i64 [[A:%.*]], i64* [[A_ADDR]], align 8
-// CHECK-NEXT:    store i32 [[B:%.*]], i32* [[B_ADDR]], align 4
-// CHECK-NEXT:    store i32 [[C:%.*]], i32* [[C_ADDR]], align 4
+// CHECK-NEXT:    store i64 [[A]], i64* [[A_ADDR]], align 8
+// CHECK-NEXT:    store i32 [[B]], i32* [[B_ADDR]], align 4
+// CHECK-NEXT:    store i32 [[C]], i32* [[C_ADDR]], align 4
 // CHECK-NEXT:    [[TMP0:%.*]] = load i64, i64* [[A_ADDR]], align 8
 // CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[B_ADDR]], align 4
 // CHECK-NEXT:    [[CONV:%.*]] = sext i32 [[TMP1]] to i64


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71456.233759.patch
Type: text/x-patch
Size: 4522 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191213/503232ab/attachment.bin>


More information about the llvm-commits mailing list