OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/loop-analysis.h" | 5 #include "src/compiler/loop-analysis.h" |
6 | 6 |
7 #include "src/compiler/graph.h" | 7 #include "src/compiler/graph.h" |
8 #include "src/compiler/node.h" | 8 #include "src/compiler/node.h" |
9 #include "src/compiler/node-marker.h" | 9 #include "src/compiler/node-marker.h" |
10 #include "src/compiler/node-properties-inl.h" | 10 #include "src/compiler/node-properties-inl.h" |
11 #include "src/zone.h" | 11 #include "src/zone.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 while (!queue_.empty()) { | 149 while (!queue_.empty()) { |
150 Node* node = queue_.front(); | 150 Node* node = queue_.front(); |
151 queue_.pop_front(); | 151 queue_.pop_front(); |
152 queued_.Set(node, false); | 152 queued_.Set(node, false); |
153 | 153 |
154 // Setup loop headers first. | 154 // Setup loop headers first. |
155 NodeInfo& ni = info(node); | 155 NodeInfo& ni = info(node); |
156 if (node->opcode() == IrOpcode::kLoop) { | 156 if (node->opcode() == IrOpcode::kLoop) { |
157 // found the loop node first. | 157 // found the loop node first. |
158 CreateLoopInfo(node, ni); | 158 CreateLoopInfo(node, ni); |
159 } else if (node->opcode() == IrOpcode::kPhi || | 159 } else if (IrOpcode::IsPhiOpcode(node->opcode())) { |
160 node->opcode() == IrOpcode::kEffectPhi) { | |
161 // found a phi first. | 160 // found a phi first. |
162 Node* merge = node->InputAt(node->InputCount() - 1); | 161 Node* merge = node->InputAt(node->InputCount() - 1); |
163 if (merge->opcode() == IrOpcode::kLoop) { | 162 if (merge->opcode() == IrOpcode::kLoop) { |
164 NodeInfo& mi = info(merge); | 163 NodeInfo& mi = info(merge); |
165 CreateLoopInfo(merge, mi); | 164 CreateLoopInfo(merge, mi); |
166 ni.MarkBackward(mi.loop_mark); | 165 ni.MarkBackward(mi.loop_mark); |
167 } | 166 } |
168 } | 167 } |
169 | 168 |
170 // Propagate reachability marks backwards from this node. | 169 // Propagate reachability marks backwards from this node. |
(...skipping 26 matching lines...) Expand all Loading... |
197 size_t loop_num = loops_.size() + 1; | 196 size_t loop_num = loops_.size() + 1; |
198 CHECK(loops_found_ <= kMaxLoops); // TODO(titzer): don't crash. | 197 CHECK(loops_found_ <= kMaxLoops); // TODO(titzer): don't crash. |
199 // Create a new loop. | 198 // Create a new loop. |
200 loops_.push_back({node, nullptr, nullptr, nullptr}); | 199 loops_.push_back({node, nullptr, nullptr, nullptr}); |
201 loop_tree_->NewLoop(); | 200 loop_tree_->NewLoop(); |
202 LoopMarks loop_mark = kVisited | (1 << loop_num); | 201 LoopMarks loop_mark = kVisited | (1 << loop_num); |
203 ni.loop_mark = loop_mark; | 202 ni.loop_mark = loop_mark; |
204 | 203 |
205 // Setup loop mark for phis attached to loop header. | 204 // Setup loop mark for phis attached to loop header. |
206 for (Node* use : node->uses()) { | 205 for (Node* use : node->uses()) { |
207 if (use->opcode() == IrOpcode::kPhi || | 206 if (IrOpcode::IsPhiOpcode(use->opcode())) { |
208 use->opcode() == IrOpcode::kEffectPhi) { | |
209 info(use).loop_mark = loop_mark; | 207 info(use).loop_mark = loop_mark; |
210 } | 208 } |
211 } | 209 } |
212 } | 210 } |
213 | 211 |
214 // Propagate marks forward from loops. | 212 // Propagate marks forward from loops. |
215 void PropagateForward() { | 213 void PropagateForward() { |
216 for (LoopInfo& li : loops_) { | 214 for (LoopInfo& li : loops_) { |
217 queued_.Set(li.header, true); | 215 queued_.Set(li.header, true); |
218 queue_.push_back(li.header); | 216 queue_.push_back(li.header); |
(...skipping 16 matching lines...) Expand all Loading... |
235 queue_.push_back(use); | 233 queue_.push_back(use); |
236 } | 234 } |
237 } | 235 } |
238 } | 236 } |
239 } | 237 } |
240 | 238 |
241 bool IsBackedge(Node* use, NodeInfo& ui, Edge& edge) { | 239 bool IsBackedge(Node* use, NodeInfo& ui, Edge& edge) { |
242 // TODO(titzer): checking for backedges here is ugly. | 240 // TODO(titzer): checking for backedges here is ugly. |
243 if (!ui.IsLoopHeader()) return false; | 241 if (!ui.IsLoopHeader()) return false; |
244 if (edge.index() == kAssumedLoopEntryIndex) return false; | 242 if (edge.index() == kAssumedLoopEntryIndex) return false; |
245 if (use->opcode() == IrOpcode::kPhi || | 243 if (IrOpcode::IsPhiOpcode(use->opcode())) { |
246 use->opcode() == IrOpcode::kEffectPhi) { | |
247 return !NodeProperties::IsControlEdge(edge); | 244 return !NodeProperties::IsControlEdge(edge); |
248 } | 245 } |
249 return true; | 246 return true; |
250 } | 247 } |
251 | 248 |
252 NodeInfo& info(Node* node) { | 249 NodeInfo& info(Node* node) { |
253 NodeInfo& i = info_[node->id()]; | 250 NodeInfo& i = info_[node->id()]; |
254 if (i.node == nullptr) i.node = node; | 251 if (i.node == nullptr) i.node = node; |
255 return i; | 252 return i; |
256 } | 253 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 finder.Run(); | 403 finder.Run(); |
407 if (FLAG_trace_turbo_graph) { | 404 if (FLAG_trace_turbo_graph) { |
408 finder.Print(); | 405 finder.Print(); |
409 } | 406 } |
410 return loop_tree; | 407 return loop_tree; |
411 } | 408 } |
412 | 409 |
413 } // namespace compiler | 410 } // namespace compiler |
414 } // namespace internal | 411 } // namespace internal |
415 } // namespace v8 | 412 } // namespace v8 |
OLD | NEW |