diff options
Diffstat (limited to 'include/llvm/Analysis/LoopInfo.h')
-rw-r--r-- | include/llvm/Analysis/LoopInfo.h | 57 |
1 files changed, 23 insertions, 34 deletions
diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h index 70e636ce1f3d..35dc6bcb6864 100644 --- a/include/llvm/Analysis/LoopInfo.h +++ b/include/llvm/Analysis/LoopInfo.h @@ -25,6 +25,12 @@ // * the loop depth // * etc... // +// Note that this analysis specifically identifies *Loops* not cycles or SCCs +// in the CFG. There can be strongly connected compontents in the CFG which +// this analysis will not recognize and that will not be represented by a Loop +// instance. In particular, a Loop might be inside such a non-loop SCC, or a +// non-loop SCC might contain a sub-SCC which is a Loop. +// //===----------------------------------------------------------------------===// #ifndef LLVM_ANALYSIS_LOOPINFO_H @@ -38,16 +44,12 @@ #include "llvm/IR/CFG.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" +#include "llvm/IR/PassManager.h" #include "llvm/Pass.h" #include <algorithm> 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; - class DominatorTree; class LoopInfo; class Loop; @@ -346,6 +348,9 @@ raw_ostream& operator<<(raw_ostream &OS, const LoopBase<BlockT, LoopT> &Loop) { // Implementation in LoopInfoImpl.h extern template class LoopBase<BasicBlock, Loop>; + +/// Represents a single loop in the control flow graph. Note that not all SCCs +/// in the CFG are neccessarily loops. class Loop : public LoopBase<BasicBlock, Loop> { public: Loop() {} @@ -452,21 +457,13 @@ public: /// location by looking at the preheader and header blocks. If it /// cannot find a terminating instruction with location information, /// it returns an unknown location. - DebugLoc getStartLoc() const { - BasicBlock *HeadBB; - - // Try the pre-header first. - if ((HeadBB = getLoopPreheader()) != nullptr) - if (DebugLoc DL = HeadBB->getTerminator()->getDebugLoc()) - return DL; + DebugLoc getStartLoc() const; - // If we have no pre-header or there are no instructions with debug - // info in it, try the header. - HeadBB = getHeader(); - if (HeadBB) - return HeadBB->getTerminator()->getDebugLoc(); - - return DebugLoc(); + StringRef getName() const { + if (BasicBlock *Header = getHeader()) + if (Header->hasName()) + return Header->getName(); + return "<unnamed loop>"; } private: @@ -775,30 +772,23 @@ template <> struct GraphTraits<Loop*> { }; /// \brief Analysis pass that exposes the \c LoopInfo for a function. -class LoopAnalysis { +class LoopAnalysis : public AnalysisInfoMixin<LoopAnalysis> { + friend AnalysisInfoMixin<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"; } - - LoopInfo run(Function &F, AnalysisManager<Function> *AM); + LoopInfo run(Function &F, AnalysisManager<Function> &AM); }; /// \brief Printer pass for the \c LoopAnalysis results. -class LoopPrinterPass { +class LoopPrinterPass : public PassInfoMixin<LoopPrinterPass> { raw_ostream &OS; public: explicit LoopPrinterPass(raw_ostream &OS) : OS(OS) {} - PreservedAnalyses run(Function &F, AnalysisManager<Function> *AM); - - static StringRef name() { return "LoopPrinterPass"; } + PreservedAnalyses run(Function &F, AnalysisManager<Function> &AM); }; /// \brief The legacy pass manager's analysis pass to compute loop information. @@ -828,7 +818,7 @@ public: }; /// \brief Pass for printing a loop's contents as LLVM's text IR assembly. -class PrintLoopPass { +class PrintLoopPass : public PassInfoMixin<PrintLoopPass> { raw_ostream &OS; std::string Banner; @@ -836,8 +826,7 @@ public: PrintLoopPass(); PrintLoopPass(raw_ostream &OS, const std::string &Banner = ""); - PreservedAnalyses run(Loop &L); - static StringRef name() { return "PrintLoopPass"; } + PreservedAnalyses run(Loop &L, AnalysisManager<Loop> &); }; } // End llvm namespace |