3db617cfb4ddb6a7e4f45af41af6bdbfe8f85bb7
[libfirm] / ir / ir / irgwalk.h
1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 * All rights reserved.
3 *
4 * Author: Boris Boesler
5 *
6 * traverse an ir graph
7 * - execute the pre function before recursion
8 * - execute the post function after recursion
9 *
10 * Uses current_ir_graph (from irgraph.h)!!! Set it to the proper
11 * graph before starting the walker.
12 */
13
14 /* $Id$ */
15
16 # ifndef _IRGWALK_H_
17 # define _IRGWALK_H_
18
19 # include "irnode.h"
20
21 /* type of callback function for ir_graph walk */
22 #ifndef _IRG_WALK_FUNC_TYPEDEF_
23 #define _IRG_WALK_FUNC_TYPEDEF_
24 typedef void (irg_walk_func)(ir_node *, void *);
25 #endif
26
27 /* Allocates some necessary datastructures. */
28 void init_ip_walk(void);
29
30 /* Frees some necessary datastructures. */
31 void finish_ip_walk(void);
32
33 /* Walks over the ir graph, starting at the node given as first argument.
34    Executes pre before visiting the predecessor of a node, post after.
35    irg_walk uses the visited flag in irg and the nodes to determine visited
36    nodes.  It executes inc_irg_visited(current_ir_graph) to generate a new
37    flag.  It marks the node as visited before executing pre.
38    The void* env can be used to pass status information between the
39    pre and post functions.  */
40 void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
41
42 /* Like "irg_walk", but walks over all reachable nodes in the ir
43  * graph, starting at the end operation. During the walk current_ir_graph
44  * is set to irg. */
45 void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
46
47 /* Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
48    Sets current_ir_graph properly for each walk.  Conserves current
49    current_ir_graph.  In interprocedural view nodes can be visited several
50    times. */
51 void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
52
53 /* Walks all irgs in interprocedural view.  Visits each node only once.
54    Sets current_ir_graph properly. */
55 void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env);
56
57 /* Walks only over Block nodes in the graph.  Has it's own visited
58    flag, so that it can be interleaved with the other walker.
59    If a none block is passed, starts at the block this node belongs to.
60    If end is passed also visites kept alive blocks. */
61 void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env);
62
63 /* Like "irg_block_walk", but walks over all reachable blocks in the
64  * ir graph, starting at the end block. */
65 void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env);
66
67 /* Walks over all code in const_code_irg.
68    Uses visited flag in const_code_irg. */
69 void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env);
70
71
72 # endif /* _IRGWALK_H_ */