[Mesa-dev] [RFC v1 27/38] nir/deref: Add a deref cleanup function
Jason Ekstrand
jason at jlekstrand.net
Wed Mar 21 05:55:01 UTC 2018
Sometimes it's useful for a pass to be able to clean up its own derefs
instead of waiting for DCE. This little helper makes it very easy.
---
src/compiler/nir/nir.h | 2 ++
src/compiler/nir/nir_deref.c | 13 +++++++++++++
2 files changed, 15 insertions(+)
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 496b123..b99dd9b 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -1018,6 +1018,8 @@ nir_deref_instr_get_variable(nir_deref_instr *instr)
return instr->var;
}
+void nir_deref_instr_cleanup(nir_deref_instr *instr);
+
nir_deref_var *
nir_deref_instr_to_deref(nir_deref_instr *instr, void *mem_ctx);
diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c
index bf39a12..de45358 100644
--- a/src/compiler/nir/nir_deref.c
+++ b/src/compiler/nir/nir_deref.c
@@ -72,6 +72,19 @@ nir_deref_path_finish(struct nir_deref_path *path)
ralloc_free(path->path);
}
+void
+nir_deref_instr_cleanup(nir_deref_instr *instr)
+{
+ for (nir_deref_instr *d = instr; d; d = nir_deref_instr_parent(d)) {
+ /* If anyone is using this deref, leave it alone */
+ assert(d->dest.is_ssa);
+ if (!list_empty(&d->dest.ssa.uses))
+ return;
+
+ nir_instr_remove(&d->instr);
+ }
+}
+
nir_deref_var *
nir_deref_instr_to_deref(nir_deref_instr *instr, void *mem_ctx)
{
--
2.5.0.400.gff86faf
More information about the mesa-dev
mailing list