OLD | NEW |
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 Loading... |
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 } |
605 | 609 |
606 void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) { | 610 void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) { |
607 int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); | 611 int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); |
608 if (sp_slot_delta > 0) { | 612 if (sp_slot_delta > 0) { |
609 __ addq(rsp, Immediate(sp_slot_delta * kPointerSize)); | 613 __ addq(rsp, Immediate(sp_slot_delta * kPointerSize)); |
610 } | 614 } |
611 frame_access_state()->SetFrameAccessToDefault(); | 615 frame_access_state()->SetFrameAccessToDefault(); |
612 } | 616 } |
613 | 617 |
614 | 618 |
615 void CodeGenerator::AssemblePrepareTailCall(int stack_param_delta) { | 619 void CodeGenerator::AssemblePrepareTailCall(int stack_param_delta) { |
616 int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); | 620 int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); |
617 if (sp_slot_delta < 0) { | 621 if (sp_slot_delta < 0) { |
618 __ subq(rsp, Immediate(-sp_slot_delta * kPointerSize)); | 622 __ subq(rsp, Immediate(-sp_slot_delta * kPointerSize)); |
619 frame_access_state()->IncreaseSPDelta(-sp_slot_delta); | 623 frame_access_state()->IncreaseSPDelta(-sp_slot_delta); |
620 } | 624 } |
621 if (frame()->needs_frame()) { | 625 if (frame_access_state()->access_frame_with_fp()) { |
622 __ movq(rbp, MemOperand(rbp, 0)); | 626 __ movq(rbp, MemOperand(rbp, 0)); |
623 } | 627 } |
624 frame_access_state()->SetFrameAccessToSP(); | 628 frame_access_state()->SetFrameAccessToSP(); |
625 } | 629 } |
626 | 630 |
627 void CodeGenerator::AssemblePopArgumentsAdaptorFrame(Register args_reg, | 631 void CodeGenerator::AssemblePopArgumentsAdaptorFrame(Register args_reg, |
628 Register scratch1, | 632 Register scratch1, |
629 Register scratch2, | 633 Register scratch2, |
630 Register scratch3) { | 634 Register scratch3) { |
631 DCHECK(!AreAliased(args_reg, scratch1, scratch2, scratch3)); | 635 DCHECK(!AreAliased(args_reg, scratch1, scratch2, scratch3)); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 case kArchRet: | 772 case kArchRet: |
769 AssembleReturn(); | 773 AssembleReturn(); |
770 break; | 774 break; |
771 case kArchStackPointer: | 775 case kArchStackPointer: |
772 __ movq(i.OutputRegister(), rsp); | 776 __ movq(i.OutputRegister(), rsp); |
773 break; | 777 break; |
774 case kArchFramePointer: | 778 case kArchFramePointer: |
775 __ movq(i.OutputRegister(), rbp); | 779 __ movq(i.OutputRegister(), rbp); |
776 break; | 780 break; |
777 case kArchParentFramePointer: | 781 case kArchParentFramePointer: |
778 if (frame_access_state()->frame()->needs_frame()) { | 782 if (frame_access_state()->access_frame_with_fp()) { |
779 __ movq(i.OutputRegister(), Operand(rbp, 0)); | 783 __ movq(i.OutputRegister(), Operand(rbp, 0)); |
780 } else { | 784 } else { |
781 __ movq(i.OutputRegister(), rbp); | 785 __ movq(i.OutputRegister(), rbp); |
782 } | 786 } |
783 break; | 787 break; |
784 case kArchTruncateDoubleToI: { | 788 case kArchTruncateDoubleToI: { |
785 auto result = i.OutputRegister(); | 789 auto result = i.OutputRegister(); |
786 auto input = i.InputDoubleRegister(0); | 790 auto input = i.InputDoubleRegister(0); |
787 auto ool = new (zone()) OutOfLineTruncateDoubleToI(this, result, input); | 791 auto ool = new (zone()) OutOfLineTruncateDoubleToI(this, result, input); |
788 __ Cvttsd2siq(result, input); | 792 __ Cvttsd2siq(result, input); |
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1792 break; | 1796 break; |
1793 default: | 1797 default: |
1794 UNREACHABLE(); | 1798 UNREACHABLE(); |
1795 break; | 1799 break; |
1796 } | 1800 } |
1797 if (!branch->fallthru) __ jmp(flabel, flabel_distance); | 1801 if (!branch->fallthru) __ jmp(flabel, flabel_distance); |
1798 } | 1802 } |
1799 | 1803 |
1800 | 1804 |
1801 void CodeGenerator::AssembleArchJump(RpoNumber target) { | 1805 void CodeGenerator::AssembleArchJump(RpoNumber target) { |
| 1806 AssembleDeconstructFrameBetweenBlocks(); |
1802 if (!IsNextInAssemblyOrder(target)) __ jmp(GetLabel(target)); | 1807 if (!IsNextInAssemblyOrder(target)) __ jmp(GetLabel(target)); |
1803 } | 1808 } |
1804 | 1809 |
1805 | 1810 |
1806 // Assembles boolean materializations after this instruction. | 1811 // Assembles boolean materializations after this instruction. |
1807 void CodeGenerator::AssembleArchBoolean(Instruction* instr, | 1812 void CodeGenerator::AssembleArchBoolean(Instruction* instr, |
1808 FlagsCondition condition) { | 1813 FlagsCondition condition) { |
1809 X64OperandConverter i(this, instr); | 1814 X64OperandConverter i(this, instr); |
1810 Label done; | 1815 Label done; |
1811 | 1816 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1910 | 1915 |
1911 namespace { | 1916 namespace { |
1912 | 1917 |
1913 static const int kQuadWordSize = 16; | 1918 static const int kQuadWordSize = 16; |
1914 | 1919 |
1915 } // namespace | 1920 } // namespace |
1916 | 1921 |
1917 | 1922 |
1918 void CodeGenerator::AssemblePrologue() { | 1923 void CodeGenerator::AssemblePrologue() { |
1919 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); | 1924 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); |
1920 if (frame()->needs_frame()) { | 1925 if (frame_access_state()->access_frame_with_fp()) { |
1921 if (descriptor->IsCFunctionCall()) { | 1926 if (descriptor->IsCFunctionCall()) { |
1922 __ pushq(rbp); | 1927 __ pushq(rbp); |
1923 __ movq(rbp, rsp); | 1928 __ movq(rbp, rsp); |
1924 } else if (descriptor->IsJSFunctionCall()) { | 1929 } else if (descriptor->IsJSFunctionCall()) { |
1925 __ Prologue(this->info()->GeneratePreagedPrologue()); | 1930 __ Prologue(this->info()->GeneratePreagedPrologue()); |
1926 } else { | 1931 } else { |
1927 __ StubPrologue(info()->GetOutputStackFrameType()); | 1932 __ StubPrologue(info()->GetOutputStackFrameType()); |
1928 } | 1933 } |
1929 } else { | |
1930 frame()->SetElidedFrameSizeInSlots(kPCOnStackSize / kPointerSize); | |
1931 } | 1934 } |
1932 frame_access_state()->SetFrameAccessToDefault(); | |
1933 | |
1934 int stack_shrink_slots = frame()->GetSpillSlotCount(); | 1935 int stack_shrink_slots = frame()->GetSpillSlotCount(); |
1935 if (info()->is_osr()) { | 1936 if (info()->is_osr()) { |
1936 // TurboFan OSR-compiled functions cannot be entered directly. | 1937 // TurboFan OSR-compiled functions cannot be entered directly. |
1937 __ Abort(kShouldNotDirectlyEnterOsrFunction); | 1938 __ Abort(kShouldNotDirectlyEnterOsrFunction); |
1938 | 1939 |
1939 // Unoptimized code jumps directly to this entrypoint while the unoptimized | 1940 // Unoptimized code jumps directly to this entrypoint while the unoptimized |
1940 // frame is still on the stack. Optimized code uses OSR values directly from | 1941 // frame is still on the stack. Optimized code uses OSR values directly from |
1941 // the unoptimized frame. Thus, all that needs to be done is to allocate the | 1942 // the unoptimized frame. Thus, all that needs to be done is to allocate the |
1942 // remaining stack slots. | 1943 // remaining stack slots. |
1943 if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); | 1944 if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2003 if (!((1 << i) & saves_fp)) continue; | 2004 if (!((1 << i) & saves_fp)) continue; |
2004 __ movdqu(XMMRegister::from_code(i), | 2005 __ movdqu(XMMRegister::from_code(i), |
2005 Operand(rsp, kQuadWordSize * slot_idx)); | 2006 Operand(rsp, kQuadWordSize * slot_idx)); |
2006 slot_idx++; | 2007 slot_idx++; |
2007 } | 2008 } |
2008 // Adjust the stack pointer. | 2009 // Adjust the stack pointer. |
2009 __ addp(rsp, Immediate(stack_size)); | 2010 __ addp(rsp, Immediate(stack_size)); |
2010 } | 2011 } |
2011 | 2012 |
2012 if (descriptor->IsCFunctionCall()) { | 2013 if (descriptor->IsCFunctionCall()) { |
2013 __ movq(rsp, rbp); // Move stack pointer back to frame pointer. | 2014 AssembleDeconstructFrameWhenLeaving(); |
2014 __ popq(rbp); // Pop caller's frame pointer. | 2015 } else if (frame_access_state()->access_frame_with_fp()) { |
2015 } else if (frame()->needs_frame()) { | |
2016 // Canonicalize JSFunction return sites for now. | 2016 // Canonicalize JSFunction return sites for now. |
2017 if (return_label_.is_bound()) { | 2017 if (return_label_.is_bound()) { |
| 2018 AssembleDeconstructFrameBetweenBlocks(); |
2018 __ jmp(&return_label_); | 2019 __ jmp(&return_label_); |
2019 return; | 2020 return; |
2020 } else { | 2021 } else { |
2021 __ bind(&return_label_); | 2022 __ bind(&return_label_); |
2022 __ movq(rsp, rbp); // Move stack pointer back to frame pointer. | 2023 AssembleDeconstructFrameWhenLeaving(); |
2023 __ popq(rbp); // Pop caller's frame pointer. | |
2024 } | 2024 } |
2025 } | 2025 } |
2026 size_t pop_size = descriptor->StackParameterCount() * kPointerSize; | 2026 size_t pop_size = descriptor->StackParameterCount() * kPointerSize; |
2027 // Might need rcx for scratch if pop_size is too big. | 2027 // Might need rcx for scratch if pop_size is too big. |
2028 DCHECK_EQ(0u, descriptor->CalleeSavedRegisters() & rcx.bit()); | 2028 DCHECK_EQ(0u, descriptor->CalleeSavedRegisters() & rcx.bit()); |
2029 __ Ret(static_cast<int>(pop_size), rcx); | 2029 __ Ret(static_cast<int>(pop_size), rcx); |
2030 } | 2030 } |
2031 | 2031 |
2032 | 2032 |
2033 void CodeGenerator::AssembleMove(InstructionOperand* source, | 2033 void CodeGenerator::AssembleMove(InstructionOperand* source, |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2233 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; | 2233 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; |
2234 __ Nop(padding_size); | 2234 __ Nop(padding_size); |
2235 } | 2235 } |
2236 } | 2236 } |
2237 | 2237 |
2238 #undef __ | 2238 #undef __ |
2239 | 2239 |
2240 } // namespace compiler | 2240 } // namespace compiler |
2241 } // namespace internal | 2241 } // namespace internal |
2242 } // namespace v8 | 2242 } // namespace v8 |
OLD | NEW |