diff options
-rw-r--r-- | llvm/include/llvm/Analysis/LoopPassManager.h | 5 | ||||
-rw-r--r-- | llvm/include/llvm/IR/PassManager.h | 10 | ||||
-rw-r--r-- | llvm/lib/Analysis/LoopPassManager.cpp | 19 | ||||
-rw-r--r-- | llvm/unittests/Analysis/LoopPassManagerTest.cpp | 2 |
4 files changed, 35 insertions, 1 deletions
diff --git a/llvm/include/llvm/Analysis/LoopPassManager.h b/llvm/include/llvm/Analysis/LoopPassManager.h index e7d9578c1f8..a8955185125 100644 --- a/llvm/include/llvm/Analysis/LoopPassManager.h +++ b/llvm/include/llvm/Analysis/LoopPassManager.h @@ -48,6 +48,9 @@ extern template class OuterAnalysisManagerProxy<FunctionAnalysisManager, Loop>; typedef OuterAnalysisManagerProxy<FunctionAnalysisManager, Loop> FunctionAnalysisManagerLoopProxy; +/// Returns the minimum set of Analyses that all loop passes must preserve. +PreservedAnalyses getLoopPassPreservedAnalyses(); + /// \brief Adaptor that maps from a function to its loops. /// /// Designed to allow composition of a LoopPass(Manager) and a @@ -101,6 +104,8 @@ public: // post-order. for (auto *L : reverse(Loops)) { PreservedAnalyses PassPA = Pass.run(*L, LAM); + assert(PassPA.preserved(getLoopPassPreservedAnalyses()) && + "Loop passes must preserve all relevant analyses"); // We know that the loop pass couldn't have invalidated any other loop's // analyses (that's the contract of a loop pass), so directly handle the diff --git a/llvm/include/llvm/IR/PassManager.h b/llvm/include/llvm/IR/PassManager.h index 2f9a8f243e0..da4b708c335 100644 --- a/llvm/include/llvm/IR/PassManager.h +++ b/llvm/include/llvm/IR/PassManager.h @@ -144,6 +144,16 @@ public: PreservedPassIDs.count(PassID); } + /// \brief Query whether all of the analyses in the set are preserved. + bool preserved(PreservedAnalyses Arg) { + if (Arg.areAllPreserved()) + return areAllPreserved(); + for (void *P : Arg.PreservedPassIDs) + if (!preserved(P)) + return false; + return true; + } + /// \brief Test whether all passes are preserved. /// /// This is used primarily to optimize for the case of no changes which will diff --git a/llvm/lib/Analysis/LoopPassManager.cpp b/llvm/lib/Analysis/LoopPassManager.cpp index 76210fa89c0..8bac19a5821 100644 --- a/llvm/lib/Analysis/LoopPassManager.cpp +++ b/llvm/lib/Analysis/LoopPassManager.cpp @@ -8,6 +8,12 @@ //===----------------------------------------------------------------------===// #include "llvm/Analysis/LoopPassManager.h" +#include "llvm/Analysis/BasicAliasAnalysis.h" +#include "llvm/Analysis/GlobalsModRef.h" +#include "llvm/Analysis/LoopInfo.h" +#include "llvm/Analysis/ScalarEvolution.h" +#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" +#include "llvm/IR/Dominators.h" using namespace llvm; @@ -18,3 +24,16 @@ template class AnalysisManager<Loop>; template class InnerAnalysisManagerProxy<LoopAnalysisManager, Function>; template class OuterAnalysisManagerProxy<FunctionAnalysisManager, Loop>; } + +PreservedAnalyses llvm::getLoopPassPreservedAnalyses() { + PreservedAnalyses PA; + PA.preserve<DominatorTreeAnalysis>(); + PA.preserve<LoopAnalysis>(); + PA.preserve<ScalarEvolutionAnalysis>(); + // TODO: What we really want to do here is preserve an AA category, but that + // concept doesn't exist yet. + PA.preserve<BasicAA>(); + PA.preserve<GlobalsAA>(); + PA.preserve<SCEVAA>(); + return PA; +} diff --git a/llvm/unittests/Analysis/LoopPassManagerTest.cpp b/llvm/unittests/Analysis/LoopPassManagerTest.cpp index 3cbe203e14d..5858e174aab 100644 --- a/llvm/unittests/Analysis/LoopPassManagerTest.cpp +++ b/llvm/unittests/Analysis/LoopPassManagerTest.cpp @@ -92,7 +92,7 @@ public: TestLoopInvalidatingPass(StringRef LoopName) : Name(LoopName) {} PreservedAnalyses run(Loop &L, AnalysisManager<Loop> &AM) { - return L.getName() == Name ? PreservedAnalyses::none() + return L.getName() == Name ? getLoopPassPreservedAnalyses() : PreservedAnalyses::all(); } |