[PM] Port LoopInfo to the new pass manager, adding both a LoopAnalysis

pass and a LoopPrinterPass with the expected associated wiring.

I've added a RUN line to the only test case (!!!) we have that actually
prints loops. Everything seems to be working.

This is somewhat exciting as this is the first analysis using another
analysis to go in for the new pass manager. =D I also believe it is the
last analysis necessary for porting instcombine, but of course I may yet
discover more.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226560 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chandler Carruth
2015-01-20 10:58:50 +00:00
parent 1540633fdb
commit a37512049c
5 changed files with 63 additions and 0 deletions

View File

@@ -42,6 +42,11 @@
namespace llvm {
// FIXME: Replace this brittle forward declaration with the include of the new
// PassManager.h when doing so doesn't break the PassManagerBuilder.
template <typename IRUnitT> class AnalysisManager;
class PreservedAnalyses;
template<typename T>
inline void RemoveFromVector(std::vector<T*> &V, T *N) {
typename std::vector<T*>::iterator I = std::find(V.begin(), V.end(), N);
@@ -716,6 +721,39 @@ template <> struct GraphTraits<Loop*> {
}
};
/// \brief Analysis pass that exposes the \c LoopInfo for a function.
class LoopAnalysis {
static char PassID;
public:
typedef LoopInfo Result;
/// \brief Opaque, unique identifier for this analysis pass.
static void *ID() { return (void *)&PassID; }
/// \brief Provide a name for the analysis for debugging and logging.
static StringRef name() { return "LoopAnalysis"; }
LoopAnalysis() {}
LoopAnalysis(const LoopAnalysis &Arg) {}
LoopAnalysis(LoopAnalysis &&Arg) {}
LoopAnalysis &operator=(const LoopAnalysis &RHS) { return *this; }
LoopAnalysis &operator=(LoopAnalysis &&RHS) { return *this; }
LoopInfo run(Function &F, AnalysisManager<Function> *AM);
};
/// \brief Printer pass for the \c LoopAnalysis results.
class LoopPrinterPass {
raw_ostream &OS;
public:
explicit LoopPrinterPass(raw_ostream &OS) : OS(OS) {}
PreservedAnalyses run(Function &F, AnalysisManager<Function> *AM);
static StringRef name() { return "LoopPrinterPass"; }
};
/// \brief The legacy pass manager's analysis pass to compute loop information.
class LoopInfoWrapperPass : public FunctionPass {
LoopInfo LI;