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

Side by Side Diff: src/compiler/mips64/instruction-selector-mips64.cc

Issue 1114163005: [turbofan] Fix tail call optimization. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
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 "src/base/adapters.h" 5 #include "src/base/adapters.h"
6 #include "src/base/bits.h" 6 #include "src/base/bits.h"
7 #include "src/compiler/instruction-selector-impl.h" 7 #include "src/compiler/instruction-selector-impl.h"
8 #include "src/compiler/node-matchers.h" 8 #include "src/compiler/node-matchers.h"
9 #include "src/compiler/node-properties.h" 9 #include "src/compiler/node-properties.h"
10 10
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 void InstructionSelector::VisitFloat64RoundTruncate(Node* node) { 641 void InstructionSelector::VisitFloat64RoundTruncate(Node* node) {
642 VisitRR(this, kMips64Float64RoundTruncate, node); 642 VisitRR(this, kMips64Float64RoundTruncate, node);
643 } 643 }
644 644
645 645
646 void InstructionSelector::VisitFloat64RoundTiesAway(Node* node) { 646 void InstructionSelector::VisitFloat64RoundTiesAway(Node* node) {
647 UNREACHABLE(); 647 UNREACHABLE();
648 } 648 }
649 649
650 650
651 void InstructionSelector::VisitCall(Node* node, BasicBlock* handler, 651 void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) {
652 CallMode call_mode) {
653 Mips64OperandGenerator g(this); 652 Mips64OperandGenerator g(this);
654 const CallDescriptor* descriptor = OpParameter<const CallDescriptor*>(node); 653 const CallDescriptor* descriptor = OpParameter<const CallDescriptor*>(node);
655 654
656 FrameStateDescriptor* frame_state_descriptor = NULL; 655 FrameStateDescriptor* frame_state_descriptor = nullptr;
657 if (descriptor->NeedsFrameState()) { 656 if (descriptor->NeedsFrameState()) {
658 frame_state_descriptor = 657 frame_state_descriptor =
659 GetFrameStateDescriptor(node->InputAt(descriptor->InputCount())); 658 GetFrameStateDescriptor(node->InputAt(descriptor->InputCount()));
660 } 659 }
661 660
662 CallBuffer buffer(zone(), descriptor, frame_state_descriptor); 661 CallBuffer buffer(zone(), descriptor, frame_state_descriptor);
663 662
664 // Compute InstructionOperands for inputs and outputs. 663 // Compute InstructionOperands for inputs and outputs.
665 InitializeCallBuffer(node, &buffer, true, false); 664 InitializeCallBuffer(node, &buffer, true, false);
666 665
667 int push_count = buffer.pushed_nodes.size(); 666 int push_count = buffer.pushed_nodes.size();
668 if (push_count > 0) { 667 if (push_count > 0) {
669 Emit(kMips64StackClaim, g.NoOutput(), 668 Emit(kMips64StackClaim, g.NoOutput(),
670 g.TempImmediate(push_count << kPointerSizeLog2)); 669 g.TempImmediate(push_count << kPointerSizeLog2));
671 } 670 }
672 int slot = buffer.pushed_nodes.size() - 1; 671 int slot = buffer.pushed_nodes.size() - 1;
673 for (Node* node : base::Reversed(buffer.pushed_nodes)) { 672 for (Node* node : base::Reversed(buffer.pushed_nodes)) {
674 Emit(kMips64StoreToStackSlot, g.NoOutput(), g.UseRegister(node), 673 Emit(kMips64StoreToStackSlot, g.NoOutput(), g.UseRegister(node),
675 g.TempImmediate(slot << kPointerSizeLog2)); 674 g.TempImmediate(slot << kPointerSizeLog2));
676 slot--; 675 slot--;
677 } 676 }
678 677
679 // Pass label of exception handler block. 678 // Pass label of exception handler block.
680 CallDescriptor::Flags flags = descriptor->flags(); 679 CallDescriptor::Flags flags = descriptor->flags();
681 if (handler != nullptr) { 680 if (handler) {
682 flags |= CallDescriptor::kHasExceptionHandler; 681 flags |= CallDescriptor::kHasExceptionHandler;
683 buffer.instruction_args.push_back(g.Label(handler)); 682 buffer.instruction_args.push_back(g.Label(handler));
684 } 683 }
685 684
686 // Select the appropriate opcode based on the call type. 685 // Select the appropriate opcode based on the call type.
687 bool is_tail_call = call_mode == TAIL_CALL;
688 InstructionCode opcode; 686 InstructionCode opcode;
689 switch (descriptor->kind()) { 687 switch (descriptor->kind()) {
690 case CallDescriptor::kCallCodeObject: { 688 case CallDescriptor::kCallCodeObject: {
691 opcode = is_tail_call ? kArchTailCallCodeObject : kArchCallCodeObject; 689 opcode = kArchCallCodeObject;
692 break; 690 break;
693 } 691 }
694 case CallDescriptor::kCallJSFunction: 692 case CallDescriptor::kCallJSFunction:
695 opcode = is_tail_call ? kArchTailCallJSFunction : kArchCallJSFunction; 693 opcode = kArchCallJSFunction;
696 break; 694 break;
697 default: 695 default:
698 UNREACHABLE(); 696 UNREACHABLE();
699 return; 697 return;
700 } 698 }
701 opcode |= MiscField::encode(flags); 699 opcode |= MiscField::encode(flags);
702 700
703 // Emit the call instruction. 701 // Emit the call instruction.
704 size_t size = is_tail_call ? 0 : buffer.outputs.size(); 702 size_t const output_count = buffer.outputs.size();
705 InstructionOperand* first_output = 703 auto* outputs = output_count ? &buffer.outputs.front() : nullptr;
706 size > 0 ? &buffer.outputs.front() : nullptr; 704 Emit(opcode, output_count, outputs, buffer.instruction_args.size(),
707 Instruction* call_instr = 705 &buffer.instruction_args.front())->MarkAsCall();
708 Emit(opcode, size, first_output, buffer.instruction_args.size(),
709 &buffer.instruction_args.front());
710 call_instr->MarkAsCall();
711 } 706 }
712 707
713 708
709 void InstructionSelector::VisitTailCall(Node* node) {
710 Mips64OperandGenerator g(this);
711 const CallDescriptor* descriptor = OpParameter<const CallDescriptor*>(node);
712 DCHECK_NE(0, descriptor->flags() & CallDescriptor::kSupportsTailCalls);
713 DCHECK_EQ(0, descriptor->flags() & CallDescriptor::kPatchableCallSite);
714 DCHECK_EQ(0, descriptor->flags() & CallDescriptor::kNeedsNopAfterCall);
715
716 // TODO(turbofan): Relax restriction for stack parameters.
717 if (descriptor->UsesOnlyRegisters() &&
718 descriptor->HasSameReturnLocationsAs(
719 linkage()->GetIncomingDescriptor())) {
720 CallBuffer buffer(zone(), descriptor, nullptr);
721
722 // Compute InstructionOperands for inputs and outputs.
723 InitializeCallBuffer(node, &buffer, true, false);
724
725 DCHECK_EQ(0u, buffer.pushed_nodes.size());
726
727 // Select the appropriate opcode based on the call type.
728 InstructionCode opcode;
729 switch (descriptor->kind()) {
730 case CallDescriptor::kCallCodeObject:
731 opcode = kArchTailCallCodeObject;
732 break;
733 case CallDescriptor::kCallJSFunction:
734 opcode = kArchTailCallJSFunction;
735 break;
736 default:
737 UNREACHABLE();
738 return;
739 }
740 opcode |= MiscField::encode(descriptor->flags());
741
742 // Emit the tailcall instruction.
743 Emit(opcode, 0, nullptr, buffer.instruction_args.size(),
744 &buffer.instruction_args.front());
745 } else {
746 FrameStateDescriptor* frame_state_descriptor =
747 descriptor->NeedsFrameState()
748 ? GetFrameStateDescriptor(
749 node->InputAt(static_cast<int>(descriptor->InputCount())))
750 : nullptr;
751
752 CallBuffer buffer(zone(), descriptor, frame_state_descriptor);
753
754 // Compute InstructionOperands for inputs and outputs.
755 InitializeCallBuffer(node, &buffer, true, false);
756
757 int push_count = buffer.pushed_nodes.size();
758 if (push_count > 0) {
759 Emit(kMips64StackClaim, g.NoOutput(),
760 g.TempImmediate(push_count << kPointerSizeLog2));
761 }
762 int slot = buffer.pushed_nodes.size() - 1;
763 for (Node* node : base::Reversed(buffer.pushed_nodes)) {
764 Emit(kMips64StoreToStackSlot, g.NoOutput(), g.UseRegister(node),
765 g.TempImmediate(slot << kPointerSizeLog2));
766 slot--;
767 }
768
769 // Select the appropriate opcode based on the call type.
770 InstructionCode opcode;
771 switch (descriptor->kind()) {
772 case CallDescriptor::kCallCodeObject: {
773 opcode = kArchCallCodeObject;
774 break;
775 }
776 case CallDescriptor::kCallJSFunction:
777 opcode = kArchCallJSFunction;
778 break;
779 default:
780 UNREACHABLE();
781 return;
782 }
783 opcode |= MiscField::encode(descriptor->flags());
784
785 // Emit the call instruction.
786 size_t const output_count = buffer.outputs.size();
787 auto* outputs = output_count ? &buffer.outputs.front() : nullptr;
788 Emit(opcode, output_count, outputs, buffer.instruction_args.size(),
789 &buffer.instruction_args.front())->MarkAsCall();
790 Emit(kArchRet, 0, nullptr, output_count, outputs);
791 }
792 }
793
794
714 void InstructionSelector::VisitCheckedLoad(Node* node) { 795 void InstructionSelector::VisitCheckedLoad(Node* node) {
715 MachineType rep = RepresentationOf(OpParameter<MachineType>(node)); 796 MachineType rep = RepresentationOf(OpParameter<MachineType>(node));
716 MachineType typ = TypeOf(OpParameter<MachineType>(node)); 797 MachineType typ = TypeOf(OpParameter<MachineType>(node));
717 Mips64OperandGenerator g(this); 798 Mips64OperandGenerator g(this);
718 Node* const buffer = node->InputAt(0); 799 Node* const buffer = node->InputAt(0);
719 Node* const offset = node->InputAt(1); 800 Node* const offset = node->InputAt(1);
720 Node* const length = node->InputAt(2); 801 Node* const length = node->InputAt(2);
721 ArchOpcode opcode; 802 ArchOpcode opcode;
722 switch (rep) { 803 switch (rep) {
723 case kRepWord8: 804 case kRepWord8:
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 InstructionSelector::SupportedMachineOperatorFlags() { 1273 InstructionSelector::SupportedMachineOperatorFlags() {
1193 return MachineOperatorBuilder::kFloat32Abs | 1274 return MachineOperatorBuilder::kFloat32Abs |
1194 MachineOperatorBuilder::kFloat64Abs | 1275 MachineOperatorBuilder::kFloat64Abs |
1195 MachineOperatorBuilder::kFloat64RoundDown | 1276 MachineOperatorBuilder::kFloat64RoundDown |
1196 MachineOperatorBuilder::kFloat64RoundTruncate; 1277 MachineOperatorBuilder::kFloat64RoundTruncate;
1197 } 1278 }
1198 1279
1199 } // namespace compiler 1280 } // namespace compiler
1200 } // namespace internal 1281 } // namespace internal
1201 } // namespace v8 1282 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698