Combine fillrpo() and fillpreds() into fillcfg().

Remove edgedel() calls from fillrpo().

Call new prunephis() from fillpreds().
[Curiously this never seems to do anything even tho edgedel()
is no longer called from fillrpo()]

One remaining fillpreds() call in parse.c typecheck - seems
like it will still work the same.

defensive; fillcfg() combining fillrpo() and fillpreds() - problem after simpljmp() - think it is cos fillrpo() is still doing edgedel() which should now be covered by fillpreds()

comment out edgedel() in fillrpo() - fillcfg() no longer asserts after simpljmp() but seems like prunephis() never triggers???

static fillrpo(); remove edgedel() from fillrpo()

replace fillrpo() and/or fillpreds() with fillcfg()
This commit is contained in:
Roland Paterson-Jones 2024-11-19 11:29:16 +02:00 committed by Quentin Carbonneaux
parent ecfdac4f00
commit 9e36cbe4d8
3 changed files with 46 additions and 12 deletions

2
all.h
View File

@ -527,7 +527,7 @@ void elimsb(Fn *);
Blk *newblk(void);
void edgedel(Blk *, Blk **);
void fillpreds(Fn *);
void fillrpo(Fn *);
void fillcfg(Fn *);
void filldom(Fn *);
int sdom(Blk *, Blk *);
int dom(Blk *, Blk *);

44
cfg.c
View File

@ -11,6 +11,34 @@ newblk()
return b;
}
/* TODO - this never seems to do anything??? */
static void
prunephis(Fn *f)
{
Blk *b;
Phi *p, **pp;
uint na, na0;
for (b = f->start; b; b = b->link) {
assert(b->id < f->nblk);
for (pp = &b->phi; (*pp);) {
p = *pp;
for (na = na0 = 0; na < p->narg; na++)
if (p->blk[na]->id != -1u) {
p->blk[na0] = p->blk[na];
p->arg[na0] = p->arg[na];
na0++;
}
if (na0 == 0) {
*pp = p->link;
} else {
p->narg = na0;
pp = &p->link;
}
}
}
}
void
edgedel(Blk *bs, Blk **pbd)
{
@ -53,7 +81,7 @@ addpred(Blk *bp, Blk *bc)
bc->pred[bc->npred-1] = bp;
}
/* fill predecessors information in blocks */
/* fill predecessors information in blocks; prune dead phi refs */
void
fillpreds(Fn *f)
{
@ -67,6 +95,8 @@ fillpreds(Fn *f)
if (b->s2 && b->s2 != b->s1)
addpred(b, b->s2);
}
/* TODO - this never seems to do anything??? */
prunephis(f);
}
static void
@ -89,7 +119,7 @@ porec(Blk *b, uint *npo)
}
/* fill the rpo information; prune dead blks */
void
static void
fillrpo(Fn *f)
{
Blk *b, **p;
@ -104,8 +134,6 @@ fillrpo(Fn *f)
f->rpo = vnew(f->nblk, sizeof f->rpo[0], PFn);
for (p=&f->start; (b=*p);) {
if (b->id == -1u) {
edgedel(b, &b->s1);
edgedel(b, &b->s2);
*p = b->link;
} else {
b->id = f->nblk-b->id-1; /* po -> rpo */
@ -115,6 +143,14 @@ fillrpo(Fn *f)
}
}
/* fill rpo, preds; prune dead blks, prune dead blk refs from phis */
void
fillcfg(Fn *f)
{
fillrpo(f);
fillpreds(f);
}
/* for dominators computation, read
* "A Simple, Fast Dominance Algorithm"
* by K. Cooper, T. Harvey, and K. Kennedy.

12
main.c
View File

@ -59,8 +59,7 @@ func(Fn *fn)
printfn(fn, stderr);
}
T.abi0(fn);
fillrpo(fn);
fillpreds(fn);
fillcfg(fn);
filluse(fn);
promote(fn);
filluse(fn);
@ -79,19 +78,18 @@ func(Fn *fn)
fold(fn);
T.abi1(fn);
simpl(fn);
fillpreds(fn);
fillcfg(fn);
filluse(fn);
T.isel(fn);
fillrpo(fn);
fillcfg(fn);
filllive(fn);
fillloop(fn);
fillcost(fn);
spill(fn);
rega(fn);
fillrpo(fn);
fillcfg(fn);
simpljmp(fn);
fillpreds(fn);
fillrpo(fn);
fillcfg(fn);
assert(fn->rpo[0] == fn->start);
for (n=0;; n++)
if (n == fn->nblk-1) {