| 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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 Revisit(phi); | 544 Revisit(phi); |
| 545 } | 545 } |
| 546 // Edit the merge in place, removing dead inputs. | 546 // Edit the merge in place, removing dead inputs. |
| 547 RemoveDeadInputs(node, node); | 547 RemoveDeadInputs(node, node); |
| 548 } | 548 } |
| 549 | 549 |
| 550 DCHECK_EQ(live, node->InputCount()); | 550 DCHECK_EQ(live, node->InputCount()); |
| 551 | 551 |
| 552 // Check if it's an unused diamond. | 552 // Check if it's an unused diamond. |
| 553 if (live == 2 && phis.empty()) { | 553 if (live == 2 && phis.empty()) { |
| 554 Node* node0 = node->InputAt(0); | 554 DiamondMatcher matcher(node); |
| 555 Node* node1 = node->InputAt(1); | 555 if (matcher.Matched() && matcher.IfProjsAreOwned()) { |
| 556 if (((node0->opcode() == IrOpcode::kIfTrue && | 556 // It's a dead diamond, i.e. neither the IfTrue nor the IfFalse nodes |
| 557 node1->opcode() == IrOpcode::kIfFalse) || | 557 // have uses except for the Merge and the Merge has no Phi or |
| 558 (node1->opcode() == IrOpcode::kIfTrue && | 558 // EffectPhi uses, so replace the Merge with the control input of the |
| 559 node0->opcode() == IrOpcode::kIfFalse)) && | 559 // diamond. |
| 560 node0->OwnedBy(node) && node1->OwnedBy(node)) { | 560 TRACE(" DeadDiamond: #%d:Branch #%d:IfTrue #%d:IfFalse\n", |
| 561 Node* branch0 = NodeProperties::GetControlInput(node0); | 561 matcher.Branch()->id(), matcher.IfTrue()->id(), |
| 562 Node* branch1 = NodeProperties::GetControlInput(node1); | 562 matcher.IfFalse()->id()); |
| 563 if (branch0 == branch1) { | 563 // TODO(turbofan): replace single-phi diamonds with selects. |
| 564 // It's a dead diamond, i.e. neither the IfTrue nor the IfFalse nodes | 564 return NodeProperties::GetControlInput(matcher.Branch()); |
| 565 // have users except for the Merge and the Merge has no Phi or | |
| 566 // EffectPhi uses, so replace the Merge with the control input of the | |
| 567 // diamond. | |
| 568 TRACE(" DeadDiamond: #%d:%s #%d:%s #%d:%s\n", node0->id(), | |
| 569 node0->op()->mnemonic(), node1->id(), node1->op()->mnemonic(), | |
| 570 branch0->id(), branch0->op()->mnemonic()); | |
| 571 return NodeProperties::GetControlInput(branch0); | |
| 572 } | |
| 573 } | 565 } |
| 574 } | 566 } |
| 575 | 567 |
| 576 return node; | 568 return node; |
| 577 } | 569 } |
| 578 | 570 |
| 579 // Reduce if projections if the branch has a constant input. | 571 // Reduce if projections if the branch has a constant input. |
| 580 Node* ReduceIfProjection(Node* node, Decision decision) { | 572 Node* ReduceIfProjection(Node* node, Decision decision) { |
| 581 Node* branch = node->InputAt(0); | 573 Node* branch = node->InputAt(0); |
| 582 DCHECK_EQ(IrOpcode::kBranch, branch->opcode()); | 574 DCHECK_EQ(IrOpcode::kBranch, branch->opcode()); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 return impl.ReduceIfProjection(node, kTrue); | 662 return impl.ReduceIfProjection(node, kTrue); |
| 671 case IrOpcode::kIfFalse: | 663 case IrOpcode::kIfFalse: |
| 672 return impl.ReduceIfProjection(node, kFalse); | 664 return impl.ReduceIfProjection(node, kFalse); |
| 673 default: | 665 default: |
| 674 return node; | 666 return node; |
| 675 } | 667 } |
| 676 } | 668 } |
| 677 } | 669 } |
| 678 } | 670 } |
| 679 } // namespace v8::internal::compiler | 671 } // namespace v8::internal::compiler |
| OLD | NEW |