OLD | NEW |
1 //===- subzero/src/IceLoopAnalyzer.cpp - Loop Analysis --------------------===// | 1 //===- subzero/src/IceLoopAnalyzer.cpp - Loop Analysis --------------------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 /// | 9 /// |
10 /// \file | 10 /// \file |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 // Allocate memory ahead of time. This is why a vector is used instead of a | 48 // Allocate memory ahead of time. This is why a vector is used instead of a |
49 // stack which doesn't support reserving (or bulk erasure used below). | 49 // stack which doesn't support reserving (or bulk erasure used below). |
50 AllNodes.reserve(Nodes.size()); | 50 AllNodes.reserve(Nodes.size()); |
51 WorkStack.reserve(Nodes.size()); | 51 WorkStack.reserve(Nodes.size()); |
52 LoopStack.reserve(Nodes.size()); | 52 LoopStack.reserve(Nodes.size()); |
53 | 53 |
54 // Create the LoopNodes from the function's CFG | 54 // Create the LoopNodes from the function's CFG |
55 for (CfgNode *Node : Nodes) | 55 for (CfgNode *Node : Nodes) |
56 AllNodes.emplace_back(Node); | 56 AllNodes.emplace_back(Node); |
| 57 computeLoopNestDepth(); |
57 } | 58 } |
58 | 59 |
59 void LoopAnalyzer::computeLoopNestDepth() { | 60 void LoopAnalyzer::computeLoopNestDepth() { |
60 assert(AllNodes.size() == Func->getNodes().size()); | 61 assert(AllNodes.size() == Func->getNodes().size()); |
61 assert(NextIndex == FirstDefinedIndex); | 62 assert(NextIndex == FirstDefinedIndex); |
62 assert(NumDeletedNodes == 0); | 63 assert(NumDeletedNodes == 0); |
63 | 64 |
64 while (NumDeletedNodes < AllNodes.size()) { | 65 while (NumDeletedNodes < AllNodes.size()) { |
65 // Prepare to run Tarjan's | 66 // Prepare to run Tarjan's |
66 for (LoopNode &Node : AllNodes) | 67 for (LoopNode &Node : AllNodes) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // Reaching here means a loop has been found! It consists of the nodes on the | 135 // Reaching here means a loop has been found! It consists of the nodes on the |
135 // top of the stack, down until the current node being processed, Node, is | 136 // top of the stack, down until the current node being processed, Node, is |
136 // found. | 137 // found. |
137 for (auto It = LoopStack.rbegin(); It != LoopStack.rend(); ++It) { | 138 for (auto It = LoopStack.rbegin(); It != LoopStack.rend(); ++It) { |
138 (*It)->setOnStack(false); | 139 (*It)->setOnStack(false); |
139 (*It)->incrementLoopNestDepth(); | 140 (*It)->incrementLoopNestDepth(); |
140 // Remove the loop from the stack and delete the head node | 141 // Remove the loop from the stack and delete the head node |
141 if (*It == &Node) { | 142 if (*It == &Node) { |
142 (*It)->setDeleted(); | 143 (*It)->setDeleted(); |
143 ++NumDeletedNodes; | 144 ++NumDeletedNodes; |
| 145 CfgVector<SizeT> LoopNodes; |
| 146 for (auto LoopIter = It.base() - 1; LoopIter != LoopStack.end(); |
| 147 ++LoopIter) { |
| 148 LoopNodes.push_back((*LoopIter)->getNode()->getIndex()); |
| 149 } |
| 150 Loops[(*It)->getNode()->getIndex()] = LoopNodes; |
144 LoopStack.erase(It.base() - 1, LoopStack.end()); | 151 LoopStack.erase(It.base() - 1, LoopStack.end()); |
145 break; | 152 break; |
146 } | 153 } |
147 } | 154 } |
148 | 155 |
149 return nullptr; | 156 return nullptr; |
150 } | 157 } |
151 | 158 |
152 } // end of namespace Ice | 159 } // end of namespace Ice |
OLD | NEW |