added new licence header
[libfirm] / ir / ir / irgwalk.h
1 /*
2  * Copyright (C) 1995-2007 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  * Project:     libFIRM
22  * File name:   ir/ir/irgwalk.h
23  * Purpose:
24  * Author:      Boris Boesler
25  * Modified by: Goetz Lindenmaier
26  * Created:
27  * CVS-ID:      $Id$
28  * Copyright:   (c) 1999-2003 Universität Karlsruhe
29  */
30
31
32 /**
33  * @file irgwalk.h
34  *
35  * Traverse an ir graph.
36  *
37  * @author Boris Boesler
38  *
39  * Traverse an ir graph:
40  * - execute the pre function before recursion
41  * - execute the post function after recursion
42  *
43  * Uses current_ir_graph (from irgraph.h)!!! Set it to the proper
44  * graph before starting the walker.
45  */
46 #ifndef _FIRM_IR_IRGWALK_H_
47 #define _FIRM_IR_IRGWALK_H_
48
49 #include "firm_types.h"
50
51 /* type of callback function for ir_graph walk */
52 #ifndef _IRG_WALK_FUNC_TYPEDEF_
53 #define _IRG_WALK_FUNC_TYPEDEF_
54 /**
55  * The type of a walk function.  Does not use the link field.
56  *
57  * @param node - the node that is just visited
58  * @param env  - an environment pointer passed by the walk functions
59  */
60 typedef void irg_walk_func(ir_node *node, void *env);
61 #endif
62
63 /**
64  * Walks over the ir graph.
65  *
66  * Walks over the ir graph, starting at the node given as first argument.
67  * Executes pre before visiting the predecessor of a node, post after.
68  * irg_walk uses the visited flag in irg and the nodes to determine visited
69  * nodes.  It executes inc_irg_visited(current_ir_graph) to generate a new
70  * flag.  Therefore current_ir_graph must be set before calling the walker.
71  * It marks the node as visited before executing pre.
72  * The void* env can be used to pass status information between the
73  * pre and post functions.  Does not use the link fields.
74  *
75  * @param node - the start node
76  * @param pre  - walker function, executed before the predecessor of a node are visited
77  * @param post - walker function, executed after the predecessor of a node are visited
78  * @param env  - environment, passed to pre and post
79  *
80  */
81 void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
82
83 /**
84  * Walks over all reachable nodes in the ir graph.
85  *
86  * @param irg  - the irg graph
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
90  *
91  * Like irg_walk(), but walks over all reachable nodes in the ir
92  * graph, starting at the end operation. During the walk current_ir_graph
93  * is set to irg.  Does not use the link field.  If interprocedural_view
94  * is set, visits all reachable irgs.
95  */
96 void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
97
98 /**
99  * Walks over the ir graph.
100  *
101  * Walks over the ir graph, starting at the node given as first argument.
102  * Executes pre before visiting the predecessor of a node, post after.
103  * irg_walk uses the visited flag in irg and the nodes to determine visited
104  * nodes.  It executes inc_irg_visited(current_ir_graph) to generate a new
105  * flag.  Therefore current_ir_graph must be set before calling the walker.
106  * It marks the node as visited before executing pre.
107  * The void* env can be used to pass status information between the
108  * pre and post functions.  Does not use the link fields.
109  * This walker also follows additional dependency egdes.
110  *
111  * @param node - the start node
112  * @param pre  - walker function, executed before the predecessor of a node are visited
113  * @param post - walker function, executed after the predecessor of a node are visited
114  * @param env  - environment, passed to pre and post
115  *
116  */
117 void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
118
119 /**
120  * Walks over all reachable nodes in the ir graph.
121  *
122  * @param irg  - the irg graph
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  * Like irg_walk(), but walks over all reachable nodes in the ir
128  * graph, starting at the end operation. During the walk current_ir_graph
129  * is set to irg.  Does not use the link field.
130  * This walker also follows additional dependency egdes.
131  * interprocedural_view is not yet supported.
132  */
133 void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
134
135 /**
136  * Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
137  *
138  * @param pre  - walker function, executed before the predecessor of a node are visited
139  * @param post - walker function, executed after the predecessor of a node are visited
140  * @param env  - environment, passed to pre and post
141  *
142  * This function executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
143  * Sets current_ir_graph properly for each walk.  Conserves current
144  * current_ir_graph.  In interprocedural view nodes can be visited several
145  * times.  Does not use the link field.
146  */
147 void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
148
149 /**
150  * Walks all irgs in interprocedural view.
151  *
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  * This function walks all irgs in interprocedural view.
157  * Visits each node only once.  Sets current_ir_graph properly. Does not use the link field.
158  */
159 void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
160
161 /** Walks only over Block nodes in the graph.
162  *
163  * @param node - the start node
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 only over Block nodes in the graph. Has it's own visited
169  * flag, so that it can be interleaved with the other walker.
170  * If a none block is passed, starts at the block this node belongs to.
171  * If end is passed also visits kept alive blocks. Does not use the link field.
172  */
173 void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
174
175 /**
176  * Walks only over reachable Block nodes in the graph.
177  *
178  * @param irg  - the irg graph
179  * @param pre  - walker function, executed before the predecessor of a node are visited
180  * @param post - walker function, executed after the predecessor of a node are visited
181  * @param env  - environment, passed to pre and post
182  *
183  * Like irg_block_walk(), but walks over all reachable blocks in the
184  * ir graph, starting at the end block. Does not use the link field.
185  */
186 void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
187
188 /**
189  * Walks over all code in const_code_irg.
190  *
191  * @param pre  - walker function, executed before the predecessor of a node are visited
192  * @param post - walker function, executed after the predecessor of a node are visited
193  * @param env  - environment, passed to pre and post
194  *
195  * This function walks over all code in const_code_irg.
196  * Uses visited flag in const_code_irg.  Does not use the link field.
197  */
198 void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env);
199
200 /**
201  * Walks over reachable nodes in block-wise order, i.e. visit all nodes in a block
202  * before going to another block, starting at the end operation.
203  * Executes pre before visiting the predecessor of a node, post after.
204  * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
205  * determine visited nodes.
206  * It executes inc_irg_visited(current_ir_graph) to generate a new
207  * flag. It marks the node as visited before executing pre.
208  * The void *env can be used to pass status information between the
209  * pre and post functions.  Does not use the link fields.
210  * Walks only intraprocedural, even in interprocedural view.
211  *
212  * @param irg  - the irg graph
213  * @param pre  - walker function, executed before the predecessor of a node are visited
214  * @param post - walker function, executed after the predecessor of a node are visited
215  * @param env  - environment, passed to pre and post
216  */
217 void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
218
219 /**
220  * Walks over reachable nodes in block-wise order, i.e. visit all nodes in a block
221  * before going to another block, starting at the end operation.
222  * Executes pre before visiting the predecessor of a node, post after.
223  * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
224  * determine visited nodes.
225  * It executes inc_irg_visited(current_ir_graph) to generate a new
226  * flag. It marks the node as visited before executing pre.
227  * The void *env can be used to pass status information between the
228  * pre and post functions.  Does not use the link fields.
229  * Walks only intraprocedural, even in interprocedural view.
230  * This walker also follows dependency edges.
231  *
232  * @param irg  - the irg graph
233  * @param pre  - walker function, executed before the predecessor of a node are visited
234  * @param post - walker function, executed after the predecessor of a node are visited
235  * @param env  - environment, passed to pre and post
236  */
237 void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
238
239 /**
240  * Additionally walk over all anchors. Do NOT increase the visit flag.
241  * This function visits all anchor nodes that otherwise might not been visited in a
242  * walk, for instance the Bad() node.
243  *
244  * @param irg  - the irg graph
245  * @param pre  - walker function, executed before the predecessor of a node are visited
246  * @param post - walker function, executed after the predecessor of a node are visited
247  * @param env  - environment, passed to pre and post
248  */
249 void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
250
251 #endif /* _FIRM_IR_IRGWALK_H_ */