[Mesa-dev] [PATCH 09/11] nir: Use the nir_pass framework internally for more passes

Jason Ekstrand jason at jlekstrand.net
Wed Oct 28 14:32:09 PDT 2015


In particular, this commit adds it for:
 - nir_opt_constant_folding
 - nir_opt_dead_cf
 - nor_opt_peephole_select
 - nir_opt_remove_phis
 - nir_opt_undef
---
 src/glsl/nir/nir_opt_constant_folding.c | 21 ++++++++-------------
 src/glsl/nir/nir_opt_dead_cf.c          | 23 +++++++++--------------
 src/glsl/nir/nir_opt_peephole_select.c  | 20 ++++++++------------
 src/glsl/nir/nir_opt_remove_phis.c      | 16 ++++++++--------
 src/glsl/nir/nir_opt_undef.c            | 26 +++++++++++++++-----------
 5 files changed, 48 insertions(+), 58 deletions(-)

diff --git a/src/glsl/nir/nir_opt_constant_folding.c b/src/glsl/nir/nir_opt_constant_folding.c
index 007b81c..b5331a6 100644
--- a/src/glsl/nir/nir_opt_constant_folding.c
+++ b/src/glsl/nir/nir_opt_constant_folding.c
@@ -170,7 +170,7 @@ constant_fold_block(nir_block *block, void *void_state)
 }
 
 static bool
-nir_opt_constant_folding_impl(nir_function_impl *impl)
+nir_opt_constant_folding_impl(nir_function_impl *impl, void *unused)
 {
    struct constant_fold_state state;
 
@@ -180,22 +180,17 @@ nir_opt_constant_folding_impl(nir_function_impl *impl)
 
    nir_foreach_block(impl, constant_fold_block, &state);
 
-   if (state.progress)
-      nir_metadata_preserve(impl, nir_metadata_block_index |
-                                  nir_metadata_dominance);
-
    return state.progress;
 }
 
+static const nir_pass nir_opt_constant_folding_pass = {
+   NULL, /* shader_pass_func */
+   nir_opt_constant_folding_impl,
+   nir_metadata_block_index | nir_metadata_dominance,
+};
+
 bool
 nir_opt_constant_folding(nir_shader *shader)
 {
-   bool progress = false;
-
-   nir_foreach_overload(shader, overload) {
-      if (overload->impl)
-         progress |= nir_opt_constant_folding_impl(overload->impl);
-   }
-
-   return progress;
+   return nir_shader_run_pass(shader, &nir_opt_constant_folding_pass);
 }
diff --git a/src/glsl/nir/nir_opt_dead_cf.c b/src/glsl/nir/nir_opt_dead_cf.c
index 0d4819b..b3e6ea5 100644
--- a/src/glsl/nir/nir_opt_dead_cf.c
+++ b/src/glsl/nir/nir_opt_dead_cf.c
@@ -334,25 +334,20 @@ dead_cf_list(struct exec_list *list, bool *list_ends_in_jump)
 }
 
 static bool
-opt_dead_cf_impl(nir_function_impl *impl)
+opt_dead_cf_impl(nir_function_impl *impl, void *unused)
 {
    bool dummy;
-   bool progress = dead_cf_list(&impl->body, &dummy);
-
-   if (progress)
-      nir_metadata_preserve(impl, nir_metadata_none);
-
-   return progress;
+   return dead_cf_list(&impl->body, &dummy);
 }
 
+static const nir_pass nir_opt_dead_cf_pass = {
+   NULL, /* shader_pass_func */
+   opt_dead_cf_impl,
+   nir_metadata_none,
+};
+
 bool
 nir_opt_dead_cf(nir_shader *shader)
 {
-   bool progress = false;
-
-   nir_foreach_overload(shader, overload)
-      if (overload->impl)
-         progress |= opt_dead_cf_impl(overload->impl);
-
-   return progress;
+   return nir_shader_run_pass(shader, &nir_opt_dead_cf_pass);
 }
