From 935ab611f0fd841f4f7e54c95ea2e57bba44f8ab Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Fri, 10 Jul 2015 11:41:11 -0400 Subject: add predecessor computation --- lisc/ssa.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lisc/ssa.c (limited to 'lisc/ssa.c') diff --git a/lisc/ssa.c b/lisc/ssa.c new file mode 100644 index 0000000..6f28634 --- /dev/null +++ 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; inpreds; 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); + } +} -- cgit 1.4.1