b13bd0753ec806aa895cc8a2d7cf23e8b851db74
[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 <string.h>
18 #include <sys/types.h>
19 #include <sys/stat.h>
20
21 #include "debug.h"
22 #include "obst.h"
23 #include "list.h"
24 #include "set.h"
25 #include "pset.h"
26 #include "bitset.h"
27 #include "sp_matrix.h"
28
29 #include "irgraph.h"
30 #include "irgwalk.h"
31 #include "irnode.h"
32 #include "irdom.h"
33 #include "irouts.h"
34
35 #include "beutil.h"
36 #include "benumb_t.h"
37 #include "belive_t.h"
38 #include "bera_t.h"
39 #include "bechordal_t.h"
40 #include "bearch.h"
41
42 /* TODO is_Copy */
43 #define is_Copy(irn) 0
44 #define DEBUG_IRG "scanner.c__init_td__gp"
45
46 /**
47  * Data representing the problem of copy minimization.
48  */
49 typedef struct _copy_opt_t {
50         ir_graph *irg;                                          /**< the irg to process */
51         char *name;                                                     /**< ProgName__IrgName__RegClass */
52         const arch_isa_if_t *isa;
53         const arch_register_class_t *cls;       /**< the registerclass all nodes belong to (in this pass) */
54         struct list_head units;                         /**< all units to optimize in right oreder */
55         pset *roots;                                            /**< used only temporary for detecting multiple appends */
56         struct obstack ob;
57 } copy_opt_t;
58
59 /**
60  * A single unit of optimization. Lots of these form a copy-opt problem
61  */
62 typedef struct _unit_t {
63         struct list_head units;         /**< chain for all units */
64         copy_opt_t *co;                         /**< the copy_opt this unit belongs to */
65         int interf;                                     /**< number of nodes dropped due to interference */
66         int node_count;                         /**< size of the nodes array */
67         const ir_node **nodes;          /**< [0] is the root-node, others are non interfering args of it. */
68
69         /* for heuristic */
70         int mis_size;                           /**< size of a mis considering only ifg (not coloring conflicts) */
71         struct list_head queue;         /**< list of (mis/color) sorted by size of mis */
72 } unit_t;
73
74 /**
75  * Generate the problem. Collect all infos and optimizable nodes.
76  */
77 copy_opt_t *new_copy_opt(ir_graph *irg, const arch_isa_if_t *isa, const arch_register_class_t *cls);
78
79 /**
80  * Free the space...
81  */
82 void free_copy_opt(copy_opt_t *co);
83
84 /**
85  * Returns the current number of copies needed
86  */
87 int co_get_copy_count(copy_opt_t *co);
88
89 /**
90  * IMPORTANT: Available only iff heuristic has run!
91  * Returns a lower bound for the number of copies needed based on interfering
92  * arguments and the size of a max indep. set (only ifg-edges) of the other args.
93  */
94 int co_get_lower_bound(copy_opt_t *co);
95
96 /**
97  * Returns the number of arguments interfering with their root node. This also
98  * is a (worse) lower bound for the number of copies needed.
99  */
100 int co_get_interferer_count(copy_opt_t *co);
101
102 /**
103  * Solves the problem using a heuristic approach
104  */
105 void co_heur_opt(copy_opt_t *co);
106
107 /**
108  * Solves the problem using mixed integer programming
109  */
110 void co_ilp_opt(copy_opt_t *co);
111
112 /**
113  * Checks the register allocation for correctness
114  */
115 void co_check_allocation(copy_opt_t *co);
116
117 #endif