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
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)
{
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);
/* 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);
/* 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) {