1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-21 18:22:53 +01:00

[NewPM][PassInstrumentation] Add PreservedAnalyses parameter to AfterPass* callbacks

Both AfterPass and AfterPassInvalidated pass instrumentation
callbacks get additional parameter of type PreservedAnalyses.
This patch was created by @fedor.sergeev. I have just slightly
changed it.

Reviewers: fedor.sergeev

Differential Revision: https://reviews.llvm.org/D81555
This commit is contained in:
Yevgeny Rouban 2020-08-21 15:52:26 +07:00
parent 76932d3b0f
commit 1bdf10a116
11 changed files with 85 additions and 62 deletions

View File

@ -508,7 +508,7 @@ public:
PassPA = Pass.run(F, FAM);
}
PI.runAfterPass<Function>(Pass, F);
PI.runAfterPass<Function>(Pass, F, PassPA);
// We know that the function pass couldn't have invalidated any other
// function's analyses (that's the contract of a function pass), so
@ -639,9 +639,9 @@ public:
PreservedAnalyses PassPA = Pass.run(*C, AM, CG, UR);
if (UR.InvalidatedSCCs.count(C))
PI.runAfterPassInvalidated<LazyCallGraph::SCC>(Pass);
PI.runAfterPassInvalidated<LazyCallGraph::SCC>(Pass, PassPA);
else
PI.runAfterPass<LazyCallGraph::SCC>(Pass, *C);
PI.runAfterPass<LazyCallGraph::SCC>(Pass, *C, PassPA);
// If the SCC structure has changed, bail immediately and let the outer
// CGSCC layer handle any iteration to reflect the refined structure.
@ -903,9 +903,9 @@ ModuleToPostOrderCGSCCPassAdaptor<CGSCCPassT>::run(Module &M,
}
if (UR.InvalidatedSCCs.count(C))
PI.runAfterPassInvalidated<LazyCallGraph::SCC>(Pass);
PI.runAfterPassInvalidated<LazyCallGraph::SCC>(Pass, PassPA);
else
PI.runAfterPass<LazyCallGraph::SCC>(Pass, *C);
PI.runAfterPass<LazyCallGraph::SCC>(Pass, *C, PassPA);
// Update the SCC and RefSCC if necessary.
C = UR.UpdatedC ? UR.UpdatedC : C;

View File

@ -76,8 +76,8 @@ public:
using BeforePassFunc = bool(StringRef, Any);
using BeforeSkippedPassFunc = void(StringRef, Any);
using BeforeNonSkippedPassFunc = void(StringRef, Any);
using AfterPassFunc = void(StringRef, Any);
using AfterPassInvalidatedFunc = void(StringRef);
using AfterPassFunc = void(StringRef, Any, const PreservedAnalyses &);
using AfterPassInvalidatedFunc = void(StringRef, const PreservedAnalyses &);
using BeforeAnalysisFunc = void(StringRef, Any);
using AfterAnalysisFunc = void(StringRef, Any);
@ -199,20 +199,22 @@ public:
/// just been executed and constant reference to \p IR it operates on.
/// \p IR is guaranteed to be valid at this point.
template <typename IRUnitT, typename PassT>
void runAfterPass(const PassT &Pass, const IRUnitT &IR) const {
void runAfterPass(const PassT &Pass, const IRUnitT &IR,
const PreservedAnalyses &PA) const {
if (Callbacks)
for (auto &C : Callbacks->AfterPassCallbacks)
C(Pass.name(), llvm::Any(&IR));
C(Pass.name(), llvm::Any(&IR), PA);
}
/// AfterPassInvalidated instrumentation point - takes \p Pass instance
/// that has just been executed. For use when IR has been invalidated
/// by \p Pass execution.
template <typename IRUnitT, typename PassT>
void runAfterPassInvalidated(const PassT &Pass) const {
void runAfterPassInvalidated(const PassT &Pass,
const PreservedAnalyses &PA) const {
if (Callbacks)
for (auto &C : Callbacks->AfterPassInvalidatedCallbacks)
C(Pass.name());
C(Pass.name(), PA);
}
/// BeforeAnalysis instrumentation point - takes \p Analysis instance

View File

@ -519,7 +519,7 @@ public:
// Call onto PassInstrumentation's AfterPass callbacks immediately after
// running the pass.
PI.runAfterPass<IRUnitT>(*P, IR);
PI.runAfterPass<IRUnitT>(*P, IR, PassPA);
// Update the analysis manager as each pass runs and potentially
// invalidates analyses.
@ -1244,7 +1244,7 @@ public:
PassPA = Pass.run(F, FAM);
}
PI.runAfterPass(Pass, F);
PI.runAfterPass(Pass, F, PassPA);
// We know that the function pass couldn't have invalidated any other
// function's analyses (that's the contract of a function pass), so
@ -1369,8 +1369,9 @@ public:
// false).
if (!PI.runBeforePass<IRUnitT>(P, IR))
continue;
PA.intersect(P.run(IR, AM, std::forward<Ts>(Args)...));
PI.runAfterPass(P, IR);
PreservedAnalyses IterPA = P.run(IR, AM, std::forward<Ts>(Args)...);
PA.intersect(IterPA);
PI.runAfterPass(P, IR, IterPA);
}
return PA;
}

