From 19bbdfa3c7ae05f4694ce5e434d9855c6f2c3682 Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 24 Jun 2023 18:47:05 +0200 Subject: backend: fix regalloc to work with more complex dataflow basically an allocation map at the beginning (in) and end (out) of each block is kept and after the first allocation pass another pass is ran to resolve allocation conflicts between each edge, plus another pass to finish lowering phi functions. also introduced `regset` and plenty of other miscellaneous fixes --- ssa.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'ssa.c') diff --git a/ssa.c b/ssa.c index 4ce8774..4a4ed4d 100644 --- a/ssa.c +++ b/ssa.c @@ -1,6 +1,29 @@ #include "common.h" #include "ir.h" +/* require use, keeps use */ +void +copyopt(struct function *fn) +{ + struct block *blk = fn->entry; + + do { + for (int i = 0; i < blk->ins.n; ++i) { + struct use *use, *uend; + union ref var = mkref(RTMP, blk->ins.p[i]); + struct instr *ins = &instrtab[var.i]; + + if (ins->op == Ocopy) { + assert(ins->l.t != RREG); + + replcuses(var, ins->l); + *ins = mkinstr(Onop,0,); + deluses(var.i); + } + } + } while ((blk = blk->lnext) != fn->entry); +} + void filluses(struct function *fn) { -- cgit v1.2.3