[Mesa-dev] [PATCH v3 023/104] nir/deref: Add a deref cleanup function
Jason Ekstrand
jason at jlekstrand.net
Tue Apr 3 18:32:50 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 5fa32fa..df7002b 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -1025,6 +1025,8 @@ nir_deref_instr_get_variable(const 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 3546013..5add79c 100644
--- a/src/compiler/nir/nir_deref.c
+++ b/src/compiler/nir/nir_deref.c
@@ -73,6 +73,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