dec_irg_block_visited() added
[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
29
30 # ifndef _IRGWALK_H_
31 # define _IRGWALK_H_
32
33 # include "firm_types.h"
34
35 /* type of callback function for ir_graph walk */
36 #ifndef _IRG_WALK_FUNC_TYPEDEF_
37 #define _IRG_WALK_FUNC_TYPEDEF_
38 /**
39  * The type of a walk function.  Does not use the link field.
40  *
41  * @param node - the node that is just visited
42  * @param env  - an environment pointer passed by the walk functions
43  */
44 typedef void irg_walk_func(ir_node *node, void *env);
45 #endif
46
47 /**
48  * Walks over the ir graph.
49  *
50  * Walks over the ir graph, starting at the node given as first argument.
51  * Executes pre before visiting the predecessor of a node, post after.
52  * irg_walk uses the visited flag in irg and the nodes to determine visited
53  * nodes.  It executes inc_irg_visited(current_ir_graph) to generate a new
54  * flag.  Therefore current_ir_graph must be set before calling the walker.
55  * It marks the node as visited before executing pre.
56  * The void* env can be used to pass status information between the
57  * pre and post functions.  Does not use the link fields.
58  *
59  * @param node - the start node
60  * @param pre  - walker function, executed before the predecessor of a node are visited
61  * @param post - walker function, executed after the predecessor of a node are visited
62  * @param env  - environment, passed to pre and post
63  *
64  */
65 void irg_walk(ir_node *node, irg_walk_func *pre, 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.  If interprocedural_view
78  * is set, visits all reachable irgs.
79  */
80 void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
81
82 /**
83  * Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
84  *
85  * @param pre  - walker function, executed before the predecessor of a node are visited
86  * @param post - walker function, executed after the predecessor of a node are visited
87  * @param env  - environment, passed to pre and post
88  *
89  * This function executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
90  * Sets current_ir_graph properly for each walk.  Conserves current
91  * current_ir_graph.  In interprocedural view nodes can be visited several
92  * times.  Does not use the link field.
93  */
94 void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
95
96 /**
97  * Walks all irgs in interprocedural view.
98  *
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  * This function walks all irgs in interprocedural view.
104  * Visits each node only once.  Sets current_ir_graph properly. Does not use the link field.
105  */
106 void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
107
108 /** Walks only over Block nodes in the graph.
109  *
110  * @param node - the start node
111  * @param pre  - walker function, executed before the predecessor of a node are visited
112  * @param post - walker function, executed after the predecessor of a node are visited
113  * @param env  - environment, passed to pre and post
114  *
115  * This function Walks only over Block nodes in the graph. Has it's own visited
116  * flag, so that it can be interleaved with the other walker.
117  * If a none block is passed, starts at the block this node belongs to.
118  * If end is passed also visits kept alive blocks. Does not use the link field.
119  */
120 void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
121
122 /**
123  * Walks only over reachable Block nodes in the graph.
124  *
125  * @param irg  - the irg graph
126  * @param pre  - walker function, executed before the predecessor of a node are visited
127  * @param post - walker function, executed after the predecessor of a node are visited
128  * @param env  - environment, passed to pre and post
129  *
130  * Like irg_block_walk(), but walks over all reachable blocks in the
131  * ir graph, starting at the end block. Does not use the link field.
132  */
133 void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
134
135 /**
136  * Walks over all code in const_code_irg.
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 walks over all code in const_code_irg.
143  * Uses visited flag in const_code_irg.  Does not use the link field.
144  */
145 void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env);
146
147 /**
148  * Walks over reachable nodes in block-wise order, i.e. visit all nodes in a block
149  * before going to another block, starting at the end operation.
150  * Executes pre before visiting the predecessor of a node, post after.
151  * irg_walk_blkwise_graph() uses the visited flag in irg and the nodes to
152  * determine visited nodes.
153  * It executes inc_irg_visited(current_ir_graph) to generate a new
154  * flag. It marks the node as visited before executing pre.
155  * The void *env can be used to pass status information between the
156  * pre and post functions.  Does not use the link fields.
157  * Walks only intraprocedural, even in interprocedural view.
158  *
159  * @param irg  - the irg graph
160  * @param pre  - walker function, executed before the predecessor of a node are visited
161  * @param post - walker function, executed after the predecessor of a node are visited
162  * @param env  - environment, passed to pre and post
163  */
164 void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
165
166 # endif /* _IRGWALK_H_ */