From: Dmitry Stogov Date: Thu, 18 Apr 2019 09:29:02 +0000 (+0300) Subject: Fixed JIT for recursive functions with type-hints X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=28828ffccbdb31ec46fd8e9b4aa1801e6a90b088;p=php Fixed JIT for recursive functions with type-hints --- diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c index bbe872cbe7..2b885a77b9 100644 --- a/ext/opcache/jit/zend_jit.c +++ b/ext/opcache/jit/zend_jit.c @@ -593,12 +593,7 @@ static int zend_jit_build_cfg(zend_op_array *op_array, zend_cfg *cfg) { uint32_t flags; - flags = ZEND_CFG_STACKLESS | ZEND_RT_CONSTANTS | ZEND_CFG_NO_ENTRY_PREDECESSORS | ZEND_SSA_RC_INFERENCE_FLAG | ZEND_SSA_USE_CV_RESULTS; - - if (!(op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) { - /* First RECV/RECV_INIT instructions may be skipped */ - flags |= ZEND_CFG_RECV_ENTRY; - } + flags = ZEND_CFG_STACKLESS | ZEND_RT_CONSTANTS | ZEND_CFG_NO_ENTRY_PREDECESSORS | ZEND_SSA_RC_INFERENCE_FLAG | ZEND_SSA_USE_CV_RESULTS | ZEND_CFG_RECV_ENTRY; if (zend_build_cfg(&CG(arena), op_array, flags, cfg) != SUCCESS) { return FAILURE; diff --git a/ext/opcache/jit/zend_jit_x86.dasc b/ext/opcache/jit/zend_jit_x86.dasc index cab7793462..b42072c0b5 100644 --- a/ext/opcache/jit/zend_jit_x86.dasc +++ b/ext/opcache/jit/zend_jit_x86.dasc @@ -7551,6 +7551,21 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, zend_op_ar | mov aword EX->opline, FCARG1a } } + + if (op_array == &func->op_array) { + /* recursive call */ +#ifdef CONTEXT_THREADED_JIT + | call >1 + |.cold_code + |1: + | pop r0 + | jmp =>num_args + |.code +#else + | jmp =>num_args +#endif + return 1; + } } else { | // opline = op_array->opcodes if (GCC_GLOBAL_REGS) { @@ -7606,51 +7621,26 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, zend_op_ar |3: } - if (func && op_array == &func->op_array) { - /* recursive call */ - uint32_t num_args; - - if (func->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) { - num_args = skip_valid_arguments(op_array, ssa, call_info); - } else { - num_args = call_info->num_args; - } - #ifdef CONTEXT_THREADED_JIT - | call >1 - |.cold_code - |1: - | pop r0 - | jmp =>num_args - |.code - if (!func) { - | jmp >9 - } + | call ->context_threaded_call + if (!func) { + | jmp >9 + } #else - | jmp =>num_args -#endif + if (zend_jit_vm_kind == ZEND_VM_KIND_HYBRID) { + | add r4, HYBRID_SPAD + | JMP_IP + } else if (GCC_GLOBAL_REGS) { + | add r4, SPAD // stack alignment + | JMP_IP } else { -#ifdef CONTEXT_THREADED_JIT - | call ->context_threaded_call - if (!func) { - | jmp >9 - } -#else - if (zend_jit_vm_kind == ZEND_VM_KIND_HYBRID) { - | add r4, HYBRID_SPAD - | JMP_IP - } else if (GCC_GLOBAL_REGS) { - | add r4, SPAD // stack alignment - | JMP_IP - } else { - | mov FP, aword T2 // restore FP - | mov RX, aword T3 // restore IP - | add r4, NR_SPAD // stack alignment - | mov r0, 1 // ZEND_VM_ENTER - | ret - } -#endif + | mov FP, aword T2 // restore FP + | mov RX, aword T3 // restore IP + | add r4, NR_SPAD // stack alignment + | mov r0, 1 // ZEND_VM_ENTER + | ret } +#endif } if (!func || func->type == ZEND_INTERNAL_FUNCTION) {