forked from OSchip/llvm-project
[StructurizeCFG] Refactor OrderNodes.
Summary: No need to copy the RPOT vector before using it. Switch from std::map to SmallDenseMap. Get rid of an unused variable (TempVisited). Get rid of a typedef, RNVector, which is now used only once. Differential Revision: https://reviews.llvm.org/D26997 llvm-svn: 287721
This commit is contained in:
parent
23aaf60277
commit
6c0f25aec6
|
@ -175,7 +175,7 @@ class StructurizeCFG : public RegionPass {
|
||||||
DominatorTree *DT;
|
DominatorTree *DT;
|
||||||
LoopInfo *LI;
|
LoopInfo *LI;
|
||||||
|
|
||||||
RNVector Order;
|
SmallVector<RegionNode *, 8> Order;
|
||||||
BBSet Visited;
|
BBSet Visited;
|
||||||
|
|
||||||
BBPhiMap DeletedPhis;
|
BBPhiMap DeletedPhis;
|
||||||
|
@ -288,17 +288,13 @@ bool StructurizeCFG::doInitialization(Region *R, RGPassManager &RGM) {
|
||||||
|
|
||||||
/// \brief Build up the general order of nodes
|
/// \brief Build up the general order of nodes
|
||||||
void StructurizeCFG::orderNodes() {
|
void StructurizeCFG::orderNodes() {
|
||||||
RNVector TempOrder;
|
|
||||||
ReversePostOrderTraversal<Region*> RPOT(ParentRegion);
|
ReversePostOrderTraversal<Region*> RPOT(ParentRegion);
|
||||||
TempOrder.append(RPOT.begin(), RPOT.end());
|
SmallDenseMap<Loop*, unsigned, 8> LoopBlocks;
|
||||||
|
|
||||||
std::map<Loop*, unsigned> LoopBlocks;
|
|
||||||
|
|
||||||
|
|
||||||
// The reverse post-order traversal of the list gives us an ordering close
|
// The reverse post-order traversal of the list gives us an ordering close
|
||||||
// to what we want. The only problem with it is that sometimes backedges
|
// to what we want. The only problem with it is that sometimes backedges
|
||||||
// for outer loops will be visited before backedges for inner loops.
|
// for outer loops will be visited before backedges for inner loops.
|
||||||
for (RegionNode *RN : TempOrder) {
|
for (RegionNode *RN : RPOT) {
|
||||||
BasicBlock *BB = RN->getEntry();
|
BasicBlock *BB = RN->getEntry();
|
||||||
Loop *Loop = LI->getLoopFor(BB);
|
Loop *Loop = LI->getLoopFor(BB);
|
||||||
++LoopBlocks[Loop];
|
++LoopBlocks[Loop];
|
||||||
|
@ -306,8 +302,7 @@ void StructurizeCFG::orderNodes() {
|
||||||
|
|
||||||
unsigned CurrentLoopDepth = 0;
|
unsigned CurrentLoopDepth = 0;
|
||||||
Loop *CurrentLoop = nullptr;
|
Loop *CurrentLoop = nullptr;
|
||||||
BBSet TempVisited;
|
for (auto I = RPOT.begin(), E = RPOT.end(); I != E; ++I) {
|
||||||
for (RNVector::iterator I = TempOrder.begin(), E = TempOrder.end(); I != E; ++I) {
|
|
||||||
BasicBlock *BB = (*I)->getEntry();
|
BasicBlock *BB = (*I)->getEntry();
|
||||||
unsigned LoopDepth = LI->getLoopDepth(BB);
|
unsigned LoopDepth = LI->getLoopDepth(BB);
|
||||||
|
|
||||||
|
@ -318,7 +313,7 @@ void StructurizeCFG::orderNodes() {
|
||||||
// Make sure we have visited all blocks in this loop before moving back to
|
// Make sure we have visited all blocks in this loop before moving back to
|
||||||
// the outer loop.
|
// the outer loop.
|
||||||
|
|
||||||
RNVector::iterator LoopI = I;
|
auto LoopI = I;
|
||||||
while (unsigned &BlockCount = LoopBlocks[CurrentLoop]) {
|
while (unsigned &BlockCount = LoopBlocks[CurrentLoop]) {
|
||||||
LoopI++;
|
LoopI++;
|
||||||
BasicBlock *LoopBB = (*LoopI)->getEntry();
|
BasicBlock *LoopBB = (*LoopI)->getEntry();
|
||||||
|
@ -330,9 +325,8 @@ void StructurizeCFG::orderNodes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentLoop = LI->getLoopFor(BB);
|
CurrentLoop = LI->getLoopFor(BB);
|
||||||
if (CurrentLoop) {
|
if (CurrentLoop)
|
||||||
LoopBlocks[CurrentLoop]--;
|
LoopBlocks[CurrentLoop]--;
|
||||||
}
|
|
||||||
|
|
||||||
CurrentLoopDepth = LoopDepth;
|
CurrentLoopDepth = LoopDepth;
|
||||||
Order.push_back(*I);
|
Order.push_back(*I);
|
||||||
|
|
Loading…
Reference in New Issue