| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 -1.0, 0.0, 1.0, 42.0, | 60 -1.0, 0.0, 1.0, 42.0, |
| 61 1000.0, INT_MAX, UINT_MAX, V8_INFINITY}; | 61 1000.0, INT_MAX, UINT_MAX, V8_INFINITY}; |
| 62 | 62 |
| 63 | 63 |
| 64 Type* const kJSTypes[] = {Type::Undefined(), Type::Null(), Type::Boolean(), | 64 Type* const kJSTypes[] = {Type::Undefined(), Type::Null(), Type::Boolean(), |
| 65 Type::Number(), Type::String(), Type::Object()}; | 65 Type::Number(), Type::String(), Type::Object()}; |
| 66 | 66 |
| 67 | 67 |
| 68 STATIC_ASSERT(LANGUAGE_END == 3); | 68 STATIC_ASSERT(LANGUAGE_END == 3); |
| 69 const LanguageMode kLanguageModes[] = {SLOPPY, STRICT, STRONG}; | 69 const LanguageMode kLanguageModes[] = {SLOPPY, STRICT, STRONG}; |
| 70 const LanguageMode kLanguageModesForStrength[] = {SLOPPY, STRONG}; |
| 70 | 71 |
| 71 } // namespace | 72 } // namespace |
| 72 | 73 |
| 73 | 74 |
| 74 class JSTypedLoweringTest : public TypedGraphTest { | 75 class JSTypedLoweringTest : public TypedGraphTest { |
| 75 public: | 76 public: |
| 76 JSTypedLoweringTest() : TypedGraphTest(3), javascript_(zone()) {} | 77 JSTypedLoweringTest() : TypedGraphTest(3), javascript_(zone()) {} |
| 77 ~JSTypedLoweringTest() override {} | 78 ~JSTypedLoweringTest() override {} |
| 78 | 79 |
| 79 protected: | 80 protected: |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 | 645 |
| 645 | 646 |
| 646 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArray) { | 647 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArray) { |
| 647 const size_t kLength = 17; | 648 const size_t kLength = 17; |
| 648 double backing_store[kLength]; | 649 double backing_store[kLength]; |
| 649 Handle<JSArrayBuffer> buffer = | 650 Handle<JSArrayBuffer> buffer = |
| 650 NewArrayBuffer(backing_store, sizeof(backing_store)); | 651 NewArrayBuffer(backing_store, sizeof(backing_store)); |
| 651 VectorSlotPair feedback(Handle<TypeFeedbackVector>::null(), | 652 VectorSlotPair feedback(Handle<TypeFeedbackVector>::null(), |
| 652 FeedbackVectorICSlot::Invalid()); | 653 FeedbackVectorICSlot::Invalid()); |
| 653 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { | 654 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { |
| 654 Handle<JSTypedArray> array = | 655 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModesForStrength) { |
| 655 factory()->NewJSTypedArray(type, buffer, 0, kLength); | 656 Handle<JSTypedArray> array = |
| 656 int const element_size = static_cast<int>(array->element_size()); | 657 factory()->NewJSTypedArray(type, buffer, 0, kLength); |
| 658 int const element_size = static_cast<int>(array->element_size()); |
| 657 | 659 |
| 658 Node* key = Parameter( | 660 Node* key = Parameter( |
| 659 Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); | 661 Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); |
| 660 Node* base = HeapConstant(array); | 662 Node* base = HeapConstant(array); |
| 661 Node* context = UndefinedConstant(); | 663 Node* context = UndefinedConstant(); |
| 662 Node* effect = graph()->start(); | 664 Node* effect = graph()->start(); |
| 663 Node* control = graph()->start(); | 665 Node* control = graph()->start(); |
| 664 Reduction r = Reduce(graph()->NewNode(javascript()->LoadProperty(feedback), | 666 Reduction r = Reduce(graph()->NewNode( |
| 665 base, key, context, EmptyFrameState(), | 667 javascript()->LoadProperty(feedback, language_mode), base, key, |
| 666 EmptyFrameState(), effect, control)); | 668 context, EmptyFrameState(), EmptyFrameState(), effect, control)); |
| 667 | 669 |
| 668 Matcher<Node*> offset_matcher = | 670 Matcher<Node*> offset_matcher = |
| 669 element_size == 1 | 671 element_size == 1 |
| 670 ? key | 672 ? key |
| 671 : IsWord32Shl(key, IsInt32Constant(WhichPowerOf2(element_size))); | 673 : IsWord32Shl(key, IsInt32Constant(WhichPowerOf2(element_size))); |
| 672 | 674 |
| 673 ASSERT_TRUE(r.Changed()); | 675 ASSERT_TRUE(r.Changed()); |
| 674 EXPECT_THAT( | 676 EXPECT_THAT( |
| 675 r.replacement(), | 677 r.replacement(), |
| 676 IsLoadBuffer(BufferAccess(type), | 678 IsLoadBuffer(BufferAccess(type), |
| 677 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), | 679 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), |
| 678 offset_matcher, | 680 offset_matcher, |
| 679 IsNumberConstant(array->byte_length()->Number()), effect, | 681 IsNumberConstant(array->byte_length()->Number()), effect, |
| 680 control)); | 682 control)); |
| 683 } |
| 681 } | 684 } |
| 682 } | 685 } |
| 683 | 686 |
| 684 | 687 |
| 685 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArrayWithSafeKey) { | 688 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArrayWithSafeKey) { |
| 686 const size_t kLength = 17; | 689 const size_t kLength = 17; |
| 687 double backing_store[kLength]; | 690 double backing_store[kLength]; |
| 688 Handle<JSArrayBuffer> buffer = | 691 Handle<JSArrayBuffer> buffer = |
| 689 NewArrayBuffer(backing_store, sizeof(backing_store)); | 692 NewArrayBuffer(backing_store, sizeof(backing_store)); |
| 690 VectorSlotPair feedback(Handle<TypeFeedbackVector>::null(), | 693 VectorSlotPair feedback(Handle<TypeFeedbackVector>::null(), |
| 691 FeedbackVectorICSlot::Invalid()); | 694 FeedbackVectorICSlot::Invalid()); |
| 692 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { | 695 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { |
| 693 Handle<JSTypedArray> array = | 696 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModesForStrength) { |
| 694 factory()->NewJSTypedArray(type, buffer, 0, kLength); | 697 Handle<JSTypedArray> array = |
| 695 ElementAccess access = AccessBuilder::ForTypedArrayElement(type, true); | 698 factory()->NewJSTypedArray(type, buffer, 0, kLength); |
| 699 ElementAccess access = AccessBuilder::ForTypedArrayElement(type, true); |
| 696 | 700 |
| 697 int min = random_number_generator()->NextInt(static_cast<int>(kLength)); | 701 int min = random_number_generator()->NextInt(static_cast<int>(kLength)); |
| 698 int max = random_number_generator()->NextInt(static_cast<int>(kLength)); | 702 int max = random_number_generator()->NextInt(static_cast<int>(kLength)); |
| 699 if (min > max) std::swap(min, max); | 703 if (min > max) std::swap(min, max); |
| 700 Node* key = Parameter(Type::Range(min, max, zone())); | 704 Node* key = Parameter(Type::Range(min, max, zone())); |
| 701 Node* base = HeapConstant(array); | 705 Node* base = HeapConstant(array); |
| 702 Node* context = UndefinedConstant(); | 706 Node* context = UndefinedConstant(); |
| 703 Node* effect = graph()->start(); | 707 Node* effect = graph()->start(); |
| 704 Node* control = graph()->start(); | 708 Node* control = graph()->start(); |
| 705 Reduction r = Reduce(graph()->NewNode(javascript()->LoadProperty(feedback), | 709 Reduction r = Reduce(graph()->NewNode( |
| 706 base, key, context, EmptyFrameState(), | 710 javascript()->LoadProperty(feedback, language_mode), base, key, |
| 707 EmptyFrameState(), effect, control)); | 711 context, EmptyFrameState(), EmptyFrameState(), effect, control)); |
| 708 | 712 |
| 709 ASSERT_TRUE(r.Changed()); | 713 ASSERT_TRUE(r.Changed()); |
| 710 EXPECT_THAT( | 714 EXPECT_THAT( |
| 711 r.replacement(), | 715 r.replacement(), |
| 712 IsLoadElement(access, | 716 IsLoadElement(access, |
| 713 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), | 717 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), |
| 714 key, effect, control)); | 718 key, effect, control)); |
| 719 } |
| 715 } | 720 } |
| 716 } | 721 } |
| 717 | 722 |
| 718 | 723 |
| 719 // ----------------------------------------------------------------------------- | 724 // ----------------------------------------------------------------------------- |
| 720 // JSStoreProperty | 725 // JSStoreProperty |
| 721 | 726 |
| 722 | 727 |
| 723 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArray) { | 728 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArray) { |
| 724 const size_t kLength = 17; | 729 const size_t kLength = 17; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 IsNumberConstant(IsNaN()) // -- | 883 IsNumberConstant(IsNaN()) // -- |
| 879 }; | 884 }; |
| 880 | 885 |
| 881 VectorSlotPair feedback(Handle<TypeFeedbackVector>::null(), | 886 VectorSlotPair feedback(Handle<TypeFeedbackVector>::null(), |
| 882 FeedbackVectorICSlot::Invalid()); | 887 FeedbackVectorICSlot::Invalid()); |
| 883 Node* global = Parameter(Type::GlobalObject()); | 888 Node* global = Parameter(Type::GlobalObject()); |
| 884 Node* context = UndefinedConstant(); | 889 Node* context = UndefinedConstant(); |
| 885 Node* effect = graph()->start(); | 890 Node* effect = graph()->start(); |
| 886 Node* control = graph()->start(); | 891 Node* control = graph()->start(); |
| 887 | 892 |
| 888 for (size_t i = 0; i < arraysize(names); i++) { | 893 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModesForStrength) { |
| 889 Unique<Name> name = Unique<Name>::CreateImmovable(names[i]); | 894 for (size_t i = 0; i < arraysize(names); i++) { |
| 890 Reduction r = Reduce(graph()->NewNode( | 895 Unique<Name> name = Unique<Name>::CreateImmovable(names[i]); |
| 891 javascript()->LoadNamed(name, feedback), global, context, | 896 Reduction r = Reduce(graph()->NewNode( |
| 892 EmptyFrameState(), EmptyFrameState(), effect, control)); | 897 javascript()->LoadNamed(name, feedback, language_mode), global, |
| 898 context, EmptyFrameState(), EmptyFrameState(), effect, control)); |
| 893 | 899 |
| 894 ASSERT_TRUE(r.Changed()); | 900 ASSERT_TRUE(r.Changed()); |
| 895 EXPECT_THAT(r.replacement(), matches[i]); | 901 EXPECT_THAT(r.replacement(), matches[i]); |
| 902 } |
| 896 } | 903 } |
| 897 } | 904 } |
| 898 | 905 |
| 899 | 906 |
| 900 // ----------------------------------------------------------------------------- | 907 // ----------------------------------------------------------------------------- |
| 901 // JSLoadDynamicGlobal | 908 // JSLoadDynamicGlobal |
| 902 | 909 |
| 903 | 910 |
| 904 TEST_F(JSTypedLoweringTest, JSLoadDynamicGlobal) { | 911 TEST_F(JSTypedLoweringTest, JSLoadDynamicGlobal) { |
| 905 Node* const context = Parameter(Type::Any()); | 912 Node* const context = Parameter(Type::Any()); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 EXPECT_THAT(r.replacement(), | 1094 EXPECT_THAT(r.replacement(), |
| 1088 IsFinish(IsAllocate(IsNumberConstant(Context::SizeFor( | 1095 IsFinish(IsAllocate(IsNumberConstant(Context::SizeFor( |
| 1089 Context::MIN_CONTEXT_SLOTS)), | 1096 Context::MIN_CONTEXT_SLOTS)), |
| 1090 effect, control), | 1097 effect, control), |
| 1091 _)); | 1098 _)); |
| 1092 } | 1099 } |
| 1093 | 1100 |
| 1094 } // namespace compiler | 1101 } // namespace compiler |
| 1095 } // namespace internal | 1102 } // namespace internal |
| 1096 } // namespace v8 | 1103 } // namespace v8 |
| OLD | NEW |