Fix compiler warnings (including a serious bug)
[candl.git] / source / statement.c
blobd6845dddf6245b45de69568e49a7e4f9354b4f9f
3 /**------ ( ----------------------------------------------------------**
4 ** )\ CAnDL **
5 **----- / ) --------------------------------------------------------**
6 ** ( * ( usr.c **
7 **---- \#/ --------------------------------------------------------**
8 ** .-"#'-. First version: june 7th 2012 **
9 **--- |"-.-"| -------------------------------------------------------**
10 | |
11 | |
12 ******** | | *************************************************************
13 * CAnDL '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
14 ******************************************************************************
15 * *
16 * Copyright (C) 2003-2008 Cedric Bastoul *
17 * *
18 * This is free software; you can redistribute it and/or modify it under the *
19 * terms of the GNU General Public License as published by the Free Software *
20 * Foundation; either version 2 of the License, or (at your option) any later *
21 * version. *
22 * *
23 * This software is distributed in the hope that it will be useful, but *
24 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
25 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
26 * for more details. *
27 * *
28 * You should have received a copy of the GNU General Public License along *
29 * with software; if not, write to the Free Software Foundation, Inc., *
30 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
31 * *
32 * CAnDL, the Chunky Dependence Analyzer *
33 * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr *
34 * *
35 ******************************************************************************/
38 * author Joel Poudroux and Cedric Bastoul
41 #include <stdlib.h>
42 #include <osl/scop.h>
43 #include <osl/statement.h>
44 #include <osl/extensions/dependence.h>
45 #include <osl/relation.h>
46 #include <candl/macros.h>
47 #include <candl/statement.h>
48 #include <candl/util.h>
50 #define CANDL_STATEMENT_USR_INDEX_MAX_LOOP_DEPTH 128
53 /**
54 * candl_statement_usr_init_all function:
55 * Init each candl_statement_usr structure of statements
57 void candl_statement_usr_init_all(osl_scop_p scop) {
59 /* TODO
60 * that statements must be sorted to compute the statement label
61 * the problem is if the scop is reordered, the second transformed scop
62 * must be aligned with it
65 osl_statement_p iter;
66 osl_relation_p scattering;
67 candl_statement_usr_p stmt_usr;
68 int i, j, k;
69 int row;
70 int precision = scop->context->precision;
71 int count = 0; /* counter for statements */
73 /* Initialize structures used in iterator indices computation. */
74 int val;
75 int max = 0;
76 int cur_index[CANDL_STATEMENT_USR_INDEX_MAX_LOOP_DEPTH];
77 int last[CANDL_STATEMENT_USR_INDEX_MAX_LOOP_DEPTH];
78 for (i = 0; i < CANDL_STATEMENT_USR_INDEX_MAX_LOOP_DEPTH; ++i) {
79 cur_index[i] = i;
80 last[i] = 0;
83 /* Add useful information in the usr field of each statements */
84 for (iter = scop->statement ; iter != NULL ; iter = iter->next) {
85 scattering = iter->scattering;
87 stmt_usr = (candl_statement_usr_p) malloc(sizeof(candl_statement_usr_t));
88 stmt_usr->depth = scattering->nb_output_dims/2;
89 stmt_usr->label = count;
90 stmt_usr->type = OSL_DEPENDENCE_ASSIGNMENT;
91 stmt_usr->usr_backup = iter->usr;
92 stmt_usr->index = (stmt_usr->depth ?
93 (int*) malloc(stmt_usr->depth * sizeof(int)) :
94 NULL);
96 /* Compute the value of the iterator indices.
97 * extracted from the last candl
99 for (j = 0; j < stmt_usr->depth; ++j) {
100 row = candl_util_relation_get_line(scattering, j*2);
101 val = osl_int_get_si(precision,
102 scattering->m[row][scattering->nb_columns - 1]);
103 if (last[j] < val) {
104 last[j] = val;
105 for (k = j + 1; k < CANDL_STATEMENT_USR_INDEX_MAX_LOOP_DEPTH; ++k)
106 last[k] = 0;
107 for (k = j; k < CANDL_STATEMENT_USR_INDEX_MAX_LOOP_DEPTH; ++k)
108 cur_index[k] = max + (k - j) + 1;
109 break;
112 for (j = 0; j < stmt_usr->depth; ++j)
113 stmt_usr->index[j] = cur_index[j];
115 max = max < cur_index[j - 1] ? cur_index[j - 1] : max;
117 iter->usr = stmt_usr;
118 count++;
124 * candl_usr_free function:
126 void candl_statement_usr_cleanup(osl_statement_p statement) {
127 candl_statement_usr_p stmt_usr;
128 stmt_usr = statement->usr;
129 if (stmt_usr) {
130 if (stmt_usr->index)
131 free(stmt_usr->index);
132 statement->usr = stmt_usr->usr_backup;
133 free(stmt_usr);