PM: Check that loop passes preserve a basic set of analyses

A loop pass that didn't preserve this entire set of passes wouldn't
play well with other loop passes, since these are generally a basic
requirement to do any interesting transformations to a loop.

Adds a helper to get the set of analyses a loop pass should preserve,
and checks that any loop pass we run satisfies the requirement.

llvm-svn: 268444
This commit is contained in:
Justin Bogner 2016-05-03 21:35:08 +00:00
parent 206fb97bf8
commit 7c792839af
4 changed files with 35 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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();
}