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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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() { | 605 void CodeGenerator::AssembleDeconstructFrame() { |
606 __ movq(rsp, rbp); | 606 __ movq(rsp, rbp); |
607 __ popq(rbp); | 607 __ popq(rbp); |
608 } | 608 } |
609 | 609 |
610 void CodeGenerator::AssembleSetupStackPointer() {} | |
611 | |
612 void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) { | 610 void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) { |
613 int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); | 611 int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); |
614 if (sp_slot_delta > 0) { | 612 if (sp_slot_delta > 0) { |
615 __ addq(rsp, Immediate(sp_slot_delta * kPointerSize)); | 613 __ addq(rsp, Immediate(sp_slot_delta * kPointerSize)); |
616 } | 614 } |
617 frame_access_state()->SetFrameAccessToDefault(); | 615 frame_access_state()->SetFrameAccessToDefault(); |
618 } | 616 } |
619 | 617 |
620 | 618 |
621 void CodeGenerator::AssemblePrepareTailCall(int stack_param_delta) { | 619 void CodeGenerator::AssemblePrepareTailCall(int stack_param_delta) { |
(...skipping 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1938 __ call(deopt_entry, RelocInfo::RUNTIME_ENTRY); | 1936 __ call(deopt_entry, RelocInfo::RUNTIME_ENTRY); |
1939 } | 1937 } |
1940 | 1938 |
1941 | 1939 |
1942 namespace { | 1940 namespace { |
1943 | 1941 |
1944 static const int kQuadWordSize = 16; | 1942 static const int kQuadWordSize = 16; |
1945 | 1943 |
1946 } // namespace | 1944 } // namespace |
1947 | 1945 |
| 1946 void CodeGenerator::FinishFrame(Frame* frame) { |
| 1947 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); |
1948 | 1948 |
1949 void CodeGenerator::AssemblePrologue() { | 1949 const RegList saves_fp = descriptor->CalleeSavedFPRegisters(); |
| 1950 if (saves_fp != 0) { |
| 1951 frame->AlignSavedCalleeRegisterSlots(); |
| 1952 if (saves_fp != 0) { // Save callee-saved XMM registers. |
| 1953 const uint32_t saves_fp_count = base::bits::CountPopulation32(saves_fp); |
| 1954 frame->AllocateSavedCalleeRegisterSlots(saves_fp_count * |
| 1955 (kQuadWordSize / kPointerSize)); |
| 1956 } |
| 1957 } |
| 1958 const RegList saves = descriptor->CalleeSavedRegisters(); |
| 1959 if (saves != 0) { // Save callee-saved registers. |
| 1960 int count = 0; |
| 1961 for (int i = Register::kNumRegisters - 1; i >= 0; i--) { |
| 1962 if (((1 << i) & saves)) { |
| 1963 ++count; |
| 1964 } |
| 1965 } |
| 1966 frame->AllocateSavedCalleeRegisterSlots(count); |
| 1967 } |
| 1968 } |
| 1969 |
| 1970 void CodeGenerator::AssembleConstructFrame() { |
1950 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); | 1971 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); |
1951 if (frame_access_state()->has_frame()) { | 1972 if (frame_access_state()->has_frame()) { |
1952 if (descriptor->IsCFunctionCall()) { | 1973 if (descriptor->IsCFunctionCall()) { |
1953 __ pushq(rbp); | 1974 __ pushq(rbp); |
1954 __ movq(rbp, rsp); | 1975 __ movq(rbp, rsp); |
1955 } else if (descriptor->IsJSFunctionCall()) { | 1976 } else if (descriptor->IsJSFunctionCall()) { |
1956 __ Prologue(this->info()->GeneratePreagedPrologue()); | 1977 __ Prologue(this->info()->GeneratePreagedPrologue()); |
1957 } else { | 1978 } else { |
1958 __ StubPrologue(info()->GetOutputStackFrameType()); | 1979 __ StubPrologue(info()->GetOutputStackFrameType()); |
1959 } | 1980 } |
1960 } | 1981 } |
1961 int stack_shrink_slots = frame()->GetSpillSlotCount(); | 1982 int shrink_slots = frame()->GetSpillSlotCount(); |
| 1983 |
1962 if (info()->is_osr()) { | 1984 if (info()->is_osr()) { |
1963 // TurboFan OSR-compiled functions cannot be entered directly. | 1985 // TurboFan OSR-compiled functions cannot be entered directly. |
1964 __ Abort(kShouldNotDirectlyEnterOsrFunction); | 1986 __ Abort(kShouldNotDirectlyEnterOsrFunction); |
1965 | 1987 |
1966 // Unoptimized code jumps directly to this entrypoint while the unoptimized | 1988 // Unoptimized code jumps directly to this entrypoint while the unoptimized |
1967 // frame is still on the stack. Optimized code uses OSR values directly from | 1989 // frame is still on the stack. Optimized code uses OSR values directly from |
1968 // the unoptimized frame. Thus, all that needs to be done is to allocate the | 1990 // the unoptimized frame. Thus, all that needs to be done is to allocate the |
1969 // remaining stack slots. | 1991 // remaining stack slots. |
1970 if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); | 1992 if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); |
1971 osr_pc_offset_ = __ pc_offset(); | 1993 osr_pc_offset_ = __ pc_offset(); |
1972 stack_shrink_slots -= | 1994 shrink_slots -= static_cast<int>(OsrHelper(info()).UnoptimizedFrameSlots()); |
1973 static_cast<int>(OsrHelper(info()).UnoptimizedFrameSlots()); | |
1974 } | 1995 } |
1975 | 1996 |
1976 const RegList saves_fp = descriptor->CalleeSavedFPRegisters(); | 1997 const RegList saves_fp = descriptor->CalleeSavedFPRegisters(); |
1977 if (saves_fp != 0) { | 1998 if (shrink_slots > 0) { |
1978 stack_shrink_slots += frame()->AlignSavedCalleeRegisterSlots(); | 1999 __ subq(rsp, Immediate(shrink_slots * kPointerSize)); |
1979 } | |
1980 if (stack_shrink_slots > 0) { | |
1981 __ subq(rsp, Immediate(stack_shrink_slots * kPointerSize)); | |
1982 } | 2000 } |
1983 | 2001 |
1984 if (saves_fp != 0) { // Save callee-saved XMM registers. | 2002 if (saves_fp != 0) { // Save callee-saved XMM registers. |
1985 const uint32_t saves_fp_count = base::bits::CountPopulation32(saves_fp); | 2003 const uint32_t saves_fp_count = base::bits::CountPopulation32(saves_fp); |
1986 const int stack_size = saves_fp_count * kQuadWordSize; | 2004 const int stack_size = saves_fp_count * kQuadWordSize; |
1987 // Adjust the stack pointer. | 2005 // Adjust the stack pointer. |
1988 __ subp(rsp, Immediate(stack_size)); | 2006 __ subp(rsp, Immediate(stack_size)); |
1989 // Store the registers on the stack. | 2007 // Store the registers on the stack. |
1990 int slot_idx = 0; | 2008 int slot_idx = 0; |
1991 for (int i = 0; i < XMMRegister::kMaxNumRegisters; i++) { | 2009 for (int i = 0; i < XMMRegister::kMaxNumRegisters; i++) { |
1992 if (!((1 << i) & saves_fp)) continue; | 2010 if (!((1 << i) & saves_fp)) continue; |
1993 __ movdqu(Operand(rsp, kQuadWordSize * slot_idx), | 2011 __ movdqu(Operand(rsp, kQuadWordSize * slot_idx), |
1994 XMMRegister::from_code(i)); | 2012 XMMRegister::from_code(i)); |
1995 slot_idx++; | 2013 slot_idx++; |
1996 } | 2014 } |
1997 frame()->AllocateSavedCalleeRegisterSlots(saves_fp_count * | |
1998 (kQuadWordSize / kPointerSize)); | |
1999 } | 2015 } |
2000 | 2016 |
2001 const RegList saves = descriptor->CalleeSavedRegisters(); | 2017 const RegList saves = descriptor->CalleeSavedRegisters(); |
2002 if (saves != 0) { // Save callee-saved registers. | 2018 if (saves != 0) { // Save callee-saved registers. |
2003 for (int i = Register::kNumRegisters - 1; i >= 0; i--) { | 2019 for (int i = Register::kNumRegisters - 1; i >= 0; i--) { |
2004 if (!((1 << i) & saves)) continue; | 2020 if (!((1 << i) & saves)) continue; |
2005 __ pushq(Register::from_code(i)); | 2021 __ pushq(Register::from_code(i)); |
2006 frame()->AllocateSavedCalleeRegisterSlots(1); | |
2007 } | 2022 } |
2008 } | 2023 } |
2009 } | 2024 } |
2010 | 2025 |
2011 | 2026 |
2012 void CodeGenerator::AssembleReturn() { | 2027 void CodeGenerator::AssembleReturn() { |
2013 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); | 2028 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); |
2014 | 2029 |
2015 // Restore registers. | 2030 // Restore registers. |
2016 const RegList saves = descriptor->CalleeSavedRegisters(); | 2031 const RegList saves = descriptor->CalleeSavedRegisters(); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2272 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; | 2287 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; |
2273 __ Nop(padding_size); | 2288 __ Nop(padding_size); |
2274 } | 2289 } |
2275 } | 2290 } |
2276 | 2291 |
2277 #undef __ | 2292 #undef __ |
2278 | 2293 |
2279 } // namespace compiler | 2294 } // namespace compiler |
2280 } // namespace internal | 2295 } // namespace internal |
2281 } // namespace v8 | 2296 } // namespace v8 |
OLD | NEW |