Lines Matching refs:ctx

274 static zend_always_inline void add_to_worklists(context *ctx, int var_num, int check) {  in add_to_worklists()  argument
275 zend_ssa_var *var = &ctx->ssa->vars[var_num]; in add_to_worklists()
277 if (!check || zend_bitset_in(ctx->instr_dead, var->definition)) { in add_to_worklists()
278 zend_bitset_incl(ctx->instr_worklist, var->definition); in add_to_worklists()
281 if (!check || zend_bitset_in(ctx->phi_dead, var_num)) { in add_to_worklists()
282 zend_bitset_incl(ctx->phi_worklist, var_num); in add_to_worklists()
287 static inline void add_to_phi_worklist_no_val(context *ctx, int var_num) { in add_to_phi_worklist_no_val() argument
288 zend_ssa_var *var = &ctx->ssa->vars[var_num]; in add_to_phi_worklist_no_val()
289 if (var->definition_phi && zend_bitset_in(ctx->phi_dead, var_num)) { in add_to_phi_worklist_no_val()
290 zend_bitset_incl(ctx->phi_worklist_no_val, var_num); in add_to_phi_worklist_no_val()
294 static zend_always_inline void add_operands_to_worklists(context *ctx, zend_op *opline, zend_ssa_op… in add_operands_to_worklists() argument
296 add_to_worklists(ctx, ssa_op->result_use, check); in add_operands_to_worklists()
302 add_to_worklists(ctx, ssa_op->op1_use, check); in add_operands_to_worklists()
304 add_to_phi_worklist_no_val(ctx, ssa_op->op1_use); in add_operands_to_worklists()
311 add_to_worklists(ctx, ssa_op->op2_use, check); in add_operands_to_worklists()
313 add_to_phi_worklist_no_val(ctx, ssa_op->op2_use); in add_operands_to_worklists()
318 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
319 zend_ssa *ssa = ctx->ssa; in add_phi_sources_to_worklists()
322 add_to_worklists(ctx, source, check); in add_phi_sources_to_worklists()
326 static inline bool is_var_dead(context *ctx, int var_num) { in is_var_dead() argument
327 zend_ssa_var *var = &ctx->ssa->vars[var_num]; in is_var_dead()
329 return zend_bitset_in(ctx->phi_dead, var_num); in is_var_dead()
331 return zend_bitset_in(ctx->instr_dead, var->definition); in is_var_dead()
336 return var_num >= ctx->op_array->last_var; in is_var_dead()
341 static bool try_remove_var_def(context *ctx, int free_var, int use_chain, zend_op *opline) { in try_remove_var_def() argument
345 zend_ssa_var *var = &ctx->ssa->vars[free_var]; in try_remove_var_def()
349 zend_ssa_op *def_op = &ctx->ssa->ops[def]; in try_remove_var_def()
353 && var->use_chain == (opline - ctx->op_array->opcodes)) { in try_remove_var_def()
354 zend_op *def_opline = &ctx->op_array->opcodes[def]; in try_remove_var_def()
397 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
401 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()
402 && !may_be_refcounted(ctx->ssa->var_info[ssa_op->op1_use].type)) { in is_free_of_live_var()
407 return !is_var_dead(ctx, ssa_op->op1_use); in is_free_of_live_var()
414 static bool dce_instr(context *ctx, zend_op *opline, zend_ssa_op *ssa_op) { in dce_instr() argument
415 zend_ssa *ssa = ctx->ssa; in dce_instr()
424 if (is_free_of_live_var(ctx, opline, ssa_op)) { in dce_instr()
428 if ((opline->op1_type & (IS_VAR|IS_TMP_VAR))&& !is_var_dead(ctx, ssa_op->op1_use)) { in dce_instr()
429 if (!try_remove_var_def(ctx, ssa_op->op1_use, ssa_op->op1_use_chain, opline)) { in dce_instr()
437 if ((opline->op2_type & (IS_VAR|IS_TMP_VAR)) && !is_var_dead(ctx, ssa_op->op2_use)) { in dce_instr()
438 if (!try_remove_var_def(ctx, ssa_op->op2_use, ssa_op->op2_use_chain, opline)) { in dce_instr()
442 zend_bitset_excl(ctx->instr_dead, opline - ctx->op_array->opcodes); in dce_instr()
451 zend_ssa_rename_defs_of_instr(ctx->ssa, ssa_op); in dce_instr()
452 zend_ssa_remove_instr(ctx->ssa, opline, ssa_op); in dce_instr()
487 static void try_remove_trivial_phi(context *ctx, zend_ssa_phi *phi) { in try_remove_trivial_phi() argument
488 zend_ssa *ssa = ctx->ssa; in try_remove_trivial_phi()
535 context ctx; in dce_optimize_op_array() local
536 ctx.ssa = ssa; in dce_optimize_op_array()
537 ctx.op_array = op_array; in dce_optimize_op_array()
538 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()
542 ctx.instr_worklist = alloca(sizeof(zend_ulong) * ctx.instr_worklist_len); in dce_optimize_op_array()
543 memset(ctx.instr_worklist, 0, sizeof(zend_ulong) * ctx.instr_worklist_len); in dce_optimize_op_array()
544 ctx.phi_worklist_len = zend_bitset_len(ssa->vars_count); in dce_optimize_op_array()
545 ctx.phi_worklist = alloca(sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
546 memset(ctx.phi_worklist, 0, sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
547 ctx.phi_worklist_no_val = alloca(sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
548 memset(ctx.phi_worklist_no_val, 0, sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
551 ctx.instr_dead = alloca(sizeof(zend_ulong) * ctx.instr_worklist_len); in dce_optimize_op_array()
552 memset(ctx.instr_dead, 0, sizeof(zend_ulong) * ctx.instr_worklist_len); in dce_optimize_op_array()
553 ctx.phi_dead = alloca(sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
554 memset(ctx.phi_dead, 0xff, sizeof(zend_ulong) * ctx.phi_worklist_len); in dce_optimize_op_array()
562 zend_bitset_excl(ctx.phi_dead, phi->ssa_var); in dce_optimize_op_array()
563 add_phi_sources_to_worklists(&ctx, phi, 0); in dce_optimize_op_array()
586 if (zend_bitset_in(ctx.instr_worklist, i)) { in dce_optimize_op_array()
587 zend_bitset_excl(ctx.instr_worklist, i); in dce_optimize_op_array()
588 add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i], ssa, 0); in dce_optimize_op_array()
590 add_operands_to_worklists(&ctx, &op_array->opcodes[op_data], &ssa->ops[op_data], ssa, 0); in dce_optimize_op_array()
592 …} else if (may_have_side_effects(op_array, ssa, &op_array->opcodes[i], &ssa->ops[i], ctx.reorder_d… in dce_optimize_op_array()
600 zend_bitset_incl(ctx.instr_dead, i); in dce_optimize_op_array()
601 zend_bitset_incl(ctx.instr_dead, i+1); in dce_optimize_op_array()
603 add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i], ssa, 0); in dce_optimize_op_array()
605 add_operands_to_worklists(&ctx, &op_array->opcodes[op_data], &ssa->ops[op_data], ssa, 0); in dce_optimize_op_array()
609 zend_bitset_incl(ctx.instr_dead, i); in dce_optimize_op_array()
611 zend_bitset_incl(ctx.instr_dead, op_data); in dce_optimize_op_array()
619 while (!zend_bitset_empty(ctx.instr_worklist, ctx.instr_worklist_len) in dce_optimize_op_array()
620 || !zend_bitset_empty(ctx.phi_worklist, ctx.phi_worklist_len)) { in dce_optimize_op_array()
621 while ((i = zend_bitset_pop_first(ctx.instr_worklist, ctx.instr_worklist_len)) >= 0) { in dce_optimize_op_array()
622 zend_bitset_excl(ctx.instr_dead, i); in dce_optimize_op_array()
623 add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i], ssa, 1); in dce_optimize_op_array()
628 zend_bitset_excl(ctx.instr_dead, i+1); in dce_optimize_op_array()
629 add_operands_to_worklists(&ctx, &op_array->opcodes[i+1], &ssa->ops[i+1], ssa, 1); in dce_optimize_op_array()
632 while ((i = zend_bitset_pop_first(ctx.phi_worklist, ctx.phi_worklist_len)) >= 0) { in dce_optimize_op_array()
633 zend_bitset_excl(ctx.phi_dead, i); in dce_optimize_op_array()
634 zend_bitset_excl(ctx.phi_worklist_no_val, i); in dce_optimize_op_array()
635 add_phi_sources_to_worklists(&ctx, ssa->vars[i].definition_phi, 1); in dce_optimize_op_array()
640 ZEND_BITSET_FOREACH(ctx.instr_dead, ctx.instr_worklist_len, i) { in dce_optimize_op_array()
641 removed_ops += dce_instr(&ctx, &op_array->opcodes[i], &ssa->ops[i]); in dce_optimize_op_array()
648 while ((i = zend_bitset_pop_first(ctx.phi_worklist_no_val, ctx.phi_worklist_len)) >= 0) { in dce_optimize_op_array()
651 zend_bitset_excl(ctx.phi_dead, i); in dce_optimize_op_array()
653 add_to_phi_worklist_no_val(&ctx, source); in dce_optimize_op_array()
659 if (zend_bitset_in(ctx.phi_dead, phi->ssa_var)) { in dce_optimize_op_array()
664 try_remove_trivial_phi(&ctx, phi); in dce_optimize_op_array()