diff --git a/ir.c b/ir.c index ca2ccd6..cc2b994 100644 --- a/ir.c +++ b/ir.c @@ -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; } diff --git a/ir.h b/ir.h index 5416261..a6ff51a 100644 --- a/ir.h +++ b/ir.h @@ -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) */ diff --git a/ir_gcm.c b/ir_gcm.c index 59740fb..cbbe2ef 100644 --- a/ir_gcm.c +++ b/ir_gcm.c @@ -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) { diff --git a/ir_sccp.c b/ir_sccp.c index 951b1d9..1776f10 100644 --- a/ir_sccp.c +++ b/ir_sccp.c @@ -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