Add is_Conv().
[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  * @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 /* type of callback function for ir_graph walk */
39 #ifndef _IRG_WALK_FUNC_TYPEDEF_
40 #define _IRG_WALK_FUNC_TYPEDEF_
41 /**
42  * The type of a walk function.  Does not use the link field.
43  *
44  * @param node - the node that is just visited
45  * @param env  - an environment pointer passed by the walk functions
46  */
47 typedef void irg_walk_func(ir_node *node, void *env);
48 #endif
49
50 /**
51  * Walks over the ir graph.
52  *
53  * Walks over the ir graph, starting at the node given as first argument.
54  * Executes pre before visiting the predecessor of a node, post after.
55  * irg_walk uses the visited flag in irg and the nodes to determine visited
56  * nodes.  It executes inc_irg_visited(current_ir_graph) to generate a new
57  * flag.  Therefore current_ir_graph must be set before calling the walker.
58  * It marks the node as visited before executing pre.
59  * The void* env can be used to pass status information between the
60  * pre and post functions.  Does not use the link fields.
61  *
62  * @param node - the start node
63  * @param pre  - walker function, executed before the predecessor of a node are visited
64  * @param post - walker function, executed after the predecessor of a node are visited
65  * @param env  - environment, passed to pre and post
66  *
67  */
68 void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
69
70 /**
71  * Walks over all reachable nodes in the ir graph.
72  *
73  * @param irg  - the irg graph
74  * @param pre  - walker function, executed before the predecessor of a node are visited
75  * @param post - walker function, executed after the predecessor of a node are visited
76  * @param env  - environment, passed to pre and post
77  *
78  * Like irg_walk(), but walks over all reachable nodes in the ir
79  * graph, starting at the end operation. During the walk current_ir_graph
80  * is set to irg.  Does not use the link field.  If interprocedural_view
81  * is set, visits all reachable irgs.
82  */
83 void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
84
85 /**
86  * Walks over the ir graph.
87  *
88  * Walks over the ir graph, starting at the node given as first argument.
89  * Executes pre before visiting the predecessor of a node, post after.
90  * irg_walk uses the visited flag in irg and the nodes to determine visited
91  * nodes.  It executes inc_irg_visited(current_ir_graph) to generate a new
92  * flag.  Therefore current_ir_graph must be set before calling the walker.
93  * It marks the node as visited before executing pre.
94  * The void* env can be used to pass status information between the
95  * pre and post functions.  Does not use the link fields.
96  * This walker also follows additional dependency egdes.
97  *
98  * @param node - the start node
99  * @param pre  - walker function, executed before the predecessor of a node are visited
100  * @param post - walker function, executed after the predecessor of a node are visited
101  * @param env  - environment, passed to pre and post
102  *
103  */
104 void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
105
106 /**
107  * Walks over all reachable nodes in the ir graph.
108  *
109  * @param irg  - the irg graph
110  * @param pre  - walker function, executed before the predecessor of a node are visited
111  * @param post - walker function, executed after the predecessor of a node are visited
112  * @param env  - environment, passed to pre and post
113  *
114  * Like irg_walk(), but walks over all reachable nodes in the ir
115  * graph, starting at the end operation. During the walk current_ir_graph
116  * is set to irg.  Does not use the link field.
117  * This walker also follows additional dependency egdes.
118  * interprocedural_view is not yet supported.
119  */
120 void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
121
122 /**
123  * Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
124  *
125  * @param pre  - walker function, executed before the predecessor of a node are visited
126  * @param post - walker function, executed after the predecessor of a node are visited
127  * @param env  - environment, passed to pre and post
128  *
129  * This function executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
130  * Sets current_ir_graph properly for each walk.  Conserves current
131  * current_ir_graph.  In interprocedural view nodes can be visited several
132  * times.  Does not use the link field.
133  */
134 void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
135
136 /**
137  * Walks all irgs in interprocedural view.
138  *
139  * @param pre  - walker function, executed before the predecessor of a node are visited
140  * @param post - walker function, executed after the predecessor of a node are visited
141  * @param env  - environment, passed to pre and post
142  *
143  * This function walks all irgs in interprocedural view.
144  * Visits each node only once.  Sets current_ir_graph properly. Does not use the link field.
145  */
146 void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
147
148 /** Walks only over Block nodes in the graph.
149  *
150  * @param node - the start node
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  * This function Walks only over Block nodes in the graph. Has it's own visited
156  * flag, so that it can be interleaved with the other walker.
157  * If a none block is passed, starts at the block this node belongs to.
158  * If end is passed also visits kept alive blocks. Does not use the link field.
159  */
160 void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
161
162 /**
163  * Walks only over reachable Block nodes in the graph.
164  *
165  * @param irg  - the irg graph
166  * @param pre  - walker function, executed before the predecessor of a node are visited
167  * @param post - walker function, executed after the predecessor of a node are visited
168  * @param env  - environment, passed to pre and post
169  *
170  * Like irg_block_walk(), but walks over all reachable blocks in the
171  * ir graph, starting at the end block. Does not use the link field.
172  */
173 void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
174
175 /**
176  * Walks over all code in const_code_irg.
177  *
178  * @param pre  - walker function, executed before the predecessor of a node are visited
179  * @param post - walker function, executed after the predecessor of a node are visited
180  * @param env  - environment, passed to pre and post
181  *
182  * This function walks over all code in const_code_irg.
183  * Uses visited flag in const_code_irg.  Does not use the link field.
184  */
185 void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env);
186
187 /**
188  * Walks over reachable nodes in block-wise order, i.e. visit all nodes in a block
189  * before going to another block, starting at the end operation.
190  * Executes pre before visiting the predecessor of a node, post after.
191  * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
192  * determine visited nodes.
193  * It executes inc_irg_visited(current_ir_graph) to generate a new
194  * flag. It marks the node as visited before executing pre.
195  * The void *env can be used to pass status information between the
196  * pre and post functions.  Does not use the link fields.
197  * Walks only intraprocedural, even in interprocedural view.
198  *
199  * @param irg  - the irg graph
200  * @param pre  - walker function, executed before the predecessor of a node are visited
201  * @param post - walker function, executed after the predecessor of a node are visited
202  * @param env  - environment, passed to pre and post
203  */
204 void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
205
206 /**
207  * Walks over reachable nodes in block-wise order, i.e. visit all nodes in a block
208  * before going to another block, starting at the end operation.
209  * Executes pre before visiting the predecessor of a node, post after.
210  * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
211  * determine visited nodes.
212  * It executes inc_irg_visited(current_ir_graph) to generate a new
213  * flag. It marks the node as visited before executing pre.
214  * The void *env can be used to pass status information between the
215  * pre and post functions.  Does not use the link fields.
216  * Walks only intraprocedural, even in interprocedural view.
217  * This walker also follows dependency edges.
218  *
219  * @param irg  - the irg graph
220  * @param pre  - walker function, executed before the predecessor of a node are visited
221  * @param post - walker function, executed after the predecessor of a node are visited
222  * @param env  - environment, passed to pre and post
223  */
224 void irg_walk_in_or_dep_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
225
226 /**
227  * Additionally walk over all anchors. Do NOT increase the visit flag.
228  * This function visits all anchor nodes that otherwise might not been visited in a
229  * walk, for instance the Bad() node.
230  *
231  * @param irg  - the irg graph
232  * @param pre  - walker function, executed before the predecessor of a node are visited
233  * @param post - walker function, executed after the predecessor of a node are visited
234  * @param env  - environment, passed to pre and post
235  */
236 void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
237
238 #endif