[llvm] a6c59e0 - [Utils] Deal with occasionally deleted functions

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 31 00:36:57 PST 2019


Author: Johannes Doerfert
Date: 2019-12-31T02:35:18-06:00
New Revision: a6c59e0792edc46df937b338fe0e68d00cabf90b

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

LOG: [Utils] Deal with occasionally deleted functions

When functions exist for some but not all run lines we need to be
careful when selecting the prefix. So far, a common prefix was
potentially chosen as there was never a "conflict" that would have
caused otherwise. With this patch we avoid common prefixes if they
are used by run lines that do not emit the function.

Reviewed By: lebedev.ri

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

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

Modified: 
    llvm/utils/UpdateTestChecks/common.py

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/sometimes_deleted_function.ll b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/sometimes_deleted_function.ll
new file mode 100644
index 000000000000..6b82c49f018e
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/sometimes_deleted_function.ll
@@ -0,0 +1,12 @@
+; RUN: opt -S < %s | FileCheck %s --check-prefixes=ALL,FIRST
+; RUN: opt -S -globalopt < %s | FileCheck %s --check-prefixes=ALL,SECOND
+;
+; Make sure we use FIRST to check for @sometimes_here as ALL does not work.
+
+define internal void @sometimes_here() {
+  ret void
+}
+
+define void @always_here() {
+  ret void
+}

diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/sometimes_deleted_function.ll.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/sometimes_deleted_function.ll.expected
new file mode 100644
index 000000000000..f9374257162f
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/sometimes_deleted_function.ll.expected
@@ -0,0 +1,19 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S < %s | FileCheck %s --check-prefixes=ALL,FIRST
+; RUN: opt -S -globalopt < %s | FileCheck %s --check-prefixes=ALL,SECOND
+;
+; Make sure we use FIRST to check for @sometimes_here as ALL does not work.
+
+define internal void @sometimes_here() {
+; FIRST-LABEL: @sometimes_here(
+; FIRST-NEXT:    ret void
+;
+  ret void
+}
+
+define void @always_here() {
+; ALL-LABEL: @always_here(
+; ALL-NEXT:    ret void
+;
+  ret void
+}

diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/sometimes_deleted_function.test b/llvm/test/tools/UpdateTestChecks/update_test_checks/sometimes_deleted_function.test
new file mode 100644
index 000000000000..db45038da9c9
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/sometimes_deleted_function.test
@@ -0,0 +1,5 @@
+# RUN: cp -f %S/Inputs/sometimes_deleted_function.ll %t.ll && %update_test_checks %t.ll
+# RUN: 
diff  -u %t.ll %S/Inputs/sometimes_deleted_function.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/sometimes_deleted_function.ll.expected

diff  --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 44e0186ae3af..985c0b074c50 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -265,16 +265,37 @@ def transform_line_vars(match):
 
 
 def add_checks(output_lines, comment_marker, prefix_list, func_dict, func_name, check_label_format, is_asm, is_analyze):
+  # prefix_blacklist are prefixes we cannot use to print the function because it doesn't exist in run lines that use these prefixes as well.
+  prefix_blacklist = set()
   printed_prefixes = []
   for p in prefix_list:
     checkprefixes = p[0]
+    # If not all checkprefixes of this run line produced the function we cannot check for it as it does not
+    # exist for this run line. A subset of the check prefixes might know about the function but only because
+    # other run lines created it.
+    if any(map(lambda checkprefix: func_name not in func_dict[checkprefix], checkprefixes)):
+        prefix_blacklist |= set(checkprefixes)
+        continue
+
+  # prefix_blacklist is constructed, we can now emit the output
+  for p in prefix_list:
+    checkprefixes = p[0]
+    saved_output = None
     for checkprefix in checkprefixes:
       if checkprefix in printed_prefixes:
         break
-      # TODO func_dict[checkprefix] may be None, '' or not exist.
-      # Fix the call sites.
-      if func_name not in func_dict[checkprefix] or not func_dict[checkprefix][func_name]:
-        continue
+
+      # prefix is blacklisted. We remember the output as we might need it later but we will not emit anything for the prefix.
+      if checkprefix in prefix_blacklist:
+          if not saved_output and func_name in func_dict[checkprefix]:
+              saved_output = func_dict[checkprefix][func_name]
+          continue
+
+      # If we do not have output for this prefix but there is one saved, we go ahead with this prefix and the saved output.
+      if not func_dict[checkprefix][func_name]:
+        if not saved_output:
+            continue
+        func_dict[checkprefix][func_name] = saved_output
 
       # Add some space between 
diff erent check prefixes, but not after the last
       # check line (before the test code).


        


More information about the llvm-commits mailing list