| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/js-call-reducer.h" | 5 #include "src/compiler/js-call-reducer.h" |
| 6 | 6 |
| 7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
| 8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
| 9 #include "src/compilation-dependencies.h" | 9 #include "src/compilation-dependencies.h" |
| 10 #include "src/compiler/js-graph.h" | 10 #include "src/compiler/js-graph.h" |
| 11 #include "src/compiler/linkage.h" | 11 #include "src/compiler/linkage.h" |
| 12 #include "src/compiler/node-matchers.h" | 12 #include "src/compiler/node-matchers.h" |
| 13 #include "src/compiler/simplified-operator.h" | 13 #include "src/compiler/simplified-operator.h" |
| 14 #include "src/objects-inl.h" | 14 #include "src/objects-inl.h" |
| 15 #include "src/type-feedback-vector-inl.h" | 15 #include "src/type-feedback-vector-inl.h" |
| 16 | 16 |
| 17 namespace v8 { | 17 namespace v8 { |
| 18 namespace internal { | 18 namespace internal { |
| 19 namespace compiler { | 19 namespace compiler { |
| 20 | 20 |
| 21 Reduction JSCallReducer::Reduce(Node* node) { | 21 Reduction JSCallReducer::Reduce(Node* node) { |
| 22 switch (node->opcode()) { | 22 switch (node->opcode()) { |
| 23 case IrOpcode::kJSCallConstruct: | 23 case IrOpcode::kJSConstruct: |
| 24 return ReduceJSCallConstruct(node); | 24 return ReduceJSConstruct(node); |
| 25 case IrOpcode::kJSCallConstructWithSpread: | 25 case IrOpcode::kJSConstructWithSpread: |
| 26 return ReduceJSCallConstructWithSpread(node); | 26 return ReduceJSConstructWithSpread(node); |
| 27 case IrOpcode::kJSCallFunction: | 27 case IrOpcode::kJSCallFunction: |
| 28 return ReduceJSCallFunction(node); | 28 return ReduceJSCallFunction(node); |
| 29 default: | 29 default: |
| 30 break; | 30 break; |
| 31 } | 31 } |
| 32 return NoChange(); | 32 return NoChange(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 | 35 |
| 36 // ES6 section 22.1.1 The Array Constructor | 36 // ES6 section 22.1.1 The Array Constructor |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 NodeProperties::ReplaceEffectInput(node, effect); | 571 NodeProperties::ReplaceEffectInput(node, effect); |
| 572 | 572 |
| 573 // Try to further reduce the JSCallFunction {node}. | 573 // Try to further reduce the JSCallFunction {node}. |
| 574 Reduction const reduction = ReduceJSCallFunction(node); | 574 Reduction const reduction = ReduceJSCallFunction(node); |
| 575 return reduction.Changed() ? reduction : Changed(node); | 575 return reduction.Changed() ? reduction : Changed(node); |
| 576 } | 576 } |
| 577 } | 577 } |
| 578 return NoChange(); | 578 return NoChange(); |
| 579 } | 579 } |
| 580 | 580 |
| 581 | 581 Reduction JSCallReducer::ReduceJSConstruct(Node* node) { |
| 582 Reduction JSCallReducer::ReduceJSCallConstruct(Node* node) { | 582 DCHECK_EQ(IrOpcode::kJSConstruct, node->opcode()); |
| 583 DCHECK_EQ(IrOpcode::kJSCallConstruct, node->opcode()); | 583 ConstructParameters const& p = ConstructParametersOf(node->op()); |
| 584 CallConstructParameters const& p = CallConstructParametersOf(node->op()); | |
| 585 DCHECK_LE(2u, p.arity()); | 584 DCHECK_LE(2u, p.arity()); |
| 586 int const arity = static_cast<int>(p.arity() - 2); | 585 int const arity = static_cast<int>(p.arity() - 2); |
| 587 Node* target = NodeProperties::GetValueInput(node, 0); | 586 Node* target = NodeProperties::GetValueInput(node, 0); |
| 588 Node* new_target = NodeProperties::GetValueInput(node, arity + 1); | 587 Node* new_target = NodeProperties::GetValueInput(node, arity + 1); |
| 589 Node* effect = NodeProperties::GetEffectInput(node); | 588 Node* effect = NodeProperties::GetEffectInput(node); |
| 590 Node* control = NodeProperties::GetControlInput(node); | 589 Node* control = NodeProperties::GetControlInput(node); |
| 591 | 590 |
| 592 // Try to specialize JSCallConstruct {node}s with constant {target}s. | 591 // Try to specialize JSConstruct {node}s with constant {target}s. |
| 593 HeapObjectMatcher m(target); | 592 HeapObjectMatcher m(target); |
| 594 if (m.HasValue()) { | 593 if (m.HasValue()) { |
| 595 if (m.Value()->IsJSFunction()) { | 594 if (m.Value()->IsJSFunction()) { |
| 596 Handle<JSFunction> function = Handle<JSFunction>::cast(m.Value()); | 595 Handle<JSFunction> function = Handle<JSFunction>::cast(m.Value()); |
| 597 | 596 |
| 598 // Raise a TypeError if the {target} is not a constructor. | 597 // Raise a TypeError if the {target} is not a constructor. |
| 599 if (!function->IsConstructor()) { | 598 if (!function->IsConstructor()) { |
| 600 NodeProperties::ReplaceValueInputs(node, target); | 599 NodeProperties::ReplaceValueInputs(node, target); |
| 601 NodeProperties::ChangeOp( | 600 NodeProperties::ChangeOp( |
| 602 node, javascript()->CallRuntime( | 601 node, javascript()->CallRuntime( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 if (cell->value()->IsJSFunction()) { | 670 if (cell->value()->IsJSFunction()) { |
| 672 Node* target_function = | 671 Node* target_function = |
| 673 jsgraph()->Constant(handle(cell->value(), isolate())); | 672 jsgraph()->Constant(handle(cell->value(), isolate())); |
| 674 | 673 |
| 675 // Check that the {target} is still the {target_function}. | 674 // Check that the {target} is still the {target_function}. |
| 676 Node* check = graph()->NewNode(simplified()->ReferenceEqual(), target, | 675 Node* check = graph()->NewNode(simplified()->ReferenceEqual(), target, |
| 677 target_function); | 676 target_function); |
| 678 effect = | 677 effect = |
| 679 graph()->NewNode(simplified()->CheckIf(), check, effect, control); | 678 graph()->NewNode(simplified()->CheckIf(), check, effect, control); |
| 680 | 679 |
| 681 // Specialize the JSCallConstruct node to the {target_function}. | 680 // Specialize the JSConstruct node to the {target_function}. |
| 682 NodeProperties::ReplaceValueInput(node, target_function, 0); | 681 NodeProperties::ReplaceValueInput(node, target_function, 0); |
| 683 NodeProperties::ReplaceEffectInput(node, effect); | 682 NodeProperties::ReplaceEffectInput(node, effect); |
| 684 if (target == new_target) { | 683 if (target == new_target) { |
| 685 NodeProperties::ReplaceValueInput(node, target_function, arity + 1); | 684 NodeProperties::ReplaceValueInput(node, target_function, arity + 1); |
| 686 } | 685 } |
| 687 | 686 |
| 688 // Try to further reduce the JSCallConstruct {node}. | 687 // Try to further reduce the JSConstruct {node}. |
| 689 Reduction const reduction = ReduceJSCallConstruct(node); | 688 Reduction const reduction = ReduceJSConstruct(node); |
| 690 return reduction.Changed() ? reduction : Changed(node); | 689 return reduction.Changed() ? reduction : Changed(node); |
| 691 } | 690 } |
| 692 } | 691 } |
| 693 | 692 |
| 694 return NoChange(); | 693 return NoChange(); |
| 695 } | 694 } |
| 696 | 695 |
| 697 Reduction JSCallReducer::ReduceJSCallConstructWithSpread(Node* node) { | 696 Reduction JSCallReducer::ReduceJSConstructWithSpread(Node* node) { |
| 698 DCHECK_EQ(IrOpcode::kJSCallConstructWithSpread, node->opcode()); | 697 DCHECK_EQ(IrOpcode::kJSConstructWithSpread, node->opcode()); |
| 699 CallConstructWithSpreadParameters const& p = | 698 ConstructWithSpreadParameters const& p = |
| 700 CallConstructWithSpreadParametersOf(node->op()); | 699 ConstructWithSpreadParametersOf(node->op()); |
| 701 DCHECK_LE(3u, p.arity()); | 700 DCHECK_LE(3u, p.arity()); |
| 702 int arity = static_cast<int>(p.arity() - 2); | 701 int arity = static_cast<int>(p.arity() - 2); |
| 703 | 702 |
| 704 // Do check to make sure we can actually avoid iteration. | 703 // Do check to make sure we can actually avoid iteration. |
| 705 if (!isolate()->initial_array_iterator_prototype_map()->is_stable()) { | 704 if (!isolate()->initial_array_iterator_prototype_map()->is_stable()) { |
| 706 return NoChange(); | 705 return NoChange(); |
| 707 } | 706 } |
| 708 | 707 |
| 709 Node* spread = NodeProperties::GetValueInput(node, arity); | 708 Node* spread = NodeProperties::GetValueInput(node, arity); |
| 710 | 709 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 node->RemoveInput(arity--); | 754 node->RemoveInput(arity--); |
| 756 | 755 |
| 757 // Add the actual parameters to the {node}, skipping the receiver. | 756 // Add the actual parameters to the {node}, skipping the receiver. |
| 758 Node* const parameters = frame_state->InputAt(kFrameStateParametersInput); | 757 Node* const parameters = frame_state->InputAt(kFrameStateParametersInput); |
| 759 for (int i = start_index + 1; i < state_info.parameter_count(); ++i) { | 758 for (int i = start_index + 1; i < state_info.parameter_count(); ++i) { |
| 760 node->InsertInput(graph()->zone(), static_cast<int>(++arity), | 759 node->InsertInput(graph()->zone(), static_cast<int>(++arity), |
| 761 parameters->InputAt(i)); | 760 parameters->InputAt(i)); |
| 762 } | 761 } |
| 763 | 762 |
| 764 NodeProperties::ChangeOp( | 763 NodeProperties::ChangeOp( |
| 765 node, javascript()->CallConstruct(arity + 2, 7, VectorSlotPair())); | 764 node, javascript()->Construct(arity + 2, 7, VectorSlotPair())); |
| 766 | 765 |
| 767 return Changed(node); | 766 return Changed(node); |
| 768 } | 767 } |
| 769 | 768 |
| 770 Graph* JSCallReducer::graph() const { return jsgraph()->graph(); } | 769 Graph* JSCallReducer::graph() const { return jsgraph()->graph(); } |
| 771 | 770 |
| 772 Isolate* JSCallReducer::isolate() const { return jsgraph()->isolate(); } | 771 Isolate* JSCallReducer::isolate() const { return jsgraph()->isolate(); } |
| 773 | 772 |
| 774 Factory* JSCallReducer::factory() const { return isolate()->factory(); } | 773 Factory* JSCallReducer::factory() const { return isolate()->factory(); } |
| 775 | 774 |
| 776 CommonOperatorBuilder* JSCallReducer::common() const { | 775 CommonOperatorBuilder* JSCallReducer::common() const { |
| 777 return jsgraph()->common(); | 776 return jsgraph()->common(); |
| 778 } | 777 } |
| 779 | 778 |
| 780 JSOperatorBuilder* JSCallReducer::javascript() const { | 779 JSOperatorBuilder* JSCallReducer::javascript() const { |
| 781 return jsgraph()->javascript(); | 780 return jsgraph()->javascript(); |
| 782 } | 781 } |
| 783 | 782 |
| 784 SimplifiedOperatorBuilder* JSCallReducer::simplified() const { | 783 SimplifiedOperatorBuilder* JSCallReducer::simplified() const { |
| 785 return jsgraph()->simplified(); | 784 return jsgraph()->simplified(); |
| 786 } | 785 } |
| 787 | 786 |
| 788 } // namespace compiler | 787 } // namespace compiler |
| 789 } // namespace internal | 788 } // namespace internal |
| 790 } // namespace v8 | 789 } // namespace v8 |
| OLD | NEW |