| 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/code-factory.h" | 5 #include "src/code-factory.h" |
| 6 #include "src/compiler/access-builder.h" | 6 #include "src/compiler/access-builder.h" |
| 7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
| 8 #include "src/compiler/js-operator.h" | 8 #include "src/compiler/js-operator.h" |
| 9 #include "src/compiler/js-typed-lowering.h" | 9 #include "src/compiler/js-typed-lowering.h" |
| 10 #include "src/compiler/machine-operator.h" | 10 #include "src/compiler/machine-operator.h" |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 | 641 |
| 642 // ----------------------------------------------------------------------------- | 642 // ----------------------------------------------------------------------------- |
| 643 // JSLoadProperty | 643 // JSLoadProperty |
| 644 | 644 |
| 645 | 645 |
| 646 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArray) { | 646 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArray) { |
| 647 const size_t kLength = 17; | 647 const size_t kLength = 17; |
| 648 double backing_store[kLength]; | 648 double backing_store[kLength]; |
| 649 Handle<JSArrayBuffer> buffer = | 649 Handle<JSArrayBuffer> buffer = |
| 650 NewArrayBuffer(backing_store, sizeof(backing_store)); | 650 NewArrayBuffer(backing_store, sizeof(backing_store)); |
| 651 VectorSlotPair feedback(Handle<TypeFeedbackVector>::null(), | 651 ResolvedFeedbackSlot feedback; |
| 652 FeedbackVectorICSlot::Invalid()); | |
| 653 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { | 652 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { |
| 654 Handle<JSTypedArray> array = | 653 Handle<JSTypedArray> array = |
| 655 factory()->NewJSTypedArray(type, buffer, 0, kLength); | 654 factory()->NewJSTypedArray(type, buffer, 0, kLength); |
| 656 int const element_size = static_cast<int>(array->element_size()); | 655 int const element_size = static_cast<int>(array->element_size()); |
| 657 | 656 |
| 658 Node* key = Parameter( | 657 Node* key = Parameter( |
| 659 Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); | 658 Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); |
| 660 Node* base = HeapConstant(array); | 659 Node* base = HeapConstant(array); |
| 660 Node* vector = UndefinedConstant(); |
| 661 Node* context = UndefinedConstant(); | 661 Node* context = UndefinedConstant(); |
| 662 Node* effect = graph()->start(); | 662 Node* effect = graph()->start(); |
| 663 Node* control = graph()->start(); | 663 Node* control = graph()->start(); |
| 664 Reduction r = Reduce(graph()->NewNode(javascript()->LoadProperty(feedback), | 664 Reduction r = Reduce(graph()->NewNode( |
| 665 base, key, context, EmptyFrameState(), | 665 javascript()->LoadProperty(feedback), base, key, vector, context, |
| 666 EmptyFrameState(), effect, control)); | 666 EmptyFrameState(), EmptyFrameState(), effect, control)); |
| 667 | 667 |
| 668 Matcher<Node*> offset_matcher = | 668 Matcher<Node*> offset_matcher = |
| 669 element_size == 1 | 669 element_size == 1 |
| 670 ? key | 670 ? key |
| 671 : IsWord32Shl(key, IsInt32Constant(WhichPowerOf2(element_size))); | 671 : IsWord32Shl(key, IsInt32Constant(WhichPowerOf2(element_size))); |
| 672 | 672 |
| 673 ASSERT_TRUE(r.Changed()); | 673 ASSERT_TRUE(r.Changed()); |
| 674 EXPECT_THAT( | 674 EXPECT_THAT( |
| 675 r.replacement(), | 675 r.replacement(), |
| 676 IsLoadBuffer(BufferAccess(type), | 676 IsLoadBuffer(BufferAccess(type), |
| 677 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), | 677 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), |
| 678 offset_matcher, | 678 offset_matcher, |
| 679 IsNumberConstant(array->byte_length()->Number()), effect, | 679 IsNumberConstant(array->byte_length()->Number()), effect, |
| 680 control)); | 680 control)); |
| 681 } | 681 } |
| 682 } | 682 } |
| 683 | 683 |
| 684 | 684 |
| 685 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArrayWithSafeKey) { | 685 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArrayWithSafeKey) { |
| 686 const size_t kLength = 17; | 686 const size_t kLength = 17; |
| 687 double backing_store[kLength]; | 687 double backing_store[kLength]; |
| 688 Handle<JSArrayBuffer> buffer = | 688 Handle<JSArrayBuffer> buffer = |
| 689 NewArrayBuffer(backing_store, sizeof(backing_store)); | 689 NewArrayBuffer(backing_store, sizeof(backing_store)); |
| 690 VectorSlotPair feedback(Handle<TypeFeedbackVector>::null(), | 690 ResolvedFeedbackSlot feedback; |
| 691 FeedbackVectorICSlot::Invalid()); | |
| 692 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { | 691 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { |
| 693 Handle<JSTypedArray> array = | 692 Handle<JSTypedArray> array = |
| 694 factory()->NewJSTypedArray(type, buffer, 0, kLength); | 693 factory()->NewJSTypedArray(type, buffer, 0, kLength); |
| 695 ElementAccess access = AccessBuilder::ForTypedArrayElement(type, true); | 694 ElementAccess access = AccessBuilder::ForTypedArrayElement(type, true); |
| 696 | 695 |
| 697 int min = random_number_generator()->NextInt(static_cast<int>(kLength)); | 696 int min = random_number_generator()->NextInt(static_cast<int>(kLength)); |
| 698 int max = random_number_generator()->NextInt(static_cast<int>(kLength)); | 697 int max = random_number_generator()->NextInt(static_cast<int>(kLength)); |
| 699 if (min > max) std::swap(min, max); | 698 if (min > max) std::swap(min, max); |
| 700 Node* key = Parameter(Type::Range(min, max, zone())); | 699 Node* key = Parameter(Type::Range(min, max, zone())); |
| 701 Node* base = HeapConstant(array); | 700 Node* base = HeapConstant(array); |
| 701 Node* vector = UndefinedConstant(); |
| 702 Node* context = UndefinedConstant(); | 702 Node* context = UndefinedConstant(); |
| 703 Node* effect = graph()->start(); | 703 Node* effect = graph()->start(); |
| 704 Node* control = graph()->start(); | 704 Node* control = graph()->start(); |
| 705 Reduction r = Reduce(graph()->NewNode(javascript()->LoadProperty(feedback), | 705 Reduction r = Reduce(graph()->NewNode( |
| 706 base, key, context, EmptyFrameState(), | 706 javascript()->LoadProperty(feedback), base, key, vector, context, |
| 707 EmptyFrameState(), effect, control)); | 707 EmptyFrameState(), EmptyFrameState(), effect, control)); |
| 708 | 708 |
| 709 ASSERT_TRUE(r.Changed()); | 709 ASSERT_TRUE(r.Changed()); |
| 710 EXPECT_THAT( | 710 EXPECT_THAT( |
| 711 r.replacement(), | 711 r.replacement(), |
| 712 IsLoadElement(access, | 712 IsLoadElement(access, |
| 713 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), | 713 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), |
| 714 key, effect, control)); | 714 key, effect, control)); |
| 715 } | 715 } |
| 716 } | 716 } |
| 717 | 717 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 Handle<String>(isolate()->heap()->infinity_string(), isolate()), | 871 Handle<String>(isolate()->heap()->infinity_string(), isolate()), |
| 872 Handle<String>(isolate()->heap()->nan_string(), isolate()) // -- | 872 Handle<String>(isolate()->heap()->nan_string(), isolate()) // -- |
| 873 }; | 873 }; |
| 874 Matcher<Node*> matches[] = { | 874 Matcher<Node*> matches[] = { |
| 875 IsHeapConstant(Unique<HeapObject>::CreateImmovable( | 875 IsHeapConstant(Unique<HeapObject>::CreateImmovable( |
| 876 Handle<HeapObject>(isolate()->heap()->undefined_value(), isolate()))), | 876 Handle<HeapObject>(isolate()->heap()->undefined_value(), isolate()))), |
| 877 IsNumberConstant(std::numeric_limits<double>::infinity()), | 877 IsNumberConstant(std::numeric_limits<double>::infinity()), |
| 878 IsNumberConstant(IsNaN()) // -- | 878 IsNumberConstant(IsNaN()) // -- |
| 879 }; | 879 }; |
| 880 | 880 |
| 881 VectorSlotPair feedback(Handle<TypeFeedbackVector>::null(), | 881 ResolvedFeedbackSlot feedback; |
| 882 FeedbackVectorICSlot::Invalid()); | |
| 883 Node* global = Parameter(Type::GlobalObject()); | 882 Node* global = Parameter(Type::GlobalObject()); |
| 883 Node* vector = UndefinedConstant(); |
| 884 Node* context = UndefinedConstant(); | 884 Node* context = UndefinedConstant(); |
| 885 Node* effect = graph()->start(); | 885 Node* effect = graph()->start(); |
| 886 Node* control = graph()->start(); | 886 Node* control = graph()->start(); |
| 887 | 887 |
| 888 for (size_t i = 0; i < arraysize(names); i++) { | 888 for (size_t i = 0; i < arraysize(names); i++) { |
| 889 Unique<Name> name = Unique<Name>::CreateImmovable(names[i]); | 889 Unique<Name> name = Unique<Name>::CreateImmovable(names[i]); |
| 890 Reduction r = Reduce(graph()->NewNode( | 890 Reduction r = Reduce(graph()->NewNode( |
| 891 javascript()->LoadNamed(name, feedback), global, context, | 891 javascript()->LoadNamed(name, feedback), global, vector, context, |
| 892 EmptyFrameState(), EmptyFrameState(), effect, control)); | 892 EmptyFrameState(), EmptyFrameState(), effect, control)); |
| 893 | 893 |
| 894 ASSERT_TRUE(r.Changed()); | 894 ASSERT_TRUE(r.Changed()); |
| 895 EXPECT_THAT(r.replacement(), matches[i]); | 895 EXPECT_THAT(r.replacement(), matches[i]); |
| 896 } | 896 } |
| 897 } | 897 } |
| 898 | 898 |
| 899 | 899 |
| 900 // ----------------------------------------------------------------------------- | 900 // ----------------------------------------------------------------------------- |
| 901 // JSLoadDynamicGlobal | 901 // JSLoadDynamicGlobal |
| 902 | 902 |
| 903 | 903 |
| 904 TEST_F(JSTypedLoweringTest, JSLoadDynamicGlobal) { | 904 TEST_F(JSTypedLoweringTest, JSLoadDynamicGlobal) { |
| 905 Node* const context = Parameter(Type::Any()); | 905 Node* const context = Parameter(Type::Any()); |
| 906 Node* const vector = UndefinedConstant(); |
| 906 Node* const frame_state = EmptyFrameState(); | 907 Node* const frame_state = EmptyFrameState(); |
| 907 Node* const effect = graph()->start(); | 908 Node* const effect = graph()->start(); |
| 908 Node* const control = graph()->start(); | 909 Node* const control = graph()->start(); |
| 909 Handle<String> name = factory()->object_string(); | 910 Handle<String> name = factory()->object_string(); |
| 910 VectorSlotPair feedback(Handle<TypeFeedbackVector>::null(), | 911 ResolvedFeedbackSlot feedback; |
| 911 FeedbackVectorICSlot::Invalid()); | |
| 912 for (int i = 0; i < DynamicGlobalAccess::kMaxCheckDepth; ++i) { | 912 for (int i = 0; i < DynamicGlobalAccess::kMaxCheckDepth; ++i) { |
| 913 uint32_t bitset = 1 << i; // Only single check. | 913 uint32_t bitset = 1 << i; // Only single check. |
| 914 Reduction r = Reduce(graph()->NewNode( | 914 Reduction r = Reduce(graph()->NewNode( |
| 915 javascript()->LoadDynamicGlobal(name, bitset, feedback, NOT_CONTEXTUAL), | 915 javascript()->LoadDynamicGlobal(name, bitset, feedback, NOT_CONTEXTUAL), |
| 916 context, context, frame_state, frame_state, effect, control)); | 916 vector, context, context, frame_state, frame_state, effect, control)); |
| 917 ASSERT_TRUE(r.Changed()); | 917 ASSERT_TRUE(r.Changed()); |
| 918 EXPECT_THAT( | 918 EXPECT_THAT( |
| 919 r.replacement(), | 919 r.replacement(), |
| 920 IsPhi(kMachAnyTagged, _, _, | 920 IsPhi(kMachAnyTagged, _, _, |
| 921 IsMerge( | 921 IsMerge( |
| 922 IsIfTrue(IsBranch( | 922 IsIfTrue(IsBranch( |
| 923 IsReferenceEqual( | 923 IsReferenceEqual( |
| 924 Type::Tagged(), | 924 Type::Tagged(), |
| 925 IsLoadContext( | 925 IsLoadContext( |
| 926 ContextAccess(i, Context::EXTENSION_INDEX, false), | 926 ContextAccess(i, Context::EXTENSION_INDEX, false), |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 EXPECT_THAT(r.replacement(), | 1087 EXPECT_THAT(r.replacement(), |
| 1088 IsFinish(IsAllocate(IsNumberConstant(Context::SizeFor( | 1088 IsFinish(IsAllocate(IsNumberConstant(Context::SizeFor( |
| 1089 Context::MIN_CONTEXT_SLOTS)), | 1089 Context::MIN_CONTEXT_SLOTS)), |
| 1090 effect, control), | 1090 effect, control), |
| 1091 _)); | 1091 _)); |
| 1092 } | 1092 } |
| 1093 | 1093 |
| 1094 } // namespace compiler | 1094 } // namespace compiler |
| 1095 } // namespace internal | 1095 } // namespace internal |
| 1096 } // namespace v8 | 1096 } // namespace v8 |
| OLD | NEW |