diff options
| author | 2023-06-01 13:01:11 +0200 | |
|---|---|---|
| committer | 2023-06-01 13:01:11 +0200 | |
| commit | a98075934ece8c7ff351f8449f6515c12b9feec8 (patch) | |
| tree | 05ee8b8f4e6119b693b2460b4761cf3166b79637 /regalloc.c | |
| parent | 82cac0ae5d4e335719445857ab16ffdf05413222 (diff) | |
struct args and return
Diffstat (limited to 'regalloc.c')
| -rw-r--r-- | regalloc.c | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -6,6 +6,13 @@ extern vec_of(struct phi) phis; static struct bitset taken[1]; +static void +def(struct instr *ins) +{ + if (ins->reg) + bsclr(taken, ins->reg - 1); +} + static int nextreg(enum irclass cls) { @@ -31,7 +38,7 @@ static void use(struct block *blk, enum op op, int hint, union ref *ref) { struct instr *ins; - if (ref->t == REXT) { + if (ref->t == RMORE) { if (op == Ocall) { struct call *call = &calls.p[ref->idx]; for (int i = 0; i < call->narg; ++i) @@ -52,17 +59,17 @@ use(struct block *blk, enum op op, int hint, union ref *ref) /* result of comparison instr is only used to conditionally branch, * doesn't usually need a reg (handled by isel) */ return; - ins->reg = hint ? hint : nextreg(ins->cls); + ins->reg = (hint ? hint : nextreg(ins->cls)) + 1; } } void regalloc(struct function *fn) { - struct block *blk = fn->entry->lprev; struct instr *ins; + struct block *last = fn->entry->lprev, *blk = last; - /* a dumb linear register allocator that visits instructions backwards + /* a dumb linear register allocator that visits instructions physically backwards * starting at the end of the function, when encountering a use of a new * temporary, it allocates a register for it. when encountering the definition * of a temporary, it frees up its register @@ -71,18 +78,17 @@ regalloc(struct function *fn) if (blk->jmp.arg.t) use(blk, blk->jmp.t == Jbcnd ? -1 : 0, 0, &blk->jmp.arg); for (int i = blk->phi.n - 1; i >= 0; --i) { ins = &instr[blk->phi.p[i]]; - bsclr(taken, ins->reg); + def(ins); assert(ins->op == Ophi); use(blk, Ophi, ins->reg, &ins->l); } for (int i = blk->ins.n - 1; i >= 0; --i) { ins = &instr[blk->ins.p[i]]; - bsclr(taken, ins->reg); + def(ins); if (ins->l.t) use(blk, ins->op, 0, &ins->l); if (ins->r.t) use(blk, ins->op, 0, &ins->r); } - blk = blk->lprev; - } while (blk != fn->entry->lprev); + } while ((blk = blk->lprev) != last); } /* vim:set ts=3 sw=3 expandtab: */ |