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

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

Issue 1843143002: [turbofan] CodeGenerator: Frame setup refactoring (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1925 __ call(deopt_entry, RelocInfo::RUNTIME_ENTRY); 1923 __ call(deopt_entry, RelocInfo::RUNTIME_ENTRY);
1926 } 1924 }
1927 1925
1928 1926
1929 namespace { 1927 namespace {
1930 1928
1931 static const int kQuadWordSize = 16; 1929 static const int kQuadWordSize = 16;
1932 1930
1933 } // namespace 1931 } // namespace
1934 1932
1933 void CodeGenerator::FinishFrame(Frame* frame) {
1934 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
1935 int stack_shrink_slots = frame->GetSpillSlotCount();
1936 if (info()->is_osr()) {
1937 stack_shrink_slots -=
1938 static_cast<int>(OsrHelper(info()).UnoptimizedFrameSlots());
1939 }
1940 const RegList saves_fp = descriptor->CalleeSavedFPRegisters();
1941 if (saves_fp != 0) {
1942 stack_shrink_slots += frame->AlignSavedCalleeRegisterSlots();
1943 if (saves_fp != 0) { // Save callee-saved XMM registers.
1944 const uint32_t saves_fp_count = base::bits::CountPopulation32(saves_fp);
1945 frame->AllocateSavedCalleeRegisterSlots(saves_fp_count *
1946 (kQuadWordSize / kPointerSize));
1947 }
1948 }
1949 const RegList saves = descriptor->CalleeSavedRegisters();
1950 if (saves != 0) { // Save callee-saved registers.
1951 int count = 0;
1952 for (int i = Register::kNumRegisters - 1; i >= 0; i--) {
1953 if (((1 << i) & saves)) {
1954 ++count;
1955 }
1956 }
1957 frame->AllocateSavedCalleeRegisterSlots(count);
1958 }
1959 frame->set_stack_shrink_slots(stack_shrink_slots);
1960 }
1935 1961
1936 void CodeGenerator::AssemblePrologue() { 1962 void CodeGenerator::AssembleConstructFrame() {
1937 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); 1963 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
1938 if (frame_access_state()->has_frame()) { 1964 if (frame_access_state()->has_frame()) {
1939 if (descriptor->IsCFunctionCall()) { 1965 if (descriptor->IsCFunctionCall()) {
1940 __ pushq(rbp); 1966 __ pushq(rbp);
1941 __ movq(rbp, rsp); 1967 __ movq(rbp, rsp);
1942 } else if (descriptor->IsJSFunctionCall()) { 1968 } else if (descriptor->IsJSFunctionCall()) {
1943 __ Prologue(this->info()->GeneratePreagedPrologue()); 1969 __ Prologue(this->info()->GeneratePreagedPrologue());
1944 } else { 1970 } else {
1945 __ StubPrologue(info()->GetOutputStackFrameType()); 1971 __ StubPrologue(info()->GetOutputStackFrameType());
1946 } 1972 }
1947 } 1973 }
1948 int stack_shrink_slots = frame()->GetSpillSlotCount();
1949 if (info()->is_osr()) { 1974 if (info()->is_osr()) {
1950 // TurboFan OSR-compiled functions cannot be entered directly. 1975 // TurboFan OSR-compiled functions cannot be entered directly.
1951 __ Abort(kShouldNotDirectlyEnterOsrFunction); 1976 __ Abort(kShouldNotDirectlyEnterOsrFunction);
1952 1977
1953 // Unoptimized code jumps directly to this entrypoint while the unoptimized 1978 // Unoptimized code jumps directly to this entrypoint while the unoptimized
1954 // frame is still on the stack. Optimized code uses OSR values directly from 1979 // frame is still on the stack. Optimized code uses OSR values directly from
1955 // the unoptimized frame. Thus, all that needs to be done is to allocate the 1980 // the unoptimized frame. Thus, all that needs to be done is to allocate the
1956 // remaining stack slots. 1981 // remaining stack slots.
1957 if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); 1982 if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
1958 osr_pc_offset_ = __ pc_offset(); 1983 osr_pc_offset_ = __ pc_offset();
1959 stack_shrink_slots -=
1960 static_cast<int>(OsrHelper(info()).UnoptimizedFrameSlots());
1961 } 1984 }
1962 1985
1963 const RegList saves_fp = descriptor->CalleeSavedFPRegisters(); 1986 const RegList saves_fp = descriptor->CalleeSavedFPRegisters();
1964 if (saves_fp != 0) { 1987 if (frame()->stack_shrink_slots() > 0) {
1965 stack_shrink_slots += frame()->AlignSavedCalleeRegisterSlots(); 1988 __ subq(rsp, Immediate(frame()->stack_shrink_slots() * kPointerSize));
1966 }
1967 if (stack_shrink_slots > 0) {
1968 __ subq(rsp, Immediate(stack_shrink_slots * kPointerSize));
1969 } 1989 }
1970 1990
1971 if (saves_fp != 0) { // Save callee-saved XMM registers. 1991 if (saves_fp != 0) { // Save callee-saved XMM registers.
1972 const uint32_t saves_fp_count = base::bits::CountPopulation32(saves_fp); 1992 const uint32_t saves_fp_count = base::bits::CountPopulation32(saves_fp);
1973 const int stack_size = saves_fp_count * kQuadWordSize; 1993 const int stack_size = saves_fp_count * kQuadWordSize;
1974 // Adjust the stack pointer. 1994 // Adjust the stack pointer.
1975 __ subp(rsp, Immediate(stack_size)); 1995 __ subp(rsp, Immediate(stack_size));
1976 // Store the registers on the stack. 1996 // Store the registers on the stack.
1977 int slot_idx = 0; 1997 int slot_idx = 0;
1978 for (int i = 0; i < XMMRegister::kMaxNumRegisters; i++) { 1998 for (int i = 0; i < XMMRegister::kMaxNumRegisters; i++) {
1979 if (!((1 << i) & saves_fp)) continue; 1999 if (!((1 << i) & saves_fp)) continue;
1980 __ movdqu(Operand(rsp, kQuadWordSize * slot_idx), 2000 __ movdqu(Operand(rsp, kQuadWordSize * slot_idx),
1981 XMMRegister::from_code(i)); 2001 XMMRegister::from_code(i));
1982 slot_idx++; 2002 slot_idx++;
1983 } 2003 }
1984 frame()->AllocateSavedCalleeRegisterSlots(saves_fp_count *
1985 (kQuadWordSize / kPointerSize));
1986 } 2004 }
1987 2005
1988 const RegList saves = descriptor->CalleeSavedRegisters(); 2006 const RegList saves = descriptor->CalleeSavedRegisters();
1989 if (saves != 0) { // Save callee-saved registers. 2007 if (saves != 0) { // Save callee-saved registers.
1990 for (int i = Register::kNumRegisters - 1; i >= 0; i--) { 2008 for (int i = Register::kNumRegisters - 1; i >= 0; i--) {
1991 if (!((1 << i) & saves)) continue; 2009 if (!((1 << i) & saves)) continue;
1992 __ pushq(Register::from_code(i)); 2010 __ pushq(Register::from_code(i));
1993 frame()->AllocateSavedCalleeRegisterSlots(1);
1994 } 2011 }
1995 } 2012 }
1996 } 2013 }
1997 2014
1998 2015
1999 void CodeGenerator::AssembleReturn() { 2016 void CodeGenerator::AssembleReturn() {
2000 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); 2017 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
2001 2018
2002 // Restore registers. 2019 // Restore registers.
2003 const RegList saves = descriptor->CalleeSavedRegisters(); 2020 const RegList saves = descriptor->CalleeSavedRegisters();
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
2245 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; 2262 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc;
2246 __ Nop(padding_size); 2263 __ Nop(padding_size);
2247 } 2264 }
2248 } 2265 }
2249 2266
2250 #undef __ 2267 #undef __
2251 2268
2252 } // namespace compiler 2269 } // namespace compiler
2253 } // namespace internal 2270 } // namespace internal
2254 } // namespace v8 2271 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698