summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>2020-05-06 17:34:09 -0400
committerMarge Bot <eric+marge@anholt.net>2020-05-20 17:06:34 +0000
commitfc06b8b7dc27d9e0b1a84e898d9f42465bd491e4 (patch)
treecc6e776de5c4c66cffa41fa32d71e8d1b0faf5b0
parentc24dfc9da42abadf079b012f0d6e52fb4c829112 (diff)
pan/mdg: Optimize liveness computation in DCE
Rather than recompute liveness every block, compute it just once for the whole shader, which ends up more efficient. Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5123>
-rw-r--r--src/panfrost/midgard/compiler.h2
-rw-r--r--src/panfrost/midgard/midgard_compile.c2
-rw-r--r--src/panfrost/midgard/midgard_opt_dce.c28
3 files changed, 25 insertions, 7 deletions
diff --git a/src/panfrost/midgard/compiler.h b/src/panfrost/midgard/compiler.h
index 93ff9605542..8132a9e91a9 100644
--- a/src/panfrost/midgard/compiler.h
+++ b/src/panfrost/midgard/compiler.h
@@ -649,7 +649,7 @@ void midgard_nir_lod_errata(nir_shader *shader);
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);
diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c
index 0e5e9844591..b7e11e334d0 100644
--- a/src/panfrost/midgard/midgard_compile.c
+++ b/src/panfrost/midgard/midgard_compile.c
@@ -2622,11 +2622,11 @@ midgard_compile_shader_nir(nir_shader *nir, panfrost_program *program, bool is_b
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);
}
diff --git a/src/panfrost/midgard/midgard_opt_dce.c b/src/panfrost/midgard/midgard_opt_dce.c
index 71395ca36c7..e9e51a6451d 100644
--- a/src/panfrost/midgard/midgard_opt_dce.c
+++ b/src/panfrost/midgard/midgard_opt_dce.c
@@ -63,14 +63,11 @@ can_dce(midgard_instruction *ins)
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) {
@@ -100,6 +97,27 @@ midgard_opt_dead_code_eliminate(compiler_context *ctx, midgard_block *block)
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 */