| 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-inl.h" | 10 #include "src/compiler/node-properties-inl.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 IsBooleanNot(IsNumberEqual(p0, IsNumberConstant(0))), p1, control)); | 107 IsBooleanNot(IsNumberEqual(p0, IsNumberConstant(0))), p1, control)); |
| 108 } | 108 } |
| 109 | 109 |
| 110 | 110 |
| 111 // ----------------------------------------------------------------------------- | 111 // ----------------------------------------------------------------------------- |
| 112 // JSLoadProperty | 112 // JSLoadProperty |
| 113 | 113 |
| 114 | 114 |
| 115 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArray) { | 115 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArray) { |
| 116 const size_t kLength = 17; | 116 const size_t kLength = 17; |
| 117 uint8_t backing_store[kLength * 8]; | 117 double backing_store[kLength]; |
| 118 Handle<JSArrayBuffer> buffer = | 118 Handle<JSArrayBuffer> buffer = |
| 119 NewArrayBuffer(backing_store, arraysize(backing_store)); | 119 NewArrayBuffer(backing_store, sizeof(backing_store)); |
| 120 VectorSlotPair feedback(Handle<TypeFeedbackVector>::null(), | 120 VectorSlotPair feedback(Handle<TypeFeedbackVector>::null(), |
| 121 FeedbackVectorICSlot::Invalid()); | 121 FeedbackVectorICSlot::Invalid()); |
| 122 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { | 122 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { |
| 123 Handle<JSTypedArray> array = | 123 Handle<JSTypedArray> array = |
| 124 factory()->NewJSTypedArray(type, buffer, 0, kLength); | 124 factory()->NewJSTypedArray(type, buffer, 0, kLength); |
| 125 | 125 |
| 126 Node* key = Parameter(Type::Integral32()); | 126 Node* key = Parameter(Type::Integral32()); |
| 127 Node* base = HeapConstant(array); | 127 Node* base = HeapConstant(array); |
| 128 Node* context = UndefinedConstant(); | 128 Node* context = UndefinedConstant(); |
| 129 Node* effect = graph()->start(); | 129 Node* effect = graph()->start(); |
| 130 Node* control = graph()->start(); | 130 Node* control = graph()->start(); |
| 131 Node* node = graph()->NewNode(javascript()->LoadProperty(feedback), base, | 131 Node* node = graph()->NewNode(javascript()->LoadProperty(feedback), base, |
| 132 key, context); | 132 key, context); |
| 133 if (FLAG_turbo_deoptimization) { | 133 if (FLAG_turbo_deoptimization) { |
| 134 node->AppendInput(zone(), UndefinedConstant()); | 134 node->AppendInput(zone(), UndefinedConstant()); |
| 135 } | 135 } |
| 136 node->AppendInput(zone(), effect); | 136 node->AppendInput(zone(), effect); |
| 137 node->AppendInput(zone(), control); | 137 node->AppendInput(zone(), control); |
| 138 Reduction r = Reduce(node); | 138 Reduction r = Reduce(node); |
| 139 | 139 |
| 140 ASSERT_TRUE(r.Changed()); | 140 ASSERT_TRUE(r.Changed()); |
| 141 EXPECT_THAT( | 141 EXPECT_THAT(r.replacement(), |
| 142 r.replacement(), | 142 IsLoadElement( |
| 143 IsLoadElement(AccessBuilder::ForTypedArrayElement(type, true), | 143 AccessBuilder::ForTypedArrayElement(type, true), |
| 144 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), | 144 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), |
| 145 key, IsNumberConstant(static_cast<double>(kLength)), | 145 key, IsNumberConstant(array->length()->Number()), effect)); |
| 146 effect)); | |
| 147 } | 146 } |
| 148 } | 147 } |
| 149 | 148 |
| 150 | 149 |
| 151 // ----------------------------------------------------------------------------- | 150 // ----------------------------------------------------------------------------- |
| 152 // JSStoreProperty | 151 // JSStoreProperty |
| 153 | 152 |
| 154 | 153 |
| 155 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArray) { | 154 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArray) { |
| 156 const size_t kLength = 17; | 155 const size_t kLength = 17; |
| 157 uint8_t backing_store[kLength * 8]; | 156 double backing_store[kLength]; |
| 158 Handle<JSArrayBuffer> buffer = | 157 Handle<JSArrayBuffer> buffer = |
| 159 NewArrayBuffer(backing_store, arraysize(backing_store)); | 158 NewArrayBuffer(backing_store, sizeof(backing_store)); |
| 160 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { | 159 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) { |
| 161 TRACED_FOREACH(StrictMode, strict_mode, kStrictModes) { | 160 TRACED_FOREACH(StrictMode, strict_mode, kStrictModes) { |
| 162 Handle<JSTypedArray> array = | 161 Handle<JSTypedArray> array = |
| 163 factory()->NewJSTypedArray(type, buffer, 0, kLength); | 162 factory()->NewJSTypedArray(type, buffer, 0, kLength); |
| 164 | 163 |
| 165 Node* key = Parameter(Type::Integral32()); | 164 Node* key = Parameter(Type::Integral32()); |
| 166 Node* base = HeapConstant(array); | 165 Node* base = HeapConstant(array); |
| 167 Node* value = Parameter(Type::Any()); | 166 Node* value = Parameter(Type::Any()); |
| 168 Node* context = UndefinedConstant(); | 167 Node* context = UndefinedConstant(); |
| 169 Node* effect = graph()->start(); | 168 Node* effect = graph()->start(); |
| 170 Node* control = graph()->start(); | 169 Node* control = graph()->start(); |
| 171 Node* node = graph()->NewNode(javascript()->StoreProperty(strict_mode), | 170 Node* node = graph()->NewNode(javascript()->StoreProperty(strict_mode), |
| 172 base, key, value, context); | 171 base, key, value, context); |
| 173 if (FLAG_turbo_deoptimization) { | 172 if (FLAG_turbo_deoptimization) { |
| 174 node->AppendInput(zone(), UndefinedConstant()); | 173 node->AppendInput(zone(), UndefinedConstant()); |
| 175 } | 174 } |
| 176 node->AppendInput(zone(), effect); | 175 node->AppendInput(zone(), effect); |
| 177 node->AppendInput(zone(), control); | 176 node->AppendInput(zone(), control); |
| 178 Reduction r = Reduce(node); | 177 Reduction r = Reduce(node); |
| 179 | 178 |
| 180 ASSERT_TRUE(r.Changed()); | 179 ASSERT_TRUE(r.Changed()); |
| 181 EXPECT_THAT(r.replacement(), | 180 EXPECT_THAT(r.replacement(), |
| 182 IsStoreElement( | 181 IsStoreElement( |
| 183 AccessBuilder::ForTypedArrayElement(type, true), | 182 AccessBuilder::ForTypedArrayElement(type, true), |
| 184 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), | 183 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), |
| 185 key, IsNumberConstant(static_cast<double>(kLength)), | 184 key, IsNumberConstant(array->length()->Number()), value, |
| 186 value, effect, control)); | 185 effect, control)); |
| 187 } | 186 } |
| 188 } | 187 } |
| 189 } | 188 } |
| 190 | 189 |
| 191 } // namespace compiler | 190 } // namespace compiler |
| 192 } // namespace internal | 191 } // namespace internal |
| 193 } // namespace v8 | 192 } // namespace v8 |
| OLD | NEW |