From 3a7675d100c8559bf53ef8043d446661b72f2e4e Mon Sep 17 00:00:00 2001 From: lemon Date: Fri, 7 Jul 2023 09:38:49 +0200 Subject: [PATCH] mem2reg; style --- optmem.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/optmem.c b/optmem.c index 7489e2a..d733a70 100644 --- a/optmem.c +++ b/optmem.c @@ -136,18 +136,17 @@ readvar(struct ssabuilder *sb, int var, enum irclass cls, struct block *blk) } static bool -tryseal(struct ssabuilder *sb, struct block *blk) +trysealrec(struct ssabuilder *sb, struct block *blk) { - vec_of(struct pendingphi) *pending; if (bstest(sb->sealed, blk->id)) return 1; if (blk->id > sb->lastvisit) return 0; - if (wasvisited(blk)) return 1; markvisited(blk); for (int i = 0; i < blk->npred; ++i) { struct block *p = blkpred(blk, i); - if (!tryseal(sb, p)) return 0; + if (wasvisited(p)) continue; + if (!trysealrec(sb, p)) return 0; } bsset(sb->sealed, blk->id); @@ -157,11 +156,18 @@ tryseal(struct ssabuilder *sb, struct block *blk) mkref(RTMP, pending->p[i].phi)); } vfree(pending); - if (blk->s1) tryseal(sb, blk->s1); - if (blk->s2) tryseal(sb, blk->s2); + if (blk->s1) trysealrec(sb, blk->s1); + if (blk->s2) trysealrec(sb, blk->s2); return 1; } +static void +tryseal(struct ssabuilder *sb, struct block *blk) +{ + startbbvisit(); + trysealrec(sb, blk); +} + /* require use, blkid; keeps use */ void mem2reg(struct function *fn) @@ -239,7 +245,6 @@ mem2reg(struct function *fn) assert(sb.lastvisit == blk->id); ++sb.lastvisit; - startbbvisit(); tryseal(&sb, blk); } while ((blk = blk->lnext) != fn->entry); -- 2.45.2