php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
dfa_pass.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Zend OPcache |
4 +----------------------------------------------------------------------+
5 | Copyright (c) The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | https://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Dmitry Stogov <dmitry@php.net> |
16 +----------------------------------------------------------------------+
17*/
18
21#include "zend_API.h"
22#include "zend_constants.h"
23#include "zend_execute.h"
24#include "zend_vm.h"
25#include "zend_bitset.h"
26#include "zend_cfg.h"
27#include "zend_ssa.h"
28#include "zend_func_info.h"
29#include "zend_call_graph.h"
30#include "zend_inference.h"
31#include "zend_dump.h"
32
33#ifndef ZEND_DEBUG_DFA
34# define ZEND_DEBUG_DFA ZEND_DEBUG
35#endif
36
37#if ZEND_DEBUG_DFA
38# include "ssa_integrity.c"
39#endif
40
42{
43 uint32_t build_flags;
44
45 if (op_array->last_try_catch) {
46 /* TODO: we can't analyze functions with try/catch/finally ??? */
47 return FAILURE;
48 }
49
50 /* Build SSA */
51 memset(ssa, 0, sizeof(zend_ssa));
52
54
56 /* TODO: we can't analyze functions with indirect variable access ??? */
57 return FAILURE;
58 }
59
61
62 if (ctx->debug_level & ZEND_DUMP_DFA_CFG) {
63 zend_dump_op_array(op_array, ZEND_DUMP_CFG, "dfa cfg", &ssa->cfg);
64 }
65
66 /* Compute Dominators Tree */
68
69 /* Identify reducible and irreducible loops */
70 zend_cfg_identify_loops(op_array, &ssa->cfg);
71
73 zend_dump_dominators(op_array, &ssa->cfg);
74 }
75
76 build_flags = 0;
78 build_flags |= ZEND_SSA_DEBUG_LIVENESS;
79 }
80 if (ctx->debug_level & ZEND_DUMP_DFA_PHI) {
81 build_flags |= ZEND_SSA_DEBUG_PHI_PLACEMENT;
82 }
83 if (zend_build_ssa(&ctx->arena, ctx->script, op_array, build_flags, ssa) == FAILURE) {
84 return FAILURE;
85 }
86
87 if (ctx->debug_level & ZEND_DUMP_DFA_SSA) {
88 zend_dump_op_array(op_array, ZEND_DUMP_SSA, "dfa ssa", ssa);
89 }
90
91
92 zend_ssa_compute_use_def_chains(&ctx->arena, op_array, ssa);
93
95
96 zend_ssa_find_sccs(op_array, ssa);
97
98 if (zend_ssa_inference(&ctx->arena, op_array, ctx->script, ssa, ctx->optimization_level) == FAILURE) {
99 return FAILURE;
100 }
101
102 if (zend_ssa_escape_analysis(ctx->script, op_array, ssa) == FAILURE) {
103 return FAILURE;
104 }
105
107 zend_dump_ssa_variables(op_array, ssa, 0);
108 }
109
110 return SUCCESS;
111}
112
113static void zend_ssa_remove_nops(zend_op_array *op_array, zend_ssa *ssa, zend_optimizer_ctx *ctx)
114{
115 zend_basic_block *blocks = ssa->cfg.blocks;
116 zend_basic_block *blocks_end = blocks + ssa->cfg.blocks_count;
118 zend_func_info *func_info;
119 int j;
120 uint32_t i = 0;
121 uint32_t target = 0;
122 uint32_t *shiftlist;
123 ALLOCA_FLAG(use_heap);
124
125 shiftlist = (uint32_t *)do_alloca(sizeof(uint32_t) * op_array->last, use_heap);
126 memset(shiftlist, 0, sizeof(uint32_t) * op_array->last);
127 /* remove empty callee_info */
128 func_info = ZEND_FUNC_INFO(op_array);
129 if (func_info) {
130 zend_call_info **call_info = &func_info->callee_info;
131 while ((*call_info)) {
132 if ((*call_info)->caller_init_opline->opcode == ZEND_NOP) {
133 *call_info = (*call_info)->next_callee;
134 } else {
135 call_info = &(*call_info)->next_callee;
136 }
137 }
138 }
139
140 for (b = blocks; b < blocks_end; b++) {
142 if (b->len) {
143 uint32_t new_start, old_end;
144 while (i < b->start) {
145 shiftlist[i] = i - target;
146 i++;
147 }
148
150 /* Only keep the FREE for the loop var */
151 ZEND_ASSERT(op_array->opcodes[b->start].opcode == ZEND_FREE
152 || op_array->opcodes[b->start].opcode == ZEND_FE_FREE);
153 b->len = 1;
154 }
155
156 new_start = target;
157 old_end = b->start + b->len;
158 while (i < old_end) {
159 shiftlist[i] = i - target;
160 if (EXPECTED(op_array->opcodes[i].opcode != ZEND_NOP)) {
161 if (i != target) {
162 op_array->opcodes[target] = op_array->opcodes[i];
163 ssa->ops[target] = ssa->ops[i];
164 ssa->cfg.map[target] = b - blocks;
165 }
166 target++;
167 }
168 i++;
169 }
170 b->start = new_start;
171 if (target != old_end) {
172 zend_op *opline;
173 zend_op *new_opline;
174
175 b->len = target - b->start;
176 opline = op_array->opcodes + old_end - 1;
177 if (opline->opcode == ZEND_NOP) {
178 continue;
179 }
180
181 new_opline = op_array->opcodes + target - 1;
182 zend_optimizer_migrate_jump(op_array, new_opline, opline);
183 }
184 } else {
185 b->start = target;
186 }
187 } else {
188 b->start = target;
189 b->len = 0;
190 }
191 }
192
193 if (target != op_array->last) {
194 /* reset rest opcodes */
195 for (i = target; i < op_array->last; i++) {
196 MAKE_NOP(op_array->opcodes + i);
197 }
198
199 /* update SSA variables */
200 for (j = 0; j < ssa->vars_count; j++) {
201 if (ssa->vars[j].definition >= 0) {
202 ssa->vars[j].definition -= shiftlist[ssa->vars[j].definition];
203 }
204 if (ssa->vars[j].use_chain >= 0) {
205 ssa->vars[j].use_chain -= shiftlist[ssa->vars[j].use_chain];
206 }
207 }
208 for (i = 0; i < op_array->last; i++) {
209 if (ssa->ops[i].op1_use_chain >= 0) {
210 ssa->ops[i].op1_use_chain -= shiftlist[ssa->ops[i].op1_use_chain];
211 }
212 if (ssa->ops[i].op2_use_chain >= 0) {
213 ssa->ops[i].op2_use_chain -= shiftlist[ssa->ops[i].op2_use_chain];
214 }
215 if (ssa->ops[i].res_use_chain >= 0) {
216 ssa->ops[i].res_use_chain -= shiftlist[ssa->ops[i].res_use_chain];
217 }
218 }
219
220 /* update branch targets */
221 for (b = blocks; b < blocks_end; b++) {
222 if ((b->flags & ZEND_BB_REACHABLE) && b->len != 0) {
223 zend_op *opline = op_array->opcodes + b->start + b->len - 1;
224 zend_optimizer_shift_jump(op_array, opline, shiftlist);
225 }
226 }
227
228 /* update try/catch array */
229 for (j = 0; j < op_array->last_try_catch; j++) {
230 op_array->try_catch_array[j].try_op -= shiftlist[op_array->try_catch_array[j].try_op];
231 op_array->try_catch_array[j].catch_op -= shiftlist[op_array->try_catch_array[j].catch_op];
232 if (op_array->try_catch_array[j].finally_op) {
233 op_array->try_catch_array[j].finally_op -= shiftlist[op_array->try_catch_array[j].finally_op];
234 op_array->try_catch_array[j].finally_end -= shiftlist[op_array->try_catch_array[j].finally_end];
235 }
236 }
237
238 /* update call graph */
239 if (func_info) {
240 zend_call_info *call_info = func_info->callee_info;
241 while (call_info) {
242 call_info->caller_init_opline -=
243 shiftlist[call_info->caller_init_opline - op_array->opcodes];
244 if (call_info->caller_call_opline) {
245 call_info->caller_call_opline -=
246 shiftlist[call_info->caller_call_opline - op_array->opcodes];
247 }
248 call_info = call_info->next_callee;
249 }
250 }
251
252 op_array->last = target;
253 }
254 free_alloca(shiftlist, use_heap);
255}
256
257static bool safe_instanceof(zend_class_entry *ce1, zend_class_entry *ce2) {
258 if (ce1 == ce2) {
259 return 1;
260 }
261 if (!(ce1->ce_flags & ZEND_ACC_LINKED)) {
262 /* This case could be generalized, similarly to unlinked_instanceof */
263 return 0;
264 }
265 return instanceof_function(ce1, ce2);
266}
267
268static inline bool can_elide_list_type(
269 const zend_script *script, const zend_op_array *op_array,
270 const zend_ssa_var_info *use_info, zend_type type)
271{
272 zend_type *single_type;
273 /* For intersection: result==false is failure, default is success.
274 * For union: result==true is success, default is failure. */
275 bool is_intersection = ZEND_TYPE_IS_INTERSECTION(type);
276 ZEND_TYPE_FOREACH(type, single_type) {
277 if (ZEND_TYPE_HAS_LIST(*single_type)) {
278 ZEND_ASSERT(!is_intersection);
279 return can_elide_list_type(script, op_array, use_info, *single_type);
280 }
281 if (ZEND_TYPE_HAS_NAME(*single_type)) {
282 zend_string *lcname = zend_string_tolower(ZEND_TYPE_NAME(*single_type));
284 zend_string_release(lcname);
285 bool result = ce && safe_instanceof(use_info->ce, ce);
286 if (result == !is_intersection) {
287 return result;
288 }
289 }
291 return is_intersection;
292}
293
294static inline bool can_elide_return_type_check(
295 const zend_script *script, zend_op_array *op_array, zend_ssa *ssa, zend_ssa_op *ssa_op) {
296 zend_arg_info *arg_info = &op_array->arg_info[-1];
297 zend_ssa_var_info *use_info = &ssa->var_info[ssa_op->op1_use];
298 uint32_t use_type = use_info->type & (MAY_BE_ANY|MAY_BE_UNDEF);
299 if (use_type & MAY_BE_REF) {
300 return 0;
301 }
302
303 if (use_type & MAY_BE_UNDEF) {
304 use_type &= ~MAY_BE_UNDEF;
305 use_type |= MAY_BE_NULL;
306 }
307
308 uint32_t disallowed_types = use_type & ~ZEND_TYPE_PURE_MASK(arg_info->type);
309 if (!disallowed_types) {
310 /* Only contains allowed types. */
311 return true;
312 }
313
314 if (disallowed_types == MAY_BE_OBJECT && use_info->ce && ZEND_TYPE_IS_COMPLEX(arg_info->type)) {
315 return can_elide_list_type(script, op_array, use_info, arg_info->type);
316 }
317
318 return false;
319}
320
321static bool opline_supports_assign_contraction(
322 zend_op_array *op_array, zend_ssa *ssa, zend_op *opline, int src_var, uint32_t cv_var) {
323 if (opline->opcode == ZEND_NEW) {
324 /* see Zend/tests/generators/aborted_yield_during_new.phpt */
325 return 0;
326 }
327
328 /* Frameless calls override the return value, but the return value may overlap with the arguments. */
329 switch (opline->opcode) {
331 if ((opline + 1)->op1_type == IS_CV && (opline + 1)->op1.var == cv_var) return 0;
334 if (opline->op2_type == IS_CV && opline->op2.var == cv_var) return 0;
337 if (opline->op1_type == IS_CV && opline->op1.var == cv_var) return 0;
338 return 1;
339 }
340
341 if (opline->opcode == ZEND_DO_ICALL || opline->opcode == ZEND_DO_UCALL
342 || opline->opcode == ZEND_DO_FCALL || opline->opcode == ZEND_DO_FCALL_BY_NAME) {
343 /* Function calls may dtor the return value after it has already been written -- allow
344 * direct assignment only for types where a double-dtor does not matter. */
345 uint32_t type = ssa->var_info[src_var].type;
347 return !((type & MAY_BE_ANY) & ~simple);
348 }
349
350 if (opline->opcode == ZEND_POST_INC || opline->opcode == ZEND_POST_DEC) {
351 /* POST_INC/DEC write the result variable before performing the inc/dec. For $i = $i++
352 * eliding the temporary variable would thus yield an incorrect result. */
353 return opline->op1_type != IS_CV || opline->op1.var != cv_var;
354 }
355
356 if (opline->opcode == ZEND_INIT_ARRAY) {
357 /* INIT_ARRAY initializes the result array before reading key/value. */
358 return (opline->op1_type != IS_CV || opline->op1.var != cv_var)
359 && (opline->op2_type != IS_CV || opline->op2.var != cv_var);
360 }
361
362 if (opline->opcode == ZEND_CAST
363 && (opline->extended_value == IS_ARRAY || opline->extended_value == IS_OBJECT)) {
364 /* CAST to array/object may initialize the result to an empty array/object before
365 * reading the expression. */
366 return opline->op1_type != IS_CV || opline->op1.var != cv_var;
367 }
368
369 if ((opline->opcode == ZEND_ASSIGN_OP
370 || opline->opcode == ZEND_ASSIGN_OBJ
371 || opline->opcode == ZEND_ASSIGN_DIM
372 || opline->opcode == ZEND_ASSIGN_OBJ_OP
373 || opline->opcode == ZEND_ASSIGN_DIM_OP)
374 && opline->op1_type == IS_CV
375 && opline->op1.var == cv_var
376 && zend_may_throw(opline, &ssa->ops[ssa->vars[src_var].definition], op_array, ssa)) {
377 return 0;
378 }
379
380 return 1;
381}
382
383static bool variable_defined_or_used_in_range(zend_ssa *ssa, int var, int start, int end)
384{
385 while (start < end) {
386 const zend_ssa_op *ssa_op = &ssa->ops[start];
387 if ((ssa_op->op1_def >= 0 && ssa->vars[ssa_op->op1_def].var == var) ||
388 (ssa_op->op2_def >= 0 && ssa->vars[ssa_op->op2_def].var == var) ||
389 (ssa_op->result_def >= 0 && ssa->vars[ssa_op->result_def].var == var) ||
390 (ssa_op->op1_use >= 0 && ssa->vars[ssa_op->op1_use].var == var) ||
391 (ssa_op->op2_use >= 0 && ssa->vars[ssa_op->op2_use].var == var) ||
392 (ssa_op->result_use >= 0 && ssa->vars[ssa_op->result_use].var == var)
393 ) {
394 return 1;
395 }
396 start++;
397 }
398 return 0;
399}
400
402{
403 zend_func_info *func_info = ZEND_FUNC_INFO(op_array);
404 int removed_ops = 0;
405
406 if (func_info->callee_info) {
407 zend_call_info *call_info = func_info->callee_info;
408
409 do {
410 zend_op *op = call_info->caller_init_opline;
411
413 || (op->opcode == ZEND_FRAMELESS_ICALL_3 && (op + 1)->op1_type == IS_CONST))
414 && call_info->callee_func
415 && zend_string_equals_literal_ci(call_info->callee_func->common.function_name, "in_array")) {
416
417 bool strict = 0;
418 bool has_opdata = op->opcode == ZEND_FRAMELESS_ICALL_3;
419 ZEND_ASSERT(!call_info->is_prototype);
420
421 if (has_opdata) {
422 if (zend_is_true(CT_CONSTANT_EX(op_array, (op + 1)->op1.constant))) {
423 strict = 1;
424 }
425 }
426
427 if (op->op2_type == IS_CONST
428 && Z_TYPE_P(CT_CONSTANT_EX(op_array, op->op2.constant)) == IS_ARRAY) {
429 bool ok = 1;
430
431 HashTable *src = Z_ARRVAL_P(CT_CONSTANT_EX(op_array, op->op2.constant));
432 HashTable *dst;
433 zval *val, tmp;
434 zend_ulong idx;
435
436 ZVAL_TRUE(&tmp);
437 dst = zend_new_array(zend_hash_num_elements(src));
438 if (strict) {
440 if (Z_TYPE_P(val) == IS_STRING) {
441 zend_hash_add(dst, Z_STR_P(val), &tmp);
442 } else if (Z_TYPE_P(val) == IS_LONG) {
443 zend_hash_index_add(dst, Z_LVAL_P(val), &tmp);
444 } else {
446 ok = 0;
447 break;
448 }
450 } else {
454 ok = 0;
455 break;
456 }
457 zend_hash_add(dst, Z_STR_P(val), &tmp);
459 }
460
461 if (ok) {
462 ZVAL_ARR(&tmp, dst);
463
464 /* Update opcode */
465 op->opcode = ZEND_IN_ARRAY;
466 op->extended_value = strict;
467 op->op2.constant = zend_optimizer_add_literal(op_array, &tmp);
468 if (has_opdata) {
469 MAKE_NOP(op + 1);
470 removed_ops++;
471 }
472 }
473 }
474 }
475 call_info = call_info->next_callee;
476 } while (call_info);
477 }
478
479 return removed_ops;
480}
481
482static zend_always_inline void take_successor_0(zend_ssa *ssa, int block_num, zend_basic_block *block)
483{
484 if (block->successors_count == 2) {
485 if (block->successors[1] != block->successors[0]) {
486 zend_ssa_remove_predecessor(ssa, block_num, block->successors[1]);
487 }
488 block->successors_count = 1;
489 }
490}
491
492static zend_always_inline void take_successor_1(zend_ssa *ssa, int block_num, zend_basic_block *block)
493{
494 if (block->successors_count == 2) {
495 if (block->successors[1] != block->successors[0]) {
496 zend_ssa_remove_predecessor(ssa, block_num, block->successors[0]);
497 block->successors[0] = block->successors[1];
498 }
499 block->successors_count = 1;
500 }
501}
502
503static zend_always_inline void take_successor_ex(zend_ssa *ssa, int block_num, zend_basic_block *block, int target_block)
504{
505 int i;
506
507 for (i = 0; i < block->successors_count; i++) {
508 if (block->successors[i] != target_block) {
509 zend_ssa_remove_predecessor(ssa, block_num, block->successors[i]);
510 }
511 }
512 block->successors[0] = target_block;
513 block->successors_count = 1;
514}
515
516static void compress_block(zend_op_array *op_array, zend_basic_block *block)
517{
518 while (block->len > 0) {
519 zend_op *opline = &op_array->opcodes[block->start + block->len - 1];
520
521 if (opline->opcode == ZEND_NOP) {
522 block->len--;
523 } else {
524 break;
525 }
526 }
527}
528
529static void replace_predecessor(zend_ssa *ssa, int block_id, int old_pred, int new_pred) {
530 zend_basic_block *block = &ssa->cfg.blocks[block_id];
531 int *predecessors = &ssa->cfg.predecessors[block->predecessor_offset];
532 zend_ssa_phi *phi;
533
534 int i;
535 int old_pred_idx = -1;
536 int new_pred_idx = -1;
537 for (i = 0; i < block->predecessors_count; i++) {
538 if (predecessors[i] == old_pred) {
539 old_pred_idx = i;
540 }
541 if (predecessors[i] == new_pred) {
542 new_pred_idx = i;
543 }
544 }
545
546 ZEND_ASSERT(old_pred_idx != -1);
547 if (new_pred_idx == -1) {
548 /* If the new predecessor doesn't exist yet, simply rewire the old one */
549 predecessors[old_pred_idx] = new_pred;
550 } else {
551 /* Otherwise, rewiring the old predecessor would make the new predecessor appear
552 * twice, which violates our CFG invariants. Remove the old predecessor instead. */
553 memmove(
554 predecessors + old_pred_idx,
555 predecessors + old_pred_idx + 1,
556 sizeof(int) * (block->predecessors_count - old_pred_idx - 1)
557 );
558
559 /* Also remove the corresponding phi node entries */
560 for (phi = ssa->blocks[block_id].phis; phi; phi = phi->next) {
561 if (phi->pi >= 0) {
562 if (phi->pi == old_pred || phi->pi == new_pred) {
564 ssa, phi->ssa_var, phi->sources[0], /* update_types */ 0);
565 zend_ssa_remove_phi(ssa, phi);
566 }
567 } else {
568 memmove(
569 phi->sources + old_pred_idx,
570 phi->sources + old_pred_idx + 1,
571 sizeof(int) * (block->predecessors_count - old_pred_idx - 1)
572 );
573 }
574 }
575
576 block->predecessors_count--;
577 }
578}
579
580static void zend_ssa_replace_control_link(zend_op_array *op_array, zend_ssa *ssa, int from, int to, int new_to)
581{
582 zend_basic_block *src = &ssa->cfg.blocks[from];
583 zend_basic_block *old = &ssa->cfg.blocks[to];
584 zend_basic_block *dst = &ssa->cfg.blocks[new_to];
585 int i;
586 zend_op *opline;
587
588 for (i = 0; i < src->successors_count; i++) {
589 if (src->successors[i] == to) {
590 src->successors[i] = new_to;
591 }
592 }
593
594 if (src->len > 0) {
595 opline = op_array->opcodes + src->start + src->len - 1;
596 switch (opline->opcode) {
597 case ZEND_JMP:
598 case ZEND_FAST_CALL:
599 ZEND_ASSERT(ZEND_OP1_JMP_ADDR(opline) == op_array->opcodes + old->start);
600 ZEND_SET_OP_JMP_ADDR(opline, opline->op1, op_array->opcodes + dst->start);
601 break;
602 case ZEND_JMPZ:
603 case ZEND_JMPNZ:
604 case ZEND_JMPZ_EX:
605 case ZEND_JMPNZ_EX:
606 case ZEND_FE_RESET_R:
607 case ZEND_FE_RESET_RW:
608 case ZEND_JMP_SET:
609 case ZEND_COALESCE:
611 case ZEND_JMP_NULL:
614 if (ZEND_OP2_JMP_ADDR(opline) == op_array->opcodes + old->start) {
615 ZEND_SET_OP_JMP_ADDR(opline, opline->op2, op_array->opcodes + dst->start);
616 }
617 break;
618 case ZEND_CATCH:
619 if (!(opline->extended_value & ZEND_LAST_CATCH)) {
620 if (ZEND_OP2_JMP_ADDR(opline) == op_array->opcodes + old->start) {
621 ZEND_SET_OP_JMP_ADDR(opline, opline->op2, op_array->opcodes + dst->start);
622 }
623 }
624 break;
625 case ZEND_FE_FETCH_R:
626 case ZEND_FE_FETCH_RW:
627 if (ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value) == old->start) {
628 opline->extended_value = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, dst->start);
629 }
630 break;
631 case ZEND_SWITCH_LONG:
633 case ZEND_MATCH:
634 {
635 HashTable *jumptable = Z_ARRVAL(ZEND_OP2_LITERAL(opline));
636 zval *zv;
637 ZEND_HASH_FOREACH_VAL(jumptable, zv) {
638 if (ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv)) == old->start) {
639 Z_LVAL_P(zv) = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, dst->start);
640 }
642 if (ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value) == old->start) {
643 opline->extended_value = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, dst->start);
644 }
645 break;
646 }
647 }
648 }
649
650 replace_predecessor(ssa, new_to, to, from);
651}
652
653static void zend_ssa_unlink_block(zend_op_array *op_array, zend_ssa *ssa, zend_basic_block *block, int block_num)
654{
655 if (block->predecessors_count == 1 && ssa->blocks[block_num].phis == NULL) {
656 int *predecessors, i;
657 zend_basic_block *fe_fetch_block = NULL;
658
659 ZEND_ASSERT(block->successors_count == 1);
660 predecessors = &ssa->cfg.predecessors[block->predecessor_offset];
661 if (block->predecessors_count == 1 && (block->flags & ZEND_BB_FOLLOW)) {
662 zend_basic_block *pred_block = &ssa->cfg.blocks[predecessors[0]];
663
664 if (pred_block->len > 0 && (pred_block->flags & ZEND_BB_REACHABLE)) {
665 if ((op_array->opcodes[pred_block->start + pred_block->len - 1].opcode == ZEND_FE_FETCH_R
666 || op_array->opcodes[pred_block->start + pred_block->len - 1].opcode == ZEND_FE_FETCH_RW)
667 && op_array->opcodes[pred_block->start + pred_block->len - 1].op2_type == IS_CV) {
668 fe_fetch_block = pred_block;
669 }
670 }
671 }
672 for (i = 0; i < block->predecessors_count; i++) {
673 zend_ssa_replace_control_link(op_array, ssa, predecessors[i], block_num, block->successors[0]);
674 }
675 zend_ssa_remove_block(op_array, ssa, block_num);
676 if (fe_fetch_block && fe_fetch_block->successors[0] == fe_fetch_block->successors[1]) {
677 /* The body of "foreach" loop was removed */
678 int ssa_var = ssa->ops[fe_fetch_block->start + fe_fetch_block->len - 1].op2_def;
679 if (ssa_var >= 0) {
680 zend_ssa_remove_uses_of_var(ssa, ssa_var);
681 }
682 }
683 }
684}
685
686static int zend_dfa_optimize_jmps(zend_op_array *op_array, zend_ssa *ssa)
687{
688 int removed_ops = 0;
689 int block_num = 0;
690
691 for (block_num = 1; block_num < ssa->cfg.blocks_count; block_num++) {
692 zend_basic_block *block = &ssa->cfg.blocks[block_num];
693
694 if (!(block->flags & ZEND_BB_REACHABLE)) {
695 continue;
696 }
697 compress_block(op_array, block);
698 if (block->len == 0) {
699 zend_ssa_unlink_block(op_array, ssa, block, block_num);
700 }
701 }
702
703 block_num = 0;
704 while (block_num < ssa->cfg.blocks_count
705 && !(ssa->cfg.blocks[block_num].flags & ZEND_BB_REACHABLE)) {
706 block_num++;
707 }
708 while (block_num < ssa->cfg.blocks_count) {
709 int next_block_num = block_num + 1;
710 zend_basic_block *block = &ssa->cfg.blocks[block_num];
711 uint32_t op_num;
712 zend_op *opline;
713 zend_ssa_op *ssa_op;
714 bool can_follow = 1;
715
716 while (next_block_num < ssa->cfg.blocks_count
717 && !(ssa->cfg.blocks[next_block_num].flags & ZEND_BB_REACHABLE)) {
718 if (ssa->cfg.blocks[next_block_num].flags & ZEND_BB_UNREACHABLE_FREE) {
719 can_follow = 0;
720 }
721 next_block_num++;
722 }
723
724 if (block->len) {
725 op_num = block->start + block->len - 1;
726 opline = op_array->opcodes + op_num;
727 ssa_op = ssa->ops + op_num;
728
729 switch (opline->opcode) {
730 case ZEND_JMP:
731optimize_jmp:
732 if (block->successors[0] == next_block_num && can_follow) {
733 MAKE_NOP(opline);
734 removed_ops++;
735 goto optimize_nop;
736 }
737 break;
738 case ZEND_JMPZ:
739optimize_jmpz:
740 if (opline->op1_type == IS_CONST) {
741 if (zend_is_true(CT_CONSTANT_EX(op_array, opline->op1.constant))) {
742 MAKE_NOP(opline);
743 removed_ops++;
744 take_successor_1(ssa, block_num, block);
745 goto optimize_nop;
746 } else {
747 opline->opcode = ZEND_JMP;
748 COPY_NODE(opline->op1, opline->op2);
749 take_successor_0(ssa, block_num, block);
750 goto optimize_jmp;
751 }
752 } else {
753 if (block->successors[0] == next_block_num && can_follow) {
754 take_successor_0(ssa, block_num, block);
755 if (opline->op1_type == IS_CV && (OP1_INFO() & MAY_BE_UNDEF)) {
756 opline->opcode = ZEND_CHECK_VAR;
757 opline->op2.num = 0;
759 zend_ssa_remove_instr(ssa, opline, ssa_op);
760 removed_ops++;
761 goto optimize_nop;
762 } else {
763 opline->opcode = ZEND_FREE;
764 opline->op2.num = 0;
765 }
766 }
767 }
768 break;
769 case ZEND_JMPNZ:
770optimize_jmpnz:
771 if (opline->op1_type == IS_CONST) {
772 if (zend_is_true(CT_CONSTANT_EX(op_array, opline->op1.constant))) {
773 opline->opcode = ZEND_JMP;
774 COPY_NODE(opline->op1, opline->op2);
775 take_successor_0(ssa, block_num, block);
776 goto optimize_jmp;
777 } else {
778 MAKE_NOP(opline);
779 removed_ops++;
780 take_successor_1(ssa, block_num, block);
781 goto optimize_nop;
782 }
783 } else if (block->successors_count == 2) {
784 if (block->successors[0] == next_block_num && can_follow) {
785 take_successor_0(ssa, block_num, block);
786 if (opline->op1_type == IS_CV && (OP1_INFO() & MAY_BE_UNDEF)) {
787 opline->opcode = ZEND_CHECK_VAR;
788 opline->op2.num = 0;
790 zend_ssa_remove_instr(ssa, opline, ssa_op);
791 removed_ops++;
792 goto optimize_nop;
793 } else {
794 opline->opcode = ZEND_FREE;
795 opline->op2.num = 0;
796 }
797 }
798 }
799 break;
800 case ZEND_JMPZ_EX:
801 if (ssa->vars[ssa_op->result_def].use_chain < 0
802 && ssa->vars[ssa_op->result_def].phi_use_chain == NULL) {
803 opline->opcode = ZEND_JMPZ;
804 opline->result_type = IS_UNUSED;
805 zend_ssa_remove_result_def(ssa, ssa_op);
806 goto optimize_jmpz;
807 } else if (opline->op1_type == IS_CONST) {
808 if (zend_is_true(CT_CONSTANT_EX(op_array, opline->op1.constant))) {
809 opline->opcode = ZEND_BOOL;
810 take_successor_1(ssa, block_num, block);
811 }
812 }
813 break;
814 case ZEND_JMPNZ_EX:
815 if (ssa->vars[ssa_op->result_def].use_chain < 0
816 && ssa->vars[ssa_op->result_def].phi_use_chain == NULL) {
817 opline->opcode = ZEND_JMPNZ;
818 opline->result_type = IS_UNUSED;
819 zend_ssa_remove_result_def(ssa, ssa_op);
820 goto optimize_jmpnz;
821 } else if (opline->op1_type == IS_CONST) {
822 if (!zend_is_true(CT_CONSTANT_EX(op_array, opline->op1.constant))) {
823 opline->opcode = ZEND_BOOL;
824 take_successor_1(ssa, block_num, block);
825 }
826 }
827 break;
828 case ZEND_JMP_SET:
829 if (ssa->vars[ssa_op->result_def].use_chain < 0
830 && ssa->vars[ssa_op->result_def].phi_use_chain == NULL) {
831 opline->opcode = ZEND_JMPNZ;
832 opline->result_type = IS_UNUSED;
833 zend_ssa_remove_result_def(ssa, ssa_op);
834 goto optimize_jmpnz;
835 } else if (opline->op1_type == IS_CONST) {
836 if (!zend_is_true(CT_CONSTANT_EX(op_array, opline->op1.constant))) {
837 MAKE_NOP(opline);
838 removed_ops++;
839 take_successor_1(ssa, block_num, block);
840 zend_ssa_remove_result_def(ssa, ssa_op);
841 goto optimize_nop;
842 }
843 }
844 break;
845 case ZEND_COALESCE:
846 {
847 zend_ssa_var *var = &ssa->vars[ssa_op->result_def];
848 if (opline->op1_type == IS_CONST
849 && var->use_chain < 0 && var->phi_use_chain == NULL) {
850 if (Z_TYPE_P(CT_CONSTANT_EX(op_array, opline->op1.constant)) == IS_NULL) {
851 zend_ssa_remove_result_def(ssa, ssa_op);
852 MAKE_NOP(opline);
853 removed_ops++;
854 take_successor_1(ssa, block_num, block);
855 goto optimize_nop;
856 } else {
857 opline->opcode = ZEND_JMP;
858 opline->result_type = IS_UNUSED;
859 zend_ssa_remove_result_def(ssa, ssa_op);
860 COPY_NODE(opline->op1, opline->op2);
861 take_successor_0(ssa, block_num, block);
862 goto optimize_jmp;
863 }
864 }
865 break;
866 }
867 case ZEND_JMP_NULL:
868 {
869 zend_ssa_var *var = &ssa->vars[ssa_op->result_def];
870 if (opline->op1_type == IS_CONST
871 && var->use_chain < 0 && var->phi_use_chain == NULL) {
872 if (Z_TYPE_P(CT_CONSTANT_EX(op_array, opline->op1.constant)) == IS_NULL) {
873 opline->opcode = ZEND_JMP;
874 opline->result_type = IS_UNUSED;
875 zend_ssa_remove_result_def(ssa, ssa_op);
876 COPY_NODE(opline->op1, opline->op2);
877 take_successor_0(ssa, block_num, block);
878 goto optimize_jmp;
879 } else {
880 zend_ssa_remove_result_def(ssa, ssa_op);
881 MAKE_NOP(opline);
882 removed_ops++;
883 take_successor_1(ssa, block_num, block);
884 goto optimize_nop;
885 }
886 }
887 break;
888 }
889 case ZEND_SWITCH_LONG:
891 case ZEND_MATCH:
892 if (opline->op1_type == IS_CONST) {
893 zval *zv = CT_CONSTANT_EX(op_array, opline->op1.constant);
894 uint8_t type = Z_TYPE_P(zv);
895 bool correct_type =
896 (opline->opcode == ZEND_SWITCH_LONG && type == IS_LONG)
897 || (opline->opcode == ZEND_SWITCH_STRING && type == IS_STRING)
898 || (opline->opcode == ZEND_MATCH && (type == IS_LONG || type == IS_STRING));
899
900 /* Switch statements have a fallback chain for loose comparison. In those
901 * cases the SWITCH_* instruction is a NOP. Match does strict comparison and
902 * thus jumps to the default branch on mismatched types, so we need to
903 * convert MATCH to a jmp. */
904 if (!correct_type && opline->opcode != ZEND_MATCH) {
905 removed_ops++;
906 MAKE_NOP(opline);
907 opline->extended_value = 0;
908 take_successor_ex(ssa, block_num, block, block->successors[block->successors_count - 1]);
909 goto optimize_nop;
910 }
911
912 uint32_t target;
913 if (correct_type) {
914 HashTable *jmptable = Z_ARRVAL_P(CT_CONSTANT_EX(op_array, opline->op2.constant));
915 zval *jmp_zv = type == IS_LONG
916 ? zend_hash_index_find(jmptable, Z_LVAL_P(zv))
917 : zend_hash_find(jmptable, Z_STR_P(zv));
918
919 if (jmp_zv) {
920 target = ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(jmp_zv));
921 } else {
922 target = ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value);
923 }
924 } else {
925 ZEND_ASSERT(opline->opcode == ZEND_MATCH);
926 target = ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value);
927 }
928 opline->opcode = ZEND_JMP;
929 opline->extended_value = 0;
930 SET_UNUSED(opline->op1);
931 ZEND_SET_OP_JMP_ADDR(opline, opline->op1, op_array->opcodes + target);
932 SET_UNUSED(opline->op2);
933 take_successor_ex(ssa, block_num, block, ssa->cfg.map[target]);
934 goto optimize_jmp;
935 }
936 break;
937 case ZEND_NOP:
938optimize_nop:
939 compress_block(op_array, block);
940 if (block->len == 0) {
941 if (block_num > 0) {
942 zend_ssa_unlink_block(op_array, ssa, block, block_num);
943 /* backtrack to previous basic block */
944 do {
945 block_num--;
946 } while (block_num >= 0
947 && !(ssa->cfg.blocks[block_num].flags & ZEND_BB_REACHABLE));
948 if (block_num >= 0) {
949 continue;
950 }
951 }
952 }
953 break;
954 default:
955 break;
956 }
957 }
958
959 block_num = next_block_num;
960 }
961
962 return removed_ops;
963}
964
965static bool zend_dfa_try_to_replace_result(zend_op_array *op_array, zend_ssa *ssa, int def, int cv_var)
966{
967 int result_var = ssa->ops[def].result_def;
968 uint32_t cv = EX_NUM_TO_VAR(ssa->vars[cv_var].var);
969
970 if (result_var >= 0
971 && !(ssa->var_info[cv_var].type & MAY_BE_REF)
972 && ssa->vars[cv_var].alias == NO_ALIAS
973 && ssa->vars[result_var].phi_use_chain == NULL
974 && ssa->vars[result_var].sym_use_chain == NULL) {
975 int use = ssa->vars[result_var].use_chain;
976
977 if (use >= 0
978 && zend_ssa_next_use(ssa->ops, result_var, use) < 0
979 && op_array->opcodes[use].opcode != ZEND_FREE
980 && op_array->opcodes[use].opcode != ZEND_SEND_VAL
981 && op_array->opcodes[use].opcode != ZEND_SEND_VAL_EX
982 && op_array->opcodes[use].opcode != ZEND_VERIFY_RETURN_TYPE
983 && op_array->opcodes[use].opcode != ZEND_YIELD) {
984 if (use > def) {
985 int i = use;
986 const zend_op *opline = &op_array->opcodes[use];
987
988 while (i > def) {
989 if ((opline->op1_type == IS_CV && opline->op1.var == cv)
990 || (opline->op2_type == IS_CV && opline->op2.var == cv)
991 || (opline->result_type == IS_CV && opline->result.var == cv)) {
992 return 0;
993 }
994 opline--;
995 i--;
996 }
997
998 /* Update opcodes and reconstruct SSA */
999 ssa->vars[result_var].definition = -1;
1000 ssa->vars[result_var].use_chain = -1;
1001 ssa->ops[def].result_def = -1;
1002
1003 op_array->opcodes[def].result_type = IS_UNUSED;
1004 op_array->opcodes[def].result.var = 0;
1005
1006 if (ssa->ops[use].op1_use == result_var) {
1007 ssa->ops[use].op1_use = cv_var;
1008 ssa->ops[use].op1_use_chain = ssa->vars[cv_var].use_chain;
1009 ssa->vars[cv_var].use_chain = use;
1010
1011 op_array->opcodes[use].op1_type = IS_CV;
1012 op_array->opcodes[use].op1.var = cv;
1013 } else if (ssa->ops[use].op2_use == result_var) {
1014 ssa->ops[use].op2_use = cv_var;
1015 ssa->ops[use].op2_use_chain = ssa->vars[cv_var].use_chain;
1016 ssa->vars[cv_var].use_chain = use;
1017
1018 op_array->opcodes[use].op2_type = IS_CV;
1019 op_array->opcodes[use].op2.var = cv;
1020 } else if (ssa->ops[use].result_use == result_var) {
1021 ssa->ops[use].result_use = cv_var;
1022 ssa->ops[use].res_use_chain = ssa->vars[cv_var].use_chain;
1023 ssa->vars[cv_var].use_chain = use;
1024
1025 op_array->opcodes[use].result_type = IS_CV;
1026 op_array->opcodes[use].result.var = cv;
1027 }
1028
1029 return 1;
1030 }
1031 }
1032 }
1033
1034 return 0;
1035}
1036
1038{
1040 zend_dump_op_array(op_array, ZEND_DUMP_SSA, "before dfa pass", ssa);
1041 }
1042
1043 if (ssa->var_info) {
1044 int op_1;
1045 int v;
1046 int remove_nops = 0;
1047 zend_op *opline;
1048 zend_ssa_op *ssa_op;
1049 zval tmp;
1050
1051#if ZEND_DEBUG_DFA
1052 ssa_verify_integrity(op_array, ssa, "before dfa");
1053#endif
1054
1056 if (sccp_optimize_op_array(ctx, op_array, ssa, call_map)) {
1057 remove_nops = 1;
1058 }
1059
1060 if (zend_dfa_optimize_jmps(op_array, ssa)) {
1061 remove_nops = 1;
1062 }
1063
1064#if ZEND_DEBUG_DFA
1065 ssa_verify_integrity(op_array, ssa, "after sccp");
1066#endif
1067 if (ZEND_FUNC_INFO(op_array)) {
1068 if (zend_dfa_optimize_calls(op_array, ssa)) {
1069 remove_nops = 1;
1070 }
1071 }
1073 zend_dump_op_array(op_array, ZEND_DUMP_SSA, "after sccp pass", ssa);
1074 }
1075#if ZEND_DEBUG_DFA
1076 ssa_verify_integrity(op_array, ssa, "after calls");
1077#endif
1078 }
1079
1081 if (dce_optimize_op_array(op_array, ctx, ssa, 0)) {
1082 remove_nops = 1;
1083 }
1084 if (zend_dfa_optimize_jmps(op_array, ssa)) {
1085 remove_nops = 1;
1086 }
1088 zend_dump_op_array(op_array, ZEND_DUMP_SSA, "after dce pass", ssa);
1089 }
1090#if ZEND_DEBUG_DFA
1091 ssa_verify_integrity(op_array, ssa, "after dce");
1092#endif
1093 }
1094
1095 for (v = op_array->last_var; v < ssa->vars_count; v++) {
1096
1097 op_1 = ssa->vars[v].definition;
1098
1099 if (op_1 < 0) {
1100 continue;
1101 }
1102
1103 opline = op_array->opcodes + op_1;
1104 ssa_op = &ssa->ops[op_1];
1105
1106 /* Convert LONG constants to DOUBLE */
1107 if (ssa->var_info[v].use_as_double) {
1108 if (opline->opcode == ZEND_ASSIGN
1109 && opline->op2_type == IS_CONST
1110 && ssa->ops[op_1].op1_def == v
1111 && !RETURN_VALUE_USED(opline)
1112 ) {
1113
1114// op_1: ASSIGN ? -> #v [use_as_double], long(?) => ASSIGN ? -> #v, double(?)
1115
1116 zval *zv = CT_CONSTANT_EX(op_array, opline->op2.constant);
1118 ZVAL_DOUBLE(&tmp, zval_get_double(zv));
1119 opline->op2.constant = zend_optimizer_add_literal(op_array, &tmp);
1120
1121 } else if (opline->opcode == ZEND_QM_ASSIGN
1122 && opline->op1_type == IS_CONST
1123 ) {
1124
1125// op_1: QM_ASSIGN #v [use_as_double], long(?) => QM_ASSIGN #v, double(?)
1126
1127 zval *zv = CT_CONSTANT_EX(op_array, opline->op1.constant);
1129 ZVAL_DOUBLE(&tmp, zval_get_double(zv));
1130 opline->op1.constant = zend_optimizer_add_literal(op_array, &tmp);
1131 }
1132
1133 } else {
1134 if (opline->opcode == ZEND_ADD
1135 || opline->opcode == ZEND_SUB
1136 || opline->opcode == ZEND_MUL
1137 || opline->opcode == ZEND_IS_EQUAL
1138 || opline->opcode == ZEND_IS_NOT_EQUAL
1139 || opline->opcode == ZEND_IS_SMALLER
1140 || opline->opcode == ZEND_IS_SMALLER_OR_EQUAL
1141 ) {
1142
1143 if (opline->op1_type == IS_CONST && opline->op2_type != IS_CONST) {
1144 zval *zv = CT_CONSTANT_EX(op_array, opline->op1.constant);
1145
1146 if ((OP2_INFO() & MAY_BE_ANY) == MAY_BE_DOUBLE
1147 && Z_TYPE_INFO_P(zv) == IS_LONG) {
1148
1149// op_1: #v.? = ADD long(?), #?.? [double] => #v.? = ADD double(?), #?.? [double]
1150
1151 ZVAL_DOUBLE(&tmp, zval_get_double(zv));
1152 opline->op1.constant = zend_optimizer_add_literal(op_array, &tmp);
1153 zv = CT_CONSTANT_EX(op_array, opline->op1.constant);
1154 }
1155 if (opline->opcode == ZEND_ADD) {
1156 zv = CT_CONSTANT_EX(op_array, opline->op1.constant);
1157
1159 && Z_TYPE_INFO_P(zv) == IS_LONG
1160 && Z_LVAL_P(zv) == 0)
1163 && Z_DVAL_P(zv) == 0.0)) {
1164
1165// op_1: #v.? = ADD 0, #?.? [double,long] => #v.? = QM_ASSIGN #?.?
1166
1167 opline->opcode = ZEND_QM_ASSIGN;
1168 opline->op1_type = opline->op2_type;
1169 opline->op1.var = opline->op2.var;
1170 opline->op2_type = IS_UNUSED;
1171 opline->op2.num = 0;
1172 ssa->ops[op_1].op1_use = ssa->ops[op_1].op2_use;
1173 ssa->ops[op_1].op1_use_chain = ssa->ops[op_1].op2_use_chain;
1174 ssa->ops[op_1].op2_use = -1;
1175 ssa->ops[op_1].op2_use_chain = -1;
1176 }
1177 } else if (opline->opcode == ZEND_MUL
1179 zv = CT_CONSTANT_EX(op_array, opline->op1.constant);
1180
1181 if ((Z_TYPE_INFO_P(zv) == IS_LONG
1182 && Z_LVAL_P(zv) == 2)
1183 || (Z_TYPE_INFO_P(zv) == IS_DOUBLE
1184 && Z_DVAL_P(zv) == 2.0
1185 && !(OP2_INFO() & MAY_BE_LONG))) {
1186
1187// op_1: #v.? = MUL 2, #x.? [double,long] => #v.? = ADD #x.?, #x.?
1188
1189 opline->opcode = ZEND_ADD;
1190 opline->op1_type = opline->op2_type;
1191 opline->op1.var = opline->op2.var;
1192 ssa->ops[op_1].op1_use = ssa->ops[op_1].op2_use;
1193 ssa->ops[op_1].op1_use_chain = ssa->ops[op_1].op2_use_chain;
1194 }
1195 }
1196 } else if (opline->op1_type != IS_CONST && opline->op2_type == IS_CONST) {
1197 zval *zv = CT_CONSTANT_EX(op_array, opline->op2.constant);
1198
1199 if ((OP1_INFO() & MAY_BE_ANY) == MAY_BE_DOUBLE
1200 && Z_TYPE_INFO_P(CT_CONSTANT_EX(op_array, opline->op2.constant)) == IS_LONG) {
1201
1202// op_1: #v.? = ADD #?.? [double], long(?) => #v.? = ADD #?.? [double], double(?)
1203
1204 ZVAL_DOUBLE(&tmp, zval_get_double(zv));
1205 opline->op2.constant = zend_optimizer_add_literal(op_array, &tmp);
1206 zv = CT_CONSTANT_EX(op_array, opline->op2.constant);
1207 }
1208 if (opline->opcode == ZEND_ADD || opline->opcode == ZEND_SUB) {
1210 && Z_TYPE_INFO_P(zv) == IS_LONG
1211 && Z_LVAL_P(zv) == 0)
1214 && Z_DVAL_P(zv) == 0.0)) {
1215
1216// op_1: #v.? = ADD #?.? [double,long], 0 => #v.? = QM_ASSIGN #?.?
1217
1218 opline->opcode = ZEND_QM_ASSIGN;
1219 opline->op2_type = IS_UNUSED;
1220 opline->op2.num = 0;
1221 }
1222 } else if (opline->opcode == ZEND_MUL
1224 zv = CT_CONSTANT_EX(op_array, opline->op2.constant);
1225
1226 if ((Z_TYPE_INFO_P(zv) == IS_LONG
1227 && Z_LVAL_P(zv) == 2)
1228 || (Z_TYPE_INFO_P(zv) == IS_DOUBLE
1229 && Z_DVAL_P(zv) == 2.0
1230 && !(OP1_INFO() & MAY_BE_LONG))) {
1231
1232// op_1: #v.? = MUL #x.? [double,long], 2 => #v.? = ADD #x.?, #x.?
1233
1234 opline->opcode = ZEND_ADD;
1235 opline->op2_type = opline->op1_type;
1236 opline->op2.var = opline->op1.var;
1237 ssa->ops[op_1].op2_use = ssa->ops[op_1].op1_use;
1238 ssa->ops[op_1].op2_use_chain = ssa->ops[op_1].op1_use_chain;
1239 }
1240 }
1241 }
1242 } else if (opline->opcode == ZEND_CONCAT) {
1243 if (!(OP1_INFO() & MAY_BE_OBJECT)
1244 && !(OP2_INFO() & MAY_BE_OBJECT)) {
1245 opline->opcode = ZEND_FAST_CONCAT;
1246 }
1247 } else if (opline->opcode == ZEND_VERIFY_RETURN_TYPE
1248 && opline->op1_type != IS_CONST
1249 && ssa->ops[op_1].op1_def == v
1250 && ssa->ops[op_1].op1_use >= 0) {
1251 int orig_var = ssa->ops[op_1].op1_use;
1252 int ret = ssa->vars[v].use_chain;
1253
1254 if (ssa->ops[op_1].op1_use_chain == -1
1255 && can_elide_return_type_check(ctx->script, op_array, ssa, &ssa->ops[op_1])) {
1256
1257// op_1: VERIFY_RETURN_TYPE #orig_var.? [T] -> #v.? [T] => NOP
1258
1259 zend_ssa_unlink_use_chain(ssa, op_1, orig_var);
1260
1261 if (ret >= 0) {
1262 ssa->ops[ret].op1_use = orig_var;
1263 ssa->ops[ret].op1_use_chain = ssa->vars[orig_var].use_chain;
1264 ssa->vars[orig_var].use_chain = ret;
1265 }
1266
1267 ssa->vars[v].definition = -1;
1268 ssa->vars[v].use_chain = -1;
1269
1270 ssa->ops[op_1].op1_def = -1;
1271 ssa->ops[op_1].op1_use = -1;
1272
1273 MAKE_NOP(opline);
1274 remove_nops = 1;
1275 } else if (ret >= 0
1276 && ssa->ops[ret].op1_use == v
1277 && ssa->ops[ret].op1_use_chain == -1
1278 && can_elide_return_type_check(ctx->script, op_array, ssa, &ssa->ops[op_1])) {
1279
1280// op_1: VERIFY_RETURN_TYPE #orig_var.? [T] -> #v.? [T] => NOP
1281
1282 zend_ssa_replace_use_chain(ssa, op_1, ret, orig_var);
1283
1284 ssa->ops[ret].op1_use = orig_var;
1285 ssa->ops[ret].op1_use_chain = ssa->ops[op_1].op1_use_chain;
1286
1287 ssa->vars[v].definition = -1;
1288 ssa->vars[v].use_chain = -1;
1289
1290 ssa->ops[op_1].op1_def = -1;
1291 ssa->ops[op_1].op1_use = -1;
1292
1293 MAKE_NOP(opline);
1294 remove_nops = 1;
1295 }
1296 }
1297 }
1298
1299 if (opline->opcode == ZEND_QM_ASSIGN
1300 && ssa->ops[op_1].result_def == v
1301 && opline->op1_type & (IS_TMP_VAR|IS_VAR)
1303 ) {
1304
1305 int src_var = ssa->ops[op_1].op1_use;
1306
1307 if (src_var >= 0
1308 && !(ssa->var_info[src_var].type & MAY_BE_REF)
1309 && (ssa->var_info[src_var].type & (MAY_BE_UNDEF|MAY_BE_ANY))
1310 && ssa->vars[src_var].definition >= 0
1311 && ssa->ops[ssa->vars[src_var].definition].result_def == src_var
1312 && ssa->ops[ssa->vars[src_var].definition].result_use < 0
1313 && ssa->vars[src_var].use_chain == op_1
1314 && ssa->ops[op_1].op1_use_chain < 0
1315 && !ssa->vars[src_var].phi_use_chain
1316 && !ssa->vars[src_var].sym_use_chain
1317 && opline_supports_assign_contraction(
1318 op_array, ssa, &op_array->opcodes[ssa->vars[src_var].definition],
1319 src_var, opline->result.var)
1320 && !variable_defined_or_used_in_range(ssa, EX_VAR_TO_NUM(opline->result.var),
1321 ssa->vars[src_var].definition+1, op_1)
1322 ) {
1323
1324 int orig_var = ssa->ops[op_1].result_use;
1325 int op_2 = ssa->vars[src_var].definition;
1326
1327// op_2: #src_var.T = OP ... => #v.CV = OP ...
1328// op_1: QM_ASSIGN #src_var.T #orig_var.CV [undef,scalar] -> #v.CV, NOP
1329
1330 if (orig_var >= 0) {
1331 zend_ssa_unlink_use_chain(ssa, op_1, orig_var);
1332 }
1333
1334 /* Reconstruct SSA */
1335 ssa->vars[v].definition = op_2;
1336 ssa->ops[op_2].result_def = v;
1337
1338 ssa->vars[src_var].definition = -1;
1339 ssa->vars[src_var].use_chain = -1;
1340
1341 ssa->ops[op_1].op1_use = -1;
1342 ssa->ops[op_1].op1_def = -1;
1343 ssa->ops[op_1].op1_use_chain = -1;
1344 ssa->ops[op_1].result_use = -1;
1345 ssa->ops[op_1].result_def = -1;
1346 ssa->ops[op_1].res_use_chain = -1;
1347
1348 /* Update opcodes */
1349 op_array->opcodes[op_2].result_type = opline->result_type;
1350 op_array->opcodes[op_2].result.var = opline->result.var;
1351
1352 MAKE_NOP(opline);
1353 remove_nops = 1;
1354
1355 if (op_array->opcodes[op_2].opcode == ZEND_SUB
1356 && op_array->opcodes[op_2].op1_type == op_array->opcodes[op_2].result_type
1357 && op_array->opcodes[op_2].op1.var == op_array->opcodes[op_2].result.var
1358 && op_array->opcodes[op_2].op2_type == IS_CONST
1359 && Z_TYPE_P(CT_CONSTANT_EX(op_array, op_array->opcodes[op_2].op2.constant)) == IS_LONG
1360 && Z_LVAL_P(CT_CONSTANT_EX(op_array, op_array->opcodes[op_2].op2.constant)) == 1
1361 && ssa->ops[op_2].op1_use >= 0
1363
1364 op_array->opcodes[op_2].opcode = ZEND_PRE_DEC;
1365 SET_UNUSED(op_array->opcodes[op_2].op2);
1366 SET_UNUSED(op_array->opcodes[op_2].result);
1367
1368 ssa->ops[op_2].result_def = -1;
1369 ssa->ops[op_2].op1_def = v;
1370
1371 } else if (op_array->opcodes[op_2].opcode == ZEND_ADD
1372 && op_array->opcodes[op_2].op1_type == op_array->opcodes[op_2].result_type
1373 && op_array->opcodes[op_2].op1.var == op_array->opcodes[op_2].result.var
1374 && op_array->opcodes[op_2].op2_type == IS_CONST
1375 && Z_TYPE_P(CT_CONSTANT_EX(op_array, op_array->opcodes[op_2].op2.constant)) == IS_LONG
1376 && Z_LVAL_P(CT_CONSTANT_EX(op_array, op_array->opcodes[op_2].op2.constant)) == 1
1377 && ssa->ops[op_2].op1_use >= 0
1379
1380 op_array->opcodes[op_2].opcode = ZEND_PRE_INC;
1381 SET_UNUSED(op_array->opcodes[op_2].op2);
1382 SET_UNUSED(op_array->opcodes[op_2].result);
1383
1384 ssa->ops[op_2].result_def = -1;
1385 ssa->ops[op_2].op1_def = v;
1386
1387 } else if (op_array->opcodes[op_2].opcode == ZEND_ADD
1388 && op_array->opcodes[op_2].op2_type == op_array->opcodes[op_2].result_type
1389 && op_array->opcodes[op_2].op2.var == op_array->opcodes[op_2].result.var
1390 && op_array->opcodes[op_2].op1_type == IS_CONST
1391 && Z_TYPE_P(CT_CONSTANT_EX(op_array, op_array->opcodes[op_2].op1.constant)) == IS_LONG
1392 && Z_LVAL_P(CT_CONSTANT_EX(op_array, op_array->opcodes[op_2].op1.constant)) == 1
1393 && ssa->ops[op_2].op2_use >= 0
1395
1396 op_array->opcodes[op_2].opcode = ZEND_PRE_INC;
1397 op_array->opcodes[op_2].op1_type = op_array->opcodes[op_2].op2_type;
1398 op_array->opcodes[op_2].op1.var = op_array->opcodes[op_2].op2.var;
1399 SET_UNUSED(op_array->opcodes[op_2].op2);
1400 SET_UNUSED(op_array->opcodes[op_2].result);
1401
1402 ssa->ops[op_2].result_def = -1;
1403 ssa->ops[op_2].op1_def = v;
1404 ssa->ops[op_2].op1_use = ssa->ops[op_2].op2_use;
1405 ssa->ops[op_2].op1_use_chain = ssa->ops[op_2].op2_use_chain;
1406 ssa->ops[op_2].op2_use = -1;
1407 ssa->ops[op_2].op2_use_chain = -1;
1408 }
1409 }
1410 }
1411
1412 if (ssa->vars[v].var >= op_array->last_var) {
1413 /* skip TMP and VAR */
1414 continue;
1415 }
1416
1417 if (ssa->ops[op_1].op1_def == v
1418 && RETURN_VALUE_USED(opline)) {
1419 if (opline->opcode == ZEND_ASSIGN
1420 || opline->opcode == ZEND_ASSIGN_OP
1421 || opline->opcode == ZEND_PRE_INC
1422 || opline->opcode == ZEND_PRE_DEC) {
1423 zend_dfa_try_to_replace_result(op_array, ssa, op_1, v);
1424 } else if (opline->opcode == ZEND_POST_INC) {
1425 int result_var = ssa->ops[op_1].result_def;
1426
1427 if (result_var >= 0
1428 && (ssa->var_info[result_var].type & ((MAY_BE_ANY|MAY_BE_REF|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_DOUBLE))) == 0) {
1429 int use = ssa->vars[result_var].use_chain;
1430
1431 if (use >= 0 && op_array->opcodes[use].opcode == ZEND_IS_SMALLER
1432 && ssa->ops[use].op1_use == result_var
1433 && zend_dfa_try_to_replace_result(op_array, ssa, op_1, v)) {
1434 opline->opcode = ZEND_PRE_INC;
1435 op_array->opcodes[use].opcode = ZEND_IS_SMALLER_OR_EQUAL;
1436 }
1437 }
1438 } else if (opline->opcode == ZEND_POST_DEC) {
1439 int result_var = ssa->ops[op_1].result_def;
1440
1441 if (result_var >= 0
1442 && (ssa->var_info[result_var].type & ((MAY_BE_ANY|MAY_BE_REF|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_DOUBLE))) == 0) {
1443 int use = ssa->vars[result_var].use_chain;
1444
1445 if (use >= 0 && op_array->opcodes[use].opcode == ZEND_IS_SMALLER
1446 && ssa->ops[use].op2_use == result_var
1447 && zend_dfa_try_to_replace_result(op_array, ssa, op_1, v)) {
1448 opline->opcode = ZEND_PRE_DEC;
1449 op_array->opcodes[use].opcode = ZEND_IS_SMALLER_OR_EQUAL;
1450 }
1451 }
1452 }
1453 }
1454
1455 if (opline->opcode == ZEND_ASSIGN
1456 && ssa->ops[op_1].op1_def == v
1457 && !RETURN_VALUE_USED(opline)
1458 ) {
1459 int orig_var = ssa->ops[op_1].op1_use;
1460
1461 if (orig_var >= 0
1463 ) {
1464 int src_var = ssa->ops[op_1].op2_use;
1465
1466 if ((opline->op2_type & (IS_TMP_VAR|IS_VAR))
1467 && src_var >= 0
1468 && !(ssa->var_info[src_var].type & MAY_BE_REF)
1469 && (ssa->var_info[src_var].type & (MAY_BE_UNDEF|MAY_BE_ANY))
1470 && ssa->vars[src_var].definition >= 0
1471 && ssa->ops[ssa->vars[src_var].definition].result_def == src_var
1472 && ssa->ops[ssa->vars[src_var].definition].result_use < 0
1473 && ssa->vars[src_var].use_chain == op_1
1474 && ssa->ops[op_1].op2_use_chain < 0
1475 && !ssa->vars[src_var].phi_use_chain
1476 && !ssa->vars[src_var].sym_use_chain
1477 && opline_supports_assign_contraction(
1478 op_array, ssa, &op_array->opcodes[ssa->vars[src_var].definition],
1479 src_var, opline->op1.var)
1480 && !variable_defined_or_used_in_range(ssa, EX_VAR_TO_NUM(opline->op1.var),
1481 ssa->vars[src_var].definition+1, op_1)
1482 ) {
1483
1484 int op_2 = ssa->vars[src_var].definition;
1485
1486// op_2: #src_var.T = OP ... => #v.CV = OP ...
1487// op_1: ASSIGN #orig_var.CV [undef,scalar] -> #v.CV, #src_var.T NOP
1488
1489 zend_ssa_unlink_use_chain(ssa, op_1, orig_var);
1490 /* Reconstruct SSA */
1491 ssa->vars[v].definition = op_2;
1492 ssa->ops[op_2].result_def = v;
1493
1494 ssa->vars[src_var].definition = -1;
1495 ssa->vars[src_var].use_chain = -1;
1496
1497 ssa->ops[op_1].op1_use = -1;
1498 ssa->ops[op_1].op2_use = -1;
1499 ssa->ops[op_1].op1_def = -1;
1500 ssa->ops[op_1].op1_use_chain = -1;
1501
1502 /* Update opcodes */
1503 op_array->opcodes[op_2].result_type = opline->op1_type;
1504 op_array->opcodes[op_2].result.var = opline->op1.var;
1505
1506 MAKE_NOP(opline);
1507 remove_nops = 1;
1508
1509 if (op_array->opcodes[op_2].opcode == ZEND_SUB
1510 && op_array->opcodes[op_2].op1_type == op_array->opcodes[op_2].result_type
1511 && op_array->opcodes[op_2].op1.var == op_array->opcodes[op_2].result.var
1512 && op_array->opcodes[op_2].op2_type == IS_CONST
1513 && Z_TYPE_P(CT_CONSTANT_EX(op_array, op_array->opcodes[op_2].op2.constant)) == IS_LONG
1514 && Z_LVAL_P(CT_CONSTANT_EX(op_array, op_array->opcodes[op_2].op2.constant)) == 1
1515 && ssa->ops[op_2].op1_use >= 0
1517
1518 op_array->opcodes[op_2].opcode = ZEND_PRE_DEC;
1519 SET_UNUSED(op_array->opcodes[op_2].op2);
1520 SET_UNUSED(op_array->opcodes[op_2].result);
1521
1522 ssa->ops[op_2].result_def = -1;
1523 ssa->ops[op_2].op1_def = v;
1524
1525 } else if (op_array->opcodes[op_2].opcode == ZEND_ADD
1526 && op_array->opcodes[op_2].op1_type == op_array->opcodes[op_2].result_type
1527 && op_array->opcodes[op_2].op1.var == op_array->opcodes[op_2].result.var
1528 && op_array->opcodes[op_2].op2_type == IS_CONST
1529 && Z_TYPE_P(CT_CONSTANT_EX(op_array, op_array->opcodes[op_2].op2.constant)) == IS_LONG
1530 && Z_LVAL_P(CT_CONSTANT_EX(op_array, op_array->opcodes[op_2].op2.constant)) == 1
1531 && ssa->ops[op_2].op1_use >= 0
1533
1534 op_array->opcodes[op_2].opcode = ZEND_PRE_INC;
1535 SET_UNUSED(op_array->opcodes[op_2].op2);
1536 SET_UNUSED(op_array->opcodes[op_2].result);
1537
1538 ssa->ops[op_2].result_def = -1;
1539 ssa->ops[op_2].op1_def = v;
1540
1541 } else if (op_array->opcodes[op_2].opcode == ZEND_ADD
1542 && op_array->opcodes[op_2].op2_type == op_array->opcodes[op_2].result_type
1543 && op_array->opcodes[op_2].op2.var == op_array->opcodes[op_2].result.var
1544 && op_array->opcodes[op_2].op1_type == IS_CONST
1545 && Z_TYPE_P(CT_CONSTANT_EX(op_array, op_array->opcodes[op_2].op1.constant)) == IS_LONG
1546 && Z_LVAL_P(CT_CONSTANT_EX(op_array, op_array->opcodes[op_2].op1.constant)) == 1
1547 && ssa->ops[op_2].op2_use >= 0
1549
1550 op_array->opcodes[op_2].opcode = ZEND_PRE_INC;
1551 op_array->opcodes[op_2].op1_type = op_array->opcodes[op_2].op2_type;
1552 op_array->opcodes[op_2].op1.var = op_array->opcodes[op_2].op2.var;
1553 SET_UNUSED(op_array->opcodes[op_2].op2);
1554 SET_UNUSED(op_array->opcodes[op_2].result);
1555
1556 ssa->ops[op_2].result_def = -1;
1557 ssa->ops[op_2].op1_def = v;
1558 ssa->ops[op_2].op1_use = ssa->ops[op_2].op2_use;
1559 ssa->ops[op_2].op1_use_chain = ssa->ops[op_2].op2_use_chain;
1560 ssa->ops[op_2].op2_use = -1;
1561 ssa->ops[op_2].op2_use_chain = -1;
1562 }
1563 } else if (opline->op2_type == IS_CONST
1564 || ((opline->op2_type & (IS_TMP_VAR|IS_VAR|IS_CV))
1565 && ssa->ops[op_1].op2_use >= 0
1566 && ssa->ops[op_1].op2_def < 0)
1567 ) {
1568
1569// op_1: ASSIGN #orig_var.CV [undef,scalar] -> #v.CV, CONST|TMPVAR => QM_ASSIGN v.CV, CONST|TMPVAR
1570
1571 if (ssa->ops[op_1].op1_use != ssa->ops[op_1].op2_use) {
1572 zend_ssa_unlink_use_chain(ssa, op_1, orig_var);
1573 } else {
1574 ssa->ops[op_1].op2_use_chain = ssa->ops[op_1].op1_use_chain;
1575 }
1576
1577 /* Reconstruct SSA */
1578 ssa->ops[op_1].result_def = v;
1579 ssa->ops[op_1].op1_def = -1;
1580 ssa->ops[op_1].op1_use = ssa->ops[op_1].op2_use;
1581 ssa->ops[op_1].op1_use_chain = ssa->ops[op_1].op2_use_chain;
1582 ssa->ops[op_1].op2_use = -1;
1583 ssa->ops[op_1].op2_use_chain = -1;
1584
1585 /* Update opcode */
1586 opline->result_type = opline->op1_type;
1587 opline->result.var = opline->op1.var;
1588 opline->op1_type = opline->op2_type;
1589 opline->op1.var = opline->op2.var;
1590 opline->op2_type = IS_UNUSED;
1591 opline->op2.var = 0;
1592 opline->opcode = ZEND_QM_ASSIGN;
1593 }
1594 }
1595
1596 } else if (opline->opcode == ZEND_ASSIGN_OP
1597 && opline->extended_value == ZEND_ADD
1598 && ssa->ops[op_1].op1_def == v
1599 && opline->op2_type == IS_CONST
1600 && Z_TYPE_P(CT_CONSTANT_EX(op_array, opline->op2.constant)) == IS_LONG
1601 && Z_LVAL_P(CT_CONSTANT_EX(op_array, opline->op2.constant)) == 1
1602 && ssa->ops[op_1].op1_use >= 0
1604
1605// op_1: ASSIGN_ADD #?.CV [undef,null,int,foat] ->#v.CV, int(1) => PRE_INC #?.CV ->#v.CV
1606
1607 opline->opcode = ZEND_PRE_INC;
1608 opline->extended_value = 0;
1609 SET_UNUSED(opline->op2);
1610
1611 } else if (opline->opcode == ZEND_ASSIGN_OP
1612 && opline->extended_value == ZEND_SUB
1613 && ssa->ops[op_1].op1_def == v
1614 && opline->op2_type == IS_CONST
1615 && Z_TYPE_P(CT_CONSTANT_EX(op_array, opline->op2.constant)) == IS_LONG
1616 && Z_LVAL_P(CT_CONSTANT_EX(op_array, opline->op2.constant)) == 1
1617 && ssa->ops[op_1].op1_use >= 0
1619
1620// op_1: ASSIGN_SUB #?.CV [undef,null,int,foat] -> #v.CV, int(1) => PRE_DEC #?.CV ->#v.CV
1621
1622 opline->opcode = ZEND_PRE_DEC;
1623 opline->extended_value = 0;
1624 SET_UNUSED(opline->op2);
1625
1626 } else if (ssa->ops[op_1].op1_def == v
1627 && !RETURN_VALUE_USED(opline)
1628 && ssa->ops[op_1].op1_use >= 0
1630 && opline->opcode == ZEND_ASSIGN_OP
1631 && opline->extended_value != ZEND_CONCAT) {
1632
1633// op_1: ASSIGN_OP #orig_var.CV [undef,null,bool,int,double] -> #v.CV, ? => #v.CV = ADD #orig_var.CV, ?
1634
1635 /* Reconstruct SSA */
1636 ssa->ops[op_1].result_def = ssa->ops[op_1].op1_def;
1637 ssa->ops[op_1].op1_def = -1;
1638
1639 /* Update opcode */
1640 opline->opcode = opline->extended_value;
1641 opline->extended_value = 0;
1642 opline->result_type = opline->op1_type;
1643 opline->result.var = opline->op1.var;
1644
1645 }
1646 }
1647
1648#if ZEND_DEBUG_DFA
1649 ssa_verify_integrity(op_array, ssa, "after dfa");
1650#endif
1651
1652 if (remove_nops) {
1653 zend_ssa_remove_nops(op_array, ssa, ctx);
1654#if ZEND_DEBUG_DFA
1655 ssa_verify_integrity(op_array, ssa, "after nop");
1656#endif
1657 }
1658 }
1659
1661 zend_dump_op_array(op_array, ZEND_DUMP_SSA, "after dfa pass", ssa);
1662 }
1663}
1664
1666{
1667 void *checkpoint = zend_arena_checkpoint(ctx->arena);
1668 zend_ssa ssa;
1669
1670 if (zend_dfa_analyze_op_array(op_array, ctx, &ssa) == FAILURE) {
1671 zend_arena_release(&ctx->arena, checkpoint);
1672 return;
1673 }
1674
1675 zend_dfa_optimize_op_array(op_array, ctx, &ssa, NULL);
1676
1677 /* Destroy SSA */
1678 zend_arena_release(&ctx->arena, checkpoint);
1679}
if(function_exists("date_default_timezone_set")) simple()
Definition bench.php:6
uint32_t v
Definition cdf.c:1237
int dce_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *optimizer_ctx, zend_ssa *ssa, bool reorder_dtor_effects)
Definition dce.c:526
void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx, zend_ssa *ssa, zend_call_info **call_map)
Definition dfa_pass.c:1037
int zend_dfa_optimize_calls(zend_op_array *op_array, zend_ssa *ssa)
Definition dfa_pass.c:401
zend_result zend_dfa_analyze_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx, zend_ssa *ssa)
Definition dfa_pass.c:41
void zend_optimize_dfa(zend_op_array *op_array, zend_optimizer_ctx *ctx)
Definition dfa_pass.c:1665
zend_result zend_ssa_escape_analysis(const zend_script *script, zend_op_array *op_array, zend_ssa *ssa)
zend_ffi_type * type
Definition ffi.c:3812
zval * zv
Definition ffi.c:3975
memset(ptr, 0, type->size)
zval * val
Definition ffi.c:4262
buf start
Definition ffi.c:4687
#define NULL
Definition gdcache.h:45
#define SUCCESS
Definition hash_sha3.c:261
again j
#define memmove(a, b, c)
unsigned const char * end
Definition php_ffi.h:51
zend_string * lcname
int sccp_optimize_op_array(zend_optimizer_ctx *ctx, zend_op_array *op_array, zend_ssa *ssa, zend_call_info **call_map)
Definition sccp.c:2469
void ssa_verify_integrity(zend_op_array *op_array, zend_ssa *ssa, const char *extra)
uint32_t start
Definition zend_cfg.h:45
uint32_t flags
Definition zend_cfg.h:44
uint32_t flags
Definition zend_cfg.h:90
uint32_t * map
Definition zend_cfg.h:89
int blocks_count
Definition zend_cfg.h:85
int * predecessors
Definition zend_cfg.h:88
zend_basic_block * blocks
Definition zend_cfg.h:87
uint32_t ce_flags
Definition zend.h:156
zend_arg_info * arg_info
zend_try_catch_element * try_catch_array
zend_op * opcodes
znode_op op1
uint8_t result_type
znode_op op2
znode_op result
uint8_t opcode
uint8_t op1_type
uint32_t extended_value
uint8_t op2_type
zend_ssa_phi * phis
Definition zend_ssa.h:79
int op2_use_chain
Definition zend_ssa.h:90
int op1_use_chain
Definition zend_ssa.h:89
int res_use_chain
Definition zend_ssa.h:91
int result_use
Definition zend_ssa.h:85
int result_def
Definition zend_ssa.h:88
int * sources
Definition zend_ssa.h:73
zend_ssa_phi * next
Definition zend_ssa.h:64
zend_class_entry * ce
Definition zend_ssa.h:132
unsigned int alias
Definition zend_ssa.h:117
zend_ssa_phi * sym_use_chain
Definition zend_ssa.h:114
zend_ssa_phi * phi_use_chain
Definition zend_ssa.h:113
int vars_count
Definition zend_ssa.h:137
zend_ssa_var * vars
Definition zend_ssa.h:141
zend_cfg cfg
Definition zend_ssa.h:136
zend_ssa_var_info * var_info
Definition zend_ssa.h:142
zend_ssa_op * ops
Definition zend_ssa.h:140
zend_ssa_block * blocks
Definition zend_ssa.h:139
uint32_t var
uint32_t constant
uint32_t num
struct _zval_struct zval
ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, uint32_t build_flags, zend_cfg *cfg)
Definition zend_cfg.c:273
ZEND_API void zend_cfg_build_predecessors(zend_arena **arena, zend_cfg *cfg)
Definition zend_cfg.c:595
ZEND_API void zend_cfg_compute_dominators_tree(const zend_op_array *op_array, zend_cfg *cfg)
Definition zend_cfg.c:676
ZEND_API void zend_cfg_identify_loops(const zend_op_array *op_array, zend_cfg *cfg)
Definition zend_cfg.c:778
struct _zend_basic_block zend_basic_block
#define ZEND_SSA_DEBUG_LIVENESS
Definition zend_cfg.h:95
#define ZEND_BB_REACHABLE
Definition zend_cfg.h:38
#define ZEND_BB_UNREACHABLE_FREE
Definition zend_cfg.h:32
#define ZEND_CFG_NO_ENTRY_PREDECESSORS
Definition zend_cfg.h:98
#define RETURN_VALUE_USED(opline)
Definition zend_cfg.h:113
#define ZEND_SSA_DEBUG_PHI_PLACEMENT
Definition zend_cfg.h:96
#define ZEND_BB_FOLLOW
Definition zend_cfg.h:24
struct _zend_op zend_op
#define IS_UNUSED
#define ZEND_SET_OP_JMP_ADDR(opline, node, val)
#define IS_CONST
#define EX_VAR_TO_NUM(n)
#define IS_VAR
#define ZEND_OFFSET_TO_OPLINE_NUM(op_array, base, offset)
#define EX_NUM_TO_VAR(n)
#define ZEND_ACC_LINKED
struct _zend_op_array zend_op_array
struct _zend_arg_info zend_arg_info
#define CT_CONSTANT_EX(op_array, num)
#define MAKE_NOP(opline)
#define SET_UNUSED(op)
#define IS_CV
#define IS_TMP_VAR
#define ZEND_LAST_CATCH
#define ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, opline_num)
void zend_dump_ssa_variables(const zend_op_array *op_array, const zend_ssa *ssa, uint32_t dump_flags)
Definition zend_dump.c:1178
ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_flags, const char *msg, const void *data)
Definition zend_dump.c:930
void zend_dump_dominators(const zend_op_array *op_array, const zend_cfg *cfg)
Definition zend_dump.c:1163
#define ZEND_DUMP_CFG
Definition zend_dump.h:29
#define ZEND_DUMP_SSA
Definition zend_dump.h:30
struct _zend_call_info zend_call_info
#define ZEND_FUNC_INDIRECT_VAR_ACCESS
#define ZEND_FUNC_INFO(op_array)
struct _zend_func_info zend_func_info
ZEND_API zval *ZEND_FASTCALL zend_hash_index_add(HashTable *ht, zend_ulong h, zval *pData)
Definition zend_hash.c:1209
ZEND_API void ZEND_FASTCALL zend_array_destroy(HashTable *ht)
Definition zend_hash.c:1808
ZEND_API zval *ZEND_FASTCALL zend_hash_find(const HashTable *ht, zend_string *key)
Definition zend_hash.c:2668
ZEND_API zval *ZEND_FASTCALL zend_hash_add(HashTable *ht, zend_string *key, zval *pData)
Definition zend_hash.c:992
ZEND_API zval *ZEND_FASTCALL zend_hash_index_find(const HashTable *ht, zend_ulong h)
Definition zend_hash.c:2701
#define zend_new_array(size)
Definition zend_hash.h:338
#define ZEND_HANDLE_NUMERIC(key, idx)
Definition zend_hash.h:420
#define ZEND_HASH_FOREACH_END()
Definition zend_hash.h:1086
#define ZEND_HASH_FOREACH_VAL(ht, _val)
Definition zend_hash.h:1102
ZEND_API bool zend_may_throw(const zend_op *opline, const zend_ssa_op *ssa_op, const zend_op_array *op_array, const zend_ssa *ssa)
ZEND_API void zend_ssa_find_false_dependencies(const zend_op_array *op_array, zend_ssa *ssa)
ZEND_API void zend_ssa_find_sccs(const zend_op_array *op_array, zend_ssa *ssa)
ZEND_API zend_result zend_ssa_inference(zend_arena **arena, const zend_op_array *op_array, const zend_script *script, zend_ssa *ssa, zend_long optimization_level)
#define OP1_INFO()
#define OP2_INFO()
uint32_t zend_ulong
Definition zend_long.h:43
struct _zend_string zend_string
ZEND_API bool ZEND_FASTCALL zend_is_true(const zval *op)
zend_class_entry * zend_optimizer_get_class_entry(const zend_script *script, const zend_op_array *op_array, zend_string *lcname)
int zend_optimizer_add_literal(zend_op_array *op_array, const zval *zv)
void zend_optimizer_migrate_jump(zend_op_array *op_array, zend_op *new_opline, zend_op *opline)
void zend_optimizer_shift_jump(zend_op_array *op_array, zend_op *opline, uint32_t *shiftlist)
#define ZEND_DUMP_DFA_PHI
#define ZEND_OPTIMIZER_PASS_14
struct _zend_script zend_script
#define ZEND_DUMP_DFA_LIVENESS
#define ZEND_DUMP_AFTER_DFA_PASS
#define ZEND_DUMP_DFA_DOMINATORS
#define ZEND_DUMP_DFA_SSA_VARS
#define ZEND_DUMP_DFA_CFG
#define ZEND_OPTIMIZER_PASS_8
#define ZEND_DUMP_AFTER_PASS_14
#define ZEND_DUMP_BEFORE_DFA_PASS
#define ZEND_DUMP_AFTER_PASS_8
#define ZEND_DUMP_DFA_SSA
#define ZEND_OP1_JMP_ADDR(opline)
#define ZEND_OP2_LITERAL(opline)
#define ZEND_OP2_JMP_ADDR(opline)
struct _zend_optimizer_ctx zend_optimizer_ctx
#define COPY_NODE(target, src)
#define ALLOCA_FLAG(name)
#define ZEND_FALLTHROUGH
#define EXPECTED(condition)
#define do_alloca(p, use_heap)
#define zend_always_inline
#define ZEND_ASSERT(c)
#define free_alloca(p, use_heap)
struct _zend_class_entry zend_class_entry
void zend_ssa_remove_uses_of_var(zend_ssa *ssa, int var_num)
Definition zend_ssa.c:1422
void zend_ssa_remove_instr(zend_ssa *ssa, zend_op *opline, zend_ssa_op *ssa_op)
Definition zend_ssa.c:1281
void zend_ssa_unlink_use_chain(zend_ssa *ssa, int op, int var)
Definition zend_ssa.c:1202
void zend_ssa_replace_use_chain(zend_ssa *ssa, int op, int new_op, int var)
Definition zend_ssa.c:1241
void zend_ssa_remove_phi(zend_ssa *ssa, zend_ssa_phi *phi)
Definition zend_ssa.c:1410
void zend_ssa_rename_var_uses(zend_ssa *ssa, int old, int new, bool update_types)
Definition zend_ssa.c:1595
void zend_ssa_remove_predecessor(zend_ssa *ssa, int from, int to)
Definition zend_ssa.c:1455
ZEND_API zend_result zend_build_ssa(zend_arena **arena, const zend_script *script, const zend_op_array *op_array, uint32_t build_flags, zend_ssa *ssa)
Definition zend_ssa.c:936
ZEND_API void zend_ssa_compute_use_def_chains(zend_arena **arena, const zend_op_array *op_array, zend_ssa *ssa)
Definition zend_ssa.c:1084
void zend_ssa_remove_block(zend_op_array *op_array, zend_ssa *ssa, int i)
Definition zend_ssa.c:1501
struct _zend_ssa zend_ssa
struct _zend_ssa_var zend_ssa_var
struct _zend_ssa_phi zend_ssa_phi
Definition zend_ssa.h:62
@ NO_ALIAS
Definition zend_ssa.h:95
struct _zend_ssa_op zend_ssa_op
struct _zend_ssa_var_info zend_ssa_var_info
#define zend_string_equals_literal_ci(str, c)
#define MAY_BE_REF
#define MAY_BE_STRING
#define MAY_BE_FALSE
#define MAY_BE_UNDEF
#define MAY_BE_NULL
#define MAY_BE_DOUBLE
#define MAY_BE_LONG
#define MAY_BE_TRUE
#define MAY_BE_ANY
#define MAY_BE_OBJECT
#define MAY_BE_RESOURCE
#define MAY_BE_ARRAY
#define Z_TYPE_P(zval_p)
Definition zend_types.h:660
#define ZEND_TYPE_PURE_MASK(t)
Definition zend_types.h:257
#define ZEND_TYPE_NAME(t)
Definition zend_types.h:198
#define Z_ARRVAL_P(zval_p)
Definition zend_types.h:987
#define ZVAL_TRUE(z)
#define IS_STRING
Definition zend_types.h:606
#define ZEND_TYPE_IS_INTERSECTION(t)
Definition zend_types.h:186
struct _zend_array HashTable
Definition zend_types.h:386
#define IS_ARRAY
Definition zend_types.h:607
#define ZEND_TYPE_HAS_NAME(t)
Definition zend_types.h:174
#define IS_DOUBLE
Definition zend_types.h:605
#define Z_TYPE_INFO_P(zval_p)
Definition zend_types.h:669
#define Z_STR_P(zval_p)
Definition zend_types.h:972
#define ZEND_TYPE_FOREACH(type, type_ptr)
Definition zend_types.h:223
#define ZEND_TYPE_HAS_LIST(t)
Definition zend_types.h:180
#define IS_NULL
Definition zend_types.h:601
@ FAILURE
Definition zend_types.h:61
#define IS_OBJECT
Definition zend_types.h:608
#define IS_LONG
Definition zend_types.h:604
#define ZVAL_ARR(z, a)
#define ZEND_TYPE_FOREACH_END()
Definition zend_types.h:236
#define ZVAL_DOUBLE(z, d)
ZEND_RESULT_CODE zend_result
Definition zend_types.h:64
#define Z_DVAL_P(zval_p)
Definition zend_types.h:969
#define Z_ARRVAL(zval)
Definition zend_types.h:986
#define Z_LVAL_P(zval_p)
Definition zend_types.h:966
#define ZEND_TYPE_IS_COMPLEX(t)
Definition zend_types.h:171
uint32_t call_info
bool result
op1
zval * ret
#define ZEND_FE_FREE
#define ZEND_YIELD
#define ZEND_SWITCH_LONG
#define ZEND_ASSIGN_DIM_OP
#define ZEND_CHECK_VAR
#define ZEND_NEW
#define ZEND_FE_FETCH_RW
#define ZEND_VERIFY_RETURN_TYPE
#define ZEND_SEND_VAL_EX
#define ZEND_FE_RESET_RW
#define ZEND_FE_FETCH_R
#define ZEND_ASSERT_CHECK
#define ZEND_SEND_VAL
#define ZEND_SWITCH_STRING
#define ZEND_ASSIGN_DIM
#define ZEND_INIT_ARRAY
#define ZEND_NOP
#define ZEND_JMPZ
#define ZEND_JMP_SET
#define ZEND_SUB
#define ZEND_JMPZ_EX
#define ZEND_IS_SMALLER
#define ZEND_PRE_INC
#define ZEND_FRAMELESS_ICALL_1
#define ZEND_POST_INC
#define ZEND_PRE_DEC
#define ZEND_IS_NOT_EQUAL
#define ZEND_DO_UCALL
#define ZEND_CONCAT
#define ZEND_FAST_CONCAT
#define ZEND_MATCH
#define ZEND_FRAMELESS_ICALL_3
#define ZEND_JMPNZ_EX
#define ZEND_DO_FCALL
#define ZEND_IN_ARRAY
#define ZEND_IS_EQUAL
#define ZEND_IS_SMALLER_OR_EQUAL
#define ZEND_POST_DEC
#define ZEND_BOOL
#define ZEND_FRAMELESS_ICALL_2
#define ZEND_MUL
#define ZEND_FAST_CALL
#define ZEND_DO_ICALL
#define ZEND_JMP_NULL
#define ZEND_BIND_INIT_STATIC_OR_JMP
#define ZEND_JMP
#define ZEND_FREE
#define ZEND_FE_RESET_R
#define ZEND_JMP_FRAMELESS
#define ZEND_ASSIGN_OBJ
#define ZEND_ASSIGN_OBJ_OP
#define ZEND_ASSIGN
#define ZEND_DO_FCALL_BY_NAME
#define ZEND_JMPNZ
#define ZEND_CAST
#define ZEND_QM_ASSIGN
#define ZEND_CATCH
#define ZEND_ADD
#define ZEND_COALESCE
#define ZEND_ASSIGN_OP