View File

@ -253,7 +253,7 @@ public:
// canonicalization pipeline.
if (PI.runBeforePass<Function>(LoopCanonicalizationFPM, F)) {
PA = LoopCanonicalizationFPM.run(F, AM);
PI.runAfterPass<Function>(LoopCanonicalizationFPM, F);
PI.runAfterPass<Function>(LoopCanonicalizationFPM, F, PA);
}
// Get the loop structure for this function
@ -337,9 +337,9 @@ public:
// Do not pass deleted Loop into the instrumentation.
if (Updater.skipCurrentLoop())
PI.runAfterPassInvalidated<Loop>(Pass);
PI.runAfterPassInvalidated<Loop>(Pass, PassPA);
else
PI.runAfterPass<Loop>(Pass, *L);
PI.runAfterPass<Loop>(Pass, *L, PassPA);
// FIXME: We should verify the set of analyses relevant to Loop passes
// are preserved.

View File

@ -85,9 +85,9 @@ PassManager<LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &,
}
if (UR.InvalidatedSCCs.count(C))
PI.runAfterPassInvalidated<LazyCallGraph::SCC>(*Pass);
PI.runAfterPassInvalidated<LazyCallGraph::SCC>(*Pass, PassPA);
else
PI.runAfterPass<LazyCallGraph::SCC>(*Pass, *C);
PI.runAfterPass<LazyCallGraph::SCC>(*Pass, *C, PassPA);
// Update the SCC if necessary.
C = UR.UpdatedC ? UR.UpdatedC : C;

View File

@ -99,7 +99,7 @@ Error MachineFunctionPassManager::run(Module &M,
// TODO: EmitSizeRemarks
PreservedAnalyses PassPA = P->run(MF, MFAM);
PI.runAfterPass(*P, MF);
PI.runAfterPass(*P, MF, PassPA);
MFAM.invalidate(MF, PassPA);
}
}

View File

@ -260,9 +260,13 @@ void TimePassesHandler::registerCallbacks(PassInstrumentationCallbacks &PIC) {
PIC.registerBeforeNonSkippedPassCallback(
[this](StringRef P, Any) { this->runBeforePass(P); });
PIC.registerAfterPassCallback(
[this](StringRef P, Any) { this->runAfterPass(P); });
[this](StringRef P, Any, const PreservedAnalyses &) {
this->runAfterPass(P);
});
PIC.registerAfterPassInvalidatedCallback(
[this](StringRef P) { this->runAfterPass(P); });
[this](StringRef P, const PreservedAnalyses &) {
this->runAfterPass(P);
});
PIC.registerBeforeAnalysisCallback(
[this](StringRef P, Any) { this->runBeforePass(P); });
PIC.registerAfterAnalysisCallback(

View File

@ -277,9 +277,13 @@ void PrintIRInstrumentation::registerCallbacks(
if (llvm::shouldPrintAfterPass()) {
PIC.registerAfterPassCallback(
[this](StringRef P, Any IR) { this->printAfterPass(P, IR); });
[this](StringRef P, Any IR, const PreservedAnalyses &) {
this->printAfterPass(P, IR);
});
PIC.registerAfterPassInvalidatedCallback(
[this](StringRef P) { this->printAfterPassInvalidated(P); });
[this](StringRef P, const PreservedAnalyses &) {
this->printAfterPassInvalidated(P);
});
}
}

View File

