[Mesa-dev] [PATCH 05/11] nir/phis_to_scalar: Use the nir_pass framework internally

Ian Romanick idr at freedesktop.org
Wed Oct 28 16:28:25 PDT 2015


On 10/28/2015 02:32 PM, Jason Ekstrand wrote:
> ---
>  src/glsl/nir/nir_lower_phis_to_scalar.c | 25 ++++++++++++++++---------
>  1 file changed, 16 insertions(+), 9 deletions(-)
> 
> diff --git a/src/glsl/nir/nir_lower_phis_to_scalar.c b/src/glsl/nir/nir_lower_phis_to_scalar.c
> index aa124d9..909a743 100644
> --- a/src/glsl/nir/nir_lower_phis_to_scalar.c
> +++ b/src/glsl/nir/nir_lower_phis_to_scalar.c
> @@ -41,6 +41,8 @@ struct lower_phis_to_scalar_state {
>      * scalarizable or non-null for scalarizable.
>      */
>     struct hash_table *phi_table;
> +
> +   bool progress;
>  };
>  
>  static bool
> @@ -192,6 +194,8 @@ lower_phis_to_scalar_block(nir_block *block, void *void_state)
>        if (!should_lower_phi(phi, state))
>           continue;
>  
> +      state->progress = true;
> +
>        /* Create a vecN operation to combine the results.  Most of these
>         * will be redundant, but copy propagation should clean them up for
>         * us.  No need to add the complexity here.
> @@ -262,8 +266,8 @@ lower_phis_to_scalar_block(nir_block *block, void *void_state)
>     return true;
>  }
>  
> -static void
> -lower_phis_to_scalar_impl(nir_function_impl *impl)
> +static bool
> +lower_phis_to_scalar_impl(nir_function_impl *impl, void *unused)

Please add a '(void) unused;' in the function so that other people don't
get added, spurious warnings... and have to submit a patch that adds it
anyway.  I really hope a future C standard enables the C++ idiom of
leaving the names off unused parameters.

>  {
>     struct lower_phis_to_scalar_state state;
>  
> @@ -271,13 +275,13 @@ lower_phis_to_scalar_impl(nir_function_impl *impl)
>     state.dead_ctx = ralloc_context(NULL);
>     state.phi_table = _mesa_hash_table_create(state.dead_ctx, _mesa_hash_pointer,
>                                               _mesa_key_pointer_equal);
> +   state.progress = false;
>  
>     nir_foreach_block(impl, lower_phis_to_scalar_block, &state);
>  
> -   nir_metadata_preserve(impl, nir_metadata_block_index |
> -                               nir_metadata_dominance);
> -
>     ralloc_free(state.dead_ctx);
> +
> +   return state.progress;
>  }
>  
>  /** A pass that lowers vector phi nodes to scalar
> @@ -287,11 +291,14 @@ 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.
>   */
> +static const nir_pass nir_lower_phis_to_scalar_pass = {
> +   NULL, /* shader_pass_func */
> +   lower_phis_to_scalar_impl,
> +   nir_metadata_block_index | nir_metadata_dominance,
> +};
> +
>  void
>  nir_lower_phis_to_scalar(nir_shader *shader)
>  {
> -   nir_foreach_overload(shader, overload) {
> -      if (overload->impl)
> -         lower_phis_to_scalar_impl(overload->impl);
> -   }
> +   nir_shader_run_pass(shader, &nir_lower_phis_to_scalar_pass);
>  }
> 



More information about the mesa-dev mailing list