refactored
[libfirm] / ir / be / becopyoptmain.c
1 /**
2  * Author:      Daniel Grund
3  * Date:                11.04.2005
4  * Copyright:   (c) Universitaet Karlsruhe
5  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
6
7  * Main file for the optimization reducing the copies needed for:
8  * - phi coalescing
9  * - register-constrained nodes
10  */
11 #ifdef HAVE_CONFIG_H
12 #include "config.h"
13 #endif
14
15 #include "debug.h"
16 #include "irouts.h"
17 #include "becopyopt.h"
18 #include "becopystat.h"
19 #include "becopyoptmain.h"
20
21 #define DO_HEUR
22 #undef DO_ILP
23
24 #define DEBUG_LVL SET_LEVEL_1
25 static firm_dbg_module_t *dbg = NULL;
26
27 void be_copy_opt_init(void) {
28         dbg = firm_dbg_register("ir.be.copyoptmain");
29         firm_dbg_set_mask(dbg, DEBUG_LVL);
30 }
31
32 void be_copy_opt(be_chordal_env_t *chordal_env) {
33         copy_opt_t *co;
34         int costs, costs_init=-1, costs_heur=-1, costs_ilp=-1;
35         int lower_bound;
36
37         /* BETTER: You can remove this if you replace all
38          * `grep get_irn_out *.c` by the irouts.h module.*/
39         compute_outs(chordal_env->session_env->irg);
40
41         co = new_copy_opt(chordal_env, get_costs_all_one);
42         DBG((dbg, LEVEL_1, "----> CO: %s\n", co->name));
43
44
45 #ifdef DO_STAT
46         lower_bound = co_get_lower_bound(co);
47         DBG((dbg, LEVEL_1, "Lower Bound: %3d\n", lower_bound));
48         costs = co_get_copy_costs(co);
49         costs_init = costs;
50         copystat_add_max_costs(co_get_max_copy_costs(co));
51         copystat_add_inevit_costs(co_get_inevit_copy_costs(co));
52         copystat_add_init_costs(costs_init);
53         DBG((dbg, LEVEL_1, "Init costs: %3d\n", costs_init));
54 #endif
55
56 #ifdef DO_HEUR
57         co_heur_opt(co);
58 #ifdef DO_STAT
59         costs = co_get_copy_costs(co);
60         costs_heur = costs;
61         copystat_add_heur_costs(costs_heur);
62         DBG((dbg, LEVEL_1, "Heur costs: %3d\n", costs_heur));
63 #endif
64 #endif
65
66 #ifdef DO_ILP
67         co_ilp_opt(co);
68 #ifdef DO_STAT
69         costs = co_get_copy_costs(co);
70         costs_ilp = costs;
71         copystat_add_opt_costs(costs_ilp);
72         DBG((dbg, LEVEL_1, "Opt  costs: %3d\n", costs_ilp));
73 #endif
74 #endif
75
76         free_copy_opt(co);
77 }