summaryrefslogtreecommitdiffstats
path: root/src/glsl/nir/nir.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2015-09-09 15:58:25 -0700
committerJason Ekstrand <[email protected]>2015-09-11 09:21:20 -0700
commitcee29220e312f7c76a07343e501fa6a1c5f3d1aa (patch)
treeb0dc2a6285a7fe0556e42c9d7e7ffe08421d53d2 /src/glsl/nir/nir.c
parent106a3b2cc33c53ab16ffedc51248b04dd995dc17 (diff)
nir: Add a function for rewriting instruction destinations
Reviewed-by: Eduardo Lima Mitev <[email protected]>
Diffstat (limited to 'src/glsl/nir/nir.c')
-rw-r--r--src/glsl/nir/nir.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
index 4a88cd1837c..aafcb939e3a 100644
--- a/src/glsl/nir/nir.c
+++ b/src/glsl/nir/nir.c
@@ -1178,6 +1178,30 @@ nir_if_rewrite_condition(nir_if *if_stmt, nir_src new_src)
}
void
+nir_instr_rewrite_dest(nir_instr *instr, nir_dest *dest, nir_dest new_dest)
+{
+ if (dest->is_ssa) {
+ /* We can only overwrite an SSA destination if it has no uses. */
+ assert(list_empty(&dest->ssa.uses) && list_empty(&dest->ssa.if_uses));
+ } else {
+ list_del(&dest->reg.def_link);
+ if (dest->reg.indirect)
+ src_remove_all_uses(dest->reg.indirect);
+ }
+
+ /* We can't re-write with an SSA def */
+ assert(!new_dest.is_ssa);
+
+ nir_dest_copy(dest, &new_dest, instr);
+
+ dest->reg.parent_instr = instr;
+ list_addtail(&dest->reg.def_link, &new_dest.reg.reg->defs);
+
+ if (dest->reg.indirect)
+ src_add_all_uses(dest->reg.indirect, instr, NULL);
+}
+
+void
nir_ssa_def_init(nir_instr *instr, nir_ssa_def *def,
unsigned num_components, const char *name)
{