| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 Node* node = queue_.front(); | 189 Node* node = queue_.front(); |
| 190 info(node); | 190 info(node); |
| 191 queue_.pop_front(); | 191 queue_.pop_front(); |
| 192 queued_.Set(node, false); | 192 queued_.Set(node, false); |
| 193 | 193 |
| 194 int loop_num = -1; | 194 int loop_num = -1; |
| 195 // Setup loop headers first. | 195 // Setup loop headers first. |
| 196 if (node->opcode() == IrOpcode::kLoop) { | 196 if (node->opcode() == IrOpcode::kLoop) { |
| 197 // found the loop node first. | 197 // found the loop node first. |
| 198 loop_num = CreateLoopInfo(node); | 198 loop_num = CreateLoopInfo(node); |
| 199 } else if (node->opcode() == IrOpcode::kPhi || | 199 } else if (IrOpcode::IsPhiOpcode(node->opcode())) { |
| 200 node->opcode() == IrOpcode::kEffectPhi) { | |
| 201 // found a phi first. | 200 // found a phi first. |
| 202 Node* merge = node->InputAt(node->InputCount() - 1); | 201 Node* merge = node->InputAt(node->InputCount() - 1); |
| 203 if (merge->opcode() == IrOpcode::kLoop) { | 202 if (merge->opcode() == IrOpcode::kLoop) { |
| 204 loop_num = CreateLoopInfo(merge); | 203 loop_num = CreateLoopInfo(merge); |
| 205 } | 204 } |
| 206 } | 205 } |
| 207 | 206 |
| 208 // Propagate marks backwards from this node. | 207 // Propagate marks backwards from this node. |
| 209 for (int i = 0; i < node->InputCount(); i++) { | 208 for (int i = 0; i < node->InputCount(); i++) { |
| 210 Node* input = node->InputAt(i); | 209 Node* input = node->InputAt(i); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 228 if (INDEX(loop_num) >= width_) ResizeBackwardMarks(); | 227 if (INDEX(loop_num) >= width_) ResizeBackwardMarks(); |
| 229 | 228 |
| 230 // Create a new loop. | 229 // Create a new loop. |
| 231 loops_.push_back({node, nullptr, nullptr, nullptr}); | 230 loops_.push_back({node, nullptr, nullptr, nullptr}); |
| 232 loop_tree_->NewLoop(); | 231 loop_tree_->NewLoop(); |
| 233 SetBackwardMark(node, loop_num); | 232 SetBackwardMark(node, loop_num); |
| 234 loop_tree_->node_to_loop_num_[node->id()] = loop_num; | 233 loop_tree_->node_to_loop_num_[node->id()] = loop_num; |
| 235 | 234 |
| 236 // Setup loop mark for phis attached to loop header. | 235 // Setup loop mark for phis attached to loop header. |
| 237 for (Node* use : node->uses()) { | 236 for (Node* use : node->uses()) { |
| 238 if (use->opcode() == IrOpcode::kPhi || | 237 if (IrOpcode::IsPhiOpcode(use->opcode())) { |
| 239 use->opcode() == IrOpcode::kEffectPhi) { | |
| 240 SetBackwardMark(use, loop_num); | 238 SetBackwardMark(use, loop_num); |
| 241 loop_tree_->node_to_loop_num_[use->id()] = loop_num; | 239 loop_tree_->node_to_loop_num_[use->id()] = loop_num; |
| 242 } | 240 } |
| 243 } | 241 } |
| 244 | 242 |
| 245 return loop_num; | 243 return loop_num; |
| 246 } | 244 } |
| 247 | 245 |
| 248 void ResizeBackwardMarks() { | 246 void ResizeBackwardMarks() { |
| 249 int new_width = width_ + 1; | 247 int new_width = width_ + 1; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 if (!IsBackedge(use, edge)) { | 282 if (!IsBackedge(use, edge)) { |
| 285 if (PropagateForwardMarks(node, use)) Queue(use); | 283 if (PropagateForwardMarks(node, use)) Queue(use); |
| 286 } | 284 } |
| 287 } | 285 } |
| 288 } | 286 } |
| 289 } | 287 } |
| 290 | 288 |
| 291 bool IsBackedge(Node* use, Edge& edge) { | 289 bool IsBackedge(Node* use, Edge& edge) { |
| 292 if (LoopNum(use) <= 0) return false; | 290 if (LoopNum(use) <= 0) return false; |
| 293 if (edge.index() == kAssumedLoopEntryIndex) return false; | 291 if (edge.index() == kAssumedLoopEntryIndex) return false; |
| 294 if (use->opcode() == IrOpcode::kPhi || | 292 if (IrOpcode::IsPhiOpcode(use->opcode())) { |
| 295 use->opcode() == IrOpcode::kEffectPhi) { | |
| 296 return !NodeProperties::IsControlEdge(edge); | 293 return !NodeProperties::IsControlEdge(edge); |
| 297 } | 294 } |
| 298 return true; | 295 return true; |
| 299 } | 296 } |
| 300 | 297 |
| 301 int LoopNum(Node* node) { return loop_tree_->node_to_loop_num_[node->id()]; } | 298 int LoopNum(Node* node) { return loop_tree_->node_to_loop_num_[node->id()]; } |
| 302 | 299 |
| 303 NodeInfo& info(Node* node) { | 300 NodeInfo& info(Node* node) { |
| 304 NodeInfo& i = info_[node->id()]; | 301 NodeInfo& i = info_[node->id()]; |
| 305 if (i.node == nullptr) i.node = node; | 302 if (i.node == nullptr) i.node = node; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 finder.Run(); | 457 finder.Run(); |
| 461 if (FLAG_trace_turbo_graph) { | 458 if (FLAG_trace_turbo_graph) { |
| 462 finder.Print(); | 459 finder.Print(); |
| 463 } | 460 } |
| 464 return loop_tree; | 461 return loop_tree; |
| 465 } | 462 } |
| 466 | 463 |
| 467 } // namespace compiler | 464 } // namespace compiler |
| 468 } // namespace internal | 465 } // namespace internal |
| 469 } // namespace v8 | 466 } // namespace v8 |
| OLD | NEW |