Mesa (master): nir: Add a deref_instr_has_indirect helper

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jul 2 20:06:29 UTC 2018


Module: Mesa
Branch: master
Commit: 893fc2d07d382c0b9563c0b48215a0e260f17d4b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=893fc2d07d382c0b9563c0b48215a0e260f17d4b

Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date:   Thu Jun 28 19:46:01 2018 -0700

nir: Add a deref_instr_has_indirect helper

Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
Reviewed-by: Iago Toral Quiroga <itoral at igalia.com>
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/compiler/nir/nir.h       |  2 ++
 src/compiler/nir/nir_deref.c | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index c16ce54764..e35bef612d 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -987,6 +987,8 @@ nir_deref_instr_get_variable(const nir_deref_instr *instr)
    return instr->var;
 }
 
+bool nir_deref_instr_has_indirect(nir_deref_instr *instr);
+
 bool nir_deref_instr_remove_if_unused(nir_deref_instr *instr);
 
 typedef struct {
diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c
index 1a00157c2f..22ecde4ecc 100644
--- a/src/compiler/nir/nir_deref.c
+++ b/src/compiler/nir/nir_deref.c
@@ -103,6 +103,24 @@ nir_deref_instr_remove_if_unused(nir_deref_instr *instr)
 }
 
 bool
+nir_deref_instr_has_indirect(nir_deref_instr *instr)
+{
+   while (instr->deref_type != nir_deref_type_var) {
+      /* Consider casts to be indirects */
+      if (instr->deref_type == nir_deref_type_cast)
+         return true;
+
+      if (instr->deref_type == nir_deref_type_array &&
+          !nir_src_as_const_value(instr->arr.index))
+         return true;
+
+      instr = nir_deref_instr_parent(instr);
+   }
+
+   return false;
+}
+
+bool
 nir_remove_dead_derefs_impl(nir_function_impl *impl)
 {
    bool progress = false;




More information about the mesa-commit mailing list