f16eca8e08353c8c9e8fc92d29e7f8aa0457307b
[libfirm] / ir / be / becopyopt_t.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_T_H
11 #define _BECOPYOPT_T_H
12
13 #include "list.h"
14 #include "bearch.h"
15 #include "bechordal_t.h"
16 #include "becopyopt.h"
17
18 #define MIS_HEUR_TRIGGER 8
19
20 /**
21  * Data representing the problem of copy minimization.
22  */
23 struct _copy_opt_t {
24         be_chordal_env_t *cenv;
25         const arch_register_class_t *cls;
26         const arch_env_t *aenv;
27         ir_graph *irg;
28         char *name;                                             /**< ProgName__IrgName__RegClass */
29
30         struct list_head units;                 /**< all units to optimize in specific order */
31         cost_fct_t get_costs;                   /**< function ptr used to get costs for copies */
32         struct obstack ob;
33 };
34
35 /**
36  * A single unit of optimization. Lots of these form a copy-opt problem
37  */
38 typedef struct _unit_t {
39         struct list_head units;         /**< chain for all units */
40         copy_opt_t *co;                         /**< the copy_opt this unit belongs to */
41         int node_count;                         /**< size of the nodes array */
42         ir_node **nodes;                        /**< [0] is the root-node, others are non interfering args of it. */
43         int *costs;                                     /**< costs[i] are arising, if nodes[i] has a different color */
44         int inevitable_costs;           /**< sum of costs of all args interfering with root */
45         int all_nodes_costs;            /**< sum of all costs[i] */
46         int min_nodes_costs;            /**< a lower bound for the costs in costs[], determined by a max indep. set */
47         int sort_key;                           /**< maximum costs. controls the order of ou's in the struct list_head units. */
48
49         /* for heuristic */
50         struct list_head queue;         /**< list of qn's sorted by weight of qn-mis */
51 } unit_t;
52
53 /* Helpers */
54 #define get_irn_col(co, irn)            arch_register_get_index(arch_get_irn_register((co)->aenv, irn))
55 #define set_irn_col(co, irn, col)       arch_set_irn_register((co)->aenv, irn, arch_register_for_index((co)->cls, col))
56 #define is_curr_reg_class(co, irn)      (arch_get_irn_reg_class((co)->aenv, irn, -1) == (co)->cls)
57
58 #define MIN(a,b) ((a<b)?(a):(b))
59 #define MAX(a,b) ((a<b)?(b):(a))
60
61 #define list_entry_units(lh) list_entry(lh, unit_t, units)
62
63
64 #define get_Copy_src(irn) (get_irn_n(get_Proj_pred(irn), get_Proj_proj(irn)))
65 #define is_Perm(arch_env, irn)                          (arch_irn_classify(arch_env, irn) == arch_irn_class_perm)
66 #define is_Reg_Phi(irn)                                         (is_Phi(irn) && mode_is_data(get_irn_mode(irn)))
67 #define is_Perm_Proj(arch_env, irn)                     (is_Proj(irn) && is_Perm(arch_env, get_Proj_pred(irn)))
68 #define is_2addr_code(arch_env, irn, req)       (arch_get_register_req(arch_env, req, irn, -1)->type == arch_register_req_type_should_be_same)
69
70 /**
71  * Checks if a node is optimizable, viz. has somthing to do with coalescing
72  * @param arch The architecture environment
73  * @param irn  The irn to check
74  * @param req  A register_requirement structure (used to check for 2-addr-code)
75  */
76 #define co_is_optimizable(arch, irn, req) (!arch_irn_is_ignore(arch, irn) && (is_Reg_Phi(irn) || is_Perm_Proj(arch, irn) || is_2addr_code(arch, irn, req)))
77
78 /**
79  * Checks if the irn is a non-interfering argument of a node which 'is_optimizable'
80  */
81 int co_is_optimizable_arg(const copy_opt_t *co, ir_node *irn);
82
83 /**
84  * Returns the maximal costs possible, i.e. the costs if all
85  * pairs would be assigned different registers.
86  */
87 int co_get_max_copy_costs(const copy_opt_t *co);
88
89 /**
90  * Returns the inevitable costs, i.e. the costs of
91  * all copy pairs which interfere.
92  */
93 int co_get_inevit_copy_costs(const copy_opt_t *co);
94
95 /**
96  * Returns the current costs the copies are causing.
97  * The result includes inevitable costs and the costs
98  * of the copies regarding the current register allocation
99  */
100 int co_get_copy_costs(const copy_opt_t *co);
101
102 /**
103  * Returns a lower bound for the costs of copies in this ou.
104  * The result includes inevitable costs and the costs of a
105  * minimal costs caused by the nodes of the ou.
106  */
107 int co_get_lower_bound(const copy_opt_t *co);
108
109
110 #endif