| 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 "test/unittests/compiler/instruction-selector-unittest.h" | 5 #include "test/unittests/compiler/instruction-selector-unittest.h" |
| 6 | 6 |
| 7 #include "src/code-stubs.h" | |
| 8 #include "src/compiler/graph.h" | 7 #include "src/compiler/graph.h" |
| 9 #include "src/compiler/schedule.h" | 8 #include "src/compiler/schedule.h" |
| 10 #include "src/flags.h" | 9 #include "src/flags.h" |
| 11 #include "test/unittests/compiler/compiler-test-utils.h" | 10 #include "test/unittests/compiler/compiler-test-utils.h" |
| 12 | 11 |
| 13 namespace v8 { | 12 namespace v8 { |
| 14 namespace internal { | 13 namespace internal { |
| 15 namespace compiler { | 14 namespace compiler { |
| 16 | 15 |
| 17 namespace { | 16 namespace { |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 // Function. | 585 // Function. |
| 587 EXPECT_EQ(s.ToVreg(function_node), s.ToVreg(call_instr->InputAt(11))); | 586 EXPECT_EQ(s.ToVreg(function_node), s.ToVreg(call_instr->InputAt(11))); |
| 588 // Context. | 587 // Context. |
| 589 EXPECT_EQ(s.ToVreg(context2), s.ToVreg(call_instr->InputAt(12))); | 588 EXPECT_EQ(s.ToVreg(context2), s.ToVreg(call_instr->InputAt(12))); |
| 590 // Continuation. | 589 // Continuation. |
| 591 | 590 |
| 592 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); | 591 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); |
| 593 EXPECT_EQ(index, s.size()); | 592 EXPECT_EQ(index, s.size()); |
| 594 } | 593 } |
| 595 | 594 |
| 596 | |
| 597 // ----------------------------------------------------------------------------- | |
| 598 // Tail calls. | |
| 599 | |
| 600 TARGET_TEST_F(InstructionSelectorTest, TailCall) { | |
| 601 for (int mode = 0; mode < 2; ++mode) { | |
| 602 bool supports_tail_calls = FLAG_turbo_tail_calls && (mode == 0); | |
| 603 | |
| 604 StreamBuilder m(this, kMachAnyTagged); | |
| 605 Node* start = m.graph()->start(); | |
| 606 Node* undefined = m.UndefinedConstant(); | |
| 607 | |
| 608 StringLengthStub stub(isolate()); | |
| 609 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | |
| 610 isolate(), zone(), stub.GetCallInterfaceDescriptor(), 0, | |
| 611 supports_tail_calls ? CallDescriptor::kSupportsTailCalls | |
| 612 : CallDescriptor::kNoFlags, | |
| 613 Operator::kNoProperties); | |
| 614 Node* stub_node = m.NewNode(m.common()->HeapConstant( | |
| 615 Unique<Code>::CreateUninitialized(stub.GetCode()))); | |
| 616 | |
| 617 Node* call = m.NewNode(m.common()->Call(desc), stub_node, undefined, | |
| 618 undefined, undefined, undefined, undefined); | |
| 619 call->AppendInput(zone(), start); // effect | |
| 620 call->AppendInput(zone(), start); // control | |
| 621 | |
| 622 m.Return(call); | |
| 623 Node* ret = *call->uses().begin(); | |
| 624 ret->AppendInput(zone(), call); // effect | |
| 625 ret->AppendInput(zone(), start); // control | |
| 626 | |
| 627 Stream s = m.Build(kAllInstructions); | |
| 628 if (supports_tail_calls) { | |
| 629 ASSERT_EQ(3U, s.size()); | |
| 630 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | |
| 631 EXPECT_EQ(kArchTailCallCodeObject, s[1]->arch_opcode()); | |
| 632 EXPECT_EQ(kArchNop, s[2]->arch_opcode()); | |
| 633 } else { | |
| 634 ASSERT_EQ(4U, s.size()); | |
| 635 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | |
| 636 EXPECT_EQ(kArchCallCodeObject, s[1]->arch_opcode()); | |
| 637 EXPECT_EQ(kArchRet, s[2]->arch_opcode()); | |
| 638 EXPECT_EQ(kArchNop, s[3]->arch_opcode()); | |
| 639 } | |
| 640 } | |
| 641 } | |
| 642 | |
| 643 } // namespace compiler | 595 } // namespace compiler |
| 644 } // namespace internal | 596 } // namespace internal |
| 645 } // namespace v8 | 597 } // namespace v8 |
| OLD | NEW |