Skip to content

Commit 620142c

Browse files
committed
Revert "Revert "JIT build fix""
This reverts commit 4e2f958.
1 parent 4e2f958 commit 620142c

File tree

9 files changed

+61
-79
lines changed

9 files changed

+61
-79
lines changed

Zend/Optimizer/dfa_pass.c

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,7 @@ int zend_dfa_optimize_calls(zend_op_array *op_array, zend_ssa *ssa)
466466
int var_num = ssa_op->op1_use;
467467
zend_ssa_var *var = ssa->vars + var_num;
468468

469-
if (ssa_op->op1_def >= 0) {
470-
zend_ssa_replace_op1_def_op1_use(ssa, ssa_op);
471-
}
472-
469+
ZEND_ASSERT(ssa_op->op1_def < 0);
473470
zend_ssa_unlink_use_chain(ssa, op_num, ssa_op->op1_use);
474471
ssa_op->op1_use = -1;
475472
ssa_op->op1_use_chain = -1;
@@ -1069,49 +1066,73 @@ static bool zend_dfa_try_to_replace_result(zend_op_array *op_array, zend_ssa *ss
10691066
return 0;
10701067
}
10711068

1069+
static bool op_dominates(const zend_op_array *op_array, const zend_ssa *ssa, const zend_op *a, const zend_op *b)
1070+
{
1071+
uint32_t a_block = ssa->cfg.map[a - op_array->opcodes];
1072+
uint32_t b_block = ssa->cfg.map[b - op_array->opcodes];
1073+
if (a_block == b_block) {
1074+
return a < b;
1075+
} else {
1076+
return dominates(ssa->cfg.blocks, a_block, b_block);
1077+
}
1078+
}
1079+
1080+
static bool op_dominates_all_uses(const zend_op_array *op_array, const zend_ssa *ssa, int start) {
1081+
int use;
1082+
FOREACH_USE(ssa->vars + ssa->ops[start].op1_def, use) {
1083+
if (!op_dominates(op_array, ssa, op_array->opcodes + start, op_array->opcodes + use)) {
1084+
return false;
1085+
}
1086+
} FOREACH_USE_END();
1087+
return true;
1088+
}
1089+
10721090
/* Sets a flag on SEND ops when a copy can be a avoided. */
1073-
static void zend_dfa_optimize_send_copies(zend_op_array *op_array, zend_ssa *ssa)
1091+
static void zend_dfa_optimize_send_copies(zend_op_array *op_array, const zend_ssa *ssa)
10741092
{
1075-
/* func_get_args() and indirect accesses could make the optimization observable */
1076-
if (ssa->cfg.flags & (ZEND_FUNC_VARARG | ZEND_FUNC_INDIRECT_VAR_ACCESS)) {
1093+
/* func_get_args() etc could make the optimization observable */
1094+
if (ssa->cfg.flags & ZEND_FUNC_VARARG) {
10771095
return;
10781096
}
10791097

10801098
for (uint32_t i = 0; i < op_array->last; i++) {
1081-
zend_op *opline = op_array->opcodes + i;
1099+
const zend_op *opline = &op_array->opcodes[i];
10821100
if ((opline->opcode != ZEND_SEND_VAR && opline->opcode != ZEND_SEND_VAR_EX) || opline->op2_type != IS_UNUSED || opline->op1_type != IS_CV) {
10831101
continue;
10841102
}
1085-
1086-
zend_ssa_op *ssa_op = ssa->ops + i;
1087-
int op1_def = ssa_op->op1_def;
1088-
if (op1_def == -1) {
1089-
continue;
1090-
}
1091-
1092-
int ssa_cv = ssa_op->op1_use;
1093-
10941103
#if 0
1095-
/* Argument move must not be observable in backtraces */
1104+
/* NULL must not be visible in backtraces */
1105+
int ssa_cv = ssa->ops[i].op1_use;
10961106
if (ssa->vars[ssa_cv].var < op_array->num_args) {
10971107
continue;
10981108
}
10991109
#endif
1100-
11011110
/* Unsetting a CV is always fine if it gets overwritten afterwards.
11021111
* Since type inference often infers very wide types, we are very loose in matching types. */
11031112
uint32_t type = ssa->var_info[ssa_cv].type;
11041113
if ((type & (MAY_BE_REF|MAY_BE_UNDEF)) || !(type & MAY_BE_RC1) || !(type & (MAY_BE_STRING|MAY_BE_ARRAY))) {
11051114
continue;
11061115
}
11071116

1108-
zend_ssa_var *ssa_var = ssa->vars + op1_def;
1109-
1110-
if (ssa_var->no_val && !ssa_var->alias) {
1111-
/* Flag will be used by VM type spec handler */
1112-
opline->extended_value = 1;
1113-
} else if (opline->opcode == ZEND_SEND_VAR) {
1114-
zend_ssa_replace_op1_def_op1_use(ssa, ssa_op);
1117+
if (opline->opcode == ZEND_SEND_VAR) {
1118+
/* Check if the call dominates the assignment and the assignment dominates all the future uses of this SSA variable */
1119+
int next_use = ssa->ops[i].op1_use_chain;
1120+
if (next_use >= 0
1121+
&& op_array->opcodes[next_use].opcode == ZEND_ASSIGN
1122+
&& ssa->ops[next_use].op1_use == ssa_cv
1123+
&& ssa->ops[next_use].op2_use >= 0
1124+
&& op_dominates(op_array, ssa, opline, op_array->opcodes + next_use)) {
1125+
if (op_dominates_all_uses(op_array, ssa, next_use)) {
1126+
op_array->opcodes[i].extended_value = 1;
1127+
//fprintf(stderr, "yes optimize 1\n");
1128+
}
1129+
}
1130+
} else /* ZEND_SEND_VAR_EX */ {
1131+
ZEND_ASSERT(ssa->ops[i].op1_def != -1);
1132+
if (ssa->vars[ssa->ops[i].op1_def].no_val) {
1133+
op_array->opcodes[i].extended_value = 1;
1134+
//fprintf(stderr, "yes optimize 2\n");
1135+
}
11151136
}
11161137
}
11171138
}
@@ -1134,14 +1155,6 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx
11341155
ssa_verify_integrity(op_array, ssa, "before dfa");
11351156
#endif
11361157

1137-
/* Optimization should not be done on main because of globals. */
1138-
if (op_array->function_name) {
1139-
zend_dfa_optimize_send_copies(op_array, ssa);
1140-
#if ZEND_DEBUG_DFA
1141-
ssa_verify_integrity(op_array, ssa, "after optimize send copies");
1142-
#endif
1143-
}
1144-
11451158
if (ZEND_OPTIMIZER_PASS_8 & ctx->optimization_level) {
11461159
if (sccp_optimize_op_array(ctx, op_array, ssa, call_map)) {
11471160
remove_nops = 1;
@@ -1182,6 +1195,11 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx
11821195
#endif
11831196
}
11841197

1198+
/* Optimization should not be done on main because of globals. */
1199+
if (op_array->function_name) {
1200+
zend_dfa_optimize_send_copies(op_array, ssa);
1201+
}
1202+
11851203
for (v = op_array->last_var; v < ssa->vars_count; v++) {
11861204

11871205
op_1 = ssa->vars[v].definition;

Zend/Optimizer/sccp.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ typedef struct _sccp_ctx {
9898
#define MAKE_TOP(zv) (Z_TYPE_INFO_P(zv) = TOP)
9999
#define MAKE_BOT(zv) (Z_TYPE_INFO_P(zv) = BOT)
100100

101-
static void scp_dump_value(const zval *zv) {
101+
static void scp_dump_value(zval *zv) {
102102
if (IS_TOP(zv)) {
103103
fprintf(stderr, " top");
104104
} else if (IS_BOT(zv)) {
@@ -245,8 +245,6 @@ static bool can_replace_op1(
245245
case ZEND_SEND_USER:
246246
case ZEND_FE_RESET_RW:
247247
return 0;
248-
case ZEND_SEND_VAR:
249-
return ssa_op->op1_def == -1;
250248
/* Do not accept CONST */
251249
case ZEND_ROPE_ADD:
252250
case ZEND_ROPE_END:
@@ -1052,12 +1050,6 @@ static void sccp_visit_instr(scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_o
10521050
case ZEND_SEND_VAL:
10531051
case ZEND_SEND_VAR:
10541052
{
1055-
if (opline->opcode == ZEND_SEND_VAR) {
1056-
/* TODO ? */
1057-
/* Can be UNDEF or a value copy */
1058-
SET_RESULT_BOT(op1);
1059-
}
1060-
10611053
/* If the value of a SEND for an ICALL changes, we need to reconsider the
10621054
* ICALL result value. Otherwise we can ignore the opcode. */
10631055
zend_call_info *call;
@@ -2042,14 +2034,8 @@ static int remove_call(sccp_ctx *ctx, zend_op *opline, zend_ssa_op *ssa_op)
20422034
&ssa->ops[call->caller_init_opline - op_array->opcodes]);
20432035

20442036
for (i = 0; i < call->num_args; i++) {
2045-
zend_op *op = call->arg_info[i].opline;
2046-
zend_ssa_op *this_ssa_op = &ssa->ops[op - op_array->opcodes];
2047-
2048-
if (op->opcode == ZEND_SEND_VAR && this_ssa_op->op1_def >= 0) {
2049-
zend_ssa_replace_op1_def_op1_use(ssa, this_ssa_op);
2050-
}
2051-
2052-
zend_ssa_remove_instr(ssa, op, this_ssa_op);
2037+
zend_ssa_remove_instr(ssa, call->arg_info[i].opline,
2038+
&ssa->ops[call->arg_info[i].opline - op_array->opcodes]);
20532039
}
20542040

20552041
// TODO: remove call_info completely???

Zend/Optimizer/zend_cfg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ ZEND_API void zend_cfg_compute_dominators_tree(const zend_op_array *op_array, ze
761761
}
762762
/* }}} */
763763

764-
static bool dominates(zend_basic_block *blocks, int a, int b) /* {{{ */
764+
bool dominates(const zend_basic_block *blocks, int a, int b) /* {{{ */
765765
{
766766
while (blocks[b].level > blocks[a].level) {
767767
b = blocks[b].idom;

Zend/Optimizer/zend_cfg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ void zend_cfg_remark_reachable_blocks(const zend_op_array *op_array, zend_cfg *c
120120
ZEND_API void zend_cfg_build_predecessors(zend_arena **arena, zend_cfg *cfg);
121121
ZEND_API void zend_cfg_compute_dominators_tree(const zend_op_array *op_array, zend_cfg *cfg);
122122
ZEND_API void zend_cfg_identify_loops(const zend_op_array *op_array, zend_cfg *cfg);
123+
bool dominates(const zend_basic_block *blocks, int a, int b);
123124

124125
END_EXTERN_C()
125126

Zend/Optimizer/zend_dfg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ static zend_always_inline void _zend_dfg_add_use_def_op(const zend_op_array *op_
152152
case ZEND_BIND_STATIC:
153153
case ZEND_SEND_VAR_NO_REF:
154154
case ZEND_SEND_VAR_NO_REF_EX:
155-
case ZEND_SEND_VAR:
156155
case ZEND_SEND_VAR_EX:
157156
case ZEND_SEND_FUNC_ARG:
158157
case ZEND_SEND_REF:
@@ -174,6 +173,7 @@ static zend_always_inline void _zend_dfg_add_use_def_op(const zend_op_array *op_
174173
goto add_op1_def;
175174
}
176175
break;
176+
case ZEND_SEND_VAR:
177177
case ZEND_CAST:
178178
case ZEND_QM_ASSIGN:
179179
case ZEND_JMP_SET:

Zend/Optimizer/zend_inference.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2950,9 +2950,6 @@ static zend_always_inline zend_result _zend_update_type_info(
29502950
if (t1 & (MAY_BE_RC1|MAY_BE_REF)) {
29512951
tmp |= MAY_BE_RCN;
29522952
}
2953-
if ((t1 & (MAY_BE_ARRAY|MAY_BE_STRING)) && (t1 & MAY_BE_RC1) && !(t1 & (MAY_BE_UNDEF|MAY_BE_REF)) && ssa_vars[ssa_op->op1_def].no_val && !ssa_vars[ssa_op->op1_def].alias) {
2954-
tmp |= MAY_BE_UNDEF;
2955-
}
29562953
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
29572954
COPY_SSA_OBJ_TYPE(ssa_op->op1_use, ssa_op->op1_def);
29582955
}
@@ -2994,9 +2991,6 @@ static zend_always_inline zend_result _zend_update_type_info(
29942991
case ZEND_SEND_FUNC_ARG:
29952992
if (ssa_op->op1_def >= 0) {
29962993
tmp = (t1 & MAY_BE_UNDEF)|MAY_BE_REF|MAY_BE_RC1|MAY_BE_RCN|MAY_BE_ANY|MAY_BE_ARRAY_KEY_ANY|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF;
2997-
if (opline->opcode == ZEND_SEND_VAR_EX && (t1 & (MAY_BE_ARRAY|MAY_BE_STRING)) && (t1 & MAY_BE_RC1) && !(t1 & (MAY_BE_UNDEF|MAY_BE_REF)) && ssa_vars[ssa_op->op1_def].no_val && !ssa_vars[ssa_op->op1_def].alias) {
2998-
tmp |= MAY_BE_UNDEF;
2999-
}
30002994
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
30012995
}
30022996
break;

Zend/Optimizer/zend_ssa.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,13 @@
1818
*/
1919

2020
#include "zend_compile.h"
21+
#include "zend_cfg.h"
2122
#include "zend_dfg.h"
2223
#include "zend_ssa.h"
2324
#include "zend_dump.h"
2425
#include "zend_inference.h"
2526
#include "Optimizer/zend_optimizer_internal.h"
2627

27-
static bool dominates(const zend_basic_block *blocks, int a, int b) {
28-
while (blocks[b].level > blocks[a].level) {
29-
b = blocks[b].idom;
30-
}
31-
return a == b;
32-
}
33-
3428
static bool will_rejoin(
3529
const zend_cfg *cfg, const zend_dfg *dfg, const zend_basic_block *block,
3630
int other_successor, int exclude, int var) {
@@ -682,7 +676,6 @@ static zend_always_inline int _zend_ssa_rename_op(const zend_op_array *op_array,
682676
case ZEND_SEND_VAR_NO_REF:
683677
case ZEND_SEND_VAR_NO_REF_EX:
684678
case ZEND_SEND_VAR_EX:
685-
case ZEND_SEND_VAR:
686679
case ZEND_SEND_FUNC_ARG:
687680
case ZEND_SEND_REF:
688681
case ZEND_SEND_UNPACK:
@@ -703,6 +696,7 @@ static zend_always_inline int _zend_ssa_rename_op(const zend_op_array *op_array,
703696
goto add_op1_def;
704697
}
705698
break;
699+
case ZEND_SEND_VAR:
706700
case ZEND_CAST:
707701
case ZEND_QM_ASSIGN:
708702
case ZEND_JMP_SET:
@@ -1680,13 +1674,3 @@ void zend_ssa_rename_var_uses(zend_ssa *ssa, int old, int new, bool update_types
16801674
old_var->phi_use_chain = NULL;
16811675
}
16821676
/* }}} */
1683-
1684-
void zend_ssa_replace_op1_def_op1_use(zend_ssa *ssa, zend_ssa_op *ssa_op)
1685-
{
1686-
int op1_new = ssa_op->op1_use;
1687-
ZEND_ASSERT(op1_new >= 0);
1688-
ZEND_ASSERT(ssa_op->op1_def >= 0);
1689-
/* zend_ssa_rename_var_uses() clear use_chain & phi_use_chain for us */
1690-
zend_ssa_rename_var_uses(ssa, ssa_op->op1_def, op1_new, true);
1691-
zend_ssa_remove_op1_def(ssa, ssa_op);
1692-
}

Zend/Optimizer/zend_ssa.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ void zend_ssa_remove_uses_of_var(zend_ssa *ssa, int var_num);
159159
void zend_ssa_remove_block(zend_op_array *op_array, zend_ssa *ssa, int b);
160160
void zend_ssa_rename_var_uses(zend_ssa *ssa, int old_var, int new_var, bool update_types);
161161
void zend_ssa_remove_block_from_cfg(zend_ssa *ssa, int b);
162-
void zend_ssa_replace_op1_def_op1_use(zend_ssa *ssa, zend_ssa_op *ssa_op);
163162

164163
static zend_always_inline void _zend_ssa_remove_def(zend_ssa_var *var)
165164
{

ext/opcache/jit/zend_jit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static int zend_jit_assign_to_variable(dasm_State **Dst,
156156
zend_jit_addr res_addr,
157157
bool check_exception);
158158

159-
static bool dominates(const zend_basic_block *blocks, int a, int b) {
159+
bool dominates(const zend_basic_block *blocks, int a, int b) {
160160
while (blocks[b].level > blocks[a].level) {
161161
b = blocks[b].idom;
162162
}

0 commit comments

Comments
 (0)