349593e88711c752e57dc1dbf542822d2eea8492
[libfirm] / ir / be / becopyilp_t.h
1 /**
2  * Author:      Daniel Grund
3  * Date:                28.02.2006
4  * Copyright:   (c) Universitaet Karlsruhe
5  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
6  *
7  * Common stuff used by all ILP fomulations.
8  *
9  */
10
11 #ifndef _BECOPYILP_T_H
12 #define _BECOPYILP_T_H
13
14 #ifdef HAVE_CONFIG_H
15 #include "config.h"
16 #endif
17 #ifdef HAVE_ALLOCA_H
18 #include <alloca.h>
19 #endif
20 #ifdef HAVE_MALLOC_H
21 #include <malloc.h>
22 #endif
23
24 #include "irnode_t.h"
25 #include "pset.h"
26 #include "becopyopt_t.h"
27
28 /******************************************************************************
29     _____ _                        _            _   _
30    / ____(_)                      | |          | | (_)
31   | (___  _ _______   _ __ ___  __| |_   _  ___| |_ _  ___  _ __
32    \___ \| |_  / _ \ | '__/ _ \/ _` | | | |/ __| __| |/ _ \| '_ \
33    ____) | |/ /  __/ | | |  __/ (_| | |_| | (__| |_| | (_) | | | |
34   |_____/|_/___\___| |_|  \___|\__,_|\__,_|\___|\__|_|\___/|_| |_|
35
36  *****************************************************************************/
37
38 typedef struct _coloring_suffix_t coloring_suffix_t;
39
40 struct _coloring_suffix_t {
41         coloring_suffix_t *next;
42         ir_node *irn;
43 };
44
45 typedef struct _size_red_t {
46         copy_opt_t *co;
47         pset *all_removed;                              /**< All nodes removed during problem size reduction */
48         coloring_suffix_t *col_suff;    /**< Coloring suffix. Reverse would be a PEO prefix */
49         struct obstack ob;
50 } size_red_t;
51
52 /**
53  * Just prepare. Do nothing yet.
54  */
55 size_red_t *new_size_red(copy_opt_t *co);
56
57 /**
58  * Checks if a node has already been removed
59  */
60 #define sr_is_removed(sr, irn)          pset_find_ptr((sr)->all_removed, irn)
61
62 /**
63  * Virtually remove all nodes not related to the problem
64  * (simplicial AND not adjacent to a equal-color-edge)
65  */
66 void sr_remove(size_red_t *sr);
67
68 /**
69  * Virtually reinsert the nodes removed before and color them
70  */
71 void sr_reinsert(size_red_t *sr);
72
73 /**
74  * Free all space...
75  */
76 void free_size_red(size_red_t *sr);
77
78 /**
79  * TODO: This search is necessary because during the construction of the
80  *       units (ou's) args could be merged and weights are accumulated.
81  *       Is this necessary?
82  */
83 static INLINE int co_ilp_get_costs(copy_opt_t *co, ir_node *root, ir_node *arg) {
84         int i;
85         unit_t *curr;
86
87         /* search optimization unit for phi */
88         list_for_each_entry(unit_t, curr, &co->units, units)
89                 if (curr->nodes[0] == root) {
90
91                         for (i=1; i<curr->node_count; ++i)
92                                 if (curr->nodes[i] == arg)
93                                         return curr->costs[i];
94
95                                 assert(0 && "irn must occur in this ou");
96                 }
97
98         assert(0 && "phi must be found in a ou");
99         return 0;
100 }
101
102 /******************************************************************************
103     _____                      _        _____ _      _____
104    / ____|                    (_)      |_   _| |    |  __ \
105   | |  __  ___ _ __   ___ _ __ _  ___    | | | |    | |__) |
106   | | |_ |/ _ \ '_ \ / _ \ '__| |/ __|   | | | |    |  ___/
107   | |__| |  __/ | | |  __/ |  | | (__   _| |_| |____| |
108    \_____|\___|_| |_|\___|_|  |_|\___| |_____|______|_|
109
110  *****************************************************************************/
111
112 #include <lpp/lpp.h>
113
114 #undef LPP_SOLVE_NET
115
116 #ifdef LPP_SOLVE_NET
117 #  include <lpp/lpp_net.h>
118 #  define LPP_HOST "i44pc52"
119 #  define LPP_SOLVER "cplex"
120 #else
121 #  include <lpp/lpp_cplex.h>
122 #endif
123
124 #define EPSILON 0.00001
125
126 typedef struct _ilp_env_t ilp_env_t;
127
128 typedef void(*ilp_callback)(ilp_env_t*);
129
130 struct _ilp_env_t {
131         const copy_opt_t *co;                   /**< the copy opt problem */
132         size_red_t *sr;                                 /**< problem size reduction. removes simple nodes */
133         lpp_t *lp;                                              /**< the linear programming problem */
134         void *env;
135         ilp_callback build;
136         ilp_callback apply;
137
138 };
139
140 ilp_env_t *new_ilp_env(copy_opt_t *co, ilp_callback build, ilp_callback apply, void *env);
141
142 lpp_sol_state_t ilp_go(ilp_env_t *ienv);
143
144 void free_ilp_env(ilp_env_t *ienv);
145
146
147 #define name_cdd(buf, char1, int1, int2) \
148                         (snprintf(buf, sizeof(buf), "%c_%d_%d", char1, int1, int2), buf)
149
150 #define name_cdd_sorted(buf, char1, int1, int2) \
151                         name_cdd(buf, char1, MIN(int1, int2), MAX(int1, int2))
152
153 #endif