Index: src/compiler/ia32/code-generator-ia32.cc |
diff --git a/src/compiler/ia32/code-generator-ia32.cc b/src/compiler/ia32/code-generator-ia32.cc |
index 1f61af8abf9c14f56ff27a7eb4dae6bcd8b40f6a..2a454127e526a895b40496dd19270e8756029b8b 100644 |
--- a/src/compiler/ia32/code-generator-ia32.cc |
+++ b/src/compiler/ia32/code-generator-ia32.cc |
@@ -355,12 +355,50 @@ void CodeGenerator::AssemblePrepareTailCall(int stack_param_delta) { |
frame_access_state()->SetFrameAccessToSP(); |
} |
+void CodeGenerator::AssemblePopArgumentsAdaptorFrame(Register args_reg, |
+ Register, Register, |
+ Register) { |
+ // There are not enough temp registers left on ia32 for a call instruction |
+ // so we pick some scratch registers and save/restore them manually here. |
+ int scratch_count = 3; |
+ Register scratch1 = ebx; |
+ Register scratch2 = ecx; |
+ Register scratch3 = edx; |
+ DCHECK(!AreAliased(args_reg, scratch1, scratch2, scratch3)); |
+ Label done; |
+ |
+ // Check if current frame is an arguments adaptor frame. |
+ __ cmp(Operand(ebp, StandardFrameConstants::kContextOffset), |
+ Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
+ __ j(not_equal, &done, Label::kNear); |
+ |
+ __ push(scratch1); |
+ __ push(scratch2); |
+ __ push(scratch3); |
+ |
+ // Load arguments count from current arguments adaptor frame (note, it |
+ // does not include receiver). |
+ Register caller_args_count_reg = scratch1; |
+ __ mov(caller_args_count_reg, |
+ Operand(ebp, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
+ __ SmiUntag(caller_args_count_reg); |
+ |
+ ParameterCount callee_args_count(args_reg); |
+ __ PrepareForTailCall(callee_args_count, caller_args_count_reg, scratch2, |
+ scratch3, ReturnAddressState::kOnStack, scratch_count); |
+ __ pop(scratch3); |
+ __ pop(scratch2); |
+ __ pop(scratch1); |
+ |
+ __ bind(&done); |
+} |
// Assembles an instruction after register allocation, producing machine code. |
void CodeGenerator::AssembleArchInstruction(Instruction* instr) { |
IA32OperandConverter i(this, instr); |
- |
- switch (ArchOpcodeField::decode(instr->opcode())) { |
+ InstructionCode opcode = instr->opcode(); |
+ ArchOpcode arch_opcode = ArchOpcodeField::decode(opcode); |
+ switch (arch_opcode) { |
case kArchCallCodeObject: { |
EnsureSpaceForLazyDeopt(); |
if (HasImmediateInput(instr, 0)) { |
@@ -375,9 +413,14 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) { |
frame_access_state()->ClearSPDelta(); |
break; |
} |
+ case kArchTailCallCodeObjectFromJSFunction: |
case kArchTailCallCodeObject: { |
int stack_param_delta = i.InputInt32(instr->InputCount() - 1); |
AssembleDeconstructActivationRecord(stack_param_delta); |
+ if (arch_opcode == kArchTailCallCodeObjectFromJSFunction) { |
+ AssemblePopArgumentsAdaptorFrame(kJavaScriptCallArgCountRegister, |
+ no_reg, no_reg, no_reg); |
+ } |
if (HasImmediateInput(instr, 0)) { |
Handle<Code> code = Handle<Code>::cast(i.InputHeapObject(0)); |
__ jmp(code, RelocInfo::CODE_TARGET); |
@@ -402,6 +445,7 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) { |
frame_access_state()->ClearSPDelta(); |
break; |
} |
+ case kArchTailCallJSFunctionFromJSFunction: |
case kArchTailCallJSFunction: { |
Register func = i.InputRegister(0); |
if (FLAG_debug_code) { |
@@ -411,6 +455,10 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) { |
} |
int stack_param_delta = i.InputInt32(instr->InputCount() - 1); |
AssembleDeconstructActivationRecord(stack_param_delta); |
+ if (arch_opcode == kArchTailCallJSFunctionFromJSFunction) { |
+ AssemblePopArgumentsAdaptorFrame(kJavaScriptCallArgCountRegister, |
+ no_reg, no_reg, no_reg); |
+ } |
__ jmp(FieldOperand(func, JSFunction::kCodeEntryOffset)); |
frame_access_state()->ClearSPDelta(); |
break; |