[llvm] 7de6dcd - [Debugify] Skip debugifying on special/immutable passes

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 16 20:40:19 PST 2020


Author: Arthur Eubanks
Date: 2020-11-16T20:39:46-08:00
New Revision: 7de6dcd24644eee6af9e642cb9e0402a47018413

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

LOG: [Debugify] Skip debugifying on special/immutable passes

With a function pass manager, it would insert debuginfo metadata before
getting to function passes while processing the pass manager, causing
debugify to skip while running the function passes.

Skip special passes + verifier + printing passes. Compared to the legacy
implementation of -debugify-each, this additionally skips verifier
passes. Probably no need to update the legacy version since it will be
obsolete soon.

This fixes 2 instcombine tests using -debugify-each under NPM.

Reviewed By: MaskRay

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

Added: 
    

Modified: 
    llvm/lib/IR/PassInstrumentation.cpp
    llvm/lib/Transforms/Utils/Debugify.cpp
    llvm/test/DebugInfo/debugify-each.ll
    llvm/test/DebugInfo/debugify-export.ll
    llvm/test/Transforms/InstCombine/call-guard.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/PassInstrumentation.cpp b/llvm/lib/IR/PassInstrumentation.cpp
index d3867de44bca..a0004a812147 100644
--- a/llvm/lib/IR/PassInstrumentation.cpp
+++ b/llvm/lib/IR/PassInstrumentation.cpp
@@ -21,9 +21,9 @@ AnalysisKey PassInstrumentationAnalysis::Key;
 
 bool isSpecialPass(StringRef PassID, const std::vector<StringRef> &Specials) {
   size_t Pos = PassID.find('<');
-  if (Pos == StringRef::npos)
-    return false;
-  StringRef Prefix = PassID.substr(0, Pos);
+  StringRef Prefix = PassID;
+  if (Pos != StringRef::npos)
+    Prefix = PassID.substr(0, Pos);
   return any_of(Specials, [Prefix](StringRef S) { return Prefix.endswith(S); });
 }
 

diff  --git a/llvm/lib/Transforms/Utils/Debugify.cpp b/llvm/lib/Transforms/Utils/Debugify.cpp
index 526083c26cf9..cb6985f4ca28 100644
--- a/llvm/lib/Transforms/Utils/Debugify.cpp
+++ b/llvm/lib/Transforms/Utils/Debugify.cpp
@@ -20,6 +20,7 @@
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/PassInstrumentation.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/CommandLine.h"
 
@@ -530,9 +531,18 @@ PreservedAnalyses NewPMCheckDebugifyPass::run(Module &M,
   return PreservedAnalyses::all();
 }
 
