| 1 |
/* |
| 2 |
* Copyright 2024 Valve Corporation |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <stdlib.h> |
| 7 |
#include "compiler.h" |
| 8 |
|
| 9 |
void |
| 10 |
bi_reindex_ssa(bi_context *ctx) |
| 11 |
{ |
| 12 |
unsigned *remap = calloc(ctx->ssa_alloc, sizeof(*remap)); |
| 13 |
|
| 14 |
ctx->ssa_alloc = 0; |
| 15 |
|
| 16 |
bi_foreach_instr_global(ctx, I) { |
| 17 |
bi_foreach_ssa_dest(I, d) { |
| 18 |
assert(!remap[I->dest[d].value] && "input is SSA"); |
| 19 |
remap[I->dest[d].value] = ctx->ssa_alloc++; |
| 20 |
I->dest[d].value = remap[I->dest[d].value]; |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
bi_foreach_instr_global(ctx, I) { |
| 25 |
bi_foreach_ssa_src(I, s) { |
| 26 |
I->src[s].value = remap[I->src[s].value]; |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
free(remap); |
| 31 |
} |