3 /**------ ( ----------------------------------------------------------**
5 **----- / ) --------------------------------------------------------**
7 **---- \#/ --------------------------------------------------------**
8 ** .-"#'-. First version: june 7th 2012 **
9 **--- |"-.-"| -------------------------------------------------------**
12 ******** | | *************************************************************
13 * CAnDL '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
14 ******************************************************************************
16 * Copyright (C) 2003-2008 Cedric Bastoul *
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 *
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 *
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 *
32 * CAnDL, the Chunky Dependence Analyzer *
33 * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr *
35 ******************************************************************************/
38 * author Joel Poudroux and Cedric Bastoul
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
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
) {
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
66 osl_relation_p scattering
;
67 candl_statement_usr_p stmt_usr
;
70 int precision
= scop
->context
->precision
;
71 int count
= 0; /* counter for statements */
73 /* Initialize structures used in iterator indices computation. */
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
) {
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)) :
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]);
105 for (k
= j
+ 1; k
< CANDL_STATEMENT_USR_INDEX_MAX_LOOP_DEPTH
; ++k
)
107 for (k
= j
; k
< CANDL_STATEMENT_USR_INDEX_MAX_LOOP_DEPTH
; ++k
)
108 cur_index
[k
] = max
+ (k
- j
) + 1;
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
;
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
;
131 free(stmt_usr
->index
);
132 statement
->usr
= stmt_usr
->usr_backup
;