remove $Id$, it doesn't work with git anyway
[libfirm] / include / libfirm / irgwalk.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief    Traverse an ir graph
23  * @author   Boris Boesler, Goetz Lindenmaier
24  * @brief
25  *  Traverse an ir graph:
26  *  - execute the pre function before recursion
27  *  - execute the post function after recursion
28  *
29  *  Uses current_ir_graph (from irgraph.h)!!! Set it to the proper
30  *  graph before starting the walker.
31  */
32 #ifndef FIRM_IR_IRGWALK_H
33 #define FIRM_IR_IRGWALK_H
34
35 #include "firm_types.h"
36 #include "begin.h"
37
38 /**
39  * Walks over the ir graph.
40  *
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.
49  *
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
54  *
55  */
56 FIRM_API void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
57                        void *env);
58
59 /**
60  * core walker function. Does NOT touch current_ir_graph and does not call
61  * inc_irg_visited before walking
62  */
63 FIRM_API void irg_walk_core(ir_node *node, irg_walk_func *pre,
64                             irg_walk_func *post, void *env);
65
66 /**
67  * Walks over all reachable nodes in the ir graph.
68  *
69  * @param irg   the irg graph
70  * @param pre   walker function, executed before the predecessor of a node are visited
71  * @param post  walker function, executed after the predecessor of a node are visited
72  * @param env   environment, passed to pre and post
73  *
74  * Like irg_walk(), but walks over all reachable nodes in the ir
75  * graph, starting at the end operation. During the walk current_ir_graph
76  * is set to irg.  Does not use the link field.
77  */
78 FIRM_API void irg_walk_graph(ir_graph *irg, irg_walk_func *pre,
79                              irg_walk_func *post, void *env);
80
81 /**
82  * Walks over the ir graph.
83  *
84  * Walks over the ir graph, starting at the node given as first argument.
85  * Executes pre before visiting the predecessor of a node, post after.
86  * irg_walk uses the visited flag in irg and the nodes to determine visited
87  * nodes.  It executes inc_irg_visited(current_ir_graph) to generate a new
88  * flag.  Therefore current_ir_graph must be set before calling the walker.
89  * It marks the node as visited before executing pre.
90  * The void* env can be used to pass status information between the
91  * pre and post functions.  Does not use the link fields.
92  * This walker also follows additional dependency egdes.
93  *
94  * @param node  the start node
95  * @param pre   walker function, executed before the predecessor of a node are visited
96  * @param post  walker function, executed after the predecessor of a node are visited
97  * @param env   environment, passed to pre and post
98  *
99  */
100 FIRM_API void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre,
101                                  irg_walk_func *post, void *env);
102
103 /**
104  * Walks over all reachable nodes in the ir graph.
105  *
106  * @param irg   the irg graph
107  * @param pre   walker function, executed before the predecessor of a node are visited
108  * @param post  walker function, executed after the predecessor of a node are visited
109  * @param env   environment, passed to pre and post
110  *
111  * Like irg_walk(), but walks over all reachable nodes in the ir
112  * graph, starting at the end operation. During the walk current_ir_graph
113  * is set to irg.  Does not use the link field.
114  * This walker also follows additional dependency egdes.
115  */
116 FIRM_API void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre,
117                                        irg_walk_func *post, void *env);
118
119 /**
120  * Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
121  *
122  * @param pre   walker function, executed before the predecessor of a node are visited
123  * @param post  walker function, executed after the predecessor of a node are visited
124  * @param env   environment, passed to pre and post
125  *
126  * This function executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
127  * Sets current_ir_graph properly for each walk.  Conserves current
128  * current_ir_graph. Does not use the link field.
129  */
130 FIRM_API void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
131
132 /** Walks only over Block nodes in the graph.
133  *
134  * @param node  the start node
135  * @param pre   walker function, executed before the predecessor of a node are visited
136  * @param post  walker function, executed after the predecessor of a node are visited
137  * @param env   environment, passed to pre and post
138  *
139  * This function Walks only over Block nodes in the graph. Has its own visited
140  * flag, so that it can be interleaved with the other walker.
141  * If a non-block is passed, starts at the block this node belongs to.
142  * If end is passed also visits kept alive blocks. Does not use the link field.
143  */
144 FIRM_API void irg_block_walk(ir_node *node, irg_walk_func *pre,
145                              irg_walk_func *post, void *env);
146
147 /**
148  * Walks only over reachable Block nodes in the graph.
149  *
150  * @param irg   the irg graph
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
154  *
155  * Like irg_block_walk(), but walks over all reachable blocks in the
156  * ir graph, starting at the end block. Does not use the link field.
157  */
158 FIRM_API void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre,
159                                    irg_walk_func *post, void *env);
160
161 /**
162  * Walks over all code in const_code_irg.
163  *
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
167  *
168  * This function walks over all code in const_code_irg.
169  * Uses visited flag in const_code_irg.  Does not use the link field.
170  */
171 FIRM_API void walk_const_code(irg_walk_func *pre, irg_walk_func *post,
172                               void *env);
173
174 /**
175  * Walks over reachable nodes in block-wise topological order, i.e. visit
176  * all nodes in a block before going to another block, starting at the end operation.
177  * Executes pre before visiting the predecessor of a node, post after.
178  * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
179  * determine visited nodes.
180  * It executes inc_irg_visited(current_ir_graph) to generate a new
181  * flag. It marks the node as visited before executing pre.
182  * The void *env can be used to pass status information between the
183  * pre and post functions.  Does not use the link fields.
184  *
185  * @param irg   the irg graph
186  * @param pre   walker function, executed before the predecessor of a node are visited
187  * @param post  walker function, executed after the predecessor of a node are visited
188  * @param env   environment, passed to pre and post
189  */
190 FIRM_API void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre,
191                                      irg_walk_func *post, void *env);
192
193 /**
194  * Walks over reachable nodes in block-wise topological order, i.e. visit
195  * all nodes in a block before going to another block, starting at the end operation.
196  * Executes pre before visiting the predecessor of a node, post after.
197  * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
198  * determine visited nodes.
199  * It executes inc_irg_visited(current_ir_graph) to generate a new
200  * flag. It marks the node as visited before executing pre.
201  * The void *env can be used to pass status information between the
202  * pre and post functions.  Does not use the link fields.
203  * This walker also follows dependency edges.
204  *
205  * @param irg   the irg graph
206  * @param pre   walker function, executed before the predecessor of a node are visited
207  * @param post  walker function, executed after the predecessor of a node are visited
208  * @param env   environment, passed to pre and post
209  */
210 FIRM_API void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg,
211                                                irg_walk_func *pre,
212                                                irg_walk_func *post, void *env);
213
214 /**
215  * Walks over reachable nodes in block-wise topological order, i.e. visit
216  * all nodes in a block before going to another block, starting at the end operation.
217  * Visit the blocks in dominator tree top-down order.
218  * Executes pre before visiting the predecessor of a node, post after.
219  * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
220  * determine visited nodes.
221  * It executes inc_irg_visited(current_ir_graph) to generate a new
222  * flag. It marks the node as visited before executing pre.
223  * The void *env can be used to pass status information between the
224  * pre and post functions.  Does not use the link fields.
225  *
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
230  */
231 FIRM_API void irg_walk_blkwise_dom_top_down(ir_graph *irg, irg_walk_func *pre,
232                                             irg_walk_func *post, void *env);
233
234 /**
235  * Additionally walk over all anchors.
236  * This function visits all anchor nodes that otherwise might not been visited in a
237  * walk, for instance the Bad() node.
238  *
239  * @param irg   the irg graph
240  * @param pre   walker function, executed before the predecessor of a node are visited
241  * @param post  walker function, executed after the predecessor of a node are visited
242  * @param env   environment, passed to pre and post
243  */
244 FIRM_API void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre,
245                                irg_walk_func *post, void *env);
246
247 /**
248  * Walker function which does not increase the visited flag before walking.
249  * Do not use this unless you know what you are doing.
250  */
251 unsigned irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
252                     void *env);
253
254 #include "end.h"
255
256 #endif