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