3 * File name: ir/ir/irgwalk.h
5 * Author: Boris Boesler
6 * Modified by: Goetz Lindenmaier
9 * Copyright: (c) 1999-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
17 * Traverse an ir graph.
19 * @author Boris Boesler
21 * Traverse an ir graph:
22 * - execute the pre function before recursion
23 * - execute the post function after recursion
25 * Uses current_ir_graph (from irgraph.h)!!! Set it to the proper
26 * graph before starting the walker.
28 #ifndef _FIRM_IR_IRGWALK_H_
29 #define _FIRM_IR_IRGWALK_H_
31 #include "firm_types.h"
33 /* type of callback function for ir_graph walk */
34 #ifndef _IRG_WALK_FUNC_TYPEDEF_
35 #define _IRG_WALK_FUNC_TYPEDEF_
37 * The type of a walk function. Does not use the link field.
39 * @param node - the node that is just visited
40 * @param env - an environment pointer passed by the walk functions
42 typedef void irg_walk_func(ir_node *node, void *env);
46 * Walks over the ir graph.
48 * Walks over the ir graph, starting at the node given as first argument.
49 * Executes pre before visiting the predecessor of a node, post after.
50 * irg_walk uses the visited flag in irg and the nodes to determine visited
51 * nodes. It executes inc_irg_visited(current_ir_graph) to generate a new
52 * flag. Therefore current_ir_graph must be set before calling the walker.
53 * It marks the node as visited before executing pre.
54 * The void* env can be used to pass status information between the
55 * pre and post functions. Does not use the link fields.
57 * @param node - the start node
58 * @param pre - walker function, executed before the predecessor of a node are visited
59 * @param post - walker function, executed after the predecessor of a node are visited
60 * @param env - environment, passed to pre and post
63 void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
66 * Walks over all reachable nodes in the ir graph.
68 * @param irg - the irg graph
69 * @param pre - walker function, executed before the predecessor of a node are visited
70 * @param post - walker function, executed after the predecessor of a node are visited
71 * @param env - environment, passed to pre and post
73 * Like irg_walk(), but walks over all reachable nodes in the ir
74 * graph, starting at the end operation. During the walk current_ir_graph
75 * is set to irg. Does not use the link field. If interprocedural_view
76 * is set, visits all reachable irgs.
78 void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
81 * Walks over the ir graph.
83 * Walks over the ir graph, starting at the node given as first argument.
84 * Executes pre before visiting the predecessor of a node, post after.
85 * irg_walk uses the visited flag in irg and the nodes to determine visited
86 * nodes. It executes inc_irg_visited(current_ir_graph) to generate a new
87 * flag. Therefore current_ir_graph must be set before calling the walker.
88 * It marks the node as visited before executing pre.
89 * The void* env can be used to pass status information between the
90 * pre and post functions. Does not use the link fields.
91 * This walker also follows additional dependency egdes.
93 * @param node - the start node
94 * @param pre - walker function, executed before the predecessor of a node are visited
95 * @param post - walker function, executed after the predecessor of a node are visited
96 * @param env - environment, passed to pre and post
99 void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
102 * Walks over all reachable nodes in the ir graph.
104 * @param irg - the irg graph
105 * @param pre - walker function, executed before the predecessor of a node are visited
106 * @param post - walker function, executed after the predecessor of a node are visited
107 * @param env - environment, passed to pre and post
109 * Like irg_walk(), but walks over all reachable nodes in the ir
110 * graph, starting at the end operation. During the walk current_ir_graph
111 * is set to irg. Does not use the link field.
112 * This walker also follows additional dependency egdes.
113 * interprocedural_view is not yet supported.
115 void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
118 * Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
120 * @param pre - walker function, executed before the predecessor of a node are visited
121 * @param post - walker function, executed after the predecessor of a node are visited
122 * @param env - environment, passed to pre and post
124 * This function executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
125 * Sets current_ir_graph properly for each walk. Conserves current
126 * current_ir_graph. In interprocedural view nodes can be visited several
127 * times. Does not use the link field.
129 void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
132 * Walks all irgs in interprocedural view.
134 * @param pre - walker function, executed before the predecessor of a node are visited
135 * @param post - walker function, executed after the predecessor of a node are visited
136 * @param env - environment, passed to pre and post
138 * This function walks all irgs in interprocedural view.
139 * Visits each node only once. Sets current_ir_graph properly. Does not use the link field.
141 void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
143 /** Walks only over Block nodes in the graph.
145 * @param node - the start node
146 * @param pre - walker function, executed before the predecessor of a node are visited
147 * @param post - walker function, executed after the predecessor of a node are visited
148 * @param env - environment, passed to pre and post
150 * This function Walks only over Block nodes in the graph. Has it's own visited
151 * flag, so that it can be interleaved with the other walker.
152 * If a none block is passed, starts at the block this node belongs to.
153 * If end is passed also visits kept alive blocks. Does not use the link field.
155 void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
158 * Walks only over reachable Block nodes in the graph.
160 * @param irg - the irg graph
161 * @param pre - walker function, executed before the predecessor of a node are visited
162 * @param post - walker function, executed after the predecessor of a node are visited
163 * @param env - environment, passed to pre and post
165 * Like irg_block_walk(), but walks over all reachable blocks in the
166 * ir graph, starting at the end block. Does not use the link field.
168 void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
171 * Walks over all code in const_code_irg.
173 * @param pre - walker function, executed before the predecessor of a node are visited
174 * @param post - walker function, executed after the predecessor of a node are visited
175 * @param env - environment, passed to pre and post
177 * This function walks over all code in const_code_irg.
178 * Uses visited flag in const_code_irg. Does not use the link field.
180 void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env);
183 * Walks over reachable nodes in block-wise order, i.e. visit all nodes in a block
184 * before going to another block, starting at the end operation.
185 * Executes pre before visiting the predecessor of a node, post after.
186 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
187 * determine visited nodes.
188 * It executes inc_irg_visited(current_ir_graph) to generate a new
189 * flag. It marks the node as visited before executing pre.
190 * The void *env can be used to pass status information between the
191 * pre and post functions. Does not use the link fields.
192 * Walks only intraprocedural, even in interprocedural view.
194 * @param irg - the irg graph
195 * @param pre - walker function, executed before the predecessor of a node are visited
196 * @param post - walker function, executed after the predecessor of a node are visited
197 * @param env - environment, passed to pre and post
199 void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
202 * Walks over reachable nodes in block-wise order, i.e. visit all nodes in a block
203 * before going to another block, starting at the end operation.
204 * Executes pre before visiting the predecessor of a node, post after.
205 * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
206 * determine visited nodes.
207 * It executes inc_irg_visited(current_ir_graph) to generate a new
208 * flag. It marks the node as visited before executing pre.
209 * The void *env can be used to pass status information between the
210 * pre and post functions. Does not use the link fields.
211 * Walks only intraprocedural, even in interprocedural view.
212 * This walker also follows dependency edges.
214 * @param irg - the irg graph
215 * @param pre - walker function, executed before the predecessor of a node are visited
216 * @param post - walker function, executed after the predecessor of a node are visited
217 * @param env - environment, passed to pre and post
219 void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
222 * Additionally walk over all anchors. Do NOT increase the visit flag.
223 * This function visits all anchor nodes that otherwise might not been visited in a
224 * walk, for instance the Bad() node.
226 * @param irg - the irg graph
227 * @param pre - walker function, executed before the predecessor of a node are visited
228 * @param post - walker function, executed after the predecessor of a node are visited
229 * @param env - environment, passed to pre and post
231 void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
233 #endif /* _FIRM_IR_IRGWALK_H_ */