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

Side by Side Diff: src/compiler/x64/code-generator-x64.cc

Issue 1775323002: [turbofan] Frame elision for code stubs (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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/compiler/code-generator.h" 5 #include "src/compiler/code-generator.h"
6 6
7 #include "src/ast/scopes.h" 7 #include "src/ast/scopes.h"
8 #include "src/compiler/code-generator-impl.h" 8 #include "src/compiler/code-generator-impl.h"
9 #include "src/compiler/gap-resolver.h" 9 #include "src/compiler/gap-resolver.h"
10 #include "src/compiler/node-matchers.h" 10 #include "src/compiler/node-matchers.h"
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 do { \ 595 do { \
596 if (instr->InputAt(4)->IsRegister()) { \ 596 if (instr->InputAt(4)->IsRegister()) { \
597 Register value = i.InputRegister(4); \ 597 Register value = i.InputRegister(4); \
598 ASSEMBLE_CHECKED_STORE_INTEGER_IMPL(asm_instr, Register); \ 598 ASSEMBLE_CHECKED_STORE_INTEGER_IMPL(asm_instr, Register); \
599 } else { \ 599 } else { \
600 Immediate value = i.InputImmediate(4); \ 600 Immediate value = i.InputImmediate(4); \
601 ASSEMBLE_CHECKED_STORE_INTEGER_IMPL(asm_instr, Immediate); \ 601 ASSEMBLE_CHECKED_STORE_INTEGER_IMPL(asm_instr, Immediate); \
602 } \ 602 } \
603 } while (false) 603 } while (false)
604 604
605 void CodeGenerator::AssembleDeconstructFrame() {
606 __ movq(rsp, rbp);
607 __ popq(rbp);
608 }
609
610 void CodeGenerator::SetupStackPointer() {}
605 611
606 void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) { 612 void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) {
607 int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); 613 int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta);
608 if (sp_slot_delta > 0) { 614 if (sp_slot_delta > 0) {
609 __ addq(rsp, Immediate(sp_slot_delta * kPointerSize)); 615 __ addq(rsp, Immediate(sp_slot_delta * kPointerSize));
610 } 616 }
611 frame_access_state()->SetFrameAccessToDefault(); 617 frame_access_state()->SetFrameAccessToDefault();
612 } 618 }
613 619
614 620
615 void CodeGenerator::AssemblePrepareTailCall(int stack_param_delta) { 621 void CodeGenerator::AssemblePrepareTailCall(int stack_param_delta) {
616 int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); 622 int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta);
617 if (sp_slot_delta < 0) { 623 if (sp_slot_delta < 0) {
618 __ subq(rsp, Immediate(-sp_slot_delta * kPointerSize)); 624 __ subq(rsp, Immediate(-sp_slot_delta * kPointerSize));
619 frame_access_state()->IncreaseSPDelta(-sp_slot_delta); 625 frame_access_state()->IncreaseSPDelta(-sp_slot_delta);
620 } 626 }
621 if (frame()->needs_frame()) { 627 if (frame_access_state()->has_frame()) {
622 __ movq(rbp, MemOperand(rbp, 0)); 628 __ movq(rbp, MemOperand(rbp, 0));
623 } 629 }
624 frame_access_state()->SetFrameAccessToSP(); 630 frame_access_state()->SetFrameAccessToSP();
625 } 631 }
626 632
627 void CodeGenerator::AssemblePopArgumentsAdaptorFrame(Register args_reg, 633 void CodeGenerator::AssemblePopArgumentsAdaptorFrame(Register args_reg,
628 Register scratch1, 634 Register scratch1,
629 Register scratch2, 635 Register scratch2,
630 Register scratch3) { 636 Register scratch3) {
631 DCHECK(!AreAliased(args_reg, scratch1, scratch2, scratch3)); 637 DCHECK(!AreAliased(args_reg, scratch1, scratch2, scratch3));
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 case kArchRet: 774 case kArchRet:
769 AssembleReturn(); 775 AssembleReturn();
770 break; 776 break;
771 case kArchStackPointer: 777 case kArchStackPointer:
772 __ movq(i.OutputRegister(), rsp); 778 __ movq(i.OutputRegister(), rsp);
773 break; 779 break;
774 case kArchFramePointer: 780 case kArchFramePointer:
775 __ movq(i.OutputRegister(), rbp); 781 __ movq(i.OutputRegister(), rbp);
776 break; 782 break;
777 case kArchParentFramePointer: 783 case kArchParentFramePointer:
778 if (frame_access_state()->frame()->needs_frame()) { 784 if (frame_access_state()->has_frame()) {
779 __ movq(i.OutputRegister(), Operand(rbp, 0)); 785 __ movq(i.OutputRegister(), Operand(rbp, 0));
780 } else { 786 } else {
781 __ movq(i.OutputRegister(), rbp); 787 __ movq(i.OutputRegister(), rbp);
782 } 788 }
783 break; 789 break;
784 case kArchTruncateDoubleToI: { 790 case kArchTruncateDoubleToI: {
785 auto result = i.OutputRegister(); 791 auto result = i.OutputRegister();
786 auto input = i.InputDoubleRegister(0); 792 auto input = i.InputDoubleRegister(0);
787 auto ool = new (zone()) OutOfLineTruncateDoubleToI(this, result, input); 793 auto ool = new (zone()) OutOfLineTruncateDoubleToI(this, result, input);
788 __ Cvttsd2siq(result, input); 794 __ Cvttsd2siq(result, input);
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 break; 1753 break;
1748 case kX64StackCheck: 1754 case kX64StackCheck:
1749 __ CompareRoot(rsp, Heap::kStackLimitRootIndex); 1755 __ CompareRoot(rsp, Heap::kStackLimitRootIndex);
1750 break; 1756 break;
1751 } 1757 }
1752 } // NOLINT(readability/fn_size) 1758 } // NOLINT(readability/fn_size)
1753 1759
1754 1760
1755 // Assembles branches after this instruction. 1761 // Assembles branches after this instruction.
1756 void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) { 1762 void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) {
1763 AssembleDeconstructFrameIfNeeded();
1757 X64OperandConverter i(this, instr); 1764 X64OperandConverter i(this, instr);
1758 Label::Distance flabel_distance = 1765 Label::Distance flabel_distance =
1759 branch->fallthru ? Label::kNear : Label::kFar; 1766 branch->fallthru ? Label::kNear : Label::kFar;
1760 Label* tlabel = branch->true_label; 1767 Label* tlabel = branch->true_label;
1761 Label* flabel = branch->false_label; 1768 Label* flabel = branch->false_label;
1762 switch (branch->condition) { 1769 switch (branch->condition) {
1763 case kUnorderedEqual: 1770 case kUnorderedEqual:
1764 __ j(parity_even, flabel, flabel_distance); 1771 __ j(parity_even, flabel, flabel_distance);
1765 // Fall through. 1772 // Fall through.
1766 case kEqual: 1773 case kEqual:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 break; 1811 break;
1805 default: 1812 default:
1806 UNREACHABLE(); 1813 UNREACHABLE();
1807 break; 1814 break;
1808 } 1815 }
1809 if (!branch->fallthru) __ jmp(flabel, flabel_distance); 1816 if (!branch->fallthru) __ jmp(flabel, flabel_distance);
1810 } 1817 }
1811 1818
1812 1819
1813 void CodeGenerator::AssembleArchJump(RpoNumber target) { 1820 void CodeGenerator::AssembleArchJump(RpoNumber target) {
1821 AssembleDeconstructFrameIfNeeded();
1814 if (!IsNextInAssemblyOrder(target)) __ jmp(GetLabel(target)); 1822 if (!IsNextInAssemblyOrder(target)) __ jmp(GetLabel(target));
1815 } 1823 }
1816 1824
1817 1825
1818 // Assembles boolean materializations after this instruction. 1826 // Assembles boolean materializations after this instruction.
1819 void CodeGenerator::AssembleArchBoolean(Instruction* instr, 1827 void CodeGenerator::AssembleArchBoolean(Instruction* instr,
1820 FlagsCondition condition) { 1828 FlagsCondition condition) {
1821 X64OperandConverter i(this, instr); 1829 X64OperandConverter i(this, instr);
1822 Label done; 1830 Label done;
1823 1831
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 1930
1923 namespace { 1931 namespace {
1924 1932
1925 static const int kQuadWordSize = 16; 1933 static const int kQuadWordSize = 16;
1926 1934
1927 } // namespace 1935 } // namespace
1928 1936
1929 1937
1930 void CodeGenerator::AssemblePrologue() { 1938 void CodeGenerator::AssemblePrologue() {
1931 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); 1939 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
1932 if (frame()->needs_frame()) { 1940 if (frame_access_state()->has_frame()) {
1933 if (descriptor->IsCFunctionCall()) { 1941 if (descriptor->IsCFunctionCall()) {
1934 __ pushq(rbp); 1942 __ pushq(rbp);
1935 __ movq(rbp, rsp); 1943 __ movq(rbp, rsp);
1936 } else if (descriptor->IsJSFunctionCall()) { 1944 } else if (descriptor->IsJSFunctionCall()) {
1937 __ Prologue(this->info()->GeneratePreagedPrologue()); 1945 __ Prologue(this->info()->GeneratePreagedPrologue());
1938 } else { 1946 } else {
1939 __ StubPrologue(info()->GetOutputStackFrameType()); 1947 __ StubPrologue(info()->GetOutputStackFrameType());
1940 } 1948 }
1941 } else {
1942 frame()->SetElidedFrameSizeInSlots(kPCOnStackSize / kPointerSize);
1943 } 1949 }
1944 frame_access_state()->SetFrameAccessToDefault();
1945
1946 int stack_shrink_slots = frame()->GetSpillSlotCount(); 1950 int stack_shrink_slots = frame()->GetSpillSlotCount();
1947 if (info()->is_osr()) { 1951 if (info()->is_osr()) {
1948 // TurboFan OSR-compiled functions cannot be entered directly. 1952 // TurboFan OSR-compiled functions cannot be entered directly.
1949 __ Abort(kShouldNotDirectlyEnterOsrFunction); 1953 __ Abort(kShouldNotDirectlyEnterOsrFunction);
1950 1954
1951 // Unoptimized code jumps directly to this entrypoint while the unoptimized 1955 // Unoptimized code jumps directly to this entrypoint while the unoptimized
1952 // frame is still on the stack. Optimized code uses OSR values directly from 1956 // frame is still on the stack. Optimized code uses OSR values directly from
1953 // the unoptimized frame. Thus, all that needs to be done is to allocate the 1957 // the unoptimized frame. Thus, all that needs to be done is to allocate the
1954 // remaining stack slots. 1958 // remaining stack slots.
1955 if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); 1959 if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2015 if (!((1 << i) & saves_fp)) continue; 2019 if (!((1 << i) & saves_fp)) continue;
2016 __ movdqu(XMMRegister::from_code(i), 2020 __ movdqu(XMMRegister::from_code(i),
2017 Operand(rsp, kQuadWordSize * slot_idx)); 2021 Operand(rsp, kQuadWordSize * slot_idx));
2018 slot_idx++; 2022 slot_idx++;
2019 } 2023 }
2020 // Adjust the stack pointer. 2024 // Adjust the stack pointer.
2021 __ addp(rsp, Immediate(stack_size)); 2025 __ addp(rsp, Immediate(stack_size));
2022 } 2026 }
2023 2027
2024 if (descriptor->IsCFunctionCall()) { 2028 if (descriptor->IsCFunctionCall()) {
2025 __ movq(rsp, rbp); // Move stack pointer back to frame pointer. 2029 AssembleDeconstructFrameIfNeeded();
2026 __ popq(rbp); // Pop caller's frame pointer. 2030 } else if (frame_access_state()->has_frame()) {
2027 } else if (frame()->needs_frame()) { 2031 if (AssembleDeconstructFrameUsingReturnLabel()) return;
2028 // Canonicalize JSFunction return sites for now.
2029 if (return_label_.is_bound()) {
2030 __ jmp(&return_label_);
2031 return;
2032 } else {
2033 __ bind(&return_label_);
2034 __ movq(rsp, rbp); // Move stack pointer back to frame pointer.
2035 __ popq(rbp); // Pop caller's frame pointer.
2036 }
2037 } 2032 }
2038 size_t pop_size = descriptor->StackParameterCount() * kPointerSize; 2033 size_t pop_size = descriptor->StackParameterCount() * kPointerSize;
2039 // Might need rcx for scratch if pop_size is too big. 2034 // Might need rcx for scratch if pop_size is too big.
2040 DCHECK_EQ(0u, descriptor->CalleeSavedRegisters() & rcx.bit()); 2035 DCHECK_EQ(0u, descriptor->CalleeSavedRegisters() & rcx.bit());
2041 __ Ret(static_cast<int>(pop_size), rcx); 2036 __ Ret(static_cast<int>(pop_size), rcx);
2042 } 2037 }
2043 2038
2044 2039
2045 void CodeGenerator::AssembleMove(InstructionOperand* source, 2040 void CodeGenerator::AssembleMove(InstructionOperand* source,
2046 InstructionOperand* destination) { 2041 InstructionOperand* destination) {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
2245 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; 2240 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc;
2246 __ Nop(padding_size); 2241 __ Nop(padding_size);
2247 } 2242 }
2248 } 2243 }
2249 2244
2250 #undef __ 2245 #undef __
2251 2246
2252 } // namespace compiler 2247 } // namespace compiler
2253 } // namespace internal 2248 } // namespace internal
2254 } // namespace v8 2249 } // namespace v8
OLDNEW
« src/compiler/frame.h ('K') | « src/compiler/register-allocator.cc ('k') | src/globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698