Skip to content

Commit

Permalink
[Debugify] Skip debugifying on special/immutable passes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aeubanks committed Nov 17, 2020
1 parent 74207e7 commit 7de6dcd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
6 changes: 3 additions & 3 deletions llvm/lib/IR/PassInstrumentation.cpp
Expand Up @@ -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); });
}

Expand Down
12 changes: 12 additions & 0 deletions llvm/lib/Transforms/Utils/Debugify.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -530,16 +531,27 @@ 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))
applyDebugify(*const_cast<Module *>(any_cast<const Module *>(IR)));
});
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();
Expand Down
17 changes: 17 additions & 0 deletions llvm/test/DebugInfo/debugify-each.ll
Expand Up @@ -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
Expand All @@ -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 [{{.*}}]
6 changes: 3 additions & 3 deletions llvm/test/DebugInfo/debugify-export.ll
@@ -1,13 +1,13 @@
; 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
; CHECK-SAME: # of missing locations
; 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() {
Expand Down
1 change: 1 addition & 0 deletions 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, ...)

Expand Down

0 comments on commit 7de6dcd

Please sign in to comment.