[Analysis] Revert r306472 changes in LoopInfo headers to fix broken builds.

llvm-svn: 306476
This commit is contained in:
Eugene Zelenko 2017-06-27 22:20:38 +00:00
parent cca75d2406
commit 9dece19159
3 changed files with 69 additions and 120 deletions

View File

@ -39,39 +39,26 @@
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/GraphTraits.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h" #include "llvm/IR/CFG.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/Instruction.h" #include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h" #include "llvm/IR/Instructions.h"
#include "llvm/IR/PassManager.h" #include "llvm/IR/PassManager.h"
#include "llvm/IR/Use.h"
#include "llvm/IR/User.h"
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include <algorithm> #include <algorithm>
#include <cassert>
#include <cstddef>
#include <string>
#include <utility>
#include <vector>
namespace llvm { namespace llvm {
class DominatorTree; class DominatorTree;
template<class N> class DominatorTreeBase;
class Function;
class Loop;
class LoopInfo; class LoopInfo;
template<class N, class M> class LoopInfoBase; class Loop;
class MDNode; class MDNode;
class PHINode;
class raw_ostream; class raw_ostream;
class Value; template<class N> class DominatorTreeBase;
template<class N, class M> class LoopInfoBase;
template<class N, class M> class LoopBase;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// Instances of this class are used to represent loops that are detected in the /// Instances of this class are used to represent loops that are detected in the
@ -79,8 +66,7 @@ class Value;
/// ///
template<class BlockT, class LoopT> template<class BlockT, class LoopT>
class LoopBase { class LoopBase {
LoopT *ParentLoop = nullptr; LoopT *ParentLoop;
// Loops contained entirely within this one. // Loops contained entirely within this one.
std::vector<LoopT *> SubLoops; std::vector<LoopT *> SubLoops;
@ -92,12 +78,12 @@ class LoopBase {
/// Indicator that this loop is no longer a valid loop. /// Indicator that this loop is no longer a valid loop.
bool IsInvalid = false; bool IsInvalid = false;
LoopBase(const LoopBase<BlockT, LoopT> &) = delete;
const LoopBase<BlockT, LoopT>&
operator=(const LoopBase<BlockT, LoopT> &) = delete;
public: public:
/// This creates an empty loop. /// This creates an empty loop.
LoopBase() = default; LoopBase() : ParentLoop(nullptr) {}
LoopBase(const LoopBase<BlockT, LoopT> &) = delete;
LoopBase<BlockT, LoopT> &operator=(const LoopBase<BlockT, LoopT> &) = delete;
~LoopBase() { ~LoopBase() {
for (size_t i = 0, e = SubLoops.size(); i != e; ++i) for (size_t i = 0, e = SubLoops.size(); i != e; ++i)
delete SubLoops[i]; delete SubLoops[i];
@ -140,11 +126,9 @@ public:
/// Return the loops contained entirely within this loop. /// Return the loops contained entirely within this loop.
const std::vector<LoopT *> &getSubLoops() const { return SubLoops; } const std::vector<LoopT *> &getSubLoops() const { return SubLoops; }
std::vector<LoopT *> &getSubLoopsVector() { return SubLoops; } std::vector<LoopT *> &getSubLoopsVector() { return SubLoops; }
typedef typename std::vector<LoopT *>::const_iterator iterator;
using iterator = typename std::vector<LoopT *>::const_iterator; typedef typename std::vector<LoopT *>::const_reverse_iterator
using reverse_iterator = reverse_iterator;
typename std::vector<LoopT *>::const_reverse_iterator;
iterator begin() const { return SubLoops.begin(); } iterator begin() const { return SubLoops.begin(); }
iterator end() const { return SubLoops.end(); } iterator end() const { return SubLoops.end(); }
reverse_iterator rbegin() const { return SubLoops.rbegin(); } reverse_iterator rbegin() const { return SubLoops.rbegin(); }
@ -153,9 +137,7 @@ public:
/// Get a list of the basic blocks which make up this loop. /// Get a list of the basic blocks which make up this loop.
const std::vector<BlockT*> &getBlocks() const { return Blocks; } const std::vector<BlockT*> &getBlocks() const { return Blocks; }
typedef typename std::vector<BlockT*>::const_iterator block_iterator;
using block_iterator = typename std::vector<BlockT*>::const_iterator;
block_iterator block_begin() const { return Blocks.begin(); } block_iterator block_begin() const { return Blocks.begin(); }
block_iterator block_end() const { return Blocks.end(); } block_iterator block_end() const { return Blocks.end(); }
inline iterator_range<block_iterator> blocks() const { inline iterator_range<block_iterator> blocks() const {
@ -191,8 +173,8 @@ public:
assert(contains(BB) && "block does not belong to the loop"); assert(contains(BB) && "block does not belong to the loop");
BlockT *Header = getHeader(); BlockT *Header = getHeader();
auto PredBegin = GraphTraits<Inverse<BlockT*>>::child_begin(Header); auto PredBegin = GraphTraits<Inverse<BlockT*> >::child_begin(Header);
auto PredEnd = GraphTraits<Inverse<BlockT*>>::child_end(Header); auto PredEnd = GraphTraits<Inverse<BlockT*> >::child_end(Header);
return std::find(PredBegin, PredEnd, BB) != PredEnd; return std::find(PredBegin, PredEnd, BB) != PredEnd;
} }
@ -201,7 +183,7 @@ public:
unsigned NumBackEdges = 0; unsigned NumBackEdges = 0;
BlockT *H = getHeader(); BlockT *H = getHeader();
for (const auto Pred : children<Inverse<BlockT *>>(H)) for (const auto Pred : children<Inverse<BlockT*> >(H))
if (contains(Pred)) if (contains(Pred))
++NumBackEdges; ++NumBackEdges;
@ -234,7 +216,7 @@ public:
BlockT *getExitBlock() const; BlockT *getExitBlock() const;
/// Edge type. /// Edge type.
using Edge = std::pair<const BlockT*, const BlockT*>; typedef std::pair<const BlockT*, const BlockT*> Edge;
/// Return all pairs of (_inside_block_,_outside_block_). /// Return all pairs of (_inside_block_,_outside_block_).
void getExitEdges(SmallVectorImpl<Edge> &ExitEdges) const; void getExitEdges(SmallVectorImpl<Edge> &ExitEdges) const;
@ -338,7 +320,7 @@ public:
/// Blocks as appropriate. This does not update the mapping in the LoopInfo /// Blocks as appropriate. This does not update the mapping in the LoopInfo
/// class. /// class.
void removeBlockFromLoop(BlockT *BB) { void removeBlockFromLoop(BlockT *BB) {
auto I = llvm::find(Blocks, BB); auto I = find(Blocks, BB);
assert(I != Blocks.end() && "N is not in this list!"); assert(I != Blocks.end() && "N is not in this list!");
Blocks.erase(I); Blocks.erase(I);
@ -356,7 +338,6 @@ public:
protected: protected:
friend class LoopInfoBase<BlockT, LoopT>; friend class LoopInfoBase<BlockT, LoopT>;
explicit LoopBase(BlockT *BB) : ParentLoop(nullptr) { explicit LoopBase(BlockT *BB) : ParentLoop(nullptr) {
Blocks.push_back(BB); Blocks.push_back(BB);
DenseBlockSet.insert(BB); DenseBlockSet.insert(BB);
@ -372,6 +353,7 @@ raw_ostream& operator<<(raw_ostream &OS, const LoopBase<BlockT, LoopT> &Loop) {
// Implementation in LoopInfoImpl.h // Implementation in LoopInfoImpl.h
extern template class LoopBase<BasicBlock, Loop>; extern template class LoopBase<BasicBlock, Loop>;
/// Represents a single loop in the control flow graph. Note that not all SCCs /// Represents a single loop in the control flow graph. Note that not all SCCs
/// in the CFG are necessarily loops. /// in the CFG are necessarily loops.
class Loop : public LoopBase<BasicBlock, Loop> { class Loop : public LoopBase<BasicBlock, Loop> {
@ -382,7 +364,7 @@ public:
DebugLoc End; DebugLoc End;
public: public:
LocRange() = default; LocRange() {}
LocRange(DebugLoc Start) : Start(std::move(Start)), End(std::move(Start)) {} LocRange(DebugLoc Start) : Start(std::move(Start)), End(std::move(Start)) {}
LocRange(DebugLoc Start, DebugLoc End) : Start(std::move(Start)), LocRange(DebugLoc Start, DebugLoc End) : Start(std::move(Start)),
End(std::move(End)) {} End(std::move(End)) {}
@ -397,7 +379,7 @@ public:
} }
}; };
Loop() = default; Loop() {}
/// Return true if the specified value is loop invariant. /// Return true if the specified value is loop invariant.
bool isLoopInvariant(const Value *V) const; bool isLoopInvariant(const Value *V) const;
@ -425,6 +407,7 @@ public:
/// ///
/// If InsertPt is specified, it is the point to hoist instructions to. /// If InsertPt is specified, it is the point to hoist instructions to.
/// If null, the terminator of the loop preheader is used. /// If null, the terminator of the loop preheader is used.
///
bool makeLoopInvariant(Instruction *I, bool &Changed, bool makeLoopInvariant(Instruction *I, bool &Changed,
Instruction *InsertPt = nullptr) const; Instruction *InsertPt = nullptr) const;
@ -434,6 +417,7 @@ public:
/// ///
/// The IndVarSimplify pass transforms loops to have a canonical induction /// The IndVarSimplify pass transforms loops to have a canonical induction
/// variable. /// variable.
///
PHINode *getCanonicalInductionVariable() const; PHINode *getCanonicalInductionVariable() const;
/// Return true if the Loop is in LCSSA form. /// Return true if the Loop is in LCSSA form.
@ -470,7 +454,6 @@ public:
/// contain llvm.loop or or if multiple latches contain different nodes then /// contain llvm.loop or or if multiple latches contain different nodes then
/// 0 is returned. /// 0 is returned.
MDNode *getLoopID() const; MDNode *getLoopID() const;
/// Set the llvm.loop loop id metadata for this loop. /// Set the llvm.loop loop id metadata for this loop.
/// ///
/// The LoopID metadata node will be added to each terminator instruction in /// The LoopID metadata node will be added to each terminator instruction in
@ -516,7 +499,6 @@ public:
private: private:
friend class LoopInfoBase<BasicBlock, Loop>; friend class LoopInfoBase<BasicBlock, Loop>;
explicit Loop(BasicBlock *BB) : LoopBase<BasicBlock, Loop>(BB) {} explicit Loop(BasicBlock *BB) : LoopBase<BasicBlock, Loop>(BB) {}
}; };
@ -527,17 +509,19 @@ private:
template<class BlockT, class LoopT> template<class BlockT, class LoopT>
class LoopInfoBase { class LoopInfoBase {
friend class LoopBase<BlockT, LoopT>;
friend class LoopInfo;
// BBMap - Mapping of basic blocks to the inner most loop they occur in // BBMap - Mapping of basic blocks to the inner most loop they occur in
DenseMap<const BlockT *, LoopT *> BBMap; DenseMap<const BlockT *, LoopT *> BBMap;
std::vector<LoopT *> TopLevelLoops; std::vector<LoopT *> TopLevelLoops;
std::vector<LoopT *> RemovedLoops; std::vector<LoopT *> RemovedLoops;
friend class LoopBase<BlockT, LoopT>;
friend class LoopInfo;
void operator=(const LoopInfoBase &) = delete;
LoopInfoBase(const LoopInfoBase &) = delete;
public: public:
LoopInfoBase() = default; LoopInfoBase() { }
~LoopInfoBase() { releaseMemory(); }
LoopInfoBase(LoopInfoBase &&Arg) LoopInfoBase(LoopInfoBase &&Arg)
: BBMap(std::move(Arg.BBMap)), : BBMap(std::move(Arg.BBMap)),
@ -545,7 +529,6 @@ public:
// We have to clear the arguments top level loops as we've taken ownership. // We have to clear the arguments top level loops as we've taken ownership.
Arg.TopLevelLoops.clear(); Arg.TopLevelLoops.clear();
} }
LoopInfoBase &operator=(LoopInfoBase &&RHS) { LoopInfoBase &operator=(LoopInfoBase &&RHS) {
BBMap = std::move(RHS.BBMap); BBMap = std::move(RHS.BBMap);
@ -556,10 +539,6 @@ public:
return *this; return *this;
} }
LoopInfoBase(const LoopInfoBase &) = delete;
LoopInfoBase &operator=(const LoopInfoBase &) = delete;
~LoopInfoBase() { releaseMemory(); }
void releaseMemory() { void releaseMemory() {
BBMap.clear(); BBMap.clear();
@ -573,10 +552,10 @@ public:
/// iterator/begin/end - The interface to the top-level loops in the current /// iterator/begin/end - The interface to the top-level loops in the current
/// function. /// function.
using iterator = typename std::vector<LoopT *>::const_iterator; ///
using reverse_iterator = typedef typename std::vector<LoopT *>::const_iterator iterator;
typename std::vector<LoopT *>::const_reverse_iterator; typedef typename std::vector<LoopT *>::const_reverse_iterator
reverse_iterator;
iterator begin() const { return TopLevelLoops.begin(); } iterator begin() const { return TopLevelLoops.begin(); }
iterator end() const { return TopLevelLoops.end(); } iterator end() const { return TopLevelLoops.end(); }
reverse_iterator rbegin() const { return TopLevelLoops.rbegin(); } reverse_iterator rbegin() const { return TopLevelLoops.rbegin(); }
@ -648,7 +627,7 @@ public:
/// loop. /// loop.
void changeTopLevelLoop(LoopT *OldLoop, void changeTopLevelLoop(LoopT *OldLoop,
LoopT *NewLoop) { LoopT *NewLoop) {
auto I = llvm::find(TopLevelLoops, OldLoop); auto I = find(TopLevelLoops, OldLoop);
assert(I != TopLevelLoops.end() && "Old loop not at top level!"); assert(I != TopLevelLoops.end() && "Old loop not at top level!");
*I = NewLoop; *I = NewLoop;
assert(!NewLoop->ParentLoop && !OldLoop->ParentLoop && assert(!NewLoop->ParentLoop && !OldLoop->ParentLoop &&
@ -696,24 +675,22 @@ public:
extern template class LoopInfoBase<BasicBlock, Loop>; extern template class LoopInfoBase<BasicBlock, Loop>;
class LoopInfo : public LoopInfoBase<BasicBlock, Loop> { class LoopInfo : public LoopInfoBase<BasicBlock, Loop> {
typedef LoopInfoBase<BasicBlock, Loop> BaseT;
friend class LoopBase<BasicBlock, Loop>; friend class LoopBase<BasicBlock, Loop>;
using BaseT = LoopInfoBase<BasicBlock, Loop>; void operator=(const LoopInfo &) = delete;
LoopInfo(const LoopInfo &) = delete;
public: public:
LoopInfo() = default; LoopInfo() {}
explicit LoopInfo(const DominatorTreeBase<BasicBlock> &DomTree); explicit LoopInfo(const DominatorTreeBase<BasicBlock> &DomTree);
LoopInfo(LoopInfo &&Arg) : BaseT(std::move(static_cast<BaseT &>(Arg))) {} LoopInfo(LoopInfo &&Arg) : BaseT(std::move(static_cast<BaseT &>(Arg))) {}
LoopInfo &operator=(LoopInfo &&RHS) { LoopInfo &operator=(LoopInfo &&RHS) {
BaseT::operator=(std::move(static_cast<BaseT &>(RHS))); BaseT::operator=(std::move(static_cast<BaseT &>(RHS)));
return *this; return *this;
} }
LoopInfo(const LoopInfo &) = delete;
LoopInfo &operator=(const LoopInfo &) = delete;
/// Handle invalidation explicitly. /// Handle invalidation explicitly.
bool invalidate(Function &F, const PreservedAnalyses &PA, bool invalidate(Function &F, const PreservedAnalyses &PA,
FunctionAnalysisManager::Invalidator &); FunctionAnalysisManager::Invalidator &);
@ -821,8 +798,8 @@ public:
// Allow clients to walk the list of nested loops... // Allow clients to walk the list of nested loops...
template <> struct GraphTraits<const Loop*> { template <> struct GraphTraits<const Loop*> {
using NodeRef = const Loop *; typedef const Loop *NodeRef;
using ChildIteratorType = LoopInfo::iterator; typedef LoopInfo::iterator ChildIteratorType;
static NodeRef getEntryNode(const Loop *L) { return L; } static NodeRef getEntryNode(const Loop *L) { return L; }
static ChildIteratorType child_begin(NodeRef N) { return N->begin(); } static ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
@ -830,8 +807,8 @@ template <> struct GraphTraits<const Loop*> {
}; };
template <> struct GraphTraits<Loop*> { template <> struct GraphTraits<Loop*> {
using NodeRef = Loop *; typedef Loop *NodeRef;
using ChildIteratorType = LoopInfo::iterator; typedef LoopInfo::iterator ChildIteratorType;
static NodeRef getEntryNode(Loop *L) { return L; } static NodeRef getEntryNode(Loop *L) { return L; }
static ChildIteratorType child_begin(NodeRef N) { return N->begin(); } static ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
@ -841,11 +818,10 @@ template <> struct GraphTraits<Loop*> {
/// \brief Analysis pass that exposes the \c LoopInfo for a function. /// \brief Analysis pass that exposes the \c LoopInfo for a function.
class LoopAnalysis : public AnalysisInfoMixin<LoopAnalysis> { class LoopAnalysis : public AnalysisInfoMixin<LoopAnalysis> {
friend AnalysisInfoMixin<LoopAnalysis>; friend AnalysisInfoMixin<LoopAnalysis>;
static AnalysisKey Key; static AnalysisKey Key;
public: public:
using Result = LoopInfo; typedef LoopInfo Result;
LoopInfo run(Function &F, FunctionAnalysisManager &AM); LoopInfo run(Function &F, FunctionAnalysisManager &AM);
}; };
@ -856,7 +832,6 @@ class LoopPrinterPass : public PassInfoMixin<LoopPrinterPass> {
public: public:
explicit LoopPrinterPass(raw_ostream &OS) : OS(OS) {} explicit LoopPrinterPass(raw_ostream &OS) : OS(OS) {}
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
}; };
@ -894,6 +869,6 @@ public:
/// Function to print a loop's contents as LLVM's text IR assembly. /// Function to print a loop's contents as LLVM's text IR assembly.
void printLoop(Loop &L, raw_ostream &OS, const std::string &Banner = ""); void printLoop(Loop &L, raw_ostream &OS, const std::string &Banner = "");
} // end namespace llvm } // End llvm namespace
#endif // LLVM_ANALYSIS_LOOPINFO_H #endif

View File

@ -15,23 +15,12 @@
#ifndef LLVM_ANALYSIS_LOOPINFOIMPL_H #ifndef LLVM_ANALYSIS_LOOPINFOIMPL_H
#define LLVM_ANALYSIS_LOOPINFOIMPL_H #define LLVM_ANALYSIS_LOOPINFOIMPL_H
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/GraphTraits.h"
#include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/Dominators.h" #include "llvm/IR/Dominators.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <vector>
namespace llvm { namespace llvm {
@ -119,8 +108,7 @@ BlockT *LoopBase<BlockT, LoopT>::getLoopPreheader() const {
return nullptr; return nullptr;
// Make sure there is only one exit out of the preheader. // Make sure there is only one exit out of the preheader.
using BlockTraits = GraphTraits<BlockT *>; typedef GraphTraits<BlockT*> BlockTraits;
typename BlockTraits::ChildIteratorType SI = BlockTraits::child_begin(Out); typename BlockTraits::ChildIteratorType SI = BlockTraits::child_begin(Out);
++SI; ++SI;
if (SI != BlockTraits::child_end(Out)) if (SI != BlockTraits::child_end(Out))
@ -249,14 +237,14 @@ void LoopBase<BlockT, LoopT>::verifyLoop() const {
[&](BlockT *B){return contains(B);}) && [&](BlockT *B){return contains(B);}) &&
"Loop block has no in-loop successors!"); "Loop block has no in-loop successors!");
assert(std::any_of(GraphTraits<Inverse<BlockT *>>::child_begin(BB), assert(std::any_of(GraphTraits<Inverse<BlockT*> >::child_begin(BB),
GraphTraits<Inverse<BlockT *>>::child_end(BB), GraphTraits<Inverse<BlockT*> >::child_end(BB),
[&](BlockT *B){return contains(B);}) && [&](BlockT *B){return contains(B);}) &&
"Loop block has no in-loop predecessors!"); "Loop block has no in-loop predecessors!");
SmallVector<BlockT *, 2> OutsideLoopPreds; SmallVector<BlockT *, 2> OutsideLoopPreds;
std::for_each(GraphTraits<Inverse<BlockT *>>::child_begin(BB), std::for_each(GraphTraits<Inverse<BlockT*> >::child_begin(BB),
GraphTraits<Inverse<BlockT *>>::child_end(BB), GraphTraits<Inverse<BlockT*> >::child_end(BB),
[&](BlockT *B){if (!contains(B)) [&](BlockT *B){if (!contains(B))
OutsideLoopPreds.push_back(B); OutsideLoopPreds.push_back(B);
}); });
@ -356,7 +344,7 @@ template<class BlockT, class LoopT>
static void discoverAndMapSubloop(LoopT *L, ArrayRef<BlockT*> Backedges, static void discoverAndMapSubloop(LoopT *L, ArrayRef<BlockT*> Backedges,
LoopInfoBase<BlockT, LoopT> *LI, LoopInfoBase<BlockT, LoopT> *LI,
const DominatorTreeBase<BlockT> &DomTree) { const DominatorTreeBase<BlockT> &DomTree) {
using InvBlockTraits = GraphTraits<Inverse<BlockT *>>; typedef GraphTraits<Inverse<BlockT*> > InvBlockTraits;
unsigned NumBlocks = 0; unsigned NumBlocks = 0;
unsigned NumSubloops = 0; unsigned NumSubloops = 0;
@ -413,13 +401,13 @@ static void discoverAndMapSubloop(LoopT *L, ArrayRef<BlockT*> Backedges,
/// Populate all loop data in a stable order during a single forward DFS. /// Populate all loop data in a stable order during a single forward DFS.
template<class BlockT, class LoopT> template<class BlockT, class LoopT>
class PopulateLoopsDFS { class PopulateLoopsDFS {
using BlockTraits = GraphTraits<BlockT *>; typedef GraphTraits<BlockT*> BlockTraits;
using SuccIterTy = typename BlockTraits::ChildIteratorType; typedef typename BlockTraits::ChildIteratorType SuccIterTy;
LoopInfoBase<BlockT, LoopT> *LI; LoopInfoBase<BlockT, LoopT> *LI;
public: public:
PopulateLoopsDFS(LoopInfoBase<BlockT, LoopT> *li) : LI(li) {} PopulateLoopsDFS(LoopInfoBase<BlockT, LoopT> *li):
LI(li) {}
void traverse(BlockT *EntryBlock); void traverse(BlockT *EntryBlock);
@ -669,6 +657,6 @@ void LoopInfoBase<BlockT, LoopT>::verify(
#endif #endif
} }
} // end namespace llvm } // End llvm namespace
#endif // LLVM_ANALYSIS_LOOPINFOIMPL_H #endif

View File

@ -1,4 +1,4 @@
//===- LoopIterator.h - Iterate over loop blocks ----------------*- C++ -*-===// //===--------- LoopIterator.h - Iterate over loop blocks --------*- C++ -*-===//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@ -24,23 +24,11 @@
#ifndef LLVM_ANALYSIS_LOOPITERATOR_H #ifndef LLVM_ANALYSIS_LOOPITERATOR_H
#define LLVM_ANALYSIS_LOOPITERATOR_H #define LLVM_ANALYSIS_LOOPITERATOR_H
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/iterator.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/CFG.h"
#include "llvm/Support/MathExtras.h"
#include <cassert>
#include <cstddef>
#include <utility>
#include <vector>
namespace llvm { namespace llvm {
class BasicBlock;
class LoopBlocksTraversal; class LoopBlocksTraversal;
// A traits type that is intended to be used in graph algorithms. The graph // A traits type that is intended to be used in graph algorithms. The graph
@ -109,11 +97,11 @@ struct LoopBodyTraits {
/// TODO: This could be generalized for any CFG region, or the entire CFG. /// TODO: This could be generalized for any CFG region, or the entire CFG.
class LoopBlocksDFS { class LoopBlocksDFS {
public: public:
friend class LoopBlocksTraversal;
/// Postorder list iterators. /// Postorder list iterators.
using POIterator = std::vector<BasicBlock *>::const_iterator; typedef std::vector<BasicBlock*>::const_iterator POIterator;
using RPOIterator = std::vector<BasicBlock *>::const_reverse_iterator; typedef std::vector<BasicBlock*>::const_reverse_iterator RPOIterator;
friend class LoopBlocksTraversal;
private: private:
Loop *L; Loop *L;
@ -183,10 +171,8 @@ public:
/// Specialize po_iterator_storage to record postorder numbers. /// Specialize po_iterator_storage to record postorder numbers.
template<> class po_iterator_storage<LoopBlocksTraversal, true> { template<> class po_iterator_storage<LoopBlocksTraversal, true> {
LoopBlocksTraversal &LBT; LoopBlocksTraversal &LBT;
public: public:
po_iterator_storage(LoopBlocksTraversal &lbs) : LBT(lbs) {} po_iterator_storage(LoopBlocksTraversal &lbs) : LBT(lbs) {}
// These functions are defined below. // These functions are defined below.
bool insertEdge(Optional<BasicBlock *> From, BasicBlock *To); bool insertEdge(Optional<BasicBlock *> From, BasicBlock *To);
void finishPostorder(BasicBlock *BB); void finishPostorder(BasicBlock *BB);
@ -196,7 +182,7 @@ public:
class LoopBlocksTraversal { class LoopBlocksTraversal {
public: public:
/// Graph traversal iterator. /// Graph traversal iterator.
using POTIterator = po_iterator<BasicBlock*, LoopBlocksTraversal, true>; typedef po_iterator<BasicBlock*, LoopBlocksTraversal, true> POTIterator;
private: private:
LoopBlocksDFS &DFS; LoopBlocksDFS &DFS;
@ -250,6 +236,6 @@ finishPostorder(BasicBlock *BB) {
LBT.finishPostorder(BB); LBT.finishPostorder(BB);
} }
} // end namespace llvm } // End namespace llvm
#endif // LLVM_ANALYSIS_LOOPITERATOR_H #endif