summaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_builder.h
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2018-03-16 01:15:47 -0700
committerJason Ekstrand <[email protected]>2018-06-22 20:15:53 -0700
commita80fa2766ec1e3e6575d06254e42da5868f43885 (patch)
treeca670e685a0468973d2f677597974f533cc86331 /src/compiler/nir/nir_builder.h
parent5286b5d832b82c7886c14328c3853eaa002bae99 (diff)
nir: Add helpers for working with deref instructions
This commit adds a pass for lowering deref instructions to deref chains as well as some smaller helpers to ease the transition. Reviewed-by: Caio Marcelo de Oliveira Filho <[email protected]> Acked-by: Rob Clark <[email protected]> Acked-by: Bas Nieuwenhuizen <[email protected]> Acked-by: Dave Airlie <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_builder.h')
-rw-r--r--src/compiler/nir/nir_builder.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index a667372bd7a..42fe285506e 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -644,6 +644,29 @@ nir_build_deref_cast(nir_builder *build, nir_ssa_def *parent,
return deref;
}
+static inline nir_deref_instr *
+nir_build_deref_for_chain(nir_builder *b, nir_deref_var *deref_var)
+{
+ nir_deref_instr *tail = nir_build_deref_var(b, deref_var->var);
+ for (nir_deref *d = deref_var->deref.child; d; d = d->child) {
+ if (d->deref_type == nir_deref_type_array) {
+ nir_deref_array *a = nir_deref_as_array(d);
+ assert(a->deref_array_type != nir_deref_array_type_wildcard);
+
+ nir_ssa_def *index = nir_imm_int(b, a->base_offset);
+ if (a->deref_array_type == nir_deref_array_type_indirect)
+ index = nir_iadd(b, index, nir_ssa_for_src(b, a->indirect, 1));
+
+ tail = nir_build_deref_array(b, tail, index);
+ } else {
+ nir_deref_struct *s = nir_deref_as_struct(d);
+ tail = nir_build_deref_struct(b, tail, s->index);
+ }
+ }
+
+ return tail;
+}
+
static inline nir_ssa_def *
nir_load_reg(nir_builder *build, nir_register *reg)
{