| OLD | NEW |
| 1 // Copyright 2014 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/common-operator.h" | 5 #include "src/compiler/common-operator.h" |
| 6 #include "src/compiler/control-reducer.h" | 6 #include "src/compiler/control-reducer.h" |
| 7 #include "src/compiler/graph.h" | 7 #include "src/compiler/graph.h" |
| 8 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
| 9 #include "src/compiler/node-matchers.h" | 9 #include "src/compiler/node-matchers.h" |
| 10 #include "src/compiler/node-properties-inl.h" | 10 #include "src/compiler/node-properties-inl.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 230 |
| 231 // Process cached nodes in the JSGraph too. | 231 // Process cached nodes in the JSGraph too. |
| 232 jsgraph_->GetCachedNodes(&nodes); | 232 jsgraph_->GetCachedNodes(&nodes); |
| 233 TrimNodes(marked, nodes); | 233 TrimNodes(marked, nodes); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void TrimNodes(ReachabilityMarker& marked, NodeVector& nodes) { | 236 void TrimNodes(ReachabilityMarker& marked, NodeVector& nodes) { |
| 237 // Remove dead->live edges. | 237 // Remove dead->live edges. |
| 238 for (size_t j = 0; j < nodes.size(); j++) { | 238 for (size_t j = 0; j < nodes.size(); j++) { |
| 239 Node* node = nodes[j]; | 239 Node* node = nodes[j]; |
| 240 for (UseIter i = node->uses().begin(); i != node->uses().end();) { | 240 for (Edge edge : node->use_edges()) { |
| 241 if (!marked.IsReachableFromEnd(*i)) { | 241 Node* use = edge.from(); |
| 242 TRACE(("DeadLink: #%d:%s(%d) -> #%d:%s\n", (*i)->id(), | 242 if (!marked.IsReachableFromEnd(use)) { |
| 243 (*i)->op()->mnemonic(), i.index(), node->id(), | 243 TRACE(("DeadLink: #%d:%s(%d) -> #%d:%s\n", use->id(), |
| 244 use->op()->mnemonic(), edge.index(), node->id(), |
| 244 node->op()->mnemonic())); | 245 node->op()->mnemonic())); |
| 245 i.UpdateToAndIncrement(NULL); | 246 edge.UpdateTo(NULL); |
| 246 } else { | |
| 247 ++i; | |
| 248 } | 247 } |
| 249 } | 248 } |
| 250 } | 249 } |
| 251 #if DEBUG | 250 #if DEBUG |
| 252 // Verify that no inputs to live nodes are NULL. | 251 // Verify that no inputs to live nodes are NULL. |
| 253 for (size_t j = 0; j < nodes.size(); j++) { | 252 for (size_t j = 0; j < nodes.size(); j++) { |
| 254 Node* node = nodes[j]; | 253 Node* node = nodes[j]; |
| 255 for (Node* const input : node->inputs()) { | 254 for (Node* const input : node->inputs()) { |
| 256 CHECK_NE(NULL, input); | 255 CHECK_NE(NULL, input); |
| 257 } | 256 } |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 // Reduce branches if they have constant inputs. | 465 // Reduce branches if they have constant inputs. |
| 467 Node* ReduceBranch(Node* node) { | 466 Node* ReduceBranch(Node* node) { |
| 468 Decision result = DecideCondition(node->InputAt(0)); | 467 Decision result = DecideCondition(node->InputAt(0)); |
| 469 if (result == kUnknown) return node; | 468 if (result == kUnknown) return node; |
| 470 | 469 |
| 471 TRACE(("BranchReduce: #%d:%s = %s\n", node->id(), node->op()->mnemonic(), | 470 TRACE(("BranchReduce: #%d:%s = %s\n", node->id(), node->op()->mnemonic(), |
| 472 (result == kTrue) ? "true" : "false")); | 471 (result == kTrue) ? "true" : "false")); |
| 473 | 472 |
| 474 // Replace IfTrue and IfFalse projections from this branch. | 473 // Replace IfTrue and IfFalse projections from this branch. |
| 475 Node* control = NodeProperties::GetControlInput(node); | 474 Node* control = NodeProperties::GetControlInput(node); |
| 476 for (UseIter i = node->uses().begin(); i != node->uses().end();) { | 475 for (Edge edge : node->use_edges()) { |
| 477 Node* to = *i; | 476 Node* use = edge.from(); |
| 478 if (to->opcode() == IrOpcode::kIfTrue) { | 477 if (use->opcode() == IrOpcode::kIfTrue) { |
| 479 TRACE((" IfTrue: #%d:%s\n", to->id(), to->op()->mnemonic())); | 478 TRACE((" IfTrue: #%d:%s\n", use->id(), use->op()->mnemonic())); |
| 480 i.UpdateToAndIncrement(NULL); | 479 edge.UpdateTo(NULL); |
| 481 ReplaceNode(to, (result == kTrue) ? control : dead()); | 480 ReplaceNode(use, (result == kTrue) ? control : dead()); |
| 482 } else if (to->opcode() == IrOpcode::kIfFalse) { | 481 } else if (use->opcode() == IrOpcode::kIfFalse) { |
| 483 TRACE((" IfFalse: #%d:%s\n", to->id(), to->op()->mnemonic())); | 482 TRACE((" IfFalse: #%d:%s\n", use->id(), use->op()->mnemonic())); |
| 484 i.UpdateToAndIncrement(NULL); | 483 edge.UpdateTo(NULL); |
| 485 ReplaceNode(to, (result == kTrue) ? dead() : control); | 484 ReplaceNode(use, (result == kTrue) ? dead() : control); |
| 486 } else { | |
| 487 ++i; | |
| 488 } | 485 } |
| 489 } | 486 } |
| 490 return control; | 487 return control; |
| 491 } | 488 } |
| 492 | 489 |
| 493 // Remove inputs to {node} corresponding to the dead inputs to {merge} | 490 // Remove inputs to {node} corresponding to the dead inputs to {merge} |
| 494 // and compact the remaining inputs, updating the operator. | 491 // and compact the remaining inputs, updating the operator. |
| 495 void RemoveDeadInputs(Node* merge, Node* node) { | 492 void RemoveDeadInputs(Node* merge, Node* node) { |
| 496 int pos = 0; | 493 int pos = 0; |
| 497 for (int i = 0; i < node->InputCount(); i++) { | 494 for (int i = 0; i < node->InputCount(); i++) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 Node* ControlReducer::ReduceBranchForTesting(JSGraph* jsgraph, | 566 Node* ControlReducer::ReduceBranchForTesting(JSGraph* jsgraph, |
| 570 CommonOperatorBuilder* common, | 567 CommonOperatorBuilder* common, |
| 571 Node* node) { | 568 Node* node) { |
| 572 Zone zone(jsgraph->graph()->zone()->isolate()); | 569 Zone zone(jsgraph->graph()->zone()->isolate()); |
| 573 ControlReducerImpl impl(&zone, jsgraph, common); | 570 ControlReducerImpl impl(&zone, jsgraph, common); |
| 574 return impl.ReduceBranch(node); | 571 return impl.ReduceBranch(node); |
| 575 } | 572 } |
| 576 } | 573 } |
| 577 } | 574 } |
| 578 } // namespace v8::internal::compiler | 575 } // namespace v8::internal::compiler |
| OLD | NEW |