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/code-factory.h" | 5 #include "src/code-factory.h" |
6 #include "src/compiler/access-builder.h" | 6 #include "src/compiler/access-builder.h" |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/js-operator.h" | 8 #include "src/compiler/js-operator.h" |
9 #include "src/compiler/js-typed-lowering.h" | 9 #include "src/compiler/js-typed-lowering.h" |
10 #include "src/compiler/machine-operator.h" | 10 #include "src/compiler/machine-operator.h" |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 Node* const context = UndefinedConstant(); | 441 Node* const context = UndefinedConstant(); |
442 Node* const effect = graph()->start(); | 442 Node* const effect = graph()->start(); |
443 Node* const control = graph()->start(); | 443 Node* const control = graph()->start(); |
444 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftLeft(hints), lhs, | 444 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftLeft(hints), lhs, |
445 rhs, context, EmptyFrameState(), | 445 rhs, context, EmptyFrameState(), |
446 EmptyFrameState(), effect, control)); | 446 EmptyFrameState(), effect, control)); |
447 ASSERT_TRUE(r.Changed()); | 447 ASSERT_TRUE(r.Changed()); |
448 EXPECT_THAT(r.replacement(), IsNumberShiftLeft(lhs, rhs)); | 448 EXPECT_THAT(r.replacement(), IsNumberShiftLeft(lhs, rhs)); |
449 } | 449 } |
450 | 450 |
| 451 TEST_F(JSTypedLoweringTest, JSShiftLeftWithTypeFeedback) { |
| 452 BinaryOperationHints::Hint const feedback_types[] = { |
| 453 BinaryOperationHints::kSignedSmall, |
| 454 BinaryOperationHints::kNumberOrOddball}; |
| 455 for (BinaryOperationHints::Hint feedback : feedback_types) { |
| 456 BinaryOperationHints const hints(feedback, feedback, feedback); |
| 457 Node* lhs = Parameter(Type::Number(), 2); |
| 458 Node* rhs = Parameter(Type::Number(), 3); |
| 459 Node* effect = graph()->start(); |
| 460 Node* control = graph()->start(); |
| 461 Reduction r = Reduce(graph()->NewNode( |
| 462 javascript()->ShiftLeft(hints), lhs, rhs, UndefinedConstant(), |
| 463 EmptyFrameState(), EmptyFrameState(), effect, control)); |
| 464 ASSERT_TRUE(r.Changed()); |
| 465 EXPECT_THAT(r.replacement(), IsSpeculativeNumberShiftLeft( |
| 466 feedback, lhs, rhs, effect, control)); |
| 467 } |
| 468 } |
451 | 469 |
452 // ----------------------------------------------------------------------------- | 470 // ----------------------------------------------------------------------------- |
453 // JSShiftRight | 471 // JSShiftRight |
454 | 472 |
455 | 473 |
456 TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndConstant) { | 474 TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndConstant) { |
457 BinaryOperationHints const hints = BinaryOperationHints::Any(); | 475 BinaryOperationHints const hints = BinaryOperationHints::Any(); |
458 Node* const lhs = Parameter(Type::Signed32()); | 476 Node* const lhs = Parameter(Type::Signed32()); |
459 Node* const context = UndefinedConstant(); | 477 Node* const context = UndefinedConstant(); |
460 Node* const effect = graph()->start(); | 478 Node* const effect = graph()->start(); |
(...skipping 16 matching lines...) Expand all Loading... |
477 Node* const context = UndefinedConstant(); | 495 Node* const context = UndefinedConstant(); |
478 Node* const effect = graph()->start(); | 496 Node* const effect = graph()->start(); |
479 Node* const control = graph()->start(); | 497 Node* const control = graph()->start(); |
480 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRight(hints), lhs, | 498 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRight(hints), lhs, |
481 rhs, context, EmptyFrameState(), | 499 rhs, context, EmptyFrameState(), |
482 EmptyFrameState(), effect, control)); | 500 EmptyFrameState(), effect, control)); |
483 ASSERT_TRUE(r.Changed()); | 501 ASSERT_TRUE(r.Changed()); |
484 EXPECT_THAT(r.replacement(), IsNumberShiftRight(lhs, rhs)); | 502 EXPECT_THAT(r.replacement(), IsNumberShiftRight(lhs, rhs)); |
485 } | 503 } |
486 | 504 |
| 505 TEST_F(JSTypedLoweringTest, JSShiftRightWithTypeFeedback) { |
| 506 BinaryOperationHints::Hint const feedback_types[] = { |
| 507 BinaryOperationHints::kSignedSmall, |
| 508 BinaryOperationHints::kNumberOrOddball}; |
| 509 for (BinaryOperationHints::Hint feedback : feedback_types) { |
| 510 BinaryOperationHints const hints(feedback, feedback, feedback); |
| 511 Node* lhs = Parameter(Type::Number(), 2); |
| 512 Node* rhs = Parameter(Type::Number(), 3); |
| 513 Node* effect = graph()->start(); |
| 514 Node* control = graph()->start(); |
| 515 Reduction r = Reduce(graph()->NewNode( |
| 516 javascript()->ShiftRight(hints), lhs, rhs, UndefinedConstant(), |
| 517 EmptyFrameState(), EmptyFrameState(), effect, control)); |
| 518 ASSERT_TRUE(r.Changed()); |
| 519 EXPECT_THAT(r.replacement(), IsSpeculativeNumberShiftRight( |
| 520 feedback, lhs, rhs, effect, control)); |
| 521 } |
| 522 } |
487 | 523 |
488 // ----------------------------------------------------------------------------- | 524 // ----------------------------------------------------------------------------- |
489 // JSShiftRightLogical | 525 // JSShiftRightLogical |
490 | 526 |
491 | 527 |
492 TEST_F(JSTypedLoweringTest, | 528 TEST_F(JSTypedLoweringTest, |
493 JSShiftRightLogicalWithUnsigned32AndConstant) { | 529 JSShiftRightLogicalWithUnsigned32AndConstant) { |
494 BinaryOperationHints const hints = BinaryOperationHints::Any(); | 530 BinaryOperationHints const hints = BinaryOperationHints::Any(); |
495 Node* const lhs = Parameter(Type::Unsigned32()); | 531 Node* const lhs = Parameter(Type::Unsigned32()); |
496 Node* const context = UndefinedConstant(); | 532 Node* const context = UndefinedConstant(); |
(...skipping 17 matching lines...) Expand all Loading... |
514 Node* const context = UndefinedConstant(); | 550 Node* const context = UndefinedConstant(); |
515 Node* const effect = graph()->start(); | 551 Node* const effect = graph()->start(); |
516 Node* const control = graph()->start(); | 552 Node* const control = graph()->start(); |
517 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRightLogical(hints), | 553 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRightLogical(hints), |
518 lhs, rhs, context, EmptyFrameState(), | 554 lhs, rhs, context, EmptyFrameState(), |
519 EmptyFrameState(), effect, control)); | 555 EmptyFrameState(), effect, control)); |
520 ASSERT_TRUE(r.Changed()); | 556 ASSERT_TRUE(r.Changed()); |
521 EXPECT_THAT(r.replacement(), IsNumberShiftRightLogical(lhs, rhs)); | 557 EXPECT_THAT(r.replacement(), IsNumberShiftRightLogical(lhs, rhs)); |
522 } | 558 } |
523 | 559 |
| 560 TEST_F(JSTypedLoweringTest, JSShiftRightLogicalWithTypeFeedback) { |
| 561 BinaryOperationHints::Hint const feedback_types[] = { |
| 562 BinaryOperationHints::kSignedSmall, |
| 563 BinaryOperationHints::kNumberOrOddball}; |
| 564 for (BinaryOperationHints::Hint feedback : feedback_types) { |
| 565 BinaryOperationHints const hints(feedback, feedback, feedback); |
| 566 Node* lhs = Parameter(Type::Number(), 2); |
| 567 Node* rhs = Parameter(Type::Number(), 3); |
| 568 Node* effect = graph()->start(); |
| 569 Node* control = graph()->start(); |
| 570 Reduction r = Reduce(graph()->NewNode( |
| 571 javascript()->ShiftRightLogical(hints), lhs, rhs, UndefinedConstant(), |
| 572 EmptyFrameState(), EmptyFrameState(), effect, control)); |
| 573 ASSERT_TRUE(r.Changed()); |
| 574 EXPECT_THAT(r.replacement(), IsSpeculativeNumberShiftRightLogical( |
| 575 feedback, lhs, rhs, effect, control)); |
| 576 } |
| 577 } |
524 | 578 |
525 // ----------------------------------------------------------------------------- | 579 // ----------------------------------------------------------------------------- |
526 // JSLoadContext | 580 // JSLoadContext |
527 | 581 |
528 | 582 |
529 TEST_F(JSTypedLoweringTest, JSLoadContext) { | 583 TEST_F(JSTypedLoweringTest, JSLoadContext) { |
530 Node* const context = Parameter(Type::Any()); | 584 Node* const context = Parameter(Type::Any()); |
531 Node* const effect = graph()->start(); | 585 Node* const effect = graph()->start(); |
532 static bool kBooleans[] = {false, true}; | 586 static bool kBooleans[] = {false, true}; |
533 TRACED_FOREACH(size_t, index, kIndices) { | 587 TRACED_FOREACH(size_t, index, kIndices) { |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 Node* control = graph()->start(); | 938 Node* control = graph()->start(); |
885 Reduction r = Reduce(graph()->NewNode(javascript()->Subtract(hints), lhs, rhs, | 939 Reduction r = Reduce(graph()->NewNode(javascript()->Subtract(hints), lhs, rhs, |
886 context, frame_state, effect, control)); | 940 context, frame_state, effect, control)); |
887 ASSERT_TRUE(r.Changed()); | 941 ASSERT_TRUE(r.Changed()); |
888 EXPECT_THAT(r.replacement(), | 942 EXPECT_THAT(r.replacement(), |
889 IsSpeculativeNumberSubtract(BinaryOperationHints::kSignedSmall, | 943 IsSpeculativeNumberSubtract(BinaryOperationHints::kSignedSmall, |
890 lhs, rhs, effect, control)); | 944 lhs, rhs, effect, control)); |
891 } | 945 } |
892 | 946 |
893 // ----------------------------------------------------------------------------- | 947 // ----------------------------------------------------------------------------- |
894 // JSShiftLeft | |
895 | |
896 TEST_F(JSTypedLoweringTest, JSShiftLeftSmis) { | |
897 BinaryOperationHints const hints(BinaryOperationHints::kSignedSmall, | |
898 BinaryOperationHints::kSignedSmall, | |
899 BinaryOperationHints::kSignedSmall); | |
900 Node* lhs = Parameter(Type::Number(), 2); | |
901 Node* rhs = Parameter(Type::Number(), 3); | |
902 Node* effect = graph()->start(); | |
903 Node* control = graph()->start(); | |
904 Reduction r = Reduce(graph()->NewNode( | |
905 javascript()->ShiftLeft(hints), lhs, rhs, UndefinedConstant(), | |
906 EmptyFrameState(), EmptyFrameState(), effect, control)); | |
907 ASSERT_TRUE(r.Changed()); | |
908 EXPECT_THAT(r.replacement(), | |
909 IsSpeculativeNumberShiftLeft(BinaryOperationHints::kSignedSmall, | |
910 lhs, rhs, effect, control)); | |
911 } | |
912 | |
913 TEST_F(JSTypedLoweringTest, JSShiftLeftNumberOrOddball) { | |
914 BinaryOperationHints const hints(BinaryOperationHints::kNumberOrOddball, | |
915 BinaryOperationHints::kNumberOrOddball, | |
916 BinaryOperationHints::kNumberOrOddball); | |
917 Node* lhs = Parameter(Type::Number(), 2); | |
918 Node* rhs = Parameter(Type::Number(), 3); | |
919 Node* effect = graph()->start(); | |
920 Node* control = graph()->start(); | |
921 Reduction r = Reduce(graph()->NewNode( | |
922 javascript()->ShiftLeft(hints), lhs, rhs, UndefinedConstant(), | |
923 EmptyFrameState(), EmptyFrameState(), effect, control)); | |
924 ASSERT_TRUE(r.Changed()); | |
925 EXPECT_THAT(r.replacement(), IsSpeculativeNumberShiftLeft( | |
926 BinaryOperationHints::kNumberOrOddball, lhs, | |
927 rhs, effect, control)); | |
928 } | |
929 | |
930 // ----------------------------------------------------------------------------- | |
931 // JSInstanceOf | 948 // JSInstanceOf |
932 // Test that instanceOf is reduced if and only if the right-hand side is a | 949 // Test that instanceOf is reduced if and only if the right-hand side is a |
933 // function constant. Functional correctness is ensured elsewhere. | 950 // function constant. Functional correctness is ensured elsewhere. |
934 | 951 |
935 TEST_F(JSTypedLoweringTest, JSInstanceOfSpecializationWithoutSmiCheck) { | 952 TEST_F(JSTypedLoweringTest, JSInstanceOfSpecializationWithoutSmiCheck) { |
936 Node* const context = Parameter(Type::Any()); | 953 Node* const context = Parameter(Type::Any()); |
937 Node* const frame_state = EmptyFrameState(); | 954 Node* const frame_state = EmptyFrameState(); |
938 Node* const effect = graph()->start(); | 955 Node* const effect = graph()->start(); |
939 Node* const control = graph()->start(); | 956 Node* const control = graph()->start(); |
940 | 957 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, | 1002 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, |
986 frame_state, effect, control); | 1003 frame_state, effect, control); |
987 Reduction r = Reduce(instanceOf); | 1004 Reduction r = Reduce(instanceOf); |
988 ASSERT_FALSE(r.Changed()); | 1005 ASSERT_FALSE(r.Changed()); |
989 ASSERT_EQ(instanceOf, dummy->InputAt(0)); | 1006 ASSERT_EQ(instanceOf, dummy->InputAt(0)); |
990 } | 1007 } |
991 | 1008 |
992 } // namespace compiler | 1009 } // namespace compiler |
993 } // namespace internal | 1010 } // namespace internal |
994 } // namespace v8 | 1011 } // namespace v8 |
OLD | NEW |