Chromium Code Reviews| Index: src/compiler/arm/code-generator-arm.cc |
| diff --git a/src/compiler/arm/code-generator-arm.cc b/src/compiler/arm/code-generator-arm.cc |
| index a9db0539b17d6a95e8ac21e72052d3baaacea7bf..fed3383d0b344bd7b80ce978baa87a2fc7c7563a 100644 |
| --- a/src/compiler/arm/code-generator-arm.cc |
| +++ b/src/compiler/arm/code-generator-arm.cc |
| @@ -411,21 +411,7 @@ void CodeGenerator::AssembleDeconstructFrame() { |
| __ LeaveFrame(StackFrame::MANUAL); |
| } |
| -void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) { |
| - int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); |
| - if (sp_slot_delta > 0) { |
| - __ add(sp, sp, Operand(sp_slot_delta * kPointerSize)); |
| - } |
| - frame_access_state()->SetFrameAccessToDefault(); |
| -} |
| - |
| - |
| -void CodeGenerator::AssemblePrepareTailCall(int stack_param_delta) { |
| - int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); |
| - if (sp_slot_delta < 0) { |
| - __ sub(sp, sp, Operand(-sp_slot_delta * kPointerSize)); |
| - frame_access_state()->IncreaseSPDelta(-sp_slot_delta); |
| - } |
| +void CodeGenerator::AssemblePrepareTailCall() { |
| if (frame_access_state()->has_frame()) { |
| if (FLAG_enable_embedded_constant_pool) { |
| __ ldr(cp, MemOperand(fp, StandardFrameConstants::kConstantPoolOffset)); |
| @@ -461,6 +447,119 @@ void CodeGenerator::AssemblePopArgumentsAdaptorFrame(Register args_reg, |
| __ bind(&done); |
| } |
| +namespace { |
| + |
| +void FlushPendingPushRegisters(MacroAssembler* masm, |
| + FrameAccessState* frame_access_state, |
| + ZoneVector<Register>* pending_pushes) { |
| + switch (pending_pushes->size()) { |
| + case 0: |
| + break; |
| + case 1: |
| + masm->push((*pending_pushes)[0]); |
|
Mircea Trofin
2016/06/30 15:32:34
pending_pushes->at(0)
same further down and else
danno
2016/07/01 07:31:57
Done.
|
| + break; |
| + case 2: |
| + masm->Push((*pending_pushes)[0], (*pending_pushes)[1]); |
| + break; |
| + case 3: |
| + masm->Push((*pending_pushes)[0], (*pending_pushes)[1], |
| + (*pending_pushes)[2]); |
| + break; |
| + default: |
| + UNREACHABLE(); |
| + break; |
| + } |
| + frame_access_state->IncreaseSPDelta(pending_pushes->size()); |
| + pending_pushes->resize(0); |
| +} |
| + |
| +void AddPendingPushRegister(MacroAssembler* masm, |
| + FrameAccessState* frame_access_state, |
| + ZoneVector<Register>* pending_pushes, |
| + Register reg) { |
| + pending_pushes->push_back(reg); |
| + if (pending_pushes->size() == 3 || reg.is(ip)) { |
| + FlushPendingPushRegisters(masm, frame_access_state, pending_pushes); |
| + } |
| +} |
| + |
| +void AdjustStackPointerForGap(MacroAssembler* masm, FrameAccessState* state, |
| + int new_slot_above_sp, |
| + ZoneVector<Register>* pending_pushes = nullptr, |
| + bool allow_shrinkage = true) { |
| + int current_sp_offset = state->GetSPToFPSlotCount() + |
| + StandardFrameConstants::kFixedSlotCountAboveFp; |
| + int stack_slot_delta = new_slot_above_sp - current_sp_offset; |
| + if (stack_slot_delta > 0) { |
| + if (pending_pushes != nullptr) { |
| + FlushPendingPushRegisters(masm, state, pending_pushes); |
| + } |
| + masm->sub(sp, sp, Operand(stack_slot_delta * kPointerSize)); |
| + state->IncreaseSPDelta(stack_slot_delta); |
| + } else if (allow_shrinkage && stack_slot_delta < 0) { |
| + if (pending_pushes != nullptr) { |
| + FlushPendingPushRegisters(masm, state, pending_pushes); |
| + } |
| + masm->add(sp, sp, Operand(-stack_slot_delta * kPointerSize)); |
| + state->IncreaseSPDelta(stack_slot_delta); |
| + } |
| +} |
| + |
| +} // namespace |
| + |
| +void CodeGenerator::AssemblePreGaps(Instruction* instr) { |
| + int first_unused_stack_slot; |
| + if (!GetSlotAboveSPAfterGap(instr, &first_unused_stack_slot)) return; |
| + |
| + GapResolver::PushTypeFlags flags(GapResolver::kImmediatePush | |
| + GapResolver::kScalarPush); |
| + ZoneVector<MoveOperands*> pushes(zone()); |
| + resolver()->GetPushCompatibleMoves(zone(), instr, flags, &pushes); |
| + |
| + if (!pushes.empty() && |
| + (LocationOperand::cast(pushes.back()->destination()).index() + 1 == |
| + first_unused_stack_slot)) { |
| + ArmOperandConverter g(this, instr); |
| + ZoneVector<Register> pending_pushes(zone()); |
| + for (auto move : pushes) { |
| + LocationOperand destination_location( |
| + LocationOperand::cast(move->destination())); |
| + InstructionOperand source(move->source()); |
| + AdjustStackPointerForGap( |
| + masm(), frame_access_state(), |
| + destination_location.index() - pending_pushes.size(), |
| + &pending_pushes); |
| + if (source.IsStackSlot()) { |
| + LocationOperand source_location(LocationOperand::cast(source)); |
| + __ ldr(ip, g.SlotToMemOperand(source_location.index())); |
| + AddPendingPushRegister(masm(), frame_access_state(), &pending_pushes, |
| + ip); |
| + } else if (source.IsRegister()) { |
| + LocationOperand source_location(LocationOperand::cast(source)); |
| + AddPendingPushRegister(masm(), frame_access_state(), &pending_pushes, |
| + source_location.GetRegister()); |
| + } else if (source.IsImmediate()) { |
| + AddPendingPushRegister(masm(), frame_access_state(), &pending_pushes, |
| + ip); |
| + } else { |
| + // Pushes of non-scalar data types is not supported. |
| + UNIMPLEMENTED(); |
| + } |
| + move->Eliminate(); |
| + } |
| + FlushPendingPushRegisters(masm(), frame_access_state(), &pending_pushes); |
| + } |
| + AdjustStackPointerForGap(masm(), frame_access_state(), |
| + first_unused_stack_slot, nullptr, false); |
| +} |
| + |
| +void CodeGenerator::AssemblePostGaps(Instruction* instr) { |
| + int first_unused_stack_slot; |
| + if (!GetSlotAboveSPAfterGap(instr, &first_unused_stack_slot)) return; |
| + AdjustStackPointerForGap(masm(), frame_access_state(), |
| + first_unused_stack_slot); |
| +} |
| + |
| // Assembles an instruction after register allocation, producing machine code. |
| CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( |
| Instruction* instr) { |
| @@ -487,8 +586,6 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( |
| } |
| case kArchTailCallCodeObjectFromJSFunction: |
| case kArchTailCallCodeObject: { |
| - int stack_param_delta = i.InputInt32(instr->InputCount() - 1); |
| - AssembleDeconstructActivationRecord(stack_param_delta); |
| if (arch_opcode == kArchTailCallCodeObjectFromJSFunction) { |
| AssemblePopArgumentsAdaptorFrame(kJavaScriptCallArgCountRegister, |
| i.TempRegister(0), i.TempRegister(1), |
| @@ -504,14 +601,14 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( |
| } |
| DCHECK_EQ(LeaveCC, i.OutputSBit()); |
| frame_access_state()->ClearSPDelta(); |
| + frame_access_state()->SetFrameAccessToDefault(); |
| break; |
| } |
| case kArchTailCallAddress: { |
| - int stack_param_delta = i.InputInt32(instr->InputCount() - 1); |
| - AssembleDeconstructActivationRecord(stack_param_delta); |
| CHECK(!instr->InputAt(0)->IsImmediate()); |
| __ Jump(i.InputRegister(0)); |
| frame_access_state()->ClearSPDelta(); |
| + frame_access_state()->SetFrameAccessToDefault(); |
| break; |
| } |
| case kArchCallJSFunction: { |
| @@ -539,8 +636,6 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( |
| __ cmp(cp, kScratchReg); |
| __ Assert(eq, kWrongFunctionContext); |
| } |
| - int stack_param_delta = i.InputInt32(instr->InputCount() - 1); |
| - AssembleDeconstructActivationRecord(stack_param_delta); |
| if (arch_opcode == kArchTailCallJSFunctionFromJSFunction) { |
| AssemblePopArgumentsAdaptorFrame(kJavaScriptCallArgCountRegister, |
| i.TempRegister(0), i.TempRegister(1), |
| @@ -550,6 +645,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( |
| __ Jump(ip); |
| DCHECK_EQ(LeaveCC, i.OutputSBit()); |
| frame_access_state()->ClearSPDelta(); |
| + frame_access_state()->SetFrameAccessToDefault(); |
| break; |
| } |
| case kArchPrepareCallCFunction: { |
| @@ -560,7 +656,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( |
| break; |
| } |
| case kArchPrepareTailCall: |
| - AssemblePrepareTailCall(i.InputInt32(instr->InputCount() - 1)); |
| + AssemblePrepareTailCall(); |
| break; |
| case kArchCallCFunction: { |
| int const num_parameters = MiscField::decode(instr->opcode()); |