agx: add SSA reindexing pass

spilling and SSA repair will generate piles of dead SSA defs. add a reindexing
pass to keep memory usag emanagable on large shaders.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28483>
This commit is contained in:
Alyssa Rosenzweig 2024-02-22 08:41:39 -04:00 committed by Marge Bot
parent 20409b6bae
commit 450e79c1e6
3 changed files with 35 additions and 0 deletions

View file

@ -938,6 +938,7 @@ void agx_lower_uniform_sources(agx_context *ctx);
void agx_opt_cse(agx_context *ctx);
void agx_dce(agx_context *ctx, bool partial);
void agx_pressure_schedule(agx_context *ctx);
void agx_reindex_ssa(agx_context *ctx);
void agx_ra(agx_context *ctx);
void agx_lower_64bit_postra(agx_context *ctx);
void agx_insert_waits(agx_context *ctx);

View file

@ -0,0 +1,33 @@
/*
* Copyright 2024 Valve Corporation
* SPDX-License-Identifier: MIT
*/
#include <stdlib.h>
#include "agx_compiler.h"
/* Reindex SSA to reduce memory usage */
void
agx_reindex_ssa(agx_context *ctx)
{
unsigned *remap = calloc(ctx->alloc, sizeof(*remap));
ctx->alloc = 0;
agx_foreach_instr_global(ctx, I) {
agx_foreach_ssa_dest(I, d) {
assert(!remap[I->dest[d].value] && "input is SSA");
remap[I->dest[d].value] = ctx->alloc++;
I->dest[d].value = remap[I->dest[d].value];
}
}
agx_foreach_instr_global(ctx, I) {
agx_foreach_ssa_src(I, s) {
I->src[s].value = remap[I->src[s].value];
}
}
free(remap);
}

View file

@ -34,6 +34,7 @@ libasahi_agx_files = files(
'agx_opt_empty_else.c',
'agx_opt_jmp_none.c',
'agx_optimizer.c',
'agx_reindex_ssa.c',
'agx_register_allocate.c',
'agx_validate.c',
)