Added new arch interface
[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 #include "debug.h"
11 #include "obst.h"
12 #include "list.h"
13 #include "set.h"
14 #include "pset.h"
15 #include "bitset.h"
16 #include "sp_matrix.h"
17
18 #include "irgraph.h"
19 #include "irgwalk.h"
20 #include "irnode.h"
21 #include "irdom.h"
22 #include "irouts.h"
23
24 #include "beutil.h"
25 #include "benumb_t.h"
26 #include "belive_t.h"
27 #include "bera_t.h"
28 #include "bechordal_t.h"
29 #include "bearch.h"
30
31 /* TODO is_Copy */
32 #define is_Copy(irn) 0
33 #define DEBUG_IRG "scanner.c__init_td__gp"
34
35 /**
36  * Data representing the problem of copy minimization.
37  */
38 typedef struct _copy_opt_t {
39         ir_graph *irg;                                          /**< the irg to process */
40         char *name;                                                     /**< ProgName__IrgName__RegClass */
41         const arch_isa_if_t *isa;
42         const arch_register_class_t *cls;       /**< the registerclass all nodes belong to (in this pass) */
43         struct list_head units;                         /**< all units to optimize in right oreder */
44         pset *roots;                                            /**< used only temporary for detecting multiple appends */
45         struct obstack ob;
46 } copy_opt_t;
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         copy_opt_t *co;                         /**< the copy_opt this unit belongs to */
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  * Generate the problem. Collect all infos and optimizable nodes.
65  */
66 copy_opt_t *new_copy_opt(ir_graph *irg, const arch_isa_if_t *isa, const arch_register_class_t *cls);
67
68 /**
69  * Free the space...
70  */
71 void free_copy_opt(copy_opt_t *co);
72
73 /**
74  * Returns the current number of copies needed
75  */
76 int co_get_copy_count(copy_opt_t *co);
77
78 /**
79  * IMPORTANT: Available only iff heuristic has run!
80  * Returns a lower bound for the number of copies needed based on interfering
81  * arguments and the size of a max indep. set (only ifg-edges) of the other args.
82  */
83 int co_get_lower_bound(copy_opt_t *co);
84
85 /**
86  * Returns the number of arguments interfering with their root node. This also
87  * is a (worse) lower bound for the number of copies needed.
88  */
89 int co_get_interferer_count(copy_opt_t *co);
90
91 /**
92  * Solves the problem using a heuristic approach
93  */
94 void co_heur_opt(copy_opt_t *co);
95
96 /**
97  * Solves the problem using mixed integer programming
98  */
99 void co_ilp_opt(copy_opt_t *co);
100
101 /**
102  * Checks the register allocation for correctness
103  */
104 void co_check_allocation(copy_opt_t *co);
105
106 #endif