2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Public header for the automatically updating outs.
9 * @author Sebastian Hack
12 #ifndef FIRM_IR_IREDGES_H
13 #define FIRM_IR_IREDGES_H
15 #include "firm_types.h"
16 #include "iredgekinds.h"
21 * @defgroup iredges Dynamic Reverse Edges
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.
33 FIRM_API const ir_edge_t *get_irn_out_edge_first_kind(const ir_node *irn,
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.
43 FIRM_API const ir_edge_t *get_irn_out_edge_first(const ir_node *irn);
46 * Returns the first edge pointing to a successor block.
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
52 FIRM_API const ir_edge_t *get_block_succ_first(const ir_node *block);
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.
61 FIRM_API const ir_edge_t *get_irn_out_edge_next(const ir_node *irn,
62 const ir_edge_t *last,
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
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))
76 * A convenience iteration macro over all out edges of a node, which is safe
77 * against alteration of the current edge.
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.
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
88 * Convenience macro for normal out edges.
90 #define foreach_out_edge(irn, edge) foreach_out_edge_kind(irn, edge, EDGE_KIND_NORMAL)
93 * Convenience macro for normal out edges.
95 #define foreach_out_edge_safe(irn, edge) foreach_out_edge_kind_safe(irn, edge, EDGE_KIND_NORMAL)
98 * A convenience iteration macro for all control flow edges.
100 #define foreach_block_succ(bl, edge) foreach_out_edge_kind(bl, edge, EDGE_KIND_BLOCK)
103 * Returns the source node of an edge.
104 * @param edge The edge.
105 * @return The source node of that edge.
107 FIRM_API ir_node *get_edge_src_irn(const ir_edge_t *edge);
110 * Returns the position of an edge.
111 * @param edge The edge.
112 * @return The position in the in array of that edges source.
114 FIRM_API int get_edge_src_pos(const ir_edge_t *edge);
117 * Returns the number of registered out edges for a specific kind.
118 * @param irn The node.
119 * @param kind The kind.
121 FIRM_API int get_irn_n_edges_kind(const ir_node *irn, ir_edge_kind_t kind);
124 * Returns the number of registered out edges with EDGE_KIND_NORMAL
125 * @param irn The node.
127 FIRM_API int get_irn_n_edges(const ir_node *irn);
130 * Checks if the out edges are activated.
132 * @param irg The graph.
133 * @param kind The edge kind.
135 * @return 1, if the edges are present for the given irg, 0 if not.
137 FIRM_API int edges_activated_kind(const ir_graph *irg, ir_edge_kind_t kind);
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.
144 FIRM_API int edges_activated(const ir_graph *irg);
147 * Activates the edges for an irg.
149 * @param irg The graph to activate the edges for.
150 * @param kind The edge kind.
152 FIRM_API void edges_activate_kind(ir_graph *irg, ir_edge_kind_t kind);
155 * Deactivates the edges for an irg.
157 * @param irg The graph.
158 * @param kind The edge kind.
160 FIRM_API void edges_deactivate_kind(ir_graph *irg, ir_edge_kind_t kind);
163 * Reroutes edges of a specified kind from an old node to a new one.
165 * @param old the old node
166 * @param nw the new node
167 * @param kind the edge kind
169 FIRM_API void edges_reroute_kind(ir_node *old, ir_node *nw, ir_edge_kind_t kind);
172 * Reroutes edges of EDGE_KIND_NORMAL from an old node to a new one.
174 * @param old the old node
175 * @param nw the new node
177 FIRM_API void edges_reroute(ir_node *old, ir_node *nw);
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.
183 FIRM_API void edges_reroute_except(ir_node *old, ir_node *nw,
187 * Verifies the out edges of graph @p irg.
188 * @return 1 if a problem was found, 0 otherwise
190 FIRM_API int edges_verify(ir_graph *irg);
193 * Verifies a certrain kind of out edges of graph @p irg.
194 * @returns 1 if a problem was found, 0 otherwise
196 FIRM_API int edges_verify_kind(ir_graph *irg, ir_edge_kind_t kind);
199 * Sets edge verification flag.
201 FIRM_API void edges_init_dbg(int do_dbg);
204 * Creates an ir_graph pass for edges_verify().
206 * @param name the name of this pass or NULL
207 * @param assert_on_problem assert if problems were found
209 * @return the newly created ir_graph pass
211 FIRM_API ir_graph_pass_t *irg_verify_edges_pass(const char *name,
212 unsigned assert_on_problem);
215 * Activates data and block edges for an irg.
216 * If the irg phase is phase_backend, Dependence edges are
217 * additionally activated.
219 * @param irg The graph to activate the edges for.
221 FIRM_API void edges_activate(ir_graph *irg);
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.
229 FIRM_API void edges_deactivate(ir_graph *irg);
232 * Ensures that edges are activated.
234 * @param irg the IR graph
236 FIRM_API void assure_edges(ir_graph *irg);
239 * Ensures that edges of a given kind are activated.
241 * @param irg the IR graph
242 * @param kind the edge kind
244 FIRM_API void assure_edges_kind(ir_graph *irg, ir_edge_kind_t kind);
247 * Walks only over Block nodes in the graph. Uses the block visited
248 * flag, so that it can be interleaved with another walker.
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
255 FIRM_API void irg_block_edges_walk(ir_node *block, irg_walk_func *pre,
256 irg_walk_func *post, void *env);
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);