From 9e36cbe4d8f8c9ff3d739ff9ead2a4a4988c0904 Mon Sep 17 00:00:00 2001 From: Roland Paterson-Jones Date: Tue, 19 Nov 2024 11:29:16 +0200 Subject: 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() --- all.h | 2 +- cfg.c | 44 ++++++++++++++++++++++++++++++++++++++++---- main.c | 12 +++++------- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/all.h b/all.h index fc98c52..a5a0163 100644 --- a/all.h +++ b/all.h @@ -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 *); diff --git a/cfg.c b/cfg.c index 631c356..99b6f40 100644 --- a/cfg.c +++ b/cfg.c @@ -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. diff --git a/main.c b/main.c index 5ecb4d0..977c55b 100644 --- a/main.c +++ b/main.c @@ -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) { -- cgit v1.2.3