added macro foreach_out_edges_safe(), which allows an iteration over a
[libfirm] / ir / ir / iredges.h
1
2 /**
3  * Public header for the automatically updating outs.
4  * @author Sebastian Hack
5  * @date 3.2.2005
6  */
7
8 #ifndef _FIRM_EDGES_H
9 #define _FIRM_EDGES_H
10
11 #include "irnode.h"
12
13 #ifndef _IR_EDGE_TYPEDEF_
14 #define _IR_EDGE_TYPEDEF_
15 typedef struct _ir_edge_t ir_edge_t;
16 #endif
17
18 #ifndef _IR_BLOCK_EDGE_TYPEDEF_
19 #define _IR_BLOCK_EDGE_TYPEDEF_
20 typedef struct _ir_block_edge_t ir_block_edge_t;
21 #endif
22
23 /**
24  * Get the first edge pointing to some node.
25  * @note There is no order on out edges. First in this context only
26  * means, that you get some starting point into the list of edges.
27  * @param irn The node.
28  * @return The first out edge that points to this node.
29  */
30 const ir_edge_t *get_irn_out_edge_first(const ir_node *irn);
31
32 /**
33  * Get the next edge in the out list of some node.
34  * @param irn The node.
35  * @param last The last out edge you have seen.
36  * @return The next out edge in @p irn 's out list after @p last.
37  */
38 const ir_edge_t *get_irn_out_edge_next(const ir_node *irn,
39                 const ir_edge_t *last);
40
41 /**
42  * A convenience iteration macro over all out edges of a node.
43  * @param irn The node.
44  * @param edge An @c ir_edge_t pointer which shall be set to the current
45  * edge.
46  */
47 #define foreach_out_edge(irn,edge) \
48         for(edge = get_irn_out_edge_first(irn); edge; edge = get_irn_out_edge_next(irn, edge))
49
50 /**
51  * A convenience iteration macro over all out edges of a node, which is safe
52  * against alteration of the current edge.
53  * @param irn The node.
54  * @param edge An @c ir_edge_t pointer which shall be set to the current
55  * edge.
56  * @param ne The next edge, enables alteration safe erge processing.
57  */
58 #define foreach_out_edge_safe(irn,edge,ne) \
59         for( \
60                 (edge) = (get_irn_out_edge_first(irn)), \
61                         (ne) = ((edge) ? (get_irn_out_edge_next(irn, edge)) : NULL); \
62                 edge; \
63                 (edge) = (ne), (ne) = ((edge) ? (get_irn_out_edge_next(irn, edge)) : NULL) \
64         )
65
66
67 /**
68  * A convenience iteration macro for all control flow edges
69  * leaving a block, and thus are cf successor edges.
70  * @param bl The block.
71  * @param edge An @c ir_edge_t pointer which is set to the current edge.
72  */
73 #define foreach_block_succ(bl,edge) \
74         for(edge = get_block_succ_first(bl); edge; edge = get_block_succ_next(bl, edge))
75
76 /*
77  * Get the source node of an edge.
78  * @param edge The edge.
79  * @return The source node of that edge.
80  */
81 ir_node *get_edge_src_irn(const ir_edge_t *edge);
82
83 /**
84  * Get the number of edges pointing to a node.
85  * @param irn The node.
86  * @return The number of edges pointing to this node.
87  */
88 int get_irn_n_edges(const ir_node *irn);
89
90 /**
91  * Get the position of an edge.
92  * @param edge The edge.
93  * @return The position in the in array of that edges source.
94  */
95 extern int get_edge_src_pos(const ir_edge_t *edge);
96
97 /**
98  * Get the edge object of an outgoing edge at a node.
99  * @param   irg The graph, the node is in.
100  * @param   irn The node at which the edge originates.
101  * @param   pos The position of the edge.
102  * @return      The corresponding edge object or NULL,
103  *              if no such edge exists.
104  */
105 const ir_edge_t *get_irn_edge(ir_graph *irg, const ir_node *irn, int pos);
106
107 /**
108  * Check, if the out edges are activated.
109  * @param irg The graph.
110  * @return 1, if the edges are present for the given irg, 0 if not.
111  */
112 extern int edges_activated(const ir_graph *irg);
113
114 /**
115  * Activate the edges for an irg.
116  * @param irg The graph to activate the edges for.
117  **/
118 extern void edges_activate(ir_graph *irg);
119
120 /**
121  * Deactivate the edges for an irg.
122  * @param irg The graph.
123  */
124 extern void edges_deactivate(ir_graph *irg);
125
126 #endif /* _FIRM_EDGES_H */