| 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 access_info.holder().ToHandle(&holder)) { | 247 access_info.holder().ToHandle(&holder)) { |
| 248 this_receiver = jsgraph()->Constant(holder); | 248 this_receiver = jsgraph()->Constant(holder); |
| 249 } | 249 } |
| 250 Node* this_storage = this_receiver; | 250 Node* this_storage = this_receiver; |
| 251 if (!field_index.is_inobject()) { | 251 if (!field_index.is_inobject()) { |
| 252 this_storage = this_effect = graph()->NewNode( | 252 this_storage = this_effect = graph()->NewNode( |
| 253 simplified()->LoadField(AccessBuilder::ForJSObjectProperties()), | 253 simplified()->LoadField(AccessBuilder::ForJSObjectProperties()), |
| 254 this_storage, this_effect, this_control); | 254 this_storage, this_effect, this_control); |
| 255 } | 255 } |
| 256 FieldAccess field_access = {kTaggedBase, field_index.offset(), name, | 256 FieldAccess field_access = {kTaggedBase, field_index.offset(), name, |
| 257 field_type, kMachAnyTagged}; | 257 field_type, MachineType::AnyTagged()}; |
| 258 if (access_mode == AccessMode::kLoad) { | 258 if (access_mode == AccessMode::kLoad) { |
| 259 if (field_type->Is(Type::UntaggedFloat64())) { | 259 if (field_type->Is(Type::UntaggedFloat64())) { |
| 260 if (!field_index.is_inobject() || field_index.is_hidden_field() || | 260 if (!field_index.is_inobject() || field_index.is_hidden_field() || |
| 261 !FLAG_unbox_double_fields) { | 261 !FLAG_unbox_double_fields) { |
| 262 this_storage = this_effect = | 262 this_storage = this_effect = |
| 263 graph()->NewNode(simplified()->LoadField(field_access), | 263 graph()->NewNode(simplified()->LoadField(field_access), |
| 264 this_storage, this_effect, this_control); | 264 this_storage, this_effect, this_control); |
| 265 field_access.offset = HeapNumber::kValueOffset; | 265 field_access.offset = HeapNumber::kValueOffset; |
| 266 field_access.name = MaybeHandle<Name>(); | 266 field_access.name = MaybeHandle<Name>(); |
| 267 } | 267 } |
| 268 field_access.machine_type = kMachFloat64; | 268 field_access.machine_type = MachineType::Float64(); |
| 269 } | 269 } |
| 270 this_value = this_effect = | 270 this_value = this_effect = |
| 271 graph()->NewNode(simplified()->LoadField(field_access), | 271 graph()->NewNode(simplified()->LoadField(field_access), |
| 272 this_storage, this_effect, this_control); | 272 this_storage, this_effect, this_control); |
| 273 } else { | 273 } else { |
| 274 DCHECK_EQ(AccessMode::kStore, access_mode); | 274 DCHECK_EQ(AccessMode::kStore, access_mode); |
| 275 if (field_type->Is(Type::UntaggedFloat64())) { | 275 if (field_type->Is(Type::UntaggedFloat64())) { |
| 276 Node* check = | 276 Node* check = |
| 277 graph()->NewNode(simplified()->ObjectIsNumber(), this_value); | 277 graph()->NewNode(simplified()->ObjectIsNumber(), this_value); |
| 278 Node* branch = graph()->NewNode(common()->Branch(BranchHint::kTrue), | 278 Node* branch = graph()->NewNode(common()->Branch(BranchHint::kTrue), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 302 this_value = this_box; | 302 this_value = this_box; |
| 303 | 303 |
| 304 field_access.type = Type::TaggedPointer(); | 304 field_access.type = Type::TaggedPointer(); |
| 305 } else { | 305 } else { |
| 306 // We just store directly to the MutableHeapNumber. | 306 // We just store directly to the MutableHeapNumber. |
| 307 this_storage = this_effect = | 307 this_storage = this_effect = |
| 308 graph()->NewNode(simplified()->LoadField(field_access), | 308 graph()->NewNode(simplified()->LoadField(field_access), |
| 309 this_storage, this_effect, this_control); | 309 this_storage, this_effect, this_control); |
| 310 field_access.offset = HeapNumber::kValueOffset; | 310 field_access.offset = HeapNumber::kValueOffset; |
| 311 field_access.name = MaybeHandle<Name>(); | 311 field_access.name = MaybeHandle<Name>(); |
| 312 field_access.machine_type = kMachFloat64; | 312 field_access.machine_type = MachineType::Float64(); |
| 313 } | 313 } |
| 314 } else { | 314 } else { |
| 315 // Unboxed double field, we store directly to the field. | 315 // Unboxed double field, we store directly to the field. |
| 316 field_access.machine_type = kMachFloat64; | 316 field_access.machine_type = MachineType::Float64(); |
| 317 } | 317 } |
| 318 } else if (field_type->Is(Type::TaggedSigned())) { | 318 } else if (field_type->Is(Type::TaggedSigned())) { |
| 319 Node* check = | 319 Node* check = |
| 320 graph()->NewNode(simplified()->ObjectIsSmi(), this_value); | 320 graph()->NewNode(simplified()->ObjectIsSmi(), this_value); |
| 321 Node* branch = graph()->NewNode(common()->Branch(BranchHint::kTrue), | 321 Node* branch = graph()->NewNode(common()->Branch(BranchHint::kTrue), |
| 322 check, this_control); | 322 check, this_control); |
| 323 exit_controls.push_back( | 323 exit_controls.push_back( |
| 324 graph()->NewNode(common()->IfFalse(), branch)); | 324 graph()->NewNode(common()->IfFalse(), branch)); |
| 325 this_control = graph()->NewNode(common()->IfTrue(), branch); | 325 this_control = graph()->NewNode(common()->IfTrue(), branch); |
| 326 } else if (field_type->Is(Type::TaggedPointer())) { | 326 } else if (field_type->Is(Type::TaggedPointer())) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 if (control_count == 0) { | 422 if (control_count == 0) { |
| 423 value = effect = control = jsgraph()->Dead(); | 423 value = effect = control = jsgraph()->Dead(); |
| 424 } else if (control_count == 1) { | 424 } else if (control_count == 1) { |
| 425 value = values.front(); | 425 value = values.front(); |
| 426 effect = effects.front(); | 426 effect = effects.front(); |
| 427 control = controls.front(); | 427 control = controls.front(); |
| 428 } else { | 428 } else { |
| 429 control = graph()->NewNode(common()->Merge(control_count), control_count, | 429 control = graph()->NewNode(common()->Merge(control_count), control_count, |
| 430 &controls.front()); | 430 &controls.front()); |
| 431 values.push_back(control); | 431 values.push_back(control); |
| 432 value = graph()->NewNode(common()->Phi(kMachAnyTagged, control_count), | 432 value = graph()->NewNode( |
| 433 control_count + 1, &values.front()); | 433 common()->Phi(MachineRepresentation::kTagged, control_count), |
| 434 control_count + 1, &values.front()); |
| 434 effects.push_back(control); | 435 effects.push_back(control); |
| 435 effect = graph()->NewNode(common()->EffectPhi(control_count), | 436 effect = graph()->NewNode(common()->EffectPhi(control_count), |
| 436 control_count + 1, &effects.front()); | 437 control_count + 1, &effects.front()); |
| 437 } | 438 } |
| 438 ReplaceWithValue(node, value, effect, control); | 439 ReplaceWithValue(node, value, effect, control); |
| 439 return Replace(value); | 440 return Replace(value); |
| 440 } | 441 } |
| 441 | 442 |
| 442 | 443 |
| 443 Reduction JSNativeContextSpecialization::ReduceJSLoadNamed(Node* node) { | 444 Reduction JSNativeContextSpecialization::ReduceJSLoadNamed(Node* node) { |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 // Check that the {index} is in the valid range for the {receiver}. | 694 // Check that the {index} is in the valid range for the {receiver}. |
| 694 Node* check = graph()->NewNode(simplified()->NumberLessThan(), this_index, | 695 Node* check = graph()->NewNode(simplified()->NumberLessThan(), this_index, |
| 695 this_length); | 696 this_length); |
| 696 Node* branch = graph()->NewNode(common()->Branch(BranchHint::kTrue), check, | 697 Node* branch = graph()->NewNode(common()->Branch(BranchHint::kTrue), check, |
| 697 this_control); | 698 this_control); |
| 698 exit_controls.push_back(graph()->NewNode(common()->IfFalse(), branch)); | 699 exit_controls.push_back(graph()->NewNode(common()->IfFalse(), branch)); |
| 699 this_control = graph()->NewNode(common()->IfTrue(), branch); | 700 this_control = graph()->NewNode(common()->IfTrue(), branch); |
| 700 | 701 |
| 701 // Compute the element access. | 702 // Compute the element access. |
| 702 Type* element_type = Type::Any(); | 703 Type* element_type = Type::Any(); |
| 703 MachineType element_machine_type = kMachAnyTagged; | 704 MachineType element_machine_type = MachineType::AnyTagged(); |
| 704 if (IsFastDoubleElementsKind(elements_kind)) { | 705 if (IsFastDoubleElementsKind(elements_kind)) { |
| 705 element_type = type_cache_.kFloat64; | 706 element_type = type_cache_.kFloat64; |
| 706 element_machine_type = kMachFloat64; | 707 element_machine_type = MachineType::Float64(); |
| 707 } else if (IsFastSmiElementsKind(elements_kind)) { | 708 } else if (IsFastSmiElementsKind(elements_kind)) { |
| 708 element_type = type_cache_.kSmi; | 709 element_type = type_cache_.kSmi; |
| 709 } | 710 } |
| 710 ElementAccess element_access = {kTaggedBase, FixedArray::kHeaderSize, | 711 ElementAccess element_access = {kTaggedBase, FixedArray::kHeaderSize, |
| 711 element_type, element_machine_type}; | 712 element_type, element_machine_type}; |
| 712 | 713 |
| 713 // Access the actual element. | 714 // Access the actual element. |
| 714 // TODO(bmeurer): Refactor this into separate methods or even a separate | 715 // TODO(bmeurer): Refactor this into separate methods or even a separate |
| 715 // class that deals with the elements access. | 716 // class that deals with the elements access. |
| 716 if (access_mode == AccessMode::kLoad) { | 717 if (access_mode == AccessMode::kLoad) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 745 graph()->zone()); | 746 graph()->zone()); |
| 746 if (receiver_type->NowIs(initial_holey_array_type) && | 747 if (receiver_type->NowIs(initial_holey_array_type) && |
| 747 isolate()->IsFastArrayConstructorPrototypeChainIntact()) { | 748 isolate()->IsFastArrayConstructorPrototypeChainIntact()) { |
| 748 // Add a code dependency on the array protector cell. | 749 // Add a code dependency on the array protector cell. |
| 749 AssumePrototypesStable(receiver_type, native_context, | 750 AssumePrototypesStable(receiver_type, native_context, |
| 750 isolate()->initial_object_prototype()); | 751 isolate()->initial_object_prototype()); |
| 751 dependencies()->AssumePropertyCell(factory()->array_protector()); | 752 dependencies()->AssumePropertyCell(factory()->array_protector()); |
| 752 // Turn the hole into undefined. | 753 // Turn the hole into undefined. |
| 753 this_control = | 754 this_control = |
| 754 graph()->NewNode(common()->Merge(2), if_true, if_false); | 755 graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 755 this_value = graph()->NewNode(common()->Phi(kMachAnyTagged, 2), | 756 this_value = graph()->NewNode( |
| 756 jsgraph()->UndefinedConstant(), | 757 common()->Phi(MachineRepresentation::kTagged, 2), |
| 757 this_value, this_control); | 758 jsgraph()->UndefinedConstant(), this_value, this_control); |
| 758 element_type = | 759 element_type = |
| 759 Type::Union(element_type, Type::Undefined(), graph()->zone()); | 760 Type::Union(element_type, Type::Undefined(), graph()->zone()); |
| 760 } else { | 761 } else { |
| 761 // Deoptimize in case of the hole. | 762 // Deoptimize in case of the hole. |
| 762 exit_controls.push_back(if_true); | 763 exit_controls.push_back(if_true); |
| 763 this_control = if_false; | 764 this_control = if_false; |
| 764 } | 765 } |
| 765 // Rename the result to represent the actual type (not polluted by the | 766 // Rename the result to represent the actual type (not polluted by the |
| 766 // hole). | 767 // hole). |
| 767 this_value = graph()->NewNode(common()->Guard(element_type), this_value, | 768 this_value = graph()->NewNode(common()->Guard(element_type), this_value, |
| 768 this_control); | 769 this_control); |
| 769 } else if (elements_kind == FAST_HOLEY_DOUBLE_ELEMENTS) { | 770 } else if (elements_kind == FAST_HOLEY_DOUBLE_ELEMENTS) { |
| 770 // Perform the hole check on the result. | 771 // Perform the hole check on the result. |
| 771 Node* check = | 772 Node* check = |
| 772 graph()->NewNode(simplified()->NumberIsHoleNaN(), this_value); | 773 graph()->NewNode(simplified()->NumberIsHoleNaN(), this_value); |
| 773 // Check if we are allowed to return the hole directly. | 774 // Check if we are allowed to return the hole directly. |
| 774 Type* initial_holey_array_type = Type::Class( | 775 Type* initial_holey_array_type = Type::Class( |
| 775 handle(isolate()->get_initial_js_array_map(elements_kind)), | 776 handle(isolate()->get_initial_js_array_map(elements_kind)), |
| 776 graph()->zone()); | 777 graph()->zone()); |
| 777 if (receiver_type->NowIs(initial_holey_array_type) && | 778 if (receiver_type->NowIs(initial_holey_array_type) && |
| 778 isolate()->IsFastArrayConstructorPrototypeChainIntact()) { | 779 isolate()->IsFastArrayConstructorPrototypeChainIntact()) { |
| 779 // Add a code dependency on the array protector cell. | 780 // Add a code dependency on the array protector cell. |
| 780 AssumePrototypesStable(receiver_type, native_context, | 781 AssumePrototypesStable(receiver_type, native_context, |
| 781 isolate()->initial_object_prototype()); | 782 isolate()->initial_object_prototype()); |
| 782 dependencies()->AssumePropertyCell(factory()->array_protector()); | 783 dependencies()->AssumePropertyCell(factory()->array_protector()); |
| 783 // Turn the hole into undefined. | 784 // Turn the hole into undefined. |
| 784 this_value = graph()->NewNode( | 785 this_value = graph()->NewNode( |
| 785 common()->Select(kMachAnyTagged, BranchHint::kFalse), check, | 786 common()->Select(MachineRepresentation::kTagged, |
| 786 jsgraph()->UndefinedConstant(), this_value); | 787 BranchHint::kFalse), |
| 788 check, jsgraph()->UndefinedConstant(), this_value); |
| 787 } else { | 789 } else { |
| 788 // Deoptimize in case of the hole. | 790 // Deoptimize in case of the hole. |
| 789 Node* branch = graph()->NewNode(common()->Branch(BranchHint::kFalse), | 791 Node* branch = graph()->NewNode(common()->Branch(BranchHint::kFalse), |
| 790 check, this_control); | 792 check, this_control); |
| 791 this_control = graph()->NewNode(common()->IfFalse(), branch); | 793 this_control = graph()->NewNode(common()->IfFalse(), branch); |
| 792 exit_controls.push_back(graph()->NewNode(common()->IfTrue(), branch)); | 794 exit_controls.push_back(graph()->NewNode(common()->IfTrue(), branch)); |
| 793 } | 795 } |
| 794 } | 796 } |
| 795 } else { | 797 } else { |
| 796 DCHECK_EQ(AccessMode::kStore, access_mode); | 798 DCHECK_EQ(AccessMode::kStore, access_mode); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 if (control_count == 0) { | 852 if (control_count == 0) { |
| 851 value = effect = control = jsgraph()->Dead(); | 853 value = effect = control = jsgraph()->Dead(); |
| 852 } else if (control_count == 1) { | 854 } else if (control_count == 1) { |
| 853 value = values.front(); | 855 value = values.front(); |
| 854 effect = effects.front(); | 856 effect = effects.front(); |
| 855 control = controls.front(); | 857 control = controls.front(); |
| 856 } else { | 858 } else { |
| 857 control = graph()->NewNode(common()->Merge(control_count), control_count, | 859 control = graph()->NewNode(common()->Merge(control_count), control_count, |
| 858 &controls.front()); | 860 &controls.front()); |
| 859 values.push_back(control); | 861 values.push_back(control); |
| 860 value = graph()->NewNode(common()->Phi(kMachAnyTagged, control_count), | 862 value = graph()->NewNode( |
| 861 control_count + 1, &values.front()); | 863 common()->Phi(MachineRepresentation::kTagged, control_count), |
| 864 control_count + 1, &values.front()); |
| 862 effects.push_back(control); | 865 effects.push_back(control); |
| 863 effect = graph()->NewNode(common()->EffectPhi(control_count), | 866 effect = graph()->NewNode(common()->EffectPhi(control_count), |
| 864 control_count + 1, &effects.front()); | 867 control_count + 1, &effects.front()); |
| 865 } | 868 } |
| 866 ReplaceWithValue(node, value, effect, control); | 869 ReplaceWithValue(node, value, effect, control); |
| 867 return Replace(value); | 870 return Replace(value); |
| 868 } | 871 } |
| 869 | 872 |
| 870 | 873 |
| 871 Reduction JSNativeContextSpecialization::ReduceKeyedAccess( | 874 Reduction JSNativeContextSpecialization::ReduceKeyedAccess( |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 } | 1020 } |
| 1018 | 1021 |
| 1019 | 1022 |
| 1020 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { | 1023 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { |
| 1021 return jsgraph()->simplified(); | 1024 return jsgraph()->simplified(); |
| 1022 } | 1025 } |
| 1023 | 1026 |
| 1024 } // namespace compiler | 1027 } // namespace compiler |
| 1025 } // namespace internal | 1028 } // namespace internal |
| 1026 } // namespace v8 | 1029 } // namespace v8 |
| OLD | NEW |