Commit 9e1f2c5e authored by mbrandy's avatar mbrandy Committed by Commit bot

PPC: [turbofan] Frame elision for code stubs.

Port 53d51c52

Includes fixes required for embedded constant pools.

Original commit message:
    Removed Frame::needs_frame and the function-wide logic using it in
    favor of FrameAccessState::has_frame, which can be set on a more
    granular level, and driving it block by block.

R=mtrofin@chromium.org, joransiu@ca.ibm.com, jyan@ca.ibm.com, michael_dawson@ca.ibm.com, rmcilroy@chromium.org
BUG=v8:4533
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#35166}
parent 719dc19d
......@@ -153,9 +153,11 @@ Handle<Code> CodeGenerator::GenerateCode() {
}
}
for (int i = block->code_start(); i < block->code_end(); ++i) {
Instruction* instr = code()->InstructionAt(i);
AssembleInstruction(instr, block);
if (FLAG_enable_embedded_constant_pool && !block->needs_frame()) {
ConstantPoolUnavailableScope constant_pool_unavailable(masm());
AssembleBlock(block);
} else {
AssembleBlock(block);
}
}
}
......@@ -300,6 +302,13 @@ bool CodeGenerator::IsMaterializableFromRoot(
return false;
}
void CodeGenerator::AssembleBlock(const InstructionBlock* block) {
for (int i = block->code_start(); i < block->code_end(); ++i) {
Instruction* instr = code()->InstructionAt(i);
AssembleInstruction(instr, block);
}
}
void CodeGenerator::AssembleInstruction(Instruction* instr,
const InstructionBlock* block) {
AssembleGaps(instr);
......
......@@ -84,6 +84,9 @@ class CodeGenerator final : public GapResolver::Assembler {
bool IsMaterializableFromRoot(Handle<HeapObject> object,
Heap::RootListIndex* index_return);
// Assemble instructions for the specified block.
void AssembleBlock(const InstructionBlock* block);
// Assemble code for the specified instruction.
void AssembleInstruction(Instruction* instr, const InstructionBlock* block);
void AssembleSourcePosition(Instruction* instr);
......
......@@ -187,7 +187,8 @@ class OutOfLineRecordWrite final : public OutOfLineCode {
value_(value),
scratch0_(scratch0),
scratch1_(scratch1),
mode_(mode) {}
mode_(mode),
must_save_lr_(!gen->frame_access_state()->has_frame()) {}
void Generate() final {
if (mode_ > RecordWriteMode::kValueIsPointer) {
......@@ -201,7 +202,7 @@ class OutOfLineRecordWrite final : public OutOfLineCode {
: OMIT_REMEMBERED_SET;
SaveFPRegsMode const save_fp_mode =
frame()->DidAllocateDoubleRegisters() ? kSaveFPRegs : kDontSaveFPRegs;
if (!frame()->needs_frame()) {
if (must_save_lr_) {
// We need to save and restore lr if the frame was elided.
__ mflr(scratch1_);
__ Push(scratch1_);
......@@ -215,7 +216,7 @@ class OutOfLineRecordWrite final : public OutOfLineCode {
__ add(scratch1_, object_, offset_);
}
__ CallStub(&stub);
if (!frame()->needs_frame()) {
if (must_save_lr_) {
// We need to save and restore lr if the frame was elided.
__ Pop(scratch1_);
__ mtlr(scratch1_);
......@@ -230,6 +231,7 @@ class OutOfLineRecordWrite final : public OutOfLineCode {
Register const scratch0_;
Register const scratch1_;
RecordWriteMode const mode_;
bool must_save_lr_;
};
......@@ -670,6 +672,11 @@ Condition FlagsConditionToCondition(FlagsCondition condition, ArchOpcode op) {
DCHECK_EQ(LeaveRC, i.OutputRCBit()); \
} while (0)
void CodeGenerator::AssembleDeconstructFrame() {
__ LeaveFrame(StackFrame::MANUAL);
}
void CodeGenerator::AssembleSetupStackPointer() {}
void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) {
int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta);
......@@ -686,7 +693,7 @@ void CodeGenerator::AssemblePrepareTailCall(int stack_param_delta) {
__ Add(sp, sp, sp_slot_delta * kPointerSize, r0);
frame_access_state()->IncreaseSPDelta(-sp_slot_delta);
}
if (frame()->needs_frame()) {
if (frame_access_state()->has_frame()) {
__ RestoreFrameStateForTailCall();
}
frame_access_state()->SetFrameAccessToSP();
......@@ -867,7 +874,7 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
DCHECK_EQ(LeaveRC, i.OutputRCBit());
break;
case kArchParentFramePointer:
if (frame_access_state()->frame()->needs_frame()) {
if (frame_access_state()->has_frame()) {
__ LoadP(i.OutputRegister(), MemOperand(fp, 0));
} else {
__ mr(i.OutputRegister(), fp);
......@@ -1707,7 +1714,7 @@ void CodeGenerator::AssembleDeoptimizerCall(
void CodeGenerator::AssemblePrologue() {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
if (frame()->needs_frame()) {
if (frame_access_state()->has_frame()) {
if (descriptor->IsCFunctionCall()) {
__ function_descriptor();
__ mflr(r0);
......@@ -1723,18 +1730,11 @@ void CodeGenerator::AssemblePrologue() {
__ Prologue(this->info()->GeneratePreagedPrologue(), ip);
} else {
StackFrame::Type type = info()->GetOutputStackFrameType();
if (!ABI_CALL_VIA_IP &&
info()->output_code_kind() == Code::WASM_FUNCTION) {
// TODO(mbrandy): Restrict only to the wasm wrapper case.
__ StubPrologue(type);
} else {
__ StubPrologue(type, ip);
}
// TODO(mbrandy): Detect cases where ip is the entrypoint (for
// efficient intialization of the constant pool pointer register).
__ StubPrologue(type);
}
} else {
frame()->SetElidedFrameSizeInSlots(0);
}
frame_access_state()->SetFrameAccessToDefault();
int stack_shrink_slots = frame()->GetSpillSlotCount();
if (info()->is_osr()) {
......@@ -1803,20 +1803,18 @@ void CodeGenerator::AssembleReturn() {
}
if (descriptor->IsCFunctionCall()) {
__ LeaveFrame(StackFrame::MANUAL, pop_count * kPointerSize);
} else if (frame()->needs_frame()) {
AssembleDeconstructFrame();
} else if (frame_access_state()->has_frame()) {
// Canonicalize JSFunction return sites for now.
if (return_label_.is_bound()) {
__ b(&return_label_);
return;
} else {
__ bind(&return_label_);
__ LeaveFrame(StackFrame::MANUAL, pop_count * kPointerSize);
AssembleDeconstructFrame();
}
} else {
__ Drop(pop_count);
}
__ Ret();
__ Ret(pop_count);
}
......
......@@ -992,8 +992,11 @@ void MacroAssembler::LoadConstantPoolPointerRegister() {
void MacroAssembler::StubPrologue(StackFrame::Type type, Register base,
int prologue_offset) {
LoadSmiLiteral(r11, Smi::FromInt(type));
PushCommonFrame(r11);
{
ConstantPoolUnavailableScope constant_pool_unavailable(this);
LoadSmiLiteral(r11, Smi::FromInt(type));
PushCommonFrame(r11);
}
if (FLAG_enable_embedded_constant_pool) {
if (!base.is(no_reg)) {
// base contains prologue address
......
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