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/compiler/access-builder.h" | 5 #include "src/compiler/access-builder.h" |
6 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/js-operator.h" | 7 #include "src/compiler/js-operator.h" |
8 #include "src/compiler/js-typed-lowering.h" | 8 #include "src/compiler/js-typed-lowering.h" |
9 #include "src/compiler/machine-operator.h" | 9 #include "src/compiler/machine-operator.h" |
10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 | 55 |
56 const double kIntegerValues[] = {-V8_INFINITY, INT_MIN, -1000.0, -42.0, | 56 const double kIntegerValues[] = {-V8_INFINITY, INT_MIN, -1000.0, -42.0, |
57 -1.0, 0.0, 1.0, 42.0, | 57 -1.0, 0.0, 1.0, 42.0, |
58 1000.0, INT_MAX, UINT_MAX, V8_INFINITY}; | 58 1000.0, INT_MAX, UINT_MAX, V8_INFINITY}; |
59 | 59 |
60 | 60 |
61 Type* const kJSTypes[] = {Type::Undefined(), Type::Null(), Type::Boolean(), | 61 Type* const kJSTypes[] = {Type::Undefined(), Type::Null(), Type::Boolean(), |
62 Type::Number(), Type::String(), Type::Object()}; | 62 Type::Number(), Type::String(), Type::Object()}; |
63 | 63 |
64 | 64 |
65 const StrictMode kStrictModes[] = {SLOPPY, STRICT}; | 65 const LanguageMode kLanguageModes[] = {SLOPPY, STRICT}; |
rossberg
2015/02/03 12:26:20
Maybe add a static assert here as well, so that we
marja
2015/02/03 14:45:02
Done.
| |
66 | 66 |
67 } // namespace | 67 } // namespace |
68 | 68 |
69 | 69 |
70 class JSTypedLoweringTest : public TypedGraphTest { | 70 class JSTypedLoweringTest : public TypedGraphTest { |
71 public: | 71 public: |
72 JSTypedLoweringTest() : TypedGraphTest(3), javascript_(zone()) {} | 72 JSTypedLoweringTest() : TypedGraphTest(3), javascript_(zone()) {} |
73 ~JSTypedLoweringTest() OVERRIDE {} | 73 ~JSTypedLoweringTest() OVERRIDE {} |
74 | 74 |
75 protected: | 75 protected: |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
658 // ----------------------------------------------------------------------------- | 658 // ----------------------------------------------------------------------------- |
659 // JSStoreProperty | 659 // JSStoreProperty |
660 | 660 |
661 | 661 |
662 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArray) { | 662 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArray) { |
663 const size_t kLength = 17; | 663 const size_t kLength = 17; |
664 double backing_store[kLength]; | 664 double backing_store[kLength]; |
665 Handle<JSArrayBuffer> buffer = | 665 Handle<JSArrayBuffer> buffer = |
666 NewArrayBuffer(backing_store, sizeof(backing_store)); | 666 NewArrayBuffer(backing_store, sizeof(backing_store)); |
667 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { | 667 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { |
668 TRACED_FOREACH(StrictMode, strict_mode, kStrictModes) { | 668 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
669 Handle<JSTypedArray> array = | 669 Handle<JSTypedArray> array = |
670 factory()->NewJSTypedArray(type, buffer, 0, kLength); | 670 factory()->NewJSTypedArray(type, buffer, 0, kLength); |
671 int const element_size = static_cast<int>(array->element_size()); | 671 int const element_size = static_cast<int>(array->element_size()); |
672 | 672 |
673 Node* key = Parameter( | 673 Node* key = Parameter( |
674 Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); | 674 Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); |
675 Node* base = HeapConstant(array); | 675 Node* base = HeapConstant(array); |
676 Node* value = | 676 Node* value = |
677 Parameter(AccessBuilder::ForTypedArrayElement(type, true).type); | 677 Parameter(AccessBuilder::ForTypedArrayElement(type, true).type); |
678 Node* context = UndefinedConstant(); | 678 Node* context = UndefinedConstant(); |
679 Node* effect = graph()->start(); | 679 Node* effect = graph()->start(); |
680 Node* control = graph()->start(); | 680 Node* control = graph()->start(); |
681 Node* node = graph()->NewNode(javascript()->StoreProperty(strict_mode), | 681 Node* node = graph()->NewNode(javascript()->StoreProperty(language_mode), |
682 base, key, value, context); | 682 base, key, value, context); |
683 if (FLAG_turbo_deoptimization) { | 683 if (FLAG_turbo_deoptimization) { |
684 node->AppendInput(zone(), UndefinedConstant()); | 684 node->AppendInput(zone(), UndefinedConstant()); |
685 } | 685 } |
686 node->AppendInput(zone(), effect); | 686 node->AppendInput(zone(), effect); |
687 node->AppendInput(zone(), control); | 687 node->AppendInput(zone(), control); |
688 Reduction r = Reduce(node); | 688 Reduction r = Reduce(node); |
689 | 689 |
690 Matcher<Node*> offset_matcher = | 690 Matcher<Node*> offset_matcher = |
691 element_size == 1 | 691 element_size == 1 |
(...skipping 12 matching lines...) Expand all Loading... | |
704 } | 704 } |
705 } | 705 } |
706 | 706 |
707 | 707 |
708 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArrayWithConversion) { | 708 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArrayWithConversion) { |
709 const size_t kLength = 17; | 709 const size_t kLength = 17; |
710 double backing_store[kLength]; | 710 double backing_store[kLength]; |
711 Handle<JSArrayBuffer> buffer = | 711 Handle<JSArrayBuffer> buffer = |
712 NewArrayBuffer(backing_store, sizeof(backing_store)); | 712 NewArrayBuffer(backing_store, sizeof(backing_store)); |
713 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { | 713 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { |
714 TRACED_FOREACH(StrictMode, strict_mode, kStrictModes) { | 714 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
715 Handle<JSTypedArray> array = | 715 Handle<JSTypedArray> array = |
716 factory()->NewJSTypedArray(type, buffer, 0, kLength); | 716 factory()->NewJSTypedArray(type, buffer, 0, kLength); |
717 int const element_size = static_cast<int>(array->element_size()); | 717 int const element_size = static_cast<int>(array->element_size()); |
718 | 718 |
719 Node* key = Parameter( | 719 Node* key = Parameter( |
720 Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); | 720 Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); |
721 Node* base = HeapConstant(array); | 721 Node* base = HeapConstant(array); |
722 Node* value = Parameter(Type::Any()); | 722 Node* value = Parameter(Type::Any()); |
723 Node* context = UndefinedConstant(); | 723 Node* context = UndefinedConstant(); |
724 Node* effect = graph()->start(); | 724 Node* effect = graph()->start(); |
725 Node* control = graph()->start(); | 725 Node* control = graph()->start(); |
726 Node* node = graph()->NewNode(javascript()->StoreProperty(strict_mode), | 726 Node* node = graph()->NewNode(javascript()->StoreProperty(language_mode), |
727 base, key, value, context); | 727 base, key, value, context); |
728 if (FLAG_turbo_deoptimization) { | 728 if (FLAG_turbo_deoptimization) { |
729 node->AppendInput(zone(), UndefinedConstant()); | 729 node->AppendInput(zone(), UndefinedConstant()); |
730 } | 730 } |
731 node->AppendInput(zone(), effect); | 731 node->AppendInput(zone(), effect); |
732 node->AppendInput(zone(), control); | 732 node->AppendInput(zone(), control); |
733 Reduction r = Reduce(node); | 733 Reduction r = Reduce(node); |
734 | 734 |
735 Matcher<Node*> offset_matcher = | 735 Matcher<Node*> offset_matcher = |
736 element_size == 1 | 736 element_size == 1 |
(...skipping 23 matching lines...) Expand all Loading... | |
760 } | 760 } |
761 } | 761 } |
762 | 762 |
763 | 763 |
764 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArrayWithSafeKey) { | 764 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArrayWithSafeKey) { |
765 const size_t kLength = 17; | 765 const size_t kLength = 17; |
766 double backing_store[kLength]; | 766 double backing_store[kLength]; |
767 Handle<JSArrayBuffer> buffer = | 767 Handle<JSArrayBuffer> buffer = |
768 NewArrayBuffer(backing_store, sizeof(backing_store)); | 768 NewArrayBuffer(backing_store, sizeof(backing_store)); |
769 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { | 769 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { |
770 TRACED_FOREACH(StrictMode, strict_mode, kStrictModes) { | 770 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
771 Handle<JSTypedArray> array = | 771 Handle<JSTypedArray> array = |
772 factory()->NewJSTypedArray(type, buffer, 0, kLength); | 772 factory()->NewJSTypedArray(type, buffer, 0, kLength); |
773 ElementAccess access = AccessBuilder::ForTypedArrayElement(type, true); | 773 ElementAccess access = AccessBuilder::ForTypedArrayElement(type, true); |
774 | 774 |
775 int min = random_number_generator()->NextInt(static_cast<int>(kLength)); | 775 int min = random_number_generator()->NextInt(static_cast<int>(kLength)); |
776 int max = random_number_generator()->NextInt(static_cast<int>(kLength)); | 776 int max = random_number_generator()->NextInt(static_cast<int>(kLength)); |
777 if (min > max) std::swap(min, max); | 777 if (min > max) std::swap(min, max); |
778 Node* key = Parameter(Type::Range(min, max, zone())); | 778 Node* key = Parameter(Type::Range(min, max, zone())); |
779 Node* base = HeapConstant(array); | 779 Node* base = HeapConstant(array); |
780 Node* value = Parameter(access.type); | 780 Node* value = Parameter(access.type); |
781 Node* context = UndefinedConstant(); | 781 Node* context = UndefinedConstant(); |
782 Node* effect = graph()->start(); | 782 Node* effect = graph()->start(); |
783 Node* control = graph()->start(); | 783 Node* control = graph()->start(); |
784 Node* node = graph()->NewNode(javascript()->StoreProperty(strict_mode), | 784 Node* node = graph()->NewNode(javascript()->StoreProperty(language_mode), |
785 base, key, value, context); | 785 base, key, value, context); |
786 if (FLAG_turbo_deoptimization) { | 786 if (FLAG_turbo_deoptimization) { |
787 node->AppendInput(zone(), UndefinedConstant()); | 787 node->AppendInput(zone(), UndefinedConstant()); |
788 } | 788 } |
789 node->AppendInput(zone(), effect); | 789 node->AppendInput(zone(), effect); |
790 node->AppendInput(zone(), control); | 790 node->AppendInput(zone(), control); |
791 Reduction r = Reduce(node); | 791 Reduction r = Reduce(node); |
792 | 792 |
793 ASSERT_TRUE(r.Changed()); | 793 ASSERT_TRUE(r.Changed()); |
794 EXPECT_THAT( | 794 EXPECT_THAT( |
795 r.replacement(), | 795 r.replacement(), |
796 IsStoreElement( | 796 IsStoreElement( |
797 access, IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), | 797 access, IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), |
798 key, value, effect, control)); | 798 key, value, effect, control)); |
799 } | 799 } |
800 } | 800 } |
801 } | 801 } |
802 | 802 |
803 } // namespace compiler | 803 } // namespace compiler |
804 } // namespace internal | 804 } // namespace internal |
805 } // namespace v8 | 805 } // namespace v8 |
OLD | NEW |