summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR/PassManagerTest.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2016-12-10 06:34:44 +0000
committerChandler Carruth <chandlerc@gmail.com>2016-12-10 06:34:44 +0000
commit6b9816477b6bbf08f74e1188bc44bbb2942c3503 (patch)
tree83cf70d5e0bc4167beadebc930ae8da80dbae751 /llvm/unittests/IR/PassManagerTest.cpp
parenta39b650d72641f33e86a277c7278c9aa16f5bbc7 (diff)
downloadbcm5719-llvm-6b9816477b6bbf08f74e1188bc44bbb2942c3503.tar.gz
bcm5719-llvm-6b9816477b6bbf08f74e1188bc44bbb2942c3503.zip
[PM] Support invalidation of inner analysis managers from a pass over the outer IR unit.
Summary: This never really got implemented, and was very hard to test before a lot of the refactoring changes to make things more robust. But now we can test it thoroughly and cleanly, especially at the CGSCC level. The core idea is that when an inner analysis manager proxy receives the invalidation event for the outer IR unit, it needs to walk the inner IR units and propagate it to the inner analysis manager for each of those units. For example, each function in the SCC needs to get an invalidation event when the SCC gets one. The function / module interaction is somewhat boring here. This really becomes interesting in the face of analysis-backed IR units. This patch effectively handles all of the CGSCC layer's needs -- both invalidating SCC analysis and invalidating function analysis when an SCC gets invalidated. However, this second aspect doesn't really handle the LoopAnalysisManager well at this point. That one will need some change of design in order to fully integrate, because unlike the call graph, the entire function behind a LoopAnalysis's results can vanish out from under us, and we won't even have a cached API to access. I'd like to try to separate solving the loop problems into a subsequent patch though in order to keep this more focused so I've adapted them to the API and updated the tests that immediately fail, but I've not added the level of testing and validation at that layer that I have at the CGSCC layer. An important aspect of this change is that the proxy for the FunctionAnalysisManager at the SCC pass layer doesn't work like the other proxies for an inner IR unit as it doesn't directly manage the FunctionAnalysisManager and invalidation or clearing of it. This would create an ever worsening problem of dual ownership of this responsibility, split between the module-level FAM proxy and this SCC-level FAM proxy. Instead, this patch changes the SCC-level FAM proxy to work in terms of the module-level proxy and defer to it to handle much of the updates. It only does SCC-specific invalidation. This will become more important in subsequent patches that support more complex invalidaiton scenarios. Reviewers: jlebar Subscribers: mehdi_amini, mcrosier, mzolotukhin, llvm-commits Differential Revision: https://reviews.llvm.org/D27197 llvm-svn: 289317
Diffstat (limited to 'llvm/unittests/IR/PassManagerTest.cpp')
-rw-r--r--llvm/unittests/IR/PassManagerTest.cpp40
1 files changed, 15 insertions, 25 deletions
diff --git a/llvm/unittests/IR/PassManagerTest.cpp b/llvm/unittests/IR/PassManagerTest.cpp
index 2b977b464ad..d7515ba6b7d 100644
--- a/llvm/unittests/IR/PassManagerTest.cpp
+++ b/llvm/unittests/IR/PassManagerTest.cpp
@@ -91,19 +91,6 @@ struct TestPreservingModulePass : PassInfoMixin<TestPreservingModulePass> {
}
};
-struct TestMinPreservingModulePass
- : PassInfoMixin<TestMinPreservingModulePass> {
- PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM) {
- PreservedAnalyses PA;
-
- // Force running an analysis.
- (void)AM.getResult<TestModuleAnalysis>(M);
-
- PA.preserve<FunctionAnalysisManagerModuleProxy>();
- return PA;
- }
-};
-
struct TestFunctionPass : PassInfoMixin<TestFunctionPass> {
TestFunctionPass(int &RunCount, int &AnalyzedInstrCount,
int &AnalyzedFunctionCount,
@@ -215,11 +202,11 @@ TEST_F(PassManagerTest, BasicPreservedAnalyses) {
}
TEST_F(PassManagerTest, Basic) {
- FunctionAnalysisManager FAM;
+ FunctionAnalysisManager FAM(/*DebugLogging*/ true);
int FunctionAnalysisRuns = 0;
FAM.registerPass([&] { return TestFunctionAnalysis(FunctionAnalysisRuns); });
- ModuleAnalysisManager MAM;
+ ModuleAnalysisManager MAM(/*DebugLogging*/ true);
int ModuleAnalysisRuns = 0;
MAM.registerPass([&] { return TestModuleAnalysis(ModuleAnalysisRuns); });
MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
@@ -233,11 +220,11 @@ TEST_F(PassManagerTest, Basic) {
int AnalyzedFunctionCount1 = 0;
{
// Pointless scoped copy to test move assignment.
- ModulePassManager NestedMPM;
+ ModulePassManager NestedMPM(/*DebugLogging*/ true);
FunctionPassManager FPM;
{
// Pointless scope to test move assignment.
- FunctionPassManager NestedFPM;
+ FunctionPassManager NestedFPM(/*DebugLogging*/ true);
NestedFPM.addPass(TestFunctionPass(
FunctionPassRunCount1, AnalyzedInstrCount1, AnalyzedFunctionCount1));
FPM = std::move(NestedFPM);
@@ -255,7 +242,7 @@ TEST_F(PassManagerTest, Basic) {
int AnalyzedInstrCount2 = 0;
int AnalyzedFunctionCount2 = 0;
{
- FunctionPassManager FPM;
+ FunctionPassManager FPM(/*DebugLogging*/ true);
FPM.addPass(TestFunctionPass(FunctionPassRunCount2, AnalyzedInstrCount2,
AnalyzedFunctionCount2));
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
@@ -268,15 +255,16 @@ TEST_F(PassManagerTest, Basic) {
int AnalyzedInstrCount3 = 0;
int AnalyzedFunctionCount3 = 0;
{
- FunctionPassManager FPM;
+ FunctionPassManager FPM(/*DebugLogging*/ true);
FPM.addPass(TestFunctionPass(FunctionPassRunCount3, AnalyzedInstrCount3,
AnalyzedFunctionCount3));
FPM.addPass(TestInvalidationFunctionPass("f"));
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
}
- // A fourth function pass manager but with a minimal intervening passes.
- MPM.addPass(TestMinPreservingModulePass());
+ // A fourth function pass manager but with only preserving intervening
+ // passes but triggering the module analysis.
+ MPM.addPass(RequireAnalysisPass<TestModuleAnalysis, Module>());
int FunctionPassRunCount4 = 0;
int AnalyzedInstrCount4 = 0;
int AnalyzedFunctionCount4 = 0;
@@ -287,12 +275,13 @@ TEST_F(PassManagerTest, Basic) {
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
}
- // A fifth function pass manager but which uses only cached results.
+ // A fifth function pass manager which invalidates one function first but
+ // uses only cached results.
int FunctionPassRunCount5 = 0;
int AnalyzedInstrCount5 = 0;
int AnalyzedFunctionCount5 = 0;
{
- FunctionPassManager FPM;
+ FunctionPassManager FPM(/*DebugLogging*/ true);
FPM.addPass(TestInvalidationFunctionPass("f"));
FPM.addPass(TestFunctionPass(FunctionPassRunCount5, AnalyzedInstrCount5,
AnalyzedFunctionCount5,
@@ -317,16 +306,17 @@ TEST_F(PassManagerTest, Basic) {
EXPECT_EQ(0, AnalyzedFunctionCount3);
EXPECT_EQ(3, FunctionPassRunCount4);
EXPECT_EQ(5, AnalyzedInstrCount4);
- EXPECT_EQ(0, AnalyzedFunctionCount4);
+ EXPECT_EQ(9, AnalyzedFunctionCount4);
EXPECT_EQ(3, FunctionPassRunCount5);
EXPECT_EQ(2, AnalyzedInstrCount5); // Only 'g' and 'h' were cached.
- EXPECT_EQ(0, AnalyzedFunctionCount5);
+ EXPECT_EQ(9, AnalyzedFunctionCount5);
// Validate the analysis counters:
// first run over 3 functions, then module pass invalidates
// second run over 3 functions, nothing invalidates
// third run over 0 functions, but 1 function invalidated
// fourth run over 1 function
+ // fifth run invalidates 1 function first, but runs over 0 functions
EXPECT_EQ(7, FunctionAnalysisRuns);
EXPECT_EQ(1, ModuleAnalysisRuns);
OpenPOWER on IntegriCloud