[Mesa-dev] [PATCH v2 07/10] nir: Use the nir_pass framework internally for copy_prop, dce, and cse
Jason Ekstrand
jason at jlekstrand.net
Tue Nov 3 13:41:13 PST 2015
Reviewed-by: Kristian Høgsberg <krh at bitplanet.net>
---
.../drivers/freedreno/ir3/ir3_compiler_nir.c | 2 +-
src/gallium/drivers/vc4/vc4_program.c | 2 +-
src/glsl/nir/nir.h | 9 +++------
src/glsl/nir/nir_opt_copy_propagate.c | 18 +++++------------
src/glsl/nir/nir_opt_cse.c | 23 +++++-----------------
src/glsl/nir/nir_opt_dce.c | 21 +++++---------------
src/mesa/drivers/dri/i965/brw_nir.c | 6 +++---
7 files changed, 23 insertions(+), 58 deletions(-)
diff --git a/src/gallium/drivers/freedreno/ir3/ir3_compiler_nir.c b/src/gallium/drivers/freedreno/ir3/ir3_compiler_nir.c
index 8c9234b..1f07e49 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3_compiler_nir.c
+++ b/src/gallium/drivers/freedreno/ir3/ir3_compiler_nir.c
@@ -192,7 +192,7 @@ static struct nir_shader *to_nir(struct ir3_compile *ctx,
nir_lower_alu_to_scalar(s);
nir_lower_phis_to_scalar(s);
- progress |= nir_copy_prop(s);
+ progress |= nir_opt_copy_prop(s);
progress |= nir_opt_dce(s);
progress |= nir_opt_cse(s);
progress |= ir3_nir_lower_if_else(s);
diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c
index a48dad8..cffc06e 100644
--- a/src/gallium/drivers/vc4/vc4_program.c
+++ b/src/gallium/drivers/vc4/vc4_program.c
@@ -1264,7 +1264,7 @@ vc4_optimize_nir(struct nir_shader *s)
nir_lower_vars_to_ssa(s);
nir_lower_alu_to_scalar(s);
- progress = nir_copy_prop(s) || progress;
+ progress = nir_opt_copy_prop(s) || progress;
progress = nir_opt_dce(s) || progress;
progress = nir_opt_cse(s) || progress;
progress = nir_opt_peephole_select(s) || progress;
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index 517b7f8..5242112 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1602,6 +1602,9 @@ 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_copy_prop)
+NIR_DECL_PASS(nir_opt_cse)
+NIR_DECL_PASS(nir_opt_dce)
nir_shader *nir_shader_create(void *mem_ctx,
gl_shader_stage stage,
@@ -2021,12 +2024,6 @@ bool nir_opt_constant_folding(nir_shader *shader);
bool nir_opt_global_to_local(nir_shader *shader);
-bool nir_copy_prop(nir_shader *shader);
-
-bool nir_opt_cse(nir_shader *shader);
-
-bool nir_opt_dce(nir_shader *shader);
-
bool nir_opt_dead_cf(nir_shader *shader);
void nir_opt_gcm(nir_shader *shader);
diff --git a/src/glsl/nir/nir_opt_copy_propagate.c b/src/glsl/nir/nir_opt_copy_propagate.c
index 96520f8..07d30de 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,7 @@ nir_copy_prop_impl(nir_function_impl *impl)
return progress;
}
-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;
-}
+const nir_pass nir_opt_copy_prop_pass = {
+ .impl_pass_func = nir_copy_prop_impl,
+ .metadata_preserved = nir_metadata_block_index | nir_metadata_dominance,
+};
diff --git a/src/glsl/nir/nir_opt_cse.c b/src/glsl/nir/nir_opt_cse.c
index 93a6635..6804aa4 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,11 @@ 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;
}
-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;
-}
-
+const nir_pass nir_opt_cse_pass = {
+ .impl_pass_func = nir_opt_cse_impl,
+ .metadata_preserved = nir_metadata_block_index | nir_metadata_dominance,
+};
diff --git a/src/glsl/nir/nir_opt_dce.c b/src/glsl/nir/nir_opt_dce.c
index 6032528..0f184a5 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,10 @@ 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;
}
-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;
-}
+const nir_pass nir_opt_dce_pass = {
+ .impl_pass_func = nir_opt_dce_impl,
+ .metadata_preserved = nir_metadata_block_index | nir_metadata_dominance,
+};
diff --git a/src/mesa/drivers/dri/i965/brw_nir.c b/src/mesa/drivers/dri/i965/brw_nir.c
index 11f1113..01e7622 100644
--- a/src/mesa/drivers/dri/i965/brw_nir.c
+++ b/src/mesa/drivers/dri/i965/brw_nir.c
@@ -150,7 +150,7 @@ nir_optimize(nir_shader *nir, bool is_scalar)
nir_validate_shader(nir);
}
- progress |= nir_copy_prop(nir);
+ progress |= nir_opt_copy_prop(nir);
nir_validate_shader(nir);
if (is_scalar) {
@@ -158,7 +158,7 @@ nir_optimize(nir_shader *nir, bool is_scalar)
nir_validate_shader(nir);
}
- progress |= nir_copy_prop(nir);
+ progress |= nir_opt_copy_prop(nir);
nir_validate_shader(nir);
progress |= nir_opt_dce(nir);
nir_validate_shader(nir);
@@ -270,7 +270,7 @@ brw_create_nir(struct brw_context *brw,
nir_lower_to_source_mods(nir);
nir_validate_shader(nir);
- nir_copy_prop(nir);
+ nir_opt_copy_prop(nir);
nir_validate_shader(nir);
nir_opt_dce(nir);
nir_validate_shader(nir);
--
2.5.0.400.gff86faf
More information about the mesa-dev
mailing list