becopyopt: Remove the attribute copy_opt_t* co from struct unit_t.
[libfirm] / ir / be / becopyopt_t.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief       Internal header for copy optimization problem.
9  * @author      Daniel Grund
10  * @date        12.04.2005
11  */
12 #ifndef FIRM_BE_BECOPYOPT_T_H
13 #define FIRM_BE_BECOPYOPT_T_H
14
15 #include "obst.h"
16 #include "list.h"
17 #include "set.h"
18 #include "irnode_t.h"
19
20 #include "bearch.h"
21 #include "bechordal_t.h"
22 #include "becopyopt.h"
23
24 /**
25  * Data representing the problem of copy minimization.
26  */
27 struct copy_opt_t {
28         be_chordal_env_t            *cenv;
29         const arch_register_class_t *cls;
30         ir_graph                    *irg;
31         cost_fct_t                  get_costs;   /**< function ptr used to get costs for copies */
32
33         /** Representation as optimization units */
34         struct list_head units;  /**< all units to optimize in specific order */
35
36         /** Representation in graph structure. Only build on demand */
37         struct obstack obst;
38         set    *nodes;
39 };
40
41 /* Helpers */
42 #define ASSERT_OU_AVAIL(co)     assert((co)->units.next && "Representation as optimization-units not built")
43 #define ASSERT_GS_AVAIL(co)     assert((co)->nodes && "Representation as graph not built")
44
45 static inline unsigned get_irn_col(const ir_node *node)
46 {
47         return arch_get_irn_register(node)->index;
48 }
49
50 static inline void set_irn_col(const arch_register_class_t *cls, ir_node *node,
51                                unsigned color)
52 {
53         const arch_register_t *reg = arch_register_for_index(cls, color);
54         arch_set_irn_register(node, reg);
55 }
56
57 #define list_entry_units(lh) list_entry(lh, unit_t, units)
58
59 #define is_Reg_Phi(irn)        (is_Phi(irn) && mode_is_data(get_irn_mode(irn)))
60
61 #define get_Perm_src(irn) (get_irn_n(get_Proj_pred(irn), get_Proj_proj(irn)))
62 #define is_Perm_Proj(irn) (is_Proj(irn) && be_is_Perm(get_Proj_pred(irn)))
63
64 /******************************************************************************
65    ____        _   _    _       _ _          _____ _
66   / __ \      | | | |  | |     (_) |        / ____| |
67  | |  | |_ __ | |_| |  | |_ __  _| |_ ___  | (___ | |_ ___  _ __ __ _  __ _  ___
68  | |  | | '_ \| __| |  | | '_ \| | __/ __|  \___ \| __/ _ \| '__/ _` |/ _` |/ _ \
69  | |__| | |_) | |_| |__| | | | | | |_\__ \  ____) | || (_) | | | (_| | (_| |  __/
70   \____/| .__/ \__|\____/|_| |_|_|\__|___/ |_____/ \__\___/|_|  \__,_|\__, |\___|
71         | |                                                            __/ |
72         |_|                                                           |___/
73  ******************************************************************************/
74
75 #define MIS_HEUR_TRIGGER 8
76
77 typedef struct unit_t {
78         struct list_head units;              /**< chain for all units */
79         int              node_count;         /**< size of the nodes array */
80         ir_node          **nodes;            /**< [0] is the root-node, others are non interfering args of it. */
81         int              *costs;             /**< costs[i] are incurred, if nodes[i] has a different color */
82         int              inevitable_costs;   /**< sum of costs of all args interfering with root */
83         int              all_nodes_costs;    /**< sum of all costs[i] */
84         int              min_nodes_costs;    /**< a lower bound for the costs in costs[], determined by a max independent set */
85         int              sort_key;           /**< maximum costs. controls the order of ou's in the struct list_head units. */
86
87         /* for heuristic */
88         struct list_head queue;              /**< list of qn's sorted by weight of qn-mis */
89 } unit_t;
90
91
92
93 /******************************************************************************
94    _____                 _        _____ _
95   / ____|               | |      / ____| |
96  | |  __ _ __ __ _ _ __ | |__   | (___ | |_ ___  _ __ __ _  __ _  ___
97  | | |_ | '__/ _` | '_ \| '_ \   \___ \| __/ _ \| '__/ _` |/ _` |/ _ \
98  | |__| | | | (_| | |_) | | | |  ____) | || (_) | | | (_| | (_| |  __/
99   \_____|_|  \__,_| .__/|_| |_| |_____/ \__\___/|_|  \__,_|\__, |\___|
100                   | |                                       __/ |
101                   |_|                                      |___/
102  ******************************************************************************/
103
104 typedef struct neighb_t neighb_t;
105 typedef struct affinity_node_t affinity_node_t;
106
107 struct neighb_t {
108         neighb_t *next;   /** the next neighbour entry*/
109         const ir_node  *irn;    /** the neighbour itself */
110         int      costs;   /** the costs of the edge (affinity_node_t->irn, neighb_t->irn) */
111 };
112
113 struct affinity_node_t {
114         const ir_node  *irn;          /** a node with affinity edges */
115         int      degree;        /** number of affinity edges in the linked list below */
116         neighb_t *neighbours;   /** a linked list of all affinity neighbours */
117         void     *data;         /** stuff that is attachable. */
118 };
119
120
121 static inline affinity_node_t *get_affinity_info(const copy_opt_t *co, const ir_node *irn)
122 {
123         affinity_node_t find;
124
125         ASSERT_GS_AVAIL(co);
126
127         find.irn = irn;
128         return set_find(affinity_node_t, co->nodes, &find, sizeof(find), hash_irn(irn));
129 }
130
131 #define co_gs_foreach_aff_node(co, aff_node)     foreach_set((co)->nodes, affinity_node_t, (aff_node))
132 #define co_gs_foreach_neighb(aff_node, neighb)   for (neighb_t *neighb = aff_node->neighbours; neighb; neighb = neighb->next)
133
134 #endif /* FIRM_BE_BECOPYOPT_T_H */