72f53d27e4a0dc5b3314388097d587c48eab4dd4
[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  * @summary
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
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 void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
57
58 /**
59  * Walks over all reachable nodes in the ir graph.
60  *
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
65  *
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.
70  */
71 void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
72
73 /**
74  * Walks over the ir graph.
75  *
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.
85  *
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
90  *
91  */
92 void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
93
94 /**
95  * Walks over all reachable nodes in the ir graph.
96  *
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
101  *
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.
107  */
108 void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
109
110 /**
111  * Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
112  *
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
116  *
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.
121  */
122 void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
123
124 #ifdef INTERPROCEDURAL_VIEW
125 /**
126  * Walks all irgs in interprocedural view.
127  *
128  * @param pre   walker function, executed before the predecessor of a node are visited
129  * @param post  walker function, executed after the predecessor of a node are visited
130  * @param env   environment, passed to pre and post
131  *
132  * This function walks all irgs in interprocedural view.
133  * Visits each node only once.  Sets current_ir_graph properly. Does not use the link field.
134  */
135 void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
136 #endif
137
138 /** Walks only over Block nodes in the graph.
139  *
140  * @param node  the start node
141  * @param pre   walker function, executed before the predecessor of a node are visited
142  * @param post  walker function, executed after the predecessor of a node are visited
143  * @param env   environment, passed to pre and post
144  *
145  * This function Walks only over Block nodes in the graph. Has it's own visited
146  * flag, so that it can be interleaved with the other walker.
147  * If a none block is passed, starts at the block this node belongs to.
148  * If end is passed also visits kept alive blocks. Does not use the link field.
149  */
150 void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
151
152 /**
153  * Walks only over reachable Block nodes in the graph.
154  *
155  * @param irg   the irg graph
156  * @param pre   walker function, executed before the predecessor of a node are visited
157  * @param post  walker function, executed after the predecessor of a node are visited
158  * @param env   environment, passed to pre and post
159  *
160  * Like irg_block_walk(), but walks over all reachable blocks in the
161  * ir graph, starting at the end block. Does not use the link field.
162  */
163 void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
164
165 /**
166  * Walks over all code in const_code_irg.
167  *
168  * @param pre   walker function, executed before the predecessor of a node are visited
169  * @param post  walker function, executed after the predecessor of a node are visited
170  * @param env   environment, passed to pre and post
171  *
172  * This function walks over all code in const_code_irg.
173  * Uses visited flag in const_code_irg.  Does not use the link field.
174  */
175 void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env);
176
177 /**
178  * Walks over reachable nodes in block-wise topological order, i.e. visit
179  * all nodes in a block before going to another block, starting at the end operation.
180  * Executes pre before visiting the predecessor of a node, post after.
181  * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
182  * determine visited nodes.
183  * It executes inc_irg_visited(current_ir_graph) to generate a new
184  * flag. It marks the node as visited before executing pre.
185  * The void *env can be used to pass status information between the
186  * pre and post functions.  Does not use the link fields.
187  * Walks only intraprocedural, even in interprocedural view.
188  *
189  * @param irg   the irg graph
190  * @param pre   walker function, executed before the predecessor of a node are visited
191  * @param post  walker function, executed after the predecessor of a node are visited
192  * @param env   environment, passed to pre and post
193  */
194 void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
195
196 /**
197  * Walks over reachable nodes in block-wise topological order, i.e. visit
198  * all nodes in a block before going to another block, starting at the end operation.
199  * Executes pre before visiting the predecessor of a node, post after.
200  * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
201  * determine visited nodes.
202  * It executes inc_irg_visited(current_ir_graph) to generate a new
203  * flag. It marks the node as visited before executing pre.
204  * The void *env can be used to pass status information between the
205  * pre and post functions.  Does not use the link fields.
206  * Walks only intraprocedural, even in interprocedural view.
207  * This walker also follows dependency edges.
208  *
209  * @param irg   the irg graph
210  * @param pre   walker function, executed before the predecessor of a node are visited
211  * @param post  walker function, executed after the predecessor of a node are visited
212  * @param env   environment, passed to pre and post
213  */
214 void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
215
216 /**
217  * Walks over reachable nodes in block-wise topological order, i.e. visit
218  * all nodes in a block before going to another block, starting at the end operation.
219  * Visit the blocks in dominator tree order.
220  * Executes pre before visiting the predecessor of a node, post after.
221  * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
222  * determine visited nodes.
223  * It executes inc_irg_visited(current_ir_graph) to generate a new
224  * flag. It marks the node as visited before executing pre.
225  * The void *env can be used to pass status information between the
226  * pre and post functions.  Does not use the link fields.
227  * Walks only intraprocedural, even in interprocedural view.
228  *
229  * @param irg   the irg graph
230  * @param pre   walker function, executed before the predecessor of a node are visited
231  * @param post  walker function, executed after the predecessor of a node are visited
232  * @param env   environment, passed to pre and post
233  */
234 void irg_walk_blkwise_dom_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
235
236 /**
237  * Additionally walk over all anchors. Do NOT increase the visit flag.
238  * This function visits all anchor nodes that otherwise might not been visited in a
239  * walk, for instance the Bad() node.
240  *
241  * @param irg   the irg graph
242  * @param pre   walker function, executed before the predecessor of a node are visited
243  * @param post  walker function, executed after the predecessor of a node are visited
244  * @param env   environment, passed to pre and post
245  */
246 void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
247
248 #endif