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