diff options
| author | 2025-09-15 17:11:05 +0200 | |
|---|---|---|
| committer | 2025-09-15 17:11:46 +0200 | |
| commit | b8ae5b14c7bbe28161ea83f4c10045f8af5b766a (patch) | |
| tree | b53e99abf48f82435220aecea86c5569b85a74e6 /cfg.c | |
| parent | bdf9776b0b127b53a34be07f8adc0541df78654e (diff) | |
mem2reg: fix deltrivialphis bug
Diffstat (limited to 'cfg.c')
| -rw-r--r-- | cfg.c | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -0,0 +1,43 @@ +#include "ir.h" + +static void +porec(struct block ***rpo, struct block *b) +{ + if (wasvisited(b)) return; + markvisited(b); + if (b->s2) porec(rpo, b->s2); + if (b->s1) porec(rpo, b->s1); + *--*rpo = b; +} + +void +sortrpo(struct function *fn) +{ + static struct block **rpobuf; + struct block **rpoend, **rpo; + int i, ndead; + + xbgrow(&rpobuf, fn->nblk); + rpo = rpoend = rpobuf + fn->nblk, + + startbbvisit(); + fn->entry->id = 0; + markvisited(fn->entry); + if (fn->entry->s1) porec(&rpo, fn->entry->s1); + if (fn->entry->s2) porec(&rpo, fn->entry->s2); + *--rpo = fn->entry; + ndead = rpo - rpobuf; + for (i = 1, ++rpo; rpo < rpoend; ++rpo, ++i) { + rpo[-1]->lnext = rpo[0]; + rpo[0]->lprev = rpo[-1]; + rpo[0]->id = i; + } + fn->entry->lprev = rpo[-1]; + rpo[-1]->lnext = fn->entry; + for (rpo = rpobuf; ndead > 0; --ndead) { + (*rpo)->lnext = (*rpo)->lprev = NULL; + freeblk(fn, *rpo); + } +} + +/* vim:set ts=3 sw=3 expandtab: */ |