| 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-marker.h" | 9 #include "src/compiler/node-marker.h" |
| 10 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 class ControlReducerImpl { | 48 class ControlReducerImpl { |
| 49 public: | 49 public: |
| 50 ControlReducerImpl(Zone* zone, JSGraph* jsgraph, | 50 ControlReducerImpl(Zone* zone, JSGraph* jsgraph, |
| 51 CommonOperatorBuilder* common) | 51 CommonOperatorBuilder* common) |
| 52 : zone_(zone), | 52 : zone_(zone), |
| 53 jsgraph_(jsgraph), | 53 jsgraph_(jsgraph), |
| 54 common_(common), | 54 common_(common), |
| 55 state_(jsgraph->graph()->NodeCount(), kUnvisited, zone_), | 55 state_(jsgraph->graph()->NodeCount(), kUnvisited, zone_), |
| 56 stack_(zone_), | 56 stack_(zone_), |
| 57 revisit_(zone_), | 57 revisit_(zone_) {} |
| 58 dead_(NULL) {} | |
| 59 | 58 |
| 60 Zone* zone_; | 59 Zone* zone_; |
| 61 JSGraph* jsgraph_; | 60 JSGraph* jsgraph_; |
| 62 CommonOperatorBuilder* common_; | 61 CommonOperatorBuilder* common_; |
| 63 ZoneVector<VisitState> state_; | 62 ZoneVector<VisitState> state_; |
| 64 ZoneDeque<Node*> stack_; | 63 ZoneDeque<Node*> stack_; |
| 65 ZoneDeque<Node*> revisit_; | 64 ZoneDeque<Node*> revisit_; |
| 66 Node* dead_; | |
| 67 | 65 |
| 68 void Reduce() { | 66 void Reduce() { |
| 69 Push(graph()->end()); | 67 Push(graph()->end()); |
| 70 do { | 68 do { |
| 71 // Process the node on the top of the stack, potentially pushing more | 69 // Process the node on the top of the stack, potentially pushing more |
| 72 // or popping the node off the stack. | 70 // or popping the node off the stack. |
| 73 ReduceTop(); | 71 ReduceTop(); |
| 74 // If the stack becomes empty, revisit any nodes in the revisit queue. | 72 // If the stack becomes empty, revisit any nodes in the revisit queue. |
| 75 // If no nodes in the revisit queue, try removing dead loops. | 73 // If no nodes in the revisit queue, try removing dead loops. |
| 76 // If no dead loops, then finish. | 74 // If no dead loops, then finish. |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 } | 371 } |
| 374 } | 372 } |
| 375 | 373 |
| 376 // Mark {node} as visited. | 374 // Mark {node} as visited. |
| 377 void MarkAsVisited(Node* node) { | 375 void MarkAsVisited(Node* node) { |
| 378 size_t id = static_cast<size_t>(node->id()); | 376 size_t id = static_cast<size_t>(node->id()); |
| 379 EnsureStateSize(id); | 377 EnsureStateSize(id); |
| 380 state_[id] = kVisited; | 378 state_[id] = kVisited; |
| 381 } | 379 } |
| 382 | 380 |
| 383 Node* dead() { | 381 Node* dead() { return jsgraph_->DeadControl(); } |
| 384 if (dead_ == NULL) dead_ = graph()->NewNode(common_->Dead()); | |
| 385 return dead_; | |
| 386 } | |
| 387 | 382 |
| 388 //=========================================================================== | 383 //=========================================================================== |
| 389 // Reducer implementation: perform reductions on a node. | 384 // Reducer implementation: perform reductions on a node. |
| 390 //=========================================================================== | 385 //=========================================================================== |
| 391 Node* ReduceNode(Node* node) { | 386 Node* ReduceNode(Node* node) { |
| 392 if (node->op()->ControlInputCount() == 1) { | 387 if (node->op()->ControlInputCount() == 1) { |
| 393 // If a node has only one control input and it is dead, replace with dead. | 388 // If a node has only one control input and it is dead, replace with dead. |
| 394 Node* control = NodeProperties::GetControlInput(node); | 389 Node* control = NodeProperties::GetControlInput(node); |
| 395 if (control->opcode() == IrOpcode::kDead) { | 390 if (control->opcode() == IrOpcode::kDead) { |
| 396 TRACE(("ControlDead: #%d:%s\n", node->id(), node->op()->mnemonic())); | 391 TRACE(("ControlDead: #%d:%s\n", node->id(), node->op()->mnemonic())); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 return impl.ReduceIfTrue(node); | 639 return impl.ReduceIfTrue(node); |
| 645 case IrOpcode::kIfFalse: | 640 case IrOpcode::kIfFalse: |
| 646 return impl.ReduceIfFalse(node); | 641 return impl.ReduceIfFalse(node); |
| 647 default: | 642 default: |
| 648 return node; | 643 return node; |
| 649 } | 644 } |
| 650 } | 645 } |
| 651 } | 646 } |
| 652 } | 647 } |
| 653 } // namespace v8::internal::compiler | 648 } // namespace v8::internal::compiler |
| OLD | NEW |