a6480641e6bc63c45ff37f6c1be7627eabbf7ec2
[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 "becopyopt.h"
17 #include "becopystat.h"
18 #include "becopyoptmain.h"
19
20 #define DO_HEUR
21 #undef DO_ILP
22
23 #define DEBUG_LVL SET_LEVEL_1
24 static firm_dbg_module_t *dbg = NULL;
25
26 void be_copy_opt_init(void) {
27         dbg = firm_dbg_register("ir.be.copyoptmain");
28         firm_dbg_set_mask(dbg, LEVEL_1);
29 }
30
31 void be_copy_opt(be_chordal_env_t *chordal_env) {
32         copy_opt_t *co;
33         int lb, copy_costs;
34
35         co = new_copy_opt(chordal_env, get_costs_loop_depth);
36         DBG((dbg, LEVEL_1, "===>  %s  <===\n", co->name));
37
38 #ifdef DO_STAT
39         copy_costs = co_get_copy_costs(co);
40         curr_vals[I_COPIES_INIT] += copy_costs;
41         DBG((dbg, LEVEL_1, "Init costs: %3d\n", copy_costs));
42 #endif
43
44 #ifdef DO_HEUR
45         co_heur_opt(co);
46         be_ra_chordal_check(chordal_env);
47 #ifdef DO_STAT
48         copy_costs = co_get_copy_costs(co);
49         curr_vals[I_COPIES_HEUR] += copy_costs;
50         DBG((dbg, LEVEL_1, "Heur costs: %3d\n", copy_costs));
51 #endif
52 #endif
53
54 #ifdef DO_ILP
55         lb = co_get_lower_bound(co);
56         copy_costs = co_get_copy_costs(co);
57         assert(copy_costs>=lb && "At least one computation of these two is boooogy");
58
59         if (copy_costs > lb) {
60                 co_ilp_opt(co);
61                 be_ra_chordal_check(chordal_env);
62         }
63
64 #ifdef DO_STAT
65         copy_costs = co_get_copy_costs(co);
66         curr_vals[I_COPIES_OPT] += copy_costs;
67         DBG((dbg, LEVEL_1, "Opt  costs: %3d\n", copy_costs));
68         assert(copy_costs>=lb && "At least one computation of these two is boooogy");
69 #endif
70 #endif
71
72         free_copy_opt(co);
73 }