| 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-native-context-specialization.h" | 5 #include "src/compiler/js-native-context-specialization.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
| 9 #include "src/compilation-dependencies.h" | 9 #include "src/compilation-dependencies.h" |
| 10 #include "src/compiler/access-builder.h" | 10 #include "src/compiler/access-builder.h" |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 transition_target->elements_kind(), | 629 transition_target->elements_kind(), |
| 630 transition_source->IsJSArrayMap()); | 630 transition_source->IsJSArrayMap()); |
| 631 CallDescriptor const* const desc = Linkage::GetStubCallDescriptor( | 631 CallDescriptor const* const desc = Linkage::GetStubCallDescriptor( |
| 632 isolate(), graph()->zone(), stub.GetCallInterfaceDescriptor(), 0, | 632 isolate(), graph()->zone(), stub.GetCallInterfaceDescriptor(), 0, |
| 633 CallDescriptor::kNeedsFrameState, node->op()->properties()); | 633 CallDescriptor::kNeedsFrameState, node->op()->properties()); |
| 634 transition_effect = graph()->NewNode( | 634 transition_effect = graph()->NewNode( |
| 635 common()->Call(desc), jsgraph()->HeapConstant(stub.GetCode()), | 635 common()->Call(desc), jsgraph()->HeapConstant(stub.GetCode()), |
| 636 receiver, jsgraph()->HeapConstant(transition_target), context, | 636 receiver, jsgraph()->HeapConstant(transition_target), context, |
| 637 frame_state, transition_effect, transition_control); | 637 frame_state, transition_effect, transition_control); |
| 638 } | 638 } |
| 639 | |
| 640 // TODO(turbofan): The effect/control linearization will not find a | |
| 641 // FrameState after the StoreField or Call that is generated for the | |
| 642 // elements kind transition above. This is because those operatos don't | |
| 643 // have the kNoWrite flag on it, even tho they are not JavaScript | |
| 644 // observable, but at the same time adding kNoWrite would make them | |
| 645 // eliminatable during instruction selection (at least the Call one). | |
| 646 transition_effect = | |
| 647 graph()->NewNode(common()->Checkpoint(), frame_state, | |
| 648 transition_effect, transition_control); | |
| 649 | |
| 650 this_controls.push_back(transition_control); | 639 this_controls.push_back(transition_control); |
| 651 this_effects.push_back(transition_effect); | 640 this_effects.push_back(transition_effect); |
| 652 } | 641 } |
| 653 | 642 |
| 654 // Create single chokepoint for the control. | 643 // Create single chokepoint for the control. |
| 655 int const this_control_count = static_cast<int>(this_controls.size()); | 644 int const this_control_count = static_cast<int>(this_controls.size()); |
| 656 if (this_control_count == 1) { | 645 if (this_control_count == 1) { |
| 657 this_control = this_controls.front(); | 646 this_control = this_controls.front(); |
| 658 this_effect = this_effects.front(); | 647 this_effect = this_effects.front(); |
| 659 } else { | 648 } else { |
| 660 this_control = | 649 this_control = |
| 661 graph()->NewNode(common()->Merge(this_control_count), | 650 graph()->NewNode(common()->Merge(this_control_count), |
| 662 this_control_count, &this_controls.front()); | 651 this_control_count, &this_controls.front()); |
| 663 this_effects.push_back(this_control); | 652 this_effects.push_back(this_control); |
| 664 this_effect = | 653 this_effect = |
| 665 graph()->NewNode(common()->EffectPhi(this_control_count), | 654 graph()->NewNode(common()->EffectPhi(this_control_count), |
| 666 this_control_count + 1, &this_effects.front()); | 655 this_control_count + 1, &this_effects.front()); |
| 667 | |
| 668 // TODO(turbofan): This is another work-around, which is necessary | |
| 669 // in addition to the Checkpoint above, as the CheckpointElimination | |
| 670 // is not really compositional. We really need a way to address the | |
| 671 // "no-write" problem on non-side-effecting nodes. | |
| 672 this_effect = graph()->NewNode(common()->Checkpoint(), frame_state, | |
| 673 this_effect, this_control); | |
| 674 } | 656 } |
| 675 } | 657 } |
| 676 | 658 |
| 677 // Certain stores need a prototype chain check because shape changes | 659 // Certain stores need a prototype chain check because shape changes |
| 678 // could allow callbacks on elements in the prototype chain that are | 660 // could allow callbacks on elements in the prototype chain that are |
| 679 // not compatible with (monomorphic) keyed stores. | 661 // not compatible with (monomorphic) keyed stores. |
| 680 Handle<JSObject> holder; | 662 Handle<JSObject> holder; |
| 681 if (access_info.holder().ToHandle(&holder)) { | 663 if (access_info.holder().ToHandle(&holder)) { |
| 682 AssumePrototypesStable(receiver_type, native_context, holder); | 664 AssumePrototypesStable(receiver_type, native_context, holder); |
| 683 } | 665 } |
| 684 | 666 |
| 667 // Check that the {index} is actually a Number. |
| 668 if (!NumberMatcher(this_index).HasValue()) { |
| 669 Node* check = |
| 670 graph()->NewNode(simplified()->ObjectIsNumber(), this_index); |
| 671 this_control = this_effect = |
| 672 graph()->NewNode(common()->DeoptimizeUnless(), check, frame_state, |
| 673 this_effect, this_control); |
| 674 this_index = graph()->NewNode(simplified()->TypeGuard(Type::Number()), |
| 675 this_index, this_control); |
| 676 } |
| 677 |
| 678 // Convert the {index} to an unsigned32 value and check if the result is |
| 679 // equal to the original {index}. |
| 680 if (!NumberMatcher(this_index).IsInRange(0.0, kMaxUInt32)) { |
| 681 Node* this_index32 = |
| 682 graph()->NewNode(simplified()->NumberToUint32(), this_index); |
| 683 Node* check = graph()->NewNode(simplified()->NumberEqual(), this_index32, |
| 684 this_index); |
| 685 this_control = this_effect = |
| 686 graph()->NewNode(common()->DeoptimizeUnless(), check, frame_state, |
| 687 this_effect, this_control); |
| 688 this_index = this_index32; |
| 689 } |
| 690 |
| 685 // TODO(bmeurer): We currently specialize based on elements kind. We should | 691 // TODO(bmeurer): We currently specialize based on elements kind. We should |
| 686 // also be able to properly support strings and other JSObjects here. | 692 // also be able to properly support strings and other JSObjects here. |
| 687 ElementsKind elements_kind = access_info.elements_kind(); | 693 ElementsKind elements_kind = access_info.elements_kind(); |
| 688 | 694 |
| 689 // Load the elements for the {receiver}. | 695 // Load the elements for the {receiver}. |
| 690 Node* this_elements = this_effect = graph()->NewNode( | 696 Node* this_elements = this_effect = graph()->NewNode( |
| 691 simplified()->LoadField(AccessBuilder::ForJSObjectElements()), | 697 simplified()->LoadField(AccessBuilder::ForJSObjectElements()), |
| 692 this_receiver, this_effect, this_control); | 698 this_receiver, this_effect, this_control); |
| 693 | 699 |
| 694 // Don't try to store to a copy-on-write backing store. | 700 // Don't try to store to a copy-on-write backing store. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 710 receiver_is_jsarray | 716 receiver_is_jsarray |
| 711 ? graph()->NewNode( | 717 ? graph()->NewNode( |
| 712 simplified()->LoadField( | 718 simplified()->LoadField( |
| 713 AccessBuilder::ForJSArrayLength(elements_kind)), | 719 AccessBuilder::ForJSArrayLength(elements_kind)), |
| 714 this_receiver, this_effect, this_control) | 720 this_receiver, this_effect, this_control) |
| 715 : graph()->NewNode( | 721 : graph()->NewNode( |
| 716 simplified()->LoadField(AccessBuilder::ForFixedArrayLength()), | 722 simplified()->LoadField(AccessBuilder::ForFixedArrayLength()), |
| 717 this_elements, this_effect, this_control); | 723 this_elements, this_effect, this_control); |
| 718 | 724 |
| 719 // Check that the {index} is in the valid range for the {receiver}. | 725 // Check that the {index} is in the valid range for the {receiver}. |
| 720 this_index = this_effect = | 726 Node* check = graph()->NewNode(simplified()->NumberLessThan(), this_index, |
| 721 graph()->NewNode(simplified()->CheckBounds(), this_index, this_length, | 727 this_length); |
| 728 this_control = this_effect = |
| 729 graph()->NewNode(common()->DeoptimizeUnless(), check, frame_state, |
| 722 this_effect, this_control); | 730 this_effect, this_control); |
| 723 | 731 |
| 724 // Compute the element access. | 732 // Compute the element access. |
| 725 Type* element_type = Type::Any(); | 733 Type* element_type = Type::Any(); |
| 726 MachineType element_machine_type = MachineType::AnyTagged(); | 734 MachineType element_machine_type = MachineType::AnyTagged(); |
| 727 if (IsFastDoubleElementsKind(elements_kind)) { | 735 if (IsFastDoubleElementsKind(elements_kind)) { |
| 728 element_type = Type::Number(); | 736 element_type = Type::Number(); |
| 729 element_machine_type = MachineType::Float64(); | 737 element_machine_type = MachineType::Float64(); |
| 730 } else if (IsFastSmiElementsKind(elements_kind)) { | 738 } else if (IsFastSmiElementsKind(elements_kind)) { |
| 731 element_type = type_cache_.kSmi; | 739 element_type = type_cache_.kSmi; |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 } | 1129 } |
| 1122 | 1130 |
| 1123 | 1131 |
| 1124 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { | 1132 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { |
| 1125 return jsgraph()->simplified(); | 1133 return jsgraph()->simplified(); |
| 1126 } | 1134 } |
| 1127 | 1135 |
| 1128 } // namespace compiler | 1136 } // namespace compiler |
| 1129 } // namespace internal | 1137 } // namespace internal |
| 1130 } // namespace v8 | 1138 } // namespace v8 |
| OLD | NEW |