Commit a9cb48bf authored by bjaideep's avatar bjaideep Committed by Commit bot

PPC: [turbofan] CodeGenerator: Frame setup refactoring

Port 81a1530e

Original commit message:

    Before frame elision, we finalized the frame shape when assembling the
    prologue, which is also when we prepared the frame (saving sp, etc).

    The frame finalization only needs to happen once, and happens to be
    actually a set of idempotent operations. With frame elision, the logic for
    frame finalization was happening every time we constructed the frame.
    Albeit idempotent operations, the code would become hard to maintain.

    This change separates frame shape finalization from frame
    construction. When constructing the CodeGenerator, we finalize the
    frame. Subsequent access is to a const Frame*.

    Also renamed AssemblePrologue to AssembleConstructFrame, as
    suggested in the frame elision CR.

    Separating frame setup gave the opportunity to do away with
    architecture-independent frame aligning (which is something just arm64
    cares about), and also with stack pointer setup (also arm64). Both of
    these happen now at frame finalization on arm64.

R=mtrofin@chromium.org, joransiu@ca.ibm.com, jyan@ca.ibm.com, michael_dawson@ca.ibm.com, mbrandy@us.ibm.com

BUG=
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#35674}
parent 70d2c1cf
......@@ -694,8 +694,6 @@ void CodeGenerator::AssembleDeconstructFrame() {
__ LeaveFrame(StackFrame::MANUAL);
}
void CodeGenerator::AssembleSetupStackPointer() {}
void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) {
int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta);
if (sp_slot_delta > 0) {
......@@ -1754,8 +1752,33 @@ void CodeGenerator::AssembleDeoptimizerCall(
__ Call(deopt_entry, RelocInfo::RUNTIME_ENTRY);
}
void CodeGenerator::FinishFrame(Frame* frame) {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
const RegList double_saves = descriptor->CalleeSavedFPRegisters();
// Save callee-saved Double registers.
if (double_saves != 0) {
frame->AlignSavedCalleeRegisterSlots();
DCHECK(kNumCalleeSavedDoubles ==
base::bits::CountPopulation32(double_saves));
frame->AllocateSavedCalleeRegisterSlots(kNumCalleeSavedDoubles *
(kDoubleSize / kPointerSize));
}
// Save callee-saved registers.
const RegList saves =
FLAG_enable_embedded_constant_pool
? descriptor->CalleeSavedRegisters() & ~kConstantPoolRegister.bit()
: descriptor->CalleeSavedRegisters();
if (saves != 0) {
// register save area does not include the fp or constant pool pointer.
const int num_saves =
kNumCalleeSaved - 1 - (FLAG_enable_embedded_constant_pool ? 1 : 0);
DCHECK(num_saves == base::bits::CountPopulation32(saves));
frame->AllocateSavedCalleeRegisterSlots(num_saves);
}
}
void CodeGenerator::AssemblePrologue() {
void CodeGenerator::AssembleConstructFrame() {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
if (frame_access_state()->has_frame()) {
if (descriptor->IsCFunctionCall()) {
......@@ -1779,7 +1802,7 @@ void CodeGenerator::AssemblePrologue() {
}
}
int stack_shrink_slots = frame()->GetSpillSlotCount();
int shrink_slots = frame()->GetSpillSlotCount();
if (info()->is_osr()) {
// TurboFan OSR-compiled functions cannot be entered directly.
__ Abort(kShouldNotDirectlyEnterOsrFunction);
......@@ -1790,15 +1813,12 @@ void CodeGenerator::AssemblePrologue() {
// remaining stack slots.
if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
osr_pc_offset_ = __ pc_offset();
stack_shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots();
shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots();
}
const RegList double_saves = descriptor->CalleeSavedFPRegisters();
if (double_saves != 0) {
stack_shrink_slots += frame()->AlignSavedCalleeRegisterSlots();
}
if (stack_shrink_slots > 0) {
__ Add(sp, sp, -stack_shrink_slots * kPointerSize, r0);
if (shrink_slots > 0) {
__ Add(sp, sp, -shrink_slots * kPointerSize, r0);
}
// Save callee-saved Double registers.
......@@ -1806,8 +1826,6 @@ void CodeGenerator::AssemblePrologue() {
__ MultiPushDoubles(double_saves);
DCHECK(kNumCalleeSavedDoubles ==
base::bits::CountPopulation32(double_saves));
frame()->AllocateSavedCalleeRegisterSlots(kNumCalleeSavedDoubles *
(kDoubleSize / kPointerSize));
}
// Save callee-saved registers.
......@@ -1818,10 +1836,6 @@ void CodeGenerator::AssemblePrologue() {
if (saves != 0) {
__ MultiPush(saves);
// register save area does not include the fp or constant pool pointer.
const int num_saves =
kNumCalleeSaved - 1 - (FLAG_enable_embedded_constant_pool ? 1 : 0);
DCHECK(num_saves == base::bits::CountPopulation32(saves));
frame()->AllocateSavedCalleeRegisterSlots(num_saves);
}
}
......
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