Lines Matching refs:ctx
218 static zend_always_inline void add_to_worklists(context *ctx, int var_num, int check) { in add_to_worklists() argument
219 zend_ssa_var *var = &ctx->ssa->vars[var_num]; in add_to_worklists()
221 if (!check || zend_bitset_in(ctx->instr_dead, var->definition)) { in add_to_worklists()
222 zend_bitset_incl(ctx->instr_worklist, var->definition); in add_to_worklists()
225 if (!check || zend_bitset_in(ctx->phi_dead, var_num)) { in add_to_worklists()
226 zend_bitset_incl(ctx->phi_worklist, var_num); in add_to_worklists()
231 static inline void add_to_phi_worklist_no_val(context *ctx, int var_num) { in add_to_phi_worklist_no_val() argument
232 zend_ssa_var *var = &ctx->ssa->vars[var_num]; in add_to_phi_worklist_no_val()
233 if (var->definition_phi && zend_bitset_in(ctx->phi_dead, var_num)) { in add_to_phi_worklist_no_val()
234 zend_bitset_incl(ctx->phi_worklist_no_val, var_num); in add_to_phi_worklist_no_val()
238 static zend_always_inline void add_operands_to_worklists(context *ctx, zend_op *opline, zend_ssa_op… in add_operands_to_worklists() argument
240 add_to_worklists(ctx, ssa_op->result_use, check); in add_operands_to_worklists()
244 add_to_worklists(ctx, ssa_op->op1_use, check); in add_operands_to_worklists()
246 add_to_phi_worklist_no_val(ctx, ssa_op->op1_use); in add_operands_to_worklists()
251 add_to_worklists(ctx, ssa_op->op2_use, check); in add_operands_to_worklists()
253 add_to_phi_worklist_no_val(ctx, ssa_op->op2_use); in add_operands_to_worklists()
258 static zend_always_inline void add_phi_sources_to_worklists(context *ctx, zend_ssa_phi *phi, int ch… in add_phi_sources_to_worklists() argument
259 zend_ssa *ssa = ctx->ssa; in add_phi_sources_to_worklists()
262 add_to_worklists(ctx, source, check); in add_phi_sources_to_worklists()
266 static inline zend_bool is_var_dead(context *ctx, int var_num) { in is_var_dead() argument
267 zend_ssa_var *var = &ctx->ssa->vars[var_num]; in is_var_dead()
269 return zend_bitset_in(ctx->phi_dead, var_num); in is_var_dead()
271 return zend_bitset_in(ctx->instr_dead, var->definition); in is_var_dead()
276 return var_num >= ctx->op_array->last_var; in is_var_dead()
281 static zend_bool try_remove_var_def(context *ctx, int free_var, int use_chain, zend_op *opline) { in try_remove_var_def() argument
285 zend_ssa_var *var = &ctx->ssa->vars[free_var]; in try_remove_var_def()
289 zend_ssa_op *def_op = &ctx->ssa->ops[def]; in try_remove_var_def()
293 && var->use_chain == (opline - ctx->op_array->opcodes)) { in try_remove_var_def()
294 zend_op *def_opline = &ctx->op_array->opcodes[def]; in try_remove_var_def()
341 static zend_bool dce_instr(context *ctx, zend_op *opline, zend_ssa_op *ssa_op) { in dce_instr() argument
342 zend_ssa *ssa = ctx->ssa; in dce_instr()
353 && !is_var_dead(ctx, ssa_op->op1_use)) { in dce_instr()
357 if ((opline->op1_type & (IS_VAR|IS_TMP_VAR))&& !is_var_dead(ctx, ssa_op->op1_use)) { in dce_instr()
358 if (!try_remove_var_def(ctx, ssa_op->op1_use, ssa_op->op1_use_chain, opline)) { in dce_instr()
366 if ((opline->op2_type & (IS_VAR|IS_TMP_VAR)) && !is_var_dead(ctx, ssa_op->op2_use)) { in dce_instr()
367 if (!try_remove_var_def(ctx, ssa_op->op2_use, ssa_op->op2_use_chain, opline)) { in dce_instr()
371 zend_bitset_excl(ctx->instr_dead, opline - ctx->op_array->opcodes); in dce_instr()
380 zend_ssa_rename_defs_of_instr(ctx->ssa, ssa_op); in dce_instr()
381 zend_ssa_remove_instr(ctx->ssa, opline, ssa_op); in dce_instr()
516 static void try_remove_trivial_phi(context *ctx, zend_ssa_phi *phi) { in try_remove_trivial_phi() argument
517 zend_ssa *ssa = ctx->ssa; in try_remove_trivial_phi()
552 static void dce_live_ranges(context *ctx, zend_op_array *op_array, zend_ssa *ssa) in dce_live_ranges() argument
608 && !is_var_dead(ctx, var)) { in dce_live_ranges()
634 context ctx; in dce_optimize_op_array() local
635 ctx.ssa = ssa; in dce_optimize_op_array()
636 ctx.op_array = op_array; in dce_optimize_op_array()
637 ctx.reorder_dtor_effects = reorder_dtor_effects; in dce_optimize_op_array()
640 ctx.instr_worklist_len = zend_bitset_len(op_array->last); in dce_optimize_op_array()
641 ctx.instr_worklist = alloca(sizeof(zend_ulong) * ctx.instr_worklist_len); in dce_optimize_op_array()
642 memset(ctx.instr_worklist, 0, sizeof(zend_ulong) * ctx.instr_worklist_len); in dce_optimize_op_array()
643 ctx.phi_worklist_len = zend_bitset_len(ssa->vars_count); in dce_optimize_op_array()
644 ctx.phi_worklist = alloca(sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
645 memset(ctx.phi_worklist, 0, sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
646 ctx.phi_worklist_no_val = alloca(sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
647 memset(ctx.phi_worklist_no_val, 0, sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
650 ctx.instr_dead = alloca(sizeof(zend_ulong) * ctx.instr_worklist_len); in dce_optimize_op_array()
651 memset(ctx.instr_dead, 0, sizeof(zend_ulong) * ctx.instr_worklist_len); in dce_optimize_op_array()
652 ctx.phi_dead = alloca(sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
653 memset(ctx.phi_dead, 0xff, sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
667 if (zend_bitset_in(ctx.instr_worklist, i)) { in dce_optimize_op_array()
668 zend_bitset_excl(ctx.instr_worklist, i); in dce_optimize_op_array()
669 add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i], 0); in dce_optimize_op_array()
670 …} else if (may_have_side_effects(op_array, ssa, &op_array->opcodes[i], &ssa->ops[i], ctx.reorder_d… in dce_optimize_op_array()
673 add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i], 0); in dce_optimize_op_array()
675 zend_bitset_incl(ctx.instr_dead, i); in dce_optimize_op_array()
682 while (!zend_bitset_empty(ctx.instr_worklist, ctx.instr_worklist_len) in dce_optimize_op_array()
683 || !zend_bitset_empty(ctx.phi_worklist, ctx.phi_worklist_len)) { in dce_optimize_op_array()
684 while ((i = zend_bitset_pop_first(ctx.instr_worklist, ctx.instr_worklist_len)) >= 0) { in dce_optimize_op_array()
685 zend_bitset_excl(ctx.instr_dead, i); in dce_optimize_op_array()
686 add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i], 1); in dce_optimize_op_array()
688 while ((i = zend_bitset_pop_first(ctx.phi_worklist, ctx.phi_worklist_len)) >= 0) { in dce_optimize_op_array()
689 zend_bitset_excl(ctx.phi_dead, i); in dce_optimize_op_array()
690 zend_bitset_excl(ctx.phi_worklist_no_val, i); in dce_optimize_op_array()
691 add_phi_sources_to_worklists(&ctx, ssa->vars[i].definition_phi, 1); in dce_optimize_op_array()
696 dce_live_ranges(&ctx, op_array, ssa); in dce_optimize_op_array()
700 ZEND_BITSET_FOREACH(ctx.instr_dead, ctx.instr_worklist_len, i) { in dce_optimize_op_array()
701 removed_ops += dce_instr(&ctx, &op_array->opcodes[i], &ssa->ops[i]); in dce_optimize_op_array()
708 while ((i = zend_bitset_pop_first(ctx.phi_worklist_no_val, ctx.phi_worklist_len)) >= 0) { in dce_optimize_op_array()
711 zend_bitset_excl(ctx.phi_dead, i); in dce_optimize_op_array()
713 add_to_phi_worklist_no_val(&ctx, source); in dce_optimize_op_array()
719 if (zend_bitset_in(ctx.phi_dead, phi->ssa_var)) { in dce_optimize_op_array()
724 try_remove_trivial_phi(&ctx, phi); in dce_optimize_op_array()