Debian Codegraph @

src/asahi/compiler/agx_reindex_ssa.c

raw
1 /*
2 * Copyright 2024 Valve Corporation
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include <stdlib.h>
7 #include "agx_compiler.h"
8
9 /* Reindex SSA to reduce memory usage */
10
11 void
12 agx_reindex_ssa(agx_context *ctx)
13 {
14 unsigned *remap = calloc(ctx->alloc, sizeof(*remap));
15
16 ctx->alloc = 0;
17
18 agx_foreach_instr_global(ctx, I) {
19 agx_foreach_ssa_dest(I, d) {
20 assert(!remap[I->dest[d].value] && "input is SSA");
21 remap[I->dest[d].value] = ctx->alloc++;
22 I->dest[d].value = remap[I->dest[d].value];
23 }
24 }
25
26 agx_foreach_instr_global(ctx, I) {
27 agx_foreach_ssa_src(I, s) {
28 I->src[s].value = remap[I->src[s].value];
29 }
30 }
31
32 free(remap);
33 }