Skip to content

Implement INIT_FCALL offset optimization #13634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -4807,7 +4807,8 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
zend_op *opline;

lcname = zend_string_tolower(Z_STR_P(name));
fbc = zend_hash_find_ptr(CG(function_table), lcname);
zval *fbc_zv = zend_hash_find(CG(function_table), lcname);
fbc = fbc_zv ? Z_PTR_P(fbc_zv) : NULL;

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

/* Store offset to function from symbol table in op2.extra. */
if (fbc->type == ZEND_INTERNAL_FUNCTION) {
Bucket *fbc_bucket = (Bucket*)((uintptr_t)fbc_zv - XtOffsetOf(Bucket, val));
Z_EXTRA_P(CT_CONSTANT(opline->op2)) = fbc_bucket - CG(function_table)->arData;
}

zend_compile_call_common(result, args_ast, fbc, ast->lineno);
}
}
Expand Down
18 changes: 18 additions & 0 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -3959,6 +3959,24 @@ ZEND_VM_HOT_HANDLER(61, ZEND_INIT_FCALL, NUM, CONST, NUM|CACHE_SLOT)
ZEND_VM_NEXT_OPCODE();
}

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)
{
USE_OPLINE
zend_function *fbc;
zend_execute_data *call;
fbc = CACHED_PTR(opline->result.num);
if (UNEXPECTED(fbc == NULL)) {
fbc = Z_PTR(EG(function_table)->arData[Z_EXTRA_P(RT_CONSTANT(opline, opline->op2))].val);
CACHE_PTR(opline->result.num, fbc);
}
call = _zend_vm_stack_push_call_frame_ex(
opline->op1.num, ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, NULL);
call->prev_execute_data = EX(call);
EX(call) = call;
ZEND_VM_NEXT_OPCODE();
}

ZEND_VM_HOT_HANDLER(129, ZEND_DO_ICALL, ANY, ANY, SPEC(RETVAL,OBSERVER))
{
USE_OPLINE
Expand Down
Loading