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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 -1.0, 0.0, 1.0, 42.0, | 60 -1.0, 0.0, 1.0, 42.0, |
61 1000.0, INT_MAX, UINT_MAX, V8_INFINITY}; | 61 1000.0, INT_MAX, UINT_MAX, V8_INFINITY}; |
62 | 62 |
63 | 63 |
64 Type* const kJSTypes[] = {Type::Undefined(), Type::Null(), Type::Boolean(), | 64 Type* const kJSTypes[] = {Type::Undefined(), Type::Null(), Type::Boolean(), |
65 Type::Number(), Type::String(), Type::Object()}; | 65 Type::Number(), Type::String(), Type::Object()}; |
66 | 66 |
67 | 67 |
68 STATIC_ASSERT(LANGUAGE_END == 3); | 68 STATIC_ASSERT(LANGUAGE_END == 3); |
69 const LanguageMode kLanguageModes[] = {SLOPPY, STRICT, STRONG}; | 69 const LanguageMode kLanguageModes[] = {SLOPPY, STRICT, STRONG}; |
| 70 const Strength kStrengths[] = {Strength::NORMAL, Strength::STRONG}; |
70 | 71 |
71 } // namespace | 72 } // namespace |
72 | 73 |
73 | 74 |
74 class JSTypedLoweringTest : public TypedGraphTest { | 75 class JSTypedLoweringTest : public TypedGraphTest { |
75 public: | 76 public: |
76 JSTypedLoweringTest() : TypedGraphTest(3), javascript_(zone()) {} | 77 JSTypedLoweringTest() : TypedGraphTest(3), javascript_(zone()) {} |
77 ~JSTypedLoweringTest() override {} | 78 ~JSTypedLoweringTest() override {} |
78 | 79 |
79 protected: | 80 protected: |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 // ----------------------------------------------------------------------------- | 455 // ----------------------------------------------------------------------------- |
455 // JSShiftLeft | 456 // JSShiftLeft |
456 | 457 |
457 | 458 |
458 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndConstant) { | 459 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndConstant) { |
459 Node* const lhs = Parameter(Type::Signed32()); | 460 Node* const lhs = Parameter(Type::Signed32()); |
460 Node* const context = UndefinedConstant(); | 461 Node* const context = UndefinedConstant(); |
461 Node* const effect = graph()->start(); | 462 Node* const effect = graph()->start(); |
462 Node* const control = graph()->start(); | 463 Node* const control = graph()->start(); |
463 TRACED_FORRANGE(double, rhs, 0, 31) { | 464 TRACED_FORRANGE(double, rhs, 0, 31) { |
464 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 465 TRACED_FOREACH(Strength, strength, kStrengths) { |
465 Reduction r = Reduce(graph()->NewNode( | 466 Reduction r = Reduce(graph()->NewNode( |
466 javascript()->ShiftLeft(language_mode), lhs, NumberConstant(rhs), | 467 javascript()->ShiftLeft(strength), lhs, NumberConstant(rhs), context, |
467 context, EmptyFrameState(), EmptyFrameState(), effect, control)); | 468 EmptyFrameState(), EmptyFrameState(), effect, control)); |
468 ASSERT_TRUE(r.Changed()); | 469 ASSERT_TRUE(r.Changed()); |
469 EXPECT_THAT(r.replacement(), | 470 EXPECT_THAT(r.replacement(), |
470 IsWord32Shl(lhs, IsNumberConstant(BitEq(rhs)))); | 471 IsWord32Shl(lhs, IsNumberConstant(BitEq(rhs)))); |
471 } | 472 } |
472 } | 473 } |
473 } | 474 } |
474 | 475 |
475 | 476 |
476 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndUnsigned32) { | 477 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndUnsigned32) { |
477 Node* const lhs = Parameter(Type::Signed32()); | 478 Node* const lhs = Parameter(Type::Signed32()); |
478 Node* const rhs = Parameter(Type::Unsigned32()); | 479 Node* const rhs = Parameter(Type::Unsigned32()); |
479 Node* const context = UndefinedConstant(); | 480 Node* const context = UndefinedConstant(); |
480 Node* const effect = graph()->start(); | 481 Node* const effect = graph()->start(); |
481 Node* const control = graph()->start(); | 482 Node* const control = graph()->start(); |
482 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 483 TRACED_FOREACH(Strength, strength, kStrengths) { |
483 Reduction r = Reduce(graph()->NewNode( | 484 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftLeft(strength), |
484 javascript()->ShiftLeft(language_mode), lhs, rhs, context, | 485 lhs, rhs, context, EmptyFrameState(), |
485 EmptyFrameState(), EmptyFrameState(), effect, control)); | 486 EmptyFrameState(), effect, control)); |
486 ASSERT_TRUE(r.Changed()); | 487 ASSERT_TRUE(r.Changed()); |
487 EXPECT_THAT(r.replacement(), | 488 EXPECT_THAT(r.replacement(), |
488 IsWord32Shl(lhs, IsWord32And(rhs, IsInt32Constant(0x1f)))); | 489 IsWord32Shl(lhs, IsWord32And(rhs, IsInt32Constant(0x1f)))); |
489 } | 490 } |
490 } | 491 } |
491 | 492 |
492 | 493 |
493 // ----------------------------------------------------------------------------- | 494 // ----------------------------------------------------------------------------- |
494 // JSShiftRight | 495 // JSShiftRight |
495 | 496 |
496 | 497 |
497 TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndConstant) { | 498 TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndConstant) { |
498 Node* const lhs = Parameter(Type::Signed32()); | 499 Node* const lhs = Parameter(Type::Signed32()); |
499 Node* const context = UndefinedConstant(); | 500 Node* const context = UndefinedConstant(); |
500 Node* const effect = graph()->start(); | 501 Node* const effect = graph()->start(); |
501 Node* const control = graph()->start(); | 502 Node* const control = graph()->start(); |
502 TRACED_FORRANGE(double, rhs, 0, 31) { | 503 TRACED_FORRANGE(double, rhs, 0, 31) { |
503 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 504 TRACED_FOREACH(Strength, strength, kStrengths) { |
504 Reduction r = Reduce(graph()->NewNode( | 505 Reduction r = Reduce(graph()->NewNode( |
505 javascript()->ShiftRight(language_mode), lhs, NumberConstant(rhs), | 506 javascript()->ShiftRight(strength), lhs, NumberConstant(rhs), context, |
506 context, EmptyFrameState(), EmptyFrameState(), effect, control)); | 507 EmptyFrameState(), EmptyFrameState(), effect, control)); |
507 ASSERT_TRUE(r.Changed()); | 508 ASSERT_TRUE(r.Changed()); |
508 EXPECT_THAT(r.replacement(), | 509 EXPECT_THAT(r.replacement(), |
509 IsWord32Sar(lhs, IsNumberConstant(BitEq(rhs)))); | 510 IsWord32Sar(lhs, IsNumberConstant(BitEq(rhs)))); |
510 } | 511 } |
511 } | 512 } |
512 } | 513 } |
513 | 514 |
514 | 515 |
515 TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndUnsigned32) { | 516 TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndUnsigned32) { |
516 Node* const lhs = Parameter(Type::Signed32()); | 517 Node* const lhs = Parameter(Type::Signed32()); |
517 Node* const rhs = Parameter(Type::Unsigned32()); | 518 Node* const rhs = Parameter(Type::Unsigned32()); |
518 Node* const context = UndefinedConstant(); | 519 Node* const context = UndefinedConstant(); |
519 Node* const effect = graph()->start(); | 520 Node* const effect = graph()->start(); |
520 Node* const control = graph()->start(); | 521 Node* const control = graph()->start(); |
521 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 522 TRACED_FOREACH(Strength, strength, kStrengths) { |
522 Reduction r = Reduce(graph()->NewNode( | 523 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRight(strength), |
523 javascript()->ShiftRight(language_mode), lhs, rhs, context, | 524 lhs, rhs, context, EmptyFrameState(), |
524 EmptyFrameState(), EmptyFrameState(), effect, control)); | 525 EmptyFrameState(), effect, control)); |
525 ASSERT_TRUE(r.Changed()); | 526 ASSERT_TRUE(r.Changed()); |
526 EXPECT_THAT(r.replacement(), | 527 EXPECT_THAT(r.replacement(), |
527 IsWord32Sar(lhs, IsWord32And(rhs, IsInt32Constant(0x1f)))); | 528 IsWord32Sar(lhs, IsWord32And(rhs, IsInt32Constant(0x1f)))); |
528 } | 529 } |
529 } | 530 } |
530 | 531 |
531 | 532 |
532 // ----------------------------------------------------------------------------- | 533 // ----------------------------------------------------------------------------- |
533 // JSShiftRightLogical | 534 // JSShiftRightLogical |
534 | 535 |
535 | 536 |
536 TEST_F(JSTypedLoweringTest, | 537 TEST_F(JSTypedLoweringTest, |
537 JSShiftRightLogicalWithUnsigned32AndConstant) { | 538 JSShiftRightLogicalWithUnsigned32AndConstant) { |
538 Node* const lhs = Parameter(Type::Unsigned32()); | 539 Node* const lhs = Parameter(Type::Unsigned32()); |
539 Node* const context = UndefinedConstant(); | 540 Node* const context = UndefinedConstant(); |
540 Node* const effect = graph()->start(); | 541 Node* const effect = graph()->start(); |
541 Node* const control = graph()->start(); | 542 Node* const control = graph()->start(); |
542 TRACED_FORRANGE(double, rhs, 0, 31) { | 543 TRACED_FORRANGE(double, rhs, 0, 31) { |
543 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 544 TRACED_FOREACH(Strength, strength, kStrengths) { |
544 Reduction r = Reduce( | 545 Reduction r = Reduce(graph()->NewNode( |
545 graph()->NewNode(javascript()->ShiftRightLogical(language_mode), lhs, | 546 javascript()->ShiftRightLogical(strength), lhs, NumberConstant(rhs), |
546 NumberConstant(rhs), context, EmptyFrameState(), | 547 context, EmptyFrameState(), EmptyFrameState(), effect, control)); |
547 EmptyFrameState(), effect, control)); | |
548 ASSERT_TRUE(r.Changed()); | 548 ASSERT_TRUE(r.Changed()); |
549 EXPECT_THAT(r.replacement(), | 549 EXPECT_THAT(r.replacement(), |
550 IsWord32Shr(lhs, IsNumberConstant(BitEq(rhs)))); | 550 IsWord32Shr(lhs, IsNumberConstant(BitEq(rhs)))); |
551 } | 551 } |
552 } | 552 } |
553 } | 553 } |
554 | 554 |
555 | 555 |
556 TEST_F(JSTypedLoweringTest, | 556 TEST_F(JSTypedLoweringTest, |
557 JSShiftRightLogicalWithUnsigned32AndUnsigned32) { | 557 JSShiftRightLogicalWithUnsigned32AndUnsigned32) { |
558 Node* const lhs = Parameter(Type::Unsigned32()); | 558 Node* const lhs = Parameter(Type::Unsigned32()); |
559 Node* const rhs = Parameter(Type::Unsigned32()); | 559 Node* const rhs = Parameter(Type::Unsigned32()); |
560 Node* const context = UndefinedConstant(); | 560 Node* const context = UndefinedConstant(); |
561 Node* const effect = graph()->start(); | 561 Node* const effect = graph()->start(); |
562 Node* const control = graph()->start(); | 562 Node* const control = graph()->start(); |
563 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 563 TRACED_FOREACH(Strength, strength, kStrengths) { |
564 Reduction r = Reduce(graph()->NewNode( | 564 Reduction r = Reduce(graph()->NewNode( |
565 javascript()->ShiftRightLogical(language_mode), lhs, rhs, context, | 565 javascript()->ShiftRightLogical(strength), lhs, rhs, context, |
566 EmptyFrameState(), EmptyFrameState(), effect, control)); | 566 EmptyFrameState(), EmptyFrameState(), effect, control)); |
567 ASSERT_TRUE(r.Changed()); | 567 ASSERT_TRUE(r.Changed()); |
568 EXPECT_THAT(r.replacement(), | 568 EXPECT_THAT(r.replacement(), |
569 IsWord32Shr(lhs, IsWord32And(rhs, IsInt32Constant(0x1f)))); | 569 IsWord32Shr(lhs, IsWord32And(rhs, IsInt32Constant(0x1f)))); |
570 } | 570 } |
571 } | 571 } |
572 | 572 |
573 | 573 |
574 // ----------------------------------------------------------------------------- | 574 // ----------------------------------------------------------------------------- |
575 // JSLoadContext | 575 // JSLoadContext |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 } | 931 } |
932 } | 932 } |
933 | 933 |
934 #if V8_TURBOFAN_TARGET | 934 #if V8_TURBOFAN_TARGET |
935 | 935 |
936 // ----------------------------------------------------------------------------- | 936 // ----------------------------------------------------------------------------- |
937 // JSAdd | 937 // JSAdd |
938 | 938 |
939 | 939 |
940 TEST_F(JSTypedLoweringTest, JSAddWithString) { | 940 TEST_F(JSTypedLoweringTest, JSAddWithString) { |
941 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 941 TRACED_FOREACH(Strength, strength, kStrengths) { |
942 Node* lhs = Parameter(Type::String(), 0); | 942 Node* lhs = Parameter(Type::String(), 0); |
943 Node* rhs = Parameter(Type::String(), 1); | 943 Node* rhs = Parameter(Type::String(), 1); |
944 Node* context = Parameter(Type::Any(), 2); | 944 Node* context = Parameter(Type::Any(), 2); |
945 Node* frame_state0 = EmptyFrameState(); | 945 Node* frame_state0 = EmptyFrameState(); |
946 Node* frame_state1 = EmptyFrameState(); | 946 Node* frame_state1 = EmptyFrameState(); |
947 Node* effect = graph()->start(); | 947 Node* effect = graph()->start(); |
948 Node* control = graph()->start(); | 948 Node* control = graph()->start(); |
949 Reduction r = Reduce(graph()->NewNode(javascript()->Add(language_mode), lhs, | 949 Reduction r = |
950 rhs, context, frame_state0, | 950 Reduce(graph()->NewNode(javascript()->Add(strength), lhs, rhs, context, |
951 frame_state1, effect, control)); | 951 frame_state0, frame_state1, effect, control)); |
952 ASSERT_TRUE(r.Changed()); | 952 ASSERT_TRUE(r.Changed()); |
953 EXPECT_THAT( | 953 EXPECT_THAT( |
954 r.replacement(), | 954 r.replacement(), |
955 IsCall(_, IsHeapConstant(Unique<HeapObject>::CreateImmovable( | 955 IsCall(_, IsHeapConstant(Unique<HeapObject>::CreateImmovable( |
956 CodeFactory::StringAdd(isolate(), STRING_ADD_CHECK_NONE, | 956 CodeFactory::StringAdd(isolate(), STRING_ADD_CHECK_NONE, |
957 NOT_TENURED).code())), | 957 NOT_TENURED).code())), |
958 lhs, rhs, context, frame_state0, effect, control)); | 958 lhs, rhs, context, frame_state0, effect, control)); |
959 } | 959 } |
960 } | 960 } |
961 | 961 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1053 EXPECT_THAT(r.replacement(), | 1053 EXPECT_THAT(r.replacement(), |
1054 IsFinish(IsAllocate(IsNumberConstant(Context::SizeFor( | 1054 IsFinish(IsAllocate(IsNumberConstant(Context::SizeFor( |
1055 Context::MIN_CONTEXT_SLOTS)), | 1055 Context::MIN_CONTEXT_SLOTS)), |
1056 effect, control), | 1056 effect, control), |
1057 _)); | 1057 _)); |
1058 } | 1058 } |
1059 | 1059 |
1060 } // namespace compiler | 1060 } // namespace compiler |
1061 } // namespace internal | 1061 } // namespace internal |
1062 } // namespace v8 | 1062 } // namespace v8 |
OLD | NEW |