From e16ad8f443939296a6da28dce832f750edd9233e Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 12 Apr 2022 20:43:32 -0400 Subject: [PATCH] agx: Lower p_split after RA Using existing regalloc infrastructure. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_register_allocate.c | 30 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/asahi/compiler/agx_register_allocate.c b/src/asahi/compiler/agx_register_allocate.c index ffffb1fc71e..c5fc4d7b543 100644 --- a/src/asahi/compiler/agx_register_allocate.c +++ b/src/asahi/compiler/agx_register_allocate.c @@ -184,6 +184,8 @@ agx_ra(agx_context *ctx) agx_foreach_instr_global_safe(ctx, ins) { /* Lower away RA pseudo-instructions */ + agx_builder b = agx_init_builder(ctx, agx_after_instr(ins)); + if (ins->op == AGX_OPCODE_P_COMBINE) { unsigned base = agx_index_to_reg(ssa_to_reg, ins->dest[0]); unsigned width = agx_size_align_16(ins->dest[0].size); @@ -203,9 +205,8 @@ agx_ra(agx_context *ctx) }; } - /* Lower away the copies pseudo-instruction */ - agx_builder b = agx_init_builder(ctx, agx_after_instr(ins)); agx_emit_parallel_copies(&b, copies, n); + agx_remove_instruction(ins); continue; } else if (ins->op == AGX_OPCODE_P_EXTRACT) { /* Uses the destination size */ @@ -214,11 +215,34 @@ agx_ra(agx_context *ctx) unsigned right = agx_index_to_reg(ssa_to_reg, ins->src[0]) + (size * ins->imm); if (left != right) { - agx_builder b = agx_init_builder(ctx, agx_after_instr(ins)); agx_mov_to(&b, agx_register(left, ins->dest[0].size), agx_register(right, ins->src[0].size)); } + agx_remove_instruction(ins); + continue; + } else if (ins->op == AGX_OPCODE_P_SPLIT) { + unsigned base = agx_index_to_reg(ssa_to_reg, ins->src[0]); + unsigned width = agx_size_align_16(ins->src[0].size); + + struct agx_copy copies[4]; + unsigned n = 0; + + /* Move the sources */ + for (unsigned i = 0; i < 4; ++i) { + if (agx_is_null(ins->dest[i])) continue; + assert(ins->dest[i].size == ins->src[0].size); + + copies[n++] = (struct agx_copy) { + .dest = agx_index_to_reg(ssa_to_reg, ins->dest[i]), + .src = base + (i * width), + .size = ins->dest[i].size + }; + } + + /* Lower away */ + agx_builder b = agx_init_builder(ctx, agx_after_instr(ins)); + agx_emit_parallel_copies(&b, copies, n); agx_remove_instruction(ins); continue; }