summary refs log tree commit diff
path: root/lisc
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-10-27 20:39:13 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-10-30 13:20:42 -0400
commitd95c8f296b6f68f413fed283b3c40715e15e298b (patch)
treec7d480a8474da19ab0af3301603033941f5873fb /lisc
parent27bcd5a3c66abab40293a52794f22ce644fe9c7e (diff)
downloadroux-d95c8f296b6f68f413fed283b3c40715e15e298b.tar.gz
fix several bugs on Blk.gen in liveness
Diffstat (limited to 'lisc')
-rw-r--r--lisc/live.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/lisc/live.c b/lisc/live.c
index 57e7533..0e59d78 100644
--- a/lisc/live.c
+++ b/lisc/live.c
@@ -19,18 +19,10 @@ liveon(Blk *b, Blk *s)
 }
 
 static void
-bset(Ref r, Blk *b, int *nlv, short *phi, Tmp *tmp)
+phifix(int t1, short *phi, Tmp *tmp)
 {
-	int t, t1, t2;
+	int t, t2;
 
-	if (rtype(r) != RTmp)
-		return;
-	t1 = r.val;
-	BSET(b->gen, t1);
-	if (!BGET(b->in, t1)) {
-		++*nlv;
-		BSET(b->in, t1);
-	}
 	/* detect temporaries in the same
 	 * phi-class that interfere and
 	 * separate them
@@ -38,14 +30,31 @@ bset(Ref r, Blk *b, int *nlv, short *phi, Tmp *tmp)
 	t = phirepr(tmp, t1);
 	t2 = phi[t];
 	if (t2 && t2 != t1) {
-		if (tmp[t1].phi != t1)
+		if (tmp[t1].phi != t1) {
 			tmp[t1].phi = t1;
-		else
+			t = t1;
+		} else {
 			tmp[t2].phi = t2;
+			phi[t2] = t2;
+		}
 	}
 	phi[t] = t1;
 }
 
+static void
+bset(Ref r, Blk *b, int *nlv, short *phi, Tmp *tmp)
+{
+
+	if (rtype(r) != RTmp)
+		return;
+	BSET(b->gen, r.val);
+	phifix(r.val, phi, tmp);
+	if (!BGET(b->in, r.val)) {
+		++*nlv;
+		BSET(b->in, r.val);
+	}
+}
+
 /* liveness analysis
  * requires rpo computation
  */
@@ -85,11 +94,11 @@ Again:
 		chg |= memcmp(&b->out, &u, sizeof(Bits));
 
 		memset(phi, 0, f->ntmp * sizeof phi[0]);
-		b->in = (Bits){{0}};
-		nlv = 0;
+		b->in = b->out;
+		nlv = bcnt(&b->in);
 		for (t=0; t<f->ntmp; t++)
-			if (BGET(b->out, t))
-				bset(TMP(t), b, &nlv, phi, f->tmp);
+			if (BGET(b->in, t))
+				phifix(t, phi, f->tmp);
 		bset(b->jmp.arg, b, &nlv, phi, f->tmp);
 		b->nlive = nlv;
 		for (i=&b->ins[b->nins]; i!=b->ins;) {
@@ -104,6 +113,7 @@ Again:
 			if (!req(i->to, R)) {
 				assert(rtype(i->to) == RTmp);
 				nlv -= BGET(b->in, i->to.val);
+				BSET(b->gen, i->to.val);
 				BCLR(b->in, i->to.val);
 				t = phirepr(f->tmp, i->to.val);
 				phi[t] = 0;
@@ -136,6 +146,8 @@ Again:
 			dumpts(&b->in, f->tmp, stderr);
 			fprintf(stderr, "\t          out:  ");
 			dumpts(&b->out, f->tmp, stderr);
+			fprintf(stderr, "\t          gen:  ");
+			dumpts(&b->gen, f->tmp, stderr);
 			fprintf(stderr, "\t          live: %d\n", b->nlive);
 		}
 	}