nir: Report progress from nir_lower_phis_to_scalar.
authorKenneth Graunke <kenneth@whitecape.org>
Tue, 13 Sep 2016 22:14:28 +0000 (15:14 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Wed, 14 Sep 2016 19:01:51 +0000 (12:01 -0700)
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/compiler/nir/nir.h
src/compiler/nir/nir_lower_phis_to_scalar.c
src/gallium/drivers/freedreno/ir3/ir3_nir.c
src/gallium/drivers/vc4/vc4_program.c
src/mesa/drivers/dri/i965/brw_nir.c

index 3b3d6ae83932dab8023779b837d434b4e0468ab3..94eae6d3037ffb89f4b67fdbc33cba1958512563 100644 (file)
@@ -2413,7 +2413,7 @@ bool nir_lower_vec_to_movs(nir_shader *shader);
 bool nir_lower_alu_to_scalar(nir_shader *shader);
 void nir_lower_load_const_to_scalar(nir_shader *shader);
 
-void nir_lower_phis_to_scalar(nir_shader *shader);
+bool nir_lower_phis_to_scalar(nir_shader *shader);
 void nir_lower_io_to_scalar(nir_shader *shader, nir_variable_mode mask);
 
 void nir_lower_samplers(nir_shader *shader,
index 9fd00cc784aad8233d6d9b931331ef9fdb51600f..b12718f27327c01abfe3e07726c1ca46554b9fa1 100644 (file)
@@ -166,6 +166,8 @@ static bool
 lower_phis_to_scalar_block(nir_block *block,
                            struct lower_phis_to_scalar_state *state)
 {
+   bool progress = false;
+
    /* Find the last phi node in the block */
    nir_phi_instr *last_phi = NULL;
    nir_foreach_instr(instr, block) {
@@ -248,6 +250,8 @@ lower_phis_to_scalar_block(nir_block *block,
       ralloc_steal(state->dead_ctx, phi);
       nir_instr_remove(&phi->instr);
 
+      progress = true;
+
       /* We're using the safe iterator and inserting all the newly
        * scalarized phi nodes before their non-scalarized version so that's
        * ok.  However, we are also inserting vec operations after all of
@@ -258,13 +262,14 @@ lower_phis_to_scalar_block(nir_block *block,
          break;
    }
 
-   return true;
+   return progress;
 }
 
-static void
+static bool
 lower_phis_to_scalar_impl(nir_function_impl *impl)
 {
    struct lower_phis_to_scalar_state state;
+   bool progress = false;
 
    state.mem_ctx = ralloc_parent(impl);
    state.dead_ctx = ralloc_context(NULL);
@@ -272,13 +277,14 @@ lower_phis_to_scalar_impl(nir_function_impl *impl)
                                              _mesa_key_pointer_equal);
 
    nir_foreach_block(block, impl) {
-      lower_phis_to_scalar_block(block, &state);
+      progress = lower_phis_to_scalar_block(block, &state) || progress;
    }
 
    nir_metadata_preserve(impl, nir_metadata_block_index |
                                nir_metadata_dominance);
 
    ralloc_free(state.dead_ctx);
+   return progress;
 }
 
 /** A pass that lowers vector phi nodes to scalar
@@ -288,11 +294,15 @@ lower_phis_to_scalar_impl(nir_function_impl *impl)
  * instance, if one of the sources is a non-scalarizable vector, then we
  * don't bother lowering because that would generate hard-to-coalesce movs.
  */
-void
+bool
 nir_lower_phis_to_scalar(nir_shader *shader)
 {
+   bool progress = false;
+
    nir_foreach_function(function, shader) {
       if (function->impl)
-         lower_phis_to_scalar_impl(function->impl);
+         progress = lower_phis_to_scalar_impl(function->impl) || progress;
    }
+
+   return progress;
 }
index 25262224f9844bd6ab287f4fa4f3722e99bb104e..2d86a524cdf96b0033607fbb5c107afa1f15efc4 100644 (file)
@@ -91,7 +91,7 @@ ir3_optimize_loop(nir_shader *s)
 
                OPT_V(s, nir_lower_vars_to_ssa);
                progress |= OPT(s, nir_lower_alu_to_scalar);
-               OPT_V(s, nir_lower_phis_to_scalar);
+               progress |= OPT(s, nir_lower_phis_to_scalar);
 
                progress |= OPT(s, nir_copy_prop);
                progress |= OPT(s, nir_opt_dce);
index 24e4699b92e4abe5b971b1caff6a66c1fd90da12..986a1ffc64bee1f5c6867b13bf9603a1b28ed8a7 100644 (file)
@@ -1424,8 +1424,7 @@ vc4_optimize_nir(struct nir_shader *s)
 
                 NIR_PASS_V(s, nir_lower_vars_to_ssa);
                 NIR_PASS(progress, s, nir_lower_alu_to_scalar);
-                NIR_PASS_V(s, nir_lower_phis_to_scalar);
-
+                NIR_PASS(progress, s, nir_lower_phis_to_scalar);
                 NIR_PASS(progress, s, nir_copy_prop);
                 NIR_PASS(progress, s, nir_opt_remove_phis);
                 NIR_PASS(progress, s, nir_opt_dce);
index 27be201db6f2159391f0277a57b50fcb284ba2fa..5b2130fa6888931773c0a855f871cd39dd22c8b2 100644 (file)
@@ -381,7 +381,7 @@ nir_optimize(nir_shader *nir, bool is_scalar)
       OPT(nir_copy_prop);
 
       if (is_scalar) {
-         OPT_V(nir_lower_phis_to_scalar);
+         OPT(nir_lower_phis_to_scalar);
       }
 
       OPT(nir_copy_prop);