aboutsummaryrefslogtreecommitdiffhomepage
path: root/ir/ir.c
diff options
context:
space:
mode:
Diffstat (limited to 'ir/ir.c')
-rw-r--r--ir/ir.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/ir/ir.c b/ir/ir.c
index 412d0f9..4a092b3 100644
--- a/ir/ir.c
+++ b/ir/ir.c
@@ -451,6 +451,27 @@ numberinstrs(struct function *fn)
} while ((blk = blk->lnext) != fn->entry);
}
+static bool
+reachablerec(struct function *fn, struct block *blk)
+{
+ if (blk == fn->entry) return 1;
+ markvisited(blk);
+ if (blk->npred == 1 && !wasvisited(blkpred(blk, 0)))
+ return reachablerec(fn, blkpred(blk, 0));
+ else for (int i = 0; i < blk->npred; ++i) {
+ struct block *p = blkpred(blk, i);
+ if (!wasvisited(p) && reachablerec(fn, p)) return 1;
+ }
+ return 0;
+}
+
+bool
+blkreachable(struct function *fn, struct block *blk)
+{
+ startbbvisit();
+ return reachablerec(fn, blk);
+}
+
/* require use */
void
replcuses(union ref from, union ref to)