Copied register assignments from in's to out's for all phi-perms.
[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, LEVEL_1);
30 }
31
32 void be_copy_opt(be_chordal_env_t *chordal_env) {
33         copy_opt_t *co;
34         int lb, copy_costs;
35
36         /* BETTER: You can remove this if you replace all `grep get_irn_out *.c`*/
37         compute_outs(chordal_env->session_env->irg);
38
39         co = new_copy_opt(chordal_env, get_costs_loop_depth);
40         DBG((dbg, LEVEL_1, "----> CO: %s\n", co->name));
41
42 #ifdef DO_STAT
43         lb = co_get_lower_bound(co);
44         copy_costs = co_get_copy_costs(co);
45         curr_vals[I_COPIES_INIT] += copy_costs;
46         DBG((dbg, LEVEL_1, "Init costs: %3d <= %3d\n", lb, copy_costs));
47 #endif
48
49 #ifdef DO_HEUR
50         co_heur_opt(co);
51 #ifdef DO_STAT
52         copy_costs = co_get_copy_costs(co);
53         curr_vals[I_COPIES_HEUR] += copy_costs;
54         DBG((dbg, LEVEL_1, "Heur costs: %3d <= %3d\n", lb, copy_costs));
55 #endif
56 #endif
57
58 #ifdef DO_ILP
59         copy_costs = co_get_copy_costs(co);
60         assert(copy_costs>=lb && "At least one computation of these two is boooogy");
61         if (copy_costs > lb) {
62                 co_ilp_opt(co);
63                 be_ra_chordal_check(chordal_env);
64         }
65
66 #ifdef DO_STAT
67         copy_costs = co_get_copy_costs(co);
68         assert(copy_costs>=lb && "At least one computation of these two is boooogy");
69         curr_vals[I_COPIES_OPT] += copy_costs;
70         DBG((dbg, LEVEL_1, "Opt  costs: %3d <= %3d\n", lb, copy_costs));
71 #endif
72 #endif
73
74         free_copy_opt(co);
75 }