aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linearize.c
diff options
authorLinus Torvalds <torvalds@ppc970.osdl.org>2004-02-22 10:59:46 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:01:25 -0700
commitbccad350df1a832c5008eef67b641031be8ac3c7 (patch)
tree00eaa5a44bf8515a734e346d26caf6032ebf0f87 /linearize.c
parentca15470fe4bdcf70942367c9c3dd1dcc9eadba07 (diff)
downloadsparse-dev-bccad350df1a832c5008eef67b641031be8ac3c7.tar.gz
Clean up linearization, and make the basic blocks be
true basic blocks (with all exits at the bottom). This will simplify some of the analysis.
Diffstat (limited to 'linearize.c')
-rw-r--r--linearize.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/linearize.c b/linearize.c
index 5a067486..8e947afb 100644
--- a/linearize.c
+++ b/linearize.c
@@ -85,11 +85,6 @@ static struct basic_block * new_basic_block(struct entrypoint *ep, struct symbol
return bb;
}
-static void linearize_simple_statement(struct entrypoint *ep, struct statement *stmt)
-{
- add_statement(&ep->active->stmts, stmt);
-}
-
static void add_label(struct entrypoint *ep, struct symbol *sym)
{
struct basic_block *new_bb = new_basic_block(ep, sym);
@@ -98,6 +93,19 @@ static void add_label(struct entrypoint *ep, struct symbol *sym)
ep->active = new_bb;
}
+static void linearize_simple_statement(struct entrypoint *ep, struct statement *stmt)
+{
+ struct basic_block *bb = ep->active;
+
+ if (bb_reachable(bb)) {
+ if (bb->flags & BB_HASBRANCH) {
+ add_label(ep, alloc_symbol(stmt->pos, SYM_LABEL));
+ bb = ep->active;
+ }
+ add_statement(&bb->stmts, stmt);
+ }
+}
+
static void set_unreachable(struct entrypoint *ep)
{
ep->active = new_basic_block(ep, NULL);
@@ -105,10 +113,15 @@ static void set_unreachable(struct entrypoint *ep)
static void add_branch(struct entrypoint *ep, struct statement *stmt, int true, struct expression *cond, struct symbol *target)
{
- struct statement *jump = alloc_statement(stmt->pos, true);
- jump->bb_conditional = cond;
- jump->bb_target = target;
- linearize_simple_statement(ep, jump);
+ struct basic_block *bb = ep->active;
+
+ if (bb_reachable(bb)) {
+ struct statement *jump = alloc_statement(stmt->pos, true);
+ jump->bb_conditional = cond;
+ jump->bb_target = target;
+ bb->flags |= BB_HASBRANCH;
+ add_statement(&bb->stmts, jump);
+ }
}
void linearize_statement(struct entrypoint *ep, struct statement *stmt)
@@ -190,7 +203,6 @@ void linearize_statement(struct entrypoint *ep, struct statement *stmt)
struct symbol *merge = alloc_symbol(never->pos, SYM_LABEL);
add_label(ep, merge);
bb->next = merge;
- ep->active = new_basic_block(ep, merge);
break;
}