Document -first-unroll in 'cloog -help' output.
[cloog/uuh.git] / source / options.c
blob7fb5dbd53fc9e55012adb6a4b1a387132f9315a8
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 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. *
21 * *
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. *
26 * *
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 *
31 * *
32 * CLooG, the Chunky Loop Generator *
33 * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr *
34 * *
35 ******************************************************************************/
38 #include <stdarg.h>
39 # include <stdlib.h>
40 # include <stdio.h>
41 # include <string.h>
42 # include "../include/cloog/cloog.h"
45 /******************************************************************************
46 * Error reporting functions *
47 ******************************************************************************/
49 void cloog_vmsg(CloogOptions *options, enum cloog_msg_type type,
50 const char *msg, va_list ap)
52 const char *type_msg;
54 if (options && options->quiet &&
55 (type == CLOOG_WARNING || type == CLOOG_INFO))
56 return;
58 switch(type) {
59 case CLOOG_WARNING:
60 type_msg = "WARNING";
61 break;
62 case CLOOG_INFO:
63 type_msg = "INFO";
64 break;
65 case CLOOG_ERROR:
66 default:
67 type_msg = "ERROR";
68 break;
70 fprintf(stderr, "[CLooG] %s: ", type_msg);
71 vfprintf(stderr, msg, ap);
74 /**
75 * Print message to stderr.
76 * @param msg printf format string
78 void cloog_msg(CloogOptions *options, enum cloog_msg_type type,
79 const char *msg, ...)
81 va_list args;
83 va_start(args, msg);
84 cloog_vmsg(options, type, msg, args);
85 va_end(args);
88 /**
89 * Print error message to stderr and exit.
90 * @param msg printf format string
92 void cloog_die(const char *msg, ...)
94 va_list args;
96 va_start(args, msg);
97 cloog_vmsg(NULL, CLOOG_ERROR, msg, args);
98 va_end(args);
99 exit(1);
102 /******************************************************************************
103 * Structure display function *
104 ******************************************************************************/
108 * cloog_option_print function:
109 * This function prints the content of a CloogOptions structure (program) into
110 * a file (foo, possibly stdout).
111 * - April 19th 2003: first version.
113 void cloog_options_print(FILE * foo, CloogOptions * options)
114 { fprintf(foo,"Options:\n") ;
115 fprintf(foo,"OPTIONS FOR LOOP GENERATION\n") ;
116 fprintf(foo,"l = %3d,\n",options->l) ;
117 fprintf(foo,"f = %3d,\n",options->f) ;
118 fprintf(foo,"stop = %3d,\n",options->stop) ;
119 fprintf(foo,"strides = %3d,\n",options->strides) ;
120 fprintf(foo,"sh = %3d,\n",options->sh);
121 fprintf(foo,"OPTIONS FOR PRETTY PRINTING\n") ;
122 fprintf(foo,"esp = %3d,\n",options->esp) ;
123 fprintf(foo,"fsp = %3d,\n",options->fsp) ;
124 fprintf(foo,"otl = %3d.\n",options->otl) ;
125 fprintf(foo,"block = %3d.\n",options->block) ;
126 fprintf(foo,"compilable = %3d.\n",options->compilable) ;
127 fprintf(foo,"callable = %3d.\n",options->callable) ;
128 fprintf(foo,"UNDOCUMENTED OPTIONS FOR THE AUTHOR ONLY\n") ;
129 fprintf(foo,"leaks = %3d.\n",options->leaks) ;
130 fprintf(foo,"backtrack = %3d.\n",options->backtrack);
131 fprintf(foo,"override = %3d.\n",options->override) ;
132 fprintf(foo,"structure = %3d.\n",options->structure) ;
133 fprintf(foo,"noscalars = %3d.\n",options->noscalars) ;
134 fprintf(foo,"noblocks = %3d.\n",options->noblocks) ;
135 fprintf(foo,"nosimplify = %3d.\n",options->nosimplify) ;
139 /******************************************************************************
140 * Memory deallocation function *
141 ******************************************************************************/
145 * cloog_options_free function:
146 * This function frees the allocated memory for a CloogOptions structure.
147 * - April 19th 2003: first version.
149 void cloog_options_free(CloogOptions *options)
151 free(options);
155 /******************************************************************************
156 * Processing functions *
157 ******************************************************************************/
161 * cloog_options_help function:
162 * This function displays the quick help when the user set the option -help
163 * while calling cloog. Prints are cutted to respect the 509 characters
164 * limitation of the ISO C 89 compilers.
165 * - August 5th 2002: first version.
167 void cloog_options_help()
168 { printf(
169 "Usage: cloog [ options | file ] ...\n"
170 "Options for code generation:\n"
171 " -l <depth> Last loop depth to optimize (-1: infinity)\n"
172 " (default setting: -1).\n"
173 " -f <depth> First loop depth to start loop separation (-1: "
174 "infinity)\n (default setting: 1).\n") ;
175 printf(
176 " -stop <depth> Loop depth to stop code generation (-1: infinity)"
177 "\n (default setting: -1).\n"
178 " -strides <boolean> Handle non-unit strides (1) or not (0)\n"
179 " (default setting: 0).\n"
180 " -first-unroll <depth> First loop dimension to unroll (-1: no unrolling)\n");
181 printf(
182 "\nOptions for pretty printing:\n"
183 " -otl <boolean> Simplify loops running one time (1) or not (0)\n"
184 " (default setting: 1).\n") ;
185 printf(
186 " -esp <boolean> Allow complex equalities spreading (1) or not (0)\n"
187 " (default setting: 0).\n");
188 printf(
189 " -fsp <level> First level to begin the spreading\n"
190 " (default setting: 1).\n"
191 " -block <boolean> Make a new statement block per iterator in C\n"
192 " programs (1) or not (0) (default setting: 0).\n") ;
193 printf(
194 " -compilable <number> Compilable code by using preprocessor (not 0) or"
195 "\n not (0), number being the value of the parameters"
196 "\n (default setting: 0).\n"
197 " -callable <boolean> Testable code by using preprocessor (not 0) or"
198 "\n not (0) (default setting: 0).\n");
199 printf(
200 "\nGeneral options:\n"
201 " -o <output> Name of the output file; 'stdout' is a special\n"
202 " value: when used, output is standard output\n"
203 " (default setting: stdout).\n"
204 " -v, --version Display the version information (and more).\n"
205 " -q, --quiet Don't print any informational messages.\n"
206 " -h, --help Display this information.\n\n") ;
207 printf(
208 "The special value 'stdin' for 'file' makes CLooG to read data on\n"
209 "standard input.\n\n"
210 "For bug reporting or any suggestions, please send an email to the author\n"
211 "<cedric.bastoul@inria.fr>.\n") ;
216 * cloog_options_version function:
217 * This function displays some version informations when the user set the
218 * option -version while calling cloog. Prints are cutted to respect the 509
219 * characters limitation of the ISO C 89 compilers.
220 * - August 5th 2002: first version.
222 void cloog_options_version()
223 { printf("%s The Chunky Loop Generator\n", cloog_version());
224 printf(
225 "-----\n"
226 "This is a loop generator for scanning Z-polyhedra. It is based on the "
227 "work of\nF. Quillere and C. Bastoul on high level code generation and of "
228 "the PolyLib Team\non polyhedral computation. This program is distributed "
229 "under the terms of the\nGNU Lesser General Public License "
230 "(details at http://www.gnu.org/licenses/lgpl-2.1.html).\n"
231 "-----\n") ;
232 printf(
233 "It would be fair to refer the following paper in any publication "
234 "resulting from\nthe use of this software or its library:\n"
235 "@InProceedings{Bas04,\n"
236 "author = {Cedric Bastoul},\n"
237 "title = {Code Generation in the Polyhedral Model Is Easier Than You "
238 "Think},\n"
239 "booktitle = {PACT'13 IEEE International Conference on Parallel "
240 "Architecture\n and Compilation Techniques},\n"
241 "pages = {7--16},\n"
242 "month = {september},\n"
243 "year = 2004,\n"
244 "address = {Juan-les-Pins}\n"
245 "}\n"
246 "-----\n"
247 "For any information, please ask the author at "
248 "<cedric.bastoul@inria.fr>.\n") ;
253 * cloog_options_set function:
254 * This function sets the value of an option thanks to the user's calling line.
255 * - option is the value to set,
256 * - argc are the elements of the user's calling line,
257 * - number is the number of the element corresponding to the considered option,
258 * this function adds 1 to number to pass away the option value.
260 * - August 5th 2002: first version.
261 * - June 29th 2003: (debug) lack of argument now detected.
263 void cloog_options_set(int * option, int argv, char ** argc, int * number)
264 { char ** endptr ;
266 if (*number+1 >= argv)
267 cloog_die("an option lacks of argument.\n");
269 endptr = NULL ;
270 *option = strtol(argc[*number+1],endptr,10) ;
271 if (endptr != NULL)
272 cloog_die("value '%s' for option '%s' is not valid.\n",
273 argc[*number+1], argc[*number]);
274 *number = *number + 1 ;
279 * cloog_options_malloc function:
280 * This functions allocate the memory space for a CLoogOptions structure and
281 * fill its fields with the defaults values. It returns a pointer to the
282 * allocated CloogOptions structure.
283 * - April 19th 2003: first version.
284 * - November 21th 2005: name changed (before it was cloog_options_init).
286 CloogOptions *cloog_options_malloc(CloogState *state)
287 { CloogOptions * options ;
289 /* Memory allocation for the CloogOptions structure. */
290 options = (CloogOptions *)malloc(sizeof(CloogOptions)) ;
291 if (options == NULL)
292 cloog_die("memory overflow.\n");
294 options->state = state;
296 /* We set the various fields with default values. */
297 /* OPTIONS FOR LOOP GENERATION */
298 options->l = -1 ; /* Last level to optimize: infinity. */
299 options->f = 1 ; /* First level to optimize: the first. */
300 options->stop = -1 ; /* Generate all the code. */
301 options->strides = 0 ; /* Generate a code with unit strides. */
302 options->sh = 0; /* Compute actual convex hull. */
303 options->first_unroll = -1; /* First level to unroll: none. */
304 options->name = "";
305 /* OPTIONS FOR PRETTY PRINTING */
306 options->esp = 1 ; /* We want Equality SPreading.*/
307 options->fsp = 1 ; /* The First level to SPread is the first. */
308 options->otl = 1 ; /* We want to fire One Time Loops. */
309 options->block = 0 ; /* We don't want to force statement blocks. */
310 options->compilable = 0 ; /* No compilable code. */
311 options->callable = 0 ; /* No callable code. */
312 options->quiet = 0; /* Do print informational messages. */
313 options->language = LANGUAGE_C; /* The default output language is C. */
314 options->save_domains = 0; /* Don't save domains. */
315 /* UNDOCUMENTED OPTIONS FOR THE AUTHOR ONLY */
316 options->leaks = 0 ; /* I don't want to print allocation statistics.*/
317 options->backtrack = 0; /* Perform backtrack in Quillere's algorithm.*/
318 options->override = 0 ; /* I don't want to override CLooG decisions.*/
319 options->structure = 0 ; /* I don't want to print internal structure.*/
320 options->noblocks = 0 ; /* I do want to make statement blocks.*/
321 options->noscalars = 0 ; /* I do want to use scalar dimensions.*/
322 options->nosimplify = 0 ; /* I do want to simplify polyhedra.*/
324 return options ;
330 * cloog_options_read function:
331 * This functions reads all the options and the input/output files thanks
332 * the the user's calling line elements (in argc). It fills a CloogOptions
333 * structure and the FILE structure corresponding to input and output files.
334 * - August 5th 2002: first version.
335 * - April 19th 2003: now in options.c and support of the CloogOptions structure.
337 void cloog_options_read(CloogState *state, int argc, char **argv,
338 FILE **input, FILE **output, CloogOptions **options)
339 { int i, infos=0, input_is_set=0 ;
341 /* CloogOptions structure allocation and initialization. */
342 *options = cloog_options_malloc(state);
344 /* The default output is the standard output. */
345 *output = stdout ;
347 for (i=1;i<argc;i++)
348 if (argv[i][0] == '-')
349 { if (strcmp(argv[i],"-l") == 0)
350 cloog_options_set(&(*options)->l,argc,argv,&i) ;
351 else
352 if (strcmp(argv[i],"-f") == 0)
353 cloog_options_set(&(*options)->f,argc,argv,&i) ;
354 else
355 if (strcmp(argv[i],"-stop") == 0)
356 cloog_options_set(&(*options)->stop,argc,argv,&i) ;
357 else
358 if (strcmp(argv[i],"-strides") == 0)
359 cloog_options_set(&(*options)->strides,argc,argv,&i) ;
360 else if (strcmp(argv[i],"-sh") == 0)
361 cloog_options_set(&(*options)->sh,argc,argv,&i) ;
362 else if (!strcmp(argv[i], "-first-unroll"))
363 cloog_options_set(&(*options)->first_unroll, argc, argv, &i);
364 else
365 if (strcmp(argv[i],"-otl") == 0)
366 cloog_options_set(&(*options)->otl,argc,argv,&i) ;
367 else
368 if (strcmp(argv[i],"-esp") == 0)
369 cloog_options_set(&(*options)->esp,argc,argv,&i) ;
370 else
371 if (strcmp(argv[i],"-fsp") == 0)
372 cloog_options_set(&(*options)->fsp,argc,argv,&i) ;
373 else
374 if (strcmp(argv[i],"-block") == 0)
375 cloog_options_set(&(*options)->block,argc,argv,&i) ;
376 else
377 if (strcmp(argv[i],"-compilable") == 0)
378 cloog_options_set(&(*options)->compilable, argc, argv, &i);
379 else if (strcmp(argv[i], "-callable") == 0)
380 cloog_options_set(&(*options)->callable, argc, argv, &i);
381 else
382 if (strcmp(argv[i],"-loopo") == 0) /* Special option for the LooPo team ! */
383 { (*options)->esp = 0 ;
384 (*options)->block = 1 ;
386 else
387 if (strcmp(argv[i],"-bipbip") == 0)/* Special option for the author only !*/
388 (*options)->backtrack = 0;
389 else
390 if (strcmp(argv[i],"-leaks") == 0)
391 (*options)->leaks = 1 ;
392 else
393 if (strcmp(argv[i],"-nobacktrack") == 0)
394 (*options)->backtrack = 0;
395 else if (strcmp(argv[i], "-backtrack") == 0)
396 (*options)->backtrack = 1;
397 else
398 if (strcmp(argv[i],"-override") == 0)
399 (*options)->override = 1 ;
400 else
401 if (strcmp(argv[i],"-noblocks") == 0)
402 (*options)->noblocks = 1 ;
403 else
404 if (strcmp(argv[i],"-noscalars") == 0)
405 (*options)->noscalars = 1 ;
406 else
407 if (strcmp(argv[i],"-nosimplify") == 0)
408 (*options)->nosimplify = 1 ;
409 else
410 if ((strcmp(argv[i],"-struct") == 0) || (strcmp(argv[i],"-structure") == 0))
411 (*options)->structure = 1 ;
412 else
413 if ((strcmp(argv[i],"--help") == 0) || (strcmp(argv[i],"-h") == 0))
414 { cloog_options_help() ;
415 infos = 1 ;
417 else
418 if ((strcmp(argv[i],"--version") == 0) || (strcmp(argv[i],"-v") == 0))
419 { cloog_options_version() ;
420 infos = 1 ;
421 } else if ((strcmp(argv[i],"--quiet") == 0) || (strcmp(argv[i],"-q") == 0))
422 (*options)->quiet = 1;
423 else
424 if (strcmp(argv[i],"-o") == 0)
425 { if (i+1 >= argc)
426 cloog_die("no output name for -o option.\n");
428 /* stdout is a special value, when used, we set output to standard
429 * output.
431 if (strcmp(argv[i+1],"stdout") == 0)
432 *output = stdout ;
433 else
434 { *output = fopen(argv[i+1],"w") ;
435 if (*output == NULL)
436 cloog_die("can't create output file %s.\n", argv[i+1]);
438 i ++ ;
440 else
441 cloog_msg(*options, CLOOG_WARNING, "unknown %s option.\n", argv[i]);
443 else
444 { if (!input_is_set)
445 { input_is_set = 1 ;
446 (*options)->name = argv[i] ;
447 /* stdin is a special value, when used, we set input to standard input. */
448 if (strcmp(argv[i],"stdin") == 0)
449 *input = stdin ;
450 else
451 { *input = fopen(argv[i],"r") ;
452 if (*input == NULL)
453 cloog_die("%s file does not exist.\n", argv[i]);
456 else
457 cloog_die("multiple input files.\n");
459 if (!input_is_set)
460 { if (!infos)
461 cloog_die("no input file (-h for help).\n");
462 exit(1) ;