3 * File name: ir/ir/iredges.h
4 * Purpose: Public header for the automatically updating outs.
5 * Author: Sebastian Hack
8 * Copyright: (c) 1998-2005 Universität Karlsruhe
9 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
13 * Public header for the automatically updating outs.
14 * @author Sebastian Hack
18 #ifndef _FIRM_IR_EDGES_H
19 #define _FIRM_IR_EDGES_H
21 #include "firm_types.h"
22 #include "iredgekinds.h"
24 #ifndef _IR_EDGE_TYPEDEF_
25 #define _IR_EDGE_TYPEDEF_
26 typedef struct _ir_edge_t ir_edge_t;
30 #ifndef _IR_EDGE_KIND_TYPEDEF_
31 #define _IR_EDGE_KIND_TYPEDEF_
32 typedef enum _ir_edge_kind_t ir_edge_kind_t;
33 #endif /* _IR_EDGE_KIND_TYPEDEF_ */
37 * Get the first edge pointing to some node.
38 * @note There is no order on out edges. First in this context only
39 * means, that you get some starting point into the list of edges.
40 * @param irn The node.
41 * @param kind The kind of the edge.
42 * @return The first out edge that points to this node.
44 const ir_edge_t *get_irn_out_edge_first_kind(const ir_node *irn, ir_edge_kind_t kind);
47 * Get the next edge in the out list of some node.
48 * @param irn The node.
49 * @param last The last out edge you have seen.
50 * @return The next out edge in @p irn 's out list after @p last.
52 const ir_edge_t *get_irn_out_edge_next(const ir_node *irn, const ir_edge_t *last);
55 * A convenience iteration macro over all out edges of a node.
56 * @param irn The node.
57 * @param kind The edge's kind.
58 * @param edge An ir_edge_t pointer which shall be set to the current
61 #define foreach_out_edge_kind(irn, edge, kind) \
62 for(edge = get_irn_out_edge_first_kind(irn, kind); edge; edge = get_irn_out_edge_next(irn, edge))
65 * A convenience iteration macro over all out edges of a node, which is safe
66 * against alteration of the current edge.
68 * @param irn The node.
69 * @param edge An ir_edge_t pointer which shall be set to the current edge.
70 * @param ne The next edge, enables alteration safe edge processing.
72 #define foreach_out_edge_kind_safe(irn, edge, ne, kind) \
73 for((edge) = (get_irn_out_edge_first_kind(irn, kind)), (ne) = ((edge) ? (get_irn_out_edge_next(irn, edge)) : NULL); \
74 edge; (edge) = (ne), (ne) = ((edge) ? (get_irn_out_edge_next(irn, edge)) : NULL))
77 * Convenience macro for normal out edges.
79 #define foreach_out_edge(irn, edge) foreach_out_edge_kind(irn, edge, EDGE_KIND_NORMAL)
82 * Convenience macro for normal out edges.
84 #define foreach_out_edge_safe(irn, edge, tmp) foreach_out_edge_kind_safe(irn, edge, tmp, EDGE_KIND_NORMAL)
87 * A convenience iteration macro for all control flow edges.
89 #define foreach_block_succ(bl, edge) foreach_out_edge_kind(bl, edge, EDGE_KIND_BLOCK)
92 * Get the source node of an edge.
93 * @param edge The edge.
94 * @return The source node of that edge.
96 ir_node *get_edge_src_irn(const ir_edge_t *edge);
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.
103 int get_irn_n_edges(const ir_node *irn);
106 * Get the position of an edge.
107 * @param edge The edge.
108 * @return The position in the in array of that edges source.
110 extern int get_edge_src_pos(const ir_edge_t *edge);
113 * Get the edge object of an outgoing edge at a node.
114 * @param irg The graph, the node is in.
115 * @param irn The node at which the edge originates.
116 * @param pos The position of the edge.
117 * @return The corresponding edge object or NULL,
118 * if no such edge exists.
120 const ir_edge_t *get_irn_edge_kind(ir_graph *irg, const ir_node *irn, int pos, ir_edge_kind_t kind);
123 * Get the number of registered out edges for a specific kind.
124 * @param irn The node.
125 * @param kind The kind.
127 extern int get_irn_n_edges_kind(const ir_node *irn, ir_edge_kind_t kind);
131 * Check, if the out edges are activated.
132 * @param irg The graph.
133 * @param kind The edge kind.
134 * @return 1, if the edges are present for the given irg, 0 if not.
136 extern int edges_activated_kind(const ir_graph *irg, ir_edge_kind_t kind);
139 * Activate the edges for an irg.
140 * @param irg The graph to activate the edges for.
141 * @param kind The edge kind.
143 extern void edges_activate_kind(ir_graph *irg, ir_edge_kind_t kind);
146 * Deactivate the edges for an irg.
147 * @param irg The graph.
148 * @param kind The edge kind.
150 extern void edges_deactivate_kind(ir_graph *irg, ir_edge_kind_t kind);
152 extern void edges_reroute_kind(ir_node *old, ir_node *nw, ir_edge_kind_t kind, ir_graph *irg);
155 * Verifies the out edges of graph @p irg.
156 * @return 1 if a problem was found, 0 otherwise
158 int edges_verify(ir_graph *irg);
162 * Set edge verification flag.
165 void edges_init_dbg(int do_dbg);
167 /************************************************************************/
168 /* Begin Old Interface */
169 /************************************************************************/
171 const ir_edge_t *get_irn_edge(ir_graph *irg, const ir_node *src, int pos);
173 #define edges_reroute(old, nw, irg) edges_reroute_kind(old, nw, EDGE_KIND_NORMAL, irg)
174 #define edges_activated(irg) (edges_activated_kind(irg, EDGE_KIND_NORMAL) && edges_activated_kind(irg, EDGE_KIND_BLOCK))
176 #ifndef get_irn_n_edges
177 #define get_irn_n_edges(irn) get_irn_n_edges_kind(irn, EDGE_KIND_NORMAL)
180 #ifndef get_irn_out_edge_first
181 #define get_irn_out_edge_first(irn) get_irn_out_edge_first_kind(irn, EDGE_KIND_NORMAL)
184 #ifndef get_block_succ_first
185 #define get_block_succ_first(irn) get_irn_out_edge_first_kind(irn, EDGE_KIND_BLOCK)
188 #ifndef get_block_succ_next
189 #define get_block_succ_next(irn, last) get_irn_out_edge_next(irn, last)
193 * Activate all the edges for an irg.
194 * @param irg The graph to activate the edges for.
196 extern void edges_activate(ir_graph *irg);
199 * Deactivate all the edges for an irg.
200 * @param irg The graph.
202 extern void edges_deactivate(ir_graph *irg);
204 extern int edges_assure(ir_graph *irg);
206 extern void edges_node_deleted(ir_node *irn, ir_graph *irg);
209 * Notify normal and block edges.
211 extern void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir_graph *irg);
213 void edges_reset_private_data(ir_graph *irg, int offset, size_t size);
215 /************************************************************************/
216 /* End Old Interface */
217 /************************************************************************/
220 #endif /* _FIRM_IR_EDGES_H */