Skip to content

Commit 383d0dc

Browse files
committed
JIT: Don't reuse IP register for EX(call)
1 parent 76d7c61 commit 383d0dc

File tree

5 files changed

+269
-288
lines changed

5 files changed

+269
-288
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_runtime_jit(ZEND_OPCODE_HANDLE
102102

103103
static int zend_jit_trace_op_len(const zend_op *opline);
104104
static int zend_jit_trace_may_exit(const zend_op_array *op_array, const zend_op *opline);
105-
static uint32_t zend_jit_trace_get_exit_point(const zend_op *to_opline, uint32_t flags);
105+
106+
typedef struct _zend_jit_ctx zend_jit_ctx; // TODO
107+
static uint32_t zend_jit_trace_get_exit_point(zend_jit_ctx *ctx, const zend_op *to_opline, uint32_t flags);
106108
static const void *zend_jit_trace_get_exit_addr(uint32_t n);
107109
static void zend_jit_trace_add_code(const void *start, uint32_t size);
108110
static zend_string *zend_jit_func_name(const zend_op_array *op_array);
@@ -802,6 +804,9 @@ static bool zend_jit_may_be_modified(const zend_function *func, const zend_op_ar
802804
# pragma clang diagnostic ignored "-Wstring-compare"
803805
#endif
804806

807+
static bool zend_jit_inc_call_level(uint8_t opcode);
808+
static bool zend_jit_dec_call_level(uint8_t opcode);
809+
805810
#include "jit/zend_jit_ir.c"
806811

807812
#if defined(__clang__)
@@ -1608,6 +1613,18 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
16081613
call_level++;
16091614
}
16101615

1616+
#if ZEND_DEBUG && 0
1617+
{
1618+
const void *handler;
1619+
if (zend_jit_vm_kind == ZEND_VM_KIND_HYBRID) {
1620+
handler = zend_get_opcode_handler_func(opline);
1621+
} else {
1622+
handler = opline->handler;
1623+
}
1624+
ir_RSTORE(8, jit_CONST_FUNC(&ctx, (uintptr_t)handler, IR_FASTCALL_FUNC));
1625+
}
1626+
#endif
1627+
16111628
if (JIT_G(opt_level) >= ZEND_JIT_LEVEL_INLINE) {
16121629
switch (opline->opcode) {
16131630
case ZEND_PRE_INC:
@@ -1675,10 +1692,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
16751692
&& zend_jit_next_is_send_result(opline)) {
16761693
i++;
16771694
res_use_info = -1;
1678-
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
1679-
if (!zend_jit_reuse_ip(&ctx)) {
1680-
goto jit_failure;
1681-
}
1695+
res_addr = ZEND_ADDR_REF_ZVAL(ir_ADD_OFFSET(jit_EX_CALL(jit), (opline+1)->result.var));
16821696
} else {
16831697
res_use_info = -1;
16841698

@@ -1729,10 +1743,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
17291743
&& zend_jit_next_is_send_result(opline)) {
17301744
i++;
17311745
res_use_info = -1;
1732-
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
1733-
if (!zend_jit_reuse_ip(&ctx)) {
1734-
goto jit_failure;
1735-
}
1746+
res_addr = ZEND_ADDR_REF_ZVAL(ir_ADD_OFFSET(jit_EX_CALL(jit), (opline+1)->result.var));
17361747
} else {
17371748
res_use_info = -1;
17381749

@@ -1785,10 +1796,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
17851796
if ((i + 1) <= end
17861797
&& zend_jit_next_is_send_result(opline)) {
17871798
i++;
1788-
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
1789-
if (!zend_jit_reuse_ip(&ctx)) {
1790-
goto jit_failure;
1791-
}
1799+
res_addr = ZEND_ADDR_REF_ZVAL(ir_ADD_OFFSET(jit_EX_CALL(jit), (opline+1)->result.var));
17921800
}
17931801
if (!zend_jit_concat(&ctx, opline,
17941802
op1_info, op2_info, res_addr,
@@ -2039,10 +2047,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
20392047
&& zend_jit_next_is_send_result(opline)
20402048
&& (!(op1_info & MAY_HAVE_DTOR) || !(op1_info & MAY_BE_RC1))) {
20412049
i++;
2042-
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
2043-
if (!zend_jit_reuse_ip(&ctx)) {
2044-
goto jit_failure;
2045-
}
2050+
res_addr = ZEND_ADDR_REF_ZVAL(ir_ADD_OFFSET(jit_EX_CALL(jit), (opline+1)->result.var));
20462051
}
20472052
}
20482053
if (!zend_jit_assign(&ctx, opline,

ext/opcache/jit/zend_jit_internal.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_loop_counter_helper(ZEND_OPCODE_H
240240

241241
ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_copy_extra_args_helper(ZEND_OPCODE_HANDLER_ARGS);
242242
ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_copy_extra_args_helper_no_skip_recv(ZEND_OPCODE_HANDLER_ARGS);
243-
bool ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D);
244-
bool ZEND_FASTCALL zend_jit_nodiscard_helper(OPLINE_D);
245-
bool ZEND_FASTCALL zend_jit_deprecated_nodiscard_helper(OPLINE_D);
243+
bool ZEND_FASTCALL zend_jit_deprecated_helper(zend_execute_data *call);
244+
bool ZEND_FASTCALL zend_jit_nodiscard_helper(zend_execute_data *call);
245+
bool ZEND_FASTCALL zend_jit_deprecated_nodiscard_helper(zend_execute_data *call);
246246
void ZEND_FASTCALL zend_jit_undefined_long_key(EXECUTE_DATA_D);
247247
void ZEND_FASTCALL zend_jit_undefined_long_key_ex(zend_long key EXECUTE_DATA_DC);
248248
void ZEND_FASTCALL zend_jit_undefined_string_key(EXECUTE_DATA_D);
@@ -446,6 +446,8 @@ typedef struct _zend_jit_trace_exit_info {
446446
int32_t poly_this_ref;
447447
int8_t poly_func_reg;
448448
int8_t poly_this_reg;
449+
int32_t call_ref;
450+
int8_t call_reg;
449451
} zend_jit_trace_exit_info;
450452

451453
typedef struct _zend_jit_trace_stack {

0 commit comments

Comments
 (0)