From 1721fe43137e54e05a62663235a5a8cebb7f4761 Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Sat, 8 Aug 2015 00:18:31 -0400 Subject: fix a bug in setloc The way we detected if limit had spilled a variable was incorrect. This is because two consecutive calls to limit could require a spill of the same variable. Instead, we now use a return value from limit. Note that this is still not so ideal. Indeed, it works properly only when limit spills one value only, if not, we should return a bitset. In the current use scheme of limit, this invariant is true but ideally we would like to call limit with *all arguments added at once*, not one after the other. --- lisc/spill.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'lisc') diff --git a/lisc/spill.c b/lisc/spill.c index 7361b11..ca7d962 100644 --- a/lisc/spill.c +++ b/lisc/spill.c @@ -184,16 +184,15 @@ emit(short op, Ref to, Ref arg0, Ref arg1) *--curi = (Ins){op, to, {arg0, arg1}}; } -static Bits +static int limit(Bits *b, int k, Bits *fst) { static int *tarr, maxt; int i, t, nt; - Bits res; nt = bcnt(b); if (nt <= k) - return *b; + return 0; if (nt > maxt) { free(tarr); tarr = alloc(nt * sizeof tarr[0]); @@ -201,8 +200,10 @@ limit(Bits *b, int k, Bits *fst) } i = 0; for (t=0; tval; BSET(*v, t); - *v = limit(v, nreg, w); - if (curi->op == OLoad) - if (curi->to.val == t) + if (limit(v, nreg, w) == t) /* if t was spilled by limit, * it was not live so we don't * have to reload it */ @@ -313,11 +313,11 @@ spill(Fn *fn) for (z=0; z NReg) - v = limit(&v, NReg, 0); + limit(&v, NReg, 0); } else if (s1) { v = s1->in; w = s1->in; @@ -327,7 +327,7 @@ spill(Fn *fn) w.t[z] &= s2->in.t[z]; } assert(bcnt(&w) <= NReg); - v = limit(&v, NReg, &w); + limit(&v, NReg, &w); } b->out = v; assert(bcnt(&v) <= NReg); @@ -347,7 +347,7 @@ spill(Fn *fn) if (BGET(v, j)) BCLR(v, j); else - v = limit(&v, nreg-1, &w); + limit(&v, nreg-1, &w); s = tmp[j].spill; break; case RReg: @@ -356,13 +356,13 @@ spill(Fn *fn) BCLR(br, j); nreg++; } else - v = limit(&v, nreg-1, &w); + limit(&v, nreg-1, &w); break; case -1:; } w = (Bits){{0}}; - setloc(&i->arg[1], &v, &w); setloc(&i->arg[0], &v, &w); + setloc(&i->arg[1], &v, &w); if (s) emit(OStore, R, i->to, SLOT(s)); emit(i->op, i->to, i->arg[0], i->arg[1]); -- cgit 1.4.1