| Index: src/ppc/builtins-ppc.cc
|
| diff --git a/src/ppc/builtins-ppc.cc b/src/ppc/builtins-ppc.cc
|
| index 95f7a6eede4267750be2b0c1e21be3bf6d8fa085..d8ef40c8493387da2dc9ae9747873123414dffa9 100644
|
| --- a/src/ppc/builtins-ppc.cc
|
| +++ b/src/ppc/builtins-ppc.cc
|
| @@ -1982,10 +1982,134 @@ void Builtins::Generate_Apply(MacroAssembler* masm) {
|
| }
|
| }
|
|
|
| +namespace {
|
| +
|
| +// Drops top JavaScript frame and an arguments adaptor frame below it (if
|
| +// present) preserving all the arguments prepared for current call.
|
| +// Does nothing if debugger is currently active.
|
| +// ES6 14.6.3. PrepareForTailCall
|
| +//
|
| +// Stack structure for the function g() tail calling f():
|
| +//
|
| +// ------- Caller frame: -------
|
| +// | ...
|
| +// | g()'s arg M
|
| +// | ...
|
| +// | g()'s arg 1
|
| +// | g()'s receiver arg
|
| +// | g()'s caller pc
|
| +// ------- g()'s frame: -------
|
| +// | g()'s caller fp <- fp
|
| +// | g()'s context
|
| +// | function pointer: g
|
| +// | -------------------------
|
| +// | ...
|
| +// | ...
|
| +// | f()'s arg N
|
| +// | ...
|
| +// | f()'s arg 1
|
| +// | f()'s receiver arg <- sp (f()'s caller pc is not on the stack yet!)
|
| +// ----------------------
|
| +//
|
| +void PrepareForTailCall(MacroAssembler* masm, Register args_reg,
|
| + Register scratch1, Register scratch2,
|
| + Register scratch3) {
|
| + DCHECK(!AreAliased(args_reg, scratch1, scratch2, scratch3));
|
| + Comment cmnt(masm, "[ PrepareForTailCall");
|
| +
|
| + // Prepare for tail call only if the debugger is not active.
|
| + Label done;
|
| + ExternalReference debug_is_active =
|
| + ExternalReference::debug_is_active_address(masm->isolate());
|
| + __ mov(scratch1, Operand(debug_is_active));
|
| + __ lbz(scratch1, MemOperand(scratch1));
|
| + __ cmpi(scratch1, Operand::Zero());
|
| + __ bne(&done);
|
| +
|
| + // Check if next frame is an arguments adaptor frame.
|
| + Label no_arguments_adaptor, formal_parameter_count_loaded;
|
| + __ LoadP(scratch2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
|
| + __ LoadP(scratch3,
|
| + MemOperand(scratch2, StandardFrameConstants::kContextOffset));
|
| + __ CmpSmiLiteral(scratch3, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
|
| + __ bne(&no_arguments_adaptor);
|
| +
|
| + // Drop arguments adaptor frame and load arguments count.
|
| + __ mr(fp, scratch2);
|
| + __ LoadP(scratch1,
|
| + MemOperand(fp, ArgumentsAdaptorFrameConstants::kLengthOffset));
|
| + __ SmiUntag(scratch1);
|
| + __ b(&formal_parameter_count_loaded);
|
| +
|
| + __ bind(&no_arguments_adaptor);
|
| + // Load caller's formal parameter count
|
| + __ LoadP(scratch1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
|
| + __ LoadP(scratch1,
|
| + FieldMemOperand(scratch1, JSFunction::kSharedFunctionInfoOffset));
|
| + __ LoadWordArith(
|
| + scratch1, FieldMemOperand(
|
| + scratch1, SharedFunctionInfo::kFormalParameterCountOffset));
|
| +#if !V8_TARGET_ARCH_PPC64
|
| + __ SmiUntag(scratch1);
|
| +#endif
|
| +
|
| + __ bind(&formal_parameter_count_loaded);
|
| +
|
| + // Calculate the end of destination area where we will put the arguments
|
| + // after we drop current frame. We add kPointerSize to count the receiver
|
| + // argument which is not included into formal parameters count.
|
| + Register dst_reg = scratch2;
|
| + __ ShiftLeftImm(dst_reg, scratch1, Operand(kPointerSizeLog2));
|
| + __ add(dst_reg, fp, dst_reg);
|
| + __ addi(dst_reg, dst_reg,
|
| + Operand(StandardFrameConstants::kCallerSPOffset + kPointerSize));
|
| +
|
| + Register src_reg = scratch1;
|
| + __ ShiftLeftImm(src_reg, args_reg, Operand(kPointerSizeLog2));
|
| + __ add(src_reg, sp, src_reg);
|
| + // Count receiver argument as well (not included in args_reg).
|
| + __ addi(src_reg, src_reg, Operand(kPointerSize));
|
| +
|
| + if (FLAG_debug_code) {
|
| + __ cmpl(src_reg, dst_reg);
|
| + __ Check(lt, kStackAccessBelowStackPointer);
|
| + }
|
| +
|
| + // Restore caller's frame pointer and return address now as they will be
|
| + // overwritten by the copying loop.
|
| + if (FLAG_enable_embedded_constant_pool) {
|
| + __ LoadP(kConstantPoolRegister,
|
| + MemOperand(fp, StandardFrameConstants::kConstantPoolOffset));
|
| + }
|
| + __ LoadP(r0, MemOperand(fp, StandardFrameConstants::kCallerPCOffset));
|
| + __ LoadP(fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
|
| + __ mtlr(r0);
|
| +
|
| + // Now copy callee arguments to the caller frame going backwards to avoid
|
| + // callee arguments corruption (source and destination areas could overlap).
|
| +
|
| + // Both src_reg and dst_reg are pointing to the word after the one to copy,
|
| + // so they must be pre-decremented in the loop.
|
| + Register tmp_reg = scratch3;
|
| + Label loop;
|
| + __ addi(tmp_reg, args_reg, Operand(1)); // +1 for receiver
|
| + __ mtctr(tmp_reg);
|
| + __ bind(&loop);
|
| + __ LoadPU(tmp_reg, MemOperand(src_reg, -kPointerSize));
|
| + __ StorePU(tmp_reg, MemOperand(dst_reg, -kPointerSize));
|
| + __ bdnz(&loop);
|
| +
|
| + // Leave current frame.
|
| + __ mr(sp, dst_reg);
|
| +
|
| + __ bind(&done);
|
| +}
|
| +} // namespace
|
|
|
| // static
|
| void Builtins::Generate_CallFunction(MacroAssembler* masm,
|
| - ConvertReceiverMode mode) {
|
| + ConvertReceiverMode mode,
|
| + TailCallMode tail_call_mode) {
|
| // ----------- S t a t e -------------
|
| // -- r3 : the number of arguments (not including the receiver)
|
| // -- r4 : the function to call (checked to be a JSFunction)
|
| @@ -2070,6 +2194,10 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm,
|
| // -- cp : the function context.
|
| // -----------------------------------
|
|
|
| + if (tail_call_mode == TailCallMode::kAllow) {
|
| + PrepareForTailCall(masm, r3, r6, r7, r8);
|
| + }
|
| +
|
| __ LoadWordArith(
|
| r5, FieldMemOperand(r5, SharedFunctionInfo::kFormalParameterCountOffset));
|
| #if !V8_TARGET_ARCH_PPC64
|
| @@ -2174,13 +2302,18 @@ void Generate_PushBoundArguments(MacroAssembler* masm) {
|
|
|
|
|
| // static
|
| -void Builtins::Generate_CallBoundFunction(MacroAssembler* masm) {
|
| +void Builtins::Generate_CallBoundFunctionImpl(MacroAssembler* masm,
|
| + TailCallMode tail_call_mode) {
|
| // ----------- S t a t e -------------
|
| // -- r3 : the number of arguments (not including the receiver)
|
| // -- r4 : the function to call (checked to be a JSBoundFunction)
|
| // -----------------------------------
|
| __ AssertBoundFunction(r4);
|
|
|
| + if (tail_call_mode == TailCallMode::kAllow) {
|
| + PrepareForTailCall(masm, r3, r6, r7, r8);
|
| + }
|
| +
|
| // Patch the receiver to [[BoundThis]].
|
| __ LoadP(ip, FieldMemOperand(r4, JSBoundFunction::kBoundThisOffset));
|
| __ ShiftLeftImm(r0, r3, Operand(kPointerSizeLog2));
|
| @@ -2201,7 +2334,8 @@ void Builtins::Generate_CallBoundFunction(MacroAssembler* masm) {
|
|
|
|
|
| // static
|
| -void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) {
|
| +void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode,
|
| + TailCallMode tail_call_mode) {
|
| // ----------- S t a t e -------------
|
| // -- r3 : the number of arguments (not including the receiver)
|
| // -- r4 : the target to call (can be any Object).
|
| @@ -2211,14 +2345,19 @@ void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) {
|
| __ JumpIfSmi(r4, &non_callable);
|
| __ bind(&non_smi);
|
| __ CompareObjectType(r4, r7, r8, JS_FUNCTION_TYPE);
|
| - __ Jump(masm->isolate()->builtins()->CallFunction(mode),
|
| + __ Jump(masm->isolate()->builtins()->CallFunction(mode, tail_call_mode),
|
| RelocInfo::CODE_TARGET, eq);
|
| __ cmpi(r8, Operand(JS_BOUND_FUNCTION_TYPE));
|
| - __ Jump(masm->isolate()->builtins()->CallBoundFunction(),
|
| + __ Jump(masm->isolate()->builtins()->CallBoundFunction(tail_call_mode),
|
| RelocInfo::CODE_TARGET, eq);
|
| __ cmpi(r8, Operand(JS_PROXY_TYPE));
|
| __ bne(&non_function);
|
|
|
| + // 0. Prepare for tail call if necessary.
|
| + if (tail_call_mode == TailCallMode::kAllow) {
|
| + PrepareForTailCall(masm, r3, r6, r7, r8);
|
| + }
|
| +
|
| // 1. Runtime fallback for Proxy [[Call]].
|
| __ Push(r4);
|
| // Increase the arguments size to include the pushed function and the
|
| @@ -2241,7 +2380,7 @@ void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) {
|
| // Let the "call_as_function_delegate" take care of the rest.
|
| __ LoadNativeContextSlot(Context::CALL_AS_FUNCTION_DELEGATE_INDEX, r4);
|
| __ Jump(masm->isolate()->builtins()->CallFunction(
|
| - ConvertReceiverMode::kNotNullOrUndefined),
|
| + ConvertReceiverMode::kNotNullOrUndefined, tail_call_mode),
|
| RelocInfo::CODE_TARGET);
|
|
|
| // 3. Call to something that is not callable.
|
|
|