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 #define DBG_EDGES "firm.ir.edges"
38 ir_node *src; /**< The source node of the edge. */
39 int pos; /**< The position of the edge at @p src. */
40 unsigned invalid : 1; /**< edges that are removed are marked invalid. */
41 unsigned present : 1; /**< Used by the verifier. Don't rely on its content. */
42 struct list_head list; /**< The list head to queue all out edges at a node. */
44 long src_nr; /**< The node number of the source node. */
49 * A block edge inherits from a normal edge.
50 * They represent edges leading from a block to a control flow node
51 * and are used to quickly find all control flow successors of
54 struct _ir_block_edge_t {
55 struct _ir_edge_t edge; /**< The inherited data. */
56 struct list_head succ_list; /**< List element listing all
57 control flow edges to the
58 successors of a block. */
61 /** Accessor for private irn info. */
62 #define _get_irn_edge_info(irn) (&(irn)->edge_info)
64 /** Accessor for private irg info. */
65 #define _get_irg_edge_info(irg) (&(irg)->edge_info)
68 * Convenience macro to get the outs_head from a irn_edge_info_t
71 #define _get_irn_outs_head(irn) (&_get_irn_edge_info(irn)->outs_head)
74 * Convenience macro to get the succ_head from a block_attr
77 #define _get_block_succ_head(bl) (&((bl)->attr.block.succ_head))
80 * Get the first edge pointing to some node.
81 * @note There is no order on out edges. First in this context only
82 * means, that you get some starting point into the list of edges.
83 * @param irn The node.
84 * @return The first out edge that points to this node.
86 static INLINE const ir_edge_t *_get_irn_out_edge_first(const ir_node *irn)
88 const struct list_head *head = _get_irn_outs_head(irn);
89 return list_empty(head) ? NULL : list_entry(head->next, ir_edge_t, list);
93 * Get the next edge in the out list of some node.
94 * @param irn The node.
95 * @param last The last out edge you have seen.
96 * @return The next out edge in @p irn 's out list after @p last.
98 static INLINE const ir_edge_t *_get_irn_out_edge_next(const ir_node *irn, const ir_edge_t *last)
100 struct list_head *next = last->list.next;
101 return next == _get_irn_outs_head(irn) ? NULL : list_entry(next, ir_edge_t, list);
105 * Get the first successor edge of a block.
106 * A successor edge is an edge originated from another block, pointing
107 * to a mode_X node in the given block and is thus a control flow
109 * @param irn The block.
110 * @return The first successor edge of the block.
112 static INLINE const ir_edge_t *_get_block_succ_first(const ir_node *irn)
114 const struct list_head *head;
116 assert(is_Block(irn) && "Node must be a block here");
117 head = _get_block_succ_head(irn);
118 return (ir_edge_t *) (list_empty(head) ? NULL :
119 list_entry(head->next, ir_block_edge_t, succ_list));
123 * Get the next block successor edge.
124 * @see See _get_block_succ_first() for details.
125 * @param irn The block.
126 * @param last The last edge.
127 * @return The next edge, or NULL if there is no further.
129 static INLINE const ir_edge_t *_get_block_succ_next(const ir_node *irn, const ir_edge_t *last)
131 const ir_block_edge_t *block_edge;
132 struct list_head *next;
134 assert(is_Block(irn) && "Node must be a block here");
135 block_edge = (const ir_block_edge_t *) last;
136 next = block_edge->succ_list.next;
137 return (ir_edge_t *) (next == _get_block_succ_head(irn) ? NULL :
138 list_entry(next, ir_block_edge_t, succ_list));
142 * Get the source node of an edge.
143 * @param edge The edge.
144 * @return The source node of that edge.
146 static INLINE ir_node *_get_edge_src_irn(const ir_edge_t *edge)
148 return edge ? edge->src : NULL;
152 * Get the position of an edge.
154 * @return The position in the in array of that edges source.
156 static INLINE int _get_edge_src_pos(const ir_edge_t *edge)
158 return edge ? edge->pos : -1;
162 * Get the number of edges pointing to a node.
163 * @param irn The node.
164 * @return The number of edges pointing to this node.
166 static INLINE int _get_irn_n_edges(const ir_node *irn)
168 /* Perhaps out_count was buggy. This code does it more safely.
171 struct list_head *pos, *head = _get_irn_outs_head(irn);
172 list_for_each(pos, head)
176 return _get_irn_edge_info(irn)->out_count;
179 static INLINE int _edges_activated(const ir_graph *irg)
181 return _get_irg_edge_info(irg)->activated;
185 * Assure, that the edges information is present for a certain graph.
186 * @param irg The graph.
188 static INLINE void _edges_assure(ir_graph *irg)
190 if(!_edges_activated(irg))
194 void edges_reroute(ir_node *old, ir_node *nw, ir_graph *irg);
196 void edges_init_graph(ir_graph *irg);
199 * Notify of a edge change.
200 * The edge from (src, pos) -> old_tgt is redirected to tgt
202 void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir_graph *irg);
207 void edges_node_deleted(ir_node *old, ir_graph *irg);
209 void edges_invalidate(ir_node *irn, ir_graph *irg);
212 * Register additional memory in an edge.
213 * This must be called before Firm is initialized.
214 * @param n Number of bytes you need.
215 * @return A number you have to keep and to pass
216 * edges_get_private_data()
217 * to get a pointer to your data.
219 int edges_register_private_data(size_t n);
222 * Get a pointer to the private data you registered.
223 * @param edge The edge.
224 * @param ofs The number, you obtained with
225 * edges_register_private_data().
226 * @return A pointer to the private data.
228 static INLINE void *_get_edge_private_data(const ir_edge_t *edge, int ofs)
230 /* Get the size of the edge. */
232 is_Block(edge->src) ? sizeof(ir_block_edge_t) : sizeof(ir_edge_t);
234 return (void *) ((char *) edge + size + ofs);
238 * Initialize the out edges.
239 * This must be called before firm is initialized.
241 extern void init_edges(void);
243 #define get_irn_out_edge_first(irn) _get_irn_out_edge_first(irn)
244 #define get_irn_out_edge_next(irn,last) _get_irn_out_edge_next(irn, last)
245 #define get_block_succ_first(irn) _get_block_succ_first(irn)
246 #define get_block_succ_next(irn,last) _get_block_succ_next(irn, last)
247 #define get_edge_src_irn(edge) _get_edge_src_irn(edge)
248 #define get_edge_src_pos(edge) _get_edge_src_pos(edge)
249 #define get_edge_private_data(edge,ofs) _get_edge_private_data(edge,ofs)
250 #define edges_activated(irg) _edges_activated(irg)
251 #define edges_assure(irg) _edges_assure(irg)
253 #endif /* _FIRM_EDGES_T_H */