| 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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 TRACE("ControlDead: #%d:%s\n", node->id(), node->op()->mnemonic()); | 409 TRACE("ControlDead: #%d:%s\n", node->id(), node->op()->mnemonic()); |
| 410 return control; | 410 return control; |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 | 413 |
| 414 // Reduce branches, phis, and merges. | 414 // Reduce branches, phis, and merges. |
| 415 switch (node->opcode()) { | 415 switch (node->opcode()) { |
| 416 case IrOpcode::kBranch: | 416 case IrOpcode::kBranch: |
| 417 return ReduceBranch(node); | 417 return ReduceBranch(node); |
| 418 case IrOpcode::kIfTrue: | 418 case IrOpcode::kIfTrue: |
| 419 return ReduceIfTrue(node); | 419 return ReduceIfProjection(node, kTrue); |
| 420 case IrOpcode::kIfFalse: | 420 case IrOpcode::kIfFalse: |
| 421 return ReduceIfFalse(node); | 421 return ReduceIfProjection(node, kFalse); |
| 422 case IrOpcode::kLoop: | 422 case IrOpcode::kLoop: |
| 423 case IrOpcode::kMerge: | 423 case IrOpcode::kMerge: |
| 424 return ReduceMerge(node); | 424 return ReduceMerge(node); |
| 425 case IrOpcode::kSelect: | 425 case IrOpcode::kSelect: |
| 426 return ReduceSelect(node); | 426 return ReduceSelect(node); |
| 427 case IrOpcode::kPhi: | 427 case IrOpcode::kPhi: |
| 428 case IrOpcode::kEffectPhi: | 428 case IrOpcode::kEffectPhi: |
| 429 return ReducePhi(node); | 429 return ReducePhi(node); |
| 430 default: | 430 default: |
| 431 return node; | 431 return node; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 node0->op()->mnemonic(), node1->id(), node1->op()->mnemonic(), | 569 node0->op()->mnemonic(), node1->id(), node1->op()->mnemonic(), |
| 570 branch0->id(), branch0->op()->mnemonic()); | 570 branch0->id(), branch0->op()->mnemonic()); |
| 571 return NodeProperties::GetControlInput(branch0); | 571 return NodeProperties::GetControlInput(branch0); |
| 572 } | 572 } |
| 573 } | 573 } |
| 574 } | 574 } |
| 575 | 575 |
| 576 return node; | 576 return node; |
| 577 } | 577 } |
| 578 | 578 |
| 579 // Reduce branches if they have constant inputs. | 579 // Reduce if projections if the branch has a constant input. |
| 580 Node* ReduceIfTrue(Node* node) { | 580 Node* ReduceIfProjection(Node* node, Decision decision) { |
| 581 Node* branch = node->InputAt(0); | 581 Node* branch = node->InputAt(0); |
| 582 DCHECK_EQ(IrOpcode::kBranch, branch->opcode()); | 582 DCHECK_EQ(IrOpcode::kBranch, branch->opcode()); |
| 583 Decision result = DecideCondition(branch->InputAt(0)); | 583 Decision result = DecideCondition(branch->InputAt(0)); |
| 584 if (result == kTrue) { | 584 if (result == decision) { |
| 585 // fold a true branch by replacing IfTrue with the branch control. | 585 // Fold a branch by replacing IfTrue/IfFalse with the branch control. |
| 586 TRACE(" BranchReduce: #%d:%s => #%d:%s\n", branch->id(), | 586 TRACE(" BranchReduce: #%d:%s => #%d:%s\n", branch->id(), |
| 587 branch->op()->mnemonic(), node->id(), node->op()->mnemonic()); | 587 branch->op()->mnemonic(), node->id(), node->op()->mnemonic()); |
| 588 return branch->InputAt(1); | 588 return branch->InputAt(1); |
| 589 } | |
| 590 return result == kUnknown ? node : dead(); | |
| 591 } | |
| 592 | |
| 593 // Reduce branches if they have constant inputs. | |
| 594 Node* ReduceIfFalse(Node* node) { | |
| 595 Node* branch = node->InputAt(0); | |
| 596 DCHECK_EQ(IrOpcode::kBranch, branch->opcode()); | |
| 597 Decision result = DecideCondition(branch->InputAt(0)); | |
| 598 if (result == kFalse) { | |
| 599 // fold a false branch by replacing IfFalse with the branch control. | |
| 600 TRACE(" BranchReduce: #%d:%s => #%d:%s\n", branch->id(), | |
| 601 branch->op()->mnemonic(), node->id(), node->op()->mnemonic()); | |
| 602 return branch->InputAt(1); | |
| 603 } | 589 } |
| 604 return result == kUnknown ? node : dead(); | 590 return result == kUnknown ? node : dead(); |
| 605 } | 591 } |
| 606 | 592 |
| 607 // Remove inputs to {node} corresponding to the dead inputs to {merge} | 593 // Remove inputs to {node} corresponding to the dead inputs to {merge} |
| 608 // and compact the remaining inputs, updating the operator. | 594 // and compact the remaining inputs, updating the operator. |
| 609 void RemoveDeadInputs(Node* merge, Node* node) { | 595 void RemoveDeadInputs(Node* merge, Node* node) { |
| 610 int live = 0; | 596 int live = 0; |
| 611 for (int i = 0; i < merge->InputCount(); i++) { | 597 for (int i = 0; i < merge->InputCount(); i++) { |
| 612 // skip dead inputs. | 598 // skip dead inputs. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 } | 660 } |
| 675 | 661 |
| 676 | 662 |
| 677 Node* ControlReducer::ReduceIfNodeForTesting(JSGraph* jsgraph, | 663 Node* ControlReducer::ReduceIfNodeForTesting(JSGraph* jsgraph, |
| 678 CommonOperatorBuilder* common, | 664 CommonOperatorBuilder* common, |
| 679 Node* node) { | 665 Node* node) { |
| 680 Zone zone; | 666 Zone zone; |
| 681 ControlReducerImpl impl(&zone, jsgraph, common); | 667 ControlReducerImpl impl(&zone, jsgraph, common); |
| 682 switch (node->opcode()) { | 668 switch (node->opcode()) { |
| 683 case IrOpcode::kIfTrue: | 669 case IrOpcode::kIfTrue: |
| 684 return impl.ReduceIfTrue(node); | 670 return impl.ReduceIfProjection(node, kTrue); |
| 685 case IrOpcode::kIfFalse: | 671 case IrOpcode::kIfFalse: |
| 686 return impl.ReduceIfFalse(node); | 672 return impl.ReduceIfProjection(node, kFalse); |
| 687 default: | 673 default: |
| 688 return node; | 674 return node; |
| 689 } | 675 } |
| 690 } | 676 } |
| 691 } | 677 } |
| 692 } | 678 } |
| 693 } // namespace v8::internal::compiler | 679 } // namespace v8::internal::compiler |
| OLD | NEW |