ir3: Refactor nir->ir3 block handling

Originally I wrote this to support multiple ir3 blocks per NIR block,
but this turned out to be more useful for creating a stable ordering to
the predecessors. We compute the predecessors ourselves, rather than
relying on NIR, so that the array of predecessors we create in the next
commit has a stable order we can rely on when creating phi nodes.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10591>
This commit is contained in:
Connor Abbott 2020-09-11 11:48:27 +02:00 committed by Marge Bot
parent d28b22374c
commit 0bd68b8386

View file

@ -2742,27 +2742,15 @@ get_block(struct ir3_context *ctx, const nir_block *nblock)
block->nblock = nblock;
_mesa_hash_table_insert(ctx->block_ht, nblock, block);
set_foreach(nblock->predecessors, sentry) {
_mesa_set_add(block->predecessors, get_block(ctx, sentry->key));
}
return block;
}
static void
emit_block(struct ir3_context *ctx, nir_block *nblock)
{
struct ir3_block *block = get_block(ctx, nblock);
ctx->block = get_block(ctx, nblock);
for (int i = 0; i < ARRAY_SIZE(block->successors); i++) {
if (nblock->successors[i]) {
block->successors[i] =
get_block(ctx, nblock->successors[i]);
}
}
ctx->block = block;
list_addtail(&block->node, &ctx->ir->block_list);
list_addtail(&ctx->block->node, &ctx->ir->block_list);
/* re-emit addr register in each block if needed: */
for (int i = 0; i < ARRAY_SIZE(ctx->addr0_ht); i++) {
@ -2781,6 +2769,13 @@ emit_block(struct ir3_context *ctx, nir_block *nblock)
return;
}
for (int i = 0; i < ARRAY_SIZE(ctx->block->successors); i++) {
if (nblock->successors[i]) {
ctx->block->successors[i] =
get_block(ctx, nblock->successors[i]);
}
}
_mesa_hash_table_clear(ctx->sel_cond_conversions, NULL);
}
@ -2899,10 +2894,6 @@ emit_stream_out(struct ir3_context *ctx)
orig_end_block->successors[1] = new_end_block;
stream_out_block->successors[0] = new_end_block;
_mesa_set_add(stream_out_block->predecessors, orig_end_block);
_mesa_set_add(new_end_block->predecessors, orig_end_block);
_mesa_set_add(new_end_block->predecessors, stream_out_block);
/* setup 'if (vtxcnt < maxvtxcnt)' condition: */
cond = ir3_CMPS_S(ctx->block, vtxcnt, 0, maxvtxcnt, 0);
@ -2962,6 +2953,17 @@ emit_stream_out(struct ir3_context *ctx)
ctx->block = new_end_block;
}
static void
setup_predecessors(struct ir3 *ir)
{
foreach_block(block, &ir->block_list) {
for (int i = 0; i < ARRAY_SIZE(block->successors); i++) {
if (block->successors[i])
_mesa_set_add(block->successors[i]->predecessors, block);
}
}
}
static void
emit_function(struct ir3_context *ctx, nir_function_impl *impl)
{
@ -3017,6 +3019,8 @@ emit_function(struct ir3_context *ctx, nir_function_impl *impl)
} else {
ir3_END(ctx->block);
}
setup_predecessors(ctx->ir);
}
static void