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 is free software; you can redistribute it and/or modify it under the *
18 * terms of the GNU General Public License as published by the Free Software *
19 * Foundation; either version 2 of the License, or (at your option) any later *
22 * This software is distributed in the hope that it will be useful, but *
23 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
24 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
27 * You should have received a copy of the GNU General Public License along *
28 * with software; if not, write to the Free Software Foundation, Inc., *
29 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
31 * CLooG, the Chunky Loop Generator *
32 * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr *
34 ******************************************************************************/
35 /* CAUTION: the english used for comments is probably the worst you ever read,
36 * please feel free to correct and improve it !
42 # include "../include/cloog/cloog.h"
45 /******************************************************************************
46 * Memory leaks hunting *
47 ******************************************************************************/
51 * These functions and global variables are devoted to memory leaks hunting: we
52 * want to know at each moment how many CloogStatement structures had been
53 * allocated (cloog_statement_allocated) and how many had been freed
54 * (cloog_statement_freed). Each time a CloogStatement structure is allocated,
55 * a call to the function cloog_statement_leak_up() must be carried out, and
56 * respectively cloog_statement_leak_down() when a CloogStatement structure is
57 * freed. The special variable cloog_statement_max gives the maximal number of
58 * CloogStatement structures simultaneously alive (i.e. allocated and
59 * non-freed) in memory.
60 * - July 3rd->11th 2003: first version (memory leaks hunt and correction).
64 int cloog_statement_allocated
= 0 ;
65 int cloog_statement_freed
= 0 ;
66 int cloog_statement_max
= 0 ;
69 void cloog_statement_leak_up()
70 { cloog_statement_allocated
++ ;
71 if ((cloog_statement_allocated
-cloog_statement_freed
) > cloog_statement_max
)
72 cloog_statement_max
= cloog_statement_allocated
- cloog_statement_freed
;
76 void cloog_statement_leak_down()
77 { cloog_statement_freed
++ ;
81 /******************************************************************************
82 * Structure display function *
83 ******************************************************************************/
87 * cloog_domain_print_structure :
88 * this function is a human-friendly way to display the CloogDomain data
89 * structure, it includes an indentation level (level) in order to work with
90 * others print_structure functions.
91 * - June 16th 2005: first version.
93 void cloog_statement_print_structure(file
, statement
, level
)
95 CloogStatement
* statement
;
99 if (statement
!= NULL
)
100 { /* Go to the right level. */
101 for (i
=0; i
<level
; i
++)
102 fprintf(file
,"|\t") ;
103 fprintf(file
,"+-- CloogStatement %d \n",statement
->number
+1) ;
105 statement
= statement
->next
;
107 while (statement
!= NULL
)
108 { for (i
=0; i
<level
; i
++)
109 fprintf(file
,"|\t") ;
110 fprintf(file
,"| |\n");
111 for (i
=0; i
<level
; i
++)
112 fprintf(file
,"|\t") ;
113 fprintf(file
,"| V\n");
115 for (i
=0; i
<level
; i
++)
116 fprintf(file
,"|\t") ;
117 fprintf(file
,"| CloogStatement %d \n",statement
->number
+1) ;
118 statement
= statement
->next
;
122 { for (i
=0; i
<level
; i
++)
123 fprintf(file
,"|\t") ;
125 fprintf(file
,"+-- No CloogStatement\n") ;
131 * cloog_statement_print function:
132 * This function prints the content of a CloogStatement structure (statement)
133 * into a file (file, possibly stdout).
135 void cloog_statement_print(FILE * file
, CloogStatement
* statement
)
136 { cloog_statement_print_structure(file
,statement
,0) ;
140 /******************************************************************************
141 * Memory deallocation function *
142 ******************************************************************************/
146 * cloog_statement_free function:
147 * This function frees the allocated memory for a CloogStatement structure.
149 void cloog_statement_free(CloogStatement
* statement
)
150 { CloogStatement
* next
;
152 while (statement
!= NULL
)
153 { cloog_statement_leak_down() ;
155 next
= statement
->next
;
156 /* free(statement->usr) ; Actually, this is user's job ! */
163 /******************************************************************************
164 * Processing functions *
165 ******************************************************************************/
169 * cloog_statement_malloc function:
170 * This function allocates the memory space for a CloogStatement structure and
171 * sets its fields with default values. Then it returns a pointer to the
173 * - November 21th 2005: first version.
175 CloogStatement
* cloog_statement_malloc()
176 { CloogStatement
* statement
;
178 /* Memory allocation for the CloogStatement structure. */
179 statement
= (CloogStatement
*)malloc(sizeof(CloogStatement
)) ;
180 if (statement
== NULL
)
181 { fprintf(stderr
, "[CLooG]ERROR: memory overflow.\n") ;
184 cloog_statement_leak_up() ;
186 /* We set the various fields with default values. */
187 statement
->number
= -1 ;
188 statement
->usr
= NULL
; /* To fill it is actually user's job ! */
189 statement
->next
= NULL
;
196 * cloog_statement_alloc function:
197 * This function allocates the memory space for a CloogStatement structure and
198 * sets its fields with those given as input. Then it returns a pointer to the
200 * - number is the statement number.
202 * - September 9th 2002: first version.
203 * - March 17th 2003: fix for the usr field in CloogStatement structure.
204 * - April 16th 2005: adaptation to new CloogStatement structure (with
205 * number), cloog_statement_read becomes
206 * cloog_statement_alloc sincethere is nothing more to
208 * - November 21th 2005: use of cloog_statement_malloc.
210 CloogStatement
* cloog_statement_alloc(int number
)
211 { CloogStatement
* statement
;
213 /* Memory allocation and initialization of the structure. */
214 statement
= cloog_statement_malloc() ;
216 statement
->number
= number
;
223 * cloog_statement_copy function:
224 * This function returns a copy of the CloogStatement structure given as input.
225 * - October 28th 2001: first version (in loop.c).
226 * - March 17th 2003: fix for the usr field in CloogStatement structure.
227 * - April 16th 2005: adaptation to new CloogStatement struct (with number).
229 CloogStatement
* cloog_statement_copy(CloogStatement
* source
)
230 { CloogStatement
* statement
, * temp
, * now
= NULL
;
234 while (source
!= NULL
)
235 { cloog_statement_leak_up() ;
237 temp
= (CloogStatement
*)malloc(sizeof(CloogStatement
)) ;
239 { fprintf(stderr
, "Memory Overflow.\n") ;
243 temp
->number
= source
->number
;
244 temp
->usr
= source
->usr
;
247 if (statement
== NULL
)
255 source
= source
->next
;
262 * cloog_statement_add function:
263 * This function adds a CloogStatement structure (statement) at a given place
264 * (now) of a NULL terminated list of CloogStatement structures. The beginning
265 * of this list is (start). This function updates (now) to (loop), and
266 * updates (start) if the added element is the first one -that is when (start)
268 * - March 27th 2004: first version.
270 void cloog_statement_add(start
, now
, statement
)
271 CloogStatement
** start
, ** now
, * statement
;
272 { if (*start
== NULL
)
273 { *start
= statement
;
277 { (*now
)->next
= statement
;
278 *now
= (*now
)->next
;