nir: Factor out nir_src_rewrite_ssa helper
authorAlyssa Rosenzweig <alyssa@collabora.com>
Thu, 6 Apr 2023 19:54:18 +0000 (15:54 -0400)
committerMarge Bot <emma+marge@anholt.net>
Fri, 7 Apr 2023 23:48:03 +0000 (23:48 +0000)
Like nir_instr_rewrite_ssa but without the asserted extra argument. Works on ifs
too, now that we have a unified use list.

We do need to assert that the source has actually been inserted and has valid
use/def chains. Previously, asserting on the parent instruction accomplished
that indirectly. For the more general helper, we instead directly assert that
there exists a non-null parent, whatever it is.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22343>

src/compiler/nir/nir.h

index 7064b42..d5d5e24 100644 (file)
@@ -4342,17 +4342,24 @@ bool nir_srcs_equal(nir_src src1, nir_src src2);
 bool nir_instrs_equal(const nir_instr *instr1, const nir_instr *instr2);
 
 static inline void
-nir_instr_rewrite_src_ssa(ASSERTED nir_instr *instr,
-                          nir_src *src, nir_ssa_def *new_ssa)
+nir_src_rewrite_ssa(nir_src *src, nir_ssa_def *new_ssa)
 {
-   assert(!src->is_if);
-   assert(src->parent_instr == instr);
    assert(src->is_ssa && src->ssa);
+   assert(src->is_if ? (src->parent_if != NULL) : (src->parent_instr != NULL));
    list_del(&src->use_link);
    src->ssa = new_ssa;
    list_addtail(&src->use_link, &new_ssa->uses);
 }
 
+static inline void
+nir_instr_rewrite_src_ssa(ASSERTED nir_instr *instr,
+                          nir_src *src, nir_ssa_def *new_ssa)
+{
+   assert(!src->is_if);
+   assert(src->parent_instr == instr);
+   nir_src_rewrite_ssa(src, new_ssa);
+}
+
 void nir_instr_rewrite_src(nir_instr *instr, nir_src *src, nir_src new_src);
 void nir_instr_move_src(nir_instr *dest_instr, nir_src *dest, nir_src *src);
 
@@ -4362,10 +4369,7 @@ nir_if_rewrite_condition_ssa(ASSERTED nir_if *if_stmt,
 {
    assert(src->is_if);
    assert(src->parent_if == if_stmt);
-   assert(src->is_ssa && src->ssa);
-   list_del(&src->use_link);
-   src->ssa = new_ssa;
-   list_addtail(&src->use_link, &new_ssa->uses);
+   nir_src_rewrite_ssa(src, new_ssa);
 }
 
 void nir_if_rewrite_condition(nir_if *if_stmt, nir_src new_src);