+ (void) opt;
+}
+
+static int void_algo(copy_opt_t *co)
+{
+ (void) co;
+ return 0;
+}
+
+/*
+ _ _ _ _ _
+ / \ | | __ _ ___ _ __(_) |_| |__ _ __ ___ ___
+ / _ \ | |/ _` |/ _ \| '__| | __| '_ \| '_ ` _ \/ __|
+ / ___ \| | (_| | (_) | | | | |_| | | | | | | | \__ \
+ /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|___/
+ |___/
+*/
+
+typedef struct {
+ co_algo_t *algo;
+ const char *name;
+ int can_improve_existing;
+} co_algo_info_t;
+
+static co_algo_info_t algos[] = {
+ { void_algo, "none", 0 },
+ { co_solve_heuristic, "heur1", 0 },
+ { co_solve_heuristic_new, "heur2", 0 },
+#ifdef WITH_JVM
+ { co_solve_heuristic_java, "heur3", 0 },
+#else
+ { NULL, "heur3", 0 },
+#endif
+ { co_solve_heuristic_mst, "heur4", 0 },
+#ifdef WITH_ILP
+ { co_solve_ilp2, "ilp", 1 },
+#else
+ { NULL, "ilp", 1 },
+#endif
+ { NULL, "", 0 }
+};
+
+/*
+ __ __ _ ____ _
+ | \/ | __ _(_)_ __ | _ \ _ __(_)_ _____ _ __
+ | |\/| |/ _` | | '_ \ | | | | '__| \ \ / / _ \ '__|
+ | | | | (_| | | | | | | |_| | | | |\ V / __/ |
+ |_| |_|\__,_|_|_| |_| |____/|_| |_| \_/ \___|_|
+
+*/
+
+static FILE *my_open(const be_chordal_env_t *env, const char *prefix, const char *suffix)
+{
+ FILE *result;
+ char buf[1024];
+ size_t i, n;
+ char *tu_name;
+
+ n = strlen(env->birg->main_env->cup_name);
+ tu_name = XMALLOCN(char, n + 1);
+ strcpy(tu_name, env->birg->main_env->cup_name);
+ for (i = 0; i < n; ++i)
+ if (tu_name[i] == '.')
+ tu_name[i] = '_';
+
+
+ ir_snprintf(buf, sizeof(buf), "%s%s_%F_%s%s", prefix, tu_name, env->irg, env->cls->name, suffix);
+ xfree(tu_name);
+ result = fopen(buf, "wt");
+ if(result == NULL) {
+ panic("Couldn't open '%s' for writing.", buf);
+ }
+
+ return result;
+}
+
+void co_driver(be_chordal_env_t *cenv)
+{
+ ir_timer_t *timer = ir_timer_register("firm.be.copyopt", "runtime");
+ co_complete_stats_t before, after;
+ copy_opt_t *co;
+ co_algo_t *algo_func;
+ int was_optimal = 0;
+
+ if (algo >= CO_ALGO_LAST)
+ return;
+
+ be_liveness_assure_chk(be_get_birg_liveness(cenv->birg));
+
+ co = new_copy_opt(cenv, cost_func);
+ co_build_ou_structure(co);
+ co_build_graph_structure(co);
+
+ co_complete_stats(co, &before);
+
+ be_stat_ev_ull("co_aff_nodes", before.aff_nodes);
+ be_stat_ev_ull("co_aff_edges", before.aff_edges);
+ be_stat_ev_ull("co_max_costs", before.max_costs);
+ be_stat_ev_ull("co_inevit_costs", before.inevit_costs);
+ be_stat_ev_ull("co_aff_int", before.aff_int);
+
+ be_stat_ev_ull("co_init_costs", before.costs);
+ be_stat_ev_ull("co_init_unsat", before.unsatisfied_edges);
+
+ if (dump_flags & DUMP_BEFORE) {
+ FILE *f = my_open(cenv, "", "-before.dot");
+ co_dump_ifg_dot(co, f, style_flags);
+ fclose(f);
+ }
+
+ /* if the algo can improve results, provide an initial solution with heur3 */
+ if (improve && algos[algo].can_improve_existing) {
+ co_complete_stats_t stats;
+
+ /* produce a heuristic solution */
+#ifdef WITH_JVM
+ co_solve_heuristic_java(co);
+#else
+ co_solve_heuristic(co);
+#endif /* WITH_JVM */
+
+ /* do the stats and provide the current costs */
+ co_complete_stats(co, &stats);
+ be_stat_ev_ull("co_prepare_costs", stats.costs);
+ }
+
+#ifdef WITH_JVM
+ /* start the JVM here so that it does not tamper the timing. */
+ if (algo == CO_ALGO_HEUR3)
+ be_java_coal_start_jvm();
+#endif /* WITH_JVM */
+
+ algo_func = algos[algo].algo;
+
+ /* perform actual copy minimization */
+ ir_timer_reset_and_start(timer);
+ was_optimal = algo_func(co);
+ ir_timer_stop(timer);
+
+ be_stat_ev("co_time", ir_timer_elapsed_msec(timer));
+ be_stat_ev_ull("co_optimal", was_optimal);
+
+ if (dump_flags & DUMP_AFTER) {
+ FILE *f = my_open(cenv, "", "-after.dot");
+ co_dump_ifg_dot(co, f, style_flags);
+ fclose(f);
+ }
+
+ co_complete_stats(co, &after);
+
+ if (do_stats) {
+ ulong64 optimizable_costs = after.max_costs - after.inevit_costs;
+ ulong64 evitable = after.costs - after.inevit_costs;
+
+ ir_printf("%30F ", cenv->irg);
+ printf("%10s %10" ULL_FMT "%10" ULL_FMT "%10" ULL_FMT, cenv->cls->name, after.max_costs, before.costs, after.inevit_costs);
+
+ if(optimizable_costs > 0)
+ printf("%10" ULL_FMT " %5.2f\n", after.costs, (evitable * 100.0) / optimizable_costs);
+ else
+ printf("%10" ULL_FMT " %5s\n", after.costs, "-");
+ }
+
+ /* Dump the interference graph in Appel's format. */
+ if (dump_flags & DUMP_APPEL) {
+ FILE *f = my_open(cenv, "", ".apl");
+ fprintf(f, "# %lld %lld\n", after.costs, after.unsatisfied_edges);
+ co_dump_appel_graph(co, f);
+ fclose(f);
+ }
+
+ be_stat_ev_ull("co_after_costs", after.costs);
+ be_stat_ev_ull("co_after_unsat", after.unsatisfied_edges);