diff options
author | Jason Ekstrand <[email protected]> | 2018-03-14 21:45:38 -0700 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2018-06-22 20:15:53 -0700 |
commit | 19a4662a540a8c940310a75f19bc8cd75be651e0 (patch) | |
tree | be24fd16f6a4b55529b015442f709971938d44a8 /src/compiler/nir/nir_clone.c | |
parent | 5fbbbda37a09e6d253532fd83097b21cd289c16b (diff) |
nir: Add a deref instruction type
This commit adds a new instruction type to NIR for handling derefs.
Nothing uses it yet but this adds the data structure as well as all of
the code to validate, print, clone, and [de]serialize them.
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_clone.c')
-rw-r--r-- | src/compiler/nir/nir_clone.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c index bcfdaa75942..20eaaff3bee 100644 --- a/src/compiler/nir/nir_clone.c +++ b/src/compiler/nir/nir_clone.c @@ -346,6 +346,46 @@ clone_alu(clone_state *state, const nir_alu_instr *alu) return nalu; } +static nir_deref_instr * +clone_deref_instr(clone_state *state, const nir_deref_instr *deref) +{ + nir_deref_instr *nderef = + nir_deref_instr_create(state->ns, deref->deref_type); + + __clone_dst(state, &nderef->instr, &nderef->dest, &deref->dest); + + nderef->mode = deref->mode; + nderef->type = deref->type; + + if (deref->deref_type == nir_deref_type_var) { + nderef->var = remap_var(state, deref->var); + return nderef; + } + + __clone_src(state, &nderef->instr, &nderef->parent, &deref->parent); + + switch (deref->deref_type) { + case nir_deref_type_struct: + nderef->strct.index = deref->strct.index; + break; + + case nir_deref_type_array: + __clone_src(state, &nderef->instr, + &nderef->arr.index, &deref->arr.index); + break; + + case nir_deref_type_array_wildcard: + case nir_deref_type_cast: + /* Nothing to do */ + break; + + default: + unreachable("Invalid instruction deref type"); + } + + return nderef; +} + static nir_intrinsic_instr * clone_intrinsic(clone_state *state, const nir_intrinsic_instr *itr) { @@ -502,6 +542,8 @@ clone_instr(clone_state *state, const nir_instr *instr) switch (instr->type) { case nir_instr_type_alu: return &clone_alu(state, nir_instr_as_alu(instr))->instr; + case nir_instr_type_deref: + return &clone_deref_instr(state, nir_instr_as_deref(instr))->instr; case nir_instr_type_intrinsic: return &clone_intrinsic(state, nir_instr_as_intrinsic(instr))->instr; case nir_instr_type_load_const: |