- /* should we really remove the Confirm here? */
- if (firm_opt.confirm) {
- timer_push(TV_CONFIRM_CREATE);
- remove_confirms(irg);
- timer_pop();
- }
-
- if (firm_opt.gvn_pre) {
- do_gvn_pre(irg);
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "pre");
- CHECK_ONE(firm_opt.check_all, irg);
- irg_verify(irg, VRFY_ENFORCE_SSA);
- }
-
- if (! firm_opt.gcse) {
- timer_push(TV_CODE_PLACE);
- optimize_graph_df(irg);
- place_code(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "place");
- CHECK_ONE(firm_opt.check_all, irg);
- }
-
- compute_doms(irg);
- compute_postdoms(irg);
- DUMP_ONE_CFG_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "dom");
- CHECK_ONE(firm_opt.check_all, irg);
-
- construct_backedges(irg);
-
- timer_push(TV_CF_OPT);
- optimize_cf(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "cfopt");
- CHECK_ONE(firm_opt.check_all, irg);
-
- if (firm_opt.if_conversion) {
- timer_push(TV_IF_CONV);
- opt_if_conv(current_ir_graph, if_conv_info);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "if");
- CHECK_ONE(firm_opt.check_all, current_ir_graph);
-
- timer_push(TV_LOCAL_OPT);
- optimize_graph_df(current_ir_graph);
- timer_pop();
- timer_push(TV_CF_OPT);
- optimize_cf(current_ir_graph);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "after_if");
- CHECK_ONE(firm_opt.check_all, current_ir_graph);
- }
-
- if (firm_opt.bool_opt) {
- opt_bool(irg);
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "bool");
- CHECK_ONE(firm_opt.check_all, irg);
- }
-
- timer_push(TV_OSR);
- opt_osr(current_ir_graph, osr_flag_default | osr_flag_keep_reg_pressure | osr_flag_ignore_x86_shift);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "stred");
- CHECK_ONE(firm_opt.check_all, irg);
-
- timer_push(TV_LOCAL_OPT);
- optimize_graph_df(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "lopt");
- CHECK_ONE(firm_opt.check_all, irg);
-
- edges_deactivate(irg);
- timer_push(TV_DEAD_NODE);
- dead_node_elimination(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "dead");
- CHECK_ONE(firm_opt.check_all, irg);
- }
-
- if (firm_opt.do_inline) {
- inline_functions(500, 50);
- DUMP_ALL_C(firm_dump.ir_graph && firm_dump.all_phases, "inl");
- CHECK_ALL(firm_opt.check_all);
- }
- if (firm_opt.cloning) {
- proc_cloning((float)firm_opt.clone_threshold);
- DUMP_ALL_C(firm_dump.ir_graph && firm_dump.all_phases, "clone");
- CHECK_ALL(firm_opt.check_all);
- }
-
- if (firm_opt.cond_eval) {
- for (i = 0; i < get_irp_n_irgs(); i++) {
- irg = get_irp_irg(i);
- timer_push(TV_COND_EVAL);
- opt_cond_eval(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "cond_eval");
- CHECK_ONE(firm_opt.check_all, irg);
- }
- }
-
- /* final run of local optimizations */
- for (i = 0; i < get_irp_n_irgs(); i++) {
- irg = get_irp_irg(i);
- timer_push(TV_LOCAL_OPT);
- optimize_graph_df(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "local_opt");
- CHECK_ONE(firm_opt.check_all, irg);
-
- timer_push(TV_CF_OPT);
- optimize_cf(irg);
- timer_pop();
- DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, irg, "cfopt");
- CHECK_ONE(firm_opt.check_all, irg);
- }
-
- if (firm_dump.ir_graph) {
- /* recompute backedges for nicer dumps */
- for (i = 0; i < get_irp_n_irgs(); i++)
- construct_cf_backedges(get_irp_irg(i));
- }
-
- if (firm_opt.remove_unused) {
- ir_entity **keep_methods;
- int arr_len;
-
- timer_push(TV_CGANA);
- /* Analysis that finds the free methods,
- i.e. methods that are dereferenced.
- Optimizes polymorphic calls :-). */
- cgana(&arr_len, &keep_methods);
-
- /* Remove methods that are never called. */
- gc_irgs(arr_len, keep_methods);
-
- free(keep_methods);
- timer_pop();
- }
-
-
- DUMP_ALL(firm_dump.ir_graph, "-opt");
-
- /* verify optimized graphs */
- for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
- ir_graph *irg = get_irp_irg(i);
- irg_verify(irg, VRFY_ENFORCE_SSA);
- }
-
- if (firm_dump.statistic & STAT_AFTER_OPT)
- stat_dump_snapshot(input_filename, "opt");
-
- timer_stop(TV_ALL_OPT);
-} /* do_firm_optimizations */
+typedef enum opt_target {
+ OPT_TARGET_IRG, /**< optimization function works on a single graph */
+ OPT_TARGET_IRP /**< optimization function works on the complete program */
+} opt_target_t;
+
+typedef enum opt_flags {
+ OPT_FLAG_NONE = 0,
+ OPT_FLAG_ENABLED = 1 << 0, /**< enable the optimization */
+ OPT_FLAG_NO_DUMP = 1 << 1, /**< don't dump after transformation */
+ OPT_FLAG_NO_VERIFY = 1 << 2, /**< don't verify after transformation */
+ OPT_FLAG_HIDE_OPTIONS = 1 << 3, /**< do not automatically process
+ -foptions for this transformation */
+ OPT_FLAG_ESSENTIAL = 1 << 4, /**< output won't work without this pass
+ so we need it even with -O0 */
+} opt_flags_t;
+
+typedef void (*transform_irg_func)(ir_graph *irg);
+typedef void (*transform_irp_func)(void);
+
+typedef struct {
+ opt_target_t target;
+ const char *name;
+ union {
+ transform_irg_func transform_irg;
+ transform_irp_func transform_irp;
+ } u;
+ const char *description;
+ opt_flags_t flags;
+} opt_config_t;
+
+static opt_config_t opts[] = {
+#define IRG(a, b, c, d) { OPT_TARGET_IRG, a, .u.transform_irg = (transform_irg_func)b, c, d }
+#define IRP(a, b, c, d) { OPT_TARGET_IRP, a, .u.transform_irp = b, c, d }
+ IRG("bool", opt_bool, "bool simplification", OPT_FLAG_NONE),
+ IRG("combo", combo, "combined CCE, UCE and GVN", OPT_FLAG_NONE),
+ IRG("confirm", construct_confirms, "confirm optimisation", OPT_FLAG_HIDE_OPTIONS),
+ IRG("control-flow", optimize_cf, "optimization of control-flow", OPT_FLAG_HIDE_OPTIONS),
+ IRG("dead", dead_node_elimination, "dead node elimination", OPT_FLAG_HIDE_OPTIONS | OPT_FLAG_NO_DUMP | OPT_FLAG_NO_VERIFY),
+ IRG("deconv", conv_opt, "conv node elimination", OPT_FLAG_NONE),
+ IRG("fp-vrp", fixpoint_vrp, "fixpoint value range propagation", OPT_FLAG_NONE),
+ IRG("frame", opt_frame_irg, "remove unused frame entities", OPT_FLAG_NONE),
+ IRG("gcse", do_gcse, "global common subexpression elimination", OPT_FLAG_NONE),
+ IRG("gvn-pre", do_gvn_pre, "global value numbering partial redundancy elimination", OPT_FLAG_NONE),
+ IRG("if-conversion", do_if_conv, "if-conversion", OPT_FLAG_NONE),
+ IRG("invert-loops", do_loop_inversion, "loop inversion", OPT_FLAG_NONE),
+ IRG("ivopts", do_stred, "induction variable strength reduction", OPT_FLAG_NONE),
+ IRG("local", optimize_graph_df, "local graph optimizations", OPT_FLAG_HIDE_OPTIONS),
+ IRG("lower", do_lower_highlevel, "lowering", OPT_FLAG_HIDE_OPTIONS | OPT_FLAG_ESSENTIAL),
+ IRG("lower-mux", do_lower_mux, "mux lowering", OPT_FLAG_NONE),
+ IRG("lower-switch", do_lower_switch, "switch lowering", OPT_FLAG_HIDE_OPTIONS | OPT_FLAG_ESSENTIAL),
+ IRG("one-return", normalize_one_return, "normalisation to 1 return", OPT_FLAG_HIDE_OPTIONS | OPT_FLAG_NO_DUMP | OPT_FLAG_NO_VERIFY),
+ IRG("opt-load-store", optimize_load_store, "load store optimization", OPT_FLAG_NONE),
+ IRG("opt-tail-rec", opt_tail_rec_irg, "tail-recursion eliminiation", OPT_FLAG_NONE),
+ IRG("parallelize-mem", opt_parallelize_mem, "parallelize memory", OPT_FLAG_NONE),
+ IRG("place", place_code, "code placement", OPT_FLAG_NONE),
+ IRG("reassociation", optimize_reassociation, "reassociation", OPT_FLAG_NONE),
+ IRG("remove-confirms", remove_confirms, "confirm removal", OPT_FLAG_HIDE_OPTIONS | OPT_FLAG_NO_DUMP | OPT_FLAG_NO_VERIFY),
+ IRG("remove-phi-cycles", remove_phi_cycles, "removal of phi cycles", OPT_FLAG_HIDE_OPTIONS),
+ IRG("scalar-replace", scalar_replacement_opt, "scalar replacement", OPT_FLAG_NONE),
+ IRG("shape-blocks", shape_blocks, "block shaping", OPT_FLAG_NONE),
+ IRG("thread-jumps", opt_jumpthreading, "path-sensitive jumpthreading", OPT_FLAG_NONE),
+ IRG("unroll-loops", do_loop_unrolling, "loop unrolling", OPT_FLAG_NONE),
+ IRG("vrp", do_vrp, "value range propagation", OPT_FLAG_NONE),
+ IRP("inline", do_inline, "inlining", OPT_FLAG_NONE),
+ IRP("lower-const", lower_const_code, "lowering of constant code", OPT_FLAG_HIDE_OPTIONS | OPT_FLAG_NO_DUMP | OPT_FLAG_NO_VERIFY | OPT_FLAG_ESSENTIAL),
+ IRP("lower-dw", do_lower_dw_ops, "lowering of doubleword operations", OPT_FLAG_HIDE_OPTIONS | OPT_FLAG_ESSENTIAL),
+ IRP("opt-func-call", do_optimize_funccalls, "function call optimization", OPT_FLAG_NONE),
+ IRP("opt-proc-clone", do_cloning, "procedure cloning", OPT_FLAG_NONE),
+ IRP("remove-unused", garbage_collect_entities, "removal of unused functions/variables", OPT_FLAG_NO_DUMP | OPT_FLAG_NO_VERIFY),
+ IRP("rts", rts_map, "optimization of known library functions", OPT_FLAG_HIDE_OPTIONS),
+#undef IRP
+#undef IRG
+};
+static const int n_opts = sizeof(opts) / sizeof(opts[0]);
+ir_timer_t *timers[sizeof(opts)/sizeof(opts[0])];
+
+static opt_config_t *get_opt(const char *name)
+{
+ int i;
+ for (i = 0; i < n_opts; ++i) {
+ opt_config_t *config = &opts[i];
+ if (strcmp(config->name, name) == 0)
+ return config;
+ }
+
+ return NULL;
+}
+
+static void set_opt_enabled(const char *name, bool enabled)
+{
+ opt_config_t *config = get_opt(name);
+ config->flags = (config->flags & ~OPT_FLAG_ENABLED)
+ | (enabled ? OPT_FLAG_ENABLED : 0);
+}
+
+static bool get_opt_enabled(const char *name)
+{
+ opt_config_t *config = get_opt(name);
+ return (config->flags & OPT_FLAG_ENABLED) != 0;
+}