pan/bi: Use variable src/dest for collect/split
authorAlyssa Rosenzweig <alyssa@collabora.com>
Fri, 22 Jul 2022 15:40:17 +0000 (11:40 -0400)
committerMarge Bot <emma+marge@anholt.net>
Fri, 2 Sep 2022 16:03:23 +0000 (16:03 +0000)
This avoids the nr_srcs/nr_dests setting dance, and will allow the builder to
handle the required memory allocation when we switch to dynamic src/dest
allocation.

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

src/panfrost/bifrost/ISA.xml
src/panfrost/bifrost/bi_opt_message_preload.c
src/panfrost/bifrost/bi_opt_push_ubo.c
src/panfrost/bifrost/bifrost_compile.c
src/panfrost/bifrost/test/test-message-preload.cpp
src/panfrost/bifrost/test/test-optimizer.cpp
src/panfrost/bifrost/valhall/va_lower_split_64bit.c

index 972c6eb..fd659e1 100644 (file)
     </mod>
   </ins>
 
-  <ins name="+COLLECT.i32" pseudo="true"/>
+  <ins name="+COLLECT.i32" pseudo="true" variable_srcs="true"/>
 
-  <ins name="+SPLIT.i32" pseudo="true">
+  <ins name="+SPLIT.i32" pseudo="true" variable_dests="true">
     <src start="0"/>
   </ins>
 
index c2d43a6..a1f4612 100644 (file)
@@ -129,8 +129,8 @@ bi_opt_message_preload(bi_context *ctx)
                  */
                 b.cursor = bi_before_instr(I);
 
-                bi_instr *collect = bi_collect_i32_to(&b, I->dest[0]);
-                collect->nr_srcs = bi_count_write_registers(I, 0);
+                unsigned nr = bi_count_write_registers(I, 0);
+                bi_instr *collect = bi_collect_i32_to(&b, I->dest[0], nr);
 
                 /* The registers themselves must be preloaded at the start of
                  * the program. Preloaded registers are coalesced, so these
index 5d38cd0..5a37bf3 100644 (file)
@@ -160,8 +160,8 @@ bi_opt_push_ubo(bi_context *ctx)
                 /* Replace the UBO load with moves from FAU */
                 bi_builder b = bi_init_builder(ctx, bi_after_instr(ins));
 
-                bi_instr *vec = bi_collect_i32_to(&b, ins->dest[0]);
-                vec->nr_srcs = bi_opcode_props[ins->op].sr_count;
+                unsigned nr = bi_opcode_props[ins->op].sr_count;
+                bi_instr *vec = bi_collect_i32_to(&b, ins->dest[0], nr);
 
                 bi_foreach_src(vec, w) {
                         /* FAU is grouped in pairs (2 x 4-byte) */
index dba542b..e05a892 100644 (file)
@@ -158,8 +158,7 @@ bi_extract(bi_builder *b, bi_index vec, unsigned channel)
          * Bypass the cache and emit an explicit split for registers.
          */
         if (vec.reg) {
-                bi_instr *I = bi_split_i32_to(b, bi_null(), vec);
-                I->nr_dests = channel + 1;
+                bi_instr *I = bi_split_i32_to(b, channel + 1, vec);
                 I->dest[channel] = bi_temp(b->shader);
                 return I->dest[channel];
         }
@@ -210,10 +209,9 @@ bi_emit_split_i32(bi_builder *b, bi_index dests[4], bi_index vec, unsigned n)
         if (n == 1) {
                 bi_mov_i32_to(b, dests[0], vec);
         } else {
-                bi_instr *I = bi_split_i32_to(b, dests[0], vec);
-                I->nr_dests = n;
+                bi_instr *I = bi_split_i32_to(b, n, vec);
 
-                for (unsigned j = 1; j < n; ++j)
+                bi_foreach_dest(I, j)
                         I->dest[j] = dests[j];
         }
 }
@@ -251,10 +249,9 @@ bi_emit_collect_to(bi_builder *b, bi_index dst, bi_index *chan, unsigned n)
         if (n == 1)
                 return bi_mov_i32_to(b, dst, chan[0]);
 
-        bi_instr *I = bi_collect_i32_to(b, dst);
-        I->nr_srcs = n;
+        bi_instr *I = bi_collect_i32_to(b, dst, n);
 
-        for (unsigned i = 0; i < n; ++i)
+        bi_foreach_src(I, i)
                 I->src[i] = chan[i];
 
         bi_cache_collect(b, dst, chan, n);
@@ -1050,10 +1047,9 @@ bi_emit_store_vary(bi_builder *b, nir_intrinsic_instr *instr)
                 bi_emit_split_i32(b, chans, data, src_comps);
 
                 bi_index tmp = bi_temp(b->shader);
-                bi_instr *collect = bi_collect_i32_to(b, tmp);
-                collect->nr_srcs = nr;
+                bi_instr *collect = bi_collect_i32_to(b, tmp, nr);
 
-                for (unsigned w = 0; w < nr; ++w)
+                bi_foreach_src(collect, w)
                         collect->src[w] = chans[w];
 
                 data = tmp;
index bbd09af..f1f0041 100644 (file)
@@ -80,11 +80,10 @@ protected:
 
    static void preload_moves(bi_builder *b, bi_index dest, int count, int idx)
    {
-      bi_instr *I = bi_collect_i32_to(b, dest);
-      I->nr_srcs = count;
+      bi_instr *I = bi_collect_i32_to(b, dest, count);
 
       b->cursor = bi_before_block(bi_start_block(&b->shader->blocks));
-      for (int i = 0; i < count; ++i)
+      bi_foreach_src(I, i)
          I->src[i] = bi_mov_i32(b, bi_register(idx*4 + i));
 
       b->cursor = bi_after_instr(I);
index b6cdc86..ccab6cb 100644 (file)
@@ -429,8 +429,8 @@ TEST_F(Optimizer, VarTexCoord32)
 
          bi_index x = bi_temp(b->shader);
          bi_index y = bi_temp(b->shader);
-         bi_instr *split = bi_split_i32_to(b, x, ld);
-         split->nr_dests = 2;
+         bi_instr *split = bi_split_i32_to(b, 2, ld);
+         split->dest[0] = x;
          split->dest[1] = y;
 
          bi_texs_2d_f32_to(b, reg, x, y, false, 0, 0);
index 849b911..3c67f3e 100644 (file)
@@ -47,11 +47,8 @@ lower_split_src(bi_context *ctx, bi_instr *I, unsigned s)
    /* Allocate temporary before the instruction */
    bi_builder b = bi_init_builder(ctx, bi_before_instr(I));
    bi_index vec = bi_temp(ctx);
-   bi_instr *collect = bi_collect_i32_to(&b, vec);
-   collect->nr_srcs = 2;
-
-   bi_instr *split = bi_split_i32_to(&b, bi_null(), vec);
-   split->nr_dests = 2;
+   bi_instr *collect = bi_collect_i32_to(&b, vec, 2);
+   bi_instr *split = bi_split_i32_to(&b, 2, vec);
 
    /* Emit collect */
    for (unsigned w = 0; w < 2; ++w) {