Hybrid precision (32, 64, GMP)
[openscop.git] / doc / openscop.texi
blob38ccb6b6e0280398e9cab96b1b79c7dca4beb610
1 \input texinfo
2 @c %
3 @c %  /**-----------------------------------------------------------------**
4 @c %   **                           OpenScop Library                      **
5 @c %   **-----------------------------------------------------------------**
6 @c %   **                            openscop.texi                        **
7 @c %   **-----------------------------------------------------------------**
8 @c %   **                 First version: september 10th 2006              **
9 @c %   **-----------------------------------------------------------------**/
10 @c %
11 @c % release 0.0: May 4th 2008
12 @c %
14 @c % /*************************************************************************
15 @c %  *                              PART I: HEADER                           *
16 @c %  *************************************************************************/
17 @c %**start of header
18 @setfilename openscop.info
19 @settitle OpenScop Specification and Library
21 @set EDITION 1.0
22 @set SPEC_VERSION 1.0
23 @set LIB_VERSION 0.5.0
24 @set UPDATED June 24 2011
25 @setchapternewpage odd
27 @c % This is to ask for A4 instead of Letter size document.
28 @iftex
29      @afourpaper
30 @end iftex
32 @c %**end of header
34 @c % /************************************************************************
35 @c %  *                PART II: SUMMARY DESCRIPTION AND COPYRIGHT            *
36 @c %  ************************************************************************/
38 @copying
39 This document describes OpenScop, a specification of a file format and a set
40 of data structures for polyhedral compilation tools to talk
41 together. It also describes briefly the OpenScop Library version @value{LIB_VERSION}, 
42 a Free Software that provides an example of OpenScop implementation.
44 It would be quite kind to refer at the present document in any publication that
45 results from the use of the OpenScop library:
47 @example
48 @@TechReport@{Bas11,
49 @ @ author =@ @ @ @ @ @ @{C\'edric Bastoul@},
50 @ @ title =@ @ @ @ @ @ @ @{OpenScop: A Specification and a Library for Data 
51 @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ Exchange in Polyhedral Compilation Tools@},
52 @ @ month =@ @ @ @ @ @ @ @{june@},
53 @ @ year =@ @ @ @ @ @ @ @ 2011,
54 @ @ institution = @{Paris-Sud University, France@}
56 @end example
58 Copyright @copyright{} 2011 Paris-Sud University and INRIA.
60 @c quotation
61 Permission is granted to copy, distribute and/or modify this document under
62 the terms of the GNU Free Documentation License, Version 1.2 published by the
63 Free Software Foundation; with no Invariant Sections, with no Front-Cover
64 Texts, and with no Back-Cover Texts. To receive a copy of the
65 GNU Free Documentation License, write to the Free Software Foundation, Inc.,
66 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA.
67 @c end quotation
68 @end copying
70 @c % /*************************************************************************
71 @c %  *                 PART III: TITLEPAGE, CONTENTS, COPYRIGHT              *
72 @c %  *************************************************************************/
73 @titlepage
74 @title OpenScop
75 @subtitle A Specification and a Library for Data Exchange in Polyhedral Compilation Tools
76 @subtitle Edition @value{EDITION}, for OpenScop Specification @value{SPEC_VERSION} and OpenScop Library @value{LIB_VERSION}
77 @subtitle @value{UPDATED}
78 @author C@'edric Bastoul
80 @c The following two commands start the copyright page.
81 @page
82 @vskip 0pt plus 1filll
83 @insertcopying
84 @end titlepage
86 @c Output the table of contents at the beginning.
87 @contents
89 @c % /*************************************************************************
90 @c %  *                     PART IV: TOP NODE AND MASTER MENU                 *
91 @c %  *************************************************************************/
92 @ifnottex
93 @node Top
94 @top OpenSCop
96 @insertcopying
97 @end ifnottex
99 @menu
100 * Introduction::
101 * Polyhedral Representation::
102 * OpenScop Specification::
103 * OpenScop Library::
104 * References::
105 @end menu
107 @c % /*************************************************************************
108 @c %  *                       PART V: BODY OF THE DOCUMENT                    *
109 @c %  *************************************************************************/
111 @c %  ****************************** INTRODUCTION ******************************
112 @node Introduction
113 @chapter Introduction
114 OpenScop is an open specification that defines a file format and a set of
115 data structures to represent a @emph{static control part} (SCoP for short),
116 i.e., a program part that can be represented in the @emph{polyhedral model}.
117 The goal of OpenScop is to provide a common interface to various
118 polyhedral compilation tools in order to simplify their interaction. 
120 Designing a single format for tools that have different purposes
121 (e.g., as different as code generation and data dependence analysis) may
122 sound strange at first. However we could observe that most available
123 polyhedral compilation tools during the last decade were manipulating
124 more or less the same kind of data (polyhedra, affine functions...) and
125 were actually sharing a part of their input (e.g., iteration domains and
126 context concepts are nearly everywhere). We could also observe that
127 those tools may rely on different internal representations, mostly based on
128 one of the major polyhedral libraries (e.g., Polylib, PPL or isl), and
129 this representation may change over time (e.g., when switching to a
130 more convenient polyhedral library).
131 The OpenScop aim is to provide a stable, unified format that offers a
132 durable guarantee that a tool can use an output or provide an input to
133 another tool without breaking a tool chain because of some internal
134 changes in one element of the chain. The other promise of OpenScop is
135 the ability to assemble or replace the basic blocks of a polyhedral
136 compilation framework at no, or at least low engineering cost.
138 The policy that drives OpenScop can be summarized by these three rules:
139 @itemize @bullet
140 @item  Embed the @emph{minimum} information to build a complete polyhedral
141        compilation framework in the so-called @emph{core part}
142        (to avoid as much as possible empty or useless information
143        for each tool).
144 @item  Provide a @emph{very stable} core part (so users have some
145        guarantee that they will not need to update their tool
146        because of frequent specification evolution),
147 @item  Provide a @emph{very flexible} extension part (so it can also
148        be used to test wild new ideas).
149 @end itemize
151 @noindent Another, more technical, rule may be added:
152 @itemize @bullet
153 @item  Avoid any need for external library or tool to support it
154        (i.e., it's not XML or YAML or anything like that).
155 @end itemize
157 The success of OpenScop in meeting its goals totally depends on its
158 acceptance by the tool developers (that have to support it in their tools).
159 To help them, we provide an example implementation: the OpenScop Library.
160 This library (and in particular its API) is not part of the OpenScop
161 specification (which includes only the file format and the set of data
162 structures). It is licensed under the 3-clause BSD license so developers may
163 feel free to use it in their code (either by linking it or copy-pasting its
164 code). This document also describes this library briefly (readers are
165 invited to read at its technical documentation).
166 The current version of the OpenScop Library is still under evaluation,
167 and there is no guarantee that the upward compatibility will be respected,
168 even if we do think so. A lot of reports are
169 necessary to freeze the library API. Thus you are very welcome and
170 encouraged to send reports on bugs, wishes, critics, comments, suggestions
171 or (please!) successful experiences to the OpenScop mailing list
172 @email{openscop-development@@googlegroups.com}.
174 This document is organized as follows. First, we provide some
175 background on the polyhedral model and how it is used to represent and to
176 manipulate programs (@pxref{Polyhedral Representation}). Next,
177 we describe the OpenScop specification, from the file format
178 (@pxref{OpenScop Core Part File Format Specification}) to the data structures
179 and the OpenScop Library API
180 (@pxref{OpenScop Core Part Data Structure Specification}).
181 Finally we will detail how to install the OpenScop Library
182 (@pxref{Installation}).
185 @c %  ******************* POLYHEDRAL REPRESENTATION OF PROGRAMS ****************
186 @node Polyhedral Representation
187 @chapter Polyhedral Representation of Programs
188 If you are reading at the OpenScop documentation, you probably don't need any
189 explanation about the polyhedral model. It is unlikely that someone will read
190 this paper by mistake. However some vicious advisor may ask their poor
191 engineers/interns/students
192 to work for the very first time on this exciting topic. Most papers on
193 polyhedral compilation are hard to read. Despite my efforts,
194 mine are no exception according to some reviewers. Hence I give there a new
195 try to provide a comprehensive explanation of the polyhedral model without the
196 size and style limits of a classical research paper.
198 Be aware that to be able to understand the polyhedral model, there are a few
199 prerequisites. You should not read the following while you still ignore
200 what is:
201 @itemize @bullet
202 @item  a @code{for} loop construction in C programs (@code{do} loops in FORTRAN are OK too!),
203 @item  an @emph{affine expression},
204 @item  a @emph{vector},
205 @item  a @emph{matrix},
206 @item  a @emph{matrix-vector multiply}.
207 @end itemize
208 If you do not know those concepts, please do some search and come back
209 afterwards. And if you are courageous enough, send me a few lines that
210 describe them so I can insert them here!
212 @menu
213 * Motivation::
214 * Thinking in Polyhedra::
215 * What's Next?::
216 @end menu
219 @node Motivation
220 @section Motivation: Program Transformations
222 A direct translation of high level programs written, e.g., in C, to assembly
223 then to object code is likely to produce (very) inefficient applications.
224 Architectures are
225 quite complex, including several levels of cache memory, many cores, deep
226 pipelines, various number of functional units, of registers etc.
227 The list of such
228 "architectural features" is growing with each new generation of processors.
229 To achieve the best performance, the object program must use
230 these features in a smart way.
231 Programmers use high level languages for productivity and portability:
232 typically they do not have to take care of the target architecture but
233 to ensure they write programs which produce the right output. Hence,
234 the problem of mapping the program to the target architecture in the most
235 efficient way is left to the compiler.
237 The compiler may see a high level program as a specification
238 @emph{of an output}. The program is a list of instructions to be executed to
239 produce the output. As long as the output is guaranteed to be as the
240 programmer specified in his code, the compiler is free to modify
241 the program.
242 For instance, let us imagine we are working on an architecture with only
243 three registers and we consider the following statements written by
244 a programmer:
246 @example
247 @group
248 x = a + b;
249 y = c + d;
250 z = a * b;
251 @end group
252 @end example
254 It is easy to see that we can reorder the three statements in any way without
255 modifying the semantics (no statement reads or writes a variable that another
256 statement writes). Because of the lack of registers, the solutions such that
257 the first and the third statements are one after the other are better
258 because @code{a} and @code{b} will be put in the processor registers by
259 one statement and can be reused directly by the other one
260 without reading from memory (this is called a @emph{data locality
261 improving} transformation). Hence a better statement order is, e.g.:
263 @example
264 @group
265 x = a + b;
266 z = a * b; // a and b are still in processor registers
267 y = c + d;
268 @end group
269 @end example
271 We can also notice that it is possible to run the three statements in
272 parallel (possibly on different processors). The programmer may
273 explicit this in a way the compiler
274 and/or the architecture is able to understand. For instance,
275 we can use OpenMP to describe parallelism
276 (this is called a @emph{parallelizing} transformation):
278 @example
279 @group
280 #pragma omp parallel sections
282    #pragma omp section
283    @{
284      x = a + b;
285    @}
286    #pragma omp section
287    @{
288      y = c + d;
289    @}
290    #pragma omp section
291    @{
292      z = a * b;
293    @}
295 @end group
296 @end example
298 However, the right way to optimize this program is probably a tradeoff
299 between these two techniques. This is true if, e.g., the target
300 architecture has some limitations to run too many operations in parallel,
301 or, like in our case, when some data may be reused by some processors.
302 Hence, the best optimization for our small example is probably the
303 following:
305 @example
306 @group
307 #pragma omp parallel sections
309    #pragma omp section
310    @{
311      x = a + b;
312      z = a * b;
313    @}
314    #pragma omp section
315    @{
316      y = c + d;
317    @}
319 @end group
320 @end example
322 This example is quite trivial because the statements are
323 executed only once. The real sport begins when we have to deal with loops,
324 as we will see momentarily. However, polyhedral compilation framework users
325 have to be conscious that we @emph{need} to transform programs to achieve
326 the best performance and that the best transformation  that has to be
327 discovered (at the price of many, many efforts) and performed may be
328 quite complex. Hence the need of powerful model and tools.
331 @node Thinking in Polyhedra
332 @section Thinking in Polyhedra
335 Since the very first compilers, the internal representation of programs
336 is the @emph{Abstract Syntax Tree}, or AST. In such representation,
337 each statement appears only once even if it is executed many times (e.g.,
338 when it is enclosed inside a loop). This is a limitation
339 for finding and applying complex transformations:
340 @itemize @bullet
341 @item It limits program analysis power. For instance if a statement
342       @emph{depends} on another statement (i.e., they access the same
343       memory location and at least one of these accesses is a write),
344       we will consider both statements as unique entities while the
345       dependence relation may involve only few statement executions.
346 @item It limits program transformation power. Loop transformations
347       operate on statement executions. For instance, because they
348       consider all statement executions at the same time, present day
349       production compilers are not able to achieve loop fusion
350       (that tries to merge the loop bodies of two loops) if the loop bounds
351       of the two loops do not match (yes, that's ridiculous).
352 @item It limits program manipulation flexibility.
353       Trees are very rigid data structures that are not easy to manipulate.
354       Program transformation may require very complex transformations that will
355       imply deep modifications of the control flow.
356 @end itemize
358 The Polyhedral Model is a convenient alternative representation which
359 combines analysis power, expressiveness and high flexibility. The drawback
360 is it breaks the classical structure of programs that every programmer
361 is familiar with. It requires some (real) efforts
362 to be smoothly manipulated, but it definitely worth it. It is based on three
363 main concepts, @emph{iteration domain},  @emph{scattering function} and
364 @emph{access function} that are described in depth in the
365 following sections.
367 A program part that can be represented using the Polyhedral Model is called
368 a @strong{Static Control Part} or @strong{SCoP} for short.
370 @menu
371 * Iteration Domain::
372 * Scattering Function::
373 * Access Function::
374 @end menu
376 @node Iteration Domain
377 @subsection Iteration Domain
379 The key aspect of the polyhedral model is to consider @emph{statement
380 instances}. A statement instance is @emph{one} execution of a statement.
381 A statement
382 outside a loop has only one instance while those inside loops may have many.
383 Let us consider the following code with two statements @code{S1}
384 and @code{S2}:
386 @example
387 @group
388 pi = 3.14;               // S1
389 for (i = 0; i < 5; i++)
390   A[i] = pi;             // S2
391 @end group
392 @end example
394 The list of statement instances is the following (we just have to fully
395 unroll the loop):
397 @example
398 @group
399 pi = 3.14;
400 A[0] = pi;
401 A[1] = pi;
402 A[2] = pi;
403 A[3] = pi;
404 A[4] = pi;
405 @end group
406 @end example
408 Each instance of a statement which is enclosed inside a loop may be referred
409 thanks to its outer loop counters (or @emph{iterators}). In the polyhedral
410 model we consider statements as functions of the outer loop counters that may
411 produce statement instances:
412 instead of simply "@code{S2}", we use preferably the notation @code{S2(i)}.
413 For instance we  denote the statement instance @code{A[3] = pi;} of the
414 previous example as @code{S2(3)}. This means @emph{instance of
415 statement @code{S2} for} @code{i = 3}.
416 If a statement @code{S3} is enclosed inside two loops of iterators @code{i}
417 (outermost loop) and @code{j} (innermost loop), we would denote it
418 @code{S3(i,j)}, and so on with more enclosing loops.
420 The ordered list
421 of iterators (ordered from the outermost iterator to the innermost iterator)
422 is called the @strong{iteration vector}. For instance the iteration vector for
423 @code{S3} is @code{(i,j)}, for @code{S2} it is @code{(i)}, and for @code{S1}
424 it is empty since it has no enclosing loop: @code{()}. A more precise reading
425 at the notation @code{S2(3)} would show that it denotes the instance of
426 statement @code{S2} for the iteration vector @code{(2)}.
428 Obviously, dealing with statement instances does not mean we have to unroll all
429 loops. First because there would be probably too many instances to deal with,
430 and second because we probably just do not know how many instances there are.
431 For instance in the following loop it is impossible to know (at compile time)
432 how many times the statement @code{S3} will be executed:
434 @example
435 @group
436 for (i = 2; i <= N; i++)
437   for (j = 2; j <= N; j++)
438     A[i] = pi;             // S3
439 @end group
440 @end example
442 @noindent Such a loop is said to be @emph{parametric}: it depends on
443 (at least) a value called a @emph{parameter} which is not modified
444 during the execution of the whole loop, but is unknown at compile time.
445 Here, the only parameter is @code{N}.
447 A compact way to represent all the instances of a given statement
448 is to consider the set of all possible values of its iteration vector.
449 This set is called the @strong{iteration domain}. It can be conveniently
450 described thanks to all the constraints on the various iterators the statement
451 depends on. For instance, let us consider
452 the statement @code{S3} of the previous program. The iteration domain is the set
453 of iteration vectors @code{(i,j)}. Because of the parameter, we are not able to
454 achieve a precise list of all possible values. It would look like this:
456 @example
457 @group
458 (2,2)  (2,3)  (2,4)  ...  (2,N)
459 (3,2)  (3,3)  (3,4)  ...  (3,N)
460 ...    ...    ...    ...  ...
461 (N,2)  (N,3)  (N,4)  ...  (N,N)
462 @end group
463 @end example
465 @noindent A better way is to say it is the set
466 of iteration vectors @code{(i,j)} such that @code{i} is an integer greater or
467 equal than 2 and lower or equal than @code{N}, and @code{j} is an integer
468 greater or equal than 2 and lower or equal than @code{N}. This may be written
469 in the following mathematical form:
471 @tex
472 $$D _{S3} =  \{(i,j) \in Z^2 \; | \; 2 \leq i \leq N \land 2 \leq j \leq N \}$$
473 @end tex
475 @ifnottex
476 @example
477 @group
478 D_S3 =  @{(i,j) in Z^2 | 2 <= i <= N && 2 <= j <= N @}
479 @end group
480 @end example
481 @end ifnottex
483 @noindent It is easy to see that this iteration domain is a part of the
484 2-dimensional space
485 @tex
486 $Z^2$.
487 @end tex
488 @ifnottex
489 @example
490 @group
491 Z^2.
492 @end group
493 @end example
494 @end ifnottex
495 We often use in our research papers a graphical representation that gives a
496 better view of this subspace:
498 @image{images/basic1,4cm}
500 @noindent Here, the iteration domain is specified thanks to a set of
501 constraints. When those constraints are affine and
502 depend only on the outer loop counters and some parameters, the set of
503 constraints defines a @emph{polyhedron} (more precisely this is a
504 @emph{Z-polyhedron}, but we use @emph{polyhedron} for short).
505 Hence the @emph{polyhedral model}!
507 To manipulate a set of affine constraints easily, we rely on a matrix
508 representation. To write it, we use the @emph{homogeneous} iteration vector:
509 it is simply the iteration vector with some additional dimensions to
510 represent the parameters and the constant.
511 For instance for the statement @code{S3}, the
512 iteration vector in homogeneous coordinates is @code{(i, j, N, 1)}
513 (we will now call it @emph{iteration vector} directly for short).
514 Then we write all the constraints as affine inequalities of the form
515 @emph{affine constraint}
516 @tex
517 $\geq 0$.
518 @end tex
519 @ifnottex
520 @code{ >= 0}.
521 @end ifnottex
522 For instance for the statement @code{S3} the set of constraints is:
524 @tex
526 \hbox{$ \cases{  i         - 2  &$\geq 0$\cr
527                 -i     + N      &$\geq 0$\cr
528                      j     - 2  &$\geq 0$\cr
529                     -j + N      &$\geq 0$}$}
531 @end tex
533 @ifnottex
534 @example
535 @group
536     i - 2 >= 0
537    -i + N >= 0
538     j - 2 >= 0
539    -j + N >= 0
540 @end group
541 @end example
542 @end ifnottex
544 @noindent Lastly, we translate the constraint system to the form
545 @strong{domain matrix}@code{ * }@emph{iteration vector}@code{ >= 0}:
547 @c Thanks to Harald Devos for the TeX :-) !  
548 @tex
550 \left[
551 \matrix{
552  1 &  0  & 0  & -2 \cr
553 -1 &  0  & 1  &  0 \cr
554  0 &  1  & 0  & -2 \cr
555  0 & -1  & 1  &  0
557 \right]
558 \left(
559 \matrix{
560 i \cr
561 j \cr
562 N \cr
565 \right)
567 \left(
568 \matrix{
569 0 \cr
570 0 \cr
571 0 \cr
574 \right)
576 @end tex
577 @ifnottex
578 @example
579 @group
580 [  1  0  0 -2 ]   [ i ]    [ 0 ]
581 [ -1  0  1  0 ]   [ j ]    [ 0 ]
582 [  0  1  0 -2 ] * [ N ] >= [ 0 ]
583 [  0 -1  1  0 ]   [ 1 ]    [ 0 ]
584 @end group
585 @end example
586 @end ifnottex
588 @noindent @strong{The domain matrix will be used in all our tools to provide the
589 information on the iteration domain of a given statement (the iteration vector
590 is in general an implicit information).}
592 @node Scattering Function
593 @subsection Scattering Function
595 There is no ordering information inside the iteration domain: it only describes
596 the set of statement instances but @strong{not} the order in which they have
597 to be executed relatively to each other. In the past the lexicographic order
598 of the iteration domain was considered, this is no more true
599 (especially when using CLooG). If we do not provide any ordering information, this
600 means that the statement instances may be executed in any order
601 (this is useful, e.g., to specify parallelism). However, some statement instances
602 may depend on some others and it may be critical to enforce a given order (or
603 non-order). Hence we need another information.
605 We call @emph{scattering} any kind of ordering information in the polyhedral
606 model. There exists many kind of ordering, such as @emph{allocation},
607 @emph{scheduling}, @emph{chunking} etc. They are all expressed
608 in the same way, i.e., using @emph{logical stamps}, but they may have
609 different semantics.
611 In the case of @strong{scheduling}, the logical stamps are logical dates that
612 express at which date a statement instance has to be executed. For instance,
613 let us consider the following three statements:
615 @example
616 @group
617 x = a + b;   // S1
618 y = c + d;   // S2
619 z = a * b;   // S3
620 @end group
621 @end example
623 @noindent The scheduling of a statement @code{S} is typically
624 denoted by
625 @tex
626 $\theta_{S}$.
627 @end tex
628 @ifnottex
629 T_S.
630 @end ifnottex
631 Let us consider the following logical dates for each statement:
633 @tex
634 @example
635 @group
636 $\theta_{S1} = 2$
637 $\theta_{S2} = 3$
638 $\theta_{S3} = 1$
639 @end group
640 @end example
641 @end tex
643 @ifnottex
644 @example
645 @group
646 T_S1 = 1
647 T_S2 = 2
648 T_S3 = 3
649 @end group
650 @end example
651 @end ifnottex
653 @noindent It means that statement @code{S3} has to be executed at logical date
654 @code{1}, statement @code{S1} has to be executed at logical date
655 @code{2} and statement @code{S2} has to be executed at logical date
656 @code{3}. The target code has to respect this scheduling (the order of
657 the logical dates), hence it would look like the following where the
658 variable @code{t} denotes the time:
660 @example
661 @group
662 t = 1;
663 z = a * b;   // S3
664 t = 2;
665 x = a + b;   // S1
666 t = 3;
667 y = c + d;   // S2
668 @end group
669 @end example
671 @noindent When some statements share the same logical date, this means that,
672 once the program reaches this logical date, the two statements can be executed
673 in any order, or better, in parallel. For instance let us consider the
674 following scheduling:
676 @tex
677 @example
678 @group
679 $\theta_{S1} = 1$
680 $\theta_{S2} = 2$
681 $\theta_{S3} = 1$
682 @end group
683 @end example
684 @end tex
686 @ifnottex
687 @example
688 @group
689 T_S1 = 1
690 T_S2 = 2
691 T_S3 = 1
692 @end group
693 @end example
694 @end ifnottex
696 @noindent Statements @code{S1} and @code{S3} have the same logical date,
697 moreover, @code{S2} has a greater logical date than @code{S1} and @code{S3}.
698 Hence the target code would be:
700 @example
701 @group
702 t = 1;
703 #pragma omp parallel sections
705    #pragma omp section
706    @{
707      x = a + b;   // S1
708    @}
709    #pragma omp section
710    @{
711      z = a * b;   // S3
712    @}
714 t = 2;
715 y = c + d;        // S2
716 @end group
717 @end example
719 Logical dates may be multidimensional, as clocks: the first dimension
720 may correspond to days (most significant), the next one to hours (less
721 significant), the third to minutes and so on. For instance we can consider
722 the following multidimensional schedules for our example:
724 @tex
725 @example
726 @group
727 $\theta_{S1} = (1,1)$
728 $\theta_{S2} = (2,1)$
729 $\theta_{S3} = (1,2)$
730 @end group
731 @end example
732 @end tex
734 @ifnottex
735 @example
736 @group
737 T_S1 = (1,1)
738 T_S2 = (2,1)
739 T_S3 = (1,2)
740 @end group
741 @end example
742 @end ifnottex
744 @noindent It is not very hard to decypher the meaning of such scheduling.
745 Because of the first dimension, statements @code{S1} and @code{S3} will be
746 executed before statement @code{S2} (@code{S1} and @code{S3} are executed at
747 day 1, while @code{S2} is executed at day 2). The second dimension is not
748 really useful there for @code{S2} because it is the only statement executed
749 at day 2. Nevertheless it allows to order @code{S1} and
750 @code{S3} relatively to each other since @code{S1} is executed at hour 1 of day
751 1 while @code{S3} is executed at hour 2 of day 1.
752 The corresponding target code is the following, with some
753 additional time variables for a better view of the ordering (@code{t1}
754 corresponds to the first time dimension, @code{t2} to the second one):
756 @example
757 @group
758 t1 = 1;
759 t2 = 1;
760 x = a + b;   // S1
761 t2 = 2;
762 z = a * b;   // S3
763 t1 = 2;
764 t2 = 1;
765 y = c + d;   // S2
766 @end group
767 @end example
769 In the case of @strong{allocation} (in the literature we can find some
770 papers calling it @emph{placement}), the logical stamp is a processor
771 number expressing on which processor a statement instance has to be
772 executed. Typically, allocations are written in the same way as scheduling.
773 Here, we denote it @math{P_S} for a statement @code{S}.
774 For instance, let us consider the following allocation:
776 @tex
777 @example
778 @group
779 $P_{S1} = 1$
780 $P_{S2} = 2$
781 $P_{S3} = 1$
782 @end group
783 @end example
784 @end tex
786 @ifnottex
787 @example
788 @group
789 P_S1 = 1
790 P_S2 = 2
791 P_S3 = 1
792 @end group
793 @end example
794 @end ifnottex
796 @noindent The corresponding target code has to take into account that both
797 statements @code{S1} and @code{S3} have to be executed on the same processor
798 (they have the same logical number 1) and that statement @code{S2} has
799 to be executed on another processor (logical number 2). A possible target code
800 is the following:
802 @example
803 @group
804 #pragma omp parallel sections
806    #pragma omp section
807    @{
808      // Logical processor 1
809      x = a + b;   // S1
810      z = a * b;   // S3
811    @}
812    #pragma omp section
813    @{
814      // Logical processor 2
815      y = c + d;   // S2
816    @}
818 @end group
819 @end example
821 @noindent We can note that no order has been specified for the
822 statements @code{S1} and @code{S3} that are executed on the same processor.
823 Hence any order is satisfying. For sake of flexibility, it is usual to build
824 a scattering whose various dimensions do not have the same semantics. A
825 typical construction is @emph{space/time mapping} where the first @code{n}
826 dimensions are devoted to allocation, then the last @code{m}
827 dimensions are devoted to scheduling. Typically, space/time mapping is
828 written in the same way as scheduling.
829 Here we denote it @math{M_S} for a statement @code{S}.
830 For instance, let us consider the following space/time mapping for our
831 example where one dimension is devoted to mapping and one dimension is
832 devoted to scheduling:
834 @tex
835 @example
836 @group
837 $M_{S1} = (1,2)$
838 $M_{S2} = (2,1)$
839 $M_{S3} = (1,1)$
840 @end group
841 @end example
842 @end tex
844 @ifnottex
845 @example
846 @group
847 M_S1 = (1,2)
848 M_S2 = (2,1)
849 M_S3 = (1,1)
850 @end group
851 @end example
852 @end ifnottex
854 @noindent Here we have the same first dimension as the previous example, thus
855 the allocation of the statements to processors is the same. The second
856 dimension precises on a given processor at which logical date a statement
857 instance has to be executed. Here, the statement @code{S1} is executed at
858 day 2 on processor 1 while the statement @code{S3} is executed at day 1 onto
859 the same processor. It follows this space/time mapping corresponds to the
860 following target code (we added an additional variable to represent the
861 local logical clocks):
863 @example
864 @group
865 #pragma omp parallel sections
867    #pragma omp section
868    @{
869      // Logical processor 1
870      t = 1;
871      z = a * b;   // S3
872      t = 2;
873      x = a + b;   // S1
874    @}
875    #pragma omp section
876    @{
877      // Logical processor 2
878      t = 1;
879      y = c + d;   // S2
880    @}
882 @end group
883 @end example
885 For the same reason as discussed for iteration domains
886 (@pxref{Iteration Domain}), it is not possible to define a scattering for
887 each statement instance, especially if the statement belongs to a
888 (possibly parametric) loop. The iteration vector fully defines an
889 instance of a given statement. Thus, a practical way to provide a scattering
890 for each instance of a given statement is to use a @emph{function}
891 that depends on the iteration vector. In this way the function may associate
892 to each iteration vector a different scattering. We call these functions
893 @strong{scattering functions}. Scattering functions are @emph{affine}
894 functions of the outer loop counter and the global parameters.
895 For instance, let us consider the following source code:
897 @example
898 @group
899 for (i = 2; i <= 4; i++)
900   for (j = 2; j <= 4; j++)
901     P[i+j] += A[i] + B[j]; // S4
902 @end group
903 @end example
905 @noindent The iteration domain of the statement @code{S4} is:
908 @tex
909 $$D _{S4} =  \{(i,j) \in Z^2 \; | \; 2 \leq i \leq 4 \land 2 \leq j \leq 4 \}.$$
910 @end tex
911 @ifnottex
912 @example
913 @group
914 D_S4=  @{(i,j) in Z^2 | 2 <= i <= 4 && 2 <= j <= 4 @}.
915 @end group
916 @end example
917 @end ifnottex
919 @noindent If you are still not comfortable with the mathematical notation, it
920 corresponds to the following graphical representation:
922 @image{images/basic2,3cm}
924 @noindent The list of the statement instances of @code{S4} (the integer
925 points of its iteration domain) corresponds to the following iteration vectors:
927 @example
928 @group
929 iteration vector
930      (2,2)
931      (2,3)
932      (2,4)
933      (3,2)
934      (3,3)
935      (3,4)
936      (4,2)
937      (4,3)
938      (4,4)
939 @end group
940 @end example
942 @noindent Let us suppose we want to schedule the instances of the statement
943 @code{S4} (the integer points of its iteration domain) using the following
944 scheduling function:
946 @tex
947 @example
948 @group
949 $\theta_{S4}(i, j) = (j+2, 3*i+j)$
950 @end group
951 @end example
952 @end tex
954 @ifnottex
955 @example
956 @group
957 T_S4(i,j) = (j+2,3*i+j)
958 @end group
959 @end example
960 @end ifnottex
962 @noindent We only need to apply the function to each iteration vector to find
963 the logical date of each instance:
965 @example
966 @group
967 iteration vector       logical date
968      (2,2)       -->       (4,8)
969      (2,3)       -->       (5,9)
970      (2,4)       -->       (6,10)
971      (3,2)       -->       (4,11)
972      (3,3)       -->       (5,12)
973      (3,4)       -->       (6,13)
974      (4,2)       -->       (4,14)
975      (4,3)       -->       (5,15)
976      (4,4)       -->       (6,16)
977 @end group
978 @end example
980 The polyhedral model users do not have to take care about the generation of a
981 target code that respects the scattering: the
982 CLooG@footnote{@url{http://www.cloog.org}} tool is there to
983 solve the problem quite easily. For the previous
984 example, the target code would be the following (@code{t1} and @code{t2}
985 correspond to the two dimensions of the logical date, the reader may
986 take care that this code actually implements the scattering function):
988 @example
989 @group
990 for (t1 = 4; t1 <= 6; t1++) @{
991   for (t2 = t1+4; t2 <= t1+10; t2++) @{
992     if ((-t1+t2+2)%3 == 0) @{
993       i = (-t1+t2+2)/3 ;
994       j = t1-2 ;
995       P[i+j] += A[i] + B[j]; // S4
996     @}
997   @}
999 @end group
1000 @end example
1004 Obviously with such a twisted scheduling, it is hard to see the "meaning"
1005 of the transformation. To name any kind of program transformation as
1006 a magic spell ("tile", "fuse", "skew"...) is an old bad habit which is not
1007 relevant anymore in the polyhedral model: a scheduling may be an arbitrary
1008 complex sequence of basic-old-good transformations. Nevertheless it is most
1009 of the time quite easy to translate well known transformations to schedules.
1010 For instance, let us consider this new scheduling function:
1012 @tex
1013 @example
1014 @group
1015 $\theta_{S4}(i,j) = (j,i)$
1016 @end group
1017 @end example
1018 @end tex
1020 @ifnottex
1021 @example
1022 @group
1023 T_S4(i,j) = (j,i)
1024 @end group
1025 @end example
1026 @end ifnottex
1028 @noindent Using CLooG, we can generate the target code:
1030 @example
1031 @group
1032 for (t1 = 2; t1 <= 4; t1++) @{
1033   for (t2 = 2; t2 <= 4; t2++) @{
1034     i = t2;
1035     j = t1;
1036     P[i+j] += A[i] + B[j]; // S4
1037   @}
1039 @end group
1040 @end example
1043 @noindent It is easy to see (and analyze) that it corresponds to a classical
1044 @emph{loop interchange} transformation.
1046 A very useful example of multi-dimensional scattering functions is
1047 the @strong{scheduling of the original program}.
1048 The method to compute it is quite simple (@pxref{Fea92}). The idea is to
1049 build an abstract syntax tree of the program and to read the scheduling for
1050 each statement. For instance, let us consider the following implementation of
1051 a Cholesky factorization:
1053 @example
1054 @group
1055 /* A Cholesky factorization kernel. */
1056 for (i=1;i<=N;i++) @{
1057   for (j=1;j<=i-1;j++) @{
1058     a[i][i] -= a[i][j] ;           // S1
1059   @}
1060   a[i][i] = sqrt(a[i][i]) ;        // S2
1061   for (j=i+1;j<=N;j++) @{
1062     for (k=1;k<=i-1;k++) @{
1063       a[j][i] -= a[j][k]*a[i][k] ; // S3
1064     @}
1065     a[j][i] /= a[i][i] ;           // S4
1066     @}
1067   @}
1069 @end group
1070 @end example
1072 @noindent The corresponding abstract syntax tree is shown in the following
1073 figure. It directly gives the scattering functions (schedules) for all the
1074 statements of the program (just follow the paths).
1076 @image{images/tree,6cm}
1078 @tex
1080 \hbox{$ \cases{ \theta _{S1}(i,j)    &$=  (0,i,0,j,0)$\cr
1081                 \theta _{S2}(i)      &$=  (0,i,1)$\cr
1082                 \theta _{S3}(i,j,k)  &$=  (0,i,2,j,0,k,0)$\cr
1083                 \theta _{S4}(i,j)    &$=  (0,i,2,j,1)$}$}
1085 @end tex
1087 @ifnottex
1088 @example
1089 @group
1090 T_S1(i,j)   = (0,i,0,j,0)
1091 T_S2(i)     = (0,i,1)
1092 T_S3(i,j,k) = (0,i,2,j,0,k,0)
1093 T_S4(i,j)   = (0,i,2,j,1)
1094 @end group
1095 @end example
1096 @end ifnottex
1098 @noindent These schedules depend on the iterators and give for each instance
1099 of each statement a unique execution date. Using such scattering functions
1100 allows CLooG to re-generate the input code.
1102 @noindent To easily manipulate the scattering function of any
1103 statement @code{S}, we translate it to the matrix form:
1104 @tex
1105 @math{\theta_S}(@emph{iteration vector})
1106 @end tex
1107 @ifnottex
1108 T_S(@emph{iteration vector})
1109 @end ifnottex
1110 @code{ = }@strong{scattering matrix}@code{ * }@emph{iteration vector}.
1111 For instance let us consider again our previous example
1112 @tex
1113 $\theta_{S4}(i, j) = (j+2, 3*i+j).$
1114 @end tex
1115 @ifnottex
1116 T_S4(i,j) = (j+2,3*i+j).
1117 @end ifnottex
1118 We write it in the following way:
1119 @tex
1121 \theta_{S4}
1122 \left(
1123 \matrix{
1124  i \cr
1125  j \cr
1128 \right)
1130 \left[
1131 \matrix{
1132  0 &  0  & 2 \cr
1133  3 &  1  & 0 
1135 \right]
1136 \left(
1137 \matrix{
1138  i \cr
1139  j \cr
1142 \right)
1144 @end tex
1145 @ifnottex
1146 @example
1147 @group
1148      [ i ]    [  0  1  2 ]   [ i ]
1149 T_S4([ j ]) = [  3  1  0 ] * [ j ]
1150      [ 1 ]                   [ 1 ]
1151 @end group
1152 @end example
1153 @end ifnottex
1155 @noindent @strong{The scattering matrix will be used in all our tools to provide
1156 the information on the scattering of a given statement
1157 (the iteration vector is in general an implicit information).}
1160 @node Access Function
1161 @subsection Access Function
1163 Before applying any transformation, it is essential to deeply analyze both the
1164 original program and the transformation to ensure the transformation does not
1165 imply any modification of the original program semantics. In the polyhedral
1166 model, we are able to achieve
1167 an exact analysis when all the memory accesses are made through arrays
1168 (note that variables are a particular case of arrays since they are simply
1169 arrays with only one memory location) with affine subscripts that depend
1170 on outer loop counters and global parameters (note that @emph{subscripts}
1171 are sometimes called @emph{index} or @emph{accesses} in the literature).
1173 For instance let us consider the array access @code{A[2*i+j][j][i+N]}. It has
1174 three dimensions, each subscript dimension is an affine form of some outer loop
1175 iterarors (@code{i} and @code{j}) and global parameters (@code{N}) hence
1176 it corresponds to an acceptable array access to be analyzed in the
1177 polyhedral model.
1179 Each array access can target a different memory cell depending on the
1180 statement instance, i.e., depending on the iteration vector.
1181 Thus we use access functions (or subscript functions, or index functions, as you
1182 prefer to call it) depending on the iteration vector to describe an array
1183 access. In our example, the access function would be written
1184 @math{F_A(i, j) = (2*i+j, j, i+N)}.
1186 @noindent To easily manipulate the access function of any
1187 array @code{A}, we translate it to the matrix form:
1188 @math{F_A}(@emph{iteration vector})
1189 @code{ = }@strong{access matrix}@code{ * }@emph{iteration vector}.
1190 For instance let us consider again our previous example. We would
1191 write it in the following way:
1192 @tex
1195 \left(
1196 \matrix{
1197  i \cr
1198  j \cr
1199  N \cr
1202 \right)
1204 \left[
1205 \matrix{
1206  2 &  1  &  0 &  0 \cr
1207  0 &  1  &  0 &  0 \cr
1208  1 &  0  &  1 &  0
1210 \right]
1211 \left(
1212 \matrix{
1213  i \cr
1214  j \cr
1215  N \cr
1218 \right)
1220 @end tex
1221 @ifnottex
1222 @example
1223 @group
1224     [ i ]    [  2  1  0  0 ]   [ i ]
1225 F_A([ j ]) = [  0  1  0  0 ] * [ j ]
1226     [ N ]    [  1  0  1  0 ]   [ N ]
1227     [ 1 ]                      [ 1 ]
1228 @end group
1229 @end example
1230 @end ifnottex
1232 @noindent @strong{The access matrix will be used in all our tools to provide the
1233 information on the access of a given statement
1234 (the iteration vector is in general an implicit information).}
1236 @node What's Next?
1237 @section What's Next?
1239 OK, now you have an idea about how we do represent a program part in the
1240 polyhedral model. You know the three main concepts, namely: domain, scattering
1241 and access. What can you do with this?! Well, pretty much anything related
1242 to code restructuring! The core idea will be to rely on the mathematical
1243 representation to extract useful information about your
1244 code (data reuse, parallelism...) and to generate a scattering
1245 to benefit from the properties you analysed.
1246 However, OpenScop's documentation is not the right
1247 place to learn at this (OpenScop is all about representation, not about
1248 manipulation). Probably it is the right time for you to
1249 have a look at:
1250 @itemize @bullet
1251 @item PoCC @url{http://pocc.sourceforge.net}
1252 @item Pluto @url{http://pluto-compiler.sourceforge.net}
1253 @end itemize
1255 @noindent Have fun :-) !
1258 @c %  *********************** OpenScop Specification **************************
1259 @node OpenScop Specification
1260 @chapter OpenScop Specification
1262 OpenScop provides an explicit polyhedral representation of a static control
1263 part. It has been designed by various polyhedral compilation tool writers from
1264 various institutions. It builds on previous popular polyhedral file and data
1265 structure formats (such as @emph{.cloog} and CLooG data structures) to provide
1266 a unique, extensible format to most polyhedral compilation tools. It
1267 is composed of two parts. The first part, the so-called 
1268 @emph{core part}, is devoted to the polyhedral representation of a SCoP.
1269 It contains what is strictly necessary to build a
1270 complete source-to-source framework in the polyhedral model and to output a
1271 semantically equivalent code for the SCoP, from analysis to code generation.
1272 The second part of the format, the so-called @emph{extension part},
1273 contains extensions to provide additional informations to some tools.
1275 @menu
1276 * Core Part::
1277 * Extension Part::
1278 * History::
1279 @end menu
1282 @c %/*************************************************************************
1283 @c % *                             CORE PART                                 *
1284 @c % *************************************************************************/
1286 @node Core Part
1287 @section Core Part
1289 @menu
1290 * Preliminary Example::
1291 * OpenScop Core Part File Format Specification::
1292 * OpenScop Core Part Data Structure Specification::
1293 @end menu
1295 @c %/*************************************************************************
1296 @c % *                         PRELIMINARY EXAMPLE                           *
1297 @c % *************************************************************************/
1298 @node Preliminary Example
1299 @subsection Preliminary Example
1300 OpenScop is a specification for representing static control program parts in
1301 the polyhedral model. Thus, we can translate some code parts to an equivalent
1302 OpenScop representation. As an example, let us consider the
1303 following matrix-multiply kernel:
1305 @example
1306 #pragma scop
1307 if (N > 0) @{
1308   for (i = 0; i < N; i++) @{
1309     for (j = 0; j < N; j++) @{
1310       C[i][j] = 0.0;
1311       for (k = 0; k < N; k++)
1312         C[i][j] = C[i][j] + A[i][k] * B[k][j];
1313     @}
1314   @}
1316 @end example
1318 The Clan@footnote{@url{http://www.lri.fr/~bastoul/development/clan/}}
1319 tool may be used to translate this code part to an OpenScop
1320 representation automatically. The @code{#pragma scop} is used here for
1321 Clan, but some other tool may not need it. Here is the result of the
1322 translation to an OpenScop textual representation.
1324 @sp 1
1325 @center @strong{DON'T PANIC}
1326 @sp 1
1328 @noindent Explanations will follow and it is not
1329 as cryptic as it seems to be !
1330 @sp 1
1332 @example
1333 <OpenScop>
1335 # =============================================== Global
1336 # Backend Language
1339 # Context
1340 CONTEXT
1341 1 3 0 0 0 1
1342    1    1   -1    ## N-1 >= 0
1344 # Parameter names are provided
1346 # Parameter names
1349 # Number of statements
1352 # =============================================== Statement 1
1353 # Number of relations describing the statement
1356 # ----------------------------------------------  1.1 Domain
1357 DOMAIN
1358 4 5 2 0 0 1
1359 # e/i   i    j    N    1
1360    1    1    0    0    0    ## i >= 0
1361    1   -1    0    1   -1    ## -i+N-1 >= 0
1362    1    0    1    0    0    ## j >= 0
1363    1    0   -1    1   -1    ## -j+N-1 >= 0
1365 # ----------------------------------------------  1.2 Scattering
1366 SCATTERING
1367 5 10 5 2 0 1
1368 # e/i  s1   s2   s3   s4   s5    i    j    N    1 
1369    0   -1    0    0    0    0    0    0    0    0    ## s1 = 0
1370    0    0   -1    0    0    0    1    0    0    0    ## s2 = i
1371    0    0    0   -1    0    0    0    0    0    0    ## s3 = 0
1372    0    0    0    0   -1    0    0    1    0    0    ## s4 = j
1373    0    0    0    0    0   -1    0    0    0    0    ## s5 = 0
1375 # ----------------------------------------------  1.3 Access
1376 WRITE
1377 3 8 3 2 0 1
1378 # e/i  Arr  [1]  [2]   i    j    N    1
1379    0   -1    0    0    0    0    0    1    ## C
1380    0    0   -1    0    1    0    0    0    ##  [i]
1381    0    0    0   -1    0    1    0    0    ##     [j]
1383 # ----------------------------------------------  1.4 Body
1384 # Statement body is provided
1386 # Original iterator names
1387 i j 
1388 # Statement body
1389 C[i][j] = 0.0;
1392 # =============================================== Statement 2
1393 # Number of relations describing the statement
1396 # ----------------------------------------------  2.1 Domain
1397 DOMAIN
1398 6 6 3 0 0 1
1399 # e/i   i    j    k    N    1
1400    1    1    0    0    0    0    ## i >= 0
1401    1   -1    0    0    1   -1    ## -i+N-1 >= 0
1402    1    0    1    0    0    0    ## j >= 0
1403    1    0   -1    0    1   -1    ## -j+N-1 >= 0
1404    1    0    0    1    0    0    ## k >= 0
1405    1    0    0   -1    1   -1    ## -k+N-1 >= 0
1407 # ----------------------------------------------  2.2 Scattering
1408 SCATTERING
1409 7 13 7 3 0 1
1410 # e/i  s1   s2   s3   s4   s5   s6   s7    i    j    k    N    1
1411    0   -1    0    0    0    0    0    0    0    0    0    0    0   ## s1 = 0
1412    0    0   -1    0    0    0    0    0    1    0    0    0    0   ## s2 = i
1413    0    0    0   -1    0    0    0    0    0    0    0    0    0   ## s3 = 0
1414    0    0    0    0   -1    0    0    0    0    1    0    0    0   ## s4 = j
1415    0    0    0    0    0   -1    0    0    0    0    0    0    1   ## s5 = 1
1416    0    0    0    0    0    0   -1    0    0    0    1    0    0   ## s6 = k
1417    0    0    0    0    0    0    0   -1    0    0    0    0    0   ## s7 = 0
1419 # ----------------------------------------------  2.3 Access
1420 RDWR
1421 3 9 3 3 0 1
1422 # e/i  Arr  [1]  [2]   i    j    k    N    1
1423    0   -1    0    0    0    0    0    0    1    ## C
1424    0    0   -1    0    1    0    0    0    0    ##  [i]
1425    0    0    0   -1    0    1    0    0    0    ##     [j]
1427 READ
1428 3 9 3 3 0 1
1429 # e/i  Arr  [1]  [2]   i    j    k    N    1
1430    0   -1    0    0    0    0    0    0    2    ## A
1431    0    0   -1    0    1    0    0    0    0    ##  [i]
1432    0    0    0   -1    0    0    1    0    0    ##     [k]
1434 READ
1435 3 9 3 3 0 1
1436 # e/i  Arr  [1]  [2]   i    j    k    N    1
1437    0   -1    0    0    0    0    0    0    3    ## B
1438    0    0   -1    0    0    0    1    0    0    ##  [k]
1439    0    0    0   -1    0    1    0    0    0    ##     [j]
1441 # ----------------------------------------------  2.4 Body
1442 # Statement body is provided
1444 # Original iterator names
1445 i j k 
1446 # Statement body
1447 C[i][j] = C[i][j] + A[i][k] * B[k][j];
1449 </OpenScop>
1450 @end example
1453 We will not describe here precisely the structure and the components of this
1454 output, this is described in depth in a further section
1455 (@pxref{OpenScop Core Part File Format Specification}). This format
1456 has been designed to be a possible input or output file format of most of
1457 polyhedral compilation tools. If you read the description of the polyhedral
1458 representation of programs, you should already feel familiar with this file
1459 format (@pxref{Polyhedral Representation}).
1462 @c %/*************************************************************************
1463 @c % *                 CORE PART FILE FORMAT SPECIFICATION                   *
1464 @c % *************************************************************************/
1465 @node OpenScop Core Part File Format Specification
1466 @subsection OpenScop Core Part File Format Specification
1468 The following grammar describes the structure of the first part of the
1469 OpenScop file format where terminals are preceeded by "_". There can be
1470 at most one terminal per line in the file. Each
1471 relevant part will be explained in more details momentarily:
1473 @example
1474 OpenScop            ::= Start_tag Data End_tag
1475 Start_tag           ::= "<OpenScop>"
1476 End_tag             ::= "</OpenScop>"
1477 Data                ::= Context Statements
1478 Context             ::= Language Parameter_Domain Parameter_list
1479 Statements          ::= Nb_statements Statement_list
1480 Statement_list      ::= Statement Statement_list | (void)
1481 String_list         ::= _String   String_list    | (void)
1482 Relation_list       ::= _Relation Relation_list  | (void)
1483 Statement           ::= Statement_relations Body
1484 Body                ::= "0" | "1" Iterator_list Body_text
1485 Parameter_list      ::= "0" | "1" String_list
1486 Statement_relations ::= Nb_relations Relation_List 
1487 Parameter_domain    ::= _Relation
1488 Language            ::= _String
1489 Body_text           ::= _Text_line
1490 Nb_Relations        ::= _Integer
1491 @end example
1494 @itemize @bullet
1495 @item  @samp{Context} represents the global information of the SCoP. It
1496        consists on the target language, the global constraints on the
1497        parameters and optionally the parameter names which may be necessary
1498        for the code generation process. The constraints on the parameters
1499        are represented as a relation (@pxref{Context Domain Representation})
1500        with zero input and zero output dimensions. The parameter name
1501        list starts with an integer: a @samp{0} means that we don't provide
1502        the names while a @samp{1} means that the name list
1503        is provided afterwards. The ordering of the names in the list is
1504        meaningful: it must reflect the ordering used in the relation.
1505 @item  @samp{Statements} represents the information about the statements.
1506        @samp{Nb_statements} is the number of statements in the SCoP,
1507        i.e. the number of @samp{Statement} items in the @samp{Statement_list}.
1508        @samp{Statement} represents the information on a given statement.
1509        To each statement is associated a list of relations and,
1510        optionaly, a body. The list of relations may include
1511        one iteration domain (@pxref{Iteration Domain Representation}),
1512        one scattering relation (@pxref{Scattering Relation Representation})
1513        and several access relations (@pxref{Access Relation Representation}).
1514        There is no mandatory ordering, but for consistency reason it would
1515        be much appreciated that iteration domain comes first (if present)
1516        then scattering (if present), then accesses (if present).
1517        The statement body is an optional information. It is preceded by a
1518        boolean which precises whether it is provided or not. It is made of two
1519        parts: first, the list of surrounding loop counters in the original
1520        program and second, the text string of the statement. This
1521        representation allows to apply the substitution of the original
1522        iterators with new iterators in the target program.
1523 @end itemize
1525 The main parts of the OpenScop format (namely, iteration domains,
1526 scattering and access information) are detailed in the next subsections.
1528 @menu
1529 * Relation Representation::
1530 * Iteration Domain Representation::
1531 * Context Domain Representation::
1532 * Scattering Relation Representation::
1533 * Access Relation Representation::
1534 @end menu
1536 @node Relation Representation
1537 @subsubsection Relation Representation
1539 As shown by the grammar, the input file describes the various pieces of
1540 information based on strings, integers and @emph{relations}.
1541 Each relation is defined as a union of convex relations, each in turn is
1542 described by a set of constraints in an extended PolyLib format (@pxref{Wil93}).
1543 The number of elements in the union is given by an integer
1544 on a separate line, optionally followed by a comment starting with @samp{#}.
1545 This number of elements can be omitted when there is only one element.
1546 Each element in the union has the following syntax:
1548 @enumerate
1549 @item Some optional comment lines beginning with @samp{#}.
1550 @item A line with the type of the relation, possibly followed by comments.
1551       The type can be one of the following:
1552       @itemize @bullet
1553       @item @code{UNDEFINED}: generic relation,
1554       @item @code{CONTEXT}: for context information,
1555       @item @code{DOMAIN}: for iteration domains,
1556       @item @code{SCATTERING}: for scattering relation,
1557       @item @code{READ}: for read accesses,
1558       @item @code{WRITE}: for write accesses,
1559       @item @code{MAY_WRITE}: for may-write accesses,
1560       @end itemize
1561 @item A line with 6 numbers, possibly followed by comments:
1562       @enumerate
1563       @item the number of rows of the constraint matrix,
1564       @item the number of columns of the constraint matrix,
1565       @item the number of @emph{output dimensions},
1566       @item the number of @emph{input dimension},
1567       @item the number of @emph{local dimensions}
1568             (existentially quantified dimensions),
1569       @item the number of @emph{parameters}.
1570       @end enumerate
1571       The sum of the last four numbers should be equal to the number of columns
1572       minus two. The remaining two columns are the equality/inequality
1573       indicator and the constant term. The number of parameters should be the
1574       same for all relations in the entire OpenScop file or data structure.
1575 @item The constraint rows. Each row corresponds to a constraint the
1576       relation has to satisfy. Each row must be on a single line and is possibly
1577       followed by comments. The constraint is an equality @math{p(x) = 0} if the
1578       first element is 0, an inequality  @math{p(x) \geq 0} if the first element
1579       is 1. The next elements are the coefficients of the output dimensions,
1580       followed by coefficients of the input dimensions, the existentially
1581       quantified dimensions and finally the parameters.
1582       The last element is the constant term.
1583 @end enumerate
1585 This representation is the basis for several purposes. Examples for
1586 iteration domains (@pxref{Iteration Domain Representation}), scattering
1587 relations (@pxref{Scattering Relation Representation}) and
1588 access relations (@pxref{Access Relation Representation}) are provided in
1589 further sections.
1591 @node Iteration Domain Representation
1592 @subsubsection Iteration Domain Representation
1594 Iteration domain represents the set of instances of the corresponding statement.
1595 OpenScop iteration domains are represented as relations with the following
1596 conventions:
1597 @itemize @bullet
1598 @item the type is @code{DOMAIN},
1599 @item there is 0 input dimension,
1600 @item loop iterators correspond to output dimensions.
1601 @end itemize
1603 @noindent For instance, assuming that @samp{i}, @samp{j} and @samp{k} are the loop
1604 iterators and @samp{M} and @samp{N} are the parameters, the domain defined by
1605 the following constraints :
1607 @tex
1609 \hbox{$ \cases{ -i     + M &$\geq 0$\cr
1610                     -j + N &$\geq 0$\cr
1611                  i + j - k &$\geq 0$}$}
1613 @end tex
1614 @ifnottex
1615 @example
1616 @group
1617    -i + M >= 0
1618    -j + N >= 0
1619 i + j - k >= 0
1620 @end group
1621 @end example
1622 @end ifnottex
1624 @noindent can be written in the input file as follows:
1626 @example
1627 @group
1628 # This is an iteration domain
1629 DOMAIN
1630 1 # Number of relations in the union
1631 3 7 3 0 0 2                  # 3 rows, 7 cols: 3 output dims and 2 params
1632 # e/i  i   j   k   M   N   1
1633    1  -1   0   0   1   0   0 #    -i + M >= 0
1634    1   0  -1   0   0   1   0 #    -j + N >= 0
1635    1   1   1  -1   0   0   0 # i + j - k >= 0
1636 @end group
1637 @end example
1639 @noindent Equivalently, it can be written in the following way as the number
1640 of relations in the union can be omitted if it is 1:
1642 @example
1643 @group
1644 # This is an iteration domain
1645 DOMAIN
1646 3 7 3 0 0 2                  # 3 rows, 7 cols: 3 output dims and 2 params
1647 # e/i  i   j   k   M   N   1
1648    1  -1   0   0   1   0   0 #    -i + M >= 0
1649    1   0  -1   0   0   1   0 #    -j + N >= 0
1650    1   1   1  -1   0   0   0 # i + j - k >= 0
1651 @end group
1652 @end example
1654 @noindent As an example for unions, let us consider the following pseudo-code:
1656 @example
1657 @group
1658 for (i = 1; i <= N; i++) @{
1659   if ((i >= M) || (i <= 2*M))
1660     S1(i);
1662 @end group
1663 @end example
1665 @noindent The iteration domain of @samp{S1} can be divided into two
1666 relations and written in the OpenScop file as follows:
1668 @example
1669 @group
1670 # This is an iteration domain
1671 DOMAIN
1672 2 # Number of relations in the union
1673 # Union part No.1
1674 3 5 1 0 0 2          # 3 rows, 5 cols: 1 output dim and 2 params
1675 # e/i  i   M   N   1
1676    1   1   0   0  -1 #  i >= 1
1677    1  -1   0   1   0 #  i <= N
1678    1   1  -1   0   0 #  i >= M
1679 # Union part No.2
1680 3 5 1 0 0 2          # 3 rows, 5 cols: 1 output dim and 2 params
1681 # e/i  i   M   N   1
1682    1   1   0   0  -1 #  i >= 1
1683    1  -1   0   1   0 #  i <= N
1684    1  -1   2   0   0 #  i <= 2*M
1685 @end group
1686 @end example
1688 @noindent As an example for local dimensions (existentially quantified
1689 dimensions), let us consider the following pseudo-code:
1691 @example
1692 @group
1693 for (i = 1; i <= N; i++) @{
1694   if ((i % 2) == 0)
1695     S1(i);
1697 @end group
1698 @end example
1700 @noindent The iteration domain of @samp{S1} is composed of all even
1701 integer values between 1 and N. The "divisible by two" constraint can
1702 be expressed as follows: there exists an integer @samp{ld} such that
1703 @samp{i = 2*ld}. We encode this thanks to a new local dimension:
1705 @example
1706 @group
1707 # This is an iteration domain
1708 DOMAIN
1709 3 5 1 0 1 1          # 3 rows, 5 cols: 1 output dim, 1 local dim, 1 param
1710 # e/i  i  ld   N   1
1711    0   1  -2   0   0 #  i = 2*ld
1712    1   1   0   0   1 #  i >= 1
1713    1  -1   0   1   0 #  i <= N
1714 @end group
1715 @end example
1718 @node Context Domain Representation
1719 @subsubsection Context Domain Representation
1721 The context domain is a particular case of iteration domain
1722 (@pxref{Iteration Domain Representation}) where there are only
1723 constraints about parameters (no loop iterators). Hence it is the same
1724 as an iteration domain, with the following conventions:
1725 @itemize @bullet
1726 @item the type is @code{CONTEXT},
1727 @item there is 0 input dimension,
1728 @item there is 0 output dimension.
1729 @end itemize
1732 @node Scattering Relation Representation
1733 @subsubsection Scattering Relation Representation
1735 Scattering relation maps an iteration domain to a logical time and/or
1736 space (and/or) anything.
1737 OpenScop scattering information is represented as relations
1738 (@pxref{Relation Representation}) with the following conventions:
1740 @itemize @bullet
1741 @item the type is @code{SCATTERING},
1742 @item output dimensions correspond to scattering dimensions,
1743 @item loop iterators correspond to input dimensions.
1744 @end itemize
1746 As an example of a scattering relation and
1747 assuming that @samp{i}, @samp{j} and @samp{k} are the loop
1748 iterators and @samp{M} and @samp{N} are the parameters, take for instance:
1749 @tex
1750 $\theta_{S}(i,j,k) = (j+2,3*i+j,k+N+1).$
1751 @end tex
1752 @ifnottex
1753 @example
1754 T_@{S@}(i,j,k) = (j+2,3*i+j,k+N+1).
1755 @end example
1756 @end ifnottex
1757 We can represent it in the following way:
1759 @example
1760 @group
1761 # A scattering relation
1762 SCATTERING
1763 # 3 rows, 10 columns: 3 scattering dimensions, 3 iterators, 2 parameters
1764 3 10 3 3 0 2
1765 # e/i s1  s2  s3   i   j   k   M   N   1
1766    0  -1   0   0   0   1   0   0   0   2 # s1 = j+2
1767    0   0  -1   0   3   1   0   0   0   0 # s2 = 3*i+j
1768    0   0   0  -1   0   0   1   0   1   1 # s3 = k+N+1
1769 @end group
1770 @end example
1772 @node Access Relation Representation
1773 @subsubsection Access Relation Representation
1775 Access relation maps an iteration domain to an array space.
1776 Each array accessed in the SCoP has a unique identification number.
1777 OpenScop relation information is represented as relations
1778 (@pxref{Relation Representation}) with the following conventions:
1780 @itemize @bullet
1781 @item the type is one of the following:
1782       @itemize @bullet
1783       @item @code{READ}, for read accesses,
1784       @item @code{WRITE}, for write accesses,
1785       @item @code{MAY_WRITE}, for may write accesses,
1786       @end itemize
1787 @item output dimensions correspond to the array identifier and dimensions,
1788 @item the first output dimension corresponds to the array identifier,
1789 @item the (i+1)th output dimension corresponds to the ith array dimension (i>1),
1790 @item loop iterators correspond to input dimensions.
1791 @end itemize
1793 As an example of a scattering relation and
1794 assuming that @samp{i}, @samp{j} and @samp{k} are the loop
1795 iterators and @samp{M} and @samp{N} are the parameters, let us consider
1796 the array access @code{A[2*i+j][j][i+N]} (the identifier of @code{A} is 42),
1797 and let us suppose this is a read access. Its representation would be the
1798 following:
1800 @example
1801 @group
1802 # A read access relation
1803 READ
1804 # 4 rows, 11 columns: 4 array dimensions, 3 iterators, 2 parameters
1805 4 11 4 3 0 2
1806 # e/i Arr [1] [2] [3]  i   j   k   M   N   1
1807    0  -1   0   0   0   0   0   0   0   0  42   # A
1808    0   0  -1   0   0   2   1   0   0   0   0   #  [2*i+j]
1809    0   0   0  -1   0   0   1   0   0   0   0   #         [j]
1810    0   0   0   0  -1   1   0   0   0   1   0   #            [i+N]
1811 @end group
1812 @end example
1814 To understand this representation, consider that OpenScop accesses
1815 are general memory accesses and not array accesses. The memory is
1816 seen as a big array @code{Mem} while usual array names correspond to
1817 the first dimension. Hence our example translates to @code{Mem[42][2*i+j][j][i+N]}.
1819 Unions of access relations are allowed. In this case, each union part must
1820 refer at the same array identifier, and the number of dimensions must be
1821 consistent.
1823 @c %/*************************************************************************
1824 @c % *                 CORE PART DATA STRUCTURE SPECIFICATION                *
1825 @c % *************************************************************************/
1826 @node OpenScop Core Part Data Structure Specification
1827 @subsection OpenScop Core Part Data Structure Specification
1829 The OpenScop specification offers a small set of C data structures devoted to
1830 represent a SCoP in memory in a convenient way. Using them in some tool or
1831 library may greatly facilitate its interaction with other tools or libraries
1832 which rely on this representation as well. Every field may not be useful for
1833 a given tool or library. A general rule for all the data structure is
1834 that a @code{NULL} pointer or a -1 integer value means the information is
1835 not present. Contrary to engineering time, memory is cheap today, so it's much
1836 probably not a big deal that some fields are left empty. Every field may not
1837 be enough for a given tool or library. In this case it is much recommended
1838 to provide a new extension which may be reused by other users
1839 (@pxref{Extension Part}).
1841 Each tool or library may have its own implementation of the OpenScop
1842 data structures. The type names should not be the same as those provided
1843 as an example here (they correspond to the OpenScop Library implementation).
1844 The names of the fields, and their ordering, should however be the same. In this
1845 way, the interaction between tools and libraries should be as simple as a cast.
1847 Before reading at the OpenScop data structures, it is much recommended to
1848 read at the OpenScop file format description, as it is quite close to this
1849 representation (@pxref{OpenScop Core Part File Format Specification}).
1851 @menu
1852 * openscop_relation_t::
1853 * openscop_relation_list_t::
1854 * openscop_body_t::
1855 * openscop_statement_t::
1856 * openscop_extension_id_t::
1857 * openscop_extension_t::
1858 * openscop_scop_t::
1859 @end menu
1861 @node openscop_relation_t
1862 @subsubsection openscop_relation_t
1864 @example
1865 @group
1866 struct openscop_relation @{
1867   int type;                        /* What this relation is encoding */ 
1868   int precision;                   /* Precision of the matrix elements */ 
1869   int nb_rows;                     /* Number of rows */
1870   int nb_columns;                  /* Number of columns */
1871   int nb_output_dims;              /* Number of output dimensions */
1872   int nb_input_dims;               /* Number of input dimensions */
1873   int nb_local_dims;               /* Number of local dimensions */
1874   int nb_parameters;               /* Number of parameters */
1875   void ** m;                       /* Matrix of constraints */
1876   struct openscop_relation * next; /* Next relation in the union */
1878 typedef struct openscop_relation   openscop_relation_t;
1879 typedef struct openscop_relation * openscop_relation_p;
1880 @end group
1881 @end example
1883 @noindent The @code{openscop_relation_t} structure stores a part of an
1884 union of relations. A union of relation is a @code{NULL}-terminated
1885 linked list of union parts (@code{next} field). The @code{type} field
1886 may provide some information about what the relation is encoding:
1887 @itemize @bullet
1888 @item -1: undefined (@code{OPENSCOP_UNDEFINED}),
1889 @item 2: context domain (@code{OPENSCOP_TYPE_CONTEXT}),
1890 @item 3: iteration domain (@code{OPENSCOP_TYPE_DOMAIN}),
1891 @item 4: scattering relation (@code{OPENSCOP_TYPE_SCATTERING}),
1892 @item 6: read access relation (@code{OPENSCOP_TYPE_READ}),
1893 @item 7: write access relation (@code{OPENSCOP_TYPE_WRITE}),
1894 @item 8: may write access relation (@code{OPENSCOP_TYPE_MAY_WRITE}),
1895 @end itemize
1896 The various numbers provide the details on the relation itself
1897 (@pxref{Relation Representation}) while the @code{m} field points to
1898 the constraint matrix. The precision of the constraint matrix elements is
1899 provided by the @code{precision} field. It can take the following
1900 values:
1901 @itemize @bullet
1902 @item 32: 32 bits precision, elements are @code{long int}
1903       (@code{OPENSCOP_PRECISION_SP}),
1904 @item 64: 64 bits precision, elements are @code{long long int}
1905       (@code{OPENSCOP_PRECISION_DP}),
1906 @item 0: multiple precision, elements are GNU GMP Library's
1907       @code{mpz_t} (@code{OPENSCOP_PRECISION_MP}).
1908 @end itemize
1910 @node openscop_relation_list_t
1911 @subsubsection openscop_relation_list_t
1913 @example
1914 @group
1915 struct openscop_relation_list @{
1916   openscop_relation_p elt;              /* Element of the list */
1917   struct openscop_relation_list * next; /* Next element of the list */
1919 typedef struct openscop_relation_list   openscop_relation_list_t;
1920 typedef struct openscop_relation_list * openscop_relation_list_p;
1921 @end group
1922 @end example
1924 @noindent The @code{openscop_relation_list_t} structure is a @code{NULL}-terminated
1925 linked list of @code{openscop_relation_t} data structures.
1926 @code{elt} is a relation element of the list and @code{next} is the pointer to
1927 the next element of the list.
1929 @node openscop_body_t
1930 @subsubsection openscop_body_t
1932 @example
1933 @group
1934 struct openscop_body @{
1935   int type;          /* Type of iterators and expressions */
1936   void ** iterators; /* NULL-terminated array of original iterators */
1937   void * expression; /* Original statement expression */
1939 typedef struct openscop_body   openscop_body_t;
1940 typedef struct openscop_body * openscop_body_p;
1941 @end group
1942 @end example
1944 @noindent The @code{openscop_body_t} structure stores a statement body.
1945 The @code{expression} field contains the information about the
1946 statement in the original program. The @code{iterators} field is a
1947 NULL-terminated array of iterators surrounding the original statement
1948 in the original program. The order matters: @code{iterators[0]} corresponds
1949 to the outermost loop iterator for the statement, @code{iterators[1]}
1950 corresponds to the second outermost loop iterator, and so on.
1951 Statement body information may be strings of characters
1952 @code{(char *)} or a generic pointer to anything else @code{(void *)}
1953 depending on the value of the @code{type} field: 1 (OPENSCOP_TYPE_STRING)
1954 means the information is textual while 0 (OPENSCOP_TYPE_GENERIC)
1955 means the information is generic.
1957 @node openscop_statement_t
1958 @subsubsection openscop_statement_t
1960 @example
1961 @group
1962 struct openscop_statement @{
1963   openscop_relation_p domain;       /* Iteration domain */
1964   openscop_relation_p scattering;   /* Scattering relation */
1965   openscop_relation_list_p access;  /* Array access relations */
1966   openscop_body_p body;             /* Statement body information */
1967   void * usr;                       /* A user-defined field */
1968   struct openscop_statement * next; /* Next statement in the list */
1970 typedef struct openscop_statement   openscop_statement_t;
1971 typedef struct openscop_statement * openscop_statement_p;
1972 @end group
1973 @end example
1975 @noindent The @code{openscop_statement_t} structure represents a node
1976 in a @code{NULL}-terminated linked list of statements. Each node contains the
1977 useful information for a given statement to process it within a polyhedral
1978 framework. The order in the list may matter for naming conventions
1979 (e.g. "S1" for the first statement in the list). The iteration domain
1980 and the scattering are represented using an @code{openscop_relation_p}
1981 structure while the accesses are using a list of
1982 relations: one for each memory access in the statement. The
1983 @code{body} field provides information about the statement body. It is
1984 possible to use the @code{usr} field, but it has to be totally managed
1985 by the user.
1987 @node openscop_extension_id_t
1988 @subsubsection openscop_extension_id_t
1990 @example
1991 @group
1992 typedef void   (*openscop_idump_f) (FILE *, void *, int);
1993 typedef void   (*openscop_dump_f)  (FILE *, void *);
1994 typedef char * (*openscop_sprint_f)(void *);
1995 typedef void * (*openscop_sread_f) (char *);
1996 typedef void * (*openscop_malloc_f)();
1997 typedef void   (*openscop_free_f)  (void *);
1998 typedef void * (*openscop_clone_f) (void *);
1999 typedef int    (*openscop_equal_f) (void *, void *);
2001 struct openscop_extension_id @{
2002   char * URI;               /* Unique extension identifier string */
2003   openscop_idump_f  idump;  /* Pointer to extension idump function */
2004   openscop_dump_f   dump;   /* Pointer to extension dump function */
2005   openscop_sprint_f sprint; /* Pointer to extension sprint function */
2006   openscop_sread_f  sread;  /* Pointer to extension sread function */
2007   openscop_malloc_f malloc; /* Pointer to extension malloc function */
2008   openscop_free_f   free;   /* Pointer to extension free function */
2009   openscop_clone_f  clone;  /* Pointer to extension clone function */
2010   openscop_equal_f  equal;  /* Pointer to extension equal function */
2011   struct openscop_extension_id * next; /**< Next id in the list */
2013 typedef struct openscop_extension_id   openscop_extension_id_t;
2014 typedef struct openscop_extension_id * openscop_extension_id_p;
2015 @end group
2016 @end example
2018 @noindent The @code{openscop_extension_id_t} structure represents a
2019 node in a @code{NULL}-terminated list of extension ids. Each node stores the
2020 @emph{identity} of an extension, i.e., its unique name (@code{URI}) and
2021 the function pointers to all the base functions it has to provide.
2022 Extension providers will find information relative to those functions
2023 in the OpenScop Library description (@pxref{Base Functions})
2024 and the section dedicated to writing extensions
2025 (@pxref{Extension Development}).
2027 @node openscop_extension_t
2028 @subsubsection openscop_extension_t
2030 @example
2031 @group
2032 struct openscop_extension @{
2033   openscop_extension_id_p id;       /* This extension's identity */
2034   void * extension;                 /* Pointer to the extension itself */
2035   struct openscop_extension * next; /* Next extension in the list */
2037 typedef struct openscop_extension   openscop_extension_t;
2038 typedef struct openscop_extension * openscop_extension_p;
2039 @end group
2040 @end example
2042 @noindent The @code{openscop_extension_t} structure represents a node in a
2043 @code{NULL}-terminated list of extensions. It stores an extension to the core
2044 OpenScop representation. The @code{id} field gives the identity of what is
2045 pointed by the @code{extension} field. An OpenScop implementation is not
2046 required to support any extension. It must warn the user that a given identity
2047 is not supported and ignore it during the processing.
2049 @node openscop_scop_t
2050 @subsubsection openscop_scop_t
2051 @example
2052 @group
2053 struct openscop_scop @{
2054   int version;                      /* Version of the data structure */
2055   char * language;                  /* Target language */
2056   openscop_relation_p context;      /* Constraints on the parameters */
2057   int parameter_type;               /* Type of the parameters */
2058   void ** parameters;               /* NULL-terminated array of parameters*/
2059   openscop_statement_p statement;   /* Statement list */
2060   openscop_extension_id_p registry; /* List of registered extensions */
2061   openscop_extension_p extension;   /* Extension list */
2062   void * usr;                       /* A user-defined field */
2063   struct openscop_scop * next;      /* Next scop in the list */
2065 typedef struct openscop_scop   openscop_scop_t;
2066 typedef struct openscop_scop * openscop_scop_p;
2067 @end group
2068 @end example
2070 @noindent @code{openscop_scop_t} represents a node in a
2071 @code{NULL}-terminated list of scops. It stores the useful informations
2072 of a static control part of a program to process it within a polyhedral
2073 framework. To prepare OpenScop specification evolution, the @code{version}
2074 field tells the version of the data structure. It should be set to 1 for
2075 now (and hopefully a very, very, long time).
2076 It contains the informations about the context: the target language
2077 in the @code{language} field, the constraints on the
2078 global parameters in the @code{context} field and the parameters
2079 in the @code{parameters} field. The order matters: @code{parameters[0]}
2080 corresponds to the first parameter column in the context and the
2081 relation, @code{parameters[1]} corresponds to the second one, and so on.
2082 The parameter information can be either
2083 generic (@code{void *}) or textual (@code{char *}) depending on the
2084 @code{parameter_type} field: 1 (OPENSCOP_TYPE_STRING)
2085 means the information is textual while 0 (OPENSCOP_TYPE_GENERIC)
2086 means the information is generic. Finally, it contains the list of
2087 statements @code{statement}, the list of registered extensions
2088 @code{registry} and the list of extentions @code{extension}.
2090 As an example, let us consider again the matrix multiply program
2091 (@pxref{Preliminary Example}).
2092 The next figure gives a possible representation in memory for this
2093 SCoP thanks to the OpenScop data structures (it has been actually printed
2094 by the @code{openscop_scop_dump} function):
2096 @c @smallexample
2097 @example
2098 +-- openscop_scop_t
2099 |    |    
2100 |    Version: 1
2101 |    |    
2102 |    Language: C
2103 |    |    
2104 |    +-- openscop_relation_t (CONTEXT, 64 bits)
2105 |    |    1 3 0 0 0 1
2106 |    |    [   1   1  -1 ]
2107 |    |    
2108 |    +-- parameters: N
2109 |    |    
2110 |    +-- openscop_statement_t (S1)
2111 |    |    |    
2112 |    |    +-- openscop_relation_t (DOMAIN, 64 bits)
2113 |    |    |    4 5 2 0 0 1
2114 |    |    |    [   1   1   0   0   0 ]
2115 |    |    |    [   1  -1   0   1  -1 ]
2116 |    |    |    [   1   0   1   0   0 ]
2117 |    |    |    [   1   0  -1   1  -1 ]
2118 |    |    |    
2119 |    |    +-- openscop_relation_t (SCATTERING, 64 bits)
2120 |    |    |    5 10 5 2 0 1
2121 |    |    |    [   0  -1   0   0   0   0   0   0   0   0 ]
2122 |    |    |    [   0   0  -1   0   0   0   1   0   0   0 ]
2123 |    |    |    [   0   0   0  -1   0   0   0   0   0   0 ]
2124 |    |    |    [   0   0   0   0  -1   0   0   1   0   0 ]
2125 |    |    |    [   0   0   0   0   0  -1   0   0   0   0 ]
2126 |    |    |    
2127 |    |    +-- openscop_relation_list_t
2128 |    |    |    |    
2129 |    |    |    +-- openscop_relation_t (WRITE, 64 bits)
2130 |    |    |    |    3 8 3 2 0 1
2131 |    |    |    |    [   0  -1   0   0   0   0   0   1 ]
2132 |    |    |    |    [   0   0  -1   0   1   0   0   0 ]
2133 |    |    |    |    [   0   0   0  -1   0   1   0   0 ]
2134 |    |    |    |    
2135 |    |    |    
2136 |    |    +-- openscop_body_t
2137 |    |    |    |    
2138 |    |    |    +-- original iterator strings: i j
2139 |    |    |    |    
2140 |    |    |    +-- Original expression: C[i][j] = 0.0;
2141 |    |    |    |    
2142 |    |    |    
2143 |    |    V
2144 |    |  openscop_statement_t (S2)
2145 |    |    |    
2146 |    |    +-- openscop_relation_t (DOMAIN, 64 bits)
2147 |    |    |    6 6 3 0 0 1
2148 |    |    |    [   1   1   0   0   0   0 ]
2149 |    |    |    [   1  -1   0   0   1  -1 ]
2150 |    |    |    [   1   0   1   0   0   0 ]
2151 |    |    |    [   1   0  -1   0   1  -1 ]
2152 |    |    |    [   1   0   0   1   0   0 ]
2153 |    |    |    [   1   0   0  -1   1  -1 ]
2154 |    |    |    
2155 |    |    +-- openscop_relation_t (SCATTERING, 64 bits)
2156 |    |    |    7 13 7 3 0 1
2157 |    |    |    [   0  -1   0   0   0   0   0   0   0   0   0   0   0 ]
2158 |    |    |    [   0   0  -1   0   0   0   0   0   1   0   0   0   0 ]
2159 |    |    |    [   0   0   0  -1   0   0   0   0   0   0   0   0   0 ]
2160 |    |    |    [   0   0   0   0  -1   0   0   0   0   1   0   0   0 ]
2161 |    |    |    [   0   0   0   0   0  -1   0   0   0   0   0   0   1 ]
2162 |    |    |    [   0   0   0   0   0   0  -1   0   0   0   1   0   0 ]
2163 |    |    |    [   0   0   0   0   0   0   0  -1   0   0   0   0   0 ]
2164 |    |    |    
2165 |    |    +-- openscop_relation_list_t
2166 |    |    |    |    
2167 |    |    |    +-- openscop_relation_t (WRITE, 64 bits)
2168 |    |    |    |    3 9 3 3 0 1
2169 |    |    |    |    [   0  -1   0   0   0   0   0   0   1 ]
2170 |    |    |    |    [   0   0  -1   0   1   0   0   0   0 ]
2171 |    |    |    |    [   0   0   0  -1   0   1   0   0   0 ]
2172 |    |    |    |    
2173 |    |    |    V
2174 |    |    |  openscop_relation_list_t
2175 |    |    |    |    
2176 |    |    |    +-- openscop_relation_t (READ, 64 bits)
2177 |    |    |    |    3 9 3 3 0 1
2178 |    |    |    |    [   0  -1   0   0   0   0   0   0   1 ]
2179 |    |    |    |    [   0   0  -1   0   1   0   0   0   0 ]
2180 |    |    |    |    [   0   0   0  -1   0   1   0   0   0 ]
2181 |    |    |    |    
2182 |    |    |    V
2183 |    |    |  openscop_relation_list_t
2184 |    |    |    |    
2185 |    |    |    +-- openscop_relation_t (READ, 64 bits)
2186 |    |    |    |    3 9 3 3 0 1
2187 |    |    |    |    [   0  -1   0   0   0   0   0   0   2 ]
2188 |    |    |    |    [   0   0  -1   0   1   0   0   0   0 ]
2189 |    |    |    |    [   0   0   0  -1   0   0   1   0   0 ]
2190 |    |    |    |    
2191 |    |    |    V
2192 |    |    |  openscop_relation_list_t
2193 |    |    |    |    
2194 |    |    |    +-- openscop_relation_t (READ, 64 bits)
2195 |    |    |    |    3 9 3 3 0 1
2196 |    |    |    |    [   0  -1   0   0   0   0   0   0   3 ]
2197 |    |    |    |    [   0   0  -1   0   0   0   1   0   0 ]
2198 |    |    |    |    [   0   0   0  -1   0   1   0   0   0 ]
2199 |    |    |    |    
2200 |    |    |    
2201 |    |    +-- openscop_body_t
2202 |    |    |    |    
2203 |    |    |    +-- original iterator strings: i j k
2204 |    |    |    |    
2205 |    |    |    +-- Original expression: C[i][j] = C[i][j] + A[i][k]*B[k][j];
2206 |    |    |    |    
2207 |    |    |    
2208 |    |    
2209 |    +-- NULL extension_id
2210 |    |    
2211 |    +-- NULL extension
2212 |    |    
2213 |    
2214 @end example
2215 @c @end smallexample
2218 @c %/*************************************************************************
2219 @c % *                           EXTENSION PART                              *
2220 @c % *************************************************************************/
2222 @node Extension Part
2223 @section Extension Part
2225 The core part of the OpenScop representation embeds what is strictly
2226 necessary to build a complete source-to-source polyhedral framework.
2227 However it may not be enough. Hence, OpenScop offers a very flexible
2228 extension part. Actually, the only constraint to build an extension is
2229 to request the OpenScop maintainer for a unique extension name: its URI
2230 (ask the maintainer through the OpenScop mailing list
2231 @email{openscop-development@@googlegroups.com}).
2233 The policy to support extensions is the following and is pretty simple: an
2234 OpenScop implementation is not required to support any extension. If it
2235 is processing an OpenScop file or data structure which contains an
2236 extension which is not supported, it must (1) warn the user with the 
2237 mention of the URI of the non-supported extension
2238 and (2) ignore this extension.
2240 Extensions in an OpenScop file are provided after the core part, without
2241 any specific order. Each extension is delimited using
2242 XML-like tags corresponding to its URI (e.g., if the extension has the URI
2243 @code{foo}, the begin tag is @code{<foo>} and the end tag is @code{</foo>}).
2244 There is no specification or preferred way to write the extension body.
2245 Extensions in an OpenScop data structure must be accessible through one
2246 pointer. This pointer will be stored in the @code{extension}
2247 field of an @code{openscop_extension_t} container. There must be only
2248 one extension with the same URI in an OpenScop file or data
2249 structure.
2251 Extension writers may write a short documentation about their extension to
2252 be added to this document. For consistency reason, this
2253 documentation should comply to the documentation of the
2254 @code{comment} option (@pxref{Comment Extension}). To describe the
2255 file format, it is allowed to reuse the existing rules and terminals
2256 present in the OpenScop core part file format without defining them
2257 (@pxref{OpenScop Core Part File Format Specification}). By sending a
2258 documentation, you accept it to be added to this document. In
2259 particular, the sender fully accepts the license and copyright notice.
2261 @menu
2262 * Comment Extension::
2263 * Arrays Extension::
2264 * Lines Extension::
2265 * Irregular Extension::
2266 @end menu
2268 @c ---------------------------------------------------------------------------
2270 @node Comment Extension
2271 @subsection Comment Extension
2273 @itemize @bullet
2274 @item Number: @code{2}.
2275 @item Name: @code{comment}.
2276 @item Author: C@'edric Bastoul <cedric.bastoul@@u-psud.fr>.
2277 @item Purpose: the @code{comment} extension stores a textual string.
2278 @end itemize
2280 @menu
2281 * Comment Extension File Format::
2282 * Comment Extension Data Structure Format::
2283 @end menu
2285 @node Comment Extension File Format
2286 @subsubsection Comment Extension File Format
2288 The @code{comment} extension file format respects the following
2289 grammar:
2290 @example
2291 Comment             ::= Begin_tag Body End_tag
2292 Body                ::= _Text
2293 Begin_tag           ::= "<comment>"
2294 End_tag             ::= "</comment>"
2295 @end example
2297 @noindent An example of textual @code{comment} extension is the following:
2298 @example
2299 @group
2300 <comment>
2301 This is a comment string.
2302 </comment>
2303 @end group
2304 @end example
2306 @node Comment Extension Data Structure Format
2307 @subsubsection Comment Extension Data Structure Format
2309 The @code{comment} extension data structure is the following:
2310 @example
2311 @group
2312 struct openscop_comment @{
2313   char * comment;  /* Comment message as a 0-terminated string */
2315 typedef struct openscop_comment   openscop_comment_t;
2316 typedef struct openscop_comment * openscop_comment_p;
2317 @end group
2318 @end example
2320 @c ---------------------------------------------------------------------------
2323 @node Arrays Extension
2324 @subsection Arrays Extension
2326 @itemize @bullet
2327 @item Number: @code{3}.
2328 @item Name: @code{arrays}.
2329 @item Author: C@'edric Bastoul <cedric.bastoul@@u-psud.fr>.
2330 @item Purpose: the @code{arrays} extension provides a set of textual array
2331 names corresponding to the array identifiers used in the access relations.
2332 @end itemize
2334 @menu
2335 * Arrays Extension File Format::
2336 * Arrays Extension Data Structure Format::
2337 @end menu
2339 @node Arrays Extension File Format
2340 @subsubsection Arrays Extension File Format
2342 The @code{arrays} extension file format respects the following
2343 grammar:
2344 @example
2345 Arrays              ::= Begin_tag Body End_tag
2346 Body                ::= Nb_items Item_list
2347 Item_List           ::= Item Item_list | (void)
2348 Item                ::= Identifier Name
2349 Nb_items            ::= _Integer
2350 Identifier          ::= _Integer
2351 Name                ::= _String
2352 Begin_tag           ::= "<arrays>"
2353 End_tag             ::= "</arrays>"
2354 @end example
2356 @noindent The number of array names is provided on the first line,
2357 then each following line contains a pair identifier-name.
2358 For instance, the following example is a correct textual @code{arrays}
2359 extension. It corresponds to the array names of the preliminary example
2360 (@pxref{Preliminary Example}):
2362 @example
2363 @group
2364 <arrays>
2365 # Number of array names:
2367 1 C # Identifier 1 corresponds to array name "C" 
2368 3 B # Identifier 3 corresponds to array name "B" 
2369 2 A # Identifier 2 corresponds to array name "A" 
2370 </arrays>
2371 @end group
2372 @end example
2374 @node Arrays Extension Data Structure Format
2375 @subsubsection Arrays Extension Data Structure Format
2377 The @code{arrays} extension data structure is the following:
2379 @example
2380 @group
2381 struct openscop_arrays @{
2382   int nb_names;      /* Number of names */
2383   int  *  id;        /* Array of nb_names identifiers */
2384   char ** names;     /* Array of nb_names names */
2386 typedef struct openscop_arrays   openscop_arrays_t;
2387 typedef struct openscop_arrays * openscop_arrays_p;
2388 @end group
2389 @end example
2391 @noindent Each name has a name string and an identifier: the ith name has name
2392 string @code{names[i]} and identifier @code{id[i]}.
2395 @c ---------------------------------------------------------------------------
2397 @node Lines Extension
2398 @subsection Lines Extension
2400 @menu
2401 * Lines Extension File Format::
2402 * Lines Extension Data Structure Format::
2403 @end menu
2405 @node Lines Extension File Format
2406 @subsubsection Lines Extension File Format
2408 @node Lines Extension Data Structure Format
2409 @subsubsection Lines Extension Data Structure Format
2411 @c ---------------------------------------------------------------------------
2413 @node Irregular Extension
2414 @subsection Irregular Extension
2416 @menu
2417 * Irregular Extension File Format::
2418 * Irregular Extension Data Structure Format::
2419 @end menu
2422 @node Irregular Extension File Format
2423 @subsubsection Irregular Extension File Format
2425 @node Irregular Extension Data Structure Format
2426 @subsubsection Irregular Extension Data Structure Format
2428 @c ---------------------------------------------------------------------------
2430 @node History
2431 @section History
2433 OpenScop is a follow-up of Louis-No@"el Pouchet et al.'s ScopLib effort which
2434 was itself based on C@'edric Bastoul et al.'s Clan tool. People involved in
2435 OpenScop's genesis are:
2436 @itemize @bullet
2437 @item C@'edric Bastoul
2438 @item Uday Bondhugula
2439 @item Tobias Grosser
2440 @item Louis-No@"el Pouchet
2441 @item Sven Verdoolaege
2442 @end itemize
2444 @c %/*************************************************************************
2445 @c % *                          OpenScop LIBRARY                             *
2446 @c % *************************************************************************/
2448 @node OpenScop Library
2449 @chapter OpenScop Library
2451 The OpenScop Library is an example implementation of the OpenScop specification.
2452 Its API is not part of the OpenScop specification. 
2453 It offers basic functionalities to manipulate the OpenScop data structures
2454 (allocate, free, copy, dump, etc.) and file format (read, print, etc.).
2455 The OpenScop Library is @emph{not} a polyhedral library. OpenScop is an
2456 exchange format, and the OpenScop Library reflects this. 
2458 It is a Free Software using the 3-clause BSD License.
2459 Programmers should feel free to use
2460 it or copy/paste its code in any project, Open Source or not@footnote{Closed
2461 source projects should consider to provide some OpenScop file input
2462 and output, so they can be incorporated to any OpenScop-based tool chain.}.
2464 @menu
2465 * Precision::
2466 * Base Functions::
2467 * Example of OpenScop Library Utilization::
2468 * Installation::
2469 * Documentation::
2470 * Development::
2471 @end menu
2473 @node Precision
2474 @section Precision
2476 The OpenScop specification does not impose a specific type for the
2477 constraint matrix elements. For a maximum flexibility, the OpenScop library
2478 offers an hybrid precision implementation. It supports 32 bits, 64 bits and
2479 multiple precision (relying on GNU GMP) relations transparently. At relation
2480 allocation time, users have two ways to set the precision. The first way is
2481 to call an allocation function with a precision parameter. The second way is
2482 to rely on the environment variable @code{OPENSCOP_PRECISION}.
2483 The accepted values for this variable are @code{32} for 32 bits precision,
2484 @code{64} for 64 bits precision and @code{0} for multiple precision. When this
2485 variable is set, its value becomes the default precision for relation elements.
2486 For instance, to ensure the OpenScop library will use 64 bits precision
2487 by default, the user may set: 
2488 @example
2489 export OPENSCOP_PRECISION=64
2490 @end example
2491 @noindent if his shell is, e.g., bash or
2492 @example
2493 setenv OPENSCOP_PRECISION 64
2494 @end example
2495 @noindent if his shell is, e.g., tcsh. The user should ad this line to
2496 his .bashrc or .tcshrc (or whatever convenient file) to make this
2497 setting permanent. 
2499 @node Base Functions
2500 @section Base Functions
2502 The OpenScop library provides, for each OpenScop data structure,
2503 a set of functions devoted to basic manipulation, conversion
2504 from file format to data structures and from data structures to
2505 file format. The naming convention is consistent for all data
2506 structures. Hence, the function prototypes differ only with the
2507 name of the data structure. In the following, we will use the
2508 generic term of @emph{structure} to refer at any OpenScop
2509 data structure. For instance the
2510 @code{openscop_}@emph{structure}@code{_malloc()} function is a
2511 generic name can be instantiated to
2512 @code{openscop_relation_malloc()} or
2513 @code{openscop_statement_malloc()} etc.
2515 We present in this documentation only
2516 the main functions. Many other utility functions are provided
2517 to ease OpenScop format manipulation. The reader is invited to
2518 refer at the technical documentation to learn everything about the
2519 OpenScop Library.
2521 @menu
2522 * Dumping::
2523 * Printing::
2524 * Reading::
2525 * Allocating::
2526 * Deallocating::
2527 * Cloning::
2528 * Testing::
2529 @end menu
2532 @node Dumping
2533 @subsection Dumping: openscop_@emph{structure}_dump and idump 
2535 @example
2536 @group
2537 void openscop_@emph{structure}_dump(FILE * output, openscop_@emph{structure}_p s);
2538 void openscop_@emph{structure}_idump(FILE * output, openscop_@emph{structure}_p s,
2539                               int i);
2540 @end group
2541 @end example
2543 @noindent Each OpenScop data structure has a dumping functions
2544 as shown above. Dumping means writing down the content of the data
2545 structure pointed by @code{s} (and its fields recursively)
2546 in a textual form to the
2547 @code{output} file (the file, possibly @code{stdout}, has to be open
2548 for writing). The textual form is not the OpenScop file format but
2549 another representation closer to the internal representation in
2550 memory and mainly intended for debugging purpose. The @code{idump}
2551 function has an additional integer parameter which corresponds to
2552 an indentation level.
2554 @node Printing
2555 @subsection Printing: openscop_@emph{structure}_print
2557 @example
2558 @group
2559 void openscop_@emph{structure}_print(FILE * output, openscop_@emph{structure}_p s);
2560 @end group
2561 @end example
2563 @noindent Each OpenScop data structure has a pretty printing function
2564 as shown above. It prints the content of the data
2565 structure pointed by @code{s} (and its fields recursively)
2566 according to the OpenScop file format
2567 (@pxref{OpenScop Core Part File Format Specification}) to the
2568 @code{output} file (the file, possibly @code{stdout}, has to be open
2569 for writing).
2571 @node Reading
2572 @subsection Reading: openscop_@emph{structure}_read
2574 @example
2575 @group
2576 openscop_@emph{structure}_p openscop_@emph{structure}_read(FILE * input);
2577 @end group
2578 @end example
2580 @noindent Each OpenScop data structure has a reading function
2581 as shown above (except one, see below). It reads the content of an OpenScop
2582 data structure written according to the OpenScop file format 
2583 (@pxref{OpenScop Core Part File Format Specification}) from 
2584 the @code{input} file (the file, possibly @code{stdin}, has to be open
2585 for reading). It returns a pointer to a freshly allocated 
2586 @code{openscop_@emph{structure}_t} structure containing the
2587 information.
2589 The reading function corresponding to the
2590 @code{openscop_body_t} has an additional parameter corresponding to
2591 the number of loops surrounding the statement @code{nb_iterators}:
2593 @example
2594 @group
2595 openscop_body_p openscop_body_read(FILE * input, int nb_iterators);
2596 @end group
2597 @end example
2599 @node Allocating
2600 @subsection Allocating: openscop_@emph{structure}_malloc
2602 @example
2603 @group
2604 openscop_@emph{structure}_p openscop_@emph{structure}_malloc();
2605 @end group
2606 @end example
2608 @noindent Each OpenScop data structure has a memory allocation function
2609 as shown above (except one see below). It allocates the memory to store
2610 the corresponding data structure, it initializes the pointer fields to
2611 @code{NULL} and the integer fields to @code{OPENSCOP_UNDEFINED}
2612 (@code{-1}) and it returns a pointer to the allocated space.
2614 An exception to this base description is the
2615 @code{openscop_relation_malloc()} function which requires two
2616 parameters: the number of rows and columns of the constraint
2617 matrix (@pxref{Relation Representation}):
2619 @example
2620 @group
2621 openscop_relation_p openscop_relation_malloc(int nb_rows, int nb_columns);
2622 @end group
2623 @end example
2625 @noindent The precision of the relation elements will depend on the
2626 @code{OPENSCOP_PRECISION} environment variable (@pxref{Precision}) if it is set,
2627 or the maximum available precision if it is not set. Another allocation
2628 function is provided to explicitly set a given precision:
2630 @example
2631 @group
2632 openscop_relation_p openscop_relation_pmalloc(int precision,
2633                                               int nb_rows, int nb_columns);
2634 @end group
2635 @end example
2637 @noindent The @code{precision} field may take the following values:
2638 @itemize @bullet
2639 @item @code{OPENSCOP_PRECISION_SP} for 32 bits precision,
2640 @item @code{OPENSCOP_PRECISION_DP} for 64 bits precision,
2641 @item @code{OPENSCOP_PRECISION_MP} for multiple precision,
2642 @end itemize
2644 @node Deallocating
2645 @subsection Deallocating: openscop_@emph{structure}_free
2647 @example
2648 @group
2649 void openscop_@emph{structure}_free(openscop_@emph{structure}_p s);
2650 @end group
2651 @end example
2653 @noindent Each OpenScop data structure has a memory deallocation function
2654 as shown above. It recursively frees the memory allocated for the
2655 structure pointed by @code{s}, i.e., internal structures are also freed.
2657 @node Cloning
2658 @subsection Cloning: openscop_@emph{structure}_clone
2660 @example
2661 @group
2662 openscop_@emph{structure}_p openscop_@emph{structure}_clone(openscop_@emph{structure}_p s);
2663 @end group
2664 @end example
2666 @noindent Each OpenScop data structure has a clone function
2667 as shown above. It recursively copies the content of the
2668 structure pointed by @code{s}, i.e., internal structures are also copied.
2669 It returns a pointer to the clone of the structure pointed by @code{s}.
2671 @node Testing
2672 @subsection Testing: openscop_@emph{structure}_equal
2674 @example
2675 @group
2676 int openscop_@emph{structure}_equal(openscop_@emph{structure}_p s1,
2677                              openscop_@emph{structure}_p s2);
2678 @end group
2679 @end example
2681 @noindent Each OpenScop data structure has a testing function
2682 as shown above. It checks whether two pointers are referring to equivalent
2683 structures (either by pointing to the same structure or to different
2684 structures which contain the same information). It returns 1 if the
2685 pointed structures are equivalent, 0 otherwise. This test is
2686 @emph{content-based} and is intended for debugging purpose. It is not
2687 (and will never be) able to state, e.g., that two relations with
2688 different constraint matrices are actually representing the same relation.
2691 @node Example of OpenScop Library Utilization
2692 @section Example of OpenScop Library Utilization
2693 Here is a basic example showing how it is possible to use the
2694 OpenScop Library, assuming that a standard installation has been done.
2695 The following C program reads an OpenScop file from the standard
2696 input and dumps the content of the data structures to the standard output.
2698 @example
2699 /* example.c */
2700 # include <stdio.h>
2701 # include <openscop/openscop.h>
2703 int main() @{
2704   openscop_scop_p scop;
2706   // Read the OpenScop file.
2707   scop = openscop_scop_read(stdin);
2709   // Dump the content of the scop data structure.
2710   openscop_scop_dump(stdout, scop);
2712   // Save the planet.
2713   openscop_scop_free(scop);
2715   return 0;
2717 @end example
2719 @noindent The compilation command could be:
2720 @example
2721 gcc example.c -lopenscop -o example
2722 @end example
2723 @noindent A calling command with the input file test.scop could be:
2724 @example
2725 more test.scop | ./example
2726 @end example
2729 @c %  ****************************** INSTALLING ********************************
2730 @node Installation
2731 @section Installation
2733 @menu
2734 * License::
2735 * Requirements::
2736 * Installation Instructions::
2737 * Optional Features::
2738 * Uninstallation::
2739 @end menu
2741 @node License
2742 @subsection License
2743 First of all, it would be very kind to refer the present document in any
2744 publication that results from the use of the OpenScop specification or library,
2745 @pxref{Bas11} (a bibtex entry is provided behind the title page of this
2746 manual, along with the copyright notice).
2747 The OpenScop Library is provided under the 3-clause BSD license:
2749 Copyright (C) 2011 University Paris-Sud 11 and INRIA
2751 Redistribution and use in source and binary forms, with or without
2752 modification, are permitted provided that the following conditions
2753 are met:
2754 @enumerate
2755 @item Redistributions of source code must retain the above copyright notice,
2756       this list of conditions and the following disclaimer.
2757 @item Redistributions in binary form must reproduce the above copyrigh
2758       notice, this list of conditions and the following disclaimer in the
2759       documentation and/or other materials provided with the distribution.
2760 @item The name of the author may not be used to endorse or promote products
2761       derived from this software without specific prior written permission
2762 @end enumerate
2764 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2765 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2766 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2767 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2768 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2769 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2770 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2771 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2772 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2773 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2775 @node Requirements
2776 @subsection Requirements
2778 The OpenScop Library is a stand-alone library. For a basic use,
2779 it does not need any additional tool or library. Anyway, to be able to
2780 work in conjunction with other tools that manipulate multiple precision
2781 numbers, the GNU GMP library can be used as an option.
2783 @menu
2784 * GMP Library::
2785 @end menu
2788 @node GMP Library
2789 @subsubsection GMP Library (optional)
2791 To be able to deal with insanely large coefficient, the user will need to
2792 install the GNU Multiple Precision Library (GMP for short) version 4.2.2
2793 or above@footnote{@code{http://www.swox.com/gmp}}.
2794 The user can compile it by typing the following commands on the GMP root
2795 directory:
2797 @itemize @bullet
2798 @item @code{./configure}
2799 @item @code{make}
2800 @item And as root: @code{make install}
2801 @end itemize
2803 The GMP default installation is @code{/usr/local}. This directory may
2804 not be inside the user's library path. To fix the problem, the user should set
2805 @example
2806 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
2807 @end example
2808 @noindent if your shell is, e.g., bash or
2809 @example
2810 setenv LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/local/lib
2811 @end example
2812 @noindent if your shell is, e.g., tcsh. Add the line to your .bashrc or .tcshrc (or
2813 whatever convenient file) to make this change permanent. Another solution
2814 is to ask GMP to install in the standard path by using the prefix
2815 option of the configure script:
2816 @samp{./configure --prefix=/usr}.
2818 The OpenScop Library has to be built using the GMP library by specifying
2819 the convenient configure script options to buid the GMP version
2820 (@pxref{Optional Features}).
2823 @node Installation Instructions
2824 @subsection Installation Instructions
2826 Once downloaded and unpacked
2827 (e.g. using the @samp{tar -zxvf openscop-@value{LIB_VERSION}.tar.gz} command),
2828 you can compile the OpenScop Library by typing the following commands
2829 on the OpenScop Library's root directory:
2831 @itemize @bullet
2832 @item @code{./autogen.sh}
2833 @item @code{./configure}
2834 @item @code{make}
2835 @item And as root: @code{make install}
2836 @end itemize
2838 The program binaries and object files can be removed from the
2839 source code directory by typing @code{make clean}. To also remove the
2840 files that the @code{configure} script created (so you can compile the
2841 package for a different kind of computer) type @code{make distclean}.
2843 @node Optional Features
2844 @subsection Optional Features
2845 The @code{configure} shell script attempts to guess correct values for
2846 various system-dependent variables and user options used during compilation.
2847 It uses those values to create the @code{Makefile}. Various user options
2848 are provided by the OpenScop Library's configure script. They are summarized in the
2849 following list and may be printed by typing @code{./configure --help} in the
2850 OpenScop Library top-level directory.
2852 @itemize @bullet
2853 @item By default, the installation directory is @code{/usr/local}:
2854 @code{make install} will install the package's files in
2855 @code{/usr/local/bin}, @code{/usr/local/lib} and @code{/usr/local/include}.
2856 The user can specify an installation prefix other than @code{/usr/local} by
2857 giving @code{configure} the option @code{--prefix=PATH}.
2859 @item By default, The OpenScop Library is built in 64bits version.
2860 If the user gives to @code{configure} the option
2861 @code{--enable-int-version}, the 32bits version of the OpenScop Library
2862 will be compiled. In the same way, the option @code{--enable-mp-version}
2863 has to be used to build the multiple precision version.
2865 @item By default, @code{configure} will look for the GMP library
2866 (necessary to build the multiple precision version) in standard
2867 locations. If necessary, the user can specify the GMP path by giving
2868 @code{configure} the option @code{--with-gmp=PATH}.
2869 @end itemize
2871 @node Uninstallation
2872 @subsection Uninstallation
2873 The user can easily remove the OpenScop Library from his system
2874 by typing (as root if necessary) from the OpenScop Library top-level
2875 directory
2876 @code{make uninstall}.
2878 @c %  **************************** DOCUMENTATION ******************************
2879 @node Documentation
2880 @section Documentation
2881 The OpenScop Library distribution provides several sources of documentation.
2882 First, the source code itself is as documented as much as possible.
2883 The code comments use the Doxygen technical documentation system.
2884 The user may install
2885 Doxygen@footnote{@code{http://www.stack.nl/~dimitri/doxygen}} to automatically
2886 generate a technical documentation by typing @code{make doc} or
2887 @code{doxygen ./autoconf/Doxyfile} at the OpenScop Library
2888 top-level directory after running the configure script
2889 (@pxref{Installation Instructions}). Doxygen will generate
2890 documentation sources (in HTML, LaTeX and man) in the @code{doc/source}
2891 directory of the OpenScop Library distribution.
2893 The Texinfo source of the present document is also provided in the @code{doc}
2894 directory. The user can build it in either PDF format
2895 (by typing @code{texi2pdf openscop.texi}) or HTML format
2896 (by typing @code{makeinfo --html openscop.texi}, using @code{--no-split}
2897 option to generate a single HTML file) or info format
2898 (by typing @code{makeinfo openscop.texi}).
2900 @c %  **************************** DEVELOPPING ********************************
2901 @node Development
2902 @section Development
2904 @menu
2905 * Copyright Issue::
2906 * Repository::
2907 * Coding Style::
2908 * Extension Development::
2909 @end menu
2911 @node Copyright Issue 
2912 @subsection Copyright Issue
2914 The OpenScop Library is an Open Source project and you should feel free to
2915 contribute by adding functionalities (in particular extensions), correcting
2916 bugs or improving documentation. However, for painful administrative reasons,
2917 the copyright of the core part (everything except extensions) should not be
2918 impacted by your work. Hence, if you are doing a significant contribution to
2919 the main part, the OpenScop Library maintainer may ask you for an agreement
2920 about this copyright. If you plan to do such a significant contribution, it
2921 may be wise to discuss this issue with the maintainer first. Extensions
2922 may include developer's own copyright.
2924 @node Repository 
2925 @subsection Repository
2927 The main repository of the OpenScop Library is
2928 @url{http://repo.or.cz/w/openscop.git}. Developers may ask the OpenScop Library
2929 maintainer to open them a write access to this repository. Only the maintainer
2930 should ever change the @code{master} branch. Developers should work on their
2931 own branches. To avoid any problem developers should use the @emph{fork}
2932 functionality of the repository.
2934 @node Coding Style 
2935 @subsection Coding Style  
2937 The OpenScop Library is written in C using an object oriented style. Each
2938 important data structure (e.g., @code{struct foo}) has its own header file
2939 (@code{include/openscop/foo.h}) where lies the definition of
2940 the data structure, the two typedefs for the data structure (one for the
2941 structure, @code{openscop_foo_t}, and one for a pointer
2942 to the structure, @code{openscop_foo_p}), the prototypes of the various
2943 functions related to this data structure, all named using the
2944 prefix "@code{openscop_foo_}". The source code of the functions is provided in a
2945 separated C file (@code{source/foo.c}).
2946   
2947 Utility functions independent from the main data structures may be placed in
2948 separate source files (e.g., definition in @code{include/openscop/util.h}
2949 and code in @code{source/util.c}). Tool-wide preprocessor directives are
2950 placed in @code{include/openscop/macros.h}, macros are prefixed with
2951 "@code{OPENSCOP_}".
2953 The core code itself has to be written according to the Google C++ Coding Style:
2954 @url{http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml} (for
2955 what can apply to C), plus the naming conventions discussed above.
2956 The extension parts must only respect the naming convention, but a consistent
2957 coding style is much appreciated.
2959 @node Extension Development
2960 @subsection Extension Development
2962 It's fairly easy to integrate a new extension to OpenScop and the OpenScop
2963 Library. Developing a new extension is very much like adding a new "object":
2964 it requires writing a data structure for the extension data and the base
2965 functions to manage this extension. Here is how developers should proceed
2966 to add an extension called @code{foo} (beware that the naming convention is
2967 strict):
2969 @enumerate
2970 @item Send the name @code{foo} to the maintainer to ensure it is unique and
2971       hence can be used as an URI. The name (one single
2972       word, or words separated with underscores "_") should be
2973       suggested by the extension developers to the OpenScop development
2974       mailing list @email{openscop-development@@googlegroups.com}). It
2975       should not correspond to an existing extension
2976       (see @code{include/openscop/scop.h} for the list).The
2977       maintainer will update @code{include/openscop/scop.h} in the development
2978       version accordingly.
2979 @item Look at the @code{comment} extension. The @code{comment} extension
2980       (@pxref{Comment Extension}) has been written to be used as a basic
2981       example for extension developers. Having a look at
2982       @code{include/openscop/extensions/comment.h} and
2983       @code{source/extensions/comment.c} will be a great help to do it right.
2984 @item Create the extension data structure: it is necessary that the
2985       extension data can be accessible through only one pointer.
2986 @item Code the base functions for the extension. Any extension must provide
2987       a small set of functions (naming convention apply only if the
2988       extension is planed to be integrated to the OpenScop Library
2989       default extensions):
2990       @itemize @bullet
2991       @item @code{openscop_foo_idump} (@pxref{Dumping}) 
2992       @item @code{openscop_foo_dump} (@pxref{Dumping}) 
2993       @item @code{openscop_foo_sprint} has the following prototype:
2994 @example
2995 @group
2996 char * openscop_@emph{structure}_sprint(openscop_@emph{structure}_p s);
2997 @end group
2998 @end example
2999            It corresponds to the pretty printing functions of the core
3000            data structures (@pxref{Printing}) with the
3001            difference that the OpenScop textual representation is written
3002            to a string (returned by the function) instead of a file.
3003       @item @code{openscop_foo_sread} has the following prototype:
3004 @example
3005 @group
3006 openscop_@emph{structure}_p openscop_@emph{structure}_sread(char * string);
3007 @end group
3008 @end example
3009            It corresponds to the reading functions of the core
3010            data structures (@pxref{Reading}) with the
3011            difference that the OpenScop textual representation is read
3012            from a string (provided as a parameter) instead of a file.
3013       @item @code{openscop_foo_malloc} (@pxref{Allocating}) 
3014       @item @code{openscop_foo_free} (@pxref{Deallocating}) 
3015       @item @code{openscop_foo_clone} (@pxref{Cloning}) 
3016       @item @code{openscop_foo_equal} (@pxref{Testing}) 
3017       @end itemize
3018 @item Code the other functions you need!
3019 @end enumerate
3021 Now let us consider two scenarios.
3023 First scenario, the extension is external and is
3024 not planned to be integrated to the OpenScop Library. In this case you are
3025 all set. Simply generate an @code{openscop_extension_id_t} for your
3026 extension and have a look at the function
3027 @code{openscop_scop_register_extension()} which is devoted to register
3028 a new extension to an existing @code{openscop_scop_t}.
3030 Second scenario, the extension will integrate the set of default
3031 OpenScop Library extensions (this would be cool so it will be easier
3032 for users to use it). In this case, a few additional
3033 things have to be done:
3034 @enumerate
3035 @item Create the extension header
3036       @code{include/openscop/extensions/foo.h} to store the extension
3037       structure and function prototypes and the
3038       extension source file @code{source/extensions/foo.c} for the code
3039       of the functions.
3040 @item Add the documentation for the extension to the texinfo source of
3041       this document (in @code{doc/openscop.texi}), following the example
3042       of the @code{comment} documentation (@pxref{Comment Extension}).
3043 @item Integrate the extension by adding the @code{extensions/foo.c} entry
3044       to the @code{libopenscop_la_SOURCES} in the @code{source/Makefile.am}
3045       file, the @code{openscop/foo.h} entry to the
3046       @code{nobase_pkginclude_HEADERS} and add the corresponding
3047       @code{#include <openscop/extensions/foo.h>} in the
3048       @code{include/scop.h.in} file.
3049 @item Add the new extension in the
3050       @code{openscop_scop_register_default_extensions()} function.
3051 @item You are done! Prepare a single commit or patch corresponding to the
3052       integration of the new extension and ask the maintainer to merge it
3053       to the master branch.
3054 @end enumerate
3057 @c %  ****************************** REFERENCES ********************************
3058 @node References
3059 @chapter References
3061 @itemize
3062 @item
3063 @anchor{Bas03a}[Bas03a] C. Bastoul, P. Feautrier. Improving data locality
3064 by chunking. CC'12 International Conference on Compiler Construction,
3065 LNCS 2622, pages 320-335, Warsaw, April 2003.
3067 @item
3068 @anchor{Bas11}[Bas11] C. Bastoul.
3069 OpenScop: A Specification and a Library for Data Exchange in Polyhedral
3070 Compilation Tools. Technical Report, Paris-Sud University, France, June 2011.
3072 @item
3073 @anchor{Fea92}[Fea92] P. Feautrier. Some efficient solutions to the affine
3074 scheduling problem, part II: multidimensional time.
3075 International Journal of Parallel Programming, 21(6):389--420, December 1992.
3077 @item
3078 @anchor{Gri04}[Gri04] M. Griebl. Automatic parallelization of loop programs
3079 for distributed memory architectures. Habilitation Thesis. Facult@"at f@"ur
3080 Mathematik und Informatik, Universit@"at Passau, 2004.
3081 @emph{http://www.infosun.fmi.uni-passau.de/cl/loopo/}
3083 @item
3084 @anchor{Wil93}[Wil93] Doran K. Wilde.
3085 A library for doing polyhedral operations.
3086 Technical Report 785, IRISA, Rennes, France, 1993.
3088 @end itemize
3093 @c % /*************************************************************************
3094 @c %  *                       PART VI: END OF THE DOCUMENT                    *
3095 @c %  *************************************************************************/
3096 @c @unnumbered Index
3098 @c @printindex cp
3100 @bye