summary refs log tree commit diff
path: root/lisc/rega.c
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-08-10 10:02:07 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:31 -0400
commit03785fbc9a3f786ad49f2bc77518e739a7d4b469 (patch)
treec71e4668b89ae653418d909876ef6ead88a716ed /lisc/rega.c
parent44329afff582b3e6a45421cf8b29e1bb98f2ed5b (diff)
downloadroux-03785fbc9a3f786ad49f2bc77518e739a7d4b469.tar.gz
use round-robin in ralloc
This gives a more uniform use of the registers.
Diffstat (limited to 'lisc/rega.c')
-rw-r--r--lisc/rega.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/lisc/rega.c b/lisc/rega.c
index 98fe711..b1eabcb 100644
--- 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