3 * File name: ir/ir/irgwalk.h
5 * Author: Boris Boesler
6 * Modified by: Goetz Lindenmaier
9 * Copyright: (c) 1999-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
17 * Traverse an ir graph.
19 * @author Boris Boesler
21 * Traverse an ir graph:
22 * - execute the pre function before recursion
23 * - execute the post function after recursion
25 * Uses current_ir_graph (from irgraph.h)!!! Set it to the proper
26 * graph before starting the walker.
28 #ifndef _FIRM_IR_IRGWALK_H_
29 #define _FIRM_IR_IRGWALK_H_
31 #include "firm_types.h"
33 /* type of callback function for ir_graph walk */
34 #ifndef _IRG_WALK_FUNC_TYPEDEF_
35 #define _IRG_WALK_FUNC_TYPEDEF_
37 * The type of a walk function. Does not use the link field.
39 * @param node - the node that is just visited
40 * @param env - an environment pointer passed by the walk functions
42 typedef void irg_walk_func(ir_node *node, void *env);
46 * Walks over the ir graph.
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.
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
63 void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
66 * Walks over all reachable nodes in the ir graph.
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
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.
78 void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
81 * Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
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
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.
92 void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
95 * Walks all irgs in interprocedural view.
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
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.
104 void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
106 /** Walks only over Block nodes in the graph.
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
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.
118 void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
121 * Walks only over reachable Block nodes in the graph.
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
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.
131 void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
134 * Walks over all code in const_code_irg.
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
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.
143 void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env);
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.
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
162 void irg_walk_blkwise_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
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.
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
174 void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
176 #endif /* _FIRM_IR_IRGWALK_H_ */