From: Jason Ekstrand Date: Thu, 11 Jul 2019 20:05:27 +0000 (-0500) Subject: nir: Add a helper for fetching the SSA def from an instruction X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c74b98486a17f85e792ff6d540569264ad359f45;p=mesa.git nir: Add a helper for fetching the SSA def from an instruction Reviewed-by: Eric Anholt --- diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index c7413aa64b0..9c252a49137 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -1041,6 +1041,53 @@ nir_foreach_ssa_def(nir_instr *instr, nir_foreach_ssa_def_cb cb, void *state) } } +nir_ssa_def * +nir_instr_ssa_def(nir_instr *instr) +{ + switch (instr->type) { + case nir_instr_type_alu: + assert(nir_instr_as_alu(instr)->dest.dest.is_ssa); + return &nir_instr_as_alu(instr)->dest.dest.ssa; + + case nir_instr_type_deref: + assert(nir_instr_as_deref(instr)->dest.is_ssa); + return &nir_instr_as_deref(instr)->dest.ssa; + + case nir_instr_type_tex: + assert(nir_instr_as_tex(instr)->dest.is_ssa); + return &nir_instr_as_tex(instr)->dest.ssa; + + case nir_instr_type_intrinsic: { + nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr); + if (nir_intrinsic_infos[intrin->intrinsic].has_dest) { + assert(intrin->dest.is_ssa); + return &intrin->dest.ssa; + } else { + return NULL; + } + } + + case nir_instr_type_phi: + assert(nir_instr_as_phi(instr)->dest.is_ssa); + return &nir_instr_as_phi(instr)->dest.ssa; + + case nir_instr_type_parallel_copy: + unreachable("Parallel copies are unsupported by this function"); + + case nir_instr_type_load_const: + return &nir_instr_as_load_const(instr)->def; + + case nir_instr_type_ssa_undef: + return &nir_instr_as_ssa_undef(instr)->def; + + case nir_instr_type_call: + case nir_instr_type_jump: + return NULL; + } + + unreachable("Invalid instruction type"); +} + static bool visit_src(nir_src *src, nir_foreach_src_cb cb, void *state) { diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index c7a1bf357c8..31121515266 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -3042,6 +3042,8 @@ nir_instr_remove(nir_instr *instr) /** @} */ +nir_ssa_def *nir_instr_ssa_def(nir_instr *instr); + typedef bool (*nir_foreach_ssa_def_cb)(nir_ssa_def *def, void *state); typedef bool (*nir_foreach_dest_cb)(nir_dest *dest, void *state); typedef bool (*nir_foreach_src_cb)(nir_src *src, void *state);