nir: Add a deref_instr_has_indirect helper
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 29 Jun 2018 02:46:01 +0000 (19:46 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Mon, 2 Jul 2018 19:09:37 +0000 (12:09 -0700)
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/compiler/nir/nir.h
src/compiler/nir/nir_deref.c

index c16ce547642b54c53a8b565b5fc7a8f017a9a9d2..e35bef612df8842fa86b88a433aa117850a30598 100644 (file)
@@ -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 {
index 1a00157c2fcd5ff300fdd526bbf168ef2162c867..22ecde4ecca9e8e2295537472bee744f7b1d97a8 100644 (file)
@@ -102,6 +102,24 @@ nir_deref_instr_remove_if_unused(nir_deref_instr *instr)
    return progress;
 }
 
+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)
 {