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);
125 * Walks all irgs in interprocedural view.
127 * @param pre - walker function, executed before the predecessor of a node are visited
128 * @param post - walker function, executed after the predecessor of a node are visited
129 * @param env - environment, passed to pre and post
131 * This function walks all irgs in interprocedural view.
132 * Visits each node only once. Sets current_ir_graph properly. Does not use the link field.
134 void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
136 /** Walks only over Block nodes in the graph.
138 * @param node - the start node
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 only over Block nodes in the graph. Has it's own visited
144 * flag, so that it can be interleaved with the other walker.
145 * If a none block is passed, starts at the block this node belongs to.
146 * If end is passed also visits kept alive blocks. Does not use the link field.
148 void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
151 * Walks only over reachable Block nodes in the graph.
153 * @param irg - the irg graph
154 * @param pre - walker function, executed before the predecessor of a node are visited
155 * @param post - walker function, executed after the predecessor of a node are visited
156 * @param env - environment, passed to pre and post
158 * Like irg_block_walk(), but walks over all reachable blocks in the
159 * ir graph, starting at the end block. Does not use the link field.
161 void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
164 * Walks over all code in const_code_irg.
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 * This function walks over all code in const_code_irg.
171 * Uses visited flag in const_code_irg. Does not use the link field.
173 void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env);
176 * Walks over reachable nodes in block-wise order, i.e. visit all nodes in a block
177 * 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.
185 * Walks only intraprocedural, even in interprocedural view.
187 * @param irg - the irg graph
188 * @param pre - walker function, executed before the predecessor of a node are visited
189 * @param post - walker function, executed after the predecessor of a node are visited
190 * @param env - environment, passed to pre and post
192 void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
195 * Walks over reachable nodes in block-wise order, i.e. visit all nodes in a block
196 * 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 * Walks only intraprocedural, even in interprocedural view.
205 * This walker also follows dependency edges.
207 * @param irg - the irg graph
208 * @param pre - walker function, executed before the predecessor of a node are visited
209 * @param post - walker function, executed after the predecessor of a node are visited
210 * @param env - environment, passed to pre and post
212 void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
215 * Additionally walk over all anchors. Do NOT increase the visit flag.
216 * This function visits all anchor nodes that otherwise might not been visited in a
217 * walk, for instance the Bad() node.
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_anchors(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);