Lines Matching refs:ctx

273 static zend_always_inline void add_to_worklists(context *ctx, int var_num, int check) {  in add_to_worklists()  argument
274 zend_ssa_var *var = &ctx->ssa->vars[var_num]; in add_to_worklists()
276 if (!check || zend_bitset_in(ctx->instr_dead, var->definition)) { in add_to_worklists()
277 zend_bitset_incl(ctx->instr_worklist, var->definition); in add_to_worklists()
280 if (!check || zend_bitset_in(ctx->phi_dead, var_num)) { in add_to_worklists()
281 zend_bitset_incl(ctx->phi_worklist, var_num); in add_to_worklists()
286 static inline void add_to_phi_worklist_no_val(context *ctx, int var_num) { in add_to_phi_worklist_no_val() argument
287 zend_ssa_var *var = &ctx->ssa->vars[var_num]; in add_to_phi_worklist_no_val()
288 if (var->definition_phi && zend_bitset_in(ctx->phi_dead, var_num)) { in add_to_phi_worklist_no_val()
289 zend_bitset_incl(ctx->phi_worklist_no_val, var_num); in add_to_phi_worklist_no_val()
293 static zend_always_inline void add_operands_to_worklists(context *ctx, zend_op *opline, zend_ssa_op… in add_operands_to_worklists() argument
295 add_to_worklists(ctx, ssa_op->result_use, check); in add_operands_to_worklists()
301 add_to_worklists(ctx, ssa_op->op1_use, check); in add_operands_to_worklists()
303 add_to_phi_worklist_no_val(ctx, ssa_op->op1_use); in add_operands_to_worklists()
310 add_to_worklists(ctx, ssa_op->op2_use, check); in add_operands_to_worklists()
312 add_to_phi_worklist_no_val(ctx, ssa_op->op2_use); in add_operands_to_worklists()
317 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
318 zend_ssa *ssa = ctx->ssa; in add_phi_sources_to_worklists()
321 add_to_worklists(ctx, source, check); in add_phi_sources_to_worklists()
325 static inline bool is_var_dead(context *ctx, int var_num) { in is_var_dead() argument
326 zend_ssa_var *var = &ctx->ssa->vars[var_num]; in is_var_dead()
328 return zend_bitset_in(ctx->phi_dead, var_num); in is_var_dead()
330 return zend_bitset_in(ctx->instr_dead, var->definition); in is_var_dead()
335 return var_num >= ctx->op_array->last_var; in is_var_dead()
340 static bool try_remove_var_def(context *ctx, int free_var, int use_chain, zend_op *opline) { in try_remove_var_def() argument
344 zend_ssa_var *var = &ctx->ssa->vars[free_var]; in try_remove_var_def()
348 zend_ssa_op *def_op = &ctx->ssa->ops[def]; in try_remove_var_def()
352 && var->use_chain == (opline - ctx->op_array->opcodes)) { in try_remove_var_def()
353 zend_op *def_opline = &ctx->op_array->opcodes[def]; in try_remove_var_def()
396 static inline bool is_free_of_live_var(context *ctx, zend_op *opline, zend_ssa_op *ssa_op) { in is_free_of_live_var() argument
400 if ((ctx->ssa->var_info[ssa_op->op1_use].type & (MAY_BE_REF|MAY_BE_ANY|MAY_BE_UNDEF)) != 0 in is_free_of_live_var()
401 && !may_be_refcounted(ctx->ssa->var_info[ssa_op->op1_use].type)) { in is_free_of_live_var()
406 return !is_var_dead(ctx, ssa_op->op1_use); in is_free_of_live_var()
413 static bool dce_instr(context *ctx, zend_op *opline, zend_ssa_op *ssa_op) { in dce_instr() argument
414 zend_ssa *ssa = ctx->ssa; in dce_instr()
423 if (is_free_of_live_var(ctx, opline, ssa_op)) { in dce_instr()
427 if ((opline->op1_type & (IS_VAR|IS_TMP_VAR))&& !is_var_dead(ctx, ssa_op->op1_use)) { in dce_instr()
428 if (!try_remove_var_def(ctx, ssa_op->op1_use, ssa_op->op1_use_chain, opline)) { in dce_instr()
436 if ((opline->op2_type & (IS_VAR|IS_TMP_VAR)) && !is_var_dead(ctx, ssa_op->op2_use)) { in dce_instr()
437 if (!try_remove_var_def(ctx, ssa_op->op2_use, ssa_op->op2_use_chain, opline)) { in dce_instr()
441 zend_bitset_excl(ctx->instr_dead, opline - ctx->op_array->opcodes); in dce_instr()
450 zend_ssa_rename_defs_of_instr(ctx->ssa, ssa_op); in dce_instr()
451 zend_ssa_remove_instr(ctx->ssa, opline, ssa_op); in dce_instr()
486 static void try_remove_trivial_phi(context *ctx, zend_ssa_phi *phi) { in try_remove_trivial_phi() argument
487 zend_ssa *ssa = ctx->ssa; in try_remove_trivial_phi()
534 context ctx; in dce_optimize_op_array() local
535 ctx.ssa = ssa; in dce_optimize_op_array()
536 ctx.op_array = op_array; in dce_optimize_op_array()
537 ctx.reorder_dtor_effects = reorder_dtor_effects; in dce_optimize_op_array()
541 ctx.instr_worklist_len = zend_bitset_len(op_array->last); in dce_optimize_op_array()
542ctx.instr_worklist = zend_arena_calloc(&optimizer_ctx->arena, ctx.instr_worklist_len, sizeof(zend_… in dce_optimize_op_array()
543 ctx.phi_worklist_len = zend_bitset_len(ssa->vars_count); in dce_optimize_op_array()
544ctx.phi_worklist = zend_arena_calloc(&optimizer_ctx->arena, ctx.phi_worklist_len, sizeof(zend_ulon… in dce_optimize_op_array()
545ctx.phi_worklist_no_val = zend_arena_calloc(&optimizer_ctx->arena, ctx.phi_worklist_len, sizeof(ze… in dce_optimize_op_array()
548ctx.instr_dead = zend_arena_calloc(&optimizer_ctx->arena, ctx.instr_worklist_len, sizeof(zend_ulon… in dce_optimize_op_array()
549 ctx.phi_dead = zend_arena_alloc(&optimizer_ctx->arena, ctx.phi_worklist_len * sizeof(zend_ulong)); in dce_optimize_op_array()
550 memset(ctx.phi_dead, 0xff, sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
558 zend_bitset_excl(ctx.phi_dead, phi->ssa_var); in dce_optimize_op_array()
559 add_phi_sources_to_worklists(&ctx, phi, 0); in dce_optimize_op_array()
582 if (zend_bitset_in(ctx.instr_worklist, i)) { in dce_optimize_op_array()
583 zend_bitset_excl(ctx.instr_worklist, i); in dce_optimize_op_array()
584 add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i], ssa, 0); in dce_optimize_op_array()
586 add_operands_to_worklists(&ctx, &op_array->opcodes[op_data], &ssa->ops[op_data], ssa, 0); in dce_optimize_op_array()
588 …} else if (may_have_side_effects(op_array, ssa, &op_array->opcodes[i], &ssa->ops[i], ctx.reorder_d… in dce_optimize_op_array()
596 zend_bitset_incl(ctx.instr_dead, i); in dce_optimize_op_array()
597 zend_bitset_incl(ctx.instr_dead, i+1); in dce_optimize_op_array()
599 add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i], ssa, 0); in dce_optimize_op_array()
601 add_operands_to_worklists(&ctx, &op_array->opcodes[op_data], &ssa->ops[op_data], ssa, 0); in dce_optimize_op_array()
605 zend_bitset_incl(ctx.instr_dead, i); in dce_optimize_op_array()
607 zend_bitset_incl(ctx.instr_dead, op_data); in dce_optimize_op_array()
615 while (!zend_bitset_empty(ctx.instr_worklist, ctx.instr_worklist_len) in dce_optimize_op_array()
616 || !zend_bitset_empty(ctx.phi_worklist, ctx.phi_worklist_len)) { in dce_optimize_op_array()
617 while ((i = zend_bitset_pop_first(ctx.instr_worklist, ctx.instr_worklist_len)) >= 0) { in dce_optimize_op_array()
618 zend_bitset_excl(ctx.instr_dead, i); in dce_optimize_op_array()
619 add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i], ssa, 1); in dce_optimize_op_array()
624 zend_bitset_excl(ctx.instr_dead, i+1); in dce_optimize_op_array()
625 add_operands_to_worklists(&ctx, &op_array->opcodes[i+1], &ssa->ops[i+1], ssa, 1); in dce_optimize_op_array()
628 while ((i = zend_bitset_pop_first(ctx.phi_worklist, ctx.phi_worklist_len)) >= 0) { in dce_optimize_op_array()
629 zend_bitset_excl(ctx.phi_dead, i); in dce_optimize_op_array()
630 zend_bitset_excl(ctx.phi_worklist_no_val, i); in dce_optimize_op_array()
631 add_phi_sources_to_worklists(&ctx, ssa->vars[i].definition_phi, 1); in dce_optimize_op_array()
636 ZEND_BITSET_FOREACH(ctx.instr_dead, ctx.instr_worklist_len, i) { in dce_optimize_op_array()
637 removed_ops += dce_instr(&ctx, &op_array->opcodes[i], &ssa->ops[i]); in dce_optimize_op_array()
644 while ((i = zend_bitset_pop_first(ctx.phi_worklist_no_val, ctx.phi_worklist_len)) >= 0) { in dce_optimize_op_array()
647 zend_bitset_excl(ctx.phi_dead, i); in dce_optimize_op_array()
649 add_to_phi_worklist_no_val(&ctx, source); in dce_optimize_op_array()
655 if (zend_bitset_in(ctx.phi_dead, phi->ssa_var)) { in dce_optimize_op_array()
660 try_remove_trivial_phi(&ctx, phi); in dce_optimize_op_array()