beifg: Remove the unused function be_ifg_nodes_break().
[libfirm] / include / libfirm / iredges.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief   Public header for the automatically updating outs.
9  * @author  Sebastian Hack
10  * @date    3.2.2005
11  */
12 #ifndef FIRM_IR_IREDGES_H
13 #define FIRM_IR_IREDGES_H
14
15 #include "firm_types.h"
16 #include "iredgekinds.h"
17 #include "begin.h"
18
19 /**
20  * @ingroup irana
21  * @defgroup iredges Dynamic Reverse Edges
22  * @{
23  */
24
25 /**
26  * Returns the first edge pointing to some node.
27  * @note There is no order on out edges. First in this context only
28  * means, that you get some starting point into the list of edges.
29  * @param irn The node.
30  * @param kind The kind of the edge.
31  * @return The first out edge that points to this node.
32  */
33 FIRM_API const ir_edge_t *get_irn_out_edge_first_kind(const ir_node *irn,
34                                                       ir_edge_kind_t kind);
35
36 /**
37  * Returns 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  * @return The first out edge that points to this node.
42  */
43 FIRM_API const ir_edge_t *get_irn_out_edge_first(const ir_node *irn);
44
45 /**
46  * Returns the first edge pointing to a successor block.
47  *
48  * You can navigate the list with the usual get_irn_out_edge_next().
49  * @param block  the Block
50  * @return first block successor edge
51  */
52 FIRM_API const ir_edge_t *get_block_succ_first(const ir_node *block);
53
54 /**
55  * Returns the next edge in the out list of some node.
56  * @param irn The node.
57  * @param last The last out edge you have seen.
58  * @param kind the kind of edge that are iterated
59  * @return The next out edge in @p irn 's out list after @p last.
60  */
61 FIRM_API const ir_edge_t *get_irn_out_edge_next(const ir_node *irn,
62                                                 const ir_edge_t *last,
63                                                 ir_edge_kind_t kind);
64
65 /**
66  * A convenience iteration macro over all out edges of a node.
67  * @param irn  The node.
68  * @param kind The edge's kind.
69  * @param edge An ir_edge_t pointer which shall be set to the current
70  * edge.
71  */
72 #define foreach_out_edge_kind(irn, edge, kind) \
73         for (ir_edge_t const *edge = get_irn_out_edge_first_kind(irn, kind); edge; edge = get_irn_out_edge_next(irn, edge, kind))
74
75 /**
76  * A convenience iteration macro over all out edges of a node, which is safe
77  * against alteration of the current edge.
78  *
79  * @param irn  The node.
80  * @param edge An ir_edge_t pointer which shall be set to the current edge.
81  * @param kind The kind of the edge.
82  */
83 #define foreach_out_edge_kind_safe(irn, edge, kind) \
84         for (ir_edge_t const *edge = get_irn_out_edge_first_kind((irn), (kind)), *edge##__next; edge; edge = edge##__next) \
85                 if (edge##__next = get_irn_out_edge_next((irn), edge, (kind)), 0) {} else
86
87 /**
88  * Convenience macro for normal out edges.
89  */
90 #define foreach_out_edge(irn, edge)       foreach_out_edge_kind(irn, edge, EDGE_KIND_NORMAL)
91
92 /**
93  * Convenience macro for normal out edges.
94  */
95 #define foreach_out_edge_safe(irn, edge)  foreach_out_edge_kind_safe(irn, edge, EDGE_KIND_NORMAL)
96
97 /**
98  * A convenience iteration macro for all control flow edges.
99  */
100 #define foreach_block_succ(bl, edge)      foreach_out_edge_kind(bl, edge, EDGE_KIND_BLOCK)
101
102 /**
103  * Returns the source node of an edge.
104  * @param edge The edge.
105  * @return The source node of that edge.
106  */
107 FIRM_API ir_node *get_edge_src_irn(const ir_edge_t *edge);
108
109 /**
110  * Returns the position of an edge.
111  * @param edge The edge.
112  * @return The position in the in array of that edges source.
113  */
114 FIRM_API int get_edge_src_pos(const ir_edge_t *edge);
115
116 /**
117  * Returns the number of registered out edges for a specific kind.
118  * @param irn The node.
119  * @param kind The kind.
120  */
121 FIRM_API int get_irn_n_edges_kind(const ir_node *irn, ir_edge_kind_t kind);
122
123 /**
124  * Returns the number of registered out edges with EDGE_KIND_NORMAL
125  * @param irn The node.
126  */
127 FIRM_API int get_irn_n_edges(const ir_node *irn);
128
129 /**
130  * Checks if the out edges are activated.
131  *
132  * @param irg   The graph.
133  * @param kind  The edge kind.
134  *
135  * @return 1, if the edges are present for the given irg, 0 if not.
136  */
137 FIRM_API int edges_activated_kind(const ir_graph *irg, ir_edge_kind_t kind);
138
139 /**
140  * Checks if out edges with EDG_KIND_NORMAL and EDGE_KIND_BLOCK are activated.
141  * @param irg   The graph.
142  * @return 1, if the edges are present for the given irg, 0 if not.
143  */
144 FIRM_API int edges_activated(const ir_graph *irg);
145
146 /**
147  * Activates the edges for an irg.
148  *
149  * @param irg   The graph to activate the edges for.
150  * @param kind  The edge kind.
151  */
152 FIRM_API void edges_activate_kind(ir_graph *irg, ir_edge_kind_t kind);
153
154 /**
155  * Deactivates the edges for an irg.
156  *
157  * @param irg   The graph.
158  * @param kind  The edge kind.
159  */
160 FIRM_API void edges_deactivate_kind(ir_graph *irg, ir_edge_kind_t kind);
161
162 /**
163  * Reroutes edges of a specified kind from an old node to a new one.
164  *
165  * @param old   the old node
166  * @param nw    the new node
167  * @param kind  the edge kind
168  */
169 FIRM_API void edges_reroute_kind(ir_node *old, ir_node *nw, ir_edge_kind_t kind);
170
171 /**
172  * Reroutes edges of EDGE_KIND_NORMAL from an old node to a new one.
173  *
174  * @param old   the old node
175  * @param nw    the new node
176  */
177 FIRM_API void edges_reroute(ir_node *old, ir_node *nw);
178
179 /**
180  * reroutes (normal) edges from an old node to a new node, except for the
181  * @p exception which keeps its input even if it is old.
182  */
183 FIRM_API void edges_reroute_except(ir_node *old, ir_node *nw,
184                                    ir_node *exception);
185
186 /**
187  * Verifies the out edges of graph @p irg.
188  * @return 1 if a problem was found, 0 otherwise
189  */
190 FIRM_API int edges_verify(ir_graph *irg);
191
192 /**
193  * Verifies a certrain kind of out edges of graph @p irg.
194  * @returns 1 if a problem was found, 0 otherwise
195  */
196 FIRM_API int edges_verify_kind(ir_graph *irg, ir_edge_kind_t kind);
197
198 /**
199  * Sets edge verification flag.
200  */
201 FIRM_API void edges_init_dbg(int do_dbg);
202
203 /**
204  * Creates an ir_graph pass for edges_verify().
205  *
206  * @param name                the name of this pass or NULL
207  * @param assert_on_problem   assert if problems were found
208  *
209  * @return  the newly created ir_graph pass
210  */
211 FIRM_API ir_graph_pass_t *irg_verify_edges_pass(const char *name,
212                                                 unsigned assert_on_problem);
213
214 /**
215  * Activates data and block edges for an irg.
216  * If the irg phase is phase_backend, Dependence edges are
217  * additionally activated.
218  *
219  * @param irg  The graph to activate the edges for.
220  */
221 FIRM_API void edges_activate(ir_graph *irg);
222
223 /**
224  * Deactivates data and block edges for an irg.
225  * If the irg phase is phase_backend, Dependence edges are
226  * additionally deactivated.
227  * @param irg  The graph.
228  */
229 FIRM_API void edges_deactivate(ir_graph *irg);
230
231 /**
232  * Ensures that edges are activated.
233  *
234  * @param irg  the IR graph
235  */
236 FIRM_API void assure_edges(ir_graph *irg);
237
238 /**
239  * Ensures that edges of a given kind are activated.
240  *
241  * @param irg   the IR graph
242  * @param kind  the edge kind
243  */
244 FIRM_API void assure_edges_kind(ir_graph *irg, ir_edge_kind_t kind);
245
246 /**
247  * Walks only over Block nodes in the graph. Uses the block visited
248  * flag, so that it can be interleaved with another walker.
249  *
250  * @param block  the start block
251  * @param pre    the pre visit function
252  * @param post   the post visit function
253  * @param env    the environment for the walker
254  */
255 FIRM_API void irg_block_edges_walk(ir_node *block, irg_walk_func *pre,
256                                    irg_walk_func *post, void *env);
257
258 /** Graph walker following #EDGE_KIND_NORMAL edges. */
259 FIRM_API void irg_walk_edges(ir_node *start, irg_walk_func *pre,
260                              irg_walk_func *post, void *env);
261
262 /** @} */
263
264 #include "end.h"
265
266 #endif