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 * @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"
38 /* type of callback function for ir_graph walk */
39 #ifndef _IRG_WALK_FUNC_TYPEDEF_
40 #define _IRG_WALK_FUNC_TYPEDEF_
42 * The type of a walk function. Does not use the link field.
44 * @param node - the node that is just visited
45 * @param env - an environment pointer passed by the walk functions
47 typedef void irg_walk_func(ir_node *node, void *env);
51 * Walks over the ir graph.
53 * Walks over the ir graph, starting at the node given as first argument.
54 * Executes pre before visiting the predecessor of a node, post after.
55 * irg_walk uses the visited flag in irg and the nodes to determine visited
56 * nodes. It executes inc_irg_visited(current_ir_graph) to generate a new
57 * flag. Therefore current_ir_graph must be set before calling the walker.
58 * It marks the node as visited before executing pre.
59 * The void* env can be used to pass status information between the
60 * pre and post functions. Does not use the link fields.
62 * @param node - the start node
63 * @param pre - walker function, executed before the predecessor of a node are visited
64 * @param post - walker function, executed after the predecessor of a node are visited
65 * @param env - environment, passed to pre and post
68 void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
71 * Walks over all reachable nodes in the ir graph.
73 * @param irg - the irg graph
74 * @param pre - walker function, executed before the predecessor of a node are visited
75 * @param post - walker function, executed after the predecessor of a node are visited
76 * @param env - environment, passed to pre and post
78 * Like irg_walk(), but walks over all reachable nodes in the ir
79 * graph, starting at the end operation. During the walk current_ir_graph
80 * is set to irg. Does not use the link field. If interprocedural_view
81 * is set, visits all reachable irgs.
83 void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
86 * Walks over the ir graph.
88 * Walks over the ir graph, starting at the node given as first argument.
89 * Executes pre before visiting the predecessor of a node, post after.
90 * irg_walk uses the visited flag in irg and the nodes to determine visited
91 * nodes. It executes inc_irg_visited(current_ir_graph) to generate a new
92 * flag. Therefore current_ir_graph must be set before calling the walker.
93 * It marks the node as visited before executing pre.
94 * The void* env can be used to pass status information between the
95 * pre and post functions. Does not use the link fields.
96 * This walker also follows additional dependency egdes.
98 * @param node - the start node
99 * @param pre - walker function, executed before the predecessor of a node are visited
100 * @param post - walker function, executed after the predecessor of a node are visited
101 * @param env - environment, passed to pre and post
104 void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre, 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.
118 * interprocedural_view is not yet supported.
120 void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre, 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. In interprocedural view nodes can be visited several
132 * times. Does not use the link field.
134 void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
137 * Walks all irgs in interprocedural view.
139 * @param pre - walker function, executed before the predecessor of a node are visited
140 * @param post - walker function, executed after the predecessor of a node are visited
141 * @param env - environment, passed to pre and post
143 * This function walks all irgs in interprocedural view.
144 * Visits each node only once. Sets current_ir_graph properly. Does not use the link field.
146 void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
148 /** Walks only over Block nodes in the graph.
150 * @param node - the start node
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 * This function Walks only over Block nodes in the graph. Has it's own visited
156 * flag, so that it can be interleaved with the other walker.
157 * If a none block is passed, starts at the block this node belongs to.
158 * If end is passed also visits kept alive blocks. Does not use the link field.
160 void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
163 * Walks only over reachable Block nodes in the graph.
165 * @param irg - the irg graph
166 * @param pre - walker function, executed before the predecessor of a node are visited
167 * @param post - walker function, executed after the predecessor of a node are visited
168 * @param env - environment, passed to pre and post
170 * Like irg_block_walk(), but walks over all reachable blocks in the
171 * ir graph, starting at the end block. Does not use the link field.
173 void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
176 * Walks over all code in const_code_irg.
178 * @param pre - walker function, executed before the predecessor of a node are visited
179 * @param post - walker function, executed after the predecessor of a node are visited
180 * @param env - environment, passed to pre and post
182 * This function walks over all code in const_code_irg.
183 * Uses visited flag in const_code_irg. Does not use the link field.
185 void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env);
188 * Walks over reachable nodes in block-wise order, i.e. visit all nodes in a block
189 * before going to another block, starting at the end operation.
190 * Executes pre before visiting the predecessor of a node, post after.
191 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
192 * determine visited nodes.
193 * It executes inc_irg_visited(current_ir_graph) to generate a new
194 * flag. It marks the node as visited before executing pre.
195 * The void *env can be used to pass status information between the
196 * pre and post functions. Does not use the link fields.
197 * Walks only intraprocedural, even in interprocedural view.
199 * @param irg - the irg graph
200 * @param pre - walker function, executed before the predecessor of a node are visited
201 * @param post - walker function, executed after the predecessor of a node are visited
202 * @param env - environment, passed to pre and post
204 void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
207 * Walks over reachable nodes in block-wise order, i.e. visit all nodes in a block
208 * before going to another block, starting at the end operation.
209 * Executes pre before visiting the predecessor of a node, post after.
210 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
211 * determine visited nodes.
212 * It executes inc_irg_visited(current_ir_graph) to generate a new
213 * flag. It marks the node as visited before executing pre.
214 * The void *env can be used to pass status information between the
215 * pre and post functions. Does not use the link fields.
216 * Walks only intraprocedural, even in interprocedural view.
217 * This walker also follows dependency edges.
219 * @param irg - the irg graph
220 * @param pre - walker function, executed before the predecessor of a node are visited
221 * @param post - walker function, executed after the predecessor of a node are visited
222 * @param env - environment, passed to pre and post
224 void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
227 * Additionally walk over all anchors. Do NOT increase the visit flag.
228 * This function visits all anchor nodes that otherwise might not been visited in a
229 * walk, for instance the Bad() node.
231 * @param irg - the irg graph
232 * @param pre - walker function, executed before the predecessor of a node are visited
233 * @param post - walker function, executed after the predecessor of a node are visited
234 * @param env - environment, passed to pre and post
236 void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);