agx: Introduce worklist infrastructure
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sun, 1 May 2022 19:53:35 +0000 (15:53 -0400)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Mon, 2 May 2022 02:00:00 +0000 (22:00 -0400)
Using the common NIR stuff.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16268>

src/asahi/compiler/agx_compile.c
src/asahi/compiler/agx_compiler.h
src/asahi/compiler/agx_print.c

index 779f39e..9a9d6ae 100644 (file)
@@ -1728,11 +1728,9 @@ agx_compile_shader_nir(nir_shader *nir,
    for (unsigned i = 0; i < 8; ++i)
       agx_trap(&_b);
 
-   unsigned block_source_count = 0;
-
-   /* Name blocks now that we're done emitting so the order is consistent */
+   /* Index blocks now that we're done emitting so the order is consistent */
    agx_foreach_block(ctx, block)
-      block->name = block_source_count++;
+      block->index = ctx->num_blocks++;
 
    if (agx_debug & AGX_DBG_SHADERS && !skip_internal)
       agx_print_shader(ctx, stdout);
index 4b1fe4b..6052535 100644 (file)
@@ -29,6 +29,7 @@
 #include "util/u_math.h"
 #include "util/half_float.h"
 #include "util/u_dynarray.h"
+#include "util/u_worklist.h"
 #include "agx_compile.h"
 #include "agx_opcodes.h"
 #include "agx_minifloat.h"
@@ -347,7 +348,7 @@ typedef struct agx_block {
    struct list_head instructions;
 
    /* Index of the block in source order */
-   unsigned name;
+   unsigned index;
 
    /* Control flow graph */
    struct agx_block *successors[2];
@@ -388,6 +389,9 @@ typedef struct {
    /* Place to start pushing new values */
    unsigned push_base;
 
+   /* Maximum block index */
+   unsigned num_blocks;
+
    /* For creating temporaries */
    unsigned alloc;
 
@@ -591,6 +595,14 @@ agx_exit_block(agx_context *ctx)
    return last;
 }
 
+#define agx_worklist_init(ctx, w) u_worklist_init(w, ctx->num_blocks, ctx)
+#define agx_worklist_push_head(w, block) u_worklist_push_head(w, block, index)
+#define agx_worklist_push_tail(w, block) u_worklist_push_tail(w, block, index)
+#define agx_worklist_peek_head(w) u_worklist_peek_head(w, agx_block, index)
+#define agx_worklist_pop_head(w)  u_worklist_pop_head( w, agx_block, index)
+#define agx_worklist_peek_tail(w) u_worklist_peek_tail(w, agx_block, index)
+#define agx_worklist_pop_tail(w)  u_worklist_pop_tail( w, agx_block, index)
+
 /* Like in NIR, for use with the builder */
 
 enum agx_cursor_option {
index 6b53cc0..2191b6f 100644 (file)
@@ -194,7 +194,7 @@ agx_print_instr(agx_instr *I, FILE *fp)
 void
 agx_print_block(agx_block *block, FILE *fp)
 {
-   fprintf(fp, "block%u {\n", block->name);
+   fprintf(fp, "block%u {\n", block->index);
 
    agx_foreach_instr_in_block(block, ins)
       agx_print_instr(ins, fp);
@@ -205,14 +205,14 @@ agx_print_block(agx_block *block, FILE *fp)
       fprintf(fp, " -> ");
 
       agx_foreach_successor(block, succ)
-         fprintf(fp, "block%u ", succ->name);
+         fprintf(fp, "block%u ", succ->index);
    }
 
    if (block->predecessors.size) {
       fprintf(fp, " from");
 
       agx_foreach_predecessor(block, pred)
-         fprintf(fp, " block%u", (*pred)->name);
+         fprintf(fp, " block%u", (*pred)->index);
    }
 
    fprintf(fp, "\n\n");