phase handling
[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 "irnode.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 /** Allocates some necessary datastructures. */
48 void init_ip_walk(void);
49
50 /** Frees some necessary datastructures. */
51 void finish_ip_walk(void);
52
53 /**
54  * Walks over the ir graph.
55  *
56  * Walks over the ir graph, starting at the node given as first argument.
57  * Executes pre before visiting the predecessor of a node, post after.
58  * irg_walk uses the visited flag in irg and the nodes to determine visited
59  * nodes.  It executes inc_irg_visited(current_ir_graph) to generate a new
60  * flag.  Therefore current_ir_graph must be set before calling the walker.
61  * It marks the node as visited before executing pre.
62  * The void* env can be used to pass status information between the
63  * pre and post functions.  Does not use the link field.
64  *
65  * @param node - the start node
66  * @param pre  - walker function, executed before the predecessor of a node are visited
67  * @param post - walker function, executed after the predecessor of a node are visited
68  * @param env  - environment, passend to pre and post
69  *
70  */
71 void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
72
73 /**
74  * Walks over all reachable nodes in the ir graph.
75  *
76  * @param irg  - the irg graph
77  * @param pre  - walker function, executed before the predecessor of a node are visited
78  * @param post - walker function, executed after the predecessor of a node are visited
79  * @param env  - environment, passend to pre and post
80  *
81  * Like irg_walk(), but walks over all reachable nodes in the ir
82  * graph, starting at the end operation. During the walk current_ir_graph
83  * is set to irg.  Does not use the link field.  If interprocedural_view
84  * is set, visits all reachable irgs.
85  */
86 void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
87
88 /**
89  * Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
90  *
91  * @param pre  - walker function, executed before the predecessor of a node are visited
92  * @param post - walker function, executed after the predecessor of a node are visited
93  * @param env  - environment, passend to pre and post
94  *
95  * This function executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
96  * Sets current_ir_graph properly for each walk.  Conserves current
97  * current_ir_graph.  In interprocedural view nodes can be visited several
98  * times.  Does not use the link field.
99  */
100 void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
101
102 /**
103  * Walks all irgs in interprocedural view.
104  *
105  * @param pre  - walker function, executed before the predecessor of a node are visited
106  * @param post - walker function, executed after the predecessor of a node are visited
107  * @param env  - environment, passend to pre and post
108  *
109  * This function walks all irgs in interprocedural view.
110  * Visits each node only once.  Sets current_ir_graph properly. Does not use the link field.
111  */
112 void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
113
114 /**
115  * Walks only over Block nodes in the graph.
116  *
117  * @param node - the start node
118  * @param pre  - walker function, executed before the predecessor of a node are visited
119  * @param post - walker function, executed after the predecessor of a node are visited
120  * @param env  - environment, passend to pre and post
121  *
122  * This function Walks only over Block nodes in the graph. Has it's own visited
123  * flag, so that it can be interleaved with the other walker.
124  * If a none block is passed, starts at the block this node belongs to.
125  * If end is passed also visites kept alive blocks. Does not use the link field.
126  */
127 void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
128
129 /**
130  * Walks only over reachable Block nodes in the graph.
131  *
132  * @param irg  - the irg graph
133  * @param pre  - walker function, executed before the predecessor of a node are visited
134  * @param post - walker function, executed after the predecessor of a node are visited
135  * @param env  - environment, passend to pre and post
136  *
137  * Like irg_block_walk(), but walks over all reachable blocks in the
138  * ir graph, starting at the end block. Does not use the link field.
139  */
140 void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
141
142 /**
143  * Walks over all code in const_code_irg.
144  *
145  * @param pre  - walker function, executed before the predecessor of a node are visited
146  * @param post - walker function, executed after the predecessor of a node are visited
147  * @param env  - environment, passend to pre and post
148  *
149  * This function walks over all code in const_code_irg.
150  * Uses visited flag in const_code_irg.  Does not use the link field.
151  */
152 void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env);
153
154 # endif /* _IRGWALK_H_ */