From 6cc8d7b52a68c665dc7d6450740cc55c6766748a Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sun, 2 Jul 2023 09:33:53 -0400 Subject: [PATCH] agx: Add try_coalesce_with helper Common logic the next few patches will use to try to assign something to the same register as something else. "If it's already been assigned a register and that register is free now, use it, otherwise bail." Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_register_allocate.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/asahi/compiler/agx_register_allocate.c b/src/asahi/compiler/agx_register_allocate.c index ba2860d..7c9364f 100644 --- a/src/asahi/compiler/agx_register_allocate.c +++ b/src/asahi/compiler/agx_register_allocate.c @@ -739,6 +739,25 @@ affinity_base_of_collect(struct ra_ctx *rctx, agx_instr *collect, unsigned src) return ~0; } +static bool +try_coalesce_with(struct ra_ctx *rctx, agx_index ssa, unsigned count, + bool may_be_unvisited, unsigned *out) +{ + assert(ssa.type == AGX_INDEX_NORMAL); + if (!BITSET_TEST(rctx->visited, ssa.value)) { + assert(may_be_unvisited); + return false; + } + + unsigned base = rctx->ssa_to_reg[ssa.value]; + if (BITSET_TEST_RANGE(rctx->used_regs, base, base + count - 1)) + return false; + + assert(base + count <= rctx->bound && "invariant"); + *out = base; + return true; +} + static unsigned pick_regs(struct ra_ctx *rctx, agx_instr *I, unsigned d) { -- 2.7.4