ref: 26d8da9a31adeabfa59d3a2ed06ad13206c94356
parent: 6a7f16a2b8e1be9639a79726d8195fc6cfae27f1
author: Ori Bernstein <[email protected]>
date: Wed Jun 13 20:17:26 EDT 2012
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.
--- a/8/isel.c
+++ b/8/isel.c
@@ -615,6 +615,8 @@
case 't':
modeidx = 0;
default:
+ /* the asm description uses 1-based indexing, so that 0
+ * can be used as a sentinel. */
if (isdigit(*p))
modeidx = strtol(p, &p, 10) - 1;
--- 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,6 +52,7 @@
Cfg *mkcfg(Node **nl, size_t nn)
{
Cfg *cfg;
+ Bb *pre, *post;
Bb *bb, *targ;
Node *a, *b;
size_t i;
@@ -59,6 +59,7 @@
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 @@
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])) {
--- a/opt/opt.h
+++ b/opt/opt.h
@@ -6,6 +6,7 @@
size_t nbb;
/* for building bb */
+ int nextbbid;
Htab *lblmap; /* label => Bb mapping */
Node **fixjmp;
size_t nfixjmp;