Skip to content

Commit 862340b

Browse files
committed
Implement feedback
1 parent 87d7a0b commit 862340b

8 files changed

+56
-78
lines changed

Zend/zend_compile.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3935,17 +3935,8 @@ static void zend_compile_ns_call(znode *result, znode *name_node, zend_ast *args
39353935
zend_function *frameless_function = NULL;
39363936
if (args_ast->kind != ZEND_AST_CALLABLE_CONVERT
39373937
&& !zend_args_contain_unpack_or_named(zend_ast_get_list(args_ast))) {
3938-
zend_function **flf_ptr = zend_flf_functions;
3939-
while (*flf_ptr != NULL) {
3940-
zend_function *func = *flf_ptr;
3941-
zend_string *caller_name = Z_STR_P(CT_CONSTANT_EX(CG(active_op_array), name_constants + 2));
3942-
zend_string *func_name = func->internal_function.function_name;
3943-
if (func_name && zend_string_equals_ci(caller_name, func_name)) {
3944-
frameless_function = func;
3945-
break;
3946-
}
3947-
flf_ptr++;
3948-
}
3938+
zend_string *lc_func_name = Z_STR_P(CT_CONSTANT_EX(CG(active_op_array), name_constants + 2));
3939+
frameless_function = zend_hash_find_ptr(CG(function_table), lc_func_name);
39493940
}
39503941

39513942
uint32_t jmp_fl_opnum = 0;

Zend/zend_frameless_function.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ typedef struct {
122122
uint32_t num_args;
123123
} zend_frameless_function_info;
124124

125+
typedef enum {
126+
ZEND_JMP_FL_UNPRIMED = 0,
127+
ZEND_JMP_FL_MISS = 1,
128+
ZEND_JMP_FL_HIT = 2,
129+
} zend_jmp_fl_result;
130+
125131
END_EXTERN_C()
126132

127133
#endif

Zend/zend_vm_def.h

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9559,27 +9559,23 @@ ZEND_VM_HANDLER(202, ZEND_CALLABLE_CONVERT, UNUSED, UNUSED)
95599559
ZEND_VM_HANDLER(208, ZEND_JMP_FRAMELESS, CONST, JMP_ADDR, NUM|CACHE_SLOT)
95609560
{
95619561
USE_OPLINE
9562-
uintptr_t result = (uintptr_t)CACHED_PTR(opline->extended_value);
9563-
switch (result) {
9564-
case 0: {
9565-
zval *func_name = (zval *)RT_CONSTANT(opline, opline->op1);
9566-
zval *func = zend_hash_find_known_hash(EG(function_table), Z_STR_P(func_name));
9567-
result = (func == NULL) + 1;
9568-
CACHE_PTR(opline->extended_value, (void *)result);
9569-
if (result == 2) {
9570-
ZEND_VM_C_GOTO(frameless);
9571-
}
9572-
ZEND_FALLTHROUGH;
9573-
}
9574-
case 1:
9575-
ZEND_VM_NEXT_OPCODE();
9576-
break;
9577-
case 2:
9578-
ZEND_VM_C_LABEL(frameless):
9579-
OPLINE = OP_JMP_ADDR(opline, opline->op2);
9580-
ZEND_VM_CONTINUE();
9581-
break;
9582-
EMPTY_SWITCH_DEFAULT_CASE()
9562+
zend_jmp_fl_result result = (uintptr_t)CACHED_PTR(opline->extended_value);
9563+
ZEND_VM_C_LABEL(try_again):
9564+
if (EXPECTED(result == ZEND_JMP_FL_HIT)) {
9565+
OPLINE = OP_JMP_ADDR(opline, opline->op2);
9566+
ZEND_VM_CONTINUE();
9567+
} else if (EXPECTED(result == ZEND_JMP_FL_MISS)) {
9568+
ZEND_VM_NEXT_OPCODE();
9569+
} else {
9570+
ZEND_ASSERT(result == ZEND_JMP_FL_UNPRIMED);
9571+
/* func_name refers to the function in the local namespace, e.g. foo\substr. */
9572+
zval *func_name = (zval *)RT_CONSTANT(opline, opline->op1);
9573+
/* If it cannot be found locally, we must be referring to the global function. */
9574+
zval *func = zend_hash_find_known_hash(EG(function_table), Z_STR_P(func_name));
9575+
/* ZEND_JMP_FL_MISS = 1, ZEND_JMP_FL_HIT = 2 */
9576+
result = (func == NULL) + 1;
9577+
CACHE_PTR(opline->extended_value, (void *)result);
9578+
ZEND_VM_C_GOTO(try_again);
95839579
}
95849580
}
95859581

Zend/zend_vm_execute.h

Lines changed: 17 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/opcache/jit/zend_jit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2560,7 +2560,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
25602560
}
25612561
break;
25622562
case ZEND_JMP_FRAMELESS:
2563-
if (!zend_jit_jmp_frameless(&ctx, opline, /* exit_addr */ NULL, /* exit_on_jmp */ false)) {
2563+
if (!zend_jit_jmp_frameless(&ctx, opline, /* exit_addr */ NULL, /* guard */ 0)) {
25642564
goto jit_failure;
25652565
}
25662566
break;

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static zend_function* ZEND_FASTCALL zend_jit_find_func_helper(zend_string *name,
7070
static uint32_t ZEND_FASTCALL zend_jit_jmp_frameless_helper(zval *func_name, void **cache_slot)
7171
{
7272
zval *func = zend_hash_find_known_hash(EG(function_table), Z_STR_P(func_name));
73-
uint32_t result = (func == NULL) + 1;
73+
zend_jmp_fl_result result = (func == NULL) + 1;
7474
*cache_slot = (void *)(uintptr_t)result;
7575
return result;
7676
}

ext/opcache/jit/zend_jit_ir.c

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3781,7 +3781,7 @@ static int zend_jit_jmp_frameless(
37813781
zend_jit_ctx *jit,
37823782
const zend_op *opline,
37833783
const void *exit_addr,
3784-
bool exit_on_jmp
3784+
zend_jmp_fl_result guard
37853785
) {
37863786
ir_ref ref, if_ref, cache_result, function_result, phi_result, cache_slot_ref;
37873787
zend_basic_block *bb;
@@ -3790,35 +3790,24 @@ static int zend_jit_jmp_frameless(
37903790
cache_slot_ref = ir_ADD_OFFSET(ir_LOAD_A(jit_EX(run_time_cache)), opline->extended_value);
37913791
cache_result = ir_LOAD_L(cache_slot_ref);
37923792

3793-
if_ref = ir_IF(ir_EQ(cache_result, ir_CONST_LONG(0)));
3794-
3795-
ir_IF_TRUE(if_ref);
3793+
// JIT: if (UNEXPECTED(!result))
3794+
if_ref = ir_IF(cache_result);
3795+
ir_IF_FALSE_cold(if_ref);
37963796
zval *func_name_zv = RT_CONSTANT(opline, opline->op1);
37973797
function_result = ir_CALL_2(IR_LONG, ir_CONST_FC_FUNC(zend_jit_jmp_frameless_helper),
37983798
ir_CONST_ADDR(func_name_zv),
37993799
cache_slot_ref);
3800-
3801-
ir_MERGE_WITH_EMPTY_FALSE(if_ref);
3800+
ir_MERGE_WITH_EMPTY_TRUE(if_ref);
38023801

38033802
phi_result = ir_PHI_2(IR_LONG, function_result, cache_result);
38043803

38053804
if (exit_addr) {
3806-
ref = ir_IF(ir_EQ(phi_result, ir_CONST_LONG(2)));
3807-
if (exit_on_jmp) {
3808-
ir_IF_TRUE(ref);
3809-
} else {
3810-
ir_IF_FALSE(ref);
3811-
}
3812-
jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr));
3813-
if (exit_on_jmp) {
3814-
ir_IF_FALSE(ref);
3815-
} else {
3816-
ir_IF_TRUE(ref);
3817-
}
3805+
ir_GUARD(ir_EQ(phi_result, ir_CONST_LONG(guard)), ir_CONST_ADDR(exit_addr));
38183806
} else {
38193807
ZEND_ASSERT(jit->b >= 0);
38203808
bb = &jit->ssa->cfg.blocks[jit->b];
3821-
ref = jit_IF_ex(jit, ir_EQ(phi_result, ir_CONST_LONG(2)), bb->successors[0]);
3809+
// JIT: if (result == ZEND_JMP_FL_HIT)
3810+
ref = jit_IF_ex(jit, ir_EQ(phi_result, ir_CONST_LONG(ZEND_JMP_FL_HIT)), bb->successors[0]);
38223811
_zend_jit_add_predecessor_ref(jit, bb->successors[0], jit->b, ref);
38233812
_zend_jit_add_predecessor_ref(jit, bb->successors[1], jit->b, ref);
38243813
jit->b = -1;

ext/opcache/jit/zend_jit_trace.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5567,15 +5567,15 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
55675567
ZEND_ASSERT((p+1)->op == ZEND_JIT_TRACE_VM);
55685568
const zend_op *exit_opline = NULL;
55695569
uint32_t exit_point;
5570-
bool exit_on_jmp;
5570+
zend_jmp_fl_result guard;
55715571

55725572
if ((p+1)->opline == OP_JMP_ADDR(opline, opline->op2)) {
55735573
/* taken branch */
5574-
exit_on_jmp = false;
5574+
guard = ZEND_JMP_FL_HIT;
55755575
exit_opline = opline + 1;
55765576
} else if ((p+1)->opline == opline + 1) {
55775577
/* not taken branch */
5578-
exit_on_jmp = true;
5578+
guard = ZEND_JMP_FL_MISS;
55795579
exit_opline = OP_JMP_ADDR(opline, opline->op2);
55805580
} else {
55815581
ZEND_UNREACHABLE();
@@ -5585,7 +5585,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
55855585
if (!exit_addr) {
55865586
goto jit_failure;
55875587
}
5588-
if (!zend_jit_jmp_frameless(&ctx, opline, exit_addr, exit_on_jmp)) {
5588+
if (!zend_jit_jmp_frameless(&ctx, opline, exit_addr, guard)) {
55895589
goto jit_failure;
55905590
}
55915591
goto done;

0 commit comments

Comments
 (0)