pan/bi: Add and use bi_replace_src helper
authorAlyssa Rosenzweig <alyssa@collabora.com>
Tue, 26 Jul 2022 17:35:34 +0000 (13:35 -0400)
committerMarge Bot <emma+marge@anholt.net>
Fri, 2 Sep 2022 16:03:24 +0000 (16:03 +0000)
This is a common pattern. Make it more ergonomic. With the help of Coccinelle:

   @@
   expression E;
   expression R;
   expression instruction;
   @@

   -instruction->src[E] = bi_replace_index(instruction->src[E], R);
   +bi_replace_src(instruction, E, R);

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17794>

src/panfrost/bifrost/bi_lower_swizzle.c
src/panfrost/bifrost/bi_opt_copy_prop.c
src/panfrost/bifrost/bi_opt_cse.c
src/panfrost/bifrost/bi_ra.c
src/panfrost/bifrost/bi_schedule.c
src/panfrost/bifrost/compiler.h
src/panfrost/bifrost/valhall/va_validate.c

index 8e372fa..e159827 100644 (file)
@@ -132,8 +132,7 @@ bi_lower_swizzle_16(bi_context *ctx, bi_instr *ins, unsigned src)
 
         /* Lower it away */
         bi_builder b = bi_init_builder(ctx, bi_before_instr(ins));
-        ins->src[src] = bi_replace_index(ins->src[src],
-                        bi_swz_v2i16(&b, ins->src[src]));
+        bi_replace_src(ins, src, bi_swz_v2i16(&b, ins->src[src]));
         ins->src[src].swizzle = BI_SWIZZLE_H01;
 }
 
index adbac98..13b9b0d 100644 (file)
@@ -105,7 +105,7 @@ bi_opt_copy_prop(bi_context *ctx)
                                 continue;
 
                         if (!bi_is_null(repl))
-                                ins->src[s] = bi_replace_index(ins->src[s], repl);
+                                bi_replace_src(ins, s, repl);
                 }
         }
 
index 9e822ef..5b4f402 100644 (file)
@@ -160,7 +160,7 @@ bi_opt_cse(bi_context *ctx)
 
                                 bi_index repl = replacement[instr->src[s].value];
                                 if (!bi_is_null(repl))
-                                        instr->src[s] = bi_replace_index(instr->src[s], repl);
+                                        bi_replace_src(instr, s, repl);
                         }
 
                         if (!instr_can_cse(instr))
index 4d9fbf6..5a439e9 100644 (file)
@@ -808,7 +808,7 @@ bi_lower_vector(bi_context *ctx, unsigned first_reg)
         bi_foreach_instr_global(ctx, I) {
                 bi_foreach_ssa_src(I, s) {
                         if (I->src[s].value < first_reg && !bi_is_null(remap[I->src[s].value]))
-                                I->src[s] = bi_replace_index(I->src[s], remap[I->src[s].value]);
+                                bi_replace_src(I, s, remap[I->src[s].value]);
                 }
         }
 
@@ -887,7 +887,7 @@ bi_coalesce_tied(bi_context *ctx)
                         bi_mov_i32_to(&b, dst, src);
                 }
 
-                I->src[0] = bi_replace_index(I->src[0], I->dest[0]);
+                bi_replace_src(I, 0, I->dest[0]);
         }
 }
 
@@ -977,7 +977,7 @@ bi_out_of_ssa(bi_context *ctx)
 
                                 bi_foreach_src(prop, s) {
                                         if (bi_is_equiv(prop->src[s], I->dest[0])) {
-                                                prop->src[s] = bi_replace_index(prop->src[s], reg);
+                                                bi_replace_src(prop, s, reg);
                                         }
                                 }
                         }
index 5df05ee..877d57a 100644 (file)
@@ -1386,7 +1386,7 @@ bi_rewrite_fau_to_pass(bi_tuple *tuple)
                 bi_index pass = bi_passthrough(ins->src[s].offset ?
                                 BIFROST_SRC_FAU_HI : BIFROST_SRC_FAU_LO);
 
-                ins->src[s] = bi_replace_index(ins->src[s], pass);
+                bi_replace_src(ins, s, pass);
         }
 }
 
@@ -1399,7 +1399,7 @@ bi_rewrite_zero(bi_instr *ins, bool fma)
                 bi_index src = ins->src[s];
 
                 if (src.type == BI_INDEX_CONSTANT && src.value == 0)
-                        ins->src[s] = bi_replace_index(src, zero);
+                        bi_replace_src(ins, s, zero);
         }
 }
 
@@ -1430,9 +1430,8 @@ bi_rewrite_constants_to_pass(bi_tuple *tuple, uint64_t constant, bool pcrel)
 
                 assert(lo || hi);
 
-                ins->src[s] = bi_replace_index(ins->src[s],
-                                bi_passthrough(hi ?  BIFROST_SRC_FAU_HI :
-                                        BIFROST_SRC_FAU_LO));
+                bi_replace_src(ins, s,
+                               bi_passthrough(hi ? BIFROST_SRC_FAU_HI : BIFROST_SRC_FAU_LO));
         }
 }
 
@@ -2062,7 +2061,7 @@ bi_lower_fau(bi_context *ctx)
                         if (bi_check_fau_src(ins, s, constants, &cwords, &fau)) continue;
 
                         bi_index copy = bi_mov_i32(&b, ins->src[s]);
-                        ins->src[s] = bi_replace_index(ins->src[s], copy);
+                        bi_replace_src(ins, s, copy);
                 }
         }
 }
index 64b777f..b8a462c 100644 (file)
@@ -574,6 +574,12 @@ bi_drop_srcs(bi_instr *I, unsigned new_count)
         I->nr_srcs = new_count;
 }
 
+static inline void
+bi_replace_src(bi_instr *I, unsigned src_index, bi_index replacement)
+{
+        I->src[src_index] = bi_replace_index(I->src[src_index], replacement);
+}
+
 /* Represents the assignment of slots for a given bi_tuple */
 
 typedef struct {
index e404d74..847a92a 100644 (file)
@@ -135,8 +135,7 @@ va_repair_fau(bi_builder *b, bi_instr *I)
       bi_index src = I->src[s];
 
       if (!valid_src(&fau, fau_page, src)) {
-         bi_index copy = bi_mov_i32(b, bi_strip_index(src));
-         I->src[s] = bi_replace_index(src, copy);
+         bi_replace_src(I, s, bi_mov_i32(b, bi_strip_index(src)));
 
          /* Rollback update. Since the replacement move doesn't affect FAU
           * state, there is no need to call valid_src again.