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 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 ResolvedFeedbackSlot feedback; | 651 ResolvedFeedbackSlot feedback; |
652 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { | 652 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { |
653 Handle<JSTypedArray> array = | 653 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
654 factory()->NewJSTypedArray(type, buffer, 0, kLength); | 654 Handle<JSTypedArray> array = |
655 int const element_size = static_cast<int>(array->element_size()); | 655 factory()->NewJSTypedArray(type, buffer, 0, kLength); |
| 656 int const element_size = static_cast<int>(array->element_size()); |
656 | 657 |
657 Node* key = Parameter( | 658 Node* key = Parameter( |
658 Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); | 659 Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); |
659 Node* base = HeapConstant(array); | 660 Node* base = HeapConstant(array); |
660 Node* vector = UndefinedConstant(); | 661 Node* vector = UndefinedConstant(); |
661 Node* context = UndefinedConstant(); | 662 Node* context = UndefinedConstant(); |
662 Node* effect = graph()->start(); | 663 Node* effect = graph()->start(); |
663 Node* control = graph()->start(); | 664 Node* control = graph()->start(); |
664 Reduction r = Reduce(graph()->NewNode( | 665 Reduction r = Reduce( |
665 javascript()->LoadProperty(feedback), base, key, vector, context, | 666 graph()->NewNode(javascript()->LoadProperty(feedback, language_mode), |
666 EmptyFrameState(), EmptyFrameState(), effect, control)); | 667 base, key, vector, context, EmptyFrameState(), |
| 668 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 ResolvedFeedbackSlot feedback; | 693 ResolvedFeedbackSlot feedback; |
691 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { | 694 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { |
692 Handle<JSTypedArray> array = | 695 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
693 factory()->NewJSTypedArray(type, buffer, 0, kLength); | 696 Handle<JSTypedArray> array = |
694 ElementAccess access = AccessBuilder::ForTypedArrayElement(type, true); | 697 factory()->NewJSTypedArray(type, buffer, 0, kLength); |
| 698 ElementAccess access = AccessBuilder::ForTypedArrayElement(type, true); |
695 | 699 |
696 int min = random_number_generator()->NextInt(static_cast<int>(kLength)); | 700 int min = random_number_generator()->NextInt(static_cast<int>(kLength)); |
697 int max = random_number_generator()->NextInt(static_cast<int>(kLength)); | 701 int max = random_number_generator()->NextInt(static_cast<int>(kLength)); |
698 if (min > max) std::swap(min, max); | 702 if (min > max) std::swap(min, max); |
699 Node* key = Parameter(Type::Range(min, max, zone())); | 703 Node* key = Parameter(Type::Range(min, max, zone())); |
700 Node* base = HeapConstant(array); | 704 Node* base = HeapConstant(array); |
701 Node* vector = UndefinedConstant(); | 705 Node* vector = UndefinedConstant(); |
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( | 709 Reduction r = Reduce( |
706 javascript()->LoadProperty(feedback), base, key, vector, context, | 710 graph()->NewNode(javascript()->LoadProperty(feedback, language_mode), |
707 EmptyFrameState(), EmptyFrameState(), effect, control)); | 711 base, key, vector, context, EmptyFrameState(), |
| 712 EmptyFrameState(), effect, control)); |
708 | 713 |
709 ASSERT_TRUE(r.Changed()); | 714 ASSERT_TRUE(r.Changed()); |
710 EXPECT_THAT( | 715 EXPECT_THAT( |
711 r.replacement(), | 716 r.replacement(), |
712 IsLoadElement(access, | 717 IsLoadElement(access, |
713 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), | 718 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), |
714 key, effect, control)); | 719 key, effect, control)); |
| 720 } |
715 } | 721 } |
716 } | 722 } |
717 | 723 |
718 | 724 |
719 // ----------------------------------------------------------------------------- | 725 // ----------------------------------------------------------------------------- |
720 // JSStoreProperty | 726 // JSStoreProperty |
721 | 727 |
722 | 728 |
723 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArray) { | 729 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArray) { |
724 const size_t kLength = 17; | 730 const size_t kLength = 17; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 IsNumberConstant(IsNaN()) // -- | 884 IsNumberConstant(IsNaN()) // -- |
879 }; | 885 }; |
880 | 886 |
881 ResolvedFeedbackSlot feedback; | 887 ResolvedFeedbackSlot feedback; |
882 Node* global = Parameter(Type::GlobalObject()); | 888 Node* global = Parameter(Type::GlobalObject()); |
883 Node* vector = UndefinedConstant(); | 889 Node* vector = UndefinedConstant(); |
884 Node* context = UndefinedConstant(); | 890 Node* context = UndefinedConstant(); |
885 Node* effect = graph()->start(); | 891 Node* effect = graph()->start(); |
886 Node* control = graph()->start(); | 892 Node* control = graph()->start(); |
887 | 893 |
888 for (size_t i = 0; i < arraysize(names); i++) { | 894 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
889 Unique<Name> name = Unique<Name>::CreateImmovable(names[i]); | 895 for (size_t i = 0; i < arraysize(names); i++) { |
890 Reduction r = Reduce(graph()->NewNode( | 896 Unique<Name> name = Unique<Name>::CreateImmovable(names[i]); |
891 javascript()->LoadNamed(name, feedback), global, vector, context, | 897 Reduction r = Reduce(graph()->NewNode( |
892 EmptyFrameState(), EmptyFrameState(), effect, control)); | 898 javascript()->LoadNamed(name, feedback, language_mode), global, |
| 899 vector, context, EmptyFrameState(), EmptyFrameState(), effect, |
| 900 control)); |
893 | 901 |
894 ASSERT_TRUE(r.Changed()); | 902 ASSERT_TRUE(r.Changed()); |
895 EXPECT_THAT(r.replacement(), matches[i]); | 903 EXPECT_THAT(r.replacement(), matches[i]); |
| 904 } |
896 } | 905 } |
897 } | 906 } |
898 | 907 |
899 | 908 |
900 // ----------------------------------------------------------------------------- | 909 // ----------------------------------------------------------------------------- |
901 // JSLoadDynamicGlobal | 910 // JSLoadDynamicGlobal |
902 | 911 |
903 | 912 |
904 TEST_F(JSTypedLoweringTest, JSLoadDynamicGlobal) { | 913 TEST_F(JSTypedLoweringTest, JSLoadDynamicGlobal) { |
905 Node* const context = Parameter(Type::Any()); | 914 Node* const context = Parameter(Type::Any()); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 EXPECT_THAT(r.replacement(), | 1096 EXPECT_THAT(r.replacement(), |
1088 IsFinish(IsAllocate(IsNumberConstant(Context::SizeFor( | 1097 IsFinish(IsAllocate(IsNumberConstant(Context::SizeFor( |
1089 Context::MIN_CONTEXT_SLOTS)), | 1098 Context::MIN_CONTEXT_SLOTS)), |
1090 effect, control), | 1099 effect, control), |
1091 _)); | 1100 _)); |
1092 } | 1101 } |
1093 | 1102 |
1094 } // namespace compiler | 1103 } // namespace compiler |
1095 } // namespace internal | 1104 } // namespace internal |
1096 } // namespace v8 | 1105 } // namespace v8 |
OLD | NEW |