| Index: src/compiler/x64/code-generator-x64.cc
|
| diff --git a/src/compiler/x64/code-generator-x64.cc b/src/compiler/x64/code-generator-x64.cc
|
| index 72a9c39f2dbc44241a1c2ed9c30cc5f21e6e353e..5607baba7a61741d9ef7f9fc69a3d4de5bd85687 100644
|
| --- a/src/compiler/x64/code-generator-x64.cc
|
| +++ b/src/compiler/x64/code-generator-x64.cc
|
| @@ -626,21 +626,7 @@ void CodeGenerator::AssembleDeconstructFrame() {
|
| __ popq(rbp);
|
| }
|
|
|
| -void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) {
|
| - int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta);
|
| - if (sp_slot_delta > 0) {
|
| - __ addq(rsp, Immediate(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) {
|
| - __ subq(rsp, Immediate(-sp_slot_delta * kPointerSize));
|
| - frame_access_state()->IncreaseSPDelta(-sp_slot_delta);
|
| - }
|
| +void CodeGenerator::AssemblePrepareTailCall() {
|
| if (frame_access_state()->has_frame()) {
|
| __ movq(rbp, MemOperand(rbp, 0));
|
| }
|
| @@ -672,6 +658,68 @@ void CodeGenerator::AssemblePopArgumentsAdaptorFrame(Register args_reg,
|
| __ bind(&done);
|
| }
|
|
|
| +namespace {
|
| +
|
| +void AdjustStackPointerForTailCall(MacroAssembler* masm,
|
| + FrameAccessState* state,
|
| + int new_slot_above_sp,
|
| + 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) {
|
| + masm->subq(rsp, Immediate(stack_slot_delta * kPointerSize));
|
| + state->IncreaseSPDelta(stack_slot_delta);
|
| + } else if (allow_shrinkage && stack_slot_delta < 0) {
|
| + masm->addq(rsp, Immediate(-stack_slot_delta * kPointerSize));
|
| + state->IncreaseSPDelta(stack_slot_delta);
|
| + }
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +void CodeGenerator::AssembleTailCallBeforeGap(Instruction* instr,
|
| + int first_unused_stack_slot) {
|
| + CodeGenerator::PushTypeFlags flags(kImmediatePush | kScalarPush);
|
| + ZoneVector<MoveOperands*> pushes(zone());
|
| + GetPushCompatibleMoves(instr, flags, &pushes);
|
| +
|
| + if (!pushes.empty() &&
|
| + (LocationOperand::cast(pushes.back()->destination()).index() + 1 ==
|
| + first_unused_stack_slot)) {
|
| + X64OperandConverter g(this, instr);
|
| + for (auto move : pushes) {
|
| + LocationOperand destination_location(
|
| + LocationOperand::cast(move->destination()));
|
| + InstructionOperand source(move->source());
|
| + AdjustStackPointerForTailCall(masm(), frame_access_state(),
|
| + destination_location.index());
|
| + if (source.IsStackSlot()) {
|
| + LocationOperand source_location(LocationOperand::cast(source));
|
| + __ Push(g.SlotToOperand(source_location.index()));
|
| + } else if (source.IsRegister()) {
|
| + LocationOperand source_location(LocationOperand::cast(source));
|
| + __ Push(source_location.GetRegister());
|
| + } else if (source.IsImmediate()) {
|
| + __ Push(Immediate(ImmediateOperand::cast(source).inline_value()));
|
| + } else {
|
| + // Pushes of non-scalar data types is not supported.
|
| + UNIMPLEMENTED();
|
| + }
|
| + frame_access_state()->IncreaseSPDelta(1);
|
| + move->Eliminate();
|
| + }
|
| + }
|
| + AdjustStackPointerForTailCall(masm(), frame_access_state(),
|
| + first_unused_stack_slot, false);
|
| +}
|
| +
|
| +void CodeGenerator::AssembleTailCallAfterGap(Instruction* instr,
|
| + int first_unused_stack_slot) {
|
| + AdjustStackPointerForTailCall(masm(), frame_access_state(),
|
| + first_unused_stack_slot);
|
| +}
|
| +
|
| // Assembles an instruction after register allocation, producing machine code.
|
| CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
|
| Instruction* instr) {
|
| @@ -695,8 +743,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),
|
| @@ -711,15 +757,15 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
|
| __ jmp(reg);
|
| }
|
| 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(!HasImmediateInput(instr, 0));
|
| Register reg = i.InputRegister(0);
|
| __ jmp(reg);
|
| frame_access_state()->ClearSPDelta();
|
| + frame_access_state()->SetFrameAccessToDefault();
|
| break;
|
| }
|
| case kArchCallJSFunction: {
|
| @@ -743,8 +789,6 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
|
| __ cmpp(rsi, FieldOperand(func, JSFunction::kContextOffset));
|
| __ Assert(equal, 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),
|
| @@ -752,6 +796,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
|
| }
|
| __ jmp(FieldOperand(func, JSFunction::kCodeEntryOffset));
|
| frame_access_state()->ClearSPDelta();
|
| + frame_access_state()->SetFrameAccessToDefault();
|
| break;
|
| }
|
| case kArchPrepareCallCFunction: {
|
| @@ -762,7 +807,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());
|
|
|