2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Loop datastructure and access functions -- private stuff.
9 * @author Goetz Lindenmaier
21 void add_loop_son(ir_loop *loop, ir_loop *son)
24 assert(loop && loop->kind == k_ir_loop);
25 assert(get_kind(son) == k_ir_loop);
27 ARR_APP1(loop_element, loop->children, lson);
30 void add_loop_node(ir_loop *loop, ir_node *n)
34 assert(loop && loop->kind == k_ir_loop);
35 ARR_APP1(loop_element, loop->children, ln);
38 void add_loop_irg(ir_loop *loop, ir_graph *irg)
42 assert(loop && loop->kind == k_ir_loop);
43 ARR_APP1(loop_element, loop->children, ln);
46 void mature_loops(ir_loop *loop, struct obstack *obst)
50 loop_element *new_children = DUP_ARR_D(loop_element, obst, loop->children);
51 DEL_ARR_F(loop->children);
52 loop->children = new_children;
54 /* mature child loops */
55 for (i = ARR_LEN(new_children); i > 0;) {
56 loop_element child = new_children[--i];
58 if (*child.kind == k_ir_loop) {
59 mature_loops(child.son, obst);
64 ir_loop *(get_loop_outer_loop)(const ir_loop *loop)
66 return _get_loop_outer_loop(loop);
69 unsigned (get_loop_depth)(const ir_loop *loop)
71 return _get_loop_depth(loop);
74 size_t get_loop_n_elements(const ir_loop *loop)
76 assert(loop && loop->kind == k_ir_loop);
77 return(ARR_LEN(loop->children));
80 loop_element get_loop_element(const ir_loop *loop, size_t pos)
82 assert(loop && loop->kind == k_ir_loop && pos < ARR_LEN(loop->children));
83 return(loop -> children[pos]);
86 void set_irn_loop(ir_node *n, ir_loop *loop)
91 ir_loop *(get_irn_loop)(const ir_node *n)
93 return _get_irn_loop(n);
96 long get_loop_loop_nr(const ir_loop *loop)
98 assert(loop && loop->kind == k_ir_loop);
100 return loop->loop_nr;
106 void set_loop_link(ir_loop *loop, void *link)
108 assert(loop && loop->kind == k_ir_loop);
112 void *get_loop_link(const ir_loop *loop)
114 assert(loop && loop->kind == k_ir_loop);
118 int (is_ir_loop)(const void *thing)
120 return _is_ir_loop(thing);
123 void (set_irg_loop)(ir_graph *irg, ir_loop *loop)
125 _set_irg_loop(irg, loop);
128 ir_loop *(get_irg_loop)(const ir_graph *irg)
130 return _get_irg_loop(irg);
133 ir_loop *alloc_loop(ir_loop *father, struct obstack *obst)
137 son = OALLOCZ(obst, ir_loop);
138 son->kind = k_ir_loop;
139 son->children = NEW_ARR_F(loop_element, 0);
142 son->outer_loop = father;
143 add_loop_son(father, son);
144 son->depth = father->depth + 1;
145 } else { /* The root loop */
146 son->outer_loop = son;
151 son->loop_nr = get_irp_new_node_nr();