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@collabora.com>
This commit is contained in:
Alyssa Rosenzweig
2019-08-15 08:11:10 -07:00
parent 4fa09329c1
commit aeeeef1242
2 changed files with 20 additions and 3 deletions
+2
View File
@@ -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?
+18 -3
View File
@@ -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) {