3 * File name: ir/ana/structure.h
4 * Purpose: structure analysis
9 * Copyright: (c) 2007 Universität Karlsruhe
10 * License: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
12 #ifndef _FIRM_STRUCTURE_H
13 #define _FIRM_STRUCTURE_H
15 #include "firm_types.h"
18 * This enum describes the different regions constructed by the structural analysis.
20 typedef enum ir_region_kind {
21 ir_rk_Unknown, /**< Unknown region kind. */
22 ir_rk_BasicBlock, /**< A Basic Block simply wraps a firm basic block, needed for the construction. */
24 * part0->part1->...->partn->XXX
26 ir_rk_Sequence, /**< A sequence of regions. */
34 ir_rk_IfThen, /**< An if-then. */
42 ir_rk_IfThenElse, /**< An if-then-else. */
50 ir_rk_Case, /**< A Case like in Pascal. No fall through is allowed. */
58 ir_rk_Switch, /**< A Switch like in C. At least one fall through exists. */
59 ir_rk_Proper, /**< A proper region. Any other DAG. */
60 ir_rk_TryCatch, /**< A TryCatch Exception handling. */
61 ir_rk_TryCatchFinally, /**< A TryCatchFinally Exception handling. */
67 ir_rk_SelfLoop, /**< A self loop. In Firm always a repeat or endless loop. */
77 ir_rk_RepeatLoop, /**< A Repeat loop. */
84 ir_rk_WhileLoop, /**< A While loop. */
86 * Arbitrary loop with single head.
88 ir_rk_NaturalLoop, /**< A natural loop. */
89 ir_rk_Improper, /**< An improper region. May contain everything. */
92 /** Returns non-zero if a region contains loops. */
93 #define is_loop_region(type) ((type) >= ir_rk_SelfLoop)
96 * Returns the link of a region.
98 * @param reg the region
100 void *get_region_link(const ir_region *reg);
103 * Sets the link of a region.
105 * @param reg the region
106 * @param data the data
108 void set_region_link(ir_region *reg, void *data);
111 * Get the immediate region of a block.
113 * @param block a block node
115 ir_region *get_block_region(const ir_node *block);
118 * Sets the immediate region of a block.
120 * @param block a block node
121 * @param reg the region
123 void set_block_region(ir_node *block, ir_region *reg);
126 * Get the immediate region of a node.
128 * @param n a Firm IR node
130 ir_region *get_irn_region(ir_node *n);
133 * Return non-if a given firm thing is a region.
135 * @param thing a Firm object address
137 int is_region(const void *thing);
140 * Return the number of predecessors in a region.
142 * @param reg the region
144 int get_region_n_preds(const ir_region *reg);
147 * Return the predecessor region at position pos.
149 * @param reg the region
151 ir_region *get_region_pred(const ir_region *reg, int pos);
154 * Set the predecessor region at position pos.
156 * @param reg the region
157 * @param pos the position number
158 * @param n the new predecessor region
160 void set_region_pred(ir_region *reg, int pos, ir_region *n);
163 * Return the number of successors in a region.
165 * @param reg the region
167 int get_region_n_succs(const ir_region *reg);
170 * Return the successor region at position pos.
172 * @param reg the region
173 * @param pos the position number
175 ir_region *get_region_succ(const ir_region *reg, int pos);
178 * Set the successor region at position pos.
180 * @param reg the region
181 * @param pos the position number
182 * @param n the new successor region
184 void set_region_succ(ir_region *reg, int pos, ir_region *n);
187 * Construct the region tree of a graph by doing
188 * structural analysis.
190 * Uses link fields of nodes.
192 * @param irg the graph
194 * @return the region tree
196 ir_reg_tree *construct_region_tree(ir_graph *irg);
199 * Walk over the region tree.
201 * @param tree the tree
202 * @param pre walker function, executed before the children of a tree node are visited
203 * @param post walker function, executed after the children of a tree node are visited
204 * @param env environment, passed to pre and post
206 void region_tree_walk(ir_reg_tree *tree, irg_reg_walk_func *pre, irg_reg_walk_func *post, void *env);
208 #endif /* _FIRM_STRUCTURE_H */