@ -47,9 +47,9 @@ PassManager<Loop, LoopAnalysisManager, LoopStandardAnalysisResults &,
// do not pass deleted Loop into the instrumentation
if (U.skipCurrentLoop())
PI.runAfterPassInvalidated<Loop>(*Pass);
PI.runAfterPassInvalidated<Loop>(*Pass, PassPA);
else
PI.runAfterPass<Loop>(*Pass, L);
PI.runAfterPass<Loop>(*Pass, L, PassPA);
// If the loop was deleted, abort the run and return to the outer walk.
if (U.skipCurrentLoop()) {

View File

@ -322,8 +322,10 @@ struct MockPassInstrumentationCallbacks {
MOCK_METHOD2(runBeforePass, bool(StringRef PassID, llvm::Any));
MOCK_METHOD2(runBeforeSkippedPass, void(StringRef PassID, llvm::Any));
MOCK_METHOD2(runBeforeNonSkippedPass, void(StringRef PassID, llvm::Any));
MOCK_METHOD2(runAfterPass, void(StringRef PassID, llvm::Any));
MOCK_METHOD1(runAfterPassInvalidated, void(StringRef PassID));
MOCK_METHOD3(runAfterPass,
void(StringRef PassID, llvm::Any, const PreservedAnalyses &PA));
MOCK_METHOD2(runAfterPassInvalidated,
void(StringRef PassID, const PreservedAnalyses &PA));
MOCK_METHOD2(runBeforeAnalysis, void(StringRef PassID, llvm::Any));
MOCK_METHOD2(runAfterAnalysis, void(StringRef PassID, llvm::Any));
@ -340,9 +342,13 @@ struct MockPassInstrumentationCallbacks {
this->runBeforeNonSkippedPass(P, IR);
});
Callbacks.registerAfterPassCallback(
[this](StringRef P, llvm::Any IR) { this->runAfterPass(P, IR); });
[this](StringRef P, llvm::Any IR, const PreservedAnalyses &PA) {
this->runAfterPass(P, IR, PA);
});
Callbacks.registerAfterPassInvalidatedCallback(
[this](StringRef P) { this->runAfterPassInvalidated(P); });
[this](StringRef P, const PreservedAnalyses &PA) {
this->runAfterPassInvalidated(P, PA);
});
Callbacks.registerBeforeAnalysisCallback([this](StringRef P, llvm::Any IR) {
return this->runBeforeAnalysis(P, IR);
});
@ -365,7 +371,8 @@ struct MockPassInstrumentationCallbacks {
EXPECT_CALL(*this, runBeforeNonSkippedPass(Not(HasNameRegex("Mock")),
HasName(IRName)))
.Times(AnyNumber());
EXPECT_CALL(*this, runAfterPass(Not(HasNameRegex("Mock")), HasName(IRName)))
EXPECT_CALL(*this,
runAfterPass(Not(HasNameRegex("Mock")), HasName(IRName), _))
.Times(AnyNumber());
EXPECT_CALL(*this,
runBeforeAnalysis(Not(HasNameRegex("Mock")), HasName(IRName)))
@ -528,8 +535,8 @@ TEST_F(ModuleCallbacksTest, InstrumentedPasses) {
CallbacksHandle,
runAfterAnalysis(HasNameRegex("MockAnalysisHandle"), HasName("<string>")))
.InSequence(PISequence);
EXPECT_CALL(CallbacksHandle,
runAfterPass(HasNameRegex("MockPassHandle"), HasName("<string>")))
EXPECT_CALL(CallbacksHandle, runAfterPass(HasNameRegex("MockPassHandle"),
HasName("<string>"), _))
.InSequence(PISequence);
// No passes are skipped, so there should be no calls to
@ -569,7 +576,8 @@ TEST_F(ModuleCallbacksTest, InstrumentedSkippedPasses) {
EXPECT_CALL(CallbacksHandle,
runBeforeNonSkippedPass(HasNameRegex("MockPassHandle"), _))
.Times(0);
EXPECT_CALL(CallbacksHandle, runAfterPass(HasNameRegex("MockPassHandle"), _))
EXPECT_CALL(CallbacksHandle,
runAfterPass(HasNameRegex("MockPassHandle"), _, _))
.Times(0);
EXPECT_CALL(CallbacksHandle,
runBeforeAnalysis(HasNameRegex("MockAnalysisHandle"), _))
@ -609,20 +617,20 @@ TEST_F(ModuleCallbacksTest, InstrumentedSkippedPasses) {
// The `runAfterPass` checks are the same as these of
// `runBeforeNonSkippedPass`.
EXPECT_CALL(CallbacksHandle, runAfterPass(HasNameRegex("PassManager"), _))
EXPECT_CALL(CallbacksHandle, runAfterPass(HasNameRegex("PassManager"), _, _))
.Times(5);
EXPECT_CALL(CallbacksHandle,
runAfterPass(HasNameRegex("ModuleToFunctionPassAdaptor"), _))
runAfterPass(HasNameRegex("ModuleToFunctionPassAdaptor"), _, _))
.Times(1);
EXPECT_CALL(
CallbacksHandle,
runAfterPass(HasNameRegex("ModuleToPostOrderCGSCCPassAdaptor"), _))
runAfterPass(HasNameRegex("ModuleToPostOrderCGSCCPassAdaptor"), _, _))
.Times(1);
EXPECT_CALL(CallbacksHandle,
runAfterPass(HasNameRegex("CGSCCToFunctionPassAdaptor"), _))
runAfterPass(HasNameRegex("CGSCCToFunctionPassAdaptor"), _, _))
.Times(1);
EXPECT_CALL(CallbacksHandle,
runAfterPass(HasNameRegex("FunctionToLoopPassAdaptor"), _))
runAfterPass(HasNameRegex("FunctionToLoopPassAdaptor"), _, _))
.Times(1);
// Ignore analyses introduced by adaptor passes.
@ -701,7 +709,7 @@ TEST_F(FunctionCallbacksTest, InstrumentedPasses) {
runAfterAnalysis(HasNameRegex("MockAnalysisHandle"), HasName("foo")))
.InSequence(PISequence);
EXPECT_CALL(CallbacksHandle,
runAfterPass(HasNameRegex("MockPassHandle"), HasName("foo")))
runAfterPass(HasNameRegex("MockPassHandle"), HasName("foo"), _))
.InSequence(PISequence);
// No passes are skipped, so there should be no calls to
@ -713,7 +721,7 @@ TEST_F(FunctionCallbacksTest, InstrumentedPasses) {
// Our mock pass does not invalidate IR.
EXPECT_CALL(CallbacksHandle,
runAfterPassInvalidated(HasNameRegex("MockPassHandle")))
runAfterPassInvalidated(HasNameRegex("MockPassHandle"), _))
.Times(0);
StringRef PipelineText = "test-transform";
@ -746,12 +754,14 @@ TEST_F(FunctionCallbacksTest, InstrumentedSkippedPasses) {
EXPECT_CALL(CallbacksHandle,
runBeforeNonSkippedPass(HasNameRegex("MockPassHandle"), _))
.Times(0);
EXPECT_CALL(CallbacksHandle, runAfterPass(HasNameRegex("MockPassHandle"), _))
EXPECT_CALL(CallbacksHandle,
runAfterPass(HasNameRegex("MockPassHandle"), _, _))
.Times(0);
EXPECT_CALL(CallbacksHandle,
runAfterPassInvalidated(HasNameRegex("MockPassHandle")))
runAfterPassInvalidated(HasNameRegex("MockPassHandle"), _))
.Times(0);
EXPECT_CALL(CallbacksHandle, runAfterPass(HasNameRegex("MockPassHandle"), _))
EXPECT_CALL(CallbacksHandle,
runAfterPass(HasNameRegex("MockPassHandle"), _, _))
.Times(0);
EXPECT_CALL(CallbacksHandle,
runBeforeAnalysis(HasNameRegex("MockAnalysisHandle"), _))
@ -807,12 +817,12 @@ TEST_F(LoopCallbacksTest, InstrumentedPasses) {
runAfterAnalysis(HasNameRegex("MockAnalysisHandle"), HasName("loop")))
.InSequence(PISequence);
EXPECT_CALL(CallbacksHandle,
runAfterPass(HasNameRegex("MockPassHandle"), HasName("loop")))
runAfterPass(HasNameRegex("MockPassHandle"), HasName("loop"), _))
.InSequence(PISequence);
// Our mock pass does not invalidate IR.
EXPECT_CALL(CallbacksHandle,
runAfterPassInvalidated(HasNameRegex("MockPassHandle")))
runAfterPassInvalidated(HasNameRegex("MockPassHandle"), _))
.Times(0);
// No passes are skipped, so there should be no calls to
@ -859,15 +869,15 @@ TEST_F(LoopCallbacksTest, InstrumentedInvalidatingPasses) {
runAfterAnalysis(HasNameRegex("MockAnalysisHandle"), HasName("loop")))
.InSequence(PISequence);
EXPECT_CALL(CallbacksHandle,
runAfterPassInvalidated(HasNameRegex("MockPassHandle")))
runAfterPassInvalidated(HasNameRegex("MockPassHandle"), _))
.InSequence(PISequence);
EXPECT_CALL(CallbacksHandle,
runAfterPassInvalidated(HasNameRegex("^PassManager")))
runAfterPassInvalidated(HasNameRegex("^PassManager"), _))
.InSequence(PISequence);
// Our mock pass invalidates IR, thus normal runAfterPass is never called.
EXPECT_CALL(CallbacksHandle,
runAfterPass(HasNameRegex("MockPassHandle"), HasName("loop")))
runAfterPass(HasNameRegex("MockPassHandle"), HasName("loop"), _))
.Times(0);
StringRef PipelineText = "test-transform";
@ -901,10 +911,11 @@ TEST_F(LoopCallbacksTest, InstrumentedSkippedPasses) {
EXPECT_CALL(CallbacksHandle,
runBeforeNonSkippedPass(HasNameRegex("MockPassHandle"), _))
.Times(0);
EXPECT_CALL(CallbacksHandle, runAfterPass(HasNameRegex("MockPassHandle"), _))
EXPECT_CALL(CallbacksHandle,
runAfterPass(HasNameRegex("MockPassHandle"), _, _))
.Times(0);
EXPECT_CALL(CallbacksHandle,
runAfterPassInvalidated(HasNameRegex("MockPassHandle")))
runAfterPassInvalidated(HasNameRegex("MockPassHandle"), _))
.Times(0);
EXPECT_CALL(CallbacksHandle,
runBeforeAnalysis(HasNameRegex("MockAnalysisHandle"), _))
@ -960,12 +971,12 @@ TEST_F(CGSCCCallbacksTest, InstrumentedPasses) {
runAfterAnalysis(HasNameRegex("MockAnalysisHandle"), HasName("(foo)")))
.InSequence(PISequence);
EXPECT_CALL(CallbacksHandle,
runAfterPass(HasNameRegex("MockPassHandle"), HasName("(foo)")))
runAfterPass(HasNameRegex("MockPassHandle"), HasName("(foo)"), _))
.InSequence(PISequence);
// Our mock pass does not invalidate IR.
EXPECT_CALL(CallbacksHandle,
runAfterPassInvalidated(HasNameRegex("MockPassHandle")))
runAfterPassInvalidated(HasNameRegex("MockPassHandle"), _))
.Times(0);
// No passes are skipped, so there should be no calls to
@ -1012,15 +1023,15 @@ TEST_F(CGSCCCallbacksTest, InstrumentedInvalidatingPasses) {
runAfterAnalysis(HasNameRegex("MockAnalysisHandle"), HasName("(foo)")))
.InSequence(PISequence);
EXPECT_CALL(CallbacksHandle,
runAfterPassInvalidated(HasNameRegex("MockPassHandle")))
runAfterPassInvalidated(HasNameRegex("MockPassHandle"), _))
.InSequence(PISequence);
EXPECT_CALL(CallbacksHandle,
runAfterPassInvalidated(HasNameRegex("^PassManager")))
runAfterPassInvalidated(HasNameRegex("^PassManager"), _))
.InSequence(PISequence);
// Our mock pass does invalidate IR, thus normal runAfterPass is never called.
EXPECT_CALL(CallbacksHandle,
runAfterPass(HasNameRegex("MockPassHandle"), HasName("(foo)")))
runAfterPass(HasNameRegex("MockPassHandle"), HasName("(foo)"), _))
.Times(0);
StringRef PipelineText = "test-transform";
@ -1055,10 +1066,11 @@ TEST_F(CGSCCCallbacksTest, InstrumentedSkippedPasses) {
EXPECT_CALL(CallbacksHandle,
runBeforeNonSkippedPass(HasNameRegex("MockPassHandle"), _))
.Times(0);
EXPECT_CALL(CallbacksHandle, runAfterPass(HasNameRegex("MockPassHandle"), _))
EXPECT_CALL(CallbacksHandle,
runAfterPass(HasNameRegex("MockPassHandle"), _, _))
.Times(0);
EXPECT_CALL(CallbacksHandle,
runAfterPassInvalidated(HasNameRegex("MockPassHandle")))
runAfterPassInvalidated(HasNameRegex("MockPassHandle"), _))
.Times(0);
EXPECT_CALL(CallbacksHandle,
runBeforeAnalysis(HasNameRegex("MockAnalysisHandle"), _))

View File

@ -134,8 +134,8 @@ TEST(TimePassesTest, CustomOut) {
// Pretending that passes are running to trigger the timers.
PI.runBeforePass(Pass1, M);
PI.runBeforePass(Pass2, M);
PI.runAfterPass(Pass2, M);
PI.runAfterPass(Pass1, M);
PI.runAfterPass(Pass2, M, PreservedAnalyses::all());
PI.runAfterPass(Pass1, M, PreservedAnalyses::all());
// Generating report.
TimePasses->print();
@ -154,7 +154,7 @@ TEST(TimePassesTest, CustomOut) {
// Now trigger just a single pass to populate timers again.
PI.runBeforePass(Pass2, M);
PI.runAfterPass(Pass2, M);
PI.runAfterPass(Pass2, M, PreservedAnalyses::all());
// Generate report by deleting the handler.
TimePasses.reset();