mirror of
https://github.com/danog/ir.git
synced 2024-11-30 04:39:43 +01:00
Calculate number of ENTRY blocks during CFG construction to avoid an eaxtra loop for ctx->entries[] gathering at ir_match()
This commit is contained in:
parent
e5abfc119d
commit
b1f2167ea5
1
ir_cfg.c
1
ir_cfg.c
@ -262,6 +262,7 @@ next_successor:
|
||||
} else if (EXPECTED(insn->op1)) {
|
||||
if (insn->op == IR_ENTRY) {
|
||||
bb->flags |= IR_BB_ENTRY;
|
||||
ctx->entries_count++;
|
||||
}
|
||||
bb->predecessors_count = 1;
|
||||
edges_count++;
|
||||
|
22
ir_emit.c
22
ir_emit.c
@ -370,6 +370,7 @@ int ir_match(ir_ctx *ctx)
|
||||
ir_ref start, ref, *prev_ref;
|
||||
ir_block *bb;
|
||||
ir_insn *insn;
|
||||
uint32_t entries_count = 0;
|
||||
|
||||
ctx->rules = ir_mem_calloc(ctx->insns_count, sizeof(uint32_t));
|
||||
|
||||
@ -379,13 +380,20 @@ int ir_match(ir_ctx *ctx)
|
||||
prev_ref = ctx->prev_ref;
|
||||
}
|
||||
|
||||
if (ctx->entries_count) {
|
||||
ctx->entries = ir_mem_malloc(ctx->entries_count * sizeof(ir_ref));
|
||||
}
|
||||
|
||||
for (b = ctx->cfg_blocks_count, bb = ctx->cfg_blocks + b; b > 0; b--, bb--) {
|
||||
IR_ASSERT(!(bb->flags & IR_BB_UNREACHABLE));
|
||||
start = bb->start;
|
||||
if (bb->flags & IR_BB_ENTRY) {
|
||||
IR_ASSERT(entries_count < ctx->entries_count);
|
||||
insn = &ctx->ir_base[start];
|
||||
IR_ASSERT(insn->op == IR_ENTRY);
|
||||
insn->op3 = ctx->entries_count++;
|
||||
insn->op3 = entries_count;
|
||||
ctx->entries[entries_count] = b;
|
||||
entries_count++;
|
||||
}
|
||||
ctx->rules[start] = IR_SKIP;
|
||||
ref = bb->end;
|
||||
@ -415,14 +423,10 @@ int ir_match(ir_ctx *ctx)
|
||||
}
|
||||
|
||||
if (ctx->entries_count) {
|
||||
ctx->entries = ir_mem_malloc(ctx->entries_count * sizeof(ir_ref));
|
||||
|
||||
for (b = ctx->cfg_blocks_count, bb = ctx->cfg_blocks + b; b > 0; b--, bb--) {
|
||||
if (bb->flags & IR_BB_ENTRY) {
|
||||
ir_ref i = bb->start;
|
||||
ir_insn *insn = ctx->ir_base + i;
|
||||
ctx->entries[insn->op3] = b;
|
||||
}
|
||||
ctx->entries_count = entries_count;
|
||||
if (!entries_count) {
|
||||
ir_mem_free(ctx->entries);
|
||||
ctx->entries = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
1
ir_gcm.c
1
ir_gcm.c
@ -654,6 +654,7 @@ restart:
|
||||
new_ctx.fixed_call_stack_size = ctx->fixed_call_stack_size;
|
||||
new_ctx.fixed_regset = ctx->fixed_regset;
|
||||
new_ctx.fixed_save_regset = ctx->fixed_save_regset;
|
||||
new_ctx.entries_count = ctx->entries_count;
|
||||
|
||||
/* Copy constants */
|
||||
if (consts_count == ctx->consts_count) {
|
||||
|
Loading…
Reference in New Issue
Block a user