summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJohannes Bucher <johannes.bucher2@student.kit.edu>2018-11-27 16:48:46 +0100
committerJohannes Bucher <johannes.bucher2@student.kit.edu>2018-11-27 16:48:46 +0100
commit22f9017807b3059f0f14c297198573acf96a1a43 (patch)
treedf7c75d7fdcc1891fd7cd49fc2e1f70804a39562
parent11e237cbcda6c5b7b5f151ba26f8552a26583e94 (diff)
Add limit parameter to booloptboolopt-improvement
-rw-r--r--include/libfirm/iroptimize.h8
-rw-r--r--ir/opt/boolopt.c9
2 files changed, 12 insertions, 5 deletions
diff --git a/include/libfirm/iroptimize.h b/include/libfirm/iroptimize.h
index 9459354..633bb1b 100644
--- a/include/libfirm/iroptimize.h
+++ b/include/libfirm/iroptimize.h
@@ -42,9 +42,15 @@ FIRM_API void opt_jumpthreading(ir_graph* irg);
* Simplifies boolean expression in the given ir graph.
* eg. x < 5 && x < 6 becomes x < 5
*
+ * Converts control flow into simple boolean expressions if possible by
+ * ignoring short circuit evaluation. limit parameter can be used to regulate the
+ * size (number of instructions) of the generated expressions. Setting this limit to 0
+ * disables this part of the optimization.
+ *
* @param irg the graph
+ * @param limit size limit for generated boolean expressions
*/
-FIRM_API void opt_bool(ir_graph *irg);
+FIRM_API void opt_bool(ir_graph *irg, unsigned limit);
/**
* Reduces the number of Conv nodes in the given ir graph.
diff --git a/ir/opt/boolopt.c b/ir/opt/boolopt.c
index 400e983..b540e04 100644
--- a/ir/opt/boolopt.c
+++ b/ir/opt/boolopt.c
@@ -34,6 +34,7 @@ typedef struct cond_pair {
/** Environment for all walker in boolopt. */
typedef struct {
bool changed; /**< Set if the graph was changed. */
+ unsigned limit; /**< size limit for boolean expressions generated by control flow conversion */
} bool_opt_env_t;
DEBUG_ONLY(static firm_dbg_module_t *dbg;)
@@ -749,8 +750,7 @@ restart:
if (expression_size_lower >= 0 && expression_size_upper >= 0) {
expression_size = expression_size_lower + expression_size_upper;
}
- int expr_limit = 8;
- //TODO add option for setting limit
+ int expr_limit = env->limit;
if (expression_size >= 0 && expression_size <= expr_limit) {
if (get_Proj_num(upper_cf) == pn_Cond_false && get_Proj_num(lower_cf) == pn_Cond_false) {
replacement = new_r_And(upper_block, upper_cond_selector, cond_selector);
@@ -762,7 +762,7 @@ restart:
env->changed = true;
fuse_blocks = true;
- DB((dbg, LEVEL_2, "build new %+F in upper %+F (calculated expr size= &d",
+ DB((dbg, LEVEL_2, "build new %+F in upper %+F (calculated expr size= %d)\n",
replacement, upper_block, expression_size));
}
}
@@ -793,7 +793,7 @@ restart:
}
}
-void opt_bool(ir_graph *const irg)
+void opt_bool(ir_graph *const irg, unsigned limit)
{
bool_opt_env_t env;
@@ -801,6 +801,7 @@ void opt_bool(ir_graph *const irg)
FIRM_DBG_REGISTER(dbg, "firm.opt.bool");
env.changed = false;
+ env.limit = limit;
/* optimize simple Andb and Orb cases */
irg_walk_graph(irg, NULL, bool_walk, &env);