From e043811980db560fc2507bb53b644e54c80527dc Mon Sep 17 00:00:00 2001 From: lemon Date: Mon, 8 Sep 2025 22:05:33 +0200 Subject: regalloc: start implementing linear scan --- ir.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'ir.c') diff --git a/ir.c b/ir.c index 06d5409..2f65192 100644 --- a/ir.c +++ b/ir.c @@ -1,5 +1,4 @@ #include "ir.h" -#include "endian.h" #include "obj.h" uchar type2cls[NTYPETAG]; @@ -13,6 +12,13 @@ const char *opnames[] = { #undef _ }; +const uchar opnarg[] = { + 0, +#define _(o,n) n, +#include "op.def" +#undef _ +}; + struct instr instrtab[MAXINSTR]; struct use *instruse[MAXINSTR]; short instrnuse[MAXINSTR]; @@ -362,6 +368,17 @@ insertphi(struct block *blk, enum irclass cls) return mkref(RTMP, new); } +void +numberinstrs(struct function *fn) +{ + struct block *blk = fn->entry; + int start = 0; + do { + blk->inumstart = start; + start += blk->ins.n+2; + } while ((blk = blk->lnext) != fn->entry); +} + /* require use */ void replcuses(union ref from, union ref to) @@ -387,7 +404,6 @@ replcuses(union ref from, union ref to) if (u[j].bits == from.bits) { u[j].bits = to.bits; adduse(use.blk, use.u, to); - deluse(use.blk, use.u, from); --i; break; } @@ -411,7 +427,7 @@ delinstr(struct block *blk, int idx) memcpy(&instrtab[t], &instrfreelist, sizeof(int)); instrfreelist = t; deluses(t); - for (int i = idx; i < blk->ins.n; ++i) + for (int i = idx; i < blk->ins.n-1; ++i) blk->ins.p[i] = blk->ins.p[i + 1]; --blk->ins.n; } -- cgit v1.2.3