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
28 #include "irgraph_t.h"
32 #if FIRM_EDGES_INPLACE
34 #define DBG_EDGES "edges"
39 typedef struct _ir_edge_t {
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 struct list_head list; /**< The list head to queue all out edges at a node. */
46 unsigned invalid : 1; /**< edges that are removed are marked invalid. */
47 unsigned present : 1; /**< Used by the verifier. Don't rely on its content. */
50 /** Accessor for private irn info. */
51 #define _get_irn_edge_info(irn) ((irn_edge_info_t *) &(irn)->edge_info)
53 /** Accessor for private irg info. */
54 #define _get_irg_edge_info(irg) ((irg_edge_info_t *) &(irg)->edge_info)
57 * Convenience macro to get the outs_head from a irn_edge_info_t
60 #define _get_irn_outs_head(irn) (&_get_irn_edge_info(irn)->outs_head)
63 * Get the first edge pointing to some node.
64 * @note There is no order on out edges. First in this context only
65 * means, that you get some starting point into the list of edges.
66 * @param irn The node.
67 * @return The first out edge that points to this node.
69 static INLINE const ir_edge_t *_get_irn_out_edge_first(const ir_node *irn)
71 struct list_head *head = _get_irn_outs_head(irn);
72 return list_empty(head) ? NULL : list_entry(head->next, ir_edge_t, list);
76 * Get the next edge in the out list of some node.
77 * @param irn The node.
78 * @param last The last out edge you have seen.
79 * @return The next out edge in @p irn 's out list after @p last.
81 static INLINE const ir_edge_t *_get_irn_out_edge_next(const ir_node *irn, const ir_edge_t *last)
83 struct list_head *next = last->list.next;
84 return next == _get_irn_outs_head(irn) ? NULL : list_entry(next, ir_edge_t, list);
88 * A convenience iteration macro over all out edges of a node.
89 * @param irn The node.
90 * @param edge An @c ir_edge_t pointer which shall be set to the current
93 #define foreach_out_edge(irn,edge) \
94 for(edge = get_irn_out_edge_first(irn); edge; edge = get_irn_out_edge_next(irn, edge))
97 * Get the source node of an edge.
98 * @param edge The edge.
99 * @return The source node of that edge.
101 static INLINE ir_node *_get_edge_src_irn(const ir_edge_t *edge)
103 return edge ? edge->src : NULL;
107 * Get the position of an edge.
109 * @return The position in the in array of that edges source.
111 static INLINE int _get_edge_src_pos(const ir_edge_t *edge)
113 return edge ? edge->pos : -1;
116 static INLINE int _edges_activated(const ir_graph *irg)
118 return _get_irg_edge_info(irg)->activated;
121 void edges_reroute(ir_node *old, ir_node *nw, ir_graph *irg);
123 void edges_init_graph(ir_graph *irg);
125 void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir_graph *irg);
127 void edges_node_deleted(ir_node *old, ir_graph *irg);
129 void edges_invalidate(ir_node *irn, ir_graph *irg);
132 * Initialize the out edges.
133 * This must be called before firm is initialized.
135 extern void init_edges(void);
137 #define get_irn_out_edge_first(irn) _get_irn_out_edge_first(irn)
138 #define get_irn_out_edge_next(irn,last) _get_irn_out_edge_next(irn, last)
139 #define get_edge_src_irn(edge) _get_edge_src_irn(edge)
140 #define get_edge_src_pos(edge) _get_edge_src_pos(edge)
141 #define edges_activated(irg) _edges_activated(irg)
144 /* new edges are disabled */
147 #define edges_reroute(old, nw, irg)
148 #define edges_init_graph(irg);
149 #define edges_notify_edge(src, pos, tgt, old_tgt, irg)
150 #define edges_node_deleted(old, irg)
151 #define edges_invalidate(irn, irg)
152 #define get_irn_out_edge_first(irn) NULL
153 #define get_irn_out_edge_next(irn,last) NULL
154 #define get_edge_src_irn(edge) NULL
155 #define get_edge_src_pos(edge) -1
156 #define edges_activated(irg) 0
158 #endif /* FIRM_EDGES_INPLACE */
160 #endif /* _FIRM_EDGES_T_H */