summary refs log tree commit diff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-11-11 21:21:54 -0500
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-11-11 21:21:54 -0500
commita3a1fc0c8025117139d5e8e6ba4c88ecbe978981 (patch)
tree80cc3c54799644cb8587aa41f94fec4904000b1e
parentd3f1cd94833b33c2817312dfd67100693987083f (diff)
downloadroux-a3a1fc0c8025117139d5e8e6ba4c88ecbe978981.tar.gz
move usage computation in filluse()
-rw-r--r--lisc/lisc.h1
-rw-r--r--lisc/main.c4
-rw-r--r--lisc/parse.c16
-rw-r--r--lisc/ssa.c47
4 files changed, 54 insertions, 14 deletions
diff --git a/lisc/lisc.h b/lisc/lisc.h
index 0179cde..5748587 100644
--- a/lisc/lisc.h
+++ b/lisc/lisc.h
@@ -357,6 +357,7 @@ void parse(FILE *, void (Dat *), void (Fn *));
 void printfn(Fn *, FILE *);
 
 /* ssa.c */
+void filluse(Fn *);
 void fillpreds(Fn *);
 void fillrpo(Fn *);
 void ssa(Fn *);
diff --git a/lisc/main.c b/lisc/main.c
index da56729..e91d65e 100644
--- a/lisc/main.c
+++ b/lisc/main.c
@@ -49,8 +49,9 @@ func(Fn *fn)
 	}
 	fillrpo(fn);
 	fillpreds(fn);
+	filluse(fn);
 	ssa(fn);
-#if 0
+	filluse(fn);
 	isel(fn);
 	filllive(fn);
 	fillcost(fn);
@@ -69,7 +70,6 @@ func(Fn *fn)
 		printf("/* end function %s */\n\n", fn->name);
 	} else
 		fprintf(stderr, "\n");
-#endif
 	freeall();
 }
 
diff --git a/lisc/parse.c b/lisc/parse.c
index fa3194f..231f90c 100644
--- a/lisc/parse.c
+++ b/lisc/parse.c
@@ -299,18 +299,15 @@ expect(int t)
 }
 
 static Ref
-tmpref(char *v, int use)
+tmpref(char *v)
 {
 	int t;
 
 	for (t=Tmp0; t<ntmp; t++)
 		if (strcmp(v, tmp[t].name) == 0)
-			goto Found;
+			return TMP(t);
 	vgrow(&tmp, ++ntmp);
 	strcpy(tmp[t].name, v);
-Found:
-	tmp[t].ndef += !use;
-	tmp[t].nuse += use;
 	return TMP(t);
 }
 
@@ -322,7 +319,7 @@ parseref()
 
 	switch (next()) {
 	case TTmp:
-		return tmpref(tokval.str, 1);
+		return tmpref(tokval.str);
 	case TNum:
 		c = (Con){.type = CNum, .val = tokval.num};
 		strcpy(c.label, "");
@@ -509,7 +506,7 @@ parseline(PState ps)
 		closeblk();
 		return PLbl;
 	}
-	r = tmpref(tokval.str, 0);
+	r = tmpref(tokval.str);
 	expect(TEq);
 	w = parsecls(&ty);
 	op = next();
@@ -547,10 +544,6 @@ DoOp:
 			arg[i] = parseref();
 			if (req(arg[i], R))
 				err("invalid instruction argument");
-			if (op == -1)
-			if (rtype(arg[i]) == RTmp)
-			if (!tmp[arg[i].val].phi)
-				tmp[arg[i].val].phi = r.val;
 			i++;
 			t = peek();
 			if (t == TNL)
@@ -572,7 +565,6 @@ DoOp:
 		curi++;
 		return PIns;
 	} else {
-		tmp[r.val].phi = r.val;
 		phi = alloc(sizeof *phi);
 		phi->to = r;
 		phi->wide = w;
diff --git a/lisc/ssa.c b/lisc/ssa.c
index 521aa38..d628f15 100644
--- a/lisc/ssa.c
+++ b/lisc/ssa.c
@@ -1,5 +1,52 @@
 #include "lisc.h"
 
+/* fill usage and phi information
+ */
+void
+filluse(Fn *fn)
+{
+	Blk *b;
+	Phi *p;
+	Ins *i;
+	int t;
+	uint a;
+	Tmp *tmp;
+
+	/* todo, is this the correct file? */
+	tmp = fn->tmp;
+	for (t=0; t<fn->ntmp; t++) {
+		tmp[t].ndef = 0;
+		tmp[t].nuse = 0;
+		tmp[t].phi = 0;
+	}
+	for (b=fn->start; b; b=b->link) {
+		for (p=b->phi; p; p=p->link) {
+			assert(rtype(p->to) == RTmp);
+			tmp[p->to.val].ndef++;
+			tmp[p->to.val].phi = p->to.val;
+			for (a=0; a<p->narg; a++)
+				if (rtype(p->arg[a]) == RTmp) {
+					t = p->arg[a].val;
+					tmp[t].nuse++;
+					if (!tmp[t].phi)
+						tmp[t].phi = p->to.val;
+				}
+		}
+		for (i=b->ins; i!=&b->ins[b->nins]; i++) {
+			if (!req(i->to, R)) {
+				assert(rtype(i->to) == RTmp);
+				tmp[i->to.val].ndef++;
+			}
+			if (rtype(i->arg[0]) == RTmp)
+				tmp[i->arg[0].val].nuse++;
+			if (rtype(i->arg[1]) == RTmp)
+				tmp[i->arg[1].val].nuse++;
+		}
+		if (rtype(b->jmp.arg) == RTmp)
+			tmp[b->jmp.arg.val].nuse++;
+	}
+}
+
 static void
 addpred(Blk *bp, Blk *bc)
 {