diff options
| author | 2025-11-21 09:38:15 +0100 | |
|---|---|---|
| committer | 2025-11-21 09:38:15 +0100 | |
| commit | e4f8fc6306cc14edd600d7691142e21af711f603 (patch) | |
| tree | 5f6fccfb97c369aefcd31205ed05a75821cc40a4 /ir/cfg.c | |
| parent | 3f4c2dd90e68475f125f02c872518dbb040746b6 (diff) | |
cfg: sortrpo delete unreachable blocks with allocas by hoisting them to the entry block
Diffstat (limited to 'ir/cfg.c')
| -rw-r--r-- | ir/cfg.c | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -14,7 +14,7 @@ void sortrpo(struct function *fn) { static struct block **rpobuf; - struct block **rpoend, **rpo; + struct block **rpoend, **rpo, *blk, *next; int i, ndead; xbgrow(&rpobuf, fn->nblk); @@ -24,19 +24,20 @@ sortrpo(struct function *fn) fn->entry->id = 0; porec(&rpo, fn->entry); ndead = rpo - rpobuf; - for (struct block *blk = fn->entry->lprev, *next; blk != fn->entry; blk = next) { + if (ndead > 0) for (blk = fn->entry->lprev; blk != fn->entry; blk = next) { next = blk->lprev; if (!wasvisited(blk)) { for (int i = 0; i < blk->ins.n; ++i) { - /* don't delete unreachable blocks with alloca pseudo-instrs */ - if (oisalloca(instrtab[blk->ins.p[i]].op)) - goto Next; + /* if unreachable block has alloca pseudo-instrs, move them to the entry + * to be able to delete it */ + if (oisalloca(instrtab[blk->ins.p[i]].op)) { + vpush(&fn->entry->ins, blk->ins.p[i]); + } } for (int i = 0; i < blk->npred; ++i) assert(!wasvisited(blkpred(blk, i))); freeblk(fn, blk); --ndead; - Next:; } } for (i = 1, ++rpo; rpo < rpoend; ++rpo, ++i) { |