summary refs log tree commit diff
path: root/lisc/ssa.c
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-25 13:02:39 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-25 13:02:44 -0400
commitf3bd48945ee0c3147bd8ed2a6cffbeb447948cf5 (patch)
tree7b8a43bebe3b69a4f8d872b4219b1ad514fab6c8 /lisc/ssa.c
parent08a2ffe8c4711e94ecd7b44952babc28e00a960f (diff)
downloadroux-f3bd48945ee0c3147bd8ed2a6cffbeb447948cf5.tar.gz
add union-find based phi-class computation
Diffstat (limited to 'lisc/ssa.c')
-rw-r--r--lisc/ssa.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/lisc/ssa.c b/lisc/ssa.c
index 9002443..9608a93 100644
--- a/lisc/ssa.c
+++ b/lisc/ssa.c
@@ -89,6 +89,52 @@ fillrpo(Fn *f)
 	}
 }
 
+/* gets the representant for the phi class of t
+ */
+int
+phirepr(Tmp *tmp, int t)
+{
+	int tp;
+
+	tp = tmp[t].phi;
+	if (tp == 0)
+		tp = t;
+	else if (tp != t) {
+		tp = phirepr(tmp, tp);
+		tmp[t].phi = tp;
+	}
+	return tp;
+}
+
+/* fill union find data for phi classes
+ */
+void
+fillphi(Fn *fn)
+{
+	Blk *b;
+	Phi *p;
+	uint a;
+	int t, ta;
+	Tmp *tmp;
+
+	tmp = fn->tmp;
+	for (t=Tmp0; t<fn->ntmp; t++)
+		tmp[t].phi = 0;
+	for (b=fn->start; b; b=b->link)
+		for (p=b->phi; p; p=p->link) {
+			t = p->to.val;
+			if (tmp[t].phi == 0)
+				tmp[t].phi = t;
+			for (a=0; a<p->narg; a++) {
+				if (rtype(p->arg[a]) != RTmp)
+					continue;
+				ta = p->arg[a].val;
+				ta = phirepr(tmp, ta);
+				tmp[ta].phi = t;
+			}
+		}
+}
+
 static Ref *top, *bot;
 static Ref topdef(Blk *, Fn *, int);