summary refs log tree commit diff
path: root/lisc
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-03-18 10:54:52 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-03-18 10:54:52 -0400
commita93af73ff296cb740d750e0101198ce748d29cfd (patch)
tree839536f6f4d62c1f764f0b2a37c9a1e79a33f2ec /lisc
parent73371a0f906916f18e2b9a085f8b49bdbfbbda06 (diff)
downloadroux-a93af73ff296cb740d750e0101198ce748d29cfd.tar.gz
factor return registers computation
Diffstat (limited to 'lisc')
-rw-r--r--lisc/isel.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/lisc/isel.c b/lisc/isel.c
index 53f98be..b0b1446 100644
--- a/lisc/isel.c
+++ b/lisc/isel.c
@@ -425,12 +425,24 @@ blit(Ref rstk, uint soff, Ref rsrc, uint sz, Fn *fn)
 }
 
 static void
-selret(Blk *b, Fn *fn)
+retr(Ref reg[2], AClass *aret)
 {
 	static int retreg[2][2] = {{RAX, RDX}, {XMM0, XMM0+1}};
-	int j, n, k, nr[2];
+	int n, k, nr[2];
+
+	nr[0] = nr[1] = 0;
+	for (n=0; n<2; n++) {
+		k = KBASE(aret->cls[n]);
+		reg[n] = TMP(retreg[k][nr[k]++]);
+	}
+}
+
+static void
+selret(Blk *b, Fn *fn)
+{
+	int j, k;
 	Ref r, r0, reg[2];
-	AClass a;
+	AClass aret;
 
 	j = b->jmp.type;
 
@@ -442,20 +454,15 @@ selret(Blk *b, Fn *fn)
 	b->jmp.type = JRet0;
 
 	if (j == JRetc) {
-		aclass(&a, &typ[fn->retty]);
-		b->jmp.type = JRet0;
-		if (a.inmem) {
+		aclass(&aret, &typ[fn->retty]);
+		if (aret.inmem) {
 			assert(rtype(fn->retr) == RTmp);
 			emit(OCopy, Kl, TMP(RAX), fn->retr, R);
 			chuse(fn->retr, +1, fn);
-			blit(fn->retr, 0, r0, a.size, fn);
+			blit(fn->retr, 0, r0, aret.size, fn);
 		} else {
-			nr[0] = nr[1] = 0;
-			for (n=0; n<2; n++) {
-				k = KBASE(a.cls[n]);
-				reg[n] = TMP(retreg[k][nr[k]++]);
-			}
-			if (a.size > 8) {
+			retr(reg, &aret);
+			if (aret.size > 8) {
 				r = newtmp("abi", Kl, fn);
 				emit(OLoad, Kl, reg[1], r, R);
 				emit(OAdd, Kl, r, r0, getcon(8, fn));