diff --git a/llvm/lib/IR/PassInstrumentation.cpp b/llvm/lib/IR/PassInstrumentation.cpp --- a/llvm/lib/IR/PassInstrumentation.cpp +++ b/llvm/lib/IR/PassInstrumentation.cpp @@ -21,9 +21,9 @@ bool isSpecialPass(StringRef PassID, const std::vector &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 --- 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 @@ 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(IR)) applyDebugify(*const_cast(any_cast(IR))); else if (any_isa(IR)) @@ -540,6 +550,8 @@ }); PIC.registerAfterPassCallback([this](StringRef P, Any IR, const PreservedAnalyses &PassPA) { + if (isIgnoredPass(P)) + return; if (any_isa(IR)) { auto &F = *const_cast(any_cast(IR)); Module &M = *F.getParent(); diff --git a/llvm/test/DebugInfo/debugify-each.ll b/llvm/test/DebugInfo/debugify-each.ll --- 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 @@ ; 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 --- 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 --- 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, ...)