agx: Implement emit_if the simplest way

Lots of optimizations are possible from here.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11023>
This commit is contained in:
Alyssa Rosenzweig 2021-05-23 17:26:50 -04:00 committed by Alyssa Rosenzweig
parent 3def66e8aa
commit cf43206e76
1 changed files with 32 additions and 1 deletions

View File

@ -743,10 +743,41 @@ emit_block(agx_context *ctx, nir_block *block)
return blk;
}
static agx_block *
emit_cf_list(agx_context *ctx, struct exec_list *list);
/* Emit if-else as
*
* if_icmp cond != 0
* ...
* else_icmp cond == 0
* ...
* pop_exec
*
* This is not usually optimal, but it's a start.
*/
static void
emit_if(agx_context *ctx, nir_if *nif)
{
unreachable("if-statements todo");
agx_builder _b = agx_init_builder(ctx, agx_after_block(ctx->current_block));
agx_index cond = agx_src_index(&nif->condition);
agx_if_icmp(&_b, cond, agx_zero(), 1, AGX_ICOND_UEQ, true);
ctx->loop_nesting++;
/* Emit the two subblocks. */
emit_cf_list(ctx, &nif->then_list);
_b.cursor = agx_after_block(ctx->current_block);
agx_else_icmp(&_b, cond, agx_zero(), 1, AGX_ICOND_UEQ, false);
emit_cf_list(ctx, &nif->else_list);
_b.cursor = agx_after_block(ctx->current_block);
agx_pop_exec(&_b, 1);
ctx->loop_nesting--;
/* TODO: control flow graph(s) */
}
static void