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 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 // JSLoadProperty | 593 // JSLoadProperty |
594 | 594 |
595 | 595 |
596 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArray) { | 596 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArray) { |
597 const size_t kLength = 17; | 597 const size_t kLength = 17; |
598 double backing_store[kLength]; | 598 double backing_store[kLength]; |
599 Handle<JSArrayBuffer> buffer = | 599 Handle<JSArrayBuffer> buffer = |
600 NewArrayBuffer(backing_store, sizeof(backing_store)); | 600 NewArrayBuffer(backing_store, sizeof(backing_store)); |
601 VectorSlotPair feedback; | 601 VectorSlotPair feedback; |
602 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { | 602 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { |
603 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 603 Handle<JSTypedArray> array = |
604 Handle<JSTypedArray> array = | 604 factory()->NewJSTypedArray(type, buffer, 0, kLength); |
605 factory()->NewJSTypedArray(type, buffer, 0, kLength); | 605 int const element_size = static_cast<int>(array->element_size()); |
606 int const element_size = static_cast<int>(array->element_size()); | |
607 | 606 |
608 Node* key = Parameter( | 607 Node* key = Parameter( |
609 Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); | 608 Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); |
610 Node* base = HeapConstant(array); | 609 Node* base = HeapConstant(array); |
611 Node* vector = UndefinedConstant(); | 610 Node* vector = UndefinedConstant(); |
612 Node* context = UndefinedConstant(); | 611 Node* context = UndefinedConstant(); |
613 Node* effect = graph()->start(); | 612 Node* effect = graph()->start(); |
614 Node* control = graph()->start(); | 613 Node* control = graph()->start(); |
615 Reduction r = Reduce( | 614 Reduction r = Reduce(graph()->NewNode( |
616 graph()->NewNode(javascript()->LoadProperty(language_mode, feedback), | 615 javascript()->LoadProperty(feedback), base, key, vector, context, |
617 base, key, vector, context, EmptyFrameState(), | 616 EmptyFrameState(), EmptyFrameState(), effect, control)); |
618 EmptyFrameState(), effect, control)); | |
619 | 617 |
620 Matcher<Node*> offset_matcher = | 618 Matcher<Node*> offset_matcher = |
621 element_size == 1 | 619 element_size == 1 |
622 ? key | 620 ? key |
623 : IsWord32Shl(key, IsInt32Constant(WhichPowerOf2(element_size))); | 621 : IsWord32Shl(key, IsInt32Constant(WhichPowerOf2(element_size))); |
624 | 622 |
625 ASSERT_TRUE(r.Changed()); | 623 ASSERT_TRUE(r.Changed()); |
626 EXPECT_THAT( | 624 EXPECT_THAT( |
627 r.replacement(), | 625 r.replacement(), |
628 IsLoadBuffer(BufferAccess(type), | 626 IsLoadBuffer(BufferAccess(type), |
629 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), | 627 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), |
630 offset_matcher, | 628 offset_matcher, |
631 IsNumberConstant(array->byte_length()->Number()), effect, | 629 IsNumberConstant(array->byte_length()->Number()), effect, |
632 control)); | 630 control)); |
633 } | |
634 } | 631 } |
635 } | 632 } |
636 | 633 |
637 | 634 |
638 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArrayWithSafeKey) { | 635 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArrayWithSafeKey) { |
639 const size_t kLength = 17; | 636 const size_t kLength = 17; |
640 double backing_store[kLength]; | 637 double backing_store[kLength]; |
641 Handle<JSArrayBuffer> buffer = | 638 Handle<JSArrayBuffer> buffer = |
642 NewArrayBuffer(backing_store, sizeof(backing_store)); | 639 NewArrayBuffer(backing_store, sizeof(backing_store)); |
643 VectorSlotPair feedback; | 640 VectorSlotPair feedback; |
644 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { | 641 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { |
645 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 642 Handle<JSTypedArray> array = |
646 Handle<JSTypedArray> array = | 643 factory()->NewJSTypedArray(type, buffer, 0, kLength); |
647 factory()->NewJSTypedArray(type, buffer, 0, kLength); | 644 ElementAccess access = AccessBuilder::ForTypedArrayElement(type, true); |
648 ElementAccess access = AccessBuilder::ForTypedArrayElement(type, true); | |
649 | 645 |
650 int min = random_number_generator()->NextInt(static_cast<int>(kLength)); | 646 int min = random_number_generator()->NextInt(static_cast<int>(kLength)); |
651 int max = random_number_generator()->NextInt(static_cast<int>(kLength)); | 647 int max = random_number_generator()->NextInt(static_cast<int>(kLength)); |
652 if (min > max) std::swap(min, max); | 648 if (min > max) std::swap(min, max); |
653 Node* key = Parameter(Type::Range(min, max, zone())); | 649 Node* key = Parameter(Type::Range(min, max, zone())); |
654 Node* base = HeapConstant(array); | 650 Node* base = HeapConstant(array); |
655 Node* vector = UndefinedConstant(); | 651 Node* vector = UndefinedConstant(); |
656 Node* context = UndefinedConstant(); | 652 Node* context = UndefinedConstant(); |
657 Node* effect = graph()->start(); | 653 Node* effect = graph()->start(); |
658 Node* control = graph()->start(); | 654 Node* control = graph()->start(); |
659 Reduction r = Reduce( | 655 Reduction r = Reduce(graph()->NewNode( |
660 graph()->NewNode(javascript()->LoadProperty(language_mode, feedback), | 656 javascript()->LoadProperty(feedback), base, key, vector, context, |
661 base, key, vector, context, EmptyFrameState(), | 657 EmptyFrameState(), EmptyFrameState(), effect, control)); |
662 EmptyFrameState(), effect, control)); | |
663 | 658 |
664 ASSERT_TRUE(r.Changed()); | 659 ASSERT_TRUE(r.Changed()); |
665 EXPECT_THAT( | 660 EXPECT_THAT( |
666 r.replacement(), | 661 r.replacement(), |
667 IsLoadElement(access, | 662 IsLoadElement(access, |
668 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), | 663 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), |
669 key, effect, control)); | 664 key, effect, control)); |
670 } | |
671 } | 665 } |
672 } | 666 } |
673 | 667 |
674 | 668 |
675 // ----------------------------------------------------------------------------- | 669 // ----------------------------------------------------------------------------- |
676 // JSStoreProperty | 670 // JSStoreProperty |
677 | 671 |
678 | 672 |
679 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArray) { | 673 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArray) { |
680 const size_t kLength = 17; | 674 const size_t kLength = 17; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 | 807 |
814 | 808 |
815 TEST_F(JSTypedLoweringTest, JSLoadNamedStringLength) { | 809 TEST_F(JSTypedLoweringTest, JSLoadNamedStringLength) { |
816 VectorSlotPair feedback; | 810 VectorSlotPair feedback; |
817 Handle<Name> name = factory()->length_string(); | 811 Handle<Name> name = factory()->length_string(); |
818 Node* const receiver = Parameter(Type::String(), 0); | 812 Node* const receiver = Parameter(Type::String(), 0); |
819 Node* const vector = Parameter(Type::Internal(), 1); | 813 Node* const vector = Parameter(Type::Internal(), 1); |
820 Node* const context = UndefinedConstant(); | 814 Node* const context = UndefinedConstant(); |
821 Node* const effect = graph()->start(); | 815 Node* const effect = graph()->start(); |
822 Node* const control = graph()->start(); | 816 Node* const control = graph()->start(); |
823 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 817 Reduction const r = Reduce(graph()->NewNode( |
824 Reduction const r = Reduce( | 818 javascript()->LoadNamed(name, feedback), receiver, vector, context, |
825 graph()->NewNode(javascript()->LoadNamed(language_mode, name, feedback), | 819 EmptyFrameState(), EmptyFrameState(), effect, control)); |
826 receiver, vector, context, EmptyFrameState(), | 820 ASSERT_TRUE(r.Changed()); |
827 EmptyFrameState(), effect, control)); | 821 EXPECT_THAT(r.replacement(), IsLoadField(AccessBuilder::ForStringLength(), |
828 ASSERT_TRUE(r.Changed()); | 822 receiver, effect, control)); |
829 EXPECT_THAT(r.replacement(), IsLoadField(AccessBuilder::ForStringLength(), | |
830 receiver, effect, control)); | |
831 } | |
832 } | 823 } |
833 | 824 |
834 | 825 |
835 TEST_F(JSTypedLoweringTest, JSLoadNamedFunctionPrototype) { | 826 TEST_F(JSTypedLoweringTest, JSLoadNamedFunctionPrototype) { |
836 VectorSlotPair feedback; | 827 VectorSlotPair feedback; |
837 Handle<Name> name = factory()->prototype_string(); | 828 Handle<Name> name = factory()->prototype_string(); |
838 Handle<JSFunction> function = isolate()->object_function(); | 829 Handle<JSFunction> function = isolate()->object_function(); |
839 Handle<JSObject> function_prototype(JSObject::cast(function->prototype())); | 830 Handle<JSObject> function_prototype(JSObject::cast(function->prototype())); |
840 Node* const receiver = Parameter(Type::Constant(function, zone()), 0); | 831 Node* const receiver = Parameter(Type::Constant(function, zone()), 0); |
841 Node* const vector = Parameter(Type::Internal(), 1); | 832 Node* const vector = Parameter(Type::Internal(), 1); |
842 Node* const context = Parameter(Type::Internal(), 2); | 833 Node* const context = Parameter(Type::Internal(), 2); |
843 Node* const effect = graph()->start(); | 834 Node* const effect = graph()->start(); |
844 Node* const control = graph()->start(); | 835 Node* const control = graph()->start(); |
845 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 836 Reduction const r = Reduce(graph()->NewNode( |
846 Reduction const r = Reduce( | 837 javascript()->LoadNamed(name, feedback), receiver, vector, context, |
847 graph()->NewNode(javascript()->LoadNamed(language_mode, name, feedback), | 838 EmptyFrameState(), EmptyFrameState(), effect, control)); |
848 receiver, vector, context, EmptyFrameState(), | 839 ASSERT_TRUE(r.Changed()); |
849 EmptyFrameState(), effect, control)); | 840 EXPECT_THAT(r.replacement(), IsHeapConstant(function_prototype)); |
850 ASSERT_TRUE(r.Changed()); | |
851 EXPECT_THAT(r.replacement(), IsHeapConstant(function_prototype)); | |
852 } | |
853 } | 841 } |
854 | 842 |
855 | 843 |
856 // ----------------------------------------------------------------------------- | 844 // ----------------------------------------------------------------------------- |
857 // JSAdd | 845 // JSAdd |
858 | 846 |
859 | 847 |
860 TEST_F(JSTypedLoweringTest, JSAddWithString) { | 848 TEST_F(JSTypedLoweringTest, JSAddWithString) { |
861 BinaryOperationHints const hints = BinaryOperationHints::Any(); | 849 BinaryOperationHints const hints = BinaryOperationHints::Any(); |
862 Node* lhs = Parameter(Type::String(), 0); | 850 Node* lhs = Parameter(Type::String(), 0); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, | 925 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, |
938 frame_state, effect, control); | 926 frame_state, effect, control); |
939 Reduction r = Reduce(instanceOf); | 927 Reduction r = Reduce(instanceOf); |
940 ASSERT_FALSE(r.Changed()); | 928 ASSERT_FALSE(r.Changed()); |
941 ASSERT_EQ(instanceOf, dummy->InputAt(0)); | 929 ASSERT_EQ(instanceOf, dummy->InputAt(0)); |
942 } | 930 } |
943 | 931 |
944 } // namespace compiler | 932 } // namespace compiler |
945 } // namespace internal | 933 } // namespace internal |
946 } // namespace v8 | 934 } // namespace v8 |
OLD | NEW |