[polly] r228193 - Import isl(+imath) as an external library into Polly

Tobias Grosser tobias at grosser.es
Wed Feb 4 12:55:55 PST 2015


Author: grosser
Date: Wed Feb  4 14:55:43 2015
New Revision: 228193

URL: http://llvm.org/viewvc/llvm-project?rev=228193&view=rev
Log:
Import isl(+imath) as an external library into Polly

With this patch Polly is always GPL-free (no dependency on GMP any more). As a
result, building and distributing Polly will be easier. Furthermore, there is no
need to tightly coordinate isl and Polly releases anymore.

We import isl b3e0fa7a05d as well as imath 4d707e5ef2. These are the git
versions Polly currently was tested with when using utils/checkout_isl.sh. The
imported libraries are both MIT-style licensed.

We build isl and imath with -fvisibility=hidden to avoid clashes in case other
projects (such as gcc) use conflicting versions of isl. The use of imath can
temporarily reduce compile-time performance of Polly. We will work on
performance tuning in tree.

Patches to isl should be contributed first to the main isl repository and can
then later be reimported to Polly.

This patch is also a prerequisite for the upcoming isl C++ interface.

Added:
    polly/trunk/lib/External/
    polly/trunk/lib/External/README.txt
    polly/trunk/lib/External/isl/
    polly/trunk/lib/External/isl/.gitignore
    polly/trunk/lib/External/isl/AUTHORS
    polly/trunk/lib/External/isl/ChangeLog
    polly/trunk/lib/External/isl/LICENSE
    polly/trunk/lib/External/isl/Makefile.am
    polly/trunk/lib/External/isl/README
    polly/trunk/lib/External/isl/autogen.sh   (with props)
    polly/trunk/lib/External/isl/basis_reduction_tab.c
    polly/trunk/lib/External/isl/basis_reduction_templ.c
    polly/trunk/lib/External/isl/bound.c
    polly/trunk/lib/External/isl/bound_test.sh.in   (with props)
    polly/trunk/lib/External/isl/cat.c
    polly/trunk/lib/External/isl/closure.c
    polly/trunk/lib/External/isl/codegen.c
    polly/trunk/lib/External/isl/codegen_test.sh.in
    polly/trunk/lib/External/isl/configure.ac
    polly/trunk/lib/External/isl/doc/
    polly/trunk/lib/External/isl/doc/Makefile.am
    polly/trunk/lib/External/isl/doc/SubmittingPatches
    polly/trunk/lib/External/isl/doc/chicago.bst
    polly/trunk/lib/External/isl/doc/chicago.sty
    polly/trunk/lib/External/isl/doc/implementation.tex
    polly/trunk/lib/External/isl/doc/isl.bib
    polly/trunk/lib/External/isl/doc/manual.tex
    polly/trunk/lib/External/isl/doc/mypod2latex   (with props)
    polly/trunk/lib/External/isl/doc/user.pod
    polly/trunk/lib/External/isl/gitversion.h
    polly/trunk/lib/External/isl/imath/
    polly/trunk/lib/External/isl/imath/ChangeLog
    polly/trunk/lib/External/isl/imath/LICENSE
    polly/trunk/lib/External/isl/imath/README.md
    polly/trunk/lib/External/isl/imath/bintest.c
    polly/trunk/lib/External/isl/imath/bug-swap.c
    polly/trunk/lib/External/isl/imath/contrib/
    polly/trunk/lib/External/isl/imath/contrib/Makefile.msvc
    polly/trunk/lib/External/isl/imath/contrib/README
    polly/trunk/lib/External/isl/imath/divide.txt
    polly/trunk/lib/External/isl/imath/doc.txt
    polly/trunk/lib/External/isl/imath/examples/
    polly/trunk/lib/External/isl/imath/examples/basecvt.c
    polly/trunk/lib/External/isl/imath/examples/findprime.c
    polly/trunk/lib/External/isl/imath/examples/imcalc.c
    polly/trunk/lib/External/isl/imath/examples/input.c
    polly/trunk/lib/External/isl/imath/examples/randprime.c
    polly/trunk/lib/External/isl/imath/examples/rounding.c
    polly/trunk/lib/External/isl/imath/examples/rsakey.c
    polly/trunk/lib/External/isl/imath/findsizes.py   (with props)
    polly/trunk/lib/External/isl/imath/findthreshold.py   (with props)
    polly/trunk/lib/External/isl/imath/gmp_compat.c
    polly/trunk/lib/External/isl/imath/gmp_compat.h
    polly/trunk/lib/External/isl/imath/imath.c
    polly/trunk/lib/External/isl/imath/imath.h
    polly/trunk/lib/External/isl/imath/imdrover.c
    polly/trunk/lib/External/isl/imath/imdrover.h
    polly/trunk/lib/External/isl/imath/imrat.c
    polly/trunk/lib/External/isl/imath/imrat.h
    polly/trunk/lib/External/isl/imath/imtest.c
    polly/trunk/lib/External/isl/imath/imtimer.c
    polly/trunk/lib/External/isl/imath/iprime.c
    polly/trunk/lib/External/isl/imath/iprime.h
    polly/trunk/lib/External/isl/imath/pi.c
    polly/trunk/lib/External/isl/imath/rsamath.c
    polly/trunk/lib/External/isl/imath/rsamath.h
    polly/trunk/lib/External/isl/imath/rtest.c
    polly/trunk/lib/External/isl/imath/tests/
    polly/trunk/lib/External/isl/imath/tests/add.t
    polly/trunk/lib/External/isl/imath/tests/bigmul.t
    polly/trunk/lib/External/isl/imath/tests/bigsqr.t
    polly/trunk/lib/External/isl/imath/tests/compare.t
    polly/trunk/lib/External/isl/imath/tests/conv.t
    polly/trunk/lib/External/isl/imath/tests/div.t
    polly/trunk/lib/External/isl/imath/tests/egcd.t
    polly/trunk/lib/External/isl/imath/tests/emod.t
    polly/trunk/lib/External/isl/imath/tests/emodv.t
    polly/trunk/lib/External/isl/imath/tests/expt.t
    polly/trunk/lib/External/isl/imath/tests/gcd.t
    polly/trunk/lib/External/isl/imath/tests/gmp-compat-test/
    polly/trunk/lib/External/isl/imath/tests/gmp-compat-test/.gitignore
    polly/trunk/lib/External/isl/imath/tests/gmp-compat-test/README
    polly/trunk/lib/External/isl/imath/tests/gmp-compat-test/genctest.py   (with props)
    polly/trunk/lib/External/isl/imath/tests/gmp-compat-test/gendata.py   (with props)
    polly/trunk/lib/External/isl/imath/tests/gmp-compat-test/genpytest.py   (with props)
    polly/trunk/lib/External/isl/imath/tests/gmp-compat-test/gmp_custom_test.c
    polly/trunk/lib/External/isl/imath/tests/gmp-compat-test/gmpapi.py
    polly/trunk/lib/External/isl/imath/tests/gmp-compat-test/imath_custom_test.c
    polly/trunk/lib/External/isl/imath/tests/gmp-compat-test/runtest   (with props)
    polly/trunk/lib/External/isl/imath/tests/gmp-compat-test/runtest.py   (with props)
    polly/trunk/lib/External/isl/imath/tests/init.t
    polly/trunk/lib/External/isl/imath/tests/invmod.t
    polly/trunk/lib/External/isl/imath/tests/lcm.t
    polly/trunk/lib/External/isl/imath/tests/mod.t
    polly/trunk/lib/External/isl/imath/tests/mul.t
    polly/trunk/lib/External/isl/imath/tests/neg.t
    polly/trunk/lib/External/isl/imath/tests/pi1024.txt
    polly/trunk/lib/External/isl/imath/tests/pi1500-10.txt
    polly/trunk/lib/External/isl/imath/tests/pi1698-16.txt
    polly/trunk/lib/External/isl/imath/tests/qadd.t
    polly/trunk/lib/External/isl/imath/tests/qaddz.t
    polly/trunk/lib/External/isl/imath/tests/qdiv.t
    polly/trunk/lib/External/isl/imath/tests/qdivz.t
    polly/trunk/lib/External/isl/imath/tests/qmisc.t
    polly/trunk/lib/External/isl/imath/tests/qmul.t
    polly/trunk/lib/External/isl/imath/tests/qmulz.t
    polly/trunk/lib/External/isl/imath/tests/qsub.t
    polly/trunk/lib/External/isl/imath/tests/qsubz.t
    polly/trunk/lib/External/isl/imath/tests/qtodec.t
    polly/trunk/lib/External/isl/imath/tests/root.t
    polly/trunk/lib/External/isl/imath/tests/set.t
    polly/trunk/lib/External/isl/imath/tests/sqr.t
    polly/trunk/lib/External/isl/imath/tests/sub.t
    polly/trunk/lib/External/isl/imath/tests/test.bc
    polly/trunk/lib/External/isl/imath/tests/test.sh   (with props)
    polly/trunk/lib/External/isl/imath_wrap/
    polly/trunk/lib/External/isl/imath_wrap/gmp_compat.c
    polly/trunk/lib/External/isl/imath_wrap/gmp_compat.h
    polly/trunk/lib/External/isl/imath_wrap/imath.c
    polly/trunk/lib/External/isl/imath_wrap/imath.h
    polly/trunk/lib/External/isl/imath_wrap/imrat.c
    polly/trunk/lib/External/isl/imath_wrap/imrat.h
    polly/trunk/lib/External/isl/imath_wrap/wrap.h
    polly/trunk/lib/External/isl/include/
    polly/trunk/lib/External/isl/include/isl/
    polly/trunk/lib/External/isl/include/isl/aff.h
    polly/trunk/lib/External/isl/include/isl/aff_type.h
    polly/trunk/lib/External/isl/include/isl/arg.h
    polly/trunk/lib/External/isl/include/isl/ast.h
    polly/trunk/lib/External/isl/include/isl/ast_build.h
    polly/trunk/lib/External/isl/include/isl/ast_type.h
    polly/trunk/lib/External/isl/include/isl/band.h
    polly/trunk/lib/External/isl/include/isl/constraint.h
    polly/trunk/lib/External/isl/include/isl/ctx.h
    polly/trunk/lib/External/isl/include/isl/deprecated/
    polly/trunk/lib/External/isl/include/isl/deprecated/aff_int.h
    polly/trunk/lib/External/isl/include/isl/deprecated/ast_int.h
    polly/trunk/lib/External/isl/include/isl/deprecated/constraint_int.h
    polly/trunk/lib/External/isl/include/isl/deprecated/ilp_int.h
    polly/trunk/lib/External/isl/include/isl/deprecated/int.h
    polly/trunk/lib/External/isl/include/isl/deprecated/map_int.h
    polly/trunk/lib/External/isl/include/isl/deprecated/mat_int.h
    polly/trunk/lib/External/isl/include/isl/deprecated/point_int.h
    polly/trunk/lib/External/isl/include/isl/deprecated/polynomial_int.h
    polly/trunk/lib/External/isl/include/isl/deprecated/set_int.h
    polly/trunk/lib/External/isl/include/isl/deprecated/union_map_int.h
    polly/trunk/lib/External/isl/include/isl/deprecated/val_int.h
    polly/trunk/lib/External/isl/include/isl/deprecated/vec_int.h
    polly/trunk/lib/External/isl/include/isl/dim.h
    polly/trunk/lib/External/isl/include/isl/flow.h
    polly/trunk/lib/External/isl/include/isl/hash.h
    polly/trunk/lib/External/isl/include/isl/hmap.h
    polly/trunk/lib/External/isl/include/isl/id.h
    polly/trunk/lib/External/isl/include/isl/id_to_ast_expr.h
    polly/trunk/lib/External/isl/include/isl/id_to_pw_aff.h
    polly/trunk/lib/External/isl/include/isl/ilp.h
    polly/trunk/lib/External/isl/include/isl/list.h
    polly/trunk/lib/External/isl/include/isl/local_space.h
    polly/trunk/lib/External/isl/include/isl/lp.h
    polly/trunk/lib/External/isl/include/isl/map.h
    polly/trunk/lib/External/isl/include/isl/map_to_basic_set.h
    polly/trunk/lib/External/isl/include/isl/map_type.h
    polly/trunk/lib/External/isl/include/isl/mat.h
    polly/trunk/lib/External/isl/include/isl/multi.h
    polly/trunk/lib/External/isl/include/isl/obj.h
    polly/trunk/lib/External/isl/include/isl/options.h
    polly/trunk/lib/External/isl/include/isl/point.h
    polly/trunk/lib/External/isl/include/isl/polynomial.h
    polly/trunk/lib/External/isl/include/isl/polynomial_type.h
    polly/trunk/lib/External/isl/include/isl/printer.h
    polly/trunk/lib/External/isl/include/isl/schedule.h
    polly/trunk/lib/External/isl/include/isl/set.h
    polly/trunk/lib/External/isl/include/isl/set_type.h
    polly/trunk/lib/External/isl/include/isl/space.h
    polly/trunk/lib/External/isl/include/isl/stream.h
    polly/trunk/lib/External/isl/include/isl/union_map.h
    polly/trunk/lib/External/isl/include/isl/union_map_type.h
    polly/trunk/lib/External/isl/include/isl/union_set.h
    polly/trunk/lib/External/isl/include/isl/union_set_type.h
    polly/trunk/lib/External/isl/include/isl/val.h
    polly/trunk/lib/External/isl/include/isl/val_gmp.h
    polly/trunk/lib/External/isl/include/isl/vec.h
    polly/trunk/lib/External/isl/include/isl/version.h
    polly/trunk/lib/External/isl/include/isl/vertices.h
    polly/trunk/lib/External/isl/interface/
    polly/trunk/lib/External/isl/interface/Makefile.am
    polly/trunk/lib/External/isl/interface/all.h
    polly/trunk/lib/External/isl/interface/extract_interface.cc
    polly/trunk/lib/External/isl/interface/extract_interface.h
    polly/trunk/lib/External/isl/interface/isl.py.top
    polly/trunk/lib/External/isl/interface/python.cc
    polly/trunk/lib/External/isl/interface/python.h
    polly/trunk/lib/External/isl/isl.py
    polly/trunk/lib/External/isl/isl_aff.c
    polly/trunk/lib/External/isl/isl_aff_private.h
    polly/trunk/lib/External/isl/isl_affine_hull.c
    polly/trunk/lib/External/isl/isl_arg.c
    polly/trunk/lib/External/isl/isl_ast.c
    polly/trunk/lib/External/isl/isl_ast_build.c
    polly/trunk/lib/External/isl/isl_ast_build_expr.c
    polly/trunk/lib/External/isl/isl_ast_build_expr.h
    polly/trunk/lib/External/isl/isl_ast_build_private.h
    polly/trunk/lib/External/isl/isl_ast_codegen.c
    polly/trunk/lib/External/isl/isl_ast_graft.c
    polly/trunk/lib/External/isl/isl_ast_graft_private.h
    polly/trunk/lib/External/isl/isl_ast_int.c
    polly/trunk/lib/External/isl/isl_ast_private.h
    polly/trunk/lib/External/isl/isl_band.c
    polly/trunk/lib/External/isl/isl_band_private.h
    polly/trunk/lib/External/isl/isl_basis_reduction.h
    polly/trunk/lib/External/isl/isl_bernstein.c
    polly/trunk/lib/External/isl/isl_bernstein.h
    polly/trunk/lib/External/isl/isl_blk.c
    polly/trunk/lib/External/isl/isl_blk.h
    polly/trunk/lib/External/isl/isl_bound.c
    polly/trunk/lib/External/isl/isl_bound.h
    polly/trunk/lib/External/isl/isl_coalesce.c
    polly/trunk/lib/External/isl/isl_config.h
    polly/trunk/lib/External/isl/isl_config_post.h
    polly/trunk/lib/External/isl/isl_constraint.c
    polly/trunk/lib/External/isl/isl_constraint_private.h
    polly/trunk/lib/External/isl/isl_convex_hull.c
    polly/trunk/lib/External/isl/isl_ctx.c
    polly/trunk/lib/External/isl/isl_ctx_private.h
    polly/trunk/lib/External/isl/isl_deprecated.c
    polly/trunk/lib/External/isl/isl_dim.c
    polly/trunk/lib/External/isl/isl_dim_map.c
    polly/trunk/lib/External/isl/isl_dim_map.h
    polly/trunk/lib/External/isl/isl_equalities.c
    polly/trunk/lib/External/isl/isl_equalities.h
    polly/trunk/lib/External/isl/isl_factorization.c
    polly/trunk/lib/External/isl/isl_factorization.h
    polly/trunk/lib/External/isl/isl_farkas.c
    polly/trunk/lib/External/isl/isl_flow.c
    polly/trunk/lib/External/isl/isl_fold.c
    polly/trunk/lib/External/isl/isl_gmp.c
    polly/trunk/lib/External/isl/isl_hash.c
    polly/trunk/lib/External/isl/isl_hide_deprecated.h
    polly/trunk/lib/External/isl/isl_hmap_templ.c
    polly/trunk/lib/External/isl/isl_id.c
    polly/trunk/lib/External/isl/isl_id_private.h
    polly/trunk/lib/External/isl/isl_id_to_ast_expr.c
    polly/trunk/lib/External/isl/isl_id_to_pw_aff.c
    polly/trunk/lib/External/isl/isl_ilp.c
    polly/trunk/lib/External/isl/isl_ilp_private.h
    polly/trunk/lib/External/isl/isl_imath.c
    polly/trunk/lib/External/isl/isl_imath.h
    polly/trunk/lib/External/isl/isl_input.c
    polly/trunk/lib/External/isl/isl_int.h
    polly/trunk/lib/External/isl/isl_int_gmp.h
    polly/trunk/lib/External/isl/isl_int_imath.h
    polly/trunk/lib/External/isl/isl_list_templ.c
    polly/trunk/lib/External/isl/isl_list_templ.h
    polly/trunk/lib/External/isl/isl_local_space.c
    polly/trunk/lib/External/isl/isl_local_space_private.h
    polly/trunk/lib/External/isl/isl_lp.c
    polly/trunk/lib/External/isl/isl_lp_private.h
    polly/trunk/lib/External/isl/isl_map.c
    polly/trunk/lib/External/isl/isl_map_lexopt_templ.c
    polly/trunk/lib/External/isl/isl_map_private.h
    polly/trunk/lib/External/isl/isl_map_simplify.c
    polly/trunk/lib/External/isl/isl_map_subtract.c
    polly/trunk/lib/External/isl/isl_map_to_basic_set.c
    polly/trunk/lib/External/isl/isl_mat.c
    polly/trunk/lib/External/isl/isl_mat_private.h
    polly/trunk/lib/External/isl/isl_morph.c
    polly/trunk/lib/External/isl/isl_morph.h
    polly/trunk/lib/External/isl/isl_multi_templ.c
    polly/trunk/lib/External/isl/isl_multi_templ.h
    polly/trunk/lib/External/isl/isl_obj.c
    polly/trunk/lib/External/isl/isl_options.c
    polly/trunk/lib/External/isl/isl_options_private.h
    polly/trunk/lib/External/isl/isl_output.c
    polly/trunk/lib/External/isl/isl_point.c
    polly/trunk/lib/External/isl/isl_point_private.h
    polly/trunk/lib/External/isl/isl_polynomial.c
    polly/trunk/lib/External/isl/isl_polynomial_private.h
    polly/trunk/lib/External/isl/isl_power_templ.c
    polly/trunk/lib/External/isl/isl_printer.c
    polly/trunk/lib/External/isl/isl_printer_private.h
    polly/trunk/lib/External/isl/isl_pw_templ.c
    polly/trunk/lib/External/isl/isl_range.c
    polly/trunk/lib/External/isl/isl_range.h
    polly/trunk/lib/External/isl/isl_reordering.c
    polly/trunk/lib/External/isl/isl_reordering.h
    polly/trunk/lib/External/isl/isl_sample.c
    polly/trunk/lib/External/isl/isl_sample.h
    polly/trunk/lib/External/isl/isl_scan.c
    polly/trunk/lib/External/isl/isl_scan.h
    polly/trunk/lib/External/isl/isl_schedule.c
    polly/trunk/lib/External/isl/isl_schedule_private.h
    polly/trunk/lib/External/isl/isl_scheduler.c
    polly/trunk/lib/External/isl/isl_seq.c
    polly/trunk/lib/External/isl/isl_seq.h
    polly/trunk/lib/External/isl/isl_set_list.c
    polly/trunk/lib/External/isl/isl_sort.c
    polly/trunk/lib/External/isl/isl_sort.h
    polly/trunk/lib/External/isl/isl_space.c
    polly/trunk/lib/External/isl/isl_space_private.h
    polly/trunk/lib/External/isl/isl_stream.c
    polly/trunk/lib/External/isl/isl_stream_private.h
    polly/trunk/lib/External/isl/isl_tab.c
    polly/trunk/lib/External/isl/isl_tab.h
    polly/trunk/lib/External/isl/isl_tab_pip.c
    polly/trunk/lib/External/isl/isl_tarjan.c
    polly/trunk/lib/External/isl/isl_tarjan.h
    polly/trunk/lib/External/isl/isl_test.c
    polly/trunk/lib/External/isl/isl_transitive_closure.c
    polly/trunk/lib/External/isl/isl_union_map.c
    polly/trunk/lib/External/isl/isl_union_map_private.h
    polly/trunk/lib/External/isl/isl_union_templ.c
    polly/trunk/lib/External/isl/isl_val.c
    polly/trunk/lib/External/isl/isl_val_gmp.c
    polly/trunk/lib/External/isl/isl_val_imath.c
    polly/trunk/lib/External/isl/isl_val_private.h
    polly/trunk/lib/External/isl/isl_vec.c
    polly/trunk/lib/External/isl/isl_vec_private.h
    polly/trunk/lib/External/isl/isl_version.c
    polly/trunk/lib/External/isl/isl_vertices.c
    polly/trunk/lib/External/isl/isl_vertices_private.h
    polly/trunk/lib/External/isl/m4/
    polly/trunk/lib/External/isl/m4/ax_c___attribute__.m4
    polly/trunk/lib/External/isl/m4/ax_cc_maxopt.m4
    polly/trunk/lib/External/isl/m4/ax_cflags_warn_all.m4
    polly/trunk/lib/External/isl/m4/ax_check_compiler_flags.m4
    polly/trunk/lib/External/isl/m4/ax_compiler_vendor.m4
    polly/trunk/lib/External/isl/m4/ax_create_pkgconfig_info.m4
    polly/trunk/lib/External/isl/m4/ax_create_stdint_h.m4
    polly/trunk/lib/External/isl/m4/ax_detect_git_head.m4
    polly/trunk/lib/External/isl/m4/ax_detect_gmp.m4
    polly/trunk/lib/External/isl/m4/ax_detect_imath.m4
    polly/trunk/lib/External/isl/m4/ax_gcc_archflag.m4
    polly/trunk/lib/External/isl/m4/ax_gcc_warn_unused_result.m4
    polly/trunk/lib/External/isl/m4/ax_gcc_x86_cpuid.m4
    polly/trunk/lib/External/isl/m4/ax_set_warning_flags.m4
    polly/trunk/lib/External/isl/m4/ax_submodule.m4
    polly/trunk/lib/External/isl/mp_get_memory_functions.c
    polly/trunk/lib/External/isl/pip.c
    polly/trunk/lib/External/isl/pip_test.sh.in   (with props)
    polly/trunk/lib/External/isl/polyhedron_detect_equalities.c
    polly/trunk/lib/External/isl/polyhedron_minimize.c
    polly/trunk/lib/External/isl/polyhedron_sample.c
    polly/trunk/lib/External/isl/polytope_scan.c
    polly/trunk/lib/External/isl/print.c
    polly/trunk/lib/External/isl/print_templ.c
    polly/trunk/lib/External/isl/test_inputs/
    polly/trunk/lib/External/isl/test_inputs/affine.polylib
    polly/trunk/lib/External/isl/test_inputs/affine2.polylib
    polly/trunk/lib/External/isl/test_inputs/affine3.polylib
    polly/trunk/lib/External/isl/test_inputs/application.omega
    polly/trunk/lib/External/isl/test_inputs/application2.omega
    polly/trunk/lib/External/isl/test_inputs/basicLinear.pwqp
    polly/trunk/lib/External/isl/test_inputs/basicLinear2.pwqp
    polly/trunk/lib/External/isl/test_inputs/basicTest.pwqp
    polly/trunk/lib/External/isl/test_inputs/basicTestParameterPosNeg.pwqp
    polly/trunk/lib/External/isl/test_inputs/boulet.pip
    polly/trunk/lib/External/isl/test_inputs/brisebarre.pip
    polly/trunk/lib/External/isl/test_inputs/cg1.pip
    polly/trunk/lib/External/isl/test_inputs/codegen/
    polly/trunk/lib/External/isl/test_inputs/codegen/atomic.c
    polly/trunk/lib/External/isl/test_inputs/codegen/atomic.in
    polly/trunk/lib/External/isl/test_inputs/codegen/atomic2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/atomic2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/atomic3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/atomic3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/atomic4.c
    polly/trunk/lib/External/isl/test_inputs/codegen/atomic4.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/0D-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/0D-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/0D-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/0D-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/0D-3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/0D-3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/1point-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/1point-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/1point-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/1point-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/4-param.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/4-param.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/README
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/backtrack.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/backtrack.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/basic-bounds-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/basic-bounds-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/basic-bounds-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/basic-bounds-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/basic-bounds-3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/basic-bounds-3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/basic-bounds-4.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/basic-bounds-4.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/basic-bounds-5.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/basic-bounds-5.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/block.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/block.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/block2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/block2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/block3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/block3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/byu98-1-2-3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/byu98-1-2-3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/cholesky.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/cholesky.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/cholesky2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/cholesky2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/christian.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/christian.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/classen.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/classen.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/classen2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/classen2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/constant.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/constant.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/constbound.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/constbound.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/darte.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/darte.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/dealII.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/dealII.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/donotsimp.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/donotsimp.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/dot.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/dot.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/dot2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/dot2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/durbin_e_s.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/durbin_e_s.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/emploi.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/emploi.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/equality.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/equality.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/equality2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/equality2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/esced.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/esced.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/ex1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/ex1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/faber.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/faber.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/forwardsub-1-1-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/forwardsub-1-1-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/forwardsub-2-1-2-3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/forwardsub-2-1-2-3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/forwardsub-3-1-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/forwardsub-3-1-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/gauss.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/gauss.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/gesced.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/gesced.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/gesced2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/gesced2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/gesced3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/gesced3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/guide.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/guide.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/iftest.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/iftest.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/iftest2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/iftest2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/infinite2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/infinite2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/jacobi-shared.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/jacobi-shared.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/largeur.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/largeur.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/levenshtein-1-2-3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/levenshtein-1-2-3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/lex.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/lex.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/lineality-1-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/lineality-1-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/lineality-2-1-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/lineality-2-1-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/logo.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/logo.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/logopar.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/logopar.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/lu.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/lu.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/lu2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/lu2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/lux.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/lux.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/merge.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/merge.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/min-1-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/min-1-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/min-2-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/min-2-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/min-3-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/min-3-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/min-4-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/min-4-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/mod.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/mod.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/mod2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/mod2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/mod3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/mod3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/mod4.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/mod4.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/mode.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/mode.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/multi-mm-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/multi-mm-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/multi-stride.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/multi-stride.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/multi-stride2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/multi-stride2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/mxm-shared.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/mxm-shared.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/no_lindep.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/no_lindep.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/nul_basic1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/nul_basic1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/nul_basic2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/nul_basic2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/nul_complex1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/nul_complex1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/nul_lcpc.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/nul_lcpc.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/orc.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/orc.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/otl.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/otl.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/param-split.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/param-split.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/pouchet.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/pouchet.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/rectangle.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/rectangle.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-QR.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-QR.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-bastoul3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-bastoul3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-cholesky2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-cholesky2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-fusion1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-fusion1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-fusion2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-fusion2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-jacobi2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-jacobi2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-jacobi3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-jacobi3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-lim-lam1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-lim-lam1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-lim-lam2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-lim-lam2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-lim-lam3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-lim-lam3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-lim-lam4.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-lim-lam4.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-lim-lam5.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-lim-lam5.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-lim-lam6.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-lim-lam6.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-liu-zhuge1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-liu-zhuge1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-loechner3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-loechner3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-loechner4.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-loechner4.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-loechner5.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-loechner5.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-mg-interp.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-mg-interp.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-mg-interp2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-mg-interp2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-mg-psinv.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-mg-psinv.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-mg-resid.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-mg-resid.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-mg-rprj3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-mg-rprj3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-pingali1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-pingali1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-pingali2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-pingali2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-pingali3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-pingali3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-pingali4.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-pingali4.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-pingali5.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-pingali5.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-pingali6.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-pingali6.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-stride.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-stride.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-stride2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-stride2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-tang-xue1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-tang-xue1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-two.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/reservoir-two.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/singleton.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/singleton.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/square+triangle-1-1-2-3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/square+triangle-1-1-2-3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/stride.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/stride.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/stride2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/stride2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/stride3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/stride3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/stride4.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/stride4.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/swim.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/swim.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/test.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/test.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/thomasset.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/thomasset.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/tiling.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/tiling.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/uday_scalars.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/uday_scalars.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/union.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/union.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/unroll.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/unroll.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/unroll2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/unroll2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/usvd_e_t.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/usvd_e_t.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/vasilache.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/vasilache.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/vivien.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/vivien.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/vivien2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/vivien2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/walters.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/walters.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/walters2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/walters2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/walters3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/walters3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/wavefront.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/wavefront.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/yosr.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/yosr.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/yosr2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/yosr2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/youcef.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/youcef.in
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/youcefn.c
    polly/trunk/lib/External/isl/test_inputs/codegen/cloog/youcefn.in
    polly/trunk/lib/External/isl/test_inputs/codegen/disjuncts.c
    polly/trunk/lib/External/isl/test_inputs/codegen/disjuncts.in
    polly/trunk/lib/External/isl/test_inputs/codegen/dwt.c
    polly/trunk/lib/External/isl/test_inputs/codegen/dwt.in
    polly/trunk/lib/External/isl/test_inputs/codegen/empty.c
    polly/trunk/lib/External/isl/test_inputs/codegen/empty.in
    polly/trunk/lib/External/isl/test_inputs/codegen/hoist.c
    polly/trunk/lib/External/isl/test_inputs/codegen/hoist.in
    polly/trunk/lib/External/isl/test_inputs/codegen/hoist2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/hoist2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/lu.c
    polly/trunk/lib/External/isl/test_inputs/codegen/lu.in
    polly/trunk/lib/External/isl/test_inputs/codegen/mod.c
    polly/trunk/lib/External/isl/test_inputs/codegen/mod.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/README
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/basics-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/basics-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/basics-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/basics-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/chosol-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/chosol-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/chosol-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/chosol-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/code_gen-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/code_gen-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/code_gen-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/code_gen-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/code_gen-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/code_gen-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/collard-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/collard-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/dagstuhl1-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/dagstuhl1-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/dagstuhl1-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/dagstuhl1-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/fc1-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/fc1-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/fc1-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/fc1-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/fc1-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/fc1-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/fc2-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/fc2-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/fc2-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/fc2-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/floor_bound-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/floor_bound-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/floor_bound-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/floor_bound-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/floor_bound-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/floor_bound-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/floor_bound-3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/floor_bound-3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/floor_bound-4.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/floor_bound-4.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/floor_bound-5.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/floor_bound-5.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/floor_bound-6.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/floor_bound-6.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/gc-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/gc-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/ge-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/ge-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/ge-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/ge-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/gist-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/gist-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/gist-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/gist-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/gist-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/gist-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/gist-3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/gist-3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/gist-4.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/gist-4.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/gist-5.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/gist-5.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/guard1-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/guard1-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/guard1-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/guard1-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/hpf-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/hpf-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/if_then-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/if_then-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/if_then-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/if_then-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/if_then-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/if_then-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/if_then-3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/if_then-3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/if_then-4.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/if_then-4.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/if_then-5.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/if_then-5.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter1-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter1-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter2-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter2-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter3-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter3-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter4-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter4-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter5-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter5-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter6-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter6-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter6-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter6-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter7-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter7-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter8-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter8-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter9-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/iter9-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lefur00-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lefur00-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lefur01-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lefur01-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lefur01-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lefur01-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lefur03-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lefur03-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lefur04-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lefur04-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift1-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift1-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift1-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift1-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift1-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift1-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift1-3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift1-3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift1-4.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift1-4.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift1-5.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift1-5.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift2-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift2-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift2-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift2-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift2-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift2-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift2-3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift2-3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift2-4.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift2-4.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift2-5.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lift2-5.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu-3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu-3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu_ijk-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu_ijk-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu_ijk-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu_ijk-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu_ijk-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu_ijk-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu_spmd-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu_spmd-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu_spmd-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/lu_spmd-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m1-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m1-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m1-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m1-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m10-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m10-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m10-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m10-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m11-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m11-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m12-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m12-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m12-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m12-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m2-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m2-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m2-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m2-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m3-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m3-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m4-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m4-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m4-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m4-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m7-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m7-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m7-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m7-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m8-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m8-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m8-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m8-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m9-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m9-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m9-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/m9-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/olda-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/olda-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/olda-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/olda-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/p.delft-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/p.delft-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/p.delft2-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/p.delft2-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/p6-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/p6-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/p6-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/p6-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride1-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride1-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride2-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride2-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride3-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride3-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride4-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride4-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride5-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride5-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride6-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride6-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride6-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride6-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride6-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride6-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride7-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride7-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride7-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/stride7-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/substitution-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/substitution-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/substitution-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/substitution-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/substitution-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/substitution-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/substitution-3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/substitution-3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/substitution-4.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/substitution-4.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/syr2k-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/syr2k-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/syr2k-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/syr2k-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/syr2k-2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/syr2k-2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/syr2k-3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/syr2k-3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/ts1d-check-sblock-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/ts1d-check-sblock-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/ts1d-check0-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/ts1d-check0-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/ts1d-mp-i_ts-m_b-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/ts1d-mp-i_ts-m_b-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/ts1d-orig0-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/ts1d-orig0-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/wak1-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/wak1-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/wak1-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/wak1-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/wak2-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/wak2-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/wak2-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/wak2-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/wak3-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/wak3-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/wak3-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/wak3-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/wak4-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/wak4-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/wak4-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/wak4-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/x-0.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/x-0.in
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/x-1.c
    polly/trunk/lib/External/isl/test_inputs/codegen/omega/x-1.in
    polly/trunk/lib/External/isl/test_inputs/codegen/pldi2012/
    polly/trunk/lib/External/isl/test_inputs/codegen/pldi2012/README
    polly/trunk/lib/External/isl/test_inputs/codegen/pldi2012/figure7_b.c
    polly/trunk/lib/External/isl/test_inputs/codegen/pldi2012/figure7_b.in
    polly/trunk/lib/External/isl/test_inputs/codegen/pldi2012/figure7_c.c
    polly/trunk/lib/External/isl/test_inputs/codegen/pldi2012/figure7_c.in
    polly/trunk/lib/External/isl/test_inputs/codegen/pldi2012/figure7_d.c
    polly/trunk/lib/External/isl/test_inputs/codegen/pldi2012/figure7_d.in
    polly/trunk/lib/External/isl/test_inputs/codegen/pldi2012/figure8_a.c
    polly/trunk/lib/External/isl/test_inputs/codegen/pldi2012/figure8_a.in
    polly/trunk/lib/External/isl/test_inputs/codegen/pldi2012/figure8_b.c
    polly/trunk/lib/External/isl/test_inputs/codegen/pldi2012/figure8_b.in
    polly/trunk/lib/External/isl/test_inputs/codegen/roman.c
    polly/trunk/lib/External/isl/test_inputs/codegen/roman.in
    polly/trunk/lib/External/isl/test_inputs/codegen/separate.c
    polly/trunk/lib/External/isl/test_inputs/codegen/separate.in
    polly/trunk/lib/External/isl/test_inputs/codegen/separate2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/separate2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/separation_class.c
    polly/trunk/lib/External/isl/test_inputs/codegen/separation_class.in
    polly/trunk/lib/External/isl/test_inputs/codegen/separation_class2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/separation_class2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/separation_class3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/separation_class3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/separation_class4.c
    polly/trunk/lib/External/isl/test_inputs/codegen/separation_class4.in
    polly/trunk/lib/External/isl/test_inputs/codegen/shift.c
    polly/trunk/lib/External/isl/test_inputs/codegen/shift.in
    polly/trunk/lib/External/isl/test_inputs/codegen/shift2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/shift2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/shift_unroll.c
    polly/trunk/lib/External/isl/test_inputs/codegen/shift_unroll.in
    polly/trunk/lib/External/isl/test_inputs/codegen/single_valued.c
    polly/trunk/lib/External/isl/test_inputs/codegen/single_valued.in
    polly/trunk/lib/External/isl/test_inputs/codegen/stride.c
    polly/trunk/lib/External/isl/test_inputs/codegen/stride.in
    polly/trunk/lib/External/isl/test_inputs/codegen/stride5.c
    polly/trunk/lib/External/isl/test_inputs/codegen/stride5.in
    polly/trunk/lib/External/isl/test_inputs/codegen/stride6.c
    polly/trunk/lib/External/isl/test_inputs/codegen/stride6.in
    polly/trunk/lib/External/isl/test_inputs/codegen/stride7.c
    polly/trunk/lib/External/isl/test_inputs/codegen/stride7.in
    polly/trunk/lib/External/isl/test_inputs/codegen/unroll.c
    polly/trunk/lib/External/isl/test_inputs/codegen/unroll.in
    polly/trunk/lib/External/isl/test_inputs/codegen/unroll10.c
    polly/trunk/lib/External/isl/test_inputs/codegen/unroll10.in
    polly/trunk/lib/External/isl/test_inputs/codegen/unroll2.c
    polly/trunk/lib/External/isl/test_inputs/codegen/unroll2.in
    polly/trunk/lib/External/isl/test_inputs/codegen/unroll3.c
    polly/trunk/lib/External/isl/test_inputs/codegen/unroll3.in
    polly/trunk/lib/External/isl/test_inputs/codegen/unroll4.c
    polly/trunk/lib/External/isl/test_inputs/codegen/unroll4.in
    polly/trunk/lib/External/isl/test_inputs/codegen/unroll6.c
    polly/trunk/lib/External/isl/test_inputs/codegen/unroll6.in
    polly/trunk/lib/External/isl/test_inputs/codegen/unroll7.c
    polly/trunk/lib/External/isl/test_inputs/codegen/unroll7.in
    polly/trunk/lib/External/isl/test_inputs/convex0.polylib
    polly/trunk/lib/External/isl/test_inputs/convex1.polylib
    polly/trunk/lib/External/isl/test_inputs/convex10.polylib
    polly/trunk/lib/External/isl/test_inputs/convex11.polylib
    polly/trunk/lib/External/isl/test_inputs/convex12.polylib
    polly/trunk/lib/External/isl/test_inputs/convex13.polylib
    polly/trunk/lib/External/isl/test_inputs/convex14.polylib
    polly/trunk/lib/External/isl/test_inputs/convex15.polylib
    polly/trunk/lib/External/isl/test_inputs/convex2.polylib
    polly/trunk/lib/External/isl/test_inputs/convex3.polylib
    polly/trunk/lib/External/isl/test_inputs/convex4.polylib
    polly/trunk/lib/External/isl/test_inputs/convex5.polylib
    polly/trunk/lib/External/isl/test_inputs/convex6.polylib
    polly/trunk/lib/External/isl/test_inputs/convex7.polylib
    polly/trunk/lib/External/isl/test_inputs/convex8.polylib
    polly/trunk/lib/External/isl/test_inputs/convex9.polylib
    polly/trunk/lib/External/isl/test_inputs/devos.pwqp
    polly/trunk/lib/External/isl/test_inputs/equality1.pwqp
    polly/trunk/lib/External/isl/test_inputs/equality2.pwqp
    polly/trunk/lib/External/isl/test_inputs/equality3.pwqp
    polly/trunk/lib/External/isl/test_inputs/equality4.pwqp
    polly/trunk/lib/External/isl/test_inputs/equality5.pwqp
    polly/trunk/lib/External/isl/test_inputs/esced.pip
    polly/trunk/lib/External/isl/test_inputs/ex.pip
    polly/trunk/lib/External/isl/test_inputs/ex2.pip
    polly/trunk/lib/External/isl/test_inputs/faddeev.pwqp
    polly/trunk/lib/External/isl/test_inputs/fimmel.pip
    polly/trunk/lib/External/isl/test_inputs/gist1.polylib
    polly/trunk/lib/External/isl/test_inputs/linearExample.pwqp
    polly/trunk/lib/External/isl/test_inputs/max.pip
    polly/trunk/lib/External/isl/test_inputs/neg.pwqp
    polly/trunk/lib/External/isl/test_inputs/negative.pip
    polly/trunk/lib/External/isl/test_inputs/philippe.pwqp
    polly/trunk/lib/External/isl/test_inputs/philippe3vars.pwqp
    polly/trunk/lib/External/isl/test_inputs/philippe3vars3pars.pwqp
    polly/trunk/lib/External/isl/test_inputs/philippeNeg.pwqp
    polly/trunk/lib/External/isl/test_inputs/philippePolynomialCoeff.pwqp
    polly/trunk/lib/External/isl/test_inputs/philippePolynomialCoeff1P.pwqp
    polly/trunk/lib/External/isl/test_inputs/product.pwqp
    polly/trunk/lib/External/isl/test_inputs/seghir-vd.pip
    polly/trunk/lib/External/isl/test_inputs/set.omega
    polly/trunk/lib/External/isl/test_inputs/small.pip
    polly/trunk/lib/External/isl/test_inputs/sor1d.pip
    polly/trunk/lib/External/isl/test_inputs/split.pwqp
    polly/trunk/lib/External/isl/test_inputs/square.pip
    polly/trunk/lib/External/isl/test_inputs/sven.pip
    polly/trunk/lib/External/isl/test_inputs/test3Deg3Var.pwqp
    polly/trunk/lib/External/isl/test_inputs/tobi.pip
    polly/trunk/lib/External/isl/test_inputs/toplas.pwqp
    polly/trunk/lib/External/isl/test_inputs/unexpanded.pwqp
Removed:
    polly/trunk/cmake/FindGmp.cmake
    polly/trunk/cmake/FindIsl.cmake
Modified:
    polly/trunk/CMakeLists.txt
    polly/trunk/Makefile.config.in
    polly/trunk/autoconf/aclocal.m4
    polly/trunk/autoconf/configure.ac
    polly/trunk/configure
    polly/trunk/lib/CMakeLists.txt
    polly/trunk/lib/Makefile

Modified: polly/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/CMakeLists.txt?rev=228193&r1=228192&r2=228193&view=diff
==============================================================================
--- polly/trunk/CMakeLists.txt (original)
+++ polly/trunk/CMakeLists.txt Wed Feb  4 14:55:43 2015
@@ -76,23 +76,29 @@ endif ()
 
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
 
+# Define the FLAGS for the compilation of isl and imath
+#
+# Those are the only C files we have in the repository. Hence, we can just use
+# the CFLAGS to identify them.
+#
+# We first set the visibility of all isl functions to hidden to ensure we do
+# not clash with other isl versions that got linked into a program that uses
+# Polly. (This happens e.g when linking Polly with dragonegg)
+#
+# We also disable all warnings, as these should be fixed upstream. There is
+# no value in reporting them here.
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -w")
+
 # Add path for custom modules
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${POLLY_SOURCE_DIR}/cmake")
 
 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
 
-FIND_PACKAGE(Isl REQUIRED)
-set(POLLY_LINK_LIBS ${ISL_LIBRARY})
-
 FIND_PACKAGE(Pluto)
 if(PLUTO_FOUND)
   set(POLLY_LINK_LIBS ${POLLY_LINK_LIBS} ${PLUTO_LIBRARY})
 endif(PLUTO_FOUND)
 
-if(GMP_FOUND)
-  set(POLLY_LINK_LIBS ${POLLY_LINK_LIBS} ${GMP_LIBRARY})
-endif(GMP_FOUND)
-
 option(POLLY_ENABLE_GPGPU_CODEGEN "Enable GPGPU code generation feature" OFF)
 if (POLLY_ENABLE_GPGPU_CODEGEN)
   # Do not require CUDA, as GPU code generation test cases can be run without
@@ -118,6 +124,9 @@ include_directories(
   BEFORE
   ${CMAKE_CURRENT_SOURCE_DIR}/include
   ${CMAKE_CURRENT_SOURCE_DIR}/lib/JSON/include
+  ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
+  ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/imath
+  ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl
   ${CMAKE_CURRENT_BINARY_DIR}/include
   )
 
@@ -151,7 +160,10 @@ configure_file( ${CMAKE_CURRENT_SOURCE_D
 # Add target to check formatting of polly files
 file( GLOB_RECURSE files *.h *.cpp)
 file( GLOB_RECURSE jsonfiles lib/JSON/*.h lib/JSON/*.cpp)
-list( REMOVE_ITEM files ${jsonfiles} )
+file( GLOB_RECURSE islfiles lib/External/isl/*.h lib/External/isl/*.c
+                   lib/External/isl/include/isl/*.h lib/External/isl/imath/*.h
+                   lib/External/isl/imath/*.c)
+list( REMOVE_ITEM files ${jsonfiles} ${islfiles})
 add_custom_command( OUTPUT formatting COMMAND
   CLANG_FORMAT=${LLVM_BINARY_DIR}/bin/clang-format
   ${CMAKE_CURRENT_SOURCE_DIR}/utils/check_format.sh ${files})

Modified: polly/trunk/Makefile.config.in
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/Makefile.config.in?rev=228193&r1=228192&r2=228193&view=diff
==============================================================================
--- polly/trunk/Makefile.config.in (original)
+++ polly/trunk/Makefile.config.in Wed Feb  4 14:55:43 2015
@@ -28,13 +28,30 @@ endif
 
 POLLY_CXXFLAGS += "-fno-rtti -fno-exceptions"
 
+# Define the FLAGS for the compilation of isl and imath
+#
+# Those are the only C files we have in the repository. Hence, we can just use
+# the CFLAGS to identify them.
+#
+# We first set the visibility of all isl functions to hidden to ensure we do
+# not clash with other isl versions that got linked into a program that uses
+# Polly. (This happens e.g when linking Polly with dragonegg)
+#
+# We also disable all warnings, as these should be fixed upstream. There is
+# no value in reporting them here.
+POLLY_CFLAGS := -fvisibility=hidden
+POLLY_CFLAGS += -w
+
 PLUTO_FOUND := @pluto_found@
 CUDALIB_FOUND := @cuda_found@
 
-# Set include directroys
-POLLY_INC :=  @gmp_inc@ @isl_inc@ @cuda_inc@\
-				      @pluto_inc@ -I$(POLLY_SRC_ROOT)/lib/JSON/include
+# Set include directories
+POLLY_INC :=  @cuda_inc@ \
+              @pluto_inc@ -I$(POLLY_SRC_ROOT)/lib/JSON/include \
+              -I$(POLLY_SRC_ROOT)/lib/External/isl/include \
+              -I$(POLLY_SRC_ROOT)/lib/External/isl/imath \
+              -I$(POLLY_SRC_ROOT)/lib/External/isl
 
-POLLY_LD := @gmp_ld@ @isl_ld@ @cuda_ld@ @pluto_ld@
+POLLY_LD := @cuda_ld@ @pluto_ld@
 
-POLLY_LIB := @gmp_lib@ @isl_lib@ @cuda_lib@ @pluto_lib@
+POLLY_LIB := @cuda_lib@ @pluto_lib@

Modified: polly/trunk/autoconf/aclocal.m4
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/autoconf/aclocal.m4?rev=228193&r1=228192&r2=228193&view=diff
==============================================================================
--- polly/trunk/autoconf/aclocal.m4 (original)
+++ polly/trunk/autoconf/aclocal.m4 Wed Feb  4 14:55:43 2015
@@ -1,8 +1,7 @@
-# generated automatically by aclocal 1.11.6 -*- Autoconf -*-
+# generated automatically by aclocal 1.14.1 -*- Autoconf -*-
+
+# Copyright (C) 1996-2013 Free Software Foundation, Inc.
 
-# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-# 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
-# Inc.
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -12,6 +11,7 @@
 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 # PARTICULAR PURPOSE.
 
+m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
 dnl find_lib_and_headers(name, verify-header, library-name, requirded?)
 dnl Export
 dnl         name_inc in -I"include-path" form

Modified: polly/trunk/autoconf/configure.ac
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/autoconf/configure.ac?rev=228193&r1=228192&r2=228193&view=diff
==============================================================================
--- polly/trunk/autoconf/configure.ac (original)
+++ polly/trunk/autoconf/configure.ac Wed Feb  4 14:55:43 2015
@@ -72,18 +72,10 @@ dnl ************************************
 dnl **************************************************************************
 dnl * Set the location of various third-party software packages
 dnl **************************************************************************
-dnl Find Gmp
-find_lib_and_headers([gmp], [gmp.h], [gmp])
-
-dnl Find Isl
-saved_CXXFLAGS=$CXXFLAGS
-CXXFLAGS="$CXXFLAGS"
-find_lib_and_headers([isl], [isl/val.h], [isl], [required])
-CXXFLAGS=$saved_CXXFLAGS
 
 dnl Check that we have libpluto.
 saved_CXXFLAGS=$CXXFLAGS
-CXXFLAGS="$CXXFLAGS $gmp_inc $isl_inc"
+CXXFLAGS="$CXXFLAGS"
 find_lib_and_headers([pluto], [pluto/libpluto.h], [pluto])
 CXXFLAGS=$saved_CXXFLAGS
 AS_IF([test "x$pluto_found" = "xyes"],

Removed: polly/trunk/cmake/FindGmp.cmake
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/cmake/FindGmp.cmake?rev=228192&view=auto
==============================================================================
--- polly/trunk/cmake/FindGmp.cmake (original)
+++ polly/trunk/cmake/FindGmp.cmake (removed)
@@ -1,19 +0,0 @@
-FIND_PATH(GMP_INCLUDE_DIR gmp.h)
-
-FIND_LIBRARY(GMP_LIBRARY NAMES gmp)
-
-IF (GMP_INCLUDE_DIR AND GMP_LIBRARY)
-  SET(GMP_FOUND TRUE)
-ENDIF (GMP_INCLUDE_DIR AND GMP_LIBRARY)
-
-
-IF (GMP_FOUND)
-  IF (NOT GMP_FIND_QUIETLY)
-    MESSAGE(STATUS "Found GMP: ${GMP_LIBRARY}")
-  ENDIF (NOT GMP_FIND_QUIETLY)
-ELSE (GMP_FOUND)
-  IF (GMP_FIND_REQUIRED)
-    MESSAGE(FATAL_ERROR "Could not find GMP")
-  ENDIF (GMP_FIND_REQUIRED)
-ENDIF (GMP_FOUND)
-

Removed: polly/trunk/cmake/FindIsl.cmake
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/cmake/FindIsl.cmake?rev=228192&view=auto
==============================================================================
--- polly/trunk/cmake/FindIsl.cmake (original)
+++ polly/trunk/cmake/FindIsl.cmake (removed)
@@ -1,19 +0,0 @@
-FIND_PATH(ISL_INCLUDE_DIR isl/val.h)
-
-FIND_LIBRARY(ISL_LIBRARY NAMES isl)
-
-IF (ISL_INCLUDE_DIR AND ISL_LIBRARY)
-  SET(ISL_FOUND TRUE)
-ENDIF (ISL_INCLUDE_DIR AND ISL_LIBRARY)
-
-
-IF (ISL_FOUND)
-  IF (NOT Isl_FIND_QUIETLY)
-    MESSAGE(STATUS "Found Isl: ${ISL_LIBRARY}")
-  ENDIF (NOT Isl_FIND_QUIETLY)
-ELSE (ISL_FOUND)
-  IF (Isl_FIND_REQUIRED)
-    MESSAGE(FATAL_ERROR "Could not find Isl")
-  ENDIF (Isl_FIND_REQUIRED)
-ENDIF (ISL_FOUND)
-

Modified: polly/trunk/configure
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/configure?rev=228193&r1=228192&r2=228193&view=diff
==============================================================================
--- polly/trunk/configure (original)
+++ polly/trunk/configure Wed Feb  4 14:55:43 2015
@@ -595,14 +595,6 @@ pluto_ld
 pluto_lib
 pluto_inc
 pluto_found
-isl_ld
-isl_lib
-isl_inc
-isl_found
-gmp_ld
-gmp_lib
-gmp_inc
-gmp_found
 OBJEXT
 EXEEXT
 ac_ct_CXX
@@ -655,8 +647,6 @@ ac_user_opts='
 enable_option_checking
 with_llvmsrc
 with_llvmobj
-with_gmp
-with_isl
 with_pluto
 enable_polly_gpu_codegen
 with_cuda
@@ -1287,8 +1277,6 @@ Optional Packages:
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
   --with-llvmsrc          Location of LLVM Source Code
   --with-llvmobj          Location of LLVM Object Code
-  --with-gmp              prefix of gmp
-  --with-isl              prefix of isl
   --with-pluto            prefix of pluto
   --with-cuda             prefix of cuda
 
@@ -1899,8 +1887,8 @@ fi
 
 
 
-
-
+saved_CXXFLAGS=$CXXFLAGS
+CXXFLAGS="$CXXFLAGS"
 ac_ext=cpp
 ac_cpp='$CXXCPP $CPPFLAGS'
 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -2412,169 +2400,6 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
 
   ac_ext=cpp
 ac_cpp='$CXXCPP $CPPFLAGS'
-ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
-
-  OLD_CXXFLAGS=$CXXFLAGS;
-  OLD_LDFLAGS=$LDFLAGS;
-  OLD_LIBS=$LIBS;
-
-  LIBS="$LIBS -lgmp";
-
-  # Get include path and lib path
-
-# Check whether --with-gmp was given.
-if test "${with_gmp+set}" = set; then :
-  withval=$with_gmp; given_inc_path="$withval/include"; CXXFLAGS="-I$given_inc_path $CXXFLAGS";
-       given_lib_path="$withval/lib"; LDFLAGS="-L$given_lib_path $LDFLAGS"
-else
-  given_inc_path=inc_not_give_gmp;
-       given_lib_path=lib_not_give_gmp
-
-fi
-
-  # Check for library and headers works
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gmp: gmp.h in $given_inc_path, and libgmp in $given_lib_path" >&5
-$as_echo_n "checking for gmp: gmp.h in $given_inc_path, and libgmp in $given_lib_path... " >&6; }
-
-  # try to compile a file that includes a header of the library
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <gmp.h>
-int
-main ()
-{
-;
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_cxx_try_link "$LINENO"; then :
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5
-$as_echo "ok" >&6; }
-    gmp_found="yes"
-
-    if test "x$given_inc_path" != "xinc_not_give_gmp"; then :
-  gmp_inc="-I$given_inc_path"
-
-fi
-    gmp_lib="-lgmp"
-
-    if test "x$given_lib_path" != "xlib_not_give_gmp"; then :
-  gmp_ld="-L$given_lib_path"
-
-fi
-else
-  if test "x" = "xrequired"; then :
-  as_fn_error $? "gmp required but not found" "$LINENO" 5
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5
-$as_echo "not found" >&6; }
-fi
-
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-
-  # reset original CXXFLAGS
-  CXXFLAGS=$OLD_CXXFLAGS
-  LDFLAGS=$OLD_LDFLAGS;
-  LIBS=$OLD_LIBS
-  ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
-
-
-saved_CXXFLAGS=$CXXFLAGS
-CXXFLAGS="$CXXFLAGS"
-
-  ac_ext=cpp
-ac_cpp='$CXXCPP $CPPFLAGS'
-ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
-
-  OLD_CXXFLAGS=$CXXFLAGS;
-  OLD_LDFLAGS=$LDFLAGS;
-  OLD_LIBS=$LIBS;
-
-  LIBS="$LIBS -lisl";
-
-  # Get include path and lib path
-
-# Check whether --with-isl was given.
-if test "${with_isl+set}" = set; then :
-  withval=$with_isl; given_inc_path="$withval/include"; CXXFLAGS="-I$given_inc_path $CXXFLAGS";
-       given_lib_path="$withval/lib"; LDFLAGS="-L$given_lib_path $LDFLAGS"
-else
-  given_inc_path=inc_not_give_isl;
-       given_lib_path=lib_not_give_isl
-
-fi
-
-  # Check for library and headers works
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for isl: isl/val.h in $given_inc_path, and libisl in $given_lib_path" >&5
-$as_echo_n "checking for isl: isl/val.h in $given_inc_path, and libisl in $given_lib_path... " >&6; }
-
-  # try to compile a file that includes a header of the library
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <isl/val.h>
-int
-main ()
-{
-;
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_cxx_try_link "$LINENO"; then :
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5
-$as_echo "ok" >&6; }
-    isl_found="yes"
-
-    if test "x$given_inc_path" != "xinc_not_give_isl"; then :
-  isl_inc="-I$given_inc_path"
-
-fi
-    isl_lib="-lisl"
-
-    if test "x$given_lib_path" != "xlib_not_give_isl"; then :
-  isl_ld="-L$given_lib_path"
-
-fi
-else
-  if test "xrequired" = "xrequired"; then :
-  as_fn_error $? "isl required but not found" "$LINENO" 5
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5
-$as_echo "not found" >&6; }
-fi
-
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-
-  # reset original CXXFLAGS
-  CXXFLAGS=$OLD_CXXFLAGS
-  LDFLAGS=$OLD_LDFLAGS;
-  LIBS=$OLD_LIBS
-  ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
-
-CXXFLAGS=$saved_CXXFLAGS
-CXXFLAGS="$CXXFLAGS $gmp_inc $isl_inc"
-
-  ac_ext=cpp
-ac_cpp='$CXXCPP $CPPFLAGS'
 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
 ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_cxx_compiler_gnu

Modified: polly/trunk/lib/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CMakeLists.txt?rev=228193&r1=228192&r2=228193&view=diff
==============================================================================
--- polly/trunk/lib/CMakeLists.txt (original)
+++ polly/trunk/lib/CMakeLists.txt Wed Feb  4 14:55:43 2015
@@ -20,6 +20,85 @@ if (GPU_CODEGEN)
        CodeGen/PTXGenerator.cpp)
 endif (GPU_CODEGEN)
 
+set (ISL_FILES
+    External/isl/basis_reduction_tab.c
+    External/isl/isl_aff.c
+    External/isl/isl_affine_hull.c
+    External/isl/isl_arg.c
+    External/isl/isl_ast_build.c
+    External/isl/isl_ast_build_expr.c
+    External/isl/isl_ast.c
+    External/isl/isl_ast_codegen.c
+    External/isl/isl_ast_graft.c
+    External/isl/isl_band.c
+    External/isl/isl_bernstein.c
+    External/isl/isl_blk.c
+    External/isl/isl_bound.c
+    External/isl/isl_coalesce.c
+    External/isl/isl_constraint.c
+    External/isl/isl_convex_hull.c
+    External/isl/isl_ctx.c
+    External/isl/isl_deprecated.c
+    External/isl/isl_dim.c
+    External/isl/isl_dim_map.c
+    External/isl/isl_equalities.c
+    External/isl/isl_factorization.c
+    External/isl/isl_farkas.c
+    External/isl/isl_flow.c
+    External/isl/isl_fold.c
+    External/isl/isl_hash.c
+    External/isl/isl_id.c
+    External/isl/isl_id_to_ast_expr.c
+    External/isl/isl_id_to_pw_aff.c
+    External/isl/isl_ilp.c
+    External/isl/isl_imath.c
+    External/isl/isl_input.c
+    External/isl/isl_local_space.c
+    External/isl/isl_lp.c
+    External/isl/isl_map.c
+    External/isl/isl_map_simplify.c
+    External/isl/isl_map_subtract.c
+    External/isl/isl_map_to_basic_set.c
+    External/isl/isl_mat.c
+    External/isl/isl_morph.c
+    External/isl/isl_obj.c
+    External/isl/isl_options.c
+    External/isl/isl_output.c
+    External/isl/isl_point.c
+    External/isl/isl_polynomial.c
+    External/isl/isl_printer.c
+    External/isl/isl_range.c
+    External/isl/isl_reordering.c
+    External/isl/isl_sample.c
+    External/isl/isl_scan.c
+    External/isl/isl_schedule.c
+    External/isl/isl_scheduler.c
+    External/isl/isl_seq.c
+    External/isl/isl_set_list.c
+    External/isl/isl_sort.c
+    External/isl/isl_space.c
+    External/isl/isl_stream.c
+    External/isl/isl_tab.c
+    External/isl/isl_tab_pip.c
+    External/isl/isl_tarjan.c
+    External/isl/isl_transitive_closure.c
+    External/isl/isl_union_map.c
+    External/isl/isl_val.c
+    External/isl/isl_val_imath.c
+    External/isl/isl_vec.c
+    External/isl/isl_version.c
+    External/isl/isl_vertices.c
+    External/isl/print.c
+    External/isl/imath/gmp_compat.c
+    External/isl/imath/imath.c
+    External/isl/imath/imdrover.c
+    External/isl/imath/imrat.c
+    External/isl/imath/iprime.c
+    External/isl/imath/pi.c
+    External/isl/imath/rsamath.c
+    )
+
+
 add_polly_library(Polly
   Analysis/Dependences.cpp
   Analysis/ScopDetection.cpp
@@ -47,6 +126,7 @@ add_polly_library(Polly
   Transform/IndependentBlocks.cpp
   Transform/ScheduleOptimizer.cpp
   ${POLLY_PLUTO_FILES}
+  ${ISL_FILES}
   )
 
 # Build a monolithic Polly.a and a thin module LLVMPolly.moduleext that links to

Added: polly/trunk/lib/External/README.txt
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/README.txt?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/README.txt (added)
+++ polly/trunk/lib/External/README.txt Wed Feb  4 14:55:43 2015
@@ -0,0 +1,17 @@
+The libraries in this directory are mirrored from external projects.
+
+Patches to them should first be contributed upstream and then return to Polly
+as normal (re)imports of these updated libraries.
+
+We currently have the following external libraries.
+
+# isl
+License: MIT-STYLE
+Details: isl/LICENSE
+Version: b3e0fa7a05d
+
+# imath
+License: MIT-STYLE
+Details: isl/imath/LICENSE
+Version: 4d707e5ef2
+

Added: polly/trunk/lib/External/isl/.gitignore
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/.gitignore?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/.gitignore (added)
+++ polly/trunk/lib/External/isl/.gitignore Wed Feb  4 14:55:43 2015
@@ -0,0 +1,53 @@
+# ignore objects and archives
+*.[oa]
+*.lo
+*.la
+
+.deps/
+.libs/
+Makefile
+Makefile.in
+aclocal.m4
+autom4te.cache/
+config.guess
+isl_config.h.in
+isl_config.h.in~
+compile
+config.log
+config.status
+config.sub
+configure
+depcomp
+doc/Makefile
+doc/Makefile.in
+include/isl/config.h
+include/isl/stdint.h
+include/stamp-h2
+include/isl/stamp-h2
+install-sh
+isl-uninstalled.pc
+isl-uninstalled.sh
+isl.pc
+isl.pc.in
+isl_bound
+isl_cat
+isl_closure
+isl_pip
+isl_polyhedron_detect_equalities
+isl_polyhedron_minimize
+isl_polyhedron_sample
+isl_polytope_scan
+isl_test
+libtool
+ltmain.sh
+m4/libtool.m4
+m4/ltoptions.m4
+m4/ltsugar.m4
+m4/ltversion.m4
+m4/lt~obsolete.m4
+missing
+stamp-h1
+test-driver
+
+bound_test.sh
+pip_test.sh

Added: polly/trunk/lib/External/isl/AUTHORS
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/AUTHORS?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/AUTHORS (added)
+++ polly/trunk/lib/External/isl/AUTHORS Wed Feb  4 14:55:43 2015
@@ -0,0 +1,42 @@
+isl was written by
+
+	    Sven Verdoolaege
+2006-2007   Leiden Institute of Advanced Computer Science
+	    Universiteit Leiden
+	    Niels Bohrweg 1
+	    2333 CA Leiden
+	    The Netherlands
+2008-2009   K.U.Leuven
+	    Departement Computerwetenschappen
+	    Celestijnenlaan 200A
+	    B-3001 Leuven
+	    Belgium
+2010-2011   INRIA Saclay - Ile-de-France
+	    Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod
+	    91893 Orsay
+	    France
+2011-2012   consultant for Leiden Institute of Advanced Computer Science
+2012-2014   Ecole Normale Superieure
+	    45 rue d'Ulm, 75230 Paris
+	    France
+2014	    INRIA Rocquencourt
+	    Domaine de Voluceau - Rocquencourt, B.P. 105
+	    78153 Le Chesnay
+	    France
+
+Contributions by
+
+Mythri Alle
+Riyadh Baghdadi
+Serge Belyshev
+Ray Donnelly
+Johannes Doerfert
+Tobias Grosser
+Alexandre Isoard
+Andreas Kloeckner
+Sebastian Pop
+Louis-Noel Pouchet
+Uday Kumar Reddy
+Sven van Haastregt
+
+The merge sort implementation was written by Jeffrey Stedfast.

Added: polly/trunk/lib/External/isl/ChangeLog
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/ChangeLog?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/ChangeLog (added)
+++ polly/trunk/lib/External/isl/ChangeLog Wed Feb  4 14:55:43 2015
@@ -0,0 +1,134 @@
+version: 0.14
+date: Sat Oct 25 16:08:47 CEST 2014
+changes:
+	- support IMath as an optional replacement for GMP
+	- minor AST generator improvements
+---
+version: 0.13
+date: Mon Apr 14 11:08:45 CEST 2014
+changes:
+	- deprecate isl_int
+	- improved support for multi piecewise quasi-affine expressions
+	- allow the user to impose a bound on the number of low-level operations
+	- add isl_id_to_ast_expr and isl_id_to_pw_aff
+	- add isl_schedule_constraints
+	- hide internal structure of isl_vec
+	- remove support for piplib
+---
+version: 0.12.2
+date: Sun Jan 12 12:09:46 CET 2014
+changes:
+	- MinGW-w64 build fix
+	- fix simplification bug
+---
+version: 0.12.1
+date: Wed Jul 24 12:54:46 CEST 2013
+changes:
+	- handle malloc returning NULL on zero-size allocation
+	- fix regression in AST generator
+---
+version: 0.12
+date: Sun Jun 23 20:23:05 CEST 2013
+changes:
+	- add isl_val abstraction
+---
+version: 0.11.2
+date: Tue Apr  9 18:45:10 CEST 2013
+changes:
+	- make code generation output the same on Solaris
+	- fix some hard to trigger bugs
+---
+version: 0.11.1
+date: Mon Dec 10 11:55:30 CET 2012
+changes:
+	- add LICENSE file to distribution
+	- make code generation output independent of endianness
+---
+version: 0.11
+date: Mon Dec  3 08:17:18 CET 2012
+changes:
+	- change license from LGPL 2.1 to MIT
+	- add support for multi piecewise quasi-affine expressions
+	- add code generation
+	- various minor bug fixes
+---
+version: 0.10
+date: Sun Jun  3 18:00:16 CEST 2012
+changes:
+	- support for interaction with dependence analysis
+	- add public API for vectors
+	- improved support for (piecewise) multi quasi-affine expressions
+	- various minor bug fixes
+---
+version: 0.09
+date: Sat Dec 17 18:19:26 CET 2011
+changes:
+	- improved argument parsing
+	- hide internal structure of isl_options
+	- improved support for parameter sets
+	- configurable scheduling
+---
+version: 0.08
+date: Fri Oct 21 12:36:20 CEST 2011
+changes:
+	- improved parsing
+	- drop isl_div abstraction
+	- rename isl_dim to isl_space
+	- |-
+	  explicitly differentiate between spaces of maps,
+	  sets and parameter sets
+	- add support for identifiers
+	- add support for (piecewise) multi quasi-affine expressions
+	- preliminary Python bindings
+---
+version: 0.07
+date: Tue Jul 12 19:34:51 CEST 2011
+changes:
+	- hide internal structures of isl_div and isl_constraint
+	- preliminary scheduling
+	- add support for local spaces and (piecewise) quasi-affine expressions
+---
+version: 0.06
+date: Fri Mar 18 15:59:16 CET 2011
+changes:
+	- improved parsing
+	- consistency changes in API
+	- hide internal structure of isl_ctx
+---
+version: 0.05.1
+date: Wed Jan  5 10:21:42 CET 2011
+changes:
+	- fix simple symmetry detection in parametric integer programming
+---
+version: 0.05
+date: Thu Dec 23 17:03:14 CET 2010
+changes:
+	- rename header files from isl_header.h to isl/header.h
+	- add higher level interface for dependence analysis
+	- improved argument parsing
+	- optionally triangulate domains during Bernstein expansion
+	- support extended PolyLib format
+	- hide internal structure of some data types
+	- improved coalescing
+	- add simple symmetry detection in parametric integer programming
+---
+version: 0.04
+date: Fri Sep 10 12:57:50 CEST 2010
+changes:
+	- rename isl_pw_qpolynomial_fold_add
+	- add isl_map_apply_pw_qpolynomial_fold
+	- support named and nested spaces
+	- support union sets and maps
+	- add public API for matrices
+---
+version: 0.03
+date: Tue Jun 29 13:16:46 CEST 2010
+changes:
+	- new printing functions
+	- support for "may" accesses in dependence analysis
+	- improved coalescing
+	- improved transitive closure
+	- fix several hard to trigger bugs
+	- improved argument parsing
+	- support parametric vertex enumeration for barvinok
+	- optionally use Bernstein expansion to compute bounds

Added: polly/trunk/lib/External/isl/LICENSE
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/LICENSE?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/LICENSE (added)
+++ polly/trunk/lib/External/isl/LICENSE Wed Feb  4 14:55:43 2015
@@ -0,0 +1,19 @@
+MIT License (MIT)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

Added: polly/trunk/lib/External/isl/Makefile.am
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/Makefile.am?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/Makefile.am (added)
+++ polly/trunk/lib/External/isl/Makefile.am Wed Feb  4 14:55:43 2015
@@ -0,0 +1,329 @@
+if HAVE_CLANG
+    MAYBE_INTERFACE = interface
+endif
+SUBDIRS = . $(MAYBE_INTERFACE) doc
+DIST_SUBDIRS = $(MAYBE_INTERFACE) doc
+
+ACLOCAL_AMFLAGS = -I m4
+AUTOMAKE_OPTIONS = nostdinc subdir-objects
+
+lib_LTLIBRARIES = libisl.la
+noinst_PROGRAMS = isl_test isl_polyhedron_sample isl_pip \
+	isl_polyhedron_minimize isl_polytope_scan \
+	isl_polyhedron_detect_equalities isl_cat \
+	isl_closure isl_bound isl_codegen
+TESTS = isl_test codegen_test.sh pip_test.sh bound_test.sh
+
+if IMATH_FOR_MP
+
+MP_SRC = \
+	isl_hide_deprecated.h \
+	isl_imath.c \
+	isl_imath.h \
+	isl_int_imath.h \
+	isl_val_imath.c \
+	imath_wrap/gmp_compat.h \
+	imath_wrap/imath.h \
+	imath_wrap/imrat.h \
+	imath_wrap/wrap.h \
+	imath_wrap/gmp_compat.c \
+	imath_wrap/imath.c \
+	imath_wrap/imrat.c
+
+DEPRECATED_SRC =
+MP_INCLUDE_H =
+endif
+
+if GMP_FOR_MP
+if NEED_GET_MEMORY_FUNCTIONS
+GET_MEMORY_FUNCTIONS=mp_get_memory_functions.c
+endif
+
+MP_SRC = \
+	$(GET_MEMORY_FUNCTIONS) \
+	isl_int_gmp.h \
+	isl_gmp.c \
+	isl_val_gmp.c
+
+DEPRECATED_SRC = isl_ast_int.c
+MP_INCLUDE_H = include/isl/val_gmp.h
+endif
+
+AM_CPPFLAGS = -I. -I$(srcdir) -I$(srcdir)/include -Iinclude/ @MP_CPPFLAGS@
+AM_CFLAGS = @WARNING_FLAGS@
+
+libisl_la_SOURCES = \
+	$(MP_SRC) \
+	$(DEPRECATED_SRC) \
+	isl_aff.c \
+	isl_aff_private.h \
+	isl_affine_hull.c \
+	isl_arg.c \
+	isl_ast.c \
+	isl_ast_private.h \
+	isl_ast_build.c \
+	isl_ast_build_private.h \
+	isl_ast_build_expr.c \
+	isl_ast_build_expr.h \
+	isl_ast_codegen.c \
+	isl_ast_graft.c \
+	isl_ast_graft_private.h \
+	isl_band.c \
+	isl_band_private.h \
+	isl_basis_reduction.h \
+	basis_reduction_tab.c \
+	isl_bernstein.c \
+	isl_bernstein.h \
+	isl_blk.c \
+	isl_blk.h \
+	isl_bound.c \
+	isl_bound.h \
+	isl_coalesce.c \
+	isl_constraint.c \
+	isl_constraint_private.h \
+	isl_convex_hull.c \
+	isl_ctx.c \
+	isl_ctx_private.h \
+	isl_deprecated.c \
+	isl_dim.c \
+	isl_dim_map.h \
+	isl_dim_map.c \
+	isl_equalities.c \
+	isl_equalities.h \
+	isl_factorization.c \
+	isl_factorization.h \
+	isl_farkas.c \
+	isl_flow.c \
+	isl_fold.c \
+	isl_hash.c \
+	isl_id_to_ast_expr.c \
+	isl_id_to_pw_aff.c \
+	isl_ilp.c \
+	isl_ilp_private.h \
+	isl_input.c \
+	isl_int.h \
+	isl_local_space_private.h \
+	isl_local_space.c \
+	isl_lp.c \
+	isl_lp_private.h \
+	isl_map.c \
+	isl_map_simplify.c \
+	isl_map_subtract.c \
+	isl_map_private.h \
+	isl_map_to_basic_set.c \
+	isl_mat.c \
+	isl_mat_private.h \
+	isl_morph.c \
+	isl_morph.h \
+	isl_id.c \
+	isl_id_private.h \
+	isl_obj.c \
+	isl_options.c \
+	isl_options_private.h \
+	isl_output.c \
+	isl_point_private.h \
+	isl_point.c \
+	isl_polynomial_private.h \
+	isl_polynomial.c \
+	isl_printer_private.h \
+	isl_printer.c \
+	print.c \
+	isl_range.c \
+	isl_range.h \
+	isl_reordering.c \
+	isl_reordering.h \
+	isl_sample.h \
+	isl_sample.c \
+	isl_scan.c \
+	isl_scan.h \
+	isl_schedule.c \
+	isl_schedule_private.h \
+	isl_scheduler.c \
+	isl_set_list.c \
+	isl_sort.c \
+	isl_sort.h \
+	isl_space.c \
+	isl_space_private.h \
+	isl_stream.c \
+	isl_stream_private.h \
+	isl_seq.c \
+	isl_seq.h \
+	isl_tab.c \
+	isl_tab.h \
+	isl_tab_pip.c \
+	isl_tarjan.c \
+	isl_tarjan.h \
+	isl_transitive_closure.c \
+	isl_union_map.c \
+	isl_union_map_private.h \
+	isl_val.c \
+	isl_val_private.h \
+	isl_vec_private.h \
+	isl_vec.c \
+	isl_version.c \
+	isl_vertices_private.h \
+	isl_vertices.c
+libisl_la_LIBADD = @MP_LIBS@
+libisl_la_LDFLAGS = -version-info @versioninfo@ \
+	@MP_LDFLAGS@
+
+isl_test_LDFLAGS = @MP_LDFLAGS@
+isl_test_LDADD = libisl.la @MP_LIBS@
+
+isl_polyhedron_sample_LDADD = libisl.la
+isl_polyhedron_sample_SOURCES = \
+	polyhedron_sample.c
+
+isl_pip_LDFLAGS = @MP_LDFLAGS@
+isl_pip_LDADD = libisl.la @MP_LIBS@
+isl_pip_SOURCES = \
+	pip.c
+
+isl_codegen_LDFLAGS = @MP_LDFLAGS@
+isl_codegen_LDADD = libisl.la @MP_LIBS@
+isl_codegen_SOURCES = \
+	codegen.c
+
+isl_bound_LDFLAGS = @MP_LDFLAGS@
+isl_bound_LDADD = libisl.la @MP_LIBS@
+isl_bound_SOURCES = \
+	bound.c
+
+isl_polyhedron_minimize_LDFLAGS = @MP_LDFLAGS@
+isl_polyhedron_minimize_LDADD = libisl.la @MP_LIBS@
+isl_polyhedron_minimize_SOURCES = \
+	polyhedron_minimize.c
+
+isl_polytope_scan_LDADD = libisl.la
+isl_polytope_scan_SOURCES = \
+	polytope_scan.c
+
+isl_polyhedron_detect_equalities_LDADD = libisl.la
+isl_polyhedron_detect_equalities_SOURCES = \
+	polyhedron_detect_equalities.c
+
+isl_cat_LDADD = libisl.la
+isl_cat_SOURCES = \
+	cat.c
+
+isl_closure_LDADD = libisl.la
+isl_closure_SOURCES = \
+	closure.c
+
+nodist_pkginclude_HEADERS = \
+	include/isl/stdint.h
+pkginclude_HEADERS = \
+	$(MP_INCLUDE_H) \
+	include/isl/aff.h \
+	include/isl/aff_type.h \
+	include/isl/arg.h \
+	include/isl/ast.h \
+	include/isl/ast_type.h \
+	include/isl/ast_build.h \
+	include/isl/band.h \
+	include/isl/constraint.h \
+	include/isl/ctx.h \
+	include/isl/dim.h \
+	include/isl/flow.h \
+	include/isl/id.h \
+	include/isl/id_to_ast_expr.h \
+	include/isl/id_to_pw_aff.h \
+	include/isl/ilp.h \
+	include/isl/hash.h \
+	include/isl/hmap.h \
+	include/isl/list.h \
+	include/isl/local_space.h \
+	include/isl/lp.h \
+	include/isl/mat.h \
+	include/isl/map.h \
+	include/isl/map_to_basic_set.h \
+	include/isl/map_type.h \
+	include/isl/multi.h \
+	include/isl/obj.h \
+	include/isl/options.h \
+	include/isl/point.h \
+	include/isl/polynomial.h \
+	include/isl/polynomial_type.h \
+	include/isl/printer.h \
+	include/isl/schedule.h \
+	include/isl/set.h \
+	include/isl/set_type.h \
+	include/isl/space.h \
+	include/isl/stream.h \
+	include/isl/union_map.h \
+	include/isl/union_map_type.h \
+	include/isl/union_set.h \
+	include/isl/union_set_type.h \
+	include/isl/val.h \
+	include/isl/vec.h \
+	include/isl/version.h \
+	include/isl/vertices.h
+deprecateddir = $(pkgincludedir)/deprecated
+deprecated_HEADERS = \
+	include/isl/deprecated/int.h \
+	include/isl/deprecated/aff_int.h \
+	include/isl/deprecated/ast_int.h \
+	include/isl/deprecated/constraint_int.h \
+	include/isl/deprecated/ilp_int.h \
+	include/isl/deprecated/map_int.h \
+	include/isl/deprecated/mat_int.h \
+	include/isl/deprecated/point_int.h \
+	include/isl/deprecated/polynomial_int.h \
+	include/isl/deprecated/set_int.h \
+	include/isl/deprecated/union_map_int.h \
+	include/isl/deprecated/val_int.h \
+	include/isl/deprecated/vec_int.h
+
+EXTRA_DIST = \
+	LICENSE \
+	isl_config_post.h \
+	basis_reduction_templ.c \
+	isl_hmap_templ.c \
+	isl_list_templ.c \
+	isl_list_templ.h \
+	isl_map_lexopt_templ.c \
+	isl_multi_templ.c \
+	isl_multi_templ.h \
+	print_templ.c \
+	isl_power_templ.c \
+	isl_pw_templ.c \
+	isl_union_templ.c \
+	isl.py \
+	doc/SubmittingPatches \
+	doc/chicago.bst \
+	doc/chicago.sty \
+	doc/implementation.tex \
+	doc/isl.bib \
+	doc/mypod2latex \
+	doc/manual.tex \
+	doc/user.pod \
+	imath/gmp_compat.c \
+	imath/gmp_compat.h \
+	imath/imath.c \
+	imath/imath.h \
+	imath/imrat.c \
+	imath/imrat.h \
+	interface/all.h \
+	interface/isl.py.top \
+	test_inputs
+
+dist-hook:
+	echo @GIT_HEAD_VERSION@ > $(distdir)/GIT_HEAD_ID
+	(cd doc; make manual.pdf)
+	cp doc/manual.pdf $(distdir)/doc/
+
+pkgconfigdir=$(pkgconfig_libdir)
+pkgconfig_DATA = $(pkgconfig_libfile)
+
+gitversion.h: @GIT_HEAD@
+	$(AM_V_GEN)echo '#define GIT_HEAD_ID "'@GIT_HEAD_VERSION@'"' > $@
+
+install-data-local: $(srcdir)/isl.py
+	@libisl=`sed -ne "/^library_names=/{s/.*='//;s/'$$//;s/ .*//;p;}" \
+		 $(builddir)/libisl.la`; \
+	case $$libisl in \
+	'') echo Cannot find isl library name. GDB bindings not installed.;; \
+	*) echo $(INSTALL_DATA) $(srcdir)/isl.py \
+		$(DESTDIR)$(libdir)/$$libisl-gdb.py; \
+	test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"; \
+	$(INSTALL_DATA) $(srcdir)/isl.py $(DESTDIR)$(libdir)/$$libisl-gdb.py; esac

Added: polly/trunk/lib/External/isl/README
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/README?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/README (added)
+++ polly/trunk/lib/External/isl/README Wed Feb  4 14:55:43 2015
@@ -0,0 +1,53 @@
+isl is a thread-safe C library for manipulating sets and relations
+of integer points bounded by affine constraints.  The descriptions of
+the sets and relations may involve both parameters and existentially
+quantified variables.  All computations are performed in exact integer
+arithmetic using GMP.
+
+isl is released under the MIT license, but depends on the LGPL GMP
+library.
+
+Minimal compilation instructions:
+
+	./configure
+	make
+	make install
+
+If you are taking the source from the git repository, then you first
+need to do
+
+	git clone git://repo.or.cz/isl.git
+	./autogen.sh
+
+For more information, see doc/user.pod or the generated documentation.
+
+New releases are announced on http://freecode.com/projects/isl
+
+If you use isl, you can let me know by stacking
+https://www.ohloh.net/p/isl on ohloh.
+
+For bug reports, feature requests and questions,
+contact http://groups.google.com/group/isl-development
+
+Whenever you report a bug, please mention the exact version of isl
+that you are using (output of "./isl_cat --version").  If you are unable
+to compile isl, then report the git version (output of "git describe")
+or the version included in the name of the tarball.
+
+If you use isl for your research, you are invited do cite
+the following paper and/or the paper(s) describing the specific
+operations you use.
+
+ at incollection{Verdoolaege2010isl,
+   author = {Verdoolaege, Sven},
+   title = {isl: An Integer Set Library for the Polyhedral Model},
+   booktitle = {Mathematical Software - ICMS 2010},
+   series = {Lecture Notes in Computer Science},
+   editor = {Fukuda, Komei and Hoeven, Joris and Joswig, Michael and
+		Takayama, Nobuki},
+   publisher = {Springer},
+   isbn = {978-3-642-15581-9},
+   pages = {299-302},
+   volume = {6327},
+   year = {2010}
+}

Added: polly/trunk/lib/External/isl/autogen.sh
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/autogen.sh?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/autogen.sh (added)
+++ polly/trunk/lib/External/isl/autogen.sh Wed Feb  4 14:55:43 2015
@@ -0,0 +1,2 @@
+#!/bin/sh
+autoreconf -i

Propchange: polly/trunk/lib/External/isl/autogen.sh
------------------------------------------------------------------------------
    svn:executable = *

Added: polly/trunk/lib/External/isl/basis_reduction_tab.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/basis_reduction_tab.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/basis_reduction_tab.c (added)
+++ polly/trunk/lib/External/isl/basis_reduction_tab.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,267 @@
+/*
+ * Copyright 2008-2009 Katholieke Universiteit Leuven
+ *
+ * Use of this software is governed by the MIT license
+ *
+ * Written by Sven Verdoolaege, K.U.Leuven, Departement
+ * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
+ */
+
+#include <assert.h>
+#include <isl_map_private.h>
+#include <isl_seq.h>
+#include "isl_tab.h"
+#include <isl_int.h>
+#include <isl_config.h>
+
+struct tab_lp {
+	struct isl_ctx  *ctx;
+	struct isl_vec  *row;
+	struct isl_tab  *tab;
+	struct isl_tab_undo	**stack;
+	isl_int		*obj;
+	isl_int		 opt;
+	isl_int		 opt_denom;
+	isl_int		 tmp;
+	isl_int		 tmp2;
+	int	         neq;
+	unsigned	 dim;
+	/* number of constraints in initial product tableau */
+	int		 con_offset;
+	/* objective function has fixed or no integer value */
+	int		 is_fixed;
+};
+
+#ifdef USE_GMP_FOR_MP
+#define GBR_type		    	    mpq_t
+#define GBR_init(v)		    	    mpq_init(v)
+#define GBR_clear(v)		    	    mpq_clear(v)
+#define GBR_set(a,b)			    mpq_set(a,b)
+#define GBR_set_ui(a,b)			    mpq_set_ui(a,b,1)
+#define GBR_mul(a,b,c)			    mpq_mul(a,b,c)
+#define GBR_lt(a,b)			    (mpq_cmp(a,b) < 0)
+#define GBR_is_zero(a)			    (mpq_sgn(a) == 0)
+#define GBR_numref(a)			    mpq_numref(a)
+#define GBR_denref(a)			    mpq_denref(a)
+#define GBR_floor(a,b)			    mpz_fdiv_q(a,GBR_numref(b),GBR_denref(b))
+#define GBR_ceil(a,b)			    mpz_cdiv_q(a,GBR_numref(b),GBR_denref(b))
+#endif /* USE_GMP_FOR_MP */
+
+#ifdef USE_IMATH_FOR_MP
+#include <imrat.h>
+
+#define GBR_type		    	    mp_rat
+#define GBR_init(v)		    	    v = mp_rat_alloc()
+#define GBR_clear(v)		    	    mp_rat_free(v)
+#define GBR_set(a,b)			    mp_rat_copy(b,a)
+#define GBR_set_ui(a,b)			    mp_rat_set_uvalue(a,b,1)
+#define GBR_mul(a,b,c)			    mp_rat_mul(b,c,a)
+#define GBR_lt(a,b)			    (mp_rat_compare(a,b) < 0)
+#define GBR_is_zero(a)			    (mp_rat_compare_zero(a) == 0)
+#define GBR_numref(a)			    mp_rat_numer_ref(a)
+#define GBR_denref(a)			    mp_rat_denom_ref(a)
+#define GBR_floor(a,b)			    impz_fdiv_q(a,GBR_numref(b),GBR_denref(b))
+#define GBR_ceil(a,b)			    impz_cdiv_q(a,GBR_numref(b),GBR_denref(b))
+#endif /* USE_IMATH_FOR_MP */
+
+static struct tab_lp *init_lp(struct isl_tab *tab);
+static void set_lp_obj(struct tab_lp *lp, isl_int *row, int dim);
+static int solve_lp(struct tab_lp *lp);
+static void get_obj_val(struct tab_lp* lp, GBR_type *F);
+static void delete_lp(struct tab_lp *lp);
+static int add_lp_row(struct tab_lp *lp, isl_int *row, int dim);
+static void get_alpha(struct tab_lp* lp, int row, GBR_type *alpha);
+static int del_lp_row(struct tab_lp *lp) WARN_UNUSED;
+static int cut_lp_to_hyperplane(struct tab_lp *lp, isl_int *row);
+
+#define GBR_LP			    	    struct tab_lp
+#define GBR_lp_init(P)		    	    init_lp(P)
+#define GBR_lp_set_obj(lp, obj, dim)	    set_lp_obj(lp, obj, dim)
+#define GBR_lp_solve(lp)		    solve_lp(lp)
+#define GBR_lp_get_obj_val(lp, F)	    get_obj_val(lp, F)
+#define GBR_lp_delete(lp)		    delete_lp(lp)
+#define GBR_lp_next_row(lp)		    lp->neq
+#define GBR_lp_add_row(lp, row, dim)	    add_lp_row(lp, row, dim)
+#define GBR_lp_get_alpha(lp, row, alpha)    get_alpha(lp, row, alpha)
+#define GBR_lp_del_row(lp)		    del_lp_row(lp)
+#define GBR_lp_is_fixed(lp)		    (lp)->is_fixed
+#define GBR_lp_cut(lp, obj)	    	    cut_lp_to_hyperplane(lp, obj)
+#include "basis_reduction_templ.c"
+
+/* Set up a tableau for the Cartesian product of bset with itself.
+ * This could be optimized by first setting up a tableau for bset
+ * and then performing the Cartesian product on the tableau.
+ */
+static struct isl_tab *gbr_tab(struct isl_tab *tab, struct isl_vec *row)
+{
+	unsigned dim;
+	struct isl_tab *prod;
+
+	if (!tab || !row)
+		return NULL;
+
+	dim = tab->n_var;
+	prod = isl_tab_product(tab, tab);
+	if (isl_tab_extend_cons(prod, 3 * dim + 1) < 0) {
+		isl_tab_free(prod);
+		return NULL;
+	}
+	return prod;
+}
+
+static struct tab_lp *init_lp(struct isl_tab *tab)
+{
+	struct tab_lp *lp = NULL;
+
+	if (!tab)
+		return NULL;
+
+	lp = isl_calloc_type(tab->mat->ctx, struct tab_lp);
+	if (!lp)
+		return NULL;
+
+	isl_int_init(lp->opt);
+	isl_int_init(lp->opt_denom);
+	isl_int_init(lp->tmp);
+	isl_int_init(lp->tmp2);
+
+	lp->dim = tab->n_var;
+
+	lp->ctx = tab->mat->ctx;
+	isl_ctx_ref(lp->ctx);
+
+	lp->stack = isl_alloc_array(lp->ctx, struct isl_tab_undo *, lp->dim);
+
+	lp->row = isl_vec_alloc(lp->ctx, 1 + 2 * lp->dim);
+	if (!lp->row)
+		goto error;
+	lp->tab = gbr_tab(tab, lp->row);
+	if (!lp->tab)
+		goto error;
+	lp->con_offset = lp->tab->n_con;
+	lp->obj = NULL;
+	lp->neq = 0;
+
+	return lp;
+error:
+	delete_lp(lp);
+	return NULL;
+}
+
+static void set_lp_obj(struct tab_lp *lp, isl_int *row, int dim)
+{
+	lp->obj = row;
+}
+
+static int solve_lp(struct tab_lp *lp)
+{
+	enum isl_lp_result res;
+	unsigned flags = 0;
+
+	lp->is_fixed = 0;
+
+	isl_int_set_si(lp->row->el[0], 0);
+	isl_seq_cpy(lp->row->el + 1, lp->obj, lp->dim);
+	isl_seq_neg(lp->row->el + 1 + lp->dim, lp->obj, lp->dim);
+	if (lp->neq)
+		flags = ISL_TAB_SAVE_DUAL;
+	res = isl_tab_min(lp->tab, lp->row->el, lp->ctx->one,
+			  &lp->opt, &lp->opt_denom, flags);
+	isl_int_mul_ui(lp->opt_denom, lp->opt_denom, 2);
+	if (isl_int_abs_lt(lp->opt, lp->opt_denom)) {
+		struct isl_vec *sample = isl_tab_get_sample_value(lp->tab);
+		if (!sample)
+			return -1;
+		isl_seq_inner_product(lp->obj, sample->el + 1, lp->dim, &lp->tmp);
+		isl_seq_inner_product(lp->obj, sample->el + 1 + lp->dim, lp->dim, &lp->tmp2);
+		isl_int_cdiv_q(lp->tmp, lp->tmp, sample->el[0]);
+		isl_int_fdiv_q(lp->tmp2, lp->tmp2, sample->el[0]);
+		if (isl_int_ge(lp->tmp, lp->tmp2))
+			lp->is_fixed = 1;
+		isl_vec_free(sample);
+	}
+	isl_int_divexact_ui(lp->opt_denom, lp->opt_denom, 2);
+	if (res != isl_lp_ok)
+		return -1;
+	return 0;
+}
+
+/* The current objective function has a fixed (or no) integer value.
+ * Cut the tableau to the hyperplane that fixes this value in
+ * both halves of the tableau.
+ * Return 1 if the resulting tableau is empty.
+ */
+static int cut_lp_to_hyperplane(struct tab_lp *lp, isl_int *row)
+{
+	enum isl_lp_result res;
+
+	isl_int_set_si(lp->row->el[0], 0);
+	isl_seq_cpy(lp->row->el + 1, row, lp->dim);
+	isl_seq_clr(lp->row->el + 1 + lp->dim, lp->dim);
+	res = isl_tab_min(lp->tab, lp->row->el, lp->ctx->one,
+			  &lp->tmp, NULL, 0);
+	if (res != isl_lp_ok)
+		return -1;
+
+	isl_int_neg(lp->row->el[0], lp->tmp);
+	if (isl_tab_add_eq(lp->tab, lp->row->el) < 0)
+		return -1;
+
+	isl_seq_cpy(lp->row->el + 1 + lp->dim, row, lp->dim);
+	isl_seq_clr(lp->row->el + 1, lp->dim);
+	if (isl_tab_add_eq(lp->tab, lp->row->el) < 0)
+		return -1;
+
+	lp->con_offset += 2;
+
+	return lp->tab->empty;
+}
+
+static void get_obj_val(struct tab_lp* lp, GBR_type *F)
+{
+	isl_int_neg(GBR_numref(*F), lp->opt);
+	isl_int_set(GBR_denref(*F), lp->opt_denom);
+}
+
+static void delete_lp(struct tab_lp *lp)
+{
+	if (!lp)
+		return;
+
+	isl_int_clear(lp->opt);
+	isl_int_clear(lp->opt_denom);
+	isl_int_clear(lp->tmp);
+	isl_int_clear(lp->tmp2);
+	isl_vec_free(lp->row);
+	free(lp->stack);
+	isl_tab_free(lp->tab);
+	isl_ctx_deref(lp->ctx);
+	free(lp);
+}
+
+static int add_lp_row(struct tab_lp *lp, isl_int *row, int dim)
+{
+	lp->stack[lp->neq] = isl_tab_snap(lp->tab);
+
+	isl_int_set_si(lp->row->el[0], 0);
+	isl_seq_cpy(lp->row->el + 1, row, lp->dim);
+	isl_seq_neg(lp->row->el + 1 + lp->dim, row, lp->dim);
+
+	if (isl_tab_add_valid_eq(lp->tab, lp->row->el) < 0)
+		return -1;
+
+	return lp->neq++;
+}
+
+static void get_alpha(struct tab_lp* lp, int row, GBR_type *alpha)
+{
+	row += lp->con_offset;
+	isl_int_neg(GBR_numref(*alpha), lp->tab->dual->el[1 + row]);
+	isl_int_set(GBR_denref(*alpha), lp->tab->dual->el[0]);
+}
+
+static int del_lp_row(struct tab_lp *lp)
+{
+	lp->neq--;
+	return isl_tab_rollback(lp->tab, lp->stack[lp->neq]);
+}

Added: polly/trunk/lib/External/isl/basis_reduction_templ.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/basis_reduction_templ.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/basis_reduction_templ.c (added)
+++ polly/trunk/lib/External/isl/basis_reduction_templ.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,358 @@
+/*
+ * Copyright 2006-2007 Universiteit Leiden
+ * Copyright 2008-2009 Katholieke Universiteit Leuven
+ *
+ * Use of this software is governed by the MIT license
+ *
+ * Written by Sven Verdoolaege, Leiden Institute of Advanced Computer Science,
+ * Universiteit Leiden, Niels Bohrweg 1, 2333 CA Leiden, The Netherlands
+ * and K.U.Leuven, Departement Computerwetenschappen, Celestijnenlaan 200A,
+ * B-3001 Leuven, Belgium
+ */
+
+#include <stdlib.h>
+#include <isl_ctx_private.h>
+#include <isl_map_private.h>
+#include <isl_vec_private.h>
+#include <isl_options_private.h>
+#include "isl_basis_reduction.h"
+
+static void save_alpha(GBR_LP *lp, int first, int n, GBR_type *alpha)
+{
+	int i;
+
+	for (i = 0; i < n; ++i)
+		GBR_lp_get_alpha(lp, first + i, &alpha[i]);
+}
+
+/* Compute a reduced basis for the set represented by the tableau "tab".
+ * tab->basis, which must be initialized by the calling function to an affine
+ * unimodular basis, is updated to reflect the reduced basis.
+ * The first tab->n_zero rows of the basis (ignoring the constant row)
+ * are assumed to correspond to equalities and are left untouched.
+ * tab->n_zero is updated to reflect any additional equalities that
+ * have been detected in the first rows of the new basis.
+ * The final tab->n_unbounded rows of the basis are assumed to correspond
+ * to unbounded directions and are also left untouched.
+ * In particular this means that the remaining rows are assumed to
+ * correspond to bounded directions.
+ *
+ * This function implements the algorithm described in
+ * "An Implementation of the Generalized Basis Reduction Algorithm
+ *  for Integer Programming" of Cook el al. to compute a reduced basis.
+ * We use \epsilon = 1/4.
+ *
+ * If ctx->opt->gbr_only_first is set, the user is only interested
+ * in the first direction.  In this case we stop the basis reduction when
+ * the width in the first direction becomes smaller than 2.
+ */
+struct isl_tab *isl_tab_compute_reduced_basis(struct isl_tab *tab)
+{
+	unsigned dim;
+	struct isl_ctx *ctx;
+	struct isl_mat *B;
+	int unbounded;
+	int i;
+	GBR_LP *lp = NULL;
+	GBR_type F_old, alpha, F_new;
+	int row;
+	isl_int tmp;
+	struct isl_vec *b_tmp;
+	GBR_type *F = NULL;
+	GBR_type *alpha_buffer[2] = { NULL, NULL };
+	GBR_type *alpha_saved;
+	GBR_type F_saved;
+	int use_saved = 0;
+	isl_int mu[2];
+	GBR_type mu_F[2];
+	GBR_type two;
+	GBR_type one;
+	int empty = 0;
+	int fixed = 0;
+	int fixed_saved = 0;
+	int mu_fixed[2];
+	int n_bounded;
+	int gbr_only_first;
+
+	if (!tab)
+		return NULL;
+
+	if (tab->empty)
+		return tab;
+
+	ctx = tab->mat->ctx;
+	gbr_only_first = ctx->opt->gbr_only_first;
+	dim = tab->n_var;
+	B = tab->basis;
+	if (!B)
+		return tab;
+
+	n_bounded = dim - tab->n_unbounded;
+	if (n_bounded <= tab->n_zero + 1)
+		return tab;
+
+	isl_int_init(tmp);
+	isl_int_init(mu[0]);
+	isl_int_init(mu[1]);
+
+	GBR_init(alpha);
+	GBR_init(F_old);
+	GBR_init(F_new);
+	GBR_init(F_saved);
+	GBR_init(mu_F[0]);
+	GBR_init(mu_F[1]);
+	GBR_init(two);
+	GBR_init(one);
+
+	b_tmp = isl_vec_alloc(ctx, dim);
+	if (!b_tmp)
+		goto error;
+
+	F = isl_alloc_array(ctx, GBR_type, n_bounded);
+	alpha_buffer[0] = isl_alloc_array(ctx, GBR_type, n_bounded);
+	alpha_buffer[1] = isl_alloc_array(ctx, GBR_type, n_bounded);
+	alpha_saved = alpha_buffer[0];
+
+	if (!F || !alpha_buffer[0] || !alpha_buffer[1])
+		goto error;
+
+	for (i = 0; i < n_bounded; ++i) {
+		GBR_init(F[i]);
+		GBR_init(alpha_buffer[0][i]);
+		GBR_init(alpha_buffer[1][i]);
+	}
+
+	GBR_set_ui(two, 2);
+	GBR_set_ui(one, 1);
+
+	lp = GBR_lp_init(tab);
+	if (!lp)
+		goto error;
+
+	i = tab->n_zero;
+
+	GBR_lp_set_obj(lp, B->row[1+i]+1, dim);
+	ctx->stats->gbr_solved_lps++;
+	unbounded = GBR_lp_solve(lp);
+	isl_assert(ctx, !unbounded, goto error);
+	GBR_lp_get_obj_val(lp, &F[i]);
+
+	if (GBR_lt(F[i], one)) {
+		if (!GBR_is_zero(F[i])) {
+			empty = GBR_lp_cut(lp, B->row[1+i]+1);
+			if (empty)
+				goto done;
+			GBR_set_ui(F[i], 0);
+		}
+		tab->n_zero++;
+	}
+
+	do {
+		if (i+1 == tab->n_zero) {
+			GBR_lp_set_obj(lp, B->row[1+i+1]+1, dim);
+			ctx->stats->gbr_solved_lps++;
+			unbounded = GBR_lp_solve(lp);
+			isl_assert(ctx, !unbounded, goto error);
+			GBR_lp_get_obj_val(lp, &F_new);
+			fixed = GBR_lp_is_fixed(lp);
+			GBR_set_ui(alpha, 0);
+		} else
+		if (use_saved) {
+			row = GBR_lp_next_row(lp);
+			GBR_set(F_new, F_saved);
+			fixed = fixed_saved;
+			GBR_set(alpha, alpha_saved[i]);
+		} else {
+			row = GBR_lp_add_row(lp, B->row[1+i]+1, dim);
+			GBR_lp_set_obj(lp, B->row[1+i+1]+1, dim);
+			ctx->stats->gbr_solved_lps++;
+			unbounded = GBR_lp_solve(lp);
+			isl_assert(ctx, !unbounded, goto error);
+			GBR_lp_get_obj_val(lp, &F_new);
+			fixed = GBR_lp_is_fixed(lp);
+
+			GBR_lp_get_alpha(lp, row, &alpha);
+
+			if (i > 0)
+				save_alpha(lp, row-i, i, alpha_saved);
+
+			if (GBR_lp_del_row(lp) < 0)
+				goto error;
+		}
+		GBR_set(F[i+1], F_new);
+
+		GBR_floor(mu[0], alpha);
+		GBR_ceil(mu[1], alpha);
+
+		if (isl_int_eq(mu[0], mu[1]))
+			isl_int_set(tmp, mu[0]);
+		else {
+			int j;
+
+			for (j = 0; j <= 1; ++j) {
+				isl_int_set(tmp, mu[j]);
+				isl_seq_combine(b_tmp->el,
+						ctx->one, B->row[1+i+1]+1,
+						tmp, B->row[1+i]+1, dim);
+				GBR_lp_set_obj(lp, b_tmp->el, dim);
+				ctx->stats->gbr_solved_lps++;
+				unbounded = GBR_lp_solve(lp);
+				isl_assert(ctx, !unbounded, goto error);
+				GBR_lp_get_obj_val(lp, &mu_F[j]);
+				mu_fixed[j] = GBR_lp_is_fixed(lp);
+				if (i > 0)
+					save_alpha(lp, row-i, i, alpha_buffer[j]);
+			}
+
+			if (GBR_lt(mu_F[0], mu_F[1]))
+				j = 0;
+			else
+				j = 1;
+
+			isl_int_set(tmp, mu[j]);
+			GBR_set(F_new, mu_F[j]);
+			fixed = mu_fixed[j];
+			alpha_saved = alpha_buffer[j];
+		}
+		isl_seq_combine(B->row[1+i+1]+1, ctx->one, B->row[1+i+1]+1,
+				tmp, B->row[1+i]+1, dim);
+
+		if (i+1 == tab->n_zero && fixed) {
+			if (!GBR_is_zero(F[i+1])) {
+				empty = GBR_lp_cut(lp, B->row[1+i+1]+1);
+				if (empty)
+					goto done;
+				GBR_set_ui(F[i+1], 0);
+			}
+			tab->n_zero++;
+		}
+
+		GBR_set(F_old, F[i]);
+
+		use_saved = 0;
+		/* mu_F[0] = 4 * F_new; mu_F[1] = 3 * F_old */
+		GBR_set_ui(mu_F[0], 4);
+		GBR_mul(mu_F[0], mu_F[0], F_new);
+		GBR_set_ui(mu_F[1], 3);
+		GBR_mul(mu_F[1], mu_F[1], F_old);
+		if (GBR_lt(mu_F[0], mu_F[1])) {
+			B = isl_mat_swap_rows(B, 1 + i, 1 + i + 1);
+			if (i > tab->n_zero) {
+				use_saved = 1;
+				GBR_set(F_saved, F_new);
+				fixed_saved = fixed;
+				if (GBR_lp_del_row(lp) < 0)
+					goto error;
+				--i;
+			} else {
+				GBR_set(F[tab->n_zero], F_new);
+				if (gbr_only_first && GBR_lt(F[tab->n_zero], two))
+					break;
+
+				if (fixed) {
+					if (!GBR_is_zero(F[tab->n_zero])) {
+						empty = GBR_lp_cut(lp, B->row[1+tab->n_zero]+1);
+						if (empty)
+							goto done;
+						GBR_set_ui(F[tab->n_zero], 0);
+					}
+					tab->n_zero++;
+				}
+			}
+		} else {
+			GBR_lp_add_row(lp, B->row[1+i]+1, dim);
+			++i;
+		}
+	} while (i < n_bounded - 1);
+
+	if (0) {
+done:
+		if (empty < 0) {
+error:
+			isl_mat_free(B);
+			B = NULL;
+		}
+	}
+
+	GBR_lp_delete(lp);
+
+	if (alpha_buffer[1])
+		for (i = 0; i < n_bounded; ++i) {
+			GBR_clear(F[i]);
+			GBR_clear(alpha_buffer[0][i]);
+			GBR_clear(alpha_buffer[1][i]);
+		}
+	free(F);
+	free(alpha_buffer[0]);
+	free(alpha_buffer[1]);
+
+	isl_vec_free(b_tmp);
+
+	GBR_clear(alpha);
+	GBR_clear(F_old);
+	GBR_clear(F_new);
+	GBR_clear(F_saved);
+	GBR_clear(mu_F[0]);
+	GBR_clear(mu_F[1]);
+	GBR_clear(two);
+	GBR_clear(one);
+
+	isl_int_clear(tmp);
+	isl_int_clear(mu[0]);
+	isl_int_clear(mu[1]);
+
+	tab->basis = B;
+
+	return tab;
+}
+
+/* Compute an affine form of a reduced basis of the given basic
+ * non-parametric set, which is assumed to be bounded and not
+ * include any integer divisions.
+ * The first column and the first row correspond to the constant term.
+ *
+ * If the input contains any equalities, we first create an initial
+ * basis with the equalities first.  Otherwise, we start off with
+ * the identity matrix.
+ */
+struct isl_mat *isl_basic_set_reduced_basis(struct isl_basic_set *bset)
+{
+	struct isl_mat *basis;
+	struct isl_tab *tab;
+
+	if (!bset)
+		return NULL;
+
+	if (isl_basic_set_dim(bset, isl_dim_div) != 0)
+		isl_die(bset->ctx, isl_error_invalid,
+			"no integer division allowed", return NULL);
+	if (isl_basic_set_dim(bset, isl_dim_param) != 0)
+		isl_die(bset->ctx, isl_error_invalid,
+			"no parameters allowed", return NULL);
+
+	tab = isl_tab_from_basic_set(bset, 0);
+	if (!tab)
+		return NULL;
+
+	if (bset->n_eq == 0)
+		tab->basis = isl_mat_identity(bset->ctx, 1 + tab->n_var);
+	else {
+		isl_mat *eq;
+		unsigned nvar = isl_basic_set_total_dim(bset);
+		eq = isl_mat_sub_alloc6(bset->ctx, bset->eq, 0, bset->n_eq,
+					1, nvar);
+		eq = isl_mat_left_hermite(eq, 0, NULL, &tab->basis);
+		tab->basis = isl_mat_lin_to_aff(tab->basis);
+		tab->n_zero = bset->n_eq;
+		isl_mat_free(eq);
+	}
+	tab = isl_tab_compute_reduced_basis(tab);
+	if (!tab)
+		return NULL;
+
+	basis = isl_mat_copy(tab->basis);
+
+	isl_tab_free(tab);
+
+	return basis;
+}

Added: polly/trunk/lib/External/isl/bound.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/bound.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/bound.c (added)
+++ polly/trunk/lib/External/isl/bound.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,291 @@
+#include <assert.h>
+#include <isl/stream.h>
+#include <isl_map_private.h>
+#include <isl_polynomial_private.h>
+#include <isl_scan.h>
+#include <isl/options.h>
+#include <isl/deprecated/point_int.h>
+#include <isl/deprecated/polynomial_int.h>
+
+struct bound_options {
+	struct isl_options	*isl;
+	unsigned		 verify;
+	int			 print_all;
+	int			 continue_on_error;
+};
+
+ISL_ARGS_START(struct bound_options, bound_options_args)
+ISL_ARG_CHILD(struct bound_options, isl, "isl", &isl_options_args,
+	"isl options")
+ISL_ARG_BOOL(struct bound_options, verify, 'T', "verify", 0, NULL)
+ISL_ARG_BOOL(struct bound_options, print_all, 'A', "print-all", 0, NULL)
+ISL_ARG_BOOL(struct bound_options, continue_on_error, '\0', "continue-on-error", 0, NULL)
+ISL_ARGS_END
+
+ISL_ARG_DEF(bound_options, struct bound_options, bound_options_args)
+
+static __isl_give isl_set *set_bounds(__isl_take isl_set *set)
+{
+	unsigned nparam;
+	int i, r;
+	isl_point *pt, *pt2;
+	isl_set *box;
+
+	nparam = isl_set_dim(set, isl_dim_param);
+	r = nparam >= 8 ? 5 : nparam >= 5 ? 15 : 50;
+
+	pt = isl_set_sample_point(isl_set_copy(set));
+	pt2 = isl_point_copy(pt);
+
+	for (i = 0; i < nparam; ++i) {
+		pt = isl_point_add_ui(pt, isl_dim_param, i, r);
+		pt2 = isl_point_sub_ui(pt2, isl_dim_param, i, r);
+	}
+
+	box = isl_set_box_from_points(pt, pt2);
+
+	return isl_set_intersect(set, box);
+}
+
+struct verify_point_bound {
+	struct bound_options *options;
+	int stride;
+	int n;
+	int exact;
+	int error;
+
+	isl_pw_qpolynomial_fold *pwf;
+	isl_pw_qpolynomial_fold *bound;
+};
+
+static int verify_point(__isl_take isl_point *pnt, void *user)
+{
+	int i;
+	unsigned nvar;
+	unsigned nparam;
+	struct verify_point_bound *vpb = (struct verify_point_bound *) user;
+	isl_int t;
+	isl_ctx *ctx;
+	isl_pw_qpolynomial_fold *pwf;
+	isl_val *bound = NULL;
+	isl_val *opt = NULL;
+	isl_set *dom = NULL;
+	isl_printer *p;
+	const char *minmax;
+	int bounded;
+	int sign;
+	int ok;
+	FILE *out = vpb->options->print_all ? stdout : stderr;
+
+	vpb->n--;
+
+	if (1) {
+		minmax = "ub";
+		sign = 1;
+	} else {
+		minmax = "lb";
+		sign = -1;
+	}
+
+	ctx = isl_point_get_ctx(pnt);
+	p = isl_printer_to_file(ctx, out);
+
+	isl_int_init(t);
+
+	pwf = isl_pw_qpolynomial_fold_copy(vpb->pwf);
+
+	nparam = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_param);
+	for (i = 0; i < nparam; ++i) {
+		isl_point_get_coordinate(pnt, isl_dim_param, i, &t);
+		pwf = isl_pw_qpolynomial_fold_fix_dim(pwf, isl_dim_param, i, t);
+	}
+
+	bound = isl_pw_qpolynomial_fold_eval(
+				    isl_pw_qpolynomial_fold_copy(vpb->bound),
+				    isl_point_copy(pnt));
+
+	dom = isl_pw_qpolynomial_fold_domain(isl_pw_qpolynomial_fold_copy(pwf));
+	bounded = isl_set_is_bounded(dom);
+
+	if (bounded < 0)
+		goto error;
+
+	if (!bounded)
+		opt = isl_pw_qpolynomial_fold_eval(
+				    isl_pw_qpolynomial_fold_copy(pwf),
+				    isl_set_sample_point(isl_set_copy(dom)));
+	else if (sign > 0)
+		opt = isl_pw_qpolynomial_fold_max(isl_pw_qpolynomial_fold_copy(pwf));
+	else
+		opt = isl_pw_qpolynomial_fold_min(isl_pw_qpolynomial_fold_copy(pwf));
+
+	nvar = isl_set_dim(dom, isl_dim_set);
+	if (vpb->exact && bounded)
+		ok = isl_val_eq(opt, bound);
+	else if (sign > 0)
+		ok = isl_val_le(opt, bound);
+	else
+		ok = isl_val_le(bound, opt);
+	if (ok < 0)
+		goto error;
+
+	if (vpb->options->print_all || !ok) {
+		p = isl_printer_print_str(p, minmax);
+		p = isl_printer_print_str(p, "(");
+		for (i = 0; i < nparam; ++i) {
+			if (i)
+				p = isl_printer_print_str(p, ", ");
+			isl_point_get_coordinate(pnt, isl_dim_param, i, &t);
+			p = isl_printer_print_isl_int(p, t);
+		}
+		p = isl_printer_print_str(p, ") = ");
+		p = isl_printer_print_val(p, bound);
+		p = isl_printer_print_str(p, ", ");
+		p = isl_printer_print_str(p, bounded ? "opt" : "sample");
+		p = isl_printer_print_str(p, " = ");
+		p = isl_printer_print_val(p, opt);
+		if (ok)
+			p = isl_printer_print_str(p, ". OK");
+		else
+			p = isl_printer_print_str(p, ". NOT OK");
+		p = isl_printer_end_line(p);
+	} else if ((vpb->n % vpb->stride) == 0) {
+		p = isl_printer_print_str(p, "o");
+		p = isl_printer_flush(p);
+	}
+
+	if (0) {
+error:
+		ok = 0;
+	}
+
+	isl_pw_qpolynomial_fold_free(pwf);
+	isl_val_free(bound);
+	isl_val_free(opt);
+	isl_point_free(pnt);
+	isl_set_free(dom);
+
+	isl_int_clear(t);
+
+	isl_printer_free(p);
+
+	if (!ok)
+		vpb->error = 1;
+
+	if (vpb->options->continue_on_error)
+		ok = 1;
+
+	return (vpb->n >= 1 && ok) ? 0 : -1;
+}
+
+static int check_solution(__isl_take isl_pw_qpolynomial_fold *pwf,
+	__isl_take isl_pw_qpolynomial_fold *bound, int exact,
+	struct bound_options *options)
+{
+	struct verify_point_bound vpb;
+	isl_int count, max;
+	isl_set *dom;
+	isl_set *context;
+	int i, r, n;
+
+	dom = isl_pw_qpolynomial_fold_domain(isl_pw_qpolynomial_fold_copy(pwf));
+	context = isl_set_params(isl_set_copy(dom));
+	context = isl_set_remove_divs(context);
+	context = set_bounds(context);
+
+	isl_int_init(count);
+	isl_int_init(max);
+
+	isl_int_set_si(max, 200);
+	r = isl_set_count_upto(context, max, &count);
+	assert(r >= 0);
+	n = isl_int_get_si(count);
+
+	isl_int_clear(max);
+	isl_int_clear(count);
+
+	vpb.options = options;
+	vpb.pwf = pwf;
+	vpb.bound = bound;
+	vpb.n = n;
+	vpb.stride = n > 70 ? 1 + (n + 1)/70 : 1;
+	vpb.error = 0;
+	vpb.exact = exact;
+
+	if (!options->print_all) {
+		for (i = 0; i < vpb.n; i += vpb.stride)
+			printf(".");
+		printf("\r");
+		fflush(stdout);
+	}
+
+	isl_set_foreach_point(context, verify_point, &vpb);
+
+	isl_set_free(context);
+	isl_set_free(dom);
+	isl_pw_qpolynomial_fold_free(pwf);
+	isl_pw_qpolynomial_fold_free(bound);
+
+	if (!options->print_all)
+		printf("\n");
+
+	if (vpb.error) {
+		fprintf(stderr, "Check failed !\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+int main(int argc, char **argv)
+{
+	isl_ctx *ctx;
+	isl_pw_qpolynomial_fold *copy;
+	isl_pw_qpolynomial_fold *pwf;
+	struct isl_stream *s;
+	struct isl_obj obj;
+	struct bound_options *options;
+	int exact;
+	int r = 0;
+
+	options = bound_options_new_with_defaults();
+	assert(options);
+	argc = bound_options_parse(options, argc, argv, ISL_ARG_ALL);
+
+	ctx = isl_ctx_alloc_with_options(&bound_options_args, options);
+
+	s = isl_stream_new_file(ctx, stdin);
+	obj = isl_stream_read_obj(s);
+	if (obj.type == isl_obj_pw_qpolynomial)
+		pwf = isl_pw_qpolynomial_fold_from_pw_qpolynomial(isl_fold_max,
+								  obj.v);
+	else if (obj.type == isl_obj_pw_qpolynomial_fold)
+		pwf = obj.v;
+	else {
+		obj.type->free(obj.v);
+		isl_die(ctx, isl_error_invalid, "invalid input", goto error);
+	}
+
+	if (options->verify)
+		copy = isl_pw_qpolynomial_fold_copy(pwf);
+
+	pwf = isl_pw_qpolynomial_fold_bound(pwf, &exact);
+	pwf = isl_pw_qpolynomial_fold_coalesce(pwf);
+
+	if (options->verify) {
+		r = check_solution(copy, pwf, exact, options);
+	} else {
+		if (!exact)
+			printf("# NOT exact\n");
+		isl_pw_qpolynomial_fold_print(pwf, stdout, 0);
+		fprintf(stdout, "\n");
+		isl_pw_qpolynomial_fold_free(pwf);
+	}
+
+error:
+	isl_stream_free(s);
+
+	isl_ctx_free(ctx);
+
+	return r;
+}

Added: polly/trunk/lib/External/isl/bound_test.sh.in
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/bound_test.sh.in?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/bound_test.sh.in (added)
+++ polly/trunk/lib/External/isl/bound_test.sh.in Wed Feb  4 14:55:43 2015
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+EXEEXT=@EXEEXT@
+
+BOUND_TESTS="\
+	basicLinear2.pwqp \
+	basicLinear.pwqp \
+	basicTestParameterPosNeg.pwqp \
+	basicTest.pwqp \
+	devos.pwqp \
+	equality1.pwqp \
+	equality2.pwqp \
+	equality3.pwqp \
+	equality4.pwqp \
+	equality5.pwqp \
+	faddeev.pwqp \
+	linearExample.pwqp \
+	neg.pwqp \
+	philippe3vars3pars.pwqp \
+	philippe3vars.pwqp \
+	philippeNeg.pwqp \
+	philippePolynomialCoeff1P.pwqp \
+	philippePolynomialCoeff.pwqp \
+	philippe.pwqp \
+	product.pwqp \
+	split.pwqp \
+	test3Deg3Var.pwqp \
+	toplas.pwqp \
+	unexpanded.pwqp"
+
+for i in $BOUND_TESTS; do
+	echo $i;
+	./isl_bound$EXEEXT -T --bound=bernstein < $srcdir/test_inputs/$i || exit
+	./isl_bound$EXEEXT -T --bound=range < $srcdir/test_inputs/$i || exit
+done

Propchange: polly/trunk/lib/External/isl/bound_test.sh.in
------------------------------------------------------------------------------
    svn:executable = *

Added: polly/trunk/lib/External/isl/cat.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/cat.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/cat.c (added)
+++ polly/trunk/lib/External/isl/cat.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,58 @@
+#include <assert.h>
+#include <isl/obj.h>
+#include <isl/printer.h>
+#include <isl/stream.h>
+#include <isl/options.h>
+
+struct isl_arg_choice cat_format[] = {
+	{"isl",		ISL_FORMAT_ISL},
+	{"omega",	ISL_FORMAT_OMEGA},
+	{"polylib",	ISL_FORMAT_POLYLIB},
+	{"ext-polylib",	ISL_FORMAT_EXT_POLYLIB},
+	{"latex",	ISL_FORMAT_LATEX},
+	{0}
+};
+
+struct cat_options {
+	struct isl_options	*isl;
+	unsigned		 format;
+};
+
+ISL_ARGS_START(struct cat_options, cat_options_args)
+ISL_ARG_CHILD(struct cat_options, isl, "isl", &isl_options_args, "isl options")
+ISL_ARG_CHOICE(struct cat_options, format, 0, "format", \
+	cat_format,	ISL_FORMAT_ISL, "output format")
+ISL_ARGS_END
+
+ISL_ARG_DEF(cat_options, struct cat_options, cat_options_args)
+
+int main(int argc, char **argv)
+{
+	struct isl_ctx *ctx;
+	struct isl_stream *s;
+	struct isl_obj obj;
+	struct cat_options *options;
+	isl_printer *p;
+
+	options = cat_options_new_with_defaults();
+	assert(options);
+	argc = cat_options_parse(options, argc, argv, ISL_ARG_ALL);
+
+	ctx = isl_ctx_alloc_with_options(&cat_options_args, options);
+
+	s = isl_stream_new_file(ctx, stdin);
+	obj = isl_stream_read_obj(s);
+	isl_stream_free(s);
+
+	p = isl_printer_to_file(ctx, stdout);
+	p = isl_printer_set_output_format(p, options->format);
+	p = obj.type->print(p, obj.v);
+	p = isl_printer_end_line(p);
+	isl_printer_free(p);
+
+	obj.type->free(obj.v);
+
+	isl_ctx_free(ctx);
+
+	return 0;
+}

Added: polly/trunk/lib/External/isl/closure.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/closure.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/closure.c (added)
+++ polly/trunk/lib/External/isl/closure.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,34 @@
+#include <assert.h>
+#include <isl/map.h>
+#include <isl/options.h>
+
+int main(int argc, char **argv)
+{
+	struct isl_ctx *ctx;
+	struct isl_map *map;
+	struct isl_options *options;
+	int exact;
+
+	options = isl_options_new_with_defaults();
+	assert(options);
+	argc = isl_options_parse(options, argc, argv, ISL_ARG_ALL);
+
+	ctx = isl_ctx_alloc_with_options(&isl_options_args, options);
+
+	map = isl_map_read_from_file(ctx, stdin);
+	map = isl_map_transitive_closure(map, &exact);
+	if (!exact)
+		printf("# NOT exact\n");
+	isl_map_print(map, stdout, 0, ISL_FORMAT_ISL);
+	printf("\n");
+	map = isl_map_compute_divs(map);
+	map = isl_map_coalesce(map);
+	printf("# coalesced\n");
+	isl_map_print(map, stdout, 0, ISL_FORMAT_ISL);
+	printf("\n");
+	isl_map_free(map);
+
+	isl_ctx_free(ctx);
+
+	return 0;
+}

Added: polly/trunk/lib/External/isl/codegen.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/codegen.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/codegen.c (added)
+++ polly/trunk/lib/External/isl/codegen.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2012      Ecole Normale Superieure
+ *
+ * Use of this software is governed by the MIT license
+ *
+ * Written by Sven Verdoolaege,
+ * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
+ */
+
+/* This program prints an AST that scans the domain elements of
+ * the domain of a given schedule in the order of their image(s).
+ *
+ * The input consists of three sets/relations.
+ * - a schedule
+ * - a context
+ * - a relation describing AST generation options
+ */
+
+#include <assert.h>
+#include <isl/ast.h>
+#include <isl/ast_build.h>
+#include <isl/options.h>
+#include <isl/set.h>
+
+struct options {
+	struct isl_options	*isl;
+	unsigned		 atomic;
+	unsigned		 separate;
+};
+
+ISL_ARGS_START(struct options, options_args)
+ISL_ARG_CHILD(struct options, isl, "isl", &isl_options_args, "isl options")
+ISL_ARG_BOOL(struct options, atomic, 0, "atomic", 0,
+	"globally set the atomic option")
+ISL_ARG_BOOL(struct options, separate, 0, "separate", 0,
+	"globally set the separate option")
+ISL_ARGS_END
+
+ISL_ARG_DEF(options, struct options, options_args)
+
+/* Return a universal, 1-dimensional set with the given name.
+ */
+static __isl_give isl_union_set *universe(isl_ctx *ctx, const char *name)
+{
+	isl_space *space;
+
+	space = isl_space_set_alloc(ctx, 0, 1);
+	space = isl_space_set_tuple_name(space, isl_dim_set, name);
+	return isl_union_set_from_set(isl_set_universe(space));
+}
+
+/* Set the "name" option for the entire schedule domain.
+ */
+static __isl_give isl_union_map *set_universe(__isl_take isl_union_map *opt,
+	__isl_keep isl_union_map *schedule, const char *name)
+{
+	isl_ctx *ctx;
+	isl_union_set *domain, *target;
+	isl_union_map *option;
+
+	ctx = isl_union_map_get_ctx(opt);
+
+	domain = isl_union_map_range(isl_union_map_copy(schedule));
+	domain = isl_union_set_universe(domain);
+	target = universe(ctx, name);
+	option = isl_union_map_from_domain_and_range(domain, target);
+	opt = isl_union_map_union(opt, option);
+
+	return opt;
+}
+
+/* Update the build options based on the user-specified options.
+ *
+ * If the --separate or --atomic options were specified, then
+ * we clear any separate or atomic options that may already exist in "opt".
+ */
+static __isl_give isl_ast_build *set_options(__isl_take isl_ast_build *build,
+	__isl_take isl_union_map *opt, struct options *options,
+	__isl_keep isl_union_map *schedule)
+{
+	if (options->separate || options->atomic) {
+		isl_ctx *ctx;
+		isl_union_set *target;
+
+		ctx = isl_union_map_get_ctx(schedule);
+
+		target = universe(ctx, "separate");
+		opt = isl_union_map_subtract_range(opt, target);
+		target = universe(ctx, "atomic");
+		opt = isl_union_map_subtract_range(opt, target);
+	}
+
+	if (options->separate)
+		opt = set_universe(opt, schedule, "separate");
+	if (options->atomic)
+		opt = set_universe(opt, schedule, "atomic");
+
+	build = isl_ast_build_set_options(build, opt);
+
+	return build;
+}
+
+int main(int argc, char **argv)
+{
+	isl_ctx *ctx;
+	isl_set *context;
+	isl_union_map *schedule;
+	isl_union_map *options_map;
+	isl_ast_build *build;
+	isl_ast_node *tree;
+	struct options *options;
+	isl_printer *p;
+
+	options = options_new_with_defaults();
+	assert(options);
+	argc = options_parse(options, argc, argv, ISL_ARG_ALL);
+
+	ctx = isl_ctx_alloc_with_options(&options_args, options);
+
+	schedule = isl_union_map_read_from_file(ctx, stdin);
+	context = isl_set_read_from_file(ctx, stdin);
+	options_map = isl_union_map_read_from_file(ctx, stdin);
+
+	build = isl_ast_build_from_context(context);
+	build = set_options(build, options_map, options, schedule);
+	tree = isl_ast_build_ast_from_schedule(build, schedule);
+	isl_ast_build_free(build);
+
+	p = isl_printer_to_file(ctx, stdout);
+	p = isl_printer_set_output_format(p, ISL_FORMAT_C);
+	p = isl_printer_print_ast_node(p, tree);
+	isl_printer_free(p);
+
+	isl_ast_node_free(tree);
+
+	isl_ctx_free(ctx);
+	return 0;
+}

Added: polly/trunk/lib/External/isl/codegen_test.sh.in
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/codegen_test.sh.in?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/codegen_test.sh.in (added)
+++ polly/trunk/lib/External/isl/codegen_test.sh.in Wed Feb  4 14:55:43 2015
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+EXEEXT=@EXEEXT@
+srcdir=@srcdir@
+
+failed=0
+
+for i in $srcdir/test_inputs/codegen/*.in \
+		$srcdir/test_inputs/codegen/cloog/*.in \
+		$srcdir/test_inputs/codegen/omega/*.in \
+		$srcdir/test_inputs/codegen/pldi2012/*.in; do
+	echo $i;
+	base=`basename $i .in`
+	test=test-$base.c
+	dir=`dirname $i`
+	ref=$dir/$base.c
+	(./isl_codegen$EXEEXT < $i > $test &&
+	 diff -uw $ref $test && rm $test) || failed=1
+done
+
+test $failed -eq 0 || exit

Added: polly/trunk/lib/External/isl/configure.ac
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/configure.ac?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/configure.ac (added)
+++ polly/trunk/lib/External/isl/configure.ac Wed Feb  4 14:55:43 2015
@@ -0,0 +1,236 @@
+AC_INIT([isl], [0.14], [isl-development at googlegroups.com])
+AC_CONFIG_AUX_DIR([.])
+AC_CONFIG_MACRO_DIR([m4])
+AM_INIT_AUTOMAKE([foreign])
+m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
+AC_SUBST(versioninfo)
+versioninfo=14:0:1
+
+if test "x$prefix" != "xNONE"; then
+	prefix_wd=`cd $prefix && pwd`
+	srcdir_wd=`cd $srcdir && pwd`
+	wd=`pwd`
+	if test "x$prefix_wd" = "x$srcdir_wd"; then
+		AC_MSG_ERROR(Installation in source directory not supported)
+	fi
+	if test "x$prefix_wd" = "x$wd"; then
+		AC_MSG_ERROR(Installation in build directory not supported)
+	fi
+fi
+
+AC_PROG_CC
+AC_PROG_CXX
+
+AX_CC_MAXOPT
+AX_GCC_WARN_UNUSED_RESULT
+AX_C___ATTRIBUTE__
+
+AC_PROG_LIBTOOL
+
+AC_CHECK_PROG(PERL, perl, perl, [])
+AC_CHECK_PROG(PDFLATEX, pdflatex, pdflatex, [])
+AC_CHECK_PROG(POD2HTML, pod2html, pod2html, [])
+
+AM_CONDITIONAL(GENERATE_DOC, test -n "$PERL" -a -n "$PDFLATEX" -a -n "$POD2HTML")
+
+AX_CREATE_STDINT_H(include/isl/stdint.h)
+
+AC_ARG_WITH([int],
+	    [AS_HELP_STRING([--with-int=gmp|imath],
+			    [Which package to use to represent
+				multi-precision integers [default=gmp]])],
+	    [], [with_int=gmp])
+case "$with_int" in
+gmp|imath)
+	;;
+*)
+	AC_MSG_ERROR([bad value ${withval} for --with-int (use gmp or imath)])
+esac
+
+AC_SUBST(MP_CPPFLAGS)
+AC_SUBST(MP_LDFLAGS)
+AC_SUBST(MP_LIBS)
+case "$with_int" in
+gmp)
+	AX_DETECT_GMP
+	;;
+imath)
+	AX_DETECT_IMATH
+	;;
+esac
+
+AM_CONDITIONAL(IMATH_FOR_MP, test x$with_int = ximath)
+AM_CONDITIONAL(GMP_FOR_MP, test x$with_int = xgmp)
+AC_CHECK_DECLS(ffs,[],[],[#include <strings.h>])
+AC_CHECK_DECLS(__builtin_ffs,[],[],[])
+
+AC_SUBST(CLANG_CXXFLAGS)
+AC_SUBST(CLANG_LDFLAGS)
+AC_SUBST(CLANG_LIBS)
+AX_SUBMODULE(clang,system|no,no)
+case "$with_clang" in
+system)
+	AC_PROG_GREP
+	llvm_config="llvm-config"
+	AC_CHECK_PROG([llvm_config_found], ["$llvm_config"], [yes])
+	if test "x$with_clang_prefix" != "x"; then
+		llvm_config="$with_clang_prefix/bin/llvm-config"
+		if test -x "$llvm_config"; then
+			llvm_config_found=yes
+		fi
+	fi
+	if test "$llvm_config_found" != yes; then
+		AC_MSG_ERROR([llvm-config not found])
+	fi
+	CLANG_CXXFLAGS=`$llvm_config --cxxflags`
+	CLANG_LDFLAGS=`$llvm_config --ldflags`
+	targets=`$llvm_config --targets-built`
+	components="$targets asmparser bitreader support mc"
+	$llvm_config --components | $GREP option > /dev/null 2> /dev/null
+	if test $? -eq 0; then
+		components="$components option"
+	fi
+	CLANG_LIBS=`$llvm_config --libs $components`
+	systemlibs=`$llvm_config --system-libs 2> /dev/null | tail -1`
+	if test $? -eq 0; then
+		CLANG_LIBS="$CLANG_LIBS $systemlibs"
+	fi
+	CLANG_PREFIX=`$llvm_config --prefix`
+	AC_DEFINE_UNQUOTED(CLANG_PREFIX, ["$CLANG_PREFIX"],
+				[Clang installation prefix])
+
+	SAVE_CPPFLAGS="$CPPFLAGS"
+	CPPFLAGS="$CLANG_CXXFLAGS $CPPFLAGS"
+	AC_LANG_PUSH(C++)
+	AC_CHECK_HEADER([clang/Basic/SourceLocation.h], [],
+		[AC_ERROR([clang header file not found])])
+	AC_EGREP_HEADER([getDefaultTargetTriple], [llvm/Support/Host.h], [],
+		[AC_DEFINE([getDefaultTargetTriple], [getHostTriple],
+		[Define to getHostTriple for older versions of clang])])
+	AC_EGREP_HEADER([getExpansionLineNumber],
+		[clang/Basic/SourceLocation.h], [],
+		[AC_DEFINE([getExpansionLineNumber],
+			[getInstantiationLineNumber],
+	    [Define to getInstantiationLineNumber for older versions of clang])])
+	AC_EGREP_HEADER([DiagnosticsEngine],
+		[clang/Basic/Diagnostic.h], [],
+		[AC_DEFINE([DiagnosticsEngine],
+			[Diagnostic],
+	    [Define to Diagnostic for older versions of clang])])
+	AC_EGREP_HEADER([ArrayRef], [clang/Driver/Driver.h],
+		[AC_DEFINE([USE_ARRAYREF], [],
+			[Define if Driver::BuildCompilation takes ArrayRef])])
+	AC_EGREP_HEADER([CXXIsProduction], [clang/Driver/Driver.h],
+		[AC_DEFINE([HAVE_CXXISPRODUCTION], [],
+		[Define if Driver constructor takes CXXIsProduction argument])])
+	AC_EGREP_HEADER([ IsProduction], [clang/Driver/Driver.h],
+		[AC_DEFINE([HAVE_ISPRODUCTION], [],
+		[Define if Driver constructor takes IsProduction argument])])
+	AC_TRY_COMPILE([#include <clang/Driver/Driver.h>], [
+		using namespace clang;
+		DiagnosticsEngine *Diags;
+		new driver::Driver("", "", "", *Diags);
+	], [AC_DEFINE([DRIVER_CTOR_TAKES_DEFAULTIMAGENAME], [],
+		      [Define if Driver constructor takes default image name])])
+	AC_EGREP_HEADER([void HandleTopLevelDecl\(], [clang/AST/ASTConsumer.h],
+		[AC_DEFINE([HandleTopLevelDeclReturn], [void],
+			   [Return type of HandleTopLevelDeclReturn])
+		 AC_DEFINE([HandleTopLevelDeclContinue], [],
+			   [Return type of HandleTopLevelDeclReturn])],
+		[AC_DEFINE([HandleTopLevelDeclReturn], [bool],
+			   [Return type of HandleTopLevelDeclReturn])
+		 AC_DEFINE([HandleTopLevelDeclContinue], [true],
+			   [Return type of HandleTopLevelDeclReturn])])
+	AC_CHECK_HEADER([clang/Basic/DiagnosticOptions.h],
+		[AC_DEFINE([HAVE_BASIC_DIAGNOSTICOPTIONS_H], [],
+			   [Define if clang/Basic/DiagnosticOptions.h exists])])
+	AC_TRY_COMPILE([#include <clang/Basic/TargetInfo.h>], [
+		using namespace clang;
+		std::shared_ptr<TargetOptions> TO;
+		DiagnosticsEngine *Diags;
+		TargetInfo::CreateTargetInfo(*Diags, TO);
+	], [AC_DEFINE([CREATETARGETINFO_TAKES_SHARED_PTR], [],
+		    [Define if TargetInfo::CreateTargetInfo takes shared_ptr])])
+	AC_TRY_COMPILE([#include <clang/Basic/TargetInfo.h>], [
+		using namespace clang;
+		TargetOptions *TO;
+		DiagnosticsEngine *Diags;
+		TargetInfo::CreateTargetInfo(*Diags, TO);
+	], [AC_DEFINE([CREATETARGETINFO_TAKES_POINTER], [],
+		      [Define if TargetInfo::CreateTargetInfo takes pointer])])
+	AC_TRY_COMPILE([#include <clang/Frontend/CompilerInstance.h>], [
+		using namespace clang;
+		DiagnosticConsumer *client;
+		CompilerInstance *Clang;
+		Clang->createDiagnostics(client);
+	], [], [AC_DEFINE([CREATEDIAGNOSTICS_TAKES_ARG], [],
+	[Define if CompilerInstance::createDiagnostics takes argc and argv])])
+	AC_TRY_COMPILE([#include <clang/Lex/HeaderSearchOptions.h>], [
+		using namespace clang;
+		HeaderSearchOptions HSO;
+		HSO.AddPath("", frontend::Angled, false, false);
+	], [AC_DEFINE([ADDPATH_TAKES_4_ARGUMENTS], [],
+		[Define if HeaderSearchOptions::AddPath takes 4 arguments])])
+	AC_EGREP_HEADER([getNumParams],
+		[clang/AST/CanonicalType.h],
+		[AC_DEFINE([getNumArgs], [getNumParams],
+		    [Define to getNumParams for newer versions of clang])
+		 AC_DEFINE([getArgType], [getParamType],
+		    [Define to getParamType for newer versions of clang])])
+	AC_EGREP_HEADER([getReturnType],
+		[clang/AST/CanonicalType.h], [],
+		[AC_DEFINE([getReturnType], [getResultType],
+		    [Define to getResultType for older versions of clang])])
+	AC_TRY_COMPILE([#include <clang/Frontend/CompilerInstance.h>], [
+		using namespace clang;
+		CompilerInstance *Clang;
+		Clang->createPreprocessor(TU_Complete);
+	], [AC_DEFINE([CREATEPREPROCESSOR_TAKES_TUKIND], [],
+	[Define if CompilerInstance::createPreprocessor takes
+	 TranslationUnitKind])])
+	AC_EGREP_HEADER([setMainFileID], [clang/Basic/SourceManager.h],
+		[AC_DEFINE([HAVE_SETMAINFILEID], [],
+		[Define if SourceManager has a setMainFileID method])])
+	AC_CHECK_HEADER([llvm/ADT/OwningPtr.h],
+		[AC_DEFINE([HAVE_ADT_OWNINGPTR_H], [],
+			   [Define if llvm/ADT/OwningPtr.h exists])])
+	AC_LANG_POP
+	CPPFLAGS="$SAVE_CPPFLAGS"
+
+	SAVE_LDFLAGS="$LDFLAGS"
+	LDFLAGS="$CLANG_LDFLAGS $LDFLAGS"
+	AC_SUBST(LIB_CLANG_EDIT)
+	AC_CHECK_LIB([clangEdit], [main], [LIB_CLANG_EDIT=-lclangEdit], [])
+	LDFLAGS="$SAVE_LDFLAGS"
+	;;
+esac
+AM_CONDITIONAL(HAVE_CLANG, test $with_clang = system)
+
+AX_SET_WARNING_FLAGS
+
+AC_SUBST(WARNING_FLAGS)
+
+PACKAGE_CFLAGS="$MP_CPPFLAGS"
+PACKAGE_LDFLAGS="$MP_LDFLAGS"
+PACKAGE_LIBS="-lisl $MP_LIBS"
+AX_CREATE_PKGCONFIG_INFO
+
+AX_DETECT_GIT_HEAD
+echo '#define GIT_HEAD_ID "'$GIT_HEAD_ID'"' > gitversion.h
+
+AH_BOTTOM([#include <isl_config_post.h>])
+AC_CONFIG_HEADERS(isl_config.h)
+AC_CONFIG_FILES(Makefile)
+AC_CONFIG_FILES(doc/Makefile)
+if test $with_clang = system; then
+	AC_CONFIG_FILES(interface/Makefile)
+fi
+AC_CONFIG_FILES([bound_test.sh], [chmod +x bound_test.sh])
+AC_CONFIG_FILES([codegen_test.sh], [chmod +x codegen_test.sh])
+AC_CONFIG_FILES([pip_test.sh], [chmod +x pip_test.sh])
+AC_CONFIG_COMMANDS_POST([
+	dnl pass on arguments to subdir configures, but don't
+	dnl add them to config.status
+	ac_configure_args="$ac_configure_args $isl_configure_args"
+])
+AC_OUTPUT

Added: polly/trunk/lib/External/isl/doc/Makefile.am
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/doc/Makefile.am?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/doc/Makefile.am (added)
+++ polly/trunk/lib/External/isl/doc/Makefile.am Wed Feb  4 14:55:43 2015
@@ -0,0 +1,17 @@
+if GENERATE_DOC
+export TEXINPUTS := $(srcdir):$(TEXINPUTS)
+export BIBINPUTS := $(srcdir):$(BIBINPUTS)
+export BSTINPUTS := $(srcdir):$(BSTINPUTS)
+
+user.tex: user.pod
+	$(PERL) $(srcdir)/mypod2latex $< $@
+manual.pdf: manual.tex user.tex $(srcdir)/implementation.tex
+	(cd ..; echo "@GIT_HEAD_VERSION@") > version.tex
+	$(PDFLATEX) $<
+	bibtex manual
+	$(PDFLATEX) $<
+	$(PDFLATEX) $<
+user.html: user.pod
+	(cd ..; echo "@GIT_HEAD_VERSION@") > version
+	$(POD2HTML) --infile=$< --outfile=$@ --title="Integer Set Library: Manual [version `cat version`]"
+endif

Added: polly/trunk/lib/External/isl/doc/SubmittingPatches
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/doc/SubmittingPatches?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/doc/SubmittingPatches (added)
+++ polly/trunk/lib/External/isl/doc/SubmittingPatches Wed Feb  4 14:55:43 2015
@@ -0,0 +1,52 @@
+[Mostly copied from git's SubmittingPatches]
+
+	Commits:
+
+	- make commits of logical units
+	- check for unnecessary whitespace with "git diff --check"
+	  before committing
+	- do not check in commented out code or unneeded files
+	- the first line of the commit message should be a short
+	  description and should skip the full stop
+	- the body should provide a meaningful commit message, which
+	  includes motivation for the change, and contrasts
+	  its implementation with previous behaviour
+	- if you want your work included in isl.git, add a
+	  "Signed-off-by: Your Name <you at example.com>" line to the
+	  commit message (or just use the option "-s" when
+	  committing) to confirm that you agree to the Developer's
+	  Certificate of Origin
+	- make sure that you have tests for the bug you are fixing
+	- make sure that the test suite passes after your commit
+
+	Patch:
+
+	- use "git format-patch -M" to create the patch
+	- do not PGP sign your patch
+	- send a single patch per mail, e.g., using git-send-email(1)
+	- do not attach your patch, but read in the mail
+	  body, unless you cannot teach your mailer to
+	  leave the formatting of the patch alone.
+	- be careful doing cut & paste into your mailer, not to
+	  corrupt whitespaces.
+	- provide additional information (which is unsuitable for
+	  the commit message) between the "---" and the diffstat
+	- if you change, add, or remove a command line option or
+	  make some other user interface change, the associated
+	  documentation should be updated as well.
+	- if your name is not writable in ASCII, make sure that
+	  you send off a message in the correct encoding.
+	- send the patch to the development mailing list
+	  (isl-development at googlegroups.com).  If you use
+	  git-send-email(1), please test it first by sending email
+	  to yourself.
+
+	Revisions:
+
+	- add the revision number inside square brackets to
+	  the subject line (e.g., use --subject-prefix='PATCH v2'
+	  when creating the patch)
+	- recall the major issues discovered during the previous
+	  review and explain how you addressed them or why you
+	  disagree.  Do so either in a cover letter, between the
+	  "---" and the diffstat or in a separate message.

Added: polly/trunk/lib/External/isl/doc/chicago.bst
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/doc/chicago.bst?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/doc/chicago.bst (added)
+++ polly/trunk/lib/External/isl/doc/chicago.bst Wed Feb  4 14:55:43 2015
@@ -0,0 +1,1726 @@
+%%% ====================================================================
+%%%  @BibTeX-style-file{
+%%%     author          = "Glenn Paulley",
+%%%     version         = "4",
+%%%     date            = "28 August 1992",
+%%%     time            = "10:23:39 199",
+%%%     filename        = "chicago.bst",
+%%%     address         = "Data Structuring Group
+%%%                        Department of Computer Science
+%%%                        University of Waterloo
+%%%                        Waterloo, Ontario, Canada
+%%%                        N2L 3G1",
+%%%     telephone       = "(519) 885-1211",
+%%%     FAX             = "(519) 885-1208",
+%%%     checksum        = "26323 1654 5143 37417",
+%%%     email           = "gnpaulle at bluebox.uwaterloo.ca",
+%%%     codetable       = "ISO/ASCII",
+%%%     keywords        = "",
+%%%     supported       = "yes",
+%%%     abstract        = "A BibTeX bibliography style that follows the
+%%%                        `B' reference style of the 13th Edition of
+%%%                        the Chicago Manual of Style. A detailed
+%%%                        feature list is given below.",
+%%%     docstring       = "The checksum field above contains a CRC-16
+%%%                        checksum as the first value, followed by the
+%%%                        equivalent of the standard UNIX wc (word
+%%%                        count) utility output of lines, words, and
+%%%                        characters.  This is produced by Robert
+%%%                        Solovay's checksum utility.",
+%%%  }
+%%% ====================================================================
+%
+% "Chicago" BibTeX style, chicago.bst
+% ===================================
+%
+% BibTeX `chicago' style file for BibTeX version 0.99c, LaTeX version 2.09
+% Place it in a file called chicago.bst in the BibTeX search path.
+% You need to include chicago.sty as a \documentstyle option.
+% (Placing it in the same directory as the LaTeX document should also work.)
+% This "chicago" style is based on newapa.bst (American Psych. Assoc.)
+% found at ymir.claremont.edu.
+%
+%   Citation format: (author-last-name year)
+%             (author-last-name and author-last-name year)
+%             (author-last-name, author-last-name, and author-last-name year)
+%             (author-last-name et al. year)
+%             (author-last-name)
+%             author-last-name (year)
+%             (author-last-name and author-last-name)
+%             (author-last-name et al.)
+%             (year) or (year,year)
+%             year or year,year
+%
+%   Reference list ordering: alphabetical by author or whatever passes
+%    for author in the absence of one.
+%
+% This BibTeX style has support for abbreviated author lists and for
+%    year-only citations.  This is done by having the citations
+%    actually look like
+%
+%    \citeauthoryear{full-author-info}{abbrev-author-info}{year}
+%
+% The LaTeX style has to have the following (or similar)
+%
+%     \let\@internalcite\cite
+%     \def\fullcite{\def\citeauthoryear##1##2##3{##1, ##3}\@internalcite}
+%     \def\fullciteA{\def\citeauthoryear##1##2##3{##1}\@internalcite}
+%     \def\shortcite{\def\citeauthoryear##1##2##3{##2, ##3}\@internalcite}
+%     \def\shortciteA{\def\citeauthoryear##1##2##3{##2}\@internalcite}
+%     \def\citeyear{\def\citeauthoryear##1##2##3{##3}\@internalcite}
+%
+% These TeX macro definitions are found in chicago.sty. Additional
+% commands to manipulate different components of a citation can be defined
+% so that, for example, you can list author's names without parentheses
+% if using a citation as a noun or object in a sentence.
+%
+% This file was originally copied from newapa.bst at ymir.claremont.edu.
+%
+% Features of chicago.bst:
+% =======================
+%
+% - full names used in citations, but abbreviated citations are available
+%   (see above)
+% - if an entry has a "month", then the month and year are also printed
+%   as part of that bibitem.
+% - all conjunctions use "and" instead of "\&"
+% - major modification from Chicago Manual of Style (13th ed.) is that
+%   only the first author in a reference appears last name first-
+%   additional authors appear as J. Q. Public.
+% - pages are listed as "pp. xx-xx" in all entry types except
+%   article entries.
+% - book, inbook, and manual use "location: publisher" (or organization)
+%   for address and publisher. All other types list publishers separately.
+% - "pp." are used to identify page numbers for all entry types except
+%   articles.
+% - organization is used as a citation label if neither author nor editor
+%   is present (for manuals).
+% - "et al." is used for long author and editor lists, or when "others"
+%   is used.
+%
+% Modifications and bug fixes from newapa.bst:
+% ===========================================
+%
+%   - added month, year to bib entries if month is present
+%   - fixed bug with In proceedings, added necessary comma after title
+%   - all conjunctions changed to "and" from "\&"
+%   - fixed bug with author labels in my.full.label: "et al." now is
+%        generated when "others" is an author name
+%   - major modification from Chicago Manual of Style (13th ed.) is that
+%     only the first author in a reference appears last name first-
+%     additional authors appear as J. Q. Public.
+%   - pages are listed as "pp. xx-xx" in all entry types except
+%     article entries. Unnecessary (IMHO) "()" around page numbers
+%     were removed, and page numbers now don't end with a period.
+%   - created chicago.sty for use with this bibstyle (required).
+%   - fixed bugs in FUNCTION {format.vol.num.pages} for missing volume,
+%     number, and /or pages. Renamed to format.jour.vol.
+%   - fixed bug in formatting booktitles: additional period an error if
+%     book has a volume.
+%   - fixed bug: editors usually given redundant period before next clause
+%     (format.editors.dot) removed.
+%   - added label support for organizations, if both author and editor
+%     are missing (from alpha.bst). If organization is too long, then
+%     the key field is used for abbreviated citations.
+%   - In proceedings or books of several volumes, no comma was written
+%     between the "Volume x" and the page numbers (this was intentional
+%     in newapa.bst). Fixed.
+%   - Some journals may not have volumes/numbers, only month/year (eg.
+%     IEEE Computer). Fixed bug in article style that assumed volume/number
+%     was always present.
+%
+% Original documentation for newapa.sty:
+% =====================================
+%
+% This version was made by modifying the master file made by
+% Oren Patashnik (PATASHNIK at SCORE.STANFORD.EDU), and the 'named' BibTeX
+% style of Peter F. Patel-Schneider.
+%
+% Copyright (C) 1985, all rights reserved.
+% Copying of this file is authorized only if either
+% (1) you make absolutely no changes to your copy, including name, or
+% (2) if you do make changes, you name it something other than 'newapa.bst'.
+% There are undoubtably bugs in this style.  If you make bug fixes,
+% improvements, etc.  please let me know.  My e-mail address is:
+%    spencer at cgrg.ohio.state.edu or 71160.3141 at compuserve.com
+%
+% This style was made from 'plain.bst', 'named.bst', and 'apalike.bst',
+% with lots of tweaking to make it look like APA style, along with tips
+% from Young Ryu and Brian Reiser's modifications of 'apalike.bst'.
+
+ENTRY
+  { address
+    author
+    booktitle
+    chapter
+    edition
+    editor
+    fjournal
+    howpublished
+    institution
+    journal
+    key
+    month
+    note
+    number
+    organization
+    pages
+    publisher
+    school
+    series
+    title
+    type
+    volume
+    year
+  }
+  {}
+  { label.year extra.label sort.year sort.label }
+
+INTEGERS { output.state before.all mid.sentence after.sentence after.block }
+
+FUNCTION {init.state.consts}
+{ #0 'before.all :=
+  #1 'mid.sentence :=
+  #2 'after.sentence :=
+  #3 'after.block :=
+}
+
+STRINGS { s t u }
+
+FUNCTION {output.nonnull}
+{ 's :=
+  output.state mid.sentence =
+    { ", " * write$ }
+    { output.state after.block =
+    { add.period$ write$
+      newline$
+      "\newblock " write$
+    }
+    { output.state before.all =
+        'write$
+        { add.period$ " " * write$ }
+      if$
+    }
+      if$
+      mid.sentence 'output.state :=
+    }
+  if$
+  s
+}
+
+% Use a colon to separate output. Used only for address/publisher
+% combination in book/inbook types, address/institution for manuals,
+% and organization:publisher for proceedings (inproceedings).
+%
+FUNCTION {output.nonnull.colon}
+{ 's :=
+  output.state mid.sentence =
+    { ": " * write$ }
+    { output.state after.block =
+    { add.period$ write$
+      newline$
+      "\newblock " write$
+    }
+    { output.state before.all =
+        'write$
+        { add.period$ " " * write$ }
+      if$
+    }
+      if$
+      mid.sentence 'output.state :=
+    }
+  if$
+  s
+}
+
+FUNCTION {output}
+{ duplicate$ empty$
+    'pop$
+    'output.nonnull
+  if$
+}
+
+FUNCTION {output.colon}
+{ duplicate$ empty$
+    'pop$
+    'output.nonnull.colon
+  if$
+}
+
+FUNCTION {output.check}
+{ 't :=
+  duplicate$ empty$
+    { pop$ "empty " t * " in " * cite$ * warning$ }
+    'output.nonnull
+  if$
+}
+
+FUNCTION {output.check.colon}
+{ 't :=
+  duplicate$ empty$
+    { pop$ "empty " t * " in " * cite$ * warning$ }
+    'output.nonnull.colon
+  if$
+}
+
+FUNCTION {output.year.check}
+{ year empty$
+     { "empty year in " cite$ * warning$ }
+     { write$
+        " (" year * extra.label *
+       month empty$
+          { ")" * }
+          { ", " * month * ")" * }
+       if$
+       mid.sentence 'output.state :=
+     }
+  if$
+}
+
+
+FUNCTION {fin.entry}
+{ add.period$
+  write$
+  newline$
+}
+
+FUNCTION {new.block}
+{ output.state before.all =
+    'skip$
+    { after.block 'output.state := }
+  if$
+}
+
+FUNCTION {new.sentence}
+{ output.state after.block =
+    'skip$
+    { output.state before.all =
+    'skip$
+    { after.sentence 'output.state := }
+      if$
+    }
+  if$
+}
+
+FUNCTION {not}
+{   { #0 }
+    { #1 }
+  if$
+}
+
+FUNCTION {and}
+{   'skip$
+    { pop$ #0 }
+  if$
+}
+
+FUNCTION {or}
+{   { pop$ #1 }
+    'skip$
+  if$
+}
+
+FUNCTION {new.block.checka}
+{ empty$
+    'skip$
+    'new.block
+  if$
+}
+
+FUNCTION {new.block.checkb}
+{ empty$
+  swap$ empty$
+  and
+    'skip$
+    'new.block
+  if$
+}
+
+FUNCTION {new.sentence.checka}
+{ empty$
+    'skip$
+    'new.sentence
+  if$
+}
+
+FUNCTION {new.sentence.checkb}
+{ empty$
+  swap$ empty$
+  and
+    'skip$
+    'new.sentence
+  if$
+}
+
+FUNCTION {field.or.null}
+{ duplicate$ empty$
+    { pop$ "" }
+    'skip$
+  if$
+}
+
+%
+% Emphasize the top string on the stack.
+%
+FUNCTION {emphasize}
+{ duplicate$ empty$
+    { pop$ "" }
+    { "{\em " swap$ * "}" * }
+  if$
+}
+
+%
+% Emphasize the top string on the stack, but add a trailing space.
+%
+FUNCTION {emphasize.space}
+{ duplicate$ empty$
+    { pop$ "" }
+    { "{\em " swap$ * "\/}" * }
+  if$
+}
+
+INTEGERS { nameptr namesleft numnames }
+%
+% Format bibliographical entries with the first author last name first,
+% and subsequent authors with initials followed by last name.
+% All names are formatted in this routine.
+%
+FUNCTION {format.names}
+{ 's :=
+  #1 'nameptr :=               % nameptr = 1;
+  s num.names$ 'numnames :=    % numnames = num.name$(s);
+  numnames 'namesleft :=
+    { namesleft #0 > }
+
+    { nameptr #1 =
+        {s nameptr "{vv~}{ll}{, jj}{, f.}" format.name$ 't := }
+        {s nameptr "{f.~}{vv~}{ll}{, jj}" format.name$ 't := }
+      if$
+      nameptr #1 >
+        { namesleft #1 >
+              { ", " * t * }
+              { numnames #2 >
+                  { "," * }
+                  'skip$
+                if$
+                t "others" =
+                    { " et~al." * }
+                    { " and " * t * } % from Chicago Manual of Style
+                  if$
+               }
+               if$
+             }
+            't
+        if$
+        s nameptr "{vv~}{ll}{, jj}{, f.}" format.name$ 't := 
+	"\protect \index {" * t * "|hyperemph}" *
+        nameptr #1 + 'nameptr :=          % nameptr += 1;
+        namesleft #1 - 'namesleft :=      % namesleft =- 1;
+    }
+  while$
+}
+
+FUNCTION {my.full.label}
+{ 's :=
+  #1 'nameptr :=               % nameptr = 1;
+  s num.names$ 'numnames :=    % numnames = num.name$(s);
+  numnames 'namesleft :=
+    { namesleft #0 > }
+
+    { s nameptr "{vv~}{ll}" format.name$ 't :=  % get the next name
+      nameptr #1 >
+        { namesleft #1 >
+              { ", " * t * }
+              { numnames #2 >
+                  { "," * }
+                  'skip$
+                if$
+                t "others" =
+                    { " et~al." * }
+                    { " and " * t * } % from Chicago Manual of Style
+                  if$
+               }
+               if$
+             }
+            't
+        if$
+        s nameptr "{vv~}{ll}{, jj}{, f.}" format.name$ 't := 
+	"\protect \index {" * t * "|bold}" *
+        nameptr #1 + 'nameptr :=          % nameptr += 1;
+        namesleft #1 - 'namesleft :=      % namesleft =- 1;
+    }
+  while$
+
+}
+
+FUNCTION {format.names.fml}
+%
+% Format names in "familiar" format, with first initial followed by
+% last name. Like format.names, ALL names are formatted.
+%
+{ 's :=
+  #1 'nameptr :=               % nameptr = 1;
+  s num.names$ 'numnames :=    % numnames = num.name$(s);
+  numnames 'namesleft :=
+    { namesleft #0 > }
+
+    { s nameptr "{f.~}{vv~}{ll}{, jj}" format.name$ 't :=
+
+      nameptr #1 >
+        { namesleft #1 >
+              { ", " * t * }
+               { numnames #2 >
+                    { "," * }
+                    'skip$
+                  if$
+                  t "others" =
+                        { " et~al." * }
+                        { " and " * t * }
+%                       { " \& " * t * }
+                      if$
+                }
+               if$
+             }
+            't
+        if$
+        nameptr #1 + 'nameptr :=          % nameptr += 1;
+        namesleft #1 - 'namesleft :=      % namesleft =- 1;
+    }
+  while$
+}
+
+FUNCTION {format.authors}
+{ author empty$
+    { "" }
+    { author format.names }
+  if$
+}
+
+FUNCTION {format.key}
+{ empty$
+    { key field.or.null }
+    { "" }
+  if$
+}
+
+%
+% Format editor names for use in the "in" types: inbook, incollection,
+% inproceedings: first initial, then last names. When editors are the
+% LABEL for an entry, then format.editor is used which lists editors
+% by last name first.
+%
+FUNCTION {format.editors.fml}
+{ editor empty$
+    { "" }
+    { editor format.names.fml
+      editor num.names$ #1 >
+    { " (Eds.)" * }
+    { " (Ed.)" * }
+      if$
+    }
+  if$
+}
+
+%
+% Format editor names for use in labels, last names first.
+%
+FUNCTION {format.editors}
+{ editor empty$
+    { "" }
+    { editor format.names
+      editor num.names$ #1 >
+    { " (Eds.)" * }
+    { " (Ed.)" * }
+      if$
+    }
+  if$
+}
+
+FUNCTION {format.title}
+{ title empty$
+    { "" }
+    { title "t" change.case$ }
+  if$
+}
+
+% Note that the APA style requres case changes
+% in article titles. The following does not
+% change cases. If you perfer it, uncomment the
+% following and comment out the above.
+
+%FUNCTION {format.title}
+%{ title empty$
+%    { "" }
+%    { title }
+%  if$
+%}
+
+FUNCTION {n.dashify}
+{ 't :=
+  ""
+    { t empty$ not }
+    { t #1 #1 substring$ "-" =
+    { t #1 #2 substring$ "--" = not
+        { "--" *
+          t #2 global.max$ substring$ 't :=
+        }
+        {   { t #1 #1 substring$ "-" = }
+        { "-" *
+          t #2 global.max$ substring$ 't :=
+        }
+          while$
+        }
+      if$
+    }
+    { t #1 #1 substring$ *
+      t #2 global.max$ substring$ 't :=
+    }
+      if$
+    }
+  while$
+}
+
+FUNCTION {format.btitle}
+{ edition empty$
+  { title emphasize }
+  { title empty$
+    { title emphasize }
+    { volume empty$     % gnp - check for volume, then don't need period
+       { "{\em " title * "\/} (" * edition * " ed.)" * "." * }
+       { "{\em " title * "\/} (" * edition * " ed.)" * }
+      if$
+    }
+    if$
+  }
+  if$
+}
+
+FUNCTION {format.emphasize.booktitle}
+{ edition empty$
+  { booktitle emphasize }
+  { booktitle empty$
+    { booktitle emphasize }
+    { volume empty$    % gnp - extra period an error if book has a volume
+        { "{\em " booktitle * "\/} (" * edition * " ed.)" * "." *}
+        { "{\em " booktitle * "\/} (" * edition * " ed.)" * }
+      if$
+      }
+    if$
+    }
+  if$
+  }
+
+
+FUNCTION {tie.or.space.connect}
+{ duplicate$ text.length$ #3 <
+    { "~" }
+    { " " }
+  if$
+  swap$ * *
+}
+
+FUNCTION {either.or.check}
+{ empty$
+    'pop$
+    { "can't use both " swap$ * " fields in " * cite$ * warning$ }
+  if$
+}
+
+FUNCTION {format.bvolume}
+{ volume empty$
+    { "" }
+    { "Volume" volume tie.or.space.connect % gnp - changed to mixed case
+      series empty$
+        'skip$
+        { " of " * series emphasize * }
+      if$
+      "volume and number" number either.or.check
+    }
+  if$
+}
+
+FUNCTION {format.number.series}
+{ volume empty$
+    { number empty$
+    { series field.or.null }
+    { output.state mid.sentence =
+        { "Number" } % gnp - changed to mixed case always
+        { "Number" }
+      if$
+      number tie.or.space.connect
+      series empty$
+        { "there's a number but no series in " cite$ * warning$ }
+        { " in " * series * }
+      if$
+    }
+      if$
+    }
+    { "" }
+  if$
+}
+
+INTEGERS { multiresult }
+
+FUNCTION {multi.page.check}
+{ 't :=
+  #0 'multiresult :=
+    { multiresult not
+      t empty$ not
+      and
+    }
+    { t #1 #1 substring$
+      duplicate$ "-" =
+      swap$ duplicate$ "," =
+      swap$ "+" =
+      or or
+    { #1 'multiresult := }
+    { t #2 global.max$ substring$ 't := }
+      if$
+    }
+  while$
+  multiresult
+}
+
+FUNCTION {format.pages}
+{ pages empty$
+  { "" }
+  { pages multi.page.check
+	{ "pp.\ " pages n.dashify tie.or.space.connect } % gnp - removed ()
+	{ "pp.\ " pages tie.or.space.connect }
+    if$
+  }
+  if$
+}
+
+% By Young (and Spencer)
+% GNP - fixed bugs with missing volume, number, and/or pages
+%
+% Format journal, volume, number, pages for article types.
+%
+FUNCTION {format.jour.vol}
+{ fjournal empty$
+    { journal empty$
+	{ "no journal in " cite$ * warning$
+	  "" }
+	{ journal emphasize.space }
+	if$
+    } 
+    { fjournal emphasize.space }
+    if$
+  number empty$
+    { volume empty$
+       { "no number and no volume in " cite$ * warning$
+         "" * }
+       { "~{\em " * Volume * "}" * }
+      if$
+    }
+    { volume empty$
+      {"no volume for " cite$ * warning$
+       "~(" * number * ")" * }
+      { "~" *
+        volume emphasize.space
+        "(" * number * ")" * * }
+      if$
+    }
+  if$
+  pages empty$
+    {"page numbers missing in " cite$ * warning$
+     "" * } % gnp - place a null string on the stack for output
+    { duplicate$ empty$
+      { pop$ format.pages }
+      { ", " *  pages n.dashify * } % gnp - removed pp. for articles
+      if$
+    }
+  if$
+}
+
+FUNCTION {format.chapter.pages}
+{ chapter empty$
+    'format.pages
+    { type empty$
+        { "Chapter" } % gnp - changed to mixed case
+        { type "t" change.case$ }
+      if$
+      chapter tie.or.space.connect
+      pages empty$
+        {"page numbers missing in " cite$ * warning$} % gnp - added check
+        { ", " * format.pages * }
+      if$
+    }
+  if$
+}
+
+FUNCTION {format.in.ed.booktitle}
+{ booktitle empty$
+  { "" }
+  { editor empty$
+    { "In " format.emphasize.booktitle * }
+    { "In " format.editors.fml * ", " * format.emphasize.booktitle * }
+    if$
+  }
+  if$
+}
+
+FUNCTION {format.thesis.type}
+{ type empty$
+    'skip$
+    { pop$
+      type "t" change.case$
+    }
+  if$
+}
+
+FUNCTION {format.tr.number}
+{ type empty$
+    { "Technical Report" }
+    'type
+  if$
+  number empty$
+    { "t" change.case$ }
+    { number tie.or.space.connect }
+  if$
+}
+
+FUNCTION {format.article.crossref}
+{ "See"
+  "\citeN{" * crossref * "}" *
+}
+
+FUNCTION {format.crossref.editor}
+{ editor #1 "{vv~}{ll}" format.name$
+  editor num.names$ duplicate$
+  #2 >
+    { pop$ " et~al." * }
+    { #2 <
+    'skip$
+    { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
+        { " et~al." * }
+        { " and " * editor #2 "{vv~}{ll}" format.name$ * }
+      if$
+    }
+      if$
+    }
+  if$
+}
+
+FUNCTION {format.book.crossref}
+{ volume empty$
+    { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
+      "In "
+    }
+    { "Volume" volume tie.or.space.connect % gnp - changed to mixed case
+      " of " *
+    }
+  if$
+  editor empty$
+  editor field.or.null author field.or.null =
+  or
+    { key empty$
+    { series empty$
+        { "need editor, key, or series for " cite$ * " to crossref " *
+          crossref * warning$
+          "" *
+        }
+        { "{\em " * series * "\/}" * }
+      if$
+    }
+    { key * }
+      if$
+    }
+    { format.crossref.editor * }
+  if$
+  " \citeN{" * crossref * "}" *
+}
+
+FUNCTION {format.incoll.inproc.crossref}
+{ "See"
+  " \citeN{" * crossref * "}" *
+}
+
+% format.lab.names:
+%
+% determines "short" names for the abbreviated author information.
+% "Long" labels are created in calc.label, using the routine my.full.label
+% to format author and editor fields.
+%
+% There are 4 cases for labels.   (n=3 in the example)
+% a) one author             Foo
+% b) one to n               Foo, Bar and Baz
+% c) use of "and others"    Foo, Bar et al.
+% d) more than n            Foo et al.
+%
+FUNCTION {format.lab.names}
+{ 's :=
+  s num.names$ 'numnames :=
+  numnames #2 >    % change number to number of others allowed before
+		   % forcing "et al".
+    { s #1 "{vv~}{ll}" format.name$ 
+      "\protect \index {" * 
+      s #1 "{vv~}{ll}{, jj}{, f.}" format.name$ *
+      "}" *
+	"\protect\chicagoetal/" * }
+    {
+      numnames #1 - 'namesleft :=
+      #2 'nameptr :=
+      s #1 "{vv~}{ll}" format.name$
+      "\protect \index {" * 
+      s #1 "{vv~}{ll}{, jj}{, f.}" format.name$ *
+      "}" *
+	{ namesleft #0 > }
+	{ nameptr numnames =
+	    { s nameptr "{ff }{vv }{ll}{ jj}" format.name$ "others" =
+		{ "\protect\chicagoetal/" * }
+		{ "\protect\chicagoand/" * s nameptr "{vv~}{ll}" format.name$ * 
+		  "\protect \index {" * 
+		  s nameptr "{vv~}{ll}{, jj}{, f.}" format.name$ *
+		  "}" *
+                }
+	      if$
+	    }
+	    { ", " * s nameptr "{vv~}{ll}" format.name$ * }
+	  if$
+	  nameptr #1 + 'nameptr :=
+	  namesleft #1 - 'namesleft :=
+	}
+      while$
+    }
+  if$
+}
+
+FUNCTION {author.key.label}
+{ author empty$
+    { key empty$
+          { "no key, author in " cite$ * warning$
+            cite$ #1 #3 substring$ }
+         'key
+      if$
+    }
+    { author format.lab.names }
+  if$
+}
+
+FUNCTION {editor.key.label}
+{ editor empty$
+    { key empty$
+          { "no key, editor in " cite$ * warning$
+            cite$ #1 #3 substring$ }
+          'key
+        if$
+     }
+     { editor format.lab.names }
+  if$
+}
+
+FUNCTION {author.key.organization.label}
+%
+% added - gnp. Provide label formatting by organization if author is null.
+%
+{ author empty$
+    { organization empty$
+	{ key empty$
+	    { "no key, author or organization in " cite$ * warning$
+              cite$ #1 #3 substring$ }
+	    'key
+	  if$
+	}
+        { organization }
+      if$
+    }
+    { author format.lab.names }
+  if$
+}
+
+FUNCTION {editor.key.organization.label}
+%
+% added - gnp. Provide label formatting by organization if editor is null.
+%
+{ editor empty$
+    { organization empty$
+	{ key empty$
+	    { "no key, editor or organization in " cite$ * warning$
+              cite$ #1 #3 substring$ }
+	    'key
+	  if$
+	}
+        { organization }
+      if$
+    }
+    { editor format.lab.names }
+  if$
+}
+
+FUNCTION {author.editor.key.label}
+{ author empty$
+    { editor empty$
+          { key empty$
+               { "no key, author, or editor in " cite$ * warning$
+                 cite$ #1 #3 substring$ }
+             'key
+           if$
+         }
+          { editor format.lab.names }
+      if$
+    }
+    { author format.lab.names }
+  if$
+}
+
+FUNCTION {calc.label.orig}
+%
+% Changed - GNP. See also author.organization.sort, editor.organization.sort
+% Form label for BibTeX entry. The classification of which fields are used
+% for which type of entry (book, inbook, etc.) are taken from alpha.bst.
+% The change here from newapa is to also include organization as a
+% citation label if author or editor is missing.
+%
+{ type$ "book" =
+  type$ "inbook" =
+  or
+    'author.editor.key.label
+    { type$ "proceedings" =
+	'editor.key.organization.label
+	{ type$ "manual" =
+	    'author.key.organization.label
+	    'author.key.label
+	  if$
+	}
+      if$
+    }
+  if$
+
+  author empty$  % generate the full label citation information.
+    { editor empty$
+        { organization empty$
+           { "no author, editor, or organization in " cite$ * warning$
+             "??" }
+           { organization }
+           if$
+        }
+        { editor my.full.label }
+        if$
+    }
+    { author.key.label }
+  if$
+
+% leave label on the stack, to be popped when required.
+
+  "}{" * swap$ *
+%  year field.or.null purify$ #-1 #4 substring$ *
+%
+% save the year for sort processing afterwards (adding a, b, c, etc.)
+%
+  year field.or.null purify$ #-1 #4 substring$
+  'label.year :=
+}
+
+FUNCTION {calc.label}
+%
+% Changed - GNP. See also author.organization.sort, editor.organization.sort
+% Form label for BibTeX entry. The classification of which fields are used
+% for which type of entry (book, inbook, etc.) are taken from alpha.bst.
+% The change here from newapa is to also include organization as a
+% citation label if author or editor is missing.
+%
+{ type$ "book" =
+  type$ "inbook" =
+  or
+    'author.editor.key.label
+    { type$ "proceedings" =
+	'editor.key.organization.label
+	{ type$ "manual" =
+	    'author.key.organization.label
+	    'author.key.label
+	  if$
+	}
+      if$
+    }
+  if$
+
+  author empty$  % generate the full label citation information.
+    { editor empty$
+        { organization empty$
+           { "no author, editor, or organization in " cite$ * warning$
+             "??" }
+           { organization }
+           if$
+        }
+        { editor my.full.label }
+        if$
+    }
+    { author my.full.label }
+  if$
+
+% leave label on the stack, to be popped when required.
+
+  "}{" * swap$ * "}{" * title * "}{" *
+%  year field.or.null purify$ #-1 #4 substring$ *
+%
+% save the year for sort processing afterwards (adding a, b, c, etc.)
+%
+  year field.or.null purify$ #-1 #4 substring$
+  'label.year :=
+}
+
+FUNCTION {output.bibitem}
+{ newline$
+
+  "\bibitem[\protect\citeauthortitleyear{" write$
+  calc.label write$
+  sort.year write$
+  "}]{" write$
+
+  cite$ write$
+  "}" write$
+  newline$
+  ""
+  before.all 'output.state :=
+}
+
+FUNCTION {article}
+{ output.bibitem
+  format.authors
+  "author" output.check
+  author format.key output          % added
+  output.year.check                 % added
+  new.block
+  format.title
+  "title" output.check
+  new.block
+  crossref missing$
+    { format.jour.vol output
+    }
+    { format.article.crossref output.nonnull
+      format.pages output
+    }
+  if$
+  new.block
+  note output
+  fin.entry
+}
+
+FUNCTION {book}
+{ output.bibitem
+  author empty$
+    { format.editors
+	  "author and editor" output.check }
+    { format.authors
+	  output.nonnull
+      crossref missing$
+    	{ "author and editor" editor either.or.check }
+    	'skip$
+      if$
+    }
+  if$
+  output.year.check       % added
+  new.block
+  format.btitle
+  "title" output.check
+  crossref missing$
+    { format.bvolume output
+      new.block
+      format.number.series output
+      new.sentence
+      address output
+      publisher "publisher" output.check.colon
+    }
+    { new.block
+      format.book.crossref output.nonnull
+    }
+  if$
+  new.block
+  note output
+  fin.entry
+}
+
+FUNCTION {booklet}
+{ output.bibitem
+  format.authors output
+  author format.key output          % added
+  output.year.check                 % added
+  new.block
+  format.title
+  "title" output.check
+  new.block
+  howpublished output
+  address output
+  new.block
+  note output
+  fin.entry
+}
+
+FUNCTION {inbook}
+{ output.bibitem
+  author empty$
+    { format.editors
+      "author and editor" output.check
+    }
+    { format.authors output.nonnull
+      crossref missing$
+    { "author and editor" editor either.or.check }
+    'skip$
+      if$
+    }
+  if$
+  output.year.check                 % added
+  new.block
+  format.btitle
+  "title" output.check
+  crossref missing$
+    { format.bvolume output
+      format.chapter.pages
+      "chapter and pages" output.check
+      new.block
+      format.number.series output
+      new.sentence
+      address output
+      publisher
+      "publisher" output.check.colon
+    }
+    { format.chapter.pages "chapter and pages" output.check
+      new.block
+      format.book.crossref output.nonnull
+    }
+  if$
+  new.block
+  note output
+  fin.entry
+}
+
+FUNCTION {incollection}
+{ output.bibitem
+  format.authors
+  "author" output.check
+  author format.key output       % added
+  output.year.check              % added
+  new.block
+  format.title
+  "title" output.check
+  new.block
+  crossref missing$
+  { format.in.ed.booktitle
+    "booktitle" output.check
+    format.bvolume output
+    format.number.series output
+    format.chapter.pages output % gnp - was special.output.nonnull
+%                                 left out comma before page numbers
+    new.sentence
+    address output
+    publisher "publisher" output.check.colon
+  }
+  { format.incoll.inproc.crossref
+	output.nonnull
+    format.chapter.pages output
+  }
+  if$
+  new.block
+  note output
+  fin.entry
+}
+
+FUNCTION {inproceedings}
+{ output.bibitem
+  format.authors
+  "author" output.check
+  author format.key output            % added
+  output.year.check                   % added
+  new.block
+  format.title
+  "title" output.check
+  new.block
+  crossref missing$
+    { format.in.ed.booktitle
+	  "booktitle" output.check
+      format.bvolume output
+      format.number.series output
+      address output
+      format.pages output
+      new.sentence
+      organization output
+      publisher output.colon
+      }
+    { format.incoll.inproc.crossref output.nonnull
+      format.pages output
+    }
+  if$
+  new.block
+  note output
+  fin.entry
+}
+
+FUNCTION {conference} { inproceedings }
+
+FUNCTION {manual}
+{ output.bibitem
+  author empty$
+    { editor empty$
+      { organization "organization" output.check
+        organization format.key output }  % if all else fails, use key
+      { format.editors "author and editor" output.check }
+      if$
+    }
+    { format.authors output.nonnull }
+    if$
+  output.year.check                 % added
+  new.block
+  format.btitle
+  "title" output.check
+  organization address new.block.checkb
+% Reversed the order of "address" and "organization", added the ":".
+  address output
+  organization "organization" output.check.colon
+%  address output
+%  ":" output
+%  organization output
+  new.block
+  note output
+  fin.entry
+}
+
+FUNCTION {mastersthesis}
+{ output.bibitem
+  format.authors
+  "author" output.check
+  author format.key output          % added
+  output.year.check                 % added
+  new.block
+  format.title
+  "title" output.check
+  new.block
+  "Master's thesis" format.thesis.type output.nonnull
+  school "school" output.check
+  address output
+  new.block
+  note output
+  fin.entry
+}
+
+FUNCTION {misc}
+{ output.bibitem
+  format.authors output
+  author format.key output            % added
+  output.year.check                   % added
+  title howpublished new.block.checkb
+  format.title output
+  new.block
+  howpublished output
+  new.block
+  note output
+  fin.entry
+}
+
+FUNCTION {phdthesis}
+{ output.bibitem
+  format.authors
+  "author" output.check
+  author format.key output            % added
+  output.year.check                   % added
+  new.block
+  format.btitle
+  "title" output.check
+  new.block
+  "Ph.\ D. thesis" format.thesis.type output.nonnull
+  school "school" output.check
+  address output
+  new.block
+  note output
+  fin.entry
+}
+
+FUNCTION {proceedings}
+{ output.bibitem
+  editor empty$
+    { organization output
+      organization format.key output }  % gnp - changed from author format.key
+    { format.editors output.nonnull }
+  if$
+% author format.key output             % gnp - removed (should be either
+%                                        editor or organization
+  output.year.check                    % added (newapa)
+  new.block
+  format.btitle
+  "title" output.check
+  format.bvolume output
+  format.number.series output
+  address output
+  new.sentence
+  organization output
+  publisher output.colon
+  new.block
+  note output
+  fin.entry
+}
+
+FUNCTION {techreport}
+{ output.bibitem
+  format.authors
+  "author" output.check
+  author format.key output             % added
+  output.year.check                    % added
+  new.block
+  format.title
+  "title" output.check
+  new.block
+  format.tr.number output.nonnull
+  institution
+  "institution" output.check
+  address output
+  new.block
+  note output
+  fin.entry
+}
+
+FUNCTION {unpublished}
+{ output.bibitem
+  format.authors
+  "author" output.check
+  author format.key output              % added
+  output.year.check                      % added
+  new.block
+  format.title
+  "title" output.check
+  new.block
+  note "note" output.check
+  fin.entry
+}
+
+FUNCTION {default.type} { misc }
+
+MACRO {jan} {"January"}
+
+MACRO {feb} {"February"}
+
+MACRO {mar} {"March"}
+
+MACRO {apr} {"April"}
+
+MACRO {may} {"May"}
+
+MACRO {jun} {"June"}
+
+MACRO {jul} {"July"}
+
+MACRO {aug} {"August"}
+
+MACRO {sep} {"September"}
+
+MACRO {oct} {"October"}
+
+MACRO {nov} {"November"}
+
+MACRO {dec} {"December"}
+
+MACRO {acmcs} {"ACM Computing Surveys"}
+
+MACRO {acta} {"Acta Informatica"}
+
+MACRO {ai} {"Artificial Intelligence"}
+
+MACRO {cacm} {"Communications of the ACM"}
+
+MACRO {ibmjrd} {"IBM Journal of Research and Development"}
+
+MACRO {ibmsj} {"IBM Systems Journal"}
+
+MACRO {ieeese} {"IEEE Transactions on Software Engineering"}
+
+MACRO {ieeetc} {"IEEE Transactions on Computers"}
+
+MACRO {ieeetcad}
+ {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}
+
+MACRO {ipl} {"Information Processing Letters"}
+
+MACRO {jacm} {"Journal of the ACM"}
+
+MACRO {jcss} {"Journal of Computer and System Sciences"}
+
+MACRO {scp} {"Science of Computer Programming"}
+
+MACRO {sicomp} {"SIAM Journal on Computing"}
+
+MACRO {tocs} {"ACM Transactions on Computer Systems"}
+
+MACRO {tods} {"ACM Transactions on Database Systems"}
+
+MACRO {tog} {"ACM Transactions on Graphics"}
+
+MACRO {toms} {"ACM Transactions on Mathematical Software"}
+
+MACRO {toois} {"ACM Transactions on Office Information Systems"}
+
+MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}
+
+MACRO {tcs} {"Theoretical Computer Science"}
+
+READ
+
+FUNCTION {sortify}
+{ purify$
+  "l" change.case$
+}
+
+INTEGERS { len }
+
+FUNCTION {chop.word}
+{ 's :=
+  'len :=
+  s #1 len substring$ =
+    { s len #1 + global.max$ substring$ }
+    's
+  if$
+}
+
+
+
+FUNCTION {sort.format.names}
+{ 's :=
+  #1 'nameptr :=
+  ""
+  s num.names$ 'numnames :=
+  numnames 'namesleft :=
+    { namesleft #0 > }
+    { nameptr #2 =
+	{ year field.or.null purify$ #-1 #4 substring$ * }
+	'skip$
+      if$
+      nameptr #1 >
+          { "   " * }
+         'skip$
+      if$
+      s nameptr "{vv{ } }{ll{ }}{  f{ }}{  jj{ }}" format.name$ 't :=
+      nameptr numnames = t "others" = and
+          { " et~al" * }
+          { t sortify * }
+      if$
+      nameptr #1 + 'nameptr :=
+      namesleft #1 - 'namesleft :=
+    }
+  while$
+}
+
+FUNCTION {sort.format.title}
+{ 't :=
+  "A " #2
+    "An " #3
+      "The " #4 t chop.word
+    chop.word
+  chop.word
+  sortify
+  #1 global.max$ substring$
+}
+
+FUNCTION {author.sort}
+{ author empty$
+    { key empty$
+         { "to sort, need author or key in " cite$ * warning$
+           "" }
+         { key sortify }
+      if$
+    }
+    { author sort.format.names }
+  if$
+}
+
+FUNCTION {editor.sort}
+{ editor empty$
+    { key empty$
+         { "to sort, need editor or key in " cite$ * warning$
+           ""
+         }
+         { key sortify }
+      if$
+    }
+    { editor sort.format.names }
+  if$
+}
+
+FUNCTION {author.editor.sort}
+{ author empty$
+    { "missing author in " cite$ * warning$
+      editor empty$
+         { key empty$
+             { "to sort, need author, editor, or key in " cite$ * warning$
+               ""
+             }
+             { key sortify }
+           if$
+         }
+         { editor sort.format.names }
+      if$
+    }
+    { author sort.format.names }
+  if$
+}
+
+FUNCTION {author.organization.sort}
+%
+% added - GNP. Stack author or organization for sorting (from alpha.bst).
+% Unlike alpha.bst, we need entire names, not abbreviations
+%
+{ author empty$
+    { organization empty$
+	{ key empty$
+	    { "to sort, need author, organization, or key in " cite$ * warning$
+	      ""
+	    }
+	    { key sortify }
+	  if$
+	}
+	{ organization sortify }
+      if$
+    }
+    { author sort.format.names }
+  if$
+}
+
+FUNCTION {editor.organization.sort}
+%
+% added - GNP. Stack editor or organization for sorting (from alpha.bst).
+% Unlike alpha.bst, we need entire names, not abbreviations
+%
+{ editor empty$
+    { organization empty$
+	{ key empty$
+	    { "to sort, need editor, organization, or key in " cite$ * warning$
+	      ""
+	    }
+	    { key sortify }
+	  if$
+	}
+	{ organization sortify }
+      if$
+    }
+    { editor sort.format.names }
+  if$
+}
+
+FUNCTION {presort}
+%
+% Presort creates the bibentry's label via a call to calc.label, and then
+% sorts the entries based on entry type. Chicago.bst adds support for
+% including organizations as the sort key; the following is stolen from
+% alpha.bst.
+%
+{ %calc.label sortify % recalculate bibitem label
+  %year field.or.null purify$ #-1 #4 substring$ * % add year
+  %duplicate$ warning$
+  %"    "
+  %*
+  type$ "book" =
+  type$ "inbook" =
+  or
+    'author.editor.sort
+    { type$ "proceedings" =
+	'editor.organization.sort
+	{ type$ "manual" =
+	    'author.organization.sort
+	    'author.sort
+	  if$
+	}
+      if$
+    }
+  if$
+  #1 entry.max$ substring$        % added for newapa
+  'sort.label :=                  % added for newapa
+  sort.label                      % added for newapa
+  %*
+  "    "
+  *
+  title field.or.null
+  sort.format.title
+  *
+  #1 entry.max$ substring$
+  'sort.key$ :=
+}
+
+ITERATE {presort}
+
+SORT             % by label, year, author/editor, title
+
+STRINGS { last.label next.extra }
+
+INTEGERS { last.extra.num }
+
+FUNCTION {initialize.extra.label.stuff}
+{ #0 int.to.chr$ 'last.label :=
+  "" 'next.extra :=
+  #0 'last.extra.num :=
+}
+
+FUNCTION {forward.pass}
+%
+% Pass through all entries, comparing current entry to last one.
+% Need to concatenate year to the stack (done by calc.label) to determine
+% if two entries are the same (see presort)
+%
+{ last.label
+  calc.label.orig year field.or.null purify$ #-1 #4 substring$ * % add year
+  #1 entry.max$ substring$ =     % are they equal?
+     { last.extra.num #1 + 'last.extra.num :=
+       last.extra.num int.to.chr$ 'extra.label :=
+     }
+     { "a" chr.to.int$ 'last.extra.num :=
+       "" 'extra.label :=
+       calc.label.orig year field.or.null purify$ #-1 #4 substring$ * % add year
+       #1 entry.max$ substring$ 'last.label := % assign to last.label
+     }
+  if$
+}
+
+FUNCTION {reverse.pass}
+{ next.extra "b" =
+    { "a" 'extra.label := }
+     'skip$
+  if$
+  label.year extra.label * 'sort.year :=
+  extra.label 'next.extra :=
+}
+
+EXECUTE {initialize.extra.label.stuff}
+
+ITERATE {forward.pass}
+
+REVERSE {reverse.pass}
+
+FUNCTION {bib.sort.order}
+{ sort.label
+  "    "
+  *
+  year field.or.null sortify
+  *
+  "    "
+  *
+  title field.or.null
+  sort.format.title
+  *
+  #1 entry.max$ substring$
+  'sort.key$ :=
+}
+
+ITERATE {bib.sort.order}
+
+SORT             % by sort.label, year, title --- giving final bib. order.
+
+FUNCTION {begin.bib}
+
+{ preamble$ empty$
+    'skip$
+    { preamble$ write$ newline$ }
+  if$
+  "\begin{thebibliography}{}" write$ newline$
+}
+
+
+EXECUTE {begin.bib}
+
+EXECUTE {init.state.consts}
+
+ITERATE {call.type$}
+
+FUNCTION {end.bib}
+{ newline$
+  "\end{thebibliography}" write$ newline$
+}
+
+EXECUTE {end.bib}
+

Added: polly/trunk/lib/External/isl/doc/chicago.sty
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/doc/chicago.sty?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/doc/chicago.sty (added)
+++ polly/trunk/lib/External/isl/doc/chicago.sty Wed Feb  4 14:55:43 2015
@@ -0,0 +1,320 @@
+% -*- LaTeX -*-
+%%% ====================================================================
+%%%  @LaTeX-style-file{
+%%%     author          = "Glenn Paulley",
+%%%     version         = "4",
+%%%     date            = "31 August 1992",
+%%%     time            = "09:42:44 199",
+%%%     filename        = "chicago.sty",
+%%%     address         = "Data Structuring Group
+%%%                        Department of Computer Science
+%%%                        University of Waterloo
+%%%                        Waterloo, Ontario, Canada
+%%%                        N2L 3G1",
+%%%     telephone       = "(519) 885-1211",
+%%%     FAX             = "(519) 885-1208",
+%%%     checksum        = "44674 264 1050 10394",
+%%%     email           = "gnpaulle at bluebox.uwaterloo.ca",
+%%%     codetable       = "ISO/ASCII",
+%%%     keywords        = "",
+%%%     supported       = "yes",
+%%%     abstract        = "Contains the LaTeX style command definitions
+%%%                        for the Chicago BibTeX styles chicago.bst and
+%%%                        chicagoa.bst. For details, see below.",
+%%%     docstring       = "The checksum field above contains a CRC-16
+%%%                        checksum as the first value, followed by the
+%%%                        equivalent of the standard UNIX wc (word
+%%%                        count) utility output of lines, words, and
+%%%                        characters.  This is produced by Robert
+%%%                        Solovay's checksum utility.",
+%%%  }
+%%% ====================================================================
+%
+% chicago.sty: Style file for use with bibtex style chicago.bst, for
+% bibliographies formatted according to the 13th Edition of the Chicago
+% Manual of Style.
+%
+% 'newapa.bst' was made from 'plain.bst', 'named.bst', and 'apalike.bst',
+% with lots of tweaking to make it look like APA style, along with tips
+% from Young Ryu and Brian Reiser's modifications of 'apalike.bst'.
+% newapa.sty formed the basis of this style, chicago.sty. Author-date
+% references in newapa.bst formed the basis for chicago.bst. Chicagoa.bst
+% supports annotations.
+%
+% Version 4 (August, 1992):
+% - fixed chicago.bst and chicagoa.bst to handle long author lists in
+%   sorting
+% - fixed chicago.bst and chicagoa.bst so that missing page numbers in
+%   ``article'' entries are handled correctly
+% - modified chicago.sty to format entries with 2nd and subsequent lines
+%   indented.
+%
+%   Citation format: (author-last-name year)
+%             (author-last-name and author-last-name year)
+%             (author-last-name et al. year)
+%             (author-last-name)
+%             author-last-name
+%             author-last-name (year)
+%             (author-last-name and author-last-name)
+%             (author-last-name et al.)
+%             (year) or (year,year)
+%             year or year,year
+%
+%   Reference list ordering: alphabetical by author or whatever passes
+%    for author in the absence of one.
+%
+% This BibTeX style has support for abbreviated author lists and for
+%    year-only citations.  This is done by having the citations
+%    actually look like
+%
+%    \citeauthoryear{full-author-info}{abbrev-author-info}{year}
+%
+% The LaTeX style has to have the following (or similar)
+%
+%     \let\@internalcite\cite
+%     \def\fullcite{\def\citeauthoryear##1##2##3{##1, ##3}\@internalcite}
+%     \def\fullciteA{\def\citeauthoryear##1##2##3{##1}\@internalcite}
+%     \def\shortcite{\def\citeauthoryear##1##2##3{##2, ##3}\@internalcite}
+%     \def\shortciteA{\def\citeauthoryear##1##2##3{##2}\@internalcite}
+%     \def\citeyear{\def\citeauthoryear##1##2##3{##3}\@internalcite}
+%
+% -------------------------------------------------------------------------
+% This file implements citations for the ``chicago'' bibliography style.
+%  Place it in a file called chicago.sty in the TeX search path.
+%(Placing it in the same directory as the LaTeX document should also work.)
+%
+%    This file is a modification of the ``newapa'' LaTeX style,
+%    originally adapted by Steven Spencer from the ``apalike'' LaTeX style.
+%    It was originally modified by Stephen N. Spencer, with further
+%    modifications by Young U. Ryu.
+%
+% The ``chicago'' BibTeX bibliography style creates citations with labels:
+%       \citeauthoryear{author-info}{abbrev. author-info}{year}
+%
+% These labels are processed by the following LaTeX commands:
+%
+%  \cite{key}
+%    which produces citations with full author list and year.
+%    eg. (Brown 1978; Jarke, Turner, Stohl, et al. 1985)
+%  \citeNP{key}
+%    which produces citations with full author list and year, but without
+%    enclosing parentheses:
+%    eg. Brown 1978; Jarke, Turner and Stohl 1985
+%  \citeA{key}
+%    which produces citations with only the full author list.
+%    eg. (Brown; Jarke, Turner and Stohl)
+%  \citeANP{key}
+%    which produces citations with only the full author list, without
+%    parentheses eg. Brown; Jarke, Turner and Stohl
+%  \citeN{key}
+%    which produces citations with the full author list and year, but
+%    can be used as nouns in a sentence; no parentheses appear around
+%    the author names, but only around the year.
+%      eg. Shneiderman (1978) states that......
+%    \citeN should only be used for a single citation.
+%  \shortcite{key}
+%    which produces citations with abbreviated author list and year.
+%  \shortciteNP{key}
+%    which produces citations with abbreviated author list and year.
+%  \shortciteA{key}
+%    which produces only the abbreviated author list.
+%  \shortciteANP{key}
+%    which produces only the abbreviated author list.
+%  \shortciteN{key}
+%    which produces the abbreviated author list and year, with only the
+%    year in parentheses. Use with only one citation.
+%  \citeyear{key}
+%    which produces the year information only, within parentheses.
+%  \citeyearNP{key}
+%    which produces the year information only.
+%
+% Abbreviated author lists use the ``et al.'' construct.
+%
+% `NP' means `no parentheses'.
+%
+% This LaTeX style file must be used with the ``chicago'' or ``chicagoa''
+% (annotated chicago style) BibTeX styles.
+%
+\typeout{Using Chicago Manual of Style bibliography: 31 August 1992}
+%
+% -------------------------------------------------------------------------
+%
+% Citation macros.
+%
+\def\chicagoand/{ and }
+\def\chicagoetal/{ et~al.}
+%
+\let\@internalcite\cite
+%
+\def\cite{\def\@citeseppen{-1000}%
+    \def\@cite##1##2{(##1\if at tempswa , ##2\fi)}%
+    \def\citeauthortitleyear##1##2##3##4{##1\ ##4}\@internalcite}
+\def\citeNP{\def\@citeseppen{-1000}%
+    \def\@cite##1##2{##1\if at tempswa , ##2\fi}%
+    \def\citeauthortitleyear##1##2##3##4{##1\ ##4}\@internalcite}
+\def\citetitleN{\def\@citeseppen{-1000}%
+    \def\@cite##1##2{##1\if at tempswa , ##2)\else{)}\fi}%
+    \def\citeauthortitleyear##1##2##3##4{##3\ (##1; ##4}\@citedata}
+\def\citeN{\def\@citeseppen{-1000}%
+    \def\@cite##1##2{##1\if at tempswa , ##2)\else{)}\fi}%
+    \def\citeauthortitleyear##1##2##3##4{##1\ (##4}\@citedata}
+\def\citeA{\def\@citeseppen{-1000}%
+    \def\@cite##1##2{(##1\if at tempswa , ##2\fi)}%
+    \def\citeauthortitleyear##1##2##3##4{##1}\@internalcite}
+\def\citeANP{\def\@citeseppen{-1000}%
+    \def\@cite##1##2{##1\if at tempswa , ##2\fi}%
+    \def\citeauthortitleyear##1##2##3##4{##1}\@internalcite}
+%
+\def\shortcite{\def\@citeseppen{-1000}%
+    \def\@cite##1##2{(##1\if at tempswa , ##2\fi)}%
+    \def\citeauthortitleyear##1##2##3##4{##2\ ##4}\@internalcite}
+\def\shortciteNP{\def\@citeseppen{-1000}%
+    \def\@cite##1##2{##1\if at tempswa , ##2\fi}%
+    \def\citeauthortitleyear##1##2##3##4{##2\ ##4}\@internalcite}
+\def\shortciteN{\def\@citeseppen{-1000}%
+    \def\@cite##1##2{##1\if at tempswa , ##2)\else{)}\fi}%
+    \def\citeauthortitleyear##1##2##3##4{##2\ (##4}\@citedata}
+\def\shortciteA{\def\@citeseppen{-1000}%
+    \def\@cite##1##2{(##1\if at tempswa , ##2\fi)}%
+    \def\citeauthortitleyear##1##2##3##4{##2}\@internalcite}
+\def\shortciteANP{\def\@citeseppen{-1000}%
+    \def\@cite##1##2{##1\if at tempswa , ##2\fi}%
+    \def\citeauthortitleyear##1##2##3##4{##2}\@internalcite}
+%
+\def\citeyear{\def\@citeseppen{-1000}%
+    \def\@cite##1##2{(##1\if at tempswa , ##2\fi)}%
+    \def\citeauthortitleyear##1##2##3##4{##4}\@citedata}
+\def\citeyearNP{\def\@citeseppen{-1000}%
+    \def\@cite##1##2{##1\if at tempswa , ##2\fi}%
+    \def\citeauthortitleyear##1##2##3##4{##4}\@citedata}
+
+%
+% \@citedata and \@citedatax:
+%
+% Place commas in-between citations in the same \citeyear, \citeyearNP,
+% \citeN, or \shortciteN command.
+% Use something like \citeN{ref1,ref2,ref3} and \citeN{ref4} for a list.
+%
+\def\@citedata{%
+	\@ifnextchar [{\@tempswatrue\@citedatax}%
+				  {\@tempswafalse\@citedatax[]}%
+}
+
+\def\@citedatax[#1]#2{%
+\if at filesw\immediate\write\@auxout{\string\citation{#2}}\fi%
+  \def\@citea{}\@cite{\@for\@citeb:=#2\do%
+    {\@citea\def\@citea{), }\@ifundefined% by Young
+       {b@\@citeb}{{\bf ?}%
+       \@warning{Citation `\@citeb' on page \thepage \space undefined}}%
+{\csname b@\@citeb\endcsname}}}{#1}}%
+
+\@ifpackageloaded{hyperref}{%
+  \let\BRorg at citedatax\@citedatax 
+  \def\@citedatax[#1]#2{%
+    \BRorg at citedatax[#1]{#2}%
+    \Hy at backout{#2}%
+  }%
+}{}
+\@ifpackageloaded{hyperref}{%
+\def\hyperemph#1{{\em\hyperpage{#1}}}%
+\def\bold#1{{\bf\hyperpage{#1}}}%
+}{%
+\def\hyperemph#1{{\em #1}}%
+\def\bold#1{{\bf #1}}%
+}
+
+\def\BR@@lbibitem[#1]#2#3\par{%
+  \BRorg at bibitem[#1]{#2}#3\hfill\penalty100\hbox{}
+  \newblock
+  \backref\hfill[{\csname br@#2\endcsname}%
+  ]\parskip=-10pt\penalty-10000\hbox{}\nobreak\par
+}%
+\def\BR@@bibitem#1#2\par{%
+  \BRorg at bibitem{#1}#2
+  \newblock
+  \backref\penalty-100\hbox{}\nobreak\hfill[\hbox{\csname br@#2\endcsname}%
+  ]\par
+}
+\def\thepageorcolor{\thepage}
+\def\Hy at backout#1{%
+  \@bsphack
+  \ifx\@empty\@currentlabel
+    \protected at write\@auxout{}{%
+      \string\@writefile{brf}{%
+        \string\backcite{#1}{{\thepageorcolor}{(document)}{Doc-Start}}%
+      }%
+    }%
+  \else
+   \protected at write\@auxout{}{%
+     \string\@writefile{brf}{%
+       \string\backcite{#1}{{\thepageorcolor}{\@currentlabel}{\@currentHref}}%
+     }%
+   }%
+  \fi
+  \@esphack
+}
+
+% don't box citations, separate with ; and a space
+% also, make the penalty between citations negative: a good place to break.
+%
+\def\@citex[#1]#2{%
+\if at filesw\immediate\write\@auxout{\string\citation{#2}}\fi%
+  \def\@citea{}\@cite{\@for\@citeb:=#2\do%
+    {\@citea\def\@citea{; }\@ifundefined% by Young
+       {b@\@citeb}{{\bf ?}%
+       \@warning{Citation `\@citeb' on page \thepage \space undefined}}%
+{\csname b@\@citeb\endcsname}}}{#1}}%
+
+% (from apalike.sty)
+% No labels in the bibliography.
+%
+\def\@biblabel#1{}
+
+% (from apalike.sty)
+% Set length of hanging indentation for bibliography entries.
+%
+\newlength{\bibhang}
+\setlength{\bibhang}{2em}
+
+% Indent second and subsequent lines of bibliographic entries. Stolen
+% from openbib.sty: \newblock is set to {}.
+
+\newdimen\bibindent
+\bibindent=1.5em
+\@ifundefined{refname}%
+   {\@ifundefined{chapter}%
+     {\newcommand{\refname}{References}}%
+     {\newcommand{\refname}{Bibliography}}%
+   }%
+   {}%
+\@ifundefined{chapter}%
+ {\def\thebibliography#1{\section*{\refname\@mkboth
+   {\uppercase{\refname}}{\uppercase{\refname}}}
+   \addcontentsline{toc}{section}{References}
+   \list
+   {[\arabic{enumi}]}{\settowidth\labelwidth{[#1]}
+   \leftmargin\labelwidth
+   \advance\leftmargin\labelsep
+   \advance\leftmargin\bibindent
+   \itemindent -\bibindent
+   \listparindent \itemindent
+   \parsep \z@
+   \usecounter{enumi}}
+   \def\newblock{}
+   \sloppy
+   \sfcode`\.=1000\relax}}
+ {\def\thebibliography#1{\chapter*{\refname\@mkboth
+   {\refname}{\refname}}
+   \addcontentsline{toc}{chapter}{References}
+   \list
+   {[\arabic{enumi}]}{\settowidth\labelwidth{[#1]}
+   \leftmargin\labelwidth
+   \advance\leftmargin\labelsep
+   \advance\leftmargin\bibindent
+   \itemindent -\bibindent
+   \listparindent \itemindent
+   \parsep \z@
+   \usecounter{enumi}}
+   \def\newblock{}
+   \sloppy
+   \sfcode`\.=1000\relax}}

Added: polly/trunk/lib/External/isl/doc/implementation.tex
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/doc/implementation.tex?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/doc/implementation.tex (added)
+++ polly/trunk/lib/External/isl/doc/implementation.tex Wed Feb  4 14:55:43 2015
@@ -0,0 +1,2036 @@
+\section{Sets and Relations}
+
+\begin{definition}[Polyhedral Set]
+A {\em polyhedral set}\index{polyhedral set} $S$ is a finite union of basic sets
+$S = \bigcup_i S_i$, each of which can be represented using affine
+constraints
+$$
+S_i : \Z^n \to 2^{\Z^d} : \vec s \mapsto
+S_i(\vec s) =
+\{\, \vec x \in \Z^d \mid \exists \vec z \in \Z^e :
+A \vec x + B \vec s + D \vec z + \vec c \geq \vec 0 \,\}
+,
+$$
+with $A \in \Z^{m \times d}$,
+$B \in \Z^{m \times n}$,
+$D \in \Z^{m \times e}$
+and $\vec c \in \Z^m$.
+\end{definition}
+
+\begin{definition}[Parameter Domain of a Set]
+Let $S \in \Z^n \to 2^{\Z^d}$ be a set.
+The {\em parameter domain} of $S$ is the set
+$$\pdom S \coloneqq \{\, \vec s \in \Z^n \mid S(\vec s) \ne \emptyset \,\}.$$
+\end{definition}
+
+\begin{definition}[Polyhedral Relation]
+A {\em polyhedral relation}\index{polyhedral relation}
+$R$ is a finite union of basic relations
+$R = \bigcup_i R_i$ of type
+$\Z^n \to 2^{\Z^{d_1+d_2}}$,
+each of which can be represented using affine
+constraints
+$$
+R_i = \vec s \mapsto
+R_i(\vec s) =
+\{\, \vec x_1 \to \vec x_2 \in \Z^{d_1} \times \Z^{d_2}
+\mid \exists \vec z \in \Z^e :
+A_1 \vec x_1 + A_2 \vec x_2 + B \vec s + D \vec z + \vec c \geq \vec 0 \,\}
+,
+$$
+with $A_i \in \Z^{m \times d_i}$,
+$B \in \Z^{m \times n}$,
+$D \in \Z^{m \times e}$
+and $\vec c \in \Z^m$.
+\end{definition}
+
+\begin{definition}[Parameter Domain of a Relation]
+Let $R \in \Z^n \to 2^{\Z^{d+d}}$ be a relation.
+The {\em parameter domain} of $R$ is the set
+$$\pdom R \coloneqq \{\, \vec s \in \Z^n \mid R(\vec s) \ne \emptyset \,\}.$$
+\end{definition}
+
+\begin{definition}[Domain of a Relation]
+Let $R \in \Z^n \to 2^{\Z^{d+d}}$ be a relation.
+The {\em domain} of $R$ is the polyhedral set
+$$\domain R \coloneqq \vec s \mapsto
+\{\, \vec x_1 \in \Z^{d_1} \mid \exists \vec x_2 \in \Z^{d_2} :
+(\vec x_1, \vec x_2) \in R(\vec s) \,\}
+.
+$$
+\end{definition}
+
+\begin{definition}[Range of a Relation]
+Let $R \in \Z^n \to 2^{\Z^{d+d}}$ be a relation.
+The {\em range} of $R$ is the polyhedral set
+$$
+\range R \coloneqq \vec s \mapsto
+\{\, \vec x_2 \in \Z^{d_2} \mid \exists \vec x_1 \in \Z^{d_1} :
+(\vec x_1, \vec x_2) \in R(\vec s) \,\}
+.
+$$
+\end{definition}
+
+\begin{definition}[Composition of Relations]
+Let $R \in \Z^n \to 2^{\Z^{d_1+d_2}}$ and
+$S \in \Z^n \to 2^{\Z^{d_2+d_3}}$ be two relations,
+then the composition of
+$R$ and $S$ is defined as
+$$
+S \circ R \coloneqq
+\vec s \mapsto
+\{\, \vec x_1 \to \vec x_3 \in \Z^{d_1} \times \Z^{d_3}
+\mid \exists \vec x_2 \in \Z^{d_2} :
+\vec x_1 \to \vec x_2 \in R(\vec s) \wedge
+\vec x_2 \to \vec x_3 \in S(\vec s)
+\,\}
+.
+$$
+\end{definition}
+
+\begin{definition}[Difference Set of a Relation]
+Let $R \in \Z^n \to 2^{\Z^{d+d}}$ be a relation.
+The difference set ($\Delta \, R$) of $R$ is the set
+of differences between image elements and the corresponding
+domain elements,
+$$
+\diff R \coloneqq
+\vec s \mapsto
+\{\, \vec \delta \in \Z^{d} \mid \exists \vec x \to \vec y \in R :
+\vec \delta = \vec y - \vec x
+\,\}
+$$
+\end{definition}
+
+\section{Simple Hull}\label{s:simple hull}
+
+It is sometimes useful to have a single
+basic set or basic relation that contains a given set or relation.
+For rational sets, the obvious choice would be to compute the
+(rational) convex hull.  For integer sets, the obvious choice
+would be the integer hull.
+However, {\tt isl} currently does not support an integer hull operation
+and even if it did, it would be fairly expensive to compute.
+The convex hull operation is supported, but it is also fairly
+expensive to compute given only an implicit representation.
+
+Usually, it is not required to compute the exact integer hull,
+and an overapproximation of this hull is sufficient.
+The ``simple hull'' of a set is such an overapproximation
+and it is defined as the (inclusion-wise) smallest basic set
+that is described by constraints that are translates of
+the constraints in the input set.
+This means that the simple hull is relatively cheap to compute
+and that the number of constraints in the simple hull is no
+larger than the number of constraints in the input.
+\begin{definition}[Simple Hull of a Set]
+The {\em simple hull} of a set
+$S = \bigcup_{1 \le i \le v} S_i$, with
+$$
+S : \Z^n \to 2^{\Z^d} : \vec s \mapsto
+S(\vec s) =
+\left\{\, \vec x \in \Z^d \mid \exists \vec z \in \Z^e :
+\bigvee_{1 \le i \le v}
+A_i \vec x + B_i \vec s + D_i \vec z + \vec c_i \geq \vec 0 \,\right\}
+$$
+is the set
+$$
+H : \Z^n \to 2^{\Z^d} : \vec s \mapsto
+S(\vec s) =
+\left\{\, \vec x \in \Z^d \mid \exists \vec z \in \Z^e :
+\bigwedge_{1 \le i \le v}
+A_i \vec x + B_i \vec s + D_i \vec z + \vec c_i + \vec K_i \geq \vec 0
+\,\right\}
+,
+$$
+with $\vec K_i$ the (component-wise) smallest non-negative integer vectors
+such that $S \subseteq H$.
+\end{definition}
+The $\vec K_i$ can be obtained by solving a number of
+LP problems, one for each element of each $\vec K_i$.
+If any LP problem is unbounded, then the corresponding constraint
+is dropped.
+
+\section{Parametric Integer Programming}
+
+\subsection{Introduction}\label{s:intro}
+
+Parametric integer programming \shortcite{Feautrier88parametric}
+is used to solve many problems within the context of the polyhedral model.
+Here, we are mainly interested in dependence analysis \shortcite{Fea91}
+and in computing a unique representation for existentially quantified
+variables.  The latter operation has been used for counting elements
+in sets involving such variables
+\shortcite{BouletRe98,Verdoolaege2005experiences} and lies at the core
+of the internal representation of {\tt isl}.
+
+Parametric integer programming was first implemented in \texttt{PipLib}.
+An alternative method for parametric integer programming
+was later implemented in {\tt barvinok} \cite{barvinok-0.22}.
+This method is not based on Feautrier's algorithm, but on rational
+generating functions \cite{Woods2003short} and was inspired by the
+``digging'' technique of \shortciteN{DeLoera2004Three} for solving
+non-parametric integer programming problems.
+
+In the following sections, we briefly recall the dual simplex
+method combined with Gomory cuts and describe some extensions
+and optimizations.  The main algorithm is applied to a matrix
+data structure known as a tableau.  In case of parametric problems,
+there are two tableaus, one for the main problem and one for
+the constraints on the parameters, known as the context tableau.
+The handling of the context tableau is described in \autoref{s:context}.
+
+\subsection{The Dual Simplex Method}
+
+Tableaus can be represented in several slightly different ways.
+In {\tt isl}, the dual simplex method uses the same representation
+as that used by its incremental LP solver based on the \emph{primal}
+simplex method.  The implementation of this LP solver is based
+on that of {\tt Simplify} \shortcite{Detlefs2005simplify}, which, in turn,
+was derived from the work of \shortciteN{Nelson1980phd}.
+In the original \shortcite{Nelson1980phd}, the tableau was implemented
+as a sparse matrix, but neither {\tt Simplify} nor the current
+implementation of {\tt isl} does so.
+
+Given some affine constraints on the variables,
+$A \vec x + \vec b \ge \vec 0$, the tableau represents the relationship
+between the variables $\vec x$ and non-negative variables
+$\vec y = A \vec x + \vec b$ corresponding to the constraints.
+The initial tableau contains $\begin{pmatrix}
+\vec b & A
+\end{pmatrix}$ and expresses the constraints $\vec y$ in the rows in terms
+of the variables $\vec x$ in the columns.  The main operation defined
+on a tableau exchanges a column and a row variable and is called a pivot.
+During this process, some coefficients may become rational.
+As in the \texttt{PipLib} implementation,
+{\tt isl} maintains a shared denominator per row.
+The sample value of a tableau is one where each column variable is assigned
+zero and each row variable is assigned the constant term of the row.
+This sample value represents a valid solution if each constraint variable
+is assigned a non-negative value, i.e., if the constant terms of
+rows corresponding to constraints are all non-negative.
+
+The dual simplex method starts from an initial sample value that
+may be invalid, but that is known to be (lexicographically) no
+greater than any solution, and gradually increments this sample value
+through pivoting until a valid solution is obtained.
+In particular, each pivot exchanges a row variable
+$r = -n + \sum_i a_i \, c_i$ with negative
+sample value $-n$ with a column variable $c_j$
+such that $a_j > 0$.  Since $c_j = (n + r - \sum_{i\ne j} a_i \, c_i)/a_j$,
+the new row variable will have a positive sample value $n$.
+If no such column can be found, then the problem is infeasible.
+By always choosing the column that leads to the (lexicographically)
+smallest increment in the variables $\vec x$,
+the first solution found is guaranteed to be the (lexicographically)
+minimal solution \cite{Feautrier88parametric}.
+In order to be able to determine the smallest increment, the tableau
+is (implicitly) extended with extra rows defining the original
+variables in terms of the column variables.
+If we assume that all variables are non-negative, then we know
+that the zero vector is no greater than the minimal solution and
+then the initial extended tableau looks as follows.
+$$
+\begin{tikzpicture}
+\matrix (m) [matrix of math nodes]
+{
+& {} & 1 & \vec c \\
+\vec x && |(top)| \vec 0 & I \\
+\vec r && \vec b & |(bottom)|A \\
+};
+\begin{pgfonlayer}{background}
+\node (core) [inner sep=0pt,fill=black!20,right delimiter=),left delimiter=(,fit=(top)(bottom)] {};
+\end{pgfonlayer}
+\end{tikzpicture}
+$$
+Each column in this extended tableau is lexicographically positive
+and will remain so because of the column choice explained above.
+It is then clear that the value of $\vec x$ will increase in each step.
+Note that there is no need to store the extra rows explicitly.
+If a given $x_i$ is a column variable, then the corresponding row
+is the unit vector $e_i$.  If, on the other hand, it is a row variable,
+then the row already appears somewhere else in the tableau.
+
+In case of parametric problems, the sign of the constant term
+may depend on the parameters.  Each time the constant term of a constraint row
+changes, we therefore need to check whether the new term can attain
+negative and/or positive values over the current set of possible
+parameter values, i.e., the context.
+If all these terms can only attain non-negative values, the current
+state of the tableau represents a solution.  If one of the terms
+can only attain non-positive values and is not identically zero,
+the corresponding row can be pivoted.
+Otherwise, we pick one of the terms that can attain both positive
+and negative values and split the context into a part where
+it only attains non-negative values and a part where it only attains
+negative values.
+
+\subsection{Gomory Cuts}
+
+The solution found by the dual simplex method may have
+non-integral coordinates.  If so, some rational solutions
+(including the current sample value), can be cut off by
+applying a (parametric) Gomory cut.
+Let $r = b(\vec p) + \sp {\vec a} {\vec c}$ be the row
+corresponding to the first non-integral coordinate of $\vec x$,
+with $b(\vec p)$ the constant term, an affine expression in the
+parameters $\vec p$, i.e., $b(\vec p) = \sp {\vec f} {\vec p} + g$.
+Note that only row variables can attain
+non-integral values as the sample value of the column variables is zero.
+Consider the expression
+$b(\vec p) - \ceil{b(\vec p)} + \sp {\fract{\vec a}} {\vec c}$,
+with $\ceil\cdot$ the ceiling function and $\fract\cdot$ the
+fractional part.  This expression is negative at the sample value
+since $\vec c = \vec 0$ and $r = b(\vec p)$ is fractional, i.e.,
+$\ceil{b(\vec p)} > b(\vec p)$.  On the other hand, for each integral
+value of $r$ and $\vec c \ge 0$, the expression is non-negative
+because $b(\vec p) - \ceil{b(\vec p)} > -1$.
+Imposing this expression to be non-negative therefore does not
+invalidate any integral solutions, while it does cut away the current
+fractional sample value.  To be able to formulate this constraint,
+a new variable $q = \floor{-b(\vec p)} = - \ceil{b(\vec p)}$ is added
+to the context.  This integral variable is uniquely defined by the constraints
+$0 \le -d \, b(\vec p) - d \, q \le d - 1$, with $d$ the common
+denominator of $\vec f$ and $g$.  In practice, the variable
+$q' = \floor{\sp {\fract{-f}} {\vec p} + \fract{-g}}$ is used instead
+and the coefficients of the new constraint are adjusted accordingly.
+The sign of the constant term of this new constraint need not be determined
+as it is non-positive by construction.
+When several of these extra context variables are added, it is important
+to avoid adding duplicates.
+Recent versions of {\tt PipLib} also check for such duplicates.
+
+\subsection{Negative Unknowns and Maximization}
+
+There are two places in the above algorithm where the unknowns $\vec x$
+are assumed to be non-negative: the initial tableau starts from
+sample value $\vec x = \vec 0$ and $\vec c$ is assumed to be non-negative
+during the construction of Gomory cuts.
+To deal with negative unknowns, \shortciteN[Appendix A.2]{Fea91}
+proposed to use a ``big parameter'', say $M$, that is taken to be
+an arbitrarily large positive number.  Instead of looking for the
+lexicographically minimal value of $\vec x$, we search instead
+for the lexicographically minimal value of $\vec x' = \vec M + \vec x$.
+The sample value $\vec x' = \vec 0$ of the initial tableau then
+corresponds to $\vec x = -\vec M$, which is clearly not greater than
+any potential solution.  The sign of the constant term of a row
+is determined lexicographically, with the coefficient of $M$ considered
+first.  That is, if the coefficient of $M$ is not zero, then its sign
+is the sign of the entire term.  Otherwise, the sign is determined
+by the remaining affine expression in the parameters.
+If the original problem has a bounded optimum, then the final sample
+value will be of the form $\vec M + \vec v$ and the optimal value
+of the original problem is then $\vec v$.
+Maximization problems can be handled in a similar way by computing
+the minimum of $\vec M - \vec x$.
+
+When the optimum is unbounded, the optimal value computed for
+the original problem will involve the big parameter.
+In the original implementation of {\tt PipLib}, the big parameter could
+even appear in some of the extra variables $\vec q$ created during
+the application of a Gomory cut.  The final result could then contain
+implicit conditions on the big parameter through conditions on such
+$\vec q$ variables.  This problem was resolved in later versions
+of {\tt PipLib} by taking $M$ to be divisible by any positive number.
+The big parameter can then never appear in any $\vec q$ because
+$\fract {\alpha M } = 0$.  It should be noted, though, that an unbounded
+problem usually (but not always)
+indicates an incorrect formulation of the problem.
+
+The original version of {\tt PipLib} required the user to ``manually''
+add a big parameter, perform the reformulation and interpret the result
+\shortcite{Feautrier02}.  Recent versions allow the user to simply
+specify that the unknowns may be negative or that the maximum should
+be computed and then these transformations are performed internally.
+Although there are some application, e.g.,
+that of \shortciteN{Feautrier92multi},
+where it is useful to have explicit control over the big parameter,
+negative unknowns and maximization are by far the most common applications
+of the big parameter and we believe that the user should not be bothered
+with such implementation issues.
+The current version of {\tt isl} therefore does not
+provide any interface for specifying big parameters.  Instead, the user
+can specify whether a maximum needs to be computed and no assumptions
+are made on the sign of the unknowns.  Instead, the sign of the unknowns
+is checked internally and a big parameter is automatically introduced when
+needed.  For compatibility with {\tt PipLib}, the {\tt isl\_pip} tool
+does explicitly add non-negativity constraints on the unknowns unless
+the \verb+Urs_unknowns+ option is specified.
+Currently, there is also no way in {\tt isl} of expressing a big
+parameter in the output.  Even though
+{\tt isl} makes the same divisibility assumption on the big parameter
+as recent versions of {\tt PipLib}, it will therefore eventually
+produce an error if the problem turns out to be unbounded.
+
+\subsection{Preprocessing}
+
+In this section, we describe some transformations that are
+or can be applied in advance to reduce the running time
+of the actual dual simplex method with Gomory cuts.
+
+\subsubsection{Feasibility Check and Detection of Equalities}
+
+Experience with the original {\tt PipLib} has shown that Gomory cuts
+do not perform very well on problems that are (non-obviously) empty,
+i.e., problems with rational solutions, but no integer solutions.
+In {\tt isl}, we therefore first perform a feasibility check on
+the original problem considered as a non-parametric problem
+over the combined space of unknowns and parameters.
+In fact, we do not simply check the feasibility, but we also
+check for implicit equalities among the integer points by computing
+the integer affine hull.  The algorithm used is the same as that
+described in \autoref{s:GBR} below.
+Computing the affine hull is fairly expensive, but it can
+bring huge benefits if any equalities can be found or if the problem
+turns out to be empty.
+
+\subsubsection{Constraint Simplification}
+
+If the coefficients of the unknown and parameters in a constraint
+have a common factor, then this factor should be removed, possibly
+rounding down the constant term.  For example, the constraint
+$2 x - 5 \ge 0$ should be simplified to $x - 3 \ge 0$.
+{\tt isl} performs such simplifications on all sets and relations.
+Recent versions of {\tt PipLib} also perform this simplification
+on the input.
+
+\subsubsection{Exploiting Equalities}\label{s:equalities}
+
+If there are any (explicit) equalities in the input description,
+{\tt PipLib} converts each into a pair of inequalities.
+It is also possible to write $r$ equalities as $r+1$ inequalities
+\shortcite{Feautrier02}, but it is even better to \emph{exploit} the
+equalities to reduce the dimensionality of the problem.
+Given an equality involving at least one unknown, we pivot
+the row corresponding to the equality with the column corresponding
+to the last unknown with non-zero coefficient.  The new column variable
+can then be removed completely because it is identically zero,
+thereby reducing the dimensionality of the problem by one.
+The last unknown is chosen to ensure that the columns of the initial
+tableau remain lexicographically positive.  In particular, if
+the equality is of the form $b + \sum_{i \le j} a_i \, x_i = 0$ with
+$a_j \ne 0$, then the (implicit) top rows of the initial tableau
+are changed as follows
+$$
+\begin{tikzpicture}
+\matrix [matrix of math nodes]
+{
+ & {} & |(top)| 0 & I_1 & |(j)| &  \\
+j && 0 & & 1 & \\
+  && 0 & & & |(bottom)|I_2 \\
+};
+\node[overlay,above=2mm of j,anchor=south]{j};
+\begin{pgfonlayer}{background}
+\node (m) [inner sep=0pt,fill=black!20,right delimiter=),left delimiter=(,fit=(top)(bottom)] {};
+\end{pgfonlayer}
+\begin{scope}[xshift=4cm]
+\matrix [matrix of math nodes]
+{
+ & {} & |(top)| 0 & I_1 &  \\
+j && |(left)| -b/a_j & -a_i/a_j & \\
+  && 0 & & |(bottom)|I_2 \\
+};
+\begin{pgfonlayer}{background}
+\node (m2) [inner sep=0pt,fill=black!20,right delimiter=),left delimiter=(,fit=(top)(bottom)(left)] {};
+\end{pgfonlayer}
+\end{scope}
+ \draw [shorten >=7mm,-to,thick,decorate,
+        decoration={snake,amplitude=.4mm,segment length=2mm,
+                    pre=moveto,pre length=5mm,post length=8mm}]
+   (m) -- (m2);
+\end{tikzpicture}
+$$
+Currently, {\tt isl} also eliminates equalities involving only parameters
+in a similar way, provided at least one of the coefficients is equal to one.
+The application of parameter compression (see below)
+would obviate the need for removing parametric equalities.
+
+\subsubsection{Offline Symmetry Detection}\label{s:offline}
+
+Some problems, notably those of \shortciteN{Bygde2010licentiate},
+have a collection of constraints, say
+$b_i(\vec p) + \sp {\vec a} {\vec x} \ge 0$,
+that only differ in their (parametric) constant terms.
+These constant terms will be non-negative on different parts
+of the context and this context may have to be split for each
+of the constraints.  In the worst case, the basic algorithm may
+have to consider all possible orderings of the constant terms.
+Instead, {\tt isl} introduces a new parameter, say $u$, and
+replaces the collection of constraints by the single
+constraint $u + \sp {\vec a} {\vec x} \ge 0$ along with
+context constraints $u \le b_i(\vec p)$.
+Any solution to the new system is also a solution
+to the original system since
+$\sp {\vec a} {\vec x} \ge -u \ge -b_i(\vec p)$.
+Conversely, $m = \min_i b_i(\vec p)$ satisfies the constraints
+on $u$ and therefore extends a solution to the new system.
+It can also be plugged into a new solution.
+See \autoref{s:post} for how this substitution is currently performed
+in {\tt isl}.
+The method described in this section can only detect symmetries
+that are explicitly available in the input.
+See \autoref{s:online} for the detection
+and exploitation of symmetries that appear during the course of
+the dual simplex method.
+
+\subsubsection{Parameter Compression}\label{s:compression}
+
+It may in some cases be apparent from the equalities in the problem
+description that there can only be a solution for a sublattice
+of the parameters.  In such cases ``parameter compression''
+\shortcite{Meister2004PhD,Meister2008} can be used to replace
+the parameters by alternative ``dense'' parameters.
+For example, if there is a constraint $2x = n$, then the system
+will only have solutions for even values of $n$ and $n$ can be replaced
+by $2n'$.  Similarly, the parameters $n$ and $m$ in a system with
+the constraint $2n = 3m$ can be replaced by a single parameter $n'$
+with $n=3n'$ and $m=2n'$.
+It is also possible to perform a similar compression on the unknowns,
+but it would be more complicated as the compression would have to
+preserve the lexicographical order.  Moreover, due to our handling
+of equalities described above there should be
+no need for such variable compression.
+Although parameter compression has been implemented in {\tt isl},
+it is currently not yet used during parametric integer programming.
+
+\subsection{Postprocessing}\label{s:post}
+
+The output of {\tt PipLib} is a quast (quasi-affine selection tree).
+Each internal node in this tree corresponds to a split of the context
+based on a parametric constant term in the main tableau with indeterminate
+sign.  Each of these nodes may introduce extra variables in the context
+corresponding to integer divisions.  Each leaf of the tree prescribes
+the solution in that part of the context that satisfies all the conditions
+on the path leading to the leaf.
+Such a quast is a very economical way of representing the solution, but
+it would not be suitable as the (only) internal representation of
+sets and relations in {\tt isl}.  Instead, {\tt isl} represents
+the constraints of a set or relation in disjunctive normal form.
+The result of a parametric integer programming problem is then also
+converted to this internal representation.  Unfortunately, the conversion
+to disjunctive normal form can lead to an explosion of the size
+of the representation.
+In some cases, this overhead would have to be paid anyway in subsequent
+operations, but in other cases, especially for outside users that just
+want to solve parametric integer programming problems, we would like
+to avoid this overhead in future.  That is, we are planning on introducing
+quasts or a related representation as one of several possible internal
+representations and on allowing the output of {\tt isl\_pip} to optionally
+be printed as a quast.
+
+Currently, {\tt isl} also does not have an internal representation
+for expressions such as $\min_i b_i(\vec p)$ from the offline
+symmetry detection of \autoref{s:offline}.
+Assume that one of these expressions has $n$ bounds $b_i(\vec p)$.
+If the expression
+does not appear in the affine expression describing the solution,
+but only in the constraints, and if moreover, the expression
+only appears with a positive coefficient, i.e.,
+$\min_i b_i(\vec p) \ge f_j(\vec p)$, then each of these constraints
+can simply be reduplicated $n$ times, once for each of the bounds.
+Otherwise, a conversion to disjunctive normal form
+leads to $n$ cases, each described as $u = b_i(\vec p)$ with constraints
+$b_i(\vec p) \le b_j(\vec p)$ for $j > i$
+and
+$b_i(\vec p)  < b_j(\vec p)$ for $j < i$.
+Note that even though this conversion leads to a size increase
+by a factor of $n$, not detecting the symmetry could lead to
+an increase by a factor of $n!$ if all possible orderings end up being
+considered.
+
+\subsection{Context Tableau}\label{s:context}
+
+The main operation that a context tableau needs to provide is a test
+on the sign of an affine expression over the elements of the context.
+This sign can be determined by solving two integer linear feasibility
+problems, one with a constraint added to the context that enforces
+the expression to be non-negative and one where the expression is
+negative.  As already mentioned by \shortciteN{Feautrier88parametric},
+any integer linear feasibility solver could be used, but the {\tt PipLib}
+implementation uses a recursive call to the dual simplex with Gomory
+cuts algorithm to determine the feasibility of a context.
+In {\tt isl}, two ways of handling the context have been implemented,
+one that performs the recursive call and one, used by default, that
+uses generalized basis reduction.
+We start with some optimizations that are shared between the two
+implementations and then discuss additional details of each of them.
+
+\subsubsection{Maintaining Witnesses}\label{s:witness}
+
+A common feature of both integer linear feasibility solvers is that
+they will not only say whether a set is empty or not, but if the set
+is non-empty, they will also provide a \emph{witness} for this result,
+i.e., a point that belongs to the set.  By maintaining a list of such
+witnesses, we can avoid many feasibility tests during the determination
+of the signs of affine expressions.  In particular, if the expression
+evaluates to a positive number on some of these points and to a negative
+number on some others, then no feasibility test needs to be performed.
+If all the evaluations are non-negative, we only need to check for the
+possibility of a negative value and similarly in case of all
+non-positive evaluations.  Finally, in the rare case that all points
+evaluate to zero or at the start, when no points have been collected yet,
+one or two feasibility tests need to be performed depending on the result
+of the first test.
+
+When a new constraint is added to the context, the points that
+violate the constraint are temporarily removed.  They are reconsidered
+when we backtrack over the addition of the constraint, as they will
+satisfy the negation of the constraint.  It is only when we backtrack
+over the addition of the points that they are finally removed completely.
+When an extra integer division is added to the context,
+the new coordinates of the
+witnesses can easily be computed by evaluating the integer division.
+The idea of keeping track of witnesses was first used in {\tt barvinok}.
+
+\subsubsection{Choice of Constant Term on which to Split}
+
+Recall that if there are no rows with a non-positive constant term,
+but there are rows with an indeterminate sign, then the context
+needs to be split along the constant term of one of these rows.
+If there is more than one such row, then we need to choose which row
+to split on first.  {\tt PipLib} uses a heuristic based on the (absolute)
+sizes of the coefficients.  In particular, it takes the largest coefficient
+of each row and then selects the row where this largest coefficient is smaller
+than those of the other rows.
+
+In {\tt isl}, we take that row for which non-negativity of its constant
+term implies non-negativity of as many of the constant terms of the other
+rows as possible.  The intuition behind this heuristic is that on the
+positive side, we will have fewer negative and indeterminate signs,
+while on the negative side, we need to perform a pivot, which may
+affect any number of rows meaning that the effect on the signs
+is difficult to predict.  This heuristic is of course much more
+expensive to evaluate than the heuristic used by {\tt PipLib}.
+More extensive tests are needed to evaluate whether the heuristic is worthwhile.
+
+\subsubsection{Dual Simplex + Gomory Cuts}
+
+When a new constraint is added to the context, the first steps
+of the dual simplex method applied to this new context will be the same
+or at least very similar to those taken on the original context, i.e.,
+before the constraint was added.  In {\tt isl}, we therefore apply
+the dual simplex method incrementally on the context and backtrack
+to a previous state when a constraint is removed again.
+An initial implementation that was never made public would also
+keep the Gomory cuts, but the current implementation backtracks
+to before the point where Gomory cuts are added before adding
+an extra constraint to the context.
+Keeping the Gomory cuts has the advantage that the sample value
+is always an integer point and that this point may also satisfy
+the new constraint.  However, due to the technique of maintaining
+witnesses explained above,
+we would not perform a feasibility test in such cases and then
+the previously added cuts may be redundant, possibly resulting
+in an accumulation of a large number of cuts.
+
+If the parameters may be negative, then the same big parameter trick
+used in the main tableau is applied to the context.  This big parameter
+is of course unrelated to the big parameter from the main tableau.
+Note that it is not a requirement for this parameter to be ``big'',
+but it does allow for some code reuse in {\tt isl}.
+In {\tt PipLib}, the extra parameter is not ``big'', but this may be because
+the big parameter of the main tableau also appears
+in the context tableau.
+
+Finally, it was reported by \shortciteN{Galea2009personal}, who
+worked on a parametric integer programming implementation
+in {\tt PPL} \shortcite{PPL},
+that it is beneficial to add cuts for \emph{all} rational coordinates
+in the context tableau.  Based on this report,
+the initial {\tt isl} implementation was adapted accordingly.
+
+\subsubsection{Generalized Basis Reduction}\label{s:GBR}
+
+The default algorithm used in {\tt isl} for feasibility checking
+is generalized basis reduction \shortcite{Cook1991implementation}.
+This algorithm is also used in the {\tt barvinok} implementation.
+The algorithm is fairly robust, but it has some overhead.
+We therefore try to avoid calling the algorithm in easy cases.
+In particular, we incrementally keep track of points for which
+the entire unit hypercube positioned at that point lies in the context.
+This set is described by translates of the constraints of the context
+and if (rationally) non-empty, any rational point
+in the set can be rounded up to yield an integer point in the context.
+
+A restriction of the algorithm is that it only works on bounded sets.
+The affine hull of the recession cone therefore needs to be projected
+out first.  As soon as the algorithm is invoked, we then also
+incrementally keep track of this recession cone.  The reduced basis
+found by one call of the algorithm is also reused as initial basis
+for the next call.
+
+Some problems lead to the
+introduction of many integer divisions.  Within a given context,
+some of these integer divisions may be equal to each other, even
+if the expressions are not identical, or they may be equal to some
+affine combination of other variables.
+To detect such cases, we compute the affine hull of the context
+each time a new integer division is added.  The algorithm used
+for computing this affine hull is that of \shortciteN{Karr1976affine},
+while the points used in this algorithm are obtained by performing
+integer feasibility checks on that part of the context outside
+the current approximation of the affine hull.
+The list of witnesses is used to construct an initial approximation
+of the hull, while any extra points found during the construction
+of the hull is added to this list.
+Any equality found in this way that expresses an integer division
+as an \emph{integer} affine combination of other variables is
+propagated to the main tableau, where it is used to eliminate that
+integer division.
+
+\subsection{Experiments}
+
+\autoref{t:comparison} compares the execution times of {\tt isl}
+(with both types of context tableau)
+on some more difficult instances to those of other tools,
+run on an Intel Xeon W3520 @ 2.66GHz.
+Easier problems such as the
+test cases distributed with {\tt Pip\-Lib} can be solved so quickly
+that we would only be measuring overhead such as input/output and conversions
+and not the running time of the actual algorithm.
+We compare the following versions:
+{\tt piplib-1.4.0-5-g0132fd9},
+{\tt barvinok-0.32.1-73-gc5d7751},
+{\tt isl-0.05.1-82-g3a37260}
+and {\tt PPL} version 0.11.2.
+
+The first test case is the following dependence analysis problem
+originating from the Phideo project \shortcite{Verhaegh1995PhD}
+that was communicated to us by Bart Kienhuis:
+\begin{lstlisting}[flexiblecolumns=true,breaklines=true]{}
+lexmax { [j1,j2] -> [i1,i2,i3,i4,i5,i6,i7,i8,i9,i10] : 1 <= i1,j1 <= 8 and 1 <= i2,i3,i4,i5,i6,i7,i8,i9,i10 <= 2 and 1 <= j2 <= 128 and i1-1 = j1-1 and i2-1+2*i3-2+4*i4-4+8*i5-8+16*i6-16+32*i7-32+64*i8-64+128*i9-128+256*i10-256=3*j2-3+66 };
+\end{lstlisting}
+This problem was the main inspiration
+for some of the optimizations in \autoref{s:GBR}.
+The second group of test cases are projections used during counting.
+The first nine of these come from \shortciteN{Seghir2006minimizing}.
+The remaining two come from \shortciteN{Verdoolaege2005experiences} and
+were used to drive the first, Gomory cuts based, implementation
+in {\tt isl}.
+The third and final group of test cases are borrowed from
+\shortciteN{Bygde2010licentiate} and inspired the offline symmetry detection
+of \autoref{s:offline}.  Without symmetry detection, the running times
+are 11s and 5.9s.
+All running times of {\tt barvinok} and {\tt isl} include a conversion
+to disjunctive normal form.  Without this conversion, the final two
+cases can be solved in 0.07s and 0.21s.
+The {\tt PipLib} implementation has some fixed limits and will
+sometimes report the problem to be too complex (TC), while on some other
+problems it will run out of memory (OOM).
+The {\tt barvinok} implementation does not support problems
+with a non-trivial lineality space (line) nor maximization problems (max).
+The Gomory cuts based {\tt isl} implementation was terminated after 1000
+minutes on the first problem.  The gbr version introduces some
+overhead on some of the easier problems, but is overall the clear winner.
+
+\begin{table}
+\begin{center}
+\begin{tabular}{lrrrrr}
+    & {\tt PipLib} & {\tt barvinok} & {\tt isl} cut & {\tt isl} gbr & {\tt PPL} \\
+\hline
+\hline
+% bart.pip
+Phideo & TC    & 793m   & $>$999m &   2.7s  & 372m \\
+\hline
+e1 & 0.33s & 3.5s & 0.08s & 0.11s & 0.18s \\
+e3 & 0.14s & 0.13s & 0.10s & 0.10s & 0.17s \\
+e4 & 0.24s & 9.1s & 0.09s & 0.11s & 0.70s \\
+e5 & 0.12s & 6.0s & 0.06s & 0.14s & 0.17s \\
+e6 & 0.10s & 6.8s & 0.17s & 0.08s & 0.21s \\
+e7 & 0.03s & 0.27s & 0.04s & 0.04s & 0.03s \\
+e8 & 0.03s & 0.18s & 0.03s & 0.04s & 0.01s \\
+e9 & OOM & 70m & 2.6s & 0.94s & 22s \\
+vd & 0.04s & 0.10s & 0.03s & 0.03s & 0.03s \\
+bouleti & 0.25s & line & 0.06s & 0.06s & 0.15s \\
+difficult & OOM & 1.3s & 1.7s & 0.33s & 1.4s \\
+\hline
+cnt/sum & TC & max & 2.2s & 2.2s & OOM \\
+jcomplex & TC & max & 3.7s & 3.9s & OOM \\
+\end{tabular}
+\caption{Comparison of Execution Times}
+\label{t:comparison}
+\end{center}
+\end{table}
+
+\subsection{Online Symmetry Detection}\label{s:online}
+
+Manual experiments on small instances of the problems of
+\shortciteN{Bygde2010licentiate} and an analysis of the results
+by the approximate MPA method developed by \shortciteN{Bygde2010licentiate}
+have revealed that these problems contain many more symmetries
+than can be detected using the offline method of \autoref{s:offline}.
+In this section, we present an online detection mechanism that has
+not been implemented yet, but that has shown promising results
+in manual applications.
+
+Let us first consider what happens when we do not perform offline
+symmetry detection.  At some point, one of the
+$b_i(\vec p) + \sp {\vec a} {\vec x} \ge 0$ constraints,
+say the $j$th constraint, appears as a column
+variable, say $c_1$, while the other constraints are represented
+as rows of the form $b_i(\vec p) - b_j(\vec p) + c$.
+The context is then split according to the relative order of
+$b_j(\vec p)$ and one of the remaining $b_i(\vec p)$.
+The offline method avoids this split by replacing all $b_i(\vec p)$
+by a single newly introduced parameter that represents the minimum
+of these $b_i(\vec p)$.
+In the online method the split is similarly avoided by the introduction
+of a new parameter.  In particular, a new parameter is introduced
+that represents
+$\left| b_j(\vec p) - b_i(\vec p) \right|_+ =
+\max(b_j(\vec p) - b_i(\vec p), 0)$.
+
+In general, let $r = b(\vec p) + \sp {\vec a} {\vec c}$ be a row
+of the tableau such that the sign of $b(\vec p)$ is indeterminate
+and such that exactly one of the elements of $\vec a$ is a $1$,
+while all remaining elements are non-positive.
+That is, $r = b(\vec p) + c_j - f$ with $f = -\sum_{i\ne j} a_i c_i \ge 0$.
+We introduce a new parameter $t$ with
+context constraints $t \ge -b(\vec p)$ and $t \ge 0$ and replace
+the column variable $c_j$ by $c' + t$.  The row $r$ is now equal
+to $b(\vec p) + t + c' - f$.  The constant term of this row is always
+non-negative because any negative value of $b(\vec p)$ is compensated
+by $t \ge -b(\vec p)$ while and non-negative value remains non-negative
+because $t \ge 0$.
+
+We need to show that this transformation does not eliminate any valid
+solutions and that it does not introduce any spurious solutions.
+Given a valid solution for the original problem, we need to find
+a non-negative value of $c'$ satisfying the constraints.
+If $b(\vec p) \ge 0$, we can take $t = 0$ so that
+$c' = c_j - t = c_j \ge 0$.
+If $b(\vec p) < 0$, we can take $t = -b(\vec p)$.
+Since $r = b(\vec p) + c_j - f \ge 0$ and $f \ge 0$, we have 
+$c' = c_j + b(\vec p) \ge 0$.
+Note that these choices amount to plugging in
+$t = \left|-b(\vec p)\right|_+ = \max(-b(\vec p), 0)$.
+Conversely, given a solution to the new problem, we need to find
+a non-negative value of $c_j$, but this is easy since $c_j = c' + t$
+and both of these are non-negative.
+
+Plugging in $t = \max(-b(\vec p), 0)$ can be performed as in
+\autoref{s:post}, but, as in the case of offline symmetry detection,
+it may be better to provide a direct representation for such
+expressions in the internal representation of sets and relations
+or at least in a quast-like output format.
+
+\section{Coalescing}\label{s:coalescing}
+
+See \shortciteN{Verdoolaege2009isl}, for now.
+More details will be added later.
+
+\section{Transitive Closure}
+
+\subsection{Introduction}
+
+\begin{definition}[Power of a Relation]
+Let $R \in \Z^n \to 2^{\Z^{d+d}}$ be a relation and
+$k \in \Z_{\ge 1}$
+a positive number, then power $k$ of relation $R$ is defined as
+\begin{equation}
+\label{eq:transitive:power}
+R^k \coloneqq
+\begin{cases}
+R & \text{if $k = 1$}
+\\
+R \circ R^{k-1} & \text{if $k \ge 2$}
+.
+\end{cases}
+\end{equation}
+\end{definition}
+
+\begin{definition}[Transitive Closure of a Relation]
+Let $R \in \Z^n \to 2^{\Z^{d+d}}$ be a relation,
+then the transitive closure $R^+$ of $R$ is the union
+of all positive powers of $R$,
+$$
+R^+ \coloneqq \bigcup_{k \ge 1} R^k
+.
+$$
+\end{definition}
+Alternatively, the transitive closure may be defined
+inductively as
+\begin{equation}
+\label{eq:transitive:inductive}
+R^+ \coloneqq R \cup \left(R \circ R^+\right)
+.
+\end{equation}
+
+Since the transitive closure of a polyhedral relation
+may no longer be a polyhedral relation \shortcite{Kelly1996closure},
+we can, in the general case, only compute an approximation
+of the transitive closure.
+Whereas \shortciteN{Kelly1996closure} compute underapproximations,
+we, like \shortciteN{Beletska2009}, compute overapproximations.
+That is, given a relation $R$, we will compute a relation $T$
+such that $R^+ \subseteq T$.  Of course, we want this approximation
+to be as close as possible to the actual transitive closure
+$R^+$ and we want to detect the cases where the approximation is
+exact, i.e., where $T = R^+$.
+
+For computing an approximation of the transitive closure of $R$,
+we follow the same general strategy as \shortciteN{Beletska2009}
+and first compute an approximation of $R^k$ for $k \ge 1$ and then project
+out the parameter $k$ from the resulting relation.
+
+\begin{example}
+As a trivial example, consider the relation
+$R = \{\, x \to x + 1 \,\}$.  The $k$th power of this map
+for arbitrary $k$ is
+$$
+R^k = k \mapsto \{\, x \to x + k \mid k \ge 1 \,\}
+.
+$$
+The transitive closure is then
+$$
+\begin{aligned}
+R^+ & = \{\, x \to y \mid \exists k \in \Z_{\ge 1} : y = x + k \,\}
+\\
+& = \{\, x \to y \mid y \ge x + 1 \,\}
+.
+\end{aligned}
+$$
+\end{example}
+
+\subsection{Computing an Approximation of $R^k$}
+\label{s:power}
+
+There are some special cases where the computation of $R^k$ is very easy.
+One such case is that where $R$ does not compose with itself,
+i.e., $R \circ R = \emptyset$ or $\domain R \cap \range R = \emptyset$.
+In this case, $R^k$ is only non-empty for $k=1$ where it is equal
+to $R$ itself.
+
+In general, it is impossible to construct a closed form
+of $R^k$ as a polyhedral relation.
+We will therefore need to make some approximations.
+As a first approximations, we will consider each of the basic
+relations in $R$ as simply adding one or more offsets to a domain element
+to arrive at an image element and ignore the fact that some of these
+offsets may only be applied to some of the domain elements.
+That is, we will only consider the difference set $\Delta\,R$ of the relation.
+In particular, we will first construct a collection $P$ of paths
+that move through
+a total of $k$ offsets and then intersect domain and range of this
+collection with those of $R$.
+That is, 
+\begin{equation}
+\label{eq:transitive:approx}
+K = P \cap \left(\domain R \to \range R\right)
+,
+\end{equation}
+with
+\begin{equation}
+\label{eq:transitive:path}
+P = \vec s \mapsto \{\, \vec x \to \vec y \mid
+\exists k_i \in \Z_{\ge 0}, \vec\delta_i \in k_i \, \Delta_i(\vec s) :
+\vec y = \vec x + \sum_i \vec\delta_i
+\wedge
+\sum_i k_i = k > 0
+\,\}
+\end{equation}
+and with $\Delta_i$ the basic sets that compose
+the difference set $\Delta\,R$.
+Note that the number of basic sets $\Delta_i$ need not be
+the same as the number of basic relations in $R$.
+Also note that since addition is commutative, it does not
+matter in which order we add the offsets and so we are allowed
+to group them as we did in \eqref{eq:transitive:path}.
+
+If all the $\Delta_i$s are singleton sets
+$\Delta_i = \{\, \vec \delta_i \,\}$ with $\vec \delta_i \in \Z^d$,
+then \eqref{eq:transitive:path} simplifies to
+\begin{equation}
+\label{eq:transitive:singleton}
+P = \{\, \vec x \to \vec y \mid
+\exists k_i \in \Z_{\ge 0} :
+\vec y = \vec x + \sum_i k_i \, \vec \delta_i
+\wedge
+\sum_i k_i = k > 0
+\,\}
+\end{equation}
+and then the approximation computed in \eqref{eq:transitive:approx}
+is essentially the same as that of \shortciteN{Beletska2009}.
+If some of the $\Delta_i$s are not singleton sets or if
+some of $\vec \delta_i$s are parametric, then we need
+to resort to further approximations.
+
+To ease both the exposition and the implementation, we will for
+the remainder of this section work with extended offsets
+$\Delta_i' = \Delta_i \times \{\, 1 \,\}$.
+That is, each offset is extended with an extra coordinate that is
+set equal to one.  The paths constructed by summing such extended
+offsets have the length encoded as the difference of their
+final coordinates.  The path $P'$ can then be decomposed into
+paths $P_i'$, one for each $\Delta_i$,
+\begin{equation}
+\label{eq:transitive:decompose}
+P' = \left(
+(P_m' \cup \identity) \circ \cdots \circ
+(P_2' \cup \identity) \circ
+(P_1' \cup \identity)
+\right) \cap
+\{\,
+\vec x' \to \vec y' \mid y_{d+1} - x_{d+1} = k > 0
+\,\}
+,
+\end{equation}
+with
+$$
+P_i' = \vec s \mapsto \{\, \vec x' \to \vec y' \mid
+\exists k \in \Z_{\ge 1}, \vec \delta \in k \, \Delta_i'(\vec s) :
+\vec y' = \vec x' + \vec \delta
+\,\}
+.
+$$
+Note that each $P_i'$ contains paths of length at least one.
+We therefore need to take the union with the identity relation
+when composing the $P_i'$s to allow for paths that do not contain
+any offsets from one or more $\Delta_i'$.
+The path that consists of only identity relations is removed
+by imposing the constraint $y_{d+1} - x_{d+1} > 0$.
+Taking the union with the identity relation means that
+that the relations we compose in \eqref{eq:transitive:decompose}
+each consist of two basic relations.  If there are $m$
+disjuncts in the input relation, then a direct application
+of the composition operation may therefore result in a relation
+with $2^m$ disjuncts, which is prohibitively expensive.
+It is therefore crucial to apply coalescing (\autoref{s:coalescing})
+after each composition.
+
+Let us now consider how to compute an overapproximation of $P_i'$.
+Those that correspond to singleton $\Delta_i$s are grouped together
+and handled as in \eqref{eq:transitive:singleton}.
+Note that this is just an optimization.  The procedure described
+below would produce results that are at least as accurate.
+For simplicity, we first assume that no constraint in $\Delta_i'$
+involves any existentially quantified variables.
+We will return to existentially quantified variables at the end
+of this section.
+Without existentially quantified variables, we can classify
+the constraints of $\Delta_i'$ as follows
+\begin{enumerate}
+\item non-parametric constraints
+\begin{equation}
+\label{eq:transitive:non-parametric}
+A_1 \vec x + \vec c_1 \geq \vec 0
+\end{equation}
+\item purely parametric constraints
+\begin{equation}
+\label{eq:transitive:parametric}
+B_2 \vec s + \vec c_2 \geq \vec 0
+\end{equation}
+\item negative mixed constraints
+\begin{equation}
+\label{eq:transitive:mixed}
+A_3 \vec x + B_3 \vec s + \vec c_3 \geq \vec 0
+\end{equation}
+such that for each row $j$ and for all $\vec s$,
+$$
+\Delta_i'(\vec s) \cap
+\{\, \vec \delta' \mid B_{3,j} \vec s + c_{3,j} > 0 \,\}
+= \emptyset
+$$
+\item positive mixed constraints
+$$
+A_4 \vec x + B_4 \vec s + \vec c_4 \geq \vec 0
+$$
+such that for each row $j$, there is at least one $\vec s$ such that
+$$
+\Delta_i'(\vec s) \cap
+\{\, \vec \delta' \mid B_{4,j} \vec s + c_{4,j} > 0 \,\}
+\ne \emptyset
+$$
+\end{enumerate}
+We will use the following approximation $Q_i$ for $P_i'$:
+\begin{equation}
+\label{eq:transitive:Q}
+\begin{aligned}
+Q_i = \vec s \mapsto
+\{\,
+\vec x' \to \vec y'
+\mid {} & \exists k \in \Z_{\ge 1}, \vec f \in \Z^d :
+\vec y' = \vec x' + (\vec f, k)
+\wedge {}
+\\
+&
+A_1 \vec f + k \vec c_1 \geq \vec 0
+\wedge
+B_2 \vec s + \vec c_2 \geq \vec 0
+\wedge
+A_3 \vec f + B_3 \vec s + \vec c_3 \geq \vec 0
+\,\}
+.
+\end{aligned}
+\end{equation}
+To prove that $Q_i$ is indeed an overapproximation of $P_i'$,
+we need to show that for every $\vec s \in \Z^n$, for every
+$k \in \Z_{\ge 1}$ and for every $\vec f \in k \, \Delta_i(\vec s)$
+we have that
+$(\vec f, k)$ satisfies the constraints in \eqref{eq:transitive:Q}.
+If $\Delta_i(\vec s)$ is non-empty, then $\vec s$ must satisfy
+the constraints in \eqref{eq:transitive:parametric}.
+Each element $(\vec f, k) \in k \, \Delta_i'(\vec s)$ is a sum
+of $k$ elements $(\vec f_j, 1)$ in $\Delta_i'(\vec s)$.
+Each of these elements satisfies the constraints in
+\eqref{eq:transitive:non-parametric}, i.e.,
+$$
+\left[
+\begin{matrix}
+A_1 & \vec c_1
+\end{matrix}
+\right]
+\left[
+\begin{matrix}
+\vec f_j \\ 1
+\end{matrix}
+\right]
+\ge \vec 0
+.
+$$
+The sum of these elements therefore satisfies the same set of inequalities,
+i.e., $A_1 \vec f + k \vec c_1 \geq \vec 0$.
+Finally, the constraints in \eqref{eq:transitive:mixed} are such
+that for any $\vec s$ in the parameter domain of $\Delta$,
+we have $-\vec r(\vec s) \coloneqq B_3 \vec s + \vec c_3 \le \vec 0$,
+i.e., $A_3 \vec f_j \ge \vec r(\vec s) \ge \vec 0$
+and therefore also $A_3 \vec f \ge \vec r(\vec s)$.
+Note that if there are no mixed constraints and if the
+rational relaxation of $\Delta_i(\vec s)$, i.e.,
+$\{\, \vec x \in \Q^d \mid A_1 \vec x + \vec c_1 \ge \vec 0\,\}$,
+has integer vertices, then the approximation is exact, i.e.,
+$Q_i = P_i'$.  In this case, the vertices of $\Delta'_i(\vec s)$
+generate the rational cone
+$\{\, \vec x' \in \Q^{d+1} \mid \left[
+\begin{matrix}
+A_1 & \vec c_1
+\end{matrix}
+\right] \vec x' \,\}$ and therefore $\Delta'_i(\vec s)$ is
+a Hilbert basis of this cone \shortcite[Theorem~16.4]{Schrijver1986}.
+
+Note however that, as pointed out by \shortciteN{DeSmet2010personal},
+if there \emph{are} any mixed constraints, then the above procedure may
+not compute the most accurate affine approximation of
+$k \, \Delta_i(\vec s)$ with $k \ge 1$.
+In particular, we only consider the negative mixed constraints that
+happen to appear in the description of $\Delta_i(\vec s)$, while we
+should instead consider \emph{all} valid such constraints.
+It is also sufficient to consider those constraints because any
+constraint that is valid for $k \, \Delta_i(\vec s)$ is also
+valid for $1 \, \Delta_i(\vec s) = \Delta_i(\vec s)$.
+Take therefore any constraint
+$\spv a x + \spv b s + c \ge 0$ valid for $\Delta_i(\vec s)$.
+This constraint is also valid for $k \, \Delta_i(\vec s)$ iff
+$k \, \spv a x + \spv b s + c \ge 0$.
+If $\spv b s + c$ can attain any positive value, then $\spv a x$
+may be negative for some elements of $\Delta_i(\vec s)$.
+We then have $k \, \spv a x < \spv a x$ for $k > 1$ and so the constraint
+is not valid for $k \, \Delta_i(\vec s)$.
+We therefore need to impose $\spv b s + c \le 0$ for all values
+of $\vec s$ such that $\Delta_i(\vec s)$ is non-empty, i.e.,
+$\vec b$ and $c$ need to be such that $- \spv b s - c \ge 0$ is a valid
+constraint of $\Delta_i(\vec s)$.  That is, $(\vec b, c)$ are the opposites
+of the coefficients of a valid constraint of $\Delta_i(\vec s)$.
+The approximation of $k \, \Delta_i(\vec s)$ can therefore be obtained
+using three applications of Farkas' lemma.  The first obtains the coefficients
+of constraints valid for $\Delta_i(\vec s)$.  The second obtains
+the coefficients of constraints valid for the projection of $\Delta_i(\vec s)$
+onto the parameters.  The opposite of the second set is then computed
+and intersected with the first set.  The result is the set of coefficients
+of constraints valid for $k \, \Delta_i(\vec s)$.  A final application
+of Farkas' lemma is needed to obtain the approximation of
+$k \, \Delta_i(\vec s)$ itself.
+
+\begin{example}
+Consider the relation
+$$
+n \to \{\, (x, y) \to (1 + x, 1 - n + y) \mid n \ge 2 \,\}
+.
+$$
+The difference set of this relation is
+$$
+\Delta = n \to \{\, (1, 1 - n) \mid n \ge 2 \,\}
+.
+$$
+Using our approach, we would only consider the mixed constraint
+$y - 1 + n \ge 0$, leading to the following approximation of the
+transitive closure:
+$$
+n \to \{\, (x, y) \to (o_0, o_1) \mid n \ge 2 \wedge o_1 \le 1 - n + y \wedge o_0 \ge 1 + x \,\}
+.
+$$
+If, instead, we apply Farkas's lemma to $\Delta$, i.e.,
+\begin{verbatim}
+D := [n] -> { [1, 1 - n] : n >= 2 };
+CD := coefficients D;
+CD;
+\end{verbatim}
+we obtain
+\begin{verbatim}
+{ rat: coefficients[[c_cst, c_n] -> [i2, i3]] : i3 <= c_n and
+  i3 <= c_cst + 2c_n + i2 }
+\end{verbatim}
+The pure-parametric constraints valid for $\Delta$,
+\begin{verbatim}
+P := { [a,b] -> [] }(D);
+CP := coefficients P;
+CP;
+\end{verbatim}
+are
+\begin{verbatim}
+{ rat: coefficients[[c_cst, c_n] -> []] : c_n >= 0 and 2c_n >= -c_cst }
+\end{verbatim}
+Negating these coefficients and intersecting with \verb+CD+,
+\begin{verbatim}
+NCP := { rat: coefficients[[a,b] -> []]
+              -> coefficients[[-a,-b] -> []] }(CP);
+CK := wrap((unwrap CD) * (dom (unwrap NCP)));
+CK;
+\end{verbatim}
+we obtain
+\begin{verbatim}
+{ rat: [[c_cst, c_n] -> [i2, i3]] : i3 <= c_n and
+  i3 <= c_cst + 2c_n + i2 and c_n <= 0 and 2c_n <= -c_cst }
+\end{verbatim}
+The approximation for $k\,\Delta$,
+\begin{verbatim}
+K := solutions CK;
+K;
+\end{verbatim}
+is then
+\begin{verbatim}
+[n] -> { rat: [i0, i1] : i1 <= -i0 and i0 >= 1 and i1 <= 2 - n - i0 }
+\end{verbatim}
+Finally, the computed approximation for $R^+$,
+\begin{verbatim}
+T := unwrap({ [dx,dy] -> [[x,y] -> [x+dx,y+dy]] }(K));
+R := [n] -> { [x,y] -> [x+1,y+1-n] : n >= 2 };
+T := T * ((dom R) -> (ran R));
+T;
+\end{verbatim}
+is
+\begin{verbatim}
+[n] -> { [x, y] -> [o0, o1] : o1 <= x + y - o0 and
+         o0 >= 1 + x and o1 <= 2 - n + x + y - o0 and n >= 2 }
+\end{verbatim}
+\end{example}
+
+Existentially quantified variables can be handled by
+classifying them into variables that are uniquely
+determined by the parameters, variables that are independent
+of the parameters and others.  The first set can be treated
+as parameters and the second as variables.  Constraints involving
+the other existentially quantified variables are removed.
+
+\begin{example}
+Consider the relation
+$$
+R =
+n \to \{\, x \to y \mid \exists \, \alpha_0, \alpha_1: 7\alpha_0 = -2 + n \wedge 5\alpha_1 = -1 - x + y \wedge y \ge 6 + x \,\}
+.
+$$
+The difference set of this relation is
+$$
+\Delta = \Delta \, R =
+n \to \{\, x \mid \exists \, \alpha_0, \alpha_1: 7\alpha_0 = -2 + n \wedge 5\alpha_1 = -1 + x \wedge x \ge 6 \,\}
+.
+$$
+The existentially quantified variables can be defined in terms
+of the parameters and variables as
+$$
+\alpha_0 = \floor{\frac{-2 + n}7}
+\qquad
+\text{and}
+\qquad
+\alpha_1 = \floor{\frac{-1 + x}5}
+.
+$$
+$\alpha_0$ can therefore be treated as a parameter,
+while $\alpha_1$ can be treated as a variable.
+This in turn means that $7\alpha_0 = -2 + n$ can be treated as
+a purely parametric constraint, while the other two constraints are
+non-parametric.
+The corresponding $Q$~\eqref{eq:transitive:Q} is therefore
+$$
+\begin{aligned}
+n \to \{\, (x,z) \to (y,w) \mid
+\exists\, \alpha_0, \alpha_1, k, f : {} &
+k \ge 1 \wedge
+y = x + f \wedge
+w = z + k \wedge {} \\
+&
+7\alpha_0 = -2 + n \wedge
+5\alpha_1 = -k + x \wedge
+x \ge 6 k
+\,\}
+.
+\end{aligned}
+$$
+Projecting out the final coordinates encoding the length of the paths,
+results in the exact transitive closure
+$$
+R^+ =
+n \to \{\, x \to y \mid \exists \, \alpha_0, \alpha_1: 7\alpha_1 = -2 + n \wedge 6\alpha_0 \ge -x + y \wedge 5\alpha_0 \le -1 - x + y \,\}
+.
+$$
+\end{example}
+
+The fact that we ignore some impure constraints clearly leads
+to a loss of accuracy.  In some cases, some of this loss can be recovered
+by not considering the parameters in a special way.
+That is, instead of considering the set
+$$
+\Delta = \diff R =
+\vec s \mapsto
+\{\, \vec \delta \in \Z^{d} \mid \exists \vec x \to \vec y \in R :
+\vec \delta = \vec y - \vec x
+\,\}
+$$
+we consider the set
+$$
+\Delta' = \diff R' =
+\{\, \vec \delta \in \Z^{n+d} \mid \exists
+(\vec s, \vec x) \to (\vec s, \vec y) \in R' :
+\vec \delta = (\vec s - \vec s, \vec y - \vec x)
+\,\}
+.
+$$
+The first $n$ coordinates of every element in $\Delta'$ are zero.
+Projecting out these zero coordinates from $\Delta'$ is equivalent
+to projecting out the parameters in $\Delta$.
+The result is obviously a superset of $\Delta$, but all its constraints
+are of type \eqref{eq:transitive:non-parametric} and they can therefore
+all be used in the construction of $Q_i$.
+
+\begin{example}
+Consider the relation
+$$
+% [n] -> { [x, y] -> [1 + x, 1 - n + y] | n >= 2 }
+R = n \to \{\, (x, y) \to (1 + x, 1 - n + y) \mid n \ge 2 \,\}
+.
+$$
+We have
+$$
+\diff R = n \to \{\, (1, 1 - n) \mid n \ge 2 \,\}
+$$
+and so, by treating the parameters in a special way, we obtain
+the following approximation for $R^+$:
+$$
+n \to \{\, (x, y) \to (x', y') \mid n \ge 2 \wedge y' \le 1 - n + y \wedge x' \ge 1 + x \,\}
+.
+$$
+If we consider instead
+$$
+R' = \{\, (n, x, y) \to (n, 1 + x, 1 - n + y) \mid n \ge 2 \,\}
+$$
+then
+$$
+\diff R' = \{\, (0, 1, y) \mid y \le -1 \,\}
+$$
+and we obtain the approximation
+$$
+n \to \{\, (x, y) \to (x', y') \mid n \ge 2 \wedge x' \ge 1 + x \wedge y' \le x + y - x' \,\}
+.
+$$
+If we consider both $\diff R$ and $\diff R'$, then we obtain
+$$
+n \to \{\, (x, y) \to (x', y') \mid n \ge 2 \wedge y' \le 1 - n + y \wedge x' \ge 1 + x \wedge y' \le x + y - x' \,\}
+.
+$$
+Note, however, that this is not the most accurate affine approximation that
+can be obtained.  That would be
+$$
+n \to \{\, (x, y) \to (x', y') \mid y' \le 2 - n + x + y - x' \wedge n \ge 2 \wedge x' \ge 1 + x \,\}
+.
+$$
+\end{example}
+
+\subsection{Checking Exactness}
+
+The approximation $T$ for the transitive closure $R^+$ can be obtained
+by projecting out the parameter $k$ from the approximation $K$
+\eqref{eq:transitive:approx} of the power $R^k$.
+Since $K$ is an overapproximation of $R^k$, $T$ will also be an
+overapproximation of $R^+$.
+To check whether the results are exact, we need to consider two
+cases depending on whether $R$ is {\em cyclic}, where $R$ is defined
+to be cyclic if $R^+$ maps any element to itself, i.e.,
+$R^+ \cap \identity \ne \emptyset$.
+If $R$ is acyclic, then the inductive definition of
+\eqref{eq:transitive:inductive} is equivalent to its completion,
+i.e.,
+$$
+R^+ = R \cup \left(R \circ R^+\right)
+$$
+is a defining property.
+Since $T$ is known to be an overapproximation, we only need to check
+whether
+$$
+T \subseteq R \cup \left(R \circ T\right)
+.
+$$
+This is essentially Theorem~5 of \shortciteN{Kelly1996closure}.
+The only difference is that they only consider lexicographically
+forward relations, a special case of acyclic relations.
+
+If, on the other hand, $R$ is cyclic, then we have to resort
+to checking whether the approximation $K$ of the power is exact.
+Note that $T$ may be exact even if $K$ is not exact, so the check
+is sound, but incomplete.
+To check exactness of the power, we simply need to check
+\eqref{eq:transitive:power}.  Since again $K$ is known
+to be an overapproximation, we only need to check whether
+$$
+\begin{aligned}
+K'|_{y_{d+1} - x_{d+1} = 1} & \subseteq R'
+\\
+K'|_{y_{d+1} - x_{d+1} \ge 2} & \subseteq R' \circ K'|_{y_{d+1} - x_{d+1} \ge 1}
+,
+\end{aligned}
+$$
+where $R' = \{\, \vec x' \to \vec y' \mid \vec x \to \vec y \in R
+\wedge y_{d+1} - x_{d+1} = 1\,\}$, i.e., $R$ extended with path
+lengths equal to 1.
+
+All that remains is to explain how to check the cyclicity of $R$.
+Note that the exactness on the power is always sound, even
+in the acyclic case, so we only need to be careful that we find
+all cyclic cases.  Now, if $R$ is cyclic, i.e.,
+$R^+ \cap \identity \ne \emptyset$, then, since $T$ is
+an overapproximation of $R^+$, also
+$T \cap \identity \ne \emptyset$.  This in turn means
+that $\Delta \, K'$ contains a point whose first $d$ coordinates
+are zero and whose final coordinate is positive.
+In the implementation we currently perform this test on $P'$ instead of $K'$.
+Note that if $R^+$ is acyclic and $T$ is not, then the approximation
+is clearly not exact and the approximation of the power $K$
+will not be exact either.
+
+\subsection{Decomposing $R$ into strongly connected components}
+
+If the input relation $R$ is a union of several basic relations
+that can be partially ordered
+then the accuracy of the approximation may be improved by computing
+an approximation of each strongly connected components separately.
+For example, if $R = R_1 \cup R_2$ and $R_1 \circ R_2 = \emptyset$,
+then we know that any path that passes through $R_2$ cannot later
+pass through $R_1$, i.e.,
+\begin{equation}
+\label{eq:transitive:components}
+R^+ = R_1^+ \cup R_2^+ \cup \left(R_2^+ \circ R_1^+\right)
+.
+\end{equation}
+We can therefore compute (approximations of) transitive closures
+of $R_1$ and $R_2$ separately.
+Note, however, that the condition $R_1 \circ R_2 = \emptyset$
+is actually too strong.
+If $R_1 \circ R_2$ is a subset of $R_2 \circ R_1$
+then we can reorder the segments
+in any path that moves through both $R_1$ and $R_2$ to
+first move through $R_1$ and then through $R_2$.
+
+This idea can be generalized to relations that are unions
+of more than two basic relations by constructing the
+strongly connected components in the graph with as vertices
+the basic relations and an edge between two basic relations
+$R_i$ and $R_j$ if $R_i$ needs to follow $R_j$ in some paths.
+That is, there is an edge from $R_i$ to $R_j$ iff
+\begin{equation}
+\label{eq:transitive:edge}
+R_i \circ R_j
+\not\subseteq
+R_j \circ R_i
+.
+\end{equation}
+The components can be obtained from the graph by applying
+Tarjan's algorithm \shortcite{Tarjan1972}.
+
+In practice, we compute the (extended) powers $K_i'$ of each component
+separately and then compose them as in \eqref{eq:transitive:decompose}.
+Note, however, that in this case the order in which we apply them is
+important and should correspond to a topological ordering of the
+strongly connected components.  Simply applying Tarjan's
+algorithm will produce topologically sorted strongly connected components.
+The graph on which Tarjan's algorithm is applied is constructed on-the-fly.
+That is, whenever the algorithm checks if there is an edge between
+two vertices, we evaluate \eqref{eq:transitive:edge}.
+The exactness check is performed on each component separately.
+If the approximation turns out to be inexact for any of the components,
+then the entire result is marked inexact and the exactness check
+is skipped on the components that still need to be handled.
+
+It should be noted that \eqref{eq:transitive:components}
+is only valid for exact transitive closures.
+If overapproximations are computed in the right hand side, then the result will
+still be an overapproximation of the left hand side, but this result
+may not be transitively closed.  If we only separate components based
+on the condition $R_i \circ R_j = \emptyset$, then there is no problem,
+as this condition will still hold on the computed approximations
+of the transitive closures.  If, however, we have exploited
+\eqref{eq:transitive:edge} during the decomposition and if the
+result turns out not to be exact, then we check whether
+the result is transitively closed.  If not, we recompute
+the transitive closure, skipping the decomposition.
+Note that testing for transitive closedness on the result may
+be fairly expensive, so we may want to make this check
+configurable.
+
+\begin{figure}
+\begin{center}
+\begin{tikzpicture}[x=0.5cm,y=0.5cm,>=stealth,shorten >=1pt]
+\foreach \x in {1,...,10}{
+    \foreach \y in {1,...,10}{
+	\draw[->] (\x,\y) -- (\x,\y+1);
+    }
+}
+\foreach \x in {1,...,20}{
+    \foreach \y in {5,...,15}{
+	\draw[->] (\x,\y) -- (\x+1,\y);
+    }
+}
+\end{tikzpicture}
+\end{center}
+\caption{The relation from \autoref{ex:closure4}}
+\label{f:closure4}
+\end{figure}
+\begin{example}
+\label{ex:closure4}
+Consider the relation in example {\tt closure4} that comes with
+the Omega calculator~\shortcite{Omega_calc}, $R = R_1 \cup R_2$,
+with
+$$
+\begin{aligned}
+R_1 & = \{\, (x,y) \to (x,y+1) \mid 1 \le x,y \le 10 \,\}
+\\
+R_2 & = \{\, (x,y) \to (x+1,y) \mid 1 \le x \le 20 \wedge 5 \le y \le 15 \,\}
+.
+\end{aligned}
+$$
+This relation is shown graphically in \autoref{f:closure4}.
+We have
+$$
+\begin{aligned}
+R_1 \circ R_2 &=
+\{\, (x,y) \to (x+1,y+1) \mid 1 \le x \le 9 \wedge 5 \le y \le 10 \,\}
+\\
+R_2 \circ R_1 &=
+\{\, (x,y) \to (x+1,y+1) \mid 1 \le x \le 10 \wedge 4 \le y \le 10 \,\}
+.
+\end{aligned}
+$$
+Clearly, $R_1 \circ R_2 \subseteq R_2 \circ R_1$ and so
+$$
+\left(
+R_1 \cup R_2
+\right)^+
+=
+\left(R_2^+ \circ R_1^+\right)
+\cup R_1^+
+\cup R_2^+
+.
+$$
+\end{example}
+
+\begin{figure}
+\newcounter{n}
+\newcounter{t1}
+\newcounter{t2}
+\newcounter{t3}
+\newcounter{t4}
+\begin{center}
+\begin{tikzpicture}[>=stealth,shorten >=1pt]
+\setcounter{n}{7}
+\foreach \i in {1,...,\value{n}}{
+    \foreach \j in {1,...,\value{n}}{
+	\setcounter{t1}{2 * \j - 4 - \i + 1}
+	\setcounter{t2}{\value{n} - 3 - \i + 1}
+	\setcounter{t3}{2 * \i - 1 - \j + 1}
+	\setcounter{t4}{\value{n} - \j + 1}
+	\ifnum\value{t1}>0\ifnum\value{t2}>0
+	\ifnum\value{t3}>0\ifnum\value{t4}>0
+	    \draw[thick,->] (\i,\j) to[out=20] (\i+3,\j);
+	\fi\fi\fi\fi
+	\setcounter{t1}{2 * \j - 1 - \i + 1}
+	\setcounter{t2}{\value{n} - \i + 1}
+	\setcounter{t3}{2 * \i - 4 - \j + 1}
+	\setcounter{t4}{\value{n} - 3 - \j + 1}
+	\ifnum\value{t1}>0\ifnum\value{t2}>0
+	\ifnum\value{t3}>0\ifnum\value{t4}>0
+	    \draw[thick,->] (\i,\j) to[in=-20,out=20] (\i,\j+3);
+	\fi\fi\fi\fi
+	\setcounter{t1}{2 * \j - 1 - \i + 1}
+	\setcounter{t2}{\value{n} - 1 - \i + 1}
+	\setcounter{t3}{2 * \i - 1 - \j + 1}
+	\setcounter{t4}{\value{n} - 1 - \j + 1}
+	\ifnum\value{t1}>0\ifnum\value{t2}>0
+	\ifnum\value{t3}>0\ifnum\value{t4}>0
+	    \draw[thick,->] (\i,\j) to (\i+1,\j+1);
+	\fi\fi\fi\fi
+    }
+}
+\end{tikzpicture}
+\end{center}
+\caption{The relation from \autoref{ex:decomposition}}
+\label{f:decomposition}
+\end{figure}
+\begin{example}
+\label{ex:decomposition}
+Consider the relation on the right of \shortciteN[Figure~2]{Beletska2009},
+reproduced in \autoref{f:decomposition}.
+The relation can be described as $R = R_1 \cup R_2 \cup R_3$,
+with
+$$
+\begin{aligned}
+R_1 &= n \mapsto \{\, (i,j) \to (i+3,j) \mid
+i \le 2 j - 4 \wedge
+i \le n - 3 \wedge
+j \le 2 i - 1 \wedge
+j \le n \,\}
+\\
+R_2 &= n \mapsto \{\, (i,j) \to (i,j+3) \mid
+i \le 2 j - 1 \wedge
+i \le n \wedge
+j \le 2 i - 4 \wedge
+j \le n - 3 \,\}
+\\
+R_3 &= n \mapsto \{\, (i,j) \to (i+1,j+1) \mid
+i \le 2 j - 1 \wedge
+i \le n - 1 \wedge
+j \le 2 i - 1 \wedge
+j \le n - 1\,\}
+.
+\end{aligned}
+$$
+The figure shows this relation for $n = 7$.
+Both
+$R_3 \circ R_1 \subseteq R_1 \circ R_3$
+and
+$R_3 \circ R_2 \subseteq R_2 \circ R_3$,
+which the reader can verify using the {\tt iscc} calculator:
+\begin{verbatim}
+R1 := [n] -> { [i,j] -> [i+3,j] : i <= 2 j - 4 and i <= n - 3 and
+                                  j <= 2 i - 1 and j <= n };
+R2 := [n] -> { [i,j] -> [i,j+3] : i <= 2 j - 1 and i <= n and
+                                  j <= 2 i - 4 and j <= n - 3 };
+R3 := [n] -> { [i,j] -> [i+1,j+1] : i <= 2 j - 1 and i <= n - 1 and
+                                    j <= 2 i - 1 and j <= n - 1 };
+(R1 . R3) - (R3 . R1);
+(R2 . R3) - (R3 . R2);
+\end{verbatim}
+$R_3$ can therefore be moved forward in any path.
+For the other two basic relations, we have both
+$R_2 \circ R_1 \not\subseteq R_1 \circ R_2$
+and
+$R_1 \circ R_2 \not\subseteq R_2 \circ R_1$
+and so $R_1$ and $R_2$ form a strongly connected component.
+By computing the power of $R_3$ and $R_1 \cup R_2$ separately
+and composing the results, the power of $R$ can be computed exactly
+using \eqref{eq:transitive:singleton}.
+As explained by \shortciteN{Beletska2009}, applying the same formula
+to $R$ directly, without a decomposition, would result in
+an overapproximation of the power.
+\end{example}
+
+\subsection{Partitioning the domains and ranges of $R$}
+
+The algorithm of \autoref{s:power} assumes that the input relation $R$
+can be treated as a union of translations.
+This is a reasonable assumption if $R$ maps elements of a given
+abstract domain to the same domain.
+However, if $R$ is a union of relations that map between different
+domains, then this assumption no longer holds.
+In particular, when an entire dependence graph is encoded
+in a single relation, as is done by, e.g.,
+\shortciteN[Section~6.1]{Barthou2000MSE}, then it does not make
+sense to look at differences between iterations of different domains.
+Now, arguably, a modified Floyd-Warshall algorithm should
+be applied to the dependence graph, as advocated by
+\shortciteN{Kelly1996closure}, with the transitive closure operation
+only being applied to relations from a given domain to itself.
+However, it is also possible to detect disjoint domains and ranges
+and to apply Floyd-Warshall internally.
+
+\LinesNumbered
+\begin{algorithm}
+\caption{The modified Floyd-Warshall algorithm of
+\protect\shortciteN{Kelly1996closure}}
+\label{a:Floyd}
+\SetKwInput{Input}{Input}
+\SetKwInput{Output}{Output}
+\Input{Relations $R_{pq}$, $0 \le p, q < n$}
+\Output{Updated relations $R_{pq}$ such that each relation
+$R_{pq}$ contains all indirect paths from $p$ to $q$ in the input graph}
+%
+\BlankLine
+\SetAlgoVlined
+\DontPrintSemicolon
+%
+\For{$r \in [0, n-1]$}{
+    $R_{rr} \coloneqq R_{rr}^+$ \nllabel{l:Floyd:closure}\;
+    \For{$p \in [0, n-1]$}{
+	\For{$q \in [0, n-1]$}{
+	    \If{$p \ne r$ or $q \ne r$}{
+		$R_{pq} \coloneqq R_{pq} \cup \left(R_{rq} \circ R_{pr}\right)
+			     \cup \left(R_{rq} \circ R_{rr} \circ R_{pr}\right)$
+	     \nllabel{l:Floyd:update}
+	     }
+	}
+    }
+}
+\end{algorithm}
+
+Let the input relation $R$ be a union of $m$ basic relations $R_i$.
+Let $D_{2i}$ be the domains of $R_i$ and $D_{2i+1}$ the ranges of $R_i$.
+The first step is to group overlapping $D_j$ until a partition is
+obtained.  If the resulting partition consists of a single part,
+then we continue with the algorithm of \autoref{s:power}.
+Otherwise, we apply Floyd-Warshall on the graph with as vertices
+the parts of the partition and as edges the $R_i$ attached to
+the appropriate pairs of vertices.
+In particular, let there be $n$ parts $P_k$ in the partition.
+We construct $n^2$ relations
+$$
+R_{pq} \coloneqq \bigcup_{i \text{ s.t. } \domain R_i \subseteq P_p \wedge
+				 \range R_i \subseteq P_q} R_i
+,
+$$
+apply \autoref{a:Floyd} and return the union of all resulting
+$R_{pq}$ as the transitive closure of $R$.
+Each iteration of the $r$-loop in \autoref{a:Floyd} updates
+all relations $R_{pq}$ to include paths that go from $p$ to $r$,
+possibly stay there for a while, and then go from $r$ to $q$.
+Note that paths that ``stay in $r$'' include all paths that
+pass through earlier vertices since $R_{rr}$ itself has been updated
+accordingly in previous iterations of the outer loop.
+In principle, it would be sufficient to use the $R_{pr}$
+and $R_{rq}$ computed in the previous iteration of the
+$r$-loop in Line~\ref{l:Floyd:update}.
+However, from an implementation perspective, it is easier
+to allow either or both of these to have been updated
+in the same iteration of the $r$-loop.
+This may result in duplicate paths, but these can usually
+be removed by coalescing (\autoref{s:coalescing}) the result of the union
+in Line~\ref{l:Floyd:update}, which should be done in any case.
+The transitive closure in Line~\ref{l:Floyd:closure}
+is performed using a recursive call.  This recursive call
+includes the partitioning step, but the resulting partition will
+usually be a singleton.
+The result of the recursive call will either be exact or an
+overapproximation.  The final result of Floyd-Warshall is therefore
+also exact or an overapproximation.
+
+\begin{figure}
+\begin{center}
+\begin{tikzpicture}[x=1cm,y=1cm,>=stealth,shorten >=3pt]
+\foreach \x/\y in {0/0,1/1,3/2} {
+    \fill (\x,\y) circle (2pt);
+}
+\foreach \x/\y in {0/1,2/2,3/3} {
+    \draw (\x,\y) circle (2pt);
+}
+\draw[->] (0,0) -- (0,1);
+\draw[->] (0,1) -- (1,1);
+\draw[->] (2,2) -- (3,2);
+\draw[->] (3,2) -- (3,3);
+\draw[->,dashed] (2,2) -- (3,3);
+\draw[->,dotted] (0,0) -- (1,1);
+\end{tikzpicture}
+\end{center}
+\caption{The relation (solid arrows) on the right of Figure~1 of
+\protect\shortciteN{Beletska2009} and its transitive closure}
+\label{f:COCOA:1}
+\end{figure}
+\begin{example}
+Consider the relation on the right of Figure~1 of
+\shortciteN{Beletska2009},
+reproduced in \autoref{f:COCOA:1}.
+This relation can be described as
+$$
+\begin{aligned}
+\{\, (x, y) \to (x_2, y_2) \mid {} & (3y = 2x \wedge x_2 = x \wedge 3y_2 = 3 + 2x \wedge x \ge 0 \wedge x \le 3) \vee {} \\
+& (x_2 = 1 + x \wedge y_2 = y \wedge x \ge 0 \wedge 3y \ge 2 + 2x \wedge x \le 2 \wedge 3y \le 3 + 2x) \,\}
+.
+\end{aligned}
+$$
+Note that the domain of the upward relation overlaps with the range
+of the rightward relation and vice versa, but that the domain
+of neither relation overlaps with its own range or the domain of
+the other relation.
+The domains and ranges can therefore be partitioned into two parts,
+$P_0$ and $P_1$, shown as the white and black dots in \autoref{f:COCOA:1},
+respectively.
+Initially, we have
+$$
+\begin{aligned}
+R_{00} & = \emptyset
+\\
+R_{01} & = 
+\{\, (x, y) \to (x+1, y) \mid 
+(x \ge 0 \wedge 3y \ge 2 + 2x \wedge x \le 2 \wedge 3y \le 3 + 2x) \,\}
+\\
+R_{10} & =
+\{\, (x, y) \to (x_2, y_2) \mid (3y = 2x \wedge x_2 = x \wedge 3y_2 = 3 + 2x \wedge x \ge 0 \wedge x \le 3) \,\}
+\\
+R_{11} & = \emptyset
+.
+\end{aligned}
+$$
+In the first iteration, $R_{00}$ remains the same ($\emptyset^+ = \emptyset$).
+$R_{01}$ and $R_{10}$ are therefore also unaffected, but
+$R_{11}$ is updated to include $R_{01} \circ R_{10}$, i.e.,
+the dashed arrow in the figure.
+This new $R_{11}$ is obviously transitively closed, so it is not
+changed in the second iteration and it does not have an effect
+on $R_{01}$ and $R_{10}$.  However, $R_{00}$ is updated to
+include $R_{10} \circ R_{01}$, i.e., the dotted arrow in the figure.
+The transitive closure of the original relation is then equal to
+$R_{00} \cup R_{01} \cup R_{10} \cup R_{11}$.
+\end{example}
+
+\subsection{Incremental Computation}
+\label{s:incremental}
+
+In some cases it is possible and useful to compute the transitive closure
+of union of basic relations incrementally.  In particular,
+if $R$ is a union of $m$ basic maps,
+$$
+R = \bigcup_j R_j
+,
+$$
+then we can pick some $R_i$ and compute the transitive closure of $R$ as
+\begin{equation}
+\label{eq:transitive:incremental}
+R^+ = R_i^+ \cup
+\left(
+\bigcup_{j \ne i}
+R_i^* \circ R_j \circ R_i^*
+\right)^+
+.
+\end{equation}
+For this approach to be successful, it is crucial that each
+of the disjuncts in the argument of the second transitive
+closure in \eqref{eq:transitive:incremental} be representable
+as a single basic relation, i.e., without a union.
+If this condition holds, then by using \eqref{eq:transitive:incremental},
+the number of disjuncts in the argument of the transitive closure
+can be reduced by one.
+Now, $R_i^* = R_i^+ \cup \identity$, but in some cases it is possible
+to relax the constraints of $R_i^+$ to include part of the identity relation,
+say on domain $D$.  We will use the notation
+${\cal C}(R_i,D) = R_i^+ \cup \identity_D$ to represent
+this relaxed version of $R^+$.
+\shortciteN{Kelly1996closure} use the notation $R_i^?$.
+${\cal C}(R_i,D)$ can be computed by allowing $k$ to attain
+the value $0$ in \eqref{eq:transitive:Q} and by using
+$$
+P \cap \left(D \to D\right)
+$$
+instead of \eqref{eq:transitive:approx}.
+Typically, $D$ will be a strict superset of both $\domain R_i$
+and $\range R_i$.  We therefore need to check that domain
+and range of the transitive closure are part of ${\cal C}(R_i,D)$,
+i.e., the part that results from the paths of positive length ($k \ge 1$),
+are equal to the domain and range of $R_i$.
+If not, then the incremental approach cannot be applied for
+the given choice of $R_i$ and $D$.
+
+In order to be able to replace $R^*$ by ${\cal C}(R_i,D)$
+in \eqref{eq:transitive:incremental}, $D$ should be chosen
+to include both $\domain R$ and $\range R$, i.e., such
+that $\identity_D \circ R_j \circ \identity_D = R_j$ for all $j\ne i$.
+\shortciteN{Kelly1996closure} say that they use
+$D = \domain R_i \cup \range R_i$, but presumably they mean that
+they use $D = \domain R \cup \range R$.
+Now, this expression of $D$ contains a union, so it not directly usable.
+\shortciteN{Kelly1996closure} do not explain how they avoid this union.
+Apparently, in their implementation,
+they are using the convex hull of $\domain R \cup \range R$
+or at least an approximation of this convex hull.
+We use the simple hull (\autoref{s:simple hull}) of $\domain R \cup \range R$.
+
+It is also possible to use a domain $D$ that does {\em not\/}
+include $\domain R \cup \range R$, but then we have to
+compose with ${\cal C}(R_i,D)$ more selectively.
+In particular, if we have
+\begin{equation}
+\label{eq:transitive:right}
+\text{for each $j \ne i$ either }
+\domain R_j \subseteq D \text{ or } \domain R_j \cap \range R_i = \emptyset
+\end{equation}
+and, similarly,
+\begin{equation}
+\label{eq:transitive:left}
+\text{for each $j \ne i$ either }
+\range R_j \subseteq D \text{ or } \range R_j \cap \domain R_i = \emptyset
+\end{equation}
+then we can refine \eqref{eq:transitive:incremental} to
+$$
+R_i^+ \cup
+\left(
+\left(
+\bigcup_{\shortstack{$\scriptstyle\domain R_j \subseteq D $\\
+		     $\scriptstyle\range R_j \subseteq D$}}
+{\cal C} \circ R_j \circ {\cal C}
+\right)
+\cup
+\left(
+\bigcup_{\shortstack{$\scriptstyle\domain R_j \cap \range R_i = \emptyset$\\
+		     $\scriptstyle\range R_j \subseteq D$}}
+\!\!\!\!\!
+{\cal C} \circ R_j
+\right)
+\cup
+\left(
+\bigcup_{\shortstack{$\scriptstyle\domain R_j \subseteq D $\\
+		     $\scriptstyle\range R_j \cap \domain R_i = \emptyset$}}
+\!\!\!\!\!
+R_j \circ {\cal C}
+\right)
+\cup
+\left(
+\bigcup_{\shortstack{$\scriptstyle\domain R_j \cap \range R_i = \emptyset$\\
+		     $\scriptstyle\range R_j \cap \domain R_i = \emptyset$}}
+\!\!\!\!\!
+R_j
+\right)
+\right)^+
+.
+$$
+If only property~\eqref{eq:transitive:right} holds,
+we can use
+$$
+R_i^+ \cup
+\left(
+\left(
+R_i^+ \cup \identity
+\right)
+\circ
+\left(
+\left(
+\bigcup_{\shortstack{$\scriptstyle\domain R_j \subseteq D $}}
+R_j \circ {\cal C}
+\right)
+\cup
+\left(
+\bigcup_{\shortstack{$\scriptstyle\domain R_j \cap \range R_i = \emptyset$}}
+\!\!\!\!\!
+R_j
+\right)
+\right)^+
+\right)
+,
+$$
+while if only property~\eqref{eq:transitive:left} holds,
+we can use
+$$
+R_i^+ \cup
+\left(
+\left(
+\left(
+\bigcup_{\shortstack{$\scriptstyle\range R_j \subseteq D $}}
+{\cal C} \circ R_j
+\right)
+\cup
+\left(
+\bigcup_{\shortstack{$\scriptstyle\range R_j \cap \domain R_i = \emptyset$}}
+\!\!\!\!\!
+R_j
+\right)
+\right)^+
+\circ
+\left(
+R_i^+ \cup \identity
+\right)
+\right)
+.
+$$
+
+It should be noted that if we want the result of the incremental
+approach to be transitively closed, then we can only apply it
+if all of the transitive closure operations involved are exact.
+If, say, the second transitive closure in \eqref{eq:transitive:incremental}
+contains extra elements, then the result does not necessarily contain
+the composition of these extra elements with powers of $R_i$.
+
+\subsection{An {\tt Omega}-like implementation}
+
+While the main algorithm of \shortciteN{Kelly1996closure} is
+designed to compute and underapproximation of the transitive closure,
+the authors mention that they could also compute overapproximations.
+In this section, we describe our implementation of an algorithm
+that is based on their ideas.
+Note that the {\tt Omega} library computes underapproximations
+\shortcite[Section 6.4]{Omega_lib}.
+
+The main tool is Equation~(2) of \shortciteN{Kelly1996closure}.
+The input relation $R$ is first overapproximated by a ``d-form'' relation
+$$
+\{\, \vec i \to \vec j \mid \exists \vec \alpha :
+\vec L \le \vec j - \vec i \le \vec U
+\wedge
+(\forall p : j_p - i_p = M_p \alpha_p)
+\,\}
+,
+$$
+where $p$ ranges over the dimensions and $\vec L$, $\vec U$ and
+$\vec M$ are constant integer vectors.  The elements of $\vec U$
+may be $\infty$, meaning that there is no upper bound corresponding
+to that element, and similarly for $\vec L$.
+Such an overapproximation can be obtained by computing strides,
+lower and upper bounds on the difference set $\Delta \, R$.
+The transitive closure of such a ``d-form'' relation is
+\begin{equation}
+\label{eq:omega}
+\{\, \vec i \to \vec j \mid \exists \vec \alpha, k :
+k \ge 1 \wedge
+k \, \vec L \le \vec j - \vec i \le k \, \vec U
+\wedge
+(\forall p : j_p - i_p = M_p \alpha_p)
+\,\}
+.
+\end{equation}
+The domain and range of this transitive closure are then
+intersected with those of the input relation.
+This is a special case of the algorithm in \autoref{s:power}.
+
+In their algorithm for computing lower bounds, the authors
+use the above algorithm as a substep on the disjuncts in the relation.
+At the end, they say
+\begin{quote}
+If an upper bound is required, it can be calculated in a manner
+similar to that of a single conjunct [sic] relation.
+\end{quote}
+Presumably, the authors mean that a ``d-form'' approximation
+of the whole input relation should be used.
+However, the accuracy can be improved by also trying to
+apply the incremental technique from the same paper,
+which is explained in more detail in \autoref{s:incremental}.
+In this case, ${\cal C}(R_i,D)$ can be obtained by
+allowing the value zero for $k$ in \eqref{eq:omega},
+i.e., by computing
+$$
+\{\, \vec i \to \vec j \mid \exists \vec \alpha, k :
+k \ge 0 \wedge
+k \, \vec L \le \vec j - \vec i \le k \, \vec U
+\wedge
+(\forall p : j_p - i_p = M_p \alpha_p)
+\,\}
+.
+$$
+In our implementation we take as $D$ the simple hull
+(\autoref{s:simple hull}) of $\domain R \cup \range R$.
+To determine whether it is safe to use ${\cal C}(R_i,D)$,
+we check the following conditions, as proposed by
+\shortciteN{Kelly1996closure}:
+${\cal C}(R_i,D) - R_i^+$ is not a union and for each $j \ne i$
+the condition
+$$
+\left({\cal C}(R_i,D) - R_i^+\right)
+\circ
+R_j
+\circ
+\left({\cal C}(R_i,D) - R_i^+\right)
+=
+R_j
+$$
+holds.

Added: polly/trunk/lib/External/isl/doc/isl.bib
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/doc/isl.bib?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/doc/isl.bib (added)
+++ polly/trunk/lib/External/isl/doc/isl.bib Wed Feb  4 14:55:43 2015
@@ -0,0 +1,313 @@
+ at inproceedings{Kelly1996closure,
+  author    = {Wayne Kelly and
+               William Pugh and
+               Evan Rosser and
+               Tatiana Shpeisman},
+  title     = {Transitive Closure of Infinite Graphs and Its Applications},
+  pages     = {126-140},
+  editor    = {Chua-Huang Huang and
+               P. Sadayappan and
+               Utpal Banerjee and
+               David Gelernter and
+               Alexandru Nicolau and
+               David A. Padua},
+  booktitle = {Languages and Compilers for Parallel Computing, 8th International
+               Workshop, LCPC'95, Columbus, Ohio, USA, August 10-12, 1995,
+               Proceedings},
+  publisher = {Springer},
+  series    = {Lecture Notes in Computer Science},
+  volume    = {1033},
+  year      = {1996},
+  isbn      = {3-540-60765-X},
+}
+
+ at inproceedings{Beletska2009,
+  author = {Beletska, Anna and Barthou, Denis and Bielecki, Wlodzimierz and Cohen, Albert},
+  title = {Computing the Transitive Closure of a Union of Affine Integer Tuple Relations},
+  booktitle = {COCOA '09: Proceedings of the 3rd International Conference on Combinatorial Optimization and Applications},
+  year = {2009},
+  isbn = {978-3-642-02025-4},
+  pages = {98--109},
+  location = {Huangshan, China},
+  doi = {10.1007/978-3-642-02026-1_9},
+  publisher = {Springer-Verlag},
+  address = {Berlin, Heidelberg},
+}
+
+ at book{Schrijver1986,
+    author  =	"Schrijver, Alexander",
+    title   =	"Theory of Linear and Integer Programming",
+    publisher	=   "John Wiley \& Sons",
+    year    =	1986
+}
+
+ at article{Tarjan1972,
+    author = {Tarjan, Robert},
+    journal = {SIAM Journal on Computing},
+    number = {2},
+    pages = {146--160},
+    publisher = {SIAM},
+    title = {Depth-First Search and Linear Graph Algorithms},
+    volume = {1},
+    year = {1972}
+}
+
+ at TechReport{ Omega_calc,
+    author = "Wayne Kelly and Vadim Maslov and William Pugh and Evan Rosser and Tatiana Shpeisman and Dave Wonnacott",
+    title = "The {Omega} Calculator and Library",
+    month = nov,
+    institution = "University of Maryland",
+    year = 1996
+}
+
+ at TechReport{ Omega_lib,
+    author = "Wayne Kelly and Vadim Maslov and William Pugh and Evan Rosser and Tatiana Shpeisman and Dave Wonnacott",
+    title = "The {Omega} Library",
+    month = nov,
+    institution = "University of Maryland",
+    year = 1996
+}
+
+ at unpublished{Verdoolaege2009isl,
+  author = "Verdoolaege, Sven",
+  title = "An integer set library for program analysis",
+  note = "Advances in the Theory of Integer Linear Optimization and its Extensions,AMS 2009 Spring Western Section Meeting, San Francisco, California, 25-26 April 2009",
+  month = Apr,
+  year = "2009",
+  url = "https://lirias.kuleuven.be/handle/123456789/228373",
+}
+
+ at article{Barthou2000MSE,
+  author = {Barthou, Denis and Cohen, Albert and Collard, Jean-Fran\c{c}ois},
+  title = {Maximal Static Expansion},
+  journal = {Int. J. Parallel Program.},
+  volume = {28},
+  number = {3},
+  year = {2000},
+  issn = {0885-7458},
+  pages = {213--243},
+  doi = {10.1023/A:1007500431910},
+  publisher = {Kluwer Academic Publishers},
+  address = {Norwell, MA, USA},
+}
+
+ at article{ Feautrier88parametric,
+    author = "P. Feautrier",
+    title = "Parametric Integer Programming",
+    journal = "RAIRO Recherche Op\'erationnelle",
+    volume = "22",
+    number = "3",
+    pages = "243--268",
+    year = "1988",
+}
+
+ at Article{ Fea91,
+  author =       {Feautrier, P.},
+  title =        {Dataflow analysis of array and scalar references},
+  journal =      {International Journal of Parallel Programming},
+  year =         {1991},
+  OPTkey =         {},
+  volume =       {20},
+  number =       {1},
+  OPTmonth =     {},
+  pages =        {23--53},
+  OPTnote =      {},
+  OPTannote =    {},
+}
+
+ at INPROCEEDINGS{BouletRe98,
+  AUTHOR = {Pierre Boulet and Xavier Redon},
+  TITLE = {Communication Pre-evaluation in {HPF}},
+  BOOKTITLE = {EUROPAR'98},
+  PAGES = {263--272},
+  YEAR = 1998,
+  VOLUME = 1470,
+  series =	 {Lecture Notes in Computer Science},
+  PUBLISHER = {Springer-Verlag, Berlin},
+  ABSTRACT = {  Parallel computers are difficult to program efficiently.  We believe
+  that a good way to help programmers write efficient programs is to
+  provide them with tools that show them how their programs behave on
+  a parallel computer.  Data distribution is the major performance
+  factor of data-parallel programs and so automatic data layout for
+  HPF programs has been studied by many researchers recently.  The
+  communication volume induced by a data distribution is a good
+  estimator of the efficiency of this data distribution.
+
+  We present here a symbolic method to compute the communication
+  volume generated by a given data distribution during the program
+  writing phase (before compilation). We stay machine-independent to
+  assure portability.  Our goal is to help the programmer understand
+  the data movements its program generates and thus find a good data
+  distribution. Our method is based on parametric polyhedral
+  computations. It can be applied to a large class of regular codes.},
+}
+
+ at INPROCEEDINGS {Verdoolaege2005experiences,
+  AUTHOR = "Verdoolaege, Sven and Beyls, Kristof and Bruynooghe, Maurice and Catthoor, Francky",
+  TITLE = {{E}xperiences with enumeration of integer projections of parametric polytopes},
+  BOOKTITLE = {{P}roceedings of 14th {I}nternational {C}onference on {C}ompiler {C}onstruction, {E}dinburgh, {S}cotland},
+  YEAR = {2005},
+  EDITOR = {Bodik, R.},
+  VOLUME = 3443,
+    pages = "91-105",
+    series = "Lecture Notes in Computer Science",
+    publisher = "Springer-Verlag",
+    address = "Berlin",
+    doi = "10.1007/b107108",
+}
+
+ at article{Detlefs2005simplify,
+ author = {David Detlefs and Greg Nelson and James B. Saxe},
+ title = {Simplify: a theorem prover for program checking},
+ journal = {J. ACM},
+ volume = {52},
+ number = {3},
+ year = {2005},
+ issn = {0004-5411},
+ pages = {365--473},
+ doi = {10.1145/1066100.1066102},
+ publisher = {ACM},
+ address = {New York, NY, USA},
+ }
+
+ at phdthesis{Nelson1980phd,
+ author = {Charles Gregory Nelson},
+ title = {Techniques for program verification},
+ year = {1980},
+ order_no = {AAI8011683},
+ school = {Stanford University},
+ address = {Stanford, CA, USA},
+ }
+
+ at article{Woods2003short,
+    year = 2003,
+    Journal = "J. Amer. Math. Soc.",
+    volume =  16,
+    pages = "957--979",
+    month = apr,
+    title = {{Short rational generating functions for lattice point
+        problems}},
+    author = {Alexander Barvinok and Kevin Woods},
+}
+
+ at misc{barvinok-0.22,
+  author = {Sven Verdoolaege},
+  title = {{\texttt{barvinok}}, version 0.22},
+  howpublished = {Available from \url{http://freshmeat.net/projects/barvinok/}},
+  year = 2006
+}
+
+ at inproceedings{DeLoera2004Three,
+    title = "Three Kinds of Integer Programming Algorithms based on Barvinok's Rational Functions",
+    author = "De Loera, J. A. and D. Haws and R. Hemmecke and P. Huggins and R. Yoshida",
+    booktitle = "Integer Programming and Combinatorial Optimization: 10th International IPCO Conference",
+    year = "2004",
+    month = jan,
+    series = "Lecture Notes in Computer Science",
+    Volume = 3064,
+    Pages = "244-255",
+}
+
+ at TechReport{Feautrier02,
+  author = 	 {P. Feautrier and J. Collard and C. Bastoul},
+  title = 	 {Solving systems of affine (in)equalities},
+  institution =  {PRiSM, Versailles University},
+  year = 	 2002
+}
+
+ at article{ Feautrier92multi,
+    author = "Paul Feautrier",
+    title = "Some Efficient Solutions to the Affine Scheduling Problem. {P}art {II}. Multidimensional Time",
+    journal = "International Journal of Parallel Programming",
+    volume = "21",
+    number = "6",
+    pages = "389--420",
+    year = "1992",
+    month = dec,
+    url = "citeseer.nj.nec.com/article/feautrier92some.html",
+}
+
+ at misc{Bygde2010licentiate,
+   author = {Stefan Bygde},
+   title = {Static {WCET} Analysis based on Abstract Interpretation and Counting of Elements},
+   month = {March},
+   year = {2010},
+   howpublished = {Licentiate thesis},
+   publisher = {M{\"{a}}lardalen University Press},
+   url = {http://www.mrtc.mdh.se/index.php?choice=publications&id=2144},
+}
+
+ at phdthesis{Meister2004PhD,
+	title = {Stating and Manipulating Periodicity in the Polytope Model. Applications to Program Analysis and Optimization},
+	author= {Beno\^it Meister},
+ 	school = {Universit\'e Louis Pasteur},
+	month = Dec,
+	year  = {2004},
+}
+
+ at inproceedings{Meister2008,
+  author = {Beno\^it Meister and Sven Verdoolaege},
+  title = {Polynomial Approximations in the Polytope Model: Bringing the Power
+  of Quasi-Polynomials to the Masses},
+  year = {2008},
+  booktitle = {Digest of the 6th Workshop on Optimization for DSP and Embedded Systems, ODES-6},
+  editor = "Jagadeesh Sankaran and Vander Aa, Tom",
+  month = apr,
+}
+
+ at misc{Galea2009personal,
+    author = "Fran\c{c}ois Galea",
+    title = "personal communication",
+    year = 2009,
+    month = nov,
+}
+
+ at misc{PPL,
+  author = "R. Bagnara and P. M. Hill and E. Zaffanella",
+  title = "The {Parma Polyhedra Library}",
+  howpublished = {\url{http://www.cs.unipr.it/ppl/}},
+}
+
+ at TECHREPORT{Cook1991implementation,
+AUTHOR={William Cook and Thomas Rutherford and Herbert E. Scarf and David F. Shallcross},
+TITLE={An Implementation of the Generalized Basis Reduction Algorithm for Integer Programming},
+YEAR=1991,
+MONTH=Aug,
+INSTITUTION={Cowles Foundation, Yale University},
+TYPE={Cowles Foundation Discussion Papers},
+NOTE={available at \url{http://ideas.repec.org/p/cwl/cwldpp/990.html}},
+NUMBER={990},
+}
+
+ @article{Karr1976affine,
+author={ Michael Karr},
+title={ Affine Relationships Among Variables of a Program },
+journal={Acta Informatica},
+Volume={6},
+pages={133-151},
+year={1976},
+publisher={Springer-Verlag},
+ignore={ },
+}
+
+ at PhdThesis{Verhaegh1995PhD,
+	title = "Multidimensional Periodic Scheduling",
+	author = "Wim F. J. Verhaegh",
+	school = "Technische Universiteit Eindhoven",
+	year = 1995,
+}
+
+ at INPROCEEDINGS{Seghir2006minimizing,
+  AUTHOR = "Rachid Seghir and Vincent Loechner",
+  TITLE = {Memory Optimization by Counting Points in Integer Transformations of Parametric Polytopes},
+  BOOKTITLE = {{P}roceedings of the {I}nternational {C}onference on {C}ompilers, {A}rchitectures, and {S}ynthesis for {E}mbedded Systems, CASES 2006, {S}eoul, {K}orea},
+  month = oct,
+  YEAR = {2006}
+}
+
+ at misc{DeSmet2010personal,
+    author = "De Smet, Sven",
+    title = "personal communication",
+    year = 2010,
+    month = apr,
+}

Added: polly/trunk/lib/External/isl/doc/manual.tex
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/doc/manual.tex?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/doc/manual.tex (added)
+++ polly/trunk/lib/External/isl/doc/manual.tex Wed Feb  4 14:55:43 2015
@@ -0,0 +1,75 @@
+\documentclass{report}
+\usepackage[plainpages=false,pdfpagelabels,breaklinks,pagebackref]{hyperref}
+\usepackage{amsmath}
+\usepackage{amssymb}
+\usepackage{txfonts}
+\usepackage{chicago}
+\usepackage{aliascnt}
+\usepackage{tikz}
+\usepackage{calc}
+\usepackage[ruled]{algorithm2e}
+\usetikzlibrary{matrix,fit,backgrounds,decorations.pathmorphing,positioning}
+\usepackage{listings}
+
+\lstset{basicstyle=\tt,flexiblecolumns=false}
+
+\def\vec#1{\mathchoice{\mbox{\boldmath$\displaystyle\bf#1$}}
+{\mbox{\boldmath$\textstyle\bf#1$}}
+{\mbox{\boldmath$\scriptstyle\bf#1$}}
+{\mbox{\boldmath$\scriptscriptstyle\bf#1$}}}
+
+\providecommand{\fract}[1]{\left\{#1\right\}}
+\providecommand{\floor}[1]{\left\lfloor#1\right\rfloor}
+\providecommand{\ceil}[1]{\left\lceil#1\right\rceil}
+\def\sp#1#2{\langle #1, #2 \rangle}
+\def\spv#1#2{\langle\vec #1,\vec #2\rangle}
+
+\newtheorem{theorem}{Theorem}
+\newaliascnt{example}{theorem}
+\newtheorem{example}[example]{Example}
+\newaliascnt{def}{theorem}
+\newtheorem{definition}[def]{Definition}
+\aliascntresetthe{example}
+\aliascntresetthe{def}
+\numberwithin{theorem}{section}
+\numberwithin{def}{section}
+\numberwithin{example}{section}
+
+\newcommand{\algocflineautorefname}{Algorithm}
+\newcommand{\exampleautorefname}{Example}
+\newcommand{\lstnumberautorefname}{Line}
+\renewcommand{\sectionautorefname}{Section}
+\renewcommand{\subsectionautorefname}{Section}
+
+\def\Z{\mathbb{Z}}
+\def\Q{\mathbb{Q}}
+
+\def\pdom{\mathop{\rm pdom}\nolimits}
+\def\domain{\mathop{\rm dom}\nolimits}
+\def\range{\mathop{\rm ran}\nolimits}
+\def\identity{\mathop{\rm Id}\nolimits}
+\def\diff{\mathop{\Delta}\nolimits}
+
+\providecommand{\floor}[1]{\left\lfloor#1\right\rfloor}
+
+\begin{document}
+
+\title{Integer Set Library: Manual\\
+\small Version: \input{version} }
+\author{Sven Verdoolaege}
+
+\maketitle
+\tableofcontents
+
+\chapter{User Manual}
+
+\input{user}
+
+\chapter{Implementation Details}
+
+\input{implementation}
+
+\bibliography{isl}
+\bibliographystyle{chicago}
+
+\end{document}

Added: polly/trunk/lib/External/isl/doc/mypod2latex
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/doc/mypod2latex?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/doc/mypod2latex (added)
+++ polly/trunk/lib/External/isl/doc/mypod2latex Wed Feb  4 14:55:43 2015
@@ -0,0 +1,14 @@
+#!/usr/bin/perl
+
+use strict;
+use Pod::LaTeX;
+
+my ($in, $out) = @ARGV;
+
+my $parser = new Pod::LaTeX(
+		AddPreamble => 0,
+		AddPostamble => 0,
+		LevelNoNum => 5,
+	     );
+
+$parser->parse_from_file($in, $out);

Propchange: polly/trunk/lib/External/isl/doc/mypod2latex
------------------------------------------------------------------------------
    svn:executable = *

Added: polly/trunk/lib/External/isl/doc/user.pod
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/doc/user.pod?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/doc/user.pod (added)
+++ polly/trunk/lib/External/isl/doc/user.pod Wed Feb  4 14:55:43 2015
@@ -0,0 +1,8039 @@
+=head1 Introduction
+
+C<isl> is a thread-safe C library for manipulating
+sets and relations of integer points bounded by affine constraints.
+The descriptions of the sets and relations may involve
+both parameters and existentially quantified variables.
+All computations are performed in exact integer arithmetic
+using C<GMP> or C<imath>.
+The C<isl> library offers functionality that is similar
+to that offered by the C<Omega> and C<Omega+> libraries,
+but the underlying algorithms are in most cases completely different.
+
+The library is by no means complete and some fairly basic
+functionality is still missing.
+Still, even in its current form, the library has been successfully
+used as a backend polyhedral library for the polyhedral
+scanner C<CLooG> and as part of an equivalence checker of
+static affine programs.
+For bug reports, feature requests and questions,
+visit the discussion group at
+L<http://groups.google.com/group/isl-development>.
+
+=head2 Backward Incompatible Changes
+
+=head3 Changes since isl-0.02
+
+=over
+
+=item * The old printing functions have been deprecated
+and replaced by C<isl_printer> functions, see L<Input and Output>.
+
+=item * Most functions related to dependence analysis have acquired
+an extra C<must> argument.  To obtain the old behavior, this argument
+should be given the value 1.  See L<Dependence Analysis>.
+
+=back
+
+=head3 Changes since isl-0.03
+
+=over
+
+=item * The function C<isl_pw_qpolynomial_fold_add> has been
+renamed to C<isl_pw_qpolynomial_fold_fold>.
+Similarly, C<isl_union_pw_qpolynomial_fold_add> has been
+renamed to C<isl_union_pw_qpolynomial_fold_fold>.
+
+=back
+
+=head3 Changes since isl-0.04
+
+=over
+
+=item * All header files have been renamed from C<isl_header.h>
+to C<isl/header.h>.
+
+=back
+
+=head3 Changes since isl-0.05
+
+=over
+
+=item * The functions C<isl_printer_print_basic_set> and
+C<isl_printer_print_basic_map> no longer print a newline.
+
+=item * The functions C<isl_flow_get_no_source>
+and C<isl_union_map_compute_flow> now return
+the accesses for which no source could be found instead of
+the iterations where those accesses occur.
+
+=item * The functions C<isl_basic_map_identity> and
+C<isl_map_identity> now take a B<map> space as input.  An old call
+C<isl_map_identity(space)> can be rewritten to
+C<isl_map_identity(isl_space_map_from_set(space))>.
+
+=item * The function C<isl_map_power> no longer takes
+a parameter position as input.  Instead, the exponent
+is now expressed as the domain of the resulting relation.
+
+=back
+
+=head3 Changes since isl-0.06
+
+=over
+
+=item * The format of C<isl_printer_print_qpolynomial>'s
+C<ISL_FORMAT_ISL> output has changed.
+Use C<ISL_FORMAT_C> to obtain the old output.
+
+=item * The C<*_fast_*> functions have been renamed to C<*_plain_*>.
+Some of the old names have been kept for backward compatibility,
+but they will be removed in the future.
+
+=back
+
+=head3 Changes since isl-0.07
+
+=over
+
+=item * The function C<isl_pw_aff_max> has been renamed to
+C<isl_pw_aff_union_max>.
+Similarly, the function C<isl_pw_aff_add> has been renamed to
+C<isl_pw_aff_union_add>.
+
+=item * The C<isl_dim> type has been renamed to C<isl_space>
+along with the associated functions.
+Some of the old names have been kept for backward compatibility,
+but they will be removed in the future.
+
+=item * Spaces of maps, sets and parameter domains are now
+treated differently.  The distinction between map spaces and set spaces
+has always been made on a conceptual level, but proper use of such spaces
+was never checked.  Furthermore, up until isl-0.07 there was no way
+of explicitly creating a parameter space.  These can now be created
+directly using C<isl_space_params_alloc> or from other spaces using
+C<isl_space_params>.
+
+=item * The space in which C<isl_aff>, C<isl_pw_aff>, C<isl_qpolynomial>,
+C<isl_pw_qpolynomial>, C<isl_qpolynomial_fold> and C<isl_pw_qpolynomial_fold>
+objects live is now a map space
+instead of a set space.  This means, for example, that the dimensions
+of the domain of an C<isl_aff> are now considered to be of type
+C<isl_dim_in> instead of C<isl_dim_set>.  Extra functions have been
+added to obtain the domain space.  Some of the constructors still
+take a domain space and have therefore been renamed.
+
+=item * The functions C<isl_equality_alloc> and C<isl_inequality_alloc>
+now take an C<isl_local_space> instead of an C<isl_space>.
+An C<isl_local_space> can be created from an C<isl_space>
+using C<isl_local_space_from_space>.
+
+=item * The C<isl_div> type has been removed.  Functions that used
+to return an C<isl_div> now return an C<isl_aff>.
+Note that the space of an C<isl_aff> is that of relation.
+When replacing a call to C<isl_div_get_coefficient> by a call to
+C<isl_aff_get_coefficient> any C<isl_dim_set> argument needs
+to be replaced by C<isl_dim_in>.
+A call to C<isl_aff_from_div> can be replaced by a call
+to C<isl_aff_floor>.
+A call to C<isl_qpolynomial_div(div)> call be replaced by
+the nested call
+
+	isl_qpolynomial_from_aff(isl_aff_floor(div))
+
+The function C<isl_constraint_div> has also been renamed
+to C<isl_constraint_get_div>.
+
+=item * The C<nparam> argument has been removed from
+C<isl_map_read_from_str> and similar functions.
+When reading input in the original PolyLib format,
+the result will have no parameters.
+If parameters are expected, the caller may want to perform
+dimension manipulation on the result.
+
+=back
+
+=head3 Changes since isl-0.09
+
+=over
+
+=item * The C<schedule_split_parallel> option has been replaced
+by the C<schedule_split_scaled> option.
+
+=item * The first argument of C<isl_pw_aff_cond> is now
+an C<isl_pw_aff> instead of an C<isl_set>.
+A call C<isl_pw_aff_cond(a, b, c)> can be replaced by
+
+	isl_pw_aff_cond(isl_set_indicator_function(a), b, c)
+
+=back
+
+=head3 Changes since isl-0.10
+
+=over
+
+=item * The functions C<isl_set_dim_has_lower_bound> and
+C<isl_set_dim_has_upper_bound> have been renamed to
+C<isl_set_dim_has_any_lower_bound> and
+C<isl_set_dim_has_any_upper_bound>.
+The new C<isl_set_dim_has_lower_bound> and
+C<isl_set_dim_has_upper_bound> have slightly different meanings.
+
+=back
+
+=head3 Changes since isl-0.12
+
+=over
+
+=item * C<isl_int> has been replaced by C<isl_val>.
+Some of the old functions are still available in C<isl/deprecated/*.h>
+but they will be removed in the future.
+
+=item * The functions C<isl_pw_qpolynomial_eval>,
+C<isl_union_pw_qpolynomial_eval>, C<isl_pw_qpolynomial_fold_eval>
+and C<isl_union_pw_qpolynomial_fold_eval> have been changed to return
+an C<isl_val> instead of an C<isl_qpolynomial>.
+
+=item * The function C<isl_band_member_is_zero_distance>
+has been removed.  Essentially the same functionality is available
+through C<isl_band_member_is_coincident>, except that is requires
+setting up coincidence constraints.
+The option C<schedule_outer_zero_distance> has accordingly been
+replaced by the option C<schedule_outer_coincidence>.
+
+=item * The function C<isl_vertex_get_expr> has been changed
+to return an C<isl_multi_aff> instead of a rational C<isl_basic_set>.
+The function C<isl_vertex_get_domain> has been changed to return
+a regular basic set, rather than a rational basic set.
+
+=back
+
+=head3 Changes since isl-0.14
+
+=over
+
+=item * Objects of type C<isl_union_pw_multi_aff> can no longer contain
+two or more C<isl_pw_multi_aff> objects with the same domain space.
+
+=item * The function C<isl_union_pw_multi_aff_add> now consistently
+computes the sum on the shared definition domain.
+The function C<isl_union_pw_multi_aff_union_add> has been added
+to compute the sum on the union of definition domains.
+The original behavior of C<isl_union_pw_multi_aff_add> was
+confused and is no longer available.
+
+=back
+
+=head1 License
+
+C<isl> is released under the MIT license.
+
+=over
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+=back
+
+Note that by default C<isl> requires C<GMP>, which is released
+under the GNU Lesser General Public License (LGPL).  This means
+that code linked against C<isl> is also linked against LGPL code.
+
+When configuring with C<--with-int=imath>, C<isl> will link against C<imath>, a
+library for exact integer arithmetic released under the MIT license.
+
+=head1 Installation
+
+The source of C<isl> can be obtained either as a tarball
+or from the git repository.  Both are available from
+L<http://freshmeat.net/projects/isl/>.
+The installation process depends on how you obtained
+the source.
+
+=head2 Installation from the git repository
+
+=over
+
+=item 1 Clone or update the repository
+
+The first time the source is obtained, you need to clone
+the repository.
+
+	git clone git://repo.or.cz/isl.git
+
+To obtain updates, you need to pull in the latest changes
+
+	git pull
+
+=item 2 Optionally get C<imath> submodule
+
+To build C<isl> with C<imath>, you need to obtain the C<imath>
+submodule by running in the git source tree of C<isl>
+
+       git submodule init
+       git submodule update
+
+This will fetch the required version of C<imath> in a subdirectory of C<isl>.
+
+=item 2 Generate C<configure>
+
+	./autogen.sh
+
+=back
+
+After performing the above steps, continue
+with the L<Common installation instructions>.
+
+=head2 Common installation instructions
+
+=over
+
+=item 1 Obtain C<GMP>
+
+By default, building C<isl> requires C<GMP>, including its headers files.
+Your distribution may not provide these header files by default
+and you may need to install a package called C<gmp-devel> or something
+similar.  Alternatively, C<GMP> can be built from
+source, available from L<http://gmplib.org/>.
+C<GMP> is not needed if you build C<isl> with C<imath>.
+
+=item 2 Configure
+
+C<isl> uses the standard C<autoconf> C<configure> script.
+To run it, just type
+
+	./configure
+
+optionally followed by some configure options.
+A complete list of options can be obtained by running
+
+	./configure --help
+
+Below we discuss some of the more common options.
+
+=over
+
+=item C<--prefix>
+
+Installation prefix for C<isl>
+
+=item C<--with-int=[gmp|imath]>
+
+Select the integer library to be used by C<isl>, the default is C<gmp>.
+Note that C<isl> may run significantly slower if you use C<imath>.
+
+=item C<--with-gmp-prefix>
+
+Installation prefix for C<GMP> (architecture-independent files).
+
+=item C<--with-gmp-exec-prefix>
+
+Installation prefix for C<GMP> (architecture-dependent files).
+
+=back
+
+=item 3 Compile
+
+	make
+
+=item 4 Install (optional)
+
+	make install
+
+=back
+
+=head1 Integer Set Library
+
+=head2 Memory Management
+
+Since a high-level operation on isl objects usually involves
+several substeps and since the user is usually not interested in
+the intermediate results, most functions that return a new object
+will also release all the objects passed as arguments.
+If the user still wants to use one or more of these arguments
+after the function call, she should pass along a copy of the
+object rather than the object itself.
+The user is then responsible for making sure that the original
+object gets used somewhere else or is explicitly freed.
+
+The arguments and return values of all documented functions are
+annotated to make clear which arguments are released and which
+arguments are preserved.  In particular, the following annotations
+are used
+
+=over
+
+=item C<__isl_give>
+
+C<__isl_give> means that a new object is returned.
+The user should make sure that the returned pointer is
+used exactly once as a value for an C<__isl_take> argument.
+In between, it can be used as a value for as many
+C<__isl_keep> arguments as the user likes.
+There is one exception, and that is the case where the
+pointer returned is C<NULL>.  Is this case, the user
+is free to use it as an C<__isl_take> argument or not.
+When applied to a C<char *>, the returned pointer needs to be
+freed using C<free>.
+
+=item C<__isl_null>
+
+C<__isl_null> means that a C<NULL> value is returned.
+
+=item C<__isl_take>
+
+C<__isl_take> means that the object the argument points to
+is taken over by the function and may no longer be used
+by the user as an argument to any other function.
+The pointer value must be one returned by a function
+returning an C<__isl_give> pointer.
+If the user passes in a C<NULL> value, then this will
+be treated as an error in the sense that the function will
+not perform its usual operation.  However, it will still
+make sure that all the other C<__isl_take> arguments
+are released.
+
+=item C<__isl_keep>
+
+C<__isl_keep> means that the function will only use the object
+temporarily.  After the function has finished, the user
+can still use it as an argument to other functions.
+A C<NULL> value will be treated in the same way as
+a C<NULL> value for an C<__isl_take> argument.
+This annotation may also be used on return values of
+type C<const char *>, in which case the returned pointer should
+not be freed by the user and is only valid until the object
+from which it was derived is updated or freed.
+
+=back
+
+=head2 Initialization
+
+All manipulations of integer sets and relations occur within
+the context of an C<isl_ctx>.
+A given C<isl_ctx> can only be used within a single thread.
+All arguments of a function are required to have been allocated
+within the same context.
+There are currently no functions available for moving an object
+from one C<isl_ctx> to another C<isl_ctx>.  This means that
+there is currently no way of safely moving an object from one
+thread to another, unless the whole C<isl_ctx> is moved.
+
+An C<isl_ctx> can be allocated using C<isl_ctx_alloc> and
+freed using C<isl_ctx_free>.
+All objects allocated within an C<isl_ctx> should be freed
+before the C<isl_ctx> itself is freed.
+
+	isl_ctx *isl_ctx_alloc();
+	void isl_ctx_free(isl_ctx *ctx);
+
+The user can impose a bound on the number of low-level I<operations>
+that can be performed by an C<isl_ctx>.  This bound can be set and
+retrieved using the following functions.  A bound of zero means that
+no bound is imposed.  The number of operations performed can be
+reset using C<isl_ctx_reset_operations>.  Note that the number
+of low-level operations needed to perform a high-level computation
+may differ significantly across different versions
+of C<isl>, but it should be the same across different platforms
+for the same version of C<isl>.
+
+Warning: This feature is experimental.  C<isl> has good support to abort and
+bail out during the computation, but this feature may exercise error code paths
+that are normally not used that much. Consequently, it is not unlikely that
+hidden bugs will be exposed.
+
+	void isl_ctx_set_max_operations(isl_ctx *ctx,
+		unsigned long max_operations);
+	unsigned long isl_ctx_get_max_operations(isl_ctx *ctx);
+	void isl_ctx_reset_operations(isl_ctx *ctx);
+
+In order to be able to create an object in the same context
+as another object, most object types (described later in
+this document) provide a function to obtain the context
+in which the object was created.
+
+	#include <isl/val.h>
+	isl_ctx *isl_val_get_ctx(__isl_keep isl_val *val);
+	isl_ctx *isl_multi_val_get_ctx(
+		__isl_keep isl_multi_val *mv);
+
+	#include <isl/id.h>
+	isl_ctx *isl_id_get_ctx(__isl_keep isl_id *id);
+
+	#include <isl/local_space.h>
+	isl_ctx *isl_local_space_get_ctx(
+		__isl_keep isl_local_space *ls);
+
+	#include <isl/set.h>
+	isl_ctx *isl_set_list_get_ctx(
+		__isl_keep isl_set_list *list);
+
+	#include <isl/aff.h>
+	isl_ctx *isl_aff_get_ctx(__isl_keep isl_aff *aff);
+	isl_ctx *isl_multi_aff_get_ctx(
+		__isl_keep isl_multi_aff *maff);
+	isl_ctx *isl_pw_aff_get_ctx(__isl_keep isl_pw_aff *pa);
+	isl_ctx *isl_pw_multi_aff_get_ctx(
+		__isl_keep isl_pw_multi_aff *pma);
+	isl_ctx *isl_multi_pw_aff_get_ctx(
+		__isl_keep isl_multi_pw_aff *mpa);
+	isl_ctx *isl_union_pw_multi_aff_get_ctx(
+		__isl_keep isl_union_pw_multi_aff *upma);
+
+	#include <isl/id_to_ast_expr.h>
+	isl_ctx *isl_id_to_ast_expr_get_ctx(
+		__isl_keep id_to_ast_expr *id2expr);
+
+	#include <isl/point.h>
+	isl_ctx *isl_point_get_ctx(__isl_keep isl_point *pnt);
+
+	#include <isl/vec.h>
+	isl_ctx *isl_vec_get_ctx(__isl_keep isl_vec *vec);
+
+	#include <isl/mat.h>
+	isl_ctx *isl_mat_get_ctx(__isl_keep isl_mat *mat);
+
+	#include <isl/vertices.h>
+	isl_ctx *isl_vertices_get_ctx(
+		__isl_keep isl_vertices *vertices);
+	isl_ctx *isl_vertex_get_ctx(__isl_keep isl_vertex *vertex);
+	isl_ctx *isl_cell_get_ctx(__isl_keep isl_cell *cell);
+
+	#include <isl/flow.h>
+	isl_ctx *isl_restriction_get_ctx(
+		__isl_keep isl_restriction *restr);
+
+	#include <isl/schedule.h>
+	isl_ctx *isl_schedule_constraints_get_ctx(
+		__isl_keep isl_schedule_constraints *sc);
+
+	#include <isl/band.h>
+	isl_ctx *isl_band_get_ctx(__isl_keep isl_band *band);
+
+	#include <isl/ast_build.h>
+	isl_ctx *isl_ast_build_get_ctx(
+		__isl_keep isl_ast_build *build);
+
+	#include <isl/ast.h>
+	isl_ctx *isl_ast_expr_get_ctx(
+		__isl_keep isl_ast_expr *expr);
+	isl_ctx *isl_ast_node_get_ctx(
+		__isl_keep isl_ast_node *node);
+
+=head2 Values
+
+An C<isl_val> represents an integer value, a rational value
+or one of three special values, infinity, negative infinity and NaN.
+Some predefined values can be created using the following functions.
+
+	#include <isl/val.h>
+	__isl_give isl_val *isl_val_zero(isl_ctx *ctx);
+	__isl_give isl_val *isl_val_one(isl_ctx *ctx);
+	__isl_give isl_val *isl_val_negone(isl_ctx *ctx);
+	__isl_give isl_val *isl_val_nan(isl_ctx *ctx);
+	__isl_give isl_val *isl_val_infty(isl_ctx *ctx);
+	__isl_give isl_val *isl_val_neginfty(isl_ctx *ctx);
+
+Specific integer values can be created using the following functions.
+
+	#include <isl/val.h>
+	__isl_give isl_val *isl_val_int_from_si(isl_ctx *ctx,
+		long i);
+	__isl_give isl_val *isl_val_int_from_ui(isl_ctx *ctx,
+		unsigned long u);
+	__isl_give isl_val *isl_val_int_from_chunks(isl_ctx *ctx,
+		size_t n, size_t size, const void *chunks);
+
+The function C<isl_val_int_from_chunks> constructs an C<isl_val>
+from the C<n> I<digits>, each consisting of C<size> bytes, stored at C<chunks>.
+The least significant digit is assumed to be stored first.
+
+Value objects can be copied and freed using the following functions.
+
+	#include <isl/val.h>
+	__isl_give isl_val *isl_val_copy(__isl_keep isl_val *v);
+	__isl_null isl_val *isl_val_free(__isl_take isl_val *v);
+
+They can be inspected using the following functions.
+
+	#include <isl/val.h>
+	long isl_val_get_num_si(__isl_keep isl_val *v);
+	long isl_val_get_den_si(__isl_keep isl_val *v);
+	double isl_val_get_d(__isl_keep isl_val *v);
+	size_t isl_val_n_abs_num_chunks(__isl_keep isl_val *v,
+		size_t size);
+	int isl_val_get_abs_num_chunks(__isl_keep isl_val *v,
+		size_t size, void *chunks);
+
+C<isl_val_n_abs_num_chunks> returns the number of I<digits>
+of C<size> bytes needed to store the absolute value of the
+numerator of C<v>.
+C<isl_val_get_abs_num_chunks> stores these digits at C<chunks>,
+which is assumed to have been preallocated by the caller.
+The least significant digit is stored first.
+Note that C<isl_val_get_num_si>, C<isl_val_get_den_si>,
+C<isl_val_get_d>, C<isl_val_n_abs_num_chunks>
+and C<isl_val_get_abs_num_chunks> can only be applied to rational values.
+
+An C<isl_val> can be modified using the following function.
+
+	#include <isl/val.h>
+	__isl_give isl_val *isl_val_set_si(__isl_take isl_val *v,
+		long i);
+
+The following unary properties are defined on C<isl_val>s.
+
+	#include <isl/val.h>
+	int isl_val_sgn(__isl_keep isl_val *v);
+	int isl_val_is_zero(__isl_keep isl_val *v);
+	int isl_val_is_one(__isl_keep isl_val *v);
+	int isl_val_is_negone(__isl_keep isl_val *v);
+	int isl_val_is_nonneg(__isl_keep isl_val *v);
+	int isl_val_is_nonpos(__isl_keep isl_val *v);
+	int isl_val_is_pos(__isl_keep isl_val *v);
+	int isl_val_is_neg(__isl_keep isl_val *v);
+	int isl_val_is_int(__isl_keep isl_val *v);
+	int isl_val_is_rat(__isl_keep isl_val *v);
+	int isl_val_is_nan(__isl_keep isl_val *v);
+	int isl_val_is_infty(__isl_keep isl_val *v);
+	int isl_val_is_neginfty(__isl_keep isl_val *v);
+
+Note that the sign of NaN is undefined.
+
+The following binary properties are defined on pairs of C<isl_val>s.
+
+	#include <isl/val.h>
+	int isl_val_lt(__isl_keep isl_val *v1,
+		__isl_keep isl_val *v2);
+	int isl_val_le(__isl_keep isl_val *v1,
+		__isl_keep isl_val *v2);
+	int isl_val_gt(__isl_keep isl_val *v1,
+		__isl_keep isl_val *v2);
+	int isl_val_ge(__isl_keep isl_val *v1,
+		__isl_keep isl_val *v2);
+	int isl_val_eq(__isl_keep isl_val *v1,
+		__isl_keep isl_val *v2);
+	int isl_val_ne(__isl_keep isl_val *v1,
+		__isl_keep isl_val *v2);
+	int isl_val_abs_eq(__isl_keep isl_val *v1,
+		__isl_keep isl_val *v2);
+
+The function C<isl_val_abs_eq> checks whether its two arguments
+are equal in absolute value.
+
+For integer C<isl_val>s we additionally have the following binary property.
+
+	#include <isl/val.h>
+	int isl_val_is_divisible_by(__isl_keep isl_val *v1,
+		__isl_keep isl_val *v2);
+
+An C<isl_val> can also be compared to an integer using the following
+function.  The result is undefined for NaN.
+
+	#include <isl/val.h>
+	int isl_val_cmp_si(__isl_keep isl_val *v, long i);
+
+The following unary operations are available on C<isl_val>s.
+
+	#include <isl/val.h>
+	__isl_give isl_val *isl_val_abs(__isl_take isl_val *v);
+	__isl_give isl_val *isl_val_neg(__isl_take isl_val *v);
+	__isl_give isl_val *isl_val_floor(__isl_take isl_val *v);
+	__isl_give isl_val *isl_val_ceil(__isl_take isl_val *v);
+	__isl_give isl_val *isl_val_trunc(__isl_take isl_val *v);
+	__isl_give isl_val *isl_val_inv(__isl_take isl_val *v);
+	__isl_give isl_val *isl_val_2exp(__isl_take isl_val *v);
+
+The following binary operations are available on C<isl_val>s.
+
+	#include <isl/val.h>
+	__isl_give isl_val *isl_val_min(__isl_take isl_val *v1,
+		__isl_take isl_val *v2);
+	__isl_give isl_val *isl_val_max(__isl_take isl_val *v1,
+		__isl_take isl_val *v2);
+	__isl_give isl_val *isl_val_add(__isl_take isl_val *v1,
+		__isl_take isl_val *v2);
+	__isl_give isl_val *isl_val_add_ui(__isl_take isl_val *v1,
+		unsigned long v2);
+	__isl_give isl_val *isl_val_sub(__isl_take isl_val *v1,
+		__isl_take isl_val *v2);
+	__isl_give isl_val *isl_val_sub_ui(__isl_take isl_val *v1,
+		unsigned long v2);
+	__isl_give isl_val *isl_val_mul(__isl_take isl_val *v1,
+		__isl_take isl_val *v2);
+	__isl_give isl_val *isl_val_mul_ui(__isl_take isl_val *v1,
+		unsigned long v2);
+	__isl_give isl_val *isl_val_div(__isl_take isl_val *v1,
+		__isl_take isl_val *v2);
+
+On integer values, we additionally have the following operations.
+
+	#include <isl/val.h>
+	__isl_give isl_val *isl_val_2exp(__isl_take isl_val *v);
+	__isl_give isl_val *isl_val_mod(__isl_take isl_val *v1,
+		__isl_take isl_val *v2);
+	__isl_give isl_val *isl_val_gcd(__isl_take isl_val *v1,
+		__isl_take isl_val *v2);
+	__isl_give isl_val *isl_val_gcdext(__isl_take isl_val *v1,
+		__isl_take isl_val *v2, __isl_give isl_val **x,
+		__isl_give isl_val **y);
+
+The function C<isl_val_gcdext> returns the greatest common divisor g
+of C<v1> and C<v2> as well as two integers C<*x> and C<*y> such
+that C<*x> * C<v1> + C<*y> * C<v2> = g.
+
+=head3 GMP specific functions
+
+These functions are only available if C<isl> has been compiled with C<GMP>
+support.
+
+Specific integer and rational values can be created from C<GMP> values using
+the following functions.
+
+	#include <isl/val_gmp.h>
+	__isl_give isl_val *isl_val_int_from_gmp(isl_ctx *ctx,
+		mpz_t z);
+	__isl_give isl_val *isl_val_from_gmp(isl_ctx *ctx,
+		const mpz_t n, const mpz_t d);
+
+The numerator and denominator of a rational value can be extracted as
+C<GMP> values using the following functions.
+
+	#include <isl/val_gmp.h>
+	int isl_val_get_num_gmp(__isl_keep isl_val *v, mpz_t z);
+	int isl_val_get_den_gmp(__isl_keep isl_val *v, mpz_t z);
+
+=head2 Sets and Relations
+
+C<isl> uses six types of objects for representing sets and relations,
+C<isl_basic_set>, C<isl_basic_map>, C<isl_set>, C<isl_map>,
+C<isl_union_set> and C<isl_union_map>.
+C<isl_basic_set> and C<isl_basic_map> represent sets and relations that
+can be described as a conjunction of affine constraints, while
+C<isl_set> and C<isl_map> represent unions of
+C<isl_basic_set>s and C<isl_basic_map>s, respectively.
+However, all C<isl_basic_set>s or C<isl_basic_map>s in the union need
+to live in the same space.  C<isl_union_set>s and C<isl_union_map>s
+represent unions of C<isl_set>s or C<isl_map>s in I<different> spaces,
+where spaces are considered different if they have a different number
+of dimensions and/or different names (see L<"Spaces">).
+The difference between sets and relations (maps) is that sets have
+one set of variables, while relations have two sets of variables,
+input variables and output variables.
+
+=head2 Error Handling
+
+C<isl> supports different ways to react in case a runtime error is triggered.
+Runtime errors arise, e.g., if a function such as C<isl_map_intersect> is called
+with two maps that have incompatible spaces. There are three possible ways
+to react on error: to warn, to continue or to abort.
+
+The default behavior is to warn. In this mode, C<isl> prints a warning, stores
+the last error in the corresponding C<isl_ctx> and the function in which the
+error was triggered returns C<NULL>. An error does not corrupt internal state,
+such that isl can continue to be used. C<isl> also provides functions to
+read the last error and to reset the memory that stores the last error. The
+last error is only stored for information purposes. Its presence does not
+change the behavior of C<isl>. Hence, resetting an error is not required to
+continue to use isl, but only to observe new errors.
+
+	#include <isl/ctx.h>
+	enum isl_error isl_ctx_last_error(isl_ctx *ctx);
+	void isl_ctx_reset_error(isl_ctx *ctx);
+
+Another option is to continue on error. This is similar to warn on error mode,
+except that C<isl> does not print any warning. This allows a program to
+implement its own error reporting.
+
+The last option is to directly abort the execution of the program from within
+the isl library. This makes it obviously impossible to recover from an error,
+but it allows to directly spot the error location. By aborting on error,
+debuggers break at the location the error occurred and can provide a stack
+trace. Other tools that automatically provide stack traces on abort or that do
+not want to continue execution after an error was triggered may also prefer to
+abort on error.
+
+The on error behavior of isl can be specified by calling
+C<isl_options_set_on_error> or by setting the command line option
+C<--isl-on-error>. Valid arguments for the function call are
+C<ISL_ON_ERROR_WARN>, C<ISL_ON_ERROR_CONTINUE> and C<ISL_ON_ERROR_ABORT>. The
+choices for the command line option are C<warn>, C<continue> and C<abort>.
+It is also possible to query the current error mode.
+
+	#include <isl/options.h>
+	int isl_options_set_on_error(isl_ctx *ctx, int val);
+	int isl_options_get_on_error(isl_ctx *ctx);
+
+=head2 Identifiers
+
+Identifiers are used to identify both individual dimensions
+and tuples of dimensions.  They consist of an optional name and an optional
+user pointer.  The name and the user pointer cannot both be C<NULL>, however.
+Identifiers with the same name but different pointer values
+are considered to be distinct.
+Similarly, identifiers with different names but the same pointer value
+are also considered to be distinct.
+Equal identifiers are represented using the same object.
+Pairs of identifiers can therefore be tested for equality using the
+C<==> operator.
+Identifiers can be constructed, copied, freed, inspected and printed
+using the following functions.
+
+	#include <isl/id.h>
+	__isl_give isl_id *isl_id_alloc(isl_ctx *ctx,
+		__isl_keep const char *name, void *user);
+	__isl_give isl_id *isl_id_set_free_user(
+		__isl_take isl_id *id,
+		__isl_give void (*free_user)(void *user));
+	__isl_give isl_id *isl_id_copy(isl_id *id);
+	__isl_null isl_id *isl_id_free(__isl_take isl_id *id);
+
+	void *isl_id_get_user(__isl_keep isl_id *id);
+	__isl_keep const char *isl_id_get_name(__isl_keep isl_id *id);
+
+	__isl_give isl_printer *isl_printer_print_id(
+		__isl_take isl_printer *p, __isl_keep isl_id *id);
+
+The callback set by C<isl_id_set_free_user> is called on the user
+pointer when the last reference to the C<isl_id> is freed.
+Note that C<isl_id_get_name> returns a pointer to some internal
+data structure, so the result can only be used while the
+corresponding C<isl_id> is alive.
+
+=head2 Spaces
+
+Whenever a new set, relation or similar object is created from scratch,
+the space in which it lives needs to be specified using an C<isl_space>.
+Each space involves zero or more parameters and zero, one or two
+tuples of set or input/output dimensions.  The parameters and dimensions
+are identified by an C<isl_dim_type> and a position.
+The type C<isl_dim_param> refers to parameters,
+the type C<isl_dim_set> refers to set dimensions (for spaces
+with a single tuple of dimensions) and the types C<isl_dim_in>
+and C<isl_dim_out> refer to input and output dimensions
+(for spaces with two tuples of dimensions).
+Local spaces (see L</"Local Spaces">) also contain dimensions
+of type C<isl_dim_div>.
+Note that parameters are only identified by their position within
+a given object.  Across different objects, parameters are (usually)
+identified by their names or identifiers.  Only unnamed parameters
+are identified by their positions across objects.  The use of unnamed
+parameters is discouraged.
+
+	#include <isl/space.h>
+	__isl_give isl_space *isl_space_alloc(isl_ctx *ctx,
+		unsigned nparam, unsigned n_in, unsigned n_out);
+	__isl_give isl_space *isl_space_params_alloc(isl_ctx *ctx,
+		unsigned nparam);
+	__isl_give isl_space *isl_space_set_alloc(isl_ctx *ctx,
+		unsigned nparam, unsigned dim);
+	__isl_give isl_space *isl_space_copy(__isl_keep isl_space *space);
+	__isl_null isl_space *isl_space_free(__isl_take isl_space *space);
+
+The space used for creating a parameter domain
+needs to be created using C<isl_space_params_alloc>.
+For other sets, the space
+needs to be created using C<isl_space_set_alloc>, while
+for a relation, the space
+needs to be created using C<isl_space_alloc>.
+
+To check whether a given space is that of a set or a map
+or whether it is a parameter space, use these functions:
+
+	#include <isl/space.h>
+	int isl_space_is_params(__isl_keep isl_space *space);
+	int isl_space_is_set(__isl_keep isl_space *space);
+	int isl_space_is_map(__isl_keep isl_space *space);
+
+Spaces can be compared using the following functions:
+
+	#include <isl/space.h>
+	int isl_space_is_equal(__isl_keep isl_space *space1,
+		__isl_keep isl_space *space2);
+	int isl_space_is_domain(__isl_keep isl_space *space1,
+		__isl_keep isl_space *space2);
+	int isl_space_is_range(__isl_keep isl_space *space1,
+		__isl_keep isl_space *space2);
+	int isl_space_tuple_is_equal(
+		__isl_keep isl_space *space1,
+		enum isl_dim_type type1,
+		__isl_keep isl_space *space2,
+		enum isl_dim_type type2);
+
+C<isl_space_is_domain> checks whether the first argument is equal
+to the domain of the second argument.  This requires in particular that
+the first argument is a set space and that the second argument
+is a map space.  C<isl_space_tuple_is_equal> checks whether the given
+tuples (C<isl_dim_in>, C<isl_dim_out> or C<isl_dim_set>) of the given
+spaces are the same.  That is, it checks if they have the same
+identifier (if any), the same dimension and the same internal structure
+(if any).
+
+It is often useful to create objects that live in the
+same space as some other object.  This can be accomplished
+by creating the new objects
+(see L</"Creating New Sets and Relations"> or
+L</"Functions">) based on the space
+of the original object.
+
+	#include <isl/set.h>
+	__isl_give isl_space *isl_basic_set_get_space(
+		__isl_keep isl_basic_set *bset);
+	__isl_give isl_space *isl_set_get_space(__isl_keep isl_set *set);
+
+	#include <isl/union_set.h>
+	__isl_give isl_space *isl_union_set_get_space(
+		__isl_keep isl_union_set *uset);
+
+	#include <isl/map.h>
+	__isl_give isl_space *isl_basic_map_get_space(
+		__isl_keep isl_basic_map *bmap);
+	__isl_give isl_space *isl_map_get_space(__isl_keep isl_map *map);
+
+	#include <isl/union_map.h>
+	__isl_give isl_space *isl_union_map_get_space(
+		__isl_keep isl_union_map *umap);
+
+	#include <isl/constraint.h>
+	__isl_give isl_space *isl_constraint_get_space(
+		__isl_keep isl_constraint *constraint);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_space *isl_qpolynomial_get_domain_space(
+		__isl_keep isl_qpolynomial *qp);
+	__isl_give isl_space *isl_qpolynomial_get_space(
+		__isl_keep isl_qpolynomial *qp);
+	__isl_give isl_space *isl_qpolynomial_fold_get_space(
+		__isl_keep isl_qpolynomial_fold *fold);
+	__isl_give isl_space *isl_pw_qpolynomial_get_domain_space(
+		__isl_keep isl_pw_qpolynomial *pwqp);
+	__isl_give isl_space *isl_pw_qpolynomial_get_space(
+		__isl_keep isl_pw_qpolynomial *pwqp);
+	__isl_give isl_space *isl_pw_qpolynomial_fold_get_domain_space(
+		__isl_keep isl_pw_qpolynomial_fold *pwf);
+	__isl_give isl_space *isl_pw_qpolynomial_fold_get_space(
+		__isl_keep isl_pw_qpolynomial_fold *pwf);
+	__isl_give isl_space *isl_union_pw_qpolynomial_get_space(
+		__isl_keep isl_union_pw_qpolynomial *upwqp);
+	__isl_give isl_space *isl_union_pw_qpolynomial_fold_get_space(
+		__isl_keep isl_union_pw_qpolynomial_fold *upwf);
+
+	#include <isl/val.h>
+	__isl_give isl_space *isl_multi_val_get_space(
+		__isl_keep isl_multi_val *mv);
+
+	#include <isl/aff.h>
+	__isl_give isl_space *isl_aff_get_domain_space(
+		__isl_keep isl_aff *aff);
+	__isl_give isl_space *isl_aff_get_space(
+		__isl_keep isl_aff *aff);
+	__isl_give isl_space *isl_pw_aff_get_domain_space(
+		__isl_keep isl_pw_aff *pwaff);
+	__isl_give isl_space *isl_pw_aff_get_space(
+		__isl_keep isl_pw_aff *pwaff);
+	__isl_give isl_space *isl_multi_aff_get_domain_space(
+		__isl_keep isl_multi_aff *maff);
+	__isl_give isl_space *isl_multi_aff_get_space(
+		__isl_keep isl_multi_aff *maff);
+	__isl_give isl_space *isl_pw_multi_aff_get_domain_space(
+		__isl_keep isl_pw_multi_aff *pma);
+	__isl_give isl_space *isl_pw_multi_aff_get_space(
+		__isl_keep isl_pw_multi_aff *pma);
+	__isl_give isl_space *isl_union_pw_multi_aff_get_space(
+		__isl_keep isl_union_pw_multi_aff *upma);
+	__isl_give isl_space *isl_multi_pw_aff_get_domain_space(
+		__isl_keep isl_multi_pw_aff *mpa);
+	__isl_give isl_space *isl_multi_pw_aff_get_space(
+		__isl_keep isl_multi_pw_aff *mpa);
+
+	#include <isl/point.h>
+	__isl_give isl_space *isl_point_get_space(
+		__isl_keep isl_point *pnt);
+
+The number of dimensions of a given type of space
+may be read off from a space or an object that lives
+in a space using the following functions.
+In case of C<isl_space_dim>, type may be
+C<isl_dim_param>, C<isl_dim_in> (only for relations),
+C<isl_dim_out> (only for relations), C<isl_dim_set>
+(only for sets) or C<isl_dim_all>.
+
+	#include <isl/space.h>
+	unsigned isl_space_dim(__isl_keep isl_space *space,
+		enum isl_dim_type type);
+
+	#include <isl/local_space.h>
+	int isl_local_space_dim(__isl_keep isl_local_space *ls,
+		enum isl_dim_type type);
+
+	#include <isl/set.h>
+	unsigned isl_basic_set_dim(__isl_keep isl_basic_set *bset,
+		enum isl_dim_type type);
+	unsigned isl_set_dim(__isl_keep isl_set *set,
+		enum isl_dim_type type);
+
+	#include <isl/union_set.h>
+	unsigned isl_union_set_dim(__isl_keep isl_union_set *uset,
+		enum isl_dim_type type);
+
+	#include <isl/map.h>
+	unsigned isl_basic_map_dim(__isl_keep isl_basic_map *bmap,
+		enum isl_dim_type type);
+	unsigned isl_map_dim(__isl_keep isl_map *map,
+		enum isl_dim_type type);
+
+	#include <isl/union_map.h>
+	unsigned isl_union_map_dim(__isl_keep isl_union_map *umap,
+		enum isl_dim_type type);
+
+	#include <isl/val.h>
+	unsigned isl_multi_val_dim(__isl_keep isl_multi_val *mv,
+		enum isl_dim_type type);
+
+	#include <isl/aff.h>
+	int isl_aff_dim(__isl_keep isl_aff *aff,
+		enum isl_dim_type type);
+	unsigned isl_multi_aff_dim(__isl_keep isl_multi_aff *maff,
+		enum isl_dim_type type);
+	unsigned isl_pw_aff_dim(__isl_keep isl_pw_aff *pwaff,
+		enum isl_dim_type type);
+	unsigned isl_pw_multi_aff_dim(
+		__isl_keep isl_pw_multi_aff *pma,
+		enum isl_dim_type type);
+	unsigned isl_multi_pw_aff_dim(
+		__isl_keep isl_multi_pw_aff *mpa,
+		enum isl_dim_type type);
+	unsigned isl_union_pw_multi_aff_dim(
+		__isl_keep isl_union_pw_multi_aff *upma,
+		enum isl_dim_type type);
+
+	#include <isl/polynomial.h>
+	unsigned isl_union_pw_qpolynomial_dim(
+		__isl_keep isl_union_pw_qpolynomial *upwqp,
+		enum isl_dim_type type);
+	unsigned isl_union_pw_qpolynomial_fold_dim(
+		__isl_keep isl_union_pw_qpolynomial_fold *upwf,
+		enum isl_dim_type type);
+
+Note that an C<isl_union_set>, an C<isl_union_map>,
+an C<isl_union_pw_multi_aff>,
+an C<isl_union_pw_qpolynomial> and
+an C<isl_union_pw_qpolynomial_fold>
+only have parameters.
+
+The identifiers or names of the individual dimensions of spaces
+may be set or read off using the following functions on spaces
+or objects that live in spaces.
+These functions are mostly useful to obtain the identifiers, positions
+or names of the parameters.  Identifiers of individual dimensions are
+essentially only useful for printing.  They are ignored by all other
+operations and may not be preserved across those operations.
+
+	#include <isl/space.h>
+	__isl_give isl_space *isl_space_set_dim_id(
+		__isl_take isl_space *space,
+		enum isl_dim_type type, unsigned pos,
+		__isl_take isl_id *id);
+	int isl_space_has_dim_id(__isl_keep isl_space *space,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_id *isl_space_get_dim_id(
+		__isl_keep isl_space *space,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_space *isl_space_set_dim_name(
+		__isl_take isl_space *space,
+		 enum isl_dim_type type, unsigned pos,
+		 __isl_keep const char *name);
+	int isl_space_has_dim_name(__isl_keep isl_space *space,
+		enum isl_dim_type type, unsigned pos);
+	__isl_keep const char *isl_space_get_dim_name(
+		__isl_keep isl_space *space,
+		enum isl_dim_type type, unsigned pos);
+
+	#include <isl/local_space.h>
+	__isl_give isl_local_space *isl_local_space_set_dim_id(
+		__isl_take isl_local_space *ls,
+		enum isl_dim_type type, unsigned pos,
+		__isl_take isl_id *id);
+	int isl_local_space_has_dim_id(
+		__isl_keep isl_local_space *ls,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_id *isl_local_space_get_dim_id(
+		__isl_keep isl_local_space *ls,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_local_space *isl_local_space_set_dim_name(
+		__isl_take isl_local_space *ls,
+		enum isl_dim_type type, unsigned pos, const char *s);
+	int isl_local_space_has_dim_name(
+		__isl_keep isl_local_space *ls,
+		enum isl_dim_type type, unsigned pos)
+	const char *isl_local_space_get_dim_name(
+		__isl_keep isl_local_space *ls,
+		enum isl_dim_type type, unsigned pos);
+
+	#include <isl/constraint.h>
+	const char *isl_constraint_get_dim_name(
+		__isl_keep isl_constraint *constraint,
+		enum isl_dim_type type, unsigned pos);
+
+	#include <isl/set.h>
+	__isl_give isl_id *isl_basic_set_get_dim_id(
+		__isl_keep isl_basic_set *bset,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_set *isl_set_set_dim_id(
+		__isl_take isl_set *set, enum isl_dim_type type,
+		unsigned pos, __isl_take isl_id *id);
+	int isl_set_has_dim_id(__isl_keep isl_set *set,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_id *isl_set_get_dim_id(
+		__isl_keep isl_set *set, enum isl_dim_type type,
+		unsigned pos);
+	const char *isl_basic_set_get_dim_name(
+		__isl_keep isl_basic_set *bset,
+		enum isl_dim_type type, unsigned pos);
+	int isl_set_has_dim_name(__isl_keep isl_set *set,
+		enum isl_dim_type type, unsigned pos);
+	const char *isl_set_get_dim_name(
+		__isl_keep isl_set *set,
+		enum isl_dim_type type, unsigned pos);
+
+	#include <isl/map.h>
+	__isl_give isl_map *isl_map_set_dim_id(
+		__isl_take isl_map *map, enum isl_dim_type type,
+		unsigned pos, __isl_take isl_id *id);
+	int isl_basic_map_has_dim_id(
+		__isl_keep isl_basic_map *bmap,
+		enum isl_dim_type type, unsigned pos);
+	int isl_map_has_dim_id(__isl_keep isl_map *map,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_id *isl_map_get_dim_id(
+		__isl_keep isl_map *map, enum isl_dim_type type,
+		unsigned pos);
+	__isl_give isl_id *isl_union_map_get_dim_id(
+		__isl_keep isl_union_map *umap,
+		enum isl_dim_type type, unsigned pos);
+	const char *isl_basic_map_get_dim_name(
+		__isl_keep isl_basic_map *bmap,
+		enum isl_dim_type type, unsigned pos);
+	int isl_map_has_dim_name(__isl_keep isl_map *map,
+		enum isl_dim_type type, unsigned pos);
+	const char *isl_map_get_dim_name(
+		__isl_keep isl_map *map,
+		enum isl_dim_type type, unsigned pos);
+
+	#include <isl/val.h>
+	__isl_give isl_multi_val *isl_multi_val_set_dim_id(
+		__isl_take isl_multi_val *mv,
+		enum isl_dim_type type, unsigned pos,
+		__isl_take isl_id *id);
+	__isl_give isl_id *isl_multi_val_get_dim_id(
+		__isl_keep isl_multi_val *mv,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_multi_val *isl_multi_val_set_dim_name(
+		__isl_take isl_multi_val *mv,
+		enum isl_dim_type type, unsigned pos, const char *s);
+
+	#include <isl/aff.h>
+	__isl_give isl_aff *isl_aff_set_dim_id(
+		__isl_take isl_aff *aff, enum isl_dim_type type,
+		unsigned pos, __isl_take isl_id *id);
+	__isl_give isl_multi_aff *isl_multi_aff_set_dim_id(
+		__isl_take isl_multi_aff *maff,
+		enum isl_dim_type type, unsigned pos,
+		__isl_take isl_id *id);
+	__isl_give isl_pw_aff *isl_pw_aff_set_dim_id(
+		__isl_take isl_pw_aff *pma,
+		enum isl_dim_type type, unsigned pos,
+		__isl_take isl_id *id);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_set_dim_id(
+		__isl_take isl_multi_pw_aff *mpa,
+		enum isl_dim_type type, unsigned pos,
+		__isl_take isl_id *id);
+	__isl_give isl_id *isl_multi_aff_get_dim_id(
+		__isl_keep isl_multi_aff *ma,
+		enum isl_dim_type type, unsigned pos);
+	int isl_pw_aff_has_dim_id(__isl_keep isl_pw_aff *pa,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_id *isl_pw_aff_get_dim_id(
+		__isl_keep isl_pw_aff *pa,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_id *isl_pw_multi_aff_get_dim_id(
+		__isl_keep isl_pw_multi_aff *pma,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_id *isl_multi_pw_aff_get_dim_id(
+		__isl_keep isl_multi_pw_aff *mpa,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_aff *isl_aff_set_dim_name(
+		__isl_take isl_aff *aff, enum isl_dim_type type,
+		unsigned pos, const char *s);
+	__isl_give isl_multi_aff *isl_multi_aff_set_dim_name(
+		__isl_take isl_multi_aff *maff,
+		enum isl_dim_type type, unsigned pos, const char *s);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_set_dim_name(
+		__isl_take isl_multi_pw_aff *mpa,
+		enum isl_dim_type type, unsigned pos, const char *s);
+	const char *isl_aff_get_dim_name(__isl_keep isl_aff *aff,
+		enum isl_dim_type type, unsigned pos);
+	const char *isl_pw_aff_get_dim_name(
+		__isl_keep isl_pw_aff *pa,
+		enum isl_dim_type type, unsigned pos);
+	const char *isl_pw_multi_aff_get_dim_name(
+		__isl_keep isl_pw_multi_aff *pma,
+		enum isl_dim_type type, unsigned pos);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_qpolynomial *isl_qpolynomial_set_dim_name(
+		__isl_take isl_qpolynomial *qp,
+		enum isl_dim_type type, unsigned pos,
+		const char *s);
+	__isl_give isl_pw_qpolynomial *
+	isl_pw_qpolynomial_set_dim_name(
+		__isl_take isl_pw_qpolynomial *pwqp,
+		enum isl_dim_type type, unsigned pos,
+		const char *s);
+	__isl_give isl_pw_qpolynomial_fold *
+	isl_pw_qpolynomial_fold_set_dim_name(
+		__isl_take isl_pw_qpolynomial_fold *pwf,
+		enum isl_dim_type type, unsigned pos,
+		const char *s);
+
+Note that C<isl_space_get_name> returns a pointer to some internal
+data structure, so the result can only be used while the
+corresponding C<isl_space> is alive.
+Also note that every function that operates on two sets or relations
+requires that both arguments have the same parameters.  This also
+means that if one of the arguments has named parameters, then the
+other needs to have named parameters too and the names need to match.
+Pairs of C<isl_set>, C<isl_map>, C<isl_union_set> and/or C<isl_union_map>
+arguments may have different parameters (as long as they are named),
+in which case the result will have as parameters the union of the parameters of
+the arguments.
+
+Given the identifier or name of a dimension (typically a parameter),
+its position can be obtained from the following functions.
+
+	#include <isl/space.h>
+	int isl_space_find_dim_by_id(__isl_keep isl_space *space,
+		enum isl_dim_type type, __isl_keep isl_id *id);
+	int isl_space_find_dim_by_name(__isl_keep isl_space *space,
+		enum isl_dim_type type, const char *name);
+
+	#include <isl/local_space.h>
+	int isl_local_space_find_dim_by_name(
+		__isl_keep isl_local_space *ls,
+		enum isl_dim_type type, const char *name);
+
+	#include <isl/val.h>
+	int isl_multi_val_find_dim_by_id(
+		__isl_keep isl_multi_val *mv,
+		enum isl_dim_type type, __isl_keep isl_id *id);
+	int isl_multi_val_find_dim_by_name(
+		__isl_keep isl_multi_val *mv,
+		enum isl_dim_type type, const char *name);
+
+	#include <isl/set.h>
+	int isl_set_find_dim_by_id(__isl_keep isl_set *set,
+		enum isl_dim_type type, __isl_keep isl_id *id);
+	int isl_set_find_dim_by_name(__isl_keep isl_set *set,
+		enum isl_dim_type type, const char *name);
+
+	#include <isl/map.h>
+	int isl_map_find_dim_by_id(__isl_keep isl_map *map,
+		enum isl_dim_type type, __isl_keep isl_id *id);
+	int isl_basic_map_find_dim_by_name(
+		__isl_keep isl_basic_map *bmap,
+		enum isl_dim_type type, const char *name);
+	int isl_map_find_dim_by_name(__isl_keep isl_map *map,
+		enum isl_dim_type type, const char *name);
+	int isl_union_map_find_dim_by_name(
+		__isl_keep isl_union_map *umap,
+		enum isl_dim_type type, const char *name);
+
+	#include <isl/aff.h>
+	int isl_multi_aff_find_dim_by_id(
+		__isl_keep isl_multi_aff *ma,
+		enum isl_dim_type type, __isl_keep isl_id *id);
+	int isl_multi_pw_aff_find_dim_by_id(
+		__isl_keep isl_multi_pw_aff *mpa,
+		enum isl_dim_type type, __isl_keep isl_id *id);
+	int isl_aff_find_dim_by_name(__isl_keep isl_aff *aff,
+		enum isl_dim_type type, const char *name);
+	int isl_multi_aff_find_dim_by_name(
+		__isl_keep isl_multi_aff *ma,
+		enum isl_dim_type type, const char *name);
+	int isl_pw_aff_find_dim_by_name(__isl_keep isl_pw_aff *pa,
+		enum isl_dim_type type, const char *name);
+	int isl_multi_pw_aff_find_dim_by_name(
+		__isl_keep isl_multi_pw_aff *mpa,
+		enum isl_dim_type type, const char *name);
+	int isl_pw_multi_aff_find_dim_by_name(
+		__isl_keep isl_pw_multi_aff *pma,
+		enum isl_dim_type type, const char *name);
+	int isl_union_pw_multi_aff_find_dim_by_name(
+		__isl_keep isl_union_pw_multi_aff *upma,
+		enum isl_dim_type type, const char *name);
+
+	#include <isl/polynomial.h>
+	int isl_pw_qpolynomial_find_dim_by_name(
+		__isl_keep isl_pw_qpolynomial *pwqp,
+		enum isl_dim_type type, const char *name);
+	int isl_pw_qpolynomial_fold_find_dim_by_name(
+		__isl_keep isl_pw_qpolynomial_fold *pwf,
+		enum isl_dim_type type, const char *name);
+	int isl_union_pw_qpolynomial_find_dim_by_name(
+		__isl_keep isl_union_pw_qpolynomial *upwqp,
+		enum isl_dim_type type, const char *name);
+	int isl_union_pw_qpolynomial_fold_find_dim_by_name(
+		__isl_keep isl_union_pw_qpolynomial_fold *upwf,
+		enum isl_dim_type type, const char *name);
+
+The identifiers or names of entire spaces may be set or read off
+using the following functions.
+
+	#include <isl/space.h>
+	__isl_give isl_space *isl_space_set_tuple_id(
+		__isl_take isl_space *space,
+		enum isl_dim_type type, __isl_take isl_id *id);
+	__isl_give isl_space *isl_space_reset_tuple_id(
+		__isl_take isl_space *space, enum isl_dim_type type);
+	int isl_space_has_tuple_id(__isl_keep isl_space *space,
+		enum isl_dim_type type);
+	__isl_give isl_id *isl_space_get_tuple_id(
+		__isl_keep isl_space *space, enum isl_dim_type type);
+	__isl_give isl_space *isl_space_set_tuple_name(
+		__isl_take isl_space *space,
+		enum isl_dim_type type, const char *s);
+	int isl_space_has_tuple_name(__isl_keep isl_space *space,
+		enum isl_dim_type type);
+	const char *isl_space_get_tuple_name(__isl_keep isl_space *space,
+		enum isl_dim_type type);
+
+	#include <isl/local_space.h>
+	__isl_give isl_local_space *isl_local_space_set_tuple_id(
+		__isl_take isl_local_space *ls,
+		enum isl_dim_type type, __isl_take isl_id *id);
+
+	#include <isl/set.h>
+	__isl_give isl_basic_set *isl_basic_set_set_tuple_id(
+		__isl_take isl_basic_set *bset,
+		__isl_take isl_id *id);
+	__isl_give isl_set *isl_set_set_tuple_id(
+		__isl_take isl_set *set, __isl_take isl_id *id);
+	__isl_give isl_set *isl_set_reset_tuple_id(
+		__isl_take isl_set *set);
+	int isl_set_has_tuple_id(__isl_keep isl_set *set);
+	__isl_give isl_id *isl_set_get_tuple_id(
+		__isl_keep isl_set *set);
+	__isl_give isl_basic_set *isl_basic_set_set_tuple_name(
+		__isl_take isl_basic_set *set, const char *s);
+	__isl_give isl_set *isl_set_set_tuple_name(
+		__isl_take isl_set *set, const char *s);
+	const char *isl_basic_set_get_tuple_name(
+		__isl_keep isl_basic_set *bset);
+	int isl_set_has_tuple_name(__isl_keep isl_set *set);
+	const char *isl_set_get_tuple_name(
+		__isl_keep isl_set *set);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_map *isl_basic_map_set_tuple_id(
+		__isl_take isl_basic_map *bmap,
+		enum isl_dim_type type, __isl_take isl_id *id);
+	__isl_give isl_map *isl_map_set_tuple_id(
+		__isl_take isl_map *map, enum isl_dim_type type,
+		__isl_take isl_id *id);
+	__isl_give isl_map *isl_map_reset_tuple_id(
+		__isl_take isl_map *map, enum isl_dim_type type);
+	int isl_map_has_tuple_id(__isl_keep isl_map *map,
+		enum isl_dim_type type);
+	__isl_give isl_id *isl_map_get_tuple_id(
+		__isl_keep isl_map *map, enum isl_dim_type type);
+	__isl_give isl_map *isl_map_set_tuple_name(
+		__isl_take isl_map *map,
+		enum isl_dim_type type, const char *s);
+	const char *isl_basic_map_get_tuple_name(
+		__isl_keep isl_basic_map *bmap,
+		enum isl_dim_type type);
+	__isl_give isl_basic_map *isl_basic_map_set_tuple_name(
+		__isl_take isl_basic_map *bmap,
+		enum isl_dim_type type, const char *s);
+	int isl_map_has_tuple_name(__isl_keep isl_map *map,
+		enum isl_dim_type type);
+	const char *isl_map_get_tuple_name(
+		__isl_keep isl_map *map,
+		enum isl_dim_type type);
+
+	#include <isl/val.h>
+	__isl_give isl_multi_val *isl_multi_val_set_tuple_id(
+		__isl_take isl_multi_val *mv,
+		enum isl_dim_type type, __isl_take isl_id *id);
+	__isl_give isl_multi_val *isl_multi_val_reset_tuple_id(
+		__isl_take isl_multi_val *mv,
+		enum isl_dim_type type);
+	int isl_multi_val_has_tuple_id(__isl_keep isl_multi_val *mv,
+		enum isl_dim_type type);
+	__isl_give isl_id *isl_multi_val_get_tuple_id(
+		__isl_keep isl_multi_val *mv,
+		enum isl_dim_type type);
+	__isl_give isl_multi_val *isl_multi_val_set_tuple_name(
+		__isl_take isl_multi_val *mv,
+		enum isl_dim_type type, const char *s);
+	const char *isl_multi_val_get_tuple_name(
+		__isl_keep isl_multi_val *mv,
+		enum isl_dim_type type);
+
+	#include <isl/aff.h>
+	__isl_give isl_aff *isl_aff_set_tuple_id(
+		__isl_take isl_aff *aff,
+		enum isl_dim_type type, __isl_take isl_id *id);
+	__isl_give isl_multi_aff *isl_multi_aff_set_tuple_id(
+		__isl_take isl_multi_aff *maff,
+		enum isl_dim_type type, __isl_take isl_id *id);
+	__isl_give isl_pw_aff *isl_pw_aff_set_tuple_id(
+		__isl_take isl_pw_aff *pwaff,
+		enum isl_dim_type type, __isl_take isl_id *id);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_set_tuple_id(
+		__isl_take isl_pw_multi_aff *pma,
+		enum isl_dim_type type, __isl_take isl_id *id);
+	__isl_give isl_multi_aff *isl_multi_aff_reset_tuple_id(
+		__isl_take isl_multi_aff *ma,
+		enum isl_dim_type type);
+	__isl_give isl_pw_aff *isl_pw_aff_reset_tuple_id(
+		__isl_take isl_pw_aff *pa,
+		enum isl_dim_type type);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_reset_tuple_id(
+		__isl_take isl_multi_pw_aff *mpa,
+		enum isl_dim_type type);
+	__isl_give isl_pw_multi_aff *
+	isl_pw_multi_aff_reset_tuple_id(
+		__isl_take isl_pw_multi_aff *pma,
+		enum isl_dim_type type);
+	int isl_multi_aff_has_tuple_id(__isl_keep isl_multi_aff *ma,
+		enum isl_dim_type type);
+	__isl_give isl_id *isl_multi_aff_get_tuple_id(
+		__isl_keep isl_multi_aff *ma,
+		enum isl_dim_type type);
+	int isl_pw_aff_has_tuple_id(__isl_keep isl_pw_aff *pa,
+		enum isl_dim_type type);
+	__isl_give isl_id *isl_pw_aff_get_tuple_id(
+		__isl_keep isl_pw_aff *pa,
+		enum isl_dim_type type);
+	int isl_pw_multi_aff_has_tuple_id(
+		__isl_keep isl_pw_multi_aff *pma,
+		enum isl_dim_type type);
+	__isl_give isl_id *isl_pw_multi_aff_get_tuple_id(
+		__isl_keep isl_pw_multi_aff *pma,
+		enum isl_dim_type type);
+	int isl_multi_pw_aff_has_tuple_id(
+		__isl_keep isl_multi_pw_aff *mpa,
+		enum isl_dim_type type);
+	__isl_give isl_id *isl_multi_pw_aff_get_tuple_id(
+		__isl_keep isl_multi_pw_aff *mpa,
+		enum isl_dim_type type);
+	__isl_give isl_multi_aff *isl_multi_aff_set_tuple_name(
+		__isl_take isl_multi_aff *maff,
+		enum isl_dim_type type, const char *s);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_set_tuple_name(
+		__isl_take isl_multi_pw_aff *mpa,
+		enum isl_dim_type type, const char *s);
+	const char *isl_multi_aff_get_tuple_name(
+		__isl_keep isl_multi_aff *multi,
+		enum isl_dim_type type);
+	int isl_pw_multi_aff_has_tuple_name(
+		__isl_keep isl_pw_multi_aff *pma,
+		enum isl_dim_type type);
+	const char *isl_pw_multi_aff_get_tuple_name(
+		__isl_keep isl_pw_multi_aff *pma,
+		enum isl_dim_type type);
+
+The C<type> argument needs to be one of C<isl_dim_in>, C<isl_dim_out>
+or C<isl_dim_set>.  As with C<isl_space_get_name>,
+the C<isl_space_get_tuple_name> function returns a pointer to some internal
+data structure.
+Binary operations require the corresponding spaces of their arguments
+to have the same name.
+
+To keep the names of all parameters and tuples, but reset the user pointers
+of all the corresponding identifiers, use the following function.
+
+	#include <isl/space.h>
+	__isl_give isl_space *isl_space_reset_user(
+		__isl_take isl_space *space);
+
+	#include <isl/set.h>
+	__isl_give isl_set *isl_set_reset_user(
+		__isl_take isl_set *set);
+
+	#include <isl/map.h>
+	__isl_give isl_map *isl_map_reset_user(
+		__isl_take isl_map *map);
+
+	#include <isl/union_set.h>
+	__isl_give isl_union_set *isl_union_set_reset_user(
+		__isl_take isl_union_set *uset);
+
+	#include <isl/union_map.h>
+	__isl_give isl_union_map *isl_union_map_reset_user(
+		__isl_take isl_union_map *umap);
+
+	#include <isl/val.h>
+	__isl_give isl_multi_val *isl_multi_val_reset_user(
+		__isl_take isl_multi_val *mv);
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_aff *isl_multi_aff_reset_user(
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_multi_pw_aff *isl_multi_pw_aff_reset_user(
+		__isl_take isl_multi_pw_aff *mpa);
+
+Spaces can be nested.  In particular, the domain of a set or
+the domain or range of a relation can be a nested relation.
+This process is also called I<wrapping>.
+The functions for detecting, constructing and deconstructing
+such nested spaces can be found in the wrapping properties
+of L</"Unary Properties">, the wrapping operations
+of L</"Unary Operations"> and the Cartesian product operations
+of L</"Basic Operations">.
+
+Spaces can be created from other spaces
+using the functions described in L</"Unary Operations">
+and L</"Binary Operations">.
+
+=head2 Local Spaces
+
+A local space is essentially a space with
+zero or more existentially quantified variables.
+The local space of various objects can be obtained
+using the following functions.
+
+	#include <isl/constraint.h>
+	__isl_give isl_local_space *isl_constraint_get_local_space(
+		__isl_keep isl_constraint *constraint);
+
+	#include <isl/set.h>
+	__isl_give isl_local_space *isl_basic_set_get_local_space(
+		__isl_keep isl_basic_set *bset);
+
+	#include <isl/map.h>
+	__isl_give isl_local_space *isl_basic_map_get_local_space(
+		__isl_keep isl_basic_map *bmap);
+
+	#include <isl/aff.h>
+	__isl_give isl_local_space *isl_aff_get_domain_local_space(
+		__isl_keep isl_aff *aff);
+	__isl_give isl_local_space *isl_aff_get_local_space(
+		__isl_keep isl_aff *aff);
+
+A new local space can be created from a space using
+
+	#include <isl/local_space.h>
+	__isl_give isl_local_space *isl_local_space_from_space(
+		__isl_take isl_space *space);
+
+They can be inspected, modified, copied and freed using the following functions.
+
+	#include <isl/local_space.h>
+	int isl_local_space_is_params(
+		__isl_keep isl_local_space *ls);
+	int isl_local_space_is_set(__isl_keep isl_local_space *ls);
+	__isl_give isl_space *isl_local_space_get_space(
+		__isl_keep isl_local_space *ls);
+	__isl_give isl_aff *isl_local_space_get_div(
+		__isl_keep isl_local_space *ls, int pos);
+	__isl_give isl_local_space *isl_local_space_copy(
+		__isl_keep isl_local_space *ls);
+	__isl_null isl_local_space *isl_local_space_free(
+		__isl_take isl_local_space *ls);
+
+Note that C<isl_local_space_get_div> can only be used on local spaces
+of sets.
+
+Two local spaces can be compared using
+
+	int isl_local_space_is_equal(__isl_keep isl_local_space *ls1,
+		__isl_keep isl_local_space *ls2);
+
+Local spaces can be created from other local spaces
+using the functions described in L</"Unary Operations">
+and L</"Binary Operations">.
+
+=head2 Creating New Sets and Relations
+
+C<isl> has functions for creating some standard sets and relations.
+
+=over
+
+=item * Empty sets and relations
+
+	__isl_give isl_basic_set *isl_basic_set_empty(
+		__isl_take isl_space *space);
+	__isl_give isl_basic_map *isl_basic_map_empty(
+		__isl_take isl_space *space);
+	__isl_give isl_set *isl_set_empty(
+		__isl_take isl_space *space);
+	__isl_give isl_map *isl_map_empty(
+		__isl_take isl_space *space);
+	__isl_give isl_union_set *isl_union_set_empty(
+		__isl_take isl_space *space);
+	__isl_give isl_union_map *isl_union_map_empty(
+		__isl_take isl_space *space);
+
+For C<isl_union_set>s and C<isl_union_map>s, the space
+is only used to specify the parameters.
+
+=item * Universe sets and relations
+
+	__isl_give isl_basic_set *isl_basic_set_universe(
+		__isl_take isl_space *space);
+	__isl_give isl_basic_map *isl_basic_map_universe(
+		__isl_take isl_space *space);
+	__isl_give isl_set *isl_set_universe(
+		__isl_take isl_space *space);
+	__isl_give isl_map *isl_map_universe(
+		__isl_take isl_space *space);
+	__isl_give isl_union_set *isl_union_set_universe(
+		__isl_take isl_union_set *uset);
+	__isl_give isl_union_map *isl_union_map_universe(
+		__isl_take isl_union_map *umap);
+
+The sets and relations constructed by the functions above
+contain all integer values, while those constructed by the
+functions below only contain non-negative values.
+
+	__isl_give isl_basic_set *isl_basic_set_nat_universe(
+		__isl_take isl_space *space);
+	__isl_give isl_basic_map *isl_basic_map_nat_universe(
+		__isl_take isl_space *space);
+	__isl_give isl_set *isl_set_nat_universe(
+		__isl_take isl_space *space);
+	__isl_give isl_map *isl_map_nat_universe(
+		__isl_take isl_space *space);
+
+=item * Identity relations
+
+	__isl_give isl_basic_map *isl_basic_map_identity(
+		__isl_take isl_space *space);
+	__isl_give isl_map *isl_map_identity(
+		__isl_take isl_space *space);
+
+The number of input and output dimensions in C<space> needs
+to be the same.
+
+=item * Lexicographic order
+
+	__isl_give isl_map *isl_map_lex_lt(
+		__isl_take isl_space *set_space);
+	__isl_give isl_map *isl_map_lex_le(
+		__isl_take isl_space *set_space);
+	__isl_give isl_map *isl_map_lex_gt(
+		__isl_take isl_space *set_space);
+	__isl_give isl_map *isl_map_lex_ge(
+		__isl_take isl_space *set_space);
+	__isl_give isl_map *isl_map_lex_lt_first(
+		__isl_take isl_space *space, unsigned n);
+	__isl_give isl_map *isl_map_lex_le_first(
+		__isl_take isl_space *space, unsigned n);
+	__isl_give isl_map *isl_map_lex_gt_first(
+		__isl_take isl_space *space, unsigned n);
+	__isl_give isl_map *isl_map_lex_ge_first(
+		__isl_take isl_space *space, unsigned n);
+
+The first four functions take a space for a B<set>
+and return relations that express that the elements in the domain
+are lexicographically less
+(C<isl_map_lex_lt>), less or equal (C<isl_map_lex_le>),
+greater (C<isl_map_lex_gt>) or greater or equal (C<isl_map_lex_ge>)
+than the elements in the range.
+The last four functions take a space for a map
+and return relations that express that the first C<n> dimensions
+in the domain are lexicographically less
+(C<isl_map_lex_lt_first>), less or equal (C<isl_map_lex_le_first>),
+greater (C<isl_map_lex_gt_first>) or greater or equal (C<isl_map_lex_ge_first>)
+than the first C<n> dimensions in the range.
+
+=back
+
+A basic set or relation can be converted to a set or relation
+using the following functions.
+
+	__isl_give isl_set *isl_set_from_basic_set(
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_map *isl_map_from_basic_map(
+		__isl_take isl_basic_map *bmap);
+
+Sets and relations can be converted to union sets and relations
+using the following functions.
+
+	__isl_give isl_union_set *isl_union_set_from_basic_set(
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_union_map *isl_union_map_from_basic_map(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_union_set *isl_union_set_from_set(
+		__isl_take isl_set *set);
+	__isl_give isl_union_map *isl_union_map_from_map(
+		__isl_take isl_map *map);
+
+The inverse conversions below can only be used if the input
+union set or relation is known to contain elements in exactly one
+space.
+
+	__isl_give isl_set *isl_set_from_union_set(
+		__isl_take isl_union_set *uset);
+	__isl_give isl_map *isl_map_from_union_map(
+		__isl_take isl_union_map *umap);
+
+Sets and relations can be copied and freed again using the following
+functions.
+
+	__isl_give isl_basic_set *isl_basic_set_copy(
+		__isl_keep isl_basic_set *bset);
+	__isl_give isl_set *isl_set_copy(__isl_keep isl_set *set);
+	__isl_give isl_union_set *isl_union_set_copy(
+		__isl_keep isl_union_set *uset);
+	__isl_give isl_basic_map *isl_basic_map_copy(
+		__isl_keep isl_basic_map *bmap);
+	__isl_give isl_map *isl_map_copy(__isl_keep isl_map *map);
+	__isl_give isl_union_map *isl_union_map_copy(
+		__isl_keep isl_union_map *umap);
+	__isl_null isl_basic_set *isl_basic_set_free(
+		__isl_take isl_basic_set *bset);
+	__isl_null isl_set *isl_set_free(__isl_take isl_set *set);
+	__isl_null isl_union_set *isl_union_set_free(
+		__isl_take isl_union_set *uset);
+	__isl_null isl_basic_map *isl_basic_map_free(
+		__isl_take isl_basic_map *bmap);
+	__isl_null isl_map *isl_map_free(__isl_take isl_map *map);
+	__isl_null isl_union_map *isl_union_map_free(
+		__isl_take isl_union_map *umap);
+
+Other sets and relations can be constructed by starting
+from a universe set or relation, adding equality and/or
+inequality constraints and then projecting out the
+existentially quantified variables, if any.
+Constraints can be constructed, manipulated and
+added to (or removed from) (basic) sets and relations
+using the following functions.
+
+	#include <isl/constraint.h>
+	__isl_give isl_constraint *isl_equality_alloc(
+		__isl_take isl_local_space *ls);
+	__isl_give isl_constraint *isl_inequality_alloc(
+		__isl_take isl_local_space *ls);
+	__isl_give isl_constraint *isl_constraint_set_constant_si(
+		__isl_take isl_constraint *constraint, int v);
+	__isl_give isl_constraint *isl_constraint_set_constant_val(
+		__isl_take isl_constraint *constraint,
+		__isl_take isl_val *v);
+	__isl_give isl_constraint *isl_constraint_set_coefficient_si(
+		__isl_take isl_constraint *constraint,
+		enum isl_dim_type type, int pos, int v);
+	__isl_give isl_constraint *
+	isl_constraint_set_coefficient_val(
+		__isl_take isl_constraint *constraint,
+		enum isl_dim_type type, int pos,
+		__isl_take isl_val *v);
+	__isl_give isl_basic_map *isl_basic_map_add_constraint(
+		__isl_take isl_basic_map *bmap,
+		__isl_take isl_constraint *constraint);
+	__isl_give isl_basic_set *isl_basic_set_add_constraint(
+		__isl_take isl_basic_set *bset,
+		__isl_take isl_constraint *constraint);
+	__isl_give isl_map *isl_map_add_constraint(
+		__isl_take isl_map *map,
+		__isl_take isl_constraint *constraint);
+	__isl_give isl_set *isl_set_add_constraint(
+		__isl_take isl_set *set,
+		__isl_take isl_constraint *constraint);
+	__isl_give isl_basic_set *isl_basic_set_drop_constraint(
+		__isl_take isl_basic_set *bset,
+		__isl_take isl_constraint *constraint);
+
+For example, to create a set containing the even integers
+between 10 and 42, you would use the following code.
+
+	isl_space *space;
+	isl_local_space *ls;
+	isl_constraint *c;
+	isl_basic_set *bset;
+
+	space = isl_space_set_alloc(ctx, 0, 2);
+	bset = isl_basic_set_universe(isl_space_copy(space));
+	ls = isl_local_space_from_space(space);
+
+	c = isl_equality_alloc(isl_local_space_copy(ls));
+	c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
+	c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 2);
+	bset = isl_basic_set_add_constraint(bset, c);
+
+	c = isl_inequality_alloc(isl_local_space_copy(ls));
+	c = isl_constraint_set_constant_si(c, -10);
+	c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
+	bset = isl_basic_set_add_constraint(bset, c);
+
+	c = isl_inequality_alloc(ls);
+	c = isl_constraint_set_constant_si(c, 42);
+	c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
+	bset = isl_basic_set_add_constraint(bset, c);
+
+	bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 1);
+
+Or, alternatively,
+
+	isl_basic_set *bset;
+	bset = isl_basic_set_read_from_str(ctx,
+		"{[i] : exists (a : i = 2a and i >= 10 and i <= 42)}");
+
+A basic set or relation can also be constructed from two matrices
+describing the equalities and the inequalities.
+
+	__isl_give isl_basic_set *isl_basic_set_from_constraint_matrices(
+		__isl_take isl_space *space,
+		__isl_take isl_mat *eq, __isl_take isl_mat *ineq,
+		enum isl_dim_type c1,
+		enum isl_dim_type c2, enum isl_dim_type c3,
+		enum isl_dim_type c4);
+	__isl_give isl_basic_map *isl_basic_map_from_constraint_matrices(
+		__isl_take isl_space *space,
+		__isl_take isl_mat *eq, __isl_take isl_mat *ineq,
+		enum isl_dim_type c1,
+		enum isl_dim_type c2, enum isl_dim_type c3,
+		enum isl_dim_type c4, enum isl_dim_type c5);
+
+The C<isl_dim_type> arguments indicate the order in which
+different kinds of variables appear in the input matrices
+and should be a permutation of C<isl_dim_cst>, C<isl_dim_param>,
+C<isl_dim_set> and C<isl_dim_div> for sets and
+of C<isl_dim_cst>, C<isl_dim_param>,
+C<isl_dim_in>, C<isl_dim_out> and C<isl_dim_div> for relations.
+
+A (basic or union) set or relation can also be constructed from a
+(union) (piecewise) (multiple) affine expression
+or a list of affine expressions
+(See L</"Functions">).
+
+	__isl_give isl_basic_map *isl_basic_map_from_aff(
+		__isl_take isl_aff *aff);
+	__isl_give isl_map *isl_map_from_aff(
+		__isl_take isl_aff *aff);
+	__isl_give isl_set *isl_set_from_pw_aff(
+		__isl_take isl_pw_aff *pwaff);
+	__isl_give isl_map *isl_map_from_pw_aff(
+		__isl_take isl_pw_aff *pwaff);
+	__isl_give isl_basic_map *isl_basic_map_from_aff_list(
+		__isl_take isl_space *domain_space,
+		__isl_take isl_aff_list *list);
+	__isl_give isl_basic_map *isl_basic_map_from_multi_aff(
+		__isl_take isl_multi_aff *maff)
+	__isl_give isl_map *isl_map_from_multi_aff(
+		__isl_take isl_multi_aff *maff)
+	__isl_give isl_set *isl_set_from_pw_multi_aff(
+		__isl_take isl_pw_multi_aff *pma);
+	__isl_give isl_map *isl_map_from_pw_multi_aff(
+		__isl_take isl_pw_multi_aff *pma);
+	__isl_give isl_set *isl_set_from_multi_pw_aff(
+		__isl_take isl_multi_pw_aff *mpa);
+	__isl_give isl_map *isl_map_from_multi_pw_aff(
+		__isl_take isl_multi_pw_aff *mpa);
+	__isl_give isl_union_map *
+	isl_union_map_from_union_pw_multi_aff(
+		__isl_take isl_union_pw_multi_aff *upma);
+
+The C<domain_space> argument describes the domain of the resulting
+basic relation.  It is required because the C<list> may consist
+of zero affine expressions.
+
+=head2 Inspecting Sets and Relations
+
+Usually, the user should not have to care about the actual constraints
+of the sets and maps, but should instead apply the abstract operations
+explained in the following sections.
+Occasionally, however, it may be required to inspect the individual
+coefficients of the constraints.  This section explains how to do so.
+In these cases, it may also be useful to have C<isl> compute
+an explicit representation of the existentially quantified variables.
+
+	__isl_give isl_set *isl_set_compute_divs(
+		__isl_take isl_set *set);
+	__isl_give isl_map *isl_map_compute_divs(
+		__isl_take isl_map *map);
+	__isl_give isl_union_set *isl_union_set_compute_divs(
+		__isl_take isl_union_set *uset);
+	__isl_give isl_union_map *isl_union_map_compute_divs(
+		__isl_take isl_union_map *umap);
+
+This explicit representation defines the existentially quantified
+variables as integer divisions of the other variables, possibly
+including earlier existentially quantified variables.
+An explicitly represented existentially quantified variable therefore
+has a unique value when the values of the other variables are known.
+If, furthermore, the same existentials, i.e., existentials
+with the same explicit representations, should appear in the
+same order in each of the disjuncts of a set or map, then the user should call
+either of the following functions.
+
+	__isl_give isl_set *isl_set_align_divs(
+		__isl_take isl_set *set);
+	__isl_give isl_map *isl_map_align_divs(
+		__isl_take isl_map *map);
+
+Alternatively, the existentially quantified variables can be removed
+using the following functions, which compute an overapproximation.
+
+	__isl_give isl_basic_set *isl_basic_set_remove_divs(
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_basic_map *isl_basic_map_remove_divs(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_set *isl_set_remove_divs(
+		__isl_take isl_set *set);
+	__isl_give isl_map *isl_map_remove_divs(
+		__isl_take isl_map *map);
+
+It is also possible to only remove those divs that are defined
+in terms of a given range of dimensions or only those for which
+no explicit representation is known.
+
+	__isl_give isl_basic_set *
+	isl_basic_set_remove_divs_involving_dims(
+		__isl_take isl_basic_set *bset,
+		enum isl_dim_type type,
+		unsigned first, unsigned n);
+	__isl_give isl_basic_map *
+	isl_basic_map_remove_divs_involving_dims(
+		__isl_take isl_basic_map *bmap,
+		enum isl_dim_type type,
+		unsigned first, unsigned n);
+	__isl_give isl_set *isl_set_remove_divs_involving_dims(
+		__isl_take isl_set *set, enum isl_dim_type type,
+		unsigned first, unsigned n);
+	__isl_give isl_map *isl_map_remove_divs_involving_dims(
+		__isl_take isl_map *map, enum isl_dim_type type,
+		unsigned first, unsigned n);
+
+	__isl_give isl_basic_set *
+	isl_basic_set_remove_unknown_divs(
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_set *isl_set_remove_unknown_divs(
+		__isl_take isl_set *set);
+	__isl_give isl_map *isl_map_remove_unknown_divs(
+		__isl_take isl_map *map);
+
+To iterate over all the sets or maps in a union set or map, use
+
+	int isl_union_set_foreach_set(__isl_keep isl_union_set *uset,
+		int (*fn)(__isl_take isl_set *set, void *user),
+		void *user);
+	int isl_union_map_foreach_map(__isl_keep isl_union_map *umap,
+		int (*fn)(__isl_take isl_map *map, void *user),
+		void *user);
+
+The number of sets or maps in a union set or map can be obtained
+from
+
+	int isl_union_set_n_set(__isl_keep isl_union_set *uset);
+	int isl_union_map_n_map(__isl_keep isl_union_map *umap);
+
+To extract the set or map in a given space from a union, use
+
+	__isl_give isl_set *isl_union_set_extract_set(
+		__isl_keep isl_union_set *uset,
+		__isl_take isl_space *space);
+	__isl_give isl_map *isl_union_map_extract_map(
+		__isl_keep isl_union_map *umap,
+		__isl_take isl_space *space);
+
+To iterate over all the basic sets or maps in a set or map, use
+
+	int isl_set_foreach_basic_set(__isl_keep isl_set *set,
+		int (*fn)(__isl_take isl_basic_set *bset, void *user),
+		void *user);
+	int isl_map_foreach_basic_map(__isl_keep isl_map *map,
+		int (*fn)(__isl_take isl_basic_map *bmap, void *user),
+		void *user);
+
+The callback function C<fn> should return 0 if successful and
+-1 if an error occurs.  In the latter case, or if any other error
+occurs, the above functions will return -1.
+
+It should be noted that C<isl> does not guarantee that
+the basic sets or maps passed to C<fn> are disjoint.
+If this is required, then the user should call one of
+the following functions first.
+
+	__isl_give isl_set *isl_set_make_disjoint(
+		__isl_take isl_set *set);
+	__isl_give isl_map *isl_map_make_disjoint(
+		__isl_take isl_map *map);
+
+The number of basic sets in a set can be obtained
+or the number of basic maps in a map can be obtained
+from
+
+	#include <isl/set.h>
+	int isl_set_n_basic_set(__isl_keep isl_set *set);
+
+	#include <isl/map.h>
+	int isl_map_n_basic_map(__isl_keep isl_map *map);
+
+To iterate over the constraints of a basic set or map, use
+
+	#include <isl/constraint.h>
+
+	int isl_basic_set_n_constraint(
+		__isl_keep isl_basic_set *bset);
+	int isl_basic_set_foreach_constraint(
+		__isl_keep isl_basic_set *bset,
+		int (*fn)(__isl_take isl_constraint *c, void *user),
+		void *user);
+	int isl_basic_map_n_constraint(
+		__isl_keep isl_basic_map *bmap);
+	int isl_basic_map_foreach_constraint(
+		__isl_keep isl_basic_map *bmap,
+		int (*fn)(__isl_take isl_constraint *c, void *user),
+		void *user);
+	__isl_null isl_constraint *isl_constraint_free(
+		__isl_take isl_constraint *c);
+
+Again, the callback function C<fn> should return 0 if successful and
+-1 if an error occurs.  In the latter case, or if any other error
+occurs, the above functions will return -1.
+The constraint C<c> represents either an equality or an inequality.
+Use the following function to find out whether a constraint
+represents an equality.  If not, it represents an inequality.
+
+	int isl_constraint_is_equality(
+		__isl_keep isl_constraint *constraint);
+
+It is also possible to obtain a list of constraints from a basic
+map or set
+
+	#include <isl/constraint.h>
+	__isl_give isl_constraint_list *
+	isl_basic_map_get_constraint_list(
+		__isl_keep isl_basic_map *bmap);
+	__isl_give isl_constraint_list *
+	isl_basic_set_get_constraint_list(
+		__isl_keep isl_basic_set *bset);
+
+These functions require that all existentially quantified variables
+have an explicit representation.
+The returned list can be manipulated using the functions in L<"Lists">.
+
+The coefficients of the constraints can be inspected using
+the following functions.
+
+	int isl_constraint_is_lower_bound(
+		__isl_keep isl_constraint *constraint,
+		enum isl_dim_type type, unsigned pos);
+	int isl_constraint_is_upper_bound(
+		__isl_keep isl_constraint *constraint,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_val *isl_constraint_get_constant_val(
+		__isl_keep isl_constraint *constraint);
+	__isl_give isl_val *isl_constraint_get_coefficient_val(
+		__isl_keep isl_constraint *constraint,
+		enum isl_dim_type type, int pos);
+
+The explicit representations of the existentially quantified
+variables can be inspected using the following function.
+Note that the user is only allowed to use this function
+if the inspected set or map is the result of a call
+to C<isl_set_compute_divs> or C<isl_map_compute_divs>.
+The existentially quantified variable is equal to the floor
+of the returned affine expression.  The affine expression
+itself can be inspected using the functions in
+L</"Functions">.
+
+	__isl_give isl_aff *isl_constraint_get_div(
+		__isl_keep isl_constraint *constraint, int pos);
+
+To obtain the constraints of a basic set or map in matrix
+form, use the following functions.
+
+	__isl_give isl_mat *isl_basic_set_equalities_matrix(
+		__isl_keep isl_basic_set *bset,
+		enum isl_dim_type c1, enum isl_dim_type c2,
+		enum isl_dim_type c3, enum isl_dim_type c4);
+	__isl_give isl_mat *isl_basic_set_inequalities_matrix(
+		__isl_keep isl_basic_set *bset,
+		enum isl_dim_type c1, enum isl_dim_type c2,
+		enum isl_dim_type c3, enum isl_dim_type c4);
+	__isl_give isl_mat *isl_basic_map_equalities_matrix(
+		__isl_keep isl_basic_map *bmap,
+		enum isl_dim_type c1,
+		enum isl_dim_type c2, enum isl_dim_type c3,
+		enum isl_dim_type c4, enum isl_dim_type c5);
+	__isl_give isl_mat *isl_basic_map_inequalities_matrix(
+		__isl_keep isl_basic_map *bmap,
+		enum isl_dim_type c1,
+		enum isl_dim_type c2, enum isl_dim_type c3,
+		enum isl_dim_type c4, enum isl_dim_type c5);
+
+The C<isl_dim_type> arguments dictate the order in which
+different kinds of variables appear in the resulting matrix.
+For set inputs, they should be a permutation of
+C<isl_dim_cst>, C<isl_dim_param>, C<isl_dim_set> and C<isl_dim_div>.
+For map inputs, they should be a permutation of
+C<isl_dim_cst>, C<isl_dim_param>,
+C<isl_dim_in>, C<isl_dim_out> and C<isl_dim_div>.
+
+=head2 Points
+
+Points are elements of a set.  They can be used to construct
+simple sets (boxes) or they can be used to represent the
+individual elements of a set.
+The zero point (the origin) can be created using
+
+	__isl_give isl_point *isl_point_zero(__isl_take isl_space *space);
+
+The coordinates of a point can be inspected, set and changed
+using
+
+	__isl_give isl_val *isl_point_get_coordinate_val(
+		__isl_keep isl_point *pnt,
+		enum isl_dim_type type, int pos);
+	__isl_give isl_point *isl_point_set_coordinate_val(
+		__isl_take isl_point *pnt,
+		enum isl_dim_type type, int pos,
+		__isl_take isl_val *v);
+
+	__isl_give isl_point *isl_point_add_ui(
+		__isl_take isl_point *pnt,
+		enum isl_dim_type type, int pos, unsigned val);
+	__isl_give isl_point *isl_point_sub_ui(
+		__isl_take isl_point *pnt,
+		enum isl_dim_type type, int pos, unsigned val);
+
+Points can be copied or freed using
+
+	__isl_give isl_point *isl_point_copy(
+		__isl_keep isl_point *pnt);
+	void isl_point_free(__isl_take isl_point *pnt);
+
+A singleton set can be created from a point using
+
+	__isl_give isl_basic_set *isl_basic_set_from_point(
+		__isl_take isl_point *pnt);
+	__isl_give isl_set *isl_set_from_point(
+		__isl_take isl_point *pnt);
+
+and a box can be created from two opposite extremal points using
+
+	__isl_give isl_basic_set *isl_basic_set_box_from_points(
+		__isl_take isl_point *pnt1,
+		__isl_take isl_point *pnt2);
+	__isl_give isl_set *isl_set_box_from_points(
+		__isl_take isl_point *pnt1,
+		__isl_take isl_point *pnt2);
+
+All elements of a B<bounded> (union) set can be enumerated using
+the following functions.
+
+	int isl_set_foreach_point(__isl_keep isl_set *set,
+		int (*fn)(__isl_take isl_point *pnt, void *user),
+		void *user);
+	int isl_union_set_foreach_point(__isl_keep isl_union_set *uset,
+		int (*fn)(__isl_take isl_point *pnt, void *user),
+		void *user);
+
+The function C<fn> is called for each integer point in
+C<set> with as second argument the last argument of
+the C<isl_set_foreach_point> call.  The function C<fn>
+should return C<0> on success and C<-1> on failure.
+In the latter case, C<isl_set_foreach_point> will stop
+enumerating and return C<-1> as well.
+If the enumeration is performed successfully and to completion,
+then C<isl_set_foreach_point> returns C<0>.
+
+To obtain a single point of a (basic) set, use
+
+	__isl_give isl_point *isl_basic_set_sample_point(
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_point *isl_set_sample_point(
+		__isl_take isl_set *set);
+
+If C<set> does not contain any (integer) points, then the
+resulting point will be ``void'', a property that can be
+tested using
+
+	int isl_point_is_void(__isl_keep isl_point *pnt);
+
+=head2 Functions
+
+Besides sets and relation, C<isl> also supports various types of functions.
+Each of these types is derived from the value type (see L</"Values">)
+or from one of two primitive function types
+through the application of zero or more type constructors.
+We first describe the primitive type and then we describe
+the types derived from these primitive types.
+
+=head3 Primitive Functions
+
+C<isl> support two primitive function types, quasi-affine
+expressions and quasipolynomials.
+A quasi-affine expression is defined either over a parameter
+space or over a set and is composed of integer constants,
+parameters and set variables, addition, subtraction and
+integer division by an integer constant.
+For example, the quasi-affine expression
+
+	[n] -> { [x] -> [2*floor((4 n + x)/9] }
+
+maps C<x> to C<2*floor((4 n + x)/9>.
+A quasipolynomial is a polynomial expression in quasi-affine
+expression.  That is, it additionally allows for multiplication.
+Note, though, that it is not allowed to construct an integer
+division of an expression involving multiplications.
+Here is an example of a quasipolynomial that is not
+quasi-affine expression
+
+	[n] -> { [x] -> (n*floor((4 n + x)/9) }
+
+Note that the external representations of quasi-affine expressions
+and quasipolynomials are different.  Quasi-affine expressions
+use a notation with square brackets just like binary relations,
+while quasipolynomials do not.  This might change at some point.
+
+If a primitive function is defined over a parameter space,
+then the space of the function itself is that of a set.
+If it is defined over a set, then the space of the function
+is that of a relation.  In both cases, the set space (or
+the output space) is single-dimensional, anonymous and unstructured.
+To create functions with multiple dimensions or with other kinds
+of set or output spaces, use multiple expressions
+(see L</"Multiple Expressions">).
+
+=over
+
+=item * Quasi-affine Expressions
+
+Besides the expressions described above, a quasi-affine
+expression can also be set to NaN.  Such expressions
+typically represent a failure to represent a result
+as a quasi-affine expression.
+
+The zero quasi affine expression or the quasi affine expression
+that is equal to a given value or
+a specified dimension on a given domain can be created using
+
+	#include <isl/aff.h>
+	__isl_give isl_aff *isl_aff_zero_on_domain(
+		__isl_take isl_local_space *ls);
+	__isl_give isl_aff *isl_aff_val_on_domain(
+		__isl_take isl_local_space *ls,
+		__isl_take isl_val *val);
+	__isl_give isl_aff *isl_aff_var_on_domain(
+		__isl_take isl_local_space *ls,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_aff *isl_aff_nan_on_domain(
+		__isl_take isl_local_space *ls);
+
+Quasi affine expressions can be copied and freed using
+
+	#include <isl/aff.h>
+	__isl_give isl_aff *isl_aff_copy(
+		__isl_keep isl_aff *aff);
+	__isl_null isl_aff *isl_aff_free(
+		__isl_take isl_aff *aff);
+
+A (rational) bound on a dimension can be extracted from an C<isl_constraint>
+using the following function.  The constraint is required to have
+a non-zero coefficient for the specified dimension.
+
+	#include <isl/constraint.h>
+	__isl_give isl_aff *isl_constraint_get_bound(
+		__isl_keep isl_constraint *constraint,
+		enum isl_dim_type type, int pos);
+
+The entire affine expression of the constraint can also be extracted
+using the following function.
+
+	#include <isl/constraint.h>
+	__isl_give isl_aff *isl_constraint_get_aff(
+		__isl_keep isl_constraint *constraint);
+
+Conversely, an equality constraint equating
+the affine expression to zero or an inequality constraint enforcing
+the affine expression to be non-negative, can be constructed using
+
+	__isl_give isl_constraint *isl_equality_from_aff(
+		__isl_take isl_aff *aff);
+	__isl_give isl_constraint *isl_inequality_from_aff(
+		__isl_take isl_aff *aff);
+
+The coefficients and the integer divisions of an affine expression
+can be inspected using the following functions.
+
+	#include <isl/aff.h>
+	__isl_give isl_val *isl_aff_get_constant_val(
+		__isl_keep isl_aff *aff);
+	__isl_give isl_val *isl_aff_get_coefficient_val(
+		__isl_keep isl_aff *aff,
+		enum isl_dim_type type, int pos);
+	int isl_aff_coefficient_sgn(__isl_keep isl_aff *aff,
+		enum isl_dim_type type, int pos);
+	__isl_give isl_val *isl_aff_get_denominator_val(
+		__isl_keep isl_aff *aff);
+	__isl_give isl_aff *isl_aff_get_div(
+		__isl_keep isl_aff *aff, int pos);
+
+They can be modified using the following functions.
+
+	#include <isl/aff.h>
+	__isl_give isl_aff *isl_aff_set_constant_si(
+		__isl_take isl_aff *aff, int v);
+	__isl_give isl_aff *isl_aff_set_constant_val(
+		__isl_take isl_aff *aff, __isl_take isl_val *v);
+	__isl_give isl_aff *isl_aff_set_coefficient_si(
+		__isl_take isl_aff *aff,
+		enum isl_dim_type type, int pos, int v);
+	__isl_give isl_aff *isl_aff_set_coefficient_val(
+		__isl_take isl_aff *aff,
+		enum isl_dim_type type, int pos,
+		__isl_take isl_val *v);
+
+	__isl_give isl_aff *isl_aff_add_constant_si(
+		__isl_take isl_aff *aff, int v);
+	__isl_give isl_aff *isl_aff_add_constant_val(
+		__isl_take isl_aff *aff, __isl_take isl_val *v);
+	__isl_give isl_aff *isl_aff_add_constant_num_si(
+		__isl_take isl_aff *aff, int v);
+	__isl_give isl_aff *isl_aff_add_coefficient_si(
+		__isl_take isl_aff *aff,
+		enum isl_dim_type type, int pos, int v);
+	__isl_give isl_aff *isl_aff_add_coefficient_val(
+		__isl_take isl_aff *aff,
+		enum isl_dim_type type, int pos,
+		__isl_take isl_val *v);
+
+Note that C<isl_aff_set_constant_si> and C<isl_aff_set_coefficient_si>
+set the I<numerator> of the constant or coefficient, while
+C<isl_aff_set_constant_val> and C<isl_aff_set_coefficient_val> set
+the constant or coefficient as a whole.
+The C<add_constant> and C<add_coefficient> functions add an integer
+or rational value to
+the possibly rational constant or coefficient.
+The C<add_constant_num> functions add an integer value to
+the numerator.
+
+=item * Quasipolynomials
+
+Some simple quasipolynomials can be created using the following functions.
+
+	#include <isl/polynomial.h>
+	__isl_give isl_qpolynomial *isl_qpolynomial_zero_on_domain(
+		__isl_take isl_space *domain);
+	__isl_give isl_qpolynomial *isl_qpolynomial_one_on_domain(
+		__isl_take isl_space *domain);
+	__isl_give isl_qpolynomial *isl_qpolynomial_infty_on_domain(
+		__isl_take isl_space *domain);
+	__isl_give isl_qpolynomial *isl_qpolynomial_neginfty_on_domain(
+		__isl_take isl_space *domain);
+	__isl_give isl_qpolynomial *isl_qpolynomial_nan_on_domain(
+		__isl_take isl_space *domain);
+	__isl_give isl_qpolynomial *isl_qpolynomial_val_on_domain(
+		__isl_take isl_space *domain,
+		__isl_take isl_val *val);
+	__isl_give isl_qpolynomial *isl_qpolynomial_var_on_domain(
+		__isl_take isl_space *domain,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_qpolynomial *isl_qpolynomial_from_aff(
+		__isl_take isl_aff *aff);
+
+Recall that the space in which a quasipolynomial lives is a map space
+with a one-dimensional range.  The C<domain> argument in some of
+the functions above corresponds to the domain of this map space.
+
+Quasipolynomials can be copied and freed again using the following
+functions.
+
+	#include <isl/polynomial.h>
+	__isl_give isl_qpolynomial *isl_qpolynomial_copy(
+		__isl_keep isl_qpolynomial *qp);
+	__isl_null isl_qpolynomial *isl_qpolynomial_free(
+		__isl_take isl_qpolynomial *qp);
+
+The constant term of a quasipolynomial can be extracted using
+
+	__isl_give isl_val *isl_qpolynomial_get_constant_val(
+		__isl_keep isl_qpolynomial *qp);
+
+To iterate over all terms in a quasipolynomial,
+use
+
+	int isl_qpolynomial_foreach_term(
+		__isl_keep isl_qpolynomial *qp,
+		int (*fn)(__isl_take isl_term *term,
+			  void *user), void *user);
+
+The terms themselves can be inspected and freed using
+these functions
+
+	unsigned isl_term_dim(__isl_keep isl_term *term,
+		enum isl_dim_type type);
+	__isl_give isl_val *isl_term_get_coefficient_val(
+		__isl_keep isl_term *term);
+	int isl_term_get_exp(__isl_keep isl_term *term,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_aff *isl_term_get_div(
+		__isl_keep isl_term *term, unsigned pos);
+	void isl_term_free(__isl_take isl_term *term);
+
+Each term is a product of parameters, set variables and
+integer divisions.  The function C<isl_term_get_exp>
+returns the exponent of a given dimensions in the given term.
+
+=back
+
+=head3 Reductions
+
+A reduction represents a maximum or a minimum of its
+base expressions.
+The only reduction type defined by C<isl> is
+C<isl_qpolynomial_fold>.
+
+There are currently no functions to directly create such
+objects, but they do appear in the piecewise quasipolynomial
+reductions returned by the C<isl_pw_qpolynomial_bound> function.
+See
+L</"Bounds on Piecewise Quasipolynomials and Piecewise Quasipolynomial Reductions">.
+
+Reductions can be copied and freed using
+the following functions.
+
+	#include <isl/polynomial.h>
+	__isl_give isl_qpolynomial_fold *
+	isl_qpolynomial_fold_copy(
+		__isl_keep isl_qpolynomial_fold *fold);
+	void isl_qpolynomial_fold_free(
+		__isl_take isl_qpolynomial_fold *fold);
+
+To iterate over all quasipolynomials in a reduction, use
+
+	int isl_qpolynomial_fold_foreach_qpolynomial(
+		__isl_keep isl_qpolynomial_fold *fold,
+		int (*fn)(__isl_take isl_qpolynomial *qp,
+			  void *user), void *user);
+
+=head3 Multiple Expressions
+
+A multiple expression represents a sequence of zero or
+more base expressions, all defined on the same domain space.
+The domain space of the multiple expression is the same
+as that of the base expressions, but the range space
+can be any space.  In case the base expressions have
+a set space, the corresponding multiple expression
+also has a set space.
+Objects of the value type do not have an associated space.
+The space of a multiple value is therefore always a set space.
+
+The multiple expression types defined by C<isl>
+are C<isl_multi_val>, C<isl_multi_aff> and C<isl_multi_pw_aff>.
+
+A multiple expression with the value zero for
+each output (or set) dimension can be created
+using the following functions.
+
+	#include <isl/val.h>
+	__isl_give isl_multi_val *isl_multi_val_zero(
+		__isl_take isl_space *space);
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_aff *isl_multi_aff_zero(
+		__isl_take isl_space *space);
+	__isl_give isl_multi_pw_aff *isl_multi_pw_aff_zero(
+		__isl_take isl_space *space);
+
+An identity function can be created using the following
+functions.  The space needs to be that of a relation
+with the same number of input and output dimensions.
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_aff *isl_multi_aff_identity(
+		__isl_take isl_space *space);
+	__isl_give isl_multi_pw_aff *isl_multi_pw_aff_identity(
+		__isl_take isl_space *space);
+
+A function that performs a projection on a universe
+relation or set can be created using the following functions.
+See also the corresponding
+projection operations in L</"Unary Operations">.
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_aff *isl_multi_aff_domain_map(
+		__isl_take isl_space *space);
+	__isl_give isl_multi_aff *isl_multi_aff_range_map(
+		__isl_take isl_space *space);
+	__isl_give isl_multi_aff *isl_multi_aff_project_out_map(
+		__isl_take isl_space *space,
+		enum isl_dim_type type,
+		unsigned first, unsigned n);
+
+A multiple expression can be created from a single
+base expression using the following functions.
+The space of the created multiple expression is the same
+as that of the base expression.
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_aff *isl_multi_aff_from_aff(
+		__isl_take isl_aff *aff);
+	__isl_give isl_multi_pw_aff *isl_multi_pw_aff_from_pw_aff(
+		__isl_take isl_pw_aff *pa);
+
+A multiple expression can be created from a list
+of base expression in a specified space.
+The domain of this space needs to be the same
+as the domains of the base expressions in the list.
+If the base expressions have a set space (or no associated space),
+then this space also needs to be a set space.
+
+	#include <isl/val.h>
+	__isl_give isl_multi_val *isl_multi_val_from_val_list(
+		__isl_take isl_space *space,
+		__isl_take isl_val_list *list);
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_aff *isl_multi_aff_from_aff_list(
+		__isl_take isl_space *space,
+		__isl_take isl_aff_list *list);
+
+As a convenience, a multiple piecewise expression can
+also be created from a multiple expression.
+Each piecewise expression in the result has a single
+universe cell.
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_from_multi_aff(
+		__isl_take isl_multi_aff *ma);
+
+A multiple quasi-affine expression can be created from
+a multiple value with a given domain space using the following
+function.
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_aff *
+	isl_multi_aff_multi_val_on_space(
+		__isl_take isl_space *space,
+		__isl_take isl_multi_val *mv);
+
+Multiple expressions can be copied and freed using
+the following functions.
+
+	#include <isl/val.h>
+	__isl_give isl_multi_val *isl_multi_val_copy(
+		__isl_keep isl_multi_val *mv);
+	__isl_null isl_multi_val *isl_multi_val_free(
+		__isl_take isl_multi_val *mv);
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_aff *isl_multi_aff_copy(
+		__isl_keep isl_multi_aff *maff);
+	__isl_null isl_multi_aff *isl_multi_aff_free(
+		__isl_take isl_multi_aff *maff);
+	__isl_give isl_multi_pw_aff *isl_multi_pw_aff_copy(
+		__isl_keep isl_multi_pw_aff *mpa);
+	__isl_null isl_multi_pw_aff *isl_multi_pw_aff_free(
+		__isl_take isl_multi_pw_aff *mpa);
+
+The base expression at a given position of a multiple
+expression can be extracted using the following functions.
+
+	#include <isl/val.h>
+	__isl_give isl_val *isl_multi_val_get_val(
+		__isl_keep isl_multi_val *mv, int pos);
+
+	#include <isl/aff.h>
+	__isl_give isl_aff *isl_multi_aff_get_aff(
+		__isl_keep isl_multi_aff *multi, int pos);
+	__isl_give isl_pw_aff *isl_multi_pw_aff_get_pw_aff(
+		__isl_keep isl_multi_pw_aff *mpa, int pos);
+
+It can be replaced using the following functions.
+
+	#include <isl/val.h>
+	__isl_give isl_multi_val *isl_multi_val_set_val(
+		__isl_take isl_multi_val *mv, int pos,
+		__isl_take isl_val *val);
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_aff *isl_multi_aff_set_aff(
+		__isl_take isl_multi_aff *multi, int pos,
+		__isl_take isl_aff *aff);
+
+=head3 Piecewise Expressions
+
+A piecewise expression is an expression that is described
+using zero or more base expression defined over the same
+number of cells in the domain space of the base expressions.
+All base expressions are defined over the same
+domain space and the cells are disjoint.
+The space of a piecewise expression is the same as
+that of the base expressions.
+If the union of the cells is a strict subset of the domain
+space, then the value of the piecewise expression outside
+this union is different for types derived from quasi-affine
+expressions and those derived from quasipolynomials.
+Piecewise expressions derived from quasi-affine expressions
+are considered to be undefined outside the union of their cells.
+Piecewise expressions derived from quasipolynomials
+are considered to be zero outside the union of their cells.
+
+Piecewise quasipolynomials are mainly used by the C<barvinok>
+library for representing the number of elements in a parametric set or map.
+For example, the piecewise quasipolynomial
+
+	[n] -> { [x] -> ((1 + n) - x) : x <= n and x >= 0 }
+
+represents the number of points in the map
+
+	[n] -> { [x] -> [y] : x,y >= 0 and 0 <= x + y <= n }
+
+The piecewise expression types defined by C<isl>
+are C<isl_pw_aff>, C<isl_pw_multi_aff>,
+C<isl_pw_qpolynomial> and C<isl_pw_qpolynomial_fold>.
+
+A piecewise expression with no cells can be created using
+the following functions.
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_aff *isl_pw_aff_empty(
+		__isl_take isl_space *space);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_empty(
+		__isl_take isl_space *space);
+
+A piecewise expression with a single universe cell can be
+created using the following functions.
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_aff *isl_pw_aff_from_aff(
+		__isl_take isl_aff *aff);
+	__isl_give isl_pw_multi_aff *
+	isl_pw_multi_aff_from_multi_aff(
+		__isl_take isl_multi_aff *ma);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_pw_qpolynomial *
+	isl_pw_qpolynomial_from_qpolynomial(
+		__isl_take isl_qpolynomial *qp);
+
+A piecewise expression with a single specified cell can be
+created using the following functions.
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_aff *isl_pw_aff_alloc(
+		__isl_take isl_set *set, __isl_take isl_aff *aff);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_alloc(
+		__isl_take isl_set *set,
+		__isl_take isl_multi_aff *maff);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_alloc(
+		__isl_take isl_set *set,
+		__isl_take isl_qpolynomial *qp);
+
+The following convenience functions first create a base expression and
+then create a piecewise expression over a universe domain.
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_aff *isl_pw_aff_zero_on_domain(
+		__isl_take isl_local_space *ls);
+	__isl_give isl_pw_aff *isl_pw_aff_var_on_domain(
+		__isl_take isl_local_space *ls,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_pw_aff *isl_pw_aff_nan_on_domain(
+		__isl_take isl_local_space *ls);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_zero(
+		__isl_take isl_space *space);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_identity(
+		__isl_take isl_space *space);
+	__isl_give isl_pw_multi_aff *
+	isl_pw_multi_aff_project_out_map(
+		__isl_take isl_space *space,
+		enum isl_dim_type type,
+		unsigned first, unsigned n);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_zero(
+		__isl_take isl_space *space);
+
+The following convenience functions first create a base expression and
+then create a piecewise expression over a given domain.
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_aff *isl_pw_aff_val_on_domain(
+		__isl_take isl_set *domain,
+		__isl_take isl_val *v);
+	__isl_give isl_pw_multi_aff *
+	isl_pw_multi_aff_multi_val_on_domain(
+		__isl_take isl_set *domain,
+		__isl_take isl_multi_val *mv);
+
+As a convenience, a piecewise multiple expression can
+also be created from a piecewise expression.
+Each multiple expression in the result is derived
+from the corresponding base expression.
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_pw_aff(
+		__isl_take isl_pw_aff *pa);
+
+Similarly, a piecewise quasipolynomial can be
+created from a piecewise quasi-affine expression using
+the following function.
+
+	#include <isl/polynomial.h>
+	__isl_give isl_pw_qpolynomial *
+	isl_pw_qpolynomial_from_pw_aff(
+		__isl_take isl_pw_aff *pwaff);
+
+Piecewise expressions can be copied and freed using the following functions.
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_aff *isl_pw_aff_copy(
+		__isl_keep isl_pw_aff *pwaff);
+	__isl_null isl_pw_aff *isl_pw_aff_free(
+		__isl_take isl_pw_aff *pwaff);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_copy(
+		__isl_keep isl_pw_multi_aff *pma);
+	__isl_null isl_pw_multi_aff *isl_pw_multi_aff_free(
+		__isl_take isl_pw_multi_aff *pma);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_copy(
+		__isl_keep isl_pw_qpolynomial *pwqp);
+	__isl_null isl_pw_qpolynomial *isl_pw_qpolynomial_free(
+		__isl_take isl_pw_qpolynomial *pwqp);
+	__isl_give isl_pw_qpolynomial_fold *
+	isl_pw_qpolynomial_fold_copy(
+		__isl_keep isl_pw_qpolynomial_fold *pwf);
+	__isl_null isl_pw_qpolynomial_fold *
+	isl_pw_qpolynomial_fold_free(
+		__isl_take isl_pw_qpolynomial_fold *pwf);
+
+To iterate over the different cells of a piecewise expression,
+use the following functions.
+
+	#include <isl/aff.h>
+	int isl_pw_aff_is_empty(__isl_keep isl_pw_aff *pwaff);
+	int isl_pw_aff_n_piece(__isl_keep isl_pw_aff *pwaff);
+	int isl_pw_aff_foreach_piece(__isl_keep isl_pw_aff *pwaff,
+		int (*fn)(__isl_take isl_set *set,
+			  __isl_take isl_aff *aff,
+			  void *user), void *user);
+	int isl_pw_multi_aff_foreach_piece(
+		__isl_keep isl_pw_multi_aff *pma,
+		int (*fn)(__isl_take isl_set *set,
+			    __isl_take isl_multi_aff *maff,
+			    void *user), void *user);
+
+	#include <isl/polynomial.h>
+	int isl_pw_qpolynomial_foreach_piece(
+		__isl_keep isl_pw_qpolynomial *pwqp,
+		int (*fn)(__isl_take isl_set *set,
+			  __isl_take isl_qpolynomial *qp,
+			  void *user), void *user);
+	int isl_pw_qpolynomial_foreach_lifted_piece(
+		__isl_keep isl_pw_qpolynomial *pwqp,
+		int (*fn)(__isl_take isl_set *set,
+			  __isl_take isl_qpolynomial *qp,
+			  void *user), void *user);
+	int isl_pw_qpolynomial_fold_foreach_piece(
+		__isl_keep isl_pw_qpolynomial_fold *pwf,
+		int (*fn)(__isl_take isl_set *set,
+			  __isl_take isl_qpolynomial_fold *fold,
+			  void *user), void *user);
+	int isl_pw_qpolynomial_fold_foreach_lifted_piece(
+		__isl_keep isl_pw_qpolynomial_fold *pwf,
+		int (*fn)(__isl_take isl_set *set,
+			  __isl_take isl_qpolynomial_fold *fold,
+			  void *user), void *user);
+
+As usual, the function C<fn> should return C<0> on success
+and C<-1> on failure.  The difference between
+C<isl_pw_qpolynomial_foreach_piece> and
+C<isl_pw_qpolynomial_foreach_lifted_piece> is that
+C<isl_pw_qpolynomial_foreach_lifted_piece> will first
+compute unique representations for all existentially quantified
+variables and then turn these existentially quantified variables
+into extra set variables, adapting the associated quasipolynomial
+accordingly.  This means that the C<set> passed to C<fn>
+will not have any existentially quantified variables, but that
+the dimensions of the sets may be different for different
+invocations of C<fn>.
+Similarly for C<isl_pw_qpolynomial_fold_foreach_piece>
+and C<isl_pw_qpolynomial_fold_foreach_lifted_piece>.
+
+A piecewise expression consisting of the expressions at a given
+position of a piecewise multiple expression can be extracted
+using the following function.
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_aff *isl_pw_multi_aff_get_pw_aff(
+		__isl_keep isl_pw_multi_aff *pma, int pos);
+
+These expressions can be replaced using the following function.
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_set_pw_aff(
+		__isl_take isl_pw_multi_aff *pma, unsigned pos,
+		__isl_take isl_pw_aff *pa);
+
+Note that there is a difference between C<isl_multi_pw_aff> and
+C<isl_pw_multi_aff> objects.  The first is a sequence of piecewise
+affine expressions, while the second is a piecewise sequence
+of affine expressions.  In particular, each of the piecewise
+affine expressions in an C<isl_multi_pw_aff> may have a different
+domain, while all multiple expressions associated to a cell
+in an C<isl_pw_multi_aff> have the same domain.
+It is possible to convert between the two, but when converting
+an C<isl_multi_pw_aff> to an C<isl_pw_multi_aff>, the domain
+of the result is the intersection of the domains of the input.
+The reverse conversion is exact.
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_multi_aff *
+	isl_pw_multi_aff_from_multi_pw_aff(
+		__isl_take isl_multi_pw_aff *mpa);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_from_pw_multi_aff(
+		__isl_take isl_pw_multi_aff *pma);
+
+=head3 Union Expressions
+
+A union expression collects base expressions defined
+over different domains.  The space of a union expression
+is that of the shared parameter space.
+
+The union expression types defined by C<isl>
+are C<isl_union_pw_multi_aff>, C<isl_union_pw_qpolynomial> and
+C<isl_union_pw_qpolynomial_fold>.
+
+An empty union expression can be created using the following functions.
+
+	#include <isl/aff.h>
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_empty(
+		__isl_take isl_space *space);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_union_pw_qpolynomial *
+	isl_union_pw_qpolynomial_zero(
+		__isl_take isl_space *space);
+
+A union expression containing a single base expression
+can be created using the following functions.
+
+	#include <isl/aff.h>
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_from_pw_multi_aff(
+		__isl_take isl_pw_multi_aff *pma);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_union_pw_qpolynomial *
+	isl_union_pw_qpolynomial_from_pw_qpolynomial(
+		__isl_take isl_pw_qpolynomial *pwqp);
+
+The following function creates a base expression on each
+of the sets in the union set and collects the results.
+
+	#include <isl/aff.h>
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_multi_val_on_domain(
+		__isl_take isl_union_set *domain,
+		__isl_take isl_multi_val *mv);
+
+A base expression can be added to a union expression using
+the following functions.
+
+	#include <isl/aff.h>
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_add_pw_multi_aff(
+		__isl_take isl_union_pw_multi_aff *upma,
+		__isl_take isl_pw_multi_aff *pma);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_union_pw_qpolynomial *
+	isl_union_pw_qpolynomial_add_pw_qpolynomial(
+		__isl_take isl_union_pw_qpolynomial *upwqp,
+		__isl_take isl_pw_qpolynomial *pwqp);
+
+Union expressions can be copied and freed using
+the following functions.
+
+	#include <isl/aff.h>
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_copy(
+		__isl_keep isl_union_pw_multi_aff *upma);
+	__isl_null isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_free(
+		__isl_take isl_union_pw_multi_aff *upma);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_union_pw_qpolynomial *
+	isl_union_pw_qpolynomial_copy(
+		__isl_keep isl_union_pw_qpolynomial *upwqp);
+	__isl_null isl_union_pw_qpolynomial *
+	isl_union_pw_qpolynomial_free(
+		__isl_take isl_union_pw_qpolynomial *upwqp);
+	__isl_give isl_union_pw_qpolynomial_fold *
+	isl_union_pw_qpolynomial_fold_copy(
+		__isl_keep isl_union_pw_qpolynomial_fold *upwf);
+	__isl_null isl_union_pw_qpolynomial_fold *
+	isl_union_pw_qpolynomial_fold_free(
+		__isl_take isl_union_pw_qpolynomial_fold *upwf);
+
+To iterate over the base expressions in a union expression,
+use the following functions.
+
+	#include <isl/aff.h>
+	int isl_union_pw_multi_aff_foreach_pw_multi_aff(
+		__isl_keep isl_union_pw_multi_aff *upma,
+		int (*fn)(__isl_take isl_pw_multi_aff *pma,
+			    void *user), void *user);
+
+	#include <isl/polynomial.h>
+	int isl_union_pw_qpolynomial_foreach_pw_qpolynomial(
+		__isl_keep isl_union_pw_qpolynomial *upwqp,
+		int (*fn)(__isl_take isl_pw_qpolynomial *pwqp,
+			    void *user), void *user);
+	int isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(
+		__isl_keep isl_union_pw_qpolynomial_fold *upwf,
+		int (*fn)(__isl_take isl_pw_qpolynomial_fold *pwf,
+			    void *user), void *user);
+
+To extract the base expression in a given space from a union, use
+the following functions.
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_multi_aff *
+	isl_union_pw_multi_aff_extract_pw_multi_aff(
+		__isl_keep isl_union_pw_multi_aff *upma,
+		__isl_take isl_space *space);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_pw_qpolynomial *
+	isl_union_pw_qpolynomial_extract_pw_qpolynomial(
+		__isl_keep isl_union_pw_qpolynomial *upwqp,
+		__isl_take isl_space *space);
+
+=head2 Input and Output
+
+For set and relation,
+C<isl> supports its own input/output format, which is similar
+to the C<Omega> format, but also supports the C<PolyLib> format
+in some cases.
+For other object types, typically only an C<isl> format is supported.
+
+=head3 C<isl> format
+
+The C<isl> format is similar to that of C<Omega>, but has a different
+syntax for describing the parameters and allows for the definition
+of an existentially quantified variable as the integer division
+of an affine expression.
+For example, the set of integers C<i> between C<0> and C<n>
+such that C<i % 10 <= 6> can be described as
+
+	[n] -> { [i] : exists (a = [i/10] : 0 <= i and i <= n and
+				i - 10 a <= 6) }
+
+A set or relation can have several disjuncts, separated
+by the keyword C<or>.  Each disjunct is either a conjunction
+of constraints or a projection (C<exists>) of a conjunction
+of constraints.  The constraints are separated by the keyword
+C<and>.
+
+=head3 C<PolyLib> format
+
+If the represented set is a union, then the first line
+contains a single number representing the number of disjuncts.
+Otherwise, a line containing the number C<1> is optional.
+
+Each disjunct is represented by a matrix of constraints.
+The first line contains two numbers representing
+the number of rows and columns,
+where the number of rows is equal to the number of constraints
+and the number of columns is equal to two plus the number of variables.
+The following lines contain the actual rows of the constraint matrix.
+In each row, the first column indicates whether the constraint
+is an equality (C<0>) or inequality (C<1>).  The final column
+corresponds to the constant term.
+
+If the set is parametric, then the coefficients of the parameters
+appear in the last columns before the constant column.
+The coefficients of any existentially quantified variables appear
+between those of the set variables and those of the parameters.
+
+=head3 Extended C<PolyLib> format
+
+The extended C<PolyLib> format is nearly identical to the
+C<PolyLib> format.  The only difference is that the line
+containing the number of rows and columns of a constraint matrix
+also contains four additional numbers:
+the number of output dimensions, the number of input dimensions,
+the number of local dimensions (i.e., the number of existentially
+quantified variables) and the number of parameters.
+For sets, the number of ``output'' dimensions is equal
+to the number of set dimensions, while the number of ``input''
+dimensions is zero.
+
+=head3 Input
+
+Objects can be read from input using the following functions.
+
+	#include <isl/val.h>
+	__isl_give isl_val *isl_val_read_from_str(isl_ctx *ctx,
+		const char *str);
+
+	#include <isl/set.h>
+	__isl_give isl_basic_set *isl_basic_set_read_from_file(
+		isl_ctx *ctx, FILE *input);
+	__isl_give isl_basic_set *isl_basic_set_read_from_str(
+		isl_ctx *ctx, const char *str);
+	__isl_give isl_set *isl_set_read_from_file(isl_ctx *ctx,
+		FILE *input);
+	__isl_give isl_set *isl_set_read_from_str(isl_ctx *ctx,
+		const char *str);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_map *isl_basic_map_read_from_file(
+		isl_ctx *ctx, FILE *input);
+	__isl_give isl_basic_map *isl_basic_map_read_from_str(
+		isl_ctx *ctx, const char *str);
+	__isl_give isl_map *isl_map_read_from_file(
+		isl_ctx *ctx, FILE *input);
+	__isl_give isl_map *isl_map_read_from_str(isl_ctx *ctx,
+		const char *str);
+
+	#include <isl/union_set.h>
+	__isl_give isl_union_set *isl_union_set_read_from_file(
+		isl_ctx *ctx, FILE *input);
+	__isl_give isl_union_set *isl_union_set_read_from_str(
+		isl_ctx *ctx, const char *str);
+
+	#include <isl/union_map.h>
+	__isl_give isl_union_map *isl_union_map_read_from_file(
+		isl_ctx *ctx, FILE *input);
+	__isl_give isl_union_map *isl_union_map_read_from_str(
+		isl_ctx *ctx, const char *str);
+
+	#include <isl/aff.h>
+	__isl_give isl_aff *isl_aff_read_from_str(
+		isl_ctx *ctx, const char *str);
+	__isl_give isl_multi_aff *isl_multi_aff_read_from_str(
+		isl_ctx *ctx, const char *str);
+	__isl_give isl_pw_aff *isl_pw_aff_read_from_str(
+		isl_ctx *ctx, const char *str);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_read_from_str(
+		isl_ctx *ctx, const char *str);
+	__isl_give isl_multi_pw_aff *isl_multi_pw_aff_read_from_str(
+		isl_ctx *ctx, const char *str);
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_read_from_str(
+		isl_ctx *ctx, const char *str);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_union_pw_qpolynomial *
+	isl_union_pw_qpolynomial_read_from_str(
+		isl_ctx *ctx, const char *str);
+
+For sets and relations,
+the input format is autodetected and may be either the C<PolyLib> format
+or the C<isl> format.
+
+=head3 Output
+
+Before anything can be printed, an C<isl_printer> needs to
+be created.
+
+	__isl_give isl_printer *isl_printer_to_file(isl_ctx *ctx,
+		FILE *file);
+	__isl_give isl_printer *isl_printer_to_str(isl_ctx *ctx);
+	__isl_null isl_printer *isl_printer_free(
+		__isl_take isl_printer *printer);
+	__isl_give char *isl_printer_get_str(
+		__isl_keep isl_printer *printer);
+
+The printer can be inspected using the following functions.
+
+	FILE *isl_printer_get_file(
+		__isl_keep isl_printer *printer);
+	int isl_printer_get_output_format(
+		__isl_keep isl_printer *p);
+
+The behavior of the printer can be modified in various ways
+
+	__isl_give isl_printer *isl_printer_set_output_format(
+		__isl_take isl_printer *p, int output_format);
+	__isl_give isl_printer *isl_printer_set_indent(
+		__isl_take isl_printer *p, int indent);
+	__isl_give isl_printer *isl_printer_set_indent_prefix(
+		__isl_take isl_printer *p, const char *prefix);
+	__isl_give isl_printer *isl_printer_indent(
+		__isl_take isl_printer *p, int indent);
+	__isl_give isl_printer *isl_printer_set_prefix(
+		__isl_take isl_printer *p, const char *prefix);
+	__isl_give isl_printer *isl_printer_set_suffix(
+		__isl_take isl_printer *p, const char *suffix);
+
+The C<output_format> may be either C<ISL_FORMAT_ISL>, C<ISL_FORMAT_OMEGA>,
+C<ISL_FORMAT_POLYLIB>, C<ISL_FORMAT_EXT_POLYLIB> or C<ISL_FORMAT_LATEX>
+and defaults to C<ISL_FORMAT_ISL>.
+Each line in the output is prefixed by C<indent_prefix>,
+indented by C<indent> (set by C<isl_printer_set_indent>) spaces
+(default: 0), prefixed by C<prefix> and suffixed by C<suffix>.
+In the C<PolyLib> format output,
+the coefficients of the existentially quantified variables
+appear between those of the set variables and those
+of the parameters.
+The function C<isl_printer_indent> increases the indentation
+by the specified amount (which may be negative).
+
+To actually print something, use
+
+	#include <isl/printer.h>
+	__isl_give isl_printer *isl_printer_print_double(
+		__isl_take isl_printer *p, double d);
+
+	#include <isl/val.h>
+	__isl_give isl_printer *isl_printer_print_val(
+		__isl_take isl_printer *p, __isl_keep isl_val *v);
+
+	#include <isl/set.h>
+	__isl_give isl_printer *isl_printer_print_basic_set(
+		__isl_take isl_printer *printer,
+		__isl_keep isl_basic_set *bset);
+	__isl_give isl_printer *isl_printer_print_set(
+		__isl_take isl_printer *printer,
+		__isl_keep isl_set *set);
+
+	#include <isl/map.h>
+	__isl_give isl_printer *isl_printer_print_basic_map(
+		__isl_take isl_printer *printer,
+		__isl_keep isl_basic_map *bmap);
+	__isl_give isl_printer *isl_printer_print_map(
+		__isl_take isl_printer *printer,
+		__isl_keep isl_map *map);
+
+	#include <isl/union_set.h>
+	__isl_give isl_printer *isl_printer_print_union_set(
+		__isl_take isl_printer *p,
+		__isl_keep isl_union_set *uset);
+
+	#include <isl/union_map.h>
+	__isl_give isl_printer *isl_printer_print_union_map(
+		__isl_take isl_printer *p,
+		__isl_keep isl_union_map *umap);
+
+	#include <isl/val.h>
+	__isl_give isl_printer *isl_printer_print_multi_val(
+		__isl_take isl_printer *p,
+		__isl_keep isl_multi_val *mv);
+
+	#include <isl/aff.h>
+	__isl_give isl_printer *isl_printer_print_aff(
+		__isl_take isl_printer *p, __isl_keep isl_aff *aff);
+	__isl_give isl_printer *isl_printer_print_multi_aff(
+		__isl_take isl_printer *p,
+		__isl_keep isl_multi_aff *maff);
+	__isl_give isl_printer *isl_printer_print_pw_aff(
+		__isl_take isl_printer *p,
+		__isl_keep isl_pw_aff *pwaff);
+	__isl_give isl_printer *isl_printer_print_pw_multi_aff(
+		__isl_take isl_printer *p,
+		__isl_keep isl_pw_multi_aff *pma);
+	__isl_give isl_printer *isl_printer_print_multi_pw_aff(
+		__isl_take isl_printer *p,
+		__isl_keep isl_multi_pw_aff *mpa);
+	__isl_give isl_printer *isl_printer_print_union_pw_multi_aff(
+		__isl_take isl_printer *p,
+		__isl_keep isl_union_pw_multi_aff *upma);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_printer *isl_printer_print_qpolynomial(
+		__isl_take isl_printer *p,
+		__isl_keep isl_qpolynomial *qp);
+	__isl_give isl_printer *isl_printer_print_pw_qpolynomial(
+		__isl_take isl_printer *p,
+		__isl_keep isl_pw_qpolynomial *pwqp);
+	__isl_give isl_printer *isl_printer_print_union_pw_qpolynomial(
+		__isl_take isl_printer *p,
+		__isl_keep isl_union_pw_qpolynomial *upwqp);
+
+	__isl_give isl_printer *
+	isl_printer_print_pw_qpolynomial_fold(
+		__isl_take isl_printer *p,
+		__isl_keep isl_pw_qpolynomial_fold *pwf);
+	__isl_give isl_printer *
+	isl_printer_print_union_pw_qpolynomial_fold(
+		__isl_take isl_printer *p,
+		__isl_keep isl_union_pw_qpolynomial_fold *upwf);
+
+For C<isl_printer_print_qpolynomial>,
+C<isl_printer_print_pw_qpolynomial> and
+C<isl_printer_print_pw_qpolynomial_fold>,
+the output format of the printer
+needs to be set to either C<ISL_FORMAT_ISL> or C<ISL_FORMAT_C>.
+For C<isl_printer_print_union_pw_qpolynomial> and
+C<isl_printer_print_union_pw_qpolynomial_fold>, only C<ISL_FORMAT_ISL>
+is supported.
+In case of printing in C<ISL_FORMAT_C>, the user may want
+to set the names of all dimensions first.
+
+When called on a file printer, the following function flushes
+the file.  When called on a string printer, the buffer is cleared.
+
+	__isl_give isl_printer *isl_printer_flush(
+		__isl_take isl_printer *p);
+
+Alternatively, a string representation can be obtained
+directly using the following functions, which always print
+in isl format.
+
+	#include <isl/space.h>
+	__isl_give char *isl_space_to_str(
+		__isl_keep isl_space *space);
+
+	#include <isl/val.h>
+	__isl_give char *isl_val_to_str(__isl_keep isl_val *v);
+	__isl_give char *isl_multi_val_to_str(
+		__isl_keep isl_multi_val *mv);
+
+	#include <isl/set.h>
+	__isl_give char *isl_set_to_str(
+		__isl_keep isl_set *set);
+
+	#include <isl/union_set.h>
+	__isl_give char *isl_union_set_to_str(
+		__isl_keep isl_union_set *uset);
+
+	#include <isl/map.h>
+	__isl_give char *isl_map_to_str(
+		__isl_keep isl_map *map);
+
+	#include <isl/union_map.h>
+	__isl_give char *isl_union_map_to_str(
+		__isl_keep isl_union_map *umap);
+
+	#include <isl/aff.h>
+	__isl_give char *isl_multi_aff_to_str(
+		__isl_keep isl_multi_aff *aff);
+	__isl_give char *isl_union_pw_multi_aff_to_str(
+		__isl_keep isl_union_pw_multi_aff *upma);
+
+=head2 Properties
+
+=head3 Unary Properties
+
+=over
+
+=item * Emptiness
+
+The following functions test whether the given set or relation
+contains any integer points.  The ``plain'' variants do not perform
+any computations, but simply check if the given set or relation
+is already known to be empty.
+
+	int isl_basic_set_plain_is_empty(__isl_keep isl_basic_set *bset);
+	int isl_basic_set_is_empty(__isl_keep isl_basic_set *bset);
+	int isl_set_plain_is_empty(__isl_keep isl_set *set);
+	int isl_set_is_empty(__isl_keep isl_set *set);
+	int isl_union_set_is_empty(__isl_keep isl_union_set *uset);
+	int isl_basic_map_plain_is_empty(__isl_keep isl_basic_map *bmap);
+	int isl_basic_map_is_empty(__isl_keep isl_basic_map *bmap);
+	int isl_map_plain_is_empty(__isl_keep isl_map *map);
+	int isl_map_is_empty(__isl_keep isl_map *map);
+	int isl_union_map_is_empty(__isl_keep isl_union_map *umap);
+
+=item * Universality
+
+	int isl_basic_set_is_universe(__isl_keep isl_basic_set *bset);
+	int isl_basic_map_is_universe(__isl_keep isl_basic_map *bmap);
+	int isl_set_plain_is_universe(__isl_keep isl_set *set);
+
+=item * Single-valuedness
+
+	#include <isl/set.h>
+	int isl_set_is_singleton(__isl_keep isl_set *set);
+
+	#include <isl/map.h>
+	int isl_basic_map_is_single_valued(
+		__isl_keep isl_basic_map *bmap);
+	int isl_map_plain_is_single_valued(
+		__isl_keep isl_map *map);
+	int isl_map_is_single_valued(__isl_keep isl_map *map);
+
+	#include <isl/union_map.h>
+	int isl_union_map_is_single_valued(__isl_keep isl_union_map *umap);
+
+=item * Injectivity
+
+	int isl_map_plain_is_injective(__isl_keep isl_map *map);
+	int isl_map_is_injective(__isl_keep isl_map *map);
+	int isl_union_map_plain_is_injective(
+		__isl_keep isl_union_map *umap);
+	int isl_union_map_is_injective(
+		__isl_keep isl_union_map *umap);
+
+=item * Bijectivity
+
+	int isl_map_is_bijective(__isl_keep isl_map *map);
+	int isl_union_map_is_bijective(__isl_keep isl_union_map *umap);
+
+=item * Position
+
+	__isl_give isl_val *
+	isl_basic_map_plain_get_val_if_fixed(
+		__isl_keep isl_basic_map *bmap,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_val *isl_set_plain_get_val_if_fixed(
+		__isl_keep isl_set *set,
+		enum isl_dim_type type, unsigned pos);
+	__isl_give isl_val *isl_map_plain_get_val_if_fixed(
+		__isl_keep isl_map *map,
+		enum isl_dim_type type, unsigned pos);
+
+If the set or relation obviously lies on a hyperplane where the given dimension
+has a fixed value, then return that value.
+Otherwise return NaN.
+
+=item * Stride
+
+	int isl_set_dim_residue_class_val(
+		__isl_keep isl_set *set,
+		int pos, __isl_give isl_val **modulo,
+		__isl_give isl_val **residue);
+
+Check if the values of the given set dimension are equal to a fixed
+value modulo some integer value.  If so, assign the modulo to C<*modulo>
+and the fixed value to C<*residue>.  If the given dimension attains only
+a single value, then assign C<0> to C<*modulo> and the fixed value to
+C<*residue>.
+If the dimension does not attain only a single value and if no modulo
+can be found then assign C<1> to C<*modulo> and C<1> to C<*residue>.
+
+=item * Dependence
+
+To check whether the description of a set, relation or function depends
+on one or more given dimensions,
+the following functions can be used.
+
+	#include <isl/constraint.h>
+	int isl_constraint_involves_dims(
+		__isl_keep isl_constraint *constraint,
+		enum isl_dim_type type, unsigned first, unsigned n);
+
+	#include <isl/set.h>
+	int isl_basic_set_involves_dims(
+		__isl_keep isl_basic_set *bset,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	int isl_set_involves_dims(__isl_keep isl_set *set,
+		enum isl_dim_type type, unsigned first, unsigned n);
+
+	#include <isl/map.h>
+	int isl_basic_map_involves_dims(
+		__isl_keep isl_basic_map *bmap,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	int isl_map_involves_dims(__isl_keep isl_map *map,
+		enum isl_dim_type type, unsigned first, unsigned n);
+
+	#include <isl/union_map.h>
+	int isl_union_map_involves_dims(
+		__isl_keep isl_union_map *umap,
+		enum isl_dim_type type, unsigned first, unsigned n);
+
+	#include <isl/aff.h>
+	int isl_aff_involves_dims(__isl_keep isl_aff *aff,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	int isl_pw_aff_involves_dims(__isl_keep isl_pw_aff *pwaff,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	int isl_multi_aff_involves_dims(
+		__isl_keep isl_multi_aff *ma,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	int isl_multi_pw_aff_involves_dims(
+		__isl_keep isl_multi_pw_aff *mpa,
+		enum isl_dim_type type, unsigned first, unsigned n);
+
+Similarly, the following functions can be used to check whether
+a given dimension is involved in any lower or upper bound.
+
+	#include <isl/set.h>
+	int isl_set_dim_has_any_lower_bound(__isl_keep isl_set *set,
+		enum isl_dim_type type, unsigned pos);
+	int isl_set_dim_has_any_upper_bound(__isl_keep isl_set *set,
+		enum isl_dim_type type, unsigned pos);
+
+Note that these functions return true even if there is a bound on
+the dimension on only some of the basic sets of C<set>.
+To check if they have a bound for all of the basic sets in C<set>,
+use the following functions instead.
+
+	#include <isl/set.h>
+	int isl_set_dim_has_lower_bound(__isl_keep isl_set *set,
+		enum isl_dim_type type, unsigned pos);
+	int isl_set_dim_has_upper_bound(__isl_keep isl_set *set,
+		enum isl_dim_type type, unsigned pos);
+
+=item * Space
+
+To check whether a set is a parameter domain, use this function:
+
+	int isl_set_is_params(__isl_keep isl_set *set);
+	int isl_union_set_is_params(
+		__isl_keep isl_union_set *uset);
+
+=item * Wrapping
+
+The following functions check whether the space of the given
+(basic) set or relation range is a wrapped relation.
+
+	#include <isl/space.h>
+	int isl_space_is_wrapping(
+		__isl_keep isl_space *space);
+	int isl_space_domain_is_wrapping(
+		__isl_keep isl_space *space);
+	int isl_space_range_is_wrapping(
+		__isl_keep isl_space *space);
+
+	#include <isl/set.h>
+	int isl_basic_set_is_wrapping(
+		__isl_keep isl_basic_set *bset);
+	int isl_set_is_wrapping(__isl_keep isl_set *set);
+
+	#include <isl/map.h>
+	int isl_map_domain_is_wrapping(
+		__isl_keep isl_map *map);
+	int isl_map_range_is_wrapping(
+		__isl_keep isl_map *map);
+
+	#include <isl/val.h>
+	int isl_multi_val_range_is_wrapping(
+		__isl_keep isl_multi_val *mv);
+
+	#include <isl/aff.h>
+	int isl_multi_aff_range_is_wrapping(
+		__isl_keep isl_multi_aff *ma);
+	int isl_multi_pw_aff_range_is_wrapping(
+		__isl_keep isl_multi_pw_aff *mpa);
+
+The input to C<isl_space_is_wrapping> should
+be the space of a set, while that of
+C<isl_space_domain_is_wrapping> and
+C<isl_space_range_is_wrapping> should be the space of a relation.
+
+=item * Internal Product
+
+	int isl_basic_map_can_zip(
+		__isl_keep isl_basic_map *bmap);
+	int isl_map_can_zip(__isl_keep isl_map *map);
+
+Check whether the product of domain and range of the given relation
+can be computed,
+i.e., whether both domain and range are nested relations.
+
+=item * Currying
+
+	int isl_basic_map_can_curry(
+		__isl_keep isl_basic_map *bmap);
+	int isl_map_can_curry(__isl_keep isl_map *map);
+
+Check whether the domain of the (basic) relation is a wrapped relation.
+
+	int isl_basic_map_can_uncurry(
+		__isl_keep isl_basic_map *bmap);
+	int isl_map_can_uncurry(__isl_keep isl_map *map);
+
+Check whether the range of the (basic) relation is a wrapped relation.
+
+=item * Special Values
+
+	#include <isl/aff.h>
+	int isl_aff_is_cst(__isl_keep isl_aff *aff);
+	int isl_pw_aff_is_cst(__isl_keep isl_pw_aff *pwaff);
+
+Check whether the given expression is a constant.
+
+	#include <isl/aff.h>
+	int isl_aff_is_nan(__isl_keep isl_aff *aff);
+	int isl_pw_aff_involves_nan(__isl_keep isl_pw_aff *pa);
+
+Check whether the given expression is equal to or involves NaN.
+
+	#include <isl/aff.h>
+	int isl_aff_plain_is_zero(__isl_keep isl_aff *aff);
+
+Check whether the affine expression is obviously zero.
+
+=back
+
+=head3 Binary Properties
+
+=over
+
+=item * Equality
+
+The following functions check whether two objects
+represent the same set, relation or function.
+The C<plain> variants only return true if the objects
+are obviously the same.  That is, they may return false
+even if the objects are the same, but they will never
+return true if the objects are not the same.
+
+	#include <isl/set.h>
+	int isl_basic_set_plain_is_equal(
+		__isl_keep isl_basic_set *bset1,
+		__isl_keep isl_basic_set *bset2);
+	int isl_set_plain_is_equal(__isl_keep isl_set *set1,
+		__isl_keep isl_set *set2);
+	int isl_set_is_equal(__isl_keep isl_set *set1,
+		__isl_keep isl_set *set2);
+
+	#include <isl/map.h>
+	int isl_basic_map_is_equal(
+		__isl_keep isl_basic_map *bmap1,
+		__isl_keep isl_basic_map *bmap2);
+	int isl_map_is_equal(__isl_keep isl_map *map1,
+		__isl_keep isl_map *map2);
+	int isl_map_plain_is_equal(__isl_keep isl_map *map1,
+		__isl_keep isl_map *map2);
+
+	#include <isl/union_set.h>
+	int isl_union_set_is_equal(
+		__isl_keep isl_union_set *uset1,
+		__isl_keep isl_union_set *uset2);
+
+	#include <isl/union_map.h>
+	int isl_union_map_is_equal(
+		__isl_keep isl_union_map *umap1,
+		__isl_keep isl_union_map *umap2);
+
+	#include <isl/aff.h>
+	int isl_aff_plain_is_equal(__isl_keep isl_aff *aff1,
+		__isl_keep isl_aff *aff2);
+	int isl_multi_aff_plain_is_equal(
+		__isl_keep isl_multi_aff *maff1,
+		__isl_keep isl_multi_aff *maff2);
+	int isl_pw_aff_plain_is_equal(
+		__isl_keep isl_pw_aff *pwaff1,
+		__isl_keep isl_pw_aff *pwaff2);
+	int isl_pw_multi_aff_plain_is_equal(
+		__isl_keep isl_pw_multi_aff *pma1,
+		__isl_keep isl_pw_multi_aff *pma2);
+	int isl_multi_pw_aff_plain_is_equal(
+		__isl_keep isl_multi_pw_aff *mpa1,
+		__isl_keep isl_multi_pw_aff *mpa2);
+	int isl_multi_pw_aff_is_equal(
+		__isl_keep isl_multi_pw_aff *mpa1,
+		__isl_keep isl_multi_pw_aff *mpa2);
+	int isl_union_pw_multi_aff_plain_is_equal(
+		__isl_keep isl_union_pw_multi_aff *upma1,
+		__isl_keep isl_union_pw_multi_aff *upma2);
+
+	#include <isl/polynomial.h>
+	int isl_union_pw_qpolynomial_plain_is_equal(
+		__isl_keep isl_union_pw_qpolynomial *upwqp1,
+		__isl_keep isl_union_pw_qpolynomial *upwqp2);
+	int isl_union_pw_qpolynomial_fold_plain_is_equal(
+		__isl_keep isl_union_pw_qpolynomial_fold *upwf1,
+		__isl_keep isl_union_pw_qpolynomial_fold *upwf2);
+
+=item * Disjointness
+
+	int isl_basic_set_is_disjoint(
+		__isl_keep isl_basic_set *bset1,
+		__isl_keep isl_basic_set *bset2);
+	int isl_set_plain_is_disjoint(__isl_keep isl_set *set1,
+		__isl_keep isl_set *set2);
+	int isl_set_is_disjoint(__isl_keep isl_set *set1,
+		__isl_keep isl_set *set2);
+	int isl_basic_map_is_disjoint(
+		__isl_keep isl_basic_map *bmap1,
+		__isl_keep isl_basic_map *bmap2);
+	int isl_map_is_disjoint(__isl_keep isl_map *map1,
+		__isl_keep isl_map *map2);
+
+=item * Subset
+
+	int isl_basic_set_is_subset(
+		__isl_keep isl_basic_set *bset1,
+		__isl_keep isl_basic_set *bset2);
+	int isl_set_is_subset(__isl_keep isl_set *set1,
+		__isl_keep isl_set *set2);
+	int isl_set_is_strict_subset(
+		__isl_keep isl_set *set1,
+		__isl_keep isl_set *set2);
+	int isl_union_set_is_subset(
+		__isl_keep isl_union_set *uset1,
+		__isl_keep isl_union_set *uset2);
+	int isl_union_set_is_strict_subset(
+		__isl_keep isl_union_set *uset1,
+		__isl_keep isl_union_set *uset2);
+	int isl_basic_map_is_subset(
+		__isl_keep isl_basic_map *bmap1,
+		__isl_keep isl_basic_map *bmap2);
+	int isl_basic_map_is_strict_subset(
+		__isl_keep isl_basic_map *bmap1,
+		__isl_keep isl_basic_map *bmap2);
+	int isl_map_is_subset(
+		__isl_keep isl_map *map1,
+		__isl_keep isl_map *map2);
+	int isl_map_is_strict_subset(
+		__isl_keep isl_map *map1,
+		__isl_keep isl_map *map2);
+	int isl_union_map_is_subset(
+		__isl_keep isl_union_map *umap1,
+		__isl_keep isl_union_map *umap2);
+	int isl_union_map_is_strict_subset(
+		__isl_keep isl_union_map *umap1,
+		__isl_keep isl_union_map *umap2);
+
+Check whether the first argument is a (strict) subset of the
+second argument.
+
+=item * Order
+
+Every comparison function returns a negative value if the first
+argument is considered smaller than the second, a positive value
+if the first argument is considered greater and zero if the two
+constraints are considered the same by the comparison criterion.
+
+	#include <isl/constraint.h>
+	int isl_constraint_plain_cmp(
+		__isl_keep isl_constraint *c1,
+		__isl_keep isl_constraint *c2);
+
+This function is useful for sorting C<isl_constraint>s.
+The order depends on the internal representation of the inputs.
+The order is fixed over different calls to the function (assuming
+the internal representation of the inputs has not changed), but may
+change over different versions of C<isl>.
+
+	#include <isl/constraint.h>
+	int isl_constraint_cmp_last_non_zero(
+		__isl_keep isl_constraint *c1,
+		__isl_keep isl_constraint *c2);
+
+This function can be used to sort constraints that live in the same
+local space.  Constraints that involve ``earlier'' dimensions or
+that have a smaller coefficient for the shared latest dimension
+are considered smaller than other constraints.
+This function only defines a B<partial> order.
+
+	#include <isl/set.h>
+	int isl_set_plain_cmp(__isl_keep isl_set *set1,
+		__isl_keep isl_set *set2);
+
+This function is useful for sorting C<isl_set>s.
+The order depends on the internal representation of the inputs.
+The order is fixed over different calls to the function (assuming
+the internal representation of the inputs has not changed), but may
+change over different versions of C<isl>.
+
+	#include <isl/aff.h>
+	int isl_pw_aff_plain_cmp(__isl_keep isl_pw_aff *pa1,
+		__isl_keep isl_pw_aff *pa2);
+
+The function C<isl_pw_aff_plain_cmp> can be used to sort
+C<isl_pw_aff>s.  The order is not strictly defined.
+The current order sorts expressions that only involve
+earlier dimensions before those that involve later dimensions.
+
+=back
+
+=head2 Unary Operations
+
+=over
+
+=item * Complement
+
+	__isl_give isl_set *isl_set_complement(
+		__isl_take isl_set *set);
+	__isl_give isl_map *isl_map_complement(
+		__isl_take isl_map *map);
+
+=item * Inverse map
+
+	#include <isl/space.h>
+	__isl_give isl_space *isl_space_reverse(
+		__isl_take isl_space *space);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_map *isl_basic_map_reverse(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_map *isl_map_reverse(
+		__isl_take isl_map *map);
+
+	#include <isl/union_map.h>
+	__isl_give isl_union_map *isl_union_map_reverse(
+		__isl_take isl_union_map *umap);
+
+=item * Projection
+
+	#include <isl/space.h>
+	__isl_give isl_space *isl_space_domain(
+		__isl_take isl_space *space);
+	__isl_give isl_space *isl_space_range(
+		__isl_take isl_space *space);
+	__isl_give isl_space *isl_space_params(
+		__isl_take isl_space *space);
+
+	#include <isl/local_space.h>
+	__isl_give isl_local_space *isl_local_space_domain(
+		__isl_take isl_local_space *ls);
+	__isl_give isl_local_space *isl_local_space_range(
+		__isl_take isl_local_space *ls);
+
+	#include <isl/set.h>
+	__isl_give isl_basic_set *isl_basic_set_project_out(
+		__isl_take isl_basic_set *bset,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	__isl_give isl_set *isl_set_project_out(__isl_take isl_set *set,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	__isl_give isl_basic_set *isl_basic_set_params(
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_set *isl_set_params(__isl_take isl_set *set);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_map *isl_basic_map_project_out(
+		__isl_take isl_basic_map *bmap,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	__isl_give isl_map *isl_map_project_out(__isl_take isl_map *map,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	__isl_give isl_basic_set *isl_basic_map_domain(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_basic_set *isl_basic_map_range(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_set *isl_map_params(__isl_take isl_map *map);
+	__isl_give isl_set *isl_map_domain(
+		__isl_take isl_map *bmap);
+	__isl_give isl_set *isl_map_range(
+		__isl_take isl_map *map);
+
+	#include <isl/union_set.h>
+	__isl_give isl_set *isl_union_set_params(
+		__isl_take isl_union_set *uset);
+
+	#include <isl/union_map.h>
+	__isl_give isl_union_map *isl_union_map_project_out(
+		__isl_take isl_union_map *umap,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	__isl_give isl_set *isl_union_map_params(
+		__isl_take isl_union_map *umap);
+	__isl_give isl_union_set *isl_union_map_domain(
+		__isl_take isl_union_map *umap);
+	__isl_give isl_union_set *isl_union_map_range(
+		__isl_take isl_union_map *umap);
+
+The function C<isl_union_map_project_out> can only project out
+parameters.
+
+	#include <isl/aff.h>
+	__isl_give isl_aff *isl_aff_project_domain_on_params(
+		__isl_take isl_aff *aff);
+	__isl_give isl_pw_multi_aff *
+	isl_pw_multi_aff_project_domain_on_params(
+		__isl_take isl_pw_multi_aff *pma);
+	__isl_give isl_set *isl_pw_aff_domain(
+		__isl_take isl_pw_aff *pwaff);
+	__isl_give isl_set *isl_pw_multi_aff_domain(
+		__isl_take isl_pw_multi_aff *pma);
+	__isl_give isl_set *isl_multi_pw_aff_domain(
+		__isl_take isl_multi_pw_aff *mpa);
+	__isl_give isl_union_set *isl_union_pw_multi_aff_domain(
+		__isl_take isl_union_pw_multi_aff *upma);
+	__isl_give isl_set *isl_pw_aff_params(
+		__isl_take isl_pw_aff *pwa);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_qpolynomial *
+	isl_qpolynomial_project_domain_on_params(
+		__isl_take isl_qpolynomial *qp);
+	__isl_give isl_pw_qpolynomial *
+	isl_pw_qpolynomial_project_domain_on_params(
+		__isl_take isl_pw_qpolynomial *pwqp);
+	__isl_give isl_pw_qpolynomial_fold *
+	isl_pw_qpolynomial_fold_project_domain_on_params(
+		__isl_take isl_pw_qpolynomial_fold *pwf);
+	__isl_give isl_set *isl_pw_qpolynomial_domain(
+		__isl_take isl_pw_qpolynomial *pwqp);
+	__isl_give isl_union_set *isl_union_pw_qpolynomial_fold_domain(
+		__isl_take isl_union_pw_qpolynomial_fold *upwf);
+	__isl_give isl_union_set *isl_union_pw_qpolynomial_domain(
+		__isl_take isl_union_pw_qpolynomial *upwqp);
+
+	#include <isl/space.h>
+	__isl_give isl_space *isl_space_domain_map(
+		__isl_take isl_space *space);
+	__isl_give isl_space *isl_space_range_map(
+		__isl_take isl_space *space);
+
+	#include <isl/map.h>
+	__isl_give isl_map *isl_set_wrapped_domain_map(
+		__isl_take isl_set *set);
+	__isl_give isl_basic_map *isl_basic_map_domain_map(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_basic_map *isl_basic_map_range_map(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_map *isl_map_domain_map(__isl_take isl_map *map);
+	__isl_give isl_map *isl_map_range_map(__isl_take isl_map *map);
+
+	#include <isl/union_map.h>
+	__isl_give isl_union_map *isl_union_map_domain_map(
+		__isl_take isl_union_map *umap);
+	__isl_give isl_union_map *isl_union_map_range_map(
+		__isl_take isl_union_map *umap);
+	__isl_give isl_union_map *
+	isl_union_set_wrapped_domain_map(
+		__isl_take isl_union_set *uset);
+
+The functions above construct a (basic, regular or union) relation
+that maps (a wrapped version of) the input relation to its domain or range.
+C<isl_set_wrapped_domain_map> maps the input set to the domain
+of its wrapped relation.
+
+=item * Elimination
+
+	__isl_give isl_basic_set *isl_basic_set_eliminate(
+		__isl_take isl_basic_set *bset,
+		enum isl_dim_type type,
+		unsigned first, unsigned n);
+	__isl_give isl_set *isl_set_eliminate(
+		__isl_take isl_set *set, enum isl_dim_type type,
+		unsigned first, unsigned n);
+	__isl_give isl_basic_map *isl_basic_map_eliminate(
+		__isl_take isl_basic_map *bmap,
+		enum isl_dim_type type,
+		unsigned first, unsigned n);
+	__isl_give isl_map *isl_map_eliminate(
+		__isl_take isl_map *map, enum isl_dim_type type,
+		unsigned first, unsigned n);
+
+Eliminate the coefficients for the given dimensions from the constraints,
+without removing the dimensions.
+
+=item * Constructing a set from a parameter domain
+
+A zero-dimensional space or (basic) set can be constructed
+on a given parameter domain using the following functions.
+
+	#include <isl/space.h>
+	__isl_give isl_space *isl_space_set_from_params(
+		__isl_take isl_space *space);
+
+	#include <isl/set.h>
+	__isl_give isl_basic_set *isl_basic_set_from_params(
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_set *isl_set_from_params(
+		__isl_take isl_set *set);
+
+=item * Constructing a relation from a set
+
+Create a relation with the given set as domain or range.
+The range or domain of the created relation is a zero-dimensional
+flat anonymous space.
+
+	#include <isl/space.h>
+	__isl_give isl_space *isl_space_from_domain(
+		__isl_take isl_space *space);
+	__isl_give isl_space *isl_space_from_range(
+		__isl_take isl_space *space);
+	__isl_give isl_space *isl_space_map_from_set(
+		__isl_take isl_space *space);
+	__isl_give isl_space *isl_space_map_from_domain_and_range(
+		__isl_take isl_space *domain,
+		__isl_take isl_space *range);
+
+	#include <isl/local_space.h>
+	__isl_give isl_local_space *isl_local_space_from_domain(
+		__isl_take isl_local_space *ls);
+
+	#include <isl/map.h>
+	__isl_give isl_map *isl_map_from_domain(
+		__isl_take isl_set *set);
+	__isl_give isl_map *isl_map_from_range(
+		__isl_take isl_set *set);
+
+	#include <isl/val.h>
+	__isl_give isl_multi_val *isl_multi_val_from_range(
+		__isl_take isl_multi_val *mv);
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_aff *isl_multi_aff_from_range(
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_pw_aff *isl_pw_aff_from_range(
+		__isl_take isl_pw_aff *pwa);
+	__isl_give isl_multi_pw_aff *isl_multi_pw_aff_from_range(
+		__isl_take isl_multi_pw_aff *mpa);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_domain(
+		__isl_take isl_set *set);
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_from_domain(
+		__isl_take isl_union_set *uset);
+
+=item * Slicing
+
+	#include <isl/set.h>
+	__isl_give isl_basic_set *isl_basic_set_fix_si(
+		__isl_take isl_basic_set *bset,
+		enum isl_dim_type type, unsigned pos, int value);
+	__isl_give isl_basic_set *isl_basic_set_fix_val(
+		__isl_take isl_basic_set *bset,
+		enum isl_dim_type type, unsigned pos,
+		__isl_take isl_val *v);
+	__isl_give isl_set *isl_set_fix_si(__isl_take isl_set *set,
+		enum isl_dim_type type, unsigned pos, int value);
+	__isl_give isl_set *isl_set_fix_val(
+		__isl_take isl_set *set,
+		enum isl_dim_type type, unsigned pos,
+		__isl_take isl_val *v);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_map *isl_basic_map_fix_si(
+		__isl_take isl_basic_map *bmap,
+		enum isl_dim_type type, unsigned pos, int value);
+	__isl_give isl_basic_map *isl_basic_map_fix_val(
+		__isl_take isl_basic_map *bmap,
+		enum isl_dim_type type, unsigned pos,
+		__isl_take isl_val *v);
+	__isl_give isl_map *isl_map_fix_si(__isl_take isl_map *map,
+		enum isl_dim_type type, unsigned pos, int value);
+	__isl_give isl_map *isl_map_fix_val(
+		__isl_take isl_map *map,
+		enum isl_dim_type type, unsigned pos,
+		__isl_take isl_val *v);
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_fix_si(
+		__isl_take isl_pw_multi_aff *pma,
+		enum isl_dim_type type, unsigned pos, int value);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_fix_val(
+		__isl_take isl_pw_qpolynomial *pwqp,
+		enum isl_dim_type type, unsigned n,
+		__isl_take isl_val *v);
+
+Intersect the set, relation or function domain
+with the hyperplane where the given
+dimension has the fixed given value.
+
+	__isl_give isl_basic_map *isl_basic_map_lower_bound_si(
+		__isl_take isl_basic_map *bmap,
+		enum isl_dim_type type, unsigned pos, int value);
+	__isl_give isl_basic_map *isl_basic_map_upper_bound_si(
+		__isl_take isl_basic_map *bmap,
+		enum isl_dim_type type, unsigned pos, int value);
+	__isl_give isl_set *isl_set_lower_bound_si(
+		__isl_take isl_set *set,
+		enum isl_dim_type type, unsigned pos, int value);
+	__isl_give isl_set *isl_set_lower_bound_val(
+		__isl_take isl_set *set,
+		enum isl_dim_type type, unsigned pos,
+		__isl_take isl_val *value);
+	__isl_give isl_map *isl_map_lower_bound_si(
+		__isl_take isl_map *map,
+		enum isl_dim_type type, unsigned pos, int value);
+	__isl_give isl_set *isl_set_upper_bound_si(
+		__isl_take isl_set *set,
+		enum isl_dim_type type, unsigned pos, int value);
+	__isl_give isl_set *isl_set_upper_bound_val(
+		__isl_take isl_set *set,
+		enum isl_dim_type type, unsigned pos,
+		__isl_take isl_val *value);
+	__isl_give isl_map *isl_map_upper_bound_si(
+		__isl_take isl_map *map,
+		enum isl_dim_type type, unsigned pos, int value);
+
+Intersect the set or relation with the half-space where the given
+dimension has a value bounded by the fixed given integer value.
+
+	__isl_give isl_set *isl_set_equate(__isl_take isl_set *set,
+		enum isl_dim_type type1, int pos1,
+		enum isl_dim_type type2, int pos2);
+	__isl_give isl_basic_map *isl_basic_map_equate(
+		__isl_take isl_basic_map *bmap,
+		enum isl_dim_type type1, int pos1,
+		enum isl_dim_type type2, int pos2);
+	__isl_give isl_map *isl_map_equate(__isl_take isl_map *map,
+		enum isl_dim_type type1, int pos1,
+		enum isl_dim_type type2, int pos2);
+
+Intersect the set or relation with the hyperplane where the given
+dimensions are equal to each other.
+
+	__isl_give isl_map *isl_map_oppose(__isl_take isl_map *map,
+		enum isl_dim_type type1, int pos1,
+		enum isl_dim_type type2, int pos2);
+
+Intersect the relation with the hyperplane where the given
+dimensions have opposite values.
+
+	__isl_give isl_map *isl_map_order_le(
+		__isl_take isl_map *map,
+		enum isl_dim_type type1, int pos1,
+		enum isl_dim_type type2, int pos2);
+	__isl_give isl_basic_map *isl_basic_map_order_ge(
+		__isl_take isl_basic_map *bmap,
+		enum isl_dim_type type1, int pos1,
+		enum isl_dim_type type2, int pos2);
+	__isl_give isl_map *isl_map_order_ge(
+		__isl_take isl_map *map,
+		enum isl_dim_type type1, int pos1,
+		enum isl_dim_type type2, int pos2);
+	__isl_give isl_map *isl_map_order_lt(__isl_take isl_map *map,
+		enum isl_dim_type type1, int pos1,
+		enum isl_dim_type type2, int pos2);
+	__isl_give isl_basic_map *isl_basic_map_order_gt(
+		__isl_take isl_basic_map *bmap,
+		enum isl_dim_type type1, int pos1,
+		enum isl_dim_type type2, int pos2);
+	__isl_give isl_map *isl_map_order_gt(__isl_take isl_map *map,
+		enum isl_dim_type type1, int pos1,
+		enum isl_dim_type type2, int pos2);
+
+Intersect the relation with the half-space where the given
+dimensions satisfy the given ordering.
+
+=item * Locus
+
+	#include <isl/aff.h>
+	__isl_give isl_basic_set *isl_aff_zero_basic_set(
+		__isl_take isl_aff *aff);
+	__isl_give isl_basic_set *isl_aff_neg_basic_set(
+		__isl_take isl_aff *aff);
+	__isl_give isl_set *isl_pw_aff_nonneg_set(
+		__isl_take isl_pw_aff *pwaff);
+	__isl_give isl_set *isl_pw_aff_zero_set(
+		__isl_take isl_pw_aff *pwaff);
+	__isl_give isl_set *isl_pw_aff_non_zero_set(
+		__isl_take isl_pw_aff *pwaff);
+
+The function C<isl_aff_neg_basic_set> returns a basic set
+containing those elements in the domain space
+of C<aff> where C<aff> is negative.
+The function C<isl_pw_aff_nonneg_set> returns a set
+containing those elements in the domain
+of C<pwaff> where C<pwaff> is non-negative.
+
+=item * Identity
+
+	__isl_give isl_map *isl_set_identity(
+		__isl_take isl_set *set);
+	__isl_give isl_union_map *isl_union_set_identity(
+		__isl_take isl_union_set *uset);
+
+Construct an identity relation on the given (union) set.
+
+=item * Function Extraction
+
+A piecewise quasi affine expression that is equal to 1 on a set
+and 0 outside the set can be created using the following function.
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_aff *isl_set_indicator_function(
+		__isl_take isl_set *set);
+
+A piecewise multiple quasi affine expression can be extracted
+from an C<isl_set> or C<isl_map>, provided the C<isl_set> is a singleton
+and the C<isl_map> is single-valued.
+In case of a conversion from an C<isl_union_map>
+to an C<isl_union_pw_multi_aff>, these properties need to hold
+in each domain space.
+
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_set(
+		__isl_take isl_set *set);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_map(
+		__isl_take isl_map *map);
+
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_from_union_set(
+		__isl_take isl_union_set *uset);
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_from_union_map(
+		__isl_take isl_union_map *umap);
+
+=item * Deltas
+
+	__isl_give isl_basic_set *isl_basic_map_deltas(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_set *isl_map_deltas(__isl_take isl_map *map);
+	__isl_give isl_union_set *isl_union_map_deltas(
+		__isl_take isl_union_map *umap);
+
+These functions return a (basic) set containing the differences
+between image elements and corresponding domain elements in the input.
+
+	__isl_give isl_basic_map *isl_basic_map_deltas_map(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_map *isl_map_deltas_map(
+		__isl_take isl_map *map);
+	__isl_give isl_union_map *isl_union_map_deltas_map(
+		__isl_take isl_union_map *umap);
+
+The functions above construct a (basic, regular or union) relation
+that maps (a wrapped version of) the input relation to its delta set.
+
+=item * Coalescing
+
+Simplify the representation of a set, relation or functions by trying
+to combine pairs of basic sets or relations into a single
+basic set or relation.
+
+	#include <isl/set.h>
+	__isl_give isl_set *isl_set_coalesce(__isl_take isl_set *set);
+
+	#include <isl/map.h>
+	__isl_give isl_map *isl_map_coalesce(__isl_take isl_map *map);
+
+	#include <isl/union_set.h>
+	__isl_give isl_union_set *isl_union_set_coalesce(
+		__isl_take isl_union_set *uset);
+
+	#include <isl/union_map.h>
+	__isl_give isl_union_map *isl_union_map_coalesce(
+		__isl_take isl_union_map *umap);
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_aff *isl_pw_aff_coalesce(
+		__isl_take isl_pw_aff *pwqp);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_coalesce(
+		__isl_take isl_pw_multi_aff *pma);
+	__isl_give isl_multi_pw_aff *isl_multi_pw_aff_coalesce(
+		__isl_take isl_multi_pw_aff *mpa);
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_coalesce(
+		__isl_take isl_union_pw_multi_aff *upma);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_pw_qpolynomial_fold *
+	isl_pw_qpolynomial_fold_coalesce(
+		__isl_take isl_pw_qpolynomial_fold *pwf);
+	__isl_give isl_union_pw_qpolynomial *
+	isl_union_pw_qpolynomial_coalesce(
+		__isl_take isl_union_pw_qpolynomial *upwqp);
+	__isl_give isl_union_pw_qpolynomial_fold *
+	isl_union_pw_qpolynomial_fold_coalesce(
+		__isl_take isl_union_pw_qpolynomial_fold *upwf);
+
+One of the methods for combining pairs of basic sets or relations
+can result in coefficients that are much larger than those that appear
+in the constraints of the input.  By default, the coefficients are
+not allowed to grow larger, but this can be changed by unsetting
+the following option.
+
+	int isl_options_set_coalesce_bounded_wrapping(
+		isl_ctx *ctx, int val);
+	int isl_options_get_coalesce_bounded_wrapping(
+		isl_ctx *ctx);
+
+=item * Detecting equalities
+
+	__isl_give isl_basic_set *isl_basic_set_detect_equalities(
+                __isl_take isl_basic_set *bset);
+	__isl_give isl_basic_map *isl_basic_map_detect_equalities(
+                __isl_take isl_basic_map *bmap);
+	__isl_give isl_set *isl_set_detect_equalities(
+		__isl_take isl_set *set);
+	__isl_give isl_map *isl_map_detect_equalities(
+		__isl_take isl_map *map);
+	__isl_give isl_union_set *isl_union_set_detect_equalities(
+		__isl_take isl_union_set *uset);
+	__isl_give isl_union_map *isl_union_map_detect_equalities(
+		__isl_take isl_union_map *umap);
+
+Simplify the representation of a set or relation by detecting implicit
+equalities.
+
+=item * Removing redundant constraints
+
+	__isl_give isl_basic_set *isl_basic_set_remove_redundancies(
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_set *isl_set_remove_redundancies(
+		__isl_take isl_set *set);
+	__isl_give isl_basic_map *isl_basic_map_remove_redundancies(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_map *isl_map_remove_redundancies(
+		__isl_take isl_map *map);
+
+=item * Convex hull
+
+	__isl_give isl_basic_set *isl_set_convex_hull(
+		__isl_take isl_set *set);
+	__isl_give isl_basic_map *isl_map_convex_hull(
+		__isl_take isl_map *map);
+
+If the input set or relation has any existentially quantified
+variables, then the result of these operations is currently undefined.
+
+=item * Simple hull
+
+	#include <isl/set.h>
+	__isl_give isl_basic_set *
+	isl_set_unshifted_simple_hull(
+		__isl_take isl_set *set);
+	__isl_give isl_basic_set *isl_set_simple_hull(
+		__isl_take isl_set *set);
+	__isl_give isl_basic_set *
+	isl_set_unshifted_simple_hull_from_set_list(
+		__isl_take isl_set *set,
+		__isl_take isl_set_list *list);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_map *
+	isl_map_unshifted_simple_hull(
+		__isl_take isl_map *map);
+	__isl_give isl_basic_map *isl_map_simple_hull(
+		__isl_take isl_map *map);
+
+	#include <isl/union_map.h>
+	__isl_give isl_union_map *isl_union_map_simple_hull(
+		__isl_take isl_union_map *umap);
+
+These functions compute a single basic set or relation
+that contains the whole input set or relation.
+In particular, the output is described by translates
+of the constraints describing the basic sets or relations in the input.
+In case of C<isl_set_unshifted_simple_hull>, only the original
+constraints are used, without any translation.
+In case of C<isl_set_unshifted_simple_hull_from_set_list>, the
+constraints are taken from the elements of the second argument.
+
+=begin latex
+
+(See \autoref{s:simple hull}.)
+
+=end latex
+
+=item * Affine hull
+
+	__isl_give isl_basic_set *isl_basic_set_affine_hull(
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_basic_set *isl_set_affine_hull(
+		__isl_take isl_set *set);
+	__isl_give isl_union_set *isl_union_set_affine_hull(
+		__isl_take isl_union_set *uset);
+	__isl_give isl_basic_map *isl_basic_map_affine_hull(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_basic_map *isl_map_affine_hull(
+		__isl_take isl_map *map);
+	__isl_give isl_union_map *isl_union_map_affine_hull(
+		__isl_take isl_union_map *umap);
+
+In case of union sets and relations, the affine hull is computed
+per space.
+
+=item * Polyhedral hull
+
+	__isl_give isl_basic_set *isl_set_polyhedral_hull(
+		__isl_take isl_set *set);
+	__isl_give isl_basic_map *isl_map_polyhedral_hull(
+		__isl_take isl_map *map);
+	__isl_give isl_union_set *isl_union_set_polyhedral_hull(
+		__isl_take isl_union_set *uset);
+	__isl_give isl_union_map *isl_union_map_polyhedral_hull(
+		__isl_take isl_union_map *umap);
+
+These functions compute a single basic set or relation
+not involving any existentially quantified variables
+that contains the whole input set or relation.
+In case of union sets and relations, the polyhedral hull is computed
+per space.
+
+=item * Other approximations
+
+	#include <isl/set.h>
+	__isl_give isl_basic_set *
+	isl_basic_set_drop_constraints_involving_dims(
+		__isl_take isl_basic_set *bset,
+		enum isl_dim_type type,
+		unsigned first, unsigned n);
+	__isl_give isl_basic_set *
+	isl_basic_set_drop_constraints_not_involving_dims(
+		__isl_take isl_basic_set *bset,
+		enum isl_dim_type type,
+		unsigned first, unsigned n);
+	__isl_give isl_set *
+	isl_set_drop_constraints_involving_dims(
+		__isl_take isl_set *set,
+		enum isl_dim_type type,
+		unsigned first, unsigned n);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_map *
+	isl_basic_map_drop_constraints_involving_dims(
+		__isl_take isl_basic_map *bmap,
+		enum isl_dim_type type,
+		unsigned first, unsigned n);
+	__isl_give isl_map *
+	isl_map_drop_constraints_involving_dims(
+		__isl_take isl_map *map,
+		enum isl_dim_type type,
+		unsigned first, unsigned n);
+
+These functions drop any constraints (not) involving the specified dimensions.
+Note that the result depends on the representation of the input.
+
+	#include <isl/polynomial.h>
+	__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_to_polynomial(
+		__isl_take isl_pw_qpolynomial *pwqp, int sign);
+	__isl_give isl_union_pw_qpolynomial *
+	isl_union_pw_qpolynomial_to_polynomial(
+		__isl_take isl_union_pw_qpolynomial *upwqp, int sign);
+
+Approximate each quasipolynomial by a polynomial.  If C<sign> is positive,
+the polynomial will be an overapproximation.  If C<sign> is negative,
+it will be an underapproximation.  If C<sign> is zero, the approximation
+will lie somewhere in between.
+
+=item * Feasibility
+
+	__isl_give isl_basic_set *isl_basic_set_sample(
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_basic_set *isl_set_sample(
+		__isl_take isl_set *set);
+	__isl_give isl_basic_map *isl_basic_map_sample(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_basic_map *isl_map_sample(
+		__isl_take isl_map *map);
+
+If the input (basic) set or relation is non-empty, then return
+a singleton subset of the input.  Otherwise, return an empty set.
+
+=item * Optimization
+
+	#include <isl/ilp.h>
+	__isl_give isl_val *isl_basic_set_max_val(
+		__isl_keep isl_basic_set *bset,
+		__isl_keep isl_aff *obj);
+	__isl_give isl_val *isl_set_min_val(
+		__isl_keep isl_set *set,
+		__isl_keep isl_aff *obj);
+	__isl_give isl_val *isl_set_max_val(
+		__isl_keep isl_set *set,
+		__isl_keep isl_aff *obj);
+
+Compute the minimum or maximum of the integer affine expression C<obj>
+over the points in C<set>, returning the result in C<opt>.
+The result is C<NULL> in case of an error, the optimal value in case
+there is one, negative infinity or infinity if the problem is unbounded and
+NaN if the problem is empty.
+
+=item * Parametric optimization
+
+	__isl_give isl_pw_aff *isl_set_dim_min(
+		__isl_take isl_set *set, int pos);
+	__isl_give isl_pw_aff *isl_set_dim_max(
+		__isl_take isl_set *set, int pos);
+	__isl_give isl_pw_aff *isl_map_dim_max(
+		__isl_take isl_map *map, int pos);
+
+Compute the minimum or maximum of the given set or output dimension
+as a function of the parameters (and input dimensions), but independently
+of the other set or output dimensions.
+For lexicographic optimization, see L<"Lexicographic Optimization">.
+
+=item * Dual
+
+The following functions compute either the set of (rational) coefficient
+values of valid constraints for the given set or the set of (rational)
+values satisfying the constraints with coefficients from the given set.
+Internally, these two sets of functions perform essentially the
+same operations, except that the set of coefficients is assumed to
+be a cone, while the set of values may be any polyhedron.
+The current implementation is based on the Farkas lemma and
+Fourier-Motzkin elimination, but this may change or be made optional
+in future.  In particular, future implementations may use different
+dualization algorithms or skip the elimination step.
+
+	__isl_give isl_basic_set *isl_basic_set_coefficients(
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_basic_set *isl_set_coefficients(
+		__isl_take isl_set *set);
+	__isl_give isl_union_set *isl_union_set_coefficients(
+		__isl_take isl_union_set *bset);
+	__isl_give isl_basic_set *isl_basic_set_solutions(
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_basic_set *isl_set_solutions(
+		__isl_take isl_set *set);
+	__isl_give isl_union_set *isl_union_set_solutions(
+		__isl_take isl_union_set *bset);
+
+=item * Power
+
+	__isl_give isl_map *isl_map_fixed_power_val(
+		__isl_take isl_map *map,
+		__isl_take isl_val *exp);
+	__isl_give isl_union_map *
+	isl_union_map_fixed_power_val(
+		__isl_take isl_union_map *umap,
+		__isl_take isl_val *exp);
+
+Compute the given power of C<map>, where C<exp> is assumed to be non-zero.
+If the exponent C<exp> is negative, then the -C<exp> th power of the inverse
+of C<map> is computed.
+
+	__isl_give isl_map *isl_map_power(__isl_take isl_map *map,
+		int *exact);
+	__isl_give isl_union_map *isl_union_map_power(
+		__isl_take isl_union_map *umap, int *exact);
+
+Compute a parametric representation for all positive powers I<k> of C<map>.
+The result maps I<k> to a nested relation corresponding to the
+I<k>th power of C<map>.
+The result may be an overapproximation.  If the result is known to be exact,
+then C<*exact> is set to C<1>.
+
+=item * Transitive closure
+
+	__isl_give isl_map *isl_map_transitive_closure(
+		__isl_take isl_map *map, int *exact);
+	__isl_give isl_union_map *isl_union_map_transitive_closure(
+		__isl_take isl_union_map *umap, int *exact);
+
+Compute the transitive closure of C<map>.
+The result may be an overapproximation.  If the result is known to be exact,
+then C<*exact> is set to C<1>.
+
+=item * Reaching path lengths
+
+	__isl_give isl_map *isl_map_reaching_path_lengths(
+		__isl_take isl_map *map, int *exact);
+
+Compute a relation that maps each element in the range of C<map>
+to the lengths of all paths composed of edges in C<map> that
+end up in the given element.
+The result may be an overapproximation.  If the result is known to be exact,
+then C<*exact> is set to C<1>.
+To compute the I<maximal> path length, the resulting relation
+should be postprocessed by C<isl_map_lexmax>.
+In particular, if the input relation is a dependence relation
+(mapping sources to sinks), then the maximal path length corresponds
+to the free schedule.
+Note, however, that C<isl_map_lexmax> expects the maximum to be
+finite, so if the path lengths are unbounded (possibly due to
+the overapproximation), then you will get an error message.
+
+=item * Wrapping
+
+	#include <isl/space.h>
+	__isl_give isl_space *isl_space_wrap(
+		__isl_take isl_space *space);
+	__isl_give isl_space *isl_space_unwrap(
+		__isl_take isl_space *space);
+
+	#include <isl/set.h>
+	__isl_give isl_basic_map *isl_basic_set_unwrap(
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_map *isl_set_unwrap(
+		__isl_take isl_set *set);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_set *isl_basic_map_wrap(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_set *isl_map_wrap(
+		__isl_take isl_map *map);
+
+	#include <isl/union_set.h>
+	__isl_give isl_union_map *isl_union_set_unwrap(
+		__isl_take isl_union_set *uset);
+
+	#include <isl/union_map.h>
+	__isl_give isl_union_set *isl_union_map_wrap(
+		__isl_take isl_union_map *umap);
+
+The input to C<isl_space_unwrap> should
+be the space of a set, while that of
+C<isl_space_wrap> should be the space of a relation.
+Conversely, the output of C<isl_space_unwrap> is the space
+of a relation, while that of C<isl_space_wrap> is the space of a set.
+
+=item * Flattening
+
+Remove any internal structure of domain (and range) of the given
+set or relation.  If there is any such internal structure in the input,
+then the name of the space is also removed.
+
+	#include <isl/local_space.h>
+	__isl_give isl_local_space *
+	isl_local_space_flatten_domain(
+		__isl_take isl_local_space *ls);
+	__isl_give isl_local_space *
+	isl_local_space_flatten_range(
+		__isl_take isl_local_space *ls);
+
+	#include <isl/set.h>
+	__isl_give isl_basic_set *isl_basic_set_flatten(
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_set *isl_set_flatten(
+		__isl_take isl_set *set);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_map *isl_basic_map_flatten_domain(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_basic_map *isl_basic_map_flatten_range(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_map *isl_map_flatten_range(
+		__isl_take isl_map *map);
+	__isl_give isl_map *isl_map_flatten_domain(
+		__isl_take isl_map *map);
+	__isl_give isl_basic_map *isl_basic_map_flatten(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_map *isl_map_flatten(
+		__isl_take isl_map *map);
+
+	#include <isl/val.h>
+	__isl_give isl_multi_val *isl_multi_val_flatten_range(
+		__isl_take isl_multi_val *mv);
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_aff *isl_multi_aff_flatten_domain(
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_multi_aff *isl_multi_aff_flatten_range(
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_flatten_range(
+		__isl_take isl_multi_pw_aff *mpa);
+
+	#include <isl/map.h>
+	__isl_give isl_map *isl_set_flatten_map(
+		__isl_take isl_set *set);
+
+The function above constructs a relation
+that maps the input set to a flattened version of the set.
+
+=item * Lifting
+
+Lift the input set to a space with extra dimensions corresponding
+to the existentially quantified variables in the input.
+In particular, the result lives in a wrapped map where the domain
+is the original space and the range corresponds to the original
+existentially quantified variables.
+
+	#include <isl/set.h>
+	__isl_give isl_basic_set *isl_basic_set_lift(
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_set *isl_set_lift(
+		__isl_take isl_set *set);
+	__isl_give isl_union_set *isl_union_set_lift(
+		__isl_take isl_union_set *uset);
+
+Given a local space that contains the existentially quantified
+variables of a set, a basic relation that, when applied to
+a basic set, has essentially the same effect as C<isl_basic_set_lift>,
+can be constructed using the following function.
+
+	#include <isl/local_space.h>
+	__isl_give isl_basic_map *isl_local_space_lifting(
+		__isl_take isl_local_space *ls);
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_aff *isl_multi_aff_lift(
+		__isl_take isl_multi_aff *maff,
+		__isl_give isl_local_space **ls);
+
+If the C<ls> argument of C<isl_multi_aff_lift> is not C<NULL>,
+then it is assigned the local space that lies at the basis of
+the lifting applied.
+
+=item * Internal Product
+
+	#include <isl/space.h>
+	__isl_give isl_space *isl_space_zip(
+		__isl_take isl_space *space);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_map *isl_basic_map_zip(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_map *isl_map_zip(
+		__isl_take isl_map *map);
+
+	#include <isl/union_map.h>
+	__isl_give isl_union_map *isl_union_map_zip(
+		__isl_take isl_union_map *umap);
+
+Given a relation with nested relations for domain and range,
+interchange the range of the domain with the domain of the range.
+
+=item * Currying
+
+	#include <isl/space.h>
+	__isl_give isl_space *isl_space_curry(
+		__isl_take isl_space *space);
+	__isl_give isl_space *isl_space_uncurry(
+		__isl_take isl_space *space);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_map *isl_basic_map_curry(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_basic_map *isl_basic_map_uncurry(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_map *isl_map_curry(
+		__isl_take isl_map *map);
+	__isl_give isl_map *isl_map_uncurry(
+		__isl_take isl_map *map);
+
+	#include <isl/union_map.h>
+	__isl_give isl_union_map *isl_union_map_curry(
+		__isl_take isl_union_map *umap);
+	__isl_give isl_union_map *isl_union_map_uncurry(
+		__isl_take isl_union_map *umap);
+
+Given a relation with a nested relation for domain,
+the C<curry> functions
+move the range of the nested relation out of the domain
+and use it as the domain of a nested relation in the range,
+with the original range as range of this nested relation.
+The C<uncurry> functions perform the inverse operation.
+
+=item * Aligning parameters
+
+Change the order of the parameters of the given set, relation
+or function
+such that the first parameters match those of C<model>.
+This may involve the introduction of extra parameters.
+All parameters need to be named.
+
+	#include <isl/space.h>
+	__isl_give isl_space *isl_space_align_params(
+		__isl_take isl_space *space1,
+		__isl_take isl_space *space2)
+
+	#include <isl/set.h>
+	__isl_give isl_basic_set *isl_basic_set_align_params(
+		__isl_take isl_basic_set *bset,
+		__isl_take isl_space *model);
+	__isl_give isl_set *isl_set_align_params(
+		__isl_take isl_set *set,
+		__isl_take isl_space *model);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_map *isl_basic_map_align_params(
+		__isl_take isl_basic_map *bmap,
+		__isl_take isl_space *model);
+	__isl_give isl_map *isl_map_align_params(
+		__isl_take isl_map *map,
+		__isl_take isl_space *model);
+
+	#include <isl/val.h>
+	__isl_give isl_multi_val *isl_multi_val_align_params(
+		__isl_take isl_multi_val *mv,
+		__isl_take isl_space *model);
+
+	#include <isl/aff.h>
+	__isl_give isl_aff *isl_aff_align_params(
+		__isl_take isl_aff *aff,
+		__isl_take isl_space *model);
+	__isl_give isl_multi_aff *isl_multi_aff_align_params(
+		__isl_take isl_multi_aff *multi,
+		__isl_take isl_space *model);
+	__isl_give isl_pw_aff *isl_pw_aff_align_params(
+		__isl_take isl_pw_aff *pwaff,
+		__isl_take isl_space *model);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_align_params(
+		__isl_take isl_pw_multi_aff *pma,
+		__isl_take isl_space *model);
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_align_params(
+		__isl_take isl_union_pw_multi_aff *upma,
+		__isl_take isl_space *model);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_qpolynomial *isl_qpolynomial_align_params(
+		__isl_take isl_qpolynomial *qp,
+		__isl_take isl_space *model);
+
+=item * Unary Arithmethic Operations
+
+	#include <isl/aff.h>
+	__isl_give isl_aff *isl_aff_neg(
+		__isl_take isl_aff *aff);
+	__isl_give isl_pw_aff *isl_pw_aff_neg(
+		__isl_take isl_pw_aff *pwaff);
+	__isl_give isl_aff *isl_aff_ceil(
+		__isl_take isl_aff *aff);
+	__isl_give isl_pw_aff *isl_pw_aff_ceil(
+		__isl_take isl_pw_aff *pwaff);
+	__isl_give isl_aff *isl_aff_floor(
+		__isl_take isl_aff *aff);
+	__isl_give isl_multi_aff *isl_multi_aff_floor(
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_pw_aff *isl_pw_aff_floor(
+		__isl_take isl_pw_aff *pwaff);
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_aff *isl_pw_aff_list_min(
+		__isl_take isl_pw_aff_list *list);
+	__isl_give isl_pw_aff *isl_pw_aff_list_max(
+		__isl_take isl_pw_aff_list *list);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_qpolynomial *isl_qpolynomial_neg(
+		__isl_take isl_qpolynomial *qp);
+	__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_neg(
+		__isl_take isl_pw_qpolynomial *pwqp);
+	__isl_give isl_union_pw_qpolynomial *
+	isl_union_pw_qpolynomial_neg(
+		__isl_take isl_union_pw_qpolynomial *upwqp);
+	__isl_give isl_qpolynomial *isl_qpolynomial_pow(
+		__isl_take isl_qpolynomial *qp,
+		unsigned exponent);
+	__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_pow(
+		__isl_take isl_pw_qpolynomial *pwqp,
+		unsigned exponent);
+
+=item * Evaluation
+
+The following functions evaluate a function in a point.
+
+	#include <isl/polynomial.h>
+	__isl_give isl_val *isl_pw_qpolynomial_eval(
+		__isl_take isl_pw_qpolynomial *pwqp,
+		__isl_take isl_point *pnt);
+	__isl_give isl_val *isl_pw_qpolynomial_fold_eval(
+		__isl_take isl_pw_qpolynomial_fold *pwf,
+		__isl_take isl_point *pnt);
+	__isl_give isl_val *isl_union_pw_qpolynomial_eval(
+		__isl_take isl_union_pw_qpolynomial *upwqp,
+		__isl_take isl_point *pnt);
+	__isl_give isl_val *isl_union_pw_qpolynomial_fold_eval(
+		__isl_take isl_union_pw_qpolynomial_fold *upwf,
+		__isl_take isl_point *pnt);
+
+=item * Dimension manipulation
+
+It is usually not advisable to directly change the (input or output)
+space of a set or a relation as this removes the name and the internal
+structure of the space.  However, the functions below can be useful
+to add new parameters, assuming
+C<isl_set_align_params> and C<isl_map_align_params>
+are not sufficient.
+
+	#include <isl/space.h>
+	__isl_give isl_space *isl_space_add_dims(
+		__isl_take isl_space *space,
+		enum isl_dim_type type, unsigned n);
+	__isl_give isl_space *isl_space_insert_dims(
+		__isl_take isl_space *space,
+		enum isl_dim_type type, unsigned pos, unsigned n);
+	__isl_give isl_space *isl_space_drop_dims(
+		__isl_take isl_space *space,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	__isl_give isl_space *isl_space_move_dims(
+		__isl_take isl_space *space,
+		enum isl_dim_type dst_type, unsigned dst_pos,
+		enum isl_dim_type src_type, unsigned src_pos,
+		unsigned n);
+
+	#include <isl/local_space.h>
+	__isl_give isl_local_space *isl_local_space_add_dims(
+		__isl_take isl_local_space *ls,
+		enum isl_dim_type type, unsigned n);
+	__isl_give isl_local_space *isl_local_space_insert_dims(
+		__isl_take isl_local_space *ls,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	__isl_give isl_local_space *isl_local_space_drop_dims(
+		__isl_take isl_local_space *ls,
+		enum isl_dim_type type, unsigned first, unsigned n);
+
+	#include <isl/set.h>
+	__isl_give isl_basic_set *isl_basic_set_add_dims(
+		__isl_take isl_basic_set *bset,
+		enum isl_dim_type type, unsigned n);
+	__isl_give isl_set *isl_set_add_dims(
+		__isl_take isl_set *set,
+		enum isl_dim_type type, unsigned n);
+	__isl_give isl_basic_set *isl_basic_set_insert_dims(
+		__isl_take isl_basic_set *bset,
+		enum isl_dim_type type, unsigned pos,
+		unsigned n);
+	__isl_give isl_set *isl_set_insert_dims(
+		__isl_take isl_set *set,
+		enum isl_dim_type type, unsigned pos, unsigned n);
+	__isl_give isl_basic_set *isl_basic_set_move_dims(
+		__isl_take isl_basic_set *bset,
+		enum isl_dim_type dst_type, unsigned dst_pos,
+		enum isl_dim_type src_type, unsigned src_pos,
+		unsigned n);
+	__isl_give isl_set *isl_set_move_dims(
+		__isl_take isl_set *set,
+		enum isl_dim_type dst_type, unsigned dst_pos,
+		enum isl_dim_type src_type, unsigned src_pos,
+		unsigned n);
+
+	#include <isl/map.h>
+	__isl_give isl_map *isl_map_add_dims(
+		__isl_take isl_map *map,
+		enum isl_dim_type type, unsigned n);
+	__isl_give isl_basic_map *isl_basic_map_insert_dims(
+		__isl_take isl_basic_map *bmap,
+		enum isl_dim_type type, unsigned pos,
+		unsigned n);
+	__isl_give isl_map *isl_map_insert_dims(
+		__isl_take isl_map *map,
+		enum isl_dim_type type, unsigned pos, unsigned n);
+	__isl_give isl_basic_map *isl_basic_map_move_dims(
+		__isl_take isl_basic_map *bmap,
+		enum isl_dim_type dst_type, unsigned dst_pos,
+		enum isl_dim_type src_type, unsigned src_pos,
+		unsigned n);
+	__isl_give isl_map *isl_map_move_dims(
+		__isl_take isl_map *map,
+		enum isl_dim_type dst_type, unsigned dst_pos,
+		enum isl_dim_type src_type, unsigned src_pos,
+		unsigned n);
+
+	#include <isl/val.h>
+	__isl_give isl_multi_val *isl_multi_val_insert_dims(
+		__isl_take isl_multi_val *mv,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	__isl_give isl_multi_val *isl_multi_val_add_dims(
+		__isl_take isl_multi_val *mv,
+		enum isl_dim_type type, unsigned n);
+	__isl_give isl_multi_val *isl_multi_val_drop_dims(
+		__isl_take isl_multi_val *mv,
+		enum isl_dim_type type, unsigned first, unsigned n);
+
+	#include <isl/aff.h>
+	__isl_give isl_aff *isl_aff_insert_dims(
+		__isl_take isl_aff *aff,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	__isl_give isl_multi_aff *isl_multi_aff_insert_dims(
+		__isl_take isl_multi_aff *ma,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	__isl_give isl_pw_aff *isl_pw_aff_insert_dims(
+		__isl_take isl_pw_aff *pwaff,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	__isl_give isl_multi_pw_aff *isl_multi_pw_aff_insert_dims(
+		__isl_take isl_multi_pw_aff *mpa,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	__isl_give isl_aff *isl_aff_add_dims(
+		__isl_take isl_aff *aff,
+		enum isl_dim_type type, unsigned n);
+	__isl_give isl_multi_aff *isl_multi_aff_add_dims(
+		__isl_take isl_multi_aff *ma,
+		enum isl_dim_type type, unsigned n);
+	__isl_give isl_pw_aff *isl_pw_aff_add_dims(
+		__isl_take isl_pw_aff *pwaff,
+		enum isl_dim_type type, unsigned n);
+	__isl_give isl_multi_pw_aff *isl_multi_pw_aff_add_dims(
+		__isl_take isl_multi_pw_aff *mpa,
+		enum isl_dim_type type, unsigned n);
+	__isl_give isl_aff *isl_aff_drop_dims(
+		__isl_take isl_aff *aff,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	__isl_give isl_multi_aff *isl_multi_aff_drop_dims(
+		__isl_take isl_multi_aff *maff,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	__isl_give isl_pw_aff *isl_pw_aff_drop_dims(
+		__isl_take isl_pw_aff *pwaff,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_drop_dims(
+		__isl_take isl_pw_multi_aff *pma,
+		enum isl_dim_type type, unsigned first, unsigned n);
+	__isl_give isl_aff *isl_aff_move_dims(
+		__isl_take isl_aff *aff,
+		enum isl_dim_type dst_type, unsigned dst_pos,
+		enum isl_dim_type src_type, unsigned src_pos,
+		unsigned n);
+	__isl_give isl_multi_aff *isl_multi_aff_move_dims(
+		__isl_take isl_multi_aff *ma,
+		enum isl_dim_type dst_type, unsigned dst_pos,
+		enum isl_dim_type src_type, unsigned src_pos,
+		unsigned n);
+	__isl_give isl_pw_aff *isl_pw_aff_move_dims(
+		__isl_take isl_pw_aff *pa,
+		enum isl_dim_type dst_type, unsigned dst_pos,
+		enum isl_dim_type src_type, unsigned src_pos,
+		unsigned n);
+	__isl_give isl_multi_pw_aff *isl_multi_pw_aff_move_dims(
+		__isl_take isl_multi_pw_aff *pma,
+		enum isl_dim_type dst_type, unsigned dst_pos,
+		enum isl_dim_type src_type, unsigned src_pos,
+		unsigned n);
+
+=back
+
+=head2 Binary Operations
+
+The two arguments of a binary operation not only need to live
+in the same C<isl_ctx>, they currently also need to have
+the same (number of) parameters.
+
+=head3 Basic Operations
+
+=over
+
+=item * Intersection
+
+	#include <isl/local_space.h>
+	__isl_give isl_local_space *isl_local_space_intersect(
+		__isl_take isl_local_space *ls1,
+		__isl_take isl_local_space *ls2);
+
+	#include <isl/set.h>
+	__isl_give isl_basic_set *isl_basic_set_intersect_params(
+		__isl_take isl_basic_set *bset1,
+		__isl_take isl_basic_set *bset2);
+	__isl_give isl_basic_set *isl_basic_set_intersect(
+		__isl_take isl_basic_set *bset1,
+		__isl_take isl_basic_set *bset2);
+	__isl_give isl_basic_set *isl_basic_set_list_intersect(
+		__isl_take struct isl_basic_set_list *list);
+	__isl_give isl_set *isl_set_intersect_params(
+		__isl_take isl_set *set,
+		__isl_take isl_set *params);
+	__isl_give isl_set *isl_set_intersect(
+		__isl_take isl_set *set1,
+		__isl_take isl_set *set2);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_map *isl_basic_map_intersect_domain(
+		__isl_take isl_basic_map *bmap,
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_basic_map *isl_basic_map_intersect_range(
+		__isl_take isl_basic_map *bmap,
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_basic_map *isl_basic_map_intersect(
+		__isl_take isl_basic_map *bmap1,
+		__isl_take isl_basic_map *bmap2);
+	__isl_give isl_map *isl_map_intersect_params(
+		__isl_take isl_map *map,
+		__isl_take isl_set *params);
+	__isl_give isl_map *isl_map_intersect_domain(
+		__isl_take isl_map *map,
+		__isl_take isl_set *set);
+	__isl_give isl_map *isl_map_intersect_range(
+		__isl_take isl_map *map,
+		__isl_take isl_set *set);
+	__isl_give isl_map *isl_map_intersect(
+		__isl_take isl_map *map1,
+		__isl_take isl_map *map2);
+
+	#include <isl/union_set.h>
+	__isl_give isl_union_set *isl_union_set_intersect_params(
+		__isl_take isl_union_set *uset,
+		__isl_take isl_set *set);
+	__isl_give isl_union_set *isl_union_set_intersect(
+		__isl_take isl_union_set *uset1,
+		__isl_take isl_union_set *uset2);
+
+	#include <isl/union_map.h>
+	__isl_give isl_union_map *isl_union_map_intersect_params(
+		__isl_take isl_union_map *umap,
+		__isl_take isl_set *set);
+	__isl_give isl_union_map *isl_union_map_intersect_domain(
+		__isl_take isl_union_map *umap,
+		__isl_take isl_union_set *uset);
+	__isl_give isl_union_map *isl_union_map_intersect_range(
+		__isl_take isl_union_map *umap,
+		__isl_take isl_union_set *uset);
+	__isl_give isl_union_map *isl_union_map_intersect(
+		__isl_take isl_union_map *umap1,
+		__isl_take isl_union_map *umap2);
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_aff *isl_pw_aff_intersect_domain(
+		__isl_take isl_pw_aff *pa,
+		__isl_take isl_set *set);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_intersect_domain(
+		__isl_take isl_multi_pw_aff *mpa,
+		__isl_take isl_set *domain);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_intersect_domain(
+		__isl_take isl_pw_multi_aff *pma,
+		__isl_take isl_set *set);
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_intersect_domain(
+		__isl_take isl_union_pw_multi_aff *upma,
+		__isl_take isl_union_set *uset);
+	__isl_give isl_pw_aff *isl_pw_aff_intersect_params(
+		__isl_take isl_pw_aff *pa,
+		__isl_take isl_set *set);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_intersect_params(
+		__isl_take isl_multi_pw_aff *mpa,
+		__isl_take isl_set *set);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_intersect_params(
+		__isl_take isl_pw_multi_aff *pma,
+		__isl_take isl_set *set);
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_intersect_params(
+		__isl_take isl_union_pw_multi_aff *upma,
+		__isl_take isl_set *set);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_pw_qpolynomial *
+	isl_pw_qpolynomial_intersect_domain(
+		__isl_take isl_pw_qpolynomial *pwpq,
+		__isl_take isl_set *set);
+	__isl_give isl_union_pw_qpolynomial *
+	isl_union_pw_qpolynomial_intersect_domain(
+		__isl_take isl_union_pw_qpolynomial *upwpq,
+		__isl_take isl_union_set *uset);
+	__isl_give isl_union_pw_qpolynomial_fold *
+	isl_union_pw_qpolynomial_fold_intersect_domain(
+		__isl_take isl_union_pw_qpolynomial_fold *upwf,
+		__isl_take isl_union_set *uset);
+	__isl_give isl_pw_qpolynomial *
+	isl_pw_qpolynomial_intersect_params(
+		__isl_take isl_pw_qpolynomial *pwpq,
+		__isl_take isl_set *set);
+	__isl_give isl_pw_qpolynomial_fold *
+	isl_pw_qpolynomial_fold_intersect_params(
+		__isl_take isl_pw_qpolynomial_fold *pwf,
+		__isl_take isl_set *set);
+	__isl_give isl_union_pw_qpolynomial *
+	isl_union_pw_qpolynomial_intersect_params(
+		__isl_take isl_union_pw_qpolynomial *upwpq,
+		__isl_take isl_set *set);
+	__isl_give isl_union_pw_qpolynomial_fold *
+	isl_union_pw_qpolynomial_fold_intersect_params(
+		__isl_take isl_union_pw_qpolynomial_fold *upwf,
+		__isl_take isl_set *set);
+
+The second argument to the C<_params> functions needs to be
+a parametric (basic) set.  For the other functions, a parametric set
+for either argument is only allowed if the other argument is
+a parametric set as well.
+The list passed to C<isl_basic_set_list_intersect> needs to have
+at least one element and all elements need to live in the same space.
+
+=item * Union
+
+	__isl_give isl_set *isl_basic_set_union(
+		__isl_take isl_basic_set *bset1,
+		__isl_take isl_basic_set *bset2);
+	__isl_give isl_map *isl_basic_map_union(
+		__isl_take isl_basic_map *bmap1,
+		__isl_take isl_basic_map *bmap2);
+	__isl_give isl_set *isl_set_union(
+		__isl_take isl_set *set1,
+		__isl_take isl_set *set2);
+	__isl_give isl_map *isl_map_union(
+		__isl_take isl_map *map1,
+		__isl_take isl_map *map2);
+	__isl_give isl_union_set *isl_union_set_union(
+		__isl_take isl_union_set *uset1,
+		__isl_take isl_union_set *uset2);
+	__isl_give isl_union_map *isl_union_map_union(
+		__isl_take isl_union_map *umap1,
+		__isl_take isl_union_map *umap2);
+
+=item * Set difference
+
+	__isl_give isl_set *isl_set_subtract(
+		__isl_take isl_set *set1,
+		__isl_take isl_set *set2);
+	__isl_give isl_map *isl_map_subtract(
+		__isl_take isl_map *map1,
+		__isl_take isl_map *map2);
+	__isl_give isl_map *isl_map_subtract_domain(
+		__isl_take isl_map *map,
+		__isl_take isl_set *dom);
+	__isl_give isl_map *isl_map_subtract_range(
+		__isl_take isl_map *map,
+		__isl_take isl_set *dom);
+	__isl_give isl_union_set *isl_union_set_subtract(
+		__isl_take isl_union_set *uset1,
+		__isl_take isl_union_set *uset2);
+	__isl_give isl_union_map *isl_union_map_subtract(
+		__isl_take isl_union_map *umap1,
+		__isl_take isl_union_map *umap2);
+	__isl_give isl_union_map *isl_union_map_subtract_domain(
+		__isl_take isl_union_map *umap,
+		__isl_take isl_union_set *dom);
+	__isl_give isl_union_map *isl_union_map_subtract_range(
+		__isl_take isl_union_map *umap,
+		__isl_take isl_union_set *dom);
+
+=item * Application
+
+	#include <isl/space.h>
+	__isl_give isl_space *isl_space_join(
+		__isl_take isl_space *left,
+		__isl_take isl_space *right);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_set *isl_basic_set_apply(
+		__isl_take isl_basic_set *bset,
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_set *isl_set_apply(
+		__isl_take isl_set *set,
+		__isl_take isl_map *map);
+	__isl_give isl_union_set *isl_union_set_apply(
+		__isl_take isl_union_set *uset,
+		__isl_take isl_union_map *umap);
+	__isl_give isl_basic_map *isl_basic_map_apply_domain(
+		__isl_take isl_basic_map *bmap1,
+		__isl_take isl_basic_map *bmap2);
+	__isl_give isl_basic_map *isl_basic_map_apply_range(
+		__isl_take isl_basic_map *bmap1,
+		__isl_take isl_basic_map *bmap2);
+	__isl_give isl_map *isl_map_apply_domain(
+		__isl_take isl_map *map1,
+		__isl_take isl_map *map2);
+	__isl_give isl_map *isl_map_apply_range(
+		__isl_take isl_map *map1,
+		__isl_take isl_map *map2);
+
+	#include <isl/union_map.h>
+	__isl_give isl_union_map *isl_union_map_apply_domain(
+		__isl_take isl_union_map *umap1,
+		__isl_take isl_union_map *umap2);
+	__isl_give isl_union_map *isl_union_map_apply_range(
+		__isl_take isl_union_map *umap1,
+		__isl_take isl_union_map *umap2);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_pw_qpolynomial_fold *
+	isl_set_apply_pw_qpolynomial_fold(
+		__isl_take isl_set *set,
+		__isl_take isl_pw_qpolynomial_fold *pwf,
+		int *tight);
+	__isl_give isl_pw_qpolynomial_fold *
+	isl_map_apply_pw_qpolynomial_fold(
+		__isl_take isl_map *map,
+		__isl_take isl_pw_qpolynomial_fold *pwf,
+		int *tight);
+	__isl_give isl_union_pw_qpolynomial_fold *
+	isl_union_set_apply_union_pw_qpolynomial_fold(
+		__isl_take isl_union_set *uset,
+		__isl_take isl_union_pw_qpolynomial_fold *upwf,
+		int *tight);
+	__isl_give isl_union_pw_qpolynomial_fold *
+	isl_union_map_apply_union_pw_qpolynomial_fold(
+		__isl_take isl_union_map *umap,
+		__isl_take isl_union_pw_qpolynomial_fold *upwf,
+		int *tight);
+
+The functions taking a map
+compose the given map with the given piecewise quasipolynomial reduction.
+That is, compute a bound (of the same type as C<pwf> or C<upwf> itself)
+over all elements in the intersection of the range of the map
+and the domain of the piecewise quasipolynomial reduction
+as a function of an element in the domain of the map.
+The functions taking a set compute a bound over all elements in the
+intersection of the set and the domain of the
+piecewise quasipolynomial reduction.
+
+=item * Preimage
+
+	#include <isl/set.h>
+	__isl_give isl_basic_set *
+	isl_basic_set_preimage_multi_aff(
+		__isl_take isl_basic_set *bset,
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_set *isl_set_preimage_multi_aff(
+		__isl_take isl_set *set,
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_set *isl_set_preimage_pw_multi_aff(
+		__isl_take isl_set *set,
+		__isl_take isl_pw_multi_aff *pma);
+	__isl_give isl_set *isl_set_preimage_multi_pw_aff(
+		__isl_take isl_set *set,
+		__isl_take isl_multi_pw_aff *mpa);
+
+	#include <isl/union_set.h>
+	__isl_give isl_union_set *
+	isl_union_set_preimage_multi_aff(
+		__isl_take isl_union_set *uset,
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_union_set *
+	isl_union_set_preimage_pw_multi_aff(
+		__isl_take isl_union_set *uset,
+		__isl_take isl_pw_multi_aff *pma);
+	__isl_give isl_union_set *
+	isl_union_set_preimage_union_pw_multi_aff(
+		__isl_take isl_union_set *uset,
+		__isl_take isl_union_pw_multi_aff *upma);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_map *
+	isl_basic_map_preimage_domain_multi_aff(
+		__isl_take isl_basic_map *bmap,
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_map *isl_map_preimage_domain_multi_aff(
+		__isl_take isl_map *map,
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_map *isl_map_preimage_range_multi_aff(
+		__isl_take isl_map *map,
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_map *
+	isl_map_preimage_domain_pw_multi_aff(
+		__isl_take isl_map *map,
+		__isl_take isl_pw_multi_aff *pma);
+	__isl_give isl_map *
+	isl_map_preimage_range_pw_multi_aff(
+		__isl_take isl_map *map,
+		__isl_take isl_pw_multi_aff *pma);
+	__isl_give isl_map *
+	isl_map_preimage_domain_multi_pw_aff(
+		__isl_take isl_map *map,
+		__isl_take isl_multi_pw_aff *mpa);
+	__isl_give isl_basic_map *
+	isl_basic_map_preimage_range_multi_aff(
+		__isl_take isl_basic_map *bmap,
+		__isl_take isl_multi_aff *ma);
+
+	#include <isl/union_map.h>
+	__isl_give isl_union_map *
+	isl_union_map_preimage_domain_multi_aff(
+		__isl_take isl_union_map *umap,
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_union_map *
+	isl_union_map_preimage_range_multi_aff(
+		__isl_take isl_union_map *umap,
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_union_map *
+	isl_union_map_preimage_domain_pw_multi_aff(
+		__isl_take isl_union_map *umap,
+		__isl_take isl_pw_multi_aff *pma);
+	__isl_give isl_union_map *
+	isl_union_map_preimage_range_pw_multi_aff(
+		__isl_take isl_union_map *umap,
+		__isl_take isl_pw_multi_aff *pma);
+	__isl_give isl_union_map *
+	isl_union_map_preimage_domain_union_pw_multi_aff(
+		__isl_take isl_union_map *umap,
+		__isl_take isl_union_pw_multi_aff *upma);
+	__isl_give isl_union_map *
+	isl_union_map_preimage_range_union_pw_multi_aff(
+		__isl_take isl_union_map *umap,
+		__isl_take isl_union_pw_multi_aff *upma);
+
+These functions compute the preimage of the given set or map domain/range under
+the given function.  In other words, the expression is plugged
+into the set description or into the domain/range of the map.
+
+=item * Pullback
+
+	#include <isl/aff.h>
+	__isl_give isl_aff *isl_aff_pullback_aff(
+		__isl_take isl_aff *aff1,
+		__isl_take isl_aff *aff2);
+	__isl_give isl_aff *isl_aff_pullback_multi_aff(
+		__isl_take isl_aff *aff,
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_pw_aff *isl_pw_aff_pullback_multi_aff(
+		__isl_take isl_pw_aff *pa,
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_pw_aff *isl_pw_aff_pullback_pw_multi_aff(
+		__isl_take isl_pw_aff *pa,
+		__isl_take isl_pw_multi_aff *pma);
+	__isl_give isl_pw_aff *isl_pw_aff_pullback_multi_pw_aff(
+		__isl_take isl_pw_aff *pa,
+		__isl_take isl_multi_pw_aff *mpa);
+	__isl_give isl_multi_aff *isl_multi_aff_pullback_multi_aff(
+		__isl_take isl_multi_aff *ma1,
+		__isl_take isl_multi_aff *ma2);
+	__isl_give isl_pw_multi_aff *
+	isl_pw_multi_aff_pullback_multi_aff(
+		__isl_take isl_pw_multi_aff *pma,
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_pullback_multi_aff(
+		__isl_take isl_multi_pw_aff *mpa,
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_pw_multi_aff *
+	isl_pw_multi_aff_pullback_pw_multi_aff(
+		__isl_take isl_pw_multi_aff *pma1,
+		__isl_take isl_pw_multi_aff *pma2);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_pullback_pw_multi_aff(
+		__isl_take isl_multi_pw_aff *mpa,
+		__isl_take isl_pw_multi_aff *pma);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_pullback_multi_pw_aff(
+		__isl_take isl_multi_pw_aff *mpa1,
+		__isl_take isl_multi_pw_aff *mpa2);
+
+These functions precompose the first expression by the second function.
+In other words, the second function is plugged
+into the first expression.
+
+=item * Locus
+
+	#include <isl/aff.h>
+	__isl_give isl_basic_set *isl_aff_le_basic_set(
+		__isl_take isl_aff *aff1,
+		__isl_take isl_aff *aff2);
+	__isl_give isl_basic_set *isl_aff_ge_basic_set(
+		__isl_take isl_aff *aff1,
+		__isl_take isl_aff *aff2);
+	__isl_give isl_set *isl_pw_aff_eq_set(
+		__isl_take isl_pw_aff *pwaff1,
+		__isl_take isl_pw_aff *pwaff2);
+	__isl_give isl_set *isl_pw_aff_ne_set(
+		__isl_take isl_pw_aff *pwaff1,
+		__isl_take isl_pw_aff *pwaff2);
+	__isl_give isl_set *isl_pw_aff_le_set(
+		__isl_take isl_pw_aff *pwaff1,
+		__isl_take isl_pw_aff *pwaff2);
+	__isl_give isl_set *isl_pw_aff_lt_set(
+		__isl_take isl_pw_aff *pwaff1,
+		__isl_take isl_pw_aff *pwaff2);
+	__isl_give isl_set *isl_pw_aff_ge_set(
+		__isl_take isl_pw_aff *pwaff1,
+		__isl_take isl_pw_aff *pwaff2);
+	__isl_give isl_set *isl_pw_aff_gt_set(
+		__isl_take isl_pw_aff *pwaff1,
+		__isl_take isl_pw_aff *pwaff2);
+
+	__isl_give isl_set *isl_multi_aff_lex_le_set(
+		__isl_take isl_multi_aff *ma1,
+		__isl_take isl_multi_aff *ma2);
+	__isl_give isl_set *isl_multi_aff_lex_ge_set(
+		__isl_take isl_multi_aff *ma1,
+		__isl_take isl_multi_aff *ma2);
+
+	__isl_give isl_set *isl_pw_aff_list_eq_set(
+		__isl_take isl_pw_aff_list *list1,
+		__isl_take isl_pw_aff_list *list2);
+	__isl_give isl_set *isl_pw_aff_list_ne_set(
+		__isl_take isl_pw_aff_list *list1,
+		__isl_take isl_pw_aff_list *list2);
+	__isl_give isl_set *isl_pw_aff_list_le_set(
+		__isl_take isl_pw_aff_list *list1,
+		__isl_take isl_pw_aff_list *list2);
+	__isl_give isl_set *isl_pw_aff_list_lt_set(
+		__isl_take isl_pw_aff_list *list1,
+		__isl_take isl_pw_aff_list *list2);
+	__isl_give isl_set *isl_pw_aff_list_ge_set(
+		__isl_take isl_pw_aff_list *list1,
+		__isl_take isl_pw_aff_list *list2);
+	__isl_give isl_set *isl_pw_aff_list_gt_set(
+		__isl_take isl_pw_aff_list *list1,
+		__isl_take isl_pw_aff_list *list2);
+
+The function C<isl_aff_ge_basic_set> returns a basic set
+containing those elements in the shared space
+of C<aff1> and C<aff2> where C<aff1> is greater than or equal to C<aff2>.
+The function C<isl_pw_aff_ge_set> returns a set
+containing those elements in the shared domain
+of C<pwaff1> and C<pwaff2> where C<pwaff1> is
+greater than or equal to C<pwaff2>.
+The function C<isl_multi_aff_lex_le_set> returns a set
+containing those elements in the shared domain space
+where C<ma1> is lexicographically smaller than or
+equal to C<ma2>.
+The functions operating on C<isl_pw_aff_list> apply the corresponding
+C<isl_pw_aff> function to each pair of elements in the two lists.
+
+=item * Cartesian Product
+
+	#include <isl/space.h>
+	__isl_give isl_space *isl_space_product(
+		__isl_take isl_space *space1,
+		__isl_take isl_space *space2);
+	__isl_give isl_space *isl_space_domain_product(
+		__isl_take isl_space *space1,
+		__isl_take isl_space *space2);
+	__isl_give isl_space *isl_space_range_product(
+		__isl_take isl_space *space1,
+		__isl_take isl_space *space2);
+
+The functions
+C<isl_space_product>, C<isl_space_domain_product>
+and C<isl_space_range_product> take pairs or relation spaces and
+produce a single relations space, where either the domain, the range
+or both domain and range are wrapped spaces of relations between
+the domains and/or ranges of the input spaces.
+If the product is only constructed over the domain or the range
+then the ranges or the domains of the inputs should be the same.
+The function C<isl_space_product> also accepts a pair of set spaces,
+in which case it returns a wrapped space of a relation between the
+two input spaces.
+
+	#include <isl/set.h>
+	__isl_give isl_set *isl_set_product(
+		__isl_take isl_set *set1,
+		__isl_take isl_set *set2);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_map *isl_basic_map_domain_product(
+		__isl_take isl_basic_map *bmap1,
+		__isl_take isl_basic_map *bmap2);
+	__isl_give isl_basic_map *isl_basic_map_range_product(
+		__isl_take isl_basic_map *bmap1,
+		__isl_take isl_basic_map *bmap2);
+	__isl_give isl_basic_map *isl_basic_map_product(
+		__isl_take isl_basic_map *bmap1,
+		__isl_take isl_basic_map *bmap2);
+	__isl_give isl_map *isl_map_domain_product(
+		__isl_take isl_map *map1,
+		__isl_take isl_map *map2);
+	__isl_give isl_map *isl_map_range_product(
+		__isl_take isl_map *map1,
+		__isl_take isl_map *map2);
+	__isl_give isl_map *isl_map_product(
+		__isl_take isl_map *map1,
+		__isl_take isl_map *map2);
+
+	#include <isl/union_set.h>
+	__isl_give isl_union_set *isl_union_set_product(
+		__isl_take isl_union_set *uset1,
+		__isl_take isl_union_set *uset2);
+
+	#include <isl/union_map.h>
+	__isl_give isl_union_map *isl_union_map_domain_product(
+		__isl_take isl_union_map *umap1,
+		__isl_take isl_union_map *umap2);
+	__isl_give isl_union_map *isl_union_map_range_product(
+		__isl_take isl_union_map *umap1,
+		__isl_take isl_union_map *umap2);
+	__isl_give isl_union_map *isl_union_map_product(
+		__isl_take isl_union_map *umap1,
+		__isl_take isl_union_map *umap2);
+
+	#include <isl/val.h>
+	__isl_give isl_multi_val *isl_multi_val_range_product(
+		__isl_take isl_multi_val *mv1,
+		__isl_take isl_multi_val *mv2);
+	__isl_give isl_multi_val *isl_multi_val_product(
+		__isl_take isl_multi_val *mv1,
+		__isl_take isl_multi_val *mv2);
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_aff *isl_multi_aff_range_product(
+		__isl_take isl_multi_aff *ma1,
+		__isl_take isl_multi_aff *ma2);
+	__isl_give isl_multi_aff *isl_multi_aff_product(
+		__isl_take isl_multi_aff *ma1,
+		__isl_take isl_multi_aff *ma2);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_range_product(
+		__isl_take isl_multi_pw_aff *mpa1,
+		__isl_take isl_multi_pw_aff *mpa2);
+	__isl_give isl_multi_pw_aff *isl_multi_pw_aff_product(
+		__isl_take isl_multi_pw_aff *mpa1,
+		__isl_take isl_multi_pw_aff *mpa2);
+	__isl_give isl_pw_multi_aff *
+	isl_pw_multi_aff_range_product(
+		__isl_take isl_pw_multi_aff *pma1,
+		__isl_take isl_pw_multi_aff *pma2);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_product(
+		__isl_take isl_pw_multi_aff *pma1,
+		__isl_take isl_pw_multi_aff *pma2);
+
+The above functions compute the cross product of the given
+sets, relations or functions.  The domains and ranges of the results
+are wrapped maps between domains and ranges of the inputs.
+To obtain a ``flat'' product, use the following functions
+instead.
+
+	#include <isl/set.h>
+	__isl_give isl_basic_set *isl_basic_set_flat_product(
+		__isl_take isl_basic_set *bset1,
+		__isl_take isl_basic_set *bset2);
+	__isl_give isl_set *isl_set_flat_product(
+		__isl_take isl_set *set1,
+		__isl_take isl_set *set2);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_map *isl_basic_map_flat_range_product(
+		__isl_take isl_basic_map *bmap1,
+		__isl_take isl_basic_map *bmap2);
+	__isl_give isl_map *isl_map_flat_domain_product(
+		__isl_take isl_map *map1,
+		__isl_take isl_map *map2);
+	__isl_give isl_map *isl_map_flat_range_product(
+		__isl_take isl_map *map1,
+		__isl_take isl_map *map2);
+	__isl_give isl_basic_map *isl_basic_map_flat_product(
+		__isl_take isl_basic_map *bmap1,
+		__isl_take isl_basic_map *bmap2);
+	__isl_give isl_map *isl_map_flat_product(
+		__isl_take isl_map *map1,
+		__isl_take isl_map *map2);
+
+	#include <isl/union_map.h>
+	__isl_give isl_union_map *
+	isl_union_map_flat_range_product(
+		__isl_take isl_union_map *umap1,
+		__isl_take isl_union_map *umap2);
+
+	#include <isl/val.h>
+	__isl_give isl_multi_val *isl_multi_val_flat_range_product(
+		__isl_take isl_multi_val *mv1,
+		__isl_take isl_multi_aff *mv2);
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_aff *isl_multi_aff_flat_range_product(
+		__isl_take isl_multi_aff *ma1,
+		__isl_take isl_multi_aff *ma2);
+	__isl_give isl_pw_multi_aff *
+	isl_pw_multi_aff_flat_range_product(
+		__isl_take isl_pw_multi_aff *pma1,
+		__isl_take isl_pw_multi_aff *pma2);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_flat_range_product(
+		__isl_take isl_multi_pw_aff *mpa1,
+		__isl_take isl_multi_pw_aff *mpa2);
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_flat_range_product(
+		__isl_take isl_union_pw_multi_aff *upma1,
+		__isl_take isl_union_pw_multi_aff *upma2);
+
+	#include <isl/space.h>
+	__isl_give isl_space *isl_space_factor_domain(
+		__isl_take isl_space *space);
+	__isl_give isl_space *isl_space_factor_range(
+		__isl_take isl_space *space);
+	__isl_give isl_space *isl_space_domain_factor_domain(
+		__isl_take isl_space *space);
+	__isl_give isl_space *isl_space_domain_factor_range(
+		__isl_take isl_space *space);
+	__isl_give isl_space *isl_space_range_factor_domain(
+		__isl_take isl_space *space);
+	__isl_give isl_space *isl_space_range_factor_range(
+		__isl_take isl_space *space);
+
+The functions C<isl_space_range_factor_domain> and
+C<isl_space_range_factor_range> extract the two arguments from
+the result of a call to C<isl_space_range_product>.
+
+The arguments of a call to C<isl_map_range_product> can be extracted
+from the result using the following functions.
+
+	#include <isl/map.h>
+	__isl_give isl_map *isl_map_factor_domain(
+		__isl_take isl_map *map);
+	__isl_give isl_map *isl_map_factor_range(
+		__isl_take isl_map *map);
+	__isl_give isl_map *isl_map_domain_factor_domain(
+		__isl_take isl_map *map);
+	__isl_give isl_map *isl_map_domain_factor_range(
+		__isl_take isl_map *map);
+	__isl_give isl_map *isl_map_range_factor_domain(
+		__isl_take isl_map *map);
+	__isl_give isl_map *isl_map_range_factor_range(
+		__isl_take isl_map *map);
+
+	#include <isl/union_map.h>
+	__isl_give isl_union_map *isl_union_map_factor_domain(
+		__isl_take isl_union_map *umap);
+	__isl_give isl_union_map *isl_union_map_factor_range(
+		__isl_take isl_union_map *umap);
+	__isl_give isl_union_map *
+	isl_union_map_domain_factor_domain(
+		__isl_take isl_union_map *umap);
+	__isl_give isl_union_map *
+	isl_union_map_domain_factor_range(
+		__isl_take isl_union_map *umap);
+	__isl_give isl_union_map *
+	isl_union_map_range_factor_range(
+		__isl_take isl_union_map *umap);
+
+	#include <isl/val.h>
+	__isl_give isl_multi_val *
+	isl_multi_val_range_factor_domain(
+		__isl_take isl_multi_val *mv);
+	__isl_give isl_multi_val *
+	isl_multi_val_range_factor_range(
+		__isl_take isl_multi_val *mv);
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_aff *
+	isl_multi_aff_range_factor_domain(
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_multi_aff *
+	isl_multi_aff_range_factor_range(
+		__isl_take isl_multi_aff *ma);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_range_factor_domain(
+		__isl_take isl_multi_pw_aff *mpa);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_range_factor_range(
+		__isl_take isl_multi_pw_aff *mpa);
+
+The splice functions are a generalization of the flat product functions,
+where the second argument may be inserted at any position inside
+the first argument rather than being placed at the end.
+
+	#include <isl/val.h>
+	__isl_give isl_multi_val *isl_multi_val_range_splice(
+		__isl_take isl_multi_val *mv1, unsigned pos,
+		__isl_take isl_multi_val *mv2);
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_aff *isl_multi_aff_range_splice(
+		__isl_take isl_multi_aff *ma1, unsigned pos,
+		__isl_take isl_multi_aff *ma2);
+	__isl_give isl_multi_aff *isl_multi_aff_splice(
+		__isl_take isl_multi_aff *ma1,
+		unsigned in_pos, unsigned out_pos,
+		__isl_take isl_multi_aff *ma2);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_range_splice(
+		__isl_take isl_multi_pw_aff *mpa1, unsigned pos,
+		__isl_take isl_multi_pw_aff *mpa2);
+	__isl_give isl_multi_pw_aff *isl_multi_pw_aff_splice(
+		__isl_take isl_multi_pw_aff *mpa1,
+		unsigned in_pos, unsigned out_pos,
+		__isl_take isl_multi_pw_aff *mpa2);
+
+=item * Simplification
+
+When applied to a set or relation,
+the gist operation returns a set or relation that has the
+same intersection with the context as the input set or relation.
+Any implicit equality in the intersection is made explicit in the result,
+while all inequalities that are redundant with respect to the intersection
+are removed.
+In case of union sets and relations, the gist operation is performed
+per space.
+
+When applied to a function,
+the gist operation applies the set gist operation to each of
+the cells in the domain of the input piecewise expression.
+The context is also exploited
+to simplify the expression associated to each cell.
+
+	#include <isl/set.h>
+	__isl_give isl_basic_set *isl_basic_set_gist(
+		__isl_take isl_basic_set *bset,
+		__isl_take isl_basic_set *context);
+	__isl_give isl_set *isl_set_gist(__isl_take isl_set *set,
+		__isl_take isl_set *context);
+	__isl_give isl_set *isl_set_gist_params(
+		__isl_take isl_set *set,
+		__isl_take isl_set *context);
+
+	#include <isl/map.h>
+	__isl_give isl_basic_map *isl_basic_map_gist(
+		__isl_take isl_basic_map *bmap,
+		__isl_take isl_basic_map *context);
+	__isl_give isl_map *isl_map_gist(__isl_take isl_map *map,
+		__isl_take isl_map *context);
+	__isl_give isl_map *isl_map_gist_params(
+		__isl_take isl_map *map,
+		__isl_take isl_set *context);
+	__isl_give isl_map *isl_map_gist_domain(
+		__isl_take isl_map *map,
+		__isl_take isl_set *context);
+	__isl_give isl_map *isl_map_gist_range(
+		__isl_take isl_map *map,
+		__isl_take isl_set *context);
+
+	#include <isl/union_set.h>
+	__isl_give isl_union_set *isl_union_set_gist(
+		__isl_take isl_union_set *uset,
+		__isl_take isl_union_set *context);
+	__isl_give isl_union_set *isl_union_set_gist_params(
+		__isl_take isl_union_set *uset,
+		__isl_take isl_set *set);
+
+	#include <isl/union_map.h>
+	__isl_give isl_union_map *isl_union_map_gist(
+		__isl_take isl_union_map *umap,
+		__isl_take isl_union_map *context);
+	__isl_give isl_union_map *isl_union_map_gist_params(
+		__isl_take isl_union_map *umap,
+		__isl_take isl_set *set);
+	__isl_give isl_union_map *isl_union_map_gist_domain(
+		__isl_take isl_union_map *umap,
+		__isl_take isl_union_set *uset);
+	__isl_give isl_union_map *isl_union_map_gist_range(
+		__isl_take isl_union_map *umap,
+		__isl_take isl_union_set *uset);
+
+	#include <isl/aff.h>
+	__isl_give isl_aff *isl_aff_gist_params(
+		__isl_take isl_aff *aff,
+		__isl_take isl_set *context);
+	__isl_give isl_aff *isl_aff_gist(__isl_take isl_aff *aff,
+		__isl_take isl_set *context);
+	__isl_give isl_multi_aff *isl_multi_aff_gist_params(
+		__isl_take isl_multi_aff *maff,
+		__isl_take isl_set *context);
+	__isl_give isl_multi_aff *isl_multi_aff_gist(
+		__isl_take isl_multi_aff *maff,
+		__isl_take isl_set *context);
+	__isl_give isl_pw_aff *isl_pw_aff_gist_params(
+		__isl_take isl_pw_aff *pwaff,
+		__isl_take isl_set *context);
+	__isl_give isl_pw_aff *isl_pw_aff_gist(
+		__isl_take isl_pw_aff *pwaff,
+		__isl_take isl_set *context);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_gist_params(
+		__isl_take isl_pw_multi_aff *pma,
+		__isl_take isl_set *set);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_gist(
+		__isl_take isl_pw_multi_aff *pma,
+		__isl_take isl_set *set);
+	__isl_give isl_multi_pw_aff *isl_multi_pw_aff_gist_params(
+		__isl_take isl_multi_pw_aff *mpa,
+		__isl_take isl_set *set);
+	__isl_give isl_multi_pw_aff *isl_multi_pw_aff_gist(
+		__isl_take isl_multi_pw_aff *mpa,
+		__isl_take isl_set *set);
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_gist_params(
+		__isl_take isl_union_pw_multi_aff *upma,
+		__isl_take isl_set *context);
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_gist(
+		__isl_take isl_union_pw_multi_aff *upma,
+		__isl_take isl_union_set *context);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_qpolynomial *isl_qpolynomial_gist_params(
+		__isl_take isl_qpolynomial *qp,
+		__isl_take isl_set *context);
+	__isl_give isl_qpolynomial *isl_qpolynomial_gist(
+		__isl_take isl_qpolynomial *qp,
+		__isl_take isl_set *context);
+	__isl_give isl_qpolynomial_fold *
+	isl_qpolynomial_fold_gist_params(
+		__isl_take isl_qpolynomial_fold *fold,
+		__isl_take isl_set *context);
+	__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_gist(
+		__isl_take isl_qpolynomial_fold *fold,
+		__isl_take isl_set *context);
+	__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_gist_params(
+		__isl_take isl_pw_qpolynomial *pwqp,
+		__isl_take isl_set *context);
+	__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_gist(
+		__isl_take isl_pw_qpolynomial *pwqp,
+		__isl_take isl_set *context);
+	__isl_give isl_pw_qpolynomial_fold *
+	isl_pw_qpolynomial_fold_gist(
+		__isl_take isl_pw_qpolynomial_fold *pwf,
+		__isl_take isl_set *context);
+	__isl_give isl_pw_qpolynomial_fold *
+	isl_pw_qpolynomial_fold_gist_params(
+		__isl_take isl_pw_qpolynomial_fold *pwf,
+		__isl_take isl_set *context);
+	__isl_give isl_union_pw_qpolynomial *
+	isl_union_pw_qpolynomial_gist_params(
+		__isl_take isl_union_pw_qpolynomial *upwqp,
+		__isl_take isl_set *context);
+	__isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_gist(
+		__isl_take isl_union_pw_qpolynomial *upwqp,
+		__isl_take isl_union_set *context);
+	__isl_give isl_union_pw_qpolynomial_fold *
+	isl_union_pw_qpolynomial_fold_gist(
+		__isl_take isl_union_pw_qpolynomial_fold *upwf,
+		__isl_take isl_union_set *context);
+	__isl_give isl_union_pw_qpolynomial_fold *
+	isl_union_pw_qpolynomial_fold_gist_params(
+		__isl_take isl_union_pw_qpolynomial_fold *upwf,
+		__isl_take isl_set *context);
+
+=item * Binary Arithmethic Operations
+
+	#include <isl/aff.h>
+	__isl_give isl_aff *isl_aff_add(
+		__isl_take isl_aff *aff1,
+		__isl_take isl_aff *aff2);
+	__isl_give isl_multi_aff *isl_multi_aff_add(
+		__isl_take isl_multi_aff *maff1,
+		__isl_take isl_multi_aff *maff2);
+	__isl_give isl_pw_aff *isl_pw_aff_add(
+		__isl_take isl_pw_aff *pwaff1,
+		__isl_take isl_pw_aff *pwaff2);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_add(
+		__isl_take isl_pw_multi_aff *pma1,
+		__isl_take isl_pw_multi_aff *pma2);
+	__isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_add(
+		__isl_take isl_union_pw_multi_aff *upma1,
+		__isl_take isl_union_pw_multi_aff *upma2);
+	__isl_give isl_pw_aff *isl_pw_aff_min(
+		__isl_take isl_pw_aff *pwaff1,
+		__isl_take isl_pw_aff *pwaff2);
+	__isl_give isl_pw_aff *isl_pw_aff_max(
+		__isl_take isl_pw_aff *pwaff1,
+		__isl_take isl_pw_aff *pwaff2);
+	__isl_give isl_aff *isl_aff_sub(
+		__isl_take isl_aff *aff1,
+		__isl_take isl_aff *aff2);
+	__isl_give isl_multi_aff *isl_multi_aff_sub(
+		__isl_take isl_multi_aff *ma1,
+		__isl_take isl_multi_aff *ma2);
+	__isl_give isl_pw_aff *isl_pw_aff_sub(
+		__isl_take isl_pw_aff *pwaff1,
+		__isl_take isl_pw_aff *pwaff2);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_sub(
+		__isl_take isl_pw_multi_aff *pma1,
+		__isl_take isl_pw_multi_aff *pma2);
+	__isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_sub(
+		__isl_take isl_union_pw_multi_aff *upma1,
+		__isl_take isl_union_pw_multi_aff *upma2);
+
+C<isl_aff_sub> subtracts the second argument from the first.
+
+	#include <isl/polynomial.h>
+	__isl_give isl_qpolynomial *isl_qpolynomial_add(
+		__isl_take isl_qpolynomial *qp1,
+		__isl_take isl_qpolynomial *qp2);
+	__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_add(
+		__isl_take isl_pw_qpolynomial *pwqp1,
+		__isl_take isl_pw_qpolynomial *pwqp2);
+	__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_add_disjoint(
+		__isl_take isl_pw_qpolynomial *pwqp1,
+		__isl_take isl_pw_qpolynomial *pwqp2);
+	__isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_add(
+		__isl_take isl_pw_qpolynomial_fold *pwf1,
+		__isl_take isl_pw_qpolynomial_fold *pwf2);
+	__isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_add(
+		__isl_take isl_union_pw_qpolynomial *upwqp1,
+		__isl_take isl_union_pw_qpolynomial *upwqp2);
+	__isl_give isl_qpolynomial *isl_qpolynomial_sub(
+		__isl_take isl_qpolynomial *qp1,
+		__isl_take isl_qpolynomial *qp2);
+	__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_sub(
+		__isl_take isl_pw_qpolynomial *pwqp1,
+		__isl_take isl_pw_qpolynomial *pwqp2);
+	__isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_sub(
+		__isl_take isl_union_pw_qpolynomial *upwqp1,
+		__isl_take isl_union_pw_qpolynomial *upwqp2);
+	__isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_fold(
+		__isl_take isl_pw_qpolynomial_fold *pwf1,
+		__isl_take isl_pw_qpolynomial_fold *pwf2);
+	__isl_give isl_union_pw_qpolynomial_fold *
+	isl_union_pw_qpolynomial_fold_fold(
+		__isl_take isl_union_pw_qpolynomial_fold *upwf1,
+		__isl_take isl_union_pw_qpolynomial_fold *upwf2);
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_aff *isl_pw_aff_union_add(
+		__isl_take isl_pw_aff *pwaff1,
+		__isl_take isl_pw_aff *pwaff2);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_union_add(
+		__isl_take isl_pw_multi_aff *pma1,
+		__isl_take isl_pw_multi_aff *pma2);
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_union_add(
+		__isl_take isl_union_pw_multi_aff *upma1,
+		__isl_take isl_union_pw_multi_aff *upma2);
+	__isl_give isl_pw_aff *isl_pw_aff_union_min(
+		__isl_take isl_pw_aff *pwaff1,
+		__isl_take isl_pw_aff *pwaff2);
+	__isl_give isl_pw_aff *isl_pw_aff_union_max(
+		__isl_take isl_pw_aff *pwaff1,
+		__isl_take isl_pw_aff *pwaff2);
+
+The function C<isl_pw_aff_union_max> computes a piecewise quasi-affine
+expression with a domain that is the union of those of C<pwaff1> and
+C<pwaff2> and such that on each cell, the quasi-affine expression is
+the maximum of those of C<pwaff1> and C<pwaff2>.  If only one of
+C<pwaff1> or C<pwaff2> is defined on a given cell, then the
+associated expression is the defined one.
+This in contrast to the C<isl_pw_aff_max> function, which is
+only defined on the shared definition domain of the arguments.
+
+	#include <isl/val.h>
+	__isl_give isl_multi_val *isl_multi_val_add_val(
+		__isl_take isl_multi_val *mv,
+		__isl_take isl_val *v);
+	__isl_give isl_multi_val *isl_multi_val_mod_val(
+		__isl_take isl_multi_val *mv,
+		__isl_take isl_val *v);
+	__isl_give isl_multi_val *isl_multi_val_scale_val(
+		__isl_take isl_multi_val *mv,
+		__isl_take isl_val *v);
+	__isl_give isl_multi_val *isl_multi_val_scale_down_val(
+		__isl_take isl_multi_val *mv,
+		__isl_take isl_val *v);
+
+	#include <isl/aff.h>
+	__isl_give isl_aff *isl_aff_mod_val(__isl_take isl_aff *aff,
+		__isl_take isl_val *mod);
+	__isl_give isl_pw_aff *isl_pw_aff_mod_val(
+		__isl_take isl_pw_aff *pa,
+		__isl_take isl_val *mod);
+	__isl_give isl_aff *isl_aff_scale_val(__isl_take isl_aff *aff,
+		__isl_take isl_val *v);
+	__isl_give isl_multi_aff *isl_multi_aff_scale_val(
+		__isl_take isl_multi_aff *ma,
+		__isl_take isl_val *v);
+	__isl_give isl_pw_aff *isl_pw_aff_scale_val(
+		__isl_take isl_pw_aff *pa, __isl_take isl_val *v);
+	__isl_give isl_multi_pw_aff *isl_multi_pw_aff_scale_val(
+		__isl_take isl_multi_pw_aff *mpa,
+		__isl_take isl_val *v);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_scale_val(
+		__isl_take isl_pw_multi_aff *pma,
+		__isl_take isl_val *v);
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_scale_val(
+		__isl_take isl_union_pw_multi_aff *upma,
+		__isl_take isl_val *val);
+	__isl_give isl_aff *isl_aff_scale_down_ui(
+		__isl_take isl_aff *aff, unsigned f);
+	__isl_give isl_aff *isl_aff_scale_down_val(
+		__isl_take isl_aff *aff, __isl_take isl_val *v);
+	__isl_give isl_multi_aff *isl_multi_aff_scale_down_val(
+		__isl_take isl_multi_aff *ma,
+		__isl_take isl_val *v);
+	__isl_give isl_pw_aff *isl_pw_aff_scale_down_val(
+		__isl_take isl_pw_aff *pa,
+		__isl_take isl_val *f);
+	__isl_give isl_multi_pw_aff *isl_multi_pw_aff_scale_down_val(
+		__isl_take isl_multi_pw_aff *mpa,
+		__isl_take isl_val *v);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_scale_down_val(
+		__isl_take isl_pw_multi_aff *pma,
+		__isl_take isl_val *v);
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_scale_down_val(
+		__isl_take isl_union_pw_multi_aff *upma,
+		__isl_take isl_val *val);
+
+	#include <isl/polynomial.h>
+	__isl_give isl_qpolynomial *isl_qpolynomial_scale_val(
+		__isl_take isl_qpolynomial *qp,
+		__isl_take isl_val *v);
+	__isl_give isl_qpolynomial_fold *
+	isl_qpolynomial_fold_scale_val(
+		__isl_take isl_qpolynomial_fold *fold,
+		__isl_take isl_val *v);
+	__isl_give isl_pw_qpolynomial *
+	isl_pw_qpolynomial_scale_val(
+		__isl_take isl_pw_qpolynomial *pwqp,
+		__isl_take isl_val *v);
+	__isl_give isl_pw_qpolynomial_fold *
+	isl_pw_qpolynomial_fold_scale_val(
+		__isl_take isl_pw_qpolynomial_fold *pwf,
+		__isl_take isl_val *v);
+	__isl_give isl_union_pw_qpolynomial *
+	isl_union_pw_qpolynomial_scale_val(
+		__isl_take isl_union_pw_qpolynomial *upwqp,
+		__isl_take isl_val *v);
+	__isl_give isl_union_pw_qpolynomial_fold *
+	isl_union_pw_qpolynomial_fold_scale_val(
+		__isl_take isl_union_pw_qpolynomial_fold *upwf,
+		__isl_take isl_val *v);
+	__isl_give isl_qpolynomial *
+	isl_qpolynomial_scale_down_val(
+		__isl_take isl_qpolynomial *qp,
+		__isl_take isl_val *v);
+	__isl_give isl_qpolynomial_fold *
+	isl_qpolynomial_fold_scale_down_val(
+		__isl_take isl_qpolynomial_fold *fold,
+		__isl_take isl_val *v);
+	__isl_give isl_pw_qpolynomial *
+	isl_pw_qpolynomial_scale_down_val(
+		__isl_take isl_pw_qpolynomial *pwqp,
+		__isl_take isl_val *v);
+	__isl_give isl_pw_qpolynomial_fold *
+	isl_pw_qpolynomial_fold_scale_down_val(
+		__isl_take isl_pw_qpolynomial_fold *pwf,
+		__isl_take isl_val *v);
+	__isl_give isl_union_pw_qpolynomial *
+	isl_union_pw_qpolynomial_scale_down_val(
+		__isl_take isl_union_pw_qpolynomial *upwqp,
+		__isl_take isl_val *v);
+	__isl_give isl_union_pw_qpolynomial_fold *
+	isl_union_pw_qpolynomial_fold_scale_down_val(
+		__isl_take isl_union_pw_qpolynomial_fold *upwf,
+		__isl_take isl_val *v);
+
+	#include <isl/val.h>
+	__isl_give isl_multi_val *isl_multi_val_scale_multi_val(
+		__isl_take isl_multi_val *mv1,
+		__isl_take isl_multi_val *mv2);
+	__isl_give isl_multi_val *
+	isl_multi_val_scale_down_multi_val(
+		__isl_take isl_multi_val *mv1,
+		__isl_take isl_multi_val *mv2);
+
+	#include <isl/aff.h>
+	__isl_give isl_multi_aff *isl_multi_aff_scale_multi_val(
+		__isl_take isl_multi_aff *ma,
+		__isl_take isl_multi_val *mv);
+	__isl_give isl_pw_multi_aff *
+	isl_pw_multi_aff_scale_multi_val(
+		__isl_take isl_pw_multi_aff *pma,
+		__isl_take isl_multi_val *mv);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_scale_multi_val(
+		__isl_take isl_multi_pw_aff *mpa,
+		__isl_take isl_multi_val *mv);
+	__isl_give isl_union_pw_multi_aff *
+	isl_union_pw_multi_aff_scale_multi_val(
+		__isl_take isl_union_pw_multi_aff *upma,
+		__isl_take isl_multi_val *mv);
+	__isl_give isl_multi_aff *
+	isl_multi_aff_scale_down_multi_val(
+		__isl_take isl_multi_aff *ma,
+		__isl_take isl_multi_val *mv);
+	__isl_give isl_multi_pw_aff *
+	isl_multi_pw_aff_scale_down_multi_val(
+		__isl_take isl_multi_pw_aff *mpa,
+		__isl_take isl_multi_val *mv);
+
+C<isl_multi_aff_scale_multi_val> scales the elements of C<ma>
+by the corresponding elements of C<mv>.
+
+	#include <isl/aff.h>
+	__isl_give isl_aff *isl_aff_mul(
+		__isl_take isl_aff *aff1,
+		__isl_take isl_aff *aff2);
+	__isl_give isl_aff *isl_aff_div(
+		__isl_take isl_aff *aff1,
+		__isl_take isl_aff *aff2);
+	__isl_give isl_pw_aff *isl_pw_aff_mul(
+		__isl_take isl_pw_aff *pwaff1,
+		__isl_take isl_pw_aff *pwaff2);
+	__isl_give isl_pw_aff *isl_pw_aff_div(
+		__isl_take isl_pw_aff *pa1,
+		__isl_take isl_pw_aff *pa2);
+	__isl_give isl_pw_aff *isl_pw_aff_tdiv_q(
+		__isl_take isl_pw_aff *pa1,
+		__isl_take isl_pw_aff *pa2);
+	__isl_give isl_pw_aff *isl_pw_aff_tdiv_r(
+		__isl_take isl_pw_aff *pa1,
+		__isl_take isl_pw_aff *pa2);
+
+When multiplying two affine expressions, at least one of the two needs
+to be a constant.  Similarly, when dividing an affine expression by another,
+the second expression needs to be a constant.
+C<isl_pw_aff_tdiv_q> computes the quotient of an integer division with
+rounding towards zero.  C<isl_pw_aff_tdiv_r> computes the corresponding
+remainder.
+
+	#include <isl/polynomial.h>
+	__isl_give isl_qpolynomial *isl_qpolynomial_mul(
+		__isl_take isl_qpolynomial *qp1,
+		__isl_take isl_qpolynomial *qp2);
+	__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_mul(
+		__isl_take isl_pw_qpolynomial *pwqp1,
+		__isl_take isl_pw_qpolynomial *pwqp2);
+	__isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_mul(
+		__isl_take isl_union_pw_qpolynomial *upwqp1,
+		__isl_take isl_union_pw_qpolynomial *upwqp2);
+
+=back
+
+=head3 Lexicographic Optimization
+
+Given a (basic) set C<set> (or C<bset>) and a zero-dimensional domain C<dom>,
+the following functions
+compute a set that contains the lexicographic minimum or maximum
+of the elements in C<set> (or C<bset>) for those values of the parameters
+that satisfy C<dom>.
+If C<empty> is not C<NULL>, then C<*empty> is assigned a set
+that contains the parameter values in C<dom> for which C<set> (or C<bset>)
+has no elements.
+In other words, the union of the parameter values
+for which the result is non-empty and of C<*empty>
+is equal to C<dom>.
+
+	#include <isl/set.h>
+	__isl_give isl_set *isl_basic_set_partial_lexmin(
+		__isl_take isl_basic_set *bset,
+		__isl_take isl_basic_set *dom,
+		__isl_give isl_set **empty);
+	__isl_give isl_set *isl_basic_set_partial_lexmax(
+		__isl_take isl_basic_set *bset,
+		__isl_take isl_basic_set *dom,
+		__isl_give isl_set **empty);
+	__isl_give isl_set *isl_set_partial_lexmin(
+		__isl_take isl_set *set, __isl_take isl_set *dom,
+		__isl_give isl_set **empty);
+	__isl_give isl_set *isl_set_partial_lexmax(
+		__isl_take isl_set *set, __isl_take isl_set *dom,
+		__isl_give isl_set **empty);
+
+Given a (basic) set C<set> (or C<bset>), the following functions simply
+return a set containing the lexicographic minimum or maximum
+of the elements in C<set> (or C<bset>).
+In case of union sets, the optimum is computed per space.
+
+	#include <isl/set.h>
+	__isl_give isl_set *isl_basic_set_lexmin(
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_set *isl_basic_set_lexmax(
+		__isl_take isl_basic_set *bset);
+	__isl_give isl_set *isl_set_lexmin(
+		__isl_take isl_set *set);
+	__isl_give isl_set *isl_set_lexmax(
+		__isl_take isl_set *set);
+	__isl_give isl_union_set *isl_union_set_lexmin(
+		__isl_take isl_union_set *uset);
+	__isl_give isl_union_set *isl_union_set_lexmax(
+		__isl_take isl_union_set *uset);
+
+Given a (basic) relation C<map> (or C<bmap>) and a domain C<dom>,
+the following functions
+compute a relation that maps each element of C<dom>
+to the single lexicographic minimum or maximum
+of the elements that are associated to that same
+element in C<map> (or C<bmap>).
+If C<empty> is not C<NULL>, then C<*empty> is assigned a set
+that contains the elements in C<dom> that do not map
+to any elements in C<map> (or C<bmap>).
+In other words, the union of the domain of the result and of C<*empty>
+is equal to C<dom>.
+
+	#include <isl/map.h>
+	__isl_give isl_map *isl_basic_map_partial_lexmax(
+		__isl_take isl_basic_map *bmap,
+		__isl_take isl_basic_set *dom,
+		__isl_give isl_set **empty);
+	__isl_give isl_map *isl_basic_map_partial_lexmin(
+		__isl_take isl_basic_map *bmap,
+		__isl_take isl_basic_set *dom,
+		__isl_give isl_set **empty);
+	__isl_give isl_map *isl_map_partial_lexmax(
+		__isl_take isl_map *map, __isl_take isl_set *dom,
+		__isl_give isl_set **empty);
+	__isl_give isl_map *isl_map_partial_lexmin(
+		__isl_take isl_map *map, __isl_take isl_set *dom,
+		__isl_give isl_set **empty);
+
+Given a (basic) map C<map> (or C<bmap>), the following functions simply
+return a map mapping each element in the domain of
+C<map> (or C<bmap>) to the lexicographic minimum or maximum
+of all elements associated to that element.
+In case of union relations, the optimum is computed per space.
+
+	#include <isl/map.h>
+	__isl_give isl_map *isl_basic_map_lexmin(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_map *isl_basic_map_lexmax(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_map *isl_map_lexmin(
+		__isl_take isl_map *map);
+	__isl_give isl_map *isl_map_lexmax(
+		__isl_take isl_map *map);
+	__isl_give isl_union_map *isl_union_map_lexmin(
+		__isl_take isl_union_map *umap);
+	__isl_give isl_union_map *isl_union_map_lexmax(
+		__isl_take isl_union_map *umap);
+
+The following functions return their result in the form of
+a piecewise multi-affine expression,
+but are otherwise equivalent to the corresponding functions
+returning a basic set or relation.
+
+	#include <isl/set.h>
+	__isl_give isl_pw_multi_aff *
+	isl_basic_set_partial_lexmin_pw_multi_aff(
+		__isl_take isl_basic_set *bset,
+		__isl_take isl_basic_set *dom,
+		__isl_give isl_set **empty);
+	__isl_give isl_pw_multi_aff *
+	isl_basic_set_partial_lexmax_pw_multi_aff(
+		__isl_take isl_basic_set *bset,
+		__isl_take isl_basic_set *dom,
+		__isl_give isl_set **empty);
+	__isl_give isl_pw_multi_aff *isl_set_lexmin_pw_multi_aff(
+		__isl_take isl_set *set);
+	__isl_give isl_pw_multi_aff *isl_set_lexmax_pw_multi_aff(
+		__isl_take isl_set *set);
+
+	#include <isl/map.h>
+	__isl_give isl_pw_multi_aff *
+	isl_basic_map_lexmin_pw_multi_aff(
+		__isl_take isl_basic_map *bmap);
+	__isl_give isl_pw_multi_aff *
+	isl_basic_map_partial_lexmin_pw_multi_aff(
+		__isl_take isl_basic_map *bmap,
+		__isl_take isl_basic_set *dom,
+		__isl_give isl_set **empty);
+	__isl_give isl_pw_multi_aff *
+	isl_basic_map_partial_lexmax_pw_multi_aff(
+		__isl_take isl_basic_map *bmap,
+		__isl_take isl_basic_set *dom,
+		__isl_give isl_set **empty);
+	__isl_give isl_pw_multi_aff *isl_map_lexmin_pw_multi_aff(
+		__isl_take isl_map *map);
+	__isl_give isl_pw_multi_aff *isl_map_lexmax_pw_multi_aff(
+		__isl_take isl_map *map);
+
+The following functions return the lexicographic minimum or maximum
+on the shared domain of the inputs and the single defined function
+on those parts of the domain where only a single function is defined.
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_union_lexmin(
+		__isl_take isl_pw_multi_aff *pma1,
+		__isl_take isl_pw_multi_aff *pma2);
+	__isl_give isl_pw_multi_aff *isl_pw_multi_aff_union_lexmax(
+		__isl_take isl_pw_multi_aff *pma1,
+		__isl_take isl_pw_multi_aff *pma2);
+
+=head2 Ternary Operations
+
+	#include <isl/aff.h>
+	__isl_give isl_pw_aff *isl_pw_aff_cond(
+		__isl_take isl_pw_aff *cond,
+		__isl_take isl_pw_aff *pwaff_true,
+		__isl_take isl_pw_aff *pwaff_false);
+
+The function C<isl_pw_aff_cond> performs a conditional operator
+and returns an expression that is equal to C<pwaff_true>
+for elements where C<cond> is non-zero and equal to C<pwaff_false> for elements
+where C<cond> is zero.
+
+=head2 Lists
+
+Lists are defined over several element types, including
+C<isl_val>, C<isl_id>, C<isl_aff>, C<isl_pw_aff>, C<isl_constraint>,
+C<isl_basic_set>, C<isl_set>, C<isl_ast_expr> and C<isl_ast_node>.
+Here we take lists of C<isl_set>s as an example.
+Lists can be created, copied, modified and freed using the following functions.
+
+	#include <isl/set.h>
+	__isl_give isl_set_list *isl_set_list_from_set(
+		__isl_take isl_set *el);
+	__isl_give isl_set_list *isl_set_list_alloc(
+		isl_ctx *ctx, int n);
+	__isl_give isl_set_list *isl_set_list_copy(
+		__isl_keep isl_set_list *list);
+	__isl_give isl_set_list *isl_set_list_insert(
+		__isl_take isl_set_list *list, unsigned pos,
+		__isl_take isl_set *el);
+	__isl_give isl_set_list *isl_set_list_add(
+		__isl_take isl_set_list *list,
+		__isl_take isl_set *el);
+	__isl_give isl_set_list *isl_set_list_drop(
+		__isl_take isl_set_list *list,
+		unsigned first, unsigned n);
+	__isl_give isl_set_list *isl_set_list_set_set(
+		__isl_take isl_set_list *list, int index,
+		__isl_take isl_set *set);
+	__isl_give isl_set_list *isl_set_list_concat(
+		__isl_take isl_set_list *list1,
+		__isl_take isl_set_list *list2);
+	__isl_give isl_set_list *isl_set_list_sort(
+		__isl_take isl_set_list *list,
+		int (*cmp)(__isl_keep isl_set *a,
+			__isl_keep isl_set *b, void *user),
+		void *user);
+	__isl_null isl_set_list *isl_set_list_free(
+		__isl_take isl_set_list *list);
+
+C<isl_set_list_alloc> creates an empty list with a capacity for
+C<n> elements.  C<isl_set_list_from_set> creates a list with a single
+element.
+
+Lists can be inspected using the following functions.
+
+	#include <isl/set.h>
+	int isl_set_list_n_set(__isl_keep isl_set_list *list);
+	__isl_give isl_set *isl_set_list_get_set(
+		__isl_keep isl_set_list *list, int index);
+	int isl_set_list_foreach(__isl_keep isl_set_list *list,
+		int (*fn)(__isl_take isl_set *el, void *user),
+		void *user);
+	int isl_set_list_foreach_scc(__isl_keep isl_set_list *list,
+		int (*follows)(__isl_keep isl_set *a,
+			__isl_keep isl_set *b, void *user),
+		void *follows_user
+		int (*fn)(__isl_take isl_set *el, void *user),
+		void *fn_user);
+
+The function C<isl_set_list_foreach_scc> calls C<fn> on each of the
+strongly connected components of the graph with as vertices the elements
+of C<list> and a directed edge from vertex C<b> to vertex C<a>
+iff C<follows(a, b)> returns C<1>.  The callbacks C<follows> and C<fn>
+should return C<-1> on error.
+
+Lists can be printed using
+
+	#include <isl/set.h>
+	__isl_give isl_printer *isl_printer_print_set_list(
+		__isl_take isl_printer *p,
+		__isl_keep isl_set_list *list);
+
+=head2 Associative arrays
+
+Associative arrays map isl objects of a specific type to isl objects
+of some (other) specific type.  They are defined for several pairs
+of types, including (C<isl_map>, C<isl_basic_set>),
+(C<isl_id>, C<isl_ast_expr>) and.
+(C<isl_id>, C<isl_pw_aff>).
+Here, we take associative arrays that map C<isl_id>s to C<isl_ast_expr>s
+as an example.
+
+Associative arrays can be created, copied and freed using
+the following functions.
+
+	#include <isl/id_to_ast_expr.h>
+	__isl_give id_to_ast_expr *isl_id_to_ast_expr_alloc(
+		isl_ctx *ctx, int min_size);
+	__isl_give id_to_ast_expr *isl_id_to_ast_expr_copy(
+		__isl_keep id_to_ast_expr *id2expr);
+	__isl_null id_to_ast_expr *isl_id_to_ast_expr_free(
+		__isl_take id_to_ast_expr *id2expr);
+
+The C<min_size> argument to C<isl_id_to_ast_expr_alloc> can be used
+to specify the expected size of the associative array.
+The associative array will be grown automatically as needed.
+
+Associative arrays can be inspected using the following functions.
+
+	#include <isl/id_to_ast_expr.h>
+	int isl_id_to_ast_expr_has(
+		__isl_keep id_to_ast_expr *id2expr,
+		__isl_keep isl_id *key);
+	__isl_give isl_ast_expr *isl_id_to_ast_expr_get(
+		__isl_keep id_to_ast_expr *id2expr,
+		__isl_take isl_id *key);
+	int isl_id_to_ast_expr_foreach(
+		__isl_keep id_to_ast_expr *id2expr,
+		int (*fn)(__isl_take isl_id *key,
+			__isl_take isl_ast_expr *val, void *user),
+		void *user);
+
+They can be modified using the following function.
+
+	#include <isl/id_to_ast_expr.h>
+	__isl_give id_to_ast_expr *isl_id_to_ast_expr_set(
+		__isl_take id_to_ast_expr *id2expr,
+		__isl_take isl_id *key,
+		__isl_take isl_ast_expr *val);
+	__isl_give id_to_ast_expr *isl_id_to_ast_expr_drop(
+		__isl_take id_to_ast_expr *id2expr,
+		__isl_take isl_id *key);
+
+Associative arrays can be printed using the following function.
+
+	#include <isl/id_to_ast_expr.h>
+	__isl_give isl_printer *isl_printer_print_id_to_ast_expr(
+		__isl_take isl_printer *p,
+		__isl_keep id_to_ast_expr *id2expr);
+
+=head2 Vectors
+
+Vectors can be created, copied and freed using the following functions.
+
+	#include <isl/vec.h>
+	__isl_give isl_vec *isl_vec_alloc(isl_ctx *ctx,
+		unsigned size);
+	__isl_give isl_vec *isl_vec_copy(__isl_keep isl_vec *vec);
+	__isl_null isl_vec *isl_vec_free(__isl_take isl_vec *vec);
+
+Note that the elements of a newly created vector may have arbitrary values.
+The elements can be changed and inspected using the following functions.
+
+	int isl_vec_size(__isl_keep isl_vec *vec);
+	__isl_give isl_val *isl_vec_get_element_val(
+		__isl_keep isl_vec *vec, int pos);
+	__isl_give isl_vec *isl_vec_set_element_si(
+		__isl_take isl_vec *vec, int pos, int v);
+	__isl_give isl_vec *isl_vec_set_element_val(
+		__isl_take isl_vec *vec, int pos,
+		__isl_take isl_val *v);
+	__isl_give isl_vec *isl_vec_set_si(__isl_take isl_vec *vec,
+		int v);
+	__isl_give isl_vec *isl_vec_set_val(
+		__isl_take isl_vec *vec, __isl_take isl_val *v);
+	int isl_vec_cmp_element(__isl_keep isl_vec *vec1,
+		__isl_keep isl_vec *vec2, int pos);
+
+C<isl_vec_get_element> will return a negative value if anything went wrong.
+In that case, the value of C<*v> is undefined.
+
+The following function can be used to concatenate two vectors.
+
+	__isl_give isl_vec *isl_vec_concat(__isl_take isl_vec *vec1,
+		__isl_take isl_vec *vec2);
+
+=head2 Matrices
+
+Matrices can be created, copied and freed using the following functions.
+
+	#include <isl/mat.h>
+	__isl_give isl_mat *isl_mat_alloc(isl_ctx *ctx,
+		unsigned n_row, unsigned n_col);
+	__isl_give isl_mat *isl_mat_copy(__isl_keep isl_mat *mat);
+	__isl_null isl_mat *isl_mat_free(__isl_take isl_mat *mat);
+
+Note that the elements of a newly created matrix may have arbitrary values.
+The elements can be changed and inspected using the following functions.
+
+	int isl_mat_rows(__isl_keep isl_mat *mat);
+	int isl_mat_cols(__isl_keep isl_mat *mat);
+	__isl_give isl_val *isl_mat_get_element_val(
+		__isl_keep isl_mat *mat, int row, int col);
+	__isl_give isl_mat *isl_mat_set_element_si(__isl_take isl_mat *mat,
+		int row, int col, int v);
+	__isl_give isl_mat *isl_mat_set_element_val(
+		__isl_take isl_mat *mat, int row, int col,
+		__isl_take isl_val *v);
+
+C<isl_mat_get_element> will return a negative value if anything went wrong.
+In that case, the value of C<*v> is undefined.
+
+The following function can be used to compute the (right) inverse
+of a matrix, i.e., a matrix such that the product of the original
+and the inverse (in that order) is a multiple of the identity matrix.
+The input matrix is assumed to be of full row-rank.
+
+	__isl_give isl_mat *isl_mat_right_inverse(__isl_take isl_mat *mat);
+
+The following function can be used to compute the (right) kernel
+(or null space) of a matrix, i.e., a matrix such that the product of
+the original and the kernel (in that order) is the zero matrix.
+
+	__isl_give isl_mat *isl_mat_right_kernel(__isl_take isl_mat *mat);
+
+=head2 Bounds on Piecewise Quasipolynomials and Piecewise Quasipolynomial Reductions
+
+The following functions determine
+an upper or lower bound on a quasipolynomial over its domain.
+
+	__isl_give isl_pw_qpolynomial_fold *
+	isl_pw_qpolynomial_bound(
+		__isl_take isl_pw_qpolynomial *pwqp,
+		enum isl_fold type, int *tight);
+
+	__isl_give isl_union_pw_qpolynomial_fold *
+	isl_union_pw_qpolynomial_bound(
+		__isl_take isl_union_pw_qpolynomial *upwqp,
+		enum isl_fold type, int *tight);
+
+The C<type> argument may be either C<isl_fold_min> or C<isl_fold_max>.
+If C<tight> is not C<NULL>, then C<*tight> is set to C<1>
+is the returned bound is known be tight, i.e., for each value
+of the parameters there is at least
+one element in the domain that reaches the bound.
+If the domain of C<pwqp> is not wrapping, then the bound is computed
+over all elements in that domain and the result has a purely parametric
+domain.  If the domain of C<pwqp> is wrapping, then the bound is
+computed over the range of the wrapped relation.  The domain of the
+wrapped relation becomes the domain of the result.
+
+=head2 Parametric Vertex Enumeration
+
+The parametric vertex enumeration described in this section
+is mainly intended to be used internally and by the C<barvinok>
+library.
+
+	#include <isl/vertices.h>
+	__isl_give isl_vertices *isl_basic_set_compute_vertices(
+		__isl_keep isl_basic_set *bset);
+
+The function C<isl_basic_set_compute_vertices> performs the
+actual computation of the parametric vertices and the chamber
+decomposition and store the result in an C<isl_vertices> object.
+This information can be queried by either iterating over all
+the vertices or iterating over all the chambers or cells
+and then iterating over all vertices that are active on the chamber.
+
+	int isl_vertices_foreach_vertex(
+		__isl_keep isl_vertices *vertices,
+		int (*fn)(__isl_take isl_vertex *vertex, void *user),
+		void *user);
+
+	int isl_vertices_foreach_cell(
+		__isl_keep isl_vertices *vertices,
+		int (*fn)(__isl_take isl_cell *cell, void *user),
+		void *user);
+	int isl_cell_foreach_vertex(__isl_keep isl_cell *cell,
+		int (*fn)(__isl_take isl_vertex *vertex, void *user),
+		void *user);
+
+Other operations that can be performed on an C<isl_vertices> object are
+the following.
+
+	int isl_vertices_get_n_vertices(
+		__isl_keep isl_vertices *vertices);
+	void isl_vertices_free(__isl_take isl_vertices *vertices);
+
+Vertices can be inspected and destroyed using the following functions.
+
+	int isl_vertex_get_id(__isl_keep isl_vertex *vertex);
+	__isl_give isl_basic_set *isl_vertex_get_domain(
+		__isl_keep isl_vertex *vertex);
+	__isl_give isl_multi_aff *isl_vertex_get_expr(
+		__isl_keep isl_vertex *vertex);
+	void isl_vertex_free(__isl_take isl_vertex *vertex);
+
+C<isl_vertex_get_expr> returns a multiple quasi-affine expression
+describing the vertex in terms of the parameters,
+while C<isl_vertex_get_domain> returns the activity domain
+of the vertex.
+
+Chambers can be inspected and destroyed using the following functions.
+
+	__isl_give isl_basic_set *isl_cell_get_domain(
+		__isl_keep isl_cell *cell);
+	void isl_cell_free(__isl_take isl_cell *cell);
+
+=head1 Polyhedral Compilation Library
+
+This section collects functionality in C<isl> that has been specifically
+designed for use during polyhedral compilation.
+
+=head2 Dependence Analysis
+
+C<isl> contains specialized functionality for performing
+array dataflow analysis.  That is, given a I<sink> access relation
+and a collection of possible I<source> access relations,
+C<isl> can compute relations that describe
+for each iteration of the sink access, which iteration
+of which of the source access relations was the last
+to access the same data element before the given iteration
+of the sink access.
+The resulting dependence relations map source iterations
+to the corresponding sink iterations.
+To compute standard flow dependences, the sink should be
+a read, while the sources should be writes.
+If any of the source accesses are marked as being I<may>
+accesses, then there will be a dependence from the last
+I<must> access B<and> from any I<may> access that follows
+this last I<must> access.
+In particular, if I<all> sources are I<may> accesses,
+then memory based dependence analysis is performed.
+If, on the other hand, all sources are I<must> accesses,
+then value based dependence analysis is performed.
+
+	#include <isl/flow.h>
+
+	typedef int (*isl_access_level_before)(void *first, void *second);
+
+	__isl_give isl_access_info *isl_access_info_alloc(
+		__isl_take isl_map *sink,
+		void *sink_user, isl_access_level_before fn,
+		int max_source);
+	__isl_give isl_access_info *isl_access_info_add_source(
+		__isl_take isl_access_info *acc,
+		__isl_take isl_map *source, int must,
+		void *source_user);
+	__isl_null isl_access_info *isl_access_info_free(
+		__isl_take isl_access_info *acc);
+
+	__isl_give isl_flow *isl_access_info_compute_flow(
+		__isl_take isl_access_info *acc);
+
+	int isl_flow_foreach(__isl_keep isl_flow *deps,
+		int (*fn)(__isl_take isl_map *dep, int must,
+			  void *dep_user, void *user),
+		void *user);
+	__isl_give isl_map *isl_flow_get_no_source(
+		__isl_keep isl_flow *deps, int must);
+	void isl_flow_free(__isl_take isl_flow *deps);
+
+The function C<isl_access_info_compute_flow> performs the actual
+dependence analysis.  The other functions are used to construct
+the input for this function or to read off the output.
+
+The input is collected in an C<isl_access_info>, which can
+be created through a call to C<isl_access_info_alloc>.
+The arguments to this functions are the sink access relation
+C<sink>, a token C<sink_user> used to identify the sink
+access to the user, a callback function for specifying the
+relative order of source and sink accesses, and the number
+of source access relations that will be added.
+The callback function has type C<int (*)(void *first, void *second)>.
+The function is called with two user supplied tokens identifying
+either a source or the sink and it should return the shared nesting
+level and the relative order of the two accesses.
+In particular, let I<n> be the number of loops shared by
+the two accesses.  If C<first> precedes C<second> textually,
+then the function should return I<2 * n + 1>; otherwise,
+it should return I<2 * n>.
+The sources can be added to the C<isl_access_info> by performing
+(at most) C<max_source> calls to C<isl_access_info_add_source>.
+C<must> indicates whether the source is a I<must> access
+or a I<may> access.  Note that a multi-valued access relation
+should only be marked I<must> if every iteration in the domain
+of the relation accesses I<all> elements in its image.
+The C<source_user> token is again used to identify
+the source access.  The range of the source access relation
+C<source> should have the same dimension as the range
+of the sink access relation.
+The C<isl_access_info_free> function should usually not be
+called explicitly, because it is called implicitly by
+C<isl_access_info_compute_flow>.
+
+The result of the dependence analysis is collected in an
+C<isl_flow>.  There may be elements of
+the sink access for which no preceding source access could be
+found or for which all preceding sources are I<may> accesses.
+The relations containing these elements can be obtained through
+calls to C<isl_flow_get_no_source>, the first with C<must> set
+and the second with C<must> unset.
+In the case of standard flow dependence analysis,
+with the sink a read and the sources I<must> writes,
+the first relation corresponds to the reads from uninitialized
+array elements and the second relation is empty.
+The actual flow dependences can be extracted using
+C<isl_flow_foreach>.  This function will call the user-specified
+callback function C<fn> for each B<non-empty> dependence between
+a source and the sink.  The callback function is called
+with four arguments, the actual flow dependence relation
+mapping source iterations to sink iterations, a boolean that
+indicates whether it is a I<must> or I<may> dependence, a token
+identifying the source and an additional C<void *> with value
+equal to the third argument of the C<isl_flow_foreach> call.
+A dependence is marked I<must> if it originates from a I<must>
+source and if it is not followed by any I<may> sources.
+
+After finishing with an C<isl_flow>, the user should call
+C<isl_flow_free> to free all associated memory.
+
+A higher-level interface to dependence analysis is provided
+by the following function.
+
+	#include <isl/flow.h>
+
+	int isl_union_map_compute_flow(__isl_take isl_union_map *sink,
+		__isl_take isl_union_map *must_source,
+		__isl_take isl_union_map *may_source,
+		__isl_take isl_union_map *schedule,
+		__isl_give isl_union_map **must_dep,
+		__isl_give isl_union_map **may_dep,
+		__isl_give isl_union_map **must_no_source,
+		__isl_give isl_union_map **may_no_source);
+
+The arrays are identified by the tuple names of the ranges
+of the accesses.  The iteration domains by the tuple names
+of the domains of the accesses and of the schedule.
+The relative order of the iteration domains is given by the
+schedule.  The relations returned through C<must_no_source>
+and C<may_no_source> are subsets of C<sink>.
+Any of C<must_dep>, C<may_dep>, C<must_no_source>
+or C<may_no_source> may be C<NULL>, but a C<NULL> value for
+any of the other arguments is treated as an error.
+
+=head3 Interaction with Dependence Analysis
+
+During the dependence analysis, we frequently need to perform
+the following operation.  Given a relation between sink iterations
+and potential source iterations from a particular source domain,
+what is the last potential source iteration corresponding to each
+sink iteration.  It can sometimes be convenient to adjust
+the set of potential source iterations before or after each such operation.
+The prototypical example is fuzzy array dataflow analysis,
+where we need to analyze if, based on data-dependent constraints,
+the sink iteration can ever be executed without one or more of
+the corresponding potential source iterations being executed.
+If so, we can introduce extra parameters and select an unknown
+but fixed source iteration from the potential source iterations.
+To be able to perform such manipulations, C<isl> provides the following
+function.
+
+	#include <isl/flow.h>
+
+	typedef __isl_give isl_restriction *(*isl_access_restrict)(
+		__isl_keep isl_map *source_map,
+		__isl_keep isl_set *sink, void *source_user,
+		void *user);
+	__isl_give isl_access_info *isl_access_info_set_restrict(
+		__isl_take isl_access_info *acc,
+		isl_access_restrict fn, void *user);
+
+The function C<isl_access_info_set_restrict> should be called
+before calling C<isl_access_info_compute_flow> and registers a callback function
+that will be called any time C<isl> is about to compute the last
+potential source.  The first argument is the (reverse) proto-dependence,
+mapping sink iterations to potential source iterations.
+The second argument represents the sink iterations for which
+we want to compute the last source iteration.
+The third argument is the token corresponding to the source
+and the final argument is the token passed to C<isl_access_info_set_restrict>.
+The callback is expected to return a restriction on either the input or
+the output of the operation computing the last potential source.
+If the input needs to be restricted then restrictions are needed
+for both the source and the sink iterations.  The sink iterations
+and the potential source iterations will be intersected with these sets.
+If the output needs to be restricted then only a restriction on the source
+iterations is required.
+If any error occurs, the callback should return C<NULL>.
+An C<isl_restriction> object can be created, freed and inspected
+using the following functions.
+
+	#include <isl/flow.h>
+
+	__isl_give isl_restriction *isl_restriction_input(
+		__isl_take isl_set *source_restr,
+		__isl_take isl_set *sink_restr);
+	__isl_give isl_restriction *isl_restriction_output(
+		__isl_take isl_set *source_restr);
+	__isl_give isl_restriction *isl_restriction_none(
+		__isl_take isl_map *source_map);
+	__isl_give isl_restriction *isl_restriction_empty(
+		__isl_take isl_map *source_map);
+	__isl_null isl_restriction *isl_restriction_free(
+		__isl_take isl_restriction *restr);
+
+C<isl_restriction_none> and C<isl_restriction_empty> are special
+cases of C<isl_restriction_input>.  C<isl_restriction_none>
+is essentially equivalent to
+
+	isl_restriction_input(isl_set_universe(
+	    isl_space_range(isl_map_get_space(source_map))),
+			    isl_set_universe(
+	    isl_space_domain(isl_map_get_space(source_map))));
+
+whereas C<isl_restriction_empty> is essentially equivalent to
+
+	isl_restriction_input(isl_set_empty(
+	    isl_space_range(isl_map_get_space(source_map))),
+			    isl_set_universe(
+	    isl_space_domain(isl_map_get_space(source_map))));
+
+=head2 Scheduling
+
+B<The functionality described in this section is fairly new
+and may be subject to change.>
+
+	#include <isl/schedule.h>
+	__isl_give isl_schedule *
+	isl_schedule_constraints_compute_schedule(
+		__isl_take isl_schedule_constraints *sc);
+	__isl_null isl_schedule *isl_schedule_free(
+		__isl_take isl_schedule *sched);
+
+The function C<isl_schedule_constraints_compute_schedule> can be
+used to compute a schedule that satisfies the given schedule constraints.
+These schedule constraints include the iteration domain for which
+a schedule should be computed and dependences between pairs of
+iterations.  In particular, these dependences include
+I<validity> dependences and I<proximity> dependences.
+By default, the algorithm used to construct the schedule is similar
+to that of C<Pluto>.
+Alternatively, Feautrier's multi-dimensional scheduling algorithm can
+be selected.
+The generated schedule respects all validity dependences.
+That is, all dependence distances over these dependences in the
+scheduled space are lexicographically positive.
+The default algorithm tries to ensure that the dependence distances
+over coincidence constraints are zero and to minimize the
+dependence distances over proximity dependences.
+Moreover, it tries to obtain sequences (bands) of schedule dimensions
+for groups of domains where the dependence distances over validity
+dependences have only non-negative values.
+When using Feautrier's algorithm, the coincidence and proximity constraints
+are only taken into account during the extension to a
+full-dimensional schedule.
+
+An C<isl_schedule_constraints> object can be constructed
+and manipulated using the following functions.
+
+	#include <isl/schedule.h>
+	__isl_give isl_schedule_constraints *
+	isl_schedule_constraints_copy(
+		__isl_keep isl_schedule_constraints *sc);
+	__isl_give isl_schedule_constraints *
+	isl_schedule_constraints_on_domain(
+		__isl_take isl_union_set *domain);
+	__isl_give isl_schedule_constraints *
+	isl_schedule_constraints_set_validity(
+		__isl_take isl_schedule_constraints *sc,
+		__isl_take isl_union_map *validity);
+	__isl_give isl_schedule_constraints *
+	isl_schedule_constraints_set_coincidence(
+		__isl_take isl_schedule_constraints *sc,
+		__isl_take isl_union_map *coincidence);
+	__isl_give isl_schedule_constraints *
+	isl_schedule_constraints_set_proximity(
+		__isl_take isl_schedule_constraints *sc,
+		__isl_take isl_union_map *proximity);
+	__isl_give isl_schedule_constraints *
+	isl_schedule_constraints_set_conditional_validity(
+		__isl_take isl_schedule_constraints *sc,
+		__isl_take isl_union_map *condition,
+		__isl_take isl_union_map *validity);
+	__isl_null isl_schedule_constraints *
+	isl_schedule_constraints_free(
+		__isl_take isl_schedule_constraints *sc);
+
+The initial C<isl_schedule_constraints> object created by
+C<isl_schedule_constraints_on_domain> does not impose any constraints.
+That is, it has an empty set of dependences.
+The function C<isl_schedule_constraints_set_validity> replaces the
+validity dependences, mapping domain elements I<i> to domain
+elements that should be scheduled after I<i>.
+The function C<isl_schedule_constraints_set_coincidence> replaces the
+coincidence dependences, mapping domain elements I<i> to domain
+elements that should be scheduled together with I<I>, if possible.
+The function C<isl_schedule_constraints_set_proximity> replaces the
+proximity dependences, mapping domain elements I<i> to domain
+elements that should be scheduled either before I<I>
+or as early as possible after I<i>.
+
+The function C<isl_schedule_constraints_set_conditional_validity>
+replaces the conditional validity constraints.
+A conditional validity constraint is only imposed when any of the corresponding
+conditions is satisfied, i.e., when any of them is non-zero.
+That is, the scheduler ensures that within each band if the dependence
+distances over the condition constraints are not all zero
+then all corresponding conditional validity constraints are respected.
+A conditional validity constraint corresponds to a condition
+if the two are adjacent, i.e., if the domain of one relation intersect
+the range of the other relation.
+The typical use case of conditional validity constraints is
+to allow order constraints between live ranges to be violated
+as long as the live ranges themselves are local to the band.
+To allow more fine-grained control over which conditions correspond
+to which conditional validity constraints, the domains and ranges
+of these relations may include I<tags>.  That is, the domains and
+ranges of those relation may themselves be wrapped relations
+where the iteration domain appears in the domain of those wrapped relations
+and the range of the wrapped relations can be arbitrarily chosen
+by the user.  Conditions and conditional validity constraints are only
+considered adjacent to each other if the entire wrapped relation matches.
+In particular, a relation with a tag will never be considered adjacent
+to a relation without a tag.
+
+The following function computes a schedule directly from
+an iteration domain and validity and proximity dependences
+and is implemented in terms of the functions described above.
+The use of C<isl_union_set_compute_schedule> is discouraged.
+
+	#include <isl/schedule.h>
+	__isl_give isl_schedule *isl_union_set_compute_schedule(
+		__isl_take isl_union_set *domain,
+		__isl_take isl_union_map *validity,
+		__isl_take isl_union_map *proximity);
+
+A mapping from the domains to the scheduled space can be obtained
+from an C<isl_schedule> using the following function.
+
+	__isl_give isl_union_map *isl_schedule_get_map(
+		__isl_keep isl_schedule *sched);
+
+A representation of the schedule can be printed using
+	 
+	__isl_give isl_printer *isl_printer_print_schedule(
+		__isl_take isl_printer *p,
+		__isl_keep isl_schedule *schedule);
+
+A representation of the schedule as a forest of bands can be obtained
+using the following function.
+
+	__isl_give isl_band_list *isl_schedule_get_band_forest(
+		__isl_keep isl_schedule *schedule);
+
+The individual bands can be visited in depth-first post-order
+using the following function.
+
+	#include <isl/schedule.h>
+	int isl_schedule_foreach_band(
+		__isl_keep isl_schedule *sched,
+		int (*fn)(__isl_keep isl_band *band, void *user),
+		void *user);
+
+The list can be manipulated as explained in L<"Lists">.
+The bands inside the list can be copied and freed using the following
+functions.
+
+	#include <isl/band.h>
+	__isl_give isl_band *isl_band_copy(
+		__isl_keep isl_band *band);
+	__isl_null isl_band *isl_band_free(
+		__isl_take isl_band *band);
+
+Each band contains zero or more scheduling dimensions.
+These are referred to as the members of the band.
+The section of the schedule that corresponds to the band is
+referred to as the partial schedule of the band.
+For those nodes that participate in a band, the outer scheduling
+dimensions form the prefix schedule, while the inner scheduling
+dimensions form the suffix schedule.
+That is, if we take a cut of the band forest, then the union of
+the concatenations of the prefix, partial and suffix schedules of
+each band in the cut is equal to the entire schedule (modulo
+some possible padding at the end with zero scheduling dimensions).
+The properties of a band can be inspected using the following functions.
+
+	#include <isl/band.h>
+	int isl_band_has_children(__isl_keep isl_band *band);
+	__isl_give isl_band_list *isl_band_get_children(
+		__isl_keep isl_band *band);
+
+	__isl_give isl_union_map *isl_band_get_prefix_schedule(
+		__isl_keep isl_band *band);
+	__isl_give isl_union_map *isl_band_get_partial_schedule(
+		__isl_keep isl_band *band);
+	__isl_give isl_union_map *isl_band_get_suffix_schedule(
+		__isl_keep isl_band *band);
+
+	int isl_band_n_member(__isl_keep isl_band *band);
+	int isl_band_member_is_coincident(
+		__isl_keep isl_band *band, int pos);
+
+	int isl_band_list_foreach_band(
+		__isl_keep isl_band_list *list,
+		int (*fn)(__isl_keep isl_band *band, void *user),
+		void *user);
+
+Note that a scheduling dimension is considered to be ``coincident''
+if it satisfies the coincidence constraints within its band.
+That is, if the dependence distances of the coincidence
+constraints are all zero in that direction (for fixed
+iterations of outer bands).
+Like C<isl_schedule_foreach_band>,
+the function C<isl_band_list_foreach_band> calls C<fn> on the bands
+in depth-first post-order.
+
+A band can be tiled using the following function.
+
+	#include <isl/band.h>
+	int isl_band_tile(__isl_keep isl_band *band,
+		__isl_take isl_vec *sizes);
+
+	int isl_options_set_tile_scale_tile_loops(isl_ctx *ctx,
+		int val);
+	int isl_options_get_tile_scale_tile_loops(isl_ctx *ctx);
+	int isl_options_set_tile_shift_point_loops(isl_ctx *ctx,
+		int val);
+	int isl_options_get_tile_shift_point_loops(isl_ctx *ctx);
+
+The C<isl_band_tile> function tiles the band using the given tile sizes
+inside its schedule.
+A new child band is created to represent the point loops and it is
+inserted between the modified band and its children.
+The C<tile_scale_tile_loops> option specifies whether the tile
+loops iterators should be scaled by the tile sizes.
+If the C<tile_shift_point_loops> option is set, then the point loops
+are shifted to start at zero.
+
+A band can be split into two nested bands using the following function.
+
+	int isl_band_split(__isl_keep isl_band *band, int pos);
+
+The resulting outer band contains the first C<pos> dimensions of C<band>
+while the inner band contains the remaining dimensions.
+
+A representation of the band can be printed using
+
+	#include <isl/band.h>
+	__isl_give isl_printer *isl_printer_print_band(
+		__isl_take isl_printer *p,
+		__isl_keep isl_band *band);
+
+=head3 Options
+
+	#include <isl/schedule.h>
+	int isl_options_set_schedule_max_coefficient(
+		isl_ctx *ctx, int val);
+	int isl_options_get_schedule_max_coefficient(
+		isl_ctx *ctx);
+	int isl_options_set_schedule_max_constant_term(
+		isl_ctx *ctx, int val);
+	int isl_options_get_schedule_max_constant_term(
+		isl_ctx *ctx);
+	int isl_options_set_schedule_fuse(isl_ctx *ctx, int val);
+	int isl_options_get_schedule_fuse(isl_ctx *ctx);
+	int isl_options_set_schedule_maximize_band_depth(
+		isl_ctx *ctx, int val);
+	int isl_options_get_schedule_maximize_band_depth(
+		isl_ctx *ctx);
+	int isl_options_set_schedule_outer_coincidence(
+		isl_ctx *ctx, int val);
+	int isl_options_get_schedule_outer_coincidence(
+		isl_ctx *ctx);
+	int isl_options_set_schedule_split_scaled(
+		isl_ctx *ctx, int val);
+	int isl_options_get_schedule_split_scaled(
+		isl_ctx *ctx);
+	int isl_options_set_schedule_algorithm(
+		isl_ctx *ctx, int val);
+	int isl_options_get_schedule_algorithm(
+		isl_ctx *ctx);
+	int isl_options_set_schedule_separate_components(
+		isl_ctx *ctx, int val);
+	int isl_options_get_schedule_separate_components(
+		isl_ctx *ctx);
+
+=over
+
+=item * schedule_max_coefficient
+
+This option enforces that the coefficients for variable and parameter
+dimensions in the calculated schedule are not larger than the specified value.
+This option can significantly increase the speed of the scheduling calculation
+and may also prevent fusing of unrelated dimensions. A value of -1 means that
+this option does not introduce bounds on the variable or parameter
+coefficients.
+
+=item * schedule_max_constant_term
+
+This option enforces that the constant coefficients in the calculated schedule
+are not larger than the maximal constant term. This option can significantly
+increase the speed of the scheduling calculation and may also prevent fusing of
+unrelated dimensions. A value of -1 means that this option does not introduce
+bounds on the constant coefficients.
+
+=item * schedule_fuse
+
+This option controls the level of fusion.
+If this option is set to C<ISL_SCHEDULE_FUSE_MIN>, then loops in the
+resulting schedule will be distributed as much as possible.
+If this option is set to C<ISL_SCHEDULE_FUSE_MAX>, then C<isl> will
+try to fuse loops in the resulting schedule.
+
+=item * schedule_maximize_band_depth
+
+If this option is set, we do not split bands at the point
+where we detect splitting is necessary. Instead, we
+backtrack and split bands as early as possible. This
+reduces the number of splits and maximizes the width of
+the bands. Wider bands give more possibilities for tiling.
+Note that if the C<schedule_fuse> option is set to C<ISL_SCHEDULE_FUSE_MIN>,
+then bands will be split as early as possible, even if there is no need.
+The C<schedule_maximize_band_depth> option therefore has no effect in this case.
+
+=item * schedule_outer_coincidence
+
+If this option is set, then we try to construct schedules
+where the outermost scheduling dimension in each band
+satisfies the coincidence constraints.
+
+=item * schedule_split_scaled
+
+If this option is set, then we try to construct schedules in which the
+constant term is split off from the linear part if the linear parts of
+the scheduling rows for all nodes in the graphs have a common non-trivial
+divisor.
+The constant term is then placed in a separate band and the linear
+part is reduced.
+
+=item * schedule_algorithm
+
+Selects the scheduling algorithm to be used.
+Available scheduling algorithms are C<ISL_SCHEDULE_ALGORITHM_ISL>
+and C<ISL_SCHEDULE_ALGORITHM_FEAUTRIER>.
+
+=item * schedule_separate_components
+
+If at any point the dependence graph contains any (weakly connected) components,
+then these components are scheduled separately.
+If this option is not set, then some iterations of the domains
+in these components may be scheduled together.
+If this option is set, then the components are given consecutive
+schedules.
+
+=back
+
+=head2 AST Generation
+
+This section describes the C<isl> functionality for generating
+ASTs that visit all the elements
+in a domain in an order specified by a schedule.
+In particular, given a C<isl_union_map>, an AST is generated
+that visits all the elements in the domain of the C<isl_union_map>
+according to the lexicographic order of the corresponding image
+element(s).  If the range of the C<isl_union_map> consists of
+elements in more than one space, then each of these spaces is handled
+separately in an arbitrary order.
+It should be noted that the image elements only specify the I<order>
+in which the corresponding domain elements should be visited.
+No direct relation between the image elements and the loop iterators
+in the generated AST should be assumed.
+
+Each AST is generated within a build.  The initial build
+simply specifies the constraints on the parameters (if any)
+and can be created, inspected, copied and freed using the following functions.
+
+	#include <isl/ast_build.h>
+	__isl_give isl_ast_build *isl_ast_build_from_context(
+		__isl_take isl_set *set);
+	__isl_give isl_ast_build *isl_ast_build_copy(
+		__isl_keep isl_ast_build *build);
+	__isl_null isl_ast_build *isl_ast_build_free(
+		__isl_take isl_ast_build *build);
+
+The C<set> argument is usually a parameter set with zero or more parameters.
+More C<isl_ast_build> functions are described in L</"Nested AST Generation">
+and L</"Fine-grained Control over AST Generation">.
+Finally, the AST itself can be constructed using the following
+function.
+
+	#include <isl/ast_build.h>
+	__isl_give isl_ast_node *isl_ast_build_ast_from_schedule(
+		__isl_keep isl_ast_build *build,
+		__isl_take isl_union_map *schedule);
+
+=head3 Inspecting the AST
+
+The basic properties of an AST node can be obtained as follows.
+
+	#include <isl/ast.h>
+	enum isl_ast_node_type isl_ast_node_get_type(
+		__isl_keep isl_ast_node *node);
+
+The type of an AST node is one of
+C<isl_ast_node_for>,
+C<isl_ast_node_if>,
+C<isl_ast_node_block> or
+C<isl_ast_node_user>.
+An C<isl_ast_node_for> represents a for node.
+An C<isl_ast_node_if> represents an if node.
+An C<isl_ast_node_block> represents a compound node.
+An C<isl_ast_node_user> represents an expression statement.
+An expression statement typically corresponds to a domain element, i.e.,
+one of the elements that is visited by the AST.
+
+Each type of node has its own additional properties.
+
+	#include <isl/ast.h>
+	__isl_give isl_ast_expr *isl_ast_node_for_get_iterator(
+		__isl_keep isl_ast_node *node);
+	__isl_give isl_ast_expr *isl_ast_node_for_get_init(
+		__isl_keep isl_ast_node *node);
+	__isl_give isl_ast_expr *isl_ast_node_for_get_cond(
+		__isl_keep isl_ast_node *node);
+	__isl_give isl_ast_expr *isl_ast_node_for_get_inc(
+		__isl_keep isl_ast_node *node);
+	__isl_give isl_ast_node *isl_ast_node_for_get_body(
+		__isl_keep isl_ast_node *node);
+	int isl_ast_node_for_is_degenerate(
+		__isl_keep isl_ast_node *node);
+
+An C<isl_ast_for> is considered degenerate if it is known to execute
+exactly once.
+
+	#include <isl/ast.h>
+	__isl_give isl_ast_expr *isl_ast_node_if_get_cond(
+		__isl_keep isl_ast_node *node);
+	__isl_give isl_ast_node *isl_ast_node_if_get_then(
+		__isl_keep isl_ast_node *node);
+	int isl_ast_node_if_has_else(
+		__isl_keep isl_ast_node *node);
+	__isl_give isl_ast_node *isl_ast_node_if_get_else(
+		__isl_keep isl_ast_node *node);
+
+	__isl_give isl_ast_node_list *
+	isl_ast_node_block_get_children(
+		__isl_keep isl_ast_node *node);
+
+	__isl_give isl_ast_expr *isl_ast_node_user_get_expr(
+		__isl_keep isl_ast_node *node);
+
+Each of the returned C<isl_ast_expr>s can in turn be inspected using
+the following functions.
+
+	#include <isl/ast.h>
+	enum isl_ast_expr_type isl_ast_expr_get_type(
+		__isl_keep isl_ast_expr *expr);
+
+The type of an AST expression is one of
+C<isl_ast_expr_op>,
+C<isl_ast_expr_id> or
+C<isl_ast_expr_int>.
+An C<isl_ast_expr_op> represents the result of an operation.
+An C<isl_ast_expr_id> represents an identifier.
+An C<isl_ast_expr_int> represents an integer value.
+
+Each type of expression has its own additional properties.
+
+	#include <isl/ast.h>
+	enum isl_ast_op_type isl_ast_expr_get_op_type(
+		__isl_keep isl_ast_expr *expr);
+	int isl_ast_expr_get_op_n_arg(__isl_keep isl_ast_expr *expr);
+	__isl_give isl_ast_expr *isl_ast_expr_get_op_arg(
+		__isl_keep isl_ast_expr *expr, int pos);
+	int isl_ast_node_foreach_ast_op_type(
+		__isl_keep isl_ast_node *node,
+		int (*fn)(enum isl_ast_op_type type, void *user),
+		void *user);
+
+C<isl_ast_expr_get_op_type> returns the type of the operation
+performed.  C<isl_ast_expr_get_op_n_arg> returns the number of
+arguments.  C<isl_ast_expr_get_op_arg> returns the specified
+argument.
+C<isl_ast_node_foreach_ast_op_type> calls C<fn> for each distinct
+C<isl_ast_op_type> that appears in C<node>.
+The operation type is one of the following.
+
+=over
+
+=item C<isl_ast_op_and>
+
+Logical I<and> of two arguments.
+Both arguments can be evaluated.
+
+=item C<isl_ast_op_and_then>
+
+Logical I<and> of two arguments.
+The second argument can only be evaluated if the first evaluates to true.
+
+=item C<isl_ast_op_or>
+
+Logical I<or> of two arguments.
+Both arguments can be evaluated.
+
+=item C<isl_ast_op_or_else>
+
+Logical I<or> of two arguments.
+The second argument can only be evaluated if the first evaluates to false.
+
+=item C<isl_ast_op_max>
+
+Maximum of two or more arguments.
+
+=item C<isl_ast_op_min>
+
+Minimum of two or more arguments.
+
+=item C<isl_ast_op_minus>
+
+Change sign.
+
+=item C<isl_ast_op_add>
+
+Sum of two arguments.
+
+=item C<isl_ast_op_sub>
+
+Difference of two arguments.
+
+=item C<isl_ast_op_mul>
+
+Product of two arguments.
+
+=item C<isl_ast_op_div>
+
+Exact division.  That is, the result is known to be an integer.
+
+=item C<isl_ast_op_fdiv_q>
+
+Result of integer division, rounded towards negative
+infinity.
+
+=item C<isl_ast_op_pdiv_q>
+
+Result of integer division, where dividend is known to be non-negative.
+
+=item C<isl_ast_op_pdiv_r>
+
+Remainder of integer division, where dividend is known to be non-negative.
+
+=item C<isl_ast_op_zdiv_r>
+
+Equal to zero iff the remainder on integer division is zero.
+
+=item C<isl_ast_op_cond>
+
+Conditional operator defined on three arguments.
+If the first argument evaluates to true, then the result
+is equal to the second argument.  Otherwise, the result
+is equal to the third argument.
+The second and third argument may only be evaluated if
+the first argument evaluates to true and false, respectively.
+Corresponds to C<a ? b : c> in C.
+
+=item C<isl_ast_op_select>
+
+Conditional operator defined on three arguments.
+If the first argument evaluates to true, then the result
+is equal to the second argument.  Otherwise, the result
+is equal to the third argument.
+The second and third argument may be evaluated independently
+of the value of the first argument.
+Corresponds to C<a * b + (1 - a) * c> in C.
+
+=item C<isl_ast_op_eq>
+
+Equality relation.
+
+=item C<isl_ast_op_le>
+
+Less than or equal relation.
+
+=item C<isl_ast_op_lt>
+
+Less than relation.
+
+=item C<isl_ast_op_ge>
+
+Greater than or equal relation.
+
+=item C<isl_ast_op_gt>
+
+Greater than relation.
+
+=item C<isl_ast_op_call>
+
+A function call.
+The number of arguments of the C<isl_ast_expr> is one more than
+the number of arguments in the function call, the first argument
+representing the function being called.
+
+=item C<isl_ast_op_access>
+
+An array access.
+The number of arguments of the C<isl_ast_expr> is one more than
+the number of index expressions in the array access, the first argument
+representing the array being accessed.
+
+=item C<isl_ast_op_member>
+
+A member access.
+This operation has two arguments, a structure and the name of
+the member of the structure being accessed.
+
+=back
+
+	#include <isl/ast.h>
+	__isl_give isl_id *isl_ast_expr_get_id(
+		__isl_keep isl_ast_expr *expr);
+
+Return the identifier represented by the AST expression.
+
+	#include <isl/ast.h>
+	__isl_give isl_val *isl_ast_expr_get_val(
+		__isl_keep isl_ast_expr *expr);
+
+Return the integer represented by the AST expression.
+
+=head3 Properties of ASTs
+
+	#include <isl/ast.h>
+	int isl_ast_expr_is_equal(__isl_keep isl_ast_expr *expr1,
+		__isl_keep isl_ast_expr *expr2);
+
+Check if two C<isl_ast_expr>s are equal to each other.
+
+=head3 Manipulating and printing the AST
+
+AST nodes can be copied and freed using the following functions.
+
+	#include <isl/ast.h>
+	__isl_give isl_ast_node *isl_ast_node_copy(
+		__isl_keep isl_ast_node *node);
+	__isl_null isl_ast_node *isl_ast_node_free(
+		__isl_take isl_ast_node *node);
+
+AST expressions can be copied and freed using the following functions.
+
+	#include <isl/ast.h>
+	__isl_give isl_ast_expr *isl_ast_expr_copy(
+		__isl_keep isl_ast_expr *expr);
+	__isl_null isl_ast_expr *isl_ast_expr_free(
+		__isl_take isl_ast_expr *expr);
+
+New AST expressions can be created either directly or within
+the context of an C<isl_ast_build>.
+
+	#include <isl/ast.h>
+	__isl_give isl_ast_expr *isl_ast_expr_from_val(
+		__isl_take isl_val *v);
+	__isl_give isl_ast_expr *isl_ast_expr_from_id(
+		__isl_take isl_id *id);
+	__isl_give isl_ast_expr *isl_ast_expr_neg(
+		__isl_take isl_ast_expr *expr);
+	__isl_give isl_ast_expr *isl_ast_expr_address_of(
+		__isl_take isl_ast_expr *expr);
+	__isl_give isl_ast_expr *isl_ast_expr_add(
+		__isl_take isl_ast_expr *expr1,
+		__isl_take isl_ast_expr *expr2);
+	__isl_give isl_ast_expr *isl_ast_expr_sub(
+		__isl_take isl_ast_expr *expr1,
+		__isl_take isl_ast_expr *expr2);
+	__isl_give isl_ast_expr *isl_ast_expr_mul(
+		__isl_take isl_ast_expr *expr1,
+		__isl_take isl_ast_expr *expr2);
+	__isl_give isl_ast_expr *isl_ast_expr_div(
+		__isl_take isl_ast_expr *expr1,
+		__isl_take isl_ast_expr *expr2);
+	__isl_give isl_ast_expr *isl_ast_expr_and(
+		__isl_take isl_ast_expr *expr1,
+		__isl_take isl_ast_expr *expr2)
+	__isl_give isl_ast_expr *isl_ast_expr_or(
+		__isl_take isl_ast_expr *expr1,
+		__isl_take isl_ast_expr *expr2)
+	__isl_give isl_ast_expr *isl_ast_expr_eq(
+		__isl_take isl_ast_expr *expr1,
+		__isl_take isl_ast_expr *expr2);
+	__isl_give isl_ast_expr *isl_ast_expr_le(
+		__isl_take isl_ast_expr *expr1,
+		__isl_take isl_ast_expr *expr2);
+	__isl_give isl_ast_expr *isl_ast_expr_lt(
+		__isl_take isl_ast_expr *expr1,
+		__isl_take isl_ast_expr *expr2);
+	__isl_give isl_ast_expr *isl_ast_expr_ge(
+		__isl_take isl_ast_expr *expr1,
+		__isl_take isl_ast_expr *expr2);
+	__isl_give isl_ast_expr *isl_ast_expr_gt(
+		__isl_take isl_ast_expr *expr1,
+		__isl_take isl_ast_expr *expr2);
+	__isl_give isl_ast_expr *isl_ast_expr_access(
+		__isl_take isl_ast_expr *array,
+		__isl_take isl_ast_expr_list *indices);
+
+The function C<isl_ast_expr_address_of> can be applied to an
+C<isl_ast_expr> of type C<isl_ast_op_access> only. It is meant
+to represent the address of the C<isl_ast_expr_access>.
+
+	#include <isl/ast_build.h>
+	__isl_give isl_ast_expr *isl_ast_build_expr_from_pw_aff(
+		__isl_keep isl_ast_build *build,
+		__isl_take isl_pw_aff *pa);
+	__isl_give isl_ast_expr *
+	isl_ast_build_access_from_pw_multi_aff(
+		__isl_keep isl_ast_build *build,
+		__isl_take isl_pw_multi_aff *pma);
+	__isl_give isl_ast_expr *
+	isl_ast_build_access_from_multi_pw_aff(
+		__isl_keep isl_ast_build *build,
+		__isl_take isl_multi_pw_aff *mpa);
+	__isl_give isl_ast_expr *
+	isl_ast_build_call_from_pw_multi_aff(
+		__isl_keep isl_ast_build *build,
+		__isl_take isl_pw_multi_aff *pma);
+	__isl_give isl_ast_expr *
+	isl_ast_build_call_from_multi_pw_aff(
+		__isl_keep isl_ast_build *build,
+		__isl_take isl_multi_pw_aff *mpa);
+
+The domains of C<pa>, C<mpa> and C<pma> should correspond
+to the schedule space of C<build>.
+The tuple id of C<mpa> or C<pma> is used as the array being accessed or
+the function being called.
+If the accessed space is a nested relation, then it is taken
+to represent an access of the member specified by the range
+of this nested relation of the structure specified by the domain
+of the nested relation.
+
+The following functions can be used to modify an C<isl_ast_expr>.
+
+	#include <isl/ast.h>
+	__isl_give isl_ast_expr *isl_ast_expr_set_op_arg(
+		__isl_take isl_ast_expr *expr, int pos,
+		__isl_take isl_ast_expr *arg);
+
+Replace the argument of C<expr> at position C<pos> by C<arg>.
+
+	#include <isl/ast.h>
+	__isl_give isl_ast_expr *isl_ast_expr_substitute_ids(
+		__isl_take isl_ast_expr *expr,
+		__isl_take isl_id_to_ast_expr *id2expr);
+
+The function C<isl_ast_expr_substitute_ids> replaces the
+subexpressions of C<expr> of type C<isl_ast_expr_id>
+by the corresponding expression in C<id2expr>, if there is any.
+
+
+User specified data can be attached to an C<isl_ast_node> and obtained
+from the same C<isl_ast_node> using the following functions.
+
+	#include <isl/ast.h>
+	__isl_give isl_ast_node *isl_ast_node_set_annotation(
+		__isl_take isl_ast_node *node,
+		__isl_take isl_id *annotation);
+	__isl_give isl_id *isl_ast_node_get_annotation(
+		__isl_keep isl_ast_node *node);
+
+Basic printing can be performed using the following functions.
+
+	#include <isl/ast.h>
+	__isl_give isl_printer *isl_printer_print_ast_expr(
+		__isl_take isl_printer *p,
+		__isl_keep isl_ast_expr *expr);
+	__isl_give isl_printer *isl_printer_print_ast_node(
+		__isl_take isl_printer *p,
+		__isl_keep isl_ast_node *node);
+	__isl_give char *isl_ast_expr_to_str(
+		__isl_keep isl_ast_expr *expr);
+
+More advanced printing can be performed using the following functions.
+
+	#include <isl/ast.h>
+	__isl_give isl_printer *isl_ast_op_type_print_macro(
+		enum isl_ast_op_type type,
+		__isl_take isl_printer *p);
+	__isl_give isl_printer *isl_ast_node_print_macros(
+		__isl_keep isl_ast_node *node,
+		__isl_take isl_printer *p);
+	__isl_give isl_printer *isl_ast_node_print(
+		__isl_keep isl_ast_node *node,
+		__isl_take isl_printer *p,
+		__isl_take isl_ast_print_options *options);
+	__isl_give isl_printer *isl_ast_node_for_print(
+		__isl_keep isl_ast_node *node,
+		__isl_take isl_printer *p,
+		__isl_take isl_ast_print_options *options);
+	__isl_give isl_printer *isl_ast_node_if_print(
+		__isl_keep isl_ast_node *node,
+		__isl_take isl_printer *p,
+		__isl_take isl_ast_print_options *options);
+
+While printing an C<isl_ast_node> in C<ISL_FORMAT_C>,
+C<isl> may print out an AST that makes use of macros such
+as C<floord>, C<min> and C<max>.
+C<isl_ast_op_type_print_macro> prints out the macro
+corresponding to a specific C<isl_ast_op_type>.
+C<isl_ast_node_print_macros> scans the C<isl_ast_node>
+for expressions where these macros would be used and prints
+out the required macro definitions.
+Essentially, C<isl_ast_node_print_macros> calls
+C<isl_ast_node_foreach_ast_op_type> with C<isl_ast_op_type_print_macro>
+as function argument.
+C<isl_ast_node_print>, C<isl_ast_node_for_print> and
+C<isl_ast_node_if_print> print an C<isl_ast_node>
+in C<ISL_FORMAT_C>, but allow for some extra control
+through an C<isl_ast_print_options> object.
+This object can be created using the following functions.
+
+	#include <isl/ast.h>
+	__isl_give isl_ast_print_options *
+	isl_ast_print_options_alloc(isl_ctx *ctx);
+	__isl_give isl_ast_print_options *
+	isl_ast_print_options_copy(
+		__isl_keep isl_ast_print_options *options);
+	__isl_null isl_ast_print_options *
+	isl_ast_print_options_free(
+		__isl_take isl_ast_print_options *options);
+
+	__isl_give isl_ast_print_options *
+	isl_ast_print_options_set_print_user(
+		__isl_take isl_ast_print_options *options,
+		__isl_give isl_printer *(*print_user)(
+			__isl_take isl_printer *p,
+			__isl_take isl_ast_print_options *options,
+			__isl_keep isl_ast_node *node, void *user),
+		void *user);
+	__isl_give isl_ast_print_options *
+	isl_ast_print_options_set_print_for(
+		__isl_take isl_ast_print_options *options,
+		__isl_give isl_printer *(*print_for)(
+			__isl_take isl_printer *p,
+			__isl_take isl_ast_print_options *options,
+			__isl_keep isl_ast_node *node, void *user),
+		void *user);
+
+The callback set by C<isl_ast_print_options_set_print_user>
+is called whenever a node of type C<isl_ast_node_user> needs to
+be printed.
+The callback set by C<isl_ast_print_options_set_print_for>
+is called whenever a node of type C<isl_ast_node_for> needs to
+be printed.
+Note that C<isl_ast_node_for_print> will I<not> call the
+callback set by C<isl_ast_print_options_set_print_for> on the node
+on which C<isl_ast_node_for_print> is called, but only on nested
+nodes of type C<isl_ast_node_for>.  It is therefore safe to
+call C<isl_ast_node_for_print> from within the callback set by
+C<isl_ast_print_options_set_print_for>.
+
+The following option determines the type to be used for iterators
+while printing the AST.
+
+	int isl_options_set_ast_iterator_type(
+		isl_ctx *ctx, const char *val);
+	const char *isl_options_get_ast_iterator_type(
+		isl_ctx *ctx);
+
+The AST printer only prints body nodes as blocks if these
+blocks cannot be safely omitted.
+For example, a C<for> node with one body node will not be
+surrounded with braces in C<ISL_FORMAT_C>.
+A block will always be printed by setting the following option.
+
+	int isl_options_set_ast_always_print_block(isl_ctx *ctx,
+		int val);
+	int isl_options_get_ast_always_print_block(isl_ctx *ctx);
+
+=head3 Options
+
+	#include <isl/ast_build.h>
+	int isl_options_set_ast_build_atomic_upper_bound(
+		isl_ctx *ctx, int val);
+	int isl_options_get_ast_build_atomic_upper_bound(
+		isl_ctx *ctx);
+	int isl_options_set_ast_build_prefer_pdiv(isl_ctx *ctx,
+		int val);
+	int isl_options_get_ast_build_prefer_pdiv(isl_ctx *ctx);
+	int isl_options_set_ast_build_exploit_nested_bounds(
+		isl_ctx *ctx, int val);
+	int isl_options_get_ast_build_exploit_nested_bounds(
+		isl_ctx *ctx);
+	int isl_options_set_ast_build_group_coscheduled(
+		isl_ctx *ctx, int val);
+	int isl_options_get_ast_build_group_coscheduled(
+		isl_ctx *ctx);
+	int isl_options_set_ast_build_scale_strides(
+		isl_ctx *ctx, int val);
+	int isl_options_get_ast_build_scale_strides(
+		isl_ctx *ctx);
+	int isl_options_set_ast_build_allow_else(isl_ctx *ctx,
+		int val);
+	int isl_options_get_ast_build_allow_else(isl_ctx *ctx);
+	int isl_options_set_ast_build_allow_or(isl_ctx *ctx,
+		int val);
+	int isl_options_get_ast_build_allow_or(isl_ctx *ctx);
+
+=over
+
+=item * ast_build_atomic_upper_bound
+
+Generate loop upper bounds that consist of the current loop iterator,
+an operator and an expression not involving the iterator.
+If this option is not set, then the current loop iterator may appear
+several times in the upper bound.
+For example, when this option is turned off, AST generation
+for the schedule
+
+	[n] -> { A[i] -> [i] : 0 <= i <= 100, n }
+
+produces
+
+	for (int c0 = 0; c0 <= 100 && n >= c0; c0 += 1)
+	  A(c0);
+
+When the option is turned on, the following AST is generated
+
+	for (int c0 = 0; c0 <= min(100, n); c0 += 1)
+	  A(c0);
+
+=item * ast_build_prefer_pdiv
+
+If this option is turned off, then the AST generation will
+produce ASTs that may only contain C<isl_ast_op_fdiv_q>
+operators, but no C<isl_ast_op_pdiv_q> or
+C<isl_ast_op_pdiv_r> operators.
+If this options is turned on, then C<isl> will try to convert
+some of the C<isl_ast_op_fdiv_q> operators to (expressions containing)
+C<isl_ast_op_pdiv_q> or C<isl_ast_op_pdiv_r> operators.
+
+=item * ast_build_exploit_nested_bounds
+
+Simplify conditions based on bounds of nested for loops.
+In particular, remove conditions that are implied by the fact
+that one or more nested loops have at least one iteration,
+meaning that the upper bound is at least as large as the lower bound.
+For example, when this option is turned off, AST generation
+for the schedule
+
+	[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and
+					0 <= j <= M }
+
+produces
+
+	if (M >= 0)
+	  for (int c0 = 0; c0 <= N; c0 += 1)
+	    for (int c1 = 0; c1 <= M; c1 += 1)
+	      A(c0, c1);
+
+When the option is turned on, the following AST is generated
+
+	for (int c0 = 0; c0 <= N; c0 += 1)
+	  for (int c1 = 0; c1 <= M; c1 += 1)
+	    A(c0, c1);
+
+=item * ast_build_group_coscheduled
+
+If two domain elements are assigned the same schedule point, then
+they may be executed in any order and they may even appear in different
+loops.  If this options is set, then the AST generator will make
+sure that coscheduled domain elements do not appear in separate parts
+of the AST.  This is useful in case of nested AST generation
+if the outer AST generation is given only part of a schedule
+and the inner AST generation should handle the domains that are
+coscheduled by this initial part of the schedule together.
+For example if an AST is generated for a schedule
+
+	{ A[i] -> [0]; B[i] -> [0] }
+
+then the C<isl_ast_build_set_create_leaf> callback described
+below may get called twice, once for each domain.
+Setting this option ensures that the callback is only called once
+on both domains together.
+
+=item * ast_build_separation_bounds
+
+This option specifies which bounds to use during separation.
+If this option is set to C<ISL_AST_BUILD_SEPARATION_BOUNDS_IMPLICIT>
+then all (possibly implicit) bounds on the current dimension will
+be used during separation.
+If this option is set to C<ISL_AST_BUILD_SEPARATION_BOUNDS_EXPLICIT>
+then only those bounds that are explicitly available will
+be used during separation.
+
+=item * ast_build_scale_strides
+
+This option specifies whether the AST generator is allowed
+to scale down iterators of strided loops.
+
+=item * ast_build_allow_else
+
+This option specifies whether the AST generator is allowed
+to construct if statements with else branches.
+
+=item * ast_build_allow_or
+
+This option specifies whether the AST generator is allowed
+to construct if conditions with disjunctions.
+
+=back
+
+=head3 Fine-grained Control over AST Generation
+
+Besides specifying the constraints on the parameters,
+an C<isl_ast_build> object can be used to control
+various aspects of the AST generation process.
+The most prominent way of control is through ``options'',
+which can be set using the following function.
+
+	#include <isl/ast_build.h>
+	__isl_give isl_ast_build *
+	isl_ast_build_set_options(
+		__isl_take isl_ast_build *control,
+		__isl_take isl_union_map *options);
+
+The options are encoded in an C<isl_union_map>.
+The domain of this union relation refers to the schedule domain,
+i.e., the range of the schedule passed to C<isl_ast_build_ast_from_schedule>.
+In the case of nested AST generation (see L</"Nested AST Generation">),
+the domain of C<options> should refer to the extra piece of the schedule.
+That is, it should be equal to the range of the wrapped relation in the
+range of the schedule.
+The range of the options can consist of elements in one or more spaces,
+the names of which determine the effect of the option.
+The values of the range typically also refer to the schedule dimension
+to which the option applies.  In case of nested AST generation
+(see L</"Nested AST Generation">), these values refer to the position
+of the schedule dimension within the innermost AST generation.
+The constraints on the domain elements of
+the option should only refer to this dimension and earlier dimensions.
+We consider the following spaces.
+
+=over
+
+=item C<separation_class>
+
+This space is a wrapped relation between two one dimensional spaces.
+The input space represents the schedule dimension to which the option
+applies and the output space represents the separation class.
+While constructing a loop corresponding to the specified schedule
+dimension(s), the AST generator will try to generate separate loops
+for domain elements that are assigned different classes.
+If only some of the elements are assigned a class, then those elements
+that are not assigned any class will be treated as belonging to a class
+that is separate from the explicitly assigned classes.
+The typical use case for this option is to separate full tiles from
+partial tiles.
+The other options, described below, are applied after the separation
+into classes.
+
+As an example, consider the separation into full and partial tiles
+of a tiling of a triangular domain.
+Take, for example, the domain
+
+	{ A[i,j] : 0 <= i,j and i + j <= 100 }
+
+and a tiling into tiles of 10 by 10.  The input to the AST generator
+is then the schedule
+
+	{ A[i,j] -> [([i/10]),[j/10],i,j] : 0 <= i,j and
+						i + j <= 100 }
+
+Without any options, the following AST is generated
+
+	for (int c0 = 0; c0 <= 10; c0 += 1)
+	  for (int c1 = 0; c1 <= -c0 + 10; c1 += 1)
+	    for (int c2 = 10 * c0;
+		 c2 <= min(-10 * c1 + 100, 10 * c0 + 9);
+		 c2 += 1)
+	      for (int c3 = 10 * c1;
+		   c3 <= min(10 * c1 + 9, -c2 + 100);
+		   c3 += 1)
+		A(c2, c3);
+
+Separation into full and partial tiles can be obtained by assigning
+a class, say C<0>, to the full tiles.  The full tiles are represented by those
+values of the first and second schedule dimensions for which there are
+values of the third and fourth dimensions to cover an entire tile.
+That is, we need to specify the following option
+
+	{ [a,b,c,d] -> separation_class[[0]->[0]] :
+		exists b': 0 <= 10a,10b' and
+			   10a+9+10b'+9 <= 100;
+	  [a,b,c,d] -> separation_class[[1]->[0]] :
+		0 <= 10a,10b and 10a+9+10b+9 <= 100 }
+
+which simplifies to
+
+	{ [a, b, c, d] -> separation_class[[1] -> [0]] :
+		a >= 0 and b >= 0 and b <= 8 - a;
+	  [a, b, c, d] -> separation_class[[0] -> [0]] :
+		a >= 0 and a <= 8 }
+
+With this option, the generated AST is as follows
+
+	{
+	  for (int c0 = 0; c0 <= 8; c0 += 1) {
+	    for (int c1 = 0; c1 <= -c0 + 8; c1 += 1)
+	      for (int c2 = 10 * c0;
+		   c2 <= 10 * c0 + 9; c2 += 1)
+		for (int c3 = 10 * c1;
+		     c3 <= 10 * c1 + 9; c3 += 1)
+		  A(c2, c3);
+	    for (int c1 = -c0 + 9; c1 <= -c0 + 10; c1 += 1)
+	      for (int c2 = 10 * c0;
+		   c2 <= min(-10 * c1 + 100, 10 * c0 + 9);
+		   c2 += 1)
+		for (int c3 = 10 * c1;
+		     c3 <= min(-c2 + 100, 10 * c1 + 9);
+		     c3 += 1)
+		  A(c2, c3);
+	  }
+	  for (int c0 = 9; c0 <= 10; c0 += 1)
+	    for (int c1 = 0; c1 <= -c0 + 10; c1 += 1)
+	      for (int c2 = 10 * c0;
+		   c2 <= min(-10 * c1 + 100, 10 * c0 + 9);
+		   c2 += 1)
+		for (int c3 = 10 * c1;
+		     c3 <= min(10 * c1 + 9, -c2 + 100);
+		     c3 += 1)
+		  A(c2, c3);
+	}
+
+=item C<separate>
+
+This is a single-dimensional space representing the schedule dimension(s)
+to which ``separation'' should be applied.  Separation tries to split
+a loop into several pieces if this can avoid the generation of guards
+inside the loop.
+See also the C<atomic> option.
+
+=item C<atomic>
+
+This is a single-dimensional space representing the schedule dimension(s)
+for which the domains should be considered ``atomic''.  That is, the
+AST generator will make sure that any given domain space will only appear
+in a single loop at the specified level.
+
+Consider the following schedule
+
+	{ a[i] -> [i] : 0 <= i < 10;
+	  b[i] -> [i+1] : 0 <= i < 10 }
+
+If the following option is specified
+
+	{ [i] -> separate[x] }
+
+then the following AST will be generated
+
+	{
+	  a(0);
+	  for (int c0 = 1; c0 <= 9; c0 += 1) {
+	    a(c0);
+	    b(c0 - 1);
+	  }
+	  b(9);
+	}
+
+If, on the other hand, the following option is specified
+
+	{ [i] -> atomic[x] }
+
+then the following AST will be generated
+
+	for (int c0 = 0; c0 <= 10; c0 += 1) {
+	  if (c0 <= 9)
+	    a(c0);
+	  if (c0 >= 1)
+	    b(c0 - 1);
+	}
+
+If neither C<atomic> nor C<separate> is specified, then the AST generator
+may produce either of these two results or some intermediate form.
+
+=item C<unroll>
+
+This is a single-dimensional space representing the schedule dimension(s)
+that should be I<completely> unrolled.
+To obtain a partial unrolling, the user should apply an additional
+strip-mining to the schedule and fully unroll the inner loop.
+
+=back
+
+Additional control is available through the following functions.
+
+	#include <isl/ast_build.h>
+	__isl_give isl_ast_build *
+	isl_ast_build_set_iterators(
+		__isl_take isl_ast_build *control,
+		__isl_take isl_id_list *iterators);
+
+The function C<isl_ast_build_set_iterators> allows the user to
+specify a list of iterator C<isl_id>s to be used as iterators.
+If the input schedule is injective, then
+the number of elements in this list should be as large as the dimension
+of the schedule space, but no direct correspondence should be assumed
+between dimensions and elements.
+If the input schedule is not injective, then an additional number
+of C<isl_id>s equal to the largest dimension of the input domains
+may be required.
+If the number of provided C<isl_id>s is insufficient, then additional
+names are automatically generated.
+
+	#include <isl/ast_build.h>
+	__isl_give isl_ast_build *
+	isl_ast_build_set_create_leaf(
+		__isl_take isl_ast_build *control,
+		__isl_give isl_ast_node *(*fn)(
+			__isl_take isl_ast_build *build,
+			void *user), void *user);
+
+The
+C<isl_ast_build_set_create_leaf> function allows for the
+specification of a callback that should be called whenever the AST
+generator arrives at an element of the schedule domain.
+The callback should return an AST node that should be inserted
+at the corresponding position of the AST.  The default action (when
+the callback is not set) is to continue generating parts of the AST to scan
+all the domain elements associated to the schedule domain element
+and to insert user nodes, ``calling'' the domain element, for each of them.
+The C<build> argument contains the current state of the C<isl_ast_build>.
+To ease nested AST generation (see L</"Nested AST Generation">),
+all control information that is
+specific to the current AST generation such as the options and
+the callbacks has been removed from this C<isl_ast_build>.
+The callback would typically return the result of a nested
+AST generation or a
+user defined node created using the following function.
+
+	#include <isl/ast.h>
+	__isl_give isl_ast_node *isl_ast_node_alloc_user(
+		__isl_take isl_ast_expr *expr);
+
+	#include <isl/ast_build.h>
+	__isl_give isl_ast_build *
+	isl_ast_build_set_at_each_domain(
+		__isl_take isl_ast_build *build,
+		__isl_give isl_ast_node *(*fn)(
+			__isl_take isl_ast_node *node,
+			__isl_keep isl_ast_build *build,
+			void *user), void *user);
+	__isl_give isl_ast_build *
+	isl_ast_build_set_before_each_for(
+		__isl_take isl_ast_build *build,
+		__isl_give isl_id *(*fn)(
+			__isl_keep isl_ast_build *build,
+			void *user), void *user);
+	__isl_give isl_ast_build *
+	isl_ast_build_set_after_each_for(
+		__isl_take isl_ast_build *build,
+		__isl_give isl_ast_node *(*fn)(
+			__isl_take isl_ast_node *node,
+			__isl_keep isl_ast_build *build,
+			void *user), void *user);
+
+The callback set by C<isl_ast_build_set_at_each_domain> will
+be called for each domain AST node.
+The callbacks set by C<isl_ast_build_set_before_each_for>
+and C<isl_ast_build_set_after_each_for> will be called
+for each for AST node.  The first will be called in depth-first
+pre-order, while the second will be called in depth-first post-order.
+Since C<isl_ast_build_set_before_each_for> is called before the for
+node is actually constructed, it is only passed an C<isl_ast_build>.
+The returned C<isl_id> will be added as an annotation (using
+C<isl_ast_node_set_annotation>) to the constructed for node.
+In particular, if the user has also specified an C<after_each_for>
+callback, then the annotation can be retrieved from the node passed to
+that callback using C<isl_ast_node_get_annotation>.
+All callbacks should C<NULL> on failure.
+The given C<isl_ast_build> can be used to create new
+C<isl_ast_expr> objects using C<isl_ast_build_expr_from_pw_aff>
+or C<isl_ast_build_call_from_pw_multi_aff>.
+
+=head3 Nested AST Generation
+
+C<isl> allows the user to create an AST within the context
+of another AST.  These nested ASTs are created using the
+same C<isl_ast_build_ast_from_schedule> function that is used to create the
+outer AST.  The C<build> argument should be an C<isl_ast_build>
+passed to a callback set by
+C<isl_ast_build_set_create_leaf>.
+The space of the range of the C<schedule> argument should refer
+to this build.  In particular, the space should be a wrapped
+relation and the domain of this wrapped relation should be the
+same as that of the range of the schedule returned by
+C<isl_ast_build_get_schedule> below.
+In practice, the new schedule is typically
+created by calling C<isl_union_map_range_product> on the old schedule
+and some extra piece of the schedule.
+The space of the schedule domain is also available from
+the C<isl_ast_build>.
+
+	#include <isl/ast_build.h>
+	__isl_give isl_union_map *isl_ast_build_get_schedule(
+		__isl_keep isl_ast_build *build);
+	__isl_give isl_space *isl_ast_build_get_schedule_space(
+		__isl_keep isl_ast_build *build);
+	__isl_give isl_ast_build *isl_ast_build_restrict(
+		__isl_take isl_ast_build *build,
+		__isl_take isl_set *set);
+
+The C<isl_ast_build_get_schedule> function returns a (partial)
+schedule for the domains elements for which part of the AST still needs to
+be generated in the current build.
+In particular, the domain elements are mapped to those iterations of the loops
+enclosing the current point of the AST generation inside which
+the domain elements are executed.
+No direct correspondence between
+the input schedule and this schedule should be assumed.
+The space obtained from C<isl_ast_build_get_schedule_space> can be used
+to create a set for C<isl_ast_build_restrict> to intersect
+with the current build.  In particular, the set passed to
+C<isl_ast_build_restrict> can have additional parameters.
+The ids of the set dimensions in the space returned by
+C<isl_ast_build_get_schedule_space> correspond to the
+iterators of the already generated loops.
+The user should not rely on the ids of the output dimensions
+of the relations in the union relation returned by
+C<isl_ast_build_get_schedule> having any particular value.
+
+=head1 Applications
+
+Although C<isl> is mainly meant to be used as a library,
+it also contains some basic applications that use some
+of the functionality of C<isl>.
+The input may be specified in either the L<isl format>
+or the L<PolyLib format>.
+
+=head2 C<isl_polyhedron_sample>
+
+C<isl_polyhedron_sample> takes a polyhedron as input and prints
+an integer element of the polyhedron, if there is any.
+The first column in the output is the denominator and is always
+equal to 1.  If the polyhedron contains no integer points,
+then a vector of length zero is printed.
+
+=head2 C<isl_pip>
+
+C<isl_pip> takes the same input as the C<example> program
+from the C<piplib> distribution, i.e., a set of constraints
+on the parameters, a line containing only -1 and finally a set
+of constraints on a parametric polyhedron.
+The coefficients of the parameters appear in the last columns
+(but before the final constant column).
+The output is the lexicographic minimum of the parametric polyhedron.
+As C<isl> currently does not have its own output format, the output
+is just a dump of the internal state.
+
+=head2 C<isl_polyhedron_minimize>
+
+C<isl_polyhedron_minimize> computes the minimum of some linear
+or affine objective function over the integer points in a polyhedron.
+If an affine objective function
+is given, then the constant should appear in the last column.
+
+=head2 C<isl_polytope_scan>
+
+Given a polytope, C<isl_polytope_scan> prints
+all integer points in the polytope.
+
+=head2 C<isl_codegen>
+
+Given a schedule, a context set and an options relation,
+C<isl_codegen> prints out an AST that scans the domain elements
+of the schedule in the order of their image(s) taking into account
+the constraints in the context set.

Added: polly/trunk/lib/External/isl/gitversion.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/gitversion.h?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/gitversion.h (added)
+++ polly/trunk/lib/External/isl/gitversion.h Wed Feb  4 14:55:43 2015
@@ -0,0 +1 @@
+#define GIT_HEAD_ID "UNKNOWN"

Added: polly/trunk/lib/External/isl/imath/ChangeLog
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/ChangeLog?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/ChangeLog (added)
+++ polly/trunk/lib/External/isl/imath/ChangeLog Wed Feb  4 14:55:43 2015
@@ -0,0 +1,377 @@
+1.0.1
+	First released version.
+
+1.0.2
+	Fixed a bug in mp_int_div() which would yield incorrect quotients
+	when the divisor was very close in value to a prefix of the
+	dividend.  This is now fixed, and there are regression tests in
+	the tests directory.
+
+	Added recursive multiplication and squaring (Karatsuba-Ofman) for
+	large input values.  Integrated these with the existing code for
+	exponentiation, too.  See the code for s_kmul() and s_ksqr() in
+	imath.c.  Tests added and verified against GNU bc.
+
+	Added documentation on mp_get_multiply_threshold() and the reason
+	why it exists.
+
+1.0.3
+	Fixed a couple of bugs in pi.c that were causing incorrect values
+	to be computed for > 30 digits or so.  Added a pi-computation test
+	to the default test suite (make test), checked against a static
+	file computed by bc (set scale=1024, compute 4 * atan(1)).  Added
+	command line option to specify output radix for pi.
+
+	Cleaned up a sign-related bug in mp_int_gcd(), which would cause
+	the sign of gcd(0, x) to be incorrect when x < 0.  Test cases
+	added for future regression.
+
+	Fixed a bug in s_reduce() which would give incorrect results for
+	powers of 2 in certain circumstances.  Added tests to drive this
+	case for future regression.
+
+	Added mp_int_exptmod_evalue() and mp_int_exptmod_bvalue() to make
+	it easier to work with small bases and small exponents.
+
+	Set default recursive multiplication threshold to 50 digits, since
+	this seems to work best for the platforms I've tested so far.
+
+	Added iprime.h and iprime.c to the distribution.
+
+1.0.4
+	Added `findsizes.pl' to the distribution.
+
+	Revised the type declarations in imath.h to use 32/64 bit
+	operations where the "long long" type is supported.
+
+	Fixed a sign-related bug in mp_int_invmod().
+
+	Fixed several small bugs related to shifting which affect the use
+	of 32-bit digits.  Many architectures cannot shift by 32 bits at a
+	time (e.g., MIPS), so I split each of these cases into two shifts
+	of half the size, which should scale properly for both the smaller
+	and larger cases.
+
+	Fixed several arithmetic issues with 32-bit digits that arose due
+	to missing type-casts on the right-hand sides of assignments.
+
+	Fixed s_print() and s_print_buf() to handle the sizes of digits
+	transparently.
+
+1.0.5
+	Updated the Makefile to include the _GNU_SOURCE macro.  For many
+	GCC systems, this is necessary to get the correct definition of
+	the ULLONG_MAX macro in <limits.h>.  Also, you may now build with
+	the make option DEBUG=Y to enable debugging, e.g.:
+
+	make DEBUG=Y imtest
+
+	By default, the Makefile builds with the optimizer enabled.
+
+	Cleaned up the definitions triggered by USE_LONG_LONG in imath.h,
+	and added an #error instruction in case the build is unable to
+	find a definition of ULLONG_MAX or ULONG_LONG_MAX in <limits.h>.
+	Also added the mp_int_to_unsigned(), mp_int_read_unsigned(), and
+	mp_int_unsigned_len() prototypes.
+
+	Fixed a bug in s_qmul() [imath.c:2493] that would grow the value
+	being multiplied even if there was room in the existing digits to
+	hold the result.  This was driving an (apparent) bug in the more
+	general mp_int_read_binary() routine.  Added the routines
+	mentioned in the previous paragraph, and factored some common
+	code out into a static s_tobin().
+
+	Added reset_registers() to imdrover.{h,c}.  Added new test
+	driver functions test_to_uns() and test_read_uns().  Renamed
+	test_read_bin to test_read_binary().
+
+	Silenced a sign-related warning in pi.c (related to printf).
+
+	Added many new test vectors to tests/conv.t, including the
+	original bug proof-of-concept from Tom Wu, and a series of new
+	tests for the unsigned conversion routines.
+
+	Updated `doc.txt' to reflect the changes described above.
+
+1.0.6
+	Updated copyright notices, added LICENSE file explaining the
+	license I am using.  This is basically the BSD license, so
+	you should have no trouble incorporating this code into other
+	open source projects.
+
+	No new functionality in this release.
+
+1.0.7
+	The mp_int_invmod(a, m, c) function would compute a negative value
+	for c when given a < 0.  I added some code to insure that the value
+	returned is always the least non-negative member of the congruence
+	class, if the inverse exists.  A test for this was added to invmod.t.
+
+1.0.8
+	Fixed a small buffer-overrun in s_qmul().  Because it only
+	allocates an extra digit if it absolutely has to, the test for
+	whether it needs to carry a shift out into the "spare" digit had
+	to be written carefully; I missed a subtlety, which is now
+	fixed. Along the way, I fixed a minor performance-related bug in
+	the same routine.
+
+	Added mp_int_error_string(), which converts mp_result values
+	into descriptive strings.  These are statically allocated, so
+	you don't have to free them.
+
+	This version also adds an "examples" subdirectory.  Currently,
+	there is only one program there, but I will add more examples as
+	time permits me.  You have to read the source to understand them
+	anyway, so I won't explain them here.
+
+1.1.0
+	Added imrat.h and imrat.c, containing routines for rational number
+	arithmetic at arbitrary precision.  Added support to the test driver,
+	in imath.c and included various tests in the tests/ subdirectory.
+
+	Fixed a sign-of-zero bug in mp_int_mul().  Tests added to mul.t to
+	regress this fix.
+
+1.1.2
+	Fixed a bug with leading zeroes after the decimal point in the
+	mp_rat_read_decimal() function (imrat.c).  Along the way, I also
+	found a sign-related bug, in which -0.5 would be treated as if it
+	were positive, because the sign of zero is implicitly positive,
+	and the denominator is treated as unsigned always.
+
+	Thanks to Eric Silva for pointing out the leading zeroes bug.
+	The solution isn't the most efficient possible.
+
+1.1.3
+	Rewrote mp_int_to_decimal() to support new rounding modes.  The
+	modes are documented in doc.txt.  Some of the code sucked anyway,
+	so I rewrote pretty much the entire function.
+
+	Added new rounding mode constants.
+
+1.1.4
+	Added mixed rational/integer operations:
+	  mp_rat_add_int, mp_rat_sub_int, mp_rat_mul_int, mp_rat_div_int
+	Added rational exponentiation (with integer exponents):
+	  mp_rat_expt
+
+	Tests for same were added to the tests/ subdirectory.
+
+1.1.5
+	Added mp_rat_read_cdecimal() and mp_rat_read_ustring()
+	Updated the input.c example.
+
+1.1.6
+	Fixed a bug in mp_int_read_cstring() which would read the string
+	"-0" with incorrect sign (MP_NEG instead of MP_ZPOS).  This would
+	violate an invariant that zero is always signed with positives.
+
+	Added some tests to tests/neg.t to catch this case.
+
+1.1.7
+	Fixed a bug in s_udiv(), internal to imath.c, which caused
+	division to fail in some corner cases masked by the use of long
+	long as a word type.  As a result, s_udiv() has now been wholly
+	rewritten.  I also fixed a few lingering buffer-length errors in
+	s_kmul(), and added a "const" qualifier to the input buffers for
+	the mp_int_read_string() and mp_int_read_cstring() functions,
+	and their analogs in imrat.c.
+
+1.1.8
+	Added mp_int_alloc() and mp_int_free().
+
+1.1.9
+	Added mp_rat_alloc() and mp_rat_free().  Fixed a couple of minor
+	bugs in the doc.txt file.  Added mp_int_sqrt() to imath.{h,c} and
+	doc.txt.
+
+1.2
+	Dropped bugfix component of revision number.  Fixed rsakey.c
+	example program to be complete and work faster.
+
+1.3
+	Replaced findsizes.pl with findsizes.py.  Fixed two bugs in the
+	rsakey tool that were leading to incorrect output.
+
+1.4
+	Fixed a bug in mp_int_alloc(), it was not returning NULL when out
+	of memory, but rather failing in assert() instead.  Also, updated
+	the documentation to have better language about the return values
+	in various error conditions.
+
+1.5
+	Changed the API for rational rounding.  Removed the two functions
+	mp_rat_set_rounding() and mp_rat_get_rounding(), along with the
+	round_output global variable.  Redefined the MP_ROUND_* constants
+	as an enumeration type (mp_round_mode).  Added a new parameter to
+	the mp_rat_to_decimal() function to accept a rounding mode.  Unit
+	tests and doc.txt updated suitably.
+
+	This release also incorporates a small patch submitted by Jonathan
+	Shapiro to support compilation in C++.
+
+1.6
+	Defined default_precision and multiply_threshold to be constant
+	and static.  If IMATH_TEST is defined at compile time, these are
+	made global, and can be modified by the caller (the imtimer tool
+	makes use of this ability, for example).
+
+	Implemented a single-digit optimization suggested by J. Shapiro.
+	Documentation updated.
+
+1.7
+	Fixed a subtle casting problem in the use of the ctype macros that
+	would permit negative signed character values to produce illogical
+	behaviour in some configurations (e.g., NetBSD).  Removed a dead
+	"return" statement.
+
+	Added the -pedantic switch for gcc, to get more aggressive
+	warnings; to permit the nonstandard "long long" type to still be
+	used, I also added -Wno-long-long when building with long long
+	enabled (the standard configuration).
+
+	Fixed a bug found by the Samba team running Valgrind on the
+	Heimdal project, and reported by Love Hörnquist Âstrand:  One of
+	the intermediate values used during modular exponentiation could
+	be overflowed during recursive multiplication.  Fixed by taking a
+	more conservative approach to buffer sizing.
+
+	Added a "contrib" subdirectory, whose first entry is a Makefile
+	to build IMath with the MSVC++ "nmake" program, contributed by
+	Matus Horvath.
+
+1.8
+	Fixed a bug in s_udiv() affecting the computation of quotient
+	digits.  Thanks to Love Âstrand for isolating this bug.  Also in
+	this release, defining USELLONG=Y or USELLONG=N on the command
+	line for make will switch support for the "long long" data type on
+	or off without having to edit the Makefile.  The default is still
+	to permit use of "long long", even though the type is not standard
+	ANSI C90.
+
+1.9
+	Increased the number of small primes used for primality testing to
+	100 from 32.  Removed an unwanted #define from imath.c, left over
+	from testing; added "static" to the declaration of the s_embar()
+	internal function since it is not used outside imath.c.  Reduced
+	the quantity of feedback generated by rsakey.c during the prime
+	finding stage of key generation.
+
+1.10
+	All primes less than 1000 are now used in iprime.c for preliminary
+	testing of prime candidates.  Removed declaration of s_pad() from
+	rsakey.c example.  Added imcalc.c example.
+
+	Beginning with this release, defining the DEBUG preprocessor macro
+	when compiling imath.c causes all the normally-static helper
+	functions to be exported.  This makes it easier to troubleshoot
+	bugs in the back end functions without manually editing the source
+	till you have found where the bug actually is.
+
+	Fixed a memory leak in the test driver (imtest.c) where the input
+	buffers allocated for test specs were not released before being
+	released.  No impact on the core routines, but nevertheless not a
+	good thing.
+
+	Fixed several uninitialized memory reads and one subtle read past
+	the end of a buffer in s_kmul(), found during a run of Purify.
+	Thanks to Love Hörnquist Âstrand for finding this one, and
+	providing a good test case so I could isolate the problem.  Also
+	fixed a buglet in s_kmul(), in which free() was being called
+	instead of s_free(), which would break if you provided a custom
+	version of s_alloc() and s_free() for your application.
+
+1.11
+	Those functions which take int parameters to supply one or more of
+	the arithmetic values of the function have been converted to use a
+	typedef "mp_small".  This is defined in imath.h, along with some
+	supporting macros.
+
+	Added mp_int_to_uint() and mp_int_lcm() in imath.{h,c}, based on a
+	patch contributed by Hal Finkel.  Added LCM tests as as well as
+	some more GCD tests in tests/lcm.t and tests/gcd.t
+
+	Also at Hal Finkel's request, added mp_int_root() to compute the
+	integer nth root, i.e., \lfloor a^{1/b}\rfloor; replaced the old
+	mp_int_sqrt() function with a call to mp_int_root() via a macro.
+	The new implementation is probably slightly less efficient for
+	square roots, but more general.  Added tests/root.t and moved the
+	sqrt tests there, also.
+
+1.12
+	Added a new global constant MP_MINERR which is the value of the
+	smallest error code defined by IMath itself.  This can be used by
+	clients who wish to define and use additional error codes, so that
+	those codes will not conflict with the existing set.
+
+	Extended the imcalc example to include memory.
+
+	Fixed a bug in mp_int_add() in which -1 + 1 = -0 (the sign of zero
+	was recorded incorrectly).  Added tests to the regression suite
+	for this fix.
+
+1.13
+	Cosmetic change -- updated all the files with my new web address.
+
+	Fixed a buglet caught by Love Hörnquist Âstrand using the LLVM
+	static checker tools, in which a mp_int_copy() failure would be
+	silently ignored and cause an extra copy to be generated.
+
+	Fixed a bug in the testing suite while building on MinGW.  The pi
+	generation tests compare to static files and these tests fail if
+	CR/LF is output instead of just LF.  The test script now strips
+	all CR and LF from the output and compares to files lacking them.
+	Reported by Chris Cole <cjcole at gmail.com>.
+
+1.14
+	Instead of using the preprocessor to delete "static", the static
+	definitions in imath.c now use an explicit STATIC macro, that is
+	made null when DEBUG is defined.  This avoids a subtle problem
+	with static variables defined inside functions (although no bugs
+	actually arose from it).
+
+	Fixed a bug in s_udiv() while building on MinGW.  When building
+	with short type digits, the routine was incorrectly discarding
+	overflow when computing the next quotient digit.
+	Reported by Paul DeMarco <pdemarco at ppg.com>.
+
+1.15
+	Fixed a bug in the definition of MP_DIGIT_MAX that caused errors
+	when IMath is built under 64-bit Linux.  Reported by
+	Klaus Stengel <klaus.stengel at informatik.stud.uni-erlangen.de>.
+
+	Unpacked the macro definitions in imath.c a bit, to make them more
+	readable.
+
+	Added mp_int_expt_full() by request of Andrea Barberio
+	<insomniac at slackware.it>.
+
+1.16
+	Fixed a bug in mp_int_to_uint() which was causing incorrect MP_RANGE
+	errors during small integer conversion.
+	Reported by Andrea Barberio <insomniac at slackware.it>
+
+	Added mp_int_compare_uvalue().
+	Added some new testing hooks in imtest.c, new unit tests.
+
+	Made some code style changes that do not affect functionality.
+
+1.17
+	Fixed a bug in mp_int_swap() where mpz_t structures using their single
+	field as storage would not get swapped correctly.
+	Reported by Andres Navarro <canavarro82 at gmail.com>
+
+	Added regression test for this and some hooks for future
+	regressions in the tests/test.sh script.
+
+1.18
+	Made mp_int_rat() use mp_int_init() to initialize numerator and
+	denominator instead of mp_int_init_size().
+	Some minor code cleanup inside the testing code (imdrover.c).
+
+	Fixed an off-by-one bug in s_udiv() which could cause the quotient
+	guessing loop to spin.  Reported by Andres Navarro.  Added
+	triggering example to div.t as a regression test.
+
+1.19
+	Fix signedness error in compile.  Reported by Paweł Sikora.

Added: polly/trunk/lib/External/isl/imath/LICENSE
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/LICENSE?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/LICENSE (added)
+++ polly/trunk/lib/External/isl/imath/LICENSE Wed Feb  4 14:55:43 2015
@@ -0,0 +1,20 @@
+IMath is Copyright © 2002-2009 Michael J. Fromberger
+You may use it subject to the following Licensing Terms:
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

Added: polly/trunk/lib/External/isl/imath/README.md
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/README.md?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/README.md (added)
+++ polly/trunk/lib/External/isl/imath/README.md Wed Feb  4 14:55:43 2015
@@ -0,0 +1,106 @@
+IMath
+=====
+
+Arbitrary precision integer and rational arithmetic library.
+
+IMath is an open-source ANSI C arbitrary precision integer and rational
+arithmetic library.
+
+IMath is copyright © 2002-2009 Michael J. Fromberger.
+
+> Permission is hereby granted, free of charge, to any person obtaining a copy
+> of this software and associated documentation files (the "Software"), to deal
+> in the Software without restriction, including without limitation the rights
+> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+> copies of the Software, and to permit persons to whom the Software is
+> furnished to do so, subject to the following conditions:
+>
+> The above copyright notice and this permission notice shall be included in
+> all copies or substantial portions of the Software.
+>
+> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+> SOFTWARE.
+
+
+About IMath
+-----------
+
+IMath is a library written in portable ANSI C that allows you to perform
+arithmetic on integers and rational numbers of arbitrary precision.  While many
+programming languages, including Java, Perl, and Python provide arbitrary
+precision numbers as a standard library or language feature, C does not.
+
+IMath was designed to be small, self-contained, easy to understand and use, and
+as portable as possible across various platforms.  The API is simple, and the
+code should be comparatively easy to modify or extend.  Simplicity and
+portability are useful goals for some applications—however, IMath does
+not attempt to break performance records.  If you need the fastest possible
+implementation, you might consider some other libraries, such as GNU MP (GMP),
+MIRACL, or the bignum library from OpenSSL.
+
+Programming with IMath
+----------------------
+
+Detailed descriptions of the IMath API can be found in `doc.txt`.  However, the
+following is a brief synopsis of how to get started with some simple tasks.
+
+To do basic integer arithmetic, you must declare variables of type `mpz_t` in
+your program, and call the functions defined in `imath.h` to operate on them.
+Here is a simple example that reads one base-10 integer from the command line,
+multiplies it by another (fixed) value, and prints the result to the standard
+output in base-10 notation:
+
+    #include <stdio.h>
+    #include <stdlib.h>
+    #include "imath.h"
+
+    int main(int argc, char *argv[])
+    {
+      mpz_t  a, b;
+      char  *buf;
+      int    len;
+
+      if(argc < 2) {
+        fprintf(stderr, "Usage: testprogram <integer>\n");
+        return 1;
+      }
+
+      /* Initialize a new zero-valued mpz_t structure */
+      mp_int_init(&a);
+
+      /* Initialize a new mpz_t with a small integer value */
+      mp_int_init_value(&b, 25101);
+
+      /* Read a string value in the specified radix */
+      mp_int_read_string(&a, 10, argv[1]);
+
+      /* Multiply the two together... */
+      mp_int_mul(&a, &b, &a);
+
+      /* Print out the result */
+      len = mp_int_string_len(&a, 10);
+      buf = calloc(len, sizeof(*buf));
+      mp_int_to_string(&a, 10, buf, len);
+      printf("result = %s\n", buf);
+      free(buf);
+
+      /* Release memory occupied by mpz_t structures when finished */
+      mp_int_clear(&b);
+      mp_int_clear(&a);
+
+      return 0;
+    }
+
+This simple example program does not do any error checking, but all the IMath
+API functions return an `mp_result` value which can be used to detect various
+problems like range errors, running out of memory, and undefined results.
+
+The IMath API also supports operations on arbitrary precision rational numbers.
+The functions for creating and manipulating rational values (type `mpq_t`) are
+defined in `imrat.h`, so that you need only include them in your project if you
+wish to.

Added: polly/trunk/lib/External/isl/imath/bintest.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/bintest.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/bintest.c (added)
+++ polly/trunk/lib/External/isl/imath/bintest.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,106 @@
+/*
+  Name:     bintest.c
+  Purpose:  Test driver for binary input/output formats from IMath.
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "imath.h"
+
+int main(int argc, char *argv[])
+{
+  unsigned char buf[512];
+  mpz_t  v, w;
+  mp_result res;
+  int len;
+
+  if(argc < 2 || argv[1][0] == '\0') {
+    fprintf(stderr, "Usage: bintest <value>\n");
+    return 1;
+  }
+
+  mp_int_init(&v);
+  mp_int_init(&w);
+  res = mp_int_read_string(&v, 10, argv[1]);
+  printf("Result code from mp_int_read_string() = %d (%s)\n",
+	 res, mp_error_string(res));
+
+  len = mp_int_binary_len(&v);
+  printf("%d bytes needed to write this value in 2's complement.\n", len);
+
+  res = mp_int_to_binary(&v, buf, sizeof(buf));
+  printf("Result code from mp_int_to_binary() = %d (%s)\n",
+	 res, mp_error_string(res));
+  if(res == MP_OK) {
+    int ix;
+
+    for(ix = 0; ix < (len - 1); ++ix)
+      printf("%d.", buf[ix]);
+
+    printf("%d\n", buf[ix]);
+  } else {
+    return 1;
+  }
+
+  /* Try converting back... */
+  res = mp_int_read_binary(&w, buf, len);
+  printf("Result code from mp_int_read_binary() = %d (%s)\n",
+	 res, mp_error_string(res));
+  if(res == MP_OK) {
+    mp_int_to_string(&w, 10, (char *) buf, sizeof(buf));
+
+    printf("[%s]\n\n", buf);
+  }
+
+  len = mp_int_unsigned_len(&v);
+  printf("%d bytes needed to write this value as unsigned.\n", len);
+
+  res = mp_int_to_unsigned(&v, buf, sizeof(buf));
+  printf("Result code from mp_int_to_unsigned() = %d\n", res);
+  if(res == MP_OK) {
+    int ix;
+
+    for(ix = 0; ix < (len - 1); ++ix)
+      printf("%d.", buf[ix]);
+
+    printf("%d\n", buf[ix]);
+  } else {
+    return 1;
+  }
+
+  res = mp_int_read_unsigned(&w, buf, len);
+  printf("Result code from mp_int_read_unsigned() = %d (%s)\n",
+	 res, mp_error_string(res));
+  if(res == MP_OK) {
+    mp_int_to_string(&w, 10, (char *) buf, sizeof(buf));
+
+    printf("[%s]\n\n", buf);
+  }
+
+  mp_int_clear(&v);
+  mp_int_clear(&w);
+  return 0;
+}

Added: polly/trunk/lib/External/isl/imath/bug-swap.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/bug-swap.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/bug-swap.c (added)
+++ polly/trunk/lib/External/isl/imath/bug-swap.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,25 @@
+/* Regression test for mp_int_swap() bug on self-stored values. */
+#include <stdio.h>
+#include "imath.h"
+
+int main(int argc, char* argv[]) {
+  mpz_t a, b;
+  int result;
+
+  mp_int_init_value(&a, 1);
+  mp_int_init_value(&b, 16);
+
+  mp_int_swap(&a, &b);
+  result = (a.digits == &(a.single) &&
+	    b.digits == &(b.single) &&
+	    a.digits[0] == 16 &&
+	    b.digits[0] == 1);
+
+  printf("REGRESSION: mp_int_swap() on self-stored values: %s\n",
+	 result ? "OK" : "FAILED");
+
+  mp_int_clear(&b);
+  mp_int_clear(&a);
+  return !result;
+}
+   

Added: polly/trunk/lib/External/isl/imath/contrib/Makefile.msvc
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/contrib/Makefile.msvc?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/contrib/Makefile.msvc (added)
+++ polly/trunk/lib/External/isl/imath/contrib/Makefile.msvc Wed Feb  4 14:55:43 2015
@@ -0,0 +1,84 @@
+##
+## Name:     Makefile.msvc
+## Purpose:  Makefile for IMath library and associated tools
+##           for Microsoft Visual Studio 2005
+## Author:   Matus Horvath <matus.horvath at nextra.sk>
+##
+## Copyright (C) 2006 Matus Horvath.  Permission has been granted to use,
+## modify, and redistribute this file according to the terms of the IMath
+## license.
+##
+## Usage: nmake /f Makefile.msvc
+##
+
+# --- begin configuration section ---
+
+## Settings for Microsoft Windows systems using nmake.
+## To build with debugging, add DEBUG=Y on the "nmake" command line.
+CC=cl.exe
+LD=link.exe
+CFLAGS=$(CFLAGS) -nologo -I. -D_CRT_SECURE_NO_DEPRECATE $(DCFLAGS)
+LDFLAGS=$(LDFLAGS) -nologo $(DLDFLAGS)
+LIBS=$(DLIBS)
+
+!if "$(DEBUG)" == "Y"
+DCFLAGS=-ZI -Od -DDEBUG=1 -DTRACEABLE_FREE=1
+DLDFLAGS=-DEBUG
+#DLIBS=-lefence
+!else
+DCFLAGS=-O2 -Ob2
+DLDFLAGS=
+#DLIBS=
+!endif
+
+## Visual Studio C/C++ 2005 compiler supports "long long" 64-bit type.  
+CFLAGS=$(CFLAGS) -DUSE_LONG_LONG
+
+# --- end of configuration section ---
+TARGETS=imtest.exe pi.exe bintest.exe findprime.exe
+HDRS=imath.h imrat.h iprime.h imdrover.h rsamath.h
+SRCS=$(HDRS:.h=.c) $(TARGETS:.exe=.c)
+OBJS=$(SRCS:.c=.obj)
+EXAMPLES=input.exe basecvt.exe rounding.exe
+
+.c.obj:
+	$(CC) $(CFLAGS) -c $<
+
+all: objs examples test
+
+objs: $(OBJS)
+
+# Because Visual Studio does not permit Unix shell syntax, you will
+# have to run the tests manually once the "test" target is built.
+test: imtest.exe pi.exe
+#	@ echo ""
+#	@ echo "Running tests, you should not see any 'FAILED' lines here."
+#	@ echo "If you do, please see doc.txt for how to report a bug."
+#	@ echo ""
+#	(cd tests && ./test.sh)
+
+$(EXAMPLES): imath.obj imrat.obj iprime.obj examples/$*.obj
+	@move $*.obj examples/$*.obj
+	$(LD) $(LDFLAGS) -out:$@ $** $(LIBS)
+
+examples: $(EXAMPLES)
+
+imtest.exe: imtest.obj imath.obj imrat.obj imdrover.obj
+	$(LD) $(LDFLAGS) -out:$@ $** $(LIBS)
+
+pi.exe: pi.obj imath.obj
+	$(LD) $(LDFLAGS) -out:$@ $** $(LIBS)
+
+findprime.exe: findprime.obj imath.obj iprime.obj
+	$(LD) $(LDFLAGS) -out:$@ $** $(LIBS)
+
+rtest.exe: rtest.obj imath.obj rsamath.obj
+	$(LD) $(LDFLAGS) -out:$@ $** $(LIBS)
+
+bintest.exe: imath.obj bintest.obj
+	$(LD) $(LDFLAGS) -out:$@ $** $(LIBS)
+
+clean:
+	del /q /f *.exe *.obj examples\*.obj
+
+# End of Makefile.msvc

Added: polly/trunk/lib/External/isl/imath/contrib/README
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/contrib/README?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/contrib/README (added)
+++ polly/trunk/lib/External/isl/imath/contrib/README Wed Feb  4 14:55:43 2015
@@ -0,0 +1,3 @@
+The files in this directory have been contributed to the IMath project
+by other authors.
+

Added: polly/trunk/lib/External/isl/imath/divide.txt
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/divide.txt?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/divide.txt (added)
+++ polly/trunk/lib/External/isl/imath/divide.txt Wed Feb  4 14:55:43 2015
@@ -0,0 +1,43 @@
+Algorithm for Arbitrary Precision Unsigned Division
+
+Inputs:
+  A = [a1 ... an]       -- array representation
+  B = [b1 ... bm]
+  ai, bi \in {0,..radix}
+
+Preconditions:
+  n >= m
+
+Outputs:
+  Q, R satisfying A = QB + R with 0 <= R < B.
+
+let Q = [], j = n, i = 1, skip = 0 in 
+  while j > 0 do
+    if B > A[j,..j + i + 1] then
+      decrement j
+      increment i
+      increment skip
+      if skip > 1 then
+        Q.append(0)
+    else
+      let pfx = A[j] in
+        if pfx < bm and j > 1 then
+          pfx := pfx * radix + A[j - 1]
+        
+        q := pfx div bm
+        if q >= radix then
+          if q > radix then
+            q = radix
+          else 
+            q := 1
+
+        let t = B * q in
+          while t > A[j,..j + i + 1] do
+            t := t - B
+            decrement q
+        
+        Q.append(q)
+        skip := 0
+  end    
+  
+  result Q, A

Added: polly/trunk/lib/External/isl/imath/doc.txt
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/doc.txt?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/doc.txt (added)
+++ polly/trunk/lib/External/isl/imath/doc.txt Wed Feb  4 14:55:43 2015
@@ -0,0 +1,820 @@
+Name:     doc.txt
+Purpose:  User documentation for IMath library
+Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+--- Installation:
+
+1. Edit Makefile to select compiler and options.  The default uses gcc.  If you
+   are building under MacOS 10.1.x, you will need to change CC to 'cc' instead
+   of 'gcc', but otherwise you can use the default GCC settings.
+ 
+   By default, the Makefile assumes you can use the "long long" integer type,
+   even though it is not standard in ANSI C90.  You can control this by setting
+   the USELLONG variable in your make command line.  Setting USELLONG=Y enables
+   "long long"; USELLONG=N disables it.  The default is Y.
+
+   If the built-in types do not work for your particular platform, you can try
+   to find suitable integer type sizes by running the Python program
+   `findsizes.py'.  This requires a Python interpreter, version 2.4.x or later.
+
+2. Type 'make' or 'make test' to build the test driver and run the unit tests.
+   None of these should fail.  If they do, see below for how you can report
+   bugs.
+
+   To build with debugging enabled (and optimization disabled), run make
+   DEBUG=Y.  This sets the preprocessor macro DEBUG to 1, and several other
+   things (see Makefile for details).
+
+To use the library in your code, include "imath.h" wherever you intend to use
+the library's routines.  The integer library is just a single source file, so
+you can compile it into your project in whatever way makes sense.  If you wish
+to use rational arithmetic, you will also need to include "imrat.h".
+
+--- Background:
+
+The basic types defined by the imath library are mpz_t, an arbitrary precision
+signed integer, and mpq_t, an arbitrary precision signed rational number.  The
+type mp_int is a pointer to an mpz_t, and mp_rat is a pointer to an mpq_t.
+
+Most of the functions in the imath library return a value of type mp_result.
+This is a signed integer type which can be used to convey status information
+and also return small values.  Any negative value is considered to be a status
+message.  The following constants are defined for processing these:
+
+ MP_OK        operation successful, all is well (= 0)
+ MP_FALSE     boolean false (= MP_OK)
+ MP_TRUE      boolean true
+ MP_MEMORY    out of memory
+ MP_RANGE     parameter out of range
+ MP_UNDEF     result is undefined (e.g., division by zero)
+ MP_TRUNC     output value was truncated
+ MP_BADARG    an invalid parameter was passed
+
+If you obtain a zero or negative value of an mp_result, you can use the
+mp_int_error_string() routine to obtain a pointer to a brief human readable
+string describing the error.  These strings are statically allocated, so they
+need not be freed by the caller; the same strings are re-used from call to
+call.
+
+Unless otherwise noted, it is legal to use the same parameter for both inputs
+and output with most of the functions in this library.  For example, you can
+add a number to itself and replace the original by writing:
+
+  mp_int_add(a, a, a);  /* a = a + a */
+
+Any cases in which this is not legal will be noted in the function summaries
+below (if you discover that this is not so, please report it as a bug; I will
+fix either the function or the documentation :)
+
+--- The IMath API
+
+Each of the API functions is documented here.  The general format of the
+entries is:
+
+return_type function_name(parameters ...)
+            English description.
+
+Unless otherwise noted, any API function that returns mp_result may be expected
+to return MP_OK, MP_BADARG, or MP_MEMORY.  Other return values should be
+documented in the description.  Please let me know if you discover this is not
+the case.
+
+The following macros are defined in "imath.h", to define the sizes of the
+various data types used in the library:
+
+ MP_DIGIT_BIT    : the number of bits in a single mpz_t digit.
+ MP_WORD_BIT     : the number of bits in a mpz_t word.
+ MP_SMALL_MIN    : the minimum value representable by an mp_small.
+ MP_SMALL_MAX    : the maximum value representable by an mp_small.
+ MP_USMALL_MIN   : the minimum value representable by an mp_usmall.
+ MP_USMALL_MAX   : the maximum value representable by an mp_usmall.
+ MP_MIN_RADIX    : the minimum radix accepted for base conversion.
+ MP_MAX_RADIX    : the maximum radix accepted for base conversion.
+
+An mp_int must be initialized before use.  This may be accomplished using the
+following functions:
+
+mp_result mp_int_init(mp_int z);
+          Initializes z with a default precision, sets the value to zero.  This
+          function cannot fail unless z is NULL.
+
+mp_int    mp_int_alloc();
+          Dynamically allocates an mpz_t, initializes it to the value zero, and
+          returns a pointer to it.  Returns NULL in case of error (the only
+          error possible is MP_MEMORY in this case).
+
+mp_result mp_int_init_size(mp_int z, mp_size prec);
+          Initializes z with at least prec digits of storage, sets the value to
+          zero.  If prec is zero, the default size is used, defined in imath.h
+          as MP_DEFAULT_PREC.  The size is rounded up to the nearest word
+          boundary.
+
+mp_result mp_int_init_copy(mp_int z, mp_int old);
+          Initializes z to be a copy of an already-initialized mp_int in old.
+          They do not share storage.
+
+mp_result mp_int_init_value(mp_int z, mp_small value);
+          Initializes z with default precision and sets its value to the value
+          of the supplied integer.
+
+To copy one mp_int to another, use:
+
+mp_result mp_int_copy(mp_int a, mp_int c);
+          Copies the value of a into c.  Does not allocate new memory unless a
+          has more significant digits than c has room for.
+
+When you are finished with an mp_int, you must free the memory it uses:
+
+void      mp_int_clear(mp_int z);
+          Releases the storage used by z.
+
+void      mp_int_free(mp_int z);
+          Releases the storage used by z, and frees the mpz_t structure z
+          points to.  This should only be used for values allocated by
+          mp_int_alloc().
+
+To set an mp_int, which has already been initialized, to a small integer value,
+use the following:
+
+mp_result mp_int_set_value(mp_int z, mp_small value);
+          Sets the value of z to the value of the supplied integer.
+
+By default, an mp_int is initialized with a certain minimum amount of storage
+for digits.  This storage is expanded automatically as needed.
+
+- The arithmetic functions are:
+
+int       mp_int_is_odd(mp_int z);
+          Returns true if z is an odd integer (z = 1 (mod 2))
+          [currently implemented as a macro]
+
+int       mp_int_is_even(mp_int z);
+          Returns true if z is an even integer (z = 0 (mod 2))
+          [currently implemented as a macro]
+
+void      mp_int_zero(mp_int z);
+          Sets z to zero.
+
+mp_result mp_int_abs(mp_int a, mp_int c);
+          Sets c to the absolute value of a. 
+          If a < 0, c = -a, else c = a.
+
+mp_result mp_int_neg(mp_int a, mp_int c);
+          Sets c to be the additive inverse of a, c = -a.
+
+mp_result mp_int_add(mp_int a, mp_int b, mp_int c);
+          Computes c = a + b.
+
+mp_result mp_int_add_value(mp_int a, mp_small value, mp_int c);
+          Computes c = a + value, where value is a small integer.
+
+mp_result mp_int_sub(mp_int a, mp_int b, mp_int c);
+          Computes c = a - b.
+
+mp_result mp_int_sub_value(mp_int a, mp_small value, mp_int c);
+          Computes c = a - value, where value is a small integer.
+
+mp_result mp_int_mul(mp_int a, mp_int b, mp_int c);
+          Computes c = a * b
+
+mp_result mp_int_mul_value(mp_int a, mp_small value, mp_int c);
+          Computes c = a * value, where value is a small integer.
+
+mp_result mp_int_mul_pow2(mp_int a, mp_small p2, mp_int c);
+          Computes c = a * 2^p2, where p2 >= 0.
+
+mp_result mp_int_sqr(mp_int a, mp_int c);
+          Computes c = a * a.  Faster than using mp_int_mul(a, a, c).
+
+mp_result mp_int_root(mp_int a, mp_small b, mp_int c);
+          Computes c = floor(a^{1/b}).  Returns MP_UNDEF if the root is
+          undefined, i.e., if a < 0 and b is even.  Uses Newton's method to
+          obtain the root.
+
+mp_result mp_int_sqrt(mp_int a, mp_int c);
+          Computes c = floor(sqrt(a)) if a >= 0.  Returns MP_UNDEF if
+          a < 0.
+          [currently implemented as a macro]
+
+mp_result mp_int_div(mp_int a, mp_int b, mp_int q, mp_int r);
+          Computes q, r such that a = bq + r and 0 <= r < b.
+
+          Pass NULL for q or r if you don't need its value.  Detects and
+          handles division by powers of two in an efficient manner.  Returns
+          MP_UNDEF if b = 0.  If both q and r point to the same non-NULL
+          location, their values on output will be arbitrary (usually
+          incorrect).
+
+mp_result mp_int_div_value(mp_int a, mp_small v, mp_int q, mp_small *r);
+          Computes q, r such that a = qv + r and 0 <= r < v, where v is a small
+          integer.  Pass NULL for q or r if you don't need its value.
+
+mp_result mp_int_div_pow2(mp_int a, mp_small p2, mp_int q, mp_int r);
+          Computes q, r such that a = q * 2^p2 + r.  This is a special case for
+          division by powers of two that is much more efficient than using the
+          regular division algorithm.  Note that mp_int_div() will
+          automatically handle this case if b = 2^k for some k >= 0;
+          mp_int_div_pow2() is for when you have only the exponent, not the
+          expanded value.
+
+mp_result mp_int_mod(mp_int a, mp_int m, mp_int c);
+          Computes the least non-negative residue of a (mod m), and assigns the
+          result to c.
+
+mp_result mp_int_mod_value(mp_int a, mp_int value, mp_small *r);
+          Computes the least non-negative residue of a (mod value), where value
+          is a small integer, and assigns the result to r.
+
+mp_result mp_int_expt(mp_int a, mp_small b, mp_int c);
+          Raises a to the b power, and assigns the result to c.  It is an error
+          if b < 0.
+
+mp_result mp_int_expt_value(mp_small a, mp_small b, mp_int c);
+          Raises a to the b power, and assigns the result to c.  It is an error
+          if b < 0.
+
+mp_result mp_int_expt_full(mp_int a, mp_int b, mp_int c);
+          Raises a to the b power, and assigns the result to c.  It is an error
+          if b < 0.
+
+- Comparison functions:
+
+Unless otherwise specified, comparison between values x and y returns a value <
+0 if x is less than y, = 0 if x is equal to y, and > 0 if x is greater than y.
+
+int       mp_int_compare(mp_int a, mp_int b);
+          Signed comparison of a and b.
+
+int       mp_int_compare_unsigned(mp_int a, mp_int b);
+          Unsigned (magnitude) comparison of a and b.  The signs of a and b are
+          not modified.
+
+int       mp_int_compare_zero(mp_int z);
+          Compare z to zero.
+
+int       mp_int_compare_value(mp_int z, mp_small value);
+int       mp_int_compare_uvalue(mp_int z, mp_usmall value);
+          Compare z to small signed (value) or unsigned (uvalue) integer value.
+
+int       mp_int_divisible_value(mp_int a, mp_small v);
+          Returns true (nonzero) if a is divisible by small integer v,
+          otherwise false (zero)
+
+int       mp_int_is_pow2(mp_int z);
+          Returns k >= 0 such that z = 2^k, if such a k exists; otherwise a
+          value < 0 is returned.
+
+- Other useful functions:
+
+mp_result mp_int_exptmod(mp_int a, mp_int b, mp_int m, mp_int c);
+          Efficiently computes c = a^b (mod m).
+          Returns MP_UNDEF if m = 0; returns MP_RANGE if b < 0.
+
+mp_result mp_int_exptmod_evalue(mp_int a, mp_small v, mp_int m, mp_int c);
+          Efficiently computes c = a^v (mod m).
+mp_result mp_int_exptmod_bvalue(mp_small v, mp_int b, mp_int m, mp_int c);
+          Efficiently computes c = v^b (mod m).
+
+          Note: These routines use Barrett's algorithm for modular reduction.
+          It is widely held (probably correctly) that using Peter Montgomery's
+          multiplication algorithm would make this operation faster; but that
+          algorithm has the restriction that a and m must be coprime, so I have
+          not implemented it here.
+
+mp_result mp_int_exptmod_known(mp_int a, mp_int b, mp_int m, mp_int mu, 
+                               mp_int c);
+          Efficiently computes c = a^b (mod m), given a precomputed reduction
+          constant mu, as defined for Barrett's modular reduction algorithm.
+          Returns MP_UNDEF if m = 0; returns MP_RANGE if b < 0.
+
+mp_result mp_int_redux_const(mp_int m, mp_int c);
+          Computes reduction constant mu for Barrett reduction by modulus m,
+          stores the result in c.
+
+mp_result mp_int_invmod(mp_int a, mp_int m, mp_int c);
+          Computes the modular inverse of a (mod m), if it exists, and assigns
+          the result to c.  Returns the least non-negative representative of
+          the congruence class (mod m) containing this inverse.  Returns
+          MP_UNDEF if the inverse does not exist; returns MP_RANGE if a = 0 or
+          m <= 0.
+
+mp_result mp_int_gcd(mp_int a, mp_int b, mp_int c);
+          Compute the greatest common divisor if a and b, and assign the result
+          to c.  Returns MP_UNDEF if the GCD is not defined (e.g., if a = 0 and
+          b = 0).
+
+mp_result mp_int_egcd(mp_int a, mp_int b, mp_int c, mp_int x, mp_int y);
+          Compute the greatest common divisor of a and b, and assign the result
+          to c.  Also computes x and y satisfying Bezout's identity, namely (a,
+          b) = ax + by.  Returns MP_UNDEF if the GCD is not defined (e.g., if a
+          = b = 0).
+
+mp_result mp_int_lcm(mp_int a, mp_int b, mp_int c)
+          Compute the least common multiple of a and b, and assign the result
+          to c.  Returns MP_UNDEF if the LCM is not defined (e.g., if a = 0 and
+          b = 0).
+
+- Conversion of values:
+
+mp_result mp_int_to_int(mp_int z, mp_small *out);
+          Convert z to an int type, if it is representable as such.  Returns
+          MP_RANGE if z cannot be represented as an value of type mp_small.  If
+          out is NULL no value is stored, but the return value will still be
+          correct.
+
+mp_result mp_int_to_uint(mp_int z, mp_usmall *out);
+          Convert z to an unsigned int type, if it is representable as such.
+          Returns MP_RANGE if z cannot be represented as a value of type
+          mp_usmall.  If out is NULL no value is stored, but the return value
+          will still be correct.
+
+mp_result mp_int_to_string(mp_int z, mp_size radix, char *str, int limit);
+          Convert z to a zero-terminated string of characters in the given
+          radix, writing at most 'limit' characters including the terminating
+          NUL value.  A leading '-' is used to indicate a negative value.
+
+          Returns MP_RANGE if radix < MP_MIN_RADIX or radix > MP_MAX_RADIX.
+          Returns MP_TRUNC if limit is too small to write out all of z.
+
+mp_result mp_int_string_len(mp_int z, mp_size radix);
+          Return the minimum number of characters required to represent z as a
+          zero-terminated string of characters in the given radix. May
+          over-estimate (but generally will not).
+
+          Returns MP_RANGE if radix < MP_MIN_RADIX or radix > MP_MAX_RADIX.
+
+mp_result mp_int_read_string(mp_int z, mp_size radix, const char *str);
+mp_result mp_int_read_cstring(mp_int z, mp_size radix, const char *str, 
+                              char **end);
+          Read a string of ASCII digits in the specified radix from the
+          zero-terminated string provided, and assign z to the corresponding
+          value.  For radices greater than 10, the ASCII letters 'A' .. 'Z' or
+          'a' .. 'z' are used.  Letters are interpreted without respect to
+          case.
+
+          Leading whitespace is ignored, and a leading '+' or '-' is
+          interpreted as a sign flag.  Processing stops when ASCII NUL or any
+          character which is out of range for a digit in the given radix is
+          encountered.
+
+          If the whole string was processed, MP_OK is returned; otherwise,
+          MP_TRUNC is returned.
+
+          Returns MP_RANGE if radix < MP_MIN_RADIX or radix > MP_MAX_RADIX.
+
+          With mp_int_read_cstring(), if end is not NULL, the target pointer is
+          set to point to the first unconsumed character of the input string
+          (the NUL byte, if the whole string was consumed).  This emulates the
+          behavior of the standard C strtol() function.
+
+mp_result mp_int_count_bits(mp_int z);
+          Returns the number of significant bits in z.
+
+mp_result mp_int_to_binary(mp_int z, unsigned char *buf, int limit);
+          Convert z to 2's complement binary, writing at most 'limit' bytes
+          into the given buffer.  Returns MP_TRUNC if the buffer limit was too
+          small to contain the whole value.  If this occurs, the contents of
+          buf will be effectively garbage, as the function uses the buffer as
+          scratch space.
+
+          The binary representation of z is in base-256 with digits ordered
+          from most significant to least significant (network byte ordering).
+          The high-order bit of the first byte is set for negative values,
+          clear for non-negative values.
+
+          As a result, non-negative values will be padded with a leading zero
+          byte if the high-order byte of the base-256 magnitude is set.  This
+          extra byte is accounted for by the mp_int_binary_len() function
+          described below.
+
+mp_result mp_int_read_binary(mp_int z, unsigned char *buf, int len);
+          Read a 2's complement binary value into z, where the length of the
+          buffer is given as 'len'.  The contents of 'buf' may be overwritten
+          during processing, although they will be restored when the function
+          returns.
+
+mp_result mp_int_binary_len(mp_int z);
+          Return the number of bytes required to represent z in 2's complement
+          binary.
+
+mp_result mp_int_to_unsigned(mp_int z, unsigned char *buf, int limit);
+          Convert |z| to unsigned binary, writing at most 'limit' bytes into
+          the given buffer.  The sign of z is ignored, but z is not modified.
+          Returns MP_TRUNC if the buffer limit was too small to contain the
+          whole value.  If this occurs, the contents of buf will be effectively
+          garbage, as the function uses the buffer as scratch space during
+          conversion.
+
+          The binary representation of z is in base-256 with digits ordered
+          from most significant to least significant (network byte ordering).
+
+mp_result mp_int_read_unsigned(mp_int z, unsigned char *buf, int len);
+          Read an unsigned binary value into z, where the length of the buffer
+          is given as 'len'.  The contents of 'buf' will not be modified during
+          processing.
+
+mp_result mp_int_unsigned_len(mp_int z);
+          Return the number of bytes required to represent z as an unsigned
+          binary value using mp_int_to_unsigned().
+
+- Other functions:
+
+Ordinarily, integer multiplication and squaring are done using the simple
+quadratic "schoolbook" algorithm.  However, for sufficiently large values,
+there is a more efficient algorithm usually attributed to Karatsuba and Ofman
+that is usually faster.  See Knuth Vol. 2 for more details about how this
+algorithm works.
+
+The breakpoint between the "normal" and the recursive algorithm is controlled
+by a static constant "multiply_threshold" defined in imath.c, which contains
+the number of significant digits below which the standard algorithm should be
+used.  This is initialized to the value of the compile-time constant
+MP_MULT_THRESH from imath.h.  If you wish to be able to modify this value at
+runtime, compile imath.c with IMATH_TEST defined true in the preprocessor, and
+declare
+
+  extern mp_size multiply_threshold;
+
+When IMATH_TEST is defined, this variable is defined as a mutable global, and
+can be changed.  Otherwise, it is defined as an immutable static constant.  The
+`imtimer' program and the `findthreshold.py' script (Python) can help you find
+a suitable value for MP_MULT_THRESH for your particular platform.
+
+const char *mp_int_error_string(mp_result res);
+          Return a pointer to a brief string describing 'res'.  These strings
+          are defined as a constant array in `imath.c', if you wish to change
+          them for your application.
+
+--- Rational Arithmetic:
+
+mp_result mp_rat_init(mp_rat r);
+          Initialize a new zero-valued rational number in r.
+
+mp_result mp_rat_reduce(mp_rat r);
+          Reduce a rational to canonical form.
+          Removes common factors from the numerator and denomenator and makes
+          the denomenator positive.
+
+mp_result mp_rat_init_size(mp_rat r, mp_size n_prec, mp_size d_prec);
+          As mp_rat_init(), but specifies the number of long digits of
+          precision for numerator (n_prec) and denominator (d_prec).  Use this
+          if you wish to preallocate storage for operations of known output
+          size.
+
+mp_result mp_rat_init_copy(mp_rat r, mp_rat old);
+          As mp_rat_init(), but initializes a copy of an existing rational
+          value.
+
+mp_result mp_rat_set_value(mp_rat r, mp_small numer, mp_small denom);
+          Set the value of the given rational to a ratio specified as ordinary
+          signed integers (denom != 0).  Returns MP_UNDEF if denom = 0.
+
+void      mp_rat_clear(mp_rat r);
+          Release the memory occupied by the given rational number.
+
+mp_result mp_rat_numer(mp_rat r, mp_int z);
+          Extract the numerator of r as an mp_int, and store it in z.
+
+mp_result mp_rat_denom(mp_rat r, mp_int z);
+          Extract the denominator of r as an mp_int, and store it in z.
+
+mp_sign   mp_rat_sign(mp_rat r);
+          Return the sign of the rational number.  Note that an mpq_t
+          is always stored so that the sign of the numerator is the
+          correct sign of the whole value.
+
+mp_result mp_rat_copy(mp_rat a, mp_rat c);
+          Copy a to c.  Avoids unnecessary allocations.
+
+void      mp_rat_zero(mp_rat r);
+          Set r to have the value zero (canonical with denominator 1).
+
+mp_result mp_rat_abs(mp_rat a, mp_rat c);
+          Set c to the absolute value of a.
+
+mp_result mp_rat_neg(mp_rat a, mp_rat c);
+          Set c to the negative (additive inverse) of a.
+
+mp_result mp_rat_recip(mp_rat a, mp_rat c);
+          Take the reciprocal of a and store it in c, if defined.
+          Returns MP_UNDEF if a/c = 0.
+
+mp_result mp_rat_add(mp_rat a, mp_rat b, mp_rat c);
+          Add a + b and store the result in c.
+
+mp_result mp_rat_sub(mp_rat a, mp_rat b, mp_rat c);
+          Subtract a - b and store the result in c.
+
+mp_result mp_rat_mul(mp_rat a, mp_rat b, mp_rat c);
+          Multiply a * b and store the result in c.
+
+mp_result mp_rat_div(mp_rat a, mp_rat b, mp_rat c);
+          Divide a / b, if possible, and store the result in c.
+          Returns MP_UNDEF if b = 0.
+
+mp_result mp_rat_add_int(mp_rat a, mp_int b, mp_rat c);
+          Add a + b and store the result in c.  Note:  b is an integer.
+
+mp_result mp_rat_sub_int(mp_rat a, mp_int b, mp_rat c);
+          Subtract a - b and store the result in c.  Note:  b is an integer.
+
+mp_result mp_rat_mul_int(mp_rat a, mp_int b, mp_rat c);
+          Multiply a * b and store the result in c.  Note:  b is an integer.
+
+mp_result mp_rat_div_int(mp_rat a, mp_int b, mp_rat c);
+          Divide a / b, if possible, and store the result in c.
+          Note:  b is an integer.
+          Returns MP_UNDEF if b = 0.
+
+mp_result mp_rat_expt(mp_rat a, mp_small b, mp_rat c);
+          Raise a to the b power, where b >= 0, and store the result in c.
+
+int       mp_rat_compare(mp_rat a, mp_rat b);
+          Full signed comparison of rational values.
+
+int       mp_rat_compare_unsigned(mp_rat a, mp_rat b);
+          Compare the absolute values of a and b.
+
+int       mp_rat_compare_zero(mp_rat r);
+          Compare r to zero.
+
+int       mp_rat_compare_value(mp_rat r, mp_small n, mp_small d);
+          Compare r to the ratio n/d.
+
+int       mp_rat_is_integer(mp_rat r);
+          Returns true if r can be represented by an integer (i.e.,
+          its denominator is one).
+
+mp_result mp_rat_to_ints(mp_rat r, mp_small *num, mp_small *den);
+          If it is possible to do so, extract the numerator and the denominator
+          of r as regular (signed) integers.  Returns MP_RANGE if either cannot
+          be so represented.
+
+mp_result mp_rat_to_string(mp_rat r, mp_size radix, char *str, int limit);
+          Convert the value of r to a string of the format "n/d" with n and d
+          in the specified radix, writing no more than "limit" bytes of data to
+          the given output buffer.  Includes sign flag.
+
+mp_result mp_rat_to_decimal(mp_rat r, mp_size radix, mp_size prec,
+                            mp_round_mode rmode, char *str, int limit);
+          Convert the value of r to a string in decimal-point notation with the
+          specified radix, writing no more than "limit" bytes of data to the
+          given output buffer.  Generates "prec" digits of precision.
+
+          Values numbers may be rounded when they are being converted for
+          output as a decimal value.  There are four rounding modes currently
+          supported:
+
+          MP_ROUND_DOWN
+            Truncates the value toward zero.  
+            Example:  12.009 to 2dp becomes 12.00
+
+          MP_ROUND_UP
+            Rounds the value away from zero:
+            Example:  12.001 to 2dp becomes 12.01, but
+                      12.000 to 2dp remains 12.00
+
+          MP_ROUND_HALF_DOWN
+             Rounds the value to nearest digit, half goes toward zero.
+             Example:  12.005 to 2dp becomes 12.00, but
+                       12.006 to 2dp becomes 12.01
+
+          MP_ROUND_HALF_UP
+             Rounds the value to nearest digit, half rounds upward.
+             Example:  12.005 to 2dp becomes 12.01, but
+                       12.004 to 2dp becomes 12.00
+
+mp_result mp_rat_string_len(mp_rat r, mp_size radix);
+          Return the length of buffer required to convert r using the
+          mp_rat_to_string() function.  May over-estimate slightly.
+
+mp_result mp_rat_decimal_len(mp_rat r, mp_size radix, mp_size prec);
+          Return the length of buffer required to convert r using the
+          mp_rat_to_decimal() function.  May over-estimate slightly.
+
+mp_result mp_rat_read_string(mp_rat r, mp_size radix, char *str);
+          Read a zero-terminated string in the format "n/d" (including sign
+          flag), and replace the value of r with it.
+
+mp_result mp_rat_read_cstring(mp_rat r, mp_size radix, char *str, char **end);
+          Like mp_rat_read_string(), but with a similar interface to the
+          strtoul() library function.  Used as the back end for the
+          mp_rat_read_string() function.  Returns MP_UNDEF if the denominator
+          read has value zero.
+
+mp_result mp_rat_read_ustring(mp_rat r, mp_size radix, char *str, char **end);
+          A "universal" reader.  Capable of reading plain integers, rational
+          number written in a/b notation, and decimal values in z.f format.
+          The end parameter works as for mp_int_read_cstring().
+
+mp_result mp_rat_read_decimal(mp_rat r, mp_size radix, char *str);
+          A wrapper around mp_rat_read_cdecimal(), which discards the resulting
+          end pointer.
+
+mp_result mp_rat_read_cdecimal(mp_rat r, mp_size radix, char *str, char **end);
+          Read a zero-terminated string in the format "z.f" (including sign
+          flag), and replace r with its value.  If end is not NULL, a pointer
+          to the first unconsumed character of the string is returned.
+
+--- Representation Details
+
+    NOTE:  You do not need to read this section to use IMath.  This is provided
+           for the benefit of developers wishing to extend or modify the
+           internals of the library.
+
+IMath uses a signed magnitude representation for arbitrary precision integers.
+The magnitude is represented as an array of radix-R digits in increasing order
+of significance; the value of R is chosen to be half the size of the largest
+available unsigned integer type, so typically 16 or 32 bits.  Digits are
+represented as mp_digit, which must be an unsigned integral type.
+
+Digit arrays are allocated using malloc(3) and realloc(3).  Because this can be
+an expensive operation, the library takes pains to avoid allocation as much as
+possible.  For this reason, the mpz_t structure distinguishes between how many
+digits are allocated and how many digits are actually consumed by the
+representation.  The fields of an mpz_t are:
+
+       mp_digit    single;  /* single-digit value (see note) */
+       mp_digit   *digits;  /* array of digits               */
+       mp_size     alloc;   /* how many digits are allocated */
+       mp_size     used;    /* how many digits are in use    */
+       mp_sign     sign;    /* the sign of the value         */
+
+The elements of "digits" at indices less than "used" are the significant
+figures of the value; the elements at indices greater than or equal to "used"
+are undefined (and may contain garbage).  At all times, "used" must be at least
+1 and at most "alloc".
+
+To avoid interaction with the memory allocator, single-digit values are stored
+directly in the mpz_t structure, in the .single field.  The semantics of access
+are the same as the more general case.
+
+The number of digits allocated for an mpz_t is referred to in the library
+documentation as its "precision".  Operations that affect an mpz_t cause
+precision to increase as needed.  In any case, all allocations are measured in
+digits, and rounded up to the nearest mp_word boundary.  There is a default
+minimum precision stored as a static constant default_precision (imath.c); its
+value is set to MP_DEFAULT_PREC (imath.h).  If the preprocessor symbol
+IMATH_TEST is defined, this value becomes global and modifiable.
+
+Note that the allocated size of an mpz_t can only grow; the library never
+reallocates in order to decrease the size.  A simple way to do so explicitly is
+to use mp_int_init_copy(), as in:
+
+  mpz_t big, new;
+
+  /* ... */
+  mp_int_init_copy(&new, &big);
+  mp_int_swap(&new, &big);
+  mp_int_clear(&new);
+
+The value of "sign" is 0 for positive values and zero, 1 for negative values.
+Constants MP_ZPOS and MP_NEG are defined for these; no other sign values are
+used.
+
+If you are adding to this library, you should be careful to preserve the
+convention that inputs and outputs can overlap, as described above.  So, for
+example, mp_int_add(a, a, a) is legal.  Often, this means you must maintain one
+or more temporary mpz_t structures for intermediate values.  The private macros
+SETUP(E, C) and TEMP(K) can be used to enforce a conventional structure like
+this:
+
+  {
+    mpz_t     temp[NUM_TEMPS];  /* declare how many you need here */
+    int       last = 0;         /* number of in-use temps         */
+    mp_result res;              /* used for checking results      */
+    ...
+
+    /* Initialization phase */ 
+    SETUP(mp_int_init(TEMP(0)), last);
+    SETUP(mp_int_init_copy(TEMP(1), x), last);
+    ...
+    SETUP(mp_int_init_value(TEMP(7), 3), last);
+
+    /* Work phase */
+    ...
+
+  CLEANUP:
+    while(--last >= 0)
+      mp_int_clear(TEMP(last));
+
+    return res;
+  }
+
+The names "temp" and "res" are fixed -- the SETUP and TEMP macros assume they
+exist.  TEMP(k) returns a pointer to the kth entry of temp.  This structure
+insures that even if a failure occurs during the "initialization phase", no
+memory is leaked.
+
+"Small" integer values are represented by the types mp_small and mp_usmall,
+which are mapped to appropriately-sized types on the host system.  The default
+for mp_small is "long" and the default for mp_usmall is "unsigned long".  You
+may change these, provided you insure that mp_small is signed and mp_usmall is
+unsigned.  You will also need to adjust the size macros:
+
+  MP_SMALL_MIN, MP_SMALL_MAX
+  MP_USMALL_MIN, MP_USMALL_MAX
+
+... which are defined in <imath.h>, if you change these.
+
+Rational numbers are represented using a pair of arbitrary precision integers,
+with the convention that the sign of the numerator is the sign of the rational
+value, and that the result of any rational operation is always represented in
+lowest terms.  The canonical representation for rational zero is 0/1.  See
+"imrat.h".
+
+--- Testing and Reporting of Bugs:
+
+Test vectors are included in the 'tests' subdirectory of the imath
+distribution.  When you run 'make test', it builds the imtest program and runs
+all available test vectors.  If any tests fail, you will get a line like this:
+
+  x    y    FAILED      v
+
+Here, x is the line number of the test which failed, y is index of the test
+within the file, and v is the value(s) actually computed.  The name of the file
+is printed at the beginning of each test, so you can find out what test vector
+failed by executing the following (with x, y, and v replaced by the above
+values, and where "foo.t" is the name of the test file that was being processed
+at the time):
+
+   % tail +x tests/foo.t | head -1
+
+None of the tests should fail [but see Note 2]; if any do, it probably
+indicates a bug in the library (or at the very least, some assumption I made
+which I shouldn't have).  Please send a bug report to the address below, which
+includes the FAILED test line above, as well as the output of the above 'tail'
+command (so I know what inputs caused the failure).
+
+If you build with the preprocessor symbol DEBUG defined as a positive integer,
+you will have access to several things:
+
+ 1. The static functions defined in imath.c are made globally visible so that
+    you can call them from a test driver.
+
+ 2. The s_print() and s_print_buf() routines are defined; these make it easier
+    to dump the contents of an mpz_t to text.
+
+ 3. If DEBUG > 1, the digit allocators (s_alloc, s_realloc) fill all new
+    buffers with the value 0xDEADBEEF, or as much of it as will fit in a digit,
+    so that you can more easily catch uninitialized reads in the debugger.
+
+--- Notes:
+
+1. You can generally use the same variables for both input and output.  One
+   exception is that you may not use the same variable for both the quotient
+   and the remainder of mp_int_div().
+
+2. Many of the tests for this library were written under the assumption that
+   the mp_small type is 32 bits or more.  If you compile with a smaller type,
+   you may see MP_RANGE errors in some of the tests that otherwise pass (due to
+   conversion failures).  Also, the pi generator (pi.c) will not work correctly
+   if mp_small is too short, as its algorithm for arc tangent is fairly
+   simple-minded.
+
+--- Contacts:
+
+The IMath library was written by 
+Michael J. Fromberger <http://spinning-yarns.org/michael/>
+
+If you discover any bugs or testing failures, please send e-mail to
+the following address:
+
+    <michael.j.fromberger at gmail.com>
+
+Please be sure to include, with any bug report, a complete description of what
+goes wrong, and if possible, a test vector for imtest or a minimal test program
+that will demonstrate the bug on your system.  Please also let me know what
+hardware, operating system, and compiler you're using.
+
+--- Acknowledgements:
+
+The algorithms used in this library came from Vol. 2 of Donald Knuth's "The Art
+of Computer Programming" (Seminumerical Algorithms).  Thanks to Nelson Bolyard,
+Bryan Olson, Tom St. Denis, Tushar Udeshi, and Eric Silva for excellent
+feedback on earlier versions of this code.  Special thanks to Jonathan Shapiro
+for some very helpful design advice, as well as feedback and some clever ideas
+for improving performance in some common use cases.
+
+--- License and Disclaimers:
+
+IMath is Copyright 2002-2009 Michael J. Fromberger
+You may use it subject to the following Licensing Terms:
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

Added: polly/trunk/lib/External/isl/imath/examples/basecvt.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/examples/basecvt.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/examples/basecvt.c (added)
+++ polly/trunk/lib/External/isl/imath/examples/basecvt.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,121 @@
+/*
+  Name:     basecvt.c
+  Purpose:  Convert integers and rationals from one base to another.
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+  Info:     $Id: basecvt.c 635 2008-01-08 18:19:40Z sting $
+
+  Copyright (C) 2004-2008 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "imath.h"
+#include "imrat.h"
+
+int main(int argc, char *argv[])
+{
+  mp_size   in_rdx, out_rdx;
+  mpq_t     value;
+  mp_result res;
+  int       ix;
+
+  if(argc < 4) {
+    fprintf(stderr, "Usage: basecvt <ibase> <obase> <values>+\n");
+    return 1;
+  }
+
+  in_rdx  = atoi(argv[1]);
+  out_rdx = atoi(argv[2]);
+
+  if(in_rdx < MP_MIN_RADIX || in_rdx > MP_MAX_RADIX) {
+    fprintf(stderr, 
+	    "basecvt: input radix %u not allowed (minimum %u, "
+	    "maximum %u)\n", in_rdx, MP_MIN_RADIX, MP_MAX_RADIX);
+    return 3;
+  }
+  if(out_rdx < MP_MIN_RADIX || out_rdx > MP_MAX_RADIX) {
+    fprintf(stderr, 
+	    "basecvt: output radix %u not allowed (minimum %u, "
+	    "maximum %u)\n", out_rdx, MP_MIN_RADIX, MP_MAX_RADIX);
+    return 3;
+  }
+  
+  if((res = mp_rat_init(&value)) != MP_OK) {
+    fprintf(stderr, "basecvt: out of memory\n");
+    return 2;
+  }
+
+  for(ix = 3; ix < argc; ++ix) {
+    char *buf, *endp = NULL;
+    mp_result   len;
+    int         is_int;
+
+    if((res = mp_rat_read_ustring(&value, in_rdx, argv[ix], &endp)) != MP_OK &&
+       res != MP_TRUNC) {
+      fprintf(stderr, "basecvt:  error reading argument %d: %s\n", ix,
+	      mp_error_string(res));
+      break;
+    }
+    else if(*endp != '\0') {
+      fprintf(stderr, "basecvt:  argument %d contains '%s' not in base %u\n",
+	      ix, endp, in_rdx);
+      continue;
+    }
+
+    if((is_int = mp_rat_is_integer(&value)) != 0) {
+      len = mp_int_string_len(MP_NUMER_P(&value), out_rdx);
+    }
+    else {
+      len = mp_rat_string_len(&value, out_rdx);
+    }
+    
+    if((buf = malloc(len)) == NULL) {
+      fprintf(stderr, "basecvt:  out of memory\n");
+      break;
+    }
+    
+    if(is_int) {
+      res = mp_int_to_string(MP_NUMER_P(&value), out_rdx, buf, len);
+    }
+    else {
+      res = mp_rat_to_string(&value, out_rdx, buf, len);
+    }
+
+    if(res != MP_OK) {
+      fprintf(stderr, "basecvt:  error converting argument %d: %s\n", ix,
+	      mp_error_string(res));
+      free(buf);
+      break;
+    }
+   
+    printf("%s\n", buf);
+    free(buf);
+  }
+  
+  mp_rat_clear(&value);
+
+  return (res != MP_OK);
+}
+
+/* Here there be dragons */

Added: polly/trunk/lib/External/isl/imath/examples/findprime.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/examples/findprime.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/examples/findprime.c (added)
+++ polly/trunk/lib/External/isl/imath/examples/findprime.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,72 @@
+/*
+  Name:     findprime.c
+  Purpose:  Find probable primes.
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+  Info:     $Id: findprime.c 635 2008-01-08 18:19:40Z sting $
+
+  Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
+
+  Notes:
+  Find the first prime number in sequence starting from the given value.
+  Demonstrates the use of mp_int_find_prime().
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#include <stdio.h>
+
+#include "iprime.h"
+
+int main(int argc, char *argv[])
+{
+  char   buf[4096];
+  mpz_t  seed;
+  mp_result res;
+
+  if(argc < 2) {
+    fprintf(stderr, "Usage: %s <start-value>\n", argv[0]);
+    return 1;
+  }
+
+  mp_int_init(&seed);
+  if((res = mp_int_read_string(&seed, 10, argv[1])) != MP_OK) {
+    fprintf(stderr, "%s: error reading `%s': %d\n", 
+	    argv[0], argv[1], res);
+    return 2;
+  }
+
+  if(mp_int_compare_value(&seed, 131) <= 0) {
+    fprintf(stderr, "%s: please enter a start value > 131\n",
+	    argv[0]);
+    return 1;
+  }
+
+  if((res = mp_int_find_prime(&seed)) != MP_TRUE) {
+    fprintf(stderr, "%s: error finding prime: %d\n",
+	    argv[0], res);
+    return 2;
+  }
+
+  mp_int_to_string(&seed, 10, buf, sizeof(buf));
+  printf("=> %s\n", buf);
+
+  mp_int_clear(&seed);
+
+  return 0;
+}

Added: polly/trunk/lib/External/isl/imath/examples/imcalc.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/examples/imcalc.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/examples/imcalc.c (added)
+++ polly/trunk/lib/External/isl/imath/examples/imcalc.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,1471 @@
+/*
+  Name:     imcalc.c
+  Purpose:  Simple RPN calculator based on IMath library.
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  This is a very simplistic RPN calculator that will let you test the features
+  of the IMath built-in functions.
+
+  Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <ctype.h>
+#include <errno.h>
+#include <assert.h>
+
+#include <unistd.h>
+
+#include "imath.h"
+#include "imrat.h"
+#include "iprime.h"
+
+/* A cstate_t represents a stack of operands; numeric operands are pushed on
+   the stack, and commands cause them to be consumed in various ways.
+ */
+typedef struct {
+  /* Operand stack    */
+  mp_int    *elts;
+  mp_size    alloc;   /* number of slots available */
+  mp_size    used;    /* number of slots free      */
+
+  /* Named variables  */
+  mp_int    *mem;     /* named memory slots        */
+  char     **names;   /* names of memory slots     */
+  mp_size    mslots;  /* number of memory slots    */
+  mp_size    mused;   /* number of used memories   */
+
+  /* I/O components   */
+  FILE      *ifp;     /* input file handle         */
+  char      *ibuf;    /* input scratch buffer      */
+  int        buflen;  /* size of scratch buffer    */
+} cstate_t;
+
+/* {{{ State function prototypes */
+
+static mp_result state_init(cstate_t *sp, mp_size n_elts);
+static void      state_clear(cstate_t *sp);
+static void      stack_flush(cstate_t *sp);
+static mp_result stack_push(cstate_t *sp, mp_int elt);
+static mp_result stack_pop(cstate_t *sp);
+static mp_result mem_insert(cstate_t *sp, const char *name, mp_int value);
+static mp_result mem_recall(cstate_t *sp, const char *name, mp_int value);
+static mp_result mem_clear(cstate_t *sp);
+
+/* }}} */
+
+/* {{{ Calculation function prototypes */
+
+typedef mp_result (*op_func)(cstate_t *);
+
+static mp_result cf_abs(cstate_t *sp);
+static mp_result cf_neg(cstate_t *sp);
+static mp_result cf_add(cstate_t *sp);
+static mp_result cf_sub(cstate_t *sp);
+static mp_result cf_mul(cstate_t *sp);
+static mp_result cf_divmod(cstate_t *sp);
+static mp_result cf_div(cstate_t *sp);
+static mp_result cf_mod(cstate_t *sp);
+static mp_result cf_expt(cstate_t *sp);
+static mp_result cf_exptmod(cstate_t *sp);
+static mp_result cf_square(cstate_t *sp);
+static mp_result cf_invmod(cstate_t *sp);
+static mp_result cf_gcd(cstate_t *sp);
+static mp_result cf_xgcd(cstate_t *sp);
+static mp_result cf_sqrt(cstate_t *sp);
+static mp_result cf_root(cstate_t *sp);
+static mp_result cf_cmplt(cstate_t *sp);
+static mp_result cf_cmpgt(cstate_t *sp);
+static mp_result cf_cmple(cstate_t *sp);
+static mp_result cf_cmpge(cstate_t *sp);
+static mp_result cf_cmpeq(cstate_t *sp);
+static mp_result cf_cmpne(cstate_t *sp);
+static mp_result cf_inc(cstate_t *sp);
+static mp_result cf_dec(cstate_t *sp);
+static mp_result cf_fact(cstate_t *sp);
+static mp_result cf_pprint(cstate_t *sp);
+static mp_result cf_print(cstate_t *sp);
+static mp_result cf_pstack(cstate_t *sp);
+static mp_result cf_clstk(cstate_t *sp);
+static mp_result cf_pop(cstate_t *sp);
+static mp_result cf_dup(cstate_t *sp);
+static mp_result cf_copy(cstate_t *sp);
+static mp_result cf_swap(cstate_t *sp);
+static mp_result cf_rot(cstate_t *sp);
+static mp_result cf_pick(cstate_t *sp);
+static mp_result cf_setr(cstate_t *sp);
+static mp_result cf_setbin(cstate_t *sp);
+static mp_result cf_help(cstate_t *sp);
+static mp_result cf_store(cstate_t *sp);
+static mp_result cf_recall(cstate_t *sp);
+static mp_result cf_cmem(cstate_t *sp);
+static mp_result cf_pmem(cstate_t *sp);
+static mp_result cf_qrecall(cstate_t *sp);
+
+/* }}} */
+
+/* {{{ Built-in operator records, g_ops[] */
+
+typedef struct {
+  char    *name;         /* The name of the operator.           */
+  int      stack_size;   /* Number of stack arguments required. */
+  op_func  handler;      /* Function implementing operation.    */
+  char    *descript;     /* Human-readable description.         */
+} calcop_t;
+
+static calcop_t g_ops[] = {
+  { "abs",   1, cf_abs,     "x -- |x|" },
+  { "neg",   1, cf_neg,     "x -- (-x)" },
+  { "+",     2, cf_add,     "x y -- (x+y)" },
+  { "add",   2, cf_add,     "x y -- (x+y)" },
+  { "-",     2, cf_sub,     "x y -- (x-y)" },
+  { "sub",   2, cf_sub,     "x y -- (x-y)" },
+  { "*",     2, cf_mul,     "x y -- (x*y)" },
+  { "mul",   2, cf_mul,     "x y -- (x*y)" },
+  { "/",     2, cf_divmod,  "x y -- q r ; x = yq + r, 0 <= r < y" },
+  { "//",    2, cf_div,     "x y -- (x div y)" },
+  { "div",   2, cf_div,     "x y -- (x div y)" },
+  { "%",     2, cf_mod,     "x y -- (x mod y)" },
+  { "mod",   2, cf_mod,     "x y -- (x mod y)" },
+  { "^",     2, cf_expt,    "x y -- (x^y)" },
+  { "expt",  2, cf_expt,    "x y -- (x^y)" },
+  { "^^",    3, cf_exptmod, "x y m -- (x^y mod m)" },
+  { "emod",  3, cf_exptmod, "x y m -- (x^y mod m)" },
+  { "sqr",   1, cf_square,  "x -- (x*x)" },
+  { "inv",   2, cf_invmod,  "x m -- (1/x mod m)" },
+  { "gcd",   2, cf_gcd,     "x y -- gcd(x, y)" },
+  { "xgcd",  2, cf_xgcd,    "x y -- g u v ; g = ux + vy" },
+  { "sqrt",  1, cf_sqrt,    "x -- floor(sqrt(x))" },
+  { "root",  2, cf_root,    "x y -- floor(x^{1/y}) ; y > 0" },
+  { "<",     2, cf_cmplt,   "x y -- (x<y)" },
+  { ">",     2, cf_cmpgt,   "x y -- (x>y)" }, 
+  { "<=",    2, cf_cmple,   "x y -- (x<=y)" },
+  { ">=",    2, cf_cmpge,   "x y -- (x>=y)" },
+  { "=",     2, cf_cmpeq,   "x y -- (x=y)" },
+  { "<>",    2, cf_cmpne,   "x y -- (x<>y)" },
+  { "inc",   1, cf_inc,     "x -- (x+1)" },
+  { "dec",   1, cf_dec,     "x -- (x-1)" },
+  { "!",     1, cf_fact,    "x -- x!" },
+  { "fact",  1, cf_fact,    "x -- x!" },
+
+  { ".",     1, cf_pprint,  "x -- ; print x in current output mode" },
+  { ";",     1, cf_print,   "x -- x ; print x in current output mode" },
+  { "?",     0, cf_pstack,  "-- ; print stack" },
+  { "cls",   0, cf_clstk,   "... -- ; clear stack" },
+  { "$",     1, cf_pop,     "x --" },
+  { "drop",  1, cf_pop,     "x --" },
+  { "dup",   1, cf_dup,     "x -- x x" },
+  { "copy",  2, cf_copy,    "vn ... v1 v0 n -- vn ... v0 vn ... v0" },
+  { "swap",  2, cf_swap,    "x y -- y x" },
+  { "rot",   3, cf_rot,     "a b c -- b c a" },
+  { "pick",  2, cf_pick,    "... v2 v1 v0 n -- ... v2 v1 v0 vn" },
+
+  { ">>",    1, cf_store,   "x -- ; save in named variable" },
+  { "<<",    0, cf_recall,  "-- x ; recall from named variable" },
+  { "clm",   0, cf_cmem,    "-- ; clear memory" },
+  { "??",    0, cf_pmem,    "-- ; print memory" },
+
+  { "out",   1, cf_setr,    "r -- ; set output radix to r" },
+  { "bin",   0, cf_setbin,  "-- ; set output format to binary" },
+  { "help",  0, cf_help,    "-- ; print help message" },
+
+  /* This is the end-marker, but it is also used to catch implicit
+     variable lookups from memory.
+   */
+  { NULL,    0, cf_qrecall, "-- x ; recall from named variable" }, 
+};
+
+/* }}} */
+
+#define BUFFER_SIZE  16384 /* max. length of input values, in chars */
+
+/* Token types from the primitive lexical analyzer */
+typedef enum { t_eof, t_symbol, t_number, t_error } token_t;
+
+/* {{{ Helper functions */
+
+static token_t   next_token(FILE *ifp, char *buf, int size);
+static mp_result read_number(char *buf, mp_int *out);
+static int       find_command(cstate_t *ops);
+static void      print_value(mp_int v);
+static mp_result run_file(FILE *ifp, cstate_t *op_state);
+
+/* }}} */
+
+/* Error code used internally to signal input problems. */
+static mp_result MP_INPUT;
+
+static int g_output_radix = 10;  /* output radix */
+static FILE *g_output_file = NULL;
+
+int main(int argc, char *argv[]) 
+{
+  extern char *optarg;
+  extern int   optind;
+
+  int   opt, errs = 0;
+  FILE *ifp;
+
+  cstate_t op_state;
+  mp_result res;
+
+  MP_INPUT = MP_MINERR - 1;
+
+  g_output_file = stdout;
+  while((opt = getopt(argc, argv, "ho:")) != EOF) {
+    switch(opt) {
+    case 'h':
+      fprintf(stderr,
+	      "Usage: imcalc [-h] [-o <output>] input*\n\n"
+	      "Options:\n"
+	      "  -h          : display this help message.\n"
+	      "  -o <output> : send output to file.\n\n"
+
+	      "If no input files are given, the standard input is read.  The\n"
+	      "special file name \"-\" is interpreted to mean the standard input.\n"
+	      "Output goes to standard output unless \"-o\" is used.\n\n");
+      return 0;
+
+    case 'o':
+      if((g_output_file = fopen(optarg, "wt")) == NULL) {
+	fprintf(stderr, "Unable to open \"%s\" for writing: %s\n",
+		optarg, strerror(errno));
+	return 1;
+      }
+      break;
+
+    default:
+      fprintf(stderr, 
+	      "Usage: imcalc [-h] [-o <output>] input*\n"
+	      "       [use \"imcalc -h\" to get help]\n\n");
+      return 1;
+    }
+  }
+
+  if((res = state_init(&op_state, 1)) != MP_OK) {
+    fprintf(stderr, "Error: state_init: %s\n", 
+	    mp_error_string(res));
+    return 1;
+  }
+
+  if(optind < argc) {
+    int ix;
+
+    for(ix = optind; ix < argc; ++ix) {
+      if(strcmp(argv[ix], "-") == 0) 
+	ifp = stdin;
+      else if((ifp = fopen(argv[optind], "rt")) == NULL) {
+	fprintf(stderr, "Unable to open \"%s\" for reading: %s\n",
+		argv[optind], strerror(errno));
+	return 1;
+      }
+
+      if(run_file(ifp, &op_state) != MP_OK)
+	++errs;
+    }
+
+    state_clear(&op_state);
+    return errs > 0;
+  }
+  else {
+    int rv = 1 - (run_file(stdin, &op_state) == MP_OK);
+    state_clear(&op_state);    
+    return rv;
+  }
+}
+
+/* {{{ next_token(*ifp, *buf, size) */
+
+static token_t next_token(FILE *ifp, char *buf, int size)
+{
+  int ch, pos = 0;
+  token_t res;
+
+  assert(buf != NULL && size > 0);
+  
+  while((ch = fgetc(ifp)) != EOF && isspace(ch))
+    /* empty */;
+  
+  if(ch == EOF) {
+    buf[0] = '\0';
+    return t_eof;
+  }
+
+  if(ch == '-') {
+    int next = fgetc(ifp);
+    if(next == EOF || !isdigit(next))
+      res = t_symbol;
+    else
+      res = t_number;
+    ungetc(next, ifp);
+  }
+  else if(isdigit(ch) || ch == '#')
+    res = t_number;
+  else
+    res = t_symbol;
+
+  buf[pos++] = ch;
+  while((ch = fgetc(ifp)) != EOF) {
+    if((res == t_number && ispunct(ch) && ch != '-') ||
+       (res == t_symbol && isdigit(ch)) ||
+       isspace(ch)) {
+      ungetc(ch, ifp);
+      break;
+    }
+    else if(pos + 1 >= size) {
+      res = t_error;
+      break;
+    }
+    buf[pos++] = ch;
+  }
+
+  buf[pos] = '\0';
+  return res;
+}
+
+/* }}} */
+
+/* {{{ read_number(*buf, *out) */
+
+static mp_result read_number(char *buf, mp_int *out)
+{
+  int radix = 10, pos = 0;
+  mp_result res;
+  mp_int    value;
+
+  assert(buf != NULL && out != NULL);
+
+  if(buf[pos] == '#') {
+    switch(buf[1]) {
+    case 'b': case 'B':
+      radix = 2;
+      break;
+    case 'd': case 'D':
+      radix = 10;
+      break;
+    case 'o': case 'O':
+      radix = 8;
+      break;
+    case 'x': case 'X':
+      radix = 16;
+      break;
+    default:
+      return MP_BADARG;
+    }
+
+    pos += 2;
+  }
+
+  if((value = mp_int_alloc()) == NULL) {
+    *out = NULL; 
+    return MP_MEMORY;
+  }
+  
+  if((res = mp_int_read_string(value, radix, buf + pos)) != MP_OK) {
+    mp_int_free(value);
+    *out = NULL;
+    return res;
+  }
+  
+  *out = value;
+  return res;
+}
+
+/* }}} */
+
+/* {{{ find_command(*buf) */
+
+static int       find_command(cstate_t *op)
+{
+  int ix, jx;
+  char *buf = op->ibuf;
+
+  /* First, try to find the command by name */
+  for(ix = 0; g_ops[ix].name != NULL; ++ix) {
+    if(strcasecmp(buf, g_ops[ix].name) == 0)
+      return ix;
+  }
+
+  /* If we don't find the command, try a variable lookup */
+  for(jx = 0; jx < op->mused; ++jx) {
+    if(strcmp(buf, op->names[jx]) == 0) 
+      return ix; /* sentinel */
+  }
+
+  /* If variable lookup fails, report command not found */
+  return -1;
+}
+
+/* }}} */
+
+/* {{{ print_value(v) */
+
+static void      print_value(mp_int v)
+{
+  if(g_output_radix == 0) {
+    mp_result len = mp_int_binary_len(v);
+    unsigned char *buf = malloc(len);
+    int ix;
+
+    if(buf != NULL) {
+      mp_int_to_binary(v, buf, len);
+      for(ix = 0; ix < len - 1; ++ix) {
+	fprintf(g_output_file, "%02x.", buf[ix]);
+      }
+      fprintf(g_output_file, "%02x\n", buf[ix]);
+      free(buf);
+    }
+    else 
+      fprintf(g_output_file, "<insufficient memory to print>\n");
+  }
+  else {
+    mp_result len = mp_int_string_len(v, g_output_radix);
+    char *buf = malloc(len);
+
+    if(buf != NULL) {
+      mp_int_to_string(v, g_output_radix, buf, len);
+      fputs(buf, g_output_file);
+      fputc('\n', g_output_file);
+      free(buf);
+    }
+    else
+      fprintf(g_output_file, "<insufficient memory to print>\n");
+  }
+}
+
+/* }}} */
+
+/* {{{ run_file(*ifp, *op_state) */
+
+static mp_result run_file(FILE *ifp, cstate_t *op_state)
+{
+  mp_result  res = MP_OK;
+  token_t    next;
+
+  op_state->ifp = ifp;
+  while((next = next_token(ifp, op_state->ibuf, op_state->buflen)) != t_eof) {
+    mp_int value = NULL;
+    int    cpos;
+
+    switch(next) {
+    case t_number:
+      if((res = read_number(op_state->ibuf, &value)) != MP_OK) 
+	fprintf(stderr, "error: invalid number syntax: %s\n", op_state->ibuf);
+      else if((res = stack_push(op_state, value)) != MP_OK)
+	goto EXIT;
+      break;
+    case t_symbol:
+      if((cpos = find_command(op_state)) < 0) 
+	fprintf(stderr, "error: command not understood: %s\n", op_state->ibuf);
+      else if(op_state->used < g_ops[cpos].stack_size) {
+	fprintf(stderr, "error: not enough arguments (have %d, want %d)\n",
+		op_state->used, g_ops[cpos].stack_size);
+      }
+      else if((res = (g_ops[cpos].handler)(op_state)) != MP_OK) {
+	if(res == MP_INPUT) 
+	  fprintf(stderr, "error: incorrect input format\n");
+	else 
+	  fprintf(stderr, "error: %s\n", mp_error_string(res));
+      }
+      break;
+    default:
+      fprintf(stderr, "error: invalid input token: %s\n", op_state->ibuf);
+      res = MP_BADARG;
+      goto EXIT;
+    }
+  }
+
+ EXIT:
+  return res;
+}
+
+/* }}} */
+
+/* {{{ state_init(*sp, n_elts) */
+
+static mp_result state_init(cstate_t *sp, mp_size n_elts)
+{
+  int ix;
+
+  assert(sp != NULL && n_elts > 0);
+
+  if((sp->elts = malloc(n_elts * sizeof(*(sp->elts)))) == NULL)
+    return MP_MEMORY;
+  if((sp->mem = malloc(n_elts * sizeof(*(sp->mem)))) == NULL) {
+    free(sp->elts);
+    return MP_MEMORY;
+  }
+  if((sp->names = malloc(n_elts * sizeof(*(sp->names)))) == NULL) {
+    free(sp->mem);
+    free(sp->elts);
+    return MP_MEMORY;
+  }
+  if((sp->ibuf = malloc(BUFFER_SIZE * sizeof(char))) == NULL) {
+    free(sp->names);
+    free(sp->mem);
+    free(sp->elts);
+    return MP_MEMORY;
+  }
+  
+  for(ix = 0; ix < n_elts; ++ix) {
+    sp->elts[ix]  = NULL;
+    sp->mem[ix]   = NULL;
+    sp->names[ix] = NULL;
+  }
+
+  sp->alloc  = n_elts;
+  sp->used   = 0;
+  sp->mslots = n_elts;
+  sp->mused  = 0;
+  sp->buflen = BUFFER_SIZE;
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ state_clear(*sp) */
+
+static void      state_clear(cstate_t *sp)
+{
+  assert(sp != NULL);
+
+  if(sp->elts != NULL) {
+    int ix;
+
+    for(ix = 0; ix < sp->used; ++ix) {
+      mp_int_clear(sp->elts[ix]);
+      sp->elts[ix] = NULL; 
+    }
+
+    free(sp->elts);
+    sp->elts = NULL;
+    sp->alloc = 0;
+    sp->used = 0;
+  }
+  if(sp->mem != NULL) {
+    int ix;
+
+    for(ix = 0; ix < sp->mused; ++ix) {
+      mp_int_free(sp->mem[ix]);
+      sp->mem[ix] = NULL;
+      free(sp->names[ix]);
+      sp->names[ix] = NULL;
+    }
+
+    free(sp->mem);
+    sp->mem = NULL;
+    free(sp->names);
+    sp->names = NULL;
+    
+    sp->mslots = 0;
+    sp->mused  = 0;
+  }
+  if(sp->ibuf != NULL) {
+    free(sp->ibuf);
+    sp->buflen = 0;
+  }
+  if(sp->ifp != NULL) {
+    fclose(sp->ifp);
+    sp->ifp = NULL;
+  }
+}
+
+/* }}} */
+
+/* {{{ stack_flush(*sp) */
+
+static void      stack_flush(cstate_t *sp)
+{
+  int ix;
+
+  assert(sp != NULL && sp->elts != NULL);
+  
+  for(ix = 0; ix < sp->used; ++ix) {
+    mp_int_clear(sp->elts[ix]);
+    sp->elts[ix] = NULL;
+  }
+
+  sp->used = 0;
+}
+
+/* }}} */
+
+/* {{{ stack_push(*sp, elt) */
+
+static mp_result stack_push(cstate_t *sp, mp_int elt)
+{
+  if(sp->used >= sp->alloc) {
+    mp_size nsize = 2 * sp->alloc;
+    mp_int *tmp;
+    int ix;
+    
+    if((tmp = malloc(nsize * sizeof(*(sp->elts)))) == NULL)
+      return MP_MEMORY;
+
+    for(ix = 0; ix < sp->used; ++ix)
+      tmp[ix] = sp->elts[ix];
+
+    free(sp->elts);
+    sp->elts = tmp;
+    sp->alloc = nsize;
+  }
+
+  sp->elts[sp->used++] = elt;
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ stack_pop(*sp) */
+
+static mp_result stack_pop(cstate_t *sp)
+{
+  assert(sp != NULL && sp->elts != NULL);
+
+  if(sp->used == 0)
+    return MP_UNDEF;
+
+  sp->used -= 1;
+  mp_int_clear(sp->elts[sp->used]);
+  sp->elts[sp->used] = NULL;
+  
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ mem_insert(*sp, *name, value) */
+
+static mp_result mem_insert(cstate_t *sp, const char *name, mp_int value)
+{
+  int ix;
+
+  for(ix = 0; ix < sp->mused; ++ix) {
+    if(strcmp(name, sp->names[ix]) == 0)
+      break;
+  }
+
+  /* Two cases:
+     ix < sp->mused   ==> replacing existing entry.
+     otherwise        ==> adding new entry, may need to grow dictionary.
+   */
+  if(ix < sp->mused) { 
+    mp_int_free(sp->mem[ix]); /* fall through to the end */
+  } 
+  else {
+    if(sp->mused >= sp->mslots) {
+      mp_size nsize = 2 * sp->mslots;
+      mp_int  *tz;
+      char   **tc;
+      int      jx;
+
+      if((tz = malloc(nsize * sizeof(*(sp->mem)))) == NULL)
+	return MP_MEMORY;
+      if((tc = malloc(nsize * sizeof(*(sp->names)))) == NULL) {
+	free(tz);
+	return MP_MEMORY;
+      }
+      
+      for(jx = 0; jx < sp->mused; ++jx) {
+	tz[jx] = sp->mem[jx];
+	tc[jx] = sp->names[jx];
+      }
+      
+      free(sp->mem);
+      sp->mem = tz;
+      free(sp->names);
+      sp->names = tc;
+      
+      sp->mslots = nsize;
+    }
+
+    sp->mused += 1;
+    sp->names[ix] = malloc(1 + strlen(name));
+    strcpy(sp->names[ix], name);
+  }
+
+  sp->mem[ix] = mp_int_alloc();
+  return mp_int_copy(value, sp->mem[ix]);
+}
+
+/* }}} */
+
+/* {{{ mem_recall(*sp, *name, value) */
+
+static mp_result mem_recall(cstate_t *sp, const char *name, mp_int value)
+{
+  int ix;
+
+  for(ix = 0; ix < sp->mused; ++ix) {
+    if(strcmp(name, sp->names[ix]) == 0) {
+      return mp_int_copy(sp->mem[ix], value);
+    }
+  }
+
+  return MP_UNDEF; /* not found */
+}
+
+/* }}} */
+
+/* {{{ mem_clear(*sp) */
+
+static mp_result mem_clear(cstate_t *sp)
+{
+  int ix;
+
+  for(ix = 0; ix < sp->mused; ++ix) {
+    mp_int_free(sp->mem[ix]);
+    free(sp->names[ix]);
+  }
+  sp->mused = 0;
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ cf_abs(sp) */
+
+static mp_result cf_abs(cstate_t *sp)
+{
+  mp_int a = sp->elts[sp->used - 1];
+
+  return mp_int_abs(a, a);
+}
+
+/* }}} */
+
+/* {{{ cf_neg(sp) */
+
+static mp_result cf_neg(cstate_t *sp)
+{
+  mp_int a = sp->elts[sp->used - 1];
+
+  return mp_int_neg(a, a);
+}
+
+/* }}} */
+
+/* {{{ cf_add(sp) */
+
+static mp_result cf_add(cstate_t *sp)
+{
+  mp_int b = sp->elts[sp->used - 1];
+  mp_int a = sp->elts[sp->used - 2];
+  mp_result res = mp_int_add(a, b, a);
+
+  if(res == MP_OK)
+    stack_pop(sp);
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ cf_sub(sp) */
+
+static mp_result cf_sub(cstate_t *sp)
+{
+  mp_int b = sp->elts[sp->used - 1];
+  mp_int a = sp->elts[sp->used - 2];
+  mp_result res = mp_int_sub(a, b, a);
+
+  if(res == MP_OK)
+    stack_pop(sp);
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ cf_mul(sp) */
+
+static mp_result cf_mul(cstate_t *sp)
+{
+  mp_int b = sp->elts[sp->used - 1];
+  mp_int a = sp->elts[sp->used - 2];
+  mp_result res = mp_int_mul(a, b, a);
+
+  if(res == MP_OK)
+    stack_pop(sp);
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ cf_divmod(sp) */
+
+static mp_result cf_divmod(cstate_t *sp)
+{
+  mp_int b = sp->elts[sp->used - 1];
+  mp_int a = sp->elts[sp->used - 2];
+  
+  return mp_int_div(a, b, a, b);
+}
+
+/* }}} */
+
+/* {{{ cf_div(sp) */
+
+static mp_result cf_div(cstate_t *sp)
+{
+  mp_int b = sp->elts[sp->used - 1];
+  mp_int a = sp->elts[sp->used - 2];
+  mp_result res = mp_int_div(a, b, a, NULL);
+
+  if(res == MP_OK)
+    stack_pop(sp);
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ cf_mod(sp) */
+
+static mp_result cf_mod(cstate_t *sp)
+{
+  mp_int b = sp->elts[sp->used - 1];
+  mp_int a = sp->elts[sp->used - 2];
+  mp_result res = mp_int_mod(a, b, a);
+
+  if(res == MP_OK)
+    stack_pop(sp);
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ cf_expt(sp) */
+
+static mp_result cf_expt(cstate_t *sp)
+{
+  mp_int b = sp->elts[sp->used - 1];
+  mp_int a = sp->elts[sp->used - 2];
+  mp_result res;
+  mp_small  bval;
+
+  if((res = mp_int_to_int(b, &bval)) != MP_OK)
+    return res;
+
+  stack_pop(sp);
+  return mp_int_expt(a, bval, a);
+}
+
+/* }}} */
+
+/* {{{ cf_exptmod(sp) */
+
+static mp_result cf_exptmod(cstate_t *sp)
+{
+  mp_int m = sp->elts[sp->used - 1];
+  mp_int b = sp->elts[sp->used - 2];
+  mp_int a = sp->elts[sp->used - 3];
+  mp_result res = mp_int_exptmod(a, b, m, a);
+
+  if(res == MP_OK) {
+    stack_pop(sp);
+    stack_pop(sp);
+  }
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ cf_square(sp) */
+
+static mp_result cf_square(cstate_t *sp)
+{
+  mp_int a = sp->elts[sp->used - 1];
+
+  return mp_int_sqr(a, a);
+}
+
+/* }}} */
+
+/* {{{ cf_invmod(sp) */
+
+static mp_result cf_invmod(cstate_t *sp)
+{
+  mp_int m = sp->elts[sp->used - 1];
+  mp_int a = sp->elts[sp->used - 2];
+  mp_result res = mp_int_invmod(a, m, a);
+
+  stack_pop(sp);
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ cf_gcd(sp) */
+
+static mp_result cf_gcd(cstate_t *sp)
+{
+  mp_int b = sp->elts[sp->used - 1];
+  mp_int a = sp->elts[sp->used - 2];
+  mp_result res = mp_int_gcd(a, b, a);
+
+  if(res == MP_OK)
+    stack_pop(sp);
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ cf_xgcd(sp) */
+
+static mp_result cf_xgcd(cstate_t *sp)
+{
+  mp_int b = sp->elts[sp->used - 1];
+  mp_int a = sp->elts[sp->used - 2];
+  mp_int t;
+  mp_result res;
+
+  if((t = mp_int_alloc()) == NULL) 
+    return MP_MEMORY;
+  if((res = mp_int_egcd(a, b, a, b, t)) != MP_OK) {
+    mp_int_free(t);
+    return res;
+  }
+
+  if((res = stack_push(sp, t)) != MP_OK)
+    mp_int_free(t);
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ cf_sqrt(sp) */
+
+static mp_result cf_sqrt(cstate_t *sp)
+{
+  mp_int a = sp->elts[sp->used - 1];
+
+  return mp_int_sqrt(a, a);
+}
+
+/* }}} */
+
+/* {{{ cf_root(sp) */
+
+static mp_result cf_root(cstate_t *sp)
+{
+  mp_int a = sp->elts[sp->used - 2];
+  mp_int bp = sp->elts[sp->used - 1];
+  mp_small b;
+  mp_result res;
+  
+  if((res = mp_int_to_int(bp, &b)) != MP_OK)
+    return res;
+
+  stack_pop(sp);
+  return mp_int_root(a, b, a);
+}
+
+/* }}} */
+
+/* {{{ cf_cmplt(sp) */
+
+static mp_result cf_cmplt(cstate_t *sp)
+{
+  mp_int b = sp->elts[sp->used - 1];
+  mp_int a = sp->elts[sp->used - 2];
+  mp_result res;
+
+  res = mp_int_set_value(a, (mp_int_compare(a, b) < 0));
+  stack_pop(sp);
+  return res;
+}
+
+/* }}} */
+
+/* {{{ cf_cmpgt(sp) */
+
+static mp_result cf_cmpgt(cstate_t *sp)
+{
+  mp_int b = sp->elts[sp->used - 1];
+  mp_int a = sp->elts[sp->used - 2];
+  mp_result res;
+
+  res = mp_int_set_value(a, (mp_int_compare(a, b) > 0));
+  stack_pop(sp);
+  return res;
+}
+
+/* }}} */
+
+/* {{{ cf_cmple(sp) */
+
+static mp_result cf_cmple(cstate_t *sp)
+{
+  mp_int b = sp->elts[sp->used - 1];
+  mp_int a = sp->elts[sp->used - 2];
+  mp_result res;
+
+  res = mp_int_set_value(a, (mp_int_compare(a, b) <= 0));
+  stack_pop(sp);
+  return res;
+}
+
+/* }}} */
+
+/* {{{ cf_cmpge(sp) */
+
+static mp_result cf_cmpge(cstate_t *sp)
+{
+  mp_int b = sp->elts[sp->used - 1];
+  mp_int a = sp->elts[sp->used - 2];
+  mp_result res;
+
+  res = mp_int_set_value(a, (mp_int_compare(a, b) >= 0));
+  stack_pop(sp);
+  return res;
+}
+
+/* }}} */
+
+/* {{{ cf_cmpeq(sp) */
+
+static mp_result cf_cmpeq(cstate_t *sp)
+{
+  mp_int b = sp->elts[sp->used - 1];
+  mp_int a = sp->elts[sp->used - 2];
+  mp_result res;
+
+  res = mp_int_set_value(a, (mp_int_compare(a, b) == 0));
+  stack_pop(sp);
+  return res;
+}
+
+/* }}} */
+
+/* {{{ cf_cmpne(sp) */
+
+static mp_result cf_cmpne(cstate_t *sp)
+{
+  mp_int b = sp->elts[sp->used - 1];
+  mp_int a = sp->elts[sp->used - 2];
+  mp_result res;
+
+  res = mp_int_set_value(a, (mp_int_compare(a, b) != 0));
+  stack_pop(sp);
+  return res;
+}
+
+/* }}} */
+
+/* {{{ cf_inc(sp) */
+
+static mp_result cf_inc(cstate_t *sp)
+{
+  mp_int a = sp->elts[sp->used - 1];
+
+  return mp_int_add_value(a, 1, a);
+}
+
+/* }}} */
+
+/* {{{ cf_dec(sp) */
+
+static mp_result cf_dec(cstate_t *sp)
+{
+  mp_int a = sp->elts[sp->used - 1];
+
+  return mp_int_sub_value(a, 1, a);
+}
+
+/* }}} */
+
+/* {{{ cf_fact(sp) */
+
+static mp_result cf_fact(cstate_t *sp)
+{
+  mpz_t  tmp;
+  mp_int x = sp->elts[sp->used - 1];
+  mp_result res = MP_OK;
+
+  if (mp_int_compare_zero(x) < 0)
+    return MP_UNDEF;
+
+  (void) mp_int_init_value(&tmp, 1);
+
+  while (mp_int_compare_value(x, 1) > 0) {
+    if ((res = mp_int_mul(&tmp, x, &tmp)) != MP_OK)
+      goto CLEANUP;
+    if ((res = mp_int_sub_value(x, 1, x)) != MP_OK)
+      goto CLEANUP;
+  }
+
+  res = mp_int_copy(&tmp, x);
+
+ CLEANUP:
+  mp_int_clear(&tmp);
+  return res;
+}
+
+/* }}} */
+
+/* {{{ cf_pprint(sp) */
+
+static mp_result cf_pprint(cstate_t *sp)
+{
+  print_value(sp->elts[sp->used - 1]);
+  stack_pop(sp);
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ cf_print(sp) */
+
+static mp_result cf_print(cstate_t *sp)
+{
+  print_value(sp->elts[sp->used - 1]);
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ cf_pstack(sp) */
+
+static mp_result cf_pstack(cstate_t *sp)
+{
+  int ix;
+
+  if(sp->used == 0) {
+    fprintf(g_output_file, "<stack empty>\n");
+  }
+  else {
+    for(ix = 0; ix < sp->used; ++ix) {
+      fprintf(g_output_file, "%2d: ", ix);
+      print_value(sp->elts[sp->used - 1 - ix]);
+    }
+  }
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ cf_clstk(sp) */
+
+static mp_result cf_clstk(cstate_t *sp)
+{
+  stack_flush(sp);
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ cf_pop(sp) */
+
+static mp_result cf_pop(cstate_t *sp)
+{
+  return stack_pop(sp);
+}
+
+/* }}} */
+
+/* {{{ cf_dup(sp) */
+
+static mp_result cf_dup(cstate_t *sp)
+{
+  mp_int cp = mp_int_alloc();
+  mp_result res;
+
+  if(cp == NULL)
+    return MP_MEMORY;
+
+  if((res = mp_int_copy(sp->elts[sp->used - 1], cp)) != MP_OK) {
+    mp_int_free(cp);
+    return res;
+  }
+
+  if((res = stack_push(sp, cp)) != MP_OK) 
+    mp_int_free(cp);
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ cf_copy(sp) */
+
+static mp_result cf_copy(cstate_t *sp)
+{
+  mp_int n = sp->elts[sp->used - 1];
+  mp_result res;
+  mp_small  ncopy;
+  int       ix;
+
+  if((res = mp_int_to_int(n, &ncopy)) != MP_OK)
+    return res;
+
+  if(ncopy < 1 || ncopy >= sp->used)
+    return MP_RANGE;
+  
+  stack_pop(sp);
+  
+  for(ix = 0; ix < ncopy; ++ix) {
+    mp_int old = sp->elts[sp->used - ncopy];
+    mp_int new = mp_int_alloc();
+
+    if(new == NULL)
+      return MP_MEMORY;
+
+    if((res = mp_int_copy(old, new)) != MP_OK) {
+      mp_int_free(new);
+      return res;
+    }
+    if((res = stack_push(sp, new)) != MP_OK)
+      return res;
+  }
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ cf_swap(sp) */
+
+static mp_result cf_swap(cstate_t *sp)
+{
+  mp_int t = sp->elts[sp->used - 1];
+  
+  sp->elts[sp->used - 1] = sp->elts[sp->used - 2];
+  sp->elts[sp->used - 2] = t;
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ cf_rot(sp) */
+
+static mp_result cf_rot(cstate_t *sp)
+{
+  mp_int t = sp->elts[sp->used - 3];
+
+  sp->elts[sp->used - 3] = sp->elts[sp->used - 2];
+  sp->elts[sp->used - 2] = sp->elts[sp->used - 1];
+  sp->elts[sp->used - 1] = t;
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ cf_pick(sp) */
+
+static mp_result cf_pick(cstate_t *sp)
+{
+  mp_int n = sp->elts[sp->used - 1];
+  mp_result res;
+  mp_small  pos = 0;
+
+  if((res = mp_int_to_int(n, &pos)) != MP_OK)
+    return res;
+
+  if(pos < 0 || pos >= sp->used - 1)
+    return MP_RANGE;
+
+  return mp_int_copy(sp->elts[sp->used - 2 - pos], n);
+}
+
+/* }}} */
+
+/* {{{ cf_setr(sp) */
+
+static mp_result cf_setr(cstate_t *sp)
+{
+  mp_int a = sp->elts[sp->used - 1];
+  mp_result res;
+  mp_small  rdx = 0;
+
+  if((res = mp_int_to_int(a, &rdx)) != MP_OK)
+    return res;
+
+  if(rdx < MP_MIN_RADIX || rdx > MP_MAX_RADIX)
+    return MP_RANGE;
+
+  g_output_radix = rdx;
+  stack_pop(sp);
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ cf_setbin(sp) */
+
+static mp_result cf_setbin(cstate_t *sp)
+{
+  g_output_radix = 0;
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ cf_help(sp) */
+
+static mp_result cf_help(cstate_t *sp)
+{
+  int ix, maxlen = 10; /* minimum width */
+
+  for(ix = 0; g_ops[ix].name != NULL; ++ix) {
+    int len = strlen(g_ops[ix].name);
+
+    if(len > maxlen)
+      maxlen = len;
+  }
+
+  fprintf(stderr, "Operators understood:\n");
+  for(ix = 0; g_ops[ix].name != NULL; ++ix) {
+    int len = strlen(g_ops[ix].name);
+
+    fputs(g_ops[ix].name, stderr);
+    while(len++ <=  maxlen)
+      fputc(' ', stderr);
+
+    fprintf(stderr, "%s\n", g_ops[ix].descript);
+  }
+  fputc('\n', stderr);
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ cf_store(*sp) */
+
+static mp_result cf_store(cstate_t *sp)
+{
+  mp_result res;
+
+  if(next_token(sp->ifp, sp->ibuf, sp->buflen) != t_symbol)
+    return MP_INPUT;
+
+  if((res = mem_insert(sp, sp->ibuf, sp->elts[sp->used - 1])) != MP_OK)
+    return res;
+
+  return stack_pop(sp);
+}
+
+/* }}} */
+
+/* {{{ cf_recall(*sp) */
+
+static mp_result cf_recall(cstate_t *sp)
+{
+  mp_result res;
+  mp_int    val;
+
+  if(next_token(sp->ifp, sp->ibuf, sp->buflen) != t_symbol)
+    return MP_INPUT;
+
+  if((val = mp_int_alloc()) == NULL)
+    return MP_MEMORY;
+  if((res = mem_recall(sp, sp->ibuf, val)) != MP_OK) {
+    mp_int_free(val);
+    return res;
+  }
+
+  return stack_push(sp, val);
+}
+
+/* }}} */
+
+/* {{{ cf_cmem(*sp) */
+
+static mp_result cf_cmem(cstate_t *sp)
+{
+  return mem_clear(sp);
+}
+
+/* }}} */
+
+/* {{{ cf_pmem(*sp) */
+
+static mp_result cf_pmem(cstate_t *sp)
+{
+  int ix, max_len = 0;
+
+  if(sp->mused == 0) {
+    fprintf(g_output_file, "<memory empty>\n");
+    return MP_OK;
+  }
+
+  for(ix = 0; ix < sp->mused; ++ix) {
+    int ln = strlen(sp->names[ix]);
+
+    if(ln > max_len)
+      max_len = ln;
+  }
+
+  max_len += 1; /* allow for a padding space */
+
+  for(ix = 0; ix < sp->mused; ++ix) {
+    int ln = strlen(sp->names[ix]);
+
+    fprintf(g_output_file, "%s:", sp->names[ix]);
+
+    while(ln++ < max_len) 
+      fputc(' ', g_output_file);
+
+    print_value(sp->mem[ix]);
+  }
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ cf_qrecall(*sp) */
+
+static mp_result cf_qrecall(cstate_t *sp)
+{
+  mp_result res;
+  mp_int    val;
+
+  if((val = mp_int_alloc()) == NULL)
+    return MP_MEMORY;
+
+  if((res = mem_recall(sp, sp->ibuf, val)) != MP_OK) {
+    mp_int_free(val); 
+    return res;
+  }
+
+  return stack_push(sp, val);
+}
+
+/* }}} */
+
+/* Here there be dragons */

Added: polly/trunk/lib/External/isl/imath/examples/input.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/examples/input.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/examples/input.c (added)
+++ polly/trunk/lib/External/isl/imath/examples/input.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,120 @@
+/*
+  input.c
+
+  Demonstrates basic input and output of arbitrary precision integers using
+  IMath.
+
+  by Michael J. Fromberger <http://spinning-yarns.org/michael/>
+  Copyright (C) 2003-2008 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "imrat.h"
+
+int main(int argc, char *argv[])
+{
+  mp_size   radix = 10;  /* Default output radix */
+  mpq_t     value;
+  mp_result res;
+  char      *endp;
+
+  if(argc < 2) {
+    fprintf(stderr, "Usage: input <value> [output-base]\n");
+    return 1;
+  }
+  if(argc > 2) {
+    if((radix = atoi(argv[2])) < MP_MIN_RADIX ||
+       (radix > MP_MAX_RADIX)) {
+      fprintf(stderr, "Error:  Specified radix is out of range (%d)\n",
+	      radix);
+      return 1;
+    }
+  }
+
+  /* Initialize a new value, initially zero; illustrates how to check
+     for errors (e.g., out of memory) and display a message.  */
+  if((res = mp_rat_init(&value)) != MP_OK) {
+    fprintf(stderr, "Error in mp_rat_init(): %s\n", 
+	    mp_error_string(res));
+    return 1;
+  }
+
+  /* Read value in base 10 */
+  if((res = mp_rat_read_ustring(&value, 0, argv[1], &endp)) != MP_OK) {
+    fprintf(stderr, "Error in mp_rat_read_ustring(): %s\n",
+	    mp_error_string(res));
+    
+    if(res == MP_TRUNC)
+      fprintf(stderr, " -- remaining input is: %s\n", endp);
+    
+    mp_rat_clear(&value);
+    return 1;
+  }
+  
+  printf("Here is your value in base %d\n", radix);
+  {
+    mp_result buf_size, res;
+    char *obuf;
+
+    if(mp_rat_is_integer(&value)) {
+      /* Allocate a buffer big enough to hold the given value, including
+	 sign and zero terminator. */
+      buf_size = mp_int_string_len(MP_NUMER_P(&value), radix);
+      obuf = malloc(buf_size);
+
+      /* Convert the value to a string in the desired radix. */
+      if((res = mp_int_to_string(MP_NUMER_P(&value), radix, 
+				 obuf, buf_size)) != MP_OK) {
+	fprintf(stderr, "Converstion to base %d failed: %s\n",
+		radix, mp_error_string(res));
+	mp_rat_clear(&value);
+	return 1;
+      }
+    } 
+    else {
+      /* Allocate a buffer big enough to hold the given value, including
+	 sign and zero terminator. */
+      buf_size = mp_rat_string_len(&value, radix);
+      obuf = malloc(buf_size);
+
+      /* Convert the value to a string in the desired radix. */
+      if((res = mp_rat_to_string(&value, radix, obuf, buf_size)) != MP_OK) {
+	fprintf(stderr, "Conversion to base %d failed: %s\n",
+		radix, mp_error_string(res));
+	mp_rat_clear(&value);
+	return 1;
+      }
+    }
+    fputs(obuf, stdout);
+    fputc('\n', stdout);
+    free(obuf);
+  }
+
+  /* When you are done with a value, it must be "cleared" to release
+     the memory it occupies */
+  mp_rat_clear(&value);
+  return 0;
+}
+
+/* Here there be dragons */

Added: polly/trunk/lib/External/isl/imath/examples/randprime.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/examples/randprime.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/examples/randprime.c (added)
+++ polly/trunk/lib/External/isl/imath/examples/randprime.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,261 @@
+/*
+  Name:     randprime.c
+  Purpose:  Generate a probable prime at random.
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  Usage:  randprime [-s] <bits> [<outfile>]
+
+  Generate a randomly-chosen probable prime having <bits> significant bits, and
+  write it to the specified output file or to the standard output.  If the "-s"
+  option is given, a prime p is chosen such that (p - 1) / 2 is also prime.
+
+  A prime is obtained by reading random bits from /dev/random, setting the
+  low-order bit, and testing for primality.  If the first candidate is not
+  prime, successive odd candidates are tried until a probable prime is found.
+
+  Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <limits.h>
+
+#include <unistd.h>
+
+#include "imath.h"
+#include "iprime.h"
+
+/* Load the specified buffer with random bytes */
+int randomize(unsigned char *buf, size_t len);
+
+/* Overwrite the specified value with n_bits random bits */
+mp_result mp_int_randomize(mp_int a, mp_size n_bits);
+
+/* Find a prime starting from the given odd seed */
+mp_result find_prime(mp_int seed, FILE *fb);
+mp_result find_strong_prime(mp_int seed, FILE *fb);
+
+typedef mp_result (*find_f)(mp_int, FILE *);
+
+int main(int argc, char *argv[])
+{
+  int       opt, modbits;
+  FILE     *ofp = stdout;
+  mp_result res;
+  find_f    find_func = find_prime;
+  char      tag = 'p';
+  mpz_t     value;
+
+  /* Process command-line arguments */
+  while((opt = getopt(argc, argv, "s")) != EOF) {
+    switch(opt) {
+    case 's':
+      find_func = find_strong_prime;
+      tag = 'P';
+      break;
+    default:
+      fprintf(stderr, "Usage: randprime [-s] <bits> [<outfile>]\n");
+      return 1;
+    }
+  }
+  
+  if(optind >= argc) {
+    fprintf(stderr, "Error:  You must specify the number of significant bits.\n");
+    fprintf(stderr, "Usage: randprime [-s] <bits> [<outfile>]\n");
+    return 1;
+  }
+  modbits = (int) strtol(argv[optind++], NULL, 0);
+  if(modbits < CHAR_BIT) {
+    fprintf(stderr, "Error:  Invalid value for number of significant bits.\n");
+    return 1;
+  }
+  if(modbits % 2 == 1)
+    ++modbits;
+
+  /* Check if output file is specified */
+  if(optind < argc) {
+    if((ofp = fopen(argv[optind], "wt")) == NULL) {
+      fprintf(stderr, "Error:  Unable to open output file for writing.\n"
+	      " - Filename: %s\n"
+	      " - Error:    %s\n", argv[optind], strerror(errno));
+      return 1;
+    }
+  }
+  
+  mp_int_init(&value);
+  if ((res = mp_int_randomize(&value, modbits - 1)) != MP_OK) {
+    fprintf(stderr, "Error:  Unable to generate random start value.\n"
+	    " - %s (%d)\n", mp_error_string(res), res);
+    goto EXIT;
+  }
+  fprintf(stderr, "%c: ", tag);
+  find_func(&value, stderr);
+  fputc('\n', stderr);
+
+  /* Write the completed value to the specified output file */
+  {
+    int len;
+    char *obuf;
+
+    len = mp_int_string_len(&value, 10);
+    obuf = malloc(len);
+    mp_int_to_string(&value, 10, obuf, len);
+    fputs(obuf, ofp);
+    fputc('\n', ofp);
+
+    free(obuf);
+  }
+
+ EXIT:
+  fclose(ofp);
+  mp_int_clear(&value);
+  return 0;
+}
+
+/* {{{ randomize(buf, len) */
+
+int randomize(unsigned char *buf, size_t len)
+{
+  FILE *rnd = fopen("/dev/random", "rb");
+  size_t nr;
+
+  if(rnd == NULL)
+    return -1;
+  
+  nr = fread(buf, sizeof(*buf), len, rnd);
+  fclose(rnd);
+  
+  return (int) nr;
+}
+
+/* }}} */
+
+/* {{{ mp_int_randomize(a, n_bits) */
+
+mp_result mp_int_randomize(mp_int a, mp_size n_bits)
+{
+  mp_size n_bytes = (n_bits + CHAR_BIT - 1) / CHAR_BIT;
+  unsigned char *buf;
+  mp_result res = MP_OK;
+  
+  if((buf = malloc(n_bytes)) == NULL)
+    return MP_MEMORY;
+  
+  if(randomize(buf, n_bytes) != n_bytes) {
+    res = MP_TRUNC;
+    goto CLEANUP;
+  }
+
+  /* Clear bits beyond the number requested */
+  if(n_bits % CHAR_BIT != 0) {
+    unsigned char b_mask = (1 << (n_bits % CHAR_BIT)) - 1;
+    unsigned char t_mask = (1 << (n_bits % CHAR_BIT)) >> 1;
+
+    buf[0] &= b_mask;
+    buf[0] |= t_mask;
+  }
+
+  /* Set low-order bit to insure value is odd */
+  buf[n_bytes - 1] |= 1;
+
+  res = mp_int_read_unsigned(a, buf, n_bytes);
+
+ CLEANUP:
+  memset(buf, 0, n_bytes);
+  free(buf);
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ find_prime(seed, fb) */
+
+mp_result find_prime(mp_int seed, FILE *fb)
+{
+  mp_result res;
+  int       count = 0;
+
+  if(mp_int_is_even(seed))
+    if((res = mp_int_add_value(seed, 1, seed)) != MP_OK)
+      return res;
+  
+  while((res = mp_int_is_prime(seed)) == MP_FALSE) {
+    ++count;
+
+    if(fb != NULL && (count % 50) == 0)
+      fputc('.', fb);
+
+    if((res = mp_int_add_value(seed, 2, seed)) != MP_OK)
+      return res;
+  }
+
+  if(res == MP_TRUE && fb != NULL)
+    fputc('+', fb);
+  
+  return res;
+}
+
+/* }}} */
+
+/* {{{ find_strong_prime(seed, fb) */
+
+mp_result find_strong_prime(mp_int seed, FILE *fb)
+{
+  mp_result res;
+  mpz_t     t;
+
+  mp_int_init(&t);
+  for(;;) {
+    if ((res = find_prime(seed, fb)) != MP_TRUE)
+      break;
+    if ((res = mp_int_copy(seed, &t)) != MP_OK)
+      break;
+
+    if ((res = mp_int_mul_pow2(&t, 1, &t)) != MP_OK ||
+	(res = mp_int_add_value(&t, 1, &t)) != MP_OK) 
+      break;
+
+    if ((res = mp_int_is_prime(&t)) == MP_TRUE) {
+      if (fb != NULL)
+	fputc('!', fb);
+
+      res = mp_int_copy(&t, seed);
+      break;
+    }
+    else if (res != MP_FALSE) 
+      break;
+
+    if (fb != NULL)
+      fputc('x', fb);
+    if ((res = mp_int_add_value(seed, 2, seed)) != MP_OK)
+      break;
+  }
+
+  mp_int_clear(&t);
+  return res;
+}
+
+/* }}} */
+
+/* Here there be dragons */

Added: polly/trunk/lib/External/isl/imath/examples/rounding.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/examples/rounding.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/examples/rounding.c (added)
+++ polly/trunk/lib/External/isl/imath/examples/rounding.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,83 @@
+/*
+  Name:     rounding.c
+  Purpose:  Demonstrates rounding modes.
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  Bugs:  The rounding mode can only be specified by value, not name.
+
+  Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+#include "imath.h"
+#include "imrat.h"
+
+int main(int argc, char *argv[])
+{
+  mp_result  mode, len, res = 0;
+  mp_size    prec, radix;
+  mpq_t      value;
+  char      *buf;
+
+  if(argc < 5) {
+    fprintf(stderr, "Usage: rounding <mode> <precision> <radix> <value>\n");
+    return 1;
+  }
+
+  if((res = mp_rat_init(&value)) != MP_OK) {
+    fprintf(stderr, "Error initializing: %s\n", mp_error_string(res));
+    return 2;
+  }
+
+  mode = atoi(argv[1]);
+  prec = atoi(argv[2]);
+  radix = atoi(argv[3]);
+  
+  printf("Rounding mode:   %d\n"
+	 "Precision:       %u digits\n"
+	 "Radix:           %u\n"
+	 "Input string:    \"%s\"\n", mode, prec, radix, argv[4]);
+  
+  if((res = mp_rat_read_decimal(&value, radix, argv[4])) != MP_OK) {
+    fprintf(stderr, "Error reading input string: %s\n", 
+	    mp_error_string(res));
+    goto CLEANUP;
+  }
+
+  len = mp_rat_decimal_len(&value, radix, prec);
+  buf = malloc(len);
+
+  if((res = mp_rat_to_decimal(&value, radix, prec, mode, buf, len)) != MP_OK)
+    fprintf(stderr, "Error converting output: %s\n",
+	    mp_error_string(res));
+
+  printf("Result string:   \"%s\"\n", buf);
+  free(buf);
+
+ CLEANUP:
+  mp_rat_clear(&value);
+  return res;
+}
+
+/* Here there be dragons */

Added: polly/trunk/lib/External/isl/imath/examples/rsakey.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/examples/rsakey.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/examples/rsakey.c (added)
+++ polly/trunk/lib/External/isl/imath/examples/rsakey.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,325 @@
+/*
+  Name:     rsakey.c
+  Purpose:  Generate keys for the RSA cryptosystem.
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  Usage:  rsakey [-e <expt>] <modbits> [<outfile>]
+
+  Generates an RSA key pair with a modulus having <modbits> significant bits,
+  and writes it to the specified output file, or to the standard output.  The
+  -e option allows the user to specify an encryption exponent; otherwise, an
+  encryption exponent is chosen at random.
+  
+  Primes p and q are obtained by reading random bits from /dev/random, setting
+  the low-order bit, and testing for primality.  If the first candidate is not
+  prime, successive odd candidates are tried until a probable prime is found.
+
+  Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <limits.h>
+
+#include <unistd.h>
+
+#include "imath.h"
+#include "iprime.h"
+
+typedef struct {
+  mpz_t   p;
+  mpz_t   q;
+  mpz_t   n;
+  mpz_t   e;
+  mpz_t   d;
+} rsa_key;
+
+/* Load the specified buffer with random bytes */
+int randomize(unsigned char *buf, size_t len);
+
+/* Overwrite the specified value with n_bits random bits */
+mp_result mp_int_randomize(mp_int a, mp_size n_bits);
+
+/* Find a prime starting from the given odd seed */
+mp_result find_prime(mp_int seed, FILE *fb);
+
+/* Initialize/destroy an rsa_key structure */
+mp_result rsa_key_init(rsa_key *kp);
+void      rsa_key_clear(rsa_key *kp);
+void      rsa_key_write(rsa_key *kp, FILE *ofp);
+
+int main(int argc, char *argv[])
+{
+  int       opt, modbits;
+  FILE     *ofp = stdout;
+  char     *expt = NULL;
+  rsa_key   the_key;
+  mp_result res;
+
+  /* Process command-line arguments */
+  while((opt = getopt(argc, argv, "e:")) != EOF) {
+    switch(opt) {
+    case 'e':
+      expt = optarg;
+      break;
+    default:
+      fprintf(stderr, "Usage: rsakey [-e <expt>] <modbits> [<outfile>]\n");
+      return 1;
+    }
+  }
+  
+  if(optind >= argc) {
+    fprintf(stderr, "Error:  You must specify the number of modulus bits.\n");
+    fprintf(stderr, "Usage: rsakey [-e <expt>] <modbits> [<outfile>]\n");
+    return 1;
+  }
+  modbits = (int) strtol(argv[optind++], NULL, 0);
+  if(modbits < CHAR_BIT) {
+    fprintf(stderr, "Error:  Invalid value for number of modulus bits.\n");
+    return 1;
+  }
+  if(modbits % 2 == 1)
+    ++modbits;
+
+  /* Check if output file is specified */
+  if(optind < argc) {
+    if((ofp = fopen(argv[optind], "wt")) == NULL) {
+      fprintf(stderr, "Error:  Unable to open output file for writing.\n"
+	      " - Filename: %s\n"
+	      " - Error:    %s\n", argv[optind], strerror(errno));
+      return 1;
+    }
+  }
+  
+  if((res = rsa_key_init(&the_key)) != MP_OK) {
+    fprintf(stderr, "Error initializing RSA key structure:\n"
+	    " - %s (%d)\n", mp_error_string(res), res);
+    return 1;
+  }
+
+  /* If specified, try to load the key exponent */
+  if(expt != NULL) {
+    if((res = mp_int_read_string(&(the_key.e), 10, expt)) != MP_OK) {
+      fprintf(stderr, "Error:  Invalid value for encryption exponent.\n"
+	      " - %s (%d)\n", mp_error_string(res), res);
+      goto EXIT;
+    }
+  }
+
+  if((res = mp_int_randomize(&(the_key.p), (modbits / 2))) != MP_OK) {
+    fprintf(stderr, "Error:  Unable to randomize first prime.\n"
+	    " - %s (%d)\n", mp_error_string(res), res);
+    goto EXIT;
+  }
+  fprintf(stderr, "p: ");
+  find_prime(&(the_key.p), stderr);
+
+  if((res = mp_int_randomize(&(the_key.q), (modbits / 2))) != MP_OK) {
+    fprintf(stderr, "Error:  Unable to randomize second prime.\n"
+	    " - %s (%d)\n", mp_error_string(res), res);
+    goto EXIT;
+  }
+  fprintf(stderr, "\nq: ");
+  find_prime(&(the_key.q), stderr);
+  fputc('\n', stderr);
+
+  /* Temporarily, the key's "n" field will be (p - 1) * (q - 1) for
+     purposes of computing the decryption exponent.
+   */
+  mp_int_mul(&(the_key.p), &(the_key.q), &(the_key.n));
+  mp_int_sub(&(the_key.n), &(the_key.p), &(the_key.n));
+  mp_int_sub(&(the_key.n), &(the_key.q), &(the_key.n));
+  mp_int_add_value(&(the_key.n), 1, &(the_key.n));
+
+  if(expt == NULL &&
+     (res = mp_int_randomize(&(the_key.e), (modbits / 2))) != MP_OK) {
+    fprintf(stderr, "Error:  Unable to randomize encryption exponent.\n"
+	    " - %s (%d)\n", mp_error_string(res), res);
+    goto EXIT;
+  }
+  while((res = mp_int_invmod(&(the_key.e), &(the_key.n), 
+			     &(the_key.d))) != MP_OK) {
+    if(expt != NULL) {
+      fprintf(stderr, "Error:  Unable to compute decryption exponent.\n"
+	      " - %s (%d)\n", mp_error_string(res), res);
+      goto EXIT;
+    }
+    if((res = mp_int_randomize(&(the_key.e), (modbits / 2))) != MP_OK) {
+      fprintf(stderr, "Error:  Unable to re-randomize encryption exponent.\n"
+	      " - %s (%d)\n", mp_error_string(res), res);
+      goto EXIT;
+    }
+  }
+
+  /* Recompute the real modulus, now that exponents are done. */
+  mp_int_mul(&(the_key.p), &(the_key.q), &(the_key.n));
+
+  /* Write completed key to the specified output file */
+  rsa_key_write(&the_key, ofp);
+
+ EXIT:
+  fclose(ofp);
+  rsa_key_clear(&the_key);
+  return 0;
+}
+
+/* {{{ randomize(buf, len) */
+
+int randomize(unsigned char *buf, size_t len)
+{
+  FILE *rnd = fopen("/dev/random", "rb");
+  size_t nr;
+
+  if(rnd == NULL)
+    return -1;
+  
+  nr = fread(buf, sizeof(*buf), len, rnd);
+  fclose(rnd);
+  
+  return (int) nr;
+}
+
+/* }}} */
+
+/* {{{ mp_int_randomize(a, n_bits) */
+
+mp_result mp_int_randomize(mp_int a, mp_size n_bits)
+{
+  mp_size n_bytes = (n_bits + CHAR_BIT - 1) / CHAR_BIT;
+  unsigned char *buf;
+  mp_result res = MP_OK;
+  
+  if((buf = malloc(n_bytes)) == NULL)
+    return MP_MEMORY;
+  
+  if(randomize(buf, n_bytes) != n_bytes) {
+    res = MP_TRUNC;
+    goto CLEANUP;
+  }
+
+  /* Clear bits beyond the number requested */
+  if(n_bits % CHAR_BIT != 0) {
+    unsigned char b_mask = (1 << (n_bits % CHAR_BIT)) - 1;
+    unsigned char t_mask = (1 << (n_bits % CHAR_BIT)) >> 1;
+
+    buf[0] &= b_mask;
+    buf[0] |= t_mask;
+  }
+
+  /* Set low-order bit to insure value is odd */
+  buf[n_bytes - 1] |= 1;
+
+  res = mp_int_read_unsigned(a, buf, n_bytes);
+
+ CLEANUP:
+  memset(buf, 0, n_bytes);
+  free(buf);
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ find_prime(seed, fb) */
+
+mp_result find_prime(mp_int seed, FILE *fb)
+{
+  mp_result res;
+  int       count = 0;
+
+  if(mp_int_is_even(seed))
+    if((res = mp_int_add_value(seed, 1, seed)) != MP_OK)
+      return res;
+  
+  while((res = mp_int_is_prime(seed)) == MP_FALSE) {
+    ++count;
+
+    if(fb != NULL && (count % 50) == 0)
+      fputc('.', fb);
+
+    if((res = mp_int_add_value(seed, 2, seed)) != MP_OK)
+      return res;
+  }
+
+  if(res == MP_TRUE && fb != NULL)
+    fputc('+', fb);
+  
+  return res;
+}
+
+/* }}} */
+
+/* {{{ rsa_key_init(kp) */
+
+mp_result rsa_key_init(rsa_key *kp)
+{
+  mp_int_init(&(kp->p));
+  mp_int_init(&(kp->q));
+  mp_int_init(&(kp->n));
+  mp_int_init(&(kp->e));
+  mp_int_init(&(kp->d));
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ rsa_key_clear(kp) */
+
+void      rsa_key_clear(rsa_key *kp)
+{
+  mp_int_clear(&(kp->p));
+  mp_int_clear(&(kp->q));
+  mp_int_clear(&(kp->n));
+  mp_int_clear(&(kp->e));
+  mp_int_clear(&(kp->d));  
+}
+
+/* }}} */
+
+/* {{{ rsa_key_write(kp, ofp) */
+
+void      rsa_key_write(rsa_key *kp, FILE *ofp)
+{
+  int   len;
+  char *obuf;
+
+  len = mp_int_string_len(&(kp->n), 10);
+  obuf = malloc(len);
+  mp_int_to_string(&(kp->p), 10, obuf, len);
+  fprintf(ofp, "p = %s\n", obuf);
+  mp_int_to_string(&(kp->q), 10, obuf, len);
+  fprintf(ofp, "q = %s\n", obuf);
+  mp_int_to_string(&(kp->e), 10, obuf, len);
+  fprintf(ofp, "e = %s\n", obuf);
+  mp_int_to_string(&(kp->d), 10, obuf, len);
+  fprintf(ofp, "d = %s\n", obuf);
+  mp_int_to_string(&(kp->n), 10, obuf, len);
+  fprintf(ofp, "n = %s\n", obuf);
+
+  free(obuf);
+}
+
+/* }}} */
+
+/* Here there be dragons */

Added: polly/trunk/lib/External/isl/imath/findsizes.py
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/findsizes.py?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/findsizes.py (added)
+++ polly/trunk/lib/External/isl/imath/findsizes.py Wed Feb  4 14:55:43 2015
@@ -0,0 +1,174 @@
+#!/usr/bin/env python
+##
+## Name:     findsizes.py
+## Purpose:  Find acceptable digit and word types for IMath.
+## Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+##
+##  Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
+##
+##  Permission is hereby granted, free of charge, to any person obtaining a
+##  copy of this software and associated documentation files (the "Software"),
+##  to deal in the Software without restriction, including without limitation
+##  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+##  and/or sell copies of the Software, and to permit persons to whom the
+##  Software is furnished to do so, subject to the following conditions:
+##
+##  The above copyright notice and this permission notice shall be included in
+##  all copies or substantial portions of the Software.
+##
+##  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+##  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+##  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+##  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+##  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+##  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+##  DEALINGS IN THE SOFTWARE.
+##
+import getopt, os, re, subprocess, sys, tempfile
+
+# These are the type names to test for suitability.  If your compiler
+# does not support "long long", e.g., it is strict ANSI C90, then you
+# should remove "long long" from this list.
+try_types = [ "unsigned %s" % s for s in
+              ("char", "short", "int", "long", "long long") ]
+
+def main(args):
+    """Scan the Makefile to find appropriate compiler settings, and then
+    compile a test program to emit the sizes of the various types that are
+    considered candidates.  The -L (--nolonglong) command line option disables
+    the use of the"long long" type, which is not standard ANSI C90; by default,
+    "long long" is considered.
+    """
+    try:
+        opts, args = getopt.getopt(args, 'L', ('nolonglong',))
+    except getopt.GetoptError, e:
+        print >> sys.stderr, "Usage: findsizes.py [-L/--nolonglong]"
+        sys.exit(1)
+
+    for opt, arg in opts:
+        if opt in ('-L', '--nolonglong'):
+            try:
+                try_types.pop(try_types.index("unsigned long long"))
+            except ValueError: pass
+    
+    vars = get_make_info()
+    sizes = get_type_sizes(try_types, vars.get('CC', 'cc'),
+                           vars.get('CFLAGS', '').split())
+    
+    stypes = sorted(sizes.keys(), key = lambda k: sizes[k], reverse = True)
+    word_type = stypes[0]
+    for t in stypes[1:]:
+        if sizes[t] <= sizes[word_type] / 2:
+            digit_type = t
+            break
+    else:
+        print >> sys.stderr, "Unable to find a compatible digit type."
+        sys.exit(1)
+
+    print "typedef %-20s mp_word;   /* %d bytes */\n" \
+          "typedef %-20s mp_digit;  /* %d bytes */" % \
+          (word_type, sizes[word_type], digit_type, sizes[digit_type])
+
+def get_type_sizes(types, cc, cflags = ()):
+    """Return a dictionary mapping the names of the specified types to
+    their sizes in bytes, based on the output of the C compiler whose
+    path and arguments are given.
+    """
+    fd, tpath = tempfile.mkstemp(suffix = '.c')
+    fp = os.fdopen(fd, 'r+')
+    fp.seek(0)
+    
+    fp.write("#include <stdio.h>\n\nint main(void)\n{\n")
+    for t in types:
+        fp.write('  printf("%%lu\\t%%s\\n", (unsigned long) sizeof(%s), '
+                 '\"%s\");\n' % (t, t))
+    fp.write('\n  return 0;\n}\n')
+    fp.close()
+
+    print >> sys.stderr, \
+          "Compiler:  %s\n" \
+          "Flags:     %s\n" \
+          "Source:    %s\n" % (cc, ' '.join(cflags), tpath)
+    
+    cmd = [cc] + list(cflags) + [tpath]
+    if subprocess.call(cmd) <> 0:
+        raise ValueError("Error while running '%s'" % ' '.join(cmd))
+
+    os.unlink(tpath)
+    if not os.path.isfile('a.out'):
+        raise ValueError("No executable a.out found")
+
+    result = subprocess.Popen(['./a.out'],
+                              stdout = subprocess.PIPE).communicate()[0]
+
+    out = {}
+    for line in result.split('\n'):
+        if line.strip() == '':
+            continue
+        size, type = re.split(r'\s+', line, 1)
+        out[type] = int(size)
+    
+    os.unlink("a.out")
+    return out
+
+def sub_make_vars(input, vars):
+    """Perform Make style variable substitution in the given input
+    string, using vars as a dictionary of variables to substitute.
+    """
+    def frep(m):
+        try:
+            return vars[m.group(1).strip()]
+        except KeyError:
+            return ' '
+    
+    expr = re.compile(r'\$\((\s*\w+\s*)\)')
+    out = input
+    while True:
+        next = expr.sub(frep, out)
+        if next == out:
+            break
+        out = next
+    
+    return out
+
+def get_make_info(target = None, makefile = None, makepath = "make",
+                  defs = ()):
+    """Extract a listing of all of the variables defined by Make.
+    Returns a dictionary mapping variable names to their string
+    values.
+
+    Optional arguments:
+    target   -- the name of the target to request that Make build.
+    makefile -- the path to the Makefile.
+    makepath -- the path to the make executable.
+    defs     -- a sequence of strings, additional make arguments.
+    """
+    cmd = [makepath]
+    if defs:
+        cmd.extend(defs)
+    cmd.extend(("-p", "-n"))
+    if makefile is not None:
+        cmd.extend(["-f", makefile])
+    if target is not None:
+        cmd.append(target)
+    
+    output = subprocess.Popen(cmd,
+                              stdout = subprocess.PIPE,
+                              stderr = subprocess.PIPE).communicate()[0]
+    vrule = re.compile(r'^(\w+)\s*=\s*(.*)$')
+    
+    vars = {}
+    for line in output.split('\n'):
+        m = vrule.match(line)
+        if m:
+            vars[m.group(1)] = m.group(2)
+
+    for key, val in vars.iteritems():
+        vars[key] = sub_make_vars(val, vars)
+    
+    return vars
+
+if __name__ == "__main__":
+    main(sys.argv[1:])
+
+# Here there be dragons

Propchange: polly/trunk/lib/External/isl/imath/findsizes.py
------------------------------------------------------------------------------
    svn:executable = *

Added: polly/trunk/lib/External/isl/imath/findthreshold.py
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/findthreshold.py?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/findthreshold.py (added)
+++ polly/trunk/lib/External/isl/imath/findthreshold.py Wed Feb  4 14:55:43 2015
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+##
+## Name:     findthreshold.py
+## Purpose:  Find a good threshold for recursive multiplication.
+## Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+## Info:     $Id: findthreshold.py 456 2006-08-16 14:24:06Z sting $
+##
+## This tool computes some timing statistics to help you select a suitable
+## recursive multiplication breakpoint.  It uses the imtimer tool to run a
+## series of tests varying precision and breakpoint, and prints out a summary
+## of the "best" values for each category.  Each summary line contains the
+## following fields, tab-separated:
+##
+## prec     -- the precision of the operands (in digits).
+## thresh   -- the threshold for recursive multiplication (digits).
+## trec     -- total time using recursive algorithm (sec).
+## tnorm    -- total time without recursive algorithm (sec).
+## ratio    -- speedup (ratio of tnorm/trec).
+##
+## You are responsible for reading and interpreting the resulting table to
+## obtain a useful value for your workload.  Change the value of MP_MULT_THRESH
+## in imath.h once you have a satisfactory result.
+##
+import math, os, random, sys, time
+
+def get_timing_stats(num_tests, precision, threshold, seed = None):
+    """Obtain timing statistics for multiplication.
+
+    num_tests      -- number of tests to run.
+    precision      -- number of digits per operand.
+    threshold      -- threshold in digits for recursive multiply.
+    seed           -- random seed; if None, the clock is used.
+
+    Returns a tuple of (seed, bits, time) where seed is the random seed used,
+    bits is the number of bits per operand, and time is a float giving the
+    total time taken for the test run.
+    """
+    if seed is None:
+        seed = int(time.time())
+    
+    line = os.popen('./imtimer -mn -p %d -t %d -s %d %d' %
+                    (precision, threshold, seed, num_tests), 'r').readline()
+    
+    count, prec, bits, thresh, status = line.strip().split('\t')
+    kind, total, unit = status.split()
+
+    return seed, int(bits), float(total)
+
+def check_binary(name):
+    if not os.path.exists(name):
+        os.system('make %s' % name)
+        if not os.path.exists(name):
+            raise ValueError("Unable to build %s" % name)
+    elif not os.path.isfile(name):
+        raise ValueError("Path exists with wrong type")
+
+def compute_stats():
+    check_binary('imtimer')
+    seed = int(time.time())
+
+    print >> sys.stderr, "Computing timer statistics (this may take a while)"
+    stats = {}
+    for prec in (32, 40, 64, 80, 128, 150, 256, 384, 512, 600, 768, 1024):
+        sys.stderr.write('%-4d ' % prec)
+        stats[prec] = (None, 1000000., 0.)
+    
+        for thresh in xrange(16, 65, 2):
+            s, b, t = get_timing_stats(1000, prec, thresh, seed)
+            sp, bp, tp = get_timing_stats(1000, prec, prec + 1, seed)
+            
+            if t < stats[prec][1]:
+                stats[prec] = (thresh, t, tp)
+                sys.stderr.write('+')
+            else:
+                sys.stderr.write('.')
+        sys.stderr.write('\n')
+
+    return list((p, h, t, tp) for p, (h, t, tp) in stats.iteritems())
+
+if __name__ == "__main__":
+    stats = compute_stats()
+    stats.sort(key = lambda s: s[3]/s[2])
+    for prec, thresh, trec, tnorm in stats:
+        print "%d\t%d\t%.3f\t%.3f\t%.4f" % (prec, thresh, trec, tnorm,
+                                            tnorm / trec)
+
+    print
+
+# Here there be dragons

Propchange: polly/trunk/lib/External/isl/imath/findthreshold.py
------------------------------------------------------------------------------
    svn:executable = *

Added: polly/trunk/lib/External/isl/imath/gmp_compat.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/gmp_compat.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/gmp_compat.c (added)
+++ polly/trunk/lib/External/isl/imath/gmp_compat.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,861 @@
+/*
+  Name:     gmp_compat.c
+  Purpose:  Provide GMP compatiable routines for imath library
+  Author:   David Peixotto
+
+  Copyright (c) 2012 Qualcomm Innovation Center, Inc. All rights reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+#include "gmp_compat.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <ctype.h>
+#include <string.h>
+
+#ifdef  NDEBUG
+#define CHECK(res) (res)
+#else
+#define CHECK(res) assert(((res) == MP_OK) && "expected MP_OK")
+#endif
+
+/*************************************************************************
+ *
+ * Functions with direct translations
+ *
+ *************************************************************************/
+/* gmp: mpq_clear */
+void GMPQAPI(clear)(mp_rat x) {
+  mp_rat_clear(x);
+}
+
+/* gmp: mpq_cmp */
+int GMPQAPI(cmp)(mp_rat op1, mp_rat op2) {
+  return mp_rat_compare(op1, op2);
+}
+
+/* gmp: mpq_init */
+void GMPQAPI(init)(mp_rat x) {
+  CHECK(mp_rat_init(x));
+}
+
+/* gmp: mpq_mul */
+void GMPQAPI(mul)(mp_rat product, mp_rat multiplier, mp_rat multiplicand) {
+  CHECK(mp_rat_mul(multiplier, multiplicand, product));
+}
+
+/* gmp: mpq_set*/
+void GMPQAPI(set)(mp_rat rop, mp_rat op) {
+  CHECK(mp_rat_copy(op, rop));
+}
+
+/* gmp: mpz_abs */
+void GMPZAPI(abs)(mp_int rop, mp_int op) {
+  CHECK(mp_int_abs(op, rop));
+}
+
+/* gmp: mpz_add */
+void GMPZAPI(add)(mp_int rop, mp_int op1, mp_int op2) {
+  CHECK(mp_int_add(op1, op2, rop));
+}
+
+/* gmp: mpz_clear */
+void GMPZAPI(clear)(mp_int x) {
+  mp_int_clear(x);
+}
+
+/* gmp: mpz_cmp_si */
+int GMPZAPI(cmp_si)(mp_int op1, long op2) {
+  return mp_int_compare_value(op1, op2);
+}
+
+/* gmp: mpz_cmpabs */
+int GMPZAPI(cmpabs)(mp_int op1, mp_int op2) {
+  return mp_int_compare_unsigned(op1, op2);
+}
+
+/* gmp: mpz_cmp */
+int GMPZAPI(cmp)(mp_int op1, mp_int op2) {
+  return mp_int_compare(op1, op2);
+}
+
+/* gmp: mpz_init */
+void GMPZAPI(init)(mp_int x) {
+  CHECK(mp_int_init(x));
+}
+
+/* gmp: mpz_mul */
+void GMPZAPI(mul)(mp_int rop, mp_int op1, mp_int op2) {
+  CHECK(mp_int_mul(op1, op2, rop));
+}
+
+/* gmp: mpz_neg */
+void GMPZAPI(neg)(mp_int rop, mp_int op) {
+  CHECK(mp_int_neg(op, rop));
+}
+
+/* gmp: mpz_set_si */
+void GMPZAPI(set_si)(mp_int rop, long op) {
+  CHECK(mp_int_set_value(rop, op));
+}
+
+/* gmp: mpz_set */
+void GMPZAPI(set)(mp_int rop, mp_int op) {
+  CHECK(mp_int_copy(op, rop));
+}
+
+/* gmp: mpz_sub */
+void GMPZAPI(sub)(mp_int rop, mp_int op1, mp_int op2) {
+  CHECK(mp_int_sub(op1, op2, rop));
+}
+
+/* gmp: mpz_swap */
+void GMPZAPI(swap)(mp_int rop1, mp_int rop2) {
+  mp_int_swap(rop1, rop2);
+}
+
+/* gmp: mpq_sgn */
+int GMPQAPI(sgn)(mp_rat op) {
+  return mp_rat_compare_zero(op);
+}
+
+/* gmp: mpz_sgn */
+int GMPZAPI(sgn)(mp_int op) {
+  return mp_int_compare_zero(op);
+}
+
+/* gmp: mpq_set_ui */
+void GMPQAPI(set_ui)(mp_rat rop, unsigned long op1, unsigned long op2) {
+  CHECK(mp_rat_set_uvalue(rop, op1, op2));
+}
+
+/* gmp: mpz_set_ui */
+void GMPZAPI(set_ui)(mp_int rop, unsigned long op) {
+  CHECK(mp_int_set_uvalue(rop, op));
+}
+
+/* gmp: mpq_den_ref */
+mp_int GMPQAPI(denref)(mp_rat op) {
+  return mp_rat_denom_ref(op);
+}
+
+/* gmp: mpq_num_ref */
+mp_int GMPQAPI(numref)(mp_rat op) {
+  return mp_rat_numer_ref(op);
+}
+
+/* gmp: mpq_canonicalize */
+void GMPQAPI(canonicalize)(mp_rat op) {
+  CHECK(mp_rat_reduce(op));
+}
+
+/*************************************************************************
+ *
+ * Functions that can be implemented as a combination of imath functions
+ *
+ *************************************************************************/
+/* gmp: mpz_addmul */
+/* gmp: rop = rop + (op1 * op2) */
+void GMPZAPI(addmul)(mp_int rop, mp_int op1, mp_int op2) {
+  mpz_t tempz;
+  mp_int temp = &tempz;
+  mp_int_init(temp);
+
+  CHECK(mp_int_mul(op1, op2, temp));
+  CHECK(mp_int_add(rop, temp, rop));
+  mp_int_clear(temp);
+}
+
+/* gmp: mpz_divexact */
+/* gmp: only produces correct results when d divides n */
+void GMPZAPI(divexact)(mp_int q, mp_int n, mp_int d) {
+  CHECK(mp_int_div(n, d, q, NULL));
+}
+
+/* gmp: mpz_divisible_p */
+/* gmp: return 1 if d divides n, 0 otherwise */
+/* gmp: 0 is considered to divide 0*/
+int GMPZAPI(divisible_p)(mp_int n, mp_int d) {
+  /* variables to hold remainder */
+  mpz_t rz;
+  mp_int r = &rz;
+  int r_is_zero;
+
+  /* check for n = 0, d = 0 */
+  int n_is_zero = mp_int_compare_zero(n) == 0;
+  int d_is_zero = mp_int_compare_zero(d) == 0;
+  if (n_is_zero && d_is_zero)
+    return 1;
+
+  /* return true if remainder is 0 */
+  CHECK(mp_int_init(r));
+  CHECK(mp_int_div(n, d, NULL, r));
+  r_is_zero = mp_int_compare_zero(r) == 0;
+  mp_int_clear(r);
+
+  return r_is_zero;
+}
+
+/* gmp: mpz_submul */
+/* gmp: rop = rop - (op1 * op2) */
+void GMPZAPI(submul)(mp_int rop, mp_int op1, mp_int op2) {
+  mpz_t tempz;
+  mp_int temp = &tempz;
+  mp_int_init(temp);
+
+  CHECK(mp_int_mul(op1, op2, temp));
+  CHECK(mp_int_sub(rop, temp, rop));
+
+  mp_int_clear(temp);
+}
+
+/* gmp: mpz_add_ui */
+void GMPZAPI(add_ui)(mp_int rop, mp_int op1, unsigned long op2) {
+  mpz_t tempz;
+  mp_int temp = &tempz;
+  CHECK(mp_int_init_uvalue(temp, op2));
+
+  CHECK(mp_int_add(op1, temp, rop));
+
+  mp_int_clear(temp);
+}
+
+/* gmp: mpz_divexact_ui */
+/* gmp: only produces correct results when d divides n */
+void GMPZAPI(divexact_ui)(mp_int q, mp_int n, unsigned long d) {
+  mpz_t tempz;
+  mp_int temp = &tempz;
+  CHECK(mp_int_init_uvalue(temp, d));
+
+  CHECK(mp_int_div(n, temp, q, NULL));
+
+  mp_int_clear(temp);
+}
+
+/* gmp: mpz_mul_ui */
+void GMPZAPI(mul_ui)(mp_int rop, mp_int op1, unsigned long op2) {
+  mpz_t tempz;
+  mp_int temp = &tempz;
+  CHECK(mp_int_init_uvalue(temp, op2));
+
+  CHECK(mp_int_mul(op1, temp, rop));
+
+  mp_int_clear(temp);
+}
+
+/* gmp: mpz_pow_ui */
+/* gmp: 0^0 = 1 */
+void GMPZAPI(pow_ui)(mp_int rop, mp_int base, unsigned long exp) {
+  mpz_t tempz;
+  mp_int temp = &tempz;
+
+  /* check for 0^0 */
+  if (exp == 0 && mp_int_compare_zero(base) == 0) {
+    CHECK(mp_int_set_value(rop, 1));
+    return;
+  }
+
+  /* rop = base^exp */
+  CHECK(mp_int_init_uvalue(temp, exp));
+  CHECK(mp_int_expt_full(base, temp, rop));
+  mp_int_clear(temp);
+}
+
+/* gmp: mpz_sub_ui */
+void GMPZAPI(sub_ui)(mp_int rop, mp_int op1, unsigned long op2) {
+  mpz_t tempz;
+  mp_int temp = &tempz;
+  CHECK(mp_int_init_uvalue(temp, op2));
+
+  CHECK(mp_int_sub(op1, temp, rop));
+
+  mp_int_clear(temp);
+}
+
+/*************************************************************************
+ *
+ * Functions with different behavior in corner cases
+ *
+ *************************************************************************/
+
+/* gmp: mpz_gcd */
+void GMPZAPI(gcd)(mp_int rop, mp_int op1, mp_int op2) {
+  int op1_is_zero = mp_int_compare_zero(op1) == 0;
+  int op2_is_zero = mp_int_compare_zero(op2) == 0;
+
+  if (op1_is_zero && op2_is_zero) {
+    mp_int_zero(rop);
+    return;
+  }
+
+  CHECK(mp_int_gcd(op1, op2, rop));
+}
+
+/* gmp: mpz_get_str */
+char* GMPZAPI(get_str)(char *str, int radix, mp_int op) {
+  int i, r, len;
+
+  /* Support negative radix like gmp */
+  r = radix;
+  if (r < 0)
+    r = -r;
+
+  /* Compute the length of the string needed to hold the int */
+  len = mp_int_string_len(op, r);
+  if (str == NULL) {
+    str = malloc(len);
+  }
+
+  /* Convert to string using imath function */
+  CHECK(mp_int_to_string(op, r, str, len));
+
+  /* Change case to match gmp */
+  for (i = 0; i < len; i++)
+    if (radix < 0)
+      str[i] = toupper(str[i]);
+    else
+      str[i] = tolower(str[i]);
+  return str;
+}
+
+/* gmp: mpq_get_str */
+char* GMPQAPI(get_str)(char *str, int radix, mp_rat op) {
+  int i, r, len;
+
+  /* Only print numerator if it is a whole number */
+  if (mp_int_compare_value(mp_rat_denom_ref(op), 1) == 0)
+    return GMPZAPI(get_str)(str, radix, mp_rat_numer_ref(op));
+
+  /* Support negative radix like gmp */
+  r = radix;
+  if (r < 0)
+    r = -r;
+
+  /* Compute the length of the string needed to hold the int */
+  len = mp_rat_string_len(op, r);
+  if (str == NULL) {
+    str = malloc(len);
+  }
+
+  /* Convert to string using imath function */
+  CHECK(mp_rat_to_string(op, r, str, len));
+
+  /* Change case to match gmp */
+  for (i = 0; i < len; i++)
+    if (radix < 0)
+      str[i] = toupper(str[i]);
+    else
+      str[i] = tolower(str[i]);
+
+  return str;
+}
+
+/* gmp: mpz_set_str */
+int GMPZAPI(set_str)(mp_int rop, char *str, int base) {
+  mp_result res = mp_int_read_string(rop, base, str);
+  return ((res == MP_OK) ? 0 : -1);
+}
+
+/* gmp: mpq_set_str */
+int GMPQAPI(set_str)(mp_rat rop, char *s, int base) {
+  char *slash;
+  char *str;
+  mp_result resN;
+  mp_result resD;
+  int res = 0;
+
+  /* Copy string to temporary storage so we can modify it below */
+  str = malloc(strlen(s)+1);
+  strcpy(str, s);
+
+  /* Properly format the string as an int by terminating at the / */
+  slash = strchr(str, '/');
+  if (slash)
+    *slash = '\0';
+
+  /* Parse numerator */
+  resN = mp_int_read_string(mp_rat_numer_ref(rop), base, str);
+
+  /* Parse denomenator if given or set to 1 if not */
+  if (slash)
+    resD = mp_int_read_string(mp_rat_denom_ref(rop), base, slash+1);
+  else
+    resD = mp_int_set_uvalue(mp_rat_denom_ref(rop), 1);
+
+  /* Return failure if either parse failed */
+  if (resN != MP_OK || resD != MP_OK)
+    res = -1;
+
+  free(str);
+  return res;
+}
+
+static unsigned long get_long_bits(mp_int op) {
+  /* Deal with integer that does not fit into unsigned long. We want to grab
+   * the least significant digits that will fit into the long.  Read the digits
+   * into the long starting at the most significant digit that fits into a
+   * long. The long is shifted over by MP_DIGIT_BIT before each digit is added.
+   * The shift is decomposed into two steps to follow the patten used in the
+   * rest of the imath library. The two step shift is used to accomedate
+   * architectures that don't deal well with 32-bit shifts. */
+  mp_size num_digits_in_long = sizeof(unsigned long) / sizeof(mp_digit);
+  mp_digit *digits = MP_DIGITS(op);
+  unsigned long out = 0;
+  int i;
+
+  for (i = num_digits_in_long - 1; i >= 0; i--) {
+    out <<= (MP_DIGIT_BIT/2);
+    out <<= (MP_DIGIT_BIT/2);
+    out  |= digits[i];
+  }
+
+  return out;
+}
+
+/* gmp: mpz_get_ui */
+unsigned long GMPZAPI(get_ui)(mp_int op) {
+  unsigned long out;
+
+  /* Try a standard conversion that fits into an unsigned long */
+  mp_result res = mp_int_to_uint(op, &out);
+  if (res == MP_OK)
+    return out;
+
+  /* Abort the try if we don't have a range error in the conversion.
+   * The range error indicates that the value cannot fit into a long. */
+  CHECK(res == MP_RANGE ? MP_OK : MP_RANGE);
+  if (res != MP_RANGE)
+    return 0;
+
+  return get_long_bits(op);
+}
+
+/* gmp: mpz_get_si */
+long GMPZAPI(get_si)(mp_int op) {
+  long out;
+  unsigned long uout;
+  int long_msb;
+
+  /* Try a standard conversion that fits into a long */
+  mp_result res = mp_int_to_int(op, &out);
+  if (res == MP_OK)
+    return out;
+
+  /* Abort the try if we don't have a range error in the conversion.
+   * The range error indicates that the value cannot fit into a long. */
+  CHECK(res == MP_RANGE ? MP_OK : MP_RANGE);
+  if (res != MP_RANGE)
+    return 0;
+
+  /* get least significant bits into an unsigned long */
+  uout = get_long_bits(op);
+
+  /* clear the top bit */
+  long_msb = (sizeof(unsigned long) * 8) - 1;
+  uout &= (~(1UL << long_msb));
+
+  /* convert to negative if needed based on sign of op */
+  if (MP_SIGN(op) == MP_NEG)
+    uout = 0 - uout;
+
+  out = (long) uout;
+  return out;
+}
+
+/* gmp: mpz_lcm */
+void GMPZAPI(lcm)(mp_int rop, mp_int op1, mp_int op2) {
+  int op1_is_zero = mp_int_compare_zero(op1) == 0;
+  int op2_is_zero = mp_int_compare_zero(op2) == 0;
+
+  if (op1_is_zero || op2_is_zero) {
+    mp_int_zero(rop);
+    return;
+  }
+
+  CHECK(mp_int_lcm(op1, op2, rop));
+  CHECK(mp_int_abs(rop, rop));
+}
+
+/* gmp: mpz_mul_2exp */
+/* gmp: allow big values for op2 when op1 == 0 */
+void GMPZAPI(mul_2exp)(mp_int rop, mp_int op1, unsigned long op2) {
+  if (mp_int_compare_zero(op1) == 0)
+    mp_int_zero(rop);
+  else
+    CHECK(mp_int_mul_pow2(op1, op2, rop));
+}
+
+/*************************************************************************
+ *
+ * Functions needing expanded functionality
+ *
+ *************************************************************************/
+/* [Note]Overview of division implementation
+
+    All division operations (N / D) compute q and r such that
+
+      N = q * D + r, with 0 <= abs(r) < abs(d)
+
+    The q and r values are not uniquely specified by N and D. To specify which q
+    and r values should be used, GMP implements three different rounding modes
+    for integer division:
+
+      ceiling  - round q twords +infinity, r has opposite sign as d
+      floor    - round q twords -infinity, r has same sign as d
+      truncate - round q twords zero,      r has same sign as n
+
+    The imath library only supports truncate as a rounding mode. We need to
+    implement the other rounding modes in terms of truncating division. We first
+    perform the division in trucate mode and then adjust q accordingly. Once we
+    know q, we can easily compute the correct r according the the formula above
+    by computing:
+
+      r = N - q * D
+
+    The main task is to compute q. We can compute the correct q from a trucated
+    version as follows.
+
+    For ceiling rounding mode, if q is less than 0 then the truncated rounding
+    mode is the same as the ceiling rounding mode.  If q is greater than zero
+    then we need to round q up by one because the truncated version was rounded
+    down to zero. If q equals zero then check to see if the result of the
+    divison is positive. A positive result needs to increment q to one.
+
+    For floor rounding mode, if q is greater than 0 then the trucated rounding
+    mode is the same as the floor rounding mode. If q is less than zero then we
+    need to round q down by one because the trucated mode rounded q up by one
+    twords zero. If q is zero then we need to check to see if the result of the
+    division is negative. A negative result needs to decrement q to negative
+    one.
+ */
+
+/* gmp: mpz_cdiv_q */
+void GMPZAPI(cdiv_q)(mp_int q, mp_int n, mp_int d) {
+  mpz_t rz;
+  mp_int r = &rz;
+  int qsign, rsign, nsign, dsign;
+  CHECK(mp_int_init(r));
+
+  /* save signs before division because q can alias with n or d */
+  nsign = mp_int_compare_zero(n);
+  dsign = mp_int_compare_zero(d);
+
+  /* truncating division */
+  CHECK(mp_int_div(n, d, q, r));
+
+  /* see: [Note]Overview of division implementation */
+  qsign = mp_int_compare_zero(q);
+  rsign = mp_int_compare_zero(r);
+  if (qsign > 0) {    /* q > 0 */
+    if (rsign != 0) { /* r != 0 */
+      CHECK(mp_int_add_value(q, 1, q));
+    }
+  }
+  else if (qsign == 0) { /* q == 0 */
+    if (rsign != 0) {    /* r != 0 */
+      if ((nsign > 0 && dsign > 0) || (nsign < 0 && dsign < 0)) {
+        CHECK(mp_int_set_value(q, 1));
+      }
+    }
+  }
+  mp_int_clear(r);
+}
+
+/* gmp: mpz_fdiv_q */
+void GMPZAPI(fdiv_q)(mp_int q, mp_int n, mp_int d) {
+  mpz_t rz;
+  mp_int r = &rz;
+  int qsign, rsign, nsign, dsign;
+  CHECK(mp_int_init(r));
+
+  /* save signs before division because q can alias with n or d */
+  nsign = mp_int_compare_zero(n);
+  dsign = mp_int_compare_zero(d);
+
+  /* truncating division */
+  CHECK(mp_int_div(n, d, q, r));
+
+  /* see: [Note]Overview of division implementation */
+  qsign = mp_int_compare_zero(q);
+  rsign = mp_int_compare_zero(r);
+  if (qsign < 0) {    /* q  < 0 */
+    if (rsign != 0) { /* r != 0 */
+      CHECK(mp_int_sub_value(q, 1, q));
+    }
+  }
+  else if (qsign == 0) { /* q == 0 */
+    if (rsign != 0) {    /* r != 0 */
+      if ((nsign < 0 && dsign > 0) || (nsign > 0 && dsign < 0)) {
+        CHECK(mp_int_set_value(q, -1));
+      }
+    }
+  }
+  mp_int_clear(r);
+}
+
+/* gmp: mpz_fdiv_r */
+void GMPZAPI(fdiv_r)(mp_int r, mp_int n, mp_int d) {
+  mpz_t qz;
+  mpz_t tempz;
+  mpz_t orig_dz;
+  mpz_t orig_nz;
+  mp_int q = &qz;
+  mp_int temp = &tempz;
+  mp_int orig_d = &orig_dz;
+  mp_int orig_n = &orig_nz;
+  CHECK(mp_int_init(q));
+  CHECK(mp_int_init(temp));
+  /* Make a copy of n in case n and d in case they overlap with q */
+  CHECK(mp_int_init_copy(orig_d, d));
+  CHECK(mp_int_init_copy(orig_n, n));
+
+  /* floor division */
+  GMPZAPI(fdiv_q)(q, n, d);
+
+  /* see: [Note]Overview of division implementation */
+  /* n = q * d + r  ==>  r = n - q * d */
+  mp_int_mul(q, orig_d, temp);
+  mp_int_sub(orig_n, temp, r);
+
+  mp_int_clear(q);
+  mp_int_clear(temp);
+  mp_int_clear(orig_d);
+  mp_int_clear(orig_n);
+}
+
+/* gmp: mpz_tdiv_q */
+void GMPZAPI(tdiv_q)(mp_int q, mp_int n, mp_int d) {
+  /* truncating division*/
+  CHECK(mp_int_div(n, d, q, NULL));
+}
+
+/* gmp: mpz_fdiv_q_ui */
+unsigned long GMPZAPI(fdiv_q_ui)(mp_int q, mp_int n, unsigned long d) {
+  mpz_t tempz;
+  mp_int temp = &tempz;
+  mpz_t rz;
+  mp_int r = &rz;
+  mpz_t orig_nz;
+  mp_int orig_n = &orig_nz;
+  unsigned long rl;
+  CHECK(mp_int_init_uvalue(temp, d));
+  CHECK(mp_int_init(r));
+  /* Make a copy of n in case n and q overlap */
+  CHECK(mp_int_init_copy(orig_n, n));
+
+  /* use floor division mode to compute q and r */
+  GMPZAPI(fdiv_q)(q, n, temp);
+  GMPZAPI(fdiv_r)(r, orig_n, temp);
+  CHECK(mp_int_to_uint(r, &rl));
+
+  mp_int_clear(temp);
+  mp_int_clear(r);
+  mp_int_clear(orig_n);
+
+  return rl;
+}
+
+/* gmp: mpz_export */
+void* GMPZAPI(export)(void *rop, size_t *countp, int order, size_t size, int endian, size_t nails, mp_int op) {
+  int i;
+  int num_used_bytes;
+  size_t num_words, num_missing_bytes;
+  unsigned char* dst;
+  unsigned char* src;
+
+  /* We do not have a complete implementation. Assert to ensure our
+   * restrictions are in place, We do not support big endian output, but do not
+   * check that native endian is little endian. */
+  assert(nails  == 0 && "Do not support non-full words");
+  assert((endian == 0 || endian == -1) && "Do not support big endian");
+
+  /* The gmp API requires that order must be -1 or 1.
+     Not sure how gmp behaves when order is not 1 or -1, so force all non-one
+     values to -1 for now. */
+  if (order != 1) order = -1;
+
+  /* Test for zero */
+  if (mp_int_compare_zero(op) == 0) {
+    if (countp)
+      *countp = 0;
+    return rop;
+  }
+
+  /* Calculate how many words we need */
+  num_used_bytes  = mp_int_unsigned_len(op);
+  num_words       = (num_used_bytes + (size-1)) / size; /* ceil division */
+  assert(num_used_bytes > 0);
+
+  /* Check to see if we will have missing bytes in the last word.
+
+     Missing bytes can only occur when the size of words we output is
+     greater than the size of words used internally by imath. The number of
+     missing bytes is the number of bytes needed to fill out the last word. If
+     this number is greater than the size of a single mp_digit, then we need to
+     pad the word with extra zeros. Otherwise, the missing bytes can be filled
+     directly from the zeros in the last digit in the number.
+   */
+  num_missing_bytes   = (size * num_words) - num_used_bytes;
+  assert(num_missing_bytes < size);
+
+  /* Allocate space for the result if needed */
+  if (rop == NULL) {
+    rop = malloc(num_words * size);
+  }
+
+  /* Initialize dst and src pointers */
+  dst = (unsigned char *)rop;
+  src = (unsigned char *)MP_DIGITS(op);
+
+  /* Most significant word first */
+  if (order == 1) {
+    size_t words_written = 0;
+    src += (num_words-1) * size;
+
+    /* Handle write of first word specially */
+    for (i = 0; i < size - num_missing_bytes; i++)
+      dst[i] = src[i];
+    for (; i < size; i++)
+      dst[i] = 0;
+    dst += size;
+    src -= size;
+    words_written++;
+
+    for (; words_written < num_words; words_written++) {
+      for (i = 0; i < size; i++)
+        dst[i] = src[i];
+      dst += size;
+      src -= size;
+    }
+  }
+  /* Least significant word first */
+  else {
+    size_t words_written = 0;
+    for (; words_written < num_words - 1; words_written++) {
+      for (i = 0; i < size; i++)
+        dst[i] = src[i];
+      dst += size;
+      src += size;
+    }
+
+    /* Handle write of last word specially */
+    for (i = 0; i < size - num_missing_bytes; i++)
+      dst[i] = src[i];
+
+    for (; i < size; i++)
+      dst[i] = 0;
+  }
+
+  if (countp)
+    *countp = num_words;
+  return rop;
+}
+
+/* gmp: mpz_import */
+void GMPZAPI(import)(mp_int rop, size_t count, int order, size_t size, int endian, size_t nails, const void* op) {
+  mpz_t tmpz;
+  mp_int tmp = &tmpz;
+  size_t total_size;
+  size_t num_digits;
+  const char *src;
+  char *dst;
+  int i;
+  if (count == 0 || op == NULL)
+    return;
+
+  /* We do not have a complete implementation. Assert to ensure our
+   * restrictions are in place, We do not support big endian output, but do not
+   * check that native endian is little endian. */
+  assert(nails  == 0 && "Do not support non-full words");
+  assert((endian == 0 || endian == -1) && "Do not support big endian");
+
+  /* Compute number of needed digits by ceil division */
+  total_size = count * size;
+  num_digits = (total_size + sizeof(mp_digit) - 1) / sizeof(mp_digit);
+
+  /* Init temporary */
+  mp_int_init_size(tmp, num_digits);
+  for (i = 0; i < num_digits; i++)
+    tmp->digits[i] = 0;
+
+  /* Copy bytes */
+  src = (const char *) op;
+  dst = (char *)MP_DIGITS(tmp);
+
+  /* Most significant word is first */
+  if (order == 1) {
+    size_t word;
+    dst += (count - 1) * size;
+    for (word = 0; word < count; word++) {
+      for (i = 0; i < size; i++)
+        dst[i] = src[i];
+      dst -= size;
+      src += size;
+    }
+  }
+  /* Least significant word is first */
+  else {
+    size_t word;
+    for (word = 0; word < count; word++) {
+      for (i = 0; i < size; i++)
+        dst[i] = src[i];
+      dst += size;
+      src += size;
+    }
+  }
+  MP_USED(tmp) = num_digits;
+
+  /* Remove leading zeros from number */
+  {
+    mp_size uz_   = MP_USED(tmp);
+    mp_digit *dz_ = MP_DIGITS(tmp) + uz_ -1;
+    while (uz_ > 1 && (*dz_-- == 0))
+      --uz_;
+    MP_USED(tmp) = uz_;
+  }
+
+  /* Copy to destination */
+  mp_int_copy(tmp, rop);
+}
+
+/* gmp: mpz_sizeinbase */
+size_t GMPZAPI(sizeinbase)(mp_int op, int base) {
+  mp_result res;
+  size_t size;
+
+  /* If op == 0, return 1 */
+  if (mp_int_compare_zero(op) == 0)
+    return 1;
+
+  /* Compute string length in base */
+  res = mp_int_string_len(op, base);
+  CHECK((res > 0) == MP_OK);
+
+  /* Now adjust the final size by getting rid of string artifacts */
+  size = res;
+
+  /* subtract one for the null terminator */
+  size -= 1;
+
+  /* subtract one for the negative sign */
+  if (mp_int_compare_zero(op) < 0)
+    size -= 1;
+
+  return size;
+}

Added: polly/trunk/lib/External/isl/imath/gmp_compat.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/gmp_compat.h?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/gmp_compat.h (added)
+++ polly/trunk/lib/External/isl/imath/gmp_compat.h Wed Feb  4 14:55:43 2015
@@ -0,0 +1,229 @@
+/*
+  Name:     gmp_compat.h
+  Purpose:  Provide GMP compatiable routines for imath library
+  Author:   David Peixotto
+
+  Copyright (c) 2012 Qualcomm Innovation Center, Inc. All rights reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#ifndef IMATH_GMP_COMPAT_H_
+#define IMATH_GMP_COMPAT_H_
+#include "imath.h"
+#include "imrat.h"
+#include <stddef.h>
+
+#define GMPZAPI(fun) impz_ ## fun
+#define GMPQAPI(fun) impq_ ## fun
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*************************************************************************
+ *
+ * Functions with direct translations
+ *
+ *************************************************************************/
+/* gmp: mpq_clear */
+void GMPQAPI(clear)(mp_rat x);
+
+/* gmp: mpq_cmp */
+int GMPQAPI(cmp)(mp_rat op1, mp_rat op2);
+
+/* gmp: mpq_init */
+void GMPQAPI(init)(mp_rat x);
+
+/* gmp: mpq_mul */
+void GMPQAPI(mul)(mp_rat product, mp_rat multiplier, mp_rat multiplicand);
+
+/* gmp: mpq_set */
+void GMPQAPI(set)(mp_rat rop, mp_rat op);
+
+/* gmp: mpz_abs */
+void GMPZAPI(abs)(mp_int rop, mp_int op);
+
+/* gmp: mpz_add */
+void GMPZAPI(add)(mp_int rop, mp_int op1, mp_int op2);
+
+/* gmp: mpz_clear */
+void GMPZAPI(clear)(mp_int x);
+
+/* gmp: mpz_cmp_si */
+int GMPZAPI(cmp_si)(mp_int op1, long op2);
+
+/* gmp: mpz_cmpabs */
+int GMPZAPI(cmpabs)(mp_int op1, mp_int op2);
+
+/* gmp: mpz_cmp */
+int GMPZAPI(cmp)(mp_int op1, mp_int op2);
+
+/* gmp: mpz_init */
+void GMPZAPI(init)(mp_int x);
+
+/* gmp: mpz_mul */
+void GMPZAPI(mul)(mp_int rop, mp_int op1, mp_int op2);
+
+/* gmp: mpz_neg */
+void GMPZAPI(neg)(mp_int rop, mp_int op);
+
+/* gmp: mpz_set_si */
+void GMPZAPI(set_si)(mp_int rop, long op);
+
+/* gmp: mpz_set */
+void GMPZAPI(set)(mp_int rop, mp_int op);
+
+/* gmp: mpz_sub */
+void GMPZAPI(sub)(mp_int rop, mp_int op1, mp_int op2);
+
+/* gmp: mpz_swap */
+void GMPZAPI(swap)(mp_int rop1, mp_int rop2);
+
+/* gmp: mpq_sgn */
+int GMPQAPI(sgn)(mp_rat op);
+
+/* gmp: mpz_sgn */
+int GMPZAPI(sgn)(mp_int op);
+
+/* gmp: mpq_set_ui */
+void GMPQAPI(set_ui)(mp_rat rop, unsigned long op1, unsigned long op2);
+
+/* gmp: mpz_set_ui */
+void GMPZAPI(set_ui)(mp_int rop, unsigned long op);
+
+/* gmp: mpq_den_ref */
+mp_int GMPQAPI(denref)(mp_rat op);
+
+/* gmp: mpq_num_ref */
+mp_int GMPQAPI(numref)(mp_rat op);
+
+/* gmp: mpq_canonicalize */
+void GMPQAPI(canonicalize)(mp_rat op);
+
+/*************************************************************************
+ *
+ * Functions that can be implemented as a combination of imath functions
+ *
+ *************************************************************************/
+/* gmp: mpz_addmul */
+void GMPZAPI(addmul)(mp_int rop, mp_int op1, mp_int op2);
+
+/* gmp: mpz_divexact */
+void GMPZAPI(divexact)(mp_int q, mp_int n, mp_int d);
+
+/* gmp: mpz_divisible_p */
+int GMPZAPI(divisible_p)(mp_int n, mp_int d);
+
+/* gmp: mpz_submul */
+void GMPZAPI(submul)(mp_int rop, mp_int op1, mp_int op2);
+
+/* gmp: mpz_add_ui */
+void GMPZAPI(add_ui)(mp_int rop, mp_int op1, unsigned long op2);
+
+/* gmp: mpz_divexact_ui */
+void GMPZAPI(divexact_ui)(mp_int q, mp_int n, unsigned long d);
+
+/* gmp: mpz_mul_ui */
+void GMPZAPI(mul_ui)(mp_int rop, mp_int op1, unsigned long op2);
+
+/* gmp: mpz_pow_ui */
+void GMPZAPI(pow_ui)(mp_int rop, mp_int base, unsigned long exp);
+
+/* gmp: mpz_sub_ui */
+void GMPZAPI(sub_ui)(mp_int rop, mp_int op1, unsigned long op2);
+
+/* gmp: mpz_fdiv_q_ui */
+unsigned long GMPZAPI(fdiv_q_ui)(mp_int q, mp_int n, unsigned long d);
+
+/* gmp: mpz_sizeinbase */
+size_t GMPZAPI(sizeinbase)(mp_int op, int base);
+
+/*************************************************************************
+ *
+ * Functions with different behavior in corner cases
+ *
+ *************************************************************************/
+/* gmp: mpz_gcd */
+/* gmp: When op1 = 0 and op2 = 0, return 0.*/
+void GMPZAPI(gcd)(mp_int rop, mp_int op1, mp_int op2);
+
+/* gmp: mpz_get_str */
+/* gmp: If str is NULL then allocate space using the default allocator. */
+char* GMPZAPI(get_str)(char *str, int radix, mp_int op);
+
+/* gmp: mpq_get_str */
+/* gmp: If str is NULL then allocate space using the default allocator. */
+/* gmp: If value is a whole number do not print denomenator. */
+/* TODO: Need to handle 0 values better. GMP prints 0/4 instead of 0.*/
+char* GMPQAPI(get_str)(char *str, int radix, mp_rat op);
+
+/* gmp: mpz_set_str */
+/* gmp: Allow and ignore spaces in string. */
+int GMPZAPI(set_str)(mp_int rop, char *str, int base);
+
+/* gmp: mpq_set_str */
+int GMPQAPI(set_str)(mp_rat rop, char *str, int base);
+
+/* gmp: mpz_get_ui */
+/* gmp: Return least significant bits if value is too big for a long. */
+unsigned long GMPZAPI(get_ui)(mp_int op);
+
+/* gmp: mpz_get_si */
+/* gmp: Return least significant bits if value is too bit for a long. */
+/* gmp: If value is too big for long, return the least significant
+        (8*sizeof(long)-1) bits from the op and set the sign bit according to
+        the sign of the op. */
+long GMPZAPI(get_si)(mp_int op);
+
+/* gmp: mpz_lcm */
+/* gmp: When op1 = 0 or op2 = 0, return 0.*/
+/* gmp: The resutl of lcm(a,b) is always positive. */
+void GMPZAPI(lcm)(mp_int rop, mp_int op1, mp_int op2);
+
+/* gmp: mpz_mul_2exp */
+/* gmp: allow big values for op2 when op1 == 0 */
+void GMPZAPI(mul_2exp)(mp_int rop, mp_int op1, unsigned long op2);
+
+/*************************************************************************
+ *
+ * Functions needing expanded functionality
+ *
+ *************************************************************************/
+/* gmp: mpz_cdiv_q */
+void GMPZAPI(cdiv_q)(mp_int q, mp_int n, mp_int d);
+
+/* gmp: mpz_fdiv_q */
+void GMPZAPI(fdiv_q)(mp_int q, mp_int n, mp_int d);
+
+/* gmp: mpz_fdiv_r */
+void GMPZAPI(fdiv_r)(mp_int r, mp_int n, mp_int d);
+
+/* gmp: mpz_tdiv_q */
+void GMPZAPI(tdiv_q)(mp_int q, mp_int n, mp_int d);
+
+/* gmp: mpz_export */
+void* GMPZAPI(export)(void *rop, size_t *countp, int order, size_t size, int endian, size_t nails, mp_int op);
+
+/* gmp: mpz_import */
+void GMPZAPI(import)(mp_int rop, size_t count, int order, size_t size, int endian, size_t nails, const void* op);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* end IMATH_GMP_COMPAT_H_ */

Added: polly/trunk/lib/External/isl/imath/imath.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/imath.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/imath.c (added)
+++ polly/trunk/lib/External/isl/imath/imath.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,3668 @@
+/*
+  Name:     imath.c
+  Purpose:  Arbitrary precision integer arithmetic routines.
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  Copyright (C) 2002-2007 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#include "imath.h"
+
+#if DEBUG
+#include <stdio.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include <assert.h>
+
+#if DEBUG
+#define STATIC /* public */
+#else
+#define STATIC static
+#endif
+
+/* {{{ Constants */
+
+const mp_result MP_OK     = 0;  /* no error, all is well  */
+const mp_result MP_FALSE  = 0;  /* boolean false          */
+const mp_result MP_TRUE   = -1; /* boolean true           */
+const mp_result MP_MEMORY = -2; /* out of memory          */
+const mp_result MP_RANGE  = -3; /* argument out of range  */
+const mp_result MP_UNDEF  = -4; /* result undefined       */
+const mp_result MP_TRUNC  = -5; /* output truncated       */
+const mp_result MP_BADARG = -6; /* invalid null argument  */
+const mp_result MP_MINERR = -6;
+
+const mp_sign   MP_NEG  = 1;    /* value is strictly negative */
+const mp_sign   MP_ZPOS = 0;    /* value is non-negative      */
+
+STATIC const char *s_unknown_err = "unknown result code";
+STATIC const char *s_error_msg[] = {
+  "error code 0",
+  "boolean true",
+  "out of memory",
+  "argument out of range",
+  "result undefined",
+  "output truncated",
+  "invalid argument",
+  NULL
+};
+
+/* }}} */
+
+/* Argument checking macros
+   Use CHECK() where a return value is required; NRCHECK() elsewhere */
+#define CHECK(TEST)   assert(TEST)
+#define NRCHECK(TEST) assert(TEST)
+
+/* {{{ Logarithm table for computing output sizes */
+
+/* The ith entry of this table gives the value of log_i(2).
+
+   An integer value n requires ceil(log_i(n)) digits to be represented
+   in base i.  Since it is easy to compute lg(n), by counting bits, we
+   can compute log_i(n) = lg(n) * log_i(2).
+
+   The use of this table eliminates a dependency upon linkage against
+   the standard math libraries.
+
+   If MP_MAX_RADIX is increased, this table should be expanded too.
+ */
+STATIC const double s_log2[] = {
+   0.000000000, 0.000000000, 1.000000000, 0.630929754, 	/* (D)(D) 2  3 */
+   0.500000000, 0.430676558, 0.386852807, 0.356207187, 	/*  4  5  6  7 */
+   0.333333333, 0.315464877, 0.301029996, 0.289064826, 	/*  8  9 10 11 */
+   0.278942946, 0.270238154, 0.262649535, 0.255958025, 	/* 12 13 14 15 */
+   0.250000000, 0.244650542, 0.239812467, 0.235408913, 	/* 16 17 18 19 */
+   0.231378213, 0.227670249, 0.224243824, 0.221064729, 	/* 20 21 22 23 */
+   0.218104292, 0.215338279, 0.212746054, 0.210309918, 	/* 24 25 26 27 */
+   0.208014598, 0.205846832, 0.203795047, 0.201849087, 	/* 28 29 30 31 */
+   0.200000000, 0.198239863, 0.196561632, 0.194959022, 	/* 32 33 34 35 */
+   0.193426404,                                         /* 36          */
+};
+
+/* }}} */
+/* {{{ Various macros */
+
+/* Return the number of digits needed to represent a static value */
+#define MP_VALUE_DIGITS(V) \
+((sizeof(V)+(sizeof(mp_digit)-1))/sizeof(mp_digit))
+
+/* Round precision P to nearest word boundary */
+#define ROUND_PREC(P) ((mp_size)(2*(((P)+1)/2)))
+
+/* Set array P of S digits to zero */
+#define ZERO(P, S) \
+do{ \
+  mp_size i__ = (S) * sizeof(mp_digit); \
+  mp_digit *p__ = (P); \
+  memset(p__, 0, i__); \
+} while(0)
+
+/* Copy S digits from array P to array Q */
+#define COPY(P, Q, S) \
+do{ \
+  mp_size i__ = (S) * sizeof(mp_digit); \
+  mp_digit *p__ = (P), *q__ = (Q); \
+  memcpy(q__, p__, i__); \
+} while(0)
+
+/* Reverse N elements of type T in array A */
+#define REV(T, A, N) \
+do{ \
+  T *u_ = (A), *v_ = u_ + (N) - 1; \
+  while (u_ < v_) { \
+    T xch = *u_; \
+    *u_++ = *v_; \
+    *v_-- = xch; \
+  } \
+} while(0)
+
+#define CLAMP(Z) \
+do{ \
+  mp_int z_ = (Z); \
+  mp_size uz_ = MP_USED(z_); \
+  mp_digit *dz_ = MP_DIGITS(z_) + uz_ -1; \
+  while (uz_ > 1 && (*dz_-- == 0)) \
+    --uz_; \
+  MP_USED(z_) = uz_; \
+} while(0)
+
+/* Select min/max.  Do not provide expressions for which multiple
+   evaluation would be problematic, e.g. x++ */
+#define MIN(A, B) ((B)<(A)?(B):(A))
+#define MAX(A, B) ((B)>(A)?(B):(A))
+
+/* Exchange lvalues A and B of type T, e.g.
+   SWAP(int, x, y) where x and y are variables of type int. */
+#define SWAP(T, A, B) \
+do{ \
+  T t_ = (A); \
+  A = (B); \
+  B = t_; \
+} while(0)
+
+/* Used to set up and access simple temp stacks within functions. */
+#define DECLARE_TEMP(N) \
+  mpz_t temp[(N)]; \
+  int last__ = 0
+#define CLEANUP_TEMP() \
+ CLEANUP: \
+  while (--last__ >= 0) \
+    mp_int_clear(TEMP(last__))
+#define TEMP(K) (temp + (K))
+#define LAST_TEMP() TEMP(last__)
+#define SETUP(E) \
+do{ \
+  if ((res = (E)) != MP_OK) \
+    goto CLEANUP; \
+  ++(last__); \
+} while(0)
+
+/* Compare value to zero. */
+#define CMPZ(Z) \
+(((Z)->used==1&&(Z)->digits[0]==0)?0:((Z)->sign==MP_NEG)?-1:1)
+
+/* Multiply X by Y into Z, ignoring signs.  Requires that Z have
+   enough storage preallocated to hold the result. */
+#define UMUL(X, Y, Z) \
+do{ \
+  mp_size ua_ = MP_USED(X), ub_ = MP_USED(Y); \
+  mp_size o_ = ua_ + ub_; \
+  ZERO(MP_DIGITS(Z), o_); \
+  (void) s_kmul(MP_DIGITS(X), MP_DIGITS(Y), MP_DIGITS(Z), ua_, ub_); \
+  MP_USED(Z) = o_; \
+  CLAMP(Z); \
+} while(0)
+
+/* Square X into Z.  Requires that Z have enough storage to hold the
+   result. */
+#define USQR(X, Z) \
+do{ \
+  mp_size ua_ = MP_USED(X), o_ = ua_ + ua_; \
+  ZERO(MP_DIGITS(Z), o_); \
+  (void) s_ksqr(MP_DIGITS(X), MP_DIGITS(Z), ua_); \
+  MP_USED(Z) = o_; \
+  CLAMP(Z); \
+} while(0)
+
+#define UPPER_HALF(W)           ((mp_word)((W) >> MP_DIGIT_BIT))
+#define LOWER_HALF(W)           ((mp_digit)(W))
+#define HIGH_BIT_SET(W)         ((W) >> (MP_WORD_BIT - 1))
+#define ADD_WILL_OVERFLOW(W, V) ((MP_WORD_MAX - (V)) < (W))
+
+/* }}} */
+/* {{{ Default configuration settings */
+
+/* Default number of digits allocated to a new mp_int */
+#if IMATH_TEST
+mp_size default_precision = MP_DEFAULT_PREC;
+#else
+STATIC const mp_size default_precision = MP_DEFAULT_PREC;
+#endif
+
+/* Minimum number of digits to invoke recursive multiply */
+#if IMATH_TEST
+mp_size multiply_threshold = MP_MULT_THRESH;
+#else
+STATIC const mp_size multiply_threshold = MP_MULT_THRESH;
+#endif
+
+/* }}} */
+
+/* Allocate a buffer of (at least) num digits, or return
+   NULL if that couldn't be done.  */
+STATIC mp_digit *s_alloc(mp_size num);
+
+/* Release a buffer of digits allocated by s_alloc(). */
+STATIC void s_free(void *ptr);
+
+/* Insure that z has at least min digits allocated, resizing if
+   necessary.  Returns true if successful, false if out of memory. */
+STATIC int  s_pad(mp_int z, mp_size min);
+
+/* Fill in a "fake" mp_int on the stack with a given value */
+STATIC void      s_fake(mp_int z, mp_small value, mp_digit vbuf[]);
+STATIC void      s_ufake(mp_int z, mp_usmall value, mp_digit vbuf[]);
+
+/* Compare two runs of digits of given length, returns <0, 0, >0 */
+STATIC int       s_cdig(mp_digit *da, mp_digit *db, mp_size len);
+
+/* Pack the unsigned digits of v into array t */
+STATIC int       s_uvpack(mp_usmall v, mp_digit t[]);
+
+/* Compare magnitudes of a and b, returns <0, 0, >0 */
+STATIC int       s_ucmp(mp_int a, mp_int b);
+
+/* Compare magnitudes of a and v, returns <0, 0, >0 */
+STATIC int       s_vcmp(mp_int a, mp_small v);
+STATIC int       s_uvcmp(mp_int a, mp_usmall uv);
+
+/* Unsigned magnitude addition; assumes dc is big enough.
+   Carry out is returned (no memory allocated). */
+STATIC mp_digit  s_uadd(mp_digit *da, mp_digit *db, mp_digit *dc,
+		        mp_size size_a, mp_size size_b);
+
+/* Unsigned magnitude subtraction.  Assumes dc is big enough. */
+STATIC void      s_usub(mp_digit *da, mp_digit *db, mp_digit *dc,
+		        mp_size size_a, mp_size size_b);
+
+/* Unsigned recursive multiplication.  Assumes dc is big enough. */
+STATIC int       s_kmul(mp_digit *da, mp_digit *db, mp_digit *dc,
+			mp_size size_a, mp_size size_b);
+
+/* Unsigned magnitude multiplication.  Assumes dc is big enough. */
+STATIC void      s_umul(mp_digit *da, mp_digit *db, mp_digit *dc,
+			mp_size size_a, mp_size size_b);
+
+/* Unsigned recursive squaring.  Assumes dc is big enough. */
+STATIC int       s_ksqr(mp_digit *da, mp_digit *dc, mp_size size_a);
+
+/* Unsigned magnitude squaring.  Assumes dc is big enough. */
+STATIC void      s_usqr(mp_digit *da, mp_digit *dc, mp_size size_a);
+
+/* Single digit addition.  Assumes a is big enough. */
+STATIC void      s_dadd(mp_int a, mp_digit b);
+
+/* Single digit multiplication.  Assumes a is big enough. */
+STATIC void      s_dmul(mp_int a, mp_digit b);
+
+/* Single digit multiplication on buffers; assumes dc is big enough. */
+STATIC void      s_dbmul(mp_digit *da, mp_digit b, mp_digit *dc,
+			 mp_size size_a);
+
+/* Single digit division.  Replaces a with the quotient,
+   returns the remainder.  */
+STATIC mp_digit  s_ddiv(mp_int a, mp_digit b);
+
+/* Quick division by a power of 2, replaces z (no allocation) */
+STATIC void      s_qdiv(mp_int z, mp_size p2);
+
+/* Quick remainder by a power of 2, replaces z (no allocation) */
+STATIC void      s_qmod(mp_int z, mp_size p2);
+
+/* Quick multiplication by a power of 2, replaces z.
+   Allocates if necessary; returns false in case this fails. */
+STATIC int       s_qmul(mp_int z, mp_size p2);
+
+/* Quick subtraction from a power of 2, replaces z.
+   Allocates if necessary; returns false in case this fails. */
+STATIC int       s_qsub(mp_int z, mp_size p2);
+
+/* Return maximum k such that 2^k divides z. */
+STATIC int       s_dp2k(mp_int z);
+
+/* Return k >= 0 such that z = 2^k, or -1 if there is no such k. */
+STATIC int       s_isp2(mp_int z);
+
+/* Set z to 2^k.  May allocate; returns false in case this fails. */
+STATIC int       s_2expt(mp_int z, mp_small k);
+
+/* Normalize a and b for division, returns normalization constant */
+STATIC int       s_norm(mp_int a, mp_int b);
+
+/* Compute constant mu for Barrett reduction, given modulus m, result
+   replaces z, m is untouched. */
+STATIC mp_result s_brmu(mp_int z, mp_int m);
+
+/* Reduce a modulo m, using Barrett's algorithm. */
+STATIC int       s_reduce(mp_int x, mp_int m, mp_int mu, mp_int q1, mp_int q2);
+
+/* Modular exponentiation, using Barrett reduction */
+STATIC mp_result s_embar(mp_int a, mp_int b, mp_int m, mp_int mu, mp_int c);
+
+/* Unsigned magnitude division.  Assumes |a| > |b|.  Allocates temporaries;
+   overwrites a with quotient, b with remainder. */
+STATIC mp_result s_udiv_knuth(mp_int a, mp_int b);
+
+/* Compute the number of digits in radix r required to represent the given
+   value.  Does not account for sign flags, terminators, etc. */
+STATIC int       s_outlen(mp_int z, mp_size r);
+
+/* Guess how many digits of precision will be needed to represent a radix r
+   value of the specified number of digits.  Returns a value guaranteed to be
+   no smaller than the actual number required. */
+STATIC mp_size   s_inlen(int len, mp_size r);
+
+/* Convert a character to a digit value in radix r, or
+   -1 if out of range */
+STATIC int       s_ch2val(char c, int r);
+
+/* Convert a digit value to a character */
+STATIC char      s_val2ch(int v, int caps);
+
+/* Take 2's complement of a buffer in place */
+STATIC void      s_2comp(unsigned char *buf, int len);
+
+/* Convert a value to binary, ignoring sign.  On input, *limpos is the bound on
+   how many bytes should be written to buf; on output, *limpos is set to the
+   number of bytes actually written. */
+STATIC mp_result s_tobin(mp_int z, unsigned char *buf, int *limpos, int pad);
+
+#if DEBUG
+/* Dump a representation of the mp_int to standard output */
+void      s_print(char *tag, mp_int z);
+void      s_print_buf(char *tag, mp_digit *buf, mp_size num);
+#endif
+
+/* {{{ mp_int_init(z) */
+
+mp_result mp_int_init(mp_int z)
+{
+  if (z == NULL)
+    return MP_BADARG;
+
+  z->single = 0;
+  z->digits = &(z->single);
+  z->alloc  = 1;
+  z->used   = 1;
+  z->sign   = MP_ZPOS;
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ mp_int_alloc() */
+
+mp_int    mp_int_alloc(void)
+{
+  mp_int out = malloc(sizeof(mpz_t));
+
+  if (out != NULL)
+    mp_int_init(out);
+
+  return out;
+}
+
+/* }}} */
+
+/* {{{ mp_int_init_size(z, prec) */
+
+mp_result mp_int_init_size(mp_int z, mp_size prec)
+{
+  CHECK(z != NULL);
+
+  if (prec == 0)
+    prec = default_precision;
+  else if (prec == 1)
+    return mp_int_init(z);
+  else
+    prec = (mp_size) ROUND_PREC(prec);
+
+  if ((MP_DIGITS(z) = s_alloc(prec)) == NULL)
+    return MP_MEMORY;
+
+  z->digits[0] = 0;
+  MP_USED(z) = 1;
+  MP_ALLOC(z) = prec;
+  MP_SIGN(z) = MP_ZPOS;
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ mp_int_init_copy(z, old) */
+
+mp_result mp_int_init_copy(mp_int z, mp_int old)
+{
+  mp_result res;
+  mp_size uold;
+
+  CHECK(z != NULL && old != NULL);
+
+  uold = MP_USED(old);
+  if (uold == 1) {
+    mp_int_init(z);
+  }
+  else {
+    mp_size target = MAX(uold, default_precision);
+
+    if ((res = mp_int_init_size(z, target)) != MP_OK)
+      return res;
+  }
+
+  MP_USED(z) = uold;
+  MP_SIGN(z) = MP_SIGN(old);
+  COPY(MP_DIGITS(old), MP_DIGITS(z), uold);
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ mp_int_init_value(z, value) */
+
+mp_result mp_int_init_value(mp_int z, mp_small value)
+{
+  mpz_t    vtmp;
+  mp_digit vbuf[MP_VALUE_DIGITS(value)];
+
+  s_fake(&vtmp, value, vbuf);
+  return mp_int_init_copy(z, &vtmp);
+}
+
+/* }}} */
+
+/* {{{ mp_int_init_uvalue(z, uvalue) */
+
+mp_result mp_int_init_uvalue(mp_int z, mp_usmall uvalue)
+{
+  mpz_t    vtmp;
+  mp_digit vbuf[MP_VALUE_DIGITS(uvalue)];
+
+  s_ufake(&vtmp, uvalue, vbuf);
+  return mp_int_init_copy(z, &vtmp);
+}
+
+/* }}} */
+
+/* {{{ mp_int_set_value(z, value) */
+
+mp_result  mp_int_set_value(mp_int z, mp_small value)
+{
+  mpz_t    vtmp;
+  mp_digit vbuf[MP_VALUE_DIGITS(value)];
+
+  s_fake(&vtmp, value, vbuf);
+  return mp_int_copy(&vtmp, z);
+}
+
+/* }}} */
+
+/* {{{ mp_int_set_uvalue(z, value) */
+
+mp_result  mp_int_set_uvalue(mp_int z, mp_usmall uvalue)
+{
+  mpz_t    vtmp;
+  mp_digit vbuf[MP_VALUE_DIGITS(uvalue)];
+
+  s_ufake(&vtmp, uvalue, vbuf);
+  return mp_int_copy(&vtmp, z);
+}
+
+/* }}} */
+
+/* {{{ mp_int_clear(z) */
+
+void      mp_int_clear(mp_int z)
+{
+  if (z == NULL)
+    return;
+
+  if (MP_DIGITS(z) != NULL) {
+    if (MP_DIGITS(z) != &(z->single))
+      s_free(MP_DIGITS(z));
+
+    MP_DIGITS(z) = NULL;
+  }
+}
+
+/* }}} */
+
+/* {{{ mp_int_free(z) */
+
+void      mp_int_free(mp_int z)
+{
+  NRCHECK(z != NULL);
+
+  mp_int_clear(z);
+  free(z); /* note: NOT s_free() */
+}
+
+/* }}} */
+
+/* {{{ mp_int_copy(a, c) */
+
+mp_result mp_int_copy(mp_int a, mp_int c)
+{
+  CHECK(a != NULL && c != NULL);
+
+  if (a != c) {
+    mp_size ua = MP_USED(a);
+    mp_digit *da, *dc;
+
+    if (!s_pad(c, ua))
+      return MP_MEMORY;
+
+    da = MP_DIGITS(a); dc = MP_DIGITS(c);
+    COPY(da, dc, ua);
+
+    MP_USED(c) = ua;
+    MP_SIGN(c) = MP_SIGN(a);
+  }
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ mp_int_swap(a, c) */
+
+void      mp_int_swap(mp_int a, mp_int c)
+{
+  if (a != c) {
+    mpz_t tmp = *a;
+
+    *a = *c;
+    *c = tmp;
+
+    if (MP_DIGITS(a) == &(c->single))
+      MP_DIGITS(a) = &(a->single);
+    if (MP_DIGITS(c) == &(a->single))
+      MP_DIGITS(c) = &(c->single);
+  }
+}
+
+/* }}} */
+
+/* {{{ mp_int_zero(z) */
+
+void      mp_int_zero(mp_int z)
+{
+  NRCHECK(z != NULL);
+
+  z->digits[0] = 0;
+  MP_USED(z) = 1;
+  MP_SIGN(z) = MP_ZPOS;
+}
+
+/* }}} */
+
+/* {{{ mp_int_abs(a, c) */
+
+mp_result mp_int_abs(mp_int a, mp_int c)
+{
+  mp_result res;
+
+  CHECK(a != NULL && c != NULL);
+
+  if ((res = mp_int_copy(a, c)) != MP_OK)
+    return res;
+
+  MP_SIGN(c) = MP_ZPOS;
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ mp_int_neg(a, c) */
+
+mp_result mp_int_neg(mp_int a, mp_int c)
+{
+  mp_result res;
+
+  CHECK(a != NULL && c != NULL);
+
+  if ((res = mp_int_copy(a, c)) != MP_OK)
+    return res;
+
+  if (CMPZ(c) != 0)
+    MP_SIGN(c) = 1 - MP_SIGN(a);
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ mp_int_add(a, b, c) */
+
+mp_result mp_int_add(mp_int a, mp_int b, mp_int c)
+{
+  mp_size ua, ub, uc, max;
+
+  CHECK(a != NULL && b != NULL && c != NULL);
+
+  ua = MP_USED(a); ub = MP_USED(b); uc = MP_USED(c);
+  max = MAX(ua, ub);
+
+  if (MP_SIGN(a) == MP_SIGN(b)) {
+    /* Same sign -- add magnitudes, preserve sign of addends */
+    mp_digit carry;
+
+    if (!s_pad(c, max))
+      return MP_MEMORY;
+
+    carry = s_uadd(MP_DIGITS(a), MP_DIGITS(b), MP_DIGITS(c), ua, ub);
+    uc = max;
+
+    if (carry) {
+      if (!s_pad(c, max + 1))
+	return MP_MEMORY;
+
+      c->digits[max] = carry;
+      ++uc;
+    }
+
+    MP_USED(c) = uc;
+    MP_SIGN(c) = MP_SIGN(a);
+
+  }
+  else {
+    /* Different signs -- subtract magnitudes, preserve sign of greater */
+    mp_int  x, y;
+    int     cmp = s_ucmp(a, b); /* magnitude comparision, sign ignored */
+
+    /* Set x to max(a, b), y to min(a, b) to simplify later code.
+       A special case yields zero for equal magnitudes.
+    */
+    if (cmp == 0) {
+      mp_int_zero(c);
+      return MP_OK;
+    }
+    else if (cmp < 0) {
+      x = b; y = a;
+    }
+    else {
+      x = a; y = b;
+    }
+
+    if (!s_pad(c, MP_USED(x)))
+      return MP_MEMORY;
+
+    /* Subtract smaller from larger */
+    s_usub(MP_DIGITS(x), MP_DIGITS(y), MP_DIGITS(c), MP_USED(x), MP_USED(y));
+    MP_USED(c) = MP_USED(x);
+    CLAMP(c);
+
+    /* Give result the sign of the larger */
+    MP_SIGN(c) = MP_SIGN(x);
+  }
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ mp_int_add_value(a, value, c) */
+
+mp_result mp_int_add_value(mp_int a, mp_small value, mp_int c)
+{
+  mpz_t    vtmp;
+  mp_digit vbuf[MP_VALUE_DIGITS(value)];
+
+  s_fake(&vtmp, value, vbuf);
+
+  return mp_int_add(a, &vtmp, c);
+}
+
+/* }}} */
+
+/* {{{ mp_int_sub(a, b, c) */
+
+mp_result mp_int_sub(mp_int a, mp_int b, mp_int c)
+{
+  mp_size ua, ub, uc, max;
+
+  CHECK(a != NULL && b != NULL && c != NULL);
+
+  ua = MP_USED(a); ub = MP_USED(b); uc = MP_USED(c);
+  max = MAX(ua, ub);
+
+  if (MP_SIGN(a) != MP_SIGN(b)) {
+    /* Different signs -- add magnitudes and keep sign of a */
+    mp_digit carry;
+
+    if (!s_pad(c, max))
+      return MP_MEMORY;
+
+    carry = s_uadd(MP_DIGITS(a), MP_DIGITS(b), MP_DIGITS(c), ua, ub);
+    uc = max;
+
+    if (carry) {
+      if (!s_pad(c, max + 1))
+	return MP_MEMORY;
+
+      c->digits[max] = carry;
+      ++uc;
+    }
+
+    MP_USED(c) = uc;
+    MP_SIGN(c) = MP_SIGN(a);
+
+  }
+  else {
+    /* Same signs -- subtract magnitudes */
+    mp_int  x, y;
+    mp_sign osign;
+    int     cmp = s_ucmp(a, b);
+
+    if (!s_pad(c, max))
+      return MP_MEMORY;
+
+    if (cmp >= 0) {
+      x = a; y = b; osign = MP_ZPOS;
+    }
+    else {
+      x = b; y = a; osign = MP_NEG;
+    }
+
+    if (MP_SIGN(a) == MP_NEG && cmp != 0)
+      osign = 1 - osign;
+
+    s_usub(MP_DIGITS(x), MP_DIGITS(y), MP_DIGITS(c), MP_USED(x), MP_USED(y));
+    MP_USED(c) = MP_USED(x);
+    CLAMP(c);
+
+    MP_SIGN(c) = osign;
+  }
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ mp_int_sub_value(a, value, c) */
+
+mp_result mp_int_sub_value(mp_int a, mp_small value, mp_int c)
+{
+  mpz_t    vtmp;
+  mp_digit vbuf[MP_VALUE_DIGITS(value)];
+
+  s_fake(&vtmp, value, vbuf);
+
+  return mp_int_sub(a, &vtmp, c);
+}
+
+/* }}} */
+
+/* {{{ mp_int_mul(a, b, c) */
+
+mp_result mp_int_mul(mp_int a, mp_int b, mp_int c)
+{
+  mp_digit *out;
+  mp_size   osize, ua, ub, p = 0;
+  mp_sign   osign;
+
+  CHECK(a != NULL && b != NULL && c != NULL);
+
+  /* If either input is zero, we can shortcut multiplication */
+  if (mp_int_compare_zero(a) == 0 || mp_int_compare_zero(b) == 0) {
+    mp_int_zero(c);
+    return MP_OK;
+  }
+
+  /* Output is positive if inputs have same sign, otherwise negative */
+  osign = (MP_SIGN(a) == MP_SIGN(b)) ? MP_ZPOS : MP_NEG;
+
+  /* If the output is not identical to any of the inputs, we'll write the
+     results directly; otherwise, allocate a temporary space. */
+  ua = MP_USED(a); ub = MP_USED(b);
+  osize = MAX(ua, ub);
+  osize = 4 * ((osize + 1) / 2);
+
+  if (c == a || c == b) {
+    p = ROUND_PREC(osize);
+    p = MAX(p, default_precision);
+
+    if ((out = s_alloc(p)) == NULL)
+      return MP_MEMORY;
+  }
+  else {
+    if (!s_pad(c, osize))
+      return MP_MEMORY;
+
+    out = MP_DIGITS(c);
+  }
+  ZERO(out, osize);
+
+  if (!s_kmul(MP_DIGITS(a), MP_DIGITS(b), out, ua, ub))
+    return MP_MEMORY;
+
+  /* If we allocated a new buffer, get rid of whatever memory c was already
+     using, and fix up its fields to reflect that.
+   */
+  if (out != MP_DIGITS(c)) {
+    if ((void *) MP_DIGITS(c) != (void *) c)
+      s_free(MP_DIGITS(c));
+    MP_DIGITS(c) = out;
+    MP_ALLOC(c) = p;
+  }
+
+  MP_USED(c) = osize; /* might not be true, but we'll fix it ... */
+  CLAMP(c);           /* ... right here */
+  MP_SIGN(c) = osign;
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ mp_int_mul_value(a, value, c) */
+
+mp_result mp_int_mul_value(mp_int a, mp_small value, mp_int c)
+{
+  mpz_t    vtmp;
+  mp_digit vbuf[MP_VALUE_DIGITS(value)];
+
+  s_fake(&vtmp, value, vbuf);
+
+  return mp_int_mul(a, &vtmp, c);
+}
+
+/* }}} */
+
+/* {{{ mp_int_mul_pow2(a, p2, c) */
+
+mp_result mp_int_mul_pow2(mp_int a, mp_small p2, mp_int c)
+{
+  mp_result res;
+  CHECK(a != NULL && c != NULL && p2 >= 0);
+
+  if ((res = mp_int_copy(a, c)) != MP_OK)
+    return res;
+
+  if (s_qmul(c, (mp_size) p2))
+    return MP_OK;
+  else
+    return MP_MEMORY;
+}
+
+/* }}} */
+
+/* {{{ mp_int_sqr(a, c) */
+
+mp_result mp_int_sqr(mp_int a, mp_int c)
+{
+  mp_digit *out;
+  mp_size   osize, p = 0;
+
+  CHECK(a != NULL && c != NULL);
+
+  /* Get a temporary buffer big enough to hold the result */
+  osize = (mp_size) 4 * ((MP_USED(a) + 1) / 2);
+  if (a == c) {
+    p = ROUND_PREC(osize);
+    p = MAX(p, default_precision);
+
+    if ((out = s_alloc(p)) == NULL)
+      return MP_MEMORY;
+  }
+  else {
+    if (!s_pad(c, osize))
+      return MP_MEMORY;
+
+    out = MP_DIGITS(c);
+  }
+  ZERO(out, osize);
+
+  s_ksqr(MP_DIGITS(a), out, MP_USED(a));
+
+  /* Get rid of whatever memory c was already using, and fix up its fields to
+     reflect the new digit array it's using
+   */
+  if (out != MP_DIGITS(c)) {
+    if ((void *) MP_DIGITS(c) != (void *) c)
+      s_free(MP_DIGITS(c));
+    MP_DIGITS(c) = out;
+    MP_ALLOC(c) = p;
+  }
+
+  MP_USED(c) = osize; /* might not be true, but we'll fix it ... */
+  CLAMP(c);           /* ... right here */
+  MP_SIGN(c) = MP_ZPOS;
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ mp_int_div(a, b, q, r) */
+
+mp_result mp_int_div(mp_int a, mp_int b, mp_int q, mp_int r)
+{
+  int cmp, lg;
+  mp_result res = MP_OK;
+  mp_int qout, rout;
+  mp_sign sa = MP_SIGN(a), sb = MP_SIGN(b);
+  DECLARE_TEMP(2);
+
+  CHECK(a != NULL && b != NULL && q != r);
+
+  if (CMPZ(b) == 0)
+    return MP_UNDEF;
+  else if ((cmp = s_ucmp(a, b)) < 0) {
+    /* If |a| < |b|, no division is required:
+       q = 0, r = a
+     */
+    if (r && (res = mp_int_copy(a, r)) != MP_OK)
+      return res;
+
+    if (q)
+      mp_int_zero(q);
+
+    return MP_OK;
+  }
+  else if (cmp == 0) {
+    /* If |a| = |b|, no division is required:
+       q = 1 or -1, r = 0
+     */
+    if (r)
+      mp_int_zero(r);
+
+    if (q) {
+      mp_int_zero(q);
+      q->digits[0] = 1;
+
+      if (sa != sb)
+	MP_SIGN(q) = MP_NEG;
+    }
+
+    return MP_OK;
+  }
+
+  /* When |a| > |b|, real division is required.  We need someplace to store
+     quotient and remainder, but q and r are allowed to be NULL or to overlap
+     with the inputs.
+   */
+  if ((lg = s_isp2(b)) < 0) {
+    if (q && b != q) {
+      if ((res = mp_int_copy(a, q)) != MP_OK)
+	goto CLEANUP;
+      else
+	qout = q;
+    }
+    else {
+      qout = LAST_TEMP();
+      SETUP(mp_int_init_copy(LAST_TEMP(), a));
+    }
+
+    if (r && a != r) {
+      if ((res = mp_int_copy(b, r)) != MP_OK)
+	goto CLEANUP;
+      else
+	rout = r;
+    }
+    else {
+      rout = LAST_TEMP();
+      SETUP(mp_int_init_copy(LAST_TEMP(), b));
+    }
+
+    if ((res = s_udiv_knuth(qout, rout)) != MP_OK) goto CLEANUP;
+  }
+  else {
+    if (q && (res = mp_int_copy(a, q)) != MP_OK) goto CLEANUP;
+    if (r && (res = mp_int_copy(a, r)) != MP_OK) goto CLEANUP;
+
+    if (q) s_qdiv(q, (mp_size) lg); qout = q;
+    if (r) s_qmod(r, (mp_size) lg); rout = r;
+  }
+
+  /* Recompute signs for output */
+  if (rout) {
+    MP_SIGN(rout) = sa;
+    if (CMPZ(rout) == 0)
+      MP_SIGN(rout) = MP_ZPOS;
+  }
+  if (qout) {
+    MP_SIGN(qout) = (sa == sb) ? MP_ZPOS : MP_NEG;
+    if (CMPZ(qout) == 0)
+      MP_SIGN(qout) = MP_ZPOS;
+  }
+
+  if (q && (res = mp_int_copy(qout, q)) != MP_OK) goto CLEANUP;
+  if (r && (res = mp_int_copy(rout, r)) != MP_OK) goto CLEANUP;
+
+  CLEANUP_TEMP();
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_int_mod(a, m, c) */
+
+mp_result mp_int_mod(mp_int a, mp_int m, mp_int c)
+{
+  mp_result res;
+  mpz_t     tmp;
+  mp_int    out;
+
+  if (m == c) {
+    mp_int_init(&tmp);
+    out = &tmp;
+  }
+  else {
+    out = c;
+  }
+
+  if ((res = mp_int_div(a, m, NULL, out)) != MP_OK)
+    goto CLEANUP;
+
+  if (CMPZ(out) < 0)
+    res = mp_int_add(out, m, c);
+  else
+    res = mp_int_copy(out, c);
+
+ CLEANUP:
+  if (out != c)
+    mp_int_clear(&tmp);
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_int_div_value(a, value, q, r) */
+
+mp_result mp_int_div_value(mp_int a, mp_small value, mp_int q, mp_small *r)
+{
+  mpz_t     vtmp, rtmp;
+  mp_digit  vbuf[MP_VALUE_DIGITS(value)];
+  mp_result res;
+
+  mp_int_init(&rtmp);
+  s_fake(&vtmp, value, vbuf);
+
+  if ((res = mp_int_div(a, &vtmp, q, &rtmp)) != MP_OK)
+    goto CLEANUP;
+
+  if (r)
+    (void) mp_int_to_int(&rtmp, r); /* can't fail */
+
+ CLEANUP:
+  mp_int_clear(&rtmp);
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_int_div_pow2(a, p2, q, r) */
+
+mp_result mp_int_div_pow2(mp_int a, mp_small p2, mp_int q, mp_int r)
+{
+  mp_result res = MP_OK;
+
+  CHECK(a != NULL && p2 >= 0 && q != r);
+
+  if (q != NULL && (res = mp_int_copy(a, q)) == MP_OK)
+    s_qdiv(q, (mp_size) p2);
+
+  if (res == MP_OK && r != NULL && (res = mp_int_copy(a, r)) == MP_OK)
+    s_qmod(r, (mp_size) p2);
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_int_expt(a, b, c) */
+
+mp_result mp_int_expt(mp_int a, mp_small b, mp_int c)
+{
+  mpz_t t;
+  mp_result res;
+  unsigned int v = abs(b);
+
+  CHECK(c != NULL);
+  if (b < 0)
+    return MP_RANGE;
+
+  if ((res = mp_int_init_copy(&t, a)) != MP_OK)
+    return res;
+
+  (void) mp_int_set_value(c, 1);
+  while (v != 0) {
+    if (v & 1) {
+      if ((res = mp_int_mul(c, &t, c)) != MP_OK)
+	goto CLEANUP;
+    }
+
+    v >>= 1;
+    if (v == 0) break;
+
+    if ((res = mp_int_sqr(&t, &t)) != MP_OK)
+      goto CLEANUP;
+  }
+
+ CLEANUP:
+  mp_int_clear(&t);
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_int_expt_value(a, b, c) */
+
+mp_result mp_int_expt_value(mp_small a, mp_small b, mp_int c)
+{
+  mpz_t     t;
+  mp_result res;
+  unsigned int v = abs(b);
+
+  CHECK(c != NULL);
+  if (b < 0)
+    return MP_RANGE;
+
+  if ((res = mp_int_init_value(&t, a)) != MP_OK)
+    return res;
+
+  (void) mp_int_set_value(c, 1);
+  while (v != 0) {
+    if (v & 1) {
+      if ((res = mp_int_mul(c, &t, c)) != MP_OK)
+	goto CLEANUP;
+    }
+
+    v >>= 1;
+    if (v == 0) break;
+
+    if ((res = mp_int_sqr(&t, &t)) != MP_OK)
+      goto CLEANUP;
+  }
+
+ CLEANUP:
+  mp_int_clear(&t);
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_int_expt_full(a, b, c) */
+
+mp_result mp_int_expt_full(mp_int a, mp_int b, mp_int c)
+{
+  mpz_t t;
+  mp_result res;
+  unsigned ix, jx;
+
+  CHECK(a != NULL && b != NULL && c != NULL);
+  if (MP_SIGN(b) == MP_NEG)
+    return MP_RANGE;
+
+  if ((res = mp_int_init_copy(&t, a)) != MP_OK)
+    return res;
+
+  (void) mp_int_set_value(c, 1);
+  for (ix = 0; ix < MP_USED(b); ++ix) {
+    mp_digit d = b->digits[ix];
+
+    for (jx = 0; jx < MP_DIGIT_BIT; ++jx) {
+      if (d & 1) {
+	if ((res = mp_int_mul(c, &t, c)) != MP_OK)
+	  goto CLEANUP;
+      }
+
+      d >>= 1;
+      if (d == 0 && ix + 1 == MP_USED(b))
+	break;
+      if ((res = mp_int_sqr(&t, &t)) != MP_OK)
+	goto CLEANUP;
+    }
+  }
+
+ CLEANUP:
+  mp_int_clear(&t);
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_int_compare(a, b) */
+
+int       mp_int_compare(mp_int a, mp_int b)
+{
+  mp_sign sa;
+
+  CHECK(a != NULL && b != NULL);
+
+  sa = MP_SIGN(a);
+  if (sa == MP_SIGN(b)) {
+    int cmp = s_ucmp(a, b);
+
+    /* If they're both zero or positive, the normal comparison applies; if both
+       negative, the sense is reversed. */
+    if (sa == MP_ZPOS)
+      return cmp;
+    else
+      return -cmp;
+
+  }
+  else {
+    if (sa == MP_ZPOS)
+      return 1;
+    else
+      return -1;
+  }
+}
+
+/* }}} */
+
+/* {{{ mp_int_compare_unsigned(a, b) */
+
+int       mp_int_compare_unsigned(mp_int a, mp_int b)
+{
+  NRCHECK(a != NULL && b != NULL);
+
+  return s_ucmp(a, b);
+}
+
+/* }}} */
+
+/* {{{ mp_int_compare_zero(z) */
+
+int       mp_int_compare_zero(mp_int z)
+{
+  NRCHECK(z != NULL);
+
+  if (MP_USED(z) == 1 && z->digits[0] == 0)
+    return 0;
+  else if (MP_SIGN(z) == MP_ZPOS)
+    return 1;
+  else
+    return -1;
+}
+
+/* }}} */
+
+/* {{{ mp_int_compare_value(z, value) */
+
+int       mp_int_compare_value(mp_int z, mp_small value)
+{
+  mp_sign vsign = (value < 0) ? MP_NEG : MP_ZPOS;
+  int cmp;
+
+  CHECK(z != NULL);
+
+  if (vsign == MP_SIGN(z)) {
+    cmp = s_vcmp(z, value);
+
+    return (vsign == MP_ZPOS) ? cmp : -cmp;
+  }
+  else {
+    return (value < 0) ? 1 : -1;
+  }
+}
+
+/* }}} */
+
+/* {{{ mp_int_compare_uvalue(z, uv) */
+
+int       mp_int_compare_uvalue(mp_int z, mp_usmall uv)
+{
+  CHECK(z != NULL);
+
+  if (MP_SIGN(z) == MP_NEG)
+    return -1;
+  else
+    return s_uvcmp(z, uv);
+}
+
+/* }}} */
+
+/* {{{ mp_int_exptmod(a, b, m, c) */
+
+mp_result mp_int_exptmod(mp_int a, mp_int b, mp_int m, mp_int c)
+{
+  mp_result res;
+  mp_size um;
+  mp_int s;
+  DECLARE_TEMP(3);
+
+  CHECK(a != NULL && b != NULL && c != NULL && m != NULL);
+
+  /* Zero moduli and negative exponents are not considered. */
+  if (CMPZ(m) == 0)
+    return MP_UNDEF;
+  if (CMPZ(b) < 0)
+    return MP_RANGE;
+
+  um = MP_USED(m);
+  SETUP(mp_int_init_size(TEMP(0), 2 * um));
+  SETUP(mp_int_init_size(TEMP(1), 2 * um));
+
+  if (c == b || c == m) {
+    SETUP(mp_int_init_size(TEMP(2), 2 * um));
+    s = TEMP(2);
+  }
+  else {
+    s = c;
+  }
+
+  if ((res = mp_int_mod(a, m, TEMP(0))) != MP_OK) goto CLEANUP;
+
+  if ((res = s_brmu(TEMP(1), m)) != MP_OK) goto CLEANUP;
+
+  if ((res = s_embar(TEMP(0), b, m, TEMP(1), s)) != MP_OK)
+    goto CLEANUP;
+
+  res = mp_int_copy(s, c);
+
+  CLEANUP_TEMP();
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_int_exptmod_evalue(a, value, m, c) */
+
+mp_result mp_int_exptmod_evalue(mp_int a, mp_small value, mp_int m, mp_int c)
+{
+  mpz_t vtmp;
+  mp_digit vbuf[MP_VALUE_DIGITS(value)];
+
+  s_fake(&vtmp, value, vbuf);
+
+  return mp_int_exptmod(a, &vtmp, m, c);
+}
+
+/* }}} */
+
+/* {{{ mp_int_exptmod_bvalue(v, b, m, c) */
+
+mp_result mp_int_exptmod_bvalue(mp_small value, mp_int b,
+				mp_int m, mp_int c)
+{
+  mpz_t vtmp;
+  mp_digit vbuf[MP_VALUE_DIGITS(value)];
+
+  s_fake(&vtmp, value, vbuf);
+
+  return mp_int_exptmod(&vtmp, b, m, c);
+}
+
+/* }}} */
+
+/* {{{ mp_int_exptmod_known(a, b, m, mu, c) */
+
+mp_result mp_int_exptmod_known(mp_int a, mp_int b, mp_int m, mp_int mu, mp_int c)
+{
+  mp_result res;
+  mp_size um;
+  mp_int s;
+  DECLARE_TEMP(2);
+
+  CHECK(a && b && m && c);
+
+  /* Zero moduli and negative exponents are not considered. */
+  if (CMPZ(m) == 0)
+    return MP_UNDEF;
+  if (CMPZ(b) < 0)
+    return MP_RANGE;
+
+  um = MP_USED(m);
+  SETUP(mp_int_init_size(TEMP(0), 2 * um));
+
+  if (c == b || c == m) {
+    SETUP(mp_int_init_size(TEMP(1), 2 * um));
+    s = TEMP(1);
+  }
+  else {
+    s = c;
+  }
+
+  if ((res = mp_int_mod(a, m, TEMP(0))) != MP_OK) goto CLEANUP;
+
+  if ((res = s_embar(TEMP(0), b, m, mu, s)) != MP_OK)
+    goto CLEANUP;
+
+  res = mp_int_copy(s, c);
+
+  CLEANUP_TEMP();
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_int_redux_const(m, c) */
+
+mp_result mp_int_redux_const(mp_int m, mp_int c)
+{
+  CHECK(m != NULL && c != NULL && m != c);
+
+  return s_brmu(c, m);
+}
+
+/* }}} */
+
+/* {{{ mp_int_invmod(a, m, c) */
+
+mp_result mp_int_invmod(mp_int a, mp_int m, mp_int c)
+{
+  mp_result res;
+  mp_sign sa;
+  DECLARE_TEMP(2);
+
+  CHECK(a != NULL && m != NULL && c != NULL);
+
+  if (CMPZ(a) == 0 || CMPZ(m) <= 0)
+    return MP_RANGE;
+
+  sa = MP_SIGN(a); /* need this for the result later */
+
+  for (last__ = 0; last__ < 2; ++last__)
+    mp_int_init(LAST_TEMP());
+
+  if ((res = mp_int_egcd(a, m, TEMP(0), TEMP(1), NULL)) != MP_OK)
+    goto CLEANUP;
+
+  if (mp_int_compare_value(TEMP(0), 1) != 0) {
+    res = MP_UNDEF;
+    goto CLEANUP;
+  }
+
+  /* It is first necessary to constrain the value to the proper range */
+  if ((res = mp_int_mod(TEMP(1), m, TEMP(1))) != MP_OK)
+    goto CLEANUP;
+
+  /* Now, if 'a' was originally negative, the value we have is actually the
+     magnitude of the negative representative; to get the positive value we
+     have to subtract from the modulus.  Otherwise, the value is okay as it
+     stands.
+   */
+  if (sa == MP_NEG)
+    res = mp_int_sub(m, TEMP(1), c);
+  else
+    res = mp_int_copy(TEMP(1), c);
+
+  CLEANUP_TEMP();
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_int_gcd(a, b, c) */
+
+/* Binary GCD algorithm due to Josef Stein, 1961 */
+mp_result mp_int_gcd(mp_int a, mp_int b, mp_int c)
+{
+  int ca, cb, k = 0;
+  mpz_t u, v, t;
+  mp_result res;
+
+  CHECK(a != NULL && b != NULL && c != NULL);
+
+  ca = CMPZ(a);
+  cb = CMPZ(b);
+  if (ca == 0 && cb == 0)
+    return MP_UNDEF;
+  else if (ca == 0)
+    return mp_int_abs(b, c);
+  else if (cb == 0)
+    return mp_int_abs(a, c);
+
+  mp_int_init(&t);
+  if ((res = mp_int_init_copy(&u, a)) != MP_OK)
+    goto U;
+  if ((res = mp_int_init_copy(&v, b)) != MP_OK)
+    goto V;
+
+  MP_SIGN(&u) = MP_ZPOS; MP_SIGN(&v) = MP_ZPOS;
+
+  { /* Divide out common factors of 2 from u and v */
+    int div2_u = s_dp2k(&u), div2_v = s_dp2k(&v);
+
+    k = MIN(div2_u, div2_v);
+    s_qdiv(&u, (mp_size) k);
+    s_qdiv(&v, (mp_size) k);
+  }
+
+  if (mp_int_is_odd(&u)) {
+    if ((res = mp_int_neg(&v, &t)) != MP_OK)
+      goto CLEANUP;
+  }
+  else {
+    if ((res = mp_int_copy(&u, &t)) != MP_OK)
+      goto CLEANUP;
+  }
+
+  for (;;) {
+    s_qdiv(&t, s_dp2k(&t));
+
+    if (CMPZ(&t) > 0) {
+      if ((res = mp_int_copy(&t, &u)) != MP_OK)
+	goto CLEANUP;
+    }
+    else {
+      if ((res = mp_int_neg(&t, &v)) != MP_OK)
+	goto CLEANUP;
+    }
+
+    if ((res = mp_int_sub(&u, &v, &t)) != MP_OK)
+      goto CLEANUP;
+
+    if (CMPZ(&t) == 0)
+      break;
+  }
+
+  if ((res = mp_int_abs(&u, c)) != MP_OK)
+    goto CLEANUP;
+  if (!s_qmul(c, (mp_size) k))
+    res = MP_MEMORY;
+
+ CLEANUP:
+  mp_int_clear(&v);
+ V: mp_int_clear(&u);
+ U: mp_int_clear(&t);
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_int_egcd(a, b, c, x, y) */
+
+/* This is the binary GCD algorithm again, but this time we keep track of the
+   elementary matrix operations as we go, so we can get values x and y
+   satisfying c = ax + by.
+ */
+mp_result mp_int_egcd(mp_int a, mp_int b, mp_int c,
+		      mp_int x, mp_int y)
+{
+  int k, ca, cb;
+  mp_result res;
+  DECLARE_TEMP(8);
+
+  CHECK(a != NULL && b != NULL && c != NULL &&
+	(x != NULL || y != NULL));
+
+  ca = CMPZ(a);
+  cb = CMPZ(b);
+  if (ca == 0 && cb == 0)
+    return MP_UNDEF;
+  else if (ca == 0) {
+    if ((res = mp_int_abs(b, c)) != MP_OK) return res;
+    mp_int_zero(x); (void) mp_int_set_value(y, 1); return MP_OK;
+  }
+  else if (cb == 0) {
+    if ((res = mp_int_abs(a, c)) != MP_OK) return res;
+    (void) mp_int_set_value(x, 1); mp_int_zero(y); return MP_OK;
+  }
+
+  /* Initialize temporaries:
+     A:0, B:1, C:2, D:3, u:4, v:5, ou:6, ov:7 */
+  for (last__ = 0; last__ < 4; ++last__)
+    mp_int_init(LAST_TEMP());
+  TEMP(0)->digits[0] = 1;
+  TEMP(3)->digits[0] = 1;
+
+  SETUP(mp_int_init_copy(TEMP(4), a));
+  SETUP(mp_int_init_copy(TEMP(5), b));
+
+  /* We will work with absolute values here */
+  MP_SIGN(TEMP(4)) = MP_ZPOS;
+  MP_SIGN(TEMP(5)) = MP_ZPOS;
+
+  { /* Divide out common factors of 2 from u and v */
+    int  div2_u = s_dp2k(TEMP(4)), div2_v = s_dp2k(TEMP(5));
+
+    k = MIN(div2_u, div2_v);
+    s_qdiv(TEMP(4), k);
+    s_qdiv(TEMP(5), k);
+  }
+
+  SETUP(mp_int_init_copy(TEMP(6), TEMP(4)));
+  SETUP(mp_int_init_copy(TEMP(7), TEMP(5)));
+
+  for (;;) {
+    while (mp_int_is_even(TEMP(4))) {
+      s_qdiv(TEMP(4), 1);
+
+      if (mp_int_is_odd(TEMP(0)) || mp_int_is_odd(TEMP(1))) {
+	if ((res = mp_int_add(TEMP(0), TEMP(7), TEMP(0))) != MP_OK)
+	  goto CLEANUP;
+	if ((res = mp_int_sub(TEMP(1), TEMP(6), TEMP(1))) != MP_OK)
+	  goto CLEANUP;
+      }
+
+      s_qdiv(TEMP(0), 1);
+      s_qdiv(TEMP(1), 1);
+    }
+
+    while (mp_int_is_even(TEMP(5))) {
+      s_qdiv(TEMP(5), 1);
+
+      if (mp_int_is_odd(TEMP(2)) || mp_int_is_odd(TEMP(3))) {
+	if ((res = mp_int_add(TEMP(2), TEMP(7), TEMP(2))) != MP_OK)
+	  goto CLEANUP;
+	if ((res = mp_int_sub(TEMP(3), TEMP(6), TEMP(3))) != MP_OK)
+	  goto CLEANUP;
+      }
+
+      s_qdiv(TEMP(2), 1);
+      s_qdiv(TEMP(3), 1);
+    }
+
+    if (mp_int_compare(TEMP(4), TEMP(5)) >= 0) {
+      if ((res = mp_int_sub(TEMP(4), TEMP(5), TEMP(4))) != MP_OK) goto CLEANUP;
+      if ((res = mp_int_sub(TEMP(0), TEMP(2), TEMP(0))) != MP_OK) goto CLEANUP;
+      if ((res = mp_int_sub(TEMP(1), TEMP(3), TEMP(1))) != MP_OK) goto CLEANUP;
+    }
+    else {
+      if ((res = mp_int_sub(TEMP(5), TEMP(4), TEMP(5))) != MP_OK) goto CLEANUP;
+      if ((res = mp_int_sub(TEMP(2), TEMP(0), TEMP(2))) != MP_OK) goto CLEANUP;
+      if ((res = mp_int_sub(TEMP(3), TEMP(1), TEMP(3))) != MP_OK) goto CLEANUP;
+    }
+
+    if (CMPZ(TEMP(4)) == 0) {
+      if (x && (res = mp_int_copy(TEMP(2), x)) != MP_OK) goto CLEANUP;
+      if (y && (res = mp_int_copy(TEMP(3), y)) != MP_OK) goto CLEANUP;
+      if (c) {
+	if (!s_qmul(TEMP(5), k)) {
+	  res = MP_MEMORY;
+	  goto CLEANUP;
+	}
+
+	res = mp_int_copy(TEMP(5), c);
+      }
+
+      break;
+    }
+  }
+
+  CLEANUP_TEMP();
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_int_lcm(a, b, c) */
+
+mp_result mp_int_lcm(mp_int a, mp_int b, mp_int c)
+{
+  mpz_t lcm;
+  mp_result res;
+
+  CHECK(a != NULL && b != NULL && c != NULL);
+
+  /* Since a * b = gcd(a, b) * lcm(a, b), we can compute
+     lcm(a, b) = (a / gcd(a, b)) * b.
+
+     This formulation insures everything works even if the input
+     variables share space.
+   */
+  if ((res = mp_int_init(&lcm)) != MP_OK)
+    return res;
+  if ((res = mp_int_gcd(a, b, &lcm)) != MP_OK)
+    goto CLEANUP;
+  if ((res = mp_int_div(a, &lcm, &lcm, NULL)) != MP_OK)
+    goto CLEANUP;
+  if ((res = mp_int_mul(&lcm, b, &lcm)) != MP_OK)
+    goto CLEANUP;
+
+  res = mp_int_copy(&lcm, c);
+
+  CLEANUP:
+    mp_int_clear(&lcm);
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_int_divisible_value(a, v) */
+
+int       mp_int_divisible_value(mp_int a, mp_small v)
+{
+  mp_small rem = 0;
+
+  if (mp_int_div_value(a, v, NULL, &rem) != MP_OK)
+    return 0;
+
+  return rem == 0;
+}
+
+/* }}} */
+
+/* {{{ mp_int_is_pow2(z) */
+
+int       mp_int_is_pow2(mp_int z)
+{
+  CHECK(z != NULL);
+
+  return s_isp2(z);
+}
+
+/* }}} */
+
+/* {{{ mp_int_root(a, b, c) */
+
+/* Implementation of Newton's root finding method, based loosely on a patch
+   contributed by Hal Finkel <half at halssoftware.com>
+   modified by M. J. Fromberger.
+ */
+mp_result mp_int_root(mp_int a, mp_small b, mp_int c)
+{
+  mp_result res = MP_OK;
+  int flips = 0;
+  DECLARE_TEMP(5);
+
+  CHECK(a != NULL && c != NULL && b > 0);
+
+  if (b == 1) {
+    return mp_int_copy(a, c);
+  }
+  if (MP_SIGN(a) == MP_NEG) {
+    if (b % 2 == 0)
+      return MP_UNDEF; /* root does not exist for negative a with even b */
+    else
+      flips = 1;
+  }
+
+  SETUP(mp_int_init_copy(LAST_TEMP(), a));
+  SETUP(mp_int_init_copy(LAST_TEMP(), a));
+  SETUP(mp_int_init(LAST_TEMP()));
+  SETUP(mp_int_init(LAST_TEMP()));
+  SETUP(mp_int_init(LAST_TEMP()));
+
+  (void) mp_int_abs(TEMP(0), TEMP(0));
+  (void) mp_int_abs(TEMP(1), TEMP(1));
+
+  for (;;) {
+    if ((res = mp_int_expt(TEMP(1), b, TEMP(2))) != MP_OK)
+      goto CLEANUP;
+
+    if (mp_int_compare_unsigned(TEMP(2), TEMP(0)) <= 0)
+      break;
+
+    if ((res = mp_int_sub(TEMP(2), TEMP(0), TEMP(2))) != MP_OK)
+      goto CLEANUP;
+    if ((res = mp_int_expt(TEMP(1), b - 1, TEMP(3))) != MP_OK)
+      goto CLEANUP;
+    if ((res = mp_int_mul_value(TEMP(3), b, TEMP(3))) != MP_OK)
+      goto CLEANUP;
+    if ((res = mp_int_div(TEMP(2), TEMP(3), TEMP(4), NULL)) != MP_OK)
+      goto CLEANUP;
+    if ((res = mp_int_sub(TEMP(1), TEMP(4), TEMP(4))) != MP_OK)
+      goto CLEANUP;
+
+    if (mp_int_compare_unsigned(TEMP(1), TEMP(4)) == 0) {
+      if ((res = mp_int_sub_value(TEMP(4), 1, TEMP(4))) != MP_OK)
+	goto CLEANUP;
+    }
+    if ((res = mp_int_copy(TEMP(4), TEMP(1))) != MP_OK)
+      goto CLEANUP;
+  }
+
+  if ((res = mp_int_copy(TEMP(1), c)) != MP_OK)
+    goto CLEANUP;
+
+  /* If the original value of a was negative, flip the output sign. */
+  if (flips)
+    (void) mp_int_neg(c, c); /* cannot fail */
+
+  CLEANUP_TEMP();
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_int_to_int(z, *out) */
+
+mp_result mp_int_to_int(mp_int z, mp_small *out)
+{
+  mp_usmall uv = 0;
+  mp_size   uz;
+  mp_digit *dz;
+  mp_sign   sz;
+
+  CHECK(z != NULL);
+
+  /* Make sure the value is representable as a small integer */
+  sz = MP_SIGN(z);
+  if ((sz == MP_ZPOS && mp_int_compare_value(z, MP_SMALL_MAX) > 0) ||
+      mp_int_compare_value(z, MP_SMALL_MIN) < 0)
+    return MP_RANGE;
+
+  uz = MP_USED(z);
+  dz = MP_DIGITS(z) + uz - 1;
+
+  while (uz > 0) {
+    uv <<= MP_DIGIT_BIT/2;
+    uv = (uv << (MP_DIGIT_BIT/2)) | *dz--;
+    --uz;
+  }
+
+  if (out)
+    *out = (sz == MP_NEG) ? -(mp_small)uv : (mp_small)uv;
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ mp_int_to_uint(z, *out) */
+
+mp_result mp_int_to_uint(mp_int z, mp_usmall *out)
+{
+  mp_usmall uv = 0;
+  mp_size   uz;
+  mp_digit *dz;
+  mp_sign   sz;
+  
+  CHECK(z != NULL);
+
+  /* Make sure the value is representable as an unsigned small integer */
+  sz = MP_SIGN(z);
+  if (sz == MP_NEG || mp_int_compare_uvalue(z, MP_USMALL_MAX) > 0)
+    return MP_RANGE;
+     
+  uz = MP_USED(z);
+  dz = MP_DIGITS(z) + uz - 1;
+  
+  while (uz > 0) {
+    uv <<= MP_DIGIT_BIT/2;
+    uv = (uv << (MP_DIGIT_BIT/2)) | *dz--;
+    --uz;
+  }
+  
+  if (out)
+    *out = uv;
+  
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ mp_int_to_string(z, radix, str, limit) */
+
+mp_result mp_int_to_string(mp_int z, mp_size radix,
+			   char *str, int limit)
+{
+  mp_result res;
+  int       cmp = 0;
+
+  CHECK(z != NULL && str != NULL && limit >= 2);
+
+  if (radix < MP_MIN_RADIX || radix > MP_MAX_RADIX)
+    return MP_RANGE;
+
+  if (CMPZ(z) == 0) {
+    *str++ = s_val2ch(0, 1);
+  }
+  else {
+    mpz_t tmp;
+    char  *h, *t;
+
+    if ((res = mp_int_init_copy(&tmp, z)) != MP_OK)
+      return res;
+
+    if (MP_SIGN(z) == MP_NEG) {
+      *str++ = '-';
+      --limit;
+    }
+    h = str;
+
+    /* Generate digits in reverse order until finished or limit reached */
+    for (/* */; limit > 0; --limit) {
+      mp_digit d;
+
+      if ((cmp = CMPZ(&tmp)) == 0)
+	break;
+
+      d = s_ddiv(&tmp, (mp_digit)radix);
+      *str++ = s_val2ch(d, 1);
+    }
+    t = str - 1;
+
+    /* Put digits back in correct output order */
+    while (h < t) {
+      char tc = *h;
+      *h++ = *t;
+      *t-- = tc;
+    }
+
+    mp_int_clear(&tmp);
+  }
+
+  *str = '\0';
+  if (cmp == 0)
+    return MP_OK;
+  else
+    return MP_TRUNC;
+}
+
+/* }}} */
+
+/* {{{ mp_int_string_len(z, radix) */
+
+mp_result mp_int_string_len(mp_int z, mp_size radix)
+{
+  int  len;
+
+  CHECK(z != NULL);
+
+  if (radix < MP_MIN_RADIX || radix > MP_MAX_RADIX)
+    return MP_RANGE;
+
+  len = s_outlen(z, radix) + 1; /* for terminator */
+
+  /* Allow for sign marker on negatives */
+  if (MP_SIGN(z) == MP_NEG)
+    len += 1;
+
+  return len;
+}
+
+/* }}} */
+
+/* {{{ mp_int_read_string(z, radix, *str) */
+
+/* Read zero-terminated string into z */
+mp_result mp_int_read_string(mp_int z, mp_size radix, const char *str)
+{
+  return mp_int_read_cstring(z, radix, str, NULL);
+}
+
+/* }}} */
+
+/* {{{ mp_int_read_cstring(z, radix, *str, **end) */
+
+mp_result mp_int_read_cstring(mp_int z, mp_size radix, const char *str, char **end)
+{
+  int ch;
+
+  CHECK(z != NULL && str != NULL);
+
+  if (radix < MP_MIN_RADIX || radix > MP_MAX_RADIX)
+    return MP_RANGE;
+
+  /* Skip leading whitespace */
+  while (isspace((int)*str))
+    ++str;
+
+  /* Handle leading sign tag (+/-, positive default) */
+  switch (*str) {
+  case '-':
+    MP_SIGN(z) = MP_NEG;
+    ++str;
+    break;
+  case '+':
+    ++str; /* fallthrough */
+  default:
+    MP_SIGN(z) = MP_ZPOS;
+    break;
+  }
+
+  /* Skip leading zeroes */
+  while ((ch = s_ch2val(*str, radix)) == 0)
+    ++str;
+
+  /* Make sure there is enough space for the value */
+  if (!s_pad(z, s_inlen(strlen(str), radix)))
+    return MP_MEMORY;
+
+  MP_USED(z) = 1; z->digits[0] = 0;
+
+  while (*str != '\0' && ((ch = s_ch2val(*str, radix)) >= 0)) {
+    s_dmul(z, (mp_digit)radix);
+    s_dadd(z, (mp_digit)ch);
+    ++str;
+  }
+
+  CLAMP(z);
+
+  /* Override sign for zero, even if negative specified. */
+  if (CMPZ(z) == 0)
+    MP_SIGN(z) = MP_ZPOS;
+
+  if (end != NULL)
+    *end = (char *)str;
+
+  /* Return a truncation error if the string has unprocessed characters
+     remaining, so the caller can tell if the whole string was done */
+  if (*str != '\0')
+    return MP_TRUNC;
+  else
+    return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ mp_int_count_bits(z) */
+
+mp_result mp_int_count_bits(mp_int z)
+{
+  mp_size  nbits = 0, uz;
+  mp_digit d;
+
+  CHECK(z != NULL);
+
+  uz = MP_USED(z);
+  if (uz == 1 && z->digits[0] == 0)
+    return 1;
+
+  --uz;
+  nbits = uz * MP_DIGIT_BIT;
+  d = z->digits[uz];
+
+  while (d != 0) {
+    d >>= 1;
+    ++nbits;
+  }
+
+  return nbits;
+}
+
+/* }}} */
+
+/* {{{ mp_int_to_binary(z, buf, limit) */
+
+mp_result mp_int_to_binary(mp_int z, unsigned char *buf, int limit)
+{
+  static const int PAD_FOR_2C = 1;
+
+  mp_result res;
+  int limpos = limit;
+
+  CHECK(z != NULL && buf != NULL);
+
+  res = s_tobin(z, buf, &limpos, PAD_FOR_2C);
+
+  if (MP_SIGN(z) == MP_NEG)
+    s_2comp(buf, limpos);
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_int_read_binary(z, buf, len) */
+
+mp_result mp_int_read_binary(mp_int z, unsigned char *buf, int len)
+{
+  mp_size need, i;
+  unsigned char *tmp;
+  mp_digit *dz;
+
+  CHECK(z != NULL && buf != NULL && len > 0);
+
+  /* Figure out how many digits are needed to represent this value */
+  need = ((len * CHAR_BIT) + (MP_DIGIT_BIT - 1)) / MP_DIGIT_BIT;
+  if (!s_pad(z, need))
+    return MP_MEMORY;
+
+  mp_int_zero(z);
+
+  /* If the high-order bit is set, take the 2's complement before reading the
+     value (it will be restored afterward) */
+  if (buf[0] >> (CHAR_BIT - 1)) {
+    MP_SIGN(z) = MP_NEG;
+    s_2comp(buf, len);
+  }
+
+  dz = MP_DIGITS(z);
+  for (tmp = buf, i = len; i > 0; --i, ++tmp) {
+    s_qmul(z, (mp_size) CHAR_BIT);
+    *dz |= *tmp;
+  }
+
+  /* Restore 2's complement if we took it before */
+  if (MP_SIGN(z) == MP_NEG)
+    s_2comp(buf, len);
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ mp_int_binary_len(z) */
+
+mp_result mp_int_binary_len(mp_int z)
+{
+  mp_result  res = mp_int_count_bits(z);
+  int        bytes = mp_int_unsigned_len(z);
+
+  if (res <= 0)
+    return res;
+
+  bytes = (res + (CHAR_BIT - 1)) / CHAR_BIT;
+
+  /* If the highest-order bit falls exactly on a byte boundary, we need to pad
+     with an extra byte so that the sign will be read correctly when reading it
+     back in. */
+  if (bytes * CHAR_BIT == res)
+    ++bytes;
+
+  return bytes;
+}
+
+/* }}} */
+
+/* {{{ mp_int_to_unsigned(z, buf, limit) */
+
+mp_result mp_int_to_unsigned(mp_int z, unsigned char *buf, int limit)
+{
+  static const int NO_PADDING = 0;
+
+  CHECK(z != NULL && buf != NULL);
+
+  return s_tobin(z, buf, &limit, NO_PADDING);
+}
+
+/* }}} */
+
+/* {{{ mp_int_read_unsigned(z, buf, len) */
+
+mp_result mp_int_read_unsigned(mp_int z, unsigned char *buf, int len)
+{
+  mp_size need, i;
+  unsigned char *tmp;
+
+  CHECK(z != NULL && buf != NULL && len > 0);
+
+  /* Figure out how many digits are needed to represent this value */
+  need = ((len * CHAR_BIT) + (MP_DIGIT_BIT - 1)) / MP_DIGIT_BIT;
+  if (!s_pad(z, need))
+    return MP_MEMORY;
+
+  mp_int_zero(z);
+
+  for (tmp = buf, i = len; i > 0; --i, ++tmp) {
+    (void) s_qmul(z, CHAR_BIT);
+    *MP_DIGITS(z) |= *tmp;
+  }
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ mp_int_unsigned_len(z) */
+
+mp_result mp_int_unsigned_len(mp_int z)
+{
+  mp_result  res = mp_int_count_bits(z);
+  int        bytes;
+
+  if (res <= 0)
+    return res;
+
+  bytes = (res + (CHAR_BIT - 1)) / CHAR_BIT;
+
+  return bytes;
+}
+
+/* }}} */
+
+/* {{{ mp_error_string(res) */
+
+const char *mp_error_string(mp_result res)
+{
+  int ix;
+  if (res > 0)
+    return s_unknown_err;
+
+  res = -res;
+  for (ix = 0; ix < res && s_error_msg[ix] != NULL; ++ix)
+    ;
+
+  if (s_error_msg[ix] != NULL)
+    return s_error_msg[ix];
+  else
+    return s_unknown_err;
+}
+
+/* }}} */
+
+/*------------------------------------------------------------------------*/
+/* Private functions for internal use.  These make assumptions.           */
+
+/* {{{ s_alloc(num) */
+
+STATIC mp_digit *s_alloc(mp_size num)
+{
+  mp_digit *out = malloc(num * sizeof(mp_digit));
+
+  assert(out != NULL); /* for debugging */
+#if DEBUG > 1
+  {
+    mp_digit v = (mp_digit) 0xdeadbeef;
+    int      ix;
+
+    for (ix = 0; ix < num; ++ix)
+      out[ix] = v;
+  }
+#endif
+
+  return out;
+}
+
+/* }}} */
+
+/* {{{ s_realloc(old, osize, nsize) */
+
+STATIC mp_digit *s_realloc(mp_digit *old, mp_size osize, mp_size nsize)
+{
+#if DEBUG > 1
+  mp_digit *new = s_alloc(nsize);
+  int       ix;
+
+  for (ix = 0; ix < nsize; ++ix)
+    new[ix] = (mp_digit) 0xdeadbeef;
+
+  memcpy(new, old, osize * sizeof(mp_digit));
+#else
+  mp_digit *new = realloc(old, nsize * sizeof(mp_digit));
+
+  assert(new != NULL); /* for debugging */
+#endif
+  return new;
+}
+
+/* }}} */
+
+/* {{{ s_free(ptr) */
+
+STATIC void s_free(void *ptr)
+{
+  free(ptr);
+}
+
+/* }}} */
+
+/* {{{ s_pad(z, min) */
+
+STATIC int      s_pad(mp_int z, mp_size min)
+{
+  if (MP_ALLOC(z) < min) {
+    mp_size nsize = ROUND_PREC(min);
+    mp_digit *tmp;
+
+    if ((void *)z->digits == (void *)z) {
+      if ((tmp = s_alloc(nsize)) == NULL)
+        return 0;
+
+      COPY(MP_DIGITS(z), tmp, MP_USED(z));
+    }
+    else if ((tmp = s_realloc(MP_DIGITS(z), MP_ALLOC(z), nsize)) == NULL)
+      return 0;
+
+    MP_DIGITS(z) = tmp;
+    MP_ALLOC(z) = nsize;
+  }
+
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ s_fake(z, value, vbuf[]) */
+
+/* Note: This will not work correctly when value == MP_SMALL_MIN */
+STATIC void      s_fake(mp_int z, mp_small value, mp_digit vbuf[])
+{
+  mp_usmall uv = (mp_usmall) (value < 0) ? -value : value;
+  s_ufake(z, uv, vbuf);
+  if (value < 0)
+    z->sign = MP_NEG;
+}
+
+/* }}} */
+
+/* {{{ s_ufake(z, value, vbuf[]) */
+
+STATIC void      s_ufake(mp_int z, mp_usmall value, mp_digit vbuf[])
+{
+  mp_size ndig = (mp_size) s_uvpack(value, vbuf);
+
+  z->used = ndig;
+  z->alloc = MP_VALUE_DIGITS(value);
+  z->sign = MP_ZPOS;
+  z->digits = vbuf;
+}
+
+/* }}} */
+
+/* {{{ s_cdig(da, db, len) */
+
+STATIC int      s_cdig(mp_digit *da, mp_digit *db, mp_size len)
+{
+  mp_digit *dat = da + len - 1, *dbt = db + len - 1;
+
+  for (/* */; len != 0; --len, --dat, --dbt) {
+    if (*dat > *dbt)
+      return 1;
+    else if (*dat < *dbt)
+      return -1;
+  }
+
+  return 0;
+}
+
+/* }}} */
+
+/* {{{ s_uvpack(uv, t[]) */
+
+STATIC int       s_uvpack(mp_usmall uv, mp_digit t[])
+{
+  int ndig = 0;
+
+  if (uv == 0)
+    t[ndig++] = 0;
+  else {
+    while (uv != 0) {
+      t[ndig++] = (mp_digit) uv;
+      uv >>= MP_DIGIT_BIT/2;
+      uv >>= MP_DIGIT_BIT/2;
+    }
+  }
+
+  return ndig;
+}
+
+/* }}} */
+
+/* {{{ s_ucmp(a, b) */
+
+STATIC int      s_ucmp(mp_int a, mp_int b)
+{
+  mp_size  ua = MP_USED(a), ub = MP_USED(b);
+
+  if (ua > ub)
+    return 1;
+  else if (ub > ua)
+    return -1;
+  else
+    return s_cdig(MP_DIGITS(a), MP_DIGITS(b), ua);
+}
+
+/* }}} */
+
+/* {{{ s_vcmp(a, v) */
+
+STATIC int      s_vcmp(mp_int a, mp_small v)
+{
+  mp_usmall uv = (mp_usmall) (v < 0) ? -v : v;
+  return s_uvcmp(a, uv);
+}
+
+/* }}} */
+
+/* {{{ s_uvcmp(a, v) */
+
+STATIC int      s_uvcmp(mp_int a, mp_usmall uv)
+{
+  mpz_t vtmp;
+  mp_digit vdig[MP_VALUE_DIGITS(uv)];
+
+  s_ufake(&vtmp, uv, vdig);
+  return s_ucmp(a, &vtmp);
+}
+
+/* }}} */
+
+/* {{{ s_uadd(da, db, dc, size_a, size_b) */
+
+STATIC mp_digit s_uadd(mp_digit *da, mp_digit *db, mp_digit *dc,
+		       mp_size size_a, mp_size size_b)
+{
+  mp_size pos;
+  mp_word w = 0;
+
+  /* Insure that da is the longer of the two to simplify later code */
+  if (size_b > size_a) {
+    SWAP(mp_digit *, da, db);
+    SWAP(mp_size, size_a, size_b);
+  }
+
+  /* Add corresponding digits until the shorter number runs out */
+  for (pos = 0; pos < size_b; ++pos, ++da, ++db, ++dc) {
+    w = w + (mp_word) *da + (mp_word) *db;
+    *dc = LOWER_HALF(w);
+    w = UPPER_HALF(w);
+  }
+
+  /* Propagate carries as far as necessary */
+  for (/* */; pos < size_a; ++pos, ++da, ++dc) {
+    w = w + *da;
+
+    *dc = LOWER_HALF(w);
+    w = UPPER_HALF(w);
+  }
+
+  /* Return carry out */
+  return (mp_digit)w;
+}
+
+/* }}} */
+
+/* {{{ s_usub(da, db, dc, size_a, size_b) */
+
+STATIC void     s_usub(mp_digit *da, mp_digit *db, mp_digit *dc,
+		       mp_size size_a, mp_size size_b)
+{
+  mp_size pos;
+  mp_word w = 0;
+
+  /* We assume that |a| >= |b| so this should definitely hold */
+  assert(size_a >= size_b);
+
+  /* Subtract corresponding digits and propagate borrow */
+  for (pos = 0; pos < size_b; ++pos, ++da, ++db, ++dc) {
+    w = ((mp_word)MP_DIGIT_MAX + 1 +  /* MP_RADIX */
+	 (mp_word)*da) - w - (mp_word)*db;
+
+    *dc = LOWER_HALF(w);
+    w = (UPPER_HALF(w) == 0);
+  }
+
+  /* Finish the subtraction for remaining upper digits of da */
+  for (/* */; pos < size_a; ++pos, ++da, ++dc) {
+    w = ((mp_word)MP_DIGIT_MAX + 1 +  /* MP_RADIX */
+	 (mp_word)*da) - w;
+
+    *dc = LOWER_HALF(w);
+    w = (UPPER_HALF(w) == 0);
+  }
+
+  /* If there is a borrow out at the end, it violates the precondition */
+  assert(w == 0);
+}
+
+/* }}} */
+
+/* {{{ s_kmul(da, db, dc, size_a, size_b) */
+
+STATIC int       s_kmul(mp_digit *da, mp_digit *db, mp_digit *dc,
+			mp_size size_a, mp_size size_b)
+{
+  mp_size  bot_size;
+
+  /* Make sure b is the smaller of the two input values */
+  if (size_b > size_a) {
+    SWAP(mp_digit *, da, db);
+    SWAP(mp_size, size_a, size_b);
+  }
+
+  /* Insure that the bottom is the larger half in an odd-length split; the code
+     below relies on this being true.
+   */
+  bot_size = (size_a + 1) / 2;
+
+  /* If the values are big enough to bother with recursion, use the Karatsuba
+     algorithm to compute the product; otherwise use the normal multiplication
+     algorithm
+   */
+  if (multiply_threshold &&
+      size_a >= multiply_threshold &&
+      size_b > bot_size) {
+
+    mp_digit *t1, *t2, *t3, carry;
+
+    mp_digit *a_top = da + bot_size;
+    mp_digit *b_top = db + bot_size;
+
+    mp_size  at_size = size_a - bot_size;
+    mp_size  bt_size = size_b - bot_size;
+    mp_size  buf_size = 2 * bot_size;
+
+    /* Do a single allocation for all three temporary buffers needed; each
+       buffer must be big enough to hold the product of two bottom halves, and
+       one buffer needs space for the completed product; twice the space is
+       plenty.
+     */
+    if ((t1 = s_alloc(4 * buf_size)) == NULL) return 0;
+    t2 = t1 + buf_size;
+    t3 = t2 + buf_size;
+    ZERO(t1, 4 * buf_size);
+
+    /* t1 and t2 are initially used as temporaries to compute the inner product
+       (a1 + a0)(b1 + b0) = a1b1 + a1b0 + a0b1 + a0b0
+     */
+    carry = s_uadd(da, a_top, t1, bot_size, at_size);      /* t1 = a1 + a0 */
+    t1[bot_size] = carry;
+
+    carry = s_uadd(db, b_top, t2, bot_size, bt_size);      /* t2 = b1 + b0 */
+    t2[bot_size] = carry;
+
+    (void) s_kmul(t1, t2, t3, bot_size + 1, bot_size + 1); /* t3 = t1 * t2 */
+
+    /* Now we'll get t1 = a0b0 and t2 = a1b1, and subtract them out so that
+       we're left with only the pieces we want:  t3 = a1b0 + a0b1
+     */
+    ZERO(t1, buf_size);
+    ZERO(t2, buf_size);
+    (void) s_kmul(da, db, t1, bot_size, bot_size);     /* t1 = a0 * b0 */
+    (void) s_kmul(a_top, b_top, t2, at_size, bt_size); /* t2 = a1 * b1 */
+
+    /* Subtract out t1 and t2 to get the inner product */
+    s_usub(t3, t1, t3, buf_size + 2, buf_size);
+    s_usub(t3, t2, t3, buf_size + 2, buf_size);
+
+    /* Assemble the output value */
+    COPY(t1, dc, buf_size);
+    carry = s_uadd(t3, dc + bot_size, dc + bot_size,
+		   buf_size + 1, buf_size);
+    assert(carry == 0);
+
+    carry = s_uadd(t2, dc + 2*bot_size, dc + 2*bot_size,
+		   buf_size, buf_size);
+    assert(carry == 0);
+
+    s_free(t1); /* note t2 and t3 are just internal pointers to t1 */
+  }
+  else {
+    s_umul(da, db, dc, size_a, size_b);
+  }
+
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ s_umul(da, db, dc, size_a, size_b) */
+
+STATIC void     s_umul(mp_digit *da, mp_digit *db, mp_digit *dc,
+		       mp_size size_a, mp_size size_b)
+{
+  mp_size a, b;
+  mp_word w;
+
+  for (a = 0; a < size_a; ++a, ++dc, ++da) {
+    mp_digit *dct = dc;
+    mp_digit *dbt = db;
+
+    if (*da == 0)
+      continue;
+
+    w = 0;
+    for (b = 0; b < size_b; ++b, ++dbt, ++dct) {
+      w = (mp_word)*da * (mp_word)*dbt + w + (mp_word)*dct;
+
+      *dct = LOWER_HALF(w);
+      w = UPPER_HALF(w);
+    }
+
+    *dct = (mp_digit)w;
+  }
+}
+
+/* }}} */
+
+/* {{{ s_ksqr(da, dc, size_a) */
+
+STATIC int       s_ksqr(mp_digit *da, mp_digit *dc, mp_size size_a)
+{
+  if (multiply_threshold && size_a > multiply_threshold) {
+    mp_size  bot_size = (size_a + 1) / 2;
+    mp_digit *a_top = da + bot_size;
+    mp_digit *t1, *t2, *t3, carry;
+    mp_size  at_size = size_a - bot_size;
+    mp_size  buf_size = 2 * bot_size;
+
+    if ((t1 = s_alloc(4 * buf_size)) == NULL) return 0;
+    t2 = t1 + buf_size;
+    t3 = t2 + buf_size;
+    ZERO(t1, 4 * buf_size);
+
+    (void) s_ksqr(da, t1, bot_size);    /* t1 = a0 ^ 2 */
+    (void) s_ksqr(a_top, t2, at_size);  /* t2 = a1 ^ 2 */
+
+    (void) s_kmul(da, a_top, t3, bot_size, at_size);  /* t3 = a0 * a1 */
+
+    /* Quick multiply t3 by 2, shifting left (can't overflow) */
+    {
+      int i, top = bot_size + at_size;
+      mp_word w, save = 0;
+
+      for (i = 0; i < top; ++i) {
+	w = t3[i];
+	w = (w << 1) | save;
+	t3[i] = LOWER_HALF(w);
+	save = UPPER_HALF(w);
+      }
+      t3[i] = LOWER_HALF(save);
+    }
+
+    /* Assemble the output value */
+    COPY(t1, dc, 2 * bot_size);
+    carry = s_uadd(t3, dc + bot_size, dc + bot_size,
+		   buf_size + 1, buf_size);
+    assert(carry == 0);
+
+    carry = s_uadd(t2, dc + 2*bot_size, dc + 2*bot_size,
+		   buf_size, buf_size);
+    assert(carry == 0);
+
+    s_free(t1); /* note that t2 and t2 are internal pointers only */
+
+  } 
+  else {
+    s_usqr(da, dc, size_a);
+  }
+
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ s_usqr(da, dc, size_a) */
+
+STATIC void      s_usqr(mp_digit *da, mp_digit *dc, mp_size size_a)
+{
+  mp_size i, j;
+  mp_word w;
+
+  for (i = 0; i < size_a; ++i, dc += 2, ++da) {
+    mp_digit  *dct = dc, *dat = da;
+
+    if (*da == 0)
+      continue;
+
+    /* Take care of the first digit, no rollover */
+    w = (mp_word)*dat * (mp_word)*dat + (mp_word)*dct;
+    *dct = LOWER_HALF(w);
+    w = UPPER_HALF(w);
+    ++dat; ++dct;
+
+    for (j = i + 1; j < size_a; ++j, ++dat, ++dct) {
+      mp_word  t = (mp_word)*da * (mp_word)*dat;
+      mp_word  u = w + (mp_word)*dct, ov = 0;
+
+      /* Check if doubling t will overflow a word */
+      if (HIGH_BIT_SET(t))
+	ov = 1;
+
+      w = t + t;
+
+      /* Check if adding u to w will overflow a word */
+      if (ADD_WILL_OVERFLOW(w, u))
+	ov = 1;
+
+      w += u;
+
+      *dct = LOWER_HALF(w);
+      w = UPPER_HALF(w);
+      if (ov) {
+	w += MP_DIGIT_MAX; /* MP_RADIX */
+	++w;
+      }
+    }
+
+    w = w + *dct;
+    *dct = (mp_digit)w;
+    while ((w = UPPER_HALF(w)) != 0) {
+      ++dct; w = w + *dct;
+      *dct = LOWER_HALF(w);
+    }
+
+    assert(w == 0);
+  }
+}
+
+/* }}} */
+
+/* {{{ s_dadd(a, b) */
+
+STATIC void      s_dadd(mp_int a, mp_digit b)
+{
+  mp_word w = 0;
+  mp_digit *da = MP_DIGITS(a);
+  mp_size ua = MP_USED(a);
+
+  w = (mp_word)*da + b;
+  *da++ = LOWER_HALF(w);
+  w = UPPER_HALF(w);
+
+  for (ua -= 1; ua > 0; --ua, ++da) {
+    w = (mp_word)*da + w;
+
+    *da = LOWER_HALF(w);
+    w = UPPER_HALF(w);
+  }
+
+  if (w) {
+    *da = (mp_digit)w;
+    MP_USED(a) += 1;
+  }
+}
+
+/* }}} */
+
+/* {{{ s_dmul(a, b) */
+
+STATIC void      s_dmul(mp_int a, mp_digit b)
+{
+  mp_word w = 0;
+  mp_digit *da = MP_DIGITS(a);
+  mp_size ua = MP_USED(a);
+
+  while (ua > 0) {
+    w = (mp_word)*da * b + w;
+    *da++ = LOWER_HALF(w);
+    w = UPPER_HALF(w);
+    --ua;
+  }
+
+  if (w) {
+    *da = (mp_digit)w;
+    MP_USED(a) += 1;
+  }
+}
+
+/* }}} */
+
+/* {{{ s_dbmul(da, b, dc, size_a) */
+
+STATIC void      s_dbmul(mp_digit *da, mp_digit b, mp_digit *dc, mp_size size_a)
+{
+  mp_word  w = 0;
+
+  while (size_a > 0) {
+    w = (mp_word)*da++ * (mp_word)b + w;
+
+    *dc++ = LOWER_HALF(w);
+    w = UPPER_HALF(w);
+    --size_a;
+  }
+
+  if (w)
+    *dc = LOWER_HALF(w);
+}
+
+/* }}} */
+
+/* {{{ s_ddiv(da, d, dc, size_a) */
+
+STATIC mp_digit  s_ddiv(mp_int a, mp_digit b)
+{
+  mp_word w = 0, qdigit;
+  mp_size ua = MP_USED(a);
+  mp_digit *da = MP_DIGITS(a) + ua - 1;
+
+  for (/* */; ua > 0; --ua, --da) {
+    w = (w << MP_DIGIT_BIT) | *da;
+
+    if (w >= b) {
+      qdigit = w / b;
+      w = w % b;
+    }
+    else {
+      qdigit = 0;
+    }
+
+    *da = (mp_digit)qdigit;
+  }
+
+  CLAMP(a);
+  return (mp_digit)w;
+}
+
+/* }}} */
+
+/* {{{ s_qdiv(z, p2) */
+
+STATIC void     s_qdiv(mp_int z, mp_size p2)
+{
+  mp_size ndig = p2 / MP_DIGIT_BIT, nbits = p2 % MP_DIGIT_BIT;
+  mp_size uz = MP_USED(z);
+
+  if (ndig) {
+    mp_size  mark;
+    mp_digit *to, *from;
+
+    if (ndig >= uz) {
+      mp_int_zero(z);
+      return;
+    }
+
+    to = MP_DIGITS(z); from = to + ndig;
+
+    for (mark = ndig; mark < uz; ++mark)
+      *to++ = *from++;
+
+    MP_USED(z) = uz - ndig;
+  }
+
+  if (nbits) {
+    mp_digit d = 0, *dz, save;
+    mp_size  up = MP_DIGIT_BIT - nbits;
+
+    uz = MP_USED(z);
+    dz = MP_DIGITS(z) + uz - 1;
+
+    for (/* */; uz > 0; --uz, --dz) {
+      save = *dz;
+
+      *dz = (*dz >> nbits) | (d << up);
+      d = save;
+    }
+
+    CLAMP(z);
+  }
+
+  if (MP_USED(z) == 1 && z->digits[0] == 0)
+    MP_SIGN(z) = MP_ZPOS;
+}
+
+/* }}} */
+
+/* {{{ s_qmod(z, p2) */
+
+STATIC void     s_qmod(mp_int z, mp_size p2)
+{
+  mp_size start = p2 / MP_DIGIT_BIT + 1, rest = p2 % MP_DIGIT_BIT;
+  mp_size uz = MP_USED(z);
+  mp_digit mask = (1 << rest) - 1;
+
+  if (start <= uz) {
+    MP_USED(z) = start;
+    z->digits[start - 1] &= mask;
+    CLAMP(z);
+  }
+}
+
+/* }}} */
+
+/* {{{ s_qmul(z, p2) */
+
+STATIC int      s_qmul(mp_int z, mp_size p2)
+{
+  mp_size   uz, need, rest, extra, i;
+  mp_digit *from, *to, d;
+
+  if (p2 == 0)
+    return 1;
+
+  uz = MP_USED(z); 
+  need = p2 / MP_DIGIT_BIT; rest = p2 % MP_DIGIT_BIT;
+
+  /* Figure out if we need an extra digit at the top end; this occurs if the
+     topmost `rest' bits of the high-order digit of z are not zero, meaning
+     they will be shifted off the end if not preserved */
+  extra = 0;
+  if (rest != 0) {
+    mp_digit *dz = MP_DIGITS(z) + uz - 1;
+
+    if ((*dz >> (MP_DIGIT_BIT - rest)) != 0)
+      extra = 1;
+  }
+
+  if (!s_pad(z, uz + need + extra))
+    return 0;
+
+  /* If we need to shift by whole digits, do that in one pass, then
+     to back and shift by partial digits.
+   */
+  if (need > 0) {
+    from = MP_DIGITS(z) + uz - 1;
+    to = from + need;
+
+    for (i = 0; i < uz; ++i)
+      *to-- = *from--;
+
+    ZERO(MP_DIGITS(z), need);
+    uz += need;
+  }
+
+  if (rest) {
+    d = 0;
+    for (i = need, from = MP_DIGITS(z) + need; i < uz; ++i, ++from) {
+      mp_digit save = *from;
+      
+      *from = (*from << rest) | (d >> (MP_DIGIT_BIT - rest));
+      d = save;
+    }
+
+    d >>= (MP_DIGIT_BIT - rest);
+    if (d != 0) {
+      *from = d;
+      uz += extra;
+    }
+  }
+
+  MP_USED(z) = uz;
+  CLAMP(z);
+
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ s_qsub(z, p2) */
+
+/* Compute z = 2^p2 - |z|; requires that 2^p2 >= |z|
+   The sign of the result is always zero/positive.
+ */
+STATIC int       s_qsub(mp_int z, mp_size p2)
+{
+  mp_digit hi = (1 << (p2 % MP_DIGIT_BIT)), *zp;
+  mp_size  tdig = (p2 / MP_DIGIT_BIT), pos;
+  mp_word  w = 0;
+
+  if (!s_pad(z, tdig + 1))
+    return 0;
+
+  for (pos = 0, zp = MP_DIGITS(z); pos < tdig; ++pos, ++zp) {
+    w = ((mp_word) MP_DIGIT_MAX + 1) - w - (mp_word)*zp;
+
+    *zp = LOWER_HALF(w);
+    w = UPPER_HALF(w) ? 0 : 1;
+  }
+
+  w = ((mp_word) MP_DIGIT_MAX + 1 + hi) - w - (mp_word)*zp;
+  *zp = LOWER_HALF(w);
+
+  assert(UPPER_HALF(w) != 0); /* no borrow out should be possible */
+
+  MP_SIGN(z) = MP_ZPOS;
+  CLAMP(z);
+
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ s_dp2k(z) */
+
+STATIC int      s_dp2k(mp_int z)
+{
+  int       k = 0;
+  mp_digit *dp = MP_DIGITS(z), d;
+
+  if (MP_USED(z) == 1 && *dp == 0)
+    return 1;
+
+  while (*dp == 0) {
+    k += MP_DIGIT_BIT;
+    ++dp;
+  }
+
+  d = *dp;
+  while ((d & 1) == 0) {
+    d >>= 1;
+    ++k;
+  }
+
+  return k;
+}
+
+/* }}} */
+
+/* {{{ s_isp2(z) */
+
+STATIC int       s_isp2(mp_int z)
+{
+  mp_size uz = MP_USED(z), k = 0;
+  mp_digit *dz = MP_DIGITS(z), d;
+
+  while (uz > 1) {
+    if (*dz++ != 0)
+      return -1;
+    k += MP_DIGIT_BIT;
+    --uz;
+  }
+
+  d = *dz;
+  while (d > 1) {
+    if (d & 1)
+      return -1;
+    ++k; d >>= 1;
+  }
+
+  return (int) k;
+}
+
+/* }}} */
+
+/* {{{ s_2expt(z, k) */
+
+STATIC int       s_2expt(mp_int z, mp_small k)
+{
+  mp_size  ndig, rest;
+  mp_digit *dz;
+
+  ndig = (k + MP_DIGIT_BIT) / MP_DIGIT_BIT;
+  rest = k % MP_DIGIT_BIT;
+
+  if (!s_pad(z, ndig))
+    return 0;
+
+  dz = MP_DIGITS(z);
+  ZERO(dz, ndig);
+  *(dz + ndig - 1) = (1 << rest);
+  MP_USED(z) = ndig;
+
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ s_norm(a, b) */
+
+STATIC int      s_norm(mp_int a, mp_int b)
+{
+  mp_digit d = b->digits[MP_USED(b) - 1];
+  int k = 0;
+
+  while (d < (mp_digit) (1 << (MP_DIGIT_BIT - 1))) { /* d < (MP_RADIX / 2) */
+    d <<= 1;
+    ++k;
+  }
+
+  /* These multiplications can't fail */
+  if (k != 0) {
+    (void) s_qmul(a, (mp_size) k);
+    (void) s_qmul(b, (mp_size) k);
+  }
+
+  return k;
+}
+
+/* }}} */
+
+/* {{{ s_brmu(z, m) */
+
+STATIC mp_result s_brmu(mp_int z, mp_int m)
+{
+  mp_size um = MP_USED(m) * 2;
+
+  if (!s_pad(z, um))
+    return MP_MEMORY;
+
+  s_2expt(z, MP_DIGIT_BIT * um);
+  return mp_int_div(z, m, z, NULL);
+}
+
+/* }}} */
+
+/* {{{ s_reduce(x, m, mu, q1, q2) */
+
+STATIC int       s_reduce(mp_int x, mp_int m, mp_int mu, mp_int q1, mp_int q2)
+{
+  mp_size   um = MP_USED(m), umb_p1, umb_m1;
+
+  umb_p1 = (um + 1) * MP_DIGIT_BIT;
+  umb_m1 = (um - 1) * MP_DIGIT_BIT;
+
+  if (mp_int_copy(x, q1) != MP_OK)
+    return 0;
+
+  /* Compute q2 = floor((floor(x / b^(k-1)) * mu) / b^(k+1)) */
+  s_qdiv(q1, umb_m1);
+  UMUL(q1, mu, q2);
+  s_qdiv(q2, umb_p1);
+
+  /* Set x = x mod b^(k+1) */
+  s_qmod(x, umb_p1);
+
+  /* Now, q is a guess for the quotient a / m.
+     Compute x - q * m mod b^(k+1), replacing x.  This may be off
+     by a factor of 2m, but no more than that.
+   */
+  UMUL(q2, m, q1);
+  s_qmod(q1, umb_p1);
+  (void) mp_int_sub(x, q1, x); /* can't fail */
+
+  /* The result may be < 0; if it is, add b^(k+1) to pin it in the proper
+     range. */
+  if ((CMPZ(x) < 0) && !s_qsub(x, umb_p1))
+    return 0;
+
+  /* If x > m, we need to back it off until it is in range.  This will be
+     required at most twice.  */
+  if (mp_int_compare(x, m) >= 0) {
+    (void) mp_int_sub(x, m, x);
+    if (mp_int_compare(x, m) >= 0)
+      (void) mp_int_sub(x, m, x);
+  }
+
+  /* At this point, x has been properly reduced. */
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ s_embar(a, b, m, mu, c) */
+
+/* Perform modular exponentiation using Barrett's method, where mu is the
+   reduction constant for m.  Assumes a < m, b > 0. */
+STATIC mp_result s_embar(mp_int a, mp_int b, mp_int m, mp_int mu, mp_int c)
+{
+  mp_digit  *db, *dbt, umu, d;
+  mp_result res;
+  DECLARE_TEMP(3);
+
+  umu = MP_USED(mu); db = MP_DIGITS(b); dbt = db + MP_USED(b) - 1;
+
+  while (last__ < 3) {
+    SETUP(mp_int_init_size(LAST_TEMP(), 4 * umu));
+    ZERO(MP_DIGITS(TEMP(last__ - 1)), MP_ALLOC(TEMP(last__ - 1)));
+  }
+
+  (void) mp_int_set_value(c, 1);
+
+  /* Take care of low-order digits */
+  while (db < dbt) {
+    int      i;
+
+    for (d = *db, i = MP_DIGIT_BIT; i > 0; --i, d >>= 1) {
+      if (d & 1) {
+	/* The use of a second temporary avoids allocation */
+	UMUL(c, a, TEMP(0));
+	if (!s_reduce(TEMP(0), m, mu, TEMP(1), TEMP(2))) {
+	  res = MP_MEMORY; goto CLEANUP;
+	}
+	mp_int_copy(TEMP(0), c);
+      }
+
+
+      USQR(a, TEMP(0));
+      assert(MP_SIGN(TEMP(0)) == MP_ZPOS);
+      if (!s_reduce(TEMP(0), m, mu, TEMP(1), TEMP(2))) {
+	res = MP_MEMORY; goto CLEANUP;
+      }
+      assert(MP_SIGN(TEMP(0)) == MP_ZPOS);
+      mp_int_copy(TEMP(0), a);
+    }
+
+    ++db;
+  }
+
+  /* Take care of highest-order digit */
+  d = *dbt;
+  for (;;) {
+    if (d & 1) {
+      UMUL(c, a, TEMP(0));
+      if (!s_reduce(TEMP(0), m, mu, TEMP(1), TEMP(2))) {
+	res = MP_MEMORY; goto CLEANUP;
+      }
+      mp_int_copy(TEMP(0), c);
+    }
+
+    d >>= 1;
+    if (!d) break;
+
+    USQR(a, TEMP(0));
+    if (!s_reduce(TEMP(0), m, mu, TEMP(1), TEMP(2))) {
+      res = MP_MEMORY; goto CLEANUP;
+    }
+    (void) mp_int_copy(TEMP(0), a);
+  }
+
+  CLEANUP_TEMP();
+  return res;
+}
+
+/* }}} */
+
+#if 0
+/* {{{ s_udiv(a, b) */
+/* The s_udiv function produces incorrect results. For example, with test
+     div:11141460315522012760862883825:48318382095:0,230584300062375935
+   commenting out the function for now and using s_udiv_knuth instead.
+   STATIC mp_result s_udiv(mp_int a, mp_int b);
+*/
+
+/* Precondition:  a >= b and b > 0
+   Postcondition: a' = a / b, b' = a % b
+ */
+STATIC mp_result s_udiv(mp_int a, mp_int b)
+{
+  mpz_t q, r, t;
+  mp_size ua, ub, qpos = 0;
+  mp_digit *da, btop;
+  mp_result res = MP_OK;
+  int k, skip = 0;
+
+  /* Force signs to positive */
+  MP_SIGN(a) = MP_ZPOS;
+  MP_SIGN(b) = MP_ZPOS;
+
+  /* Normalize, per Knuth */
+  k = s_norm(a, b);
+
+  ua = MP_USED(a); ub = MP_USED(b); btop = b->digits[ub - 1];
+  if ((res = mp_int_init_size(&q, ua)) != MP_OK) return res;
+  if ((res = mp_int_init_size(&t, ua + 1)) != MP_OK) goto CLEANUP;
+
+  da = MP_DIGITS(a);
+  r.digits = da + ua - 1;  /* The contents of r are shared with a */
+  r.used   = 1;
+  r.sign   = MP_ZPOS;
+  r.alloc  = MP_ALLOC(a);
+  ZERO(t.digits, t.alloc);
+
+  /* Solve for quotient digits, store in q.digits in reverse order */
+  while (r.digits >= da) {
+    assert(qpos <= q.alloc);
+
+    if (s_ucmp(b, &r) > 0) {
+      r.digits -= 1;
+      r.used += 1;
+
+      if (++skip > 1 && qpos > 0)
+	q.digits[qpos++] = 0;
+
+      CLAMP(&r);
+    }
+    else {
+      mp_word  pfx = r.digits[r.used - 1];
+      mp_word  qdigit;
+
+      if (r.used > 1 && pfx < btop) {
+	pfx <<= MP_DIGIT_BIT / 2;
+	pfx <<= MP_DIGIT_BIT / 2;
+	pfx |= r.digits[r.used - 2];
+      }
+
+      qdigit = pfx / btop;
+      if (qdigit > MP_DIGIT_MAX) {
+	qdigit = MP_DIGIT_MAX;
+      }
+
+      s_dbmul(MP_DIGITS(b), (mp_digit) qdigit, t.digits, ub);
+      t.used = ub + 1; CLAMP(&t);
+      while (s_ucmp(&t, &r) > 0) {
+	--qdigit;
+	(void) mp_int_sub(&t, b, &t); /* cannot fail */
+      }
+
+      s_usub(r.digits, t.digits, r.digits, r.used, t.used);
+      CLAMP(&r);
+
+      q.digits[qpos++] = (mp_digit) qdigit;
+      ZERO(t.digits, t.used);
+      skip = 0;
+    }
+  }
+
+  /* Put quotient digits in the correct order, and discard extra zeroes */
+  q.used = qpos;
+  REV(mp_digit, q.digits, qpos);
+  CLAMP(&q);
+
+  /* Denormalize the remainder */
+  CLAMP(a);
+  if (k != 0)
+    s_qdiv(a, k);
+
+  mp_int_copy(a, b);  /* ok:  0 <= r < b */
+  mp_int_copy(&q, a); /* ok:  q <= a     */
+
+  mp_int_clear(&t);
+ CLEANUP:
+  mp_int_clear(&q);
+  return res;
+}
+
+/* }}} */
+#endif
+
+/* Division of nonnegative integers
+
+   This function implements division algorithm for unsigned multi-precision
+   integers. The algorithm is based on Algorithm D from Knuth's "The Art of
+   Computer Programming", 3rd ed. 1998, pg 272-273.
+
+   We diverge from Knuth's algorithm in that we do not perform the subtraction
+   from the remainder until we have determined that we have the correct
+   quotient digit. This makes our algorithm less efficient that Knuth because
+   we might have to perform multiple multiplication and comparison steps before
+   the subtraction. The advantage is that it is easy to implement and ensure
+   correctness without worrying about underflow from the subtraction.
+
+   inputs: u   a n+m digit integer in base b (b is 2^MP_DIGIT_BIT)
+           v   a n   digit integer in base b (b is 2^MP_DIGIT_BIT)
+           n >= 1
+           m >= 0
+  outputs: u / v stored in u
+           u % v stored in v
+ */
+STATIC mp_result s_udiv_knuth(mp_int u, mp_int v) {
+  mpz_t q, r, t;
+  mp_result
+  res = MP_OK;
+  int k,j;
+  mp_size m,n;
+
+  /* Force signs to positive */
+  MP_SIGN(u) = MP_ZPOS;
+  MP_SIGN(v) = MP_ZPOS;
+
+  /* Use simple division algorithm when v is only one digit long */
+  if (MP_USED(v) == 1) {
+    mp_digit d, rem;
+    d   = v->digits[0];
+    rem = s_ddiv(u, d);
+    mp_int_set_value(v, rem);
+    return MP_OK;
+  }
+
+  /************************************************************/
+  /* Algorithm D */
+  /************************************************************/
+  /* The n and m variables are defined as used by Knuth.
+     u is an n digit number with digits u_{n-1}..u_0.
+     v is an n+m digit number with digits from v_{m+n-1}..v_0.
+     We require that n > 1 and m >= 0 */
+  n = MP_USED(v);
+  m = MP_USED(u) - n;
+  assert(n >  1);
+  assert(m >= 0);
+
+  /************************************************************/
+  /* D1: Normalize.
+     The normalization step provides the necessary condition for Theorem B,
+     which states that the quotient estimate for q_j, call it qhat
+
+       qhat = u_{j+n}u_{j+n-1} / v_{n-1}
+
+     is bounded by
+
+      qhat - 2 <= q_j <= qhat.
+
+     That is, qhat is always greater than the actual quotient digit q,
+     and it is never more than two larger than the actual quotient digit.  */
+  k = s_norm(u, v);
+
+  /* Extend size of u by one if needed.
+
+     The algorithm begins with a value of u that has one more digit of input.
+     The normalization step sets u_{m+n}..u_0 = 2^k * u_{m+n-1}..u_0. If the
+     multiplication did not increase the number of digits of u, we need to add
+     a leading zero here.
+   */
+  if (k == 0 || MP_USED(u) != m + n + 1) {
+    if (!s_pad(u, m+n+1))
+      return MP_MEMORY;
+    u->digits[m+n] = 0;
+    u->used = m+n+1;
+  }
+
+  /* Add a leading 0 to v.
+
+     The multiplication in step D4 multiplies qhat * 0v_{n-1}..v_0.  We need to
+     add the leading zero to v here to ensure that the multiplication will
+     produce the full n+1 digit result.  */
+  if (!s_pad(v, n+1)) return MP_MEMORY; v->digits[n] = 0;
+
+  /* Initialize temporary variables q and t.
+     q allocates space for m+1 digits to store the quotient digits
+     t allocates space for n+1 digits to hold the result of q_j*v */
+  if ((res = mp_int_init_size(&q, m + 1)) != MP_OK) return res;
+  if ((res = mp_int_init_size(&t, n + 1)) != MP_OK) goto CLEANUP;
+
+  /************************************************************/
+  /* D2: Initialize j */
+  j = m;
+  r.digits = MP_DIGITS(u) + j;  /* The contents of r are shared with u */
+  r.used   = n + 1;
+  r.sign   = MP_ZPOS;
+  r.alloc  = MP_ALLOC(u);
+  ZERO(t.digits, t.alloc);
+
+  /* Calculate the m+1 digits of the quotient result */
+  for (; j >= 0; j--) {
+    /************************************************************/
+    /* D3: Calculate q' */
+    /* r->digits is aligned to position j of the number u */
+    mp_word pfx, qhat;
+    pfx   = r.digits[n];
+    pfx <<= MP_DIGIT_BIT / 2;
+    pfx <<= MP_DIGIT_BIT / 2;
+    pfx |= r.digits[n-1]; /* pfx = u_{j+n}{j+n-1} */
+
+    qhat = pfx / v->digits[n-1];
+    /* Check to see if qhat > b, and decrease qhat if so.
+       Theorem B guarantess that qhat is at most 2 larger than the
+       actual value, so it is possible that qhat is greater than
+       the maximum value that will fit in a digit */
+    if (qhat > MP_DIGIT_MAX)
+      qhat = MP_DIGIT_MAX;
+
+    /************************************************************/
+    /* D4,D5,D6: Multiply qhat * v and test for a correct value of q
+
+       We proceed a bit different than the way described by Knuth. This way is
+       simpler but less efficent. Instead of doing the multiply and subtract
+       then checking for underflow, we first do the multiply of qhat * v and
+       see if it is larger than the current remainder r. If it is larger, we
+       decrease qhat by one and try again. We may need to decrease qhat one
+       more time before we get a value that is smaller than r.
+
+       This way is less efficent than Knuth becuase we do more multiplies, but
+       we do not need to worry about underflow this way.  */
+    /* t = qhat * v */
+    s_dbmul(MP_DIGITS(v), (mp_digit) qhat, t.digits, n+1); t.used = n + 1;
+    CLAMP(&t);
+
+    /* Clamp r for the comparison. Comparisons do not like leading zeros. */
+    CLAMP(&r);
+    if (s_ucmp(&t, &r) > 0) {   /* would the remainder be negative? */
+      qhat -= 1;   /* try a smaller q */
+      s_dbmul(MP_DIGITS(v), (mp_digit) qhat, t.digits, n+1);
+      t.used = n + 1; CLAMP(&t);
+      if (s_ucmp(&t, &r) > 0) { /* would the remainder be negative? */
+        assert(qhat > 0);
+        qhat -= 1; /* try a smaller q */
+        s_dbmul(MP_DIGITS(v), (mp_digit) qhat, t.digits, n+1);
+        t.used = n + 1; CLAMP(&t);
+      }
+      assert(s_ucmp(&t, &r) <=  0 && "The mathematics failed us.");
+    }
+    /* Unclamp r. The D algorithm expects r = u_{j+n}..u_j to always be n+1
+       digits long. */
+    r.used = n + 1;
+
+    /************************************************************/
+    /* D4: Multiply and subtract */
+    /* note: The multiply was completed above so we only need to subtract here.
+     **/
+    s_usub(r.digits, t.digits, r.digits, r.used, t.used);
+
+    /************************************************************/
+    /* D5: Test remainder */
+    /* note: Not needed because we always check that qhat is the correct value
+     *       before performing the subtract. */
+    q.digits[j] = qhat;
+
+    /************************************************************/
+    /* D6: Add back */
+    /* note: Not needed because we always check that qhat is the correct value
+     *       before performing the subtract. */
+
+    /************************************************************/
+    /* D7: Loop on j */
+    r.digits--;
+    ZERO(t.digits, t.alloc);
+  }
+
+  /* Get rid of leading zeros in q */
+  q.used = m + 1;
+  CLAMP(&q);
+
+  /* Denormalize the remainder */
+  CLAMP(u); /* use u here because the r.digits pointer is off-by-one */
+  if (k != 0)
+    s_qdiv(u, k);
+
+  mp_int_copy(u, v);  /* ok:  0 <= r < v */
+  mp_int_copy(&q, u); /* ok:  q <= u     */
+
+  mp_int_clear(&t);
+ CLEANUP:
+  mp_int_clear(&q);
+  return res;
+}
+
+/* {{{ s_outlen(z, r) */
+
+STATIC int       s_outlen(mp_int z, mp_size r)
+{
+  mp_result bits;
+  double raw;
+
+  assert(r >= MP_MIN_RADIX && r <= MP_MAX_RADIX);
+
+  bits = mp_int_count_bits(z);
+  raw = (double)bits * s_log2[r];
+
+  return (int)(raw + 0.999999);
+}
+
+/* }}} */
+
+/* {{{ s_inlen(len, r) */
+
+STATIC mp_size   s_inlen(int len, mp_size r)
+{
+  double  raw = (double)len / s_log2[r];
+  mp_size bits = (mp_size)(raw + 0.5);
+
+  return (mp_size)((bits + (MP_DIGIT_BIT - 1)) / MP_DIGIT_BIT) + 1;
+}
+
+/* }}} */
+
+/* {{{ s_ch2val(c, r) */
+
+STATIC int       s_ch2val(char c, int r)
+{
+  int out;
+
+  if (isdigit((unsigned char) c))
+    out = c - '0';
+  else if (r > 10 && isalpha((unsigned char) c))
+    out = toupper(c) - 'A' + 10;
+  else
+    return -1;
+
+  return (out >= r) ? -1 : out;
+}
+
+/* }}} */
+
+/* {{{ s_val2ch(v, caps) */
+
+STATIC char      s_val2ch(int v, int caps)
+{
+  assert(v >= 0);
+
+  if (v < 10)
+    return v + '0';
+  else {
+    char out = (v - 10) + 'a';
+
+    if (caps)
+      return toupper(out);
+    else
+      return out;
+  }
+}
+
+/* }}} */
+
+/* {{{ s_2comp(buf, len) */
+
+STATIC void      s_2comp(unsigned char *buf, int len)
+{
+  int i;
+  unsigned short s = 1;
+
+  for (i = len - 1; i >= 0; --i) {
+    unsigned char c = ~buf[i];
+
+    s = c + s;
+    c = s & UCHAR_MAX;
+    s >>= CHAR_BIT;
+
+    buf[i] = c;
+  }
+
+  /* last carry out is ignored */
+}
+
+/* }}} */
+
+/* {{{ s_tobin(z, buf, *limpos) */
+
+STATIC mp_result s_tobin(mp_int z, unsigned char *buf, int *limpos, int pad)
+{
+  mp_size uz;
+  mp_digit *dz;
+  int pos = 0, limit = *limpos;
+
+  uz = MP_USED(z); dz = MP_DIGITS(z);
+  while (uz > 0 && pos < limit) {
+    mp_digit d = *dz++;
+    int i;
+
+    for (i = sizeof(mp_digit); i > 0 && pos < limit; --i) {
+      buf[pos++] = (unsigned char)d;
+      d >>= CHAR_BIT;
+
+      /* Don't write leading zeroes */
+      if (d == 0 && uz == 1)
+	i = 0; /* exit loop without signaling truncation */
+    }
+
+    /* Detect truncation (loop exited with pos >= limit) */
+    if (i > 0) break;
+
+    --uz;
+  }
+
+  if (pad != 0 && (buf[pos - 1] >> (CHAR_BIT - 1))) {
+    if (pos < limit)
+      buf[pos++] = 0;
+    else
+      uz = 1;
+  }
+
+  /* Digits are in reverse order, fix that */
+  REV(unsigned char, buf, pos);
+
+  /* Return the number of bytes actually written */
+  *limpos = pos;
+
+  return (uz == 0) ? MP_OK : MP_TRUNC;
+}
+
+/* }}} */
+
+/* {{{ s_print(tag, z) */
+
+#if DEBUG
+void      s_print(char *tag, mp_int z)
+{
+  int  i;
+
+  fprintf(stderr, "%s: %c ", tag,
+	  (MP_SIGN(z) == MP_NEG) ? '-' : '+');
+
+  for (i = MP_USED(z) - 1; i >= 0; --i)
+    fprintf(stderr, "%0*X", (int)(MP_DIGIT_BIT / 4), z->digits[i]);
+
+  fputc('\n', stderr);
+
+}
+
+void      s_print_buf(char *tag, mp_digit *buf, mp_size num)
+{
+  int i;
+
+  fprintf(stderr, "%s: ", tag);
+
+  for (i = num - 1; i >= 0; --i)
+    fprintf(stderr, "%0*X", (int)(MP_DIGIT_BIT / 4), buf[i]);
+
+  fputc('\n', stderr);
+}
+#endif
+
+/* }}} */
+
+/* Here there be dragons */

Added: polly/trunk/lib/External/isl/imath/imath.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/imath.h?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/imath.h (added)
+++ polly/trunk/lib/External/isl/imath/imath.h Wed Feb  4 14:55:43 2015
@@ -0,0 +1,232 @@
+/*
+  Name:     imath.h
+  Purpose:  Arbitrary precision integer arithmetic routines.
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  Copyright (C) 2002-2007 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#ifndef IMATH_H_
+#define IMATH_H_
+
+#include <stdint.h>
+#include <limits.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef unsigned char      mp_sign;
+typedef unsigned int       mp_size;
+typedef int                mp_result;
+typedef long               mp_small;  /* must be a signed type */
+typedef unsigned long      mp_usmall; /* must be an unsigned type */
+
+/* Force building with uint64_t so that the library builds consistently
+ * whether we build from the makefile or by embedding imath in another project.
+ */
+#undef  USE_64BIT_WORDS
+#define USE_64BIT_WORDS
+#ifdef  USE_64BIT_WORDS
+typedef uint32_t           mp_digit;
+typedef uint64_t           mp_word;
+#else
+typedef uint16_t           mp_digit;
+typedef uint32_t           mp_word;
+#endif
+
+typedef struct mpz {
+  mp_digit    single;
+  mp_digit   *digits;
+  mp_size     alloc;
+  mp_size     used;
+  mp_sign     sign;
+} mpz_t, *mp_int;
+
+#define MP_DIGITS(Z) ((Z)->digits)
+#define MP_ALLOC(Z)  ((Z)->alloc)
+#define MP_USED(Z)   ((Z)->used)
+#define MP_SIGN(Z)   ((Z)->sign)
+
+extern const mp_result MP_OK;
+extern const mp_result MP_FALSE;
+extern const mp_result MP_TRUE;
+extern const mp_result MP_MEMORY;
+extern const mp_result MP_RANGE;
+extern const mp_result MP_UNDEF;
+extern const mp_result MP_TRUNC;
+extern const mp_result MP_BADARG;
+extern const mp_result MP_MINERR;
+
+#define MP_DIGIT_BIT    (sizeof(mp_digit) * CHAR_BIT)
+#define MP_WORD_BIT     (sizeof(mp_word) * CHAR_BIT)
+#define MP_SMALL_MIN    LONG_MIN
+#define MP_SMALL_MAX    LONG_MAX
+#define MP_USMALL_MIN   ULONG_MIN
+#define MP_USMALL_MAX   ULONG_MAX
+
+#ifdef USE_64BIT_WORDS
+#  define MP_DIGIT_MAX   (UINT32_MAX * UINT64_C(1))
+#  define MP_WORD_MAX    (UINT64_MAX)
+#else
+#  define MP_DIGIT_MAX   (UINT16_MAX * 1UL)
+#  define MP_WORD_MAX    (UINT32_MAX * 1UL)
+#endif
+
+#define MP_MIN_RADIX    2
+#define MP_MAX_RADIX    36
+
+/* Values with fewer than this many significant digits use the standard
+   multiplication algorithm; otherwise, a recursive algorithm is used.  
+   Choose a value to suit your platform.
+ */
+#define MP_MULT_THRESH  22
+
+#define MP_DEFAULT_PREC 8   /* default memory allocation, in digits */
+
+extern const mp_sign   MP_NEG;
+extern const mp_sign   MP_ZPOS;
+
+#define mp_int_is_odd(Z)  ((Z)->digits[0] & 1)
+#define mp_int_is_even(Z) !((Z)->digits[0] & 1)
+
+mp_result mp_int_init(mp_int z);
+mp_int    mp_int_alloc(void);
+mp_result mp_int_init_size(mp_int z, mp_size prec);
+mp_result mp_int_init_copy(mp_int z, mp_int old);
+mp_result mp_int_init_value(mp_int z, mp_small value);
+mp_result mp_int_init_uvalue(mp_int z, mp_usmall uvalue);
+mp_result mp_int_set_value(mp_int z, mp_small value);
+mp_result mp_int_set_uvalue(mp_int z, mp_usmall uvalue);
+void      mp_int_clear(mp_int z);
+void      mp_int_free(mp_int z);
+
+mp_result mp_int_copy(mp_int a, mp_int c);           /* c = a     */
+void      mp_int_swap(mp_int a, mp_int c);           /* swap a, c */
+void      mp_int_zero(mp_int z);                     /* z = 0     */
+mp_result mp_int_abs(mp_int a, mp_int c);            /* c = |a|   */
+mp_result mp_int_neg(mp_int a, mp_int c);            /* c = -a    */
+mp_result mp_int_add(mp_int a, mp_int b, mp_int c);  /* c = a + b */
+mp_result mp_int_add_value(mp_int a, mp_small value, mp_int c);
+mp_result mp_int_sub(mp_int a, mp_int b, mp_int c);  /* c = a - b */
+mp_result mp_int_sub_value(mp_int a, mp_small value, mp_int c);
+mp_result mp_int_mul(mp_int a, mp_int b, mp_int c);  /* c = a * b */
+mp_result mp_int_mul_value(mp_int a, mp_small value, mp_int c);
+mp_result mp_int_mul_pow2(mp_int a, mp_small p2, mp_int c);
+mp_result mp_int_sqr(mp_int a, mp_int c);            /* c = a * a */
+mp_result mp_int_div(mp_int a, mp_int b,             /* q = a / b */
+		     mp_int q, mp_int r);            /* r = a % b */
+mp_result mp_int_div_value(mp_int a, mp_small value, /* q = a / value */
+			   mp_int q, mp_small *r);   /* r = a % value */
+mp_result mp_int_div_pow2(mp_int a, mp_small p2,     /* q = a / 2^p2  */
+			  mp_int q, mp_int r);       /* r = q % 2^p2  */
+mp_result mp_int_mod(mp_int a, mp_int m, mp_int c);  /* c = a % m */
+#define   mp_int_mod_value(A, V, R) mp_int_div_value((A), (V), 0, (R))
+mp_result mp_int_expt(mp_int a, mp_small b, mp_int c);         /* c = a^b */
+mp_result mp_int_expt_value(mp_small a, mp_small b, mp_int c); /* c = a^b */
+mp_result mp_int_expt_full(mp_int a, mp_int b, mp_int c);      /* c = a^b */
+
+int       mp_int_compare(mp_int a, mp_int b);          /* a <=> b     */
+int       mp_int_compare_unsigned(mp_int a, mp_int b); /* |a| <=> |b| */
+int       mp_int_compare_zero(mp_int z);                 /* a <=> 0  */
+int       mp_int_compare_value(mp_int z, mp_small v);    /* a <=> v  */
+int       mp_int_compare_uvalue(mp_int z, mp_usmall uv); /* a <=> uv */
+
+/* Returns true if v|a, false otherwise (including errors) */
+int       mp_int_divisible_value(mp_int a, mp_small v);
+
+/* Returns k >= 0 such that z = 2^k, if one exists; otherwise < 0 */
+int       mp_int_is_pow2(mp_int z);
+
+mp_result mp_int_exptmod(mp_int a, mp_int b, mp_int m,
+			 mp_int c);                    /* c = a^b (mod m) */
+mp_result mp_int_exptmod_evalue(mp_int a, mp_small value,
+				mp_int m, mp_int c);   /* c = a^v (mod m) */
+mp_result mp_int_exptmod_bvalue(mp_small value, mp_int b,
+				mp_int m, mp_int c);   /* c = v^b (mod m) */
+mp_result mp_int_exptmod_known(mp_int a, mp_int b,
+			       mp_int m, mp_int mu,
+			       mp_int c);              /* c = a^b (mod m) */
+mp_result mp_int_redux_const(mp_int m, mp_int c);
+
+mp_result mp_int_invmod(mp_int a, mp_int m, mp_int c); /* c = 1/a (mod m) */
+
+mp_result mp_int_gcd(mp_int a, mp_int b, mp_int c);    /* c = gcd(a, b)   */
+
+mp_result mp_int_egcd(mp_int a, mp_int b, mp_int c,    /* c = gcd(a, b)   */
+		      mp_int x, mp_int y);             /* c = ax + by     */
+
+mp_result mp_int_lcm(mp_int a, mp_int b, mp_int c);    /* c = lcm(a, b)   */
+
+mp_result mp_int_root(mp_int a, mp_small b, mp_int c); /* c = floor(a^{1/b}) */
+#define   mp_int_sqrt(a, c) mp_int_root(a, 2, c)       /* c = floor(sqrt(a)) */
+
+/* Convert to a small int, if representable; else MP_RANGE */
+mp_result mp_int_to_int(mp_int z, mp_small *out);
+mp_result mp_int_to_uint(mp_int z, mp_usmall *out);
+
+/* Convert to nul-terminated string with the specified radix, writing at
+   most limit characters including the nul terminator  */
+mp_result mp_int_to_string(mp_int z, mp_size radix,
+			   char *str, int limit);
+
+/* Return the number of characters required to represent
+   z in the given radix.  May over-estimate. */
+mp_result mp_int_string_len(mp_int z, mp_size radix);
+
+/* Read zero-terminated string into z */
+mp_result mp_int_read_string(mp_int z, mp_size radix, const char *str);
+mp_result mp_int_read_cstring(mp_int z, mp_size radix, const char *str,
+			      char **end);
+
+/* Return the number of significant bits in z */
+mp_result mp_int_count_bits(mp_int z);
+
+/* Convert z to two's complement binary, writing at most limit bytes */
+mp_result mp_int_to_binary(mp_int z, unsigned char *buf, int limit);
+
+/* Read a two's complement binary value into z from the given buffer */
+mp_result mp_int_read_binary(mp_int z, unsigned char *buf, int len);
+
+/* Return the number of bytes required to represent z in binary. */
+mp_result mp_int_binary_len(mp_int z);
+
+/* Convert z to unsigned binary, writing at most limit bytes */
+mp_result mp_int_to_unsigned(mp_int z, unsigned char *buf, int limit);
+
+/* Read an unsigned binary value into z from the given buffer */
+mp_result mp_int_read_unsigned(mp_int z, unsigned char *buf, int len);
+
+/* Return the number of bytes required to represent z as unsigned output */
+mp_result mp_int_unsigned_len(mp_int z);
+
+/* Return a statically allocated string describing error code res */
+const char *mp_error_string(mp_result res);
+
+#if DEBUG
+void      s_print(char *tag, mp_int z);
+void      s_print_buf(char *tag, mp_digit *buf, mp_size num);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* end IMATH_H_ */

Added: polly/trunk/lib/External/isl/imath/imdrover.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/imdrover.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/imdrover.c (added)
+++ polly/trunk/lib/External/isl/imath/imdrover.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,1780 @@
+/*
+  Name:     imdrover.c
+  Purpose:  Keeper of the hordes of testing code.
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  Copyright (C) 2002-2007 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <assert.h>
+
+#include "imdrover.h"
+#include "imath.h"
+#include "imrat.h"
+
+/* Globals visible from outside this file */
+mp_result imath_errno;
+char     *imath_errmsg;
+
+/* Set imath_errno and return failure from a test. */
+#define FAIL(E) return (imath_errno = (E), 0)
+
+/* Check that an expression X yields the expected mp_result value V. */
+#define VCHECK(X, V)         \
+do {                         \
+  mp_result res_;            \
+  if ((res_ = (X)) != (V)) { \
+    FAIL(res_);              \
+  }                          \
+} while(0)
+#define CHECK(X) VCHECK(X, MP_OK)
+#define ECHECK(X) VCHECK(X, expect)
+#define ACHECK(X)    \
+do {                 \
+  if (!(X)) {        \
+    FAIL(MP_BADARG); \
+  }                  \
+} while(0)
+
+#define OUTPUT_LIMIT 2048
+#define NUM_REGS     16
+#define OTHER_ERROR  -1024
+
+static char g_output[OUTPUT_LIMIT];
+static mpz_t g_zreg[NUM_REGS];
+static mpq_t g_qreg[NUM_REGS];
+static unsigned char g_bin1[OUTPUT_LIMIT];
+static unsigned char g_bin2[OUTPUT_LIMIT];
+
+extern void trim_line(char *line); /* borrowed from imtest.c */
+
+/* Read in a string with radix tags */
+static mp_result read_int_value(mp_int z, char *str);
+static mp_result read_rat_value(mp_rat q, char *str);
+
+/* Read in a string with radix tags, as a long (not an mp_int) */
+static int read_long(long *z, char *str);
+
+/* Parse the input and output values and fill in pointers to the
+   registers containing them.  Returns true if all is well, false
+   in case of error.  Caller allocates in/out to correct sizes. */
+static int parse_int_values(testspec_t* t, mp_int *in, mp_int *out,
+			    mp_result *rval);
+static int parse_rat_values(testspec_t* t, mp_rat *in, mp_rat *out,
+			    mp_result *rval);
+
+/* Parse a result code name and return the corresponding result
+   code */
+static int parse_result_code(char *str, mp_result *code);
+
+/* Read in a dot-delimited binary sequence to the given buffer, and
+   return the number of bytes read.  Returns < 0 in case of a syntax
+   error.  Records no more than limit bytes. */
+static int parse_binary(char *str, unsigned char *buf, int limit);
+
+/* Clean up registers (called from atexit()) */
+static void done_testing(void);
+
+/*------------------------------------------------------------------------*/
+/* Utility subroutines for writing tests (explained above)                */
+
+/* {{{ read_int_value(z, str) */
+
+static mp_result read_int_value(mp_int z, char *str)
+{
+  int radix = 10;
+
+  if(*str == '#') {
+    ++str;
+    switch(*str) {
+    case 'x': case 'X':
+      radix = 16;
+      break;
+    case 'd': case 'D':
+      radix = 10;
+      break;
+    case 'o': case 'O':
+      radix = 8;
+      break;
+    case 'b': case 'B':
+      radix = 2;
+      break;
+    default:
+      return MP_RANGE;
+    }
+    ++str;
+  }
+
+  return mp_int_read_string(z, radix, str);
+}
+
+/* }}} */
+
+/* {{{ read_rat_value(q, str) */
+
+static mp_result read_rat_value(mp_rat q, char *str)
+{
+  int radix = 10;
+
+  if(*str == '#') {
+    ++str;
+    switch(*str) {
+    case 'x': case 'X':
+      radix = 16;
+      break;
+    case 'd': case 'D':
+      radix = 10;
+      break;
+    case 'o': case 'O':
+      radix = 8;
+      break;
+    case 'b': case 'B':
+      radix = 2;
+      break;
+    default:
+      return MP_RANGE;
+    }
+    ++str;
+  }
+
+  if(*str == '@')
+    return mp_rat_read_decimal(q, radix, str + 1);
+  else
+    return mp_rat_read_string(q, radix, str);
+}
+
+/* }}} */
+
+/* {{{ read_long(z, str) */
+
+static int read_long(long *z, char *str)
+{
+  char *end;
+  int radix = 10;
+
+  if (*str == '#') {
+    ++str;
+    switch (*str) {
+    case 'x': case 'X':
+      radix = 16;
+      break;
+    case 'd': case 'D':
+      radix = 10;
+      break;
+    case 'o': case 'O':
+      radix = 8;
+      break;
+    case 'b': case 'B':
+      radix = 2;
+      break;
+    default:
+      return 0;
+    }
+    ++str;
+  }
+
+  *z = strtol(str, &end, radix);
+  return (end != str && *end == '\0');
+}
+
+/* }}} */
+
+/* {{{ parse_int_values(t, in, out) */
+
+static int parse_int_values(testspec_t* t, mp_int* in, mp_int* out,
+			    mp_result* rval)
+{
+  int i, pos = 0;
+  char *str;
+
+  if (rval != NULL)
+    *rval = MP_OK;  /* default */
+
+  if (in != NULL) {
+    for (i = 0; i < t->num_inputs; ++i) {
+      str = t->input[i];
+
+      trim_line(str);
+
+      if (*str == '=') {
+	int k = abs(atoi(str + 1)) - 1;
+
+	if (k < 0 || k >= i) {
+	  fprintf(stderr, "Line %d: Invalid input back-reference [%s]\n",
+		  t->line, str);
+	  return 0;
+	}
+
+	in[i] = in[k];
+      } 
+      else {
+	mp_int reg = g_zreg + pos++; /* grab next free register */
+
+	if (read_int_value(reg, str) != MP_OK) {
+	  fprintf(stderr, "Line %d: Invalid input value [%s]\n",
+		  t->line, str);
+	  return 0;
+	}
+
+	in[i] = reg;
+      }
+    }
+  }
+
+  for (i = 0; i < t->num_outputs; ++i) {
+    mp_int reg = g_zreg + pos++;
+
+    str = t->output[i];
+
+    trim_line(str);
+
+    if (strcmp(str, "?") == 0)
+      mp_int_zero(reg);
+    else if (*str == '$') {
+      mp_result code;
+
+      if (!parse_result_code(str, &code)) {
+	fprintf(stderr, "Line %d: Invalid result code [%s]\n",
+		t->line, str);
+	return 0;
+      }
+      else if(rval == NULL) {
+	fprintf(stderr, "Line %d: Result code not permitted here [%s]\n",
+		t->line, str);
+	return 0;
+      }
+      else
+	*rval = code;
+
+      /* Provide a dummy value for the corresponding output */
+      mp_int_zero(reg);
+    }
+    else if (out != NULL && read_int_value(reg, str) != MP_OK) {
+      fprintf(stderr, "Line %d: Invalid output value [%s]\n",
+	      t->line, str);
+      return 0;
+    }
+
+    if (out != NULL)
+      out[i] = reg;
+  }
+
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ parse_rat_values(t, in, out) */
+
+static int parse_rat_values(testspec_t* t, mp_rat *in, mp_rat *out,
+			    mp_result *rval)
+{
+  int i, pos = 0;
+  char *str;
+
+  if (rval != NULL)
+    *rval = MP_OK;  /* default */
+
+  if (in != NULL) {
+    for (i = 0; i < t->num_inputs; ++i) {
+      str = t->input[i];
+
+      trim_line(str);
+
+      if (*str == '=') {
+	int k = abs(atoi(str + 1)) - 1;
+
+	if (k < 0 || k >= i) {
+	  fprintf(stderr, "Line %d: Invalid input back-reference [%s]\n",
+		  t->line, str);
+	  return 0;
+	}
+
+	in[i] = in[k];
+      } 
+      else {
+	mp_rat reg = g_qreg + pos++; /* grab next free register */
+
+	if (read_rat_value(reg, str) != MP_OK) {
+	  fprintf(stderr, "Line %d: Invalid input value [%s]\n",
+		  t->line, str);
+	  return 0;
+	}
+
+	in[i] = reg;
+      }
+    }
+  }
+
+  for (i = 0; i < t->num_outputs; ++i) {
+    mp_rat reg = g_qreg + pos++;
+
+    str = t->output[i];
+
+    trim_line(str);
+
+    if (strcmp(str, "?") == 0)
+      mp_rat_zero(reg);
+    else if (*str == '$') {
+      mp_result code;
+
+      if (!parse_result_code(str, &code)) {
+	fprintf(stderr, "Line %d: Invalid result code [%s]\n",
+		t->line, str);
+	return 0;
+      }
+      else if (rval == NULL) {
+	fprintf(stderr, "Line %d: Result code not permitted here [%s]\n",
+		t->line, str);
+	return 0;
+      }
+      else
+	*rval = code;
+
+      /* Provide a dummy value for the corresponding output */
+      mp_rat_zero(reg);
+    }
+    else if (out != NULL && read_rat_value(reg, str) != MP_OK) {
+      fprintf(stderr, "Line %d: Invalid output value [%s]\n",
+	      t->line, str);
+      return 0;
+    }
+
+    if (out != NULL)
+      out[i] = reg;
+  }
+
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ parse_result_code(str, *code) */
+
+static int parse_result_code(char *str, mp_result *code)
+{
+  if (str[0] == '$') {
+    if (str[1] == '#') {
+      long v;
+
+      if (!read_long(&v, str + 2))
+	return 0;
+
+      *code = (mp_result) v;
+    }
+    else if (strcmp(str + 1, "MP_OK") == 0 ||
+	    strcmp(str + 1, "MP_FALSE") == 0)
+      *code = MP_OK;
+    else if (strcmp(str + 1, "MP_TRUE") == 0)
+      *code = MP_TRUE;
+    else if (strcmp(str + 1, "MP_MEMORY") == 0)
+      *code = MP_MEMORY;
+    else if (strcmp(str + 1, "MP_RANGE") == 0)
+      *code = MP_RANGE;
+    else if (strcmp(str + 1, "MP_UNDEF") == 0)
+      *code = MP_UNDEF;
+    else if (strcmp(str + 1, "MP_TRUNC") == 0)
+      *code = MP_TRUNC;
+    else if (strcmp(str + 1, "MP_ROUND_UP") == 0)
+      *code = MP_ROUND_UP;
+    else if (strcmp(str + 1, "MP_ROUND_DOWN") == 0)
+      *code = MP_ROUND_DOWN;
+    else if (strcmp(str + 1, "MP_ROUND_HALF_UP") == 0)
+      *code = MP_ROUND_HALF_UP;
+    else if (strcmp(str + 1, "MP_ROUND_HALF_DOWN") == 0)
+      *code = MP_ROUND_HALF_DOWN;
+    else
+      return 0;
+  }
+
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ parse_binary(str, buf, limit) */
+
+static int parse_binary(char *str, unsigned char *buf, int limit)
+{
+  int pos = 0;
+  char *tok;
+
+  trim_line(str);
+
+  for (tok = strtok(str, ".");
+       tok != NULL && pos < limit;
+       tok = strtok(NULL, ".")) {
+    long v;
+
+    if (!read_long(&v, tok) || v > UCHAR_MAX || v < 0)
+      return -1;
+
+    buf[pos++] = (unsigned char)v;
+  }
+
+  return pos;
+}
+
+/* }}} */
+
+/* {{{ done_testing() */
+
+static void done_testing(void)
+{
+  int i;
+
+  for (i = 0; i < NUM_REGS; ++i) {
+    mp_int_clear(g_zreg + i);
+    mp_rat_clear(g_qreg + i);
+  }
+}
+
+/* }}} */
+
+/*------------------------------------------------------------------------*/
+/* Global functions visible to callers outside this file                  */
+
+/* {{{ init_testing() */
+
+void init_testing(void)
+{
+  static int is_done = 0;
+  int i;
+
+  if (is_done)
+    return;
+
+  for (i = 0; i < NUM_REGS; ++i) {
+    assert(mp_int_init(g_zreg + i) == MP_OK);
+    assert(mp_rat_init(g_qreg + i) == MP_OK);
+  }
+
+  imath_errmsg = g_output;
+
+  assert(atexit(done_testing) == 0);
+  is_done = 1;
+}
+
+/* }}} */
+
+/* {{{ reset_registers() */
+
+void reset_registers(void)
+{
+  int i;
+
+  for (i = 0; i < NUM_REGS; ++i) {
+    mp_int_zero(g_zreg + i);
+    mp_rat_zero(g_qreg + i);
+  }
+}
+
+/* }}} */
+
+int test_init(testspec_t* t, FILE* ofp)
+{
+  mp_int in[2], out[1];
+  mp_small   v;
+  mp_usmall uv;
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+
+  if (strcmp(t->code, "initu") == 0) {
+    CHECK(mp_int_to_uint(in[1], &uv));
+    ECHECK(mp_int_init_uvalue(in[0], uv));
+  }
+  else { /* initv */
+    CHECK(mp_int_to_int(in[1], &v));
+    ECHECK(mp_int_init_value(in[0], v));
+  }
+
+
+  if (expect == MP_OK && mp_int_compare(in[0], out[0]) != 0) {
+    mp_int_to_string(in[0], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+
+  return 1;
+}
+
+int test_set(testspec_t* t, FILE* ofp)
+{
+  mp_int in[2], out[1];
+  mp_small   v;
+  mp_usmall uv;
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+
+  if (strcmp(t->code, "setu") == 0) {
+    CHECK(mp_int_to_uint(in[1], &uv));
+    ECHECK(mp_int_set_uvalue(in[0], uv));
+  }
+  else { /* setv */
+    CHECK(mp_int_to_int(in[1], &v));
+    ECHECK(mp_int_set_value(in[0], v));
+  }
+
+  if (expect == MP_OK && mp_int_compare(in[0], out[0]) != 0) {
+    mp_int_to_string(in[0], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+
+  return 1;
+}
+
+/* {{{ test_neg(t, ofp) */
+
+int test_neg(testspec_t* t, FILE* ofp)
+{
+  mp_int in[2], out[1];
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  ECHECK(mp_int_neg(in[0], in[1]));
+
+  if (expect == MP_OK && mp_int_compare(in[1], out[0]) != 0) {
+    mp_int_to_string(in[1], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_abs(t, ofp) */
+
+int test_abs(testspec_t* t, FILE* ofp)
+{
+  mp_int in[2], out[1];
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  ECHECK(mp_int_abs(in[0], in[1]));
+
+  if (expect == MP_OK && mp_int_compare(in[1], out[0]) != 0) {
+    mp_int_to_string(in[1], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_add(t, ofp) */
+
+int test_add(testspec_t* t, FILE* ofp)
+{
+  mp_int in[3], out[1];
+  mp_small v;
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+
+  if (strcmp(t->code, "addv") == 0) {
+    CHECK(mp_int_to_int(in[1], &v));
+    ECHECK(mp_int_add_value(in[0], v, in[2]));
+  } 
+  else {
+    ECHECK(mp_int_add(in[0], in[1], in[2]));
+  }
+
+  if (expect == MP_OK && mp_int_compare(in[2], out[0]) != 0) {
+    mp_int_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_sub(t, ofp) */
+
+int test_sub(testspec_t* t, FILE* ofp)
+{
+  mp_int in[3], out[1];
+  mp_small v;
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+
+  if (strcmp(t->code, "subv") == 0) {
+    CHECK(mp_int_to_int(in[1], &v));
+    ECHECK(mp_int_sub_value(in[0], v, in[2]));
+  } 
+  else {
+    ECHECK(mp_int_sub(in[0], in[1], in[2]));
+  }
+
+  if (expect == MP_OK && mp_int_compare(in[2], out[0]) != 0) {
+    mp_int_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_mul(t, ofp) */
+
+int test_mul(testspec_t* t, FILE* ofp)
+{
+  mp_int in[3], out[1];
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  ECHECK(mp_int_mul(in[0], in[1], in[2]));
+
+  if(expect == MP_OK && mp_int_compare(in[2], out[0]) != 0) {
+    mp_int_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_mulp2(t, ofp) */
+
+int test_mulp2(testspec_t* t, FILE* ofp)
+{
+  mp_int in[3], out[1];
+  mp_result expect;
+  mp_small p2;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  CHECK(mp_int_to_int(in[1], &p2));
+  ECHECK(mp_int_mul_pow2(in[0], p2, in[2]));
+
+  if(expect == MP_OK && mp_int_compare(in[2], out[0]) != 0) {
+    mp_int_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_mulv(t, ofp) */
+
+int test_mulv(testspec_t* t, FILE* ofp)
+{
+  mp_int in[3], out[1];
+  mp_result expect;
+  mp_small v;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  CHECK(mp_int_to_int(in[1], &v));
+  ECHECK(mp_int_mul_value(in[0], v, in[2]));
+
+  if(expect == MP_OK && mp_int_compare(in[2], out[0]) != 0) {
+    mp_int_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_sqr(t, ofp) */
+
+int test_sqr(testspec_t* t, FILE* ofp)
+{
+  mp_int in[2], out[1];
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  ECHECK(mp_int_sqr(in[0], in[1]));
+
+  if(expect == MP_OK && mp_int_compare(in[1], out[0]) != 0) {
+    mp_int_to_string(in[1], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_div(t, ofp) */
+
+int test_div(testspec_t* t, FILE* ofp)
+{
+  mp_int in[4], out[2];
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  ECHECK(mp_int_div(in[0], in[1], in[2], in[3]));
+
+  if (expect == MP_OK &&
+      ((mp_int_compare(in[2], out[0]) != 0) ||
+       (mp_int_compare(in[3], out[1]) != 0))) {
+    int len;
+    char *str;
+
+    mp_int_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    str = g_output + (len = strlen(g_output));
+    *str++ = ',';
+    mp_int_to_string(in[3], 10, str, OUTPUT_LIMIT - (len + 1));
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_divp2(t, ofp) */
+
+int test_divp2(testspec_t* t, FILE* ofp)
+{
+  mp_int in[4], out[2];
+  mp_result expect;
+  mp_small p2;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  CHECK(mp_int_to_int(in[1], &p2));
+  ECHECK(mp_int_div_pow2(in[0], p2, in[2], in[3]));
+
+  if (expect == MP_OK &&
+      ((mp_int_compare(in[2], out[0]) != 0) ||
+       (mp_int_compare(in[3], out[1]) != 0))) {
+    int len;
+    char *str;
+
+    mp_int_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    str = g_output + (len = strlen(g_output));
+    *str++ = ',';
+    mp_int_to_string(in[3], 10, str, OUTPUT_LIMIT - (len + 1));
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_divv(t, ofp) */
+
+int test_divv(testspec_t* t, FILE* ofp)
+{
+  mp_int in[3], out[2];
+  mp_result expect;
+  mp_small v, rem, orem;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  CHECK(mp_int_to_int(in[1], &v));
+  CHECK(mp_int_to_int(out[1], &orem));
+  ECHECK(mp_int_div_value(in[0], v, in[2], &rem));
+
+  if (expect == MP_OK &&
+      ((mp_int_compare(in[2], out[0]) != 0) || (rem != orem))) {
+    char *str;
+
+    mp_int_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    str = g_output + strlen(g_output);
+    *str++ = ',';
+    sprintf(str, "%ld", rem);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_expt(t, ofp) */
+
+int test_expt(testspec_t* t, FILE* ofp)
+{
+  mp_int in[3], out[1];
+  mp_result expect;
+  mp_small  pow;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  CHECK(mp_int_to_int(in[1], &pow));
+  ECHECK(mp_int_expt(in[0], pow, in[2]));
+
+  if (expect == MP_OK && mp_int_compare(in[2], out[0]) != 0) {
+    mp_int_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_exptv(t, ofp) */
+
+int test_exptv(testspec_t* t, FILE* ofp)
+{
+  mp_int in[3], out[1];
+  mp_result expect;
+  mp_small a, b;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  CHECK(mp_int_to_int(in[0], &a));
+  CHECK(mp_int_to_int(in[1], &b));
+  ECHECK(mp_int_expt_value(a, b, in[2]));
+
+  if (expect == MP_OK && mp_int_compare(in[2], out[0]) != 0) {
+    mp_int_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_exptf(t, ofp) */
+
+int test_exptf(testspec_t* t, FILE* ofp)
+{
+  mp_int in[3], out[1];
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  ECHECK(mp_int_expt_full(in[0], in[1], in[2]));
+
+  if (expect == MP_OK && mp_int_compare(in[2], out[0]) != 0) {
+    mp_int_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_mod(t, ofp) */
+
+int test_mod(testspec_t* t, FILE* ofp)
+{
+  mp_int in[3], out[1];
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  ECHECK(mp_int_mod(in[0], in[1], in[2]));
+
+  if (expect == MP_OK && mp_int_compare(in[2], out[0]) != 0) {
+    mp_int_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_gcd(t, ofp) */
+
+int test_gcd(testspec_t* t, FILE* ofp)
+{
+  mp_int in[3], out[1];
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  ECHECK(mp_int_gcd(in[0], in[1], in[2]));
+
+  if (expect == MP_OK && mp_int_compare(in[2], out[0]) != 0) {
+    mp_int_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_egcd(t, ofp) */
+
+int test_egcd(testspec_t* t, FILE* ofp)
+{
+  mp_int in[5], out[3], t1 = g_zreg + 8, t2 = g_zreg + 9;
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  ECHECK(mp_int_egcd(in[0], in[1], in[2], in[3], in[4]));
+
+  /* If we got an error we expected, return success immediately */
+  if(expect != MP_OK)
+    return 1;
+
+  if ((mp_int_compare(in[2], out[0]) != 0) ||
+      (mp_int_compare(in[3], out[1]) != 0) ||
+      (mp_int_compare(in[4], out[2]) != 0)) {
+    int len, len2;
+    char *str;
+
+    /* Failure might occur because the tester computed x and y in a different
+       way than we did.  Verify that the results are correct before reporting
+       an error. */
+    mp_int_mul(in[3], in[0], t1);
+    mp_int_mul(in[4], in[1], t2);
+    mp_int_add(t1, t2, t2);
+    if (mp_int_compare(t2, in[2]) == 0)
+      return 1;
+
+    mp_int_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    str = g_output + (len = strlen(g_output));
+    *str++ = ',';
+    mp_int_to_string(in[3], 10, str, OUTPUT_LIMIT - (len + 1));
+    str = str + (len2 = strlen(str));
+    *str++ = ',';
+    mp_int_to_string(in[4], 10, str, OUTPUT_LIMIT - (len + len2 + 2));
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_lcm(t, ofp) */
+
+int test_lcm(testspec_t* t, FILE* ofp)
+{
+  mp_int in[3], out[1];
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  ECHECK(mp_int_lcm(in[0], in[1], in[2]));
+
+  if (expect == MP_OK && mp_int_compare(in[2], out[0]) != 0) {
+    mp_int_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_sqrt(t, ofp) */
+
+int test_sqrt(testspec_t* t, FILE* ofp)
+{
+  mp_int in[2], out[1];
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  ECHECK(mp_int_sqrt(in[0], in[1]));
+
+  if (expect == MP_OK && mp_int_compare(in[1], out[0]) != 0) {
+    mp_int_to_string(in[1], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_root(t, ofp) */
+
+int test_root(testspec_t* t, FILE* ofp)
+{
+  mp_int in[3], out[1];
+  mp_small v;
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  CHECK(mp_int_to_int(in[1], &v));
+  ECHECK(mp_int_root(in[0], v, in[2]));
+
+  if (expect == MP_OK && mp_int_compare(in[2], out[0]) != 0) {
+    mp_int_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_invmod(t, ofp) */
+
+int test_invmod(testspec_t* t, FILE* ofp)
+{
+  mp_int in[3], out[1];
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  ECHECK(mp_int_invmod(in[0], in[1], in[2]));
+
+  if (expect == MP_OK && mp_int_compare(in[2], out[0]) != 0) {
+    mp_int_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_exptmod(t, ofp) */
+
+int test_exptmod(testspec_t* t, FILE* ofp)
+{
+  mp_int in[4], out[1];
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  ECHECK(mp_int_exptmod(in[0], in[1], in[2], in[3]));
+
+  if (expect == MP_OK && mp_int_compare(in[3], out[0]) != 0) {
+    mp_int_to_string(in[3], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_exptmod_ev(t, ofp) */
+
+int test_exptmod_ev(testspec_t* t, FILE* ofp)
+{
+  mp_int in[4], out[1];
+  mp_result expect;
+  mp_small v;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  CHECK(mp_int_to_int(in[1], &v));
+  ECHECK(mp_int_exptmod_evalue(in[0], v, in[2], in[3]));
+
+  if (expect == MP_OK && mp_int_compare(in[3], out[0]) != 0) {
+    mp_int_to_string(in[3], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_exptmod_bv(t, ofp) */
+
+int test_exptmod_bv(testspec_t* t, FILE* ofp)
+{
+  mp_int in[4], out[1];
+  mp_result expect;
+  mp_small v;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  CHECK(mp_int_to_int(in[0], &v));
+  ECHECK(mp_int_exptmod_bvalue(v, in[1], in[2], in[3]));
+
+  if (expect == MP_OK && mp_int_compare(in[3], out[0]) != 0) {
+    mp_int_to_string(in[3], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_comp(t, ofp) */
+
+int test_comp(testspec_t* t, FILE* ofp)
+{
+  mp_int in[2];
+  mp_result res, expect;
+
+  ACHECK(parse_int_values(t, in, NULL, &expect));
+
+  if ((res = mp_int_compare(in[0], in[1])) != expect) {
+    sprintf(g_output, "Incorrect comparison result (want %d, got %d)", 
+	    expect, res);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_ucomp(t, ofp) */
+
+int test_ucomp(testspec_t* t, FILE* ofp)
+{
+  mp_int in[2];
+  mp_result res, expect;
+
+  ACHECK(parse_int_values(t, in, NULL, &expect));
+
+  if ((res = mp_int_compare_unsigned(in[0], in[1])) != expect) {
+    sprintf(g_output, "Incorrect comparison result (want %d, got %d)", 
+	    expect, res);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_zcomp(t, ofp) */
+
+int test_zcomp(testspec_t* t, FILE* ofp)
+{
+  mp_int in[1];
+  mp_result res, expect;
+
+  ACHECK(parse_int_values(t, in, NULL, &expect));
+
+  if ((res = mp_int_compare_zero(in[0])) != expect) {
+    sprintf(g_output, "Incorrect comparison result (want %d, got %d)", 
+	    expect, res);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_vcomp(t, ofp) */
+
+int test_vcomp(testspec_t* t, FILE* ofp)
+{
+  mp_int in[2];
+  mp_result res, expect;
+  mp_small v;
+
+  ACHECK(parse_int_values(t, in, NULL, &expect));
+
+  v = atoi(t->input[1]);
+  if ((res = mp_int_compare_value(in[0], v)) != expect) {
+    sprintf(g_output, "Incorrect comparison result (want %d, got %d)", 
+	    expect, res);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_uvcomp(t, ofp) */
+
+int test_uvcomp(testspec_t* t, FILE* ofp)
+{
+  mp_int in[2];
+  mp_result res, expect;
+  mp_usmall v;
+
+  ACHECK(parse_int_values(t, in, NULL, &expect));
+
+  v = strtoul(t->input[1], NULL, 0);
+  if ((res = mp_int_compare_uvalue(in[0], v)) != expect) {
+    sprintf(g_output, "Incorrect comparison result (want %d, got %d)",
+	    expect, res);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_tostr(t, ofp) */
+
+int test_tostr(testspec_t* t, FILE* ofp)
+{
+  mp_int in[2];
+  mp_small radix;
+  mp_result len;
+
+  ACHECK(parse_int_values(t, in, NULL, NULL));
+  ACHECK(mp_int_to_int(in[1], &radix) == MP_OK);
+
+  if (radix < MP_MIN_RADIX || radix > MP_MAX_RADIX)
+    FAIL(MP_RANGE);
+
+  trim_line(t->output[0]);
+  len = mp_int_string_len(in[0], radix);
+
+  CHECK(mp_int_to_string(in[0], radix, g_output, len));
+
+  if(strcmp(t->output[0], g_output) != 0)
+    FAIL(OTHER_ERROR);
+
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_tobin(t, ofp) */
+
+int test_tobin(testspec_t* t, FILE* ofp)
+{
+  mp_int in[1];
+  int test_len, out_len;
+
+  ACHECK(parse_int_values(t, in, NULL, NULL));
+
+  trim_line(t->output[0]);
+  if((out_len = parse_binary(t->output[0], g_bin1, sizeof(g_bin1))) < 0)
+    FAIL(MP_BADARG);
+
+  if((test_len = mp_int_binary_len(in[0])) != out_len) {
+    sprintf(g_output, "Output lengths do not match (want %d, got %d)",
+	    test_len, out_len);
+    FAIL(OTHER_ERROR);
+  }
+
+  CHECK(mp_int_to_binary(in[0], g_bin2, sizeof(g_bin2)));
+
+  if (memcmp(g_bin1, g_bin2, test_len) != 0) {
+    int pos = 0, i;
+
+    for(i = 0; i < test_len - 1; ++i)
+      pos += sprintf(g_output + pos, "%d.", g_bin2[i]);
+
+    sprintf(g_output + pos, "%d", g_bin2[i]);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_to_int(t, ofp) */
+
+int test_to_int(testspec_t* t, FILE* ofp)
+{
+  mp_int in[1], out[1];
+  mp_small v;
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  ECHECK(mp_int_to_int(in[0], &v));
+
+  if (expect == MP_OK && mp_int_compare_value(out[0], v) != 0) {
+    sprintf(g_output, "Incorrect value (got %ld)", v);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_to_uint(t, ofp) */
+
+int test_to_uint(testspec_t* t, FILE* ofp)
+{
+  mp_int in[1], out[1];
+  mp_usmall v;
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+  ECHECK(mp_int_to_uint(in[0], &v));
+
+  if (expect == MP_OK && mp_int_compare_uvalue(out[0], v) != 0) {
+    sprintf(g_output, "Incorrect value (got %lu)", v);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_read_binary(t, ofp) */
+
+int test_read_binary(testspec_t* t, FILE* ofp)
+{
+  mp_int out[1], in = g_zreg + 1;
+  int in_len;
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, NULL, out, &expect));
+
+  trim_line(t->input[0]);
+  if((in_len = parse_binary(t->input[0], g_bin1, sizeof(g_bin1))) < 0)
+    FAIL(MP_BADARG);
+
+  ECHECK(mp_int_read_binary(in, g_bin1, in_len));
+
+  if (expect == MP_OK && mp_int_compare(in, out[0]) != 0) {
+    mp_int_to_string(in, 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_to_uns(t, ofp) */
+
+int test_to_uns(testspec_t* t, FILE* ofp)
+{
+  mp_int in[1];
+  int test_len, out_len;
+
+  ACHECK(parse_int_values(t, in, NULL, NULL));
+
+  trim_line(t->output[0]);
+  if((out_len = parse_binary(t->output[0], g_bin1, sizeof(g_bin1))) < 0)
+    FAIL(MP_BADARG);
+
+  if((test_len = mp_int_unsigned_len(in[0])) != out_len) {
+    sprintf(g_output, "Output lengths do not match (want %d, got %d)",
+	    test_len, out_len);
+    FAIL(OTHER_ERROR);
+  }
+
+  CHECK(mp_int_to_unsigned(in[0], g_bin2, sizeof(g_bin2)));
+
+  if (memcmp(g_bin1, g_bin2, test_len) != 0) {
+    int pos = 0, i;
+
+    for(i = 0; i < test_len - 1; ++i)
+      pos += sprintf(g_output + pos, "%d.", g_bin2[i]);
+
+    sprintf(g_output + pos, "%d", g_bin2[i]);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_read_uns(t, ofp) */
+
+int test_read_uns(testspec_t* t, FILE* ofp)
+{
+  mp_int out[1], in = g_zreg + 1;
+  int in_len;
+  mp_result expect;
+
+  ACHECK(parse_int_values(t, NULL, out, &expect));
+
+  trim_line(t->input[0]);
+  if((in_len = parse_binary(t->input[0], g_bin1, sizeof(g_bin1))) < 0)
+    FAIL(MP_BADARG);
+
+  ECHECK(mp_int_read_unsigned(in, g_bin1, in_len));
+
+  if (expect == MP_OK && mp_int_compare(in, out[0]) != 0) {
+    mp_int_to_string(in, 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_meta(t, ofp) */
+
+int test_meta(testspec_t* t, FILE* ofp)
+{
+  mp_int *in = NULL, *out = NULL;
+  int i, j;
+  mp_result expect;
+
+  if (t->num_inputs > 0)
+    in = calloc(t->num_inputs, sizeof(mp_int));
+  if (t->num_outputs > 0)
+    out = calloc(t->num_outputs, sizeof(mp_int));
+
+  ACHECK(parse_int_values(t, in, out, &expect));
+
+  fprintf(ofp, "Test '%s' defined at line %d\n",
+	  t->code, t->line);
+  fprintf(ofp, "Expected result: %d\n", expect);
+  fprintf(ofp, "Input values: %d\n", t->num_inputs);
+  for (i = 0; i < t->num_inputs; ++i) {
+    mp_int_to_string(in[i], 10, g_output, OUTPUT_LIMIT);
+
+    fprintf(ofp, " %2d.) %s", i + 1, g_output);
+
+    for (j = i - 1; j >= 0; --j)
+      if (in[j] == in[i]) {
+	fprintf(ofp, " (=> %d)", j + 1);
+	break;
+      }
+
+    fputc('\n', ofp);
+  }
+  fprintf(ofp, "Output values: %d\n", t->num_outputs);
+  for (i = 0; i < t->num_outputs; ++i) {
+    mp_int_to_string(out[i], 10, g_output, OUTPUT_LIMIT);
+
+    fprintf(ofp, " %2d.) %s\n", i + 1, g_output);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_qneg(t, ofp) */
+
+int test_qneg(testspec_t* t, FILE* ofp)
+{
+  mp_rat in[2], out[1];
+  mp_result expect;
+
+  ACHECK(parse_rat_values(t, in, out, &expect));
+  ECHECK(mp_rat_neg(in[0], in[1]));
+
+  if (expect == MP_OK && mp_rat_compare(in[1], out[0]) != 0) {
+    mp_rat_to_string(in[1], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_qrecip(t, ofp) */
+
+int test_qrecip(testspec_t* t, FILE* ofp)
+{
+  mp_rat in[2], out[1];
+  mp_result expect;
+
+  ACHECK(parse_rat_values(t, in, out, &expect));
+  ECHECK(mp_rat_recip(in[0], in[1]));
+
+  if (expect == MP_OK  && mp_rat_compare(in[1], out[0]) != 0) {
+    mp_rat_to_string(in[1], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_qabs(t, ofp) */
+
+int test_qabs(testspec_t* t, FILE* ofp)
+{
+  mp_rat in[2], out[1];
+  mp_result expect;
+
+  ACHECK(parse_rat_values(t, in, out, &expect));
+  ECHECK(mp_rat_abs(in[0], in[1]));
+
+  if (expect == MP_OK && mp_rat_compare(in[1], out[0]) != 0) {
+    mp_rat_to_string(in[1], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_qadd(t, ofp) */
+
+int test_qadd(testspec_t* t, FILE* ofp)
+{
+  mp_rat in[3], out[1];
+  mp_result expect;
+
+  ACHECK(parse_rat_values(t, in, out, &expect));
+  ECHECK(mp_rat_add(in[0], in[1], in[2]));
+
+  if (expect == MP_OK && mp_rat_compare(in[2], out[0]) != 0) {
+    mp_rat_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_qsub(t, ofp) */
+
+int test_qsub(testspec_t* t, FILE* ofp)
+{
+  mp_rat in[3], out[1];
+  mp_result expect;
+
+  ACHECK(parse_rat_values(t, in, out, &expect));
+  ECHECK(mp_rat_sub(in[0], in[1], in[2]));
+
+  if (expect == MP_OK && mp_rat_compare(in[2], out[0]) != 0) {
+    mp_rat_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_qmul(t, ofp) */
+
+int test_qmul(testspec_t* t, FILE* ofp)
+{
+  mp_rat in[3], out[1];
+  mp_result expect;
+
+  ACHECK(parse_rat_values(t, in, out, &expect));
+  ECHECK(mp_rat_mul(in[0], in[1], in[2]));
+
+  if (expect == MP_OK && mp_rat_compare(in[2], out[0]) != 0) {
+    mp_rat_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_qdiv(t, ofp) */
+
+int test_qdiv(testspec_t* t, FILE* ofp)
+{
+  mp_rat in[3], out[1];
+  mp_result expect;
+
+  ACHECK(parse_rat_values(t, in, out, &expect));
+  ECHECK(mp_rat_div(in[0], in[1], in[2]));
+
+  if (expect == MP_OK && mp_rat_compare(in[2], out[0]) != 0) {
+    mp_rat_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_qaddz(t, ofp) */
+
+int test_qaddz(testspec_t* t, FILE* ofp)
+{
+  mp_rat in[3], out[1];
+  mp_result expect;
+
+  ACHECK(parse_rat_values(t, in, out, &expect));
+
+  if (!mp_rat_is_integer(in[1])) {
+    fprintf(stderr, "Line %d: Second argument must be an integer (test_qaddz)\n",
+	    t->line);
+    FAIL(MP_BADARG);
+  }
+
+  ECHECK(mp_rat_add_int(in[0], MP_NUMER_P(in[1]), in[2]));
+
+  if (expect == MP_OK && mp_rat_compare(in[2], out[0]) != 0) {
+    mp_rat_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_qsubz(t, ofp) */
+
+int test_qsubz(testspec_t* t, FILE* ofp)
+{
+  mp_rat in[3], out[1];
+  mp_result expect;
+
+  ACHECK(parse_rat_values(t, in, out, &expect));
+
+  if (!mp_rat_is_integer(in[1])) {
+    fprintf(stderr, "Line %d: Second argument must be an integer (test_qsubz)\n",
+	    t->line);
+    FAIL(MP_BADARG);
+  }
+
+  ECHECK(mp_rat_sub_int(in[0], MP_NUMER_P(in[1]), in[2]));
+
+  if (expect == MP_OK && mp_rat_compare(in[2], out[0]) != 0) {
+    mp_rat_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_qmulz(t, ofp) */
+
+int test_qmulz(testspec_t* t, FILE* ofp)
+{
+  mp_rat in[3], out[1];
+  mp_result expect;
+
+  ACHECK(parse_rat_values(t, in, out, &expect));
+
+  if (!mp_rat_is_integer(in[1])) {
+    fprintf(stderr, "Line %d: Second argument must be an integer (test_qmulz)\n",
+	    t->line);
+    FAIL(MP_BADARG);
+  }
+
+  ECHECK(mp_rat_mul_int(in[0], MP_NUMER_P(in[1]), in[2]));
+
+  if (expect == MP_OK && mp_rat_compare(in[2], out[0]) != 0) {
+    mp_rat_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_qdivz(t, ofp) */
+
+int test_qdivz(testspec_t* t, FILE* ofp)
+{
+  mp_rat in[3], out[1];
+  mp_result expect;
+
+  ACHECK(parse_rat_values(t, in, out, &expect));
+
+  if (!mp_rat_is_integer(in[1])) {
+    fprintf(stderr, "Line %d: Second argument must be an integer (test_qdivz)\n",
+	    t->line);
+    FAIL(MP_BADARG);
+  }
+
+  ECHECK(mp_rat_div_int(in[0], MP_NUMER_P(in[1]), in[2]));
+
+  if (expect == MP_OK && mp_rat_compare(in[2], out[0]) != 0) {
+    mp_rat_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_qexpt(t, ofp) */
+
+int test_qexpt(testspec_t* t, FILE* ofp)
+{
+  mp_rat in[3], out[1];
+  mp_result expect;
+  mp_small power;
+
+  ACHECK(parse_rat_values(t, in, out, &expect));
+
+  if (!mp_rat_is_integer(in[1])) {
+    fprintf(stderr, "Line %d: Second argument must be an integer (test_qexpt)\n",
+	    t->line);
+    FAIL(MP_BADARG);
+  }
+
+  CHECK(mp_int_to_int(MP_NUMER_P(in[1]), &power));
+  ECHECK(mp_rat_expt(in[0], power, in[2]));
+
+  if (expect == MP_OK && mp_rat_compare(in[2], out[0]) != 0) {
+    mp_rat_to_string(in[2], 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_qtostr(t, ofp) */
+
+int test_qtostr(testspec_t* t, FILE* ofp)
+{
+  mp_rat in[2];
+  long radix;
+  mp_result len;
+
+  ACHECK(parse_rat_values(t, in, NULL, NULL));
+  trim_line(t->input[1]);
+  ACHECK(read_long(&radix, t->input[1]));
+
+  if (radix < MP_MIN_RADIX || radix > MP_MAX_RADIX) {
+    fprintf(stderr, "Line %d: Radix %ld out of range\n",
+	    t->line, radix);
+    FAIL(MP_RANGE);
+  }
+
+  trim_line(t->output[0]);
+  len = mp_rat_string_len(in[0], radix);
+
+  CHECK(mp_rat_to_string(in[0], radix, g_output, len));
+
+  if (strcmp(t->output[0], g_output) != 0)
+    FAIL(OTHER_ERROR);
+
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_qtodec(t, ofp) */
+
+int test_qtodec(testspec_t* t, FILE* ofp)
+{
+  mp_rat in[4];
+  long radix, prec, m;
+  mp_round_mode rmode;
+  mp_result res, expect = MP_OK, len;
+
+  ACHECK(parse_rat_values(t, in, NULL, NULL));
+
+  if (t->output[0][0] == '$' && !parse_result_code(t->output[0], &expect)) {
+    fprintf(stderr, "Line %d: Invalid result code [%s]\n",
+	    t->line, t->output[0]);
+    FAIL(OTHER_ERROR);
+  }
+
+  trim_line(t->input[1]);
+  trim_line(t->input[2]);
+  trim_line(t->input[3]);
+  ACHECK(read_long(&radix, t->input[1]));
+  ACHECK(read_long(&prec, t->input[2]));
+  ACHECK(read_long(&m, t->input[3]));
+  rmode = (mp_round_mode) m;
+
+  if (prec < 0) {
+    fprintf(stderr, "Line %d: Precision %ld out of range\n",
+	    t->line, prec);
+    FAIL(MP_RANGE);
+  }
+
+  trim_line(t->output[0]);
+  len = mp_rat_decimal_len(in[0], radix, prec);
+  ECHECK((res = mp_rat_to_decimal(in[0], radix, prec, rmode, g_output, len)));
+
+  if (res == MP_OK && strcmp(t->output[0], g_output) != 0)
+    FAIL(OTHER_ERROR);
+
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ test_qrdec(t, ofp) */
+
+int test_qrdec(testspec_t* t, FILE* ofp)
+{
+  mp_rat out[1], reg = g_qreg + 1;
+  long radix;
+  mp_result expect;
+
+  ACHECK(parse_rat_values(t, NULL, out, &expect));
+  trim_line(t->input[1]);
+  ACHECK(read_long(&radix, t->input[1]));
+
+  ECHECK(mp_rat_read_decimal(reg, radix, t->input[0]));
+  if (expect == MP_OK &&
+      mp_rat_compare(reg, out[0]) != 0) {
+    mp_rat_to_string(reg, 10, g_output, OUTPUT_LIMIT);
+    FAIL(OTHER_ERROR);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* Here there be dragons */

Added: polly/trunk/lib/External/isl/imath/imdrover.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/imdrover.h?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/imdrover.h (added)
+++ polly/trunk/lib/External/isl/imath/imdrover.h Wed Feb  4 14:55:43 2015
@@ -0,0 +1,106 @@
+/*
+  Name:     imdrover.h
+  Purpose:  Keeper of the hordes of testing code.
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  Copyright (C) 2002-2007 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#ifndef IMDROVER_H_
+#define IMDROVER_H_
+
+#include <stdio.h>
+
+typedef struct {
+  int    line;
+  char  *code;
+  int    num_inputs;
+  char **input;
+  int    num_outputs;
+  char **output;
+} testspec_t;
+
+typedef int (*test_f)(testspec_t *, FILE *);
+
+/* Call this once at the outset to set up test registers */
+void init_testing(void);
+void reset_registers(void);
+
+/* Integer tests, and general */
+int test_init(testspec_t* t, FILE* ofp);
+int test_set(testspec_t* t, FILE* ofp);
+int test_neg(testspec_t* t, FILE* ofp);
+int test_abs(testspec_t* t, FILE* ofp);
+int test_add(testspec_t* t, FILE* ofp);
+int test_sub(testspec_t* t, FILE* ofp);
+int test_mul(testspec_t* t, FILE* ofp);
+int test_mulp2(testspec_t* t, FILE* ofp);
+int test_mulv(testspec_t* t, FILE* ofp);
+int test_sqr(testspec_t* t, FILE* ofp);
+int test_div(testspec_t* t, FILE* ofp);
+int test_divp2(testspec_t* t, FILE* ofp);
+int test_divv(testspec_t* t, FILE* ofp);
+int test_expt(testspec_t* t, FILE* ofp);
+int test_exptv(testspec_t* t, FILE* ofp);
+int test_exptf(testspec_t* t, FILE* ofp);
+int test_mod(testspec_t* t, FILE* ofp);
+int test_gcd(testspec_t* t, FILE* ofp);
+int test_egcd(testspec_t* t, FILE* ofp);
+int test_lcm(testspec_t* t, FILE* ofp);
+int test_sqrt(testspec_t* t, FILE* ofp);
+int test_root(testspec_t* t, FILE* ofp);
+int test_invmod(testspec_t* t, FILE* ofp);
+int test_exptmod(testspec_t* t, FILE* ofp);
+int test_exptmod_ev(testspec_t* t, FILE* ofp);
+int test_exptmod_bv(testspec_t* t, FILE* ofp);
+int test_comp(testspec_t* t, FILE* ofp);
+int test_ucomp(testspec_t* t, FILE* ofp);
+int test_zcomp(testspec_t* t, FILE* ofp);
+int test_vcomp(testspec_t* t, FILE* ofp);
+int test_uvcomp(testspec_t* t, FILE* ofp);
+int test_tostr(testspec_t* t, FILE* ofp);
+int test_tobin(testspec_t* t, FILE* ofp);
+int test_to_int(testspec_t* t, FILE* ofp);
+int test_to_uint(testspec_t* t, FILE* ofp);
+int test_read_binary(testspec_t* t, FILE* ofp);
+int test_to_uns(testspec_t* t, FILE* ofp);
+int test_read_uns(testspec_t* t, FILE* ofp);
+int test_meta(testspec_t* t, FILE* ofp);
+
+/* Rational tests */
+int test_qneg(testspec_t* t, FILE* ofp);
+int test_qrecip(testspec_t* t, FILE* ofp);
+int test_qabs(testspec_t* t, FILE* ofp);
+int test_qadd(testspec_t* t, FILE* ofp);
+int test_qsub(testspec_t* t, FILE* ofp);
+int test_qmul(testspec_t* t, FILE* ofp);
+int test_qdiv(testspec_t* t, FILE* ofp);
+int test_qdiv(testspec_t* t, FILE* ofp);
+int test_qaddz(testspec_t* t, FILE* ofp);
+int test_qsubz(testspec_t* t, FILE* ofp);
+int test_qmulz(testspec_t* t, FILE* ofp);
+int test_qdivz(testspec_t* t, FILE* ofp);
+int test_qexpt(testspec_t* t, FILE* ofp);
+int test_qtostr(testspec_t* t, FILE* ofp);
+int test_qtodec(testspec_t* t, FILE* ofp);
+int test_qrdec(testspec_t* t, FILE* ofp);
+
+#endif /* IMDROVER_H_ */

Added: polly/trunk/lib/External/isl/imath/imrat.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/imrat.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/imrat.c (added)
+++ polly/trunk/lib/External/isl/imath/imrat.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,1141 @@
+/*
+  Name:     imrat.c
+  Purpose:  Arbitrary precision rational arithmetic routines.
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  Copyright (C) 2002-2007 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#include "imrat.h"
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <assert.h>
+
+/* {{{ Useful macros */
+
+#define TEMP(K) (temp + (K))
+#define SETUP(E, C) \
+do{if((res = (E)) != MP_OK) goto CLEANUP; ++(C);}while(0)
+
+/* Argument checking:
+   Use CHECK() where a return value is required; NRCHECK() elsewhere */
+#define CHECK(TEST)   assert(TEST)
+#define NRCHECK(TEST) assert(TEST)
+
+/* }}} */
+
+/* Reduce the given rational, in place, to lowest terms and canonical form.
+   Zero is represented as 0/1, one as 1/1.  Signs are adjusted so that the sign
+   of the numerator is definitive. */
+static mp_result s_rat_reduce(mp_rat r);
+
+/* Common code for addition and subtraction operations on rationals. */
+static mp_result s_rat_combine(mp_rat a, mp_rat b, mp_rat c,
+			       mp_result (*comb_f)(mp_int, mp_int, mp_int));
+
+/* {{{ mp_rat_init(r) */
+
+mp_result mp_rat_init(mp_rat r)
+{
+  mp_result res;
+
+  if ((res = mp_int_init(MP_NUMER_P(r))) != MP_OK)
+    return res;
+  if ((res = mp_int_init(MP_DENOM_P(r))) != MP_OK) {
+    mp_int_clear(MP_NUMER_P(r));
+    return res;
+  }
+
+  return mp_int_set_value(MP_DENOM_P(r), 1);
+}
+
+/* }}} */
+
+/* {{{ mp_rat_alloc() */
+
+mp_rat mp_rat_alloc(void)
+{
+  mp_rat out = malloc(sizeof(*out));
+
+  if (out != NULL) {
+    if (mp_rat_init(out) != MP_OK) {
+      free(out);
+      return NULL;
+    }
+  }
+
+  return out;
+}
+
+/* }}} */
+
+/* {{{ mp_rat_reduce(r) */
+
+mp_result mp_rat_reduce(mp_rat r) {
+  return s_rat_reduce(r);
+}
+
+/* }}} */
+
+/* {{{ mp_rat_init_size(r, n_prec, d_prec) */
+
+mp_result mp_rat_init_size(mp_rat r, mp_size n_prec, mp_size d_prec)
+{
+  mp_result res;
+
+  if ((res = mp_int_init_size(MP_NUMER_P(r), n_prec)) != MP_OK)
+    return res;
+  if ((res = mp_int_init_size(MP_DENOM_P(r), d_prec)) != MP_OK) {
+    mp_int_clear(MP_NUMER_P(r));
+    return res;
+  }
+  
+  return mp_int_set_value(MP_DENOM_P(r), 1);
+}
+
+/* }}} */
+
+/* {{{ mp_rat_init_copy(r, old) */
+
+mp_result mp_rat_init_copy(mp_rat r, mp_rat old)
+{
+  mp_result res;
+
+  if ((res = mp_int_init_copy(MP_NUMER_P(r), MP_NUMER_P(old))) != MP_OK)
+    return res;
+  if ((res = mp_int_init_copy(MP_DENOM_P(r), MP_DENOM_P(old))) != MP_OK) 
+    mp_int_clear(MP_NUMER_P(r));
+  
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_rat_set_value(r, numer, denom) */
+
+mp_result mp_rat_set_value(mp_rat r, mp_small numer, mp_small denom)
+{
+  mp_result res;
+
+  if (denom == 0)
+    return MP_UNDEF;
+
+  if ((res = mp_int_set_value(MP_NUMER_P(r), numer)) != MP_OK)
+    return res;
+  if ((res = mp_int_set_value(MP_DENOM_P(r), denom)) != MP_OK)
+    return res;
+
+  return s_rat_reduce(r);
+}
+
+/* }}} */
+
+/* {{{ mp_rat_set_uvalue(r, numer, denom) */
+
+mp_result mp_rat_set_uvalue(mp_rat r, mp_usmall numer, mp_usmall denom)
+{
+  mp_result res;
+
+  if (denom == 0)
+    return MP_UNDEF;
+
+  if ((res = mp_int_set_uvalue(MP_NUMER_P(r), numer)) != MP_OK)
+    return res;
+  if ((res = mp_int_set_uvalue(MP_DENOM_P(r), denom)) != MP_OK)
+    return res;
+
+  return s_rat_reduce(r);
+}
+
+/* }}} */
+
+/* {{{ mp_rat_clear(r) */
+
+void      mp_rat_clear(mp_rat r)
+{
+  mp_int_clear(MP_NUMER_P(r));
+  mp_int_clear(MP_DENOM_P(r));
+
+}
+
+/* }}} */
+
+/* {{{ mp_rat_free(r) */
+
+void      mp_rat_free(mp_rat r)
+{
+  NRCHECK(r != NULL);
+  
+  if (r->num.digits != NULL)
+    mp_rat_clear(r);
+
+  free(r);
+}
+
+/* }}} */
+
+/* {{{ mp_rat_numer(r, z) */
+
+mp_result mp_rat_numer(mp_rat r, mp_int z)
+{
+  return mp_int_copy(MP_NUMER_P(r), z);
+}
+
+/* }}} */
+
+/* {{{ mp_rat_numer_ref(r) */
+
+mp_int mp_rat_numer_ref(mp_rat r)
+{
+  return MP_NUMER_P(r);
+}
+
+/* }}} */
+
+
+/* {{{ mp_rat_denom(r, z) */
+
+mp_result mp_rat_denom(mp_rat r, mp_int z)
+{
+  return mp_int_copy(MP_DENOM_P(r), z);
+}
+
+/* }}} */
+
+/* {{{ mp_rat_denom_ref(r) */
+
+mp_int    mp_rat_denom_ref(mp_rat r)
+{
+  return MP_DENOM_P(r);
+}
+
+/* }}} */
+
+/* {{{ mp_rat_sign(r) */
+
+mp_sign   mp_rat_sign(mp_rat r)
+{
+  return MP_SIGN(MP_NUMER_P(r));
+}
+
+/* }}} */
+
+/* {{{ mp_rat_copy(a, c) */
+
+mp_result mp_rat_copy(mp_rat a, mp_rat c)
+{
+  mp_result res;
+
+  if ((res = mp_int_copy(MP_NUMER_P(a), MP_NUMER_P(c))) != MP_OK)
+    return res;
+  
+  res = mp_int_copy(MP_DENOM_P(a), MP_DENOM_P(c));
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_rat_zero(r) */
+
+void      mp_rat_zero(mp_rat r)
+{
+  mp_int_zero(MP_NUMER_P(r));
+  mp_int_set_value(MP_DENOM_P(r), 1);
+  
+}
+
+/* }}} */
+
+/* {{{ mp_rat_abs(a, c) */
+
+mp_result mp_rat_abs(mp_rat a, mp_rat c)
+{
+  mp_result res;
+
+  if ((res = mp_int_abs(MP_NUMER_P(a), MP_NUMER_P(c))) != MP_OK)
+    return res;
+  
+  res = mp_int_abs(MP_DENOM_P(a), MP_DENOM_P(c));
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_rat_neg(a, c) */
+
+mp_result mp_rat_neg(mp_rat a, mp_rat c)
+{
+  mp_result res;
+
+  if ((res = mp_int_neg(MP_NUMER_P(a), MP_NUMER_P(c))) != MP_OK)
+    return res;
+
+  res = mp_int_copy(MP_DENOM_P(a), MP_DENOM_P(c));
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_rat_recip(a, c) */
+
+mp_result mp_rat_recip(mp_rat a, mp_rat c)
+{
+  mp_result res;
+
+  if (mp_rat_compare_zero(a) == 0)
+    return MP_UNDEF;
+
+  if ((res = mp_rat_copy(a, c)) != MP_OK)
+    return res;
+
+  mp_int_swap(MP_NUMER_P(c), MP_DENOM_P(c));
+
+  /* Restore the signs of the swapped elements */
+  {
+    mp_sign tmp = MP_SIGN(MP_NUMER_P(c));
+
+    MP_SIGN(MP_NUMER_P(c)) = MP_SIGN(MP_DENOM_P(c));
+    MP_SIGN(MP_DENOM_P(c)) = tmp;
+  }
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ mp_rat_add(a, b, c) */
+
+mp_result mp_rat_add(mp_rat a, mp_rat b, mp_rat c)
+{
+  return s_rat_combine(a, b, c, mp_int_add);
+
+}
+
+/* }}} */
+
+/* {{{ mp_rat_sub(a, b, c) */
+
+mp_result mp_rat_sub(mp_rat a, mp_rat b, mp_rat c)
+{
+  return s_rat_combine(a, b, c, mp_int_sub);
+
+}
+
+/* }}} */
+
+/* {{{ mp_rat_mul(a, b, c) */
+
+mp_result mp_rat_mul(mp_rat a, mp_rat b, mp_rat c)
+{
+  mp_result res;
+
+  if ((res = mp_int_mul(MP_NUMER_P(a), MP_NUMER_P(b), MP_NUMER_P(c))) != MP_OK)
+    return res;
+
+  if (mp_int_compare_zero(MP_NUMER_P(c)) != 0) {
+    if ((res = mp_int_mul(MP_DENOM_P(a), MP_DENOM_P(b), MP_DENOM_P(c))) != MP_OK)
+      return res;
+  }
+
+  return s_rat_reduce(c);
+}
+
+/* }}} */
+
+/* {{{ mp_int_div(a, b, c) */
+
+mp_result mp_rat_div(mp_rat a, mp_rat b, mp_rat c)
+{
+  mp_result res = MP_OK;
+
+  if (mp_rat_compare_zero(b) == 0)
+    return MP_UNDEF;
+
+  if (c == a || c == b) {
+    mpz_t tmp;
+
+    if ((res = mp_int_init(&tmp)) != MP_OK) return res;
+    if ((res = mp_int_mul(MP_NUMER_P(a), MP_DENOM_P(b), &tmp)) != MP_OK) 
+      goto CLEANUP;
+    if ((res = mp_int_mul(MP_DENOM_P(a), MP_NUMER_P(b), MP_DENOM_P(c))) != MP_OK)
+      goto CLEANUP;
+    res = mp_int_copy(&tmp, MP_NUMER_P(c));
+
+  CLEANUP:
+    mp_int_clear(&tmp);
+  }
+  else {
+    if ((res = mp_int_mul(MP_NUMER_P(a), MP_DENOM_P(b), MP_NUMER_P(c))) != MP_OK)
+      return res;
+    if ((res = mp_int_mul(MP_DENOM_P(a), MP_NUMER_P(b), MP_DENOM_P(c))) != MP_OK)
+      return res;
+  }
+
+  if (res != MP_OK)
+    return res;
+  else
+    return s_rat_reduce(c);
+}
+
+/* }}} */
+
+/* {{{ mp_rat_add_int(a, b, c) */
+
+mp_result mp_rat_add_int(mp_rat a, mp_int b, mp_rat c)
+{
+  mpz_t tmp;
+  mp_result res;
+
+  if ((res = mp_int_init_copy(&tmp, b)) != MP_OK)
+    return res;
+
+  if ((res = mp_int_mul(&tmp, MP_DENOM_P(a), &tmp)) != MP_OK)
+    goto CLEANUP;
+
+  if ((res = mp_rat_copy(a, c)) != MP_OK)
+    goto CLEANUP;
+
+  if ((res = mp_int_add(MP_NUMER_P(c), &tmp, MP_NUMER_P(c))) != MP_OK)
+    goto CLEANUP;
+
+  res = s_rat_reduce(c);
+
+ CLEANUP:
+  mp_int_clear(&tmp);
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_rat_sub_int(a, b, c) */
+
+mp_result mp_rat_sub_int(mp_rat a, mp_int b, mp_rat c)
+{
+  mpz_t tmp;
+  mp_result res;
+
+  if ((res = mp_int_init_copy(&tmp, b)) != MP_OK)
+    return res;
+
+  if ((res = mp_int_mul(&tmp, MP_DENOM_P(a), &tmp)) != MP_OK)
+    goto CLEANUP;
+
+  if ((res = mp_rat_copy(a, c)) != MP_OK)
+    goto CLEANUP;
+
+  if ((res = mp_int_sub(MP_NUMER_P(c), &tmp, MP_NUMER_P(c))) != MP_OK)
+    goto CLEANUP;
+
+  res = s_rat_reduce(c);
+
+ CLEANUP:
+  mp_int_clear(&tmp);
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_rat_mul_int(a, b, c) */
+
+mp_result mp_rat_mul_int(mp_rat a, mp_int b, mp_rat c)
+{
+  mp_result res;
+
+  if ((res = mp_rat_copy(a, c)) != MP_OK)
+    return res;
+
+  if ((res = mp_int_mul(MP_NUMER_P(c), b, MP_NUMER_P(c))) != MP_OK)
+    return res;
+
+  return s_rat_reduce(c);
+}
+
+/* }}} */
+
+/* {{{ mp_rat_div_int(a, b, c) */
+
+mp_result mp_rat_div_int(mp_rat a, mp_int b, mp_rat c)
+{
+  mp_result res;
+
+  if (mp_int_compare_zero(b) == 0)
+    return MP_UNDEF;
+
+  if ((res = mp_rat_copy(a, c)) != MP_OK)
+    return res;
+
+  if ((res = mp_int_mul(MP_DENOM_P(c), b, MP_DENOM_P(c))) != MP_OK)
+    return res;
+
+  return s_rat_reduce(c);
+}
+
+/* }}} */
+
+/* {{{ mp_rat_expt(a, b, c) */
+
+mp_result mp_rat_expt(mp_rat a, mp_small b, mp_rat c)
+{
+  mp_result  res;
+
+  /* Special cases for easy powers. */
+  if (b == 0)
+    return mp_rat_set_value(c, 1, 1);
+  else if(b == 1)
+    return mp_rat_copy(a, c);
+
+  /* Since rationals are always stored in lowest terms, it is not necessary to
+     reduce again when raising to an integer power. */
+  if ((res = mp_int_expt(MP_NUMER_P(a), b, MP_NUMER_P(c))) != MP_OK)
+    return res;
+
+  return mp_int_expt(MP_DENOM_P(a), b, MP_DENOM_P(c));
+}
+
+/* }}} */
+
+/* {{{ mp_rat_compare(a, b) */
+
+int       mp_rat_compare(mp_rat a, mp_rat b)
+{
+  /* Quick check for opposite signs.  Works because the sign of the numerator
+     is always definitive. */
+  if (MP_SIGN(MP_NUMER_P(a)) != MP_SIGN(MP_NUMER_P(b))) {
+    if (MP_SIGN(MP_NUMER_P(a)) == MP_ZPOS)
+      return 1;
+    else
+      return -1;
+  }
+  else {
+    /* Compare absolute magnitudes; if both are positive, the answer stands,
+       otherwise it needs to be reflected about zero. */
+    int cmp = mp_rat_compare_unsigned(a, b);
+
+    if (MP_SIGN(MP_NUMER_P(a)) == MP_ZPOS)
+      return cmp;
+    else
+      return -cmp;
+  }
+}
+
+/* }}} */
+
+/* {{{ mp_rat_compare_unsigned(a, b) */
+
+int       mp_rat_compare_unsigned(mp_rat a, mp_rat b)
+{
+  /* If the denominators are equal, we can quickly compare numerators without
+     multiplying.  Otherwise, we actually have to do some work. */
+  if (mp_int_compare_unsigned(MP_DENOM_P(a), MP_DENOM_P(b)) == 0)
+    return mp_int_compare_unsigned(MP_NUMER_P(a), MP_NUMER_P(b));
+
+  else {
+    mpz_t  temp[2];
+    mp_result res;
+    int  cmp = INT_MAX, last = 0;
+
+    /* t0 = num(a) * den(b), t1 = num(b) * den(a) */
+    SETUP(mp_int_init_copy(TEMP(last), MP_NUMER_P(a)), last);
+    SETUP(mp_int_init_copy(TEMP(last), MP_NUMER_P(b)), last);
+
+    if ((res = mp_int_mul(TEMP(0), MP_DENOM_P(b), TEMP(0))) != MP_OK ||
+	(res = mp_int_mul(TEMP(1), MP_DENOM_P(a), TEMP(1))) != MP_OK)
+      goto CLEANUP;
+    
+    cmp = mp_int_compare_unsigned(TEMP(0), TEMP(1));
+    
+  CLEANUP:
+    while (--last >= 0)
+      mp_int_clear(TEMP(last));
+
+    return cmp;
+  }
+}
+
+/* }}} */
+
+/* {{{ mp_rat_compare_zero(r) */
+
+int       mp_rat_compare_zero(mp_rat r)
+{
+  return mp_int_compare_zero(MP_NUMER_P(r));
+}
+
+/* }}} */
+
+/* {{{ mp_rat_compare_value(r, n, d) */
+
+int       mp_rat_compare_value(mp_rat r, mp_small n, mp_small d)
+{
+  mpq_t tmp;
+  mp_result res;
+  int  out = INT_MAX;
+
+  if ((res = mp_rat_init(&tmp)) != MP_OK)
+    return out;
+  if ((res = mp_rat_set_value(&tmp, n, d)) != MP_OK)
+    goto CLEANUP;
+  
+  out = mp_rat_compare(r, &tmp);
+  
+ CLEANUP:
+  mp_rat_clear(&tmp);
+  return out;
+}
+
+/* }}} */
+
+/* {{{ mp_rat_is_integer(r) */
+
+int       mp_rat_is_integer(mp_rat r)
+{
+  return (mp_int_compare_value(MP_DENOM_P(r), 1) == 0);
+}
+
+/* }}} */
+
+/* {{{ mp_rat_to_ints(r, *num, *den) */
+
+mp_result mp_rat_to_ints(mp_rat r, mp_small *num, mp_small *den)
+{
+  mp_result res;
+
+  if ((res = mp_int_to_int(MP_NUMER_P(r), num)) != MP_OK)
+    return res;
+
+  res = mp_int_to_int(MP_DENOM_P(r), den);
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_rat_to_string(r, radix, *str, limit) */
+
+mp_result mp_rat_to_string(mp_rat r, mp_size radix, char *str, int limit)
+{
+  char *start;
+  int   len;
+  mp_result res;
+
+  /* Write the numerator.  The sign of the rational number is written by the
+     underlying integer implementation. */
+  if ((res = mp_int_to_string(MP_NUMER_P(r), radix, str, limit)) != MP_OK)
+    return res;
+
+  /* If the value is zero, don't bother writing any denominator */
+  if (mp_int_compare_zero(MP_NUMER_P(r)) == 0)
+    return MP_OK;
+  
+  /* Locate the end of the numerator, and make sure we are not going to exceed
+     the limit by writing a slash. */
+  len = strlen(str);
+  start = str + len;
+  limit -= len;
+  if(limit == 0)
+    return MP_TRUNC;
+
+  *start++ = '/';
+  limit -= 1;
+  
+  res = mp_int_to_string(MP_DENOM_P(r), radix, start, limit);
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_rat_to_decimal(r, radix, prec, *str, limit) */
+mp_result mp_rat_to_decimal(mp_rat r, mp_size radix, mp_size prec,
+                            mp_round_mode round, char *str, int limit)
+{
+  mpz_t temp[3];
+  mp_result res;
+  char *start = str;
+  int len, lead_0, left = limit, last = 0;
+    
+  SETUP(mp_int_init_copy(TEMP(last), MP_NUMER_P(r)), last);
+  SETUP(mp_int_init(TEMP(last)), last);
+  SETUP(mp_int_init(TEMP(last)), last);
+
+  /* Get the unsigned integer part by dividing denominator into the absolute
+     value of the numerator. */
+  mp_int_abs(TEMP(0), TEMP(0));
+  if ((res = mp_int_div(TEMP(0), MP_DENOM_P(r), TEMP(0), TEMP(1))) != MP_OK)
+    goto CLEANUP;
+
+  /* Now:  T0 = integer portion, unsigned;
+           T1 = remainder, from which fractional part is computed. */
+
+  /* Count up leading zeroes after the radix point. */
+  for (lead_0 = 0; lead_0 < prec && mp_int_compare(TEMP(1), MP_DENOM_P(r)) < 0; 
+      ++lead_0) {
+    if ((res = mp_int_mul_value(TEMP(1), radix, TEMP(1))) != MP_OK)
+      goto CLEANUP;
+  }
+
+  /* Multiply remainder by a power of the radix sufficient to get the right
+     number of significant figures. */
+  if (prec > lead_0) {
+    if ((res = mp_int_expt_value(radix, prec - lead_0, TEMP(2))) != MP_OK)
+      goto CLEANUP;
+    if ((res = mp_int_mul(TEMP(1), TEMP(2), TEMP(1))) != MP_OK)
+      goto CLEANUP;
+  }
+  if ((res = mp_int_div(TEMP(1), MP_DENOM_P(r), TEMP(1), TEMP(2))) != MP_OK)
+    goto CLEANUP;
+
+  /* Now:  T1 = significant digits of fractional part;
+           T2 = leftovers, to use for rounding. 
+
+     At this point, what we do depends on the rounding mode.  The default is
+     MP_ROUND_DOWN, for which everything is as it should be already.
+  */
+  switch (round) {
+    int cmp;
+
+  case MP_ROUND_UP:
+    if (mp_int_compare_zero(TEMP(2)) != 0) {
+      if (prec == 0)
+	res = mp_int_add_value(TEMP(0), 1, TEMP(0));
+      else
+	res = mp_int_add_value(TEMP(1), 1, TEMP(1));
+    }
+    break;
+
+  case MP_ROUND_HALF_UP:
+  case MP_ROUND_HALF_DOWN:
+    if ((res = mp_int_mul_pow2(TEMP(2), 1, TEMP(2))) != MP_OK)
+      goto CLEANUP;
+
+    cmp = mp_int_compare(TEMP(2), MP_DENOM_P(r));    
+
+    if (round == MP_ROUND_HALF_UP)
+      cmp += 1;
+
+    if (cmp > 0) {
+      if (prec == 0)
+	res = mp_int_add_value(TEMP(0), 1, TEMP(0));
+      else
+	res = mp_int_add_value(TEMP(1), 1, TEMP(1));
+    }
+    break;
+    
+  case MP_ROUND_DOWN:
+    break;  /* No action required */
+
+  default: 
+    return MP_BADARG; /* Invalid rounding specifier */
+  }
+
+  /* The sign of the output should be the sign of the numerator, but if all the
+     displayed digits will be zero due to the precision, a negative shouldn't
+     be shown. */
+  if (MP_SIGN(MP_NUMER_P(r)) == MP_NEG &&
+      (mp_int_compare_zero(TEMP(0)) != 0 ||
+       mp_int_compare_zero(TEMP(1)) != 0)) {
+    *start++ = '-';
+    left -= 1;
+  }
+
+  if ((res = mp_int_to_string(TEMP(0), radix, start, left)) != MP_OK)
+    goto CLEANUP;
+  
+  len = strlen(start);
+  start += len;
+  left -= len;
+  
+  if (prec == 0) 
+    goto CLEANUP;
+  
+  *start++ = '.';
+  left -= 1;
+  
+  if (left < prec + 1) {
+    res = MP_TRUNC;
+    goto CLEANUP;
+  }
+
+  memset(start, '0', lead_0 - 1);
+  left -= lead_0;
+  start += lead_0 - 1;
+
+  res = mp_int_to_string(TEMP(1), radix, start, left);
+
+ CLEANUP:
+  while (--last >= 0)
+    mp_int_clear(TEMP(last));
+  
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_rat_string_len(r, radix) */
+
+mp_result mp_rat_string_len(mp_rat r, mp_size radix)
+{
+  mp_result n_len, d_len = 0;
+
+  n_len = mp_int_string_len(MP_NUMER_P(r), radix);
+
+  if (mp_int_compare_zero(MP_NUMER_P(r)) != 0)
+    d_len = mp_int_string_len(MP_DENOM_P(r), radix);
+
+  /* Though simplistic, this formula is correct.  Space for the sign flag is
+     included in n_len, and the space for the NUL that is counted in n_len
+     counts for the separator here.  The space for the NUL counted in d_len
+     counts for the final terminator here. */
+
+  return n_len + d_len;
+
+}
+
+/* }}} */
+
+/* {{{ mp_rat_decimal_len(r, radix, prec) */
+
+mp_result mp_rat_decimal_len(mp_rat r, mp_size radix, mp_size prec)
+{
+  int  z_len, f_len;
+
+  z_len = mp_int_string_len(MP_NUMER_P(r), radix);
+  
+  if (prec == 0)
+    f_len = 1; /* terminator only */
+  else
+    f_len = 1 + prec + 1; /* decimal point, digits, terminator */
+  
+  return z_len + f_len;
+}
+
+/* }}} */
+
+/* {{{ mp_rat_read_string(r, radix, *str) */
+
+mp_result mp_rat_read_string(mp_rat r, mp_size radix, const char *str)
+{
+  return mp_rat_read_cstring(r, radix, str, NULL);
+}
+
+/* }}} */
+
+/* {{{ mp_rat_read_cstring(r, radix, *str, **end) */
+
+mp_result mp_rat_read_cstring(mp_rat r, mp_size radix, const char *str, 
+			      char **end)
+{
+  mp_result res;
+  char *endp;
+
+  if ((res = mp_int_read_cstring(MP_NUMER_P(r), radix, str, &endp)) != MP_OK &&
+      (res != MP_TRUNC))
+    return res;
+
+  /* Skip whitespace between numerator and (possible) separator */
+  while (isspace((unsigned char) *endp))
+    ++endp;
+  
+  /* If there is no separator, we will stop reading at this point. */
+  if (*endp != '/') {
+    mp_int_set_value(MP_DENOM_P(r), 1);
+    if (end != NULL)
+      *end = endp;
+    return res;
+  }
+  
+  ++endp; /* skip separator */
+  if ((res = mp_int_read_cstring(MP_DENOM_P(r), radix, endp, end)) != MP_OK)
+    return res;
+  
+  /* Make sure the value is well-defined */
+  if (mp_int_compare_zero(MP_DENOM_P(r)) == 0)
+    return MP_UNDEF;
+
+  /* Reduce to lowest terms */
+  return s_rat_reduce(r);
+}
+
+/* }}} */
+
+/* {{{ mp_rat_read_ustring(r, radix, *str, **end) */
+
+/* Read a string and figure out what format it's in.  The radix may be supplied
+   as zero to use "default" behaviour.
+
+   This function will accept either a/b notation or decimal notation.
+ */
+mp_result mp_rat_read_ustring(mp_rat r, mp_size radix, const char *str, 
+			      char **end)
+{
+  char      *endp;
+  mp_result  res;
+
+  if (radix == 0)
+    radix = 10;  /* default to decimal input */
+
+  if ((res = mp_rat_read_cstring(r, radix, str, &endp)) != MP_OK) {
+    if (res == MP_TRUNC) {
+      if (*endp == '.')
+	res = mp_rat_read_cdecimal(r, radix, str, &endp);
+    }
+    else
+      return res;
+  }
+
+  if (end != NULL)
+    *end = endp;
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ mp_rat_read_decimal(r, radix, *str) */
+
+mp_result mp_rat_read_decimal(mp_rat r, mp_size radix, const char *str)
+{
+  return mp_rat_read_cdecimal(r, radix, str, NULL);
+}
+
+/* }}} */
+
+/* {{{ mp_rat_read_cdecimal(r, radix, *str, **end) */
+
+mp_result mp_rat_read_cdecimal(mp_rat r, mp_size radix, const char *str, 
+			       char **end)
+{
+  mp_result res;
+  mp_sign   osign;
+  char *endp;
+
+  while (isspace((unsigned char) *str))
+    ++str;
+  
+  switch (*str) {
+  case '-':
+    osign = MP_NEG;
+    break;
+  default:
+    osign = MP_ZPOS;
+  }
+  
+  if ((res = mp_int_read_cstring(MP_NUMER_P(r), radix, str, &endp)) != MP_OK &&
+     (res != MP_TRUNC))
+    return res;
+
+  /* This needs to be here. */
+  (void) mp_int_set_value(MP_DENOM_P(r), 1);
+
+  if (*endp != '.') {
+    if (end != NULL)
+      *end = endp;
+    return res;
+  }
+
+  /* If the character following the decimal point is whitespace or a sign flag,
+     we will consider this a truncated value.  This special case is because
+     mp_int_read_string() will consider whitespace or sign flags to be valid
+     starting characters for a value, and we do not want them following the
+     decimal point.
+
+     Once we have done this check, it is safe to read in the value of the
+     fractional piece as a regular old integer.
+  */
+  ++endp;
+  if (*endp == '\0') {
+    if (end != NULL)
+      *end = endp;
+    return MP_OK;
+  }
+  else if(isspace((unsigned char) *endp) || *endp == '-' || *endp == '+') {
+    return MP_TRUNC;
+  }
+  else {
+    mpz_t  frac;
+    mp_result save_res;
+    char  *save = endp;
+    int    num_lz = 0;
+
+    /* Make a temporary to hold the part after the decimal point. */
+    if ((res = mp_int_init(&frac)) != MP_OK)
+      return res;
+    
+    if ((res = mp_int_read_cstring(&frac, radix, endp, &endp)) != MP_OK &&
+       (res != MP_TRUNC))
+      goto CLEANUP;
+
+    /* Save this response for later. */
+    save_res = res;
+
+    if (mp_int_compare_zero(&frac) == 0)
+      goto FINISHED;
+
+    /* Discard trailing zeroes (somewhat inefficiently) */
+    while (mp_int_divisible_value(&frac, radix))
+      if ((res = mp_int_div_value(&frac, radix, &frac, NULL)) != MP_OK)
+	goto CLEANUP;
+    
+    /* Count leading zeros after the decimal point */
+    while (save[num_lz] == '0')
+      ++num_lz;
+
+    /* Find the least power of the radix that is at least as large as the
+       significant value of the fractional part, ignoring leading zeroes.  */
+    (void) mp_int_set_value(MP_DENOM_P(r), radix); 
+    
+    while (mp_int_compare(MP_DENOM_P(r), &frac) < 0) {
+      if ((res = mp_int_mul_value(MP_DENOM_P(r), radix, MP_DENOM_P(r))) != MP_OK)
+	goto CLEANUP;
+    }
+    
+    /* Also shift by enough to account for leading zeroes */
+    while (num_lz > 0) {
+      if ((res = mp_int_mul_value(MP_DENOM_P(r), radix, MP_DENOM_P(r))) != MP_OK)
+	goto CLEANUP;
+
+      --num_lz;
+    }
+
+    /* Having found this power, shift the numerator leftward that many, digits,
+       and add the nonzero significant digits of the fractional part to get the
+       result. */
+    if ((res = mp_int_mul(MP_NUMER_P(r), MP_DENOM_P(r), MP_NUMER_P(r))) != MP_OK)
+      goto CLEANUP;
+    
+    { /* This addition needs to be unsigned. */
+      MP_SIGN(MP_NUMER_P(r)) = MP_ZPOS;
+      if ((res = mp_int_add(MP_NUMER_P(r), &frac, MP_NUMER_P(r))) != MP_OK)
+	goto CLEANUP;
+
+      MP_SIGN(MP_NUMER_P(r)) = osign;
+    }
+    if ((res = s_rat_reduce(r)) != MP_OK)
+      goto CLEANUP;
+
+    /* At this point, what we return depends on whether reading the fractional
+       part was truncated or not.  That information is saved from when we
+       called mp_int_read_string() above. */
+  FINISHED:
+    res = save_res;
+    if (end != NULL)
+      *end = endp;
+
+  CLEANUP:
+    mp_int_clear(&frac);
+
+    return res;
+  }
+}
+
+/* }}} */
+
+/* Private functions for internal use.  Make unchecked assumptions about format
+   and validity of inputs. */
+
+/* {{{ s_rat_reduce(r) */
+
+static mp_result s_rat_reduce(mp_rat r)
+{
+  mpz_t gcd;
+  mp_result res = MP_OK;
+
+  if (mp_int_compare_zero(MP_NUMER_P(r)) == 0) {
+    mp_int_set_value(MP_DENOM_P(r), 1);
+    return MP_OK;
+  }
+
+  /* If the greatest common divisor of the numerator and denominator is greater
+     than 1, divide it out. */
+  if ((res = mp_int_init(&gcd)) != MP_OK)
+    return res;
+
+  if ((res = mp_int_gcd(MP_NUMER_P(r), MP_DENOM_P(r), &gcd)) != MP_OK)
+    goto CLEANUP;
+
+  if (mp_int_compare_value(&gcd, 1) != 0) {
+    if ((res = mp_int_div(MP_NUMER_P(r), &gcd, MP_NUMER_P(r), NULL)) != MP_OK)
+      goto CLEANUP;
+    if ((res = mp_int_div(MP_DENOM_P(r), &gcd, MP_DENOM_P(r), NULL)) != MP_OK)
+      goto CLEANUP;
+  }
+
+  /* Fix up the signs of numerator and denominator */
+  if (MP_SIGN(MP_NUMER_P(r)) == MP_SIGN(MP_DENOM_P(r)))
+    MP_SIGN(MP_NUMER_P(r)) = MP_SIGN(MP_DENOM_P(r)) = MP_ZPOS;
+  else {
+    MP_SIGN(MP_NUMER_P(r)) = MP_NEG;
+    MP_SIGN(MP_DENOM_P(r)) = MP_ZPOS;
+  }
+
+ CLEANUP:
+  mp_int_clear(&gcd);
+
+  return res;
+}
+
+/* }}} */
+
+/* {{{ s_rat_combine(a, b, c, comb_f) */
+
+static mp_result s_rat_combine(mp_rat a, mp_rat b, mp_rat c, 
+			       mp_result (*comb_f)(mp_int, mp_int, mp_int))
+{
+  mp_result res;
+
+  /* Shortcut when denominators are already common */
+  if (mp_int_compare(MP_DENOM_P(a), MP_DENOM_P(b)) == 0) {
+    if ((res = (comb_f)(MP_NUMER_P(a), MP_NUMER_P(b), MP_NUMER_P(c))) != MP_OK)
+      return res;
+    if ((res = mp_int_copy(MP_DENOM_P(a), MP_DENOM_P(c))) != MP_OK)
+      return res;
+    
+    return s_rat_reduce(c);
+  }
+  else {
+    mpz_t  temp[2];
+    int    last = 0;
+
+    SETUP(mp_int_init_copy(TEMP(last), MP_NUMER_P(a)), last);
+    SETUP(mp_int_init_copy(TEMP(last), MP_NUMER_P(b)), last);
+    
+    if ((res = mp_int_mul(TEMP(0), MP_DENOM_P(b), TEMP(0))) != MP_OK)
+      goto CLEANUP;
+    if ((res = mp_int_mul(TEMP(1), MP_DENOM_P(a), TEMP(1))) != MP_OK)
+      goto CLEANUP;
+    if ((res = (comb_f)(TEMP(0), TEMP(1), MP_NUMER_P(c))) != MP_OK)
+      goto CLEANUP;
+
+    res = mp_int_mul(MP_DENOM_P(a), MP_DENOM_P(b), MP_DENOM_P(c));
+
+  CLEANUP:
+    while (--last >= 0) 
+      mp_int_clear(TEMP(last));
+
+    if (res == MP_OK)
+      return s_rat_reduce(c);
+    else
+      return res;
+  }
+}
+
+/* }}} */
+
+/* Here there be dragons */

Added: polly/trunk/lib/External/isl/imath/imrat.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/imrat.h?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/imrat.h (added)
+++ polly/trunk/lib/External/isl/imath/imrat.h Wed Feb  4 14:55:43 2015
@@ -0,0 +1,124 @@
+/*
+  Name:     imrat.h
+  Purpose:  Arbitrary precision rational arithmetic routines.
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  Copyright (C) 2002-2007 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#ifndef IMRAT_H_
+#define IMRAT_H_
+
+#include "imath.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct mpq {
+  mpz_t   num;    /* Numerator         */
+  mpz_t   den;    /* Denominator, <> 0 */
+} mpq_t, *mp_rat;
+
+#define MP_NUMER_P(Q)  (&((Q)->num)) /* Pointer to numerator   */
+#define MP_DENOM_P(Q)  (&((Q)->den)) /* Pointer to denominator */
+
+/* Rounding constants */
+typedef enum {
+  MP_ROUND_DOWN,
+  MP_ROUND_HALF_UP,
+  MP_ROUND_UP,
+  MP_ROUND_HALF_DOWN
+} mp_round_mode;
+
+mp_result mp_rat_init(mp_rat r);
+mp_rat    mp_rat_alloc(void);
+mp_result mp_rat_reduce(mp_rat r);
+mp_result mp_rat_init_size(mp_rat r, mp_size n_prec, mp_size d_prec);
+mp_result mp_rat_init_copy(mp_rat r, mp_rat old);
+mp_result mp_rat_set_value(mp_rat r, mp_small numer, mp_small denom);
+mp_result mp_rat_set_uvalue(mp_rat r, mp_usmall numer, mp_usmall denom);
+void      mp_rat_clear(mp_rat r);
+void      mp_rat_free(mp_rat r);
+mp_result mp_rat_numer(mp_rat r, mp_int z);             /* z = num(r)  */
+mp_int    mp_rat_numer_ref(mp_rat r);                   /* &num(r)     */
+mp_result mp_rat_denom(mp_rat r, mp_int z);             /* z = den(r)  */
+mp_int    mp_rat_denom_ref(mp_rat r);                   /* &den(r)     */
+mp_sign   mp_rat_sign(mp_rat r);
+
+mp_result mp_rat_copy(mp_rat a, mp_rat c);              /* c = a       */
+void      mp_rat_zero(mp_rat r);                        /* r = 0       */
+mp_result mp_rat_abs(mp_rat a, mp_rat c);               /* c = |a|     */
+mp_result mp_rat_neg(mp_rat a, mp_rat c);               /* c = -a      */
+mp_result mp_rat_recip(mp_rat a, mp_rat c);             /* c = 1 / a   */
+mp_result mp_rat_add(mp_rat a, mp_rat b, mp_rat c);     /* c = a + b   */
+mp_result mp_rat_sub(mp_rat a, mp_rat b, mp_rat c);     /* c = a - b   */
+mp_result mp_rat_mul(mp_rat a, mp_rat b, mp_rat c);     /* c = a * b   */
+mp_result mp_rat_div(mp_rat a, mp_rat b, mp_rat c);     /* c = a / b   */
+
+mp_result mp_rat_add_int(mp_rat a, mp_int b, mp_rat c); /* c = a + b   */
+mp_result mp_rat_sub_int(mp_rat a, mp_int b, mp_rat c); /* c = a - b   */
+mp_result mp_rat_mul_int(mp_rat a, mp_int b, mp_rat c); /* c = a * b   */
+mp_result mp_rat_div_int(mp_rat a, mp_int b, mp_rat c); /* c = a / b   */
+mp_result mp_rat_expt(mp_rat a, mp_small b, mp_rat c);  /* c = a ^ b   */
+
+int       mp_rat_compare(mp_rat a, mp_rat b);           /* a <=> b     */
+int       mp_rat_compare_unsigned(mp_rat a, mp_rat b);  /* |a| <=> |b| */
+int       mp_rat_compare_zero(mp_rat r);                /* r <=> 0     */
+int       mp_rat_compare_value(mp_rat r, mp_small n, mp_small d); /* r <=> n/d */
+int       mp_rat_is_integer(mp_rat r);
+
+/* Convert to integers, if representable (returns MP_RANGE if not). */
+mp_result mp_rat_to_ints(mp_rat r, mp_small *num, mp_small *den);
+
+/* Convert to nul-terminated string with the specified radix, writing
+   at most limit characters including the nul terminator. */
+mp_result mp_rat_to_string(mp_rat r, mp_size radix, char *str, int limit);
+
+/* Convert to decimal format in the specified radix and precision,
+   writing at most limit characters including a nul terminator. */
+mp_result mp_rat_to_decimal(mp_rat r, mp_size radix, mp_size prec,
+                            mp_round_mode round, char *str, int limit);
+
+/* Return the number of characters required to represent r in the given
+   radix.  May over-estimate. */
+mp_result mp_rat_string_len(mp_rat r, mp_size radix);
+
+/* Return the number of characters required to represent r in decimal
+   format with the given radix and precision.  May over-estimate. */
+mp_result mp_rat_decimal_len(mp_rat r, mp_size radix, mp_size prec);
+
+/* Read zero-terminated string into r */
+mp_result mp_rat_read_string(mp_rat r, mp_size radix, const char *str);
+mp_result mp_rat_read_cstring(mp_rat r, mp_size radix, const char *str,
+			      char **end);
+mp_result mp_rat_read_ustring(mp_rat r, mp_size radix, const char *str,
+			      char **end);
+
+/* Read zero-terminated string in decimal format into r */
+mp_result mp_rat_read_decimal(mp_rat r, mp_size radix, const char *str);
+mp_result mp_rat_read_cdecimal(mp_rat r, mp_size radix, const char *str,
+			       char **end);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* IMRAT_H_ */

Added: polly/trunk/lib/External/isl/imath/imtest.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/imtest.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/imtest.c (added)
+++ polly/trunk/lib/External/isl/imath/imtest.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,474 @@
+/*
+  Name:     imtest.c
+  Purpose:  Test driver for imath library.
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+
+  Reads tests from input files or standard input, and runs them.  Tests have
+  the form:
+
+  code:inputs:outputs
+
+  The 'code' is a string identifying the test to be performed.  The inputs and
+  outputs are comma-separated sequences of values.  The format of each input
+  is:
+
+    1005    number in decimal notation (signs ok)
+    #x-C0E  number in hexadecimal notation
+    #b1011  number in binary notation
+    #o37750 number in octal notation
+    =k      use register k for this input
+
+  For rational tests, the following syntax is also legal:
+    @5.33   use decimal notation (for rationals only)
+            may be combined with radix notation, e.g. #x at A0.5C
+
+  Each output is a string representing the value to which the corresponding
+  result is compared in order to pass the test.  By default, tests are expected
+  to succeed (i.e., return MP_OK).  To specify an alternate return value, use
+  the notation $RESULT, where RESULT is the name of an error (e.g., MP_MEMORY,
+  MP_UNDEF, etc.) or a numeric result denoted $#number (e.g., $#-5).
+
+  Results are written to standard output in the following formats:
+
+  line<tab>number<tab>result<eoln>
+  line<tab>number<tab>result<tab>message<eoln>
+
+  The number is the number of the test in the input (starting from 1).  The
+  result is a textual description of the result code returned by the operation
+  being tested.
+
+  Note:  There is currently a fixed limit on the length of lines by this test
+  ----   driver.  You can increase it if you wish, but the code doesn't check;
+         lines over the length are truncated (split).
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <ctype.h>
+#include <time.h>
+#include <errno.h>
+#include <assert.h>
+
+#include "imath.h"
+#include "imdrover.h"
+
+#ifdef LINE_MAX
+#undef LINE_MAX
+#endif
+
+#define LINE_MAX 4096
+
+typedef struct {
+  char  *code;
+  int    num_inputs;
+  int    num_outputs;
+  test_f call;
+} test_t;
+
+test_t g_tests[] = {                  /* What it does...    */
+  { "initu",   2,  1, test_init},     /* r0 = uv(r1)        */
+  { "initv",   2,  1, test_init},     /* r0 = v(r1)         */
+  { "setu",    2,  1, test_set},      /* r0 = uv(r1)        */
+  { "setv",    2,  1, test_set},      /* r0 = v(r1)         */
+  { "neg",     2,  1, test_neg },     /* r1 = -r0           */
+  { "abs",     2,  1, test_abs },     /* r1 = |r0|          */
+  { "add",     3,  1, test_add },     /* r3 = r1 + r2       */
+  { "addv",    3,  1, test_add },     /* r3 = r1 + v(r2)    */
+  { "sub",     3,  1, test_sub },     /* r3 = r1 - r2       */
+  { "subv",    3,  1, test_sub },     /* r3 = r1 - v(r2)    */
+  { "mul",     3,  1, test_mul },     /* r3 = r1 * r2       */
+  { "mulp2",   3,  1, test_mulp2 },   /* r3 = r1 * 2^v(r2)  */
+  { "mulv",    3,  1, test_mulv },    /* r3 = r1 * v(r2)    */
+  { "sqr",     2,  1, test_sqr },     /* r2 = r1 * r1       */
+  { "div",     4,  2, test_div },     /* r2 = r1 / r2, r3 = r1 % r2         */
+  { "divp2",   4,  2, test_divp2 },   /* r2 = r1 / 2^v(r2),r3 = r1 % 2^v(r2)*/
+  { "divv",    3,  2, test_divv },    /* r2 = r1 / v(r2), r3 = r1 % v(r2)   */
+  { "expt",    3,  1, test_expt },    /* r3 = r1 ^ v(r2) */
+  { "exptv",   3,  1, test_exptv },   /* r3 = v(r1) ^ v(r2) */
+  { "exptf",   3,  1, test_exptf },   /* r3 = r1 ^ r2 */
+  { "mod",     3,  1, test_mod },     /* r3 = r1 % r2       */
+  { "gcd",     3,  1, test_gcd },     /* r3 = gcd(r1, r2)   */
+  { "egcd",    5,  3, test_egcd },    /* r3 = gcd(r1, r2) = r1*r4 + r2*r5   */
+  { "lcm",     3,  1, test_lcm },     /* r3 = lcm(r1, r2)   */
+  { "sqrt",    2,  1, test_sqrt },    /* r2 = sqrt(r1)      */
+  { "root",    3,  1, test_root },    /* r3 = r1^(1/v(r2))  */
+  { "invmod",  3,  1, test_invmod },  /* r3 = r1^-1 mod r2  */
+  { "emod",    4,  1, test_exptmod }, /* r4 = r1^r2 mod r3  */
+  { "emodev",  4,  1, test_exptmod_ev }, /* r4 = r1^v(r2) mod r3  */
+  { "emodbv",  4,  1, test_exptmod_bv }, /* r4 = v(r1)^r2 mod r3  */
+  { "cmp",     2,  1, test_comp },       /* rtn = compare(r1, r2) */
+  { "cmpu",    2,  1, test_ucomp },      /* rtn = compare(|r1|, |r2|) */
+  { "cmpz",    1,  1, test_zcomp },      /* rtn = compare(r1, 0)      */
+  { "cmpv",    2,  1, test_vcomp },      /* rtn = compare(r1, v(r2))  */
+  { "cmpuv",   2,  1, test_uvcomp },     /* rtn = compare(r1, v(r2))  */
+  { "tostr",   2,  1, test_tostr },      /* r1: value, r2: radix, o1: result */
+  { "tobin",   1,  1, test_tobin },      /* r1: value, o1: result binary     */
+  { "readbin", 1,  1, test_read_binary },/* r1: 2's comp, o1: result value   */
+  { "to-uns",  1,  1, test_to_uns },     /* r1: value, o1: result binary     */
+  { "readuns", 1,  1, test_read_uns },   /* r1: unsigned, o1: result value   */
+  { "to-int",  1,  1, test_to_int },     /* r1: value, o1: result */
+  { "to-uint", 1,  1, test_to_uint },    /* r1: value, o1: result */
+  { "meta",   -1, -1, test_meta },
+  { "qneg",    2,  1, test_qneg },       /* r2 = -r1        */
+  { "qrecip",  2,  1, test_qrecip },     /* r2 = 1 / r1     */
+  { "qabs",    2,  1, test_qabs },       /* r2 = |r1|       */
+  { "qadd",    3,  1, test_qadd },       /* r3 = r1 + r2    */
+  { "qsub",    3,  1, test_qsub },       /* r3 = r1 - r2    */
+  { "qmul",    3,  1, test_qmul },       /* r3 = r1 * r2    */
+  { "qdiv",    3,  1, test_qdiv },       /* r3 = r1 / r2    */
+  { "qaddz",   3,  1, test_qaddz },      /* r3 = r1 + r2    */
+  { "qsubz",   3,  1, test_qsubz },      /* r3 = r1 - r2    */
+  { "qmulz",   3,  1, test_qmulz },      /* r3 = r1 * r2    */
+  { "qdivz",   3,  1, test_qdivz },      /* r3 = r1 / r2    */
+  { "qexpt",   3,  1, test_qexpt },      /* r3 = r1 ^ v(r2) */
+  { "qtostr",  2,  1, test_qtostr },     /* r1: value, r2: radix; o1: result */
+  { "qtodec",  4,  1, test_qtodec },     /* r1: val, r2: rdx, r3: prec,
+                                            r4: rounding mode; o1: res */
+  { "qrdec",   2,  1, test_qrdec },   /* r1: dec, r2: rdx; o1: result value  */
+  { NULL, 0, 0, NULL } /* end of list marker */
+};
+
+char      g_line[LINE_MAX];
+
+extern mp_result imath_errno;
+extern char *imath_errmsg;
+
+const char *g_imath_strerr[] = {
+  "MP_OK",    "MP_TRUE",  "MP_MEMORY",  "MP_RANGE",
+  "MP_UNDEF", "MP_TRUNC", "MP_BADARG"
+};
+
+int  process_file(FILE *ifp, FILE *ofp);
+int  read_line(FILE *ifp, char *line, int limit);
+void trim_line(char *line);
+int  is_blank(char *line);
+int  parse_line(char *line, testspec_t *t);
+int  count_fields(char *line, int delim);
+void parse_fields(char *line, int delim, char **start);
+int  run_test(int test_num, testspec_t *t, FILE *ofp);
+void free_test(testspec_t *t);
+int  find_test(char *code, test_t *info);
+char *error_string(mp_result res);
+
+int main(int argc, char *argv[])
+{
+  int exit_status = 0;
+
+  init_testing();
+
+  if (argc == 1) {
+    process_file(stdin, stdout);
+  }
+  else {
+    FILE *ifp;
+    int i;
+
+    for (i = 1; i < argc; ++i) {
+      if (strcmp(argv[i], "-") == 0) {
+	ifp = stdin;
+	printf("# [stdin]\n");
+      }
+      else if ((ifp = fopen(argv[i], "r")) == NULL) {
+	fprintf(stderr, "Cannot open '%s': %s\n",
+		argv[i], strerror(errno));
+	return 1;
+      }
+      else {
+	printf("# %s\n", argv[i]);
+      }
+
+      if (process_file(ifp, stdout) != 0)
+	exit_status = 1;
+
+      fclose(ifp);
+    }
+  }
+  return exit_status;
+}
+
+/* {{{ process_file(ifp, ofp) */
+
+int process_file(FILE *ifp, FILE *ofp)
+{
+  int        res, line_num, test_num = 0, num_failed = 0, num_bogus = 0;
+  clock_t    start, finish;
+  testspec_t t;
+
+  start = clock();
+  while ((line_num = read_line(ifp, g_line, LINE_MAX)) != 0) {
+    if (parse_line(g_line, &t)) {
+      t.line = line_num;
+      if ((res = run_test(++test_num, &t, ofp)) < 0)
+	++num_bogus;
+      else if (!res)
+	++num_failed;
+
+      free_test(&t);
+    }
+    else {
+      fprintf(stderr, "Line %d: Incorrect input syntax.\n", line_num);
+    }
+  }
+  finish = clock();
+
+  fprintf(ofp, "# %d tests: %d passed, %d failed, %d errors. (%.2f seconds)\n",
+	  test_num, (test_num - num_failed - num_bogus), num_failed, num_bogus,
+	  ((double)(finish - start) / CLOCKS_PER_SEC));
+
+  return num_failed;
+}
+
+/* }}} */
+
+/* {{{ read_line(ifp, line, limit) */
+
+int  read_line(FILE *ifp, char *line, int limit)
+{
+  static FILE *current_fp = NULL;
+  static int   current_line = 0;
+
+  if (ifp != current_fp) {
+    current_fp = ifp;
+    current_line = 0;
+  }
+
+  do {
+    if (fgets(line, limit, ifp) == NULL)
+      return 0;
+
+    ++current_line;
+  } while (is_blank(line));
+
+  trim_line(line);
+  return current_line;
+}
+
+/* }}} */
+
+/* {{{ trim_line(line) */
+
+void trim_line(char *line)
+{
+  int len;
+  char *fnw = line;
+
+  /* Remove leading whitespace */
+  while (isspace((unsigned char) *fnw))
+    ++fnw;
+
+  len = strlen(fnw);
+  memmove(line, fnw, len);
+
+  /* Remove trailing whitespace (including linefeeds) */
+  fnw = line + len - 1;
+  while (fnw >= line && isspace((unsigned char) *fnw))
+    *fnw-- = '\0';
+}
+
+/* }}} */
+
+/* {{{ is_blank(line) */
+
+int  is_blank(char *line)
+{
+  while (*line && *line != '#' && isspace((unsigned char) *line))
+    ++line;
+
+  return *line == '\0' || *line == '#';
+}
+
+/* }}} */
+
+/* {{{ parse_line(line, t) */
+
+int  parse_line(char *line, testspec_t *t)
+{
+  char *code_brk, *in_brk;
+  int   num_fields;
+
+  if ((code_brk = strchr(line, ':')) == NULL)
+    return 0;
+  if ((in_brk = strchr(code_brk + 1, ':')) == NULL)
+    return 0;
+
+  *code_brk = '\0';
+  t->code = line;
+  *in_brk = '\0';
+
+  num_fields = count_fields(code_brk + 1, ',');
+  t->num_inputs = num_fields;
+
+  num_fields = count_fields(in_brk + 1, ',');
+  t->num_outputs = num_fields;
+
+  if (t->num_inputs > 0) {
+    t->input = calloc(t->num_inputs, sizeof(char *));
+    parse_fields(code_brk + 1, ',', t->input);
+  }
+  if (t->num_outputs > 0) {
+    t->output = calloc(t->num_outputs, sizeof(char *));
+    parse_fields(in_brk + 1, ',', t->output);
+  }
+  return 1;
+}
+
+/* }}} */
+
+/* {{{ count_fields(line, delim) */
+
+int  count_fields(char *line, int delim)
+{
+  int count = 1;
+
+  if (*line == '\0')
+    return 0;
+
+  while (*line) {
+    if (*line == (char)delim && *(line+1) != '\0')
+      ++count;
+    ++line;
+  }
+  return count;
+}
+
+/* }}} */
+
+/* {{{ parse_fields(line, delim, start) */
+
+void parse_fields(char *line, int delim, char **start)
+{
+  int pos = 0;
+
+  start[pos++] = line;
+  while ((line = strchr(line, delim)) != NULL) {
+    *line++ = '\0';
+    start[pos++] = line;
+  }
+}
+
+/* }}} */
+
+/* {{{ run_test(test_num, t, ofp) */
+
+int  run_test(int test_num, testspec_t *t, FILE *ofp)
+{
+  test_t info;
+
+  /* Look up and reality check test parameters */
+  if (find_test(t->code, &info) < 0) {
+    fprintf(stderr, "Line %d: Test code '%s' is unknown.\n",
+	    t->line, t->code);
+    return -1;
+  }
+  else {
+    int errs = 0;
+
+    if (info.num_inputs >= 0 && t->num_inputs != info.num_inputs) {
+      fprintf(stderr,
+	      "Line %d: Wrong number of inputs to %s (want %d, have %d)\n",
+	      t->line, t->code, info.num_inputs, t->num_inputs);
+      ++errs;
+    }
+    if (info.num_outputs >= 0 && t->num_outputs != info.num_outputs) {
+      fprintf(stderr,
+	      "Line %d: Wrong number of outputs to %s (want %d, have %d)\n",
+	      t->line, t->code, info.num_outputs, t->num_outputs);
+      ++errs;
+    }
+    if (errs) {
+      fprintf(stderr, "Line %d: %d error(s), skipping this test.\n",
+	      t->line, errs);
+      return -1;
+    }
+  }
+
+  /* If return value is true, just print a generic OK message;
+     otherwise, it is assumed that imath_errno has been set to
+     a value indicating the problem. */
+  if ((info.call)(t, ofp)) {
+    fprintf(ofp, "%d\t%d\tOK\n", t->line, test_num);
+    return 1;
+  }
+  else if(imath_errno >= MP_BADARG) {
+    fprintf(ofp, "%d\t%d\t%s\n",
+	    t->line, test_num, error_string(imath_errno));
+  }
+  else {
+    fprintf(ofp, "%d\t%d\tFAILED\t%s\n",
+	    t->line, test_num, imath_errmsg);
+  }
+  return 0;
+}
+
+/* }}} */
+
+/* {{{ find_test(code, info) */
+
+int  find_test(char *code, test_t *info)
+{
+  int i = 0;
+
+  while (g_tests[i].code != NULL) {
+    if (strcmp(g_tests[i].code, code) == 0) {
+      *info = g_tests[i];
+      return i;
+    }
+    ++i;
+  }
+  return -1;
+}
+
+/* }}} */
+
+/* {{{ free_test(*t) */
+
+void free_test(testspec_t *t)
+{
+  assert(t != NULL);
+
+  if (t->input != NULL) {
+    free(t->input);
+    t->input = NULL;
+  }
+  if (t->output != NULL) {
+    free(t->output);
+    t->output = NULL;
+  }
+}
+
+/* }}} */
+
+/* {{{ error_string(res) */
+
+char *error_string(mp_result res)
+{
+  int v = abs(res);
+
+  return (char *)g_imath_strerr[v];
+}
+
+/* }}} */
+
+/* Here there be dragons */

Added: polly/trunk/lib/External/isl/imath/imtimer.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/imtimer.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/imtimer.c (added)
+++ polly/trunk/lib/External/isl/imath/imtimer.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,259 @@
+/*
+  Name:     imtimer.c
+  Purpose:  Timing tests for the imath library.
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <time.h>
+
+#include <unistd.h>
+
+#include "imath.h"
+
+extern mp_size multiply_threshold; /* global in imath.c */
+extern mp_size default_precision;  /* global in imath.c */
+
+double clocks_to_seconds(clock_t start, clock_t end);
+double get_multiply_time(int nt, int prec);
+double get_exptmod_time(int nt, int prec);
+mp_int alloc_values(int nt, int prec);
+void   randomize_values(mp_int values, int nt, int prec);
+void   release_values(mp_int values, int nt);
+void   mp_int_random(mp_int z, int prec);
+
+const int g_mul_factor = 1000;
+
+int main(int argc, char *argv[])
+{
+  int do_mul = 0, do_exp = 0, do_header = 1;
+  int num_tests, precision = default_precision, opt;
+  unsigned int seed = (unsigned int) time(NULL);
+
+  while ((opt = getopt(argc, argv, "ehmnp:s:t:")) != EOF) {
+    switch (opt) {
+    case 'e':
+      do_exp = 1;
+      break;
+    case 'm':
+      do_mul = 1;
+      break;
+    case 'n':
+      do_header = 0;
+      break;
+    case 'p':
+      precision = atoi(optarg);
+      break;
+    case 's':
+      seed = atoi(optarg);
+      break;
+    case 't':
+      multiply_threshold = (mp_size) atoi(optarg);
+      break;
+    default:
+      fprintf(stderr, "Usage:  imtimer [options] <num-tests>\n\n"
+              "Options understood:\n"
+              " -e        -- test modular exponentiation speed.\n"
+              " -h        -- display this help message.\n"
+              " -m        -- test multiplication speed.\n"
+              " -n        -- no header line.\n"
+              " -p <dig>  -- use values with <dig> digits.\n"
+              " -s <rnd>  -- set random seed to <rnd>.\n"
+              " -t <dig>  -- set recursion threshold to <dig> digits.\n\n");
+      return (opt != 'h');
+    }
+  }
+
+  if (optind >= argc) {
+    fprintf(stderr, "Usage:  imtimer [options] <num-tests>\n"
+            "[use \"imtimer -h\" for help with options]\n\n");
+    return 1;
+  }
+  else
+    num_tests = atoi(argv[optind]);
+
+  srand(seed);
+
+  if (num_tests <= 0) {
+    fprintf(stderr, "You must request at least one test.\n");
+    return 1;
+  }
+  if (precision <= 0) {
+    fprintf(stderr, "Precision must be positive.\n");
+    return 1;
+  } 
+  
+  if (do_header)
+    printf("NUM\tPREC\tBITS\tREC\tRESULT\n");
+  printf("%d\t%d\t%d\t%u", num_tests, precision,
+         (int) (precision * MP_DIGIT_BIT), 
+         multiply_threshold);
+
+  if (do_mul) {
+    double m_time = get_multiply_time(num_tests, precision);
+    
+    printf("\tMUL %.3f %.3f", m_time, m_time / num_tests);
+  }
+
+  if (do_exp) {
+    double e_time = get_exptmod_time(num_tests, precision);
+    
+    printf("\tEXP %.3f %.3f", e_time, e_time / num_tests);
+  }
+  fputc('\n', stdout);
+  fflush(stdout);
+
+  return 0;
+}
+
+/* {{{ clocks_to_seconds(start, end) */
+
+double clocks_to_seconds(clock_t start, clock_t end)
+{
+  return (double)(end - start) / CLOCKS_PER_SEC;
+}
+
+/* }}} */
+
+/* {{{ alloc_values(nt, prec) */
+
+mp_int alloc_values(int nt, int prec)
+{
+  mp_int out = malloc(nt * sizeof(mpz_t));
+  int i;
+
+  if (out == NULL)
+    return NULL;
+
+  for (i = 0; i < nt; ++i) {
+    if (mp_int_init_size(out + i, prec) != MP_OK) {
+      while (--i >= 0)
+	mp_int_clear(out + i);
+      return NULL;
+    }
+  }
+  
+  return out;
+}
+
+/* }}} */
+
+/* {{{ randomize_values(values, nt, prec) */
+
+void   randomize_values(mp_int values, int nt, int prec)
+{
+  int i;
+  
+  for (i = 0; i < nt; ++i)
+    mp_int_random(values + i, prec);
+}
+
+/* }}} */
+
+/* {{{ release_values(values, nt) */
+
+void   release_values(mp_int values, int nt)
+{
+  int i;
+
+  for (i = 0; i < nt; ++i)
+    mp_int_clear(values + i);
+
+  free(values);
+}
+
+/* }}} */
+
+/* {{{ get_multiply_time(nt, prec) */
+
+double get_multiply_time(int nt, int prec)
+{
+  clock_t start, end;
+  mp_int values;
+  int i;
+
+  if ((values = alloc_values(3, prec)) == NULL)
+    return 0.0;
+  randomize_values(values, 2, prec);
+
+  start = clock(); 
+  for (i = 0; i < nt; ++i)
+    mp_int_mul(values, values + 1, values + 2);
+  end = clock();
+
+  release_values(values, 3);
+
+  return clocks_to_seconds(start, end);
+}
+
+/* }}} */
+
+/* {{{ get_exptmod_time(nt, prec) */
+
+double get_exptmod_time(int nt, int prec)
+{
+  clock_t start, end;
+  mp_int values;
+  int i;
+
+  if ((values = alloc_values(4, prec)) == NULL)
+    return 0.0;
+  randomize_values(values, 3, prec);
+
+  start = clock(); 
+  for (i = 0; i < nt; ++i)
+    mp_int_exptmod(values, values + 1, values + 2, values + 3);
+  end = clock();
+
+  release_values(values, 4);
+
+  return clocks_to_seconds(start, end);
+}
+
+/* }}} */
+
+/* {{{ mp_int_random(z, prec) */
+
+void   mp_int_random(mp_int z, int prec)
+{
+  int i;
+
+  if (prec > MP_ALLOC(z))
+    prec = MP_ALLOC(z);
+
+  for (i = 0; i < prec; ++i) {
+    mp_digit d = 0;
+    int j;
+    
+    for (j = 0; j < sizeof(d); ++j)
+      d = (d << CHAR_BIT) | (rand() & UCHAR_MAX);
+    
+    z->digits[i] = d;
+  }
+  MP_USED(z) = prec;
+}
+
+/* }}} */

Added: polly/trunk/lib/External/isl/imath/iprime.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/iprime.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/iprime.c (added)
+++ polly/trunk/lib/External/isl/imath/iprime.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,116 @@
+/*
+  Name:     iprime.c
+  Purpose:  Pseudoprimality testing routines
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#include "iprime.h"
+#include <stdlib.h>
+
+static int s_ptab_size = 168;
+static int s_ptab[] = {
+  2,   3,   5,   7,   11,  13,  17,  19,  23,  29,  31,  37,  41,  43,
+  47,  53,  59,  61,  67,  71,  73,  79,  83,  89,  97,  101, 103, 107,
+  109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,
+  191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263,
+  269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
+  353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433,
+  439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521,
+  523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613,
+  617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,
+  709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809,
+  811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887,
+  907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997
+};
+
+/* {{{ mp_int_is_prime(z) */
+
+/* Test whether z is likely to be prime:
+   MP_TRUE  means it is probably prime
+   MP_FALSE means it is definitely composite
+ */
+mp_result mp_int_is_prime(mp_int z)
+{
+  int       i;
+  mp_small  rem;
+  mp_result res;
+
+  /* First check for divisibility by small primes; this eliminates a large
+     number of composite candidates quickly
+   */
+  for(i = 0; i < s_ptab_size; ++i) {
+    if((res = mp_int_div_value(z, s_ptab[i], NULL, &rem)) != MP_OK)
+      return res;
+
+    if(rem == 0)
+      return MP_FALSE;
+  }
+
+  /* Now try Fermat's test for several prime witnesses (since we now know from
+     the above that z is not a multiple of any of them)
+   */
+  {
+    mpz_t  tmp;
+
+    if((res = mp_int_init(&tmp)) != MP_OK) return res;
+
+    for(i = 0; i < 10 && i < s_ptab_size; ++i) {
+      if((res = mp_int_exptmod_bvalue(s_ptab[i], z, z, &tmp)) != MP_OK)
+	return res;
+
+      if(mp_int_compare_value(&tmp, s_ptab[i]) != 0) {
+	mp_int_clear(&tmp);
+	return MP_FALSE;
+      }
+    }
+
+    mp_int_clear(&tmp);
+  }
+
+  return MP_TRUE;
+}
+
+/* }}} */
+
+/* {{{ mp_int_find_prime(z) */
+
+/* Find the first apparent prime in ascending order from z */
+mp_result mp_int_find_prime(mp_int z)
+{
+  mp_result  res;
+
+  if(mp_int_is_even(z) && ((res = mp_int_add_value(z, 1, z)) != MP_OK))
+    return res;
+
+  while((res = mp_int_is_prime(z)) == MP_FALSE) {
+    if((res = mp_int_add_value(z, 2, z)) != MP_OK)
+      break;
+
+  }
+
+  return res;
+}
+
+/* }}} */
+
+/* Here there be dragons */

Added: polly/trunk/lib/External/isl/imath/iprime.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/iprime.h?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/iprime.h (added)
+++ polly/trunk/lib/External/isl/imath/iprime.h Wed Feb  4 14:55:43 2015
@@ -0,0 +1,48 @@
+/*
+  Name:     iprime.h
+  Purpose:  Pseudoprimality testing routines
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#ifndef IPRIME_H_
+#define IPRIME_H_
+
+#include "imath.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Test whether z is likely to be prime
+   MP_YES means it is probably prime
+   MP_NO  means it is definitely composite
+ */
+mp_result mp_int_is_prime(mp_int z);
+
+/* Find the first apparent prime in ascending order from z */
+mp_result mp_int_find_prime(mp_int z);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* IPRIME_H_ */

Added: polly/trunk/lib/External/isl/imath/pi.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/pi.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/pi.c (added)
+++ polly/trunk/lib/External/isl/imath/pi.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,177 @@
+/*
+  Name:     pi.c
+  Purpose:  Computes digits of the physical constant pi.
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
+
+  Notes:
+  Uses Machin's formula, which should be suitable for a few thousand digits.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "imath.h"
+
+int g_radix = 10; /* use this radix for output */
+
+mp_result arctan(mp_small radix, mp_small mul, mp_small x, 
+		 mp_small prec, mp_int sum);
+
+char g_buf[4096];
+
+int main(int argc, char *argv[]) 
+{
+  mp_result  res;
+  mpz_t      sum1, sum2;
+  int        ndigits, out = 0;
+  clock_t    start, end;
+
+  if(argc < 2) {
+    fprintf(stderr, "Usage: %s <num-digits> [<radix>]\n", argv[0]);
+    return 1;
+  }
+
+  if((ndigits = abs(atoi(argv[1]))) == 0) {
+    fprintf(stderr, "%s: you must request at least 1 digit\n", argv[0]);
+    return 1;
+  } else if(ndigits > MP_DIGIT_MAX) {
+    fprintf(stderr, "%s: you may request at most %u digits\n", 
+	    argv[0], (unsigned int)MP_DIGIT_MAX);
+    return 1;
+  }
+
+  if(argc > 2) {
+    int radix = atoi(argv[2]);
+
+    if(radix < MP_MIN_RADIX || radix > MP_MAX_RADIX) {
+      fprintf(stderr, "%s: you may only specify a radix between %d and %d\n",
+	      argv[0], MP_MIN_RADIX, MP_MAX_RADIX);
+      return 1;
+    }
+    g_radix = radix;
+  }
+
+  mp_int_init(&sum1); mp_int_init(&sum2);
+  start = clock();
+
+  /* sum1 = 16 * arctan(1/5) */
+  if((res = arctan(g_radix, 16, 5, ndigits, &sum1)) != MP_OK) {
+    fprintf(stderr, "%s: error computing arctan: %d\n", argv[0], res);
+    out = 1; goto CLEANUP;
+  }
+
+  /* sum2 = 4 * arctan(1/239) */
+  if((res = arctan(g_radix, 4, 239, ndigits, &sum2)) != MP_OK) {
+    fprintf(stderr, "%s: error computing arctan: %d\n", argv[0], res);
+    out = 1; goto CLEANUP;
+  }
+
+  /* pi = sum1 - sum2 */
+  if((res = mp_int_sub(&sum1, &sum2, &sum1)) != MP_OK) {
+    fprintf(stderr, "%s: error computing pi: %d\n", argv[0], res);
+    out = 1; goto CLEANUP;
+  }
+  end = clock();
+
+  mp_int_to_string(&sum1, g_radix, g_buf, sizeof(g_buf));
+  printf("%c.%s\n", g_buf[0], g_buf + 1);
+
+  fprintf(stderr, "Computation took %.2f sec.\n",
+	  (double)(end - start) / CLOCKS_PER_SEC);
+
+ CLEANUP:
+  mp_int_clear(&sum1);
+  mp_int_clear(&sum2);
+
+  return out;
+}
+
+/* {{{ arctan(radix, mul, x, prec, sum) */
+
+/*
+  Compute mul * atan(1/x) to prec digits of precision, and store the
+  result in sum.
+
+  Computes atan(1/x) using the formula:
+
+               1     1      1      1  
+  atan(1/x) = --- - ---- + ---- - ---- + ...
+               x    3x^3   5x^5   7x^7
+  
+ */
+mp_result arctan(mp_small radix, mp_small mul, mp_small x, 
+		 mp_small prec, mp_int sum)
+{
+  mpz_t   t, v;
+  mp_result res;
+  mp_small  rem, sign = 1, coeff = 1;
+
+  mp_int_init(&t);
+  mp_int_init(&v);
+  ++prec;
+
+  /* Compute mul * radix^prec * x
+     The initial multiplication by x saves a special case in the loop for
+     the first term of the series.
+   */
+  if((res = mp_int_expt_value(radix, prec, &t)) != MP_OK ||
+     (res = mp_int_mul_value(&t, mul, &t)) != MP_OK ||
+     (res = mp_int_mul_value(&t, x, &t)) != MP_OK)
+    goto CLEANUP;
+
+  x *= x; /* assumes x <= sqrt(MP_SMALL_MAX) */
+  mp_int_zero(sum);
+
+  do {
+    if((res = mp_int_div_value(&t, x, &t, &rem)) != MP_OK)
+      goto CLEANUP;
+
+    if((res = mp_int_div_value(&t, coeff, &v, &rem)) != MP_OK)
+      goto CLEANUP;
+
+    /* Add or subtract the result depending on the current sign (1 = add) */
+    if(sign > 0) 
+      res = mp_int_add(sum, &v, sum);
+    else
+      res = mp_int_sub(sum, &v, sum);
+
+    if(res != MP_OK) goto CLEANUP;
+    sign = -sign;
+    coeff += 2;
+
+  } while(mp_int_compare_zero(&t) != 0);
+
+  res = mp_int_div_value(sum, radix, sum, NULL);
+
+ CLEANUP:
+  mp_int_clear(&v);
+  mp_int_clear(&t);
+  
+  return res;
+}
+
+/* }}} */
+
+/* Here there be dragons */

Added: polly/trunk/lib/External/isl/imath/rsamath.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/rsamath.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/rsamath.c (added)
+++ polly/trunk/lib/External/isl/imath/rsamath.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,203 @@
+/*
+  Name:     rsamath.c
+  Purpose:  Implements part of PKCS#1, v. 2.1, June 14, 2002 (RSA Labs)
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#include "rsamath.h"
+
+#include <string.h>
+#include <limits.h>
+
+static mp_result s_rsa_transform(mp_int msg, mp_int exp, 
+				 mp_int mod, mp_int out);
+
+/* {{{ rsa_i2osp(z, out, len) */
+
+/* Convert integer to octet string, per PKCS#1 v.2.1 */
+mp_result rsa_i2osp(mp_int z, unsigned char *out, int len)
+{
+  int  excess_len = mp_int_binary_len(z);
+
+  if(excess_len < len)
+    return MP_RANGE;
+
+  memset(out, 0, len);
+
+  excess_len -= len;
+  mp_int_to_binary(z, out + excess_len, len);
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ rsa_os2ip(z, in, len) */
+
+/* Convert octet string to integer, per PKCS#1 v.2.1 */
+mp_result rsa_os2ip(mp_int z, unsigned char *in, int len)
+{
+  return mp_int_read_binary(z, in, len);
+}
+
+/* }}} */
+
+/* {{{ rsa_rsaep(msg, exp, mod, cipher) */
+
+/* Primitive RSA encryption operation */
+mp_result rsa_rsaep(mp_int msg, mp_int exp, mp_int mod, mp_int cipher)
+{
+  return s_rsa_transform(msg, exp, mod, cipher);
+}
+
+/* }}} */
+
+/* {{{ rsa_rsadp(cipher, exp, mod, msg) */
+
+/* Primitive RSA decryption operation */
+mp_result rsa_rsadp(mp_int cipher, mp_int exp, mp_int mod, mp_int msg)
+{
+  return s_rsa_transform(cipher, exp, mod, msg);
+}
+
+/* }}} */
+
+/* {{{ rsa_rsasp(msg, exp, mod, signature) */
+
+/* Primitive RSA signing operation */
+mp_result rsa_rsasp(mp_int msg, mp_int exp, mp_int mod, mp_int signature)
+{
+  return s_rsa_transform(msg, exp, mod, signature);
+}
+
+/* }}} */
+
+/* {{{ rsa_rsavp(signature, exp, mod, msg) */
+
+/* Primitive RSA verification operation */
+mp_result rsa_rsavp(mp_int signature, mp_int exp, mp_int mod, mp_int msg)
+{
+  return s_rsa_transform(signature, exp, mod, msg);
+}
+
+/* }}} */
+
+/* {{{ rsa_max_message_len(mod) */
+
+/* Compute the maximum length in bytes a message can have using PKCS#1
+   v.1.5 encoding with the given modulus */
+int       rsa_max_message_len(mp_int mod)
+{
+  int  num_bits = mp_int_count_bits(mod);
+  int  num_bytes = num_bits / CHAR_BIT;
+
+  if(num_bytes < 11)
+    return 0; /* at least eleven bytes are required for padding */
+  else
+    return num_bytes - 11;
+}
+
+/* }}} */
+
+/* {{{ rsa_pkcs1v15_encode(buf, msg_len, buf_len, tag, filler) */
+
+mp_result rsa_pkcs1v15_encode(unsigned char *buf, int msg_len, 
+			      int buf_len, int tag, random_f filler)
+{
+  int  pad_len, msg_start;
+
+  /* Make sure there is enough space for the encoded output */
+  if(msg_len > (buf_len - 11))
+    return MP_RANGE;
+
+  msg_start = buf_len - msg_len;
+  pad_len = msg_start - 3;
+
+  /* Move message to top of buffer -- these might overlap, so we rely
+     on the semantics of memmove() here */
+  memmove(buf + msg_start, buf, msg_len);
+
+  /* Set initial bytes as required by the specification */
+  buf[0] = 0x00;
+  buf[1] = (unsigned char)tag;
+
+  /* Fill with random padding.  We'll just assume the filler function
+     does the right thing and only writes the requested number of
+     nonzero bytes */
+  (filler)(buf + 2, pad_len);
+
+  /* Write separator between pad and message body */
+  buf[msg_start - 1] = 0x00;
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ rsa_pkcs1v15_decode(buf, buf_len, *msg_len) */
+
+mp_result rsa_pkcs1v15_decode(unsigned char *buf, int buf_len, 
+			      int tag, int *msg_len)
+{
+  int  pad_len = 0, data_len, data_start, i;
+
+  /* Make sure the buffer is syntactically valid */
+  if(buf_len < 11 || buf[0] != 0x00 || buf[1] != (unsigned char)tag)
+    return MP_UNDEF;
+
+  /* Figure out how many bytes of random padding there are */
+  i = 2;
+  while(buf[i++] != '\0')
+    ++pad_len;
+
+  data_start = i;
+  data_len = buf_len - data_start;
+
+  /* Shift the message to the front of the buffer */
+  memmove(buf, buf + data_start, data_len);
+
+  /* Zero out the rest of the buffer */
+  memset(buf + data_len, 0, pad_len + 3);
+
+  *msg_len = data_len;
+
+  return MP_OK;
+}
+
+/* }}} */
+
+/* {{{ s_rsa_transform(msg, exp, mod, out) */
+
+static mp_result s_rsa_transform(mp_int msg, mp_int exp, 
+				 mp_int mod, mp_int out)
+{
+  if(mp_int_compare_zero(msg) < 0 ||
+     mp_int_compare(msg, mod) >= 0)
+    return MP_RANGE;
+
+  return mp_int_exptmod(msg, exp, mod, out);
+}
+
+/* }}} */
+
+/* Here there be dragons */

Added: polly/trunk/lib/External/isl/imath/rsamath.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/rsamath.h?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/rsamath.h (added)
+++ polly/trunk/lib/External/isl/imath/rsamath.h Wed Feb  4 14:55:43 2015
@@ -0,0 +1,94 @@
+/*
+  Name:     rsamath.h
+  Purpose:  Implements part of PKCS#1, v. 2.1, June 14, 2002 (RSA Labs)
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+
+  Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#ifndef RSAMATH_H_
+#define RSAMATH_H_
+
+#include "imath.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Function to fill a buffer with nonzero random bytes */
+typedef void (*random_f)(unsigned char *, int);
+
+/* Convert integer to octet string, per PKCS#1 v.2.1 */
+mp_result rsa_i2osp(mp_int z, unsigned char *out, int len);
+
+/* Convert octet string to integer, per PKCS#1 v.2.1 */
+mp_result rsa_os2ip(mp_int z, unsigned char *in, int len);
+
+/* The following operations assume that you have converted your keys
+   and message data into mp_int values somehow.                      */
+
+/* Primitive RSA encryption operation */
+mp_result rsa_rsaep(mp_int msg, mp_int exp, mp_int mod, mp_int cipher);
+
+/* Primitive RSA decryption operation */
+mp_result rsa_rsadp(mp_int cipher, mp_int exp, mp_int mod, mp_int msg);
+
+/* Primitive RSA signing operation */
+mp_result rsa_rsasp(mp_int msg, mp_int exp, mp_int mod, mp_int signature);
+
+/* Primitive RSA verification operation */
+mp_result rsa_rsavp(mp_int signature, mp_int exp, mp_int mod, mp_int msg);
+
+/* Compute the maximum length in bytes a message can have using PKCS#1
+   v.1.5 encoding with the given modulus */
+int       rsa_max_message_len(mp_int mod);
+
+/* Encode a raw message per PKCS#1 v.1.5
+   buf      - the buffer containing the message
+   msg_len  - the length in bytes of the message
+   buf_len  - the size in bytes of the buffer
+   tag      - the message tag (nonzero byte)
+   filler   - function to generate pseudorandom nonzero padding
+
+   On input, the message is in the first msg_len bytes of the buffer;
+   on output, the contents of the buffer are replaced by the padded
+   message.  If there is not enough room, MP_RANGE is returned.
+ */
+mp_result rsa_pkcs1v15_encode(unsigned char *buf, int msg_len, 
+			      int buf_len, int tag, random_f filler);
+
+/* Decode a PKCS#1 v.1.5 message back to its raw form 
+   buf      - the buffer containing the encoded message
+   buf_len  - the length in bytes of the buffer
+   tag      - the expected message tag (nonzero byte)
+   msg_len  - on output, receives the length of the message content
+   
+   On output, the message is packed into the first msg_len bytes of
+   the buffer, and the rest of the buffer is zeroed.  If the buffer is
+   not of the correct form, MP_UNDEF is returned and msg_len is undefined.
+ */
+mp_result rsa_pkcs1v15_decode(unsigned char *buf, int buf_len, 
+			      int tag, int *msg_len);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* end RSAMATH_H_ */

Added: polly/trunk/lib/External/isl/imath/rtest.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/imath/rtest.c?rev=228193&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/imath/rtest.c (added)
+++ polly/trunk/lib/External/isl/imath/rtest.c Wed Feb  4 14:55:43 2015
@@ -0,0 +1,124 @@
+/* 
+  Name:     rtest.c
+  Purpose:  Test routines for RSA implementation.
+  Author:   M. J. Fromberger <http://spinning-yarns.org/michael/>
+  
+  Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <time.h>
+
+#include "rsamath.h"
+
+void random_fill(unsigned char *buf, int len);
+void print_buf(unsigned char *buf, int len, int brk, FILE *ofp);
+
+int main(int argc, char *argv[])
+{
+  int buf_len, msg_len, i;
+  unsigned char *buf;
+  mp_result      res;
+
+  if(argc < 3) {
+    fprintf(stderr, "Usage: %s <bufsize> <msglen>\n", argv[0]);
+    return 1;
+  }
+
+  srand((unsigned int)time(NULL));
+
+  if((buf_len = atoi(argv[1])) <= 0) {
+    fprintf(stderr, "Buffer length must be positive, not %d\n", buf_len);
+    return 2;
+  }
+  if((msg_len = atoi(argv[2])) <= 0) {
+    fprintf(stderr, "Message length must be positive, not %d\n", msg_len);
+    return 2;
+  }
+  if(msg_len > buf_len) 
+    msg_len = buf_len;
+
+  buf = calloc(buf_len, sizeof(*buf));
+  for(i = 0; i < msg_len; ++i)
+    buf[i] = i + 1;
+
+  printf("Buffer size:  %d bytes\n"
+	 "Message len:  %d bytes\n\n", buf_len, msg_len);
+
+  printf("Message:\n");
+  print_buf(buf, msg_len, 16, stdout);
+  fputc('\n', stdout);
+
+  if((res = rsa_pkcs1v15_encode(buf, msg_len, buf_len, 2, random_fill)) != MP_OK) {
+    printf("Error from encoding function: %d\n", res);
+    free(buf);
+    return 1;
+  }
+  printf("Encoded message:\n");
+  print_buf(buf, buf_len, 16, stdout);
+  fputc('\n', stdout);
+
+  msg_len = -1;  /* make decoder fill this in */
+  if((res = rsa_pkcs1v15_decode(buf, buf_len, 2, &msg_len)) != MP_OK) {
+    printf("Error from decoding function: %d\n", res);
+    free(buf);
+    return 1;
+  }
+  printf("Decoded message (%d bytes):\n", msg_len);
+  print_buf(buf, msg_len, 16, stdout);
+  fputc('\n', stdout);
+
+  free(buf);
+  return 0;
+}
+
+void random_fill(unsigned char *buf, int len)
+{
+  int i;
+
+  for(i = 0; i < len; ++i) {
+    unsigned char c = 0; 
+
+    while(c == 0) 
+      c = (unsigned char)rand();
+
+    buf[i] = c;
+  }
+}
+
+void print_buf(unsigned char *buf, int len, int brk, FILE *ofp)
+{
+  int i;
+
+  for(i = 0; i < len; ++i) {
+    fprintf(ofp, "%02X", buf[i]);
+
+    if((i + 1) % brk == 0)
+      fputc('\n', ofp);
+    else
+      fputc(' ', ofp);
+  }
+  if(i % brk)
+    fputc('\n', ofp);
+}






More information about the llvm-commits mailing list