Lines Matching refs:ctx
260 static zend_always_inline void add_to_worklists(context *ctx, int var_num, int check) { in add_to_worklists() argument
261 zend_ssa_var *var = &ctx->ssa->vars[var_num]; in add_to_worklists()
263 if (!check || zend_bitset_in(ctx->instr_dead, var->definition)) { in add_to_worklists()
264 zend_bitset_incl(ctx->instr_worklist, var->definition); in add_to_worklists()
267 if (!check || zend_bitset_in(ctx->phi_dead, var_num)) { in add_to_worklists()
268 zend_bitset_incl(ctx->phi_worklist, var_num); in add_to_worklists()
273 static inline void add_to_phi_worklist_no_val(context *ctx, int var_num) { in add_to_phi_worklist_no_val() argument
274 zend_ssa_var *var = &ctx->ssa->vars[var_num]; in add_to_phi_worklist_no_val()
275 if (var->definition_phi && zend_bitset_in(ctx->phi_dead, var_num)) { in add_to_phi_worklist_no_val()
276 zend_bitset_incl(ctx->phi_worklist_no_val, var_num); in add_to_phi_worklist_no_val()
280 static zend_always_inline void add_operands_to_worklists(context *ctx, zend_op *opline, zend_ssa_op… in add_operands_to_worklists() argument
282 add_to_worklists(ctx, ssa_op->result_use, check); in add_operands_to_worklists()
288 add_to_worklists(ctx, ssa_op->op1_use, check); in add_operands_to_worklists()
290 add_to_phi_worklist_no_val(ctx, ssa_op->op1_use); in add_operands_to_worklists()
297 add_to_worklists(ctx, ssa_op->op2_use, check); in add_operands_to_worklists()
299 add_to_phi_worklist_no_val(ctx, ssa_op->op2_use); in add_operands_to_worklists()
304 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
305 zend_ssa *ssa = ctx->ssa; in add_phi_sources_to_worklists()
308 add_to_worklists(ctx, source, check); in add_phi_sources_to_worklists()
312 static inline zend_bool is_var_dead(context *ctx, int var_num) { in is_var_dead() argument
313 zend_ssa_var *var = &ctx->ssa->vars[var_num]; in is_var_dead()
315 return zend_bitset_in(ctx->phi_dead, var_num); in is_var_dead()
317 return zend_bitset_in(ctx->instr_dead, var->definition); in is_var_dead()
322 return var_num >= ctx->op_array->last_var; in is_var_dead()
327 static zend_bool try_remove_var_def(context *ctx, int free_var, int use_chain, zend_op *opline) { in try_remove_var_def() argument
331 zend_ssa_var *var = &ctx->ssa->vars[free_var]; in try_remove_var_def()
335 zend_ssa_op *def_op = &ctx->ssa->ops[def]; in try_remove_var_def()
339 && var->use_chain == (opline - ctx->op_array->opcodes)) { in try_remove_var_def()
340 zend_op *def_opline = &ctx->op_array->opcodes[def]; in try_remove_var_def()
384 static zend_bool dce_instr(context *ctx, zend_op *opline, zend_ssa_op *ssa_op) { in dce_instr() argument
385 zend_ssa *ssa = ctx->ssa; in dce_instr()
397 && !is_var_dead(ctx, ssa_op->op1_use)) { in dce_instr()
401 if ((opline->op1_type & (IS_VAR|IS_TMP_VAR))&& !is_var_dead(ctx, ssa_op->op1_use)) { in dce_instr()
402 if (!try_remove_var_def(ctx, ssa_op->op1_use, ssa_op->op1_use_chain, opline)) { in dce_instr()
410 if ((opline->op2_type & (IS_VAR|IS_TMP_VAR)) && !is_var_dead(ctx, ssa_op->op2_use)) { in dce_instr()
411 if (!try_remove_var_def(ctx, ssa_op->op2_use, ssa_op->op2_use_chain, opline)) { in dce_instr()
415 zend_bitset_excl(ctx->instr_dead, opline - ctx->op_array->opcodes); in dce_instr()
424 zend_ssa_rename_defs_of_instr(ctx->ssa, ssa_op); in dce_instr()
425 zend_ssa_remove_instr(ctx->ssa, opline, ssa_op); in dce_instr()
460 static void try_remove_trivial_phi(context *ctx, zend_ssa_phi *phi) { in try_remove_trivial_phi() argument
461 zend_ssa *ssa = ctx->ssa; in try_remove_trivial_phi()
508 context ctx; in dce_optimize_op_array() local
509 ctx.ssa = ssa; in dce_optimize_op_array()
510 ctx.op_array = op_array; in dce_optimize_op_array()
511 ctx.reorder_dtor_effects = reorder_dtor_effects; in dce_optimize_op_array()
514 ctx.instr_worklist_len = zend_bitset_len(op_array->last); in dce_optimize_op_array()
515 ctx.instr_worklist = alloca(sizeof(zend_ulong) * ctx.instr_worklist_len); in dce_optimize_op_array()
516 memset(ctx.instr_worklist, 0, sizeof(zend_ulong) * ctx.instr_worklist_len); in dce_optimize_op_array()
517 ctx.phi_worklist_len = zend_bitset_len(ssa->vars_count); in dce_optimize_op_array()
518 ctx.phi_worklist = alloca(sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
519 memset(ctx.phi_worklist, 0, sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
520 ctx.phi_worklist_no_val = alloca(sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
521 memset(ctx.phi_worklist_no_val, 0, sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
524 ctx.instr_dead = alloca(sizeof(zend_ulong) * ctx.instr_worklist_len); in dce_optimize_op_array()
525 memset(ctx.instr_dead, 0, sizeof(zend_ulong) * ctx.instr_worklist_len); in dce_optimize_op_array()
526 ctx.phi_dead = alloca(sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
527 memset(ctx.phi_dead, 0xff, sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
535 zend_bitset_excl(ctx.phi_dead, phi->ssa_var); in dce_optimize_op_array()
536 add_phi_sources_to_worklists(&ctx, phi, 0); in dce_optimize_op_array()
559 if (zend_bitset_in(ctx.instr_worklist, i)) { in dce_optimize_op_array()
560 zend_bitset_excl(ctx.instr_worklist, i); in dce_optimize_op_array()
561 add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i], ssa, 0); in dce_optimize_op_array()
563 add_operands_to_worklists(&ctx, &op_array->opcodes[op_data], &ssa->ops[op_data], ssa, 0); in dce_optimize_op_array()
565 …} else if (may_have_side_effects(op_array, ssa, &op_array->opcodes[i], &ssa->ops[i], ctx.reorder_d… in dce_optimize_op_array()
573 zend_bitset_incl(ctx.instr_dead, i); in dce_optimize_op_array()
574 zend_bitset_incl(ctx.instr_dead, i+1); in dce_optimize_op_array()
576 add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i], ssa, 0); in dce_optimize_op_array()
578 add_operands_to_worklists(&ctx, &op_array->opcodes[op_data], &ssa->ops[op_data], ssa, 0); in dce_optimize_op_array()
582 zend_bitset_incl(ctx.instr_dead, i); in dce_optimize_op_array()
584 zend_bitset_incl(ctx.instr_dead, op_data); in dce_optimize_op_array()
592 while (!zend_bitset_empty(ctx.instr_worklist, ctx.instr_worklist_len) in dce_optimize_op_array()
593 || !zend_bitset_empty(ctx.phi_worklist, ctx.phi_worklist_len)) { in dce_optimize_op_array()
594 while ((i = zend_bitset_pop_first(ctx.instr_worklist, ctx.instr_worklist_len)) >= 0) { in dce_optimize_op_array()
595 zend_bitset_excl(ctx.instr_dead, i); in dce_optimize_op_array()
596 add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i], ssa, 1); in dce_optimize_op_array()
601 zend_bitset_excl(ctx.instr_dead, i+1); in dce_optimize_op_array()
602 add_operands_to_worklists(&ctx, &op_array->opcodes[i+1], &ssa->ops[i+1], ssa, 1); in dce_optimize_op_array()
605 while ((i = zend_bitset_pop_first(ctx.phi_worklist, ctx.phi_worklist_len)) >= 0) { in dce_optimize_op_array()
606 zend_bitset_excl(ctx.phi_dead, i); in dce_optimize_op_array()
607 zend_bitset_excl(ctx.phi_worklist_no_val, i); in dce_optimize_op_array()
608 add_phi_sources_to_worklists(&ctx, ssa->vars[i].definition_phi, 1); in dce_optimize_op_array()
613 ZEND_BITSET_FOREACH(ctx.instr_dead, ctx.instr_worklist_len, i) { in dce_optimize_op_array()
614 removed_ops += dce_instr(&ctx, &op_array->opcodes[i], &ssa->ops[i]); in dce_optimize_op_array()
621 while ((i = zend_bitset_pop_first(ctx.phi_worklist_no_val, ctx.phi_worklist_len)) >= 0) { in dce_optimize_op_array()
624 zend_bitset_excl(ctx.phi_dead, i); in dce_optimize_op_array()
626 add_to_phi_worklist_no_val(&ctx, source); in dce_optimize_op_array()
632 if (zend_bitset_in(ctx.phi_dead, phi->ssa_var)) { in dce_optimize_op_array()
637 try_remove_trivial_phi(&ctx, phi); in dce_optimize_op_array()