reorganize backend headers (kill some _t variants in favor of a be_types.h)
[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  * @version     $Id$
26  */
27 #ifndef FIRM_BE_BECOPYOPT_T_H
28 #define FIRM_BE_BECOPYOPT_T_H
29
30 #include "obst.h"
31 #include "list.h"
32 #include "set.h"
33 #include "irnode_t.h"
34
35 #include "bearch.h"
36 #include "bechordal_t.h"
37 #include "becopyopt.h"
38
39 /**
40  * Data representing the problem of copy minimization.
41  */
42 struct _copy_opt_t {
43         be_chordal_env_t            *cenv;
44         const arch_register_class_t *cls;
45         ir_graph                    *irg;
46         char                        *name;       /**< ProgName__IrgName__RegClassName */
47         cost_fct_t                  get_costs;   /**< function ptr used to get costs for copies */
48
49         /** Representation as optimization units */
50         struct list_head units;    /**< all units to optimize in specific order */
51
52         /** Representation in graph structure. Only build on demand */
53         struct obstack obst;
54         set    *nodes;
55 };
56
57 /* Helpers */
58 #define ASSERT_OU_AVAIL(co)             assert((co)->units.next && "Representation as optimization-units not build")
59 #define ASSERT_GS_AVAIL(co)             assert((co)->nodes && "Representation as graph not build")
60
61 #define get_irn_col(irn)          arch_register_get_index(arch_get_irn_register(irn))
62 #define set_irn_col(co, irn, col) arch_set_irn_register(irn, arch_register_for_index((co)->cls, col))
63
64 #define list_entry_units(lh) list_entry(lh, unit_t, units)
65
66 #define is_Reg_Phi(irn)                                         (is_Phi(irn) && mode_is_data(get_irn_mode(irn)))
67
68 #define get_Perm_src(irn) (get_irn_n(get_Proj_pred(irn), get_Proj_proj(irn)))
69 #define is_Perm_Proj(irn) (is_Proj(irn) && be_is_Perm(get_Proj_pred(irn)))
70
71 static inline int is_2addr_code(const arch_register_req_t *req)
72 {
73         return (req->type & arch_register_req_type_should_be_same) != 0;
74 }
75
76 /******************************************************************************
77    ____        _   _    _       _ _          _____ _
78   / __ \      | | | |  | |     (_) |        / ____| |
79  | |  | |_ __ | |_| |  | |_ __  _| |_ ___  | (___ | |_ ___  _ __ __ _  __ _  ___
80  | |  | | '_ \| __| |  | | '_ \| | __/ __|  \___ \| __/ _ \| '__/ _` |/ _` |/ _ \
81  | |__| | |_) | |_| |__| | | | | | |_\__ \  ____) | || (_) | | | (_| | (_| |  __/
82   \____/| .__/ \__|\____/|_| |_|_|\__|___/ |_____/ \__\___/|_|  \__,_|\__, |\___|
83         | |                                                            __/ |
84         |_|                                                           |___/
85  ******************************************************************************/
86
87 #define MIS_HEUR_TRIGGER 8
88
89 typedef struct _unit_t {
90         struct list_head units;              /**< chain for all units */
91         copy_opt_t       *co;                /**< the copy opt this unit belongs to */
92         int              node_count;         /**< size of the nodes array */
93         ir_node          **nodes;            /**< [0] is the root-node, others are non interfering args of it. */
94         int              *costs;             /**< costs[i] are incurred, if nodes[i] has a different color */
95         int              inevitable_costs;   /**< sum of costs of all args interfering with root */
96         int              all_nodes_costs;    /**< sum of all costs[i] */
97         int              min_nodes_costs;    /**< a lower bound for the costs in costs[], determined by a max independent set */
98         int              sort_key;           /**< maximum costs. controls the order of ou's in the struct list_head units. */
99
100         /* for heuristic */
101         struct list_head queue;                  /**< list of qn's sorted by weight of qn-mis */
102 } unit_t;
103
104
105
106 /******************************************************************************
107    _____                 _        _____ _
108   / ____|               | |      / ____| |
109  | |  __ _ __ __ _ _ __ | |__   | (___ | |_ ___  _ __ __ _  __ _  ___
110  | | |_ | '__/ _` | '_ \| '_ \   \___ \| __/ _ \| '__/ _` |/ _` |/ _ \
111  | |__| | | | (_| | |_) | | | |  ____) | || (_) | | | (_| | (_| |  __/
112   \_____|_|  \__,_| .__/|_| |_| |_____/ \__\___/|_|  \__,_|\__, |\___|
113                   | |                                       __/ |
114                   |_|                                      |___/
115  ******************************************************************************/
116
117 typedef struct _neighb_t neighb_t;
118 typedef struct _affinity_node_t affinity_node_t;
119
120 struct _neighb_t {
121         neighb_t *next;   /** the next neighbour entry*/
122         const ir_node  *irn;    /** the neighbour itself */
123         int      costs;   /** the costs of the edge (affinity_node_t->irn, neighb_t->irn) */
124 };
125
126 struct _affinity_node_t {
127         const ir_node  *irn;          /** a node with affinity edges */
128         int      degree;        /** number of affinity edges in the linked list below */
129         neighb_t *neighbours;   /** a linked list of all affinity neighbours */
130         void     *data;         /** stuff that is attachable. */
131 };
132
133
134 static inline affinity_node_t *get_affinity_info(const copy_opt_t *co, const ir_node *irn) {
135         affinity_node_t find;
136
137         ASSERT_GS_AVAIL(co);
138
139         find.irn = irn;
140         return set_find(co->nodes, &find, sizeof(find), hash_irn(irn));
141 }
142
143 #define co_gs_nodes_begin(co)                   set_first((co)->nodes)
144 #define co_gs_nodes_next(co)                    set_next((co)->nodes)
145 #define co_gs_nodes_break(co)                   set_break((co)->nodes)
146
147 #define co_gs_foreach_aff_node(co, aff_node)    for (aff_node = co_gs_nodes_begin(co); aff_node; aff_node = co_gs_nodes_next(co))
148 #define co_gs_foreach_neighb(aff_node, neighb)  for (neighb = aff_node->neighbours; neighb; neighb = neighb->next)
149
150
151 #endif /* FIRM_BE_BECOPYOPT_T_H */