Branch: Tag:

2017-11-18

2017-11-18 10:13:13 by Arne Goedeke <el@laramies.com>

Interpreter: moved tailcall optimization

Tailcall optimizations now happen inside of two API variants.
This is an initial step towards refactoring the tailcall optimization
code to not allocate new frames.

2244:    NAME " & return",I_UPDATE_ALL, \   { \    PIKE_OPCODE_T *addr; \ -  if((addr = low_mega_apply(TYPE, (INT32)(Pike_sp - *--Pike_mark_sp), \ -  ARG2,ARG3))) \ +  if((addr = low_mega_apply_tailcall(TYPE, \ +  (INT32)(Pike_sp - *--Pike_mark_sp), \ +  ARG2,ARG3))) \    { \ -  DO_IF_DEBUG(Pike_fp->next->pc=0); \ -  unlink_previous_frame(); \ +     DO_JUMP_TO(addr); \    } \    else { \
2296:    "mark, " NAME " & return",I_UPDATE_ALL, \   { \    PIKE_OPCODE_T *addr; \ -  if((addr=low_mega_apply(TYPE, 0, ARG2, ARG3))) \ +  if((addr=low_mega_apply_tailcall(TYPE, 0, ARG2, ARG3))) \    { \ -  DO_IF_DEBUG(Pike_fp->next->pc=0); \ -  unlink_previous_frame(); \ +     DO_JUMP_TO(addr); \    } \    else { \
2359:      OPCODE1_RETURN(F_CALL_LFUN_AND_RETURN , "call lfun & return", I_UPDATE_ALL, {    PIKE_OPCODE_T *addr; -  if((addr = lower_mega_apply((INT32)(Pike_sp - *--Pike_mark_sp), +  if((addr = lower_mega_apply_tailcall((INT32)(Pike_sp - *--Pike_mark_sp),    Pike_fp->current_object,    (arg1+Pike_fp->context->identifier_level))))    { -  DO_IF_DEBUG(Pike_fp->next->pc=0); -  unlink_previous_frame(); +     DO_JUMP_TO(addr);    }else{    DO_DUMB_RETURN;
2401:      OPCODE1_RETURN(F_MARK_CALL_LFUN_AND_RETURN , "mark, call lfun & return", I_UPDATE_ALL, {    PIKE_OPCODE_T *addr; -  if((addr = lower_mega_apply(0, Pike_fp->current_object, +  if((addr = lower_mega_apply_tailcall(0, Pike_fp->current_object,    (arg1+Pike_fp->context->identifier_level))))    { -  DO_IF_DEBUG(Pike_fp->next->pc=0); -  unlink_previous_frame(); +     DO_JUMP_TO(addr);    }    else
2543:    INT32 args=(INT32)(Pike_sp - *--Pike_mark_sp);    struct svalue *s;    s = Pike_sp - args; -  if(TYPEOF(*s) == T_OBJECT) +  /* +  * this optimization is broken since *_tailcall was introduced. +  * I have no idea why... Disable it for now. +  * +  */ +  if(0 && TYPEOF(*s) == T_OBJECT)    {    struct object *o;    struct program *p;
2560:    if(fun >= 0)    {    fun += o->prog->inherits[SUBTYPEOF(*s)].identifier_level; -  if((addr = lower_mega_apply(args-1, o, fun))) +  if((addr = lower_mega_apply_tailcall(args-1, o, fun)))    {    Pike_fp->save_sp_offset--; -  DO_IF_DEBUG(Pike_fp->next->pc=0); -  unlink_previous_frame(); +     DO_JUMP_TO(addr);    }    stack_pop_keep_top();
2586:    move_svalue (s, &tmp2);    print_return_value();    -  if((addr = low_mega_apply(APPLY_STACK, args, 0, 0))) +  if((addr = low_mega_apply_tailcall(APPLY_STACK, args, 0, 0)))    { -  DO_IF_DEBUG(Pike_fp->next->pc=0); -  unlink_previous_frame(); +     DO_JUMP_TO(addr);    }    DO_DUMB_RETURN;