Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: test/unittests/compiler/instruction-selector-unittest.cc

Issue 1108563002: Detect simple tail calls (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixed index type Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/hydrogen-instructions.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
7 #include "src/compiler/graph.h" 8 #include "src/compiler/graph.h"
8 #include "src/compiler/schedule.h" 9 #include "src/compiler/schedule.h"
9 #include "src/flags.h" 10 #include "src/flags.h"
10 #include "test/unittests/compiler/compiler-test-utils.h" 11 #include "test/unittests/compiler/compiler-test-utils.h"
11 12
12 namespace v8 { 13 namespace v8 {
13 namespace internal { 14 namespace internal {
14 namespace compiler { 15 namespace compiler {
15 16
16 namespace { 17 namespace {
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 // Function. 584 // Function.
584 EXPECT_EQ(s.ToVreg(function_node), s.ToVreg(call_instr->InputAt(11))); 585 EXPECT_EQ(s.ToVreg(function_node), s.ToVreg(call_instr->InputAt(11)));
585 // Context. 586 // Context.
586 EXPECT_EQ(s.ToVreg(context2), s.ToVreg(call_instr->InputAt(12))); 587 EXPECT_EQ(s.ToVreg(context2), s.ToVreg(call_instr->InputAt(12)));
587 // Continuation. 588 // Continuation.
588 589
589 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); 590 EXPECT_EQ(kArchRet, s[index++]->arch_opcode());
590 EXPECT_EQ(index, s.size()); 591 EXPECT_EQ(index, s.size());
591 } 592 }
592 593
594
595 // -----------------------------------------------------------------------------
596 // Tail calls.
597
598 TARGET_TEST_F(InstructionSelectorTest, TailCall) {
599 for (int mode = 0; mode < 2; ++mode) {
600 bool supports_tail_calls = FLAG_turbo_tail_calls && (mode == 0);
601
602 StreamBuilder m(this, kMachAnyTagged);
603 Node* start = m.graph()->start();
604 Node* undefined = m.UndefinedConstant();
605
606 StringLengthStub stub(isolate());
607 CallDescriptor* desc = Linkage::GetStubCallDescriptor(
608 isolate(), zone(), stub.GetCallInterfaceDescriptor(), 0,
609 supports_tail_calls ? CallDescriptor::kSupportsTailCalls
610 : CallDescriptor::kNoFlags,
611 Operator::kNoProperties);
612 Node* stub_node = m.NewNode(m.common()->HeapConstant(
613 Unique<Code>::CreateUninitialized(stub.GetCode())));
614
615 Node* call = m.NewNode(m.common()->Call(desc), stub_node, undefined,
616 undefined, undefined, undefined, undefined);
617 call->AppendInput(zone(), start); // effect
618 call->AppendInput(zone(), start); // control
619
620 m.Return(call);
621 Node* ret = *call->uses().begin();
622 ret->AppendInput(zone(), call); // effect
623 ret->AppendInput(zone(), start); // control
624
625 Stream s = m.Build(kAllInstructions);
626 if (supports_tail_calls) {
627 ASSERT_EQ(3U, s.size());
628 EXPECT_EQ(kArchNop, s[0]->arch_opcode());
629 EXPECT_EQ(kArchTailCallCodeObject, s[1]->arch_opcode());
630 EXPECT_EQ(kArchNop, s[2]->arch_opcode());
631 } else {
632 ASSERT_EQ(4U, s.size());
633 EXPECT_EQ(kArchNop, s[0]->arch_opcode());
634 EXPECT_EQ(kArchCallCodeObject, s[1]->arch_opcode());
635 EXPECT_EQ(kArchRet, s[2]->arch_opcode());
636 EXPECT_EQ(kArchNop, s[3]->arch_opcode());
637 }
638 }
639 }
640
593 } // namespace compiler 641 } // namespace compiler
594 } // namespace internal 642 } // namespace internal
595 } // namespace v8 643 } // namespace v8
OLDNEW
« no previous file with comments | « src/hydrogen-instructions.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698