Skip to content

JIT: Don't reuse IP register for EX(call) #18392

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

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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
38 changes: 21 additions & 17 deletions ext/opcache/jit/zend_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_runtime_jit(ZEND_OPCODE_HANDLE

static int zend_jit_trace_op_len(const zend_op *opline);
static int zend_jit_trace_may_exit(const zend_op_array *op_array, const zend_op *opline);
static uint32_t zend_jit_trace_get_exit_point(const zend_op *to_opline, uint32_t flags);

static uint32_t zend_jit_trace_get_exit_point(zend_jit_ctx *ctx, const zend_op *to_opline, uint32_t flags);
static const void *zend_jit_trace_get_exit_addr(uint32_t n);
static void zend_jit_trace_add_code(const void *start, uint32_t size);
static zend_string *zend_jit_func_name(const zend_op_array *op_array);
Expand Down Expand Up @@ -802,6 +803,9 @@ static bool zend_jit_may_be_modified(const zend_function *func, const zend_op_ar
# pragma clang diagnostic ignored "-Wstring-compare"
#endif

static bool zend_jit_inc_call_level(uint8_t opcode);
static bool zend_jit_dec_call_level(uint8_t opcode);

#include "jit/zend_jit_ir.c"

#if defined(__clang__)
Expand Down Expand Up @@ -1608,6 +1612,18 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
call_level++;
}

#if ZEND_DEBUG && 0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debugging helper, will remove

{
const void *handler;
if (zend_jit_vm_kind == ZEND_VM_KIND_HYBRID) {
handler = zend_get_opcode_handler_func(opline);
} else {
handler = opline->handler;
}
ir_RSTORE(8, jit_CONST_FUNC(&ctx, (uintptr_t)handler, IR_FASTCALL_FUNC));
}
#endif

if (JIT_G(opt_level) >= ZEND_JIT_LEVEL_INLINE) {
switch (opline->opcode) {
case ZEND_PRE_INC:
Expand Down Expand Up @@ -1675,10 +1691,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
&& zend_jit_next_is_send_result(opline)) {
i++;
res_use_info = -1;
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
if (!zend_jit_reuse_ip(&ctx)) {
goto jit_failure;
}
res_addr = ZEND_ADDR_ARG(jit_EX_CALL(jit), (opline+1)->result.var);
} else {
res_use_info = -1;

Expand Down Expand Up @@ -1729,10 +1742,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
&& zend_jit_next_is_send_result(opline)) {
i++;
res_use_info = -1;
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
if (!zend_jit_reuse_ip(&ctx)) {
goto jit_failure;
}
res_addr = ZEND_ADDR_ARG(jit_EX_CALL(jit), (opline+1)->result.var);
} else {
res_use_info = -1;

Expand Down Expand Up @@ -1785,10 +1795,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
if ((i + 1) <= end
&& zend_jit_next_is_send_result(opline)) {
i++;
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
if (!zend_jit_reuse_ip(&ctx)) {
goto jit_failure;
}
res_addr = ZEND_ADDR_ARG(jit_EX_CALL(jit), (opline+1)->result.var);
}
if (!zend_jit_concat(&ctx, opline,
op1_info, op2_info, res_addr,
Expand Down Expand Up @@ -2039,10 +2046,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
&& zend_jit_next_is_send_result(opline)
&& (!(op1_info & MAY_HAVE_DTOR) || !(op1_info & MAY_BE_RC1))) {
i++;
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
if (!zend_jit_reuse_ip(&ctx)) {
goto jit_failure;
}
res_addr = ZEND_ADDR_ARG(jit_EX_CALL(jit), (opline+1)->result.var);
}
}
if (!zend_jit_assign(&ctx, opline,
Expand Down
18 changes: 15 additions & 3 deletions ext/opcache/jit/zend_jit_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "Zend/Optimizer/zend_func_info.h"
#include "Zend/Optimizer/zend_call_graph.h"

typedef struct _zend_jit_ctx zend_jit_ctx;

/* Address Encoding */
typedef uintptr_t zend_jit_addr;

Expand Down Expand Up @@ -62,6 +64,14 @@ typedef uintptr_t zend_jit_addr;
#define Z_SSA_VAR(addr) ((addr)>>_ZEND_ADDR_REG_SHIFT)
#define Z_IR_REF(addr) ((addr)>>_ZEND_ADDR_REG_SHIFT)

#define ZEND_ADDR_ARG(call, var) ZEND_ADDR_REF_ZVAL(ir_ADD_OFFSET(call, var))

#define Z_IS_ARG_ADDR(addr) \
(Z_MODE(addr) == IS_REF_ZVAL && ( \
Z_IR_REF(addr) == jit->call \
|| (jit->ctx.ir_base[Z_IR_REF(addr)].op == IR_ADD \
&& jit->ctx.ir_base[Z_IR_REF(addr)].op1 == jit->call)))

#define Z_STORE(addr) \
((jit->ra && jit->ra[Z_SSA_VAR(addr)].ref) ? \
(jit->ra[Z_SSA_VAR(addr)].flags & ZREG_STORE) : \
Expand Down Expand Up @@ -240,9 +250,9 @@ ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_loop_counter_helper(ZEND_OPCODE_H

ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_copy_extra_args_helper(ZEND_OPCODE_HANDLER_ARGS);
ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_copy_extra_args_helper_no_skip_recv(ZEND_OPCODE_HANDLER_ARGS);
bool ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D);
bool ZEND_FASTCALL zend_jit_nodiscard_helper(OPLINE_D);
bool ZEND_FASTCALL zend_jit_deprecated_nodiscard_helper(OPLINE_D);
bool ZEND_FASTCALL zend_jit_deprecated_helper(zend_execute_data *call);
bool ZEND_FASTCALL zend_jit_nodiscard_helper(zend_execute_data *call);
bool ZEND_FASTCALL zend_jit_deprecated_nodiscard_helper(zend_execute_data *call);
void ZEND_FASTCALL zend_jit_undefined_long_key(EXECUTE_DATA_D);
void ZEND_FASTCALL zend_jit_undefined_long_key_ex(zend_long key EXECUTE_DATA_DC);
void ZEND_FASTCALL zend_jit_undefined_string_key(EXECUTE_DATA_D);
Expand Down Expand Up @@ -446,6 +456,8 @@ typedef struct _zend_jit_trace_exit_info {
int32_t poly_this_ref;
int8_t poly_func_reg;
int8_t poly_this_reg;
int32_t call_ref;
int8_t call_reg;
Comment on lines +459 to +460
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deoptimization relied on EX(call) being in IP when ZEND_JIT_EXIT_RESTORE_CALL was set. I now use the SNAPSHOT mechanism so that deopt knows in which register the call actually is.

} zend_jit_trace_exit_info;

typedef struct _zend_jit_trace_stack {
Expand Down
Loading
Loading