2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief structure analysis
23 * @author Michael Beck
27 #ifndef FIRM_ANA_STRUCTURE_H
28 #define FIRM_ANA_STRUCTURE_H
30 #include "firm_types.h"
35 * This enum describes the different regions constructed by the structural analysis.
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. */
41 * part0->part1->...->partn->XXX
43 ir_rk_Sequence, /**< A sequence of regions. */
51 ir_rk_IfThen, /**< An if-then. */
59 ir_rk_IfThenElse, /**< An if-then-else. */
67 ir_rk_Case, /**< A Case like in Pascal. No fall through is allowed. */
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. */
84 ir_rk_SelfLoop, /**< A self loop. In Firm always a repeat or endless loop. */
94 ir_rk_RepeatLoop, /**< A Repeat loop. */
101 ir_rk_WhileLoop, /**< A While loop. */
103 * Arbitrary loop with single head.
105 ir_rk_NaturalLoop, /**< A natural loop. */
106 ir_rk_Improper, /**< An improper region. May contain everything. */
109 /** Returns non-zero if a region contains loops. */
110 #define is_loop_region(type) ((type) >= ir_rk_SelfLoop)
113 * Returns the link of a region.
115 * @param reg the region
117 FIRM_API void *get_region_link(const ir_region *reg);
120 * Sets the link of a region.
122 * @param reg the region
123 * @param data the data
125 FIRM_API void set_region_link(ir_region *reg, void *data);
128 * Get the immediate region of a block.
130 * @param block a block node
132 FIRM_API ir_region *get_block_region(const ir_node *block);
135 * Sets the immediate region of a block.
137 * @param block a block node
138 * @param reg the region
140 FIRM_API void set_block_region(ir_node *block, ir_region *reg);
143 * Get the immediate region of a node.
145 * @param n a Firm IR node
147 FIRM_API ir_region *get_irn_region(ir_node *n);
150 * Return non-if a given firm thing is a region.
152 * @param thing a Firm object address
154 FIRM_API int is_region(const void *thing);
157 * Return the number of predecessors in a region.
159 * @param reg the region
161 FIRM_API int get_region_n_preds(const ir_region *reg);
164 * Return the predecessor region at position pos.
166 * @param reg the region
167 * @param pos the position number
169 FIRM_API ir_region *get_region_pred(const ir_region *reg, int pos);
172 * Set the predecessor region at position pos.
174 * @param reg the region
175 * @param pos the position number
176 * @param n the new predecessor region
178 FIRM_API void set_region_pred(ir_region *reg, int pos, ir_region *n);
181 * Return the number of successors in a region.
183 * @param reg the region
185 FIRM_API int get_region_n_succs(const ir_region *reg);
188 * Return the successor region at position pos.
190 * @param reg the region
191 * @param pos the position number
193 FIRM_API ir_region *get_region_succ(const ir_region *reg, int pos);
196 * Set the successor region at position pos.
198 * @param reg the region
199 * @param pos the position number
200 * @param n the new successor region
202 FIRM_API void set_region_succ(ir_region *reg, int pos, ir_region *n);
205 * Construct the region tree of a graph by doing
206 * structural analysis.
208 * Uses link fields of nodes.
210 * @param irg the graph
212 * @return the region tree
214 FIRM_API ir_reg_tree *construct_region_tree(ir_graph *irg);
217 * Walk over the region tree.
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
224 FIRM_API void region_tree_walk(ir_reg_tree *tree, irg_reg_walk_func *pre,
225 irg_reg_walk_func *post, void *env);