- moved the imul mem,imm32 splitting into peephole optimizations
[libfirm] / ir / be / becopyilp_t.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief       Common stuff used by all ILP formulations.
23  * @author      Daniel Grund
24  * @date        28.02.2006
25  * @version     $Id$
26  */
27 #ifndef FIRM_BE_BECOPYILP_T_H
28 #define FIRM_BE_BECOPYILP_T_H
29
30 #include "firm_config.h"
31 #include "firm_types.h"
32 #include "pset.h"
33 #include "becopyopt_t.h"
34
35 /******************************************************************************
36     _____ _                        _            _   _
37    / ____(_)                      | |          | | (_)
38   | (___  _ _______   _ __ ___  __| |_   _  ___| |_ _  ___  _ __
39    \___ \| |_  / _ \ | '__/ _ \/ _` | | | |/ __| __| |/ _ \| '_ \
40    ____) | |/ /  __/ | | |  __/ (_| | |_| | (__| |_| | (_) | | | |
41   |_____/|_/___\___| |_|  \___|\__,_|\__,_|\___|\__|_|\___/|_| |_|
42
43  *****************************************************************************/
44
45 typedef struct _coloring_suffix_t coloring_suffix_t;
46
47 struct _coloring_suffix_t {
48         coloring_suffix_t *next;
49         ir_node           *irn;
50 };
51
52 typedef struct _size_red_t {
53         copy_opt_t        *co;
54         pset              *all_removed;   /**< All nodes removed during problem size reduction */
55         coloring_suffix_t *col_suff;      /**< Coloring suffix. Reverse would be a PEO prefix */
56         struct obstack    ob;
57 } size_red_t;
58
59 /**
60  * Just prepare. Do nothing yet.
61  */
62 size_red_t *new_size_red(copy_opt_t *co);
63
64 /**
65  * Checks if a node has already been removed
66  */
67 #define sr_is_removed(sr, irn)          pset_find_ptr((sr)->all_removed, irn)
68
69 /**
70  * Virtually remove all nodes not related to the problem
71  * (simplicial AND not adjacent to a equal-color-edge)
72  */
73 void sr_remove(size_red_t *sr);
74
75 /**
76  * Virtually reinsert the nodes removed before and color them
77  */
78 void sr_reinsert(size_red_t *sr);
79
80 /**
81  * Free all space...
82  */
83 void free_size_red(size_red_t *sr);
84
85 /**
86  * TODO: This search is necessary because during the construction of the
87  *       units (ou's) args could be merged and weights are accumulated.
88  *       Is this necessary?
89  */
90 static INLINE int co_ilp_get_costs(copy_opt_t *co, ir_node *root, ir_node *arg) {
91         int    i;
92         unit_t *curr;
93
94         /* search optimization unit for phi */
95         list_for_each_entry(unit_t, curr, &co->units, units)
96                 if (curr->nodes[0] == root) {
97
98                         for (i = 1; i < curr->node_count; ++i)
99                                 if (curr->nodes[i] == arg)
100                                         return curr->costs[i];
101
102                                 assert(0 && "irn must occur in this ou");
103                 }
104
105         assert(0 && "phi must be found in a ou");
106         return 0;
107 }
108
109 /******************************************************************************
110     _____                      _        _____ _      _____
111    / ____|                    (_)      |_   _| |    |  __ \
112   | |  __  ___ _ __   ___ _ __ _  ___    | | | |    | |__) |
113   | | |_ |/ _ \ '_ \ / _ \ '__| |/ __|   | | | |    |  ___/
114   | |__| |  __/ | | |  __/ |  | | (__   _| |_| |____| |
115    \_____|\___|_| |_|\___|_|  |_|\___| |_____|______|_|
116
117  *****************************************************************************/
118
119 #ifdef WITH_ILP
120 #include <lpp/lpp.h>
121
122 #define LPP_SOLVE_NET
123
124 #ifdef LPP_SOLVE_NET
125 #  include <lpp/lpp_net.h>
126 #else
127 #  include <lpp/lpp_cplex.h>
128 #endif
129
130 #define EPSILON 0.00001
131
132 typedef struct _ilp_env_t ilp_env_t;
133
134 typedef void(*ilp_callback)(ilp_env_t*);
135
136 struct _ilp_env_t {
137         const copy_opt_t *co;   /**< the copy opt problem */
138         size_red_t       *sr;   /**< problem size reduction. removes simple nodes */
139         lpp_t            *lp;   /**< the linear programming problem */
140         void             *env;
141         ilp_callback     build;
142         ilp_callback     apply;
143 };
144
145 ilp_env_t *new_ilp_env(copy_opt_t *co, ilp_callback build, ilp_callback apply, void *env);
146
147 lpp_sol_state_t ilp_go(ilp_env_t *ienv);
148
149 void free_ilp_env(ilp_env_t *ienv);
150
151
152 #define name_cdd(buf, char1, int1, int2) \
153                         (snprintf(buf, sizeof(buf), "%c_%d_%d", char1, int1, int2), buf)
154
155 #define name_cdd_sorted(buf, char1, int1, int2) \
156                         name_cdd(buf, char1, MIN(int1, int2), MAX(int1, int2))
157
158 #endif /* WITH_ILP */
159
160 #endif /* FIRM_BE_BECOPYILP_T_H */