Skip to content

Commit 9b6c36e

Browse files
committed
JIT: Don't reuse IP register for EX(call)
1 parent 4b7da22 commit 9b6c36e

File tree

5 files changed

+191
-206
lines changed

5 files changed

+191
-206
lines changed

ext/opcache/jit/zend_jit.c

+19-16
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,9 @@ static bool zend_jit_may_be_modified(const zend_function *func, const zend_op_ar
803803
# pragma clang diagnostic ignored "-Wstring-compare"
804804
#endif
805805

806+
static bool zend_jit_inc_call_level(uint8_t opcode);
807+
static bool zend_jit_dec_call_level(uint8_t opcode);
808+
806809
#include "jit/zend_jit_ir.c"
807810

808811
#if defined(__clang__)
@@ -1609,6 +1612,18 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
16091612
call_level++;
16101613
}
16111614

1615+
#if ZEND_DEBUG && 0
1616+
{
1617+
const void *handler;
1618+
if (zend_jit_vm_kind == ZEND_VM_KIND_HYBRID) {
1619+
handler = zend_get_opcode_handler_func(opline);
1620+
} else {
1621+
handler = opline->handler;
1622+
}
1623+
ir_RSTORE(8, jit_CONST_FUNC(&ctx, (uintptr_t)handler, IR_FASTCALL_FUNC));
1624+
}
1625+
#endif
1626+
16121627
if (JIT_G(opt_level) >= ZEND_JIT_LEVEL_INLINE) {
16131628
switch (opline->opcode) {
16141629
case ZEND_PRE_INC:
@@ -1676,10 +1691,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
16761691
&& zend_jit_next_is_send_result(opline)) {
16771692
i++;
16781693
res_use_info = -1;
1679-
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
1680-
if (!zend_jit_reuse_ip(&ctx)) {
1681-
goto jit_failure;
1682-
}
1694+
res_addr = ZEND_ADDR_ARG(jit_EX_CALL(jit), (opline+1)->result.var);
16831695
} else {
16841696
res_use_info = -1;
16851697

@@ -1730,10 +1742,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
17301742
&& zend_jit_next_is_send_result(opline)) {
17311743
i++;
17321744
res_use_info = -1;
1733-
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
1734-
if (!zend_jit_reuse_ip(&ctx)) {
1735-
goto jit_failure;
1736-
}
1745+
res_addr = ZEND_ADDR_ARG(jit_EX_CALL(jit), (opline+1)->result.var);
17371746
} else {
17381747
res_use_info = -1;
17391748

@@ -1786,10 +1795,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
17861795
if ((i + 1) <= end
17871796
&& zend_jit_next_is_send_result(opline)) {
17881797
i++;
1789-
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
1790-
if (!zend_jit_reuse_ip(&ctx)) {
1791-
goto jit_failure;
1792-
}
1798+
res_addr = ZEND_ADDR_ARG(jit_EX_CALL(jit), (opline+1)->result.var);
17931799
}
17941800
if (!zend_jit_concat(&ctx, opline,
17951801
op1_info, op2_info, res_addr,
@@ -2040,10 +2046,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
20402046
&& zend_jit_next_is_send_result(opline)
20412047
&& (!(op1_info & MAY_HAVE_DTOR) || !(op1_info & MAY_BE_RC1))) {
20422048
i++;
2043-
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
2044-
if (!zend_jit_reuse_ip(&ctx)) {
2045-
goto jit_failure;
2046-
}
2049+
res_addr = ZEND_ADDR_ARG(jit_EX_CALL(jit), (opline+1)->result.var);
20472050
}
20482051
}
20492052
if (!zend_jit_assign(&ctx, opline,

ext/opcache/jit/zend_jit_internal.h

+13-3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ typedef uintptr_t zend_jit_addr;
6464
#define Z_SSA_VAR(addr) ((addr)>>_ZEND_ADDR_REG_SHIFT)
6565
#define Z_IR_REF(addr) ((addr)>>_ZEND_ADDR_REG_SHIFT)
6666

67+
#define ZEND_ADDR_ARG(call, var) ZEND_ADDR_REF_ZVAL(ir_ADD_OFFSET(call, var))
68+
69+
#define Z_IS_ARG_ADDR(addr) \
70+
(Z_MODE(addr) == IS_REF_ZVAL && ( \
71+
Z_IR_REF(addr) == jit->call \
72+
|| (jit->ctx.ir_base[Z_IR_REF(addr)].op == IR_ADD \
73+
&& jit->ctx.ir_base[Z_IR_REF(addr)].op1 == jit->call)))
74+
6775
#define Z_STORE(addr) \
6876
((jit->ra && jit->ra[Z_SSA_VAR(addr)].ref) ? \
6977
(jit->ra[Z_SSA_VAR(addr)].flags & ZREG_STORE) : \
@@ -242,9 +250,9 @@ ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_loop_counter_helper(ZEND_OPCODE_H
242250

243251
ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_copy_extra_args_helper(ZEND_OPCODE_HANDLER_ARGS);
244252
ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_copy_extra_args_helper_no_skip_recv(ZEND_OPCODE_HANDLER_ARGS);
245-
bool ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D);
246-
bool ZEND_FASTCALL zend_jit_nodiscard_helper(OPLINE_D);
247-
bool ZEND_FASTCALL zend_jit_deprecated_nodiscard_helper(OPLINE_D);
253+
bool ZEND_FASTCALL zend_jit_deprecated_helper(zend_execute_data *call);
254+
bool ZEND_FASTCALL zend_jit_nodiscard_helper(zend_execute_data *call);
255+
bool ZEND_FASTCALL zend_jit_deprecated_nodiscard_helper(zend_execute_data *call);
248256
void ZEND_FASTCALL zend_jit_undefined_long_key(EXECUTE_DATA_D);
249257
void ZEND_FASTCALL zend_jit_undefined_long_key_ex(zend_long key EXECUTE_DATA_DC);
250258
void ZEND_FASTCALL zend_jit_undefined_string_key(EXECUTE_DATA_D);
@@ -448,6 +456,8 @@ typedef struct _zend_jit_trace_exit_info {
448456
int32_t poly_this_ref;
449457
int8_t poly_func_reg;
450458
int8_t poly_this_reg;
459+
int32_t call_ref;
460+
int8_t call_reg;
451461
} zend_jit_trace_exit_info;
452462

453463
typedef struct _zend_jit_trace_stack {

0 commit comments

Comments
 (0)