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"
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 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 void irg_walk_core(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
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. If interprocedural_view
77 * is set, visits all reachable irgs.
79 void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, 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 void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
103 * Walks over all reachable nodes in the ir graph.
105 * @param irg the irg graph
106 * @param pre walker function, executed before the predecessor of a node are visited
107 * @param post walker function, executed after the predecessor of a node are visited
108 * @param env environment, passed to pre and post
110 * Like irg_walk(), but walks over all reachable nodes in the ir
111 * graph, starting at the end operation. During the walk current_ir_graph
112 * is set to irg. Does not use the link field.
113 * This walker also follows additional dependency egdes.
114 * interprocedural_view is not yet supported.
116 void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
119 * Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
121 * @param pre walker function, executed before the predecessor of a node are visited
122 * @param post walker function, executed after the predecessor of a node are visited
123 * @param env environment, passed to pre and post
125 * This function executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
126 * Sets current_ir_graph properly for each walk. Conserves current
127 * current_ir_graph. In interprocedural view nodes can be visited several
128 * times. Does not use the link field.
130 void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
132 #ifdef INTERPROCEDURAL_VIEW
134 * Walks all irgs in interprocedural view.
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 all irgs in interprocedural view.
141 * Visits each node only once. Sets current_ir_graph properly. Does not use the link field.
143 void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
146 /** Walks only over Block nodes in the graph.
148 * @param node the start node
149 * @param pre walker function, executed before the predecessor of a node are visited
150 * @param post walker function, executed after the predecessor of a node are visited
151 * @param env environment, passed to pre and post
153 * This function Walks only over Block nodes in the graph. Has it's own visited
154 * flag, so that it can be interleaved with the other walker.
155 * If a none block is passed, starts at the block this node belongs to.
156 * If end is passed also visits kept alive blocks. Does not use the link field.
158 void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
161 * Walks only over reachable Block nodes in the graph.
163 * @param irg the irg graph
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 * Like irg_block_walk(), but walks over all reachable blocks in the
169 * ir graph, starting at the end block. Does not use the link field.
171 void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
174 * Walks over all code in const_code_irg.
176 * @param pre walker function, executed before the predecessor of a node are visited
177 * @param post walker function, executed after the predecessor of a node are visited
178 * @param env environment, passed to pre and post
180 * This function walks over all code in const_code_irg.
181 * Uses visited flag in const_code_irg. Does not use the link field.
183 void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env);
186 * Walks over reachable nodes in block-wise topological order, i.e. visit
187 * all nodes in a block before going to another block, starting at the end operation.
188 * Executes pre before visiting the predecessor of a node, post after.
189 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
190 * determine visited nodes.
191 * It executes inc_irg_visited(current_ir_graph) to generate a new
192 * flag. It marks the node as visited before executing pre.
193 * The void *env can be used to pass status information between the
194 * pre and post functions. Does not use the link fields.
195 * Walks only intraprocedural, even in interprocedural view.
197 * @param irg the irg graph
198 * @param pre walker function, executed before the predecessor of a node are visited
199 * @param post walker function, executed after the predecessor of a node are visited
200 * @param env environment, passed to pre and post
202 void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
205 * Walks over reachable nodes in block-wise topological order, i.e. visit
206 * all nodes in a block before going to another block, starting at the end operation.
207 * Executes pre before visiting the predecessor of a node, post after.
208 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
209 * determine visited nodes.
210 * It executes inc_irg_visited(current_ir_graph) to generate a new
211 * flag. It marks the node as visited before executing pre.
212 * The void *env can be used to pass status information between the
213 * pre and post functions. Does not use the link fields.
214 * Walks only intraprocedural, even in interprocedural view.
215 * This walker also follows dependency edges.
217 * @param irg the irg graph
218 * @param pre walker function, executed before the predecessor of a node are visited
219 * @param post walker function, executed after the predecessor of a node are visited
220 * @param env environment, passed to pre and post
222 void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
225 * Walks over reachable nodes in block-wise topological order, i.e. visit
226 * all nodes in a block before going to another block, starting at the end operation.
227 * Visit the blocks in dominator tree top-down order.
228 * Executes pre before visiting the predecessor of a node, post after.
229 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
230 * determine visited nodes.
231 * It executes inc_irg_visited(current_ir_graph) to generate a new
232 * flag. It marks the node as visited before executing pre.
233 * The void *env can be used to pass status information between the
234 * pre and post functions. Does not use the link fields.
235 * Walks only intraprocedural, even in interprocedural view.
237 * @param irg the irg graph
238 * @param pre walker function, executed before the predecessor of a node are visited
239 * @param post walker function, executed after the predecessor of a node are visited
240 * @param env environment, passed to pre and post
242 void irg_walk_blkwise_dom_top_down(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
245 * Additionally walk over all anchors.
246 * This function visits all anchor nodes that otherwise might not been visited in a
247 * walk, for instance the Bad() node.
249 * @param irg the irg graph
250 * @param pre walker function, executed before the predecessor of a node are visited
251 * @param post walker function, executed after the predecessor of a node are visited
252 * @param env environment, passed to pre and post
254 void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
257 * Walker function which does not increase the visited flag before walking.
258 * Do not use this unless you know what you are doing.
260 unsigned irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post,