4b9401bf15d0804e8477728f129a9ba3d7699d8c
[libfirm] / ir / be / becopyopt.h
1 /**
2  * Header for copy optimization problem. Analysis and set up of the problem.
3  * @author Daniel Grund
4  * @date 12.04.2005
5  */
6
7 #ifndef _BECOPYOPT_H
8 #define _BECOPYOPT_H
9
10 #ifdef HAVE_CONFIG_H
11 #include "config.h"
12 #endif
13
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <alloca.h>
17 #include <sys/types.h>
18 #include <sys/stat.h>
19
20 #include "debug.h"
21 #include "obst.h"
22 #include "list.h"
23 #include "set.h"
24 #include "pset.h"
25 #include "bitset.h"
26 #include "sp_matrix.h"
27
28 #include "irgraph.h"
29 #include "irgwalk.h"
30 #include "irnode.h"
31 #include "irdom.h"
32 #include "irouts.h"
33
34 #include "benumb_t.h"
35 #include "belive_t.h"
36 #include "bera_t.h"
37 #include "bechordal_t.h"
38
39 /**
40  * TODO THIS EXTERNAL THINGS
41  * define get_weight to sth representing the _gain_ if node n and m
42  * have the same color. Must return values MIN_WEIGHT <= . <= MAX_WEIGHT.
43  */
44 #define get_weight(n,m) 1
45 #define is_possible_color(irn, col) 1
46 #define MAX_COLORS 32
47
48 /**
49  * A single unit of optimization. Lots of these form a copy-opt problem
50  */
51 typedef struct _unit_t {
52         struct list_head units;         /**< chain for all units */
53         int interf;                                     /**< number of nodes dropped due to interference */
54         int node_count;                         /**< size of the nodes array */
55         const ir_node **nodes;          /**< [0] is the root-node, others are non interfering args of it. */
56
57         /* for heuristic */
58         int mis_size;                           /**< size of a mis considering only ifg (not coloring conflicts) */
59         struct list_head queue;         /**< list of (mis/color) sorted by size of mis */
60 } unit_t;
61
62 /**
63  * Data representing the problem of copy minimization.
64  */
65 typedef struct _copy_opt_t {
66         ir_graph *irg;                          /**< the irg which is processed */
67         struct list_head units;         /**< all units to optimize in right oreder */
68         pset *roots;                            /**< used only temporary for detecting multiple appends */
69
70         /* for heuristic */
71         pset *pinned_global;            /**< optimized nodes should not be altered any more */
72 } copy_opt_t;
73
74
75 /**
76  * Generate the problem. Collect all infos and optimizable nodes.
77  */
78 copy_opt_t *new_copy_opt(ir_graph *irg);
79
80 /**
81  * Free the space...
82  */
83 void free_copy_opt(copy_opt_t *co);
84
85 /**
86  * Returns a lower bound for the number of copies needed based on interfering
87  * arguments and the size of a max indep. set (only ifg-edges) of the other args.
88  */
89 int co_get_lower_bound(copy_opt_t *co);
90
91 /**
92  * Returns the number of arguments interfering with their root node. This also
93  * is a (worse) lower bound for the number of copies needed.
94  */
95 int co_get_interferer_count(copy_opt_t *co);
96
97 /**
98  * Solves the problem using a heuristic approach
99  */
100 void co_heur_opt(copy_opt_t *co);
101
102 /**
103  * Solves the problem using mixed integer programming
104  */
105 void co_ilp_opt(copy_opt_t *co);
106
107 #endif