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 VectorSlotPair feedback; | 651 VectorSlotPair 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 VectorSlotPair feedback; | 693 VectorSlotPair 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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 EXPECT_THAT(r.replacement(), | 1099 EXPECT_THAT(r.replacement(), |
1094 IsFinish(IsAllocate(IsNumberConstant(Context::SizeFor( | 1100 IsFinish(IsAllocate(IsNumberConstant(Context::SizeFor( |
1095 Context::MIN_CONTEXT_SLOTS)), | 1101 Context::MIN_CONTEXT_SLOTS)), |
1096 effect, control), | 1102 effect, control), |
1097 _)); | 1103 _)); |
1098 } | 1104 } |
1099 | 1105 |
1100 } // namespace compiler | 1106 } // namespace compiler |
1101 } // namespace internal | 1107 } // namespace internal |
1102 } // namespace v8 | 1108 } // namespace v8 |
OLD | NEW |