summary refs log tree commit diff
path: root/cfg.c
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-12-21 09:56:40 -0500
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-12-21 09:56:40 -0500
commit3c3afdc896be4de996d7486e40e7b81488b745b9 (patch)
treeee630a1d0754103dd726fc06cd50ea2cb2134e9b /cfg.c
parentd04ba5eae886ce4e5407ccd711fb1c9846dcf1f7 (diff)
downloadroux-3c3afdc896be4de996d7486e40e7b81488b745b9.tar.gz
schedule loop nesting computations earlier
Diffstat (limited to 'cfg.c')
-rw-r--r--cfg.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/cfg.c b/cfg.c
index ae54deb..bebf0fa 100644
--- a/cfg.c
+++ b/cfg.c
@@ -228,3 +228,50 @@ fillfron(Fn *fn)
 				addfron(a, b->s2);
 	}
 }
+
+static void
+loopmark(Blk *hd, Blk *b, void f(Blk *, Blk *))
+{
+	uint p;
+
+	if (b->id < hd->id || b->visit == hd->id)
+		return;
+	b->visit = hd->id;
+	f(hd, b);
+	for (p=0; p<b->npred; ++p)
+		loopmark(hd, b->pred[p], f);
+}
+
+void
+loopiter(Fn *fn, void f(Blk *, Blk *))
+{
+	int n;
+	uint p;
+	Blk *b;
+
+	for (b=fn->start; b; b=b->link)
+		b->visit = -1;
+	for (n=0; n<fn->nblk; ++n) {
+		b = fn->rpo[n];
+		for (p=0; p<b->npred; ++p)
+			if (b->pred[p]->id >= n)
+				loopmark(b, b->pred[p], f);
+	}
+}
+
+void
+multloop(Blk *hd, Blk *b)
+{
+	(void)hd;
+	b->loop *= 10;
+}
+
+void
+fillloop(Fn *fn)
+{
+	Blk *b;
+
+	for (b=fn->start; b; b=b->link)
+		b->loop = 1;
+	loopiter(fn, multloop);
+}