Skip to content

Commit 980f7bd

Browse files
committed
Implement INIT_FCALL offset optimization
Closes GH-13634
1 parent 4bf4c24 commit 980f7bd

File tree

4 files changed

+608
-552
lines changed

4 files changed

+608
-552
lines changed

Zend/zend_compile.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4807,7 +4807,8 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
48074807
zend_op *opline;
48084808

48094809
lcname = zend_string_tolower(Z_STR_P(name));
4810-
fbc = zend_hash_find_ptr(CG(function_table), lcname);
4810+
zval *fbc_zv = zend_hash_find(CG(function_table), lcname);
4811+
fbc = fbc_zv ? Z_PTR_P(fbc_zv) : NULL;
48114812

48124813
/* Special assert() handling should apply independently of compiler flags. */
48134814
if (fbc && zend_string_equals_literal(lcname, "assert") && !is_callable_convert) {
@@ -4842,6 +4843,12 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
48424843
opline = zend_emit_op(NULL, ZEND_INIT_FCALL, NULL, &name_node);
48434844
opline->result.num = zend_alloc_cache_slot();
48444845

4846+
/* Store offset to function from symbol table in op2.extra. */
4847+
if (fbc->type == ZEND_INTERNAL_FUNCTION) {
4848+
Bucket *fbc_bucket = (Bucket*)((uintptr_t)fbc_zv - XtOffsetOf(Bucket, val));
4849+
Z_EXTRA_P(CT_CONSTANT(opline->op2)) = fbc_bucket - CG(function_table)->arData;
4850+
}
4851+
48454852
zend_compile_call_common(result, args_ast, fbc, ast->lineno);
48464853
}
48474854
}

Zend/zend_vm_def.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3959,6 +3959,24 @@ ZEND_VM_HOT_HANDLER(61, ZEND_INIT_FCALL, NUM, CONST, NUM|CACHE_SLOT)
39593959
ZEND_VM_NEXT_OPCODE();
39603960
}
39613961

3962+
ZEND_VM_HOT_TYPE_SPEC_HANDLER(ZEND_INIT_FCALL, Z_EXTRA_P(RT_CONSTANT(op, op->op2)) != 0, ZEND_INIT_FCALL_OFFSET, NUM, CONST, NUM|CACHE_SLOT)
3963+
{
3964+
USE_OPLINE
3965+
zend_function *fbc;
3966+
zend_execute_data *call;
3967+
fbc = CACHED_PTR(opline->result.num);
3968+
if (UNEXPECTED(fbc == NULL)) {
3969+
fbc = Z_PTR(EG(function_table)->arData[Z_EXTRA_P(RT_CONSTANT(opline, opline->op2))].val);
3970+
CACHE_PTR(opline->result.num, fbc);
3971+
}
3972+
call = _zend_vm_stack_push_call_frame_ex(
3973+
opline->op1.num, ZEND_CALL_NESTED_FUNCTION,
3974+
fbc, opline->extended_value, NULL);
3975+
call->prev_execute_data = EX(call);
3976+
EX(call) = call;
3977+
ZEND_VM_NEXT_OPCODE();
3978+
}
3979+
39623980
ZEND_VM_HOT_HANDLER(129, ZEND_DO_ICALL, ANY, ANY, SPEC(RETVAL,OBSERVER))
39633981
{
39643982
USE_OPLINE

0 commit comments

Comments
 (0)