Commit 19f33159 authored by mbrandy's avatar mbrandy Committed by Commit bot

PPC: [turbofan] Add general support for sp-based frame access

Port 51669873

Original commit message:
    Some highlights of this CL:
    * Refactor the mutable state out of Frame into FrameAccessState,
      which is maintained and updated during code generation to
      record whether sp- or fp-based frame access is currently active
      and how deep the stack on top of the frame is.
    * The operand resultion in linkage.cc now uses FrameAccessState
      to determine how to generate frame-accessing operands.
    * Update all platforms to accurately track additionally pushed
      stack slots (e.g. arguments for calls) in the FrameAccessState.
    * Add a flag, --turbo_sp_frame_access, which forces all frame
      access to be sp-based whenever possible. This will likely never
      be used in production, but for testing it's useful in verifying
      that the stack-tracking of each platform maintained in the
      FrameAccessState is correct.
    * Use sp-based frame access for gap resolving before tail
      calls. This will allow for slightly more efficient restoration
      of the frame pointer in the tail call in a later CL.
    * Remove most ad hoc groping into CallDescriptors to
      determine if a frame is needed, instead consistently use
      predicates like needs_frame(), IsCFunctionCall() and
      IsJSFunctionCall().

R=danno@chromium.org, joransiu@ca.ibm.com, jyan@ca.ibm.com, michael_dawson@ca.ibm.com
BUG=v8:4076
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#32420}
parent cf5546ba
...@@ -101,8 +101,8 @@ class PPCOperandConverter final : public InstructionOperandConverter { ...@@ -101,8 +101,8 @@ class PPCOperandConverter final : public InstructionOperandConverter {
MemOperand ToMemOperand(InstructionOperand* op) const { MemOperand ToMemOperand(InstructionOperand* op) const {
DCHECK(op != NULL); DCHECK(op != NULL);
DCHECK(op->IsStackSlot() || op->IsDoubleStackSlot()); DCHECK(op->IsStackSlot() || op->IsDoubleStackSlot());
FrameOffset offset = FrameOffset offset = frame_access_state()->GetFrameOffset(
linkage()->GetFrameOffset(AllocatedOperand::cast(op)->index(), frame()); AllocatedOperand::cast(op)->index());
return MemOperand(offset.from_stack_pointer() ? sp : fp, offset.offset()); return MemOperand(offset.from_stack_pointer() ? sp : fp, offset.offset());
} }
}; };
...@@ -610,10 +610,7 @@ void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) { ...@@ -610,10 +610,7 @@ void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) {
if (sp_slot_delta > 0) { if (sp_slot_delta > 0) {
__ Add(sp, sp, sp_slot_delta * kPointerSize, r0); __ Add(sp, sp, sp_slot_delta * kPointerSize, r0);
} }
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); if (frame()->needs_frame()) {
int spill_slots = frame()->GetSpillSlotCount();
bool has_frame = descriptor->IsJSFunctionCall() || spill_slots > 0;
if (has_frame) {
if (FLAG_enable_embedded_constant_pool) { if (FLAG_enable_embedded_constant_pool) {
__ Pop(r0, fp, kConstantPoolRegister); __ Pop(r0, fp, kConstantPoolRegister);
} else { } else {
...@@ -621,6 +618,7 @@ void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) { ...@@ -621,6 +618,7 @@ void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) {
} }
__ mtlr(r0); __ mtlr(r0);
} }
frame_access_state()->SetFrameAccessToDefault();
} }
...@@ -628,7 +626,9 @@ void CodeGenerator::AssemblePrepareTailCall(int stack_param_delta) { ...@@ -628,7 +626,9 @@ void CodeGenerator::AssemblePrepareTailCall(int stack_param_delta) {
int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta);
if (sp_slot_delta < 0) { if (sp_slot_delta < 0) {
__ Add(sp, sp, sp_slot_delta * kPointerSize, r0); __ Add(sp, sp, sp_slot_delta * kPointerSize, r0);
frame_access_state()->IncreaseSPDelta(-sp_slot_delta);
} }
frame_access_state()->SetFrameAccessToSP();
} }
...@@ -652,6 +652,7 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) { ...@@ -652,6 +652,7 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
} }
RecordCallPosition(instr); RecordCallPosition(instr);
DCHECK_EQ(LeaveRC, i.OutputRCBit()); DCHECK_EQ(LeaveRC, i.OutputRCBit());
frame_access_state()->ClearSPDelta();
break; break;
} }
case kArchTailCallCodeObject: { case kArchTailCallCodeObject: {
...@@ -669,6 +670,7 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) { ...@@ -669,6 +670,7 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
RelocInfo::CODE_TARGET); RelocInfo::CODE_TARGET);
} }
DCHECK_EQ(LeaveRC, i.OutputRCBit()); DCHECK_EQ(LeaveRC, i.OutputRCBit());
frame_access_state()->ClearSPDelta();
break; break;
} }
case kArchCallJSFunction: { case kArchCallJSFunction: {
...@@ -687,6 +689,7 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) { ...@@ -687,6 +689,7 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
__ Call(ip); __ Call(ip);
RecordCallPosition(instr); RecordCallPosition(instr);
DCHECK_EQ(LeaveRC, i.OutputRCBit()); DCHECK_EQ(LeaveRC, i.OutputRCBit());
frame_access_state()->ClearSPDelta();
break; break;
} }
case kArchTailCallJSFunction: { case kArchTailCallJSFunction: {
...@@ -703,6 +706,7 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) { ...@@ -703,6 +706,7 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
__ LoadP(ip, FieldMemOperand(func, JSFunction::kCodeEntryOffset)); __ LoadP(ip, FieldMemOperand(func, JSFunction::kCodeEntryOffset));
__ Jump(ip); __ Jump(ip);
DCHECK_EQ(LeaveRC, i.OutputRCBit()); DCHECK_EQ(LeaveRC, i.OutputRCBit());
frame_access_state()->ClearSPDelta();
break; break;
} }
case kArchLazyBailout: { case kArchLazyBailout: {
...@@ -715,6 +719,8 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) { ...@@ -715,6 +719,8 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
case kArchPrepareCallCFunction: { case kArchPrepareCallCFunction: {
int const num_parameters = MiscField::decode(instr->opcode()); int const num_parameters = MiscField::decode(instr->opcode());
__ PrepareCallCFunction(num_parameters, kScratchReg); __ PrepareCallCFunction(num_parameters, kScratchReg);
// Frame alignment requires using FP-relative frame addressing.
frame_access_state()->SetFrameAccessToFP();
break; break;
} }
case kArchPrepareTailCall: case kArchPrepareTailCall:
...@@ -729,6 +735,8 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) { ...@@ -729,6 +735,8 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
Register func = i.InputRegister(0); Register func = i.InputRegister(0);
__ CallCFunction(func, num_parameters); __ CallCFunction(func, num_parameters);
} }
frame_access_state()->SetFrameAccessToDefault();
frame_access_state()->ClearSPDelta();
break; break;
} }
case kArchJmp: case kArchJmp:
...@@ -1068,8 +1076,10 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) { ...@@ -1068,8 +1076,10 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
case kPPC_Push: case kPPC_Push:
if (instr->InputAt(0)->IsDoubleRegister()) { if (instr->InputAt(0)->IsDoubleRegister()) {
__ stfdu(i.InputDoubleRegister(0), MemOperand(sp, -kDoubleSize)); __ stfdu(i.InputDoubleRegister(0), MemOperand(sp, -kDoubleSize));
frame_access_state()->IncreaseSPDelta(kDoubleSize / kPointerSize);
} else { } else {
__ Push(i.InputRegister(0)); __ Push(i.InputRegister(0));
frame_access_state()->IncreaseSPDelta(1);
} }
DCHECK_EQ(LeaveRC, i.OutputRCBit()); DCHECK_EQ(LeaveRC, i.OutputRCBit());
break; break;
...@@ -1449,8 +1459,7 @@ void CodeGenerator::AssembleDeoptimizerCall( ...@@ -1449,8 +1459,7 @@ void CodeGenerator::AssembleDeoptimizerCall(
void CodeGenerator::AssemblePrologue() { void CodeGenerator::AssemblePrologue() {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
if (descriptor->IsCFunctionCall()) {
if (descriptor->kind() == CallDescriptor::kCallAddress) {
__ function_descriptor(); __ function_descriptor();
__ mflr(r0); __ mflr(r0);
if (FLAG_enable_embedded_constant_pool) { if (FLAG_enable_embedded_constant_pool) {
...@@ -1464,11 +1473,12 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1464,11 +1473,12 @@ void CodeGenerator::AssemblePrologue() {
} else if (descriptor->IsJSFunctionCall()) { } else if (descriptor->IsJSFunctionCall()) {
CompilationInfo* info = this->info(); CompilationInfo* info = this->info();
__ Prologue(info->IsCodePreAgingActive()); __ Prologue(info->IsCodePreAgingActive());
} else if (needs_frame_) { } else if (frame()->needs_frame()) {
__ StubPrologue(); __ StubPrologue();
} else { } else {
frame()->SetElidedFrameSizeInSlots(0); frame()->SetElidedFrameSizeInSlots(0);
} }
frame_access_state()->SetFrameAccessToDefault();
int stack_shrink_slots = frame()->GetSpillSlotCount(); int stack_shrink_slots = frame()->GetSpillSlotCount();
if (info()->is_osr()) { if (info()->is_osr()) {
...@@ -1538,9 +1548,9 @@ void CodeGenerator::AssembleReturn() { ...@@ -1538,9 +1548,9 @@ void CodeGenerator::AssembleReturn() {
__ MultiPopDoubles(double_saves); __ MultiPopDoubles(double_saves);
} }
if (descriptor->kind() == CallDescriptor::kCallAddress) { if (descriptor->IsCFunctionCall()) {
__ LeaveFrame(StackFrame::MANUAL, pop_count * kPointerSize); __ LeaveFrame(StackFrame::MANUAL, pop_count * kPointerSize);
} else if (descriptor->IsJSFunctionCall() || needs_frame_) { } else if (frame()->needs_frame()) {
// Canonicalize JSFunction return sites for now. // Canonicalize JSFunction return sites for now.
if (return_label_.is_bound()) { if (return_label_.is_bound()) {
__ b(&return_label_); __ b(&return_label_);
......
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