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 e0c46e7..018592a 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -1019,6 +1019,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 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 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev