2 /*--------------------------------------------------------------------+
4 |--------------------------------------------------------------------|
6 |--------------------------------------------------------------------|
7 | First version: 03/04/2012 |
8 +--------------------------------------------------------------------+
10 +--------------------------------------------------------------------------+
11 | / __)( ) /__\ ( \/ ) |
12 | ( (__ )(__ /(__)\ \ / Chunky Loop Alteration wizardrY |
13 | \___)(____)(__)(__)(__) |
14 +--------------------------------------------------------------------------+
15 | Copyright (C) 2012 University of Paris-Sud |
17 | This library is free software; you can redistribute it and/or modify it |
18 | under the terms of the GNU Lesser General Public License as published by |
19 | the Free Software Foundation; either version 2.1 of the License, or |
20 | (at your option) any later version. |
22 | This library is distributed in the hope that it will be useful but |
23 | WITHOUT ANY WARRANTY; without even the implied warranty of |
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
25 | General Public License for more details. |
27 | You should have received a copy of the GNU Lesser General Public License |
28 | along with this software; if not, write to the Free Software Foundation, |
29 | Inc., 51 Franklin Street, Fifth Floor, |
30 | Boston, MA 02110-1301 USA |
32 | Clay, the Chunky Loop Alteration wizardrY |
33 | Written by Joel Poudroux, joel.poudroux@u-psud.fr |
34 +--------------------------------------------------------------------------*/
41 #include <osl/extensions/arrays.h>
43 #include <clay/macros.h>
44 #include <clay/array.h>
45 #include <clay/beta.h>
46 #include <clay/betatree.h>
47 #include <clay/util.h>
48 #include <clay/ident.h>
52 * clay_ident_find_stmt function:
53 * Search the corresponding beta of the `ident'th statement
55 * \param[in] ident >= 0
58 clay_array_p
clay_ident_find_stmt(osl_scop_p scop
, int ident
) {
65 clay_array_p beta_last
;
68 beta_last
= clay_array_malloc(); // empty beta
69 beta
= clay_beta_next(scop
->statement
, beta_last
, &sout
);
72 clay_array_free(beta_last
);
74 beta
= clay_beta_next(scop
->statement
, beta_last
, &sout
);
77 clay_array_free(beta_last
);
84 clay_array_free(beta_last
);
91 * clay_ident_find_iterator function:
92 * Search the first loop which has the `iter' in original iterator
94 * \param[in] iter name of the original iterator we want to search
97 clay_array_p
clay_ident_find_iterator(osl_scop_p scop
, char *iter
) {
101 clay_array_p beta_last
;
104 beta_last
= clay_array_malloc(); // empty beta
105 beta
= clay_beta_next(scop
->statement
, beta_last
, &sout
);
108 clay_array_free(beta_last
);
112 while ((i
= clay_util_statement_find_iterator(sout
, iter
)) == -1) {
113 clay_array_free(beta_last
);
115 beta
= clay_beta_next(scop
->statement
, beta_last
, &sout
);
118 clay_array_free(beta_last
);
123 clay_array_free(beta_last
);
126 clay_array_free(beta
);
136 * clay_ident_find_loop function:
137 * Search the `ident'th loop
138 * /!\ Assume that all nodes are sorted in ascending order
140 * \param[in] ident >= 1
143 clay_array_p
clay_ident_find_loop(clay_betatree_p tree
, int ident
) {
147 CLAY_malloc(count
, int*, sizeof(int));
150 beta
= clay_ident_find_loop_aux(tree
, ident
, count
);
158 * clay_ident_find_loop_aux function:
159 * Required by clay_ident_find_loop
161 clay_array_p
clay_ident_find_loop_aux(clay_betatree_p tree
, int ident
,
164 if (tree
->nbnodes
== 0 || ident
< 0)
167 if (*count
> ident
) {
173 clay_betatree_p node
;
175 clay_array_p beta_rest
;
177 beta
= clay_array_malloc();
179 // if we are not at the root (the root has no value)
181 clay_array_add(beta
, tree
->value
);
183 // OK the beta is found
189 // TODO : we need to sort the nodes before
190 // No problems for now because when we create a tree from a scop, the nodes
191 // are sorted by ascending order
192 for (i
= 0 ; i
< tree
->nbnodes
; i
++) {
193 node
= tree
->nodes
[i
];
195 // get the rest of the branch
196 // if not null, we have found the `ident'th loop
197 beta_rest
= clay_ident_find_loop_aux(node
, ident
, count
);
199 if (beta_rest
!= NULL
) {
200 clay_array_concat(beta
, beta_rest
);
201 clay_array_free(beta_rest
);
205 clay_array_free(beta_rest
);
208 clay_array_free(beta
);