added edge verification routines
[libfirm] / ir / ir / iredges.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/iredges.h
4  * Purpose:     Public header for the automatically updating outs.
5  * Author:      Sebastian Hack
6  * Created:     3.2.2005
7  * CVS-ID:      $Id$
8  * Copyright:   (c) 1998-2005 Universität Karlsruhe
9  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
10  */
11
12 /**
13  * Public header for the automatically updating outs.
14  * @author Sebastian Hack
15  * @date 3.2.2005
16  */
17
18 #ifndef _FIRM_IR_EDGES_H
19 #define _FIRM_IR_EDGES_H
20
21 #include "firm_types.h"
22 #include "iredgekinds.h"
23
24 #ifndef _IR_EDGE_TYPEDEF_
25 #define _IR_EDGE_TYPEDEF_
26 typedef struct _ir_edge_t ir_edge_t;
27 #endif
28
29 #if 0
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_ */
34 #endif
35
36 /**
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.
43  */
44 const ir_edge_t *get_irn_out_edge_first_kind(const ir_node *irn, ir_edge_kind_t kind);
45
46 /**
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.
51  */
52 const ir_edge_t *get_irn_out_edge_next(const ir_node *irn, const ir_edge_t *last);
53
54 /**
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
59  * edge.
60  */
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))
63
64 /**
65  * A convenience iteration macro over all out edges of a node, which is safe
66  * against alteration of the current edge.
67  *
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.
71  */
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))
75
76 /**
77  * Convenience macro for normal out edges.
78  */
79 #define foreach_out_edge(irn, edge)            foreach_out_edge_kind(irn, edge, EDGE_KIND_NORMAL)
80
81 /**
82  * Convenience macro for normal out edges.
83  */
84 #define foreach_out_edge_safe(irn, edge, tmp)  foreach_out_edge_kind_safe(irn, edge, tmp, EDGE_KIND_NORMAL)
85
86 /**
87  * A convenience iteration macro for all control flow edges.
88  */
89 #define foreach_block_succ(bl, edge)           foreach_out_edge_kind(bl, edge, EDGE_KIND_BLOCK)
90
91 /*
92  * Get the source node of an edge.
93  * @param edge The edge.
94  * @return The source node of that edge.
95  */
96 ir_node *get_edge_src_irn(const ir_edge_t *edge);
97
98 /**
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.
102  */
103 int get_irn_n_edges(const ir_node *irn);
104
105 /**
106  * Get the position of an edge.
107  * @param edge The edge.
108  * @return The position in the in array of that edges source.
109  */
110 extern int get_edge_src_pos(const ir_edge_t *edge);
111
112 /**
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.
119  */
120 const ir_edge_t *get_irn_edge_kind(ir_graph *irg, const ir_node *irn, int pos, ir_edge_kind_t kind);
121
122 /**
123  * Get the number of registered out edges for a specific kind.
124  * @param irn The node.
125  * @param kind The kind.
126  */
127 extern int get_irn_n_edges_kind(const ir_node *irn, ir_edge_kind_t kind);
128
129
130 /**
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.
135  */
136 extern int edges_activated_kind(const ir_graph *irg, ir_edge_kind_t kind);
137
138 /**
139  * Activate the edges for an irg.
140  * @param irg The graph to activate the edges for.
141  * @param kind The edge kind.
142  */
143 extern void edges_activate_kind(ir_graph *irg, ir_edge_kind_t kind);
144
145 /**
146  * Deactivate the edges for an irg.
147  * @param irg The graph.
148  * @param kind The edge kind.
149  */
150 extern void edges_deactivate_kind(ir_graph *irg, ir_edge_kind_t kind);
151
152 extern void edges_reroute_kind(ir_node *old, ir_node *nw, ir_edge_kind_t kind, ir_graph *irg);
153
154 /**
155  * Verifies the out edges of graph @p irg.
156  * @return 1 if a problem was found, 0 otherwise
157  */
158 int edges_verify(ir_graph *irg);
159
160 /************************************************************************/
161 /* Begin Old Interface                                                  */
162 /************************************************************************/
163
164 #define edges_reroute(old, nw, irg)                     edges_reroute_kind(old, nw, EDGE_KIND_NORMAL, irg)
165 #define edges_activated(irg)                            (edges_activated_kind(irg, EDGE_KIND_NORMAL) && edges_activated_kind(irg, EDGE_KIND_BLOCK))
166
167 #ifndef get_irn_n_edges
168 #define get_irn_n_edges(irn)                            get_irn_n_edges_kind(irn, EDGE_KIND_NORMAL)
169 #endif
170
171 #ifndef get_irn_out_edge_first
172 #define get_irn_out_edge_first(irn)                     get_irn_out_edge_first_kind(irn, EDGE_KIND_NORMAL)
173 #endif
174
175 #ifndef get_block_succ_first
176 #define get_block_succ_first(irn)                       get_irn_out_edge_first_kind(irn, EDGE_KIND_BLOCK)
177 #endif
178
179 #ifndef get_block_succ_next
180 #define get_block_succ_next(irn, last)                  get_irn_out_edge_next(irn, last)
181 #endif
182
183 /**
184 * Activate all the edges for an irg.
185 * @param irg The graph to activate the edges for.
186 */
187 extern void edges_activate(ir_graph *irg);
188
189 /**
190 * Deactivate all the edges for an irg.
191 * @param irg The graph.
192 */
193 extern void edges_deactivate(ir_graph *irg);
194
195 extern int edges_assure(ir_graph *irg);
196
197 extern void edges_node_deleted(ir_node *irn, ir_graph *irg);
198
199 /**
200 * Notify normal and block edges.
201 */
202 extern void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir_graph *irg);
203
204 /************************************************************************/
205 /* End Old Interface                                                    */
206 /************************************************************************/
207
208
209 #endif /* _FIRM_IR_EDGES_H */