Skip to content

Commit af0a980

Browse files
committed
Tracing JIT: Use information about really called internal function return type to improve type inference.
1 parent 88982a1 commit af0a980

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

ext/opcache/jit/zend_jit_trace.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
15651565
p = trace_buffer + ZEND_JIT_TRACE_START_REC_SIZE;
15661566
idx = 0;
15671567
level = 0;
1568+
opline = NULL;
15681569
for (;;p++) {
15691570
if (p->op == ZEND_JIT_TRACE_VM) {
15701571
uint8_t orig_op1_type, orig_op2_type, op1_type, op2_type, op3_type;
@@ -2378,6 +2379,25 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
23782379
top = call;
23792380
frame->call = call->prev;
23802381
}
2382+
2383+
if (idx > 0
2384+
&& ssa_ops[idx-1].result_def >= 0
2385+
&& (p->func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE)
2386+
&& !(p->func->common.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
2387+
ZEND_ASSERT(ssa_opcodes[idx-1] == opline);
2388+
ZEND_ASSERT(opline->opcode == ZEND_DO_ICALL ||
2389+
opline->opcode == ZEND_DO_FCALL ||
2390+
opline->opcode == ZEND_DO_FCALL_BY_NAME);
2391+
2392+
if (opline->result_type != IS_UNDEF) {
2393+
zend_class_entry *ce;
2394+
const zend_function *func = p->func;
2395+
zend_arg_info *ret_info = func->common.arg_info - 1;
2396+
uint32_t ret_type = zend_fetch_arg_info_type(NULL, ret_info, &ce);
2397+
2398+
ssa_var_info[ssa_ops[idx-1].result_def].type &= ret_type;
2399+
}
2400+
}
23812401
} else if (p->op == ZEND_JIT_TRACE_END) {
23822402
break;
23832403
}

0 commit comments

Comments
 (0)