Skip to content

Commit 5de50e2

Browse files
committed
Separate common code
1 parent d5dd9d5 commit 5de50e2

File tree

2 files changed

+55
-174
lines changed

2 files changed

+55
-174
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,6 +2109,17 @@ static zend_lifetime_interval** zend_jit_allocate_registers(const zend_op_array
21092109
return NULL;
21102110
}
21112111

2112+
static bool zend_jit_next_is_send_result(const zend_op *opline)
2113+
{
2114+
if (opline->result_type == IS_TMP_VAR
2115+
&& (opline+1)->opcode == ZEND_SEND_VAL
2116+
&& (opline+1)->op1_type == IS_TMP_VAR
2117+
&& (opline+1)->op1.var == opline->result.var) {
2118+
return 1;
2119+
}
2120+
return 0;
2121+
}
2122+
21122123
static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op *rt_opline)
21132124
{
21142125
int b, i, end;
@@ -2400,11 +2411,8 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
24002411
}
24012412
res_addr = RES_REG_ADDR();
24022413
if (Z_MODE(res_addr) != IS_REG
2403-
&& opline->result_type == IS_TMP_VAR
24042414
&& (i + 1) <= end
2405-
&& (opline+1)->opcode == ZEND_SEND_VAL
2406-
&& (opline+1)->op1_type == IS_TMP_VAR
2407-
&& (opline+1)->op1.var == opline->result.var) {
2415+
&& zend_jit_next_is_send_result(opline)) {
24082416
i++;
24092417
res_use_info = -1;
24102418
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
@@ -2454,11 +2462,8 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
24542462
}
24552463
res_addr = RES_REG_ADDR();
24562464
if (Z_MODE(res_addr) != IS_REG
2457-
&& opline->result_type == IS_TMP_VAR
24582465
&& (i + 1) <= end
2459-
&& (opline+1)->opcode == ZEND_SEND_VAL
2460-
&& (opline+1)->op1_type == IS_TMP_VAR
2461-
&& (opline+1)->op1.var == opline->result.var) {
2466+
&& zend_jit_next_is_send_result(opline)) {
24622467
i++;
24632468
res_use_info = -1;
24642469
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
@@ -2511,12 +2516,8 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
25112516
break;
25122517
}
25132518
res_addr = RES_REG_ADDR();
2514-
if (Z_MODE(res_addr) != IS_REG
2515-
&& opline->result_type == IS_TMP_VAR
2516-
&& (i + 1) <= end
2517-
&& (opline+1)->opcode == ZEND_SEND_VAL
2518-
&& (opline+1)->op1_type == IS_TMP_VAR
2519-
&& (opline+1)->op1.var == opline->result.var) {
2519+
if ((i + 1) <= end
2520+
&& zend_jit_next_is_send_result(opline)) {
25202521
i++;
25212522
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
25222523
if (!zend_jit_reuse_ip(&dasm_state)) {
@@ -2765,11 +2766,8 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
27652766
res_addr = RES_REG_ADDR();
27662767
res_info = RES_INFO();
27672768
if (Z_MODE(res_addr) != IS_REG
2768-
&& opline->result_type == IS_TMP_VAR
27692769
&& (i + 1) <= end
2770-
&& (opline+1)->opcode == ZEND_SEND_VAL
2771-
&& (opline+1)->op1_type == IS_TMP_VAR
2772-
&& (opline+1)->op1.var == opline->result.var
2770+
&& zend_jit_next_is_send_result(opline)
27732771
&& (!(op1_info & MAY_HAVE_DTOR) || !(op1_info & MAY_BE_RC1))) {
27742772
i++;
27752773
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);

ext/opcache/jit/zend_jit_trace.c

Lines changed: 39 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ static const void **zend_jit_exit_groups = NULL;
2828
#define ZEND_JIT_TRACE_STOP_DESCRIPTION(name, description) \
2929
description,
3030

31-
#define USE_ABSTRACT_STACK_FOR_RES_USE_INFO 1
32-
3331
static const char * zend_jit_trace_stop_description[] = {
3432
ZEND_JIT_TRACE_STOP(ZEND_JIT_TRACE_STOP_DESCRIPTION)
3533
};
@@ -3574,6 +3572,37 @@ static bool zend_jit_may_skip_comparison(const zend_op *opline, const zend_ssa_o
35743572
return 0;
35753573
}
35763574

3575+
static bool zend_jit_trace_next_is_send_result(const zend_op *opline,
3576+
zend_jit_trace_rec *p,
3577+
zend_jit_trace_stack_frame *frame)
3578+
{
3579+
if (opline->result_type == IS_TMP_VAR
3580+
&& (p+1)->op == ZEND_JIT_TRACE_VM
3581+
&& (p+1)->opline == opline + 1
3582+
&& ((opline+1)->opcode == ZEND_SEND_VAL
3583+
|| ((opline+1)->opcode == ZEND_SEND_VAL_EX
3584+
&& frame
3585+
&& frame->call
3586+
&& frame->call->func
3587+
&& !ARG_MUST_BE_SENT_BY_REF(frame->call->func, (opline+1)->op2.num)))
3588+
&& (opline+1)->op1_type == IS_TMP_VAR
3589+
&& (opline+1)->op2_type != IS_CONST /* Named parameters not supported in JIT */
3590+
&& (opline+1)->op1.var == opline->result.var) {
3591+
3592+
if (frame->call
3593+
&& frame->call->func
3594+
&& frame->call->func->type == ZEND_USER_FUNCTION) {
3595+
uint8_t res_type = (p+1)->op1_type;
3596+
3597+
if (res_type != IS_UNKNOWN && !(res_type & IS_TRACE_REFERENCE) ) {
3598+
zend_jit_trace_send_type(opline+1, frame->call, res_type);
3599+
}
3600+
}
3601+
return 1;
3602+
}
3603+
return 0;
3604+
}
3605+
35773606
static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t parent_trace, uint32_t exit_num)
35783607
{
35793608
const void *handler = NULL;
@@ -3930,22 +3959,9 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
39303959
break;
39313960
}
39323961
if (opline->result_type != IS_UNUSED) {
3933-
#if USE_ABSTRACT_STACK_FOR_RES_USE_INFO
39343962
res_use_info = zend_jit_trace_type_to_info(
39353963
STACK_MEM_TYPE(stack, EX_VAR_TO_NUM(opline->result.var)))
39363964
& (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE);
3937-
#else
3938-
res_use_info = -1;
3939-
if (opline->result_type == IS_CV) {
3940-
zend_jit_addr res_use_addr = RES_USE_REG_ADDR();
3941-
3942-
if (Z_MODE(res_use_addr) != IS_REG
3943-
|| Z_LOAD(res_use_addr)
3944-
|| Z_STORE(res_use_addr)) {
3945-
res_use_info = RES_USE_INFO();
3946-
}
3947-
}
3948-
#endif
39493965
res_info = RES_INFO();
39503966
res_addr = RES_REG_ADDR();
39513967
} else {
@@ -3997,55 +4013,17 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
39974013
}
39984014
res_addr = RES_REG_ADDR();
39994015
if (Z_MODE(res_addr) != IS_REG
4000-
&& opline->result_type == IS_TMP_VAR
4001-
&& (p+1)->op == ZEND_JIT_TRACE_VM
4002-
&& (p+1)->opline == opline + 1
4003-
&& ((opline+1)->opcode == ZEND_SEND_VAL
4004-
|| ((opline+1)->opcode == ZEND_SEND_VAL_EX
4005-
&& frame
4006-
&& frame->call
4007-
&& frame->call->func
4008-
&& !ARG_MUST_BE_SENT_BY_REF(frame->call->func, (opline+1)->op2.num)))
4009-
&& (opline+1)->op1_type == IS_TMP_VAR
4010-
&& (opline+1)->op2_type != IS_CONST /* Named parameters not supported in JIT */
4011-
&& (opline+1)->op1.var == opline->result.var) {
4012-
p++;
4013-
if (frame->call) {
4014-
uint8_t res_type = p->op1_type;
4015-
if (res_type & IS_TRACE_REFERENCE) {
4016-
res_type = IS_UNKNOWN;
4017-
}
4018-
if (res_type != IS_UNKNOWN) {
4019-
zend_jit_trace_send_type(opline+1, frame->call, res_type);
4020-
}
4021-
}
4022-
while ((p+1)->op == ZEND_JIT_TRACE_OP1_TYPE ||
4023-
(p+1)->op == ZEND_JIT_TRACE_OP2_TYPE) {
4024-
p++;
4025-
}
4016+
&& zend_jit_trace_next_is_send_result(opline, p, frame)) {
40264017
send_result = 1;
40274018
res_use_info = -1;
40284019
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
40294020
if (!zend_jit_reuse_ip(&dasm_state)) {
40304021
goto jit_failure;
40314022
}
40324023
} else {
4033-
#if USE_ABSTRACT_STACK_FOR_RES_USE_INFO
40344024
res_use_info = zend_jit_trace_type_to_info(
40354025
STACK_MEM_TYPE(stack, EX_VAR_TO_NUM(opline->result.var)))
40364026
& (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE);
4037-
#else
4038-
res_use_info = -1;
4039-
if (opline->result_type == IS_CV) {
4040-
zend_jit_addr res_use_addr = RES_USE_REG_ADDR();
4041-
4042-
if (Z_MODE(res_use_addr) != IS_REG
4043-
|| Z_LOAD(res_use_addr)
4044-
|| Z_STORE(res_use_addr)) {
4045-
res_use_info = RES_USE_INFO();
4046-
}
4047-
}
4048-
#endif
40494027
}
40504028
res_info = RES_INFO();
40514029
if (!zend_jit_long_math(&dasm_state, opline,
@@ -4077,57 +4055,17 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
40774055
}
40784056
res_addr = RES_REG_ADDR();
40794057
if (Z_MODE(res_addr) != IS_REG
4080-
&& opline->result_type == IS_TMP_VAR
4081-
&& (p+1)->op == ZEND_JIT_TRACE_VM
4082-
&& (p+1)->opline == opline + 1
4083-
&& ((opline+1)->opcode == ZEND_SEND_VAL
4084-
|| ((opline+1)->opcode == ZEND_SEND_VAL_EX
4085-
&& frame
4086-
&& frame->call
4087-
&& frame->call->func
4088-
&& !ARG_MUST_BE_SENT_BY_REF(frame->call->func, (opline+1)->op2.num)))
4089-
&& (opline+1)->op1_type == IS_TMP_VAR
4090-
&& (opline+1)->op2_type != IS_CONST /* Named parameters not supported in JIT */
4091-
&& (opline+1)->op1.var == opline->result.var) {
4092-
p++;
4093-
if (frame->call
4094-
&& frame->call->func
4095-
&& frame->call->func->type == ZEND_USER_FUNCTION) {
4096-
uint8_t res_type = p->op1_type;
4097-
if (res_type & IS_TRACE_REFERENCE) {
4098-
res_type = IS_UNKNOWN;
4099-
}
4100-
if (res_type != IS_UNKNOWN) {
4101-
zend_jit_trace_send_type(opline+1, frame->call, res_type);
4102-
}
4103-
}
4104-
while ((p+1)->op == ZEND_JIT_TRACE_OP1_TYPE ||
4105-
(p+1)->op == ZEND_JIT_TRACE_OP2_TYPE) {
4106-
p++;
4107-
}
4058+
&& zend_jit_trace_next_is_send_result(opline, p, frame)) {
41084059
send_result = 1;
41094060
res_use_info = -1;
41104061
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
41114062
if (!zend_jit_reuse_ip(&dasm_state)) {
41124063
goto jit_failure;
41134064
}
41144065
} else {
4115-
#if USE_ABSTRACT_STACK_FOR_RES_USE_INFO
41164066
res_use_info = zend_jit_trace_type_to_info(
41174067
STACK_MEM_TYPE(stack, EX_VAR_TO_NUM(opline->result.var)))
41184068
& (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE);
4119-
#else
4120-
res_use_info = -1;
4121-
if (opline->result_type == IS_CV) {
4122-
zend_jit_addr res_use_addr = RES_USE_REG_ADDR();
4123-
4124-
if (Z_MODE(res_use_addr) != IS_REG
4125-
|| Z_LOAD(res_use_addr)
4126-
|| Z_STORE(res_use_addr)) {
4127-
res_use_info = RES_USE_INFO();
4128-
}
4129-
}
4130-
#endif
41314069
}
41324070
res_info = RES_INFO();
41334071
if (opline->opcode == ZEND_ADD &&
@@ -4165,35 +4103,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
41654103
break;
41664104
}
41674105
res_addr = RES_REG_ADDR();
4168-
if (Z_MODE(res_addr) != IS_REG
4169-
&& opline->result_type == IS_TMP_VAR
4170-
&& (p+1)->op == ZEND_JIT_TRACE_VM
4171-
&& (p+1)->opline == opline + 1
4172-
&& ((opline+1)->opcode == ZEND_SEND_VAL
4173-
|| ((opline+1)->opcode == ZEND_SEND_VAL_EX
4174-
&& frame
4175-
&& frame->call
4176-
&& frame->call->func
4177-
&& !ARG_MUST_BE_SENT_BY_REF(frame->call->func, (opline+1)->op2.num)))
4178-
&& (opline+1)->op1_type == IS_TMP_VAR
4179-
&& (opline+1)->op2_type != IS_CONST /* Named parameters not supported in JIT */
4180-
&& (opline+1)->op1.var == opline->result.var) {
4181-
p++;
4182-
if (frame->call
4183-
&& frame->call->func
4184-
&& frame->call->func->type == ZEND_USER_FUNCTION) {
4185-
uint8_t res_type = p->op1_type;
4186-
if (res_type & IS_TRACE_REFERENCE) {
4187-
res_type = IS_UNKNOWN;
4188-
}
4189-
if (res_type != IS_UNKNOWN) {
4190-
zend_jit_trace_send_type(opline+1, frame->call, res_type);
4191-
}
4192-
}
4193-
while ((p+1)->op == ZEND_JIT_TRACE_OP1_TYPE ||
4194-
(p+1)->op == ZEND_JIT_TRACE_OP2_TYPE) {
4195-
p++;
4196-
}
4106+
if (zend_jit_trace_next_is_send_result(opline, p, frame)) {
41974107
send_result = 1;
41984108
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
41994109
if (!zend_jit_reuse_ip(&dasm_state)) {
@@ -4616,34 +4526,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
46164526
res_addr = RES_REG_ADDR();
46174527
res_info = RES_INFO();
46184528
if (Z_MODE(res_addr) != IS_REG
4619-
&& opline->result_type == IS_TMP_VAR
4620-
&& (p+1)->op == ZEND_JIT_TRACE_VM
4621-
&& (p+1)->opline == opline + 1
4622-
&& ((opline+1)->opcode == ZEND_SEND_VAL
4623-
|| ((opline+1)->opcode == ZEND_SEND_VAL_EX
4624-
&& frame
4625-
&& frame->call
4626-
&& frame->call->func
4627-
&& !ARG_MUST_BE_SENT_BY_REF(frame->call->func, (opline+1)->op2.num)))
4628-
&& (opline+1)->op1_type == IS_TMP_VAR
4629-
&& (opline+1)->op2_type != IS_CONST /* Named parameters not supported in JIT */
4630-
&& (opline+1)->op1.var == opline->result.var) {
4631-
p++;
4632-
if (frame->call
4633-
&& frame->call->func
4634-
&& frame->call->func->type == ZEND_USER_FUNCTION) {
4635-
uint8_t res_type = p->op1_type;
4636-
if (res_type & IS_TRACE_REFERENCE) {
4637-
res_type = IS_UNKNOWN;
4638-
}
4639-
if (res_type != IS_UNKNOWN) {
4640-
zend_jit_trace_send_type(opline+1, frame->call, res_type);
4641-
}
4642-
}
4643-
while ((p+1)->op == ZEND_JIT_TRACE_OP1_TYPE ||
4644-
(p+1)->op == ZEND_JIT_TRACE_OP2_TYPE) {
4645-
p++;
4646-
}
4529+
&& zend_jit_trace_next_is_send_result(opline, p, frame)) {
46474530
send_result = 1;
46484531
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
46494532
if (!zend_jit_reuse_ip(&dasm_state)) {
@@ -4682,13 +4565,9 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
46824565
op1_info = OP1_INFO();
46834566
CHECK_OP1_TRACE_TYPE();
46844567
res_info = RES_INFO();
4685-
#if USE_ABSTRACT_STACK_FOR_RES_USE_INFO
46864568
res_use_info = zend_jit_trace_type_to_info(
46874569
STACK_MEM_TYPE(stack, EX_VAR_TO_NUM(opline->result.var)))
46884570
& (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE);
4689-
#else
4690-
res_use_info = MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE;
4691-
#endif
46924571
if (!zend_jit_qm_assign(&dasm_state, opline,
46934572
op1_info, op1_addr, op1_def_addr,
46944573
res_use_info, res_info, RES_REG_ADDR())) {
@@ -6077,6 +5956,10 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
60775956

60785957
if (send_result) {
60795958
ssa_op++;
5959+
p++;
5960+
if ((p+1)->op == ZEND_JIT_TRACE_OP1_TYPE) {
5961+
p++;
5962+
}
60805963
send_result = 0;
60815964
}
60825965
}

0 commit comments

Comments
 (0)