properly mark symbols in the public API to be exported. This allows us to use -fvisib...
[libfirm] / include / libfirm / structure.h
1 /*
2  * Copyright (C) 1995-2008 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    structure analysis
23  * @author   Michael Beck
24  * @date     05.04.2007
25  * @version  $Id$
26  */
27 #ifndef FIRM_ANA_STRUCTURE_H
28 #define FIRM_ANA_STRUCTURE_H
29
30 #include "firm_types.h"
31
32 #include "begin.h"
33
34 /**
35  * This enum describes the different regions constructed by the structural analysis.
36  */
37 typedef enum ir_region_kind {
38         ir_rk_Unknown,         /**< Unknown region kind. */
39         ir_rk_BasicBlock,      /**< A Basic Block simply wraps a firm basic block, needed for the construction. */
40         /*
41          * part0->part1->...->partn->XXX
42          */
43         ir_rk_Sequence,        /**< A sequence of regions. */
44         /*
45          *    part0
46          *    /  |
47          * part1 |
48          *    \  |
49          *     XXX
50          */
51         ir_rk_IfThen,          /**< An if-then. */
52         /*
53          *     part0
54          *     /   \
55          * part1   part2
56          *     \   /
57          *      XXX
58          */
59         ir_rk_IfThenElse,      /**< An if-then-else. */
60         /*
61          *      part0
62          *     /    \
63          * part1 ... partn
64          *     \    /
65          *      XXX
66          */
67         ir_rk_Case,            /**< A Case like in Pascal. No fall through is allowed. */
68         /*
69          *        part0
70          *     /    |    \
71          * part1->part2 partn
72          *     \         /
73          *         XXX
74          */
75         ir_rk_Switch,          /**< A Switch like in C. At least one fall through exists. */
76         ir_rk_Proper,          /**< A proper region. Any other DAG. */
77         ir_rk_TryCatch,        /**< A TryCatch Exception handling. */
78         ir_rk_TryCatchFinally, /**< A TryCatchFinally Exception handling. */
79         /*
80          *  +-+
81          *  v |
82          * part0
83          */
84         ir_rk_SelfLoop,        /**< A self loop. In Firm always a repeat or endless loop. */
85         /*
86          * part0
87          *  | ^
88          *  v |
89          * part1
90          *  |
91          *  v
92          * XXX
93          */
94         ir_rk_RepeatLoop,      /**< A Repeat loop. */
95         /*
96          * part0 ---> XXX
97          *  | ^
98          *  v |
99          * part1
100          */
101         ir_rk_WhileLoop,       /**< A While loop. */
102         /*
103          * Arbitrary loop with single head.
104          */
105         ir_rk_NaturalLoop,     /**< A natural loop. */
106         ir_rk_Improper,        /**< An improper region. May contain everything. */
107 } ir_region_kind;
108
109 /** Returns non-zero if a region contains loops. */
110 #define is_loop_region(type) ((type) >= ir_rk_SelfLoop)
111
112 /**
113  * Returns the link of a region.
114  *
115  * @param reg  the region
116  */
117 FIRM_DLL void *get_region_link(const ir_region *reg);
118
119 /**
120  * Sets the link of a region.
121  *
122  * @param reg   the region
123  * @param data  the data
124  */
125 FIRM_DLL void set_region_link(ir_region *reg, void *data);
126
127 /**
128  * Get the immediate region of a block.
129  *
130  * @param block  a block node
131  */
132 FIRM_DLL ir_region *get_block_region(const ir_node *block);
133
134 /**
135  * Sets the immediate region of a block.
136  *
137  * @param block  a block node
138  * @param reg    the region
139  */
140 FIRM_DLL void set_block_region(ir_node *block, ir_region *reg);
141
142 /**
143  * Get the immediate region of a node.
144  *
145  * @param n  a Firm IR node
146  */
147 FIRM_DLL ir_region *get_irn_region(ir_node *n);
148
149 /**
150  * Return non-if a given firm thing is a region.
151  *
152  * @param thing  a Firm object address
153  */
154 FIRM_DLL int is_region(const void *thing);
155
156 /**
157  * Return the number of predecessors in a region.
158  *
159  * @param reg  the region
160  */
161 FIRM_DLL int get_region_n_preds(const ir_region *reg);
162
163 /**
164  * Return the predecessor region at position pos.
165  *
166  * @param reg  the region
167  * @param pos  the position number
168  */
169 FIRM_DLL ir_region *get_region_pred(const ir_region *reg, int pos);
170
171 /**
172  * Set the predecessor region at position pos.
173  *
174  * @param reg  the region
175  * @param pos  the position number
176  * @param n    the new predecessor region
177  */
178 FIRM_DLL void set_region_pred(ir_region *reg, int pos, ir_region *n);
179
180 /**
181  * Return the number of successors in a region.
182  *
183  * @param reg  the region
184  */
185 FIRM_DLL int get_region_n_succs(const ir_region *reg);
186
187 /**
188  * Return the successor region at position pos.
189  *
190  * @param reg  the region
191  * @param pos  the position number
192  */
193 FIRM_DLL ir_region *get_region_succ(const ir_region *reg, int pos);
194
195 /**
196  * Set the successor region at position pos.
197  *
198  * @param reg  the region
199  * @param pos  the position number
200  * @param n    the new successor region
201  */
202 FIRM_DLL void set_region_succ(ir_region *reg, int pos, ir_region *n);
203
204 /**
205  * Construct the region tree of a graph by doing
206  * structural analysis.
207  *
208  * Uses link fields of nodes.
209  *
210  * @param irg  the graph
211  *
212  * @return the region tree
213  */
214 FIRM_DLL ir_reg_tree *construct_region_tree(ir_graph *irg);
215
216 /**
217  * Walk over the region tree.
218  *
219  * @param tree  the tree
220  * @param pre   walker function, executed before the children of a tree node are visited
221  * @param post  walker function, executed after the children of a tree node are visited
222  * @param env   environment, passed to pre and post
223  */
224 FIRM_DLL void region_tree_walk(ir_reg_tree *tree, irg_reg_walk_func *pre,
225                                irg_reg_walk_func *post, void *env);
226
227 #include "end.h"
228
229 #endif