Skip to content

Commit

Permalink
Merge branch 'PHP-8.4'
Browse files Browse the repository at this point in the history
* PHP-8.4:
  Extract call_level conditions out to separate functions (php#16949)
  • Loading branch information
nielsdos committed Nov 26, 2024
2 parents 4591f04 + ed55693 commit 30ec2de
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 77 deletions.
77 changes: 40 additions & 37 deletions ext/opcache/jit/zend_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,38 @@ ZEND_EXT_API void zend_jit_status(zval *ret)
add_assoc_zval(ret, "jit", &stats);
}

static bool zend_jit_inc_call_level(uint8_t opcode)
{
switch (opcode) {
case ZEND_INIT_FCALL:
case ZEND_INIT_FCALL_BY_NAME:
case ZEND_INIT_NS_FCALL_BY_NAME:
case ZEND_INIT_METHOD_CALL:
case ZEND_INIT_DYNAMIC_CALL:
case ZEND_INIT_STATIC_METHOD_CALL:
case ZEND_INIT_PARENT_PROPERTY_HOOK_CALL:
case ZEND_INIT_USER_CALL:
case ZEND_NEW:
return true;
default:
return false;
}
}

static bool zend_jit_dec_call_level(uint8_t opcode)
{
switch (opcode) {
case ZEND_DO_FCALL:
case ZEND_DO_ICALL:
case ZEND_DO_UCALL:
case ZEND_DO_FCALL_BY_NAME:
case ZEND_CALLABLE_CONVERT:
return true;
default:
return false;
}
}

static zend_string *zend_jit_func_name(const zend_op_array *op_array)
{
smart_str buf = {0};
Expand Down Expand Up @@ -1572,17 +1604,8 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
for (i = ssa->cfg.blocks[b].start; i <= end; i++) {
zend_ssa_op *ssa_op = ssa->ops ? &ssa->ops[i] : NULL;
opline = op_array->opcodes + i;
switch (opline->opcode) {
case ZEND_INIT_FCALL:
case ZEND_INIT_FCALL_BY_NAME:
case ZEND_INIT_NS_FCALL_BY_NAME:
case ZEND_INIT_METHOD_CALL:
case ZEND_INIT_DYNAMIC_CALL:
case ZEND_INIT_STATIC_METHOD_CALL:
case ZEND_INIT_PARENT_PROPERTY_HOOK_CALL:
case ZEND_INIT_USER_CALL:
case ZEND_NEW:
call_level++;
if (zend_jit_inc_call_level(opline->opcode)) {
call_level++;
}

if (JIT_G(opt_level) >= ZEND_JIT_LEVEL_INLINE) {
Expand Down Expand Up @@ -2720,25 +2743,10 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
i++;
for (; i < end; i++) {
opline = op_array->opcodes + i;
switch (opline->opcode) {
case ZEND_INIT_FCALL:
case ZEND_INIT_FCALL_BY_NAME:
case ZEND_INIT_NS_FCALL_BY_NAME:
case ZEND_INIT_METHOD_CALL:
case ZEND_INIT_DYNAMIC_CALL:
case ZEND_INIT_STATIC_METHOD_CALL:
case ZEND_INIT_PARENT_PROPERTY_HOOK_CALL:
case ZEND_INIT_USER_CALL:
case ZEND_NEW:
call_level++;
break;
case ZEND_DO_FCALL:
case ZEND_DO_ICALL:
case ZEND_DO_UCALL:
case ZEND_DO_FCALL_BY_NAME:
case ZEND_CALLABLE_CONVERT:
call_level--;
break;
if (zend_jit_inc_call_level(opline->opcode)) {
call_level++;
} else if (zend_jit_dec_call_level(opline->opcode)) {
call_level--;
}
}
opline = op_array->opcodes + i;
Expand Down Expand Up @@ -2853,13 +2861,8 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
}
}
done:
switch (opline->opcode) {
case ZEND_DO_FCALL:
case ZEND_DO_ICALL:
case ZEND_DO_UCALL:
case ZEND_DO_FCALL_BY_NAME:
case ZEND_CALLABLE_CONVERT:
call_level--;
if (zend_jit_dec_call_level(opline->opcode)) {
call_level--;
}
}
zend_jit_bb_end(&ctx, b);
Expand Down
51 changes: 11 additions & 40 deletions ext/opcache/jit/zend_jit_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1164,28 +1164,13 @@ static const zend_op *zend_jit_trace_find_init_fcall_op(zend_jit_trace_rec *p, c
if (opline) {
while (opline > op_array->opcodes) {
opline--;
switch (opline->opcode) {
case ZEND_INIT_FCALL:
case ZEND_INIT_FCALL_BY_NAME:
case ZEND_INIT_NS_FCALL_BY_NAME:
case ZEND_INIT_METHOD_CALL:
case ZEND_INIT_DYNAMIC_CALL:
case ZEND_INIT_STATIC_METHOD_CALL:
case ZEND_INIT_PARENT_PROPERTY_HOOK_CALL:
case ZEND_INIT_USER_CALL:
case ZEND_NEW:
if (call_level == 0) {
return opline;
}
call_level--;
break;
case ZEND_DO_FCALL:
case ZEND_DO_ICALL:
case ZEND_DO_UCALL:
case ZEND_DO_FCALL_BY_NAME:
case ZEND_CALLABLE_CONVERT:
call_level++;
break;
if (zend_jit_inc_call_level(opline->opcode)) {
if (call_level == 0) {
return opline;
}
call_level--;
} else if (zend_jit_dec_call_level(opline->opcode)) {
call_level++;
}
}
}
Expand Down Expand Up @@ -4422,17 +4407,8 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par

frame_flags = 0;

switch (opline->opcode) {
case ZEND_INIT_FCALL:
case ZEND_INIT_FCALL_BY_NAME:
case ZEND_INIT_NS_FCALL_BY_NAME:
case ZEND_INIT_METHOD_CALL:
case ZEND_INIT_DYNAMIC_CALL:
case ZEND_INIT_STATIC_METHOD_CALL:
case ZEND_INIT_PARENT_PROPERTY_HOOK_CALL:
case ZEND_INIT_USER_CALL:
case ZEND_NEW:
frame->call_level++;
if (zend_jit_inc_call_level(opline->opcode)) {
frame->call_level++;
}

if (JIT_G(opt_level) >= ZEND_JIT_LEVEL_INLINE) {
Expand Down Expand Up @@ -6497,13 +6473,8 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par

done:
polymorphic_side_trace = 0;
switch (opline->opcode) {
case ZEND_DO_FCALL:
case ZEND_DO_ICALL:
case ZEND_DO_UCALL:
case ZEND_DO_FCALL_BY_NAME:
case ZEND_CALLABLE_CONVERT:
frame->call_level--;
if (zend_jit_dec_call_level(opline->opcode)) {
frame->call_level--;
}

if (ra) {
Expand Down

0 comments on commit 30ec2de

Please sign in to comment.