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 #ifndef FIRM_IR_IRGWALK_H
26 #define FIRM_IR_IRGWALK_H
28 #include "firm_types.h"
33 * @defgroup irgwalk Traversing
36 * - execute the pre function before recursion
37 * - execute the post function after recursion
42 * Walks over the ir graph.
44 * Walks over the ir graph, starting at the node given as first argument.
45 * Executes pre before visiting the predecessor of a node, post after.
46 * irg_walk uses the visited flag in irg and the nodes to determine visited
47 * nodes. It executes inc_irg_visited(current_ir_graph) to generate a new
48 * flag. Therefore current_ir_graph must be set before calling the walker.
49 * It marks the node as visited before executing pre.
50 * The void* env can be used to pass status information between the
51 * pre and post functions. Does not use the link fields.
53 * @param node the start node
54 * @param pre walker function, executed before the predecessor of a node are visited
55 * @param post walker function, executed after the predecessor of a node are visited
56 * @param env environment, passed to pre and post
59 FIRM_API void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
63 * core walker function. Does NOT touch current_ir_graph and does not call
64 * inc_irg_visited before walking
66 FIRM_API void irg_walk_core(ir_node *node, irg_walk_func *pre,
67 irg_walk_func *post, void *env);
70 * Walks over all reachable nodes in the ir graph.
72 * @param irg the irg graph
73 * @param pre walker function, executed before the predecessor of a node are visited
74 * @param post walker function, executed after the predecessor of a node are visited
75 * @param env environment, passed to pre and post
77 * Like irg_walk(), but walks over all reachable nodes in the ir
78 * graph, starting at the end operation. During the walk current_ir_graph
79 * is set to irg. Does not use the link field.
81 FIRM_API void irg_walk_graph(ir_graph *irg, irg_walk_func *pre,
82 irg_walk_func *post, void *env);
85 * Walks over the ir graph.
87 * Walks over the ir graph, starting at the node given as first argument.
88 * Executes pre before visiting the predecessor of a node, post after.
89 * irg_walk uses the visited flag in irg and the nodes to determine visited
90 * nodes. It executes inc_irg_visited(current_ir_graph) to generate a new
91 * flag. Therefore current_ir_graph must be set before calling the walker.
92 * It marks the node as visited before executing pre.
93 * The void* env can be used to pass status information between the
94 * pre and post functions. Does not use the link fields.
95 * This walker also follows additional dependency egdes.
97 * @param node the start node
98 * @param pre walker function, executed before the predecessor of a node are visited
99 * @param post walker function, executed after the predecessor of a node are visited
100 * @param env environment, passed to pre and post
103 FIRM_API void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre,
104 irg_walk_func *post, void *env);
107 * Walks over all reachable nodes in the ir graph.
109 * @param irg the irg graph
110 * @param pre walker function, executed before the predecessor of a node are visited
111 * @param post walker function, executed after the predecessor of a node are visited
112 * @param env environment, passed to pre and post
114 * Like irg_walk(), but walks over all reachable nodes in the ir
115 * graph, starting at the end operation. During the walk current_ir_graph
116 * is set to irg. Does not use the link field.
117 * This walker also follows additional dependency egdes.
119 FIRM_API void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre,
120 irg_walk_func *post, void *env);
123 * Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
125 * @param pre walker function, executed before the predecessor of a node are visited
126 * @param post walker function, executed after the predecessor of a node are visited
127 * @param env environment, passed to pre and post
129 * This function executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
130 * Sets current_ir_graph properly for each walk. Conserves current
131 * current_ir_graph. Does not use the link field.
133 FIRM_API void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
135 /** Walks only over Block nodes in the graph.
137 * @param node the start node
138 * @param pre walker function, executed before the predecessor of a node are visited
139 * @param post walker function, executed after the predecessor of a node are visited
140 * @param env environment, passed to pre and post
142 * This function Walks only over Block nodes in the graph. Has its own visited
143 * flag, so that it can be interleaved with the other walker.
144 * If a non-block is passed, starts at the block this node belongs to.
145 * If end is passed also visits kept alive blocks. Does not use the link field.
147 FIRM_API void irg_block_walk(ir_node *node, irg_walk_func *pre,
148 irg_walk_func *post, void *env);
151 * Walks only over reachable Block nodes in the graph.
153 * @param irg the irg graph
154 * @param pre walker function, executed before the predecessor of a node are visited
155 * @param post walker function, executed after the predecessor of a node are visited
156 * @param env environment, passed to pre and post
158 * Like irg_block_walk(), but walks over all reachable blocks in the
159 * ir graph, starting at the end block. Does not use the link field.
161 FIRM_API void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre,
162 irg_walk_func *post, void *env);
165 * Walks over all code in const_code_irg.
167 * @param pre walker function, executed before the predecessor of a node are visited
168 * @param post walker function, executed after the predecessor of a node are visited
169 * @param env environment, passed to pre and post
171 * This function walks over all code in const_code_irg.
172 * Uses visited flag in const_code_irg. Does not use the link field.
174 FIRM_API void walk_const_code(irg_walk_func *pre, irg_walk_func *post,
178 * Walks over reachable nodes in block-wise topological order, i.e. visit
179 * all nodes in a block before going to another block, starting at the end operation.
180 * Executes pre before visiting the predecessor of a node, post after.
181 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
182 * determine visited nodes.
183 * It executes inc_irg_visited(current_ir_graph) to generate a new
184 * flag. It marks the node as visited before executing pre.
185 * The void *env can be used to pass status information between the
186 * pre and post functions. Does not use the link fields.
188 * @param irg the irg graph
189 * @param pre walker function, executed before the predecessor of a node are visited
190 * @param post walker function, executed after the predecessor of a node are visited
191 * @param env environment, passed to pre and post
193 FIRM_API void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre,
194 irg_walk_func *post, void *env);
197 * Walks over reachable nodes in block-wise topological order, i.e. visit
198 * all nodes in a block before going to another block, starting at the end operation.
199 * Executes pre before visiting the predecessor of a node, post after.
200 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
201 * determine visited nodes.
202 * It executes inc_irg_visited(current_ir_graph) to generate a new
203 * flag. It marks the node as visited before executing pre.
204 * The void *env can be used to pass status information between the
205 * pre and post functions. Does not use the link fields.
206 * This walker also follows dependency edges.
208 * @param irg the irg graph
209 * @param pre walker function, executed before the predecessor of a node are visited
210 * @param post walker function, executed after the predecessor of a node are visited
211 * @param env environment, passed to pre and post
213 FIRM_API void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg,
215 irg_walk_func *post, void *env);
218 * Walks over reachable nodes in block-wise topological order, i.e. visit
219 * all nodes in a block before going to another block, starting at the end operation.
220 * Visit the blocks in dominator tree top-down order.
221 * Executes pre before visiting the predecessor of a node, post after.
222 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
223 * determine visited nodes.
224 * It executes inc_irg_visited(current_ir_graph) to generate a new
225 * flag. It marks the node as visited before executing pre.
226 * The void *env can be used to pass status information between the
227 * pre and post functions. Does not use the link fields.
229 * @param irg the irg graph
230 * @param pre walker function, executed before the predecessor of a node are visited
231 * @param post walker function, executed after the predecessor of a node are visited
232 * @param env environment, passed to pre and post
234 FIRM_API void irg_walk_blkwise_dom_top_down(ir_graph *irg, irg_walk_func *pre,
235 irg_walk_func *post, void *env);
238 * Additionally walk over all anchors.
239 * This function visits all anchor nodes that otherwise might not been visited in a
240 * walk, for instance the Bad() node.
242 * @param irg the irg graph
243 * @param pre walker function, executed before the predecessor of a node are visited
244 * @param post walker function, executed after the predecessor of a node are visited
245 * @param env environment, passed to pre and post
247 FIRM_API void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre,
248 irg_walk_func *post, void *env);
251 * Walker function which does not increase the visited flag before walking.
252 * Do not use this unless you know what you are doing.
254 unsigned irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post,