[03/20] pan/midgard: Maintain block predecessor set

Submitted by Alyssa Rosenzweig on Aug. 16, 2019, 3:35 p.m.

Details

Message ID 20190816153600.10519-4-alyssa.rosenzweig@collabora.com
State New
Headers show
Series "panfrost: Fix Midgard liveness analysis" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Alyssa Rosenzweig Aug. 16, 2019, 3:35 p.m.
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@collabora.com>
---
 src/panfrost/midgard/compiler.h        |  2 ++
 src/panfrost/midgard/midgard_compile.c | 21 ++++++++++++++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

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
@@ -2252,6 +2255,18 @@  emit_fragment_epilogue(compiler_context *ctx)
         EMIT(alu_br_compact_cond, midgard_jmp_writeout_op_writeout, TAG_ALU_4, -1, midgard_condition_always);
 }
 
+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)
 {
@@ -2259,7 +2274,7 @@  emit_block(compiler_context *ctx, nir_block *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) {