Skip to content

Commit 3958d5b

Browse files
committed
JIT for ECHO and variable string operands
1 parent 282265b commit 3958d5b

File tree

3 files changed

+49
-21
lines changed

3 files changed

+49
-21
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,11 +2795,11 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
27952795
}
27962796
goto done;
27972797
case ZEND_ECHO:
2798-
if (opline->op1_type != IS_CONST
2799-
|| Z_TYPE_P(RT_CONSTANT(opline, opline->op1)) != IS_STRING) {
2798+
op1_info = OP1_INFO();
2799+
if ((op1_info & (MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF)) != MAY_BE_STRING) {
28002800
break;
28012801
}
2802-
if (!zend_jit_echo(&dasm_state, opline, op_array)) {
2802+
if (!zend_jit_echo(&dasm_state, opline, op_array, op1_info)) {
28032803
goto jit_failure;
28042804
}
28052805
goto done;

ext/opcache/jit/zend_jit_trace.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
12421242
case ZEND_JMPZNZ:
12431243
case ZEND_JMPZ_EX:
12441244
case ZEND_JMPNZ_EX:
1245+
case ZEND_ECHO:
12451246
if (tssa->ops[idx].op1_use >= 0 && op1_type != IS_UNKNOWN) {
12461247
zend_ssa_var_info *info = &ssa_var_info[ssa_ops[idx].op1_use];
12471248
if ((info->type & (MAY_BE_ANY|MAY_BE_UNDEF)) != (1 << op1_type)) {
@@ -2624,11 +2625,12 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
26242625
}
26252626
goto done;
26262627
case ZEND_ECHO:
2627-
if (opline->op1_type != IS_CONST
2628-
|| Z_TYPE_P(RT_CONSTANT(opline, opline->op1)) != IS_STRING) {
2628+
op1_info = OP1_INFO();
2629+
CHECK_OP1_TRACE_TYPE();
2630+
if ((op1_info & (MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF)) != MAY_BE_STRING) {
26292631
break;
26302632
}
2631-
if (!zend_jit_echo(&dasm_state, opline, op_array)) {
2633+
if (!zend_jit_echo(&dasm_state, opline, op_array, op1_info)) {
26322634
goto jit_failure;
26332635
}
26342636
goto done;

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10459,31 +10459,57 @@ static int zend_jit_free(dasm_State **Dst, const zend_op *opline, const zend_op_
1045910459
return 1;
1046010460
}
1046110461

10462-
static int zend_jit_echo(dasm_State **Dst, const zend_op *opline, const zend_op_array *op_array)
10462+
static int zend_jit_echo(dasm_State **Dst, const zend_op *opline, const zend_op_array *op_array, uint32_t op1_info)
1046310463
{
1046410464
zval *zv;
1046510465
size_t len;
1046610466

10467-
ZEND_ASSERT(opline->op1_type == IS_CONST);
10468-
zv = RT_CONSTANT(opline, opline->op1);
10469-
ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING);
10470-
len = Z_STRLEN_P(zv);
10467+
if (opline->op1_type == IS_CONST) {
10468+
zv = RT_CONSTANT(opline, opline->op1);
10469+
ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING);
10470+
len = Z_STRLEN_P(zv);
1047110471

10472-
if (len > 0) {
10473-
const char *str = Z_STRVAL_P(zv);
10472+
if (len > 0) {
10473+
const char *str = Z_STRVAL_P(zv);
10474+
10475+
| SAVE_VALID_OPLINE opline, r0
10476+
|.if X64
10477+
| LOAD_ADDR CARG1, str
10478+
| LOAD_ADDR CARG2, len
10479+
| EXT_CALL zend_write, r0
10480+
|.else
10481+
| sub r4, 8
10482+
| push len
10483+
| push str
10484+
| EXT_CALL zend_write, r0
10485+
| add r4, 16
10486+
|.endif
10487+
if (!zend_jit_check_exception(Dst)) {
10488+
return 0;
10489+
}
10490+
}
10491+
} else {
10492+
zend_jit_addr op1_addr = OP1_ADDR();
10493+
10494+
ZEND_ASSERT((op1_info & (MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF)) == MAY_BE_STRING);
1047410495

1047510496
| SAVE_VALID_OPLINE opline, r0
10497+
| GET_ZVAL_PTR r0, op1_addr
1047610498
|.if X64
10477-
| LOAD_ADDR CARG1, str
10478-
| LOAD_ADDR CARG2, len
10479-
| EXT_CALL zend_write, r0
10499+
| lea CARG1, aword [r0 + offsetof(zend_string, val)]
10500+
| mov CARG2, aword [r0 + offsetof(zend_string, len)]
10501+
| EXT_CALL zend_write, r0
1048010502
|.else
10481-
| sub r4, 8
10482-
| push len
10483-
| push str
10484-
| EXT_CALL zend_write, r0
10485-
| add r4, 16
10503+
| sub r4, 8
10504+
| push aword [r0 + offsetof(zend_string, len)]
10505+
| add r0, offsetof(zend_string, val)
10506+
| push r0
10507+
| EXT_CALL zend_write, r0
10508+
| add r4, 16
1048610509
|.endif
10510+
if (opline->op1_type & (IS_VAR|IS_TMP_VAR)) {
10511+
| ZVAL_PTR_DTOR op1_addr, op1_info, 0, 0, opline
10512+
}
1048710513
if (!zend_jit_check_exception(Dst)) {
1048810514
return 0;
1048910515
}

0 commit comments

Comments
 (0)