3483174db25a0a989a3c5dece17b7663e726f570
[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
16 #include <libcore/lc_timing.h>
17 #include "debug.h"
18 #include "irouts.h"
19 #include "becopyopt.h"
20 #include "becopystat.h"
21 #include "becopyoptmain.h"
22
23 #define DO_HEUR
24 #define DO_ILP
25
26 #define DEBUG_LVL SET_LEVEL_1
27 static firm_dbg_module_t *dbg = NULL;
28
29 void be_copy_opt_init(void) {
30         dbg = firm_dbg_register("ir.be.copyoptmain");
31         firm_dbg_set_mask(dbg, DEBUG_LVL);
32 }
33
34 void be_copy_opt(be_chordal_env_t *chordal_env) {
35         copy_opt_t *co;
36         int costs, costs_init=-1, costs_heur=-1, costs_ilp=-1;
37         int lower_bound;
38
39         /* BETTER: You can remove this if you replace all
40          * `grep get_irn_out *.c` by the irouts.h module.*/
41         compute_outs(chordal_env->session_env->irg);
42
43         co = new_copy_opt(chordal_env, get_costs_all_one);
44         DBG((dbg, LEVEL_1, "----> CO: %s\n", co->name));
45
46
47 #ifdef DO_STAT
48         lower_bound = co_get_lower_bound(co);
49         DBG((dbg, LEVEL_1, "Lower Bound: %3d\n", lower_bound));
50         costs = co_get_copy_costs(co);
51         costs_init = costs;
52         copystat_add_max_costs(co_get_max_copy_costs(co));
53         copystat_add_inevit_costs(co_get_inevit_copy_costs(co));
54         copystat_add_init_costs(costs_init);
55         DBG((dbg, LEVEL_1, "Init costs: %3d\n", costs_init));
56 #endif
57
58 #ifdef DO_HEUR
59         lc_timer_t *timer = lc_timer_register("heur", NULL);
60         lc_timer_start(timer);
61         co_heur_opt(co);
62         lc_timer_stop(timer);
63         copystat_add_heur_time(lc_timer_elapsed_msec(timer));
64 #ifdef DO_STAT
65         costs = co_get_copy_costs(co);
66         costs_heur = costs;
67         copystat_add_heur_costs(costs_heur);
68         DBG((dbg, LEVEL_1, "Heur costs: %3d\n", costs_heur));
69 #endif
70 #endif
71
72 #ifdef DO_ILP
73         co_ilp_opt(co);
74 #ifdef DO_STAT
75         costs = co_get_copy_costs(co);
76         costs_ilp = costs;
77         copystat_add_opt_costs(costs_ilp);
78         DBG((dbg, LEVEL_1, "Opt  costs: %3d\n", costs_ilp));
79 #endif
80 #endif
81         assert(lower_bound <= costs_ilp);
82         assert(costs_ilp <= costs_heur);
83
84         free_copy_opt(co);
85 }