ia32_Minus64Bit needs no contraint copies.
[libfirm] / ir / ir / iredges_t.h
1 /*
2  * Copyright (C) 1995-2011 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   Everlasting outs -- private header.
23  * @author  Sebastian Hack, Andreas Schoesser
24  * @date    15.01.2005
25  * @version $Id$
26  */
27 #ifndef FIRM_IR_EDGES_T_H
28 #define FIRM_IR_EDGES_T_H
29
30 #include "debug.h"
31
32 #include "set.h"
33 #include "list.h"
34
35 #include "irnode_t.h"
36 #include "irgraph_t.h"
37
38 #include "iredgekinds.h"
39 #include "iredges.h"
40
41 #define DBG_EDGES  "firm.ir.edges"
42
43 /**
44  * An edge.
45  */
46 struct ir_edge_t {
47         ir_node  *src;          /**< The source node of the edge. */
48         int      pos;           /**< The position of the edge at @p src. */
49         unsigned invalid : 1;   /**< edges that are removed are marked invalid. */
50         unsigned present : 1;   /**< Used by the verifier. Don't rely on its content. */
51         unsigned kind    : 4;   /**< The kind of the edge. */
52         struct list_head list;  /**< The list head to queue all out edges at a node. */
53 };
54
55
56 /** Accessor for private irn info. */
57 #define _get_irn_edge_info(irn, kind) (&(((irn)->edge_info)[kind]))
58
59 /** Accessor for private irg info. */
60 #define _get_irg_edge_info(irg, kind) (&(((irg)->edge_info)[kind]))
61
62 /**
63 * Convenience macro to get the outs_head from a irn_edge_info_t
64 * struct.
65 */
66 #define _get_irn_outs_head(irn, kind) (&_get_irn_edge_info(irn, kind)->outs_head)
67
68 /**
69 * Get the first edge pointing to some node.
70 * @note There is no order on out edges. First in this context only
71 * means, that you get some starting point into the list of edges.
72 * @param irn The node.
73 * @return The first out edge that points to this node.
74 */
75 static inline const ir_edge_t *_get_irn_out_edge_first_kind(const ir_node *irn, ir_edge_kind_t kind)
76 {
77         const struct list_head *head;
78         assert(edges_activated_kind(get_irn_irg(irn), kind));
79         head = _get_irn_outs_head(irn, kind);
80         return list_empty(head) ? NULL : list_entry(head->next, ir_edge_t, list);
81 }
82
83 /**
84 * Get the next edge in the out list of some node.
85 * @param irn The node.
86 * @param last The last out edge you have seen.
87 * @return The next out edge in @p irn 's out list after @p last.
88 */
89 static inline const ir_edge_t *_get_irn_out_edge_next(const ir_node *irn, const ir_edge_t *last)
90 {
91         struct list_head *next = last->list.next;
92         return next == _get_irn_outs_head(irn, last->kind) ? NULL : list_entry(next, ir_edge_t, list);
93 }
94
95 /**
96 * Get the number of edges pointing to a node.
97 * @param irn The node.
98 * @return The number of edges pointing to this node.
99 */
100 static inline int _get_irn_n_edges_kind(const ir_node *irn, int kind)
101 {
102         return _get_irn_edge_info(irn, kind)->out_count;
103 }
104
105 static inline int _edges_activated_kind(const ir_graph *irg, ir_edge_kind_t kind)
106 {
107         return _get_irg_edge_info(irg, kind)->activated;
108 }
109
110 /**
111 * Assure, that the edges information is present for a certain graph.
112 * @param irg The graph.
113 */
114 static inline void _edges_assure_kind(ir_graph *irg, ir_edge_kind_t kind)
115 {
116         if(!_edges_activated_kind(irg, kind))
117                 edges_activate_kind(irg, kind);
118 }
119
120 void edges_init_graph_kind(ir_graph *irg, ir_edge_kind_t kind);
121
122 /**
123  * A node might be revivaled by CSE.
124  */
125 void edges_node_revival(ir_node *node);
126
127 void edges_invalidate_kind(ir_node *irn, ir_edge_kind_t kind);
128
129 /**
130 * Register additional memory in an edge.
131 * This must be called before Firm is initialized.
132 * @param  n Number of bytes you need.
133 * @return A number you have to keep and to pass
134 *         edges_get_private_data()
135 *         to get a pointer to your data.
136 */
137 size_t edges_register_private_data(size_t n);
138
139 /**
140 * Get a pointer to the private data you registered.
141 * @param  edge The edge.
142 * @param  ofs  The number, you obtained with
143 *              edges_register_private_data().
144 * @return A pointer to the private data.
145 */
146 static inline void *_get_edge_private_data(const ir_edge_t *edge, int ofs)
147 {
148         return (void *) ((char *) edge + sizeof(edge[0]) + ofs);
149 }
150
151 static inline ir_node *_get_edge_src_irn(const ir_edge_t *edge)
152 {
153         return edge->src;
154 }
155
156 static inline int _get_edge_src_pos(const ir_edge_t *edge)
157 {
158         return edge->pos;
159 }
160
161 /**
162 * Initialize the out edges.
163 * This must be called before firm is initialized.
164 */
165 extern void init_edges(void);
166
167 void edges_invalidate_all(ir_node *irn);
168
169 /**
170  * Helper function to dump the edge set of a graph,
171  * unused in normal code.
172  */
173 void edges_dump_kind(ir_graph *irg, ir_edge_kind_t kind);
174
175 /**
176  * Notify normal and block edges.
177  */
178 void edges_notify_edge(ir_node *src, int pos, ir_node *tgt,
179                        ir_node *old_tgt, ir_graph *irg);
180
181 #define get_irn_n_edges_kind(irn, kind)   _get_irn_n_edges_kind(irn, kind)
182 #define get_edge_src_irn(edge)            _get_edge_src_irn(edge)
183 #define get_edge_src_pos(edge)            _get_edge_src_pos(edge)
184 #define get_edge_private_data(edge, ofs)  _get_edge_private_data(edge,ofs)
185 #define get_irn_out_edge_next(irn, last)  _get_irn_out_edge_next(irn, last)
186
187 #ifndef get_irn_n_edges
188 #define get_irn_n_edges(irn)              _get_irn_n_edges_kind(irn, EDGE_KIND_NORMAL)
189 #endif
190
191 #ifndef get_irn_out_edge_first
192 #define get_irn_out_edge_first(irn)       _get_irn_out_edge_first_kind(irn, EDGE_KIND_NORMAL)
193 #endif
194
195 #ifndef get_block_succ_first
196 #define get_block_succ_first(irn)         _get_irn_out_edge_first_kind(irn, EDGE_KIND_BLOCK)
197 #endif
198
199 #ifndef get_block_succ_next
200 #define get_block_succ_next(irn, last)    _get_irn_out_edge_next(irn, last)
201 #endif
202
203 #endif