[Mesa-dev] [PATCH v2 08/10] nir/algebraic: Use the nir_pass framework internally

Jason Ekstrand jason at jlekstrand.net
Tue Nov 3 13:41:14 PST 2015


Reviewed-by: Kristian Høgsberg <krh at bitplanet.net>
---
 src/glsl/nir/nir.h            |  4 ++--
 src/glsl/nir/nir_algebraic.py | 38 +++++++++++++-------------------------
 2 files changed, 15 insertions(+), 27 deletions(-)

diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index 5242112..beca805 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1602,6 +1602,8 @@ bool nir_function_impl_run_pass(nir_function_impl *impl, const nir_pass *pass,
 NIR_DECL_PASS(nir_lower_alu_to_scalar)
 NIR_DECL_PASS(nir_lower_phis_to_scalar)
 NIR_DECL_PASS(nir_lower_vars_to_ssa)
+NIR_DECL_PASS(nir_opt_algebraic)
+NIR_DECL_PASS(nir_opt_algebraic_late)
 NIR_DECL_PASS(nir_opt_copy_prop)
 NIR_DECL_PASS(nir_opt_cse)
 NIR_DECL_PASS(nir_opt_dce)
@@ -2018,8 +2020,6 @@ void nir_convert_to_ssa(nir_shader *shader);
  */
 void nir_convert_from_ssa(nir_shader *shader, bool phi_webs_only);
 
-bool nir_opt_algebraic(nir_shader *shader);
-bool nir_opt_algebraic_late(nir_shader *shader);
 bool nir_opt_constant_folding(nir_shader *shader);
 
 bool nir_opt_global_to_local(nir_shader *shader);
diff --git a/src/glsl/nir/nir_algebraic.py b/src/glsl/nir/nir_algebraic.py
index bbf4f08..a8812e7 100644
--- a/src/glsl/nir/nir_algebraic.py
+++ b/src/glsl/nir/nir_algebraic.py
@@ -247,42 +247,30 @@ ${pass_name}_block(nir_block *block, void *void_state)
 }
 
 static bool
-${pass_name}_impl(nir_function_impl *impl, const bool *condition_flags)
+${pass_name}_impl(nir_function_impl *impl, void *unused)
 {
-   struct opt_state state;
+   nir_shader *shader = impl->overload->function->shader;
+   const nir_shader_compiler_options *options = shader->options;
 
+   bool condition_flags[${len(condition_list)}];
+   % for index, condition in enumerate(condition_list):
+   condition_flags[${index}] = ${condition};
+   % endfor
+
+   struct opt_state state;
    state.mem_ctx = ralloc_parent(impl);
    state.progress = false;
    state.condition_flags = condition_flags;
 
    nir_foreach_block(impl, ${pass_name}_block, &state);
 
-   if (state.progress)
-      nir_metadata_preserve(impl, nir_metadata_block_index |
-                                  nir_metadata_dominance);
-
    return state.progress;
 }
 
-
-bool
-${pass_name}(nir_shader *shader)
-{
-   bool progress = false;
-   bool condition_flags[${len(condition_list)}];
-   const nir_shader_compiler_options *options = shader->options;
-
-   % for index, condition in enumerate(condition_list):
-   condition_flags[${index}] = ${condition};
-   % endfor
-
-   nir_foreach_overload(shader, overload) {
-      if (overload->impl)
-         progress |= ${pass_name}_impl(overload->impl, condition_flags);
-   }
-
-   return progress;
-}
+const nir_pass ${pass_name}_pass = {
+   .impl_pass_func = ${pass_name}_impl,
+   .metadata_preserved = nir_metadata_block_index | nir_metadata_dominance,
+};
 """)
 
 class AlgebraicPass(object):
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list