From eae4c50be9607caac5ceadd132888e1905a2d3c3 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sun, 22 Sep 2024 16:00:16 -0400 Subject: [PATCH] agx: add spilling debug helpers I keep typing these Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_register_allocate.c | 16 ++++++++++++++++ src/asahi/compiler/agx_spill.c | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/src/asahi/compiler/agx_register_allocate.c b/src/asahi/compiler/agx_register_allocate.c index b68edaab82a..ac4cc97bb29 100644 --- a/src/asahi/compiler/agx_register_allocate.c +++ b/src/asahi/compiler/agx_register_allocate.c @@ -151,6 +151,13 @@ agx_split_width(const agx_instr *I) static unsigned agx_calc_register_demand(agx_context *ctx) { + /* Print detailed demand calculation, helpful to debug spilling */ + bool debug = false; + + if (debug) { + agx_print_shader(ctx, stdout); + } + uint8_t *widths = calloc(ctx->alloc, sizeof(uint8_t)); enum ra_class *classes = calloc(ctx->alloc, sizeof(enum ra_class)); @@ -201,6 +208,10 @@ agx_calc_register_demand(agx_context *ctx) */ unsigned late_kill_count = 0; + if (debug) { + printf("\n"); + } + agx_foreach_instr_in_block(block, I) { /* Phis happen in parallel and are already accounted for in the live-in * set, just skip them so we don't double count. @@ -208,6 +219,11 @@ agx_calc_register_demand(agx_context *ctx) if (I->op == AGX_OPCODE_PHI) continue; + if (debug) { + printf("%u: ", demand); + agx_print_instr(I, stdout); + } + if (I->op == AGX_OPCODE_PRELOAD) { unsigned size = agx_size_align_16(I->src[0].size); max_demand = MAX2(max_demand, I->src[0].value + size); diff --git a/src/asahi/compiler/agx_spill.c b/src/asahi/compiler/agx_spill.c index 5b4dfa8b74e..f8c1a4c0c7e 100644 --- a/src/asahi/compiler/agx_spill.c +++ b/src/asahi/compiler/agx_spill.c @@ -683,6 +683,12 @@ min_algorithm(struct spill_ctx *ctx) agx_foreach_instr_in_block(ctx->block, I) { assert(ctx->nW <= ctx->k && "invariant"); + /* Debug to check against our RA demand calculations */ + if (0) { + printf("%u: ", ctx->nW); + agx_print_instr(I, stdout); + } + /* Phis are special since they happen along the edge. When we initialized * W and S, we implicitly chose which phis are spilled. So, here we just * need to rewrite the phis to write into memory.