summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-09-17 10:03:34 -0400
committerTavian Barnes <tavianator@tavianator.com>2017-09-17 10:12:12 -0400
commit4b8a441fa9c57fa6dcfaa84de9c8010a69b8fc4c (patch)
tree832f92871caff9fffc6909fa5657b9d53eb3a7ff
parent511d6fe676056a72f58daa7307267603f42003f3 (diff)
downloadbfs-4b8a441fa9c57fa6dcfaa84de9c8010a69b8fc4c.tar.xz
opt: Have data flow analysis respect always_{true,false}
-rw-r--r--opt.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/opt.c b/opt.c
index 7f84bba..26aec0b 100644
--- a/opt.c
+++ b/opt.c
@@ -61,6 +61,13 @@ static bool facts_impossible(const struct opt_facts *facts) {
return facts->mindepth > facts->maxdepth || !facts->types;
}
+/** Set some facts to be impossible. */
+static void set_facts_impossible(struct opt_facts *facts) {
+ facts->mindepth = INT_MAX;
+ facts->maxdepth = -1;
+ facts->types = 0;
+}
+
/**
* Optimizer state.
*/
@@ -556,7 +563,18 @@ static struct expr *optimize_expr_recursive(struct opt_state *state, struct expr
facts_union(state->facts_when_impure, state->facts_when_impure, &state->facts);
}
- if (!expr || expr == &expr_true || expr == &expr_false || state->cmdline->optlevel < 2) {
+ if (!expr) {
+ goto done;
+ }
+
+ if (expr->always_true) {
+ set_facts_impossible(&state->facts_when_false);
+ }
+ if (expr->always_false) {
+ set_facts_impossible(&state->facts_when_true);
+ }
+
+ if (state->cmdline->optlevel < 2 || expr == &expr_true || expr == &expr_false) {
goto done;
}
@@ -585,11 +603,8 @@ done:
}
int optimize_cmdline(struct cmdline *cmdline) {
- struct opt_facts facts_when_impure = {
- .mindepth = INT_MAX,
- .maxdepth = -1,
- .types = 0,
- };
+ struct opt_facts facts_when_impure;
+ set_facts_impossible(&facts_when_impure);
struct opt_state state = {
.cmdline = cmdline,