| 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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 Revisit(phi); | 559 Revisit(phi); |
| 560 } | 560 } |
| 561 // Edit the merge in place, removing dead inputs. | 561 // Edit the merge in place, removing dead inputs. |
| 562 RemoveDeadInputs(node, node); | 562 RemoveDeadInputs(node, node); |
| 563 } | 563 } |
| 564 | 564 |
| 565 DCHECK_EQ(live, node->InputCount()); | 565 DCHECK_EQ(live, node->InputCount()); |
| 566 | 566 |
| 567 // Check if it's an unused diamond. | 567 // Check if it's an unused diamond. |
| 568 if (live == 2 && phis.empty()) { | 568 if (live == 2 && phis.empty()) { |
| 569 Node* node0 = node->InputAt(0); | 569 DiamondMatcher matcher(node); |
| 570 Node* node1 = node->InputAt(1); | 570 if (matcher.Matched() && matcher.IfProjectionsAreOwned()) { |
| 571 if (((node0->opcode() == IrOpcode::kIfTrue && | 571 // It's a dead diamond, i.e. neither the IfTrue nor the IfFalse nodes |
| 572 node1->opcode() == IrOpcode::kIfFalse) || | 572 // have uses except for the Merge and the Merge has no Phi or |
| 573 (node1->opcode() == IrOpcode::kIfTrue && | 573 // EffectPhi uses, so replace the Merge with the control input of the |
| 574 node0->opcode() == IrOpcode::kIfFalse)) && | 574 // diamond. |
| 575 node0->OwnedBy(node) && node1->OwnedBy(node)) { | 575 TRACE(" DeadDiamond: #%d:Branch #%d:IfTrue #%d:IfFalse\n", |
| 576 Node* branch0 = NodeProperties::GetControlInput(node0); | 576 matcher.Branch()->id(), matcher.IfTrue()->id(), |
| 577 Node* branch1 = NodeProperties::GetControlInput(node1); | 577 matcher.IfFalse()->id()); |
| 578 if (branch0 == branch1) { | 578 // TODO(turbofan): replace single-phi diamonds with selects. |
| 579 // It's a dead diamond, i.e. neither the IfTrue nor the IfFalse nodes | 579 return NodeProperties::GetControlInput(matcher.Branch()); |
| 580 // have users except for the Merge and the Merge has no Phi or | |
| 581 // EffectPhi uses, so replace the Merge with the control input of the | |
| 582 // diamond. | |
| 583 TRACE(" DeadDiamond: #%d:%s #%d:%s #%d:%s\n", node0->id(), | |
| 584 node0->op()->mnemonic(), node1->id(), node1->op()->mnemonic(), | |
| 585 branch0->id(), branch0->op()->mnemonic()); | |
| 586 return NodeProperties::GetControlInput(branch0); | |
| 587 } | |
| 588 } | 580 } |
| 589 } | 581 } |
| 590 | 582 |
| 591 return node; | 583 return node; |
| 592 } | 584 } |
| 593 | 585 |
| 594 // Reduce if projections if the branch has a constant input. | 586 // Reduce if projections if the branch has a constant input. |
| 595 Node* ReduceIfProjection(Node* node, Decision decision) { | 587 Node* ReduceIfProjection(Node* node, Decision decision) { |
| 596 Node* branch = node->InputAt(0); | 588 Node* branch = node->InputAt(0); |
| 597 DCHECK_EQ(IrOpcode::kBranch, branch->opcode()); | 589 DCHECK_EQ(IrOpcode::kBranch, branch->opcode()); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 return impl.ReduceIfProjection(node, kTrue); | 677 return impl.ReduceIfProjection(node, kTrue); |
| 686 case IrOpcode::kIfFalse: | 678 case IrOpcode::kIfFalse: |
| 687 return impl.ReduceIfProjection(node, kFalse); | 679 return impl.ReduceIfProjection(node, kFalse); |
| 688 default: | 680 default: |
| 689 return node; | 681 return node; |
| 690 } | 682 } |
| 691 } | 683 } |
| 692 } | 684 } |
| 693 } | 685 } |
| 694 } // namespace v8::internal::compiler | 686 } // namespace v8::internal::compiler |
| OLD | NEW |