509c28fc07dddb14e1f25fe6d71a1146eb27804f
[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 "beutil.h"
35 #include "benumb_t.h"
36 #include "belive_t.h"
37 #include "bera_t.h"
38 #include "bechordal_t.h"
39
40 /**
41  * TODO external things
42  * define get_weight to sth representing the _gain_ if node n and m
43  * have the same color. Must return values MIN_WEIGHT <= . <= MAX_WEIGHT.
44  */
45 #define get_weight(n,m) 1
46 #define is_possible_color(irn, col) 1
47 #define MAX_COLORS 32
48
49 /**
50  * A single unit of optimization. Lots of these form a copy-opt problem
51  */
52 typedef struct _unit_t {
53         struct list_head units;         /**< chain for all units */
54         int interf;                                     /**< number of nodes dropped due to interference */
55         int node_count;                         /**< size of the nodes array */
56         const ir_node **nodes;          /**< [0] is the root-node, others are non interfering args of it. */
57
58         /* for heuristic */
59         int mis_size;                           /**< size of a mis considering only ifg (not coloring conflicts) */
60         struct list_head queue;         /**< list of (mis/color) sorted by size of mis */
61 } unit_t;
62
63 /**
64  * Data representing the problem of copy minimization.
65  */
66 typedef struct _copy_opt_t {
67         ir_graph *irg;                          /**< the irg which is processed */
68         struct list_head units;         /**< all units to optimize in right oreder */
69         pset *roots;                            /**< used only temporary for detecting multiple appends */
70 } copy_opt_t;
71
72
73 /**
74  * Generate the problem. Collect all infos and optimizable nodes.
75  */
76 copy_opt_t *new_copy_opt(ir_graph *irg);
77
78 /**
79  * Free the space...
80  */
81 void free_copy_opt(copy_opt_t *co);
82
83 /**
84  * Returns a lower bound for the number of copies needed based on interfering
85  * arguments and the size of a max indep. set (only ifg-edges) of the other args.
86  */
87 int co_get_lower_bound(copy_opt_t *co);
88
89 /**
90  * Returns the number of arguments interfering with their root node. This also
91  * is a (worse) lower bound for the number of copies needed.
92  */
93 int co_get_interferer_count(copy_opt_t *co);
94
95 /**
96  * Solves the problem using a heuristic approach
97  */
98 void co_heur_opt(copy_opt_t *co);
99
100 /**
101  * Solves the problem using mixed integer programming
102  */
103 void co_ilp_opt(copy_opt_t *co);
104
105 #endif