Updated header
[libfirm] / ir / ana / irextbb.h
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   Extended basis block support.
23  * @author  Michael Beck
24  * @date    5.2005
25  * @version $Id$
26  */
27 #ifndef FIRM_ANA_IREXTBB_H
28 #define FIRM_ANA_IREXTBB_H
29
30 #include "firm_types.h"
31 #include "execfreq.h"
32
33 #ifndef _IR_EXTBB_TYPEDEF_
34 #define _IR_EXTBB_TYPEDEF_
35 typedef struct _ir_extblk ir_extblk;
36 #endif
37
38 /** Flags for extended basic block state. */
39 typedef enum {
40   ir_extblk_info_none    = 0,  /**< No extended basic block information is constructed. Default. */
41   ir_extblk_info_valid   = 1,  /**< Extended basic block information is valid. */
42   ir_extblk_info_invalid = 2   /**< Extended basic block information is constructed but invalid. */
43 } irg_extblk_info_state;
44
45 /* type of callback function for ir_graph walk */
46 #ifndef _EXTBB_WALK_FUNC_TYPEDEF_
47 #define _EXTBB_WALK_FUNC_TYPEDEF_
48 /**
49  * The type of a walk function.  Does not use the link field.
50  *
51  * @param blk  - the extended basic block that is just visited
52  * @param env  - an environment pointer passed by the walk functions
53  */
54 typedef void extbb_walk_func(ir_extblk *blk, void *env);
55 #endif
56
57 /**
58  * Checks whether a pointer points to a extended basic block.
59  * Intern version for libFirm.
60  */
61 int is_ir_extbb(const void *thing);
62
63 /**
64  * Compute the extended basic blocks for a graph.
65  */
66 void compute_extbb(ir_graph *irg);
67
68 /**
69  * Compute the extended basic blocks for a graph based on execution frequencies.
70  */
71 void compute_extbb_execfreqs(ir_graph *irg, ir_exec_freq *execfreqs);
72
73 /**
74  * free all extended block info.
75  */
76 void free_extbb(ir_graph *irg);
77
78 /**
79  * Return the extended block of a node.
80  *
81  * @param node  the node
82  */
83 ir_extblk *get_nodes_extbb(ir_node *node);
84
85 /**
86  * Gets the visited counter of an extended block.
87  *
88  * @param blk  the extended basic block
89  */
90 unsigned long get_extbb_visited(const ir_extblk *blk);
91
92 /**
93  * Sets the visited counter of an extended block.
94  *
95  * @param blk  the extended basic block
96  */
97 void set_extbb_visited(ir_extblk *blk, unsigned long visited);
98
99 /**
100  * Mark an extended block as visited in a graph.
101  * Uses the block visit flag.
102  *
103  * @param blk  the extended basic block
104  */
105 void mark_extbb_visited(ir_extblk *blk);
106
107 /**
108  * Returns non-zero if an extended was visited.
109  * Uses the block visit flag.
110  *
111  * @param blk  the extended basic block
112  */
113 int extbb_visited(const ir_extblk *blk);
114
115 /**
116  * Returns non-zero if an extended block was NOT visited.
117  * Uses the block visit flag.
118  *
119  * @param blk  the extended basic block
120  */
121 int extbb_not_visited(const ir_extblk *blk);
122
123 /**
124  * Returns the link field of an extended block.
125  *
126  * @param blk  the extended basic block
127  */
128 void *get_extbb_link(const ir_extblk *blk);
129
130 /**
131  * Sets the link field of an extended block.
132  *
133  * @param blk  the extended basic block
134  * @param link the new link value
135  */
136 void set_extbb_link(ir_extblk *blk, void *link);
137
138 /**
139  * Return the number of basic blocks of an extended block.
140  *
141  * @param blk  the extended basic block
142  */
143 int get_extbb_n_blocks(const ir_extblk *blk);
144
145 /**
146  * Return the i'th basic block of an extended block.
147  *
148  * @param blk  the extended basic block
149  * @param pos  the position
150  */
151 ir_node *get_extbb_block(ir_extblk *blk, int pos);
152
153 /**
154  * Return the leader basic block of an extended block.
155  *
156  * @param blk  the extended basic block
157  */
158 ir_node *get_extbb_leader(ir_extblk *blk);
159
160 /**
161  * Return the node number of an extended block.
162  * Its the block number of the leader block
163  *
164  * @param blk  the extended basic block
165  */
166 long get_extbb_node_nr(ir_extblk *blk);
167
168 /**
169  * Walks only over Extended Basic Block nodes in the graph.
170  *
171  * @param blk  - the start extended block node
172  * @param pre  - walker function, executed before the predecessor of a node are visited
173  * @param post - walker function, executed after the predecessor of a node are visited
174  * @param env  - environment, passed to pre and post
175  *
176  * This function Walks only over Block nodes in the graph. Has it's own visited
177  * flag, so that it can be interleaved with the other walker.
178  * If a none block is passed, starts at the block this node belongs to.
179  * If end is passed also visits kept alive blocks. Does not use the link field.
180  */
181 void irg_extblock_walk(ir_extblk *blk, extbb_walk_func *pre, extbb_walk_func *post, void *env);
182
183 /**
184  * Walks only over reachable Extended Basic Block nodes in the graph.
185  * Ensures, that the extended block containing the End node is visited last
186  * and the block containing Start visited first (in post order).
187  *
188  * @param irg  - the irg graph
189  * @param pre  - walker function, executed before the predecessor of a block are visited
190  * @param post - walker function, executed after the predecessor of a block are visited
191  * @param env  - environment, passed to pre and post
192  */
193 void irg_extblock_walk_graph(ir_graph *irg, extbb_walk_func *pre, extbb_walk_func *post, void *env);
194
195 #endif