Mesa (master): pan/mdg: Optimize liveness computation in DCE

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed May 20 17:29:32 UTC 2020


Module: Mesa
Branch: master
Commit: fc06b8b7dc27d9e0b1a84e898d9f42465bd491e4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=fc06b8b7dc27d9e0b1a84e898d9f42465bd491e4

Author: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Date:   Wed May  6 17:34:09 2020 -0400

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 at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5123>

---

 src/panfrost/midgard/compiler.h        |  2 +-
 src/panfrost/midgard/midgard_compile.c |  2 +-
 src/panfrost/midgard/midgard_opt_dce.c | 28 +++++++++++++++++++++++-----
 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 */



More information about the mesa-commit mailing list