Skip to content

Commit

Permalink
[NewPM] Add callbacks to PassBuilder to run before/after parsing a pass
Browse files Browse the repository at this point in the history
This is in preparation for supporting -debugify-each, which adds a debug
info pass before and after each pass.

Switch VerifyEach to use this.

Reviewed By: ychen

Differential Revision: https://reviews.llvm.org/D88107
  • Loading branch information
aeubanks committed Sep 23, 2020
1 parent 6b1ce83 commit 111aa4e
Show file tree
Hide file tree
Showing 6 changed files with 306 additions and 151 deletions.
77 changes: 63 additions & 14 deletions llvm/include/llvm/Passes/PassBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ class PassBuilder {
/// preferred when a pipeline is largely of one type, but one or just a few
/// passes are of different types(See PassBuilder.cpp for examples).
Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText,
bool VerifyEachPass = true,
bool DebugLogging = false);

/// {{@ Parse a textual pass pipeline description into a specific PassManager
Expand All @@ -499,13 +498,10 @@ class PassBuilder {
///
/// function(lpass)
Error parsePassPipeline(CGSCCPassManager &CGPM, StringRef PipelineText,
bool VerifyEachPass = true,
bool DebugLogging = false);
Error parsePassPipeline(FunctionPassManager &FPM, StringRef PipelineText,
bool VerifyEachPass = true,
bool DebugLogging = false);
Error parsePassPipeline(LoopPassManager &LPM, StringRef PipelineText,
bool VerifyEachPass = true,
bool DebugLogging = false);
/// @}}

Expand Down Expand Up @@ -682,10 +678,46 @@ class PassBuilder {
/// PassManagers and populate the passed ModulePassManager.
void registerParseTopLevelPipelineCallback(
const std::function<bool(ModulePassManager &, ArrayRef<PipelineElement>,
bool VerifyEachPass, bool DebugLogging)> &C) {
bool DebugLogging)> &C) {
TopLevelPipelineParsingCallbacks.push_back(C);
}

/// {{@ Register callbacks for before/after parsing passes.
/// For example, to add a verifier pass after each parsed pass.
void registerBeforeParsingModulePassCallback(
const std::function<void(ModulePassManager &)> &C) {
ModulePassBeforeParsingCallbacks.push_back(C);
}
void registerBeforeParsingCGSCCPassCallback(
const std::function<void(CGSCCPassManager &)> &C) {
CGSCCPassBeforeParsingCallbacks.push_back(C);
}
void registerBeforeParsingFunctionPassCallback(
const std::function<void(FunctionPassManager &)> &C) {
FunctionPassBeforeParsingCallbacks.push_back(C);
}
void registerBeforeParsingLoopPassCallback(
const std::function<void(LoopPassManager &)> &C) {
LoopPassBeforeParsingCallbacks.push_back(C);
}
void registerAfterParsingModulePassCallback(
const std::function<void(ModulePassManager &)> &C) {
ModulePassAfterParsingCallbacks.push_back(C);
}
void registerAfterParsingCGSCCPassCallback(
const std::function<void(CGSCCPassManager &)> &C) {
CGSCCPassAfterParsingCallbacks.push_back(C);
}
void registerAfterParsingFunctionPassCallback(
const std::function<void(FunctionPassManager &)> &C) {
FunctionPassAfterParsingCallbacks.push_back(C);
}
void registerAfterParsingLoopPassCallback(
const std::function<void(LoopPassManager &)> &C) {
LoopPassAfterParsingCallbacks.push_back(C);
}
/// @}}

/// Add PGOInstrumenation passes for O0 only.
void addPGOInstrPassesForO0(ModulePassManager &MPM, bool DebugLogging,
bool RunProfileGen, bool IsCS,
Expand All @@ -708,27 +740,27 @@ class PassBuilder {
parsePipelineText(StringRef Text);

Error parseModulePass(ModulePassManager &MPM, const PipelineElement &E,
bool VerifyEachPass, bool DebugLogging);
bool DebugLogging);
Error parseCGSCCPass(CGSCCPassManager &CGPM, const PipelineElement &E,
bool VerifyEachPass, bool DebugLogging);
bool DebugLogging);
Error parseFunctionPass(FunctionPassManager &FPM, const PipelineElement &E,
bool VerifyEachPass, bool DebugLogging);
bool DebugLogging);
Error parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
bool VerifyEachPass, bool DebugLogging);
bool DebugLogging);
bool parseAAPassName(AAManager &AA, StringRef Name);

Error parseLoopPassPipeline(LoopPassManager &LPM,
ArrayRef<PipelineElement> Pipeline,
bool VerifyEachPass, bool DebugLogging);
bool DebugLogging);
Error parseFunctionPassPipeline(FunctionPassManager &FPM,
ArrayRef<PipelineElement> Pipeline,
bool VerifyEachPass, bool DebugLogging);
bool DebugLogging);
Error parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
ArrayRef<PipelineElement> Pipeline,
bool VerifyEachPass, bool DebugLogging);
bool DebugLogging);
Error parseModulePassPipeline(ModulePassManager &MPM,
ArrayRef<PipelineElement> Pipeline,
bool VerifyEachPass, bool DebugLogging);
bool DebugLogging);

void addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
OptimizationLevel Level, bool RunProfileGen, bool IsCS,
Expand Down Expand Up @@ -761,7 +793,7 @@ class PassBuilder {
2>
ModulePipelineParsingCallbacks;
SmallVector<std::function<bool(ModulePassManager &, ArrayRef<PipelineElement>,
bool VerifyEachPass, bool DebugLogging)>,
bool DebugLogging)>,
2>
TopLevelPipelineParsingCallbacks;
// CGSCC callbacks
Expand All @@ -788,6 +820,23 @@ class PassBuilder {
// AA callbacks
SmallVector<std::function<bool(StringRef Name, AAManager &AA)>, 2>
AAParsingCallbacks;
// Before/after pass parsing callbacks
SmallVector<std::function<void(ModulePassManager &)>, 2>
ModulePassBeforeParsingCallbacks;
SmallVector<std::function<void(ModulePassManager &)>, 2>
ModulePassAfterParsingCallbacks;
SmallVector<std::function<void(CGSCCPassManager &)>, 2>
CGSCCPassBeforeParsingCallbacks;
SmallVector<std::function<void(CGSCCPassManager &)>, 2>
CGSCCPassAfterParsingCallbacks;
SmallVector<std::function<void(FunctionPassManager &)>, 2>
FunctionPassBeforeParsingCallbacks;
SmallVector<std::function<void(FunctionPassManager &)>, 2>
FunctionPassAfterParsingCallbacks;
SmallVector<std::function<void(LoopPassManager &)>, 2>
LoopPassBeforeParsingCallbacks;
SmallVector<std::function<void(LoopPassManager &)>, 2>
LoopPassAfterParsingCallbacks;
};

/// This utility template takes care of adding require<> and invalidate<>
Expand Down
Loading

0 comments on commit 111aa4e

Please sign in to comment.