OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/diamond.h" | 6 #include "src/compiler/diamond.h" |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/js-intrinsic-lowering.h" | 8 #include "src/compiler/js-intrinsic-lowering.h" |
9 #include "src/compiler/js-operator.h" | 9 #include "src/compiler/js-operator.h" |
| 10 #include "src/types-inl.h" |
10 #include "test/unittests/compiler/graph-unittest.h" | 11 #include "test/unittests/compiler/graph-unittest.h" |
11 #include "test/unittests/compiler/node-test-utils.h" | 12 #include "test/unittests/compiler/node-test-utils.h" |
12 #include "testing/gmock-support.h" | 13 #include "testing/gmock-support.h" |
13 | 14 |
14 | 15 |
15 using testing::_; | 16 using testing::_; |
16 using testing::AllOf; | 17 using testing::AllOf; |
17 using testing::BitEq; | 18 using testing::BitEq; |
18 using testing::Capture; | 19 using testing::Capture; |
19 using testing::CaptureEq; | 20 using testing::CaptureEq; |
20 | 21 |
21 | 22 |
22 namespace v8 { | 23 namespace v8 { |
23 namespace internal { | 24 namespace internal { |
24 namespace compiler { | 25 namespace compiler { |
25 | 26 |
26 class JSIntrinsicLoweringTest : public GraphTest { | 27 class JSIntrinsicLoweringTest : public TypedGraphTest { |
27 public: | 28 public: |
28 JSIntrinsicLoweringTest() : GraphTest(3), javascript_(zone()) {} | 29 JSIntrinsicLoweringTest() : TypedGraphTest(3), javascript_(zone()) {} |
29 ~JSIntrinsicLoweringTest() override {} | 30 ~JSIntrinsicLoweringTest() override {} |
30 | 31 |
31 protected: | 32 protected: |
32 Reduction Reduce(Node* node, MachineOperatorBuilder::Flags flags = | 33 Reduction Reduce(Node* node, MachineOperatorBuilder::Flags flags = |
33 MachineOperatorBuilder::kNoFlags) { | 34 MachineOperatorBuilder::kNoFlags) { |
34 MachineOperatorBuilder machine(zone(), kMachPtr, flags); | 35 MachineOperatorBuilder machine(zone(), kMachPtr, flags); |
35 SimplifiedOperatorBuilder simplified(zone()); | 36 SimplifiedOperatorBuilder simplified(zone()); |
36 JSGraph jsgraph(isolate(), graph(), common(), javascript(), &simplified, | 37 JSGraph jsgraph(isolate(), graph(), common(), javascript(), &simplified, |
37 &machine); | 38 &machine); |
38 // TODO(titzer): mock the GraphReducer here for better unit testing. | 39 // TODO(titzer): mock the GraphReducer here for better unit testing. |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), | 281 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), |
281 IsBranch(IsObjectIsSmi(input), control))), | 282 IsBranch(IsObjectIsSmi(input), control))), |
282 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); | 283 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); |
283 } | 284 } |
284 | 285 |
285 | 286 |
286 // ----------------------------------------------------------------------------- | 287 // ----------------------------------------------------------------------------- |
287 // %_IsJSReceiver | 288 // %_IsJSReceiver |
288 | 289 |
289 | 290 |
290 TEST_F(JSIntrinsicLoweringTest, InlineIsJSReceiver) { | 291 TEST_F(JSIntrinsicLoweringTest, InlineIsJSReceiverWithAny) { |
291 Node* const input = Parameter(0); | 292 Node* const input = Parameter(Type::Any()); |
292 Node* const context = Parameter(1); | 293 Node* const context = Parameter(Type::Any()); |
293 Node* const effect = graph()->start(); | 294 Node* const effect = graph()->start(); |
294 Node* const control = graph()->start(); | 295 Node* const control = graph()->start(); |
295 Reduction const r = Reduce(graph()->NewNode( | 296 Reduction const r = Reduce(graph()->NewNode( |
296 javascript()->CallRuntime(Runtime::kInlineIsJSReceiver, 1), input, | 297 javascript()->CallRuntime(Runtime::kInlineIsJSReceiver, 1), input, |
297 context, effect, control)); | 298 context, effect, control)); |
298 ASSERT_TRUE(r.Changed()); | 299 ASSERT_TRUE(r.Changed()); |
299 | 300 |
300 Node* phi = r.replacement(); | 301 Node* phi = r.replacement(); |
301 Capture<Node *> branch, if_false; | 302 Capture<Node *> branch, if_false; |
302 EXPECT_THAT( | 303 EXPECT_THAT( |
303 phi, | 304 phi, |
304 IsPhi( | 305 IsPhi( |
305 static_cast<MachineType>(kTypeBool | kRepTagged), IsFalseConstant(), | 306 kMachAnyTagged, IsFalseConstant(), |
306 IsUint32LessThanOrEqual( | 307 IsUint32LessThanOrEqual( |
307 IsInt32Constant(FIRST_JS_RECEIVER_TYPE), | 308 IsInt32Constant(FIRST_JS_RECEIVER_TYPE), |
308 IsLoadField(AccessBuilder::ForMapInstanceType(), | 309 IsLoadField(AccessBuilder::ForMapInstanceType(), |
309 IsLoadField(AccessBuilder::ForMap(), input, effect, | 310 IsLoadField(AccessBuilder::ForMap(), input, effect, |
310 CaptureEq(&if_false)), | 311 CaptureEq(&if_false)), |
311 effect, _)), | 312 effect, _)), |
312 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), | 313 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), |
313 IsBranch(IsObjectIsSmi(input), control))), | 314 IsBranch(IsObjectIsSmi(input), control))), |
314 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); | 315 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); |
315 } | 316 } |
316 | 317 |
317 | 318 |
| 319 TEST_F(JSIntrinsicLoweringTest, InlineIsJSReceiverWithReceiver) { |
| 320 Node* const input = Parameter(Type::Receiver()); |
| 321 Node* const context = Parameter(Type::Any()); |
| 322 Node* const effect = graph()->start(); |
| 323 Node* const control = graph()->start(); |
| 324 Reduction const r = Reduce(graph()->NewNode( |
| 325 javascript()->CallRuntime(Runtime::kInlineIsJSReceiver, 1), input, |
| 326 context, effect, control)); |
| 327 ASSERT_TRUE(r.Changed()); |
| 328 EXPECT_THAT(r.replacement(), IsTrueConstant()); |
| 329 } |
| 330 |
| 331 |
| 332 TEST_F(JSIntrinsicLoweringTest, InlineIsJSReceiverWithUndefined) { |
| 333 Node* const input = Parameter(Type::Undefined()); |
| 334 Node* const context = Parameter(Type::Any()); |
| 335 Node* const effect = graph()->start(); |
| 336 Node* const control = graph()->start(); |
| 337 Reduction const r = Reduce(graph()->NewNode( |
| 338 javascript()->CallRuntime(Runtime::kInlineIsJSReceiver, 1), input, |
| 339 context, effect, control)); |
| 340 ASSERT_TRUE(r.Changed()); |
| 341 EXPECT_THAT(r.replacement(), IsFalseConstant()); |
| 342 } |
| 343 |
| 344 |
318 // ----------------------------------------------------------------------------- | 345 // ----------------------------------------------------------------------------- |
319 // %_JSValueGetValue | 346 // %_JSValueGetValue |
320 | 347 |
321 | 348 |
322 TEST_F(JSIntrinsicLoweringTest, InlineJSValueGetValue) { | 349 TEST_F(JSIntrinsicLoweringTest, InlineJSValueGetValue) { |
323 Node* const input = Parameter(0); | 350 Node* const input = Parameter(0); |
324 Node* const context = Parameter(1); | 351 Node* const context = Parameter(1); |
325 Node* const effect = graph()->start(); | 352 Node* const effect = graph()->start(); |
326 Node* const control = graph()->start(); | 353 Node* const control = graph()->start(); |
327 Reduction const r = Reduce(graph()->NewNode( | 354 Reduction const r = Reduce(graph()->NewNode( |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 CaptureEq(&if_false0)))))), | 468 CaptureEq(&if_false0)))))), |
442 IsMerge( | 469 IsMerge( |
443 IsIfTrue(AllOf(CaptureEq(&branch0), | 470 IsIfTrue(AllOf(CaptureEq(&branch0), |
444 IsBranch(IsObjectIsSmi(input), control))), | 471 IsBranch(IsObjectIsSmi(input), control))), |
445 AllOf(CaptureEq(&if_false0), IsIfFalse(CaptureEq(&branch0)))))); | 472 AllOf(CaptureEq(&if_false0), IsIfFalse(CaptureEq(&branch0)))))); |
446 } | 473 } |
447 | 474 |
448 } // namespace compiler | 475 } // namespace compiler |
449 } // namespace internal | 476 } // namespace internal |
450 } // namespace v8 | 477 } // namespace v8 |
OLD | NEW |