Skip to content

Commit

Permalink
Replace loop doing postorder walk with postorder iterator
Browse files Browse the repository at this point in the history
Summary: LoopInfoImpl's loop population is just a normal postorder walk, written out.

Reviewers: chandlerc

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D9032

llvm-svn: 235073
  • Loading branch information
dberlin committed Apr 16, 2015
1 parent c984b90 commit 4421ac6
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions llvm/include/llvm/Analysis/LoopInfoImpl.h
Expand Up @@ -409,9 +409,6 @@ class PopulateLoopsDFS {
typedef typename BlockTraits::ChildIteratorType SuccIterTy;

LoopInfoBase<BlockT, LoopT> *LI;
DenseSet<const BlockT *> VisitedBlocks;
std::vector<std::pair<BlockT*, SuccIterTy> > DFSStack;

public:
PopulateLoopsDFS(LoopInfoBase<BlockT, LoopT> *li):
LI(li) {}
Expand All @@ -420,36 +417,13 @@ class PopulateLoopsDFS {

protected:
void insertIntoLoop(BlockT *Block);

BlockT *dfsSource() { return DFSStack.back().first; }
SuccIterTy &dfsSucc() { return DFSStack.back().second; }
SuccIterTy dfsSuccEnd() { return BlockTraits::child_end(dfsSource()); }

void pushBlock(BlockT *Block) {
DFSStack.push_back(std::make_pair(Block, BlockTraits::child_begin(Block)));
}
};

/// Top-level driver for the forward DFS within the loop.
template<class BlockT, class LoopT>
void PopulateLoopsDFS<BlockT, LoopT>::traverse(BlockT *EntryBlock) {
pushBlock(EntryBlock);
VisitedBlocks.insert(EntryBlock);
while (!DFSStack.empty()) {
// Traverse the leftmost path as far as possible.
while (dfsSucc() != dfsSuccEnd()) {
BlockT *BB = *dfsSucc();
++dfsSucc();
if (!VisitedBlocks.insert(BB).second)
continue;

// Push the next DFS successor onto the stack.
pushBlock(BB);
}
// Visit the top of the stack in postorder and backtrack.
insertIntoLoop(dfsSource());
DFSStack.pop_back();
}
for (BlockT *BB : post_order(EntryBlock))
insertIntoLoop(BB);
}

/// Add a single Block to its ancestor loops in PostOrder. If the block is a
Expand Down

0 comments on commit 4421ac6

Please sign in to comment.