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
26 * Traverse an ir graph:
27 * - execute the pre function before recursion
28 * - execute the post function after recursion
30 * Uses current_ir_graph (from irgraph.h)!!! Set it to the proper
31 * graph before starting the walker.
33 #ifndef FIRM_IR_IRGWALK_H
34 #define FIRM_IR_IRGWALK_H
36 #include "firm_types.h"
40 * Walks over the ir graph.
42 * Walks over the ir graph, starting at the node given as first argument.
43 * Executes pre before visiting the predecessor of a node, post after.
44 * irg_walk uses the visited flag in irg and the nodes to determine visited
45 * nodes. It executes inc_irg_visited(current_ir_graph) to generate a new
46 * flag. Therefore current_ir_graph must be set before calling the walker.
47 * It marks the node as visited before executing pre.
48 * The void* env can be used to pass status information between the
49 * pre and post functions. Does not use the link fields.
51 * @param node the start node
52 * @param pre walker function, executed before the predecessor of a node are visited
53 * @param post walker function, executed after the predecessor of a node are visited
54 * @param env environment, passed to pre and post
57 FIRM_API void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
61 * core walker function. Does NOT touch current_ir_graph and does not call
62 * inc_irg_visited before walking
64 FIRM_API void irg_walk_core(ir_node *node, irg_walk_func *pre,
65 irg_walk_func *post, void *env);
68 * Walks over all reachable nodes in the ir graph.
70 * @param irg the irg graph
71 * @param pre walker function, executed before the predecessor of a node are visited
72 * @param post walker function, executed after the predecessor of a node are visited
73 * @param env environment, passed to pre and post
75 * Like irg_walk(), but walks over all reachable nodes in the ir
76 * graph, starting at the end operation. During the walk current_ir_graph
77 * is set to irg. Does not use the link field.
79 FIRM_API void irg_walk_graph(ir_graph *irg, irg_walk_func *pre,
80 irg_walk_func *post, void *env);
83 * Walks over the ir graph.
85 * Walks over the ir graph, starting at the node given as first argument.
86 * Executes pre before visiting the predecessor of a node, post after.
87 * irg_walk uses the visited flag in irg and the nodes to determine visited
88 * nodes. It executes inc_irg_visited(current_ir_graph) to generate a new
89 * flag. Therefore current_ir_graph must be set before calling the walker.
90 * It marks the node as visited before executing pre.
91 * The void* env can be used to pass status information between the
92 * pre and post functions. Does not use the link fields.
93 * This walker also follows additional dependency egdes.
95 * @param node the start node
96 * @param pre walker function, executed before the predecessor of a node are visited
97 * @param post walker function, executed after the predecessor of a node are visited
98 * @param env environment, passed to pre and post
101 FIRM_API void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre,
102 irg_walk_func *post, void *env);
105 * Walks over all reachable nodes in the ir graph.
107 * @param irg the irg graph
108 * @param pre walker function, executed before the predecessor of a node are visited
109 * @param post walker function, executed after the predecessor of a node are visited
110 * @param env environment, passed to pre and post
112 * Like irg_walk(), but walks over all reachable nodes in the ir
113 * graph, starting at the end operation. During the walk current_ir_graph
114 * is set to irg. Does not use the link field.
115 * This walker also follows additional dependency egdes.
117 FIRM_API void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre,
118 irg_walk_func *post, void *env);
121 * Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
123 * @param pre walker function, executed before the predecessor of a node are visited
124 * @param post walker function, executed after the predecessor of a node are visited
125 * @param env environment, passed to pre and post
127 * This function executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
128 * Sets current_ir_graph properly for each walk. Conserves current
129 * current_ir_graph. Does not use the link field.
131 FIRM_API void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
133 /** Walks only over Block nodes in the graph.
135 * @param node the start node
136 * @param pre walker function, executed before the predecessor of a node are visited
137 * @param post walker function, executed after the predecessor of a node are visited
138 * @param env environment, passed to pre and post
140 * This function Walks only over Block nodes in the graph. Has it's own visited
141 * flag, so that it can be interleaved with the other walker.
142 * If a none block is passed, starts at the block this node belongs to.
143 * If end is passed also visits kept alive blocks. Does not use the link field.
145 FIRM_API void irg_block_walk(ir_node *node, irg_walk_func *pre,
146 irg_walk_func *post, void *env);
149 * Walks only over reachable Block nodes in the graph.
151 * @param irg the irg graph
152 * @param pre walker function, executed before the predecessor of a node are visited
153 * @param post walker function, executed after the predecessor of a node are visited
154 * @param env environment, passed to pre and post
156 * Like irg_block_walk(), but walks over all reachable blocks in the
157 * ir graph, starting at the end block. Does not use the link field.
159 FIRM_API void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre,
160 irg_walk_func *post, void *env);
163 * Walks over all code in const_code_irg.
165 * @param pre walker function, executed before the predecessor of a node are visited
166 * @param post walker function, executed after the predecessor of a node are visited
167 * @param env environment, passed to pre and post
169 * This function walks over all code in const_code_irg.
170 * Uses visited flag in const_code_irg. Does not use the link field.
172 FIRM_API void walk_const_code(irg_walk_func *pre, irg_walk_func *post,
176 * Walks over reachable nodes in block-wise topological order, i.e. visit
177 * all nodes in a block before going to another block, starting at the end operation.
178 * Executes pre before visiting the predecessor of a node, post after.
179 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
180 * determine visited nodes.
181 * It executes inc_irg_visited(current_ir_graph) to generate a new
182 * flag. It marks the node as visited before executing pre.
183 * The void *env can be used to pass status information between the
184 * pre and post functions. Does not use the link fields.
186 * @param irg the irg graph
187 * @param pre walker function, executed before the predecessor of a node are visited
188 * @param post walker function, executed after the predecessor of a node are visited
189 * @param env environment, passed to pre and post
191 FIRM_API void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre,
192 irg_walk_func *post, void *env);
195 * Walks over reachable nodes in block-wise topological order, i.e. visit
196 * all nodes in a block before going to another block, starting at the end operation.
197 * Executes pre before visiting the predecessor of a node, post after.
198 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
199 * determine visited nodes.
200 * It executes inc_irg_visited(current_ir_graph) to generate a new
201 * flag. It marks the node as visited before executing pre.
202 * The void *env can be used to pass status information between the
203 * pre and post functions. Does not use the link fields.
204 * This walker also follows dependency edges.
206 * @param irg the irg graph
207 * @param pre walker function, executed before the predecessor of a node are visited
208 * @param post walker function, executed after the predecessor of a node are visited
209 * @param env environment, passed to pre and post
211 FIRM_API void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg,
213 irg_walk_func *post, void *env);
216 * Walks over reachable nodes in block-wise topological order, i.e. visit
217 * all nodes in a block before going to another block, starting at the end operation.
218 * Visit the blocks in dominator tree top-down order.
219 * Executes pre before visiting the predecessor of a node, post after.
220 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
221 * determine visited nodes.
222 * It executes inc_irg_visited(current_ir_graph) to generate a new
223 * flag. It marks the node as visited before executing pre.
224 * The void *env can be used to pass status information between the
225 * pre and post functions. Does not use the link fields.
227 * @param irg the irg graph
228 * @param pre walker function, executed before the predecessor of a node are visited
229 * @param post walker function, executed after the predecessor of a node are visited
230 * @param env environment, passed to pre and post
232 FIRM_API void irg_walk_blkwise_dom_top_down(ir_graph *irg, irg_walk_func *pre,
233 irg_walk_func *post, void *env);
236 * Additionally walk over all anchors.
237 * This function visits all anchor nodes that otherwise might not been visited in a
238 * walk, for instance the Bad() node.
240 * @param irg the irg graph
241 * @param pre walker function, executed before the predecessor of a node are visited
242 * @param post walker function, executed after the predecessor of a node are visited
243 * @param env environment, passed to pre and post
245 FIRM_API void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre,
246 irg_walk_func *post, void *env);
249 * Walker function which does not increase the visited flag before walking.
250 * Do not use this unless you know what you are doing.
252 unsigned irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post,