summaryrefslogtreecommitdiff
path: root/opt
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2012-06-11 13:07:43 -0400
committerOri Bernstein <ori@eigenstate.org>2012-06-11 13:07:43 -0400
commit5cf89f06e6dc31901b495ad16adc1cd93f586ebf (patch)
treeccc7cedb55d44ea1aa5e8ab00c4d84b35a38f5bb /opt
parent3c8b80689e43668ae45177cd22d042407757ab02 (diff)
downloadmc-5cf89f06e6dc31901b495ad16adc1cd93f586ebf.tar.gz
More work towards getting dataflow going.
This commit temporarily breaks things.
Diffstat (limited to 'opt')
-rw-r--r--opt/df.c77
-rw-r--r--opt/opt.h2
2 files changed, 77 insertions, 2 deletions
diff --git a/opt/df.c b/opt/df.c
index c19059d..08b864c 100644
--- a/opt/df.c
+++ b/opt/df.c
@@ -27,6 +27,12 @@ Bb *mkbb(Cfg *cfg)
return bb;
}
+void label(Cfg *cfg, Node *lbl, Bb *bb)
+{
+ htput(cfg->lblmap, lbl->lbl.name, bb);
+ lappend(&bb->lbls, &bb->nlbls, lbl->lbl.name);
+}
+
int addnode(Cfg *cfg, Bb *bb, Node *n)
{
switch (exprop(n)) {
@@ -47,16 +53,19 @@ int addnode(Cfg *cfg, Bb *bb, Node *n)
Cfg *mkcfg(Node **nl, int nn)
{
Cfg *cfg;
- Bb *bb;
+ Bb *bb, *targ;
+ Node *a, *b;
int i;
cfg = zalloc(sizeof(Cfg));
+ cfg->lblmap = mkht(strhash, streq);
+ bb = mkbb(cfg);
for (i = 0; i < nn; i++) {
switch (nl[i]->type) {
case Nlbl:
if (bb->nnl)
bb = mkbb(cfg);
- lappend(&bb->lbls, &bb->nlbls, nl[i]->lbl.name);
+ label(cfg, nl[i], bb);
break;
case Nexpr:
if (addnode(cfg, bb, nl[i]))
@@ -68,5 +77,69 @@ Cfg *mkcfg(Node **nl, int nn)
die("Invalid node type %s in mkcfg", nodestr(nl[i]->type));
}
}
+ for (i = 0; i < cfg->nfixjmp; i++) {
+ bb = cfg->fixblk[i];
+ switch (exprop(cfg->fixjmp[i])) {
+ case Ojmp:
+ a = cfg->fixjmp[i]->expr.args[0];
+ b = NULL;
+ break;
+ case Ocjmp:
+ a = cfg->fixjmp[i]->expr.args[0];
+ b = cfg->fixjmp[i]->expr.args[1];
+ break;
+ default:
+ die("Bad jump fix thingy");
+ break;
+ }
+ if (a) {
+ targ = htget(cfg->lblmap, a->lbl.name);
+ if (!targ)
+ die("No bb with label %s", a->lbl.name);
+ bsput(bb->out, targ->id);
+ bsput(targ->in, bb->id);
+ }
+ if (b) {
+ targ = htget(cfg->lblmap, b->lbl.name);
+ if (!targ)
+ die("No bb with label %s", b->lbl.name);
+ bsput(bb->out, targ->id);
+ bsput(targ->in, bb->id);
+ }
+ }
return cfg;
}
+void dumpcfg(Cfg *cfg, FILE *fd)
+{
+ int i, j;
+ Bb *bb;
+ char *sep;
+
+ for (j = 0; j < cfg->nbb; j++) {
+ bb = cfg->bb[j];
+ fprintf(fd, "Bb: %d\n", bb->id);
+
+ /* in edges */
+ fprintf(fd, "In: ");
+ sep = "";
+ for (i = 0; i < bsmax(bb->in); i++) {
+ if (bshas(bb->in, i))
+ fprintf(fd, "%d%s", i, sep);
+ sep = ",";
+ }
+ fprintf(fd, "\n");
+
+ /* out edges */
+ fprintf(fd, "Out: ");
+ sep = "";
+ for (i = 0; i < bsmax(bb->out); i++) {
+ if (bshas(bb->in, i))
+ fprintf(fd, "%d%s", i, sep);
+ sep = ",";
+ }
+ fprintf(fd, "\n");
+
+ for (i = 0; i < bb->nnl; i++)
+ dump(bb->nl[i], fd);
+ }
+}
diff --git a/opt/opt.h b/opt/opt.h
index cbdd63e..dbf7dce 100644
--- a/opt/opt.h
+++ b/opt/opt.h
@@ -6,6 +6,7 @@ struct Cfg {
size_t nbb;
/* for building bb */
+ Htab *lblmap; /* label => Bb mapping */
Node **fixjmp;
size_t nfixjmp;
Bb **fixblk;
@@ -24,4 +25,5 @@ struct Bb {
/* Takes a reduced block, and returns a flow graph. */
Cfg *mkcfg(Node **nl, int nn);
+void dumpcfg(Cfg *c, FILE *fd);
void flow(Cfg *cfg);