bugfix, comments...
[libfirm] / ir / ir / irgwalk.h
1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 * All rights reserved.
3 */
4
5 /**
6  * @file irgwalk.h
7  *
8  * Traverse an ir graph.
9  *
10  * @author Boris Boesler
11  *
12  * Traverse an ir graph:
13  * - execute the pre function before recursion
14  * - execute the post function after recursion
15  *
16  * Uses current_ir_graph (from irgraph.h)!!! Set it to the proper
17  * graph before starting the walker.
18  */
19
20 /* $Id$ */
21
22 # ifndef _IRGWALK_H_
23 # define _IRGWALK_H_
24
25 # include "irnode.h"
26
27 /* type of callback function for ir_graph walk */
28 #ifndef _IRG_WALK_FUNC_TYPEDEF_
29 #define _IRG_WALK_FUNC_TYPEDEF_
30 /**
31  * The type of a walk function.  Does not use the link field.
32  *
33  * @param node - the node that is just visited
34  * @param env  - an environment pointer passed by the walk functions
35  */
36 typedef void irg_walk_func(ir_node *node, void *env);
37 #endif
38
39 /** Allocates some necessary datastructures. */
40 void init_ip_walk(void);
41
42 /** Frees some necessary datastructures. */
43 void finish_ip_walk(void);
44
45 /**
46  * Walks over the ir graph.
47  *
48  * @param node - the start node
49  * @param pre  - walker function, executed before the predecessor of a node are visited
50  * @param post - walker function, executed after the predecessor of a node are visited
51  * @param env  - environment, passend to pre and post
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.  It marks the node as visited before executing pre.
58  * The void* env can be used to pass status information between the
59  * pre and post functions.  Does not use the link field.
60  */
61 void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
62
63 /**
64  * Walks over all reachable nodes in the ir graph.
65  *
66  * @param irg  - the irg graph
67  * @param pre  - walker function, executed before the predecessor of a node are visited
68  * @param post - walker function, executed after the predecessor of a node are visited
69  * @param env  - environment, passend to pre and post
70  *
71  * Like irg_walk(), but walks over all reachable nodes in the ir
72  * graph, starting at the end operation. During the walk current_ir_graph
73  * is set to irg.  Does not use the link field.
74  */
75 void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
76
77 /**
78  * Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
79  *
80  * @param pre  - walker function, executed before the predecessor of a node are visited
81  * @param post - walker function, executed after the predecessor of a node are visited
82  * @param env  - environment, passend to pre and post
83  *
84  * This function executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
85  * Sets current_ir_graph properly for each walk.  Conserves current
86  * current_ir_graph.  In interprocedural view nodes can be visited several
87  * times.  Does not use the link field.
88  */
89 void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
90
91 /**
92  * Walks all irgs in interprocedural view.
93  *
94  * @param pre  - walker function, executed before the predecessor of a node are visited
95  * @param post - walker function, executed after the predecessor of a node are visited
96  * @param env  - environment, passend to pre and post
97  *
98  * This function walks all irgs in interprocedural view.
99  * Visits each node only once.  Sets current_ir_graph properly. Does not use the link field.
100  */
101 void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
102
103 /**
104  * Walks only over Block nodes in the graph.
105  *
106  * @param node - the start node
107  * @param pre  - walker function, executed before the predecessor of a node are visited
108  * @param post - walker function, executed after the predecessor of a node are visited
109  * @param env  - environment, passend to pre and post
110  *
111  * This function Walks only over Block nodes in the graph. Has it's own visited
112  * flag, so that it can be interleaved with the other walker.
113  * If a none block is passed, starts at the block this node belongs to.
114  * If end is passed also visites kept alive blocks. Does not use the link field.
115  */
116 void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
117
118 /**
119  * Walks only over reachable Block nodes in the graph.
120  *
121  * @param irg  - the irg graph
122  * @param pre  - walker function, executed before the predecessor of a node are visited
123  * @param post - walker function, executed after the predecessor of a node are visited
124  * @param env  - environment, passend to pre and post
125  *
126  * Like irg_block_walk(), but walks over all reachable blocks in the
127  * ir graph, starting at the end block. Does not use the link field.
128  */
129 void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
130
131 /**
132  * Walks over all code in const_code_irg.
133  *
134  * @param pre  - walker function, executed before the predecessor of a node are visited
135  * @param post - walker function, executed after the predecessor of a node are visited
136  * @param env  - environment, passend to pre and post
137  *
138  * This function walks over all code in const_code_irg.
139  * Uses visited flag in const_code_irg.  Does not use the link field.
140  */
141 void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env);
142
143 # endif /* _IRGWALK_H_ */