static bi_block *emit_cf_list(bi_context *ctx, struct exec_list *list);
static void
+bi_block_add_successor(bi_block *block, bi_block *successor)
+{
+ assert(block != NULL && successor != NULL);
+
+ /* Cull impossible edges */
+ if (block->base.unconditional_jumps)
+ return;
+
+ for (unsigned i = 0; i < ARRAY_SIZE(block->base.successors); ++i) {
+ if (block->base.successors[i]) {
+ if (block->base.successors[i] == (pan_block *) successor)
+ return;
+ else
+ continue;
+ }
+
+ block->base.successors[i] = (void *) successor;
+ _mesa_set_add(successor->base.predecessors, block);
+ return;
+ }
+
+ unreachable("Too many successors");
+}
+
+static void
bi_emit_jump(bi_builder *b, nir_jump_instr *instr)
{
bi_instr *branch = bi_jump(b, bi_zero());
unreachable("Unhandled jump type");
}
- pan_block_add_successor(&b->shader->current_block->base, &branch->branch_target->base);
+ bi_block_add_successor(b->shader->current_block, branch->branch_target);
b->shader->current_block->base.unconditional_jumps = true;
}
if (ctx->instruction_count == count_in) {
then_branch->branch_target = ctx->after_block;
- pan_block_add_successor(&end_then_block->base, &ctx->after_block->base); /* fallthrough */
+ bi_block_add_successor(end_then_block, ctx->after_block); /* fallthrough */
} else {
then_branch->branch_target = else_block;
bi_instr *then_exit = bi_jump(&_b, bi_zero());
then_exit->branch_target = ctx->after_block;
- pan_block_add_successor(&end_then_block->base, &then_exit->branch_target->base);
- pan_block_add_successor(&end_else_block->base, &ctx->after_block->base); /* fallthrough */
+ bi_block_add_successor(end_then_block, then_exit->branch_target);
+ bi_block_add_successor(end_else_block, ctx->after_block); /* fallthrough */
}
- pan_block_add_successor(&before_block->base, &then_branch->branch_target->base); /* then_branch */
- pan_block_add_successor(&before_block->base, &then_block->base); /* fallthrough */
+ bi_block_add_successor(before_block, then_branch->branch_target); /* then_branch */
+ bi_block_add_successor(before_block, then_block); /* fallthrough */
}
static void
bi_builder _b = bi_init_builder(ctx, bi_after_block(ctx->current_block));
bi_instr *I = bi_jump(&_b, bi_zero());
I->branch_target = ctx->continue_block;
- pan_block_add_successor(&start_block->base, &ctx->continue_block->base);
- pan_block_add_successor(&ctx->current_block->base, &ctx->continue_block->base);
+ bi_block_add_successor(start_block, ctx->continue_block);
+ bi_block_add_successor(ctx->current_block, ctx->continue_block);
ctx->after_block = ctx->break_block;