When checking PhiM's, ignore Bad predecessors
[libfirm] / ir / ir / irgwalk.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irgwalk.h
4  * Purpose:
5  * Author:      Boris Boesler
6  * Modified by: Goetz Lindenmaier
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1999-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13
14 /**
15  * @file irgwalk.h
16  *
17  * Traverse an ir graph.
18  *
19  * @author Boris Boesler
20  *
21  * Traverse an ir graph:
22  * - execute the pre function before recursion
23  * - execute the post function after recursion
24  *
25  * Uses current_ir_graph (from irgraph.h)!!! Set it to the proper
26  * graph before starting the walker.
27  */
28 #ifndef _FIRM_IR_IRGWALK_H_
29 #define _FIRM_IR_IRGWALK_H_
30
31 #include "firm_types.h"
32
33 /* type of callback function for ir_graph walk */
34 #ifndef _IRG_WALK_FUNC_TYPEDEF_
35 #define _IRG_WALK_FUNC_TYPEDEF_
36 /**
37  * The type of a walk function.  Does not use the link field.
38  *
39  * @param node - the node that is just visited
40  * @param env  - an environment pointer passed by the walk functions
41  */
42 typedef void irg_walk_func(ir_node *node, void *env);
43 #endif
44
45 /**
46  * Walks over the ir graph.
47  *
48  * Walks over the ir graph, starting at the node given as first argument.
49  * Executes pre before visiting the predecessor of a node, post after.
50  * irg_walk uses the visited flag in irg and the nodes to determine visited
51  * nodes.  It executes inc_irg_visited(current_ir_graph) to generate a new
52  * flag.  Therefore current_ir_graph must be set before calling the walker.
53  * It marks the node as visited before executing pre.
54  * The void* env can be used to pass status information between the
55  * pre and post functions.  Does not use the link fields.
56  *
57  * @param node - the start node
58  * @param pre  - walker function, executed before the predecessor of a node are visited
59  * @param post - walker function, executed after the predecessor of a node are visited
60  * @param env  - environment, passed to pre and post
61  *
62  */
63 void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
64
65 /**
66  * Walks over all reachable nodes in the ir graph.
67  *
68  * @param irg  - the irg graph
69  * @param pre  - walker function, executed before the predecessor of a node are visited
70  * @param post - walker function, executed after the predecessor of a node are visited
71  * @param env  - environment, passed to pre and post
72  *
73  * Like irg_walk(), but walks over all reachable nodes in the ir
74  * graph, starting at the end operation. During the walk current_ir_graph
75  * is set to irg.  Does not use the link field.  If interprocedural_view
76  * is set, visits all reachable irgs.
77  */
78 void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
79
80 /**
81  * Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
82  *
83  * @param pre  - walker function, executed before the predecessor of a node are visited
84  * @param post - walker function, executed after the predecessor of a node are visited
85  * @param env  - environment, passed to pre and post
86  *
87  * This function executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
88  * Sets current_ir_graph properly for each walk.  Conserves current
89  * current_ir_graph.  In interprocedural view nodes can be visited several
90  * times.  Does not use the link field.
91  */
92 void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
93
94 /**
95  * Walks all irgs in interprocedural view.
96  *
97  * @param pre  - walker function, executed before the predecessor of a node are visited
98  * @param post - walker function, executed after the predecessor of a node are visited
99  * @param env  - environment, passed to pre and post
100  *
101  * This function walks all irgs in interprocedural view.
102  * Visits each node only once.  Sets current_ir_graph properly. Does not use the link field.
103  */
104 void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
105
106 /** Walks only over Block nodes in the graph.
107  *
108  * @param node - the start node
109  * @param pre  - walker function, executed before the predecessor of a node are visited
110  * @param post - walker function, executed after the predecessor of a node are visited
111  * @param env  - environment, passed to pre and post
112  *
113  * This function Walks only over Block nodes in the graph. Has it's own visited
114  * flag, so that it can be interleaved with the other walker.
115  * If a none block is passed, starts at the block this node belongs to.
116  * If end is passed also visits kept alive blocks. Does not use the link field.
117  */
118 void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
119
120 /**
121  * Walks only over reachable Block nodes in the graph.
122  *
123  * @param irg  - the irg graph
124  * @param pre  - walker function, executed before the predecessor of a node are visited
125  * @param post - walker function, executed after the predecessor of a node are visited
126  * @param env  - environment, passed to pre and post
127  *
128  * Like irg_block_walk(), but walks over all reachable blocks in the
129  * ir graph, starting at the end block. Does not use the link field.
130  */
131 void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
132
133 /**
134  * Walks over all code in const_code_irg.
135  *
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 over all code in const_code_irg.
141  * Uses visited flag in const_code_irg.  Does not use the link field.
142  */
143 void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env);
144
145 /**
146  * Walks over reachable nodes in block-wise order, i.e. visit all nodes in a block
147  * before going to another block, starting at the end operation.
148  * Executes pre before visiting the predecessor of a node, post after.
149  * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
150  * determine visited nodes.
151  * It executes inc_irg_visited(current_ir_graph) to generate a new
152  * flag. It marks the node as visited before executing pre.
153  * The void *env can be used to pass status information between the
154  * pre and post functions.  Does not use the link fields.
155  * Walks only intraprocedural, even in interprocedural view.
156  *
157  * @param irg  - the irg graph
158  * @param pre  - walker function, executed before the predecessor of a node are visited
159  * @param post - walker function, executed after the predecessor of a node are visited
160  * @param env  - environment, passed to pre and post
161  */
162 void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
163
164 /**
165  * Additionally walk over all anchors. Do NOT increase the visit flag.
166  * This function visits all anchor nodes that otherwise might not been visited in a
167  * walk, for instance the Bad() node.
168  *
169  * @param irg  - the irg graph
170  * @param pre  - walker function, executed before the predecessor of a node are visited
171  * @param post - walker function, executed after the predecessor of a node are visited
172  * @param env  - environment, passed to pre and post
173  */
174 void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
175
176 #endif /* _FIRM_IR_IRGWALK_H_ */