Commit 97a48c53 authored by chunyang.dai's avatar chunyang.dai Committed by Commit bot

X87: [turbofan] Unify referencing of stack slots

port cbbaf9ea (r30224).

original commit message:

    [turbofan] Unify referencing of stack slots

    Previously, it was not possible to specify StackSlotOperands for all
    slots in both the caller and callee stacks. Specifically, the region
    of the callee's stack including the saved return address, frame
    pointer, function pointer and context pointer could not be addressed
    by the register allocator/gap resolver.

    In preparation for better tail call support, which will use the gap
    resolver to reconcile outgoing parameters, this change makes it
    possible to address all slots on the stack, because slots in the
    previously inaccessible dead zone may become parameter slots for
    outgoing tail calls. All caller stack slots are accessible as they
    were before, with slot -1 corresponding to the last stack
    parameter. Stack slot indices >= 0 access the callee stack, with slot
    0 corresponding to the callee's saved return address, 1 corresponding
    to the saved frame pointer, 2 corresponding to the current function
    context, 3 corresponding to the frame marker/JSFunction, and slots 4
    and above corresponding to spill slots.

    The following changes were specifically     needed:

    * Frame     has been changed to explicitly manage three areas of the
      callee frame, the fixed header, the spill slot area, and the
      callee-saved register area.
    * Conversions from stack slot indices to fp offsets all now go through
      a common bottleneck: OptimizedFrame::StackSlotOffsetRelativeToFp
    * The generation of deoptimization translation tables has been changed
      to support the new stack slot indexing scheme. Crankshaft, which
      doesn't support the new slot numbering in its register allocator,
      must adapt the indexes when creating translation tables.
    * Callee-saved parameters are now kept below spill slots, not above,
      to support saving only the optimal set of used registers, which is
      only known after register allocation is finished and spill slots
      have been allocated.

BUG=

Review URL: https://codereview.chromium.org/1293103003

