2 * Copyright (C) 1995-2011 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 Loop datastructure and access functions -- private stuff.
23 * @author Goetz Lindenmaier
35 void add_loop_son(ir_loop *loop, ir_loop *son)
38 assert(loop && loop->kind == k_ir_loop);
39 assert(get_kind(son) == k_ir_loop);
41 ARR_APP1(loop_element, loop->children, lson);
42 loop->flags |= loop_outer_loop;
45 void add_loop_node(ir_loop *loop, ir_node *n)
49 assert(loop && loop->kind == k_ir_loop);
50 ARR_APP1(loop_element, loop->children, ln);
53 void add_loop_irg(ir_loop *loop, ir_graph *irg)
57 assert(loop && loop->kind == k_ir_loop);
58 ARR_APP1(loop_element, loop->children, ln);
62 * Mature all loops by removing the flexible arrays of a loop.
64 * @param loop the loop to mature
65 * @param obst an obstack, where the new arrays are allocated on
67 void mature_loops(ir_loop *loop, struct obstack *obst)
71 loop_element *new_children = DUP_ARR_D(loop_element, obst, loop->children);
72 DEL_ARR_F(loop->children);
73 loop->children = new_children;
75 /* mature child loops */
76 for (i = ARR_LEN(new_children); i > 0;) {
77 loop_element child = new_children[--i];
79 if (*child.kind == k_ir_loop) {
80 mature_loops(child.son, obst);
85 /* Returns outer loop, itself if outermost. */
86 ir_loop *(get_loop_outer_loop)(const ir_loop *loop)
88 return _get_loop_outer_loop(loop);
91 /* Returns nesting depth of this loop */
92 unsigned (get_loop_depth)(const ir_loop *loop)
94 return _get_loop_depth(loop);
97 /* Returns the number of elements contained in loop. */
98 size_t get_loop_n_elements(const ir_loop *loop)
100 assert(loop && loop->kind == k_ir_loop);
101 return(ARR_LEN(loop->children));
104 loop_element get_loop_element(const ir_loop *loop, size_t pos)
106 assert(loop && loop->kind == k_ir_loop && pos < ARR_LEN(loop->children));
107 return(loop -> children[pos]);
111 * Sets the loop for a node.
113 void set_irn_loop(ir_node *n, ir_loop *loop)
118 ir_loop *(get_irn_loop)(const ir_node *n)
120 return _get_irn_loop(n);
123 long get_loop_loop_nr(const ir_loop *loop)
125 assert(loop && loop->kind == k_ir_loop);
127 return loop->loop_nr;
133 void set_loop_link(ir_loop *loop, void *link)
135 assert(loop && loop->kind == k_ir_loop);
139 void *get_loop_link(const ir_loop *loop)
141 assert(loop && loop->kind == k_ir_loop);
145 int (is_ir_loop)(const void *thing)
147 return _is_ir_loop(thing);
150 /* The outermost loop is remarked in the surrounding graph. */
151 void (set_irg_loop)(ir_graph *irg, ir_loop *loop)
153 _set_irg_loop(irg, loop);
156 /* Returns the root loop info (if exists) for an irg. */
157 ir_loop *(get_irg_loop)(const ir_graph *irg)
159 return _get_irg_loop(irg);
163 * Allocates a new loop as son of father on the given obstack.
164 * If father is equal NULL, a new root loop is created.
166 ir_loop *alloc_loop(ir_loop *father, struct obstack *obst)
170 son = OALLOCZ(obst, ir_loop);
171 son->kind = k_ir_loop;
172 son->children = NEW_ARR_F(loop_element, 0);
175 son->outer_loop = father;
176 add_loop_son(father, son);
177 son->depth = father->depth + 1;
178 } else { /* The root loop */
179 son->outer_loop = son;
184 son->loop_nr = get_irp_new_node_nr();