aboutsummaryrefslogtreecommitdiffhomepage
path: root/ir
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-11-21 09:38:15 +0100
committerlemon <lsof@mailbox.org>2025-11-21 09:38:15 +0100
commite4f8fc6306cc14edd600d7691142e21af711f603 (patch)
tree5f6fccfb97c369aefcd31205ed05a75821cc40a4 /ir
parent3f4c2dd90e68475f125f02c872518dbb040746b6 (diff)
cfg: sortrpo delete unreachable blocks with allocas by hoisting them to the entry block
Diffstat (limited to 'ir')
-rw-r--r--ir/cfg.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/ir/cfg.c b/ir/cfg.c
index 8e86cb2..e79dc63 100644
--- a/ir/cfg.c
+++ b/ir/cfg.c
@@ -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) {