Cr-Commit-Position: refs/heads/master@{#30292}
parent 8c70c205
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "src/compiler/code-generator-impl.h" #include "src/compiler/code-generator-impl.h"
#include "src/compiler/gap-resolver.h" #include "src/compiler/gap-resolver.h"
#include "src/compiler/node-matchers.h" #include "src/compiler/node-matchers.h"
#include "src/compiler/osr.h"
#include "src/scopes.h" #include "src/scopes.h"
#include "src/x87/assembler-x87.h" #include "src/x87/assembler-x87.h"
#include "src/x87/frames-x87.h" #include "src/x87/frames-x87.h"
...@@ -1530,34 +1531,22 @@ void CodeGenerator::AssembleDeoptimizerCall( ...@@ -1530,34 +1531,22 @@ void CodeGenerator::AssembleDeoptimizerCall(
void CodeGenerator::AssemblePrologue() { void CodeGenerator::AssemblePrologue() {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
int stack_slots = frame()->GetSpillSlotCount();
if (descriptor->kind() == CallDescriptor::kCallAddress) { if (descriptor->kind() == CallDescriptor::kCallAddress) {
// Assemble a prologue similar the to cdecl calling convention. // Assemble a prologue similar the to cdecl calling convention.
__ push(ebp); __ push(ebp);
__ mov(ebp, esp); __ mov(ebp, esp);
const RegList saves = descriptor->CalleeSavedRegisters();
if (saves != 0) { // Save callee-saved registers.
int register_save_area_size = 0;
for (int i = Register::kNumRegisters - 1; i >= 0; i--) {
if (!((1 << i) & saves)) continue;
__ push(Register::from_code(i));
register_save_area_size += kPointerSize;
}
frame()->SetRegisterSaveAreaSize(register_save_area_size);
}
} else if (descriptor->IsJSFunctionCall()) { } else if (descriptor->IsJSFunctionCall()) {
// TODO(turbofan): this prologue is redundant with OSR, but needed for // TODO(turbofan): this prologue is redundant with OSR, but needed for
// code aging. // code aging.
CompilationInfo* info = this->info(); CompilationInfo* info = this->info();
__ Prologue(info->IsCodePreAgingActive()); __ Prologue(info->IsCodePreAgingActive());
frame()->SetRegisterSaveAreaSize(
StandardFrameConstants::kFixedFrameSizeFromFp);
} else if (needs_frame_) { } else if (needs_frame_) {
__ StubPrologue(); __ StubPrologue();
frame()->SetRegisterSaveAreaSize( } else {
StandardFrameConstants::kFixedFrameSizeFromFp); frame()->SetElidedFrameSizeInSlots(kPCOnStackSize / kPointerSize);
} }
int stack_shrink_slots = frame()->GetSpillSlotCount();
if (info()->is_osr()) { if (info()->is_osr()) {
// TurboFan OSR-compiled functions cannot be entered directly. // TurboFan OSR-compiled functions cannot be entered directly.
__ Abort(kShouldNotDirectlyEnterOsrFunction); __ Abort(kShouldNotDirectlyEnterOsrFunction);
...@@ -1570,13 +1559,23 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1570,13 +1559,23 @@ void CodeGenerator::AssemblePrologue() {
osr_pc_offset_ = __ pc_offset(); osr_pc_offset_ = __ pc_offset();
// TODO(titzer): cannot address target function == local #-1 // TODO(titzer): cannot address target function == local #-1
__ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
DCHECK(stack_slots >= frame()->GetOsrStackSlotCount()); stack_shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots();
stack_slots -= frame()->GetOsrStackSlotCount(); }
const RegList saves = descriptor->CalleeSavedRegisters();
if (stack_shrink_slots > 0) {
__ sub(esp, Immediate(stack_shrink_slots * kPointerSize));
} }
if (stack_slots > 0) { if (saves != 0) { // Save callee-saved registers.
// Allocate the stack slots used by this frame. DCHECK(!info()->is_osr());
__ sub(esp, Immediate(stack_slots * kPointerSize)); int pushed = 0;
for (int i = Register::kNumRegisters - 1; i >= 0; i--) {
if (!((1 << i) & saves)) continue;
__ push(Register::from_code(i));
++pushed;
}
frame()->AllocateSavedCalleeRegisterSlots(pushed);
} }
// Initailize FPU state. // Initailize FPU state.
...@@ -1587,28 +1586,20 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1587,28 +1586,20 @@ void CodeGenerator::AssemblePrologue() {
void CodeGenerator::AssembleReturn() { void CodeGenerator::AssembleReturn() {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
int stack_slots = frame()->GetSpillSlotCount();
int pop_count = static_cast<int>(descriptor->StackParameterCount()); int pop_count = static_cast<int>(descriptor->StackParameterCount());
if (descriptor->kind() == CallDescriptor::kCallAddress) { const RegList saves = descriptor->CalleeSavedRegisters();
const RegList saves = descriptor->CalleeSavedRegisters(); // Restore registers.
if (frame()->GetRegisterSaveAreaSize() > 0) { if (saves != 0) {
// Remove this frame's spill slots first. for (int i = 0; i < Register::kNumRegisters; i++) {
if (stack_slots > 0) { if (!((1 << i) & saves)) continue;
__ add(esp, Immediate(stack_slots * kPointerSize)); __ pop(Register::from_code(i));
}
// Restore registers.
if (saves != 0) {
for (int i = 0; i < Register::kNumRegisters; i++) {
if (!((1 << i) & saves)) continue;
__ pop(Register::from_code(i));
}
}
__ pop(ebp); // Pop caller's frame pointer.
} else {
// No saved registers.
__ mov(esp, ebp); // Move stack pointer back to frame pointer.
__ pop(ebp); // Pop caller's frame pointer.
} }
}
if (descriptor->kind() == CallDescriptor::kCallAddress) {
__ mov(esp, ebp); // Move stack pointer back to frame pointer.
__ pop(ebp); // Pop caller's frame pointer.
} else if (descriptor->IsJSFunctionCall() || needs_frame_) { } else if (descriptor->IsJSFunctionCall() || needs_frame_) {
// Canonicalize JSFunction return sites for now. // Canonicalize JSFunction return sites for now.
if (return_label_.is_bound()) { if (return_label_.is_bound()) {
......
...@@ -943,15 +943,23 @@ void LCodeGen::AddToTranslation(LEnvironment* environment, ...@@ -943,15 +943,23 @@ void LCodeGen::AddToTranslation(LEnvironment* environment,
} }
if (op->IsStackSlot()) { if (op->IsStackSlot()) {
int index = op->index();
if (index >= 0) {
index += StandardFrameConstants::kFixedFrameSize / kPointerSize;
}
if (is_tagged) { if (is_tagged) {
translation->StoreStackSlot(op->index()); translation->StoreStackSlot(index);
} else if (is_uint32) { } else if (is_uint32) {
translation->StoreUint32StackSlot(op->index()); translation->StoreUint32StackSlot(index);
} else { } else {
translation->StoreInt32StackSlot(op->index()); translation->StoreInt32StackSlot(index);
} }
} else if (op->IsDoubleStackSlot()) { } else if (op->IsDoubleStackSlot()) {
translation->StoreDoubleStackSlot(op->index()); int index = op->index();
if (index >= 0) {
index += StandardFrameConstants::kFixedFrameSize / kPointerSize;
}
translation->StoreDoubleStackSlot(index);
} else if (op->IsRegister()) { } else if (op->IsRegister()) {
Register reg = ToRegister(op); Register reg = ToRegister(op);
if (is_tagged) { if (is_tagged) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment