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); Blk *newblk(void);
void edgedel(Blk *, Blk **); void edgedel(Blk *, Blk **);
void fillpreds(Fn *); void fillpreds(Fn *);
void fillrpo(Fn *); void fillcfg(Fn *);
void filldom(Fn *); void filldom(Fn *);
int sdom(Blk *, Blk *); int sdom(Blk *, Blk *);
int dom(Blk *, Blk *); int dom(Blk *, Blk *);

44
cfg.c
View File

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

12
main.c
View File

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