4 * @author Sebastian Hack
8 #ifndef _FIRM_EDGES_T_H
9 #define _FIRM_EDGES_T_H
18 #include "irgraph_t.h"
22 #define DBG_EDGES "edges"
27 typedef struct _ir_edge_t {
29 long src_nr; /**< The node number of the source node. */
31 ir_node *src; /**< The source node of the edge. */
32 int pos; /**< The position of the edge at @p src. */
33 struct list_head list; /**< The list head to queue all out edges at a node. */
34 unsigned invalid : 1; /**< edges that are removed are marked invalid. */
35 unsigned present : 1; /**< Used by the verifier. Don't rely on its content. */
38 /** Accessor for private irn info. */
39 #define _get_irn_edge_info(irn) ((irn_edge_info_t *) &(irn)->edge_info)
41 /** Accessor for private irg info. */
42 #define _get_irg_edge_info(irg) ((irg_edge_info_t *) &(irg)->edge_info)
45 * Convenience macro to get the outs_head from a irn_edge_info_t
48 #define _get_irn_outs_head(irn) (&_get_irn_edge_info(irn)->outs_head)
51 * Get the first edge pointing to some node.
52 * @note There is no order on out edges. First in this context only
53 * means, that you get some starting point into the list of edges.
54 * @param irn The node.
55 * @return The first out edge that points to this node.
57 static INLINE const ir_edge_t *_get_irn_out_edge_first(const ir_node *irn)
59 struct list_head *head = _get_irn_outs_head(irn);
60 return list_empty(head) ? NULL : list_entry(head->next, ir_edge_t, list);
64 * Get the next edge in the out list of some node.
65 * @param irn The node.
66 * @param last The last out edge you have seen.
67 * @return The next out edge in @p irn 's out list after @p last.
69 static INLINE const ir_edge_t *_get_irn_out_edge_next(const ir_node *irn, const ir_edge_t *last)
71 struct list_head *next = last->list.next;
72 return next == _get_irn_outs_head(irn) ? NULL : list_entry(next, ir_edge_t, list);
76 * A convenience iteration macro over all out edges of a node.
77 * @param irn The node.
78 * @param edge An @c ir_edge_t pointer which shall be set to the current
81 #define foreach_out_edge(irn,edge) \
82 for(edge = get_irn_out_edge_first(irn); edge; edge = get_irn_out_edge_next(irn, edge))
85 * Get the source node of an edge.
86 * @param edge The edge.
87 * @return The source node of that edge.
89 static INLINE ir_node *_get_edge_src_irn(const ir_edge_t *edge)
91 return edge ? edge->src : NULL;
95 * Get the position of an edge.
97 * @return The position in the in array of that edges source.
99 static INLINE int _get_edge_src_pos(const ir_edge_t *edge)
101 return edge ? edge->pos : -1;
104 static INLINE int _edges_activated(const ir_graph *irg)
106 return _get_irg_edge_info(irg)->activated;
109 void edges_reroute(ir_node *old, ir_node *nw, ir_graph *irg);
111 void edges_init_graph(ir_graph *irg);
113 void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir_graph *irg);
115 void edges_node_deleted(ir_node *old, ir_graph *irg);
117 void edges_invalidate(ir_node *irn, ir_graph *irg);
120 * Initialize the out edges.
121 * This must be called before firm is initialized.
123 extern void init_edges(void);
125 #define get_irn_out_edge_first(irn) _get_irn_out_edge_first(irn)
126 #define get_irn_out_edge_next(irn,last) _get_irn_out_edge_next(irn, last)
127 #define get_edge_src_irn(edge) _get_edge_src_irn(edge)
128 #define get_edge_src_pos(edge) _get_edge_src_pos(edge)
129 #define edges_activated(irg) _edges_activated(irg)
131 #endif /* _FIRM_EDGES_T_H */