24 #ifndef LLVM_ANALYSIS_LOOPITERATOR_H
25 #define LLVM_ANALYSIS_LOOPITERATOR_H
32 class LoopBlocksTraversal;
41 typedef std::vector<BasicBlock*>::const_iterator
POIterator;
42 typedef std::vector<BasicBlock*>::const_reverse_iterator
RPOIterator;
53 std::vector<BasicBlock*> PostBlocks;
57 L(Container), PostNumbers(
NextPowerOf2(Container->getNumBlocks())) {
72 return PostBlocks.begin();
79 return PostBlocks.rbegin();
89 return I != PostNumbers.end() && I->second;
95 assert(I != PostNumbers.end() &&
"block not visited by DFS");
96 assert(I->second &&
"block not finished by DFS");
133 DFS(Storage), LI(LInfo) {}
139 assert(DFS.PostBlocks.empty() &&
"Need clear DFS result before traversing");
140 assert(DFS.L->
getNumBlocks() &&
"po_iterator cannot handle an empty graph");
157 return DFS.PostNumbers.insert(std::make_pair(BB, 0)).second;
163 assert(DFS.PostNumbers.count(BB) &&
"Loop DFS skipped preorder");
164 DFS.PostBlocks.push_back(BB);
165 DFS.PostNumbers[BB] = DFS.PostBlocks.size();
171 return LBT.visitPreorder(To);
176 LBT.finishPostorder(BB);
po_ext_iterator< T, SetType > po_ext_end(T G, SetType &S)
LoopBlocksDFS(Loop *Container)
POIterator endPostorder() const
BlockT * getHeader() const
LoopInfoBase< BlockT, LoopT > * LI
Traverse the blocks in a loop using a depth-first search.
po_iterator_storage(LoopBlocksTraversal &lbs)
Loop * getLoopFor(const BasicBlock *BB) const
void perform(LoopInfo *LI)
Traverse the loop blocks and store the DFS result.
unsigned getPostorder(BasicBlock *BB) const
Get a block's postorder number.
po_iterator< BasicBlock *, LoopBlocksTraversal, true > POTIterator
Graph traversal iterator.
bool hasPostorder(BasicBlock *BB) const
Return true if this block has a postorder number.
LLVM Basic Block Representation.
unsigned getRPO(BasicBlock *BB) const
Get a block's reverse postorder number.
bool contains(const LoopT *L) const
Default po_iterator_storage implementation with an internal set object.
std::vector< BasicBlock * >::const_reverse_iterator RPOIterator
bool isComplete() const
Return true if postorder numbers are assigned to all loop blocks.
uint64_t NextPowerOf2(uint64_t A)
bool insertEdge(NodeType *From, NodeType *To)
bool visitPreorder(BasicBlock *BB)
bool hasPreorder(BasicBlock *BB) const
Return true if this block has been preorder visited.
unsigned getNumBlocks() const
getNumBlocks - Get the number of blocks in this loop in constant time.
po_ext_iterator< T, SetType > po_ext_begin(T G, SetType &S)
std::vector< BasicBlock * >::const_iterator POIterator
Postorder list iterators.
LoopBlocksTraversal(LoopBlocksDFS &Storage, LoopInfo *LInfo)
RPOIterator beginRPO() const
Reverse iterate over the cached postorder blocks.
void finishPostorder(BasicBlock *BB)
void finishPostorder(NodeType *BB)
POIterator beginPostorder() const
Iterate over the cached postorder blocks.
RPOIterator endRPO() const