diff --git a/ext/opcache/jit/zend_jit_ir.c b/ext/opcache/jit/zend_jit_ir.c index ea7ed81d5f18..0f14cc61fb9b 100644 --- a/ext/opcache/jit/zend_jit_ir.c +++ b/ext/opcache/jit/zend_jit_ir.c @@ -43,6 +43,14 @@ # define ZREG_FP 14 /* IR_REG_R14 */ # define ZREG_IP 15 /* IR_REG_R15 */ # endif +# if defined(__linux__) && defined(__LP64__) +/* IR_EXITCALL saves both registers. Use one that the VM does not use for FP or IP. */ +# if ZEND_VM_KIND == ZEND_VM_KIND_HYBRID +# define ZREG_TRACE_NUM 12 /* IR_REG_R12 */ +# elif ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL +# define ZREG_TRACE_NUM 14 /* IR_REG_R14 */ +# endif +# endif # define ZREG_FIRST_FPR 16 # if defined(_WIN64) # define IR_REGSET_PRESERVED ((1<<3) | (1<<5) | (1<<6) | (1<<7) | (1<<12) | (1<<13) | (1<<14) | (1<<15)) @@ -68,6 +76,11 @@ # define ZREG_FP 27 /* IR_REG_X27 */ # define ZREG_IP 28 /* IR_REG_X28 */ # endif +# if defined(__linux__) && defined(__LP64__) \ + && (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) +/* X22 is callee-saved, captured by IR_EXITCALL. */ +# define ZREG_TRACE_NUM 22 /* IR_REG_X22 */ +# endif # define ZREG_FIRST_FPR 32 # define IR_REGSET_PRESERVED ((1<<19) | (1<<20) | (1<<21) | (1<<22) | (1<<23) | \ (1<<24) | (1<<25) | (1<<26) | (1<<27) | (1<<28)) /* all preserved registers */ @@ -2498,6 +2511,11 @@ static int zend_jit_trace_exit_stub(zend_jit_ctx *jit) { ir_ref ref, ret, if_zero, addr; +#ifdef ZREG_TRACE_NUM + /* Keep the trace number intact until IR_EXITCALL captures the registers. */ + jit->ctx.fixed_regset |= 1u << ZREG_TRACE_NUM; +#endif + // EX(opline) = opline ir_STORE(jit_EX(opline), jit_IP(jit)); @@ -17706,7 +17724,12 @@ static int zend_jit_trace_start(zend_jit_ctx *jit, zend_jit_preserve_parent_regs(jit, ssa, parent, exit_num); +#ifdef ZREG_TRACE_NUM + jit->ctx.fixed_regset |= 1u << ZREG_TRACE_NUM; + ir_RSTORE(ZREG_TRACE_NUM, ir_CONST_U32(trace_num)); +#else ir_STORE(jit_EG(jit_trace_num), ir_CONST_U32(trace_num)); +#endif return 1; } diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c index a344f4e1ea86..24f5c3906da4 100644 --- a/ext/opcache/jit/zend_jit_trace.c +++ b/ext/opcache/jit/zend_jit_trace.c @@ -8759,7 +8759,11 @@ int ZEND_FASTCALL zend_jit_trace_hot_side(zend_execute_data *execute_data, uint3 int ZEND_FASTCALL zend_jit_trace_exit(uint32_t exit_num, zend_jit_registers_buf *regs) { +#ifdef ZREG_TRACE_NUM + uint32_t trace_num = (uint32_t) regs->gpr[ZREG_TRACE_NUM]; +#else uint32_t trace_num = EG(jit_trace_num); +#endif zend_execute_data *execute_data = EG(current_execute_data); const zend_op *orig_opline = EX(opline); const zend_op *opline;