diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c index d3fb649a28f..c9ab2d3e32d 100644 --- a/src/asahi/compiler/agx_compile.c +++ b/src/asahi/compiler/agx_compile.c @@ -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