Commit 7e88aa3d authored by zhengxing.li's avatar zhengxing.li Committed by Commit bot

X87: [turbofan] CodeGenerator: Frame setup refactoring.

  port 81a1530e (r35642)

  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.

  additional message:
  This CL also removed the temporary workaround for CL #35139 (53d51c52)

BUG=

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

Cr-Commit-Position: refs/heads/master@{#35648}
parent 85870e86
......@@ -374,11 +374,6 @@ void CodeGenerator::AssembleDeconstructFrame() {
__ pop(ebp);
}
// For insert fninit/fld1 instructions after the Prologue
thread_local bool is_block_0 = false;
void CodeGenerator::AssembleSetupStackPointer() { is_block_0 = true; }
void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) {
int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta);
if (sp_slot_delta > 0) {
......@@ -444,13 +439,6 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
InstructionCode opcode = instr->opcode();
ArchOpcode arch_opcode = ArchOpcodeField::decode(opcode);
// Workaround for CL #35139 (https://codereview.chromium.org/1775323002)
if (is_block_0) {
__ fninit();
__ fld1();
is_block_0 = false;
}
switch (arch_opcode) {
case kArchCallCodeObject: {
if (FLAG_debug_code && FLAG_enable_slow_asserts) {
......@@ -2128,8 +2116,25 @@ void CodeGenerator::AssembleDeoptimizerCall(
// | RET | args | caller frame |
// ^ esp ^ ebp
void CodeGenerator::FinishFrame(Frame* frame) {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
const RegList saves = descriptor->CalleeSavedRegisters();
if (saves != 0) { // Save callee-saved registers.
DCHECK(!info()->is_osr());
int pushed = 0;
for (int i = Register::kNumRegisters - 1; i >= 0; i--) {
if (!((1 << i) & saves)) continue;
++pushed;
}
frame->AllocateSavedCalleeRegisterSlots(pushed);
}
// Initailize FPU state.
__ fninit();
__ fld1();
}
void CodeGenerator::AssemblePrologue() {
void CodeGenerator::AssembleConstructFrame() {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
if (frame_access_state()->has_frame()) {
if (descriptor->IsCFunctionCall()) {
......@@ -2141,7 +2146,9 @@ void CodeGenerator::AssemblePrologue() {
__ StubPrologue(info()->GetOutputStackFrameType());
}
}
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);
......@@ -2152,7 +2159,7 @@ 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();
// Initailize FPU state.
__ fninit();
......@@ -2160,8 +2167,8 @@ void CodeGenerator::AssemblePrologue() {
}
const RegList saves = descriptor->CalleeSavedRegisters();
if (stack_shrink_slots > 0) {
__ sub(esp, Immediate(stack_shrink_slots * kPointerSize));
if (shrink_slots > 0) {
__ sub(esp, Immediate(shrink_slots * kPointerSize));
}
if (saves != 0) { // Save callee-saved registers.
......@@ -2172,7 +2179,6 @@ void CodeGenerator::AssemblePrologue() {
__ push(Register::from_code(i));
++pushed;
}
frame()->AllocateSavedCalleeRegisterSlots(pushed);
}
}
......
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