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"
33 * This enum describes the different regions constructed by the structural analysis.
35 typedef enum ir_region_kind {
36 ir_rk_Unknown, /**< Unknown region kind. */
37 ir_rk_BasicBlock, /**< A Basic Block simply wraps a firm basic block, needed for the construction. */
39 * part0->part1->...->partn->XXX
41 ir_rk_Sequence, /**< A sequence of regions. */
49 ir_rk_IfThen, /**< An if-then. */
57 ir_rk_IfThenElse, /**< An if-then-else. */
65 ir_rk_Case, /**< A Case like in Pascal. No fall through is allowed. */
73 ir_rk_Switch, /**< A Switch like in C. At least one fall through exists. */
74 ir_rk_Proper, /**< A proper region. Any other DAG. */
75 ir_rk_TryCatch, /**< A TryCatch Exception handling. */
76 ir_rk_TryCatchFinally, /**< A TryCatchFinally Exception handling. */
82 ir_rk_SelfLoop, /**< A self loop. In Firm always a repeat or endless loop. */
92 ir_rk_RepeatLoop, /**< A Repeat loop. */
99 ir_rk_WhileLoop, /**< A While loop. */
101 * Arbitrary loop with single head.
103 ir_rk_NaturalLoop, /**< A natural loop. */
104 ir_rk_Improper, /**< An improper region. May contain everything. */
107 /** Returns non-zero if a region contains loops. */
108 #define is_loop_region(type) ((type) >= ir_rk_SelfLoop)
111 * Returns the link of a region.
113 * @param reg the region
115 void *get_region_link(const ir_region *reg);
118 * Sets the link of a region.
120 * @param reg the region
121 * @param data the data
123 void set_region_link(ir_region *reg, void *data);
126 * Get the immediate region of a block.
128 * @param block a block node
130 ir_region *get_block_region(const ir_node *block);
133 * Sets the immediate region of a block.
135 * @param block a block node
136 * @param reg the region
138 void set_block_region(ir_node *block, ir_region *reg);
141 * Get the immediate region of a node.
143 * @param n a Firm IR node
145 ir_region *get_irn_region(ir_node *n);
148 * Return non-if a given firm thing is a region.
150 * @param thing a Firm object address
152 int is_region(const void *thing);
155 * Return the number of predecessors in a region.
157 * @param reg the region
159 int get_region_n_preds(const ir_region *reg);
162 * Return the predecessor region at position pos.
164 * @param reg the region
166 ir_region *get_region_pred(const ir_region *reg, int pos);
169 * Set the predecessor region at position pos.
171 * @param reg the region
172 * @param pos the position number
173 * @param n the new predecessor region
175 void set_region_pred(ir_region *reg, int pos, ir_region *n);
178 * Return the number of successors in a region.
180 * @param reg the region
182 int get_region_n_succs(const ir_region *reg);
185 * Return the successor region at position pos.
187 * @param reg the region
188 * @param pos the position number
190 ir_region *get_region_succ(const ir_region *reg, int pos);
193 * Set the successor region at position pos.
195 * @param reg the region
196 * @param pos the position number
197 * @param n the new successor region
199 void set_region_succ(ir_region *reg, int pos, ir_region *n);
202 * Construct the region tree of a graph by doing
203 * structural analysis.
205 * Uses link fields of nodes.
207 * @param irg the graph
209 * @return the region tree
211 ir_reg_tree *construct_region_tree(ir_graph *irg);
214 * Walk over the region tree.
216 * @param tree the tree
217 * @param pre walker function, executed before the children of a tree node are visited
218 * @param post walker function, executed after the children of a tree node are visited
219 * @param env environment, passed to pre and post
221 void region_tree_walk(ir_reg_tree *tree, irg_reg_walk_func *pre, irg_reg_walk_func *post, void *env);