[Mesa-dev] [PATCH v2 09/10] nir: Use the nir_pass framework internally for more passes
Jason Ekstrand
jason at jlekstrand.net
Tue Nov 3 13:41:15 PST 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
Reviewed-by: Kristian Høgsberg <krh at bitplanet.net>
---
src/glsl/nir/nir.h | 14 +++++---------
src/glsl/nir/nir_opt_constant_folding.c | 22 +++++-----------------
src/glsl/nir/nir_opt_dead_cf.c | 24 ++++++------------------
src/glsl/nir/nir_opt_peephole_select.c | 21 +++++----------------
src/glsl/nir/nir_opt_remove_phis.c | 18 +++++-------------
src/glsl/nir/nir_opt_undef.c | 19 ++++++++-----------
6 files changed, 34 insertions(+), 84 deletions(-)
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index beca805..3140df8 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1604,9 +1604,14 @@ 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_constant_folding)
NIR_DECL_PASS(nir_opt_copy_prop)
NIR_DECL_PASS(nir_opt_cse)
NIR_DECL_PASS(nir_opt_dce)
+NIR_DECL_PASS(nir_opt_dead_cf)
+NIR_DECL_PASS(nir_opt_peephole_select)
+NIR_DECL_PASS(nir_opt_remove_phis)
+NIR_DECL_PASS(nir_opt_undef)
nir_shader *nir_shader_create(void *mem_ctx,
gl_shader_stage stage,
@@ -2020,21 +2025,12 @@ void nir_convert_to_ssa(nir_shader *shader);
*/
void nir_convert_from_ssa(nir_shader *shader, bool phi_webs_only);
-bool nir_opt_constant_folding(nir_shader *shader);
-
bool nir_opt_global_to_local(nir_shader *shader);
-bool nir_opt_dead_cf(nir_shader *shader);
-
void nir_opt_gcm(nir_shader *shader);
-bool nir_opt_peephole_select(nir_shader *shader);
bool nir_opt_peephole_ffma(nir_shader *shader);
-bool nir_opt_remove_phis(nir_shader *shader);
-
-bool nir_opt_undef(nir_shader *shader);
-
void nir_sweep(nir_shader *shader);
nir_intrinsic_op nir_intrinsic_from_system_value(gl_system_value val);
diff --git a/src/glsl/nir/nir_opt_constant_folding.c b/src/glsl/nir/nir_opt_constant_folding.c
index 007b81c..40c1cbe 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,10 @@ 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;
}
-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;
-}
+const nir_pass nir_opt_constant_folding_pass = {
+ .impl_pass_func = nir_opt_constant_folding_impl,
+ .metadata_preserved = nir_metadata_block_index | nir_metadata_dominance,
+};
diff --git a/src/glsl/nir/nir_opt_dead_cf.c b/src/glsl/nir/nir_opt_dead_cf.c
index 0d4819b..6f6bda4 100644
--- a/src/glsl/nir/nir_opt_dead_cf.c
+++ b/src/glsl/nir/nir_opt_dead_cf.c
@@ -334,25 +334,13 @@ 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);
}
-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;
-}
+const nir_pass nir_opt_dead_cf_pass = {
+ .impl_pass_func = opt_dead_cf_impl,
+ .metadata_preserved = nir_metadata_none,
+};
diff --git a/src/glsl/nir/nir_opt_peephole_select.c b/src/glsl/nir/nir_opt_peephole_select.c
index 90902b9..47f083e 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,10 @@ 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;
}
-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;
-}
+const nir_pass nir_opt_peephole_select_pass = {
+ .impl_pass_func = nir_opt_peephole_select_impl,
+ .metadata_preserved = nir_metadata_none,
+};
diff --git a/src/glsl/nir/nir_opt_remove_phis.c b/src/glsl/nir/nir_opt_remove_phis.c
index 5bdf7ef..8fb0a80 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,7 @@ remove_phis_impl(nir_function_impl *impl)
return progress;
}
-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;
-}
-
+const nir_pass nir_opt_remove_phis_pass = {
+ .impl_pass_func = remove_phis_impl,
+ .metadata_preserved = nir_metadata_block_index | nir_metadata_dominance,
+};
diff --git a/src/glsl/nir/nir_opt_undef.c b/src/glsl/nir/nir_opt_undef.c
index 4ab27a8..c2a0b79 100644
--- a/src/glsl/nir/nir_opt_undef.c
+++ b/src/glsl/nir/nir_opt_undef.c
@@ -85,20 +85,17 @@ 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;
}
+
+const nir_pass nir_opt_undef_pass = {
+ .impl_pass_func = opt_undef_impl,
+ .metadata_preserved = nir_metadata_block_index | nir_metadata_dominance,
+};
--
2.5.0.400.gff86faf
More information about the mesa-dev
mailing list