Chromium Code Reviews| 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 | 208 |
| 209 // Process cached nodes in the JSGraph too. | 209 // Process cached nodes in the JSGraph too. |
| 210 jsgraph_->GetCachedNodes(&nodes); | 210 jsgraph_->GetCachedNodes(&nodes); |
| 211 TrimNodes(nodes); | 211 TrimNodes(nodes); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void TrimNodes(NodeVector& nodes) { | 214 void TrimNodes(NodeVector& nodes) { |
| 215 // Remove dead->live edges. | 215 // Remove dead->live edges. |
| 216 for (size_t j = 0; j < nodes.size(); j++) { | 216 for (size_t j = 0; j < nodes.size(); j++) { |
| 217 Node* node = nodes[j]; | 217 Node* node = nodes[j]; |
| 218 for (UseIter i = node->uses().begin(); i != node->uses().end();) { | 218 for (auto edge : node->use_edges()) { |
|
Michael Starzinger
2014/11/28 13:55:46
Can we pretty please with a cherry on top just wri
| |
| 219 size_t id = static_cast<size_t>((*i)->id()); | 219 Node* use = edge.from(); |
| 220 size_t id = static_cast<size_t>(use->id()); | |
| 220 if (state_[id] != kVisited) { | 221 if (state_[id] != kVisited) { |
| 221 TRACE(("DeadLink: #%d:%s(%d) -> #%d:%s\n", (*i)->id(), | 222 TRACE(("DeadLink: #%d:%s(%d) -> #%d:%s\n", use->id(), |
| 222 (*i)->op()->mnemonic(), i.index(), node->id(), | 223 use->op()->mnemonic(), edge.index(), node->id(), |
| 223 node->op()->mnemonic())); | 224 node->op()->mnemonic())); |
| 224 i.UpdateToAndIncrement(NULL); | 225 edge.UpdateTo(NULL); |
| 225 } else { | |
| 226 ++i; | |
| 227 } | 226 } |
| 228 } | 227 } |
| 229 } | 228 } |
| 230 #if DEBUG | 229 #if DEBUG |
| 231 // Verify that no inputs to live nodes are NULL. | 230 // Verify that no inputs to live nodes are NULL. |
| 232 for (size_t j = 0; j < nodes.size(); j++) { | 231 for (size_t j = 0; j < nodes.size(); j++) { |
| 233 Node* node = nodes[j]; | 232 Node* node = nodes[j]; |
| 234 for (Node* const input : node->inputs()) { | 233 for (Node* const input : node->inputs()) { |
| 235 CHECK_NE(NULL, input); | 234 CHECK_NE(NULL, input); |
| 236 } | 235 } |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 // Reduce branches if they have constant inputs. | 445 // Reduce branches if they have constant inputs. |
| 447 Node* ReduceBranch(Node* node) { | 446 Node* ReduceBranch(Node* node) { |
| 448 Decision result = DecideCondition(node->InputAt(0)); | 447 Decision result = DecideCondition(node->InputAt(0)); |
| 449 if (result == kUnknown) return node; | 448 if (result == kUnknown) return node; |
| 450 | 449 |
| 451 TRACE(("BranchReduce: #%d:%s = %s\n", node->id(), node->op()->mnemonic(), | 450 TRACE(("BranchReduce: #%d:%s = %s\n", node->id(), node->op()->mnemonic(), |
| 452 (result == kTrue) ? "true" : "false")); | 451 (result == kTrue) ? "true" : "false")); |
| 453 | 452 |
| 454 // Replace IfTrue and IfFalse projections from this branch. | 453 // Replace IfTrue and IfFalse projections from this branch. |
| 455 Node* control = NodeProperties::GetControlInput(node); | 454 Node* control = NodeProperties::GetControlInput(node); |
| 456 for (UseIter i = node->uses().begin(); i != node->uses().end();) { | 455 for (auto edge : node->use_edges()) { |
| 457 Node* to = *i; | 456 Node* use = edge.from(); |
| 458 if (to->opcode() == IrOpcode::kIfTrue) { | 457 if (use->opcode() == IrOpcode::kIfTrue) { |
| 459 TRACE((" IfTrue: #%d:%s\n", to->id(), to->op()->mnemonic())); | 458 TRACE((" IfTrue: #%d:%s\n", use->id(), use->op()->mnemonic())); |
| 460 i.UpdateToAndIncrement(NULL); | 459 edge.UpdateTo(NULL); |
| 461 ReplaceNode(to, (result == kTrue) ? control : dead()); | 460 ReplaceNode(use, (result == kTrue) ? control : dead()); |
| 462 } else if (to->opcode() == IrOpcode::kIfFalse) { | 461 } else if (use->opcode() == IrOpcode::kIfFalse) { |
| 463 TRACE((" IfFalse: #%d:%s\n", to->id(), to->op()->mnemonic())); | 462 TRACE((" IfFalse: #%d:%s\n", use->id(), use->op()->mnemonic())); |
| 464 i.UpdateToAndIncrement(NULL); | 463 edge.UpdateTo(NULL); |
| 465 ReplaceNode(to, (result == kTrue) ? dead() : control); | 464 ReplaceNode(use, (result == kTrue) ? dead() : control); |
| 466 } else { | |
| 467 ++i; | |
| 468 } | 465 } |
| 469 } | 466 } |
| 470 return control; | 467 return control; |
| 471 } | 468 } |
| 472 | 469 |
| 473 // Remove inputs to {node} corresponding to the dead inputs to {merge} | 470 // Remove inputs to {node} corresponding to the dead inputs to {merge} |
| 474 // and compact the remaining inputs, updating the operator. | 471 // and compact the remaining inputs, updating the operator. |
| 475 void RemoveDeadInputs(Node* merge, Node* node) { | 472 void RemoveDeadInputs(Node* merge, Node* node) { |
| 476 int pos = 0; | 473 int pos = 0; |
| 477 for (int i = 0; i < node->InputCount(); i++) { | 474 for (int i = 0; i < node->InputCount(); i++) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 550 Node* ControlReducer::ReduceBranchForTesting(JSGraph* jsgraph, | 547 Node* ControlReducer::ReduceBranchForTesting(JSGraph* jsgraph, |
| 551 CommonOperatorBuilder* common, | 548 CommonOperatorBuilder* common, |
| 552 Node* node) { | 549 Node* node) { |
| 553 Zone zone(jsgraph->graph()->zone()->isolate()); | 550 Zone zone(jsgraph->graph()->zone()->isolate()); |
| 554 ControlReducerImpl impl(&zone, jsgraph, common); | 551 ControlReducerImpl impl(&zone, jsgraph, common); |
| 555 return impl.ReduceBranch(node); | 552 return impl.ReduceBranch(node); |
| 556 } | 553 } |
| 557 } | 554 } |
| 558 } | 555 } |
| 559 } // namespace v8::internal::compiler | 556 } // namespace v8::internal::compiler |
| OLD | NEW |