Lines Matching refs:ctx
250 static zend_always_inline void add_to_worklists(context *ctx, int var_num, int check) { in add_to_worklists() argument
251 zend_ssa_var *var = &ctx->ssa->vars[var_num]; in add_to_worklists()
253 if (!check || zend_bitset_in(ctx->instr_dead, var->definition)) { in add_to_worklists()
254 zend_bitset_incl(ctx->instr_worklist, var->definition); in add_to_worklists()
257 if (!check || zend_bitset_in(ctx->phi_dead, var_num)) { in add_to_worklists()
258 zend_bitset_incl(ctx->phi_worklist, var_num); in add_to_worklists()
263 static inline void add_to_phi_worklist_no_val(context *ctx, int var_num) { in add_to_phi_worklist_no_val() argument
264 zend_ssa_var *var = &ctx->ssa->vars[var_num]; in add_to_phi_worklist_no_val()
265 if (var->definition_phi && zend_bitset_in(ctx->phi_dead, var_num)) { in add_to_phi_worklist_no_val()
266 zend_bitset_incl(ctx->phi_worklist_no_val, var_num); in add_to_phi_worklist_no_val()
270 static zend_always_inline void add_operands_to_worklists(context *ctx, zend_op *opline, zend_ssa_op… in add_operands_to_worklists() argument
272 add_to_worklists(ctx, ssa_op->result_use, check); in add_operands_to_worklists()
276 add_to_worklists(ctx, ssa_op->op1_use, check); in add_operands_to_worklists()
278 add_to_phi_worklist_no_val(ctx, ssa_op->op1_use); in add_operands_to_worklists()
283 add_to_worklists(ctx, ssa_op->op2_use, check); in add_operands_to_worklists()
285 add_to_phi_worklist_no_val(ctx, ssa_op->op2_use); in add_operands_to_worklists()
290 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
291 zend_ssa *ssa = ctx->ssa; in add_phi_sources_to_worklists()
294 add_to_worklists(ctx, source, check); in add_phi_sources_to_worklists()
298 static inline zend_bool is_var_dead(context *ctx, int var_num) { in is_var_dead() argument
299 zend_ssa_var *var = &ctx->ssa->vars[var_num]; in is_var_dead()
301 return zend_bitset_in(ctx->phi_dead, var_num); in is_var_dead()
303 return zend_bitset_in(ctx->instr_dead, var->definition); in is_var_dead()
308 return var_num >= ctx->op_array->last_var; in is_var_dead()
313 static zend_bool try_remove_var_def(context *ctx, int free_var, int use_chain, zend_op *opline) { in try_remove_var_def() argument
317 zend_ssa_var *var = &ctx->ssa->vars[free_var]; in try_remove_var_def()
321 zend_ssa_op *def_op = &ctx->ssa->ops[def]; in try_remove_var_def()
325 && var->use_chain == (opline - ctx->op_array->opcodes)) { in try_remove_var_def()
326 zend_op *def_opline = &ctx->op_array->opcodes[def]; in try_remove_var_def()
373 static zend_bool dce_instr(context *ctx, zend_op *opline, zend_ssa_op *ssa_op) { in dce_instr() argument
374 zend_ssa *ssa = ctx->ssa; in dce_instr()
385 && !is_var_dead(ctx, ssa_op->op1_use)) { in dce_instr()
389 if ((opline->op1_type & (IS_VAR|IS_TMP_VAR))&& !is_var_dead(ctx, ssa_op->op1_use)) { in dce_instr()
390 if (!try_remove_var_def(ctx, ssa_op->op1_use, ssa_op->op1_use_chain, opline)) { in dce_instr()
398 if ((opline->op2_type & (IS_VAR|IS_TMP_VAR)) && !is_var_dead(ctx, ssa_op->op2_use)) { in dce_instr()
399 if (!try_remove_var_def(ctx, ssa_op->op2_use, ssa_op->op2_use_chain, opline)) { in dce_instr()
403 zend_bitset_excl(ctx->instr_dead, opline - ctx->op_array->opcodes); in dce_instr()
412 zend_ssa_rename_defs_of_instr(ctx->ssa, ssa_op); in dce_instr()
413 zend_ssa_remove_instr(ctx->ssa, opline, ssa_op); in dce_instr()
442 static void try_remove_trivial_phi(context *ctx, zend_ssa_phi *phi) { in try_remove_trivial_phi() argument
443 zend_ssa *ssa = ctx->ssa; in try_remove_trivial_phi()
478 static void dce_live_ranges(context *ctx, zend_op_array *op_array, zend_ssa *ssa) in dce_live_ranges() argument
534 && !is_var_dead(ctx, var)) { in dce_live_ranges()
560 context ctx; in dce_optimize_op_array() local
561 ctx.ssa = ssa; in dce_optimize_op_array()
562 ctx.op_array = op_array; in dce_optimize_op_array()
563 ctx.reorder_dtor_effects = reorder_dtor_effects; in dce_optimize_op_array()
566 ctx.instr_worklist_len = zend_bitset_len(op_array->last); in dce_optimize_op_array()
567 ctx.instr_worklist = alloca(sizeof(zend_ulong) * ctx.instr_worklist_len); in dce_optimize_op_array()
568 memset(ctx.instr_worklist, 0, sizeof(zend_ulong) * ctx.instr_worklist_len); in dce_optimize_op_array()
569 ctx.phi_worklist_len = zend_bitset_len(ssa->vars_count); in dce_optimize_op_array()
570 ctx.phi_worklist = alloca(sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
571 memset(ctx.phi_worklist, 0, sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
572 ctx.phi_worklist_no_val = alloca(sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
573 memset(ctx.phi_worklist_no_val, 0, sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
576 ctx.instr_dead = alloca(sizeof(zend_ulong) * ctx.instr_worklist_len); in dce_optimize_op_array()
577 memset(ctx.instr_dead, 0, sizeof(zend_ulong) * ctx.instr_worklist_len); in dce_optimize_op_array()
578 ctx.phi_dead = alloca(sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
579 memset(ctx.phi_dead, 0xff, sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
600 if (zend_bitset_in(ctx.instr_worklist, i)) { in dce_optimize_op_array()
601 zend_bitset_excl(ctx.instr_worklist, i); in dce_optimize_op_array()
602 add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i], 0); in dce_optimize_op_array()
604 add_operands_to_worklists(&ctx, &op_array->opcodes[op_data], &ssa->ops[op_data], 0); in dce_optimize_op_array()
606 …} else if (may_have_side_effects(op_array, ssa, &op_array->opcodes[i], &ssa->ops[i], ctx.reorder_d… in dce_optimize_op_array()
613 zend_bitset_incl(ctx.instr_dead, i); in dce_optimize_op_array()
614 zend_bitset_incl(ctx.instr_dead, i+1); in dce_optimize_op_array()
616 add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i], 0); in dce_optimize_op_array()
618 add_operands_to_worklists(&ctx, &op_array->opcodes[op_data], &ssa->ops[op_data], 0); in dce_optimize_op_array()
622 zend_bitset_incl(ctx.instr_dead, i); in dce_optimize_op_array()
624 zend_bitset_incl(ctx.instr_dead, op_data); in dce_optimize_op_array()
632 while (!zend_bitset_empty(ctx.instr_worklist, ctx.instr_worklist_len) in dce_optimize_op_array()
633 || !zend_bitset_empty(ctx.phi_worklist, ctx.phi_worklist_len)) { in dce_optimize_op_array()
634 while ((i = zend_bitset_pop_first(ctx.instr_worklist, ctx.instr_worklist_len)) >= 0) { in dce_optimize_op_array()
635 zend_bitset_excl(ctx.instr_dead, i); in dce_optimize_op_array()
636 add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i], 1); in dce_optimize_op_array()
638 zend_bitset_excl(ctx.instr_dead, i+1); in dce_optimize_op_array()
639 add_operands_to_worklists(&ctx, &op_array->opcodes[i+1], &ssa->ops[i+1], 1); in dce_optimize_op_array()
642 while ((i = zend_bitset_pop_first(ctx.phi_worklist, ctx.phi_worklist_len)) >= 0) { in dce_optimize_op_array()
643 zend_bitset_excl(ctx.phi_dead, i); in dce_optimize_op_array()
644 zend_bitset_excl(ctx.phi_worklist_no_val, i); in dce_optimize_op_array()
645 add_phi_sources_to_worklists(&ctx, ssa->vars[i].definition_phi, 1); in dce_optimize_op_array()
650 dce_live_ranges(&ctx, op_array, ssa); in dce_optimize_op_array()
654 ZEND_BITSET_FOREACH(ctx.instr_dead, ctx.instr_worklist_len, i) { in dce_optimize_op_array()
655 removed_ops += dce_instr(&ctx, &op_array->opcodes[i], &ssa->ops[i]); in dce_optimize_op_array()
662 while ((i = zend_bitset_pop_first(ctx.phi_worklist_no_val, ctx.phi_worklist_len)) >= 0) { in dce_optimize_op_array()
665 zend_bitset_excl(ctx.phi_dead, i); in dce_optimize_op_array()
667 add_to_phi_worklist_no_val(&ctx, source); in dce_optimize_op_array()
673 if (zend_bitset_in(ctx.phi_dead, phi->ssa_var)) { in dce_optimize_op_array()
678 try_remove_trivial_phi(&ctx, phi); in dce_optimize_op_array()