Mesa (master): pan/midgard: Maintain block predecessor set

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Aug 19 15:37:27 UTC 2019


Module: Mesa
Branch: master
Commit: aeeeef1242b7f0541f5021d080bd7c1e55060feb
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=aeeeef1242b7f0541f5021d080bd7c1e55060feb

Author: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Date:   Thu Aug 15 08:11:10 2019 -0700

pan/midgard: Maintain block predecessor set

While we already compute the successors array, for backwards data flow
analysis, it is useful to walk the control flow graph backwards based on
predecessors, so let's compute that information as well.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>

---

 src/panfrost/midgard/compiler.h        |  2 ++
 src/panfrost/midgard/midgard_compile.c | 21 ++++++++++++++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/panfrost/midgard/compiler.h b/src/panfrost/midgard/compiler.h
index 61fe8a92b2e..fb47c3475bf 100644
--- a/src/panfrost/midgard/compiler.h
+++ b/src/panfrost/midgard/compiler.h
@@ -173,6 +173,8 @@ typedef struct midgard_block {
         struct midgard_block *successors[2];
         unsigned nr_successors;
 
+        struct set *predecessors;
+
         /* The successors pointer form a graph, and in the case of
          * complex control flow, this graph has a cycles. To aid
          * traversal during liveness analysis, we have a visited?
diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c
index 4a010c97443..f08f60fc328 100644
--- a/src/panfrost/midgard/midgard_compile.c
+++ b/src/panfrost/midgard/midgard_compile.c
@@ -89,6 +89,9 @@ midgard_block_add_successor(midgard_block *block, midgard_block *successor)
 
         block->successors[block->nr_successors++] = successor;
         assert(block->nr_successors <= ARRAY_SIZE(block->successors));
+
+        /* Note the predecessor in the other direction */
+        _mesa_set_add(successor->predecessors, block);
 }
 
 /* Helpers to generate midgard_instruction's using macro magic, since every
@@ -2253,13 +2256,25 @@ emit_fragment_epilogue(compiler_context *ctx)
 }
 
 static midgard_block *
+create_empty_block(compiler_context *ctx)
+{
+        midgard_block *blk = rzalloc(ctx, midgard_block);
+
+        blk->predecessors = _mesa_set_create(blk,
+                        _mesa_hash_pointer,
+                        _mesa_key_pointer_equal);
+
+        return blk;
+}
+
+static midgard_block *
 emit_block(compiler_context *ctx, nir_block *block)
 {
         midgard_block *this_block = ctx->after_block;
         ctx->after_block = NULL;
 
         if (!this_block)
-                this_block = rzalloc(ctx, midgard_block);
+                this_block = create_empty_block(ctx);
 
         list_addtail(&this_block->link, &ctx->blocks);
 
@@ -2342,7 +2357,7 @@ emit_if(struct compiler_context *ctx, nir_if *nif)
 
         /* Wire up the successors */
 
-        ctx->after_block = rzalloc(ctx, midgard_block);
+        ctx->after_block = create_empty_block(ctx);
 
         midgard_block_add_successor(before_block, then_block);
         midgard_block_add_successor(before_block, else_block);
@@ -2381,7 +2396,7 @@ emit_loop(struct compiler_context *ctx, nir_loop *nloop)
 
         /* Fix up the break statements we emitted to point to the right place,
          * now that we can allocate a block number for them */
-        ctx->after_block = rzalloc(ctx, midgard_block);
+        ctx->after_block = create_empty_block(ctx);
 
         list_for_each_entry_from(struct midgard_block, block, start_block, &ctx->blocks, link) {
                 mir_foreach_instr_in_block(block, ins) {




More information about the mesa-commit mailing list