becopyilp: Do not advertise the switch to dump the solution, because this is not...
[libfirm] / ir / ana / irloop.c
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief    Loop datastructure and access functions -- private stuff.
9  * @author   Goetz Lindenmaier
10  * @date     7.2002
11  */
12 #include "config.h"
13
14 #include <string.h>
15 #include <stdlib.h>
16
17 #include "irloop_t.h"
18 #include "irprog_t.h"
19 #include "error.h"
20
21 void add_loop_son(ir_loop *loop, ir_loop *son)
22 {
23         loop_element lson;
24         assert(loop && loop->kind == k_ir_loop);
25         assert(get_kind(son) == k_ir_loop);
26         lson.son = son;
27         ARR_APP1(loop_element, loop->children, lson);
28 }
29
30 void add_loop_node(ir_loop *loop, ir_node *n)
31 {
32         loop_element ln;
33         ln.node = n;
34         assert(loop && loop->kind == k_ir_loop);
35         ARR_APP1(loop_element, loop->children, ln);
36 }
37
38 void add_loop_irg(ir_loop *loop, ir_graph *irg)
39 {
40         loop_element ln;
41         ln.irg = irg;
42         assert(loop && loop->kind == k_ir_loop);
43         ARR_APP1(loop_element, loop->children, ln);
44 }
45
46 void mature_loops(ir_loop *loop, struct obstack *obst)
47 {
48         size_t i;
49
50         loop_element *new_children = DUP_ARR_D(loop_element, obst, loop->children);
51         DEL_ARR_F(loop->children);
52         loop->children = new_children;
53
54         /* mature child loops */
55         for (i = ARR_LEN(new_children); i > 0;) {
56                 loop_element child = new_children[--i];
57
58                 if (*child.kind == k_ir_loop) {
59                         mature_loops(child.son, obst);
60                 }
61         }
62 }
63
64 ir_loop *(get_loop_outer_loop)(const ir_loop *loop)
65 {
66         return _get_loop_outer_loop(loop);
67 }
68
69 unsigned (get_loop_depth)(const ir_loop *loop)
70 {
71         return _get_loop_depth(loop);
72 }
73
74 size_t get_loop_n_elements(const ir_loop *loop)
75 {
76         assert(loop && loop->kind == k_ir_loop);
77         return(ARR_LEN(loop->children));
78 }
79
80 loop_element get_loop_element(const ir_loop *loop, size_t pos)
81 {
82         assert(loop && loop->kind == k_ir_loop && pos < ARR_LEN(loop->children));
83         return(loop -> children[pos]);
84 }
85
86 void set_irn_loop(ir_node *n, ir_loop *loop)
87 {
88         n->loop = loop;
89 }
90
91 ir_loop *(get_irn_loop)(const ir_node *n)
92 {
93         return _get_irn_loop(n);
94 }
95
96 long get_loop_loop_nr(const ir_loop *loop)
97 {
98         assert(loop && loop->kind == k_ir_loop);
99 #ifdef DEBUG_libfirm
100         return loop->loop_nr;
101 #else
102         return (long)loop;
103 #endif
104 }
105
106 void set_loop_link(ir_loop *loop, void *link)
107 {
108         assert(loop && loop->kind == k_ir_loop);
109         loop->link = link;
110 }
111
112 void *get_loop_link(const ir_loop *loop)
113 {
114         assert(loop && loop->kind == k_ir_loop);
115         return loop->link;
116 }
117
118 int (is_ir_loop)(const void *thing)
119 {
120         return _is_ir_loop(thing);
121 }
122
123 void (set_irg_loop)(ir_graph *irg, ir_loop *loop)
124 {
125         _set_irg_loop(irg, loop);
126 }
127
128 ir_loop *(get_irg_loop)(const ir_graph *irg)
129 {
130         return _get_irg_loop(irg);
131 }
132
133 ir_loop *alloc_loop(ir_loop *father, struct obstack *obst)
134 {
135         ir_loop *son;
136
137         son = OALLOCZ(obst, ir_loop);
138         son->kind     = k_ir_loop;
139         son->children = NEW_ARR_F(loop_element, 0);
140         son->link     = NULL;
141         if (father) {
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;
147                 son->depth      = 0;
148         }
149
150 #ifdef DEBUG_libfirm
151         son->loop_nr = get_irp_new_node_nr();
152 #endif
153
154         return son;
155 }