Skip to content

Commit 6c0f25a

Browse files
author
Justin Lebar
committedNov 22, 2016
[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
1 parent 23aaf60 commit 6c0f25a

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed
 

‎llvm/lib/Transforms/Scalar/StructurizeCFG.cpp

+6-12
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class StructurizeCFG : public RegionPass {
175175
DominatorTree *DT;
176176
LoopInfo *LI;
177177

178-
RNVector Order;
178+
SmallVector<RegionNode *, 8> Order;
179179
BBSet Visited;
180180

181181
BBPhiMap DeletedPhis;
@@ -288,26 +288,21 @@ bool StructurizeCFG::doInitialization(Region *R, RGPassManager &RGM) {
288288

289289
/// \brief Build up the general order of nodes
290290
void StructurizeCFG::orderNodes() {
291-
RNVector TempOrder;
292291
ReversePostOrderTraversal<Region*> RPOT(ParentRegion);
293-
TempOrder.append(RPOT.begin(), RPOT.end());
294-
295-
std::map<Loop*, unsigned> LoopBlocks;
296-
292+
SmallDenseMap<Loop*, unsigned, 8> LoopBlocks;
297293

298294
// The reverse post-order traversal of the list gives us an ordering close
299295
// to what we want. The only problem with it is that sometimes backedges
300296
// for outer loops will be visited before backedges for inner loops.
301-
for (RegionNode *RN : TempOrder) {
297+
for (RegionNode *RN : RPOT) {
302298
BasicBlock *BB = RN->getEntry();
303299
Loop *Loop = LI->getLoopFor(BB);
304300
++LoopBlocks[Loop];
305301
}
306302

307303
unsigned CurrentLoopDepth = 0;
308304
Loop *CurrentLoop = nullptr;
309-
BBSet TempVisited;
310-
for (RNVector::iterator I = TempOrder.begin(), E = TempOrder.end(); I != E; ++I) {
305+
for (auto I = RPOT.begin(), E = RPOT.end(); I != E; ++I) {
311306
BasicBlock *BB = (*I)->getEntry();
312307
unsigned LoopDepth = LI->getLoopDepth(BB);
313308

@@ -318,7 +313,7 @@ void StructurizeCFG::orderNodes() {
318313
// Make sure we have visited all blocks in this loop before moving back to
319314
// the outer loop.
320315

321-
RNVector::iterator LoopI = I;
316+
auto LoopI = I;
322317
while (unsigned &BlockCount = LoopBlocks[CurrentLoop]) {
323318
LoopI++;
324319
BasicBlock *LoopBB = (*LoopI)->getEntry();
@@ -330,9 +325,8 @@ void StructurizeCFG::orderNodes() {
330325
}
331326

332327
CurrentLoop = LI->getLoopFor(BB);
333-
if (CurrentLoop) {
328+
if (CurrentLoop)
334329
LoopBlocks[CurrentLoop]--;
335-
}
336330

337331
CurrentLoopDepth = LoopDepth;
338332
Order.push_back(*I);

0 commit comments

Comments
 (0)
Please sign in to comment.