Made lpp stuff modular.
[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 "becopyopt.h"
16 #include "becopystat.h"
17 #include "becopyoptmain.h"
18
19 #define DO_HEUR
20 #define DO_ILP
21
22 #define DEBUG_LVL SET_LEVEL_1
23 static firm_dbg_module_t *dbg = NULL;
24
25 void be_copy_opt_init(void) {
26         dbg = firm_dbg_register("ir.be.copyopt");
27         firm_dbg_set_mask(dbg, DEBUG_LVL);
28 }
29
30 void be_copy_opt(be_chordal_env_t *chordal_env,
31     const arch_env_t *env, const arch_register_class_t *cls) {
32
33         copy_opt_t *co;
34         int lb, copies;
35         co = new_copy_opt(chordal_env, env, cls);
36         DBG((dbg, LEVEL_1, "\n\n    ===>  %s  <===\n\n", co->name));
37         co_check_allocation(co);
38
39 #ifdef DO_STAT
40         copies = co_get_copy_count(co);
41         curr_vals[I_COPIES_INIT] += copies;
42         DBG((dbg, 1, "Init copies: %3d\n", copies));
43 #endif
44
45 #ifdef DO_HEUR
46         co_heur_opt(co);
47         co_check_allocation(co);
48 #ifdef DO_STAT
49         copies = co_get_copy_count(co);
50         curr_vals[I_COPIES_HEUR] += copies;
51         DBG((dbg, 1, "Heur copies: %3d\n", copies));
52 #endif
53         DBG((dbg, 1, "Heur copies: %3d\n", co_get_copy_count(co)));
54 #endif
55
56 #ifdef DO_ILP
57         lb = co_get_lower_bound(co);
58         copies = co_get_copy_count(co);
59 //TODO remove checks and enable lb
60         if (copies<lb)
61                 DBG((dbg, 0, "\n\nAt least one computation of these two is boooogy %d < %d\n\n", lb, copies));
62
63 //      if (copies > lb) {
64                 co_ilp_opt(co);
65                 co_check_allocation(co);
66 //      }
67         copies = co_get_copy_count(co);
68         assert(copies>=lb && "At least one computation of these two is boooogy");
69
70 #ifdef DO_STAT
71         copies = co_get_copy_count(co);
72         curr_vals[I_COPIES_HEUR] += copies;
73         DBG((dbg, 1, "Opt  copies: %3d\n", copies));
74 #endif
75         DBG((dbg, 1, "Opt  copies: %3d\n", co_get_copy_count(co)));
76 #endif
77
78         free_copy_opt(co);
79 }