| 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 } |
| 609 |
| 610 void CodeGenerator::AssembleSetupStackPointer() {} |
| 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 Loading... |
| 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 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1922 | 1928 |
| 1923 namespace { | 1929 namespace { |
| 1924 | 1930 |
| 1925 static const int kQuadWordSize = 16; | 1931 static const int kQuadWordSize = 16; |
| 1926 | 1932 |
| 1927 } // namespace | 1933 } // namespace |
| 1928 | 1934 |
| 1929 | 1935 |
| 1930 void CodeGenerator::AssemblePrologue() { | 1936 void CodeGenerator::AssemblePrologue() { |
| 1931 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); | 1937 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); |
| 1932 if (frame()->needs_frame()) { | 1938 if (frame_access_state()->has_frame()) { |
| 1933 if (descriptor->IsCFunctionCall()) { | 1939 if (descriptor->IsCFunctionCall()) { |
| 1934 __ pushq(rbp); | 1940 __ pushq(rbp); |
| 1935 __ movq(rbp, rsp); | 1941 __ movq(rbp, rsp); |
| 1936 } else if (descriptor->IsJSFunctionCall()) { | 1942 } else if (descriptor->IsJSFunctionCall()) { |
| 1937 __ Prologue(this->info()->GeneratePreagedPrologue()); | 1943 __ Prologue(this->info()->GeneratePreagedPrologue()); |
| 1938 } else { | 1944 } else { |
| 1939 __ StubPrologue(info()->GetOutputStackFrameType()); | 1945 __ StubPrologue(info()->GetOutputStackFrameType()); |
| 1940 } | 1946 } |
| 1941 } else { | |
| 1942 frame()->SetElidedFrameSizeInSlots(kPCOnStackSize / kPointerSize); | |
| 1943 } | 1947 } |
| 1944 frame_access_state()->SetFrameAccessToDefault(); | |
| 1945 | |
| 1946 int stack_shrink_slots = frame()->GetSpillSlotCount(); | 1948 int stack_shrink_slots = frame()->GetSpillSlotCount(); |
| 1947 if (info()->is_osr()) { | 1949 if (info()->is_osr()) { |
| 1948 // TurboFan OSR-compiled functions cannot be entered directly. | 1950 // TurboFan OSR-compiled functions cannot be entered directly. |
| 1949 __ Abort(kShouldNotDirectlyEnterOsrFunction); | 1951 __ Abort(kShouldNotDirectlyEnterOsrFunction); |
| 1950 | 1952 |
| 1951 // Unoptimized code jumps directly to this entrypoint while the unoptimized | 1953 // Unoptimized code jumps directly to this entrypoint while the unoptimized |
| 1952 // frame is still on the stack. Optimized code uses OSR values directly from | 1954 // 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 | 1955 // the unoptimized frame. Thus, all that needs to be done is to allocate the |
| 1954 // remaining stack slots. | 1956 // remaining stack slots. |
| 1955 if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); | 1957 if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2015 if (!((1 << i) & saves_fp)) continue; | 2017 if (!((1 << i) & saves_fp)) continue; |
| 2016 __ movdqu(XMMRegister::from_code(i), | 2018 __ movdqu(XMMRegister::from_code(i), |
| 2017 Operand(rsp, kQuadWordSize * slot_idx)); | 2019 Operand(rsp, kQuadWordSize * slot_idx)); |
| 2018 slot_idx++; | 2020 slot_idx++; |
| 2019 } | 2021 } |
| 2020 // Adjust the stack pointer. | 2022 // Adjust the stack pointer. |
| 2021 __ addp(rsp, Immediate(stack_size)); | 2023 __ addp(rsp, Immediate(stack_size)); |
| 2022 } | 2024 } |
| 2023 | 2025 |
| 2024 if (descriptor->IsCFunctionCall()) { | 2026 if (descriptor->IsCFunctionCall()) { |
| 2025 __ movq(rsp, rbp); // Move stack pointer back to frame pointer. | 2027 AssembleDeconstructFrame(); |
| 2026 __ popq(rbp); // Pop caller's frame pointer. | 2028 } else if (frame_access_state()->has_frame()) { |
| 2027 } else if (frame()->needs_frame()) { | |
| 2028 // Canonicalize JSFunction return sites for now. | 2029 // Canonicalize JSFunction return sites for now. |
| 2029 if (return_label_.is_bound()) { | 2030 if (return_label_.is_bound()) { |
| 2030 __ jmp(&return_label_); | 2031 __ jmp(&return_label_); |
| 2031 return; | 2032 return; |
| 2032 } else { | 2033 } else { |
| 2033 __ bind(&return_label_); | 2034 __ bind(&return_label_); |
| 2034 __ movq(rsp, rbp); // Move stack pointer back to frame pointer. | 2035 AssembleDeconstructFrame(); |
| 2035 __ popq(rbp); // Pop caller's frame pointer. | |
| 2036 } | 2036 } |
| 2037 } | 2037 } |
| 2038 size_t pop_size = descriptor->StackParameterCount() * kPointerSize; | 2038 size_t pop_size = descriptor->StackParameterCount() * kPointerSize; |
| 2039 // Might need rcx for scratch if pop_size is too big. | 2039 // Might need rcx for scratch if pop_size is too big. |
| 2040 DCHECK_EQ(0u, descriptor->CalleeSavedRegisters() & rcx.bit()); | 2040 DCHECK_EQ(0u, descriptor->CalleeSavedRegisters() & rcx.bit()); |
| 2041 __ Ret(static_cast<int>(pop_size), rcx); | 2041 __ Ret(static_cast<int>(pop_size), rcx); |
| 2042 } | 2042 } |
| 2043 | 2043 |
| 2044 | 2044 |
| 2045 void CodeGenerator::AssembleMove(InstructionOperand* source, | 2045 void CodeGenerator::AssembleMove(InstructionOperand* source, |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2245 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; | 2245 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; |
| 2246 __ Nop(padding_size); | 2246 __ Nop(padding_size); |
| 2247 } | 2247 } |
| 2248 } | 2248 } |
| 2249 | 2249 |
| 2250 #undef __ | 2250 #undef __ |
| 2251 | 2251 |
| 2252 } // namespace compiler | 2252 } // namespace compiler |
| 2253 } // namespace internal | 2253 } // namespace internal |
| 2254 } // namespace v8 | 2254 } // namespace v8 |
| OLD | NEW |