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"
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, void *env);
59 * Walks over all reachable nodes in the ir graph.
61 * @param irg - the irg graph
62 * @param pre - walker function, executed before the predecessor of a node are visited
63 * @param post - walker function, executed after the predecessor of a node are visited
64 * @param env - environment, passed to pre and post
66 * Like irg_walk(), but walks over all reachable nodes in the ir
67 * graph, starting at the end operation. During the walk current_ir_graph
68 * is set to irg. Does not use the link field. If interprocedural_view
69 * is set, visits all reachable irgs.
71 void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
74 * Walks over the ir graph.
76 * Walks over the ir graph, starting at the node given as first argument.
77 * Executes pre before visiting the predecessor of a node, post after.
78 * irg_walk uses the visited flag in irg and the nodes to determine visited
79 * nodes. It executes inc_irg_visited(current_ir_graph) to generate a new
80 * flag. Therefore current_ir_graph must be set before calling the walker.
81 * It marks the node as visited before executing pre.
82 * The void* env can be used to pass status information between the
83 * pre and post functions. Does not use the link fields.
84 * This walker also follows additional dependency egdes.
86 * @param node - the start node
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
92 void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
95 * Walks over all reachable nodes in the ir graph.
97 * @param irg - the irg graph
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
102 * Like irg_walk(), but walks over all reachable nodes in the ir
103 * graph, starting at the end operation. During the walk current_ir_graph
104 * is set to irg. Does not use the link field.
105 * This walker also follows additional dependency egdes.
106 * interprocedural_view is not yet supported.
108 void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
111 * Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
113 * @param pre - walker function, executed before the predecessor of a node are visited
114 * @param post - walker function, executed after the predecessor of a node are visited
115 * @param env - environment, passed to pre and post
117 * This function executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
118 * Sets current_ir_graph properly for each walk. Conserves current
119 * current_ir_graph. In interprocedural view nodes can be visited several
120 * times. Does not use the link field.
122 void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
124 #ifdef INTERPROCEDURAL_VIEW
126 * Walks all irgs in interprocedural view.
128 * @param pre - walker function, executed before the predecessor of a node are visited
129 * @param post - walker function, executed after the predecessor of a node are visited
130 * @param env - environment, passed to pre and post
132 * This function walks all irgs in interprocedural view.
133 * Visits each node only once. Sets current_ir_graph properly. Does not use the link field.
135 void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
138 /** Walks only over Block nodes in the graph.
140 * @param node - the start node
141 * @param pre - walker function, executed before the predecessor of a node are visited
142 * @param post - walker function, executed after the predecessor of a node are visited
143 * @param env - environment, passed to pre and post
145 * This function Walks only over Block nodes in the graph. Has it's own visited
146 * flag, so that it can be interleaved with the other walker.
147 * If a none block is passed, starts at the block this node belongs to.
148 * If end is passed also visits kept alive blocks. Does not use the link field.
150 void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
153 * Walks only over reachable Block nodes in the graph.
155 * @param irg - the irg graph
156 * @param pre - walker function, executed before the predecessor of a node are visited
157 * @param post - walker function, executed after the predecessor of a node are visited
158 * @param env - environment, passed to pre and post
160 * Like irg_block_walk(), but walks over all reachable blocks in the
161 * ir graph, starting at the end block. Does not use the link field.
163 void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
166 * Walks over all code in const_code_irg.
168 * @param pre - walker function, executed before the predecessor of a node are visited
169 * @param post - walker function, executed after the predecessor of a node are visited
170 * @param env - environment, passed to pre and post
172 * This function walks over all code in const_code_irg.
173 * Uses visited flag in const_code_irg. Does not use the link field.
175 void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env);
178 * Walks over reachable nodes in block-wise order, i.e. visit all nodes in a block
179 * 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.
187 * Walks only intraprocedural, even in interprocedural view.
189 * @param irg - the irg graph
190 * @param pre - walker function, executed before the predecessor of a node are visited
191 * @param post - walker function, executed after the predecessor of a node are visited
192 * @param env - environment, passed to pre and post
194 void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
197 * Walks over reachable nodes in block-wise order, i.e. visit all nodes in a block
198 * 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 * Walks only intraprocedural, even in interprocedural view.
207 * This walker also follows dependency edges.
209 * @param irg - the irg graph
210 * @param pre - walker function, executed before the predecessor of a node are visited
211 * @param post - walker function, executed after the predecessor of a node are visited
212 * @param env - environment, passed to pre and post
214 void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
217 * Additionally walk over all anchors. Do NOT increase the visit flag.
218 * This function visits all anchor nodes that otherwise might not been visited in a
219 * walk, for instance the Bad() node.
221 * @param irg - the irg graph
222 * @param pre - walker function, executed before the predecessor of a node are visited
223 * @param post - walker function, executed after the predecessor of a node are visited
224 * @param env - environment, passed to pre and post
226 void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);