Allow SCCP to grow use_lists (through reallocation)

This commit is contained in:
Dmitry Stogov 2022-09-14 15:14:18 +03:00
parent cdc34ae22b
commit 11db21a98c
4 changed files with 12 additions and 2 deletions

2
ir.c
View File

@ -280,6 +280,7 @@ void ir_init(ir_ctx *ctx, ir_ref consts_limit, ir_ref insns_limit)
ctx->use_lists = NULL;
ctx->use_edges = NULL;
ctx->use_edges_count = 0;
ctx->cfg_blocks_count = 0;
ctx->cfg_edges_count = 0;
@ -939,6 +940,7 @@ void ir_build_def_use_lists(ir_ctx *ctx)
}
ctx->use_edges = edges;
ctx->use_edges_count = edges_count;
ctx->use_lists = lists;
}

1
ir.h
View File

@ -440,6 +440,7 @@ typedef struct _ir_ctx {
ir_insn fold_insn;
ir_use_list *use_lists; /* def->use lists for each instruction */
ir_ref *use_edges;
uint32_t use_edges_count;
uint32_t cfg_blocks_count;
uint32_t cfg_edges_count;
ir_block *cfg_blocks; /* list of Basic Blocks (starts from 1) */

View File

@ -581,6 +581,7 @@ restart:
}
new_ctx.use_edges = edges;
new_ctx.use_edges_count = edges_count;
new_ctx.use_lists = lists;
if (ctx->cfg_blocks) {

View File

@ -196,11 +196,17 @@ static void ir_sccp_add_to_use_list(ir_ctx *ctx, ir_ref to, ir_ref ref)
ir_use_list *use_list = &ctx->use_lists[to];
ir_ref n = use_list->refs + use_list->count;
if (ctx->use_edges[n] == IR_UNUSED) {
if (n < ctx->use_edges_count && ctx->use_edges[n] == IR_UNUSED) {
ctx->use_edges[n] = ref;
use_list->count++;
} else {
IR_ASSERT(0 && "NIY: insert def->use edges"); // TODO:
/* Reallocate the whole edges buffer (this is inefficient) */
ctx->use_edges = ir_mem_realloc(ctx->use_edges, (ctx->use_edges_count + use_list->count + 1) * sizeof(ir_ref));
memcpy(ctx->use_edges + ctx->use_edges_count, ctx->use_edges + use_list->refs, use_list->count * sizeof(ir_ref));
use_list->refs = ctx->use_edges_count;
ctx->use_edges[use_list->refs + use_list->count] = ref;
use_list->count++;
ctx->use_edges_count += use_list->count;
}
}
#endif