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" |
11 #include "src/compiler/typer.h" | 11 #include "src/compiler/typer.h" |
12 #include "test/unittests/compiler/compiler-test-utils.h" | 12 #include "test/unittests/compiler/compiler-test-utils.h" |
13 #include "test/unittests/compiler/graph-unittest.h" | 13 #include "test/unittests/compiler/graph-unittest.h" |
14 #include "test/unittests/compiler/node-test-utils.h" | 14 #include "test/unittests/compiler/node-test-utils.h" |
15 | 15 |
16 namespace v8 { | 16 namespace v8 { |
17 namespace internal { | 17 namespace internal { |
18 namespace compiler { | 18 namespace compiler { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 const ExternalArrayType kExternalArrayTypes[] = { | 22 const ExternalArrayType kExternalArrayTypes[] = { |
23 kExternalUint8Array, kExternalInt8Array, kExternalUint16Array, | 23 kExternalUint8Array, kExternalInt8Array, kExternalUint16Array, |
24 kExternalInt16Array, kExternalUint32Array, kExternalInt32Array, | 24 kExternalInt16Array, kExternalUint32Array, kExternalInt32Array, |
25 kExternalFloat32Array, kExternalFloat64Array}; | 25 kExternalFloat32Array, kExternalFloat64Array}; |
26 | 26 |
27 | 27 |
| 28 const size_t kIndices[] = {0, 1, 42, 100, 1024}; |
| 29 |
| 30 |
28 Type* const kJSTypes[] = {Type::Undefined(), Type::Null(), Type::Boolean(), | 31 Type* const kJSTypes[] = {Type::Undefined(), Type::Null(), Type::Boolean(), |
29 Type::Number(), Type::String(), Type::Object()}; | 32 Type::Number(), Type::String(), Type::Object()}; |
30 | 33 |
31 | 34 |
32 const StrictMode kStrictModes[] = {SLOPPY, STRICT}; | 35 const StrictMode kStrictModes[] = {SLOPPY, STRICT}; |
33 | 36 |
34 } // namespace | 37 } // namespace |
35 | 38 |
36 | 39 |
37 class JSTypedLoweringTest : public TypedGraphTest { | 40 class JSTypedLoweringTest : public TypedGraphTest { |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 Node* const control = graph()->start(); | 226 Node* const control = graph()->start(); |
224 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRightLogical(), lhs, | 227 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRightLogical(), lhs, |
225 rhs, context, effect, control)); | 228 rhs, context, effect, control)); |
226 ASSERT_TRUE(r.Changed()); | 229 ASSERT_TRUE(r.Changed()); |
227 EXPECT_THAT(r.replacement(), | 230 EXPECT_THAT(r.replacement(), |
228 IsWord32Shr(lhs, IsWord32And(rhs, IsInt32Constant(0x1f)))); | 231 IsWord32Shr(lhs, IsWord32And(rhs, IsInt32Constant(0x1f)))); |
229 } | 232 } |
230 | 233 |
231 | 234 |
232 // ----------------------------------------------------------------------------- | 235 // ----------------------------------------------------------------------------- |
| 236 // JSLoadContext |
| 237 |
| 238 |
| 239 TEST_F(JSTypedLoweringTest, JSLoadContext) { |
| 240 Node* const context = Parameter(Type::Any()); |
| 241 Node* const effect = graph()->start(); |
| 242 static bool kBooleans[] = {false, true}; |
| 243 TRACED_FOREACH(size_t, index, kIndices) { |
| 244 TRACED_FOREACH(bool, immutable, kBooleans) { |
| 245 Reduction const r1 = Reduce( |
| 246 graph()->NewNode(javascript()->LoadContext(0, index, immutable), |
| 247 context, context, effect)); |
| 248 ASSERT_TRUE(r1.Changed()); |
| 249 EXPECT_THAT(r1.replacement(), |
| 250 IsLoadField(AccessBuilder::ForContextSlot(index), context, |
| 251 effect, graph()->start())); |
| 252 |
| 253 Reduction const r2 = Reduce( |
| 254 graph()->NewNode(javascript()->LoadContext(1, index, immutable), |
| 255 context, context, effect)); |
| 256 ASSERT_TRUE(r2.Changed()); |
| 257 EXPECT_THAT(r2.replacement(), |
| 258 IsLoadField(AccessBuilder::ForContextSlot(index), |
| 259 IsLoadField(AccessBuilder::ForContextSlot( |
| 260 Context::PREVIOUS_INDEX), |
| 261 context, effect, graph()->start()), |
| 262 effect, graph()->start())); |
| 263 } |
| 264 } |
| 265 } |
| 266 |
| 267 |
| 268 // ----------------------------------------------------------------------------- |
| 269 // JSStoreContext |
| 270 |
| 271 |
| 272 TEST_F(JSTypedLoweringTest, JSStoreContext) { |
| 273 Node* const context = Parameter(Type::Any()); |
| 274 Node* const effect = graph()->start(); |
| 275 Node* const control = graph()->start(); |
| 276 TRACED_FOREACH(size_t, index, kIndices) { |
| 277 TRACED_FOREACH(Type*, type, kJSTypes) { |
| 278 Node* const value = Parameter(type); |
| 279 |
| 280 Reduction const r1 = |
| 281 Reduce(graph()->NewNode(javascript()->StoreContext(0, index), context, |
| 282 value, context, effect, control)); |
| 283 ASSERT_TRUE(r1.Changed()); |
| 284 EXPECT_THAT(r1.replacement(), |
| 285 IsStoreField(AccessBuilder::ForContextSlot(index), context, |
| 286 value, effect, control)); |
| 287 |
| 288 Reduction const r2 = |
| 289 Reduce(graph()->NewNode(javascript()->StoreContext(1, index), context, |
| 290 value, context, effect, control)); |
| 291 ASSERT_TRUE(r2.Changed()); |
| 292 EXPECT_THAT(r2.replacement(), |
| 293 IsStoreField(AccessBuilder::ForContextSlot(index), |
| 294 IsLoadField(AccessBuilder::ForContextSlot( |
| 295 Context::PREVIOUS_INDEX), |
| 296 context, effect, graph()->start()), |
| 297 value, effect, control)); |
| 298 } |
| 299 } |
| 300 } |
| 301 |
| 302 |
| 303 // ----------------------------------------------------------------------------- |
233 // JSLoadProperty | 304 // JSLoadProperty |
234 | 305 |
235 | 306 |
236 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArray) { | 307 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArray) { |
237 const size_t kLength = 17; | 308 const size_t kLength = 17; |
238 double backing_store[kLength]; | 309 double backing_store[kLength]; |
239 Handle<JSArrayBuffer> buffer = | 310 Handle<JSArrayBuffer> buffer = |
240 NewArrayBuffer(backing_store, sizeof(backing_store)); | 311 NewArrayBuffer(backing_store, sizeof(backing_store)); |
241 VectorSlotPair feedback(Handle<TypeFeedbackVector>::null(), | 312 VectorSlotPair feedback(Handle<TypeFeedbackVector>::null(), |
242 FeedbackVectorICSlot::Invalid()); | 313 FeedbackVectorICSlot::Invalid()); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 IsStoreElement( | 533 IsStoreElement( |
463 access, IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), | 534 access, IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), |
464 key, value, effect, control)); | 535 key, value, effect, control)); |
465 } | 536 } |
466 } | 537 } |
467 } | 538 } |
468 | 539 |
469 } // namespace compiler | 540 } // namespace compiler |
470 } // namespace internal | 541 } // namespace internal |
471 } // namespace v8 | 542 } // namespace v8 |
OLD | NEW |