[Mesa-dev] [PATCH 07/11] nir: Use the nir_pass framework internally for copy_prop, dce, and cse
Jason Ekstrand
jason at jlekstrand.net
Wed Oct 28 14:32:07 PDT 2015
---
src/glsl/nir/nir_opt_copy_propagate.c | 17 ++++++++---------
src/glsl/nir/nir_opt_cse.c | 21 ++++++++-------------
src/glsl/nir/nir_opt_dce.c | 20 ++++++++------------
3 files changed, 24 insertions(+), 34 deletions(-)
diff --git a/src/glsl/nir/nir_opt_copy_propagate.c b/src/glsl/nir/nir_opt_copy_propagate.c
index 96520f8..7ee86d4 100644
--- a/src/glsl/nir/nir_opt_copy_propagate.c
+++ b/src/glsl/nir/nir_opt_copy_propagate.c
@@ -257,7 +257,7 @@ copy_prop_block(nir_block *block, void *_state)
}
static bool
-nir_copy_prop_impl(nir_function_impl *impl)
+nir_copy_prop_impl(nir_function_impl *impl, void *unused)
{
bool progress = false;
@@ -265,15 +265,14 @@ nir_copy_prop_impl(nir_function_impl *impl)
return progress;
}
+static const nir_pass nir_opt_copy_prop_pass = {
+ NULL, /* shader_pass_func */
+ nir_copy_prop_impl,
+ nir_metadata_block_index | nir_metadata_dominance,
+};
+
bool
nir_copy_prop(nir_shader *shader)
{
- bool progress = false;
-
- nir_foreach_overload(shader, overload) {
- if (overload->impl && nir_copy_prop_impl(overload->impl))
- progress = true;
- }
-
- return progress;
+ return nir_shader_run_pass(shader, &nir_opt_copy_prop_pass);
}
diff --git a/src/glsl/nir/nir_opt_cse.c b/src/glsl/nir/nir_opt_cse.c
index 93a6635..453aa38 100644
--- a/src/glsl/nir/nir_opt_cse.c
+++ b/src/glsl/nir/nir_opt_cse.c
@@ -62,7 +62,7 @@ cse_block(nir_block *block, struct set *instr_set)
}
static bool
-nir_opt_cse_impl(nir_function_impl *impl)
+nir_opt_cse_impl(nir_function_impl *impl, void *unused)
{
struct set *instr_set = nir_instr_set_create(NULL);
@@ -70,24 +70,19 @@ nir_opt_cse_impl(nir_function_impl *impl)
bool progress = cse_block(nir_start_block(impl), instr_set);
- if (progress)
- nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
-
nir_instr_set_destroy(instr_set);
return progress;
}
+static const nir_pass nir_opt_cse_pass = {
+ NULL, /* shader_pass_func */
+ nir_opt_cse_impl,
+ nir_metadata_block_index | nir_metadata_dominance,
+};
+
bool
nir_opt_cse(nir_shader *shader)
{
- bool progress = false;
-
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- progress |= nir_opt_cse_impl(overload->impl);
- }
-
- return progress;
+ return nir_shader_run_pass(shader, &nir_opt_cse_pass);
}
diff --git a/src/glsl/nir/nir_opt_dce.c b/src/glsl/nir/nir_opt_dce.c
index 6032528..9d133cd 100644
--- a/src/glsl/nir/nir_opt_dce.c
+++ b/src/glsl/nir/nir_opt_dce.c
@@ -146,7 +146,7 @@ delete_block_cb(nir_block *block, void *_state)
}
static bool
-nir_opt_dce_impl(nir_function_impl *impl)
+nir_opt_dce_impl(nir_function_impl *impl, void *unused)
{
struct exec_list *worklist = ralloc(NULL, struct exec_list);
exec_list_make_empty(worklist);
@@ -163,21 +163,17 @@ nir_opt_dce_impl(nir_function_impl *impl)
bool progress = false;
nir_foreach_block(impl, delete_block_cb, &progress);
- if (progress)
- nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
-
return progress;
}
+static const nir_pass nir_opt_dce_pass = {
+ NULL, /* shader_pass_func */
+ nir_opt_dce_impl,
+ nir_metadata_block_index | nir_metadata_dominance,
+};
+
bool
nir_opt_dce(nir_shader *shader)
{
- bool progress = false;
- nir_foreach_overload(shader, overload) {
- if (overload->impl && nir_opt_dce_impl(overload->impl))
- progress = true;
- }
-
- return progress;
+ return nir_shader_run_pass(shader, &nir_opt_dce_pass);
}
--
2.5.0.400.gff86faf
More information about the mesa-dev
mailing list