forked from OSchip/llvm-project
[Debugify] Port -debugify-each to NewPM
Preemptively switch 2 tests to the new PM Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D90365
This commit is contained in:
parent
1b2fa6e46e
commit
98b9338588
|
@ -92,6 +92,12 @@ struct NewPMCheckDebugifyPass
|
|||
llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM);
|
||||
};
|
||||
|
||||
struct DebugifyEachInstrumentation {
|
||||
DebugifyStatsMap StatsMap;
|
||||
|
||||
void registerCallbacks(PassInstrumentationCallbacks &PIC);
|
||||
};
|
||||
|
||||
/// DebugifyCustomPassManager wraps each pass with the debugify passes if
|
||||
/// needed.
|
||||
/// NOTE: We support legacy custom pass manager only.
|
||||
|
|
|
@ -198,6 +198,18 @@ bool llvm::applyDebugifyMetadata(
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool applyDebugify(Function &F) {
|
||||
Module &M = *F.getParent();
|
||||
auto FuncIt = F.getIterator();
|
||||
return applyDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)),
|
||||
"FunctionDebugify: ", /*ApplyToMF=*/nullptr);
|
||||
}
|
||||
|
||||
static bool applyDebugify(Module &M) {
|
||||
return applyDebugifyMetadata(M, M.functions(),
|
||||
"ModuleDebugify: ", /*ApplyToMF=*/nullptr);
|
||||
}
|
||||
|
||||
bool llvm::stripDebugifyMetadata(Module &M) {
|
||||
bool Changed = false;
|
||||
|
||||
|
@ -383,10 +395,7 @@ bool checkDebugifyMetadata(Module &M,
|
|||
/// ModulePass for attaching synthetic debug info to everything, used with the
|
||||
/// legacy module pass manager.
|
||||
struct DebugifyModulePass : public ModulePass {
|
||||
bool runOnModule(Module &M) override {
|
||||
return applyDebugifyMetadata(M, M.functions(),
|
||||
"ModuleDebugify: ", /*ApplyToMF*/ nullptr);
|
||||
}
|
||||
bool runOnModule(Module &M) override { return applyDebugify(M); }
|
||||
|
||||
DebugifyModulePass() : ModulePass(ID) {}
|
||||
|
||||
|
@ -400,12 +409,7 @@ struct DebugifyModulePass : public ModulePass {
|
|||
/// FunctionPass for attaching synthetic debug info to instructions within a
|
||||
/// single function, used with the legacy module pass manager.
|
||||
struct DebugifyFunctionPass : public FunctionPass {
|
||||
bool runOnFunction(Function &F) override {
|
||||
Module &M = *F.getParent();
|
||||
auto FuncIt = F.getIterator();
|
||||
return applyDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)),
|
||||
"FunctionDebugify: ", /*ApplyToMF*/ nullptr);
|
||||
}
|
||||
bool runOnFunction(Function &F) override { return applyDebugify(F); }
|
||||
|
||||
DebugifyFunctionPass() : FunctionPass(ID) {}
|
||||
|
||||
|
@ -526,6 +530,30 @@ PreservedAnalyses NewPMCheckDebugifyPass::run(Module &M,
|
|||
return PreservedAnalyses::all();
|
||||
}
|
||||
|
||||
void DebugifyEachInstrumentation::registerCallbacks(
|
||||
PassInstrumentationCallbacks &PIC) {
|
||||
PIC.registerBeforeNonSkippedPassCallback([](StringRef P, Any IR) {
|
||||
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 (any_isa<const Function *>(IR)) {
|
||||
auto &F = *const_cast<Function *>(any_cast<const Function *>(IR));
|
||||
Module &M = *F.getParent();
|
||||
auto It = F.getIterator();
|
||||
checkDebugifyMetadata(M, make_range(It, std::next(It)), P,
|
||||
"CheckFunctionDebugify", /*Strip=*/true, &StatsMap);
|
||||
} else if (any_isa<const Module *>(IR)) {
|
||||
auto &M = *const_cast<Module *>(any_cast<const Module *>(IR));
|
||||
checkDebugifyMetadata(M, M.functions(), P, "CheckModuleDebugify",
|
||||
/*Strip=*/true, &StatsMap);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
char DebugifyModulePass::ID = 0;
|
||||
static RegisterPass<DebugifyModulePass> DM("debugify",
|
||||
"Attach debug info to everything");
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
; RUN: opt -debugify-each -O3 -S -o /dev/null < %s 2> %t
|
||||
; RUN: FileCheck %s -input-file=%t -check-prefix=MODULE-PASS
|
||||
; RUN: FileCheck %s -input-file=%t -check-prefix=FUNCTION-PASS
|
||||
; RUN: opt -disable-output -debugify-each -passes='default<O3>' %s 2> %t
|
||||
; RUN: FileCheck %s -input-file=%t -check-prefix=MODULE-PASS
|
||||
; RUN: FileCheck %s -input-file=%t -check-prefix=FUNCTION-PASS
|
||||
|
||||
; RUN: opt -enable-debugify -debugify-each -O3 -S -o /dev/null < %s 2> %t
|
||||
; RUN: FileCheck %s -input-file=%t -check-prefix=MODULE-PASS
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -debugify-each -debugify-quiet -debugify-export - -o /dev/null | FileCheck %s
|
||||
; 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
|
||||
|
||||
; CHECK: Pass Name
|
||||
; CHECK-SAME: # of missing debug values
|
||||
|
@ -6,7 +7,7 @@
|
|||
; CHECK-SAME: Missing/Expected value ratio
|
||||
; CHECK-SAME: Missing/Expected location ratio
|
||||
|
||||
; CHECK: Module Verifier
|
||||
; CHECK: {{Module Verifier|VerifierPass}}
|
||||
; CHECK-SAME: 0,0,0.000000e+00,0.000000e+00
|
||||
|
||||
define void @foo() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
; RUN: opt -disable-output -debugify-each -gvn < %s 2>&1 | FileCheck %s
|
||||
; RUN: opt -disable-output -debugify-each -passes=gvn < %s 2>&1 | FileCheck %s
|
||||
|
||||
; CHECK-NOT: ERROR: Instruction with empty DebugLoc in function _Z3bazv -- {{%.*}} = phi
|
||||
; CHECK: CheckFunctionDebugify [Global Value Numbering]: PASS
|
||||
; CHECK: CheckFunctionDebugify [GVN]: PASS
|
||||
|
||||
@foo = dso_local local_unnamed_addr global i32 0, align 4
|
||||
@x = global i8 17
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include "llvm/Passes/PassBuilder.h"
|
||||
#include "llvm/Passes/PassPlugin.h"
|
||||
#include "llvm/Passes/StandardInstrumentations.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/ToolOutputFile.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
|
@ -42,6 +41,17 @@
|
|||
using namespace llvm;
|
||||
using namespace opt_tool;
|
||||
|
||||
namespace llvm {
|
||||
cl::opt<bool> DebugifyEach(
|
||||
"debugify-each",
|
||||
cl::desc("Start each pass with debugify and end it with check-debugify"));
|
||||
|
||||
cl::opt<std::string>
|
||||
DebugifyExport("debugify-export",
|
||||
cl::desc("Export per-pass debugify statistics to this file"),
|
||||
cl::value_desc("filename"));
|
||||
} // namespace llvm
|
||||
|
||||
static cl::opt<bool>
|
||||
DebugPM("debug-pass-manager", cl::Hidden,
|
||||
cl::desc("Print pass management debugging information"));
|
||||
|
@ -249,6 +259,9 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
|
|||
PassInstrumentationCallbacks PIC;
|
||||
StandardInstrumentations SI(DebugPM, VerifyEachPass);
|
||||
SI.registerCallbacks(PIC);
|
||||
DebugifyEachInstrumentation Debugify;
|
||||
if (DebugifyEach)
|
||||
Debugify.registerCallbacks(PIC);
|
||||
|
||||
PipelineTuningOptions PTO;
|
||||
// LoopUnrolling defaults on to true and DisableLoopUnrolling is initialized
|
||||
|
@ -421,5 +434,8 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
|
|||
if (OptRemarkFile)
|
||||
OptRemarkFile->keep();
|
||||
|
||||
if (DebugifyEach && !DebugifyExport.empty())
|
||||
exportDebugifyStats(DebugifyExport, Debugify.StatsMap);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#define LLVM_TOOLS_OPT_NEWPMDRIVER_H
|
||||
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
|
||||
namespace llvm {
|
||||
class StringRef;
|
||||
|
@ -29,6 +30,9 @@ class TargetMachine;
|
|||
class ToolOutputFile;
|
||||
class TargetLibraryInfoImpl;
|
||||
|
||||
extern cl::opt<bool> DebugifyEach;
|
||||
extern cl::opt<std::string> DebugifyExport;
|
||||
|
||||
namespace opt_tool {
|
||||
enum OutputKind {
|
||||
OK_NoOutput,
|
||||
|
|
|
@ -209,16 +209,6 @@ static cl::opt<bool> EnableDebugify(
|
|||
cl::desc(
|
||||
"Start the pipeline with debugify and end it with check-debugify"));
|
||||
|
||||
static cl::opt<bool> DebugifyEach(
|
||||
"debugify-each",
|
||||
cl::desc(
|
||||
"Start each pass with debugify and end it with check-debugify"));
|
||||
|
||||
static cl::opt<std::string>
|
||||
DebugifyExport("debugify-export",
|
||||
cl::desc("Export per-pass debugify statistics to this file"),
|
||||
cl::value_desc("filename"), cl::init(""));
|
||||
|
||||
static cl::opt<bool>
|
||||
PrintBreakpoints("print-breakpoints-for-testing",
|
||||
cl::desc("Print select breakpoints location for testing"));
|
||||
|
|
Loading…
Reference in New Issue