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