3 * File name: ir/ir/iredges_t.h
4 * Purpose: Everlasting outs -- private header.
5 * Author: Sebastian Hack
8 * Copyright: (c) 1998-2005 Universit�t Karlsruhe
9 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
14 * @author Sebastian Hack
18 #ifndef _FIRM_EDGES_T_H
19 #define _FIRM_EDGES_T_H
21 #include "firm_config.h"
28 #include "irgraph_t.h"
32 #if FIRM_EDGES_INPLACE
34 #define DBG_EDGES "edges"
41 long src_nr; /**< The node number of the source node. */
43 ir_node *src; /**< The source node of the edge. */
44 int pos; /**< The position of the edge at @p src. */
45 unsigned invalid : 1; /**< edges that are removed are marked invalid. */
46 unsigned present : 1; /**< Used by the verifier. Don't rely on its content. */
47 struct list_head list; /**< The list head to queue all out edges at a node. */
51 * A block edge inherits from a normal edge.
52 * They represent edges leading from a block to a control flow node
53 * and are used to quickly find all control flow successors of
56 struct _ir_block_edge_t {
57 struct _ir_edge_t edge; /**< The inherited data. */
58 struct list_head succ_list; /**< List element listing all
59 control flow edges to the
60 successors of a block. */
63 /** Accessor for private irn info. */
64 #define _get_irn_edge_info(irn) ((irn_edge_info_t *) &(irn)->edge_info)
66 /** Accessor for private irg info. */
67 #define _get_irg_edge_info(irg) ((irg_edge_info_t *) &(irg)->edge_info)
70 * Convenience macro to get the outs_head from a irn_edge_info_t
73 #define _get_irn_outs_head(irn) (&_get_irn_edge_info(irn)->outs_head)
76 * Convenience macro to get the succ_head from a block_attr
79 #define _get_block_succ_head(bl) (&((bl)->attr.block.succ_head))
82 * Get the first edge pointing to some node.
83 * @note There is no order on out edges. First in this context only
84 * means, that you get some starting point into the list of edges.
85 * @param irn The node.
86 * @return The first out edge that points to this node.
88 static INLINE const ir_edge_t *_get_irn_out_edge_first(const ir_node *irn)
90 struct list_head *head = _get_irn_outs_head(irn);
91 return list_empty(head) ? NULL : list_entry(head->next, ir_edge_t, list);
95 * Get the next edge in the out list of some node.
96 * @param irn The node.
97 * @param last The last out edge you have seen.
98 * @return The next out edge in @p irn 's out list after @p last.
100 static INLINE const ir_edge_t *_get_irn_out_edge_next(const ir_node *irn, const ir_edge_t *last)
102 struct list_head *next = last->list.next;
103 return next == _get_irn_outs_head(irn) ? NULL : list_entry(next, ir_edge_t, list);
107 * Get the first successor edge of a block.
108 * A successor edge is an edge originated from another block, pointing
109 * to a mode_X node in the given block and is thus a control flow
111 * @param irn The block.
112 * @return The first successor edge of the block.
114 static INLINE const ir_edge_t *_get_block_succ_first(const ir_node *irn)
116 const struct list_head *head;
118 assert(is_Block(irn) && "Node must be a block here");
119 head = _get_block_succ_head(irn);
120 return (ir_edge_t *) (list_empty(head) ? NULL :
121 list_entry(head->next, ir_block_edge_t, succ_list));
125 * Get the next block successor edge.
126 * @see See _get_block_succ_first() for details.
127 * @param irn The block.
128 * @param last The last edge.
129 * @return The next edge, or NULL if there is no further.
131 static INLINE const ir_edge_t *_get_block_succ_next(const ir_node *irn, const ir_edge_t *last)
133 const ir_block_edge_t *block_edge;
134 struct list_head *next;
136 assert(is_Block(irn) && "Node must be a block here");
137 block_edge = (const ir_block_edge_t *) last;
138 next = block_edge->succ_list.next;
139 return (ir_edge_t *) (next == _get_block_succ_head(irn) ? NULL :
140 list_entry(next, ir_block_edge_t, succ_list));
144 * Get the source node of an edge.
145 * @param edge The edge.
146 * @return The source node of that edge.
148 static INLINE ir_node *_get_edge_src_irn(const ir_edge_t *edge)
150 return edge ? edge->src : NULL;
154 * Get the position of an edge.
156 * @return The position in the in array of that edges source.
158 static INLINE int _get_edge_src_pos(const ir_edge_t *edge)
160 return edge ? edge->pos : -1;
164 * Get the number of edges pointing to a node.
165 * @param irn The node.
166 * @return The number of edges pointing to this node.
168 static INLINE int _get_irn_n_edges(const ir_node *irn)
170 /* Perhaps out_count was buggy. This code does it more safely.
173 struct list_head *pos, *head = _get_irn_outs_head(irn);
174 list_for_each(pos, head)
178 return _get_irn_edge_info(irn)->out_count;
181 static INLINE int _edges_activated(const ir_graph *irg)
183 return _get_irg_edge_info(irg)->activated;
187 * Assure, that the edges information is present for a certain graph.
188 * @param irg The graph.
190 static INLINE void _edges_assure(ir_graph *irg)
192 if(!_edges_activated(irg))
196 void edges_reroute(ir_node *old, ir_node *nw, ir_graph *irg);
198 void edges_init_graph(ir_graph *irg);
200 void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir_graph *irg);
202 void edges_node_deleted(ir_node *old, ir_graph *irg);
204 void edges_invalidate(ir_node *irn, ir_graph *irg);
207 * Register additional memory in an edge.
208 * This must be called before Firm is initialized.
209 * @param n Number of bytes you need.
210 * @return A number you have to keep and to pass
211 * edges_get_private_data()
212 * to get a pointer to your data.
214 int edges_register_private_data(size_t n);
217 * Get a pointer to the private data you registered.
218 * @param edge The edge.
219 * @param ofs The number, you obtained with
220 * edges_register_private_data().
221 * @return A pointer to the private data.
223 static INLINE void *_get_edge_private_data(const ir_edge_t *edge, int ofs)
225 /* Get the size of the edge. */
227 is_Block(edge->src) ? sizeof(ir_block_edge_t) : sizeof(ir_edge_t);
229 return (void *) ((char *) edge + size + ofs);
233 * Initialize the out edges.
234 * This must be called before firm is initialized.
236 extern void init_edges(void);
238 #define get_irn_out_edge_first(irn) _get_irn_out_edge_first(irn)
239 #define get_irn_out_edge_next(irn,last) _get_irn_out_edge_next(irn, last)
240 #define get_block_succ_first(irn) _get_block_succ_first(irn)
241 #define get_block_succ_next(irn,last) _get_block_succ_next(irn, last)
242 #define get_edge_src_irn(edge) _get_edge_src_irn(edge)
243 #define get_edge_src_pos(edge) _get_edge_src_pos(edge)
244 #define get_edge_private_data(edge,ofs) _get_edge_private_data(edge,ofs)
245 #define edges_activated(irg) _edges_activated(irg)
246 #define edges_assure(irg) _edges_assure(irg)
249 /* new edges are disabled */
252 #define edges_reroute(old, nw, irg)
253 #define edges_init_graph(irg);
254 #define edges_notify_edge(src, pos, tgt, old_tgt, irg)
255 #define edges_node_deleted(old, irg)
256 #define edges_invalidate(irn, irg)
257 #define get_irn_out_edge_first(irn) NULL
258 #define get_irn_out_edge_next(irn,last) NULL
259 #define get_edge_src_irn(edge) NULL
260 #define get_edge_src_pos(edge) -1
261 #define get_edge_private_data(edge,ofs) NULL
262 #define edges_activated(irg) 0
263 #define edges_assure(irg)
265 #endif /* FIRM_EDGES_INPLACE */
267 #endif /* _FIRM_EDGES_T_H */