2 /**-------------------------------------------------------------------**
4 **-------------------------------------------------------------------**
6 **-------------------------------------------------------------------**
7 ** First version: november 4th 2001 **
8 **-------------------------------------------------------------------**/
11 /******************************************************************************
12 * CLooG : the Chunky Loop Generator (experimental) *
13 ******************************************************************************
15 * Copyright (C) 2001-2005 Cedric Bastoul *
17 * This library is free software; you can redistribute it and/or *
18 * modify it under the terms of the GNU Lesser General Public *
19 * License as published by the Free Software Foundation; either *
20 * version 2.1 of the License, or (at your option) any later version. *
22 * This library is distributed in the hope that it will be useful, *
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
25 * Lesser General Public License for more details. *
27 * You should have received a copy of the GNU Lesser General Public *
28 * License along with this library; if not, write to the Free Software *
29 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
30 * Boston, MA 02110-1301 USA *
32 * CLooG, the Chunky Loop Generator *
33 * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr *
35 ******************************************************************************/
36 /* CAUTION: the english used for comments is probably the worst you ever read,
37 * please feel free to correct and improve it !
43 # include "../include/cloog/cloog.h"
46 /******************************************************************************
47 * Memory leaks hunting *
48 ******************************************************************************/
52 * These functions and global variables are devoted to memory leaks hunting: we
53 * want to know at each moment how many CloogStatement structures had been
54 * allocated (cloog_statement_allocated) and how many had been freed
55 * (cloog_statement_freed). Each time a CloogStatement structure is allocated,
56 * a call to the function cloog_statement_leak_up() must be carried out, and
57 * respectively cloog_statement_leak_down() when a CloogStatement structure is
58 * freed. The special variable cloog_statement_max gives the maximal number of
59 * CloogStatement structures simultaneously alive (i.e. allocated and
60 * non-freed) in memory.
61 * - July 3rd->11th 2003: first version (memory leaks hunt and correction).
65 int cloog_statement_allocated
= 0 ;
66 int cloog_statement_freed
= 0 ;
67 int cloog_statement_max
= 0 ;
70 static void cloog_statement_leak_up()
71 { cloog_statement_allocated
++ ;
72 if ((cloog_statement_allocated
-cloog_statement_freed
) > cloog_statement_max
)
73 cloog_statement_max
= cloog_statement_allocated
- cloog_statement_freed
;
77 static void cloog_statement_leak_down()
78 { cloog_statement_freed
++ ;
82 /******************************************************************************
83 * Structure display function *
84 ******************************************************************************/
88 * cloog_domain_print_structure :
89 * this function is a human-friendly way to display the CloogDomain data
90 * structure, it includes an indentation level (level) in order to work with
91 * others print_structure functions.
92 * - June 16th 2005: first version.
94 void cloog_statement_print_structure(file
, statement
, level
)
96 CloogStatement
* statement
;
100 if (statement
!= NULL
)
101 { /* Go to the right level. */
102 for (i
=0; i
<level
; i
++)
103 fprintf(file
,"|\t") ;
104 fprintf(file
,"+-- CloogStatement %d \n",statement
->number
) ;
106 statement
= statement
->next
;
108 while (statement
!= NULL
)
109 { for (i
=0; i
<level
; i
++)
110 fprintf(file
,"|\t") ;
111 fprintf(file
,"| |\n");
112 for (i
=0; i
<level
; i
++)
113 fprintf(file
,"|\t") ;
114 fprintf(file
,"| V\n");
116 for (i
=0; i
<level
; i
++)
117 fprintf(file
,"|\t") ;
118 fprintf(file
,"| CloogStatement %d \n",statement
->number
) ;
119 statement
= statement
->next
;
123 { for (i
=0; i
<level
; i
++)
124 fprintf(file
,"|\t") ;
126 fprintf(file
,"+-- No CloogStatement\n") ;
132 * cloog_statement_print function:
133 * This function prints the content of a CloogStatement structure (statement)
134 * into a file (file, possibly stdout).
136 void cloog_statement_print(FILE * file
, CloogStatement
* statement
)
137 { cloog_statement_print_structure(file
,statement
,0) ;
141 /******************************************************************************
142 * Memory deallocation function *
143 ******************************************************************************/
147 * cloog_statement_free function:
148 * This function frees the allocated memory for a CloogStatement structure.
150 void cloog_statement_free(CloogStatement
* statement
)
151 { CloogStatement
* next
;
153 while (statement
!= NULL
)
154 { cloog_statement_leak_down() ;
156 next
= statement
->next
;
157 /* free(statement->usr) ; Actually, this is user's job ! */
164 /******************************************************************************
165 * Processing functions *
166 ******************************************************************************/
170 * cloog_statement_malloc function:
171 * This function allocates the memory space for a CloogStatement structure and
172 * sets its fields with default values. Then it returns a pointer to the
174 * - November 21th 2005: first version.
176 CloogStatement
* cloog_statement_malloc()
177 { CloogStatement
* statement
;
179 /* Memory allocation for the CloogStatement structure. */
180 statement
= (CloogStatement
*)malloc(sizeof(CloogStatement
)) ;
181 if (statement
== NULL
)
182 cloog_die("memory overflow.\n");
183 cloog_statement_leak_up() ;
185 /* We set the various fields with default values. */
186 statement
->number
= 0;
187 statement
->usr
= NULL
; /* To fill it is actually user's job ! */
188 statement
->next
= NULL
;
195 * cloog_statement_alloc function:
196 * This function allocates the memory space for a CloogStatement structure and
197 * sets its fields with those given as input. Then it returns a pointer to the
199 * - number is the statement number.
201 * - September 9th 2002: first version.
202 * - March 17th 2003: fix for the usr field in CloogStatement structure.
203 * - April 16th 2005: adaptation to new CloogStatement structure (with
204 * number), cloog_statement_read becomes
205 * cloog_statement_alloc sincethere is nothing more to
207 * - November 21th 2005: use of cloog_statement_malloc.
209 CloogStatement
* cloog_statement_alloc(int number
)
210 { CloogStatement
* statement
;
212 /* Memory allocation and initialization of the structure. */
213 statement
= cloog_statement_malloc() ;
215 statement
->number
= number
;
222 * cloog_statement_copy function:
223 * This function returns a copy of the CloogStatement structure given as input.
224 * - October 28th 2001: first version (in loop.c).
225 * - March 17th 2003: fix for the usr field in CloogStatement structure.
226 * - April 16th 2005: adaptation to new CloogStatement struct (with number).
228 CloogStatement
* cloog_statement_copy(CloogStatement
* source
)
229 { CloogStatement
* statement
, * temp
, * now
= NULL
;
233 while (source
!= NULL
)
234 { cloog_statement_leak_up() ;
236 temp
= (CloogStatement
*)malloc(sizeof(CloogStatement
)) ;
238 cloog_die("memory overflow.\n");
240 temp
->number
= source
->number
;
241 temp
->usr
= source
->usr
;
244 if (statement
== NULL
)
252 source
= source
->next
;
259 * cloog_statement_add function:
260 * This function adds a CloogStatement structure (statement) at a given place
261 * (now) of a NULL terminated list of CloogStatement structures. The beginning
262 * of this list is (start). This function updates (now) to (loop), and
263 * updates (start) if the added element is the first one -that is when (start)
265 * - March 27th 2004: first version.
267 void cloog_statement_add(start
, now
, statement
)
268 CloogStatement
** start
, ** now
, * statement
;
269 { if (*start
== NULL
)
270 { *start
= statement
;
274 { (*now
)->next
= statement
;
275 *now
= (*now
)->next
;