First commit : 0.14.0 version (with roadmap in doc instead of
[cloog.git] / source / options.c
blobd53dbcc71aaa0ae70cac850028123fd7a165804a
2 /**-------------------------------------------------------------------**
3 ** CLooG **
4 **-------------------------------------------------------------------**
5 ** options.c **
6 **-------------------------------------------------------------------**
7 ** First version: april 19th 2003 **
8 **-------------------------------------------------------------------**/
11 /******************************************************************************
12 * CLooG : the Chunky Loop Generator (experimental) *
13 ******************************************************************************
14 * *
15 * Copyright (C) 2001-2005 Cedric Bastoul *
16 * *
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 *
20 * version. *
21 * *
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 *
25 * for more details. *
26 * *
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 *
30 * *
31 * CLooG, the Chunky Loop Generator *
32 * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr *
33 * *
34 ******************************************************************************/
37 # include <stdlib.h>
38 # include <stdio.h>
39 # include <string.h>
40 # include "../include/cloog/cloog.h"
42 /**
43 * Maximum number of rays in the dual representation of PolyLib, see
44 * domain.c for the original declaration.
46 extern int MAX_RAYS ;
49 /******************************************************************************
50 * Structure display function *
51 ******************************************************************************/
54 /**
55 * cloog_option_print function:
56 * This function prints the content of a CloogOptions structure (program) into
57 * a file (foo, possibly stdout).
58 * - April 19th 2003: first version.
60 void cloog_options_print(FILE * foo, CloogOptions * options)
61 { fprintf(foo,"Options:\n") ;
62 fprintf(foo,"OPTIONS FOR LOOP GENERATION\n") ;
63 fprintf(foo,"l = %3d,\n",options->l) ;
64 fprintf(foo,"f = %3d,\n",options->f) ;
65 fprintf(foo,"stop = %3d,\n",options->stop) ;
66 fprintf(foo,"strides = %3d,\n",options->strides) ;
67 fprintf(foo,"OPTIONS FOR PRETTY PRINTING\n") ;
68 fprintf(foo,"esp = %3d,\n",options->esp) ;
69 fprintf(foo,"csp = %3d,\n",options->csp) ;
70 fprintf(foo,"fsp = %3d,\n",options->fsp) ;
71 fprintf(foo,"otl = %3d.\n",options->otl) ;
72 fprintf(foo,"block = %3d.\n",options->block) ;
73 fprintf(foo,"cpp = %3d.\n",options->cpp) ;
74 fprintf(foo,"compilable = %3d.\n",options->compilable) ;
75 fprintf(foo,"UNDOCUMENTED OPTIONS FOR THE AUTHOR ONLY\n") ;
76 fprintf(foo,"leaks = %3d.\n",options->leaks) ;
77 fprintf(foo,"nobacktrack = %3d.\n",options->nobacktrack) ;
78 fprintf(foo,"override = %3d.\n",options->override) ;
79 fprintf(foo,"structure = %3d.\n",options->structure) ;
80 fprintf(foo,"noscalars = %3d.\n",options->noscalars) ;
81 fprintf(foo,"noblocks = %3d.\n",options->noblocks) ;
82 fprintf(foo,"nosimplify = %3d.\n",options->nosimplify) ;
86 /******************************************************************************
87 * Memory deallocation function *
88 ******************************************************************************/
91 /**
92 * cloog_options_free function:
93 * This function frees the allocated memory for a CloogOptions structure.
94 * - April 19th 2003: first version.
96 void cloog_options_free(CloogOptions * options)
97 { free(options) ;
101 /******************************************************************************
102 * Processing functions *
103 ******************************************************************************/
107 * cloog_options_help function:
108 * This function displays the quick help when the user set the option -help
109 * while calling cloog. Prints are cutted to respect the 509 characters
110 * limitation of the ISO C 89 compilers.
111 * - August 5th 2002: first version.
113 void cloog_options_help()
114 { printf(
115 "Usage: cloog [ options | file ] ...\n"
116 "Options for code generation:\n"
117 " -l <depth> Last loop depth to optimize (-1: infinity)\n"
118 " (default setting: -1).\n"
119 " -f <depth> First loop depth to start loop separation (-1: "
120 "infinity)\n (default setting: 1).\n") ;
121 printf(
122 " -stop <depth> Loop depth to stop code generation (-1: infinity)"
123 "\n (default setting: -1).\n"
124 " -strides <boolean> Handle non-unit strides (1) or not (0)\n"
125 " (default setting: 0).\n") ;
126 printf(
127 "\nOptions for pretty printing:\n"
128 " -otl <boolean> Simplify loops running one time (1) or not (0)\n"
129 " (default setting: 1).\n") ;
130 printf(
131 " -esp <boolean> Allow complex equalities spreading (1) or not (0)\n"
132 " (default setting: 0).\n"
133 " -csp <boolean> Allow constant spreading (1) or not (0)\n"
134 " (default setting: 1).\n") ;
135 printf(
136 " -fsp <level> First level to begin the spreading\n"
137 " (default setting: 1).\n"
138 " -block <boolean> Make a new statement block per iterator in C\n"
139 " programs (1) or not (0) (default setting: 0).\n") ;
140 printf(
141 " -cpp <boolean> Compilable block by using preprocessor (1) or not "
142 "(0)\n (default setting: 0).\n"
143 " -compilable <number> Compilable code by using preprocessor (not 0) or"
144 "\n not (0), number being the value of the parameters"
145 "\n (default setting: 0).\n");
146 printf(
147 "\nGeneral options:\n"
148 " -o <output> Name of the output file; 'stdout' is a special\n"
149 " value: when used, output is standard output\n"
150 " (default setting: stdout).\n"
151 " -v, --version Display the version information (and more).\n"
152 " -h, --help Display this information.\n\n") ;
153 printf(
154 "The special value 'stdin' for 'file' makes CLooG to read data on\n"
155 "standard input.\n\n"
156 "For bug reporting or any suggestions, please send an email to the author\n"
157 "<cedric.bastoul@inria.fr>.\n") ;
162 * cloog_options_version function:
163 * This function displays some version informations when the user set the
164 * option -version while calling cloog. Prints are cutted to respect the 509
165 * characters limitation of the ISO C 89 compilers.
166 * - August 5th 2002: first version.
168 void cloog_options_version()
169 { printf("CLooG %s %s bits The Chunky Loop Generator\n",
170 CLOOG_RELEASE,CLOOG_VERSION) ;
171 printf(
172 "-----\n"
173 "This is a loop generator for scanning Z-polyhedra. It is based on the "
174 "work of\nF. Quillere and C. Bastoul on high level code generation and of "
175 "the PolyLib Team\non polyhedral computation. This program is distributed "
176 "under the terms of the\nGNU General Public License "
177 "(details at http://www.gnu.org/copyleft/gpl.html).\n"
178 "-----\n") ;
179 printf(
180 "It would be fair to refer the following paper in any publication "
181 "resulting from\nthe use of this software or its library:\n"
182 "@InProceedings{Bas04,\n"
183 "author = {Cedric Bastoul},\n"
184 "title = {Code Generation in the Polyhedral Model Is Easier Than You "
185 "Think},\n"
186 "booktitle = {PACT'13 IEEE International Conference on Parallel "
187 "Architecture\n and Compilation Techniques},\n"
188 "pages = {7--16},\n"
189 "month = {september},\n"
190 "year = 2004,\n"
191 "address = {Juan-les-Pins}\n"
192 "}\n"
193 "-----\n"
194 "For any information, please ask the author at "
195 "<cedric.bastoul@inria.fr>.\n") ;
200 * cloog_options_set function:
201 * This function sets the value of an option thanks to the user's calling line.
202 * - option is the value to set,
203 * - argc are the elements of the user's calling line,
204 * - number is the number of the element corresponding to the considered option,
205 * this function adds 1 to number to pass away the option value.
207 * - August 5th 2002: first version.
208 * - June 29th 2003: (debug) lack of argument now detected.
210 void cloog_options_set(int * option, int argv, char ** argc, int * number)
211 { char ** endptr ;
213 if (*number+1 >= argv)
214 { fprintf(stderr, "[CLooG]ERROR: an option lacks of argument.\n") ;
215 exit(1) ;
218 endptr = NULL ;
219 *option = strtol(argc[*number+1],endptr,10) ;
220 if (endptr != NULL)
221 { fprintf(stderr, "[CLooG]ERROR: %s value for %s option is not valid.\n",
222 argc[*number+1],argc[*number]) ;
223 exit(1) ;
225 *number = *number + 1 ;
230 * cloog_options_malloc function:
231 * This functions allocate the memory space for a CLoogOptions structure and
232 * fill its fields with the defaults values. It returns a pointer to the
233 * allocated CloogOptions structure.
234 * - April 19th 2003: first version.
235 * - November 21th 2005: name changed (before it was cloog_options_init).
237 CloogOptions * cloog_options_malloc(void)
238 { CloogOptions * options ;
240 /* Memory allocation for the CloogOptions structure. */
241 options = (CloogOptions *)malloc(sizeof(CloogOptions)) ;
242 if (options == NULL)
243 { fprintf(stderr, "[CLooG]ERROR: memory overflow.\n") ;
244 exit(1) ;
247 /* We set the various fields with default values. */
248 /* OPTIONS FOR LOOP GENERATION */
249 options->l = -1 ; /* Last level to optimize: infinity. */
250 options->f = 1 ; /* First level to optimize: the first. */
251 options->stop = -1 ; /* Generate all the code. */
252 options->strides = 0 ; /* Generate a code with unit strides. */
253 /* OPTIONS FOR PRETTY PRINTING */
254 options->esp = 0 ; /* We don't want Equality SPreading.*/
255 options->csp = 1 ; /* We want only Constant SPreading. */
256 options->fsp = 1 ; /* The First level to SPread is the first. */
257 options->otl = 1 ; /* We want to fire One Time Loops. */
258 options->block = 0 ; /* We don't want to force statement blocks. */
259 options->cpp = 0 ; /* No preprocessing facilities. */
260 options->compilable = 0 ; /* No compilable code. */
261 /* UNDOCUMENTED OPTIONS FOR THE AUTHOR ONLY */
262 options->leaks = 0 ; /* I don't want to print allocation statistics.*/
263 options->nobacktrack = 0 ; /* No backtrack in Quillere's algorithm.*/
264 options->override = 0 ; /* I don't want to override CLooG decisions.*/
265 options->structure = 0 ; /* I don't want to print internal structure.*/
266 options->noblocks = 0 ; /* I do want to make statement blocks.*/
267 options->noscalars = 0 ; /* I do want to use scalar dimensions.*/
268 options->nosimplify = 0 ; /* I do want to simplify polyhedra.*/
270 return options ;
276 * cloog_options_read function:
277 * This functions reads all the options and the input/output files thanks
278 * the the user's calling line elements (in argc). It fills a CloogOptions
279 * structure and the FILE structure corresponding to input and output files.
280 * - August 5th 2002: first version.
281 * - April 19th 2003: now in options.c and support of the CloogOptions structure.
283 void cloog_options_read(argv, argc, input, output, options)
284 int argv ;
285 char ** argc ;
286 FILE ** input, ** output ;
287 CloogOptions ** options ;
288 { int i, infos=0, input_is_set=0 ;
290 /* CloogOptions structure allocation and initialization. */
291 *options = cloog_options_malloc() ;
293 /* The default output is the standard output. */
294 *output = stdout ;
296 for (i=1;i<argv;i++)
297 if (argc[i][0] == '-')
298 { if (strcmp(argc[i],"-l") == 0)
299 cloog_options_set(&(*options)->l,argv,argc,&i) ;
300 else
301 if (strcmp(argc[i],"-f") == 0)
302 cloog_options_set(&(*options)->f,argv,argc,&i) ;
303 else
304 if (strcmp(argc[i],"-stop") == 0)
305 cloog_options_set(&(*options)->stop,argv,argc,&i) ;
306 else
307 if (strcmp(argc[i],"-strides") == 0)
308 cloog_options_set(&(*options)->strides,argv,argc,&i) ;
309 else
310 if (strcmp(argc[i],"-otl") == 0)
311 cloog_options_set(&(*options)->otl,argv,argc,&i) ;
312 else
313 if (strcmp(argc[i],"-esp") == 0)
314 cloog_options_set(&(*options)->esp,argv,argc,&i) ;
315 else
316 if (strcmp(argc[i],"-csp") == 0)
317 cloog_options_set(&(*options)->csp,argv,argc,&i) ;
318 else
319 if (strcmp(argc[i],"-fsp") == 0)
320 cloog_options_set(&(*options)->fsp,argv,argc,&i) ;
321 else
322 if (strcmp(argc[i],"-block") == 0)
323 cloog_options_set(&(*options)->block,argv,argc,&i) ;
324 else
325 if (strcmp(argc[i],"-cpp") == 0)
326 cloog_options_set(&(*options)->cpp,argv,argc,&i) ;
327 else
328 if (strcmp(argc[i],"-compilable") == 0)
329 { cloog_options_set(&(*options)->compilable,argv,argc,&i) ;
330 (*options)->cpp = 1 ;
332 else
333 if (strcmp(argc[i],"-rays") == 0)
334 { if (i+1 >= argv)
335 { fprintf(stderr, "[CLooG]ERROR: an option lacks of argument.\n") ;
336 exit(1) ;
339 MAX_RAYS = atoi(argc[i+1]) ;
340 if (MAX_RAYS < 1)
341 { fprintf(stderr, "[CLooG]ERROR: %s value for %s option is not valid.\n",
342 argc[i+1],argc[i]) ;
343 exit(1) ;
345 i++ ;
347 else
348 if (strcmp(argc[i],"-loopo") == 0) /* Special option for the LooPo team ! */
349 { (*options)->esp = 0 ;
350 (*options)->csp = 0 ;
351 (*options)->block = 1 ;
352 (*options)->cpp = 1 ;
354 else
355 if (strcmp(argc[i],"-bipbip") == 0)/* Special option for the author only !*/
356 { (*options)->nobacktrack = 1 ;
357 MAX_RAYS = 50 ;
359 else
360 if (strcmp(argc[i],"-leaks") == 0)
361 (*options)->leaks = 1 ;
362 else
363 if (strcmp(argc[i],"-nobacktrack") == 0)
364 (*options)->nobacktrack = 1 ;
365 else
366 if (strcmp(argc[i],"-override") == 0)
367 (*options)->override = 1 ;
368 else
369 if (strcmp(argc[i],"-noblocks") == 0)
370 (*options)->noblocks = 1 ;
371 else
372 if (strcmp(argc[i],"-noscalars") == 0)
373 (*options)->noscalars = 1 ;
374 else
375 if (strcmp(argc[i],"-nosimplify") == 0)
376 (*options)->nosimplify = 1 ;
377 else
378 if ((strcmp(argc[i],"-struct") == 0) || (strcmp(argc[i],"-structure") == 0))
379 (*options)->structure = 1 ;
380 else
381 if ((strcmp(argc[i],"--help") == 0) || (strcmp(argc[i],"-h") == 0))
382 { cloog_options_help() ;
383 infos = 1 ;
385 else
386 if ((strcmp(argc[i],"--version") == 0) || (strcmp(argc[i],"-v") == 0))
387 { cloog_options_version() ;
388 infos = 1 ;
390 else
391 if (strcmp(argc[i],"-o") == 0)
392 { if (i+1 >= argv)
393 { fprintf(stderr, "[CLooG]ERROR: no output name for -o option.\n") ;
394 exit(1) ;
397 /* stdout is a special value, when used, we set output to standard
398 * output.
400 if (strcmp(argc[i+1],"stdout") == 0)
401 *output = stdout ;
402 else
403 { *output = fopen(argc[i+1],"w") ;
404 if (*output == NULL)
405 { fprintf(stderr, "[CLooG]ERROR: can't create output file %s.\n",
406 argc[i+1]) ;
407 exit(1) ;
410 i ++ ;
412 else
413 fprintf(stderr, "[CLooG]WARNING: unknown %s option.\n",argc[i]) ;
415 else
416 { if (!input_is_set)
417 { input_is_set = 1 ;
418 (*options)->name = argc[i] ;
419 /* stdin is a special value, when used, we set input to standard input. */
420 if (strcmp(argc[i],"stdin") == 0)
421 *input = stdin ;
422 else
423 { *input = fopen(argc[i],"r") ;
424 if (*input == NULL)
425 { fprintf(stderr, "[CLooG]ERROR: %s file does not exist.\n",argc[i]) ;
426 exit(1) ;
430 else
431 { fprintf(stderr, "[CLooG]ERROR: multiple input files.\n") ;
432 exit(1) ;
435 if (!input_is_set)
436 { if (!infos)
437 fprintf(stderr, "[CLooG]ERROR: no input file (-h for help).\n") ;
438 exit(1) ;