Add a source-2-source compiler example to the documentation
[cloog/uuh.git] / doc / cloog.texi
blob77e6ee8006fd34ed4f6ae678e5002c33b450abbf
1 \input texinfo
2 @c %
3 @c %  /**-----------------------------------------------------------------**
4 @c %   **                              CLooG                              **
5 @c %   **-----------------------------------------------------------------**
6 @c %   **                            cloog.texi                           **
7 @c %   **-----------------------------------------------------------------**
8 @c %   **                   First version: july 6th 2002                  **
9 @c %   **-----------------------------------------------------------------**/
10 @c %
11 @c % release 1.0: September 17th 2002
12 @c % release 1.1: December   5th 2002
13 @c % release 1.2: April     22th 2003
14 @c % release 2.0: November  21th 2005 (and now in texinfo instead of LaTeX)
15 @c % release 2.1: October   15th 2007
16 @c %
17 @c %/**************************************************************************
18 @c % *               CLooG : the Chunky Loop Generator (experimental)         *
19 @c % **************************************************************************/
20 @c %/* CAUTION: the English used is probably the worst you ever read, please
21 @c % *          feel free to correct and improve it !
22 @c % */
24 @c %\textit{"I found the ultimate transformation functions, optimization for
25 @c %static control programs is now a closed problem, I have \textnormal{just}
26 @c %to generate the target code !"} 
30 @c % /*************************************************************************
31 @c %  *                              PART I: HEADER                           *
32 @c %  *************************************************************************/
33 @c %**start of header
34 @setfilename cloog.info
35 @settitle CLooG - a loop generator for scanning polyhedra
37 @set EDITION 2.1.2
38 @include gitversion.texi
39 @set UPDATED July 27th 2015
40 @setchapternewpage odd
42 @c %**end of header
44 @c % /*************************************************************************
45 @c %  *                 PART II: SUMMARY DESCRIPTION AND COPYRIGHT            *
46 @c %  *************************************************************************/
48 @copying
49 This manual is for CLooG version @value{VERSION}, a software
50 which generates loops for scanning Z-polyhedra. That is, CLooG produces a
51 code visiting each integral point of a union of parametrized
52 polyhedra. CLooG is designed to avoid control overhead and to produce a very
53 efficient code.
55 It would be quite kind to refer the following paper in any publication that
56 results from the use of the CLooG software or its library:
58 @example
59 @@InProceedings@{Bas04,
60 @ @ author =@ @ @ @ @{C. Bastoul@},
61 @ @ title =@ @ @ @ @ @{Code Generation in the Polyhedral Model
62 @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ Is Easier Than You Think@},
63 @ @ booktitle = @{PACT'13 IEEE International Conference on
64 @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ Parallel Architecture and Compilation Techniques@},
65 @ @ year =@ @ @ @ @ @ 2004,
66 @ @ pages =@ @ @ @ @ @{7--16@},
67 @ @ month =@ @ @ @ @ @{september@},
68 @ @ address =@ @ @ @{Juan-les-Pins@}
70 @end example
72 Copyright @copyright{} 2002-2014 C@'edric Bastoul.
74 @c quotation
75 Permission is granted to copy, distribute and/or modify this document under
76 the terms of the GNU Free Documentation License, Version 1.2 
77 published by the Free Software Foundation. To receive a copy of the
78 GNU Free Documentation License, write to the Free Software Foundation, Inc.,
79 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA.
80 @c end quotation
81 @end copying
83 @c % /*************************************************************************
84 @c %  *                 PART III: TITLEPAGE, CONTENTS, COPYRIGHT              *
85 @c %  *************************************************************************/
86 @titlepage
87 @title CLooG
88 @subtitle A Loop Generator For Scanning Polyhedra
89 @subtitle Edition @value{EDITION}, for CLooG @value{VERSION}
90 @subtitle @value{UPDATED}
91 @author C@'edric Bastoul
92      
93 @c The following two commands start the copyright page.
94 @page
95 @noindent (September 2001)
96 @table @code
97 @item C@'edric Bastoul
98 SCHEDULES GENERATE !!! I just need to apply them now, where can I find
99 a good code generator ?!
100      
101 @item Paul Feautrier
102 Hmmm. I fear that if you want something powerful enough, you'll have to
103 write it yourself !
104 @end table
106 @vskip 0pt plus 1filll
107 @insertcopying
108 @end titlepage
109      
110 @c Output the table of contents at the beginning.
111 @contents
113 @c % /*************************************************************************
114 @c %  *                     PART IV: TOP NODE AND MASTER MENU                 *
115 @c %  *************************************************************************/
116 @ifnottex
117 @node Top
118 @top CLooG
119      
120 @insertcopying
121 @end ifnottex
123 @menu
124 * Introduction::
125 * CLooG Software::
126 * CLooG Library::
127 @c * Hacking::
128 * Installing::
129 * Documentation::
130 * References::
131 @end menu
135 @c % /*************************************************************************
136 @c %  *                       PART V: BODY OF THE DOCUMENT                    *
137 @c %  *************************************************************************/
139 @c %  ****************************** INTRODUCTION ******************************
140 @node Introduction
141 @chapter Introduction
142 CLooG is a free software and library generating loops for scanning Z-polyhedra.
143 That is, it finds a code (e.g. in C, FORTRAN...) that reaches each integral
144 point of one or more parameterized polyhedra. CLooG has been originally
145 written to solve the code generation problem for optimizing compilers based on
146 the polytope model. Nevertheless it is used now in various area, e.g., to build
147 control automata for high-level synthesis or to find the best polynomial
148 approximation of a function. CLooG may help in any situation where scanning
149 polyhedra matters. It uses the best state-of-the-art code generation
150 algorithm known as the Quiller@'e et al. algorithm (@pxref{Qui00})
151 with our own improvements and extensions (@pxref{Bas04}).
152 The user has full control on generated code quality.
153 On one hand, generated code size has to be tuned for sake of
154 readability or instruction cache use. On the other hand, we must ensure that
155 a bad control management does not hamper performance of the generated code,
156 for instance by producing redundant guards or complex loop bounds.
157 CLooG is specially designed to avoid control overhead and to produce a very
158 efficient code.
160 CLooG stands for @emph{Chunky Loop Generator}: it is a part of the Chunky
161 project, a research tool for data locality improvement (@pxref{Bas03a}).
162 It is designed
163 also to be the back-end of automatic parallelizers like LooPo (@pxref{Gri04}).
164 Thus it is very
165 compilable code oriented and provides powerful program transformation
166 facilities. Mainly, it allows the user to specify very general schedules where, 
167 e.g., unimodularity or invertibility of the transformation doesn't matter.
169 The current version is still under
170 evaluation, and there is no guarantee that the upward compatibility
171 will be respected (but the previous API has been stable for two years,
172 we hope this one will be as successful -and we believe it-).
173 A lot of reports are necessary to freeze the library
174 API and the input file shape. Most API changes from 0.12.x to 0.14.x
175 have been requested by the users themselves.
176 Thus you are very welcome and encouraged
177 to post reports on bugs, wishes, critics, comments, suggestions or
178 successful experiences in the forum of @code{http://www.CLooG.org}
179 or to send them to cedric.bastoul@@inria.fr directly.
181 @menu
182 * Basics::
183 * Scattering::
184 @end menu
186 @node Basics
187 @section Basically, what's the point ?
188 If you want to use CLooG, this is because you want to scan or to find
189 something inside the integral points of a set of polyhedra. There are many
190 reasons for that. Maybe you need the generated code itself because it
191 actually implements a very smart program transformation you found.
192 Maybe you want to use the generated code
193 because you know that the solution of your problem belongs to the integral
194 points of those damned polyhedra and you don't know which one. Maybe you just
195 want to know if a polyhedron has integral points depending on some parameters,
196 which is the lexicographic minimum, maximum, the third on the basis of the
197 left etc. Probably you have your own reasons to use CLooG.
199 Let us illustrate a basic use of CLooG. Suppose we have a set of affine
200 constraints that describes a part of a whatever-dimensional space,
201 called a @strong{domain}, and we
202 want to scan it. Let us consider for instance the following set of constraints
203 where @samp{i}
204 and @samp{j} are the unknown (the two dimensions of the space) and
205 @samp{m} and @samp{n} are the parameters (some symbolic constants):
206 @example
207 @group
208 2<=i<=n
209 2<=j<=m
210 j<=n+2-i
211 @end group
212 @end example
213 Let us also consider that we have a partial knowledge of the parameter values,
214 called the @strong{context}, expressed as affine constraints as well,
215 for instance:
216 @example
217 @group
218 m>=2
219 n>=2
220 @end group
221 @end example
222 Note that using parameters is optional, if you are not comfortable with
223 parameter manipulation, just replace them with any scalar value that fits
224 @code{m>=2} and @code{n>=2}.
225 A graphical representation of this part of the 2-dimensional space, where
226 the integral points are represented using heavy dots would be for instance:
228 @image{images/basic,6cm}
230 The affine constraints of both the domain and the context are what we will
231 provide to CLooG as input (in a particular shape that will be described later).
232 The output of CLooG is a pseudo-code to scan the integral points of the
233 input domain according to the context:
234 @example
235 @group
236 for (i=2;i<=n;i++) @{
237   for (j=2;j<=min(m,-i+n+2);j++) @{    
238     S1(i,j) ;
239   @}
241 @end group
242 @end example
243 If you felt such a basic example is yet interesting, there is a good chance
244 that CLooG is appropriate for you. CLooG can do much more: scanning several
245 polyhedra or unions of polyhedra at the same time, applying general affine
246 transformations to the polyhedra, generate compilable code etc. Welcome
247 to the CLooG's user's guide !
249 @node Scattering
250 @section Defining a Scanning Order: Scattering Functions
251 In CLooG, domains only define the set of integral points to scan and their
252 coordinates. In particular, CLooG is free to choose the scanning order for
253 generating the most efficient code. This means, for optimizing/parallelizing
254 compiler people, that CLooG doesn't make any speculation on dependences on and
255 between statements (by the way, it's not its job !).
256 For instance, if an user give to
257 CLooG only two domains @code{S1:1<=i<=n}, @code{S2:1<=i<=n} and the context
258 @code{n>=1}, the following pseudo-codes are considered to be equivalent:
260 @example
261 @group
262 /* A convenient target pseudo-code. */
263 for (i=1;i<=N;i++) @{
264  S1(i) ;
266 for (i=1;i<=N;i++) @{
267  S2(i) ;
269 @end group
270 @end example
272 @example
273 @group
274 /* Another convenient target pseudo-code. */
275 for (i=1;i<=N;i++) @{
276  S1(i) ;
277  S2(i) ;
279 @end group
280 @end example
282 The default behaviour
283 of CLooG is to generate the second one, since it is optimized in control. 
284 It is right if there are no data dependences
285 between @code{S1} and @code{S2}, but wrong otherwise. 
287 Thus it is often useful to force scanning to respect a given order. This can be
288 done in CLooG by using @strong{scattering functions}. Scattering is a
289 shortcut for scheduling, allocation, chunking functions and the like we can
290 find in the restructuring compilation literature. There are a lot of reasons
291 to scatter the integral points of the domains (i.e. the statement instances
292 of a program, for compilation people), parallelization or optimization are good
293 examples. For instance, if the user wants for any reason to set some
294 precedence constraints between the statements of our example above
295 in order to force the generation of the
296 first code, he can do it easily by setting (for example) the following
297 scheduling functions:
299 @tex
300 $$\theta _{S1}(i) =  (1)$$
301 $$\theta _{S2}(j) =  (2)$$
302 @end tex
304 @ifnottex
305 @example
306 @group
307 T_S1(i) = (1)
308 T_S2(j) = (2)
309 @end group
310 @end example
311 @end ifnottex
313 This scattering means that each integral point of the domain @code{S1}
314 is scanned at logical date @code{1} while each integral point of the domain
315 @code{S2} is scanned at logical date @code{2}. As a result, the whole
316 domain @code{S1} is scanned before domain @code{S2} and the first code in our
317 example is generated.
319 The user can set every kind of affine scanning order thanks to the
320 scattering functions. Each domain has its own scattering function and
321 each scattering function may be multi-dimensional. A multi-dimensional logical
322 date may be seen as classical date (year,month,day,hour,minute,etc.) where
323 the first dimensions are the most significant. Each scattering dimension
324 may depend linearly on the original dimensions (e.g., @code{i}), the
325 parameters (e.g., @code{n}) ans scalars (e.g., @code{2}).
327 A very useful example of multi-dimensional scattering functions is, for
328 compilation people, the scheduling of the original program.
329 The basic data to use for code generation are statement iteration domains.
330 As we saw, these data are not sufficient to rebuild the original
331 program (what is the ordering between instances of different statements ?).
332 The missing data can be put in the scattering functions as the original
333 scheduling. The method to compute it is quite simple (@pxref{Fea92}). The idea is to
334 build an abstract syntax tree of the program and to read the scheduling for
335 each statement. For instance, let us consider the following implementation of
336 a Cholesky factorization:
338 @example
339 @group
340 /* A Cholesky factorization kernel. */
341 for (i=1;i<=N;i++) @{
342   for (j=1;j<=i-1;j++) @{
343     a[i][i] -= a[i][j] ;           /* S1 */
344   @}
345   a[i][i] = sqrt(a[i][i]) ;        /* S2 */
346   for (j=i+1;j<=N;j++) @{
347     for (k=1;k<=i-1;k++) @{
348       a[j][i] -= a[j][k]*a[i][k] ; /* S3 */
349     @}
350     a[j][i] /= a[i][i] ;           /* S4 */
351     @}
352   @}
354 @end group
355 @end example
357 The corresponding abstract syntax tree is given in the following figure.
358 It directly gives the scattering functions (schedules) for all the
359 statements of the program.
361 @image{images/tree,6cm}
363 @tex
365 \hbox{$ \cases{ \theta _{S1}(i,j)^T    &$=  (0,i,0,j,0)^T$\cr
366                 \theta _{S2}(i)        &$=  (0,i,1)^T$\cr
367                 \theta _{S3}(i,j,k)^T  &$=  (0,i,2,j,0,k,0)^T$\cr
368                 \theta _{S4}(i,j)^T    &$=  (0,i,2,j,1)^T$}$}
370 @end tex
372 @ifnottex
373 @example
374 @group
375 T_S1(i,j)^T   = (0,i,0,j,0)^T
376 T_S2(i)       = (0,i,1)^T
377 T_S3(i,j,k)^T = (0,i,2,j,0,k,0)^T
378 T_S4(i,j)^T   = (0,i,2,j,1)^T
379 @end group
380 @end example
381 @end ifnottex
383 These schedules depend on the iterators and give for each instance of each
384 statement a unique execution date. Using such scattering functions allow
385 CLooG to re-generate the input code. 
391 @c %  ***********************Using the CLooG Software **************************
392 @node CLooG Software
393 @chapter Using the CLooG Software
396 @menu
397 * A First Example::
398 * Writing The Input File::
399 * Calling CLooG::
400 * CLooG Options::
401 * Full Example::
402 @end menu
404 @c %/*************************************************************************
405 @c % *                              A FIRST EXAMPLE                          *
406 @c % *************************************************************************/
407 @node A First Example
408 @section A First Example
409 CLooG takes as input a file that must be written accordingly to a grammar
410 described in depth in a further section (@pxref{Writing The Input File}). 
411 Moreover it supports many options to tune the target code presentation or
412 quality as discussed in a dedicated section (@pxref{Calling CLooG}).
413 However, a basic use
414 of CLooG is not very complex and we present in this section how to generate the
415 code corresponding to a basic example discussed earlier (@pxref{Basics}).
417 The problem is to find the code that scans a 2-dimensional polyhedron
418 where @samp{i} and @samp{j} are the unknown (the two dimensions of the space)
419 and @samp{m} and @samp{n} are the parameters (the symbolic constants),
420 defined by the following set of constraints:
421 @example
422 @group
423 2<=i<=n
424 2<=j<=m
425 j<=n+2-i
426 @end group
427 @end example
428 @noindent We also consider a partial knowledge of the parameter values,
429 expressed thanks to the following affine constraints:
430 @example
431 @group
432 m>=2
433 n>=2
434 @end group
435 @end example
437 An input file that corresponds to this problem, and asks for a generated
438 code in C, may be the following. Note that we do not describe here precisely
439 the structure and the components of this file (@pxref{Writing The Input File}
440  for such information, if you feel it necessary):
442 @example
443 # ---------------------- CONTEXT ----------------------
444 c # language is C
446 # Context (constraints on two parameters)
447 2 4                   # 2 lines and 4 columns
448 # eq/in m  n  1         eq/in: 1 for inequality >=0, 0 for equality =0
449     1   1  0 -2       # 1*m + 0*n -2*1 >= 0, i.e. m>=2
450     1   0  1 -2       # 0*m + 1*n -2*1 >= 0, i.e. n>=2
452 1 # We want to set manually the parameter names
453 m n                   # parameter names
455 # --------------------- STATEMENTS --------------------
456 1 # Number of statements
458 1 # First statement: one domain
459 # First domain
460 5 6                   # 5 lines and 6 columns
461 # eq/in i  j  m  n  1 
462     1   1  0  0  0 -2 # i >= 2
463     1  -1  0  0  1  0 # i <= n
464     1   0  1  0  0 -2 # j >= 2
465     1   0 -1  1  0  0 # j <= m
466     1  -1 -1  0  1  2 # n+2-i>=j
467 0  0  0               # for future options
469 1 # We want to set manually the iterator names
470 i j                   # iterator names
472 # --------------------- SCATTERING --------------------
473 0 # No scattering functions
474 @end example
476 This file may be called @samp{basic.cloog}
477 (this example is provided in the CLooG distribution as
478 @code{test/manual_basic.cloog}) and we can ask CLooG to process it
479 and to generate the code by a simple calling to CLooG with this file as input:
480 @samp{cloog basic.cloog}. By default, CLooG will print the generated code in
481 the standard output:
483 @example
484 @group
485 /* Generated by CLooG v@value{VERSION} in 0.00s. */
486 for (i=2;i<=n;i++) @{
487   for (j=2;j<=min(m,-i+n+2);j++) @{    
488     S1(i,j) ;
489   @}
491 @end group
492 @end example
494 @c %/*************************************************************************
495 @c % *                                Input file                             *
496 @c % *************************************************************************/
497 @node Writing The Input File
498 @section Writing The Input File
499 The input text file contains a problem description, i.e. the context,
500 the domains and the scattering functions.
501 Because CLooG is very 'compilable code generation oriented', we can associate
502 some additional informations to each domain. We call this association a
503 @emph{statement}. The set of all informations is 
504 called a @emph{program}. The input file respects the grammar below
505 (terminals are preceded by "_"):
507 @example
508 File             ::= Program
509 Program          ::= Context Statements Scattering
510 Context          ::= Language      Domain_union   Naming
511 Statements       ::= Nb_statements Statement_list Naming
512 Scatterings      ::= Nb_functions  Scattering_list Naming
513 Naming           ::= Option Name_list
514 Name_list        ::= _String   Name_list      | (void)
515 Statement_list   ::= Statement Statement_list | (void)
516 Domain_list      ::= _Domain   Domain_list    | (void)
517 Scattering_list  ::= Domain_union Scattering_list | (void)
518 Statement        ::= Iteration_domain 0 0 0
519 Iteration_domain ::= Domain_union
520 Domain_union     ::= Nb_domains Domain_list
521 Option           ::= 0 | 1
522 Language         ::= c | f
523 Nb_statements    ::= _Integer
524 Nb_domains       ::= _Integer
525 Nb_functions     ::= _Integer
526 @end example
528 Note: if there is only one domain in a @samp{Domain_union},
529 i.e., if @samp{Nb_domains} is 1, then this 1 may be omitted.
531 @itemize @bullet
532 @item  @samp{Context} represents the informations that are
533        shared by all the statements. It consists on
534        the language used (which can be @samp{c} for C or @samp{f} for FORTRAN 90)
535        and the global constraints on parameters.
536        These constraints are essential
537        since they give to CLooG the number of parameters. If there is no
538        parameter or no constraints on parameters, just give a constraint
539        always satisfied like @math{1 \geq 0}. @samp{Naming} sets the parameter
540        names.
541        If the naming option @samp{Option} is 1, parameter names will be read
542        on the next line. There must be exactly as many names as parameters.
543        If the naming option @samp{Option} is 0, parameter names are
544        automatically generated. The name of the first parameter will
545        be @samp{M}, and the name of the @math{(n+1)^{th}} parameter directly
546        follows the name of the @math{n^{th}} parameter in ASCII code.
547        It is the user responsibility to ensure that parameter names,
548        iterators and scattering dimension names are different. 
549 @item  @samp{Statements} represents the informations on the statements.
550        @samp{Nb_statements} is the number of statements in the program, 
551        i.e. the number of @samp{Statement} items in the @samp{Statement_list}.
552        @samp{Statement} represents the informations on a given statement.
553        To each statement is associated a domain
554        (the statement iteration domain: @samp{Iteration_domain}) and three
555        zeroes that represents future options.
556        @samp{Naming} sets the iterator names. If the naming option
557        @samp{Option} is 1, the iterator names
558        will be read on the next line. There must be exactly as many names as
559        nesting level in the deepest iteration domain. If the naming option
560        @samp{Option} is 0, iterator names are automatically generated.
561        The iterator name of the outermost loop will be @samp{i}, and the
562        iterator name of the loop at level @math{n+1} directly follows the 
563        iterator name of the loop at level @math{n} in ASCII code. 
564 @item  @samp{Scatterings} represents the informations on scattering functions.
565        @samp{Nb_functions} is the number of functions (it must be
566        equal to the number of statements or 0 if there is no scattering
567        function). The functions themselves are represented through
568        @samp{Scattering_list}.
569        @samp{Naming} sets the scattering dimension names. If the naming option
570        @samp{Option} is 1, the scattering dimension names will be read on the
571        next line.
572        There must be exactly as many names as scattering dimensions. If the
573        naming option @samp{Option} is 0, scattering dimension names are automatically
574        generated. The name of the @math{n^{th}} scattering dimension
575        will be @samp{cn}.
576 @end itemize
578 @menu
579 * Domain Representation::
580 * Scattering Representation::
581 @end menu
583 @node Domain Representation
584 @subsection Domain Representation
585 As shown by the grammar, the input file describes the various informations
586 thanks to characters, integers and domains. Each domain is defined by a set of
587 constraints in the PolyLib format (@pxref{Wil93}). They have the
588 following syntax:
589 @enumerate
590 @item some optional comment lines beginning with @samp{#},
591 @item the row and column numbers, possibly followed by comments,
592 @item the constraint rows, each row corresponds to a constraint the
593       domain have to satisfy. Each row must be on a single line and is possibly
594       followed by comments. The constraint is an equality @math{p(x) = 0} if the
595       first element is 0, an inequality  @math{p(x) \geq 0} if the first element
596       is 1. The next elements are the unknown coefficients, followed by
597       the parameter coefficients. The last element is the constant factor.
598 @end enumerate
599 For instance, assuming that @samp{i}, @samp{j} and @samp{k} are iterators and
600 @samp{m} and @samp{n} are parameters, the domain defined by the following
601 constraints :
603 @tex
605 \hbox{$ \cases{ -i     + m &$\geq 0$\cr
606                     -j + n &$\geq 0$\cr
607                  i + j - k &$\geq 0$}$}
609 @end tex
611 @ifnottex
612 @example
613 @group
614    -i + m >= 0
615    -j + n >= 0
616 i + j - k >= 0
617 @end group
618 @end example
619 @end ifnottex
621 @noindent can be written in the input file as follows :
623 @example
624 @group
625 # This is the domain
626 3 7                      # 3 lines and 7 columns
627 # eq/in i  j  k  m  n  1 
628     1  -1  0  0  1  0  0 #    -i + m >= 0
629     1   0 -1  0  0  1  0 #    -j + n >= 0
630     1   1  1 -1  0  0  0 # i + j - k >= 0
631 @end group
632 @end example
634 Each iteration domain @samp{Iteration_domain} of a given statement
635 is a union of polyhedra
636 @samp{Domain_union}. A union is defined by its number of elements
637 @samp{Nb_domains} and the elements themselves @samp{Domain_list}.
638 For instance, let us consider the following pseudo-code:
640 @example
641 @group
642 for (i=1;i<=n;i++) @{
643   if ((i >= m) || (i <= 2*m))
644     S1 ;
645   for (j=i+1;j<=m;j++)
646     S2 ;
647 @} 
648 @end group
649 @end example
651 @noindent The iteration domain of @samp{S1} can be divided into two
652 polyhedra and written in the input file as follows:
654 @example
655 @group
656 2 # Number of polyhedra in the union
657 # First domain
658 3 5                # 3 lines and 5 columns
659 # eq/in i  m  n  1 
660     1   1  0  0 -1 #  i >= 1
661     1  -1  0  1  0 #  i <= n
662     1   1 -1  0  0 #  i >= m
663 # Second domain
664 3 5                # 3 lines and 5 columns
665 # eq/in i  m  n  1 
666     1   1  0  0 -1 #  i >= 1
667     1  -1  0  1  0 #  i <= n
668     1  -1  2  0  0 #  i <= 2*m
669 @end group
670 @end example
672 @node Scattering Representation
673 @subsection Scattering Function Representation
674 Scattering functions are depicted in the input file thanks a representation
675 very close to the domain one.
676 An integer gives the number of functions @samp{Nb_functions} and each function
677 is represented by a domain. Each line of the domain corresponds to an equality
678 defining a dimension of the function. Note that at present
679 (CLooG @value{VERSION})
680 @strong{all functions must have the same scattering dimension number}. If a
681 user wants to set scattering functions with different dimensionality, he has
682 to complete the smaller one with zeroes to reach the maximum dimensionality.
683 For instance, let us consider the following code and
684 scheduling functions:
686 @example
687 @group
688 for (i=1;i<=n;i++) @{
689   if ((i >= m) || (i <= 2*m))
690     S1 ;
691   for (j=i+1;j<=m;j++)
692     S2 ;
693 @} 
694 @end group
695 @end example
697 @tex
699 \hbox{$ \cases{ \theta _{S1}(i)      &$=  (i,0)^T$\cr
700                 \theta _{S2}(i,j)^T  &$=  (n,i+j)^T$}$}
702 @end tex
704 @ifnottex
705 @example
706 @group
707 T_S1(i)     = (i,0)^T
708 T_S2(i,j)^T = (n,i+j)^T
709 @end group
710 @end example
711 @end ifnottex
714 @noindent This scheduling can be written in the input file as follows:
716 @example
717 @group
718 2 # Number of scattering functions
719 # First function
720 2 7                          # 2 lines and 7 columns
721 # eq/in c1 c2  i  m  n  1 
722     0    1  0 -1  0  0  0    #  c1 = i
723     0    0  1  0  0  0  0    #  c2 = 0
724 # Second function
725 2 8                          # 2 lines and 8 columns
726 # eq/in c1 c2  i  j  m  n  1 
727     0    1  0  0  0  0 -1  0 #  c1 = n
728     0    0  1 -1 -1  0  0  0 #  c2 = i+j
729 @end group
730 @end example
731 The complete input file for the user who wants to generate the code for this
732 example with the preceding scheduling would be
733 (this file is provided in the CLooG distribution
734 as @code{test/manual_scattering.cloog}:
736 @example
737 # ---------------------- CONTEXT ----------------------
738 c # language is C
740 # Context (no constraints on two parameters)
741 1 4                   # 1 lines and 4 columns
742 # eq/in m  n  1
743     1   0  0  0       # 0 >= 0, always true
745 1 # We want to set manually the parameter names
746 m n                   # parameter names
748 # --------------------- STATEMENTS --------------------
749 2 # Number of statements
751 2 # First statement: two domains
752 # First domain
753 3 5                   # 3 lines and 5 columns
754 # eq/in i  m  n  1
755     1   1  0  0 -1    # i >= 1
756     1  -1  0  1  0    # i <= n
757     1   1 -1  0  0    # i >= m
758 # Second domain
759 3 5                   # 3 lines and 5 columns
760 # eq/in i  m  n  1 
761     1   1  0  0 -1    # i >= 1
762     1  -1  0  1  0    # i <= n
763     1  -1  2  0  0    # i <= 2*m
764 0  0  0               # for future options
766 1 # Second statement: one domain
767 4 6                   # 4 lines and 6 columns
768 # eq/in i  j  m  n  1 
769     1   1  0  0  0 -1 # i >= 1
770     1  -1  0  0  1  0 # i <= n
771     1  -1  1  0  0 -1 # j >= i+1
772     1   0 -1  1  0  0 # j <= m
773 0  0  0               # for future options
775 1 # We want to set manually the iterator names
776 i j                   # iterator names
778 # --------------------- SCATTERING --------------------
779 2 # Scattering functions
780 # First function
781 2 7                   # 2 lines and 7 columns
782 # eq/in p1 p2  i  m  n  1 
783     0    1  0 -1  0  0  0    # p1 = i
784     0    0  1  0  0  0  0    # p2 = 0
785 # Second function
786 2 8                   # 2 lines and 8 columns
787 # eq/in p1 p2  i  j  m  n  1 
788     0    1  0  0  0  0 -1  0 # p1 = n
789     0    0  1 -1 -1  0  0  0 # p2 = i+j
791 1 # We want to set manually the scattering dimension names
792 p1 p2                 # scattering dimension names
793 @end example
796 @c %/*************************************************************************
797 @c % *                             Calling CLooG                             *
798 @c % *************************************************************************/
799 @node Calling CLooG
800 @section Calling CLooG
801 CLooG is called by the following command:
802 @example
803        cloog [ options | file ]
804 @end example
805 The default behavior of CLooG is to read the input informations from a file and
806 to print the generated code or pseudo-code on the standard output.
807 CLooG's behavior and the output code shape is under the user control thanks
808 to many options which are detailed a further section (@pxref{CLooG Options}).
809 @code{file} is the input file. @code{stdin} is a special value: when used,
810 input is standard input. For instance, we can call CLooG to treat the
811 input file @code{basic.cloog} with default options by typing:
812 @code{cloog basic.cloog} or @code{more basic.cloog | cloog stdin}.
814 @c %/*************************************************************************
815 @c % *                             CLooG Options                             *
816 @c % *************************************************************************/
817 @node CLooG Options
818 @section CLooG Options
820 @menu
821 * Last Depth to Optimize Control::
822 * First Depth to Optimize Control::
823 * Statement-wise First and Last Depths to Optimize Control
824 * Simplify Convex Hull::
825 * Once Time Loop Elimination::
826 * Equality Spreading::
827 * First Level for Spreading::
828 * Statement Block::
829 * Loop Strides::
830 * Unrolling::
831 * Compilable Code::
832 * Output::
833 * OpenScop::
834 * Help::
835 * Version ::
836 * Quiet ::
837 @end menu
839 @node Last Depth to Optimize Control
840 @subsection Last Depth to Optimize Control @code{-l <depth>}
842 @code{-l <depth>}: this option sets the last loop depth to be optimized in
843 control. The higher this depth, the less control overhead.
844 For instance, with some input file, a user can generate
845 different pseudo-codes with different @code{depth} values as shown below.
846 @example
847 @group
848 /* Generated using a given input file and @strong{option -l 1} */
849 for (i=0;i<=M;i++) @{
850   S1 ;
851   for (j=0;j<=N;j++) @{
852     S2 ;
853   @}
854   for (j=0;j<=N;j++) @{
855     S3 ;
856   @}
857   S4 ;
859 @end group
860 @end example
861 @example
862 @group
863 /* Generated using the same input file but @strong{option -l 2} */
864 for (i=0;i<=M;i++) @{
865   S1 ;
866   for (j=0;j<=N;j++) @{
867     S2 ;
868     S3 ;
869   @}
870   S4 ;
872 @end group
873 @end example
874      In this example we can see that this option can change the operation
875      execution order between statements. Let us remind that CLooG does not
876      make any speculation on dependences between statements
877      (@pxref{Scattering}). Thus if nothing (i.e. scattering functions)
878      forbids this, CLooG considers the above codes to be equivalent.
879      If there is no scattering functions, the minimum value for @code{depth}
880      is 1 (in the case of 0, the user doesn't really need a loop generator !),
881      and the number of scattering dimensions otherwise (CLooG will warn the
882      user if he doesn't respect such constraint).
883      The maximum value for depth is -1 (infinity).
884      Default value is infinity.
886 @node First Depth to Optimize Control
887 @subsection First Depth to Optimize Control @code{-f <depth>}
889      @code{-f <depth>}: this option sets the first loop depth to be optimized
890      in control. The lower this depth, the less control overhead (and the longer
891      the generated code). For instance, with some input file, a user
892      can generate different pseudo-codes with different @code{depth} values
893      as shown below.
894      The minimum value for @code{depth} is 1, and the
895      maximum value is -1 (infinity).
896      Default value is 1.
897 @example
898 @group
899 /* Generated using a given input file and @strong{option -f 3} */
900 for (i=1;i<=N;i++) @{
901   for (j=1;j<=M;j++) @{
902     S1 ;
903     if (j >= 10) @{
904       S2 ;
905     @}
906   @}
908 @end group
909 @end example
910 @example
911 @group
912 /* Generated using the same input file but @strong{option -f 2} */
913 for (i=1;i<=N;i++) @{
914   for (j=1;j<=9;j++) @{
915     S1 ;
916   @}
917   for (j=10;j<=M;j++) @{
918     S1 ;
919     S2 ;
920   @}
922 @end group
923 @end example
925 @node Statement-wise First and Last Depths to Optimize Control
926 @subsection Statement-wise First and Last Depths to Optimize Control @code{options->fs, options->ls}
928 option->f/l (command-line arguments: -f and -l) provide first and last levels to optimize
929 control overhead at a global level (across the entire program / all statements)
930 by separating / splitting loops. option->fs/ls allow the equivalent of setting
931 -f/-l options on a statement-wise basis. Integer arrays options->fs, options->ls should
932 be allocated by the user with options->fs_ls_size set to the number of elements (always equal
933 to the number of statements).  For any
934 given loop, the first and last depths of all statements under it are looked at
935 to determine if the loop should be separated (max across all fs' and ls' is
936 taken). A user has to set fs meaningfully, i.e., for eg., if two statements i &
937 j have a fused loop and fs[i], fs[j] specify separation for that level for stmt
938 i but not for stmt j, the input is ambiguous and we will in this case not
939 separate (since a max is taken). options->fs/ls override f/l; if fs/ls are not
940 set or are set inconsistently (max across ls[i] < max across fs[i]), f/l take
941 over.
943 fs/ls can only be set via the library interface for now.
945 @node Simple Convex Hull
946 @subsection  Simple Convex Hull @code{-sh <boolean>}
948      @code{-sh <boolean>}: this option enables (@code{boolean=1})
949      or forbids (@code{boolean=0}) the use of an overapproximation
950      of the convex hull that may be easier to compute
951      (especially in the isl backend) and that may result in
952      simpler bounds.
953      This option works only for generated code without
954      code duplication (it means, you have to tune @code{-f} and
955      @code{-l} options first to generate only a loop nest with internal
956      guards). For instance, with the input file @code{test/union.cloog}, a user
957      can generate different pseudo-codes  as shown below.
958      Default value is 0.
959 @example
960 @group
961 /* Generated using test/union.cloog and @strong{option -f -1 -l 2 -override} */
962 for (i=0;i<=11;i++) @{
963   for (j=max(0,5*i-50);j<=min(15,5*i+10);j++) @{
964     if ((i <= 10) && (j <= 10)) @{
965       S1 ;
966     @}
967     if ((i >= 1) && (j >= 5)) @{
968       S2 ;
969     @}
970   @}
972 @end group
973 @end example
974 @example
975 @group
976 /* Generated using the same input file but @strong{option -sh 1 -f -1 -l 2 -override} */
977 for (i=0;i<=11;i++) @{
978   for (j=0;j<=15;j++) @{
979     if ((i <= 10) && (j <= 10)) @{
980       S1 ;
981     @}
982     if ((i >= 1) && (j >= 5)) @{
983       S2 ;
984     @}
985   @}
987 @end group
988 @end example
990 @node Once Time Loop Elimination
991 @subsection Once Time Loop Elimination @code{-otl <boolean>}
993      @code{-otl <boolean>}: this option allows (@code{boolean=1}) or
994      forbids (@code{boolean=0}) the simplification of loops running
995      once. Default value is 1.
996 @example
997 @group
998 /* Generated using a given input file and @strong{option -otl 0} */
999 for (j=i+1;j<=i+1;j++) @{
1000   S1 ;
1002 @end group
1003 @end example
1004 @example
1005 @group
1006 /* Generated using the same input file but @strong{option -otl 1} */
1007 j = i+1 ;
1008 S1 ;
1009 @end group
1010 @end example
1013 @node Equality Spreading 
1014 @subsection Equality Spreading @code{-esp <boolean>}
1016      @code{-esp <boolean>}: this option allows (@code{boolean=1}) or
1017      forbids (@code{boolean=0}) values spreading when there
1018      are equalities. Default value is 1.
1019 @example
1020 @group
1021 /* Generated using a given input file and @strong{option -esp 0} */
1022 i = M+2 ;
1023 j = N ;
1024 for (k=i;k<=j+M;k++) @{
1025   S1 ;
1027 @end group
1028 @end example
1029 @example
1030 @group
1031 /* Generated using the same input file but @strong{option -esp 1} */
1032 for (k=M+2;k<=N+M;k++) @{
1033   S1(i = M+2, j = N) ;
1035 @end group
1036 @end example
1039 @node First Level for Spreading 
1040 @subsection First Level for Spreading @code{-fsp <level>}
1042      @code{-fsp <level>}: it can be useful to set a
1043      first level to begin equality spreading. Particularly when using
1044      scattering functions, the user may want to see the scattering dimension
1045      values instead of spreading or hiding them. If user has set a
1046      spreading, @code{level} is
1047      the first level to start it. Default value is 1.
1048 @example
1049 @group
1050 /* Generated using a given input file and @strong{option -fsp 1} */
1051 for (j=0;j<=N+M;j++) @{
1052   S1(i = N) ;
1054 for (j=0;j<=N+M;j++) @{
1055   S1(i = M) ;
1057 @end group
1058 @end example
1059 @example
1060 @group
1061 /* Generated using the same input file but @strong{option -fsp 2} */
1062 c1 = N ;
1063 for (j=0;j<=c1+M;j++) @{
1064   S1(i = c1) ;
1066 c1 = M ;
1067 for (j=0;j<=N+c1;j++) @{
1068   S1(i = c1) ;
1070 @end group
1071 @end example
1074 @node Statement Block  
1075 @subsection Statement Block @code{-block <boolean>}
1077      @code{-block <boolean>}: this option allows (@code{boolean=1}) to
1078      create a statement block for each new iterator, even if there is only
1079      an equality. This can be useful in order to parse the generated
1080      pseudo-code. When @code{boolean} is set to 0 or when the generation
1081      language is FORTRAN, this feature is disabled. Default value is 0.
1082 @example
1083 @group
1084 /* Generated using a given input file and @strong{option -block 0} */
1085 i = M+2 ;
1086 j = N ;
1087 S1 ;
1088 @end group
1089 @end example
1090 @example
1091 @group
1092 /* Generated using the same input file but @strong{option -block 1} */
1093 @{ i = M+2 ;
1094   @{ j = N ;
1095     S1 ;
1096   @}
1098 @end group
1099 @end example
1102 @node Loop Strides 
1103 @subsection Loop Strides @code{-strides <boolean>}
1105      @code{-strides <boolean>}: this options allows (@code{boolean=1}) to
1106      handle non-unit strides for loop increments. This can remove a lot of
1107      guards and make the generated code more efficient. Default value is 0.
1108 @example
1109 @group
1110 /* Generated using a given input file and @strong{option -strides 0} */
1111 for (i=1;i<=n;i++) @{
1112   if (i%2 == 0) @{
1113     S1(j = i/2) ;
1114   @}
1115   if (i%4 == 0) @{
1116     S2(j = i/4) ;
1117   @}
1119 @end group
1120 @end example
1121 @example
1122 @group
1123 /* Generated using the same input file but @strong{option -strides 1} */
1124 for (i=2;i<=n;i+=2) @{
1125   S1(j = i/2) ;
1126   if (i%4 == 0) @{
1127     S2(j = i/4) ;
1128   @}
1130 @end group
1131 @end example
1134 @node Unrolling
1135 @subsection First Depth to Unroll @code{-first-unroll <depth>}
1137     @code{-first-unroll <depth>}: this option sets the first loop depth
1138     to unroll.  Note that a loop is only unrolled when it is supported
1139     by the backend.  In case of the isl backend, a loop is unrolled
1140     if it has a lower bound that can only be incremented
1141     a fixed (non-parametric) amount of times.
1144 @node Compilable Code
1145 @subsection Compilable Code @code{-compilable <value>}
1147      @code{-compilable <value>}: this options allows (@code{value} is not 0)
1148      to generate a compilable code where all parameters have the integral value
1149      @code{value}. This option creates a macro for each statement. Since
1150      CLooG do not know anything about the statement sources, it fills the
1151      macros with a basic increment that computes the total number of
1152      scanned integral points. The user may change easily the macros according
1153      to his own needs. This option is possible only if the generated code is
1154      in C. Default value is 0.
1155 @example
1156 @group
1157 /* Generated using a given input file and @strong{option -compilable 0} */
1158 for (i=0;i<=n;i++) @{
1159   for (j=0;j<=n;j++) @{
1160     S1 ;
1161     S2 ;
1162   @}
1163   S3 ;
1165 @end group
1166 @end example
1167 @example
1168 /* Generated using the same input file but @strong{option -compilable 10} */
1169 /* DON'T FORGET TO USE -lm OPTION TO COMPILE. */
1171 /* Useful headers. */
1172 #include <stdio.h>
1173 #include <stdlib.h>
1174 #include <math.h>
1176 /* Parameter value. */
1177 #define PARVAL 10
1179 /* Statement macros (please set). */
1180 #define S1(i,j) @{total++;@}
1181 #define S2(i,j) @{total++;@}
1182 #define S3(i)   @{total++;@}
1184 int main() @{
1185   /* Original iterators. */
1186   int i, j ;
1187   /* Parameters. */
1188   int n=PARVAL, total=0 ;
1190   for (i=0;i<=n;i++) @{
1191     for (j=0;j<=n;j++) @{
1192       S1(i,j) ;
1193       S2(i,j) ;
1194     @}
1195     S3(i) ;
1196   @}
1198   printf("Number of integral points: %d.\n",total) ;
1199   return 0 ;
1201 @end example
1203 @node Callable Code
1204 @subsection Callable Code @code{-callable <boolean>}
1206      @code{-callable <boolean>}: if @code{boolean=1}, then a @code{test}
1207      function will be generated that has the parameters as arguments.
1208      Similarly to the @code{-compilable} option,
1209      a macro for each statement is generated.  The generated definitions of
1210      these macros are as used during the correctness testing, but they
1211      can easily be changed by the user to suit her own needs.
1212      This option is only available if the target language is C.
1213      The default value is 0.
1215 @example
1216 /* Generated from double.cloog with @strong{option -callable 0} */
1217 for (i=0;i<=M;i++) @{
1218   S1 ;
1219   for (j=0;j<=N;j++) @{
1220     S2 ;
1221     S3 ;
1222   @}
1223   S4 ;
1225 @end example
1226 @example
1227 /* Generated from double.cloog with @strong{option -callable 1} */
1228 extern void hash(int);
1230 /* Useful macros. */
1231 #define floord(n,d) (((n)<0) ? ((n)-(d)+1)/(d) : (n)/(d))
1232 #define ceild(n,d)  (((n)<0) ? (n)/(d) : ((n)+(d)+1)/(d))
1233 #define max(x,y)    ((x) > (y) ? (x) : (y))
1234 #define min(x,y)    ((x) < (y) ? (x) : (y))
1236 #define S1(i) @{ hash(1); hash(i); @}
1237 #define S2(i,j) @{ hash(2); hash(i); hash(j); @}
1238 #define S3(i,j) @{ hash(3); hash(i); hash(j); @}
1239 #define S4(i) @{ hash(4); hash(i); @}
1241 void test(int M, int N)
1243   /* Original iterators. */
1244   int i, j;
1245   for (i=0;i<=M;i++) @{
1246     S1(i) ;
1247     for (j=0;j<=N;j++) @{
1248       S2(i,j) ;
1249       S3(i,j) ;
1250     @}
1251     S4(i) ;
1252   @}
1254 @end example
1256 @node Output
1257 @subsection Output @code{-o <output>}
1259      @code{-o <output>}: this option sets the output file. @code{stdout} is a
1260      special value: when used, output is standard output.
1261      Default value is @code{stdout}.
1263 @node OpenScop
1264 @subsection OpenScop @code{-openscop}
1266      @code{-openscop}: this option states that the input file complies to
1267      the OpenScop specification instead of the native file format
1268      (@pxref{Bas11}). This option is available only if the OpenScop
1269      support has been enabled at compile time (@pxref{Optional Features}).
1270      The following OpenScop extensions are supported by CLooG
1271      (for the details about those extensions, @pxref{Bas11}):
1272      @itemize @bullet
1273      @item @emph{scatnames} to set the scattering dimension names.
1274      @item @emph{coordinates} to inject the generated code at the
1275            place of a given SCoP in a given file. The use of
1276            this extension is disabled when the options
1277            @emph{-compilable} or @emph{-callable} are set.
1278      @item @emph{loop} to add loop decorations such as OpenMP
1279            or vectorization pragmas.
1280      @end itemize
1282 @node Help
1283 @subsection Help @code{--help} or @code{-h}
1285      @code{--help} or @code{-h}: this option ask CLooG to print a short help.
1287 @node Version
1288 @subsection Version @code{--version} or @code{-v}
1290      @code{--version} or @code{-v}: this option ask CLooG to print some version
1291      informations.
1293 @node Quiet
1294 @subsection Quiet @code{--quiet} or @code{-q}
1296      @code{--quiet} or @code{-q}: this option tells CLooG not to print
1297      any informational messages.
1300 @c %/*************************************************************************
1301 @c % *                           A Full Example                              *
1302 @c % *************************************************************************/
1303 @node Full Example
1304 @section A Full Example
1306 Let us consider the allocation problem of a Gaussian elimination, i.e. we want
1307 to distribute the various statement instances of the compute kernel onto
1308 different processors. The original code is the following:
1309 @example
1310 @group
1311 for (i=1;j<=N-1;i++) @{
1312   for (j=i+1;j<=N;j++) @{
1313     c[i][j] = a[j][i]/a[i][i] ;    /* S1 */
1314     for (k=i+1;k<=N;k++) @{
1315       a[j][k] -= c[i][j]*a[i][k] ; /* S2 */
1316     @}
1317   @}
1319 @end group
1320 @end example
1322 @noindent The best affine allocation functions can be found by any good automatic
1323 parallelizer like LooPo (@pxref{Gri04}):
1325 @tex
1327 \hbox{$ \cases{ \theta _{S1}(i,j)^T    &$=  (i)$\cr
1328                 \theta _{S2}(i,j,k)^T  &$=  (k)$}$}
1330 @end tex
1332 @ifnottex
1333 @example
1334 @group
1335 T_S1(i,j)^T   = (i)
1336 T_S2(i,j,k)^T = (k)
1337 @end group
1338 @end example
1339 @end ifnottex
1341 @noindent To ensure that on each processor, the set of statement instances is
1342 executed according to the original ordering, we add as minor scattering
1343 dimensions the original scheduling (@pxref{Scattering}):
1345 @tex
1347 \hbox{$ \cases{ \theta _{S1}(i,j)^T    &$=  (i,0,i,0,j,0)^T$\cr
1348                 \theta _{S2}(i,j,k)^T  &$=  (k,0,i,0,j,1,k,0)^T$}$}
1350 @end tex
1352 @ifnottex
1353 @example
1354 @group
1355 T_S1(i,j)^T   = (i,0,i,0,j,0)^T
1356 T_S2(i,j,k)^T = (k,0,i,0,j,1,k,0)^T
1357 @end group
1358 @end example
1359 @end ifnottex
1361 @noindent To ensure that the scattering functions have the same dimensionality, we
1362 complete the first function with zeroes
1363 (this is a CLooG @value{VERSION} and previous versions requirement,
1364 it should be removed in a future version, don't worry it's absolutely legal !):
1366 @tex
1368 \hbox{$ \cases{ \theta _{S1}(i,j)^T    &$=  (i,0,i,0,j,0,0,0)^T$\cr
1369                 \theta _{S2}(i,j,k)^T  &$=  (k,0,i,0,j,1,k,0)^T$}$}
1371 @end tex
1373 @ifnottex
1374 @example
1375 @group
1376 T_S1(i,j)^T   = (i,0,i,0,j,0,0,0)^T
1377 T_S2(i,j,k)^T = (k,0,i,0,j,1,k,0)^T
1378 @end group
1379 @end example
1380 @end ifnottex
1382 @noindent The input file corresponding to this code generation problem
1383 could be (this file is provided in the CLooG distribution
1384 as @code{test/manual_gauss.cloog}:
1386 @example
1387 # ---------------------- CONTEXT ----------------------
1388 c # language is C
1390 # Context (no constraints on one parameter)
1391 1 3                     # 1 line and 3 columns    
1392 # eq/in n  1
1393     1   0  0            # 0 >= 0, always true
1395 1 # We want to set manually the parameter name
1396 n                       # parameter name
1398 # --------------------- STATEMENTS --------------------
1399 2 # Number of statements
1401 1 # First statement: one domain
1402 4 5                     # 4 lines and 3 columns
1403 # eq/in i  j  n  1
1404     1   1  0  0 -1      # i >= 1
1405     1  -1  0  1 -1      # i <= n-1
1406     1  -1  1  0 -1      # j >= i+1
1407     1   0 -1  1  0      # j <= n
1408 0  0  0                 # for future options
1411 # Second statement: one domain
1412 6 6                     # 6 lines and 3 columns
1413 # eq/in i  j  k  n  1
1414     1   1  0  0  0 -1   # i >= 1
1415     1  -1  0  0  1 -1   # i <= n-1
1416     1  -1  1  0  0 -1   # j >= i+1
1417     1   0 -1  0  1  0   # j <= n
1418     1  -1  0  1  0 -1   # k >= i+1
1419     1   0  0 -1  1  0   # k <= n
1420 0  0  0                 # for future options
1422 0 # We let CLooG set the iterator names
1424 # --------------------- SCATTERING --------------------
1425 2 # Scattering functions
1426 # First function
1427 8 13                    # 3 lines and 3 columns
1428 # eq/in p1 p2 p3 p4 p5 p6 p7 p8  i  j  n  1
1429     0    1  0  0  0  0  0  0  0 -1  0  0  0     # p1 = i
1430     0    0  1  0  0  0  0  0  0  0  0  0  0     # p2 = 0
1431     0    0  0  1  0  0  0  0  0 -1  0  0  0     # p3 = i
1432     0    0  0  0  1  0  0  0  0  0  0  0  0     # p4 = 0
1433     0    0  0  0  0  1  0  0  0  0 -1  0  0     # p5 = j
1434     0    0  0  0  0  0  1  0  0  0  0  0  0     # p6 = 0
1435     0    0  0  0  0  0  0  1  0  0  0  0  0     # p7 = 0
1436     0    0  0  0  0  0  0  0  1  0  0  0  0     # p8 = 0
1437 # Second function
1438 8 14                    # 3 lines and 3 columns
1439 # eq/in p1 p2 p3 p4 p5 p6 p7 p8  i  j  k  n  1
1440     0    1  0  0  0  0  0  0  0  0  0 -1  0  0  # p1 = k
1441     0    0  1  0  0  0  0  0  0  0  0  0  0  0  # p2 = 0
1442     0    0  0  1  0  0  0  0  0 -1  0  0  0  0  # p3 = i
1443     0    0  0  0  1  0  0  0  0  0  0  0  0  0  # p4 = 0
1444     0    0  0  0  0  1  0  0  0  0 -1  0  0  0  # p5 = j
1445     0    0  0  0  0  0  1  0  0  0  0  0  0 -1  # p6 = 1
1446     0    0  0  0  0  0  0  1  0  0  0 -1  0  0  # p7 = k
1447     0    0  0  0  0  0  0  0  1  0  0  0  0  0  # p8 = 0
1449 1 # We want to set manually the scattering dimension names
1450 p1 p2 p3 p4 p5 p6 p7 p8 # scattering dimension names
1451 @end example
1453 Calling CLooG, with for instance the command line
1454 @code{cloog -fsp 2 gauss.cloog} for a better view
1455 of the allocation (the processor number is given by @code{p1}),
1456 will result on the following target code that actually implements
1457 the transformation. A minor processing on the dimension @code{p1}
1458 to implement, e.g., MPI calls, which is not shown here may
1459 result in dramatic speedups !
1461 @example
1462 if (n >= 2) @{
1463   p1 = 1 ;
1464   for (p5=2;p5<=n;p5++) @{
1465     S1(i = 1,j = p5) ;
1466   @}
1468 for (p1=2;p1<=n-1;p1++) @{
1469   for (p3=1;p3<=p1-1;p3++) @{
1470     for (p5=p3+1;p5<=n;p5++) @{
1471       S2(i = p3,j = p5,k = p1) ;
1472     @}
1473   @}
1474   for (p5=p1+1;p5<=n;p5++) @{
1475     S1(i = p1,j = p5) ;
1476   @}
1478 if (n >= 2) @{
1479   p1 = n ;
1480   for (p3=1;p3<=n-1;p3++) @{
1481     for (p5=p3+1;p5<=n;p5++) @{
1482       S2(i = p3,j = p5,k = n) ;
1483     @}
1484   @}
1486 @end example
1489 @c %/*************************************************************************
1490 @c % *                           A Full Example                              *
1491 @c % *************************************************************************/
1492 @node CLooG Library
1493 @chapter Using the CLooG Library
1494 The CLooG Library was implemented to allow the user to call CLooG
1495 directly from his programs, without file accesses or system calls. The
1496 user only needs to link his programs with C libraries. The CLooG
1497 library mainly provides one function (@code{cloog_clast_create_from_input})
1498 which takes as input the problem
1499 description with some options, and returns the data structure corresponding
1500 to the generated code (a @code{struct clast_stmt} structure)
1501 which is more or less an abstract syntax tree.
1502 The user can work with this data structure and/or use
1503 our pretty printing function to write the final code in either C or FORTRAN.
1504 Some other functions are provided for convenience reasons.
1505 These functions as well as the data structures are described in this section.
1507 @menu
1508 * CLooG Data Structures::
1509 * CLooG Output::
1510 * Retrieving version information::
1511 * Example of Library Utilization::
1512 @end menu
1515 @node CLooG Data Structures
1516 @section CLooG Data Structures Description
1517 In this section, we describe the data structures used by the loop
1518 generator to represent and to process a code generation problem.
1520 @menu
1521 * CloogState::
1522 * CloogMatrix::
1523 * CloogDomain::
1524 * CloogScattering::
1525 * CloogUnionDomain::
1526 * CloogStatement::
1527 * CloogOptions::
1528 * CloogInput::
1529 @end menu
1532 @node CloogState
1533 @subsection CloogState
1534 @example
1535 @group
1536 CloogState *cloog_state_malloc(void);
1537 void cloog_state_free(CloogState *state);
1538 @end group
1539 @end example
1541 @noindent The @code{CloogState} structure is (implicitly) needed to perform
1542 any CLooG operation.  It should be created using @code{cloog_state_malloc}
1543 before any other CLooG objects are created and destroyed using
1544 @code{cloog_state_free} after all objects have been freed.
1545 It is allowed to use more than one @code{CloogState} structure at
1546 the same time, but an object created within the state of a one
1547 @code{CloogState} structure is not allowed to interact with an object
1548 created within the state of an other @code{CloogState} structure.
1550 @menu
1551 * CloogState/isl::
1552 @end menu
1554 @node CloogState/isl
1555 @subsubsection isl
1557 @example
1558 #include <cloog/isl/cloog.h>
1559 CloogState *cloog_isl_state_malloc(isl_ctx *ctx);
1560 @end example
1562 @noindent
1563 When using the isl backend, CLooG will internally create many isl objects.
1564 If the user creates any CLooG objects from isl objects (e.g.,
1565 through @code{cloog_domain_from_isl_set} below), then the user needs
1566 to make sure that these isl objects live in the same @code{isl_ctx}
1567 as those created by CLooG internally.  The best way to ensure this
1568 property is to pass the @code{isl_ctx} created by the user to CLooG
1569 by calling @code{cloog_isl_state_malloc} to create a @code{CloogState}.
1570 Note that this makes the created @code{CloogState} a user of the
1571 given @code{isl_ctx}, meaning that the @code{CloogState} needs to
1572 be freed before the @code{isl_ctx} is freed.
1575 @node CloogMatrix
1576 @subsection CloogMatrix
1578 @noindent The @code{CloogMatrix} structure is equivalent to the PolyLib
1579 @code{Matrix} data structure (@pxref{Wil93}). This structure is devoted to
1580 represent a set of constraints.
1582 @example
1583 @group
1584 struct cloogmatrix
1585 @{ unsigned NbRows ;    /* Number of rows. */
1586   unsigned NbColumns ; /* Number of columns. */
1587   cloog_int_t **p;     /* Array of pointers to the matrix rows. */
1588   cloog_int_t *p_Init; /* Matrix rows contiguously in memory. */
1590 typedef struct cloogmatrix CloogMatrix;
1592 CloogMatrix *cloog_matrix_alloc(unsigned NbRows, unsigned NbColumns);
1593 void cloog_matrix_print(FILE *foo, CloogMatrix *m);
1594 void cloog_matrix_free(CloogMatrix *matrix);
1595 @end group
1596 @end example
1598 @noindent The whole matrix is stored in memory row after row at the
1599 @code{p_Init} address. @code{p} is an array of pointers where
1600 @code{p[i]} points to the first element of the @math{i^{th}} row.
1601 @code{NbRows} and @code{NbColumns} are respectively the number of
1602 rows and columns of the matrix. 
1603 Each row corresponds to a constraint. The first element of each row is an
1604 equality/inequality tag. The
1605 constraint is an equality @math{p(x) = 0} if the first element is 0, but it is
1606 an inequality @math{p(x) \geq 0} if the first element is 1.
1607 The next elements are the coefficients of the unknowns,
1608 followed by the coefficients of the parameters, and finally the constant term.
1609 For instance, the following three constraints:
1611 @tex
1613 \hbox{$ \cases{ -i + m       &$= 0$\cr
1614                 -j + n       &$\geq 0$\cr
1615                  j + i - k   &$\geq 0$}$}
1617 @end tex
1619 @ifnottex
1620 @example
1621 @group
1622     -i + m  = 0
1623     -j + n >= 0
1624  i + j - k >= 0
1625 @end group
1626 @end example
1627 @end ifnottex
1629 @noindent would be represented by the following rows:
1631 @example
1632 @group
1633 # eq/in  i   j   k   m   n   cst
1634     0    0  -1   0   1   0    0 
1635     1   -1   0   0   0   1    0 
1636     1    1   1  -1   0   0    0 
1637 @end group
1638 @end example
1640 @noindent To be able to provide different precision version (CLooG
1641 supports 32 bits, 64 bits and arbitrary precision through the GMP library),
1642 the @code{cloog_int_t} type depends on the configuration options (it may be
1643 @code{long int} for 32 bits version, @code{long long int} for 64 bits version,
1644 and @code{mpz_t} for multiple precision version).
1646 @node CloogDomain
1647 @subsection CloogDomain
1648 @example
1649 @group
1650 CloogDomain *cloog_domain_union_read(CloogState *state,
1651                                      FILE *input, int nb_parameters);
1652 CloogDomain *cloog_domain_from_cloog_matrix(CloogState *state,
1653                                     CloogMatrix *matrix, int nb_par);
1654 void cloog_domain_free(CloogDomain *domain);
1655 @end group
1656 @end example
1658 @noindent @code{CloogDomain} is an opaque type representing a polyhedral
1659 domain (a union of polyhedra).
1660 A @code{CloogDomain} can be read
1661 from a file using @code{cloog_domain_union_read} or
1662 converted from a @code{CloogMatrix}.
1663 The input format for @code{cloog_domain_union_read}
1664 is that of @ref{Domain Representation}.
1665 The function @code{cloog_domain_from_cloog_matrix} takes a @code{CloogState}, a
1666 @code{CloogMatrix} and @code{int} as input and returns a pointer to a
1667 @code{CloogDomain}. @code{matrix} describes the domain and @code{nb_par} is the
1668 number of parameters in this domain. The input data structures are neither
1669 modified nor freed.
1670 The @code{CloogDomain} can be freed using @code{cloog_domain_free}.
1671 There are also some backend dependent functions for creating
1672 @code{CloogDomain}s.
1674 @menu
1675 * CloogDomain/PolyLib::
1676 * CloogDomain/isl::
1677 @end menu
1679 @node CloogDomain/PolyLib
1680 @subsubsection PolyLib
1682 @example
1683 #include <cloog/polylib/cloog.h>
1684 CloogDomain *cloog_domain_from_polylib_polyhedron(CloogState *state,
1685                                         Polyhedron *, int nb_par);
1686 @end example
1687 @noindent
1688 The function @code{cloog_domain_from_polylib_polyhedron} takes a PolyLib
1689 @code{Polyhedron} as input and returns a pointer to a @code{CloogDomain}.
1690 The @code{nb_par} parameter indicates the number of parameters
1691 in the domain.  The input data structure if neither modified nor freed.
1693 @node CloogDomain/isl
1694 @subsubsection isl
1696 @example
1697 #include <cloog/isl/cloog.h>
1698 CloogDomain *cloog_domain_from_isl_set(__isl_take isl_set *set);
1699 __isl_give isl_set *isl_set_from_cloog_domain(CloogDomain *domain);
1700 @end example
1701 @noindent
1702 The function @code{cloog_domain_from_isl_set} takes an
1703 @code{isl_set} as input and returns a pointer to a @code{CloogDomain}.
1704 The function consumes a reference to the given @code{isl_set}.
1705 Similarly, @code{isl_set_from_cloog_domain} consumes a reference
1706 to a @code{CloogDomain} and returns an @code{isl_set}.
1709 @node CloogScattering
1710 @subsection CloogScattering
1711 @example
1712 @group
1713 CloogScattering *cloog_domain_read_scattering(CloogDomain *domain,
1714                                               FILE *foo);
1715 CloogScattering *cloog_scattering_from_cloog_matrix(CloogState *state,
1716                          CloogMatrix *matrix, int nb_scat, int nb_par);
1717 void cloog_scattering_free(CloogScattering *);
1718 @end group
1719 @end example
1721 @noindent
1722 The @code{CloogScattering} type represents a scattering function.
1723 A @code{CloogScattering} for a given @code{CloogDomain} can be read
1724 from a file using @code{cloog_scattering_read} or converted
1725 from a @code{CloogMatrix} using @code{cloog_scattering_from_cloog_matrix}.
1726 The function @code{cloog_scattering_from_cloog_matrix} takes a
1727 @code{CloogState}, a @code{CloogMatrix} and two @code{int}s as input and
1728 returns a
1729 pointer to a @code{CloogScattering}.
1730 @code{matrix} describes the scattering, while @code{nb_scat} and
1731 @code{nb_par} are the number of scattering dimensions and
1732 the number of parameters, respectively. The input data structures are
1733 neither modified nor freed.
1734 A @code{CloogScattering} can be freed using @code{cloog_scattering_free}.
1735 There are also some backend dependent functions for creating
1736 @code{CloogScattering}s.
1738 @menu
1739 * CloogScattering/PolyLib::
1740 * CloogScattering/isl::
1741 @end menu
1743 @node CloogScattering/PolyLib
1744 @subsubsection PolyLib
1746 @example
1747 #include <cloog/polylib/cloog.h>
1748 CloogScattering *cloog_scattering_from_polylib_polyhedron(
1749         CloogState *state, Polyhedron *polyhedron, int nb_par);
1750 @end example
1751 @noindent
1752 The function @code{cloog_scattering_from_polylib_polyhedron} takes a PolyLib
1753 @code{Polyhedron} as input and returns a pointer to a @code{CloogScattering}.
1754 The @code{nb_par} parameter indicates the number of parameters
1755 in the domain.  The input data structure if neither modified nor freed.
1757 @node CloogScattering/isl
1758 @subsubsection isl
1760 @example
1761 #include <cloog/isl/cloog.h>
1762 CloogScattering *cloog_scattering_from_isl_map(__isl_take isl_map *map);
1763 @end example
1764 @noindent
1765 The function @code{cloog_scattering_from_isl_map} takes an
1766 @code{isl_map} as input and returns a pointer to a @code{CloogScattering}.
1767 The output dimensions of the @code{isl_map} correspond to the
1768 scattering dimensions, while the input dimensions correspond to the
1769 domain dimensions.
1770 The function consumes a reference to the given @code{isl_map}.
1773 @node CloogUnionDomain
1774 @subsection CloogUnionDomain
1775 @example
1776 @group
1777 enum cloog_dim_type @{ CLOOG_PARAM, CLOOG_ITER, CLOOG_SCAT @};
1779 CloogUnionDomain *cloog_union_domain_alloc(int nb_par);
1780 CloogUnionDomain *cloog_union_domain_add_domain(CloogUnionDomain *ud,
1781         const char *name, CloogDomain *domain,
1782         CloogScattering *scattering, void *usr);
1783 CloogUnionDomain *cloog_union_domain_set_name(CloogUnionDomain *ud,
1784         enum cloog_dim_type type, int index, const char *name);
1785 void cloog_union_domain_free(CloogUnionDomain *ud);
1786 @end group
1787 @end example
1789 @noindent A @code{CloogUnionDomain} structure represents a union
1790 of scattered named domains.  A @code{CloogUnionDomain} is
1791 initialized by a call to @code{cloog_union_domain_alloc},
1792 after which domains can be added using @code{cloog_union_domain_add_domain}.
1794 @code{cloog_union_domain_alloc} takes the number of parameters as input.
1795 @code{cloog_union_domain_add_domain} takes a previously created
1796 @code{CloogUnionDomain} as input along with an optional name,
1797 a domain, an optional scattering function and a user pointer.
1798 The name may be @code{NULL} and is duplicated if it is not.
1799 If no name is specified, then the statements will be named according
1800 to the order in which they were added.
1801 @code{domain} and @code{scattering} are taken over
1802 by the @code{CloogUnionDomain}.  @code{scattering} may be @code{NULL},
1803 but it must be consistently @code{NULL} or not over all calls
1804 to @code{cloog_union_domain_add_domain}.
1805 @code{cloog_union_domain_set_name} can be used to set the names
1806 of parameters, iterators and scattering dimensions.
1807 The names of iterators and scattering dimensions can only be set
1808 after all domains have been added.
1810 There is also a backend dependent function for creating
1811 @code{CloogUnionDomain}s.
1813 @menu
1814 * CloogUnionDomain/isl::
1815 @end menu
1817 @node CloogUnionDomain/isl
1818 @subsubsection isl
1820 @example
1821 #include <cloog/isl/cloog.h>
1822 CloogUnionDomain *cloog_union_domain_from_isl_union_map(
1823         __isl_take isl_union_map *umap);
1824 CloogUnionDomain *cloog_union_domain_from_isl_set(
1825         __isl_take isl_set *set);
1826 @end example
1827 @noindent
1828 The function @code{cloog_union_domain_from_isl_union_map} takes a
1829 @code{isl_union_map} as input and returns a pointer
1830 to a @code{CloogUnionDomain}.
1831 The input is a mapping from different
1832 spaces (different tuple names and possibly different dimensions)
1833 to a common space.  The iteration domains are set to the domains
1834 in each space.  The statement names are set to the names of the
1835 spaces.  The parameter names of the result are set to those of
1836 the input, but the iterator and scattering dimension names are
1837 left unspecified.
1838 The function consumes a reference to the given @code{isl_union_map}.  The
1839 function @code{cloog_union_domain_from_isl_set} is similar, but takes an
1840 unscattered domain as input. It is not defined for an union_set, because the
1841 order of iterations from two different isl_sets is undefined, if no scattering
1842 is provided.
1845 @node CloogStatement
1846 @subsection CloogStatement
1847 @example
1848 @group
1849 struct cloogstatement
1850 @{ int number ;                  /* The statement unique number. */
1851   char *name;                   /* Name of the statement. */
1852   void * usr ;                  /* Pointer for user's convenience. */
1853   struct cloogstatement * next ;/* Next element of the linked list. */
1854 @} ;
1855 typedef struct cloogstatement CloogStatement ;
1857 CloogStatement *cloog_statement_malloc(CloogState *state);
1858 void cloog_statement_print(FILE *, CloogStatement *);
1859 void cloog_statement_free(CloogStatement *);
1860 @end group
1861 @end example
1863 @noindent The @code{CloogStatement} structure represents a @code{NULL}
1864 terminated linked
1865 list of statements. In CLooG, a statement is only defined by its unique
1866 number (@code{number}). The user can use the pointer @code{usr} for his
1867 own convenience to link his own statement representation to the
1868 corresponding @code{CloogStatement} structure. The whole management of the
1869 @code{usr} pointer is under the responsibility of the user, in particular,
1870 CLooG never tries to print, to allocate or to free a memory block pointed
1871 by @code{usr}. 
1875 @node CloogOptions
1876 @subsection CloogOptions
1877 @example
1878 @group
1879 struct cloogoptions
1880 @{ int l;                     /* -l option.                                */
1881   int f;                     /* -f option.                                 */
1882   int *ls;                   /* Statement-wise l option                    */
1883   int *fs;                   /* Statement-wise f option                    */
1884   int fs_ls_size;            /* Size of the fs and ls arrays (same size)   */
1885   int strides;               /* -strides option.                           */
1886   int sh;                    /* -sh option.                                */
1887   int first_unroll;          /* -first-unroll option.                      */
1888   int esp;                   /* -esp option.                               */
1889   int fsp;                   /* -fsp option.                               */
1890   int otl;                   /* -otl option.                               */
1891   int block;                 /* -block option.                             */
1892   int compilable;            /* -compilable option.                        */
1893   int language;              /* CLOOG_LANGUAGE_C or CLOOG_LANGUAGE_FORTRAN */
1894   int save_domains;          /* Save unsimplified copy of domain.          */
1895 @} ;
1896 typedef struct cloogoptions CloogOptions ;
1898 CloogOptions *cloog_options_malloc(CloogState *state);
1899 void cloog_options_print(FILE *foo, CloogOptions *options);
1900 void cloog_options_free(CloogOptions *options);
1901 @end group
1902 @end example
1904 @noindent The @code{CloogOptions} structure contains all the possible options to
1905 rule CLooG's behaviour (@pxref{Calling CLooG}).
1906 As a reminder, the default values are:
1907 @itemize @bullet
1908 @item @math{l = -1} (optimize control until the innermost loops),
1909 @item @math{f = 1} (optimize control from the outermost loops),
1910 @item @math{ls/fs = NULL} and @math{fs\_ls\_size = 0} (statement-wise l/f are not set),
1911 @item @math{strides = 0} (use only unit strides),
1912 @item @math{sh = 0} (do not compute simple convex hulls),
1913 @item @math{first\_unroll = -1} (do not perform unrolling),
1914 @item @math{esp = 1} (spread complex equalities),
1915 @item @math{fsp = 1} (start to spread from the first iterators),
1916 @item @math{otl = 1} (simplify loops running only once).
1917 @item @math{block = 0} (do not make statement blocks when not necessary).
1918 @item @math{compilable = 0} (do not generate a compilable code).
1919 @end itemize 
1921 The @code{save_domains} option is only useful for users of the CLooG
1922 library.  This option defaults to 0, but when it is set, the @code{domain}
1923 field of each @code{clast_user_stmt} will be set to the set of values for the
1924 scattering dimensions for which this instance of the user statement is executed.
1925 The @code{domain} field of each @code{clast_for} contains the set of values for
1926 the scattering dimensions for which an instance of a user statement is executed
1927 inside the @code{clast_for}. It is only available if the @code{clast_for}
1928 enumerates a scattering dimension.
1930 @node CloogInput
1931 @subsection CloogInput
1932 @example
1933 @group
1934 CloogInput *cloog_input_read(FILE *file, CloogOptions *options);
1935 CloogInput *cloog_input_alloc(CloogDomain *context,
1936                                 CloogUnionDomain *ud);
1937 void cloog_input_free(CloogInput *input);
1939 void cloog_input_dump_cloog(FILE *, CloogInput *, CloogOptions *);
1940 @end group
1941 @end example
1943 @noindent A @code{CloogInput} structure represents the input to CLooG.
1944 It is essentially a @code{CloogUnionDomain} along with a context
1945 @code{CloogDomain}.  A @code{CloogInput} can be created from
1946 a @code{CloogDomain} and a @code{CloogUnionDomains} using
1947 @code{cloog_input_alloc}, or it can be read from a CLooG input
1948 file using @code{cloog_input_read}.  The latter also modifies
1949 the @code{language} field of the @code{CloogOptions} structure.
1950 The constructed @code{CloogInput} can be used as input
1951 to a @code{cloog_clast_create_from_input} call.
1953 A @code{CloogInput} data structure and a @code{CloogOptions} contain
1954 the same information as a .cloog file. This function dumps the .cloog
1955 description of the given data structures into a file.
1957 @node Dump CLooG Input File Function
1958 @subsection Dump CLooG Input File Function
1959 @example
1960 @end example
1962 @node CLooG Output
1963 @section CLooG Output
1965 @noindent
1966 Given a description of the input,
1967 an AST corresponding to the @code{CloogInput} can be constructed
1968 using @code{cloog_clast_create_from_input} and destroyed using
1969 @code{free_clast_stmt}.
1970 @example
1971 struct clast_stmt *cloog_clast_create_from_input(CloogInput *input,
1972                                       CloogOptions *options);
1973 void free_clast_stmt(struct clast_stmt *s);
1974 @end example
1975 @noindent
1976 @code{clast_stmt} represents a linked list of ``statements''.
1977 @example
1978 struct clast_stmt @{
1979     const struct clast_stmt_op    *op;
1980     struct clast_stmt   *next;
1982 @end example
1983 @noindent
1984 The entries in the list are not of type @code{clast_stmt} itself,
1985 but of some larger type.  The following statement types are defined
1986 by CLooG.
1988 @example
1989 struct clast_root @{
1990     struct clast_stmt   stmt;
1991     CloogNames *        names;
1993 struct clast_root *new_clast_root(CloogNames *names);
1995 struct clast_assignment @{
1996     struct clast_stmt   stmt;
1997     const char *        LHS;
1998     struct clast_expr * RHS;
2000 struct clast_assignment *new_clast_assignment(const char *lhs,
2001                                               struct clast_expr *rhs);
2003 struct clast_block @{
2004     struct clast_stmt   stmt;
2005     struct clast_stmt * body;
2007 struct clast_block *new_clast_block(void);
2009 struct clast_user_stmt @{
2010     struct clast_stmt   stmt;
2011     CloogDomain *       domain;
2012     CloogStatement *    statement;
2013     struct clast_stmt * substitutions;
2015 struct clast_user_stmt *new_clast_user_stmt(CloogDomain *domain,
2016     CloogStatement *stmt, struct clast_stmt *subs);
2018 struct clast_for @{
2019     struct clast_stmt   stmt;
2020     CloogDomain *       domain;
2021     const char *        iterator;
2022     struct clast_expr * LB;
2023     struct clast_expr * UB;
2024     cloog_int_t         stride;
2025     struct clast_stmt * body;
2027 struct clast_for *new_clast_for(CloogDomain *domain, const char *it,
2028                                 struct clast_expr *LB, struct clast_expr *UB,
2029                                 cloog_int_t stride);
2031 struct clast_guard @{
2032     struct clast_stmt   stmt;
2033     struct clast_stmt * then;
2034     int                 n;
2035     struct clast_equation       eq[1];
2037 struct clast_guard *new_clast_guard(int n);
2038 @end example
2039 @noindent
2040 The @code{clast_stmt} returned by @code{cloog_clast_create}
2041 is a @code{clast_root}.
2042 It contains a placeholder for all the variable names that appear
2043 in the AST and a (list of) nested statement(s).
2045 @noindent
2046 A @code{clast_assignment} assigns the value given by
2047 the @code{clast_expr} @code{RHS} to a variable named @code{LHS}.
2049 @noindent
2050 A @code{clast_block} groups a list of statements into one statement.
2051 These statements are only generated if the @code{block} option is set,
2052 @pxref{Statement Block} and @ref{CloogOptions}.
2054 @noindent
2055 A @code{clast_user_stmt} represents a call to a statement specified
2056 by the user, @pxref{CloogStatement}.
2057 @code{substitutions} is a list of @code{clast_assignment} statements
2058 assigning an expression in terms of the scattering dimensions to
2059 each of the original iterators in the original order.
2060 The @code{LHS}s of these assignments are left blank (@code{NULL}).
2061 The @code{domain} is set to @code{NULL} if the @code{save_domains} option
2062 is not set.  Otherwise, it is set to the set
2063 of values for the scattering dimensions
2064 for which this instance of the user statement is executed.
2065 Note that unless the @code{noscalars} option has been set, the
2066 constant scattering dimensions may have been removed from this set.
2068 @noindent
2069 A @code{clast_for} represents a for loop, iterating @code{body} for each
2070 value of @code{iterator} between @code{LB} and @code{UB} in steps
2071 of size @code{stride}.
2072 The @code{domain} is set to @code{NULL} if the @code{save_domains} option is not
2073 set.  Otherwise, it is set to the set of values for the scattering dimensions
2074 for which a user statement is executed inside this @code{clast_for}.  Note that
2075 unless the @code{noscalars} option has been set, the constant scattering
2076 dimensions may have been removed from this set.
2078 @noindent
2079 A @code{clast_guard} represents the guarded execution of the @code{then}
2080 (list of) statement(s) by a conjunction of @code{n} (in)equalities.
2081 Each (in)equality is represented by a @code{clast_equation}.
2082 @example
2083 struct clast_equation @{
2084     struct clast_expr * LHS;
2085     struct clast_expr * RHS;
2086     int                 sign;
2088 @end example
2089 @noindent
2090 The condition expressed by a @code{clast_equation} is
2091 @code{LHS <= RHS}, @code{LHS == RHS} or @code{LHS >= RHS}
2092 depending on whether @code{sign} is less than zero, equal
2093 to zero, or greater than zero.
2095 The dynamic type of a @code{clast_stmt} can be determined
2096 using the macro @code{CLAST_STMT_IS_A(stmt,type)},
2097 where @code{stmt} is a pointer to a @code{clast_stmt}
2098 and @code{type} is one of @code{stmt_root}, @code{stmt_ass},
2099 @code{stmt_user}, @code{stmt_block}, @code{stmt_for} or
2100 @code{stmt_guard}.
2101 Users are allowed to define their own statement types by
2102 assigning the @code{op} field of the statements a pointer
2103 to a @code{clast_stmt_op} structure.
2104 @example
2105 struct clast_stmt_op @{
2106     void (*free)(struct clast_stmt *);
2108 @end example
2109 @noindent
2110 The @code{free} field of this structure should point
2111 to a function that frees the user defined statement.
2113 @noindent
2114 A @code{clast_expr} can be an identifier, a term,
2115 a binary expression or a reduction.
2116 @example
2117 enum clast_expr_type @{
2118     clast_expr_name,
2119     clast_expr_term,
2120     clast_expr_bin,
2121     clast_expr_red
2123 struct clast_expr @{
2124     enum clast_expr_type type;
2126 void free_clast_expr(struct clast_expr *e);
2127 @end example
2129 @noindent
2130 Identifiers are of subtype @code{clast_name}.
2131 @example
2132 struct clast_name @{
2133     struct clast_expr   expr;
2134     const char *        name;
2136 struct clast_name *new_clast_name(const char *name);
2137 void free_clast_name(struct clast_name *t);
2138 @end example
2139 @noindent
2140 The character string pointed to by @code{name} is
2141 assumed to be part of the @code{CloogNames} structure
2142 in the root of the clast as is therefore not copied.
2144 @noindent
2145 Terms are of type @code{clast_term}.
2146 @example
2147 struct clast_term @{
2148     struct clast_expr   expr;
2149     cloog_int_t         val;
2150     struct clast_expr  *var;
2152 struct clast_term *new_clast_term(cloog_int_t c, struct clast_expr *v);
2153 void free_clast_term(struct clast_term *t);
2154 @end example
2155 @noindent
2156 If @code{var} is set to @code{NULL}, then the term represents
2157 the integer value @code{val}.  Otherwise, it represents
2158 the term @code{val * var}.
2159 @code{new_clast_term} simply copies the @code{v} pointer
2160 without copying the underlying @code{clast_expr}.
2161 @code{free_clast_term}, on the other hand, recursively frees
2162 @code{var}.
2164 @noindent
2165 Binary expressions are of type @code{clast_bin_type} and
2166 represent either the floor of a division (fdiv),
2167 the ceil of a division (cdiv), an exact division or
2168 the remainder of an fdiv.
2169 @example
2170 enum clast_bin_type @{ clast_bin_fdiv, clast_bin_cdiv, 
2171                       clast_bin_div, clast_bin_mod @};
2172 struct clast_binary @{
2173     struct clast_expr   expr;
2174     enum clast_bin_type type;
2175     struct clast_expr*  LHS;
2176     cloog_int_t         RHS;
2178 struct clast_binary *new_clast_binary(enum clast_bin_type t, 
2179                           struct clast_expr *lhs, cloog_int_t rhs);
2180 void free_clast_binary(struct clast_binary *b);
2181 @end example
2183 @noindent
2184 Reductions are of type @code{clast_reduction} and
2185 can represent either the sum, the minimum or the maximum
2186 of its elements.
2187 @example
2188 enum clast_red_type @{ clast_red_sum, clast_red_min, clast_red_max @};
2189 struct clast_reduction @{
2190     struct clast_expr   expr;
2191     enum clast_red_type type;
2192     int                 n;
2193     struct clast_expr*  elts[1];
2195 struct clast_reduction *new_clast_reduction(enum clast_red_type t,
2196                                             int n);
2197 void free_clast_reduction(struct clast_reduction *r);
2198 @end example
2200 @node Retrieving version information
2201 @section Retrieving version information
2202 CLooG provides static and dynamic version checks to assist on
2203 including a compatible version of the library.
2204 A static version check at compile time can be achieved by
2205 querying the version constants defined in @code{version.h}:
2207 @itemize @bullet
2208 @item @code{CLOOG_VERSION_MAJOR}
2209 @item @code{CLOOG_VERSION_MINOR}
2210 @item @code{CLOOG_VERSION_REVISION}
2211 @end itemize
2213 This way it is possible to ensure the included headers are of the
2214 correct version. It is still possible that the installed CLooG
2215 library version differs from the installed headers.
2216 In order to avoid this, a dynamic version check is provided with
2217 the functions:
2219 @example
2220 @group
2221 int cloog_version_major(void);
2222 int cloog_version_minor(void);
2223 int cloog_version_revision(void);
2224 @end group
2225 @end example
2227 By using both the static and the dynamic version check, it is possible
2228 to match CLooG's header version with the library's version.
2230 @node Example of Library Utilization
2231 @section Example of Library Utilization
2232 @menu
2233 * Basic Library Utilization::
2234 * Scanning isl Sets::
2235 * Source to Source Compiler::
2236 @end menu
2238 @node Basic Library Utilization
2239 @subsection Basic Library Utilization
2240 Here is a basic example showing how it is possible to use the CLooG library,
2241 assuming that a standard installation has been done.
2242 The following C program reads a CLooG input file on the standard input,
2243 then prints the solution on the standard output.
2244 Options are preselected to the default values of the CLooG software.
2245 This example is provided in the @code{example} directory of the
2246 CLooG distribution.
2247 @example
2248 /* example.c */
2249 # include <stdio.h>
2250 # include <cloog/cloog.h>
2252 int main() @{
2253   CloogState *state;
2254   CloogInput *input;
2255   CloogOptions *options ;
2256   struct clast_stmt *root;
2257   
2258   /* Setting options and reading program informations. */
2259   state = cloog_state_malloc();
2260   options = cloog_options_malloc(state);
2261   input = cloog_input_read(stdin, options);
2263   /* Generating and printing the code. */
2264   root = cloog_clast_create_from_input(input, options);
2265   clast_pprint(stdout, root, 0, options);
2267   cloog_clast_free(root);
2268   cloog_options_free(options) ;
2269   cloog_state_free(state);
2270   return 0;
2272 @end example
2274 @noindent The compilation (with default isl/GMP version installed)
2275 command could be:
2276 @example
2277 gcc -DCLOOG_INT_GMP example.c -lcloog-isl -o example
2278 @end example
2279 @noindent A calling command with the input file test.cloog could be:
2280 @example
2281 more test.cloog | ./example
2282 @end example
2284 @node Scanning isl Sets
2285 @subsection Scanning isl Sets
2286 Here is an isl-level example to prepare a convenient input, to generate the
2287 Clast of the scanning code for this input, to pretty-print the code and to
2288 de-allocate memory in a clean way. This example is provided in the
2289 @code{example} directory of the CLooG distribution.
2291 @example
2292 /* example-isl.c */
2293 #include <cloog/cloog.h>
2294 #include <cloog/isl/cloog.h>
2296 /* Input problem */
2297 int nb_parameters = 1;
2298 char *parameter_name[]  = @{"N"@};
2299 char *iterator_name[]   = @{"i", "j"@};
2300 char *scattering_name[] = @{"t0", "t1", "t2"@};
2301 char *str_context       = "[N] -> @{ : N > 0@}";
2302 char *str_domain1       = "[N] -> @{[i, j] : 0 <= i < N and 0 <= j < N@}";
2303 char *str_domain2       = "[N] -> @{[i, j] : 0 <= i < N and 0 <= j < N@}";
2304 char *str_scattering1   = "[N] -> @{[i, j] -> [0, i + j, j]@}";
2305 char *str_scattering2   = "[N] -> @{[i, j] -> [1, i,    -j]@}";
2307 int main() @{
2308   isl_ctx *ctx;
2309   isl_set *set_context, *set1, *set2;
2310   isl_map *map1, *map2;
2311   CloogDomain *context, *domain1, *domain2;
2312   CloogScattering *scattering1, *scattering2;
2313   CloogUnionDomain *domains;
2314   CloogInput *input;
2315   CloogState *state;
2316   CloogOptions *options;
2317   struct clast_stmt *root;
2319   /* Build isl structures for context, sets and mapping */
2320   ctx = isl_ctx_alloc();
2321   set_context = isl_set_read_from_str(ctx, str_context);
2322   set1 = isl_set_read_from_str(ctx, str_domain1);
2323   set2 = isl_set_read_from_str(ctx, str_domain2);
2324   map1 = isl_map_read_from_str(ctx, str_scattering1);
2325   map2 = isl_map_read_from_str(ctx, str_scattering2);
2327   /* Translate them to CLooG context, domains and scattering */
2328   context = cloog_domain_from_isl_set(set_context);
2329   domain1 = cloog_domain_from_isl_set(set1);
2330   domain2 = cloog_domain_from_isl_set(set2);
2331   scattering1 = cloog_scattering_from_isl_map(map1);
2332   scattering2 = cloog_scattering_from_isl_map(map2);
2334   /* Prepare the list of domains to scan */
2335   domains = cloog_union_domain_alloc(nb_parameters);
2336   cloog_union_domain_add_domain(domains,"S1",domain1,scattering1,NULL);
2337   cloog_union_domain_add_domain(domains,"S2",domain2,scattering2,NULL);
2338   cloog_union_domain_set_name(domains,CLOOG_PARAM,0,parameter_name[0]);
2339   cloog_union_domain_set_name(domains,CLOOG_ITER, 0,iterator_name[0]);
2340   cloog_union_domain_set_name(domains,CLOOG_ITER, 1,iterator_name[1]);
2341   cloog_union_domain_set_name(domains,CLOOG_SCAT, 0,scattering_name[0]);
2342   cloog_union_domain_set_name(domains,CLOOG_SCAT, 1,scattering_name[1]);
2343   cloog_union_domain_set_name(domains,CLOOG_SCAT, 2,scattering_name[2]);
2345   /* Build the input, generate a scanning code AST and print the code */
2346   input = cloog_input_alloc(context, domains);
2347   state = cloog_isl_state_malloc(ctx);
2348   options = cloog_options_malloc(state);
2349   root = cloog_clast_create_from_input(input, options);
2350   clast_pprint(stdout, root, 0, options);
2352   /* Recycle allocated memory */
2353   cloog_clast_free(root);
2354   cloog_options_free(options);
2355   cloog_state_free(state);
2356   isl_ctx_free(ctx);
2358 @end example
2360 @noindent The compilation (with default isl/GMP version installed)
2361 command could be:
2362 @example
2363 gcc -DCLOOG_INT_GMP example-isl.c -lcloog-isl -o example-isl
2364 @end example
2365 @noindent A calling command could be:
2366 @example
2367 ./example-isl
2368 @end example
2370 @node Source to Source Compiler
2371 @subsection Source to Source Compiler
2372 Here is an example of a source (to polyhedra) to source compiler. It uses the
2373 Clan library to raise a SCoP from C to the OpenScop representation, and CLooG
2374 to translate back the SCoP to C. You may analyze the polyhedral representation
2375 and apply optimizing transformation to that representation to build your own
2376 high-level optimizing compiler. That example requires to install Clan, OpenScop
2377 and to build CLooG with the OpenScop support. This example is provided in the
2378 @code{example} directory of the CLooG distribution.
2380 @example
2381 /* poc.c A complete C to polyhedra to C compiler */
2382 #include <stdlib.h>
2383 #include <osl/osl.h>
2384 #include <clan/clan.h>
2385 #include <cloog/cloog.h>
2387 /* Use the Clan library to convert a SCoP from C to OpenScop */
2388 osl_scop_p read_scop_from_c(FILE* input, char* input_name) @{
2389   clan_options_p clanoptions;
2390   osl_scop_p scop;
2392   clanoptions = clan_options_malloc();
2393   clanoptions->precision = OSL_PRECISION_MP;
2394   CLAN_strdup(clanoptions->name, input_name);
2395   scop = clan_scop_extract(input, clanoptions);
2396   clan_options_free(clanoptions);
2397   return scop;
2400 /* Use the CLooG library to output a SCoP from OpenScop to C */
2401 void print_scop_to_c(FILE* output, osl_scop_p scop) @{
2402   CloogState* state;
2403   CloogOptions* options;
2404   CloogInput* input;
2405   struct clast_stmt* clast;
2407   state = cloog_state_malloc();
2408   options = cloog_options_malloc(state);
2409   options->openscop = 1;
2410   cloog_options_copy_from_osl_scop(scop, options);
2411   input = cloog_input_from_osl_scop(options->state, scop);
2412   clast = cloog_clast_create_from_input(input, options);
2413   clast_pprint(output, clast, 0, options);
2414   
2415   cloog_clast_free(clast);
2416   options->scop = NULL; // don't free the scop
2417   cloog_options_free(options);
2418   cloog_state_free(state); // the input is freed inside
2421 int main(int argc, char* argv[]) @{
2422   osl_scop_p scop;
2423   FILE* input;
2425   if ((argc < 2) || (argc > 2)) @{
2426     fprintf(stderr, "usage: %s file.c\n", argv[0]);
2427     exit(0);
2428   @}
2430   if (argc == 1)
2431     input = stdin;
2432   else
2433     input = fopen(argv[1], "r");
2435   if (input == NULL) @{
2436     fprintf(stderr, "cannot open input file\n");
2437     exit(0);
2438   @}
2440   scop = read_scop_from_c(input, argv[1]);
2441   osl_scop_print(stdout, scop);
2443   // UPDATE THE SCOP IN A SMART WAY HERE 
2445   print_scop_to_c(stdout, scop);
2446   osl_scop_free(scop);
2447   
2448   fclose(input);
2449   return 0;
2451 @end example
2453 @noindent The compilation (with default isl/GMP with OpenScop support
2454 version installed, along with the OpenScop library and Clan library)
2455 command could be:
2456 @example
2457 gcc -DCLOOG_INT_GMP poc.c -lcloog-isl -lclan -losl -o poc
2458 @end example
2459 @noindent A calling command could be:
2460 @example
2461 ./poc scop.c
2462 @end example
2465 @c %  ******************************** HACKING *********************************
2466 @c @node Hacking
2467 @c @chapter Hacking CLooG
2469 @c @menu
2470 @c * Program organization::
2471 @c * Special Options::
2472 @c * CLooG Coding Standards::
2473 @c @end menu
2475 @c @node Program organization
2476 @c @section Program organization
2478 @c @node Special Options
2479 @c @section Special Options
2481 @c @node CLooG Coding Standards
2482 @c @section CLooG Coding Standards
2485 @c %  ****************************** INSTALLING ********************************
2486 @node Installing
2487 @chapter Installing CLooG
2489 @menu
2490 * License::
2491 * Requirements::
2492 * Basic Installation::
2493 * Optional Features::
2494 * Uninstallation::
2495 @end menu
2497 @node License
2498 @section License
2499 First of all, it would be very kind to refer the following paper in any
2500 publication that result from the use of the CLooG software or its library,
2501 @pxref{Bas04} (a bibtex entry is provided behind the title page of this
2502 manual, along with copyright notice, and in the CLooG home
2503 @code{http://www.CLooG.org}.
2505 This library is free software; you can redistribute it and/or
2506 modify it under the terms of the GNU Lesser General Public
2507 License as published by the Free Software Foundation; either
2508 version 2.1 of the License, or (at your option) any later version.
2509 This library is distributed in the hope that it will be useful,
2510 but WITHOUT ANY WARRANTY; without even the implied warranty of
2511 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2512 Lesser General Public License for more details.
2513 @code{http://www.gnu.org/licenses/lgpl-2.1.html}
2515 Note, though, that if you link CLooG against a GPL library such
2516 as the PolyLib backend, then the combination becomes GPL too.
2517 In particular, a CLooG library based on the PolyLib backend
2518 is GPL version 2 only.
2519 Since the isl backend is LGPL, linking against it does not affect
2520 the license of CLooG.
2523 @node Requirements
2524 @section Requirements
2526 CLooG can be used with one of two possible backends,
2527 one using isl and one using PolyLib.
2528 The isl library is included in the CLooG distribution,
2529 while the PolyLib library needs to be obtained separately.
2530 On the other hand, isl requires GMP, while PolyLib can be
2531 compiled with or without the use of GMP.
2532 The user therefore needs to install at least one of
2533 PolyLib or GMP.
2535 @menu
2536 * PolyLib::
2537 * GMP Library::
2538 @end menu
2541 @node PolyLib
2542 @subsection PolyLib (optional)
2543 To successfully install CLooG with the PolyLib backend,
2544 the user first needs to install PolyLib
2545 version 5.22.1 or above (default 64 bits version is satisfying
2546 as well as 32 bits or GMP multiple precision version).
2547 Polylib can be downloaded freely
2548 at @code{http://icps.u-strasbg.fr/PolyLib/} or
2549 @code{http://www.irisa.fr/polylib/}. Once downloaded and unpacked
2550 (e.g. using the @samp{tar -zxvf polylib-5.22.3.tar.gz} command),
2551 the user can compile
2552 it by typing the following commands on the PolyLib's root directory:
2554 @itemize @bullet
2555 @item @code{./configure}
2556 @item @code{make}
2557 @item And as root: @code{make install}
2558 @end itemize
2560 Alternatively, the latest development version can be obtained from the
2561 git repository:
2562 @itemize @bullet
2563 @item @code{git clone git://repo.or.cz/polylib.git}
2564 @item @code{cd polylib}
2565 @item @code{./autogen.sh}
2566 @item @code{./configure}
2567 @item @code{make}
2568 @item And as root: @code{make install}
2569 @end itemize
2571 The PolyLib default installation is @code{/usr/local}. This directory may
2572 not be inside your library path. To fix the problem, the user should set
2573 @example
2574 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
2575 @end example
2576 @noindent if your shell is, e.g., bash or
2577 @example
2578 setenv LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/local/lib
2579 @end example
2580 @noindent if your shell is, e.g., tcsh. Add the line to your .bashrc or .tcshrc (or
2581 whatever convenient file) to make this change permanent. Another solution
2582 is to ask PolyLib to install in the standard path by using the prefix
2583 option of the configure script:
2584 @samp{./configure --prefix=/usr}.
2586 CLooG makes intensive calls to polyhedral operations, and PolyLib
2587 functions do the job. Polylib is a free library written in C for the
2588 manipulation of polyhedra. The library is operating on objects like
2589 vectors, matrices, lattices, polyhedra, Z-polyhedra, unions of
2590 polyhedra and a lot of other intermediary structures. It provides
2591 functions for all the important operations on these structures. 
2593 @node GMP Library
2594 @subsection GMP Library (optional)
2596 To be able to deal with insanely large coefficient, the user will need to
2597 install the GNU Multiple Precision Library (GMP for short) version 4.1.4
2598 or above. It can be freely downloaded from @code{http://www.swox.com/gmp}.
2599 Note that the isl backend currently requires GMP.
2600 The user can compile GMP by typing the following commands on the GMP root
2601 directory:
2603 @itemize @bullet
2604 @item @code{./configure}
2605 @item @code{make}
2606 @item And as root: @code{make install}
2607 @end itemize
2609 The GMP default installation is @code{/usr/local}, the same method to
2610 fix a library path problem applies as with PolyLib (@pxref{PolyLib}).
2612 If you want to use the PolyLib backend, then
2613 PolyLib has to be built using the GMP library by specifying the option
2614 @samp{--with-libgmp=PATH_TO_GMP} to the PolyLib configure script
2615 (where @code{PATH_TO_GMP} is @code{/usr/local} if you did not change the GMP
2616 installation directory). Then you have to set the convenient CLooG configure
2617 script options to build the GMP version (@pxref{Optional Features}).
2620 @node Basic Installation
2621 @section CLooG Basic Installation
2623 Once downloaded and unpacked
2624 (e.g. using the @samp{tar -zxvf cloog-@value{VERSION}.tar.gz} command),
2625 you can compile CLooG by typing the following commands on the CLooG's root
2626 directory:
2628 @itemize @bullet
2629 @item @code{./configure}
2630 @item @code{make}
2631 @item And as root: @code{make install}
2632 @end itemize
2634 Alternatively, the latest development version can be obtained from the
2635 git repository:
2636 @itemize @bullet
2637 @item @code{git clone git://repo.or.cz/cloog.git}
2638 @item @code{cd cloog}
2639 @item @code{./get_submodules.sh}
2640 @item @code{./autogen.sh}
2641 @item @code{./configure}
2642 @item @code{make}
2643 @item And as root: @code{make install}
2644 @end itemize
2646 Depending on which backend you want to use and where they
2647 are located, you may need to pass some
2648 options to the configure script, @pxref{Optional Features}.
2650 The program binaries and object files can be removed from the
2651 source code directory by typing @code{make clean}. To also remove the
2652 files that the @code{configure} script created (so you can compile the
2653 package for a different kind of computer) type @code{make distclean}.
2655 Both the CLooG software and library have been successfully compiled
2656 on the following systems:
2657 @itemize @bullet
2658 @item PC's under Linux, with the @code{gcc} compiler,
2659 @item PC's under Windows (Cygwin), with the @code{gcc} compiler,
2660 @item Sparc and UltraSparc Stations, with the @code{gcc} compiler.
2661 @end itemize
2663 @node Optional Features 
2664 @section Optional Features  
2665 The @code{configure} shell script attempts to guess correct values for
2666 various system-dependent variables and user options used during compilation.
2667 It uses those values to create the @code{Makefile}. Various user options
2668 are provided by the CLooG's configure script. They are summarized in the
2669 following list and may be printed by typing @code{./configure --help} in the
2670 CLooG top-level directory.
2672 @itemize @bullet
2673 @item By default, the installation directory is @code{/usr/local}:
2674 @code{make install} will install the package's files in
2675 @code{/usr/local/bin}, @code{/usr/local/lib} and @code{/usr/local/include}.
2676 The user can specify an installation prefix other than @code{/usr/local} by
2677 giving @code{configure} the option @code{--prefix=PATH}.
2679 @item By default, the isl backend will use the version of isl
2680 that is @code{bundled} together with CLooG.
2681 Using the @code{--with-isl} option of @code{configure}
2682 the user can specify that @code{no} isl,
2683 a previously installed (@code{system}) isl or a @code{build} isl
2684 should be used.
2685 In the latter case, the user should also specify the build location
2686 using @code{--with-isl-builddir=PATH}.
2687 In case of an installed isl,
2688 the installation location can be specified using the
2689 @code{--with-isl-prefix=PATH} and
2690 @code{--with-isl-exec-prefix=PATH} options of @code{configure}.
2692 @item By default, the PolyLib backend will use an installed
2693 (@code{system}) PolyLib, if any.
2694 The installation location can be specified using the
2695 @code{--with-polylib-prefix=PATH} and
2696 @code{--with-polylib-exec-prefix=PATH} options of @code{configure}.
2697 Using the @code{--with-polylib} option of @code{configure}
2698 the user can specify that @code{no} PolyLib or a @code{build} PolyLib
2699 should be used.
2700 In the latter case, the user should also specify the build location
2701 using @code{--with-polylib-builddir=PATH}.
2703 @item By default, the PolyLib backend of CLooG is built
2704 in 64bits version if such version of the
2705 PolyLib is found by @code{configure}. If the only existing version of the
2706 PolyLib is the 32bits or if the user give to @code{configure} the option
2707 @code{--with-bits=32}, the 32bits version of CLooG will be compiled. In the
2708 same way, the option @code{--with-bits=gmp} have to be used to build
2709 the multiple precision version.
2711 @item By default, @code{configure} will look for the GMP library
2712 (necessary to build the multiple precision version) in standard
2713 locations. If necessary, the user can specify the GMP path by giving
2714 @code{configure} the option @code{--with-gmp-prefix=PATH} and/or
2715 @code{--with-gmp-exec-prefix=PATH}.
2717 @item By default, the OpenScop Library (osl) support is not enabled.
2718 @c @code{configure} will use the bundled OpenScop Library (osl).
2719 Using the @code{--with-osl} option of @code{configure}
2720 the user can specify that @code{no} osl,
2721 a previously installed (@code{system}) osl, a @code{bundled} osl, or a
2722 @code{build} osl should be used.
2723 In the latter case, the user should also specify the build location
2724 using @code{--with-osl-builddir=PATH}.
2725 In case of an installed osl,
2726 the installation location can be specified using the
2727 @code{--with-osl-prefix=PATH} and
2728 @code{--with-osl-exec-prefix=PATH} options of @code{configure}.
2729 @end itemize
2731 @node Uninstallation 
2732 @section Uninstallation  
2733 The user can easily remove the CLooG software and library from his system
2734 by typing (as root if necessary) from the CLooG top-level directory
2735 @code{make uninstall}.
2737 @c %  **************************** DOCUMENTATION ******************************
2738 @node Documentation
2739 @chapter Documentation
2740 The CLooG distribution provides several documentation sources. First, the
2741 source code itself is as documented as possible. The code comments use a
2742 Doxygen-compatible presentation (something similar to what JavaDoc does for
2743 JAVA). The user may install Doxygen
2744 (see @code{http://www.stack.nl/~dimitri/doxygen}) to automatically
2745 generate a technical documentation by typing @code{make doc} or
2746 @code{doxygen ./autoconf/Doxyfile} at the CLooG top-level directory after
2747 running the configure script (@pxref{Installing}). Doxygen will generate
2748 documentation sources (in HTML, LaTeX and man) in the @code{doc/source}
2749 directory of the CLooG distribution.
2751 The Texinfo sources of the present document are also provided in the @code{doc}
2752 directory. You can build it in either DVI format (by typing
2753 @code{texi2dvi cloog.texi}) or PDF format
2754 (by typing @code{texi2pdf cloog.texi}) or HTML format
2755 (by typing @code{makeinfo --html cloog.texi}, using @code{--no-split}
2756 option to generate a single HTML file) or info format
2757 (by typing @code{makeinfo cloog.texi}).
2759 @c %  ****************************** REFERENCES ********************************
2760 @node References
2761 @chapter References
2763 @itemize
2764 @item
2765 @anchor{Bas03a}[Bas03a] C. Bastoul, P. Feautrier. Improving data locality
2766 by chunking. CC'12 International Conference on Compiler Construction,
2767 LNCS 2622, pages 320-335, Warsaw, april 2003. 
2769 @item
2770 @anchor{Bas03b}[Bas03b] C. Bastoul. Efficient code generation for automatic
2771 parallelization and optimization. ISPDC'03 IEEE International Symposium on
2772 Parallel and Distributed Computing, pages 23-30, Ljubljana, october 2003. 
2774 @item
2775 @anchor{Bas04}[Bas04] C. Bastoul. Code Generation in the Polyhedral Model
2776 Is Easier Than You Think. PACT'13 IEEE International Conference on Parallel
2777 Architecture and Compilation Techniques, pages 7-16, Juan-les-Pins,
2778 september 2004.
2780 @item
2781 @anchor{Bas11}[Bas11] C. Bastoul. A Specification and a Library for Data 
2782 Exchange in Polyhedral Compilation Tools. Technical Report,
2783 Paris-Sud University, France, September 2011.
2785 @item
2786 @anchor{Fea92}[Fea92] P. Feautrier Some efficient solutions to the affine
2787 scheduling problem, part II: multidimensional time.
2788 International Journal of Parallel Programming, 21(6):389--420, December 1992.
2790 @item
2791 @anchor{Gri04}[Gri04] M. Griebl. Automatic parallelization of loop programs
2792 for distributed memory architectures. Habilitation Thesis. Facult@"at f@"ur
2793 Mathematik und Informatik, Universit@"at Passau, 2004.
2794 @emph{http://www.infosun.fmi.uni-passau.de/cl/loopo/}
2796 @item
2797 @anchor{Qui00}[Qui00] F. Quiller@'e, S. Rajopadhye, and D. Wilde.
2798 Generation of efficient nested loops from polyhedra.
2799 International Journal of Parallel Programming, 28(5):469-498,
2800 october 2000.
2802 @item
2803 @anchor{Wil93}[Wil93] Doran K. Wilde.
2804 A library for doing polyhedral operations.
2805 Technical Report 785, IRISA, Rennes, France, 1993.
2807 @end itemize
2812 @c % /*************************************************************************
2813 @c %  *                       PART VI: END OF THE DOCUMENT                    *
2814 @c %  *************************************************************************/
2815 @c @unnumbered Index
2816      
2817 @c @printindex cp
2818      
2819 @bye