2 * Copyright (C) 1995-2007 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 * File name: ir/ir/irgwalk.h
24 * Author: Boris Boesler
25 * Modified by: Goetz Lindenmaier
28 * Copyright: (c) 1999-2003 Universität Karlsruhe
35 * Traverse an ir graph.
37 * @author Boris Boesler
39 * Traverse an ir graph:
40 * - execute the pre function before recursion
41 * - execute the post function after recursion
43 * Uses current_ir_graph (from irgraph.h)!!! Set it to the proper
44 * graph before starting the walker.
46 #ifndef _FIRM_IR_IRGWALK_H_
47 #define _FIRM_IR_IRGWALK_H_
49 #include "firm_types.h"
51 /* type of callback function for ir_graph walk */
52 #ifndef _IRG_WALK_FUNC_TYPEDEF_
53 #define _IRG_WALK_FUNC_TYPEDEF_
55 * The type of a walk function. Does not use the link field.
57 * @param node - the node that is just visited
58 * @param env - an environment pointer passed by the walk functions
60 typedef void irg_walk_func(ir_node *node, void *env);
64 * Walks over the ir graph.
66 * Walks over the ir graph, starting at the node given as first argument.
67 * Executes pre before visiting the predecessor of a node, post after.
68 * irg_walk uses the visited flag in irg and the nodes to determine visited
69 * nodes. It executes inc_irg_visited(current_ir_graph) to generate a new
70 * flag. Therefore current_ir_graph must be set before calling the walker.
71 * It marks the node as visited before executing pre.
72 * The void* env can be used to pass status information between the
73 * pre and post functions. Does not use the link fields.
75 * @param node - the start node
76 * @param pre - walker function, executed before the predecessor of a node are visited
77 * @param post - walker function, executed after the predecessor of a node are visited
78 * @param env - environment, passed to pre and post
81 void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
84 * Walks over all reachable nodes in the ir graph.
86 * @param irg - the irg graph
87 * @param pre - walker function, executed before the predecessor of a node are visited
88 * @param post - walker function, executed after the predecessor of a node are visited
89 * @param env - environment, passed to pre and post
91 * Like irg_walk(), but walks over all reachable nodes in the ir
92 * graph, starting at the end operation. During the walk current_ir_graph
93 * is set to irg. Does not use the link field. If interprocedural_view
94 * is set, visits all reachable irgs.
96 void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
99 * Walks over the ir graph.
101 * Walks over the ir graph, starting at the node given as first argument.
102 * Executes pre before visiting the predecessor of a node, post after.
103 * irg_walk uses the visited flag in irg and the nodes to determine visited
104 * nodes. It executes inc_irg_visited(current_ir_graph) to generate a new
105 * flag. Therefore current_ir_graph must be set before calling the walker.
106 * It marks the node as visited before executing pre.
107 * The void* env can be used to pass status information between the
108 * pre and post functions. Does not use the link fields.
109 * This walker also follows additional dependency egdes.
111 * @param node - the start node
112 * @param pre - walker function, executed before the predecessor of a node are visited
113 * @param post - walker function, executed after the predecessor of a node are visited
114 * @param env - environment, passed to pre and post
117 void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
120 * Walks over all reachable nodes in the ir graph.
122 * @param irg - the irg graph
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 * Like irg_walk(), but walks over all reachable nodes in the ir
128 * graph, starting at the end operation. During the walk current_ir_graph
129 * is set to irg. Does not use the link field.
130 * This walker also follows additional dependency egdes.
131 * interprocedural_view is not yet supported.
133 void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
136 * Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
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 executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
143 * Sets current_ir_graph properly for each walk. Conserves current
144 * current_ir_graph. In interprocedural view nodes can be visited several
145 * times. Does not use the link field.
147 void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
150 * Walks all irgs in interprocedural view.
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 * This function walks all irgs in interprocedural view.
157 * Visits each node only once. Sets current_ir_graph properly. Does not use the link field.
159 void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
161 /** Walks only over Block nodes in the graph.
163 * @param node - the start node
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 only over Block nodes in the graph. Has it's own visited
169 * flag, so that it can be interleaved with the other walker.
170 * If a none block is passed, starts at the block this node belongs to.
171 * If end is passed also visits kept alive blocks. Does not use the link field.
173 void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
176 * Walks only over reachable Block nodes in the graph.
178 * @param irg - the irg graph
179 * @param pre - walker function, executed before the predecessor of a node are visited
180 * @param post - walker function, executed after the predecessor of a node are visited
181 * @param env - environment, passed to pre and post
183 * Like irg_block_walk(), but walks over all reachable blocks in the
184 * ir graph, starting at the end block. Does not use the link field.
186 void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
189 * Walks over all code in const_code_irg.
191 * @param pre - walker function, executed before the predecessor of a node are visited
192 * @param post - walker function, executed after the predecessor of a node are visited
193 * @param env - environment, passed to pre and post
195 * This function walks over all code in const_code_irg.
196 * Uses visited flag in const_code_irg. Does not use the link field.
198 void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env);
201 * Walks over reachable nodes in block-wise order, i.e. visit all nodes in a block
202 * before going to another block, starting at the end operation.
203 * Executes pre before visiting the predecessor of a node, post after.
204 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
205 * determine visited nodes.
206 * It executes inc_irg_visited(current_ir_graph) to generate a new
207 * flag. It marks the node as visited before executing pre.
208 * The void *env can be used to pass status information between the
209 * pre and post functions. Does not use the link fields.
210 * Walks only intraprocedural, even in interprocedural view.
212 * @param irg - the irg graph
213 * @param pre - walker function, executed before the predecessor of a node are visited
214 * @param post - walker function, executed after the predecessor of a node are visited
215 * @param env - environment, passed to pre and post
217 void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
220 * Walks over reachable nodes in block-wise order, i.e. visit all nodes in a block
221 * before going to another block, starting at the end operation.
222 * Executes pre before visiting the predecessor of a node, post after.
223 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
224 * determine visited nodes.
225 * It executes inc_irg_visited(current_ir_graph) to generate a new
226 * flag. It marks the node as visited before executing pre.
227 * The void *env can be used to pass status information between the
228 * pre and post functions. Does not use the link fields.
229 * Walks only intraprocedural, even in interprocedural view.
230 * This walker also follows dependency edges.
232 * @param irg - the irg graph
233 * @param pre - walker function, executed before the predecessor of a node are visited
234 * @param post - walker function, executed after the predecessor of a node are visited
235 * @param env - environment, passed to pre and post
237 void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
240 * Additionally walk over all anchors. Do NOT increase the visit flag.
241 * This function visits all anchor nodes that otherwise might not been visited in a
242 * walk, for instance the Bad() node.
244 * @param irg - the irg graph
245 * @param pre - walker function, executed before the predecessor of a node are visited
246 * @param post - walker function, executed after the predecessor of a node are visited
247 * @param env - environment, passed to pre and post
249 void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
251 #endif /* _FIRM_IR_IRGWALK_H_ */