Simplify fillpreds()

Now that b->pred is a vector we do can remove the counting pass.
This commit is contained in:
Roland Paterson-Jones 2024-11-19 11:11:30 +02:00 committed by Quentin Carbonneaux
parent 1c769584ac
commit ecfdac4f00

14
cfg.c
View File

@ -45,12 +45,12 @@ edgedel(Blk *bs, Blk **pbd)
static void static void
addpred(Blk *bp, Blk *bc) addpred(Blk *bp, Blk *bc)
{ {
++bc->npred;
if (bc->pred) if (bc->pred)
vgrow(&bc->pred, bc->npred); vgrow(&bc->pred, bc->npred);
else else
bc->pred = vnew(bc->npred, sizeof bc->pred[0], PFn); bc->pred = vnew(bc->npred, sizeof bc->pred[0], PFn);
assert(bc->visit < bc->npred); bc->pred[bc->npred-1] = bp;
bc->pred[bc->visit++] = bp;
} }
/* fill predecessors information in blocks */ /* fill predecessors information in blocks */
@ -59,16 +59,8 @@ fillpreds(Fn *f)
{ {
Blk *b; Blk *b;
for (b=f->start; b; b=b->link) { for (b=f->start; b; b=b->link)
b->npred = 0; b->npred = 0;
b->visit = 0;
}
for (b=f->start; b; b=b->link) {
if (b->s1)
b->s1->npred++;
if (b->s2 && b->s2 != b->s1)
b->s2->npred++;
}
for (b=f->start; b; b=b->link) { for (b=f->start; b; b=b->link) {
if (b->s1) if (b->s1)
addpred(b, b->s1); addpred(b, b->s1);