Add the return type as parameter to the macros set_find() and set_insert().
[libfirm] / ir / be / becopyopt_t.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief       Internal header for copy optimization problem.
23  * @author      Daniel Grund
24  * @date        12.04.2005
25  */
26 #ifndef FIRM_BE_BECOPYOPT_T_H
27 #define FIRM_BE_BECOPYOPT_T_H
28
29 #include "obst.h"
30 #include "list.h"
31 #include "set.h"
32 #include "irnode_t.h"
33
34 #include "bearch.h"
35 #include "bechordal_t.h"
36 #include "becopyopt.h"
37
38 /**
39  * Data representing the problem of copy minimization.
40  */
41 struct copy_opt_t {
42         be_chordal_env_t            *cenv;
43         const arch_register_class_t *cls;
44         ir_graph                    *irg;
45         char                        *name;       /**< ProgName__IrgName__RegClassName */
46         cost_fct_t                  get_costs;   /**< function ptr used to get costs for copies */
47
48         /** Representation as optimization units */
49         struct list_head units;  /**< all units to optimize in specific order */
50
51         /** Representation in graph structure. Only build on demand */
52         struct obstack obst;
53         set    *nodes;
54 };
55
56 /* Helpers */
57 #define ASSERT_OU_AVAIL(co)     assert((co)->units.next && "Representation as optimization-units not build")
58 #define ASSERT_GS_AVAIL(co)     assert((co)->nodes && "Representation as graph not build")
59
60 static inline unsigned get_irn_col(const ir_node *node)
61 {
62         return arch_register_get_index(arch_get_irn_register(node));
63 }
64
65 static inline void set_irn_col(const arch_register_class_t *cls, ir_node *node,
66                                unsigned color)
67 {
68         const arch_register_t *reg = arch_register_for_index(cls, color);
69         arch_set_irn_register(node, reg);
70 }
71
72 #define list_entry_units(lh) list_entry(lh, unit_t, units)
73
74 #define is_Reg_Phi(irn)        (is_Phi(irn) && mode_is_data(get_irn_mode(irn)))
75
76 #define get_Perm_src(irn) (get_irn_n(get_Proj_pred(irn), get_Proj_proj(irn)))
77 #define is_Perm_Proj(irn) (is_Proj(irn) && be_is_Perm(get_Proj_pred(irn)))
78
79 static inline int is_2addr_code(const arch_register_req_t *req)
80 {
81         return (req->type & arch_register_req_type_should_be_same) != 0;
82 }
83
84 /******************************************************************************
85    ____        _   _    _       _ _          _____ _
86   / __ \      | | | |  | |     (_) |        / ____| |
87  | |  | |_ __ | |_| |  | |_ __  _| |_ ___  | (___ | |_ ___  _ __ __ _  __ _  ___
88  | |  | | '_ \| __| |  | | '_ \| | __/ __|  \___ \| __/ _ \| '__/ _` |/ _` |/ _ \
89  | |__| | |_) | |_| |__| | | | | | |_\__ \  ____) | || (_) | | | (_| | (_| |  __/
90   \____/| .__/ \__|\____/|_| |_|_|\__|___/ |_____/ \__\___/|_|  \__,_|\__, |\___|
91         | |                                                            __/ |
92         |_|                                                           |___/
93  ******************************************************************************/
94
95 #define MIS_HEUR_TRIGGER 8
96
97 typedef struct unit_t {
98         struct list_head units;              /**< chain for all units */
99         copy_opt_t       *co;                /**< the copy opt this unit belongs to */
100         int              node_count;         /**< size of the nodes array */
101         ir_node          **nodes;            /**< [0] is the root-node, others are non interfering args of it. */
102         int              *costs;             /**< costs[i] are incurred, if nodes[i] has a different color */
103         int              inevitable_costs;   /**< sum of costs of all args interfering with root */
104         int              all_nodes_costs;    /**< sum of all costs[i] */
105         int              min_nodes_costs;    /**< a lower bound for the costs in costs[], determined by a max independent set */
106         int              sort_key;           /**< maximum costs. controls the order of ou's in the struct list_head units. */
107
108         /* for heuristic */
109         struct list_head queue;              /**< list of qn's sorted by weight of qn-mis */
110 } unit_t;
111
112
113
114 /******************************************************************************
115    _____                 _        _____ _
116   / ____|               | |      / ____| |
117  | |  __ _ __ __ _ _ __ | |__   | (___ | |_ ___  _ __ __ _  __ _  ___
118  | | |_ | '__/ _` | '_ \| '_ \   \___ \| __/ _ \| '__/ _` |/ _` |/ _ \
119  | |__| | | | (_| | |_) | | | |  ____) | || (_) | | | (_| | (_| |  __/
120   \_____|_|  \__,_| .__/|_| |_| |_____/ \__\___/|_|  \__,_|\__, |\___|
121                   | |                                       __/ |
122                   |_|                                      |___/
123  ******************************************************************************/
124
125 typedef struct neighb_t neighb_t;
126 typedef struct affinity_node_t affinity_node_t;
127
128 struct neighb_t {
129         neighb_t *next;   /** the next neighbour entry*/
130         const ir_node  *irn;    /** the neighbour itself */
131         int      costs;   /** the costs of the edge (affinity_node_t->irn, neighb_t->irn) */
132 };
133
134 struct affinity_node_t {
135         const ir_node  *irn;          /** a node with affinity edges */
136         int      degree;        /** number of affinity edges in the linked list below */
137         neighb_t *neighbours;   /** a linked list of all affinity neighbours */
138         void     *data;         /** stuff that is attachable. */
139 };
140
141
142 static inline affinity_node_t *get_affinity_info(const copy_opt_t *co, const ir_node *irn)
143 {
144         affinity_node_t find;
145
146         ASSERT_GS_AVAIL(co);
147
148         find.irn = irn;
149         return set_find(affinity_node_t, co->nodes, &find, sizeof(find), hash_irn(irn));
150 }
151
152 #define co_gs_foreach_aff_node(co, aff_node)     foreach_set((co)->nodes, affinity_node_t, (aff_node))
153 #define co_gs_foreach_neighb(aff_node, neighb)   for (neighb = aff_node->neighbours; neighb != NULL; neighb = neighb->next)
154
155 #endif /* FIRM_BE_BECOPYOPT_T_H */