| 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 STATIC_ASSERT(LANGUAGE_END == 2); |
| 66 const LanguageMode kLanguageModes[] = {SLOPPY, STRICT}; |
| 66 | 67 |
| 67 } // namespace | 68 } // namespace |
| 68 | 69 |
| 69 | 70 |
| 70 class JSTypedLoweringTest : public TypedGraphTest { | 71 class JSTypedLoweringTest : public TypedGraphTest { |
| 71 public: | 72 public: |
| 72 JSTypedLoweringTest() : TypedGraphTest(3), javascript_(zone()) {} | 73 JSTypedLoweringTest() : TypedGraphTest(3), javascript_(zone()) {} |
| 73 ~JSTypedLoweringTest() OVERRIDE {} | 74 ~JSTypedLoweringTest() OVERRIDE {} |
| 74 | 75 |
| 75 protected: | 76 protected: |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 // ----------------------------------------------------------------------------- | 659 // ----------------------------------------------------------------------------- |
| 659 // JSStoreProperty | 660 // JSStoreProperty |
| 660 | 661 |
| 661 | 662 |
| 662 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArray) { | 663 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArray) { |
| 663 const size_t kLength = 17; | 664 const size_t kLength = 17; |
| 664 double backing_store[kLength]; | 665 double backing_store[kLength]; |
| 665 Handle<JSArrayBuffer> buffer = | 666 Handle<JSArrayBuffer> buffer = |
| 666 NewArrayBuffer(backing_store, sizeof(backing_store)); | 667 NewArrayBuffer(backing_store, sizeof(backing_store)); |
| 667 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { | 668 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { |
| 668 TRACED_FOREACH(StrictMode, strict_mode, kStrictModes) { | 669 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
| 669 Handle<JSTypedArray> array = | 670 Handle<JSTypedArray> array = |
| 670 factory()->NewJSTypedArray(type, buffer, 0, kLength); | 671 factory()->NewJSTypedArray(type, buffer, 0, kLength); |
| 671 int const element_size = static_cast<int>(array->element_size()); | 672 int const element_size = static_cast<int>(array->element_size()); |
| 672 | 673 |
| 673 Node* key = Parameter( | 674 Node* key = Parameter( |
| 674 Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); | 675 Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); |
| 675 Node* base = HeapConstant(array); | 676 Node* base = HeapConstant(array); |
| 676 Node* value = | 677 Node* value = |
| 677 Parameter(AccessBuilder::ForTypedArrayElement(type, true).type); | 678 Parameter(AccessBuilder::ForTypedArrayElement(type, true).type); |
| 678 Node* context = UndefinedConstant(); | 679 Node* context = UndefinedConstant(); |
| 679 Node* effect = graph()->start(); | 680 Node* effect = graph()->start(); |
| 680 Node* control = graph()->start(); | 681 Node* control = graph()->start(); |
| 681 Node* node = graph()->NewNode(javascript()->StoreProperty(strict_mode), | 682 Node* node = graph()->NewNode(javascript()->StoreProperty(language_mode), |
| 682 base, key, value, context); | 683 base, key, value, context); |
| 683 if (FLAG_turbo_deoptimization) { | 684 if (FLAG_turbo_deoptimization) { |
| 684 node->AppendInput(zone(), UndefinedConstant()); | 685 node->AppendInput(zone(), UndefinedConstant()); |
| 685 } | 686 } |
| 686 node->AppendInput(zone(), effect); | 687 node->AppendInput(zone(), effect); |
| 687 node->AppendInput(zone(), control); | 688 node->AppendInput(zone(), control); |
| 688 Reduction r = Reduce(node); | 689 Reduction r = Reduce(node); |
| 689 | 690 |
| 690 Matcher<Node*> offset_matcher = | 691 Matcher<Node*> offset_matcher = |
| 691 element_size == 1 | 692 element_size == 1 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 704 } | 705 } |
| 705 } | 706 } |
| 706 | 707 |
| 707 | 708 |
| 708 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArrayWithConversion) { | 709 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArrayWithConversion) { |
| 709 const size_t kLength = 17; | 710 const size_t kLength = 17; |
| 710 double backing_store[kLength]; | 711 double backing_store[kLength]; |
| 711 Handle<JSArrayBuffer> buffer = | 712 Handle<JSArrayBuffer> buffer = |
| 712 NewArrayBuffer(backing_store, sizeof(backing_store)); | 713 NewArrayBuffer(backing_store, sizeof(backing_store)); |
| 713 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { | 714 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { |
| 714 TRACED_FOREACH(StrictMode, strict_mode, kStrictModes) { | 715 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
| 715 Handle<JSTypedArray> array = | 716 Handle<JSTypedArray> array = |
| 716 factory()->NewJSTypedArray(type, buffer, 0, kLength); | 717 factory()->NewJSTypedArray(type, buffer, 0, kLength); |
| 717 int const element_size = static_cast<int>(array->element_size()); | 718 int const element_size = static_cast<int>(array->element_size()); |
| 718 | 719 |
| 719 Node* key = Parameter( | 720 Node* key = Parameter( |
| 720 Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); | 721 Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); |
| 721 Node* base = HeapConstant(array); | 722 Node* base = HeapConstant(array); |
| 722 Node* value = Parameter(Type::Any()); | 723 Node* value = Parameter(Type::Any()); |
| 723 Node* context = UndefinedConstant(); | 724 Node* context = UndefinedConstant(); |
| 724 Node* effect = graph()->start(); | 725 Node* effect = graph()->start(); |
| 725 Node* control = graph()->start(); | 726 Node* control = graph()->start(); |
| 726 Node* node = graph()->NewNode(javascript()->StoreProperty(strict_mode), | 727 Node* node = graph()->NewNode(javascript()->StoreProperty(language_mode), |
| 727 base, key, value, context); | 728 base, key, value, context); |
| 728 if (FLAG_turbo_deoptimization) { | 729 if (FLAG_turbo_deoptimization) { |
| 729 node->AppendInput(zone(), UndefinedConstant()); | 730 node->AppendInput(zone(), UndefinedConstant()); |
| 730 } | 731 } |
| 731 node->AppendInput(zone(), effect); | 732 node->AppendInput(zone(), effect); |
| 732 node->AppendInput(zone(), control); | 733 node->AppendInput(zone(), control); |
| 733 Reduction r = Reduce(node); | 734 Reduction r = Reduce(node); |
| 734 | 735 |
| 735 Matcher<Node*> offset_matcher = | 736 Matcher<Node*> offset_matcher = |
| 736 element_size == 1 | 737 element_size == 1 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 760 } | 761 } |
| 761 } | 762 } |
| 762 | 763 |
| 763 | 764 |
| 764 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArrayWithSafeKey) { | 765 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArrayWithSafeKey) { |
| 765 const size_t kLength = 17; | 766 const size_t kLength = 17; |
| 766 double backing_store[kLength]; | 767 double backing_store[kLength]; |
| 767 Handle<JSArrayBuffer> buffer = | 768 Handle<JSArrayBuffer> buffer = |
| 768 NewArrayBuffer(backing_store, sizeof(backing_store)); | 769 NewArrayBuffer(backing_store, sizeof(backing_store)); |
| 769 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { | 770 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { |
| 770 TRACED_FOREACH(StrictMode, strict_mode, kStrictModes) { | 771 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
| 771 Handle<JSTypedArray> array = | 772 Handle<JSTypedArray> array = |
| 772 factory()->NewJSTypedArray(type, buffer, 0, kLength); | 773 factory()->NewJSTypedArray(type, buffer, 0, kLength); |
| 773 ElementAccess access = AccessBuilder::ForTypedArrayElement(type, true); | 774 ElementAccess access = AccessBuilder::ForTypedArrayElement(type, true); |
| 774 | 775 |
| 775 int min = random_number_generator()->NextInt(static_cast<int>(kLength)); | 776 int min = random_number_generator()->NextInt(static_cast<int>(kLength)); |
| 776 int max = random_number_generator()->NextInt(static_cast<int>(kLength)); | 777 int max = random_number_generator()->NextInt(static_cast<int>(kLength)); |
| 777 if (min > max) std::swap(min, max); | 778 if (min > max) std::swap(min, max); |
| 778 Node* key = Parameter(Type::Range(min, max, zone())); | 779 Node* key = Parameter(Type::Range(min, max, zone())); |
| 779 Node* base = HeapConstant(array); | 780 Node* base = HeapConstant(array); |
| 780 Node* value = Parameter(access.type); | 781 Node* value = Parameter(access.type); |
| 781 Node* context = UndefinedConstant(); | 782 Node* context = UndefinedConstant(); |
| 782 Node* effect = graph()->start(); | 783 Node* effect = graph()->start(); |
| 783 Node* control = graph()->start(); | 784 Node* control = graph()->start(); |
| 784 Node* node = graph()->NewNode(javascript()->StoreProperty(strict_mode), | 785 Node* node = graph()->NewNode(javascript()->StoreProperty(language_mode), |
| 785 base, key, value, context); | 786 base, key, value, context); |
| 786 if (FLAG_turbo_deoptimization) { | 787 if (FLAG_turbo_deoptimization) { |
| 787 node->AppendInput(zone(), UndefinedConstant()); | 788 node->AppendInput(zone(), UndefinedConstant()); |
| 788 } | 789 } |
| 789 node->AppendInput(zone(), effect); | 790 node->AppendInput(zone(), effect); |
| 790 node->AppendInput(zone(), control); | 791 node->AppendInput(zone(), control); |
| 791 Reduction r = Reduce(node); | 792 Reduction r = Reduce(node); |
| 792 | 793 |
| 793 ASSERT_TRUE(r.Changed()); | 794 ASSERT_TRUE(r.Changed()); |
| 794 EXPECT_THAT( | 795 EXPECT_THAT( |
| 795 r.replacement(), | 796 r.replacement(), |
| 796 IsStoreElement( | 797 IsStoreElement( |
| 797 access, IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), | 798 access, IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), |
| 798 key, value, effect, control)); | 799 key, value, effect, control)); |
| 799 } | 800 } |
| 800 } | 801 } |
| 801 } | 802 } |
| 802 | 803 |
| 803 } // namespace compiler | 804 } // namespace compiler |
| 804 } // namespace internal | 805 } // namespace internal |
| 805 } // namespace v8 | 806 } // namespace v8 |
| OLD | NEW |