c2ee3aa0b4db779240fd599bc3ceeca49a8e507b
[libfirm] / ir / be / becopyopt.h
1 /**
2  * Author:      Daniel Grund
3  * Date:                12.04.2005
4  * Copyright:   (c) Universitaet Karlsruhe
5  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
6  *
7  * Header for copy optimization problem. Analysis and set up of the problem.
8  */
9
10 #ifndef _BECOPYOPT_H
11 #define _BECOPYOPT_H
12
13 #include "debug.h"
14 #include "obst.h"
15 #include "list.h"
16 #include "set.h"
17 #include "pset.h"
18 #include "bitset.h"
19 #include "sp_matrix.h"
20
21 #include "irgraph.h"
22 #include "irgwalk.h"
23 #include "irnode.h"
24 #include "irdom.h"
25 #include "irouts.h"
26
27 #include "beutil.h"
28 #include "benumb_t.h"
29 #include "belive_t.h"
30 #include "bera_t.h"
31 #include "bechordal_t.h"
32 #include "bearch.h"
33
34 /* TODO is_Copy */
35 #define is_Copy(irn) 0
36 #define DEBUG_IRG "-scanner.c__init_td__gp"
37
38 /**
39  * Data representing the problem of copy minimization.
40  */
41 typedef struct _copy_opt_t {
42         ir_graph *irg;                                          /**< the irg to process */
43         char *name;                                                     /**< ProgName__IrgName__RegClass */
44         const arch_env_t *env;                          /**< Environment (isa + handlers) */
45         const arch_register_class_t *cls;       /**< the registerclass all nodes belong to (in this pass) */
46         struct list_head units;                         /**< all units to optimize in right order */
47         pset *roots;                                            /**< used only temporary for detecting multiple appends */
48         struct obstack ob;
49 } copy_opt_t;
50
51 /**
52  * A single unit of optimization. Lots of these form a copy-opt problem
53  */
54 typedef struct _unit_t {
55         struct list_head units;         /**< chain for all units */
56         copy_opt_t *co;                         /**< the copy_opt this unit belongs to */
57         int interf;                                     /**< number of nodes dropped due to interference */
58         int node_count;                         /**< size of the nodes array */
59         ir_node **nodes;                        /**< [0] is the root-node, others are non interfering args of it. */
60
61         /* for heuristic */
62         int mis_size;                           /**< size of a mis considering only ifg (not coloring conflicts) */
63         struct list_head queue;         /**< list of (mis/color) sorted by size of mis */
64 } unit_t;
65
66 /* Helpers */
67 #define set_irn_col(co, irn, col) \
68         arch_set_irn_register(co->env, irn, 0, arch_register_for_index(co->cls, col))
69
70 #define get_irn_col(co, irn) \
71         arch_register_get_index(arch_get_irn_register(co->env, irn, 0))
72
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_env_t *env, const arch_register_class_t *cls);
78
79 /**
80  * Free the space...
81  */
82 void free_copy_opt(copy_opt_t *co);
83
84 #define is_optimizable(irn) (is_Phi(irn) || is_Copy(irn))
85
86 /**
87  * Checks if the irn is a non-interfering argument of a node which 'is_optimizable'
88  */
89 int is_optimizable_arg(ir_node *irn);
90
91 /**
92  * Returns the current number of copies needed
93  */
94 int co_get_copy_count(copy_opt_t *co);
95
96 /**
97  * IMPORTANT: Available only iff heuristic has run!
98  * Returns a lower bound for the number of copies needed based on interfering
99  * arguments and the size of a max indep. set (only ifg-edges) of the other args.
100  */
101 int co_get_lower_bound(copy_opt_t *co);
102
103 /**
104  * Returns the number of arguments interfering with their root node. This also
105  * is a (worse) lower bound for the number of copies needed.
106  */
107 int co_get_interferer_count(copy_opt_t *co);
108
109 /**
110  * Solves the problem using a heuristic approach
111  */
112 void co_heur_opt(copy_opt_t *co);
113
114 /**
115  * Solves the problem using mixed integer programming
116  */
117 void co_ilp_opt(copy_opt_t *co);
118
119 /**
120  * Checks the register allocation for correctness
121  */
122 void co_check_allocation(copy_opt_t *co);
123
124 #endif