summaryrefslogtreecommitdiff
path: root/opt
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2012-06-14 00:17:26 -0400
committerOri Bernstein <ori@eigenstate.org>2012-06-14 00:17:26 -0400
commit26d8da9a31adeabfa59d3a2ed06ad13206c94356 (patch)
treefdd5347de80174c93399a3d913ee6131dfe2f9a1 /opt
parent6a7f16a2b8e1be9639a79726d8195fc6cfae27f1 (diff)
downloadmc-26d8da9a31adeabfa59d3a2ed06ad13206c94356.tar.gz
Make the BB ids identity mapped with their index.
bb->id should be equal to cfg->bb[bb->id]->id, so that we can look up the BB from the pred/succ sets directly.
Diffstat (limited to 'opt')
-rw-r--r--opt/cfg.c10
-rw-r--r--opt/opt.h1
2 files changed, 9 insertions, 2 deletions
diff --git a/opt/cfg.c b/opt/cfg.c
index 209a1fa..ce362a0 100644
--- a/opt/cfg.c
+++ b/opt/cfg.c
@@ -16,11 +16,10 @@
static Bb *mkbb(Cfg *cfg)
{
- static int nextbbid = 0;
Bb *bb;
bb = zalloc(sizeof(Bb));
- bb->id = nextbbid++;
+ bb->id = cfg->nextbbid++;
bb->pred = mkbs();
bb->succ = mkbs();
lappend(&cfg->bb, &cfg->nbb, bb);
@@ -53,12 +52,14 @@ static int addnode(Cfg *cfg, Bb *bb, Node *n)
Cfg *mkcfg(Node **nl, size_t nn)
{
Cfg *cfg;
+ Bb *pre, *post;
Bb *bb, *targ;
Node *a, *b;
size_t i;
cfg = zalloc(sizeof(Cfg));
cfg->lblmap = mkht(strhash, streq);
+ pre = mkbb(cfg);
bb = mkbb(cfg);
for (i = 0; i < nn; i++) {
switch (nl[i]->type) {
@@ -82,6 +83,11 @@ Cfg *mkcfg(Node **nl, size_t nn)
die("Invalid node type %s in mkcfg", nodestr(nl[i]->type));
}
}
+ post = mkbb(cfg);
+ bsput(pre->succ, cfg->bb[1]->id);
+ bsput(cfg->bb[1]->pred, pre->id);
+ bsput(post->succ, cfg->bb[cfg->nbb - 2]->id);
+ bsput(cfg->bb[cfg->nbb - 2]->pred, post->id);
for (i = 0; i < cfg->nfixjmp; i++) {
bb = cfg->fixblk[i];
switch (exprop(cfg->fixjmp[i])) {
diff --git a/opt/opt.h b/opt/opt.h
index d8b2922..745dea1 100644
--- a/opt/opt.h
+++ b/opt/opt.h
@@ -6,6 +6,7 @@ struct Cfg {
size_t nbb;
/* for building bb */
+ int nextbbid;
Htab *lblmap; /* label => Bb mapping */
Node **fixjmp;
size_t nfixjmp;