2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Traverse an ir graph
23 * @author Boris Boesler, Goetz Lindenmaier
25 * Traverse an ir graph:
26 * - execute the pre function before recursion
27 * - execute the post function after recursion
29 * Uses current_ir_graph (from irgraph.h)!!! Set it to the proper
30 * graph before starting the walker.
32 #ifndef FIRM_IR_IRGWALK_H
33 #define FIRM_IR_IRGWALK_H
35 #include "firm_types.h"
39 * Walks over the ir graph.
41 * Walks over the ir graph, starting at the node given as first argument.
42 * Executes pre before visiting the predecessor of a node, post after.
43 * irg_walk uses the visited flag in irg and the nodes to determine visited
44 * nodes. It executes inc_irg_visited(current_ir_graph) to generate a new
45 * flag. Therefore current_ir_graph must be set before calling the walker.
46 * It marks the node as visited before executing pre.
47 * The void* env can be used to pass status information between the
48 * pre and post functions. Does not use the link fields.
50 * @param node the start node
51 * @param pre walker function, executed before the predecessor of a node are visited
52 * @param post walker function, executed after the predecessor of a node are visited
53 * @param env environment, passed to pre and post
56 FIRM_API void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
60 * core walker function. Does NOT touch current_ir_graph and does not call
61 * inc_irg_visited before walking
63 FIRM_API void irg_walk_core(ir_node *node, irg_walk_func *pre,
64 irg_walk_func *post, void *env);
67 * Walks over all reachable nodes in the ir graph.
69 * @param irg the irg graph
70 * @param pre walker function, executed before the predecessor of a node are visited
71 * @param post walker function, executed after the predecessor of a node are visited
72 * @param env environment, passed to pre and post
74 * Like irg_walk(), but walks over all reachable nodes in the ir
75 * graph, starting at the end operation. During the walk current_ir_graph
76 * is set to irg. Does not use the link field.
78 FIRM_API void irg_walk_graph(ir_graph *irg, irg_walk_func *pre,
79 irg_walk_func *post, void *env);
82 * Walks over the ir graph.
84 * Walks over the ir graph, starting at the node given as first argument.
85 * Executes pre before visiting the predecessor of a node, post after.
86 * irg_walk uses the visited flag in irg and the nodes to determine visited
87 * nodes. It executes inc_irg_visited(current_ir_graph) to generate a new
88 * flag. Therefore current_ir_graph must be set before calling the walker.
89 * It marks the node as visited before executing pre.
90 * The void* env can be used to pass status information between the
91 * pre and post functions. Does not use the link fields.
92 * This walker also follows additional dependency egdes.
94 * @param node the start node
95 * @param pre walker function, executed before the predecessor of a node are visited
96 * @param post walker function, executed after the predecessor of a node are visited
97 * @param env environment, passed to pre and post
100 FIRM_API void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre,
101 irg_walk_func *post, void *env);
104 * Walks over all reachable nodes in the ir graph.
106 * @param irg the irg graph
107 * @param pre walker function, executed before the predecessor of a node are visited
108 * @param post walker function, executed after the predecessor of a node are visited
109 * @param env environment, passed to pre and post
111 * Like irg_walk(), but walks over all reachable nodes in the ir
112 * graph, starting at the end operation. During the walk current_ir_graph
113 * is set to irg. Does not use the link field.
114 * This walker also follows additional dependency egdes.
116 FIRM_API void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre,
117 irg_walk_func *post, void *env);
120 * Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
122 * @param pre walker function, executed before the predecessor of a node are visited
123 * @param post walker function, executed after the predecessor of a node are visited
124 * @param env environment, passed to pre and post
126 * This function executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
127 * Sets current_ir_graph properly for each walk. Conserves current
128 * current_ir_graph. Does not use the link field.
130 FIRM_API void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
132 /** Walks only over Block nodes in the graph.
134 * @param node the start node
135 * @param pre walker function, executed before the predecessor of a node are visited
136 * @param post walker function, executed after the predecessor of a node are visited
137 * @param env environment, passed to pre and post
139 * This function Walks only over Block nodes in the graph. Has its own visited
140 * flag, so that it can be interleaved with the other walker.
141 * If a non-block is passed, starts at the block this node belongs to.
142 * If end is passed also visits kept alive blocks. Does not use the link field.
144 FIRM_API void irg_block_walk(ir_node *node, irg_walk_func *pre,
145 irg_walk_func *post, void *env);
148 * Walks only over reachable Block nodes in the graph.
150 * @param irg the irg graph
151 * @param pre walker function, executed before the predecessor of a node are visited
152 * @param post walker function, executed after the predecessor of a node are visited
153 * @param env environment, passed to pre and post
155 * Like irg_block_walk(), but walks over all reachable blocks in the
156 * ir graph, starting at the end block. Does not use the link field.
158 FIRM_API void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre,
159 irg_walk_func *post, void *env);
162 * Walks over all code in const_code_irg.
164 * @param pre walker function, executed before the predecessor of a node are visited
165 * @param post walker function, executed after the predecessor of a node are visited
166 * @param env environment, passed to pre and post
168 * This function walks over all code in const_code_irg.
169 * Uses visited flag in const_code_irg. Does not use the link field.
171 FIRM_API void walk_const_code(irg_walk_func *pre, irg_walk_func *post,
175 * Walks over reachable nodes in block-wise topological order, i.e. visit
176 * all nodes in a block before going to another block, starting at the end operation.
177 * Executes pre before visiting the predecessor of a node, post after.
178 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
179 * determine visited nodes.
180 * It executes inc_irg_visited(current_ir_graph) to generate a new
181 * flag. It marks the node as visited before executing pre.
182 * The void *env can be used to pass status information between the
183 * pre and post functions. Does not use the link fields.
185 * @param irg the irg graph
186 * @param pre walker function, executed before the predecessor of a node are visited
187 * @param post walker function, executed after the predecessor of a node are visited
188 * @param env environment, passed to pre and post
190 FIRM_API void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre,
191 irg_walk_func *post, void *env);
194 * Walks over reachable nodes in block-wise topological order, i.e. visit
195 * all nodes in a block before going to another block, starting at the end operation.
196 * Executes pre before visiting the predecessor of a node, post after.
197 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
198 * determine visited nodes.
199 * It executes inc_irg_visited(current_ir_graph) to generate a new
200 * flag. It marks the node as visited before executing pre.
201 * The void *env can be used to pass status information between the
202 * pre and post functions. Does not use the link fields.
203 * This walker also follows dependency edges.
205 * @param irg the irg graph
206 * @param pre walker function, executed before the predecessor of a node are visited
207 * @param post walker function, executed after the predecessor of a node are visited
208 * @param env environment, passed to pre and post
210 FIRM_API void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg,
212 irg_walk_func *post, void *env);
215 * Walks over reachable nodes in block-wise topological order, i.e. visit
216 * all nodes in a block before going to another block, starting at the end operation.
217 * Visit the blocks in dominator tree top-down order.
218 * Executes pre before visiting the predecessor of a node, post after.
219 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
220 * determine visited nodes.
221 * It executes inc_irg_visited(current_ir_graph) to generate a new
222 * flag. It marks the node as visited before executing pre.
223 * The void *env can be used to pass status information between the
224 * pre and post functions. Does not use the link fields.
226 * @param irg the irg graph
227 * @param pre walker function, executed before the predecessor of a node are visited
228 * @param post walker function, executed after the predecessor of a node are visited
229 * @param env environment, passed to pre and post
231 FIRM_API void irg_walk_blkwise_dom_top_down(ir_graph *irg, irg_walk_func *pre,
232 irg_walk_func *post, void *env);
235 * Additionally walk over all anchors.
236 * This function visits all anchor nodes that otherwise might not been visited in a
237 * walk, for instance the Bad() node.
239 * @param irg the irg graph
240 * @param pre walker function, executed before the predecessor of a node are visited
241 * @param post walker function, executed after the predecessor of a node are visited
242 * @param env environment, passed to pre and post
244 FIRM_API void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre,
245 irg_walk_func *post, void *env);
248 * Walker function which does not increase the visited flag before walking.
249 * Do not use this unless you know what you are doing.
251 unsigned irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post,