commit 03785fbc9a3f786ad49f2bc77518e739a7d4b469
parent 44329afff582b3e6a45421cf8b29e1bb98f2ed5b
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date: Mon, 10 Aug 2015 10:02:07 -0400
use round-robin in ralloc
This gives a more uniform use of the registers.
Diffstat:
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/lisc/rega.c b/lisc/rega.c
@@ -72,7 +72,8 @@ radd(RMap *m, int t, int r)
static Ref
ralloc(RMap *m, int t)
{
- int r;
+ static int x;
+ int n, r;
if (BGET(m->bt, t)) {
r = rfind(m, t);
@@ -80,8 +81,13 @@ ralloc(RMap *m, int t)
} else {
r = tmp[t].hint;
if (r == -1 || BGET(m->br, r))
- for (r=RAX; BGET(m->br, r); r++)
- ;
+ for (n=0;; x=(x+1)%NReg, n++) {
+ if (n > NReg)
+ diag("rega: no more regs");
+ r = RAX + x;
+ if (!BGET(m->br, r))
+ break;
+ }
radd(m, t, r);
if (tmp[t].hint == -1)
tmp[t].hint = r;
@@ -294,9 +300,9 @@ rega(Fn *fn)
cur.bt = (Bits){{0}};
cur.br = (Bits){{0}};
b1 = b;
- if (b->s1 && b1->loop < b->s1->loop)
+ if (b->s1 && b1->loop <= b->s1->loop)
b1 = b->s1;
- if (b->s2 && b1->loop < b->s2->loop)
+ if (b->s2 && b1->loop <= b->s2->loop)
b1 = b->s1;
/* try to reuse the register
* assignment of the most frequent