bool midgard_opt_copy_prop(compiler_context *ctx, midgard_block *block);
bool midgard_opt_combine_projection(compiler_context *ctx, midgard_block *block);
bool midgard_opt_varying_projection(compiler_context *ctx, midgard_block *block);
-bool midgard_opt_dead_code_eliminate(compiler_context *ctx, midgard_block *block);
+bool midgard_opt_dead_code_eliminate(compiler_context *ctx);
bool midgard_opt_dead_move_eliminate(compiler_context *ctx, midgard_block *block);
bool midgard_opt_promote_fmov(compiler_context *ctx, midgard_block *block);
do {
progress = false;
+ progress |= midgard_opt_dead_code_eliminate(ctx);
mir_foreach_block(ctx, _block) {
midgard_block *block = (midgard_block *) _block;
progress |= midgard_opt_copy_prop(ctx, block);
- progress |= midgard_opt_dead_code_eliminate(ctx, block);
progress |= midgard_opt_combine_projection(ctx, block);
progress |= midgard_opt_varying_projection(ctx, block);
}
return true;
}
-bool
-midgard_opt_dead_code_eliminate(compiler_context *ctx, midgard_block *block)
+static bool
+midgard_opt_dead_code_eliminate_block(compiler_context *ctx, midgard_block *block)
{
bool progress = false;
- mir_invalidate_liveness(ctx);
- mir_compute_liveness(ctx);
-
uint16_t *live = mem_dup(block->base.live_out, ctx->temp_count * sizeof(uint16_t));
mir_foreach_instr_in_block_rev(block, ins) {
return progress;
}
+bool
+midgard_opt_dead_code_eliminate(compiler_context *ctx)
+{
+ /* We track liveness. In fact, it's ok if we assume more things are
+ * live than they actually are, that just reduces the effectiveness of
+ * this iterations lightly. And DCE has the effect of strictly reducing
+ * liveness, so we can run DCE across all blocks while only computing
+ * liveness at the beginning. */
+
+ mir_invalidate_liveness(ctx);
+ mir_compute_liveness(ctx);
+
+ bool progress = false;
+
+ mir_foreach_block(ctx, block) {
+ progress |= midgard_opt_dead_code_eliminate_block(ctx, (midgard_block *) block);
+ }
+
+ return progress;
+}
+
/* Removes dead moves, that is, moves with a destination overwritten before
* being read. Normally handled implicitly as part of DCE, but this has to run
* after the out-of-SSA pass */