Chromium Code Reviews| 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()); | 691 |
|
Michael Starzinger
2015/06/09 13:23:30
nit: Drop the empty newline for consistency.
mvstanton
2015/06/09 15:21:27
Done.
| |
| 692 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { | 692 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { |
| 693 Handle<JSTypedArray> array = | 693 Handle<JSTypedArray> array = |
| 694 factory()->NewJSTypedArray(type, buffer, 0, kLength); | 694 factory()->NewJSTypedArray(type, buffer, 0, kLength); |
| 695 ElementAccess access = AccessBuilder::ForTypedArrayElement(type, true); | 695 ElementAccess access = AccessBuilder::ForTypedArrayElement(type, true); |
| 696 | 696 |
| 697 int min = random_number_generator()->NextInt(static_cast<int>(kLength)); | 697 int min = random_number_generator()->NextInt(static_cast<int>(kLength)); |
| 698 int max = random_number_generator()->NextInt(static_cast<int>(kLength)); | 698 int max = random_number_generator()->NextInt(static_cast<int>(kLength)); |
| 699 if (min > max) std::swap(min, max); | 699 if (min > max) std::swap(min, max); |
| 700 Node* key = Parameter(Type::Range(min, max, zone())); | 700 Node* key = Parameter(Type::Range(min, max, zone())); |
| 701 Node* base = HeapConstant(array); | 701 Node* base = HeapConstant(array); |
| 702 Node* vector = UndefinedConstant(); | |
| 702 Node* context = UndefinedConstant(); | 703 Node* context = UndefinedConstant(); |
| 703 Node* effect = graph()->start(); | 704 Node* effect = graph()->start(); |
| 704 Node* control = graph()->start(); | 705 Node* control = graph()->start(); |
| 705 Reduction r = Reduce(graph()->NewNode(javascript()->LoadProperty(feedback), | 706 Reduction r = Reduce(graph()->NewNode( |
| 706 base, key, context, EmptyFrameState(), | 707 javascript()->LoadProperty(feedback), base, key, vector, context, |
| 707 EmptyFrameState(), effect, control)); | 708 EmptyFrameState(), EmptyFrameState(), effect, control)); |
| 708 | 709 |
| 709 ASSERT_TRUE(r.Changed()); | 710 ASSERT_TRUE(r.Changed()); |
| 710 EXPECT_THAT( | 711 EXPECT_THAT( |
| 711 r.replacement(), | 712 r.replacement(), |
| 712 IsLoadElement(access, | 713 IsLoadElement(access, |
| 713 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), | 714 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), |
| 714 key, effect, control)); | 715 key, effect, control)); |
| 715 } | 716 } |
| 716 } | 717 } |
| 717 | 718 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 871 Handle<String>(isolate()->heap()->infinity_string(), isolate()), | 872 Handle<String>(isolate()->heap()->infinity_string(), isolate()), |
| 872 Handle<String>(isolate()->heap()->nan_string(), isolate()) // -- | 873 Handle<String>(isolate()->heap()->nan_string(), isolate()) // -- |
| 873 }; | 874 }; |
| 874 Matcher<Node*> matches[] = { | 875 Matcher<Node*> matches[] = { |
| 875 IsHeapConstant(Unique<HeapObject>::CreateImmovable( | 876 IsHeapConstant(Unique<HeapObject>::CreateImmovable( |
| 876 Handle<HeapObject>(isolate()->heap()->undefined_value(), isolate()))), | 877 Handle<HeapObject>(isolate()->heap()->undefined_value(), isolate()))), |
| 877 IsNumberConstant(std::numeric_limits<double>::infinity()), | 878 IsNumberConstant(std::numeric_limits<double>::infinity()), |
| 878 IsNumberConstant(IsNaN()) // -- | 879 IsNumberConstant(IsNaN()) // -- |
| 879 }; | 880 }; |
| 880 | 881 |
| 881 VectorSlotPair feedback(Handle<TypeFeedbackVector>::null(), | 882 ResolvedFeedbackSlot feedback; |
| 882 FeedbackVectorICSlot::Invalid()); | |
| 883 Node* global = Parameter(Type::GlobalObject()); | 883 Node* global = Parameter(Type::GlobalObject()); |
| 884 Node* vector = UndefinedConstant(); | |
| 884 Node* context = UndefinedConstant(); | 885 Node* context = UndefinedConstant(); |
| 885 Node* effect = graph()->start(); | 886 Node* effect = graph()->start(); |
| 886 Node* control = graph()->start(); | 887 Node* control = graph()->start(); |
| 887 | 888 |
| 888 for (size_t i = 0; i < arraysize(names); i++) { | 889 for (size_t i = 0; i < arraysize(names); i++) { |
| 889 Unique<Name> name = Unique<Name>::CreateImmovable(names[i]); | 890 Unique<Name> name = Unique<Name>::CreateImmovable(names[i]); |
| 890 Reduction r = Reduce(graph()->NewNode( | 891 Reduction r = Reduce(graph()->NewNode( |
| 891 javascript()->LoadNamed(name, feedback), global, context, | 892 javascript()->LoadNamed(name, feedback), global, vector, context, |
| 892 EmptyFrameState(), EmptyFrameState(), effect, control)); | 893 EmptyFrameState(), EmptyFrameState(), effect, control)); |
| 893 | 894 |
| 894 ASSERT_TRUE(r.Changed()); | 895 ASSERT_TRUE(r.Changed()); |
| 895 EXPECT_THAT(r.replacement(), matches[i]); | 896 EXPECT_THAT(r.replacement(), matches[i]); |
| 896 } | 897 } |
| 897 } | 898 } |
| 898 | 899 |
| 899 | 900 |
| 900 // ----------------------------------------------------------------------------- | 901 // ----------------------------------------------------------------------------- |
| 901 // JSLoadDynamicGlobal | 902 // JSLoadDynamicGlobal |
| 902 | 903 |
| 903 | 904 |
| 904 TEST_F(JSTypedLoweringTest, JSLoadDynamicGlobal) { | 905 TEST_F(JSTypedLoweringTest, JSLoadDynamicGlobal) { |
| 905 Node* const context = Parameter(Type::Any()); | 906 Node* const context = Parameter(Type::Any()); |
| 907 Node* const vector = UndefinedConstant(); | |
| 906 Node* const frame_state = EmptyFrameState(); | 908 Node* const frame_state = EmptyFrameState(); |
| 907 Node* const effect = graph()->start(); | 909 Node* const effect = graph()->start(); |
| 908 Node* const control = graph()->start(); | 910 Node* const control = graph()->start(); |
| 909 Handle<String> name = factory()->object_string(); | 911 Handle<String> name = factory()->object_string(); |
| 910 VectorSlotPair feedback(Handle<TypeFeedbackVector>::null(), | 912 ResolvedFeedbackSlot feedback; |
| 911 FeedbackVectorICSlot::Invalid()); | |
| 912 for (int i = 0; i < DynamicGlobalAccess::kMaxCheckDepth; ++i) { | 913 for (int i = 0; i < DynamicGlobalAccess::kMaxCheckDepth; ++i) { |
| 913 uint32_t bitset = 1 << i; // Only single check. | 914 uint32_t bitset = 1 << i; // Only single check. |
| 914 Reduction r = Reduce(graph()->NewNode( | 915 Reduction r = Reduce(graph()->NewNode( |
| 915 javascript()->LoadDynamicGlobal(name, bitset, feedback, NOT_CONTEXTUAL), | 916 javascript()->LoadDynamicGlobal(name, bitset, feedback, NOT_CONTEXTUAL), |
| 916 context, context, frame_state, frame_state, effect, control)); | 917 vector, context, context, frame_state, frame_state, effect, control)); |
| 917 ASSERT_TRUE(r.Changed()); | 918 ASSERT_TRUE(r.Changed()); |
| 918 EXPECT_THAT( | 919 EXPECT_THAT( |
| 919 r.replacement(), | 920 r.replacement(), |
| 920 IsPhi(kMachAnyTagged, _, _, | 921 IsPhi(kMachAnyTagged, _, _, |
| 921 IsMerge( | 922 IsMerge( |
| 922 IsIfTrue(IsBranch( | 923 IsIfTrue(IsBranch( |
| 923 IsReferenceEqual( | 924 IsReferenceEqual( |
| 924 Type::Tagged(), | 925 Type::Tagged(), |
| 925 IsLoadContext( | 926 IsLoadContext( |
| 926 ContextAccess(i, Context::EXTENSION_INDEX, false), | 927 ContextAccess(i, Context::EXTENSION_INDEX, false), |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1087 EXPECT_THAT(r.replacement(), | 1088 EXPECT_THAT(r.replacement(), |
| 1088 IsFinish(IsAllocate(IsNumberConstant(Context::SizeFor( | 1089 IsFinish(IsAllocate(IsNumberConstant(Context::SizeFor( |
| 1089 Context::MIN_CONTEXT_SLOTS)), | 1090 Context::MIN_CONTEXT_SLOTS)), |
| 1090 effect, control), | 1091 effect, control), |
| 1091 _)); | 1092 _)); |
| 1092 } | 1093 } |
| 1093 | 1094 |
| 1094 } // namespace compiler | 1095 } // namespace compiler |
| 1095 } // namespace internal | 1096 } // namespace internal |
| 1096 } // namespace v8 | 1097 } // namespace v8 |
| OLD | NEW |