+static bool isIgnoredPass(StringRef PassID) {
+  return isSpecialPass(PassID, {"PassManager", "PassAdaptor",
+                                "AnalysisManagerProxy", "PrintFunctionPass",
+                                "PrintModulePass", "BitcodeWriterPass",
+                                "ThinLTOBitcodeWriterPass", "VerifierPass"});
+}
+
 void DebugifyEachInstrumentation::registerCallbacks(
     PassInstrumentationCallbacks &PIC) {
   PIC.registerBeforeNonSkippedPassCallback([](StringRef P, Any IR) {
+    if (isIgnoredPass(P))
+      return;
     if (any_isa<const Function *>(IR))
       applyDebugify(*const_cast<Function *>(any_cast<const Function *>(IR)));
     else if (any_isa<const Module *>(IR))
@@ -540,6 +550,8 @@ void DebugifyEachInstrumentation::registerCallbacks(
   });
   PIC.registerAfterPassCallback([this](StringRef P, Any IR,
                                        const PreservedAnalyses &PassPA) {
+    if (isIgnoredPass(P))
+      return;
     if (any_isa<const Function *>(IR)) {
       auto &F = *const_cast<Function *>(any_cast<const Function *>(IR));
       Module &M = *F.getParent();

diff  --git a/llvm/test/DebugInfo/debugify-each.ll b/llvm/test/DebugInfo/debugify-each.ll
index 74ce1b8c99dc..1020b8137268 100644
--- a/llvm/test/DebugInfo/debugify-each.ll
+++ b/llvm/test/DebugInfo/debugify-each.ll
@@ -30,6 +30,16 @@
 ; RUN: opt -O1 -debugify-each < %s | llvm-dis -o %t.after
 ; RUN: 
diff  %t.before %t.after
 
+; Check that we only run debugify once per function per function pass.
+; This ensures that we don't run it for pass managers/verifiers/printers.
+; RUN: opt -debugify-each -passes=instsimplify -S -o /dev/null < %s 2> %t
+; RUN: FileCheck %s -input-file=%t -check-prefix=FUNCTION-PASS-ONE
+
+; Check that we only run debugify once per module pass
+; (plus the implicitly added begin/end verifier passes).
+; RUN: opt -debugify-each -passes=globalopt -S -o /dev/null < %s 2> %t
+; RUN: FileCheck %s -input-file=%t -check-prefix=MODULE-PASS-ONE
+
 define void @foo(i32 %arg) {
   call i32 asm "bswap $0", "=r,r"(i32 %arg)
   ret void
@@ -48,3 +58,10 @@ define void @bar() {
 ; FUNCTION-PASS: CheckFunctionDebugify [{{.*}}]
 ; FUNCTION-PASS: CheckFunctionDebugify [{{.*}}]
 ; FUNCTION-PASS: CheckFunctionDebugify [{{.*}}]
+
+; MODULE-PASS-ONE: CheckModuleDebugify [{{.*}}]
+; MODULE-PASS-ONE-NOT: CheckModuleDebugify [{{.*}}]
+
+; FUNCTION-PASS-ONE: CheckFunctionDebugify [{{.*}}]
+; FUNCTION-PASS-ONE: CheckFunctionDebugify [{{.*}}]
+; FUNCTION-PASS-ONE-NOT: CheckFunctionDebugify [{{.*}}]

diff  --git a/llvm/test/DebugInfo/debugify-export.ll b/llvm/test/DebugInfo/debugify-export.ll
index 93fb17bf5f04..af8865c11e70 100644
--- a/llvm/test/DebugInfo/debugify-export.ll
+++ b/llvm/test/DebugInfo/debugify-export.ll
@@ -1,5 +1,5 @@
-; RUN: opt %s -disable-output -debugify-each -debugify-quiet -debugify-export - -enable-new-pm=0 | FileCheck %s
-; RUN: opt %s -disable-output -debugify-each -debugify-quiet -debugify-export - -enable-new-pm=1 | FileCheck %s
+; RUN: opt %s -disable-output -debugify-each -debugify-quiet -debugify-export - -globalopt | FileCheck %s
+; RUN: opt %s -disable-output -debugify-each -debugify-quiet -debugify-export - -passes=globalopt | FileCheck %s
 
 ; CHECK: Pass Name
 ; CHECK-SAME: # of missing debug values
@@ -7,7 +7,7 @@
 ; CHECK-SAME: Missing/Expected value ratio
 ; CHECK-SAME: Missing/Expected location ratio
 
-; CHECK:      {{Module Verifier|VerifierPass}}
+; CHECK:      {{Module Verifier|GlobalOptPass}}
 ; CHECK-SAME: 0,0,0.000000e+00,0.000000e+00
 
 define void @foo() {

diff  --git a/llvm/test/Transforms/InstCombine/call-guard.ll b/llvm/test/Transforms/InstCombine/call-guard.ll
index 3d61a5a50d31..e9ff9fa68155 100644
--- a/llvm/test/Transforms/InstCombine/call-guard.ll
+++ b/llvm/test/Transforms/InstCombine/call-guard.ll
@@ -1,5 +1,6 @@
 ; RUN: opt < %s -instcombine -instcombine-infinite-loop-threshold=2 -S | FileCheck %s
 ; RUN: opt < %s -instcombine -S -debugify-each | FileCheck %s
+; RUN: opt < %s -passes=instcombine -S -debugify-each | FileCheck %s
 
 declare void @llvm.experimental.guard(i1, ...)
 


        


More information about the llvm-commits mailing list