From: Jason Ekstrand Date: Fri, 29 Jun 2018 02:46:01 +0000 (-0700) Subject: nir: Add a deref_instr_has_indirect helper X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=893fc2d07d382c0b9563c0b48215a0e260f17d4b;p=mesa.git nir: Add a deref_instr_has_indirect helper Reviewed-by: Timothy Arceri Reviewed-by: Iago Toral Quiroga Reviewed-by: Kenneth Graunke --- diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index c16ce547642..e35bef612df 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 1a00157c2fc..22ecde4ecca 100644 --- a/src/compiler/nir/nir_deref.c +++ b/src/compiler/nir/nir_deref.c @@ -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) {