aboutsummaryrefslogtreecommitdiff
path: root/src/unreachable.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-04-03 16:00:15 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-04-03 16:00:15 +0300
commit36de4f902c4eec9f8d918e00cf0bf89d6b670cf5 (patch)
tree6fc1a8f172ac018411f54b24b2d989992b20fe40 /src/unreachable.c
parenta7cb592efa9ec72c4c5e9d3c1e7469203a4b47e2 (diff)
downloadqbt-36de4f902c4eec9f8d918e00cf0bf89d6b670cf5.tar.gz
qbt-36de4f902c4eec9f8d918e00cf0bf89d6b670cf5.zip
add ssa form
Diffstat (limited to 'src/unreachable.c')
-rw-r--r--src/unreachable.c34
1 files changed, 6 insertions, 28 deletions
diff --git a/src/unreachable.c b/src/unreachable.c
index 90a65bd..aa04f46 100644
--- a/src/unreachable.c
+++ b/src/unreachable.c
@@ -1,38 +1,16 @@
#include <qbt/unreachable.h>
-void build_reachable_vec(struct vec *reachable, struct blk *cur)
+void remove_unvisited(struct fn *f, int visited)
{
- if (cur->reachable)
- return;
-
- cur->reachable = true;
- vec_append(reachable, &cur);
-
- if (cur->btype == RET)
- return;
-
- if (cur->btype == J)
- cur->s1 = cur->s2;
-
- if (cur->s1)
- build_reachable_vec(reachable, cur->s1);
-
- if (cur->s2)
- build_reachable_vec(reachable, cur->s2);
-}
-
-void unreachable(struct fn *f)
-{
- struct vec reachable = vec_create(sizeof(struct blk *));
- struct blk *b = blk_at(f->blks, 0);
- build_reachable_vec(&reachable, b);
+ struct vec new = vec_create(sizeof(struct blk *));
foreach_blk(bi, f->blks) {
struct blk *b = blk_at(f->blks, bi);
- if (!b->reachable)
+ if (b->visited < visited)
destroy_block(b);
-
+ else
+ vec_append(&new, &b);
}
vec_destroy(&f->blks);
- f->blks = reachable;
+ f->blks = new;
}