diff --git a/src/glsl/nir/nir_opt_peephole_select.c b/src/glsl/nir/nir_opt_peephole_select.c
index 90902b9..59022f6 100644
--- a/src/glsl/nir/nir_opt_peephole_select.c
+++ b/src/glsl/nir/nir_opt_peephole_select.c
@@ -227,7 +227,7 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state)
 }
 
 static bool
-nir_opt_peephole_select_impl(nir_function_impl *impl)
+nir_opt_peephole_select_impl(nir_function_impl *impl, void *unused)
 {
    struct peephole_select_state state;
 
@@ -236,21 +236,17 @@ nir_opt_peephole_select_impl(nir_function_impl *impl)
 
    nir_foreach_block(impl, nir_opt_peephole_select_block, &state);
 
-   if (state.progress)
-      nir_metadata_preserve(impl, nir_metadata_none);
-
    return state.progress;
 }
 
+static const nir_pass nir_opt_peephole_select_pass = {
+   NULL, /* shader_pass_func */
+   nir_opt_peephole_select_impl,
+   nir_metadata_none,
+};
+
 bool
 nir_opt_peephole_select(nir_shader *shader)
 {
-   bool progress = false;
-
-   nir_foreach_overload(shader, overload) {
-      if (overload->impl)
-         progress |= nir_opt_peephole_select_impl(overload->impl);
-   }
-
-   return progress;
+   return nir_shader_run_pass(shader, &nir_opt_peephole_select_pass);
 }
diff --git a/src/glsl/nir/nir_opt_remove_phis.c b/src/glsl/nir/nir_opt_remove_phis.c
index 5bdf7ef..ec061c6 100644
--- a/src/glsl/nir/nir_opt_remove_phis.c
+++ b/src/glsl/nir/nir_opt_remove_phis.c
@@ -102,7 +102,7 @@ remove_phis_block(nir_block *block, void *state)
 }
 
 static bool
-remove_phis_impl(nir_function_impl *impl)
+remove_phis_impl(nir_function_impl *impl, void *unused)
 {
    bool progress = false;
 
@@ -111,15 +111,15 @@ remove_phis_impl(nir_function_impl *impl)
    return progress;
 }
 
+static const nir_pass nir_opt_remove_phis_pass = {
+   NULL, /* shader_pass_func */
+   remove_phis_impl,
+   nir_metadata_block_index | nir_metadata_dominance,
+};
+
 bool
 nir_opt_remove_phis(nir_shader *shader)
 {
-   bool progress = false;
-
-   nir_foreach_overload(shader, overload)
-      if (overload->impl)
-         progress = remove_phis_impl(overload->impl) || progress;
-
-   return progress;
+   return nir_shader_run_pass(shader, &nir_opt_remove_phis_pass);
 }
 
diff --git a/src/glsl/nir/nir_opt_undef.c b/src/glsl/nir/nir_opt_undef.c
index 4ab27a8..27c3c7d 100644
--- a/src/glsl/nir/nir_opt_undef.c
+++ b/src/glsl/nir/nir_opt_undef.c
@@ -85,20 +85,24 @@ opt_undef_block(nir_block *block, void *data)
    return true;
 }
 
-bool
-nir_opt_undef(nir_shader *shader)
+static bool
+opt_undef_impl(nir_function_impl *impl, void *unused)
 {
    bool progress = false;
 
-   nir_foreach_overload(shader, overload) {
-      if (overload->impl) {
-         nir_foreach_block(overload->impl, opt_undef_block, &progress);
-         if (progress)
-            nir_metadata_preserve(overload->impl,
-                                  nir_metadata_block_index |
-                                  nir_metadata_dominance);
-      }
-   }
+   nir_foreach_block(impl, opt_undef_block, &progress);
 
    return progress;
 }
+
+static const nir_pass nir_opt_undef_pass = {
+   NULL, /* shader_pass_func */
+   opt_undef_impl,
+   nir_metadata_block_index | nir_metadata_dominance,
+};
+
+bool
+nir_opt_undef(nir_shader *shader)
+{
+   return nir_shader_run_pass(shader, &nir_opt_undef_pass);
+}
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list