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