2 /**------ ( ----------------------------------------------------------**
4 **----- / ) --------------------------------------------------------**
6 **---- \#/ --------------------------------------------------------**
7 ** .-"#'-. First version: september 8th 2003 **
8 **--- |"-.-"| -------------------------------------------------------**
11 ******** | | *************************************************************
12 * CAnDL '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
13 ******************************************************************************
15 * Copyright (C) 2003 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 * CAnDL, the Chunky Dependence Analyser *
32 * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr *
34 ******************************************************************************/
40 #include <candl/macros.h>
41 #include <candl/options.h>
44 /******************************************************************************
45 * Structure display function *
46 ******************************************************************************/
50 * candl_option_print function:
51 * This function prints the content of a candl_options_t structure (program) into
52 * a file (foo, possibly stdout).
53 * April 19th 2003: first version.
55 void candl_options_print(FILE * foo
, candl_options_p options
) {
56 fprintf(foo
, "Options:\n");
60 /******************************************************************************
61 * Memory deallocation function *
62 ******************************************************************************/
66 * candl_options_free function:
67 * This function frees the allocated memory for a candl_options_t structure.
68 * April 19th 2003: first version.
70 void candl_options_free(candl_options_p options
) {
75 /******************************************************************************
76 * Processing functions *
77 ******************************************************************************/
81 * candl_options_malloc function:
82 * This functions allocate the memory space for a candl_options_t structure and
83 * fill its fields with the defaults values. It returns a pointer to the
84 * allocated candl_options_t structure.
85 * April 19th 2003: first version.
87 candl_options_p
candl_options_malloc(void) {
88 candl_options_p options
;
90 /* Memory allocation for the candl_options_t structure. */
91 options
= (candl_options_p
) malloc(sizeof(candl_options_t
));
92 if (options
== NULL
) {
93 fprintf(stderr
, "[Candl]ERROR: memory overflow.\n");
97 /* We set the various fields with default values. */
98 /* OPTIONS FOR DEPENDENCE COMPUTATION */
99 options
->waw
= 1; /* WAW (output) dependences matter. */
100 options
->raw
= 1; /* RAW (flow) dependences matter. */
101 options
->war
= 1; /* WAR (anti) dependences matter. */
102 options
->rar
= 0; /* RAR (input) dependences don't matter. */
103 options
->commute
= 0; /* Don't use commutativity to simplify dependences.*/
104 options
->fullcheck
= 0; /* Don't compute all violations.*/
105 options
->scalar_renaming
= 0; /* Don't enable scalar renaming. */
106 options
->scalar_privatization
= 0; /* Don't enable scalar privatization. */
107 options
->scalar_expansion
= 0; /* Don't enable scalar expansion. */
108 options
->lastwriter
= 0; /* Compute the last writer for RAW and WAW dependences */
109 options
->verbose
= 0; /* Don't be verbose. */
110 options
->outscop
= 0; /* Don't print the scop. */
111 options
->autocorrect
= 0; /* Don't correct violations. */
112 /* UNDOCUMENTED OPTIONS FOR THE AUTHOR ONLY */
113 options
->view
= 0; /* Do not visualize the graph with dot and gv.*/
114 options
->structure
= 0; /* Don't print internal dependence structure. */
115 options
->prune_dups
= 0; /**< 1 to use experimental dependence pruning algorithm. */
122 * candl_options_help function:
123 * This function displays the quick help when the user set the option -help
124 * while calling candl. Prints are cutted to respect the 509 characters
125 * limitation of the ISO C 89 compilers.
126 * August 5th 2002: first version.
128 void candl_options_help() {
130 "Usage: candl [ options | file ] ...\n"
131 "Options for data dependence computation:\n"
132 " -waw <boolean> Consider WAW (output) dependences (1) or not (0)\n"
133 " (default setting: 1).\n"
134 " -raw <boolean> Consider RAW (flow) dependences (1) or not (0)\n"
135 " (default setting: 1).\n"
136 " -war <boolean> Consider WAR (anti) dependences (1) or not (0)\n"
137 " (default setting: 1).\n"
138 " -rar <boolean> Consider RAR (input) dependences (1) or not (0)\n"
139 " (default setting: 0).\n");
141 " -commute <boolean> Consider commutativity (1) or not (0)\n"
142 " (default setting: 0).\n"
143 " -fullcheck <boolean> Compute all legality violation (1) or just the\n"
145 " (default setting: 0, or 1 if autocorrect is set).\n"
146 " -scalren <boolean> Ask to enable scalar renaming (1) or not (0)\n"
147 " (default setting: 0).\n"
148 " -scalpriv <boolean> Ask to enable scalar privatization (1) or not (0)\n"
149 " (default setting: 0).\n"
150 " -scalexp <boolean> Ask to enable scalar expansion (1) or not (0)\n"
151 " (default setting: 0).\n");
153 " -view Ask to display the graphs (1) or not (0)\n"
154 " (requires dot -graphviz- and gv tools).\n");
156 "\nGeneral options:\n"
157 " -test <origscop> Test violations with the original scop.\n"
158 //" -autocorrect <boolean> Correct violations with a shifting (1) or not(0)\n"
159 " -test must be set\n"
160 " (default setting: 0).\n"
161 " -outscop Output a .scop formatted file as the output.\n"
162 " -o <output> Name of the output file; 'stdout' is a special\n"
163 " value: when used, output is standard output\n"
164 " (default setting: stdout).\n"
165 " -verbose Display a verbose output.\n"
166 " -v, --version Display the version information.\n"
167 " -h, --help Display this information.\n\n"
168 "The special value 'stdin' for 'file' makes Candl to read data on standard\n"
170 "If the -test is not given, the dependences graph of the input 'file' will\n"
171 "be computed, otherwise it's the violation graph between 'origscop' and 'file'"
173 "For bug reporting or any suggestions, please send an email to the author\n"
174 "<cedric.bastoul@inria.fr> or to the maintainer of Candl:\n"
175 "<pouchet@cse.ohio-state.edu>.\n");
180 * candl_options_version function:
181 * This function displays some version informations when the user set the
182 * option -version while calling candl. Prints are cutted to respect the 509
183 * characters limitation of the ISO C 89 compilers.
184 * August 5th 2002: first version.
186 void candl_options_version() { printf("Candl %s %s bits The Chunky Dependence Analyzer\n",
187 CANDL_RELEASE
,CANDL_VERSION
);
190 "Candl is a dependence analyzer for static control programs, coming from \n"
191 "the CHUNKY project: a research tool for data-locality improvement. This \n"
192 "program is distributed under the terms of the GNU Lesser General Public\n"
193 "License (details at http://www.gnu.org/copyleft/gpl.html).\n"
196 "It would be kind to refer the following paper in any publication "
197 "resulting \nfrom the use of this software or its library:\n"
199 "author = {Cedric Bastoul and Paul Feautrier},\n"
200 "title = {Adjusting a program transformation for legality},\n"
201 "journal = {Parallel Processing Letters},\n"
209 "For bug reporting or any suggestions, please send an email to the author\n"
210 "<cedric.bastoul@inria.fr>.\n");
215 * candl_options_set function:
216 * This function sets the value of an option thanks to the user's calling line.
217 * - option is the value to set,
218 * - argc are the elements of the user's calling line,
219 * - number is the number of the element corresponding to the considered option,
220 * this function adds 1 to number to pass away the option value.
221 * August 5th 2002: first version.
222 * June 29th 2003: (debug) lack of argument now detected.
224 void candl_options_set(int * option
, int argc
, char ** argv
, int * number
) {
227 if (*number
+1 >= argc
) {
228 fprintf(stderr
, "[Candl]ERROR: an option lacks of argument.\n");
233 *option
= strtol(argv
[*number
+1],endptr
,10);
234 if (endptr
!= NULL
) {
235 fprintf(stderr
, "[Candl]ERROR: %s option value is not valid.\n",
239 *number
= *number
+ 1;
244 * candl_options_read function:
245 * This functions reads all the options and the input/output files thanks
246 * the the user's calling line elements (in argc). It fills a candl_options_t
247 * structure and the FILE structure corresponding to input and output files.
248 * August 5th 2002: first version.
249 * April 19th 2003: now in options.c and support of the candl_options_t structure.
251 void candl_options_read(int argc
, char** argv
, FILE** input
, FILE** output
,
252 FILE **input_test
, candl_options_p
* options
) {
253 int i
, infos
= 0, input_is_set
= 0, testscop_is_set
= 0;
255 /* candl_options_t structure allocation and initialization. */
256 *options
= candl_options_malloc();
257 /* The default output is the standard output. */
261 for (i
= 1; i
< argc
; i
++) {
262 if (argv
[i
][0] == '-') {
263 if (!strcmp(argv
[i
], "-waw")) {
264 candl_options_set(&(*options
)->waw
, argc
, argv
, &i
);
266 if (!strcmp(argv
[i
], "-raw")) {
267 candl_options_set(&(*options
)->raw
, argc
, argv
, &i
);
269 if (!strcmp(argv
[i
], "-war")) {
270 candl_options_set(&(*options
)->war
, argc
, argv
, &i
);
272 if (!strcmp(argv
[i
], "-rar")) {
273 candl_options_set(&(*options
)->rar
, argc
, argv
, &i
);
275 if (!strcmp(argv
[i
], "-commute")) {
276 candl_options_set(&(*options
)->commute
, argc
, argv
, &i
);
278 if (!strcmp(argv
[i
], "-fullcheck")) {
279 candl_options_set(&(*options
)->fullcheck
, argc
, argv
, &i
);
281 if (!strcmp(argv
[i
], "-scalren")) {
282 candl_options_set(&(*options
)->scalar_renaming
, argc
, argv
, &i
);
284 if (!strcmp(argv
[i
], "-scalpriv")) {
285 candl_options_set(&(*options
)->scalar_privatization
, argc
, argv
, &i
);
287 if (!strcmp(argv
[i
], "-scalexp")) {
288 candl_options_set(&(*options
)->scalar_expansion
, argc
, argv
, &i
);
290 if (!strcmp(argv
[i
], "-lastwriter")) {
291 candl_options_set(&(*options
)->lastwriter
, argc
, argv
, &i
);
293 if (!strcmp(argv
[i
], "-autocorrect")) {
294 candl_options_set(&(*options
)->autocorrect
, argc
, argv
, &i
);
296 if (!strcmp(argv
[i
], "-view")) {
297 (*options
)->view
= 1;
299 if (!strcmp(argv
[i
], "-verbose")) {
300 (*options
)->verbose
= 1;
302 if (!strcmp(argv
[i
], "-outscop")) {
303 (*options
)->outscop
= 1;
305 if (!strcmp(argv
[i
], "-prune-dups")) {
306 (*options
)->prune_dups
= 1;
308 if ((!strcmp(argv
[i
], "-struct")) ||
309 (!strcmp(argv
[i
], "-structure"))) {
310 (*options
)->structure
= 1;
312 if ((!strcmp(argv
[i
], "--help")) || (!strcmp(argv
[i
], "-h"))) {
313 candl_options_help();
316 if ((!strcmp(argv
[i
], "--version")) || (!strcmp(argv
[i
], "-v"))) {
317 candl_options_version();
320 if (!strcmp(argv
[i
], "-o")) {
324 "[Candl]ERROR: no output name for -o option.\n");
328 /* stdout is a special value, when used, we set output to standard
331 if (!strcmp(argv
[i
], "stdout")) {
334 *output
= fopen(argv
[i
], "w");
335 if (*output
== NULL
) {
337 "[Candl]ERROR: can't create output file %s.\n",
343 if (!strcmp(argv
[i
], "-test")) {
345 if (!testscop_is_set
) {
347 /* stdin is a special value, when used, we set input to
349 if (!strcmp(argv
[i
], "stdin")) {
352 *input_test
= fopen(argv
[i
], "r");
353 if (*input_test
== NULL
) {
355 "[Candl]ERROR: %s file does not exist.\n", argv
[i
]);
360 fprintf(stderr
, "[Candl]ERROR: multiple input files.\n");
364 fprintf(stderr
, "[Candl]ERROR: unknown %s option.\n", argv
[i
]);
367 else { /* open a file */
370 /* stdin is a special value, when used, we set input to
372 if (!strcmp(argv
[i
], "stdin")) {
375 *input
= fopen(argv
[i
], "r");
376 if (*input
== NULL
) {
378 "[Candl]ERROR: %s file does not exist.\n", argv
[i
]);
383 CANDL_error("multiple input files.\n");
388 if ((*options
)->autocorrect
) {
389 (*options
)->fullcheck
= 1;
391 CANDL_error("no test file (-h for help).\n");
396 CANDL_error("no input file (-h for help).\n");
400 if (*input_test
&& !strcmp(argv
[input_is_set
], argv
[testscop_is_set
])) {
402 CANDL_error("the input file and the test scop can't be the same file.\n");