summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2013-11-22 00:43:29 +0000
committerChandler Carruth <chandlerc@gmail.com>2013-11-22 00:43:29 +0000
commitd793a053ad9839e40bf59293b8f2190dc5b21dc1 (patch)
tree30aadcdabaf87f169c9a5b59af0a982b4c01cb6d /unittests
parent8d56c5923587be937872678fd67501c3d21578e4 (diff)
downloadllvm-d793a053ad9839e40bf59293b8f2190dc5b21dc1.tar.gz
llvm-d793a053ad9839e40bf59293b8f2190dc5b21dc1.tar.bz2
llvm-d793a053ad9839e40bf59293b8f2190dc5b21dc1.tar.xz
[PM] Switch analysis managers to be threaded through the run methods
rather than the constructors of passes. This simplifies the APIs of passes significantly and removes an error prone pattern where the *same* manager had to be given to every different layer. With the new API the analysis managers themselves will have to be cross connected with proxy analyses that allow a pass at one layer to query for the analysis manager of another layer. The proxy will both expose a handle to the other layer's manager and it will provide the invalidation hooks to ensure things remain consistent across layers. Finally, the outer-most analysis manager has to be passed to the run method of the outer-most pass manager. The rest of the propagation is automatic. I've used SFINAE again to allow passes to completely disregard the analysis manager if they don't need or want to care. This helps keep simple things simple for users of the new pass manager. Also, the system specifically supports passing a null pointer into the outer-most run method if your pass pipeline neither needs nor wants to deal with analyses. I find this of dubious utility as while some *passes* don't care about analysis, I'm not sure there are any real-world users of the pass manager itself that need to avoid even creating an analysis manager. But it is easy to support, so there we go. Finally I renamed the module proxy for the function analysis manager to the more verbose but less confusing name of FunctionAnalysisManagerModuleProxy. I hate this name, but I have no idea what else to name these things. I'm expecting in the fullness of time to potentially have the complete cross product of types at the proxy layer: {Module,SCC,Function,Loop,Region}AnalysisManager{Module,SCC,Function,Loop,Region}Proxy (except for XAnalysisManagerXProxy which doesn't make any sense) This should make it somewhat easier to do the next phases which is to build the upward proxy and get its invalidation correct, as well as to make the invalidation within the Module -> Function mapping pass be more fine grained so as to invalidate fewer fuction analyses. After all of the proxy analyses are done and the invalidation working, I'll finally be able to start working on the next two fun fronts: how to adapt an existing pass to work in both the legacy pass world and the new one, and building the SCC, Loop, and Region counterparts. Fun times! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195400 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/IR/PassManagerTest.cpp42
1 files changed, 20 insertions, 22 deletions
diff --git a/unittests/IR/PassManagerTest.cpp b/unittests/IR/PassManagerTest.cpp
index d23d85b882..94fe99a3aa 100644
--- a/unittests/IR/PassManagerTest.cpp
+++ b/unittests/IR/PassManagerTest.cpp
@@ -73,26 +73,24 @@ struct TestPreservingModulePass {
struct TestMinPreservingModulePass {
PreservedAnalyses run(Module *M) {
PreservedAnalyses PA;
- PA.preserve<FunctionAnalysisModuleProxy>();
+ PA.preserve<FunctionAnalysisManagerModuleProxy>();
return PA;
}
};
struct TestFunctionPass {
- TestFunctionPass(FunctionAnalysisManager &AM, int &RunCount,
- int &AnalyzedInstrCount)
- : AM(AM), RunCount(RunCount), AnalyzedInstrCount(AnalyzedInstrCount) {}
+ TestFunctionPass(int &RunCount, int &AnalyzedInstrCount)
+ : RunCount(RunCount), AnalyzedInstrCount(AnalyzedInstrCount) {}
- PreservedAnalyses run(Function *F) {
+ PreservedAnalyses run(Function *F, FunctionAnalysisManager *AM) {
++RunCount;
- const TestAnalysisPass::Result &AR = AM.getResult<TestAnalysisPass>(F);
+ const TestAnalysisPass::Result &AR = AM->getResult<TestAnalysisPass>(F);
AnalyzedInstrCount += AR.InstructionCount;
return PreservedAnalyses::all();
}
- FunctionAnalysisManager &AM;
int &RunCount;
int &AnalyzedInstrCount;
};
@@ -129,45 +127,45 @@ TEST_F(PassManagerTest, Basic) {
FAM.registerPass(TestAnalysisPass(AnalysisRuns));
ModuleAnalysisManager MAM;
- MAM.registerPass(FunctionAnalysisModuleProxy(FAM));
+ MAM.registerPass(FunctionAnalysisManagerModuleProxy(FAM));
- ModulePassManager MPM(&MAM);
+ ModulePassManager MPM;
// Count the runs over a Function.
- FunctionPassManager FPM1(&FAM);
+ FunctionPassManager FPM1;
int FunctionPassRunCount1 = 0;
int AnalyzedInstrCount1 = 0;
- FPM1.addPass(TestFunctionPass(FAM, FunctionPassRunCount1, AnalyzedInstrCount1));
- MPM.addPass(createModuleToFunctionPassAdaptor(FPM1, &MAM));
+ FPM1.addPass(TestFunctionPass(FunctionPassRunCount1, AnalyzedInstrCount1));
+ MPM.addPass(createModuleToFunctionPassAdaptor(FPM1));
// Count the runs over a module.
int ModulePassRunCount = 0;
MPM.addPass(TestModulePass(ModulePassRunCount));
// Count the runs over a Function in a separate manager.
- FunctionPassManager FPM2(&FAM);
+ FunctionPassManager FPM2;
int FunctionPassRunCount2 = 0;
int AnalyzedInstrCount2 = 0;
- FPM2.addPass(TestFunctionPass(FAM, FunctionPassRunCount2, AnalyzedInstrCount2));
- MPM.addPass(createModuleToFunctionPassAdaptor(FPM2, &MAM));
+ FPM2.addPass(TestFunctionPass(FunctionPassRunCount2, AnalyzedInstrCount2));
+ MPM.addPass(createModuleToFunctionPassAdaptor(FPM2));
// A third function pass manager but with only preserving intervening passes.
MPM.addPass(TestPreservingModulePass());
- FunctionPassManager FPM3(&FAM);
+ FunctionPassManager FPM3;
int FunctionPassRunCount3 = 0;
int AnalyzedInstrCount3 = 0;
- FPM3.addPass(TestFunctionPass(FAM, FunctionPassRunCount3, AnalyzedInstrCount3));
- MPM.addPass(createModuleToFunctionPassAdaptor(FPM3, &MAM));
+ FPM3.addPass(TestFunctionPass(FunctionPassRunCount3, AnalyzedInstrCount3));
+ MPM.addPass(createModuleToFunctionPassAdaptor(FPM3));
// A fourth function pass manager but with a minimal intervening passes.
MPM.addPass(TestMinPreservingModulePass());
- FunctionPassManager FPM4(&FAM);
+ FunctionPassManager FPM4;
int FunctionPassRunCount4 = 0;
int AnalyzedInstrCount4 = 0;
- FPM4.addPass(TestFunctionPass(FAM, FunctionPassRunCount4, AnalyzedInstrCount4));
- MPM.addPass(createModuleToFunctionPassAdaptor(FPM4, &MAM));
+ FPM4.addPass(TestFunctionPass(FunctionPassRunCount4, AnalyzedInstrCount4));
+ MPM.addPass(createModuleToFunctionPassAdaptor(FPM4));
- MPM.run(M.get());
+ MPM.run(M.get(), &MAM);
// Validate module pass counters.
EXPECT_EQ(1, ModulePassRunCount);