2 /**-------------------------------------------------------------------**
4 **-------------------------------------------------------------------**
6 **-------------------------------------------------------------------**
7 ** First version: april 19th 2003 **
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 ******************************************************************************/
42 # include "../include/cloog/cloog.h"
49 /******************************************************************************
50 * Error reporting functions *
51 ******************************************************************************/
53 void cloog_vmsg(CloogOptions
*options
, enum cloog_msg_type type
,
54 const char *msg
, va_list ap
)
58 if (options
&& options
->quiet
&&
59 (type
== CLOOG_WARNING
|| type
== CLOOG_INFO
))
74 fprintf(stderr
, "[CLooG] %s: ", type_msg
);
75 vfprintf(stderr
, msg
, ap
);
79 * Print message to stderr.
80 * @param msg printf format string
82 void cloog_msg(CloogOptions
*options
, enum cloog_msg_type type
,
88 cloog_vmsg(options
, type
, msg
, args
);
93 * Print error message to stderr and exit.
94 * @param msg printf format string
96 void cloog_die(const char *msg
, ...)
101 cloog_vmsg(NULL
, CLOOG_ERROR
, msg
, args
);
106 /******************************************************************************
107 * Structure display function *
108 ******************************************************************************/
112 * cloog_option_print function:
113 * This function prints the content of a CloogOptions structure (program) into
114 * a file (foo, possibly stdout).
115 * - April 19th 2003: first version.
117 void cloog_options_print(FILE * foo
, CloogOptions
* options
)
118 { fprintf(foo
,"Options:\n") ;
119 fprintf(foo
,"OPTIONS FOR LOOP GENERATION\n") ;
120 fprintf(foo
,"l = %3d,\n",options
->l
) ;
121 fprintf(foo
,"f = %3d,\n",options
->f
) ;
122 fprintf(foo
,"stop = %3d,\n",options
->stop
) ;
123 fprintf(foo
,"strides = %3d,\n",options
->strides
) ;
124 fprintf(foo
,"sh = %3d,\n",options
->sh
);
125 fprintf(foo
,"OPTIONS FOR PRETTY PRINTING\n") ;
126 fprintf(foo
,"esp = %3d,\n",options
->esp
) ;
127 fprintf(foo
,"fsp = %3d,\n",options
->fsp
) ;
128 fprintf(foo
,"otl = %3d.\n",options
->otl
) ;
129 fprintf(foo
,"block = %3d.\n",options
->block
) ;
130 fprintf(foo
,"compilable = %3d.\n",options
->compilable
) ;
131 fprintf(foo
,"callable = %3d.\n",options
->callable
) ;
132 fprintf(foo
,"MISC OPTIONS\n") ;
133 fprintf(foo
,"name = %3s.\n", options
->name
);
134 fprintf(foo
,"openscop = %3d.\n", options
->openscop
);
135 if (options
->scop
!= NULL
)
136 fprintf(foo
,"scop = (present but not printed).\n");
138 fprintf(foo
,"scop = NULL.\n");
139 fprintf(foo
,"UNDOCUMENTED OPTIONS FOR THE AUTHOR ONLY\n") ;
140 fprintf(foo
,"leaks = %3d.\n",options
->leaks
) ;
141 fprintf(foo
,"backtrack = %3d.\n",options
->backtrack
);
142 fprintf(foo
,"override = %3d.\n",options
->override
) ;
143 fprintf(foo
,"structure = %3d.\n",options
->structure
) ;
144 fprintf(foo
,"noscalars = %3d.\n",options
->noscalars
) ;
145 fprintf(foo
,"noblocks = %3d.\n",options
->noblocks
) ;
146 fprintf(foo
,"nosimplify = %3d.\n",options
->nosimplify
) ;
150 /******************************************************************************
151 * Memory deallocation function *
152 ******************************************************************************/
156 * cloog_options_free function:
157 * This function frees the allocated memory for a CloogOptions structure.
158 * - April 19th 2003: first version.
160 void cloog_options_free(CloogOptions
*options
)
163 if (options
->scop
!= NULL
) {
164 osl_scop_free(options
->scop
);
171 /******************************************************************************
172 * Processing functions *
173 ******************************************************************************/
177 * cloog_options_help function:
178 * This function displays the quick help when the user set the option -help
179 * while calling cloog. Prints are cutted to respect the 509 characters
180 * limitation of the ISO C 89 compilers.
181 * - August 5th 2002: first version.
183 void cloog_options_help()
185 "Usage: cloog [ options | file ] ...\n"
186 "Options for code generation:\n"
187 " -l <depth> Last loop depth to optimize (-1: infinity)\n"
188 " (default setting: -1).\n"
189 " -f <depth> First loop depth to start loop separation (-1: "
190 "infinity)\n (default setting: 1).\n") ;
192 " -stop <depth> Loop depth to stop code generation (-1: infinity)"
193 "\n (default setting: -1).\n"
194 " -strides <boolean> Handle non-unit strides (1) or not (0)\n"
195 " (default setting: 0).\n"
196 " -first-unroll <depth> First loop dimension to unroll (-1: no unrolling)\n");
198 "\nOptions for pretty printing:\n"
199 " -otl <boolean> Simplify loops running one time (1) or not (0)\n"
200 " (default setting: 1).\n") ;
202 " -esp <boolean> Allow complex equalities spreading (1) or not (0)\n"
203 " (default setting: 0).\n");
205 " -fsp <level> First level to begin the spreading\n"
206 " (default setting: 1).\n"
207 " -block <boolean> Make a new statement block per iterator in C\n"
208 " programs (1) or not (0) (default setting: 0).\n") ;
210 " -compilable <number> Compilable code by using preprocessor (not 0) or"
211 "\n not (0), number being the value of the parameters"
212 "\n (default setting: 0).\n"
213 " -callable <boolean> Testable code by using preprocessor (not 0) or"
214 "\n not (0) (default setting: 0).\n");
216 "\nGeneral options:\n"
217 " -o <output> Name of the output file; 'stdout' is a special\n"
218 " value: when used, output is standard output\n"
219 " (default setting: stdout).\n"
221 " -openscop Input file has OpenScop format.\n"
223 " -v, --version Display the version information (and more).\n"
224 " -q, --quiet Don't print any informational messages.\n"
225 " -h, --help Display this information.\n\n") ;
227 "The special value 'stdin' for 'file' makes CLooG to read data on\n"
228 "standard input.\n\n"
229 "For bug reporting or any suggestions, please send an email to the author\n"
230 "<cedric.bastoul@inria.fr>.\n") ;
235 * cloog_options_version function:
236 * This function displays some version informations when the user set the
237 * option -version while calling cloog. Prints are cutted to respect the 509
238 * characters limitation of the ISO C 89 compilers.
239 * - August 5th 2002: first version.
241 void cloog_options_version()
242 { printf("%s The Chunky Loop Generator\n", cloog_version());
245 "This is a loop generator for scanning Z-polyhedra. It is based on the "
246 "work of\nF. Quillere and C. Bastoul on high level code generation and of "
247 "the PolyLib Team\non polyhedral computation. This program is distributed "
248 "under the terms of the\nGNU Lesser General Public License "
249 "(details at http://www.gnu.org/licenses/lgpl-2.1.html).\n"
252 "It would be fair to refer the following paper in any publication "
253 "resulting from\nthe use of this software or its library:\n"
254 "@InProceedings{Bas04,\n"
255 "author = {Cedric Bastoul},\n"
256 "title = {Code Generation in the Polyhedral Model Is Easier Than You "
258 "booktitle = {PACT'13 IEEE International Conference on Parallel "
259 "Architecture\n and Compilation Techniques},\n"
261 "month = {september},\n"
263 "address = {Juan-les-Pins}\n"
266 "For any information, please ask the author at "
267 "<cedric.bastoul@inria.fr>.\n") ;
272 * cloog_options_set function:
273 * This function sets the value of an option thanks to the user's calling line.
274 * - option is the value to set,
275 * - argc are the elements of the user's calling line,
276 * - number is the number of the element corresponding to the considered option,
277 * this function adds 1 to number to pass away the option value.
279 * - August 5th 2002: first version.
280 * - June 29th 2003: (debug) lack of argument now detected.
282 void cloog_options_set(int * option
, int argv
, char ** argc
, int * number
)
285 if (*number
+1 >= argv
)
286 cloog_die("an option lacks of argument.\n");
289 *option
= strtol(argc
[*number
+1],endptr
,10) ;
291 cloog_die("value '%s' for option '%s' is not valid.\n",
292 argc
[*number
+1], argc
[*number
]);
293 *number
= *number
+ 1 ;
298 * cloog_options_malloc function:
299 * This functions allocate the memory space for a CLoogOptions structure and
300 * fill its fields with the defaults values. It returns a pointer to the
301 * allocated CloogOptions structure.
302 * - April 19th 2003: first version.
303 * - November 21th 2005: name changed (before it was cloog_options_init).
305 CloogOptions
*cloog_options_malloc(CloogState
*state
)
306 { CloogOptions
* options
;
308 /* Memory allocation for the CloogOptions structure. */
309 options
= (CloogOptions
*)malloc(sizeof(CloogOptions
)) ;
311 cloog_die("memory overflow.\n");
313 options
->state
= state
;
315 /* We set the various fields with default values. */
316 /* OPTIONS FOR LOOP GENERATION */
317 options
->l
= -1 ; /* Last level to optimize: infinity. */
318 options
->f
= 1 ; /* First level to optimize: the first. */
319 options
->stop
= -1 ; /* Generate all the code. */
320 options
->strides
= 0 ; /* Generate a code with unit strides. */
321 options
->sh
= 0; /* Compute actual convex hull. */
322 options
->first_unroll
= -1; /* First level to unroll: none. */
324 /* OPTIONS FOR PRETTY PRINTING */
325 options
->esp
= 1 ; /* We want Equality SPreading.*/
326 options
->fsp
= 1 ; /* The First level to SPread is the first. */
327 options
->otl
= 1 ; /* We want to fire One Time Loops. */
328 options
->block
= 0 ; /* We don't want to force statement blocks. */
329 options
->compilable
= 0 ; /* No compilable code. */
330 options
->callable
= 0 ; /* No callable code. */
331 options
->quiet
= 0; /* Do print informational messages. */
332 options
->save_domains
= 0; /* Don't save domains. */
334 options
->language
= CLOOG_LANGUAGE_C
; /* The default output language is C. */
335 options
->openscop
= 0 ; /* The input file has not the OpenScop format.*/
336 options
->scop
= NULL
;/* No default SCoP.*/
337 /* UNDOCUMENTED OPTIONS FOR THE AUTHOR ONLY */
338 options
->leaks
= 0 ; /* I don't want to print allocation statistics.*/
339 options
->backtrack
= 0; /* Perform backtrack in Quillere's algorithm.*/
340 options
->override
= 0 ; /* I don't want to override CLooG decisions.*/
341 options
->structure
= 0 ; /* I don't want to print internal structure.*/
342 options
->noblocks
= 0 ; /* I do want to make statement blocks.*/
343 options
->noscalars
= 0 ; /* I do want to use scalar dimensions.*/
344 options
->nosimplify
= 0 ; /* I do want to simplify polyhedra.*/
352 * cloog_options_read function:
353 * This functions reads all the options and the input/output files thanks
354 * the the user's calling line elements (in argc). It fills a CloogOptions
355 * structure and the FILE structure corresponding to input and output files.
356 * - August 5th 2002: first version.
357 * - April 19th 2003: now in options.c and support of the CloogOptions structure.
359 void cloog_options_read(CloogState
*state
, int argc
, char **argv
,
360 FILE **input
, FILE **output
, CloogOptions
**options
)
361 { int i
, infos
=0, input_is_set
=0 ;
363 /* CloogOptions structure allocation and initialization. */
364 *options
= cloog_options_malloc(state
);
366 /* The default output is the standard output. */
370 if (argv
[i
][0] == '-')
371 { if (strcmp(argv
[i
],"-l") == 0)
372 cloog_options_set(&(*options
)->l
,argc
,argv
,&i
) ;
374 if (strcmp(argv
[i
],"-f") == 0)
375 cloog_options_set(&(*options
)->f
,argc
,argv
,&i
) ;
377 if (strcmp(argv
[i
],"-stop") == 0)
378 cloog_options_set(&(*options
)->stop
,argc
,argv
,&i
) ;
380 if (strcmp(argv
[i
],"-strides") == 0)
381 cloog_options_set(&(*options
)->strides
,argc
,argv
,&i
) ;
382 else if (strcmp(argv
[i
],"-sh") == 0)
383 cloog_options_set(&(*options
)->sh
,argc
,argv
,&i
) ;
384 else if (!strcmp(argv
[i
], "-first-unroll"))
385 cloog_options_set(&(*options
)->first_unroll
, argc
, argv
, &i
);
387 if (strcmp(argv
[i
],"-otl") == 0)
388 cloog_options_set(&(*options
)->otl
,argc
,argv
,&i
) ;
390 if (strcmp(argv
[i
],"-openscop") == 0) {
392 (*options
)->openscop
= 1 ;
394 cloog_die("CLooG has not been compiled with OpenScop support.\n");
398 if (strcmp(argv
[i
],"-esp") == 0)
399 cloog_options_set(&(*options
)->esp
,argc
,argv
,&i
) ;
401 if (strcmp(argv
[i
],"-fsp") == 0)
402 cloog_options_set(&(*options
)->fsp
,argc
,argv
,&i
) ;
404 if (strcmp(argv
[i
],"-block") == 0)
405 cloog_options_set(&(*options
)->block
,argc
,argv
,&i
) ;
407 if (strcmp(argv
[i
],"-compilable") == 0)
408 cloog_options_set(&(*options
)->compilable
, argc
, argv
, &i
);
409 else if (strcmp(argv
[i
], "-callable") == 0)
410 cloog_options_set(&(*options
)->callable
, argc
, argv
, &i
);
412 if (strcmp(argv
[i
],"-loopo") == 0) /* Special option for the LooPo team ! */
413 { (*options
)->esp
= 0 ;
414 (*options
)->block
= 1 ;
417 if (strcmp(argv
[i
],"-bipbip") == 0)/* Special option for the author only !*/
418 (*options
)->backtrack
= 0;
420 if (strcmp(argv
[i
],"-leaks") == 0)
421 (*options
)->leaks
= 1 ;
423 if (strcmp(argv
[i
],"-nobacktrack") == 0)
424 (*options
)->backtrack
= 0;
425 else if (strcmp(argv
[i
], "-backtrack") == 0)
426 (*options
)->backtrack
= 1;
428 if (strcmp(argv
[i
],"-override") == 0)
429 (*options
)->override
= 1 ;
431 if (strcmp(argv
[i
],"-noblocks") == 0)
432 (*options
)->noblocks
= 1 ;
434 if (strcmp(argv
[i
],"-noscalars") == 0)
435 (*options
)->noscalars
= 1 ;
437 if (strcmp(argv
[i
],"-nosimplify") == 0)
438 (*options
)->nosimplify
= 1 ;
440 if ((strcmp(argv
[i
],"-struct") == 0) || (strcmp(argv
[i
],"-structure") == 0))
441 (*options
)->structure
= 1 ;
443 if ((strcmp(argv
[i
],"--help") == 0) || (strcmp(argv
[i
],"-h") == 0))
444 { cloog_options_help() ;
448 if ((strcmp(argv
[i
],"--version") == 0) || (strcmp(argv
[i
],"-v") == 0))
449 { cloog_options_version() ;
451 } else if ((strcmp(argv
[i
],"--quiet") == 0) || (strcmp(argv
[i
],"-q") == 0))
452 (*options
)->quiet
= 1;
454 if (strcmp(argv
[i
],"-o") == 0)
456 cloog_die("no output name for -o option.\n");
458 /* stdout is a special value, when used, we set output to standard
461 if (strcmp(argv
[i
+1],"stdout") == 0)
464 { *output
= fopen(argv
[i
+1],"w") ;
466 cloog_die("can't create output file %s.\n", argv
[i
+1]);
471 cloog_msg(*options
, CLOOG_WARNING
, "unknown %s option.\n", argv
[i
]);
476 (*options
)->name
= argv
[i
] ;
477 /* stdin is a special value, when used, we set input to standard input. */
478 if (strcmp(argv
[i
],"stdin") == 0)
481 { *input
= fopen(argv
[i
],"r") ;
483 cloog_die("%s file does not exist.\n", argv
[i
]);
487 cloog_die("multiple input files.\n");
491 cloog_die("no input file (-h for help).\n");
498 * This function extracts CLooG option values from an OpenScop scop and
499 * updates an existing CloogOption structure with those values. If the
500 * options were already set, they are updated without warning.
501 * \param[in] scop Input Scop.
502 * \param[in,out] options CLooG options to be updated.
504 void cloog_options_copy_from_osl_scop(osl_scop_p scop
,
505 CloogOptions
*options
) {
507 cloog_die("Options must be provided.\n");
510 /* Extract the language. */
511 if (!strcmp(scop
->language
, "FORTRAN"))
512 options
->language
= CLOOG_LANGUAGE_FORTRAN
;
514 options
->language
= CLOOG_LANGUAGE_C
;
516 /* Store the input SCoP in the option structure. */
517 options
->scop
= scop
;