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,
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) {
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
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);
_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
* 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;
}
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);
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);