forked from OSchip/llvm-project
Restructure PopulateLoopsDFS::insertIntoLoop.
As Nadav pointed out the first implementation was obscure. llvm-svn: 158862
This commit is contained in:
parent
8618cb7ef8
commit
2ed08a7cc1
|
@ -618,7 +618,7 @@ public:
|
||||||
void traverse(BlockT *EntryBlock);
|
void traverse(BlockT *EntryBlock);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void reverseInsertIntoLoop(BlockT *Block);
|
void insertIntoLoop(BlockT *Block);
|
||||||
|
|
||||||
BlockT *dfsSource() { return DFSStack.back().first; }
|
BlockT *dfsSource() { return DFSStack.back().first; }
|
||||||
SuccIterTy &dfsSucc() { return DFSStack.back().second; }
|
SuccIterTy &dfsSucc() { return DFSStack.back().second; }
|
||||||
|
@ -647,7 +647,7 @@ void PopulateLoopsDFS<BlockT, LoopT>::traverse(BlockT *EntryBlock) {
|
||||||
pushBlock(BB);
|
pushBlock(BB);
|
||||||
}
|
}
|
||||||
// Visit the top of the stack in postorder and backtrack.
|
// Visit the top of the stack in postorder and backtrack.
|
||||||
reverseInsertIntoLoop(dfsSource());
|
insertIntoLoop(dfsSource());
|
||||||
DFSStack.pop_back();
|
DFSStack.pop_back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -656,14 +656,11 @@ void PopulateLoopsDFS<BlockT, LoopT>::traverse(BlockT *EntryBlock) {
|
||||||
/// subloop header, add the subloop to its parent in PostOrder, then reverse the
|
/// subloop header, add the subloop to its parent in PostOrder, then reverse the
|
||||||
/// Block and Subloop vectors of the now complete subloop to achieve RPO.
|
/// Block and Subloop vectors of the now complete subloop to achieve RPO.
|
||||||
template<class BlockT, class LoopT>
|
template<class BlockT, class LoopT>
|
||||||
void PopulateLoopsDFS<BlockT, LoopT>::reverseInsertIntoLoop(BlockT *Block) {
|
void PopulateLoopsDFS<BlockT, LoopT>::insertIntoLoop(BlockT *Block) {
|
||||||
for (LoopT *Subloop = LI->getLoopFor(Block);
|
LoopT *Subloop = LI->getLoopFor(Block);
|
||||||
Subloop; Subloop = Subloop->getParentLoop()) {
|
if (Subloop && Block == Subloop->getHeader()) {
|
||||||
|
// We reach this point once per subloop after processing all the blocks in
|
||||||
if (Block != Subloop->getHeader()) {
|
// the subloop.
|
||||||
Subloop->getBlocksVector().push_back(Block);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (Subloop->getParentLoop())
|
if (Subloop->getParentLoop())
|
||||||
Subloop->getParentLoop()->getSubLoopsVector().push_back(Subloop);
|
Subloop->getParentLoop()->getSubLoopsVector().push_back(Subloop);
|
||||||
else
|
else
|
||||||
|
@ -675,7 +672,11 @@ void PopulateLoopsDFS<BlockT, LoopT>::reverseInsertIntoLoop(BlockT *Block) {
|
||||||
Subloop->getBlocksVector().end());
|
Subloop->getBlocksVector().end());
|
||||||
std::reverse(Subloop->getSubLoopsVector().begin(),
|
std::reverse(Subloop->getSubLoopsVector().begin(),
|
||||||
Subloop->getSubLoopsVector().end());
|
Subloop->getSubLoopsVector().end());
|
||||||
|
|
||||||
|
Subloop = Subloop->getParentLoop();
|
||||||
}
|
}
|
||||||
|
for (; Subloop; Subloop = Subloop->getParentLoop())
|
||||||
|
Subloop->getBlocksVector().push_back(Block);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Analyze LoopInfo discovers loops during a postorder DominatorTree traversal
|
/// Analyze LoopInfo discovers loops during a postorder DominatorTree traversal
|
||||||
|
|
Loading…
Reference in New Issue