mirror of
https://github.com/danog/ir.git
synced 2024-11-30 04:39:43 +01:00
Separate ir_build_prev_refs(). It's necessary only for -O0 pipeline.
This commit is contained in:
parent
7fd1ccf48b
commit
a137adfdf9
1
ir.h
1
ir.h
@ -582,6 +582,7 @@ int ir_build_cfg(ir_ctx *ctx);
|
|||||||
int ir_build_dominators_tree(ir_ctx *ctx);
|
int ir_build_dominators_tree(ir_ctx *ctx);
|
||||||
int ir_find_loops(ir_ctx *ctx);
|
int ir_find_loops(ir_ctx *ctx);
|
||||||
int ir_schedule_blocks(ir_ctx *ctx);
|
int ir_schedule_blocks(ir_ctx *ctx);
|
||||||
|
void ir_build_prev_refs(ir_ctx *ctx);
|
||||||
|
|
||||||
/* SCCP - Sparse Conditional Constant Propagation (implementation in ir_sccp.c) */
|
/* SCCP - Sparse Conditional Constant Propagation (implementation in ir_sccp.c) */
|
||||||
int ir_sccp(ir_ctx *ctx);
|
int ir_sccp(ir_ctx *ctx);
|
||||||
|
21
ir_emit.c
21
ir_emit.c
@ -264,27 +264,11 @@ static void *ir_jmp_addr(ir_ctx *ctx, ir_insn *insn, ir_insn *addr_insn)
|
|||||||
int ir_match(ir_ctx *ctx)
|
int ir_match(ir_ctx *ctx)
|
||||||
{
|
{
|
||||||
uint32_t b;
|
uint32_t b;
|
||||||
ir_ref i, n, prev;
|
ir_ref i;
|
||||||
ir_block *bb;
|
ir_block *bb;
|
||||||
ir_insn *insn;
|
|
||||||
|
|
||||||
if (!ctx->prev_ref) {
|
if (!ctx->prev_ref) {
|
||||||
ctx->prev_ref = ir_mem_malloc(ctx->insns_count * sizeof(ir_ref));
|
ir_build_prev_refs(ctx);
|
||||||
prev = 0;
|
|
||||||
for (b = 1, bb = ctx->cfg_blocks + b; b <= ctx->cfg_blocks_count; b++, bb++) {
|
|
||||||
if (bb->flags & IR_BB_UNREACHABLE) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (i = bb->start, insn = ctx->ir_base + i; i < bb->end;) {
|
|
||||||
ctx->prev_ref[i] = prev;
|
|
||||||
n = ir_operands_count(ctx, insn);
|
|
||||||
n = 1 + (n >> 2); // support for multi-word instructions like MERGE and PHI
|
|
||||||
prev = i;
|
|
||||||
i += n;
|
|
||||||
insn += n;
|
|
||||||
}
|
|
||||||
ctx->prev_ref[i] = prev;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->rules = ir_mem_calloc(ctx->insns_count, sizeof(uint32_t));
|
ctx->rules = ir_mem_calloc(ctx->insns_count, sizeof(uint32_t));
|
||||||
@ -293,7 +277,6 @@ int ir_match(ir_ctx *ctx)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (i = bb->end; i > bb->start; i = ctx->prev_ref[i]) {
|
for (i = bb->end; i > bb->start; i = ctx->prev_ref[i]) {
|
||||||
insn = &ctx->ir_base[i];
|
|
||||||
if (!ctx->rules[i]) {
|
if (!ctx->rules[i]) {
|
||||||
ctx->rules[i] = ir_match_insn(ctx, i, bb);
|
ctx->rules[i] = ir_match_insn(ctx, i, bb);
|
||||||
}
|
}
|
||||||
|
@ -672,6 +672,10 @@ static int ir_emit_func(ir_ctx *ctx, FILE *f)
|
|||||||
|
|
||||||
ret_type = ir_get_return_type(ctx);
|
ret_type = ir_get_return_type(ctx);
|
||||||
|
|
||||||
|
if (!ctx->prev_ref) {
|
||||||
|
ir_build_prev_refs(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
use_list = &ctx->use_lists[1];
|
use_list = &ctx->use_lists[1];
|
||||||
n = use_list->count;
|
n = use_list->count;
|
||||||
for (i = 0, p = &ctx->use_edges[use_list->refs]; i < n; i++, p++) {
|
for (i = 0, p = &ctx->use_edges[use_list->refs]; i < n; i++, p++) {
|
||||||
|
25
ir_gcm.c
25
ir_gcm.c
@ -739,3 +739,28 @@ restart:
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ir_build_prev_refs(ir_ctx *ctx)
|
||||||
|
{
|
||||||
|
uint32_t b;
|
||||||
|
ir_block *bb;
|
||||||
|
ir_ref i, n, prev;
|
||||||
|
ir_insn *insn;
|
||||||
|
|
||||||
|
ctx->prev_ref = ir_mem_malloc(ctx->insns_count * sizeof(ir_ref));
|
||||||
|
prev = 0;
|
||||||
|
for (b = 1, bb = ctx->cfg_blocks + b; b <= ctx->cfg_blocks_count; b++, bb++) {
|
||||||
|
if (bb->flags & IR_BB_UNREACHABLE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (i = bb->start, insn = ctx->ir_base + i; i < bb->end;) {
|
||||||
|
ctx->prev_ref[i] = prev;
|
||||||
|
n = ir_operands_count(ctx, insn);
|
||||||
|
n = 1 + (n >> 2); // support for multi-word instructions like MERGE and PHI
|
||||||
|
prev = i;
|
||||||
|
i += n;
|
||||||
|
insn += n;
|
||||||
|
}
|
||||||
|
ctx->prev_ref[i] = prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
11
ir_ra.c
11
ir_ra.c
@ -46,18 +46,14 @@ int ir_assign_virtual_registers(ir_ctx *ctx)
|
|||||||
uint32_t *vregs;
|
uint32_t *vregs;
|
||||||
uint32_t vregs_count = 0;
|
uint32_t vregs_count = 0;
|
||||||
uint32_t b;
|
uint32_t b;
|
||||||
ir_ref i, n, prev;
|
ir_ref i, n;
|
||||||
ir_block *bb;
|
ir_block *bb;
|
||||||
ir_insn *insn;
|
ir_insn *insn;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
|
|
||||||
/* Assign unique virtual register to each data node */
|
/* Assign unique virtual register to each data node */
|
||||||
if (!ctx->prev_ref) {
|
|
||||||
ctx->prev_ref = ir_mem_malloc(ctx->insns_count * sizeof(ir_ref));
|
|
||||||
}
|
|
||||||
vregs = ir_mem_calloc(ctx->insns_count, sizeof(ir_ref));
|
vregs = ir_mem_calloc(ctx->insns_count, sizeof(ir_ref));
|
||||||
n = 1;
|
n = 1;
|
||||||
prev = 0;
|
|
||||||
for (b = 1, bb = ctx->cfg_blocks + b; b <= ctx->cfg_blocks_count; b++, bb++) {
|
for (b = 1, bb = ctx->cfg_blocks + b; b <= ctx->cfg_blocks_count; b++, bb++) {
|
||||||
if (bb->flags & IR_BB_UNREACHABLE) {
|
if (bb->flags & IR_BB_UNREACHABLE) {
|
||||||
continue;
|
continue;
|
||||||
@ -66,14 +62,11 @@ int ir_assign_virtual_registers(ir_ctx *ctx)
|
|||||||
|
|
||||||
/* skip first instruction */
|
/* skip first instruction */
|
||||||
insn = ctx->ir_base + i;
|
insn = ctx->ir_base + i;
|
||||||
ctx->prev_ref[i] = prev;
|
|
||||||
prev = i;
|
|
||||||
n = ir_operands_count(ctx, insn);
|
n = ir_operands_count(ctx, insn);
|
||||||
n = 1 + (n >> 2); // support for multi-word instructions like MERGE and PHI
|
n = 1 + (n >> 2); // support for multi-word instructions like MERGE and PHI
|
||||||
i += n;
|
i += n;
|
||||||
insn += n;
|
insn += n;
|
||||||
while (i < bb->end) {
|
while (i < bb->end) {
|
||||||
ctx->prev_ref[i] = prev;
|
|
||||||
flags = ir_op_flags[insn->op];
|
flags = ir_op_flags[insn->op];
|
||||||
if (((flags & IR_OP_FLAG_DATA) && ctx->use_lists[i].count > 0)
|
if (((flags & IR_OP_FLAG_DATA) && ctx->use_lists[i].count > 0)
|
||||||
|| ((flags & IR_OP_FLAG_MEM) && ctx->use_lists[i].count > 1)) {
|
|| ((flags & IR_OP_FLAG_MEM) && ctx->use_lists[i].count > 1)) {
|
||||||
@ -83,11 +76,9 @@ int ir_assign_virtual_registers(ir_ctx *ctx)
|
|||||||
}
|
}
|
||||||
n = ir_operands_count(ctx, insn);
|
n = ir_operands_count(ctx, insn);
|
||||||
n = 1 + (n >> 2); // support for multi-word instructions like MERGE and PHI
|
n = 1 + (n >> 2); // support for multi-word instructions like MERGE and PHI
|
||||||
prev = i;
|
|
||||||
i += n;
|
i += n;
|
||||||
insn += n;
|
insn += n;
|
||||||
}
|
}
|
||||||
ctx->prev_ref[i] = prev;
|
|
||||||
}
|
}
|
||||||
ctx->vregs_count = vregs_count;
|
ctx->vregs_count = vregs_count;
|
||||||
ctx->vregs = vregs;
|
ctx->vregs = vregs;
|
||||||
|
Loading…
Reference in New Issue
Block a user