commit 935ab611f0fd841f4f7e54c95ea2e57bba44f8ab
parent 1d62b4bf478a17d7b825bb0064a50dba570dfe01
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date: Fri, 10 Jul 2015 11:41:11 -0400
add predecessor computation
Diffstat:
3 files changed, 51 insertions(+), 3 deletions(-)
diff --git a/lisc/lisc.h b/lisc/lisc.h
@@ -88,7 +88,9 @@ struct Blk {
Blk *s2;
char name[NString];
- int rpo;
+ Blk *link;
+ Blk **preds;
+ int npreds;
};
struct Sym {
@@ -110,4 +112,8 @@ struct Fn {
/* parse.c */
+void *alloc(size_t);
Fn *parsefn(FILE *);
+
+/* ssa.c */
+void fillpreds(Fn *);
diff --git a/lisc/parse.c b/lisc/parse.c
@@ -53,6 +53,7 @@ static struct {
Blk *blk;
} bmap[NBlks+1];
static Blk *curb;
+static Blk **blink;
static struct {
long long num;
@@ -200,6 +201,8 @@ blocka()
b = alloc(sizeof *b);
*b = zblock;
+ *blink = b;
+ blink = &b->link;
return b;
}
@@ -441,8 +444,8 @@ parsefn(FILE *f)
curb = 0;
lnum = 1;
fn = alloc(sizeof *fn);
- ps = parseline(PLbl);
- fn->start = curb; /* todo, it's a hack */
+ blink = &fn->start;
+ ps = PLbl;
do
ps = parseline(ps);
while (ps != PEnd);
diff --git a/lisc/ssa.c b/lisc/ssa.c
@@ -0,0 +1,39 @@
+#include "lisc.h"
+
+static void
+addpred(Blk *bp, Blk *bc)
+{
+ int i;
+
+ if (!bc->preds) {
+ bc->preds = alloc(bc->npreds * sizeof(Blk*));
+ for (i=0; i<bc->npreds; i++)
+ bc->preds[i] = 0;
+ }
+ for (i=0; bc->preds[i]; i++)
+ ;
+ bc->preds[i] = bp;
+}
+
+void
+fillpreds(Fn *f)
+{
+ Blk *b;
+
+ for (b=f->start; b; b=b->link) {
+ b->npreds = 0;
+ free(b->preds);
+ }
+ for (b=f->start; b; b=b->link) {
+ if (b->s1)
+ b->s1->npreds++;
+ if (b->s2)
+ b->s2->npreds++;
+ }
+ for (b=f->start; b; b=b->link) {
+ if (b->s1)
+ addpred(b, b->s1);
+ if (b->s2)
+ addpred(b, b->s2);
+ }
+}