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