]> git.pld-linux.org Git - packages/candl.git/blob - candl-git.patch
- added opt patch (adjust CFLAGS check for current autoconf); release 3
[packages/candl.git] / candl-git.patch
1 diff --git a/.gitmodules b/.gitmodules
2 new file mode 100644
3 index 0000000..3279daf
4 --- /dev/null
5 +++ b/.gitmodules
6 @@ -0,0 +1,6 @@
7 +[submodule "osl"]
8 +       path = osl
9 +       url = https://github.com/periscop/openscop.git
10 +[submodule "piplib"]
11 +       path = piplib
12 +       url = https://github.com/periscop/piplib.git
13 diff --git a/CMakeLists.txt b/CMakeLists.txt
14 new file mode 100755
15 index 0000000..a16d5e4
16 --- /dev/null
17 +++ b/CMakeLists.txt
18 @@ -0,0 +1,249 @@
19 +cmake_minimum_required(VERSION 2.8)
20 +
21 +
22 +set(PACKAGE_VERSION "0.6.2")
23 +set(RELEASE "${PACKAGE_VERSION}")
24 +set(BITS "32")
25 +set(DEFINE_HAS_ISL_LIB "")
26 +set(top_srcdir "${CMAKE_CURRENT_SOURCE_DIR}")
27 +
28 +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
29 +
30 +
31 +# User's settings - C Flags
32 +
33 +#      set(release "TRUE")
34 +       set(release "FALSE")
35 +
36 +       # Release
37 +       if (release)
38 +               set(CMAKE_C_FLAGS "-O3")
39 +       # Debug # valgrind --show-reachable=yes --leak-check=full -v exe
40 +       else()
41 +               set(CMAKE_C_FLAGS "-O0 -g3")
42 +       endif()
43 +
44 +# User's settings - General C Flags
45 +       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -std=c99")
46 +
47 +
48 +# Build doxygen
49 +       find_package(Doxygen)
50 +       if (DOXYGEN_FOUND)
51 +               configure_file("doc/Doxyfile.in" "Doxyfile")
52 +               add_custom_target(
53 +                       doxygen
54 +                       ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
55 +                       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
56 +                       COMMENT "Generating API documentation with Doxygen" VERBATIM
57 +               )
58 +       else()
59 +               message (STATUS "Doxygen not found :( API documentation can not be built")
60 +       endif()
61 +
62 +# Build documentation
63 +
64 +       # doc
65 +       find_program(texi2pdf_exe texi2pdf)
66 +       if (texi2pdf_exe)
67 +               add_custom_target(
68 +                       doc
69 +                       ${texi2pdf_exe} ${CMAKE_CURRENT_SOURCE_DIR}/doc/candl.texi --output=${CMAKE_CURRENT_BINARY_DIR}/candl.pdf
70 +                       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
71 +                       COMMENT "Generating documentation (pdf) (with texi2pdf)" VERBATIM
72 +               )
73 +       else()
74 +               message (STATUS "texi2pdf not found :( Documentation can not be built")
75 +       endif()
76 +
77 +
78 +# osl
79 +       find_package(osl REQUIRED)
80 +
81 +# GMP & piplib
82 +       message(STATUS "---")
83 +       find_library(gmp_LIB gmp)
84 +       if (gmp_LIB)
85 +               message (STATUS "Library gmp found =) ${gmp_LIB}")
86 +               set(BITS "MP")
87 +               # piplibMP
88 +               find_package(piplibMP REQUIRED)
89 +       else()
90 +               message(STATUS "Library gmp not found :(")
91 +               # piplib64
92 +               find_package(piplib64 REQUIRED)
93 +       endif()
94 +
95 +# Include directories (to use #include <> instead of #include "")
96 +
97 +       # include/candl/macros.h
98 +       configure_file("include/candl/macros.h.in" "include/candl/macros.h")
99 +       include_directories("${CMAKE_CURRENT_BINARY_DIR}/include")
100 +       # candl
101 +       include_directories("./include")
102 +
103 +
104 +# Compiler log
105 +       message(STATUS "---")
106 +       message(STATUS "C compiler = ${CMAKE_C_COMPILER}")
107 +       if (release)
108 +               message(STATUS "Mode Release")
109 +       else()
110 +               message(STATUS "Mode Debug")
111 +       endif()
112 +       message(STATUS "C flags    = ${CMAKE_C_FLAGS}")
113 +
114 +
115 +# Library
116 +
117 +       message(STATUS "---")
118 +
119 +       # files .c
120 +       file(
121 +               GLOB_RECURSE
122 +               sources
123 +               source/*
124 +       )
125 +       string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/source/candl.c;" "" sources "${sources}") # with ;
126 +       string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/source/candl.c" "" sources "${sources}")  # without ;
127 +
128 +       # Shared
129 +       add_library(
130 +               candl
131 +               SHARED
132 +               ${sources}
133 +       )
134 +       target_link_libraries(candl ${OSL_LIBRARY})
135 +       if (gmp_LIB)
136 +               target_link_libraries(candl ${PIPLIBMP_LIBRARY})
137 +       else()
138 +               target_link_libraries(candl ${PIPLIB64_LIBRARY})
139 +       endif()
140 +       get_property(candl_lib_location TARGET candl PROPERTY LOCATION)
141 +       message(STATUS "Add candl library (shared) ${candl_lib_location}")
142 +
143 +       # Static
144 +       add_library(
145 +               candl_static
146 +               STATIC
147 +               ${sources}
148 +       )
149 +       set_target_properties(candl_static PROPERTIES OUTPUT_NAME candl)
150 +       if (gmp_LIB)
151 +               target_link_libraries(candl_static ${PIPLIBMP_LIBRARY})
152 +       else()
153 +               target_link_libraries(candl_static ${PIPLIB64_LIBRARY})
154 +       endif()
155 +       target_link_libraries(candl_static ${OSL_LIBRARY})
156 +       get_property(candl_static_lib_location TARGET candl_static PROPERTY LOCATION)
157 +       message(STATUS "Add candl library (static) ${candl_static_lib_location}")
158 +
159 +
160 +# Executables & tests
161 +
162 +       message(STATUS "---") # candl
163 +
164 +       message(STATUS "Add executable candl")
165 +       add_executable(candl_exe "source/candl.c")
166 +       set_target_properties(candl_exe PROPERTIES OUTPUT_NAME "candl")
167 +       target_link_libraries(candl_exe candl_static ${OSL_LIBRARY})
168 +       if (gmp_LIB)
169 +               target_link_libraries(candl_exe candl_static ${gmp_LIB})
170 +       endif()
171 +
172 +       # candl test
173 +       find_program(bash_exe bash)
174 +       if (bash_exe)
175 +       
176 +               message(STATUS "---")
177 +
178 +               enable_testing()
179 +               
180 +               file(
181 +                       GLOB_RECURSE
182 +                       tests_unitary
183 +                       tests/unitary/*.c
184 +               )
185 +
186 +               foreach(test ${tests_unitary})
187 +                       message(STATUS "Add Unitary test ${test}")
188 +                       add_test(
189 +                               "tests_unitary_${test}"
190 +                               "${bash_exe}"
191 +                               "${CMAKE_CURRENT_SOURCE_DIR}/tests/checker.sh"
192 +                               "${test}"
193 +                               "${test}"
194 +                               "0"
195 +                       )
196 +               endforeach()
197 +
198 +               file(
199 +                       GLOB_RECURSE
200 +                       tests_transformations_must_fail
201 +                       tests/transformations/must_fail/*.c
202 +               )
203 +
204 +               foreach(test ${tests_transformations_must_fail})
205 +                       message(STATUS "Add Transformation must fail test ${test}")
206 +                       add_test(
207 +                               "tests_transformations_must_fail_${test}"
208 +                               "${bash_exe}"
209 +                               "${CMAKE_CURRENT_SOURCE_DIR}/tests/checker.sh"
210 +                               "${test}"
211 +                               "${test}"
212 +                               "1"
213 +                       )
214 +               endforeach()
215 +
216 +               file(
217 +                       GLOB_RECURSE
218 +                       tests_transformations_working
219 +                       tests/transformations/working/*.c
220 +               )
221 +
222 +               foreach(test ${tests_transformations_working})
223 +                       message(STATUS "Add Transformation working test ${test}")
224 +                       add_test(
225 +                               "tests_transformations_working_${test}"
226 +                               "${bash_exe}"
227 +                               "${CMAKE_CURRENT_SOURCE_DIR}/tests/checker.sh"
228 +                               "${test}"
229 +                               "${test}"
230 +                               "1"
231 +                       )
232 +               endforeach()
233 +
234 +       endif()
235 +
236 +
237 +# Install
238 +
239 +       install(TARGETS candl LIBRARY DESTINATION lib)
240 +       install(TARGETS candl_static ARCHIVE DESTINATION lib)
241 +       install(DIRECTORY include/ DESTINATION include FILES_MATCHING PATTERN "*.h")
242 +       install(DIRECTORY include/ DESTINATION include FILES_MATCHING PATTERN "*.hpp")
243 +       install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include/" DESTINATION include FILES_MATCHING PATTERN "*.h")
244 +       install(FILES candl-config.cmake DESTINATION lib/candl)
245 +       install(TARGETS candl_exe RUNTIME DESTINATION bin)
246 +
247 +
248 +# Little help
249 +
250 +       message(STATUS "You can execute:")
251 +       message(STATUS "    make         # To compile candl library & candl")
252 +       if (bash_exe)
253 +               message(STATUS "    make test    # To execute tests")
254 +               message(STATUS "                   (with the first candl in the $PATH (?))")
255 +       endif()
256 +       message(STATUS "    make install # To install library, include and CMake module")
257 +       message(STATUS "                 # If you need root access:")
258 +       message(STATUS "                 #     sudo make install")
259 +       message(STATUS "                 #     su -c \"make install\"")
260 +       if (DOXYGEN_FOUND)
261 +               message(STATUS "    make doxygen # To generate the Doxygen")
262 +       endif()
263 +       if( texi2pdf_exe)
264 +               message(STATUS "    make doc     # To generate the documentation")
265 +       endif()
266 +
267 +       message(STATUS "---")
268 diff --git a/Makefile.am b/Makefile.am
269 index fefbf45..6839b4b 100644
270 --- a/Makefile.am
271 +++ b/Makefile.am
272 @@ -32,39 +32,90 @@
273  # *                                                                           *
274  # *****************************************************************************/
275  
276 +#############################################################################
277 +
278 +if BUNDLED_OSL
279 +  MAYBE_OSL = osl
280 +  OSL_LA = $(top_builddir)/osl/libosl.la
281 +endif
282 +if BUNDLED_PIPLIB
283 +  MAYBE_PIPLIB = piplib
284 +  PIPLIB_LA = $(top_builddir)/piplib/libpiplib$(BITS).la
285 +endif
286 +
287 +SUBDIRS         = $(MAYBE_OSL) $(MAYBE_PIPLIB) doc tests
288 +DIST_SUBDIRS    = $(MAYBE_OSL) $(MAYBE_PIPLIB) doc tests
289 +ACLOCAL_AMFLAGS = -I m4
290 +
291 +#############################################################################
292 +
293 +bin_PROGRAMS    = candl
294 +lib_LTLIBRARIES = libcandl.la
295  
296  #############################################################################
297 -SUBDIRS                = doc source include tests
298  
299 +pkginclude_HEADERS =                   \
300 +       include/candl/candl.h          \
301 +       include/candl/dependence.h     \
302 +       include/candl/scop.h           \
303 +       include/candl/statement.h      \
304 +       include/candl/macros.h         \
305 +       include/candl/util.h           \
306 +       include/candl/ddv.h            \
307 +       include/candl/matrix.h         \
308 +       include/candl/options.h        \
309 +       include/candl/piplib.h         \
310 +       include/candl/piplib-wrapper.h \
311 +       include/candl/violation.h
312 +
313 +DEFAULT_INCLUDES = -I.
314 +INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include
315 +AM_CFLAGS = $(CFLAGS_WARN)
316  
317  #############################################################################
318 -ACLOCAL_AMFLAGS                = -I autoconf
319  
320 -m4datadir              = $(datadir)/aclocal
321 +EXTRA_DIST = COPYING.LESSER AUTHORS
322 +
323 +libcandl_la_LIBADD   = @OSL_LIBS@ @PIPLIB_LIBS@ $(OSL_LA) $(PIPLIB_LA)
324 +libcandl_la_CPPFLAGS = @OSL_CPPFLAGS@ @PIPLIB_CPPFLAGS@ -g
325 +libcandl_la_LDFLAGS  = @OSL_LDFLAGS@ @PIPLIB_LDFLAGS@ 
326 +libcandl_la_SOURCES  =          \
327 +       source/dependence.c     \
328 +       source/ddv.c            \
329 +       source/scop.c           \
330 +       source/statement.c      \
331 +       source/util.c           \
332 +       source/isl-wrapper.c    \
333 +       source/matrix.c         \
334 +       source/options.c        \
335 +       source/piplib-wrapper.c \
336 +       source/pruning.c        \
337 +       source/violation.c
338  
339 -EXTRA_DIST             = COPYING.LESSER AUTHORS
340 +#############################################################################
341  
342 -AUX_DIST                =                      \
343 -       $(ac_aux_dir)/config.guess              \
344 -       $(ac_aux_dir)/config.sub                \
345 -       $(ac_aux_dir)/install-sh                \
346 -       $(ac_aux_dir)/ltmain.sh                 \
347 -       $(ac_aux_dir)/missing                   \
348 -       $(ac_aux_dir)/depcomp                   \
349 -       $(ac_aux_dir)/texinfo.tex
350 +LDADD              = @CANDL_LIBS@ @OSL_LIBS@ @PIPLIB_LIBS@
351 +candl_CPPFLAGS     = @OSL_CPPFLAGS@ @PIPLIB_CPPFLAGS@ -g -Wall
352 +candl_LDFLAGS      = #@OSL_LDFLAGS@ @PIPLIB_LDFLAGS@ # TO BE REMOVED
353 +candl_DEPENDENCIES = libcandl.la
354 +candl_SOURCES      = source/candl.c
355  
356 +#############################################################################
357  
358 -MAINTAINERCLEANFILES   =                       \
359 -       Makefile.in                             \
360 -       aclocal.m4                              \
361 -       configure                               \
362 -       source/stamp-h.in                       \
363 +MAINTAINERCLEANFILES = \
364 +       Makefile.in    \
365 +       aclocal.m4     \
366 +       configure      \
367         $(AUX_DIST)
368  
369  #############################################################################
370 +
371  dist-hook:
372         (cd $(distdir) && mkdir -p $(ac_aux_dir))
373         for file in $(AUX_DIST); do \
374           cp $$file $(distdir)/$$file; \
375         done
376  #############################################################################
377 +
378 +valcheck:
379 +       $(MAKE) valcheck -C tests
380 diff --git a/README b/README
381 index 1b20de6..864d102 100644
382 --- a/README
383 +++ b/README
384 @@ -5,7 +5,7 @@
385  Install
386  -------
387  
388 -To install candl, PIPLib must be installed. Optionally, scoplib must
389 +To install candl, PIPLib must be installed. Optionally, OpenScop library must
390  be installed to enable SCoP support.
391  
392  $> ./configure --with-piplib=/path/to/piplib/install --with-scoplib=/path/to/scoplib/install
393 @@ -15,6 +15,32 @@ $> make
394  $> make install
395  
396  
397 +Alternatively, to use bunled PIPLib and  OpenScop library, follow following command
398 +sequence:
399 +
400 +$> ./get_submodules.sh
401 +
402 +$> ./autogen.sh
403 +
404 +$> ./configure --with-piplib=bundled --with-scoplib=bundled
405 +
406 +$> make
407 +
408 +$> make install
409 +
410 +Alternative: Install with CMake
411 +-------------------------------
412 +
413 +$> mkdir build
414 +$> cd build
415 +$> cmake .. # -DCMAKE_INSTALL_PREFIX="/your/install/directory"
416 +$> make
417 +$> make test
418 +$> # make install # sudo make install # su -c "make install"
419 +$> make doc
420 +$> make doxygen
421 +
422 +
423  Support
424  -------
425  
426 diff --git a/TODO b/TODO
427 new file mode 100644
428 index 0000000..74b6087
429 --- /dev/null
430 +++ b/TODO
431 @@ -0,0 +1,59 @@
432 +
433 +- unchecked -commute 
434 +
435 +- lastwriter not finished
436 +  see the FIXME in the function candl_dep_compute_lastwriter
437 +
438 +- compilation error with ISL :
439 +  To test it, in isl-wrapper change #ifdef CANDL_SUPPORTS_ISL to
440 +  #ifndef CANDL_SUPPORTS_ISL
441 +  
442 +  The error is :
443 +  source/isl-wrapper.c: In function â€˜isl_constraint_read_from_matrix’:
444 +  source/isl-wrapper.c:79: warning: passing argument 1 of â€˜isl_equality_alloc’ from incompatible pointer type
445 +  /home/jpoudroux/usr/include/isl/constraint.h:28: note: expected â€˜struct isl_local_space *’ but argument is of type â€˜struct isl_space *’
446 +  source/isl-wrapper.c:81: warning: passing argument 1 of â€˜isl_inequality_alloc’ from incompatible pointer type
447 +  /home/jpoudroux/usr/include/isl/constraint.h:29: note: expected â€˜struct isl_local_space *’ but argument is of type â€˜struct isl_space *’
448 +
449 +- prunnning not finish (prunning.c: line 258 to 328)
450 +  Uncomment the CANDL_COMPILE_PRUNNING in candl.h, or remove the ifdef in
451 +  prunning.c
452 +
453 +- change the type of the dependence/violation domain
454 +  (at the end of candl_dependence_build_system and candl_matrix_violation)
455 +  today it's : OSL_UNDEFINED
456 +  
457 +- candl_usr_init
458 +  the statements must be sorted to compute the statement label
459 +  the problem is if the scop is reordered, the second transformed scop
460 +  must be "aligned" with it (the first statement need to corresponds to the first
461 +  statement of the second scop, but the scattering could be different)
462 +
463 +  Functions of clay, which could return a non ordered scop :
464 +  (they create new statements)
465 +  iss, unroll, peel
466 +
467 +- in pip_has_rational_point:
468 +  -> FIXME (dependence.c:2243)
469 +
470 +- autocorrect not implemented yet 
471 +
472 +- compilation warning with gmp :
473 +  /usr/bin/ld: warning: libgmp.so.3, needed by /home/jpoudroux/usr/lib/libosl.so, may conflict with libgmp.so.10
474 +
475 +- autoreconf error in the piplib module
476 +  -> piplib must be installed in /
477 +  
478 +  or execute these commands :
479 +  $ cd piplib
480 +  $ echo "AM_PROG_CC_C_O" >>configure.in
481 +  $ touch NEWS AUTHORS ChangeLog
482 +  $ cd ..
483 +  $ ./redo.sh
484 +
485 +  If you want to set piplib as "bundled", uncomment these lines in the
486 +  configure.ac :
487 +  295: if test $with_piplib = bundled; then
488 +  296:   AC_CONFIG_SUBDIRS(piplib)
489 +  297: fi
490 +
491 diff --git a/autoconf/.gitignore b/autoconf/.gitignore
492 new file mode 100644
493 index 0000000..e69de29
494 diff --git a/autoconf/candl.m4 b/autoconf/candl.m4
495 deleted file mode 100644
496 index 2d1347e..0000000
497 --- a/autoconf/candl.m4
498 +++ /dev/null
499 @@ -1,81 +0,0 @@
500 -AC_DEFUN([CANDL_ARG_LIBS_DEPENDENCIES],
501 -[
502 -dnl Add $prefix to the library path (convenience).
503 -  if test -e ${prefix}/include; then
504 -    CPPFLAGS="${CPPFLAGS} -I${prefix}/include"
505 -  fi;
506 -  if test -e ${prefix}/lib; then
507 -    LDFLAGS="${LDFLAGS} -L${prefix}/lib"
508 -  fi;
509 -dnl Offer --with-piplib.
510 -  AC_ARG_WITH(piplib,
511 -             AC_HELP_STRING([--with-piplib=DIR],
512 -                            [DIR Location of PIPLib package]),
513 -              [with_piplib=$withval;
514 -              CPPFLAGS="${CPPFLAGS} -I$withval/include";
515 -              LDFLAGS="${LDFLAGS} -L$withval/lib"
516 -             ],
517 -              [with_piplib=yes])
518 -dnl Check for piplib existence.
519 -  AS_IF([test "x$with_piplib" != xno],
520 -       [AC_SEARCH_LIBS([pip_solve], [piplib$BITS],
521 -        [LIBS="-lpiplib$BITS $LIBS";
522 -        AC_DEFINE([HAVE_LIBPIPLIB], [1], [Define if you have libpiplib$BITS])
523 -         ],
524 -         [if test "x$with_piplib" != xcheck; then
525 -           AC_MSG_FAILURE([--with-piplib was given, but test for piplib failed])
526 -          fi
527 -         ])
528 -       ])
529 -dnl Offer --with-scoplib.
530 -  AC_ARG_WITH(scoplib,
531 -             AC_HELP_STRING([--with-scoplib=DIR],
532 -                            [DIR Location of ScopLib package]),
533 -              [with_scoplib=$withval;
534 -              CPPFLAGS="${CPPFLAGS} -I$withval/include";
535 -              LDFLAGS="${LDFLAGS} -L$withval/lib"
536 -             ],
537 -              [with_scoplib=check])
538 -dnl Check for scoplib existence.
539 -  AS_IF([test "x$with_scoplib" != xno],
540 -       [AC_SEARCH_LIBS([scoplib_scop_read], [scoplib],
541 -        [LIBS="-lscoplib $LIBS";
542 -        DEFINE_HAS_SCOPLIB_LIB="# define CANDL_SUPPORTS_SCOPLIB"
543 -        ],
544 -         [DEFINE_HAS_SCOPLIB_LIB=""
545 -         if test "x$with_scoplib" != xcheck; then
546 -           AC_MSG_FAILURE([Test for ScopLib failed. Use --with-scoplib to specify libscoplib path.])
547 -          fi
548 -         ])
549 -       ])
550 -dnl Offer --with-gmp-prefix.
551 -  AC_ARG_WITH(gmp-prefix,
552 -             AC_HELP_STRING([--with-gmp-prefix=DIR],
553 -                            [DIR Location of GMP package (only headers are needed)]),
554 -              [CPPFLAGS="${CPPFLAGS} -I$withval/include";
555 -               LDFLAGS="${LDFLAGS} -L$withval/lib";
556 -             ])
557 -dnl Offer --with-isl.
558 -  AC_ARG_WITH(isl,
559 -             AC_HELP_STRING([--with-isl=DIR],
560 -                            [DIR Location of Isl package]),
561 -              [with_isl=$withval;
562 -              CPPFLAGS="${CPPFLAGS} -I$withval/include";
563 -              LDFLAGS="${LDFLAGS} -L$withval/lib"
564 -             ],
565 -              [with_isl=check])
566 -dnl Check for isl existence.
567 -  AS_IF([test "x$with_isl" != xno],
568 -       [AC_SEARCH_LIBS([isl_version], [isl],
569 -        [LIBS="-lisl $LIBS";
570 -        DEFINE_HAS_ISL_LIB="# define CANDL_SUPPORTS_ISL"
571 -        ],
572 -         [DEFINE_HAS_ISL_LIB=""
573 -         if test "x$with_isl" != xcheck; then
574 -           AC_MSG_FAILURE([Test for Isl failed. Use --with-isl to specify libisl path.])
575 -          fi
576 -         ])
577 -       ])
578 -])
579 -
580 -
581 #diff --git a/autogen.sh b/autogen.sh
582 #index b67de1f..c27fa40 100755
583 #--- a/autogen.sh
584 #+++ b/autogen.sh
585 #@@ -1,5 +1,8 @@
586 #-#! /bin/sh
587 #-
588 #-aclocal -I autoconf
589 #-libtoolize --force --copy
590 #-autoreconf -vfi
591 #+#!/bin/sh
592 #+autoreconf -i
593 #+if test -f osl/autogen.sh; then
594 #+      (cd osl; ./autogen.sh)
595 #+fi
596 #+if test -f piplib/autogen.sh; then
597 #+      (cd piplib; ./autogen.sh)
598 #+fi
599 diff --git a/candl-config.cmake b/candl-config.cmake
600 new file mode 100644
601 index 0000000..c1047d0
602 --- /dev/null
603 +++ b/candl-config.cmake
604 @@ -0,0 +1,25 @@
605 +# Try to find the candl library
606 +
607 +# CANDL_FOUND       - System has candl lib
608 +# CANDL_INCLUDE_DIR - The candl include directory
609 +# CANDL_LIBRARY     - Library needed to use candl
610 +
611 +
612 +if (CANDL_INCLUDE_DIR AND CANDL_LIBRARY)
613 +       # Already in cache, be silent
614 +       set(CANDL_FIND_QUIETLY TRUE)
615 +endif()
616 +
617 +find_path(CANDL_INCLUDE_DIR NAMES candl/candl.h)
618 +find_library(CANDL_LIBRARY NAMES candl)
619 +
620 +if (CANDL_LIBRARY AND CANDL_INCLUDE_DIR)
621 +       message(STATUS "Library candl found =) ${CANDL_LIBRARY}")
622 +else()
623 +       message(STATUS "Library candl not found =(")
624 +endif()
625 +
626 +include(FindPackageHandleStandardArgs)
627 +FIND_PACKAGE_HANDLE_STANDARD_ARGS(CANDL DEFAULT_MSG CANDL_INCLUDE_DIR CANDL_LIBRARY)
628 +
629 +mark_as_advanced(CANDL_INCLUDE_DIR CANDL_LIBRARY)
630 diff --git a/configure.ac b/configure.ac
631 new file mode 100644
632 index 0000000..03c9ce4
633 --- /dev/null
634 +++ b/configure.ac
635 @@ -0,0 +1,320 @@
636 +dnl /**-------------------------------------------------------------------**
637 +dnl  **                              CAnDL                                **
638 +dnl  **-------------------------------------------------------------------**
639 +dnl  **                           configure.in                            **
640 +dnl  **-------------------------------------------------------------------**
641 +dnl  **                 First version: september 8th 2003                 **
642 +dnl  **-------------------------------------------------------------------**/
643 +dnl 
644 +dnl /**************************************************************************
645 +dnl *   CAnDL : the Chunky Analyser for Dependences in Loops (experimental)   *
646 +dnl ***************************************************************************
647 +dnl *                                                                         *
648 +dnl * Copyright (C) 2003-2008 Cedric Bastoul                                  *
649 +dnl *                                                                         *
650 +dnl * This is free software; you can redistribute it and/or modify it under   *
651 +dnl * the terms of the GNU General Public License as published by the Free    *
652 +dnl * Software Foundation; either version 2 of the License, or (at your       *
653 +dnl * option) any later version.                                              *
654 +dnl *                                                                         *
655 +dnl * This software is distributed in the hope that it will be useful, but    *
656 +dnl * WITHOUT ANY WARRANTY; without even the implied warranty of              *
657 +dnl * MERCHANTABILITYor FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
658 +dnl * General Public License for more details.                                *
659 +dnl *                                                                         *
660 +dnl * You should have received a copy of the GNU General Public License along *
661 +dnl * with software; if not, write to the Free Software Foundation, Inc.,     *
662 +dnl * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA                  *
663 +dnl *                                                                         *
664 +dnl * CAnDL, the Chunky Dependence Analyser                                   *
665 +dnl * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr                      *
666 +dnl *                                                                         *
667 +dnl ***************************************************************************/
668 +
669 +m4_define([version_major], [0])
670 +m4_define([version_minor], [0])
671 +m4_define([version_revision], [1])
672 +
673 +AC_PREREQ(2.53)
674 +
675 +dnl Fill here the @bug email adress.
676 +AC_INIT([candl], [0.6.2], [cedric.bastoul@inria.fr,pouchet@cse.ohio-state.edu])
677 +
678 +AC_CONFIG_SRCDIR([include/candl/candl.h])
679 +
680 +dnl Put as most as possible configuration files to an auxialiry
681 +dnl directory.
682 +AC_CONFIG_AUX_DIR(autoconf)
683 +AC_CONFIG_MACRO_DIR([m4])
684 +
685 +dnl Initialize automake. Here, a special tar version that enables
686 +dnl (very) long filenames.
687 +#AM_INIT_AUTOMAKE([1.9 tar-ustar no-define foreign dist-bzip2])
688 +AM_INIT_AUTOMAKE([foreign])
689 +m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
690 +
691 +dnl default version
692 +BITS="MP"
693 +CPPFLAGS=-DCANDL_LINEAR_VALUE_IS_MP
694 +
695 +
696 +dnl /**************************************************************************
697 +dnl  *                              Checking                                  *
698 +dnl  **************************************************************************/
699 +
700 +
701 +dnl Checks for programs.
702 +AC_PROG_CC
703 +AC_PROG_LN_S
704 +AC_PROG_MAKE_SET
705 +AC_CHECK_PROG(CD, cd)
706 +AC_PROG_INSTALL
707 +AC_PROG_LIBTOOL
708 +AC_CHECK_PROGS(DOXYGEN,doxygen,doxygen)
709 +
710 +AX_CC_MAXOPT
711 +AC_SUBST(CFLAGS_WARN)
712 +AX_CFLAGS_WARN_ALL(CFLAGS_WARN)
713 +
714 +dnl Checks for typedefs, structures, and compiler characteristics.
715 +AC_C_CONST
716 +AC_TYPE_SIZE_T
717 +
718 +dnl Checks for header files.
719 +AC_HEADER_STDC
720 +AC_CHECK_HEADERS([errno.h stddef.h stdlib.h string.h strings.h unistd.h])
721 +
722 +dnl Checks for library functions.
723 +AC_CHECK_FUNCS(strtol)
724 +
725 +
726 +dnl /**************************************************************************
727 +dnl  *                             Option setting                             *
728 +dnl  **************************************************************************/
729 +
730 +dnl /**************************************************************************
731 +dnl  *                   Where is the OpenScop Library?                       *
732 +dnl  **************************************************************************/
733 +
734 +AX_SUBMODULE(osl,system|build|bundled,system)
735 +
736 +AC_SUBST(OSL_CPPFLAGS)
737 +AC_SUBST(OSL_LDFLAGS)
738 +AC_SUBST(OSL_LIBS)
739 +case "$with_osl" in
740 +bundled)
741 +  OSL_CPPFLAGS="-I$srcdir/osl/include -Iosl/include"
742 +  OSL_LIBS="$srcdir/osl/libosl.la"
743 +  ;;
744 +build)
745 +  OSL_CPPFLAGS="-I$osl_srcdir/include -I$with_osl_builddir/include"
746 +  OSL_LIBS="$with_osl_builddir/libosl.la"
747 +  ;;
748 +system)
749 +  if test "x$with_osl_prefix" != "x"; then
750 +    OSL_CPPFLAGS="-I$with_osl_prefix/include"
751 +  fi
752 +  if test "x$with_osl_exec_prefix" != "x"; then
753 +    OSL_LDFLAGS="-L$with_osl_exec_prefix/lib"
754 +  fi
755 +  OSL_LIBS="$with_osl_prefix/lib/libosl.la -losl"
756 +esac
757 +AM_CONDITIONAL(BUNDLED_OSL, test $with_osl = bundled)
758 +
759 +
760 +
761 +dnl GMP
762 +
763 +dnl Some default values cause I'm not sure whether autoconf set them, while
764 +dnl documentation says it does...
765 +gmp_package="yes"
766 +gmp_include_package="yes"
767 +gmp_library_package="yes"
768 +
769 +NEED_MP="no"
770 +
771 +dnl --with-gmp=gmp-path
772 +AC_ARG_WITH(gmp,
773 +        [  --with-gmp=DIR          DIR where the gmp package is installed],
774 +  [ echo "Package gmp : $withval" &&
775 +    gmp_package=$withval &&
776 +          GMP_INC=$gmp_package/include &&
777 +          GMP_LIB=$gmp_package/lib &&
778 +          CPPFLAGS=-DCANDL_LINEAR_VALUE_IS_MP &&
779 +          NEED_MP="yes"])
780 +
781 +AC_ARG_WITH(gmp-include,
782 +        [  --with-gmp-include=DIR  DIR where gmp.h is installed],
783 +  [ echo "Package gmp-include : $withval" &&
784 +    gmp_include_package=$withval &&
785 +          GMP_INC=$gmp_include_package &&
786 +          CPPFLAGS=-DCANDL_LINEAR_VALUE_IS_MP &&
787 +    NEED_MP="yes"])
788 +
789 +AC_ARG_WITH(gmp-library,
790 +        [  --with-gmp-library=DIR  DIR where the gmp library is installed],
791 +  [ echo "Package gmp-library : $withval" &&
792 +    gmp_library_package=$withval &&
793 +          GMP_LIB=$gmp_library_package &&
794 +          CPPFLAGS=-DCANDL_LINEAR_VALUE_IS_MP &&
795 +    NEED_MP="yes"])
796 +
797 +AC_ARG_ENABLE(int-version,
798 +  [  --enable-int-version    'int' (32 bits) version is built],
799 +  [ echo "Package int : $enableval" &&
800 +    BITS="32" &&
801 +          CPPFLAGS=-DCANDL_LINEAR_VALUE_IS_LONG])
802 +
803 +AC_ARG_ENABLE(llint-version,
804 +  [  --enable-llint-version  'long long int' (64 bits) version is built],
805 +  [ echo "Package long long int : $enableval" &&
806 +    BITS="64" &&
807 +          CPPFLAGS=-DCANDL_LINEAR_VALUE_IS_LONGLONG])
808 +
809 +AC_ARG_ENABLE(mp-version,
810 +  [  --enable-mp-version     'MP' (multiple precision) version is built],
811 +  [ echo "Package mp : $enableval" &&
812 +    BITS="MP" &&
813 +          CPPFLAGS=-DCANDL_LINEAR_VALUE_IS_MP &&
814 +          NEED_MP="yes"])
815 +
816 +AC_ARG_ENABLE(piplib-hybrid,
817 +  [  --enable-piplib-hybrid   Link with piplib-hybrid],
818 +  [ echo "Piplib-hybrid support : $enableval" &&
819 +          if test "x$enableval" = "xyes"; then 
820 +            CPPFLAGS=-DCANDL_HAS_PIPLIB_HYBRID
821 +          fi])
822 +
823 +
824 +dnl /**************************************************************************
825 +dnl  *                   Where is the PipLib Library?                         *
826 +dnl  **************************************************************************/
827 +
828 +AX_SUBMODULE(piplib,system|build|bundled,system)
829 +
830 +AC_SUBST(PIPLIB_CPPFLAGS)
831 +AC_SUBST(PIPLIB_LDFLAGS)
832 +AC_SUBST(PIPLIB_LIBS)
833 +case "$with_piplib" in
834 +bundled)
835 +  PIPLIB_CPPFLAGS="-I$srcdir/piplib/include -Ipiplib/include"
836 +  PIPLIB_LIBS="$srcdir/piplib/libpiplib$BITS.la"
837 +  ;;
838 +build)
839 +  PIPLIB_CPPFLAGS="-I$piplib_srcdir/include -I$with_piplib_builddir/include"
840 +  PIPLIB_LIBS="$with_piplib_builddir/libpiplib$BITS.la"
841 +  ;;
842 +system)
843 +  if test "x$with_piplib_prefix" != "x"; then
844 +    PIPLIB_CPPFLAGS="-I$with_piplib_prefix/include"
845 +  fi
846 +  if test "x$with_piplib_exec_prefix" != "x"; then
847 +    PIPLIB_LDFLAGS="-L$with_piplib_exec_prefix/lib"
848 +  fi
849 +  PIPLIB_LIBS="$with_piplib_prefix/lib/libpiplib$BITS.la -lpiplib$BITS"
850 +esac
851 +AM_CONDITIONAL(BUNDLED_PIPLIB, test $with_piplib = bundled)
852 +
853 +
854 +
855 +dnl /**************************************************************************
856 +dnl  *                            Where is GMP?                               *
857 +dnl  **************************************************************************/
858 +
859 +
860 +dnl Checking for gmp
861 +AC_MSG_CHECKING(whether gmp works)
862 +if test "$gmp_package" = "no"; then
863 +  echo "GMP package not defined"
864 +  AC_MSG_RESULT(no)
865 +  TO_BUILD_MP=""
866 +else
867 +  if test "$NEED_MP" = "no"; then
868 +    echo "Mode normal GMP"
869 +    TO_BUILD="$TO_BUILD MP"
870 +    AC_CHECK_HEADER(gmp.h,
871 +                    [AC_SEARCH_LIBS([__gmpz_init], [gmp],
872 +                      [LIBS="$LIBS -lgmp"],
873 +          [echo "Can't find gmp library." &&
874 +           echo "MP version will not be built." &&
875 +           TO_BUILD_MP=""])],
876 +        [echo "Can't find gmp headers." &&
877 +         echo "MP version will not be built." &&
878 +         TO_BUILD_MP=""])
879 +  else
880 +    dnl Default given by --with-X is "yes", --without-X is "no". We also
881 +    dnl initialized manually all gmp_package* variables to "yes" (thus they are
882 +    dnl supposed to be "yes" except if the user set them himself).
883 +    if test "$gmp_package" != "yes" ; then
884 +      echo "(GMP path has been set by user)"
885 +      GMP_DIR=$gmp_package
886 +      dnl Useful for AC_CHECK_X to find what we want.
887 +      CPPFLAGS="-I$GMP_DIR/include $CPPFLAGS"
888 +      LDFLAGS="-L$GMP_DIR/lib $LDFLAGS"
889 +    fi
890 +
891 +    if test "$gmp_include_package" != "yes" ; then
892 +      CPPFLAGS="-I$GMP_INC $CPPFLAGS"
893 +    fi
894 +
895 +    if test "$gmp_library_package" != "yes" ; then
896 +      LDFLAGS="-L$GMP_LIB $LDFLAGS"
897 +    fi
898 +
899 +    AC_CHECK_HEADER(gmp.h,
900 +                    [],
901 +                    [AC_MSG_ERROR(Can't find gmp headers.)])
902 +    AC_SEARCH_LIBS([__gmpz_init], [gmp],
903 +                 [LIBS="$LIBS -lgmp"],
904 +                 [AC_MSG_ERROR(Can't find gmp library.)])
905 +
906 +    AC_MSG_RESULT(yes)
907 +  fi
908 +fi
909 +
910 +dnl /**************************************************************************
911 +dnl  *                            Substitutions                               *
912 +dnl  **************************************************************************/
913 +
914 +
915 +dnl Substitutions to do.
916 +AC_SUBST(BITS)
917 +AC_SUBST(DEFINE_HAS_ISL_LIB)
918 +AC_SUBST(ac_aux_dir)
919 +AC_SUBST(abs_top_srcdir)
920 +
921 +
922 +dnl Configure Makefiles.
923 +AC_CONFIG_FILES([
924 +  Makefile
925 +  doc/Makefile
926 +  doc/Doxyfile
927 +  include/candl/macros.h
928 +  include/candl/piplib.h
929 +  tests/Makefile
930 +  ],
931 +  [test -z "$CONFIG_HEADERS" || echo timestamp > source/stamp-h.in])
932 +
933 +#if test $with_piplib = system; then
934 +#  AC_CONFIG_SUBDIRS(piplib)
935 +#fi
936 +if test $with_osl = bundled; then
937 +  AC_CONFIG_SUBDIRS(osl)
938 +fi
939 +
940 +dnl forcing candl to use local libcandl.la
941 +dnl if --prefix is not specified
942 +CANDL_LIBS="$srcdir/libcandl.la -lcandl"
943 +AC_SUBST(CANDL_LIBS)
944 +
945 +
946 +
947 +AC_OUTPUT
948 +
949 +echo "             /*-----------------------------------------------*"
950 +echo "              *          Candl configuration is OK            *"
951 +echo "              *-----------------------------------------------*/"
952 +echo "It appears that your system is OK to start Candl compilation. You need"
953 +echo "now to type \"make\". Lastly type \"make install\" to install Candl on"
954 +echo "your system (log as root if necessary)."
955 +
956 diff --git a/configure.in b/configure.in
957 deleted file mode 100644
958 index f6cf7ad..0000000
959 --- a/configure.in
960 +++ /dev/null
961 @@ -1,233 +0,0 @@
962 -dnl /**-------------------------------------------------------------------**
963 -dnl  **                              CAnDL                                **
964 -dnl  **-------------------------------------------------------------------**
965 -dnl  **                           configure.in                            **
966 -dnl  **-------------------------------------------------------------------**
967 -dnl  **                 First version: september 8th 2003                 **
968 -dnl  **-------------------------------------------------------------------**/
969 -dnl 
970 -dnl /**************************************************************************
971 -dnl *   CAnDL : the Chunky Analyser for Dependences in Loops (experimental)   *
972 -dnl ***************************************************************************
973 -dnl *                                                                         *
974 -dnl * Copyright (C) 2003-2008 Cedric Bastoul                                  *
975 -dnl *                                                                         *
976 -dnl * This is free software; you can redistribute it and/or modify it under   *
977 -dnl * the terms of the GNU General Public License as published by the Free    *
978 -dnl * Software Foundation; either version 2 of the License, or (at your       *
979 -dnl * option) any later version.                                              *
980 -dnl *                                                                         *
981 -dnl * This software is distributed in the hope that it will be useful, but    *
982 -dnl * WITHOUT ANY WARRANTY; without even the implied warranty of              *
983 -dnl * MERCHANTABILITYor FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
984 -dnl * General Public License for more details.                                *
985 -dnl *                                                                         *
986 -dnl * You should have received a copy of the GNU General Public License along *
987 -dnl * with software; if not, write to the Free Software Foundation, Inc.,     *
988 -dnl * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA                  *
989 -dnl *                                                                         *
990 -dnl * CAnDL, the Chunky Dependence Analyser                                   *
991 -dnl * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr                      *
992 -dnl *                                                                         *
993 -dnl ***************************************************************************/
994 -
995 -
996 -AC_PREREQ(2.13)
997 -dnl Fill here the @bug email adress.
998 -AC_INIT([candl], [0.6.2], [cedric.bastoul@inria.fr,pouchet@cse.ohio-state.edu])
999 -dnl A common file, which serve as a test.
1000 -AC_CONFIG_SRCDIR([include/candl/program.h])
1001 -dnl Put as most as possible configuration files to an auxialiry
1002 -dnl directory.
1003 -AC_CONFIG_AUX_DIR([autoconf])
1004 -dnl Initialize automake. Here, a special tar version that enables
1005 -dnl (very) long filenames.
1006 -AM_INIT_AUTOMAKE([1.9 tar-ustar no-define foreign dist-bzip2])
1007 -
1008 -
1009 -dnl default version
1010 -BITS="64"
1011 -CPPFLAGS=-DLINEAR_VALUE_IS_LONGLONG
1012 -
1013 -
1014 -dnl /**************************************************************************
1015 -dnl  *                              Checking                                  *
1016 -dnl  **************************************************************************/
1017 -
1018 -
1019 -dnl Checks for programs.
1020 -AC_PROG_CC
1021 -AC_PROG_LN_S
1022 -AC_PROG_MAKE_SET
1023 -AC_CHECK_PROG(CD, cd)
1024 -AC_PROG_LIBTOOL
1025 -AC_CHECK_PROGS(DOXYGEN,doxygen,doxygen)
1026 -
1027 -dnl Checks for typedefs, structures, and compiler characteristics.
1028 -AC_C_CONST
1029 -AC_TYPE_SIZE_T
1030 -
1031 -dnl Checks for header files.
1032 -AC_HEADER_STDC
1033 -AC_CHECK_HEADERS([errno.h stddef.h stdlib.h string.h strings.h unistd.h])
1034 -
1035 -dnl Checks for library functions.
1036 -AC_CHECK_FUNCS(strtol)
1037 -
1038 -
1039 -dnl /**************************************************************************
1040 -dnl  *                             Option setting                             *
1041 -dnl  **************************************************************************/
1042 -
1043 -dnl Some default values cause I'm not sure whether autoconf set them, while
1044 -dnl documentation says it does...
1045 -gmp_package="yes"
1046 -gmp_include_package="yes"
1047 -gmp_library_package="yes"
1048 -
1049 -NEED_MP="no"
1050 -
1051 -dnl --with-gmp=gmp-path
1052 -AC_ARG_WITH(gmp,
1053 -        [  --with-gmp=DIR          DIR where the gmp package is installed],
1054 -       [ echo "Package gmp : $withval" &&
1055 -         gmp_package=$withval &&
1056 -          GMP_INC=$gmp_package/include &&
1057 -          GMP_LIB=$gmp_package/lib &&
1058 -          CPPFLAGS=-DLINEAR_VALUE_IS_MP &&
1059 -          NEED_MP="yes"])
1060 -
1061 -AC_ARG_WITH(gmp-include,
1062 -        [  --with-gmp-include=DIR  DIR where gmp.h is installed],
1063 -       [ echo "Package gmp-include : $withval" &&
1064 -         gmp_include_package=$withval &&
1065 -          GMP_INC=$gmp_include_package &&
1066 -          CPPFLAGS=-DLINEAR_VALUE_IS_MP &&
1067 -         NEED_MP="yes"])
1068 -
1069 -AC_ARG_WITH(gmp-library,
1070 -        [  --with-gmp-library=DIR  DIR where the gmp library is installed],
1071 -       [ echo "Package gmp-library : $withval" &&
1072 -         gmp_library_package=$withval &&
1073 -          GMP_LIB=$gmp_library_package &&
1074 -          CPPFLAGS=-DLINEAR_VALUE_IS_MP &&
1075 -         NEED_MP="yes"])
1076 -
1077 -AC_ARG_ENABLE(int-version,
1078 -       [  --enable-int-version    'int' (32 bits) version is built],
1079 -       [ echo "Package int : $enableval" &&
1080 -         BITS="32" &&
1081 -          CPPFLAGS=-DLINEAR_VALUE_IS_LONG])
1082 -
1083 -AC_ARG_ENABLE(llint-version,
1084 -       [  --enable-llint-version  'long long int' (64 bits) version is built],
1085 -       [ echo "Package long long int : $enableval" &&
1086 -         BITS="64" &&
1087 -          CPPFLAGS=-DLINEAR_VALUE_IS_LONGLONG])
1088 -
1089 -AC_ARG_ENABLE(mp-version,
1090 -       [  --enable-mp-version     'MP' (multiple precision) version is built],
1091 -       [ echo "Package mp : $enableval" &&
1092 -         BITS="MP" &&
1093 -          CPPFLAGS=-DLINEAR_VALUE_IS_MP &&
1094 -          NEED_MP="yes"])
1095 -
1096 -AC_ARG_ENABLE(piplib-hybrid,
1097 -       [  --enable-piplib-hybrid   Link with piplib-hybrid],
1098 -       [ echo "Piplib-hybrid support : $enableval" &&
1099 -          if test "x$enableval" = "xyes"; then 
1100 -            CPPFLAGS=-DCANDL_HAS_PIPLIB_HYBRID
1101 -          fi])
1102 -
1103 -
1104 -dnl /**************************************************************************
1105 -dnl  *                            Where is GMP?                               *
1106 -dnl  **************************************************************************/
1107 -
1108 -
1109 -dnl Checking for gmp
1110 -AC_MSG_CHECKING(whether gmp works)
1111 -if test "$gmp_package" = "no"; then
1112 -  echo "GMP package not defined"
1113 -  AC_MSG_RESULT(no)
1114 -  TO_BUILD_MP=""
1115 -else
1116 -  if test "$NEED_MP" = "no"; then
1117 -    echo "Mode normal GMP"
1118 -    TO_BUILD="$TO_BUILD MP"
1119 -    AC_CHECK_HEADER(gmp.h,
1120 -                    [AC_SEARCH_LIBS([__gmpz_init], [gmp],
1121 -                                 [LIBS="$LIBS -lgmp"],
1122 -                                 [echo "Can't find gmp library." &&
1123 -                                  echo "MP version will not be built." &&
1124 -                                  TO_BUILD_MP=""])],
1125 -                   [echo "Can't find gmp headers." &&
1126 -                    echo "MP version will not be built." &&
1127 -                    TO_BUILD_MP=""])
1128 -  else
1129 -    dnl Default given by --with-X is "yes", --without-X is "no". We also
1130 -    dnl initialized manually all gmp_package* variables to "yes" (thus they are
1131 -    dnl supposed to be "yes" except if the user set them himself).
1132 -
1133 -    if test "$gmp_package" != "yes" ; then
1134 -      echo "(GMP path has been set by user)"
1135 -      GMP_DIR=$gmp_package
1136 -      dnl Useful for AC_CHECK_X to find what we want.
1137 -      CPPFLAGS="-I$GMP_DIR/include $CPPFLAGS"
1138 -      LDFLAGS="-L$GMP_DIR/lib $LDFLAGS"
1139 -    fi
1140 -
1141 -    if test "$gmp_include_package" != "yes" ; then
1142 -      CPPFLAGS="-I$GMP_INC $CPPFLAGS"
1143 -    fi
1144 -
1145 -    if test "$gmp_library_package" != "yes" ; then
1146 -      LDFLAGS="-L$GMP_LIB $LDFLAGS"
1147 -    fi
1148 -
1149 -    AC_CHECK_HEADER(gmp.h,
1150 -                    [],
1151 -                    [AC_MSG_ERROR(Can't find gmp headers.)])
1152 -    AC_SEARCH_LIBS([__gmpz_init], [gmp],
1153 -                 [LIBS="$LIBS -lgmp"],
1154 -                 [AC_MSG_ERROR(Can't find gmp library.)])
1155 -
1156 -    AC_MSG_RESULT(yes)
1157 -  fi
1158 -fi
1159 -
1160 -CANDL_ARG_LIBS_DEPENDENCIES
1161 -
1162 -
1163 -
1164 -dnl /**************************************************************************
1165 -dnl  *                            Substitutions                               *
1166 -dnl  **************************************************************************/
1167 -
1168 -
1169 -dnl Substitutions to do.
1170 -AC_SUBST(BITS)
1171 -AC_SUBST(DEFINE_HAS_SCOPLIB_LIB)
1172 -AC_SUBST(DEFINE_HAS_ISL_LIB)
1173 -AC_SUBST(ac_aux_dir)
1174 -
1175 -dnl Configure Makefiles.
1176 -AC_CONFIG_FILES([
1177 -       Makefile
1178 -       doc/Makefile
1179 -       doc/Doxyfile
1180 -       include/Makefile
1181 -       include/candl/candl.h
1182 -       source/Makefile
1183 -       tests/Makefile
1184 -       ],
1185 -       [test -z "$CONFIG_HEADERS" || echo timestamp > source/stamp-h.in])
1186 -
1187 -AC_OUTPUT
1188 -
1189 -echo "             /*-----------------------------------------------*"
1190 -echo "              *          Candl configuration is OK            *"
1191 -echo "              *-----------------------------------------------*/"
1192 -echo "It appears that your system is OK to start Candl compilation. You need"
1193 -echo "now to type \"make\". Lastly type \"make install\" to install Candl on"
1194 -echo "your system (log as root if necessary)."
1195 diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in
1196 index e172bda..510d8f1 100644
1197 --- a/doc/Doxyfile.in
1198 +++ b/doc/Doxyfile.in
1199 @@ -478,7 +478,8 @@ WARN_LOGFILE           =
1200  # with spaces.
1201  
1202  INPUT                  = @top_srcdir@/source \
1203 -                         @top_srcdir@/include/candl
1204 +                         @top_srcdir@/include/candl \
1205 +                         include/candl/macros.h
1206  
1207  # This tag can be used to specify the character encoding of the source files that 
1208  # doxygen parses. Internally doxygen uses the UTF-8 encoding, which is also the default 
1209 diff --git a/get_submodules.sh b/get_submodules.sh
1210 new file mode 100755
1211 index 0000000..94842b6
1212 --- /dev/null
1213 +++ b/get_submodules.sh
1214 @@ -0,0 +1,9 @@
1215 +#!/bin/bash
1216 +git submodule init
1217 +git submodule update
1218 +if test -f osl/autogen.sh; then
1219 +       (cd osl; ./autogen.sh && ./configure)
1220 +fi
1221 +if test -f piplib/autogen.sh; then
1222 +       (cd piplib; ./autogen.sh && ./configure)
1223 +fi
1224 diff --git a/include/Makefile.am b/include/Makefile.am
1225 deleted file mode 100644
1226 index ed48dcd..0000000
1227 --- a/include/Makefile.am
1228 +++ /dev/null
1229 @@ -1,54 +0,0 @@
1230 -#
1231 -#   /**-------------------------------------------------------------------**
1232 -#    **                              CAnDL                                **
1233 -#    **-------------------------------------------------------------------**
1234 -#    **                           Makefile.am                             **
1235 -#    **-------------------------------------------------------------------**
1236 -#    **                 First version: september 8th 2003                 **
1237 -#    **-------------------------------------------------------------------**/
1238 -#
1239 -#/*****************************************************************************
1240 -# *   CAnDL : the Chunky Analyser for Dependences in Loops (experimental)     *
1241 -# *****************************************************************************
1242 -# *                                                                           *
1243 -# * Copyright (C) 2003-2008 Cedric Bastoul                                    *
1244 -# *                                                                           *
1245 -# * This is free software; you can redistribute it and/or modify it under the *
1246 -# * terms of the GNU General Public License as published by the Free Software *
1247 -# * Foundation; either version 2 of the License, or (at your option) any      *
1248 -# * later version.                                                           *
1249 -# *                                                                           *
1250 -# * This software is distributed in the hope that it will be useful, but      *
1251 -# * WITHOUT ANY WARRANTY; without even the implied warranty of                *
1252 -# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General *
1253 -# * Public License for more details.                                          *
1254 -# *                                                                           *
1255 -# * You should have received a copy of the GNU General Public License along   *
1256 -# * with software; if not, write to the Free Software Foundation, Inc.,       *
1257 -# * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA                    *
1258 -# *                                                                           *
1259 -# * CAnDL, the Chunky Dependence Analyser                                     *
1260 -# * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr                        *
1261 -# *                                                                           *
1262 -# *****************************************************************************/
1263 -
1264 -
1265 -#############################################################################
1266 -SUBDIRS                        =
1267 -
1268 -#############################################################################
1269 -MAINTAINERCLEANFILES   = Makefile.in
1270 -
1271 -#############################################################################
1272 -
1273 -pkginclude_HEADERS     =                       \
1274 -       candl/candl.h                           \
1275 -       candl/dependence.h                      \
1276 -       candl/ddv.h                             \
1277 -       candl/matrix.h                          \
1278 -       candl/options.h                         \
1279 -       candl/piplib-wrapper.h                  \
1280 -       candl/program.h                         \
1281 -       candl/pruning.h                         \
1282 -       candl/statement.h                       \
1283 -       candl/violation.h
1284 diff --git a/include/candl/candl.h b/include/candl/candl.h
1285 new file mode 100644
1286 index 0000000..926511f
1287 --- /dev/null
1288 +++ b/include/candl/candl.h
1289 @@ -0,0 +1,50 @@
1290 +
1291 +   /**------ ( ----------------------------------------------------------**
1292 +    **       )\                      CAnDL                               **
1293 +    **----- /  ) --------------------------------------------------------**
1294 +    **     ( * (                    candl.h                              **
1295 +    **----  \#/  --------------------------------------------------------**
1296 +    **    .-"#'-.        First version: september 8th 2003               **
1297 +    **--- |"-.-"| -------------------------------------------------------**
1298 +          |     |
1299 +          |     |
1300 + ******** |     | *************************************************************
1301 + * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
1302 + ******************************************************************************
1303 + *                                                                            *
1304 + * Copyright (C) 2003-2008 Cedric Bastoul                                     *
1305 + *                                                                            *
1306 + * This is free software; you can redistribute it and/or modify it under the  *
1307 + * terms of the GNU Lesser General Public License as published by the Free    *
1308 + * Software Foundation; either version 3 of the License, or (at your option)  *
1309 + * any later version.                                                         *
1310 + *                                                                            *
1311 + * This software is distributed in the hope that it will be useful, but       *
1312 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
1313 + * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   *
1314 + * for more details.                                                          *
1315 + *                                                                            *
1316 + * You should have received a copy of the GNU Lesser General Public License   *
1317 + * along with software; if not, write to the Free Software Foundation, Inc.,  *
1318 + * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA                     *
1319 + *                                                                            *
1320 + * CAnDL, the Chunky Dependence Analyser                                      *
1321 + * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr                         *
1322 + *                                                                            *
1323 + ******************************************************************************/
1324 +
1325 +#ifndef CANDL_H
1326 +#define CANDL_H
1327 +
1328 +# include <candl/ddv.h>
1329 +# include <candl/dependence.h>
1330 +# include <candl/macros.h>
1331 +# include <candl/matrix.h>
1332 +# include <candl/options.h>
1333 +# include <candl/piplib-wrapper.h>
1334 +# include <candl/scop.h>
1335 +# include <candl/statement.h>
1336 +# include <candl/util.h>
1337 +# include <candl/violation.h>
1338 +
1339 +#endif
1340 diff --git a/include/candl/candl.h.in b/include/candl/candl.h.in
1341 deleted file mode 100644
1342 index 187981e..0000000
1343 --- a/include/candl/candl.h.in
1344 +++ /dev/null
1345 @@ -1,160 +0,0 @@
1346 -
1347 -   /**------ ( ----------------------------------------------------------**
1348 -    **       )\                      CAnDL                               **
1349 -    **----- /  ) --------------------------------------------------------**
1350 -    **     ( * (                    candl.h                              **
1351 -    **----  \#/  --------------------------------------------------------**
1352 -    **    .-"#'-.        First version: september 8th 2003               **
1353 -    **--- |"-.-"| -------------------------------------------------------**
1354 -          |     |
1355 -          |     |
1356 - ******** |     | *************************************************************
1357 - * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
1358 - ******************************************************************************
1359 - *                                                                            *
1360 - * Copyright (C) 2003-2008 Cedric Bastoul                                     *
1361 - *                                                                            *
1362 - * This is free software; you can redistribute it and/or modify it under the  *
1363 - * terms of the GNU Lesser General Public License as published by the Free    *
1364 - * Software Foundation; either version 3 of the License, or (at your option)  *
1365 - * any later version.                                                         *
1366 - *                                                                            *
1367 - * This software is distributed in the hope that it will be useful, but       *
1368 - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
1369 - * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   *
1370 - * for more details.                                                          *
1371 - *                                                                            *
1372 - * You should have received a copy of the GNU Lesser General Public License   *
1373 - * along with software; if not, write to the Free Software Foundation, Inc.,  *
1374 - * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA                     *
1375 - *                                                                            *
1376 - * CAnDL, the Chunky Dependence Analyser                                      *
1377 - * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr                         *
1378 - *                                                                            *
1379 - ******************************************************************************/
1380 -
1381 -
1382 -/******************************************************************************
1383 - *  THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM candl.h.in BY configure   *
1384 - ******************************************************************************/
1385 -
1386 -
1387 -#ifndef CANDL_H
1388 -# define CANDL_H
1389 -
1390 -# define CANDL_RELEASE "@PACKAGE_VERSION@"
1391 -# define CANDL_VERSION "@BITS@"
1392 -@DEFINE_HAS_SCOPLIB_LIB@
1393 -@DEFINE_HAS_ISL_LIB@
1394 -
1395 -
1396 -# include <piplib/piplib@BITS@.h>
1397 -# include <candl/options.h>
1398 -# include <candl/matrix.h>
1399 -# include <candl/statement.h>
1400 -# include <candl/program.h>
1401 -# include <candl/dependence.h>
1402 -# include <candl/ddv.h>
1403 -# include <candl/violation.h>
1404 -# include <candl/pruning.h>
1405 -
1406 -# define CANDL_UNSET -1 /* Must be negative (we do use that property).
1407 -                         * All other constants have to be different.
1408 -                         */
1409 -
1410 -# define CANDL_RAW    1
1411 -# define CANDL_WAR    2
1412 -# define CANDL_WAW    3
1413 -# define CANDL_RAR    4
1414 -# define CANDL_RAW_SCALPRIV    5
1415 -
1416 -# define CANDL_ASSIGNMENT  1
1417 -# define CANDL_P_REDUCTION 2
1418 -# define CANDL_M_REDUCTION 3
1419 -# define CANDL_T_REDUCTION 4
1420 -
1421 -# define CANDL_EQUAL 1
1422 -# define CANDL_POSIT 2
1423 -# define CANDL_LATER 3
1424 -# define CANDL_NEVER 4
1425 -
1426 -# define CANDL_NB_INFOS  3
1427 -
1428 -# define CANDL_MAX_STRING  2048
1429 -# define CANDL_TEMP_OUTPUT "candl.temp"
1430 -
1431 -/* Useful macros. */
1432 -# define CANDL_max(x,y)    ((x) > (y)? (x) : (y))
1433 -# define CANDL_min(x,y)    ((x) < (y)? (x) : (y))
1434 -
1435 -# define CANDL_FAIL(msg)   { fprintf(stderr, "[Candl] " msg "\n"); exit(1); }
1436 -
1437 -/******************************************************************************
1438 - *                                   FORMAT                                   *
1439 - ******************************************************************************/
1440 -#if defined(LINEAR_VALUE_IS_LONGLONG)
1441 -#define CANDL_FMT "%4lld "
1442 -#elif defined(LINEAR_VALUE_IS_LONG)
1443 -#define CANDL_FMT "%4ld "
1444 -#else  /* GNUMP */
1445 -#define CANDL_FMT "%4s"
1446 -#endif
1447 -
1448 -/******************************************************************************
1449 - *                             CANDL GMP MACROS                               *
1450 - ******************************************************************************/
1451 -#ifdef LINEAR_VALUE_IS_MP
1452 -/* Basic Macros */
1453 -#define CANDL_init(val)                (mpz_init((val)))
1454 -#define CANDL_assign(v1,v2)            (mpz_set((v1),(v2)))
1455 -#define CANDL_set_si(val,i)            (mpz_set_si((val),(i)))
1456 -#define CANDL_get_si(val)              (mpz_get_si((val)))
1457 -#define CANDL_clear(val)               (mpz_clear((val)))
1458 -#define CANDL_print(Dst,fmt,val)       { char *str; \
1459 -                                         str = mpz_get_str(0,10,(val)); \
1460 -                                         fprintf((Dst),(fmt),str); free(str); \
1461 -                                       }
1462 -
1463 -/* Boolean operators on 'Value' or 'Entier' */
1464 -#define CANDL_eq(v1,v2)                (mpz_cmp((v1),(v2)) == 0)
1465 -#define CANDL_ne(v1,v2)                (mpz_cmp((v1),(v2)) != 0)
1466 -
1467 -/* Binary operators on 'Value' or 'Entier' */
1468 -#define CANDL_increment(ref,val)       (mpz_add_ui((ref),(val),1))
1469 -#define CANDL_decrement(ref,val)       (mpz_sub_ui((ref),(val),1))
1470 -#define CANDL_subtract(ref,val1,val2) (mpz_sub((ref),(val1),(val2)))
1471 -#define CANDL_oppose(ref,val)          (mpz_neg((ref),(val)))
1472 -
1473 -/* Conditional operations on 'Value' or 'Entier' */
1474 -#define CANDL_zero_p(val)              (mpz_sgn(val) == 0)
1475 -#define CANDL_notzero_p(val)           (mpz_sgn(val) != 0)
1476 -
1477 -/******************************************************************************
1478 - *                          CANDL BASIC TYPES MACROS                          *
1479 - ******************************************************************************/
1480 -#else
1481 -/* Basic Macros */
1482 -#define CANDL_init(val)                ((val) = 0)
1483 -#define CANDL_assign(v1,v2)            ((v1)  = (v2))
1484 -#define CANDL_set_si(val,i)            ((val) = (Entier)(i))
1485 -#define CANDL_get_si(val)              ((val))
1486 -#define CANDL_clear(val)               ((val) = 0)
1487 -#define CANDL_print(Dst,fmt,val)       (fprintf((Dst),(fmt),(val)))
1488 -
1489 -/* Boolean operators on 'Value' or 'Entier' */
1490 -#define CANDL_eq(v1,v2)                ((v1)==(v2))
1491 -#define CANDL_ne(v1,v2)                ((v1)!=(v2))
1492 -
1493 -/* Binary operators on 'Value' or 'Entier' */
1494 -#define CANDL_increment(ref,val)       ((ref) = (val)+(Entier)(1))
1495 -#define CANDL_decrement(ref,val)       ((ref) = (val)-(Entier)(1))
1496 -#define CANDL_subtract(ref,val1,val2) ((ref) = (val1)-(val2))
1497 -#define CANDL_oppose(ref,val)          ((ref) = (-(val)))
1498 -
1499 -/* Conditional operations on 'Value' or 'Entier' */
1500 -#define CANDL_zero_p(val)               CANDL_eq(val,0)
1501 -#define CANDL_notzero_p(val)            CANDL_ne(val,0)
1502 -
1503 -#endif
1504 -
1505 -#endif // !CANDL_H
1506 diff --git a/include/candl/ddv.h b/include/candl/ddv.h
1507 index bbc97db..8ae9a61 100644
1508 --- a/include/candl/ddv.h
1509 +++ b/include/candl/ddv.h
1510 @@ -38,26 +38,18 @@
1511   * \author Louis-Noel Pouchet
1512   */
1513  
1514 -
1515  #ifndef CANDL_DDV_H
1516  # define CANDL_DDV_H
1517  
1518 -
1519  # include <stdio.h>
1520 -# include <candl/statement.h>
1521 -# include <candl/matrix.h>
1522 -# include <candl/program.h>
1523 -# include <candl/options.h>
1524 -# include <candl/dependence.h>
1525 -
1526 -
1527  
1528  # if defined(__cplusplus)
1529  extern "C"
1530    {
1531  # endif
1532  
1533 -
1534 +struct osl_scop;
1535 +struct osl_dependence;
1536  
1537  /******************************************************************************
1538   *                        Dependence Distance structures                      *
1539 @@ -112,9 +104,6 @@ extern "C"
1540  
1541      typedef struct candl_ddv CandlDDV;
1542  
1543 -
1544 -
1545 -
1546  /******************************************************************************
1547   *                         Memory deallocation function                       *
1548   ******************************************************************************/
1549 @@ -127,7 +116,6 @@ extern "C"
1550  CandlDDV*
1551  candl_ddv_malloc();
1552  
1553 -
1554  /**
1555   * candl_ddv_alloc: Allocate a ddv for a loop of depth 'size'.
1556   *
1557 @@ -136,7 +124,6 @@ candl_ddv_malloc();
1558  CandlDDV*
1559  candl_ddv_alloc(int);
1560  
1561 -
1562  /**
1563   * candl_ddv_free: Free a ddv.
1564   *
1565 @@ -145,7 +132,6 @@ candl_ddv_alloc(int);
1566  void
1567  candl_ddv_free(CandlDDV*);
1568  
1569 -
1570  /**
1571   * candl_ddv_set_type_at: Set the type of a ddv component. Type is one of
1572   * '=', '>', '<', '*' or 'constant' as defined by the enum e_dv_type.
1573 @@ -173,12 +159,10 @@ candl_ddv_set_value_at(CandlDDV*, int, int);
1574  void
1575  candl_ddv_set_deptype(CandlDDV*, int);
1576  
1577 -
1578  /******************************************************************************
1579   *                          Structure display function                        *
1580   ******************************************************************************/
1581  
1582 -
1583  /**
1584   * candl_ddv_print: print a ddv.
1585   *
1586 @@ -186,7 +170,6 @@ candl_ddv_set_deptype(CandlDDV*, int);
1587  void
1588  candl_ddv_print(FILE*, CandlDDV*);
1589  
1590 -
1591  /******************************************************************************
1592   *                            Processing functions                            *
1593   ******************************************************************************/
1594 @@ -199,7 +182,7 @@ candl_ddv_print(FILE*, CandlDDV*);
1595   *
1596   */
1597  CandlDDV*
1598 -candl_ddv_extract_in_loop(CandlProgram*, CandlDependence*, int);
1599 +candl_ddv_extract_in_loop(struct osl_scop*, struct osl_dependence*, int);
1600      
1601  /**
1602   * candl_loops_are_permutable: output 1 if the 2 loops are permutable.
1603 @@ -207,10 +190,7 @@ candl_ddv_extract_in_loop(CandlProgram*, CandlDependence*, int);
1604   *
1605   */
1606  int
1607 -candl_loops_are_permutable(CandlProgram* program, CandlDependence* deps,
1608 -                          int loop_id1, int loop_id2);
1609 -    
1610 -
1611 +candl_loops_are_permutable(struct osl_scop*, struct osl_dependence*, int, int);
1612  
1613  # if defined(__cplusplus)
1614    }
1615 diff --git a/include/candl/dependence.h b/include/candl/dependence.h
1616 index 0f40e65..9205de4 100644
1617 --- a/include/candl/dependence.h
1618 +++ b/include/candl/dependence.h
1619 @@ -33,153 +33,99 @@
1620   *                                                                            *
1621   ******************************************************************************/
1622  
1623 -
1624  #ifndef CANDL_DEPENDENCE_H
1625  # define CANDL_DEPENDENCE_H
1626  
1627 -
1628  # include <stdio.h>
1629 -# include <candl/statement.h>
1630 -# include <candl/matrix.h>
1631 -# include <candl/program.h>
1632  # include <candl/options.h>
1633  
1634 -
1635 -
1636 -# define CANDL_ARRAY_BUFF_SIZE         2048
1637 -# define CANDL_VAR_UNDEF               1
1638 -# define CANDL_VAR_IS_DEF              2
1639 -# define CANDL_VAR_IS_USED             3
1640 -# define CANDL_VAR_IS_DEF_USED         4
1641 -
1642 +# define CANDL_ARRAY_BUFF_SIZE 2048
1643 +# define CANDL_VAR_UNDEF       1
1644 +# define CANDL_VAR_IS_DEF      2
1645 +# define CANDL_VAR_IS_USED     3
1646 +# define CANDL_VAR_IS_DEF_USED 4
1647  
1648  # if defined(__cplusplus)
1649  extern "C"
1650    {
1651  # endif
1652  
1653 -
1654 -/**
1655 - * CandlDependence structure:
1656 - * this structure contains all the informations about a data dependence, it is
1657 - * also a node of the linked list of all dependences of the dependence graph.
1658 - */
1659 -struct candldependence
1660 -{ CandlStatement  * source;      /**< Pointer to source statement. */
1661 -  CandlStatement  * target;      /**< Pointer to target statement. */
1662 -  int depth;                     /**< Dependence level. */
1663 -  int type;                      /**< Dependence type: a dependence from source
1664 -                                   *   to target can be:
1665 -                                  *   - CANDL_UNSET if the dependence type is
1666 -                                  *     still not set,
1667 -                                  *   - CANDL_RAW if source writes M and
1668 -                                  *     target read M (flow-dependence),
1669 -                                  *   - CANDL_WAR if source reads M and
1670 -                                  *     target writes M (anti-dependence),
1671 -                                  *   - CANDL_WAW if source writes M and
1672 -                                  *     target writes M too (output-dependence)
1673 -                                  *   - CANDL_RAR if source reads M and
1674 -                                  *     target reads M too (input-dependence).
1675 -                                  */
1676 -  int ref_source;                /**< Position of source reference. */
1677 -  int ref_target;                /**< Position of target reference. */
1678 -  CandlMatrix * domain;          /**< Dependence polyhedron. */
1679 -
1680 -  void* usr;                    /**< User field, for library users
1681 -                                   convenience. */
1682 -  struct candldependence * next; /**< Pointer to next dependence */
1683 -};
1684 -typedef struct candldependence CandlDependence;
1685 -typedef struct candldependence candl_dependence_t;
1686 -typedef struct candldependence * candl_dependence_p;
1687 -
1688 -
1689 -/******************************************************************************
1690 - *                          Structure display function                        *
1691 - ******************************************************************************/
1692 -void candl_dependence_print_structure(FILE *, candl_dependence_p, int);
1693 -void candl_dependence_print(FILE *, candl_dependence_p);
1694 -void candl_dependence_pprint(FILE *, candl_dependence_p);
1695 -void candl_dependence_view(candl_dependence_p);
1696 -# ifdef CANDL_SUPPORTS_SCOPLIB
1697 -CandlDependence* candl_dependence_read_from_scop(scoplib_scop_p, CandlProgram*);
1698 -void candl_dependence_update_scop_with_deps(scoplib_scop_p, CandlDependence*);
1699 -void candl_dependence_print_scop(FILE*, FILE*, CandlDependence*);
1700 -# endif
1701 +struct osl_relation;
1702 +struct osl_statement;
1703 +struct osl_scop;
1704 +struct osl_dependence;
1705  
1706  #ifdef CANDL_SUPPORTS_ISL
1707 -CandlDependence* candl_dependence_isl_simplify(CandlDependence*, CandlProgram*);
1708 +struct osl_dependence* candl_dependence_isl_simplify(struct osl_dependence*,
1709 +                                        struct osl_scop*);
1710  # endif
1711  
1712 -
1713 -/******************************************************************************
1714 - *                         Memory alloc/dealloc function                      *
1715 - ******************************************************************************/
1716 -candl_dependence_p      candl_dependence_malloc();
1717 -void                   candl_dependence_free(candl_dependence_p);
1718 -
1719 +/*+***************************************************************************
1720 + *                          Structure display function                       *
1721 + *****************************************************************************/
1722 +void                   candl_dependence_pprint(FILE*, struct osl_dependence*);
1723 +void                   candl_dependence_view(struct osl_dependence*);
1724  
1725  /******************************************************************************
1726   *                             Processing functions                           *
1727   ******************************************************************************/
1728 -int                    candl_dependence_gcd_test(CandlStatement*,
1729 -                                                 CandlStatement*,
1730 -                                                 CandlMatrix*, int);
1731 -int                    candl_dependence_check(CandlProgram *,
1732 -                                              candl_dependence_p,
1733 -                                              CandlOptions *);
1734 -candl_dependence_p      candl_dependence(CandlProgram *, CandlOptions *);
1735 -
1736 +int                    candl_dependence_gcd_test(struct osl_statement*,
1737 +                                        struct osl_statement*,
1738 +                                        struct osl_relation*, int);
1739 +int                    candl_dependence_check(struct osl_scop*,
1740 +                                        struct osl_dependence*,
1741 +                                        candl_options_p);
1742 +struct osl_dependence* candl_dependence(struct osl_scop*, candl_options_p);
1743 +void                   candl_dependence_add_extension(struct osl_scop*,
1744 +                                        candl_options_p);
1745 +
1746 +/*+***************************************************************************
1747 + *                    Memory allocation/deallocation function                *
1748 + *****************************************************************************/
1749 +void                   candl_dependence_init_fields(struct osl_scop*,
1750 +                                        struct osl_dependence*);
1751  
1752  /******************************************************************************
1753   *                          Scalar analysis functions                         *
1754   ******************************************************************************/
1755 -int
1756 -candl_dependence_var_is_scalar (candl_program_p, int);
1757 -
1758 -CandlStatement**
1759 -candl_dependence_refvar_chain(candl_program_p, CandlStatement*, int, int);
1760 -
1761 -int
1762 -candl_dependence_var_is_ref(CandlStatement*, int);
1763 -
1764 -int
1765 -candl_dependence_check_domain_is_included(CandlStatement*, CandlStatement*,
1766 -                                         CandlMatrix*, int);
1767 -
1768 -int
1769 -candl_dependence_scalar_is_privatizable_at(candl_program_p, int, int);
1770 -
1771 -int
1772 -candl_dependence_is_loop_carried (candl_program_p, CandlDependence*, int);
1773 -
1774 -void
1775 -candl_dependence_prune_scalar_waw (candl_program_p, CandlOptions*,
1776 -                                  CandlDependence**);
1777 -
1778 -void
1779 -candl_dependence_prune_with_privatization (candl_program_p, CandlOptions*,
1780 -                                          CandlDependence**);
1781 -
1782 -int
1783 -candl_dependence_scalar_renaming(candl_program_p, CandlOptions*,
1784 -                                CandlDependence**);
1785 -
1786 -int
1787 -candl_dependence_analyze_scalars(candl_program_p, CandlOptions*);
1788 +int                    candl_dependence_var_is_scalar(struct osl_scop*, int);
1789 +struct osl_statement** candl_dependence_refvar_chain(struct osl_scop*,
1790 +                                        struct osl_statement*, int, int);
1791 +int                    candl_dependence_var_is_ref(struct osl_statement*, int);
1792 +int                    candl_dependence_check_domain_is_included(
1793 +                                        struct osl_statement*,
1794 +                                        struct osl_statement*,
1795 +                                        struct osl_relation*, int);
1796 +int                    candl_dependence_scalar_is_privatizable_at(
1797 +                                        struct osl_scop*, int, int);
1798 +int                    candl_dependence_is_loop_carried(struct osl_scop*,
1799 +                                        struct osl_dependence*, int);
1800 +void                   candl_dependence_prune_scalar_waw(struct osl_scop*,
1801 +                                        candl_options_p,
1802 +                                        struct osl_dependence**);
1803 +void                   candl_dependence_prune_with_privatization(
1804 +                                        struct osl_scop*,
1805 +                                        candl_options_p,
1806 +                                        struct osl_dependence**);
1807 +int                    candl_dependence_scalar_renaming(struct osl_scop*,
1808 +                                        candl_options_p,
1809 +                                        struct osl_dependence**);
1810 +int                    candl_dependence_analyze_scalars(struct osl_scop*,
1811 +                                        candl_options_p);
1812  
1813  /******************************************************************************
1814   *                          Miscellaneous functions                           *
1815   ******************************************************************************/
1816 -int
1817 -candl_num_dependences(CandlDependence *candl_deps);
1818 -
1819 -void
1820 -candl_compute_last_writer (CandlDependence *dep, CandlProgram *prog);
1821 +struct osl_relation*   candl_dependence_get_relation_ref_source_in_dep(
1822 +                                        struct osl_dependence*);
1823 +struct osl_relation*   candl_dependence_get_relation_ref_target_in_dep(
1824 +                                        struct osl_dependence*);
1825 +int                    candl_num_dependences(struct osl_dependence*);
1826 +void                   candl_compute_last_writer(struct osl_dependence*,
1827 +                                        struct osl_scop*);
1828 +struct osl_dependence* candl_dependence_prune_transitively_covered(
1829 +                                        struct osl_dependence*);
1830  
1831 -CandlDependence*
1832 -candl_dependence_prune_transitively_covered (CandlDependence* deps);
1833 -    
1834  # if defined(__cplusplus)
1835    }
1836  # endif
1837 diff --git a/include/candl/macros.h.in b/include/candl/macros.h.in
1838 new file mode 100644
1839 index 0000000..def4643
1840 --- /dev/null
1841 +++ b/include/candl/macros.h.in
1842 @@ -0,0 +1,160 @@
1843 +
1844 +   /**------ ( ----------------------------------------------------------**
1845 +    **       )\                      CAnDL                               **
1846 +    **----- /  ) --------------------------------------------------------**
1847 +    **     ( * (                    candl.h                              **
1848 +    **----  \#/  --------------------------------------------------------**
1849 +    **    .-"#'-.        First version: september 8th 2003               **
1850 +    **--- |"-.-"| -------------------------------------------------------**
1851 +          |     |
1852 +          |     |
1853 + ******** |     | *************************************************************
1854 + * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
1855 + ******************************************************************************
1856 + *                                                                            *
1857 + * Copyright (C) 2003-2008 Cedric Bastoul                                     *
1858 + *                                                                            *
1859 + * This is free software; you can redistribute it and/or modify it under the  *
1860 + * terms of the GNU Lesser General Public License as published by the Free    *
1861 + * Software Foundation; either version 3 of the License, or (at your option)  *
1862 + * any later version.                                                         *
1863 + *                                                                            *
1864 + * This software is distributed in the hope that it will be useful, but       *
1865 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
1866 + * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   *
1867 + * for more details.                                                          *
1868 + *                                                                            *
1869 + * You should have received a copy of the GNU Lesser General Public License   *
1870 + * along with software; if not, write to the Free Software Foundation, Inc.,  *
1871 + * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA                     *
1872 + *                                                                            *
1873 + * CAnDL, the Chunky Dependence Analyser                                      *
1874 + * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr                         *
1875 + *                                                                            *
1876 + ******************************************************************************/
1877 +
1878 +
1879 +/******************************************************************************
1880 + *  THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM macros.h.in BY configure  *
1881 + ******************************************************************************/
1882 +
1883 +#ifndef CANDL_MACROS_H
1884 +# define CANDL_MACROS_H
1885 +
1886 +# define CANDL_EQUAL 1
1887 +# define CANDL_POSIT 2
1888 +# define CANDL_LATER 3
1889 +# define CANDL_NEVER 4
1890 +
1891 +# define CANDL_NB_INFOS  3
1892 +
1893 +# define CANDL_MAX_STRING  2048
1894 +# define CANDL_TEMP_OUTPUT "candl.temp"
1895 +
1896 +# define CANDL_RELEASE "@PACKAGE_VERSION@"
1897 +# define CANDL_VERSION "@BITS@"
1898 +@DEFINE_HAS_ISL_LIB@
1899 +
1900 +/* Useful macros. */
1901 +# define CANDL_max(x,y)    ((x) > (y)? (x) : (y))
1902 +# define CANDL_min(x,y)    ((x) < (y)? (x) : (y))
1903 +
1904 +# define CANDL_info(msg)                                                   \
1905 +         do {                                                              \
1906 +           fprintf(stderr,"[Candl] Info: "msg" (%s).\n", __func__);        \
1907 +         } while (0)
1908 +
1909 +# define CANDL_warning(msg)                                                \
1910 +         do {                                                              \
1911 +           fprintf(stderr,"[Candl] Warning: "msg" (%s).\n", __func__);     \
1912 +         } while (0)
1913 +
1914 +# define CANDL_error(msg)                                                  \
1915 +         do {                                                              \
1916 +           fprintf(stderr,"[Candl] Error: "msg" (%s).\n", __func__);       \
1917 +           exit(1);                                                        \
1918 +         } while (0)
1919 +
1920 +# define CANDL_malloc(ptr, type, size)                                     \
1921 +         do {                                                              \
1922 +           if (((ptr) = (type)malloc(size)) == NULL)                       \
1923 +             CANDL_error("memory overflow");                               \
1924 +         } while (0)
1925 +
1926 +# define CANDL_realloc(ptr, type, size)                                    \
1927 +         do {                                                              \
1928 +           if (((ptr) = (type)realloc(ptr, size)) == NULL)                 \
1929 +             CANDL_error("memory overflow");                               \
1930 +         } while (0)
1931 +
1932 +# define CANDL_fail(msg)   { fprintf(stderr, "[Candl] " msg "\n"); exit(1); }
1933 +
1934 +/******************************************************************************
1935 + *                                   FORMAT                                   *
1936 + ******************************************************************************/
1937 +#if defined(CANDL_LINEAR_VALUE_IS_LONGLONG)
1938 +#define CANDL_FMT "%4lld "
1939 +#elif defined(CANDL_LINEAR_VALUE_IS_LONG)
1940 +#define CANDL_FMT "%4ld "
1941 +#else  /* GNUMP */
1942 +#define CANDL_FMT "%4s"
1943 +#endif
1944 +
1945 +/******************************************************************************
1946 + *                             CANDL GMP MACROS                               *
1947 + ******************************************************************************/
1948 +#ifdef CANDL_LINEAR_VALUE_IS_MP
1949 +/* Basic Macros */
1950 +#define CANDL_init(val)                (mpz_init((val)))
1951 +#define CANDL_assign(v1,v2)            (mpz_set((v1),(v2)))
1952 +#define CANDL_set_si(val,i)            (mpz_set_si((val),(i)))
1953 +#define CANDL_get_si(val)              (mpz_get_si((val)))
1954 +#define CANDL_clear(val)               (mpz_clear((val)))
1955 +#define CANDL_print(Dst,fmt,val)       { char *str; \
1956 +                                         str = mpz_get_str(0,10,(val)); \
1957 +                                         fprintf((Dst),(fmt),str); free(str); \
1958 +                                       }
1959 +
1960 +/* Boolean operators on 'Value' or 'Entier' */
1961 +#define CANDL_eq(v1,v2)                (mpz_cmp((v1),(v2)) == 0)
1962 +#define CANDL_ne(v1,v2)                (mpz_cmp((v1),(v2)) != 0)
1963 +
1964 +/* Binary operators on 'Value' or 'Entier' */
1965 +#define CANDL_increment(ref,val)       (mpz_add_ui((ref),(val),1))
1966 +#define CANDL_decrement(ref,val)       (mpz_sub_ui((ref),(val),1))
1967 +#define CANDL_subtract(ref,val1,val2) (mpz_sub((ref),(val1),(val2)))
1968 +#define CANDL_oppose(ref,val)          (mpz_neg((ref),(val)))
1969 +
1970 +/* Conditional operations on 'Value' or 'Entier' */
1971 +#define CANDL_zero_p(val)              (mpz_sgn(val) == 0)
1972 +#define CANDL_notzero_p(val)           (mpz_sgn(val) != 0)
1973 +
1974 +/******************************************************************************
1975 + *                          CANDL BASIC TYPES MACROS                          *
1976 + ******************************************************************************/
1977 +#else
1978 +/* Basic Macros */
1979 +#define CANDL_init(val)                ((val) = 0)
1980 +#define CANDL_assign(v1,v2)            ((v1)  = (v2))
1981 +#define CANDL_set_si(val,i)            ((val) = (Entier)(i))
1982 +#define CANDL_get_si(val)              ((val))
1983 +#define CANDL_clear(val)               ((val) = 0)
1984 +#define CANDL_print(Dst,fmt,val)       (fprintf((Dst),(fmt),(val)))
1985 +
1986 +/* Boolean operators on 'Value' or 'Entier' */
1987 +#define CANDL_eq(v1,v2)                ((v1)==(v2))
1988 +#define CANDL_ne(v1,v2)                ((v1)!=(v2))
1989 +
1990 +/* Binary operators on 'Value' or 'Entier' */
1991 +#define CANDL_increment(ref,val)       ((ref) = (val)+(Entier)(1))
1992 +#define CANDL_decrement(ref,val)       ((ref) = (val)-(Entier)(1))
1993 +#define CANDL_subtract(ref,val1,val2) ((ref) = (val1)-(val2))
1994 +#define CANDL_oppose(ref,val)          ((ref) = (-(val)))
1995 +
1996 +/* Conditional operations on 'Value' or 'Entier' */
1997 +#define CANDL_zero_p(val)               CANDL_eq(val,0)
1998 +#define CANDL_notzero_p(val)            CANDL_ne(val,0)
1999 +
2000 +#endif
2001 +
2002 +#endif // !CANDL_MACROS_H
2003 diff --git a/include/candl/matrix.h b/include/candl/matrix.h
2004 index 7bbc13b..60e525f 100644
2005 --- a/include/candl/matrix.h
2006 +++ b/include/candl/matrix.h
2007 @@ -33,92 +33,26 @@
2008   *                                                                            *
2009   ******************************************************************************/
2010  
2011 -
2012  #ifndef CANDL_MATRIX_H
2013  # define CANDL_MATRIX_H
2014  
2015 -# include <stdio.h>
2016 -# include <piplib/piplib.h>
2017 -
2018 -# ifdef LINEAR_VALUE_IS_LONG
2019 -#  define CLAN_INT_T_IS_LONG
2020 -# endif
2021 -# ifdef LINEAR_VALUE_IS_LONGLONG
2022 -#  define CLAN_INT_T_IS_LONGLONG
2023 -# endif
2024 -# ifdef LINEAR_VALUE_IS_MP
2025 -#  define CLAN_INT_T_IS_MP
2026 -# endif
2027 +# include <candl/violation.h>
2028  
2029  # if defined(__cplusplus)
2030  extern "C"
2031    {
2032  # endif
2033  
2034 +struct osl_relation;
2035 +struct osl_dependence;
2036  
2037 -/**
2038 - * The matrix structure comes directly from PipLib (defined in piplib/piplib.h)
2039 - * which is directly the PolyLib Matrix (defined in polylib/types.h)
2040 - * here is how it looks like (at least in PipLib 1.3.5 version):
2041 - *
2042 - * struct pipmatrix
2043 - * { unsigned NbRows;    // The number of rows (= NbConstraints in Polyhedron).
2044 - *   unsigned NbColumns; // The number of columns (= Dimension+2 in Polyhedron).
2045 - *   Value **p;          // An array of pointers to the beginning of each row.
2046 - *   Value *p_Init;      // The matrix is stored here, contiguously in memory.
2047 - *   int p_Init_size;    // Needed to free the memory allocated by mpz_init.
2048 - * } ;
2049 - * typedef struct pipmatrix PipMatrix ;
2050 - */
2051 -
2052 -typedef PipMatrix CandlMatrix;
2053 -
2054 -
2055 -/**
2056 - * CandlMatrixList structure:
2057 - * this structure reprensents a node of a linked list of CandlMatrix structures.
2058 - */
2059 -struct candlmatrixlist
2060 -{ CandlMatrix * matrix;         /**< An element of the list. */
2061 -  struct candlmatrixlist * next;/**< Pointer to the next element of the list.*/
2062 -};
2063 -typedef struct candlmatrixlist CandlMatrixList;
2064 -
2065 -
2066 -/******************************************************************************
2067 - *                          Structure display function                        *
2068 - ******************************************************************************/
2069 -void candl_matrix_print_structure(FILE *, CandlMatrix *, int);
2070 -void candl_matrix_print(FILE *, CandlMatrix *);
2071 -void candl_matrix_print_data(FILE *, CandlMatrix *);
2072 -void candl_matrix_list_print_structure(FILE *, CandlMatrixList *, int);
2073 -void candl_matrix_list_print(FILE *, CandlMatrixList *);
2074 -
2075 -/******************************************************************************
2076 - *                         Memory deallocation function                       *
2077 - ******************************************************************************/
2078 -void candl_matrix_free(CandlMatrix *);
2079 -void candl_matrix_list_free(CandlMatrixList *);
2080 -
2081 -
2082 -/******************************************************************************
2083 - *                              Reading functions                             *
2084 - ******************************************************************************/
2085 -CandlMatrix * candl_matrix_read(FILE *);
2086 -CandlMatrixList * candl_matrix_list_read(FILE *);
2087 -
2088 -
2089 -/******************************************************************************
2090 - *                            Processing functions                            *
2091 - ******************************************************************************/
2092 -CandlMatrix     * candl_matrix_malloc(int, int);
2093 -CandlMatrixList * candl_matrix_list_malloc();
2094 -CandlMatrix     * candl_matrix_violation(CandlMatrix  *, CandlMatrix  *,
2095 -                                         CandlMatrix  *, int, int);
2096 -int            candl_matrix_check_point (CandlMatrix* , CandlMatrix* );
2097 +candl_violation_p candl_matrix_violation(struct osl_dependence*,
2098 +                               struct osl_relation*, struct osl_relation*,
2099 +                               int, int);
2100 +int               candl_matrix_check_point(struct osl_relation*,
2101 +                               struct osl_relation*);
2102  
2103  # if defined(__cplusplus)
2104    }
2105  # endif
2106 -#endif /* define CANDL_DEPENDENCE_H */
2107 -
2108 +#endif
2109 diff --git a/include/candl/options.h b/include/candl/options.h
2110 index e62fddb..7154cb5 100644
2111 --- a/include/candl/options.h
2112 +++ b/include/candl/options.h
2113 @@ -33,7 +33,6 @@
2114   *                                                                            *
2115   ******************************************************************************/
2116  
2117 -
2118  #ifndef CANDL_OPTIONS_H
2119  # define CANDL_OPTIONS_H
2120  
2121 @@ -44,60 +43,55 @@ extern "C"
2122    {
2123  # endif
2124  
2125 -
2126  /**
2127 - * CandlOptions structure:
2128 + * candl_options structure:
2129   * this structure contains all the informations on the state of Candl options.
2130   */
2131 -struct candloptions
2132 -{ /* OPTIONS FOR DEPENDENCE COMPUTATION */
2133 +struct candl_options {
2134 +  /* OPTIONS FOR DEPENDENCE COMPUTATION */
2135    int waw;       /**< 1 if write after write (output) dependences matter. */
2136    int raw;       /**< 1 if read  after write (flow)   dependences matter. */
2137    int war;       /**< 1 if write after read  (anti)   dependences matter. */
2138    int rar;       /**< 1 if read  after read  (input)  dependences matter. */
2139    int commute;   /**< 1 to use commutativity to simplify dependences. */
2140    int fullcheck; /**< 1 to compute all dependence violations. */
2141 -  int depgraph;  /**< 1 to print the dependence graph. */
2142 -  int violgraph; /**< 1 to print the violation graph. */
2143    int scalar_renaming; /**< 1 to enable scalar renaming. */
2144    int scalar_privatization; /**< 1 to enable scalar privatization. */
2145    int scalar_expansion; /**< 1 to enable scalar privatization. */
2146    int lastwriter; /**< 1 to compute last writer */
2147 -  int readscop; /**< 1 to enable reading from a .scop formatted file. */
2148 -  int writescop; /**< 1 to enable writing to a .scop formatted file. */
2149 -  int scoptocandl; /**< 1 to act as a .scop to candl converter. */
2150    int verbose; /**< 1 to enable verbose output. */
2151 +  int outscop; /**< 1 to print the scop with dependences. */
2152 +  int autocorrect; /**< 1 to correct violations. fullcheck is set to 1 and 
2153 +                     * the -test is required.
2154 +                    */
2155    /* UNDOCUMENTED OPTIONS FOR THE AUTHOR ONLY */
2156    int view;      /**< 1 to call dot and gv to visualize the graphs. */
2157    int structure; /**< 1 to print internal dependence structure. */
2158    int prune_dups; /**< 1 to use experimental dependence pruning algorithm. */
2159 -} ;
2160 -typedef struct candloptions CandlOptions;
2161 +};
2162  
2163 +typedef struct candl_options  candl_options_t;
2164 +typedef struct candl_options* candl_options_p;
2165  
2166  /******************************************************************************
2167   *                          Structure display function                        *
2168   ******************************************************************************/
2169 -void candl_options_print(FILE *, CandlOptions *);
2170 -
2171 +void candl_options_print(FILE *, candl_options_p);
2172  
2173  /******************************************************************************
2174   *                         Memory deallocation function                       *
2175   ******************************************************************************/
2176 -void candl_options_free(CandlOptions *);
2177 -
2178 +void candl_options_free(candl_options_p);
2179  
2180  /******************************************************************************
2181   *                               Reading function                             *
2182   ******************************************************************************/
2183 -void candl_options_read(int, char **, FILE **, FILE **, CandlOptions **);
2184 -
2185 +void candl_options_read(int, char **, FILE **, FILE **, FILE**, candl_options_p*);
2186  
2187  /******************************************************************************
2188   *                            Processing functions                            *
2189   ******************************************************************************/
2190 -CandlOptions * candl_options_malloc(void);
2191 -
2192 +candl_options_p candl_options_malloc(void);
2193  
2194  #if defined(__cplusplus)
2195    }
2196 diff --git a/include/candl/piplib-wrapper.h b/include/candl/piplib-wrapper.h
2197 index 27576f5..642e366 100644
2198 --- a/include/candl/piplib-wrapper.h
2199 +++ b/include/candl/piplib-wrapper.h
2200 @@ -41,23 +41,27 @@
2201  #ifndef CANDL_PIPLIB_WRAPPER_H
2202  # define CANDL_PIPLIB_WRAPPER_H
2203  
2204 -
2205 -# include <stdio.h>
2206 -# include <candl/matrix.h>
2207 -
2208 -
2209 -
2210  # if defined(__cplusplus)
2211  extern "C"
2212    {
2213  # endif
2214 -    
2215  
2216 -int 
2217 -pip_has_rational_point(PipMatrix* system,
2218 -                      PipMatrix* context,
2219 -                      int conservative);
2220 -    
2221 +struct osl_relation;
2222 +struct pipmatrix;
2223 +struct pipquast;
2224 +struct pipoptions;
2225 +struct piplist;
2226 +
2227 +struct pipmatrix*    pip_relation2matrix(struct osl_relation*);
2228 +struct osl_relation* pip_matrix2relation(struct pipmatrix*);
2229 +int                  pip_has_rational_point(struct osl_relation*,
2230 +                         struct osl_relation*, int);
2231 +struct pipquast*     pip_solve_osl(struct osl_relation*, struct osl_relation*,
2232 +                         int, struct pipoptions*);
2233 +int                  piplist_are_equal(struct piplist*, struct piplist*, int);
2234 +struct osl_relation* pip_quast_to_polyhedra(struct pipquast*, int, int);
2235 +struct osl_relation* pip_quast_no_solution_to_polyhedra(struct pipquast*,
2236 +                         int, int);
2237  
2238  # if defined(__cplusplus)
2239    }
2240 diff --git a/include/candl/piplib.h.in b/include/candl/piplib.h.in
2241 new file mode 100644
2242 index 0000000..dfaf33a
2243 --- /dev/null
2244 +++ b/include/candl/piplib.h.in
2245 @@ -0,0 +1,51 @@
2246 +
2247 +   /**------ ( ----------------------------------------------------------**
2248 +    **       )\                      CAnDL                               **
2249 +    **----- /  ) --------------------------------------------------------**
2250 +    **     ( * (                    piplib.h                             **
2251 +    **----  \#/  --------------------------------------------------------**
2252 +    **    .-"#'-.         First version: August 5th 2014                 **
2253 +    **--- |"-.-"| -------------------------------------------------------**
2254 +          |     |
2255 +          |     |
2256 + ******** |     | *************************************************************
2257 + * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
2258 + ******************************************************************************
2259 + *                                                                            *
2260 + * Copyright (C) 2003-2008 Cedric Bastoul                                     *
2261 + *                                                                            *
2262 + * This is free software; you can redistribute it and/or modify it under the  *
2263 + * terms of the GNU Lesser General Public License as published by the Free    *
2264 + * Software Foundation; either version 3 of the License, or (at your option)  *
2265 + * any later version.                                                         *
2266 + *                                                                            *
2267 + * This software is distributed in the hope that it will be useful, but       *
2268 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
2269 + * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   *
2270 + * for more details.                                                          *
2271 + *                                                                            *
2272 + * You should have received a copy of the GNU Lesser General Public License   *
2273 + * along with software; if not, write to the Free Software Foundation, Inc.,  *
2274 + * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA                     *
2275 + *                                                                            *
2276 + * CAnDL, the Chunky Dependence Analyzer                                      *
2277 + * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr                         *
2278 + *                                                                            *
2279 + ******************************************************************************/
2280 +
2281 +
2282 +#ifndef CANDL_PIPLIB_H
2283 +# define CANDL_PIPLIB_H
2284 +
2285 +# if defined(__cplusplus)
2286 +extern "C"
2287 +  {
2288 +# endif
2289 +
2290 +# include <piplib/piplib@BITS@.h>
2291 +
2292 +# if defined(__cplusplus)
2293 +  }
2294 +# endif
2295 +#endif /* define CANDL_PIPLIB_H */
2296 +
2297 diff --git a/include/candl/program.h b/include/candl/program.h
2298 deleted file mode 100644
2299 index 073016a..0000000
2300 --- a/include/candl/program.h
2301 +++ /dev/null
2302 @@ -1,113 +0,0 @@
2303 -
2304 -   /**------ ( ----------------------------------------------------------**
2305 -    **       )\                      CAnDL                               **
2306 -    **----- /  ) --------------------------------------------------------**
2307 -    **     ( * (                   program.h                             **
2308 -    **----  \#/  --------------------------------------------------------**
2309 -    **    .-"#'-.        First version: september 9th 2003               **
2310 -    **--- |"-.-"| -------------------------------------------------------**
2311 -          |     |
2312 -          |     |
2313 - ******** |     | *************************************************************
2314 - * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
2315 - ******************************************************************************
2316 - *                                                                            *
2317 - * Copyright (C) 2003-2008 Cedric Bastoul                                     *
2318 - *                                                                            *
2319 - * This is free software; you can redistribute it and/or modify it under the  *
2320 - * terms of the GNU General Public License as published by the Free Software  *
2321 - * Foundation; either version 2 of the License, or (at your option) any later *
2322 - * version.                                                                   *
2323 - *                                                                            *
2324 - * This software is distributed in the hope that it will be useful, but       *
2325 - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
2326 - * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   *
2327 - * for more details.                                                          *
2328 - *                                                                            *
2329 - * You should have received a copy of the GNU General Public License along    *
2330 - * with software; if not, write to the Free Software Foundation, Inc.,        *
2331 - * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA                     *
2332 - *                                                                            *
2333 - * CAnDL, the Chunky Dependence Analyzer                                      *
2334 - * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr                         *
2335 - *                                                                            *
2336 - ******************************************************************************/
2337 -
2338 -
2339 -#ifndef CANDL_PROGRAM_H
2340 -# define CANDL_PROGRAM_H
2341 -
2342 -# include <stdio.h>
2343 -# include <stdlib.h>
2344 -# include <candl/matrix.h>
2345 -# include <candl/statement.h>
2346 -
2347 -# ifdef CANDL_SUPPORTS_SCOPLIB
2348 -#  include <scoplib/scop.h>
2349 -# endif
2350 -
2351 -
2352 -# if defined(__cplusplus)
2353 -extern "C"
2354 -  {
2355 -# endif
2356 -
2357 -/**
2358 - * candl_program_t structure:
2359 - * this structure contains all the informations about a program.
2360 - */
2361 -struct candl_program
2362 -{
2363 -  CandlMatrix * context;            /**< The context of the program. */
2364 -  int nb_statements;                /**< The number of statements. */
2365 -  CandlStatement ** statement;      /**< Array of nb_statements pointers on
2366 -                                      *   the statements of the program.
2367 -                                      */
2368 -  CandlMatrix    ** transformation; /**< Array of nb_statements pointers on
2369 -                                      *   the transformation candidate (one
2370 -                                      *   function per statement). If NULL:
2371 -                                      *   no tranformation candidate.
2372 -                                      */
2373 -  int* scalars_privatizable;
2374 -};
2375 -typedef struct candl_program CandlProgram;
2376 -typedef struct candl_program candl_program_t;
2377 -typedef struct candl_program * candl_program_p;
2378 -
2379 -
2380 -/******************************************************************************
2381 - *                          Structure display function                        *
2382 - ******************************************************************************/
2383 -void candl_program_print_structure(FILE *, candl_program_p, int);
2384 -void candl_program_print(FILE *, candl_program_p);
2385 -void candl_program_print_candl_file(FILE *, candl_program_p);
2386 -
2387 -/******************************************************************************
2388 - *                         Memory alloc/dealloc function                      *
2389 - ******************************************************************************/
2390 -candl_program_p candl_program_malloc();
2391 -void candl_program_free(candl_program_p);
2392 -
2393 -
2394 -/******************************************************************************
2395 - *                               Reading function                             *
2396 - ******************************************************************************/
2397 -candl_program_p candl_program_read(FILE *);
2398 -/* This function is compiled if candl was configured with CLAN support. */
2399 -# ifdef CANDL_SUPPORTS_SCOPLIB
2400 -candl_program_p candl_program_read_scop(FILE *);
2401 -# endif
2402 -
2403 -/******************************************************************************
2404 - *                            Processing functions                            *
2405 - ******************************************************************************/
2406 -/* This function is compiled if candl was configured with CLAN support. */
2407 -# ifdef CANDL_SUPPORTS_SCOPLIB
2408 -candl_program_p candl_program_convert_scop(scoplib_scop_p, int**);
2409 -# endif
2410 -
2411 -# if defined(__cplusplus)
2412 -  }
2413 -# endif
2414 -#endif /* define CANDL_PROGRAM_H */
2415 -
2416 diff --git a/include/candl/pruning.h b/include/candl/pruning.h
2417 deleted file mode 100644
2418 index ad75e38..0000000
2419 --- a/include/candl/pruning.h
2420 +++ /dev/null
2421 @@ -1,65 +0,0 @@
2422 -
2423 -   /**------ ( ----------------------------------------------------------**
2424 -    **       )\                      CAnDL                               **
2425 -    **----- /  ) --------------------------------------------------------**
2426 -    **     ( * (                    pruning.h                            **
2427 -    **----  \#/  --------------------------------------------------------**
2428 -    **    .-"#'-.        First version: July 17th 2011                   **
2429 -    **--- |"-.-"| -------------------------------------------------------**
2430 -          |     |
2431 -          |     |
2432 - ******** |     | *************************************************************
2433 - * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
2434 - ******************************************************************************
2435 - *                                                                            *
2436 - * Copyright (C) 2003-2008 Cedric Bastoul                                     *
2437 - *                                                                            *
2438 - * This is free software; you can redistribute it and/or modify it under the  *
2439 - * terms of the GNU General Public License as published by the Free Software  *
2440 - * Foundation; either version 2 of the License, or (at your option) any later *
2441 - * version.                                                                   *
2442 - *                                                                            *
2443 - * This software is distributed in the hope that it will be useful, but       *
2444 - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
2445 - * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   *
2446 - * for more details.                                                          *
2447 - *                                                                            *
2448 - * You should have received a copy of the GNU General Public License along    *
2449 - * with software; if not, write to the Free Software Foundation, Inc.,        *
2450 - * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA                     *
2451 - *                                                                            *
2452 - * CAnDL, the Chunky Dependence Analyzer                                      *
2453 - * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr                         *
2454 - *                                                                            *
2455 - ******************************************************************************/
2456 -
2457 -/**
2458 - * \file pruning.h
2459 - * \author Louis-Noel Pouchet
2460 - */
2461 -
2462 -#ifndef CANDL_PRUNING_H
2463 -# define CANDL_PRUNING_H
2464 -
2465 -
2466 -# include <stdio.h>
2467 -# include <candl/statement.h>
2468 -# include <candl/matrix.h>
2469 -# include <candl/program.h>
2470 -# include <candl/options.h>
2471 -# include <candl/matrix.h>
2472 -
2473 -
2474 -# if defined(__cplusplus)
2475 -extern "C"
2476 -  {
2477 -# endif
2478 -
2479 -CandlDependence*
2480 -candl_dependence_prune_transitively_covered (CandlDependence* deps);
2481 -
2482 -# if defined(__cplusplus)
2483 -  }
2484 -# endif
2485 -#endif /* define CANDL_PRUNING_H */
2486 -
2487 diff --git a/include/candl/scop.h b/include/candl/scop.h
2488 new file mode 100644
2489 index 0000000..ead43ed
2490 --- /dev/null
2491 +++ b/include/candl/scop.h
2492 @@ -0,0 +1,66 @@
2493 +
2494 +   /**------ ( ----------------------------------------------------------**
2495 +    **       )\                      CAnDL                               **
2496 +    **----- /  ) --------------------------------------------------------**
2497 +    **     ( * (                   scop.h                                **
2498 +    **----  \#/  --------------------------------------------------------**
2499 +    **    .-"#'-.        First version: july 9th 2012                    **
2500 +    **--- |"-.-"| -------------------------------------------------------**
2501 +          |     |
2502 +          |     |
2503 + ******** |     | *************************************************************
2504 + * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
2505 + ******************************************************************************
2506 + *                                                                            *
2507 + * Copyright (C) 2003-2008 Cedric Bastoul                                     *
2508 + *                                                                            *
2509 + * This is free software; you can redistribute it and/or modify it under the  *
2510 + * terms of the GNU General Public License as published by the Free Software  *
2511 + * Foundation; either version 2 of the License, or (at your option) any later *
2512 + * version.                                                                   *
2513 + *                                                                            *
2514 + * This software is distributed in the hope that it will be useful, but       *
2515 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
2516 + * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   *
2517 + * for more details.                                                          *
2518 + *                                                                            *
2519 + * You should have received a copy of the GNU General Public License along    *
2520 + * with software; if not, write to the Free Software Foundation, Inc.,        *
2521 + * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA                     *
2522 + *                                                                            *
2523 + * CAnDL, the Chunky Dependence Analyzer                                      *
2524 + * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr                         *
2525 + *                                                                            *
2526 + ******************************************************************************/
2527 +
2528 +/*
2529 + * author Joel Poudroux
2530 + */
2531 +
2532 +#ifndef CANDL_SCOP_H
2533 +# define CANDL_SCOP_H
2534 +
2535 +# if defined(__cplusplus)
2536 +extern "C"
2537 +  {
2538 +# endif
2539 +
2540 +struct osl_scop;
2541 +
2542 +struct candl_scop_usr {
2543 +  int size;
2544 +  int *scalars_privatizable;
2545 +  void *usr_backup; /**< If there is already a usr field, it will be saved */
2546 +};
2547 +
2548 +typedef struct candl_scop_usr  candl_scop_usr_t;
2549 +typedef struct candl_scop_usr* candl_scop_usr_p;
2550 +
2551 +void candl_scop_usr_init(struct osl_scop*);
2552 +void candl_scop_usr_cleanup(struct osl_scop*);
2553 +
2554 +# if defined(__cplusplus)
2555 +  }
2556 +# endif
2557 +
2558 +#endif
2559 diff --git a/include/candl/statement.h b/include/candl/statement.h
2560 index 9e434a4..a26eff6 100644
2561 --- a/include/candl/statement.h
2562 +++ b/include/candl/statement.h
2563 @@ -4,7 +4,7 @@
2564      **----- /  ) --------------------------------------------------------**
2565      **     ( * (                   statement.h                           **
2566      **----  \#/  --------------------------------------------------------**
2567 -    **    .-"#'-.        First version: september 8th 2003               **
2568 +    **    .-"#'-.        First version: july 9th 2012                    **
2569      **--- |"-.-"| -------------------------------------------------------**
2570            |     |
2571            |     |
2572 @@ -33,68 +33,38 @@
2573   *                                                                            *
2574   ******************************************************************************/
2575  
2576 +/*
2577 + * author Joel Poudroux
2578 + */
2579  
2580  #ifndef CANDL_STATEMENT_H
2581 -# define CANDL_STATEMENT_H
2582 -
2583 -# include <stdio.h>
2584 -# include <candl/matrix.h>
2585 +#define CANDL_STATEMENT_H
2586  
2587  # if defined(__cplusplus)
2588  extern "C"
2589    {
2590  # endif
2591  
2592 +struct osl_scop;
2593 +struct osl_statement;
2594  
2595 -/**
2596 - * CandlStatement structure:
2597 - * this structure contains all the informations about a program statement.
2598 - */
2599 -struct candlstatement
2600 -{ int label;                    /**< Statement number (it must be the array
2601 -                                  *   index of this statement in the "statement"
2602 -                                  *   field of the CandlProgram structure).
2603 -                                  */
2604 -  int type;                     /**< Statement type. */
2605 -  int depth;                    /**< Nesting level (nb of surrounding loops).*/
2606 -  int * index;                  /**< Iteration domain's iterator labels. */
2607 -  CandlMatrix * domain;         /**< Iteration domain. */
2608 -  CandlMatrix * written;        /**< Array of written data. */
2609 -  CandlMatrix * read;           /**< Array of read data. */
2610 -  void* ref;                   /**< Reference to another structure
2611 -                                  describing the same statement. */
2612 +struct candl_statement_usr {
2613 +  int label; /**< Statement label = 'n'th statement */
2614 +  int depth;
2615 +  int type;
2616 +  int *index; /**< Loops label name */
2617 +  void *usr_backup; /**< If there is already a usr field, it will be saved */
2618  };
2619 -typedef struct candlstatement CandlStatement;
2620 -
2621  
2622 -/******************************************************************************
2623 - *                          Structure display function                        *
2624 - ******************************************************************************/
2625 -void candl_statement_print_structure(FILE *, CandlStatement *, int);
2626 -void candl_statement_print(FILE *, CandlStatement *);
2627 -
2628 -
2629 -/******************************************************************************
2630 - *                         Memory deallocation function                       *
2631 - ******************************************************************************/
2632 -void candl_statement_free(CandlStatement *);
2633 -
2634 -
2635 -/******************************************************************************
2636 - *                              Reading functions                             *
2637 - ******************************************************************************/
2638 -CandlStatement * candl_statement_read(FILE *, int, int);
2639 -
2640 -
2641 -/******************************************************************************
2642 - *                            Processing functions                            *
2643 - ******************************************************************************/
2644 -CandlStatement * candl_statement_malloc();
2645 -int              candl_statement_commute(CandlStatement *, CandlStatement *);
2646 +typedef struct candl_statement_usr  candl_statement_usr_t;
2647 +typedef struct candl_statement_usr* candl_statement_usr_p;
2648  
2649 +void candl_statement_usr_init_all(struct osl_scop*);
2650 +void candl_statement_usr_cleanup(struct osl_statement*);
2651  
2652  # if defined(__cplusplus)
2653    }
2654  # endif
2655 -#endif /* define CANDL_STATEMENT_H */
2656  
2657 +
2658 +#endif
2659 diff --git a/include/candl/util.h b/include/candl/util.h
2660 new file mode 100644
2661 index 0000000..c20f09b
2662 --- /dev/null
2663 +++ b/include/candl/util.h
2664 @@ -0,0 +1,61 @@
2665 +
2666 +   /**------ ( ----------------------------------------------------------**
2667 +    **       )\                      CAnDL                               **
2668 +    **----- /  ) --------------------------------------------------------**
2669 +    **     ( * (                   util.h                                **
2670 +    **----  \#/  --------------------------------------------------------**
2671 +    **    .-"#'-.        First version: june 7th 2012                    **
2672 +    **--- |"-.-"| -------------------------------------------------------**
2673 +          |     |
2674 +          |     |
2675 + ******** |     | *************************************************************
2676 + * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
2677 + ******************************************************************************
2678 + *                                                                            *
2679 + * Copyright (C) 2003-2008 Cedric Bastoul                                     *
2680 + *                                                                            *
2681 + * This is free software; you can redistribute it and/or modify it under the  *
2682 + * terms of the GNU General Public License as published by the Free Software  *
2683 + * Foundation; either version 2 of the License, or (at your option) any later *
2684 + * version.                                                                   *
2685 + *                                                                            *
2686 + * This software is distributed in the hope that it will be useful, but       *
2687 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
2688 + * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   *
2689 + * for more details.                                                          *
2690 + *                                                                            *
2691 + * You should have received a copy of the GNU General Public License along    *
2692 + * with software; if not, write to the Free Software Foundation, Inc.,        *
2693 + * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA                     *
2694 + *                                                                            *
2695 + * CAnDL, the Chunky Dependence Analyzer                                      *
2696 + * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr                         *
2697 + *                                                                            *
2698 + ******************************************************************************/
2699 +
2700 +/*
2701 + * author Joel Poudroux
2702 + */
2703 +
2704 +#ifndef CANDL_UTIL_H
2705 +#define CANDL_UTIL_H
2706 +
2707 +# if defined(__cplusplus)
2708 +extern "C"
2709 +  {
2710 +# endif
2711 +
2712 +struct osl_scop;
2713 +struct osl_relation;
2714 +struct osl_statement;
2715 +
2716 +int candl_util_relation_get_line(struct osl_relation*, int);
2717 +int candl_util_statement_commute(struct osl_statement*, struct osl_statement*);
2718 +int candl_util_check_scop(struct osl_scop*, struct osl_scop*);
2719 +int candl_util_check_scop_list(struct osl_scop*, struct osl_scop*);
2720 +
2721 +# if defined(__cplusplus)
2722 +  }
2723 +# endif
2724 +
2725 +#endif
2726 diff --git a/include/candl/violation.h b/include/candl/violation.h
2727 index da09565..f395b63 100644
2728 --- a/include/candl/violation.h
2729 +++ b/include/candl/violation.h
2730 @@ -38,52 +38,92 @@
2731  # define CANDL_VIOLATION_H
2732  
2733  # include <stdio.h>
2734 -# include <candl/dependence.h>
2735 -# include <candl/matrix.h>
2736 +# include <candl/options.h>
2737  
2738  # if defined(__cplusplus)
2739  extern "C"
2740    {
2741  # endif
2742  
2743 +struct osl_scop;
2744 +struct osl_dependence;
2745 +struct osl_relation;
2746  
2747  /**
2748   * CandlViolation structure:
2749   * this structure contains all informations about a data dependence violation.
2750 - */
2751 -struct candlviolation
2752 -{ CandlDependence * dependence; /**< Pointer to violated dependence. */
2753 -  int dimension;                /**< Violation dimension. */
2754 -  CandlMatrix * domain;         /**< Violation polyhedron. */
2755 -  struct candlviolation * next; /**< Pointer to next violation. */
2756 + *
2757
2758 +  Violation domain structure
2759 +                                     ________________________________________________________________________________________________  
2760 +                                   /       source (output) |       target (input)  |                   local dims                     \ 
2761 +                                __ |_______________________|_______________________|___________________________________________________|_____________
2762 +                              / eq |output |output |output |output |output |output |ld dom |ld acc |ld scatt |ld dom |ld acc |ld scatt |           |  \ 
2763 +                              | in |domain |access |scatt  |domain |access |scatt  |source |source |source   |target |target |target   |parameters | 1 |
2764 +         _____________________|____|_______|_______|_______|_______|_______|_______|_______|_______|_________|_______|_______|_________|___________|___|
2765 +             |Domain source   | X  |   X   :       :       |       :       :       |   X   :       :         |       :       :         |     X     | X |
2766 +             |________________|____|_______:_______:_______|_______:_______:_______|_______:_______:_________|_______:_______:_________|___________|___|
2767 +             |Domain target   | X  |       :       :       |   X   :       :       |       :       :         |   X   :       :         |     X     | X |
2768 +             |________________|____|_______:_______:_______|_______:_______:_______|_______:_______:_________|_______:_______:_________|___________|___|
2769 +  Dependence |Access source   | X  |   X   :   X   :       |       :       :       |       :   X   :         |       :       :         |     X     | X |
2770 +  system     |________________|____|_______:_______:_______|_______:_______:_______|_______:_______:_________|_______:_______:_________|___________|___| 
2771 +             |Access target   | X  |       :       :       |   X   :   X   :       |       :       :         |       :   X   :         |     X     | X |
2772 +             |________________|____|_______:_______:_______|_______:_______:_______|_______:_______:_________|_______:_______:_________|___________|___|
2773 +             |Access equality |    |       :  Id   :       |       :  -Id  :       |       :       :         |       :       :         |           |   |
2774 +             |________________|____|_______:_______:_______|_______:_______:_______|_______:_______:_________|_______:_______:_________|___________|___|    | 0    : 0..depth-1 
2775 +             |Precedence      | X  |  Id   :       :       |  -Id  :       :       |       :       :         |       :       :         |           | X | <--| 0|-1 : depth
2776 +         ===============================================================================================================================================
2777 +             |Scattering      |    |       :       :       |       :       :       |       :       :         |       :       :         |           |   |
2778 +             |source          | X  |   X   :       :   X   |       :       :       |       :       :    X    |       :       :         |     X     | X |
2779 +             |________________|____|_______:_______:_______|_______:_______:_______|_______:_______:_________|_______:_______:_________|___________|___|
2780 +             |Scattering      |    |       :       :       |       :       :       |       :       :         |       :       :         |           |   |
2781 +             |target          | X  |       :       :       |   X   :       :   X   |       :       :         |       :       :    X    |     X     | X |
2782 +             |________________|____|_______:_______:_______|_______:_______:_______|_______:_______:_________|_______:_______:_________|___________|___|
2783 +             |Equality at     |    |       :       :       |       :       :       |       :       :         |       :       :         |           |   |
2784 +             |1 ... dim_1     |    |       :       :  Id   |       :       : -Id   |       :       :         |       :       :         |           |   |
2785 +             |________________|____|_______:_______:_______|_______:_______:_______|_______:_______:_________|_______:_______:_________|___________|___|
2786 +         at  |Scat source >   |    |       :       :       |       :       :       |       :       :         |       :       :         |           |   |
2787 +         dim |Scat target     | 1  |       :       :   1   |       :       :  -1   |       :       :         |       :       :         |           |-1 |
2788 +             \________________|____|_______:_______:_______|_______:_______:_______|_______:_______:_________|_______:_______:_________|___________|___/
2789 +
2790 +                                                      (1)                     (2)                      (3)                       (4)
2791 +*/
2792 +
2793 +struct candl_violation {
2794 +  struct osl_dependence* dependence;    /**< Pointer to violated dependence. */
2795 +  int dimension;                        /**< Violation dimension. */
2796 +  struct osl_relation* domain;          /**< Violation polyhedron. */
2797 +  struct candl_violation* next;         /**< Pointer to next violation. */
2798 +  
2799 +  int source_nb_output_dims_scattering; // (1)
2800 +  int target_nb_output_dims_scattering; // (2)
2801 +  int source_nb_local_dims_scattering;  // (3)
2802 +  int target_nb_local_dims_scattering;  // (4)
2803  };
2804 -typedef struct candlviolation CandlViolation;
2805 -
2806 +typedef struct candl_violation  candl_violation_t;
2807 +typedef struct candl_violation* candl_violation_p;
2808  
2809  /******************************************************************************
2810   *                          Structure display function                        *
2811   ******************************************************************************/
2812 -void candl_violation_print_structure(FILE *, CandlViolation *, int);
2813 -void candl_violation_print(FILE *, CandlViolation *);
2814 -void candl_violation_pprint(FILE *, CandlViolation *);
2815 -void candl_violation_view(CandlViolation *);
2816 -
2817 +void              candl_violation_idump(FILE*, candl_violation_p, int);
2818 +void              candl_violation_dump(FILE*, candl_violation_p);
2819 +void              candl_violation_pprint(FILE*, candl_violation_p);
2820 +void              candl_violation_view(candl_violation_p);
2821  
2822  /******************************************************************************
2823   *                         Memory deallocation function                       *
2824   ******************************************************************************/
2825 -void candl_violation_free(CandlViolation *);
2826 -
2827 +void              candl_violation_free(candl_violation_p);
2828  
2829  /******************************************************************************
2830   *                             Processing functions                           *
2831   ******************************************************************************/
2832 -CandlViolation * candl_violation_malloc();
2833 -void             candl_violation_add(CandlViolation **, CandlViolation **,
2834 -                                     CandlViolation *);
2835 -CandlViolation * candl_violation(CandlProgram *, CandlDependence *,
2836 -                                 CandlOptions *);
2837 -
2838 +candl_violation_p candl_violation_malloc();
2839 +void              candl_violation_add(candl_violation_p*, candl_violation_p*,
2840 +                                  candl_violation_p);
2841 +candl_violation_p candl_violation(struct osl_scop*, struct osl_dependence*,
2842 +                                  struct osl_scop*, candl_options_p);
2843  
2844  # if defined(__cplusplus)
2845    }
2846 diff --git a/m4/ax_cc_maxopt.m4 b/m4/ax_cc_maxopt.m4
2847 new file mode 100644
2848 index 0000000..da415be
2849 --- /dev/null
2850 +++ b/m4/ax_cc_maxopt.m4
2851 @@ -0,0 +1,178 @@
2852 +# ===========================================================================
2853 +#          http://www.nongnu.org/autoconf-archive/ax_cc_maxopt.html
2854 +# ===========================================================================
2855 +#
2856 +# SYNOPSIS
2857 +#
2858 +#   AX_CC_MAXOPT
2859 +#
2860 +# DESCRIPTION
2861 +#
2862 +#   Try to turn on "good" C optimization flags for various compilers and
2863 +#   architectures, for some definition of "good". (In our case, good for
2864 +#   FFTW and hopefully for other scientific codes. Modify as needed.)
2865 +#
2866 +#   The user can override the flags by setting the CFLAGS environment
2867 +#   variable. The user can also specify --enable-portable-binary in order to
2868 +#   disable any optimization flags that might result in a binary that only
2869 +#   runs on the host architecture.
2870 +#
2871 +#   Note also that the flags assume that ANSI C aliasing rules are followed
2872 +#   by the code (e.g. for gcc's -fstrict-aliasing), and that floating-point
2873 +#   computations can be re-ordered as needed.
2874 +#
2875 +#   Requires macros: AX_CHECK_COMPILER_FLAGS, AX_COMPILER_VENDOR,
2876 +#   AX_GCC_ARCHFLAG, AX_GCC_X86_CPUID.
2877 +#
2878 +# LICENSE
2879 +#
2880 +#   Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
2881 +#   Copyright (c) 2008 Matteo Frigo
2882 +#
2883 +#   This program is free software: you can redistribute it and/or modify it
2884 +#   under the terms of the GNU General Public License as published by the
2885 +#   Free Software Foundation, either version 3 of the License, or (at your
2886 +#   option) any later version.
2887 +#
2888 +#   This program is distributed in the hope that it will be useful, but
2889 +#   WITHOUT ANY WARRANTY; without even the implied warranty of
2890 +#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
2891 +#   Public License for more details.
2892 +#
2893 +#   You should have received a copy of the GNU General Public License along
2894 +#   with this program. If not, see <http://www.gnu.org/licenses/>.
2895 +#
2896 +#   As a special exception, the respective Autoconf Macro's copyright owner
2897 +#   gives unlimited permission to copy, distribute and modify the configure
2898 +#   scripts that are the output of Autoconf when processing the Macro. You
2899 +#   need not follow the terms of the GNU General Public License when using
2900 +#   or distributing such scripts, even though portions of the text of the
2901 +#   Macro appear in them. The GNU General Public License (GPL) does govern
2902 +#   all other use of the material that constitutes the Autoconf Macro.
2903 +#
2904 +#   This special exception to the GPL applies to versions of the Autoconf
2905 +#   Macro released by the Autoconf Archive. When you make and distribute a
2906 +#   modified version of the Autoconf Macro, you may extend this special
2907 +#   exception to the GPL to apply to your modified version as well.
2908 +
2909 +AC_DEFUN([AX_CC_MAXOPT],
2910 +[
2911 +AC_REQUIRE([AC_PROG_CC])
2912 +AC_REQUIRE([AX_COMPILER_VENDOR])
2913 +AC_REQUIRE([AC_CANONICAL_HOST])
2914 +
2915 +AC_ARG_ENABLE(portable-binary, [AC_HELP_STRING([--enable-portable-binary], [disable compiler optimizations that would produce unportable binaries])],
2916 +       acx_maxopt_portable=$withval, acx_maxopt_portable=no)
2917 +
2918 +# Try to determine "good" native compiler flags if none specified via CFLAGS
2919 +if test "$ac_test_CFLAGS" != "set"; then
2920 +  CFLAGS=""
2921 +  case $ax_cv_c_compiler_vendor in
2922 +    dec) CFLAGS="-newc -w0 -O5 -ansi_alias -ansi_args -fp_reorder -tune host"
2923 +        if test "x$acx_maxopt_portable" = xno; then
2924 +           CFLAGS="$CFLAGS -arch host"
2925 +         fi;;
2926 +
2927 +    sun) CFLAGS="-native -fast -xO5 -dalign"
2928 +        if test "x$acx_maxopt_portable" = xyes; then
2929 +          CFLAGS="$CFLAGS -xarch=generic"
2930 +         fi;;
2931 +
2932 +    hp)  CFLAGS="+Oall +Optrs_ansi +DSnative"
2933 +        if test "x$acx_maxopt_portable" = xyes; then
2934 +          CFLAGS="$CFLAGS +DAportable"
2935 +        fi;;
2936 +
2937 +    ibm) if test "x$acx_maxopt_portable" = xno; then
2938 +           xlc_opt="-qarch=auto -qtune=auto"
2939 +        else
2940 +           xlc_opt="-qtune=auto"
2941 +        fi
2942 +         AX_CHECK_COMPILER_FLAGS($xlc_opt,
2943 +               CFLAGS="-O3 -qansialias -w $xlc_opt",
2944 +               [CFLAGS="-O3 -qansialias -w"
2945 +                echo "******************************************************"
2946 +                echo "*  You seem to have the IBM  C compiler.  It is      *"
2947 +                echo "*  recommended for best performance that you use:    *"
2948 +                echo "*                                                    *"
2949 +                echo "*    CFLAGS=-O3 -qarch=xxx -qtune=xxx -qansialias -w *"
2950 +                echo "*                      ^^^        ^^^                *"
2951 +                echo "*  where xxx is pwr2, pwr3, 604, or whatever kind of *"
2952 +                echo "*  CPU you have.  (Set the CFLAGS environment var.   *"
2953 +                echo "*  and re-run configure.)  For more info, man cc.    *"
2954 +                echo "******************************************************"])
2955 +         ;;
2956 +
2957 +    intel) CFLAGS="-O3 -ansi_alias"
2958 +       if test "x$acx_maxopt_portable" = xno; then
2959 +         icc_archflag=unknown
2960 +         icc_flags=""
2961 +         case $host_cpu in
2962 +           i686*|x86_64*)
2963 +              # icc accepts gcc assembly syntax, so these should work:
2964 +             AX_GCC_X86_CPUID(0)
2965 +              AX_GCC_X86_CPUID(1)
2966 +             case $ax_cv_gcc_x86_cpuid_0 in # see AX_GCC_ARCHFLAG
2967 +                *:756e6547:*:*) # Intel
2968 +                  case $ax_cv_gcc_x86_cpuid_1 in
2969 +                    *6a?:*[[234]]:*:*|*6[[789b]]?:*:*:*) icc_flags="-xK";;
2970 +                    *f3[[347]]:*:*:*|*f4[1347]:*:*:*) icc_flags="-xP -xN -xW -xK";;
2971 +                    *f??:*:*:*) icc_flags="-xN -xW -xK";;
2972 +                  esac ;;
2973 +              esac ;;
2974 +          esac
2975 +          if test "x$icc_flags" != x; then
2976 +            for flag in $icc_flags; do
2977 +              AX_CHECK_COMPILER_FLAGS($flag, [icc_archflag=$flag; break])
2978 +            done
2979 +          fi
2980 +          AC_MSG_CHECKING([for icc architecture flag])
2981 +         AC_MSG_RESULT($icc_archflag)
2982 +          if test "x$icc_archflag" != xunknown; then
2983 +            CFLAGS="$CFLAGS $icc_archflag"
2984 +          fi
2985 +        fi
2986 +       ;;
2987 +
2988 +    gnu)
2989 +     # default optimization flags for gcc on all systems
2990 +     CFLAGS="-O3 -fomit-frame-pointer"
2991 +
2992 +     # -malign-double for x86 systems
2993 +     AX_CHECK_COMPILER_FLAGS(-malign-double, CFLAGS="$CFLAGS -malign-double")
2994 +
2995 +     #  -fstrict-aliasing for gcc-2.95+
2996 +     AX_CHECK_COMPILER_FLAGS(-fstrict-aliasing,
2997 +       CFLAGS="$CFLAGS -fstrict-aliasing")
2998 +
2999 +     # note that we enable "unsafe" fp optimization with other compilers, too
3000 +     AX_CHECK_COMPILER_FLAGS(-ffast-math, CFLAGS="$CFLAGS -ffast-math")
3001 +
3002 +     AX_GCC_ARCHFLAG($acx_maxopt_portable)
3003 +     ;;
3004 +  esac
3005 +
3006 +  if test -z "$CFLAGS"; then
3007 +       echo ""
3008 +       echo "********************************************************"
3009 +        echo "* WARNING: Don't know the best CFLAGS for this system  *"
3010 +        echo "* Use ./configure CFLAGS=... to specify your own flags *"
3011 +       echo "* (otherwise, a default of CFLAGS=-O3 will be used)    *"
3012 +       echo "********************************************************"
3013 +       echo ""
3014 +        CFLAGS="-O3"
3015 +  fi
3016 +
3017 +  AX_CHECK_COMPILER_FLAGS($CFLAGS, [], [
3018 +       echo ""
3019 +        echo "********************************************************"
3020 +        echo "* WARNING: The guessed CFLAGS don't seem to work with  *"
3021 +        echo "* your compiler.                                       *"
3022 +        echo "* Use ./configure CFLAGS=... to specify your own flags *"
3023 +        echo "********************************************************"
3024 +        echo ""
3025 +        CFLAGS=""
3026 +  ])
3027 +
3028 +fi
3029 +])
3030 diff --git a/m4/ax_cflags_warn_all.m4 b/m4/ax_cflags_warn_all.m4
3031 new file mode 100644
3032 index 0000000..026c6e9
3033 --- /dev/null
3034 +++ b/m4/ax_cflags_warn_all.m4
3035 @@ -0,0 +1,149 @@
3036 +# ===========================================================================
3037 +#       http://www.nongnu.org/autoconf-archive/ax_cflags_warn_all.html
3038 +# ===========================================================================
3039 +#
3040 +# SYNOPSIS
3041 +#
3042 +#   AX_CFLAGS_WARN_ALL [(shellvar [,default, [A/NA]])]
3043 +#
3044 +# DESCRIPTION
3045 +#
3046 +#   Try to find a compiler option that enables most reasonable warnings.
3047 +#
3048 +#   For the GNU CC compiler it will be -Wall (and -ansi -pedantic) The
3049 +#   result is added to the shellvar being CFLAGS by default.
3050 +#
3051 +#   Currently this macro knows about GCC, Solaris C compiler, Digital Unix C
3052 +#   compiler, C for AIX Compiler, HP-UX C compiler, IRIX C compiler, NEC
3053 +#   SX-5 (Super-UX 10) C compiler, and Cray J90 (Unicos 10.0.0.8) C
3054 +#   compiler.
3055 +#
3056 +#    - $1 shell-variable-to-add-to : CFLAGS
3057 +#    - $2 add-value-if-not-found : nothing
3058 +#    - $3 action-if-found : add value to shellvariable
3059 +#    - $4 action-if-not-found : nothing
3060 +#
3061 +# LICENSE
3062 +#
3063 +#   Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
3064 +#
3065 +#   This program is free software; you can redistribute it and/or modify it
3066 +#   under the terms of the GNU General Public License as published by the
3067 +#   Free Software Foundation; either version 2 of the License, or (at your
3068 +#   option) any later version.
3069 +#
3070 +#   This program is distributed in the hope that it will be useful, but
3071 +#   WITHOUT ANY WARRANTY; without even the implied warranty of
3072 +#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
3073 +#   Public License for more details.
3074 +#
3075 +#   You should have received a copy of the GNU General Public License along
3076 +#   with this program. If not, see <http://www.gnu.org/licenses/>.
3077 +#
3078 +#   As a special exception, the respective Autoconf Macro's copyright owner
3079 +#   gives unlimited permission to copy, distribute and modify the configure
3080 +#   scripts that are the output of Autoconf when processing the Macro. You
3081 +#   need not follow the terms of the GNU General Public License when using
3082 +#   or distributing such scripts, even though portions of the text of the
3083 +#   Macro appear in them. The GNU General Public License (GPL) does govern
3084 +#   all other use of the material that constitutes the Autoconf Macro.
3085 +#
3086 +#   This special exception to the GPL applies to versions of the Autoconf
3087 +#   Macro released by the Autoconf Archive. When you make and distribute a
3088 +#   modified version of the Autoconf Macro, you may extend this special
3089 +#   exception to the GPL to apply to your modified version as well.
3090 +
3091 +AC_DEFUN([AX_CFLAGS_WARN_ALL],[dnl
3092 +AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
3093 +AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_warn_all])dnl
3094 +AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum warnings],
3095 +VAR,[VAR="no, unknown"
3096 + AC_LANG_SAVE
3097 + AC_LANG_C
3098 + ac_save_[]FLAGS="$[]FLAGS"
3099 +for ac_arg dnl
3100 +in "-pedantic  % -Wall"       dnl   GCC
3101 +   "-xstrconst % -v"          dnl Solaris C
3102 +   "-std1      % -verbose -w0 -warnprotos" dnl Digital Unix
3103 +   "-qlanglvl=ansi % -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" dnl AIX
3104 +   "-ansi -ansiE % -fullwarn" dnl IRIX
3105 +   "+ESlit     % +w1"         dnl HP-UX C
3106 +   "-Xc        % -pvctl[,]fullmsg" dnl NEC SX-5 (Super-UX 10)
3107 +   "-h conform % -h msglevel 2" dnl Cray C (Unicos)
3108 +   #
3109 +do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
3110 +   AC_TRY_COMPILE([],[return 0;],
3111 +   [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
3112 +done
3113 + FLAGS="$ac_save_[]FLAGS"
3114 + AC_LANG_RESTORE
3115 +])
3116 +case ".$VAR" in
3117 +     .ok|.ok,*) m4_ifvaln($3,$3) ;;
3118 +   .|.no|.no,*) m4_ifvaln($4,$4,[m4_ifval($2,[
3119 +        AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])
3120 +                      m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])]) ;;
3121 +   *) m4_ifvaln($3,$3,[
3122 +   if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
3123 +   then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
3124 +   else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
3125 +                      m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
3126 +   fi ]) ;;
3127 +esac
3128 +AS_VAR_POPDEF([VAR])dnl
3129 +AS_VAR_POPDEF([FLAGS])dnl
3130 +])
3131 +
3132 +dnl the only difference - the LANG selection... and the default FLAGS
3133 +
3134 +AC_DEFUN([AX_CXXFLAGS_WARN_ALL],[dnl
3135 +AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
3136 +AS_VAR_PUSHDEF([VAR],[ax_cv_cxxflags_warn_all])dnl
3137 +AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum warnings],
3138 +VAR,[VAR="no, unknown"
3139 + AC_LANG_SAVE
3140 + AC_LANG_CPLUSPLUS
3141 + ac_save_[]FLAGS="$[]FLAGS"
3142 +for ac_arg dnl
3143 +in "-pedantic  % -Wall"       dnl   GCC
3144 +   "-xstrconst % -v"          dnl Solaris C
3145 +   "-std1      % -verbose -w0 -warnprotos" dnl Digital Unix
3146 +   "-qlanglvl=ansi % -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" dnl AIX
3147 +   "-ansi -ansiE % -fullwarn" dnl IRIX
3148 +   "+ESlit     % +w1"         dnl HP-UX C
3149 +   "-Xc        % -pvctl[,]fullmsg" dnl NEC SX-5 (Super-UX 10)
3150 +   "-h conform % -h msglevel 2" dnl Cray C (Unicos)
3151 +   #
3152 +do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
3153 +   AC_TRY_COMPILE([],[return 0;],
3154 +   [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
3155 +done
3156 + FLAGS="$ac_save_[]FLAGS"
3157 + AC_LANG_RESTORE
3158 +])
3159 +case ".$VAR" in
3160 +     .ok|.ok,*) m4_ifvaln($3,$3) ;;
3161 +   .|.no|.no,*) m4_ifvaln($4,$4,[m4_ifval($2,[
3162 +        AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])
3163 +                      m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])]) ;;
3164 +   *) m4_ifvaln($3,$3,[
3165 +   if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
3166 +   then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
3167 +   else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
3168 +                      m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
3169 +   fi ]) ;;
3170 +esac
3171 +AS_VAR_POPDEF([VAR])dnl
3172 +AS_VAR_POPDEF([FLAGS])dnl
3173 +])
3174 +
3175 +dnl  implementation tactics:
3176 +dnl   the for-argument contains a list of options. The first part of
3177 +dnl   these does only exist to detect the compiler - usually it is
3178 +dnl   a global option to enable -ansi or -extrawarnings. All other
3179 +dnl   compilers will fail about it. That was needed since a lot of
3180 +dnl   compilers will give false positives for some option-syntax
3181 +dnl   like -Woption or -Xoption as they think of it is a pass-through
3182 +dnl   to later compile stages or something. The "%" is used as a
3183 +dnl   delimimiter. A non-option comment can be given after "%%" marks
3184 +dnl   which will be shown but not added to the respective C/CXXFLAGS.
3185 diff --git a/m4/ax_check_compiler_flags.m4 b/m4/ax_check_compiler_flags.m4
3186 new file mode 100644
3187 index 0000000..7da8324
3188 --- /dev/null
3189 +++ b/m4/ax_check_compiler_flags.m4
3190 @@ -0,0 +1,74 @@
3191 +# ===========================================================================
3192 +#     http://www.nongnu.org/autoconf-archive/ax_check_compiler_flags.html
3193 +# ===========================================================================
3194 +#
3195 +# SYNOPSIS
3196 +#
3197 +#   AX_CHECK_COMPILER_FLAGS(FLAGS, [ACTION-SUCCESS], [ACTION-FAILURE])
3198 +#
3199 +# DESCRIPTION
3200 +#
3201 +#   Check whether the given compiler FLAGS work with the current language's
3202 +#   compiler, or whether they give an error. (Warnings, however, are
3203 +#   ignored.)
3204 +#
3205 +#   ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
3206 +#   success/failure.
3207 +#
3208 +# LICENSE
3209 +#
3210 +#   Copyright (c) 2009 Steven G. Johnson <stevenj@alum.mit.edu>
3211 +#   Copyright (c) 2009 Matteo Frigo
3212 +#
3213 +#   This program is free software: you can redistribute it and/or modify it
3214 +#   under the terms of the GNU General Public License as published by the
3215 +#   Free Software Foundation, either version 3 of the License, or (at your
3216 +#   option) any later version.
3217 +#
3218 +#   This program is distributed in the hope that it will be useful, but
3219 +#   WITHOUT ANY WARRANTY; without even the implied warranty of
3220 +#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
3221 +#   Public License for more details.
3222 +#
3223 +#   You should have received a copy of the GNU General Public License along
3224 +#   with this program. If not, see <http://www.gnu.org/licenses/>.
3225 +#
3226 +#   As a special exception, the respective Autoconf Macro's copyright owner
3227 +#   gives unlimited permission to copy, distribute and modify the configure
3228 +#   scripts that are the output of Autoconf when processing the Macro. You
3229 +#   need not follow the terms of the GNU General Public License when using
3230 +#   or distributing such scripts, even though portions of the text of the
3231 +#   Macro appear in them. The GNU General Public License (GPL) does govern
3232 +#   all other use of the material that constitutes the Autoconf Macro.
3233 +#
3234 +#   This special exception to the GPL applies to versions of the Autoconf
3235 +#   Macro released by the Autoconf Archive. When you make and distribute a
3236 +#   modified version of the Autoconf Macro, you may extend this special
3237 +#   exception to the GPL to apply to your modified version as well.
3238 +
3239 +AC_DEFUN([AX_CHECK_COMPILER_FLAGS],
3240 +[AC_PREREQ(2.59) dnl for _AC_LANG_PREFIX
3241 +AC_MSG_CHECKING([whether _AC_LANG compiler accepts $1])
3242 +dnl Some hackery here since AC_CACHE_VAL can't handle a non-literal varname:
3243 +AS_LITERAL_IF([$1],
3244 +  [AC_CACHE_VAL(AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_[$1]), [
3245 +      ax_save_FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
3246 +      _AC_LANG_PREFIX[]FLAGS="$1"
3247 +      AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
3248 +        AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_[$1])=yes,
3249 +        AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_[$1])=no)
3250 +      _AC_LANG_PREFIX[]FLAGS=$ax_save_FLAGS])],
3251 +  [ax_save_FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
3252 +   _AC_LANG_PREFIX[]FLAGS="$1"
3253 +   AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
3254 +     eval AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_[$1])=yes,
3255 +     eval AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_[$1])=no)
3256 +   _AC_LANG_PREFIX[]FLAGS=$ax_save_FLAGS])
3257 +eval ax_check_compiler_flags=$AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_[$1])
3258 +AC_MSG_RESULT($ax_check_compiler_flags)
3259 +if test "x$ax_check_compiler_flags" = xyes; then
3260 +       m4_default([$2], :)
3261 +else
3262 +       m4_default([$3], :)
3263 +fi
3264 +])dnl AX_CHECK_COMPILER_FLAGS
3265 diff --git a/m4/ax_compiler_vendor.m4 b/m4/ax_compiler_vendor.m4
3266 new file mode 100644
3267 index 0000000..b074260
3268 --- /dev/null
3269 +++ b/m4/ax_compiler_vendor.m4
3270 @@ -0,0 +1,61 @@
3271 +# ===========================================================================
3272 +#       http://www.nongnu.org/autoconf-archive/ax_compiler_vendor.html
3273 +# ===========================================================================
3274 +#
3275 +# SYNOPSIS
3276 +#
3277 +#   AX_COMPILER_VENDOR
3278 +#
3279 +# DESCRIPTION
3280 +#
3281 +#   Determine the vendor of the C/C++ compiler, e.g., gnu, intel, ibm, sun,
3282 +#   hp, borland, comeau, dec, cray, kai, lcc, metrowerks, sgi, microsoft,
3283 +#   watcom, etc. The vendor is returned in the cache variable
3284 +#   $ax_cv_c_compiler_vendor for C and $ax_cv_cxx_compiler_vendor for C++.
3285 +#
3286 +# LICENSE
3287 +#
3288 +#   Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
3289 +#   Copyright (c) 2008 Matteo Frigo
3290 +#
3291 +#   This program is free software: you can redistribute it and/or modify it
3292 +#   under the terms of the GNU General Public License as published by the
3293 +#   Free Software Foundation, either version 3 of the License, or (at your
3294 +#   option) any later version.
3295 +#
3296 +#   This program is distributed in the hope that it will be useful, but
3297 +#   WITHOUT ANY WARRANTY; without even the implied warranty of
3298 +#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
3299 +#   Public License for more details.
3300 +#
3301 +#   You should have received a copy of the GNU General Public License along
3302 +#   with this program. If not, see <http://www.gnu.org/licenses/>.
3303 +#
3304 +#   As a special exception, the respective Autoconf Macro's copyright owner
3305 +#   gives unlimited permission to copy, distribute and modify the configure
3306 +#   scripts that are the output of Autoconf when processing the Macro. You
3307 +#   need not follow the terms of the GNU General Public License when using
3308 +#   or distributing such scripts, even though portions of the text of the
3309 +#   Macro appear in them. The GNU General Public License (GPL) does govern
3310 +#   all other use of the material that constitutes the Autoconf Macro.
3311 +#
3312 +#   This special exception to the GPL applies to versions of the Autoconf
3313 +#   Macro released by the Autoconf Archive. When you make and distribute a
3314 +#   modified version of the Autoconf Macro, you may extend this special
3315 +#   exception to the GPL to apply to your modified version as well.
3316 +
3317 +AC_DEFUN([AX_COMPILER_VENDOR],
3318 +[
3319 +AC_CACHE_CHECK([for _AC_LANG compiler vendor], ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor,
3320 + [ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor=unknown
3321 +  # note: don't check for gcc first since some other compilers define __GNUC__
3322 +  for ventest in intel:__ICC,__ECC,__INTEL_COMPILER ibm:__xlc__,__xlC__,__IBMC__,__IBMCPP__ pathscale:__PATHCC__,__PATHSCALE__ gnu:__GNUC__ sun:__SUNPRO_C,__SUNPRO_CC hp:__HP_cc,__HP_aCC dec:__DECC,__DECCXX,__DECC_VER,__DECCXX_VER borland:__BORLANDC__,__TURBOC__ comeau:__COMO__ cray:_CRAYC kai:__KCC lcc:__LCC__ metrowerks:__MWERKS__ sgi:__sgi,sgi microsoft:_MSC_VER watcom:__WATCOMC__ portland:__PGI; do
3323 +    vencpp="defined("`echo $ventest | cut -d: -f2 | sed 's/,/) || defined(/g'`")"
3324 +    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[
3325 +#if !($vencpp)
3326 +      thisisanerror;
3327 +#endif
3328 +])], [ax_cv_]_AC_LANG_ABBREV[_compiler_vendor=`echo $ventest | cut -d: -f1`; break])
3329 +  done
3330 + ])
3331 +])
3332 diff --git a/m4/ax_gcc_archflag.m4 b/m4/ax_gcc_archflag.m4
3333 new file mode 100644
3334 index 0000000..dedeef4
3335 --- /dev/null
3336 +++ b/m4/ax_gcc_archflag.m4
3337 @@ -0,0 +1,213 @@
3338 +# ===========================================================================
3339 +#         http://www.nongnu.org/autoconf-archive/ax_gcc_archflag.html
3340 +# ===========================================================================
3341 +#
3342 +# SYNOPSIS
3343 +#
3344 +#   AX_GCC_ARCHFLAG([PORTABLE?], [ACTION-SUCCESS], [ACTION-FAILURE])
3345 +#
3346 +# DESCRIPTION
3347 +#
3348 +#   This macro tries to guess the "native" arch corresponding to the target
3349 +#   architecture for use with gcc's -march=arch or -mtune=arch flags. If
3350 +#   found, the cache variable $ax_cv_gcc_archflag is set to this flag and
3351 +#   ACTION-SUCCESS is executed; otherwise $ax_cv_gcc_archflag is is set to
3352 +#   "unknown" and ACTION-FAILURE is executed. The default ACTION-SUCCESS is
3353 +#   to add $ax_cv_gcc_archflag to the end of $CFLAGS.
3354 +#
3355 +#   PORTABLE? should be either [yes] (default) or [no]. In the former case,
3356 +#   the flag is set to -mtune (or equivalent) so that the architecture is
3357 +#   only used for tuning, but the instruction set used is still portable. In
3358 +#   the latter case, the flag is set to -march (or equivalent) so that
3359 +#   architecture-specific instructions are enabled.
3360 +#
3361 +#   The user can specify --with-gcc-arch=<arch> in order to override the
3362 +#   macro's choice of architecture, or --without-gcc-arch to disable this.
3363 +#
3364 +#   When cross-compiling, or if $CC is not gcc, then ACTION-FAILURE is
3365 +#   called unless the user specified --with-gcc-arch manually.
3366 +#
3367 +#   Requires macros: AX_CHECK_COMPILER_FLAGS, AX_GCC_X86_CPUID
3368 +#
3369 +#   (The main emphasis here is on recent CPUs, on the principle that doing
3370 +#   high-performance computing on old hardware is uncommon.)
3371 +#
3372 +# LICENSE
3373 +#
3374 +#   Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
3375 +#   Copyright (c) 2008 Matteo Frigo
3376 +#
3377 +#   This program is free software: you can redistribute it and/or modify it
3378 +#   under the terms of the GNU General Public License as published by the
3379 +#   Free Software Foundation, either version 3 of the License, or (at your
3380 +#   option) any later version.
3381 +#
3382 +#   This program is distributed in the hope that it will be useful, but
3383 +#   WITHOUT ANY WARRANTY; without even the implied warranty of
3384 +#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
3385 +#   Public License for more details.
3386 +#
3387 +#   You should have received a copy of the GNU General Public License along
3388 +#   with this program. If not, see <http://www.gnu.org/licenses/>.
3389 +#
3390 +#   As a special exception, the respective Autoconf Macro's copyright owner
3391 +#   gives unlimited permission to copy, distribute and modify the configure
3392 +#   scripts that are the output of Autoconf when processing the Macro. You
3393 +#   need not follow the terms of the GNU General Public License when using
3394 +#   or distributing such scripts, even though portions of the text of the
3395 +#   Macro appear in them. The GNU General Public License (GPL) does govern
3396 +#   all other use of the material that constitutes the Autoconf Macro.
3397 +#
3398 +#   This special exception to the GPL applies to versions of the Autoconf
3399 +#   Macro released by the Autoconf Archive. When you make and distribute a
3400 +#   modified version of the Autoconf Macro, you may extend this special
3401 +#   exception to the GPL to apply to your modified version as well.
3402 +
3403 +AC_DEFUN([AX_GCC_ARCHFLAG],
3404 +[AC_REQUIRE([AC_PROG_CC])
3405 +AC_REQUIRE([AC_CANONICAL_HOST])
3406 +
3407 +AC_ARG_WITH(gcc-arch, [AC_HELP_STRING([--with-gcc-arch=<arch>], [use architecture <arch> for gcc -march/-mtune, instead of guessing])],
3408 +       ax_gcc_arch=$withval, ax_gcc_arch=yes)
3409 +
3410 +AC_MSG_CHECKING([for gcc architecture flag])
3411 +AC_MSG_RESULT([])
3412 +AC_CACHE_VAL(ax_cv_gcc_archflag,
3413 +[
3414 +ax_cv_gcc_archflag="unknown"
3415 +
3416 +if test "$GCC" = yes; then
3417 +
3418 +if test "x$ax_gcc_arch" = xyes; then
3419 +ax_gcc_arch=""
3420 +if test "$cross_compiling" = no; then
3421 +case $host_cpu in
3422 +  i[[3456]]86*|x86_64*) # use cpuid codes, in part from x86info-1.7 by D. Jones
3423 +     AX_GCC_X86_CPUID(0)
3424 +     AX_GCC_X86_CPUID(1)
3425 +     case $ax_cv_gcc_x86_cpuid_0 in
3426 +       *:756e6547:*:*) # Intel
3427 +          case $ax_cv_gcc_x86_cpuid_1 in
3428 +           *5[[48]]?:*:*:*) ax_gcc_arch="pentium-mmx pentium" ;;
3429 +           *5??:*:*:*) ax_gcc_arch=pentium ;;
3430 +           *6[[3456]]?:*:*:*) ax_gcc_arch="pentium2 pentiumpro" ;;
3431 +           *6a?:*[[01]]:*:*) ax_gcc_arch="pentium2 pentiumpro" ;;
3432 +           *6a?:*[[234]]:*:*) ax_gcc_arch="pentium3 pentiumpro" ;;
3433 +           *6[[9d]]?:*:*:*) ax_gcc_arch="pentium-m pentium3 pentiumpro" ;;
3434 +           *6[[78b]]?:*:*:*) ax_gcc_arch="pentium3 pentiumpro" ;;
3435 +           *6??:*:*:*) ax_gcc_arch=pentiumpro ;;
3436 +            *f3[[347]]:*:*:*|*f4[1347]:*:*:*)
3437 +               case $host_cpu in
3438 +                  x86_64*) ax_gcc_arch="nocona pentium4 pentiumpro" ;;
3439 +                  *) ax_gcc_arch="prescott pentium4 pentiumpro" ;;
3440 +                esac ;;
3441 +            *f??:*:*:*) ax_gcc_arch="pentium4 pentiumpro";;
3442 +          esac ;;
3443 +       *:68747541:*:*) # AMD
3444 +          case $ax_cv_gcc_x86_cpuid_1 in
3445 +           *5[[67]]?:*:*:*) ax_gcc_arch=k6 ;;
3446 +           *5[[8d]]?:*:*:*) ax_gcc_arch="k6-2 k6" ;;
3447 +           *5[[9]]?:*:*:*) ax_gcc_arch="k6-3 k6" ;;
3448 +           *60?:*:*:*) ax_gcc_arch=k7 ;;
3449 +           *6[[12]]?:*:*:*) ax_gcc_arch="athlon k7" ;;
3450 +           *6[[34]]?:*:*:*) ax_gcc_arch="athlon-tbird k7" ;;
3451 +           *67?:*:*:*) ax_gcc_arch="athlon-4 athlon k7" ;;
3452 +           *6[[68a]]?:*:*:*)
3453 +              AX_GCC_X86_CPUID(0x80000006) # L2 cache size
3454 +              case $ax_cv_gcc_x86_cpuid_0x80000006 in
3455 +                 *:*:*[[1-9a-f]]??????:*) # (L2 = ecx >> 16) >= 256
3456 +                       ax_gcc_arch="athlon-xp athlon-4 athlon k7" ;;
3457 +                 *) ax_gcc_arch="athlon-4 athlon k7" ;;
3458 +              esac ;;
3459 +           *f[[4cef8b]]?:*:*:*) ax_gcc_arch="athlon64 k8" ;;
3460 +           *f5?:*:*:*) ax_gcc_arch="opteron k8" ;;
3461 +           *f7?:*:*:*) ax_gcc_arch="athlon-fx opteron k8" ;;
3462 +           *f??:*:*:*) ax_gcc_arch="k8" ;;
3463 +          esac ;;
3464 +       *:746e6543:*:*) # IDT
3465 +          case $ax_cv_gcc_x86_cpuid_1 in
3466 +            *54?:*:*:*) ax_gcc_arch=winchip-c6 ;;
3467 +            *58?:*:*:*) ax_gcc_arch=winchip2 ;;
3468 +            *6[[78]]?:*:*:*) ax_gcc_arch=c3 ;;
3469 +            *69?:*:*:*) ax_gcc_arch="c3-2 c3" ;;
3470 +          esac ;;
3471 +     esac
3472 +     if test x"$ax_gcc_arch" = x; then # fallback
3473 +       case $host_cpu in
3474 +         i586*) ax_gcc_arch=pentium ;;
3475 +         i686*) ax_gcc_arch=pentiumpro ;;
3476 +        esac
3477 +     fi
3478 +     ;;
3479 +
3480 +  sparc*)
3481 +     AC_PATH_PROG([PRTDIAG], [prtdiag], [prtdiag], [$PATH:/usr/platform/`uname -i`/sbin/:/usr/platform/`uname -m`/sbin/])
3482 +     cputype=`(((grep cpu /proc/cpuinfo | cut -d: -f2) ; ($PRTDIAG -v |grep -i sparc) ; grep -i cpu /var/run/dmesg.boot ) | head -n 1) 2> /dev/null`
3483 +     cputype=`echo "$cputype" | tr -d ' -' |tr $as_cr_LETTERS $as_cr_letters`
3484 +     case $cputype in
3485 +         *ultrasparciv*) ax_gcc_arch="ultrasparc4 ultrasparc3 ultrasparc v9" ;;
3486 +         *ultrasparciii*) ax_gcc_arch="ultrasparc3 ultrasparc v9" ;;
3487 +         *ultrasparc*) ax_gcc_arch="ultrasparc v9" ;;
3488 +         *supersparc*|*tms390z5[[05]]*) ax_gcc_arch="supersparc v8" ;;
3489 +         *hypersparc*|*rt62[[056]]*) ax_gcc_arch="hypersparc v8" ;;
3490 +         *cypress*) ax_gcc_arch=cypress ;;
3491 +     esac ;;
3492 +
3493 +  alphaev5) ax_gcc_arch=ev5 ;;
3494 +  alphaev56) ax_gcc_arch=ev56 ;;
3495 +  alphapca56) ax_gcc_arch="pca56 ev56" ;;
3496 +  alphapca57) ax_gcc_arch="pca57 pca56 ev56" ;;
3497 +  alphaev6) ax_gcc_arch=ev6 ;;
3498 +  alphaev67) ax_gcc_arch=ev67 ;;
3499 +  alphaev68) ax_gcc_arch="ev68 ev67" ;;
3500 +  alphaev69) ax_gcc_arch="ev69 ev68 ev67" ;;
3501 +  alphaev7) ax_gcc_arch="ev7 ev69 ev68 ev67" ;;
3502 +  alphaev79) ax_gcc_arch="ev79 ev7 ev69 ev68 ev67" ;;
3503 +
3504 +  powerpc*)
3505 +     cputype=`((grep cpu /proc/cpuinfo | head -n 1 | cut -d: -f2 | cut -d, -f1 | sed 's/ //g') ; /usr/bin/machine ; /bin/machine; grep CPU /var/run/dmesg.boot | head -n 1 | cut -d" " -f2) 2> /dev/null`
3506 +     cputype=`echo $cputype | sed -e 's/ppc//g;s/ *//g'`
3507 +     case $cputype in
3508 +       *750*) ax_gcc_arch="750 G3" ;;
3509 +       *740[[0-9]]*) ax_gcc_arch="$cputype 7400 G4" ;;
3510 +       *74[[4-5]][[0-9]]*) ax_gcc_arch="$cputype 7450 G4" ;;
3511 +       *74[[0-9]][[0-9]]*) ax_gcc_arch="$cputype G4" ;;
3512 +       *970*) ax_gcc_arch="970 G5 power4";;
3513 +       *POWER4*|*power4*|*gq*) ax_gcc_arch="power4 970";;
3514 +       *POWER5*|*power5*|*gr*|*gs*) ax_gcc_arch="power5 power4 970";;
3515 +       603ev|8240) ax_gcc_arch="$cputype 603e 603";;
3516 +       *) ax_gcc_arch=$cputype ;;
3517 +     esac
3518 +     ax_gcc_arch="$ax_gcc_arch powerpc"
3519 +     ;;
3520 +esac
3521 +fi # not cross-compiling
3522 +fi # guess arch
3523 +
3524 +if test "x$ax_gcc_arch" != x -a "x$ax_gcc_arch" != xno; then
3525 +for arch in $ax_gcc_arch; do
3526 +  if test "x[]m4_default([$1],yes)" = xyes; then # if we require portable code
3527 +    flags="-mtune=$arch"
3528 +    # -mcpu=$arch and m$arch generate nonportable code on every arch except
3529 +    # x86.  And some other arches (e.g. Alpha) don't accept -mtune.  Grrr.
3530 +    case $host_cpu in i*86|x86_64*) flags="$flags -mcpu=$arch -m$arch";; esac
3531 +  else
3532 +    flags="-march=$arch -mcpu=$arch -m$arch"
3533 +  fi
3534 +  for flag in $flags; do
3535 +    AX_CHECK_COMPILER_FLAGS($flag, [ax_cv_gcc_archflag=$flag; break])
3536 +  done
3537 +  test "x$ax_cv_gcc_archflag" = xunknown || break
3538 +done
3539 +fi
3540 +
3541 +fi # $GCC=yes
3542 +])
3543 +AC_MSG_CHECKING([for gcc architecture flag])
3544 +AC_MSG_RESULT($ax_cv_gcc_archflag)
3545 +if test "x$ax_cv_gcc_archflag" = xunknown; then
3546 +  m4_default([$3],:)
3547 +else
3548 +  m4_default([$2], [CFLAGS="$CFLAGS $ax_cv_gcc_archflag"])
3549 +fi
3550 +])
3551 diff --git a/m4/ax_gcc_x86_cpuid.m4 b/m4/ax_gcc_x86_cpuid.m4
3552 new file mode 100644
3553 index 0000000..5420b09
3554 --- /dev/null
3555 +++ b/m4/ax_gcc_x86_cpuid.m4
3556 @@ -0,0 +1,77 @@
3557 +# ===========================================================================
3558 +#        http://www.nongnu.org/autoconf-archive/ax_gcc_x86_cpuid.html
3559 +# ===========================================================================
3560 +#
3561 +# SYNOPSIS
3562 +#
3563 +#   AX_GCC_X86_CPUID(OP)
3564 +#
3565 +# DESCRIPTION
3566 +#
3567 +#   On Pentium and later x86 processors, with gcc or a compiler that has a
3568 +#   compatible syntax for inline assembly instructions, run a small program
3569 +#   that executes the cpuid instruction with input OP. This can be used to
3570 +#   detect the CPU type.
3571 +#
3572 +#   On output, the values of the eax, ebx, ecx, and edx registers are stored
3573 +#   as hexadecimal strings as "eax:ebx:ecx:edx" in the cache variable
3574 +#   ax_cv_gcc_x86_cpuid_OP.
3575 +#
3576 +#   If the cpuid instruction fails (because you are running a
3577 +#   cross-compiler, or because you are not using gcc, or because you are on
3578 +#   a processor that doesn't have this instruction), ax_cv_gcc_x86_cpuid_OP
3579 +#   is set to the string "unknown".
3580 +#
3581 +#   This macro mainly exists to be used in AX_GCC_ARCHFLAG.
3582 +#
3583 +# LICENSE
3584 +#
3585 +#   Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
3586 +#   Copyright (c) 2008 Matteo Frigo
3587 +#
3588 +#   This program is free software: you can redistribute it and/or modify it
3589 +#   under the terms of the GNU General Public License as published by the
3590 +#   Free Software Foundation, either version 3 of the License, or (at your
3591 +#   option) any later version.
3592 +#
3593 +#   This program is distributed in the hope that it will be useful, but
3594 +#   WITHOUT ANY WARRANTY; without even the implied warranty of
3595 +#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
3596 +#   Public License for more details.
3597 +#
3598 +#   You should have received a copy of the GNU General Public License along
3599 +#   with this program. If not, see <http://www.gnu.org/licenses/>.
3600 +#
3601 +#   As a special exception, the respective Autoconf Macro's copyright owner
3602 +#   gives unlimited permission to copy, distribute and modify the configure
3603 +#   scripts that are the output of Autoconf when processing the Macro. You
3604 +#   need not follow the terms of the GNU General Public License when using
3605 +#   or distributing such scripts, even though portions of the text of the
3606 +#   Macro appear in them. The GNU General Public License (GPL) does govern
3607 +#   all other use of the material that constitutes the Autoconf Macro.
3608 +#
3609 +#   This special exception to the GPL applies to versions of the Autoconf
3610 +#   Macro released by the Autoconf Archive. When you make and distribute a
3611 +#   modified version of the Autoconf Macro, you may extend this special
3612 +#   exception to the GPL to apply to your modified version as well.
3613 +
3614 +AC_DEFUN([AX_GCC_X86_CPUID],
3615 +[AC_REQUIRE([AC_PROG_CC])
3616 +AC_LANG_PUSH([C])
3617 +AC_CACHE_CHECK(for x86 cpuid $1 output, ax_cv_gcc_x86_cpuid_$1,
3618 + [AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>], [
3619 +     int op = $1, eax, ebx, ecx, edx;
3620 +     FILE *f;
3621 +      __asm__("cpuid"
3622 +        : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
3623 +        : "a" (op));
3624 +     f = fopen("conftest_cpuid", "w"); if (!f) return 1;
3625 +     fprintf(f, "%x:%x:%x:%x\n", eax, ebx, ecx, edx);
3626 +     fclose(f);
3627 +     return 0;
3628 +])],
3629 +     [ax_cv_gcc_x86_cpuid_$1=`cat conftest_cpuid`; rm -f conftest_cpuid],
3630 +     [ax_cv_gcc_x86_cpuid_$1=unknown; rm -f conftest_cpuid],
3631 +     [ax_cv_gcc_x86_cpuid_$1=unknown])])
3632 +AC_LANG_POP([C])
3633 +])
3634 diff --git a/m4/ax_submodule.m4 b/m4/ax_submodule.m4
3635 new file mode 100644
3636 index 0000000..57e3a56
3637 --- /dev/null
3638 +++ b/m4/ax_submodule.m4
3639 @@ -0,0 +1,63 @@
3640 +AC_DEFUN([AX_SUBMODULE],
3641 +[
3642 +
3643 +AC_ARG_WITH($1,
3644 +       [AS_HELP_STRING([--with-$1=$2],
3645 +                       [Which $1 to use])])
3646 +case "system" in
3647 +$2)
3648 +       AC_ARG_WITH($1_prefix,
3649 +                   [AS_HELP_STRING([--with-$1-prefix=DIR],
3650 +                                   [Prefix of $1 installation])])
3651 +       AC_ARG_WITH($1_exec_prefix,
3652 +                   [AS_HELP_STRING([--with-$1-exec-prefix=DIR],
3653 +                                   [Exec prefix of $1 installation])])
3654 +esac
3655 +case "build" in
3656 +$2)
3657 +       AC_ARG_WITH($1_builddir,
3658 +                   [AS_HELP_STRING([--with-$1-builddir=DIR],
3659 +                                   [Location of $1 builddir])])
3660 +esac
3661 +if test "x$with_$1_prefix" != "x" -a "x$with_$1_exec_prefix" = "x"; then
3662 +       with_$1_exec_prefix=$with_$1_prefix
3663 +fi
3664 +if test "x$with_$1_prefix" != "x" -o "x$with_$1_exec_prefix" != "x"; then
3665 +       if test "x$with_$1" != "x" -a "x$with_$1" != "xsystem"; then
3666 +               AC_MSG_ERROR([Setting $with_$1_prefix implies use of system $1])
3667 +       fi
3668 +       with_$1="system"
3669 +fi
3670 +if test "x$with_$1_builddir" != "x"; then
3671 +       if test "x$with_$1" != "x" -a "x$with_$1" != "xbuild"; then
3672 +               AC_MSG_ERROR([Setting $with_$1_builddir implies use of build $1])
3673 +       fi
3674 +       with_$1="build"
3675 +       $1_srcdir=`echo @abs_srcdir@ | $with_$1_builddir/config.status --file=-`
3676 +       AC_MSG_NOTICE($1 sources in $$1_srcdir)
3677 +fi
3678 +case "$with_$1" in
3679 +$2)
3680 +       ;;
3681 +*)
3682 +       if test -d $srcdir/.git -a \
3683 +               -d $srcdir/$1 -a \
3684 +               ! -d $srcdir/$1/.git; then
3685 +               AC_MSG_WARN(
3686 +[git repo detected, but submodule $1 not initialized])
3687 +               AC_MSG_WARN([You may want to run])
3688 +               AC_MSG_WARN([   git submodule init])
3689 +               AC_MSG_WARN([   git submodule update])
3690 +               AC_MSG_WARN([   sh autogen.sh])
3691 +       fi
3692 +       if test -f $srcdir/$1/configure -a "$3" != "no"; then
3693 +               with_$1="bundled"
3694 +       else
3695 +               with_$1="$3"
3696 +       fi
3697 +       ;;
3698 +esac
3699 +AC_MSG_CHECKING([which $1 to use])
3700 +AC_MSG_RESULT($with_$1)
3701 +
3702 +])
3703 diff --git a/osl b/osl
3704 new file mode 160000
3705 index 0000000..46ef4ec
3706 --- /dev/null
3707 +++ b/osl
3708 @@ -0,0 +1 @@
3709 +Subproject commit 46ef4ec9917713d5d51dd45331c0e74870c5375d
3710 diff --git a/piplib b/piplib
3711 new file mode 160000
3712 index 0000000..f2cfdd3
3713 --- /dev/null
3714 +++ b/piplib
3715 @@ -0,0 +1 @@
3716 +Subproject commit f2cfdd3f7a7c4c0c4f7408437205fa27bfb041ba
3717 diff --git a/redo.sh b/redo.sh
3718 new file mode 100755
3719 index 0000000..a1cdb50
3720 --- /dev/null
3721 +++ b/redo.sh
3722 @@ -0,0 +1,12 @@
3723 +#!/bin/sh
3724 +make maintainer-clean
3725 +#./get_submodules.sh
3726 +./autogen.sh
3727 +./configure  \
3728 +            --prefix=$HOME/usr \
3729 +            --with-osl=system \
3730 +            --with-osl-prefix=$HOME/usr \
3731 +            --with-piplib=system \
3732 +            --with-piplib-prefix=$HOME/usr 
3733 +
3734 +make
3735 diff --git a/source/Makefile.am b/source/Makefile.am
3736 deleted file mode 100644
3737 index 3909be1..0000000
3738 --- a/source/Makefile.am
3739 +++ /dev/null
3740 @@ -1,70 +0,0 @@
3741 -#
3742 -#   /**-------------------------------------------------------------------**
3743 -#    **                              CAnDL                                **
3744 -#    **-------------------------------------------------------------------**
3745 -#    **                           Makefile.am                             **
3746 -#    **-------------------------------------------------------------------**
3747 -#    **                 First version: september 8th 2003                 **
3748 -#    **-------------------------------------------------------------------**/
3749 -#
3750 -#/*****************************************************************************
3751 -# *   CAnDL : the Chunky Analyser for Dependences in Loops (experimental)     *
3752 -# *****************************************************************************
3753 -# *                                                                           *
3754 -# * Copyright (C) 2003-2008 Cedric Bastoul                                    *
3755 -# *                                                                           *
3756 -# * This is free software; you can redistribute it and/or modify it under the *
3757 -# * terms of the GNU General Public License as published by the Free Software *
3758 -# * Foundation; either version 2 of the License, or (at your option) any      *
3759 -# * later version.                                                           *
3760 -# *                                                                           *
3761 -# * This software is distributed in the hope that it will be useful, but      *
3762 -# * WITHOUT ANY WARRANTY; without even the implied warranty of                *
3763 -# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General *
3764 -# * Public License for more details.                                          *
3765 -# *                                                                           *
3766 -# * You should have received a copy of the GNU General Public License along   *
3767 -# * with software; if not, write to the Free Software Foundation, Inc.,       *
3768 -# * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA                    *
3769 -# *                                                                           *
3770 -# * CAnDL, the Chunky Dependence Analyser                                     *
3771 -# * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr                        *
3772 -# *                                                                           *
3773 -# *****************************************************************************/
3774 -
3775 -
3776 -#############################################################################
3777 -SUBDIRS                        =
3778 -
3779 -#############################################################################
3780 -MAINTAINERCLEANFILES   = Makefile.in
3781 -
3782 -INCLUDES               = -I$(top_builddir) -I$(top_srcdir)     \
3783 -                         -I$(top_builddir)/include             \
3784 -                         -I$(top_srcdir)/include
3785 -
3786 -#############################################################################
3787 -
3788 -lib_LTLIBRARIES        = libcandl.la
3789 -
3790 -
3791 -libcandl_la_SOURCES    =                       \
3792 -       dependence.c                            \
3793 -       ddv.c                                   \
3794 -       isl-wrapper.c                           \
3795 -       matrix.c                                \
3796 -       options.c                               \
3797 -       piplib-wrapper.c                        \
3798 -       program.c                               \
3799 -       pruning.c                               \
3800 -       statement.c                             \
3801 -       violation.c
3802 -
3803 -AM_CFLAGS = -Wall -fomit-frame-pointer -g
3804 -
3805 -
3806 -bin_PROGRAMS = candl
3807 -
3808 -LDADD = libcandl.la
3809 -
3810 -candl_SOURCES = candl.c
3811 diff --git a/source/candl.c b/source/candl.c
3812 index 27e8ca4..df6bf18 100644
3813 --- a/source/candl.c
3814 +++ b/source/candl.c
3815 @@ -6,8 +6,8 @@
3816      **----  \#/  --------------------------------------------------------**
3817      **    .-"#'-.        First version: september 8th 2003               **
3818      **--- |"-.-"| -------------------------------------------------------**
3819 -          |     |
3820 -          |     |
3821 +    |     |
3822 +    |     |
3823   ******** |     | *************************************************************
3824   * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
3825   ******************************************************************************
3826 @@ -33,98 +33,162 @@
3827   *                                                                            *
3828   ******************************************************************************/
3829  
3830 -
3831  #include <stdlib.h>
3832  #include <stdio.h>
3833 -#include <candl/candl.h>
3834 +#include <osl/scop.h>
3835 +#include <osl/macros.h>
3836 +#include <osl/util.h>
3837 +#include <osl/extensions/dependence.h>
3838 +#include <candl/macros.h>
3839  #include <candl/dependence.h>
3840 -#include <candl/program.h>
3841  #include <candl/violation.h>
3842  #include <candl/options.h>
3843 +#include <candl/scop.h>
3844 +#include <candl/util.h>
3845 +#include <candl/piplib.h>
3846  
3847  
3848 -int main(int argc, char * argv[])
3849 -{
3850 -  CandlProgram * program = NULL;
3851 -  CandlOptions * options;
3852 -  CandlDependence * dependence;
3853 -  CandlViolation * violation = NULL;
3854 -  FILE * input, * output;
3855 +int main(int argc, char * argv[]) {
3856 +  
3857 +  osl_scop_p scop = NULL;
3858 +  osl_scop_p orig_scop = NULL;
3859 +  osl_dependence_p dep = NULL;
3860 +  int num_scops = 0,  i= 0;
3861 +  candl_options_p options;
3862 +  candl_violation_p *violations = NULL;
3863 +  FILE *input, *output, *input_test;
3864 +  int precision;
3865 +  #if defined(CANDL_LINEAR_VALUE_IS_INT)
3866 +    precision = OSL_PRECISION_SP;
3867 +  #elif defined(CANDL_LINEAR_VALUE_IS_LONGLONG)
3868 +    precision = OSL_PRECISION_DP;
3869 +  #elif defined(CANDL_LINEAR_VALUE_IS_MP)
3870 +    precision = OSL_PRECISION_MP;
3871 +  #endif
3872  
3873    /* Options and input/output file setting. */
3874 -  candl_options_read(argc, argv, &input, &output, &options);
3875 -
3876 -  /* Reading the program informations. */
3877 -#ifdef CANDL_SUPPORTS_SCOPLIB
3878 -  if (options->readscop)
3879 -    {
3880 -      program = candl_program_read_scop(input);
3881 -      if (options->scoptocandl)
3882 -       {
3883 -         if (! options->readscop)
3884 -           program = candl_program_read_scop(input);
3885 -         candl_program_print_candl_file(output, program);
3886 -         candl_program_free(program);
3887 -         candl_options_free(options);
3888 -         return 0;
3889 -       }
3890 -    }
3891 -  else
3892 -#endif
3893 -    program = candl_program_read(input);
3894 -
3895 +  candl_options_read(argc, argv, &input, &output, &input_test, &options);
3896 +  
3897 +  /* Open the scop
3898 +   * If there is no original scop (given with the -test), the input file
3899 +   * is considered as the original scop
3900 +   */
3901 +  osl_interface_p registry = osl_interface_get_default_registry();
3902 +  if (input_test != NULL) {
3903 +    scop = osl_scop_pread(input, registry, precision);
3904 +    orig_scop = osl_scop_pread(input_test, registry, precision);
3905 +  } else {
3906 +    orig_scop = osl_scop_pread(input, registry, precision);
3907 +  }
3908 +  osl_interface_free(registry);
3909 +  
3910 +  if (orig_scop == NULL || (scop == NULL && input_test != NULL)) {
3911 +    CANDL_error("Fail to open scop");
3912 +    exit(1);
3913 +  }
3914 +  
3915 +  /* Check if we can compare the two scop
3916 +   * The function compare only domains and access arrays
3917 +   */
3918 +  if (input_test != NULL && !candl_util_check_scop_list(orig_scop, scop))
3919 +    CANDL_error("The two scop lists can't be compared");
3920 +  
3921 +  /* Add more infos (depth, label, ...)
3922 +   * Not important for the transformed scop
3923 +   * TODO : the statements must be sorted to compute the statement label
3924 +   *        the problem is if the scop is reordered, the second transformed scop
3925 +   *        must be aligned with it
3926 +   */
3927 +  candl_scop_usr_init(orig_scop);
3928 +  
3929    /* Calculating dependences. */
3930 -  dependence = candl_dependence(program, options);
3931 +  candl_dependence_add_extension(orig_scop, options);
3932  
3933 +  osl_scop_p s1 = orig_scop;
3934 +  while (s1) {num_scops++; s1 = s1->next;}
3935 +
3936 +  s1 = orig_scop;
3937 +  osl_scop_p s2 = scop;
3938    /* Calculating legality violations. */
3939 -  if (options->violgraph)
3940 -    violation = candl_violation(program, dependence, options);
3941 +  if (input_test != NULL) {
3942 +    CANDL_malloc(violations, candl_violation_p*, num_scops);
3943  
3944 -  /* Printing data structures if asked. */
3945 -  if (options->structure)
3946 -    {
3947 -      fprintf(output, "Program:\n");
3948 -      candl_program_print(output, program);
3949 -      fprintf(output, "\nDependences:\n");
3950 -      candl_dependence_print(output, dependence);
3951 -      fprintf(output, "\nViolations:\n");
3952 -      candl_violation_print(output, violation);
3953 +    for (i=0; i< num_scops; i++, s1 = s1->next, s2 = s2->next) {
3954 +      dep = osl_generic_lookup(s1->extension, 
3955 +                                            OSL_URI_DEPENDENCE);
3956 +      violations[i] = candl_violation(s1, dep, s2, options);
3957      }
3958 +  }
3959 +
3960 +  /* Printing data structures if asked. */
3961 +  if (options->structure) {
3962 +
3963 +    if (input_test != NULL) {
3964 +      s1=orig_scop; s2=scop;
3965 +      for (i=0; i< num_scops; i++, s1=s1->next, s2=s2->next) {
3966 +        fprintf(output, "\033[33mORIGINAL SCOP:\033[00m\n");
3967 +        osl_scop_print(output, s1);
3968 +        fprintf(output, "\n\033[33mTRANSFORMED SCOP:\033[00m\n");
3969 +        osl_scop_print(output, s2);
3970  
3971 -#ifdef CANDL_SUPPORTS_SCOPLIB
3972 -  if (options->readscop && options->writescop)
3973 -    candl_dependence_print_scop (input, output, dependence);
3974 -  else
3975 -    {
3976 -#endif
3977 -      /* Printing dependence graph if asked or if there is no transformation. */
3978 -      if (options->depgraph || (program->transformation == NULL))
3979 -       {
3980 -         candl_dependence_pprint(output, dependence);
3981 -         if (options->view)
3982 -           candl_dependence_view(dependence);
3983 -       }
3984 -      /* Printing violation graph if asked and if there is a transformation. */
3985 -      if (options->violgraph && (program->transformation != NULL))
3986 -       {
3987 -         candl_violation_pprint(output, violation);
3988 -         if (options->view)
3989 -           candl_violation_view(violation);
3990 -       }
3991 +        dep = osl_generic_lookup(s1->extension, OSL_URI_DEPENDENCE);
3992 +        fprintf(output, "\n\033[33mDEPENDENCES GRAPH:\033[00m\n");
3993 +        candl_dependence_pprint(output, dep);
3994 +        fprintf(output, "\n\n\033[33mVIOLATIONS GRAPH:\033[00m\n");
3995 +        candl_violation_pprint(output, violations[i]);
3996 +      }
3997 +    } else {
3998 +      s1=orig_scop;
3999 +      for (i=0; i< num_scops; i++, s1=s1->next) {
4000 +        fprintf(output, "\033[33mORIGINAL SCOP:\033[00m\n");
4001 +        osl_scop_print(output, s1);
4002  
4003 -#ifdef CANDL_SUPPORTS_SCOPLIB
4004 +        dep = osl_generic_lookup(s1->extension, OSL_URI_DEPENDENCE);
4005 +        fprintf(output, "\n\033[33mDEPENDENCES GRAPH:\033[00m\n");
4006 +        candl_dependence_pprint(output, dep);
4007 +      }
4008      }
4009 -#endif
4010  
4011 +  } else if (input_test != NULL) {
4012 +     /* Printing violation graph */
4013 +    for (i=0; i< num_scops; i++) {
4014 +      candl_violation_pprint(output, violations[i]);
4015 +      if (options->view)
4016 +        candl_violation_view(violations[i]);
4017 +    }
4018 +  } else if (options->outscop) {
4019 +    /* Export to the scop format */
4020 +    s1=orig_scop;
4021 +    osl_scop_print(output, s1); //prints list
4022 +  } else {
4023 +    /* Printing dependence graph if asked or if there is no transformation. */
4024 +    s1=orig_scop;
4025 +    for(i=0; i< num_scops; i++, s1=s1->next){
4026 +      dep = osl_generic_lookup(s1->extension, OSL_URI_DEPENDENCE);
4027 +      fprintf(output, "\033[33mSCOP #%d:\033[00m\n", i+1);
4028 +      candl_dependence_pprint(output, dep);
4029 +      fprintf(output, "\n");
4030 +      if (options->view)
4031 +        candl_dependence_view(dep);
4032 +    }
4033 +  }
4034  
4035    /* Being clean. */
4036 -  candl_violation_free(violation);
4037 -  candl_dependence_free(dependence);
4038 -  candl_program_free(program);
4039 +  if (input_test != NULL) {
4040 +    for (i=0; i< num_scops; i++)
4041 +      candl_violation_free(violations[i]);
4042 +    osl_scop_free(scop);
4043 +    fclose(input_test);
4044 +  }
4045 +  
4046 +  // the dependence is freed with the scop
4047 +  //osl_dependence_free(orig_dependence); 
4048    candl_options_free(options);
4049 -  pip_close();
4050 +  candl_scop_usr_cleanup(orig_scop);
4051 +  osl_scop_free(orig_scop);
4052    fclose(input);
4053    fclose(output);
4054 -
4055 +  pip_close();
4056 +  
4057    return 0;
4058  }
4059 diff --git a/source/ddv.c b/source/ddv.c
4060 index 8ac06f5..7220198 100644
4061 --- a/source/ddv.c
4062 +++ b/source/ddv.c
4063 @@ -6,8 +6,8 @@
4064      **----  \#/  --------------------------------------------------------**
4065      **    .-"#'-.         First version: February 4th 2010               **
4066      **--- |"-.-"| -------------------------------------------------------**
4067 -          |     |
4068 -          |     |
4069 +    |     |
4070 +    |     |
4071   ******** |     | *************************************************************
4072   * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
4073   ******************************************************************************
4074 @@ -41,13 +41,16 @@
4075  #include <stdlib.h>
4076  #include <stdio.h>
4077  #include <string.h>
4078 -#include <candl/candl.h>
4079 -
4080  #include <assert.h>
4081 -
4082 +#include <osl/statement.h>
4083 +#include <osl/scop.h>
4084 +#include <osl/extensions/dependence.h>
4085 +#include <candl/macros.h>
4086 +#include <candl/ddv.h>
4087 +#include <candl/statement.h>
4088 +#include <candl/piplib.h>
4089  #include <candl/piplib-wrapper.h>
4090  
4091 -
4092  #ifndef min
4093  # define min(x,y) (x < y ? x : y)
4094  #endif
4095 @@ -55,6 +58,7 @@
4096  # define max(x,y) (x > y ? x : y)
4097  #endif
4098  
4099 +
4100  /******************************************************************************
4101   *                         Memory deallocation function                       *
4102   ******************************************************************************/
4103 @@ -65,8 +69,7 @@
4104   *
4105   */
4106  CandlDDV*
4107 -candl_ddv_malloc()
4108 -{
4109 +candl_ddv_malloc() {
4110    CandlDDV* dv = (CandlDDV*) malloc(sizeof(CandlDDV));
4111    dv->next = NULL;
4112    dv->data = NULL;
4113 @@ -82,19 +85,17 @@ candl_ddv_malloc()
4114   *
4115   */
4116  CandlDDV*
4117 -candl_ddv_alloc(int size)
4118 -{
4119 +candl_ddv_alloc(int size) {
4120    CandlDDV* dv = candl_ddv_malloc();
4121  
4122    dv->data = (s_dv_descriptor*) malloc(size * sizeof(s_dv_descriptor));
4123    dv->length = size;
4124  
4125    int i;
4126 -  for (i = 0; i < size; ++i)
4127 -    {
4128 -      dv->data[i].type = candl_dv_star;
4129 -      dv->data[i].value = 0;
4130 -    }
4131 +  for (i = 0; i < size; ++i) {
4132 +    dv->data[i].type = candl_dv_star;
4133 +    dv->data[i].value = 0;
4134 +  }
4135  
4136    return dv;
4137  }
4138 @@ -106,19 +107,17 @@ candl_ddv_alloc(int size)
4139   *
4140   */
4141  void
4142 -candl_ddv_free(CandlDDV* dv)
4143 -{
4144 +candl_ddv_free(CandlDDV* dv) {
4145    CandlDDV* tmp;
4146    CandlDDV* next;
4147  
4148 -  for (tmp = dv; tmp; )
4149 -    {
4150 -      next = tmp->next;
4151 -      if (tmp->data)
4152 -       free(tmp->data);
4153 -      free(tmp);
4154 -      tmp = next;
4155 -    }
4156 +  for (tmp = dv; tmp; ) {
4157 +    next = tmp->next;
4158 +    if (tmp->data)
4159 +      free(tmp->data);
4160 +    free(tmp);
4161 +    tmp = next;
4162 +  }
4163  
4164  }
4165  
4166 @@ -130,8 +129,7 @@ candl_ddv_free(CandlDDV* dv)
4167   *
4168   */
4169  void
4170 -candl_ddv_set_type_at(CandlDDV* dv, e_dv_type type, int pos)
4171 -{
4172 +candl_ddv_set_type_at(CandlDDV* dv, e_dv_type type, int pos) {
4173    dv->data[pos].type = type;
4174  }
4175  
4176 @@ -143,19 +141,17 @@ candl_ddv_set_type_at(CandlDDV* dv, e_dv_type type, int pos)
4177   *
4178   */
4179  void
4180 -candl_ddv_set_value_at(CandlDDV* dv, int value, int pos)
4181 -{
4182 +candl_ddv_set_value_at(CandlDDV* dv, int value, int pos) {
4183    dv->data[pos].value = value;
4184  }
4185  
4186  /**
4187   * candl_ddv_set_type: Set the type of the dependence in
4188 - * CANDL_UNSET, CANDL_RAW, CANDL_WAR, CANDL_WAW, CANDL_RAR.
4189 + * CANDL_UNDEFINED, CANDL_RAW, CANDL_WAR, CANDL_WAW, CANDL_RAR.
4190   *
4191   */
4192  void
4193 -candl_ddv_set_deptype(CandlDDV* dv, int type)
4194 -{
4195 +candl_ddv_set_deptype(CandlDDV* dv, int type) {
4196    dv->deptype = type;
4197  }
4198  
4199 @@ -170,33 +166,30 @@ candl_ddv_set_deptype(CandlDDV* dv, int type)
4200   *
4201   */
4202  void
4203 -candl_ddv_print(FILE* out, CandlDDV* dv)
4204 -{
4205 -  if (!dv)
4206 -    {
4207 -      fprintf(out, "(null ddv)\n");
4208 -      return;
4209 -    }
4210 +candl_ddv_print(FILE* out, CandlDDV* dv) {
4211 +  if (!dv) {
4212 +    fprintf(out, "(null ddv)\n");
4213 +    return;
4214 +  }
4215  
4216    int i;
4217    fprintf(out, "loop_id=%d, (", dv->loop_id);
4218 -  for (i = 0; i < dv->length; ++i)
4219 -    {
4220 -      if (dv->data[i].type == candl_dv_star)
4221 -       fprintf(out, "*");
4222 -      else if (dv->data[i].type == candl_dv_eq)
4223 -       fprintf(out, "=");
4224 -      else if (dv->data[i].type == candl_dv_plus)
4225 -       fprintf(out, ">");
4226 -      else if (dv->data[i].type == candl_dv_minus)
4227 -       fprintf(out, "<");
4228 -      else if (dv->data[i].type == candl_dv_scalar)
4229 -       fprintf(out, "%d", dv->data[i].value);
4230 -      if (i < dv->length - 1)
4231 -       fprintf(out, ", ");
4232 -      else
4233 -       fprintf(out, ")\n");
4234 -    }
4235 +  for (i = 0; i < dv->length; ++i) {
4236 +    if (dv->data[i].type == candl_dv_star)
4237 +      fprintf(out, "*");
4238 +    else if (dv->data[i].type == candl_dv_eq)
4239 +      fprintf(out, "=");
4240 +    else if (dv->data[i].type == candl_dv_plus)
4241 +      fprintf(out, ">");
4242 +    else if (dv->data[i].type == candl_dv_minus)
4243 +      fprintf(out, "<");
4244 +    else if (dv->data[i].type == candl_dv_scalar)
4245 +      fprintf(out, "%d", dv->data[i].value);
4246 +    if (i < dv->length - 1)
4247 +      fprintf(out, ", ");
4248 +    else
4249 +      fprintf(out, ")\n");
4250 +  }
4251  }
4252  
4253  
4254 @@ -206,24 +199,11 @@ candl_ddv_print(FILE* out, CandlDDV* dv)
4255  
4256  
4257  /**
4258 - * Integer emptiness test on a given polyhedron.
4259 - *
4260 - */
4261 -static
4262 -int
4263 -candl_ddv_has_point(CandlMatrix* system)
4264 -{
4265 -  return pip_has_rational_point (system, NULL, 1);
4266 -}
4267 -
4268 -
4269 -/**
4270   * Recursively count the number of leaves in a QUAST.
4271   *
4272   */
4273  static
4274 -int count_quast_leaves(PipQuast* q)
4275 -{
4276 +int count_quast_leaves(PipQuast* q) {
4277    if (!q)
4278      return 0;
4279    if (q->condition == NULL)
4280 @@ -238,22 +218,19 @@ int count_quast_leaves(PipQuast* q)
4281   *
4282   */
4283  static
4284 -void get_quast_leaves(PipQuast* q, PipList** leaves)
4285 -{
4286 +void get_quast_leaves(PipQuast* q, PipList** leaves) {
4287    if (!q)
4288      return;
4289 -  if (q->condition == NULL)
4290 -    {
4291 -      int i;
4292 -      for (i = 0; leaves[i]; ++i)
4293 -       ;
4294 -      leaves[i] = q->list;
4295 -    }
4296 -  else
4297 -    {
4298 -      get_quast_leaves(q->next_else, leaves);
4299 -      get_quast_leaves(q->next_then, leaves);
4300 -    }
4301 +  if (q->condition == NULL) {
4302 +    int i;
4303 +    for (i = 0; leaves[i]; ++i)
4304 +      ;
4305 +    leaves[i] = q->list;
4306 +  }
4307 +  else {
4308 +    get_quast_leaves(q->next_else, leaves);
4309 +    get_quast_leaves(q->next_then, leaves);
4310 +  }
4311  }
4312  
4313  
4314 @@ -266,15 +243,16 @@ void get_quast_leaves(PipQuast* q, PipList** leaves)
4315   */
4316  static
4317  int
4318 -candl_ddv_constant_val(CandlMatrix* system, int* val, int nb_par)
4319 -{
4320 +candl_ddv_constant_val(osl_relation_p system, int* val, int nb_par) {
4321    PipOptions * options;
4322    PipQuast * solution;
4323 +  osl_relation_p context;
4324    int is_constant_val = 1;
4325    int cst;
4326    int cst_base = 42;
4327    int first = 1;
4328    int i, j;
4329 +  int precision = system->precision;
4330  
4331    // 1- Comute the lexmin of the system, to get a QUAST.
4332    options = pip_options_init();
4333 @@ -282,54 +260,51 @@ candl_ddv_constant_val(CandlMatrix* system, int* val, int nb_par)
4334    options->Urs_parms = -1;
4335    options->Urs_unknowns = -1;
4336    options->Nq = 0;
4337 -  CandlMatrix* context = candl_matrix_malloc(0, nb_par + 2);
4338 -  solution = pip_solve(system, context, -1, options);
4339 +  
4340 +  context = osl_relation_pmalloc(precision, 0, nb_par + 2);
4341 +  solution = pip_solve_osl(system, context, -1, options);
4342  
4343    if ((solution != NULL) &&
4344 -      ((solution->list != NULL) || (solution->condition != NULL)))
4345 -    {
4346 -      // 2- Traverse all leaves, ensure they have the same value.
4347 -      int nb_leaves = count_quast_leaves(solution);
4348 -      PipList* leaveslist[nb_leaves + 1];
4349 -      for (i = 0; i < nb_leaves + 1; ++i)
4350 -       leaveslist[i] = NULL;
4351 -      get_quast_leaves(solution, leaveslist);
4352 -
4353 -      for (i = 0; i < nb_leaves; ++i)
4354 -       {
4355 -         PipList* list = leaveslist[i];
4356 -         if (list && list->vector)
4357 -           {
4358 -             PipVector* vect = list->vector;
4359 -             for (j = 0; j < nb_par; ++j)
4360 -               if (CANDL_get_si(vect->the_vector[j]) != 0)
4361 -                 {
4362 -                   is_constant_val = 0;
4363 -                   break;
4364 -                 }
4365 -             if (is_constant_val)
4366 -               {
4367 -                 cst = CANDL_get_si(vect->the_vector[vect->nb_elements - 1]);
4368 -                 if (first)
4369 -                   {
4370 -                     first = 0;
4371 -                     cst_base = cst;
4372 -                   }
4373 -                 else if (! first && cst != cst_base)
4374 -                   {
4375 -                     is_constant_val = 0;
4376 -                     break;
4377 -                   }
4378 -               }
4379 -             else
4380 -               break;
4381 -           }
4382 -       }
4383 +      ((solution->list != NULL) || (solution->condition != NULL))) {
4384 +    // 2- Traverse all leaves, ensure they have the same value.
4385 +    int nb_leaves = count_quast_leaves(solution);
4386 +    PipList* leaveslist[nb_leaves + 1];
4387 +    for (i = 0; i < nb_leaves + 1; ++i)
4388 +      leaveslist[i] = NULL;
4389 +    get_quast_leaves(solution, leaveslist);
4390 +
4391 +    for (i = 0; i < nb_leaves; ++i) {
4392 +      PipList* list = leaveslist[i];
4393 +      if (list && list->vector) {
4394 +        PipVector* vect = list->vector;
4395 +        
4396 +        // FIXME : check if precision is correct to use piplib
4397 +        
4398 +        for (j = 0; j < nb_par; ++j)
4399 +          if (!CANDL_zero_p(vect->the_vector[j])) {
4400 +            is_constant_val = 0;
4401 +            break;
4402 +          }
4403 +        if (is_constant_val) {
4404 +          cst = CANDL_get_si(vect->the_vector[vect->nb_elements-1]);
4405 +          if (first) {
4406 +            first = 0;
4407 +            cst_base = cst;
4408 +          }
4409 +          else if (! first && cst != cst_base) {
4410 +            is_constant_val = 0;
4411 +            break;
4412 +          }
4413 +        }
4414 +        else
4415 +          break;
4416 +      }
4417      }
4418 +  }
4419  
4420    pip_quast_free(solution);
4421    pip_options_free(options);
4422 -  candl_matrix_free(context);
4423 +  osl_relation_free(context);
4424  
4425    if (is_constant_val)
4426      *val = cst_base;
4427 @@ -345,98 +320,97 @@ candl_ddv_constant_val(CandlMatrix* system, int* val, int nb_par)
4428   */
4429  static
4430  CandlDDV*
4431 -candl_ddv_create_from_dep(CandlDependence* dep, int loop_id, int ddv_size)
4432 -{
4433 +candl_ddv_create_from_dep(osl_dependence_p dep, int loop_id, int ddv_size) {
4434 +  osl_relation_p mat = dep->domain;
4435 +  osl_statement_p src = dep->stmt_source_ptr;
4436 +  candl_statement_usr_p usr = src->usr;
4437 +  CandlDDV* dv = candl_ddv_alloc(ddv_size);
4438 +  int precision = src->domain->precision;
4439    int i, j;
4440    int pos;
4441 -  CandlMatrix* mat = dep->domain;
4442 -  CandlStatement* src = dep->source;
4443 -  CandlDDV* dv = candl_ddv_alloc(ddv_size);
4444 +  
4445    dv->loop_id = loop_id;
4446    dv->deptype = dep->type;
4447  
4448    // Create the template of the system to operate on.
4449    // Add one dimension at the beginning, and one row for the extra constraint.
4450 -  int nb_par = src->domain->NbColumns - 2 - src->depth;
4451 -  CandlMatrix* testsyst =
4452 -    candl_matrix_malloc(mat->NbRows + 1, mat->NbColumns + 1);
4453 -  for (pos = 0; pos < mat->NbRows; ++pos)
4454 -    {
4455 -      CANDL_assign(testsyst->p[pos][0], mat->p[pos][0]);
4456 -      for (j = 1; j < mat->NbColumns; ++j)
4457 -       CANDL_assign(testsyst->p[pos][j + 1], mat->p[pos][j]);
4458 -    }
4459 +  int nb_par = src->domain->nb_parameters;
4460 +  osl_relation_p testsyst = osl_relation_pmalloc(precision,
4461 +                                                 mat->nb_rows + 1,
4462 +                                                 mat->nb_columns + 1);
4463 +  for (pos = 0; pos < mat->nb_rows; ++pos) {
4464 +    osl_int_assign(precision, &testsyst->m[pos][0], mat->m[pos][0]);
4465 +    for (j = 1; j < mat->nb_columns; ++j)
4466 +      osl_int_assign(precision, &testsyst->m[pos][j + 1],mat->m[pos][j]);
4467 +  }
4468 +  
4469    int has_eq, has_pos, has_neg, has_cst;
4470    int scal1, scal2;
4471 -  for (i = 1; i <= ddv_size; ++i)
4472 -    {
4473 -      // Test for '='.
4474 -      CANDL_set_si(testsyst->p[pos][0], 0);
4475 -      CANDL_set_si(testsyst->p[pos][1 + i], 1);
4476 -      CANDL_set_si(testsyst->p[pos][1 + i + src->depth], -1);
4477 -      CANDL_set_si(testsyst->p[pos][testsyst->NbColumns - 1], 0);
4478 -      has_eq = candl_ddv_has_point(testsyst);
4479 -
4480 -      // Test for '>'.
4481 -      CANDL_set_si(testsyst->p[pos][0], 1);
4482 -      CANDL_set_si(testsyst->p[pos][1 + i], 1);
4483 -      CANDL_set_si(testsyst->p[pos][1 + i + src->depth], -1);
4484 -      CANDL_set_si(testsyst->p[pos][testsyst->NbColumns - 1], -1);
4485 -      has_pos = candl_ddv_has_point(testsyst);
4486 -
4487 -      // Test for '<'.
4488 -      CANDL_set_si(testsyst->p[pos][0], 1);
4489 -      CANDL_set_si(testsyst->p[pos][1 + i], -1);
4490 -      CANDL_set_si(testsyst->p[pos][1 + i + src->depth], 1);
4491 -      CANDL_set_si(testsyst->p[pos][testsyst->NbColumns - 1], -1);
4492 -      has_neg = candl_ddv_has_point(testsyst);
4493 -
4494 -      // Test for constant distance.
4495 -      // min(x_R^i - x_S^i)
4496 -      // max(x_R^i - x_S^i) = - min(- x_R^i + x_S^i)
4497 -      CANDL_set_si(testsyst->p[pos][0], 0);
4498 -      CANDL_set_si(testsyst->p[pos][1], 1);
4499 -      CANDL_set_si(testsyst->p[pos][1 + i], -1);
4500 -      CANDL_set_si(testsyst->p[pos][1 + i + src->depth], 1);
4501 -      CANDL_set_si(testsyst->p[pos][testsyst->NbColumns - 1], 0);
4502 -      has_cst = candl_ddv_constant_val(testsyst, &scal1, nb_par);
4503 -
4504 +  for (i = 1; i <= ddv_size; ++i) {
4505 +    // Test for '='.
4506 +    osl_int_set_si(precision, &testsyst->m[pos][0], 0);
4507 +    osl_int_set_si(precision, &testsyst->m[pos][1 + i], 1);
4508 +    osl_int_set_si(precision, &testsyst->m[pos][1 + i + usr->depth], -1);
4509 +    osl_int_set_si(precision, &testsyst->m[pos][testsyst->nb_columns-1], 0);
4510 +    has_eq = pip_has_rational_point(testsyst, NULL, 1);
4511 +
4512 +    // Test for '>'.
4513 +    osl_int_set_si(precision, &testsyst->m[pos][0], 1);
4514 +    osl_int_set_si(precision, &testsyst->m[pos][1 + i], 1);
4515 +    osl_int_set_si(precision, &testsyst->m[pos][1 + i + usr->depth], -1);
4516 +    osl_int_set_si(precision, &testsyst->m[pos][testsyst->nb_columns-1], -1);
4517 +    has_pos = pip_has_rational_point(testsyst, NULL, 1);
4518 +
4519 +    // Test for '<'.
4520 +    osl_int_set_si(precision, &testsyst->m[pos][0], 1);
4521 +    osl_int_set_si(precision, &testsyst->m[pos][1 + i], -1);
4522 +    osl_int_set_si(precision, &testsyst->m[pos][1 + i + usr->depth], 1);
4523 +    osl_int_set_si(precision, &testsyst->m[pos][testsyst->nb_columns-1], -1);
4524 +    has_neg = pip_has_rational_point(testsyst, NULL, 1);
4525 +
4526 +    // Test for constant distance.
4527 +    // min(x_R^i - x_S^i)
4528 +    // max(x_R^i - x_S^i) = - min(- x_R^i + x_S^i)
4529 +    osl_int_set_si(precision, &testsyst->m[pos][0], 0);
4530 +    osl_int_set_si(precision, &testsyst->m[pos][1], 1);
4531 +    osl_int_set_si(precision, &testsyst->m[pos][1 + i], -1);
4532 +    osl_int_set_si(precision, &testsyst->m[pos][1 + i + usr->depth], 1);
4533 +    osl_int_set_si(precision, &testsyst->m[pos][testsyst->nb_columns-1], 0);
4534 +    has_cst = candl_ddv_constant_val(testsyst, &scal1, nb_par);
4535 +
4536 +    if (has_cst) {
4537 +      osl_int_set_si(precision, &testsyst->m[pos][1 + i], 1);
4538 +      osl_int_set_si(precision, &testsyst->m[pos][1 + i + usr->depth], -1);
4539 +      osl_int_set_si(precision, &testsyst->m[pos][1], 1);
4540 +      has_cst = candl_ddv_constant_val(testsyst, &scal2, nb_par);
4541 +      scal2 *= -1;
4542        if (has_cst)
4543 -       {
4544 -         CANDL_set_si(testsyst->p[pos][1 + i], 1);
4545 -         CANDL_set_si(testsyst->p[pos][1 + i + src->depth], -1);
4546 -         CANDL_set_si(testsyst->p[pos][1], 1);
4547 -         has_cst = candl_ddv_constant_val(testsyst, &scal2, nb_par);
4548 -         scal2 *= -1;
4549 -         if (has_cst)
4550 -           has_cst = (scal1 == scal2);
4551 -       }
4552 -
4553 -      if (has_cst && scal1 != 0)
4554 -       {
4555 -         candl_ddv_set_type_at (dv, candl_dv_scalar, i - 1);
4556 -         candl_ddv_set_value_at (dv, scal1, i - 1);
4557 -       }
4558 -      else if (has_pos && has_neg)
4559 -       candl_ddv_set_type_at (dv, candl_dv_star, i - 1);
4560 -      else if (has_pos)
4561 -       candl_ddv_set_type_at (dv, candl_dv_plus, i - 1);
4562 -      else if (has_neg)
4563 -       candl_ddv_set_type_at (dv, candl_dv_minus, i - 1);
4564 -      else if (has_eq)
4565 -       {
4566 -         candl_ddv_set_type_at (dv, candl_dv_eq, i - 1);
4567 -         candl_ddv_set_value_at (dv, 0, i - 1);
4568 -       }
4569 -
4570 -      // Reset the constraint.
4571 -      CANDL_set_si(testsyst->p[pos][0], 0);
4572 -      CANDL_set_si(testsyst->p[pos][1], 0);
4573 -      CANDL_set_si(testsyst->p[pos][1 + i], 0);
4574 -      CANDL_set_si(testsyst->p[pos][1 + i + src->depth], 0);
4575 -      CANDL_set_si(testsyst->p[pos][testsyst->NbColumns - 1], 0);
4576 +        has_cst = (scal1 == scal2);
4577      }
4578  
4579 +    if (has_cst && scal1 != 0) {
4580 +      candl_ddv_set_type_at(dv, candl_dv_scalar, i - 1);
4581 +      candl_ddv_set_value_at(dv, scal1, i - 1);
4582 +    }
4583 +    else if (has_pos && has_neg)
4584 +      candl_ddv_set_type_at(dv, candl_dv_star, i - 1);
4585 +    else if (has_pos)
4586 +      candl_ddv_set_type_at(dv, candl_dv_plus, i - 1);
4587 +    else if (has_neg)
4588 +      candl_ddv_set_type_at(dv, candl_dv_minus, i - 1);
4589 +    else if (has_eq) {
4590 +      candl_ddv_set_type_at(dv, candl_dv_eq, i - 1);
4591 +      candl_ddv_set_value_at(dv, 0, i - 1);
4592 +    }
4593 +
4594 +    // Reset the constraint.
4595 +    osl_int_set_si(precision, &testsyst->m[pos][0], 0);
4596 +    osl_int_set_si(precision, &testsyst->m[pos][1], 0);
4597 +    osl_int_set_si(precision, &testsyst->m[pos][1 + i], 0);
4598 +    osl_int_set_si(precision, &testsyst->m[pos][1 + i + usr->depth], 0);
4599 +    osl_int_set_si(precision, &testsyst->m[pos][testsyst->nb_columns-1], 0);
4600 +  }
4601 +
4602    return dv;
4603  }
4604  
4605 @@ -449,38 +423,39 @@ candl_ddv_create_from_dep(CandlDependence* dep, int loop_id, int ddv_size)
4606   *
4607   */
4608  CandlDDV*
4609 -candl_ddv_extract_in_loop(CandlProgram* program, CandlDependence* deps,
4610 -                         int loop_id)
4611 -{
4612 -  CandlDependence* tmp;
4613 +candl_ddv_extract_in_loop(osl_scop_p scop, osl_dependence_p deps,
4614 +                          int loop_id) {
4615 +  osl_dependence_p tmp;
4616 +  candl_statement_usr_p src_usr, dst_usr;
4617    CandlDDV* head = NULL;
4618    CandlDDV* last = NULL;
4619    int i;
4620  
4621 -  for (tmp = deps; tmp; tmp = tmp->next)
4622 -    {
4623 -      CandlStatement* src = tmp->source;
4624 -      CandlStatement* dst = tmp->target;
4625 -
4626 -      // Iterate on all dependences that lie within the given loop.
4627 -      for (i = 0; i < min(src->depth, dst->depth); ++i)
4628 -       if (src->index[i] == dst->index[i] && dst->index[i] == loop_id)
4629 -         break;
4630 -      if (i == min(src->depth, dst->depth))
4631 -       continue;
4632 -      // The dependence involves statement carried by the loop.
4633 -      // Convert it into dependence vector.
4634 -      CandlDDV* dv = candl_ddv_create_from_dep(tmp, loop_id, i + 1);
4635 -
4636 -      // Append the dependence vector to the list.
4637 -      if (head == NULL)
4638 -       head = last = dv;
4639 -      else
4640 -       {
4641 -         last->next = dv;
4642 -         last = dv;
4643 -       }
4644 +  for (tmp = deps; tmp; tmp = tmp->next) {
4645 +    osl_statement_p src = tmp->stmt_source_ptr;
4646 +    osl_statement_p dst = tmp->stmt_target_ptr;
4647 +    src_usr = src->usr;
4648 +    dst_usr = dst->usr;
4649 +
4650 +    // Iterate on all dependences that lie within the given loop.
4651 +    for (i = 0; i < min(src_usr->depth, dst_usr->depth); ++i)
4652 +      if (src_usr->index[i] == dst_usr->index[i] &&
4653 +          dst_usr->index[i] == loop_id)
4654 +        break;
4655 +    if (i == min(src_usr->depth, dst_usr->depth))
4656 +      continue;
4657 +    // The dependence involves statement carried by the loop.
4658 +    // Convert it into dependence vector.
4659 +    CandlDDV* dv = candl_ddv_create_from_dep(tmp, loop_id, i + 1);
4660 +
4661 +    // Append the dependence vector to the list.
4662 +    if (head == NULL)
4663 +      head = last = dv;
4664 +    else {
4665 +      last->next = dv;
4666 +      last = dv;
4667      }
4668 +  }
4669  
4670    return head;
4671  }
4672 @@ -493,11 +468,10 @@ candl_ddv_extract_in_loop(CandlProgram* program, CandlDependence* deps,
4673   *
4674   */
4675  int
4676 -candl_loops_are_permutable(CandlProgram* program, CandlDependence* deps,
4677 -                          int loop_id1, int loop_id2)
4678 -{
4679 -  CandlDDV* l1 = candl_ddv_extract_in_loop (program, deps, loop_id1);
4680 -  CandlDDV* l2 = candl_ddv_extract_in_loop (program, deps, loop_id2);
4681 +candl_loops_are_permutable(osl_scop_p scop, osl_dependence_p deps,
4682 +                           int loop_id1, int loop_id2) {
4683 +  CandlDDV* l1 = candl_ddv_extract_in_loop(scop, deps, loop_id1);
4684 +  CandlDDV* l2 = candl_ddv_extract_in_loop(scop, deps, loop_id2);
4685  
4686    // One of the loop do not carry any dependence.
4687    if (l1 == NULL || l2 == NULL)
4688 @@ -511,79 +485,75 @@ candl_loops_are_permutable(CandlProgram* program, CandlDependence* deps,
4689  
4690    int loop_dim_1 = -1;
4691    int loop_dim_2 = -1;
4692 -  int i, j;
4693 -  CandlStatement* stm;
4694 -  for (j = 0; j < program->nb_statements; ++j)
4695 -    {
4696 -      stm = program->statement[j];
4697 -      for (i = 0; i < stm->depth; ++i)
4698 -       if (stm->index[i] == loop_id1)
4699 -         loop_dim_1 = i;
4700 -       else if (stm->index[i] == loop_id2)
4701 -         loop_dim_2 = i;
4702 -      if (loop_dim_1 != -1 && loop_dim_2 != -1)
4703 -       break;
4704 -    }
4705 +  int i;
4706 +  candl_statement_usr_p usr;
4707 +  osl_statement_p stm = scop->statement;
4708 +  for (; stm != NULL; stm = stm->next) {
4709 +    usr = stm->usr;
4710 +    for (i = 0; i < usr->depth; ++i)
4711 +      if (usr->index[i] == loop_id1)
4712 +        loop_dim_1 = i;
4713 +      else if (usr->index[i] == loop_id2)
4714 +        loop_dim_2 = i;
4715 +    if (loop_dim_1 != -1 && loop_dim_2 != -1)
4716 +      break;
4717 +  }
4718  
4719    int is_pos_1 = 0;
4720    int is_neg_1 = 0;
4721    int is_pos_2 = 0;
4722    int is_neg_2 = 0;
4723    int is_star = 0;
4724 -  for (; dv; dv = dv->next)
4725 -    {
4726 -      switch (dv->data[loop_dim_1].type)
4727 -       {
4728 -       case candl_dv_plus:
4729 -         is_pos_1 = 1;
4730 -         break;
4731 -       case candl_dv_minus:
4732 -         is_neg_1 = 1;
4733 -         break;
4734 -       case candl_dv_scalar:
4735 -         if (dv->data[loop_dim_1].value > 0)
4736 -           is_pos_1 = 1;
4737 -         else if (dv->data[loop_dim_1].value < 0)
4738 -           is_neg_1 = 1;
4739 -         break;
4740 -       case candl_dv_star:
4741 -         is_star = 1;
4742 -         break;
4743 -       default:
4744 -         break;
4745 -       }
4746 -      switch (dv->data[loop_dim_2].type)
4747 -       {
4748 -       case candl_dv_plus:
4749 -         is_pos_2 = 1;
4750 -         break;
4751 -       case candl_dv_minus:
4752 -         is_neg_2 = 1;
4753 -         break;
4754 -       case candl_dv_scalar:
4755 -         if (dv->data[loop_dim_2].value > 0)
4756 -           is_pos_2 = 1;
4757 -         else if (dv->data[loop_dim_2].value < 0)
4758 -           is_neg_2 = 1;
4759 -         break;
4760 -       case candl_dv_star:
4761 -         is_star = 1;
4762 -         break;
4763 -       default:
4764 -         break;
4765 -       }
4766 -      if ((is_pos_1 && is_neg_1) || (is_pos_2 && is_neg_2) || is_star)
4767 -       {
4768 -         candl_ddv_free (l1);
4769 -         candl_ddv_free (l2);
4770 -         return 0;
4771 -       }
4772 +  for (; dv; dv = dv->next) {
4773 +    switch (dv->data[loop_dim_1].type) {
4774 +      case candl_dv_plus:
4775 +        is_pos_1 = 1;
4776 +        break;
4777 +      case candl_dv_minus:
4778 +        is_neg_1 = 1;
4779 +        break;
4780 +      case candl_dv_scalar:
4781 +        if (dv->data[loop_dim_1].value > 0)
4782 +          is_pos_1 = 1;
4783 +        else if (dv->data[loop_dim_1].value < 0)
4784 +          is_neg_1 = 1;
4785 +        break;
4786 +      case candl_dv_star:
4787 +        is_star = 1;
4788 +        break;
4789 +      default:
4790 +        break;
4791      }
4792 -  
4793 -  candl_ddv_free (l1);
4794 -  candl_ddv_free (l2);
4795 -  
4796 -  
4797 +    switch (dv->data[loop_dim_2].type) {
4798 +      case candl_dv_plus:
4799 +        is_pos_2 = 1;
4800 +        break;
4801 +      case candl_dv_minus:
4802 +        is_neg_2 = 1;
4803 +        break;
4804 +      case candl_dv_scalar:
4805 +        if (dv->data[loop_dim_2].value > 0)
4806 +          is_pos_2 = 1;
4807 +        else if (dv->data[loop_dim_2].value < 0)
4808 +          is_neg_2 = 1;
4809 +        break;
4810 +      case candl_dv_star:
4811 +        is_star = 1;
4812 +        break;
4813 +      default:
4814 +        break;
4815 +    }
4816 +    if ((is_pos_1 && is_neg_1) || (is_pos_2 && is_neg_2) || is_star) {
4817 +      candl_ddv_free(l1);
4818 +      candl_ddv_free(l2);
4819 +      return 0;
4820 +    }
4821 +  }
4822 +
4823 +  candl_ddv_free(l1);
4824 +  candl_ddv_free(l2);
4825 +
4826 +
4827    return ! ((is_pos_1 && is_neg_2) || (is_neg_1 && is_pos_2));
4828  }
4829  
4830 diff --git a/source/dependence.c b/source/dependence.c
4831 index 41afccf..c8a61dc 100644
4832 --- a/source/dependence.c
4833 +++ b/source/dependence.c
4834 @@ -6,8 +6,8 @@
4835      **----  \#/  --------------------------------------------------------**
4836      **    .-"#'-.        First version: september 18th 2003              **
4837      **--- |"-.-"| -------------------------------------------------------**
4838 -          |     |
4839 -          |     |
4840 +    |     |
4841 +    |     |
4842   ******** |     | *************************************************************
4843   * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
4844   ******************************************************************************
4845 @@ -40,11 +40,20 @@
4846  #include <stdlib.h>
4847  #include <stdio.h>
4848  #include <string.h>
4849 -#include <candl/candl.h>
4850 -
4851 -#include <candl/piplib-wrapper.h>
4852 -
4853  #include <assert.h>
4854 +#include <candl/macros.h>
4855 +#include <candl/dependence.h>
4856 +#include <candl/scop.h>
4857 +#include <candl/statement.h>
4858 +#include <candl/util.h>
4859 +#include <candl/matrix.h>
4860 +#include <candl/piplib.h>
4861 +#include <candl/piplib-wrapper.h>
4862 +#include <osl/macros.h>
4863 +#include <osl/scop.h>
4864 +#include <osl/statement.h>
4865 +#include <osl/relation.h>
4866 +#include <osl/extensions/dependence.h>
4867  
4868  #ifdef CANDL_SUPPORTS_ISL
4869  # undef Q // Thank you polylib...
4870 @@ -55,154 +64,106 @@
4871  #endif
4872  
4873  
4874 -
4875 -/******************************************************************************
4876 - *                          Structure display function                        *
4877 - ******************************************************************************/
4878 -
4879 -
4880  /**
4881 - * candl_dependence_print_structure function:
4882 - * Displays a CandlDependence structure (dependence) into a file (file,
4883 - * possibly stdout) in a way that trends to be understandable without falling
4884 - * in a deep depression or, for the lucky ones, getting a headache... It
4885 - * includes an indentation level (level) in order to work with others
4886 - * print_structure functions.
4887 - * - 18/09/2003: first version.
4888 + * candl_dependence_get_relation_ref_source_in_dep function:
4889 + * This function return the corresponding osl_relation_p of
4890 + * the ref_source
4891   */
4892 -void candl_dependence_print_structure(FILE* file,
4893 -                                     candl_dependence_p dependence,
4894 -                                     int level)
4895 -{
4896 -  int j, first = 1;
4897 -
4898 -  if (dependence != NULL)
4899 -    { /* Go to the right level. */
4900 -      for(j=0; j<level; j++)
4901 -       fprintf(file, "|\t");
4902 -      fprintf(file, "+-- CandlDependence\n");
4903 -    }
4904 -  else
4905 -    { for(j=0; j<level; j++)
4906 -       fprintf(file, "|\t");
4907 -      fprintf(file, "+-- NULL dependence\n");
4908 -    }
4909 -
4910 -  while (dependence != NULL)
4911 -    { if (!first)
4912 -       { /* Go to the right level. */
4913 -         for(j=0; j<level; j++)
4914 -           fprintf(file, "|\t");
4915 -         fprintf(file, "|   CandlDependence\n");
4916 -       }
4917 -      else
4918 -       first = 0;
4919 -
4920 -      /* A blank line. */
4921 -      for(j=0; j<=level+1; j++)
4922 -       fprintf(file, "|\t");
4923 -      fprintf(file, "\n");
4924 -
4925 -      /* Go to the right level and print the type. */
4926 -      for(j=0; j<=level; j++)
4927 -       fprintf(file, "|\t");
4928 -      fprintf(file, "Type: ");
4929 -      switch (dependence->type)
4930 -       {
4931 -       case CANDL_UNSET : fprintf(file, "UNSET\n");        break;
4932 -       case CANDL_RAW   : fprintf(file, "RAW (flow)\n");   break;
4933 -       case CANDL_WAR   : fprintf(file, "WAR (anti)\n");   break;
4934 -       case CANDL_WAW   : fprintf(file, "WAW (output)\n"); break;
4935 -       case CANDL_RAR   : fprintf(file, "RAR (input)\n");  break;
4936 -       case CANDL_RAW_SCALPRIV   : fprintf(file, "RAW_SCALPRIV (scalar priv)\n");  break;
4937 -       default : fprintf(file, "unknown\n"); break;
4938 -       }
4939 -
4940 -      /* A blank line. */
4941 -      for(j=0; j<=level+1; j++)
4942 -       fprintf(file, "|\t");
4943 -      fprintf(file, "\n");
4944 -
4945 -      /* Go to the right level and print the depth. */
4946 -      for(j=0; j<=level; j++)
4947 -       fprintf(file, "|\t");
4948 -      fprintf(file, "Depth: %d\n", dependence->depth);
4949 -
4950 -      /* A blank line. */
4951 -      for(j=0; j<=level+1; j++)
4952 -       fprintf(file, "|\t");
4953 -      fprintf(file, "\n");
4954 -
4955 -      /* Print the source statement. */
4956 -      candl_statement_print_structure(file, dependence->source, level+1);
4957 -
4958 -      /* Print the target statement. */
4959 -      candl_statement_print_structure(file, dependence->target, level+1);
4960 -
4961 -      /* Print the dependence polyhedron. */
4962 -      candl_matrix_print_structure(file, dependence->domain, level+1);
4963 -
4964 -      dependence = dependence->next;
4965 -
4966 -      /* Next line. */
4967 -      if (dependence != NULL)
4968 -       { for (j=0; j<=level; j++)
4969 -           fprintf(file, "|\t");
4970 -         fprintf(file, "V\n");
4971 -       }
4972 -    }
4973 +osl_relation_p
4974 +candl_dependence_get_relation_ref_source_in_dep(osl_dependence_p tmp) {
4975 +  if (tmp->ref_source_access_ptr != NULL)
4976 +    return tmp->ref_source_access_ptr;
4977 +  int count = 0;
4978 +  osl_relation_p elt = NULL;
4979 +  osl_relation_list_p access;
4980 +  access = tmp->stmt_source_ptr->access;
4981 +  for (; access != NULL ; access = access->next) {
4982 +    elt = access->elt;
4983 +    if (count == tmp->ref_source)
4984 +      break;
4985 +    count++;
4986 +  }
4987 +  tmp->ref_source_access_ptr = elt;
4988 +  return elt;
4989 +}
4990  
4991 -  /* The last line. */
4992 -  for(j=0; j<=level; j++)
4993 -    fprintf(file, "|\t");
4994 -  fprintf(file, "\n");
4995 +/**
4996 + * candl_dependence_get_relation_ref_target_in_dep function:
4997 + * same as candl_dependence_get_relation_ref_source_in_dep but for the target
4998 + */
4999 +osl_relation_p
5000 +candl_dependence_get_relation_ref_target_in_dep(osl_dependence_p tmp) {
5001 +  if (tmp->ref_target_access_ptr != NULL)
5002 +    return tmp->ref_target_access_ptr;
5003 +  int count = 0;
5004 +  osl_relation_list_p access;
5005 +  osl_relation_p elt = NULL;
5006 +  access = tmp->stmt_target_ptr->access;
5007 +  for (; access != NULL ; access = access->next) {
5008 +    elt = access->elt;
5009 +    if (count == tmp->ref_target)
5010 +      break;
5011 +    count++;
5012 +  }
5013 +  tmp->ref_target_access_ptr = elt;
5014 +  return elt;
5015  }
5016  
5017  
5018 -/* candl_dependence_print function:
5019 - * This function prints the content of a CandlDependence structure (dependence)
5020 - * into a file (file, possibly stdout).
5021 +
5022 +/**
5023 + * candl_dependence_get_array_refs_in_dep function:
5024 + * This function return the array indices referenced in the
5025 + * dependence.
5026   */
5027 -void candl_dependence_print(FILE * file, candl_dependence_p dependence)
5028 -{
5029 -  candl_dependence_print_structure(file, dependence, 0);
5030 +void candl_dependence_get_array_refs_in_dep(osl_dependence_p tmp,
5031 +                                            int* refs, int* reft) {
5032 +  if (! tmp)
5033 +    return;
5034 +
5035 +  osl_relation_p src, targ;
5036 +  
5037 +  src = candl_dependence_get_relation_ref_source_in_dep(tmp);
5038 +  targ = candl_dependence_get_relation_ref_target_in_dep(tmp);
5039 +  
5040 +  *refs = osl_relation_get_array_id(src);
5041 +
5042 +  *reft = osl_relation_get_array_id(targ);
5043  }
5044  
5045  
5046 -/* candl_dependence_pprint function:
5047 - * This function prints the content of a CandlDependence structure (dependence)
5048 +/* osl_dependence_pprint function:
5049 + * This function prints the content of a osl_dependence_p structure (dependence)
5050   * into a file (file, possibly stdout) as a Graphviz input file.
5051   * See http://www.graphviz.org
5052   * - 08/12/2005: first version.
5053   */
5054 -void candl_dependence_pprint(FILE * file, candl_dependence_p dependence)
5055 -{
5056 +void candl_dependence_pprint(FILE * file, osl_dependence_p dependence) {
5057    int i = 0;
5058 -
5059 +  
5060    fprintf(file, "digraph G {\n");
5061  
5062    fprintf(file, "# Data Dependence Graph\n");
5063    fprintf(file, "# Generated by Candl "CANDL_RELEASE" "CANDL_VERSION" bits\n");
5064 -  while (dependence != NULL)
5065 -    {
5066 -      fprintf(file, "  S%d -> S%d [label=\" ", dependence->source->label,
5067 -             dependence->target->label);
5068 -      switch (dependence->type)
5069 -       {
5070 -       case CANDL_UNSET : fprintf(file, "UNSET"); break;
5071 -       case CANDL_RAW   : fprintf(file, "RAW")  ; break;
5072 -       case CANDL_WAR   : fprintf(file, "WAR")  ; break;
5073 -       case CANDL_WAW   : fprintf(file, "WAW")  ; break;
5074 -       case CANDL_RAR   : fprintf(file, "RAR")  ; break;
5075 -       case CANDL_RAW_SCALPRIV   : fprintf(file, "RAW_SCALPRIV (scalar-priv)")  ; break;
5076 -       default : fprintf(file, "unknown"); break;
5077 -       }
5078 -      fprintf(file, " depth %d, ref %d->%d \"];\n", dependence->depth,
5079 -             dependence->ref_source,
5080 -             dependence->ref_target);
5081 -      dependence = dependence->next;
5082 -      i++;
5083 +  while (dependence != NULL) {
5084 +    fprintf(file, "  S%d -> S%d [label=\" ", dependence->label_source,
5085 +                                             dependence->label_target);
5086 +    switch (dependence->type) {
5087 +      case OSL_UNDEFINED : fprintf(file, "UNSET"); break;
5088 +      case OSL_DEPENDENCE_RAW   : fprintf(file, "RAW") ; break;
5089 +      case OSL_DEPENDENCE_WAR   : fprintf(file, "WAR") ; break;
5090 +      case OSL_DEPENDENCE_WAW   : fprintf(file, "WAW") ; break;
5091 +      case OSL_DEPENDENCE_RAR   : fprintf(file, "RAR") ; break;
5092 +      case OSL_DEPENDENCE_RAW_SCALPRIV   :
5093 +           fprintf(file, "RAW_SCALPRIV (scalar-priv)") ; break;
5094 +      default : fprintf(file, "unknown"); break;
5095      }
5096 +    fprintf(file, " depth %d, ref %d->%d \"];\n", dependence->depth,
5097 +            dependence->ref_source,
5098 +            dependence->ref_target);
5099 +    dependence = dependence->next;
5100 +    i++;
5101 +  }
5102  
5103    if (i>4)
5104      fprintf(file, "# Number of edges = %i\n}\n", i);
5105 @@ -217,135 +178,25 @@ void candl_dependence_pprint(FILE * file, candl_dependence_p dependence)
5106   * dependence graph.
5107   * - 20/03/2006: first version.
5108   */
5109 -void candl_dependence_view(candl_dependence_p dependence)
5110 -{
5111 +void candl_dependence_view(osl_dependence_p dep) {
5112    FILE * temp_output;
5113 -
5114 -  temp_output = fopen(CANDL_TEMP_OUTPUT, "w");
5115 -  candl_dependence_pprint(temp_output, dependence);
5116 +  temp_output = fopen(CANDL_TEMP_OUTPUT,"w+");
5117 +  candl_dependence_pprint(temp_output, dep);
5118    fclose(temp_output);
5119 -  system("(dot -Tps "CANDL_TEMP_OUTPUT" | gv - &) && rm -f "CANDL_TEMP_OUTPUT);
5120 -}
5121 -
5122 -
5123 -/**
5124 - * Returns a string containing the dependence, formatted to fit the
5125 - * .scop representation.
5126 - *
5127 - */
5128 -static
5129 -char*
5130 -candl_program_deps_to_string(CandlDependence* dependence)
5131 -{
5132 -  CandlDependence* tmp = dependence;
5133 -  int refs = 0, reft = 0;
5134 -  int i, j, k;
5135 -  int nb_deps;
5136 -  int buffer_size = 2048;
5137 -  int szbuff;
5138 -  char* buffer = (char*) malloc(buffer_size * sizeof(char));
5139 -  char buff[1024];
5140 -  char* type;
5141 -  char* pbuffer;
5142 -
5143 -  for (tmp = dependence, nb_deps = 0; tmp; tmp = tmp->next, ++nb_deps)
5144 +  /* check the return to remove the warning compilation */
5145 +  if(system("dot -Tps "CANDL_TEMP_OUTPUT" | gv - && rm -f "CANDL_TEMP_OUTPUT" &"))
5146      ;
5147 -  sprintf(buffer, "# Number of dependences\n%d\n", nb_deps);
5148 -  if (nb_deps)
5149 -    {
5150 -      for (tmp = dependence, nb_deps = 1; tmp; tmp = tmp->next, ++nb_deps)
5151 -       {
5152 -         /* Compute the type of the dependence, and the array id
5153 -            accessed. */
5154 -         switch (tmp->type)
5155 -           {
5156 -           case CANDL_UNSET:
5157 -             type = "UNSET";
5158 -             break;
5159 -           case CANDL_RAW:
5160 -             type = "RAW #(flow)";
5161 -             refs = CANDL_get_si(tmp->source->written->p[tmp->ref_source][0]);
5162 -             reft = CANDL_get_si(tmp->target->read->p[tmp->ref_target][0]);
5163 -             break;
5164 -           case CANDL_WAR:
5165 -             type = "WAR #(anti)";
5166 -             refs = CANDL_get_si(tmp->source->read->p[tmp->ref_source][0]);
5167 -             reft = CANDL_get_si(tmp->target->written->p[tmp->ref_target][0]);
5168 -             break;
5169 -           case CANDL_WAW:
5170 -             type = "WAW #(output)";
5171 -             refs = CANDL_get_si(tmp->source->written->p[tmp->ref_source][0]);
5172 -             reft = CANDL_get_si(tmp->target->written->p[tmp->ref_target][0]);
5173 -             break;
5174 -           case CANDL_RAR:
5175 -             type = "RAR #(input)";
5176 -             refs = CANDL_get_si(tmp->source->read->p[tmp->ref_source][0]);
5177 -             reft = CANDL_get_si(tmp->target->read->p[tmp->ref_target][0]);
5178 -             break;
5179 -           case CANDL_RAW_SCALPRIV:
5180 -             type = "RAW_SCALPRIV #(scalar priv)";
5181 -             refs = CANDL_get_si(tmp->source->written->p[tmp->ref_source][0]);
5182 -             reft = CANDL_get_si(tmp->target->read->p[tmp->ref_target][0]);
5183 -             break;
5184 -           default:
5185 -             exit(1);
5186 -             break;
5187 -           }
5188 -         /* Quick consistency check. */
5189 -         if (refs != reft)
5190 -           CANDL_FAIL("Internal error. refs != reft\n");
5191 -
5192 -         /* Output dependence information. */
5193 -         sprintf(buff, "# Description of dependence %d\n"
5194 -                 "# type\n%s\n# From statement id\n%d\n"
5195 -                 "# To statement id\n%d\n# Depth \n%d\n# Array id\n%d\n"
5196 -                 "# Dependence domain\n%d %d\n", nb_deps, type,
5197 -                 tmp->source->label, tmp->target->label, tmp->depth,
5198 -                 refs, tmp->domain->NbRows, tmp->domain->NbColumns);
5199 -         strcat(buffer, buff);
5200 -         /* Output dependence domain. */
5201 -         pbuffer = buffer + strlen(buffer);
5202 -         for (i = 0; i < tmp->domain->NbRows; ++i)
5203 -           {
5204 -             for (j = 0; j < tmp->domain->NbColumns; ++j)
5205 -               {
5206 -                 sprintf(buff, "%lld ", CANDL_get_si(tmp->domain->p[i][j]));
5207 -                 szbuff = strlen(buff);
5208 -                 if (szbuff == 2)
5209 -                   *(pbuffer++) = ' ';
5210 -                 for (k = 0; k < szbuff; ++k)
5211 -                   *(pbuffer++) = buff[k];
5212 -               }
5213 -             *(pbuffer++) = '\n';
5214 -           }
5215 -         *(pbuffer++) = '\0';
5216 -         /* Increase the buffer size if needed. Conservatively assume a
5217 -            dependence is never larger than 2k. */
5218 -         szbuff = strlen(buffer);
5219 -         if (szbuff + 2048 > buffer_size)
5220 -           {
5221 -             buffer = (char*) realloc(buffer, (buffer_size *= 2) *
5222 -                                      sizeof(char));
5223 -             if (buffer == NULL)
5224 -               CANDL_FAIL("Error: memory overflow");
5225 -             buffer[szbuff] = '\0';
5226 -           }
5227 -       }
5228 -    }
5229 -
5230 -  return buffer;
5231  }
5232  
5233 +
5234  #ifdef CANDL_SUPPORTS_ISL
5235  
5236 -struct isl_set*
5237 -isl_set_from_piplib_matrix(struct isl_ctx* ctx,
5238 -                          PipMatrix* matrix,
5239 -                          int nparam);
5240 -PipMatrix*
5241 -isl_set_to_piplib_matrix(struct isl_ctx* ctx,
5242 -                        struct isl_set* set,
5243 -                        int nparam);
5244 +struct isl_set* isl_set_from_piplib_matrix(struct isl_ctx* ctx,
5245 +                                           osl_relation_p matrix,
5246 +                                           int nparam);
5247 +osl_relation_p isl_set_to_piplib_matrix(struct isl_ctx* ctx,
5248 +                                        struct isl_set* set,
5249 +                                        int nparam);
5250  /**
5251   * candl_dependence_isl_simplify function:
5252   *
5253 @@ -353,33 +204,35 @@ isl_set_to_piplib_matrix(struct isl_ctx* ctx,
5254   * Useful for polyhedra that contain large coefficient values.
5255   *
5256   */
5257 -CandlDependence* candl_dependence_isl_simplify(CandlDependence* dep,
5258 -                                              CandlProgram* program)
5259 -{
5260 -  if (dep == NULL || program == NULL)
5261 +osl_dependence_p candl_dependence_isl_simplify(osl_dependence_p dep,
5262 +                                                 osl_scop_p scop) {
5263 +  if (dep == NULL || scop == NULL)
5264      return dep;
5265  
5266 -  CandlDependence* tmp;
5267 -  PipMatrix* context = (PipMatrix*) program->context;
5268 -  int nparam = context->NbColumns - 2;
5269 -
5270 -  struct isl_ctx* ctx = isl_ctx_alloc ();
5271 -
5272 -  for (tmp = dep; tmp; tmp = tmp->next)
5273 -    {
5274 -      // 1- Convert the dependence polyhedron into ISL set.
5275 -      struct isl_set* set =
5276 -       isl_set_from_piplib_matrix(ctx, tmp->domain, nparam);
5277 -
5278 -      // 2- Simplify the ISL set.
5279 -      set = isl_set_detect_equalities(set);
5280 -
5281 -      // 3- Convert back into Candl matrix representation.
5282 -      PipMatrix* newdom = isl_set_to_piplib_matrix(ctx, set, nparam);
5283 -      isl_set_free (set);
5284 -      candl_matrix_free (tmp->domain);
5285 -      tmp->domain = (CandlMatrix*) newdom;
5286 -    }
5287 +  osl_dependence_p tmp;
5288 +  osl_relation_p context = scop->context;
5289 +  int nparam = context->nb_parameters;
5290 +
5291 +  struct isl_ctx* ctx = isl_ctx_alloc();
5292 +
5293 +  for (tmp = dep; tmp; tmp = tmp->next) {
5294 +    // 1- Convert the dependence polyhedron into ISL set.
5295 +    
5296 +    struct isl_set* set = isl_set_from_piplib_matrix(ctx, tmp->domain, nparam);
5297 +    
5298 +    // 2- Simplify the ISL set.
5299 +    set = isl_set_detect_equalities(set);
5300 +
5301 +    // 3- Convert back into Candl matrix representation.
5302 +    osl_relation_p newdom = isl_set_to_piplib_matrix(ctx, set, nparam);
5303 +    isl_set_free(set);
5304 +    newdom->nb_output_dims = tmp->domain->nb_output_dims;
5305 +    newdom->nb_input_dims  = tmp->domain->nb_input_dims;
5306 +    newdom->nb_local_dims  = tmp->domain->nb_local_dims;
5307 +    newdom->nb_parameters  = tmp->domain->nb_parameters;
5308 +    osl_relation_free(tmp->domain);
5309 +    tmp->domain = newdom;
5310 +  }
5311  
5312    /// FIXME: Some dead ref.
5313    //isl_ctx_free (ctx);
5314 @@ -390,476 +243,76 @@ CandlDependence* candl_dependence_isl_simplify(CandlDependence* dep,
5315  #endif
5316  
5317  
5318 -
5319 -/**
5320 - * candl_dependence_print_scop function:
5321 - * This function adds to the .scop file provided as the 'input' the
5322 - * optional tags to represent the dependences 'dependence' of the
5323 - * program. Finally, it prints the updated .scop to the file 'output'.
5324 - *
5325 - *
5326 - */
5327 -#ifdef CANDL_SUPPORTS_SCOPLIB
5328 -/**
5329 - * Read one dependence from a string.
5330 - *
5331 +/* candl_dependence_init_fields:
5332 + * Set the various other fields of the dependence structure
5333   */
5334 -static
5335 -CandlDependence* candl_dependence_read_one_dep(char* str, char** next,
5336 -                                              CandlProgram* program)
5337 -{
5338 -  CandlDependence* dep = candl_dependence_malloc();
5339 -  CandlMatrix* msource = NULL;
5340 -  CandlMatrix* mtarget = NULL;
5341 -  char buffer[1024];
5342 -
5343 -  int i, j, k;
5344 -  int id;
5345 -  int id2;
5346 -  /* # Description of dependence xxx */
5347 -  for (; *str != '\n'; ++str);
5348 -  ++str;
5349 -
5350 -  /* # type */
5351 -  for (; *str != '\n'; ++str);
5352 -  ++str;
5353 -
5354 -  /* {RAW,RAR,WAR,WAW} #(type) */
5355 -  for (i = 0; *str != ' '; ++str, ++i)
5356 -    buffer[i] = *str;
5357 -  buffer[i] = '\0';
5358 -  if (! strcmp(buffer, "RAW"))
5359 -    dep->type = CANDL_RAW;
5360 -  else if (! strcmp(buffer, "RAR"))
5361 -    dep->type = CANDL_RAR;
5362 -  else if (! strcmp(buffer, "WAR"))
5363 -    dep->type = CANDL_WAR;
5364 -  else if (! strcmp(buffer, "WAW"))
5365 -    dep->type = CANDL_WAW;
5366 -  else if (! strcmp(buffer, "RAW_SCALPRIV"))
5367 -    dep->type = CANDL_RAW_SCALPRIV;
5368 -  for (; *str != '\n'; ++str);
5369 -  ++str;
5370 -
5371 -  /* # From statement xxx */
5372 -  for (; *str != '\n'; ++str);
5373 -  ++str;
5374 -  /* stmt-id */
5375 -  for (i = 0; *str != '\n'; ++str, ++i)
5376 -    buffer[i] = *str;
5377 -  ++str;
5378 -  buffer[i] = '\0';
5379 -  id = atoi(buffer);
5380 -  for (i = 0; i < program->nb_statements; ++i)
5381 -    if (program->statement[i]->label == id)
5382 -      {
5383 -       dep->source = program->statement[i];
5384 -       break;
5385 -      }
5386 -
5387 -  /* # To statement xxx */
5388 -  for (; *str != '\n'; ++str);
5389 -  ++str;
5390 -  /* stmt-id */
5391 -  for (i = 0; *str != '\n'; ++str, ++i)
5392 -    buffer[i] = *str;
5393 -  ++str;
5394 -  buffer[i] = '\0';
5395 -  id = atoi(buffer);
5396 -  for (i = 0; i < program->nb_statements; ++i)
5397 -    if (program->statement[i]->label == id)
5398 -      {
5399 -       dep->target = program->statement[i];
5400 -       break;
5401 -      }
5402 -
5403 -  /* # Depth */
5404 -  for (; *str != '\n'; ++str);
5405 -  ++str;
5406 -  /* depth */
5407 -  for (i = 0; *str != '\n'; ++str, ++i)
5408 -    buffer[i] = *str;
5409 -  ++str;
5410 -  buffer[i] = '\0';
5411 -  dep->depth = atoi(buffer);
5412 -
5413 -  /* # Array id */
5414 -  for (; *str != '\n'; ++str);
5415 -  ++str;
5416 -  /* array-id */
5417 -  for (i = 0; *str != '\n'; ++str, ++i)
5418 -    buffer[i] = *str;
5419 -  ++str;
5420 -  buffer[i] = '\0';
5421 -  id = atoi(buffer);
5422 -  switch (dep->type)
5423 -    {
5424 -    case CANDL_RAW:
5425 -    case CANDL_RAW_SCALPRIV:
5426 -      msource = dep->source->written;
5427 -      mtarget = dep->target->read;
5428 -      break;
5429 -    case CANDL_WAR:
5430 -      msource = dep->source->read;
5431 -      mtarget = dep->target->written;
5432 -      break;
5433 -    case CANDL_WAW:
5434 -      msource = dep->source->written;
5435 -      mtarget = dep->target->written;
5436 -      break;
5437 -    case CANDL_RAR:
5438 -      msource = dep->source->read;
5439 -      mtarget = dep->target->read;
5440 -      break;
5441 -    default:
5442 -      exit(1);
5443 +void candl_dependence_init_fields(osl_scop_p scop, osl_dependence_p dep) {
5444 +  
5445 +  osl_statement_p iter;
5446 +  candl_statement_usr_p usr;
5447 +  osl_relation_p array_s, array_t;
5448 +  
5449 +  /* source statement */
5450 +  iter = scop->statement;
5451 +  for (; iter != NULL ; iter = iter->next) {
5452 +    usr = iter->usr;
5453 +    if (usr->label == dep->label_source) {
5454 +      dep->stmt_source_ptr = iter;
5455        break;
5456      }
5457 -  for (i = 0; i < msource->NbRows && msource->p[i][0] != id; ++i)
5458 -    ;
5459 -  if (i < msource->NbRows)
5460 -    dep->ref_source = i;
5461 -  for (i = 0; i < mtarget->NbRows && mtarget->p[i][0] != id; ++i)
5462 -    ;
5463 -  if (i < mtarget->NbRows)
5464 -    dep->ref_target = i;
5465 -
5466 -  /* # Dependence domain */
5467 -  for (; *str != '\n'; ++str);
5468 -  ++str;
5469 -
5470 -  /* nb-row nb-col */
5471 -  for (i = 0; *str != ' '; ++str, ++i)
5472 -    buffer[i] = *str;
5473 -  ++str;
5474 -  buffer[i] = '\0';
5475 -  id = atoi(buffer);
5476 -  for (i = 0; *str != '\n'; ++str, ++i)
5477 -    buffer[i] = *str;
5478 -  ++str;
5479 -  buffer[i] = '\0';
5480 -  id2 = atoi(buffer);
5481 -
5482 -  dep->domain = candl_matrix_malloc(id, id2);
5483 -  /* Read matrix elements. */
5484 -  for (j = 0; j < id; ++j)
5485 -    {
5486 -    for (k = 0; k < id2; ++k)
5487 -      {
5488 -       while (*str && *str == ' ')
5489 -         str++;
5490 -       for (i = 0; *str != '\n' && *str != ' '; ++str, ++i)
5491 -         buffer[i] = *str;
5492 -       buffer[i] = '\0';
5493 -       ++str;
5494 -       CANDL_set_si(dep->domain->p[j][k], atoi(buffer));
5495 -      }
5496 -    if (*(str - 1) != '\n')
5497 -      {
5498 -       for (; *str != '\n'; ++str);
5499 -       ++str;
5500 -      }
5501 -    }
5502 -  /* Store the next character in the string to be analyzed. */
5503 -  *next = str;
5504 -
5505 -  return dep;
5506 -}
5507 -
5508 -/**
5509 - * Retrieve a CandlDependence list from the option tag in the scop.
5510 - *
5511 - */
5512 -CandlDependence* candl_dependence_read_from_scop(scoplib_scop_p scop,
5513 -                                                CandlProgram* program)
5514 -{
5515 -  CandlDependence* first = NULL;
5516 -  CandlDependence* currdep = NULL;
5517 -
5518 -  char* deps = scoplib_scop_tag_content(scop,
5519 -                                       "<dependence-polyhedra>",
5520 -                                       "</dependence-polyhedra>");
5521 -
5522 -  /* No dependence, nothing to do. */
5523 -  if (deps == NULL)
5524 -    return NULL;
5525 -
5526 -  /* Keep the starting address of the array. */
5527 -  char* base = deps;
5528 -
5529 -  int i;
5530 -  int depcount;
5531 -  /* Get the number of dependences. */
5532 -  char buffer_nb[32];
5533 -  /* # Number of dependences */
5534 -  for (; *deps != '\n'; ++deps);
5535 -  ++deps;
5536 -  for (i = 0; *deps != '\n'; ++i, ++deps)
5537 -    buffer_nb[i] = *deps;
5538 -  buffer_nb[i] = '\0';
5539 -  ++deps;
5540 -  int nbdeps = atoi (buffer_nb);
5541 -  char* next;
5542 -
5543 -  /* For each of them, read 1 and shift of the read size. */
5544 -  for (depcount = 0; depcount < nbdeps; ++depcount)
5545 -    {
5546 -      CandlDependence* adep =
5547 -       candl_dependence_read_one_dep(deps, &next, program);
5548 -      if (first == NULL)
5549 -       currdep = first = adep;
5550 -      else
5551 -       {
5552 -         currdep->next = adep;
5553 -         currdep = currdep->next;
5554 -       }
5555 -      deps = next;
5556 -    }
5557 -
5558 -  /* Be clean. */
5559 -  free(base);
5560 -
5561 -  return first;
5562 -}
5563 -
5564 -/**
5565 - * Update the scop option tag with the dependence list.
5566 - *
5567 - */
5568 -void candl_dependence_update_scop_with_deps(scoplib_scop_p scop,
5569 -                                           CandlDependence* dependence)
5570 -{
5571 -  char* start;
5572 -  char* stop;
5573 -  char* content;
5574 -  char* olddeps = NULL;
5575 -  char* newdeps;
5576 -  char* newopttags;
5577 -  char* curr;
5578 -  char* tmp;
5579 -  int size = 0;
5580 -  int size_newdeps;
5581 -  int size_olddeps = 0;
5582 -  int size_optiontags;
5583 -
5584 -  start = stop = scop->optiontags;
5585 -  /* Get the candl tag, if any. */
5586 -  content = scoplib_scop_tag_content(scop, "<candl>", "</candl>");
5587 -  if (content)
5588 -    {
5589 -      /* Get the dependence tag, if any. */
5590 -      olddeps = scoplib_scop_tag_content_from_string
5591 -       (content, "<dependence-polyhedra>", "</dependence-polyhedra>");
5592 -      /* Seek for the correct start/stop characters to insert
5593 -        dependences. */
5594 -      if (olddeps)
5595 -       {
5596 -         size = size_olddeps = strlen(olddeps);
5597 -         while (start && *start && strncmp(start, olddeps, size))
5598 -           ++start;
5599 -         stop = start + size;
5600 -       }
5601 -      else
5602 -       {
5603 -         size = strlen(content);
5604 -         while (start && *start && strncmp(start, content, size))
5605 -           ++start;
5606 -         stop = start;
5607 -       }
5608 -    }
5609 -
5610 -  /* Convert the program dependences to dotscop representation. */
5611 -  newdeps = candl_program_deps_to_string(dependence);
5612 -
5613 -  /* Compute the new size of the full options tags, and allocate a new
5614 -     string. */
5615 -  size_newdeps = newdeps ? strlen(newdeps) : 0;
5616 -  size_optiontags = scop->optiontags ? strlen(scop->optiontags) : 0;
5617 -  if (content == NULL)
5618 -    size = strlen("<candl>") + strlen("</candl>") +
5619 -      strlen("<dependence-polyhedra>")
5620 -      + strlen("</dependence-polyhedra>");
5621 -  else if (olddeps == NULL)
5622 -    size = strlen("<dependence-polyhedra>") + strlen("</dependence-polyhedra>");
5623 -  else
5624 -    size = 0;
5625 -  newopttags = (char*) malloc((size_newdeps + size_optiontags
5626 -                              - size_olddeps + size + 1)
5627 -                             * sizeof(char));
5628 -  if (newopttags == NULL)
5629 -    CANDL_FAIL("Error: memory overflow");
5630 -  curr = newopttags;
5631 -
5632 -  /* Copy the beginning of the options. */
5633 -  for (tmp = scop->optiontags; tmp != start; ++tmp)
5634 -    *(curr++) = *tmp;
5635 -  *curr = '\0';
5636 -  /* Copy the candl tags, if needed. */
5637 -  if (content == NULL)
5638 -    {
5639 -      strcat(newopttags, "<candl>\n");
5640 -      curr += strlen("<candl>\n");
5641 -    }
5642 -  if (olddeps == NULL)
5643 -    {
5644 -      strcat(newopttags, "<dependence-polyhedra>\n");
5645 -      curr += strlen("<dependence-polyhedra>\n");
5646 -    }
5647 -  /* Copy the program dependences. */
5648 -  for (tmp = newdeps; tmp && *tmp; ++tmp)
5649 -      *(curr++) = *tmp;
5650 -  *curr = '\0';
5651 -  /* Copy the candl tags, if needed. */
5652 -  if (olddeps == NULL)
5653 -    {
5654 -      strcat(curr, "</dependence-polyhedra>\n");
5655 -      curr += strlen("</dependence-polyhedra>\n");
5656 -    }
5657 -  if (content == NULL)
5658 -    {
5659 -      strcat(curr, "</candl>\n");
5660 -      curr += strlen("</candl>\n");
5661 -    }
5662 -  /* Copy the remainder of the options. */
5663 -  for (tmp = stop; tmp && *tmp; ++tmp)
5664 -      *(curr++) = *tmp;
5665 -  *curr = '\0';
5666 -
5667 -  if (scop->optiontags)
5668 -    free(scop->optiontags);
5669 -  scop->optiontags = newopttags;
5670 -
5671 -  /* Be clean. */
5672 -  if (content)
5673 -    free(content);
5674 -  if (olddeps)
5675 -    free(olddeps);
5676 -  if (newdeps)
5677 -    free(newdeps);
5678 -}
5679 -
5680 -/**
5681 - * Print the scop, containing the list of dependences.
5682 - *
5683 - */
5684 -void candl_dependence_print_scop(FILE* input, FILE* output,
5685 -                                CandlDependence* dependence)
5686 -{
5687 -  scoplib_scop_p scop;
5688 -
5689 -  /* Go to the beginning of the file. */
5690 -  rewind(input);
5691 -
5692 -  /* Re-read the options tags. */
5693 -  scop = scoplib_scop_read(input);
5694 -
5695 -  /* Embed the dependences in the scop option tag. */
5696 -  candl_dependence_update_scop_with_deps(scop, dependence);
5697 -
5698 -  /* Dump the .scop. */
5699 -  scoplib_scop_print_dot_scop(output, scop);
5700 -}
5701 -#endif
5702 -
5703 -
5704 -/******************************************************************************
5705 - *                         Memory deallocation function                       *
5706 - ******************************************************************************/
5707 -
5708 -
5709 -/* candl_dependence_free function:
5710 - * This function frees the allocated memory for a CandlDependence structure.
5711 - * - 18/09/2003: first version.
5712 - */
5713 -void candl_dependence_free(candl_dependence_p dependence)
5714 -{
5715 -  candl_dependence_p next;
5716 -
5717 -  while (dependence != NULL)
5718 -    {
5719 -      next = dependence->next;
5720 -      candl_matrix_free(dependence->domain);
5721 -      free(dependence);
5722 -      dependence = next;
5723 -    }
5724 -}
5725 -
5726 -
5727 -/******************************************************************************
5728 - *                            Processing functions                            *
5729 - ******************************************************************************/
5730 -
5731 -
5732 -/**
5733 - * candl_dependence_malloc function:
5734 - * This function allocates the memory space for a CandlDependence structure and
5735 - * sets its fields with default values. Then it returns a pointer to the
5736 - * allocated space.
5737 - * - 07/12/2005: first version.
5738 - */
5739 -candl_dependence_p candl_dependence_malloc()
5740 -{
5741 -  candl_dependence_p dependence;
5742 -
5743 -  /* Memory allocation for the CandlDependence structure. */
5744 -  dependence = (candl_dependence_p) malloc(sizeof(CandlDependence));
5745 -  if (dependence == NULL)
5746 -    CANDL_FAIL(" Error: memory overflow");
5747 -
5748 -  /* We set the various fields with default values. */
5749 -  dependence->source     = NULL;
5750 -  dependence->target     = NULL;
5751 -  dependence->depth      = CANDL_UNSET;
5752 -  dependence->type       = CANDL_UNSET;
5753 -  dependence->ref_source = CANDL_UNSET;
5754 -  dependence->ref_target = CANDL_UNSET;
5755 -  dependence->domain     = NULL;
5756 -  dependence->next       = NULL;
5757 -  dependence->usr       = NULL;
5758 -
5759 -  return dependence;
5760 -}
5761 -
5762 -
5763 -/**
5764 - * candl_dependence_add function:
5765 - * This function adds a CandlDependence structure (dependence) at a given place
5766 - * (now) of a NULL terminated list of CandlDependence structures. The beginning
5767 - * of this list is (start). This function updates (now) to the end of the loop
5768 - * list (loop), and updates (start) if the added element is the first one -that
5769 - * is when (start) is NULL-.
5770 - * - 18/09/2003: first version.
5771 - */
5772 -void candl_dependence_add(candl_dependence_p* start,
5773 -                         candl_dependence_p* now,
5774 -                         candl_dependence_p dependence)
5775 -{
5776 -  if (dependence != NULL)
5777 -    {
5778 -      if (*start == NULL)
5779 -       {
5780 -         *start = dependence;
5781 -         *now = *start;
5782 -       }
5783 -      else
5784 -       {
5785 -         (*now)->next = dependence;
5786 -         *now = (*now)->next;
5787 -       }
5788 -
5789 -      while ((*now)->next != NULL)
5790 -       *now = (*now)->next;
5791 +  }
5792 +  if (iter == NULL) {
5793 +    fprintf(stderr, "[Candl] Can't find the %dth label\n", dep->label_source);
5794 +    exit(1);
5795 +  }
5796 +  
5797 +  /* target statement */
5798 +  iter = scop->statement;
5799 +  for (; iter != NULL ; iter = iter->next) {
5800 +    usr = iter->usr;
5801 +    if (usr->label == dep->label_target) {
5802 +      dep->stmt_target_ptr = iter;
5803 +      break;
5804      }
5805 +  }
5806 +  if (iter == NULL) {
5807 +    fprintf(stderr, "[Candl] Can't find the %dth label\n", dep->label_target);
5808 +    exit(1);
5809 +  }
5810 +  
5811 +  array_s = candl_dependence_get_relation_ref_source_in_dep(dep); 
5812 +  if (array_s == NULL) {
5813 +    fprintf(stderr, "[Candl] Can't find the %dth access of the statement :\n",
5814 +            dep->ref_source);
5815 +    osl_statement_dump(stderr, dep->stmt_source_ptr);
5816 +    exit(1);
5817 +  }
5818 +  
5819 +  array_t = candl_dependence_get_relation_ref_source_in_dep(dep);
5820 +  if (array_t == NULL) {
5821 +    fprintf(stderr, "[Candl] Can't find the %dth access of the statement :\n",
5822 +            dep->ref_target);
5823 +    osl_statement_dump(stderr, dep->stmt_target_ptr);
5824 +    exit(1);
5825 +  }
5826 +  
5827 +  dep->source_nb_output_dims_domain = dep->stmt_source_ptr->domain->nb_output_dims;
5828 +  dep->source_nb_output_dims_access = array_s->nb_output_dims;
5829 +  
5830 +  dep->target_nb_output_dims_domain = dep->stmt_target_ptr->domain->nb_output_dims;
5831 +  dep->target_nb_output_dims_access = array_t->nb_output_dims;
5832 +  
5833 +  dep->source_nb_local_dims_domain  = dep->stmt_source_ptr->domain->nb_local_dims;
5834 +  dep->source_nb_local_dims_access  = array_s->nb_local_dims;
5835 +  dep->target_nb_local_dims_domain  = dep->stmt_target_ptr->domain->nb_local_dims;
5836 +  dep->target_nb_local_dims_access  = array_t->nb_local_dims;
5837  }
5838  
5839  
5840  /**
5841   * GCD computation.
5842   */
5843 -static
5844 -int
5845 -candl_dependence_gcd(int a, int b)
5846 -{
5847 +static int candl_dependence_gcd(int a, int b) {
5848    int z = 1;
5849  
5850    if (a < 0)
5851 @@ -870,19 +323,17 @@ candl_dependence_gcd(int a, int b)
5852      return b;
5853    if (b == 0)
5854      return a;
5855 -  if (b > a)
5856 -    {
5857 -      int temp = a;
5858 -      a = b;
5859 -      b = temp;
5860 -    }
5861 +  if (b > a) {
5862 +    int temp = a;
5863 +    a = b;
5864 +    b = temp;
5865 +  }
5866  
5867 -  while (z != 0)
5868 -    {
5869 -      z = a % b;
5870 -      a = b;
5871 -      b = z;
5872 -    }
5873 +  while (z != 0) {
5874 +    z = a % b;
5875 +    a = b;
5876 +    b = z;
5877 +  }
5878  
5879    return a;
5880  }
5881 @@ -891,9 +342,7 @@ candl_dependence_gcd(int a, int b)
5882   *
5883   *
5884   */
5885 -static
5886 -int candl_dependence_gcd_test_context (CandlMatrix* system, int id)
5887 -{
5888 +static int candl_dependence_gcd_test_context(osl_relation_p system, int id) {
5889    /* FIXME: implement me! */
5890  
5891    return 1;
5892 @@ -915,16 +364,18 @@ int candl_dependence_gcd_test_context (CandlMatrix* system, int id)
5893   * are also performed before the actual GCD test.
5894   *
5895   */
5896 -int candl_dependence_gcd_test(CandlStatement* source,
5897 -                             CandlStatement* target,
5898 -                             CandlMatrix* system,
5899 -                             int level)
5900 -{
5901 +int candl_dependence_gcd_test(osl_statement_p source,
5902 +                              osl_statement_p target,
5903 +                              osl_relation_p system,
5904 +                              int level) {
5905    int i;
5906    int gcd;
5907    int id;
5908    int value;
5909    int null_iter, null_param, null_cst, pos_iter, neg_iter;
5910 +  int precision = source->domain->precision;
5911 +  candl_statement_usr_p s_usr = source->usr;
5912 +  candl_statement_usr_p t_usr = target->usr;
5913  
5914    /* Check that the precedence constraint, if any, is not strict in a
5915       self-dependence. */
5916 @@ -937,59 +388,63 @@ int candl_dependence_gcd_test(CandlStatement* source,
5917    /*   strict_pred = 0; */
5918  
5919    /* Inspect the array access function equalities. */
5920 -  for (id = source->domain->NbRows + target->domain->NbRows;
5921 -       id < system->NbRows && CANDL_get_si(system->p[id][0]) == 0; ++id)
5922 -    {
5923 -      /* Inspect which parts of the access function equality are null,
5924 -        positive or negative. */
5925 -      null_iter = null_param = null_cst = pos_iter = neg_iter = 0;
5926 -      for (i = 1; i < source->depth + target->depth + 1 &&
5927 -            CANDL_get_si(system->p[id][i]) == 0; ++i)
5928 -       ;
5929 -      if (i == source->depth + target->depth + 1)
5930 -       null_iter = 1;
5931 -      else
5932 -       for (pos_iter = 1, neg_iter = 1;
5933 -            i < source->depth + target->depth + 1; ++i)
5934 -         {
5935 -           if (CANDL_get_si(system->p[id][i]) < 0)
5936 -             pos_iter = 0;
5937 -           else if (CANDL_get_si(system->p[id][i]) > 0)
5938 -             neg_iter = 0;
5939 -         }
5940 -      for (; i < system->NbColumns - 1 && CANDL_get_si(system->p[id][i]) == 0;
5941 -          ++i)
5942 -       ;
5943 -      if (i == system->NbColumns - 1)
5944 -       null_param = 1;
5945 -      null_cst = ! CANDL_get_si(system->p[id][system->NbColumns - 1]);
5946 -
5947 -      /* Some useful ZIV/SIV/MIV tests. */
5948 -      if (null_iter && null_param && !null_cst)
5949 -       return 0;
5950 -      if (null_iter)
5951 -       if (! candl_dependence_gcd_test_context (system, id))
5952 -         return 0;
5953 -      if (null_cst || !null_param)
5954 -       continue;
5955 -/* FIXME: implement the loop bound check. */
5956 -/*       /\* A clever test on access bounds. *\/ */
5957 -/*       if (null_param && pos_iter &&  */
5958 -/*       CANDL_get_si(system->p[id][system->NbColumns - 1]) > 0) */
5959 -/*     return 0; */
5960 -/*       if (null_param && neg_iter &&  */
5961 -/*       CANDL_get_si(system->p[id][system->NbColumns - 1]) < 0) */
5962 -/*     return 0; */
5963 -
5964 -      /* Compute GCD test for the array access equality. */
5965 -      for (i = 1, gcd = CANDL_get_si(system->p[id][i]);
5966 -          i < source->depth + target->depth; ++i)
5967 -       gcd = candl_dependence_gcd(gcd, CANDL_get_si(system->p[id][i + 1]));
5968 -      value = CANDL_get_si(system->p[id][system->NbColumns - 1]);
5969 -      value = value < 0 ? -value : value;
5970 -      if ((gcd == 0 && value != 0) || value % gcd)
5971 -       return 0;
5972 -    }
5973 +  for (id = source->domain->nb_rows + target->domain->nb_rows;
5974 +       id < system->nb_rows && 
5975 +       osl_int_zero(precision, system->m[id][0]);
5976 +       ++id) {
5977 +    /* Inspect which parts of the access function equality are null,
5978 +       positive or negative. */
5979 +    null_iter = null_param = null_cst = pos_iter = neg_iter = 0;
5980 +    
5981 +    for (i = 1; i < s_usr->depth + t_usr->depth + 1 &&
5982 +         osl_int_zero(precision, system->m[id][i]); ++i)
5983 +     ;
5984 +     
5985 +    if (i == s_usr->depth + t_usr->depth + 1)
5986 +      null_iter = 1;
5987 +    else
5988 +      for (pos_iter = 1, neg_iter = 1;
5989 +           i < s_usr->depth + t_usr->depth + 1; ++i) {
5990 +        if (osl_int_neg(precision, system->m[id][i]))
5991 +          pos_iter = 0;
5992 +        else if (osl_int_pos(precision, system->m[id][i]))
5993 +          neg_iter = 0;
5994 +      }
5995 +    for (; i < system->nb_columns - 1 && 
5996 +         osl_int_zero(precision, system->m[id][i]) == 0; ++i)
5997 +     ;
5998 +    if (i == system->nb_columns - 1)
5999 +      null_param = 1;
6000 +    null_cst = osl_int_zero(precision, system->m[id][system->nb_columns - 1]);
6001 +
6002 +    /* Some useful ZIV/SIV/MIV tests. */
6003 +    if (null_iter && null_param && !null_cst)
6004 +      return 0;
6005 +    if (null_iter)
6006 +      if (! candl_dependence_gcd_test_context(system, id))
6007 +        return 0;
6008 +    if (null_cst || !null_param)
6009 +      continue;
6010 +    /* FIXME: implement the loop bound check. */
6011 +    /*       /\* A clever test on access bounds. *\/ */
6012 +    /*       if (null_param && pos_iter &&  */
6013 +    /*           CANDL_get_si(system->p[id][system->NbColumns - 1]) > 0) */
6014 +    /*         return 0; */
6015 +    /*       if (null_param && neg_iter &&  */
6016 +    /*           CANDL_get_si(system->p[id][system->NbColumns - 1]) < 0) */
6017 +    /*         return 0; */
6018 +
6019 +    /* Compute GCD test for the array access equality. */
6020 +    for (i = 1, gcd = osl_int_get_si(precision, system->m[id][i]);
6021 +         i < s_usr->depth + t_usr->depth; ++i)
6022 +      gcd = candl_dependence_gcd(gcd,
6023 +        osl_int_get_si(precision, system->m[id][i + 1]));
6024 +
6025 +    value = osl_int_get_si(precision, system->m[id][system->nb_columns - 1]);
6026 +    value = value < 0 ? -value : value;
6027 +    if ((gcd == 0 && value != 0) || value % gcd)
6028 +      return 0;
6029 +  }
6030  
6031    return 1;
6032  }
6033 @@ -1006,135 +461,243 @@ int candl_dependence_gcd_test(CandlStatement* source,
6034   * See the [bastoul and Feautrier, PPL 2005] paper for details !
6035   * - source is the source iteration domain,
6036   * - target is the target iteration domain,
6037 - * - array_s is the array list for the source,
6038 - * - array_t is the array list for the target,
6039 - * - ref_s is the position of the source reference in array_s,
6040 - * - ref_s is the position of the target reference in array_t,
6041 + * - array_s is the access array for the source,
6042 + * - array_t is the access array for the target,
6043   * - depth is the dependence depth,
6044   * - before is 1 if the source is textually before the target, 0 otherwise,
6045 - * - nb_par is the number of parameters.
6046   ***
6047   * - 13/12/2005: first version (extracted from candl_dependence_system).
6048   * - 23/02/2006: a stupid bug corrected in the subscript equality.
6049   * - 07/04/2007: fix the precedence condition to respect C. Bastoul PhD thesis
6050   */
6051 -static
6052 -CandlMatrix * candl_dependence_build_system(source, target, array_s, array_t,
6053 -                                           ref_s, ref_t, depth, before, nb_par)
6054 -CandlStatement  * source, * target;
6055 -CandlMatrix * array_s, * array_t ;
6056 -int ref_s, ref_t, depth, before, nb_par ;
6057 -{ int i, j, nb_rows, nb_columns, nb_dimensions, constraint, s_dims, t_dims ;
6058 -  CandlMatrix * system ;
6059 -  Entier temp ;
6060 -
6061 -  CANDL_init(temp) ;
6062 -
6063 -  /* We calculate the number of dimensions of the considered array. */
6064 -  nb_dimensions = 1;
6065 -  while (((ref_s + nb_dimensions + 1) <= array_s->NbRows) &&
6066 -         (array_s->p[ref_s + nb_dimensions][0] == 0))
6067 -  nb_dimensions ++ ;
6068 -
6069 -  /* The number of dimensions of the source and target domains. */
6070 -  s_dims = source->domain->NbColumns - nb_par - 2 ;
6071 -  t_dims = target->domain->NbColumns - nb_par - 2 ;
6072 -
6073 -  /* The number of rows of the system is:
6074 -   * - the number of constraints of the source iteration domain +
6075 -   * - the number of constraints of the target iteration domain +
6076 -   * - the number of dimensions of the considered array (subscript equality) +
6077 -   * - the number of precedence constraints (equal to depth).
6078 -   */
6079 -  nb_rows = source->domain->NbRows + target->domain->NbRows +
6080 -    nb_dimensions + depth ;
6081 -
6082 -  /* The number of columns of the system is:
6083 -   * - the number of source statement surrounding loops +
6084 -   * - the number of target statement surrounding loops +
6085 -   * - the number of parameters +
6086 -   * - 2 (1 for equality/inequality identifier + 1 for the constant).
6087 -   */
6088 -  nb_columns = s_dims + t_dims + nb_par + 2 ;
6089 -
6090 -  /* We allocate memory space for the constraint system. */
6091 -  system = candl_matrix_malloc(nb_rows,nb_columns) ;
6092 -
6093 -  /* Compute the maximal common depth. */
6094 +static osl_dependence_p candl_dependence_build_system(
6095 +                            osl_statement_p source, osl_statement_p target,
6096 +                            osl_relation_p array_s, osl_relation_p array_t,
6097 +                            int depth, int before) {
6098 +  osl_dependence_p dependence;
6099 +  osl_relation_p system;
6100 +  int i, j, k, c;
6101 +  int constraint = 0;
6102 +  int precision = source->domain->precision;
6103 +  int nb_output_dims; // source column
6104 +  int nb_input_dims;  // target column
6105 +  int nb_local_dims;
6106 +  int nb_par;
6107 +  int nb_rows, nb_columns;
6108 +  int ind_source_local_domain;
6109 +  int ind_source_local_access;
6110 +  int ind_target_local_domain;
6111 +  int ind_target_local_access;
6112 +  int ind_params;
6113    int min_depth = 0;
6114 -  while (min_depth < source->depth && min_depth < target->depth &&
6115 -        source->index[min_depth] == target->index[min_depth])
6116 -    ++min_depth;
6117 -
6118 -  /* We fill the constraint system (note that there is no need to put zeros
6119 -   * in the empty zones since candl_matrix_alloc initialized all entries to 0):
6120 -   */
6121 -
6122 -  /* 1. The source iteration domain constraints. */
6123 -  constraint = 0 ;
6124 -  for (i=0;i<source->domain->NbRows;i++)
6125 -  { for (j=0;j<=s_dims;j++)
6126 -    CANDL_assign(system->p[constraint][j],source->domain->p[i][j]) ;
6127 -
6128 -    for (j=s_dims+1;j<source->domain->NbColumns;j++)
6129 -    CANDL_assign(system->p[constraint][j+t_dims],source->domain->p[i][j]) ;
6130 -
6131 -    constraint++ ;
6132 +  
6133 +  /* Create a new dependence structure */
6134 +  dependence = osl_dependence_malloc();
6135 +  
6136 +  /* Compute the maximal common depth. */
6137 +  min_depth = CANDL_min(array_s->nb_output_dims, array_t->nb_output_dims);
6138 +  
6139 +  /* Compute the system size */
6140 +  dependence->source_nb_output_dims_domain = source->domain->nb_output_dims;
6141 +  dependence->source_nb_output_dims_access = array_s->nb_output_dims;
6142 +  
6143 +  dependence->target_nb_output_dims_domain = target->domain->nb_output_dims;
6144 +  dependence->target_nb_output_dims_access = array_t->nb_output_dims;
6145 +  
6146 +  dependence->source_nb_local_dims_domain  = source->domain->nb_local_dims;
6147 +  dependence->source_nb_local_dims_access  = array_s->nb_local_dims;
6148 +  dependence->target_nb_local_dims_domain  = target->domain->nb_local_dims;
6149 +  dependence->target_nb_local_dims_access  = array_t->nb_local_dims;
6150 +    
6151 +  nb_par         = source->domain->nb_parameters;
6152 +  nb_local_dims  = dependence->source_nb_local_dims_domain +
6153 +                   dependence->source_nb_local_dims_access +
6154 +                   dependence->target_nb_local_dims_domain +
6155 +                   dependence->target_nb_local_dims_access;
6156 +  nb_output_dims = dependence->source_nb_output_dims_domain +
6157 +                   dependence->source_nb_output_dims_access;
6158 +  nb_input_dims  = dependence->target_nb_output_dims_domain +
6159 +                   dependence->target_nb_output_dims_access;
6160 +
6161 +  nb_columns = nb_output_dims + nb_input_dims + nb_local_dims + nb_par + 2;
6162 +  nb_rows    = source->domain->nb_rows + target->domain->nb_rows +
6163 +               array_s->nb_rows + array_t->nb_rows +
6164 +               min_depth + 
6165 +               depth;
6166 +
6167 +  system = osl_relation_pmalloc(precision, nb_rows, nb_columns);
6168 +  
6169 +  /* Compute some indexes */
6170 +  ind_source_local_domain = 1 + nb_output_dims + nb_input_dims;
6171 +  ind_source_local_access = ind_source_local_domain + dependence->source_nb_local_dims_domain;
6172 +  ind_target_local_domain = ind_source_local_access + dependence->source_nb_local_dims_access;
6173 +  ind_target_local_access = ind_target_local_domain + dependence->target_nb_local_dims_domain;
6174 +  ind_params              = ind_target_local_access + dependence->target_nb_local_dims_access;
6175 +  
6176 +  /* 1. Copy the source domain */
6177 +  for (i = 0 ; i < source->domain->nb_rows ; i++) {
6178 +    /* eq/in */
6179 +    osl_int_assign(precision,
6180 +                   &system->m[constraint][0], source->domain->m[i][0]);
6181 +    /* output dims */
6182 +    k = 1;
6183 +    j = 1;
6184 +    for (c = source->domain->nb_output_dims ; c > 0 ; c--, k++, j++)
6185 +      osl_int_assign(precision,
6186 +                     &system->m[constraint][k], source->domain->m[i][j]);
6187 +    /* local dims (no input in domain, so j is the same) */
6188 +    k = ind_source_local_domain;
6189 +    for (c = source->domain->nb_local_dims ; c > 0 ; c--, k++, j++)
6190 +      osl_int_assign(precision,
6191 +                     &system->m[constraint][k], source->domain->m[i][j]);
6192 +    /* params + const */
6193 +    k = ind_params;
6194 +    for (c = nb_par+1 ; c > 0 ; c--, k++, j++)
6195 +      osl_int_assign(precision,
6196 +                     &system->m[constraint][k], source->domain->m[i][j]);
6197 +    constraint++;
6198    }
6199 -
6200 -  /* 2. The target iteration domain constraints. */
6201 -  for (i = 0; i < target->domain->NbRows; i++)
6202 -  { CANDL_assign(system->p[constraint][0],target->domain->p[i][0]) ;
6203 -
6204 -    for (j = 1; j < target->domain->NbColumns; j++)
6205 -    CANDL_assign(system->p[constraint][j + s_dims], target->domain->p[i][j]) ;
6206 -
6207 -    constraint++ ;
6208 +  
6209 +  /* 2. Copy the target domain */
6210 +  for (i = 0 ; i < target->domain->nb_rows ; i++) {
6211 +    /* eq/in */
6212 +    osl_int_assign(precision,
6213 +                   &system->m[constraint][0], target->domain->m[i][0]);
6214 +    /* output dims */
6215 +    k = 1 + nb_output_dims;
6216 +    j = 1;
6217 +    for (c = target->domain->nb_output_dims ; c > 0 ; c--, k++, j++)
6218 +      osl_int_assign(precision,
6219 +                     &system->m[constraint][k], target->domain->m[i][j]);
6220 +    /* local dims (no input in domain, so j is the same) */
6221 +    k = ind_target_local_domain;
6222 +    for (c = target->domain->nb_local_dims ; c > 0 ; c--, k++, j++)
6223 +      osl_int_assign(precision,
6224 +                     &system->m[constraint][k], target->domain->m[i][j]);
6225 +    /* params + const */
6226 +    k = ind_params;
6227 +    for (c = nb_par+1 ; c > 0 ; c--, k++, j++)
6228 +      osl_int_assign(precision,
6229 +                     &system->m[constraint][k], target->domain->m[i][j]);
6230 +    constraint++;
6231    }
6232 -
6233 -  int subeq = 0;
6234 -
6235 -  /* 3. The equality of the subscripts. */
6236 -  for (i = 0; i < nb_dimensions; i++)
6237 -  { /* Source iterator coefficients part. */
6238 -    for (j = 1; j <= s_dims; j++)
6239 -    CANDL_assign(system->p[constraint][j], array_s->p[ref_s + i][j]) ;
6240 -
6241 -    /* Target iterator coefficients part (negative). */
6242 -    for (j = 1; j <= t_dims; j++)
6243 -    { CANDL_oppose(temp, array_t->p[ref_t + i][j]) ;
6244 -      CANDL_assign(system->p[constraint][j + s_dims], temp) ;
6245 +  
6246 +  /* 3. Copy the source access */
6247 +  for (i = 0 ; i < array_s->nb_rows ; i++) {
6248 +    /* eq/in */
6249 +    osl_int_assign(precision,
6250 +                   &system->m[constraint][0], array_s->m[i][0]);
6251 +    /* output dims */
6252 +    k = 1 + source->domain->nb_output_dims;
6253 +    j = 1;
6254 +    for (c = array_s->nb_output_dims ; c > 0 ; c--, k++, j++)
6255 +      osl_int_assign(precision,
6256 +                     &system->m[constraint][k], array_s->m[i][j]);
6257 +    /* link input dims access to the output dims domain */
6258 +    k = 1;
6259 +    for (c = array_s->nb_input_dims ; c > 0 ; c--, k++, j++)
6260 +      osl_int_assign(precision,
6261 +                     &system->m[constraint][k], array_s->m[i][j]);
6262 +    /* local dims */
6263 +    k = ind_source_local_access;
6264 +    for (c = array_s->nb_local_dims ; c > 0 ; c--, k++, j++)
6265 +      osl_int_assign(precision,
6266 +                     &system->m[constraint][k], array_s->m[i][j]);
6267 +    /* params + const */
6268 +    k = ind_params;
6269 +    for (c = nb_par+1 ; c > 0 ; c--, k++, j++)
6270 +      osl_int_assign(precision,
6271 +                     &system->m[constraint][k], array_s->m[i][j]);
6272 +    
6273 +    constraint++;
6274 +  }
6275 +  
6276 +  /* 4. Copy the target access */
6277 +  for (i = 0 ; i < array_t->nb_rows ; i++) {
6278 +    /* eq/in */
6279 +    osl_int_assign(precision,
6280 +                   &system->m[constraint][0], array_t->m[i][0]);
6281 +    /* output dims */
6282 +    k = 1 + nb_output_dims + target->domain->nb_output_dims;
6283 +    j = 1;
6284 +    for (c = array_t->nb_output_dims ; c > 0 ; c--, k++, j++) {
6285 +      osl_int_assign(precision,
6286 +                     &system->m[constraint][k], array_t->m[i][j]);
6287 +      osl_int_oppose(precision,
6288 +                     &system->m[constraint][k], system->m[constraint][k]);
6289      }
6290 -
6291 -    /* Parameters and constant coefficients part. */
6292 -    for (j = 1; j <= nb_par + 1; j++)
6293 -    CANDL_subtract(system->p[constraint][j + s_dims + t_dims],
6294 -                    array_s->p[ref_s + i][j + s_dims],
6295 -                    array_t->p[ref_t + i][j + t_dims]) ;
6296 -    constraint++ ;
6297 -    subeq++;
6298 +    /* link input dims access to the output dims domain */
6299 +    k = 1 + nb_output_dims;
6300 +    for (c = array_t->nb_input_dims ; c > 0 ; c--, k++, j++) {
6301 +      osl_int_assign(precision,
6302 +                     &system->m[constraint][k], array_t->m[i][j]);
6303 +      osl_int_oppose(precision,
6304 +                     &system->m[constraint][k], system->m[constraint][k]);
6305 +    }
6306 +    /* local dims */
6307 +    k = ind_target_local_access;
6308 +    for (c = array_t->nb_local_dims ; c > 0 ; c--, k++, j++) {
6309 +      osl_int_assign(precision,
6310 +                     &system->m[constraint][k], array_t->m[i][j]);
6311 +      osl_int_oppose(precision,
6312 +                     &system->m[constraint][k], system->m[constraint][k]);
6313 +    }
6314 +    /* params + const */
6315 +    k = ind_params;
6316 +    for (c = nb_par+1 ; c > 0 ; c--, k++, j++) {
6317 +      osl_int_assign(precision,
6318 +                     &system->m[constraint][k], array_t->m[i][j]);
6319 +      osl_int_oppose(precision,
6320 +                     &system->m[constraint][k], system->m[constraint][k]);
6321 +    }
6322 +    constraint++;
6323    }
6324 -
6325 -  /* 4. The precedence constraints (their number is equal to depth). */
6326 -  for (i = 0; i < depth; i++)
6327 -  { /* i = i' for all dimension less than depth. */
6328 -    CANDL_set_si(system->p[constraint][i + 1], -1) ;
6329 -    CANDL_set_si(system->p[constraint][s_dims + i + 1], 1) ;
6330 -    if (i == depth - 1)
6331 -      {
6332 -       /* i <= i' at dimension depth if source is textually before target. */
6333 -       CANDL_set_si(system->p[constraint][0], 1) ;
6334 -       /* If source is textually after target, this is obviously i < i'. */
6335 -       if (before || depth < min_depth)
6336 -         //if (before)
6337 -         CANDL_set_si(system->p[constraint][nb_columns - 1], -1);
6338 -      }
6339 -
6340 -    constraint++ ;
6341 +  
6342 +  
6343 +  /* 5. Set the equality between the output access */
6344 +  /* Note here that the equality between the 2 Arr are necessarily equal */
6345 +  k = 1 + source->domain->nb_output_dims;
6346 +  j = 1 + nb_output_dims + target->domain->nb_output_dims;
6347 +  for (i = 0 ; i < min_depth ; i++, k++, j++) {
6348 +    osl_int_set_si(precision, &system->m[constraint][k], -1);
6349 +    osl_int_set_si(precision, &system->m[constraint][j], 1);
6350 +    constraint++;
6351    }
6352 +  
6353 +  /* 6. The precedence constraints */
6354 +  int min_dim = 0;
6355 +  while (min_dim < ((candl_statement_usr_p)source->usr)->depth && 
6356 +         min_dim < ((candl_statement_usr_p)target->usr)->depth &&
6357 +         ((candl_statement_usr_p)source->usr)->index[min_dim] ==
6358 +         ((candl_statement_usr_p)target->usr)->index[min_dim])
6359 +    ++min_dim;
6360 +
6361 +  k = 1;
6362 +  j = 1 + nb_output_dims;
6363 +  for (i = 0; i < depth; i++, k++, j++) {
6364 +    /* i = i' for all dimension less than depth. */
6365 +    osl_int_set_si(precision, &system->m[constraint][k], -1);
6366 +    osl_int_set_si(precision, &system->m[constraint][j], 1);
6367 +    if (i == depth - 1) {
6368 +      /* i <= i' at dimension depth if source is textually before target. */
6369 +      osl_int_set_si(precision, &system->m[constraint][0], 1);
6370 +      /* If source is textually after target, this is obviously i < i'. */
6371 +      if (before || depth < min_dim) // sub 1 for the Arr dim
6372 +        osl_int_set_si(precision, &system->m[constraint][nb_columns - 1], -1);
6373 +    }
6374  
6375 -  CANDL_clear(temp) ;
6376 -  return system ;
6377 +    constraint++;
6378 +  }
6379 +  
6380 +  system->nb_output_dims = nb_output_dims;
6381 +  system->nb_input_dims = nb_input_dims;
6382 +  system->nb_parameters = nb_par;
6383 +  system->nb_local_dims = nb_local_dims;
6384 +  system->type = OSL_UNDEFINED;
6385 +  
6386 +  dependence->domain = system;
6387 +  
6388 +  return dependence; 
6389  }
6390  
6391  
6392 @@ -1157,49 +720,53 @@ int ref_s, ref_t, depth, before, nb_par ;
6393   * - 18/09/2003: first version.
6394   * - 09/12/2005: few corrections and polishing.
6395   */
6396 -candl_dependence_p candl_dependence_system(CandlStatement* source,
6397 -                                          CandlStatement* target,
6398 -                                          CandlMatrix* context,
6399 -                                          CandlMatrix* array_s,
6400 -                                          CandlMatrix* array_t,
6401 -                                          int ref_s, int ref_t,
6402 -                                          int type, int depth)
6403 -{
6404 -  candl_dependence_p dependence = NULL;
6405 -  CandlMatrix * system;
6406 +osl_dependence_p candl_dependence_system(osl_statement_p source,
6407 +                                           osl_statement_p target,
6408 +                                           osl_relation_p context,
6409 +                                           osl_relation_p array_s,
6410 +                                           osl_relation_p array_t,
6411 +                                           int ref_s, int ref_t,
6412 +                                           int type, int depth) {
6413 +  candl_statement_usr_p s_usr = source->usr;
6414 +  candl_statement_usr_p t_usr = target->usr;
6415 +  osl_dependence_p dependence = NULL;
6416  
6417    /* First, a trivial case: for two different statements at depth 0, there is
6418     * a dependence only if the source is textually before the target.
6419     */
6420 -  if ((source != target) && (depth == 0) && (source->label > target->label))
6421 +  if ((source != target) && (depth == 0) && 
6422 +      (s_usr->label > t_usr->label))
6423      return NULL;
6424 -
6425 +    
6426    /* We build the system of constraints. */
6427 -  system = candl_dependence_build_system(source,  target,
6428 -                                        array_s, array_t, ref_s, ref_t,
6429 -                                        depth,
6430 -                                        (source->label >= target->label),
6431 -                                        context->NbColumns-2);
6432 +  dependence = candl_dependence_build_system(source,  target,
6433 +                                             array_s, array_t, 
6434 +                                             depth,
6435 +                                             (s_usr->label >= 
6436 +                                              t_usr->label));
6437  
6438    /* We start by simple SIV/ZIV/GCD tests. */
6439 -  if (! candl_dependence_gcd_test(source, target, system, depth))
6440 +  if (!candl_dependence_gcd_test(source, target, dependence->domain, depth)) {
6441 +    osl_dependence_free(dependence);
6442      return NULL;
6443 +  }
6444  
6445 -  if (pip_has_rational_point (system, context, 1))
6446 -    {
6447 -      dependence = candl_dependence_malloc();
6448 -
6449 -      /* We set the various fields with corresponding values. */
6450 -      dependence->type       = type;
6451 -      dependence->depth      = depth;
6452 -      dependence->source     = source;
6453 -      dependence->target     = target;
6454 -      dependence->ref_source = ref_s;
6455 -      dependence->ref_target = ref_t;
6456 -      dependence->domain     = system;
6457 -    }
6458 -  else
6459 -    candl_matrix_free(system);
6460 +  if (pip_has_rational_point(dependence->domain, context, 1)) {
6461 +    /* We set the various fields with corresponding values. */
6462 +    dependence->ref_source = ref_s;
6463 +    dependence->ref_target = ref_t;      
6464 +    dependence->label_source = ((candl_statement_usr_p)source->usr)->label;
6465 +    dependence->label_target = ((candl_statement_usr_p)target->usr)->label;
6466 +    dependence->type  = type;
6467 +    dependence->depth = depth;
6468 +    dependence->stmt_source_ptr       = source;
6469 +    dependence->stmt_target_ptr       = target;
6470 +    dependence->ref_source_access_ptr = array_s;
6471 +    dependence->ref_target_access_ptr = array_t;
6472 +  } else {
6473 +    osl_dependence_free(dependence);
6474 +    dependence = NULL;
6475 +  }
6476  
6477    return dependence;
6478  }
6479 @@ -1215,20 +782,25 @@ candl_dependence_p candl_dependence_system(CandlStatement* source,
6480   * - 07/12/2005: (debug) correction of depth bounds.
6481   * - 09/12/2005: We may take commutativity into consideration.
6482   */
6483 -candl_dependence_p candl_dependence_between(CandlStatement* source,
6484 -                                           CandlStatement* target,
6485 -                                           CandlMatrix* context,
6486 -                                           CandlOptions* options)
6487 -{
6488 -  int i, j, k, min_depth, max_depth;
6489 -  candl_dependence_p new;
6490 -  candl_dependence_p dependence = NULL;
6491 -  candl_dependence_p now;
6492 -
6493 +osl_dependence_p candl_dependence_between(osl_statement_p source,
6494 +                                            osl_statement_p target,
6495 +                                            osl_relation_p context,
6496 +                                            candl_options_p options) {
6497 +  osl_dependence_p new;
6498 +  osl_dependence_p dependence = NULL;
6499 +  osl_dependence_p now;
6500 +  osl_relation_list_p access_src, access_targ;
6501 +  osl_relation_p elt_src, elt_targ;
6502 +  candl_statement_usr_p s_usr = source->usr;
6503 +  candl_statement_usr_p t_usr = target->usr;
6504 +  int i, min_depth, max_depth;
6505 +  int src_id, targ_id;
6506 +  int ref_s, ref_t;
6507 +  
6508    /* If the statements commute and the user asks to use this information to
6509     * simplify the dependence graph, we return no dependences.
6510     */
6511 -  if (options->commute && candl_statement_commute(source, target))
6512 +  if (options->commute && candl_util_statement_commute(source, target))
6513      return NULL;
6514  
6515    /* In the case of a self-dependence, the dependence depth can be as low as 1
6516 @@ -1237,155 +809,209 @@ candl_dependence_p candl_dependence_between(CandlStatement* source,
6517     * In the case of different statements, the dependence depth can be as low
6518     * as 0 and as high as the number of shared loops.
6519     */
6520 -  if (source == target)
6521 -    {
6522 -      min_depth = 1;
6523 -      max_depth = source->depth;
6524 -    }
6525 -  else
6526 -    {
6527 -      /* Depth 0 is for statements that don't share any loop. */
6528 -      min_depth = (source->index[0] == target->index[0]) ? 1 : 0;
6529 -
6530 -      max_depth = 0;
6531 -      while ((max_depth < source->depth) &&
6532 -            (max_depth < target->depth) &&
6533 -            (source->index[max_depth] == target->index[max_depth]))
6534 -       max_depth++;
6535 -    }
6536 -
6537 -  /* Flow and output-dependences analysis. */
6538 -  for (j = 0; j < source->written->NbRows; j++)
6539 -    if (CANDL_notzero_p(source->written->p[j][0]))
6540 -      {
6541 -       /* Flow-dependences analysis. */
6542 -       if (options->raw)
6543 -         for (k = 0; k < target->read->NbRows; k++)
6544 -           if (CANDL_eq(target->read->p[k][0], source->written->p[j][0]))
6545 -             for (i = min_depth; i <= max_depth; i++)
6546 -               {
6547 -                 new = candl_dependence_system(source, target, context,
6548 -                                               source->written, target->read,
6549 -                                               j, k, CANDL_RAW, i);
6550 -                 candl_dependence_add(&dependence, &now, new);
6551 -               }
6552 -       /* Output-dependences analysis. */
6553 -       if (options->waw)
6554 -         for (k = 0; k < target->written->NbRows; k++)
6555 -           if (CANDL_eq(target->written->p[k][0], source->written->p[j][0]))
6556 -             for (i = min_depth; i <= max_depth; i++)
6557 -               {
6558 -                 new = candl_dependence_system(source, target, context,
6559 -                                               source->written,
6560 -                                               target->written, j, k,
6561 -                                               CANDL_WAW, i);
6562 -                 candl_dependence_add(&dependence, &now, new);
6563 -               }
6564 -      }
6565 -
6566 -  /* Anti and input-dependences analysis. */
6567 -  for (j = 0; j < source->read->NbRows; j++)
6568 -    if (source->read->p[j][0] != 0)
6569 -      {
6570 -       /* Anti-dependences analysis. */
6571 -       if (options->war)
6572 -         for (k = 0; k < target->written->NbRows; k++)
6573 -           if (CANDL_eq(target->written->p[k][0], source->read->p[j][0]))
6574 -             for (i = min_depth; i <= max_depth; i++)
6575 -               {
6576 -                 new = candl_dependence_system(source, target, context,
6577 -                                               source->read, target->written,
6578 -                                               j, k, CANDL_WAR, i);
6579 -                 candl_dependence_add(&dependence, &now, new);
6580 -               }
6581 -       /* Input-dependences analysis. */
6582 -       if (options->rar)
6583 -         for (k = 0; k < target->read->NbRows; k++)
6584 -           if (CANDL_eq(target->read->p[k][0], source->read->p[j][0]))
6585 -             for (i = min_depth; i <= max_depth; i++)
6586 -               {
6587 -                 new = candl_dependence_system(source, target, context,
6588 -                                               source->read, target->read,
6589 -                                               j, k, CANDL_RAR, i);
6590 -                 candl_dependence_add(&dependence, &now, new);
6591 -               }
6592 -      }
6593 +  if (source == target) {
6594 +    min_depth = 1;
6595 +    max_depth = s_usr->depth;
6596 +  } else {
6597 +    /* Depth 0 is for statements that don't share any loop. */
6598 +    if (s_usr->depth > 0 && t_usr->depth > 0)
6599 +      min_depth = (s_usr->index[0] == t_usr->index[0]) ? 1 : 0;
6600 +    else
6601 +      min_depth = 0;
6602  
6603 +    max_depth = 0;
6604 +    while ((max_depth < s_usr->depth) &&
6605 +           (max_depth < t_usr->depth) &&
6606 +           (s_usr->index[max_depth] == t_usr->index[max_depth]))
6607 +      max_depth++;
6608 +  }
6609 +  
6610 +  ref_s = 0;
6611 +  access_src = source->access;
6612 +  
6613 +  for (; access_src != NULL; access_src = access_src->next, ref_s++) {
6614 +    elt_src = access_src->elt;
6615 +    src_id = osl_relation_get_array_id(elt_src);
6616 +    
6617 +    switch(elt_src->type) {
6618 +    
6619 +      /* Anti and input-dependences analysis. */
6620 +      case OSL_TYPE_READ: /* source READ */
6621 +        if (!options->war && !options->rar)
6622 +          break;
6623 +        access_targ = target->access;
6624 +        ref_t = 0;
6625 +        for (; access_targ != NULL; access_targ = access_targ->next, ref_t++) {
6626 +          elt_targ = access_targ->elt;
6627 +          targ_id  = osl_relation_get_array_id(elt_targ);
6628 +          
6629 +          /* Anti-dependences analysis. */
6630 +          if (elt_targ->type != OSL_TYPE_READ) { /* target WRITE | MAY_WRITE */
6631 +            if (options->war && src_id == targ_id) {
6632 +              for (i = min_depth; i <= max_depth; i++) {
6633 +                new = candl_dependence_system(source, target, context,
6634 +                                              elt_src, elt_targ,
6635 +                                              ref_s, ref_t,
6636 +                                              OSL_DEPENDENCE_WAR, i);
6637 +                osl_dependence_add(&dependence, &now, new);
6638 +              }
6639 +            }
6640 +          }
6641 +          /* Input-dependences analysis. */
6642 +          else { /* target READ */
6643 +            if (options->rar && src_id == targ_id) {
6644 +              for (i = min_depth; i <= max_depth; i++) {
6645 +                new = candl_dependence_system(source, target, context,
6646 +                                              elt_src, elt_targ,
6647 +                                              ref_s, ref_t,
6648 +                                              OSL_DEPENDENCE_RAR, i);
6649 +                osl_dependence_add(&dependence, &now, new);
6650 +              }
6651 +            }
6652 +          }
6653 +        }
6654 +        break;
6655 +     
6656 +      default: /* source WRITE | MAY-WRITE */
6657 +        if (!options->raw && !options->waw)
6658 +          break;
6659 +        access_targ = target->access;
6660 +        ref_t = 0;
6661 +        for (; access_targ != NULL; access_targ = access_targ->next, ref_t++) {
6662 +          elt_targ = access_targ->elt;
6663 +          targ_id = osl_relation_get_array_id(elt_targ);
6664 +          
6665 +          /* Anti-dependences analysis. */
6666 +          if (elt_targ->type != OSL_TYPE_READ) { /* target WRITE | MAY_WRITE */
6667 +            if (options->waw && src_id == targ_id) {
6668 +              for (i = min_depth; i <= max_depth; i++) {
6669 +                new = candl_dependence_system(source, target, context,
6670 +                                              elt_src, elt_targ,
6671 +                                              ref_s, ref_t,
6672 +                                              OSL_DEPENDENCE_WAW, i);
6673 +                osl_dependence_add(&dependence, &now, new);
6674 +              }
6675 +            }
6676 +          }
6677 +          /* Input-dependences analysis. */
6678 +          else { /* target READ */
6679 +            if (options->raw && src_id == targ_id) {
6680 +              for (i = min_depth; i <= max_depth; i++) {
6681 +                new = candl_dependence_system(source, target, context,
6682 +                                              elt_src, elt_targ,
6683 +                                              ref_s, ref_t,
6684 +                                              OSL_DEPENDENCE_RAW, i);
6685 +                osl_dependence_add(&dependence, &now, new);
6686 +              }
6687 +            }
6688 +          }
6689 +        }
6690 +        break;
6691 +    }
6692 +  }
6693 +  
6694    return dependence;
6695  }
6696  
6697  
6698 -
6699 -
6700 -
6701  /**
6702   * candl_dependence function:
6703 - * this function builds the dependence graph of a program (program)
6704 + * this function builds the dependence graph of a scop
6705   * according to some user options (options).
6706   * - 18/09/2003: first version.
6707   */
6708 -candl_dependence_p candl_dependence(candl_program_p program,
6709 -                                   CandlOptions* options)
6710 -{
6711 -  int i, j;
6712 -  candl_dependence_p dependence = NULL;
6713 -  candl_dependence_p new = NULL;
6714 -  candl_dependence_p now;
6715 -  CandlStatement  ** statement;
6716 -  CandlMatrix * context;
6717 -
6718 -  statement = program->statement;
6719 -  context = program->context;
6720 +osl_dependence_p candl_dependence(osl_scop_p scop, candl_options_p options) {
6721 +  if (scop == NULL) { return NULL; }
6722 +  
6723 +  osl_dependence_p dependence = NULL;
6724 +  osl_dependence_p new = NULL;
6725 +  osl_dependence_p now;
6726 +  osl_statement_p stmt_i, stmt_j;
6727 +  osl_relation_p context = scop->context;
6728 +  
6729    if (options->scalar_privatization || options->scalar_expansion)
6730 -    candl_dependence_analyze_scalars (program, options);
6731 -
6732 -  for (i = 0; i < program->nb_statements; i++)
6733 -    { /* We add self dependence. */
6734 -      /* S->S */
6735 -      new = candl_dependence_between(statement[i], statement[i],
6736 -                                    context, options);
6737 -      candl_dependence_add(&dependence, &now, new);
6738 -
6739 -      for (j = i + 1; j < program->nb_statements; j++)
6740 -       { /* And dependences with other statements. */
6741 -         /* S1->S2 */
6742 -         new = candl_dependence_between(statement[i], statement[j],
6743 -                                        context, options);
6744 -         candl_dependence_add(&dependence, &now, new);
6745 -
6746 -         /* S2->S1 */
6747 -         new = candl_dependence_between(statement[j], statement[i],
6748 -                                        context, options);
6749 -         candl_dependence_add(&dependence, &now, new);
6750 -       }
6751 +    candl_dependence_analyze_scalars(scop, options);
6752 +
6753 +  stmt_i = scop->statement;
6754 +  for (; stmt_i != NULL; stmt_i = stmt_i->next) {
6755 +    /* We add self dependence. */
6756 +    /* S->S */
6757 +    new = candl_dependence_between(stmt_i, stmt_i, context, options);
6758 +    osl_dependence_add(&dependence, &now, new);
6759 +    
6760 +    stmt_j = stmt_i->next;
6761 +    for (; stmt_j != NULL; stmt_j = stmt_j ->next) {
6762 +      /* And dependences with other statements. */
6763 +      /* S1->S2 */
6764 +      new = candl_dependence_between(stmt_i, stmt_j, context, options);
6765 +      osl_dependence_add(&dependence, &now, new);
6766 +
6767 +      /* S2->S1 */
6768 +      new = candl_dependence_between(stmt_j, stmt_i, context, options);
6769 +      osl_dependence_add(&dependence, &now, new);
6770      }
6771 -
6772 +  }
6773 +  
6774    /* If scalar analysis is called, remove some useless dependences. */
6775    /* LNP: This is subsubmed by the updated prune-with-privatization function. */
6776 -  /* if (options->scalar_privatization || options->scalar_expansion || */
6777 -  /*     options->scalar_renaming) */
6778 -  /*   candl_dependence_prune_scalar_waw (program, options, &dependence); */
6779 +  /*  if (options->scalar_privatization || options->scalar_expansion || */
6780 +  /*      options->scalar_renaming) */
6781 +  /*    candl_dependence_prune_scalar_waw(scop, options, &dependence); */
6782  
6783    /* Final treatment for scalar analysis. */
6784    int check = 0;
6785    if (options->scalar_renaming)
6786 -    check = candl_dependence_scalar_renaming (program, options, &dependence);
6787 +    check = candl_dependence_scalar_renaming(scop, options, &dependence);
6788 +
6789    if (! check && options->scalar_privatization)
6790 -    candl_dependence_prune_with_privatization (program, options, &dependence);
6791 +    candl_dependence_prune_with_privatization(scop, options, &dependence);
6792  
6793    /* Compute the last writer */
6794 -  if (options->lastwriter)  {
6795 -      candl_compute_last_writer(dependence, program);
6796 -  }
6797 +  if (options->lastwriter)
6798 +    candl_compute_last_writer(dependence, scop);
6799  
6800 +  #if defined(CANDL_COMPILE_PRUNNING_C)
6801    /* Remove some transitively covered dependences (experimental). */
6802    if (options->prune_dups)
6803 -    dependence = candl_dependence_prune_transitively_covered (dependence);
6804 +    dependence = candl_dependence_prune_transitively_covered(dependence);
6805 +  #endif
6806  
6807    return dependence;
6808  }
6809  
6810  
6811 +
6812 +/**
6813 + * candl_dependence_add_extension function:
6814 + * this function builds the dependence graph for a scop list
6815 + * according to some user options (options).
6816 + * For each scop the dependence graph is added in the extension of the scop.
6817 + * Any old dependence graph in the extension is deleted.
6818 + * 
6819 + * @param[in,out] scop    A osl scop
6820 + * @param[in]     options Candl options
6821 + */
6822 +void candl_dependence_add_extension(osl_scop_p scop, candl_options_p options) {
6823 +
6824 +  while (scop) {
6825 +    /* Calculating dependences. */
6826 +    osl_dependence_p dep = osl_generic_lookup(scop->extension, 
6827 +                                            OSL_URI_DEPENDENCE);
6828 +    if (dep != NULL) {
6829 +      osl_generic_remove(&scop->extension, OSL_URI_DEPENDENCE);
6830 +      CANDL_info("Deleting old dependences found in the options tag.");
6831 +    }
6832 +
6833 +    dep = candl_dependence(scop, options);
6834 +
6835 +    osl_generic_p data = osl_generic_shell(dep, osl_dependence_interface());
6836 +    data->next = scop->extension;
6837 +    scop->extension = data;
6838 +    
6839 +    scop = scop->next;
6840 +  }
6841 +}
6842 +
6843  /******************************************************************************
6844   *                          Scalar analysis functions                         *
6845   ******************************************************************************/
6846 @@ -1393,29 +1019,39 @@ candl_dependence_p candl_dependence(candl_program_p program,
6847  /**
6848   * candl_dependence_var_is_scalar function:
6849   * This function returns true if the variable indexed by 'var_index'
6850 - * is a scalar in the whole program.
6851 + * is a scalar in the whole scop.
6852   */
6853 -int
6854 -candl_dependence_var_is_scalar (candl_program_p program, int var_index)
6855 -{
6856 -  CandlMatrix* m;
6857 -  int i, j, k, cpt;
6858 -
6859 -  for (i = 0; i < program->nb_statements; ++i)
6860 -    for (m = program->statement[i]->read, cpt = 0; cpt < 2; ++cpt,
6861 -          m = program->statement[i]->written)
6862 -      for (j = 0; j < m->NbRows; ++j)
6863 -       if (CANDL_get_si(m->p[j][0]) == var_index)
6864 -         {
6865 -           /* Ensure it is not an array. */
6866 -           if (j < m->NbRows - 1 && CANDL_get_si(m->p[j + 1][0]) == 0)
6867 -             return 0;
6868 -           /* Ensure the access function is '0'. */
6869 -           for (k = 1; k < m->NbColumns; ++k)
6870 -             if (CANDL_get_si(m->p[j][k]) != 0)
6871 -               return 0;
6872 -         }
6873 -
6874 +int candl_dependence_var_is_scalar(osl_scop_p scop, int var_index) {
6875 +  osl_statement_p statement;
6876 +  osl_relation_list_p access;
6877 +  osl_relation_p elt;
6878 +  int precision = scop->context->precision;
6879 +  int i;
6880 +  int id, row;
6881 +
6882 +  statement = scop->statement;
6883 +  while (statement != NULL) {
6884 +    access = statement->access;
6885 +    while (access != NULL) {
6886 +      elt = access->elt;
6887 +      id = osl_relation_get_array_id(elt);
6888 +      row = candl_util_relation_get_line(elt, 0);
6889 +      if (id == var_index) {
6890 +        /* Ensure it is not an array. */
6891 +        if (elt->nb_output_dims > 1)
6892 +          return 0;
6893 +        /* Ensure the access function is '0'. */
6894 +        if (!osl_int_zero(precision, elt->m[row][0]))
6895 +          return 0;
6896 +        for (i = 2; i < elt->nb_columns-2; ++i) /* jmp the 'Arr' */
6897 +          if (!osl_int_zero(precision, elt->m[row][i]))
6898 +            return 0;
6899 +      }
6900 +      access = access->next;
6901 +    }
6902 +    statement = statement->next;
6903 +  }
6904 +  
6905    return 1;
6906  }
6907  
6908 @@ -1427,61 +1063,33 @@ candl_dependence_var_is_scalar (candl_program_p program, int var_index)
6909   * variable in the statement list.
6910   *
6911   */
6912 -static
6913 -void
6914 -candl_dependence_expand_scalar(CandlStatement** sl,
6915 -                              int scalar_idx)
6916 -{
6917 -  CandlMatrix* m;
6918 -  int i, l, n, j;
6919 +static void candl_dependence_expand_scalar(osl_statement_p* sl,
6920 +                                           int scalar_idx) {
6921 +  osl_relation_list_p access;
6922 +  osl_relation_p elt;
6923 +  int id, row;
6924 +  int precision = sl[0]->scattering->precision;
6925 +  int i;
6926  
6927    /* Iterate on all statements of the list. */
6928 -  for (i = 0; sl[i] != NULL; ++i)
6929 -    {
6930 -      /* Check if the scalar is referenced in the 'read' access
6931 -        function. */
6932 -      for (j = 0; j < sl[i]->read->NbRows &&
6933 -            CANDL_get_si(sl[i]->read->p[j][0]) != scalar_idx; ++j)
6934 -       ;
6935 -      /* It is. */
6936 -      if (j < sl[i]->read->NbRows)
6937 -       {
6938 -         /* Add a row to the 'read' matrix, just after the reference
6939 -            to 'scalar_idx'. */
6940 -         m = candl_matrix_malloc (sl[i]->read->NbRows +1,
6941 -                                  sl[i]->read->NbColumns);
6942 -         for (l = 0; l <= j; ++l)
6943 -           for (n = 0; n < m->NbColumns; ++n)
6944 -             CANDL_assign(m->p[l][n], sl[i]->read->p[l][n]);
6945 -         for (++l; l < m->NbRows; ++l)
6946 -           for (n = 0; n < m->NbColumns; ++n)
6947 -             CANDL_assign(m->p[l][n], sl[i]->read->p[l - 1][n]);
6948 -         for (n = 0; n < m->NbColumns; ++n)
6949 -           CANDL_set_si(m->p[j + 1][n], 0);
6950 -         candl_matrix_free (sl[i]->read);
6951 -         sl[i]->read = m;
6952 -       }
6953 -
6954 -      /* Same for 'written' access function. */
6955 -      for (j = 0; j < sl[i]->written->NbRows &&
6956 -            CANDL_get_si(sl[i]->written->p[j][0]) != scalar_idx;++j)
6957 -       ;
6958 -      if (j < sl[i]->written->NbRows)
6959 -       {
6960 -         m = candl_matrix_malloc (sl[i]->written->NbRows +1,
6961 -                                  sl[i]->written->NbColumns);
6962 -         for (l = 0; l <= j; ++l)
6963 -           for (n = 0; n < m->NbColumns; ++n)
6964 -             CANDL_assign(m->p[l][n], sl[i]->written->p[l][n]);
6965 -         for (++l; l < m->NbRows; ++l)
6966 -           for (n = 0; n < m->NbColumns; ++n)
6967 -             CANDL_assign(m->p[l][n], sl[i]->written->p[l - 1][n]);
6968 -         for (n = 0; n < m->NbColumns; ++n)
6969 -           CANDL_set_si(m->p[j + 1][n], 0);
6970 -         candl_matrix_free (sl[i]->written);
6971 -         sl[i]->written = m;
6972 -       }
6973 +  for (i = 0; sl[i] != NULL; ++i) {
6974 +    
6975 +    /* Check if the scalar is referenced in the 'read' access
6976 +       function. */
6977 +    access = sl[i]->access;
6978 +    for (; access != NULL ; access = access->next) {
6979 +      elt = access->elt;
6980 +      id = osl_relation_get_array_id(elt);
6981 +      row = candl_util_relation_get_line(elt, 0);
6982 +      if (id == scalar_idx) {
6983 +        row = elt->nb_rows;
6984 +        osl_relation_insert_blank_row(elt, row);
6985 +        osl_relation_insert_blank_column(elt, 1 + elt->nb_output_dims);
6986 +        osl_int_set_si(precision, &elt->m[row][1 + elt->nb_output_dims], -1);
6987 +        elt->nb_output_dims++;
6988 +      }
6989      }
6990 +  }
6991  }
6992  
6993  
6994 @@ -1490,51 +1098,70 @@ candl_dependence_expand_scalar(CandlStatement** sl,
6995   * This function returns a chain of statements as a feshly allocated
6996   * array of pointer on statements, of all statements reading or
6997   * writing the variable 'var_index', surrounded by the 'level' common
6998 - * loops of 'dom'.  Output is a NULL-terminated array.
6999 + * loops of 'dom'. 
7000 + * Output is a NULL-terminated array. We don't create a chained list,
7001 + * because it demands to clone every statements each time, and we need
7002 + * to clone the field usr too.
7003   */
7004 -CandlStatement**
7005 -candl_dependence_refvar_chain(candl_program_p program, CandlStatement* dom,
7006 -                             int var_index, int level)
7007 -{
7008 -  /* No or empty program -> no chain! */
7009 -  if (program == NULL || program->nb_statements == 0)
7010 +osl_statement_p* candl_dependence_refvar_chain(osl_scop_p scop,
7011 +                              osl_statement_p dom, int var_index, int level) {
7012 +  /* No or empty scop -> no chain! */
7013 +  if (scop == NULL || scop->statement == NULL)
7014      return NULL;
7015  
7016 +  osl_statement_p* res; /* not a chained list, but an array of statement */
7017 +  osl_statement_p statement;
7018 +  candl_statement_usr_p dom_usr;
7019 +  candl_statement_usr_p stmt_usr;
7020 +  int i;
7021    int buffer_size = 64;
7022 -  CandlStatement** res =
7023 -    (CandlStatement**) malloc(buffer_size * sizeof(CandlStatement*));
7024 -  int i, j, count = 0;
7025 -  CandlStatement* s;
7026 +  int count = 0;
7027  
7028    /* If no dominator is provided, assume we start with the first statement. */
7029    if (dom == NULL)
7030 -    dom = program->statement[0];
7031 -  for (i = 0; i < program->nb_statements && program->statement[i] != dom; ++i)
7032 -    ;
7033 +    dom = scop->statement;
7034 +  
7035 +  dom_usr = dom->usr;
7036 +  
7037 +  statement = scop->statement;
7038 +  while (statement != NULL && statement != dom)
7039 +    statement = statement->next;
7040 +  
7041    /* The dominator is not in the list of statements. */
7042 -  if (i == program->nb_statements)
7043 +  if (statement == NULL)
7044      return NULL;
7045 -  for (; i < program->nb_statements; ++i)
7046 -    {
7047 -      s = program->statement[i];
7048 -      /* We look for exactly 'level' common loops. */
7049 -      if (s->depth < level)
7050 -       continue;
7051 -      /* Ensure it has 'level' common loop(s) with the dominator. */
7052 -      for (j = 0; j < level&& s->index[j] == dom->index[j]; ++j)
7053 -       ;
7054 -      if (j < level)
7055 -       continue;
7056 -      /* Ensure the variable is referenced. */
7057 -      if (candl_dependence_var_is_ref (s, var_index) != CANDL_VAR_UNDEF)
7058 -       {
7059 -         res[count++] = s;
7060 -         if (count == buffer_size)
7061 -           res = realloc(res, (buffer_size*=2) * sizeof(CandlStatement*));
7062 -       }
7063 +  
7064 +  CANDL_malloc(res, osl_statement_p*, sizeof(osl_statement_p) * buffer_size);
7065 +  
7066 +  for (; statement != NULL; statement = statement->next) {
7067 +    stmt_usr = statement->usr;
7068 +    
7069 +    /* We look for exactly 'level' common loops. */
7070 +    if (stmt_usr->depth < level)
7071 +      continue;
7072 +      
7073 +    /* Ensure it has 'level' common loop(s) with the dominator. */
7074 +    for (i = 0; i < level && 
7075 +         stmt_usr->index[i] == dom_usr->index[i];
7076 +         ++i)
7077 +      ;
7078 +         
7079 +    if (i < level)
7080 +      continue;
7081 +   
7082 +    /* Ensure the variable is referenced. */
7083 +    if (candl_dependence_var_is_ref(statement, var_index) != CANDL_VAR_UNDEF) {
7084 +      if (count == buffer_size) {
7085 +        buffer_size *= 2;
7086 +        CANDL_realloc(res, osl_statement_p*,
7087 +                      sizeof(osl_statement_p) * buffer_size);
7088 +      }
7089 +      res[count++] = statement;
7090      }
7091 +  }
7092  
7093 -  res = realloc(res, (count + 1) * sizeof(CandlStatement*));
7094 +  CANDL_realloc(res, osl_statement_p*,
7095 +                sizeof(osl_statement_p) * (count+1));
7096    res[count] = NULL;
7097  
7098    return res;
7099 @@ -1546,30 +1173,44 @@ candl_dependence_refvar_chain(candl_program_p program, CandlStatement* dom,
7100   * This function checks if a var 'var_index' is referenced (DEF or
7101   * USE) by the statement.
7102   */
7103 -int
7104 -candl_dependence_var_is_ref(CandlStatement* s, int var_index)
7105 -{
7106 -  int j;
7107 +int candl_dependence_var_is_ref(osl_statement_p s, int var_index) {
7108 +  osl_relation_list_p access;
7109 +  osl_relation_p elt;
7110 +  int id;
7111    int ret = CANDL_VAR_UNDEF;
7112 -
7113 -  if (s)
7114 -    {
7115 -      for (j = 0; s->read && j < s->read->NbRows; ++j)
7116 -       if (CANDL_get_si(s->read->p[j][0]) == var_index)
7117 -         {
7118 -           ret = CANDL_VAR_IS_USED;
7119 -           break;
7120 -         }
7121 -      for (j = 0; s->written && j < s->written->NbRows; ++j)
7122 -       if (CANDL_get_si(s->written->p[j][0]) == var_index)
7123 -         {
7124 -           if (ret == CANDL_VAR_IS_USED)
7125 -             ret = CANDL_VAR_IS_DEF_USED;
7126 -           else
7127 -             ret = CANDL_VAR_IS_DEF;
7128 -           break;
7129 -         }
7130 +  
7131 +  if (s) {
7132 +    /* read access */
7133 +    access = s->access;
7134 +    while (access != NULL) {
7135 +      elt = access->elt;
7136 +      if (elt->type == OSL_TYPE_READ) {
7137 +        id = osl_relation_get_array_id(elt);
7138 +        if (id == var_index) {
7139 +          ret = CANDL_VAR_IS_USED;
7140 +          break;
7141 +        }
7142 +      }
7143 +      access = access->next;
7144 +    }
7145 +    
7146 +    /* right access */
7147 +    access = s->access;
7148 +    while (access != NULL) {
7149 +      elt = access->elt;
7150 +      if (elt->type != OSL_TYPE_READ) {
7151 +        id = osl_relation_get_array_id(elt);
7152 +        if (id == var_index) {
7153 +          if (ret == CANDL_VAR_IS_USED)
7154 +            ret = CANDL_VAR_IS_DEF_USED;
7155 +          else
7156 +            ret = CANDL_VAR_IS_DEF;
7157 +          break;
7158 +        }
7159 +      }
7160 +      access = access->next;
7161      }
7162 +  }
7163  
7164    return ret;
7165  }
7166 @@ -1580,29 +1221,26 @@ candl_dependence_var_is_ref(CandlStatement* s, int var_index)
7167   * This function assigns to the Entier 'lb' the lexmin of variable
7168   * 'col'-1 in the polyhedron 'm'.
7169   */
7170 -static
7171 -void
7172 -candl_dependence_compute_lb (CandlMatrix* m, Entier* lb, int col)
7173 -{
7174 +static void candl_dependence_compute_lb(osl_relation_p m, Entier* lb, int col) {
7175    PipOptions* options;
7176    PipQuast* solution;
7177    PipList* l;
7178 -  options = pip_options_init ();
7179 +  options = pip_options_init();
7180    options->Simplify = 1;
7181    options->Urs_parms = -1;
7182    options->Urs_unknowns = -1;
7183    /* Compute lexmin. */
7184 -  solution = pip_solve (m, NULL, -1, options);
7185 +  solution = pip_solve_osl(m, NULL, -1, options);
7186 +  
7187    if ((solution != NULL) &&
7188 -      ((solution->list != NULL) || (solution->condition != NULL)))
7189 -    {
7190 -      l = solution->list;
7191 -      while (col-- > 1)
7192 -       l = l->next;
7193 -      CANDL_assign(*lb, l->vector->the_vector[0]);
7194 -    }
7195 -  pip_options_free (options);
7196 -  pip_quast_free (solution);
7197 +      ((solution->list != NULL) || (solution->condition != NULL))) {
7198 +    l = solution->list;
7199 +    while (col-- > 1)
7200 +      l = l->next;
7201 +    CANDL_assign(*lb, l->vector->the_vector[0]);
7202 +  }
7203 +  pip_options_free(options);
7204 +  pip_quast_free(solution);
7205  }
7206  
7207  
7208 @@ -1613,66 +1251,95 @@ candl_dependence_compute_lb (CandlMatrix* m, Entier* lb, int col)
7209   * considered iterator dimensions.
7210   *
7211   */
7212 -int
7213 -candl_dependence_check_domain_is_included(CandlStatement* s1,
7214 -                                         CandlStatement* s2,
7215 -                                         CandlMatrix* context,
7216 -                                         int level)
7217 -{
7218 +int candl_dependence_check_domain_is_included(osl_statement_p s1,
7219 +                                              osl_statement_p s2,
7220 +                                              osl_relation_p context,
7221 +                                              int level) {
7222 +  candl_statement_usr_p s1_usr = s1->usr;
7223 +  candl_statement_usr_p s2_usr = s2->usr;
7224 +  osl_relation_p matrix;
7225    int max = level;
7226 -  Entier lb; CANDL_init(lb);
7227 -  max = s1->depth < max ? s1->depth : max;
7228 -  max = s2->depth < max ? s2->depth : max;
7229 -  CandlMatrix* m = candl_matrix_malloc(s2->domain->NbRows + s2->depth - max +1,
7230 -                                      s2->domain->NbColumns);
7231    int i, j;
7232 +  int precision = s2->domain->precision;
7233 +  Entier lb;
7234 +  osl_int_t osl_lb;
7235 +
7236 +  CANDL_init(lb);
7237 +  osl_int_init(precision, &osl_lb);
7238 +  
7239 +  if (s1_usr->depth < max) max = s1_usr->depth;
7240 +  if (s2_usr->depth < max) max = s2_usr->depth;
7241 +  
7242 +  matrix = osl_relation_pmalloc(precision,
7243 +                                s2->domain->nb_rows + s2_usr->depth - max + 1,
7244 +                                s2->domain->nb_columns);
7245 +
7246    /* Duplicate s2 to the dest matrix. */
7247 -  for (i = 0; i < s2->domain->NbRows; ++i)
7248 -    for (j = 0; j < s2->domain->NbColumns; ++j)
7249 -      CANDL_assign(m->p[i][j], s2->domain->p[i][j]);
7250 +  for (i = 0; i < s2->domain->nb_rows; ++i) {
7251 +    for (j = 0; j < s2->domain->nb_columns; ++j)
7252 +      osl_int_assign(precision,
7253 +                     &matrix->m[i][j], s2->domain->m[i][j]);
7254 +  }
7255 +  
7256    /* Make useless dimensions equal to 1. */
7257 -  for (j = 0; j < s2->depth - max; ++j)
7258 -    {
7259 -      candl_dependence_compute_lb (s2->domain, &lb, j + 1 + max);
7260 -      CANDL_assign(m->p[i][m->NbColumns - 1], lb);
7261 -      CANDL_set_si(m->p[i++][j + 1 + max], -1);
7262 -    }
7263 +  for (j = 0; j < s2_usr->depth - max; ++j) {
7264 +    candl_dependence_compute_lb(s2->domain, &lb, j + 1 + max);
7265 +    #ifdef CANDL_LINEAR_VALUE_IS_INT
7266 +    osl_lb.sp = lb;
7267 +    #elif defined(CANDL_LINEAR_VALUE_IS_LONGLONG)
7268 +    osl_lb.dp = lb;
7269 +    #elif defined(CANDL_LINEAR_VALUE_IS_MP)
7270 +    mpz_set(*((mpz_t*)osl_lb.mp), lb);
7271 +    #endif
7272 +    osl_int_assign(precision,
7273 +                   &matrix->m[i][matrix->nb_columns - 1], osl_lb);
7274 +    osl_int_set_si(precision,
7275 +                   &matrix->m[i++][j+1+max], -1);
7276 +  }
7277 +  
7278    /* Iterate on all constraints of s1, and check them. */
7279 -  for (i = 0; i < s1->domain->NbRows; ++i)
7280 -    {
7281 -      /* Skip constraints defining other iterators. */
7282 -      for (j = max + 1; j <= s1->depth; ++j)
7283 -       if (CANDL_get_si(s1->domain->p[i][j]) != 0)
7284 -         break;
7285 -      if (j <= s1->depth)
7286 -       continue;
7287 -      /* Invert the constraint, and add it to m. */
7288 -      for (j = 0; j <= max; ++j)
7289 -       {
7290 -         CANDL_assign(m->p[m->NbRows - 1][j], s1->domain->p[i][j]);
7291 -         CANDL_oppose(m->p[m->NbRows - 1][j], m->p[m->NbRows - 1][j]);
7292 -       }
7293 -      for (j = s1->depth + 1; j < s1->domain->NbColumns; ++j)
7294 -       {
7295 -         CANDL_assign(m->p[m->NbRows - 1][j - s1->depth + s2->depth],
7296 -                      s1->domain->p[i][j]);
7297 -         CANDL_oppose(m->p[m->NbRows - 1][j - s1->depth + s2->depth],
7298 -                      m->p[m->NbRows - 1][j - s1->depth + s2->depth]);
7299 -       }
7300 -      /* Make the inequality strict. */
7301 -      CANDL_decrement(m->p[m->NbRows - 1][m->NbColumns - 1],
7302 -                     m->p[m->NbRows - 1][m->NbColumns - 1]);
7303 -      if (candl_matrix_check_point (m, context))
7304 -       {
7305 -         /* There is a point. dom(s1) - dom(s2) > 0. */
7306 -         CANDL_clear(lb);
7307 -         candl_matrix_free(m);
7308 -         return 0;
7309 -       }
7310 +  for (i = 0; i < s1->domain->nb_rows; ++i) {
7311 +    /* Skip constraints defining other iterators. */
7312 +    for (j = max + 1; j <= s1_usr->depth; ++j) {
7313 +      if (!osl_int_zero(precision, s1->domain->m[i][j]))
7314 +        break;
7315 +    }
7316 +    if (j <= s1_usr->depth)
7317 +      continue;
7318 +    /* Invert the constraint, and add it to matrix. */
7319 +    for (j = 0; j <= max; ++j) {
7320 +      osl_int_assign(precision,
7321 +                     &matrix->m[matrix->nb_rows - 1][j],
7322 +                     s1->domain->m[i][j]);
7323 +      osl_int_oppose(precision,
7324 +                     &matrix->m[matrix->nb_rows - 1][j],
7325 +                     matrix->m[matrix->nb_rows - 1][j]);
7326 +    }
7327 +    for (j = s1_usr->depth + 1; j < s1->domain->nb_columns; ++j) {
7328 +      osl_int_assign(precision,
7329 +        &matrix->m[matrix->nb_rows - 1][j - s1_usr->depth + s2_usr->depth],
7330 +        s1->domain->m[i][j]);
7331 +      osl_int_oppose(precision,
7332 +        &matrix->m[matrix->nb_rows - 1][j - s1_usr->depth + s2_usr->depth],
7333 +        matrix->m[matrix->nb_rows - 1][j - s1_usr->depth + s2_usr->depth]);
7334 +    }
7335 +    /* Make the inequality strict. */
7336 +    osl_int_decrement(precision,
7337 +                      &matrix->m[matrix->nb_rows - 1][matrix->nb_columns - 1],
7338 +                      matrix->m[matrix->nb_rows - 1][matrix->nb_columns - 1]);
7339 +
7340 +    if (candl_matrix_check_point(matrix, context)) {
7341 +      /* There is a point. dom(s1) - dom(s2) > 0. */
7342 +      CANDL_clear(lb);
7343 +      osl_int_clear(precision, &osl_lb);
7344 +      osl_relation_free(matrix);
7345 +      return 0;
7346      }
7347 +  }
7348  
7349    CANDL_clear(lb);
7350 -  candl_matrix_free(m);
7351 +  osl_int_clear(precision, &osl_lb);
7352 +  osl_relation_free(matrix);
7353  
7354    return 1;
7355  }
7356 @@ -1680,49 +1347,48 @@ candl_dependence_check_domain_is_included(CandlStatement* s1,
7357  
7358  /**
7359   * candl_dependence_extract_scalar_variables function:
7360 - * This functions returns a -1-terminated array of the program scalar
7361 + * This functions returns a -1-terminated array of the scop scalar
7362   * variables.
7363   */
7364 -int*
7365 -candl_dependence_extract_scalar_variables (candl_program_p program)
7366 -{
7367 -  /* FIXME: implement a real buffer. */
7368 -  int scalars[1024];
7369 +int* candl_dependence_extract_scalar_variables(osl_scop_p scop) {
7370 +  osl_statement_p statement;
7371 +  osl_relation_p elt;
7372 +  osl_relation_list_p access;
7373 +  int scalars[1024]; /* FIXME: implement a real buffer. */
7374    int checked[1024];
7375 -  int i, j, k, idx, cpt;
7376 +  int i, idx;
7377    int count_s = 0, count_c = 0;
7378 -  CandlMatrix* m;
7379 -
7380 +  
7381    /* Detect all scalar variables. */
7382 -  for (i = 0; i < program->nb_statements; ++i)
7383 -    for (m = program->statement[i]->read, cpt = 0; cpt < 2; ++cpt,
7384 -          m = program->statement[i]->written)
7385 -      for (j = 0; j < m->NbRows; ++j)
7386 -       {
7387 -         idx = CANDL_get_si(m->p[j][0]);
7388 -         if (idx != 0)
7389 -           {
7390 -             for (k = 0; k < count_s && scalars[k] != idx; ++k)
7391 -               ;
7392 -             if (k == count_s)
7393 -               {
7394 -                 for (k = 0; k < count_c && checked[k] != idx; ++k)
7395 -                   ;
7396 -                 if (k == count_c)
7397 -                   {
7398 -                     if (candl_dependence_var_is_scalar(program, idx))
7399 -                       scalars[count_s++] = idx;
7400 -                     else
7401 -                       checked[count_c++] = idx;
7402 -                   }
7403 -                 if (count_s == 1024 || count_c == 1024)
7404 -                   CANDL_FAIL("Error: Buffer size too small");
7405 -               }
7406 -           }
7407 -       }
7408 -
7409 +  statement = scop->statement;
7410 +  while (statement != NULL) {
7411 +    access = statement->access;
7412 +    while (access != NULL) {
7413 +      elt = access->elt;
7414 +      idx = osl_relation_get_array_id(elt);
7415 +      
7416 +      for (i = 0; i < count_s && scalars[i] != idx; ++i)
7417 +       ;
7418 +      if (i == count_s) {
7419 +        for (i = 0; i < count_c && checked[i] != idx; ++i)
7420 +         ;
7421 +        if (i == count_c) {
7422 +          if (candl_dependence_var_is_scalar(scop, idx))
7423 +            scalars[count_s++] = idx;
7424 +          else
7425 +            checked[count_c++] = idx;
7426 +        }
7427 +        if (count_s == 1024 || count_c == 1024)
7428 +          CANDL_error("Error: Buffer size too small");
7429 +      }
7430 +      access = access->next;
7431 +    }
7432 +    statement = statement->next;
7433 +  }
7434 +  
7435    /* Rearrange the array to the exact size. */
7436 -  int* res = (int*) malloc((count_s + 1) * sizeof(int));
7437 +  int *res;
7438 +  CANDL_malloc(res, int*, (count_s + 1) * sizeof(int));
7439    for (i = 0; i < count_s; ++i)
7440      res[i] = scalars[i];
7441    res[i] = -1;
7442 @@ -1732,88 +1398,46 @@ candl_dependence_extract_scalar_variables (candl_program_p program)
7443  
7444  
7445  /**
7446 - * candl_dependence_get_array_refs_in_dep function:
7447 - * This function return the array indices referenced in the
7448 - * dependence.
7449 - */
7450 -static
7451 -void
7452 -candl_dependence_get_array_refs_in_dep (CandlDependence* tmp, int* refs,
7453 -                                       int* reft)
7454 -{
7455 -  if (! tmp)
7456 -    return;
7457 -  switch (tmp->type)
7458 -    {
7459 -    case CANDL_RAR:
7460 -      *refs = CANDL_get_si(tmp->source->read->p[tmp->ref_source][0]);
7461 -      *reft = CANDL_get_si(tmp->target->read->p[tmp->ref_target][0]);
7462 -      break;
7463 -    case CANDL_RAW:
7464 -    case CANDL_RAW_SCALPRIV:
7465 -      *refs = CANDL_get_si(tmp->source->written->p[tmp->ref_source][0]);
7466 -      *reft = CANDL_get_si(tmp->target->read->p[tmp->ref_target][0]);
7467 -      break;
7468 -    case CANDL_WAR:
7469 -      *refs = CANDL_get_si(tmp->source->read->p[tmp->ref_source][0]);
7470 -      *reft = CANDL_get_si(tmp->target->written->p[tmp->ref_target][0]);
7471 -      break;
7472 -    case CANDL_WAW:
7473 -      *refs = CANDL_get_si(tmp->source->written->p[tmp->ref_source][0]);
7474 -      *reft = CANDL_get_si(tmp->target->written->p[tmp->ref_target][0]);
7475 -      break;
7476 -    default:
7477 -      exit(1);
7478 -    }
7479 -}
7480 -
7481 -
7482 -/**
7483 - * candl_dependence_prune_scalar_waw function:
7484 + * osl_dependence_prune_scalar_waw function:
7485   * This function removes all WAW dependences between the same scalar
7486   * (they are useless dependences).
7487   */
7488 -void
7489 -candl_dependence_prune_scalar_waw (candl_program_p program,
7490 -                                  CandlOptions* options,
7491 -                                  CandlDependence** deps)
7492 -{
7493 +void osl_dependence_prune_scalar_waw(osl_scop_p scop,
7494 +                                       candl_options_p options,
7495 +                                       osl_dependence_p* deps) {
7496    int* scalars;
7497    int i;
7498    int refs, reft;
7499 -  CandlDependence* tmp;
7500 -  CandlDependence* next;
7501 -  CandlDependence* pred = NULL;
7502 +  osl_dependence_p tmp;
7503 +  osl_dependence_p next;
7504 +  osl_dependence_p pred = NULL;
7505  
7506    if (options->verbose)
7507      fprintf (stderr, "[Candl] Scalar Analysis: Remove all WAW between the same"
7508 -            " scalar\n");
7509 -
7510 -  scalars = candl_dependence_extract_scalar_variables (program);
7511 -
7512 -  for (tmp = *deps; tmp; )
7513 -    {
7514 -      candl_dependence_get_array_refs_in_dep (tmp, &refs, &reft);
7515 -      if (refs == reft && tmp->type == CANDL_WAW)
7516 -       {
7517 -         for (i = 0; scalars[i] != -1 && scalars[i] != refs; ++i)
7518 -           ;
7519 -         if (scalars[i] != -1)
7520 -           {
7521 -             candl_matrix_free (tmp->domain);
7522 -             next = tmp->next;
7523 -             if (pred == NULL)
7524 -               *deps = next;
7525 -             else
7526 -               pred->next = next;
7527 -             free (tmp);
7528 -             tmp = next;
7529 -             continue;
7530 -           }
7531 -       }
7532 -      pred = tmp;
7533 -      tmp = tmp->next;
7534 +             " scalar\n");
7535 +
7536 +  scalars = candl_dependence_extract_scalar_variables(scop);
7537 +
7538 +  for (tmp = *deps; tmp; ) {
7539 +    candl_dependence_get_array_refs_in_dep(tmp, &refs, &reft);
7540 +    if (refs == reft && tmp->type == OSL_DEPENDENCE_WAW) {
7541 +      for (i = 0; scalars[i] != -1 && scalars[i] != refs; ++i)
7542 +       ;
7543 +      if (scalars[i] != -1) {
7544 +        osl_relation_free(tmp->domain);
7545 +        next = tmp->next;
7546 +        if (pred == NULL)
7547 +          *deps = next;
7548 +        else
7549 +          pred->next = next;
7550 +        free(tmp);
7551 +        tmp = next;
7552 +        continue;
7553 +      }
7554      }
7555 +    pred = tmp;
7556 +    tmp = tmp->next;
7557 +  }
7558  
7559    free(scalars);
7560  }
7561 @@ -1824,160 +1448,189 @@ candl_dependence_prune_scalar_waw (candl_program_p program,
7562   * This function renames scalars in the program. In case scalars have
7563   * been renamed, the dependence analysis is re-run.
7564   */
7565 -int
7566 -candl_dependence_scalar_renaming (candl_program_p program,
7567 -                                 CandlOptions* options,
7568 -                                 CandlDependence** deps)
7569 -{
7570 +int candl_dependence_scalar_renaming(osl_scop_p scop,
7571 +                                     candl_options_p options,
7572 +                                     osl_dependence_p* deps) {
7573 +  osl_statement_p *statement; /* not a chained list */
7574 +  osl_statement_p iter;
7575 +  osl_statement_p defs[1024];
7576 +  osl_statement_p uses[1024];
7577 +  osl_statement_p last_def;
7578 +  osl_statement_p *current; /* not a chained list */
7579 +  osl_relation_p elt;
7580 +  osl_relation_list_p access;
7581 +  candl_statement_usr_p usr;
7582 +  candl_statement_usr_p last_usr;
7583    int i, j, k;
7584 -  CandlStatement** stmts;
7585 -  CandlStatement* defs[1024];
7586 -  CandlStatement* uses[1024];
7587 -  CandlStatement* current[program->nb_statements];
7588 -  int parts[program->nb_statements];
7589 -  CandlStatement* s;
7590 -  CandlStatement* last_def;
7591 -  CandlMatrix* m;
7592 +  int nb_statements = 0;
7593 +  int *parts;
7594    int defs_c, uses_c;
7595 -  int val, cpt, tmp, has_changed = 0;
7596 +  int *scalars;
7597 +  int precision = scop->context->precision;
7598 +  int row;
7599 +  int tmp, has_changed = 0;
7600    int newvar = 0;
7601  
7602 -  for (i = 0; i < program->nb_statements; ++i)
7603 -    current[i] = NULL;
7604 -
7605    if (options->verbose)
7606      fprintf (stderr, "[Candl] Scalar Analysis: Perform scalar renaming\n");
7607 -
7608 +  
7609    /* Compute the first free variable index seed. */
7610 -  for (i = 0; i < program->nb_statements; ++i)
7611 -    for (m = program->statement[i]->read, cpt = 0; cpt < 2;
7612 -        ++cpt, m = program->statement[i]->written)
7613 -      for (j = 0; j < m->NbRows; ++j)
7614 -       if (CANDL_get_si(m->p[j][0]) >= newvar)
7615 -         newvar = CANDL_get_si(m->p[j][0]) + 1;
7616 +  for (iter = scop->statement; iter != NULL; iter = iter->next) {
7617 +    access = iter->access;
7618 +    for (; access != NULL; access = access->next) {
7619 +      elt = access->elt;
7620 +      tmp = osl_relation_get_array_id(elt);
7621 +      if (tmp >= newvar)
7622 +        newvar = tmp + 1;
7623 +    }
7624 +    nb_statements++;
7625 +  }
7626  
7627 +  /* Init */
7628 +  CANDL_malloc(current, osl_statement_p*, sizeof(osl_statement_p) * nb_statements);
7629 +  CANDL_malloc(parts, int*, sizeof(int) * nb_statements);
7630 +  
7631    /* Get the list of scalars. */
7632 -  int* scalars = candl_dependence_extract_scalar_variables (program);
7633 +  scalars = candl_dependence_extract_scalar_variables(scop);
7634  
7635    /* Iterate on all scalars. */
7636 -  for (i = 0; scalars[i] != -1; ++i)
7637 -    {
7638 -      /* Get all statements referencing the scalar. */
7639 -      stmts = candl_dependence_refvar_chain (program, NULL, scalars[i], 0);
7640 -
7641 -      /* If the chain starts by a USE, we can't do anything. */
7642 -      if (stmts[0] == NULL || candl_dependence_var_is_ref (stmts[0], scalars[i])
7643 -         != CANDL_VAR_IS_DEF)
7644 -       {
7645 -         free (stmts);
7646 -         continue;
7647 -       }
7648 -
7649 -      /* Get all defs. */
7650 -      for (j = 0, defs_c = 0; stmts[j]; ++j)
7651 -       if (candl_dependence_var_is_ref (stmts[j], scalars[i])
7652 -           == CANDL_VAR_IS_DEF)
7653 -         defs[defs_c++] = stmts[j];
7654 -      /* Get all uses. */
7655 -      for (j = 0, uses_c = 0; stmts[j]; ++j)
7656 -       {
7657 -         val = candl_dependence_var_is_ref (stmts[j], scalars[i]);
7658 -         if (val == CANDL_VAR_IS_USED ||  val == CANDL_VAR_IS_DEF_USED)
7659 -           uses[uses_c++] = stmts[j];
7660 -       }
7661 -
7662 -      /* Clean buffer. */
7663 -      for (j = 0; j < program->nb_statements; ++j)
7664 -       current[j] = NULL;
7665 -
7666 -      free (stmts);
7667 -
7668 -      /* Iterate on all DEFs. */
7669 -      for (j = 0, last_def = NULL; j < defs_c; ++j)
7670 -       {
7671 -         if (last_def == NULL)
7672 -           last_def = defs[j];
7673 -         else
7674 -           {
7675 -             /* Ensure the current DEF covers all iterations covered
7676 -                by the last checked one. */
7677 -             for (k = 0; k < last_def->depth && k < defs[j]->depth &&
7678 -                    last_def->index[k] == defs[j]->index[k]; ++k)
7679 -               ;
7680 -             /* We only need to check when there are common loops. */
7681 -             if (k && ! candl_dependence_check_domain_is_included
7682 -                 (last_def, defs[j], program->context, k + 1))
7683 -               {
7684 -                 current[defs[j]->label] = last_def;
7685 -                 continue;
7686 -               }
7687 -             else
7688 -               last_def = defs[j];
7689 -           }
7690 -         /* Create DEF-USE table. */
7691 -         for (k = 0; k < uses_c; ++k)
7692 -           if (uses[k]->label > defs[j]->label)
7693 -               current[uses[k]->label] = defs[j];
7694 -       }
7695 -
7696 -      /* Initialize partition table. */
7697 -      for (j = 0; j < program->nb_statements; ++j)
7698 -       parts[j] = -1;
7699 -
7700 -      /* Create partitions. */
7701 -      for (j = 0; j < defs_c; ++j)
7702 -       for (k = 0; k < program->nb_statements; ++k)
7703 -         if ((current[k] && current[k] == defs[j]) ||
7704 -             (k == defs[j]->label && current[defs[j]->label] == NULL))
7705 -           parts[k] = j;
7706 -
7707 -      /* Check if it is needed to rename the scalar. */
7708 -      for (j = 0, tmp = -1; j < program->nb_statements; ++j)
7709 -       if (tmp == -1)
7710 -         {
7711 -           if (parts[j] != -1)
7712 -             tmp = parts[j];
7713 -         }
7714 -       else
7715 -         if (parts[j] != -1 && tmp != parts[j])
7716 -           break;
7717 -
7718 -      /* Rename scalar variable. */
7719 -      if (j != program->nb_statements)
7720 -       for (j = 0, tmp = -1; j < program->nb_statements; ++j)
7721 -         if (parts[j] != -1)
7722 -           {
7723 -             if (tmp == -1)
7724 -               tmp = parts[j];
7725 -             else
7726 -               if (tmp != parts[j])
7727 -                 has_changed = 1;
7728 -             s = program->statement[j];
7729 -             for (m = s->read, cpt = 0; cpt < 2; ++cpt, m = s->written)
7730 -               for (k = 0; k < m->NbRows; ++k)
7731 -                 if (CANDL_get_si(m->p[k][0]) == scalars[i])
7732 -                   {
7733 -                     if (options->verbose)
7734 -                       fprintf (stderr, "[Candl] Scalar analysis: Renamed "
7735 -                                "variable %d to %d at statement S%d\n",
7736 -                                scalars[i], newvar + parts[j], j);
7737 -                     CANDL_set_si(m->p[k][0], newvar + parts[j]);
7738 -                   }
7739 -           }
7740 +  for (i = 0; scalars[i] != -1; ++i) {
7741 +    /* Get all statements referencing the scalar. */
7742 +    statement = candl_dependence_refvar_chain(scop, NULL, scalars[i], 0);
7743 +
7744 +    /* If the chain starts by a USE, we can't do anything. */
7745 +    if (statement[0] == NULL ||
7746 +        candl_dependence_var_is_ref(statement[0], scalars[i])
7747 +        != CANDL_VAR_IS_DEF) {
7748 +      free(statement);
7749 +      continue;
7750      }
7751  
7752 -  /* Redo the full dependence analysis, if needed. */
7753 -  if (has_changed)
7754 -    {
7755 -      int bopt = options->scalar_renaming;
7756 -      options->scalar_renaming = 0;
7757 -      if (options->scalar_privatization)
7758 -       free (program->scalars_privatizable);
7759 -      candl_dependence_free (*deps);
7760 -      *deps = candl_dependence (program, options);
7761 -      options->scalar_renaming = bopt;
7762 +    /* Get all defs and all uses. */
7763 +    defs_c = 0;
7764 +    uses_c = 0;
7765 +    for (j = 0; statement[j]; ++j) {
7766 +      tmp = candl_dependence_var_is_ref(statement[j], scalars[i]);
7767 +      switch (tmp) {
7768 +        case CANDL_VAR_IS_USED:
7769 +        case CANDL_VAR_IS_DEF_USED:
7770 +          uses[uses_c++] = statement[j];
7771 +          break;
7772 +        case CANDL_VAR_IS_DEF:
7773 +          defs[defs_c++] = statement[j];
7774 +          break;
7775 +      }
7776 +    }
7777 +
7778 +    /* Clean buffer. */
7779 +    j = 0;
7780 +    for (iter = scop->statement; iter != NULL; iter = iter->next)
7781 +      current[j++] = NULL;
7782 +
7783 +    free(statement);
7784 +
7785 +    /* Iterate on all DEFs. */
7786 +    last_def = NULL;
7787 +    for (j = 0; j < defs_c; ++j) {
7788 +      if (last_def == NULL) {
7789 +        last_def = defs[j];
7790 +      } else {
7791 +        /* Ensure the current DEF covers all iterations covered
7792 +           by the last checked one. */
7793 +        last_usr = last_def->usr;
7794 +        usr = defs[j]->usr;
7795 +        for (k = 0; k < last_usr->depth && k < usr->depth &&
7796 +             last_usr->index[k] == usr->index[k];
7797 +             ++k)
7798 +          ;
7799 +        /* We only need to check when there are common loops. */
7800 +        if (k && ! candl_dependence_check_domain_is_included
7801 +            (last_def, defs[j], scop->context, k + 1)) {
7802 +          usr = defs[j]->usr;
7803 +          current[usr->label] = last_def;
7804 +          continue;
7805 +        } else {
7806 +          last_def = defs[j];
7807 +        }
7808 +      }
7809 +      /* Create DEF-USE table. */
7810 +      for (k = 0; k < uses_c; ++k) {
7811 +        usr = uses[k]->usr;
7812 +        if (usr->label > ((candl_statement_usr_p)defs[j]->usr)->label)
7813 +          current[usr->label] = defs[j];
7814 +      }
7815 +    }
7816 +
7817 +    /* Initialize partition table. */
7818 +    for (j = 0; j < nb_statements; ++j)
7819 +      parts[j] = -1;
7820 +
7821 +    /* Create partitions. */
7822 +    for (j = 0; j < defs_c; ++j) {
7823 +      usr = defs[j]->usr;
7824 +      for (k = 0; k < nb_statements; ++k)
7825 +        if ((current[k] && current[k] == defs[j]) ||
7826 +            (k == usr->label && current[usr->label] == NULL))
7827 +          parts[k] = j;
7828 +    }
7829 +
7830 +    /* Check if it is needed to rename the scalar. */
7831 +    tmp = -1;
7832 +    for (j = 0; j < nb_statements; ++j)
7833 +      if (tmp == -1) {
7834 +        if (parts[j] != -1)
7835 +          tmp = parts[j];
7836 +      } else {
7837 +        if (parts[j] != -1 && tmp != parts[j])
7838 +          break;
7839 +      }
7840 +
7841 +    /* Rename scalar variable. */
7842 +    if (j != nb_statements) {
7843 +      tmp = -1;
7844 +      j = 0;
7845 +      for (iter = scop->statement ; iter != NULL ; iter = iter->next) {
7846 +        if (parts[j] != -1) {
7847 +          if (tmp == -1)
7848 +            tmp = parts[j];
7849 +          else if (tmp != parts[j])
7850 +            has_changed = 1;
7851 +          
7852 +          access = iter->access;
7853 +          for (; access != NULL; access = access->next) {
7854 +            elt = access->elt;
7855 +            row = candl_util_relation_get_line(elt, 0);
7856 +            tmp = osl_relation_get_array_id(elt);
7857 +            if (tmp == scalars[i]) {
7858 +              if (options->verbose)
7859 +                fprintf (stderr, "[Candl] Scalar analysis: Renamed "
7860 +                         "variable %d to %d at statement S%d\n",
7861 +                         scalars[i], newvar + parts[j], j);
7862 +              osl_int_set_si(precision,
7863 +                             &elt->m[row][elt->nb_columns - 1],
7864 +                             newvar + parts[j]);
7865 +            }
7866 +          }
7867 +        }
7868 +        j++;
7869 +      }
7870      }
7871 -  free (scalars);
7872 +  } /* end Iterate on all scalars */
7873 +
7874 +  /* Redo the full dependence analysis, if needed. */
7875 +  if (has_changed) {
7876 +    int bopt = options->scalar_renaming;
7877 +    options->scalar_renaming = 0;
7878 +    if (options->scalar_privatization)
7879 +      free(((candl_scop_usr_p)scop->usr)->scalars_privatizable);
7880 +    osl_dependence_free(*deps);
7881 +    *deps = candl_dependence(scop, options);
7882 +    options->scalar_renaming = bopt;
7883 +  }
7884 +  
7885 +  free(scalars);
7886 +  free(current);
7887 +  free(parts);
7888  
7889    return has_changed;
7890  }
7891 @@ -1988,188 +1641,171 @@ candl_dependence_scalar_renaming (candl_program_p program,
7892   * This function returns true if the dependence 'dep' is loop-carried
7893   * for loop 'loop_index', false otherwise.
7894   */
7895 -int
7896 -candl_dependence_is_loop_carried (candl_program_p program,
7897 -                                 CandlDependence* dep,
7898 -                                 int loop_index)
7899 -{
7900 +int candl_dependence_is_loop_carried(osl_scop_p scop,
7901 +                                     osl_dependence_p dep,
7902 +                                     int loop_index) {
7903 +  osl_relation_p msrc = NULL, mtarg = NULL;
7904 +  candl_statement_usr_p s_usr = dep->stmt_source_ptr->usr;
7905 +  candl_statement_usr_p t_usr = dep->stmt_target_ptr->usr;
7906    int i, j;
7907 +  int k, kp, l;
7908 +  int row_k, row_kp;
7909 +  int precision = scop->context->precision;
7910 +  
7911    /* Ensure source and sink share common loop 'loop_index', and that
7912       dependence depth is consistent with the considered loop. */
7913 -  for (i = 0; i < dep->source->depth; ++i)
7914 -    if (dep->source->index[i] == loop_index)
7915 +  for (i = 0; i < s_usr->depth; ++i)
7916 +    if (s_usr->index[i] == loop_index)
7917        break;
7918 -  if (i != dep->depth - 1 || i >= dep->target->depth)
7919 +  if (i != dep->depth - 1 || i >= t_usr->depth)
7920      return 0;
7921 -  for (j = 0; j < dep->target->depth; ++j)
7922 -    if (dep->target->index[j] == loop_index)
7923 +  for (j = 0; j < t_usr->depth; ++j)
7924 +    if (t_usr->index[j] == loop_index)
7925        break;
7926    if (j != i)
7927      return 0;
7928 -
7929 -  int k = 0;
7930 -  int l = 0;
7931 -  CandlMatrix* mats;
7932 -  if (dep->type == CANDL_WAR || dep->type == CANDL_RAR)
7933 -    mats = dep->source->read;
7934 -  else
7935 -    mats = dep->source->written;
7936 -  CandlMatrix* matt;
7937 -  if (dep->type == CANDL_RAW || dep->type == CANDL_RAW_SCALPRIV
7938 -      || dep->type == CANDL_RAR)
7939 -    matt = dep->target->read;
7940 -  else
7941 -    matt = dep->target->written;
7942 -
7943 -  int src_ref_iter = 0;
7944 -  int dst_ref_iter = 0;
7945 -  for (k = 0; k == 0 ||
7946 -        (dep->ref_source + k < mats->NbRows &&
7947 -         CANDL_get_si(mats->p[dep->ref_source + k][0]) == 0); ++k)
7948 -    if (CANDL_get_si(mats->p[dep->ref_source + k][i + 1]) != 0)
7949 -      {
7950 -       src_ref_iter = 1;
7951 -       break;
7952 -      }
7953 -  for (k = 0; k == 0 ||
7954 -        (dep->ref_target + k < matt->NbRows &&
7955 -         CANDL_get_si(matt->p[dep->ref_target + k][0]) == 0); ++k)
7956 -    if (CANDL_get_si(matt->p[dep->ref_target + k][j + 1]) != 0)
7957 -      {
7958 -       dst_ref_iter = 1;
7959 -       break;
7960 -      }
7961 +  
7962 +  msrc = candl_dependence_get_relation_ref_source_in_dep(dep);
7963 +  mtarg = candl_dependence_get_relation_ref_target_in_dep(dep);
7964 +  
7965 +  /* plus one for the Arr output dim */
7966 +  int src_ref_iter = (candl_util_relation_get_line(msrc, i+1) != -1);
7967 +  int dst_ref_iter = (candl_util_relation_get_line(mtarg,j+1) != -1);
7968  
7969    /* Ensure it is not a basic loop-independent dependence (pure
7970       equality of the access functions for the surrounding iterators +
7971       parameters + constant, no occurence of the inner loop iterators,
7972       and contain the current loop iterator. */
7973    int must_test = 0;
7974 -  k = 0;
7975 -  do
7976 -    {
7977 -      // Ensure the reference do reference the current loop iterator
7978 -      // to be tested.
7979 -      if (CANDL_get_si(mats->p[dep->ref_source + k][i + 1]) != 0)
7980 -       {
7981 -         int kp = 0;
7982 -         do
7983 -           {
7984 -             if (CANDL_get_si(matt->p[dep->ref_target + kp][j + 1]) != 0)
7985 -               {
7986 -                 // Ensure the access functions are equal for the
7987 -                 // surrounding loop iterators, and no inner iterator
7988 -                 // is referenced.
7989 -                 for (l = 0; l <= i + 1; ++l)
7990 -                   if (CANDL_get_si(mats->p[dep->ref_source + k][l]) !=
7991 -                       CANDL_get_si(matt->p[dep->ref_target + kp][l]))
7992 -                     {
7993 -                       must_test = 1;
7994 -                       break;
7995 -                     }
7996 -                 int m = l;
7997 -                 if (!must_test)
7998 -                   for (; l <= dep->source->depth; ++l)
7999 -                     if (CANDL_get_si(mats->p[dep->ref_source + k][l]) != 0)
8000 -                       {
8001 -                         must_test = 1;
8002 -                         break;
8003 -                       }
8004 -                 if (!must_test)
8005 -                   for (; m <= dep->target->depth; ++m)
8006 -                     if (CANDL_get_si(matt->p[dep->ref_target + kp][m]) != 0)
8007 -                       {
8008 -                         must_test = 1;
8009 -                         break;
8010 -                       }
8011 -                 if (!must_test)
8012 -                   for (; l < mats->NbColumns; ++l, ++m)
8013 -                     if (CANDL_get_si(mats->p[dep->ref_source + k][l]) !=
8014 -                         CANDL_get_si(matt->p[dep->ref_target + kp][m]))
8015 -                       {
8016 -                         must_test = 1;
8017 -                         break;
8018 -                       }
8019 -               }
8020 -             ++kp;
8021 -           }
8022 -         while (!must_test &&
8023 -                dep->ref_target + kp < matt->NbRows &&
8024 -                CANDL_get_si(matt->p[dep->ref_target + kp][0]) == 0);
8025 -       }
8026 -      ++k;
8027 -    }
8028 +  k = 1; // start after the Arr column
8029 +  row_k = candl_util_relation_get_line(msrc, k);
8030    while (!must_test &&
8031 -        dep->ref_source + k < mats->NbRows &&
8032 -        CANDL_get_si(mats->p[dep->ref_source + k][0]) == 0);
8033 +         k < msrc->nb_output_dims &&
8034 +         osl_int_zero(precision, msrc->m[row_k][0])) {
8035 +
8036 +    // Ensure the reference do reference the current loop iterator
8037 +    // to be tested.
8038 +    if (!osl_int_zero(precision, msrc->m[row_k][i])) {
8039 +      kp = 1;
8040 +      row_kp = candl_util_relation_get_line(mtarg, kp);
8041 +
8042 +      while (!must_test &&
8043 +             kp < mtarg->nb_output_dims &&
8044 +             osl_int_zero(precision, mtarg->m[row_kp][0])) {
8045 +
8046 +        if (!osl_int_zero(precision, mtarg->m[row_kp][j])) {
8047 +          // Ensure the access functions are equal for the
8048 +          // surrounding loop iterators, and no inner iterator
8049 +          // is referenced.
8050 +          if (!osl_int_eq(precision,
8051 +                          msrc->m[row_k][0], mtarg->m[row_kp][0])) {
8052 +            must_test = 1;
8053 +          } else {
8054 +            for (l = 1; l <= i; ++l)
8055 +              if (!osl_int_eq(precision,
8056 +                              msrc->m[row_k][msrc->nb_output_dims + l],
8057 +                              mtarg->m[row_kp][mtarg->nb_output_dims + l])) {
8058 +                must_test = 1;
8059 +                break;
8060 +              }
8061 +          }
8062 +          int m = l;
8063 +          if (!must_test)
8064 +            for (; l <= s_usr->depth+1; ++l)
8065 +              if (!osl_int_zero(precision, msrc->m[row_k][msrc->nb_output_dims + l])) {
8066 +                must_test = 1;
8067 +                break;
8068 +              }
8069 +          if (!must_test)
8070 +            for (; m <= t_usr->depth+1; ++m)
8071 +              if (!osl_int_zero(precision, mtarg->m[row_kp][mtarg->nb_output_dims + m])) {
8072 +                must_test = 1;
8073 +                break;
8074 +              }
8075 +          if (!must_test)
8076 +            for (; l < msrc->nb_columns-1; ++l, ++m)
8077 +            if (!osl_int_eq(precision,
8078 +                            msrc->m[row_k][msrc->nb_output_dims + l],
8079 +                            mtarg->m[row_kp][mtarg->nb_output_dims + m])) {
8080 +                must_test = 1;
8081 +                break;
8082 +              }
8083 +        }
8084 +        ++kp;
8085 +        row_kp = candl_util_relation_get_line(mtarg, kp);
8086 +      }
8087 +    }
8088 +    ++k;
8089 +    row_k = candl_util_relation_get_line(msrc, k);
8090 +  }
8091 +  
8092    if (src_ref_iter && dst_ref_iter && !must_test)
8093      return 0;
8094  
8095 -
8096    /* Final check. For loop i, the dependence is loop carried if there exists
8097       x_i^R != x_i^S in the dependence polyhedron, with
8098       x_{1..i-1}^R = x_{1..i-1}^S
8099 -  */
8100 +   */
8101    int pos;
8102 -  CandlMatrix* mat = dep->domain;
8103 -  CandlStatement* src = dep->source;
8104 -  CandlMatrix* testsyst =
8105 -    candl_matrix_malloc(mat->NbRows + 1 + dep->source->depth, mat->NbColumns);
8106 -  for (pos = 0; pos < mat->NbRows; ++pos)
8107 -    for (j = 0; j < mat->NbColumns; ++j)
8108 -      CANDL_assign(testsyst->p[pos][j], mat->p[pos][j]);
8109 -  for (j = 0; j < i; ++j)
8110 -    {
8111 -      CANDL_set_si(testsyst->p[pos + j + 1][0], 0);
8112 -      CANDL_set_si(testsyst->p[pos + j + 1][1 + j], -1);
8113 -      CANDL_set_si(testsyst->p[pos + j + 1][1 + j + dep->source->depth], 1);
8114 -    }
8115 +  osl_relation_p mat = dep->domain;
8116 +  
8117 +  osl_relation_p testsyst = osl_relation_pmalloc(precision,
8118 +                           mat->nb_rows + 1 + s_usr->depth,
8119 +                           mat->nb_columns);
8120 +  for (pos = 0; pos < mat->nb_rows; ++pos)
8121 +    for (j = 0; j < mat->nb_columns; ++j)
8122 +      osl_int_assign(precision,
8123 +                     &testsyst->m[pos][j], mat->m[pos][j]);
8124 +  for (j = 0; j < i; ++j) {
8125 +    osl_int_set_si(precision, &testsyst->m[pos+j+1][0], 0);
8126 +    osl_int_set_si(precision, &testsyst->m[pos+j+1][1+j], -1);
8127 +    osl_int_set_si(precision, &testsyst->m[pos+j+1][1+j+mat->nb_output_dims], 1);
8128 +  }
8129  
8130    int has_pt = 0;
8131    // Test for '>'.
8132 -  CANDL_set_si(testsyst->p[pos][0], 1);
8133 -  CANDL_set_si(testsyst->p[pos][testsyst->NbColumns - 1], -1);
8134 -  CANDL_set_si(testsyst->p[pos][1 + i], 1);
8135 -  CANDL_set_si(testsyst->p[pos][1 + i + src->depth], -1);
8136 -  has_pt = pip_has_rational_point (testsyst, NULL, 1);
8137 -  if (! has_pt)
8138 -    {
8139 -      // Test for '<'.
8140 -      CANDL_set_si(testsyst->p[pos][1 + i], -1);
8141 -      CANDL_set_si(testsyst->p[pos][1 + i + src->depth], 1);
8142 -      has_pt = pip_has_rational_point (testsyst, NULL, 1);
8143 -    }
8144 -
8145 -  candl_matrix_free (testsyst);
8146 -
8147 +  osl_int_set_si(precision, &testsyst->m[pos][0], 1);
8148 +  osl_int_set_si(precision, &testsyst->m[pos][testsyst->nb_columns-1], -1);
8149 +  osl_int_set_si(precision, &testsyst->m[pos][1+i], 1);
8150 +  osl_int_set_si(precision, &testsyst->m[pos][1+i+mat->nb_output_dims], -1);
8151 +  
8152 +  has_pt = pip_has_rational_point(testsyst, NULL, 1);
8153 +  if (!has_pt) {
8154 +    // Test for '<'.
8155 +    osl_int_set_si(precision, &testsyst->m[pos][1+i], -1);
8156 +    osl_int_set_si(precision, &testsyst->m[pos][1+i+mat->nb_output_dims], 1);
8157 +    has_pt = pip_has_rational_point(testsyst, NULL, 1);
8158 +  }
8159 +  
8160    return has_pt;
8161  
8162 -  /* LNP: OLD VERSION. The above is more robust. */
8163 -/*   /\* Final check. The dependence exists only because the loop */
8164 -/*      iterates. Make the loop not iterate and check if there's still */
8165 -/*      dependent iterations. *\/ */
8166 -/*   CandlMatrix* m = candl_matrix_malloc(dep->domain->NbRows + 2, */
8167 -/*                                    dep->domain->NbColumns); */
8168 -/*   CANDL_set_si(m->p[m->NbRows - 2][i + 1], -1); */
8169 -/*   CANDL_set_si(m->p[m->NbRows - 1][dep->source->depth + 1 + j], -1); */
8170 -/*   /\* Copy the rest of the matrix. *\/ */
8171 -/*   int ii, jj; */
8172 -/*   for (ii = 0; ii < dep->domain->NbRows; ++ii) */
8173 -/*     for (jj = 0; jj < dep->domain->NbColumns; ++jj) */
8174 -/*       CANDL_assign(m->p[ii][jj], dep->domain->p[ii][jj]); */
8175 -/*   /\* Compute real lb of loops. *\/ */
8176 -/*   Entier lb; CANDL_init(lb); */
8177 -/*   candl_dependence_compute_lb (m, &lb, i + 1); */
8178 -/*   CANDL_assign(m->p[m->NbRows - 2][m->NbColumns - 1], lb); */
8179 -/*   candl_dependence_compute_lb (m, &lb, dep->source->depth + 1 + j); */
8180 -/*   CANDL_assign(m->p[m->NbRows - 1][m->NbColumns - 1], lb); */
8181 -/*   int ret = candl_matrix_check_point(m, program->context); */
8182 -/*   CANDL_clear(lb); */
8183 -
8184 -/*   /\* Be clean. *\/ */
8185 -/*   candl_matrix_free(m); */
8186 -
8187 -/*   return !ret; */
8188 +  /* LNP: OLD VERSION */
8189 +  /* The above is more robust. */
8190 +  /*   /\* Final check. The dependence exists only because the loop */
8191 +  /*      iterates. Make the loop not iterate and check if there's still */
8192 +  /*      dependent iterations. *\/ */
8193 +  /*   CandlMatrix* m = candl_matrix_malloc(dep->domain->NbRows + 2, */
8194 +  /*                                  dep->domain->NbColumns); */
8195 +  /*   CANDL_set_si(m->p[m->NbRows - 2][i + 1], -1); */
8196 +  /*   CANDL_set_si(m->p[m->NbRows - 1][dep->source->depth + 1 + j], -1); */
8197 +  /*   /\* Copy the rest of the matrix. *\/ */
8198 +  /*   int ii, jj; */
8199 +  /*   for (ii = 0; ii < dep->domain->NbRows; ++ii) */
8200 +  /*     for (jj = 0; jj < dep->domain->NbColumns; ++jj) */
8201 +  /*       CANDL_assign(m->p[ii][jj], dep->domain->p[ii][jj]); */
8202 +  /*   /\* Compute real lb of loops. *\/ */
8203 +  /*   Entier lb; CANDL_init(lb); */
8204 +  /*   candl_dependence_compute_lb (m, &lb, i + 1); */
8205 +  /*   CANDL_assign(m->p[m->NbRows - 2][m->NbColumns - 1], lb); */
8206 +  /*   candl_dependence_compute_lb (m, &lb, dep->source->depth + 1 + j); */
8207 +  /*   CANDL_assign(m->p[m->NbRows - 1][m->NbColumns - 1], lb); */
8208 +  /*   int ret = candl_matrix_check_point(m, program->context); */
8209 +  /*   CANDL_clear(lb); */
8210 +
8211 +  /*   /\* Be clean. *\/ */
8212 +  /*   candl_matrix_free(m); */
8213 +
8214 +  /*   return !ret; */
8215  }
8216  
8217  
8218 @@ -2178,98 +1814,100 @@ candl_dependence_is_loop_carried (candl_program_p program,
8219   * prunes the dependence graph 'deps' by removing loop-carried
8220   * dependences involving a scalar variable privatizable for that loop.
8221   */
8222 -void
8223 -candl_dependence_prune_with_privatization (candl_program_p program,
8224 -                                          CandlOptions* options,
8225 -                                          CandlDependence** deps)
8226 -{
8227 -  CandlDependence* next;
8228 -  CandlDependence* tmp;
8229 -  CandlDependence* pred = NULL;
8230 +void candl_dependence_prune_with_privatization(osl_scop_p scop,
8231 +                                               candl_options_p options,
8232 +                                               osl_dependence_p* deps) {
8233 +  osl_dependence_p next;
8234 +  osl_dependence_p tmp;
8235 +  osl_dependence_p pred = NULL;
8236 +  candl_statement_usr_p s_usr;
8237 +  candl_statement_usr_p t_usr;
8238 +  candl_scop_usr_p scop_usr = scop->usr;
8239    int is_priv;
8240 -  int i, j;
8241 +  int i;
8242 +  int row;
8243    int loop_idx = 0;
8244    int refs, reft;
8245    int loop_pos_priv;
8246 -
8247 +  int precision = scop->context->precision;
8248  
8249    if (options->verbose)
8250      fprintf (stderr, "[Candl] Scalar Analysis: Remove loop-carried dependences"
8251 -            " on privatizable scalars\n");
8252 +             " on privatizable scalars\n");
8253  
8254 -  if (program->nb_statements == 0)
8255 +  if (scop->statement == NULL)
8256      return;
8257 +  
8258    /* Perform the scalar analysis, if not done before. */
8259 -  if (program->scalars_privatizable == NULL)
8260 -    {
8261 -      CandlOptions* options = candl_options_malloc ();
8262 -      options->scalar_privatization = 1;
8263 -      candl_dependence_analyze_scalars (program, options);
8264 -      candl_options_free (options);
8265 +  if (scop_usr->scalars_privatizable == NULL) {
8266 +    candl_options_p options = candl_options_malloc();
8267 +    options->scalar_privatization = 1;
8268 +    candl_dependence_analyze_scalars(scop, options);
8269 +    candl_options_free(options);
8270 +  }
8271 +  
8272 +  for (tmp = *deps; tmp; ) {
8273 +    s_usr = tmp->stmt_source_ptr->usr;
8274 +    t_usr = tmp->stmt_target_ptr->usr;
8275 +    
8276 +    /* Check if the dependence is involving a privatizable scalar. */
8277 +    is_priv = 1;
8278 +    candl_dependence_get_array_refs_in_dep(tmp, &refs, &reft);
8279 +    for (i = 0; i < s_usr->depth; ++i) {
8280 +      if (candl_dependence_scalar_is_privatizable_at(scop, refs,
8281 +                                                     s_usr->index[i]))
8282 +        break;
8283      }
8284 -
8285 -  for (tmp = *deps; tmp; )
8286 -    {
8287 -      /* Check if the dependence is involving a privatizable scalar. */
8288 -      is_priv = 1;
8289 -      candl_dependence_get_array_refs_in_dep (tmp, &refs, &reft);
8290 -      for (i = 0; i < tmp->source->depth; ++i)
8291 -       if (candl_dependence_scalar_is_privatizable_at (program, refs,
8292 -                                                       tmp->source->index[i]))
8293 -         break;
8294 -      if (i == tmp->source->depth)
8295 -       {
8296 -         for (i = 0; i < tmp->target->depth; ++i)
8297 -           if (candl_dependence_scalar_is_privatizable_at
8298 -               (program, reft, tmp->target->index[i]))
8299 -             break;
8300 -         if (i == tmp->target->depth)
8301 -           is_priv = 0;
8302 -         else
8303 -           loop_idx = tmp->target->index[i];
8304 -       }
8305 +    if (i == s_usr->depth) {
8306 +      for (i = 0; i < t_usr->depth; ++i) {
8307 +        if (candl_dependence_scalar_is_privatizable_at
8308 +            (scop, reft, t_usr->index[i]))
8309 +          break;
8310 +      }
8311 +      if (i == t_usr->depth)
8312 +        is_priv = 0;
8313        else
8314 -       loop_idx = tmp->source->index[i];
8315 -      loop_pos_priv = i;
8316 -      /* Check if the dependence is loop-carried at loop i. */
8317 -      if (is_priv && candl_dependence_is_loop_carried (program, tmp, loop_idx))
8318 -       {
8319 -         /* If so, make the dependence loop-independent. */
8320 -         CandlMatrix* m = candl_matrix_malloc (tmp->domain->NbRows + 1,
8321 -                                               tmp->domain->NbColumns);
8322 -         for (i = 0; i < tmp->domain->NbRows; ++i)
8323 -           for (j = 0; j < tmp->domain->NbColumns; ++j)
8324 -             CANDL_assign(m->p[i][j], tmp->domain->p[i][j]);
8325 -         candl_matrix_free (tmp->domain);
8326 -         tmp->domain = m;
8327 -         CANDL_set_si(tmp->domain->p[tmp->domain->NbRows - 1]
8328 -                      [1 + loop_pos_priv], 1);
8329 -         CANDL_set_si(tmp->domain->p[tmp->domain->NbRows - 1]
8330 -                      [1 + loop_pos_priv + tmp->source->depth], -1);
8331 -         /* Set the type of the dependence as special
8332 -            scalar-privatization one. */
8333 -         if (tmp->type == CANDL_RAW)
8334 -           tmp->type = CANDL_RAW_SCALPRIV;
8335 -         next = tmp->next;
8336 -         if (!candl_matrix_check_point (tmp->domain, NULL))
8337 -           {
8338 -             /* It is, the dependence can be removed. */
8339 -             candl_matrix_free (tmp->domain);
8340 -             if (pred == NULL)
8341 -               *deps = next;
8342 -             else
8343 -               pred->next = next;
8344 -             free (tmp);
8345 -           }
8346 -         pred = tmp;
8347 -         tmp = next;
8348 -
8349 -         continue;
8350 -       }
8351 -      /* Go to the next victim. */
8352 +        loop_idx = t_usr->index[i];
8353 +    } else {
8354 +      loop_idx = s_usr->index[i];
8355 +    }
8356 +    loop_pos_priv = i;
8357 +    
8358 +    /* Check if the dependence is loop-carried at loop i. */
8359 +    if (is_priv && candl_dependence_is_loop_carried(scop, tmp, loop_idx)) {
8360 +      /* If so, make the dependence loop-independent. */
8361 +      row = tmp->domain->nb_rows;
8362 +      osl_relation_insert_blank_row(tmp->domain, row);
8363 +      osl_int_set_si(precision,
8364 +                     &tmp->domain->m[row][1 + loop_pos_priv],
8365 +                     1);
8366 +      osl_int_set_si(precision,
8367 +                     &tmp->domain->m[row][1 + loop_pos_priv + s_usr->depth],
8368 +                     -1);
8369 +
8370 +      /* Set the type of the dependence as special
8371 +         scalar-privatization one. */
8372 +      if (tmp->type == OSL_DEPENDENCE_RAW)
8373 +        tmp->type = OSL_DEPENDENCE_RAW_SCALPRIV;
8374 +      next = tmp->next;
8375 +      if (!candl_matrix_check_point(tmp->domain, NULL)) {
8376 +        /* It is, the dependence can be removed. */
8377 +        osl_relation_free(tmp->domain);
8378 +        if (pred == NULL)
8379 +          *deps = next;
8380 +        else
8381 +          pred->next = next;
8382 +        free(tmp);
8383 +      }
8384        pred = tmp;
8385 -      tmp = tmp->next;
8386 +      tmp = next;
8387 +
8388 +      continue;
8389      }
8390 +    /* Go to the next victim. */
8391 +    pred = tmp;
8392 +    tmp = tmp->next;
8393 +  }
8394  }
8395  
8396  
8397 @@ -2278,27 +1916,29 @@ candl_dependence_prune_with_privatization (candl_program_p program,
8398   * This function checks if a given scalar 'var_index' is privatizable
8399   * for loop 'loop_index'.
8400   */
8401 -int
8402 -candl_dependence_scalar_is_privatizable_at (candl_program_p program,
8403 -                                           int var_index,
8404 -                                           int loop_index)
8405 -{
8406 +int candl_dependence_scalar_is_privatizable_at(osl_scop_p scop,
8407 +                                               int var_index,
8408 +                                               int loop_index) {
8409 +  candl_scop_usr_p scop_usr = scop->usr;
8410    int i;
8411  
8412    /* If the scalar analysis wasn't performed yet, do it. */
8413 -  if (program->scalars_privatizable == NULL)
8414 -    {
8415 -      CandlOptions* options = candl_options_malloc();
8416 -      options->scalar_privatization = 1;
8417 -      candl_dependence_analyze_scalars (program, options);
8418 -      candl_options_free (options);
8419 -    }
8420 +  if (scop_usr->scalars_privatizable == NULL) {
8421 +    candl_options_p options = candl_options_malloc();
8422 +    options->scalar_privatization = 1;
8423 +    candl_dependence_analyze_scalars(scop, options);
8424 +    candl_options_free(options);
8425 +  }
8426 +  
8427 +  i = 0;
8428 +  while (scop_usr->scalars_privatizable[i] != -1)
8429 +    i++;
8430  
8431    /* Check in the array of privatizable scalar variables for the tuple
8432       (var,loop). */
8433 -  for (i = 0; program->scalars_privatizable[i] != -1; i += 2)
8434 -    if (program->scalars_privatizable[i] == var_index &&
8435 -       program->scalars_privatizable[i + 1] == loop_index)
8436 +  for (i = 0; scop_usr->scalars_privatizable[i] != -1; i += 2)
8437 +    if (scop_usr->scalars_privatizable[i] == var_index &&
8438 +        scop_usr->scalars_privatizable[i + 1] == loop_index)
8439        return 1;
8440  
8441    return 0;
8442 @@ -2307,320 +1947,222 @@ candl_dependence_scalar_is_privatizable_at (candl_program_p program,
8443  
8444  /**
8445   * candl_dependence_analyze_scalars function:
8446 - * This function checks, for all scalar variables of the program, and
8447 + * This function checks, for all scalar variables of the scop, and
8448   * all loop levels, if the scalar can be privatized at that level.
8449   */
8450 -int
8451 -candl_dependence_analyze_scalars(candl_program_p program,
8452 -                                CandlOptions* options)
8453 -{
8454 +int candl_dependence_analyze_scalars(osl_scop_p scop,
8455 +                                     candl_options_p options) {
8456    int* scalars;
8457 -  CandlStatement** stmts;
8458 -  CandlStatement** fullchain = NULL;
8459 -  int i, j, k, l, n;
8460 -  CandlMatrix* m;
8461 -  int max, is_priv, cpt, offset, was_priv;
8462 -  CandlStatement* curlast;
8463 -  CandlStatement* last;
8464 +  osl_statement_p* statement; /* not a chained list, but an array of */
8465 +  osl_statement_p* fullchain; /* statement to not realloc the usr field */
8466 +  osl_statement_p s;
8467 +  osl_statement_p curlast;
8468 +  osl_statement_p last;
8469 +  osl_statement_p iter; /* used to iterate on the scop */
8470 +  osl_relation_list_p access;
8471 +  osl_relation_p elt;
8472 +  candl_scop_usr_p scop_usr = scop->usr;
8473 +  candl_statement_usr_p stmt_usr;
8474 +  int i, j, k;
8475 +  int max, is_priv, offset, was_priv;
8476    int nb_priv = 0;
8477    int priv_buff_size = 64;
8478 +  int id, row;
8479  
8480    /* Initialize the list of privatizable scalars to empty. */
8481 -  if (options->scalar_privatization)
8482 -    {
8483 -      program->scalars_privatizable = (int*) malloc(2 * sizeof(int));
8484 -      program->scalars_privatizable[0] = program->scalars_privatizable[1] = -1;
8485 -    }
8486 +  if (options->scalar_privatization) {
8487 +    CANDL_malloc(scop_usr->scalars_privatizable, int*, 2 * sizeof(int));
8488 +    scop_usr->scalars_privatizable[0] = -1;
8489 +    scop_usr->scalars_privatizable[1] = -1;
8490 +  }
8491  
8492    /* Retrieve all scalar variables. */
8493 -  scalars = candl_dependence_extract_scalar_variables (program);
8494 +  scalars = candl_dependence_extract_scalar_variables(scop);
8495  
8496    /* For each of those, detect (at any level) if it can be privatized
8497       / expanded / renamed. */
8498 -  for (i = 0; scalars[i] != -1; ++i)
8499 -    {
8500 -      /* Go to the first statement referencing the scalar. */
8501 -      for (j = 0; j < program->nb_statements; ++j)
8502 -       if (candl_dependence_var_is_ref (program->statement[j], scalars[i])
8503 -           != CANDL_VAR_UNDEF)
8504 -         break;
8505 -      /* A weird error occured. */
8506 -      if (j == program->nb_statements)
8507 -       continue;
8508 -
8509 -      /* Take all statements referencing the scalar. */
8510 -      fullchain = candl_dependence_refvar_chain (program, program->statement[j],
8511 -                                                scalars[i], 0);
8512 -      /* Compute the maximum loop depth of the chain. */
8513 -      for (k = 0, max = 0; fullchain[k]; ++k)
8514 -       max = max < fullchain[k]->depth ? fullchain[k]->depth : max;
8515 -      last = fullchain[k - 1];
8516 -      /* Initialize the offset for expansion. */
8517 -      offset = 0;
8518 -      was_priv = 0;
8519 -      /* Iterate on all possible depth for analysis. */
8520 -      for (k = 1; k <= max; ++k)
8521 -       {
8522 -         CandlStatement* s = fullchain[0];
8523 -         if (was_priv)
8524 -           {
8525 -             ++offset;
8526 -             was_priv = 0;
8527 -           }
8528 -         do
8529 -           {
8530 -             /* Take all statements dominated by s referencing the
8531 -                current scalar variable. */
8532 -             stmts = candl_dependence_refvar_chain (program, s, scalars[i], k);
8533 -             /* No more statement in the chain, exit. */
8534 -             if (stmts[0] == NULL)
8535 -               break;
8536 -             int c = 0;
8537 -             is_priv = candl_dependence_var_is_ref (stmts[c], scalars[i])
8538 -               == CANDL_VAR_IS_DEF;
8539 -             /* Ensure we have a use in the chain. */
8540 -             for (l = c + 1; stmts[l - 1] && stmts[l]; ++l)
8541 -               if (candl_dependence_var_is_ref (stmts[l], scalars[i]) ==
8542 -                   CANDL_VAR_IS_USED)
8543 -                 break;
8544 -             if (stmts[l - 1] == NULL || stmts[l] == NULL)
8545 -               is_priv = 0;
8546 -             /* Check for privatization, while the entry of the chain
8547 -                is a DEF. */
8548 -             while (stmts[c] && candl_dependence_var_is_ref
8549 -                    (stmts[c], scalars[i]) == CANDL_VAR_IS_DEF)
8550 -               {
8551 -                 /* From the current DEF node, ensure the rest of the
8552 -                    chain covers not more than the iteration domain
8553 -                    of the DEF. */
8554 -                 for (l = c + 1; stmts[l - 1] && stmts[l]; ++l)
8555 -                   /* FIXME: we should deal with
8556 -                      def_1->use->def_2->use chains where dom(def_2)
8557 -                      > dom(def_1). */
8558 -                   if (! candl_dependence_check_domain_is_included
8559 -                       (stmts[c], stmts[l], program->context, k))
8560 -                     {
8561 -                       /* dom(use) - dom(def) > 0. Check if there is
8562 -                          another DEF to test at the entry of the
8563 -                          block. */
8564 -                       if (stmts[c + 1])
8565 -                         if (candl_dependence_var_is_ref
8566 -                             (stmts[c + 1], scalars[i]) != CANDL_VAR_IS_DEF)
8567 -                           /* No. The variable is not privatizable. */
8568 -                           is_priv = 0;
8569 -                       break;
8570 -                     }
8571 -                 if (! is_priv || ! stmts[l])
8572 -                   break;
8573 -                 /* The chain dominated by stmts[c] is not
8574 -                    privatizable. Go for the next DEF at the
8575 -                    beginning of the block, if any. */
8576 -                 ++c;
8577 -               }
8578 -             if (is_priv)
8579 -               {
8580 -                 /* Perform the privatization / expansion. */
8581 -                 if (options->verbose)
8582 -                   fprintf (stderr, "[Candl] Scalar Analysis: The variable %d"
8583 -                            " can be privatized at loop %d\n",
8584 -                            scalars[i], stmts[0]->index[k - 1]);
8585 -                 if (options->scalar_expansion)
8586 -                   /* Traverse all statements in the chain. */
8587 -                   for (l = c; stmts[l]; ++l)
8588 -                     {
8589 -                       /* It's not the first expansion of the scalar,
8590 -                          we need to increase its dimension all along
8591 -                          the program. */
8592 -                       if (offset && !was_priv)
8593 -                         candl_dependence_expand_scalar (fullchain,
8594 -                                                         scalars[i]);
8595 -                       /* Perform scalar expansion in the array
8596 -                          access functions. */
8597 -                       for (cpt = 0, m = stmts[l]->read; cpt < 2;
8598 -                            ++cpt, m = stmts[l]->written)
8599 -                         for (n = 0; n < m->NbRows; ++n)
8600 -                           if (CANDL_get_si(m->p[n][0]) == scalars[i])
8601 -                             CANDL_set_si(m->p[n + offset][k], 1);
8602 -                       was_priv = 1;
8603 -                     }
8604 -                 if (options->scalar_privatization)
8605 -                   {
8606 -                     /* Memory management for the array of
8607 -                        privatizable scalars. */
8608 -                     if (nb_priv == 0)
8609 -                       {
8610 -                         free (program->scalars_privatizable);
8611 -                         program->scalars_privatizable =
8612 -                           (int*)malloc(priv_buff_size * sizeof(int));
8613 -                         for (l = 0; l < priv_buff_size; ++l)
8614 -                           program->scalars_privatizable[l] = -1;
8615 -                       }
8616 -                     if (nb_priv == priv_buff_size)
8617 -                       {
8618 -                         program->scalars_privatizable =
8619 -                           realloc(program->scalars_privatizable,
8620 -                                   (priv_buff_size *= 2) * sizeof(int));
8621 -                         for (l = nb_priv; l < priv_buff_size; ++l)
8622 -                           program->scalars_privatizable[l] = -1;
8623 -                       }
8624 -                     /* Memorize the scalar information in the
8625 -                        privatizable list. */
8626 -                     program->scalars_privatizable[nb_priv++] = scalars[i];
8627 -                     program->scalars_privatizable[nb_priv++] =
8628 -                       stmts[0]->index[k - 1];
8629 -                   }
8630 -               }
8631 -             /* Go to the next block, if any. */
8632 -             for (l = 0; stmts[l]; ++l)
8633 -               ;
8634 -             curlast = stmts[l - 1];
8635 -             if (curlast != last)
8636 -               {
8637 -                 for (l = 0; fullchain[l]; ++l)
8638 -                   if (fullchain[l] == curlast)
8639 -                     s = fullchain[l + 1];
8640 -               }
8641 -             free (stmts);
8642 -           }
8643 -         while (curlast != last);
8644 -       }
8645 -      free (fullchain);
8646 +  for (i = 0; scalars[i] != -1; ++i) {
8647 +    /* Go to the first statement referencing the scalar in the scop. */
8648 +    for (iter = scop->statement; iter != NULL; iter = iter->next) {
8649 +      if (candl_dependence_var_is_ref(iter, scalars[i])
8650 +          != CANDL_VAR_UNDEF)
8651 +        break;
8652      }
8653 -
8654 -  return 0;
8655 -}
8656 -
8657 -
8658 -/**
8659 - * candl_num_dependences function:
8660 - * This function returns the number of dependences in the dependence
8661 - * list
8662 - * \param dependence The first dependence of the dependence list.
8663 - **
8664 - */
8665 -int
8666 -candl_num_dependences(CandlDependence *candl_deps)
8667 -{
8668 -    CandlDependence *candl_dep = candl_deps;
8669 -
8670 -    int num = 0;
8671 -    while (candl_dep != NULL)
8672 -    {
8673 -        num++;
8674 -        candl_dep = candl_dep->next;
8675 +    
8676 +    /* A weird error occured. */
8677 +    if (iter == NULL)
8678 +      continue;
8679 +    
8680 +    /* Take all statements referencing the scalar. */
8681 +    fullchain = candl_dependence_refvar_chain(scop, iter, scalars[i], 0);
8682 +
8683 +    /* Compute the maximum loop depth of the chain. */
8684 +    max = 0;
8685 +    for (k = 0; fullchain[k]; ++k) {
8686 +      stmt_usr = fullchain[k]->usr;
8687 +      if (max < stmt_usr->depth)
8688 +        max = stmt_usr->depth;
8689      }
8690 -    return num;
8691 -}
8692 -
8693 -
8694 -/*
8695 - * Convert a PIP quast to a union of polyhedra (Pip matrices)
8696 - *
8697 - * num: number of Pip matrices returned
8698 - *
8699 - **/
8700 -static
8701 -PipMatrix **quast_to_polyhedra (PipQuast *quast, int *num,
8702 -                               int nvar, int npar)
8703 -{
8704 -    int num1, num2;
8705 -    PipMatrix** ep;
8706 -    PipMatrix** tp;
8707 -    PipMatrix** qp;
8708 -    int i, j;
8709 -    if (quast == NULL)
8710 -      {
8711 -        *num = 0;
8712 -        return NULL;
8713 -      }
8714 -
8715 -    if (quast->condition != NULL)
8716 -      {
8717 -        tp = quast_to_polyhedra(quast->next_then, &num1, nvar, npar);
8718 -        ep = quast_to_polyhedra(quast->next_else, &num2, nvar, npar);
8719 -
8720 -        /* Each of the matrices in the then tree needs to be augmented with
8721 -         * the condition */
8722 -        for (i = 0; i < num1; i++)
8723 -         {
8724 -           int nrows = tp[i]->NbRows;
8725 -           CANDL_set_si(tp[i]->p[nrows][0], 1);
8726 -           for (j = 1; j < 1 + nvar; j++)
8727 -             CANDL_set_si(tp[i]->p[nrows][j], 0);
8728 -           for (j = 0; j < npar + 1; j++)
8729 -             CANDL_assign(tp[i]->p[nrows][1+nvar+j],
8730 -                          quast->condition->the_vector[j]);
8731 -           (tp[i]->NbRows)++;
8732 -         }
8733 -
8734 -        for (i = 0; i < num2; i++)
8735 -         {
8736 -           int nrows = ep[i]->NbRows;
8737 -           /* Inequality */
8738 -           CANDL_set_si(ep[i]->p[nrows][0], 1);
8739 -           for (j = 1; j < 1 + nvar; j++)
8740 -             CANDL_set_si(ep[i]->p[nrows][j], 0);
8741 -           for (j = 0; j < npar + 1; j++)
8742 -             CANDL_set_si(ep[i]->p[nrows][1+nvar+j],
8743 -                          -CANDL_get_si(quast->condition->the_vector[j]));
8744 -           (ep[i]->NbRows)++;
8745 -         }
8746 -
8747 -        qp = (PipMatrix **) malloc((num1 + num2) * sizeof(PipMatrix*));
8748 -       for (i = 0; i < num1; ++i)
8749 -         qp[i] = tp[i];
8750 -       for (i = 0; i < num2; ++i)
8751 -         qp[i + num1] = ep[i];
8752 -
8753 -        *num = num1 + num2;
8754 -
8755 -        return qp;
8756 -
8757 +    last = fullchain[k-1];
8758 +    
8759 +    /* Initialize the offset for expansion. */
8760 +    offset = 0;
8761 +    was_priv = 0;
8762 +    
8763 +    /* Iterate on all possible depth for analysis. */
8764 +    for (j = 1; j <= max; ++j) {
8765 +      s = fullchain[0];
8766 +      
8767 +      if (was_priv) {
8768 +        ++offset;
8769 +        was_priv = 0;
8770        }
8771 -    else
8772 -      {
8773 -        /* quast condition is NULL */
8774 -        PipMatrix *lwmatrix = pip_matrix_alloc(nvar+npar+1, nvar+npar+2);
8775 -
8776 -        PipList *vecList = quast->list;
8777 -
8778 -        int count=0;
8779 -        while (vecList != NULL) {
8780 -         /* Equality */
8781 -         CANDL_set_si(lwmatrix->p[count][0], 0);
8782 -         for (j=0; j<nvar; j++)
8783 -           if (j == count)
8784 -             CANDL_set_si(lwmatrix->p[count][j+1], 1);
8785 -           else
8786 -             CANDL_set_si(lwmatrix->p[count][j+1], 0);
8787 -
8788 -         for (j=0; j<npar; j++)
8789 -           CANDL_set_si(lwmatrix->p[count][j+1+nvar],
8790 -                        -CANDL_get_si(vecList->vector->the_vector[j]));
8791 -         /* Constant portion */
8792 -         if (quast->newparm != NULL)
8793 -           /* Don't handle newparm for now */
8794 -           CANDL_set_si(lwmatrix->p[count][npar+1+nvar],
8795 -                        -CANDL_get_si(vecList->vector->the_vector[npar+1]));
8796 -         else
8797 -           CANDL_set_si(lwmatrix->p[count][npar+1+nvar],
8798 -                        -CANDL_get_si(vecList->vector->the_vector[npar]));
8799 -
8800 -         count++;
8801 -
8802 -         vecList = vecList->next;
8803 +      
8804 +      do {
8805 +        /* Take all statements dominated by s referencing the
8806 +           current scalar variable. */
8807 +        statement = candl_dependence_refvar_chain(scop, s, scalars[i], j);
8808 +        
8809 +        /* No more statement in the chain, exit. */
8810 +        if (statement[0] == NULL) {
8811 +          free(statement);
8812 +          break;
8813          }
8814 -        lwmatrix->NbRows = count;
8815 -
8816 -        if (count > 0)
8817 -         *num = 1;
8818 -        else
8819 -         *num = 0;
8820 +        
8821 +        int c = 0;
8822 +        
8823 +        is_priv = candl_dependence_var_is_ref(statement[0], scalars[i]) ==
8824 +                  CANDL_VAR_IS_DEF;
8825 +        
8826 +        /* Ensure we have a use in the chain. */
8827 +        /* here statement[c] is not NULL */
8828 +        for (k = c + 1; statement[k]; ++k) {
8829 +          if (candl_dependence_var_is_ref(statement[k], scalars[i]) ==
8830 +              CANDL_VAR_IS_USED)
8831 +            break;
8832 +        }
8833 +        
8834 +        if (statement[k] == NULL)
8835 +          is_priv = 0;
8836 +          
8837 +        /* Check for privatization, while the entry of the chain
8838 +           is a DEF. */
8839 +        while (statement[c] && candl_dependence_var_is_ref
8840 +               (statement[c], scalars[i]) == CANDL_VAR_IS_DEF) {
8841 +          /* From the current DEF node, ensure the rest of the
8842 +             chain covers not more than the iteration domain
8843 +             of the DEF. */
8844 +          for (k = c + 1; statement[k]; ++k) {
8845 +            /* FIXME: we should deal with
8846 +               def_1->use->def_2->use chains where dom(def_2)
8847 +               > dom(def_1). */
8848 +            if (! candl_dependence_check_domain_is_included
8849 +                (statement[c], statement[k], scop->context, j)) {
8850 +              /* dom(use) - dom(def) > 0. Check if there is
8851 +                 another DEF to test at the entry of the
8852 +                 block. */
8853 +              if (candl_dependence_var_is_ref
8854 +                  (statement[c+1], scalars[i]) != CANDL_VAR_IS_DEF)
8855 +                /* No. The variable is not privatizable. */
8856 +                is_priv = 0;
8857 +              break;
8858 +            }
8859 +          }
8860 +
8861 +          if (! is_priv || ! statement[k])
8862 +            break;
8863 +
8864 +          /* The chain dominated by statement is not
8865 +             privatizable. Go for the next DEF at the
8866 +             beginning of the block, if any. */
8867 +          ++c;
8868 +        }
8869 +        
8870 +        if (is_priv) {
8871 +          /* Perform the privatization / expansion. */
8872 +          if (options->verbose)
8873 +            fprintf(stderr, "[Candl] Scalar Analysis: The variable %d"
8874 +                     " can be privatized at loop %d\n",
8875 +                     scalars[i], 
8876 +                     ((candl_statement_usr_p)statement[0]->usr)->index[j-1]);
8877 +
8878 +          if (options->scalar_expansion) {
8879 +            int precision = scop->context->precision;
8880 +            /* Traverse all statements in the chain. */
8881 +            for (k = c; statement[k]; ++k) {
8882 +              /* It's not the first expansion of the scalar,
8883 +                 we need to increase its dimension all along
8884 +                 the program. */
8885 +              if (!offset && !was_priv)
8886 +                candl_dependence_expand_scalar(fullchain,
8887 +                                               scalars[i]);
8888 +              /* Perform scalar expansion in the array
8889 +                 access functions. */
8890 +              access = statement[k]->access;
8891 +              for (; access != NULL; access = access->next) {
8892 +                elt = access->elt;
8893 +                id = osl_relation_get_array_id(elt);
8894 +                if (scalars[i] == id) {
8895 +                  row = candl_util_relation_get_line(elt, offset+1);
8896 +                  osl_int_set_si(precision, &elt->m[row][elt->nb_output_dims + j], 1);
8897 +                }
8898 +              }
8899 +              was_priv = 1;
8900 +            }
8901 +          }
8902 +          
8903 +          if (options->scalar_privatization) {
8904 +            /* Memory management for the array of
8905 +               privatizable scalars. */
8906 +            if (nb_priv == 0) {
8907 +              free(scop_usr->scalars_privatizable);
8908 +              CANDL_malloc(scop_usr->scalars_privatizable, 
8909 +                           int*, priv_buff_size * sizeof(int));
8910 +              for (k = 0; k < priv_buff_size; ++k)
8911 +                scop_usr->scalars_privatizable[k] = -1;
8912 +            }
8913 +
8914 +            if (nb_priv == priv_buff_size) {
8915 +              CANDL_realloc(scop_usr->scalars_privatizable, 
8916 +                            int*, (priv_buff_size *= 2) * sizeof(int));
8917 +              for (k = nb_priv; k < priv_buff_size; ++k)
8918 +                scop_usr->scalars_privatizable[k] = -1;
8919 +            }
8920 +          
8921 +            /* Memorize the scalar information in the
8922 +               privatizable list. */
8923 +            scop_usr->scalars_privatizable[nb_priv++] = scalars[i];
8924 +            scop_usr->scalars_privatizable[nb_priv++] =
8925 +                ((candl_statement_usr_p)statement[0]->usr)->index[j - 1];
8926 +          }
8927 +          
8928 +        } // end is_priv
8929 +
8930 +        
8931 +        /* Go to the next block, if any. */
8932 +        for (k = 0; statement[k]; ++k)
8933 +          ;
8934 +        curlast = statement[k-1];
8935 +
8936 +        if (curlast != last) {
8937 +          for (k = 0; fullchain[k]; ++k) {
8938 +            if (fullchain[k] == curlast) {
8939 +              s = fullchain[k+1];
8940 +              break;
8941 +            }
8942 +          }
8943 +        }
8944 +        free(statement);
8945 +        
8946 +      } while (curlast != last);
8947 +      
8948 +    } // end iterate all possible depth
8949 +    
8950 +    free(fullchain);
8951 +    
8952 +  } // end iterate scalars
8953  
8954 -       PipMatrix** ret = (PipMatrix**) malloc(sizeof(PipMatrix*));
8955 -       ret[0] = lwmatrix;
8956 -        return ret;
8957 -      }
8958 +  return 0;
8959  }
8960  
8961  
8962 @@ -2631,119 +2173,142 @@ PipMatrix **quast_to_polyhedra (PipQuast *quast, int *num,
8963   * Returns 0 if lastwriter is computed successfully and dep domain updated,
8964   * returns 1 otherwise
8965   */
8966 -static
8967 -int candl_dep_compute_lastwriter (CandlDependence **dep, CandlProgram *prog)
8968 -{
8969 -    PipQuast *lexmax;
8970 -    PipMatrix *new_domain;
8971 -
8972 -    int i, j;
8973 -
8974 -    int npar = prog->context->NbColumns-2;
8975 -
8976 -    PipOptions *pipOptions = pip_options_init();
8977 -
8978 -    /* We do a parametric lexmax on the source iterators
8979 -     * keeping the target iterators as parameters */
8980 -    pipOptions->Maximize = 1;
8981 -    pipOptions->Simplify = 1;
8982 -    // pipOptions->Deepest_cut = 1;
8983 -    // pipOptions->Urs_unknowns = -1;
8984 -    // pipOptions->Urs_parms = -1;
8985 -
8986 -    /* Build a context with equalities /inequalities only on the target
8987 -     * variables */
8988 -    PipMatrix *context = pip_matrix_alloc((*dep)->domain->NbRows,
8989 -                                         (*dep)->target->depth + npar + 2);
8990 -
8991 -    int nrows = 0;
8992 -    for (i = 0; i < (*dep)->domain->NbRows; i++)
8993 -      {
8994 -       for (j = 1; j < (*dep)->source->depth+1; j++)
8995 -         {
8996 -           if ((*dep)->domain->p[i][j] != 0)
8997 -             break;
8998 -         }
8999 -       if (j == (*dep)->source->depth+1)
9000 -         {
9001 -           /* Include this in the context */
9002 -           CANDL_assign(context->p[nrows][0], (*dep)->domain->p[i][0]);
9003 -           for (j = 1; j < 1 + (*dep)->target->depth + npar + 1; j++)
9004 -             CANDL_assign(context->p[nrows][j],
9005 -                          (*dep)->domain->p[i][(*dep)->source->depth+j]);
9006 -
9007 -           nrows++;
9008 -         }
9009 -      }
9010 -    context->NbRows = nrows;
9011 +static 
9012 +int candl_dep_compute_lastwriter(osl_dependence_p *dep, osl_scop_p scop) {
9013 +  PipQuast *lexmax;
9014 +  PipOptions *pipOptions = pip_options_init();
9015 +  candl_statement_usr_p s_usr = (*dep)->stmt_source_ptr->usr;
9016 +  candl_statement_usr_p t_usr = (*dep)->stmt_target_ptr->usr;
9017 +  osl_relation_p new_domain;
9018 +  int i, j;
9019 +  int npar = scop->context->nb_parameters;
9020 +  int precision;
9021 +  
9022 +  #if defined(CANDL_LINEAR_VALUE_IS_INT)
9023 +    precision = OSL_PRECISION_SP;
9024 +  #elif defined(CANDL_LINEAR_VALUE_IS_LONGLONG)
9025 +    precision = OSL_PRECISION_DP;
9026 +  #elif defined(CANDL_LINEAR_VALUE_IS_MP)
9027 +    precision = OSL_PRECISION_MP;
9028 +  #endif
9029 +  
9030 +  if (precision != scop->context->precision) {
9031 +    CANDL_error("Precision not compatible with piplib ! (pip_relation2matrix)");
9032 +  }
9033  
9034 -    /* Parameteric lexmax */
9035 -    lexmax = pip_solve((*dep)->domain, context, -1, pipOptions);
9036 +  /* We do a parametric lexmax on the source iterators
9037 +   * keeping the target iterators as parameters */
9038 +  pipOptions->Maximize = 1;
9039 +  pipOptions->Simplify = 1;
9040 +  // pipOptions->Deepest_cut = 1;
9041 +  // pipOptions->Urs_unknowns = -1;
9042 +  // pipOptions->Urs_parms = -1;
9043 +
9044 +  /* Build a context with equalities /inequalities only on the target
9045 +   * variables */
9046 +  osl_relation_p context = osl_relation_pmalloc(precision, 
9047 +                                   (*dep)->domain->nb_rows,
9048 +                                   (*dep)->stmt_target_ptr->domain->nb_columns);
9049 +  int nrows = 0;
9050 +  for (i = 0; i < (*dep)->domain->nb_rows; i++) {
9051 +    for (j = 1; j < s_usr->depth+1; j++) {
9052 +
9053 +      // FIXME : new domain structure for dependence
9054 +
9055 +      if (!osl_int_zero(precision, (*dep)->domain->m[i][j]))
9056 +        break;
9057 +    }
9058 +    
9059 +    if (j == t_usr->depth+1) {
9060 +      /* Include this in the context */
9061 +      osl_int_assign(precision,
9062 +                     &context->m[nrows][0], (*dep)->domain->m[i][0]);
9063 +      
9064 +      for (j = 1; j < (*dep)->stmt_target_ptr->domain->nb_columns; j++)
9065 +        osl_int_assign(precision,
9066 +                       &context->m[nrows][j],
9067 +                       (*dep)->domain->m[i][s_usr->depth+j]);
9068 +
9069 +      nrows++;
9070 +    }
9071 +  }
9072  
9073 -    pip_options_free(pipOptions);
9074 +  /* Parameteric lexmax */
9075 +  lexmax = pip_solve_osl((*dep)->domain, context, -1, pipOptions);
9076  
9077 -    if (lexmax == NULL)
9078 -      {
9079 -        printf("WARNING: last writer failed (mostly invalid dependence): %s\n",
9080 -               "bailing out safely without modification");
9081 -        pip_matrix_print(stdout, (*dep)->domain);
9082 -        pip_matrix_print(stdout, context);
9083 -        return 1;
9084 -      }
9085 +  pip_options_free(pipOptions);
9086 +
9087 +  if (lexmax == NULL) {
9088 +    CANDL_warning("last writer failed (mostly invalid dependence): bailing out"
9089 +                  "safely without modification");
9090 +    osl_relation_print(stderr, context);
9091 +    osl_relation_print(stderr, (*dep)->domain);
9092 +    return 1;
9093 +  }
9094  
9095 -    int num;
9096 -    PipMatrix **qp = quast_to_polyhedra(lexmax, &num, (*dep)->source->depth,
9097 -                                       (*dep)->target->depth + npar);
9098 -
9099 -    /* Update the dependence domains */
9100 -    if (num > 0)
9101 -      {
9102 -       int it_mat;
9103 -       PipMatrix* original_domain = (*dep)->domain;
9104 -       for (it_mat = 0; it_mat < num; ++it_mat)
9105 -         {
9106 -           new_domain = pip_matrix_alloc(original_domain->NbRows +
9107 -                                         qp[it_mat]->NbRows,
9108 -                                         original_domain->NbColumns);
9109 -           for (i = 0; i < original_domain->NbRows; i++)
9110 -             for (j = 0; j < original_domain->NbColumns; j++)
9111 -               CANDL_assign(new_domain->p[i][j], original_domain->p[i][j]);
9112 -
9113 -           for (i = 0; i < qp[it_mat]->NbRows; i++)
9114 -             for (j = 0; j < original_domain->NbColumns; j++)
9115 -               CANDL_assign(new_domain->p[i+original_domain->NbRows][j],
9116 -                            qp[it_mat]->p[i][j]);
9117 -
9118 -           (*dep)->domain = new_domain;
9119 -           /* More than 1 pipmatrix from the quast, we need to insert
9120 -              new dependences to have the union of domains. */
9121 -           if (it_mat < num - 1)
9122 -             {
9123 -               CandlDependence* newdep = candl_dependence_malloc ();
9124 -               newdep->source = (*dep)->source;
9125 -               newdep->target = (*dep)->target;
9126 -               newdep->depth = (*dep)->depth;
9127 -               newdep->type = (*dep)->type;
9128 -               newdep->ref_source = (*dep)->ref_source;
9129 -               newdep->ref_target = (*dep)->ref_target;
9130 -               newdep->usr = (*dep)->usr;
9131 -               newdep->next = (*dep)->next;
9132 -               (*dep)->next = newdep;
9133 -               *dep = newdep;
9134 -             }
9135 -         }
9136 -
9137 -       pip_matrix_free(original_domain);
9138 -       for (i = 0; i < num; ++i)
9139 -         pip_matrix_free(qp[i]);
9140 +  osl_relation_p qp = pip_quast_to_polyhedra(lexmax, s_usr->depth,
9141 +                                             t_usr->depth + npar);
9142 +
9143 +  /* Update the dependence domains */
9144 +  if (osl_relation_nb_components(qp) > 0) {
9145 +    osl_relation_p iter;
9146 +    osl_relation_p original_domain = (*dep)->domain;
9147 +    for (iter = qp ; iter != NULL ; iter = iter->next) {
9148 +
9149 +      new_domain = osl_relation_pmalloc(precision,
9150 +                                    original_domain->nb_rows +
9151 +                                    qp->nb_rows,
9152 +                                    original_domain->nb_columns);
9153 +
9154 +      for (i = 0; i < original_domain->nb_rows; i++)
9155 +        for (j = 0; j < original_domain->nb_columns; j++)
9156 +          osl_int_assign(precision,
9157 +                         &new_domain->m[i][j],
9158 +                         original_domain->m[i][j]);
9159 +
9160 +      for (i = 0; i < qp->nb_rows; i++)
9161 +        for (j = 0; j < original_domain->nb_columns; j++)
9162 +          osl_int_assign(precision,
9163 +                         &new_domain->m[i+original_domain->nb_rows][j],
9164 +                         qp->m[i][j]);
9165 +
9166 +      (*dep)->domain = new_domain;
9167 +      /* More than 1 pipmatrix from the quast, we need to insert
9168 +         new dependences to have the union of domains. */
9169 +      if (qp->next != NULL) {
9170 +        osl_dependence_p newdep = osl_dependence_malloc();
9171 +        newdep->stmt_source_ptr = (*dep)->stmt_source_ptr;
9172 +        newdep->stmt_target_ptr = (*dep)->stmt_target_ptr;
9173 +        newdep->depth = (*dep)->depth;
9174 +        newdep->type = (*dep)->type;
9175 +        newdep->label_source = (*dep)->label_source;
9176 +        newdep->label_target = (*dep)->label_target;
9177 +        newdep->ref_source = (*dep)->ref_source;
9178 +        newdep->ref_target = (*dep)->ref_target;
9179 +        newdep->usr = (*dep)->usr;
9180 +        newdep->source_nb_output_dims_domain = (*dep)->source_nb_output_dims_domain;
9181 +        newdep->source_nb_output_dims_access = (*dep)->source_nb_output_dims_access;
9182 +        newdep->target_nb_output_dims_domain = (*dep)->target_nb_output_dims_domain;
9183 +        newdep->target_nb_output_dims_access = (*dep)->target_nb_output_dims_access;
9184 +        newdep->source_nb_local_dims_domain  = (*dep)->source_nb_local_dims_domain;
9185 +        newdep->source_nb_local_dims_access  = (*dep)->source_nb_local_dims_access;
9186 +        newdep->target_nb_local_dims_domain  = (*dep)->target_nb_local_dims_domain;
9187 +        newdep->target_nb_local_dims_access  = (*dep)->target_nb_local_dims_access;
9188 +        newdep->next = (*dep)->next;
9189 +        (*dep)->next = newdep;
9190 +        *dep = newdep;
9191        }
9192 +    }
9193  
9194 -    if (qp)
9195 -      free(qp);
9196 -    pip_quast_free(lexmax);
9197 -    pip_matrix_free(context);
9198 +    osl_relation_free(original_domain);
9199 +    osl_relation_free(qp);
9200 +  }
9201  
9202 -    return 0;
9203 +  pip_quast_free(lexmax);
9204 +  osl_relation_free(qp);
9205 +  osl_relation_free(context);
9206 +
9207 +  return 0;
9208  }
9209  
9210  /**
9211 @@ -2751,16 +2316,15 @@ int candl_dep_compute_lastwriter (CandlDependence **dep, CandlProgram *prog)
9212   * modify the dependence polyhedra. Be careful of any references to the old
9213   * dependence polyhedra. They are freed and new ones allocated.
9214   */
9215 -void candl_compute_last_writer (CandlDependence *dep, CandlProgram *prog)
9216 -{
9217 +void candl_compute_last_writer(osl_dependence_p dep, osl_scop_p scop) {
9218    // int count=0;
9219 -    while (dep != NULL)    {
9220 -        if (dep->type != CANDL_WAR)   {
9221 -         // printf("Last writer for dep %d: %d %d\n", count++, dep->source->depth, dep->target->depth);
9222 -            // candl_matrix_print(stdout, dep->domain);
9223 -            candl_dep_compute_lastwriter(&dep, prog);
9224 -            // candl_matrix_print(stdout, dep->domain);
9225 -        }
9226 -        dep = dep->next;
9227 +  while (dep != NULL)    {
9228 +    if (dep->type != OSL_DEPENDENCE_WAR)   {
9229 +      // printf("Last writer for dep %d: %d %d\n", count++, dep->source->usr->depth, dep->target->usr->depth);
9230 +      // candl_matrix_print(stdout, dep->domain);
9231 +      candl_dep_compute_lastwriter(&dep, scop);
9232 +      // candl_matrix_print(stdout, dep->domain);
9233      }
9234 +    dep = dep->next;
9235 +  }
9236  }
9237 diff --git a/source/isl-wrapper.c b/source/isl-wrapper.c
9238 index 870c9c9..36d9b05 100644
9239 --- a/source/isl-wrapper.c
9240 +++ b/source/isl-wrapper.c
9241 @@ -6,8 +6,8 @@
9242      **----  \#/  --------------------------------------------------------**
9243      **    .-"#'-.        First version: January 31st 2011                **
9244      **--- |"-.-"| -------------------------------------------------------**
9245 -          |     |
9246 -          |     |
9247 +    |     |
9248 +    |     |
9249   ******** |     | *************************************************************
9250   * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
9251   ******************************************************************************
9252 @@ -41,19 +41,18 @@
9253  #include <stdlib.h>
9254  #include <stdio.h>
9255  #include <string.h>
9256 -#include <candl/candl.h>
9257 +#include <osl/relation.h>
9258  
9259 -# ifdef CANDL_SUPPORTS_ISL
9260 -
9261 -# undef Q
9262 -# include <isl/constraint.h>
9263 -# include <isl/map.h>
9264 -# include <isl/map.h>
9265 -# include <isl/set.h>
9266 -# include <isl/dim.h>
9267 -# include <isl/seq.h>
9268 -# include <isl/ctx.h>
9269 +#ifdef CANDL_SUPPORTS_ISL
9270  
9271 +#undef Q
9272 +#include <isl/constraint.h>
9273 +#include <isl/map.h>
9274 +#include <isl/map.h>
9275 +#include <isl/set.h>
9276 +#include <isl/dim.h>
9277 +#include <isl/seq.h>
9278 +#include <isl/ctx.h>
9279  
9280  
9281  /// WARNING: This is hard-coding that ISL uses GMP.
9282 @@ -66,8 +65,7 @@
9283   */
9284  static
9285  struct isl_constraint*
9286 -isl_constraint_read_from_matrix(struct isl_dim* dim, Entier* row)
9287 -{
9288 +isl_constraint_read_from_matrix(struct isl_dim* dim, Entier* row) {
9289    struct isl_constraint* constraint;
9290    int j;
9291    int nvariables = isl_dim_size(dim, isl_dim_set);
9292 @@ -79,17 +77,15 @@ isl_constraint_read_from_matrix(struct isl_dim* dim, Entier* row)
9293    else
9294      constraint = isl_inequality_alloc(dim);
9295  
9296 -  for (j = 0; j < nvariables; ++j)
9297 -    {
9298 -      mpz_set_si(val, CANDL_get_si(row[1 + j]));
9299 -      isl_constraint_set_coefficient(constraint, isl_dim_out, j, val);
9300 -    }
9301 +  for (j = 0; j < nvariables; ++j) {
9302 +    mpz_set_si(val, CANDL_get_si(row[1 + j]));
9303 +    isl_constraint_set_coefficient(constraint, isl_dim_out, j, val);
9304 +  }
9305  
9306 -  for (j = 0; j < nparam; ++j)
9307 -    {
9308 -      mpz_set_si(val, CANDL_get_si(row[1 + nvariables + j]));
9309 -      isl_constraint_set_coefficient(constraint, isl_dim_param, j, val);
9310 -    }
9311 +  for (j = 0; j < nparam; ++j) {
9312 +    mpz_set_si(val, CANDL_get_si(row[1 + nvariables + j]));
9313 +    isl_constraint_set_coefficient(constraint, isl_dim_param, j, val);
9314 +  }
9315  
9316    mpz_set_si(val, CANDL_get_si(row[1 + nvariables + nparam]));
9317    isl_constraint_set_constant(constraint, val);
9318 @@ -102,16 +98,16 @@ isl_constraint_read_from_matrix(struct isl_dim* dim, Entier* row)
9319  
9320  struct isl_set*
9321  isl_set_from_piplib_matrix(struct isl_ctx* ctx,
9322 -                          PipMatrix* matrix,
9323 -                          int nparam)
9324 -{
9325 +                           osl_relation_p matrix,
9326 +                           int nparam) {
9327 +  PipMatrix* pmatrix = pip_relation2matrix(matrix);
9328    struct isl_dim* dim;
9329    struct isl_basic_set* bset;
9330    int i;
9331    unsigned nrows, ncolumns;
9332  
9333 -  nrows = matrix->NbRows;
9334 -  ncolumns = matrix->NbColumns;
9335 +  nrows = pmatrix->NbRows;
9336 +  ncolumns = pmatrix->NbColumns;
9337    int nvariables = ncolumns - 2 - nparam;
9338  
9339    dim = isl_dim_set_alloc(ctx, nparam, nvariables);
9340 @@ -119,36 +115,33 @@ isl_set_from_piplib_matrix(struct isl_ctx* ctx,
9341    bset = isl_basic_set_universe(isl_dim_copy(dim));
9342  
9343    for (i = 0; i < nrows; ++i) {
9344 -    Entier* row = matrix->p[i];
9345 +    Entier* row = pmatrix->p[i];
9346      struct isl_constraint* constraint =
9347 -      isl_constraint_read_from_matrix(isl_dim_copy(dim), row);
9348 +        isl_constraint_read_from_matrix(isl_dim_copy(dim), row);
9349      bset = isl_basic_set_add_constraint(bset, constraint);
9350    }
9351  
9352    isl_dim_free(dim);
9353  
9354 -  return isl_set_from_basic_set(bset);;
9355 +  return isl_set_from_basic_set(bset);
9356  }
9357  
9358  
9359  static
9360 -int count_cst(__isl_take isl_constraint *c, void *user)
9361 -{
9362 +int count_cst(__isl_take isl_constraint *c, void *user) {
9363    (*((int*)user))++;
9364  
9365    return 0;
9366  }
9367  
9368  
9369 -
9370  static
9371 -int copy_cst_to_mat(__isl_take isl_constraint *c, void *user)
9372 -{
9373 +int copy_cst_to_mat(__isl_take isl_constraint *c, void *user) {
9374    // 1- Get the first free row of the matrix.
9375    int pos;
9376    PipMatrix* mat = (PipMatrix*)user;
9377    for (pos = 0; pos < mat->NbRows &&
9378 -        CANDL_get_si(mat->p[pos][0]) != -1; ++pos)
9379 +       CANDL_get_si(mat->p[pos][0]) != -1; ++pos)
9380      ;
9381  
9382    // 2- Set the eq/ineq bit.
9383 @@ -161,17 +154,15 @@ int copy_cst_to_mat(__isl_take isl_constraint *c, void *user)
9384    isl_int val; isl_int_init(val);
9385    int j;
9386    int nb_vars = isl_constraint_dim(c, isl_dim_set);
9387 -  for (j = 0; j < nb_vars; ++j)
9388 -    {
9389 -      isl_constraint_get_coefficient(c, isl_dim_set, j, &val);
9390 -      CANDL_set_si(mat->p[pos][j + 1], isl_int_get_si(val));
9391 -    }
9392 +  for (j = 0; j < nb_vars; ++j) {
9393 +    isl_constraint_get_coefficient(c, isl_dim_set, j, &val);
9394 +    CANDL_set_si(mat->p[pos][j + 1], isl_int_get_si(val));
9395 +  }
9396    int nb_param = isl_constraint_dim(c, isl_dim_param);
9397 -  for (j = 0; j < nb_param; ++j)
9398 -    {
9399 -      isl_constraint_get_coefficient(c, isl_dim_param, j, &val);
9400 -      CANDL_set_si(mat->p[pos][j + nb_vars + 1], isl_int_get_si(val));
9401 -    }
9402 +  for (j = 0; j < nb_param; ++j) {
9403 +    isl_constraint_get_coefficient(c, isl_dim_param, j, &val);
9404 +    CANDL_set_si(mat->p[pos][j + nb_vars + 1], isl_int_get_si(val));
9405 +  }
9406    isl_constraint_get_constant(c, &val);
9407    CANDL_set_si(mat->p[pos][mat->NbColumns - 1], isl_int_get_si(val));
9408  
9409 @@ -181,19 +172,17 @@ int copy_cst_to_mat(__isl_take isl_constraint *c, void *user)
9410  }
9411  
9412  
9413 -int bset_get(__isl_take isl_basic_set *bset, void *user)
9414 -{
9415 +int bset_get(__isl_take isl_basic_set *bset, void *user) {
9416    *((struct isl_basic_set**)user) = bset;
9417  
9418    return 0;
9419  }
9420  
9421  
9422 -PipMatrix*
9423 +osl_relation_p
9424  isl_set_to_piplib_matrix(struct isl_ctx* ctx,
9425 -                        struct isl_set* set,
9426 -                        int nparam)
9427 -{
9428 +                         struct isl_set* set,
9429 +                         int nparam) {
9430    struct isl_basic_set* bset = NULL;
9431    // There is only one basic set in this set.
9432    isl_set_foreach_basic_set(set, bset_get, &bset);
9433 @@ -215,8 +204,11 @@ isl_set_to_piplib_matrix(struct isl_ctx* ctx,
9434  
9435    // 4- Convert each constraint to a row of the matrix.
9436    isl_basic_set_foreach_constraint(bset, copy_cst_to_mat, res);
9437 -
9438 -  return res;
9439 +  
9440 +  osl_relation_p tmp = pip_matrix2relation(res);
9441 +  pip_matrix_free(res);
9442 +  
9443 +  return tmp;
9444  }
9445  
9446  
9447 diff --git a/source/matrix.c b/source/matrix.c
9448 index 03c8546..8c3a1aa 100644
9449 --- a/source/matrix.c
9450 +++ b/source/matrix.c
9451 @@ -6,8 +6,8 @@
9452      **----  \#/  --------------------------------------------------------**
9453      **    .-"#'-.        First version: december 9th 2005                **
9454      **--- |"-.-"| -------------------------------------------------------**
9455 -          |     |
9456 -          |     |
9457 +    |     |
9458 +    |     |
9459   ******** |     | *************************************************************
9460   * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
9461   ******************************************************************************
9462 @@ -36,298 +36,18 @@
9463   *          please feel free to correct and improve it !
9464   */
9465  
9466 -# include <stdlib.h>
9467 -# include <stdio.h>
9468 -# include <ctype.h>
9469 -# include <string.h>
9470 -# include <candl/candl.h>
9471 -
9472 -/******************************************************************************
9473 - *                          Structure display function                        *
9474 - ******************************************************************************/
9475 -
9476 -
9477 -/**
9478 - * candl_matrix_print_structure function:
9479 - * Displays a CandlMatrix structure (matrix) into a file (file, possibly stdout)
9480 - * in a way that trends to be understandable without falling in a deep
9481 - * depression or, for the lucky ones, getting a headache... It includes an
9482 - * indentation level (level) in order to work with others print_structure
9483 - * functions.
9484 - * - 09/12/2005: first version (from CLooG 0.14.0).
9485 - */
9486 -void candl_matrix_print_structure(FILE * file, CandlMatrix * matrix, int level)
9487 -{ int i, j ;
9488 -
9489 -  if (matrix != NULL)
9490 -  { /* Go to the right level. */
9491 -    for(j=0; j<level; j++)
9492 -    fprintf(file,"|\t") ;
9493 -    fprintf(file,"+-- CandlMatrix\n") ;
9494 -
9495 -    for(j=0; j<=level; j++)
9496 -    fprintf(file,"|\t") ;
9497 -    fprintf(file,"%d %d\n",matrix->NbRows,matrix->NbColumns) ;
9498 -
9499 -    /* Display the matrix. */
9500 -    for (i=0; i<matrix->NbRows; i++)
9501 -    { for(j=0; j<=level; j++)
9502 -      fprintf(file,"|\t") ;
9503 -
9504 -      fprintf(file,"[ ") ;
9505 -
9506 -      for (j=0; j<matrix->NbColumns; j++)
9507 -      { CANDL_print(file,CANDL_FMT,matrix->p[i][j]) ;
9508 -        fprintf(file," ") ;
9509 -      }
9510 -
9511 -      fprintf(file,"]\n") ;
9512 -    }
9513 -  }
9514 -  else
9515 -  { /* Go to the right level. */
9516 -    for(j=0; j<level; j++)
9517 -    fprintf(file,"|\t") ;
9518 -    fprintf(file,"+-- NULL matrix\n") ;
9519 -  }
9520 -
9521 -  /* The last line. */
9522 -  for(j=0; j<=level; j++)
9523 -  fprintf(file,"|\t") ;
9524 -  fprintf(file,"\n") ;
9525 -}
9526 -
9527 -
9528 -/**
9529 - * candl_matrix_print function:
9530 - * This function prints the content of a CandlMatrix structure (matrix) into a
9531 - * file (file, possibly stdout).
9532 - * - 09/12/2005: first version (from CLooG 0.14.0).
9533 - */
9534 -void candl_matrix_print(FILE * file, CandlMatrix * matrix)
9535 -{ candl_matrix_print_structure(file,matrix,0) ;
9536 -}
9537 -
9538 -
9539 -
9540 -/**
9541 - * candl_matrix_print_data function:
9542 - * This function prints the content of a CandlMatrix data (matrix) into a
9543 - * file (file, possibly stdout).
9544 - */
9545 -void candl_matrix_print_data(FILE * file, CandlMatrix * matrix)
9546 -{
9547 -  int i, j;
9548 -
9549 -  fprintf (file, "%d %d\n", matrix->NbRows, matrix->NbColumns);
9550 -  for (i = 0; i < matrix->NbRows; ++i)
9551 -    {
9552 -      for (j = 0; j < matrix->NbColumns; ++j)
9553 -       CANDL_print(file,CANDL_FMT,matrix->p[i][j]);
9554 -      fprintf (file, "\n");
9555 -    }
9556 -}
9557 -
9558 -
9559 -/**
9560 - * candl_matrix_list_print_structure function:
9561 - * Displays a CandlMatrixList structure (list) into a file (file, possibly
9562 - * stdout) in a way that trends to be understandable without falling in a deep
9563 - * depression or, for the lucky ones, getting a headache... It includes an
9564 - * indentation level (level) in order to work with others print_structure
9565 - * functions.
9566 - * - 11/12/2005: first version.
9567 - */
9568 -void candl_matrix_list_print_structure(file, list, level)
9569 -FILE * file ;
9570 -CandlMatrixList *list ;
9571 -int level ;
9572 -{ int i, j, first=1 ;
9573 -
9574 -  if (list != NULL)
9575 -  { /* Go to the right level. */
9576 -    for(j=0; j<level; j++)
9577 -    fprintf(file,"|\t") ;
9578 -    fprintf(file,"+-- CandlMatrixList\n") ;
9579 -  }
9580 -  else
9581 -  { /* Go to the right level. */
9582 -    for(j=0; j<level; j++)
9583 -    fprintf(file,"|\t") ;
9584 -    fprintf(file,"+-- NULL matrix list\n") ;
9585 -  }
9586 -
9587 -  while (list != NULL)
9588 -  { if (!first)
9589 -    { /* Go to the right level. */
9590 -      for(j=0; j<level; j++)
9591 -      fprintf(file,"|\t") ;
9592 -      fprintf(file,"|   CandlMatrixList\n") ;
9593 -    }
9594 -    else
9595 -    first = 0 ;
9596 -
9597 -    /* A blank line. */
9598 -    for(j=0; j<=level+1; j++)
9599 -    fprintf(file,"|\t") ;
9600 -    fprintf(file,"\n") ;
9601 -
9602 -    /* Print the matrix. */
9603 -    candl_matrix_print_structure(file,list->matrix,level+1) ;
9604 -
9605 -    /* Next line. */
9606 -    if (list->next != NULL)
9607 -    { for(i=0; i<=level; i++)
9608 -      fprintf(file,"|\t") ;
9609 -      fprintf(file,"V\n") ;
9610 -    }
9611 -    list = list->next ;
9612 -  }
9613 -
9614 -  /* The last line. */
9615 -  for(j=0; j<=level; j++)
9616 -  fprintf(file,"|\t") ;
9617 -  fprintf(file,"\n") ;
9618 -}
9619 -
9620 -
9621 -/**
9622 - * candl_matrix_list_print function:
9623 - * This function prints the content of a CandlMatrixList structure (list) into a
9624 - * file (file, possibly stdout).
9625 - * - 11/12/2005: first version.
9626 - */
9627 -void candl_matrix_list_print(FILE * file, CandlMatrixList * list)
9628 -{ candl_matrix_list_print_structure(file,list,0) ;
9629 -}
9630 -
9631 -
9632 -/******************************************************************************
9633 - *                         Memory deallocation function                       *
9634 - ******************************************************************************/
9635 -
9636 -
9637 -/**
9638 - * candl_matrix_free function:
9639 - * This function frees the allocated memory for a CandlMatrix structure.
9640 - * - 09/12/2005: first version.
9641 - */
9642 -void candl_matrix_free(CandlMatrix * matrix)
9643 -{ pip_matrix_free(matrix) ;
9644 -}
9645 -
9646 -
9647 -/**
9648 - * candl_matrix_list_free function:
9649 - * This function frees the allocated memory for a CandlMatrixList structure.
9650 - * - 11/12/2005: first version.
9651 - */
9652 -void candl_matrix_list_free(CandlMatrixList * list)
9653 -{ CandlMatrixList * next ;
9654 -
9655 -  while (list != NULL)
9656 -  { next = list->next ;
9657 -    pip_matrix_free(list->matrix) ;
9658 -    free(list) ;
9659 -    list = next ;
9660 -  }
9661 -}
9662 -
9663 -
9664 -/******************************************************************************
9665 - *                              Reading functions                             *
9666 - ******************************************************************************/
9667 -
9668 -
9669 -/**
9670 - * candl_matrix_read function:
9671 - * This function reads a matrix into a file (foo, posibly stdin) and returns a
9672 - * pointer to a CandlMatrix containing the read informations.
9673 - * - 09/12/2005: first version.
9674 - */
9675 -CandlMatrix * candl_matrix_read(FILE * file)
9676 -{ return pip_matrix_read(file) ;
9677 -}
9678 -
9679 -
9680 -/**
9681 - * cloog_domain_list_read function:
9682 - * This function reads a list of matrices into a file (foo, posibly stdin) and
9683 - * returns a pointer to a CandlMatrixList containing the read information.
9684 - * - 11/12/2005: first version (from CLooG 0.14.0's cloog_domain_list_read).
9685 - */
9686 -CandlMatrixList * candl_matrix_list_read(FILE * file)
9687 -{ int i, nb_matrices ;
9688 -  char s[CANDL_MAX_STRING] ;
9689 -  CandlMatrixList * list, * now, * next ;
9690 -
9691 -  /* We read first the number of matrices in the list. */
9692 -  while (fgets(s,CANDL_MAX_STRING,file) == 0) ;
9693 -  while ((*s=='#' || *s=='\n') || (sscanf(s," %d",&nb_matrices)<1))
9694 -  fgets(s,CANDL_MAX_STRING,file) ;
9695 -
9696 -  /* Then we read the matrices. */
9697 -  list = NULL ;
9698 -  if (nb_matrices > 0)
9699 -  { list = (CandlMatrixList *)malloc(sizeof(CandlMatrixList)) ;
9700 -    list->matrix = candl_matrix_read(file) ;
9701 -    list->next = NULL ;
9702 -    now = list ;
9703 -    for (i=1;i<nb_matrices;i++)
9704 -    { next = (CandlMatrixList *)malloc(sizeof(CandlMatrixList)) ;
9705 -      next->matrix = candl_matrix_read(file) ;
9706 -      next->next = NULL ;
9707 -      now->next = next ;
9708 -      now = now->next ;
9709 -    }
9710 -  }
9711 -
9712 -  return(list) ;
9713 -}
9714 -
9715 -
9716 -/******************************************************************************
9717 - *                            Processing functions                            *
9718 - ******************************************************************************/
9719 -
9720 -
9721 -/**
9722 - * candl_matrix_malloc function:
9723 - * This function allocates the memory space for a CandlMatrix structure and
9724 - * sets its fields with default values. Then it returns a pointer to the
9725 - * allocated space.
9726 - * - 09/12/2005: first version.
9727 - */
9728 -CandlMatrix * candl_matrix_malloc(int nb_rows, int nb_columns)
9729 -{ return pip_matrix_alloc(nb_rows,nb_columns) ;
9730 -}
9731 -
9732 -
9733 -/**
9734 - * candl_matrix_list_malloc function:
9735 - * This function allocates the memory space for a CandlMatrixList structure and
9736 - * sets its fields with default values. Then it returns a pointer to the
9737 - * allocated space.
9738 - * - 11/12/2005: first version.
9739 - */
9740 -CandlMatrixList * candl_matrix_list_malloc()
9741 -{ CandlMatrixList * list ;
9742 -
9743 -  /* Memory allocation for the CandlDependence structure. */
9744 -  list = (CandlMatrixList *)malloc(sizeof(CandlMatrixList)) ;
9745 -  if (list == NULL)
9746 -  { fprintf(stderr, "[Candl]ERROR: memory overflow.\n") ;
9747 -    exit(1) ;
9748 -  }
9749 -
9750 -  /* We set the various fields with default values. */
9751 -  list->matrix = NULL ;
9752 -  list->next   = NULL ;
9753 -
9754 -  return list ;
9755 -}
9756 -
9757 -
9758 +#include <stdlib.h>
9759 +#include <stdio.h>
9760 +#include <ctype.h>
9761 +#include <string.h>
9762 +#include <osl/macros.h>
9763 +#include <osl/relation.h>
9764 +#include <osl/extensions/dependence.h>
9765 +#include <candl/macros.h>
9766 +#include <candl/matrix.h>
9767 +#include <candl/violation.h>
9768 +#include <candl/piplib.h>
9769 +#include <candl/piplib-wrapper.h>
9770  
9771  
9772  /**
9773 @@ -335,7 +55,7 @@ CandlMatrixList * candl_matrix_list_malloc()
9774   * this function builds the constraint system corresponding to a violation of a
9775   * dependence, for a given transformation couple at a given depth.
9776   * - dependence is the constraint system of a dependence between two
9777 -     statements,
9778 + statements,
9779   * - t_source is the transformation function for the source statement,
9780   * - t_target is the transformation function for the target statement,
9781   * - dimension is the transformation dimension checked for legality,
9782 @@ -343,116 +63,249 @@ CandlMatrixList * candl_matrix_list_malloc()
9783   ***
9784   * - 13/12/2005: first version (extracted from candl_violation).
9785   */
9786 -CandlMatrix * candl_matrix_violation(dependence,t_source,t_target,
9787 -                                     dimension,nb_par)
9788 -CandlMatrix * dependence, * t_source, * t_target ;
9789 -int dimension, nb_par ;
9790 -{ int i, j, nb_rows, nb_columns, constraint, s_dims, t_dims ;
9791 -  CandlMatrix * system ;
9792 -  Entier temp ;
9793 -
9794 -  CANDL_init(temp) ;
9795 -
9796 -  /* The number of dimensions of the source and target domains. */
9797 -  s_dims = t_source->NbColumns - nb_par - 2 ;
9798 -  t_dims = t_target->NbColumns - nb_par - 2 ;
9799 -
9800 -  /* Size of the constraint system. */
9801 -  nb_rows    = dependence->NbRows + dimension + 1 ;
9802 -  nb_columns = dependence->NbColumns ;
9803 -
9804 -  /* We allocate memory space for the constraint system. */
9805 -  system = candl_matrix_malloc(nb_rows, nb_columns) ;
9806 -
9807 -  /* We fill the constraint system (there is no need to put zeros in the
9808 -   * empty zones since candl_matrix_alloc initialized all to 0):
9809 -   */
9810 -
9811 -  /* 1. We copy the constraints of the dependence polyhedron. */
9812 -  for (i = 0; i < dependence->NbRows; i++)
9813 -  for (j = 0; j < dependence->NbColumns; j++)
9814 -  CANDL_assign(system->p[i][j],dependence->p[i][j]) ;
9815 -
9816 -  constraint = dependence->NbRows ;
9817 -
9818 -  /* 2. We set the equality constraints (equality tag is already 0). */
9819 -  for (i = 0; i < dimension; i++)
9820 -  { /* The source dimension part. */
9821 -    for (j = 1; j <= s_dims; j++)
9822 -    CANDL_assign(system->p[constraint][j],t_source->p[i][j]) ;
9823 +candl_violation_p candl_matrix_violation(osl_dependence_p dependence,
9824 +                                         osl_relation_p source,
9825 +                                         osl_relation_p target,
9826 +                                         int dimension, int nb_par) {
9827 +  candl_violation_p violation;
9828 +  osl_relation_p system;
9829 +  int i, j, k, c;
9830 +  int constraint = 0;
9831 +  int precision = dependence->domain->precision;
9832 +  int nb_rows, nb_columns;
9833 +  int nb_output_dims, nb_input_dims, nb_local_dims;
9834 +  int ind_source_output_scatt;
9835 +  int ind_target_output_scatt;
9836 +  int ind_source_local_scatt;
9837 +  int ind_target_local_scatt;
9838 +  int ind_params;
9839 +  
9840 +  /* Create a new violation structure */
9841 +  violation = candl_violation_malloc();
9842 +  
9843 +  violation->source_nb_output_dims_scattering = source->nb_output_dims;
9844 +  violation->target_nb_output_dims_scattering = target->nb_output_dims;
9845 +  violation->source_nb_local_dims_scattering  = source->nb_local_dims;
9846 +  violation->target_nb_local_dims_scattering  = target->nb_local_dims;
9847 +  
9848 +  /* Compute the system size */
9849 +  nb_local_dims  = dependence->domain->nb_local_dims +
9850 +                   violation->source_nb_local_dims_scattering +
9851 +                   violation->target_nb_local_dims_scattering;
9852 +  nb_output_dims = dependence->domain->nb_output_dims +
9853 +                   violation->source_nb_output_dims_scattering;
9854 +  nb_input_dims  = dependence->domain->nb_input_dims +
9855 +                   violation->target_nb_output_dims_scattering;
9856 +
9857 +  nb_columns = nb_output_dims + nb_input_dims + nb_local_dims + nb_par + 2;
9858 +  nb_rows    = dependence->domain->nb_rows +
9859 +               source->nb_rows + target->nb_rows + 
9860 +               dimension;
9861 +
9862 +  system = osl_relation_pmalloc(precision, nb_rows, nb_columns);
9863 +  
9864 +  /* Compute some indexes */
9865 +  ind_source_output_scatt = 1 + dependence->domain->nb_output_dims;
9866 +  ind_target_output_scatt = ind_source_output_scatt + source->nb_output_dims +  
9867 +                            dependence->domain->nb_input_dims;
9868 +  ind_source_local_scatt  = ind_target_output_scatt + target->nb_output_dims +
9869 +                            dependence->domain->nb_local_dims;
9870 +  ind_target_local_scatt  = ind_source_local_scatt + source->nb_local_dims +
9871 +                            dependence->domain->nb_local_dims;
9872 +  ind_params              = ind_target_local_scatt + target->nb_local_dims;
9873 +  
9874 +  /* 1. Copy the dependence domain */
9875 +  for (i = 0 ; i < dependence->domain->nb_rows ; i++) {
9876 +    /* eq/in */
9877 +    osl_int_assign(precision,
9878 +                   &system->m[constraint][0],
9879 +                   dependence->domain->m[i][0]);
9880 +    /* output dims */
9881 +    k = 1;
9882 +    j = 1;
9883 +    for (c = dependence->domain->nb_output_dims ; c > 0 ; c--, k++, j++)
9884 +      osl_int_assign(precision,
9885 +                     &system->m[constraint][k],
9886 +                     dependence->domain->m[i][j]);
9887 +    /* input dims */
9888 +    k += source->nb_output_dims;
9889 +    for (c = dependence->domain->nb_input_dims ; c > 0 ; c--, k++, j++)
9890 +      osl_int_assign(precision,
9891 +                     &system->m[constraint][k],
9892 +                     dependence->domain->m[i][j]);
9893 +    /* source local dims */
9894 +    k += target->nb_output_dims;
9895 +    for (c = dependence->source_nb_local_dims_domain +
9896 +             dependence->source_nb_local_dims_access ; c > 0 ; c--, k++, j++)
9897 +      osl_int_assign(precision,
9898 +                     &system->m[constraint][k],
9899 +                     dependence->domain->m[i][j]);
9900 +    /* target local dims */
9901 +    k += source->nb_local_dims;
9902 +    for (c = dependence->target_nb_local_dims_domain +
9903 +             dependence->target_nb_local_dims_access ; c > 0 ; c--, k++, j++)
9904 +      osl_int_assign(precision,
9905 +                     &system->m[constraint][k],
9906 +                     dependence->domain->m[i][j]);
9907 +    /* params + const */
9908 +    k = ind_params;
9909 +    for (c = nb_par+1 ; c > 0 ; c--, k++, j++)
9910 +      osl_int_assign(precision,
9911 +                     &system->m[constraint][k],
9912 +                     dependence->domain->m[i][j]);
9913 +    constraint++;
9914 +  }
9915 +  
9916 +  /* 2. Copy the source scattering */
9917 +  for (i = 0 ; i < source->nb_rows ; i++) {
9918 +    /* eq/in */
9919 +    osl_int_assign(precision,
9920 +                   &system->m[constraint][0],
9921 +                   source->m[i][0]);
9922 +    /* output dims */
9923 +    k = ind_source_output_scatt;
9924 +    j = 1;
9925 +    for (c = source->nb_output_dims ; c > 0 ; c--, k++, j++)
9926 +      osl_int_assign(precision,
9927 +                     &system->m[constraint][k],
9928 +                     source->m[i][j]);
9929 +    /* input dims (linked with the output dims of domain) */
9930 +    k = 1;
9931 +    for (c = source->nb_input_dims ; c > 0 ; c--, k++, j++)
9932 +      osl_int_assign(precision,
9933 +                     &system->m[constraint][k],
9934 +                     source->m[i][j]);
9935 +    /* local dims */
9936 +    k = ind_source_local_scatt;
9937 +    for (c = source->nb_local_dims ; c > 0 ; c--, k++, j++)
9938 +      osl_int_assign(precision,
9939 +                     &system->m[constraint][k],
9940 +                     source->m[i][j]);
9941 +    /* params + const */
9942 +    k = ind_params;
9943 +    for (c = nb_par+1 ; c > 0 ; c--, k++, j++)
9944 +      osl_int_assign(precision,
9945 +                     &system->m[constraint][k],
9946 +                     source->m[i][j]);
9947 +    constraint++;
9948 +  }
9949  
9950 -    /* The -target dimension part. */
9951 -    for (; j <= s_dims + t_dims; j++)
9952 -    { CANDL_oppose(temp,t_target->p[i][j - s_dims]) ;
9953 -      CANDL_assign(system->p[constraint][j], temp) ;
9954 +  /* 2. Copy the target scattering */
9955 +  for (i = 0 ; i < target->nb_rows ; i++) {
9956 +    /* eq/in */
9957 +    osl_int_assign(precision,
9958 +                   &system->m[constraint][0],
9959 +                   target->m[i][0]);
9960 +    /* output dims */
9961 +    k = ind_target_output_scatt;
9962 +    j = 1;
9963 +    for (c = target->nb_output_dims ; c > 0 ; c--, k++, j++) {
9964 +      osl_int_assign(precision,
9965 +                     &system->m[constraint][k],
9966 +                     target->m[i][j]);
9967 +      osl_int_oppose(precision,
9968 +                     &system->m[constraint][k],
9969 +                     system->m[constraint][k]);
9970      }
9971 -
9972 -    /* The source-target parameter/scalar part. */
9973 -    for (; j < nb_columns; j++)
9974 -    CANDL_subtract(system->p[constraint][j],
9975 -                    t_source->p[i][j - t_dims],
9976 -                    t_target->p[i][j - s_dims]) ;
9977 -    constraint++ ;
9978 +    /* input dims (linked with the output dims of domain) */
9979 +    k = 1 + nb_output_dims;
9980 +    for (c = target->nb_input_dims ; c > 0 ; c--, k++, j++) {
9981 +      osl_int_assign(precision,
9982 +                     &system->m[constraint][k],
9983 +                     target->m[i][j]);
9984 +      osl_int_oppose(precision,
9985 +                     &system->m[constraint][k],
9986 +                     system->m[constraint][k]);
9987 +    }
9988 +    /* local dims */
9989 +    k = ind_target_local_scatt;
9990 +    for (c = target->nb_local_dims ; c > 0 ; c--, k++, j++) {
9991 +      osl_int_assign(precision,
9992 +                     &system->m[constraint][k],
9993 +                     target->m[i][j]);
9994 +      osl_int_oppose(precision,
9995 +                     &system->m[constraint][k],
9996 +                     system->m[constraint][k]);
9997 +    }
9998 +    /* params + const */
9999 +    k = ind_params;
10000 +    for (c = nb_par+1 ; c > 0 ; c--, k++, j++) {
10001 +      osl_int_assign(precision,
10002 +                     &system->m[constraint][k],
10003 +                     target->m[i][j]);
10004 +      osl_int_oppose(precision,
10005 +                     &system->m[constraint][k],
10006 +                     system->m[constraint][k]);
10007 +    }
10008 +    constraint++;
10009    }
10010 -
10011 -  /* 3. We set the target < source constraint. */
10012 -  /* This is an inequality. */
10013 -  CANDL_set_si(system->p[constraint][0], 1) ;
10014 -
10015 -  /* The source dimension part. */
10016 -  for (j = 1; j<= s_dims; j++)
10017 -  CANDL_assign(system->p[constraint][j],t_source->p[dimension][j]) ;
10018 -
10019 -  /* The -target dimension part. */
10020 -  for (; j<= s_dims + t_dims; j++)
10021 -  { CANDL_oppose(temp,t_target->p[dimension][j - s_dims]) ;
10022 -    CANDL_assign(system->p[constraint][j],temp) ;
10023 +  
10024 +  /* 3. We set the equality constraints */
10025 +  k = ind_source_output_scatt;
10026 +  j = ind_target_output_scatt;
10027 +  for (i = 1; i < dimension; i++, k++, j++) {
10028 +    /* source */
10029 +    osl_int_set_si(precision, &system->m[constraint][k], 1);
10030 +    /* target */
10031 +    osl_int_set_si(precision, &system->m[constraint][j], -1);
10032 +    constraint++;
10033    }
10034  
10035 -  /* The source-target parameter/scalar part. */
10036 -  for (; j < nb_columns; j++)
10037 -  CANDL_subtract(system->p[constraint][j],
10038 -                  t_source->p[dimension][j - t_dims],
10039 -                  t_target->p[dimension][j - s_dims]) ;
10040 +  /* 4. We set the target < source constraint. */
10041 +  osl_int_set_si(precision, &system->m[constraint][0], 1);
10042 +  /* source */
10043 +  osl_int_set_si(precision, &system->m[constraint][k], 1);
10044 +  /* target */
10045 +  osl_int_set_si(precision, &system->m[constraint][j], -1);
10046    /* We subtract 1 to the scalar to achieve >0 constraint. */
10047 -  CANDL_decrement(system->p[constraint][nb_columns - 1],
10048 -                 system->p[constraint][nb_columns - 1]) ;
10049 -
10050 -  CANDL_clear(temp) ;
10051 -  return system ;
10052 +  osl_int_decrement(precision,
10053 +                    &system->m[constraint][nb_columns - 1],
10054 +                    system->m[constraint][nb_columns - 1]);
10055 +  
10056 +  system->nb_output_dims = nb_output_dims;
10057 +  system->nb_input_dims = nb_input_dims;
10058 +  system->nb_parameters = nb_par;
10059 +  system->nb_local_dims = nb_local_dims;
10060 +  system->type = OSL_UNDEFINED;
10061 +  
10062 +  violation->domain = system;
10063 +  
10064 +  return violation;
10065  }
10066  
10067  
10068 -
10069 -
10070  /**
10071   * candl_matrix_check_point function:
10072   * This function checks if there is an integral point in the set of
10073   * constraints, provided a given domain (possibly NULL).
10074   *
10075 + * FIXME : is it the same as pip_has_rational_point ?
10076 + * here options->Nq = 1 (default)
10077   */
10078  int
10079 -candl_matrix_check_point (CandlMatrix* domain,
10080 -                         CandlMatrix* context)
10081 -{
10082 -#ifdef CANDL_HAS_PIPLIB_HYBRID
10083 -  return piplib_hybrid_has_integer_point (domain, context, 0);
10084 -#else  
10085 +candl_matrix_check_point(osl_relation_p domain,
10086 +                         osl_relation_p context) {
10087 +// FIXME : compatibility with osl
10088 +//#ifdef CANDL_HAS_PIPLIB_HYBRID
10089 +//  return piplib_hybrid_has_integer_point (domain, context, 0);
10090 +//#else  
10091    PipOptions* options;
10092    PipQuast* solution;
10093    int ret = 0;
10094 -  options = pip_options_init ();
10095 +  options = pip_options_init();
10096    options->Simplify = 1;
10097    options->Urs_parms = -1;
10098    options->Urs_unknowns = -1;
10099 -  solution = pip_solve (domain, context, -1, options);
10100 +  
10101 +  solution = pip_solve_osl(domain, context, -1, options);
10102  
10103    if ((solution != NULL) &&
10104        ((solution->list != NULL) || (solution->condition != NULL)))
10105      ret = 1;
10106 -  pip_options_free (options);
10107 -  pip_quast_free (solution);
10108 +  pip_options_free(options);
10109 +  pip_quast_free(solution);
10110  
10111    return ret;
10112 -#endif  
10113 +//#endif  
10114  }
10115 +
10116 diff --git a/source/options.c b/source/options.c
10117 index fea449f..91a738a 100644
10118 --- a/source/options.c
10119 +++ b/source/options.c
10120 @@ -6,8 +6,8 @@
10121      **----  \#/  --------------------------------------------------------**
10122      **    .-"#'-.         First version: september 8th 2003              **
10123      **--- |"-.-"| -------------------------------------------------------**
10124 -          |     |
10125 -          |     |
10126 +    |     |
10127 +    |     |
10128   ******** |     | *************************************************************
10129   * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
10130   ******************************************************************************
10131 @@ -37,7 +37,7 @@
10132  #include <stdlib.h>
10133  #include <stdio.h>
10134  #include <string.h>
10135 -#include <candl/candl.h>
10136 +#include <candl/macros.h>
10137  #include <candl/options.h>
10138  
10139  
10140 @@ -48,12 +48,11 @@
10141  
10142  /**
10143   * candl_option_print function:
10144 - * This function prints the content of a CandlOptions structure (program) into
10145 + * This function prints the content of a candl_options_t structure (program) into
10146   * a file (foo, possibly stdout).
10147   * April 19th 2003: first version.
10148   */
10149 -void candl_options_print(FILE * foo, CandlOptions * options)
10150 -{
10151 +void candl_options_print(FILE * foo, candl_options_p options) {
10152    fprintf(foo, "Options:\n");
10153  }
10154  
10155 @@ -65,11 +64,10 @@ void candl_options_print(FILE * foo, CandlOptions * options)
10156  
10157  /**
10158   * candl_options_free function:
10159 - * This function frees the allocated memory for a CandlOptions structure.
10160 + * This function frees the allocated memory for a candl_options_t structure.
10161   * April 19th 2003: first version.
10162   */
10163 -void candl_options_free(CandlOptions * options)
10164 -{
10165 +void candl_options_free(candl_options_p options) {
10166    free(options);
10167  }
10168  
10169 @@ -81,19 +79,17 @@ void candl_options_free(CandlOptions * options)
10170  
10171  /**
10172   * candl_options_malloc function:
10173 - * This functions allocate the memory space for a CandlOptions structure and
10174 + * This functions allocate the memory space for a candl_options_t structure and
10175   * fill its fields with the defaults values. It returns a pointer to the
10176 - * allocated CandlOptions structure.
10177 + * allocated candl_options_t structure.
10178   * April 19th 2003: first version.
10179   */
10180 -CandlOptions * candl_options_malloc(void)
10181 -{
10182 -  CandlOptions * options;
10183 -
10184 -  /* Memory allocation for the CandlOptions structure. */
10185 -  options = (CandlOptions *) malloc(sizeof(CandlOptions));
10186 -  if (options == NULL)
10187 -  {
10188 +candl_options_p candl_options_malloc(void) {
10189 +  candl_options_p options;
10190 +
10191 +  /* Memory allocation for the candl_options_t structure. */
10192 +  options = (candl_options_p) malloc(sizeof(candl_options_t));
10193 +  if (options == NULL) {
10194      fprintf(stderr, "[Candl]ERROR: memory overflow.\n");
10195      exit(1);
10196    }
10197 @@ -106,16 +102,13 @@ CandlOptions * candl_options_malloc(void)
10198    options->rar = 0;       /* RAR (input)  dependences don't matter. */
10199    options->commute = 0;   /* Don't use commutativity to simplify dependences.*/
10200    options->fullcheck = 0; /* Don't compute all violations.*/
10201 -  options->depgraph  = 0; /* Don't print the dependence graph.*/
10202 -  options->violgraph = 0; /* Don' compute the violation graph.*/
10203    options->scalar_renaming = 0; /* Don't enable scalar renaming. */
10204    options->scalar_privatization = 0; /* Don't enable scalar privatization. */
10205    options->scalar_expansion = 0; /* Don't enable scalar expansion. */
10206    options->lastwriter = 0; /* Compute the last writer for RAW and WAW dependences */
10207 -  options->readscop = 0; /* Don't read a .scop format for the input. */
10208 -  options->writescop = 0; /* Don't write a .scop format for the output. */
10209 -  options->scoptocandl = 0; /* Don't act as a .scop to candl converter. */
10210    options->verbose = 0; /* Don't be verbose. */
10211 +  options->outscop = 0; /* Don't print the scop. */
10212 +  options->autocorrect = 0; /* Don't correct violations. */
10213    /* UNDOCUMENTED OPTIONS FOR THE AUTHOR ONLY */
10214    options->view = 0;      /* Do not visualize the graph with dot and gv.*/
10215    options->structure = 0; /* Don't print internal dependence structure. */
10216 @@ -132,54 +125,54 @@ CandlOptions * candl_options_malloc(void)
10217   * limitation of the ISO C 89 compilers.
10218   * August 5th 2002: first version.
10219   */
10220 -void candl_options_help()
10221 -{ printf(
10222 -  "Usage: candl [ options | file ] ...\n"
10223 -  "Options for data dependence computation:\n"
10224 -  "  -waw <boolean>       Consider WAW (output) dependences (1) or not (0)\n"
10225 -  "                       (default setting: 1).\n"
10226 -  "  -raw <boolean>       Consider RAW (flow)   dependences (1) or not (0)\n"
10227 -  "                       (default setting: 1).\n"
10228 -  "  -war <boolean>       Consider WAR (anti)   dependences (1) or not (0)\n"
10229 -  "                       (default setting: 1).\n"
10230 -  "  -rar <boolean>       Consider RAR (input)  dependences (1) or not (0)\n"
10231 -  "                       (default setting: 0).\n");
10232 +void candl_options_help() {
10233 +  printf(
10234 +    "Usage: candl [ options | file ] ...\n"
10235 +    "Options for data dependence computation:\n"
10236 +    "  -waw <boolean>       Consider WAW (output) dependences (1) or not (0)\n"
10237 +    "                       (default setting: 1).\n"
10238 +    "  -raw <boolean>       Consider RAW (flow)   dependences (1) or not (0)\n"
10239 +    "                       (default setting: 1).\n"
10240 +    "  -war <boolean>       Consider WAR (anti)   dependences (1) or not (0)\n"
10241 +    "                       (default setting: 1).\n"
10242 +    "  -rar <boolean>       Consider RAR (input)  dependences (1) or not (0)\n"
10243 +    "                       (default setting: 0).\n");
10244    printf(
10245 -  "  -commute   <boolean> Consider commutativity (1) or not (0)\n"
10246 -  "                       (default setting: 0).\n"
10247 -  "  -fullcheck <boolean> Compute all legality violation (1) or only one (0)\n"
10248 -  "                       (default setting: 0).\n"
10249 -  "  -depgraph  <boolean> Ask to print the dependence graph (1) or not (0)\n"
10250 -  "                       (default setting: 0 but 1 if no transformation).\n"
10251 -  "  -violgraph <boolean> Ask to print the violation graph (1) or not (0)\n"
10252 -  "                       (default setting: 1 but 0 if no transformation).\n"
10253 -  "  -scalren   <boolean> Ask to enable scalar renaming (1) or not (0)\n"
10254 -  "                       (default setting: 0).\n"
10255 -  "  -scalpriv  <boolean> Ask to enable scalar privatization (1) or not (0)\n"
10256 -  "                       (default setting: 0).\n"
10257 -  "  -scalexp   <boolean> Ask to enable scalar expansion (1) or not (0)\n"
10258 -  "                       (default setting: 0).\n");
10259 +    "  -commute   <boolean> Consider commutativity (1) or not (0)\n"
10260 +    "                       (default setting: 0).\n"
10261 +    "  -fullcheck <boolean> Compute all legality violation (1) or just the\n"
10262 +    "                       first (0)\n"
10263 +    "                       (default setting: 0, or 1 if autocorrect is set).\n"
10264 +    "  -scalren   <boolean> Ask to enable scalar renaming (1) or not (0)\n"
10265 +    "                       (default setting: 0).\n"
10266 +    "  -scalpriv  <boolean> Ask to enable scalar privatization (1) or not (0)\n"
10267 +    "                       (default setting: 0).\n"
10268 +    "  -scalexp   <boolean> Ask to enable scalar expansion (1) or not (0)\n"
10269 +    "                       (default setting: 0).\n");
10270    printf(
10271 -  "  -view                Ask to display the graphs (1) or not (0)\n"
10272 -  "                       (requires dot -graphviz- and gv tools).\n");
10273 +    "  -view                Ask to display the graphs (1) or not (0)\n"
10274 +    "                       (requires dot -graphviz- and gv tools).\n");
10275    printf(
10276 -  "\nGeneral options:\n"
10277 -#ifdef CANDL_SUPPORTS_SCOPLIB
10278 -  "  -inscop              Read a .scop formatted file as the input.\n"
10279 -  "  -outscop             Output a .scop formatted file as the output.\n"
10280 -  "  -scoptocandl         Output a .candl formatted file from a .scop input.\n"
10281 -#endif
10282 -  "  -o <output>          Name of the output file; 'stdout' is a special\n"
10283 -  "                       value: when used, output is standard output\n"
10284 -  "                       (default setting: stdout).\n"
10285 -  "  -verbose             Display a verbose output.\n"
10286 -  "  -v, --version        Display the version information.\n"
10287 -  "  -h, --help           Display this information.\n\n"
10288 -  "The special value 'stdin' for 'file' makes Candl to read data on\n"
10289 -  "standard input.\n\n"
10290 -  "For bug reporting or any suggestions, please send an email to the author\n"
10291 -  "<cedric.bastoul@inria.fr> or to the maintainer of Candl:\n"
10292 -  "<pouchet@cse.ohio-state.edu>.\n");
10293 +    "\nGeneral options:\n"
10294 +    "  -test     <origscop> Test violations with the original scop.\n"
10295 +    //"  -autocorrect <boolean> Correct violations with a shifting (1) or not(0)\n"
10296 +    "                       -test must be set\n"
10297 +    "                       (default setting: 0).\n"
10298 +    "  -outscop             Output a .scop formatted file as the output.\n"
10299 +    "  -o        <output>   Name of the output file; 'stdout' is a special\n"
10300 +    "                       value: when used, output is standard output\n"
10301 +    "                       (default setting: stdout).\n"
10302 +    "  -verbose             Display a verbose output.\n"
10303 +    "  -v, --version        Display the version information.\n"
10304 +    "  -h, --help           Display this information.\n\n"
10305 +    "The special value 'stdin' for 'file' makes Candl to read data on standard\n"
10306 +    "input.\n"
10307 +    "If the -test is not given, the dependences graph of the input 'file' will\n"
10308 +    "be computed, otherwise it's the violation graph between 'origscop' and 'file'"
10309 +    ".\n\n"
10310 +    "For bug reporting or any suggestions, please send an email to the author\n"
10311 +    "<cedric.bastoul@inria.fr> or to the maintainer of Candl:\n"
10312 +    "<pouchet@cse.ohio-state.edu>.\n");
10313  }
10314  
10315  
10316 @@ -190,32 +183,31 @@ void candl_options_help()
10317   * characters limitation of the ISO C 89 compilers.
10318   * August 5th 2002: first version.
10319   */
10320 -void candl_options_version()
10321 -{ printf("Candl %s %s bits   The Chunky Dependence Analyzer\n",
10322 +void candl_options_version() { printf("Candl %s %s bits   The Chunky Dependence Analyzer\n",
10323           CANDL_RELEASE,CANDL_VERSION);
10324    printf(
10325 -  "-----\n"
10326 -  "Candl is a dependence analyzer for static control programs, coming from \n"
10327 -  "the CHUNKY project: a research tool for data-locality improvement. This \n"
10328 -  "program is distributed under the terms of the GNU Lesser General Public\n"
10329 -  "License (details at http://www.gnu.org/copyleft/gpl.html).\n"
10330 -  "-----\n");
10331 +    "-----\n"
10332 +    "Candl is a dependence analyzer for static control programs, coming from \n"
10333 +    "the CHUNKY project: a research tool for data-locality improvement. This \n"
10334 +    "program is distributed under the terms of the GNU Lesser General Public\n"
10335 +    "License (details at http://www.gnu.org/copyleft/gpl.html).\n"
10336 +    "-----\n");
10337    printf(
10338 -  "It would be kind to refer the following paper in any publication "
10339 -  "resulting \nfrom the use of this software or its library:\n"
10340 -  "@Article{Bas05,\n"
10341 -  "author    =  {Cedric Bastoul and Paul Feautrier},\n"
10342 -  "title     =  {Adjusting a program transformation for legality},\n"
10343 -  "journal   =  {Parallel Processing Letters},\n"
10344 -  "year      =  2005,\n"
10345 -  "volume    =  15,\n"
10346 -  "number    =  1,\n"
10347 -  "pages     =  {3--17},\n"
10348 -  "month     =  {March},\n"
10349 -  "}\n"
10350 -  "-----\n"
10351 -  "For bug reporting or any suggestions, please send an email to the author\n"
10352 -  "<cedric.bastoul@inria.fr>.\n");
10353 +    "It would be kind to refer the following paper in any publication "
10354 +    "resulting \nfrom the use of this software or its library:\n"
10355 +    "@Article{Bas05,\n"
10356 +    "author    =  {Cedric Bastoul and Paul Feautrier},\n"
10357 +    "title     =  {Adjusting a program transformation for legality},\n"
10358 +    "journal   =  {Parallel Processing Letters},\n"
10359 +    "year      =  2005,\n"
10360 +    "volume    =  15,\n"
10361 +    "number    =  1,\n"
10362 +    "pages     =  {3--17},\n"
10363 +    "month     =  {March},\n"
10364 +    "}\n"
10365 +    "-----\n"
10366 +    "For bug reporting or any suggestions, please send an email to the author\n"
10367 +    "<cedric.bastoul@inria.fr>.\n");
10368  }
10369  
10370  
10371 @@ -229,20 +221,17 @@ void candl_options_version()
10372   * August 5th 2002: first version.
10373   * June 29th 2003: (debug) lack of argument now detected.
10374   */
10375 -void candl_options_set(int * option, int argc, char ** argv, int * number)
10376 -{
10377 +void candl_options_set(int * option, int argc, char ** argv, int * number) {
10378    char ** endptr;
10379  
10380 -  if (*number+1 >= argc)
10381 -  {
10382 +  if (*number+1 >= argc) {
10383      fprintf(stderr, "[Candl]ERROR: an option lacks of argument.\n");
10384      exit(1);
10385    }
10386  
10387    endptr = NULL;
10388    *option = strtol(argv[*number+1],endptr,10);
10389 -  if (endptr != NULL)
10390 -  {
10391 +  if (endptr != NULL) {
10392      fprintf(stderr, "[Candl]ERROR: %s option value is not valid.\n",
10393              argv[*number]);
10394      exit(1);
10395 @@ -254,155 +243,167 @@ void candl_options_set(int * option, int argc, char ** argv, int * number)
10396  /**
10397   * candl_options_read function:
10398   * This functions reads all the options and the input/output files thanks
10399 - * the the user's calling line elements (in argc). It fills a CandlOptions
10400 + * the the user's calling line elements (in argc). It fills a candl_options_t
10401   * structure and the FILE structure corresponding to input and output files.
10402   * August 5th 2002: first version.
10403 - * April 19th 2003: now in options.c and support of the CandlOptions structure.
10404 + * April 19th 2003: now in options.c and support of the candl_options_t structure.
10405   */
10406  void candl_options_read(int argc, char** argv, FILE** input, FILE** output,
10407 -                       CandlOptions** options)
10408 -{
10409 -  int i, infos = 0, input_is_set = 0;
10410 +                        FILE **input_test, candl_options_p* options) {
10411 +  int i, infos = 0, input_is_set = 0, testscop_is_set = 0;
10412  
10413 -  /* CandlOptions structure allocation and initialization. */
10414 +  /* candl_options_t structure allocation and initialization. */
10415    *options = candl_options_malloc();
10416    /* The default output is the standard output. */
10417    *output = stdout;
10418 -
10419 -  for (i = 1; i < argc; i++)
10420 -    if (argv[i][0] == '-')
10421 -      {
10422 -       if (!strcmp(argv[i], "-waw"))
10423 -         candl_options_set(&(*options)->waw, argc, argv, &i);
10424 -       else
10425 -       if (!strcmp(argv[i], "-raw"))
10426 -         candl_options_set(&(*options)->raw, argc, argv, &i);
10427 -       else
10428 -       if (!strcmp(argv[i], "-war"))
10429 -         candl_options_set(&(*options)->war, argc, argv, &i);
10430 -       else
10431 -       if (!strcmp(argv[i], "-rar"))
10432 -         candl_options_set(&(*options)->rar, argc, argv, &i);
10433 -       else
10434 -       if (!strcmp(argv[i], "-commute"))
10435 -         candl_options_set(&(*options)->commute, argc, argv, &i);
10436 -       else
10437 -       if (!strcmp(argv[i], "-fullcheck"))
10438 -         candl_options_set(&(*options)->fullcheck, argc, argv, &i);
10439 -       else
10440 -       if (!strcmp(argv[i], "-depgraph"))
10441 -         candl_options_set(&(*options)->depgraph, argc, argv, &i);
10442 -       else
10443 -       if (!strcmp(argv[i], "-violgraph"))
10444 -         candl_options_set(&(*options)->violgraph, argc, argv, &i);
10445 -       else
10446 -       if (!strcmp(argv[i], "-scalren"))
10447 -         candl_options_set(&(*options)->scalar_renaming, argc, argv, &i);
10448 -       else
10449 -       if (!strcmp(argv[i], "-scalpriv"))
10450 -         candl_options_set(&(*options)->scalar_privatization, argc, argv, &i);
10451 -       else
10452 -       if (!strcmp(argv[i], "-scalexp"))
10453 -         candl_options_set(&(*options)->scalar_expansion, argc, argv, &i);
10454 -       else
10455 -       if (!strcmp(argv[i], "-lastwriter"))
10456 -         candl_options_set(&(*options)->lastwriter, argc, argv, &i);
10457 -       else
10458 -       if (!strcmp(argv[i], "-view"))
10459 -         (*options)->view = 1;
10460 -       else
10461 -       if (!strcmp(argv[i], "-verbose"))
10462 -         (*options)->verbose = 1;
10463 -       else
10464 -       if (!strcmp(argv[i], "-inscop"))
10465 -         (*options)->readscop = 1;
10466 -       else
10467 -       if (!strcmp(argv[i], "-outscop"))
10468 -         (*options)->writescop = 1;
10469 -       else
10470 -       if (!strcmp(argv[i], "-scoptocandl"))
10471 -         (*options)->scoptocandl = 1;
10472 -       else
10473 -       if (!strcmp(argv[i], "-prune-dups"))
10474 -         (*options)->prune_dups = 1;
10475 -       else
10476 -       if ((!strcmp(argv[i], "-struct")) ||
10477 -           (!strcmp(argv[i], "-structure")))
10478 -         (*options)->structure = 1;
10479 -       else
10480 -       if ((!strcmp(argv[i], "--help")) || (!strcmp(argv[i], "-h")))
10481 -         {
10482 -           candl_options_help();
10483 -           infos = 1;
10484 -         }
10485 -       else
10486 -       if ((!strcmp(argv[i], "--version")) || (!strcmp(argv[i], "-v")))
10487 -         {
10488 -           candl_options_version();
10489 -           infos = 1;
10490 -         }
10491 -       else
10492 -       if (!strcmp(argv[i], "-o"))
10493 -         {
10494 -           if (i+1 >= argc)
10495 -             {
10496 -               fprintf(stderr,
10497 -                       "[Candl]ERROR: no output name for -o option.\n");
10498 -               exit(1);
10499 -             }
10500 -
10501 -           /* stdout is a special value, when used, we set output to standard
10502 -            * output.
10503 -            */
10504 -           if (!strcmp(argv[i+1], "stdout"))
10505 -             *output = stdout;
10506 -           else
10507 -             {
10508 -               *output = fopen(argv[i+1], "w");
10509 -               if (*output == NULL)
10510 -                 {
10511 -                   fprintf(stderr,
10512 -                           "[Candl]ERROR: can't create output file %s.\n",
10513 -                           argv[i+1]);
10514 -                   exit(1);
10515 -                 }
10516 -             }
10517 -           i++;
10518 -         }
10519 -       else
10520 -         fprintf(stderr,  "[Candl]ERROR: unknown %s option.\n", argv[i]);
10521 +  *input_test = NULL;
10522 +
10523 +  for (i = 1; i < argc; i++) {
10524 +    if (argv[i][0] == '-') {
10525 +      if (!strcmp(argv[i], "-waw")) {
10526 +        candl_options_set(&(*options)->waw, argc, argv, &i);
10527 +      } else
10528 +      if (!strcmp(argv[i], "-raw")) {
10529 +        candl_options_set(&(*options)->raw, argc, argv, &i);
10530 +      } else
10531 +      if (!strcmp(argv[i], "-war")) {
10532 +        candl_options_set(&(*options)->war, argc, argv, &i);
10533 +      } else
10534 +      if (!strcmp(argv[i], "-rar")) {
10535 +        candl_options_set(&(*options)->rar, argc, argv, &i);
10536 +      } else
10537 +      if (!strcmp(argv[i], "-commute")) {
10538 +        candl_options_set(&(*options)->commute, argc, argv, &i);
10539 +      } else
10540 +      if (!strcmp(argv[i], "-fullcheck")) {
10541 +        candl_options_set(&(*options)->fullcheck, argc, argv, &i);
10542 +      } else
10543 +      if (!strcmp(argv[i], "-scalren")) {
10544 +        candl_options_set(&(*options)->scalar_renaming, argc, argv, &i);
10545 +      } else
10546 +      if (!strcmp(argv[i], "-scalpriv")) {
10547 +        candl_options_set(&(*options)->scalar_privatization, argc, argv, &i);
10548 +      } else
10549 +      if (!strcmp(argv[i], "-scalexp")) {
10550 +        candl_options_set(&(*options)->scalar_expansion, argc, argv, &i);
10551 +      } else
10552 +      if (!strcmp(argv[i], "-lastwriter")) {
10553 +        candl_options_set(&(*options)->lastwriter, argc, argv, &i);
10554 +      }  else
10555 +      if (!strcmp(argv[i], "-autocorrect")) {
10556 +        candl_options_set(&(*options)->autocorrect, argc, argv, &i);
10557 +      } else
10558 +      if (!strcmp(argv[i], "-view")) {
10559 +        (*options)->view = 1;
10560 +      } else
10561 +      if (!strcmp(argv[i], "-verbose")) {
10562 +        (*options)->verbose = 1;
10563 +      } else
10564 +      if (!strcmp(argv[i], "-outscop")) {
10565 +        (*options)->outscop = 1;
10566 +      } else
10567 +      if (!strcmp(argv[i], "-prune-dups")) {
10568 +        (*options)->prune_dups = 1;
10569 +      } else
10570 +      if ((!strcmp(argv[i], "-struct")) ||
10571 +          (!strcmp(argv[i], "-structure"))) {
10572 +        (*options)->structure = 1;
10573 +      } else
10574 +      if ((!strcmp(argv[i], "--help")) || (!strcmp(argv[i], "-h"))) {
10575 +        candl_options_help();
10576 +        infos = 1;
10577 +      } else
10578 +      if ((!strcmp(argv[i], "--version")) || (!strcmp(argv[i], "-v"))) {
10579 +        candl_options_version();
10580 +        infos = 1;
10581 +      } else
10582 +      if (!strcmp(argv[i], "-o")) {
10583 +        i++;
10584 +        if (i >= argc) {
10585 +          fprintf(stderr,
10586 +                  "[Candl]ERROR: no output name for -o option.\n");
10587 +          exit(1);
10588 +        }
10589 +
10590 +        /* stdout is a special value, when used, we set output to standard
10591 +         * output.
10592 +         */
10593 +        if (!strcmp(argv[i], "stdout")) {
10594 +          *output = stdout;
10595 +        } else {
10596 +          *output = fopen(argv[i], "w");
10597 +          if (*output == NULL) {
10598 +            fprintf(stderr,
10599 +                    "[Candl]ERROR: can't create output file %s.\n",
10600 +                    argv[i]);
10601 +            exit(1);
10602 +          }
10603 +        }
10604 +      } else
10605 +      if (!strcmp(argv[i], "-test")) {
10606 +        i++;
10607 +        if (!testscop_is_set) {
10608 +          testscop_is_set = i;
10609 +          /* stdin is a special value, when used, we set input to
10610 +             standard input. */
10611 +          if (!strcmp(argv[i], "stdin")) {
10612 +            *input_test = stdin;
10613 +          } else {
10614 +            *input_test = fopen(argv[i], "r");
10615 +            if (*input_test == NULL) {
10616 +              fprintf(stderr,
10617 +                      "[Candl]ERROR: %s file does not exist.\n", argv[i]);
10618 +              exit(1);
10619 +            }
10620 +          }
10621 +        } else {
10622 +          fprintf(stderr, "[Candl]ERROR: multiple input files.\n");
10623 +          exit(1);
10624 +        }
10625 +      } else {
10626 +        fprintf(stderr,  "[Candl]ERROR: unknown %s option.\n", argv[i]);
10627        }
10628 -  else
10629 -  {
10630 -    if (!input_is_set)
10631 -      {
10632 -       input_is_set = 1;
10633 -       /* stdin is a special value, when used, we set input to
10634 -          standard input. */
10635 -       if (!strcmp(argv[i], "stdin"))
10636 -         *input = stdin;
10637 -       else
10638 -         {
10639 -           *input = fopen(argv[i], "r");
10640 -           if (*input == NULL)
10641 -             {
10642 -               fprintf(stderr,
10643 -                       "[Candl]ERROR: %s file does not exist.\n", argv[i]);
10644 -               exit(1);
10645 -             }
10646 -         }
10647 +    }
10648 +    else { /* open a file */
10649 +      if (!input_is_set) {
10650 +        input_is_set = i;
10651 +        /* stdin is a special value, when used, we set input to
10652 +           standard input. */
10653 +        if (!strcmp(argv[i], "stdin")) {
10654 +          *input = stdin;
10655 +        } else {
10656 +          *input = fopen(argv[i], "r");
10657 +          if (*input == NULL) {
10658 +            fprintf(stderr,
10659 +                    "[Candl]ERROR: %s file does not exist.\n", argv[i]);
10660 +            exit(1);
10661 +          }
10662 +        }
10663 +      } else {
10664 +        CANDL_error("multiple input files.\n");
10665        }
10666 -    else
10667 -    {
10668 -      fprintf(stderr, "[Candl]ERROR: multiple input files.\n");
10669 -      exit(1);
10670      }
10671    }
10672 -  if (!input_is_set)
10673 -    {
10674 -      if (!infos)
10675 -       fprintf(stderr, "[Candl]ERROR: no input file (-h for help).\n");
10676 -      exit(1);
10677 -    }
10678 +
10679 +  if ((*options)->autocorrect) {
10680 +    (*options)->fullcheck = 1;
10681 +    if (!*input_test)
10682 +      CANDL_error("no test file (-h for help).\n");
10683 +  }
10684 +
10685 +  if (!input_is_set) {
10686 +    if (!infos)
10687 +      CANDL_error("no input file (-h for help).\n");
10688 +    exit(1);
10689 +  }
10690 +
10691 +  if (*input_test && !strcmp(argv[input_is_set], argv[testscop_is_set])) {
10692 +    if (!infos)
10693 +      CANDL_error("the input file and the test scop can't be the same file.\n");
10694 +    exit(1);
10695 +  }
10696 +  
10697 +  if (infos)
10698 +    exit(0);
10699  }
10700  
10701 diff --git a/source/piplib-wrapper.c b/source/piplib-wrapper.c
10702 index 2ff4bb7..cdd44f3 100644
10703 --- a/source/piplib-wrapper.c
10704 +++ b/source/piplib-wrapper.c
10705 @@ -1,13 +1,13 @@
10706  
10707 -   /**------ ( ----------------------------------------------------------**
10708 -    **       )\                      CAnDL                               **
10709 -    **----- /  ) --------------------------------------------------------**
10710 -    **     ( * (               piplib-wrapper.c                          **
10711 -    **----  \#/  --------------------------------------------------------**
10712 -    **    .-"#'-.        First version: January 31st 2012                **
10713 -    **--- |"-.-"| -------------------------------------------------------**
10714 -          |     |
10715 -          |     |
10716 +/**------ ( ----------------------------------------------------------**
10717 + **       )\                      CAnDL                               **
10718 + **----- /  ) --------------------------------------------------------**
10719 + **     ( * (               piplib-wrapper.c                          **
10720 + **----  \#/  --------------------------------------------------------**
10721 + **    .-"#'-.        First version: January 31st 2012                **
10722 + **--- |"-.-"| -------------------------------------------------------**
10723 + |     |
10724 + |     |
10725   ******** |     | *************************************************************
10726   * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
10727   ******************************************************************************
10728 @@ -42,16 +42,99 @@
10729  #include <stdio.h>
10730  #include <string.h>
10731  #include <candl/candl.h>
10732 +#include <osl/macros.h> /* Need OSL_PRECISION for compatibility with piplib */
10733 +#include <osl/relation.h>
10734 +#include <candl/macros.h>
10735 +#include <candl/piplib.h>
10736  
10737  
10738 -int
10739 -pip_has_rational_point(PipMatrix* system,
10740 -                      PipMatrix* context,
10741 -                      int conservative)
10742 -{
10743 -#ifdef CANDL_HAS_PIPLIB_HYBRID
10744 -  return piplib_hybrid_has_rational_point(system, context, conservative);
10745 -#else
10746 +/**
10747 + * pip_relation2matrix function :
10748 + * This function is used to keep the compatibility with Piplib
10749 + */
10750 +PipMatrix* pip_relation2matrix(osl_relation_p in) {
10751 +  int i, j, precision;
10752 +  PipMatrix *out;
10753 +
10754 +  if (in == NULL)
10755 +    return NULL;
10756 +
10757 +  #ifdef CANDL_LINEAR_VALUE_IS_INT
10758 +    precision = OSL_PRECISION_SP;
10759 +  #elif defined(CANDL_LINEAR_VALUE_IS_LONGLONG)
10760 +    precision = OSL_PRECISION_DP;
10761 +  #elif defined(CANDL_LINEAR_VALUE_IS_MP)
10762 +    precision = OSL_PRECISION_MP;
10763 +  #endif
10764 +
10765 +  if (precision != in->precision)
10766 +    CANDL_error("Precision not compatible with piplib ! (pip_relation2matrix)");
10767 +
10768 +  out = pip_matrix_alloc(in->nb_rows, in->nb_columns);
10769 +  
10770 +  for (i = 0 ; i < in->nb_rows ; i++) {
10771 +    for (j = 0 ; j < in->nb_columns ; j++) {
10772 +      #if defined(CANDL_LINEAR_VALUE_IS_INT)
10773 +        CANDL_assign(out->p[i][j], in->m[i][j].sp);
10774 +      #elif defined(CANDL_LINEAR_VALUE_IS_LONGLONG)
10775 +        CANDL_assign(out->p[i][j], in->m[i][j].dp);
10776 +      #elif defined(CANDL_LINEAR_VALUE_IS_MP)
10777 +        CANDL_assign(out->p[i][j], *((mpz_t*)in->m[i][j].mp));
10778 +      #endif
10779 +    }
10780 +  }
10781 +  
10782 +  return out;
10783 +}
10784 +
10785 +
10786 +/**
10787 + * pip_matrix2relation function :
10788 + * This function is used to keep the compatibility with Piplib
10789 + */
10790 +osl_relation_p pip_matrix2relation(PipMatrix* in) {
10791 +  int i, j, precision;
10792 +  osl_relation_p out;
10793 +  osl_int_t temp;
10794 +  
10795 +  if (in == NULL)
10796 +    return NULL;
10797 +  
10798 +  #if defined(CANDL_LINEAR_VALUE_IS_INT)
10799 +    precision = OSL_PRECISION_SP;
10800 +  #elif defined(CANDL_LINEAR_VALUE_IS_LONGLONG)
10801 +    precision = OSL_PRECISION_DP;
10802 +  #elif defined(CANDL_LINEAR_VALUE_IS_MP)
10803 +    precision = OSL_PRECISION_MP;
10804 +  #endif
10805 +  
10806 +  out = osl_relation_pmalloc(precision, in->NbRows, in->NbColumns);
10807 +  osl_int_init(precision, &temp);
10808 +
10809 +  for (i = 0 ; i < in->NbRows ; i++) {
10810 +    for (j = 0 ; j < in->NbColumns ; j++) {
10811 +      #ifdef CANDL_LINEAR_VALUE_IS_INT
10812 +        temp.sp = in->p[i][j];
10813 +      #elif defined(CANDL_LINEAR_VALUE_IS_LONGLONG)
10814 +        temp.dp = in->p[i][j];
10815 +      #elif defined(CANDL_LINEAR_VALUE_IS_MP)
10816 +        mpz_set(*((mpz_t*)temp.mp), in->p[i][j]);
10817 +      #endif
10818 +      osl_int_assign(precision, &out->m[i][j], temp);
10819 +    }
10820 +  }
10821 +  
10822 +  osl_int_clear(precision, &temp);
10823 +  return out;
10824 +}
10825 +
10826 +int pip_has_rational_point(osl_relation_p system,
10827 +                       osl_relation_p context,
10828 +                       int conservative) {
10829 +// FIXME : compatibility with osl
10830 +//#ifdef CANDL_HAS_PIPLIB_HYBRID
10831 +//  return piplib_hybrid_has_rational_point(system, context, conservative);
10832 +//#else
10833    PipOptions* options;
10834    int ret = 0;
10835    options = pip_options_init ();
10836 @@ -59,13 +142,256 @@ pip_has_rational_point(PipMatrix* system,
10837    options->Urs_parms = -1;
10838    options->Urs_unknowns = -1;
10839    options->Nq = 0;
10840 -  PipQuast* solution = pip_solve (system, context, -1, options);
10841 +  PipQuast* solution = pip_solve_osl(system, context, -1, options);
10842    if ((solution != NULL) &&
10843        ((solution->list != NULL) || (solution->condition != NULL)))
10844      ret = 1;
10845 -  pip_options_free (options);
10846 -  pip_quast_free (solution);
10847 +  pip_options_free(options);
10848 +  pip_quast_free(solution);
10849    return ret;
10850 -#endif
10851 +//#endif
10852  }
10853  
10854 +
10855 +/**
10856 + * pip_solve_osl function :
10857 + * A pip_solve with osl_relation_p instead of PipMatrix
10858 + */
10859 +PipQuast* pip_solve_osl(osl_relation_p inequnk, osl_relation_p ineqpar,
10860 +                        int Bg, PipOptions *options) {
10861 +  PipMatrix *pip_unk  = pip_relation2matrix(inequnk);
10862 +  PipMatrix *pip_par  = pip_relation2matrix(ineqpar);
10863 +  PipQuast  *solution = pip_solve(pip_unk, pip_par, Bg, options);
10864 +  if (pip_unk) pip_matrix_free(pip_unk);
10865 +  if (pip_par) pip_matrix_free(pip_par);
10866 +  return solution;
10867 +}
10868 +
10869 +
10870 +/**
10871 + * Return true if the 'size' first elements of 'l1' and 'l2' are equal.
10872 + */
10873 +int piplist_are_equal(PipList* l1, PipList* l2, int size) {
10874 +  if (l1 == NULL && l2 == NULL)
10875 +    return 1;
10876 +  if (l1 == NULL || l2 == NULL)
10877 +    return 0;
10878 +  if (l1->vector == NULL && l2->vector == NULL)
10879 +    return 1;
10880 +  if (l1->vector == NULL || l2->vector == NULL)
10881 +    return 0;
10882 +
10883 +  int count = 0;
10884 +  for (; l1 && l2 && count < size; l1 = l1->next, l2 = l2->next, ++count) {
10885 +    if (l1->vector == NULL && l2->vector == NULL)
10886 +      return 1;
10887 +    if (l1->vector == NULL || l2->vector == NULL)
10888 +      return 0;
10889 +    if (l1->vector->nb_elements != l2->vector->nb_elements)
10890 +      return 0;
10891 +    int j;
10892 +    for (j = 0; j < l1->vector->nb_elements; ++j)
10893 +      if (! CANDL_eq(l1->vector->the_vector[j],
10894 +                     l2->vector->the_vector[j]) ||
10895 +          ! CANDL_eq(l1->vector->the_deno[j],
10896 +                     l2->vector->the_deno[j]))
10897 +        return 0;
10898 +  }
10899 +
10900 +  return 1;
10901 +}
10902 +
10903 +
10904 +/*
10905 + * Converts all conditions where the path does not lead to a solution
10906 + * The return is a upip_quast_to_polyhedranion of polyhedra
10907 + * extracted from pip_quast_to_polyhedra
10908 + */
10909 +osl_relation_p pip_quast_no_solution_to_polyhedra(PipQuast *quast, int nvar, 
10910 +                                                  int npar) {
10911 +  osl_relation_p ep;
10912 +  osl_relation_p tp;
10913 +  osl_relation_p qp;
10914 +  osl_relation_p iter;
10915 +  int precision;
10916 +  int j;
10917 +  if (quast == NULL)
10918 +    return NULL;
10919 +
10920 +  #if defined(CANDL_LINEAR_VALUE_IS_INT)
10921 +    precision = OSL_PRECISION_SP;
10922 +  #elif defined(CANDL_LINEAR_VALUE_IS_LONGLONG)
10923 +    precision = OSL_PRECISION_DP;
10924 +  #elif defined(CANDL_LINEAR_VALUE_IS_MP)
10925 +    precision = OSL_PRECISION_MP;
10926 +  #endif
10927 +
10928 +  if (quast->condition != NULL) {
10929 +    tp = pip_quast_no_solution_to_polyhedra(quast->next_then, nvar, npar);
10930 +    ep = pip_quast_no_solution_to_polyhedra(quast->next_else, nvar, npar);
10931 +      
10932 +    /* Each of the matrices in the then tree needs to be augmented with
10933 +     * the condition */
10934 +    for (iter = tp ; iter != NULL ; iter = iter->next) {
10935 +      int nrows = iter->nb_rows;
10936 +      osl_int_set_si(precision, &iter->m[nrows][0], 1);
10937 +      for (j = 1; j < 1 + nvar; j++)
10938 +        osl_int_set_si(precision, &iter->m[nrows][j], 0);
10939 +      for (j = 0; j < npar + 1; j++)
10940 +        osl_int_set_si(precision, &iter->m[nrows][1 + nvar + j],
10941 +                        CANDL_get_si(quast->condition->the_vector[j]));
10942 +      (iter->nb_rows)++;
10943 +    }
10944 +
10945 +    for (iter = ep; iter != NULL ; iter = iter->next) {
10946 +      int nrows = iter->nb_rows;
10947 +      /* Inequality */
10948 +      osl_int_set_si(precision, &iter->m[nrows][0], 1);
10949 +      for (j = 1; j < 1 + nvar; j++)
10950 +        osl_int_set_si(precision, &iter->m[nrows][j], 0);
10951 +      for (j = 0; j < npar + 1; j++)
10952 +        osl_int_set_si(precision, &iter->m[nrows][1 + nvar + j],
10953 +                     -CANDL_get_si(quast->condition->the_vector[j]));
10954 +      osl_int_decrement(precision, 
10955 +                        &iter->m[nrows][iter->nb_columns - 1],
10956 +                        iter->m[nrows][iter->nb_columns - 1]);
10957 +      (iter->nb_rows)++;
10958 +    }
10959 +
10960 +    /* union of tp and ep */
10961 +    if (tp) {
10962 +      qp = tp;
10963 +      for (iter = tp ; iter->next != NULL ; iter = iter->next)
10964 +        ;
10965 +      iter->next = ep;
10966 +    } else {
10967 +      qp = ep;
10968 +    }
10969 +
10970 +    return qp;
10971 +
10972 +  }
10973 +
10974 +  if (quast->list != NULL)
10975 +    return NULL;
10976 +
10977 +  /* quast condition is NULL */
10978 +  osl_relation_p lwmatrix = osl_relation_pmalloc(precision, nvar+npar+1,
10979 +                                                nvar+npar+2);
10980 +  lwmatrix->nb_rows = 0;
10981 +  lwmatrix->nb_parameters = npar;
10982 +
10983 +  return lwmatrix;
10984 +}
10985 +
10986 +
10987 +/*
10988 + * Converts a PIP quast to a union of polyhedra
10989 + */
10990 +osl_relation_p pip_quast_to_polyhedra(PipQuast *quast, int nvar, int npar) {
10991 +  // originaly used for lastwriter
10992 +  // july 5th 2012 : extracted from dependence.c
10993 +
10994 +  osl_relation_p ep;
10995 +  osl_relation_p tp;
10996 +  osl_relation_p qp;
10997 +  osl_relation_p iter;
10998 +  int precision;
10999 +  int j;
11000 +  if (quast == NULL)
11001 +    return NULL;
11002 +
11003 +  #if defined(CANDL_LINEAR_VALUE_IS_INT)
11004 +    precision = OSL_PRECISION_SP;
11005 +  #elif defined(CANDL_LINEAR_VALUE_IS_LONGLONG)
11006 +    precision = OSL_PRECISION_DP;
11007 +  #elif defined(CANDL_LINEAR_VALUE_IS_MP)
11008 +    precision = OSL_PRECISION_MP;
11009 +  #endif
11010 +
11011 +  if (quast->condition != NULL) {
11012 +    tp = pip_quast_to_polyhedra(quast->next_then, nvar, npar);
11013 +    ep = pip_quast_to_polyhedra(quast->next_else, nvar, npar);
11014 +      
11015 +    /* Each of the matrices in the then tree needs to be augmented with
11016 +     * the condition */
11017 +    for (iter = tp ; iter != NULL ; iter = iter->next) {
11018 +      int nrows = iter->nb_rows;
11019 +      osl_int_set_si(precision, &iter->m[nrows][0], 1);
11020 +      for (j = 1; j < 1 + nvar; j++)
11021 +        osl_int_set_si(precision, &iter->m[nrows][j], 0);
11022 +      for (j = 0; j < npar + 1; j++)
11023 +        osl_int_set_si(precision, &iter->m[nrows][1 + nvar + j],
11024 +                        CANDL_get_si(quast->condition->the_vector[j]));
11025 +      (iter->nb_rows)++;
11026 +    }
11027 +
11028 +    /* JP : july 5th 2012:
11029 +     * Fix negation of a constraint in adding -1 to the constant
11030 +     */
11031 +
11032 +    for (iter = ep; iter != NULL ; iter = iter->next) {
11033 +      int nrows = iter->nb_rows;
11034 +      /* Inequality */
11035 +      osl_int_set_si(precision, &iter->m[nrows][0], 5);
11036 +      for (j = 1; j < 1 + nvar; j++)
11037 +        osl_int_set_si(precision, &iter->m[nrows][j], 0);
11038 +      for (j = 0; j < npar + 1; j++)
11039 +        osl_int_set_si(precision, &iter->m[nrows][1 + nvar + j],
11040 +                     -CANDL_get_si(quast->condition->the_vector[j]));
11041 +      osl_int_decrement(precision, 
11042 +                        &iter->m[nrows][iter->nb_columns - 1],
11043 +                        iter->m[nrows][iter->nb_columns - 1]);
11044 +      (iter->nb_rows)++;
11045 +    }
11046 +
11047 +    /* union of tp and ep */
11048 +    if (tp) {
11049 +      qp = tp;
11050 +      for (iter = tp ; iter->next != NULL ; iter = iter->next)
11051 +        ;
11052 +      iter->next = ep;
11053 +    } else {
11054 +      qp = ep;
11055 +    }
11056 +
11057 +    return qp;
11058 +
11059 +  } else {
11060 +    /* quast condition is NULL */
11061 +    osl_relation_p lwmatrix = osl_relation_pmalloc(precision, nvar+npar+1,
11062 +                                                  nvar+npar+2);
11063 +    PipList *vecList = quast->list;
11064 +
11065 +    int count=0;
11066 +    while (vecList != NULL) {
11067 +      /* Equality */
11068 +      osl_int_set_si(precision, &lwmatrix->m[count][0], 0);
11069 +      for (j=0; j < nvar; j++)
11070 +        if (j == count)
11071 +          osl_int_set_si(precision, &lwmatrix->m[count][j + 1], 1);
11072 +        else
11073 +          osl_int_set_si(precision, &lwmatrix->m[count][j + 1], 0);
11074 +
11075 +      for (j=0; j < npar; j++)
11076 +        osl_int_set_si(precision, &lwmatrix->m[count][j + 1 + nvar],
11077 +                       -CANDL_get_si(vecList->vector->the_vector[j]));
11078 +      /* Constant portion */
11079 +      if (quast->newparm != NULL)
11080 +        /* Don't handle newparm for now */
11081 +        osl_int_set_si(precision, &lwmatrix->m[count][npar + 1 + nvar],
11082 +                       -CANDL_get_si(vecList->vector->the_vector[npar+1]));
11083 +      else
11084 +        osl_int_set_si(precision, &lwmatrix->m[count][npar + 1 + nvar],
11085 +                       -CANDL_get_si(vecList->vector->the_vector[npar]));
11086 +
11087 +      count++;
11088 +
11089 +      vecList = vecList->next;
11090 +    }
11091 +    lwmatrix->nb_rows = count;
11092 +    lwmatrix->nb_parameters = npar;
11093 +
11094 +    return lwmatrix;
11095 +  }
11096 +}
11097 diff --git a/source/program.c b/source/program.c
11098 deleted file mode 100644
11099 index 003e753..0000000
11100 --- a/source/program.c
11101 +++ /dev/null
11102 @@ -1,574 +0,0 @@
11103 -
11104 -   /**------ ( ----------------------------------------------------------**
11105 -    **       )\                      CAnDL                               **
11106 -    **----- /  ) --------------------------------------------------------**
11107 -    **     ( * (                   program.c                             **
11108 -    **----  \#/  --------------------------------------------------------**
11109 -    **    .-"#'-.        First version: september 9th 2003               **
11110 -    **--- |"-.-"| -------------------------------------------------------**
11111 -          |     |
11112 -          |     |
11113 - ******** |     | *************************************************************
11114 - * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
11115 - ******************************************************************************
11116 - *                                                                            *
11117 - * Copyright (C) 2003-2008 Cedric Bastoul                                     *
11118 - *                                                                            *
11119 - * This is free software; you can redistribute it and/or modify it under the  *
11120 - * terms of the GNU Lesser General Public License as published by the Free    *
11121 - * Software Foundation; either version 3 of the License, or (at your option)  *
11122 - * any later version.                                                         *
11123 - *                                                                            *
11124 - * This software is distributed in the hope that it will be useful, but       *
11125 - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
11126 - * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   *
11127 - * for more details.                                                          *
11128 - *                                                                            *
11129 - * You should have received a copy of the GNU Lesser General Public License   *
11130 - * along with software; if not, write to the Free Software Foundation, Inc.,  *
11131 - * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA                     *
11132 - *                                                                            *
11133 - * CAnDL, the Chunky Dependence Analyzer                                      *
11134 - * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr                         *
11135 - *                                                                            *
11136 - ******************************************************************************/
11137 -
11138 -
11139 -#include <sys/types.h>
11140 -#include <sys/time.h>
11141 -#include <sys/resource.h>
11142 -#include <stdlib.h>
11143 -#include <stdio.h>
11144 -#include <string.h>
11145 -#include <ctype.h>
11146 -
11147 -#include <candl/candl.h>
11148 -#include <candl/program.h>
11149 -
11150 -
11151 -/******************************************************************************
11152 - *                          Structure display function                        *
11153 - ******************************************************************************/
11154 -
11155 -/**
11156 - * candl_program_print_structure function:
11157 - * Displays a candl_program_t structure (program) into a file (file,
11158 - * possibly stdout) in a way that trends to be understandable without falling
11159 - * in a deep depression or, for the lucky ones, getting a headache... It
11160 - * includes an indentation level (level) in order to work with others
11161 - * print_structure functions.
11162 - * - 09/09/2003: first version.
11163 - */
11164 -void candl_program_print_structure(FILE* file, candl_program_p program,
11165 -                                  int level)
11166 -{
11167 -  int i, j;
11168 -
11169 -  if (program != NULL)
11170 -  {
11171 -    /* Go to the right level. */
11172 -    for (j = 0; j < level; j++)
11173 -      fprintf(file,"|\t");
11174 -    fprintf(file,"+-- candl_program_t\n");
11175 -
11176 -    /* A blank line. */
11177 -    for (j = 0; j <= level + 1; j++)
11178 -      fprintf(file,"|\t");
11179 -    fprintf(file,"\n");
11180 -
11181 -    /* Print the context. */
11182 -    candl_matrix_print_structure(file, program->context, level+1);
11183 -
11184 -    /* A blank line. */
11185 -    for (j = 0; j <= level+1; j++)
11186 -      fprintf(file, "|\t");
11187 -    fprintf(file, "\n");
11188 -
11189 -    /* Go to the right level and print the statement number. */
11190 -    for (j = 0; j <= level; j++)
11191 -      fprintf(file, "|\t");
11192 -    fprintf(file, "Statement number: %d\n", program->nb_statements);
11193 -
11194 -    /* A blank line. */
11195 -    for (j = 0; j <= level+1; j++)
11196 -      fprintf(file, "|\t");
11197 -    fprintf(file, "\n");
11198 -
11199 -    /* Print the statements. */
11200 -    for (i = 0; i < program->nb_statements; ++i)
11201 -      candl_statement_print_structure(file, program->statement[i], level+1);
11202 -
11203 -    /* Print the transformation candidate. */
11204 -    if (program->transformation != NULL)
11205 -      for (i = 0; i < program->nb_statements; i++)
11206 -       candl_matrix_print_structure(file, program->transformation[i], level+1);
11207 -    else
11208 -      {
11209 -       /* Go to the right level. */
11210 -       for (j = 0; j <= level; j++)
11211 -         fprintf(file, "|\t");
11212 -       fprintf(file, "+-- No transformation candidate\n");
11213 -
11214 -       /* A blank line. */
11215 -       for (j = 0; j <= level+1; j++)
11216 -         fprintf(file, "|\t");
11217 -       fprintf(file, "\n");
11218 -      }
11219 -  }
11220 -  else
11221 -    {
11222 -      /* Go to the right level. */
11223 -      for (j = 0; j < level; j++)
11224 -       fprintf(file, "|\t");
11225 -      fprintf(file, "+-- NULL candl_program_t\n");
11226 -    }
11227 -
11228 -  /* The last line. */
11229 -  for (j = 0; j <= level; j++)
11230 -    fprintf(file, "|\t");
11231 -  fprintf(file, "\n");
11232 -}
11233 -
11234 -
11235 -/**
11236 - * candl_program_print function:
11237 - * This function prints the content of a candl_program_t structure
11238 - * (program) into a file (file, possibly stdout).
11239 - */
11240 -void candl_program_print(FILE * file,  candl_program_p program)
11241 -{
11242 -  candl_program_print_structure(file, program,0);
11243 -}
11244 -
11245 -
11246 -
11247 -/**
11248 - * candl_program_print function:
11249 - * This function prints a candl_program_t structure (program) into a
11250 - * candl-formatted file (file, possibly stdout).
11251 - */
11252 -void candl_program_print_candl_file(FILE * file, candl_program_p program)
11253 -{
11254 -  int i, j;
11255 -
11256 -  fprintf (file, "# -------------------\n");
11257 -  fprintf (file, "# Context\n");
11258 -  candl_matrix_print_data(file, program->context);
11259 -  fprintf (file, "\n");
11260 -  fprintf (file, "# Number of statements\n");
11261 -  fprintf (file, "%d\n", program->nb_statements);
11262 -  for (i = 0; i < program->nb_statements; ++i)
11263 -    {
11264 -      fprintf (file, "# -------------------\n");
11265 -      fprintf (file, "# Statement %d\n", i + 1);
11266 -      fprintf (file, "# Statement type\n");
11267 -      /* All types set to Assignment. */
11268 -      fprintf (file, "A\n");
11269 -      fprintf (file, "\n");
11270 -      fprintf (file, "# Iteration domain\n");
11271 -      candl_matrix_print_data(file, program->statement[i]->domain);
11272 -      fprintf (file, "\n");
11273 -      fprintf (file, "# Loop labels\n");
11274 -      for (j = 0; j < program->statement[i]->depth; ++j)
11275 -       fprintf (file, "%d ", program->statement[i]->index[j]);
11276 -      fprintf (file, "\n");
11277 -      fprintf (file, "# Written items\n");
11278 -      candl_matrix_print_data(file, program->statement[i]->written);
11279 -      fprintf (file, "\n");
11280 -      fprintf (file, "# Read items\n");
11281 -      candl_matrix_print_data(file, program->statement[i]->read);
11282 -      fprintf (file, "\n");
11283 -    }
11284 -  fprintf (file, "# -------------------\n");
11285 -  fprintf (file, "# Transformation candidate\n");
11286 -  fprintf (file, "0\n");
11287 -}
11288 -
11289 -
11290 -/******************************************************************************
11291 - *                         Memory alloc/dealloc function                      *
11292 - ******************************************************************************/
11293 -
11294 -
11295 -/**
11296 - * candl_program_malloc function:
11297 - * This function allocates the memory space for a candl_program_t structure and
11298 - * sets its fields with default values. Then it returns a pointer to the
11299 - * allocated space.
11300 - * - 09/12/2005: first version.
11301 - */
11302 -candl_program_p candl_program_malloc()
11303 -{
11304 -  candl_program_p program;
11305 -
11306 -  /* Memory allocation for the candl_program_t structure. */
11307 -  program = (candl_program_p)malloc(sizeof(candl_program_t));
11308 -  if (program == NULL)
11309 -    CANDL_FAIL("Error: memory overflow");
11310 -
11311 -  /* We set the various fields with default values. */
11312 -  program->context        = NULL;
11313 -  program->nb_statements  = 0;
11314 -  program->statement      = NULL;
11315 -  program->transformation = NULL;
11316 -  program->scalars_privatizable = NULL;
11317 -
11318 -  return program;
11319 -}
11320 -
11321 -
11322 -/**
11323 - * candl_program_free function:
11324 - * This function frees the allocated memory for a candl_program_t structure, it
11325 - * recursively frees everything inside.
11326 - */
11327 -void candl_program_free(candl_program_p program)
11328 -{
11329 -  int i;
11330 -
11331 -  candl_matrix_free(program->context);
11332 -
11333 -  if (program->statement != NULL)
11334 -    {
11335 -      for (i = 0; i < program->nb_statements; i++)
11336 -       candl_statement_free(program->statement[i]);
11337 -      free(program->statement);
11338 -    }
11339 -
11340 -  if (program->transformation != NULL)
11341 -    {
11342 -      for (i = 0; i < program->nb_statements; i++)
11343 -       candl_matrix_free(program->transformation[i]);
11344 -      free(program->transformation);
11345 -    }
11346 -
11347 -  if (program->scalars_privatizable != NULL)
11348 -    free(program->scalars_privatizable);
11349 -
11350 -  free(program);
11351 -}
11352 -
11353 -
11354 -/******************************************************************************
11355 - *                               Reading function                             *
11356 - ******************************************************************************/
11357 -
11358 -
11359 -/**
11360 - * candl_program_read function:
11361 - * This function reads the informations to put in a candl_program_t
11362 - * structure from a file (file, possibly stdin). It returns a pointer
11363 - * to a candl_program_t structure containing the read informations.
11364 - * September 10th 2003: first version.
11365 - */
11366 -candl_program_p candl_program_read(FILE * file)
11367 -{
11368 -  int i,  nb_statements,  nb_parameters,  nb_functions;
11369 -  char s[CANDL_MAX_STRING];
11370 -  CandlStatement ** statement;
11371 -  CandlMatrix    ** transformation;
11372 -  candl_program_p program;
11373 -
11374 -  /* Memory allocation for the candl_program_t structure. */
11375 -  program = candl_program_malloc();
11376 -
11377 -  /* First of all,  we read the context data. */
11378 -  program->context  = candl_matrix_read(file);
11379 -  nb_parameters = program->context->NbColumns - 2;
11380 -
11381 -  /* We read the number of statements. */
11382 -  while (fgets(s, CANDL_MAX_STRING, file) == 0)
11383 -    ;
11384 -  while ((*s=='#'||*s=='\n') || (sscanf(s, " %d", &nb_statements) < 1))
11385 -    fgets(s, CANDL_MAX_STRING, file);
11386 -
11387 -  program->nb_statements = nb_statements;
11388 -
11389 -  /* Reading of each statement. */
11390 -  if (nb_statements > 0)
11391 -    {
11392 -      /* Memory allocation for the array of pointers to the statements. */
11393 -      statement = (CandlStatement**) malloc(nb_statements *
11394 -                                           sizeof(CandlStatement*));
11395 -      if (statement == NULL)
11396 -       CANDL_FAIL("Error: memory overflow");
11397 -
11398 -      for (i = 0; i < nb_statements; i++)
11399 -       statement[i] = candl_statement_read(file, i, nb_parameters);
11400 -
11401 -      program->statement = statement;
11402 -    }
11403 -
11404 -  /* We read the number of transformation functions. */
11405 -  while (fgets(s, CANDL_MAX_STRING, file) == 0)
11406 -    ;
11407 -  while ((*s=='#' || *s=='\n') || (sscanf(s, " %d", &nb_functions) < 1))
11408 -    fgets(s, CANDL_MAX_STRING, file);
11409 -
11410 -  /* Reading of each transformation function. */
11411 -  if (nb_functions > 0)
11412 -    {
11413 -      /* The function number must be the same as statement number. */
11414 -      if (nb_functions != nb_statements)
11415 -       {
11416 -         fprintf(stderr,
11417 -                 "[Candl]ERROR: the numbers of transformations (%d) and "
11418 -                 "statements (%d) differ.\n", nb_functions, nb_statements);
11419 -         exit(1);
11420 -       }
11421 -
11422 -      /* Memory allocation for the array of pointers to the functions. */
11423 -      transformation = (CandlMatrix **)malloc(nb_functions *
11424 -                                             sizeof(CandlMatrix *));
11425 -      if (transformation == NULL)
11426 -       CANDL_FAIL("Error: memory overflow");
11427 -
11428 -      for (i = 0; i < nb_functions; i++)
11429 -       transformation[i] = candl_matrix_read(file);
11430 -
11431 -      program->transformation = transformation;
11432 -    }
11433 -
11434 -  return(program);
11435 -}
11436 -
11437 -
11438 -/**
11439 - * This function reads the .scop formatted file 'file', check for the
11440 - * existence of the <candl> tag in the file, and retrieve the loop
11441 - * index information, if any.
11442 - * This function is built only if candl was configured with ScopLib support.
11443 - *
11444 - */
11445 -#ifdef CANDL_SUPPORTS_SCOPLIB
11446 -static
11447 -int** candl_program_scop_get_opt_indices(scoplib_scop_p scop)
11448 -{
11449 -  /* Get the <candl></candl> tag content. */
11450 -  char* candl_opts = scoplib_scop_tag_content(scop, "<candl>", "</candl>");
11451 -  if (! candl_opts)
11452 -    return NULL;
11453 -  /* Get the <candl><indices></indices></candl> tag content. */
11454 -  char* indices = scoplib_scop_tag_content_from_string(candl_opts, "<indices>",
11455 -                                                      "</indices>");
11456 -  free (candl_opts);
11457 -  if (! indices)
11458 -    return NULL;
11459 -
11460 -  /* Tag was found. Scan it. */
11461 -  int buffer_size = 128;
11462 -  /* Assume maximum loop nest depth of 128. */
11463 -  int line[128];
11464 -  char buff[32];
11465 -  int** res = malloc(buffer_size * sizeof(int*));
11466 -  int i, j;
11467 -  int count, idx = 0;
11468 -  int line_added = 0;
11469 -  char* s = indices;
11470 -
11471 -  while (s && *s != '\0')
11472 -    {
11473 -      for (i = 0; i < 128; ++i)
11474 -       {
11475 -         while (*s != '\0' && *s != '\n' && isspace(*s))
11476 -           ++s;
11477 -         if (*s != '\0' && *s != '#' && *s != '\n')
11478 -           {
11479 -             for (count = 0; *s >= '0' && *s <= '9'; ++count)
11480 -               buff[count] = *(s++);
11481 -             buff[count] = '\0';
11482 -             line[i] = atoi(buff);
11483 -             line_added = 1;
11484 -           }
11485 -         else
11486 -           break;
11487 -       }
11488 -      if (line_added)
11489 -       {
11490 -         if (idx == buffer_size)
11491 -           res = realloc(res, (buffer_size *= 2) * sizeof(int*));
11492 -         res[idx] = (int*) malloc(i * sizeof(int));
11493 -         for (j = 0; j < i; ++j)
11494 -           res[idx][j] = line[j];
11495 -         ++idx;
11496 -         line_added = 0;
11497 -       }
11498 -      while (s && *s != '\0' && *s != '\n')
11499 -       ++s;
11500 -      if (s && *s != '\0' && *s == '\n')
11501 -       ++s;
11502 -    }
11503 -  res = realloc(res, idx * sizeof(int*));
11504 -  free (indices);
11505 -
11506 -  return res;
11507 -}
11508 -#endif
11509 -
11510 -
11511 -/**
11512 - * candl_program_read_scop function:
11513 - * This function reads the informations to put in a candl_program_t
11514 - * structure from a file (file, possibly stdin) following the .scop
11515 - * format.  It returns a pointer to a candl_program_t structure
11516 - * containing the read informations.
11517 - * This function is built only if candl was configured with ScopLib support.
11518 - *
11519 - */
11520 -#ifdef CANDL_SUPPORTS_SCOPLIB
11521 -candl_program_p candl_program_read_scop(FILE * file)
11522 -{
11523 -  int i;
11524 -
11525 -  /* Read the scop. */
11526 -  scoplib_scop_p scop = scoplib_scop_read(file);
11527 -  /* Check for the <candl> tag in the options of the .scop file. */
11528 -  int** indices = candl_program_scop_get_opt_indices(scop);
11529 -  /* Convert the scop. */
11530 -  candl_program_p res = candl_program_convert_scop(scop, indices);
11531 -
11532 -  /* Clean temporary data. */
11533 -  if (indices)
11534 -    {
11535 -      for (i = 0; i < res->nb_statements; ++i)
11536 -       free(indices[i]);
11537 -      free(indices);
11538 -    }
11539 -  scoplib_scop_free(scop);
11540 -
11541 -  return res;
11542 -}
11543 -#endif
11544 -
11545 -
11546 -/******************************************************************************
11547 - *                            Processing functions                            *
11548 - ******************************************************************************/
11549 -
11550 -
11551 -/**
11552 - * candl_program_convert_scop function:
11553 - * This function extracts the useful information of a scoplib_scop_t
11554 - * structure to a fresh, independent candl_program_t structure.
11555 - * This function is built only if candl was configured with ScopLib support.
11556 - *
11557 - */
11558 -#ifdef CANDL_SUPPORTS_SCOPLIB
11559 -candl_program_p candl_program_convert_scop(scoplib_scop_p scop, int** indices)
11560 -{
11561 -  int i, j, k, l;
11562 -  candl_program_p res = candl_program_malloc();
11563 -  scoplib_statement_p s = scop->statement;
11564 -
11565 -  /* Duplicate the context. */
11566 -  res->context = (CandlMatrix*) scoplib_matrix_copy(scop->context);
11567 -  if (res->context == NULL)
11568 -    res->context = candl_matrix_malloc(0, 2);
11569 -
11570 -  /* Count the number of statements. */
11571 -  for (res->nb_statements = 0; s; s = s->next, res->nb_statements++)
11572 -    ;
11573 -
11574 -  /* Allocate the statements array. */
11575 -  res->statement = (CandlStatement**) malloc(res->nb_statements *
11576 -                                            sizeof(CandlStatement*));
11577 -
11578 -  /* Initialize structures used in iterator indices computation. */
11579 -  int max = 0;
11580 -  int max_loop_depth = 128;
11581 -  int cur_index[max_loop_depth];
11582 -  int last[max_loop_depth];
11583 -  for (i = 0; i < max_loop_depth; ++i)
11584 -    {
11585 -      cur_index[i] = i;
11586 -      last[i] = 0;
11587 -    }
11588 -  /* Create the statements. */
11589 -  for (i = 0, s = scop->statement; s; s = s->next, ++i)
11590 -    {
11591 -      CandlStatement* statement = candl_statement_malloc();
11592 -      statement->label = i;
11593 -      statement->ref = s;
11594 -      if (s->domain->next != NULL)
11595 -       CANDL_FAIL("Error: union of domains not supported");
11596 -
11597 -      statement->domain = (CandlMatrix*) scoplib_matrix_copy(s->domain->elt);
11598 -      /* For the moment, we do not parse the statement to extract its type. */
11599 -      statement->type = CANDL_ASSIGNMENT;
11600 -      statement->depth = statement->domain->NbColumns - 2 - scop->nb_parameters;
11601 -      statement->written = (CandlMatrix*) scoplib_matrix_copy(s->write);
11602 -      if (statement->written == NULL)
11603 -       statement->written =
11604 -         candl_matrix_malloc(0, statement->domain->NbColumns);
11605 -      statement->read = (CandlMatrix*) scoplib_matrix_copy(s->read);
11606 -      if (statement->read == NULL)
11607 -       statement->read = candl_matrix_malloc(0, statement->domain->NbColumns);
11608 -      statement->index = (int*) malloc(statement->depth * sizeof(int));
11609 -      if (indices != NULL)
11610 -       /* Iterator indices are provided. */
11611 -       for (j = 0; j < statement->depth; ++j)
11612 -         statement->index[j] = indices[i][j];
11613 -      else
11614 -       {
11615 -         /* Iterator indices must be computed from the scattering matrix. */
11616 -         scoplib_matrix_p m = s->schedule;
11617 -         if (m == NULL)
11618 -           CANDL_FAIL("Error: No scheduling matrix and no loop "
11619 -                      "indices specification");
11620 -
11621 -         /* FIXME: Sort the statements in their execution order. */
11622 -         /* It must be a 2d+1 identity scheduling matrix, and
11623 -            statements must be sorted in their execution order. */
11624 -         /* Check that it is a identity matrix. */
11625 -         int error = 0;
11626 -         if (m->NbRows != 2 * statement->depth + 1)
11627 -           error = 1;
11628 -         else
11629 -           for (l = 0; l < m->NbRows; ++l)
11630 -             {
11631 -               for (k = 1; k < m->NbColumns - 1; ++k)
11632 -                 switch (CANDL_get_si(m->p[l][k]))
11633 -                   {
11634 -                   case 0:
11635 -                     if (l % 2 && k == (l / 2) + 1) error = 1;
11636 -                     break;
11637 -                   case 1:
11638 -                     if ((l % 2 && k != (l / 2) + 1) || (! l % 2)) error = 1;
11639 -                     break;
11640 -                   default:
11641 -                     error = 1;
11642 -                     break;
11643 -                   }
11644 -               if (l % 2 && CANDL_get_si(m->p[l][k]))
11645 -                 error = 1;
11646 -             }
11647 -         if (error)
11648 -           CANDL_FAIL("Error: schedule is not identity 2d+1 shaped.\n"
11649 -                      "Consider using the <indices> option tag to declare "
11650 -                      " iterator indices");
11651 -
11652 -         /* Compute the value of the iterator indices. */
11653 -         for (j = 0; j < statement->depth; ++j)
11654 -           {
11655 -             int val = CANDL_get_si(m->p[2 * j][m->NbColumns - 1]);
11656 -             if (last[j] < val)
11657 -               {
11658 -                 last[j] = val;
11659 -                 for (k = j + 1; k < max_loop_depth; ++k)
11660 -                   last[k] = 0;
11661 -                 for (k = j; k < max_loop_depth; ++k)
11662 -                   cur_index[k] = max + (k - j) + 1;
11663 -                 break;
11664 -               }
11665 -           }
11666 -         for (j = 0; j < statement->depth; ++j)
11667 -           statement->index[j] = cur_index[j];
11668 -         max = max < cur_index[j - 1] ? cur_index[j - 1] : max;
11669 -       }
11670 -      /* Store the statement. */
11671 -      res->statement[i] = statement;
11672 -    }
11673 -
11674 -  return res;
11675 -}
11676 -#endif
11677 diff --git a/source/pruning.c b/source/pruning.c
11678 index 2b0cf49..db4a90f 100644
11679 --- a/source/pruning.c
11680 +++ b/source/pruning.c
11681 @@ -6,8 +6,8 @@
11682      **----  \#/  --------------------------------------------------------**
11683      **    .-"#'-.        First version: July 17th 2011                   **
11684      **--- |"-.-"| -------------------------------------------------------**
11685 -          |     |
11686 -          |     |
11687 +    |     |
11688 +    |     |
11689   ******** |     | *************************************************************
11690   * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
11691   ******************************************************************************
11692 @@ -40,35 +40,15 @@
11693  #include <stdlib.h>
11694  #include <stdio.h>
11695  #include <string.h>
11696 -#include <candl/candl.h>
11697 -
11698  #include <assert.h>
11699 +#include <osl/statement.h>
11700 +#include <osl/relation.h>
11701 +#include <candl/statement.h>
11702 +#include <candl/dependence.h>
11703  
11704  
11705 -/**
11706 - * Return true if the 2 matrices are strictly identical.
11707 - */
11708 -static
11709 -int candl_matrix_equal(CandlMatrix* m1, CandlMatrix* m2)
11710 -{
11711 -  int i, j;
11712 +#if defined(CANDL_COMPILE_PRUNNING_C)
11713  
11714 -  if (m1 == NULL)
11715 -    {
11716 -      if (m2 == NULL)
11717 -       return 1;
11718 -      return 0;
11719 -    }
11720 -
11721 -  if (m1->NbRows != m2->NbRows || m1->NbColumns != m2->NbColumns)
11722 -    return 0;
11723 -
11724 -  for (i = 0; i < m1->NbRows; ++i)
11725 -    for (j = 0; j < m1->NbColumns; ++j)
11726 -      if (! CANDL_eq(m1->p[i][j], m2->p[i][j]))
11727 -       return 0;
11728 -  return 1;
11729 -}
11730  
11731  #define BUFF_SIZE 1024
11732  
11733 @@ -79,79 +59,69 @@ int candl_matrix_equal(CandlMatrix* m1, CandlMatrix* m2)
11734   * Paths are stored as list of lists of dependences in 'paths_list'.
11735   */
11736  static
11737 -void find_paths_rec (int tgt_id, int cur_length, int max_length,
11738 -                    int final_id,
11739 -                    CandlDependence** alldeps,
11740 -                    CandlDependence** cur_path,
11741 -                    CandlDependence**** paths_list)
11742 -{
11743 +void find_paths_rec(int tgt_id, int cur_length, int max_length,
11744 +                    int final_id,
11745 +                    osl_dependence_p* alldeps,
11746 +                    osl_dependence_p* cur_path,
11747 +                    osl_dependence_p*** paths_list) {
11748    int i;
11749  
11750 -  for (i = 0; alldeps[i]; ++i)
11751 -    {
11752 -      if (alldeps[i]->usr == NULL)
11753 -       {
11754 -         if (alldeps[i]->source->label == tgt_id)
11755 -           {
11756 -             // Ensure the path flow is consistent.
11757 -             if (cur_length > 1)
11758 -               {
11759 -                 if (cur_path[cur_length - 1]->type == CANDL_RAW ||
11760 -                     cur_path[cur_length - 1]->type == CANDL_RAW_SCALPRIV ||
11761 -                     cur_path[cur_length - 1]->type == CANDL_RAR)
11762 -                   {
11763 -                     // RAW or RAR.
11764 -                     if (alldeps[i]->type != CANDL_RAR &&
11765 -                         alldeps[i]->type != CANDL_WAR)
11766 -                       continue;
11767 -                   }
11768 -                 else
11769 -                   {
11770 -                     // WAW or WAR.
11771 -                     if (alldeps[i]->type != CANDL_WAW &&
11772 -                         alldeps[i]->type != CANDL_RAW)
11773 -                       continue;
11774 -                   }
11775 -               }
11776 -             if (cur_length + 1 == max_length)
11777 -               {
11778 -                 if (alldeps[i]->target->label == final_id)
11779 -                   {
11780 -                     // Found a path.
11781 -                     int j, pos;
11782 -                     for (pos = 0; (*paths_list)[pos]; ++pos)
11783 -                       ;
11784 -                     if (pos + 1 % BUFF_SIZE == 0)
11785 -                       {
11786 -                         *paths_list = (CandlDependence***)
11787 -                           realloc(*paths_list, sizeof(CandlDependence**) *
11788 -                                   (BUFF_SIZE + pos + 1));
11789 -                         *paths_list[pos + 1] = NULL;
11790 -                       }
11791 -                     (*paths_list)[pos] = (CandlDependence**)
11792 -                       malloc((max_length + 1) * sizeof(CandlDependence*));
11793 -                     for (j = 0; j < max_length - 1; ++j)
11794 -                       (*paths_list)[pos][j] = cur_path[j];
11795 -                     (*paths_list)[pos][j++] = alldeps[i];
11796 -                     (*paths_list)[pos][j] = NULL;
11797 -                   }
11798 -               }
11799 -             else
11800 -               {
11801 -                 // Store the current node in the path.
11802 -                 cur_path[cur_length] = alldeps[i];
11803 -                 // Mark the dependence as processed.
11804 -                 alldeps[i]->usr = alldeps[i];
11805 -                 // Look for the next node.
11806 -                 find_paths_rec (alldeps[i]->target->label, cur_length + 1,
11807 -                                 max_length, final_id, alldeps, cur_path,
11808 -                                 paths_list);
11809 -                 // Reset the dependence.
11810 -                 alldeps[i]->usr = NULL;
11811 -               }
11812 -           }
11813 -       }
11814 +  for (i = 0; alldeps[i]; ++i) {
11815 +    if (alldeps[i]->usr == NULL) {
11816 +      ((candl_statement_usr_p)target->usr)->label
11817 +      if (alldeps[i]->((candl_statement_usr_p)source->usr)->label == tgt_id) {
11818 +        // Ensure the path flow is consistent.
11819 +        if (cur_length > 1) {
11820 +          if (cur_path[cur_length - 1]->type == CANDL_RAW ||
11821 +              cur_path[cur_length - 1]->type == CANDL_RAW_SCALPRIV ||
11822 +              cur_path[cur_length - 1]->type == CANDL_RAR) {
11823 +            // RAW or RAR.
11824 +            if (alldeps[i]->type != CANDL_RAR &&
11825 +                alldeps[i]->type != CANDL_WAR)
11826 +              continue;
11827 +          }
11828 +          else {
11829 +            // WAW or WAR.
11830 +            if (alldeps[i]->type != CANDL_WAW &&
11831 +                alldeps[i]->type != CANDL_RAW)
11832 +              continue;
11833 +          }
11834 +        }
11835 +        if (cur_length + 1 == max_length) {
11836 +          if (alldeps[i]->((candl_statement_usr_p)target->usr)->label == final_id) {
11837 +            // Found a path.
11838 +            int j, pos;
11839 +            for (pos = 0; (*paths_list)[pos]; ++pos)
11840 +              ;
11841 +            if (pos + 1 % BUFF_SIZE == 0) {
11842 +              *paths_list = (osl_dependence_p**)
11843 +                  realloc(*paths_list, sizeof(osl_dependence_p*) *
11844 +                          (BUFF_SIZE + pos + 1));
11845 +              *paths_list[pos + 1] = NULL;
11846 +            }
11847 +            (*paths_list)[pos] = (osl_dependence_p*)
11848 +                malloc((max_length + 1) * sizeof(osl_dependence_p));
11849 +            for (j = 0; j < max_length - 1; ++j)
11850 +              (*paths_list)[pos][j] = cur_path[j];
11851 +            (*paths_list)[pos][j++] = alldeps[i];
11852 +            (*paths_list)[pos][j] = NULL;
11853 +          }
11854 +        }
11855 +        else {
11856 +          // Store the current node in the path.
11857 +          cur_path[cur_length] = alldeps[i];
11858 +          // Mark the dependence as processed.
11859 +          alldeps[i]->usr = alldeps[i];
11860 +          // Look for the next node.
11861 +          find_paths_rec(alldeps[i]->((candl_statement_usr_p)target->usr)->label,
11862 +                         cur_length + 1, max_length, final_id, alldeps,
11863 +                         cur_path, paths_list);
11864 +          // Reset the dependence.
11865 +          alldeps[i]->usr = NULL;
11866 +        }
11867 +      }
11868      }
11869 +  }
11870  }
11871  
11872  
11873 @@ -162,91 +132,55 @@ void find_paths_rec (int tgt_id, int cur_length, int max_length,
11874   * 'target->label'.
11875   */
11876  static
11877 -CandlDependence***
11878 -find_dep_paths (CandlDependence** ardeps,
11879 -               CandlStatement* source,
11880 -               CandlStatement*target)
11881 -{
11882 +osl_dependence_p** find_dep_paths(osl_dependence_p* ardeps,
11883 +                                    osl_statement_p source,
11884 +                                    osl_statement_p target) {
11885    int i, nb_dep;
11886    for (nb_dep = 0; ardeps[nb_dep]; ++nb_dep)
11887      ;
11888    if (nb_dep < 2)
11889      return NULL;
11890 -  CandlDependence* cur_path[nb_dep + 1];
11891 -  CandlDependence*** paths_list =
11892 -    (CandlDependence***)malloc(BUFF_SIZE * sizeof(CandlDependence**));
11893 +  osl_dependence_p *cur_path =
11894 +      (osl_dependence_p*) malloc(sizeof(osl_dependence_p) *
11895 +                                   (nb_dep + 1));
11896 +  osl_dependence_p** paths_list =
11897 +      (osl_dependence_p**)malloc(BUFF_SIZE * sizeof(osl_dependence_p*));
11898    for (i = 0; i < BUFF_SIZE; ++i)
11899      paths_list[i] = NULL;
11900    // Iterate on all possible paths length, from Sx to Sy, of length y-x.
11901 -  for (i = 2; i <= target->label - source->label; ++i)
11902 -    find_paths_rec (source->label, 0, i, target->label, ardeps, cur_path,
11903 -                   &paths_list);
11904 -
11905 +  for (i = 2; i <= ((candl_statement_usr_p)target->usr)->label - 
11906 +                   ((candl_statement_usr_p)source->usr)->label; ++i)
11907 +    find_paths_rec(((candl_statement_usr_p)source->usr)->label, 0, i, 
11908 +                   ((candl_statement_usr_p)target->usr)->label, ardeps,
11909 +                   cur_path, &paths_list);
11910 +  free(cur_path);
11911    return paths_list;
11912  }
11913  
11914 -/**
11915 - * Return true if the 'size' first elements of 'l1' and 'l2' are equal.
11916 - */
11917 -static
11918 -int piplist_are_equal (PipList* l1, PipList* l2, int size)
11919 -{
11920 -  if (l1 == NULL && l2 == NULL)
11921 -      return 1;
11922 -  if (l1 == NULL || l2 == NULL)
11923 -      return 0;
11924 -  if (l1->vector == NULL && l2->vector == NULL)
11925 -    return 1;
11926 -  if (l1->vector == NULL || l2->vector == NULL)
11927 -    return 0;
11928 -
11929 -  int count = 0;
11930 -  for (; l1 && l2 && count < size; l1 = l1->next, l2 = l2->next, ++count)
11931 -    {
11932 -      if (l1->vector == NULL && l2->vector == NULL)
11933 -       return 1;
11934 -      if (l1->vector == NULL || l2->vector == NULL)
11935 -       return 0;
11936 -      if (l1->vector->nb_elements != l2->vector->nb_elements)
11937 -       return 0;
11938 -      int j;
11939 -      for (j = 0; j < l1->vector->nb_elements; ++j)
11940 -       if (! CANDL_eq(l1->vector->the_vector[j],
11941 -                      l2->vector->the_vector[j]) ||
11942 -           ! CANDL_eq(l1->vector->the_deno[j],
11943 -                      l2->vector->the_deno[j]))
11944 -         return 0;
11945 -    }
11946 -
11947 -  return 1;
11948 -}
11949  
11950  /**
11951   * Return true if the 'size' first variables in a quast are strictly
11952   * equal.
11953   */
11954  static
11955 -int
11956 -quast_are_equal (PipQuast* q1, PipQuast* q2, int size)
11957 -{
11958 +int quast_are_equal (PipQuast* q1, PipQuast* q2, int size) {
11959    if (q1 == NULL && q2 == NULL)
11960      return 1;
11961    if (q1 == NULL || q2 == NULL)
11962      return 0;
11963  
11964    // Inspect conditions.
11965 -  if (q1->condition != NULL && q2->condition != NULL)
11966 -    {
11967 -      PipList c1; c1.next = NULL; c1.vector = q1->condition;
11968 -      PipList c2; c2.next = NULL; c2.vector = q2->condition;
11969 -      if (! piplist_are_equal(&c1, &c2, size))
11970 -       return 0;
11971 -      return quast_are_equal (q1->next_then, q2->next_then, size) &&
11972 -       quast_are_equal (q1->next_else, q2->next_else, size);
11973 -    }
11974 +  if (q1->condition != NULL && q2->condition != NULL) {
11975 +    PipList c1; c1.next = NULL; c1.vector = q1->condition;
11976 +    PipList c2; c2.next = NULL; c2.vector = q2->condition;
11977 +    if (! piplist_are_equal(&c1, &c2, size))
11978 +      return 0;
11979 +    return quast_are_equal(q1->next_then, q2->next_then, size) &&
11980 +        quast_are_equal(q1->next_else, q2->next_else, size);
11981 +  }
11982    if (q1->condition != NULL || q2->condition != NULL)
11983      return 0;
11984 -  return piplist_are_equal (q1->list, q2->list, size);
11985 +  return piplist_are_equal(q1->list, q2->list, size);
11986  }
11987  
11988  /**
11989 @@ -256,9 +190,7 @@ quast_are_equal (PipQuast* q1, PipQuast* q2, int size)
11990   * corresponding to loop iterators).
11991   */
11992  static
11993 -int
11994 -is_covering (CandlDependence* dep, CandlDependence**  path)
11995 -{
11996 +int is_covering(osl_dependence_p dep, osl_dependence_p* path) {
11997    int i, path_length;
11998  
11999    for (path_length = 0; path[path_length]; ++path_length)
12000 @@ -267,170 +199,154 @@ is_covering (CandlDependence* dep, CandlDependence**  path)
12001    /// FIXME: This may be overly conservative.
12002    // Check the path extremal points type.
12003    if (dep->type == CANDL_RAW || dep->type == CANDL_RAW_SCALPRIV
12004 -      || dep->type == CANDL_WAW)
12005 -    {
12006 -      // RAW or WAW.
12007 -      if (path[0]->type != CANDL_RAW && path[0]->type != CANDL_RAW_SCALPRIV &&
12008 -         path[0]->type != CANDL_WAW)
12009 -       return 0;
12010 -      if (dep->type == CANDL_RAW || dep->type == CANDL_RAW_SCALPRIV)
12011 -       if (path[path_length - 1]->type != CANDL_RAW &&
12012 -           path[path_length - 1]->type != CANDL_RAW_SCALPRIV &&
12013 -           path[path_length - 1]->type != CANDL_RAR)
12014 -         return 0;
12015 -      if (dep->type == CANDL_WAW)
12016 -       if (path[path_length - 1]->type != CANDL_WAR &&
12017 -           path[path_length - 1]->type != CANDL_WAW)
12018 -         return 0;
12019 -    }
12020 -  else
12021 -    {
12022 -      // WAR or RAR.
12023 -      if (path[0]->type != CANDL_WAR && path[0]->type != CANDL_RAR)
12024 -       return 0;
12025 -      if (dep->type == CANDL_WAR)
12026 -       if (path[path_length - 1]->type != CANDL_WAW &&
12027 -           path[path_length - 1]->type != CANDL_WAR)
12028 -         return 0;
12029 -      if (dep->type == CANDL_RAR)
12030 -       if (path[path_length - 1]->type != CANDL_RAR &&
12031 -           path[path_length - 1]->type != CANDL_RAW_SCALPRIV &&
12032 -           path[path_length - 1]->type != CANDL_RAW)
12033 -         return 0;
12034 -    }
12035 +      || dep->type == CANDL_WAW) {
12036 +    // RAW or WAW.
12037 +    if (path[0]->type != CANDL_RAW && path[0]->type != CANDL_RAW_SCALPRIV &&
12038 +        path[0]->type != CANDL_WAW)
12039 +      return 0;
12040 +    if (dep->type == CANDL_RAW || dep->type == CANDL_RAW_SCALPRIV)
12041 +      if (path[path_length - 1]->type != CANDL_RAW &&
12042 +          path[path_length - 1]->type != CANDL_RAW_SCALPRIV &&
12043 +          path[path_length - 1]->type != CANDL_RAR)
12044 +        return 0;
12045 +    if (dep->type == CANDL_WAW)
12046 +      if (path[path_length - 1]->type != CANDL_WAR &&
12047 +          path[path_length - 1]->type != CANDL_WAW)
12048 +        return 0;
12049 +  }
12050 +  else {
12051 +    // WAR or RAR.
12052 +    if (path[0]->type != CANDL_WAR && path[0]->type != CANDL_RAR)
12053 +      return 0;
12054 +    if (dep->type == CANDL_WAR)
12055 +      if (path[path_length - 1]->type != CANDL_WAW &&
12056 +          path[path_length - 1]->type != CANDL_WAR)
12057 +        return 0;
12058 +    if (dep->type == CANDL_RAR)
12059 +      if (path[path_length - 1]->type != CANDL_RAR &&
12060 +          path[path_length - 1]->type != CANDL_RAW_SCALPRIV &&
12061 +          path[path_length - 1]->type != CANDL_RAW)
12062 +        return 0;
12063 +  }
12064  
12065    // a- Fast check. Ensure the dependence depth is consistent across
12066    // the path. We may correctly cover _more_ points and still have a
12067    // perfect transitive cover.
12068    /// FIXME: ambiguous test?
12069 -/*   for (i = 0; i < path_length; ++i) */
12070 -/*     if (path[i]->depth > dep->depth) */
12071 -/*       return 0; */
12072 +  /*   for (i = 0; i < path_length; ++i) */
12073 +  /*     if (path[i]->depth > dep->depth) */
12074 +  /*       return 0; */
12075  
12076    // b- Check the covering property. Works only if
12077    // the iterator part of iteration domains and access functions are
12078    // unimodular matrices.
12079    // Build a large system with all dependences.
12080 -  int nb_par = path[0]->source->domain->NbColumns - path[0]->source->depth - 2;
12081 +  int nb_par = path[0]->domain->nb_parameters;
12082    int nb_iters = 0;
12083    int nb_rows = 0;
12084 -  for (i = 0; i < path_length; ++i)
12085 -    {
12086 -      nb_iters += path[i]->domain->NbColumns - nb_par - 2;
12087 -      nb_rows += path[i]->domain->NbRows;
12088 -      if (i > 0)
12089 -       nb_iters -= path[i]->source->depth;
12090 -    }
12091 -  CandlMatrix* syst = candl_matrix_malloc (nb_rows, nb_iters + nb_par + 2);
12092 +  for (i = 0; i < path_length; ++i) {
12093 +    nb_iters += path[i]->source_nb_output_dims_domain +
12094 +                path[i]->target_nb_output_dims_domain;
12095 +    nb_rows += path[i]->domain->nb_rows;
12096 +    if (i > 0)
12097 +      nb_iters -= ((candl_statement_usr_p) path[i]->source->usr)->depth;
12098 +  }
12099 +  
12100 +  CandlMatrix* syst = candl_matrix_malloc(nb_rows, nb_iters + nb_par + 2);
12101    int pos = 0;
12102    int j, k;
12103    int iter_off = 0;
12104 -  for (k = 0; k < path_length; ++k)
12105 -    {
12106 -      for (i = 0; i < path[k]->domain->NbRows; ++i)
12107 -       {
12108 -         CANDL_assign(syst->p[pos][0], path[k]->domain->p[i][0]);
12109 -         for (j = 1; j < path[k]->domain->NbColumns - 1 - nb_par; ++j)
12110 -           CANDL_assign(syst->p[pos][j + iter_off], path[k]->domain->p[i][j]);
12111 -         for (; j < path[k]->domain->NbColumns; ++j)
12112 -           {
12113 -             int parpos = j - (path[k]->domain->NbColumns - 1 - nb_par) +
12114 -               syst->NbColumns - nb_par - 1;
12115 -             CANDL_assign(syst->p[pos][parpos], path[k]->domain->p[i][j]);
12116 -           }
12117 -         ++pos;
12118 -       }
12119 -      iter_off += path[k]->source->depth;
12120 +  for (k = 0; k < path_length; ++k) {
12121 +    for (i = 0; i < path[k]->domain->NbRows; ++i) {
12122 +      CANDL_assign(syst->p[pos][0], path[k]->domain->p[i][0]);
12123 +      for (j = 1; j < path[k]->domain->NbColumns - 1 - nb_par; ++j)
12124 +        CANDL_assign(syst->p[pos][j + iter_off], path[k]->domain->p[i][j]);
12125 +      for (; j < path[k]->domain->NbColumns; ++j) {
12126 +        int parpos = j - (path[k]->domain->NbColumns - 1 - nb_par) +
12127 +            syst->NbColumns - nb_par - 1;
12128 +        CANDL_assign(syst->p[pos][parpos], path[k]->domain->p[i][j]);
12129 +      }
12130 +      ++pos;
12131      }
12132 +    iter_off += path[k]->source->depth;
12133 +  }
12134  
12135    // Algo:
12136    // lexmin(dep, R) == lexmin(path, R) && lexmax(dep, R) == lexmax(path, R) &&
12137    // lexmin(dep, S) == lexmin(path, S) && lexmax(dep, S) == lexmax(path, S)
12138    PipOptions* options;
12139 -  options = pip_options_init ();
12140 +  options = pip_options_init();
12141    options->Simplify = 1;
12142    options->Urs_parms = -1;
12143    options->Urs_unknowns = -1;
12144 -  CandlMatrix* context = candl_matrix_malloc (0, nb_par + 2);
12145 -  PipQuast* qpath = pip_solve (syst, context, -1, options);
12146 -  PipQuast* qdep = pip_solve (dep->domain, context, -1, options);
12147 -  int are_equal = quast_are_equal (qpath, qdep, dep->source->depth);
12148 -  if (are_equal)
12149 -    {
12150 -      pip_quast_free (qpath);
12151 -      pip_quast_free (qdep);
12152 -      options->Maximize = 1;
12153 -      qpath = pip_solve (syst, context, -1, options);
12154 -      qdep = pip_solve (dep->domain, context, -1, options);
12155 -      are_equal = quast_are_equal (qpath, qdep, dep->source->depth);
12156 +  CandlMatrix* context = candl_matrix_malloc(0, nb_par + 2);
12157 +  PipQuast* qpath = pip_solve(syst, context, -1, options);
12158 +  PipQuast* qdep = pip_solve(dep->domain, context, -1, options);
12159 +  int are_equal = quast_are_equal(qpath, qdep, dep->source->depth);
12160 +  if (are_equal) {
12161 +    pip_quast_free (qpath);
12162 +    pip_quast_free (qdep);
12163 +    options->Maximize = 1;
12164 +    qpath = pip_solve(syst, context, -1, options);
12165 +    qdep = pip_solve(dep->domain, context, -1, options);
12166 +    are_equal = quast_are_equal(qpath, qdep, dep->source->depth);
12167 +  }
12168 +  if (are_equal) {
12169 +    pip_quast_free(qpath);
12170 +    pip_quast_free(qdep);
12171 +    options->Maximize = 0;
12172 +    // Permute columns for first and last iterators.
12173 +    for (i = 0; i < dep->target->depth; ++i) {
12174 +      for (j = 0; j < syst->NbRows; ++j) {
12175 +        int tmp = CANDL_get_si(syst->p[j][1]);
12176 +        int pos = syst->NbColumns - 1 - nb_par - dep->target->depth + i;
12177 +        CANDL_assign(syst->p[j][1], syst->p[j][pos]);
12178 +        CANDL_set_si(syst->p[j][pos], tmp);
12179 +      }
12180      }
12181 -  if (are_equal)
12182 -    {
12183 -      pip_quast_free (qpath);
12184 -      pip_quast_free (qdep);
12185 -      options->Maximize = 0;
12186 -      // Permute columns for first and last iterators.
12187 -      for (i = 0; i < dep->target->depth; ++i)
12188 -       {
12189 -         for (j = 0; j < syst->NbRows; ++j)
12190 -           {
12191 -             int tmp = CANDL_get_si(syst->p[j][1]);
12192 -             int pos = syst->NbColumns - 1 - nb_par - dep->target->depth + i;
12193 -             CANDL_assign(syst->p[j][1], syst->p[j][pos]);
12194 -             CANDL_set_si(syst->p[j][pos], tmp);
12195 -           }
12196 -       }
12197 -      qpath = pip_solve (syst, context, -1, options);
12198 -      qdep = pip_solve (dep->domain, context, -1, options);
12199 -      are_equal = quast_are_equal (qpath, qdep, dep->target->depth);
12200 -    }
12201 -  if (are_equal)
12202 -    {
12203 -      pip_quast_free (qpath);
12204 -      pip_quast_free (qdep);
12205 -      options->Maximize = 1;
12206 -      qpath = pip_solve (syst, context, -1, options);
12207 -      qdep = pip_solve (dep->domain, context, -1, options);
12208 -      are_equal = quast_are_equal (qpath, qdep, dep->target->depth);
12209 -    }
12210 -
12211 -  pip_options_free (options);
12212 -  pip_quast_free (qpath);
12213 -  pip_quast_free (qdep);
12214 -  pip_matrix_free (syst);
12215 +    qpath = pip_solve(syst, context, -1, options);
12216 +    qdep = pip_solve(dep->domain, context, -1, options);
12217 +    are_equal = quast_are_equal(qpath, qdep, dep->target->depth);
12218 +  }
12219 +  if (are_equal) {
12220 +    pip_quast_free(qpath);
12221 +    pip_quast_free(qdep);
12222 +    options->Maximize = 1;
12223 +    qpath = pip_solve(syst, context, -1, options);
12224 +    qdep = pip_solve(dep->domain, context, -1, options);
12225 +    are_equal = quast_are_equal(qpath, qdep, dep->target->depth);
12226 +  }
12227 +
12228 +  pip_options_free(options);
12229 +  pip_quast_free(qpath);
12230 +  pip_quast_free(qdep);
12231 +  pip_matrix_free(syst);
12232  
12233    return are_equal;
12234  }
12235  
12236  static
12237 -int
12238 -is_iter_unimodular (CandlDependence* dep)
12239 -{
12240 +int is_iter_unimodular(osl_dependence_p dep) {
12241    // Check unimodular on the iterator part.
12242    int i, j;
12243 -  for (i = 0; i < dep->domain->NbRows; ++i)
12244 -    {
12245 -      if (i < dep->source->domain->NbRows ||
12246 -         i > dep->source->domain->NbRows + dep->target->domain->NbRows)
12247 -       {
12248 -         for (j = 1; j <= dep->source->depth; ++j)
12249 -           {
12250 -             int val = CANDL_get_si(dep->domain->p[i][j]);
12251 -             if (val < -1 || val > 1)
12252 -               return 0;
12253 -           }
12254 -       }
12255 -      else if (i < dep->source->domain->NbRows +
12256 -              dep->target->domain->NbRows  ||
12257 -              i > dep->source->domain->NbRows + dep->target->domain->NbRows)
12258 -       {
12259 -         for (j = 1; j <= dep->source->depth; ++j)
12260 -           {
12261 -             int val = CANDL_get_si(dep->domain->p[i][j + dep->source->depth]);
12262 -             if (val < -1 || val > 1)
12263 -               return 0;
12264 -           }
12265 -       }
12266 +  int n;
12267 +  int precision = dep->domain->precision;
12268 +  osl_relation_p matrix;
12269 +  
12270 +  matrix = dep->source->domain;
12271 +  for (i = 0 ; i < matrix->nb_rows ; i++)
12272 +    for (j = 1 ; j <= matrix->nb_output_dims ; j++) {
12273 +      n = osl_int_get_si(precision, matrix->m[i][j]);
12274 +      if (n < -1 || n > 1)
12275 +        return 0;
12276 +    }
12277 +  
12278 +  matrix = dep->target->domain;
12279 +  for (i = 0 ; i < matrix->nb_rows ; i++)
12280 +    for (j = 1 ; j <= matrix->nb_output_dims ; j++) {
12281 +      n = osl_int_get_si(precision, matrix->m[i][j]);
12282 +      if (n < -1 || n > 1)
12283 +        return 0;
12284      }
12285  
12286    return 1;
12287 @@ -441,157 +357,169 @@ is_iter_unimodular (CandlDependence* dep)
12288   * In-place modification of the list of dependence polyhedra.
12289   *
12290   */
12291 -CandlDependence*
12292 -candl_dependence_prune_transitively_covered (CandlDependence* deps)
12293 -{
12294 -  CandlDependence* tmp;
12295 +osl_dependence_p osl_dependence_prune_transitively_covered(
12296 +                                      osl_dependence_p deps) {
12297 +  if (deps == NULL)
12298 +    return NULL;
12299 +  
12300 +  osl_dependence_p tmp;
12301 +  osl_dependence_p *ardeps;
12302 +  osl_relation_p srcmat;
12303 +  osl_relation_p *allarrays;
12304 +  osl_dependence_p** path;
12305 +  osl_dependence_p *curardeps;
12306 +  candl_statement_usr_p s_usr, t_usr;
12307 +  int precision = deps->domain->precision;
12308 +  int nb_deps;
12309  
12310    // 1- Collect all arrays that occur in dependences.
12311    int cnt, i, j, k, l;
12312    int nb_stmts = 0;
12313 -  for (tmp = deps, cnt = 0; tmp; tmp = tmp->next)
12314 -    {
12315 -      nb_stmts = tmp->source->label > nb_stmts ? tmp->source->label : nb_stmts;
12316 -      nb_stmts = tmp->target->label > nb_stmts ? tmp->target->label : nb_stmts;
12317 -      ++cnt;
12318 -    }
12319 +  for (tmp = deps, cnt = 0; tmp; tmp = tmp->next) {
12320 +    s_usr = tmp->source->usr;
12321 +    t_usr = tmp->target->usr;
12322 +    nb_stmts = s_usr->label > nb_stmts ? s_usr->label : nb_stmts;
12323 +    nb_stmts = t_usr->label > nb_stmts ? t_usr->label : nb_stmts;
12324 +    ++cnt;
12325 +  }
12326    ++nb_stmts;
12327 -  int nb_deps = cnt;
12328 -  int allarrays[cnt];
12329 -  for (tmp = deps, cnt = 0; tmp; tmp = tmp->next)
12330 -    {
12331 -      CandlMatrix* srcmat;
12332 -      if (tmp->type == CANDL_RAW || tmp->type == CANDL_RAW_SCALPRIV
12333 -         || tmp->type == CANDL_WAW)
12334 -       srcmat = tmp->source->written;
12335 -      else
12336 -       srcmat = tmp->source->read;
12337 -      for (i = 0; i < cnt; ++i)
12338 -       if (allarrays[i] == CANDL_get_si(srcmat->p[tmp->ref_source][0]))
12339 -         break;
12340 -      if (i == cnt)
12341 -       allarrays[cnt++] = CANDL_get_si(srcmat->p[tmp->ref_source][0]);
12342 -    }
12343 -  allarrays[cnt] = -1;
12344 +  nb_deps = cnt;
12345 +  allarrays = (osl_relation_p*)malloc(sizeof(osl_relation_p)*cnt);
12346 +  
12347 +  for (tmp = deps, cnt = 0; tmp; tmp = tmp->next) {
12348 +    srcmat = candl_dependence_get_relation_ref_source_in_dep(tmp);
12349 +    for (i = 0; i < cnt; ++i)
12350 +      if (allarrays[i] == srcmat)
12351 +        break;
12352 +    if (i == cnt)
12353 +      allarrays[cnt++] = srcmat;
12354 +  }
12355 +  allarrays[cnt] = NULL;
12356  
12357    // 2- Iterate on all arrays.
12358 -  for (i = 0; allarrays[i] != -1; ++i)
12359 -    {
12360 -      // a- Collect all dependences to this array.
12361 -      CandlDependence* ardeps[nb_deps + 1];
12362 -      for (tmp = deps, cnt = 0; tmp; tmp = tmp->next)
12363 -       {
12364 -         CandlMatrix* srcmat;
12365 -         if (tmp->type == CANDL_RAW || tmp->type == CANDL_RAW_SCALPRIV
12366 -             || tmp->type == CANDL_WAW)
12367 -           srcmat = tmp->source->written;
12368 -         else
12369 -           srcmat = tmp->source->read;
12370 -         if (allarrays[i] == CANDL_get_si(srcmat->p[tmp->ref_source][0]))
12371 -           ardeps[cnt++] = tmp;
12372 -       }
12373 -      ardeps[cnt] = NULL;
12374 -
12375 -      // b- First pruning. Remove all dependence polyhedra that are equal.
12376 -      for (j = 0; ardeps[j]; ++j)
12377 -       {
12378 -         for (k = j + 1; ardeps[k]; ++k)
12379 -           if (ardeps[j]->source == ardeps[k]->source &&
12380 -               ardeps[j]->target == ardeps[k]->target &&
12381 -               ardeps[j]->depth == ardeps[k]->depth &&
12382 -               candl_matrix_equal (ardeps[j]->domain, ardeps[k]->domain))
12383 -             {
12384 -               ardeps[k - 1]->next = ardeps[k+1];
12385 -               for (l = k; ardeps[l + 1]; ++l)
12386 -                 ardeps[l] = ardeps[l + 1];
12387 -               ardeps[l] = NULL;
12388 -               --k;
12389 -             }
12390 -       }
12391 -
12392 -      // c- Local pruning. Remove all self-dependences (1-cycles)
12393 -      // and all backward-dependences.
12394 -      for (j = 0; ardeps[j]; ++j)
12395 -       if (ardeps[j]->source >= ardeps[j]->target)
12396 -         {
12397 -           for (k = j; ardeps[k + 1]; ++k)
12398 -             ardeps[k] = ardeps[k + 1];
12399 -           ardeps[k] = NULL;
12400 -           --j;
12401 -         }
12402 -
12403 -      // d- Local pruning. Remove all dependences where source/target
12404 -      // are not unimodular in the iterator part of the access function and
12405 -      // iteration domain.
12406 -      for (j = 0; ardeps[j]; ++j)
12407 -       if (! is_iter_unimodular (ardeps[j]))
12408 -         {
12409 -           for (k = j; ardeps[k + 1]; ++k)
12410 -             ardeps[k] = ardeps[k + 1];
12411 -           ardeps[k] = NULL;
12412 -           --j;
12413 -         }
12414 -
12415 -      // d- Given a pair of statements, check if there is a dependence
12416 -      // path from its source to its target, of same type of a found
12417 -      // direct dependence.
12418 -      int stmts, stmtt;
12419 -      for (stmts = 0; stmts < nb_stmts - 2; ++stmts)
12420 -       for (stmtt = stmts + 2; stmtt < nb_stmts; ++stmtt)
12421 -         {
12422 -           // Ensure there exists a direct dependence between stmts
12423 -           // and stmtt.
12424 -           //printf ("consider S%d -> S%d\n", stmts, stmtt);
12425 -           for (j = 0; ardeps[j]; ++j)
12426 -             if (ardeps[j]->source->label == stmts &&
12427 -                 ardeps[j]->target->label == stmtt)
12428 -               break;
12429 -           if (ardeps[j])
12430 -               {
12431 -                 CandlStatement* source = ardeps[j]->source;
12432 -                 CandlStatement* target = ardeps[j]->target;
12433 -
12434 -                 // Subset of deps that can be on the path.
12435 -                 CandlDependence* curardeps[nb_deps + 1];
12436 -                 for (k = 0, l = 0; ardeps[k]; ++k)
12437 -                   if (ardeps[k]->source->label >= source->label &&
12438 -                       ardeps[k]->source->label <= target->label &&
12439 -                       ardeps[k]->target->label >= source->label &&
12440 -                       ardeps[k]->target->label <= target->label)
12441 -                     curardeps[l++] = ardeps[k];
12442 -                 curardeps[l] = NULL;
12443 -                 CandlDependence*** paths =
12444 -                   find_dep_paths(curardeps, source, target);
12445 -
12446 -                 if (paths)
12447 -                   {
12448 -                     for (j = 0; ardeps[j]; ++j)
12449 -                       if (ardeps[j]->source->label == stmts &&
12450 -                           ardeps[j]->target->label == stmtt)
12451 -                         {
12452 -                           // Inspect all paths. If there is a path
12453 -                           // that respect the transitive cover prop,
12454 -                           // then discard the dependence.
12455 -                           for (k = 0; paths[k] &&
12456 -                                  ! is_covering (ardeps[j], paths[k]); ++k)
12457 -                             ;
12458 -                           if (paths[k])
12459 -                             {
12460 -                               candl_matrix_free (ardeps[j]->domain);
12461 -                               free (ardeps[j]);
12462 -                               if (j == 0)
12463 -                                 deps = ardeps[j + 1];
12464 -                               else
12465 -                                 ardeps[j - 1]->next = ardeps[j + 1];
12466 -                             }
12467 -                         }
12468 -                     for (k = 0; paths[k]; ++k)
12469 -                       free (paths[k]);
12470 -                     free (paths);
12471 -                   }
12472 -               }
12473 -         }
12474 +  for (i = 0 ; allarrays[i] != NULL ; ++i) {
12475 +    ardeps = (osl_dependence_p*) malloc(sizeof(osl_dependence_p) *
12476 +                                          (nb_deps + 1));
12477 +    
12478 +    // a- Collect all dependences to this array.
12479 +    for (tmp = deps, cnt = 0; tmp; tmp = tmp->next) {
12480 +      srcmat = candl_dependence_get_relation_ref_source_in_dep(tmp);
12481 +      if (allarrays[i] == srcmat)
12482 +        ardeps[cnt++] = tmp;
12483 +    }
12484 +    ardeps[cnt] = NULL;
12485 +
12486 +    // b- First pruning. Remove all dependence polyhedra that are equal.
12487 +    for (j = 0; ardeps[j]; ++j)
12488 +      for (k = j + 1; ardeps[k]; ++k)
12489 +        if (ardeps[j]->source == ardeps[k]->source &&
12490 +            ardeps[j]->target == ardeps[k]->target &&
12491 +            ardeps[j]->depth == ardeps[k]->depth &&
12492 +            osl_relation_equal(ardeps[j]->domain, ardeps[k]->domain)) {
12493 +          ardeps[k - 1]->next = ardeps[k+1];
12494 +          for (l = k; ardeps[l + 1]; ++l)
12495 +            ardeps[l] = ardeps[l + 1];
12496 +          ardeps[l] = NULL;
12497 +          --k;
12498 +        }
12499 +
12500 +    // c- Local pruning. Remove all self-dependences (1-cycles)
12501 +    // and all backward-dependences.
12502 +    for (j = 0; ardeps[j]; ++j) {
12503 +      s_usr = ardeps[j]->source->usr;
12504 +      t_usr = ardeps[j]->target->usr;
12505 +      if (s_usr->label >= t_usr->label) {
12506 +        for (k = j; ardeps[k + 1]; ++k)
12507 +          ardeps[k] = ardeps[k + 1];
12508 +        ardeps[k] = NULL;
12509 +        --j;
12510 +      }
12511      }
12512  
12513 +    // d- Local pruning. Remove all dependences where source/target
12514 +    // are not unimodular in the iterator part of the access function and
12515 +    // iteration domain.
12516 +    for (j = 0; ardeps[j]; ++j)
12517 +      if (! is_iter_unimodular(ardeps[j])) {
12518 +        for (k = j; ardeps[k + 1]; ++k)
12519 +          ardeps[k] = ardeps[k + 1];
12520 +        ardeps[k] = NULL;
12521 +        --j;
12522 +      }
12523 +
12524 +    // d- Given a pair of statements, check if there is a dependence
12525 +    // path from its source to its target, of same type of a found
12526 +    // direct dependence.
12527 +    int source_label, target_label;
12528 +    for (source_label = 0; source_label < nb_stmts - 2; ++source_label)
12529 +      for (target_label = source_label + 2; target_label < nb_stmts;
12530 +           ++target_label) {
12531 +        // Ensure there exists a direct dependence between source_label
12532 +        // and target_label.
12533 +        //printf ("consider S%d -> S%d\n", source_label, target_label);
12534 +        for (j = 0; ardeps[j]; ++j) {
12535 +          s_usr = ardeps[j]->source->usr;
12536 +          t_usr = ardeps[j]->target->usr;
12537 +          if (s_usr->label == source_label &&
12538 +              t_usr->label == target_label)
12539 +            break;
12540 +        }
12541 +        if (ardeps[j]) {
12542 +          osl_statement_p source = ardeps[j]->source;
12543 +          osl_statement_p target = ardeps[j]->target;
12544 +
12545 +          // Subset of deps that can be on the path.
12546 +          curardeps = (osl_dependence_p*) malloc(sizeof(osl_dependence_p) *
12547 +                                                   (nb_deps + 1));
12548 +          
12549 +          for (k = 0, l = 0; ardeps[k]; ++k) {
12550 +            s_usr = ardeps[k]->source->usr;
12551 +            t_usr = ardeps[k]->target->usr;
12552 +            if (s_usr->label >= source->label &&
12553 +                s_usr->label <= target->label &&
12554 +                t_usr->label >= source->label &&
12555 +                t_usr->label <= target->label)
12556 +              curardeps[l++] = ardeps[k];
12557 +          }
12558 +          curardeps[l] = NULL;
12559 +          paths = find_dep_paths(curardeps, source, target);
12560 +
12561 +          if (paths) {
12562 +            for (j = 0; ardeps[j]; ++j) {
12563 +              s_usr = ardeps[j]->source->usr;
12564 +              t_usr = ardeps[j]->target->usr;
12565 +              if (s_usr->label == source_label &&
12566 +                  t_usr->label == target_label) {
12567 +                // Inspect all paths. If there is a path
12568 +                // that respect the transitive cover prop,
12569 +                // then discard the dependence.
12570 +                for (k = 0; paths[k] && !is_covering(ardeps[j], paths[k]); ++k)
12571 +                  ;
12572 +                if (paths[k]) {
12573 +                  osl_relation_free(ardeps[j]->domain);
12574 +                  free(ardeps[j]);
12575 +                  if (j == 0)
12576 +                    deps = ardeps[j + 1];
12577 +                  else
12578 +                    ardeps[j - 1]->next = ardeps[j + 1];
12579 +                }
12580 +              }
12581 +            }
12582 +            for (k = 0; paths[k]; ++k)
12583 +              free(paths[k]);
12584 +            free(paths);
12585 +          }
12586 +          
12587 +          free(curardeps);
12588 +        }
12589 +      }
12590 +    
12591 +    free(ardeps);
12592 +  }
12593 +  
12594 +  free(allarrays);
12595 +
12596    return deps;
12597  }
12598 +
12599 +#endif
12600 diff --git a/source/scop.c b/source/scop.c
12601 new file mode 100644
12602 index 0000000..f6ec0ae
12603 --- /dev/null
12604 +++ b/source/scop.c
12605 @@ -0,0 +1,93 @@
12606 +
12607 +
12608 +   /**------ ( ----------------------------------------------------------**
12609 +    **       )\                      CAnDL                               **
12610 +    **----- /  ) --------------------------------------------------------**
12611 +    **     ( * (                   scop.c                                **
12612 +    **----  \#/  --------------------------------------------------------**
12613 +    **    .-"#'-.        First version: june 7th 2012                    **
12614 +    **--- |"-.-"| -------------------------------------------------------**
12615 +          |     |
12616 +          |     |
12617 + ******** |     | *************************************************************
12618 + * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
12619 + ******************************************************************************
12620 + *                                                                            *
12621 + * Copyright (C) 2003-2008 Cedric Bastoul                                     *
12622 + *                                                                            *
12623 + * This is free software; you can redistribute it and/or modify it under the  *
12624 + * terms of the GNU General Public License as published by the Free Software  *
12625 + * Foundation; either version 2 of the License, or (at your option) any later *
12626 + * version.                                                                   *
12627 + *                                                                            *
12628 + * This software is distributed in the hope that it will be useful, but       *
12629 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
12630 + * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   *
12631 + * for more details.                                                          *
12632 + *                                                                            *
12633 + * You should have received a copy of the GNU General Public License along    *
12634 + * with software; if not, write to the Free Software Foundation, Inc.,        *
12635 + * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA                     *
12636 + *                                                                            *
12637 + * CAnDL, the Chunky Dependence Analyzer                                      *
12638 + * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr                         *
12639 + *                                                                            *
12640 + ******************************************************************************/
12641 +
12642 +/*
12643 + * author Joel Poudroux 
12644 + */
12645 +
12646 +#include <stdlib.h>
12647 +#include <osl/scop.h>
12648 +#include <osl/statement.h>
12649 +#include <candl/scop.h>
12650 +#include <candl/statement.h>
12651 +
12652 +/**
12653 + * candl_scop_usr_init function:
12654 + * initialize a candl_scop_usr structure
12655 + *
12656 + * May, 2013 extended to each scop in the list,
12657 + */
12658 +void candl_scop_usr_init(osl_scop_p scop) {
12659 +
12660 +  while (scop) {
12661 +    candl_scop_usr_p scop_usr;
12662 +    
12663 +    /* Init the scop_usr structure */
12664 +    scop_usr = (candl_scop_usr_p) malloc(sizeof(candl_scop_usr_t));
12665 +    scop_usr->scalars_privatizable = NULL;
12666 +    scop_usr->usr_backup           = scop->usr;
12667 +    scop->usr = scop_usr;
12668 +    
12669 +    candl_statement_usr_init_all(scop);
12670 +
12671 +    scop = scop->next;
12672 +  }
12673 +}
12674 +
12675 +
12676 +/**
12677 + * candl_scop_usr_cleanup function:
12678 + */
12679 +void candl_scop_usr_cleanup(osl_scop_p scop) {
12680 +
12681 +  while (scop) {
12682 +    osl_statement_p statement = scop->statement;
12683 +    candl_scop_usr_p scop_usr;
12684 +    while (statement != NULL) {
12685 +      candl_statement_usr_cleanup(statement);
12686 +      statement = statement->next;
12687 +    }
12688 +    scop_usr = scop->usr;
12689 +    if (scop_usr) {
12690 +      if (scop_usr->scalars_privatizable)
12691 +        free(scop_usr->scalars_privatizable);
12692 +      scop->usr = scop_usr->usr_backup;
12693 +      free(scop_usr);
12694 +    }
12695 +   
12696 +    scop = scop->next;
12697 +  }
12698 +}
12699 diff --git a/source/statement.c b/source/statement.c
12700 index 39ee0b8..d6845dd 100644
12701 --- a/source/statement.c
12702 +++ b/source/statement.c
12703 @@ -1,18 +1,19 @@
12704  
12705 +
12706     /**------ ( ----------------------------------------------------------**
12707      **       )\                      CAnDL                               **
12708      **----- /  ) --------------------------------------------------------**
12709 -    **     ( * (                  statement.c                            **
12710 +    **     ( * (                   usr.c                                 **
12711      **----  \#/  --------------------------------------------------------**
12712 -    **    .-"#'-.        First version: september 9th 2003               **
12713 +    **    .-"#'-.        First version: june 7th 2012                    **
12714      **--- |"-.-"| -------------------------------------------------------**
12715 -          |     | 
12716 -          |     | 
12717 +          |     |
12718 +          |     |
12719   ******** |     | *************************************************************
12720   * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
12721   ******************************************************************************
12722   *                                                                            *
12723 - * Copyright (C) 2003 Cedric Bastoul                                          *
12724 + * Copyright (C) 2003-2008 Cedric Bastoul                                     *
12725   *                                                                            *
12726   * This is free software; you can redistribute it and/or modify it under the  *
12727   * terms of the GNU General Public License as published by the Free Software  *
12728 @@ -32,319 +33,103 @@
12729   * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr                         *
12730   *                                                                            *
12731   ******************************************************************************/
12732 -/* CAUTION: the english used for comments is probably the worst you ever read,
12733 - *          please feel free to correct and improve it !
12734 - */
12735 -
12736 -# include <stdlib.h>
12737 -# include <stdio.h>
12738 -# include <ctype.h>
12739 -# include <string.h>
12740 -# include "../include/candl/candl.h"
12741  
12742 -
12743 -/******************************************************************************
12744 - *                          Structure display function                        *
12745 - ******************************************************************************/
12746 -
12747 -
12748 -/**
12749 - * candl_statement_print_structure function:
12750 - * Displays a CandlStatement structure (statement) into a file (file,
12751 - * possibly stdout) in a way that trends to be understandable without falling
12752 - * in a deep depression or, for the lucky ones, getting a headache... It
12753 - * includes an indentation level (level) in order to work with others
12754 - * print_structure functions.
12755 - * - 18/09/2003: first version.
12756 +/*
12757 + * author Joel Poudroux and Cedric Bastoul
12758   */
12759 -void candl_statement_print_structure(file, statement, level)
12760 -FILE * file ;
12761 -CandlStatement * statement ;
12762 -int level ;
12763 -{ int i, j ;
12764 -
12765 -  if (statement != NULL)
12766 -  { /* Go to the right level. */
12767 -    for(j=0; j<level; j++)
12768 -    fprintf(file,"|\t") ;
12769 -    fprintf(file,"+-- CandlStatement\n") ;
12770 -    
12771 -    /* A blank line. */
12772 -    for(j=0; j<=level+1; j++)
12773 -    fprintf(file,"|\t") ;
12774 -    fprintf(file,"\n") ;
12775 -
12776 -    /* Go to the right level and print the label. */
12777 -    for(j=0; j<=level; j++)
12778 -    fprintf(file,"|\t") ;
12779 -    fprintf(file,"Label: %d\n",statement->label) ;
12780 -  
12781 -    /* A blank line. */
12782 -    for(j=0; j<=level+1; j++)
12783 -    fprintf(file,"|\t") ;
12784 -    fprintf(file,"\n") ;
12785 -
12786 -    /* Go to the right level and print the type. */
12787 -    for(j=0; j<=level; j++)
12788 -    fprintf(file,"|\t") ;
12789 -    fprintf(file,"Type: ") ;
12790 -    switch (statement->type)
12791 -    { case CANDL_UNSET        : fprintf(file,"UNSET\n") ;           break ;
12792 -      case CANDL_ASSIGNMENT   : fprintf(file,"assignment\n") ;     break ;
12793 -      case CANDL_P_REDUCTION  : fprintf(file,"plus-reduction\n") ;  break ;
12794 -      case CANDL_M_REDUCTION  : fprintf(file,"minus-reduction\n") ; break ;
12795 -      case CANDL_T_REDUCTION  : fprintf(file,"times-reduction\n") ; break ;
12796 -      default : fprintf(file,"unknown\n") ;
12797 -    }
12798 -    
12799 -    /* A blank line. */
12800 -    for(j=0; j<=level+1; j++)
12801 -    fprintf(file,"|\t") ;
12802 -    fprintf(file,"\n") ;
12803 -
12804 -    /* Go to the right level and print the outer loops. */
12805 -    for(j=0; j<=level; j++)
12806 -    fprintf(file,"|\t") ;
12807 -    fprintf(file,"Depth: %d, outer loops(s):",statement->depth) ;
12808 -    for (i=0;i<statement->depth;i++)
12809 -    fprintf(file," %d",statement->index[i]) ;
12810 -    fprintf(file,"\n") ;
12811 -    
12812 -    /* A blank line. */
12813 -    for(j=0; j<=level+1; j++)
12814 -    fprintf(file,"|\t") ;
12815 -    fprintf(file,"\n") ;
12816 -
12817 -    /* Print the iteration domain. */
12818 -    candl_matrix_print_structure(file,statement->domain,level+1) ;
12819 -    
12820 -    /* Print the written data. */
12821 -    candl_matrix_print_structure(file,statement->written,level+1) ;
12822 -    
12823 -    /* Print the read data. */
12824 -    candl_matrix_print_structure(file,statement->read,level+1) ;
12825 -  }
12826 -  else
12827 -  { /* Go to the right level. */
12828 -    for(j=0; j<level; j++)
12829 -    fprintf(file,"|\t") ;
12830 -    fprintf(file,"+-- NULL statement\n") ;
12831 -  }
12832 -   
12833 -  /* The last line. */
12834 -  for(j=0; j<=level; j++)
12835 -  fprintf(file,"|\t") ;
12836 -  fprintf(file,"\n") ;
12837 -}
12838 -
12839 -
12840 -/** 
12841 - * candl_statement_print function:
12842 - * This function prints the content of a CandlStatement structure (statement)
12843 - * into a file (file, possibly stdout).
12844 - * - 09/09/2003: first version.
12845 - */
12846 -void candl_statement_print(FILE * file, CandlStatement * statement)
12847 -{ candl_statement_print_structure(file,statement,0) ;
12848 -}
12849 -
12850 -
12851 -/******************************************************************************
12852 - *                         Memory deallocation function                       *
12853 - ******************************************************************************/
12854 -
12855 -
12856 -/**
12857 - * candl_statement_free function:
12858 - * This function frees the allocated memory for a CandlStatement structure.
12859 - * - 09/09/2003: first version.
12860 - */
12861 -void candl_statement_free(CandlStatement * statement)
12862 -{ free(statement->index) ;
12863 -  pip_matrix_free(statement->domain) ;
12864 -  pip_matrix_free(statement->read) ;
12865 -  pip_matrix_free(statement->written) ;
12866 -  free(statement) ;
12867 -}
12868  
12869 +#include <stdlib.h>
12870 +#include <osl/scop.h>
12871 +#include <osl/statement.h>
12872 +#include <osl/extensions/dependence.h>
12873 +#include <osl/relation.h>
12874 +#include <candl/macros.h>
12875 +#include <candl/statement.h>
12876 +#include <candl/util.h>
12877  
12878 -/******************************************************************************
12879 - *                              Reading functions                             *
12880 - ******************************************************************************/
12881 +#define CANDL_STATEMENT_USR_INDEX_MAX_LOOP_DEPTH 128
12882  
12883  
12884  /**
12885 - * candl_statement_read function:
12886 - * This function reads statement data from a file (file) and puts them into
12887 - * a CandlStatement structure. This function returns a pointer to this
12888 - * structure.
12889 - * - label is the statement number ;
12890 - * - nb_parameters is the number of parameters.
12891 - ***
12892 - * - 09/09/2003: first version.
12893 + * candl_statement_usr_init_all function:
12894 + * Init each candl_statement_usr structure of statements
12895   */
12896 -CandlStatement * candl_statement_read(FILE * file, int label, int nb_parameters)
12897 -{ int i, n, * index ;
12898 -  char s[CANDL_MAX_STRING], str[CANDL_MAX_STRING], * c, type ;
12899 -  CandlStatement * statement ;
12900 -  
12901 -  /* Statement data. */
12902 -  statement = candl_statement_malloc() ;
12903 -
12904 -  /* We first read the statement type. */
12905 -  while (fgets(s,CANDL_MAX_STRING,file) == 0) ;
12906 -  while ((*s=='#' || *s=='\n') || (sscanf(s," %c",&type)<1))
12907 -  fgets(s,CANDL_MAX_STRING,file) ;
12908 +void candl_statement_usr_init_all(osl_scop_p scop) {
12909 +
12910 +  /* TODO
12911 +   * that statements must be sorted to compute the statement label
12912 +   * the problem is if the scop is reordered, the second transformed scop
12913 +   * must be aligned with it
12914 +  */
12915 +
12916 +  osl_statement_p iter;
12917 +  osl_relation_p scattering;
12918 +  candl_statement_usr_p stmt_usr;
12919 +  int i, j, k;
12920 +  int row;
12921 +  int precision = scop->context->precision;
12922 +  int count = 0; /* counter for statements */
12923    
12924 -  switch (type)
12925 -  { case 'A': statement->type = CANDL_ASSIGNMENT ; break ;
12926 -    case 'P': statement->type = CANDL_P_REDUCTION ; break ;
12927 -    case 'M': statement->type = CANDL_M_REDUCTION ; break ;
12928 -    case 'T': statement->type = CANDL_T_REDUCTION ; break ;
12929 -    default : fprintf(stderr, "[Candl]ERROR: unknown statement type %c\n",type);
12930 -              fprintf(stderr, "              possible types are:\n") ;
12931 -              fprintf(stderr, "              - A for assignment       (=),\n") ;
12932 -              fprintf(stderr, "              - P for plus-reduction  (+=),\n") ;
12933 -              fprintf(stderr, "              - M for minus-reduction (-=),\n") ;
12934 -              fprintf(stderr, "              - T for times-reduction (*=).\n") ;
12935 -              exit(1) ;
12936 +  /* Initialize structures used in iterator indices computation. */
12937 +  int val;
12938 +  int max = 0;
12939 +  int cur_index[CANDL_STATEMENT_USR_INDEX_MAX_LOOP_DEPTH];
12940 +  int last[CANDL_STATEMENT_USR_INDEX_MAX_LOOP_DEPTH];
12941 +  for (i = 0; i < CANDL_STATEMENT_USR_INDEX_MAX_LOOP_DEPTH; ++i) {
12942 +    cur_index[i] = i;
12943 +    last[i] = 0;
12944    }
12945 -
12946 -  statement->label = label ;
12947 -  statement->domain  = pip_matrix_read(file) ;
12948 -  statement->depth = statement->domain->NbColumns - nb_parameters - 2 ;
12949 -
12950 -  index = (int *)malloc(sizeof(int)*statement->depth) ;
12951 -  if (index == NULL) 
12952 -  { fprintf(stderr, "[Candl]ERROR: memory overflow.\n") ;
12953 -    exit(1) ;
12954 -  }
12955 -
12956 -  do  /* Skip the comments, spaces and empty lines... */
12957 -  { c = fgets(s,CANDL_MAX_STRING,file) ;
12958 -    while ((c != NULL) && isspace(*c) && (*c != '\n'))
12959 -    c++ ;
12960 -  }
12961 -  while (c != NULL && (*c == '#' || *c == '\n'));
12962 +  
12963 +  /* Add useful information in the usr field of each statements */
12964 +  for (iter = scop->statement ; iter != NULL ; iter = iter->next) {
12965 +    scattering = iter->scattering;
12966      
12967 -  if (c == NULL) 
12968 -  { fprintf(stderr, "[Candl]ERROR: no labels in input file.\n") ;
12969 -    exit(1) ;
12970 -  }
12971 -  for (i=0;i<statement->depth;i++) 
12972 -  { /* All iterator labels must be on the same line. */
12973 -    while (isspace(*c))
12974 -    c++ ;
12975 -    if (c == NULL || *c == '#' || *c == '\n')
12976 -    { fprintf(stderr, "[Candl]ERROR: not enough labels in input file.\n") ;
12977 -      exit(1) ;
12978 -    }
12979 -    /* n is strlen(str). */
12980 -    if (sscanf(c,"%s%n",str,&n) == 0) 
12981 -    { fprintf(stderr, "[Candl]ERROR: no labels in input file.\n") ;
12982 -      exit(1) ;
12983 +    stmt_usr = (candl_statement_usr_p) malloc(sizeof(candl_statement_usr_t));
12984 +    stmt_usr->depth      = scattering->nb_output_dims/2;
12985 +    stmt_usr->label      = count;
12986 +    stmt_usr->type       = OSL_DEPENDENCE_ASSIGNMENT;
12987 +    stmt_usr->usr_backup = iter->usr;
12988 +    stmt_usr->index      = (stmt_usr->depth ?
12989 +                            (int*) malloc(stmt_usr->depth * sizeof(int)) : 
12990 +                            NULL);
12991 +    
12992 +    /* Compute the value of the iterator indices.
12993 +     * extracted from the last candl
12994 +     */
12995 +    for (j = 0; j < stmt_usr->depth; ++j) {
12996 +      row = candl_util_relation_get_line(scattering, j*2);
12997 +      val = osl_int_get_si(precision,
12998 +                           scattering->m[row][scattering->nb_columns - 1]);
12999 +      if (last[j] < val) {
13000 +        last[j] = val;
13001 +        for (k = j + 1; k < CANDL_STATEMENT_USR_INDEX_MAX_LOOP_DEPTH; ++k)
13002 +          last[k] = 0;
13003 +        for (k = j; k < CANDL_STATEMENT_USR_INDEX_MAX_LOOP_DEPTH; ++k)
13004 +          cur_index[k] = max + (k - j) + 1;
13005 +        break;
13006 +      }
13007      }
13008 -    sscanf(str,"%d",&index[i]) ;
13009 -    c += n ;
13010 -  }
13011 -  statement->index   = index ;
13012 -  
13013 -  statement->written = pip_matrix_read(file) ;
13014 -  statement->read    = pip_matrix_read(file) ;
13015 +    for (j = 0; j < stmt_usr->depth; ++j)
13016 +      stmt_usr->index[j] = cur_index[j];
13017  
13018 -  return statement ;
13019 -}
13020 -
13021 -
13022 -/******************************************************************************
13023 - *                            Processing functions                            *
13024 - ******************************************************************************/
13025 -
13026 -
13027 -/**
13028 - * candl_statement_malloc function:
13029 - * This function allocates the memory space for a CandlStatement structure and
13030 - * sets its fields with default values. Then it returns a pointer to the
13031 - * allocated space.
13032 - * - 09/12/2005: first version.
13033 - */
13034 -CandlStatement * candl_statement_malloc()
13035 -{ CandlStatement * statement ;
13036 -
13037 -  /* Memory allocation for the CloogProgram structure. */
13038 -  statement = (CandlStatement *)malloc(sizeof(CandlStatement)) ;
13039 -  if (statement == NULL) 
13040 -  { fprintf(stderr, "[Candl]ERROR: memory overflow.\n") ;
13041 -    exit(1) ;
13042 +    max = max < cur_index[j - 1] ? cur_index[j - 1] : max;
13043 +    
13044 +    iter->usr = stmt_usr;
13045 +    count++;
13046    }
13047 -  
13048 -  /* We set the various fields with default values. */
13049 -  statement->label   = CANDL_UNSET ;
13050 -  statement->type    = CANDL_UNSET ;
13051 -  statement->depth   = CANDL_UNSET ;
13052 -  statement->index   = NULL ;
13053 -  statement->domain  = NULL ;
13054 -  statement->written = NULL ;
13055 -  statement->read    = NULL ;
13056 -  statement->ref     = NULL ;
13057 -
13058 -  return statement ;
13059  }
13060  
13061  
13062  /**
13063 - * candl_statement_commute function:
13064 - * This function returns 1 if the two statements given as parameter commute,
13065 - * 0 otherwise. It uses the statement type information to answer the question.
13066 - * - 09/12/2005: first version.
13067 + * candl_usr_free function:
13068   */
13069 -int candl_statement_commute(statement1, statement2)
13070 -CandlStatement * statement1, * statement2 ;
13071 -{ int type1, type2, nb_rows, i ;
13072 -  
13073 -  type1 = statement1->type ;
13074 -  type2 = statement2->type ;
13075 -
13076 -   /* In the case of self-dependence, a statement commutes with hitself if
13077 -    * it is a reduction.
13078 -    */
13079 -   if ((statement1 == statement2) &&
13080 -       ((type1 == CANDL_P_REDUCTION) ||
13081 -        (type1 == CANDL_M_REDUCTION) ||
13082 -        (type1 == CANDL_T_REDUCTION)))
13083 -   return 1 ;
13084 -   
13085 -   /* Two statement commute when they are a reduction of the same type (or if
13086 -    * their left and right members are the same, but it's not exploited here).
13087 -    * The type may differ if it is either minus or plus-reduction. Furthermore,
13088 -    * they have to write onto the same array (and only one array).
13089 -    */
13090 -   if (((type1 == CANDL_P_REDUCTION) && (type2 == CANDL_P_REDUCTION)) ||
13091 -       ((type1 == CANDL_M_REDUCTION) && (type2 == CANDL_M_REDUCTION)) ||
13092 -       ((type1 == CANDL_T_REDUCTION) && (type2 == CANDL_T_REDUCTION)) ||
13093 -       ((type1 == CANDL_P_REDUCTION) && (type2 == CANDL_M_REDUCTION)) ||
13094 -       ((type1 == CANDL_M_REDUCTION) && (type2 == CANDL_P_REDUCTION)))
13095 -   { /* Here we check that there is one, only one and the same array. */
13096 -     nb_rows = statement1->written->NbRows ;
13097 -     if ((nb_rows == 0) || (nb_rows != statement2->written->NbRows))
13098 -     return 0 ;
13099 -     
13100 -     if (statement1->written->p[0][0] != statement2->written->p[0][0])
13101 -     return 0 ;
13102 -          
13103 -     for (i=1;i<nb_rows;i++)
13104 -     if ((statement1->written->p[i][0] != 0) ||
13105 -         (statement2->written->p[i][0] != 0))
13106 -     return 0 ;
13107 -   
13108 -     return 1 ;
13109 -   }
13110 -   
13111 -   return 0 ;
13112 +void candl_statement_usr_cleanup(osl_statement_p statement) {
13113 +  candl_statement_usr_p stmt_usr;
13114 +  stmt_usr = statement->usr;
13115 +  if (stmt_usr) {
13116 +    if (stmt_usr->index)
13117 +      free(stmt_usr->index);
13118 +    statement->usr = stmt_usr->usr_backup;
13119 +    free(stmt_usr);
13120 +  }
13121  }
13122 -
13123 -
13124 -
13125 -
13126 -
13127 -
13128 diff --git a/source/util.c b/source/util.c
13129 new file mode 100644
13130 index 0000000..df83aad
13131 --- /dev/null
13132 +++ b/source/util.c
13133 @@ -0,0 +1,207 @@
13134 +
13135 +   /**------ ( ----------------------------------------------------------**
13136 +    **       )\                      CAnDL                               **
13137 +    **----- /  ) --------------------------------------------------------**
13138 +    **     ( * (                   util.c                                **
13139 +    **----  \#/  --------------------------------------------------------**
13140 +    **    .-"#'-.        First version: june 7th 2012                    **
13141 +    **--- |"-.-"| -------------------------------------------------------**
13142 +          |     |
13143 +          |     |
13144 + ******** |     | *************************************************************
13145 + * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
13146 + ******************************************************************************
13147 + *                                                                            *
13148 + * Copyright (C) 2003-2008 Cedric Bastoul                                     *
13149 + *                                                                            *
13150 + * This is free software; you can redistribute it and/or modify it under the  *
13151 + * terms of the GNU General Public License as published by the Free Software  *
13152 + * Foundation; either version 2 of the License, or (at your option) any later *
13153 + * version.                                                                   *
13154 + *                                                                            *
13155 + * This software is distributed in the hope that it will be useful, but       *
13156 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
13157 + * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   *
13158 + * for more details.                                                          *
13159 + *                                                                            *
13160 + * You should have received a copy of the GNU General Public License along    *
13161 + * with software; if not, write to the Free Software Foundation, Inc.,        *
13162 + * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA                     *
13163 + *                                                                            *
13164 + * CAnDL, the Chunky Dependence Analyzer                                      *
13165 + * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr                         *
13166 + *                                                                            *
13167 + ******************************************************************************/
13168 +
13169 +/*
13170 + * author Joel Poudroux and Cedric Bastoul
13171 + */
13172 +
13173 +#include <stdio.h>
13174 +#include <stdlib.h>
13175 +#include <osl/statement.h>
13176 +#include <osl/relation.h>
13177 +#include <osl/macros.h>
13178 +#include <osl/extensions/dependence.h>
13179 +#include <osl/relation_list.h>
13180 +#include <osl/scop.h>
13181 +#include <candl/macros.h>
13182 +#include <candl/util.h>
13183 +#include <candl/statement.h>
13184 +
13185 +
13186 +/**
13187 + * candl_util_relation_get_line function:
13188 + * Because the lines in the scattering matrix may have not ordered, we have to
13189 + * search the corresponding line. It returns the first line where the value is
13190 + * different from zero in the `column'. `column' is between 0 and 
13191 + * nb_output_dims-1
13192 + * \param[in] relation
13193 + * \param[in] column        Line to search
13194 + * \return                  Return the real line
13195 + */
13196 +int candl_util_relation_get_line(osl_relation_p relation, int column) {
13197 +  if (column < 0 || column > relation->nb_output_dims)
13198 +    return -1;
13199 +  int i;
13200 +  int precision = relation->precision;
13201 +  for (i = 0 ; i < relation->nb_rows ; i++) {
13202 +    if (!osl_int_zero(precision, relation->m[i][column + 1])) {
13203 +      break;
13204 +    }
13205 +  }
13206 +  return (i == relation->nb_rows ? -1 : i );
13207 +}
13208 +
13209 +
13210 +
13211 +/* Check if two scop can be compared (same number of statements and
13212 + * same access array/domain in the same order)
13213 + *
13214 + * \param[in] s1  first scop to compare
13215 + * \param[in] s2  second scop to compare
13216 + * \return        1 if two scops equal, 0 otherwise
13217 + */
13218 +int candl_util_check_scop(osl_scop_p s1, osl_scop_p s2) {
13219 +  
13220 +  osl_statement_p it1 = s1->statement, it2 = s2->statement;
13221 +  for (; it1 != NULL && it2 != NULL ; it1 = it1->next, it2 = it2->next) {
13222 +    if (!osl_relation_list_equal(it1->access, it2->access))
13223 +      return 0;
13224 +    if (!osl_relation_equal(it1->domain, it2->domain))
13225 +      return 0;
13226 +  }
13227 +  
13228 +  /* Different number of statements */
13229 +  if ((it1 == NULL || it2 == NULL) && it1 != it2)
13230 +    return 0;
13231 +  
13232 +  return 1;
13233 +}
13234 +
13235 +/* Extends the candl_util_check_scop() functionality to a list of scops
13236 + * Compares each scop in s1 to the corresponding element in list s2
13237 + * same access array/domain in the same order)
13238 + *
13239 + * \param[in] s1  first scop List to compare
13240 + * \param[in] s2  second scop List to compare
13241 + * \return    1 if two scops lists equal, 0 otherwise
13242 + */
13243 +int candl_util_check_scop_list(osl_scop_p s1, osl_scop_p s2) {
13244 +
13245 +  while ((s1!=NULL) && (s2!=NULL)) {
13246 +    if(!candl_util_check_scop(s1, s2))
13247 +      return 0;
13248 +
13249 +    s1 = s1->next; 
13250 +    s2 = s2->next;
13251 +  }
13252 +
13253 +  /* Different number of scops */
13254 +  if ((s1 == NULL || s2 == NULL) && s1 != s2)
13255 +    return 0;
13256 +
13257 +  /*scop lists can be compared*/
13258 +  return 1;
13259 +}
13260 +
13261 +/* Return the number access array which have the type `type'
13262 + */
13263 +static int count_nb_access(osl_statement_p st, int type) {
13264 +  osl_relation_list_p access = st->access;
13265 +  int count = 0;
13266 +  for (; access != NULL ; access = access->next)
13267 +    if (access->elt->type == type)
13268 +      count ++;
13269 +  return count;
13270 +}
13271 +
13272 +
13273 +/**
13274 + * candl_util_statement_commute function:
13275 + * This function returns 1 if the two statements given as parameter commute,
13276 + * 0 otherwise. It uses the statement type information to answer the question.
13277 + * - 09/12/2005: first version.
13278 + */
13279 +int candl_util_statement_commute(osl_statement_p statement1,
13280 +                                 osl_statement_p statement2) {
13281 +  candl_statement_usr_p usr1, usr2;
13282 +  int type1, type2;
13283 +  int id1, id2;
13284 +  
13285 +  usr1  = statement1->usr;
13286 +  usr2  = statement2->usr;
13287 +  type1 = usr1->type;
13288 +  type2 = usr2->type;
13289 +
13290 +  /* In the case of self-dependence, a statement commutes with hitself if
13291 +   * it is a reduction.
13292 +   */
13293 +  if ((statement1 == statement2) &&
13294 +      ((type1 == OSL_DEPENDENCE_P_REDUCTION) ||
13295 +       (type1 == OSL_DEPENDENCE_M_REDUCTION) ||
13296 +       (type1 == OSL_DEPENDENCE_T_REDUCTION)))
13297 +  return 1;
13298 +  
13299 +  /* Two statement commute when they are a reduction of the same type (or if
13300 +   * their left and right members are the same, but it's not exploited here).
13301 +   * The type may differ if it is either minus or plus-reduction. Furthermore,
13302 +   * they have to write onto the same array (and only one array).
13303 +   */
13304 +  if ((type1 == OSL_DEPENDENCE_P_REDUCTION && type2 == OSL_DEPENDENCE_P_REDUCTION) ||
13305 +      (type1 == OSL_DEPENDENCE_M_REDUCTION && type2 == OSL_DEPENDENCE_M_REDUCTION) ||
13306 +      (type1 == OSL_DEPENDENCE_T_REDUCTION && type2 == OSL_DEPENDENCE_T_REDUCTION) ||
13307 +      (type1 == OSL_DEPENDENCE_P_REDUCTION && type2 == OSL_DEPENDENCE_M_REDUCTION) ||
13308 +      (type1 == OSL_DEPENDENCE_M_REDUCTION && type2 == OSL_DEPENDENCE_P_REDUCTION)) {
13309 +    /* Here we check that there is one, only one and the same array. */
13310 +    if (count_nb_access(statement1, OSL_TYPE_WRITE) > 1 ||
13311 +        count_nb_access(statement2, OSL_TYPE_WRITE) > 1)
13312 +      return 0;
13313 +    
13314 +    /* search the first osl_write access */
13315 +    osl_relation_list_p access1 = statement1->access;
13316 +    osl_relation_list_p access2 = statement2->access;
13317 +    for (; access1 != NULL && access2 != NULL ;
13318 +         access1 = access1->next, access2 = access2->next)
13319 +      if (access1->elt->type == OSL_TYPE_WRITE)
13320 +        break;
13321 +    
13322 +    if (access1 == NULL || access2 == NULL ||
13323 +        access2->elt->type != OSL_TYPE_WRITE || 
13324 +        access2->elt->nb_output_dims != access1->elt->nb_output_dims) {
13325 +      osl_statement_dump(stderr, statement1);
13326 +      osl_statement_dump(stderr, statement2);
13327 +      CANDL_error("These statements haven't the same access array or access is NULL");
13328 +    }
13329 +    
13330 +    /* Check if the first dim (the Arr column) is the same */
13331 +    id1 = osl_relation_get_array_id(access1->elt);
13332 +    id2 = osl_relation_get_array_id(access2->elt);
13333 +    if (id1 != id2)
13334 +      return 0;
13335 +  
13336 +    return 1;
13337 +  }
13338 +  
13339 +  return 0;
13340 +}
13341 diff --git a/source/violation.c b/source/violation.c
13342 index 1f2d4bb..3f8e3fe 100644
13343 --- a/source/violation.c
13344 +++ b/source/violation.c
13345 @@ -6,8 +6,8 @@
13346      **----  \#/  --------------------------------------------------------**
13347      **    .-"#'-.        First version: december 12th 2005               **
13348      **--- |"-.-"| -------------------------------------------------------**
13349 -          |     |
13350 -          |     |
13351 +    |     |
13352 +    |     |
13353   ******** |     | *************************************************************
13354   * CAnDL  '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
13355   ******************************************************************************
13356 @@ -36,10 +36,20 @@
13357   *          please feel free to correct and improve it !
13358   */
13359  
13360 -# include <stdlib.h>
13361 -# include <stdio.h>
13362 -# include <string.h>
13363 -# include "../include/candl/candl.h"
13364 +#include <stdlib.h>
13365 +#include <stdio.h>
13366 +#include <string.h>
13367 +#include <osl/macros.h>
13368 +#include <osl/relation.h>
13369 +#include <osl/statement.h>
13370 +#include <osl/scop.h>
13371 +#include <osl/extensions/dependence.h>
13372 +#include <candl/macros.h>
13373 +#include <candl/matrix.h>
13374 +#include <candl/piplib.h>
13375 +#include <candl/piplib-wrapper.h>
13376 +#include <candl/statement.h>
13377 +#include <candl/violation.h>
13378  
13379  
13380  /******************************************************************************
13381 @@ -48,84 +58,79 @@
13382  
13383  
13384  /**
13385 - * candl_violation_print_structure function:
13386 + * candl_violation_idump function:
13387   * Displays a CandlViolation structure (violation) into a file (file,
13388   * possibly stdout) in a way that trends to be understandable without falling
13389   * in a deep depression or, for the lucky ones, getting a headache... It
13390   * includes an indentation level (level) in order to work with others
13391 - * print_structure functions.
13392 + * idump functions.
13393   * - 18/09/2003: first version.
13394   */
13395 -void candl_violation_print_structure(file, violation, level)
13396 -FILE * file ;
13397 -CandlViolation * violation ;
13398 -int level ;
13399 -{ int j, first=1 ;
13400 -  CandlDependence * next=NULL ;
13401 -
13402 -  if (violation != NULL)
13403 -  { /* Go to the right level. */
13404 +void candl_violation_idump(FILE *file, candl_violation_p violation, 
13405 +                                    int level) {
13406 +  int j, first=1;
13407 +  osl_dependence_p next=NULL;
13408 +
13409 +  if (violation != NULL) { /* Go to the right level. */
13410      for(j=0; j<level; j++)
13411 -    fprintf(file,"|\t") ;
13412 -    fprintf(file,"+-- CandlViolation\n") ;
13413 -  }
13414 -  else
13415 -  { for(j=0; j<level; j++)
13416 -    fprintf(file,"|\t") ;
13417 -    fprintf(file,"+-- NULL dependence violation\n") ;
13418 +      fprintf(file,"|\t");
13419 +    fprintf(file,"+-- CandlViolation\n");
13420 +  } else {
13421 +    for(j=0; j<level; j++)
13422 +      fprintf(file,"|\t");
13423 +    fprintf(file,"+-- NULL dependence violation\n");
13424    }
13425  
13426 -  while (violation != NULL)
13427 -  { if (!first)
13428 -    { /* Go to the right level. */
13429 +  while (violation != NULL) {
13430 +    if (!first) { /* Go to the right level. */
13431        for(j=0; j<level; j++)
13432 -      fprintf(file,"|\t") ;
13433 -      fprintf(file,"|   CandlViolation\n") ;
13434 +        fprintf(file,"|\t");
13435 +      fprintf(file,"|   CandlViolation\n");
13436 +    } else {
13437 +      first = 0;
13438      }
13439 -    else
13440 -    first = 0 ;
13441  
13442      /* A blank line. */
13443      for(j=0; j<=level+1; j++)
13444 -    fprintf(file,"|\t") ;
13445 -    fprintf(file,"\n") ;
13446 +      fprintf(file,"|\t");
13447 +    fprintf(file,"\n");
13448  
13449      /* Go to the right level and print the dimension. */
13450      for(j=0; j<=level; j++)
13451 -    fprintf(file,"|\t") ;
13452 -    fprintf(file,"Dimension: %d\n",violation->dimension) ;
13453 +      fprintf(file,"|\t");
13454 +    fprintf(file,"Dimension: %d\n",violation->dimension);
13455  
13456      /* A blank line. */
13457      for(j=0; j<=level+1; j++)
13458 -    fprintf(file,"|\t") ;
13459 -    fprintf(file,"\n") ;
13460 +      fprintf(file,"|\t");
13461 +    fprintf(file,"\n");
13462  
13463      /* Print the dependence. */
13464 -    if (violation->dependence != NULL)
13465 -    { next = violation->dependence->next ; /* To not print the whole list... */
13466 -      violation->dependence->next = NULL ; /* I know it's not beautiful :-/ ! */
13467 +    if (violation->dependence != NULL) {
13468 +      next = violation->dependence->next; /* To not print the whole list... */
13469 +      violation->dependence->next = NULL; /* I know it's not beautiful :-/ ! */
13470      }
13471 -    candl_dependence_print_structure(file,violation->dependence,level+1) ;
13472 +    osl_dependence_idump(file,violation->dependence,level+1);
13473      if (violation->dependence != NULL)
13474 -    violation->dependence->next = next ;
13475 +      violation->dependence->next = next;
13476  
13477      /* Print the dependence polyhedron. */
13478 -    candl_matrix_print_structure(file,violation->domain,level+1) ;
13479 +    osl_relation_idump(file, violation->domain, level+1);
13480  
13481 -    violation = violation->next ;
13482 +    violation = violation->next;
13483  
13484      /* Next line. */
13485 -    if (violation != NULL)
13486 -    { for (j=0; j<=level; j++)
13487 -      fprintf(file,"|\t") ;
13488 -      fprintf(file,"V\n") ;
13489 +    if (violation != NULL) {
13490 +      for (j=0; j<=level; j++)
13491 +        fprintf(file,"|\t");
13492 +      fprintf(file,"V\n");
13493      }
13494    }
13495  
13496    /* The last line. */
13497    for(j=0; j<=level; j++)
13498 -  fprintf(file,"|\t") ;
13499 -  fprintf(file,"\n") ;
13500 +    fprintf(file,"|\t");
13501 +  fprintf(file,"\n");
13502  }
13503  
13504  
13505 @@ -133,8 +138,8 @@ int level ;
13506   * This function prints the content of a CandlViolation structure
13507   * (violation) into a file (file, possibly stdout).
13508   */
13509 -void candl_violation_print(FILE * file, CandlViolation * violation)
13510 -{ candl_violation_print_structure(file,violation,0) ;
13511 +void candl_violation_dump(FILE * file, candl_violation_p violation) {
13512 +  candl_violation_idump(file,violation,0);
13513  }
13514  
13515  
13516 @@ -144,43 +149,47 @@ void candl_violation_print(FILE * file, CandlViolation * violation)
13517   * See http://www.graphviz.org
13518   * - 12/12/2005: first version.
13519   */
13520 -void candl_violation_pprint(FILE * file, CandlViolation * violation)
13521 -{ int i=0 ;
13522 -  CandlDependence * dependence ;
13523 +void candl_violation_pprint(FILE * file, candl_violation_p violation) {
13524 +  int i=0;
13525 +  osl_dependence_p dependence;
13526 +  candl_statement_usr_p s_usr;
13527 +  candl_statement_usr_p t_usr;
13528  
13529 -  fprintf(file,"digraph G {\n") ;
13530 +  fprintf(file,"digraph G {\n");
13531  
13532 -  fprintf(file,"# Legality Violation Graph\n") ;
13533 +  fprintf(file,"# Legality Violation Graph\n");
13534    fprintf(file,"# Generated by Candl "CANDL_RELEASE" "CANDL_VERSION" bits\n");
13535    if (violation == NULL)
13536 -  fprintf(file,"# Congratulations: the transformation is legal !\n");
13537 -
13538 -  while (violation != NULL)
13539 -  { dependence = violation->dependence ;
13540 -
13541 -    fprintf(file,"  S%d -> S%d [label=\" ",dependence->source->label,
13542 -                                           dependence->target->label) ;
13543 -    switch (dependence->type)
13544 -    { case CANDL_UNSET : fprintf(file,"UNSET") ; break ;
13545 -      case CANDL_RAW   : fprintf(file,"RAW")   ; break ;
13546 -      case CANDL_WAR   : fprintf(file,"WAR")   ; break ;
13547 -      case CANDL_WAW   : fprintf(file,"WAW")   ; break ;
13548 -      case CANDL_RAR   : fprintf(file,"RAR")   ; break ;
13549 -      default : fprintf(file,"unknown") ;
13550 +    fprintf(file,"# Congratulations: the transformation is legal !\n");
13551 +
13552 +  while (violation != NULL) {
13553 +    dependence = violation->dependence;
13554 +    s_usr = dependence->stmt_source_ptr->usr;
13555 +    t_usr = dependence->stmt_target_ptr->usr;
13556 +
13557 +    fprintf(file,"  S%d -> S%d [label=\" ", s_usr->label,
13558 +                                            t_usr->label);
13559 +    switch (dependence->type) {
13560 +      case OSL_UNDEFINED : fprintf(file,"UNSET"); break;
13561 +      case OSL_DEPENDENCE_RAW   : fprintf(file,"RAW")  ; break;
13562 +      case OSL_DEPENDENCE_WAR   : fprintf(file,"WAR")  ; break;
13563 +      case OSL_DEPENDENCE_WAW   : fprintf(file,"WAW")  ; break;
13564 +      case OSL_DEPENDENCE_RAR   : fprintf(file,"RAR")  ; break;
13565 +      default : fprintf(file,"unknown");
13566      }
13567      fprintf(file," depth %d, ref %d->%d, viol %d \"];\n",
13568              dependence->depth,
13569              dependence->ref_source,
13570              dependence->ref_target,
13571 -            violation->dimension) ;
13572 -    violation = violation->next ;
13573 -    i++ ;
13574 +            violation->dimension);
13575 +    violation = violation->next;
13576 +    i++;
13577    }
13578  
13579    if (i>4)
13580 -  fprintf(file,"# Number of edges = %i\n}\n",i) ;
13581 +    fprintf(file,"# Number of edges = %i\n}\n",i);
13582    else
13583 -  fprintf(file,"}\n") ;
13584 +    fprintf(file,"}\n");
13585  }
13586  
13587  
13588 @@ -190,13 +199,14 @@ void candl_violation_pprint(FILE * file, CandlViolation * violation)
13589   * violation graph.
13590   * - 20/03/2006: first version.
13591   */
13592 -void candl_violation_view(CandlViolation * violation)
13593 -{ FILE * temp_output ;
13594 -
13595 -  temp_output = fopen(CANDL_TEMP_OUTPUT,"w") ;
13596 -  candl_violation_pprint(temp_output,violation) ;
13597 -  fclose(temp_output) ;
13598 -  system("(dot -Tps "CANDL_TEMP_OUTPUT" | gv - &) && rm -f "CANDL_TEMP_OUTPUT) ;
13599 +void candl_violation_view(candl_violation_p violation) {
13600 +  FILE * temp_output;
13601 +  temp_output = fopen(CANDL_TEMP_OUTPUT,"w+");
13602 +  candl_violation_pprint(temp_output,violation);
13603 +  fclose(temp_output);
13604 +  /* check the return to remove the warning compilation */
13605 +  if(system("dot -Tps "CANDL_TEMP_OUTPUT" | gv - && rm -f "CANDL_TEMP_OUTPUT" &"))
13606 +    ;
13607  }
13608  
13609  
13610 @@ -208,14 +218,13 @@ void candl_violation_view(CandlViolation * violation)
13611   * This function frees the allocated memory for a CandlViolation structure.
13612   * - 18/09/2003: first version.
13613   */
13614 -void candl_violation_free(CandlViolation * violation)
13615 -{ CandlViolation * next ;
13616 -
13617 -  while (violation != NULL)
13618 -  { next = violation->next ;
13619 -    candl_matrix_free(violation->domain) ;
13620 -    free(violation) ;
13621 -    violation = next ;
13622 +void candl_violation_free(candl_violation_p violation) {
13623 +  candl_violation_p next;
13624 +  while (violation != NULL) {
13625 +    next = violation->next;
13626 +    osl_relation_free(violation->domain);
13627 +    free(violation);
13628 +    violation = next;
13629    }
13630  }
13631  
13632 @@ -232,23 +241,27 @@ void candl_violation_free(CandlViolation * violation)
13633   * allocated space.
13634   * - 07/12/2005: first version.
13635   */
13636 -CandlViolation * candl_violation_malloc()
13637 -{ CandlViolation * violation ;
13638 +candl_violation_p candl_violation_malloc() {
13639 +  candl_violation_p violation;
13640  
13641    /* Memory allocation for the CandlViolation structure. */
13642 -  violation = (CandlViolation *)malloc(sizeof(CandlViolation)) ;
13643 -  if (violation == NULL)
13644 -  { fprintf(stderr, "[Candl]ERROR: memory overflow.\n") ;
13645 -    exit(1) ;
13646 +  violation = (candl_violation_p) malloc(sizeof(candl_violation_t));
13647 +  if (violation == NULL) {
13648 +    fprintf(stderr, "[Candl]ERROR: memory overflow.\n");
13649 +    exit(1);
13650    }
13651  
13652    /* We set the various fields with default values. */
13653 -  violation->dependence = NULL ;
13654 -  violation->domain     = NULL ;
13655 -  violation->next       = NULL ;
13656 -  violation->dimension  = CANDL_UNSET ;
13657 -
13658 -  return violation ;
13659 +  violation->dependence = NULL;
13660 +  violation->domain     = NULL;
13661 +  violation->next       = NULL;
13662 +  violation->dimension  = OSL_UNDEFINED;
13663 +  violation->source_nb_output_dims_scattering = -1;
13664 +  violation->target_nb_output_dims_scattering = -1;
13665 +  violation->source_nb_local_dims_scattering = -1;
13666 +  violation->target_nb_local_dims_scattering = -1;
13667 +
13668 +  return violation;
13669  }
13670  
13671  
13672 @@ -258,22 +271,23 @@ CandlViolation * candl_violation_malloc()
13673   * of this list is (start). This function updates (now) to the end of the loop
13674   * list (loop), and updates (start) if the added element is the first one -that
13675   * is when (start) is NULL-.
13676 - * - 12/12/2005: first version (from candl_dependence_add).
13677 + * - 12/12/2005: first version (from candl_dependence_add, 
13678 + *                              currently osl_dependence_add).
13679   */
13680 -void candl_violation_add(start, now, violation)
13681 -CandlViolation ** start, ** now, * violation ;
13682 -{ if (violation != NULL)
13683 -  { if (*start == NULL)
13684 -    { *start = violation ;
13685 -      *now = *start ;
13686 -    }
13687 -    else
13688 -    { (*now)->next = violation ;
13689 -      *now = (*now)->next ;
13690 +void candl_violation_add(candl_violation_p* start,
13691 +                         candl_violation_p* now,
13692 +                         candl_violation_p violation) {
13693 +  if (violation != NULL) {
13694 +    if (*start == NULL) {
13695 +      *start = violation;
13696 +      *now = *start;
13697 +    } else {
13698 +      (*now)->next = violation;
13699 +      *now = (*now)->next;
13700      }
13701  
13702      while ((*now)->next != NULL)
13703 -    *now = (*now)->next ;
13704 +      *now = (*now)->next;
13705    }
13706  }
13707  
13708 @@ -289,86 +303,97 @@ CandlViolation ** start, ** now, * violation ;
13709   **
13710   * - 12/12/2005: first version.
13711   */
13712 -CandlViolation * candl_violation(program, dependence, options)
13713 -CandlProgram * program ;
13714 -CandlDependence * dependence ;
13715 -CandlOptions * options ;
13716 -{ int dimension, max_dimension, violated ;
13717 -  CandlMatrix * system, * domain, * t_source, * t_target ;
13718 -  CandlStatement * source, * target ;
13719 -  CandlViolation * violation=NULL, * now=NULL, * new ;
13720 -  PipOptions * pip_options ;
13721 -  PipQuast * solution ;
13722 -
13723 -  /* If there is no program or transformation, we consider this legal. */
13724 -  if ((program == NULL) || (program->transformation == NULL))
13725 -  return NULL ;
13726 -
13727 -  /* If the dependence graph is not already built, do it. */
13728 -  if (dependence == NULL)
13729 -  dependence = candl_dependence(program,options) ;
13730 -
13731 -  pip_options = pip_options_init() ;
13732 -  pip_options->Simplify = 1 ;
13733 +candl_violation_p candl_violation(osl_scop_p orig_scop,
13734 +                                  osl_dependence_p orig_dependence,
13735 +                                  osl_scop_p test_scop,
13736 +                                  candl_options_p options) {
13737 +  osl_statement_p source, target, iter;
13738 +  osl_statement_p *stmts;
13739 +  osl_relation_p t_source, t_target;
13740 +  candl_statement_usr_p s_usr, t_usr;
13741 +  candl_violation_p violation = NULL, now, new;
13742 +  PipOptions *pip_options;
13743 +  PipQuast *solution;
13744 +  int i;
13745 +  int nb_par = orig_scop->context->nb_parameters;
13746 +  int nb_stmts = 0;
13747 +  int dimension, max_dimension, violated;
13748 +  
13749 +  /* If there is no scop or transformation, we consider this legal. */
13750 +  if (test_scop == NULL)
13751 +    return NULL;
13752 +  
13753 +  /* Temporary array to access faster at the `label'th statement */
13754 +  for (iter = test_scop->statement ; iter != NULL ;
13755 +       iter = iter->next, nb_stmts++)
13756 +    ;
13757 +  stmts = (osl_statement_p*) malloc(sizeof(osl_statement_p) * nb_stmts);
13758 +  for (i = 0, iter = test_scop->statement ; iter != NULL ;
13759 +       iter = iter->next, i++) {
13760 +    stmts[i] = iter;
13761 +  }
13762  
13763 +  pip_options = pip_options_init();
13764 +  pip_options->Simplify = 1;
13765 +  
13766    /* We check every edge of the dependence graph. */
13767 -  while (dependence != NULL)
13768 -  { source = dependence->source ;
13769 -    target = dependence->target ;
13770 -    domain = dependence->domain ;
13771 +  while (orig_dependence != NULL) {
13772 +    source = orig_dependence->stmt_source_ptr;
13773 +    target = orig_dependence->stmt_target_ptr;
13774 +    s_usr  = source->usr;
13775 +    t_usr  = target->usr;
13776  
13777      /* We find the source transformation matrix. */
13778 -    t_source = program->transformation[source->label] ;
13779 +    t_source = stmts[s_usr->label]->scattering;
13780  
13781      /* We find the target transformation matrix. */
13782 -    t_target = program->transformation[target->label] ;
13783 -
13784 +    t_target = stmts[t_usr->label]->scattering;
13785 +    
13786      /* The maximal dimension we have to check for legality. */
13787 -    max_dimension = CANDL_min(t_source->NbRows,t_target->NbRows) ;
13788 -
13789 +    max_dimension = CANDL_min(t_source->nb_output_dims,t_target->nb_output_dims);
13790 +    
13791      /* We check each dimension for legality. */
13792 -    for (dimension = 0; dimension<max_dimension; dimension++)
13793 -    { violated = 0 ;
13794 -      system = NULL ;
13795 +    for (dimension = 1; dimension <= max_dimension; dimension++) {
13796 +      violated = 0;
13797  
13798        /* We build the constraint system corresponding to that
13799         * violation then check if there is an integral point inside,
13800         * if yes there is actually a dependence violation and we
13801         * will add this one to the list.
13802         */
13803 -      system = candl_matrix_violation(dependence->domain,t_source,t_target,
13804 -                                      dimension,program->context->NbColumns-2) ;
13805 -
13806 -      solution = pip_solve(system,program->context,-1,pip_options) ;
13807 +      new = candl_matrix_violation(orig_dependence, t_source,
13808 +                                   t_target, dimension,
13809 +                                   nb_par);
13810 +      solution = pip_solve_osl(new->domain, orig_scop->context, -1, pip_options);
13811  
13812        if ((solution != NULL) &&
13813            ((solution->list != NULL) || (solution->condition != NULL)))
13814 -      violated = 1 ;
13815 -
13816 -      pip_quast_free(solution) ;
13817 +        violated = 1;
13818  
13819 -      if (violated)
13820 -      { new = candl_violation_malloc() ;
13821 +      pip_quast_free(solution);
13822  
13823 -       /* We set the various fields with corresponding values. */
13824 -        new->dependence = dependence ;
13825 -       new->dimension = dimension ;
13826 -       new->domain = system ;
13827 +      if (violated) {
13828  
13829 -       candl_violation_add(&violation,&now,new) ;
13830 +        /* We set the various fields with corresponding values. */
13831 +        new->dependence = orig_dependence;
13832 +        new->dimension = dimension;
13833 +        candl_violation_add(&violation,&now,new);
13834  
13835 -       if (!options->fullcheck)
13836 -       { pip_options_free(pip_options) ;
13837 -          return violation ;
13838 -       }
13839 +        if (!options->fullcheck) {
13840 +          pip_options_free(pip_options);
13841 +          return violation;
13842 +        }
13843 +      } else if (new) {
13844 +          candl_violation_free(new);
13845        }
13846 -      else
13847 -      candl_matrix_free(system) ;
13848      }
13849 -    dependence = dependence->next ;
13850 +    orig_dependence = orig_dependence->next;
13851    }
13852  
13853 -  pip_options_free(pip_options) ;
13854 -  return violation ;
13855 +  free(stmts);
13856 +  
13857 +  pip_options_free(pip_options);
13858 +
13859 +  return violation;
13860  }
13861  
This page took 1.469353 seconds and 3 git commands to generate.