Merge branch 'maint'
authorSven Verdoolaege <skimo@kotnet.org>
Fri, 9 Sep 2011 15:45:51 +0000 (17:45 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Fri, 9 Sep 2011 15:45:51 +0000 (17:45 +0200)
97 files changed:
Makefile.am
bound.c
doc/user.pod
include/isl/aff.h
include/isl/arg.h
include/isl/constraint.h
include/isl/dim.h
include/isl/div.h
include/isl/id.h [new file with mode: 0644]
include/isl/ilp.h
include/isl/int.h
include/isl/list.h
include/isl/local_space.h
include/isl/map.h
include/isl/mat.h
include/isl/obj.h
include/isl/point.h
include/isl/polynomial.h
include/isl/polynomial_type.h [new file with mode: 0644]
include/isl/set.h
include/isl/space.h [new file with mode: 0644]
include/isl/stream.h
include/isl/union_map.h
include/isl/union_set.h
include/isl/vec.h
isl_aff.c
isl_aff_private.h
isl_affine_hull.c
isl_band.c
isl_bernstein.c
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_dim.c
isl_dim_map.c
isl_dim_map.h
isl_dim_private.h [deleted file]
isl_div.c
isl_factorization.c
isl_farkas.c
isl_flow.c
isl_fold.c
isl_id.c [new file with mode: 0644]
isl_id_private.h [new file with mode: 0644]
isl_ilp.c
isl_input.c
isl_list.c
isl_list_private.h
isl_list_templ.c
isl_list_templ.h
isl_local_space.c
isl_local_space_private.h
isl_lp.c
isl_map.c
isl_map_piplib.c
isl_map_private.h
isl_map_simplify.c
isl_map_subtract.c
isl_mat.c
isl_morph.c
isl_morph.h
isl_name.c [deleted file]
isl_name.h [deleted file]
isl_obj.c
isl_output.c
isl_point.c
isl_point_private.h
isl_polynomial.c
isl_polynomial_private.h
isl_pw_templ.c
isl_range.c
isl_reordering.c
isl_reordering.h
isl_sample.c
isl_schedule.c
isl_schedule_private.h
isl_space.c [new file with mode: 0644]
isl_space_private.h [new file with mode: 0644]
isl_stream.c
isl_stream_private.h [new file with mode: 0644]
isl_tab.c
isl_tab_pip.c
isl_test.c
isl_transitive_closure.c
isl_union_map.c
isl_union_map_private.h
isl_union_templ.c
isl_vec.c
isl_vertices.c
pip.c
print.c [new file with mode: 0644]
print_templ.c [new file with mode: 0644]

index e3e96d0..9a8f877 100644 (file)
@@ -55,7 +55,6 @@ libisl_la_SOURCES = \
        isl_ctx.c \
        isl_ctx_private.h \
        isl_dim.c \
-       isl_dim_private.h \
        isl_dim_map.h \
        isl_dim_map.c \
        isl_div.c \
@@ -88,8 +87,8 @@ libisl_la_SOURCES = \
        isl_mat_private.h \
        isl_morph.c \
        isl_morph.h \
-       isl_name.c \
-       isl_name.h \
+       isl_id.c \
+       isl_id_private.h \
        isl_obj.c \
        isl_options.c \
        isl_output.c \
@@ -102,6 +101,7 @@ libisl_la_SOURCES = \
        isl_polynomial.c \
        isl_printer_private.h \
        isl_printer.c \
+       print.c \
        isl_range.c \
        isl_range.h \
        isl_reordering.c \
@@ -112,7 +112,10 @@ libisl_la_SOURCES = \
        isl_scan.h \
        isl_schedule.c \
        isl_schedule_private.h \
+       isl_space.c \
+       isl_space_private.h \
        isl_stream.c \
+       isl_stream_private.h \
        isl_seq.c \
        isl_tab.c \
        isl_tab.h \
@@ -199,6 +202,7 @@ pkginclude_HEADERS = \
        include/isl/dim.h \
        include/isl/div.h \
        include/isl/flow.h \
+       include/isl/id.h \
        include/isl/ilp.h \
        include/isl/int.h \
        include/isl/hash.h \
@@ -212,11 +216,13 @@ pkginclude_HEADERS = \
        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/seq.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_set.h \
@@ -229,6 +235,7 @@ EXTRA_DIST = \
        basis_reduction_templ.c \
        isl_list_templ.c \
        isl_list_templ.h \
+       print_templ.c \
        isl_pw_templ.c \
        isl_union_templ.c \
        isl.py \
diff --git a/bound.c b/bound.c
index f83e025..7115002 100644 (file)
--- a/bound.c
+++ b/bound.c
@@ -111,7 +111,7 @@ static int verify_point(__isl_take isl_point *pnt, void *user)
                opt = isl_pw_qpolynomial_fold_min(isl_pw_qpolynomial_fold_copy(pwf));
 
        nvar = isl_set_dim(dom, isl_dim_set);
-       opt = isl_qpolynomial_drop_dims(opt, isl_dim_set, 0, nvar);
+       opt = isl_qpolynomial_project_domain_on_params(opt);
        if (vpb->exact && bounded)
                ok = isl_qpolynomial_plain_is_equal(opt, bound);
        else if (sign > 0)
@@ -175,8 +175,7 @@ static int check_solution(__isl_take isl_pw_qpolynomial_fold *pwf,
        int i, r, n;
 
        dom = isl_pw_qpolynomial_fold_domain(isl_pw_qpolynomial_fold_copy(pwf));
-       context = isl_set_remove_dims(isl_set_copy(dom), isl_dim_set,
-                                       0, isl_set_dim(dom, isl_dim_set));
+       context = isl_set_params(isl_set_copy(dom));
        context = isl_set_remove_divs(context);
        context = set_bounds(context);
 
index 76799c1..245259d 100644 (file)
@@ -68,10 +68,9 @@ 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 the dimension specification
-of a B<map> as input.  An old call
-C<isl_map_identity(dim)> can be rewritten to
-C<isl_map_identity(isl_dim_map_from_set(dim))>.
+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
@@ -93,6 +92,37 @@ 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>.
+
+=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.
+
+=back
+
 =head1 Installation
 
 The source of C<isl> can be obtained either as a tarball
@@ -358,10 +388,10 @@ 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 have the same dimension.  C<isl_union_set>s and C<isl_union_map>s
-represent unions of C<isl_set>s or C<isl_map>s of I<different> dimensions,
-where dimensions with different space names
-(see L<Dimension Specifications>) are considered different as well.
+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.
@@ -378,7 +408,7 @@ 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 documents functions are
+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
@@ -406,7 +436,7 @@ 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 the other C<__isl_take> arguments
+make sure that all the other C<__isl_take> arguments
 are released.
 
 =item C<__isl_keep>
@@ -419,118 +449,192 @@ a C<NULL> value for an C<__isl_take> argument.
 
 =back
 
-=head2 Dimension Specifications
+=head2 Identifiers
+
+Identifiers are used to identify both individual dimensions
+and tuples of dimensions.  They consist of a name and an optional
+pointer.  Identifiers with the same name but different pointer values
+are considered to be distinct.
+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_copy(isl_id *id);
+       void *isl_id_free(__isl_take isl_id *id);
+
+       isl_ctx *isl_id_get_ctx(__isl_keep 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);
+
+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 or relation is created from scratch,
-its dimension needs to be specified using an C<isl_dim>.
+the space in which it lives needs to be specified using an C<isl_space>.
 
-       #include <isl/dim.h>
-       __isl_give isl_dim *isl_dim_alloc(isl_ctx *ctx,
+       #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_dim *isl_dim_set_alloc(isl_ctx *ctx,
+       __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_dim *isl_dim_copy(__isl_keep isl_dim *dim);
-       void isl_dim_free(__isl_take isl_dim *dim);
-       unsigned isl_dim_size(__isl_keep isl_dim *dim,
+       __isl_give isl_space *isl_space_copy(__isl_keep isl_space *space);
+       void isl_space_free(__isl_take isl_space *space);
+       unsigned isl_space_dim(__isl_keep isl_space *space,
                enum isl_dim_type type);
 
-The dimension specification used for creating a set
-needs to be created using C<isl_dim_set_alloc>, while
-that for creating a relation
-needs to be created using C<isl_dim_alloc>.
-C<isl_dim_size> can be used
+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>.
+C<isl_space_dim> can be used
 to find out the number of dimensions of each type in
-a dimension specification, where type may be
+a space, where 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>.
 
+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);
+
 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<Creating New (Piecewise) Quasipolynomials>) based on the dimension
-specification of the original object.
+L<Creating New (Piecewise) Quasipolynomials>) based on the space
+of the original object.
 
        #include <isl/set.h>
-       __isl_give isl_dim *isl_basic_set_get_dim(
+       __isl_give isl_space *isl_basic_set_get_space(
                __isl_keep isl_basic_set *bset);
-       __isl_give isl_dim *isl_set_get_dim(__isl_keep isl_set *set);
+       __isl_give isl_space *isl_set_get_space(__isl_keep isl_set *set);
 
        #include <isl/union_set.h>
-       __isl_give isl_dim *isl_union_set_get_dim(
+       __isl_give isl_space *isl_union_set_get_space(
                __isl_keep isl_union_set *uset);
 
        #include <isl/map.h>
-       __isl_give isl_dim *isl_basic_map_get_dim(
+       __isl_give isl_space *isl_basic_map_get_space(
                __isl_keep isl_basic_map *bmap);
-       __isl_give isl_dim *isl_map_get_dim(__isl_keep isl_map *map);
+       __isl_give isl_space *isl_map_get_space(__isl_keep isl_map *map);
 
        #include <isl/union_map.h>
-       __isl_give isl_dim *isl_union_map_get_dim(
+       __isl_give isl_space *isl_union_map_get_space(
                __isl_keep isl_union_map *umap);
 
        #include <isl/constraint.h>
-       __isl_give isl_dim *isl_constraint_get_dim(
+       __isl_give isl_space *isl_constraint_get_space(
                __isl_keep isl_constraint *constraint);
 
        #include <isl/polynomial.h>
-       __isl_give isl_dim *isl_qpolynomial_get_dim(
+       __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_dim *isl_qpolynomial_fold_get_dim(
+       __isl_give isl_space *isl_qpolynomial_fold_get_space(
                __isl_keep isl_qpolynomial_fold *fold);
-       __isl_give isl_dim *isl_pw_qpolynomial_get_dim(
+       __isl_give isl_space *isl_pw_qpolynomial_get_domain_space(
                __isl_keep isl_pw_qpolynomial *pwqp);
-       __isl_give isl_dim *isl_union_pw_qpolynomial_get_dim(
+       __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_dim *isl_union_pw_qpolynomial_fold_get_dim(
+       __isl_give isl_space *isl_union_pw_qpolynomial_fold_get_space(
                __isl_keep isl_union_pw_qpolynomial_fold *upwf);
 
        #include <isl/aff.h>
-       __isl_give isl_dim *isl_aff_get_dim(
+       __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_dim *isl_pw_aff_get_dim(
+       __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);
 
        #include <isl/point.h>
-       __isl_give isl_dim *isl_point_get_dim(
+       __isl_give isl_space *isl_point_get_space(
                __isl_keep isl_point *pnt);
 
-The names of the individual dimensions may be set or read off
+The identifiers or names of the individual dimensions may be set or read off
 using the following functions.
 
-       #include <isl/dim.h>
-       __isl_give isl_dim *isl_dim_set_name(__isl_take isl_dim *dim,
+       #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);
-       __isl_keep const char *isl_dim_get_name(__isl_keep isl_dim *dim,
+       __isl_keep const char *isl_space_get_dim_name(__isl_keep isl_space *space,
                                 enum isl_dim_type type, unsigned pos);
 
-Note that C<isl_dim_get_name> returns a pointer to some internal
+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_dim> is alive.
+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_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
+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.
 
-The names of entire spaces may be set or read off
+Given the identifier of a dimension (typically a parameter),
+its position can be obtained from the following function.
+
+       #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);
+
+The identifiers or names of entire spaces may be set or read off
 using the following functions.
 
-       #include <isl/dim.h>
-       __isl_give isl_dim *isl_dim_set_tuple_name(
-               __isl_take isl_dim *dim,
+       #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);
-       const char *isl_dim_get_tuple_name(__isl_keep isl_dim *dim,
+       const char *isl_space_get_tuple_name(__isl_keep isl_space *space,
                enum isl_dim_type type);
 
-The C<dim> argument needs to be one of C<isl_dim_in>, C<isl_dim_out>
-or C<isl_dim_set>.  As with C<isl_dim_get_name>,
-the C<isl_dim_get_tuple_name> function returns a pointer to some internal
+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.
@@ -538,48 +642,53 @@ to have the same name.
 Spaces can be nested.  In particular, the domain of a set or
 the domain or range of a relation can be a nested relation.
 The following functions can be used to construct and deconstruct
-such nested dimension specifications.
-
-       #include <isl/dim.h>
-       int isl_dim_is_wrapping(__isl_keep isl_dim *dim);
-       __isl_give isl_dim *isl_dim_wrap(__isl_take isl_dim *dim);
-       __isl_give isl_dim *isl_dim_unwrap(__isl_take isl_dim *dim);
-
-The input to C<isl_dim_is_wrapping> and C<isl_dim_unwrap> should
-be the dimension specification of a set, while that of
-C<isl_dim_wrap> should be the dimension specification of a relation.
-Conversely, the output of C<isl_dim_unwrap> is the dimension specification
-of a relation, while that of C<isl_dim_wrap> is the dimension specification
-of a set.
-
-Dimension specifications can be created from other dimension
-specifications using the following functions.
-
-       __isl_give isl_dim *isl_dim_domain(__isl_take isl_dim *dim);
-       __isl_give isl_dim *isl_dim_from_domain(__isl_take isl_dim *dim);
-       __isl_give isl_dim *isl_dim_range(__isl_take isl_dim *dim);
-       __isl_give isl_dim *isl_dim_from_range(__isl_take isl_dim *dim);
-       __isl_give isl_dim *isl_dim_reverse(__isl_take isl_dim *dim);
-       __isl_give isl_dim *isl_dim_join(__isl_take isl_dim *left,
-               __isl_take isl_dim *right);
-       __isl_give isl_dim *isl_dim_align_params(
-               __isl_take isl_dim *dim1, __isl_take isl_dim *dim2)
-       __isl_give isl_dim *isl_dim_insert(__isl_take isl_dim *dim,
+such nested spaces.
+
+       #include <isl/space.h>
+       int isl_space_is_wrapping(__isl_keep isl_space *space);
+       __isl_give isl_space *isl_space_wrap(__isl_take isl_space *space);
+       __isl_give isl_space *isl_space_unwrap(__isl_take isl_space *space);
+
+The input to C<isl_space_is_wrapping> and 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.
+
+Spaces can be created from other spaces
+using the following functions.
+
+       __isl_give isl_space *isl_space_domain(__isl_take isl_space *space);
+       __isl_give isl_space *isl_space_from_domain(__isl_take isl_space *space);
+       __isl_give isl_space *isl_space_range(__isl_take isl_space *space);
+       __isl_give isl_space *isl_space_from_range(__isl_take isl_space *space);
+       __isl_give isl_space *isl_space_params(
+               __isl_take isl_space *space);
+       __isl_give isl_space *isl_space_reverse(__isl_take isl_space *space);
+       __isl_give isl_space *isl_space_join(__isl_take isl_space *left,
+               __isl_take isl_space *right);
+       __isl_give isl_space *isl_space_align_params(
+               __isl_take isl_space *space1, __isl_take isl_space *space2)
+       __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_dim *isl_dim_add(__isl_take isl_dim *dim,
+       __isl_give isl_space *isl_space_add_dims(__isl_take isl_space *space,
                enum isl_dim_type type, unsigned n);
-       __isl_give isl_dim *isl_dim_drop(__isl_take isl_dim *dim,
+       __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_dim *isl_dim_map_from_set(
-               __isl_take isl_dim *dim);
-       __isl_give isl_dim *isl_dim_zip(__isl_take isl_dim *dim);
+       __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);
+       __isl_give isl_space *isl_space_map_from_set(
+               __isl_take isl_space *space);
+       __isl_give isl_space *isl_space_zip(__isl_take isl_space *space);
 
 Note that if dimensions are added or removed from a space, then
 the name and the internal structure are lost.
 
 =head2 Local Spaces
 
-A local space is essentially a dimension specification with
+A local space is essentially a space with
 zero or more existentially quantified variables.
 The local space of a basic set or relation can be obtained
 using the following functions.
@@ -592,17 +701,18 @@ using the following functions.
        __isl_give isl_local_space *isl_basic_map_get_local_space(
                __isl_keep isl_basic_map *bmap);
 
-A new local space can be created from a dimension specification using
+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_dim(
-               __isl_take isl_dim *dim);
+       __isl_give isl_local_space *isl_local_space_from_space(
+               __isl_take isl_space *space);
 
 They can be inspected, copied and freed using the following functions.
 
        #include <isl/local_space.h>
        isl_ctx *isl_local_space_get_ctx(
                __isl_keep isl_local_space *ls);
+       int isl_local_space_is_set(__isl_keep isl_local_space *ls);
        int isl_local_space_dim(__isl_keep isl_local_space *ls,
                enum isl_dim_type type);
        const char *isl_local_space_get_dim_name(
@@ -611,7 +721,7 @@ They can be inspected, copied and freed using the following functions.
        __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);
-       __isl_give isl_dim *isl_local_space_get_dim(
+       __isl_give isl_space *isl_local_space_get_space(
                __isl_keep isl_local_space *ls);
        __isl_give isl_div *isl_local_space_get_div(
                __isl_keep isl_local_space *ls, int pos);
@@ -627,6 +737,8 @@ Two local spaces can be compared using
 Local spaces can be created from other local spaces
 using the following functions.
 
+       __isl_give isl_local_space *isl_local_space_domain(
+               __isl_take isl_local_space *ls);
        __isl_give isl_local_space *isl_local_space_from_domain(
                __isl_take isl_local_space *ls);
        __isl_give isl_local_space *isl_local_space_add_dims(
@@ -715,7 +827,7 @@ dimensions is zero.
        __isl_give isl_basic_map *isl_basic_map_read_from_str(
                isl_ctx *ctx, const char *str, int nparam);
        __isl_give isl_map *isl_map_read_from_file(
-               struct isl_ctx *ctx, FILE *input, int nparam);
+               isl_ctx *ctx, FILE *input, int nparam);
        __isl_give isl_map *isl_map_read_from_str(isl_ctx *ctx,
                const char *str, int nparam);
 
@@ -723,13 +835,13 @@ dimensions is zero.
        __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(
-               struct isl_ctx *ctx, const char *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(
-               struct isl_ctx *ctx, const char *str);
+               isl_ctx *ctx, const char *str);
 
 The input format is autodetected and may be either the C<PolyLib> format
 or the C<isl> format.
@@ -822,31 +934,31 @@ C<isl> has functions for creating some standard sets and relations.
 =item * Empty sets and relations
 
        __isl_give isl_basic_set *isl_basic_set_empty(
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
        __isl_give isl_basic_map *isl_basic_map_empty(
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
        __isl_give isl_set *isl_set_empty(
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
        __isl_give isl_map *isl_map_empty(
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
        __isl_give isl_union_set *isl_union_set_empty(
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
        __isl_give isl_union_map *isl_union_map_empty(
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
 
-For C<isl_union_set>s and C<isl_union_map>s, the dimensions specification
+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_dim *dim);
+               __isl_take isl_space *space);
        __isl_give isl_basic_map *isl_basic_map_universe(
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
        __isl_give isl_set *isl_set_universe(
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
        __isl_give isl_map *isl_map_universe(
-               __isl_take isl_dim *dim);
+               __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(
@@ -857,50 +969,50 @@ 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_dim *dim);
+               __isl_take isl_space *space);
        __isl_give isl_basic_map *isl_basic_map_nat_universe(
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
        __isl_give isl_set *isl_set_nat_universe(
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
        __isl_give isl_map *isl_map_nat_universe(
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
 
 =item * Identity relations
 
        __isl_give isl_basic_map *isl_basic_map_identity(
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
        __isl_give isl_map *isl_map_identity(
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
 
-The number of input and output dimensions in C<dim> needs
+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_dim *set_dim);
+               __isl_take isl_space *set_space);
        __isl_give isl_map *isl_map_lex_le(
-               __isl_take isl_dim *set_dim);
+               __isl_take isl_space *set_space);
        __isl_give isl_map *isl_map_lex_gt(
-               __isl_take isl_dim *set_dim);
+               __isl_take isl_space *set_space);
        __isl_give isl_map *isl_map_lex_ge(
-               __isl_take isl_dim *set_dim);
+               __isl_take isl_space *set_space);
        __isl_give isl_map *isl_map_lex_lt_first(
-               __isl_take isl_dim *dim, unsigned n);
+               __isl_take isl_space *space, unsigned n);
        __isl_give isl_map *isl_map_lex_le_first(
-               __isl_take isl_dim *dim, unsigned n);
+               __isl_take isl_space *space, unsigned n);
        __isl_give isl_map *isl_map_lex_gt_first(
-               __isl_take isl_dim *dim, unsigned n);
+               __isl_take isl_space *space, unsigned n);
        __isl_give isl_map *isl_map_lex_ge_first(
-               __isl_take isl_dim *dim, unsigned n);
+               __isl_take isl_space *space, unsigned n);
 
-The first four functions take a dimension specification for a B<set>
+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 dimension specification for a map
+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>),
@@ -964,14 +1076,19 @@ using the following functions.
 
        #include <isl/constraint.h>
        __isl_give isl_constraint *isl_equality_alloc(
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
        __isl_give isl_constraint *isl_inequality_alloc(
-               __isl_take isl_dim *dim);
-       void isl_constraint_set_constant(
-               __isl_keep isl_constraint *constraint, isl_int v);
-       void isl_constraint_set_coefficient(
-               __isl_keep isl_constraint *constraint,
+               __isl_take isl_space *space);
+       __isl_give isl_constraint *isl_constraint_set_constant(
+               __isl_take isl_constraint *constraint, isl_int v);
+       __isl_give isl_constraint *isl_constraint_set_constant_si(
+               __isl_take isl_constraint *constraint, int v);
+       __isl_give isl_constraint *isl_constraint_set_coefficient(
+               __isl_take isl_constraint *constraint,
                enum isl_dim_type type, int pos, isl_int 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_basic_map *isl_basic_map_add_constraint(
                __isl_take isl_basic_map *bmap,
                __isl_take isl_constraint *constraint);
@@ -992,29 +1109,29 @@ For example, to create a set containing the even integers
 between 10 and 42, you would use the following code.
 
        isl_int v;
-       struct isl_dim *dim;
-       struct isl_constraint *c;
-       struct isl_basic_set *bset;
+       isl_space *space;
+       isl_constraint *c;
+       isl_basic_set *bset;
 
        isl_int_init(v);
-       dim = isl_dim_set_alloc(ctx, 0, 2);
-       bset = isl_basic_set_universe(isl_dim_copy(dim));
+       space = isl_space_set_alloc(ctx, 0, 2);
+       bset = isl_basic_set_universe(isl_space_copy(space));
 
-       c = isl_equality_alloc(isl_dim_copy(dim));
+       c = isl_equality_alloc(isl_space_copy(space));
        isl_int_set_si(v, -1);
        isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
        isl_int_set_si(v, 2);
        isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
        bset = isl_basic_set_add_constraint(bset, c);
 
-       c = isl_inequality_alloc(isl_dim_copy(dim));
+       c = isl_inequality_alloc(isl_space_copy(space));
        isl_int_set_si(v, -10);
        isl_constraint_set_constant(c, v);
        isl_int_set_si(v, 1);
        isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
        bset = isl_basic_set_add_constraint(bset, c);
 
-       c = isl_inequality_alloc(dim);
+       c = isl_inequality_alloc(space);
        isl_int_set_si(v, 42);
        isl_constraint_set_constant(c, v);
        isl_int_set_si(v, -1);
@@ -1027,7 +1144,7 @@ between 10 and 42, you would use the following code.
 
 Or, alternatively,
 
-       struct isl_basic_set *bset;
+       isl_basic_set *bset;
        bset = isl_basic_set_read_from_str(ctx,
                "{[i] : exists (a : i = 2a and i >= 10 and i <= 42)}", -1);
 
@@ -1035,13 +1152,13 @@ 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_dim *dim,
+               __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_dim *dim,
+               __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,
@@ -1054,15 +1171,18 @@ 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) relation can also be constructed from a (piecewise) affine expression
+A (basic) set or relation can also be constructed from a (piecewise)
+affine expression
 or a list of affine expressions (See L<"Piecewise Quasi Affine Expressions">).
 
        __isl_give isl_basic_map *isl_basic_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_dim *domain_dim,
+               __isl_take isl_space *domain_space,
                __isl_take isl_aff_list *list);
 
 The C<domain_dim> argument describes the domain of the resulting
@@ -1130,15 +1250,14 @@ 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 from a union with a given dimension
-specification, use
+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_dim *dim);
+               __isl_take isl_space *space);
        __isl_give isl_map *isl_union_map_extract_map(
                __isl_keep isl_union_map *umap,
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
 
 To iterate over all the basic sets or maps in a set or map, use
 
@@ -1176,7 +1295,7 @@ To iterate over the constraints of a basic set or map, use
                __isl_keep isl_basic_map *bmap,
                int (*fn)(__isl_take isl_constraint *c, void *user),
                void *user);
-       void isl_constraint_free(struct isl_constraint *c);
+       void *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
@@ -1243,8 +1362,60 @@ different kinds of variables appear in the resulting matrix
 and 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>.
 
-The names of the domain and range spaces of a set or relation can be
-read off or set using the following functions.
+The number of parameters, input, output or set dimensions can
+be obtained using the following functions.
+
+       unsigned isl_basic_set_dim(__isl_keep isl_basic_set *bset,
+               enum isl_dim_type type);
+       unsigned isl_basic_map_dim(__isl_keep isl_basic_map *bmap,
+               enum isl_dim_type type);
+       unsigned isl_set_dim(__isl_keep isl_set *set,
+               enum isl_dim_type type);
+       unsigned isl_map_dim(__isl_keep isl_map *map,
+               enum isl_dim_type type);
+
+To check whether the description of a set or relation depends
+on one or more given dimensions, it is not necessary to iterate over all
+constraints.  Instead the following functions can be used.
+
+       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);
+       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);
+
+Similarly, the following functions can be used to check whether
+a given dimension is involved in any lower or upper bound.
+
+       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);
+
+The identifiers or names of the domain and range spaces of a set
+or relation can be read off or set using the following functions.
+
+       __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_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);
 
        const char *isl_basic_set_get_tuple_name(
                __isl_keep isl_basic_set *bset);
@@ -1259,10 +1430,32 @@ read off or set using the following functions.
                __isl_keep isl_map *map,
                enum isl_dim_type type);
 
-As with C<isl_dim_get_tuple_name>, the value returned points to
+As with C<isl_space_get_tuple_name>, the value returned points to
 an internal data structure.
-The names of individual dimensions can be read off using
-the following functions.
+The identifiers, positions or names of individual dimensions can be
+read off using the following functions.
+
+       __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);
+       __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_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);
+
+       int isl_set_find_dim_by_id(__isl_keep isl_set *set,
+               enum isl_dim_type type, __isl_keep isl_id *id);
+       int isl_map_find_dim_by_id(__isl_keep isl_map *map,
+               enum isl_dim_type type, __isl_keep isl_id *id);
 
        const char *isl_constraint_get_dim_name(
                __isl_keep isl_constraint *constraint,
@@ -1280,8 +1473,10 @@ the following functions.
                __isl_keep isl_map *map,
                enum isl_dim_type type, unsigned pos);
 
-These functions are mostly useful to obtain the names
-of the parameters.
+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.
 
 =head2 Properties
 
@@ -1332,6 +1527,25 @@ is already known to be empty.
        int isl_map_is_bijective(__isl_keep isl_map *map);
        int isl_union_map_is_bijective(__isl_keep isl_union_map *umap);
 
+=item * Position
+
+       int isl_basic_map_plain_is_fixed(
+               __isl_keep isl_basic_map *bmap,
+               enum isl_dim_type type, unsigned pos,
+               isl_int *val);
+       int isl_map_plain_is_fixed(__isl_keep isl_map *map,
+               enum isl_dim_type type, unsigned pos,
+               isl_int *val);
+
+Check if the relation obviously lies on a hyperplane where the given dimension
+has a fixed value and if so, return that value in C<*val>.
+
+=item * Space
+
+To check whether a set is a parameter domain, use this function:
+
+       int isl_set_is_params(__isl_keep isl_set *set);
+
 =item * Wrapping
 
 The following functions check whether the domain of the given
@@ -1446,10 +1660,13 @@ i.e., whether both domain and range are nested relations.
                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_set_params(
+               __isl_take isl_basic_set *bset);
        __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_set_params(__isl_take isl_set *set);
        __isl_give isl_set *isl_map_domain(
                __isl_take isl_map *bmap);
        __isl_give isl_set *isl_map_range(
@@ -1505,6 +1722,23 @@ without removing the dimensions.
 Intersect the set or relation with the hyperplane where the given
 dimension has the fixed given 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_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.
+
 =item * Identity
 
        __isl_give isl_map *isl_set_identity(
@@ -1648,20 +1882,24 @@ per space.
        enum isl_lp_result isl_basic_set_max(
                __isl_keep isl_basic_set *bset,
                __isl_keep isl_aff *obj, isl_int *opt)
+       enum isl_lp_result isl_set_min(__isl_keep isl_set *set,
+               __isl_keep isl_aff *obj, isl_int *opt);
        enum isl_lp_result isl_set_max(__isl_keep isl_set *set,
                __isl_keep isl_aff *obj, isl_int *opt);
 
-Compute the maximum of the integer affine expression C<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 return value may be one of C<isl_lp_error>,
 C<isl_lp_ok>, C<isl_lp_unbounded> or C<isl_lp_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);
 
-Compute the maximum of the given set dimension as a function of the
+Compute the minimum or maximum of the given set dimension as a function of the
 parameters, but independently of the other set dimensions.
 For lexicographic optimization, see L<"Lexicographic Optimization">.
 
@@ -1759,10 +1997,14 @@ then the name of the space is also removed.
                __isl_take isl_basic_set *bset);
        __isl_give isl_set *isl_set_flatten(
                __isl_take isl_set *set);
+       __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(
@@ -1805,10 +2047,10 @@ interchange the range of the domain with the domain of the range.
 
        __isl_give isl_set *isl_set_align_params(
                __isl_take isl_set *set,
-               __isl_take isl_dim *model);
+               __isl_take isl_space *model);
        __isl_give isl_map *isl_map_align_params(
                __isl_take isl_map *map,
-               __isl_take isl_dim *model);
+               __isl_take isl_space *model);
 
 Change the order of the parameters of the given set or relation
 such that the first parameters match those of C<model>.
@@ -1823,6 +2065,12 @@ All parameters need to be named.
        __isl_give isl_map *isl_map_add_dims(
                __isl_take isl_map *map,
                enum isl_dim_type type, 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_map *isl_map_insert_dims(
+               __isl_take isl_map *map,
+               enum isl_dim_type type, unsigned pos, unsigned n);
 
 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
@@ -1962,9 +2210,15 @@ the same (number of) parameters.
        __isl_give isl_union_set *isl_union_set_product(
                __isl_take isl_union_set *uset1,
                __isl_take isl_union_set *uset2);
+       __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_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);
@@ -1993,6 +2247,9 @@ instead.
        __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);
@@ -2013,6 +2270,9 @@ instead.
                __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);
        __isl_give isl_union_set *isl_union_set_gist(
                __isl_take isl_union_set *uset,
                __isl_take isl_union_set *context);
@@ -2021,6 +2281,9 @@ instead.
                __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_union_map *isl_union_map_gist(
                __isl_take isl_union_map *umap,
                __isl_take isl_union_map *context);
@@ -2131,11 +2394,13 @@ In case of union relations, the optimum is computed per space.
 =head2 Lists
 
 Lists are defined over several element types, including
-C<isl_aff>, C<isl_basic_set> and C<isl_set>.
+C<isl_aff>, C<isl_pw_aff>, C<isl_basic_set> and C<isl_set>.
 Here we take lists of C<isl_set>s as an example.
 Lists can be created, copied and freed using the following functions.
 
        #include <isl/list.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(
@@ -2143,20 +2408,24 @@ Lists can be created, copied and freed using the following functions.
        __isl_give isl_set_list *isl_set_list_add(
                __isl_take isl_set_list *list,
                __isl_take isl_set *el);
-       void isl_set_list_free(__isl_take isl_set_list *list);
+       __isl_give isl_set_list *isl_set_list_concat(
+               __isl_take isl_set_list *list1,
+               __isl_take isl_set_list *list2);
+       void *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<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/list.h>
        isl_ctx *isl_set_list_get_ctx(__isl_keep isl_set_list *list);
        int isl_set_list_n_set(__isl_keep isl_set_list *list);
-       __isl_give struct isl_set *isl_set_list_get_set(
+       __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 struct isl_set *el, void *user),
+               int (*fn)(__isl_take isl_set *el, void *user),
                void *user);
 
 Lists can be printed using
@@ -2171,7 +2440,7 @@ Lists can be printed using
 Matrices can be created, copied and freed using the following functions.
 
        #include <isl/mat.h>
-       __isl_give isl_mat *isl_mat_alloc(struct isl_ctx *ctx,
+       __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);
        void isl_mat_free(__isl_take isl_mat *mat);
@@ -2207,11 +2476,14 @@ the original and the kernel (in that order) is the zero matrix.
 
 =head2 Piecewise Quasi Affine Expressions
 
-The zero quasi affine expression can be created using
+The zero quasi affine expression on a given domain can be created using
 
-       __isl_give isl_aff *isl_aff_zero(
+       __isl_give isl_aff *isl_aff_zero_on_domain(
                __isl_take isl_local_space *ls);
 
+Note that the space in which the resulting object lives is a map space
+with the given space as domain and a one-dimensional range.
+
 A quasi affine expression can also be initialized from an C<isl_div>:
 
        #include <isl/div.h>
@@ -2223,9 +2495,11 @@ be created using the following functions.
 
        #include <isl/aff.h>
        __isl_give isl_pw_aff *isl_pw_aff_empty(
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
        __isl_give isl_pw_aff *isl_pw_aff_alloc(
                __isl_take isl_set *set, __isl_take isl_aff *aff);
+       __isl_give isl_pw_aff *isl_pw_aff_from_aff(
+               __isl_take isl_aff *aff);
 
 Quasi affine expressions can be copied and freed using
 
@@ -2268,6 +2542,8 @@ The expression can be inspected using
        isl_ctx *isl_aff_get_ctx(__isl_keep isl_aff *aff);
        int isl_aff_dim(__isl_keep isl_aff *aff,
                enum isl_dim_type type);
+       __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);
        const char *isl_aff_get_dim_name(__isl_keep isl_aff *aff,
@@ -2281,6 +2557,14 @@ The expression can be inspected using
        __isl_give isl_div *isl_aff_get_div(
                __isl_keep isl_aff *aff, int pos);
 
+       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_aff_is_cst(__isl_keep isl_aff *aff);
+       int isl_pw_aff_is_cst(__isl_keep isl_pw_aff *pwaff);
+
        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,
@@ -2294,6 +2578,9 @@ The expression can be inspected using
 It can be modified using
 
        #include <isl/aff.h>
+       __isl_give isl_pw_aff *isl_pw_aff_set_tuple_id(
+               __isl_take isl_pw_aff *pwaff,
+               __isl_take isl_id *id);
        __isl_give isl_aff *isl_aff_set_dim_name(
                __isl_take isl_aff *aff, enum isl_dim_type type,
                unsigned pos, const char *s);
@@ -2361,6 +2648,12 @@ Operations include
        __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_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_pw_aff *isl_pw_aff_sub(
@@ -2375,6 +2668,10 @@ Operations include
        __isl_give isl_aff *isl_aff_floor(__isl_take isl_aff *aff);
        __isl_give isl_pw_aff *isl_pw_aff_floor(
                __isl_take isl_pw_aff *pwaff);
+       __isl_give isl_aff *isl_aff_mod(__isl_take isl_aff *aff,
+               isl_int mod);
+       __isl_give isl_pw_aff *isl_pw_aff_mod(
+               __isl_take isl_pw_aff *pwaff, isl_int mod);
        __isl_give isl_aff *isl_aff_scale(__isl_take isl_aff *aff,
                isl_int f);
        __isl_give isl_pw_aff *isl_pw_aff_scale(
@@ -2386,12 +2683,17 @@ Operations include
        __isl_give isl_pw_aff *isl_pw_aff_scale_down(
                __isl_take isl_pw_aff *pwaff, isl_int f);
 
+       __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);
+
        __isl_give isl_pw_aff *isl_pw_aff_coalesce(
                __isl_take isl_pw_aff *pwqp);
 
        __isl_give isl_pw_aff *isl_pw_aff_align_params(
                __isl_take isl_pw_aff *pwaff,
-               __isl_take isl_dim *model);
+               __isl_take isl_space *model);
 
        __isl_give isl_aff *isl_aff_gist(__isl_take isl_aff *aff,
                __isl_take isl_set *context);
@@ -2402,11 +2704,26 @@ Operations include
        __isl_give isl_set *isl_pw_aff_domain(
                __isl_take isl_pw_aff *pwaff);
 
+       __isl_give isl_aff *isl_aff_mul(__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);
+
+When multiplying two affine expressions, at least one of the two needs
+to be a constant.
+
+       #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);
@@ -2420,16 +2737,41 @@ Operations include
                __isl_take isl_pw_aff *pwaff1,
                __isl_take isl_pw_aff *pwaff2);
 
+       __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_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 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.
 
        #include <isl/aff.h>
        __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_pw_aff_nonneg_set> returns a set
 containing those elements in the domain
@@ -2447,11 +2789,14 @@ for elements in C<cond> and equal to C<pwaff_false> for elements
 not in C<cond>.
 
        #include <isl/aff.h>
-       __isl_give isl_pw_aff *isl_pw_aff_max(
+       __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_max> computes a piecewise quasi-affine
+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
@@ -2475,7 +2820,7 @@ 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_dim *dim);
+       __isl_give isl_point *isl_point_zero(__isl_take isl_space *space);
 
 The coordinates of a point can be inspected, set and changed
 using
@@ -2619,40 +2964,48 @@ More complicated quasipolynomials can be created by applying
 operations such as addition and multiplication
 on the resulting quasipolynomials
 
-       __isl_give isl_qpolynomial *isl_qpolynomial_zero(
-               __isl_take isl_dim *dim);
-       __isl_give isl_qpolynomial *isl_qpolynomial_one(
-               __isl_take isl_dim *dim);
-       __isl_give isl_qpolynomial *isl_qpolynomial_infty(
-               __isl_take isl_dim *dim);
-       __isl_give isl_qpolynomial *isl_qpolynomial_neginfty(
-               __isl_take isl_dim *dim);
-       __isl_give isl_qpolynomial *isl_qpolynomial_nan(
-               __isl_take isl_dim *dim);
-       __isl_give isl_qpolynomial *isl_qpolynomial_rat_cst(
-               __isl_take isl_dim *dim,
+       __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_rat_cst_on_domain(
+               __isl_take isl_space *domain,
                const isl_int n, const isl_int d);
        __isl_give isl_qpolynomial *isl_qpolynomial_div(
                __isl_take isl_div *div);
-       __isl_give isl_qpolynomial *isl_qpolynomial_var(
-               __isl_take isl_dim *dim,
+       __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);
 
+Note 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.
+
 The zero piecewise quasipolynomial or a piecewise quasipolynomial
 with a single cell can be created using the following functions.
 Multiple of these single cell piecewise quasipolynomials can
 be combined to create more complicated piecewise quasipolynomials.
 
        __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_zero(
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
        __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_alloc(
                __isl_take isl_set *set,
                __isl_take isl_qpolynomial *qp);
+       __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_from_qpolynomial(
+               __isl_take isl_qpolynomial *qp);
+       __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_from_pw_aff(
+               __isl_take isl_pw_aff *pwaff);
 
        __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_zero(
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
        __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_from_pw_qpolynomial(
                __isl_take isl_pw_qpolynomial *pwqp);
        __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_add_pw_qpolynomial(
@@ -2664,7 +3017,7 @@ functions.
 
        __isl_give isl_qpolynomial *isl_qpolynomial_copy(
                __isl_keep isl_qpolynomial *qp);
-       void isl_qpolynomial_free(__isl_take isl_qpolynomial *qp);
+       void *isl_qpolynomial_free(__isl_take isl_qpolynomial *qp);
 
        __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_copy(
                __isl_keep isl_pw_qpolynomial *pwqp);
@@ -2686,13 +3039,12 @@ piecewise quasipolynomial, use the following function
                int (*fn)(__isl_take isl_pw_qpolynomial *pwqp, void *user),
                void *user);
 
-To extract the piecewise quasipolynomial from a union with a given dimension
-specification, use
+To extract the piecewise quasipolynomial in a given space from a union, use
 
        __isl_give isl_pw_qpolynomial *
        isl_union_pw_qpolynomial_extract_pw_qpolynomial(
                __isl_keep isl_union_pw_qpolynomial *upwqp,
-               __isl_take isl_dim *dim);
+               __isl_take isl_space *space);
 
 To iterate over the cells in a piecewise quasipolynomial,
 use either of the following two functions
@@ -2795,6 +3147,8 @@ are returned in C<*n> and C<*d>, respectively.
        __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_mul(
                __isl_take isl_pw_qpolynomial *pwqp1,
                __isl_take isl_pw_qpolynomial *pwqp2);
+       __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_pow(
+               __isl_take isl_pw_qpolynomial *pwqp, unsigned exponent);
 
        __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_add(
                __isl_take isl_union_pw_qpolynomial *upwqp1,
@@ -2828,7 +3182,12 @@ are returned in C<*n> and C<*d>, respectively.
 
        __isl_give isl_qpolynomial *isl_qpolynomial_align_params(
                __isl_take isl_qpolynomial *qp,
-               __isl_take isl_dim *model);
+               __isl_take isl_space *model);
+
+       __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_union_pw_qpolynomial *isl_union_pw_qpolynomial_coalesce(
                __isl_take isl_union_pw_qpolynomial *upwqp);
@@ -2997,6 +3356,9 @@ To iterate over all quasipolynomials in a reduction, use
                __isl_take isl_union_pw_qpolynomial_fold *upwf,
                __isl_take isl_union_set *uset);
 
+       __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_project_domain_on_params(
+               __isl_take isl_pw_qpolynomial_fold *pwf);
+
        __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_coalesce(
                __isl_take isl_pw_qpolynomial_fold *pwf);
 
index ffeca4b..058b062 100644 (file)
@@ -6,12 +6,13 @@
 #include <isl/printer.h>
 #include <isl/set_type.h>
 #include <isl/aff_type.h>
+#include <isl/list.h>
 
 #if defined(__cplusplus)
 extern "C" {
 #endif
 
-__isl_give isl_aff *isl_aff_zero(__isl_take isl_local_space *ls);
+__isl_give isl_aff *isl_aff_zero_on_domain(__isl_take isl_local_space *ls);
 
 __isl_give isl_aff *isl_aff_copy(__isl_keep isl_aff *aff);
 void *isl_aff_free(__isl_take isl_aff *aff);
@@ -22,7 +23,10 @@ int isl_aff_dim(__isl_keep isl_aff *aff, enum isl_dim_type type);
 int isl_aff_involves_dims(__isl_keep isl_aff *aff,
        enum isl_dim_type type, unsigned first, unsigned n);
 
-__isl_give isl_dim *isl_aff_get_dim(__isl_keep isl_aff *aff);
+__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_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);
 
 const char *isl_aff_get_dim_name(__isl_keep isl_aff *aff,
@@ -45,6 +49,8 @@ __isl_give isl_aff *isl_aff_add_coefficient(__isl_take isl_aff *aff,
 __isl_give isl_aff *isl_aff_add_coefficient_si(__isl_take isl_aff *aff,
        enum isl_dim_type type, int pos, int v);
 
+int isl_aff_is_cst(__isl_keep isl_aff *aff);
+
 __isl_give isl_aff *isl_aff_set_dim_name(__isl_take isl_aff *aff,
        enum isl_dim_type type, unsigned pos, const char *s);
 
@@ -56,7 +62,10 @@ __isl_give isl_div *isl_aff_get_div(__isl_keep isl_aff *aff, int pos);
 __isl_give isl_aff *isl_aff_neg(__isl_take isl_aff *aff);
 __isl_give isl_aff *isl_aff_ceil(__isl_take isl_aff *aff);
 __isl_give isl_aff *isl_aff_floor(__isl_take isl_aff *aff);
+__isl_give isl_aff *isl_aff_mod(__isl_take isl_aff *aff, isl_int mod);
 
+__isl_give isl_aff *isl_aff_mul(__isl_take isl_aff *aff1,
+       __isl_take isl_aff *aff2);
 __isl_give isl_aff *isl_aff_add(__isl_take isl_aff *aff1,
        __isl_take isl_aff *aff2);
 __isl_give isl_aff *isl_aff_sub(__isl_take isl_aff *aff1,
@@ -76,6 +85,8 @@ __isl_give isl_aff *isl_aff_drop_dims(__isl_take isl_aff *aff,
 __isl_give isl_aff *isl_aff_gist(__isl_take isl_aff *aff,
        __isl_take isl_set *context);
 
+__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);
 
@@ -84,15 +95,19 @@ __isl_give isl_printer *isl_printer_print_aff(__isl_take isl_printer *p,
 void isl_aff_dump(__isl_keep isl_aff *aff);
 
 isl_ctx *isl_pw_aff_get_ctx(__isl_keep isl_pw_aff *pwaff);
-__isl_give isl_dim *isl_pw_aff_get_dim(__isl_keep isl_pw_aff *pwaff);
+__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_pw_aff *isl_pw_aff_empty(__isl_take isl_dim *dim);
+__isl_give isl_pw_aff *isl_pw_aff_from_aff(__isl_take isl_aff *aff);
+__isl_give isl_pw_aff *isl_pw_aff_empty(__isl_take isl_space *dim);
 __isl_give isl_pw_aff *isl_pw_aff_alloc(__isl_take isl_set *set,
        __isl_take isl_aff *aff);
 
 int isl_pw_aff_is_empty(__isl_keep isl_pw_aff *pwaff);
 
-__isl_give isl_pw_aff *isl_pw_aff_max(__isl_take isl_pw_aff *pwaff1,
+__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);
 
 __isl_give isl_pw_aff *isl_pw_aff_copy(__isl_keep isl_pw_aff *pwaff);
@@ -102,11 +117,22 @@ unsigned isl_pw_aff_dim(__isl_keep isl_pw_aff *pwaff, enum isl_dim_type type);
 int isl_pw_aff_involves_dims(__isl_keep isl_pw_aff *pwaff,
        enum isl_dim_type type, unsigned first, unsigned n);
 
+int isl_pw_aff_is_cst(__isl_keep isl_pw_aff *pwaff);
+
 __isl_give isl_pw_aff *isl_pw_aff_align_params(__isl_take isl_pw_aff *pwaff,
-       __isl_take isl_dim *model);
+       __isl_take isl_space *model);
+
+__isl_give isl_pw_aff *isl_pw_aff_set_tuple_id(__isl_take isl_pw_aff *pwaff,
+       __isl_take isl_id *id);
 
 __isl_give isl_set *isl_pw_aff_domain(__isl_take isl_pw_aff *pwaff);
 
+__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_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_add(__isl_take isl_pw_aff *pwaff1,
        __isl_take isl_pw_aff *pwaff2);
 __isl_give isl_pw_aff *isl_pw_aff_sub(__isl_take isl_pw_aff *pwaff1,
@@ -114,6 +140,8 @@ __isl_give isl_pw_aff *isl_pw_aff_sub(__isl_take isl_pw_aff *pwaff1,
 __isl_give isl_pw_aff *isl_pw_aff_neg(__isl_take isl_pw_aff *pwaff);
 __isl_give isl_pw_aff *isl_pw_aff_ceil(__isl_take isl_pw_aff *pwaff);
 __isl_give isl_pw_aff *isl_pw_aff_floor(__isl_take isl_pw_aff *pwaff);
+__isl_give isl_pw_aff *isl_pw_aff_mod(__isl_take isl_pw_aff *pwaff,
+       isl_int mod);
 
 __isl_give isl_pw_aff *isl_pw_aff_cond(__isl_take isl_set *cond,
        __isl_take isl_pw_aff *pwaff_true, __isl_take isl_pw_aff *pwaff_false);
@@ -134,12 +162,21 @@ __isl_give isl_pw_aff *isl_pw_aff_coalesce(__isl_take isl_pw_aff *pwqp);
 __isl_give isl_pw_aff *isl_pw_aff_gist(__isl_take isl_pw_aff *pwaff,
        __isl_take isl_set *context);
 
+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);
+
+__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_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);
 
 __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,
@@ -153,8 +190,26 @@ __isl_give isl_printer *isl_printer_print_pw_aff(__isl_take isl_printer *p,
        __isl_keep isl_pw_aff *pwaff);
 void isl_pw_aff_dump(__isl_keep isl_pw_aff *pwaff);
 
+__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);
+
+__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);
+
 #if defined(__cplusplus)
 }
 #endif
 
+#include <isl/dim.h>
+
 #endif
index c05885e..8c775f6 100644 (file)
@@ -204,15 +204,18 @@ struct isl_arg {
        .help_msg = h,                                                  \
        .u = { .ul = { .default_value = d } }                           \
 },
-#define ISL_ARG_STR(st,f,s,l,a,d,h)    {                               \
+#define ISL_ARG_STR_F(st,f,s,l,a,d,h,fl)       {                       \
        .type = isl_arg_str,                                            \
        .short_name = s,                                                \
        .long_name = l,                                                 \
        .argument_name = a,                                             \
        .offset = offsetof(st, f),                                      \
        .help_msg = h,                                                  \
+       .flags = fl,                                                    \
        .u = { .str = { .default_value = d } }                          \
 },
+#define ISL_ARG_STR(st,f,s,l,a,d,h)                                    \
+       ISL_ARG_STR_F(st,f,s,l,a,d,h,0)
 #define _ISL_ARG_CHILD(o,sz,l,c,h,fl)  {                               \
        .type = isl_arg_child,                                          \
        .long_name = l,                                                 \
index 6f2e8c7..50d071f 100644 (file)
@@ -24,18 +24,13 @@ typedef struct isl_constraint isl_constraint;
 
 isl_ctx *isl_constraint_get_ctx(__isl_keep isl_constraint *c);
 
-__isl_give isl_constraint *isl_equality_alloc(__isl_take isl_dim *dim);
-__isl_give isl_constraint *isl_inequality_alloc(__isl_take isl_dim *dim);
+__isl_give isl_constraint *isl_equality_alloc(__isl_take isl_space *dim);
+__isl_give isl_constraint *isl_inequality_alloc(__isl_take isl_space *dim);
 
 struct isl_constraint *isl_constraint_cow(struct isl_constraint *c);
 struct isl_constraint *isl_constraint_copy(struct isl_constraint *c);
-void isl_constraint_free(struct isl_constraint *c);
+void *isl_constraint_free(__isl_take isl_constraint *c);
 
-__isl_give isl_constraint *isl_basic_map_first_constraint(
-       __isl_take isl_basic_map *bmap);
-__isl_give isl_constraint *isl_basic_set_first_constraint(
-       __isl_take isl_basic_set *bset);
-struct isl_constraint *isl_constraint_next(struct isl_constraint *c);
 int isl_basic_map_foreach_constraint(__isl_keep isl_basic_map *bmap,
        int (*fn)(__isl_take isl_constraint *c, void *user), void *user);
 int isl_basic_set_foreach_constraint(__isl_keep isl_basic_set *bset,
@@ -69,7 +64,7 @@ int isl_basic_set_has_defining_inequalities(
        struct isl_constraint **lower,
        struct isl_constraint **upper);
 
-__isl_give isl_dim *isl_constraint_get_dim(
+__isl_give isl_space *isl_constraint_get_space(
        __isl_keep isl_constraint *constraint);
 int isl_constraint_dim(struct isl_constraint *constraint,
        enum isl_dim_type type);
@@ -83,20 +78,20 @@ void isl_constraint_get_constant(__isl_keep isl_constraint *constraint,
        isl_int *v);
 void isl_constraint_get_coefficient(__isl_keep isl_constraint *constraint,
        enum isl_dim_type type, int pos, isl_int *v);
-void isl_constraint_set_constant(__isl_keep isl_constraint *constraint, isl_int v);
-void isl_constraint_set_constant_si(__isl_keep isl_constraint *constraint,
-       int v);
-void isl_constraint_set_coefficient(__isl_keep isl_constraint *constraint,
+__isl_give isl_constraint *isl_constraint_set_constant(
+       __isl_take isl_constraint *constraint, isl_int v);
+__isl_give isl_constraint *isl_constraint_set_constant_si(
+       __isl_take isl_constraint *constraint, int v);
+__isl_give isl_constraint *isl_constraint_set_coefficient(
+       __isl_take isl_constraint *constraint,
        enum isl_dim_type type, int pos, isl_int v);
-void isl_constraint_set_coefficient_si(__isl_keep isl_constraint *constraint,
+__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_div *isl_constraint_div(__isl_keep isl_constraint *constraint,
        int pos);
-struct isl_constraint *isl_constraint_add_div(struct isl_constraint *constraint,
-       struct isl_div *div, int *pos);
 
-void isl_constraint_clear(struct isl_constraint *constraint);
 struct isl_constraint *isl_constraint_negate(struct isl_constraint *constraint);
 
 int isl_constraint_is_equality(__isl_keep isl_constraint *constraint);
@@ -125,4 +120,6 @@ void isl_constraint_dump(__isl_keep isl_constraint *c);
 }
 #endif
 
+#include <isl/dim.h>
+
 #endif
index 5cb2664..7c31c02 100644 (file)
-/*
- * Copyright 2008-2009 Katholieke Universiteit Leuven
- *
- * Use of this software is governed by the GNU LGPLv2.1 license
- *
- * Written by Sven Verdoolaege, K.U.Leuven, Departement
- * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
- */
-
 #ifndef ISL_DIM_H
 #define ISL_DIM_H
 
-#include <isl/ctx.h>
-#include <isl/printer.h>
+#include <isl/space.h>
+#include <isl/local_space.h>
+#include <isl/aff_type.h>
+#include <isl/constraint.h>
+#include <isl/map_type.h>
+#include <isl/set_type.h>
+#include <isl/point.h>
+#include <isl/union_map.h>
+#include <isl/union_set.h>
+#include <isl/polynomial_type.h>
 
 #if defined(__cplusplus)
 extern "C" {
 #endif
 
-struct isl_dim;
-typedef struct isl_dim isl_dim;
-
-enum isl_dim_type {
-       isl_dim_cst,
-       isl_dim_param,
-       isl_dim_in,
-       isl_dim_out,
-       isl_dim_set = isl_dim_out,
-       isl_dim_div,
-       isl_dim_all
-};
-
-isl_ctx *isl_dim_get_ctx(__isl_keep isl_dim *dim);
-__isl_give isl_dim *isl_dim_alloc(isl_ctx *ctx,
+#define isl_dim isl_space
+
+isl_ctx *isl_dim_get_ctx(__isl_keep isl_space *dim);
+__isl_give isl_space *isl_dim_alloc(isl_ctx *ctx,
                        unsigned nparam, unsigned n_in, unsigned n_out);
-__isl_give isl_dim *isl_dim_set_alloc(isl_ctx *ctx,
+__isl_give isl_space *isl_dim_set_alloc(isl_ctx *ctx,
                        unsigned nparam, unsigned dim);
-__isl_give isl_dim *isl_dim_copy(__isl_keep isl_dim *dim);
-struct isl_dim *isl_dim_cow(struct isl_dim *dim);
-void isl_dim_free(__isl_take isl_dim *dim);
-
-__isl_give isl_dim *isl_dim_set_tuple_name(__isl_take isl_dim *dim,
+__isl_give isl_space *isl_dim_copy(__isl_keep isl_space *dim);
+void isl_dim_free(__isl_take isl_space *dim);
+
+unsigned isl_dim_size(__isl_keep isl_space *dim, enum isl_dim_type type);
+
+__isl_give isl_space *isl_dim_set_dim_id(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned pos, __isl_take isl_id *id);
+int isl_dim_has_dim_id(__isl_keep isl_space *dim,
+       enum isl_dim_type type, unsigned pos);
+__isl_give isl_id *isl_dim_get_dim_id(__isl_keep isl_space *dim,
+       enum isl_dim_type type, unsigned pos);
+
+int isl_dim_find_dim_by_id(__isl_keep isl_space *dim,
+       enum isl_dim_type type, __isl_keep isl_id *id);
+
+__isl_give isl_space *isl_dim_set_tuple_id(__isl_take isl_space *dim,
+       enum isl_dim_type type, __isl_take isl_id *id);
+__isl_give isl_space *isl_dim_reset_tuple_id(__isl_take isl_space *dim,
+       enum isl_dim_type type);
+int isl_dim_has_tuple_id(__isl_keep isl_space *dim, enum isl_dim_type type);
+__isl_give isl_id *isl_dim_get_tuple_id(__isl_keep isl_space *dim,
+       enum isl_dim_type type);
+
+__isl_give isl_space *isl_dim_set_name(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned pos, __isl_keep const char *name);
+__isl_keep const char *isl_dim_get_name(__isl_keep isl_space *dim,
+       enum isl_dim_type type, unsigned pos);
+
+__isl_give isl_space *isl_dim_set_tuple_name(__isl_take isl_space *dim,
        enum isl_dim_type type, const char *s);
-const char *isl_dim_get_tuple_name(__isl_keep isl_dim *dim,
+const char *isl_dim_get_tuple_name(__isl_keep isl_space *dim,
                                 enum isl_dim_type type);
 
-__isl_give isl_dim *isl_dim_set_name(__isl_take isl_dim *dim,
-                                enum isl_dim_type type, unsigned pos,
-                                __isl_keep const char *name);
-__isl_keep const char *isl_dim_get_name(__isl_keep isl_dim *dim,
-                                enum isl_dim_type type, unsigned pos);
-
-struct isl_dim *isl_dim_extend(struct isl_dim *dim,
-                       unsigned nparam, unsigned n_in, unsigned n_out);
-__isl_give isl_dim *isl_dim_add(__isl_take isl_dim *dim, enum isl_dim_type type,
-               unsigned n);
-__isl_give isl_dim *isl_dim_move(__isl_take isl_dim *dim,
+int isl_dim_is_wrapping(__isl_keep isl_space *dim);
+__isl_give isl_space *isl_dim_wrap(__isl_take isl_space *dim);
+__isl_give isl_space *isl_dim_unwrap(__isl_take isl_space *dim);
+
+__isl_give isl_space *isl_dim_domain(__isl_take isl_space *dim);
+__isl_give isl_space *isl_dim_from_domain(__isl_take isl_space *dim);
+__isl_give isl_space *isl_dim_range(__isl_take isl_space *dim);
+__isl_give isl_space *isl_dim_from_range(__isl_take isl_space *dim);
+__isl_give isl_space *isl_dim_reverse(__isl_take isl_space *dim);
+__isl_give isl_space *isl_dim_join(__isl_take isl_space *left,
+       __isl_take isl_space *right);
+__isl_give isl_space *isl_dim_align_params(__isl_take isl_space *dim1,
+       __isl_take isl_space *dim2);
+__isl_give isl_space *isl_dim_insert(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned pos, unsigned n);
+__isl_give isl_space *isl_dim_add(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned n);
+__isl_give isl_space *isl_dim_drop(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned first, unsigned n);
+__isl_give isl_space *isl_dim_move(__isl_take isl_space *dim,
        enum isl_dim_type dst_type, unsigned dst_pos,
        enum isl_dim_type src_type, unsigned src_pos, unsigned n);
-__isl_give isl_dim *isl_dim_insert(__isl_take isl_dim *dim,
-       enum isl_dim_type type, unsigned pos, unsigned n);
-__isl_give isl_dim *isl_dim_join(__isl_take isl_dim *left,
-       __isl_take isl_dim *right);
-struct isl_dim *isl_dim_product(struct isl_dim *left, struct isl_dim *right);
-__isl_give isl_dim *isl_dim_range_product(__isl_take isl_dim *left,
-       __isl_take isl_dim *right);
-__isl_give isl_dim *isl_dim_map_from_set(__isl_take isl_dim *dim);
-__isl_give isl_dim *isl_dim_reverse(__isl_take isl_dim *dim);
-__isl_give isl_dim *isl_dim_drop(__isl_take isl_dim *dim,
-       enum isl_dim_type type, unsigned first, unsigned num);
-struct isl_dim *isl_dim_drop_inputs(struct isl_dim *dim,
-               unsigned first, unsigned n);
-struct isl_dim *isl_dim_drop_outputs(struct isl_dim *dim,
-               unsigned first, unsigned n);
-__isl_give isl_dim *isl_dim_domain(__isl_take isl_dim *dim);
-__isl_give isl_dim *isl_dim_from_domain(__isl_take isl_dim *dim);
-__isl_give isl_dim *isl_dim_range(__isl_take isl_dim *dim);
-__isl_give isl_dim *isl_dim_from_range(__isl_take isl_dim *dim);
-struct isl_dim *isl_dim_underlying(struct isl_dim *dim, unsigned n_div);
-
-__isl_give isl_dim *isl_dim_align_params(__isl_take isl_dim *dim1,
-       __isl_take isl_dim *dim2);
-
-int isl_dim_is_wrapping(__isl_keep isl_dim *dim);
-__isl_give isl_dim *isl_dim_wrap(__isl_take isl_dim *dim);
-__isl_give isl_dim *isl_dim_unwrap(__isl_take isl_dim *dim);
-
-int isl_dim_can_zip(__isl_keep isl_dim *dim);
-__isl_give isl_dim *isl_dim_zip(__isl_take isl_dim *dim);
-
-int isl_dim_equal(struct isl_dim *dim1, struct isl_dim *dim2);
-int isl_dim_match(struct isl_dim *dim1, enum isl_dim_type dim1_type,
-               struct isl_dim *dim2, enum isl_dim_type dim2_type);
-int isl_dim_tuple_match(__isl_keep isl_dim *dim1, enum isl_dim_type dim1_type,
-                       __isl_keep isl_dim *dim2, enum isl_dim_type dim2_type);
-int isl_dim_compatible(struct isl_dim *dim1, struct isl_dim *dim2);
-unsigned isl_dim_size(__isl_keep isl_dim *dim, enum isl_dim_type type);
-unsigned isl_dim_total(struct isl_dim *dim);
-
-__isl_give isl_printer *isl_printer_print_dim(__isl_take isl_printer *p,
-       __isl_keep isl_dim *dim);
-void isl_dim_dump(__isl_keep isl_dim *dim);
+__isl_give isl_space *isl_dim_map_from_set(
+       __isl_take isl_space *dim);
+__isl_give isl_space *isl_dim_zip(__isl_take isl_space *dim);
+
+__isl_give isl_local_space *isl_local_space_from_dim(
+       __isl_take isl_space *dim);
+__isl_give isl_space *isl_local_space_get_dim(
+       __isl_keep isl_local_space *ls);
+
+__isl_give isl_space *isl_aff_get_dim(__isl_keep isl_aff *aff);
+__isl_give isl_space *isl_pw_aff_get_dim(__isl_keep isl_pw_aff *pwaff);
+
+__isl_give isl_space *isl_constraint_get_dim(
+       __isl_keep isl_constraint *constraint);
+
+__isl_give isl_space *isl_basic_map_get_dim(__isl_keep isl_basic_map *bmap);
+__isl_give isl_space *isl_map_get_dim(__isl_keep isl_map *map);
+__isl_give isl_space *isl_union_map_get_dim(__isl_keep isl_union_map *umap);
+
+__isl_give isl_space *isl_basic_set_get_dim(__isl_keep isl_basic_set *bset);
+__isl_give isl_space *isl_set_get_dim(__isl_keep isl_set *set);
+__isl_give isl_space *isl_union_set_get_dim(__isl_keep isl_union_set *uset);
+
+__isl_give isl_space *isl_point_get_dim(__isl_keep isl_point *pnt);
+
+__isl_give isl_space *isl_qpolynomial_get_dim(__isl_keep isl_qpolynomial *qp);
+__isl_give isl_space *isl_pw_qpolynomial_get_dim(
+       __isl_keep isl_pw_qpolynomial *pwqp);
+__isl_give isl_space *isl_qpolynomial_fold_get_dim(
+       __isl_keep isl_qpolynomial_fold *fold);
+__isl_give isl_space *isl_pw_qpolynomial_fold_get_dim(
+       __isl_keep isl_pw_qpolynomial_fold *pwf);
+__isl_give isl_space *isl_union_pw_qpolynomial_get_dim(
+       __isl_keep isl_union_pw_qpolynomial *upwqp);
+__isl_give isl_space *isl_union_pw_qpolynomial_fold_get_dim(
+       __isl_keep isl_union_pw_qpolynomial_fold *upwf);
 
 #if defined(__cplusplus)
 }
index 398c7be..b4a3331 100644 (file)
@@ -10,7 +10,7 @@
 #ifndef ISL_DIV_H
 #define ISL_DIV_H
 
-#include <isl/dim.h>
+#include <isl/space.h>
 #include <isl/aff_type.h>
 
 #if defined(__cplusplus)
@@ -22,7 +22,7 @@ typedef struct isl_div isl_div;
 
 isl_ctx *isl_div_get_ctx(__isl_keep isl_div *div);
 
-struct isl_div *isl_div_alloc(struct isl_dim *dim);
+__isl_give isl_div *isl_div_alloc(__isl_take isl_space *dim);
 __isl_give isl_div *isl_div_copy(__isl_keep isl_div *div);
 void isl_div_free(struct isl_div *c);
 
diff --git a/include/isl/id.h b/include/isl/id.h
new file mode 100644 (file)
index 0000000..86232f7
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef ISL_ID_H
+#define ISL_ID_H
+
+#include <isl/ctx.h>
+#include <isl/printer.h>
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+struct isl_id;
+typedef struct isl_id isl_id;
+
+isl_ctx *isl_id_get_ctx(__isl_keep isl_id *id);
+
+__isl_give isl_id *isl_id_alloc(isl_ctx *ctx,
+       __isl_keep const char *name, void *user);
+__isl_give isl_id *isl_id_copy(isl_id *id);
+void *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);
+void isl_id_dump(__isl_keep isl_id *id);
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif
index 460aaed..de5ec80 100644 (file)
@@ -22,6 +22,8 @@ enum isl_lp_result isl_basic_set_solve_ilp(struct isl_basic_set *bset, int max,
                                      struct isl_vec **sol_p);
 enum isl_lp_result isl_basic_set_max(__isl_keep isl_basic_set *bset,
        __isl_keep isl_aff *obj, isl_int *opt);
+enum isl_lp_result isl_set_min(__isl_keep isl_set *set,
+       __isl_keep isl_aff *obj, isl_int *opt);
 enum isl_lp_result isl_set_max(__isl_keep isl_set *set,
        __isl_keep isl_aff *obj, isl_int *opt);
 
index 7c292d0..d5385b1 100644 (file)
@@ -56,6 +56,7 @@ typedef mpz_t isl_int;
 #define isl_int_add(r,i,j)     mpz_add(r,i,j)
 #define isl_int_sub(r,i,j)     mpz_sub(r,i,j)
 #define isl_int_mul(r,i,j)     mpz_mul(r,i,j)
+#define isl_int_mul_2exp(r,i,j)        mpz_mul_2exp(r,i,j)
 #define isl_int_mul_ui(r,i,j)  mpz_mul_ui(r,i,j)
 #define isl_int_pow_ui(r,i,j)  mpz_pow_ui(r,i,j)
 #define isl_int_addmul(r,i,j)  mpz_addmul(r,i,j)
index 51387c3..e0dbfed 100644 (file)
@@ -22,13 +22,18 @@ struct isl_##EL;                                                    \
 struct isl_##EL##_list;                                                        \
 typedef struct isl_##EL##_list isl_##EL##_list;                                \
 isl_ctx *isl_##EL##_list_get_ctx(__isl_keep isl_##EL##_list *list);    \
+__isl_give isl_##EL##_list *isl_##EL##_list_from_##EL(                 \
+       __isl_take struct isl_##EL *el);                                \
 __isl_give isl_##EL##_list *isl_##EL##_list_alloc(isl_ctx *ctx, int n);        \
 __isl_give isl_##EL##_list *isl_##EL##_list_copy(                      \
        __isl_keep isl_##EL##_list *list);                              \
-void isl_##EL##_list_free(__isl_take isl_##EL##_list *list);           \
+void *isl_##EL##_list_free(__isl_take isl_##EL##_list *list);          \
 __isl_give isl_##EL##_list *isl_##EL##_list_add(                       \
        __isl_take isl_##EL##_list *list,                               \
        __isl_take struct isl_##EL *el);                                \
+__isl_give isl_##EL##_list *isl_##EL##_list_concat(                    \
+       __isl_take isl_##EL##_list *list1,                              \
+       __isl_take isl_##EL##_list *list2);                             \
 int isl_##EL##_list_n_##EL(__isl_keep isl_##EL##_list *list);          \
 __isl_give struct isl_##EL *isl_##EL##_list_get_##EL(                  \
        __isl_keep isl_##EL##_list *list, int index);                   \
@@ -42,6 +47,7 @@ void isl_##EL##_list_dump(__isl_keep isl_##EL##_list *list);
 ISL_DECLARE_LIST(basic_set)
 ISL_DECLARE_LIST(set)
 ISL_DECLARE_LIST(aff)
+ISL_DECLARE_LIST(pw_aff)
 ISL_DECLARE_LIST(band)
 
 #if defined(__cplusplus)
index 3faa041..74fa4a6 100644 (file)
@@ -13,12 +13,14 @@ typedef struct isl_local_space isl_local_space;
 
 isl_ctx *isl_local_space_get_ctx(__isl_keep isl_local_space *ls);
 
-__isl_give isl_local_space *isl_local_space_from_dim(__isl_take isl_dim *dim);
+__isl_give isl_local_space *isl_local_space_from_space(__isl_take isl_space *dim);
 
 __isl_give isl_local_space *isl_local_space_copy(
        __isl_keep isl_local_space *ls);
 void *isl_local_space_free(__isl_take isl_local_space *ls);
 
+int isl_local_space_is_set(__isl_keep isl_local_space *ls);
+
 int isl_local_space_dim(__isl_keep isl_local_space *ls,
        enum isl_dim_type type);
 const char *isl_local_space_get_dim_name(__isl_keep isl_local_space *ls,
@@ -26,10 +28,12 @@ const char *isl_local_space_get_dim_name(__isl_keep isl_local_space *ls,
 __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);
-__isl_give isl_dim *isl_local_space_get_dim(__isl_keep isl_local_space *ls);
+__isl_give isl_space *isl_local_space_get_space(__isl_keep isl_local_space *ls);
 __isl_give isl_div *isl_local_space_get_div(__isl_keep isl_local_space *ls,
        int pos);
 
+__isl_give isl_local_space *isl_local_space_domain(
+       __isl_take isl_local_space *ls);
 __isl_give isl_local_space *isl_local_space_from_domain(
        __isl_take isl_local_space *ls);
 __isl_give isl_local_space *isl_local_space_add_dims(
index 4678227..cd0de43 100644 (file)
@@ -15,7 +15,7 @@
 #include <isl/int.h>
 #include <isl/ctx.h>
 #include <isl/blk.h>
-#include <isl/dim.h>
+#include <isl/space.h>
 #include <isl/div.h>
 #include <isl/vec.h>
 #include <isl/mat.h>
@@ -48,18 +48,18 @@ unsigned isl_basic_map_n_out(const struct isl_basic_map *bmap);
 unsigned isl_basic_map_n_param(const struct isl_basic_map *bmap);
 unsigned isl_basic_map_n_div(const struct isl_basic_map *bmap);
 unsigned isl_basic_map_total_dim(const struct isl_basic_map *bmap);
-unsigned isl_basic_map_dim(const struct isl_basic_map *bmap,
+unsigned isl_basic_map_dim(__isl_keep isl_basic_map *bmap,
                                enum isl_dim_type type);
 
 unsigned isl_map_n_in(const struct isl_map *map);
 unsigned isl_map_n_out(const struct isl_map *map);
 unsigned isl_map_n_param(const struct isl_map *map);
-unsigned isl_map_dim(const struct isl_map *map, enum isl_dim_type type);
+unsigned isl_map_dim(__isl_keep isl_map *map, enum isl_dim_type type);
 
 isl_ctx *isl_basic_map_get_ctx(__isl_keep isl_basic_map *bmap);
 isl_ctx *isl_map_get_ctx(__isl_keep isl_map *map);
-__isl_give isl_dim *isl_basic_map_get_dim(__isl_keep isl_basic_map *bmap);
-__isl_give isl_dim *isl_map_get_dim(__isl_keep isl_map *map);
+__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);
 
 struct isl_div *isl_basic_map_div(struct isl_basic_map *bmap, int pos);
 
@@ -84,12 +84,29 @@ __isl_give isl_basic_map *isl_basic_map_set_dim_name(
 __isl_give isl_map *isl_map_set_dim_name(__isl_take isl_map *map,
        enum isl_dim_type type, unsigned pos, const char *s);
 
+__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_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_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);
+
+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_is_rational(__isl_keep isl_basic_map *bmap);
 
 struct isl_basic_map *isl_basic_map_alloc(struct isl_ctx *ctx,
                unsigned nparam, unsigned in, unsigned out, unsigned extra,
                unsigned n_eq, unsigned n_ineq);
-__isl_give isl_basic_map *isl_basic_map_identity(__isl_take isl_dim *dim);
+__isl_give isl_basic_map *isl_basic_map_identity(__isl_take isl_space *dim);
 struct isl_basic_map *isl_basic_map_identity_like(struct isl_basic_map *model);
 struct isl_basic_map *isl_basic_map_finalize(struct isl_basic_map *bmap);
 void isl_basic_map_free(__isl_take isl_basic_map *bmap);
@@ -99,15 +116,17 @@ struct isl_basic_map *isl_basic_map_extend(struct isl_basic_map *base,
                unsigned n_eq, unsigned n_ineq);
 struct isl_basic_map *isl_basic_map_extend_constraints(
                struct isl_basic_map *base, unsigned n_eq, unsigned n_ineq);
-struct isl_basic_map *isl_basic_map_equal(
-               struct isl_dim *dim, unsigned n_equal);
-struct isl_basic_map *isl_basic_map_less_at(struct isl_dim *dim, unsigned pos);
-struct isl_basic_map *isl_basic_map_more_at(struct isl_dim *dim, unsigned pos);
-__isl_give isl_basic_map *isl_basic_map_empty(__isl_take isl_dim *dim);
+__isl_give isl_basic_map *isl_basic_map_equal(
+       __isl_take isl_space *dim, unsigned n_equal);
+__isl_give isl_basic_map *isl_basic_map_less_at(__isl_take isl_space *dim,
+       unsigned pos);
+__isl_give isl_basic_map *isl_basic_map_more_at(__isl_take isl_space *dim,
+       unsigned pos);
+__isl_give isl_basic_map *isl_basic_map_empty(__isl_take isl_space *dim);
 struct isl_basic_map *isl_basic_map_empty_like(struct isl_basic_map *model);
 struct isl_basic_map *isl_basic_map_empty_like_map(struct isl_map *model);
-__isl_give isl_basic_map *isl_basic_map_universe(__isl_take isl_dim *dim);
-__isl_give isl_basic_map *isl_basic_map_nat_universe(__isl_take isl_dim *dim);
+__isl_give isl_basic_map *isl_basic_map_universe(__isl_take isl_space *dim);
+__isl_give isl_basic_map *isl_basic_map_nat_universe(__isl_take isl_space *dim);
 __isl_give isl_basic_map *isl_basic_map_universe_like(
                __isl_keep isl_basic_map *bmap);
 __isl_give isl_basic_map *isl_basic_map_remove_redundancies(
@@ -145,8 +164,8 @@ __isl_give isl_basic_map *isl_basic_map_range_map(
 __isl_give isl_basic_map *isl_basic_map_remove_dims(
        __isl_take isl_basic_map *bmap,
        enum isl_dim_type type, unsigned first, unsigned n);
-struct isl_basic_map *isl_basic_map_from_basic_set(struct isl_basic_set *bset,
-               struct isl_dim *dim);
+__isl_give isl_basic_map *isl_basic_map_from_basic_set(
+       __isl_take isl_basic_set *bset, __isl_take isl_space *dim);
 struct isl_basic_set *isl_basic_set_from_basic_map(struct isl_basic_map *bmap);
 __isl_give isl_basic_map *isl_basic_map_sample(__isl_take isl_basic_map *bmap);
 struct isl_basic_map *isl_basic_map_simplify(struct isl_basic_map *bmap);
@@ -156,7 +175,7 @@ __isl_give isl_basic_map *isl_basic_map_read_from_file(isl_ctx *ctx,
                FILE *input, int nparam);
 __isl_give isl_basic_map *isl_basic_map_read_from_str(isl_ctx *ctx,
                const char *str, int nparam);
-__isl_give isl_map *isl_map_read_from_file(struct isl_ctx *ctx,
+__isl_give isl_map *isl_map_read_from_file(isl_ctx *ctx,
                FILE *input, int nparam);
 __isl_give isl_map *isl_map_read_from_str(isl_ctx *ctx,
                const char *str, int nparam);
@@ -222,7 +241,7 @@ struct isl_basic_map *isl_map_copy_basic_map(struct isl_map *map);
 __isl_give isl_map *isl_map_drop_basic_map(__isl_take isl_map *map,
                                                __isl_keep isl_basic_map *bmap);
 
-int isl_basic_map_plain_is_fixed(struct isl_basic_map *bmap,
+int isl_basic_map_plain_is_fixed(__isl_keep isl_basic_map *bmap,
        enum isl_dim_type type, unsigned pos, isl_int *val);
 
 int isl_basic_map_image_is_bounded(__isl_keep isl_basic_map *bmap);
@@ -238,25 +257,25 @@ int isl_basic_map_is_strict_subset(__isl_keep isl_basic_map *bmap1,
 struct isl_map *isl_map_alloc(struct isl_ctx *ctx,
                unsigned nparam, unsigned in, unsigned out, int n,
                unsigned flags);
-__isl_give isl_map *isl_map_universe(__isl_take isl_dim *dim);
-__isl_give isl_map *isl_map_nat_universe(__isl_take isl_dim *dim);
-__isl_give isl_map *isl_map_empty(__isl_take isl_dim *dim);
+__isl_give isl_map *isl_map_universe(__isl_take isl_space *dim);
+__isl_give isl_map *isl_map_nat_universe(__isl_take isl_space *dim);
+__isl_give isl_map *isl_map_empty(__isl_take isl_space *dim);
 struct isl_map *isl_map_empty_like(struct isl_map *model);
 struct isl_map *isl_map_empty_like_basic_map(struct isl_basic_map *model);
 struct isl_map *isl_map_dup(struct isl_map *map);
 __isl_give isl_map *isl_map_add_basic_map(__isl_take isl_map *map,
                                                __isl_take isl_basic_map *bmap);
-__isl_give isl_map *isl_map_identity(__isl_take isl_dim *dim);
+__isl_give isl_map *isl_map_identity(__isl_take isl_space *dim);
 struct isl_map *isl_map_identity_like(struct isl_map *model);
 struct isl_map *isl_map_identity_like_basic_map(struct isl_basic_map *model);
-__isl_give isl_map *isl_map_lex_lt_first(__isl_take isl_dim *dim, unsigned n);
-__isl_give isl_map *isl_map_lex_le_first(__isl_take isl_dim *dim, unsigned n);
-__isl_give isl_map *isl_map_lex_lt(__isl_take isl_dim *set_dim);
-__isl_give isl_map *isl_map_lex_le(__isl_take isl_dim *set_dim);
-__isl_give isl_map *isl_map_lex_gt_first(__isl_take isl_dim *dim, unsigned n);
-__isl_give isl_map *isl_map_lex_ge_first(__isl_take isl_dim *dim, unsigned n);
-__isl_give isl_map *isl_map_lex_gt(__isl_take isl_dim *set_dim);
-__isl_give isl_map *isl_map_lex_ge(__isl_take isl_dim *set_dim);
+__isl_give isl_map *isl_map_lex_lt_first(__isl_take isl_space *dim, unsigned n);
+__isl_give isl_map *isl_map_lex_le_first(__isl_take isl_space *dim, unsigned n);
+__isl_give isl_map *isl_map_lex_lt(__isl_take isl_space *set_dim);
+__isl_give isl_map *isl_map_lex_le(__isl_take isl_space *set_dim);
+__isl_give isl_map *isl_map_lex_gt_first(__isl_take isl_space *dim, unsigned n);
+__isl_give isl_map *isl_map_lex_ge_first(__isl_take isl_space *dim, unsigned n);
+__isl_give isl_map *isl_map_lex_gt(__isl_take isl_space *set_dim);
+__isl_give isl_map *isl_map_lex_ge(__isl_take isl_space *set_dim);
 struct isl_map *isl_map_finalize(struct isl_map *map);
 void isl_map_free(__isl_take isl_map *map);
 __isl_give isl_map *isl_map_copy(__isl_keep isl_map *map);
@@ -282,8 +301,12 @@ __isl_give isl_map *isl_map_apply_range(
                __isl_take isl_map *map2);
 __isl_give isl_map *isl_map_product(__isl_take isl_map *map1,
        __isl_take isl_map *map2);
+__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_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_basic_map *isl_basic_map_flat_product(
@@ -292,6 +315,8 @@ __isl_give isl_map *isl_map_flat_product(__isl_take isl_map *map1,
        __isl_take isl_map *map2);
 __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_map *isl_map_intersect(__isl_take isl_map *map1,
@@ -320,7 +345,7 @@ __isl_give isl_basic_map *isl_basic_map_add(__isl_take isl_basic_map *bmap,
                enum isl_dim_type type, unsigned n);
 __isl_give isl_map *isl_map_add_dims(__isl_take isl_map *map,
                enum isl_dim_type type, unsigned n);
-__isl_give isl_map *isl_map_insert(__isl_take isl_map *map,
+__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,
@@ -342,6 +367,11 @@ __isl_give isl_map *isl_map_remove_dims(__isl_take isl_map *map,
 struct isl_map *isl_map_remove_inputs(struct isl_map *map,
        unsigned first, unsigned n);
 
+__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);
+__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);
+
 __isl_give isl_map *isl_set_identity(__isl_take isl_set *set);
 
 int isl_basic_set_is_wrapping(__isl_keep isl_basic_set *bset);
@@ -352,8 +382,11 @@ __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);
 __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);
+__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_domain(__isl_take isl_map *map);
 __isl_give isl_map *isl_map_flatten_range(__isl_take isl_map *map);
 __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);
@@ -373,7 +406,8 @@ __isl_give isl_basic_map *isl_basic_map_from_domain_and_range(
        __isl_take isl_basic_set *domain, __isl_take isl_basic_set *range);
 __isl_give isl_map *isl_map_from_domain_and_range(__isl_take isl_set *domain,
        __isl_take isl_set *range);
-struct isl_map *isl_map_from_set(struct isl_set *set, struct isl_dim *dim);
+__isl_give isl_map *isl_map_from_set(__isl_take isl_set *set,
+       __isl_take isl_space *dim);
 struct isl_set *isl_set_from_map(struct isl_map *map);
 __isl_give isl_basic_map *isl_map_sample(__isl_take isl_map *map);
 
@@ -389,7 +423,7 @@ int isl_map_plain_is_injective(__isl_keep isl_map *map);
 int isl_map_is_injective(__isl_keep isl_map *map);
 int isl_map_is_bijective(__isl_keep isl_map *map);
 int isl_map_is_translation(__isl_keep isl_map *map);
-int isl_map_has_equal_dim(__isl_keep isl_map *map1, __isl_keep isl_map *map2);
+int isl_map_has_equal_space(__isl_keep isl_map *map1, __isl_keep isl_map *map2);
 
 int isl_basic_map_can_zip(__isl_keep isl_basic_map *bmap);
 int isl_map_can_zip(__isl_keep isl_map *map);
@@ -401,11 +435,16 @@ __isl_give isl_map *isl_basic_map_compute_divs(__isl_take isl_basic_map *bmap);
 __isl_give isl_map *isl_map_compute_divs(__isl_take isl_map *map);
 __isl_give isl_map *isl_map_align_divs(__isl_take isl_map *map);
 
+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);
+
 void isl_map_print_internal(__isl_keep isl_map *map, FILE *out, int indent);
 
 int isl_map_plain_input_is_fixed(__isl_keep isl_map *map,
                unsigned in, isl_int *val);
-int isl_map_plain_is_fixed(struct isl_map *map,
+int isl_map_plain_is_fixed(__isl_keep isl_map *map,
        enum isl_dim_type type, unsigned pos, isl_int *val);
 int isl_map_fast_is_fixed(__isl_keep isl_map *map,
        enum isl_dim_type type, unsigned pos, isl_int *val);
@@ -414,6 +453,8 @@ __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_basic_map(__isl_take isl_map *map,
        __isl_take isl_basic_map *context);
 
@@ -445,7 +486,7 @@ __isl_give isl_map *isl_map_lex_gt_map(__isl_take isl_map *map1,
        __isl_take isl_map *map2);
 
 __isl_give isl_map *isl_map_align_params(__isl_take isl_map *map,
-       __isl_take isl_dim *model);
+       __isl_take isl_space *model);
 
 __isl_give isl_mat *isl_basic_map_equalities_matrix(
                __isl_keep isl_basic_map *bmap, enum isl_dim_type c1,
@@ -456,17 +497,19 @@ __isl_give isl_mat *isl_basic_map_inequalities_matrix(
                enum isl_dim_type c2, enum isl_dim_type c3,
                enum isl_dim_type c4, enum isl_dim_type c5);
 __isl_give isl_basic_map *isl_basic_map_from_constraint_matrices(
-       __isl_take isl_dim *dim,
+       __isl_take isl_space *dim,
        __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);
 
 __isl_give isl_basic_map *isl_basic_map_from_aff(__isl_take isl_aff *aff);
 __isl_give isl_basic_map *isl_basic_map_from_aff_list(
-       __isl_take isl_dim *domain_dim, __isl_take isl_aff_list *list);
+       __isl_take isl_space *domain_dim, __isl_take isl_aff_list *list);
 
 #if defined(__cplusplus)
 }
 #endif
 
+#include <isl/dim.h>
+
 #endif
index eda1048..e888888 100644 (file)
@@ -26,7 +26,7 @@ typedef struct isl_mat        isl_mat;
 
 isl_ctx *isl_mat_get_ctx(__isl_keep isl_mat *mat);
 
-__isl_give isl_mat *isl_mat_alloc(struct isl_ctx *ctx,
+__isl_give isl_mat *isl_mat_alloc(isl_ctx *ctx,
        unsigned n_row, unsigned n_col);
 struct isl_mat *isl_mat_dup(struct isl_mat *mat);
 struct isl_mat *isl_mat_extend(struct isl_mat *mat,
index b2a6afc..d40a82c 100644 (file)
@@ -5,7 +5,7 @@
 #include <isl/map_type.h>
 #include <isl/union_set.h>
 #include <isl/union_map.h>
-#include <isl/polynomial.h>
+#include <isl/polynomial_type.h>
 #include <isl/printer.h>
 
 #if defined(__cplusplus)
index a5a7f93..7d95db1 100644 (file)
@@ -2,7 +2,7 @@
 #define ISL_POINT_H
 
 #include <stdio.h>
-#include <isl/dim.h>
+#include <isl/space.h>
 
 #if defined(__cplusplus)
 extern "C" {
@@ -12,9 +12,9 @@ struct isl_point;
 typedef struct isl_point isl_point;
 
 isl_ctx *isl_point_get_ctx(__isl_keep isl_point *pnt);
-__isl_give isl_dim *isl_point_get_dim(__isl_keep isl_point *pnt);
+__isl_give isl_space *isl_point_get_space(__isl_keep isl_point *pnt);
 
-__isl_give isl_point *isl_point_zero(__isl_take isl_dim *dim);
+__isl_give isl_point *isl_point_zero(__isl_take isl_space *dim);
 __isl_give isl_point *isl_point_copy(__isl_keep isl_point *pnt);
 void isl_point_free(__isl_take isl_point *pnt);
 
@@ -28,13 +28,16 @@ __isl_give isl_point *isl_point_add_ui(__isl_take isl_point *pnt,
 __isl_give isl_point *isl_point_sub_ui(__isl_take isl_point *pnt,
        enum isl_dim_type type, int pos, unsigned val);
 
-__isl_give isl_point *isl_point_void(__isl_take isl_dim *dim);
+__isl_give isl_point *isl_point_void(__isl_take isl_space *dim);
 int isl_point_is_void(__isl_keep isl_point *pnt);
 
-void isl_point_print(__isl_keep isl_point *pnt, FILE *out);
+__isl_give isl_printer *isl_printer_print_point(
+       __isl_take isl_printer *printer, __isl_keep isl_point *pnt);
 
 #if defined(__cplusplus)
 }
 #endif
 
+#include <isl/dim.h>
+
 #endif
index 389d6ce..a468845 100644 (file)
@@ -3,25 +3,23 @@
 
 #include <isl/ctx.h>
 #include <isl/constraint.h>
-#include <isl/dim.h>
+#include <isl/space.h>
 #include <isl/div.h>
 #include <isl/set_type.h>
 #include <isl/point.h>
 #include <isl/printer.h>
 #include <isl/union_set.h>
 #include <isl/aff_type.h>
+#include <isl/polynomial_type.h>
 
 #if defined(__cplusplus)
 extern "C" {
 #endif
 
-struct isl_qpolynomial;
-typedef struct isl_qpolynomial isl_qpolynomial;
-
 isl_ctx *isl_qpolynomial_get_ctx(__isl_keep isl_qpolynomial *qp);
-__isl_give isl_dim *isl_qpolynomial_get_dim(__isl_keep isl_qpolynomial *qp);
-__isl_give isl_qpolynomial *isl_qpolynomial_reset_dim(
-       __isl_take isl_qpolynomial *qp, __isl_take isl_dim *dim);
+__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);
 unsigned isl_qpolynomial_dim(__isl_keep isl_qpolynomial *qp,
        enum isl_dim_type type);
 int isl_qpolynomial_involves_dims(__isl_keep isl_qpolynomial *qp,
@@ -31,18 +29,18 @@ __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_qpolynomial *isl_qpolynomial_zero(__isl_take isl_dim *dim);
-__isl_give isl_qpolynomial *isl_qpolynomial_one(__isl_take isl_dim *dim);
-__isl_give isl_qpolynomial *isl_qpolynomial_infty(__isl_take isl_dim *dim);
-__isl_give isl_qpolynomial *isl_qpolynomial_neginfty(__isl_take isl_dim *dim);
-__isl_give isl_qpolynomial *isl_qpolynomial_nan(__isl_take isl_dim *dim);
-__isl_give isl_qpolynomial *isl_qpolynomial_rat_cst(__isl_take isl_dim *dim,
+__isl_give isl_qpolynomial *isl_qpolynomial_zero_on_domain(__isl_take isl_space *dim);
+__isl_give isl_qpolynomial *isl_qpolynomial_one_on_domain(__isl_take isl_space *dim);
+__isl_give isl_qpolynomial *isl_qpolynomial_infty_on_domain(__isl_take isl_space *dim);
+__isl_give isl_qpolynomial *isl_qpolynomial_neginfty_on_domain(__isl_take isl_space *dim);
+__isl_give isl_qpolynomial *isl_qpolynomial_nan_on_domain(__isl_take isl_space *dim);
+__isl_give isl_qpolynomial *isl_qpolynomial_rat_cst_on_domain(__isl_take isl_space *dim,
        const isl_int n, const isl_int d);
 __isl_give isl_qpolynomial *isl_qpolynomial_div(__isl_take isl_div *div);
-__isl_give isl_qpolynomial *isl_qpolynomial_var(__isl_take isl_dim *dim,
+__isl_give isl_qpolynomial *isl_qpolynomial_var_on_domain(__isl_take isl_space *dim,
        enum isl_dim_type type, unsigned pos);
 __isl_give isl_qpolynomial *isl_qpolynomial_copy(__isl_keep isl_qpolynomial *qp);
-void isl_qpolynomial_free(__isl_take isl_qpolynomial *qp);
+void *isl_qpolynomial_free(__isl_take isl_qpolynomial *qp);
 
 int isl_qpolynomial_plain_is_equal(__isl_keep isl_qpolynomial *qp1,
        __isl_keep isl_qpolynomial *qp2);
@@ -80,6 +78,8 @@ __isl_give isl_qpolynomial *isl_qpolynomial_move_dims(
        __isl_take isl_qpolynomial *qp,
        enum isl_dim_type dst_type, unsigned dst_pos,
        enum isl_dim_type src_type, unsigned src_pos, unsigned n);
+__isl_give isl_qpolynomial *isl_qpolynomial_project_domain_on_params(
+       __isl_take isl_qpolynomial *qp);
 __isl_give isl_qpolynomial *isl_qpolynomial_drop_dims(
        __isl_take isl_qpolynomial *qp,
        enum isl_dim_type type, unsigned first, unsigned n);
@@ -98,13 +98,11 @@ __isl_give isl_qpolynomial *isl_qpolynomial_homogenize(
        __isl_take isl_qpolynomial *poly);
 
 __isl_give isl_qpolynomial *isl_qpolynomial_align_params(
-       __isl_take isl_qpolynomial *qp, __isl_take isl_dim *model);
-
-struct isl_term;
-typedef struct isl_term isl_term;
+       __isl_take isl_qpolynomial *qp, __isl_take isl_space *model);
 
 isl_ctx *isl_term_get_ctx(__isl_keep isl_term *term);
 
+__isl_give isl_term *isl_term_copy(__isl_keep isl_term *term);
 void isl_term_free(__isl_take isl_term *term);
 
 unsigned isl_term_dim(__isl_keep isl_term *term, enum isl_dim_type type);
@@ -136,29 +134,30 @@ void isl_qpolynomial_print(__isl_keep isl_qpolynomial *qp, FILE *out,
        unsigned output_format);
 void isl_qpolynomial_dump(__isl_keep isl_qpolynomial *qp);
 
-struct isl_pw_qpolynomial;
-typedef struct isl_pw_qpolynomial isl_pw_qpolynomial;
-
 isl_ctx *isl_pw_qpolynomial_get_ctx(__isl_keep isl_pw_qpolynomial *pwqp);
 
-__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_zero(__isl_take isl_dim *dim);
+__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_zero(__isl_take isl_space *dim);
 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_alloc(__isl_take isl_set *set,
        __isl_take isl_qpolynomial *qp);
+__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_from_qpolynomial(
+       __isl_take isl_qpolynomial *qp);
 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_copy(
        __isl_keep isl_pw_qpolynomial *pwqp);
 void *isl_pw_qpolynomial_free(__isl_take isl_pw_qpolynomial *pwqp);
 
 int isl_pw_qpolynomial_is_zero(__isl_keep isl_pw_qpolynomial *pwqp);
 
-__isl_give isl_dim *isl_pw_qpolynomial_get_dim(
+__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_pw_qpolynomial *isl_pw_qpolynomial_reset_dim(
-       __isl_take isl_pw_qpolynomial *pwqp, __isl_take isl_dim *dim);
+__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_reset_domain_space(
+       __isl_take isl_pw_qpolynomial *pwqp, __isl_take isl_space *dim);
 unsigned isl_pw_qpolynomial_dim(__isl_keep isl_pw_qpolynomial *pwqp,
        enum isl_dim_type type);
 int isl_pw_qpolynomial_involves_dims(__isl_keep isl_pw_qpolynomial *pwqp,
        enum isl_dim_type type, unsigned first, unsigned n);
-int isl_pw_qpolynomial_has_equal_dim(__isl_keep isl_pw_qpolynomial *pwqp1,
+int isl_pw_qpolynomial_has_equal_space(__isl_keep isl_pw_qpolynomial *pwqp1,
        __isl_keep isl_pw_qpolynomial *pwqp2);
 
 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_set_dim_name(
@@ -169,6 +168,8 @@ __isl_give isl_set *isl_pw_qpolynomial_domain(__isl_take isl_pw_qpolynomial *pwq
 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_intersect_domain(
        __isl_take isl_pw_qpolynomial *pwpq, __isl_take isl_set *set);
 
+__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_project_domain_on_params(
+       __isl_take isl_pw_qpolynomial *pwqp);
 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_drop_dims(
        __isl_take isl_pw_qpolynomial *pwqp,
        enum isl_dim_type type, unsigned first, unsigned n);
@@ -192,6 +193,8 @@ __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_mul(
        __isl_take isl_pw_qpolynomial *pwqp2);
 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_mul_isl_int(
        __isl_take isl_pw_qpolynomial *pwqp, isl_int v);
+__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_pow(
+       __isl_take isl_pw_qpolynomial *pwqp, unsigned exponent);
 
 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_insert_dims(
        __isl_take isl_pw_qpolynomial *pwqp, enum isl_dim_type type,
@@ -223,6 +226,9 @@ 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);
 
+__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_from_pw_aff(
+       __isl_take isl_pw_aff *pwaff);
+
 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_read_from_str(isl_ctx *ctx,
                const char *str);
 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_read_from_file(isl_ctx *ctx,
@@ -245,34 +251,22 @@ __isl_give isl_pw_qpolynomial *isl_basic_set_multiplicative_call(
        __isl_take isl_basic_set *bset,
        __isl_give isl_pw_qpolynomial *(*fn)(__isl_take isl_basic_set *bset));
 
-enum isl_fold {
-       isl_fold_min,
-       isl_fold_max,
-       isl_fold_list
-};
-
-struct isl_qpolynomial_fold;
-typedef struct isl_qpolynomial_fold isl_qpolynomial_fold;
-
 isl_ctx *isl_qpolynomial_fold_get_ctx(__isl_keep isl_qpolynomial_fold *fold);
 enum isl_fold isl_qpolynomial_fold_get_type(__isl_keep isl_qpolynomial_fold *fold);
 
 __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_empty(enum isl_fold type,
-       __isl_take isl_dim *dim);
+       __isl_take isl_space *dim);
 __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_alloc(
        enum isl_fold type, __isl_take isl_qpolynomial *qp);
 __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);
 
-__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_reset_dim(
-       __isl_take isl_qpolynomial_fold *fold, __isl_take isl_dim *dim);
-
 int isl_qpolynomial_fold_is_empty(__isl_keep isl_qpolynomial_fold *fold);
 int isl_qpolynomial_fold_plain_is_equal(__isl_keep isl_qpolynomial_fold *fold1,
        __isl_keep isl_qpolynomial_fold *fold2);
 
-__isl_give isl_dim *isl_qpolynomial_fold_get_dim(
+__isl_give isl_space *isl_qpolynomial_fold_get_space(
        __isl_keep isl_qpolynomial_fold *fold);
 
 __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_fold(
@@ -307,9 +301,6 @@ void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold *fold, FILE *out
        unsigned output_format);
 void isl_qpolynomial_fold_dump(__isl_keep isl_qpolynomial_fold *fold);
 
-struct isl_pw_qpolynomial_fold;
-typedef struct isl_pw_qpolynomial_fold isl_pw_qpolynomial_fold;
-
 isl_ctx *isl_pw_qpolynomial_fold_get_ctx(__isl_keep isl_pw_qpolynomial_fold *pwf);
 
 __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_from_pw_qpolynomial(
@@ -324,20 +315,22 @@ void *isl_pw_qpolynomial_fold_free(__isl_take isl_pw_qpolynomial_fold *pwf);
 
 int isl_pw_qpolynomial_fold_is_zero(__isl_keep isl_pw_qpolynomial_fold *pwf);
 
-__isl_give isl_dim *isl_pw_qpolynomial_fold_get_dim(
+__isl_give isl_space *isl_pw_qpolynomial_fold_get_domain_space(
        __isl_keep isl_pw_qpolynomial_fold *pwf);
-__isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_reset_dim(
-       __isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_dim *dim);
+__isl_give isl_space *isl_pw_qpolynomial_fold_get_space(
+       __isl_keep isl_pw_qpolynomial_fold *pwf);
+__isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_reset_space(
+       __isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_space *dim);
 unsigned isl_pw_qpolynomial_fold_dim(__isl_keep isl_pw_qpolynomial_fold *pwf,
        enum isl_dim_type type);
-int isl_pw_qpolynomial_fold_has_equal_dim(
+int isl_pw_qpolynomial_fold_has_equal_space(
        __isl_keep isl_pw_qpolynomial_fold *pwf1,
        __isl_keep isl_pw_qpolynomial_fold *pwf2);
 
 size_t isl_pw_qpolynomial_fold_size(__isl_keep isl_pw_qpolynomial_fold *pwf);
 
 __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_zero(
-       __isl_take isl_dim *dim, enum isl_fold type);
+       __isl_take isl_space *dim, enum isl_fold type);
 
 __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_set_dim_name(
        __isl_take isl_pw_qpolynomial_fold *pwf,
@@ -360,6 +353,8 @@ __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_add_disjoint(
 __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_mul_isl_int(
        __isl_take isl_pw_qpolynomial_fold *pwf, isl_int v);
 
+__isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_project_domain_on_params(
+       __isl_take isl_pw_qpolynomial_fold *pwf);
 __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_drop_dims(
        __isl_take isl_pw_qpolynomial_fold *pwf,
        enum isl_dim_type type, unsigned first, unsigned n);
@@ -414,15 +409,12 @@ __isl_give isl_pw_qpolynomial_fold *isl_map_apply_pw_qpolynomial_fold(
 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_to_polynomial(
        __isl_take isl_pw_qpolynomial *pwqp, int sign);
 
-struct isl_union_pw_qpolynomial;
-typedef struct isl_union_pw_qpolynomial isl_union_pw_qpolynomial;
-
 isl_ctx *isl_union_pw_qpolynomial_get_ctx(
        __isl_keep isl_union_pw_qpolynomial *upwqp);
 
 __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_from_pw_qpolynomial(__isl_take isl_pw_qpolynomial *pwqp);
 __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_zero(
-       __isl_take isl_dim *dim);
+       __isl_take isl_space *dim);
 __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);
@@ -448,7 +440,7 @@ __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_dim *isl_union_pw_qpolynomial_get_dim(
+__isl_give isl_space *isl_union_pw_qpolynomial_get_space(
        __isl_keep isl_union_pw_qpolynomial *upwqp);
 
 __isl_give isl_qpolynomial *isl_union_pw_qpolynomial_eval(
@@ -462,26 +454,23 @@ __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_gist(
 
 __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_align_params(
        __isl_take isl_union_pw_qpolynomial *upwqp,
-       __isl_take isl_dim *model);
+       __isl_take isl_space *model);
 
 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);
 __isl_give isl_pw_qpolynomial *isl_union_pw_qpolynomial_extract_pw_qpolynomial(
-       __isl_keep isl_union_pw_qpolynomial *upwqp, __isl_take isl_dim *dim);
+       __isl_keep isl_union_pw_qpolynomial *upwqp, __isl_take isl_space *dim);
 
 __isl_give isl_printer *isl_printer_print_union_pw_qpolynomial(
        __isl_take isl_printer *p, __isl_keep isl_union_pw_qpolynomial *upwqp);
 
-struct isl_union_pw_qpolynomial_fold;
-typedef struct isl_union_pw_qpolynomial_fold isl_union_pw_qpolynomial_fold;
-
 isl_ctx *isl_union_pw_qpolynomial_fold_get_ctx(
        __isl_keep isl_union_pw_qpolynomial_fold *upwf);
 
 __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_fold_from_pw_qpolynomial_fold(__isl_take isl_pw_qpolynomial_fold *pwf);
 __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_fold_zero(
-       __isl_take isl_dim *dim, enum isl_fold type);
+       __isl_take isl_space *dim, enum isl_fold type);
 __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_fold_fold_pw_qpolynomial_fold(
        __isl_take isl_union_pw_qpolynomial_fold *upwqp,
        __isl_take isl_pw_qpolynomial_fold *pwqp);
@@ -507,7 +496,7 @@ __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_fold_intersec
 
 enum isl_fold isl_union_pw_qpolynomial_fold_get_type(
        __isl_keep isl_union_pw_qpolynomial_fold *upwf);
-__isl_give isl_dim *isl_union_pw_qpolynomial_fold_get_dim(
+__isl_give isl_space *isl_union_pw_qpolynomial_fold_get_space(
        __isl_keep isl_union_pw_qpolynomial_fold *upwf);
 
 __isl_give isl_qpolynomial *isl_union_pw_qpolynomial_fold_eval(
@@ -522,14 +511,14 @@ __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_fold_gist(
 
 __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_fold_align_params(
        __isl_take isl_union_pw_qpolynomial_fold *upwf,
-       __isl_take isl_dim *model);
+       __isl_take isl_space *model);
 
 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);
 __isl_give isl_pw_qpolynomial_fold *isl_union_pw_qpolynomial_fold_extract_pw_qpolynomial_fold(
-       __isl_keep isl_union_pw_qpolynomial_fold *upwf, __isl_take isl_dim *dim);
+       __isl_keep isl_union_pw_qpolynomial_fold *upwf, __isl_take isl_space *dim);
 
 __isl_give isl_printer *isl_printer_print_union_pw_qpolynomial_fold(
        __isl_take isl_printer *p,
@@ -552,4 +541,6 @@ __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_to_polynomial(
 }
 #endif
 
+#include <isl/dim.h>
+
 #endif
diff --git a/include/isl/polynomial_type.h b/include/isl/polynomial_type.h
new file mode 100644 (file)
index 0000000..021374e
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef ISL_POLYNOMIAL_TYPE_H
+#define ISL_POLYNOMIAL_TYPE_H
+
+struct isl_qpolynomial;
+typedef struct isl_qpolynomial isl_qpolynomial;
+
+struct isl_term;
+typedef struct isl_term isl_term;
+
+struct isl_pw_qpolynomial;
+typedef struct isl_pw_qpolynomial isl_pw_qpolynomial;
+
+enum isl_fold {
+       isl_fold_min,
+       isl_fold_max,
+       isl_fold_list
+};
+
+struct isl_qpolynomial_fold;
+typedef struct isl_qpolynomial_fold isl_qpolynomial_fold;
+
+struct isl_pw_qpolynomial_fold;
+typedef struct isl_pw_qpolynomial_fold isl_pw_qpolynomial_fold;
+
+struct isl_union_pw_qpolynomial;
+typedef struct isl_union_pw_qpolynomial isl_union_pw_qpolynomial;
+
+struct isl_union_pw_qpolynomial_fold;
+typedef struct isl_union_pw_qpolynomial_fold isl_union_pw_qpolynomial_fold;
+
+#endif
index 026adc3..2316038 100644 (file)
 extern "C" {
 #endif
 
-unsigned isl_basic_set_n_dim(const struct isl_basic_set *bset);
-unsigned isl_basic_set_n_param(const struct isl_basic_set *bset);
+unsigned isl_basic_set_n_dim(__isl_keep isl_basic_set *bset);
+unsigned isl_basic_set_n_param(__isl_keep isl_basic_set *bset);
 unsigned isl_basic_set_total_dim(const struct isl_basic_set *bset);
-unsigned isl_basic_set_dim(const struct isl_basic_set *bset,
+unsigned isl_basic_set_dim(__isl_keep isl_basic_set *bset,
                                enum isl_dim_type type);
 
-unsigned isl_set_n_dim(const struct isl_set *set);
-unsigned isl_set_n_param(const struct isl_set *set);
-unsigned isl_set_dim(const struct isl_set *set, enum isl_dim_type type);
+unsigned isl_set_n_dim(__isl_keep isl_set *set);
+unsigned isl_set_n_param(__isl_keep isl_set *set);
+unsigned isl_set_dim(__isl_keep isl_set *set, enum isl_dim_type type);
 
 isl_ctx *isl_basic_set_get_ctx(__isl_keep isl_basic_set *bset);
 isl_ctx *isl_set_get_ctx(__isl_keep isl_set *set);
-__isl_give isl_dim *isl_basic_set_get_dim(__isl_keep isl_basic_set *bset);
-__isl_give isl_dim *isl_set_get_dim(__isl_keep isl_set *set);
-__isl_give isl_set *isl_set_reset_dim(__isl_take isl_set *set,
-       __isl_take isl_dim *dim);
+__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);
+__isl_give isl_set *isl_set_reset_space(__isl_take isl_set *set,
+       __isl_take isl_space *dim);
 
 struct isl_div *isl_basic_set_div(struct isl_basic_set *bset, int pos);
 
@@ -59,6 +59,21 @@ const char *isl_set_get_dim_name(__isl_keep isl_set *set,
 __isl_give isl_set *isl_set_set_dim_name(__isl_take isl_set *set,
        enum isl_dim_type type, unsigned pos, const char *s);
 
+__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);
+__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);
+
+int isl_set_find_dim_by_id(__isl_keep isl_set *set, enum isl_dim_type type,
+       __isl_keep isl_id *id);
+
 int isl_basic_set_is_rational(__isl_keep isl_basic_set *bset);
 
 struct isl_basic_set *isl_basic_set_alloc(struct isl_ctx *ctx,
@@ -73,16 +88,17 @@ struct isl_basic_set *isl_basic_set_finalize(struct isl_basic_set *bset);
 void isl_basic_set_free(__isl_take isl_basic_set *bset);
 __isl_give isl_basic_set *isl_basic_set_copy(__isl_keep isl_basic_set *bset);
 struct isl_basic_set *isl_basic_set_dup(struct isl_basic_set *bset);
-__isl_give isl_basic_set *isl_basic_set_empty(__isl_take isl_dim *dim);
+__isl_give isl_basic_set *isl_basic_set_empty(__isl_take isl_space *dim);
 struct isl_basic_set *isl_basic_set_empty_like(struct isl_basic_set *bset);
-__isl_give isl_basic_set *isl_basic_set_universe(__isl_take isl_dim *dim);
-__isl_give isl_basic_set *isl_basic_set_nat_universe(__isl_take isl_dim *dim);
+__isl_give isl_basic_set *isl_basic_set_universe(__isl_take isl_space *dim);
+__isl_give isl_basic_set *isl_basic_set_nat_universe(__isl_take isl_space *dim);
 struct isl_basic_set *isl_basic_set_universe_like(struct isl_basic_set *bset);
 __isl_give isl_basic_set *isl_basic_set_universe_like_set(
        __isl_keep isl_set *model);
 struct isl_basic_set *isl_basic_set_interval(struct isl_ctx *ctx,
        isl_int min, isl_int max);
-struct isl_basic_set *isl_basic_set_positive_orthant(struct isl_dim *dims);
+__isl_give isl_basic_set *isl_basic_set_positive_orthant(
+       __isl_take isl_space *space);
 void isl_basic_set_print_internal(__isl_keep isl_basic_set *bset,
                                FILE *out, int indent);
 __isl_give isl_basic_set *isl_basic_set_intersect(
@@ -132,6 +148,9 @@ __isl_give isl_set *isl_set_fix_si(__isl_take isl_set *set,
 __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_equate(__isl_take isl_set *set,
+       enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2);
+
 struct isl_basic_set *isl_basic_set_from_underlying_set(
        struct isl_basic_set *bset, struct isl_basic_set *like);
 struct isl_set *isl_set_from_underlying_set(
@@ -171,6 +190,9 @@ int isl_basic_set_compare_at(struct isl_basic_set *bset1,
 int isl_set_follows_at(__isl_keep isl_set *set1,
        __isl_keep isl_set *set2, int pos);
 
+__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);
+
 int isl_basic_set_dims_get_sign(__isl_keep isl_basic_set *bset,
        enum isl_dim_type type, unsigned pos, unsigned n, int *signs);
 
@@ -184,10 +206,10 @@ struct isl_set *isl_set_alloc(struct isl_ctx *ctx,
                unsigned nparam, unsigned dim, int n, unsigned flags);
 struct isl_set *isl_set_extend(struct isl_set *base,
                unsigned nparam, unsigned dim);
-__isl_give isl_set *isl_set_empty(__isl_take isl_dim *dim);
+__isl_give isl_set *isl_set_empty(__isl_take isl_space *dim);
 struct isl_set *isl_set_empty_like(struct isl_set *set);
-__isl_give isl_set *isl_set_universe(__isl_take isl_dim *dim);
-__isl_give isl_set *isl_set_nat_universe(__isl_take isl_dim *dim);
+__isl_give isl_set *isl_set_universe(__isl_take isl_space *dim);
+__isl_give isl_set *isl_set_nat_universe(__isl_take isl_space *dim);
 __isl_give isl_set *isl_set_universe_like(__isl_keep isl_set *model);
 __isl_give isl_set *isl_set_add_basic_set(__isl_take isl_set *set,
                                                __isl_take isl_basic_set *bset);
@@ -236,7 +258,7 @@ struct isl_set *isl_set_fix_dim_si(struct isl_set *set,
                unsigned dim, int value);
 struct isl_set *isl_set_lower_bound_dim(struct isl_set *set,
                unsigned dim, isl_int value);
-__isl_give isl_set *isl_set_insert(__isl_take isl_set *set,
+__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_add(__isl_take isl_basic_set *bset,
                enum isl_dim_type type, unsigned n);
@@ -278,6 +300,7 @@ int isl_set_plain_is_empty(__isl_keep isl_set *set);
 int isl_set_fast_is_empty(__isl_keep isl_set *set);
 int isl_set_plain_is_universe(__isl_keep isl_set *set);
 int isl_set_fast_is_universe(__isl_keep isl_set *set);
+int isl_set_is_params(__isl_keep isl_set *set);
 int isl_set_is_empty(__isl_keep isl_set *set);
 int isl_set_is_bounded(__isl_keep isl_set *set);
 int isl_set_is_subset(__isl_keep isl_set *set1, __isl_keep isl_set *set2);
@@ -285,7 +308,7 @@ int isl_set_is_strict_subset(__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);
 int isl_set_is_singleton(__isl_keep isl_set *set);
 int isl_set_is_box(__isl_keep isl_set *set);
-int isl_set_has_equal_dim(__isl_keep isl_set *set1, __isl_keep isl_set *set2);
+int isl_set_has_equal_space(__isl_keep isl_set *set1, __isl_keep isl_set *set2);
 
 __isl_give isl_set *isl_set_sum(__isl_take isl_set *set1,
        __isl_take isl_set *set2);
@@ -312,6 +335,10 @@ int isl_set_plain_dim_has_fixed_lower_bound(__isl_keep isl_set *set,
        unsigned dim, isl_int *val);
 int isl_set_dim_is_bounded(__isl_keep isl_set *set,
        enum isl_dim_type type, unsigned pos);
+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);
 
 __isl_give isl_basic_set *isl_basic_set_gist(__isl_take isl_basic_set *bset,
                                            __isl_take isl_basic_set *context);
@@ -319,6 +346,8 @@ __isl_give isl_set *isl_set_gist_basic_set(__isl_take isl_set *set,
        __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);
 int isl_basic_set_dim_residue_class(struct isl_basic_set *bset,
        int pos, isl_int *modulo, isl_int *residue);
 int isl_set_dim_residue_class(struct isl_set *set,
@@ -370,7 +399,7 @@ __isl_give isl_map *isl_set_lex_gt_set(__isl_take isl_set *set1,
 int isl_set_size(__isl_keep isl_set *set);
 
 __isl_give isl_set *isl_set_align_params(__isl_take isl_set *set,
-       __isl_take isl_dim *model);
+       __isl_take isl_space *model);
 
 __isl_give isl_mat *isl_basic_set_equalities_matrix(
        __isl_keep isl_basic_set *bset, enum isl_dim_type c1,
@@ -379,7 +408,7 @@ __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_basic_set *isl_basic_set_from_constraint_matrices(
-       __isl_take isl_dim *dim,
+       __isl_take isl_space *dim,
        __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);
 
@@ -393,9 +422,12 @@ __isl_give isl_basic_set *isl_basic_set_solutions(
 __isl_give isl_basic_set *isl_set_solutions(__isl_take isl_set *set);
 
 __isl_give isl_pw_aff *isl_set_dim_max(__isl_take isl_set *set, int pos);
+__isl_give isl_pw_aff *isl_set_dim_min(__isl_take isl_set *set, int pos);
 
 #if defined(__cplusplus)
 }
 #endif
 
+#include <isl/dim.h>
+
 #endif
diff --git a/include/isl/space.h b/include/isl/space.h
new file mode 100644 (file)
index 0000000..2ca7f95
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2008-2009 Katholieke Universiteit Leuven
+ *
+ * Use of this software is governed by the GNU LGPLv2.1 license
+ *
+ * Written by Sven Verdoolaege, K.U.Leuven, Departement
+ * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
+ */
+
+#ifndef ISL_SPACE_H
+#define ISL_SPACE_H
+
+#include <isl/ctx.h>
+#include <isl/id.h>
+#include <isl/printer.h>
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+struct isl_space;
+typedef struct isl_space isl_space;
+
+enum isl_dim_type {
+       isl_dim_cst,
+       isl_dim_param,
+       isl_dim_in,
+       isl_dim_out,
+       isl_dim_set = isl_dim_out,
+       isl_dim_div,
+       isl_dim_all
+};
+
+isl_ctx *isl_space_get_ctx(__isl_keep isl_space *dim);
+__isl_give isl_space *isl_space_alloc(isl_ctx *ctx,
+                       unsigned nparam, unsigned n_in, unsigned n_out);
+__isl_give isl_space *isl_space_set_alloc(isl_ctx *ctx,
+                       unsigned nparam, unsigned dim);
+__isl_give isl_space *isl_space_params_alloc(isl_ctx *ctx, unsigned nparam);
+__isl_give isl_space *isl_space_copy(__isl_keep isl_space *dim);
+void isl_space_free(__isl_take isl_space *dim);
+
+int isl_space_is_params(__isl_keep isl_space *space);
+int isl_space_is_set(__isl_keep isl_space *space);
+
+__isl_give isl_space *isl_space_set_tuple_name(__isl_take isl_space *dim,
+       enum isl_dim_type type, const char *s);
+const char *isl_space_get_tuple_name(__isl_keep isl_space *dim,
+                                enum isl_dim_type type);
+__isl_give isl_space *isl_space_set_tuple_id(__isl_take isl_space *dim,
+       enum isl_dim_type type, __isl_take isl_id *id);
+__isl_give isl_space *isl_space_reset_tuple_id(__isl_take isl_space *dim,
+       enum isl_dim_type type);
+int isl_space_has_tuple_id(__isl_keep isl_space *dim, enum isl_dim_type type);
+__isl_give isl_id *isl_space_get_tuple_id(__isl_keep isl_space *dim,
+       enum isl_dim_type type);
+
+__isl_give isl_space *isl_space_set_dim_id(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned pos, __isl_take isl_id *id);
+int isl_space_has_dim_id(__isl_keep isl_space *dim,
+       enum isl_dim_type type, unsigned pos);
+__isl_give isl_id *isl_space_get_dim_id(__isl_keep isl_space *dim,
+       enum isl_dim_type type, unsigned pos);
+
+int isl_space_find_dim_by_id(__isl_keep isl_space *dim, enum isl_dim_type type,
+       __isl_keep isl_id *id);
+
+__isl_give isl_space *isl_space_set_dim_name(__isl_take isl_space *dim,
+                                enum isl_dim_type type, unsigned pos,
+                                __isl_keep const char *name);
+__isl_keep const char *isl_space_get_dim_name(__isl_keep isl_space *dim,
+                                enum isl_dim_type type, unsigned pos);
+
+__isl_give isl_space *isl_space_extend(__isl_take isl_space *dim,
+                       unsigned nparam, unsigned n_in, unsigned n_out);
+__isl_give isl_space *isl_space_add_dims(__isl_take isl_space *dim, enum isl_dim_type type,
+               unsigned n);
+__isl_give isl_space *isl_space_move_dims(__isl_take isl_space *dim,
+       enum isl_dim_type dst_type, unsigned dst_pos,
+       enum isl_dim_type src_type, unsigned src_pos, unsigned n);
+__isl_give isl_space *isl_space_insert_dims(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned pos, unsigned n);
+__isl_give isl_space *isl_space_join(__isl_take isl_space *left,
+       __isl_take isl_space *right);
+__isl_give isl_space *isl_space_product(__isl_take isl_space *left,
+       __isl_take isl_space *right);
+__isl_give isl_space *isl_space_domain_product(__isl_take isl_space *left,
+       __isl_take isl_space *right);
+__isl_give isl_space *isl_space_range_product(__isl_take isl_space *left,
+       __isl_take isl_space *right);
+__isl_give isl_space *isl_space_map_from_set(__isl_take isl_space *dim);
+__isl_give isl_space *isl_space_reverse(__isl_take isl_space *dim);
+__isl_give isl_space *isl_space_drop_dims(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned first, unsigned num);
+__isl_give isl_space *isl_space_drop_inputs(__isl_take isl_space *dim,
+               unsigned first, unsigned n);
+__isl_give isl_space *isl_space_drop_outputs(__isl_take isl_space *dim,
+               unsigned first, unsigned n);
+__isl_give isl_space *isl_space_domain(__isl_take isl_space *dim);
+__isl_give isl_space *isl_space_from_domain(__isl_take isl_space *dim);
+__isl_give isl_space *isl_space_range(__isl_take isl_space *dim);
+__isl_give isl_space *isl_space_from_range(__isl_take isl_space *dim);
+__isl_give isl_space *isl_space_params(__isl_take isl_space *space);
+
+__isl_give isl_space *isl_space_align_params(__isl_take isl_space *dim1,
+       __isl_take isl_space *dim2);
+
+int isl_space_is_wrapping(__isl_keep isl_space *dim);
+__isl_give isl_space *isl_space_wrap(__isl_take isl_space *dim);
+__isl_give isl_space *isl_space_unwrap(__isl_take isl_space *dim);
+
+int isl_space_can_zip(__isl_keep isl_space *dim);
+__isl_give isl_space *isl_space_zip(__isl_take isl_space *dim);
+
+int isl_space_is_equal(__isl_keep isl_space *dim1, __isl_keep isl_space *dim2);
+int isl_space_match(__isl_keep isl_space *dim1, enum isl_dim_type dim1_type,
+       __isl_keep isl_space *dim2, enum isl_dim_type dim2_type);
+int isl_space_tuple_match(__isl_keep isl_space *dim1, enum isl_dim_type dim1_type,
+                       __isl_keep isl_space *dim2, enum isl_dim_type dim2_type);
+int isl_space_compatible(__isl_keep isl_space *dim1,
+       __isl_keep isl_space *dim2);
+unsigned isl_space_dim(__isl_keep isl_space *dim, enum isl_dim_type type);
+
+__isl_give isl_printer *isl_printer_print_space(__isl_take isl_printer *p,
+       __isl_keep isl_space *dim);
+void isl_space_dump(__isl_keep isl_space *dim);
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif
index 779c6cf..5d9b979 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <stdio.h>
 #include <isl/hash.h>
+#include <isl/aff_type.h>
 #include <isl/obj.h>
 
 #if defined(__cplusplus)
@@ -22,6 +23,7 @@ enum isl_token_type { ISL_TOKEN_ERROR = -1,
                        ISL_TOKEN_UNKNOWN = 256, ISL_TOKEN_VALUE,
                        ISL_TOKEN_IDENT, ISL_TOKEN_GE,
                        ISL_TOKEN_LE, ISL_TOKEN_GT, ISL_TOKEN_LT,
+                       ISL_TOKEN_NE,
                        ISL_TOKEN_LEX_GE, ISL_TOKEN_LEX_LE,
                        ISL_TOKEN_LEX_GT, ISL_TOKEN_LEX_LT,
                        ISL_TOKEN_TO, ISL_TOKEN_AND,
@@ -29,8 +31,9 @@ enum isl_token_type { ISL_TOKEN_ERROR = -1,
                        ISL_TOKEN_DEF, ISL_TOKEN_INFTY, ISL_TOKEN_NAN,
                        ISL_TOKEN_MIN, ISL_TOKEN_MAX, ISL_TOKEN_RAT,
                        ISL_TOKEN_TRUE, ISL_TOKEN_FALSE,
-                       ISL_TOKEN_CEILD, ISL_TOKEN_FLOORD,
+                       ISL_TOKEN_CEILD, ISL_TOKEN_FLOORD, ISL_TOKEN_MOD,
                        ISL_TOKEN_STRING,
+                       ISL_TOKEN_MAP, ISL_TOKEN_AFF,
                        ISL_TOKEN_LAST };
 
 struct isl_token {
@@ -44,6 +47,8 @@ struct isl_token {
        union {
                isl_int v;
                char    *s;
+               isl_map *map;
+               isl_pw_aff *pwaff;
        } u;
 };
 
index 5f61d0a..70699a7 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef ISL_UNION_MAP_H
 #define ISL_UNION_MAP_H
 
-#include <isl/dim.h>
+#include <isl/space.h>
 #include <isl/map_type.h>
 #include <isl/printer.h>
 
@@ -17,12 +17,12 @@ typedef struct isl_union_set isl_union_set;
 #endif
 
 __isl_give isl_union_map *isl_union_map_from_map(__isl_take isl_map *map);
-__isl_give isl_union_map *isl_union_map_empty(__isl_take isl_dim *dim);
+__isl_give isl_union_map *isl_union_map_empty(__isl_take isl_space *dim);
 __isl_give isl_union_map *isl_union_map_copy(__isl_keep isl_union_map *umap);
 void *isl_union_map_free(__isl_take isl_union_map *umap);
 
 isl_ctx *isl_union_map_get_ctx(__isl_keep isl_union_map *umap);
-__isl_give isl_dim *isl_union_map_get_dim(__isl_keep isl_union_map *umap);
+__isl_give isl_space *isl_union_map_get_space(__isl_keep isl_union_map *umap);
 
 __isl_give isl_union_map *isl_union_map_universe(
        __isl_take isl_union_map *umap);
@@ -104,9 +104,9 @@ int isl_union_map_n_map(__isl_keep isl_union_map *umap);
 int isl_union_map_foreach_map(__isl_keep isl_union_map *umap,
        int (*fn)(__isl_take isl_map *map, void *user), void *user);
 __isl_give int isl_union_map_contains(__isl_keep isl_union_map *umap,
-       __isl_keep isl_dim *dim);
+       __isl_keep isl_space *dim);
 __isl_give isl_map *isl_union_map_extract_map(__isl_keep isl_union_map *umap,
-       __isl_take isl_dim *dim);
+       __isl_take isl_space *dim);
 __isl_give isl_map *isl_map_from_union_map(__isl_take isl_union_map *umap);
 
 __isl_give isl_basic_map *isl_union_map_sample(__isl_take isl_union_map *umap);
@@ -127,7 +127,7 @@ __isl_give isl_union_map *isl_union_map_lex_ge_union_map(
 
 __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(struct isl_ctx *ctx,
+__isl_give isl_union_map *isl_union_map_read_from_str(isl_ctx *ctx,
        const char *str);
 __isl_give isl_printer *isl_printer_print_union_map(__isl_take isl_printer *p,
        __isl_keep isl_union_map *umap);
@@ -139,12 +139,14 @@ __isl_give isl_union_map *isl_union_set_unwrap(__isl_take isl_union_set *uset);
 __isl_give isl_union_map *isl_union_map_zip(__isl_take isl_union_map *umap);
 
 __isl_give isl_union_map *isl_union_map_align_params(
-       __isl_take isl_union_map *umap, __isl_take isl_dim *model);
+       __isl_take isl_union_map *umap, __isl_take isl_space *model);
 __isl_give isl_union_set *isl_union_set_align_params(
-       __isl_take isl_union_set *uset, __isl_take isl_dim *model);
+       __isl_take isl_union_set *uset, __isl_take isl_space *model);
 
 #if defined(__cplusplus)
 }
 #endif
 
+#include <isl/dim.h>
+
 #endif
index 3401f4e..eda3ff9 100644 (file)
@@ -9,12 +9,12 @@ extern "C" {
 #endif
 
 __isl_give isl_union_set *isl_union_set_from_set(__isl_take isl_set *set);
-__isl_give isl_union_set *isl_union_set_empty(__isl_take isl_dim *dim);
+__isl_give isl_union_set *isl_union_set_empty(__isl_take isl_space *dim);
 __isl_give isl_union_set *isl_union_set_copy(__isl_keep isl_union_set *uset);
 void *isl_union_set_free(__isl_take isl_union_set *uset);
 
 isl_ctx *isl_union_set_get_ctx(__isl_keep isl_union_set *uset);
-__isl_give isl_dim *isl_union_set_get_dim(__isl_keep isl_union_set *uset);
+__isl_give isl_space *isl_union_set_get_space(__isl_keep isl_union_set *uset);
 
 __isl_give isl_union_set *isl_union_set_universe(
        __isl_take isl_union_set *uset);
@@ -63,9 +63,9 @@ int isl_union_set_n_set(__isl_keep isl_union_set *uset);
 int isl_union_set_foreach_set(__isl_keep isl_union_set *uset,
        int (*fn)(__isl_take isl_set *set, void *user), void *user);
 __isl_give int isl_union_set_contains(__isl_keep isl_union_set *uset,
-       __isl_keep isl_dim *dim);
+       __isl_keep isl_space *dim);
 __isl_give isl_set *isl_union_set_extract_set(__isl_keep isl_union_set *uset,
-       __isl_take isl_dim *dim);
+       __isl_take isl_space *dim);
 __isl_give isl_set *isl_set_from_union_set(__isl_take isl_union_set *uset);
 int isl_union_set_foreach_point(__isl_keep isl_union_set *uset,
        int (*fn)(__isl_take isl_point *pnt, void *user), void *user);
@@ -90,7 +90,7 @@ __isl_give isl_union_set *isl_union_set_solutions(
 
 __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(struct isl_ctx *ctx,
+__isl_give isl_union_set *isl_union_set_read_from_str(isl_ctx *ctx,
        const char *str);
 __isl_give isl_printer *isl_printer_print_union_set(__isl_take isl_printer *p,
        __isl_keep isl_union_set *uset);
@@ -100,4 +100,6 @@ void isl_union_set_dump(__isl_keep isl_union_set *uset);
 }
 #endif
 
+#include <isl/dim.h>
+
 #endif
index e592838..eb9a7e2 100644 (file)
@@ -50,6 +50,7 @@ void isl_vec_lcm(struct isl_vec *vec, isl_int *lcm);
 struct isl_vec *isl_vec_ceil(struct isl_vec *vec);
 struct isl_vec *isl_vec_normalize(struct isl_vec *vec);
 __isl_give isl_vec *isl_vec_clr(__isl_take isl_vec *vec);
+__isl_give isl_vec *isl_vec_neg(__isl_take isl_vec *vec);
 __isl_give isl_vec *isl_vec_scale(__isl_take isl_vec *vec, isl_int m);
 __isl_give isl_vec *isl_vec_add(__isl_take isl_vec *vec1,
        __isl_take isl_vec *vec2);
index 941dcb6..437e44f 100644 (file)
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -9,11 +9,13 @@
  * 91893 Orsay, France
  */
 
+#include <isl_ctx_private.h>
 #include <isl_map_private.h>
 #include <isl_aff_private.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl_local_space_private.h>
 #include <isl_mat_private.h>
+#include <isl_list_private.h>
 #include <isl/constraint.h>
 #include <isl/seq.h>
 #include <isl/set.h>
@@ -54,6 +56,10 @@ __isl_give isl_aff *isl_aff_alloc(__isl_take isl_local_space *ls)
        if (!isl_local_space_divs_known(ls))
                isl_die(ctx, isl_error_invalid, "local space has unknown divs",
                        goto error);
+       if (!isl_local_space_is_set(ls))
+               isl_die(ctx, isl_error_invalid,
+                       "domain of affine expression should be a set",
+                       goto error);
 
        total = isl_local_space_dim(ls, isl_dim_all);
        v = isl_vec_alloc(ctx, 1 + 1 + total);
@@ -63,7 +69,7 @@ error:
        return NULL;
 }
 
-__isl_give isl_aff *isl_aff_zero(__isl_take isl_local_space *ls)
+__isl_give isl_aff *isl_aff_zero_on_domain(__isl_take isl_local_space *ls)
 {
        isl_aff *aff;
 
@@ -127,45 +133,97 @@ isl_ctx *isl_aff_get_ctx(__isl_keep isl_aff *aff)
        return aff ? isl_local_space_get_ctx(aff->ls) : NULL;
 }
 
+/* Externally, an isl_aff has a map space, but internally, the
+ * ls field corresponds to the domain of that space.
+ */
 int isl_aff_dim(__isl_keep isl_aff *aff, enum isl_dim_type type)
 {
-       return aff ? isl_local_space_dim(aff->ls, type) : 0;
+       if (!aff)
+               return 0;
+       if (type == isl_dim_out)
+               return 1;
+       if (type == isl_dim_in)
+               type = isl_dim_set;
+       return isl_local_space_dim(aff->ls, type);
 }
 
-__isl_give isl_dim *isl_aff_get_dim(__isl_keep isl_aff *aff)
+__isl_give isl_space *isl_aff_get_domain_space(__isl_keep isl_aff *aff)
 {
-       return aff ? isl_local_space_get_dim(aff->ls) : NULL;
+       return aff ? isl_local_space_get_space(aff->ls) : NULL;
 }
 
-__isl_give isl_local_space *isl_aff_get_local_space(__isl_keep isl_aff *aff)
+__isl_give isl_space *isl_aff_get_space(__isl_keep isl_aff *aff)
+{
+       isl_space *space;
+       if (!aff)
+               return NULL;
+       space = isl_local_space_get_space(aff->ls);
+       space = isl_space_from_domain(space);
+       space = isl_space_add_dims(space, isl_dim_out, 1);
+       return space;
+}
+
+__isl_give isl_local_space *isl_aff_get_domain_local_space(
+       __isl_keep isl_aff *aff)
 {
        return aff ? isl_local_space_copy(aff->ls) : NULL;
 }
 
+__isl_give isl_local_space *isl_aff_get_local_space(__isl_keep isl_aff *aff)
+{
+       isl_local_space *ls;
+       if (!aff)
+               return NULL;
+       ls = isl_local_space_copy(aff->ls);
+       ls = isl_local_space_from_domain(ls);
+       ls = isl_local_space_add_dims(ls, isl_dim_out, 1);
+       return ls;
+}
+
+/* Externally, an isl_aff has a map space, but internally, the
+ * ls field corresponds to the domain of that space.
+ */
 const char *isl_aff_get_dim_name(__isl_keep isl_aff *aff,
        enum isl_dim_type type, unsigned pos)
 {
-       return aff ? isl_local_space_get_dim_name(aff->ls, type, pos) : 0;
+       if (!aff)
+               return NULL;
+       if (type == isl_dim_out)
+               return NULL;
+       if (type == isl_dim_in)
+               type = isl_dim_set;
+       return isl_local_space_get_dim_name(aff->ls, type, pos);
 }
 
-__isl_give isl_aff *isl_aff_reset_dim(__isl_take isl_aff *aff,
-       __isl_take isl_dim *dim)
+__isl_give isl_aff *isl_aff_reset_domain_space(__isl_take isl_aff *aff,
+       __isl_take isl_space *dim)
 {
        aff = isl_aff_cow(aff);
        if (!aff || !dim)
                goto error;
 
-       aff->ls = isl_local_space_reset_dim(aff->ls, dim);
+       aff->ls = isl_local_space_reset_space(aff->ls, dim);
        if (!aff->ls)
                return isl_aff_free(aff);
 
        return aff;
 error:
        isl_aff_free(aff);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
+/* Reset the space of "aff".  This function is called from isl_pw_templ.c
+ * and doesn't know if the space of an element object is represented
+ * directly or through its domain.  It therefore passes along both.
+ */
+__isl_give isl_aff *isl_aff_reset_space_and_domain(__isl_take isl_aff *aff,
+       __isl_take isl_space *space, __isl_take isl_space *domain)
+{
+       isl_space_free(space);
+       return isl_aff_reset_domain_space(aff, domain);
+}
+
 /* Reorder the coefficients of the affine expression based
  * on the given reodering.
  * The reordering r is assumed to have been extended with the local
@@ -180,7 +238,8 @@ static __isl_give isl_vec *vec_reorder(__isl_take isl_vec *vec,
        if (!vec || !r)
                goto error;
 
-       res = isl_vec_alloc(vec->ctx, 2 + isl_dim_total(r->dim) + n_div);
+       res = isl_vec_alloc(vec->ctx,
+                           2 + isl_space_dim(r->dim, isl_dim_all) + n_div);
        isl_seq_cpy(res->el, vec->el, 2);
        isl_seq_clr(res->el + 2, res->size - 2);
        for (i = 0; i < r->len; ++i)
@@ -195,9 +254,10 @@ error:
        return NULL;
 }
 
-/* Reorder the dimensions of "aff" according to the given reordering.
+/* Reorder the dimensions of the domain of "aff" according
+ * to the given reordering.
  */
-__isl_give isl_aff *isl_aff_realign(__isl_take isl_aff *aff,
+__isl_give isl_aff *isl_aff_realign_domain(__isl_take isl_aff *aff,
        __isl_take isl_reordering *r)
 {
        aff = isl_aff_cow(aff);
@@ -263,6 +323,13 @@ int isl_aff_get_coefficient(__isl_keep isl_aff *aff,
        if (!aff)
                return -1;
 
+       if (type == isl_dim_out)
+               isl_die(aff->v->ctx, isl_error_invalid,
+                       "output/set dimension does not have a coefficient",
+                       return -1);
+       if (type == isl_dim_in)
+               type = isl_dim_set;
+
        if (pos >= isl_local_space_dim(aff->ls, type))
                isl_die(aff->v->ctx, isl_error_invalid,
                        "position out of bounds", return -1);
@@ -354,6 +421,13 @@ __isl_give isl_aff *isl_aff_set_coefficient(__isl_take isl_aff *aff,
        if (!aff)
                return NULL;
 
+       if (type == isl_dim_out)
+               isl_die(aff->v->ctx, isl_error_invalid,
+                       "output/set dimension does not have a coefficient",
+                       return isl_aff_free(aff));
+       if (type == isl_dim_in)
+               type = isl_dim_set;
+
        if (pos >= isl_local_space_dim(aff->ls, type))
                isl_die(aff->v->ctx, isl_error_invalid,
                        "position out of bounds", return isl_aff_free(aff));
@@ -378,6 +452,13 @@ __isl_give isl_aff *isl_aff_set_coefficient_si(__isl_take isl_aff *aff,
        if (!aff)
                return NULL;
 
+       if (type == isl_dim_out)
+               isl_die(aff->v->ctx, isl_error_invalid,
+                       "output/set dimension does not have a coefficient",
+                       return isl_aff_free(aff));
+       if (type == isl_dim_in)
+               type = isl_dim_set;
+
        if (pos >= isl_local_space_dim(aff->ls, type))
                isl_die(aff->v->ctx, isl_error_invalid,
                        "position out of bounds", return isl_aff_free(aff));
@@ -402,6 +483,13 @@ __isl_give isl_aff *isl_aff_add_coefficient(__isl_take isl_aff *aff,
        if (!aff)
                return NULL;
 
+       if (type == isl_dim_out)
+               isl_die(aff->v->ctx, isl_error_invalid,
+                       "output/set dimension does not have a coefficient",
+                       return isl_aff_free(aff));
+       if (type == isl_dim_in)
+               type = isl_dim_set;
+
        if (pos >= isl_local_space_dim(aff->ls, type))
                isl_die(aff->v->ctx, isl_error_invalid,
                        "position out of bounds", return isl_aff_free(aff));
@@ -457,12 +545,16 @@ __isl_give isl_aff *isl_aff_neg(__isl_take isl_aff *aff)
 
 /* Given f, return floor(f).
  * If f is an integer expression, then just return f.
- * Otherwise, create a new div d = [f] and return the expression d.
+ * Otherwise, if f = g/m, write g = q m + r,
+ * create a new div d = [r/m] and return the expression q + d.
+ * The coefficients in r are taken to lie between -m/2 and m/2.
  */
 __isl_give isl_aff *isl_aff_floor(__isl_take isl_aff *aff)
 {
+       int i;
        int size;
        isl_ctx *ctx;
+       isl_vec *div;
 
        if (!aff)
                return NULL;
@@ -474,15 +566,29 @@ __isl_give isl_aff *isl_aff_floor(__isl_take isl_aff *aff)
        if (!aff)
                return NULL;
 
-       aff->ls = isl_local_space_add_div(aff->ls, isl_vec_copy(aff->v));
-       if (!aff->ls)
+       aff->v = isl_vec_cow(aff->v);
+       div = isl_vec_copy(aff->v);
+       div = isl_vec_cow(div);
+       if (!div)
                return isl_aff_free(aff);
 
        ctx = isl_aff_get_ctx(aff);
+       isl_int_fdiv_q(aff->v->el[0], aff->v->el[0], ctx->two);
+       for (i = 1; i < aff->v->size; ++i) {
+               isl_int_fdiv_r(div->el[i], div->el[i], div->el[0]);
+               isl_int_fdiv_q(aff->v->el[i], aff->v->el[i], div->el[0]);
+               if (isl_int_gt(div->el[i], aff->v->el[0])) {
+                       isl_int_sub(div->el[i], div->el[i], div->el[0]);
+                       isl_int_add_ui(aff->v->el[i], aff->v->el[i], 1);
+               }
+       }
+
+       aff->ls = isl_local_space_add_div(aff->ls, div);
+       if (!aff->ls)
+               return isl_aff_free(aff);
+
        size = aff->v->size;
-       isl_vec_free(aff->v);
-       aff->v = isl_vec_alloc(ctx, size + 1);
-       aff->v = isl_vec_clr(aff->v);
+       aff->v = isl_vec_extend(aff->v, size + 1);
        if (!aff->v)
                return isl_aff_free(aff);
        isl_int_set_si(aff->v->el[0], 1);
@@ -491,6 +597,40 @@ __isl_give isl_aff *isl_aff_floor(__isl_take isl_aff *aff)
        return aff;
 }
 
+/* Compute
+ *
+ *     aff mod m = aff - m * floor(aff/m)
+ */
+__isl_give isl_aff *isl_aff_mod(__isl_take isl_aff *aff, isl_int m)
+{
+       isl_aff *res;
+
+       res = isl_aff_copy(aff);
+       aff = isl_aff_scale_down(aff, m);
+       aff = isl_aff_floor(aff);
+       aff = isl_aff_scale(aff, m);
+       res = isl_aff_sub(res, aff);
+
+       return res;
+}
+
+/* Compute
+ *
+ *     pwaff mod m = pwaff - m * floor(pwaff/m)
+ */
+__isl_give isl_pw_aff *isl_pw_aff_mod(__isl_take isl_pw_aff *pwaff, isl_int m)
+{
+       isl_pw_aff *res;
+
+       res = isl_pw_aff_copy(pwaff);
+       pwaff = isl_pw_aff_scale_down(pwaff, m);
+       pwaff = isl_pw_aff_floor(pwaff);
+       pwaff = isl_pw_aff_scale(pwaff, m);
+       res = isl_pw_aff_sub(res, pwaff);
+
+       return res;
+}
+
 /* Given f, return ceil(f).
  * If f is an integer expression, then just return f.
  * Otherwise, create a new div d = [-f] and return the expression -d.
@@ -606,7 +746,7 @@ __isl_give isl_aff *isl_aff_add(__isl_take isl_aff *aff1,
                goto error;
 
        ctx = isl_aff_get_ctx(aff1);
-       if (!isl_dim_equal(aff1->ls->dim, aff2->ls->dim))
+       if (!isl_space_is_equal(aff1->ls->dim, aff2->ls->dim))
                isl_die(ctx, isl_error_invalid,
                        "spaces don't match", goto error);
 
@@ -709,6 +849,12 @@ __isl_give isl_aff *isl_aff_set_dim_name(__isl_take isl_aff *aff,
        aff = isl_aff_cow(aff);
        if (!aff)
                return NULL;
+       if (type == isl_dim_out)
+               isl_die(aff->v->ctx, isl_error_invalid,
+                       "cannot set name of output/set dimension",
+                       return isl_aff_free(aff));
+       if (type == isl_dim_in)
+               type = isl_dim_set;
        aff->ls = isl_local_space_set_dim_name(aff->ls, type, pos, s);
        if (!aff->ls)
                return isl_aff_free(aff);
@@ -744,7 +890,7 @@ static __isl_give isl_aff *isl_aff_substitute_equalities_lifted(
        if (!aff->ls)
                goto error;
 
-       total = 1 + isl_dim_total(eq->dim);
+       total = 1 + isl_space_dim(eq->dim, isl_dim_all);
        n_div = eq->n_div;
        for (i = 0; i < eq->n_eq; ++i) {
                j = isl_seq_last_non_zero(eq->eq[i], total + n_div);
@@ -799,9 +945,10 @@ __isl_give isl_aff *isl_aff_gist(__isl_take isl_aff *aff,
        n_div = isl_local_space_dim(aff->ls, isl_dim_div);
        if (n_div > 0) {
                isl_basic_set *bset;
+               isl_local_space *ls;
                context = isl_set_add_dims(context, isl_dim_set, n_div);
-               bset = isl_basic_set_from_local_space(
-                                           isl_aff_get_local_space(aff));
+               ls = isl_aff_get_domain_local_space(aff);
+               bset = isl_basic_set_from_local_space(ls);
                bset = isl_basic_set_lift(bset);
                bset = isl_basic_set_flatten(bset);
                context = isl_set_intersect(context,
@@ -851,6 +998,15 @@ __isl_give isl_basic_set *isl_aff_ge_basic_set(__isl_take isl_aff *aff1,
        return isl_aff_nonneg_basic_set(aff1);
 }
 
+/* Return a basic set containing those elements in the shared space
+ * of aff1 and aff2 where aff1 is smaller than or equal to aff2.
+ */
+__isl_give isl_basic_set *isl_aff_le_basic_set(__isl_take isl_aff *aff1,
+       __isl_take isl_aff *aff2)
+{
+       return isl_aff_ge_basic_set(aff2, aff1);
+}
+
 __isl_give isl_aff *isl_aff_add_on_domain(__isl_keep isl_set *dom,
        __isl_take isl_aff *aff1, __isl_take isl_aff *aff2)
 {
@@ -867,34 +1023,6 @@ int isl_aff_is_empty(__isl_keep isl_aff *aff)
        return 0;
 }
 
-/* Set active[i] to 1 if the dimension at position i is involved
- * in the affine expression.
- */
-static int set_active(__isl_keep isl_aff *aff, int *active)
-{
-       int i, j;
-       unsigned total;
-       unsigned offset;
-
-       if (!aff || !active)
-               return -1;
-
-       total = aff->v->size - 2;
-       for (i = 0; i < total; ++i)
-               active[i] = !isl_int_is_zero(aff->v->el[2 + i]);
-
-       offset = isl_local_space_offset(aff->ls, isl_dim_div) - 1;
-       for (i = aff->ls->div->n_row - 1; i >= 0; --i) {
-               if (!active[offset + i])
-                       continue;
-               for (j = 0; j < total; ++j)
-                       active[j] |=
-                               !isl_int_is_zero(aff->ls->div->row[i][2 + j]);
-       }
-
-       return 0;
-}
-
 /* Check whether the given affine expression has non-zero coefficient
  * for any dimension in the given range or if any of these dimensions
  * appear with non-zero coefficients in any of the integer divisions
@@ -918,9 +1046,8 @@ int isl_aff_involves_dims(__isl_keep isl_aff *aff,
                isl_die(ctx, isl_error_invalid,
                        "range out of bounds", return -1);
 
-       active = isl_calloc_array(ctx, int,
-                                 isl_local_space_dim(aff->ls, isl_dim_all));
-       if (set_active(aff, active) < 0)
+       active = isl_local_space_get_active(aff->ls, aff->v->el + 2);
+       if (!active)
                goto error;
 
        first += isl_local_space_offset(aff->ls, type) - 1;
@@ -945,11 +1072,17 @@ __isl_give isl_aff *isl_aff_drop_dims(__isl_take isl_aff *aff,
 
        if (!aff)
                return NULL;
+       if (type == isl_dim_out)
+               isl_die(aff->v->ctx, isl_error_invalid,
+                       "cannot drop output/set dimension",
+                       return isl_aff_free(aff));
+       if (type == isl_dim_in)
+               type = isl_dim_set;
        if (n == 0 && !isl_local_space_is_named_or_nested(aff->ls, type))
                return aff;
 
        ctx = isl_aff_get_ctx(aff);
-       if (first + n > isl_aff_dim(aff, type))
+       if (first + n > isl_local_space_dim(aff->ls, type))
                isl_die(ctx, isl_error_invalid, "range out of bounds",
                        return isl_aff_free(aff));
 
@@ -976,11 +1109,17 @@ __isl_give isl_aff *isl_aff_insert_dims(__isl_take isl_aff *aff,
 
        if (!aff)
                return NULL;
+       if (type == isl_dim_out)
+               isl_die(aff->v->ctx, isl_error_invalid,
+                       "cannot insert output/set dimensions",
+                       return isl_aff_free(aff));
+       if (type == isl_dim_in)
+               type = isl_dim_set;
        if (n == 0 && !isl_local_space_is_named_or_nested(aff->ls, type))
                return aff;
 
        ctx = isl_aff_get_ctx(aff);
-       if (first > isl_aff_dim(aff, type))
+       if (first > isl_local_space_dim(aff->ls, type))
                isl_die(ctx, isl_error_invalid, "position out of bounds",
                        return isl_aff_free(aff));
 
@@ -1020,6 +1159,23 @@ __isl_give isl_pw_aff *isl_pw_aff_add_dims(__isl_take isl_pw_aff *pwaff,
        return isl_pw_aff_insert_dims(pwaff, type, pos, n);
 }
 
+__isl_give isl_pw_aff *isl_pw_aff_set_tuple_id(__isl_take isl_pw_aff *pwaff,
+       __isl_take isl_id *id)
+{
+       isl_space *dim;
+
+       dim = isl_pw_aff_get_space(pwaff);
+       dim = isl_space_set_tuple_id(dim, isl_dim_in, id);
+
+       return isl_pw_aff_reset_space(pwaff, dim);
+}
+
+__isl_give isl_pw_aff *isl_pw_aff_from_aff(__isl_take isl_aff *aff)
+{
+       isl_set *dom = isl_set_universe(isl_aff_get_domain_space(aff));
+       return isl_pw_aff_alloc(dom, aff);
+}
+
 #undef PW
 #define PW isl_pw_aff
 #undef EL
@@ -1041,14 +1197,40 @@ __isl_give isl_pw_aff *isl_pw_aff_add_dims(__isl_take isl_pw_aff *pwaff,
 
 #include <isl_pw_templ.c>
 
+static __isl_give isl_set *align_params_pw_pw_set_and(
+       __isl_take isl_pw_aff *pwaff1, __isl_take isl_pw_aff *pwaff2,
+       __isl_give isl_set *(*fn)(__isl_take isl_pw_aff *pwaff1,
+                                   __isl_take isl_pw_aff *pwaff2))
+{
+       if (!pwaff1 || !pwaff2)
+               goto error;
+       if (isl_space_match(pwaff1->dim, isl_dim_param,
+                         pwaff2->dim, isl_dim_param))
+               return fn(pwaff1, pwaff2);
+       if (!isl_space_has_named_params(pwaff1->dim) ||
+           !isl_space_has_named_params(pwaff2->dim))
+               isl_die(isl_pw_aff_get_ctx(pwaff1), isl_error_invalid,
+                       "unaligned unnamed parameters", goto error);
+       pwaff1 = isl_pw_aff_align_params(pwaff1, isl_pw_aff_get_space(pwaff2));
+       pwaff2 = isl_pw_aff_align_params(pwaff2, isl_pw_aff_get_space(pwaff1));
+       return fn(pwaff1, pwaff2);
+error:
+       isl_pw_aff_free(pwaff1);
+       isl_pw_aff_free(pwaff2);
+       return NULL;
+}
+
 /* Compute a piecewise quasi-affine expression with a domain that
  * is the union of those of pwaff1 and pwaff2 and such that on each
- * cell, the quasi-affine expression is the maximum of those of pwaff1
- * and pwaff2.  If only one of pwaff1 or pwaff2 is defined on a given
- * cell, then the associated expression is the defined one.
+ * cell, the quasi-affine expression is the better (according to cmp)
+ * of those of pwaff1 and pwaff2.  If only one of pwaff1 or pwaff2
+ * is defined on a given cell, then the associated expression
+ * is the defined one.
  */
-__isl_give isl_pw_aff *isl_pw_aff_max(__isl_take isl_pw_aff *pwaff1,
-       __isl_take isl_pw_aff *pwaff2)
+static __isl_give isl_pw_aff *pw_aff_union_opt(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2,
+       __isl_give isl_basic_set *(*cmp)(__isl_take isl_aff *aff1,
+                                       __isl_take isl_aff *aff2))
 {
        int i, j, n;
        isl_pw_aff *res;
@@ -1058,8 +1240,8 @@ __isl_give isl_pw_aff *isl_pw_aff_max(__isl_take isl_pw_aff *pwaff1,
        if (!pwaff1 || !pwaff2)
                goto error;
 
-       ctx = isl_dim_get_ctx(pwaff1->dim);
-       if (!isl_dim_equal(pwaff1->dim, pwaff2->dim))
+       ctx = isl_space_get_ctx(pwaff1->dim);
+       if (!isl_space_is_equal(pwaff1->dim, pwaff2->dim))
                isl_die(ctx, isl_error_invalid,
                        "arguments should live in same space", goto error);
 
@@ -1074,28 +1256,28 @@ __isl_give isl_pw_aff *isl_pw_aff_max(__isl_take isl_pw_aff *pwaff1,
        }
 
        n = 2 * (pwaff1->n + 1) * (pwaff2->n + 1);
-       res = isl_pw_aff_alloc_(isl_dim_copy(pwaff1->dim), n);
+       res = isl_pw_aff_alloc_size(isl_space_copy(pwaff1->dim), n);
 
        for (i = 0; i < pwaff1->n; ++i) {
                set = isl_set_copy(pwaff1->p[i].set);
                for (j = 0; j < pwaff2->n; ++j) {
                        struct isl_set *common;
-                       isl_set *ge;
+                       isl_set *better;
 
                        common = isl_set_intersect(
                                        isl_set_copy(pwaff1->p[i].set),
                                        isl_set_copy(pwaff2->p[j].set));
-                       ge = isl_set_from_basic_set(isl_aff_ge_basic_set(
+                       better = isl_set_from_basic_set(cmp(
                                        isl_aff_copy(pwaff2->p[j].aff),
                                        isl_aff_copy(pwaff1->p[i].aff)));
-                       ge = isl_set_intersect(common, ge);
-                       if (isl_set_plain_is_empty(ge)) {
-                               isl_set_free(ge);
+                       better = isl_set_intersect(common, better);
+                       if (isl_set_plain_is_empty(better)) {
+                               isl_set_free(better);
                                continue;
                        }
-                       set = isl_set_subtract(set, isl_set_copy(ge));
+                       set = isl_set_subtract(set, isl_set_copy(better));
 
-                       res = isl_pw_aff_add_piece(res, ge,
+                       res = isl_pw_aff_add_piece(res, better,
                                                isl_aff_copy(pwaff2->p[j].aff));
                }
                res = isl_pw_aff_add_piece(res, set,
@@ -1121,21 +1303,64 @@ error:
        return NULL;
 }
 
+/* Compute a piecewise quasi-affine expression with a domain that
+ * is the union of those of pwaff1 and pwaff2 and such that on each
+ * cell, the quasi-affine expression is the maximum of those of pwaff1
+ * and pwaff2.  If only one of pwaff1 or pwaff2 is defined on a given
+ * cell, then the associated expression is the defined one.
+ */
+static __isl_give isl_pw_aff *pw_aff_union_max(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2)
+{
+       return pw_aff_union_opt(pwaff1, pwaff2, &isl_aff_ge_basic_set);
+}
+
+__isl_give isl_pw_aff *isl_pw_aff_union_max(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2)
+{
+       return align_params_pw_pw_and(pwaff1, pwaff2, &pw_aff_union_max);
+}
+
+/* Compute a piecewise quasi-affine expression with a domain that
+ * is the union of those of pwaff1 and pwaff2 and such that on each
+ * cell, the quasi-affine expression is the minimum of those of pwaff1
+ * and pwaff2.  If only one of pwaff1 or pwaff2 is defined on a given
+ * cell, then the associated expression is the defined one.
+ */
+static __isl_give isl_pw_aff *pw_aff_union_min(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2)
+{
+       return pw_aff_union_opt(pwaff1, pwaff2, &isl_aff_le_basic_set);
+}
+
+__isl_give isl_pw_aff *isl_pw_aff_union_min(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2)
+{
+       return align_params_pw_pw_and(pwaff1, pwaff2, &pw_aff_union_min);
+}
+
+__isl_give isl_pw_aff *isl_pw_aff_union_opt(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2, int max)
+{
+       if (max)
+               return isl_pw_aff_union_max(pwaff1, pwaff2);
+       else
+               return isl_pw_aff_union_min(pwaff1, pwaff2);
+}
+
 /* Construct a map with as domain the domain of pwaff and
  * one-dimensional range corresponding to the affine expressions.
  */
-__isl_give isl_map *isl_map_from_pw_aff(__isl_take isl_pw_aff *pwaff)
+static __isl_give isl_map *map_from_pw_aff(__isl_take isl_pw_aff *pwaff)
 {
        int i;
-       isl_dim *dim;
+       isl_space *dim;
        isl_map *map;
 
        if (!pwaff)
                return NULL;
 
-       dim = isl_pw_aff_get_dim(pwaff);
-       dim = isl_dim_from_domain(dim);
-       dim = isl_dim_add(dim, isl_dim_out, 1);
+       dim = isl_pw_aff_get_space(pwaff);
        map = isl_map_empty(dim);
 
        for (i = 0; i < pwaff->n; ++i) {
@@ -1154,6 +1379,31 @@ __isl_give isl_map *isl_map_from_pw_aff(__isl_take isl_pw_aff *pwaff)
        return map;
 }
 
+/* Construct a map with as domain the domain of pwaff and
+ * one-dimensional range corresponding to the affine expressions.
+ */
+__isl_give isl_map *isl_map_from_pw_aff(__isl_take isl_pw_aff *pwaff)
+{
+       if (isl_space_is_set(pwaff->dim))
+               isl_die(isl_pw_aff_get_ctx(pwaff), isl_error_invalid,
+                       "space of input is not a map",
+                       return isl_pw_aff_free(pwaff));
+       return map_from_pw_aff(pwaff);
+}
+
+/* Construct a one-dimensional set with as parameter domain
+ * the domain of pwaff and the single set dimension
+ * corresponding to the affine expressions.
+ */
+__isl_give isl_set *isl_set_from_pw_aff(__isl_take isl_pw_aff *pwaff)
+{
+       if (!isl_space_is_set(pwaff->dim))
+               isl_die(isl_pw_aff_get_ctx(pwaff), isl_error_invalid,
+                       "space of input is not a set",
+                       return isl_pw_aff_free(pwaff));
+       return map_from_pw_aff(pwaff);
+}
+
 /* Return a set containing those elements in the domain
  * of pwaff where it is non-negative.
  */
@@ -1165,7 +1415,7 @@ __isl_give isl_set *isl_pw_aff_nonneg_set(__isl_take isl_pw_aff *pwaff)
        if (!pwaff)
                return NULL;
 
-       set = isl_set_empty(isl_pw_aff_get_dim(pwaff));
+       set = isl_set_empty(isl_pw_aff_get_domain_space(pwaff));
 
        for (i = 0; i < pwaff->n; ++i) {
                isl_basic_set *bset;
@@ -1193,7 +1443,7 @@ __isl_give isl_set *isl_pw_aff_zero_set(__isl_take isl_pw_aff *pwaff)
        if (!pwaff)
                return NULL;
 
-       set = isl_set_empty(isl_pw_aff_get_dim(pwaff));
+       set = isl_set_empty(isl_pw_aff_get_domain_space(pwaff));
 
        for (i = 0; i < pwaff->n; ++i) {
                isl_basic_set *bset;
@@ -1210,6 +1460,14 @@ __isl_give isl_set *isl_pw_aff_zero_set(__isl_take isl_pw_aff *pwaff)
        return set;
 }
 
+/* Return a set containing those elements in the domain
+ * of pwaff where it is not zero.
+ */
+__isl_give isl_set *isl_pw_aff_non_zero_set(__isl_take isl_pw_aff *pwaff)
+{
+       return isl_set_complement(isl_pw_aff_zero_set(pwaff));
+}
+
 /* Return a set containing those elements in the shared domain
  * of pwaff1 and pwaff2 where pwaff1 is greater than (or equal) to pwaff2.
  *
@@ -1232,9 +1490,9 @@ static __isl_give isl_set *pw_aff_gte_set(__isl_take isl_pw_aff *pwaff1,
        pwaff1 = isl_pw_aff_add(pwaff1, isl_pw_aff_neg(pwaff2));
 
        if (strict) {
-               isl_dim *dim = isl_set_get_dim(set1);
+               isl_space *dim = isl_set_get_space(set1);
                isl_aff *aff;
-               aff = isl_aff_zero(isl_local_space_from_dim(dim));
+               aff = isl_aff_zero_on_domain(isl_local_space_from_space(dim));
                aff = isl_aff_add_constant_si(aff, -1);
                pwaff1 = isl_pw_aff_add(pwaff1, isl_pw_aff_alloc(set1, aff));
        } else
@@ -1248,30 +1506,48 @@ static __isl_give isl_set *pw_aff_gte_set(__isl_take isl_pw_aff *pwaff1,
 /* Return a set containing those elements in the shared domain
  * of pwaff1 and pwaff2 where pwaff1 is equal to pwaff2.
  */
-__isl_give isl_set *isl_pw_aff_eq_set(__isl_take isl_pw_aff *pwaff1,
+static __isl_give isl_set *pw_aff_eq_set(__isl_take isl_pw_aff *pwaff1,
        __isl_take isl_pw_aff *pwaff2)
 {
        return pw_aff_gte_set(pwaff1, pwaff2, 0, 1);
 }
 
+__isl_give isl_set *isl_pw_aff_eq_set(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2)
+{
+       return align_params_pw_pw_set_and(pwaff1, pwaff2, &pw_aff_eq_set);
+}
+
 /* Return a set containing those elements in the shared domain
  * of pwaff1 and pwaff2 where pwaff1 is greater than or equal to pwaff2.
  */
-__isl_give isl_set *isl_pw_aff_ge_set(__isl_take isl_pw_aff *pwaff1,
+static __isl_give isl_set *pw_aff_ge_set(__isl_take isl_pw_aff *pwaff1,
        __isl_take isl_pw_aff *pwaff2)
 {
        return pw_aff_gte_set(pwaff1, pwaff2, 0, 0);
 }
 
+__isl_give isl_set *isl_pw_aff_ge_set(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2)
+{
+       return align_params_pw_pw_set_and(pwaff1, pwaff2, &pw_aff_ge_set);
+}
+
 /* Return a set containing those elements in the shared domain
  * of pwaff1 and pwaff2 where pwaff1 is strictly greater than pwaff2.
  */
-__isl_give isl_set *isl_pw_aff_gt_set(__isl_take isl_pw_aff *pwaff1,
+static __isl_give isl_set *pw_aff_gt_set(__isl_take isl_pw_aff *pwaff1,
        __isl_take isl_pw_aff *pwaff2)
 {
        return pw_aff_gte_set(pwaff1, pwaff2, 1, 0);
 }
 
+__isl_give isl_set *isl_pw_aff_gt_set(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2)
+{
+       return align_params_pw_pw_set_and(pwaff1, pwaff2, &pw_aff_gt_set);
+}
+
 __isl_give isl_set *isl_pw_aff_le_set(__isl_take isl_pw_aff *pwaff1,
        __isl_take isl_pw_aff *pwaff2)
 {
@@ -1284,6 +1560,111 @@ __isl_give isl_set *isl_pw_aff_lt_set(__isl_take isl_pw_aff *pwaff1,
        return isl_pw_aff_gt_set(pwaff2, pwaff1);
 }
 
+/* Return a set containing those elements in the shared domain
+ * of the elements of list1 and list2 where each element in list1
+ * has the relation specified by "fn" with each element in list2.
+ */
+static __isl_give isl_set *pw_aff_list_set(__isl_take isl_pw_aff_list *list1,
+       __isl_take isl_pw_aff_list *list2,
+       __isl_give isl_set *(*fn)(__isl_take isl_pw_aff *pwaff1,
+                                   __isl_take isl_pw_aff *pwaff2))
+{
+       int i, j;
+       isl_ctx *ctx;
+       isl_set *set;
+
+       if (!list1 || !list2)
+               goto error;
+
+       ctx = isl_pw_aff_list_get_ctx(list1);
+       if (list1->n < 1 || list2->n < 1)
+               isl_die(ctx, isl_error_invalid,
+                       "list should contain at least one element", goto error);
+
+       set = isl_set_universe(isl_pw_aff_get_domain_space(list1->p[0]));
+       for (i = 0; i < list1->n; ++i)
+               for (j = 0; j < list2->n; ++j) {
+                       isl_set *set_ij;
+
+                       set_ij = fn(isl_pw_aff_copy(list1->p[i]),
+                                   isl_pw_aff_copy(list2->p[j]));
+                       set = isl_set_intersect(set, set_ij);
+               }
+
+       isl_pw_aff_list_free(list1);
+       isl_pw_aff_list_free(list2);
+       return set;
+error:
+       isl_pw_aff_list_free(list1);
+       isl_pw_aff_list_free(list2);
+       return NULL;
+}
+
+/* Return a set containing those elements in the shared domain
+ * of the elements of list1 and list2 where each element in list1
+ * is equal to each element in list2.
+ */
+__isl_give isl_set *isl_pw_aff_list_eq_set(__isl_take isl_pw_aff_list *list1,
+       __isl_take isl_pw_aff_list *list2)
+{
+       return pw_aff_list_set(list1, list2, &isl_pw_aff_eq_set);
+}
+
+__isl_give isl_set *isl_pw_aff_list_ne_set(__isl_take isl_pw_aff_list *list1,
+       __isl_take isl_pw_aff_list *list2)
+{
+       return pw_aff_list_set(list1, list2, &isl_pw_aff_ne_set);
+}
+
+/* Return a set containing those elements in the shared domain
+ * of the elements of list1 and list2 where each element in list1
+ * is less than or equal to each element in 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)
+{
+       return pw_aff_list_set(list1, list2, &isl_pw_aff_le_set);
+}
+
+__isl_give isl_set *isl_pw_aff_list_lt_set(__isl_take isl_pw_aff_list *list1,
+       __isl_take isl_pw_aff_list *list2)
+{
+       return pw_aff_list_set(list1, list2, &isl_pw_aff_lt_set);
+}
+
+__isl_give isl_set *isl_pw_aff_list_ge_set(__isl_take isl_pw_aff_list *list1,
+       __isl_take isl_pw_aff_list *list2)
+{
+       return pw_aff_list_set(list1, list2, &isl_pw_aff_ge_set);
+}
+
+__isl_give isl_set *isl_pw_aff_list_gt_set(__isl_take isl_pw_aff_list *list1,
+       __isl_take isl_pw_aff_list *list2)
+{
+       return pw_aff_list_set(list1, list2, &isl_pw_aff_gt_set);
+}
+
+
+/* Return a set containing those elements in the shared domain
+ * of pwaff1 and pwaff2 where pwaff1 is not equal to pwaff2.
+ */
+static __isl_give isl_set *pw_aff_ne_set(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2)
+{
+       isl_set *set_lt, *set_gt;
+
+       set_lt = isl_pw_aff_lt_set(isl_pw_aff_copy(pwaff1),
+                                  isl_pw_aff_copy(pwaff2));
+       set_gt = isl_pw_aff_gt_set(pwaff1, pwaff2);
+       return isl_set_union_disjoint(set_lt, set_gt);
+}
+
+__isl_give isl_set *isl_pw_aff_ne_set(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2)
+{
+       return align_params_pw_pw_set_and(pwaff1, pwaff2, &pw_aff_ne_set);
+}
+
 __isl_give isl_pw_aff *isl_pw_aff_scale_down(__isl_take isl_pw_aff *pwaff,
        isl_int v)
 {
@@ -1363,3 +1744,177 @@ __isl_give isl_pw_aff *isl_pw_aff_cond(__isl_take isl_set *cond,
 
        return isl_pw_aff_add_disjoint(pwaff_true, pwaff_false);
 }
+
+int isl_aff_is_cst(__isl_keep isl_aff *aff)
+{
+       if (!aff)
+               return -1;
+
+       return isl_seq_first_non_zero(aff->v->el + 2, aff->v->size - 2) == -1;
+}
+
+/* Check whether pwaff is a piecewise constant.
+ */
+int isl_pw_aff_is_cst(__isl_keep isl_pw_aff *pwaff)
+{
+       int i;
+
+       if (!pwaff)
+               return -1;
+
+       for (i = 0; i < pwaff->n; ++i) {
+               int is_cst = isl_aff_is_cst(pwaff->p[i].aff);
+               if (is_cst < 0 || !is_cst)
+                       return is_cst;
+       }
+
+       return 1;
+}
+
+__isl_give isl_aff *isl_aff_mul(__isl_take isl_aff *aff1,
+       __isl_take isl_aff *aff2)
+{
+       if (!isl_aff_is_cst(aff2) && isl_aff_is_cst(aff1))
+               return isl_aff_mul(aff2, aff1);
+
+       if (!isl_aff_is_cst(aff2))
+               isl_die(isl_aff_get_ctx(aff1), isl_error_invalid,
+                       "at least one affine expression should be constant",
+                       goto error);
+
+       aff1 = isl_aff_cow(aff1);
+       if (!aff1 || !aff2)
+               goto error;
+
+       aff1 = isl_aff_scale(aff1, aff2->v->el[1]);
+       aff1 = isl_aff_scale_down(aff1, aff2->v->el[0]);
+
+       isl_aff_free(aff2);
+       return aff1;
+error:
+       isl_aff_free(aff1);
+       isl_aff_free(aff2);
+       return NULL;
+}
+
+static __isl_give isl_pw_aff *pw_aff_mul(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2)
+{
+       int i, j, n;
+       isl_pw_aff *res;
+
+       if (!pwaff1 || !pwaff2)
+               goto error;
+
+       n = pwaff1->n * pwaff2->n;
+       res = isl_pw_aff_alloc_size(isl_space_copy(pwaff1->dim), n);
+
+       for (i = 0; i < pwaff1->n; ++i) {
+               for (j = 0; j < pwaff2->n; ++j) {
+                       isl_set *common;
+                       isl_aff *prod;
+                       common = isl_set_intersect(
+                                       isl_set_copy(pwaff1->p[i].set),
+                                       isl_set_copy(pwaff2->p[j].set));
+                       if (isl_set_plain_is_empty(common)) {
+                               isl_set_free(common);
+                               continue;
+                       }
+
+                       prod = isl_aff_mul(isl_aff_copy(pwaff1->p[i].aff),
+                                           isl_aff_copy(pwaff2->p[j].aff));
+
+                       res = isl_pw_aff_add_piece(res, common, prod);
+               }
+       }
+
+       isl_pw_aff_free(pwaff1);
+       isl_pw_aff_free(pwaff2);
+       return res;
+error:
+       isl_pw_aff_free(pwaff1);
+       isl_pw_aff_free(pwaff2);
+       return NULL;
+}
+
+__isl_give isl_pw_aff *isl_pw_aff_mul(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2)
+{
+       return align_params_pw_pw_and(pwaff1, pwaff2, &pw_aff_mul);
+}
+
+static __isl_give isl_pw_aff *pw_aff_min(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2)
+{
+       isl_set *le;
+
+       le = isl_pw_aff_le_set(isl_pw_aff_copy(pwaff1),
+                               isl_pw_aff_copy(pwaff2));
+       return isl_pw_aff_cond(le, pwaff1, pwaff2);
+}
+
+__isl_give isl_pw_aff *isl_pw_aff_min(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2)
+{
+       return align_params_pw_pw_and(pwaff1, pwaff2, &pw_aff_min);
+}
+
+static __isl_give isl_pw_aff *pw_aff_max(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2)
+{
+       isl_set *le;
+
+       le = isl_pw_aff_ge_set(isl_pw_aff_copy(pwaff1),
+                               isl_pw_aff_copy(pwaff2));
+       return isl_pw_aff_cond(le, pwaff1, pwaff2);
+}
+
+__isl_give isl_pw_aff *isl_pw_aff_max(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2)
+{
+       return align_params_pw_pw_and(pwaff1, pwaff2, &pw_aff_max);
+}
+
+static __isl_give isl_pw_aff *pw_aff_list_reduce(
+       __isl_take isl_pw_aff_list *list,
+       __isl_give isl_pw_aff *(*fn)(__isl_take isl_pw_aff *pwaff1,
+                                       __isl_take isl_pw_aff *pwaff2))
+{
+       int i;
+       isl_ctx *ctx;
+       isl_pw_aff *res;
+
+       if (!list)
+               return NULL;
+
+       ctx = isl_pw_aff_list_get_ctx(list);
+       if (list->n < 1)
+               isl_die(ctx, isl_error_invalid,
+                       "list should contain at least one element",
+                       return isl_pw_aff_list_free(list));
+
+       res = isl_pw_aff_copy(list->p[0]);
+       for (i = 1; i < list->n; ++i)
+               res = fn(res, isl_pw_aff_copy(list->p[i]));
+
+       isl_pw_aff_list_free(list);
+       return res;
+}
+
+/* Return an isl_pw_aff that maps each element in the intersection of the
+ * domains of the elements of list to the minimal corresponding affine
+ * expression.
+ */
+__isl_give isl_pw_aff *isl_pw_aff_list_min(__isl_take isl_pw_aff_list *list)
+{
+       return pw_aff_list_reduce(list, &isl_pw_aff_min);
+}
+
+/* Return an isl_pw_aff that maps each element in the intersection of the
+ * domains of the elements of list to the maximal corresponding affine
+ * expression.
+ */
+__isl_give isl_pw_aff *isl_pw_aff_list_max(__isl_take isl_pw_aff_list *list)
+{
+       return pw_aff_list_reduce(list, &isl_pw_aff_max);
+}
index cd51804..54705f6 100644 (file)
@@ -6,6 +6,8 @@
 #include <isl/mat.h>
 #include <isl/local_space.h>
 
+/* ls represents the domain space.
+ */
 struct isl_aff {
        int ref;
 
@@ -21,7 +23,7 @@ struct isl_pw_aff_piece {
 struct isl_pw_aff {
        int ref;
 
-       isl_dim *dim;
+       isl_space *dim;
 
        int n;
 
@@ -31,15 +33,24 @@ struct isl_pw_aff {
 
 __isl_give isl_aff *isl_aff_alloc(__isl_take isl_local_space *ls);
 
-__isl_give isl_aff *isl_aff_reset_dim(__isl_take isl_aff *aff,
-       __isl_take isl_dim *dim);
-__isl_give isl_aff *isl_aff_realign(__isl_take isl_aff *aff,
+__isl_give isl_aff *isl_aff_reset_space_and_domain(__isl_take isl_aff *aff,
+       __isl_take isl_space *space, __isl_take isl_space *domain);
+__isl_give isl_aff *isl_aff_reset_domain_space(__isl_take isl_aff *aff,
+       __isl_take isl_space *dim);
+__isl_give isl_aff *isl_aff_realign_domain(__isl_take isl_aff *aff,
        __isl_take isl_reordering *r);
 
 __isl_give isl_aff *isl_aff_expand_divs( __isl_take isl_aff *aff,
        __isl_take isl_mat *div, int *exp);
 
+__isl_give isl_pw_aff *isl_pw_aff_reset_space(__isl_take isl_pw_aff *pwaff,
+       __isl_take isl_space *dim);
+__isl_give isl_pw_aff *isl_pw_aff_reset_domain_space(
+       __isl_take isl_pw_aff *pwaff, __isl_take isl_space *space);
 __isl_give isl_pw_aff *isl_pw_aff_add_disjoint(
        __isl_take isl_pw_aff *pwaff1, __isl_take isl_pw_aff *pwaff2);
 
+__isl_give isl_pw_aff *isl_pw_aff_union_opt(__isl_take isl_pw_aff *pwaff1,
+       __isl_take isl_pw_aff *pwaff2, int max);
+
 #endif
index ffb775b..96af313 100644 (file)
@@ -873,7 +873,7 @@ struct isl_basic_map *isl_basic_map_detect_equalities(
                isl_basic_set_free(hull);
                return isl_basic_map_set_to_empty(bmap);
        }
-       bmap = isl_basic_map_extend_dim(bmap, isl_dim_copy(bmap->dim), 0,
+       bmap = isl_basic_map_extend_space(bmap, isl_space_copy(bmap->dim), 0,
                                        hull->n_eq, 0);
        for (i = 0; i < hull->n_eq; ++i) {
                j = isl_basic_map_alloc_equality(bmap);
index e4fbf93..53582f0 100644 (file)
@@ -140,7 +140,7 @@ __isl_give isl_union_map *isl_band_get_suffix_schedule(
                int i, n;
                isl_band_list *children;
 
-               suffix = isl_union_map_empty(isl_union_map_get_dim(band->map));
+               suffix = isl_union_map_empty(isl_union_map_get_space(band->map));
                children = isl_band_get_children(band);
                n = isl_band_list_n_band(children);
                for (i = 0; i < n; ++i) {
@@ -186,17 +186,3 @@ __isl_give isl_printer *isl_printer_print_band(__isl_take isl_printer *p,
 
        return p;
 }
-
-void isl_band_dump(__isl_keep isl_band *band)
-{
-       isl_printer *printer;
-
-       if (!band)
-               return;
-
-       printer = isl_printer_to_file(isl_band_get_ctx(band), stderr);
-       printer = isl_printer_print_band(printer, band);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
index 7358b71..43045fa 100644 (file)
@@ -55,7 +55,7 @@ static int vertex_is_integral(__isl_keep isl_basic_set *vertex)
 }
 
 static __isl_give isl_qpolynomial *vertex_coordinate(
-       __isl_keep isl_basic_set *vertex, int i, __isl_take isl_dim *dim)
+       __isl_keep isl_basic_set *vertex, int i, __isl_take isl_space *dim)
 {
        unsigned nvar;
        unsigned nparam;
@@ -82,7 +82,7 @@ static __isl_give isl_qpolynomial *vertex_coordinate(
 
        return v;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_int_clear(denom);
        return NULL;
 }
@@ -150,7 +150,7 @@ static void extract_coefficients(isl_qpolynomial *poly,
                return;
 
        ctx = isl_qpolynomial_get_ctx(poly);
-       n = isl_qpolynomial_dim(poly, isl_dim_set);
+       n = isl_qpolynomial_dim(poly, isl_dim_in);
        d = isl_qpolynomial_degree(poly);
        isl_assert(ctx, n >= 2, return);
 
@@ -165,25 +165,24 @@ static void extract_coefficients(isl_qpolynomial *poly,
        for (k[0] = d; k[0] >= 0; --k[0]) {
                int i = 1;
                isl_qpolynomial_free(c[0]);
-               c[0] = isl_qpolynomial_coeff(poly, isl_dim_set, n - 1, k[0]);
+               c[0] = isl_qpolynomial_coeff(poly, isl_dim_in, n - 1, k[0]);
                left[0] = d - k[0];
                k[1] = -1;
                isl_int_set(multinom->el[1], multinom->el[0]);
                while (i > 0) {
                        if (i == n - 1) {
                                int j;
-                               isl_dim *dim;
+                               isl_space *dim;
                                isl_qpolynomial *b;
                                isl_qpolynomial *f;
                                for (j = 2; j <= left[i - 1]; ++j)
                                        isl_int_divexact_ui(multinom->el[i],
                                                multinom->el[i], j);
-                               b = isl_qpolynomial_coeff(c[i - 1], isl_dim_set,
+                               b = isl_qpolynomial_coeff(c[i - 1], isl_dim_in,
                                        n - 1 - i, left[i - 1]);
-                               b = isl_qpolynomial_drop_dims(b, isl_dim_set,
-                                                               0, n);
-                               dim = isl_qpolynomial_get_dim(b);
-                               f = isl_qpolynomial_rat_cst(dim, ctx->one,
+                               b = isl_qpolynomial_project_domain_on_params(b);
+                               dim = isl_qpolynomial_get_domain_space(b);
+                               f = isl_qpolynomial_rat_cst_on_domain(dim, ctx->one,
                                        multinom->el[i]);
                                b = isl_qpolynomial_mul(b, f);
                                k[n - 1] = left[n - 2];
@@ -200,7 +199,7 @@ static void extract_coefficients(isl_qpolynomial *poly,
                                isl_int_divexact_ui(multinom->el[i],
                                        multinom->el[i], k[i]);
                        isl_qpolynomial_free(c[i]);
-                       c[i] = isl_qpolynomial_coeff(c[i - 1], isl_dim_set,
+                       c[i] = isl_qpolynomial_coeff(c[i - 1], isl_dim_in,
                                        n - 1 - i, k[i]);
                        left[i] = left[i - 1] - k[i];
                        k[i + 1] = -1;
@@ -245,8 +244,8 @@ static int bernstein_coefficients_cell(__isl_take isl_cell *cell, void *user)
 {
        int i, j;
        struct bernstein_data *data = (struct bernstein_data *)user;
-       isl_dim *dim_param;
-       isl_dim *dim_dst;
+       isl_space *dim_param;
+       isl_space *dim_dst;
        isl_qpolynomial *poly = data->poly;
        unsigned nvar;
        int n_vertices;
@@ -258,7 +257,7 @@ static int bernstein_coefficients_cell(__isl_take isl_cell *cell, void *user)
        if (!poly)
                goto error;
 
-       nvar = isl_qpolynomial_dim(poly, isl_dim_set) - 1;
+       nvar = isl_qpolynomial_dim(poly, isl_dim_in) - 1;
        n_vertices = cell->n_vertices;
 
        ctx = isl_qpolynomial_get_ctx(poly);
@@ -270,40 +269,40 @@ static int bernstein_coefficients_cell(__isl_take isl_cell *cell, void *user)
        if (!subs)
                goto error;
 
-       dim_param = isl_basic_set_get_dim(cell->dom);
-       dim_dst = isl_qpolynomial_get_dim(poly);
-       dim_dst = isl_dim_add(dim_dst, isl_dim_set, n_vertices);
+       dim_param = isl_basic_set_get_space(cell->dom);
+       dim_dst = isl_qpolynomial_get_domain_space(poly);
+       dim_dst = isl_space_add_dims(dim_dst, isl_dim_set, n_vertices);
 
        for (i = 0; i < 1 + nvar; ++i)
-               subs[i] = isl_qpolynomial_zero(isl_dim_copy(dim_dst));
+               subs[i] = isl_qpolynomial_zero_on_domain(isl_space_copy(dim_dst));
 
        for (i = 0; i < n_vertices; ++i) {
                isl_qpolynomial *c;
-               c = isl_qpolynomial_var(isl_dim_copy(dim_dst), isl_dim_set,
+               c = isl_qpolynomial_var_on_domain(isl_space_copy(dim_dst), isl_dim_set,
                                        1 + nvar + i);
                for (j = 0; j < nvar; ++j) {
                        int k = cell->ids[i];
                        isl_qpolynomial *v;
                        v = vertex_coordinate(cell->vertices->v[k].vertex, j,
-                                               isl_dim_copy(dim_param));
-                       v = isl_qpolynomial_add_dims(v, isl_dim_set,
+                                               isl_space_copy(dim_param));
+                       v = isl_qpolynomial_add_dims(v, isl_dim_in,
                                                        1 + nvar + n_vertices);
                        v = isl_qpolynomial_mul(v, isl_qpolynomial_copy(c));
                        subs[1 + j] = isl_qpolynomial_add(subs[1 + j], v);
                }
                subs[0] = isl_qpolynomial_add(subs[0], c);
        }
-       isl_dim_free(dim_dst);
+       isl_space_free(dim_dst);
 
        poly = isl_qpolynomial_copy(poly);
 
-       poly = isl_qpolynomial_add_dims(poly, isl_dim_set, n_vertices);
-       poly = isl_qpolynomial_substitute(poly, isl_dim_set, 0, 1 + nvar, subs);
-       poly = isl_qpolynomial_drop_dims(poly, isl_dim_set, 0, 1 + nvar);
+       poly = isl_qpolynomial_add_dims(poly, isl_dim_in, n_vertices);
+       poly = isl_qpolynomial_substitute(poly, isl_dim_in, 0, 1 + nvar, subs);
+       poly = isl_qpolynomial_drop_dims(poly, isl_dim_in, 0, 1 + nvar);
 
        data->cell = cell;
        dom = isl_set_from_basic_set(isl_basic_set_copy(cell->dom));
-       data->fold = isl_qpolynomial_fold_empty(data->type, isl_dim_copy(dim_param));
+       data->fold = isl_qpolynomial_fold_empty(data->type, isl_space_copy(dim_param));
        data->fold_tight = isl_qpolynomial_fold_empty(data->type, dim_param);
        extract_coefficients(poly, dom, data);
 
@@ -335,7 +334,7 @@ static __isl_give isl_pw_qpolynomial_fold *bernstein_coefficients_base(
        __isl_take isl_qpolynomial *poly, struct bernstein_data *data, int *tight)
 {
        unsigned nvar;
-       isl_dim *dim;
+       isl_space *dim;
        isl_pw_qpolynomial_fold *pwf;
        isl_vertices *vertices;
        int covers;
@@ -344,11 +343,13 @@ static __isl_give isl_pw_qpolynomial_fold *bernstein_coefficients_base(
        if (nvar == 0) {
                isl_set *dom;
                isl_qpolynomial_fold *fold;
+
                fold = isl_qpolynomial_fold_alloc(data->type, poly);
                dom = isl_set_from_basic_set(bset);
                if (tight)
                        *tight = 1;
-               return isl_pw_qpolynomial_fold_alloc(data->type, dom, fold);
+               pwf = isl_pw_qpolynomial_fold_alloc(data->type, dom, fold);
+               return isl_pw_qpolynomial_fold_project_domain_on_params(pwf);
        }
 
        if (isl_qpolynomial_is_zero(poly)) {
@@ -359,13 +360,14 @@ static __isl_give isl_pw_qpolynomial_fold *bernstein_coefficients_base(
                pwf = isl_pw_qpolynomial_fold_alloc(data->type, dom, fold);
                if (tight)
                        *tight = 1;
-               return isl_pw_qpolynomial_fold_drop_dims(pwf,
-                                                           isl_dim_set, 0, nvar);
+               return isl_pw_qpolynomial_fold_project_domain_on_params(pwf);
        }
 
-       dim = isl_basic_set_get_dim(bset);
-       dim = isl_dim_drop(dim, isl_dim_set, 0, nvar);
-       data->pwf = isl_pw_qpolynomial_fold_zero(isl_dim_copy(dim), data->type);
+       dim = isl_basic_set_get_space(bset);
+       dim = isl_space_params(dim);
+       dim = isl_space_from_domain(dim);
+       dim = isl_space_add_dims(dim, isl_dim_set, 1);
+       data->pwf = isl_pw_qpolynomial_fold_zero(isl_space_copy(dim), data->type);
        data->pwf_tight = isl_pw_qpolynomial_fold_zero(dim, data->type);
        data->poly = isl_qpolynomial_homogenize(isl_qpolynomial_copy(poly));
        vertices = isl_basic_set_compute_vertices(bset);
@@ -414,15 +416,15 @@ static __isl_give isl_pw_qpolynomial_fold *bernstein_coefficients_recursive(
                return NULL;
 
        nparam = isl_pw_qpolynomial_dim(pwqp, isl_dim_param);
-       nvar = isl_pw_qpolynomial_dim(pwqp, isl_dim_set);
+       nvar = isl_pw_qpolynomial_dim(pwqp, isl_dim_in);
 
        pwqp = isl_pw_qpolynomial_move_dims(pwqp, isl_dim_param, nparam,
-                                       isl_dim_set, 0, nvar - len[n_group - 1]);
+                                       isl_dim_in, 0, nvar - len[n_group - 1]);
        pwf = isl_pw_qpolynomial_bound(pwqp, data->type, tight);
 
        for (i = n_group - 2; i >= 0; --i) {
                nparam = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_param);
-               pwf = isl_pw_qpolynomial_fold_move_dims(pwf, isl_dim_set, 0,
+               pwf = isl_pw_qpolynomial_fold_move_dims(pwf, isl_dim_in, 0,
                                isl_dim_param, nparam - len[i], len[i]);
                if (tight && !*tight)
                        tight = NULL;
@@ -451,7 +453,7 @@ static __isl_give isl_pw_qpolynomial_fold *bernstein_coefficients_factors(
 
        set = isl_set_from_basic_set(bset);
        pwqp = isl_pw_qpolynomial_alloc(set, poly);
-       pwqp = isl_pw_qpolynomial_morph(pwqp, isl_morph_copy(f->morph));
+       pwqp = isl_pw_qpolynomial_morph_domain(pwqp, isl_morph_copy(f->morph));
 
        pwf = bernstein_coefficients_recursive(pwqp, f->n_group, f->len, data,
                                                tight);
index 3828f8d..a2fd067 100644 (file)
@@ -53,9 +53,8 @@ static int unwrapped_guarded_poly_bound(__isl_take isl_basic_set *bset,
        struct isl_bound *bound = (struct isl_bound *)user;
        isl_pw_qpolynomial_fold *top_pwf;
        isl_pw_qpolynomial_fold *top_pwf_tight;
-       isl_dim *dim;
+       isl_space *dim;
        isl_morph *morph;
-       unsigned orig_nvar, final_nvar;
        int r;
 
        bset = isl_basic_set_detect_equalities(bset);
@@ -66,34 +65,33 @@ static int unwrapped_guarded_poly_bound(__isl_take isl_basic_set *bset,
        if (bset->n_eq == 0)
                return compressed_guarded_poly_bound(bset, poly, user);
 
-       orig_nvar = isl_basic_set_dim(bset, isl_dim_set);
-
        morph = isl_basic_set_full_compression(bset);
 
        bset = isl_morph_basic_set(isl_morph_copy(morph), bset);
-       poly = isl_qpolynomial_morph(poly, isl_morph_copy(morph));
-
-       final_nvar = isl_basic_set_dim(bset, isl_dim_set);
+       poly = isl_qpolynomial_morph_domain(poly, isl_morph_copy(morph));
 
-       dim = isl_morph_get_ran_dim(morph);
-       dim = isl_dim_drop(dim, isl_dim_set, 0, isl_dim_size(dim, isl_dim_set));
+       dim = isl_morph_get_ran_space(morph);
+       dim = isl_space_params(dim);
 
        top_pwf = bound->pwf;
        top_pwf_tight = bound->pwf_tight;
 
-       bound->pwf = isl_pw_qpolynomial_fold_zero(isl_dim_copy(dim),
+       dim = isl_space_from_domain(dim);
+       dim = isl_space_add_dims(dim, isl_dim_out, 1);
+       bound->pwf = isl_pw_qpolynomial_fold_zero(isl_space_copy(dim),
                                                  bound->type);
        bound->pwf_tight = isl_pw_qpolynomial_fold_zero(dim, bound->type);
 
        r = compressed_guarded_poly_bound(bset, poly, user);
 
-       morph = isl_morph_remove_dom_dims(morph, isl_dim_set, 0, orig_nvar);
-       morph = isl_morph_remove_ran_dims(morph, isl_dim_set, 0, final_nvar);
+       morph = isl_morph_dom_params(morph);
+       morph = isl_morph_ran_params(morph);
        morph = isl_morph_inverse(morph);
 
-       bound->pwf = isl_pw_qpolynomial_fold_morph(bound->pwf,
+       bound->pwf = isl_pw_qpolynomial_fold_morph_domain(bound->pwf,
                                                        isl_morph_copy(morph));
-       bound->pwf_tight = isl_pw_qpolynomial_fold_morph(bound->pwf_tight, morph);
+       bound->pwf_tight = isl_pw_qpolynomial_fold_morph_domain(
+                                               bound->pwf_tight, morph);
 
        bound->pwf = isl_pw_qpolynomial_fold_fold(top_pwf, bound->pwf);
        bound->pwf_tight = isl_pw_qpolynomial_fold_fold(top_pwf_tight,
@@ -110,7 +108,7 @@ static int guarded_poly_bound(__isl_take isl_basic_set *bset,
        __isl_take isl_qpolynomial *poly, void *user)
 {
        struct isl_bound *bound = (struct isl_bound *)user;
-       isl_dim *dim;
+       isl_space *dim;
        isl_pw_qpolynomial_fold *top_pwf;
        isl_pw_qpolynomial_fold *top_pwf_tight;
        int nparam;
@@ -120,30 +118,32 @@ static int guarded_poly_bound(__isl_take isl_basic_set *bset,
        if (!bound->wrapping)
                return unwrapped_guarded_poly_bound(bset, poly, user);
 
-       nparam = isl_dim_size(bound->dim, isl_dim_param);
-       n_in = isl_dim_size(bound->dim, isl_dim_set);
+       nparam = isl_space_dim(bound->dim, isl_dim_param);
+       n_in = isl_space_dim(bound->dim, isl_dim_in);
 
        bset = isl_basic_set_move_dims(bset, isl_dim_param, nparam,
                                        isl_dim_set, 0, n_in);
        poly = isl_qpolynomial_move_dims(poly, isl_dim_param, nparam,
-                                       isl_dim_set, 0, n_in);
+                                       isl_dim_in, 0, n_in);
 
-       dim = isl_basic_set_get_dim(bset);
-       dim = isl_dim_drop(dim, isl_dim_set, 0, isl_dim_size(dim, isl_dim_set));
+       dim = isl_basic_set_get_space(bset);
+       dim = isl_space_params(dim);
 
        top_pwf = bound->pwf;
        top_pwf_tight = bound->pwf_tight;
 
-       bound->pwf = isl_pw_qpolynomial_fold_zero(isl_dim_copy(dim),
+       dim = isl_space_from_domain(dim);
+       dim = isl_space_add_dims(dim, isl_dim_out, 1);
+       bound->pwf = isl_pw_qpolynomial_fold_zero(isl_space_copy(dim),
                                                  bound->type);
        bound->pwf_tight = isl_pw_qpolynomial_fold_zero(dim, bound->type);
 
        r = unwrapped_guarded_poly_bound(bset, poly, user);
 
-       bound->pwf = isl_pw_qpolynomial_fold_reset_dim(bound->pwf,
-                                                   isl_dim_copy(bound->dim));
-       bound->pwf_tight = isl_pw_qpolynomial_fold_reset_dim(bound->pwf_tight,
-                                                   isl_dim_copy(bound->dim));
+       bound->pwf = isl_pw_qpolynomial_fold_reset_space(bound->pwf,
+                                                   isl_space_copy(bound->dim));
+       bound->pwf_tight = isl_pw_qpolynomial_fold_reset_space(bound->pwf_tight,
+                                                   isl_space_copy(bound->dim));
 
        bound->pwf = isl_pw_qpolynomial_fold_fold(top_pwf, bound->pwf);
        bound->pwf_tight = isl_pw_qpolynomial_fold_fold(top_pwf_tight,
@@ -211,21 +211,20 @@ __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_bound(
        if (!pwf)
                return NULL;
 
-       bound.dim = isl_pw_qpolynomial_fold_get_dim(pwf);
-       nvar = isl_dim_size(bound.dim, isl_dim_set);
+       bound.dim = isl_pw_qpolynomial_fold_get_domain_space(pwf);
 
-       bound.wrapping = isl_dim_is_wrapping(bound.dim);
-       if (bound.wrapping) {
-               bound.dim = isl_dim_unwrap(bound.dim);
-               nvar = isl_dim_size(bound.dim, isl_dim_out);
-               bound.dim = isl_dim_domain(bound.dim);
-       } else
-               bound.dim = isl_dim_drop(bound.dim, isl_dim_set, 0, nvar);
+       bound.wrapping = isl_space_is_wrapping(bound.dim);
+       if (bound.wrapping)
+               bound.dim = isl_space_unwrap(bound.dim);
+       nvar = isl_space_dim(bound.dim, isl_dim_out);
+       bound.dim = isl_space_domain(bound.dim);
+       bound.dim = isl_space_from_domain(bound.dim);
+       bound.dim = isl_space_add_dims(bound.dim, isl_dim_out, 1);
 
        if (nvar == 0) {
                if (tight)
                        *tight = 1;
-               return isl_pw_qpolynomial_fold_reset_dim(pwf, bound.dim);
+               return isl_pw_qpolynomial_fold_reset_space(pwf, bound.dim);
        }
 
        if (isl_pw_qpolynomial_fold_is_zero(pwf)) {
@@ -236,9 +235,9 @@ __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_bound(
                return isl_pw_qpolynomial_fold_zero(bound.dim, type);
        }
 
-       bound.pwf = isl_pw_qpolynomial_fold_zero(isl_dim_copy(bound.dim),
+       bound.pwf = isl_pw_qpolynomial_fold_zero(isl_space_copy(bound.dim),
                                                        pwf->type);
-       bound.pwf_tight = isl_pw_qpolynomial_fold_zero(isl_dim_copy(bound.dim),
+       bound.pwf_tight = isl_pw_qpolynomial_fold_zero(isl_space_copy(bound.dim),
                                                        pwf->type);
        bound.check_tight = !!tight;
 
@@ -253,7 +252,7 @@ __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_bound(
        if (tight)
                *tight = covers;
 
-       isl_dim_free(bound.dim);
+       isl_space_free(bound.dim);
        isl_pw_qpolynomial_fold_free(pwf);
 
        if (covers) {
@@ -268,7 +267,7 @@ error:
        isl_pw_qpolynomial_fold_free(bound.pwf_tight);
        isl_pw_qpolynomial_fold_free(bound.pwf);
        isl_pw_qpolynomial_fold_free(pwf);
-       isl_dim_free(bound.dim);
+       isl_space_free(bound.dim);
        return NULL;
 }
 
@@ -304,7 +303,7 @@ __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)
 {
-       isl_dim *dim;
+       isl_space *dim;
        struct isl_union_bound_data data = { type, 1, NULL };
 
        if (!upwqp)
@@ -313,7 +312,7 @@ __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_bound(
        if (!tight)
                data.tight = 0;
 
-       dim = isl_union_pw_qpolynomial_get_dim(upwqp);
+       dim = isl_union_pw_qpolynomial_get_space(upwqp);
        data.res = isl_union_pw_qpolynomial_fold_zero(dim, type);
        if (isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp,
                                                    &bound_pw, &data) < 0)
index b3a40db..1a9d390 100644 (file)
@@ -8,7 +8,7 @@ struct isl_bound {
        int check_tight;
        int wrapping;
        enum isl_fold type;
-       isl_dim *dim;
+       isl_space *dim;
        isl_basic_set *bset;
        isl_qpolynomial_fold *fold;
 
index 8cb942e..b99c7b5 100644 (file)
@@ -158,7 +158,7 @@ static int fuse(struct isl_map *map, int i, int j,
        unsigned total = isl_basic_map_total_dim(map->p[i]);
        unsigned extra_rows = extra ? extra->n_row : 0;
 
-       fused = isl_basic_map_alloc_dim(isl_dim_copy(map->p[i]->dim),
+       fused = isl_basic_map_alloc_space(isl_space_copy(map->p[i]->dim),
                        map->p[i]->n_div,
                        map->p[i]->n_eq + map->p[j]->n_eq,
                        map->p[i]->n_ineq + map->p[j]->n_ineq + extra_rows);
index 7c4b778..a64a00d 100644 (file)
 
 #include <isl_map_private.h>
 #include <isl_constraint_private.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl_div_private.h>
 #include <isl/seq.h>
 #include <isl_aff_private.h>
+#include <isl_local_space_private.h>
 
 isl_ctx *isl_constraint_get_ctx(__isl_keep isl_constraint *c)
 {
-       return c ? c->ctx : NULL;
+       return c ? isl_local_space_get_ctx(c->ls) : NULL;
 }
 
 static unsigned n(struct isl_constraint *c, enum isl_dim_type type)
 {
-       return isl_basic_map_dim(c->bmap, type);
+       return isl_local_space_dim(c->ls, type);
 }
 
 static unsigned offset(struct isl_constraint *c, enum isl_dim_type type)
 {
-       struct isl_dim *dim = c->bmap->dim;
-       switch (type) {
-       case isl_dim_param:     return 1;
-       case isl_dim_in:        return 1 + dim->nparam;
-       case isl_dim_out:       return 1 + dim->nparam + dim->n_in;
-       case isl_dim_div:       return 1 + dim->nparam + dim->n_in + dim->n_out;
-       default:                return 0;
-       }
+       return isl_local_space_offset(c->ls, type);
 }
 
 static unsigned basic_map_offset(__isl_keep isl_basic_map *bmap,
                                                        enum isl_dim_type type)
 {
-       return type == isl_dim_div ? 1 + isl_dim_total(bmap->dim)
-                                  : 1 + isl_dim_offset(bmap->dim, type);
+       return type == isl_dim_div ? 1 + isl_space_dim(bmap->dim, isl_dim_all)
+                                  : 1 + isl_space_offset(bmap->dim, type);
 }
 
 static unsigned basic_set_offset(struct isl_basic_set *bset,
                                                        enum isl_dim_type type)
 {
-       struct isl_dim *dim = bset->dim;
+       isl_space *dim = bset->dim;
        switch (type) {
        case isl_dim_param:     return 1;
        case isl_dim_in:        return 1 + dim->nparam;
@@ -59,26 +53,56 @@ static unsigned basic_set_offset(struct isl_basic_set *bset,
        }
 }
 
-struct isl_constraint *isl_basic_map_constraint(struct isl_basic_map *bmap,
-       isl_int **line)
+__isl_give isl_constraint *isl_constraint_alloc(int eq,
+       __isl_take isl_local_space *ls, __isl_take isl_vec *v)
 {
-       struct isl_constraint *constraint;
+       isl_constraint *constraint;
 
-       if (!bmap || !line)
+       if (!ls || !v)
                goto error;
-       
-       constraint = isl_alloc_type(bmap->ctx, struct isl_constraint);
+
+       constraint = isl_alloc_type(isl_vec_get_ctx(v), isl_constraint);
        if (!constraint)
                goto error;
 
-       constraint->ctx = bmap->ctx;
-       isl_ctx_ref(constraint->ctx);
        constraint->ref = 1;
-       constraint->bmap = bmap;
-       constraint->line = line;
+       constraint->eq = eq;
+       constraint->ls = ls;
+       constraint->v = v;
 
        return constraint;
 error:
+       isl_local_space_free(ls);
+       isl_vec_free(v);
+       return NULL;
+}
+
+struct isl_constraint *isl_basic_map_constraint(struct isl_basic_map *bmap,
+       isl_int **line)
+{
+       int eq;
+       isl_ctx *ctx;
+       isl_vec *v;
+       isl_local_space *ls = NULL;
+       isl_constraint *constraint;
+
+       if (!bmap || !line)
+               goto error;
+
+       eq = line >= bmap->eq;
+
+       ctx = isl_basic_map_get_ctx(bmap);
+       ls = isl_basic_map_get_local_space(bmap);
+       v = isl_vec_alloc(ctx, 1 + isl_local_space_dim(ls, isl_dim_all));
+       if (!v)
+               goto error;
+       isl_seq_cpy(v->el, line[0], v->size);
+       constraint = isl_constraint_alloc(eq, ls, v);
+
+       isl_basic_map_free(bmap);
+       return constraint;
+error:
+       isl_local_space_free(ls);
        isl_basic_map_free(bmap);
        return NULL;
 }
@@ -89,14 +113,14 @@ struct isl_constraint *isl_basic_set_constraint(struct isl_basic_set *bset,
        return isl_basic_map_constraint((struct isl_basic_map *)bset, line);
 }
 
-struct isl_constraint *isl_equality_alloc(struct isl_dim *dim)
+struct isl_constraint *isl_equality_alloc(__isl_take isl_space *dim)
 {
        struct isl_basic_map *bmap;
 
        if (!dim)
                return NULL;
 
-       bmap = isl_basic_map_alloc_dim(dim, 0, 1, 0);
+       bmap = isl_basic_map_alloc_space(dim, 0, 1, 0);
        if (!bmap)
                return NULL;
 
@@ -105,14 +129,14 @@ struct isl_constraint *isl_equality_alloc(struct isl_dim *dim)
        return isl_basic_map_constraint(bmap, &bmap->eq[0]);
 }
 
-struct isl_constraint *isl_inequality_alloc(struct isl_dim *dim)
+struct isl_constraint *isl_inequality_alloc(__isl_take isl_space *dim)
 {
        struct isl_basic_map *bmap;
 
        if (!dim)
                return NULL;
 
-       bmap = isl_basic_map_alloc_dim(dim, 0, 0, 1);
+       bmap = isl_basic_map_alloc_space(dim, 0, 0, 1);
        if (!bmap)
                return NULL;
 
@@ -123,19 +147,11 @@ struct isl_constraint *isl_inequality_alloc(struct isl_dim *dim)
 
 struct isl_constraint *isl_constraint_dup(struct isl_constraint *c)
 {
-       struct isl_basic_map *bmap;
-       int i;
-       int eq;
-
        if (!c)
                return NULL;
 
-       eq = c->line < c->bmap->eq + c->bmap->n_eq;
-       i = eq ? c->line - c->bmap->eq : c->line - c->bmap->ineq;
-       bmap = isl_basic_map_copy(c->bmap);
-       if (!bmap)
-               return NULL;
-       return isl_basic_map_constraint(bmap, eq ? bmap->eq + i : bmap->ineq + i);
+       return isl_constraint_alloc(c->eq, isl_local_space_copy(c->ls),
+                                               isl_vec_copy(c->v));
 }
 
 struct isl_constraint *isl_constraint_cow(struct isl_constraint *c)
@@ -158,54 +174,18 @@ struct isl_constraint *isl_constraint_copy(struct isl_constraint *constraint)
        return constraint;
 }
 
-void isl_constraint_free(struct isl_constraint *c)
+void *isl_constraint_free(struct isl_constraint *c)
 {
        if (!c)
-               return;
+               return NULL;
 
        if (--c->ref > 0)
-               return;
-
-       isl_basic_map_free(c->bmap);
-       isl_ctx_deref(c->ctx);
-       free(c);
-}
-
-__isl_give isl_constraint *isl_basic_map_first_constraint(
-       __isl_take isl_basic_map *bmap)
-{
-       if (!bmap)
                return NULL;
 
-       if (bmap->n_eq > 0)
-               return isl_basic_map_constraint(bmap, &bmap->eq[0]);
-
-       if (bmap->n_ineq > 0)
-               return isl_basic_map_constraint(bmap, &bmap->ineq[0]);
-
-       isl_basic_map_free(bmap);
-       return NULL;
-}
-
-__isl_give isl_constraint *isl_basic_set_first_constraint(
-       __isl_take isl_basic_set *bset)
-{
-       return isl_basic_map_first_constraint((struct isl_basic_map *)bset);
-}
+       isl_local_space_free(c->ls);
+       isl_vec_free(c->v);
+       free(c);
 
-struct isl_constraint *isl_constraint_next(struct isl_constraint *c)
-{
-       c = isl_constraint_cow(c);
-       if (c->line >= c->bmap->eq) {
-               c->line++;
-               if (c->line < c->bmap->eq + c->bmap->n_eq)
-                       return c;
-               c->line = c->bmap->ineq;
-       } else
-               c->line++;
-       if (c->line < c->bmap->ineq + c->bmap->n_ineq)
-               return c;
-       isl_constraint_free(c);
        return NULL;
 }
 
@@ -251,20 +231,33 @@ int isl_basic_set_foreach_constraint(__isl_keep isl_basic_set *bset,
 int isl_constraint_is_equal(struct isl_constraint *constraint1,
        struct isl_constraint *constraint2)
 {
+       int equal;
+
        if (!constraint1 || !constraint2)
                return 0;
-       return constraint1->bmap == constraint2->bmap &&
-              constraint1->line == constraint2->line;
+       if (constraint1->eq != constraint2->eq)
+               return 0;
+       equal = isl_local_space_is_equal(constraint1->ls, constraint2->ls);
+       if (equal < 0 || !equal)
+               return equal;
+       return isl_vec_is_equal(constraint1->v, constraint2->v);
 }
 
 struct isl_basic_map *isl_basic_map_add_constraint(
        struct isl_basic_map *bmap, struct isl_constraint *constraint)
 {
+       isl_ctx *ctx;
+       isl_space *dim;
+       int equal_space;
+
        if (!bmap || !constraint)
                goto error;
 
-       isl_assert(constraint->ctx,
-               isl_dim_equal(bmap->dim, constraint->bmap->dim), goto error);
+       ctx = isl_constraint_get_ctx(constraint);
+       dim = isl_constraint_get_space(constraint);
+       equal_space = isl_space_is_equal(bmap->dim, dim);
+       isl_space_free(dim);
+       isl_assert(ctx, equal_space, goto error);
 
        bmap = isl_basic_map_intersect(bmap,
                                isl_basic_map_from_constraint(constraint));
@@ -300,40 +293,10 @@ __isl_give isl_set *isl_set_add_constraint(__isl_take isl_set *set,
        return isl_map_add_constraint(set, constraint);
 }
 
-struct isl_constraint *isl_constraint_add_div(struct isl_constraint *constraint,
-       struct isl_div *div, int *pos)
-{
-       if (!constraint || !div)
-               goto error;
-
-       isl_assert(constraint->ctx,
-           isl_dim_equal(div->bmap->dim, constraint->bmap->dim), goto error);
-       isl_assert(constraint->ctx,
-           constraint->bmap->n_eq + constraint->bmap->n_ineq == 1, goto error);
-
-       constraint->bmap = isl_basic_map_cow(constraint->bmap);
-       constraint->bmap = isl_basic_map_extend_dim(constraint->bmap,
-                               isl_dim_copy(constraint->bmap->dim), 1, 0, 0);
-       if (!constraint->bmap)
-               goto error;
-       constraint->line = &constraint->bmap->ineq[0];
-       *pos = isl_basic_map_alloc_div(constraint->bmap);
-       if (*pos < 0)
-               goto error;
-       isl_seq_cpy(constraint->bmap->div[*pos], div->line[0],
-                       1 + 1 + isl_basic_map_total_dim(constraint->bmap));
-       isl_div_free(div);
-       return constraint;
-error:
-       isl_constraint_free(constraint);
-       isl_div_free(div);
-       return NULL;
-}
-
-__isl_give isl_dim *isl_constraint_get_dim(
+__isl_give isl_space *isl_constraint_get_space(
        __isl_keep isl_constraint *constraint)
 {
-       return constraint ? isl_basic_map_get_dim(constraint->bmap) : NULL;
+       return constraint ? isl_local_space_get_space(constraint->ls) : NULL;
 }
 
 int isl_constraint_dim(struct isl_constraint *constraint,
@@ -347,33 +310,53 @@ int isl_constraint_dim(struct isl_constraint *constraint,
 int isl_constraint_involves_dims(__isl_keep isl_constraint *constraint,
        enum isl_dim_type type, unsigned first, unsigned n)
 {
+       int i;
+       isl_ctx *ctx;
+       int *active = NULL;
+       int involves = 0;
+
        if (!constraint)
                return -1;
+       if (n == 0)
+               return 0;
 
-       if (first + n > isl_basic_set_dim(constraint->bmap, type))
-               isl_die(constraint->ctx, isl_error_invalid,
-                       "index out of bounds", return -1);
+       ctx = isl_constraint_get_ctx(constraint);
+       if (first + n > isl_constraint_dim(constraint, type))
+               isl_die(ctx, isl_error_invalid,
+                       "range out of bounds", return -1);
 
-       first += isl_basic_map_offset(constraint->bmap, type);
+       active = isl_local_space_get_active(constraint->ls,
+                                           constraint->v->el + 1);
+       if (!active)
+               goto error;
 
-       if (isl_seq_first_non_zero(constraint->line[0] + first, n) >= 0)
-               return 1;
+       first += isl_local_space_offset(constraint->ls, type) - 1;
+       for (i = 0; i < n; ++i)
+               if (active[first + i]) {
+                       involves = 1;
+                       break;
+               }
 
-       return 0;
+       free(active);
+
+       return involves;
+error:
+       free(active);
+       return -1;
 }
 
 const char *isl_constraint_get_dim_name(__isl_keep isl_constraint *constraint,
        enum isl_dim_type type, unsigned pos)
 {
        return constraint ?
-           isl_basic_map_get_dim_name(constraint->bmap, type, pos) : NULL;
+           isl_local_space_get_dim_name(constraint->ls, type, pos) : NULL;
 }
 
 void isl_constraint_get_constant(struct isl_constraint *constraint, isl_int *v)
 {
        if (!constraint)
                return;
-       isl_int_set(*v, constraint->line[0][0]);
+       isl_int_set(*v, constraint->v->el[0]);
 }
 
 void isl_constraint_get_coefficient(struct isl_constraint *constraint,
@@ -382,8 +365,12 @@ void isl_constraint_get_coefficient(struct isl_constraint *constraint,
        if (!constraint)
                return;
 
-       isl_assert(constraint->ctx, pos < n(constraint, type), return);
-       isl_int_set(*v, constraint->line[0][offset(constraint, type) + pos]);
+       if (pos >= isl_local_space_dim(constraint->ls, type))
+               isl_die(constraint->v->ctx, isl_error_invalid,
+                       "position out of bounds", return);
+
+       pos += isl_local_space_offset(constraint->ls, type);
+       isl_int_set(*v, constraint->v->el[pos]);
 }
 
 struct isl_div *isl_constraint_div(struct isl_constraint *constraint, int pos)
@@ -391,79 +378,91 @@ struct isl_div *isl_constraint_div(struct isl_constraint *constraint, int pos)
        if (!constraint)
                return NULL;
 
-       isl_assert(constraint->ctx, pos < n(constraint, isl_dim_div),
-                       return NULL);
-       isl_assert(constraint->ctx,
-               !isl_int_is_zero(constraint->bmap->div[pos][0]), return NULL);
-       return isl_basic_map_div(isl_basic_map_copy(constraint->bmap), pos);
+       return isl_local_space_get_div(constraint->ls, pos);
 }
 
-void isl_constraint_set_constant(struct isl_constraint *constraint, isl_int v)
+__isl_give isl_constraint *isl_constraint_set_constant(
+       __isl_take isl_constraint *constraint, isl_int v)
 {
+       constraint = isl_constraint_cow(constraint);
        if (!constraint)
-               return;
-       isl_int_set(constraint->line[0][0], v);
+               return NULL;
+
+       constraint->v = isl_vec_cow(constraint->v);
+       if (!constraint->v)
+               return isl_constraint_free(constraint);
+
+       isl_int_set(constraint->v->el[0], v);
+       return constraint;
 }
 
-void isl_constraint_set_constant_si(__isl_keep isl_constraint *constraint,
-       int v)
+__isl_give isl_constraint *isl_constraint_set_constant_si(
+       __isl_take isl_constraint *constraint, int v)
 {
+       constraint = isl_constraint_cow(constraint);
        if (!constraint)
-               return;
-       isl_int_set_si(constraint->line[0][0], v);
+               return NULL;
+
+       constraint->v = isl_vec_cow(constraint->v);
+       if (!constraint->v)
+               return isl_constraint_free(constraint);
+
+       isl_int_set_si(constraint->v->el[0], v);
+       return constraint;
 }
 
-void isl_constraint_set_coefficient(struct isl_constraint *constraint,
+__isl_give isl_constraint *isl_constraint_set_coefficient(
+       __isl_take isl_constraint *constraint,
        enum isl_dim_type type, int pos, isl_int v)
 {
+       constraint = isl_constraint_cow(constraint);
        if (!constraint)
-               return;
+               return NULL;
 
-       isl_assert(constraint->ctx, pos < n(constraint, type), return);
-       isl_int_set(constraint->line[0][offset(constraint, type) + pos], v);
-}
+       if (pos >= isl_local_space_dim(constraint->ls, type))
+               isl_die(constraint->v->ctx, isl_error_invalid,
+                       "position out of bounds",
+                       return isl_constraint_free(constraint));
 
-void isl_constraint_set_coefficient_si(__isl_keep isl_constraint *constraint,
-       enum isl_dim_type type, int pos, int v)
-{
+       constraint = isl_constraint_cow(constraint);
        if (!constraint)
-               return;
+               return NULL;
 
-       isl_assert(constraint->ctx, pos < n(constraint, type), return);
-       isl_int_set_si(constraint->line[0][offset(constraint, type) + pos], v);
-}
+       constraint->v = isl_vec_cow(constraint->v);
+       if (!constraint->v)
+               return isl_constraint_free(constraint);
 
-void isl_constraint_clear(struct isl_constraint *constraint)
-{
-       unsigned total;
+       pos += isl_local_space_offset(constraint->ls, type);
+       isl_int_set(constraint->v->el[pos], v);
 
-       if (!constraint)
-               return;
-       total = isl_basic_map_total_dim(constraint->bmap);
-       isl_seq_clr(constraint->line[0], 1 + total);
+       return constraint;
 }
 
-/* Check whether the two basic maps have identical divs in the same order.
- */
-static int equal_divs(__isl_keep isl_basic_map *bmap1,
-       __isl_keep isl_basic_map *bmap2)
+__isl_give isl_constraint *isl_constraint_set_coefficient_si(
+       __isl_take isl_constraint *constraint,
+       enum isl_dim_type type, int pos, int v)
 {
-       int i;
-       unsigned total;
+       constraint = isl_constraint_cow(constraint);
+       if (!constraint)
+               return NULL;
 
-       if (!isl_basic_map_divs_known(bmap1))
-               return 0;
-       if (!isl_basic_map_divs_known(bmap2))
-               return 0;
-       if (bmap1->n_div != bmap2->n_div)
-               return 0;
+       if (pos >= isl_local_space_dim(constraint->ls, type))
+               isl_die(constraint->v->ctx, isl_error_invalid,
+                       "position out of bounds",
+                       return isl_constraint_free(constraint));
+
+       constraint = isl_constraint_cow(constraint);
+       if (!constraint)
+               return NULL;
 
-       total = isl_basic_map_total_dim(bmap1);
-       for (i = 0; i < bmap1->n_div; ++i)
-               if (!isl_seq_eq(bmap1->div[i], bmap2->div[i], 2 + total))
-                       return 0;
+       constraint->v = isl_vec_cow(constraint->v);
+       if (!constraint->v)
+               return isl_constraint_free(constraint);
 
-       return 1;
+       pos += isl_local_space_offset(constraint->ls, type);
+       isl_int_set_si(constraint->v->el[pos], v);
+
+       return constraint;
 }
 
 /* Drop any constraint from "bset" that is identical to "constraint".
@@ -483,15 +482,18 @@ __isl_give isl_basic_set *isl_basic_set_drop_constraint(
        unsigned n;
        isl_int **row;
        unsigned total;
+       isl_local_space *ls1;
+       int equal;
 
        if (!bset || !constraint)
                goto error;
 
-       if (!isl_dim_equal(bset->dim, constraint->bmap->dim))
-               isl_die(bset->ctx, isl_error_invalid,
-                       "spaces don't match", goto error);
-
-       if (bset != constraint->bmap && !equal_divs(bset, constraint->bmap)) {
+       ls1 = isl_basic_set_get_local_space(bset);
+       equal = isl_local_space_is_equal(ls1, constraint->ls);
+       isl_local_space_free(ls1);
+       if (equal < 0)
+               goto error;
+       if (!equal) {
                isl_constraint_free(constraint);
                return bset;
        }
@@ -504,9 +506,9 @@ __isl_give isl_basic_set *isl_basic_set_drop_constraint(
                row = bset->ineq;
        }
 
-       total = isl_basic_map_total_dim(constraint->bmap);
+       total = isl_constraint_dim(constraint, isl_dim_all);
        for (i = 0; i < n; ++i)
-               if (isl_seq_eq(row[i], constraint->line[0], 1 + total))
+               if (isl_seq_eq(row[i], constraint->v->el, 1 + total))
                        isl_seq_clr(row[i], 1 + total);
                        
        isl_constraint_free(constraint);
@@ -519,44 +521,44 @@ error:
 
 struct isl_constraint *isl_constraint_negate(struct isl_constraint *constraint)
 {
-       unsigned total;
+       isl_ctx *ctx;
 
+       constraint = isl_constraint_cow(constraint);
        if (!constraint)
                return NULL;
 
-       isl_assert(constraint->ctx, !isl_constraint_is_equality(constraint),
-                       goto error);
-       isl_assert(constraint->ctx, constraint->bmap->ref == 1, goto error);
-       total = isl_basic_map_total_dim(constraint->bmap);
-       isl_seq_neg(constraint->line[0], constraint->line[0], 1 + total);
-       isl_int_sub_ui(constraint->line[0][0], constraint->line[0][0], 1);
-       ISL_F_CLR(constraint->bmap, ISL_BASIC_MAP_NORMALIZED);
+       ctx = isl_constraint_get_ctx(constraint);
+       if (isl_constraint_is_equality(constraint))
+               isl_die(ctx, isl_error_invalid, "cannot negate equality",
+                       return isl_constraint_free(constraint));
+       constraint->v = isl_vec_neg(constraint->v);
+       constraint->v = isl_vec_cow(constraint->v);
+       if (!constraint->v)
+               return isl_constraint_free(constraint);
+       isl_int_sub_ui(constraint->v->el[0], constraint->v->el[0], 1);
        return constraint;
-error:
-       isl_constraint_free(constraint);
-       return NULL;
 }
 
 int isl_constraint_is_equality(struct isl_constraint *constraint)
 {
        if (!constraint)
                return -1;
-       return constraint->line >= constraint->bmap->eq;
+       return constraint->eq;
 }
 
 int isl_constraint_is_div_constraint(__isl_keep isl_constraint *constraint)
 {
        int i;
+       int n_div;
 
        if (!constraint)
                return -1;
        if (isl_constraint_is_equality(constraint))
                return 0;
-       for (i = 0; i < constraint->bmap->n_div; ++i) {
-               if (isl_int_is_zero(constraint->bmap->div[i][0]))
-                       continue;
-               if (isl_basic_map_is_div_constraint(constraint->bmap,
-                                       constraint->line[0], i))
+       n_div = isl_constraint_dim(constraint, isl_dim_div);
+       for (i = 0; i < n_div; ++i) {
+               if (isl_local_space_is_div_constraint(constraint->ls,
+                                                       constraint->v->el, i))
                        return 1;
        }
 
@@ -572,6 +574,7 @@ __isl_give isl_basic_map *isl_basic_map_from_constraint(
        __isl_take isl_constraint *constraint)
 {
        int k;
+       isl_local_space *ls;
        struct isl_basic_map *bmap;
        isl_int *c;
        unsigned total;
@@ -579,15 +582,8 @@ __isl_give isl_basic_map *isl_basic_map_from_constraint(
        if (!constraint)
                return NULL;
 
-       if (constraint->bmap->n_eq == 1 && constraint->bmap->n_ineq == 0) {
-               bmap = isl_basic_map_copy(constraint->bmap);
-               isl_constraint_free(constraint);
-               return bmap;
-       }
-
-       bmap = isl_basic_map_universe_like(constraint->bmap);
-       bmap = isl_basic_map_align_divs(bmap, constraint->bmap);
-       bmap = isl_basic_map_cow(bmap);
+       ls = isl_local_space_copy(constraint->ls);
+       bmap = isl_basic_map_from_local_space(ls);
        bmap = isl_basic_map_extend_constraints(bmap, 1, 1);
        if (isl_constraint_is_equality(constraint)) {
                k = isl_basic_map_alloc_equality(bmap);
@@ -602,7 +598,7 @@ __isl_give isl_basic_map *isl_basic_map_from_constraint(
                c = bmap->ineq[k];
        }
        total = isl_basic_map_total_dim(bmap);
-       isl_seq_cpy(c, constraint->line[0], 1 + total);
+       isl_seq_cpy(c, constraint->v->el, 1 + total);
        isl_constraint_free(constraint);
        if (bmap)
                ISL_F_SET(bmap, ISL_BASIC_SET_FINAL);
@@ -619,11 +615,11 @@ struct isl_basic_set *isl_basic_set_from_constraint(
        if (!constraint)
                return NULL;
 
-       isl_assert(constraint->ctx,n(constraint, isl_dim_in) == 0, goto error);
+       if (isl_constraint_dim(constraint, isl_dim_in) != 0)
+               isl_die(isl_constraint_get_ctx(constraint), isl_error_invalid,
+                       "not a set constraint",
+                       return isl_constraint_free(constraint));
        return (isl_basic_set *)isl_basic_map_from_constraint(constraint);
-error:
-       isl_constraint_free(constraint);
-       return NULL;
 }
 
 int isl_basic_map_has_defining_equality(
@@ -1062,36 +1058,34 @@ __isl_give isl_aff *isl_constraint_get_bound(
        __isl_keep isl_constraint *constraint, enum isl_dim_type type, int pos)
 {
        isl_aff *aff;
-       isl_local_space *ls;
+       isl_ctx *ctx;
 
        if (!constraint)
                return NULL;
-       if (pos >= isl_basic_set_dim(constraint->bmap, type))
-               isl_die(constraint->ctx, isl_error_invalid,
+       ctx = isl_constraint_get_ctx(constraint);
+       if (pos >= isl_constraint_dim(constraint, type))
+               isl_die(ctx, isl_error_invalid,
                        "index out of bounds", return NULL);
-       if (!isl_basic_map_may_be_set(constraint->bmap))
-               isl_die(constraint->ctx, isl_error_invalid,
+       if (isl_constraint_dim(constraint, isl_dim_in) != 0)
+               isl_die(ctx, isl_error_invalid,
                        "not a set constraint", return NULL);
 
        pos += offset(constraint, type);
-       if (isl_int_is_zero(constraint->line[0][pos]))
-               isl_die(constraint->ctx, isl_error_invalid,
+       if (isl_int_is_zero(constraint->v->el[pos]))
+               isl_die(ctx, isl_error_invalid,
                        "constraint does not define a bound on given dimension",
                        return NULL);
 
-       ls = isl_basic_set_get_local_space(constraint->bmap);
-       aff = isl_aff_alloc(ls);
+       aff = isl_aff_alloc(isl_local_space_copy(constraint->ls));
        if (!aff)
                return NULL;
 
-       if (isl_int_is_neg(constraint->line[0][pos]))
-               isl_seq_cpy(aff->v->el + 1, constraint->line[0],
-                           aff->v->size - 1);
+       if (isl_int_is_neg(constraint->v->el[pos]))
+               isl_seq_cpy(aff->v->el + 1, constraint->v->el, aff->v->size - 1);
        else
-               isl_seq_neg(aff->v->el + 1, constraint->line[0],
-                           aff->v->size - 1);
+               isl_seq_neg(aff->v->el + 1, constraint->v->el, aff->v->size - 1);
        isl_int_set_si(aff->v->el[1 + pos], 0);
-       isl_int_abs(aff->v->el[0], constraint->line[0][pos]);
+       isl_int_abs(aff->v->el[0], constraint->v->el[pos]);
 
        return aff;
 }
@@ -1110,17 +1104,15 @@ __isl_give isl_aff *isl_constraint_get_aff(
        __isl_keep isl_constraint *constraint)
 {
        isl_aff *aff;
-       isl_local_space *ls;
 
        if (!constraint)
                return NULL;
 
-       ls = isl_basic_set_get_local_space(constraint->bmap);
-       aff = isl_aff_alloc(ls);
+       aff = isl_aff_alloc(isl_local_space_copy(constraint->ls));
        if (!aff)
                return NULL;
 
-       isl_seq_cpy(aff->v->el + 1, constraint->line[0], aff->v->size - 1);
+       isl_seq_cpy(aff->v->el + 1, constraint->v->el, aff->v->size - 1);
        isl_int_set_si(aff->v->el[0], 1);
 
        return aff;
@@ -1132,12 +1124,14 @@ __isl_give isl_aff *isl_constraint_get_aff(
 __isl_give isl_constraint *isl_equality_from_aff(__isl_take isl_aff *aff)
 {
        int k;
+       isl_local_space *ls;
        isl_basic_set *bset;
 
        if (!aff)
                return NULL;
 
-       bset = isl_basic_set_from_local_space(isl_aff_get_local_space(aff));
+       ls = isl_aff_get_domain_local_space(aff);
+       bset = isl_basic_set_from_local_space(ls);
        bset = isl_basic_set_extend_constraints(bset, 1, 0);
        k = isl_basic_set_alloc_equality(bset);
        if (k < 0)
@@ -1159,12 +1153,14 @@ error:
 __isl_give isl_constraint *isl_inequality_from_aff(__isl_take isl_aff *aff)
 {
        int k;
+       isl_local_space *ls;
        isl_basic_set *bset;
 
        if (!aff)
                return NULL;
 
-       bset = isl_basic_set_from_local_space(isl_aff_get_local_space(aff));
+       ls = isl_aff_get_domain_local_space(aff);
+       bset = isl_basic_set_from_local_space(ls);
        bset = isl_basic_set_extend_constraints(bset, 0, 1);
        k = isl_basic_set_alloc_inequality(bset);
        if (k < 0)
index 8fab9d4..8314325 100644 (file)
@@ -1,14 +1,15 @@
 #ifndef ISL_CONSTRAINT_PRIVATE_H
 #define ISL_CONSTRAINT_PRIVATE_H
 
+#include <isl/aff.h>
 #include <isl/constraint.h>
 
 struct isl_constraint {
        int ref;
-       struct isl_ctx *ctx;
 
-       struct isl_basic_map    *bmap;
-       isl_int                 **line;
+       int eq;
+       isl_local_space *ls;
+       isl_vec         *v;
 };
 
 struct isl_constraint *isl_basic_set_constraint(struct isl_basic_set *bset,
index 266d9a7..20c0e2f 100644 (file)
@@ -201,24 +201,29 @@ __isl_give isl_basic_set *isl_basic_set_set_rational(
        return isl_basic_map_set_rational(bset);
 }
 
-static struct isl_set *isl_set_set_rational(struct isl_set *set)
+__isl_give isl_map *isl_map_set_rational(__isl_take isl_map *map)
 {
        int i;
 
-       set = isl_set_cow(set);
-       if (!set)
+       map = isl_map_cow(map);
+       if (!map)
                return NULL;
-       for (i = 0; i < set->n; ++i) {
-               set->p[i] = isl_basic_set_set_rational(set->p[i]);
-               if (!set->p[i])
+       for (i = 0; i < map->n; ++i) {
+               map->p[i] = isl_basic_map_set_rational(map->p[i]);
+               if (!map->p[i])
                        goto error;
        }
-       return set;
+       return map;
 error:
-       isl_set_free(set);
+       isl_map_free(map);
        return NULL;
 }
 
+__isl_give isl_set *isl_set_set_rational(__isl_take isl_set *set)
+{
+       return isl_map_set_rational(set);
+}
+
 static struct isl_basic_set *isl_basic_set_add_equality(
        struct isl_basic_set *bset, isl_int *c)
 {
@@ -642,8 +647,8 @@ static struct isl_basic_set *extend(struct isl_basic_set *hull,
                if (!facet || !hull_facet)
                        goto error;
                hull = isl_basic_set_cow(hull);
-               hull = isl_basic_set_extend_dim(hull,
-                       isl_dim_copy(hull->dim), 0, 0, facet->n_ineq);
+               hull = isl_basic_set_extend_space(hull,
+                       isl_space_copy(hull->dim), 0, 0, facet->n_ineq);
                if (!hull)
                        goto error;
                for (j = 0; j < facet->n_ineq; ++j) {
@@ -805,9 +810,9 @@ static struct isl_basic_set *convex_hull_0d(struct isl_set *set)
                return NULL;
 
        if (isl_set_is_empty(set))
-               convex_hull = isl_basic_set_empty(isl_dim_copy(set->dim));
+               convex_hull = isl_basic_set_empty(isl_space_copy(set->dim));
        else
-               convex_hull = isl_basic_set_universe(isl_dim_copy(set->dim));
+               convex_hull = isl_basic_set_universe(isl_space_copy(set->dim));
        isl_set_free(set);
        return convex_hull;
 }
@@ -956,7 +961,7 @@ static struct isl_basic_set *induced_lineality_space(
                goto error;
 
        dim = isl_basic_set_total_dim(bset1);
-       lin = isl_basic_set_alloc_dim(isl_basic_set_get_dim(bset1), 0,
+       lin = isl_basic_set_alloc_space(isl_basic_set_get_space(bset1), 0,
                                        bset1->n_eq + bset2->n_eq,
                                        bset1->n_ineq + bset2->n_ineq);
        lin = isl_basic_set_set_rational(lin);
@@ -1070,7 +1075,7 @@ error:
 static struct isl_basic_set *valid_direction_lp(
        struct isl_basic_set *bset1, struct isl_basic_set *bset2)
 {
-       struct isl_dim *dim;
+       isl_space *dim;
        struct isl_basic_set *lp;
        unsigned d;
        int n;
@@ -1081,8 +1086,8 @@ static struct isl_basic_set *valid_direction_lp(
        d = 1 + isl_basic_set_total_dim(bset1);
        n = 2 +
            2 * bset1->n_eq + bset1->n_ineq + 2 * bset2->n_eq + bset2->n_ineq;
-       dim = isl_dim_set_alloc(bset1->ctx, 0, n);
-       lp = isl_basic_set_alloc_dim(dim, 0, d, n);
+       dim = isl_space_set_alloc(bset1->ctx, 0, n);
+       lp = isl_basic_set_alloc_space(dim, 0, d, n);
        if (!lp)
                goto error;
        for (i = 0; i < n; ++i) {
@@ -1317,7 +1322,7 @@ static struct isl_basic_set *convex_hull_pair_pointed(
 
        bset1 = homogeneous_map(bset1, isl_mat_copy(T2));
        bset2 = homogeneous_map(bset2, T2);
-       set = isl_set_alloc_dim(isl_basic_set_get_dim(bset1), 2, 0);
+       set = isl_set_alloc_space(isl_basic_set_get_space(bset1), 2, 0);
        set = isl_set_add_basic_set(set, bset1);
        set = isl_set_add_basic_set(set, bset2);
        hull = uset_convex_hull(set);
@@ -1390,7 +1395,7 @@ static struct isl_basic_set *convex_hull_pair(struct isl_basic_set *bset1,
        }
        if (lin->n_eq < isl_basic_set_total_dim(lin)) {
                struct isl_set *set;
-               set = isl_set_alloc_dim(isl_basic_set_get_dim(bset1), 2, 0);
+               set = isl_set_alloc_space(isl_basic_set_get_space(bset1), 2, 0);
                set = isl_set_add_basic_set(set, bset1);
                set = isl_set_add_basic_set(set, bset2);
                return modulo_lineality(set, lin);
@@ -1420,7 +1425,7 @@ struct isl_basic_set *isl_basic_set_lineality_space(struct isl_basic_set *bset)
        isl_assert(bset->ctx, bset->n_div == 0, goto error);
        dim = isl_basic_set_total_dim(bset);
 
-       lin = isl_basic_set_alloc_dim(isl_basic_set_get_dim(bset), 0, dim, 0);
+       lin = isl_basic_set_alloc_space(isl_basic_set_get_space(bset), 0, dim, 0);
        if (!lin)
                goto error;
        for (i = 0; i < bset->n_eq; ++i) {
@@ -1462,12 +1467,12 @@ static struct isl_basic_set *uset_combined_lineality_space(struct isl_set *set)
        if (!set)
                return NULL;
        if (set->n == 0) {
-               struct isl_dim *dim = isl_set_get_dim(set);
+               isl_space *dim = isl_set_get_space(set);
                isl_set_free(set);
                return isl_basic_set_empty(dim);
        }
 
-       lin = isl_set_alloc_dim(isl_set_get_dim(set), set->n, 0);
+       lin = isl_set_alloc_space(isl_set_get_space(set), set->n, 0);
        for (i = 0; i < set->n; ++i)
                lin = isl_set_add_basic_set(lin,
                    isl_basic_set_lineality_space(isl_basic_set_copy(set->p[i])));
@@ -1665,7 +1670,7 @@ static struct isl_basic_set *common_constraints(struct isl_basic_set *hull,
        if (isl_hash_table_init(hull->ctx, table, min_constraints))
                goto error;
 
-       total = isl_dim_total(set->dim);
+       total = isl_space_dim(set->dim, isl_dim_all);
        for (i = 0; i < set->p[best]->n_ineq; ++i) {
                constraints[i].c = isl_mat_sub_alloc6(hull->ctx,
                        set->p[best]->ineq + i, 0, 1, 0, 1 + total);
@@ -1762,7 +1767,7 @@ static struct isl_basic_set *proto_hull(struct isl_set *set, int *is_hull)
                n_ineq += set->p[i]->n_eq;
                n_ineq += set->p[i]->n_ineq;
        }
-       hull = isl_basic_set_alloc_dim(isl_dim_copy(set->dim), 0, 0, n_ineq);
+       hull = isl_basic_set_alloc_space(isl_space_copy(set->dim), 0, 0, n_ineq);
        hull = isl_basic_set_set_rational(hull);
        if (!hull)
                return NULL;
@@ -1848,7 +1853,7 @@ static struct isl_basic_set *uset_convex_hull_wrap_bounded(struct isl_set *set)
                goto error;
 
        if (isl_set_n_dim(set) == 0) {
-               convex_hull = isl_basic_set_universe(isl_dim_copy(set->dim));
+               convex_hull = isl_basic_set_universe(isl_space_copy(set->dim));
                isl_set_free(set);
                convex_hull = isl_basic_set_set_rational(convex_hull);
                return convex_hull;
@@ -2274,7 +2279,7 @@ static struct isl_basic_set *uset_simple_hull(struct isl_set *set)
                n_ineq += 2 * set->p[i]->n_eq + set->p[i]->n_ineq;
        }
 
-       hull = isl_basic_set_alloc_dim(isl_dim_copy(set->dim), 0, 0, n_ineq);
+       hull = isl_basic_set_alloc_space(isl_space_copy(set->dim), 0, 0, n_ineq);
        if (!hull)
                goto error;
 
index 5b37bf5..21108bf 100644 (file)
--- a/isl_ctx.c
+++ b/isl_ctx.c
@@ -65,7 +65,7 @@ isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, void *user_opt)
        if (!ctx)
                goto error;
 
-       if (isl_hash_table_init(ctx, &ctx->name_hash, 0))
+       if (isl_hash_table_init(ctx, &ctx->id_table, 0))
                goto error;
 
        ctx->stats = isl_calloc_type(ctx, struct isl_stats);
@@ -131,7 +131,7 @@ void isl_ctx_free(struct isl_ctx *ctx)
        if (!ctx)
                return;
        isl_assert(ctx, ctx->ref == 0, return);
-       isl_hash_table_clear(&ctx->name_hash);
+       isl_hash_table_clear(&ctx->id_table);
        isl_blk_clear_cache(ctx);
        isl_int_clear(ctx->zero);
        isl_int_clear(ctx->one);
index a943b24..ff8b233 100644 (file)
@@ -20,7 +20,7 @@ struct isl_ctx {
        int                     n_cached;
        int                     n_miss;
        struct isl_blk          cache[ISL_BLK_CACHE_SIZE];
-       struct isl_hash_table   name_hash;
+       struct isl_hash_table   id_table;
 
        enum isl_error          error;
 
index b850384..914d666 100644 (file)
--- a/isl_dim.c
+++ b/isl_dim.c
-/*
- * Copyright 2008-2009 Katholieke Universiteit Leuven
- * Copyright 2010      INRIA Saclay
- *
- * Use of this software is governed by the GNU LGPLv2.1 license
- *
- * Written by Sven Verdoolaege, K.U.Leuven, Departement
- * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
- * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
- * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France 
- */
+#include <isl/dim.h>
+#include <isl/aff.h>
+#include <isl/map.h>
+#include <isl/set.h>
+#include <isl/polynomial.h>
 
-#include <stdlib.h>
-#include <isl_dim_private.h>
-#include "isl_name.h"
-#include <isl_reordering.h>
-
-isl_ctx *isl_dim_get_ctx(__isl_keep isl_dim *dim)
+isl_ctx *isl_dim_get_ctx(__isl_keep isl_space *dim)
 {
-       return dim ? dim->ctx : NULL;
+       return isl_space_get_ctx(dim);
 }
 
-struct isl_dim *isl_dim_alloc(struct isl_ctx *ctx,
-                       unsigned nparam, unsigned n_in, unsigned n_out)
+__isl_give isl_space *isl_dim_alloc(isl_ctx *ctx,
+       unsigned nparam, unsigned n_in, unsigned n_out)
 {
-       struct isl_dim *dim;
-
-       dim = isl_alloc_type(ctx, struct isl_dim);
-       if (!dim)
-               return NULL;
-
-       dim->ctx = ctx;
-       isl_ctx_ref(ctx);
-       dim->ref = 1;
-       dim->nparam = nparam;
-       dim->n_in = n_in;
-       dim->n_out = n_out;
-
-       dim->tuple_name[0] = NULL;
-       dim->tuple_name[1] = NULL;
-
-       dim->nested[0] = NULL;
-       dim->nested[1] = NULL;
-
-       dim->n_name = 0;
-       dim->names = NULL;
-
-       return dim;
+       return isl_space_alloc(ctx, nparam, n_in, n_out);
 }
-
-struct isl_dim *isl_dim_set_alloc(struct isl_ctx *ctx,
-                       unsigned nparam, unsigned dim)
+__isl_give isl_space *isl_dim_set_alloc(isl_ctx *ctx,
+       unsigned nparam, unsigned dim)
 {
-       return isl_dim_alloc(ctx, nparam, 0, dim);
+       return isl_space_set_alloc(ctx, nparam, dim);
 }
-
-static unsigned global_pos(struct isl_dim *dim,
-                                enum isl_dim_type type, unsigned pos)
+__isl_give isl_space *isl_dim_copy(__isl_keep isl_space *dim)
 {
-       struct isl_ctx *ctx = dim->ctx;
-
-       switch (type) {
-       case isl_dim_param:
-               isl_assert(ctx, pos < dim->nparam, return isl_dim_total(dim));
-               return pos;
-       case isl_dim_in:
-               isl_assert(ctx, pos < dim->n_in, return isl_dim_total(dim));
-               return pos + dim->nparam;
-       case isl_dim_out:
-               isl_assert(ctx, pos < dim->n_out, return isl_dim_total(dim));
-               return pos + dim->nparam + dim->n_in;
-       default:
-               isl_assert(ctx, 0, return isl_dim_total(dim));
-       }
-       return isl_dim_total(dim);
+       return isl_space_copy(dim);
 }
-
-/* Extend length of names array to the total number of dimensions.
- */
-static __isl_give isl_dim *extend_names(__isl_take isl_dim *dim)
+void isl_dim_free(__isl_take isl_space *dim)
 {
-       struct isl_name **names;
-       int i;
-
-       if (isl_dim_total(dim) <= dim->n_name)
-               return dim;
-
-       if (!dim->names) {
-               dim->names = isl_calloc_array(dim->ctx,
-                               struct isl_name *, isl_dim_total(dim));
-               if (!dim->names)
-                       goto error;
-       } else {
-               names = isl_realloc_array(dim->ctx, dim->names,
-                               struct isl_name *, isl_dim_total(dim));
-               if (!names)
-                       goto error;
-               dim->names = names;
-               for (i = dim->n_name; i < isl_dim_total(dim); ++i)
-                       dim->names[i] = NULL;
-       }
-
-       dim->n_name = isl_dim_total(dim);
-
-       return dim;
-error:
-       isl_dim_free(dim);
-       return NULL;
+       isl_space_free(dim);
 }
 
-static struct isl_dim *set_name(struct isl_dim *dim,
-                                enum isl_dim_type type, unsigned pos,
-                                struct isl_name *name)
+unsigned isl_dim_size(__isl_keep isl_space *dim, enum isl_dim_type type)
 {
-       struct isl_ctx *ctx = dim->ctx;
-       dim = isl_dim_cow(dim);
-
-       if (!dim)
-               goto error;
-
-       pos = global_pos(dim, type, pos);
-       if (pos == isl_dim_total(dim))
-               goto error;
-
-       if (pos >= dim->n_name) {
-               if (!name)
-                       return dim;
-               dim = extend_names(dim);
-               if (!dim)
-                       goto error;
-       }
-
-       dim->names[pos] = name;
-
-       return dim;
-error:
-       isl_name_free(ctx, name);
-       isl_dim_free(dim);
-       return NULL;
-}
-
-static struct isl_name *get_name(struct isl_dim *dim,
-                                enum isl_dim_type type, unsigned pos)
-{
-       if (!dim)
-               return NULL;
-
-       pos = global_pos(dim, type, pos);
-       if (pos == isl_dim_total(dim))
-               return NULL;
-       if (pos >= dim->n_name)
-               return NULL;
-       return dim->names[pos];
+       return isl_space_dim(dim, type);
 }
 
-static unsigned offset(struct isl_dim *dim, enum isl_dim_type type)
+__isl_give isl_space *isl_dim_set_dim_id(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
 {
-       switch (type) {
-       case isl_dim_param:     return 0;
-       case isl_dim_in:        return dim->nparam;
-       case isl_dim_out:       return dim->nparam + dim->n_in;
-       default:                return 0;
-       }
+       return isl_space_set_dim_id(dim, type, pos, id);
 }
-
-static unsigned n(struct isl_dim *dim, enum isl_dim_type type)
+int isl_dim_has_dim_id(__isl_keep isl_space *dim,
+       enum isl_dim_type type, unsigned pos)
 {
-       switch (type) {
-       case isl_dim_param:     return dim->nparam;
-       case isl_dim_in:        return dim->n_in;
-       case isl_dim_out:       return dim->n_out;
-       case isl_dim_all:       return dim->nparam + dim->n_in + dim->n_out;
-       default:                return 0;
-       }
+       return isl_space_has_dim_id(dim, type, pos);
 }
-
-unsigned isl_dim_size(struct isl_dim *dim, enum isl_dim_type type)
+__isl_give isl_id *isl_dim_get_dim_id(__isl_keep isl_space *dim,
+       enum isl_dim_type type, unsigned pos)
 {
-       if (!dim)
-               return 0;
-       return n(dim, type);
+       return isl_space_get_dim_id(dim, type, pos);
 }
 
-unsigned isl_dim_offset(__isl_keep isl_dim *dim, enum isl_dim_type type)
+int isl_dim_find_dim_by_id(__isl_keep isl_space *dim,
+       enum isl_dim_type type, __isl_keep isl_id *id)
 {
-       if (!dim)
-               return 0;
-       return offset(dim, type);
+       return isl_space_find_dim_by_id(dim, type, id);
 }
 
-static struct isl_dim *copy_names(struct isl_dim *dst,
-       enum isl_dim_type dst_type, unsigned offset, struct isl_dim *src,
-       enum isl_dim_type src_type)
+__isl_give isl_space *isl_dim_set_tuple_id(__isl_take isl_space *dim,
+       enum isl_dim_type type, __isl_take isl_id *id)
 {
-       int i;
-       struct isl_name *name;
-
-       if (!dst)
-               return NULL;
-
-       for (i = 0; i < n(src, src_type); ++i) {
-               name = get_name(src, src_type, i);
-               if (!name)
-                       continue;
-               dst = set_name(dst, dst_type, offset + i,
-                                       isl_name_copy(dst->ctx, name));
-               if (!dst)
-                       return NULL;
-       }
-       return dst;
+       return isl_space_set_tuple_id(dim, type, id);
 }
-
-struct isl_dim *isl_dim_dup(struct isl_dim *dim)
+__isl_give isl_space *isl_dim_reset_tuple_id(__isl_take isl_space *dim,
+       enum isl_dim_type type)
 {
-       struct isl_dim *dup;
-       if (!dim)
-               return NULL;
-       dup = isl_dim_alloc(dim->ctx, dim->nparam, dim->n_in, dim->n_out);
-       if (dim->tuple_name[0] &&
-           !(dup->tuple_name[0] = isl_name_copy(dim->ctx, dim->tuple_name[0])))
-               goto error;
-       if (dim->tuple_name[1] &&
-           !(dup->tuple_name[1] = isl_name_copy(dim->ctx, dim->tuple_name[1])))
-               goto error;
-       if (dim->nested[0] && !(dup->nested[0] = isl_dim_copy(dim->nested[0])))
-               goto error;
-       if (dim->nested[1] && !(dup->nested[1] = isl_dim_copy(dim->nested[1])))
-               goto error;
-       if (!dim->names)
-               return dup;
-       dup = copy_names(dup, isl_dim_param, 0, dim, isl_dim_param);
-       dup = copy_names(dup, isl_dim_in, 0, dim, isl_dim_in);
-       dup = copy_names(dup, isl_dim_out, 0, dim, isl_dim_out);
-       return dup;
-error:
-       isl_dim_free(dup);
-       return NULL;
+       return isl_space_reset_tuple_id(dim, type);
 }
-
-struct isl_dim *isl_dim_cow(struct isl_dim *dim)
+int isl_dim_has_tuple_id(__isl_keep isl_space *dim, enum isl_dim_type type)
 {
-       if (!dim)
-               return NULL;
-
-       if (dim->ref == 1)
-               return dim;
-       dim->ref--;
-       return isl_dim_dup(dim);
+       return isl_space_has_tuple_id(dim, type);
 }
-
-struct isl_dim *isl_dim_copy(struct isl_dim *dim)
+__isl_give isl_id *isl_dim_get_tuple_id(__isl_keep isl_space *dim,
+       enum isl_dim_type type)
 {
-       if (!dim)
-               return NULL;
-
-       dim->ref++;
-       return dim;
+       return isl_space_get_tuple_id(dim, type);
 }
 
-void isl_dim_free(struct isl_dim *dim)
+__isl_give isl_space *isl_dim_set_name(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned pos, __isl_keep const char *name)
 {
-       int i;
-
-       if (!dim)
-               return;
-
-       if (--dim->ref > 0)
-               return;
-
-       isl_name_free(dim->ctx, dim->tuple_name[0]);
-       isl_name_free(dim->ctx, dim->tuple_name[1]);
-
-       isl_dim_free(dim->nested[0]);
-       isl_dim_free(dim->nested[1]);
-
-       for (i = 0; i < dim->n_name; ++i)
-               isl_name_free(dim->ctx, dim->names[i]);
-       free(dim->names);
-       isl_ctx_deref(dim->ctx);
-       
-       free(dim);
+       return isl_space_set_dim_name(dim, type, pos, name);
 }
-
-static int name_ok(isl_ctx *ctx, const char *s)
+__isl_keep const char *isl_dim_get_name(__isl_keep isl_space *dim,
+       enum isl_dim_type type, unsigned pos)
 {
-       char *p;
-       long dummy;
-
-       dummy = strtol(s, &p, 0);
-       if (p != s)
-               isl_die(ctx, isl_error_invalid, "name looks like a number",
-                       return 0);
-
-       return 1;
+       return isl_space_get_dim_name(dim, type, pos);
 }
 
-__isl_give isl_dim *isl_dim_set_tuple_name(__isl_take isl_dim *dim,
+__isl_give isl_space *isl_dim_set_tuple_name(__isl_take isl_space *dim,
        enum isl_dim_type type, const char *s)
 {
-       struct isl_name *name;
-
-       dim = isl_dim_cow(dim);
-       if (!dim)
-               return NULL;
-       if (type != isl_dim_in && type != isl_dim_out)
-               isl_die(dim->ctx, isl_error_invalid,
-                       "only input, output and set tuples can have names",
-                       goto error);
-       if (!s) {
-               name = NULL;
-       } else {
-               if (!name_ok(dim->ctx, s))
-                       goto error;
-               name = isl_name_get(dim->ctx, s);
-               if (!name)
-                       goto error;
-       }
-
-       isl_name_free(dim->ctx, dim->tuple_name[type - isl_dim_in]);
-       dim->tuple_name[type - isl_dim_in] = name;
-
-       return dim;
-error:
-       isl_dim_free(dim);
-       return NULL;
-}
-
-const char *isl_dim_get_tuple_name(__isl_keep isl_dim *dim,
-        enum isl_dim_type type)
-{
-       struct isl_name *name;
-       if (!dim)
-               return NULL;
-       if (type != isl_dim_in && type != isl_dim_out)
-               return NULL;
-       name = dim->tuple_name[type - isl_dim_in];
-       return name ? name->name : NULL;
-}
-
-struct isl_dim *isl_dim_set_name(struct isl_dim *dim,
-                                enum isl_dim_type type, unsigned pos,
-                                const char *s)
-{
-       struct isl_name *name;
-
-       if (!dim)
-               return NULL;
-       if (!name_ok(dim->ctx, s))
-               goto error;
-       isl_name_free(dim->ctx, get_name(dim, type, pos));
-       name = isl_name_get(dim->ctx, s);
-       if (!name)
-               goto error;
-       return set_name(dim, type, pos, name);
-error:
-       isl_dim_free(dim);
-       return NULL;
+       return isl_space_set_tuple_name(dim, type, s);
 }
-
-const char *isl_dim_get_name(struct isl_dim *dim,
-                                enum isl_dim_type type, unsigned pos)
-{
-       struct isl_name *name = get_name(dim, type, pos);
-       return name ? name->name : NULL;
-}
-
-static struct isl_name *tuple_name(__isl_keep isl_dim *dim,
+const char *isl_dim_get_tuple_name(__isl_keep isl_space *dim,
        enum isl_dim_type type)
 {
-       if (!dim)
-               return NULL;
-       if (type == isl_dim_in)
-               return dim->tuple_name[0];
-       if (type == isl_dim_out)
-               return dim->tuple_name[1];
-       return NULL;
-}
-
-static __isl_keep isl_dim *nested(__isl_keep isl_dim *dim,
-       enum isl_dim_type type)
-{
-       if (!dim)
-               return NULL;
-       if (type == isl_dim_in)
-               return dim->nested[0];
-       if (type == isl_dim_out)
-               return dim->nested[1];
-       return NULL;
-}
-
-int isl_dim_tuple_match(__isl_keep isl_dim *dim1, enum isl_dim_type dim1_type,
-                       __isl_keep isl_dim *dim2, enum isl_dim_type dim2_type)
-{
-       struct isl_name *name1, *name2;
-       isl_dim *nested1, *nested2;
-
-       if (!dim1 || !dim2)
-               return -1;
-
-       if (n(dim1, dim1_type) != n(dim2, dim2_type))
-               return 0;
-       name1 = tuple_name(dim1, dim1_type);
-       name2 = tuple_name(dim2, dim2_type);
-       if (!name1 ^ !name2)
-               return 0;
-       if (name1 && name1->name != name2->name)
-               return 0;
-       nested1 = nested(dim1, dim1_type);
-       nested2 = nested(dim2, dim2_type);
-       if (!nested1 ^ !nested2)
-               return 0;
-       if (nested1 && !isl_dim_equal(nested1, nested2))
-               return 0;
-       return 1;
-}
-
-static int match(struct isl_dim *dim1, enum isl_dim_type dim1_type,
-               struct isl_dim *dim2, enum isl_dim_type dim2_type)
-{
-       int i;
-
-       if (!isl_dim_tuple_match(dim1, dim1_type, dim2, dim2_type))
-               return 0;
-
-       if (!dim1->names && !dim2->names)
-               return 1;
-
-       for (i = 0; i < n(dim1, dim1_type); ++i) {
-               if (get_name(dim1, dim1_type, i) !=
-                   get_name(dim2, dim2_type, i))
-                       return 0;
-       }
-       return 1;
-}
-
-int isl_dim_match(struct isl_dim *dim1, enum isl_dim_type dim1_type,
-               struct isl_dim *dim2, enum isl_dim_type dim2_type)
-{
-       return match(dim1, dim1_type, dim2, dim2_type);
-}
-
-static void get_names(struct isl_dim *dim, enum isl_dim_type type,
-       unsigned first, unsigned n, struct isl_name **names)
-{
-       int i;
-
-       for (i = 0; i < n ; ++i)
-               names[i] = get_name(dim, type, first+i);
-}
-
-struct isl_dim *isl_dim_extend(struct isl_dim *dim,
-                       unsigned nparam, unsigned n_in, unsigned n_out)
-{
-       struct isl_name **names = NULL;
-
-       if (!dim)
-               return NULL;
-       if (dim->nparam == nparam && dim->n_in == n_in && dim->n_out == n_out)
-               return dim;
-
-       isl_assert(dim->ctx, dim->nparam <= nparam, goto error);
-       isl_assert(dim->ctx, dim->n_in <= n_in, goto error);
-       isl_assert(dim->ctx, dim->n_out <= n_out, goto error);
-
-       dim = isl_dim_cow(dim);
-
-       if (dim->names) {
-               names = isl_calloc_array(dim->ctx, struct isl_name *,
-                                        nparam + n_in + n_out);
-               if (!names)
-                       goto error;
-               get_names(dim, isl_dim_param, 0, dim->nparam, names);
-               get_names(dim, isl_dim_in, 0, dim->n_in, names + nparam);
-               get_names(dim, isl_dim_out, 0, dim->n_out,
-                               names + nparam + n_in);
-               free(dim->names);
-               dim->names = names;
-               dim->n_name = nparam + n_in + n_out;
-       }
-       dim->nparam = nparam;
-       dim->n_in = n_in;
-       dim->n_out = n_out;
-
-       return dim;
-error:
-       free(names);
-       isl_dim_free(dim);
-       return NULL;
-}
-
-struct isl_dim *isl_dim_add(struct isl_dim *dim, enum isl_dim_type type,
-       unsigned n)
-{
-       if (!dim)
-               return NULL;
-       dim = isl_dim_reset(dim, type);
-       switch (type) {
-       case isl_dim_param:
-               dim = isl_dim_extend(dim,
-                                       dim->nparam + n, dim->n_in, dim->n_out);
-               if (dim && dim->nested[0] &&
-                   !(dim->nested[0] = isl_dim_add(dim->nested[0],
-                                                   isl_dim_param, n)))
-                       goto error;
-               if (dim && dim->nested[1] &&
-                   !(dim->nested[1] = isl_dim_add(dim->nested[1],
-                                                   isl_dim_param, n)))
-                       goto error;
-               return dim;
-       case isl_dim_in:
-               return isl_dim_extend(dim,
-                                       dim->nparam, dim->n_in + n, dim->n_out);
-       case isl_dim_out:
-               return isl_dim_extend(dim,
-                                       dim->nparam, dim->n_in, dim->n_out + n);
-       default:
-               isl_die(dim->ctx, isl_error_invalid,
-                       "cannot add dimensions of specified type", goto error);
-       }
-error:
-       isl_dim_free(dim);
-       return NULL;
-}
-
-static int valid_dim_type(enum isl_dim_type type)
-{
-       switch (type) {
-       case isl_dim_param:
-       case isl_dim_in:
-       case isl_dim_out:
-               return 1;
-       default:
-               return 0;
-       }
-}
-
-__isl_give isl_dim *isl_dim_insert(__isl_take isl_dim *dim,
-       enum isl_dim_type type, unsigned pos, unsigned n)
-{
-       struct isl_name **names = NULL;
-
-       if (!dim)
-               return NULL;
-       if (n == 0)
-               return isl_dim_reset(dim, type);
-
-       if (!valid_dim_type(type))
-               isl_die(dim->ctx, isl_error_invalid,
-                       "cannot insert dimensions of specified type",
-                       goto error);
-
-       isl_assert(dim->ctx, pos <= isl_dim_size(dim, type), goto error);
-
-       dim = isl_dim_cow(dim);
-       if (!dim)
-               return NULL;
-
-       if (dim->names) {
-               enum isl_dim_type t;
-               int off;
-               int s[3];
-               int *size = s - isl_dim_param;
-               names = isl_calloc_array(dim->ctx, struct isl_name *,
-                                    dim->nparam + dim->n_in + dim->n_out + n);
-               if (!names)
-                       goto error;
-               off = 0;
-               size[isl_dim_param] = dim->nparam;
-               size[isl_dim_in] = dim->n_in;
-               size[isl_dim_out] = dim->n_out;
-               for (t = isl_dim_param; t <= isl_dim_out; ++t) {
-                       if (t != type) {
-                               get_names(dim, t, 0, size[t], names + off);
-                               off += size[t];
-                       } else {
-                               get_names(dim, t, 0, pos, names + off);
-                               off += pos + n;
-                               get_names(dim, t, pos, size[t]-pos, names+off);
-                               off += size[t] - pos;
-                       }
-               }
-               free(dim->names);
-               dim->names = names;
-               dim->n_name = dim->nparam + dim->n_in + dim->n_out + n;
-       }
-       switch (type) {
-       case isl_dim_param:     dim->nparam += n; break;
-       case isl_dim_in:        dim->n_in += n; break;
-       case isl_dim_out:       dim->n_out += n; break;
-       default:                ;
-       }
-       dim = isl_dim_reset(dim, type);
-
-       return dim;
-error:
-       isl_dim_free(dim);
-       return NULL;
-}
-
-__isl_give isl_dim *isl_dim_move(__isl_take isl_dim *dim,
-       enum isl_dim_type dst_type, unsigned dst_pos,
-       enum isl_dim_type src_type, unsigned src_pos, unsigned n)
-{
-       int i;
-
-       if (!dim)
-               return NULL;
-       if (n == 0)
-               return dim;
-
-       isl_assert(dim->ctx, src_pos + n <= isl_dim_size(dim, src_type),
-               goto error);
-
-       if (dst_type == src_type && dst_pos == src_pos)
-               return dim;
-
-       isl_assert(dim->ctx, dst_type != src_type, goto error);
-
-       dim = isl_dim_reset(dim, src_type);
-       dim = isl_dim_reset(dim, dst_type);
-
-       dim = isl_dim_cow(dim);
-       if (!dim)
-               return NULL;
-
-       if (dim->names) {
-               struct isl_name **names;
-               enum isl_dim_type t;
-               int off;
-               int s[3];
-               int *size = s - isl_dim_param;
-               names = isl_calloc_array(dim->ctx, struct isl_name *,
-                                        dim->nparam + dim->n_in + dim->n_out);
-               if (!names)
-                       goto error;
-               off = 0;
-               size[isl_dim_param] = dim->nparam;
-               size[isl_dim_in] = dim->n_in;
-               size[isl_dim_out] = dim->n_out;
-               for (t = isl_dim_param; t <= isl_dim_out; ++t) {
-                       if (t == dst_type) {
-                               get_names(dim, t, 0, dst_pos, names + off);
-                               off += dst_pos;
-                               get_names(dim, src_type, src_pos, n, names+off);
-                               off += n;
-                               get_names(dim, t, dst_pos, size[t] - dst_pos,
-                                               names + off);
-                               off += size[t] - dst_pos;
-                       } else if (t == src_type) {
-                               get_names(dim, t, 0, src_pos, names + off);
-                               off += src_pos;
-                               get_names(dim, t, src_pos + n,
-                                           size[t] - src_pos - n, names + off);
-                               off += size[t] - src_pos - n;
-                       } else {
-                               get_names(dim, t, 0, size[t], names + off);
-                               off += size[t];
-                       }
-               }
-               free(dim->names);
-               dim->names = names;
-               dim->n_name = dim->nparam + dim->n_in + dim->n_out;
-       }
-
-       switch (dst_type) {
-       case isl_dim_param:     dim->nparam += n; break;
-       case isl_dim_in:        dim->n_in += n; break;
-       case isl_dim_out:       dim->n_out += n; break;
-       default:                ;
-       }
-
-       switch (src_type) {
-       case isl_dim_param:     dim->nparam -= n; break;
-       case isl_dim_in:        dim->n_in -= n; break;
-       case isl_dim_out:       dim->n_out -= n; break;
-       default:                ;
-       }
-
-       if (dst_type != isl_dim_param && src_type != isl_dim_param)
-               return dim;
-
-       for (i = 0; i < 2; ++i) {
-               if (!dim->nested[i])
-                       continue;
-               dim->nested[i] = isl_dim_replace(dim->nested[i],
-                                                isl_dim_param, dim);
-               if (!dim->nested[i])
-                       goto error;
-       }
-
-       return dim;
-error:
-       isl_dim_free(dim);
-       return NULL;
+       return isl_space_get_tuple_name(dim, type);
 }
 
-struct isl_dim *isl_dim_join(struct isl_dim *left, struct isl_dim *right)
+int isl_dim_is_wrapping(__isl_keep isl_space *dim)
 {
-       struct isl_dim *dim;
-
-       if (!left || !right)
-               goto error;
-
-       isl_assert(left->ctx, match(left, isl_dim_param, right, isl_dim_param),
-                       goto error);
-       isl_assert(left->ctx,
-               isl_dim_tuple_match(left, isl_dim_out, right, isl_dim_in),
-               goto error);
-
-       dim = isl_dim_alloc(left->ctx, left->nparam, left->n_in, right->n_out);
-       if (!dim)
-               goto error;
-
-       dim = copy_names(dim, isl_dim_param, 0, left, isl_dim_param);
-       dim = copy_names(dim, isl_dim_in, 0, left, isl_dim_in);
-       dim = copy_names(dim, isl_dim_out, 0, right, isl_dim_out);
-
-       if (dim && left->tuple_name[0] &&
-           !(dim->tuple_name[0] = isl_name_copy(dim->ctx, left->tuple_name[0])))
-               goto error;
-       if (dim && right->tuple_name[1] &&
-           !(dim->tuple_name[1] = isl_name_copy(dim->ctx, right->tuple_name[1])))
-               goto error;
-       if (dim && left->nested[0] &&
-           !(dim->nested[0] = isl_dim_copy(left->nested[0])))
-               goto error;
-       if (dim && right->nested[1] &&
-           !(dim->nested[1] = isl_dim_copy(right->nested[1])))
-               goto error;
-
-       isl_dim_free(left);
-       isl_dim_free(right);
-
-       return dim;
-error:
-       isl_dim_free(left);
-       isl_dim_free(right);
-       return NULL;
+       return isl_space_is_wrapping(dim);
 }
-
-struct isl_dim *isl_dim_product(struct isl_dim *left, struct isl_dim *right)
+__isl_give isl_space *isl_dim_wrap(__isl_take isl_space *dim)
 {
-       isl_dim *dom1, *dom2, *nest1, *nest2;
-
-       if (!left || !right)
-               goto error;
-
-       isl_assert(left->ctx, match(left, isl_dim_param, right, isl_dim_param),
-                       goto error);
-
-       dom1 = isl_dim_domain(isl_dim_copy(left));
-       dom2 = isl_dim_domain(isl_dim_copy(right));
-       nest1 = isl_dim_wrap(isl_dim_join(isl_dim_reverse(dom1), dom2));
-
-       dom1 = isl_dim_range(left);
-       dom2 = isl_dim_range(right);
-       nest2 = isl_dim_wrap(isl_dim_join(isl_dim_reverse(dom1), dom2));
-
-       return isl_dim_join(isl_dim_reverse(nest1), nest2);
-error:
-       isl_dim_free(left);
-       isl_dim_free(right);
-       return NULL;
+       return isl_space_wrap(dim);
 }
-
-__isl_give isl_dim *isl_dim_range_product(__isl_take isl_dim *left,
-       __isl_take isl_dim *right)
+__isl_give isl_space *isl_dim_unwrap(__isl_take isl_space *dim)
 {
-       isl_dim *dom, *ran1, *ran2, *nest;
-
-       if (!left || !right)
-               goto error;
-
-       isl_assert(left->ctx, match(left, isl_dim_param, right, isl_dim_param),
-                       goto error);
-       if (!isl_dim_tuple_match(left, isl_dim_in, right, isl_dim_in))
-               isl_die(left->ctx, isl_error_invalid,
-                       "domains need to match", goto error);
-
-       dom = isl_dim_domain(isl_dim_copy(left));
-
-       ran1 = isl_dim_range(left);
-       ran2 = isl_dim_range(right);
-       nest = isl_dim_wrap(isl_dim_join(isl_dim_reverse(ran1), ran2));
-
-       return isl_dim_join(isl_dim_reverse(dom), nest);
-error:
-       isl_dim_free(left);
-       isl_dim_free(right);
-       return NULL;
+       return isl_space_unwrap(dim);
 }
 
-__isl_give isl_dim *isl_dim_map_from_set(__isl_take isl_dim *dim)
+__isl_give isl_space *isl_dim_domain(__isl_take isl_space *dim)
 {
-       struct isl_name **names = NULL;
-
-       if (!dim)
-               return NULL;
-       isl_assert(dim->ctx, dim->n_in == 0, goto error);
-       if (dim->n_out == 0 && !isl_dim_is_named_or_nested(dim, isl_dim_out))
-               return dim;
-       dim = isl_dim_cow(dim);
-       if (!dim)
-               return NULL;
-       if (dim->names) {
-               names = isl_calloc_array(dim->ctx, struct isl_name *,
-                                       dim->nparam + dim->n_out + dim->n_out);
-               if (!names)
-                       goto error;
-               get_names(dim, isl_dim_param, 0, dim->nparam, names);
-               get_names(dim, isl_dim_out, 0, dim->n_out, names + dim->nparam);
-       }
-       dim->n_in = dim->n_out;
-       if (names) {
-               free(dim->names);
-               dim->names = names;
-               dim->n_name = dim->nparam + dim->n_out + dim->n_out;
-               dim = copy_names(dim, isl_dim_out, 0, dim, isl_dim_in);
-       }
-       isl_name_free(dim->ctx, dim->tuple_name[0]);
-       dim->tuple_name[0] = isl_name_copy(dim->ctx, dim->tuple_name[1]);
-       isl_dim_free(dim->nested[0]);
-       dim->nested[0] = isl_dim_copy(dim->nested[1]);
-       return dim;
-error:
-       isl_dim_free(dim);
-       return NULL;
+       return isl_space_domain(dim);
 }
-
-static struct isl_dim *set_names(struct isl_dim *dim, enum isl_dim_type type,
-       unsigned first, unsigned n, struct isl_name **names)
+__isl_give isl_space *isl_dim_from_domain(__isl_take isl_space *dim)
 {
-       int i;
-
-       for (i = 0; i < n ; ++i)
-               dim = set_name(dim, type, first+i, names[i]);
-
-       return dim;
+       return isl_space_from_domain(dim);
 }
-
-struct isl_dim *isl_dim_reverse(struct isl_dim *dim)
+__isl_give isl_space *isl_dim_range(__isl_take isl_space *dim)
 {
-       unsigned t;
-       isl_dim *nested;
-       struct isl_name **names = NULL;
-       struct isl_name *name;
-
-       if (!dim)
-               return NULL;
-       if (match(dim, isl_dim_in, dim, isl_dim_out))
-               return dim;
-
-       dim = isl_dim_cow(dim);
-       if (!dim)
-               return NULL;
-
-       name = dim->tuple_name[0];
-       dim->tuple_name[0] = dim->tuple_name[1];
-       dim->tuple_name[1] = name;
-
-       nested = dim->nested[0];
-       dim->nested[0] = dim->nested[1];
-       dim->nested[1] = nested;
-
-       if (dim->names) {
-               names = isl_alloc_array(dim->ctx, struct isl_name *,
-                                       dim->n_in + dim->n_out);
-               if (!names)
-                       goto error;
-               get_names(dim, isl_dim_in, 0, dim->n_in, names);
-               get_names(dim, isl_dim_out, 0, dim->n_out, names + dim->n_in);
-       }
-
-       t = dim->n_in;
-       dim->n_in = dim->n_out;
-       dim->n_out = t;
-
-       if (dim->names) {
-               dim = set_names(dim, isl_dim_out, 0, dim->n_out, names);
-               dim = set_names(dim, isl_dim_in, 0, dim->n_in, names + dim->n_out);
-               free(names);
-       }
-
-       return dim;
-error:
-       free(names);
-       isl_dim_free(dim);
-       return NULL;
+       return isl_space_range(dim);
 }
-
-struct isl_dim *isl_dim_drop(struct isl_dim *dim, enum isl_dim_type type,
-               unsigned first, unsigned num)
+__isl_give isl_space *isl_dim_from_range(__isl_take isl_space *dim)
 {
-       int i;
-
-       if (!dim)
-               return NULL;
-
-       if (num == 0)
-               return isl_dim_reset(dim, type);
-
-       if (!valid_dim_type(type))
-               isl_die(dim->ctx, isl_error_invalid,
-                       "cannot drop dimensions of specified type", goto error);
-
-       isl_assert(dim->ctx, first + num <= n(dim, type), goto error);
-       dim = isl_dim_cow(dim);
-       if (!dim)
-               goto error;
-       if (dim->names) {
-               dim = extend_names(dim);
-               if (!dim)
-                       goto error;
-               for (i = 0; i < num; ++i)
-                       isl_name_free(dim->ctx, get_name(dim, type, first+i));
-               for (i = first+num; i < n(dim, type); ++i)
-                       set_name(dim, type, i - num, get_name(dim, type, i));
-               switch (type) {
-               case isl_dim_param:
-                       get_names(dim, isl_dim_in, 0, dim->n_in,
-                               dim->names + offset(dim, isl_dim_in) - num);
-               case isl_dim_in:
-                       get_names(dim, isl_dim_out, 0, dim->n_out,
-                               dim->names + offset(dim, isl_dim_out) - num);
-               default:
-                       ;
-               }
-               dim->n_name -= num;
-       }
-       switch (type) {
-       case isl_dim_param:     dim->nparam -= num; break;
-       case isl_dim_in:        dim->n_in -= num; break;
-       case isl_dim_out:       dim->n_out -= num; break;
-       default:                ;
-       }
-       dim = isl_dim_reset(dim, type);
-       if (type == isl_dim_param) {
-               if (dim && dim->nested[0] &&
-                   !(dim->nested[0] = isl_dim_drop(dim->nested[0],
-                                                   isl_dim_param, first, num)))
-                       goto error;
-               if (dim && dim->nested[1] &&
-                   !(dim->nested[1] = isl_dim_drop(dim->nested[1],
-                                                   isl_dim_param, first, num)))
-                       goto error;
-       }
-       return dim;
-error:
-       isl_dim_free(dim);
-       return NULL;
+       return isl_space_from_range(dim);
 }
-
-struct isl_dim *isl_dim_drop_inputs(struct isl_dim *dim,
-               unsigned first, unsigned n)
+__isl_give isl_space *isl_dim_reverse(__isl_take isl_space *dim)
 {
-       if (!dim)
-               return NULL;
-       return isl_dim_drop(dim, isl_dim_in, first, n);
+       return isl_space_reverse(dim);
 }
-
-struct isl_dim *isl_dim_drop_outputs(struct isl_dim *dim,
-               unsigned first, unsigned n)
+__isl_give isl_space *isl_dim_join(__isl_take isl_space *left,
+       __isl_take isl_space *right)
 {
-       if (!dim)
-               return NULL;
-       return isl_dim_drop(dim, isl_dim_out, first, n);
+       return isl_space_join(left, right);
 }
-
-struct isl_dim *isl_dim_domain(struct isl_dim *dim)
+__isl_give isl_space *isl_dim_align_params(__isl_take isl_space *dim1,
+       __isl_take isl_space *dim2)
 {
-       if (!dim)
-               return NULL;
-       dim = isl_dim_drop_outputs(dim, 0, dim->n_out);
-       return isl_dim_reverse(dim);
+       return isl_space_align_params(dim1, dim2);
 }
-
-__isl_give isl_dim *isl_dim_from_domain(__isl_take isl_dim *dim)
+__isl_give isl_space *isl_dim_insert(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned pos, unsigned n)
 {
-       return isl_dim_reverse(dim);
+       return isl_space_insert_dims(dim, type, pos, n);
 }
-
-struct isl_dim *isl_dim_range(struct isl_dim *dim)
+__isl_give isl_space *isl_dim_add(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned n)
 {
-       if (!dim)
-               return NULL;
-       return isl_dim_drop_inputs(dim, 0, dim->n_in);
+       return isl_space_add_dims(dim, type, n);
 }
-
-__isl_give isl_dim *isl_dim_from_range(__isl_take isl_dim *dim)
+__isl_give isl_space *isl_dim_drop(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned first, unsigned n)
 {
-       return dim;
+       return isl_space_drop_dims(dim, type, first, n);
 }
-
-__isl_give isl_dim *isl_dim_as_set_dim(__isl_take isl_dim *dim)
+__isl_give isl_space *isl_dim_move(__isl_take isl_space *dim,
+       enum isl_dim_type dst_type, unsigned dst_pos,
+       enum isl_dim_type src_type, unsigned src_pos, unsigned n)
 {
-       dim = isl_dim_cow(dim);
-       if (!dim)
-               return NULL;
-
-       dim->n_out += dim->n_in;
-       dim->n_in = 0;
-       dim = isl_dim_reset(dim, isl_dim_in);
-       dim = isl_dim_reset(dim, isl_dim_out);
-
-       return dim;
+       return isl_space_move_dims(dim, dst_type, dst_pos, src_type, src_pos, n);
 }
-
-struct isl_dim *isl_dim_underlying(struct isl_dim *dim, unsigned n_div)
+__isl_give isl_space *isl_dim_map_from_set(__isl_take isl_space *dim)
 {
-       int i;
-
-       if (!dim)
-               return NULL;
-       if (n_div == 0 &&
-           dim->nparam == 0 && dim->n_in == 0 && dim->n_name == 0)
-               return isl_dim_reset(isl_dim_reset(dim, isl_dim_in), isl_dim_out);
-       dim = isl_dim_cow(dim);
-       if (!dim)
-               return NULL;
-       dim->n_out += dim->nparam + dim->n_in + n_div;
-       dim->nparam = 0;
-       dim->n_in = 0;
-
-       for (i = 0; i < dim->n_name; ++i)
-               isl_name_free(dim->ctx, get_name(dim, isl_dim_out, i));
-       dim->n_name = 0;
-       dim = isl_dim_reset(dim, isl_dim_in);
-       dim = isl_dim_reset(dim, isl_dim_out);
-
-       return dim;
+       return isl_space_map_from_set(dim);
 }
-
-unsigned isl_dim_total(struct isl_dim *dim)
+__isl_give isl_space *isl_dim_zip(__isl_take isl_space *dim)
 {
-       return dim ? dim->nparam + dim->n_in + dim->n_out : 0;
+       return isl_space_zip(dim);
 }
 
-int isl_dim_equal(struct isl_dim *dim1, struct isl_dim *dim2)
+__isl_give isl_local_space *isl_local_space_from_dim(
+       __isl_take isl_space *dim)
 {
-       if (!dim1 || !dim2)
-               return -1;
-       return match(dim1, isl_dim_param, dim2, isl_dim_param) &&
-              isl_dim_tuple_match(dim1, isl_dim_in, dim2, isl_dim_in) &&
-              isl_dim_tuple_match(dim1, isl_dim_out, dim2, isl_dim_out);
+       return isl_local_space_from_space(dim);
 }
-
-int isl_dim_compatible(struct isl_dim *dim1, struct isl_dim *dim2)
+__isl_give isl_space *isl_local_space_get_dim(
+       __isl_keep isl_local_space *ls)
 {
-       return dim1->nparam == dim2->nparam &&
-              dim1->n_in + dim1->n_out == dim2->n_in + dim2->n_out;
+       return isl_local_space_get_space(ls);
 }
 
-static uint32_t isl_hash_dim(uint32_t hash, __isl_keep isl_dim *dim)
+__isl_give isl_space *isl_aff_get_dim(__isl_keep isl_aff *aff)
 {
-       int i;
-       struct isl_name *name;
-
-       if (!dim)
-               return hash;
-
-       hash = isl_hash_builtin(hash, dim->nparam);
-       hash = isl_hash_builtin(hash, dim->n_in);
-       hash = isl_hash_builtin(hash, dim->n_out);
-
-       for (i = 0; i < dim->nparam; ++i) {
-               name = get_name(dim, isl_dim_param, i);
-               hash = isl_hash_name(hash, name);
-       }
-
-       name = tuple_name(dim, isl_dim_in);
-       hash = isl_hash_name(hash, name);
-       name = tuple_name(dim, isl_dim_out);
-       hash = isl_hash_name(hash, name);
-
-       hash = isl_hash_dim(hash, dim->nested[0]);
-       hash = isl_hash_dim(hash, dim->nested[1]);
-
-       return hash;
+       return isl_aff_get_space(aff);
 }
-
-uint32_t isl_dim_get_hash(__isl_keep isl_dim *dim)
+__isl_give isl_space *isl_pw_aff_get_dim(__isl_keep isl_pw_aff *pwaff)
 {
-       uint32_t hash;
-
-       if (!dim)
-               return 0;
-
-       hash = isl_hash_init();
-       hash = isl_hash_dim(hash, dim);
-
-       return hash;
+       return isl_pw_aff_get_space(pwaff);
 }
 
-int isl_dim_is_wrapping(__isl_keep isl_dim *dim)
+__isl_give isl_space *isl_constraint_get_dim(
+       __isl_keep isl_constraint *constraint)
 {
-       if (!dim)
-               return -1;
-
-       if (dim->n_in != 0 || dim->tuple_name[0] || dim->nested[0])
-               return 0;
-
-       return dim->nested[1] != NULL;
+       return isl_constraint_get_space(constraint);
 }
 
-__isl_give isl_dim *isl_dim_wrap(__isl_take isl_dim *dim)
+__isl_give isl_space *isl_basic_map_get_dim(__isl_keep isl_basic_map *bmap)
 {
-       isl_dim *wrap;
-
-       if (!dim)
-               return NULL;
-
-       wrap = isl_dim_alloc(dim->ctx, dim->nparam, 0, dim->n_in + dim->n_out);
-
-       wrap = copy_names(wrap, isl_dim_param, 0, dim, isl_dim_param);
-       wrap = copy_names(wrap, isl_dim_set, 0, dim, isl_dim_in);
-       wrap = copy_names(wrap, isl_dim_set, dim->n_in, dim, isl_dim_out);
-
-       if (!wrap)
-               goto error;
-
-       wrap->nested[1] = dim;
-
-       return wrap;
-error:
-       isl_dim_free(dim);
-       return NULL;
+       return isl_basic_map_get_space(bmap);
 }
-
-__isl_give isl_dim *isl_dim_unwrap(__isl_take isl_dim *dim)
+__isl_give isl_space *isl_map_get_dim(__isl_keep isl_map *map)
 {
-       isl_dim *unwrap;
-
-       if (!dim)
-               return NULL;
-
-       if (!isl_dim_is_wrapping(dim))
-               isl_die(dim->ctx, isl_error_invalid, "not a wrapping dim",
-                       goto error);
-
-       unwrap = isl_dim_copy(dim->nested[1]);
-       isl_dim_free(dim);
-
-       return unwrap;
-error:
-       isl_dim_free(dim);
-       return NULL;
+       return isl_map_get_space(map);
 }
-
-int isl_dim_is_named_or_nested(__isl_keep isl_dim *dim, enum isl_dim_type type)
+__isl_give isl_space *isl_union_map_get_dim(__isl_keep isl_union_map *umap)
 {
-       if (type != isl_dim_in && type != isl_dim_out)
-               return 0;
-       if (!dim)
-               return -1;
-       if (dim->tuple_name[type - isl_dim_in])
-               return 1;
-       if (dim->nested[type - isl_dim_in])
-               return 1;
-       return 0;
+       return isl_union_map_get_space(umap);
 }
 
-int isl_dim_may_be_set(__isl_keep isl_dim *dim)
+__isl_give isl_space *isl_basic_set_get_dim(__isl_keep isl_basic_set *bset)
 {
-       if (!dim)
-               return -1;
-       if (isl_dim_size(dim, isl_dim_in) != 0)
-               return 0;
-       if (isl_dim_is_named_or_nested(dim, isl_dim_in))
-               return 0;
-       return 1;
+       return isl_basic_set_get_space(bset);
 }
-
-__isl_give isl_dim *isl_dim_reset(__isl_take isl_dim *dim,
-       enum isl_dim_type type)
+__isl_give isl_space *isl_set_get_dim(__isl_keep isl_set *set)
 {
-       if (!isl_dim_is_named_or_nested(dim, type))
-               return dim;
-
-       dim = isl_dim_cow(dim);
-       if (!dim)
-               return NULL;
-
-       isl_name_free(dim->ctx, dim->tuple_name[type - isl_dim_in]);
-       dim->tuple_name[type - isl_dim_in] = NULL;
-       isl_dim_free(dim->nested[type - isl_dim_in]);
-       dim->nested[type - isl_dim_in] = NULL;
-
-       return dim;
+       return isl_set_get_space(set);
 }
-
-__isl_give isl_dim *isl_dim_flatten(__isl_take isl_dim *dim)
+__isl_give isl_space *isl_union_set_get_dim(__isl_keep isl_union_set *uset)
 {
-       if (!dim)
-               return NULL;
-       if (!dim->nested[0] && !dim->nested[1])
-               return dim;
-
-       if (dim->nested[0])
-               dim = isl_dim_reset(dim, isl_dim_in);
-       if (dim && dim->nested[1])
-               dim = isl_dim_reset(dim, isl_dim_out);
-
-       return dim;
+       return isl_union_set_get_space(uset);
 }
 
-__isl_give isl_dim *isl_dim_flatten_range(__isl_take isl_dim *dim)
+__isl_give isl_space *isl_point_get_dim(__isl_keep isl_point *pnt)
 {
-       if (!dim)
-               return NULL;
-       if (!dim->nested[1])
-               return dim;
-
-       return isl_dim_reset(dim, isl_dim_out);
+       return isl_point_get_space(pnt);
 }
 
-/* Replace the dimensions of the given type of dst by those of src.
- */
-__isl_give isl_dim *isl_dim_replace(__isl_take isl_dim *dst,
-       enum isl_dim_type type, __isl_keep isl_dim *src)
+__isl_give isl_space *isl_qpolynomial_get_dim(__isl_keep isl_qpolynomial *qp)
 {
-       dst = isl_dim_cow(dst);
-
-       if (!dst || !src)
-               goto error;
-
-       dst = isl_dim_drop(dst, type, 0, isl_dim_size(dst, type));
-       dst = isl_dim_add(dst, type, isl_dim_size(src, type));
-       dst = copy_names(dst, type, 0, src, type);
-
-       if (dst && type == isl_dim_param) {
-               int i;
-               for (i = 0; i <= 1; ++i) {
-                       if (!dst->nested[i])
-                               continue;
-                       dst->nested[i] = isl_dim_replace(dst->nested[i],
-                                                        type, src);
-                       if (!dst->nested[i])
-                               goto error;
-               }
-       }
-
-       return dst;
-error:
-       isl_dim_free(dst);
-       return NULL;
+       return isl_qpolynomial_get_space(qp);
 }
-
-/* Given a dimension specification "dim" of a set, create a dimension
- * specification for the lift of the set.  In particular, the result
- * is of the form [dim -> local[..]], with n_local variables in the
- * range of the wrapped map.
- */
-__isl_give isl_dim *isl_dim_lift(__isl_take isl_dim *dim, unsigned n_local)
+__isl_give isl_space *isl_pw_qpolynomial_get_dim(
+       __isl_keep isl_pw_qpolynomial *pwqp)
 {
-       isl_dim *local_dim;
-
-       if (!dim)
-               return NULL;
-
-       local_dim = isl_dim_dup(dim);
-       local_dim = isl_dim_drop(local_dim, isl_dim_set, 0, dim->n_out);
-       local_dim = isl_dim_add(local_dim, isl_dim_set, n_local);
-       local_dim = isl_dim_set_tuple_name(local_dim, isl_dim_set, "local");
-       dim = isl_dim_join(isl_dim_from_domain(dim),
-                           isl_dim_from_range(local_dim));
-       dim = isl_dim_wrap(dim);
-       dim = isl_dim_set_tuple_name(dim, isl_dim_set, "lifted");
-
-       return dim;
+       return isl_pw_qpolynomial_get_space(pwqp);
 }
-
-int isl_dim_can_zip(__isl_keep isl_dim *dim)
+__isl_give isl_space *isl_qpolynomial_fold_get_dim(
+       __isl_keep isl_qpolynomial_fold *fold)
 {
-       if (!dim)
-               return -1;
-
-       return dim->nested[0] && dim->nested[1];
+       return isl_qpolynomial_fold_get_space(fold);
 }
-
-__isl_give isl_dim *isl_dim_zip(__isl_take isl_dim *dim)
+__isl_give isl_space *isl_pw_qpolynomial_fold_get_dim(
+       __isl_keep isl_pw_qpolynomial_fold *pwf)
 {
-       isl_dim *dom, *ran;
-       isl_dim *dom_dom, *dom_ran, *ran_dom, *ran_ran;
-
-       if (!isl_dim_can_zip(dim))
-               isl_die(dim->ctx, isl_error_invalid, "dim cannot be zipped",
-                       goto error);
-
-       if (!dim)
-               return 0;
-       dom = isl_dim_unwrap(isl_dim_domain(isl_dim_copy(dim)));
-       ran = isl_dim_unwrap(isl_dim_range(dim));
-       dom_dom = isl_dim_domain(isl_dim_copy(dom));
-       dom_ran = isl_dim_range(dom);
-       ran_dom = isl_dim_domain(isl_dim_copy(ran));
-       ran_ran = isl_dim_range(ran);
-       dom = isl_dim_join(isl_dim_from_domain(dom_dom),
-                          isl_dim_from_range(ran_dom));
-       ran = isl_dim_join(isl_dim_from_domain(dom_ran),
-                          isl_dim_from_range(ran_ran));
-       return isl_dim_join(isl_dim_from_domain(isl_dim_wrap(dom)),
-                           isl_dim_from_range(isl_dim_wrap(ran)));
-error:
-       isl_dim_free(dim);
-       return NULL;
+       return isl_pw_qpolynomial_fold_get_space(pwf);
 }
-
-int isl_dim_has_named_params(__isl_keep isl_dim *dim)
+__isl_give isl_space *isl_union_pw_qpolynomial_get_dim(
+       __isl_keep isl_union_pw_qpolynomial *upwqp)
 {
-       int i;
-       unsigned off;
-
-       if (!dim)
-               return -1;
-       if (dim->nparam == 0)
-               return 1;
-       off = isl_dim_offset(dim, isl_dim_param);
-       if (off + dim->nparam > dim->n_name)
-               return 0;
-       for (i = 0; i < dim->nparam; ++i)
-               if (!dim->names[off + i])
-                       return 0;
-       return 1;
+       return isl_union_pw_qpolynomial_get_space(upwqp);
 }
-
-/* Align the initial parameters of dim1 to match the order in dim2.
- */
-__isl_give isl_dim *isl_dim_align_params(__isl_take isl_dim *dim1,
-       __isl_take isl_dim *dim2)
+__isl_give isl_space *isl_union_pw_qpolynomial_fold_get_dim(
+       __isl_keep isl_union_pw_qpolynomial_fold *upwf)
 {
-       isl_reordering *exp;
-
-       if (!isl_dim_has_named_params(dim1) || !isl_dim_has_named_params(dim2))
-               isl_die(isl_dim_get_ctx(dim1), isl_error_invalid,
-                       "parameter alignment requires named parameters",
-                       goto error);
-
-       exp = isl_parameter_alignment_reordering(dim1, dim2);
-       isl_dim_free(dim1);
-       isl_dim_free(dim2);
-       if (!exp)
-               return NULL;
-       dim1 = isl_dim_copy(exp->dim);
-       isl_reordering_free(exp);
-       return dim1;
-error:
-       isl_dim_free(dim1);
-       isl_dim_free(dim2);
-       return NULL;
+       return isl_union_pw_qpolynomial_fold_get_space(upwf);
 }
index ab3d303..37da3d4 100644 (file)
@@ -11,7 +11,7 @@
  */
 
 #include <isl_map_private.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl_dim_map.h>
 #include <isl_reordering.h>
 
@@ -61,7 +61,7 @@ void isl_dim_map_range(__isl_keep isl_dim_map *dim_map,
 }
 
 void isl_dim_map_dim_range(__isl_keep isl_dim_map *dim_map,
-       struct isl_dim *dim, enum isl_dim_type type,
+       __isl_keep isl_space *dim, enum isl_dim_type type,
        unsigned first, unsigned n, unsigned dst_pos)
 {
        int i;
@@ -70,18 +70,18 @@ void isl_dim_map_dim_range(__isl_keep isl_dim_map *dim_map,
        if (!dim_map || !dim)
                return;
        
-       src_pos = 1 + isl_dim_offset(dim, type);
+       src_pos = 1 + isl_space_offset(dim, type);
        for (i = 0; i < n; ++i) {
                dim_map->m[1 + dst_pos + i].pos = src_pos + first + i;
                dim_map->m[1 + dst_pos + i].sgn = 1;
        }
 }
 
-void isl_dim_map_dim(__isl_keep isl_dim_map *dim_map, __isl_keep isl_dim *dim,
+void isl_dim_map_dim(__isl_keep isl_dim_map *dim_map, __isl_keep isl_space *dim,
        enum isl_dim_type type, unsigned dst_pos)
 {
        isl_dim_map_dim_range(dim_map, dim, type,
-                             0, isl_dim_size(dim, type), dst_pos);
+                             0, isl_space_dim(dim, type), dst_pos);
 }
 
 void isl_dim_map_div(__isl_keep isl_dim_map *dim_map,
@@ -93,7 +93,7 @@ void isl_dim_map_div(__isl_keep isl_dim_map *dim_map,
        if (!dim_map || !bmap)
                return;
        
-       src_pos = 1 + isl_dim_total(bmap->dim);
+       src_pos = 1 + isl_space_dim(bmap->dim, isl_dim_all);
        for (i = 0; i < bmap->n_div; ++i) {
                dim_map->m[1 + dst_pos + i].pos = src_pos + i;
                dim_map->m[1 + dst_pos + i].sgn = 1;
@@ -219,8 +219,8 @@ __isl_give isl_dim_map *isl_dim_map_from_reordering(
        if (!exp)
                return NULL;
 
-       ctx = isl_dim_get_ctx(exp->dim);
-       dim_map = isl_dim_map_alloc(ctx, isl_dim_total(exp->dim));
+       ctx = isl_space_get_ctx(exp->dim);
+       dim_map = isl_dim_map_alloc(ctx, isl_space_dim(exp->dim, isl_dim_all));
        if (!dim_map)
                return NULL;
 
index 0dcdc73..0f988c3 100644 (file)
@@ -2,7 +2,7 @@
 #define ISL_DIM_MAP_H
 
 #include <isl/ctx.h>
-#include <isl/dim.h>
+#include <isl/space.h>
 #include <isl/map.h>
 
 struct isl_dim_map;
@@ -14,9 +14,9 @@ void isl_dim_map_range(__isl_keep isl_dim_map *dim_map,
        unsigned src_pos, unsigned src_stride,
        unsigned n, int sign);
 void isl_dim_map_dim_range(__isl_keep isl_dim_map *dim_map,
-       struct isl_dim *dim, enum isl_dim_type type,
+       isl_space *dim, enum isl_dim_type type,
        unsigned first, unsigned n, unsigned dst_pos);
-void isl_dim_map_dim(__isl_keep isl_dim_map *dim_map, __isl_keep isl_dim *dim,
+void isl_dim_map_dim(__isl_keep isl_dim_map *dim_map, __isl_keep isl_space *dim,
        enum isl_dim_type type, unsigned dst_pos);
 void isl_dim_map_div(__isl_keep isl_dim_map *dim_map,
        __isl_keep isl_basic_map *bmap, unsigned dst_pos);
diff --git a/isl_dim_private.h b/isl_dim_private.h
deleted file mode 100644 (file)
index c9e5ca8..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-#include <isl/dim.h>
-#include <isl/hash.h>
-
-struct isl_name;
-struct isl_dim {
-       int ref;
-
-       struct isl_ctx *ctx;
-
-       unsigned nparam;
-       unsigned n_in;          /* zero for sets */
-       unsigned n_out;         /* dim for sets */
-
-       struct isl_name *tuple_name[2];
-       struct isl_dim *nested[2];
-
-       unsigned n_name;
-       struct isl_name **names;
-};
-
-uint32_t isl_dim_get_hash(__isl_keep isl_dim *dim);
-
-__isl_give isl_dim *isl_dim_as_set_dim(__isl_take isl_dim *dim);
-
-unsigned isl_dim_offset(__isl_keep isl_dim *dim, enum isl_dim_type type);
-
-int isl_dim_may_be_set(__isl_keep isl_dim *dim);
-int isl_dim_is_named_or_nested(__isl_keep isl_dim *dim, enum isl_dim_type type);
-int isl_dim_has_named_params(__isl_keep isl_dim *dim);
-__isl_give isl_dim *isl_dim_reset(__isl_take isl_dim *dim,
-       enum isl_dim_type type);
-__isl_give isl_dim *isl_dim_flatten(__isl_take isl_dim *dim);
-__isl_give isl_dim *isl_dim_flatten_range(__isl_take isl_dim *dim);
-
-__isl_give isl_dim *isl_dim_replace(__isl_take isl_dim *dst,
-       enum isl_dim_type type, __isl_keep isl_dim *src);
-
-__isl_give isl_dim *isl_dim_lift(__isl_take isl_dim *dim, unsigned n_local);
index a04646f..84913af 100644 (file)
--- a/isl_div.c
+++ b/isl_div.c
@@ -10,7 +10,7 @@
 #include <isl_map_private.h>
 #include <isl_div_private.h>
 #include <isl/map.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl/seq.h>
 #include <isl/aff.h>
 
@@ -21,7 +21,7 @@ isl_ctx *isl_div_get_ctx(__isl_keep isl_div *div)
 
 static unsigned n(struct isl_div *d, enum isl_dim_type type)
 {
-       struct isl_dim *dim = d->bmap->dim;
+       isl_space *dim = d->bmap->dim;
        switch (type) {
        case isl_dim_param:     return dim->nparam;
        case isl_dim_in:        return dim->n_in;
@@ -38,7 +38,7 @@ unsigned isl_div_dim(__isl_keep isl_div *div, enum isl_dim_type type)
 
 static unsigned offset(struct isl_div *d, enum isl_dim_type type)
 {
-       struct isl_dim *dim = d->bmap->dim;
+       isl_space *dim = d->bmap->dim;
        switch (type) {
        case isl_dim_param: return 1 + 1;
        case isl_dim_in:    return 1 + 1 + dim->nparam;
@@ -88,14 +88,14 @@ __isl_give isl_div *isl_div_div(__isl_take isl_div *div, int pos)
        return isl_basic_map_div(bmap, pos);
 }
 
-struct isl_div *isl_div_alloc(struct isl_dim *dim)
+__isl_give isl_div *isl_div_alloc(__isl_take isl_space *dim)
 {
        struct isl_basic_map *bmap;
 
        if (!dim)
                return NULL;
 
-       bmap = isl_basic_map_alloc_dim(dim, 1, 0, 0);
+       bmap = isl_basic_map_alloc_space(dim, 1, 0, 0);
        if (!bmap)
                return NULL;
 
@@ -183,7 +183,7 @@ __isl_give isl_aff *isl_aff_from_div(__isl_take isl_div *div)
                return NULL;
 
        pos = div->line - div->bmap->div;
-       aff = isl_aff_zero(isl_basic_map_get_local_space(div->bmap));
+       aff = isl_aff_zero_on_domain(isl_basic_map_get_local_space(div->bmap));
        aff = isl_aff_set_coefficient_si(aff, isl_dim_div, pos, 1);
 
        isl_div_free(div);
index 6acfd73..64d6b30 100644 (file)
@@ -15,7 +15,7 @@
 
 #include <isl_map_private.h>
 #include <isl_factorization.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl_mat_private.h>
 
 static __isl_give isl_factorizer *isl_factorizer_alloc(
@@ -86,7 +86,7 @@ __isl_give isl_factorizer *isl_factorizer_groups(__isl_keep isl_basic_set *bset,
        int i;
        unsigned nvar;
        unsigned ovar;
-       isl_dim *dim;
+       isl_space *dim;
        isl_basic_set *dom;
        isl_basic_set *ran;
        isl_morph *morph;
@@ -96,16 +96,16 @@ __isl_give isl_factorizer *isl_factorizer_groups(__isl_keep isl_basic_set *bset,
        if (!bset || !Q || !U)
                goto error;
 
-       ovar = 1 + isl_dim_offset(bset->dim, isl_dim_set);
+       ovar = 1 + isl_space_offset(bset->dim, isl_dim_set);
        id = isl_mat_identity(bset->ctx, ovar);
        Q = isl_mat_diagonal(isl_mat_copy(id), Q);
        U = isl_mat_diagonal(id, U);
 
        nvar = isl_basic_set_dim(bset, isl_dim_set);
-       dim = isl_basic_set_get_dim(bset);
-       dom = isl_basic_set_universe(isl_dim_copy(dim));
-       dim = isl_dim_drop(dim, isl_dim_set, 0, nvar);
-       dim = isl_dim_add(dim, isl_dim_set, nvar);
+       dim = isl_basic_set_get_space(bset);
+       dom = isl_basic_set_universe(isl_space_copy(dim));
+       dim = isl_space_drop_dims(dim, isl_dim_set, 0, nvar);
+       dim = isl_space_add_dims(dim, isl_dim_set, nvar);
        ran = isl_basic_set_universe(dim);
        morph = isl_morph_alloc(dom, ran, Q, U);
        f = isl_factorizer_alloc(morph, n);
@@ -276,9 +276,9 @@ __isl_give isl_factorizer *isl_basic_set_factorizer(
        if (!H)
                return NULL;
        isl_mat_sub_copy(bset->ctx, H->row, bset->eq, bset->n_eq,
-               0, 1 + isl_dim_offset(bset->dim, isl_dim_set), nvar);
+               0, 1 + isl_space_offset(bset->dim, isl_dim_set), nvar);
        isl_mat_sub_copy(bset->ctx, H->row + bset->n_eq, bset->ineq, bset->n_ineq,
-               0, 1 + isl_dim_offset(bset->dim, isl_dim_set), nvar);
+               0, 1 + isl_space_offset(bset->dim, isl_dim_set), nvar);
        H = isl_mat_left_hermite(H, 0, &U, &Q);
 
        if (init_groups(&g, H) < 0)
index 2dc617e..9f6a462 100644 (file)
@@ -10,7 +10,7 @@
 
 #include <isl_map_private.h>
 #include <isl/set.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl/seq.h>
 
 /*
@@ -63,7 +63,7 @@
 
 /* Add the given prefix to all named isl_dim_set dimensions in "dim".
  */
-static __isl_give isl_dim *isl_dim_prefix(__isl_take isl_dim *dim,
+static __isl_give isl_space *isl_space_prefix(__isl_take isl_space *dim,
        const char *prefix)
 {
        int i;
@@ -74,14 +74,14 @@ static __isl_give isl_dim *isl_dim_prefix(__isl_take isl_dim *dim,
        if (!dim)
                return NULL;
 
-       ctx = isl_dim_get_ctx(dim);
-       nvar = isl_dim_size(dim, isl_dim_set);
+       ctx = isl_space_get_ctx(dim);
+       nvar = isl_space_dim(dim, isl_dim_set);
 
        for (i = 0; i < nvar; ++i) {
                const char *name;
                char *prefix_name;
 
-               name = isl_dim_get_name(dim, isl_dim_set, i);
+               name = isl_space_get_dim_name(dim, isl_dim_set, i);
                if (!name)
                        continue;
 
@@ -92,13 +92,13 @@ static __isl_give isl_dim *isl_dim_prefix(__isl_take isl_dim *dim,
                memcpy(prefix_name, prefix, prefix_len);
                strcpy(prefix_name + prefix_len, name);
 
-               dim = isl_dim_set_name(dim, isl_dim_set, i, prefix_name);
+               dim = isl_space_set_dim_name(dim, isl_dim_set, i, prefix_name);
                free(prefix_name);
        }
 
        return dim;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -115,52 +115,52 @@ error:
  *
  * and prefix each dimension name with "c_".
  */
-static __isl_give isl_dim *isl_dim_coefficients(__isl_take isl_dim *dim)
+static __isl_give isl_space *isl_space_coefficients(__isl_take isl_space *dim)
 {
-       isl_dim *dim_param;
+       isl_space *dim_param;
        unsigned nvar;
        unsigned nparam;
 
-       nvar = isl_dim_size(dim, isl_dim_set);
-       nparam = isl_dim_size(dim, isl_dim_param);
-       dim_param = isl_dim_copy(dim);
-       dim_param = isl_dim_drop(dim_param, isl_dim_set, 0, nvar);
-       dim_param = isl_dim_move(dim_param, isl_dim_set, 0,
+       nvar = isl_space_dim(dim, isl_dim_set);
+       nparam = isl_space_dim(dim, isl_dim_param);
+       dim_param = isl_space_copy(dim);
+       dim_param = isl_space_drop_dims(dim_param, isl_dim_set, 0, nvar);
+       dim_param = isl_space_move_dims(dim_param, isl_dim_set, 0,
                                 isl_dim_param, 0, nparam);
-       dim_param = isl_dim_prefix(dim_param, "c_");
-       dim_param = isl_dim_insert(dim_param, isl_dim_set, 0, 1);
-       dim_param = isl_dim_set_name(dim_param, isl_dim_set, 0, "c_cst");
-       dim = isl_dim_drop(dim, isl_dim_param, 0, nparam);
-       dim = isl_dim_prefix(dim, "c_");
-       dim = isl_dim_join(isl_dim_from_domain(dim_param),
-                          isl_dim_from_range(dim));
-       dim = isl_dim_wrap(dim);
-       dim = isl_dim_set_tuple_name(dim, isl_dim_set, "coefficients");
+       dim_param = isl_space_prefix(dim_param, "c_");
+       dim_param = isl_space_insert_dims(dim_param, isl_dim_set, 0, 1);
+       dim_param = isl_space_set_dim_name(dim_param, isl_dim_set, 0, "c_cst");
+       dim = isl_space_drop_dims(dim, isl_dim_param, 0, nparam);
+       dim = isl_space_prefix(dim, "c_");
+       dim = isl_space_join(isl_space_from_domain(dim_param),
+                          isl_space_from_range(dim));
+       dim = isl_space_wrap(dim);
+       dim = isl_space_set_tuple_name(dim, isl_dim_set, "coefficients");
 
        return dim;
 }
 
 /* Drop the given prefix from all named dimensions of type "type" in "dim".
  */
-static __isl_give isl_dim *isl_dim_unprefix(__isl_take isl_dim *dim,
+static __isl_give isl_space *isl_space_unprefix(__isl_take isl_space *dim,
        enum isl_dim_type type, const char *prefix)
 {
        int i;
        unsigned n;
        size_t prefix_len = strlen(prefix);
 
-       n = isl_dim_size(dim, type);
+       n = isl_space_dim(dim, type);
 
        for (i = 0; i < n; ++i) {
                const char *name;
 
-               name = isl_dim_get_name(dim, type, i);
+               name = isl_space_get_dim_name(dim, type, i);
                if (!name)
                        continue;
                if (strncmp(name, prefix, prefix_len))
                        continue;
 
-               dim = isl_dim_set_name(dim, type, i, name + prefix_len);
+               dim = isl_space_set_dim_name(dim, type, i, name + prefix_len);
        }
 
        return dim;
@@ -179,17 +179,17 @@ static __isl_give isl_dim *isl_dim_unprefix(__isl_take isl_dim *dim,
  *
  * and drop the "c_" prefix from the dimension names.
  */
-static __isl_give isl_dim *isl_dim_solutions(__isl_take isl_dim *dim)
+static __isl_give isl_space *isl_space_solutions(__isl_take isl_space *dim)
 {
        unsigned nparam;
 
-       dim = isl_dim_unwrap(dim);
-       dim = isl_dim_drop(dim, isl_dim_in, 0, 1);
-       dim = isl_dim_unprefix(dim, isl_dim_in, "c_");
-       dim = isl_dim_unprefix(dim, isl_dim_out, "c_");
-       nparam = isl_dim_size(dim, isl_dim_in);
-       dim = isl_dim_move(dim, isl_dim_param, 0, isl_dim_in, 0, nparam);
-       dim = isl_dim_range(dim);
+       dim = isl_space_unwrap(dim);
+       dim = isl_space_drop_dims(dim, isl_dim_in, 0, 1);
+       dim = isl_space_unprefix(dim, isl_dim_in, "c_");
+       dim = isl_space_unprefix(dim, isl_dim_out, "c_");
+       nparam = isl_space_dim(dim, isl_dim_in);
+       dim = isl_space_move_dims(dim, isl_dim_param, 0, isl_dim_in, 0, nparam);
+       dim = isl_space_range(dim);
 
        return dim;
 }
@@ -201,7 +201,7 @@ static __isl_give isl_dim *isl_dim_solutions(__isl_take isl_dim *dim)
  * in the opposite direction (shift == -1).  "dim" is the space in which
  * the dual should be created.
  */
-static __isl_give isl_basic_set *farkas(__isl_take isl_dim *dim,
+static __isl_give isl_basic_set *farkas(__isl_take isl_space *dim,
        __isl_take isl_basic_set *bset, int shift)
 {
        int i, j, k;
@@ -210,7 +210,7 @@ static __isl_give isl_basic_set *farkas(__isl_take isl_dim *dim,
 
        total = isl_basic_set_total_dim(bset);
 
-       dual = isl_basic_set_alloc_dim(dim, bset->n_eq + bset->n_ineq,
+       dual = isl_basic_set_alloc_space(dim, bset->n_eq + bset->n_ineq,
                                        total, bset->n_ineq + (shift > 0));
        dual = isl_basic_set_set_rational(dual);
 
@@ -276,7 +276,7 @@ error:
 __isl_give isl_basic_set *isl_basic_set_coefficients(
        __isl_take isl_basic_set *bset)
 {
-       isl_dim *dim;
+       isl_space *dim;
 
        if (!bset)
                return NULL;
@@ -285,8 +285,8 @@ __isl_give isl_basic_set *isl_basic_set_coefficients(
                        "input set not allowed to have local variables",
                        goto error);
 
-       dim = isl_basic_set_get_dim(bset);
-       dim = isl_dim_coefficients(dim);
+       dim = isl_basic_set_get_space(bset);
+       dim = isl_space_coefficients(dim);
 
        return farkas(dim, bset, 1);
 error:
@@ -301,7 +301,7 @@ error:
 __isl_give isl_basic_set *isl_basic_set_solutions(
        __isl_take isl_basic_set *bset)
 {
-       isl_dim *dim;
+       isl_space *dim;
 
        if (!bset)
                return NULL;
@@ -310,8 +310,8 @@ __isl_give isl_basic_set *isl_basic_set_solutions(
                        "input set not allowed to have local variables",
                        goto error);
 
-       dim = isl_basic_set_get_dim(bset);
-       dim = isl_dim_solutions(dim);
+       dim = isl_basic_set_get_space(bset);
+       dim = isl_space_solutions(dim);
 
        return farkas(dim, bset, -1);
 error:
@@ -330,8 +330,8 @@ __isl_give isl_basic_set *isl_set_coefficients(__isl_take isl_set *set)
        if (!set)
                return NULL;
        if (set->n == 0) {
-               isl_dim *dim = isl_set_get_dim(set);
-               dim = isl_dim_coefficients(dim);
+               isl_space *dim = isl_set_get_space(set);
+               dim = isl_space_coefficients(dim);
                coeff = isl_basic_set_universe(dim);
                coeff = isl_basic_set_set_rational(coeff);
                isl_set_free(set);
@@ -363,8 +363,8 @@ __isl_give isl_basic_set *isl_set_solutions(__isl_take isl_set *set)
        if (!set)
                return NULL;
        if (set->n == 0) {
-               isl_dim *dim = isl_set_get_dim(set);
-               dim = isl_dim_solutions(dim);
+               isl_space *dim = isl_set_get_space(set);
+               dim = isl_space_solutions(dim);
                sol = isl_basic_set_universe(dim);
                sol = isl_basic_set_set_rational(sol);
                isl_set_free(set);
index 6b6c3cb..bb513c5 100644 (file)
@@ -242,6 +242,20 @@ error:
        return NULL;
 }
 
+/* Align the parameters of the two spaces if needed and then call
+ * isl_space_join.
+ */
+static __isl_give isl_space *space_align_and_join(__isl_take isl_space *left,
+       __isl_take isl_space *right)
+{
+       if (isl_space_match(left, isl_dim_param, right, isl_dim_param))
+               return isl_space_join(left, right);
+
+       left = isl_space_align_params(left, isl_space_copy(right));
+       right = isl_space_align_params(right, isl_space_copy(left));
+       return isl_space_join(left, right);
+}
+
 /* Initialize an empty isl_flow structure corresponding to a given
  * isl_access_info structure.
  * For each must access, two dependences are created (initialized
@@ -273,9 +287,10 @@ static __isl_give isl_flow *isl_flow_alloc(__isl_keep isl_access_info *acc)
 
        dep->n_source = 2 * acc->n_must + acc->n_may;
        for (i = 0; i < acc->n_must; ++i) {
-               struct isl_dim *dim;
-               dim = isl_dim_join(isl_map_get_dim(acc->source[i].map),
-                           isl_dim_reverse(isl_map_get_dim(acc->sink.map)));
+               isl_space *dim;
+               dim = space_align_and_join(
+                       isl_map_get_space(acc->source[i].map),
+                       isl_space_reverse(isl_map_get_space(acc->sink.map)));
                dep->dep[2 * i].map = isl_map_empty(dim);
                dep->dep[2 * i + 1].map = isl_map_copy(dep->dep[2 * i].map);
                dep->dep[2 * i].data = acc->source[i].data;
@@ -286,9 +301,9 @@ static __isl_give isl_flow *isl_flow_alloc(__isl_keep isl_access_info *acc)
                        goto error;
        }
        for (i = acc->n_must; i < acc->n_must + acc->n_may; ++i) {
-               struct isl_dim *dim;
-               dim = isl_dim_join(isl_map_get_dim(acc->source[i].map),
-                           isl_dim_reverse(isl_map_get_dim(acc->sink.map)));
+               isl_space *dim;
+               dim = isl_space_join(isl_map_get_space(acc->source[i].map),
+                           isl_space_reverse(isl_map_get_space(acc->sink.map)));
                dep->dep[acc->n_must + i].map = isl_map_empty(dim);
                dep->dep[acc->n_must + i].data = acc->source[i].data;
                dep->dep[acc->n_must + i].must = 0;
@@ -372,7 +387,7 @@ isl_ctx *isl_flow_get_ctx(__isl_keep isl_flow *deps)
  * be greater than the loop iterator of the range at the last
  * of the level/2 shared loops, i.e., loop level/2 - 1.
  */
-static __isl_give isl_map *after_at_level(struct isl_dim *dim, int level)
+static __isl_give isl_map *after_at_level(__isl_take isl_space *dim, int level)
 {
        struct isl_basic_map *bmap;
 
@@ -403,7 +418,7 @@ static struct isl_map *last_source(struct isl_access_info *acc,
        write_map = isl_map_copy(acc->source[j].map);
        write_map = isl_map_reverse(write_map);
        dep_map = isl_map_apply_range(read_map, write_map);
-       after = after_at_level(isl_map_get_dim(dep_map), level);
+       after = after_at_level(isl_map_get_space(dep_map), level);
        dep_map = isl_map_intersect(dep_map, after);
        result = isl_map_partial_lexmax(dep_map, set_C, empty);
        result = isl_map_reverse(result);
@@ -423,7 +438,7 @@ static struct isl_map *last_later_source(struct isl_access_info *acc,
                                         int k, int after_level,
                                         struct isl_set **empty)
 {
-       struct isl_dim *dim;
+       isl_space *dim;
        struct isl_set *set_C;
        struct isl_map *read_map;
        struct isl_map *write_map;
@@ -438,13 +453,13 @@ static struct isl_map *last_later_source(struct isl_access_info *acc,
 
        write_map = isl_map_reverse(write_map);
        dep_map = isl_map_apply_range(read_map, write_map);
-       dim = isl_dim_join(isl_map_get_dim(acc->source[k].map),
-                   isl_dim_reverse(isl_map_get_dim(acc->source[j].map)));
+       dim = space_align_and_join(isl_map_get_space(acc->source[k].map),
+                   isl_space_reverse(isl_map_get_space(acc->source[j].map)));
        after_write = after_at_level(dim, after_level);
        after_write = isl_map_apply_range(after_write, old_map);
        after_write = isl_map_reverse(after_write);
        dep_map = isl_map_intersect(dep_map, after_write);
-       before_read = after_at_level(isl_map_get_dim(dep_map), before_level);
+       before_read = after_at_level(isl_map_get_space(dep_map), before_level);
        dep_map = isl_map_intersect(dep_map, before_read);
        result = isl_map_partial_lexmax(dep_map, set_C, empty);
        result = isl_map_reverse(result);
@@ -539,7 +554,7 @@ static __isl_give isl_map *all_sources(__isl_keep isl_access_info *acc,
        write_map = isl_map_copy(acc->source[acc->n_must + j].map);
        write_map = isl_map_reverse(write_map);
        dep_map = isl_map_apply_range(read_map, write_map);
-       after = after_at_level(isl_map_get_dim(dep_map), level);
+       after = after_at_level(isl_map_get_space(dep_map), level);
        dep_map = isl_map_intersect(dep_map, after);
 
        return isl_map_reverse(dep_map);
@@ -555,7 +570,7 @@ static __isl_give isl_map *all_later_sources(__isl_keep isl_access_info *acc,
        __isl_keep isl_map *old_map,
        int j, int before_level, int k, int after_level)
 {
-       isl_dim *dim;
+       isl_space *dim;
        isl_set *set_C;
        isl_map *read_map;
        isl_map *write_map;
@@ -570,13 +585,13 @@ static __isl_give isl_map *all_later_sources(__isl_keep isl_access_info *acc,
 
        write_map = isl_map_reverse(write_map);
        dep_map = isl_map_apply_range(read_map, write_map);
-       dim = isl_dim_join(isl_map_get_dim(acc->source[acc->n_must + j].map),
-                   isl_dim_reverse(isl_map_get_dim(acc->source[k].map)));
+       dim = isl_space_join(isl_map_get_space(acc->source[acc->n_must + j].map),
+                   isl_space_reverse(isl_map_get_space(acc->source[k].map)));
        after_write = after_at_level(dim, after_level);
        after_write = isl_map_apply_range(after_write, old_map);
        after_write = isl_map_reverse(after_write);
        dep_map = isl_map_intersect(dep_map, after_write);
-       before_read = after_at_level(isl_map_get_dim(dep_map), before_level);
+       before_read = after_at_level(isl_map_get_space(dep_map), before_level);
        dep_map = isl_map_intersect(dep_map, before_read);
        return isl_map_reverse(dep_map);
 }
@@ -628,7 +643,7 @@ static __isl_give isl_map *all_intermediate_sources(
                                                    isl_set_copy(ran)));
                        T = isl_map_from_domain_and_range(
                            isl_set_universe(
-                               isl_dim_domain(isl_map_get_dim(must_rel[k]))),
+                               isl_space_domain(isl_map_get_space(must_rel[k]))),
                            ran);
                        must_rel[k] = isl_map_subtract(must_rel[k], T);
                }
@@ -660,7 +675,7 @@ static __isl_give isl_flow *compute_mem_based_dependences(
        for (i = 0; i < acc->n_may; ++i) {
                int plevel;
                int is_before;
-               isl_dim *dim;
+               isl_space *dim;
                isl_map *before;
                isl_map *dep;
 
@@ -668,7 +683,7 @@ static __isl_give isl_flow *compute_mem_based_dependences(
                is_before = plevel & 1;
                plevel >>= 1;
 
-               dim = isl_map_get_dim(res->dep[i].map);
+               dim = isl_map_get_space(res->dep[i].map);
                if (is_before)
                        before = isl_map_lex_le_first(dim, plevel);
                else
@@ -951,18 +966,18 @@ static __isl_give struct isl_sched_info *sched_info_alloc(
        __isl_keep isl_map *map)
 {
        isl_ctx *ctx;
-       isl_dim *dim;
+       isl_space *dim;
        struct isl_sched_info *info;
        int i, n;
 
        if (!map)
                return NULL;
 
-       dim = isl_dim_unwrap(isl_dim_domain(isl_map_get_dim(map)));
+       dim = isl_space_unwrap(isl_space_domain(isl_map_get_space(map)));
        if (!dim)
                return NULL;
-       n = isl_dim_size(dim, isl_dim_in);
-       isl_dim_free(dim);
+       n = isl_space_dim(dim, isl_dim_in);
+       isl_space_free(dim);
 
        ctx = isl_map_get_ctx(map);
        info = isl_alloc_type(ctx, struct isl_sched_info);
@@ -993,7 +1008,7 @@ struct isl_compute_flow_data {
 
        int count;
        int must;
-       isl_dim *dim;
+       isl_space *dim;
        struct isl_sched_info *sink_info;
        struct isl_sched_info **source_info;
        isl_access_info *accesses;
@@ -1002,16 +1017,16 @@ struct isl_compute_flow_data {
 static int count_matching_array(__isl_take isl_map *map, void *user)
 {
        int eq;
-       isl_dim *dim;
+       isl_space *dim;
        struct isl_compute_flow_data *data;
 
        data = (struct isl_compute_flow_data *)user;
 
-       dim = isl_dim_range(isl_map_get_dim(map));
+       dim = isl_space_range(isl_map_get_space(map));
 
-       eq = isl_dim_equal(dim, data->dim);
+       eq = isl_space_is_equal(dim, data->dim);
 
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_map_free(map);
 
        if (eq < 0)
@@ -1025,17 +1040,17 @@ static int count_matching_array(__isl_take isl_map *map, void *user)
 static int collect_matching_array(__isl_take isl_map *map, void *user)
 {
        int eq;
-       isl_dim *dim;
+       isl_space *dim;
        struct isl_sched_info *info;
        struct isl_compute_flow_data *data;
 
        data = (struct isl_compute_flow_data *)user;
 
-       dim = isl_dim_range(isl_map_get_dim(map));
+       dim = isl_space_range(isl_map_get_space(map));
 
-       eq = isl_dim_equal(dim, data->dim);
+       eq = isl_space_is_equal(dim, data->dim);
 
-       isl_dim_free(dim);
+       isl_space_free(dim);
 
        if (eq < 0)
                goto error;
@@ -1115,7 +1130,7 @@ static int compute_flow(__isl_take isl_map *map, void *user)
        data->sink_info = NULL;
        data->source_info = NULL;
        data->count = 0;
-       data->dim = isl_dim_range(isl_map_get_dim(map));
+       data->dim = isl_space_range(isl_map_get_space(map));
 
        if (isl_union_map_foreach_map(data->must_source,
                                        &count_matching_array, data) < 0)
@@ -1170,7 +1185,7 @@ static int compute_flow(__isl_take isl_map *map, void *user)
                        sched_info_free(data->source_info[i]);
                free(data->source_info);
        }
-       isl_dim_free(data->dim);
+       isl_space_free(data->dim);
        isl_map_free(map);
 
        return 0;
@@ -1182,7 +1197,7 @@ error:
                        sched_info_free(data->source_info[i]);
                free(data->source_info);
        }
-       isl_dim_free(data->dim);
+       isl_space_free(data->dim);
        isl_map_free(map);
 
        return -1;
@@ -1212,20 +1227,20 @@ int isl_union_map_compute_flow(__isl_take isl_union_map *sink,
        __isl_give isl_union_map **must_no_source,
        __isl_give isl_union_map **may_no_source)
 {
-       isl_dim *dim;
+       isl_space *dim;
        isl_union_map *range_map = NULL;
        struct isl_compute_flow_data data;
 
        sink = isl_union_map_align_params(sink,
-                                           isl_union_map_get_dim(must_source));
+                                           isl_union_map_get_space(must_source));
        sink = isl_union_map_align_params(sink,
-                                           isl_union_map_get_dim(may_source));
+                                           isl_union_map_get_space(may_source));
        sink = isl_union_map_align_params(sink,
-                                           isl_union_map_get_dim(schedule));
-       dim = isl_union_map_get_dim(sink);
-       must_source = isl_union_map_align_params(must_source, isl_dim_copy(dim));
-       may_source = isl_union_map_align_params(may_source, isl_dim_copy(dim));
-       schedule = isl_union_map_align_params(schedule, isl_dim_copy(dim));
+                                           isl_union_map_get_space(schedule));
+       dim = isl_union_map_get_space(sink);
+       must_source = isl_union_map_align_params(must_source, isl_space_copy(dim));
+       may_source = isl_union_map_align_params(may_source, isl_space_copy(dim));
+       schedule = isl_union_map_align_params(schedule, isl_space_copy(dim));
 
        schedule = isl_union_map_reverse(schedule);
        range_map = isl_union_map_range_map(schedule);
@@ -1238,14 +1253,14 @@ int isl_union_map_compute_flow(__isl_take isl_union_map *sink,
        data.must_source = must_source;
        data.may_source = may_source;
        data.must_dep = must_dep ?
-               isl_union_map_empty(isl_dim_copy(dim)) : NULL;
-       data.may_dep = may_dep ? isl_union_map_empty(isl_dim_copy(dim)) : NULL;
+               isl_union_map_empty(isl_space_copy(dim)) : NULL;
+       data.may_dep = may_dep ? isl_union_map_empty(isl_space_copy(dim)) : NULL;
        data.must_no_source = must_no_source ?
-               isl_union_map_empty(isl_dim_copy(dim)) : NULL;
+               isl_union_map_empty(isl_space_copy(dim)) : NULL;
        data.may_no_source = may_no_source ?
-               isl_union_map_empty(isl_dim_copy(dim)) : NULL;
+               isl_union_map_empty(isl_space_copy(dim)) : NULL;
 
-       isl_dim_free(dim);
+       isl_space_free(dim);
 
        if (isl_union_map_foreach_map(sink, &compute_flow, &data) < 0)
                goto error;
index dbf0578..98a91ae 100644 (file)
@@ -8,11 +8,12 @@
  * 91893 Orsay, France 
  */
 
+#define ISL_DIM_H
 #include <isl_map_private.h>
 #include <isl_union_map_private.h>
 #include <isl_polynomial_private.h>
 #include <isl_point_private.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl/lp.h>
 #include <isl/seq.h>
 #include <isl_mat_private.h>
@@ -33,7 +34,7 @@ enum isl_fold isl_fold_type_negate(enum isl_fold type)
 }
 
 static __isl_give isl_qpolynomial_fold *qpolynomial_fold_alloc(
-       enum isl_fold type, __isl_take isl_dim *dim, int n)
+       enum isl_fold type, __isl_take isl_space *dim, int n)
 {
        isl_qpolynomial_fold *fold;
 
@@ -55,7 +56,7 @@ static __isl_give isl_qpolynomial_fold *qpolynomial_fold_alloc(
 
        return fold;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -64,14 +65,26 @@ isl_ctx *isl_qpolynomial_fold_get_ctx(__isl_keep isl_qpolynomial_fold *fold)
        return fold ? fold->dim->ctx : NULL;
 }
 
-__isl_give isl_dim *isl_qpolynomial_fold_get_dim(
+__isl_give isl_space *isl_qpolynomial_fold_get_domain_space(
        __isl_keep isl_qpolynomial_fold *fold)
 {
-       return fold ? isl_dim_copy(fold->dim) : NULL;
+       return fold ? isl_space_copy(fold->dim) : NULL;
 }
 
-__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_reset_dim(
-       __isl_take isl_qpolynomial_fold *fold, __isl_take isl_dim *dim)
+__isl_give isl_space *isl_qpolynomial_fold_get_space(
+       __isl_keep isl_qpolynomial_fold *fold)
+{
+       isl_space *space;
+       if (!fold)
+               return NULL;
+       space = isl_space_copy(fold->dim);
+       space = isl_space_from_domain(space);
+       space = isl_space_add_dims(space, isl_dim_out, 1);
+       return space;
+}
+
+__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_reset_domain_space(
+       __isl_take isl_qpolynomial_fold *fold, __isl_take isl_space *dim)
 {
        int i;
 
@@ -80,22 +93,34 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_reset_dim(
                goto error;
 
        for (i = 0; i < fold->n; ++i) {
-               fold->qp[i] = isl_qpolynomial_reset_dim(fold->qp[i],
-                                                       isl_dim_copy(dim));
+               fold->qp[i] = isl_qpolynomial_reset_domain_space(fold->qp[i],
+                                                       isl_space_copy(dim));
                if (!fold->qp[i])
                        goto error;
        }
 
-       isl_dim_free(fold->dim);
+       isl_space_free(fold->dim);
        fold->dim = dim;
 
        return fold;
 error:
        isl_qpolynomial_fold_free(fold);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
+/* Reset the space of "fold".  This function is called from isl_pw_templ.c
+ * and doesn't know if the space of an element object is represented
+ * directly or through its domain.  It therefore passes along both.
+ */
+__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_reset_space_and_domain(
+       __isl_take isl_qpolynomial_fold *fold, __isl_take isl_space *space,
+       __isl_take isl_space *domain)
+{
+       isl_space_free(space);
+       return isl_qpolynomial_fold_reset_domain_space(fold, domain);
+}
+
 int isl_qpolynomial_fold_involves_dims(__isl_keep isl_qpolynomial_fold *fold,
        enum isl_dim_type type, unsigned first, unsigned n)
 {
@@ -124,7 +149,7 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_set_dim_name(
        fold = isl_qpolynomial_fold_cow(fold);
        if (!fold)
                return NULL;
-       fold->dim = isl_dim_set_name(fold->dim, type, pos, s);
+       fold->dim = isl_space_set_dim_name(fold->dim, type, pos, s);
        if (!fold->dim)
                goto error;
 
@@ -146,16 +171,19 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_drop_dims(
        enum isl_dim_type type, unsigned first, unsigned n)
 {
        int i;
+       enum isl_dim_type set_type;
 
        if (!fold)
                return NULL;
        if (n == 0)
                return fold;
 
+       set_type = type == isl_dim_in ? isl_dim_set : type;
+
        fold = isl_qpolynomial_fold_cow(fold);
        if (!fold)
                return NULL;
-       fold->dim = isl_dim_drop(fold->dim, type, first, n);
+       fold->dim = isl_space_drop_dims(fold->dim, set_type, first, n);
        if (!fold->dim)
                goto error;
 
@@ -180,13 +208,13 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_insert_dims(
 
        if (!fold)
                return NULL;
-       if (n == 0 && !isl_dim_is_named_or_nested(fold->dim, type))
+       if (n == 0 && !isl_space_is_named_or_nested(fold->dim, type))
                return fold;
 
        fold = isl_qpolynomial_fold_cow(fold);
        if (!fold)
                return NULL;
-       fold->dim = isl_dim_insert(fold->dim, type, first, n);
+       fold->dim = isl_space_insert_dims(fold->dim, type, first, n);
        if (!fold->dim)
                goto error;
 
@@ -300,7 +328,7 @@ static int isl_qpolynomial_sign(__isl_keep isl_set *set,
        if (!rec)
                return 0;
 
-       d = isl_dim_total(qp->dim);
+       d = isl_space_dim(qp->dim, isl_dim_all);
        v = isl_vec_alloc(set->ctx, 2 + d);
        if (!v)
                return 0;
@@ -318,17 +346,17 @@ static int isl_qpolynomial_sign(__isl_keep isl_set *set,
                isl_qpolynomial *r, *q;
                isl_qpolynomial *t;
 
-               min = isl_qpolynomial_cst(isl_dim_copy(qp->dim), l);
-               base = isl_qpolynomial_var_pow(isl_dim_copy(qp->dim),
+               min = isl_qpolynomial_cst_on_domain(isl_space_copy(qp->dim), l);
+               base = isl_qpolynomial_var_pow_on_domain(isl_space_copy(qp->dim),
                                                qp->upoly->var, 1);
 
-               r = isl_qpolynomial_alloc(isl_dim_copy(qp->dim), 0,
+               r = isl_qpolynomial_alloc(isl_space_copy(qp->dim), 0,
                                          isl_upoly_copy(rec->p[rec->n - 1]));
                q = isl_qpolynomial_copy(r);
 
                for (i = rec->n - 2; i >= 0; --i) {
                        r = isl_qpolynomial_mul(r, isl_qpolynomial_copy(min));
-                       t = isl_qpolynomial_alloc(isl_dim_copy(qp->dim), 0,
+                       t = isl_qpolynomial_alloc(isl_space_copy(qp->dim), 0,
                                                  isl_upoly_copy(rec->p[i]));
                        r = isl_qpolynomial_add(r, t);
                        if (i == 0)
@@ -376,7 +404,7 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_fold_on_domain(
                goto error;
 
        isl_assert(fold1->dim->ctx, fold1->type == fold2->type, goto error);
-       isl_assert(fold1->dim->ctx, isl_dim_equal(fold1->dim, fold2->dim),
+       isl_assert(fold1->dim->ctx, isl_space_is_equal(fold1->dim, fold2->dim),
                        goto error);
 
        better = fold1->type == isl_fold_max ? -1 : 1;
@@ -391,7 +419,7 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_fold_on_domain(
                return fold1;
        }
 
-       res = qpolynomial_fold_alloc(fold1->type, isl_dim_copy(fold1->dim),
+       res = qpolynomial_fold_alloc(fold1->type, isl_space_copy(fold1->dim),
                                        fold1->n + fold2->n);
        if (!res)
                goto error;
@@ -608,11 +636,12 @@ error:
 #define PART isl_pw_qpolynomial_fold
 #undef PARTS
 #define PARTS pw_qpolynomial_fold
+#define ALIGN_DOMAIN
 
 #include <isl_union_templ.c>
 
 __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_empty(enum isl_fold type,
-       __isl_take isl_dim *dim)
+       __isl_take isl_space *dim)
 {
        return qpolynomial_fold_alloc(type, dim, 0);
 }
@@ -625,7 +654,7 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_alloc(
        if (!qp)
                return NULL;
 
-       fold = qpolynomial_fold_alloc(type, isl_dim_copy(qp->dim), 1);
+       fold = qpolynomial_fold_alloc(type, isl_space_copy(qp->dim), 1);
        if (!fold)
                goto error;
 
@@ -658,7 +687,7 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_dup(
        if (!fold)
                return NULL;
        dup = qpolynomial_fold_alloc(fold->type,
-                                       isl_dim_copy(fold->dim), fold->n);
+                                       isl_space_copy(fold->dim), fold->n);
        if (!dup)
                return NULL;
        
@@ -698,7 +727,7 @@ void isl_qpolynomial_fold_free(__isl_take isl_qpolynomial_fold *fold)
 
        for (i = 0; i < fold->n; ++i)
                isl_qpolynomial_free(fold->qp[i]);
-       isl_dim_free(fold->dim);
+       isl_space_free(fold->dim);
        free(fold);
 }
 
@@ -721,7 +750,7 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_fold(
                goto error;
 
        isl_assert(fold1->dim->ctx, fold1->type == fold2->type, goto error);
-       isl_assert(fold1->dim->ctx, isl_dim_equal(fold1->dim, fold2->dim),
+       isl_assert(fold1->dim->ctx, isl_space_is_equal(fold1->dim, fold2->dim),
                        goto error);
 
        if (isl_qpolynomial_fold_is_empty(fold1)) {
@@ -734,7 +763,7 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_fold(
                return fold1;
        }
 
-       res = qpolynomial_fold_alloc(fold1->type, isl_dim_copy(fold1->dim),
+       res = qpolynomial_fold_alloc(fold1->type, isl_space_copy(fold1->dim),
                                        fold1->n + fold2->n);
        if (!res)
                goto error;
@@ -775,7 +804,7 @@ __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_fold(
        if (!pw1 || !pw2)
                goto error;
 
-       isl_assert(pw1->dim->ctx, isl_dim_equal(pw1->dim, pw2->dim), goto error);
+       isl_assert(pw1->dim->ctx, isl_space_is_equal(pw1->dim, pw2->dim), goto error);
 
        if (isl_pw_qpolynomial_fold_is_zero(pw1)) {
                isl_pw_qpolynomial_fold_free(pw1);
@@ -792,7 +821,7 @@ __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_fold(
                        "fold types don't match", goto error);
 
        n = (pw1->n + 1) * (pw2->n + 1);
-       res = isl_pw_qpolynomial_fold_alloc_(isl_dim_copy(pw1->dim),
+       res = isl_pw_qpolynomial_fold_alloc_size(isl_space_copy(pw1->dim),
                                                pw1->type, n);
 
        for (i = 0; i < pw1->n; ++i) {
@@ -849,10 +878,10 @@ __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_fold_fold_pw_
        if (!part || !u)
                goto error;
 
-       isl_assert(u->dim->ctx, isl_dim_match(part->dim, isl_dim_param, u->dim,
+       isl_assert(u->dim->ctx, isl_space_match(part->dim, isl_dim_param, u->dim,
                                              isl_dim_param), goto error);
 
-       hash = isl_dim_get_hash(part->dim);
+       hash = isl_space_get_hash(part->dim);
        entry = isl_hash_table_find(u->dim->ctx, &u->table, hash,
                                    &has_dim, part->dim, 1);
        if (!entry)
@@ -916,8 +945,8 @@ __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_from_pw_qpolynomial(
        if (!pwqp)
                return NULL;
        
-       pwf = isl_pw_qpolynomial_fold_alloc_(isl_dim_copy(pwqp->dim), type,
-                                               pwqp->n);
+       pwf = isl_pw_qpolynomial_fold_alloc_size(isl_space_copy(pwqp->dim),
+                                               type, pwqp->n);
 
        for (i = 0; i < pwqp->n; ++i)
                pwf = isl_pw_qpolynomial_fold_add_piece(pwf,
@@ -958,13 +987,13 @@ __isl_give isl_qpolynomial *isl_qpolynomial_fold_eval(
 
        if (!fold || !pnt)
                goto error;
-       isl_assert(pnt->dim->ctx, isl_dim_equal(pnt->dim, fold->dim), goto error);
+       isl_assert(pnt->dim->ctx, isl_space_is_equal(pnt->dim, fold->dim), goto error);
        isl_assert(pnt->dim->ctx,
                fold->type == isl_fold_max || fold->type == isl_fold_min,
                goto error);
 
        if (fold->n == 0)
-               qp = isl_qpolynomial_zero(isl_dim_copy(fold->dim));
+               qp = isl_qpolynomial_zero_on_domain(isl_space_copy(fold->dim));
        else {
                int i;
                qp = isl_qpolynomial_eval(isl_qpolynomial_copy(fold->qp[0]),
@@ -1011,10 +1040,10 @@ __isl_give isl_qpolynomial *isl_qpolynomial_fold_opt_on_domain(
                goto error;
 
        if (fold->n == 0) {
-               isl_dim *dim = isl_dim_copy(fold->dim);
+               isl_space *dim = isl_space_copy(fold->dim);
                isl_set_free(set);
                isl_qpolynomial_fold_free(fold);
-               return isl_qpolynomial_zero(dim);
+               return isl_qpolynomial_zero_on_domain(dim);
        }
 
        opt = isl_qpolynomial_opt_on_domain(isl_qpolynomial_copy(fold->qp[0]),
@@ -1129,7 +1158,7 @@ int isl_pw_qpolynomial_fold_covers(__isl_keep isl_pw_qpolynomial_fold *pwf1,
        return 1;
 }
 
-__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_morph(
+__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_morph_domain(
        __isl_take isl_qpolynomial_fold *fold, __isl_take isl_morph *morph)
 {
        int i;
@@ -1139,19 +1168,19 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_morph(
                goto error;
 
        ctx = fold->dim->ctx;
-       isl_assert(ctx, isl_dim_equal(fold->dim, morph->dom->dim), goto error);
+       isl_assert(ctx, isl_space_is_equal(fold->dim, morph->dom->dim), goto error);
 
        fold = isl_qpolynomial_fold_cow(fold);
        if (!fold)
                goto error;
 
-       isl_dim_free(fold->dim);
-       fold->dim = isl_dim_copy(morph->ran->dim);
+       isl_space_free(fold->dim);
+       fold->dim = isl_space_copy(morph->ran->dim);
        if (!fold->dim)
                goto error;
 
        for (i = 0; i < fold->n; ++i) {
-               fold->qp[i] = isl_qpolynomial_morph(fold->qp[i],
+               fold->qp[i] = isl_qpolynomial_morph_domain(fold->qp[i],
                                                isl_morph_copy(morph));
                if (!fold->qp[i])
                        goto error;
@@ -1182,15 +1211,15 @@ enum isl_fold isl_union_pw_qpolynomial_fold_get_type(
 }
 
 __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_lift(
-       __isl_take isl_qpolynomial_fold *fold, __isl_take isl_dim *dim)
+       __isl_take isl_qpolynomial_fold *fold, __isl_take isl_space *dim)
 {
        int i;
 
        if (!fold || !dim)
                goto error;
 
-       if (isl_dim_equal(fold->dim, dim)) {
-               isl_dim_free(dim);
+       if (isl_space_is_equal(fold->dim, dim)) {
+               isl_space_free(dim);
                return fold;
        }
 
@@ -1198,24 +1227,24 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_lift(
        if (!fold)
                goto error;
 
-       isl_dim_free(fold->dim);
-       fold->dim = isl_dim_copy(dim);
+       isl_space_free(fold->dim);
+       fold->dim = isl_space_copy(dim);
        if (!fold->dim)
                goto error;
 
        for (i = 0; i < fold->n; ++i) {
                fold->qp[i] = isl_qpolynomial_lift(fold->qp[i],
-                                               isl_dim_copy(dim));
+                                               isl_space_copy(dim));
                if (!fold->qp[i])
                        goto error;
        }
 
-       isl_dim_free(dim);
+       isl_space_free(dim);
 
        return fold;
 error:
        isl_qpolynomial_fold_free(fold);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -1249,7 +1278,7 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_move_dims(
        if (!fold)
                return NULL;
 
-       fold->dim = isl_dim_move(fold->dim, dst_type, dst_pos,
+       fold->dim = isl_space_move_dims(fold->dim, dst_type, dst_pos,
                                                src_type, src_pos, n);
        if (!fold->dim)
                goto error;
@@ -1308,7 +1337,7 @@ static int add_pwqp(__isl_take isl_pw_qpolynomial *pwqp, void *user)
        upwf = (isl_union_pw_qpolynomial_fold **)user;
 
        ctx = pwqp->dim->ctx;
-       hash = isl_dim_get_hash(pwqp->dim);
+       hash = isl_space_get_hash(pwqp->dim);
        entry = isl_hash_table_find(ctx, &(*upwf)->table,
                                     hash, &has_dim, pwqp->dim, 1);
        if (!entry)
@@ -1338,9 +1367,9 @@ __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_fold_add_unio
        __isl_take isl_union_pw_qpolynomial *upwqp)
 {
        upwf = isl_union_pw_qpolynomial_fold_align_params(upwf,
-                               isl_union_pw_qpolynomial_get_dim(upwqp));
+                               isl_union_pw_qpolynomial_get_space(upwqp));
        upwqp = isl_union_pw_qpolynomial_align_params(upwqp,
-                               isl_union_pw_qpolynomial_fold_get_dim(upwf));
+                               isl_union_pw_qpolynomial_fold_get_space(upwf));
 
        upwf = isl_union_pw_qpolynomial_fold_cow(upwf);
        if (!upwf || !upwqp)
@@ -1359,13 +1388,13 @@ error:
        return NULL;
 }
 
-static int compatible_range(__isl_keep isl_dim *dim1, __isl_keep isl_dim *dim2)
+static int join_compatible(__isl_keep isl_space *dim1, __isl_keep isl_space *dim2)
 {
        int m;
-       m = isl_dim_match(dim1, isl_dim_param, dim2, isl_dim_param);
+       m = isl_space_match(dim1, isl_dim_param, dim2, isl_dim_param);
        if (m < 0 || !m)
                return m;
-       return isl_dim_tuple_match(dim1, isl_dim_out, dim2, isl_dim_set);
+       return isl_space_tuple_match(dim1, isl_dim_out, dim2, isl_dim_in);
 }
 
 /* Compute the intersection of the range of the map and the domain
@@ -1383,8 +1412,8 @@ __isl_give isl_pw_qpolynomial_fold *isl_map_apply_pw_qpolynomial_fold(
 {
        isl_ctx *ctx;
        isl_set *dom;
-       isl_dim *map_dim;
-       isl_dim *pwf_dim;
+       isl_space *map_dim;
+       isl_space *pwf_dim;
        unsigned n_in;
        int ok;
 
@@ -1392,20 +1421,21 @@ __isl_give isl_pw_qpolynomial_fold *isl_map_apply_pw_qpolynomial_fold(
        if (!ctx)
                goto error;
 
-       map_dim = isl_map_get_dim(map);
-       pwf_dim = isl_pw_qpolynomial_fold_get_dim(pwf);
-       ok = compatible_range(map_dim, pwf_dim);
-       isl_dim_free(map_dim);
-       isl_dim_free(pwf_dim);
+       map_dim = isl_map_get_space(map);
+       pwf_dim = isl_pw_qpolynomial_fold_get_space(pwf);
+       ok = join_compatible(map_dim, pwf_dim);
+       isl_space_free(map_dim);
+       isl_space_free(pwf_dim);
        if (!ok)
                isl_die(ctx, isl_error_invalid, "incompatible dimensions",
                        goto error);
 
        n_in = isl_map_dim(map, isl_dim_in);
-       pwf = isl_pw_qpolynomial_fold_insert_dims(pwf, isl_dim_set, 0, n_in);
+       pwf = isl_pw_qpolynomial_fold_insert_dims(pwf, isl_dim_in, 0, n_in);
 
        dom = isl_map_wrap(map);
-       pwf = isl_pw_qpolynomial_fold_reset_dim(pwf, isl_set_get_dim(dom));
+       pwf = isl_pw_qpolynomial_fold_reset_domain_space(pwf,
+                                               isl_set_get_space(dom));
 
        pwf = isl_pw_qpolynomial_fold_intersect_domain(pwf, dom);
        pwf = isl_pw_qpolynomial_fold_bound(pwf, tight);
@@ -1421,10 +1451,7 @@ __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_map *map;
-
-       map = isl_map_from_range(set);
-       return isl_map_apply_pw_qpolynomial_fold(map, pwf, tight);
+       return isl_map_apply_pw_qpolynomial_fold(set, pwf, tight);
 }
 
 struct isl_apply_fold_data {
@@ -1437,16 +1464,16 @@ struct isl_apply_fold_data {
 static int pw_qpolynomial_fold_apply(__isl_take isl_pw_qpolynomial_fold *pwf,
        void *user)
 {
-       isl_dim *map_dim;
-       isl_dim *pwf_dim;
+       isl_space *map_dim;
+       isl_space *pwf_dim;
        struct isl_apply_fold_data *data = user;
        int ok;
 
-       map_dim = isl_map_get_dim(data->map);
-       pwf_dim = isl_pw_qpolynomial_fold_get_dim(pwf);
-       ok = compatible_range(map_dim, pwf_dim);
-       isl_dim_free(map_dim);
-       isl_dim_free(pwf_dim);
+       map_dim = isl_map_get_space(data->map);
+       pwf_dim = isl_pw_qpolynomial_fold_get_space(pwf);
+       ok = join_compatible(map_dim, pwf_dim);
+       isl_space_free(map_dim);
+       isl_space_free(pwf_dim);
 
        if (ok) {
                pwf = isl_map_apply_pw_qpolynomial_fold(isl_map_copy(data->map),
@@ -1476,18 +1503,18 @@ __isl_give isl_union_pw_qpolynomial_fold *isl_union_map_apply_union_pw_qpolynomi
        __isl_take isl_union_map *umap,
        __isl_take isl_union_pw_qpolynomial_fold *upwf, int *tight)
 {
-       isl_dim *dim;
+       isl_space *dim;
        enum isl_fold type;
        struct isl_apply_fold_data data;
 
        upwf = isl_union_pw_qpolynomial_fold_align_params(upwf,
-                               isl_union_map_get_dim(umap));
+                               isl_union_map_get_space(umap));
        umap = isl_union_map_align_params(umap,
-                               isl_union_pw_qpolynomial_fold_get_dim(upwf));
+                               isl_union_pw_qpolynomial_fold_get_space(upwf));
 
        data.upwf = upwf;
        data.tight = tight ? 1 : 0;
-       dim = isl_union_pw_qpolynomial_fold_get_dim(upwf);
+       dim = isl_union_pw_qpolynomial_fold_get_space(upwf);
        type = isl_union_pw_qpolynomial_fold_get_type(upwf);
        data.res = isl_union_pw_qpolynomial_fold_zero(dim, type);
        if (isl_union_map_foreach_map(umap, &map_apply, &data) < 0)
@@ -1516,7 +1543,7 @@ __isl_give isl_union_pw_qpolynomial_fold *isl_union_set_apply_union_pw_qpolynomi
 
 /* Reorder the dimension of "fold" according to the given reordering.
  */
-__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_realign(
+__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_realign_domain(
        __isl_take isl_qpolynomial_fold *fold, __isl_take isl_reordering *r)
 {
        int i;
@@ -1526,13 +1553,14 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_realign(
                goto error;
 
        for (i = 0; i < fold->n; ++i) {
-               fold->qp[i] = isl_qpolynomial_realign(fold->qp[i],
+               fold->qp[i] = isl_qpolynomial_realign_domain(fold->qp[i],
                                                    isl_reordering_copy(r));
                if (!fold->qp[i])
                        goto error;
        }
 
-       fold = isl_qpolynomial_fold_reset_dim(fold, isl_dim_copy(r->dim));
+       fold = isl_qpolynomial_fold_reset_domain_space(fold,
+                                                   isl_space_copy(r->dim));
 
        isl_reordering_free(r);
 
@@ -1552,7 +1580,7 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_mul_isl_int(
                return fold;
        if (fold && isl_int_is_zero(v)) {
                isl_qpolynomial_fold *zero;
-               isl_dim *dim = isl_dim_copy(fold->dim);
+               isl_space *dim = isl_space_copy(fold->dim);
                zero = isl_qpolynomial_fold_empty(fold->type, dim);
                isl_qpolynomial_fold_free(fold);
                return zero;
diff --git a/isl_id.c b/isl_id.c
new file mode 100644 (file)
index 0000000..ef03330
--- /dev/null
+++ b/isl_id.c
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2008-2009 Katholieke Universiteit Leuven
+ *
+ * Use of this software is governed by the GNU LGPLv2.1 license
+ *
+ * Written by Sven Verdoolaege, K.U.Leuven, Departement
+ * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
+ */
+
+#include <string.h>
+#include <isl_ctx_private.h>
+#include <isl_id_private.h>
+
+/* A special, static isl_id to use as domains (and ranges)
+ * of sets and parameters domains.
+ * The user should never get a hold on this isl_id.
+ */
+isl_id isl_id_none = {
+       .ref = -1,
+       .ctx = NULL,
+       .name = "#none",
+       .user = NULL
+};
+
+isl_ctx *isl_id_get_ctx(__isl_keep isl_id *id)
+{
+       return id ? id->ctx : NULL;
+}
+
+void *isl_id_get_user(__isl_keep isl_id *id)
+{
+       return id ? id->user : NULL;
+}
+
+const char *isl_id_get_name(__isl_keep isl_id *id)
+{
+       return id ? id->name : NULL;
+}
+
+static __isl_give isl_id *id_alloc(isl_ctx *ctx, const char *name, void *user)
+{
+       const char *copy = name ? strdup(name) : NULL;
+       isl_id *id;
+
+       if (name && !copy)
+               return NULL;
+       id = isl_alloc_type(ctx, struct isl_id);
+       if (!id)
+               goto error;
+
+       id->ctx = ctx;
+       isl_ctx_ref(id->ctx);
+       id->ref = 1;
+       id->name = copy;
+       id->user = user;
+
+       id->hash = isl_hash_init();
+       if (name)
+               id->hash = isl_hash_string(id->hash, name);
+       else
+               id->hash = isl_hash_builtin(id->hash, user);
+
+       return id;
+error:
+       free((char *)copy);
+       return NULL;
+}
+
+static int isl_id_has_name(const void *entry, const void *val)
+{
+       isl_id *id = (isl_id *)entry;
+       const char *s = (const char *)val;
+
+       return !strcmp(id->name, s);
+}
+
+__isl_give isl_id *isl_id_alloc(isl_ctx *ctx, const char *name, void *user)
+{
+       struct isl_hash_table_entry *entry;
+       uint32_t id_hash;
+
+       id_hash = isl_hash_init();
+       if (name)
+               id_hash = isl_hash_string(id_hash, name);
+       else
+               id_hash = isl_hash_builtin(id_hash, user);
+       entry = isl_hash_table_find(ctx, &ctx->id_table, id_hash,
+                                       isl_id_has_name, name, 1);
+       if (!entry)
+               return NULL;
+       if (entry->data)
+               return isl_id_copy(entry->data);
+       entry->data = id_alloc(ctx, name, user);
+       if (!entry->data)
+               ctx->id_table.n--;
+       return entry->data;
+}
+
+/* If the id has a negative refcount, then it is a static isl_id
+ * which should not be changed.
+ */
+__isl_give isl_id *isl_id_copy(isl_id *id)
+{
+       if (!id)
+               return NULL;
+
+       if (id->ref < 0)
+               return id;
+
+       id->ref++;
+       return id;
+}
+
+static int isl_id_eq(const void *entry, const void *name)
+{
+       return entry == name;
+}
+
+uint32_t isl_hash_id(uint32_t hash, __isl_keep isl_id *id)
+{
+       if (id)
+               isl_hash_hash(hash, id->hash);
+
+       return hash;
+}
+
+/* If the id has a negative refcount, then it is a static isl_id
+ * and should not be freed.
+ */
+void *isl_id_free(__isl_take isl_id *id)
+{
+       struct isl_hash_table_entry *entry;
+
+       if (!id)
+               return NULL;
+
+       if (id->ref < 0)
+               return NULL;
+
+       if (--id->ref > 0)
+               return NULL;
+
+       entry = isl_hash_table_find(id->ctx, &id->ctx->id_table, id->hash,
+                                       isl_id_eq, id, 0);
+       if (!entry)
+               isl_die(id->ctx, isl_error_unknown,
+                       "unable to find id", (void)0);
+       else
+               isl_hash_table_remove(id->ctx, &id->ctx->id_table, entry);
+
+       free((char *)id->name);
+       isl_ctx_deref(id->ctx);
+       free(id);
+
+       return NULL;
+}
+
+__isl_give isl_printer *isl_printer_print_id(__isl_take isl_printer *p,
+       __isl_keep isl_id *id)
+{
+       if (!id)
+               goto error;
+
+       if (id->name)
+               p = isl_printer_print_str(p, id->name);
+       if (id->user) {
+               char buffer[50];
+               snprintf(buffer, sizeof(buffer), "@%p", id->user);
+               p = isl_printer_print_str(p, buffer);
+       }
+       return p;
+error:
+       isl_printer_free(p);
+       return NULL;
+}
diff --git a/isl_id_private.h b/isl_id_private.h
new file mode 100644 (file)
index 0000000..a472d77
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2008-2009 Katholieke Universiteit Leuven
+ *
+ * Use of this software is governed by the GNU LGPLv2.1 license
+ *
+ * Written by Sven Verdoolaege, K.U.Leuven, Departement
+ * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
+ */
+
+#ifndef ISL_ID_PRIVATE_H
+#define ISL_ID_PRIVATE_H
+
+#include <isl/id.h>
+
+struct isl_id {
+       int ref;
+       isl_ctx *ctx;
+
+       const char *name;
+       void *user;
+       uint32_t hash;
+};
+
+uint32_t isl_hash_id(uint32_t hash, __isl_keep isl_id *id);
+
+extern isl_id isl_id_none;
+
+#endif
index 1994a68..abfac26 100644 (file)
--- a/isl_ilp.c
+++ b/isl_ilp.c
@@ -42,7 +42,7 @@ static struct isl_basic_set *unit_box_base_points(struct isl_basic_set *bset)
        }
 
        total = isl_basic_set_total_dim(bset);
-       unit_box = isl_basic_set_alloc_dim(isl_basic_set_get_dim(bset),
+       unit_box = isl_basic_set_alloc_space(isl_basic_set_get_space(bset),
                                        0, 0, bset->n_ineq);
 
        for (i = 0; i < bset->n_ineq; ++i) {
@@ -380,7 +380,7 @@ enum isl_lp_result isl_basic_set_opt(__isl_keep isl_basic_set *bset, int max,
                return isl_lp_error;
 
        ctx = isl_aff_get_ctx(obj);
-       if (!isl_dim_equal(bset->dim, obj->ls->dim))
+       if (!isl_space_is_equal(bset->dim, obj->ls->dim))
                isl_die(ctx, isl_error_invalid,
                        "spaces don't match", return isl_lp_error);
        if (!isl_int_is_one(obj->v->el[0]))
@@ -477,3 +477,9 @@ enum isl_lp_result isl_set_max(__isl_keep isl_set *set,
 {
        return isl_set_opt(set, 1, obj, opt);
 }
+
+enum isl_lp_result isl_set_min(__isl_keep isl_set *set,
+       __isl_keep isl_aff *obj, isl_int *opt)
+{
+       return isl_set_opt(set, 0, obj, opt);
+}
index a1cf268..031bf11 100644 (file)
 #include <isl/set.h>
 #include <isl/seq.h>
 #include <isl/div.h>
-#include <isl/stream.h>
+#include <isl_stream_private.h>
 #include <isl/obj.h>
 #include "isl_polynomial_private.h"
 #include <isl/union_map.h>
 #include <isl_mat_private.h>
+#include <isl_aff_private.h>
+#include <isl/list.h>
 
 struct variable {
        char                    *name;
        int                      pos;
-       isl_vec                 *def;
-       /* non-zero if variable represents a min (-1) or a max (1) */
-       int                      sign;
-       isl_mat                 *list;
        struct variable         *next;
 };
 
@@ -56,8 +54,6 @@ static void variable_free(struct variable *var)
 {
        while (var) {
                struct variable *next = var->next;
-               isl_mat_free(var->list);
-               isl_vec_free(var->def);
                free(var->name);
                free(var);
                var = next;
@@ -84,8 +80,6 @@ static void vars_drop(struct vars *v, int n)
        var = v->v;
        while (--n >= 0) {
                struct variable *next = var->next;
-               isl_mat_free(var->list);
-               isl_vec_free(var->def);
                free(var->name);
                free(var);
                var = next;
@@ -103,7 +97,6 @@ static struct variable *variable_new(struct vars *v, const char *name, int len,
        var->name = strdup(name);
        var->name[len] = '\0';
        var->pos = pos;
-       var->def = NULL;
        var->next = v->v;
        return var;
 error:
@@ -145,24 +138,24 @@ static int vars_add_anon(struct vars *v)
        return 0;
 }
 
-static __isl_give isl_basic_map *set_name(__isl_take isl_basic_map *bmap,
+static __isl_give isl_map *set_name(__isl_take isl_map *map,
        enum isl_dim_type type, unsigned pos, char *name)
 {
        char *prime;
 
-       if (!bmap)
+       if (!map)
                return NULL;
        if (!name)
-               return bmap;
+               return map;
 
        prime = strchr(name, '\'');
        if (prime)
                *prime = '\0';
-       bmap = isl_basic_map_set_dim_name(bmap, type, pos, name);
+       map = isl_map_set_dim_name(map, type, pos, name);
        if (prime)
                *prime = '\'';
 
-       return bmap;
+       return map;
 }
 
 /* Obtain next token, with some preprocessing.
@@ -224,12 +217,11 @@ error:
  * We introduce an integer division q = [aff/d] and the result
  * is set to aff - d q.
  */
-static __isl_give isl_vec *affine_mod(struct isl_stream *s,
-       struct vars *v, __isl_take isl_vec *aff)
+static __isl_give isl_pw_aff *affine_mod(struct isl_stream *s,
+       struct vars *v, __isl_take isl_pw_aff *aff)
 {
        struct isl_token *tok;
-       struct variable *var;
-       isl_vec *mod;
+       isl_pw_aff *q;
 
        tok = next_token(s);
        if (!tok || tok->type != ISL_TOKEN_VALUE) {
@@ -237,52 +229,144 @@ static __isl_give isl_vec *affine_mod(struct isl_stream *s,
                goto error;
        }
 
-       if (vars_add_anon(v) < 0)
+       q = isl_pw_aff_copy(aff);
+       q = isl_pw_aff_scale_down(q, tok->u.v);
+       q = isl_pw_aff_floor(q);
+       q = isl_pw_aff_scale(q, tok->u.v);
+
+       aff = isl_pw_aff_sub(aff, q);
+
+       isl_token_free(tok);
+       return aff;
+error:
+       isl_pw_aff_free(aff);
+       isl_token_free(tok);
+       return NULL;
+}
+
+static __isl_give isl_pw_aff *accept_affine(struct isl_stream *s,
+       __isl_take isl_space *dim, struct vars *v);
+static __isl_give isl_pw_aff_list *accept_affine_list(struct isl_stream *s,
+       __isl_take isl_space *dim, struct vars *v);
+
+static __isl_give isl_pw_aff *accept_minmax(struct isl_stream *s,
+       __isl_take isl_space *dim, struct vars *v)
+{
+       struct isl_token *tok;
+       isl_pw_aff_list *list = NULL;
+       int min;
+
+       tok = isl_stream_next_token(s);
+       if (!tok)
                goto error;
+       min = tok->type == ISL_TOKEN_MIN;
+       isl_token_free(tok);
 
-       var = v->v;
+       if (isl_stream_eat(s, '('))
+               goto error;
 
-       var->def = isl_vec_alloc(s->ctx, 2 + v->n);
-       if (!var->def)
+       list = accept_affine_list(s, isl_space_copy(dim), v);
+       if (!list)
                goto error;
-       isl_seq_cpy(var->def->el + 1, aff->el, aff->size);
-       isl_int_set_si(var->def->el[1 + aff->size], 0);
-       isl_int_set(var->def->el[0], tok->u.v);
 
-       mod = isl_vec_alloc(v->ctx, 1 + v->n);
-       if (!mod)
+       if (isl_stream_eat(s, ')'))
                goto error;
 
-       isl_seq_cpy(mod->el, aff->el, aff->size);
-       isl_int_neg(mod->el[aff->size], tok->u.v);
+       isl_space_free(dim);
+       return min ? isl_pw_aff_list_min(list) : isl_pw_aff_list_max(list);
+error:
+       isl_space_free(dim);
+       isl_pw_aff_list_free(list);
+       return NULL;
+}
+
+static __isl_give isl_pw_aff *accept_div(struct isl_stream *s,
+       __isl_take isl_space *dim, struct vars *v)
+{
+       struct isl_token *tok;
+       int seen_paren = 0;
+       int f = 0;
+       int c = 0;
+       isl_pw_aff *pwaff = NULL;
+
+       if (isl_stream_eat_if_available(s, ISL_TOKEN_FLOORD))
+               f = 1;
+       else if (isl_stream_eat_if_available(s, ISL_TOKEN_CEILD))
+               c = 1;
+       if (f || c) {
+               if (isl_stream_eat(s, '('))
+                       goto error;
+       } else {
+               if (isl_stream_eat(s, '['))
+                       goto error;
+               if (isl_stream_eat_if_available(s, '('))
+                       seen_paren = 1;
+       }
+
+       pwaff = accept_affine(s, isl_space_copy(dim), v);
+
+       if (f || c) {
+               if (isl_stream_eat(s, ','))
+                       goto error;
+       } else {
+               if (seen_paren && isl_stream_eat(s, ')'))
+                       goto error;
+               if (isl_stream_eat(s, '/'))
+                       goto error;
+       }
 
-       isl_vec_free(aff);
+       tok = next_token(s);
+       if (!tok)
+               goto error;
+       if (tok->type != ISL_TOKEN_VALUE) {
+               isl_stream_error(s, tok, "expected denominator");
+               isl_stream_push_token(s, tok);
+               goto error;
+       }
+       isl_pw_aff_scale_down(pwaff,  tok->u.v);
        isl_token_free(tok);
-       return mod;
+
+       if (c)
+               pwaff = isl_pw_aff_ceil(pwaff);
+       else
+               pwaff = isl_pw_aff_floor(pwaff);
+
+       if (f || c) {
+               if (isl_stream_eat(s, ')'))
+                       goto error;
+       } else {
+               if (isl_stream_eat(s, ']'))
+                       goto error;
+       }
+
+       isl_space_free(dim);
+       return pwaff;
 error:
-       isl_vec_free(aff);
-       isl_token_free(tok);
+       isl_space_free(dim);
+       isl_pw_aff_free(pwaff);
        return NULL;
 }
 
-static struct isl_vec *accept_affine(struct isl_stream *s, struct vars *v);
-static int read_div_definition(struct isl_stream *s, struct vars *v);
-static int read_minmax_definition(struct isl_stream *s, struct vars *v);
-
-static __isl_give isl_vec *accept_affine_factor(struct isl_stream *s,
-       struct vars *v)
+static __isl_give isl_pw_aff *accept_affine_factor(struct isl_stream *s,
+       __isl_take isl_space *dim, struct vars *v)
 {
        struct isl_token *tok = NULL;
-       isl_vec *aff = NULL;
+       isl_pw_aff *res = NULL;
 
        tok = next_token(s);
        if (!tok) {
                isl_stream_error(s, NULL, "unexpected EOF");
                goto error;
        }
-       if (tok->type == ISL_TOKEN_IDENT) {
+
+       if (tok->type == ISL_TOKEN_AFF) {
+               res = isl_pw_aff_copy(tok->u.pwaff);
+               isl_token_free(tok);
+       } else if (tok->type == ISL_TOKEN_IDENT) {
                int n = v->n;
                int pos = vars_pos(v, tok->u.s, -1);
+               isl_aff *aff;
+
                if (pos < 0)
                        goto error;
                if (pos >= n) {
@@ -290,72 +374,52 @@ static __isl_give isl_vec *accept_affine_factor(struct isl_stream *s,
                        goto error;
                }
 
-               aff = isl_vec_alloc(v->ctx, 1 + v->n);
+               aff = isl_aff_zero_on_domain(isl_local_space_from_space(isl_space_copy(dim)));
                if (!aff)
                        goto error;
-               isl_seq_clr(aff->el, aff->size);
-               isl_int_set_si(aff->el[1 + pos], 1);
+               isl_int_set_si(aff->v->el[2 + pos], 1);
+               res = isl_pw_aff_from_aff(aff);
                isl_token_free(tok);
        } else if (tok->type == ISL_TOKEN_VALUE) {
                if (isl_stream_eat_if_available(s, '*')) {
-                       aff = accept_affine_factor(s, v);
-                       aff = isl_vec_scale(aff, tok->u.v);
+                       res = accept_affine_factor(s, isl_space_copy(dim), v);
+                       res = isl_pw_aff_scale(res, tok->u.v);
                } else {
-                       aff = isl_vec_alloc(v->ctx, 1 + v->n);
-                       if (!aff)
-                               goto error;
-                       isl_seq_clr(aff->el, aff->size);
-                       isl_int_set(aff->el[0], tok->u.v);
+                       isl_local_space *ls;
+                       isl_aff *aff;
+                       ls = isl_local_space_from_space(isl_space_copy(dim));
+                       aff = isl_aff_zero_on_domain(ls);
+                       aff = isl_aff_add_constant(aff, tok->u.v);
+                       res = isl_pw_aff_from_aff(aff);
                }
                isl_token_free(tok);
        } else if (tok->type == '(') {
                isl_token_free(tok);
                tok = NULL;
-               aff = accept_affine(s, v);
-               if (!aff)
+               res = accept_affine(s, isl_space_copy(dim), v);
+               if (!res)
                        goto error;
                if (isl_stream_eat(s, ')'))
                        goto error;
        } else if (tok->type == '[' ||
                    tok->type == ISL_TOKEN_FLOORD ||
                    tok->type == ISL_TOKEN_CEILD) {
-               int ceil = tok->type == ISL_TOKEN_CEILD;
-               struct variable *var;
-               if (vars_add_anon(v) < 0)
-                       goto error;
-               var = v->v;
-               aff = isl_vec_alloc(v->ctx, 1 + v->n);
-               if (!aff)
-                       goto error;
-               isl_seq_clr(aff->el, aff->size);
-               isl_int_set_si(aff->el[1 + v->n - 1], ceil ? -1 : 1);
                isl_stream_push_token(s, tok);
                tok = NULL;
-               if (read_div_definition(s, v) < 0)
-                       goto error;
-               if (ceil)
-                       isl_seq_neg(var->def->el + 1, var->def->el + 1,
-                                   var->def->size - 1);
-               aff = isl_vec_zero_extend(aff, 1 + v->n);
+               res = accept_div(s, isl_space_copy(dim), v);
        } else if (tok->type == ISL_TOKEN_MIN || tok->type == ISL_TOKEN_MAX) {
-               if (vars_add_anon(v) < 0)
-                       goto error;
-               aff = isl_vec_alloc(v->ctx, 1 + v->n);
-               if (!aff)
-                       goto error;
-               isl_seq_clr(aff->el, aff->size);
-               isl_int_set_si(aff->el[1 + v->n - 1], 1);
                isl_stream_push_token(s, tok);
                tok = NULL;
-               if (read_minmax_definition(s, v) < 0)
-                       goto error;
-               aff = isl_vec_zero_extend(aff, 1 + v->n);
+               res = accept_minmax(s, isl_space_copy(dim), v);
        } else {
                isl_stream_error(s, tok, "expecting factor");
                goto error;
        }
-       if (isl_stream_eat_if_available(s, '%'))
-               return affine_mod(s, v, aff);
+       if (isl_stream_eat_if_available(s, '%') ||
+           isl_stream_eat_if_available(s, ISL_TOKEN_MOD)) {
+               isl_space_free(dim);
+               return affine_mod(s, v, res);
+       }
        if (isl_stream_eat_if_available(s, '*')) {
                isl_int f;
                isl_int_init(f);
@@ -364,28 +428,44 @@ static __isl_give isl_vec *accept_affine_factor(struct isl_stream *s,
                        isl_int_clear(f);
                        goto error2;
                }
-               aff = isl_vec_scale(aff, f);
+               res = isl_pw_aff_scale(res, f);
                isl_int_clear(f);
        }
 
-       return aff;
+       isl_space_free(dim);
+       return res;
 error:
        isl_token_free(tok);
 error2:
-       isl_vec_free(aff);
+       isl_pw_aff_free(res);
+       isl_space_free(dim);
        return NULL;
 }
 
-static struct isl_vec *accept_affine(struct isl_stream *s, struct vars *v)
+static __isl_give isl_pw_aff *add_cst(__isl_take isl_pw_aff *pwaff, isl_int v)
+{
+       isl_aff *aff;
+       isl_space *space;
+
+       space = isl_pw_aff_get_domain_space(pwaff);
+       aff = isl_aff_zero_on_domain(isl_local_space_from_space(space));
+       aff = isl_aff_add_constant(aff, v);
+
+       return isl_pw_aff_add(pwaff, isl_pw_aff_from_aff(aff));
+}
+
+static __isl_give isl_pw_aff *accept_affine(struct isl_stream *s,
+       __isl_take isl_space *dim, struct vars *v)
 {
        struct isl_token *tok = NULL;
-       struct isl_vec *aff;
+       isl_local_space *ls;
+       isl_pw_aff *res;
        int sign = 1;
 
-       aff = isl_vec_alloc(v->ctx, 1 + v->n);
-       if (!aff)
-               return NULL;
-       isl_seq_clr(aff->el, aff->size);
+       ls = isl_local_space_from_space(isl_space_copy(dim));
+       res = isl_pw_aff_from_aff(isl_aff_zero_on_domain(ls));
+       if (!res)
+               goto error;
 
        for (;;) {
                tok = next_token(s);
@@ -402,16 +482,17 @@ static struct isl_vec *accept_affine(struct isl_stream *s, struct vars *v)
                    tok->type == ISL_TOKEN_MIN || tok->type == ISL_TOKEN_MAX ||
                    tok->type == ISL_TOKEN_FLOORD ||
                    tok->type == ISL_TOKEN_CEILD ||
-                   tok->type == ISL_TOKEN_IDENT) {
-                       isl_vec *aff2;
+                   tok->type == ISL_TOKEN_IDENT ||
+                   tok->type == ISL_TOKEN_AFF) {
+                       isl_pw_aff *term;
                        isl_stream_push_token(s, tok);
                        tok = NULL;
-                       aff2 = accept_affine_factor(s, v);
+                       term = accept_affine_factor(s, isl_space_copy(dim), v);
                        if (sign < 0)
-                               aff2 = isl_vec_scale(aff2, s->ctx->negone);
-                       aff = isl_vec_zero_extend(aff, 1 + v->n);
-                       aff = isl_vec_add(aff, aff2);
-                       if (!aff)
+                               res = isl_pw_aff_sub(res, term);
+                       else
+                               res = isl_pw_aff_add(res, term);
+                       if (!res)
                                goto error;
                        sign = 1;
                } else if (tok->type == ISL_TOKEN_VALUE) {
@@ -419,21 +500,22 @@ static struct isl_vec *accept_affine(struct isl_stream *s, struct vars *v)
                                isl_int_neg(tok->u.v, tok->u.v);
                        if (isl_stream_eat_if_available(s, '*') ||
                            isl_stream_next_token_is(s, ISL_TOKEN_IDENT)) {
-                               isl_vec *aff2;
-                               aff2 = accept_affine_factor(s, v);
-                               aff2 = isl_vec_scale(aff2, tok->u.v);
-                               aff = isl_vec_zero_extend(aff, 1 + v->n);
-                               aff = isl_vec_add(aff, aff2);
-                               if (!aff)
+                               isl_pw_aff *term;
+                               term = accept_affine_factor(s,
+                                                       isl_space_copy(dim), v);
+                               term = isl_pw_aff_scale(term, tok->u.v);
+                               res = isl_pw_aff_add(res, term);
+                               if (!res)
                                        goto error;
                        } else {
-                               isl_int_add(aff->el[0], aff->el[0], tok->u.v);
+                               res = add_cst(res, tok->u.v);
                        }
                        sign = 1;
                } else {
                        isl_stream_error(s, tok, "unexpected isl_token");
                        isl_stream_push_token(s, tok);
-                       isl_vec_free(aff);
+                       isl_pw_aff_free(res);
+                       isl_space_free(dim);
                        return NULL;
                }
                isl_token_free(tok);
@@ -455,100 +537,161 @@ static struct isl_vec *accept_affine(struct isl_stream *s, struct vars *v)
                }
        }
 
-       return aff;
+       isl_space_free(dim);
+       return res;
 error:
+       isl_space_free(dim);
        isl_token_free(tok);
-       isl_vec_free(aff);
+       isl_pw_aff_free(res);
        return NULL;
 }
 
-/* Add any variables in the variable list "v" that are not already in "bmap"
- * as existentially quantified variables in "bmap".
- */
-static __isl_give isl_basic_map *add_divs(__isl_take isl_basic_map *bmap,
-       struct vars *v)
+static int is_comparator(struct isl_token *tok)
 {
-       int i;
-       int extra;
-       struct variable *var;
+       if (!tok)
+               return 0;
+
+       switch (tok->type) {
+       case ISL_TOKEN_LT:
+       case ISL_TOKEN_GT:
+       case ISL_TOKEN_LE:
+       case ISL_TOKEN_GE:
+       case ISL_TOKEN_NE:
+       case '=':
+               return 1;
+       default:
+               return 0;
+       }
+}
 
-       extra = v->n - isl_basic_map_total_dim(bmap);
+static struct isl_map *read_disjuncts(struct isl_stream *s,
+       struct vars *v, __isl_take isl_map *map);
+static __isl_give isl_pw_aff *accept_extended_affine(struct isl_stream *s,
+       __isl_take isl_space *dim, struct vars *v);
 
-       if (extra == 0)
-               return bmap;
+/* Accept a ternary operator, given the first argument.
+ */
+static __isl_give isl_pw_aff *accept_ternary(struct isl_stream *s,
+       __isl_take isl_map *cond, struct vars *v)
+{
+       isl_space *dim;
+       isl_pw_aff *pwaff1 = NULL, *pwaff2 = NULL;
 
-       bmap = isl_basic_map_extend_dim(bmap, isl_basic_map_get_dim(bmap),
-                                       extra, 0, 2 * extra);
+       if (!cond)
+               return NULL;
 
-       for (i = 0; i < extra; ++i)
-               if (isl_basic_map_alloc_div(bmap) < 0)
-                       goto error;
+       if (isl_stream_eat(s, '?'))
+               goto error;
 
-       for (i = 0, var = v->v; i < extra; ++i, var = var->next) {
-               int k = bmap->n_div - 1 - i;
+       dim = isl_space_wrap(isl_map_get_space(cond));
+       pwaff1 = accept_extended_affine(s, dim, v);
+       if (!pwaff1)
+               goto error;
 
-               isl_seq_cpy(bmap->div[k], var->def->el, var->def->size);
-               isl_seq_clr(bmap->div[k] + var->def->size,
-                           2 + v->n - var->def->size);
+       if (isl_stream_eat(s, ':'))
+               goto error;
 
-               if (isl_basic_map_add_div_constraints(bmap, k) < 0)
-                       goto error;
-       }
+       dim = isl_pw_aff_get_domain_space(pwaff1);
+       pwaff2 = accept_extended_affine(s, dim, v);
+       if (!pwaff1)
+               goto error;
 
-       return bmap;
+       return isl_pw_aff_cond(isl_map_wrap(cond), pwaff1, pwaff2);
 error:
-       isl_basic_map_free(bmap);
+       isl_map_free(cond);
+       isl_pw_aff_free(pwaff1);
+       isl_pw_aff_free(pwaff2);
        return NULL;
 }
 
-static __isl_give isl_basic_map *read_var_def(struct isl_stream *s,
-       __isl_take isl_basic_map *bmap, enum isl_dim_type type, struct vars *v)
+/* Accept an affine expression that may involve ternary operators.
+ * We first read an affine expression.
+ * If it is not followed by a comparison operator, we simply return it.
+ * Otherwise, we assume the affine epxression is part of the first
+ * argument of a ternary operator and try to parse that.
+ */
+static __isl_give isl_pw_aff *accept_extended_affine(struct isl_stream *s,
+       __isl_take isl_space *dim, struct vars *v)
 {
-       isl_dim *dim;
-       isl_basic_map *def = NULL;
-       struct isl_vec *vec;
-       int k;
-       int n;
+       isl_space *space;
+       isl_map *cond;
+       isl_pw_aff *pwaff;
+       struct isl_token *tok;
+       int line = -1, col = -1;
+       int is_comp;
 
-       if (vars_add_anon(v) < 0)
-               goto error;
-       n = v->n;
+       tok = isl_stream_next_token(s);
+       if (tok) {
+               line = tok->line;
+               col = tok->col;
+               isl_stream_push_token(s, tok);
+       }
 
-       vec = accept_affine(s, v);
-       if (!vec)
-               goto error;
+       pwaff = accept_affine(s, dim, v);
+       if (!pwaff)
+               return NULL;
+
+       tok = isl_stream_next_token(s);
+       if (!tok)
+               return isl_pw_aff_free(pwaff);
+
+       is_comp = is_comparator(tok);
+       isl_stream_push_token(s, tok);
+       if (!is_comp)
+               return pwaff;
+
+       tok = isl_token_new(s->ctx, line, col, 0);
+       if (!tok)
+               return isl_pw_aff_free(pwaff);
+       tok->type = ISL_TOKEN_AFF;
+       tok->u.pwaff = pwaff;
+
+       space = isl_pw_aff_get_domain_space(pwaff);
+       cond = isl_map_universe(isl_space_unwrap(space));
+
+       isl_stream_push_token(s, tok);
+
+       cond = read_disjuncts(s, v, cond);
+
+       return accept_ternary(s, cond, v);
+}
 
-       dim = isl_basic_map_get_dim(bmap);
-       def = isl_basic_map_universe(dim);
-       def = add_divs(def, v);
-       def = isl_basic_map_extend_constraints(def, 1, 0);
-       k = isl_basic_map_alloc_equality(def);
-       if (k >= 0) {
-               isl_seq_cpy(def->eq[k], vec->el, vec->size);
-               isl_int_set_si(def->eq[k][1 + n - 1], -1);
+static __isl_give isl_map *read_var_def(struct isl_stream *s,
+       __isl_take isl_map *map, enum isl_dim_type type, struct vars *v)
+{
+       isl_pw_aff *def;
+       int pos;
+       isl_map *def_map;
+
+       if (type == isl_dim_param)
+               pos = isl_map_dim(map, isl_dim_param);
+       else {
+               pos = isl_map_dim(map, isl_dim_in);
+               if (type == isl_dim_out)
+                       pos += isl_map_dim(map, isl_dim_out);
+               type = isl_dim_in;
        }
-       isl_vec_free(vec);
-       if (k < 0)
-               goto error;
+       --pos;
 
-       vars_drop(v, v->n - n);
+       def = accept_extended_affine(s, isl_space_wrap(isl_map_get_space(map)), v);
+       def_map = isl_map_from_pw_aff(def);
+       def_map = isl_map_equate(def_map, type, pos, isl_dim_out, 0);
+       def_map = isl_set_unwrap(isl_map_domain(def_map));
 
-       def = isl_basic_map_simplify(def);
-       def = isl_basic_map_finalize(def);
-       bmap = isl_basic_map_intersect(bmap, def);
-       return bmap;
-error:
-       isl_basic_map_free(bmap);
-       isl_basic_map_free(def);
-       return NULL;
+       map = isl_map_intersect(map, def_map);
+
+       return map;
 }
 
-static __isl_give isl_basic_map *read_var_list(struct isl_stream *s,
-       __isl_take isl_basic_map *bmap, enum isl_dim_type type, struct vars *v)
+static __isl_give isl_map *read_var_list(struct isl_stream *s,
+       __isl_take isl_map *map, enum isl_dim_type type, struct vars *v)
 {
        int i = 0;
        struct isl_token *tok;
 
+       if (isl_stream_next_token_is(s, ']'))
+               return isl_map_add_dims(map, type, 0);
+
        while ((tok = next_token(s)) != NULL) {
                int new_name = 0;
 
@@ -561,13 +704,12 @@ static __isl_give isl_basic_map *read_var_list(struct isl_stream *s,
                }
 
                if (new_name) {
-                       bmap = isl_basic_map_add(bmap, type, 1);
-                       bmap = set_name(bmap, type, i, v->v->name);
+                       map = isl_map_add_dims(map, type, 1);
+                       map = set_name(map, type, i, v->v->name);
                        isl_token_free(tok);
-               } else if (tok->type == ISL_TOKEN_IDENT ||
-                          tok->type == ISL_TOKEN_VALUE ||
-                          tok->type == '-' ||
-                          tok->type == '(') {
+                       if (isl_stream_eat_if_available(s, '='))
+                               map = read_var_def(s, map, type, v);
+               } else {
                        if (type == isl_dim_param) {
                                isl_stream_error(s, tok,
                                                "expecting unique identifier");
@@ -575,10 +717,11 @@ static __isl_give isl_basic_map *read_var_list(struct isl_stream *s,
                        }
                        isl_stream_push_token(s, tok);
                        tok = NULL;
-                       bmap = isl_basic_map_add(bmap, type, 1);
-                       bmap = read_var_def(s, bmap, type, v);
-               } else
-                       break;
+                       if (vars_add_anon(v) < 0)
+                               goto error;
+                       map = isl_map_add_dims(map, type, 1);
+                       map = read_var_def(s, map, type, v);
+               }
 
                tok = isl_stream_next_token(s);
                if (tok && tok->type == ']' &&
@@ -594,24 +737,24 @@ static __isl_give isl_basic_map *read_var_list(struct isl_stream *s,
        if (tok)
                isl_stream_push_token(s, tok);
 
-       return bmap;
+       return map;
 error:
        isl_token_free(tok);
-       isl_basic_map_free(bmap);
+       isl_map_free(map);
        return NULL;
 }
 
-static __isl_give isl_mat *accept_affine_list(struct isl_stream *s,
-       struct vars *v)
+static __isl_give isl_pw_aff_list *accept_affine_list(struct isl_stream *s,
+       __isl_take isl_space *dim, struct vars *v)
 {
-       struct isl_vec *vec;
-       struct isl_mat *mat;
+       isl_pw_aff *pwaff;
+       isl_pw_aff_list *list;
        struct isl_token *tok = NULL;
 
-       vec = accept_affine(s, v);
-       mat = isl_mat_from_row_vec(vec);
-       if (!mat)
-               return NULL;
+       pwaff = accept_affine(s, isl_space_copy(dim), v);
+       list = isl_pw_aff_list_from_pw_aff(pwaff);
+       if (!list)
+               goto error;
 
        for (;;) {
                tok = isl_stream_next_token(s);
@@ -625,141 +768,29 @@ static __isl_give isl_mat *accept_affine_list(struct isl_stream *s,
                }
                isl_token_free(tok);
 
-               vec = accept_affine(s, v);
-               mat = isl_mat_add_zero_cols(mat, 1 + v->n - isl_mat_cols(mat));
-               mat = isl_mat_vec_concat(mat, vec);
-               if (!mat)
+               pwaff = accept_affine(s, isl_space_copy(dim), v);
+               list = isl_pw_aff_list_concat(list,
+                               isl_pw_aff_list_from_pw_aff(pwaff));
+               if (!list)
                        return NULL;
        }
 
-       return mat;
+       isl_space_free(dim);
+       return list;
 error:
-       isl_mat_free(mat);
+       isl_space_free(dim);
+       isl_pw_aff_list_free(list);
        return NULL;
 }
 
-static int read_minmax_definition(struct isl_stream *s, struct vars *v)
-{
-       struct isl_token *tok;
-       struct variable *var;
-
-       var = v->v;
-
-       tok = isl_stream_next_token(s);
-       if (!tok)
-               return -1;
-       var->sign = tok->type == ISL_TOKEN_MIN ? -1 : 1;
-       isl_token_free(tok);
-
-       if (isl_stream_eat(s, '('))
-               return -1;
-
-       var->list = accept_affine_list(s, v);
-       if (!var->list)
-               return -1;
-
-       if (isl_stream_eat(s, ')'))
-               return -1;
-
-       return 0;
-}
-
-static int read_div_definition(struct isl_stream *s, struct vars *v)
-{
-       struct isl_token *tok;
-       int seen_paren = 0;
-       struct isl_vec *aff;
-       struct variable *var;
-       int fc = 0;
-
-       if (isl_stream_eat_if_available(s, ISL_TOKEN_FLOORD) ||
-           isl_stream_eat_if_available(s, ISL_TOKEN_CEILD)) {
-               fc = 1;
-               if (isl_stream_eat(s, '('))
-                       return -1;
-       } else {
-               if (isl_stream_eat(s, '['))
-                       return -1;
-               if (isl_stream_eat_if_available(s, '('))
-                       seen_paren = 1;
-       }
-
-       var = v->v;
-
-       aff = accept_affine(s, v);
-       if (!aff)
-               return -1;
-
-       var->def = isl_vec_alloc(s->ctx, 2 + v->n);
-       if (!var->def) {
-               isl_vec_free(aff);
-               return -1;
-       }
-
-       isl_seq_cpy(var->def->el + 1, aff->el, aff->size);
-
-       isl_vec_free(aff);
-
-       if (fc) {
-               if (isl_stream_eat(s, ','))
-                       return -1;
-       } else {
-               if (seen_paren && isl_stream_eat(s, ')'))
-                       return -1;
-               if (isl_stream_eat(s, '/'))
-                       return -1;
-       }
-
-       tok = next_token(s);
-       if (!tok)
-               return -1;
-       if (tok->type != ISL_TOKEN_VALUE) {
-               isl_stream_error(s, tok, "expected denominator");
-               isl_stream_push_token(s, tok);
-               return -1;
-       }
-       isl_int_set(var->def->el[0], tok->u.v);
-       isl_token_free(tok);
-
-       if (fc) {
-               if (isl_stream_eat(s, ')'))
-                       return -1;
-       } else {
-               if (isl_stream_eat(s, ']'))
-                       return -1;
-       }
-
-       return 0;
-}
-
-static struct isl_basic_map *add_div_definition(struct isl_stream *s,
-       struct vars *v, struct isl_basic_map *bmap, int pos)
-{
-       struct variable *var = v->v;
-       unsigned o_out = isl_basic_map_offset(bmap, isl_dim_out) - 1;
-
-       if (read_div_definition(s, v) < 0)
-               goto error;
-
-       if (isl_basic_map_add_div_constraints_var(bmap, o_out + pos,
-                                                 var->def->el) < 0)
-               goto error;
-
-       return bmap;
-error:
-       isl_basic_map_free(bmap);
-       return NULL;
-}
-
-static struct isl_basic_map *read_defined_var_list(struct isl_stream *s,
-       struct vars *v, struct isl_basic_map *bmap)
+static __isl_give isl_map *read_defined_var_list(struct isl_stream *s,
+       struct vars *v, __isl_take isl_map *map)
 {
        struct isl_token *tok;
 
        while ((tok = isl_stream_next_token(s)) != NULL) {
                int p;
                int n = v->n;
-               unsigned n_out = isl_basic_map_dim(bmap, isl_dim_out);
 
                if (tok->type != ISL_TOKEN_IDENT)
                        break;
@@ -772,16 +803,13 @@ static struct isl_basic_map *read_defined_var_list(struct isl_stream *s,
                        goto error;
                }
 
-               bmap = isl_basic_map_cow(bmap);
-               bmap = isl_basic_map_add(bmap, isl_dim_out, 1);
-               bmap = isl_basic_map_extend_dim(bmap, isl_dim_copy(bmap->dim),
-                                               0, 0, 2);
+               map = isl_map_add_dims(map, isl_dim_out, 1);
 
                isl_token_free(tok);
                tok = isl_stream_next_token(s);
                if (tok && tok->type == '=') {
                        isl_token_free(tok);
-                       bmap = add_div_definition(s, v, bmap, n_out);
+                       map = read_var_def(s, map, isl_dim_out, v);
                        tok = isl_stream_next_token(s);
                }
 
@@ -793,10 +821,10 @@ static struct isl_basic_map *read_defined_var_list(struct isl_stream *s,
        if (tok)
                isl_stream_push_token(s, tok);
 
-       return bmap;
+       return map;
 error:
        isl_token_free(tok);
-       isl_basic_map_free(bmap);
+       isl_map_free(map);
        return NULL;
 }
 
@@ -824,25 +852,24 @@ static int next_is_tuple(struct isl_stream *s)
        return is_tuple;
 }
 
-static __isl_give isl_basic_map *read_tuple(struct isl_stream *s,
-       __isl_take isl_basic_map *bmap, enum isl_dim_type type, struct vars *v);
+static __isl_give isl_map *read_tuple(struct isl_stream *s,
+       __isl_take isl_map *map, enum isl_dim_type type, struct vars *v);
 
-static __isl_give isl_basic_map *read_nested_tuple(struct isl_stream *s,
-       __isl_take isl_basic_map *bmap, struct vars *v)
+static __isl_give isl_set *read_nested_tuple(struct isl_stream *s,
+       __isl_take isl_map *map, struct vars *v)
 {
-       bmap = read_tuple(s, bmap, isl_dim_in, v);
+       map = read_tuple(s, map, isl_dim_in, v);
        if (isl_stream_eat(s, ISL_TOKEN_TO))
                goto error;
-       bmap = read_tuple(s, bmap, isl_dim_out, v);
-       bmap = isl_basic_map_from_range(isl_basic_map_wrap(bmap));
-       return bmap;
+       map = read_tuple(s, map, isl_dim_out, v);
+       return isl_map_wrap(map);
 error:
-       isl_basic_map_free(bmap);
+       isl_map_free(map);
        return NULL;
 }
 
-static __isl_give isl_basic_map *read_tuple(struct isl_stream *s,
-       __isl_take isl_basic_map *bmap, enum isl_dim_type type, struct vars *v)
+static __isl_give isl_map *read_tuple(struct isl_stream *s,
+       __isl_take isl_map *map, enum isl_dim_type type, struct vars *v)
 {
        struct isl_token *tok;
        char *name = NULL;
@@ -861,160 +888,88 @@ static __isl_give isl_basic_map *read_tuple(struct isl_stream *s,
        }
        isl_token_free(tok);
        if (type != isl_dim_param && next_is_tuple(s)) {
-               isl_dim *dim = isl_basic_map_get_dim(bmap);
-               int nparam = isl_dim_size(dim, isl_dim_param);
-               int n_in = isl_dim_size(dim, isl_dim_in);
-               isl_basic_map *nested;
-               if (type == isl_dim_out)
-                       dim = isl_dim_move(dim, isl_dim_param, nparam,
+               isl_space *dim = isl_map_get_space(map);
+               int nparam = isl_space_dim(dim, isl_dim_param);
+               int n_in = isl_space_dim(dim, isl_dim_in);
+               isl_set *nested;
+               if (type == isl_dim_out) {
+                       dim = isl_space_move_dims(dim, isl_dim_param, nparam,
                                                isl_dim_in, 0, n_in);
-               nested = isl_basic_map_alloc_dim(dim, 0, 0, 0);
-               nested = read_nested_tuple(s, nested, v);
+                       dim = isl_space_params(dim);
+               }
+               nested = read_nested_tuple(s, isl_map_universe(dim), v);
                if (type == isl_dim_in) {
-                       nested = isl_basic_map_reverse(nested);
-                       bmap = isl_basic_map_intersect(nested, bmap);
+                       nested = isl_map_reverse(nested);
+                       map = isl_map_intersect(nested, map);
                } else {
-                       isl_basic_set *bset;
-                       dim = isl_dim_range(isl_basic_map_get_dim(nested));
-                       dim = isl_dim_drop(dim, isl_dim_param, nparam, n_in);
-                       dim = isl_dim_join(isl_basic_map_get_dim(bmap), dim);
-                       bset = isl_basic_map_domain(bmap);
-                       nested = isl_basic_map_reset_dim(nested, dim);
-                       bmap = isl_basic_map_intersect_domain(nested, bset);
+                       isl_set *set;
+                       dim = isl_set_get_space(nested);
+                       dim = isl_space_drop_dims(dim, isl_dim_param, nparam, n_in);
+                       dim = isl_space_join(isl_map_get_space(map), dim);
+                       set = isl_map_domain(map);
+                       nested = isl_map_reset_space(nested, dim);
+                       map = isl_map_intersect_domain(nested, set);
                }
        } else
-               bmap = read_var_list(s, bmap, type, v);
+               map = read_var_list(s, map, type, v);
        tok = isl_stream_next_token(s);
        if (!tok || tok->type != ']') {
                isl_stream_error(s, tok, "expecting ']'");
                goto error;
        }
-       isl_token_free(tok);
-
-       if (name) {
-               bmap = isl_basic_map_set_tuple_name(bmap, type, name);
-               free(name);
-       }
-
-       return bmap;
-error:
-       if (tok)
-               isl_token_free(tok);
-       isl_basic_map_free(bmap);
-       return NULL;
-}
-
-static __isl_give isl_basic_map *construct_constraint(
-       __isl_take isl_basic_map *bmap, enum isl_token_type type,
-       isl_int *left, isl_int *right)
-{
-       int k;
-       unsigned len;
-       struct isl_ctx *ctx;
-
-       if (!bmap)
-               return NULL;
-       len = 1 + isl_basic_map_total_dim(bmap);
-       ctx = bmap->ctx;
-
-       k = isl_basic_map_alloc_inequality(bmap);
-       if (k < 0)
-               goto error;
-       if (type == ISL_TOKEN_LE)
-               isl_seq_combine(bmap->ineq[k], ctx->negone, left,
-                                              ctx->one, right,
-                                              len);
-       else if (type == ISL_TOKEN_GE)
-               isl_seq_combine(bmap->ineq[k], ctx->one, left,
-                                              ctx->negone, right,
-                                              len);
-       else if (type == ISL_TOKEN_LT) {
-               isl_seq_combine(bmap->ineq[k], ctx->negone, left,
-                                              ctx->one, right,
-                                              len);
-               isl_int_sub_ui(bmap->ineq[k][0], bmap->ineq[k][0], 1);
-       } else if (type == ISL_TOKEN_GT) {
-               isl_seq_combine(bmap->ineq[k], ctx->one, left,
-                                              ctx->negone, right,
-                                              len);
-               isl_int_sub_ui(bmap->ineq[k][0], bmap->ineq[k][0], 1);
-       } else {
-               isl_seq_combine(bmap->ineq[k], ctx->one, left,
-                                              ctx->negone, right,
-                                              len);
-               isl_basic_map_inequality_to_equality(bmap, k);
-       }
-
-       return bmap;
-error:
-       isl_basic_map_free(bmap);
-       return NULL;
-}
-
-static int is_comparator(struct isl_token *tok)
-{
-       if (!tok)
-               return 0;
-
-       switch (tok->type) {
-       case ISL_TOKEN_LT:
-       case ISL_TOKEN_GT:
-       case ISL_TOKEN_LE:
-       case ISL_TOKEN_GE:
-       case '=':
-               return 1;
-       default:
-               return 0;
+       isl_token_free(tok);
+
+       if (name) {
+               map = isl_map_set_tuple_name(map, type, name);
+               free(name);
        }
+
+       return map;
+error:
+       if (tok)
+               isl_token_free(tok);
+       isl_map_free(map);
+       return NULL;
 }
 
-/* Add any variables in the variable list "v" that are not already in "bmap"
- * as output variables in "bmap".
- */
-static __isl_give isl_basic_map *add_lifted_divs(__isl_take isl_basic_map *bmap,
-       struct vars *v)
+static __isl_give isl_set *construct_constraints(
+       __isl_take isl_set *set, enum isl_token_type type,
+       __isl_keep isl_pw_aff_list *left, __isl_keep isl_pw_aff_list *right)
 {
-       int i;
-       int extra;
-       struct variable *var;
-
-       extra = v->n - isl_basic_map_total_dim(bmap);
-
-       if (extra == 0)
-               return bmap;
+       isl_set *cond;
 
-       bmap = isl_basic_map_add(bmap, isl_dim_out, extra);
-       bmap = isl_basic_map_extend_dim(bmap, isl_basic_map_get_dim(bmap),
-                                       0, 0, 2 * extra);
-
-       for (i = 0, var = v->v; i < extra; ++i, var = var->next) {
-               if (!var->def)
-                       continue;
-               var->def = isl_vec_zero_extend(var->def, 2 + v->n);
-               if (!var->def)
-                       goto error;
-               if (isl_basic_map_add_div_constraints_var(bmap, var->pos,
-                                                         var->def->el) < 0)
-                       goto error;
-       }
+       if (type == ISL_TOKEN_LE)
+               cond = isl_pw_aff_list_le_set(isl_pw_aff_list_copy(left),
+                                             isl_pw_aff_list_copy(right));
+       else if (type == ISL_TOKEN_GE)
+               cond = isl_pw_aff_list_ge_set(isl_pw_aff_list_copy(left),
+                                             isl_pw_aff_list_copy(right));
+       else if (type == ISL_TOKEN_LT)
+               cond = isl_pw_aff_list_lt_set(isl_pw_aff_list_copy(left),
+                                             isl_pw_aff_list_copy(right));
+       else if (type == ISL_TOKEN_GT)
+               cond = isl_pw_aff_list_gt_set(isl_pw_aff_list_copy(left),
+                                             isl_pw_aff_list_copy(right));
+       else if (type == ISL_TOKEN_NE)
+               cond = isl_pw_aff_list_ne_set(isl_pw_aff_list_copy(left),
+                                             isl_pw_aff_list_copy(right));
+       else
+               cond = isl_pw_aff_list_eq_set(isl_pw_aff_list_copy(left),
+                                             isl_pw_aff_list_copy(right));
 
-       return bmap;
-error:
-       isl_basic_map_free(bmap);
-       return NULL;
+       return isl_set_intersect(set, cond);
 }
 
-static struct isl_basic_map *add_constraint(struct isl_stream *s,
-       struct vars *v, struct isl_basic_map *bmap)
+static __isl_give isl_map *add_constraint(struct isl_stream *s,
+       struct vars *v, __isl_take isl_map *map)
 {
-       int i, j;
        struct isl_token *tok = NULL;
-       struct isl_mat *aff1 = NULL, *aff2 = NULL;
-
-       bmap = isl_basic_map_cow(bmap);
+       isl_pw_aff_list *list1 = NULL, *list2 = NULL;
+       isl_set *set;
 
-       aff1 = accept_affine_list(s, v);
-       if (!aff1)
+       set = isl_map_wrap(map);
+       list1 = accept_affine_list(s, isl_set_get_space(set), v);
+       if (!list1)
                goto error;
        tok = isl_stream_next_token(s);
        if (!is_comparator(tok)) {
@@ -1025,23 +980,14 @@ static struct isl_basic_map *add_constraint(struct isl_stream *s,
                goto error;
        }
        for (;;) {
-               aff2 = accept_affine_list(s, v);
-               if (!aff2)
+               list2 = accept_affine_list(s, isl_set_get_space(set), v);
+               if (!list2)
                        goto error;
 
-               aff1 = isl_mat_add_zero_cols(aff1, aff2->n_col - aff1->n_col);
-               if (!aff1)
-                       goto error;
-               bmap = add_lifted_divs(bmap, v);
-               bmap = isl_basic_map_extend_constraints(bmap, 0,
-                                               aff1->n_row * aff2->n_row);
-               for (i = 0; i < aff1->n_row; ++i)
-                       for (j = 0; j < aff2->n_row; ++j)
-                               bmap = construct_constraint(bmap, tok->type,
-                                                   aff1->row[i], aff2->row[j]);
+               set = construct_constraints(set, tok->type, list1, list2);
                isl_token_free(tok);
-               isl_mat_free(aff1);
-               aff1 = aff2;
+               isl_pw_aff_list_free(list1);
+               list1 = list2;
 
                tok = isl_stream_next_token(s);
                if (!is_comparator(tok)) {
@@ -1050,352 +996,207 @@ static struct isl_basic_map *add_constraint(struct isl_stream *s,
                        break;
                }
        }
-       isl_mat_free(aff1);
+       isl_pw_aff_list_free(list1);
 
-       return bmap;
+       return isl_set_unwrap(set);
 error:
        if (tok)
                isl_token_free(tok);
-       isl_mat_free(aff1);
-       isl_mat_free(aff2);
-       isl_basic_map_free(bmap);
+       isl_pw_aff_list_free(list1);
+       isl_pw_aff_list_free(list2);
+       isl_set_free(set);
        return NULL;
 }
 
-/* Return first variable, starting at n, representing a min or max,
- * or NULL if there is no such variable.
- */
-static struct variable *first_minmax(struct vars *v, int n)
-{
-       struct variable *first = NULL;
-       struct variable *var;
-
-       for (var = v->v; var && var->pos >= n; var = var->next)
-               if (var->list)
-                       first = var;
-
-       return first;
-}
-
-/* Check whether the variable at the given position only occurs in
- * inequalities and only with the given sign.
- */
-static int all_coefficients_of_sign(__isl_keep isl_map *map, int pos, int sign)
+static __isl_give isl_map *read_exists(struct isl_stream *s,
+       struct vars *v, __isl_take isl_map *map)
 {
-       int i, j;
-
-       if (!map)
-               return -1;
-
-       for (i = 0; i < map->n; ++i) {
-               isl_basic_map *bmap = map->p[i];
-
-               for (j = 0; j < bmap->n_eq; ++j)
-                       if (!isl_int_is_zero(bmap->eq[j][1 + pos]))
-                               return 0;
-               for (j = 0; j < bmap->n_ineq; ++j) {
-                       int s = isl_int_sgn(bmap->ineq[j][1 + pos]);
-                       if (s == 0)
-                               continue;
-                       if (s != sign)
-                               return 0;
-               }
-       }
-
-       return 1;
-}
+       int n = v->n;
+       int seen_paren = isl_stream_eat_if_available(s, '(');
 
-/* Given a variable m which represents a min or a max of n expressions
- * b_i, add the constraints
- *
- *     m <= b_i
- *
- * in case of a min (var->sign < 0) and m >= b_i in case of a max.
- */
-static __isl_give isl_map *bound_minmax(__isl_take isl_map *map,
-       struct variable *var)
-{
-       int i, k;
-       isl_basic_map *bound;
-       int total;
+       map = isl_map_from_domain(isl_map_wrap(map));
+       map = read_defined_var_list(s, v, map);
 
-       total = isl_map_dim(map, isl_dim_all);
-       bound = isl_basic_map_alloc_dim(isl_map_get_dim(map),
-                                       0, 0, var->list->n_row);
+       if (isl_stream_eat(s, ':'))
+               goto error;
 
-       for (i = 0; i < var->list->n_row; ++i) {
-               k = isl_basic_map_alloc_inequality(bound);
-               if (k < 0)
-                       goto error;
-               if (var->sign < 0)
-                       isl_seq_cpy(bound->ineq[k], var->list->row[i],
-                                   var->list->n_col);
-               else
-                       isl_seq_neg(bound->ineq[k], var->list->row[i],
-                                   var->list->n_col);
-               isl_int_set_si(bound->ineq[k][1 + var->pos], var->sign);
-               isl_seq_clr(bound->ineq[k] + var->list->n_col,
-                           1 + total - var->list->n_col);
-       }
+       map = read_disjuncts(s, v, map);
+       map = isl_set_unwrap(isl_map_domain(map));
 
-       map = isl_map_intersect(map, isl_map_from_basic_map(bound));
+       vars_drop(v, v->n - n);
+       if (seen_paren && isl_stream_eat(s, ')'))
+               goto error;
 
        return map;
 error:
-       isl_basic_map_free(bound);
        isl_map_free(map);
        return NULL;
 }
 
-/* Given a variable m which represents a min (or max) of n expressions
- * b_i, add constraints that assigns the minimal upper bound to m, i.e.,
- * divide the space into cells where one
- * of the upper bounds is smaller than all the others and assign
- * this upper bound to m.
- *
- * In particular, if there are n bounds b_i, then the input map
- * is split into n pieces, each with the extra constraints
- *
- *     m = b_i
- *     b_i <= b_j      for j > i
- *     b_i <  b_j      for j < i
+/* Parse an expression between parentheses and push the result
+ * back on the stream.
  *
- * in case of a min (var->sign < 0) and similarly in case of a max.
+ * The parsed expression may be either an affine expression
+ * or a condition.  The first type is pushed onto the stream
+ * as an isl_pw_aff, while the second is pushed as an isl_map.
  *
- * Note: this function is very similar to set_minimum in isl_tab_pip.c
- * Perhaps we should try to merge the two.
- */
-static __isl_give isl_map *set_minmax(__isl_take isl_map *map,
-       struct variable *var)
-{
-       int i, j, k;
-       isl_basic_map *bmap = NULL;
-       isl_ctx *ctx;
-       isl_map *split = NULL;
-       int total;
-
-       ctx = isl_map_get_ctx(map);
-       total = isl_map_dim(map, isl_dim_all);
-       split = isl_map_alloc_dim(isl_map_get_dim(map),
-                               var->list->n_row, ISL_SET_DISJOINT);
-
-       for (i = 0; i < var->list->n_row; ++i) {
-               bmap = isl_basic_map_alloc_dim(isl_map_get_dim(map), 0,
-                                              1, var->list->n_row - 1);
-               k = isl_basic_map_alloc_equality(bmap);
-               if (k < 0)
-                       goto error;
-               isl_seq_cpy(bmap->eq[k], var->list->row[i], var->list->n_col);
-               isl_int_set_si(bmap->eq[k][1 + var->pos], -1);
-               for (j = 0; j < var->list->n_row; ++j) {
-                       if (j == i)
-                               continue;
-                       k = isl_basic_map_alloc_inequality(bmap);
-                       if (k < 0)
-                               goto error;
-                       if (var->sign < 0)
-                               isl_seq_combine(bmap->ineq[k],
-                                               ctx->one, var->list->row[j],
-                                               ctx->negone, var->list->row[i],
-                                               var->list->n_col);
-                       else
-                               isl_seq_combine(bmap->ineq[k],
-                                               ctx->negone, var->list->row[j],
-                                               ctx->one, var->list->row[i],
-                                               var->list->n_col);
-                       isl_seq_clr(bmap->ineq[k] + var->list->n_col,
-                                   1 + total - var->list->n_col);
-                       if (j < i)
-                               isl_int_sub_ui(bmap->ineq[k][0],
-                                              bmap->ineq[k][0], 1);
-               }
-               bmap = isl_basic_map_finalize(bmap);
-               split = isl_map_add_basic_map(split, bmap);
-       }
-
-       map = isl_map_intersect(map, split);
-
-       return map;
-error:
-       isl_basic_map_free(bmap);
-       isl_map_free(split);
-       isl_map_free(map);
-       return NULL;
-}
-
-/* Plug in the definitions of all min and max expressions.
- * If a min expression only appears in inequalities and only
- * with a positive coefficient, then we can simply bound
- * the variable representing the min by its defining terms
- * and similarly for a max expression.
- * Otherwise, we have to assign the different terms to the
- * variable under the condition that the assigned term is smaller
- * than the other terms.
+ * If the initial token indicates the start of a condition,
+ * we parse it as such.
+ * Otherwise, we first parse an affine expression and push
+ * that onto the stream.  If the affine expression covers the
+ * entire expression between parentheses, we return.
+ * Otherwise, we assume that the affine expression is the
+ * start of a condition and continue parsing.
  */
-static __isl_give isl_map *add_minmax(__isl_take isl_map *map,
-       struct vars *v, int n)
-{
-       struct variable *var;
-
-       while (n < v->n) {
-               var = first_minmax(v, n);
-               if (!var)
-                       break;
-               if (all_coefficients_of_sign(map, var->pos, -var->sign))
-                       map = bound_minmax(map, var);
-               else
-                       map = set_minmax(map, var);
-               n = var->pos + 1;
-       }
-
-       return map;
-}
-
-static isl_map *read_constraint(struct isl_stream *s,
-       struct vars *v, __isl_take isl_basic_map *bmap)
+static int resolve_paren_expr(struct isl_stream *s,
+       struct vars *v, __isl_take isl_map *map)
 {
-       int n = v->n;
-       isl_map *map;
-       unsigned total;
+       struct isl_token *tok, *tok2;
+       int line, col;
+       isl_pw_aff *pwaff;
 
-       if (!bmap)
-               return NULL;
+       tok = isl_stream_next_token(s);
+       if (!tok || tok->type != '(')
+               goto error;
 
-       bmap = isl_basic_set_unwrap(isl_basic_set_lift(isl_basic_map_wrap(bmap)));
-       total = isl_basic_map_total_dim(bmap);
-       while (v->n < total)
-               if (vars_add_anon(v) < 0)
+       if (isl_stream_next_token_is(s, ISL_TOKEN_EXISTS) ||
+           isl_stream_next_token_is(s, ISL_TOKEN_TRUE) ||
+           isl_stream_next_token_is(s, ISL_TOKEN_FALSE)) {
+               map = read_disjuncts(s, v, map);
+               if (isl_stream_eat(s, ')'))
                        goto error;
+               tok->type = ISL_TOKEN_MAP;
+               tok->u.map = map;
+               isl_stream_push_token(s, tok);
+               return 0;
+       }
 
-       bmap = add_constraint(s, v, bmap);
-       bmap = isl_basic_map_simplify(bmap);
-       bmap = isl_basic_map_finalize(bmap);
-
-       map = isl_map_from_basic_map(bmap);
-
-       map = add_minmax(map, v, n);
-
-       map = isl_set_unwrap(isl_map_domain(map));
-
-       vars_drop(v, v->n - n);
+       tok2 = isl_stream_next_token(s);
+       if (!tok2)
+               goto error;
+       line = tok2->line;
+       col = tok2->col;
+       isl_stream_push_token(s, tok2);
 
-       return map;
-error:
-       isl_basic_map_free(bmap);
-       return NULL;
-}
+       pwaff = accept_affine(s, isl_space_wrap(isl_map_get_space(map)), v);
+       if (!pwaff)
+               goto error;
 
-static struct isl_map *read_disjuncts(struct isl_stream *s,
-       struct vars *v, __isl_take isl_basic_map *bmap);
+       tok2 = isl_token_new(s->ctx, line, col, 0);
+       if (!tok2)
+               goto error2;
+       tok2->type = ISL_TOKEN_AFF;
+       tok2->u.pwaff = pwaff;
 
-static __isl_give isl_map *read_exists(struct isl_stream *s,
-       struct vars *v, __isl_take isl_basic_map *bmap)
-{
-       int n = v->n;
-       int seen_paren = isl_stream_eat_if_available(s, '(');
-       isl_map *map = NULL;
+       if (isl_stream_eat_if_available(s, ')')) {
+               isl_stream_push_token(s, tok2);
+               isl_token_free(tok);
+               isl_map_free(map);
+               return 0;
+       }
 
-       bmap = isl_basic_map_from_domain(isl_basic_map_wrap(bmap));
-       bmap = read_defined_var_list(s, v, bmap);
+       isl_stream_push_token(s, tok2);
 
-       if (isl_stream_eat(s, ':'))
+       map = read_disjuncts(s, v, map);
+       if (isl_stream_eat(s, ')'))
                goto error;
 
-       map = read_disjuncts(s, v, bmap);
-       map = isl_set_unwrap(isl_map_domain(map));
-       bmap = NULL;
-
-       vars_drop(v, v->n - n);
-       if (seen_paren && isl_stream_eat(s, ')'))
-               goto error;
+       tok->type = ISL_TOKEN_MAP;
+       tok->u.map = map;
+       isl_stream_push_token(s, tok);
 
-       return map;
+       return 0;
+error2:
+       isl_pw_aff_free(pwaff);
 error:
-       isl_basic_map_free(bmap);
+       isl_token_free(tok);
        isl_map_free(map);
-       return NULL;
+       return -1;
 }
 
 static __isl_give isl_map *read_conjunct(struct isl_stream *s,
-       struct vars *v, __isl_take isl_basic_map *bmap)
+       struct vars *v, __isl_take isl_map *map)
 {
-       isl_map *map;
+       if (isl_stream_next_token_is(s, '('))
+               if (resolve_paren_expr(s, v, isl_map_copy(map)))
+                       goto error;
 
-       if (isl_stream_eat_if_available(s, '(')) {
-               map = read_disjuncts(s, v, bmap);
-               if (isl_stream_eat(s, ')'))
+       if (isl_stream_next_token_is(s, ISL_TOKEN_MAP)) {
+               struct isl_token *tok;
+               tok = isl_stream_next_token(s);
+               if (!tok)
                        goto error;
+               isl_map_free(map);
+               map = isl_map_copy(tok->u.map);
+               isl_token_free(tok);
                return map;
        }
 
        if (isl_stream_eat_if_available(s, ISL_TOKEN_EXISTS))
-               return read_exists(s, v, bmap);
+               return read_exists(s, v, map);
 
        if (isl_stream_eat_if_available(s, ISL_TOKEN_TRUE))
-               return isl_map_from_basic_map(bmap);
+               return map;
 
        if (isl_stream_eat_if_available(s, ISL_TOKEN_FALSE)) {
-               isl_dim *dim = isl_basic_map_get_dim(bmap);
-               isl_basic_map_free(bmap);
+               isl_space *dim = isl_map_get_space(map);
+               isl_map_free(map);
                return isl_map_empty(dim);
        }
                
-       return read_constraint(s, v, bmap);
+       return add_constraint(s, v, map);
 error:
        isl_map_free(map);
        return NULL;
 }
 
 static __isl_give isl_map *read_conjuncts(struct isl_stream *s,
-       struct vars *v, __isl_take isl_basic_map *bmap)
+       struct vars *v, __isl_take isl_map *map)
 {
-       isl_map *map;
+       isl_map *res;
        int negate;
 
        negate = isl_stream_eat_if_available(s, ISL_TOKEN_NOT);
-       map = read_conjunct(s, v, isl_basic_map_copy(bmap));
-       if (negate) {
-               isl_map *t;
-               t = isl_map_from_basic_map(isl_basic_map_copy(bmap));
-               map = isl_map_subtract(t, map);
-       }
+       res = read_conjunct(s, v, isl_map_copy(map));
+       if (negate)
+               res = isl_map_subtract(isl_map_copy(map), res);
 
        while (isl_stream_eat_if_available(s, ISL_TOKEN_AND)) {
-               isl_map *map_i;
+               isl_map *res_i;
 
                negate = isl_stream_eat_if_available(s, ISL_TOKEN_NOT);
-               map_i = read_conjunct(s, v, isl_basic_map_copy(bmap));
+               res_i = read_conjunct(s, v, isl_map_copy(map));
                if (negate)
-                       map = isl_map_subtract(map, map_i);
+                       res = isl_map_subtract(res, res_i);
                else
-                       map = isl_map_intersect(map, map_i);
+                       res = isl_map_intersect(res, res_i);
        }
 
-       isl_basic_map_free(bmap);
-       return map;
+       isl_map_free(map);
+       return res;
 }
 
 static struct isl_map *read_disjuncts(struct isl_stream *s,
-       struct vars *v, __isl_take isl_basic_map *bmap)
+       struct vars *v, __isl_take isl_map *map)
 {
-       struct isl_map *map;
+       isl_map *res;
 
        if (isl_stream_next_token_is(s, '}')) {
-               isl_dim *dim = isl_basic_map_get_dim(bmap);
-               isl_basic_map_free(bmap);
+               isl_space *dim = isl_map_get_space(map);
+               isl_map_free(map);
                return isl_map_universe(dim);
        }
 
-       map = read_conjuncts(s, v, isl_basic_map_copy(bmap));
+       res = read_conjuncts(s, v, isl_map_copy(map));
        while (isl_stream_eat_if_available(s, ISL_TOKEN_OR)) {
-               isl_map *map_i;
+               isl_map *res_i;
 
-               map_i = read_conjuncts(s, v, isl_basic_map_copy(bmap));
-               map = isl_map_union(map, map_i);
+               res_i = read_conjuncts(s, v, isl_map_copy(map));
+               res = isl_map_union(res, res_i);
        }
 
-       isl_basic_map_free(bmap);
-       return map;
+       isl_map_free(map);
+       return res;
 }
 
 static int polylib_pos_to_isl_pos(__isl_keep isl_basic_map *bmap, int pos)
@@ -1673,38 +1474,13 @@ static int optional_power(struct isl_stream *s)
        return pow;
 }
 
-static __isl_give isl_div *read_div(struct isl_stream *s,
-       __isl_take isl_dim *dim, struct vars *v)
-{
-       int n;
-       isl_basic_map *bmap;
-
-       n = v->n;
-       bmap = isl_basic_map_universe(dim);
-
-       if (vars_add_anon(v) < 0)
-               goto error;
-       if (read_div_definition(s, v) < 0)
-               goto error;
-       bmap = add_divs(bmap, v);
-       bmap = isl_basic_map_order_divs(bmap);
-       if (!bmap)
-               goto error;
-       vars_drop(v, v->n - n);
-
-       return isl_basic_map_div(bmap, bmap->n_div - 1);
-error:
-       isl_basic_map_free(bmap);
-       return NULL;
-}
+static __isl_give isl_pw_qpolynomial *read_term(struct isl_stream *s,
+       __isl_keep isl_map *map, struct vars *v);
 
-static __isl_give isl_qpolynomial *read_term(struct isl_stream *s,
-       __isl_keep isl_basic_map *bmap, struct vars *v);
-
-static __isl_give isl_qpolynomial *read_factor(struct isl_stream *s,
-       __isl_keep isl_basic_map *bmap, struct vars *v)
+static __isl_give isl_pw_qpolynomial *read_factor(struct isl_stream *s,
+       __isl_keep isl_map *map, struct vars *v)
 {
-       struct isl_qpolynomial *qp;
+       isl_pw_qpolynomial *pwqp;
        struct isl_token *tok;
 
        tok = next_token(s);
@@ -1716,16 +1492,17 @@ static __isl_give isl_qpolynomial *read_factor(struct isl_stream *s,
                int pow;
 
                isl_token_free(tok);
-               qp = read_term(s, bmap, v);
-               if (!qp)
+               pwqp = read_term(s, map, v);
+               if (!pwqp)
                        return NULL;
                if (isl_stream_eat(s, ')'))
                        goto error;
                pow = optional_power(s);
-               qp = isl_qpolynomial_pow(qp, pow);
+               pwqp = isl_pw_qpolynomial_pow(pwqp, pow);
        } else if (tok->type == ISL_TOKEN_VALUE) {
                struct isl_token *tok2;
                tok2 = isl_stream_next_token(s);
+               isl_qpolynomial *qp;
                if (tok2 && tok2->type == '/') {
                        isl_token_free(tok2);
                        tok2 = next_token(s);
@@ -1735,25 +1512,31 @@ static __isl_give isl_qpolynomial *read_factor(struct isl_stream *s,
                                isl_token_free(tok2);
                                return NULL;
                        }
-                       qp = isl_qpolynomial_rat_cst(isl_basic_map_get_dim(bmap),
+                       qp = isl_qpolynomial_rat_cst_on_domain(isl_map_get_space(map),
                                                    tok->u.v, tok2->u.v);
                        isl_token_free(tok2);
                } else {
                        isl_stream_push_token(s, tok2);
-                       qp = isl_qpolynomial_cst(isl_basic_map_get_dim(bmap),
+                       qp = isl_qpolynomial_cst_on_domain(isl_map_get_space(map),
                                                tok->u.v);
                }
                isl_token_free(tok);
+               pwqp = isl_pw_qpolynomial_from_qpolynomial(qp);
        } else if (tok->type == ISL_TOKEN_INFTY) {
+               isl_qpolynomial *qp;
                isl_token_free(tok);
-               qp = isl_qpolynomial_infty(isl_basic_map_get_dim(bmap));
+               qp = isl_qpolynomial_infty_on_domain(isl_map_get_space(map));
+               pwqp = isl_pw_qpolynomial_from_qpolynomial(qp);
        } else if (tok->type == ISL_TOKEN_NAN) {
+               isl_qpolynomial *qp;
                isl_token_free(tok);
-               qp = isl_qpolynomial_nan(isl_basic_map_get_dim(bmap));
+               qp = isl_qpolynomial_nan_on_domain(isl_map_get_space(map));
+               pwqp = isl_pw_qpolynomial_from_qpolynomial(qp);
        } else if (tok->type == ISL_TOKEN_IDENT) {
                int n = v->n;
                int pos = vars_pos(v, tok->u.s, -1);
                int pow;
+               isl_qpolynomial *qp;
                if (pos < 0) {
                        isl_token_free(tok);
                        return NULL;
@@ -1766,23 +1549,21 @@ static __isl_give isl_qpolynomial *read_factor(struct isl_stream *s,
                }
                isl_token_free(tok);
                pow = optional_power(s);
-               qp = isl_qpolynomial_var_pow(isl_basic_map_get_dim(bmap), pos, pow);
+               qp = isl_qpolynomial_var_pow_on_domain(isl_map_get_space(map), pos, pow);
+               pwqp = isl_pw_qpolynomial_from_qpolynomial(qp);
        } else if (tok->type == '[') {
-               isl_div *div;
+               isl_pw_aff *pwaff;
                int pow;
 
                isl_stream_push_token(s, tok);
-               div = read_div(s, isl_basic_map_get_dim(bmap), v);
+               pwaff = accept_affine(s, isl_map_get_space(map), v);
                pow = optional_power(s);
-               qp = isl_qpolynomial_div_pow(div, pow);
+               pwqp = isl_pw_qpolynomial_from_pw_aff(pwaff);
+               pwqp = isl_pw_qpolynomial_pow(pwqp, pow);
        } else if (tok->type == '-') {
-               struct isl_qpolynomial *qp2;
-
                isl_token_free(tok);
-               qp = isl_qpolynomial_cst(isl_basic_map_get_dim(bmap),
-                                           s->ctx->negone);
-               qp2 = read_factor(s, bmap, v);
-               qp = isl_qpolynomial_mul(qp, qp2);
+               pwqp = read_factor(s, map, v);
+               pwqp = isl_pw_qpolynomial_neg(pwqp);
        } else {
                isl_stream_error(s, tok, "unexpected isl_token");
                isl_stream_push_token(s, tok);
@@ -1791,101 +1572,94 @@ static __isl_give isl_qpolynomial *read_factor(struct isl_stream *s,
 
        if (isl_stream_eat_if_available(s, '*') ||
            isl_stream_next_token_is(s, ISL_TOKEN_IDENT)) {
-               struct isl_qpolynomial *qp2;
+               isl_pw_qpolynomial *pwqp2;
 
-               qp2 = read_factor(s, bmap, v);
-               qp = isl_qpolynomial_mul(qp, qp2);
+               pwqp2 = read_factor(s, map, v);
+               pwqp = isl_pw_qpolynomial_mul(pwqp, pwqp2);
        }
 
-       return qp;
+       return pwqp;
 error:
-       isl_qpolynomial_free(qp);
+       isl_pw_qpolynomial_free(pwqp);
        return NULL;
 }
 
-static __isl_give isl_qpolynomial *read_term(struct isl_stream *s,
-       __isl_keep isl_basic_map *bmap, struct vars *v)
+static __isl_give isl_pw_qpolynomial *read_term(struct isl_stream *s,
+       __isl_keep isl_map *map, struct vars *v)
 {
        struct isl_token *tok;
-       struct isl_qpolynomial *qp;
+       isl_pw_qpolynomial *pwqp;
 
-       qp = read_factor(s, bmap, v);
+       pwqp = read_factor(s, map, v);
 
        for (;;) {
                tok = next_token(s);
                if (!tok)
-                       return qp;
+                       return pwqp;
 
                if (tok->type == '+') {
-                       struct isl_qpolynomial *qp2;
+                       isl_pw_qpolynomial *pwqp2;
 
                        isl_token_free(tok);
-                       qp2 = read_factor(s, bmap, v);
-                       qp = isl_qpolynomial_add(qp, qp2);
+                       pwqp2 = read_factor(s, map, v);
+                       pwqp = isl_pw_qpolynomial_add(pwqp, pwqp2);
                } else if (tok->type == '-') {
-                       struct isl_qpolynomial *qp2;
+                       isl_pw_qpolynomial *pwqp2;
 
                        isl_token_free(tok);
-                       qp2 = read_factor(s, bmap, v);
-                       qp = isl_qpolynomial_sub(qp, qp2);
+                       pwqp2 = read_factor(s, map, v);
+                       pwqp = isl_pw_qpolynomial_sub(pwqp, pwqp2);
                } else if (tok->type == ISL_TOKEN_VALUE &&
                            isl_int_is_neg(tok->u.v)) {
-                       struct isl_qpolynomial *qp2;
+                       isl_pw_qpolynomial *pwqp2;
 
                        isl_stream_push_token(s, tok);
-                       qp2 = read_factor(s, bmap, v);
-                       qp = isl_qpolynomial_add(qp, qp2);
+                       pwqp2 = read_factor(s, map, v);
+                       pwqp = isl_pw_qpolynomial_add(pwqp, pwqp2);
                } else {
                        isl_stream_push_token(s, tok);
                        break;
                }
        }
 
-       return qp;
+       return pwqp;
 }
 
 static __isl_give isl_map *read_optional_disjuncts(struct isl_stream *s,
-       __isl_take isl_basic_map *bmap, struct vars *v)
+       __isl_take isl_map *map, struct vars *v)
 {
        struct isl_token *tok;
-       struct isl_map *map;
 
        tok = isl_stream_next_token(s);
        if (!tok) {
                isl_stream_error(s, NULL, "unexpected EOF");
                goto error;
        }
-       map = isl_map_from_basic_map(isl_basic_map_copy(bmap));
        if (tok->type == ':' ||
            (tok->type == ISL_TOKEN_OR && !strcmp(tok->u.s, "|"))) {
                isl_token_free(tok);
-               map = isl_map_intersect(map,
-                           read_disjuncts(s, v, isl_basic_map_copy(bmap)));
+               map = read_disjuncts(s, v, map);
        } else
                isl_stream_push_token(s, tok);
 
-       isl_basic_map_free(bmap);
-
        return map;
 error:
-       isl_basic_map_free(bmap);
+       isl_map_free(map);
        return NULL;
 }
 
 static struct isl_obj obj_read_poly(struct isl_stream *s,
-       __isl_take isl_basic_map *bmap, struct vars *v, int n)
+       __isl_take isl_map *map, struct vars *v, int n)
 {
        struct isl_obj obj = { isl_obj_pw_qpolynomial, NULL };
-       struct isl_pw_qpolynomial *pwqp;
-       struct isl_qpolynomial *qp;
-       struct isl_map *map;
+       isl_pw_qpolynomial *pwqp;
        struct isl_set *set;
 
-       qp = read_term(s, bmap, v);
-       map = read_optional_disjuncts(s, bmap, v);
+       pwqp = read_term(s, map, v);
+       map = read_optional_disjuncts(s, map, v);
        set = isl_map_range(map);
 
-       pwqp = isl_pw_qpolynomial_alloc(set, qp);
+       pwqp = isl_pw_qpolynomial_intersect_domain(pwqp, set);
 
        vars_drop(v, v->n - n);
 
@@ -1894,45 +1668,42 @@ static struct isl_obj obj_read_poly(struct isl_stream *s,
 }
 
 static struct isl_obj obj_read_poly_or_fold(struct isl_stream *s,
-       __isl_take isl_basic_map *bmap, struct vars *v, int n)
+       __isl_take isl_set *set, struct vars *v, int n)
 {
        struct isl_obj obj = { isl_obj_pw_qpolynomial_fold, NULL };
-       isl_qpolynomial *qp;
-       isl_qpolynomial_fold *fold = NULL;
-       isl_pw_qpolynomial_fold *pwf;
-       isl_map *map;
-       isl_set *set;
+       isl_pw_qpolynomial *pwqp;
+       isl_pw_qpolynomial_fold *pwf = NULL;
 
        if (!isl_stream_eat_if_available(s, ISL_TOKEN_MAX))
-               return obj_read_poly(s, bmap, v, n);
+               return obj_read_poly(s, set, v, n);
 
        if (isl_stream_eat(s, '('))
                goto error;
 
-       qp = read_term(s, bmap, v);
-       fold = isl_qpolynomial_fold_alloc(isl_fold_max, qp);
+       pwqp = read_term(s, set, v);
+       pwf = isl_pw_qpolynomial_fold_from_pw_qpolynomial(isl_fold_max, pwqp);
 
        while (isl_stream_eat_if_available(s, ',')) {
-               isl_qpolynomial_fold *fold_i;
-               qp = read_term(s, bmap, v);
-               fold_i = isl_qpolynomial_fold_alloc(isl_fold_max, qp);
-               fold = isl_qpolynomial_fold_fold(fold, fold_i);
+               isl_pw_qpolynomial_fold *pwf_i;
+               pwqp = read_term(s, set, v);
+               pwf_i = isl_pw_qpolynomial_fold_from_pw_qpolynomial(isl_fold_max,
+                                                                       pwqp);
+               pwf = isl_pw_qpolynomial_fold_fold(pwf, pwf_i);
        }
 
        if (isl_stream_eat(s, ')'))
                goto error;
 
-       map = read_optional_disjuncts(s, bmap, v);
-       set = isl_map_range(map);
-       pwf = isl_pw_qpolynomial_fold_alloc(isl_fold_max, set, fold);
+       set = read_optional_disjuncts(s, set, v);
+       pwf = isl_pw_qpolynomial_fold_intersect_domain(pwf, set);
 
        vars_drop(v, v->n - n);
 
        obj.v = pwf;
        return obj;
 error:
-       isl_basic_map_free(bmap);
-       isl_qpolynomial_fold_free(fold);
+       isl_set_free(set);
+       isl_pw_qpolynomial_fold_free(pwf);
        obj.type = isl_obj_none;
        return obj;
 }
@@ -1956,47 +1727,52 @@ static int is_rational(struct isl_stream *s)
 }
 
 static struct isl_obj obj_read_body(struct isl_stream *s,
-       __isl_take isl_basic_map *bmap, struct vars *v)
+       __isl_take isl_map *map, struct vars *v)
 {
-       struct isl_map *map = NULL;
        struct isl_token *tok;
        struct isl_obj obj = { isl_obj_set, NULL };
        int n = v->n;
 
        if (is_rational(s))
-               bmap = isl_basic_map_set_rational(bmap);
+               map = isl_map_set_rational(map);
+
+       if (isl_stream_next_token_is(s, ':')) {
+               obj.type = isl_obj_set;
+               obj.v = read_optional_disjuncts(s, map, v);
+               return obj;
+       }
 
        if (!next_is_tuple(s))
-               return obj_read_poly_or_fold(s, bmap, v, n);
+               return obj_read_poly_or_fold(s, map, v, n);
 
-       bmap = read_tuple(s, bmap, isl_dim_in, v);
-       if (!bmap)
+       map = read_tuple(s, map, isl_dim_in, v);
+       if (!map)
                goto error;
        tok = isl_stream_next_token(s);
        if (tok && tok->type == ISL_TOKEN_TO) {
                obj.type = isl_obj_map;
                isl_token_free(tok);
                if (!next_is_tuple(s)) {
-                       bmap = isl_basic_map_reverse(bmap);
-                       return obj_read_poly_or_fold(s, bmap, v, n);
+                       isl_set *set = isl_map_domain(map);
+                       return obj_read_poly_or_fold(s, set, v, n);
                }
-               bmap = read_tuple(s, bmap, isl_dim_out, v);
-               if (!bmap)
+               map = read_tuple(s, map, isl_dim_out, v);
+               if (!map)
                        goto error;
        } else {
-               bmap = isl_basic_map_reverse(bmap);
+               map = isl_map_reverse(map);
                if (tok)
                        isl_stream_push_token(s, tok);
        }
 
-       map = read_optional_disjuncts(s, bmap, v);
+       map = read_optional_disjuncts(s, map, v);
 
        vars_drop(v, v->n - n);
 
        obj.v = map;
        return obj;
 error:
-       isl_basic_map_free(bmap);
+       isl_map_free(map);
        obj.type = isl_obj_none;
        return obj;
 }
@@ -2048,21 +1824,21 @@ static struct isl_obj obj_add(struct isl_ctx *ctx,
            obj2.type == isl_obj_pw_qpolynomial_fold)
                obj2 = to_union(ctx, obj2);
        isl_assert(ctx, obj1.type == obj2.type, goto error);
-       if (obj1.type == isl_obj_map && !isl_map_has_equal_dim(obj1.v, obj2.v)) {
+       if (obj1.type == isl_obj_map && !isl_map_has_equal_space(obj1.v, obj2.v)) {
                obj1 = to_union(ctx, obj1);
                obj2 = to_union(ctx, obj2);
        }
-       if (obj1.type == isl_obj_set && !isl_set_has_equal_dim(obj1.v, obj2.v)) {
+       if (obj1.type == isl_obj_set && !isl_set_has_equal_space(obj1.v, obj2.v)) {
                obj1 = to_union(ctx, obj1);
                obj2 = to_union(ctx, obj2);
        }
        if (obj1.type == isl_obj_pw_qpolynomial &&
-           !isl_pw_qpolynomial_has_equal_dim(obj1.v, obj2.v)) {
+           !isl_pw_qpolynomial_has_equal_space(obj1.v, obj2.v)) {
                obj1 = to_union(ctx, obj1);
                obj2 = to_union(ctx, obj2);
        }
        if (obj1.type == isl_obj_pw_qpolynomial_fold &&
-           !isl_pw_qpolynomial_fold_has_equal_dim(obj1.v, obj2.v)) {
+           !isl_pw_qpolynomial_fold_has_equal_space(obj1.v, obj2.v)) {
                obj1 = to_union(ctx, obj1);
                obj2 = to_union(ctx, obj2);
        }
@@ -2078,7 +1854,7 @@ error:
 
 static struct isl_obj obj_read(struct isl_stream *s, int nparam)
 {
-       isl_basic_map *bmap = NULL;
+       isl_map *map = NULL;
        struct isl_token *tok;
        struct vars *v = NULL;
        struct isl_obj obj = { isl_obj_set, NULL };
@@ -2107,9 +1883,12 @@ static struct isl_obj obj_read(struct isl_stream *s, int nparam)
                map = map_read_polylib(s, nparam);
                if (!map)
                        goto error;
-               if (isl_map_dim(map, isl_dim_in) > 0)
+               if (isl_map_may_be_set(map))
+                       obj.v = isl_map_range(map);
+               else {
                        obj.type = isl_obj_map;
-               obj.v = map;
+                       obj.v = map;
+               }
                return obj;
        }
        v = vars_new(s->ctx);
@@ -2117,11 +1896,11 @@ static struct isl_obj obj_read(struct isl_stream *s, int nparam)
                isl_stream_push_token(s, tok);
                goto error;
        }
-       bmap = isl_basic_map_alloc(s->ctx, 0, 0, 0, 0, 0, 0);
+       map = isl_map_universe(isl_space_params_alloc(s->ctx, 0));
        if (tok->type == '[') {
                isl_stream_push_token(s, tok);
-               bmap = read_tuple(s, bmap, isl_dim_param, v);
-               if (!bmap)
+               map = read_tuple(s, map, isl_dim_param, v);
+               if (!map)
                        goto error;
                if (nparam >= 0)
                        isl_assert(s->ctx, nparam == v->n, goto error);
@@ -2135,7 +1914,7 @@ static struct isl_obj obj_read(struct isl_stream *s, int nparam)
                isl_token_free(tok);
                tok = isl_stream_next_token(s);
        } else if (nparam > 0)
-               bmap = isl_basic_map_add(bmap, isl_dim_param, nparam);
+               map = isl_map_add_dims(map, isl_dim_param, nparam);
        if (!tok || tok->type != '{') {
                isl_stream_error(s, tok, "expecting '{'");
                if (tok)
@@ -2151,14 +1930,14 @@ static struct isl_obj obj_read(struct isl_stream *s, int nparam)
                isl_token_free(tok);
                if (isl_stream_eat(s, '='))
                        goto error;
-               bmap = read_tuple(s, bmap, isl_dim_param, v);
-               if (!bmap)
+               map = read_tuple(s, map, isl_dim_param, v);
+               if (!map)
                        goto error;
                if (nparam >= 0)
                        isl_assert(s->ctx, nparam == v->n, goto error);
        } else if (tok->type == '}') {
                obj.type = isl_obj_union_set;
-               obj.v = isl_union_set_empty(isl_basic_map_get_dim(bmap));
+               obj.v = isl_union_set_empty(isl_map_get_space(map));
                isl_token_free(tok);
                goto done;
        } else
@@ -2167,7 +1946,7 @@ static struct isl_obj obj_read(struct isl_stream *s, int nparam)
        for (;;) {
                struct isl_obj o;
                tok = NULL;
-               o = obj_read_body(s, isl_basic_map_copy(bmap), v);
+               o = obj_read_body(s, isl_map_copy(map), v);
                if (o.type == isl_obj_none || !o.v)
                        goto error;
                if (!obj.v)
@@ -2197,11 +1976,11 @@ static struct isl_obj obj_read(struct isl_stream *s, int nparam)
        }
 done:
        vars_free(v);
-       isl_basic_map_free(bmap);
+       isl_map_free(map);
 
        return obj;
 error:
-       isl_basic_map_free(bmap);
+       isl_map_free(map);
        obj.type->free(obj.v);
        if (v)
                vars_free(v);
@@ -2234,8 +2013,13 @@ __isl_give isl_set *isl_stream_read_set(struct isl_stream *s, int nparam)
        struct isl_obj obj;
 
        obj = obj_read(s, nparam);
-       if (obj.v)
+       if (obj.v) {
+               if (obj.type == isl_obj_map && isl_map_may_be_set(obj.v)) {
+                       obj.v = isl_map_range(obj.v);
+                       obj.type = isl_obj_set;
+               }
                isl_assert(s->ctx, obj.type == isl_obj_set, goto error);
+       }
 
        return obj.v;
 error:
@@ -2310,6 +2094,22 @@ error:
        return NULL;
 }
 
+static __isl_give isl_basic_set *basic_set_read(struct isl_stream *s,
+       int nparam)
+{
+       isl_basic_map *bmap;
+       bmap = basic_map_read(s, nparam);
+       if (!bmap)
+               return NULL;
+       if (!isl_basic_map_may_be_set(bmap))
+               isl_die(s->ctx, isl_error_invalid,
+                       "input is not a set", goto error);
+       return isl_basic_map_range(bmap);
+error:
+       isl_basic_map_free(bmap);
+       return NULL;
+}
+
 __isl_give isl_basic_map *isl_basic_map_read_from_file(isl_ctx *ctx,
                FILE *input, int nparam)
 {
@@ -2325,15 +2125,13 @@ __isl_give isl_basic_map *isl_basic_map_read_from_file(isl_ctx *ctx,
 __isl_give isl_basic_set *isl_basic_set_read_from_file(isl_ctx *ctx,
                FILE *input, int nparam)
 {
-       struct isl_basic_map *bmap;
-       bmap = isl_basic_map_read_from_file(ctx, input, nparam);
-       if (!bmap)
+       isl_basic_set *bset;
+       struct isl_stream *s = isl_stream_new_file(ctx, input);
+       if (!s)
                return NULL;
-       isl_assert(ctx, isl_basic_map_n_in(bmap) == 0, goto error);
-       return (struct isl_basic_set *)bmap;
-error:
-       isl_basic_map_free(bmap);
-       return NULL;
+       bset = basic_set_read(s, nparam);
+       isl_stream_free(s);
+       return bset;
 }
 
 struct isl_basic_map *isl_basic_map_read_from_str(struct isl_ctx *ctx,
@@ -2351,15 +2149,13 @@ struct isl_basic_map *isl_basic_map_read_from_str(struct isl_ctx *ctx,
 struct isl_basic_set *isl_basic_set_read_from_str(struct isl_ctx *ctx,
                const char *str, int nparam)
 {
-       struct isl_basic_map *bmap;
-       bmap = isl_basic_map_read_from_str(ctx, str, nparam);
-       if (!bmap)
+       isl_basic_set *bset;
+       struct isl_stream *s = isl_stream_new_str(ctx, str);
+       if (!s)
                return NULL;
-       isl_assert(ctx, isl_basic_map_n_in(bmap) == 0, goto error);
-       return (struct isl_basic_set *)bmap;
-error:
-       isl_basic_map_free(bmap);
-       return NULL;
+       bset = basic_set_read(s, nparam);
+       isl_stream_free(s);
+       return bset;
 }
 
 __isl_give isl_map *isl_map_read_from_file(struct isl_ctx *ctx,
@@ -2389,29 +2185,25 @@ __isl_give isl_map *isl_map_read_from_str(struct isl_ctx *ctx,
 __isl_give isl_set *isl_set_read_from_file(struct isl_ctx *ctx,
                FILE *input, int nparam)
 {
-       struct isl_map *map;
-       map = isl_map_read_from_file(ctx, input, nparam);
-       if (!map)
+       isl_set *set;
+       struct isl_stream *s = isl_stream_new_file(ctx, input);
+       if (!s)
                return NULL;
-       isl_assert(ctx, isl_map_n_in(map) == 0, goto error);
-       return (struct isl_set *)map;
-error:
-       isl_map_free(map);
-       return NULL;
+       set = isl_stream_read_set(s, nparam);
+       isl_stream_free(s);
+       return set;
 }
 
 struct isl_set *isl_set_read_from_str(struct isl_ctx *ctx,
                const char *str, int nparam)
 {
-       struct isl_map *map;
-       map = isl_map_read_from_str(ctx, str, nparam);
-       if (!map)
+       isl_set *set;
+       struct isl_stream *s = isl_stream_new_str(ctx, str);
+       if (!s)
                return NULL;
-       isl_assert(ctx, isl_map_n_in(map) == 0, goto error);
-       return (struct isl_set *)map;
-error:
-       isl_map_free(map);
-       return NULL;
+       set = isl_stream_read_set(s, nparam);
+       isl_stream_free(s);
+       return set;
 }
 
 __isl_give isl_union_map *isl_union_map_read_from_file(isl_ctx *ctx,
index ec1dd29..27baab1 100644 (file)
 #include <isl_list_templ.c>
 
 #undef BASE
+#define BASE pw_aff
+
+#include <isl_list_templ.c>
+
+#undef BASE
 #define BASE band
 
 #include <isl_list_templ.c>
index 15c0547..da57f41 100644 (file)
 #include <isl_list_templ.h>
 
 #undef EL
+#define EL isl_pw_aff
+
+#include <isl_list_templ.h>
+
+#undef EL
 #define EL isl_band
 
 #include <isl_list_templ.h>
index 0bf8294..9aa4351 100644 (file)
@@ -85,20 +85,22 @@ error:
        return NULL;
 }
 
-void FN(LIST(EL),free)(__isl_take LIST(EL) *list)
+void *FN(LIST(EL),free)(__isl_take LIST(EL) *list)
 {
        int i;
 
        if (!list)
-               return;
+               return NULL;
 
        if (--list->ref > 0)
-               return;
+               return NULL;
 
        isl_ctx_deref(list->ctx);
        for (i = 0; i < list->n; ++i)
                FN(EL,free)(list->p[i]);
        free(list);
+
+       return NULL;
 }
 
 int FN(FN(LIST(EL),n),BASE)(__isl_keep LIST(EL) *list)
@@ -135,6 +137,50 @@ int FN(LIST(EL),foreach)(__isl_keep LIST(EL) *list,
        return 0;
 }
 
+__isl_give LIST(EL) *FN(FN(LIST(EL),from),BASE)(__isl_take EL *el)
+{
+       isl_ctx *ctx;
+       LIST(EL) *list;
+
+       if (!el)
+               return NULL;
+       ctx = FN(EL,get_ctx)(el);
+       list = FN(LIST(EL),alloc)(ctx, 1);
+       if (!list)
+               goto error;
+       list = FN(LIST(EL),add)(list, el);
+       return list;
+error:
+       FN(EL,free)(el);
+       return NULL;
+}
+
+__isl_give LIST(EL) *FN(LIST(EL),concat)(__isl_take LIST(EL) *list1,
+       __isl_take LIST(EL) *list2)
+{
+       int i;
+       isl_ctx *ctx;
+       LIST(EL) *res;
+
+       if (!list1 || !list2)
+               goto error;
+
+       ctx = FN(LIST(EL),get_ctx)(list1);
+       res = FN(LIST(EL),alloc)(ctx, list1->n + list2->n);
+       for (i = 0; i < list1->n; ++i)
+               res = FN(LIST(EL),add)(res, FN(EL,copy)(list1->p[i]));
+       for (i = 0; i < list2->n; ++i)
+               res = FN(LIST(EL),add)(res, FN(EL,copy)(list2->p[i]));
+
+       FN(LIST(EL),free)(list1);
+       FN(LIST(EL),free)(list2);
+       return res;
+error:
+       FN(LIST(EL),free)(list1);
+       FN(LIST(EL),free)(list2);
+       return NULL;
+}
+
 __isl_give isl_printer *CAT(isl_printer_print_,LIST(BASE))(
        __isl_take isl_printer *p, __isl_keep LIST(EL) *list)
 {
index a959980..9c60f5a 100644 (file)
@@ -20,4 +20,5 @@ __isl_give isl_##EL##_list *isl_##EL##_list_dup(                      \
 ISL_DECLARE_LIST_PRIVATE(basic_set)
 ISL_DECLARE_LIST_PRIVATE(set)
 ISL_DECLARE_LIST_PRIVATE(aff)
+ISL_DECLARE_LIST_PRIVATE(pw_aff)
 ISL_DECLARE_LIST_PRIVATE(band)
index 17ac9ea..26db94a 100644 (file)
@@ -11,7 +11,7 @@
 #include <isl_ctx_private.h>
 #include <isl_map_private.h>
 #include <isl_local_space_private.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl_mat_private.h>
 #include <isl/seq.h>
 
@@ -20,7 +20,7 @@ isl_ctx *isl_local_space_get_ctx(__isl_keep isl_local_space *ls)
        return ls ? ls->dim->ctx : NULL;
 }
 
-__isl_give isl_local_space *isl_local_space_alloc_div(__isl_take isl_dim *dim,
+__isl_give isl_local_space *isl_local_space_alloc_div(__isl_take isl_space *dim,
        __isl_take isl_mat *div)
 {
        isl_ctx *ctx;
@@ -29,7 +29,7 @@ __isl_give isl_local_space *isl_local_space_alloc_div(__isl_take isl_dim *dim,
        if (!dim)
                goto error;
 
-       ctx = isl_dim_get_ctx(dim);
+       ctx = isl_space_get_ctx(dim);
        ls = isl_calloc_type(ctx, struct isl_local_space);
        if (!ls)
                goto error;
@@ -40,12 +40,12 @@ __isl_give isl_local_space *isl_local_space_alloc_div(__isl_take isl_dim *dim,
 
        return ls;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_local_space_free(ls);
        return NULL;
 }
 
-__isl_give isl_local_space *isl_local_space_alloc(__isl_take isl_dim *dim,
+__isl_give isl_local_space *isl_local_space_alloc(__isl_take isl_space *dim,
        unsigned n_div)
 {
        isl_ctx *ctx;
@@ -55,14 +55,14 @@ __isl_give isl_local_space *isl_local_space_alloc(__isl_take isl_dim *dim,
        if (!dim)
                return NULL;
 
-       total = isl_dim_total(dim);
+       total = isl_space_dim(dim, isl_dim_all);
 
-       ctx = isl_dim_get_ctx(dim);
+       ctx = isl_space_get_ctx(dim);
        div = isl_mat_alloc(ctx, n_div, 1 + 1 + total + n_div);
        return isl_local_space_alloc_div(dim, div);
 }
 
-__isl_give isl_local_space *isl_local_space_from_dim(__isl_take isl_dim *dim)
+__isl_give isl_local_space *isl_local_space_from_space(__isl_take isl_space *dim)
 {
        return isl_local_space_alloc(dim, 0);
 }
@@ -81,7 +81,7 @@ __isl_give isl_local_space *isl_local_space_dup(__isl_keep isl_local_space *ls)
        if (!ls)
                return NULL;
 
-       return isl_local_space_alloc_div(isl_dim_copy(ls->dim),
+       return isl_local_space_alloc_div(isl_space_copy(ls->dim),
                                         isl_mat_copy(ls->div));
 
 }
@@ -105,7 +105,7 @@ void *isl_local_space_free(__isl_take isl_local_space *ls)
        if (--ls->ref > 0)
                return NULL;
 
-       isl_dim_free(ls->dim);
+       isl_space_free(ls->dim);
        isl_mat_free(ls->div);
 
        free(ls);
@@ -113,6 +113,13 @@ void *isl_local_space_free(__isl_take isl_local_space *ls)
        return NULL;
 }
 
+/* Is the local space that of a set?
+ */
+int isl_local_space_is_set(__isl_keep isl_local_space *ls)
+{
+       return ls ? isl_space_is_set(ls->dim) : -1;
+}
+
 /* Return true if the two local spaces are identical, with identical
  * expressions for the integer divisions.
  */
@@ -124,7 +131,7 @@ int isl_local_space_is_equal(__isl_keep isl_local_space *ls1,
        if (!ls1 || !ls2)
                return -1;
 
-       equal = isl_dim_equal(ls1->dim, ls2->dim);
+       equal = isl_space_is_equal(ls1->dim, ls2->dim);
        if (equal < 0 || !equal)
                return equal;
 
@@ -144,14 +151,14 @@ int isl_local_space_dim(__isl_keep isl_local_space *ls,
        if (type == isl_dim_div)
                return ls->div->n_row;
        if (type == isl_dim_all)
-               return isl_dim_size(ls->dim, isl_dim_all) + ls->div->n_row;
-       return isl_dim_size(ls->dim, type);
+               return isl_space_dim(ls->dim, isl_dim_all) + ls->div->n_row;
+       return isl_space_dim(ls->dim, type);
 }
 
 unsigned isl_local_space_offset(__isl_keep isl_local_space *ls,
        enum isl_dim_type type)
 {
-       isl_dim *dim;
+       isl_space *dim;
 
        if (!ls)
                return 0;
@@ -170,7 +177,7 @@ unsigned isl_local_space_offset(__isl_keep isl_local_space *ls,
 const char *isl_local_space_get_dim_name(__isl_keep isl_local_space *ls,
        enum isl_dim_type type, unsigned pos)
 {
-       return ls ? isl_dim_get_name(ls->dim, type, pos) : NULL;
+       return ls ? isl_space_get_dim_name(ls->dim, type, pos) : NULL;
 }
 
 __isl_give isl_div *isl_local_space_get_div(__isl_keep isl_local_space *ls,
@@ -193,12 +200,12 @@ __isl_give isl_div *isl_local_space_get_div(__isl_keep isl_local_space *ls,
        return isl_basic_map_div(bmap, pos);
 }
 
-__isl_give isl_dim *isl_local_space_get_dim(__isl_keep isl_local_space *ls)
+__isl_give isl_space *isl_local_space_get_space(__isl_keep isl_local_space *ls)
 {
        if (!ls)
                return NULL;
 
-       return isl_dim_copy(ls->dim);
+       return isl_space_copy(ls->dim);
 }
 
 __isl_give isl_local_space *isl_local_space_set_dim_name(
@@ -208,27 +215,27 @@ __isl_give isl_local_space *isl_local_space_set_dim_name(
        ls = isl_local_space_cow(ls);
        if (!ls)
                return NULL;
-       ls->dim = isl_dim_set_name(ls->dim, type, pos, s);
+       ls->dim = isl_space_set_dim_name(ls->dim, type, pos, s);
        if (!ls->dim)
                return isl_local_space_free(ls);
 
        return ls;
 }
 
-__isl_give isl_local_space *isl_local_space_reset_dim(
-       __isl_take isl_local_space *ls, __isl_take isl_dim *dim)
+__isl_give isl_local_space *isl_local_space_reset_space(
+       __isl_take isl_local_space *ls, __isl_take isl_space *dim)
 {
        ls = isl_local_space_cow(ls);
        if (!ls || !dim)
                goto error;
 
-       isl_dim_free(ls->dim);
+       isl_space_free(ls->dim);
        ls->dim = dim;
 
        return ls;
 error:
        isl_local_space_free(ls);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -246,7 +253,7 @@ static __isl_give isl_mat *reorder_divs(__isl_take isl_mat *div,
        if (!div || !r)
                goto error;
 
-       extra = isl_dim_total(r->dim) + div->n_row - r->len;
+       extra = isl_space_dim(r->dim, isl_dim_all) + div->n_row - r->len;
        mat = isl_mat_alloc(div->ctx, div->n_row, div->n_col + extra);
        if (!mat)
                goto error;
@@ -283,7 +290,7 @@ __isl_give isl_local_space *isl_local_space_realign(
        if (!ls->div)
                goto error;
 
-       ls = isl_local_space_reset_dim(ls, isl_dim_copy(r->dim));
+       ls = isl_local_space_reset_space(ls, isl_space_copy(r->dim));
 
        isl_reordering_free(r);
        return ls;
@@ -440,6 +447,20 @@ int isl_local_space_divs_known(__isl_keep isl_local_space *ls)
        return 1;
 }
 
+__isl_give isl_local_space *isl_local_space_domain(
+       __isl_take isl_local_space *ls)
+{
+       ls = isl_local_space_drop_dims(ls, isl_dim_out,
+                                       0, isl_local_space_dim(ls, isl_dim_out));
+       ls = isl_local_space_cow(ls);
+       if (!ls)
+               return NULL;
+       ls->dim = isl_space_domain(ls->dim);
+       if (!ls->dim)
+               return isl_local_space_free(ls);
+       return ls;
+}
+
 /* Construct a local space for a map that has the given local
  * space as domain and that has a zero-dimensional range.
  */
@@ -449,7 +470,7 @@ __isl_give isl_local_space *isl_local_space_from_domain(
        ls = isl_local_space_cow(ls);
        if (!ls)
                return NULL;
-       ls->dim = isl_dim_from_domain(ls->dim);
+       ls->dim = isl_space_from_domain(ls->dim);
        if (!ls->dim)
                return isl_local_space_free(ls);
        return ls;
@@ -503,7 +524,7 @@ __isl_give isl_local_space *isl_local_space_substitute_equalities(
        if (!ls || !eq)
                goto error;
 
-       total = isl_dim_total(eq->dim);
+       total = isl_space_dim(eq->dim, isl_dim_all);
        if (isl_local_space_dim(ls, isl_dim_all) != total)
                isl_die(isl_local_space_get_ctx(ls), isl_error_invalid,
                        "dimensions don't match", goto error);
@@ -536,7 +557,7 @@ int isl_local_space_is_named_or_nested(__isl_keep isl_local_space *ls,
 {
        if (!ls)
                return -1;
-       return isl_dim_is_named_or_nested(ls->dim, type);
+       return isl_space_is_named_or_nested(ls->dim, type);
 }
 
 __isl_give isl_local_space *isl_local_space_drop_dims(
@@ -562,7 +583,7 @@ __isl_give isl_local_space *isl_local_space_drop_dims(
        if (type == isl_dim_div) {
                ls->div = isl_mat_drop_rows(ls->div, first, n);
        } else {
-               ls->dim = isl_dim_drop(ls->dim, type, first, n);
+               ls->dim = isl_space_drop_dims(ls->dim, type, first, n);
                if (!ls->dim)
                        return isl_local_space_free(ls);
        }
@@ -598,7 +619,7 @@ __isl_give isl_local_space *isl_local_space_insert_dims(
        if (type == isl_dim_div) {
                ls->div = isl_mat_insert_zero_rows(ls->div, first, n);
        } else {
-               ls->dim = isl_dim_insert(ls->dim, type, first, n);
+               ls->dim = isl_space_insert_dims(ls->dim, type, first, n);
                if (!ls->dim)
                        return isl_local_space_free(ls);
        }
@@ -610,3 +631,83 @@ __isl_give isl_local_space *isl_local_space_insert_dims(
 
        return ls;
 }
+
+/* Check if the constraints pointed to by "constraint" is a div
+ * constraint corresponding to div "div" in "ls".
+ *
+ * That is, if div = floor(f/m), then check if the constraint is
+ *
+ *             f - m d >= 0
+ * or
+ *             -(f-(m-1)) + m d >= 0
+ */
+int isl_local_space_is_div_constraint(__isl_keep isl_local_space *ls,
+       isl_int *constraint, unsigned div)
+{
+       unsigned pos;
+
+       if (!ls)
+               return -1;
+
+       if (isl_int_is_zero(ls->div->row[div][0]))
+               return 0;
+
+       pos = isl_local_space_offset(ls, isl_dim_div) + div;
+
+       if (isl_int_eq(constraint[pos], ls->div->row[div][0])) {
+               int neg;
+               isl_int_sub(ls->div->row[div][1],
+                               ls->div->row[div][1], ls->div->row[div][0]);
+               isl_int_add_ui(ls->div->row[div][1], ls->div->row[div][1], 1);
+               neg = isl_seq_is_neg(constraint, ls->div->row[div]+1, pos);
+               isl_int_sub_ui(ls->div->row[div][1], ls->div->row[div][1], 1);
+               isl_int_add(ls->div->row[div][1],
+                               ls->div->row[div][1], ls->div->row[div][0]);
+               if (!neg)
+                       return 0;
+               if (isl_seq_first_non_zero(constraint+pos+1,
+                                           ls->div->n_row-div-1) != -1)
+                       return 0;
+       } else if (isl_int_abs_eq(constraint[pos], ls->div->row[div][0])) {
+               if (!isl_seq_eq(constraint, ls->div->row[div]+1, pos))
+                       return 0;
+               if (isl_seq_first_non_zero(constraint+pos+1,
+                                           ls->div->n_row-div-1) != -1)
+                       return 0;
+       } else
+               return 0;
+
+       return 1;
+}
+
+/*
+ * Set active[i] to 1 if the dimension at position i is involved
+ * in the linear expression l.
+ */
+int *isl_local_space_get_active(__isl_keep isl_local_space *ls, isl_int *l)
+{
+       int i, j;
+       isl_ctx *ctx;
+       int *active = NULL;
+       unsigned total;
+       unsigned offset;
+
+       ctx = isl_local_space_get_ctx(ls);
+       total = isl_local_space_dim(ls, isl_dim_all);
+       active = isl_calloc_array(ctx, int, total);
+       if (!active)
+               return NULL;
+
+       for (i = 0; i < total; ++i)
+               active[i] = !isl_int_is_zero(l[i]);
+
+       offset = isl_local_space_offset(ls, isl_dim_div) - 1;
+       for (i = ls->div->n_row - 1; i >= 0; --i) {
+               if (!active[offset + i])
+                       continue;
+               for (j = 0; j < total; ++j)
+                       active[j] |= !isl_int_is_zero(ls->div->row[i][2 + j]);
+       }
+
+       return active;
+}
index 6f3e93d..85ecfe1 100644 (file)
@@ -9,11 +9,11 @@
 struct isl_local_space {
        int ref;
 
-       isl_dim *dim;
+       isl_space *dim;
        isl_mat *div;
 };
 
-__isl_give isl_local_space *isl_local_space_alloc(__isl_take isl_dim *dim,
+__isl_give isl_local_space *isl_local_space_alloc(__isl_take isl_space *dim,
        unsigned n_div);
 
 __isl_give isl_local_space *isl_local_space_add_div(
@@ -35,9 +35,14 @@ __isl_give isl_local_space *isl_local_space_substitute_equalities(
 int isl_local_space_is_named_or_nested(__isl_keep isl_local_space *ls,
        enum isl_dim_type type);
 
-__isl_give isl_local_space *isl_local_space_reset_dim(
-       __isl_take isl_local_space *ls, __isl_take isl_dim *dim);
+__isl_give isl_local_space *isl_local_space_reset_space(
+       __isl_take isl_local_space *ls, __isl_take isl_space *dim);
 __isl_give isl_local_space *isl_local_space_realign(
        __isl_take isl_local_space *ls, __isl_take isl_reordering *r);
 
+int isl_local_space_is_div_constraint(__isl_keep isl_local_space *ls,
+       isl_int *constraint, unsigned div);
+
+int *isl_local_space_get_active(__isl_keep isl_local_space *ls, isl_int *l);
+
 #endif
index 1673b5b..7ad0939 100644 (file)
--- a/isl_lp.c
+++ b/isl_lp.c
@@ -108,7 +108,7 @@ enum isl_lp_result isl_map_solve_lp(__isl_keep isl_map *map, int max,
                if (map->p[i]->n_div > max_div)
                        max_div = map->p[i]->n_div;
        if (max_div > 0) {
-               unsigned total = isl_dim_total(map->dim);
+               unsigned total = isl_space_dim(map->dim, isl_dim_all);
                v = isl_vec_alloc(map->ctx, 1 + total + max_div);
                if (!v)
                        return isl_lp_error;
index c16f909..f86458c 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -14,7 +14,7 @@
 #include <isl_ctx_private.h>
 #include <isl_map_private.h>
 #include <isl/blk.h>
-#include "isl_dim_private.h"
+#include "isl_space_private.h"
 #include "isl_equalities.h"
 #include <isl_list_private.h>
 #include <isl/lp.h>
@@ -31,7 +31,7 @@
 #include <isl_local_space_private.h>
 #include <isl_aff_private.h>
 
-static unsigned n(struct isl_dim *dim, enum isl_dim_type type)
+static unsigned n(__isl_keep isl_space *dim, enum isl_dim_type type)
 {
        switch (type) {
        case isl_dim_param:     return dim->nparam;
@@ -42,7 +42,7 @@ static unsigned n(struct isl_dim *dim, enum isl_dim_type type)
        }
 }
 
-static unsigned pos(struct isl_dim *dim, enum isl_dim_type type)
+static unsigned pos(__isl_keep isl_space *dim, enum isl_dim_type type)
 {
        switch (type) {
        case isl_dim_param:     return 1;
@@ -52,7 +52,7 @@ static unsigned pos(struct isl_dim *dim, enum isl_dim_type type)
        }
 }
 
-unsigned isl_basic_map_dim(const struct isl_basic_map *bmap,
+unsigned isl_basic_map_dim(__isl_keep isl_basic_map *bmap,
                                enum isl_dim_type type)
 {
        if (!bmap)
@@ -61,19 +61,19 @@ unsigned isl_basic_map_dim(const struct isl_basic_map *bmap,
        case isl_dim_cst:       return 1;
        case isl_dim_param:
        case isl_dim_in:
-       case isl_dim_out:       return isl_dim_size(bmap->dim, type);
+       case isl_dim_out:       return isl_space_dim(bmap->dim, type);
        case isl_dim_div:       return bmap->n_div;
        case isl_dim_all:       return isl_basic_map_total_dim(bmap);
        default:                return 0;
        }
 }
 
-unsigned isl_map_dim(const struct isl_map *map, enum isl_dim_type type)
+unsigned isl_map_dim(__isl_keep isl_map *map, enum isl_dim_type type)
 {
        return map ? n(map->dim, type) : 0;
 }
 
-unsigned isl_set_dim(const struct isl_set *set, enum isl_dim_type type)
+unsigned isl_set_dim(__isl_keep isl_set *set, enum isl_dim_type type)
 {
        return set ? n(set->dim, type) : 0;
 }
@@ -81,7 +81,7 @@ unsigned isl_set_dim(const struct isl_set *set, enum isl_dim_type type)
 unsigned isl_basic_map_offset(struct isl_basic_map *bmap,
                                        enum isl_dim_type type)
 {
-       struct isl_dim *dim = bmap->dim;
+       isl_space *dim = bmap->dim;
        switch (type) {
        case isl_dim_cst:       return 0;
        case isl_dim_param:     return 1;
@@ -103,33 +103,33 @@ static unsigned map_offset(struct isl_map *map, enum isl_dim_type type)
        return pos(map->dim, type);
 }
 
-unsigned isl_basic_set_dim(const struct isl_basic_set *bset,
+unsigned isl_basic_set_dim(__isl_keep isl_basic_set *bset,
                                enum isl_dim_type type)
 {
-       return isl_basic_map_dim((const struct isl_basic_map*)bset, type);
+       return isl_basic_map_dim(bset, type);
 }
 
-unsigned isl_basic_set_n_dim(const struct isl_basic_set *bset)
+unsigned isl_basic_set_n_dim(__isl_keep isl_basic_set *bset)
 {
        return isl_basic_set_dim(bset, isl_dim_set);
 }
 
-unsigned isl_basic_set_n_param(const struct isl_basic_set *bset)
+unsigned isl_basic_set_n_param(__isl_keep isl_basic_set *bset)
 {
        return isl_basic_set_dim(bset, isl_dim_param);
 }
 
 unsigned isl_basic_set_total_dim(const struct isl_basic_set *bset)
 {
-       return isl_dim_total(bset->dim) + bset->n_div;
+       return isl_space_dim(bset->dim, isl_dim_all) + bset->n_div;
 }
 
-unsigned isl_set_n_dim(const struct isl_set *set)
+unsigned isl_set_n_dim(__isl_keep isl_set *set)
 {
        return isl_set_dim(set, isl_dim_set);
 }
 
-unsigned isl_set_n_param(const struct isl_set *set)
+unsigned isl_set_n_param(__isl_keep isl_set *set)
 {
        return isl_set_dim(set, isl_dim_param);
 }
@@ -156,7 +156,7 @@ unsigned isl_basic_map_n_div(const struct isl_basic_map *bmap)
 
 unsigned isl_basic_map_total_dim(const struct isl_basic_map *bmap)
 {
-       return bmap ? isl_dim_total(bmap->dim) + bmap->n_div : 0;
+       return bmap ? isl_space_dim(bmap->dim, isl_dim_all) + bmap->n_div : 0;
 }
 
 unsigned isl_map_n_in(const struct isl_map *map)
@@ -179,10 +179,10 @@ int isl_map_compatible_domain(struct isl_map *map, struct isl_set *set)
        int m;
        if (!map || !set)
                return -1;
-       m = isl_dim_match(map->dim, isl_dim_param, set->dim, isl_dim_param);
+       m = isl_space_match(map->dim, isl_dim_param, set->dim, isl_dim_param);
        if (m < 0 || !m)
                return m;
-       return isl_dim_tuple_match(map->dim, isl_dim_in, set->dim, isl_dim_set);
+       return isl_space_tuple_match(map->dim, isl_dim_in, set->dim, isl_dim_set);
 }
 
 int isl_basic_map_compatible_domain(struct isl_basic_map *bmap,
@@ -191,10 +191,10 @@ int isl_basic_map_compatible_domain(struct isl_basic_map *bmap,
        int m;
        if (!bmap || !bset)
                return -1;
-       m = isl_dim_match(bmap->dim, isl_dim_param, bset->dim, isl_dim_param);
+       m = isl_space_match(bmap->dim, isl_dim_param, bset->dim, isl_dim_param);
        if (m < 0 || !m)
                return m;
-       return isl_dim_tuple_match(bmap->dim, isl_dim_in, bset->dim, isl_dim_set);
+       return isl_space_tuple_match(bmap->dim, isl_dim_in, bset->dim, isl_dim_set);
 }
 
 int isl_map_compatible_range(__isl_keep isl_map *map, __isl_keep isl_set *set)
@@ -202,10 +202,10 @@ int isl_map_compatible_range(__isl_keep isl_map *map, __isl_keep isl_set *set)
        int m;
        if (!map || !set)
                return -1;
-       m = isl_dim_match(map->dim, isl_dim_param, set->dim, isl_dim_param);
+       m = isl_space_match(map->dim, isl_dim_param, set->dim, isl_dim_param);
        if (m < 0 || !m)
                return m;
-       return isl_dim_tuple_match(map->dim, isl_dim_out, set->dim, isl_dim_set);
+       return isl_space_tuple_match(map->dim, isl_dim_out, set->dim, isl_dim_set);
 }
 
 int isl_basic_map_compatible_range(struct isl_basic_map *bmap,
@@ -214,10 +214,10 @@ int isl_basic_map_compatible_range(struct isl_basic_map *bmap,
        int m;
        if (!bmap || !bset)
                return -1;
-       m = isl_dim_match(bmap->dim, isl_dim_param, bset->dim, isl_dim_param);
+       m = isl_space_match(bmap->dim, isl_dim_param, bset->dim, isl_dim_param);
        if (m < 0 || !m)
                return m;
-       return isl_dim_tuple_match(bmap->dim, isl_dim_out, bset->dim, isl_dim_set);
+       return isl_space_tuple_match(bmap->dim, isl_dim_out, bset->dim, isl_dim_set);
 }
 
 isl_ctx *isl_basic_map_get_ctx(__isl_keep isl_basic_map *bmap)
@@ -240,18 +240,18 @@ isl_ctx *isl_set_get_ctx(__isl_keep isl_set *set)
        return set ? set->ctx : NULL;
 }
 
-struct isl_dim *isl_basic_map_get_dim(struct isl_basic_map *bmap)
+__isl_give isl_space *isl_basic_map_get_space(__isl_keep isl_basic_map *bmap)
 {
        if (!bmap)
                return NULL;
-       return isl_dim_copy(bmap->dim);
+       return isl_space_copy(bmap->dim);
 }
 
-struct isl_dim *isl_basic_set_get_dim(struct isl_basic_set *bset)
+__isl_give isl_space *isl_basic_set_get_space(__isl_keep isl_basic_set *bset)
 {
        if (!bset)
                return NULL;
-       return isl_dim_copy(bset->dim);
+       return isl_space_copy(bset->dim);
 }
 
 __isl_give isl_local_space *isl_basic_map_get_local_space(
@@ -265,7 +265,7 @@ __isl_give isl_local_space *isl_basic_map_get_local_space(
                return NULL;
 
        total = isl_basic_map_total_dim(bmap);
-       ls = isl_local_space_alloc(isl_dim_copy(bmap->dim), bmap->n_div);
+       ls = isl_local_space_alloc(isl_space_copy(bmap->dim), bmap->n_div);
        if (!ls)
                return NULL;
 
@@ -292,7 +292,7 @@ __isl_give isl_basic_map *isl_basic_map_from_local_space(
                return NULL;
 
        n_div = isl_local_space_dim(ls, isl_dim_div);
-       bmap = isl_basic_map_alloc_dim(isl_local_space_get_dim(ls),
+       bmap = isl_basic_map_alloc_space(isl_local_space_get_space(ls),
                                        n_div, 0, 2 * n_div);
 
        for (i = 0; i < n_div; ++i)
@@ -319,18 +319,18 @@ __isl_give isl_basic_set *isl_basic_set_from_local_space(
        return isl_basic_map_from_local_space(ls);
 }
 
-struct isl_dim *isl_map_get_dim(struct isl_map *map)
+__isl_give isl_space *isl_map_get_space(__isl_keep isl_map *map)
 {
        if (!map)
                return NULL;
-       return isl_dim_copy(map->dim);
+       return isl_space_copy(map->dim);
 }
 
-struct isl_dim *isl_set_get_dim(struct isl_set *set)
+__isl_give isl_space *isl_set_get_space(__isl_keep isl_set *set)
 {
        if (!set)
                return NULL;
-       return isl_dim_copy(set->dim);
+       return isl_space_copy(set->dim);
 }
 
 __isl_give isl_basic_map *isl_basic_map_set_tuple_name(
@@ -339,7 +339,7 @@ __isl_give isl_basic_map *isl_basic_map_set_tuple_name(
        bmap = isl_basic_map_cow(bmap);
        if (!bmap)
                return NULL;
-       bmap->dim = isl_dim_set_tuple_name(bmap->dim, type, s);
+       bmap->dim = isl_space_set_tuple_name(bmap->dim, type, s);
        if (!bmap->dim)
                goto error;
        bmap = isl_basic_map_finalize(bmap);
@@ -358,7 +358,7 @@ __isl_give isl_basic_set *isl_basic_set_set_tuple_name(
 const char *isl_basic_map_get_tuple_name(__isl_keep isl_basic_map *bmap,
        enum isl_dim_type type)
 {
-       return bmap ? isl_dim_get_tuple_name(bmap->dim, type) : NULL;
+       return bmap ? isl_space_get_tuple_name(bmap->dim, type) : NULL;
 }
 
 __isl_give isl_map *isl_map_set_tuple_name(__isl_take isl_map *map,
@@ -370,7 +370,7 @@ __isl_give isl_map *isl_map_set_tuple_name(__isl_take isl_map *map,
        if (!map)
                return NULL;
 
-       map->dim = isl_dim_set_tuple_name(map->dim, type, s);
+       map->dim = isl_space_set_tuple_name(map->dim, type, s);
        if (!map->dim)
                goto error;
 
@@ -389,7 +389,7 @@ error:
 const char *isl_map_get_tuple_name(__isl_keep isl_map *map,
        enum isl_dim_type type)
 {
-       return map ? isl_dim_get_tuple_name(map->dim, type) : NULL;
+       return map ? isl_space_get_tuple_name(map->dim, type) : NULL;
 }
 
 __isl_give isl_set *isl_set_set_tuple_name(__isl_take isl_set *set,
@@ -398,38 +398,94 @@ __isl_give isl_set *isl_set_set_tuple_name(__isl_take isl_set *set,
        return (isl_set *)isl_map_set_tuple_name((isl_map *)set, isl_dim_set, s);
 }
 
+__isl_give isl_map *isl_map_set_tuple_id(__isl_take isl_map *map,
+       enum isl_dim_type type, __isl_take isl_id *id)
+{
+       map = isl_map_cow(map);
+       if (!map)
+               return isl_id_free(id);
+
+       map->dim = isl_space_set_tuple_id(map->dim, type, id);
+
+       return isl_map_reset_space(map, isl_space_copy(map->dim));
+}
+
+__isl_give isl_set *isl_set_set_tuple_id(__isl_take isl_set *set,
+       __isl_take isl_id *id)
+{
+       return isl_map_set_tuple_id(set, isl_dim_set, id);
+}
+
+__isl_give isl_map *isl_map_reset_tuple_id(__isl_take isl_map *map,
+       enum isl_dim_type type)
+{
+       map = isl_map_cow(map);
+       if (!map)
+               return NULL;
+
+       map->dim = isl_space_reset_tuple_id(map->dim, type);
+
+       return isl_map_reset_space(map, isl_space_copy(map->dim));
+}
+
+__isl_give isl_set *isl_set_reset_tuple_id(__isl_take isl_set *set)
+{
+       return isl_map_reset_tuple_id(set, isl_dim_set);
+}
+
+int isl_map_has_tuple_id(__isl_keep isl_map *map, enum isl_dim_type type)
+{
+       return map ? isl_space_has_tuple_id(map->dim, type) : -1;
+}
+
+__isl_give isl_id *isl_map_get_tuple_id(__isl_keep isl_map *map,
+       enum isl_dim_type type)
+{
+       return map ? isl_space_get_tuple_id(map->dim, type) : NULL;
+}
+
+int isl_set_has_tuple_id(__isl_keep isl_set *set)
+{
+       return isl_map_has_tuple_id(set, isl_dim_set);
+}
+
+__isl_give isl_id *isl_set_get_tuple_id(__isl_keep isl_set *set)
+{
+       return isl_map_get_tuple_id(set, isl_dim_set);
+}
+
 const char *isl_basic_set_get_tuple_name(__isl_keep isl_basic_set *bset)
 {
-       return bset ? isl_dim_get_tuple_name(bset->dim, isl_dim_set) : NULL;
+       return bset ? isl_space_get_tuple_name(bset->dim, isl_dim_set) : NULL;
 }
 
 const char *isl_set_get_tuple_name(__isl_keep isl_set *set)
 {
-       return set ? isl_dim_get_tuple_name(set->dim, isl_dim_set) : NULL;
+       return set ? isl_space_get_tuple_name(set->dim, isl_dim_set) : NULL;
 }
 
 const char *isl_basic_map_get_dim_name(__isl_keep isl_basic_map *bmap,
        enum isl_dim_type type, unsigned pos)
 {
-       return bmap ? isl_dim_get_name(bmap->dim, type, pos) : NULL;
+       return bmap ? isl_space_get_dim_name(bmap->dim, type, pos) : NULL;
 }
 
 const char *isl_basic_set_get_dim_name(__isl_keep isl_basic_set *bset,
        enum isl_dim_type type, unsigned pos)
 {
-       return bset ? isl_dim_get_name(bset->dim, type, pos) : NULL;
+       return bset ? isl_space_get_dim_name(bset->dim, type, pos) : NULL;
 }
 
 const char *isl_map_get_dim_name(__isl_keep isl_map *map,
        enum isl_dim_type type, unsigned pos)
 {
-       return map ? isl_dim_get_name(map->dim, type, pos) : NULL;
+       return map ? isl_space_get_dim_name(map->dim, type, pos) : NULL;
 }
 
 const char *isl_set_get_dim_name(__isl_keep isl_set *set,
        enum isl_dim_type type, unsigned pos)
 {
-       return set ? isl_dim_get_name(set->dim, type, pos) : NULL;
+       return set ? isl_space_get_dim_name(set->dim, type, pos) : NULL;
 }
 
 __isl_give isl_basic_map *isl_basic_map_set_dim_name(
@@ -438,7 +494,7 @@ __isl_give isl_basic_map *isl_basic_map_set_dim_name(
 {
        if (!bmap)
                return NULL;
-       bmap->dim = isl_dim_set_name(bmap->dim, type, pos, s);
+       bmap->dim = isl_space_set_dim_name(bmap->dim, type, pos, s);
        if (!bmap->dim)
                goto error;
        return bmap;
@@ -455,7 +511,7 @@ __isl_give isl_map *isl_map_set_dim_name(__isl_take isl_map *map,
        if (!map)
                return NULL;
 
-       map->dim = isl_dim_set_name(map->dim, type, pos, s);
+       map->dim = isl_space_set_dim_name(map->dim, type, pos, s);
        if (!map->dim)
                goto error;
 
@@ -485,6 +541,62 @@ __isl_give isl_set *isl_set_set_dim_name(__isl_take isl_set *set,
        return (isl_set *)isl_map_set_dim_name((isl_map *)set, type, pos, s);
 }
 
+int isl_map_has_dim_id(__isl_keep isl_map *map,
+       enum isl_dim_type type, unsigned pos)
+{
+       return map ? isl_space_has_dim_id(map->dim, type, pos) : -1;
+}
+
+__isl_give isl_id *isl_map_get_dim_id(__isl_keep isl_map *map,
+       enum isl_dim_type type, unsigned pos)
+{
+       return map ? isl_space_get_dim_id(map->dim, type, pos) : NULL;
+}
+
+int isl_set_has_dim_id(__isl_keep isl_set *set,
+       enum isl_dim_type type, unsigned pos)
+{
+       return isl_map_has_dim_id(set, type, pos);
+}
+
+__isl_give isl_id *isl_set_get_dim_id(__isl_keep isl_set *set,
+       enum isl_dim_type type, unsigned pos)
+{
+       return isl_map_get_dim_id(set, type, pos);
+}
+
+__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)
+{
+       map = isl_map_cow(map);
+       if (!map)
+               return isl_id_free(id);
+
+       map->dim = isl_space_set_dim_id(map->dim, type, pos, id);
+
+       return isl_map_reset_space(map, isl_space_copy(map->dim));
+}
+
+__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)
+{
+       return isl_map_set_dim_id(set, type, pos, id);
+}
+
+int isl_map_find_dim_by_id(__isl_keep isl_map *map, enum isl_dim_type type,
+       __isl_keep isl_id *id)
+{
+       if (!map)
+               return -1;
+       return isl_space_find_dim_by_id(map->dim, type, id);
+}
+
+int isl_set_find_dim_by_id(__isl_keep isl_set *set, enum isl_dim_type type,
+       __isl_keep isl_id *id)
+{
+       return isl_map_find_dim_by_id(set, type, id);
+}
+
 int isl_basic_map_is_rational(__isl_keep isl_basic_map *bmap)
 {
        if (!bmap)
@@ -497,12 +609,30 @@ int isl_basic_set_is_rational(__isl_keep isl_basic_set *bset)
        return isl_basic_map_is_rational(bset);
 }
 
+/* Is this basic set a parameter domain?
+ */
+int isl_basic_set_is_params(__isl_keep isl_basic_set *bset)
+{
+       if (!bset)
+               return -1;
+       return isl_space_is_params(bset->dim);
+}
+
+/* Is this set a parameter domain?
+ */
+int isl_set_is_params(__isl_keep isl_set *set)
+{
+       if (!set)
+               return -1;
+       return isl_space_is_params(set->dim);
+}
+
 static struct isl_basic_map *basic_map_init(struct isl_ctx *ctx,
                struct isl_basic_map *bmap, unsigned extra,
                unsigned n_eq, unsigned n_ineq)
 {
        int i;
-       size_t row_size = 1 + isl_dim_total(bmap->dim) + extra;
+       size_t row_size = 1 + isl_space_dim(bmap->dim, isl_dim_all) + extra;
 
        bmap->ctx = ctx;
        isl_ctx_ref(ctx);
@@ -555,25 +685,31 @@ struct isl_basic_set *isl_basic_set_alloc(struct isl_ctx *ctx,
                unsigned n_eq, unsigned n_ineq)
 {
        struct isl_basic_map *bmap;
-       bmap = isl_basic_map_alloc(ctx, nparam, 0, dim, extra, n_eq, n_ineq);
+       isl_space *space;
+
+       space = isl_space_set_alloc(ctx, nparam, dim);
+       if (!space)
+               return NULL;
+
+       bmap = isl_basic_map_alloc_space(space, extra, n_eq, n_ineq);
        return (struct isl_basic_set *)bmap;
 }
 
-struct isl_basic_set *isl_basic_set_alloc_dim(struct isl_dim *dim,
+struct isl_basic_set *isl_basic_set_alloc_space(__isl_take isl_space *dim,
                unsigned extra, unsigned n_eq, unsigned n_ineq)
 {
        struct isl_basic_map *bmap;
        if (!dim)
                return NULL;
        isl_assert(dim->ctx, dim->n_in == 0, goto error);
-       bmap = isl_basic_map_alloc_dim(dim, extra, n_eq, n_ineq);
+       bmap = isl_basic_map_alloc_space(dim, extra, n_eq, n_ineq);
        return (struct isl_basic_set *)bmap;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
-struct isl_basic_map *isl_basic_map_alloc_dim(struct isl_dim *dim,
+struct isl_basic_map *isl_basic_map_alloc_space(__isl_take isl_space *dim,
                unsigned extra, unsigned n_eq, unsigned n_ineq)
 {
        struct isl_basic_map *bmap;
@@ -587,7 +723,7 @@ struct isl_basic_map *isl_basic_map_alloc_dim(struct isl_dim *dim,
 
        return basic_map_init(dim->ctx, bmap, extra, n_eq, n_ineq);
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -596,13 +732,13 @@ struct isl_basic_map *isl_basic_map_alloc(struct isl_ctx *ctx,
                unsigned n_eq, unsigned n_ineq)
 {
        struct isl_basic_map *bmap;
-       struct isl_dim *dim;
+       isl_space *dim;
 
-       dim = isl_dim_alloc(ctx, nparam, in, out);
+       dim = isl_space_alloc(ctx, nparam, in, out);
        if (!dim)
                return NULL;
 
-       bmap = isl_basic_map_alloc_dim(dim, extra, n_eq, n_ineq);
+       bmap = isl_basic_map_alloc_space(dim, extra, n_eq, n_ineq);
        return bmap;
 }
 
@@ -635,7 +771,7 @@ struct isl_basic_map *isl_basic_map_dup(struct isl_basic_map *bmap)
 
        if (!bmap)
                return NULL;
-       dup = isl_basic_map_alloc_dim(isl_dim_copy(bmap->dim),
+       dup = isl_basic_map_alloc_space(isl_space_copy(bmap->dim),
                        bmap->n_div, bmap->n_eq, bmap->n_ineq);
        if (!dup)
                return NULL;
@@ -712,7 +848,7 @@ void isl_basic_map_free(struct isl_basic_map *bmap)
        free(bmap->ineq);
        isl_blk_free(bmap->ctx, bmap->block);
        isl_vec_free(bmap->sample);
-       isl_dim_free(bmap->dim);
+       isl_space_free(bmap->dim);
        free(bmap);
 }
 
@@ -726,6 +862,52 @@ static int room_for_con(struct isl_basic_map *bmap, unsigned n)
        return bmap->n_eq + bmap->n_ineq + n <= bmap->c_size;
 }
 
+__isl_give isl_map *isl_map_align_params_map_map_and(
+       __isl_take isl_map *map1, __isl_take isl_map *map2,
+       __isl_give isl_map *(*fn)(__isl_take isl_map *map1,
+                                   __isl_take isl_map *map2))
+{
+       if (!map1 || !map2)
+               goto error;
+       if (isl_space_match(map1->dim, isl_dim_param, map2->dim, isl_dim_param))
+               return fn(map1, map2);
+       if (!isl_space_has_named_params(map1->dim) ||
+           !isl_space_has_named_params(map2->dim))
+               isl_die(map1->ctx, isl_error_invalid,
+                       "unaligned unnamed parameters", goto error);
+       map1 = isl_map_align_params(map1, isl_map_get_space(map2));
+       map2 = isl_map_align_params(map2, isl_map_get_space(map1));
+       return fn(map1, map2);
+error:
+       isl_map_free(map1);
+       isl_map_free(map2);
+       return NULL;
+}
+
+static int align_params_map_map_and_test(__isl_keep isl_map *map1,
+       __isl_keep isl_map *map2,
+       int (*fn)(__isl_keep isl_map *map1, __isl_keep isl_map *map2))
+{
+       int r;
+
+       if (!map1 || !map2)
+               return -1;
+       if (isl_space_match(map1->dim, isl_dim_param, map2->dim, isl_dim_param))
+               return fn(map1, map2);
+       if (!isl_space_has_named_params(map1->dim) ||
+           !isl_space_has_named_params(map2->dim))
+               isl_die(map1->ctx, isl_error_invalid,
+                       "unaligned unnamed parameters", return -1);
+       map1 = isl_map_copy(map1);
+       map2 = isl_map_copy(map2);
+       map1 = isl_map_align_params(map1, isl_map_get_space(map2));
+       map2 = isl_map_align_params(map2, isl_map_get_space(map1));
+       r = fn(map1, map2);
+       isl_map_free(map1);
+       isl_map_free(map2);
+       return r;
+}
+
 int isl_basic_map_alloc_equality(struct isl_basic_map *bmap)
 {
        struct isl_ctx *ctx;
@@ -1066,8 +1248,8 @@ struct isl_basic_set *isl_basic_set_add_constraints(struct isl_basic_set *bset1,
                                (struct isl_basic_map *)bset2, 0, pos);
 }
 
-struct isl_basic_map *isl_basic_map_extend_dim(struct isl_basic_map *base,
-               struct isl_dim *dim, unsigned extra,
+struct isl_basic_map *isl_basic_map_extend_space(struct isl_basic_map *base,
+               __isl_take isl_space *dim, unsigned extra,
                unsigned n_eq, unsigned n_ineq)
 {
        struct isl_basic_map *ext;
@@ -1080,12 +1262,12 @@ struct isl_basic_map *isl_basic_map_extend_dim(struct isl_basic_map *base,
        if (!base)
                goto error;
 
-       dims_ok = isl_dim_equal(base->dim, dim) &&
+       dims_ok = isl_space_is_equal(base->dim, dim) &&
                  base->extra >= base->n_div + extra;
 
        if (dims_ok && room_for_con(base, n_eq + n_ineq) &&
                       room_for_ineq(base, n_ineq)) {
-               isl_dim_free(dim);
+               isl_space_free(dim);
                return base;
        }
 
@@ -1096,7 +1278,7 @@ struct isl_basic_map *isl_basic_map_extend_dim(struct isl_basic_map *base,
        n_eq += base->n_eq;
        n_ineq += base->n_ineq;
 
-       ext = isl_basic_map_alloc_dim(dim, extra, n_eq, n_ineq);
+       ext = isl_basic_map_alloc_space(dim, extra, n_eq, n_ineq);
        dim = NULL;
        if (!ext)
                goto error;
@@ -1113,17 +1295,17 @@ struct isl_basic_map *isl_basic_map_extend_dim(struct isl_basic_map *base,
        return ext;
 
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_basic_map_free(base);
        return NULL;
 }
 
-struct isl_basic_set *isl_basic_set_extend_dim(struct isl_basic_set *base,
-               struct isl_dim *dim, unsigned extra,
+struct isl_basic_set *isl_basic_set_extend_space(struct isl_basic_set *base,
+               __isl_take isl_space *dim, unsigned extra,
                unsigned n_eq, unsigned n_ineq)
 {
        return (struct isl_basic_set *)
-               isl_basic_map_extend_dim((struct isl_basic_map *)base, dim,
+               isl_basic_map_extend_space((struct isl_basic_map *)base, dim,
                                                        extra, n_eq, n_ineq);
 }
 
@@ -1132,7 +1314,7 @@ struct isl_basic_map *isl_basic_map_extend_constraints(
 {
        if (!base)
                return NULL;
-       return isl_basic_map_extend_dim(base, isl_dim_copy(base->dim),
+       return isl_basic_map_extend_space(base, isl_space_copy(base->dim),
                                        0, n_eq, n_ineq);
 }
 
@@ -1141,15 +1323,15 @@ struct isl_basic_map *isl_basic_map_extend(struct isl_basic_map *base,
                unsigned n_eq, unsigned n_ineq)
 {
        struct isl_basic_map *bmap;
-       struct isl_dim *dim;
+       isl_space *dim;
 
        if (!base)
                return NULL;
-       dim = isl_dim_alloc(base->ctx, nparam, n_in, n_out);
+       dim = isl_space_alloc(base->ctx, nparam, n_in, n_out);
        if (!dim)
                goto error;
 
-       bmap = isl_basic_map_extend_dim(base, dim, extra, n_eq, n_ineq);
+       bmap = isl_basic_map_extend_space(base, dim, extra, n_eq, n_ineq);
        return bmap;
 error:
        isl_basic_map_free(base);
@@ -1320,7 +1502,7 @@ struct isl_basic_set *isl_basic_set_set_to_empty(struct isl_basic_set *bset)
 void isl_basic_map_swap_div(struct isl_basic_map *bmap, int a, int b)
 {
        int i;
-       unsigned off = isl_dim_total(bmap->dim);
+       unsigned off = isl_space_dim(bmap->dim, isl_dim_all);
        isl_int *t = bmap->div[a];
        bmap->div[a] = bmap->div[b];
        bmap->div[b] = t;
@@ -1392,8 +1574,8 @@ __isl_give isl_basic_map *isl_basic_map_remove_divs(
 {
        if (!bmap)
                return NULL;
-       bmap = isl_basic_map_eliminate_vars(bmap, isl_dim_total(bmap->dim),
-                                               bmap->n_div);
+       bmap = isl_basic_map_eliminate_vars(bmap,
+                           isl_space_dim(bmap->dim, isl_dim_all), bmap->n_div);
        if (!bmap)
                return NULL;
        bmap->n_div = 0;
@@ -1443,7 +1625,7 @@ struct isl_basic_map *isl_basic_map_remove_dims(struct isl_basic_map *bmap,
                return NULL;
        isl_assert(bmap->ctx, first + n <= isl_basic_map_dim(bmap, type),
                        goto error);
-       if (n == 0 && !isl_dim_is_named_or_nested(bmap->dim, type))
+       if (n == 0 && !isl_space_is_named_or_nested(bmap->dim, type))
                return bmap;
        bmap = isl_basic_map_eliminate_vars(bmap,
                        isl_basic_map_offset(bmap, type) - 1 + first, n);
@@ -1545,43 +1727,43 @@ __isl_give isl_set *isl_set_remove_divs_involving_dims(__isl_take isl_set *set,
                                                              type, first, n);
 }
 
-int isl_basic_set_involves_dims(__isl_keep isl_basic_set *bset,
+int isl_basic_map_involves_dims(__isl_keep isl_basic_map *bmap,
        enum isl_dim_type type, unsigned first, unsigned n)
 {
        int i;
 
-       if (!bset)
+       if (!bmap)
                return -1;
 
-       if (first + n > isl_basic_set_dim(bset, type))
-               isl_die(bset->ctx, isl_error_invalid,
+       if (first + n > isl_basic_map_dim(bmap, type))
+               isl_die(bmap->ctx, isl_error_invalid,
                        "index out of bounds", return -1);
 
-       first += isl_basic_set_offset(bset, type);
-       for (i = 0; i < bset->n_eq; ++i)
-               if (isl_seq_first_non_zero(bset->eq[i] + first, n) >= 0)
+       first += isl_basic_map_offset(bmap, type);
+       for (i = 0; i < bmap->n_eq; ++i)
+               if (isl_seq_first_non_zero(bmap->eq[i] + first, n) >= 0)
                        return 1;
-       for (i = 0; i < bset->n_ineq; ++i)
-               if (isl_seq_first_non_zero(bset->ineq[i] + first, n) >= 0)
+       for (i = 0; i < bmap->n_ineq; ++i)
+               if (isl_seq_first_non_zero(bmap->ineq[i] + first, n) >= 0)
                        return 1;
 
        return 0;
 }
 
-int isl_set_involves_dims(__isl_keep isl_set *set,
+int isl_map_involves_dims(__isl_keep isl_map *map,
        enum isl_dim_type type, unsigned first, unsigned n)
 {
        int i;
 
-       if (!set)
+       if (!map)
                return -1;
 
-       if (first + n > isl_set_dim(set, type))
-               isl_die(set->ctx, isl_error_invalid,
+       if (first + n > isl_map_dim(map, type))
+               isl_die(map->ctx, isl_error_invalid,
                        "index out of bounds", return -1);
 
-       for (i = 0; i < set->n; ++i) {
-               int involves = isl_basic_set_involves_dims(set->p[i],
+       for (i = 0; i < map->n; ++i) {
+               int involves = isl_basic_map_involves_dims(map->p[i],
                                                            type, first, n);
                if (involves < 0 || !involves)
                        return involves;
@@ -1590,6 +1772,18 @@ int isl_set_involves_dims(__isl_keep isl_set *set,
        return 1;
 }
 
+int isl_basic_set_involves_dims(__isl_keep isl_basic_set *bset,
+       enum isl_dim_type type, unsigned first, unsigned n)
+{
+       return isl_basic_map_involves_dims(bset, type, first, n);
+}
+
+int isl_set_involves_dims(__isl_keep isl_set *set,
+       enum isl_dim_type type, unsigned first, unsigned n)
+{
+       return isl_map_involves_dims(set, type, first, n);
+}
+
 /* Return true if the definition of the given div is unknown or depends
  * on unknown divs.
  */
@@ -1719,7 +1913,7 @@ static void dump_term(struct isl_basic_map *bmap,
                if (!isl_int_is_one(c))
                        isl_int_print(out, c, 0);
                if (pos < 1 + nparam) {
-                       name = isl_dim_get_name(bmap->dim,
+                       name = isl_space_get_dim_name(bmap->dim,
                                                isl_dim_param, pos - 1);
                        if (name)
                                fprintf(out, "%s", name);
@@ -1771,7 +1965,7 @@ static void dump_constraint(struct isl_basic_map *bmap, isl_int *c,
        fprintf(out, "\n");
 
        for (i = bmap->n_div; i < bmap->extra; ++i) {
-               if (isl_int_is_zero(c[1+isl_dim_total(bmap->dim)+i]))
+               if (isl_int_is_zero(c[1+isl_space_dim(bmap->dim, isl_dim_all)+i]))
                        continue;
                fprintf(out, "%*s", indent, "");
                fprintf(out, "ERROR: unused div coefficient not zero\n");
@@ -1850,7 +2044,7 @@ void isl_basic_map_print_internal(struct isl_basic_map *bmap,
                        "flags: %x, n_name: %d\n",
                bmap->ref,
                bmap->dim->nparam, bmap->dim->n_in, bmap->dim->n_out,
-               bmap->extra, bmap->flags, bmap->dim->n_name);
+               bmap->extra, bmap->flags, bmap->dim->n_id);
        dump(bmap, out, indent);
 }
 
@@ -1867,7 +2061,8 @@ int isl_inequality_negate(struct isl_basic_map *bmap, unsigned pos)
        return 0;
 }
 
-struct isl_set *isl_set_alloc_dim(struct isl_dim *dim, int n, unsigned flags)
+__isl_give isl_set *isl_set_alloc_space(__isl_take isl_space *dim, int n,
+       unsigned flags)
 {
        struct isl_set *set;
 
@@ -1890,7 +2085,7 @@ struct isl_set *isl_set_alloc_dim(struct isl_dim *dim, int n, unsigned flags)
        set->flags = flags;
        return set;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -1898,13 +2093,13 @@ struct isl_set *isl_set_alloc(struct isl_ctx *ctx,
                unsigned nparam, unsigned dim, int n, unsigned flags)
 {
        struct isl_set *set;
-       struct isl_dim *dims;
+       isl_space *dims;
 
-       dims = isl_dim_alloc(ctx, nparam, 0, dim);
+       dims = isl_space_alloc(ctx, nparam, 0, dim);
        if (!dims)
                return NULL;
 
-       set = isl_set_alloc_dim(dims, n, flags);
+       set = isl_set_alloc_space(dims, n, flags);
        return set;
 }
 
@@ -1920,7 +2115,7 @@ struct isl_map *isl_map_grow(struct isl_map *map, int n)
        isl_assert(map->ctx, n >= 0, goto error);
        if (map->n + n <= map->size)
                return map;
-       grown = isl_map_alloc_dim(isl_map_get_dim(map), map->n + n, map->flags);
+       grown = isl_map_alloc_space(isl_map_get_space(map), map->n + n, map->flags);
        if (!grown)
                goto error;
        for (i = 0; i < map->n; ++i) {
@@ -1952,7 +2147,7 @@ struct isl_set *isl_set_dup(struct isl_set *set)
        if (!set)
                return NULL;
 
-       dup = isl_set_alloc_dim(isl_dim_copy(set->dim), set->n, set->flags);
+       dup = isl_set_alloc_space(isl_space_copy(set->dim), set->n, set->flags);
        if (!dup)
                return NULL;
        for (i = 0; i < set->n; ++i)
@@ -1972,7 +2167,7 @@ struct isl_map *isl_map_from_basic_map(struct isl_basic_map *bmap)
        if (!bmap)
                return NULL;
 
-       map = isl_map_alloc_dim(isl_dim_copy(bmap->dim), 1, ISL_MAP_DISJOINT);
+       map = isl_map_alloc_space(isl_space_copy(bmap->dim), 1, ISL_MAP_DISJOINT);
        return isl_map_add_basic_map(map, bmap);
 }
 
@@ -1996,7 +2191,7 @@ void isl_set_free(struct isl_set *set)
        isl_ctx_deref(set->ctx);
        for (i = 0; i < set->n; ++i)
                isl_basic_set_free(set->p[i]);
-       isl_dim_free(set->dim);
+       isl_space_free(set->dim);
        free(set);
 }
 
@@ -2033,7 +2228,7 @@ void isl_map_print_internal(struct isl_map *map, FILE *out, int indent)
        fprintf(out, "ref: %d, n: %d, nparam: %d, in: %d, out: %d, "
                     "flags: %x, n_name: %d\n",
                        map->ref, map->n, map->dim->nparam, map->dim->n_in,
-                       map->dim->n_out, map->flags, map->dim->n_name);
+                       map->dim->n_out, map->flags, map->dim->n_id);
        for (i = 0; i < map->n; ++i) {
                fprintf(out, "%*s", indent, "");
                fprintf(out, "basic map %d:\n", i);
@@ -2049,17 +2244,17 @@ struct isl_basic_map *isl_basic_map_intersect_domain(
        if (!bmap || !bset)
                goto error;
 
-       isl_assert(bset->ctx, isl_dim_match(bmap->dim, isl_dim_param,
+       isl_assert(bset->ctx, isl_space_match(bmap->dim, isl_dim_param,
                                        bset->dim, isl_dim_param), goto error);
 
-       if (isl_dim_size(bset->dim, isl_dim_set) != 0)
+       if (isl_space_dim(bset->dim, isl_dim_set) != 0)
                isl_assert(bset->ctx,
                    isl_basic_map_compatible_domain(bmap, bset), goto error);
 
        bmap = isl_basic_map_cow(bmap);
        if (!bmap)
                goto error;
-       bmap = isl_basic_map_extend_dim(bmap, isl_dim_copy(bmap->dim),
+       bmap = isl_basic_map_extend_space(bmap, isl_space_copy(bmap->dim),
                        bset->n_div, bset->n_eq, bset->n_ineq);
        bmap_domain = isl_basic_map_from_domain(bset);
        bmap = add_constraints(bmap, bmap_domain, 0, 0);
@@ -2080,10 +2275,10 @@ struct isl_basic_map *isl_basic_map_intersect_range(
        if (!bmap || !bset)
                goto error;
 
-       isl_assert(bset->ctx, isl_dim_match(bmap->dim, isl_dim_param,
+       isl_assert(bset->ctx, isl_space_match(bmap->dim, isl_dim_param,
                                        bset->dim, isl_dim_param), goto error);
 
-       if (isl_dim_size(bset->dim, isl_dim_set) != 0)
+       if (isl_space_dim(bset->dim, isl_dim_set) != 0)
                isl_assert(bset->ctx,
                    isl_basic_map_compatible_range(bmap, bset), goto error);
 
@@ -2095,9 +2290,9 @@ struct isl_basic_map *isl_basic_map_intersect_range(
        bmap = isl_basic_map_cow(bmap);
        if (!bmap)
                goto error;
-       bmap = isl_basic_map_extend_dim(bmap, isl_dim_copy(bmap->dim),
+       bmap = isl_basic_map_extend_space(bmap, isl_space_copy(bmap->dim),
                        bset->n_div, bset->n_eq, bset->n_ineq);
-       bmap_range = isl_basic_map_from_basic_set(bset, isl_dim_copy(bset->dim));
+       bmap_range = isl_basic_map_from_basic_set(bset, isl_space_copy(bset->dim));
        bmap = add_constraints(bmap, bmap_range, 0, 0);
 
        bmap = isl_basic_map_simplify(bmap);
@@ -2154,18 +2349,18 @@ struct isl_basic_map *isl_basic_map_intersect(
        if (!bmap1 || !bmap2)
                goto error;
 
-       isl_assert(bmap1->ctx, isl_dim_match(bmap1->dim, isl_dim_param,
+       isl_assert(bmap1->ctx, isl_space_match(bmap1->dim, isl_dim_param,
                                     bmap2->dim, isl_dim_param), goto error);
-       if (isl_dim_total(bmap1->dim) ==
-                               isl_dim_size(bmap1->dim, isl_dim_param) &&
-           isl_dim_total(bmap2->dim) !=
-                               isl_dim_size(bmap2->dim, isl_dim_param))
+       if (isl_space_dim(bmap1->dim, isl_dim_all) ==
+                               isl_space_dim(bmap1->dim, isl_dim_param) &&
+           isl_space_dim(bmap2->dim, isl_dim_all) !=
+                               isl_space_dim(bmap2->dim, isl_dim_param))
                return isl_basic_map_intersect(bmap2, bmap1);
 
-       if (isl_dim_total(bmap2->dim) !=
-                                       isl_dim_size(bmap2->dim, isl_dim_param))
+       if (isl_space_dim(bmap2->dim, isl_dim_all) !=
+                                       isl_space_dim(bmap2->dim, isl_dim_param))
                isl_assert(bmap1->ctx,
-                           isl_dim_equal(bmap1->dim, bmap2->dim), goto error);
+                           isl_space_is_equal(bmap1->dim, bmap2->dim), goto error);
 
        if (bmap1->sample &&
            isl_basic_map_contains(bmap1, bmap1->sample) > 0 &&
@@ -2179,7 +2374,7 @@ struct isl_basic_map *isl_basic_map_intersect(
        bmap1 = isl_basic_map_cow(bmap1);
        if (!bmap1)
                goto error;
-       bmap1 = isl_basic_map_extend_dim(bmap1, isl_dim_copy(bmap1->dim),
+       bmap1 = isl_basic_map_extend_space(bmap1, isl_space_copy(bmap1->dim),
                        bmap2->n_div, bmap2->n_eq, bmap2->n_ineq);
        bmap1 = add_constraints(bmap1, bmap2, 0, 0);
 
@@ -2261,7 +2456,8 @@ error:
        return NULL;
 }
 
-struct isl_map *isl_map_intersect(struct isl_map *map1, struct isl_map *map2)
+static __isl_give isl_map *map_intersect(__isl_take isl_map *map1,
+       __isl_take isl_map *map2)
 {
        unsigned flags = 0;
        struct isl_map *result;
@@ -2271,38 +2467,38 @@ struct isl_map *isl_map_intersect(struct isl_map *map1, struct isl_map *map2)
                goto error;
 
        if (isl_map_plain_is_empty(map1) &&
-           isl_dim_equal(map1->dim, map2->dim)) {
+           isl_space_is_equal(map1->dim, map2->dim)) {
                isl_map_free(map2);
                return map1;
        }
        if (isl_map_plain_is_empty(map2) &&
-           isl_dim_equal(map1->dim, map2->dim)) {
+           isl_space_is_equal(map1->dim, map2->dim)) {
                isl_map_free(map1);
                return map2;
        }
 
        if (map1->n == 1 && map2->n == 1 &&
            map1->p[0]->n_div == 0 && map2->p[0]->n_div == 0 &&
-           isl_dim_equal(map1->dim, map2->dim) &&
+           isl_space_is_equal(map1->dim, map2->dim) &&
            (map1->p[0]->n_eq + map1->p[0]->n_ineq == 1 ||
             map2->p[0]->n_eq + map2->p[0]->n_ineq == 1))
                return map_intersect_add_constraint(map1, map2);
-       isl_assert(map1->ctx, isl_dim_match(map1->dim, isl_dim_param,
-                                        map2->dim, isl_dim_param), goto error);
-       if (isl_dim_total(map1->dim) ==
-                               isl_dim_size(map1->dim, isl_dim_param) &&
-           isl_dim_total(map2->dim) != isl_dim_size(map2->dim, isl_dim_param))
+       if (isl_space_dim(map1->dim, isl_dim_all) ==
+                               isl_space_dim(map1->dim, isl_dim_param) &&
+           isl_space_dim(map2->dim, isl_dim_all) !=
+                               isl_space_dim(map2->dim, isl_dim_param))
                return isl_map_intersect(map2, map1);
 
-       if (isl_dim_total(map2->dim) != isl_dim_size(map2->dim, isl_dim_param))
+       if (isl_space_dim(map2->dim, isl_dim_all) !=
+                               isl_space_dim(map2->dim, isl_dim_param))
                isl_assert(map1->ctx,
-                           isl_dim_equal(map1->dim, map2->dim), goto error);
+                           isl_space_is_equal(map1->dim, map2->dim), goto error);
 
        if (ISL_F_ISSET(map1, ISL_MAP_DISJOINT) &&
            ISL_F_ISSET(map2, ISL_MAP_DISJOINT))
                ISL_FL_SET(flags, ISL_MAP_DISJOINT);
 
-       result = isl_map_alloc_dim(isl_dim_copy(map1->dim),
+       result = isl_map_alloc_space(isl_space_copy(map1->dim),
                                map1->n * map2->n, flags);
        if (!result)
                goto error;
@@ -2328,6 +2524,12 @@ error:
        return NULL;
 }
 
+__isl_give isl_map *isl_map_intersect(__isl_take isl_map *map1,
+       __isl_take isl_map *map2)
+{
+       return isl_map_align_params_map_map_and(map1, map2, &map_intersect);
+}
+
 struct isl_set *isl_set_intersect(struct isl_set *set1, struct isl_set *set2)
 {
        return (struct isl_set *)
@@ -2338,12 +2540,18 @@ struct isl_set *isl_set_intersect(struct isl_set *set1, struct isl_set *set2)
 /* The current implementation of isl_map_intersect accepts intersections
  * with parameter domains, so we can just call that for now.
  */
-__isl_give isl_map *isl_map_intersect_params(__isl_take isl_map *map,
+static __isl_give isl_map *map_intersect_params(__isl_take isl_map *map,
                __isl_take isl_set *params)
 {
        return isl_map_intersect(map, params);
 }
 
+__isl_give isl_map *isl_map_intersect_params(__isl_take isl_map *map1,
+       __isl_take isl_map *map2)
+{
+       return isl_map_align_params_map_map_and(map1, map2, &map_intersect_params);
+}
+
 __isl_give isl_set *isl_set_intersect_params(__isl_take isl_set *set,
                __isl_take isl_set *params)
 {
@@ -2352,7 +2560,7 @@ __isl_give isl_set *isl_set_intersect_params(__isl_take isl_set *set,
 
 struct isl_basic_map *isl_basic_map_reverse(struct isl_basic_map *bmap)
 {
-       struct isl_dim *dim;
+       isl_space *dim;
        struct isl_basic_set *bset;
        unsigned in;
 
@@ -2361,7 +2569,7 @@ struct isl_basic_map *isl_basic_map_reverse(struct isl_basic_map *bmap)
        bmap = isl_basic_map_cow(bmap);
        if (!bmap)
                return NULL;
-       dim = isl_dim_reverse(isl_dim_copy(bmap->dim));
+       dim = isl_space_reverse(isl_space_copy(bmap->dim));
        in = isl_basic_map_n_in(bmap);
        bset = isl_basic_set_from_basic_map(bmap);
        bset = isl_basic_set_swap_vars(bset, in);
@@ -2371,21 +2579,21 @@ struct isl_basic_map *isl_basic_map_reverse(struct isl_basic_map *bmap)
 static __isl_give isl_basic_map *basic_map_space_reset(
        __isl_take isl_basic_map *bmap, enum isl_dim_type type)
 {
-       isl_dim *space;
+       isl_space *space;
 
-       if (!isl_dim_is_named_or_nested(bmap->dim, type))
+       if (!isl_space_is_named_or_nested(bmap->dim, type))
                return bmap;
 
-       space = isl_basic_map_get_dim(bmap);
-       space = isl_dim_reset(space, type);
-       bmap = isl_basic_map_reset_dim(bmap, space);
+       space = isl_basic_map_get_space(bmap);
+       space = isl_space_reset(space, type);
+       bmap = isl_basic_map_reset_space(bmap, space);
        return bmap;
 }
 
 __isl_give isl_basic_map *isl_basic_map_insert(__isl_take isl_basic_map *bmap,
                enum isl_dim_type type, unsigned pos, unsigned n)
 {
-       struct isl_dim *res_dim;
+       isl_space *res_dim;
        struct isl_basic_map *res;
        struct isl_dim_map *dim_map;
        unsigned total, off;
@@ -2397,7 +2605,7 @@ __isl_give isl_basic_map *isl_basic_map_insert(__isl_take isl_basic_map *bmap,
        if (!bmap)
                return NULL;
 
-       res_dim = isl_dim_insert(isl_basic_map_get_dim(bmap), type, pos, n);
+       res_dim = isl_space_insert_dims(isl_basic_map_get_space(bmap), type, pos, n);
 
        total = isl_basic_map_total_dim(bmap) + n;
        dim_map = isl_dim_map_alloc(bmap->ctx, total);
@@ -2412,11 +2620,11 @@ __isl_give isl_basic_map *isl_basic_map_insert(__isl_take isl_basic_map *bmap,
                        isl_dim_map_dim_range(dim_map, bmap->dim, t,
                                                pos, size - pos, off + pos + n);
                }
-               off += isl_dim_size(res_dim, t);
+               off += isl_space_dim(res_dim, t);
        }
        isl_dim_map_div(dim_map, bmap, off);
 
-       res = isl_basic_map_alloc_dim(res_dim,
+       res = isl_basic_map_alloc_space(res_dim,
                        bmap->n_div, bmap->n_eq, bmap->n_ineq);
        if (isl_basic_map_is_rational(bmap))
                res = isl_basic_map_set_rational(res);
@@ -2448,18 +2656,18 @@ error:
 static __isl_give isl_map *map_space_reset(__isl_take isl_map *map,
        enum isl_dim_type type)
 {
-       isl_dim *space;
+       isl_space *space;
 
-       if (!isl_dim_is_named_or_nested(map->dim, type))
+       if (!isl_space_is_named_or_nested(map->dim, type))
                return map;
 
-       space = isl_map_get_dim(map);
-       space = isl_dim_reset(space, type);
-       map = isl_map_reset_dim(map, space);
+       space = isl_map_get_space(map);
+       space = isl_space_reset(space, type);
+       map = isl_map_reset_space(map, space);
        return map;
 }
 
-__isl_give isl_map *isl_map_insert(__isl_take isl_map *map,
+__isl_give isl_map *isl_map_insert_dims(__isl_take isl_map *map,
                enum isl_dim_type type, unsigned pos, unsigned n)
 {
        int i;
@@ -2471,7 +2679,7 @@ __isl_give isl_map *isl_map_insert(__isl_take isl_map *map,
        if (!map)
                return NULL;
 
-       map->dim = isl_dim_insert(map->dim, type, pos, n);
+       map->dim = isl_space_insert_dims(map->dim, type, pos, n);
        if (!map->dim)
                goto error;
 
@@ -2487,10 +2695,10 @@ error:
        return NULL;
 }
 
-__isl_give isl_set *isl_set_insert(__isl_take isl_set *set,
+__isl_give isl_set *isl_set_insert_dims(__isl_take isl_set *set,
                enum isl_dim_type type, unsigned pos, unsigned n)
 {
-       return (isl_set *)isl_map_insert((isl_map *)set, type, pos, n);
+       return isl_map_insert_dims(set, type, pos, n);
 }
 
 __isl_give isl_map *isl_map_add_dims(__isl_take isl_map *map,
@@ -2498,7 +2706,7 @@ __isl_give isl_map *isl_map_add_dims(__isl_take isl_map *map,
 {
        if (!map)
                return NULL;
-       return isl_map_insert(map, type, isl_map_dim(map, type), n);
+       return isl_map_insert_dims(map, type, isl_map_dim(map, type), n);
 }
 
 __isl_give isl_set *isl_set_add_dims(__isl_take isl_set *set,
@@ -2543,7 +2751,7 @@ __isl_give isl_basic_map *isl_basic_map_move_dims(
                if (!bmap)
                        return NULL;
 
-               bmap->dim = isl_dim_move(bmap->dim, dst_type, dst_pos,
+               bmap->dim = isl_space_move_dims(bmap->dim, dst_type, dst_pos,
                                                src_type, src_pos, n);
                if (!bmap->dim)
                        goto error;
@@ -2558,7 +2766,7 @@ __isl_give isl_basic_map *isl_basic_map_move_dims(
 
        off = 0;
        for (t = isl_dim_param; t <= isl_dim_out; ++t) {
-               unsigned size = isl_dim_size(bmap->dim, t);
+               unsigned size = isl_space_dim(bmap->dim, t);
                if (t == dst_type) {
                        isl_dim_map_dim_range(dim_map, bmap->dim, t,
                                            0, dst_pos, off);
@@ -2583,11 +2791,11 @@ __isl_give isl_basic_map *isl_basic_map_move_dims(
        }
        isl_dim_map_div(dim_map, bmap, off);
 
-       res = isl_basic_map_alloc_dim(isl_basic_map_get_dim(bmap),
+       res = isl_basic_map_alloc_space(isl_basic_map_get_space(bmap),
                        bmap->n_div, bmap->n_eq, bmap->n_ineq);
        bmap = isl_basic_map_add_constraints_dim_map(res, bmap, dim_map);
 
-       bmap->dim = isl_dim_move(bmap->dim, dst_type, dst_pos,
+       bmap->dim = isl_space_move_dims(bmap->dim, dst_type, dst_pos,
                                        src_type, src_pos, n);
        if (!bmap->dim)
                goto error;
@@ -2647,7 +2855,7 @@ __isl_give isl_map *isl_map_move_dims(__isl_take isl_map *map,
        if (!map)
                return NULL;
 
-       map->dim = isl_dim_move(map->dim, dst_type, dst_pos, src_type, src_pos, n);
+       map->dim = isl_space_move_dims(map->dim, dst_type, dst_pos, src_type, src_pos, n);
        if (!map->dim)
                goto error;
 
@@ -2679,7 +2887,8 @@ static __isl_give isl_basic_map *move_last(__isl_take isl_basic_map *bmap,
 
        if (!bmap)
                return NULL;
-       if (pos(bmap->dim, type) + first + n == 1 + isl_dim_total(bmap->dim))
+       if (pos(bmap->dim, type) + first + n ==
+                               1 + isl_space_dim(bmap->dim, isl_dim_all))
                return bmap;
 
        total = isl_basic_map_total_dim(bmap);
@@ -2687,7 +2896,7 @@ static __isl_give isl_basic_map *move_last(__isl_take isl_basic_map *bmap,
 
        off = 0;
        for (t = isl_dim_param; t <= isl_dim_out; ++t) {
-               unsigned size = isl_dim_size(bmap->dim, t);
+               unsigned size = isl_space_dim(bmap->dim, t);
                if (t == type) {
                        isl_dim_map_dim_range(dim_map, bmap->dim, t,
                                            0, first, off);
@@ -2704,7 +2913,7 @@ static __isl_give isl_basic_map *move_last(__isl_take isl_basic_map *bmap,
        }
        isl_dim_map_div(dim_map, bmap, off + n);
 
-       res = isl_basic_map_alloc_dim(isl_basic_map_get_dim(bmap),
+       res = isl_basic_map_alloc_space(isl_basic_map_get_space(bmap),
                        bmap->n_div, bmap->n_eq, bmap->n_ineq);
        res = isl_basic_map_add_constraints_dim_map(res, bmap, dim_map);
        return res;
@@ -2739,7 +2948,7 @@ __isl_give isl_basic_map *isl_basic_map_project_out(
        if (!bmap)
                return NULL;
 
-       row_size = 1 + isl_dim_total(bmap->dim) + bmap->extra;
+       row_size = 1 + isl_space_dim(bmap->dim, isl_dim_all) + bmap->extra;
        old = bmap->block2.data;
        bmap->block2 = isl_blk_extend(bmap->ctx, bmap->block2,
                                        (bmap->extra + n) * (1 + row_size));
@@ -2760,7 +2969,7 @@ __isl_give isl_basic_map *isl_basic_map_project_out(
        bmap->n_div += n;
        bmap->extra += n;
 
-       bmap->dim = isl_dim_drop(bmap->dim, type, first, n);
+       bmap->dim = isl_space_drop_dims(bmap->dim, type, first, n);
        if (!bmap->dim)
                goto error;
        bmap = isl_basic_map_simplify(bmap);
@@ -2801,7 +3010,7 @@ __isl_give isl_map *isl_map_project_out(__isl_take isl_map *map,
        if (!map)
                return NULL;
 
-       map->dim = isl_dim_drop(map->dim, type, first, n);
+       map->dim = isl_space_drop_dims(map->dim, type, first, n);
        if (!map->dim)
                goto error;
 
@@ -2845,7 +3054,7 @@ error:
 struct isl_basic_map *isl_basic_map_apply_range(
                struct isl_basic_map *bmap1, struct isl_basic_map *bmap2)
 {
-       struct isl_dim *dim_result = NULL;
+       isl_space *dim_result = NULL;
        struct isl_basic_map *bmap;
        unsigned n_in, n_out, n, nparam, total, pos;
        struct isl_dim_map *dim_map1, *dim_map2;
@@ -2853,8 +3062,8 @@ struct isl_basic_map *isl_basic_map_apply_range(
        if (!bmap1 || !bmap2)
                goto error;
 
-       dim_result = isl_dim_join(isl_dim_copy(bmap1->dim),
-                                 isl_dim_copy(bmap2->dim));
+       dim_result = isl_space_join(isl_space_copy(bmap1->dim),
+                                 isl_space_copy(bmap2->dim));
 
        n_in = isl_basic_map_n_in(bmap1);
        n_out = isl_basic_map_n_out(bmap2);
@@ -2873,7 +3082,7 @@ struct isl_basic_map *isl_basic_map_apply_range(
        isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_out, pos += bmap2->n_div);
        isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_in, pos);
 
-       bmap = isl_basic_map_alloc_dim(dim_result,
+       bmap = isl_basic_map_alloc_space(dim_result,
                        bmap1->n_div + bmap2->n_div + n,
                        bmap1->n_eq + bmap2->n_eq,
                        bmap1->n_ineq + bmap2->n_ineq);
@@ -2941,7 +3150,7 @@ struct isl_basic_map *isl_basic_map_sum(
        if (!bmap1 || !bmap2)
                goto error;
 
-       isl_assert(bmap1->ctx, isl_dim_equal(bmap1->dim, bmap2->dim),
+       isl_assert(bmap1->ctx, isl_space_is_equal(bmap1->dim, bmap2->dim),
                goto error);
 
        nparam = isl_basic_map_n_param(bmap1);
@@ -2960,7 +3169,7 @@ struct isl_basic_map *isl_basic_map_sum(
        isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_out, pos += bmap2->n_div);
        isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_out, pos += n_out);
 
-       bmap = isl_basic_map_alloc_dim(isl_dim_copy(bmap1->dim),
+       bmap = isl_basic_map_alloc_space(isl_space_copy(bmap1->dim),
                        bmap1->n_div + bmap2->n_div + 2 * n_out,
                        bmap1->n_eq + bmap2->n_eq + n_out,
                        bmap1->n_ineq + bmap2->n_ineq);
@@ -2997,9 +3206,9 @@ struct isl_map *isl_map_sum(struct isl_map *map1, struct isl_map *map2)
        if (!map1 || !map2)
                goto error;
 
-       isl_assert(map1->ctx, isl_dim_equal(map1->dim, map2->dim), goto error);
+       isl_assert(map1->ctx, isl_space_is_equal(map1->dim, map2->dim), goto error);
 
-       result = isl_map_alloc_dim(isl_dim_copy(map1->dim),
+       result = isl_map_alloc_space(isl_space_copy(map1->dim),
                                map1->n * map2->n, 0);
        if (!result)
                goto error;
@@ -3114,7 +3323,7 @@ struct isl_basic_map *isl_basic_map_floordiv(struct isl_basic_map *bmap,
        isl_dim_map_div(dim_map, bmap, pos += n_in + n_out);
        isl_dim_map_dim(dim_map, bmap->dim, isl_dim_out, pos += bmap->n_div);
 
-       result = isl_basic_map_alloc_dim(isl_dim_copy(bmap->dim),
+       result = isl_basic_map_alloc_space(isl_space_copy(bmap->dim),
                        bmap->n_div + n_out,
                        bmap->n_eq, bmap->n_ineq + 2 * n_out);
        result = isl_basic_map_add_constraints_dim_map(result, bmap, dim_map);
@@ -3280,11 +3489,12 @@ error:
        return NULL;
 }
 
-struct isl_basic_map *isl_basic_map_equal(struct isl_dim *dim, unsigned n_equal)
+__isl_give isl_basic_map *isl_basic_map_equal(
+       __isl_take isl_space *dim, unsigned n_equal)
 {
        int i;
        struct isl_basic_map *bmap;
-       bmap = isl_basic_map_alloc_dim(dim, 0, n_equal, 0);
+       bmap = isl_basic_map_alloc_space(dim, 0, n_equal, 0);
        if (!bmap)
                return NULL;
        for (i = 0; i < n_equal && bmap; ++i)
@@ -3294,11 +3504,12 @@ struct isl_basic_map *isl_basic_map_equal(struct isl_dim *dim, unsigned n_equal)
 
 /* Return a relation on of dimension "dim" expressing i_[0..pos] << o_[0..pos]
  */
-struct isl_basic_map *isl_basic_map_less_at(struct isl_dim *dim, unsigned pos)
+__isl_give isl_basic_map *isl_basic_map_less_at(__isl_take isl_space *dim,
+       unsigned pos)
 {
        int i;
        struct isl_basic_map *bmap;
-       bmap = isl_basic_map_alloc_dim(dim, 0, pos, 1);
+       bmap = isl_basic_map_alloc_space(dim, 0, pos, 1);
        if (!bmap)
                return NULL;
        for (i = 0; i < pos && bmap; ++i)
@@ -3311,12 +3522,12 @@ struct isl_basic_map *isl_basic_map_less_at(struct isl_dim *dim, unsigned pos)
 /* Return a relation on of dimension "dim" expressing i_[0..pos] <<= o_[0..pos]
  */
 __isl_give isl_basic_map *isl_basic_map_less_or_equal_at(
-       __isl_take isl_dim *dim, unsigned pos)
+       __isl_take isl_space *dim, unsigned pos)
 {
        int i;
        isl_basic_map *bmap;
 
-       bmap = isl_basic_map_alloc_dim(dim, 0, pos, 1);
+       bmap = isl_basic_map_alloc_space(dim, 0, pos, 1);
        for (i = 0; i < pos; ++i)
                bmap = var_equal(bmap, i);
        bmap = var_less_or_equal(bmap, pos);
@@ -3325,11 +3536,12 @@ __isl_give isl_basic_map *isl_basic_map_less_or_equal_at(
 
 /* Return a relation on pairs of sets of dimension "dim" expressing i_pos > o_pos
  */
-struct isl_basic_map *isl_basic_map_more_at(struct isl_dim *dim, unsigned pos)
+__isl_give isl_basic_map *isl_basic_map_more_at(__isl_take isl_space *dim,
+       unsigned pos)
 {
        int i;
        struct isl_basic_map *bmap;
-       bmap = isl_basic_map_alloc_dim(dim, 0, pos, 1);
+       bmap = isl_basic_map_alloc_space(dim, 0, pos, 1);
        if (!bmap)
                return NULL;
        for (i = 0; i < pos && bmap; ++i)
@@ -3342,19 +3554,19 @@ struct isl_basic_map *isl_basic_map_more_at(struct isl_dim *dim, unsigned pos)
 /* Return a relation on of dimension "dim" expressing i_[0..pos] >>= o_[0..pos]
  */
 __isl_give isl_basic_map *isl_basic_map_more_or_equal_at(
-       __isl_take isl_dim *dim, unsigned pos)
+       __isl_take isl_space *dim, unsigned pos)
 {
        int i;
        isl_basic_map *bmap;
 
-       bmap = isl_basic_map_alloc_dim(dim, 0, pos, 1);
+       bmap = isl_basic_map_alloc_space(dim, 0, pos, 1);
        for (i = 0; i < pos; ++i)
                bmap = var_equal(bmap, i);
        bmap = var_more_or_equal(bmap, pos);
        return isl_basic_map_finalize(bmap);
 }
 
-static __isl_give isl_map *map_lex_lte_first(__isl_take isl_dim *dims,
+static __isl_give isl_map *map_lex_lte_first(__isl_take isl_space *dims,
        unsigned n, int equal)
 {
        struct isl_map *map;
@@ -3363,11 +3575,11 @@ static __isl_give isl_map *map_lex_lte_first(__isl_take isl_dim *dims,
        if (n == 0 && equal)
                return isl_map_universe(dims);
 
-       map = isl_map_alloc_dim(isl_dim_copy(dims), n, ISL_MAP_DISJOINT);
+       map = isl_map_alloc_space(isl_space_copy(dims), n, ISL_MAP_DISJOINT);
 
        for (i = 0; i + 1 < n; ++i)
                map = isl_map_add_basic_map(map,
-                                 isl_basic_map_less_at(isl_dim_copy(dims), i));
+                                 isl_basic_map_less_at(isl_space_copy(dims), i));
        if (n > 0) {
                if (equal)
                        map = isl_map_add_basic_map(map,
@@ -3376,39 +3588,39 @@ static __isl_give isl_map *map_lex_lte_first(__isl_take isl_dim *dims,
                        map = isl_map_add_basic_map(map,
                              isl_basic_map_less_at(dims, n - 1));
        } else
-               isl_dim_free(dims);
+               isl_space_free(dims);
 
        return map;
 }
 
-static __isl_give isl_map *map_lex_lte(__isl_take isl_dim *dims, int equal)
+static __isl_give isl_map *map_lex_lte(__isl_take isl_space *dims, int equal)
 {
        if (!dims)
                return NULL;
        return map_lex_lte_first(dims, dims->n_out, equal);
 }
 
-__isl_give isl_map *isl_map_lex_lt_first(__isl_take isl_dim *dim, unsigned n)
+__isl_give isl_map *isl_map_lex_lt_first(__isl_take isl_space *dim, unsigned n)
 {
        return map_lex_lte_first(dim, n, 0);
 }
 
-__isl_give isl_map *isl_map_lex_le_first(__isl_take isl_dim *dim, unsigned n)
+__isl_give isl_map *isl_map_lex_le_first(__isl_take isl_space *dim, unsigned n)
 {
        return map_lex_lte_first(dim, n, 1);
 }
 
-__isl_give isl_map *isl_map_lex_lt(__isl_take isl_dim *set_dim)
+__isl_give isl_map *isl_map_lex_lt(__isl_take isl_space *set_dim)
 {
-       return map_lex_lte(isl_dim_map_from_set(set_dim), 0);
+       return map_lex_lte(isl_space_map_from_set(set_dim), 0);
 }
 
-__isl_give isl_map *isl_map_lex_le(__isl_take isl_dim *set_dim)
+__isl_give isl_map *isl_map_lex_le(__isl_take isl_space *set_dim)
 {
-       return map_lex_lte(isl_dim_map_from_set(set_dim), 1);
+       return map_lex_lte(isl_space_map_from_set(set_dim), 1);
 }
 
-static __isl_give isl_map *map_lex_gte_first(__isl_take isl_dim *dims,
+static __isl_give isl_map *map_lex_gte_first(__isl_take isl_space *dims,
        unsigned n, int equal)
 {
        struct isl_map *map;
@@ -3417,11 +3629,11 @@ static __isl_give isl_map *map_lex_gte_first(__isl_take isl_dim *dims,
        if (n == 0 && equal)
                return isl_map_universe(dims);
 
-       map = isl_map_alloc_dim(isl_dim_copy(dims), n, ISL_MAP_DISJOINT);
+       map = isl_map_alloc_space(isl_space_copy(dims), n, ISL_MAP_DISJOINT);
 
        for (i = 0; i + 1 < n; ++i)
                map = isl_map_add_basic_map(map,
-                                 isl_basic_map_more_at(isl_dim_copy(dims), i));
+                                 isl_basic_map_more_at(isl_space_copy(dims), i));
        if (n > 0) {
                if (equal)
                        map = isl_map_add_basic_map(map,
@@ -3430,43 +3642,43 @@ static __isl_give isl_map *map_lex_gte_first(__isl_take isl_dim *dims,
                        map = isl_map_add_basic_map(map,
                              isl_basic_map_more_at(dims, n - 1));
        } else
-               isl_dim_free(dims);
+               isl_space_free(dims);
 
        return map;
 }
 
-static __isl_give isl_map *map_lex_gte(__isl_take isl_dim *dims, int equal)
+static __isl_give isl_map *map_lex_gte(__isl_take isl_space *dims, int equal)
 {
        if (!dims)
                return NULL;
        return map_lex_gte_first(dims, dims->n_out, equal);
 }
 
-__isl_give isl_map *isl_map_lex_gt_first(__isl_take isl_dim *dim, unsigned n)
+__isl_give isl_map *isl_map_lex_gt_first(__isl_take isl_space *dim, unsigned n)
 {
        return map_lex_gte_first(dim, n, 0);
 }
 
-__isl_give isl_map *isl_map_lex_ge_first(__isl_take isl_dim *dim, unsigned n)
+__isl_give isl_map *isl_map_lex_ge_first(__isl_take isl_space *dim, unsigned n)
 {
        return map_lex_gte_first(dim, n, 1);
 }
 
-__isl_give isl_map *isl_map_lex_gt(__isl_take isl_dim *set_dim)
+__isl_give isl_map *isl_map_lex_gt(__isl_take isl_space *set_dim)
 {
-       return map_lex_gte(isl_dim_map_from_set(set_dim), 0);
+       return map_lex_gte(isl_space_map_from_set(set_dim), 0);
 }
 
-__isl_give isl_map *isl_map_lex_ge(__isl_take isl_dim *set_dim)
+__isl_give isl_map *isl_map_lex_ge(__isl_take isl_space *set_dim)
 {
-       return map_lex_gte(isl_dim_map_from_set(set_dim), 1);
+       return map_lex_gte(isl_space_map_from_set(set_dim), 1);
 }
 
 __isl_give isl_map *isl_set_lex_le_set(__isl_take isl_set *set1,
        __isl_take isl_set *set2)
 {
        isl_map *map;
-       map = isl_map_lex_le(isl_set_get_dim(set1));
+       map = isl_map_lex_le(isl_set_get_space(set1));
        map = isl_map_intersect_domain(map, set1);
        map = isl_map_intersect_range(map, set2);
        return map;
@@ -3476,7 +3688,7 @@ __isl_give isl_map *isl_set_lex_lt_set(__isl_take isl_set *set1,
        __isl_take isl_set *set2)
 {
        isl_map *map;
-       map = isl_map_lex_lt(isl_set_get_dim(set1));
+       map = isl_map_lex_lt(isl_set_get_space(set1));
        map = isl_map_intersect_domain(map, set1);
        map = isl_map_intersect_range(map, set2);
        return map;
@@ -3486,7 +3698,7 @@ __isl_give isl_map *isl_set_lex_ge_set(__isl_take isl_set *set1,
        __isl_take isl_set *set2)
 {
        isl_map *map;
-       map = isl_map_lex_ge(isl_set_get_dim(set1));
+       map = isl_map_lex_ge(isl_set_get_space(set1));
        map = isl_map_intersect_domain(map, set1);
        map = isl_map_intersect_range(map, set2);
        return map;
@@ -3496,7 +3708,7 @@ __isl_give isl_map *isl_set_lex_gt_set(__isl_take isl_set *set1,
        __isl_take isl_set *set2)
 {
        isl_map *map;
-       map = isl_map_lex_gt(isl_set_get_dim(set1));
+       map = isl_map_lex_gt(isl_set_get_space(set1));
        map = isl_map_intersect_domain(map, set1);
        map = isl_map_intersect_range(map, set2);
        return map;
@@ -3506,7 +3718,7 @@ __isl_give isl_map *isl_map_lex_le_map(__isl_take isl_map *map1,
        __isl_take isl_map *map2)
 {
        isl_map *map;
-       map = isl_map_lex_le(isl_dim_range(isl_map_get_dim(map1)));
+       map = isl_map_lex_le(isl_space_range(isl_map_get_space(map1)));
        map = isl_map_apply_domain(map, isl_map_reverse(map1));
        map = isl_map_apply_range(map, isl_map_reverse(map2));
        return map;
@@ -3516,7 +3728,7 @@ __isl_give isl_map *isl_map_lex_lt_map(__isl_take isl_map *map1,
        __isl_take isl_map *map2)
 {
        isl_map *map;
-       map = isl_map_lex_lt(isl_dim_range(isl_map_get_dim(map1)));
+       map = isl_map_lex_lt(isl_space_range(isl_map_get_space(map1)));
        map = isl_map_apply_domain(map, isl_map_reverse(map1));
        map = isl_map_apply_range(map, isl_map_reverse(map2));
        return map;
@@ -3526,7 +3738,7 @@ __isl_give isl_map *isl_map_lex_ge_map(__isl_take isl_map *map1,
        __isl_take isl_map *map2)
 {
        isl_map *map;
-       map = isl_map_lex_ge(isl_dim_range(isl_map_get_dim(map1)));
+       map = isl_map_lex_ge(isl_space_range(isl_map_get_space(map1)));
        map = isl_map_apply_domain(map, isl_map_reverse(map1));
        map = isl_map_apply_range(map, isl_map_reverse(map2));
        return map;
@@ -3536,14 +3748,14 @@ __isl_give isl_map *isl_map_lex_gt_map(__isl_take isl_map *map1,
        __isl_take isl_map *map2)
 {
        isl_map *map;
-       map = isl_map_lex_gt(isl_dim_range(isl_map_get_dim(map1)));
+       map = isl_map_lex_gt(isl_space_range(isl_map_get_space(map1)));
        map = isl_map_apply_domain(map, isl_map_reverse(map1));
        map = isl_map_apply_range(map, isl_map_reverse(map2));
        return map;
 }
 
-struct isl_basic_map *isl_basic_map_from_basic_set(
-               struct isl_basic_set *bset, struct isl_dim *dim)
+__isl_give isl_basic_map *isl_basic_map_from_basic_set(
+       __isl_take isl_basic_set *bset, __isl_take isl_space *dim)
 {
        struct isl_basic_map *bmap;
 
@@ -3551,14 +3763,14 @@ struct isl_basic_map *isl_basic_map_from_basic_set(
        if (!bset || !dim)
                goto error;
 
-       isl_assert(bset->ctx, isl_dim_compatible(bset->dim, dim), goto error);
-       isl_dim_free(bset->dim);
+       isl_assert(bset->ctx, isl_space_compatible(bset->dim, dim), goto error);
+       isl_space_free(bset->dim);
        bmap = (struct isl_basic_map *) bset;
        bmap->dim = dim;
        return isl_basic_map_finalize(bmap);
 error:
        isl_basic_set_free(bset);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -3571,7 +3783,7 @@ struct isl_basic_set *isl_basic_set_from_basic_map(struct isl_basic_map *bmap)
        bmap = isl_basic_map_cow(bmap);
        if (!bmap)
                goto error;
-       bmap->dim = isl_dim_as_set_dim(bmap->dim);
+       bmap->dim = isl_space_as_set_space(bmap->dim);
        if (!bmap->dim)
                goto error;
        bmap = isl_basic_map_finalize(bmap);
@@ -3634,13 +3846,13 @@ struct isl_basic_set *isl_basic_map_underlying_set(
                goto error;
        if (bmap->dim->nparam == 0 && bmap->dim->n_in == 0 &&
            bmap->n_div == 0 &&
-           !isl_dim_is_named_or_nested(bmap->dim, isl_dim_in) &&
-           !isl_dim_is_named_or_nested(bmap->dim, isl_dim_out))
+           !isl_space_is_named_or_nested(bmap->dim, isl_dim_in) &&
+           !isl_space_is_named_or_nested(bmap->dim, isl_dim_out))
                return (struct isl_basic_set *)bmap;
        bmap = isl_basic_map_cow(bmap);
        if (!bmap)
                goto error;
-       bmap->dim = isl_dim_underlying(bmap->dim, bmap->n_div);
+       bmap->dim = isl_space_underlying(bmap->dim, bmap->n_div);
        if (!bmap->dim)
                goto error;
        bmap->extra -= bmap->n_div;
@@ -3672,7 +3884,7 @@ struct isl_basic_map *isl_basic_map_overlying_set(
        isl_assert(ctx, isl_basic_set_n_param(bset) == 0, goto error);
        isl_assert(ctx, bset->dim->n_out == isl_basic_map_total_dim(like),
                        goto error);
-       if (isl_dim_equal(bset->dim, like->dim) && like->n_div == 0) {
+       if (isl_space_is_equal(bset->dim, like->dim) && like->n_div == 0) {
                isl_basic_map_free(like);
                return (struct isl_basic_map *)bset;
        }
@@ -3681,8 +3893,8 @@ struct isl_basic_map *isl_basic_map_overlying_set(
                goto error;
        total = bset->dim->n_out + bset->extra;
        bmap = (struct isl_basic_map *)bset;
-       isl_dim_free(bmap->dim);
-       bmap->dim = isl_dim_copy(like->dim);
+       isl_space_free(bmap->dim);
+       bmap->dim = isl_space_copy(like->dim);
        if (!bmap->dim)
                goto error;
        bmap->n_div = like->n_div;
@@ -3742,7 +3954,7 @@ struct isl_set *isl_set_from_underlying_set(
                goto error;
        isl_assert(set->ctx, set->dim->n_out == isl_basic_set_total_dim(like),
                    goto error);
-       if (isl_dim_equal(set->dim, like->dim) && like->n_div == 0) {
+       if (isl_space_is_equal(set->dim, like->dim) && like->n_div == 0) {
                isl_basic_set_free(like);
                return set;
        }
@@ -3755,8 +3967,8 @@ struct isl_set *isl_set_from_underlying_set(
                if (!set->p[i])
                        goto error;
        }
-       isl_dim_free(set->dim);
-       set->dim = isl_dim_copy(like->dim);
+       isl_space_free(set->dim);
+       set->dim = isl_space_copy(like->dim);
        if (!set->dim)
                goto error;
        isl_basic_set_free(like);
@@ -3774,7 +3986,7 @@ struct isl_set *isl_map_underlying_set(struct isl_map *map)
        map = isl_map_cow(map);
        if (!map)
                return NULL;
-       map->dim = isl_dim_cow(map->dim);
+       map->dim = isl_space_cow(map->dim);
        if (!map->dim)
                goto error;
 
@@ -3788,10 +4000,10 @@ struct isl_set *isl_map_underlying_set(struct isl_map *map)
                        goto error;
        }
        if (map->n == 0)
-               map->dim = isl_dim_underlying(map->dim, 0);
+               map->dim = isl_space_underlying(map->dim, 0);
        else {
-               isl_dim_free(map->dim);
-               map->dim = isl_dim_copy(map->p[0]->dim);
+               isl_space_free(map->dim);
+               map->dim = isl_space_copy(map->p[0]->dim);
        }
        if (!map->dim)
                goto error;
@@ -3806,14 +4018,14 @@ struct isl_set *isl_set_to_underlying_set(struct isl_set *set)
        return (struct isl_set *)isl_map_underlying_set((struct isl_map *)set);
 }
 
-__isl_give isl_basic_map *isl_basic_map_reset_dim(
-       __isl_take isl_basic_map *bmap, __isl_take isl_dim *dim)
+__isl_give isl_basic_map *isl_basic_map_reset_space(
+       __isl_take isl_basic_map *bmap, __isl_take isl_space *dim)
 {
        bmap = isl_basic_map_cow(bmap);
        if (!bmap || !dim)
                goto error;
 
-       isl_dim_free(bmap->dim);
+       isl_space_free(bmap->dim);
        bmap->dim = dim;
 
        bmap = isl_basic_map_finalize(bmap);
@@ -3821,19 +4033,19 @@ __isl_give isl_basic_map *isl_basic_map_reset_dim(
        return bmap;
 error:
        isl_basic_map_free(bmap);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
-__isl_give isl_basic_set *isl_basic_set_reset_dim(
-       __isl_take isl_basic_set *bset, __isl_take isl_dim *dim)
+__isl_give isl_basic_set *isl_basic_set_reset_space(
+       __isl_take isl_basic_set *bset, __isl_take isl_space *dim)
 {
-       return (isl_basic_set *)isl_basic_map_reset_dim((isl_basic_map *)bset,
+       return (isl_basic_set *)isl_basic_map_reset_space((isl_basic_map *)bset,
                                                        dim);
 }
 
-__isl_give isl_map *isl_map_reset_dim(__isl_take isl_map *map,
-       __isl_take isl_dim *dim)
+__isl_give isl_map *isl_map_reset_space(__isl_take isl_map *map,
+       __isl_take isl_space *dim)
 {
        int i;
 
@@ -3842,44 +4054,80 @@ __isl_give isl_map *isl_map_reset_dim(__isl_take isl_map *map,
                goto error;
 
        for (i = 0; i < map->n; ++i) {
-               map->p[i] = isl_basic_map_reset_dim(map->p[i],
-                                                   isl_dim_copy(dim));
+               map->p[i] = isl_basic_map_reset_space(map->p[i],
+                                                   isl_space_copy(dim));
                if (!map->p[i])
                        goto error;
        }
-       isl_dim_free(map->dim);
+       isl_space_free(map->dim);
        map->dim = dim;
 
        return map;
 error:
        isl_map_free(map);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
-__isl_give isl_set *isl_set_reset_dim(__isl_take isl_set *set,
-       __isl_take isl_dim *dim)
+__isl_give isl_set *isl_set_reset_space(__isl_take isl_set *set,
+       __isl_take isl_space *dim)
+{
+       return (struct isl_set *) isl_map_reset_space((struct isl_map *)set, dim);
+}
+
+/* Compute the parameter domain of the given basic set.
+ */
+__isl_give isl_basic_set *isl_basic_set_params(__isl_take isl_basic_set *bset)
 {
-       return (struct isl_set *) isl_map_reset_dim((struct isl_map *)set, dim);
+       isl_space *space;
+       unsigned n;
+
+       if (isl_basic_set_is_params(bset))
+               return bset;
+
+       n = isl_basic_set_dim(bset, isl_dim_set);
+       bset = isl_basic_set_project_out(bset, isl_dim_set, 0, n);
+       space = isl_basic_set_get_space(bset);
+       space = isl_space_params(space);
+       bset = isl_basic_set_reset_space(bset, space);
+       return bset;
+}
+
+/* Compute the parameter domain of the given set.
+ */
+__isl_give isl_set *isl_set_params(__isl_take isl_set *set)
+{
+       isl_space *space;
+       unsigned n;
+
+       if (isl_set_is_params(set))
+               return set;
+
+       n = isl_set_dim(set, isl_dim_set);
+       set = isl_set_project_out(set, isl_dim_set, 0, n);
+       space = isl_set_get_space(set);
+       space = isl_space_params(space);
+       set = isl_set_reset_space(set, space);
+       return set;
 }
 
 struct isl_basic_set *isl_basic_map_domain(struct isl_basic_map *bmap)
 {
-       isl_dim *dim;
+       isl_space *dim;
        struct isl_basic_set *domain;
        unsigned n_in;
        unsigned n_out;
 
        if (!bmap)
                return NULL;
-       dim = isl_dim_domain(isl_basic_map_get_dim(bmap));
+       dim = isl_space_domain(isl_basic_map_get_space(bmap));
 
        n_in = isl_basic_map_n_in(bmap);
        n_out = isl_basic_map_n_out(bmap);
        domain = isl_basic_set_from_basic_map(bmap);
        domain = isl_basic_set_project_out(domain, isl_dim_set, n_in, n_out);
 
-       domain = isl_basic_set_reset_dim(domain, dim);
+       domain = isl_basic_set_reset_space(domain, dim);
 
        return domain;
 }
@@ -3888,14 +4136,25 @@ int isl_basic_map_may_be_set(__isl_keep isl_basic_map *bmap)
 {
        if (!bmap)
                return -1;
-       return isl_dim_may_be_set(bmap->dim);
+       return isl_space_may_be_set(bmap->dim);
+}
+
+/* Is this basic map actually a set?
+ * Users should never call this function.  Outside of isl,
+ * the type should indicate whether something is a set or a map.
+ */
+int isl_basic_map_is_set(__isl_keep isl_basic_map *bmap)
+{
+       if (!bmap)
+               return -1;
+       return isl_space_is_set(bmap->dim);
 }
 
 struct isl_basic_set *isl_basic_map_range(struct isl_basic_map *bmap)
 {
        if (!bmap)
                return NULL;
-       if (isl_basic_map_may_be_set(bmap))
+       if (isl_basic_map_is_set(bmap))
                return bmap;
        return isl_basic_map_domain(isl_basic_map_reverse(bmap));
 }
@@ -3904,7 +4163,7 @@ __isl_give isl_basic_map *isl_basic_map_domain_map(
        __isl_take isl_basic_map *bmap)
 {
        int i, k;
-       isl_dim *dim;
+       isl_space *dim;
        isl_basic_map *domain;
        int nparam, n_in, n_out;
        unsigned total;
@@ -3913,7 +4172,7 @@ __isl_give isl_basic_map *isl_basic_map_domain_map(
        n_in = isl_basic_map_dim(bmap, isl_dim_in);
        n_out = isl_basic_map_dim(bmap, isl_dim_out);
 
-       dim = isl_dim_from_range(isl_dim_domain(isl_basic_map_get_dim(bmap)));
+       dim = isl_space_from_range(isl_space_domain(isl_basic_map_get_space(bmap)));
        domain = isl_basic_map_universe(dim);
 
        bmap = isl_basic_map_from_domain(isl_basic_map_wrap(bmap));
@@ -3942,7 +4201,7 @@ __isl_give isl_basic_map *isl_basic_map_range_map(
        __isl_take isl_basic_map *bmap)
 {
        int i, k;
-       isl_dim *dim;
+       isl_space *dim;
        isl_basic_map *range;
        int nparam, n_in, n_out;
        unsigned total;
@@ -3951,7 +4210,7 @@ __isl_give isl_basic_map *isl_basic_map_range_map(
        n_in = isl_basic_map_dim(bmap, isl_dim_in);
        n_out = isl_basic_map_dim(bmap, isl_dim_out);
 
-       dim = isl_dim_from_range(isl_dim_range(isl_basic_map_get_dim(bmap)));
+       dim = isl_space_from_range(isl_space_range(isl_basic_map_get_space(bmap)));
        range = isl_basic_map_universe(dim);
 
        bmap = isl_basic_map_from_domain(isl_basic_map_wrap(bmap));
@@ -3980,7 +4239,18 @@ int isl_map_may_be_set(__isl_keep isl_map *map)
 {
        if (!map)
                return -1;
-       return isl_dim_may_be_set(map->dim);
+       return isl_space_may_be_set(map->dim);
+}
+
+/* Is this map actually a set?
+ * Users should never call this function.  Outside of isl,
+ * the type should indicate whether something is a set or a map.
+ */
+int isl_map_is_set(__isl_keep isl_map *map)
+{
+       if (!map)
+               return -1;
+       return isl_space_is_set(map->dim);
 }
 
 struct isl_set *isl_map_range(struct isl_map *map)
@@ -3990,7 +4260,7 @@ struct isl_set *isl_map_range(struct isl_map *map)
 
        if (!map)
                goto error;
-       if (isl_map_may_be_set(map))
+       if (isl_map_is_set(map))
                return (isl_set *)map;
 
        map = isl_map_cow(map);
@@ -3998,7 +4268,7 @@ struct isl_set *isl_map_range(struct isl_map *map)
                goto error;
 
        set = (struct isl_set *) map;
-       set->dim = isl_dim_drop_inputs(set->dim, 0, set->dim->n_in);
+       set->dim = isl_space_range(set->dim);
        if (!set->dim)
                goto error;
        for (i = 0; i < map->n; ++i) {
@@ -4017,15 +4287,15 @@ error:
 __isl_give isl_map *isl_map_domain_map(__isl_take isl_map *map)
 {
        int i;
-       isl_dim *domain_dim;
+       isl_space *domain_dim;
 
        map = isl_map_cow(map);
        if (!map)
                return NULL;
 
-       domain_dim = isl_dim_from_range(isl_dim_domain(isl_map_get_dim(map)));
-       map->dim = isl_dim_from_domain(isl_dim_wrap(map->dim));
-       map->dim = isl_dim_join(map->dim, domain_dim);
+       domain_dim = isl_space_from_range(isl_space_domain(isl_map_get_space(map)));
+       map->dim = isl_space_from_domain(isl_space_wrap(map->dim));
+       map->dim = isl_space_join(map->dim, domain_dim);
        if (!map->dim)
                goto error;
        for (i = 0; i < map->n; ++i) {
@@ -4044,15 +4314,16 @@ error:
 __isl_give isl_map *isl_map_range_map(__isl_take isl_map *map)
 {
        int i;
-       isl_dim *range_dim;
+       isl_space *range_dim;
 
        map = isl_map_cow(map);
        if (!map)
                return NULL;
 
-       range_dim = isl_dim_range(isl_map_get_dim(map));
-       map->dim = isl_dim_from_domain(isl_dim_wrap(map->dim));
-       map->dim = isl_dim_join(map->dim, range_dim);
+       range_dim = isl_space_range(isl_map_get_space(map));
+       range_dim = isl_space_from_range(range_dim);
+       map->dim = isl_space_from_domain(isl_space_wrap(map->dim));
+       map->dim = isl_space_join(map->dim, range_dim);
        if (!map->dim)
                goto error;
        for (i = 0; i < map->n; ++i) {
@@ -4068,7 +4339,8 @@ error:
        return NULL;
 }
 
-struct isl_map *isl_map_from_set(struct isl_set *set, struct isl_dim *dim)
+__isl_give isl_map *isl_map_from_set(__isl_take isl_set *set,
+       __isl_take isl_space *dim)
 {
        int i;
        struct isl_map *map = NULL;
@@ -4076,19 +4348,19 @@ struct isl_map *isl_map_from_set(struct isl_set *set, struct isl_dim *dim)
        set = isl_set_cow(set);
        if (!set || !dim)
                goto error;
-       isl_assert(set->ctx, isl_dim_compatible(set->dim, dim), goto error);
+       isl_assert(set->ctx, isl_space_compatible(set->dim, dim), goto error);
        map = (struct isl_map *)set;
        for (i = 0; i < set->n; ++i) {
                map->p[i] = isl_basic_map_from_basic_set(
-                               set->p[i], isl_dim_copy(dim));
+                               set->p[i], isl_space_copy(dim));
                if (!map->p[i])
                        goto error;
        }
-       isl_dim_free(map->dim);
+       isl_space_free(map->dim);
        map->dim = dim;
        return map;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_set_free(set);
        return NULL;
 }
@@ -4102,11 +4374,19 @@ __isl_give isl_basic_map *isl_basic_map_from_domain(
 __isl_give isl_basic_map *isl_basic_map_from_range(
        __isl_take isl_basic_set *bset)
 {
+       isl_space *space;
+       space = isl_basic_set_get_space(bset);
+       space = isl_space_from_range(space);
+       bset = isl_basic_set_reset_space(bset, space);
        return (isl_basic_map *)bset;
 }
 
 struct isl_map *isl_map_from_range(struct isl_set *set)
 {
+       isl_space *space;
+       space = isl_set_get_space(set);
+       space = isl_space_from_range(space);
+       set = isl_set_reset_space(set, space);
        return (struct isl_map *)set;
 }
 
@@ -4118,15 +4398,13 @@ __isl_give isl_map *isl_map_from_domain(__isl_take isl_set *set)
 __isl_give isl_basic_map *isl_basic_map_from_domain_and_range(
        __isl_take isl_basic_set *domain, __isl_take isl_basic_set *range)
 {
-       return isl_basic_map_apply_range(isl_basic_map_from_domain(domain),
-                                        isl_basic_map_from_range(range));
+       return isl_basic_map_apply_range(isl_basic_map_reverse(domain), range);
 }
 
 __isl_give isl_map *isl_map_from_domain_and_range(__isl_take isl_set *domain,
        __isl_take isl_set *range)
 {
-       return isl_map_apply_range(isl_map_from_domain(domain),
-                                  isl_map_from_range(range));
+       return isl_map_apply_range(isl_map_reverse(domain), range);
 }
 
 struct isl_set *isl_set_from_map(struct isl_map *map)
@@ -4139,7 +4417,7 @@ struct isl_set *isl_set_from_map(struct isl_map *map)
        map = isl_map_cow(map);
        if (!map)
                return NULL;
-       map->dim = isl_dim_as_set_dim(map->dim);
+       map->dim = isl_space_as_set_space(map->dim);
        if (!map->dim)
                goto error;
        set = (struct isl_set *)map;
@@ -4154,7 +4432,8 @@ error:
        return NULL;
 }
 
-struct isl_map *isl_map_alloc_dim(struct isl_dim *dim, int n, unsigned flags)
+__isl_give isl_map *isl_map_alloc_space(__isl_take isl_space *dim, int n,
+       unsigned flags)
 {
        struct isl_map *map;
 
@@ -4176,7 +4455,7 @@ struct isl_map *isl_map_alloc_dim(struct isl_dim *dim, int n, unsigned flags)
        map->flags = flags;
        return map;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -4185,28 +4464,28 @@ struct isl_map *isl_map_alloc(struct isl_ctx *ctx,
                unsigned flags)
 {
        struct isl_map *map;
-       struct isl_dim *dims;
+       isl_space *dims;
 
-       dims = isl_dim_alloc(ctx, nparam, in, out);
+       dims = isl_space_alloc(ctx, nparam, in, out);
        if (!dims)
                return NULL;
 
-       map = isl_map_alloc_dim(dims, n, flags);
+       map = isl_map_alloc_space(dims, n, flags);
        return map;
 }
 
-struct isl_basic_map *isl_basic_map_empty(struct isl_dim *dim)
+__isl_give isl_basic_map *isl_basic_map_empty(__isl_take isl_space *dim)
 {
        struct isl_basic_map *bmap;
-       bmap = isl_basic_map_alloc_dim(dim, 0, 1, 0);
+       bmap = isl_basic_map_alloc_space(dim, 0, 1, 0);
        bmap = isl_basic_map_set_to_empty(bmap);
        return bmap;
 }
 
-struct isl_basic_set *isl_basic_set_empty(struct isl_dim *dim)
+__isl_give isl_basic_set *isl_basic_set_empty(__isl_take isl_space *dim)
 {
        struct isl_basic_set *bset;
-       bset = isl_basic_set_alloc_dim(dim, 0, 1, 0);
+       bset = isl_basic_set_alloc_space(dim, 0, 1, 0);
        bset = isl_basic_set_set_to_empty(bset);
        return bset;
 }
@@ -4216,7 +4495,7 @@ struct isl_basic_map *isl_basic_map_empty_like(struct isl_basic_map *model)
        struct isl_basic_map *bmap;
        if (!model)
                return NULL;
-       bmap = isl_basic_map_alloc_dim(isl_dim_copy(model->dim), 0, 1, 0);
+       bmap = isl_basic_map_alloc_space(isl_space_copy(model->dim), 0, 1, 0);
        bmap = isl_basic_map_set_to_empty(bmap);
        return bmap;
 }
@@ -4226,7 +4505,7 @@ struct isl_basic_map *isl_basic_map_empty_like_map(struct isl_map *model)
        struct isl_basic_map *bmap;
        if (!model)
                return NULL;
-       bmap = isl_basic_map_alloc_dim(isl_dim_copy(model->dim), 0, 1, 0);
+       bmap = isl_basic_map_alloc_space(isl_space_copy(model->dim), 0, 1, 0);
        bmap = isl_basic_map_set_to_empty(bmap);
        return bmap;
 }
@@ -4236,34 +4515,34 @@ struct isl_basic_set *isl_basic_set_empty_like(struct isl_basic_set *model)
        struct isl_basic_set *bset;
        if (!model)
                return NULL;
-       bset = isl_basic_set_alloc_dim(isl_dim_copy(model->dim), 0, 1, 0);
+       bset = isl_basic_set_alloc_space(isl_space_copy(model->dim), 0, 1, 0);
        bset = isl_basic_set_set_to_empty(bset);
        return bset;
 }
 
-struct isl_basic_map *isl_basic_map_universe(struct isl_dim *dim)
+__isl_give isl_basic_map *isl_basic_map_universe(__isl_take isl_space *dim)
 {
        struct isl_basic_map *bmap;
-       bmap = isl_basic_map_alloc_dim(dim, 0, 0, 0);
+       bmap = isl_basic_map_alloc_space(dim, 0, 0, 0);
        bmap = isl_basic_map_finalize(bmap);
        return bmap;
 }
 
-struct isl_basic_set *isl_basic_set_universe(struct isl_dim *dim)
+__isl_give isl_basic_set *isl_basic_set_universe(__isl_take isl_space *dim)
 {
        struct isl_basic_set *bset;
-       bset = isl_basic_set_alloc_dim(dim, 0, 0, 0);
+       bset = isl_basic_set_alloc_space(dim, 0, 0, 0);
        bset = isl_basic_set_finalize(bset);
        return bset;
 }
 
-__isl_give isl_basic_map *isl_basic_map_nat_universe(__isl_take isl_dim *dim)
+__isl_give isl_basic_map *isl_basic_map_nat_universe(__isl_take isl_space *dim)
 {
        int i;
-       unsigned total = isl_dim_total(dim);
+       unsigned total = isl_space_dim(dim, isl_dim_all);
        isl_basic_map *bmap;
 
-       bmap= isl_basic_map_alloc_dim(dim, 0, 0, total);
+       bmap= isl_basic_map_alloc_space(dim, 0, 0, total);
        for (i = 0; i < total; ++i) {
                int k = isl_basic_map_alloc_inequality(bmap);
                if (k < 0)
@@ -4277,17 +4556,17 @@ error:
        return NULL;
 }
 
-__isl_give isl_basic_set *isl_basic_set_nat_universe(__isl_take isl_dim *dim)
+__isl_give isl_basic_set *isl_basic_set_nat_universe(__isl_take isl_space *dim)
 {
        return isl_basic_map_nat_universe(dim);
 }
 
-__isl_give isl_map *isl_map_nat_universe(__isl_take isl_dim *dim)
+__isl_give isl_map *isl_map_nat_universe(__isl_take isl_space *dim)
 {
        return isl_map_from_basic_map(isl_basic_map_nat_universe(dim));
 }
 
-__isl_give isl_set *isl_set_nat_universe(__isl_take isl_dim *dim)
+__isl_give isl_set *isl_set_nat_universe(__isl_take isl_space *dim)
 {
        return isl_map_nat_universe(dim);
 }
@@ -4297,14 +4576,14 @@ __isl_give isl_basic_map *isl_basic_map_universe_like(
 {
        if (!model)
                return NULL;
-       return isl_basic_map_alloc_dim(isl_dim_copy(model->dim), 0, 0, 0);
+       return isl_basic_map_alloc_space(isl_space_copy(model->dim), 0, 0, 0);
 }
 
 struct isl_basic_set *isl_basic_set_universe_like(struct isl_basic_set *model)
 {
        if (!model)
                return NULL;
-       return isl_basic_set_alloc_dim(isl_dim_copy(model->dim), 0, 0, 0);
+       return isl_basic_set_alloc_space(isl_space_copy(model->dim), 0, 0, 0);
 }
 
 __isl_give isl_basic_set *isl_basic_set_universe_like_set(
@@ -4312,56 +4591,56 @@ __isl_give isl_basic_set *isl_basic_set_universe_like_set(
 {
        if (!model)
                return NULL;
-       return isl_basic_set_alloc_dim(isl_dim_copy(model->dim), 0, 0, 0);
+       return isl_basic_set_alloc_space(isl_space_copy(model->dim), 0, 0, 0);
 }
 
-struct isl_map *isl_map_empty(struct isl_dim *dim)
+__isl_give isl_map *isl_map_empty(__isl_take isl_space *dim)
 {
-       return isl_map_alloc_dim(dim, 0, ISL_MAP_DISJOINT);
+       return isl_map_alloc_space(dim, 0, ISL_MAP_DISJOINT);
 }
 
 struct isl_map *isl_map_empty_like(struct isl_map *model)
 {
        if (!model)
                return NULL;
-       return isl_map_alloc_dim(isl_dim_copy(model->dim), 0, ISL_MAP_DISJOINT);
+       return isl_map_alloc_space(isl_space_copy(model->dim), 0, ISL_MAP_DISJOINT);
 }
 
 struct isl_map *isl_map_empty_like_basic_map(struct isl_basic_map *model)
 {
        if (!model)
                return NULL;
-       return isl_map_alloc_dim(isl_dim_copy(model->dim), 0, ISL_MAP_DISJOINT);
+       return isl_map_alloc_space(isl_space_copy(model->dim), 0, ISL_MAP_DISJOINT);
 }
 
-struct isl_set *isl_set_empty(struct isl_dim *dim)
+__isl_give isl_set *isl_set_empty(__isl_take isl_space *dim)
 {
-       return isl_set_alloc_dim(dim, 0, ISL_MAP_DISJOINT);
+       return isl_set_alloc_space(dim, 0, ISL_MAP_DISJOINT);
 }
 
 struct isl_set *isl_set_empty_like(struct isl_set *model)
 {
        if (!model)
                return NULL;
-       return isl_set_empty(isl_dim_copy(model->dim));
+       return isl_set_empty(isl_space_copy(model->dim));
 }
 
-struct isl_map *isl_map_universe(struct isl_dim *dim)
+__isl_give isl_map *isl_map_universe(__isl_take isl_space *dim)
 {
        struct isl_map *map;
        if (!dim)
                return NULL;
-       map = isl_map_alloc_dim(isl_dim_copy(dim), 1, ISL_MAP_DISJOINT);
+       map = isl_map_alloc_space(isl_space_copy(dim), 1, ISL_MAP_DISJOINT);
        map = isl_map_add_basic_map(map, isl_basic_map_universe(dim));
        return map;
 }
 
-struct isl_set *isl_set_universe(struct isl_dim *dim)
+__isl_give isl_set *isl_set_universe(__isl_take isl_space *dim)
 {
        struct isl_set *set;
        if (!dim)
                return NULL;
-       set = isl_set_alloc_dim(isl_dim_copy(dim), 1, ISL_MAP_DISJOINT);
+       set = isl_set_alloc_space(isl_space_copy(dim), 1, ISL_MAP_DISJOINT);
        set = isl_set_add_basic_set(set, isl_basic_set_universe(dim));
        return set;
 }
@@ -4370,7 +4649,7 @@ __isl_give isl_set *isl_set_universe_like(__isl_keep isl_set *model)
 {
        if (!model)
                return NULL;
-       return isl_set_universe(isl_dim_copy(model->dim));
+       return isl_set_universe(isl_space_copy(model->dim));
 }
 
 struct isl_map *isl_map_dup(struct isl_map *map)
@@ -4380,7 +4659,7 @@ struct isl_map *isl_map_dup(struct isl_map *map)
 
        if (!map)
                return NULL;
-       dup = isl_map_alloc_dim(isl_dim_copy(map->dim), map->n, map->flags);
+       dup = isl_map_alloc_space(isl_space_copy(map->dim), map->n, map->flags);
        for (i = 0; i < map->n; ++i)
                dup = isl_map_add_basic_map(dup, isl_basic_map_copy(map->p[i]));
        return dup;
@@ -4395,7 +4674,7 @@ __isl_give isl_map *isl_map_add_basic_map(__isl_take isl_map *map,
                isl_basic_map_free(bmap);
                return map;
        }
-       isl_assert(map->ctx, isl_dim_equal(map->dim, bmap->dim), goto error);
+       isl_assert(map->ctx, isl_space_is_equal(map->dim, bmap->dim), goto error);
        isl_assert(map->ctx, map->n < map->size, goto error);
        map->p[map->n] = bmap;
        map->n++;
@@ -4422,7 +4701,7 @@ void isl_map_free(struct isl_map *map)
        isl_ctx_deref(map->ctx);
        for (i = 0; i < map->n; ++i)
                isl_basic_map_free(map->p[i]);
-       isl_dim_free(map->dim);
+       isl_space_free(map->dim);
        free(map);
 }
 
@@ -4435,12 +4714,12 @@ struct isl_map *isl_map_extend(struct isl_map *base,
        if (!base)
                return NULL;
 
-       base->dim = isl_dim_extend(base->dim, nparam, n_in, n_out);
+       base->dim = isl_space_extend(base->dim, nparam, n_in, n_out);
        if (!base->dim)
                goto error;
        for (i = 0; i < base->n; ++i) {
-               base->p[i] = isl_basic_map_extend_dim(base->p[i],
-                               isl_dim_copy(base->dim), 0, 0, 0);
+               base->p[i] = isl_basic_map_extend_space(base->p[i],
+                               isl_space_copy(base->dim), 0, 0, 0);
                if (!base->p[i])
                        goto error;
        }
@@ -4726,7 +5005,7 @@ struct isl_map *isl_map_reverse(struct isl_map *map)
        if (!map)
                return NULL;
 
-       map->dim = isl_dim_reverse(map->dim);
+       map->dim = isl_space_reverse(map->dim);
        if (!map->dim)
                goto error;
        for (i = 0; i < map->n; ++i) {
@@ -4896,7 +5175,7 @@ error:
  * even when the domain of basic map i is disjoint from the domains of
  * the previous basic maps.
  */
-static __isl_give isl_map *isl_map_partial_lexopt(
+static __isl_give isl_map *isl_map_partial_lexopt_aligned(
                __isl_take isl_map *map, __isl_take isl_set *dom,
                __isl_give isl_set **empty, int max)
 {
@@ -4922,16 +5201,16 @@ static __isl_give isl_map *isl_map_partial_lexopt(
                isl_map *lt, *le;
                isl_map *res_i;
                isl_set *todo_i;
-               isl_dim *dim = isl_dim_range(isl_map_get_dim(res));
+               isl_space *dim = isl_space_range(isl_map_get_space(res));
 
                res_i = basic_map_partial_lexopt(isl_basic_map_copy(map->p[i]),
                                        isl_set_copy(dom), &todo_i, max);
 
                if (max) {
-                       lt = isl_map_lex_lt(isl_dim_copy(dim));
+                       lt = isl_map_lex_lt(isl_space_copy(dim));
                        le = isl_map_lex_le(dim);
                } else {
-                       lt = isl_map_lex_gt(isl_dim_copy(dim));
+                       lt = isl_map_lex_gt(isl_space_copy(dim));
                        le = isl_map_lex_ge(dim);
                }
                lt = isl_map_apply_range(isl_map_copy(res), lt);
@@ -4970,6 +5249,35 @@ error:
        return NULL;
 }
 
+/* Given a map "map", compute the lexicographically minimal
+ * (or maximal) image element for each domain element in dom.
+ * Set *empty to those elements in dom that do not have an image element.
+ *
+ * Align parameters if needed and then call isl_map_partial_lexopt_aligned.
+ */
+static __isl_give isl_map *isl_map_partial_lexopt(
+               __isl_take isl_map *map, __isl_take isl_set *dom,
+               __isl_give isl_set **empty, int max)
+{
+       if (!map || !dom)
+               goto error;
+       if (isl_space_match(map->dim, isl_dim_param, dom->dim, isl_dim_param))
+               return isl_map_partial_lexopt_aligned(map, dom, empty, max);
+       if (!isl_space_has_named_params(map->dim) ||
+           !isl_space_has_named_params(dom->dim))
+               isl_die(map->ctx, isl_error_invalid,
+                       "unaligned unnamed parameters", goto error);
+       map = isl_map_align_params(map, isl_map_get_space(dom));
+       dom = isl_map_align_params(dom, isl_map_get_space(map));
+       return isl_map_partial_lexopt_aligned(map, dom, empty, max);
+error:
+       if (empty)
+               *empty = NULL;
+       isl_set_free(dom);
+       isl_map_free(map);
+       return NULL;
+}
+
 __isl_give isl_map *isl_map_partial_lexmax(
                __isl_take isl_map *map, __isl_take isl_set *dom,
                __isl_give isl_set **empty)
@@ -5005,11 +5313,11 @@ __isl_give isl_set *isl_set_partial_lexmax(
 __isl_give isl_map *isl_basic_map_lexopt(__isl_take isl_basic_map *bmap, int max)
 {
        struct isl_basic_set *dom = NULL;
-       struct isl_dim *dom_dim;
+       isl_space *dom_dim;
 
        if (!bmap)
                goto error;
-       dom_dim = isl_dim_domain(isl_dim_copy(bmap->dim));
+       dom_dim = isl_space_domain(isl_space_copy(bmap->dim));
        dom = isl_basic_set_universe(dom_dim);
        return isl_basic_map_partial_lexopt(bmap, dom, NULL, max);
 error:
@@ -5040,11 +5348,11 @@ __isl_give isl_set *isl_basic_set_lexmax(__isl_take isl_basic_set *bset)
 __isl_give isl_map *isl_map_lexopt(__isl_take isl_map *map, int max)
 {
        struct isl_set *dom = NULL;
-       struct isl_dim *dom_dim;
+       isl_space *dom_dim;
 
        if (!map)
                goto error;
-       dom_dim = isl_dim_domain(isl_dim_copy(map->dim));
+       dom_dim = isl_space_domain(isl_space_copy(map->dim));
        dom = isl_set_universe(dom_dim);
        return isl_map_partial_lexopt(map, dom, NULL, max);
 error:
@@ -5074,14 +5382,14 @@ __isl_give isl_set *isl_set_lexmax(__isl_take isl_set *set)
 
 /* Construct a map that equates the two given dimensions in the given space.
  */
-static __isl_give isl_map *equate(__isl_take isl_dim *dim,
+static __isl_give isl_map *equate(__isl_take isl_space *dim,
        enum isl_dim_type src_type, int src_pos,
        enum isl_dim_type dst_type, int dst_pos)
 {
        isl_basic_map *bmap;
        int k;
 
-       bmap = isl_basic_map_alloc_dim(dim, 0, 1, 0);
+       bmap = isl_basic_map_alloc_space(dim, 0, 1, 0);
        k = isl_basic_map_alloc_equality(bmap);
        if (k < 0)
                goto error;
@@ -5102,7 +5410,7 @@ error:
  * This domain is known to be disjoint from other domains
  * because of the way isl_basic_set_foreach_lexmax works.
  */
-static int update_dim_max(__isl_take isl_basic_set *dom,
+static int update_dim_opt(__isl_take isl_basic_set *dom,
        __isl_take isl_aff_list *list, void *user)
 {
        isl_ctx *ctx = isl_basic_set_get_ctx(dom);
@@ -5128,36 +5436,40 @@ error:
        return -1;
 }
 
-/* Given a one-dimensional basic set, compute the maximum of that
+/* Given a one-dimensional basic set, compute the minimum or maximum of that
  * dimension as an isl_pw_aff.
  *
- * The isl_pw_aff is constructed by having isl_basic_set_foreach_lexmax
- * call update_dim_max on each leaf of the result.
+ * The isl_pw_aff is constructed by having isl_basic_set_foreach_lexopt
+ * call update_dim_opt on each leaf of the result.
  */
-static __isl_give isl_pw_aff *basic_set_dim_max(__isl_keep isl_basic_set *bset)
+static __isl_give isl_pw_aff *basic_set_dim_opt(__isl_keep isl_basic_set *bset,
+       int max)
 {
-       isl_dim *dim = isl_basic_set_get_dim(bset);
+       isl_space *dim = isl_basic_set_get_space(bset);
        isl_pw_aff *pwaff;
        int r;
 
-       dim = isl_dim_domain(isl_dim_from_range(dim));
+       dim = isl_space_params(dim);
+       dim = isl_space_add_dims(dim, isl_dim_set, 1);
        pwaff = isl_pw_aff_empty(dim);
 
-       r = isl_basic_set_foreach_lexmax(bset, &update_dim_max, &pwaff);
+       r = isl_basic_set_foreach_lexopt(bset, max, &update_dim_opt, &pwaff);
        if (r < 0)
                return isl_pw_aff_free(pwaff);
 
        return pwaff;
 }
 
-/* Compute the maximum of the given set dimension as a function of the
- * parameters, but independently of the other set dimensions.
+/* Compute the minimum or maximum of the given set dimension
+ * as a function of the parameters, but independently of
+ * the other set dimensions.
  *
  * We first project the set onto the given dimension and then compute
  * the "lexicographic" maximum in each basic set, combining the results
- * using isl_pw_aff_max.
+ * using isl_pw_aff_union_max.
  */
-__isl_give isl_pw_aff *isl_set_dim_max(__isl_take isl_set *set, int pos)
+static __isl_give isl_pw_aff *set_dim_opt(__isl_take isl_set *set, int pos,
+       int max)
 {
        int i;
        isl_map *map;
@@ -5166,25 +5478,25 @@ __isl_give isl_pw_aff *isl_set_dim_max(__isl_take isl_set *set, int pos)
        map = isl_map_from_domain(set);
        map = isl_map_add_dims(map, isl_dim_out, 1);
        map = isl_map_intersect(map,
-               equate(isl_map_get_dim(map), isl_dim_in, pos,
+               equate(isl_map_get_space(map), isl_dim_in, pos,
                                             isl_dim_out, 0));
        set = isl_map_range(map);
        if (!set)
                return NULL;
 
        if (set->n == 0) {
-               isl_dim *dim = isl_set_get_dim(set);
-               dim = isl_dim_domain(isl_dim_from_range(dim));
+               isl_space *dim = isl_set_get_space(set);
+               dim = isl_space_domain(isl_space_from_range(dim));
                isl_set_free(set);
                return isl_pw_aff_empty(dim);
        }
 
-       pwaff = basic_set_dim_max(set->p[0]);
+       pwaff = basic_set_dim_opt(set->p[0], max);
        for (i = 1; i < set->n; ++i) {
                isl_pw_aff *pwaff_i;
 
-               pwaff_i = basic_set_dim_max(set->p[i]);
-               pwaff = isl_pw_aff_max(pwaff, pwaff_i);
+               pwaff_i = basic_set_dim_opt(set->p[i], max);
+               pwaff = isl_pw_aff_union_opt(pwaff, pwaff_i, max);
        }
 
        isl_set_free(set);
@@ -5192,6 +5504,22 @@ __isl_give isl_pw_aff *isl_set_dim_max(__isl_take isl_set *set, int pos)
        return pwaff;
 }
 
+/* Compute the maximum of the given set dimension as a function of the
+ * parameters, but independently of the other set dimensions.
+ */
+__isl_give isl_pw_aff *isl_set_dim_max(__isl_take isl_set *set, int pos)
+{
+       return set_dim_opt(set, pos, 1);
+}
+
+/* Compute the minimum of the given set dimension as a function of the
+ * parameters, but independently of the other set dimensions.
+ */
+__isl_give isl_pw_aff *isl_set_dim_min(__isl_take isl_set *set, int pos)
+{
+       return set_dim_opt(set, pos, 0);
+}
+
 /* Apply a preimage specified by "mat" on the parameters of "bset".
  * bset is assumed to have only parameters and divs.
  */
@@ -5203,7 +5531,7 @@ static struct isl_basic_set *basic_set_parameter_preimage(
        if (!bset || !mat)
                goto error;
 
-       bset->dim = isl_dim_cow(bset->dim);
+       bset->dim = isl_space_cow(bset->dim);
        if (!bset->dim)
                goto error;
 
@@ -5231,14 +5559,14 @@ error:
 static struct isl_set *set_parameter_preimage(
        struct isl_set *set, struct isl_mat *mat)
 {
-       struct isl_dim *dim = NULL;
+       isl_space *dim = NULL;
        unsigned nparam;
 
        if (!set || !mat)
                goto error;
 
-       dim = isl_dim_copy(set->dim);
-       dim = isl_dim_cow(dim);
+       dim = isl_space_copy(set->dim);
+       dim = isl_space_cow(dim);
        if (!dim)
                goto error;
 
@@ -5248,20 +5576,20 @@ static struct isl_set *set_parameter_preimage(
 
        dim->nparam = 0;
        dim->n_out = nparam;
-       isl_set_reset_dim(set, dim);
+       isl_set_reset_space(set, dim);
        set = isl_set_preimage(set, mat);
        if (!set)
                goto error2;
-       dim = isl_dim_copy(set->dim);
-       dim = isl_dim_cow(dim);
+       dim = isl_space_copy(set->dim);
+       dim = isl_space_cow(dim);
        if (!dim)
                goto error2;
        dim->nparam = dim->n_out;
        dim->n_out = 0;
-       isl_set_reset_dim(set, dim);
+       isl_set_reset_space(set, dim);
        return set;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_mat_free(mat);
 error2:
        isl_set_free(set);
@@ -5280,12 +5608,12 @@ static struct isl_basic_set *basic_set_append_equalities(
        if (!bset || !eq)
                goto error;
 
-       bset = isl_basic_set_extend_dim(bset, isl_dim_copy(bset->dim), 0,
+       bset = isl_basic_set_extend_space(bset, isl_space_copy(bset->dim), 0,
                                        eq->n_row, 0);
        if (!bset)
                goto error;
 
-       len = 1 + isl_dim_total(bset->dim) + bset->extra;
+       len = 1 + isl_space_dim(bset->dim, isl_dim_all) + bset->extra;
        for (i = 0; i < eq->n_row; ++i) {
                k = isl_basic_set_alloc_equality(bset);
                if (k < 0)
@@ -5400,7 +5728,7 @@ static struct isl_map *compute_divs(struct isl_basic_map *bmap)
        struct isl_basic_set *bset;
        struct isl_set *set;
        struct isl_map *map;
-       struct isl_dim *dim, *orig_dim = NULL;
+       isl_space *dim, *orig_dim = NULL;
        unsigned         nparam;
        unsigned         n_in;
        unsigned         n_out;
@@ -5412,7 +5740,7 @@ static struct isl_map *compute_divs(struct isl_basic_map *bmap)
        nparam = isl_basic_map_dim(bmap, isl_dim_param);
        n_in = isl_basic_map_dim(bmap, isl_dim_in);
        n_out = isl_basic_map_dim(bmap, isl_dim_out);
-       dim = isl_dim_set_alloc(bmap->ctx, nparam + n_in + n_out, 0);
+       dim = isl_space_set_alloc(bmap->ctx, nparam + n_in + n_out, 0);
        if (!dim)
                goto error;
 
@@ -5422,7 +5750,7 @@ static struct isl_map *compute_divs(struct isl_basic_map *bmap)
 
        set = parameter_compute_divs(bset);
        map = (struct isl_map *)set;
-       map = isl_map_reset_dim(map, orig_dim);
+       map = isl_map_reset_space(map, orig_dim);
 
        return map;
 error:
@@ -5438,7 +5766,7 @@ int isl_basic_map_divs_known(__isl_keep isl_basic_map *bmap)
        if (!bmap)
                return -1;
 
-       off = isl_dim_total(bmap->dim);
+       off = isl_space_dim(bmap->dim, isl_dim_all);
        for (i = 0; i < bmap->n_div; ++i) {
                if (isl_int_is_zero(bmap->div[i][0]))
                        return 0;
@@ -5553,7 +5881,7 @@ struct isl_set *isl_map_domain(struct isl_map *map)
                return NULL;
 
        set = (struct isl_set *)map;
-       set->dim = isl_dim_domain(set->dim);
+       set->dim = isl_space_domain(set->dim);
        if (!set->dim)
                goto error;
        for (i = 0; i < map->n; ++i) {
@@ -5569,8 +5897,8 @@ error:
        return NULL;
 }
 
-struct isl_map *isl_map_union_disjoint(
-                       struct isl_map *map1, struct isl_map *map2)
+static __isl_give isl_map *map_union_disjoint(__isl_take isl_map *map1,
+       __isl_take isl_map *map2)
 {
        int i;
        unsigned flags = 0;
@@ -5588,13 +5916,13 @@ struct isl_map *isl_map_union_disjoint(
                return map1;
        }
 
-       isl_assert(map1->ctx, isl_dim_equal(map1->dim, map2->dim), goto error);
+       isl_assert(map1->ctx, isl_space_is_equal(map1->dim, map2->dim), goto error);
 
        if (ISL_F_ISSET(map1, ISL_MAP_DISJOINT) &&
            ISL_F_ISSET(map2, ISL_MAP_DISJOINT))
                ISL_FL_SET(flags, ISL_MAP_DISJOINT);
 
-       map = isl_map_alloc_dim(isl_dim_copy(map1->dim),
+       map = isl_map_alloc_space(isl_space_copy(map1->dim),
                                map1->n + map2->n, flags);
        if (!map)
                goto error;
@@ -5620,6 +5948,12 @@ error:
        return NULL;
 }
 
+__isl_give isl_map *isl_map_union_disjoint(__isl_take isl_map *map1,
+       __isl_take isl_map *map2)
+{
+       return isl_map_align_params_map_map_and(map1, map2, &map_union_disjoint);
+}
+
 struct isl_map *isl_map_union(struct isl_map *map1, struct isl_map *map2)
 {
        map1 = isl_map_union_disjoint(map1, map2);
@@ -5644,8 +5978,8 @@ struct isl_set *isl_set_union(struct isl_set *set1, struct isl_set *set2)
                isl_map_union((struct isl_map *)set1, (struct isl_map *)set2);
 }
 
-struct isl_map *isl_map_intersect_range(
-               struct isl_map *map, struct isl_set *set)
+static __isl_give isl_map *map_intersect_range(__isl_take isl_map *map,
+       __isl_take isl_set *set)
 {
        unsigned flags = 0;
        struct isl_map *result;
@@ -5654,11 +5988,11 @@ struct isl_map *isl_map_intersect_range(
        if (!map || !set)
                goto error;
 
-       if (!isl_dim_match(map->dim, isl_dim_param, set->dim, isl_dim_param))
+       if (!isl_space_match(map->dim, isl_dim_param, set->dim, isl_dim_param))
                isl_die(set->ctx, isl_error_invalid,
                        "parameters don't match", goto error);
 
-       if (isl_dim_size(set->dim, isl_dim_set) != 0 &&
+       if (isl_space_dim(set->dim, isl_dim_set) != 0 &&
            !isl_map_compatible_range(map, set))
                isl_die(set->ctx, isl_error_invalid,
                        "incompatible spaces", goto error);
@@ -5672,7 +6006,7 @@ struct isl_map *isl_map_intersect_range(
            ISL_F_ISSET(set, ISL_MAP_DISJOINT))
                ISL_FL_SET(flags, ISL_MAP_DISJOINT);
 
-       result = isl_map_alloc_dim(isl_dim_copy(map->dim),
+       result = isl_map_alloc_space(isl_space_copy(map->dim),
                                        map->n * set->n, flags);
        if (!result)
                goto error;
@@ -5694,6 +6028,12 @@ error:
        return NULL;
 }
 
+__isl_give isl_map *isl_map_intersect_range(__isl_take isl_map *map,
+       __isl_take isl_set *set)
+{
+       return isl_map_align_params_map_map_and(map, set, &map_intersect_range);
+}
+
 struct isl_map *isl_map_intersect_domain(
                struct isl_map *map, struct isl_set *set)
 {
@@ -5701,8 +6041,8 @@ struct isl_map *isl_map_intersect_domain(
                isl_map_intersect_range(isl_map_reverse(map), set));
 }
 
-struct isl_map *isl_map_apply_domain(
-               struct isl_map *map1, struct isl_map *map2)
+static __isl_give isl_map *map_apply_domain(__isl_take isl_map *map1,
+       __isl_take isl_map *map2)
 {
        if (!map1 || !map2)
                goto error;
@@ -5715,20 +6055,26 @@ error:
        return NULL;
 }
 
-struct isl_map *isl_map_apply_range(
-               struct isl_map *map1, struct isl_map *map2)
+__isl_give isl_map *isl_map_apply_domain(__isl_take isl_map *map1,
+       __isl_take isl_map *map2)
 {
-       struct isl_dim *dim_result;
+       return isl_map_align_params_map_map_and(map1, map2, &map_apply_domain);
+}
+
+static __isl_give isl_map *map_apply_range(__isl_take isl_map *map1,
+       __isl_take isl_map *map2)
+{
+       isl_space *dim_result;
        struct isl_map *result;
        int i, j;
 
        if (!map1 || !map2)
                goto error;
 
-       dim_result = isl_dim_join(isl_dim_copy(map1->dim),
-                                 isl_dim_copy(map2->dim));
+       dim_result = isl_space_join(isl_space_copy(map1->dim),
+                                 isl_space_copy(map2->dim));
 
-       result = isl_map_alloc_dim(dim_result, map1->n * map2->n, 0);
+       result = isl_map_alloc_space(dim_result, map1->n * map2->n, 0);
        if (!result)
                goto error;
        for (i = 0; i < map1->n; ++i)
@@ -5751,12 +6097,18 @@ error:
        return NULL;
 }
 
+__isl_give isl_map *isl_map_apply_range(__isl_take isl_map *map1,
+       __isl_take isl_map *map2)
+{
+       return isl_map_align_params_map_map_and(map1, map2, &map_apply_range);
+}
+
 /*
  * returns range - domain
  */
 struct isl_basic_set *isl_basic_map_deltas(struct isl_basic_map *bmap)
 {
-       isl_dim *dims, *target_dim;
+       isl_space *dims, *target_dim;
        struct isl_basic_set *bset;
        unsigned dim;
        unsigned nparam;
@@ -5764,17 +6116,17 @@ struct isl_basic_set *isl_basic_map_deltas(struct isl_basic_map *bmap)
 
        if (!bmap)
                goto error;
-       isl_assert(bmap->ctx, isl_dim_tuple_match(bmap->dim, isl_dim_in,
+       isl_assert(bmap->ctx, isl_space_tuple_match(bmap->dim, isl_dim_in,
                                                  bmap->dim, isl_dim_out),
                   goto error);
-       target_dim = isl_dim_domain(isl_basic_map_get_dim(bmap));
+       target_dim = isl_space_domain(isl_basic_map_get_space(bmap));
        dim = isl_basic_map_n_in(bmap);
        nparam = isl_basic_map_n_param(bmap);
        bset = isl_basic_set_from_basic_map(bmap);
        bset = isl_basic_set_cow(bset);
-       dims = isl_basic_set_get_dim(bset);
-       dims = isl_dim_add(dims, isl_dim_set, dim);
-       bset = isl_basic_set_extend_dim(bset, dims, 0, dim, 0);
+       dims = isl_basic_set_get_space(bset);
+       dims = isl_space_add_dims(dims, isl_dim_set, dim);
+       bset = isl_basic_set_extend_space(bset, dims, 0, dim, 0);
        bset = isl_basic_set_swap_vars(bset, 2*dim);
        for (i = 0; i < dim; ++i) {
                int j = isl_basic_map_alloc_equality(
@@ -5787,7 +6139,7 @@ struct isl_basic_set *isl_basic_map_deltas(struct isl_basic_map *bmap)
                isl_int_set_si(bset->eq[j][1+nparam+2*dim+i], -1);
        }
        bset = isl_basic_set_project_out(bset, isl_dim_set, dim, 2*dim);
-       bset = isl_basic_set_reset_dim(bset, target_dim);
+       bset = isl_basic_set_reset_space(bset, target_dim);
        return bset;
 error:
        isl_basic_map_free(bmap);
@@ -5800,18 +6152,18 @@ error:
 struct isl_set *isl_map_deltas(struct isl_map *map)
 {
        int i;
-       isl_dim *dim;
+       isl_space *dim;
        struct isl_set *result;
 
        if (!map)
                return NULL;
 
-       isl_assert(map->ctx, isl_dim_tuple_match(map->dim, isl_dim_in,
+       isl_assert(map->ctx, isl_space_tuple_match(map->dim, isl_dim_in,
                                                 map->dim, isl_dim_out),
                   goto error);
-       dim = isl_map_get_dim(map);
-       dim = isl_dim_domain(dim);
-       result = isl_set_alloc_dim(dim, map->n, 0);
+       dim = isl_map_get_space(map);
+       dim = isl_space_domain(dim);
+       result = isl_set_alloc_space(dim, map->n, 0);
        if (!result)
                goto error;
        for (i = 0; i < map->n; ++i)
@@ -5831,19 +6183,19 @@ __isl_give isl_basic_map *isl_basic_map_deltas_map(
        __isl_take isl_basic_map *bmap)
 {
        int i, k;
-       isl_dim *dim;
+       isl_space *dim;
        isl_basic_map *domain;
        int nparam, n;
        unsigned total;
 
-       if (!isl_dim_tuple_match(bmap->dim, isl_dim_in, bmap->dim, isl_dim_out))
+       if (!isl_space_tuple_match(bmap->dim, isl_dim_in, bmap->dim, isl_dim_out))
                isl_die(bmap->ctx, isl_error_invalid,
                        "domain and range don't match", goto error);
 
        nparam = isl_basic_map_dim(bmap, isl_dim_param);
        n = isl_basic_map_dim(bmap, isl_dim_in);
 
-       dim = isl_dim_from_range(isl_dim_domain(isl_basic_map_get_dim(bmap)));
+       dim = isl_space_from_range(isl_space_domain(isl_basic_map_get_space(bmap)));
        domain = isl_basic_map_universe(dim);
 
        bmap = isl_basic_map_from_domain(isl_basic_map_wrap(bmap));
@@ -5875,12 +6227,12 @@ error:
 __isl_give isl_map *isl_map_deltas_map(__isl_take isl_map *map)
 {
        int i;
-       isl_dim *domain_dim;
+       isl_space *domain_dim;
 
        if (!map)
                return NULL;
 
-       if (!isl_dim_tuple_match(map->dim, isl_dim_in, map->dim, isl_dim_out))
+       if (!isl_space_tuple_match(map->dim, isl_dim_in, map->dim, isl_dim_out))
                isl_die(map->ctx, isl_error_invalid,
                        "domain and range don't match", goto error);
 
@@ -5888,9 +6240,9 @@ __isl_give isl_map *isl_map_deltas_map(__isl_take isl_map *map)
        if (!map)
                return NULL;
 
-       domain_dim = isl_dim_from_range(isl_dim_domain(isl_map_get_dim(map)));
-       map->dim = isl_dim_from_domain(isl_dim_wrap(map->dim));
-       map->dim = isl_dim_join(map->dim, domain_dim);
+       domain_dim = isl_space_from_range(isl_space_domain(isl_map_get_space(map)));
+       map->dim = isl_space_from_domain(isl_space_wrap(map->dim));
+       map->dim = isl_space_join(map->dim, domain_dim);
        if (!map->dim)
                goto error;
        for (i = 0; i < map->n; ++i) {
@@ -5905,7 +6257,7 @@ error:
        return NULL;
 }
 
-static struct isl_basic_map *basic_map_identity(struct isl_dim *dims)
+__isl_give struct isl_basic_map *basic_map_identity(__isl_take isl_space *dims)
 {
        struct isl_basic_map *bmap;
        unsigned nparam;
@@ -5917,7 +6269,7 @@ static struct isl_basic_map *basic_map_identity(struct isl_dim *dims)
 
        nparam = dims->nparam;
        dim = dims->n_out;
-       bmap = isl_basic_map_alloc_dim(dims, 0, dim, 0);
+       bmap = isl_basic_map_alloc_space(dims, 0, dim, 0);
        if (!bmap)
                goto error;
 
@@ -5935,7 +6287,7 @@ error:
        return NULL;
 }
 
-__isl_give isl_basic_map *isl_basic_map_identity(__isl_take isl_dim *dim)
+__isl_give isl_basic_map *isl_basic_map_identity(__isl_take isl_space *dim)
 {
        if (!dim)
                return NULL;
@@ -5945,7 +6297,7 @@ __isl_give isl_basic_map *isl_basic_map_identity(__isl_take isl_dim *dim)
                        "the same", goto error);
        return basic_map_identity(dim);
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -5953,10 +6305,10 @@ struct isl_basic_map *isl_basic_map_identity_like(struct isl_basic_map *model)
 {
        if (!model || !model->dim)
                return NULL;
-       return isl_basic_map_identity(isl_dim_copy(model->dim));
+       return isl_basic_map_identity(isl_space_copy(model->dim));
 }
 
-__isl_give isl_map *isl_map_identity(__isl_take isl_dim *dim)
+__isl_give isl_map *isl_map_identity(__isl_take isl_space *dim)
 {
        return isl_map_from_basic_map(isl_basic_map_identity(dim));
 }
@@ -5965,39 +6317,40 @@ struct isl_map *isl_map_identity_like(struct isl_map *model)
 {
        if (!model || !model->dim)
                return NULL;
-       return isl_map_identity(isl_dim_copy(model->dim));
+       return isl_map_identity(isl_space_copy(model->dim));
 }
 
 struct isl_map *isl_map_identity_like_basic_map(struct isl_basic_map *model)
 {
        if (!model || !model->dim)
                return NULL;
-       return isl_map_identity(isl_dim_copy(model->dim));
+       return isl_map_identity(isl_space_copy(model->dim));
 }
 
 __isl_give isl_map *isl_set_identity(__isl_take isl_set *set)
 {
-       isl_dim *dim = isl_set_get_dim(set);
+       isl_space *dim = isl_set_get_space(set);
        isl_map *id;
-       id = isl_map_identity(isl_dim_map_from_set(dim));
+       id = isl_map_identity(isl_space_map_from_set(dim));
        return isl_map_intersect_range(id, set);
 }
 
 /* Construct a basic set with all set dimensions having only non-negative
  * values.
  */
-struct isl_basic_set *isl_basic_set_positive_orthant(struct isl_dim *dims)
+__isl_give isl_basic_set *isl_basic_set_positive_orthant(
+       __isl_take isl_space *space)
 {
        int i;
        unsigned nparam;
        unsigned dim;
        struct isl_basic_set *bset;
 
-       if (!dims)
+       if (!space)
                return NULL;
-       nparam = dims->nparam;
-       dim = dims->n_out;
-       bset = isl_basic_set_alloc_dim(dims, 0, 0, dim);
+       nparam = space->nparam;
+       dim = space->n_out;
+       bset = isl_basic_set_alloc_space(space, 0, 0, dim);
        if (!bset)
                return NULL;
        for (i = 0; i < dim; ++i) {
@@ -6015,13 +6368,13 @@ error:
 
 /* Construct the half-space x_pos >= 0.
  */
-static __isl_give isl_basic_set *nonneg_halfspace(__isl_take isl_dim *dim,
+static __isl_give isl_basic_set *nonneg_halfspace(__isl_take isl_space *dim,
        int pos)
 {
        int k;
        isl_basic_set *nonneg;
 
-       nonneg = isl_basic_set_alloc_dim(dim, 0, 0, 1);
+       nonneg = isl_basic_set_alloc_space(dim, 0, 0, 1);
        k = isl_basic_set_alloc_inequality(nonneg);
        if (k < 0)
                goto error;
@@ -6036,12 +6389,12 @@ error:
 
 /* Construct the half-space x_pos <= -1.
  */
-static __isl_give isl_basic_set *neg_halfspace(__isl_take isl_dim *dim, int pos)
+static __isl_give isl_basic_set *neg_halfspace(__isl_take isl_space *dim, int pos)
 {
        int k;
        isl_basic_set *neg;
 
-       neg = isl_basic_set_alloc_dim(dim, 0, 0, 1);
+       neg = isl_basic_set_alloc_space(dim, 0, 0, 1);
        k = isl_basic_set_alloc_inequality(neg);
        if (k < 0)
                goto error;
@@ -6070,9 +6423,9 @@ __isl_give isl_set *isl_set_split_dims(__isl_take isl_set *set,
        isl_assert(set->ctx, first + n <= isl_set_dim(set, type), goto error);
 
        for (i = 0; i < n; ++i) {
-               nonneg = nonneg_halfspace(isl_set_get_dim(set),
+               nonneg = nonneg_halfspace(isl_set_get_space(set),
                                          pos(set->dim, type) + first + i);
-               neg = neg_halfspace(isl_set_get_dim(set),
+               neg = neg_halfspace(isl_set_get_space(set),
                                          pos(set->dim, type) + first + i);
 
                set = isl_set_intersect(set, isl_basic_set_union(nonneg, neg));
@@ -6100,14 +6453,14 @@ static int foreach_orthant(__isl_take isl_set *set, int *signs, int first,
                return fn(set, signs, user);
 
        signs[first] = 1;
-       half = isl_set_from_basic_set(nonneg_halfspace(isl_set_get_dim(set),
+       half = isl_set_from_basic_set(nonneg_halfspace(isl_set_get_space(set),
                                                        1 + first));
        half = isl_set_intersect(half, isl_set_copy(set));
        if (foreach_orthant(half, signs, first + 1, len, fn, user) < 0)
                goto error;
 
        signs[first] = -1;
-       half = isl_set_from_basic_set(neg_halfspace(isl_set_get_dim(set),
+       half = isl_set_from_basic_set(neg_halfspace(isl_set_get_space(set),
                                                        1 + first));
        half = isl_set_intersect(half, set);
        return foreach_orthant(half, signs, first + 1, len, fn, user);
@@ -6237,23 +6590,23 @@ int isl_set_is_empty(struct isl_set *set)
        return isl_map_is_empty((struct isl_map *)set);
 }
 
-int isl_map_has_equal_dim(__isl_keep isl_map *map1, __isl_keep isl_map *map2)
+int isl_map_has_equal_space(__isl_keep isl_map *map1, __isl_keep isl_map *map2)
 {
        if (!map1 || !map2)
                return -1;
 
-       return isl_dim_equal(map1->dim, map2->dim);
+       return isl_space_is_equal(map1->dim, map2->dim);
 }
 
-int isl_set_has_equal_dim(__isl_keep isl_set *set1, __isl_keep isl_set *set2)
+int isl_set_has_equal_space(__isl_keep isl_set *set1, __isl_keep isl_set *set2)
 {
        if (!set1 || !set2)
                return -1;
 
-       return isl_dim_equal(set1->dim, set2->dim);
+       return isl_space_is_equal(set1->dim, set2->dim);
 }
 
-int isl_map_is_equal(struct isl_map *map1, struct isl_map *map2)
+static int map_is_equal(__isl_keep isl_map *map1, __isl_keep isl_map *map2)
 {
        int is_subset;
 
@@ -6266,6 +6619,11 @@ int isl_map_is_equal(struct isl_map *map1, struct isl_map *map2)
        return is_subset;
 }
 
+int isl_map_is_equal(__isl_keep isl_map *map1, __isl_keep isl_map *map2)
+{
+       return align_params_map_map_and_test(map1, map2, &map_is_equal);
+}
+
 int isl_basic_map_is_strict_subset(
                struct isl_basic_map *bmap1, struct isl_basic_map *bmap2)
 {
@@ -6424,9 +6782,9 @@ struct isl_map *isl_basic_map_union(
        if (!bmap1 || !bmap2)
                return NULL;
 
-       isl_assert(bmap1->ctx, isl_dim_equal(bmap1->dim, bmap2->dim), goto error);
+       isl_assert(bmap1->ctx, isl_space_is_equal(bmap1->dim, bmap2->dim), goto error);
 
-       map = isl_map_alloc_dim(isl_dim_copy(bmap1->dim), 2, 0);
+       map = isl_map_alloc_space(isl_space_copy(bmap1->dim), 2, 0);
        if (!map)
                goto error;
        map = isl_map_add_basic_map(map, bmap1);
@@ -6455,7 +6813,7 @@ struct isl_basic_map *isl_basic_map_order_divs(struct isl_basic_map *bmap)
        if (!bmap)
                return NULL;
 
-       off = isl_dim_total(bmap->dim);
+       off = isl_space_dim(bmap->dim, isl_dim_all);
 
        for (i = 0; i < bmap->n_div; ++i) {
                int pos;
@@ -6514,7 +6872,7 @@ __isl_give isl_basic_set *isl_basic_set_expand_divs(
                isl_die(isl_mat_get_ctx(div), isl_error_invalid,
                        "not an expansion", goto error);
 
-       bset = isl_basic_map_extend_dim(bset, isl_dim_copy(bset->dim),
+       bset = isl_basic_map_extend_space(bset, isl_space_copy(bset->dim),
                                        div->n_row - bset->n_div, 0,
                                        2 * (div->n_row - bset->n_div));
 
@@ -6555,7 +6913,7 @@ static int find_div(struct isl_basic_map *dst,
 {
        int i;
 
-       unsigned total = isl_dim_total(src->dim);
+       unsigned total = isl_space_dim(src->dim, isl_dim_all);
 
        isl_assert(dst->ctx, div <= dst->n_div, return -1);
        for (i = div; i < dst->n_div; ++i)
@@ -6570,7 +6928,7 @@ struct isl_basic_map *isl_basic_map_align_divs(
                struct isl_basic_map *dst, struct isl_basic_map *src)
 {
        int i;
-       unsigned total = isl_dim_total(src->dim);
+       unsigned total = isl_space_dim(src->dim, isl_dim_all);
 
        if (!dst || !src)
                goto error;
@@ -6583,7 +6941,7 @@ struct isl_basic_map *isl_basic_map_align_divs(
 
        src = isl_basic_map_order_divs(src);
        dst = isl_basic_map_cow(dst);
-       dst = isl_basic_map_extend_dim(dst, isl_dim_copy(dst->dim),
+       dst = isl_basic_map_extend_space(dst, isl_space_copy(dst->dim),
                        src->n_div, 0, 2 * src->n_div);
        if (!dst)
                return NULL;
@@ -6641,7 +6999,8 @@ struct isl_set *isl_set_align_divs(struct isl_set *set)
        return (struct isl_set *)isl_map_align_divs((struct isl_map *)set);
 }
 
-struct isl_set *isl_set_apply(struct isl_set *set, struct isl_map *map)
+static __isl_give isl_set *set_apply( __isl_take isl_set *set,
+       __isl_take isl_map *map)
 {
        if (!set || !map)
                goto error;
@@ -6655,6 +7014,12 @@ error:
        return NULL;
 }
 
+__isl_give isl_set *isl_set_apply( __isl_take isl_set *set,
+       __isl_take isl_map *map)
+{
+       return isl_map_align_params_map_map_and(set, map, &set_apply);
+}
+
 /* There is no need to cow as removing empty parts doesn't change
  * the meaning of the set.
  */
@@ -6743,7 +7108,7 @@ static enum isl_lp_result basic_set_maximal_difference_at(
        __isl_keep isl_basic_set *bset1, __isl_keep isl_basic_set *bset2,
        int pos, isl_int *opt)
 {
-       struct isl_dim *dims;
+       isl_space *dims;
        struct isl_basic_map *bmap1 = NULL;
        struct isl_basic_map *bmap2 = NULL;
        struct isl_ctx *ctx;
@@ -6759,9 +7124,9 @@ static enum isl_lp_result basic_set_maximal_difference_at(
        nparam = isl_basic_set_n_param(bset1);
        dim1 = isl_basic_set_n_dim(bset1);
        dim2 = isl_basic_set_n_dim(bset2);
-       dims = isl_dim_alloc(bset1->ctx, nparam, pos, dim1 - pos);
+       dims = isl_space_alloc(bset1->ctx, nparam, pos, dim1 - pos);
        bmap1 = isl_basic_map_from_basic_set(isl_basic_set_copy(bset1), dims);
-       dims = isl_dim_alloc(bset2->ctx, nparam, pos, dim2 - pos);
+       dims = isl_space_alloc(bset2->ctx, nparam, pos, dim2 - pos);
        bmap2 = isl_basic_map_from_basic_set(isl_basic_set_copy(bset2), dims);
        if (!bmap1 || !bmap2)
                goto error;
@@ -7305,7 +7670,7 @@ int isl_map_plain_is_equal(__isl_keep isl_map *map1, __isl_keep isl_map *map2)
 
        if (map1 == map2)
                return 1;
-       if (!isl_dim_equal(map1->dim, map2->dim))
+       if (!isl_space_is_equal(map1->dim, map2->dim))
                return 0;
 
        map1 = isl_map_copy(map1);
@@ -7427,7 +7792,7 @@ error:
 struct isl_basic_map *isl_basic_map_product(
                struct isl_basic_map *bmap1, struct isl_basic_map *bmap2)
 {
-       struct isl_dim *dim_result = NULL;
+       isl_space *dim_result = NULL;
        struct isl_basic_map *bmap;
        unsigned in1, in2, out1, out2, nparam, total, pos;
        struct isl_dim_map *dim_map1, *dim_map2;
@@ -7435,10 +7800,10 @@ struct isl_basic_map *isl_basic_map_product(
        if (!bmap1 || !bmap2)
                goto error;
 
-       isl_assert(bmap1->ctx, isl_dim_match(bmap1->dim, isl_dim_param,
+       isl_assert(bmap1->ctx, isl_space_match(bmap1->dim, isl_dim_param,
                                     bmap2->dim, isl_dim_param), goto error);
-       dim_result = isl_dim_product(isl_dim_copy(bmap1->dim),
-                                                  isl_dim_copy(bmap2->dim));
+       dim_result = isl_space_product(isl_space_copy(bmap1->dim),
+                                                  isl_space_copy(bmap2->dim));
 
        in1 = isl_basic_map_n_in(bmap1);
        in2 = isl_basic_map_n_in(bmap2);
@@ -7458,7 +7823,7 @@ struct isl_basic_map *isl_basic_map_product(
        isl_dim_map_div(dim_map1, bmap1, pos += out2);
        isl_dim_map_div(dim_map2, bmap2, pos += bmap1->n_div);
 
-       bmap = isl_basic_map_alloc_dim(dim_result,
+       bmap = isl_basic_map_alloc_space(dim_result,
                        bmap1->n_div + bmap2->n_div,
                        bmap1->n_eq + bmap2->n_eq,
                        bmap1->n_ineq + bmap2->n_ineq);
@@ -7488,10 +7853,55 @@ __isl_give isl_basic_set *isl_basic_set_flat_product(
        return isl_basic_map_flat_range_product(bset1, bset2);
 }
 
+__isl_give isl_basic_map *isl_basic_map_domain_product(
+       __isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2)
+{
+       isl_space *space_result = NULL;
+       isl_basic_map *bmap;
+       unsigned in1, in2, out, nparam, total, pos;
+       struct isl_dim_map *dim_map1, *dim_map2;
+
+       if (!bmap1 || !bmap2)
+               goto error;
+
+       space_result = isl_space_domain_product(isl_space_copy(bmap1->dim),
+                                               isl_space_copy(bmap2->dim));
+
+       in1 = isl_basic_map_dim(bmap1, isl_dim_in);
+       in2 = isl_basic_map_dim(bmap2, isl_dim_in);
+       out = isl_basic_map_dim(bmap1, isl_dim_out);
+       nparam = isl_basic_map_dim(bmap1, isl_dim_param);
+
+       total = nparam + in1 + in2 + out + bmap1->n_div + bmap2->n_div;
+       dim_map1 = isl_dim_map_alloc(bmap1->ctx, total);
+       dim_map2 = isl_dim_map_alloc(bmap1->ctx, total);
+       isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_param, pos = 0);
+       isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_param, pos = 0);
+       isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_in, pos += nparam);
+       isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_in, pos += in1);
+       isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_out, pos += in2);
+       isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_out, pos);
+       isl_dim_map_div(dim_map1, bmap1, pos += out);
+       isl_dim_map_div(dim_map2, bmap2, pos += bmap1->n_div);
+
+       bmap = isl_basic_map_alloc_space(space_result,
+                       bmap1->n_div + bmap2->n_div,
+                       bmap1->n_eq + bmap2->n_eq,
+                       bmap1->n_ineq + bmap2->n_ineq);
+       bmap = isl_basic_map_add_constraints_dim_map(bmap, bmap1, dim_map1);
+       bmap = isl_basic_map_add_constraints_dim_map(bmap, bmap2, dim_map2);
+       bmap = isl_basic_map_simplify(bmap);
+       return isl_basic_map_finalize(bmap);
+error:
+       isl_basic_map_free(bmap1);
+       isl_basic_map_free(bmap2);
+       return NULL;
+}
+
 __isl_give isl_basic_map *isl_basic_map_range_product(
        __isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2)
 {
-       isl_dim *dim_result = NULL;
+       isl_space *dim_result = NULL;
        isl_basic_map *bmap;
        unsigned in, out1, out2, nparam, total, pos;
        struct isl_dim_map *dim_map1, *dim_map2;
@@ -7499,8 +7909,8 @@ __isl_give isl_basic_map *isl_basic_map_range_product(
        if (!bmap1 || !bmap2)
                goto error;
 
-       dim_result = isl_dim_range_product(isl_dim_copy(bmap1->dim),
-                                          isl_dim_copy(bmap2->dim));
+       dim_result = isl_space_range_product(isl_space_copy(bmap1->dim),
+                                          isl_space_copy(bmap2->dim));
 
        in = isl_basic_map_dim(bmap1, isl_dim_in);
        out1 = isl_basic_map_n_out(bmap1);
@@ -7519,7 +7929,7 @@ __isl_give isl_basic_map *isl_basic_map_range_product(
        isl_dim_map_div(dim_map1, bmap1, pos += out2);
        isl_dim_map_div(dim_map2, bmap2, pos += bmap1->n_div);
 
-       bmap = isl_basic_map_alloc_dim(dim_result,
+       bmap = isl_basic_map_alloc_space(dim_result,
                        bmap1->n_div + bmap2->n_div,
                        bmap1->n_eq + bmap2->n_eq,
                        bmap1->n_ineq + bmap2->n_ineq);
@@ -7545,8 +7955,8 @@ __isl_give isl_basic_map *isl_basic_map_flat_range_product(
 
 static __isl_give isl_map *map_product(__isl_take isl_map *map1,
        __isl_take isl_map *map2,
-       __isl_give isl_dim *(*dim_product)(__isl_take isl_dim *left,
-                                          __isl_take isl_dim *right),
+       __isl_give isl_space *(*dim_product)(__isl_take isl_space *left,
+                                          __isl_take isl_space *right),
        __isl_give isl_basic_map *(*basic_map_product)(
                __isl_take isl_basic_map *left, __isl_take isl_basic_map *right))
 {
@@ -7557,15 +7967,15 @@ static __isl_give isl_map *map_product(__isl_take isl_map *map1,
        if (!map1 || !map2)
                goto error;
 
-       isl_assert(map1->ctx, isl_dim_match(map1->dim, isl_dim_param,
+       isl_assert(map1->ctx, isl_space_match(map1->dim, isl_dim_param,
                                         map2->dim, isl_dim_param), goto error);
 
        if (ISL_F_ISSET(map1, ISL_MAP_DISJOINT) &&
            ISL_F_ISSET(map2, ISL_MAP_DISJOINT))
                ISL_FL_SET(flags, ISL_MAP_DISJOINT);
 
-       result = isl_map_alloc_dim(dim_product(isl_dim_copy(map1->dim),
-                                              isl_dim_copy(map2->dim)),
+       result = isl_map_alloc_space(dim_product(isl_space_copy(map1->dim),
+                                              isl_space_copy(map2->dim)),
                                map1->n * map2->n, flags);
        if (!result)
                goto error;
@@ -7592,9 +8002,16 @@ error:
 
 /* Given two maps A -> B and C -> D, construct a map [A -> C] -> [B -> D]
  */
-struct isl_map *isl_map_product(struct isl_map *map1, struct isl_map *map2)
+static __isl_give isl_map *map_product_aligned(__isl_take isl_map *map1,
+       __isl_take isl_map *map2)
 {
-       return map_product(map1, map2, &isl_dim_product, &isl_basic_map_product);
+       return map_product(map1, map2, &isl_space_product, &isl_basic_map_product);
+}
+
+__isl_give isl_map *isl_map_product(__isl_take isl_map *map1,
+       __isl_take isl_map *map2)
+{
+       return isl_map_align_params_map_map_and(map1, map2, &map_product_aligned);
 }
 
 /* Given two maps A -> B and C -> D, construct a map (A, C) -> (B, D)
@@ -7622,15 +8039,50 @@ __isl_give isl_set *isl_set_flat_product(__isl_take isl_set *set1,
        return isl_map_flat_range_product(set1, set2);
 }
 
+/* Given two maps A -> B and C -> D, construct a map [A -> C] -> (B * D)
+ */
+static __isl_give isl_map *map_domain_product_aligned(__isl_take isl_map *map1,
+       __isl_take isl_map *map2)
+{
+       return map_product(map1, map2, &isl_space_domain_product,
+                               &isl_basic_map_domain_product);
+}
+
 /* Given two maps A -> B and C -> D, construct a map (A * C) -> [B -> D]
  */
-__isl_give isl_map *isl_map_range_product(__isl_take isl_map *map1,
+static __isl_give isl_map *map_range_product_aligned(__isl_take isl_map *map1,
        __isl_take isl_map *map2)
 {
-       return map_product(map1, map2, &isl_dim_range_product,
+       return map_product(map1, map2, &isl_space_range_product,
                                &isl_basic_map_range_product);
 }
 
+__isl_give isl_map *isl_map_domain_product(__isl_take isl_map *map1,
+       __isl_take isl_map *map2)
+{
+       return isl_map_align_params_map_map_and(map1, map2,
+                                               &map_domain_product_aligned);
+}
+
+__isl_give isl_map *isl_map_range_product(__isl_take isl_map *map1,
+       __isl_take isl_map *map2)
+{
+       return isl_map_align_params_map_map_and(map1, map2,
+                                               &map_range_product_aligned);
+}
+
+/* Given two maps A -> B and C -> D, construct a map (A, C) -> (B * D)
+ */
+__isl_give isl_map *isl_map_flat_domain_product(__isl_take isl_map *map1,
+       __isl_take isl_map *map2)
+{
+       isl_map *prod;
+
+       prod = isl_map_domain_product(map1, map2);
+       prod = isl_map_flatten_domain(prod);
+       return prod;
+}
+
 /* Given two maps A -> B and C -> D, construct a map (A * C) -> (B, D)
  */
 __isl_give isl_map *isl_map_flat_range_product(__isl_take isl_map *map1,
@@ -7790,7 +8242,7 @@ int isl_set_foreach_basic_set(__isl_keep isl_set *set,
 
 __isl_give isl_basic_set *isl_basic_set_lift(__isl_take isl_basic_set *bset)
 {
-       struct isl_dim *dim;
+       isl_space *dim;
 
        if (!bset)
                return NULL;
@@ -7799,11 +8251,11 @@ __isl_give isl_basic_set *isl_basic_set_lift(__isl_take isl_basic_set *bset)
        if (!bset)
                return NULL;
 
-       dim = isl_basic_set_get_dim(bset);
-       dim = isl_dim_lift(dim, bset->n_div);
+       dim = isl_basic_set_get_space(bset);
+       dim = isl_space_lift(dim, bset->n_div);
        if (!dim)
                goto error;
-       isl_dim_free(bset->dim);
+       isl_space_free(bset->dim);
        bset->dim = dim;
        bset->extra -= bset->n_div;
        bset->n_div = 0;
@@ -7819,7 +8271,7 @@ error:
 __isl_give isl_set *isl_set_lift(__isl_take isl_set *set)
 {
        int i;
-       struct isl_dim *dim;
+       isl_space *dim;
        unsigned n_div;
 
        set = isl_set_align_divs(set);
@@ -7832,11 +8284,11 @@ __isl_give isl_set *isl_set_lift(__isl_take isl_set *set)
                return NULL;
 
        n_div = set->p[0]->n_div;
-       dim = isl_set_get_dim(set);
-       dim = isl_dim_lift(dim, n_div);
+       dim = isl_set_get_space(set);
+       dim = isl_space_lift(dim, n_div);
        if (!dim)
                goto error;
-       isl_dim_free(set->dim);
+       isl_space_free(set->dim);
        set->dim = dim;
 
        for (i = 0; i < set->n; ++i) {
@@ -7853,7 +8305,7 @@ error:
 
 __isl_give isl_map *isl_set_lifting(__isl_take isl_set *set)
 {
-       struct isl_dim *dim;
+       isl_space *dim;
        struct isl_basic_map *bmap;
        unsigned n_set;
        unsigned n_div;
@@ -7866,18 +8318,18 @@ __isl_give isl_map *isl_set_lifting(__isl_take isl_set *set)
        if (!set)
                return NULL;
 
-       dim = isl_set_get_dim(set);
+       dim = isl_set_get_space(set);
        if (set->n == 0 || set->p[0]->n_div == 0) {
                isl_set_free(set);
-               return isl_map_identity(isl_dim_map_from_set(dim));
+               return isl_map_identity(isl_space_map_from_set(dim));
        }
 
        n_div = set->p[0]->n_div;
-       dim = isl_dim_map_from_set(dim);
-       n_param = isl_dim_size(dim, isl_dim_param);
-       n_set = isl_dim_size(dim, isl_dim_in);
-       dim = isl_dim_extend(dim, n_param, n_set, n_set + n_div);
-       bmap = isl_basic_map_alloc_dim(dim, 0, n_set, 2 * n_div);
+       dim = isl_space_map_from_set(dim);
+       n_param = isl_space_dim(dim, isl_dim_param);
+       n_set = isl_space_dim(dim, isl_dim_in);
+       dim = isl_space_extend(dim, n_param, n_set, n_set + n_div);
+       bmap = isl_basic_map_alloc_space(dim, 0, n_set, 2 * n_div);
        for (i = 0; i < n_set; ++i)
                bmap = var_equal(bmap, i);
 
@@ -7942,11 +8394,13 @@ int isl_set_size(__isl_keep isl_set *set)
        return size;
 }
 
-int isl_basic_map_dim_is_bounded(__isl_keep isl_basic_map *bmap,
-       enum isl_dim_type type, unsigned pos)
+/* Check if there is any lower bound (if lower == 0) and/or upper
+ * bound (if upper == 0) on the specified dim.
+ */
+static int basic_map_dim_is_bounded(__isl_keep isl_basic_map *bmap,
+       enum isl_dim_type type, unsigned pos, int lower, int upper)
 {
        int i;
-       int lower, upper;
 
        if (!bmap)
                return -1;
@@ -7955,11 +8409,17 @@ int isl_basic_map_dim_is_bounded(__isl_keep isl_basic_map *bmap,
 
        pos += isl_basic_map_offset(bmap, type);
 
+       for (i = 0; i < bmap->n_div; ++i) {
+               if (isl_int_is_zero(bmap->div[i][0]))
+                       continue;
+               if (!isl_int_is_zero(bmap->div[i][1 + pos]))
+                       return 1;
+       }
+
        for (i = 0; i < bmap->n_eq; ++i)
                if (!isl_int_is_zero(bmap->eq[i][pos]))
                        return 1;
 
-       lower = upper = 0;
        for (i = 0; i < bmap->n_ineq; ++i) {
                int sgn = isl_int_sgn(bmap->ineq[i][pos]);
                if (sgn > 0)
@@ -7971,6 +8431,24 @@ int isl_basic_map_dim_is_bounded(__isl_keep isl_basic_map *bmap,
        return lower && upper;
 }
 
+int isl_basic_map_dim_is_bounded(__isl_keep isl_basic_map *bmap,
+       enum isl_dim_type type, unsigned pos)
+{
+       return basic_map_dim_is_bounded(bmap, type, pos, 0, 0);
+}
+
+int isl_basic_map_dim_has_lower_bound(__isl_keep isl_basic_map *bmap,
+       enum isl_dim_type type, unsigned pos)
+{
+       return basic_map_dim_is_bounded(bmap, type, pos, 0, 1);
+}
+
+int isl_basic_map_dim_has_upper_bound(__isl_keep isl_basic_map *bmap,
+       enum isl_dim_type type, unsigned pos)
+{
+       return basic_map_dim_is_bounded(bmap, type, pos, 1, 0);
+}
+
 int isl_map_dim_is_bounded(__isl_keep isl_map *map,
        enum isl_dim_type type, unsigned pos)
 {
@@ -7998,6 +8476,42 @@ int isl_set_dim_is_bounded(__isl_keep isl_set *set,
        return isl_map_dim_is_bounded((isl_map *)set, type, pos);
 }
 
+static int has_bound(__isl_keep isl_map *map,
+       enum isl_dim_type type, unsigned pos,
+       int (*fn)(__isl_keep isl_basic_map *bmap,
+                 enum isl_dim_type type, unsigned pos))
+{
+       int i;
+
+       if (!map)
+               return -1;
+
+       for (i = 0; i < map->n; ++i) {
+               int bounded;
+               bounded = fn(map->p[i], type, pos);
+               if (bounded < 0 || bounded)
+                       return bounded;
+       }
+
+       return 0;
+}
+
+/* Return 1 if the specified dim is involved in any lower bound.
+ */
+int isl_set_dim_has_lower_bound(__isl_keep isl_set *set,
+       enum isl_dim_type type, unsigned pos)
+{
+       return has_bound(set, type, pos, &isl_basic_map_dim_has_lower_bound);
+}
+
+/* Return 1 if the specified dim is involved in any upper bound.
+ */
+int isl_set_dim_has_upper_bound(__isl_keep isl_set *set,
+       enum isl_dim_type type, unsigned pos)
+{
+       return has_bound(set, type, pos, &isl_basic_map_dim_has_upper_bound);
+}
+
 /* For each of the "n" variables starting at "first", determine
  * the sign of the variable and put the results in the first "n"
  * elements of the array "signs".
@@ -8131,7 +8645,7 @@ int isl_map_plain_is_single_valued(__isl_keep isl_map *map)
  */
 int isl_map_is_single_valued(__isl_keep isl_map *map)
 {
-       isl_dim *dim;
+       isl_space *dim;
        isl_map *test;
        isl_map *id;
        int sv;
@@ -8143,7 +8657,7 @@ int isl_map_is_single_valued(__isl_keep isl_map *map)
        test = isl_map_reverse(isl_map_copy(map));
        test = isl_map_apply_range(test, isl_map_copy(map));
 
-       dim = isl_dim_map_from_set(isl_dim_range(isl_map_get_dim(map)));
+       dim = isl_space_map_from_set(isl_space_range(isl_map_get_space(map)));
        id = isl_map_identity(dim);
 
        sv = isl_map_is_subset(test, id);
@@ -8230,7 +8744,7 @@ int isl_basic_set_is_box(__isl_keep isl_basic_set *bset)
                return 0;
 
        nvar = isl_basic_set_dim(bset, isl_dim_set);
-       ovar = isl_dim_offset(bset->dim, isl_dim_set);
+       ovar = isl_space_offset(bset->dim, isl_dim_set);
        for (j = 0; j < nvar; ++j) {
                int lower = 0, upper = 0;
                for (i = 0; i < bset->n_eq; ++i) {
@@ -8274,7 +8788,7 @@ int isl_basic_set_is_wrapping(__isl_keep isl_basic_set *bset)
        if (!bset)
                return -1;
        
-       return isl_dim_is_wrapping(bset->dim);
+       return isl_space_is_wrapping(bset->dim);
 }
 
 int isl_set_is_wrapping(__isl_keep isl_set *set)
@@ -8282,7 +8796,7 @@ int isl_set_is_wrapping(__isl_keep isl_set *set)
        if (!set)
                return -1;
        
-       return isl_dim_is_wrapping(set->dim);
+       return isl_space_is_wrapping(set->dim);
 }
 
 __isl_give isl_basic_set *isl_basic_map_wrap(__isl_take isl_basic_map *bmap)
@@ -8291,7 +8805,7 @@ __isl_give isl_basic_set *isl_basic_map_wrap(__isl_take isl_basic_map *bmap)
        if (!bmap)
                return NULL;
 
-       bmap->dim = isl_dim_wrap(bmap->dim);
+       bmap->dim = isl_space_wrap(bmap->dim);
        if (!bmap->dim)
                goto error;
 
@@ -8316,7 +8830,7 @@ __isl_give isl_set *isl_map_wrap(__isl_take isl_map *map)
                if (!map->p[i])
                        goto error;
        }
-       map->dim = isl_dim_wrap(map->dim);
+       map->dim = isl_space_wrap(map->dim);
        if (!map->dim)
                goto error;
 
@@ -8332,7 +8846,7 @@ __isl_give isl_basic_map *isl_basic_set_unwrap(__isl_take isl_basic_set *bset)
        if (!bset)
                return NULL;
 
-       bset->dim = isl_dim_unwrap(bset->dim);
+       bset->dim = isl_space_unwrap(bset->dim);
        if (!bset->dim)
                goto error;
 
@@ -8365,7 +8879,7 @@ __isl_give isl_map *isl_set_unwrap(__isl_take isl_set *set)
                        goto error;
        }
 
-       set->dim = isl_dim_unwrap(set->dim);
+       set->dim = isl_space_unwrap(set->dim);
        if (!set->dim)
                goto error;
 
@@ -8381,14 +8895,14 @@ __isl_give isl_basic_map *isl_basic_map_reset(__isl_take isl_basic_map *bmap,
        if (!bmap)
                return NULL;
 
-       if (!isl_dim_is_named_or_nested(bmap->dim, type))
+       if (!isl_space_is_named_or_nested(bmap->dim, type))
                return bmap;
 
        bmap = isl_basic_map_cow(bmap);
        if (!bmap)
                return NULL;
 
-       bmap->dim = isl_dim_reset(bmap->dim, type);
+       bmap->dim = isl_space_reset(bmap->dim, type);
        if (!bmap->dim)
                goto error;
 
@@ -8408,7 +8922,7 @@ __isl_give isl_map *isl_map_reset(__isl_take isl_map *map,
        if (!map)
                return NULL;
 
-       if (!isl_dim_is_named_or_nested(map->dim, type))
+       if (!isl_space_is_named_or_nested(map->dim, type))
                return map;
 
        map = isl_map_cow(map);
@@ -8420,7 +8934,7 @@ __isl_give isl_map *isl_map_reset(__isl_take isl_map *map,
                if (!map->p[i])
                        goto error;
        }
-       map->dim = isl_dim_reset(map->dim, type);
+       map->dim = isl_space_reset(map->dim, type);
        if (!map->dim)
                goto error;
 
@@ -8442,7 +8956,7 @@ __isl_give isl_basic_map *isl_basic_map_flatten(__isl_take isl_basic_map *bmap)
        if (!bmap)
                return NULL;
 
-       bmap->dim = isl_dim_flatten(bmap->dim);
+       bmap->dim = isl_space_flatten(bmap->dim);
        if (!bmap->dim)
                goto error;
 
@@ -8459,6 +8973,31 @@ __isl_give isl_basic_set *isl_basic_set_flatten(__isl_take isl_basic_set *bset)
        return (isl_basic_set *)isl_basic_map_flatten((isl_basic_map *)bset);
 }
 
+__isl_give isl_basic_map *isl_basic_map_flatten_domain(
+       __isl_take isl_basic_map *bmap)
+{
+       if (!bmap)
+               return NULL;
+
+       if (!bmap->dim->nested[0])
+               return bmap;
+
+       bmap = isl_basic_map_cow(bmap);
+       if (!bmap)
+               return NULL;
+
+       bmap->dim = isl_space_flatten_domain(bmap->dim);
+       if (!bmap->dim)
+               goto error;
+
+       bmap = isl_basic_map_finalize(bmap);
+
+       return bmap;
+error:
+       isl_basic_map_free(bmap);
+       return NULL;
+}
+
 __isl_give isl_basic_map *isl_basic_map_flatten_range(
        __isl_take isl_basic_map *bmap)
 {
@@ -8472,7 +9011,7 @@ __isl_give isl_basic_map *isl_basic_map_flatten_range(
        if (!bmap)
                return NULL;
 
-       bmap->dim = isl_dim_flatten_range(bmap->dim);
+       bmap->dim = isl_space_flatten_range(bmap->dim);
        if (!bmap->dim)
                goto error;
 
@@ -8503,7 +9042,7 @@ __isl_give isl_map *isl_map_flatten(__isl_take isl_map *map)
                if (!map->p[i])
                        goto error;
        }
-       map->dim = isl_dim_flatten(map->dim);
+       map->dim = isl_space_flatten(map->dim);
        if (!map->dim)
                goto error;
 
@@ -8520,17 +9059,46 @@ __isl_give isl_set *isl_set_flatten(__isl_take isl_set *set)
 
 __isl_give isl_map *isl_set_flatten_map(__isl_take isl_set *set)
 {
-       isl_dim *dim, *flat_dim;
+       isl_space *dim, *flat_dim;
        isl_map *map;
 
-       dim = isl_set_get_dim(set);
-       flat_dim = isl_dim_flatten(isl_dim_copy(dim));
-       map = isl_map_identity(isl_dim_join(isl_dim_reverse(dim), flat_dim));
+       dim = isl_set_get_space(set);
+       flat_dim = isl_space_flatten(isl_space_copy(dim));
+       map = isl_map_identity(isl_space_join(isl_space_reverse(dim), flat_dim));
        map = isl_map_intersect_domain(map, set);
 
        return map;
 }
 
+__isl_give isl_map *isl_map_flatten_domain(__isl_take isl_map *map)
+{
+       int i;
+
+       if (!map)
+               return NULL;
+
+       if (!map->dim->nested[0])
+               return map;
+
+       map = isl_map_cow(map);
+       if (!map)
+               return NULL;
+
+       for (i = 0; i < map->n; ++i) {
+               map->p[i] = isl_basic_map_flatten_domain(map->p[i]);
+               if (!map->p[i])
+                       goto error;
+       }
+       map->dim = isl_space_flatten_domain(map->dim);
+       if (!map->dim)
+               goto error;
+
+       return map;
+error:
+       isl_map_free(map);
+       return NULL;
+}
+
 __isl_give isl_map *isl_map_flatten_range(__isl_take isl_map *map)
 {
        int i;
@@ -8550,7 +9118,7 @@ __isl_give isl_map *isl_map_flatten_range(__isl_take isl_map *map)
                if (!map->p[i])
                        goto error;
        }
-       map->dim = isl_dim_flatten_range(map->dim);
+       map->dim = isl_space_flatten_range(map->dim);
        if (!map->dim)
                goto error;
 
@@ -8564,7 +9132,7 @@ error:
  * and set the dimension specification to "dim".
  */
 __isl_give isl_basic_map *isl_basic_map_realign(__isl_take isl_basic_map *bmap,
-       __isl_take isl_dim *dim, __isl_take struct isl_dim_map *dim_map)
+       __isl_take isl_space *dim, __isl_take struct isl_dim_map *dim_map)
 {
        isl_basic_map *res;
 
@@ -8572,7 +9140,7 @@ __isl_give isl_basic_map *isl_basic_map_realign(__isl_take isl_basic_map *bmap,
        if (!bmap || !dim || !dim_map)
                goto error;
 
-       res = isl_basic_map_alloc_dim(dim,
+       res = isl_basic_map_alloc_space(dim,
                        bmap->n_div, bmap->n_eq, bmap->n_ineq);
        res = isl_basic_map_add_constraints_dim_map(res, bmap, dim_map);
        res = isl_basic_map_finalize(res);
@@ -8580,7 +9148,7 @@ __isl_give isl_basic_map *isl_basic_map_realign(__isl_take isl_basic_map *bmap,
 error:
        free(dim_map);
        isl_basic_map_free(bmap);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -8603,13 +9171,13 @@ __isl_give isl_map *isl_map_realign(__isl_take isl_map *map,
                dim_map_i = isl_dim_map_extend(dim_map, map->p[i]);
 
                map->p[i] = isl_basic_map_realign(map->p[i],
-                                           isl_dim_copy(r->dim), dim_map_i);
+                                           isl_space_copy(r->dim), dim_map_i);
 
                if (!map->p[i])
                        goto error;
        }
 
-       map = isl_map_reset_dim(map, isl_dim_copy(r->dim));
+       map = isl_map_reset_space(map, isl_space_copy(r->dim));
 
        isl_reordering_free(r);
        free(dim_map);
@@ -8628,42 +9196,42 @@ __isl_give isl_set *isl_set_realign(__isl_take isl_set *set,
 }
 
 __isl_give isl_map *isl_map_align_params(__isl_take isl_map *map,
-       __isl_take isl_dim *model)
+       __isl_take isl_space *model)
 {
        isl_ctx *ctx;
 
        if (!map || !model)
                goto error;
 
-       ctx = isl_dim_get_ctx(model);
-       if (!isl_dim_has_named_params(model))
+       ctx = isl_space_get_ctx(model);
+       if (!isl_space_has_named_params(model))
                isl_die(ctx, isl_error_invalid,
                        "model has unnamed parameters", goto error);
-       if (!isl_dim_has_named_params(map->dim))
+       if (!isl_space_has_named_params(map->dim))
                isl_die(ctx, isl_error_invalid,
                        "relation has unnamed parameters", goto error);
-       if (!isl_dim_match(map->dim, isl_dim_param, model, isl_dim_param)) {
+       if (!isl_space_match(map->dim, isl_dim_param, model, isl_dim_param)) {
                isl_reordering *exp;
 
-               model = isl_dim_drop(model, isl_dim_in,
-                                       0, isl_dim_size(model, isl_dim_in));
-               model = isl_dim_drop(model, isl_dim_out,
-                                       0, isl_dim_size(model, isl_dim_out));
+               model = isl_space_drop_dims(model, isl_dim_in,
+                                       0, isl_space_dim(model, isl_dim_in));
+               model = isl_space_drop_dims(model, isl_dim_out,
+                                       0, isl_space_dim(model, isl_dim_out));
                exp = isl_parameter_alignment_reordering(map->dim, model);
-               exp = isl_reordering_extend_dim(exp, isl_map_get_dim(map));
+               exp = isl_reordering_extend_space(exp, isl_map_get_space(map));
                map = isl_map_realign(map, exp);
        }
 
-       isl_dim_free(model);
+       isl_space_free(model);
        return map;
 error:
-       isl_dim_free(model);
+       isl_space_free(model);
        isl_map_free(map);
        return NULL;
 }
 
 __isl_give isl_set *isl_set_align_params(__isl_take isl_set *set,
-       __isl_take isl_dim *model)
+       __isl_take isl_space *model)
 {
        return isl_map_align_params(set, model);
 }
@@ -8727,7 +9295,7 @@ __isl_give isl_mat *isl_basic_map_inequalities_matrix(
 }
 
 __isl_give isl_basic_map *isl_basic_map_from_constraint_matrices(
-       __isl_take isl_dim *dim,
+       __isl_take isl_space *dim,
        __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)
@@ -8747,7 +9315,7 @@ __isl_give isl_basic_map *isl_basic_map_from_constraint_matrices(
                        "equalities and inequalities matrices should have "
                        "same number of columns", goto error);
 
-       total = 1 + isl_dim_total(dim);
+       total = 1 + isl_space_dim(dim, isl_dim_all);
 
        if (eq->n_col < total)
                isl_die(dim->ctx, isl_error_invalid,
@@ -8755,7 +9323,7 @@ __isl_give isl_basic_map *isl_basic_map_from_constraint_matrices(
 
        extra = eq->n_col - total;
 
-       bmap = isl_basic_map_alloc_dim(isl_dim_copy(dim), extra,
+       bmap = isl_basic_map_alloc_space(isl_space_copy(dim), extra,
                                       eq->n_row, ineq->n_row);
        if (!bmap)
                goto error;
@@ -8792,13 +9360,13 @@ __isl_give isl_basic_map *isl_basic_map_from_constraint_matrices(
                }
        }
 
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_mat_free(eq);
        isl_mat_free(ineq);
 
        return bmap;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_mat_free(eq);
        isl_mat_free(ineq);
        return NULL;
@@ -8821,7 +9389,7 @@ __isl_give isl_mat *isl_basic_set_inequalities_matrix(
 }
 
 __isl_give isl_basic_set *isl_basic_set_from_constraint_matrices(
-       __isl_take isl_dim *dim,
+       __isl_take isl_space *dim,
        __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)
 {
@@ -8835,7 +9403,7 @@ int isl_basic_map_can_zip(__isl_keep isl_basic_map *bmap)
        if (!bmap)
                return -1;
        
-       return isl_dim_can_zip(bmap->dim);
+       return isl_space_can_zip(bmap->dim);
 }
 
 int isl_map_can_zip(__isl_keep isl_map *map)
@@ -8843,7 +9411,7 @@ int isl_map_can_zip(__isl_keep isl_map *map)
        if (!map)
                return -1;
        
-       return isl_dim_can_zip(map->dim);
+       return isl_space_can_zip(map->dim);
 }
 
 /* Given a basic map (A -> B) -> (C -> D), return the corresponding basic map
@@ -8862,13 +9430,13 @@ __isl_give isl_basic_map *isl_basic_map_zip(__isl_take isl_basic_map *bmap)
                isl_die(bmap->ctx, isl_error_invalid,
                        "basic map cannot be zipped", goto error);
        pos = isl_basic_map_offset(bmap, isl_dim_in) +
-               isl_dim_size(bmap->dim->nested[0], isl_dim_in);
-       n1 = isl_dim_size(bmap->dim->nested[0], isl_dim_out);
-       n2 = isl_dim_size(bmap->dim->nested[1], isl_dim_in);
+               isl_space_dim(bmap->dim->nested[0], isl_dim_in);
+       n1 = isl_space_dim(bmap->dim->nested[0], isl_dim_out);
+       n2 = isl_space_dim(bmap->dim->nested[1], isl_dim_in);
        bmap = isl_basic_map_swap_vars(bmap, pos, n1, n2);
        if (!bmap)
                return NULL;
-       bmap->dim = isl_dim_zip(bmap->dim);
+       bmap->dim = isl_space_zip(bmap->dim);
        if (!bmap->dim)
                goto error;
        return bmap;
@@ -8901,7 +9469,7 @@ __isl_give isl_map *isl_map_zip(__isl_take isl_map *map)
                        goto error;
        }
 
-       map->dim = isl_dim_zip(map->dim);
+       map->dim = isl_space_zip(map->dim);
        if (!map->dim)
                goto error;
 
@@ -8925,8 +9493,6 @@ __isl_give isl_basic_map *isl_basic_map_from_aff(__isl_take isl_aff *aff)
                return NULL;
 
        ls = isl_aff_get_local_space(aff);
-       ls = isl_local_space_from_domain(ls);
-       ls = isl_local_space_add_dims(ls, isl_dim_out, 1);
        bmap = isl_basic_map_from_local_space(ls);
        bmap = isl_basic_map_extend_constraints(bmap, 1, 0);
        k = isl_basic_map_alloc_equality(bmap);
@@ -8956,16 +9522,16 @@ error:
  * domain_dim.
  */
 __isl_give isl_basic_map *isl_basic_map_from_aff_list(
-       __isl_take isl_dim *domain_dim, __isl_take isl_aff_list *list)
+       __isl_take isl_space *domain_dim, __isl_take isl_aff_list *list)
 {
        int i;
-       isl_dim *dim;
+       isl_space *dim;
        isl_basic_map *bmap;
 
        if (!list)
                return NULL;
 
-       dim = isl_dim_from_domain(domain_dim);
+       dim = isl_space_from_domain(domain_dim);
        bmap = isl_basic_map_universe(dim);
 
        for (i = 0; i < list->n; ++i) {
@@ -8981,3 +9547,85 @@ __isl_give isl_basic_map *isl_basic_map_from_aff_list(
        isl_aff_list_free(list);
        return bmap;
 }
+
+__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)
+{
+       return isl_map_equate(set, type1, pos1, type2, pos2);
+}
+
+/* Add a constraint imposing that the given two dimensions are equal.
+ */
+__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)
+{
+       isl_basic_map *bmap = NULL;
+       int i;
+
+       if (!map)
+               return NULL;
+
+       if (pos1 >= isl_map_dim(map, type1))
+               isl_die(map->ctx, isl_error_invalid,
+                       "index out of bounds", goto error);
+       if (pos2 >= isl_map_dim(map, type2))
+               isl_die(map->ctx, isl_error_invalid,
+                       "index out of bounds", goto error);
+
+       bmap = isl_basic_map_alloc_space(isl_map_get_space(map), 0, 1, 0);
+       i = isl_basic_map_alloc_equality(bmap);
+       if (i < 0)
+               goto error;
+       isl_seq_clr(bmap->eq[i], 1 + isl_basic_map_total_dim(bmap));
+       pos1 += isl_basic_map_offset(bmap, type1);
+       pos2 += isl_basic_map_offset(bmap, type2);
+       isl_int_set_si(bmap->eq[i][pos1], -1);
+       isl_int_set_si(bmap->eq[i][pos2], 1);
+       bmap = isl_basic_map_finalize(bmap);
+
+       map = isl_map_intersect(map, isl_map_from_basic_map(bmap));
+
+       return map;
+error:
+       isl_basic_map_free(bmap);
+       isl_map_free(map);
+       return NULL;
+}
+
+/* Add a constraint imposing that the given two dimensions have opposite values.
+ */
+__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)
+{
+       isl_basic_map *bmap = NULL;
+       int i;
+
+       if (!map)
+               return NULL;
+
+       if (pos1 >= isl_map_dim(map, type1))
+               isl_die(map->ctx, isl_error_invalid,
+                       "index out of bounds", goto error);
+       if (pos2 >= isl_map_dim(map, type2))
+               isl_die(map->ctx, isl_error_invalid,
+                       "index out of bounds", goto error);
+
+       bmap = isl_basic_map_alloc_space(isl_map_get_space(map), 0, 1, 0);
+       i = isl_basic_map_alloc_equality(bmap);
+       if (i < 0)
+               goto error;
+       isl_seq_clr(bmap->eq[i], 1 + isl_basic_map_total_dim(bmap));
+       pos1 += isl_basic_map_offset(bmap, type1);
+       pos2 += isl_basic_map_offset(bmap, type2);
+       isl_int_set_si(bmap->eq[i][pos1], 1);
+       isl_int_set_si(bmap->eq[i][pos2], 1);
+       bmap = isl_basic_map_finalize(bmap);
+
+       map = isl_map_intersect(map, isl_map_from_basic_map(bmap));
+
+       return map;
+error:
+       isl_basic_map_free(bmap);
+       isl_map_free(map);
+       return NULL;
+}
index b1434eb..1718153 100644 (file)
@@ -256,11 +256,11 @@ error:
 
 /*
  * Returns a map of dimension "keep_dim" with "context" as domain and
- * as range the first "isl_dim_size(keep_dim, isl_dim_out)" variables
+ * as range the first "isl_space_dim(keep_dim, isl_dim_out)" variables
  * in the quast lists.
  */
 static struct isl_map *isl_map_from_quast(struct isl_ctx *ctx, PipQuast *q,
-               struct isl_dim *keep_dim,
+               isl_space *keep_dim,
                struct isl_basic_set *context,
                struct isl_set **rest)
 {
@@ -270,7 +270,7 @@ static struct isl_map *isl_map_from_quast(struct isl_ctx *ctx, PipQuast *q,
        int             n_sol, n_nosol;
        struct scan_data        data;
        struct isl_map          *map = NULL;
-       struct isl_dim          *dims;
+       isl_space               *dims;
        unsigned                nparam;
        unsigned                dim;
        unsigned                keep;
@@ -285,7 +285,7 @@ static struct isl_map *isl_map_from_quast(struct isl_ctx *ctx, PipQuast *q,
 
        dim = isl_basic_set_n_dim(context);
        nparam = isl_basic_set_n_param(context);
-       keep = isl_dim_size(keep_dim, isl_dim_out);
+       keep = isl_space_dim(keep_dim, isl_dim_out);
        pip_param = nparam + dim;
 
        max_depth = 0;
@@ -296,19 +296,19 @@ static struct isl_map *isl_map_from_quast(struct isl_ctx *ctx, PipQuast *q,
        nexist -= pip_param-1;
 
        if (rest) {
-               *rest = isl_set_alloc_dim(isl_dim_copy(context->dim), n_nosol,
+               *rest = isl_set_alloc_space(isl_space_copy(context->dim), n_nosol,
                                        ISL_MAP_DISJOINT);
                if (!*rest)
                        goto error;
        }
-       map = isl_map_alloc_dim(isl_dim_copy(keep_dim), n_sol,
+       map = isl_map_alloc_space(isl_space_copy(keep_dim), n_sol,
                                ISL_MAP_DISJOINT);
        if (!map)
                goto error;
 
-       dims = isl_dim_reverse(isl_dim_copy(context->dim));
+       dims = isl_space_reverse(isl_space_copy(context->dim));
        data.bmap = isl_basic_map_from_basic_set(context, dims);
-       data.bmap = isl_basic_map_extend_dim(data.bmap,
+       data.bmap = isl_basic_map_extend_space(data.bmap,
                keep_dim, nexist, keep, max_depth+2*nexist);
        if (!data.bmap)
                goto error2;
@@ -337,7 +337,7 @@ static struct isl_map *isl_map_from_quast(struct isl_ctx *ctx, PipQuast *q,
        return map;
 error:
        isl_basic_set_free(context);
-       isl_dim_free(keep_dim);
+       isl_space_free(keep_dim);
 error2:
        if (data.pos)
                free(data.pos);
@@ -444,7 +444,7 @@ struct isl_map *isl_pip_basic_map_lexopt(
                struct isl_basic_set *copy;
                copy = isl_basic_set_copy(dom);
                map = isl_map_from_quast(ctx, sol,
-                               isl_dim_copy(bmap->dim), copy, empty);
+                               isl_space_copy(bmap->dim), copy, empty);
        } else {
                map = isl_map_empty_like_basic_map(bmap);
                if (empty)
index a3b106b..0309e29 100644 (file)
@@ -50,7 +50,7 @@ struct isl_basic_map {
 
        struct isl_ctx *ctx;
 
-       struct isl_dim *dim;
+       isl_space *dim;
        unsigned extra;
 
        unsigned n_eq;
@@ -87,7 +87,7 @@ struct isl_map {
 
        struct isl_ctx *ctx;
 
-       struct isl_dim *dim;
+       isl_space *dim;
 
        int n;
 
@@ -103,12 +103,12 @@ __isl_give isl_set *isl_set_realign(__isl_take isl_set *set,
 __isl_give isl_map *isl_map_reset(__isl_take isl_map *map,
        enum isl_dim_type type);
 
-__isl_give isl_basic_set *isl_basic_set_reset_dim(
-       __isl_take isl_basic_set *bset, __isl_take isl_dim *dim);
-__isl_give isl_basic_map *isl_basic_map_reset_dim(
-       __isl_take isl_basic_map *bmap, __isl_take isl_dim *dim);
-__isl_give isl_map *isl_map_reset_dim(__isl_take isl_map *map,
-       __isl_take isl_dim *dim);
+__isl_give isl_basic_set *isl_basic_set_reset_space(
+       __isl_take isl_basic_set *bset, __isl_take isl_space *dim);
+__isl_give isl_basic_map *isl_basic_map_reset_space(
+       __isl_take isl_basic_map *bmap, __isl_take isl_space *dim);
+__isl_give isl_map *isl_map_reset_space(__isl_take isl_map *map,
+       __isl_take isl_space *dim);
 
 unsigned isl_basic_map_offset(struct isl_basic_map *bmap,
                                        enum isl_dim_type type);
@@ -123,11 +123,11 @@ int isl_basic_map_compatible_domain(struct isl_basic_map *bmap,
 int isl_basic_map_compatible_range(struct isl_basic_map *bmap,
                struct isl_basic_set *bset);
 
-struct isl_basic_map *isl_basic_map_extend_dim(struct isl_basic_map *base,
-               struct isl_dim *dim, unsigned extra,
+struct isl_basic_map *isl_basic_map_extend_space(struct isl_basic_map *base,
+               __isl_take isl_space *dim, unsigned extra,
                unsigned n_eq, unsigned n_ineq);
-struct isl_basic_set *isl_basic_set_extend_dim(struct isl_basic_set *base,
-               struct isl_dim *dim, unsigned extra,
+struct isl_basic_set *isl_basic_set_extend_space(struct isl_basic_set *base,
+               __isl_take isl_space *dim, unsigned extra,
                unsigned n_eq, unsigned n_ineq);
 struct isl_basic_set *isl_basic_set_add_constraints(struct isl_basic_set *bset1,
                struct isl_basic_set *bset2, unsigned pos);
@@ -138,12 +138,14 @@ struct isl_set *isl_set_grow(struct isl_set *set, int n);
 int isl_basic_set_contains(struct isl_basic_set *bset, struct isl_vec *vec);
 int isl_basic_map_contains(struct isl_basic_map *bmap, struct isl_vec *vec);
 
-struct isl_basic_set *isl_basic_set_alloc_dim(struct isl_dim *dim,
+__isl_give isl_basic_set *isl_basic_set_alloc_space(__isl_take isl_space *dim,
                unsigned extra, unsigned n_eq, unsigned n_ineq);
-struct isl_set *isl_set_alloc_dim(struct isl_dim *dim, int n, unsigned flags);
-struct isl_basic_map *isl_basic_map_alloc_dim(struct isl_dim *dim,
+__isl_give isl_set *isl_set_alloc_space(__isl_take isl_space *dim, int n,
+       unsigned flags);
+__isl_give isl_basic_map *isl_basic_map_alloc_space(__isl_take isl_space *dim,
                unsigned extra, unsigned n_eq, unsigned n_ineq);
-struct isl_map *isl_map_alloc_dim(struct isl_dim *dim, int n, unsigned flags);
+__isl_give isl_map *isl_map_alloc_space(__isl_take isl_space *dim, int n,
+       unsigned flags);
 
 unsigned isl_basic_map_total_dim(const struct isl_basic_map *bmap);
 
@@ -265,6 +267,7 @@ struct isl_basic_set *isl_basic_set_lineality_space(struct isl_basic_set *bset);
 struct isl_basic_set *isl_basic_set_set_rational(struct isl_basic_set *bset);
 __isl_give isl_basic_map *isl_basic_map_set_rational(
        __isl_take isl_basic_map *bmap);
+__isl_give isl_map *isl_map_set_rational(__isl_take isl_map *map);
 
 struct isl_mat;
 
@@ -308,4 +311,14 @@ int isl_basic_map_divs_known(__isl_keep isl_basic_map *bmap);
 __isl_give isl_map *isl_map_inline_foreach_basic_map(__isl_take isl_map *map,
        __isl_give isl_basic_map *(*fn)(__isl_take isl_basic_map *bmap));
 
+__isl_give isl_map *isl_map_align_params_map_map_and(
+       __isl_take isl_map *map1, __isl_take isl_map *map2,
+       __isl_give isl_map *(*fn)(__isl_take isl_map *map1,
+                                   __isl_take isl_map *map2));
+
+int isl_basic_set_foreach_lexopt(__isl_keep isl_basic_set *bset, int max,
+       int (*fn)(__isl_take isl_basic_set *dom, __isl_take isl_aff_list *list,
+                 void *user),
+       void *user);
+
 #endif
index c299aba..db025eb 100644 (file)
@@ -14,7 +14,7 @@
 #include <isl/map.h>
 #include <isl/seq.h>
 #include "isl_tab.h"
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl_mat_private.h>
 
 static void swap_equality(struct isl_basic_map *bmap, int a, int b)
@@ -56,7 +56,7 @@ struct isl_basic_set *isl_basic_set_drop_dims(
 
        isl_assert(bset->ctx, first + n <= bset->dim->n_out, goto error);
 
-       if (n == 0 && !isl_dim_get_tuple_name(bset->dim, isl_dim_set))
+       if (n == 0 && !isl_space_get_tuple_name(bset->dim, isl_dim_set))
                return bset;
 
        bset = isl_basic_set_cow(bset);
@@ -75,7 +75,7 @@ struct isl_basic_set *isl_basic_set_drop_dims(
                constraint_drop_vars(bset->div[i]+1+1+bset->dim->nparam+first, n,
                                     (bset->dim->n_out-first-n)+bset->extra);
 
-       bset->dim = isl_dim_drop_outputs(bset->dim, first, n);
+       bset->dim = isl_space_drop_outputs(bset->dim, first, n);
        if (!bset->dim)
                goto error;
 
@@ -97,12 +97,12 @@ struct isl_set *isl_set_drop_dims(
 
        isl_assert(set->ctx, first + n <= set->dim->n_out, goto error);
 
-       if (n == 0 && !isl_dim_get_tuple_name(set->dim, isl_dim_set))
+       if (n == 0 && !isl_space_get_tuple_name(set->dim, isl_dim_set))
                return set;
        set = isl_set_cow(set);
        if (!set)
                goto error;
-       set->dim = isl_dim_drop_outputs(set->dim, first, n);
+       set->dim = isl_space_drop_outputs(set->dim, first, n);
        if (!set->dim)
                goto error;
 
@@ -167,7 +167,7 @@ struct isl_basic_map *isl_basic_map_drop(struct isl_basic_map *bmap,
        dim = isl_basic_map_dim(bmap, type);
        isl_assert(bmap->ctx, first + n <= dim, goto error);
 
-       if (n == 0 && !isl_dim_is_named_or_nested(bmap->dim, type))
+       if (n == 0 && !isl_space_is_named_or_nested(bmap->dim, type))
                return bmap;
 
        bmap = isl_basic_map_cow(bmap);
@@ -191,7 +191,7 @@ struct isl_basic_map *isl_basic_map_drop(struct isl_basic_map *bmap,
                        goto error;
                isl_basic_map_free_div(bmap, n);
        } else
-               bmap->dim = isl_dim_drop(bmap->dim, type, first, n);
+               bmap->dim = isl_space_drop_dims(bmap->dim, type, first, n);
        if (!bmap->dim)
                goto error;
 
@@ -226,12 +226,12 @@ struct isl_map *isl_map_drop(struct isl_map *map,
 
        isl_assert(map->ctx, first + n <= isl_map_dim(map, type), goto error);
 
-       if (n == 0 && !isl_dim_get_tuple_name(map->dim, type))
+       if (n == 0 && !isl_space_get_tuple_name(map->dim, type))
                return map;
        map = isl_map_cow(map);
        if (!map)
                goto error;
-       map->dim = isl_dim_drop(map->dim, type, first, n);
+       map->dim = isl_space_drop_dims(map->dim, type, first, n);
        if (!map->dim)
                goto error;
 
@@ -272,7 +272,7 @@ static struct isl_basic_map *isl_basic_map_drop_div(
        if (!bmap)
                goto error;
 
-       pos = 1 + isl_dim_total(bmap->dim) + div;
+       pos = 1 + isl_space_dim(bmap->dim, isl_dim_all) + div;
 
        isl_assert(bmap->ctx, div < bmap->n_div, goto error);
 
@@ -376,12 +376,13 @@ static void eliminate_var_using_equality(struct isl_basic_map *bmap,
        unsigned pos, isl_int *eq, int keep_divs, int *progress)
 {
        unsigned total;
+       unsigned space_total;
        int k;
        int last_div;
 
        total = isl_basic_map_total_dim(bmap);
-       last_div = isl_seq_last_non_zero(eq + 1 + isl_dim_total(bmap->dim),
-                                               bmap->n_div);
+       space_total = isl_space_dim(bmap->dim, isl_dim_all);
+       last_div = isl_seq_last_non_zero(eq + 1 + space_total, bmap->n_div);
        for (k = 0; k < bmap->n_eq; ++k) {
                if (bmap->eq[k] == eq)
                        continue;
@@ -431,7 +432,7 @@ static void eliminate_var_using_equality(struct isl_basic_map *bmap,
 static void eliminate_div(struct isl_basic_map *bmap, isl_int *eq,
        unsigned div, int keep_divs)
 {
-       unsigned pos = isl_dim_total(bmap->dim) + div;
+       unsigned pos = isl_space_dim(bmap->dim, isl_dim_all) + div;
 
        eliminate_var_using_equality(bmap, pos, eq, keep_divs, NULL);
 
@@ -446,10 +447,10 @@ static int ok_to_eliminate_div(struct isl_basic_map *bmap, isl_int *eq,
 {
        int k;
        int last_div;
-       unsigned pos = isl_dim_total(bmap->dim) + div;
+       unsigned space_total = isl_space_dim(bmap->dim, isl_dim_all);
+       unsigned pos = space_total + div;
 
-       last_div = isl_seq_last_non_zero(eq + 1 + isl_dim_total(bmap->dim),
-                                               bmap->n_div);
+       last_div = isl_seq_last_non_zero(eq + 1 + space_total, bmap->n_div);
        if (last_div < 0 || last_div <= div)
                return 1;
 
@@ -478,7 +479,7 @@ static struct isl_basic_map *eliminate_divs_eq(
        if (!bmap)
                return NULL;
 
-       off = 1 + isl_dim_total(bmap->dim);
+       off = 1 + isl_space_dim(bmap->dim, isl_dim_all);
 
        for (d = bmap->n_div - 1; d >= 0 ; --d) {
                for (i = 0; i < bmap->n_eq; ++i) {
@@ -513,7 +514,7 @@ static struct isl_basic_map *eliminate_divs_ineq(
                return NULL;
 
        ctx = bmap->ctx;
-       off = 1 + isl_dim_total(bmap->dim);
+       off = 1 + isl_space_dim(bmap->dim, isl_dim_all);
 
        for (d = bmap->n_div - 1; d >= 0 ; --d) {
                for (i = 0; i < bmap->n_eq; ++i)
@@ -653,7 +654,7 @@ static struct isl_basic_map *remove_duplicate_divs(
        if (!bmap || bmap->n_div <= 1)
                return bmap;
 
-       total_var = isl_dim_total(bmap->dim);
+       total_var = isl_space_dim(bmap->dim, isl_dim_all);
        total = total_var + bmap->n_div;
 
        ctx = bmap->ctx;
@@ -716,7 +717,7 @@ static int n_pure_div_eq(struct isl_basic_map *bmap)
        int i, j;
        unsigned total;
 
-       total = isl_dim_total(bmap->dim);
+       total = isl_space_dim(bmap->dim, isl_dim_all);
        for (i = 0, j = bmap->n_div-1; i < bmap->n_eq; ++i) {
                while (j >= 0 && isl_int_is_zero(bmap->eq[i][1 + total + j]))
                        --j;
@@ -803,7 +804,7 @@ static struct isl_basic_map *normalize_divs(
        if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_NORMALIZED_DIVS))
                return bmap;
 
-       total = isl_dim_total(bmap->dim);
+       total = isl_space_dim(bmap->dim, isl_dim_all);
        div_eq = n_pure_div_eq(bmap);
        if (div_eq == 0)
                return bmap;
@@ -878,7 +879,7 @@ static struct isl_basic_map *normalize_divs(
                        needed++;
        }
        if (needed > dropped) {
-               bmap = isl_basic_map_extend_dim(bmap, isl_dim_copy(bmap->dim),
+               bmap = isl_basic_map_extend_space(bmap, isl_space_copy(bmap->dim),
                                needed, needed, 0);
                if (!bmap)
                        goto error;
@@ -928,7 +929,7 @@ error:
 static struct isl_basic_map *set_div_from_lower_bound(
        struct isl_basic_map *bmap, int div, int ineq)
 {
-       unsigned total = 1 + isl_dim_total(bmap->dim);
+       unsigned total = 1 + isl_space_dim(bmap->dim, isl_dim_all);
 
        isl_seq_neg(bmap->div[div] + 1, bmap->ineq[ineq], total + bmap->n_div);
        isl_int_set(bmap->div[div][0], bmap->ineq[ineq][total + div]);
@@ -949,7 +950,7 @@ static int ok_to_set_div_from_bound(struct isl_basic_map *bmap,
        int div, int ineq)
 {
        int j;
-       unsigned total = 1 + isl_dim_total(bmap->dim);
+       unsigned total = 1 + isl_space_dim(bmap->dim, isl_dim_all);
 
        /* Not defined in terms of unknown divs */
        for (j = 0; j < bmap->n_div; ++j) {
@@ -989,7 +990,7 @@ static struct isl_basic_map *check_for_div_constraints(
        struct isl_basic_map *bmap, int k, int l, isl_int sum, int *progress)
 {
        int i;
-       unsigned total = 1 + isl_dim_total(bmap->dim);
+       unsigned total = 1 + isl_space_dim(bmap->dim, isl_dim_all);
 
        for (i = 0; i < bmap->n_div; ++i) {
                if (!isl_int_is_zero(bmap->div[i][0]))
@@ -1117,7 +1118,7 @@ int isl_basic_map_is_div_constraint(__isl_keep isl_basic_map *bmap,
        if (!bmap)
                return -1;
 
-       pos = 1 + isl_dim_total(bmap->dim) + div;
+       pos = 1 + isl_space_dim(bmap->dim, isl_dim_all) + div;
 
        if (isl_int_eq(constraint[pos], bmap->div[div][0])) {
                int neg;
@@ -1157,7 +1158,7 @@ int isl_basic_map_is_div_constraint(__isl_keep isl_basic_map *bmap,
 static int div_is_redundant(struct isl_basic_map *bmap, int div)
 {
        int i;
-       unsigned pos = 1 + isl_dim_total(bmap->dim) + div;
+       unsigned pos = 1 + isl_space_dim(bmap->dim, isl_dim_all) + div;
 
        for (i = 0; i < bmap->n_eq; ++i)
                if (!isl_int_is_zero(bmap->eq[i][pos]))
@@ -1371,7 +1372,7 @@ static void compute_elimination_index(struct isl_basic_map *bmap, int *elim)
        int d, i;
        unsigned total;
 
-       total = isl_dim_total(bmap->dim);
+       total = isl_space_dim(bmap->dim, isl_dim_all);
        for (d = 0; d < total; ++d)
                elim[d] = -1;
        for (i = 0; i < bmap->n_eq; ++i) {
@@ -1396,7 +1397,7 @@ static int reduced_using_equalities(isl_int *dst, isl_int *src,
        int copied = 0;
        unsigned total;
 
-       total = isl_dim_total(bmap->dim);
+       total = isl_space_dim(bmap->dim, isl_dim_all);
        for (d = total - 1; d >= 0; --d) {
                if (isl_int_is_zero(src[1+d]))
                        continue;
@@ -1737,7 +1738,7 @@ struct isl_basic_map *isl_basic_map_gist(struct isl_basic_map *bmap,
                return bmap;
        }
        if (isl_basic_map_plain_is_empty(context)) {
-               struct isl_dim *dim = isl_dim_copy(bmap->dim);
+               isl_space *dim = isl_space_copy(bmap->dim);
                isl_basic_map_free(context);
                isl_basic_map_free(bmap);
                return isl_basic_map_universe(dim);
@@ -1778,7 +1779,7 @@ __isl_give isl_map *isl_map_gist_basic_map(__isl_take isl_map *map,
                goto error;;
 
        if (isl_basic_map_plain_is_empty(context)) {
-               struct isl_dim *dim = isl_dim_copy(map->dim);
+               isl_space *dim = isl_space_copy(map->dim);
                isl_basic_map_free(context);
                isl_map_free(map);
                return isl_map_universe(dim);
@@ -1788,7 +1789,7 @@ __isl_give isl_map *isl_map_gist_basic_map(__isl_take isl_map *map,
        map = isl_map_cow(map);
        if (!map || !context)
                goto error;;
-       isl_assert(map->ctx, isl_dim_equal(map->dim, context->dim), goto error);
+       isl_assert(map->ctx, isl_space_is_equal(map->dim, context->dim), goto error);
        map = isl_map_compute_divs(map);
        for (i = 0; i < map->n; ++i)
                context = isl_basic_map_align_divs(context, map->p[i]);
@@ -1813,13 +1814,19 @@ error:
        return NULL;
 }
 
-__isl_give isl_map *isl_map_gist(__isl_take isl_map *map,
+static __isl_give isl_map *map_gist(__isl_take isl_map *map,
        __isl_take isl_map *context)
 {
        context = isl_map_compute_divs(context);
        return isl_map_gist_basic_map(map, isl_map_simple_hull(context));
 }
 
+__isl_give isl_map *isl_map_gist(__isl_take isl_map *map,
+       __isl_take isl_map *context)
+{
+       return isl_map_align_params_map_map_and(map, context, &map_gist);
+}
+
 struct isl_basic_set *isl_basic_set_gist(struct isl_basic_set *bset,
                                                struct isl_basic_set *context)
 {
@@ -1841,6 +1848,20 @@ __isl_give isl_set *isl_set_gist(__isl_take isl_set *set,
                                        (struct isl_map *)context);
 }
 
+__isl_give isl_map *isl_map_gist_params(__isl_take isl_map *map,
+       __isl_take isl_set *context)
+{
+       isl_map *map_context = isl_map_universe(isl_map_get_space(map));
+       map_context = isl_map_intersect_params(map_context, context);
+       return isl_map_gist(map, map_context);
+}
+
+__isl_give isl_set *isl_set_gist_params(__isl_take isl_set *set,
+       __isl_take isl_set *context)
+{
+       return isl_map_gist_params(set, context);
+}
+
 /* Quick check to see if two basic maps are disjoint.
  * In particular, we reduce the equalities and inequalities of
  * one basic map in the context of the equalities of the other
@@ -1856,14 +1877,14 @@ int isl_basic_map_plain_is_disjoint(__isl_keep isl_basic_map *bmap1,
 
        if (!bmap1 || !bmap2)
                return -1;
-       isl_assert(bmap1->ctx, isl_dim_equal(bmap1->dim, bmap2->dim),
+       isl_assert(bmap1->ctx, isl_space_is_equal(bmap1->dim, bmap2->dim),
                        return -1);
        if (bmap1->n_div || bmap2->n_div)
                return 0;
        if (!bmap1->n_eq && !bmap2->n_eq)
                return 0;
 
-       total = isl_dim_total(bmap1->dim);
+       total = isl_space_dim(bmap1->dim, isl_dim_all);
        if (total == 0)
                return 0;
        v = isl_vec_alloc(bmap1->ctx, 1 + total);
@@ -1989,7 +2010,7 @@ static int div_find_coalesce(struct isl_basic_map *bmap, int *pairs,
 
        if (bmap->n_div <= 1)
                return -1;
-       dim = isl_dim_total(bmap->dim);
+       dim = isl_space_dim(bmap->dim, isl_dim_all);
        if (isl_seq_first_non_zero(bmap->ineq[l] + 1 + dim, div) != -1)
                return -1;
        if (isl_seq_first_non_zero(bmap->ineq[l] + 1 + dim + div + 1,
@@ -2092,7 +2113,7 @@ static void construct_test_ineq(struct isl_basic_map *bmap, int i,
        int l, int u, isl_int *ineq, isl_int g, isl_int fl, isl_int fu)
 {
        unsigned dim;
-       dim = isl_dim_total(bmap->dim);
+       dim = isl_space_dim(bmap->dim, isl_dim_all);
 
        isl_int_gcd(g, bmap->ineq[l][1 + dim + i], bmap->ineq[u][1 + dim + i]);
        isl_int_divexact(fl, bmap->ineq[l][1 + dim + i], g);
@@ -2130,7 +2151,7 @@ static struct isl_basic_map *drop_more_redundant_divs(
        if (!bmap)
                goto error;
 
-       dim = isl_dim_total(bmap->dim);
+       dim = isl_space_dim(bmap->dim, isl_dim_all);
        vec = isl_vec_alloc(bmap->ctx, 1 + dim + bmap->n_div);
        if (!vec)
                goto error;
@@ -2261,7 +2282,7 @@ static struct isl_basic_map *coalesce_divs(struct isl_basic_map *bmap,
        unsigned dim, total;
        int i;
 
-       dim = isl_dim_total(bmap->dim);
+       dim = isl_space_dim(bmap->dim, isl_dim_all);
        total = 1 + dim + bmap->n_div;
 
        isl_int_init(a);
@@ -2321,7 +2342,7 @@ static struct isl_basic_map *coalesce_or_drop_more_redundant_divs(
        int i, l, u;
        unsigned dim;
 
-       dim = isl_dim_total(bmap->dim);
+       dim = isl_space_dim(bmap->dim, isl_dim_all);
 
        for (i = 0; i < bmap->n_div; ++i) {
                if (!pairs[i])
@@ -2375,7 +2396,7 @@ struct isl_basic_map *isl_basic_map_drop_redundant_divs(
        if (!bmap)
                goto error;
 
-       off = isl_dim_total(bmap->dim);
+       off = isl_space_dim(bmap->dim, isl_dim_all);
        pairs = isl_calloc_array(bmap->ctx, int, bmap->n_div);
        if (!pairs)
                goto error;
index 08177e7..5109377 100644 (file)
@@ -43,7 +43,7 @@ static int tab_add_constraints(struct isl_tab *tab,
 
        tab_total = isl_basic_map_total_dim(tab->bmap);
        bmap_total = isl_basic_map_total_dim(bmap);
-       dim = isl_dim_total(tab->bmap->dim);
+       dim = isl_space_dim(tab->bmap->dim, isl_dim_all);
 
        if (isl_tab_extend_cons(tab, 2 * bmap->n_eq + bmap->n_ineq) < 0)
                return -1;
@@ -99,7 +99,7 @@ static int tab_add_constraint(struct isl_tab *tab,
 
        tab_total = isl_basic_map_total_dim(tab->bmap);
        bmap_total = isl_basic_map_total_dim(bmap);
-       dim = isl_dim_total(tab->bmap->dim);
+       dim = isl_space_dim(tab->bmap->dim, isl_dim_all);
 
        v = isl_vec_alloc(bmap->ctx, 1 + tab_total);
        if (!v)
@@ -478,7 +478,8 @@ static __isl_give isl_map *basic_map_subtract(__isl_take isl_basic_map *bmap,
 /* Return the set difference between map1 and map2.
  * (U_i A_i) \ (U_j B_j) is computed as U_i (A_i \ (U_j B_j))
  */
-struct isl_map *isl_map_subtract(struct isl_map *map1, struct isl_map *map2)
+static __isl_give isl_map *map_subtract( __isl_take isl_map *map1,
+       __isl_take isl_map *map2)
 {
        int i;
        struct isl_map *diff;
@@ -486,7 +487,7 @@ struct isl_map *isl_map_subtract(struct isl_map *map1, struct isl_map *map2)
        if (!map1 || !map2)
                goto error;
 
-       isl_assert(map1->ctx, isl_dim_equal(map1->dim, map2->dim), goto error);
+       isl_assert(map1->ctx, isl_space_is_equal(map1->dim, map2->dim), goto error);
 
        if (isl_map_is_empty(map2)) {
                isl_map_free(map2);
@@ -522,6 +523,12 @@ error:
        return NULL;
 }
 
+__isl_give isl_map *isl_map_subtract( __isl_take isl_map *map1,
+       __isl_take isl_map *map2)
+{
+       return isl_map_align_params_map_map_and(map1, map2, &map_subtract);
+}
+
 struct isl_set *isl_set_subtract(struct isl_set *set1, struct isl_set *set2)
 {
        return (struct isl_set *)
@@ -665,7 +672,7 @@ static __isl_give isl_point *singleton_extract_point(
        }
 
        isl_int_clear(m);
-       return isl_point_alloc(isl_basic_map_get_dim(bmap), point);
+       return isl_point_alloc(isl_basic_map_get_space(bmap), point);
 error:
        isl_int_clear(m);
        isl_vec_free(point);
@@ -709,7 +716,7 @@ int isl_map_is_subset(struct isl_map *map1, struct isl_map *map2)
        if (!map1 || !map2)
                return -1;
 
-       if (!isl_map_has_equal_dim(map1, map2))
+       if (!isl_map_has_equal_space(map1, map2))
                return 0;
 
        if (isl_map_is_empty(map1))
@@ -787,7 +794,7 @@ __isl_give isl_set *isl_set_complement(__isl_take isl_set *set)
        if (!set)
                return NULL;
 
-       universe = isl_set_universe(isl_set_get_dim(set));
+       universe = isl_set_universe(isl_set_get_space(set));
 
        return isl_set_subtract(universe, set);
 }
index e64beae..7a0d1a2 100644 (file)
--- a/isl_mat.c
+++ b/isl_mat.c
@@ -8,11 +8,11 @@
  */
 
 #include <isl_ctx_private.h>
-#include <isl/dim.h>
+#include <isl/space.h>
 #include <isl/seq.h>
 #include <isl_mat_private.h>
 #include "isl_map_private.h"
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 
 isl_ctx *isl_mat_get_ctx(__isl_keep isl_mat *mat)
 {
@@ -1064,7 +1064,7 @@ struct isl_basic_set *isl_basic_set_preimage(struct isl_basic_set *bset,
                if (!bset)
                        goto error;
        } else if (mat->n_col < mat->n_row) {
-               bset->dim = isl_dim_cow(bset->dim);
+               bset->dim = isl_space_cow(bset->dim);
                if (!bset->dim)
                        goto error;
                bset->dim->n_out -= mat->n_row - mat->n_col;
@@ -1115,7 +1115,7 @@ struct isl_set *isl_set_preimage(struct isl_set *set, struct isl_mat *mat)
                        goto error;
        }
        if (mat->n_col != mat->n_row) {
-               set->dim = isl_dim_cow(set->dim);
+               set->dim = isl_space_cow(set->dim);
                if (!set->dim)
                        goto error;
                set->dim->n_out += mat->n_col;
index 5887403..69aabab 100644 (file)
@@ -12,7 +12,7 @@
 #include <isl_morph.h>
 #include <isl/seq.h>
 #include <isl_mat_private.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl_equalities.h>
 
 __isl_give isl_morph *isl_morph_alloc(
@@ -88,12 +88,12 @@ void isl_morph_free(__isl_take isl_morph *morph)
        free(morph);
 }
 
-__isl_give isl_dim *isl_morph_get_ran_dim(__isl_keep isl_morph *morph)
+__isl_give isl_space *isl_morph_get_ran_space(__isl_keep isl_morph *morph)
 {
        if (!morph)
                return NULL;
        
-       return isl_dim_copy(morph->ran->dim);
+       return isl_space_copy(morph->ran->dim);
 }
 
 unsigned isl_morph_dom_dim(__isl_keep isl_morph *morph, enum isl_dim_type type)
@@ -124,7 +124,7 @@ __isl_give isl_morph *isl_morph_remove_dom_dims(__isl_take isl_morph *morph,
        if (!morph)
                return NULL;
 
-       dom_offset = 1 + isl_dim_offset(morph->dom->dim, type);
+       dom_offset = 1 + isl_space_offset(morph->dom->dim, type);
 
        morph->dom = isl_basic_set_remove_dims(morph->dom, type, first, n);
 
@@ -151,7 +151,7 @@ __isl_give isl_morph *isl_morph_remove_ran_dims(__isl_take isl_morph *morph,
        if (!morph)
                return NULL;
 
-       ran_offset = 1 + isl_dim_offset(morph->ran->dim, type);
+       ran_offset = 1 + isl_space_offset(morph->ran->dim, type);
 
        morph->ran = isl_basic_set_remove_dims(morph->ran, type, first, n);
 
@@ -166,6 +166,46 @@ __isl_give isl_morph *isl_morph_remove_ran_dims(__isl_take isl_morph *morph,
        return NULL;
 }
 
+/* Project domain of morph onto its parameter domain.
+ */
+__isl_give isl_morph *isl_morph_dom_params(__isl_take isl_morph *morph)
+{
+       unsigned n;
+
+       if (!morph)
+               return NULL;
+       n = isl_basic_set_dim(morph->dom, isl_dim_set);
+       morph = isl_morph_remove_dom_dims(morph, isl_dim_set, 0, n);
+       if (!morph)
+               return NULL;
+       morph->dom = isl_basic_set_params(morph->dom);
+       if (morph->dom)
+               return morph;
+
+       isl_morph_free(morph);
+       return NULL;
+}
+
+/* Project range of morph onto its parameter domain.
+ */
+__isl_give isl_morph *isl_morph_ran_params(__isl_take isl_morph *morph)
+{
+       unsigned n;
+
+       if (!morph)
+               return NULL;
+       n = isl_basic_set_dim(morph->ran, isl_dim_set);
+       morph = isl_morph_remove_ran_dims(morph, isl_dim_set, 0, n);
+       if (!morph)
+               return NULL;
+       morph->ran = isl_basic_set_params(morph->ran);
+       if (morph->ran)
+               return morph;
+
+       isl_morph_free(morph);
+       return NULL;
+}
+
 void isl_morph_dump(__isl_take isl_morph *morph, FILE *out)
 {
        if (!morph)
@@ -188,7 +228,7 @@ __isl_give isl_morph *isl_morph_identity(__isl_keep isl_basic_set *bset)
 
        total = isl_basic_set_total_dim(bset);
        id = isl_mat_identity(bset->ctx, 1 + total);
-       universe = isl_basic_set_universe(isl_dim_copy(bset->dim));
+       universe = isl_basic_set_universe(isl_space_copy(bset->dim));
 
        return isl_morph_alloc(universe, isl_basic_set_copy(universe),
                id, isl_mat_copy(id));
@@ -208,7 +248,7 @@ __isl_give isl_morph *isl_morph_empty(__isl_keep isl_basic_set *bset)
 
        total = isl_basic_set_total_dim(bset);
        id = isl_mat_identity(bset->ctx, 1 + total);
-       empty = isl_basic_set_empty(isl_dim_copy(bset->dim));
+       empty = isl_basic_set_empty(isl_space_copy(bset->dim));
 
        return isl_morph_alloc(empty, isl_basic_set_copy(empty),
                id, isl_mat_copy(id));
@@ -253,7 +293,7 @@ static __isl_give isl_basic_set *copy_equalities(__isl_keep isl_basic_set *bset,
        isl_assert(bset->ctx, bset->n_div == 0, return NULL);
 
        total = isl_basic_set_total_dim(bset);
-       eq = isl_basic_set_alloc_dim(isl_dim_copy(bset->dim), 0, n, 0);
+       eq = isl_basic_set_alloc_space(isl_space_copy(bset->dim), 0, n, 0);
        if (!eq)
                return NULL;
        for (i = 0; i < n; ++i) {
@@ -327,7 +367,7 @@ __isl_give isl_morph *isl_basic_set_variable_compression(
        unsigned orest;
        unsigned nrest;
        int f_eq, n_eq;
-       isl_dim *dim;
+       isl_space *dim;
        isl_mat *H, *U, *Q, *C = NULL, *H1, *U1, *U2;
        isl_basic_set *dom, *ran;
 
@@ -339,7 +379,7 @@ __isl_give isl_morph *isl_basic_set_variable_compression(
 
        isl_assert(bset->ctx, bset->n_div == 0, return NULL);
 
-       otype = 1 + isl_dim_offset(bset->dim, type);
+       otype = 1 + isl_space_offset(bset->dim, type);
        ntype = isl_basic_set_dim(bset, type);
        orest = otype + ntype;
        nrest = isl_basic_set_total_dim(bset) - (orest - 1);
@@ -407,9 +447,9 @@ __isl_give isl_morph *isl_basic_set_variable_compression(
        C = insert_parameter_rows(C, otype - 1);
        C = isl_mat_diagonal(C, isl_mat_identity(bset->ctx, nrest));
 
-       dim = isl_dim_copy(bset->dim);
-       dim = isl_dim_drop(dim, type, 0, ntype);
-       dim = isl_dim_add(dim, type, ntype - n_eq);
+       dim = isl_space_copy(bset->dim);
+       dim = isl_space_drop_dims(dim, type, 0, ntype);
+       dim = isl_space_add_dims(dim, type, ntype - n_eq);
        ran = isl_basic_set_universe(dim);
        dom = copy_equalities(bset, f_eq, n_eq);
 
@@ -481,8 +521,8 @@ __isl_give isl_morph *isl_basic_set_parameter_compression(
        inv = isl_mat_diagonal(inv, isl_mat_identity(bset->ctx, nvar));
        map = isl_mat_right_inverse(isl_mat_copy(inv));
 
-       dom = isl_basic_set_universe(isl_dim_copy(bset->dim));
-       ran = isl_basic_set_universe(isl_dim_copy(bset->dim));
+       dom = isl_basic_set_universe(isl_space_copy(bset->dim));
+       ran = isl_basic_set_universe(isl_space_copy(bset->dim));
 
        return isl_morph_alloc(dom, ran, map, inv);
 error:
@@ -569,13 +609,13 @@ __isl_give isl_basic_set *isl_morph_basic_set(__isl_take isl_morph *morph,
        if (!morph || !bset)
                goto error;
 
-       isl_assert(bset->ctx, isl_dim_equal(bset->dim, morph->dom->dim),
+       isl_assert(bset->ctx, isl_space_is_equal(bset->dim, morph->dom->dim),
                    goto error);
 
        max_stride = morph->inv->n_row - 1;
        if (isl_int_is_one(morph->inv->row[0][0]))
                max_stride = 0;
-       res = isl_basic_set_alloc_dim(isl_dim_copy(morph->ran->dim),
+       res = isl_basic_set_alloc_space(isl_space_copy(morph->ran->dim),
                bset->n_div + max_stride, bset->n_eq + max_stride, bset->n_ineq);
 
        for (i = 0; i < bset->n_div; ++i)
@@ -659,14 +699,14 @@ __isl_give isl_set *isl_morph_set(__isl_take isl_morph *morph,
        if (!morph || !set)
                goto error;
 
-       isl_assert(set->ctx, isl_dim_equal(set->dim, morph->dom->dim), goto error);
+       isl_assert(set->ctx, isl_space_is_equal(set->dim, morph->dom->dim), goto error);
 
        set = isl_set_cow(set);
        if (!set)
                goto error;
 
-       isl_dim_free(set->dim);
-       set->dim = isl_dim_copy(morph->ran->dim);
+       isl_space_free(set->dim);
+       set->dim = isl_space_copy(morph->ran->dim);
        if (!set->dim)
                goto error;
 
index f125cdc..3723448 100644 (file)
@@ -12,7 +12,7 @@
 #define ISL_MORHP_H
 
 #include <stdio.h>
-#include <isl/dim.h>
+#include <isl/space.h>
 #include <isl/mat.h>
 #include <isl/set.h>
 
@@ -42,7 +42,7 @@ __isl_give isl_morph *isl_morph_copy(__isl_keep isl_morph *morph);
 __isl_give isl_morph *isl_morph_identity(__isl_keep isl_basic_set *bset);
 void isl_morph_free(__isl_take isl_morph *morph);
 
-__isl_give isl_dim *isl_morph_get_ran_dim(__isl_keep isl_morph *morph);
+__isl_give isl_space *isl_morph_get_ran_space(__isl_keep isl_morph *morph);
 unsigned isl_morph_dom_dim(__isl_keep isl_morph *morph, enum isl_dim_type type);
 unsigned isl_morph_ran_dim(__isl_keep isl_morph *morph, enum isl_dim_type type);
 
@@ -50,6 +50,8 @@ __isl_give isl_morph *isl_morph_remove_dom_dims(__isl_take isl_morph *morph,
        enum isl_dim_type type, unsigned first, unsigned n);
 __isl_give isl_morph *isl_morph_remove_ran_dims(__isl_take isl_morph *morph,
        enum isl_dim_type type, unsigned first, unsigned n);
+__isl_give isl_morph *isl_morph_dom_params(__isl_take isl_morph *morph);
+__isl_give isl_morph *isl_morph_ran_params(__isl_take isl_morph *morph);
 
 __isl_give isl_morph *isl_morph_compose(__isl_take isl_morph *morph1,
        __isl_take isl_morph *morph2);
diff --git a/isl_name.c b/isl_name.c
deleted file mode 100644 (file)
index a9a6382..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 2008-2009 Katholieke Universiteit Leuven
- *
- * Use of this software is governed by the GNU LGPLv2.1 license
- *
- * Written by Sven Verdoolaege, K.U.Leuven, Departement
- * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
- */
-
-#include <string.h>
-#include <isl_ctx_private.h>
-#include "isl_name.h"
-
-struct isl_name *isl_name_alloc(struct isl_ctx *ctx, const char *s)
-{
-       const char *copy = strdup(s);
-       struct isl_name *name;
-
-       if (!copy)
-               return NULL;
-       name = isl_alloc_type(ctx, struct isl_name);
-       if (!name)
-               goto error;
-
-       name->ref = 1;
-       name->name = copy;
-
-       name->hash = isl_hash_init();
-       name->hash = isl_hash_string(name->hash, s);
-
-       return name;
-error:
-       free((char *)copy);
-       return NULL;
-}
-
-static int isl_name_has_name(const void *entry, const void *val)
-{
-       struct isl_name *name = (struct isl_name *)entry;
-       const char *s = (const char *)val;
-
-       return !strcmp(name->name, s);
-}
-
-struct isl_name *isl_name_get(struct isl_ctx *ctx, const char *name)
-{
-       struct isl_hash_table_entry *entry;
-       uint32_t name_hash;
-
-       name_hash = isl_hash_string(isl_hash_init(), name);
-       entry = isl_hash_table_find(ctx, &ctx->name_hash, name_hash,
-                                       isl_name_has_name, name, 1);
-       if (!entry)
-               return NULL;
-       if (entry->data)
-               return isl_name_copy(ctx, entry->data);
-       entry->data = isl_name_alloc(ctx, name);
-       if (!entry->data)
-               ctx->name_hash.n--;
-       return entry->data;
-}
-
-struct isl_name *isl_name_copy(struct isl_ctx *ctx, struct isl_name *name)
-{
-       if (!name)
-               return NULL;
-
-       name->ref++;
-       return name;
-}
-
-static int isl_name_eq(const void *entry, const void *name)
-{
-       return entry == name;
-}
-
-uint32_t isl_hash_name(uint32_t hash, struct isl_name *name)
-{
-       if (name)
-               isl_hash_hash(hash, name->hash);
-
-       return hash;
-}
-
-void isl_name_free(struct isl_ctx *ctx, struct isl_name *name)
-{
-       uint32_t name_hash;
-       struct isl_hash_table_entry *entry;
-
-       if (!name)
-               return;
-
-       if (--name->ref > 0)
-               return;
-
-       name_hash = isl_hash_string(isl_hash_init(), name->name);
-       entry = isl_hash_table_find(ctx, &ctx->name_hash, name_hash,
-                                       isl_name_eq, name, 0);
-       isl_assert(ctx, entry, return);
-       isl_hash_table_remove(ctx, &ctx->name_hash, entry);
-
-       free((char *)name->name);
-       free(name);
-}
diff --git a/isl_name.h b/isl_name.h
deleted file mode 100644 (file)
index 3db7683..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2008-2009 Katholieke Universiteit Leuven
- *
- * Use of this software is governed by the GNU LGPLv2.1 license
- *
- * Written by Sven Verdoolaege, K.U.Leuven, Departement
- * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
- */
-
-#ifndef ISL_NAME_H
-#define ISL_NAME_H
-
-#include <isl/ctx.h>
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-struct isl_name {
-       int ref;
-
-       const char *name;
-       uint32_t hash;
-};
-
-struct isl_name *isl_name_alloc(struct isl_ctx *ctx, const char *name);
-struct isl_name *isl_name_get(struct isl_ctx *ctx, const char *name);
-struct isl_name *isl_name_copy(struct isl_ctx *ctx, struct isl_name *name);
-uint32_t isl_hash_name(uint32_t hash, struct isl_name *name);
-void isl_name_free(struct isl_ctx *ctx, struct isl_name *name);
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif
index 928982d..dc63454 100644 (file)
--- a/isl_obj.c
+++ b/isl_obj.c
@@ -10,6 +10,7 @@
 
 #include <isl/set.h>
 #include <isl/map.h>
+#include <isl/polynomial.h>
 #include <isl/obj.h>
 
 struct isl_int_obj {
index ec2d664..c2541cf 100644 (file)
@@ -18,7 +18,7 @@
 #include <isl/seq.h>
 #include <isl_polynomial_private.h>
 #include <isl_printer_private.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl_mat_private.h>
 #include <isl/union_map.h>
 #include <isl/constraint.h>
@@ -150,7 +150,7 @@ static __isl_give isl_printer *isl_set_print_polylib(__isl_keep isl_set *set,
        return isl_map_print_polylib((struct isl_map *)set, p, ext);
 }
 
-static int count_same_name(__isl_keep isl_dim *dim,
+static int count_same_name(__isl_keep isl_space *dim,
        enum isl_dim_type type, unsigned pos, const char *name)
 {
        enum isl_dim_type t;
@@ -158,9 +158,9 @@ static int count_same_name(__isl_keep isl_dim *dim,
        int count = 0;
 
        for (t = isl_dim_param; t <= type && t <= isl_dim_out; ++t) {
-               s = t == type ? pos : isl_dim_size(dim, t);
+               s = t == type ? pos : isl_space_dim(dim, t);
                for (p = 0; p < s; ++p) {
-                       const char *n = isl_dim_get_name(dim, t, p);
+                       const char *n = isl_space_get_dim_name(dim, t, p);
                        if (n && !strcmp(n, name))
                                count++;
                }
@@ -168,15 +168,15 @@ static int count_same_name(__isl_keep isl_dim *dim,
        return count;
 }
 
-static __isl_give isl_printer *print_name(__isl_keep isl_dim *dim,
+static __isl_give isl_printer *print_name(__isl_keep isl_space *dim,
        __isl_take isl_printer *p, enum isl_dim_type type, unsigned pos,
-       int set, int latex)
+       int latex)
 {
        const char *name;
        char buffer[20];
        int primes;
 
-       name = type == isl_dim_div ? NULL : isl_dim_get_name(dim, type, pos);
+       name = type == isl_dim_div ? NULL : isl_space_get_dim_name(dim, type, pos);
 
        if (!name) {
                const char *prefix;
@@ -184,7 +184,7 @@ static __isl_give isl_printer *print_name(__isl_keep isl_dim *dim,
                        prefix = s_param_prefix[latex];
                else if (type == isl_dim_div)
                        prefix = s_div_prefix[latex];
-               else if (set || type == isl_dim_in)
+               else if (isl_space_is_set(dim) || type == isl_dim_in)
                        prefix = s_input_prefix[latex];
                else
                        prefix = s_output_prefix[latex];
@@ -199,12 +199,12 @@ static __isl_give isl_printer *print_name(__isl_keep isl_dim *dim,
        return p;
 }
 
-static enum isl_dim_type pos2type(__isl_keep isl_dim *dim, unsigned *pos)
+static enum isl_dim_type pos2type(__isl_keep isl_space *dim, unsigned *pos)
 {
        enum isl_dim_type type;
-       unsigned n_in = isl_dim_size(dim, isl_dim_in);
-       unsigned n_out = isl_dim_size(dim, isl_dim_out);
-       unsigned nparam = isl_dim_size(dim, isl_dim_param);
+       unsigned n_in = isl_space_dim(dim, isl_dim_in);
+       unsigned n_out = isl_space_dim(dim, isl_dim_out);
+       unsigned nparam = isl_space_dim(dim, isl_dim_param);
 
        if (*pos < 1 + nparam) {
                type = isl_dim_param;
@@ -223,12 +223,12 @@ static enum isl_dim_type pos2type(__isl_keep isl_dim *dim, unsigned *pos)
        return type;
 }
 
-static __isl_give isl_printer *print_div(__isl_keep isl_dim *dim,
+static __isl_give isl_printer *print_div(__isl_keep isl_space *dim,
        __isl_keep isl_mat *div, int pos, __isl_take isl_printer *p);
 
-static __isl_give isl_printer *print_term(__isl_keep isl_dim *dim,
+static __isl_give isl_printer *print_term(__isl_keep isl_space *dim,
        __isl_keep isl_mat *div,
-       isl_int c, unsigned pos, __isl_take isl_printer *p, int set, int latex)
+       isl_int c, unsigned pos, __isl_take isl_printer *p, int latex)
 {
        enum isl_dim_type type;
        int print_div_def;
@@ -252,13 +252,13 @@ static __isl_give isl_printer *print_term(__isl_keep isl_dim *dim,
        if (print_div_def)
                p = print_div(dim, div, pos, p);
        else
-               p = print_name(dim, p, type, pos, set, latex);
+               p = print_name(dim, p, type, pos, latex);
        return p;
 }
 
-static __isl_give isl_printer *print_affine_of_len(__isl_keep isl_dim *dim,
+static __isl_give isl_printer *print_affine_of_len(__isl_keep isl_space *dim,
        __isl_keep isl_mat *div,
-       __isl_take isl_printer *p, isl_int *c, int len, int set)
+       __isl_take isl_printer *p, isl_int *c, int len)
 {
        int i;
        int first;
@@ -276,7 +276,7 @@ static __isl_give isl_printer *print_affine_of_len(__isl_keep isl_dim *dim,
                                p = isl_printer_print_str(p, " + ");
                }
                first = 0;
-               p = print_term(dim, div, c[i], i, p, set, 0);
+               p = print_term(dim, div, c[i], i, p, 0);
                if (flip)
                        isl_int_neg(c[i], c[i]);
        }
@@ -286,14 +286,14 @@ static __isl_give isl_printer *print_affine_of_len(__isl_keep isl_dim *dim,
 }
 
 static __isl_give isl_printer *print_affine(__isl_keep isl_basic_map *bmap,
-       __isl_keep isl_dim *dim, __isl_take isl_printer *p, isl_int *c, int set)
+       __isl_keep isl_space *dim, __isl_take isl_printer *p, isl_int *c)
 {
        unsigned len = 1 + isl_basic_map_total_dim(bmap);
-       return print_affine_of_len(dim, NULL, p, c, len, set);
+       return print_affine_of_len(dim, NULL, p, c, len);
 }
 
 static int defining_equality(__isl_keep isl_basic_map *eq,
-       __isl_keep isl_dim *dim, enum isl_dim_type type, int pos)
+       __isl_keep isl_space *dim, enum isl_dim_type type, int pos)
 {
        int i;
        unsigned total;
@@ -301,7 +301,7 @@ static int defining_equality(__isl_keep isl_basic_map *eq,
        if (!eq)
                return -1;
 
-       pos += isl_dim_offset(dim, type);
+       pos += isl_space_offset(dim, type);
        total = isl_basic_map_total_dim(eq);
 
        for (i = 0; i < eq->n_eq; ++i) {
@@ -318,53 +318,53 @@ static int defining_equality(__isl_keep isl_basic_map *eq,
 /* offset is the offset of local_dim inside global_type of global_dim.
  */
 static __isl_give isl_printer *print_nested_var_list(__isl_take isl_printer *p,
-       __isl_keep isl_dim *global_dim, enum isl_dim_type global_type,
-       __isl_keep isl_dim *local_dim, enum isl_dim_type local_type,
-       int set, int latex, __isl_keep isl_basic_map *eq, int offset)
+       __isl_keep isl_space *global_dim, enum isl_dim_type global_type,
+       __isl_keep isl_space *local_dim, enum isl_dim_type local_type,
+       int latex, __isl_keep isl_basic_map *eq, int offset)
 {
        int i, j;
 
        if (global_dim != local_dim && local_type == isl_dim_out)
                offset += local_dim->n_in;
 
-       for (i = 0; i < isl_dim_size(local_dim, local_type); ++i) {
+       for (i = 0; i < isl_space_dim(local_dim, local_type); ++i) {
                if (i)
                        p = isl_printer_print_str(p, ", ");
                j = defining_equality(eq, global_dim, global_type, offset + i);
                if (j >= 0) {
-                       int pos = 1 + isl_dim_offset(global_dim, global_type)
+                       int pos = 1 + isl_space_offset(global_dim, global_type)
                                    + offset + i;
                        p = print_affine_of_len(eq->dim, NULL,
-                                               p, eq->eq[j], pos, set);
+                                               p, eq->eq[j], pos);
                } else {
                        p = print_name(global_dim, p, global_type, offset + i,
-                                       set, latex);
+                                       latex);
                }
        }
        return p;
 }
 
-static __isl_give isl_printer *print_var_list(__isl_keep isl_dim *dim,
+static __isl_give isl_printer *print_var_list(__isl_keep isl_space *dim,
        __isl_take isl_printer *p, enum isl_dim_type type,
-       int set, int latex, __isl_keep isl_basic_map *eq)
+       int latex, __isl_keep isl_basic_map *eq)
 {
-       return print_nested_var_list(p, dim, type, dim, type, set, latex, eq, 0);
+       return print_nested_var_list(p, dim, type, dim, type, latex, eq, 0);
 }
 
 static __isl_give isl_printer *print_nested_map_dim(__isl_take isl_printer *p,
-       __isl_keep isl_dim *global_dim, enum isl_dim_type global_type,
-       __isl_keep isl_dim *local_dim,
-        int set, int latex, __isl_keep isl_basic_map *eq, int offset);
+       __isl_keep isl_space *global_dim, enum isl_dim_type global_type,
+       __isl_keep isl_space *local_dim,
+       int latex, __isl_keep isl_basic_map *eq, int offset);
 
 static __isl_give isl_printer *print_nested_tuple(__isl_take isl_printer *p,
-       __isl_keep isl_dim *global_dim, enum isl_dim_type global_type,
-       __isl_keep isl_dim *local_dim, enum isl_dim_type local_type,
-       int set, int latex, __isl_keep isl_basic_map *eq, int offset)
+       __isl_keep isl_space *global_dim, enum isl_dim_type global_type,
+       __isl_keep isl_space *local_dim, enum isl_dim_type local_type,
+       int latex, __isl_keep isl_basic_map *eq, int offset)
 {
        const char *name = NULL;
-       unsigned n = isl_dim_size(local_dim, local_type);
+       unsigned n = isl_space_dim(local_dim, local_type);
        if ((local_type == isl_dim_in || local_type == isl_dim_out)) {
-               name = isl_dim_get_tuple_name(local_dim, local_type);
+               name = isl_space_get_tuple_name(local_dim, local_type);
                if (name) {
                        if (latex)
                                p = isl_printer_print_str(p, "\\mathrm{");
@@ -381,91 +381,92 @@ static __isl_give isl_printer *print_nested_tuple(__isl_take isl_printer *p,
                        offset += local_dim->n_in;
                p = print_nested_map_dim(p, global_dim, global_type,
                                local_dim->nested[local_type - isl_dim_in],
-                               set, latex, eq, offset);
+                               latex, eq, offset);
        } else
                p = print_nested_var_list(p, global_dim, global_type,
-                                local_dim, local_type, set, latex, eq, offset);
+                                local_dim, local_type, latex, eq, offset);
        if (!latex || n != 1 || name)
                p = isl_printer_print_str(p, s_close_list[latex]);
        return p;
 }
 
-static __isl_give isl_printer *print_tuple(__isl_keep isl_dim *dim,
+static __isl_give isl_printer *print_tuple(__isl_keep isl_space *dim,
        __isl_take isl_printer *p, enum isl_dim_type type,
-       int set, int latex, __isl_keep isl_basic_map *eq)
+       int latex, __isl_keep isl_basic_map *eq)
 {
-       return print_nested_tuple(p, dim, type, dim, type, set, latex, eq, 0);
+       return print_nested_tuple(p, dim, type, dim, type, latex, eq, 0);
 }
 
 static __isl_give isl_printer *print_nested_map_dim(__isl_take isl_printer *p,
-       __isl_keep isl_dim *global_dim, enum isl_dim_type global_type,
-       __isl_keep isl_dim *local_dim,
-        int set, int latex, __isl_keep isl_basic_map *eq, int offset)
+       __isl_keep isl_space *global_dim, enum isl_dim_type global_type,
+       __isl_keep isl_space *local_dim,
+       int latex, __isl_keep isl_basic_map *eq, int offset)
 {
        p = print_nested_tuple(p, global_dim, global_type,
-                       local_dim, isl_dim_in, set, latex, eq, offset);
+                       local_dim, isl_dim_in, latex, eq, offset);
        p = isl_printer_print_str(p, s_to[latex]);
        p = print_nested_tuple(p, global_dim, global_type,
-                       local_dim, isl_dim_out, set, latex, eq, offset);
+                       local_dim, isl_dim_out, latex, eq, offset);
 
        return p;
 }
 
-static __isl_give isl_printer *print_dim(__isl_keep isl_dim *dim,
-       __isl_take isl_printer *p, int set, int latex, int rational,
+static __isl_give isl_printer *print_space(__isl_keep isl_space *dim,
+       __isl_take isl_printer *p, int latex, int rational,
        __isl_keep isl_basic_map *eq)
 {
        if (rational && !latex)
                p = isl_printer_print_str(p, "rat: ");
-       if (set)
-               p = print_tuple(dim, p, isl_dim_set, 1, latex, eq);
+       if (isl_space_is_params(dim))
+               ;
+       else if (isl_space_is_set(dim))
+               p = print_tuple(dim, p, isl_dim_set, latex, eq);
        else {
-               p = print_tuple(dim, p, isl_dim_in, 0, latex, eq);
+               p = print_tuple(dim, p, isl_dim_in, latex, eq);
                p = isl_printer_print_str(p, s_to[latex]);
-               p = print_tuple(dim, p, isl_dim_out, 0, latex, eq);
+               p = print_tuple(dim, p, isl_dim_out, latex, eq);
        }
 
        return p;
 }
 
-static __isl_give isl_printer *print_omega_parameters(__isl_keep isl_dim *dim,
+static __isl_give isl_printer *print_omega_parameters(__isl_keep isl_space *dim,
        __isl_take isl_printer *p)
 {
-       if (isl_dim_size(dim, isl_dim_param) == 0)
+       if (isl_space_dim(dim, isl_dim_param) == 0)
                return p;
 
        p = isl_printer_start_line(p);
        p = isl_printer_print_str(p, "symbolic ");
-       p = print_var_list(dim, p, isl_dim_param, 0, 0, NULL);
+       p = print_var_list(dim, p, isl_dim_param, 0, NULL);
        p = isl_printer_print_str(p, ";");
        p = isl_printer_end_line(p);
        return p;
 }
 
 static __isl_give isl_printer *print_constraint(struct isl_basic_map *bmap,
-       __isl_keep isl_dim *dim, __isl_take isl_printer *p,
-       isl_int *c, int last, const char *op, int first_constraint, int set,
-       int latex)
+       __isl_keep isl_space *dim, __isl_take isl_printer *p,
+       isl_int *c, int last, const char *op, int first_constraint, int latex)
 {
        if (!first_constraint)
                p = isl_printer_print_str(p, s_and[latex]);
 
        isl_int_abs(c[last], c[last]);
 
-       p = print_term(dim, NULL, c[last], last, p, set, latex);
+       p = print_term(dim, NULL, c[last], last, p, latex);
 
        p = isl_printer_print_str(p, " ");
        p = isl_printer_print_str(p, op);
        p = isl_printer_print_str(p, " ");
 
        isl_int_set_si(c[last], 0);
-       p = print_affine(bmap, dim, p, c, set);
+       p = print_affine(bmap, dim, p, c);
 
        return p;
 }
 
 static __isl_give isl_printer *print_constraints(__isl_keep isl_basic_map *bmap,
-       __isl_keep isl_dim *dim, __isl_take isl_printer *p, int set, int latex)
+       __isl_keep isl_space *dim, __isl_take isl_printer *p, int latex)
 {
        int i;
        struct isl_vec *c;
@@ -488,7 +489,7 @@ static __isl_give isl_printer *print_constraints(__isl_keep isl_basic_map *bmap,
                else
                        isl_seq_neg(c->el, bmap->eq[i], 1 + total);
                p = print_constraint(bmap, dim, p, c->el, l,
-                                   "=", i == bmap->n_eq - 1, set, latex);
+                                   "=", i == bmap->n_eq - 1, latex);
        }
        for (i = 0; i < bmap->n_ineq; ++i) {
                int l = isl_seq_last_non_zero(bmap->ineq[i], 1 + total);
@@ -503,7 +504,7 @@ static __isl_give isl_printer *print_constraints(__isl_keep isl_basic_map *bmap,
                        isl_seq_neg(c->el, bmap->ineq[i], 1 + total);
                op = s < 0 ? s_le[latex] : s_ge[latex];
                p = print_constraint(bmap, dim, p, c->el, l,
-                                       op, !bmap->n_eq && !i, set, latex);
+                                       op, !bmap->n_eq && !i, latex);
        }
 
        isl_vec_free(c);
@@ -516,7 +517,7 @@ error:
 }
 
 static __isl_give isl_printer *print_omega_constraints(
-       __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p, int set)
+       __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p)
 {
        if (bmap->n_eq + bmap->n_ineq == 0)
                return p;
@@ -528,11 +529,11 @@ static __isl_give isl_printer *print_omega_constraints(
                for (i = 0; i < bmap->n_div; ++i) {
                        if (i)
                                p = isl_printer_print_str(p, ", ");
-                       p = print_name(bmap->dim, p, isl_dim_div, i, 0, 0);
+                       p = print_name(bmap->dim, p, isl_dim_div, i, 0);
                }
                p = isl_printer_print_str(p, ": ");
        }
-       p = print_constraints(bmap, bmap->dim, p, set, 0);
+       p = print_constraints(bmap, bmap->dim, p, 0);
        if (bmap->n_div > 0)
                p = isl_printer_print_str(p, ")");
        return p;
@@ -542,11 +543,11 @@ static __isl_give isl_printer *basic_map_print_omega(
        __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p)
 {
        p = isl_printer_print_str(p, "{ [");
-       p = print_var_list(bmap->dim, p, isl_dim_in, 0, 0, NULL);
+       p = print_var_list(bmap->dim, p, isl_dim_in, 0, NULL);
        p = isl_printer_print_str(p, "] -> [");
-       p = print_var_list(bmap->dim, p, isl_dim_out, 0, 0, NULL);
+       p = print_var_list(bmap->dim, p, isl_dim_out, 0, NULL);
        p = isl_printer_print_str(p, "] ");
-       p = print_omega_constraints(bmap, p, 0);
+       p = print_omega_constraints(bmap, p);
        p = isl_printer_print_str(p, " }");
        return p;
 }
@@ -566,9 +567,9 @@ static __isl_give isl_printer *basic_set_print_omega(
        __isl_keep isl_basic_set *bset, __isl_take isl_printer *p)
 {
        p = isl_printer_print_str(p, "{ [");
-       p = print_var_list(bset->dim, p, isl_dim_set, 1, 0, NULL);
+       p = print_var_list(bset->dim, p, isl_dim_set, 0, NULL);
        p = isl_printer_print_str(p, "] ");
-       p = print_omega_constraints((isl_basic_map *)bset, p, 1);
+       p = print_omega_constraints((isl_basic_map *)bset, p);
        p = isl_printer_print_str(p, " }");
        return p;
 }
@@ -619,7 +620,7 @@ static __isl_give isl_printer *isl_set_print_omega(__isl_keep isl_set *set,
 }
 
 static __isl_give isl_printer *print_disjunct(__isl_keep isl_basic_map *bmap,
-       __isl_keep isl_dim *dim, __isl_take isl_printer *p, int set, int latex)
+       __isl_keep isl_space *dim, __isl_take isl_printer *p, int latex)
 {
        if (bmap->n_div > 0) {
                int i;
@@ -627,11 +628,11 @@ static __isl_give isl_printer *print_disjunct(__isl_keep isl_basic_map *bmap,
                for (i = 0; i < bmap->n_div; ++i) {
                        if (i)
                                p = isl_printer_print_str(p, ", ");
-                       p = print_name(dim, p, isl_dim_div, i, 0, latex);
+                       p = print_name(dim, p, isl_dim_div, i, latex);
                        if (latex || isl_int_is_zero(bmap->div[i][0]))
                                continue;
                        p = isl_printer_print_str(p, " = [(");
-                       p = print_affine(bmap, dim, p, bmap->div[i] + 1, set);
+                       p = print_affine(bmap, dim, p, bmap->div[i] + 1);
                        p = isl_printer_print_str(p, ")/");
                        p = isl_printer_print_isl_int(p, bmap->div[i][0]);
                        p = isl_printer_print_str(p, "]");
@@ -639,7 +640,7 @@ static __isl_give isl_printer *print_disjunct(__isl_keep isl_basic_map *bmap,
                p = isl_printer_print_str(p, ": ");
        }
 
-       p = print_constraints(bmap, dim, p, set, latex);
+       p = print_constraints(bmap, dim, p, latex);
 
        if (bmap->n_div > 0)
                p = isl_printer_print_str(p, s_close_exists[latex]);
@@ -648,23 +649,23 @@ static __isl_give isl_printer *print_disjunct(__isl_keep isl_basic_map *bmap,
 
 static __isl_give isl_printer *isl_basic_map_print_isl(
        __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p,
-       int set, int latex)
+       int latex)
 {
        int rational = ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL);
        if (isl_basic_map_dim(bmap, isl_dim_param) > 0) {
-               p = print_tuple(bmap->dim, p, isl_dim_param, 0, latex, NULL);
+               p = print_tuple(bmap->dim, p, isl_dim_param, latex, NULL);
                p = isl_printer_print_str(p, " -> ");
        }
        p = isl_printer_print_str(p, "{ ");
-       p = print_dim(bmap->dim, p, set, latex, rational, NULL);
+       p = print_space(bmap->dim, p, latex, rational, NULL);
        p = isl_printer_print_str(p, " : ");
-       p = print_disjunct(bmap, bmap->dim, p, set, latex);
+       p = print_disjunct(bmap, bmap->dim, p, latex);
        p = isl_printer_print_str(p, " }");
        return p;
 }
 
 static __isl_give isl_printer *print_disjuncts(__isl_keep isl_map *map,
-       __isl_take isl_printer *p, int set, int latex)
+       __isl_take isl_printer *p, int latex)
 {
        int i;
 
@@ -679,13 +680,27 @@ static __isl_give isl_printer *print_disjuncts(__isl_keep isl_map *map,
                        p = isl_printer_print_str(p, s_or[latex]);
                if (map->n > 1 && map->p[i]->n_eq + map->p[i]->n_ineq > 1)
                        p = isl_printer_print_str(p, "(");
-               p = print_disjunct(map->p[i], map->dim, p, set, latex);
+               p = print_disjunct(map->p[i], map->dim, p, latex);
                if (map->n > 1 && map->p[i]->n_eq + map->p[i]->n_ineq > 1)
                        p = isl_printer_print_str(p, ")");
        }
        return p;
 }
 
+/* Print the disjuncts of a map (or set).
+ * If the map turns out to be a universal parameter domain, then
+ * we need to print the colon.  Otherwise, the output looks identical
+ * to the empty set.
+ */
+static __isl_give isl_printer *print_disjuncts_map(__isl_keep isl_map *map,
+       __isl_take isl_printer *p, int latex)
+{
+       if (isl_map_plain_is_universe(map) && isl_space_is_params(map->dim))
+               return isl_printer_print_str(p, s_such_that[latex]);
+       else
+               return print_disjuncts(map, p, latex);
+}
+
 struct isl_aff_split {
        isl_basic_map *aff;
        isl_map *map;
@@ -757,7 +772,7 @@ static __isl_give isl_basic_map *drop_aff(__isl_take isl_basic_map *bmap,
        if (!bmap || !aff)
                goto error;
 
-       total = isl_dim_total(bmap->dim);
+       total = isl_space_dim(bmap->dim, isl_dim_all);
 
        for (i = bmap->n_eq - 1; i >= 0; --i) {
                if (isl_seq_first_non_zero(bmap->eq[i] + 1 + total,
@@ -825,13 +840,13 @@ error:
 }
 
 static __isl_give isl_printer *print_split_map(__isl_take isl_printer *p,
-       struct isl_aff_split *split, int n, int set)
+       struct isl_aff_split *split, int n)
 {
        int i;
        int rational;
 
        for (i = 0; i < n; ++i) {
-               isl_dim *dim;
+               isl_space *dim;
 
                if (!split[i].map)
                        break;
@@ -840,15 +855,15 @@ static __isl_give isl_printer *print_split_map(__isl_take isl_printer *p,
                    ISL_F_ISSET(split[i].map->p[0], ISL_BASIC_MAP_RATIONAL);
                if (i)
                        p = isl_printer_print_str(p, "; ");
-               p = print_dim(dim, p, set, 0, rational, split[i].aff);
-               p = print_disjuncts(split[i].map, p, set, 0);
+               p = print_space(dim, p, 0, rational, split[i].aff);
+               p = print_disjuncts_map(split[i].map, p, 0);
        }
 
        return p;
 }
 
 static __isl_give isl_printer *isl_map_print_isl_body(__isl_keep isl_map *map,
-       __isl_take isl_printer *p, int set)
+       __isl_take isl_printer *p)
 {
        struct isl_aff_split *split = NULL;
        int rational;
@@ -856,47 +871,47 @@ static __isl_give isl_printer *isl_map_print_isl_body(__isl_keep isl_map *map,
        if (map->n > 0)
                split = split_aff(map);
        if (split) {
-               p = print_split_map(p, split, map->n, set);
+               p = print_split_map(p, split, map->n);
        } else {
                rational = map->n > 0 &&
                    ISL_F_ISSET(map->p[0], ISL_BASIC_MAP_RATIONAL);
-               p = print_dim(map->dim, p, set, 0, rational, NULL);
-               p = print_disjuncts(map, p, set, 0);
+               p = print_space(map->dim, p, 0, rational, NULL);
+               p = print_disjuncts_map(map, p, 0);
        }
        free_split(split, map->n);
        return p;
 }
 
 static __isl_give isl_printer *isl_map_print_isl(__isl_keep isl_map *map,
-       __isl_take isl_printer *p, int set)
+       __isl_take isl_printer *p)
 {
        if (isl_map_dim(map, isl_dim_param) > 0) {
-               p = print_tuple(map->dim, p, isl_dim_param, set, 0, NULL);
+               p = print_tuple(map->dim, p, isl_dim_param, 0, NULL);
                p = isl_printer_print_str(p, s_to[0]);
        }
        p = isl_printer_print_str(p, s_open_set[0]);
-       p = isl_map_print_isl_body(map, p, set);
+       p = isl_map_print_isl_body(map, p);
        p = isl_printer_print_str(p, s_close_set[0]);
        return p;
 }
 
 static __isl_give isl_printer *print_latex_map(__isl_keep isl_map *map,
-       __isl_take isl_printer *p, __isl_keep isl_basic_map *aff, int set)
+       __isl_take isl_printer *p, __isl_keep isl_basic_map *aff)
 {
        if (isl_map_dim(map, isl_dim_param) > 0) {
-               p = print_tuple(map->dim, p, isl_dim_param, set, 1, NULL);
+               p = print_tuple(map->dim, p, isl_dim_param, 1, NULL);
                p = isl_printer_print_str(p, s_to[1]);
        }
        p = isl_printer_print_str(p, s_open_set[1]);
-       p = print_dim(map->dim, p, set, 1, 0, aff);
-       p = print_disjuncts(map, p, set, 1);
+       p = print_space(map->dim, p, 1, 0, aff);
+       p = print_disjuncts_map(map, p, 1);
        p = isl_printer_print_str(p, s_close_set[1]);
 
        return p;
 }
 
 static __isl_give isl_printer *isl_map_print_latex(__isl_keep isl_map *map,
-       __isl_take isl_printer *p, int set)
+       __isl_take isl_printer *p)
 {
        int i;
        struct isl_aff_split *split = NULL;
@@ -905,14 +920,14 @@ static __isl_give isl_printer *isl_map_print_latex(__isl_keep isl_map *map,
                split = split_aff(map);
 
        if (!split)
-               return print_latex_map(map, p, NULL, set);
+               return print_latex_map(map, p, NULL);
 
        for (i = 0; i < map->n; ++i) {
                if (!split[i].map)
                        break;
                if (i)
                        p = isl_printer_print_str(p, " \\cup ");
-               p = print_latex_map(split[i].map, p, split[i].aff, set);
+               p = print_latex_map(split[i].map, p, split[i].aff);
        }
 
        free_split(split, map->n);
@@ -925,7 +940,7 @@ __isl_give isl_printer *isl_printer_print_basic_map(__isl_take isl_printer *p,
        if (!p || !bmap)
                goto error;
        if (p->output_format == ISL_FORMAT_ISL)
-               return isl_basic_map_print_isl(bmap, p, 0, 0);
+               return isl_basic_map_print_isl(bmap, p, 0);
        else if (p->output_format == ISL_FORMAT_OMEGA)
                return isl_basic_map_print_omega(bmap, p);
        isl_assert(bmap->ctx, 0, goto error);
@@ -959,7 +974,7 @@ __isl_give isl_printer *isl_printer_print_basic_set(__isl_take isl_printer *p,
                goto error;
 
        if (p->output_format == ISL_FORMAT_ISL)
-               return isl_basic_map_print_isl(bset, p, 1, 0);
+               return isl_basic_map_print_isl(bset, p, 0);
        else if (p->output_format == ISL_FORMAT_POLYLIB)
                return isl_basic_set_print_polylib(bset, p, 0);
        else if (p->output_format == ISL_FORMAT_EXT_POLYLIB)
@@ -998,7 +1013,7 @@ __isl_give isl_printer *isl_printer_print_set(__isl_take isl_printer *p,
        if (!p || !set)
                goto error;
        if (p->output_format == ISL_FORMAT_ISL)
-               return isl_map_print_isl((isl_map *)set, p, 1);
+               return isl_map_print_isl((isl_map *)set, p);
        else if (p->output_format == ISL_FORMAT_POLYLIB)
                return isl_set_print_polylib(set, p, 0);
        else if (p->output_format == ISL_FORMAT_EXT_POLYLIB)
@@ -1006,7 +1021,7 @@ __isl_give isl_printer *isl_printer_print_set(__isl_take isl_printer *p,
        else if (p->output_format == ISL_FORMAT_OMEGA)
                return isl_set_print_omega(set, p);
        else if (p->output_format == ISL_FORMAT_LATEX)
-               return isl_map_print_latex((isl_map *)set, p, 1);
+               return isl_map_print_latex((isl_map *)set, p);
        isl_assert(set->ctx, 0, goto error);
 error:
        isl_printer_free(p);
@@ -1036,7 +1051,7 @@ __isl_give isl_printer *isl_printer_print_map(__isl_take isl_printer *p,
                goto error;
 
        if (p->output_format == ISL_FORMAT_ISL)
-               return isl_map_print_isl(map, p, 0);
+               return isl_map_print_isl(map, p);
        else if (p->output_format == ISL_FORMAT_POLYLIB)
                return isl_map_print_polylib(map, p, 0);
        else if (p->output_format == ISL_FORMAT_EXT_POLYLIB)
@@ -1044,7 +1059,7 @@ __isl_give isl_printer *isl_printer_print_map(__isl_take isl_printer *p,
        else if (p->output_format == ISL_FORMAT_OMEGA)
                return isl_map_print_omega(map, p);
        else if (p->output_format == ISL_FORMAT_LATEX)
-               return isl_map_print_latex(map, p, 0);
+               return isl_map_print_latex(map, p);
        isl_assert(map->ctx, 0, goto error);
 error:
        isl_printer_free(p);
@@ -1053,7 +1068,6 @@ error:
 
 struct isl_union_print_data {
        isl_printer *p;
-       int set;
        int first;
 };
 
@@ -1066,23 +1080,23 @@ static int print_map_body(__isl_take isl_map *map, void *user)
                data->p = isl_printer_print_str(data->p, "; ");
        data->first = 0;
 
-       data->p = isl_map_print_isl_body(map, data->p, data->set);
+       data->p = isl_map_print_isl_body(map, data->p);
        isl_map_free(map);
 
        return 0;
 }
 
 static __isl_give isl_printer *isl_union_map_print_isl(
-       __isl_keep isl_union_map *umap, __isl_take isl_printer *p, int set)
+       __isl_keep isl_union_map *umap, __isl_take isl_printer *p)
 {
-       struct isl_union_print_data data = { p, set, 1 };
-       isl_dim *dim;
-       dim = isl_union_map_get_dim(umap);
-       if (isl_dim_size(dim, isl_dim_param) > 0) {
-               p = print_tuple(dim, p, isl_dim_param, set, 0, NULL);
+       struct isl_union_print_data data = { p, 1 };
+       isl_space *dim;
+       dim = isl_union_map_get_space(umap);
+       if (isl_space_dim(dim, isl_dim_param) > 0) {
+               p = print_tuple(dim, p, isl_dim_param, 0, NULL);
                p = isl_printer_print_str(p, s_to[0]);
        }
-       isl_dim_free(dim);
+       isl_space_free(dim);
        p = isl_printer_print_str(p, s_open_set[0]);
        isl_union_map_foreach_map(umap, &print_map_body, &data);
        p = data.p;
@@ -1099,16 +1113,16 @@ static int print_latex_map_body(__isl_take isl_map *map, void *user)
                data->p = isl_printer_print_str(data->p, " \\cup ");
        data->first = 0;
 
-       data->p = isl_map_print_latex(map, data->p, data->set);
+       data->p = isl_map_print_latex(map, data->p);
        isl_map_free(map);
 
        return 0;
 }
 
 static __isl_give isl_printer *isl_union_map_print_latex(
-       __isl_keep isl_union_map *umap, __isl_take isl_printer *p, int set)
+       __isl_keep isl_union_map *umap, __isl_take isl_printer *p)
 {
-       struct isl_union_print_data data = { p, set, 1 };
+       struct isl_union_print_data data = { p, 1 };
        isl_union_map_foreach_map(umap, &print_latex_map_body, &data);
        p = data.p;
        return p;
@@ -1121,9 +1135,9 @@ __isl_give isl_printer *isl_printer_print_union_map(__isl_take isl_printer *p,
                goto error;
 
        if (p->output_format == ISL_FORMAT_ISL)
-               return isl_union_map_print_isl(umap, p, 0);
+               return isl_union_map_print_isl(umap, p);
        if (p->output_format == ISL_FORMAT_LATEX)
-               return isl_union_map_print_latex(umap, p, 0);
+               return isl_union_map_print_latex(umap, p);
 
        isl_die(p->ctx, isl_error_invalid,
                "invalid output format for isl_union_map", goto error);
@@ -1139,9 +1153,9 @@ __isl_give isl_printer *isl_printer_print_union_set(__isl_take isl_printer *p,
                goto error;
 
        if (p->output_format == ISL_FORMAT_ISL)
-               return isl_union_map_print_isl((isl_union_map *)uset, p, 1);
+               return isl_union_map_print_isl((isl_union_map *)uset, p);
        if (p->output_format == ISL_FORMAT_LATEX)
-               return isl_union_map_print_latex((isl_union_map *)uset, p, 1);
+               return isl_union_map_print_latex((isl_union_map *)uset, p);
 
        isl_die(p->ctx, isl_error_invalid,
                "invalid output format for isl_union_set", goto error);
@@ -1166,179 +1180,6 @@ void isl_map_print(__isl_keep isl_map *map, FILE *out, int indent,
        isl_printer_free(printer);
 }
 
-void isl_basic_map_dump(__isl_keep isl_basic_map *bmap)
-{
-       isl_printer *printer;
-
-       if (!bmap)
-               return;
-
-       printer = isl_printer_to_file(isl_basic_map_get_ctx(bmap), stderr);
-       printer = isl_printer_print_basic_map(printer, bmap);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
-
-void isl_basic_set_dump(__isl_keep isl_basic_set *bset)
-{
-       isl_printer *printer;
-
-       if (!bset)
-               return;
-
-       printer = isl_printer_to_file(isl_basic_set_get_ctx(bset), stderr);
-       printer = isl_printer_print_basic_set(printer, bset);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
-
-void isl_map_dump(__isl_keep isl_map *map)
-{
-       isl_printer *printer;
-
-       if (!map)
-               return;
-
-       printer = isl_printer_to_file(isl_map_get_ctx(map), stderr);
-       printer = isl_printer_print_map(printer, map);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
-
-void isl_set_dump(__isl_keep isl_set *set)
-{
-       isl_printer *printer;
-
-       if (!set)
-               return;
-
-       printer = isl_printer_to_file(isl_set_get_ctx(set), stderr);
-       printer = isl_printer_print_set(printer, set);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
-
-void isl_union_map_dump(__isl_keep isl_union_map *umap)
-{
-       isl_printer *printer;
-
-       if (!umap)
-               return;
-
-       printer = isl_printer_to_file(isl_union_map_get_ctx(umap), stderr);
-       printer = isl_printer_print_union_map(printer, umap);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
-
-void isl_union_set_dump(__isl_keep isl_union_set *uset)
-{
-       isl_printer *printer;
-
-       if (!uset)
-               return;
-
-       printer = isl_printer_to_file(isl_union_set_get_ctx(uset), stderr);
-       printer = isl_printer_print_union_set(printer, uset);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
-
-void isl_union_pw_qpolynomial_dump(__isl_keep isl_union_pw_qpolynomial *upwqp)
-{
-       isl_printer *printer;
-
-       if (!upwqp)
-               return;
-
-       printer = isl_printer_to_file(isl_union_pw_qpolynomial_get_ctx(upwqp),
-                                       stderr);
-       printer = isl_printer_print_union_pw_qpolynomial(printer, upwqp);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
-
-void isl_qpolynomial_dump(__isl_keep isl_qpolynomial *qp)
-{
-       isl_printer *printer;
-
-       if (!qp)
-               return;
-
-       printer = isl_printer_to_file(isl_qpolynomial_get_ctx(qp), stderr);
-       printer = isl_printer_print_qpolynomial(printer, qp);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
-
-void isl_qpolynomial_fold_dump(__isl_keep isl_qpolynomial_fold *fold)
-{
-       isl_printer *printer;
-
-       if (!fold)
-               return;
-
-       printer = isl_printer_to_file(isl_qpolynomial_fold_get_ctx(fold),
-                                       stderr);
-       printer = isl_printer_print_qpolynomial_fold(printer, fold);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
-
-void isl_pw_qpolynomial_dump(__isl_keep isl_pw_qpolynomial *pwqp)
-{
-       isl_printer *printer;
-
-       if (!pwqp)
-               return;
-
-       printer = isl_printer_to_file(isl_pw_qpolynomial_get_ctx(pwqp), stderr);
-       printer = isl_printer_print_pw_qpolynomial(printer, pwqp);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
-
-void isl_pw_qpolynomial_fold_dump(__isl_keep isl_pw_qpolynomial_fold *pwf)
-{
-       isl_printer *printer;
-
-       if (!pwf)
-               return;
-
-       printer = isl_printer_to_file(
-                       isl_pw_qpolynomial_fold_get_ctx(pwf), stderr);
-       printer = isl_printer_print_pw_qpolynomial_fold(printer, pwf);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
-
-void isl_union_pw_qpolynomial_fold_dump(
-       __isl_keep isl_union_pw_qpolynomial_fold *upwf)
-{
-       isl_printer *printer;
-
-       if (!upwf)
-               return;
-
-       printer = isl_printer_to_file(
-                       isl_union_pw_qpolynomial_fold_get_ctx(upwf), stderr);
-       printer = isl_printer_print_union_pw_qpolynomial_fold(printer, upwf);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
-
 static int upoly_rec_n_non_zero(__isl_keep struct isl_upoly_rec *rec)
 {
        int i;
@@ -1351,13 +1192,13 @@ static int upoly_rec_n_non_zero(__isl_keep struct isl_upoly_rec *rec)
        return n;
 }
 
-static __isl_give isl_printer *print_div(__isl_keep isl_dim *dim,
+static __isl_give isl_printer *print_div(__isl_keep isl_space *dim,
        __isl_keep isl_mat *div, int pos, __isl_take isl_printer *p)
 {
        int c = p->output_format == ISL_FORMAT_C;
        p = isl_printer_print_str(p, c ? "floord(" : "[(");
        p = print_affine_of_len(dim, div, p,
-                               div->row[pos] + 1, div->n_col - 1, 1);
+                               div->row[pos] + 1, div->n_col - 1);
        p = isl_printer_print_str(p, c ? ", " : ")/");
        p = isl_printer_print_isl_int(p, div->row[pos][0]);
        p = isl_printer_print_str(p, c ? ")" : "]");
@@ -1397,20 +1238,20 @@ error:
 }
 
 static __isl_give isl_printer *print_base(__isl_take isl_printer *p,
-       __isl_keep isl_dim *dim, __isl_keep isl_mat *div, int var)
+       __isl_keep isl_space *dim, __isl_keep isl_mat *div, int var)
 {
        unsigned total;
 
-       total = isl_dim_total(dim);
+       total = isl_space_dim(dim, isl_dim_all);
        if (var < total)
-               p = print_term(dim, NULL, dim->ctx->one, 1 + var, p, 1, 0);
+               p = print_term(dim, NULL, dim->ctx->one, 1 + var, p, 0);
        else
                p = print_div(dim, div, var - total, p);
        return p;
 }
 
 static __isl_give isl_printer *print_pow(__isl_take isl_printer *p,
-       __isl_keep isl_dim *dim, __isl_keep isl_mat *div, int var, int exp)
+       __isl_keep isl_space *dim, __isl_keep isl_mat *div, int var, int exp)
 {
        p = print_base(p, dim, div, var);
        if (exp == 1)
@@ -1429,7 +1270,7 @@ static __isl_give isl_printer *print_pow(__isl_take isl_printer *p,
 }
 
 static __isl_give isl_printer *upoly_print(__isl_keep struct isl_upoly *up,
-       __isl_keep isl_dim *dim, __isl_keep isl_mat *div,
+       __isl_keep isl_space *dim, __isl_keep isl_mat *div,
        __isl_take isl_printer *p, int outer)
 {
        int i, n, first, print_parens;
@@ -1445,7 +1286,8 @@ static __isl_give isl_printer *upoly_print(__isl_keep struct isl_upoly *up,
        if (!rec)
                goto error;
        n = upoly_rec_n_non_zero(rec);
-       print_parens = n > 1 || (outer && rec->up.var >= isl_dim_total(dim));
+       print_parens = n > 1 ||
+                   (outer && rec->up.var >= isl_space_dim(dim, isl_dim_all));
        if (print_parens)
                p = isl_printer_print_str(p, "(");
        for (i = 0, first = 1; i < rec->n; ++i) {
@@ -1501,14 +1343,13 @@ static __isl_give isl_printer *print_qpolynomial_isl(__isl_take isl_printer *p,
        if (!p || !qp)
                goto error;
 
-       if (isl_dim_size(qp->dim, isl_dim_param) > 0) {
-               p = print_tuple(qp->dim, p, isl_dim_param, 0, 0, NULL);
+       if (isl_space_dim(qp->dim, isl_dim_param) > 0) {
+               p = print_tuple(qp->dim, p, isl_dim_param, 0, NULL);
                p = isl_printer_print_str(p, " -> ");
        }
        p = isl_printer_print_str(p, "{ ");
-       if (isl_dim_size(qp->dim, isl_dim_set) > 0 ||
-           isl_dim_is_named_or_nested(qp->dim, isl_dim_set)) {
-               p = print_dim(qp->dim, p, 1, 0, 0, NULL);
+       if (!isl_space_is_params(qp->dim)) {
+               p = print_space(qp->dim, p, 0, 0, NULL);
                p = isl_printer_print_str(p, " -> ");
        }
        p = print_qpolynomial(p, qp);
@@ -1520,7 +1361,7 @@ error:
 }
 
 static __isl_give isl_printer *print_qpolynomial_c(__isl_take isl_printer *p,
-       __isl_keep isl_dim *dim, __isl_keep isl_qpolynomial *qp)
+       __isl_keep isl_space *dim, __isl_keep isl_qpolynomial *qp)
 {
        isl_int den;
 
@@ -1530,7 +1371,7 @@ static __isl_give isl_printer *print_qpolynomial_c(__isl_take isl_printer *p,
                isl_qpolynomial *f;
                p = isl_printer_print_str(p, "(");
                qp = isl_qpolynomial_copy(qp);
-               f = isl_qpolynomial_rat_cst(isl_dim_copy(qp->dim),
+               f = isl_qpolynomial_rat_cst_on_domain(isl_space_copy(qp->dim),
                                                den, qp->dim->ctx->one);
                qp = isl_qpolynomial_mul(qp, f);
        }
@@ -1621,13 +1462,12 @@ static __isl_give isl_printer *isl_pwqp_print_isl_body(
        for (i = 0; i < pwqp->n; ++i) {
                if (i)
                        p = isl_printer_print_str(p, "; ");
-               if (isl_dim_size(pwqp->dim, isl_dim_set) > 0 ||
-                   isl_dim_is_named_or_nested(pwqp->dim, isl_dim_set)) {
-                       p = print_dim(pwqp->p[i].set->dim, p, 1, 0, 0, NULL);
+               if (!isl_space_is_params(pwqp->p[i].set->dim)) {
+                       p = print_space(pwqp->p[i].set->dim, p, 0, 0, NULL);
                        p = isl_printer_print_str(p, " -> ");
                }
                p = print_qpolynomial(p, pwqp->p[i].qp);
-               p = print_disjuncts((isl_map *)pwqp->p[i].set, p, 1, 0);
+               p = print_disjuncts((isl_map *)pwqp->p[i].set, p, 0);
        }
 
        return p;
@@ -1639,15 +1479,14 @@ static __isl_give isl_printer *print_pw_qpolynomial_isl(
        if (!p || !pwqp)
                goto error;
 
-       if (isl_dim_size(pwqp->dim, isl_dim_param) > 0) {
-               p = print_tuple(pwqp->dim, p, isl_dim_param, 0, 0, NULL);
+       if (isl_space_dim(pwqp->dim, isl_dim_param) > 0) {
+               p = print_tuple(pwqp->dim, p, isl_dim_param, 0, NULL);
                p = isl_printer_print_str(p, " -> ");
        }
        p = isl_printer_print_str(p, "{ ");
        if (pwqp->n == 0) {
-               if (isl_dim_size(pwqp->dim, isl_dim_set) > 0 ||
-                   isl_dim_is_named_or_nested(pwqp->dim, isl_dim_set)) {
-                       p = print_dim(pwqp->dim, p, 1, 0, 0, NULL);
+               if (!isl_space_is_set(pwqp->dim)) {
+                       p = print_tuple(pwqp->dim, p, isl_dim_in, 0, NULL);
                        p = isl_printer_print_str(p, " -> ");
                }
                p = isl_printer_print_str(p, "0");
@@ -1683,13 +1522,12 @@ static __isl_give isl_printer *isl_pwf_print_isl_body(
        for (i = 0; i < pwf->n; ++i) {
                if (i)
                        p = isl_printer_print_str(p, "; ");
-               if (isl_dim_size(pwf->dim, isl_dim_set) > 0 ||
-                   isl_dim_is_named_or_nested(pwf->dim, isl_dim_set)) {
-                       p = print_dim(pwf->p[i].set->dim, p, 1, 0, 0, NULL);
+               if (!isl_space_is_params(pwf->p[i].set->dim)) {
+                       p = print_space(pwf->p[i].set->dim, p, 0, 0, NULL);
                        p = isl_printer_print_str(p, " -> ");
                }
                p = qpolynomial_fold_print(pwf->p[i].fold, p);
-               p = print_disjuncts((isl_map *)pwf->p[i].set, p, 1, 0);
+               p = print_disjuncts((isl_map *)pwf->p[i].set, p, 0);
        }
 
        return p;
@@ -1698,15 +1536,14 @@ static __isl_give isl_printer *isl_pwf_print_isl_body(
 static __isl_give isl_printer *print_pw_qpolynomial_fold_isl(
        __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf)
 {
-       if (isl_dim_size(pwf->dim, isl_dim_param) > 0) {
-               p = print_tuple(pwf->dim, p, isl_dim_param, 0, 0, NULL);
+       if (isl_space_dim(pwf->dim, isl_dim_param) > 0) {
+               p = print_tuple(pwf->dim, p, isl_dim_param, 0, NULL);
                p = isl_printer_print_str(p, " -> ");
        }
        p = isl_printer_print_str(p, "{ ");
        if (pwf->n == 0) {
-               if (isl_dim_size(pwf->dim, isl_dim_set) > 0 ||
-                   isl_dim_is_named_or_nested(pwf->dim, isl_dim_set)) {
-                       p = print_dim(pwf->dim, p, 1, 0, 0, NULL);
+               if (!isl_space_is_set(pwf->dim)) {
+                       p = print_tuple(pwf->dim, p, isl_dim_in, 0, NULL);
                        p = isl_printer_print_str(p, " -> ");
                }
                p = isl_printer_print_str(p, "0");
@@ -1717,10 +1554,10 @@ static __isl_give isl_printer *print_pw_qpolynomial_fold_isl(
 }
 
 static __isl_give isl_printer *print_affine_c(__isl_take isl_printer *p,
-       __isl_keep isl_dim *dim, __isl_keep isl_basic_set *bset, isl_int *c);
+       __isl_keep isl_space *dim, __isl_keep isl_basic_set *bset, isl_int *c);
 
 static __isl_give isl_printer *print_name_c(__isl_take isl_printer *p,
-       __isl_keep isl_dim *dim,
+       __isl_keep isl_space *dim,
        __isl_keep isl_basic_set *bset, enum isl_dim_type type, unsigned pos)
 {
        if (type == isl_dim_div) {
@@ -1732,7 +1569,7 @@ static __isl_give isl_printer *print_name_c(__isl_take isl_printer *p,
        } else {
                const char *name;
 
-               name = isl_dim_get_name(dim, type, pos);
+               name = isl_space_get_dim_name(dim, type, pos);
                if (!name)
                        name = "UNNAMED";
                p = isl_printer_print_str(p, name);
@@ -1741,7 +1578,7 @@ static __isl_give isl_printer *print_name_c(__isl_take isl_printer *p,
 }
 
 static __isl_give isl_printer *print_term_c(__isl_take isl_printer *p,
-       __isl_keep isl_dim *dim,
+       __isl_keep isl_space *dim,
        __isl_keep isl_basic_set *bset, isl_int c, unsigned pos)
 {
        enum isl_dim_type type;
@@ -1763,7 +1600,7 @@ static __isl_give isl_printer *print_term_c(__isl_take isl_printer *p,
 }
 
 static __isl_give isl_printer *print_partial_affine_c(__isl_take isl_printer *p,
-       __isl_keep isl_dim *dim,
+       __isl_keep isl_space *dim,
        __isl_keep isl_basic_set *bset, isl_int *c, unsigned len)
 {
        int i;
@@ -1792,14 +1629,14 @@ static __isl_give isl_printer *print_partial_affine_c(__isl_take isl_printer *p,
 }
 
 static __isl_give isl_printer *print_affine_c(__isl_take isl_printer *p,
-       __isl_keep isl_dim *dim, __isl_keep isl_basic_set *bset, isl_int *c)
+       __isl_keep isl_space *dim, __isl_keep isl_basic_set *bset, isl_int *c)
 {
        unsigned len = 1 + isl_basic_set_total_dim(bset);
        return print_partial_affine_c(p, dim, bset, c, len);
 }
 
 static __isl_give isl_printer *print_constraint_c(__isl_take isl_printer *p,
-       __isl_keep isl_dim *dim,
+       __isl_keep isl_space *dim,
        __isl_keep isl_basic_set *bset, isl_int *c, const char *op, int first)
 {
        if (!first)
@@ -1813,7 +1650,7 @@ static __isl_give isl_printer *print_constraint_c(__isl_take isl_printer *p,
 }
 
 static __isl_give isl_printer *print_basic_set_c(__isl_take isl_printer *p,
-       __isl_keep isl_dim *dim, __isl_keep isl_basic_set *bset)
+       __isl_keep isl_space *dim, __isl_keep isl_basic_set *bset)
 {
        int i, j;
        unsigned n_div = isl_basic_set_dim(bset, isl_dim_div);
@@ -1843,7 +1680,7 @@ static __isl_give isl_printer *print_basic_set_c(__isl_take isl_printer *p,
 }
 
 static __isl_give isl_printer *print_set_c(__isl_take isl_printer *p,
-       __isl_keep isl_dim *dim, __isl_keep isl_set *set)
+       __isl_keep isl_space *dim, __isl_keep isl_set *set)
 {
        int i;
 
@@ -1916,14 +1753,14 @@ static int print_pwqp_body(__isl_take isl_pw_qpolynomial *pwqp, void *user)
 static __isl_give isl_printer *print_union_pw_qpolynomial_isl(
        __isl_take isl_printer *p, __isl_keep isl_union_pw_qpolynomial *upwqp)
 {
-       struct isl_union_print_data data = { p, 1, 1 };
-       isl_dim *dim;
-       dim = isl_union_pw_qpolynomial_get_dim(upwqp);
-       if (isl_dim_size(dim, isl_dim_param) > 0) {
-               p = print_tuple(dim, p, isl_dim_param, 1, 0, NULL);
+       struct isl_union_print_data data = { p, 1 };
+       isl_space *dim;
+       dim = isl_union_pw_qpolynomial_get_space(upwqp);
+       if (isl_space_dim(dim, isl_dim_param) > 0) {
+               p = print_tuple(dim, p, isl_dim_param, 0, NULL);
                p = isl_printer_print_str(p, " -> ");
        }
-       isl_dim_free(dim);
+       isl_space_free(dim);
        p = isl_printer_print_str(p, "{ ");
        isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp, &print_pwqp_body,
                                                        &data);
@@ -1949,7 +1786,7 @@ error:
 }
 
 static __isl_give isl_printer *print_qpolynomial_fold_c(
-       __isl_take isl_printer *p, __isl_keep isl_dim *dim,
+       __isl_take isl_printer *p, __isl_keep isl_space *dim,
        __isl_keep isl_qpolynomial_fold *fold)
 {
        int i;
@@ -2056,14 +1893,14 @@ static __isl_give isl_printer *print_union_pw_qpolynomial_fold_isl(
        __isl_take isl_printer *p,
        __isl_keep isl_union_pw_qpolynomial_fold *upwf)
 {
-       struct isl_union_print_data data = { p, 1, 1 };
-       isl_dim *dim;
-       dim = isl_union_pw_qpolynomial_fold_get_dim(upwf);
-       if (isl_dim_size(dim, isl_dim_param) > 0) {
-               p = print_tuple(dim, p, isl_dim_param, 1, 0, NULL);
+       struct isl_union_print_data data = { p, 1 };
+       isl_space *dim;
+       dim = isl_union_pw_qpolynomial_fold_get_space(upwf);
+       if (isl_space_dim(dim, isl_dim_param) > 0) {
+               p = print_tuple(dim, p, isl_dim_param, 0, NULL);
                p = isl_printer_print_str(p, " -> ");
        }
-       isl_dim_free(dim);
+       isl_space_free(dim);
        p = isl_printer_print_str(p, "{ ");
        isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(upwf,
                                                        &print_pwf_body, &data);
@@ -2106,35 +1943,22 @@ error:
        return NULL;
 }
 
-void isl_constraint_dump(__isl_keep isl_constraint *c)
-{
-       isl_printer *printer;
-
-       if (!c)
-               return;
-
-       printer = isl_printer_to_file(isl_constraint_get_ctx(c), stderr);
-       printer = isl_printer_print_constraint(printer, c);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
-
-__isl_give isl_printer *isl_printer_print_dim(__isl_take isl_printer *p,
-       __isl_keep isl_dim *dim)
+__isl_give isl_printer *isl_printer_print_space(__isl_take isl_printer *p,
+       __isl_keep isl_space *dim)
 {
        if (!dim)
                goto error;
 
-       if (isl_dim_size(dim, isl_dim_param) > 0) {
-               p = print_tuple(dim, p, isl_dim_param, 0, 0, NULL);
+       if (isl_space_dim(dim, isl_dim_param) > 0) {
+               p = print_tuple(dim, p, isl_dim_param, 0, NULL);
                p = isl_printer_print_str(p, " -> ");
        }
 
        p = isl_printer_print_str(p, "{ ");
-       p = print_tuple(dim, p, isl_dim_in, 0, 0, NULL);
-       p = isl_printer_print_str(p, " -> ");
-       p = print_tuple(dim, p, isl_dim_out, 0, 0, NULL);
+       if (isl_space_is_params(dim))
+               p = isl_printer_print_str(p, s_such_that[0]);
+       else
+               p = print_space(dim, p, 0, 0, NULL);
        p = isl_printer_print_str(p, " }");
 
        return p;
@@ -2143,20 +1967,6 @@ error:
        return NULL;
 }
 
-void isl_dim_dump(__isl_keep isl_dim *dim)
-{
-       isl_printer *printer;
-
-       if (!dim)
-               return;
-
-       printer = isl_printer_to_file(isl_dim_get_ctx(dim), stderr);
-       printer = isl_printer_print_dim(printer, dim);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
-
 __isl_give isl_printer *isl_printer_print_local_space(__isl_take isl_printer *p,
        __isl_keep isl_local_space *ls)
 {
@@ -2168,13 +1978,11 @@ __isl_give isl_printer *isl_printer_print_local_space(__isl_take isl_printer *p,
 
        total = isl_local_space_dim(ls, isl_dim_all);
        if (isl_local_space_dim(ls, isl_dim_param) > 0) {
-               p = print_tuple(ls->dim, p, isl_dim_param, 0, 0, NULL);
+               p = print_tuple(ls->dim, p, isl_dim_param, 0, NULL);
                p = isl_printer_print_str(p, " -> ");
        }
        p = isl_printer_print_str(p, "{ ");
-       p = print_tuple(ls->dim, p, isl_dim_in, 0, 0, NULL);
-       p = isl_printer_print_str(p, " -> ");
-       p = print_tuple(ls->dim, p, isl_dim_out, 0, 0, NULL);
+       p = print_space(ls->dim, p, 0, 0, NULL);
        n_div = isl_local_space_dim(ls, isl_dim_div);
        if (n_div > 0) {
                int i;
@@ -2183,17 +1991,18 @@ __isl_give isl_printer *isl_printer_print_local_space(__isl_take isl_printer *p,
                for (i = 0; i < n_div; ++i) {
                        if (i)
                                p = isl_printer_print_str(p, ", ");
-                       p = print_name(ls->dim, p, isl_dim_div, i, 0, 0);
+                       p = print_name(ls->dim, p, isl_dim_div, i, 0);
                        if (isl_int_is_zero(ls->div->row[i][0]))
                                continue;
                        p = isl_printer_print_str(p, " = [(");
                        p = print_affine_of_len(ls->dim, ls->div, p,
-                                           ls->div->row[i] + 1, 1 + total, 0);
+                                           ls->div->row[i] + 1, 1 + total);
                        p = isl_printer_print_str(p, ")/");
                        p = isl_printer_print_isl_int(p, ls->div->row[i][0]);
                        p = isl_printer_print_str(p, "]");
                }
-       }
+       } else if (isl_space_is_params(ls->dim))
+               p = isl_printer_print_str(p, s_such_that[0]);
        p = isl_printer_print_str(p, " }");
        return p;
 error:
@@ -2201,31 +2010,22 @@ error:
        return NULL;
 }
 
-void isl_local_space_dump(__isl_keep isl_local_space *ls)
-{
-       isl_printer *printer;
-
-       if (!ls)
-               return;
-
-       printer = isl_printer_to_file(isl_local_space_get_ctx(ls), stderr);
-       printer = isl_printer_print_local_space(printer, ls);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
-
 static __isl_give isl_printer *print_aff(__isl_take isl_printer *p,
        __isl_keep isl_aff *aff)
 {
        unsigned total;
 
        total = isl_local_space_dim(aff->ls, isl_dim_all);
-       p = print_tuple(aff->ls->dim, p, isl_dim_set, 1, 0, NULL);
-       p = isl_printer_print_str(p, " -> [");
+       if (isl_space_is_params(aff->ls->dim))
+               ;
+       else {
+               p = print_tuple(aff->ls->dim, p, isl_dim_set, 0, NULL);
+               p = isl_printer_print_str(p, " -> ");
+       }
+       p = isl_printer_print_str(p, "[");
        p = isl_printer_print_str(p, "(");
        p = print_affine_of_len(aff->ls->dim, aff->ls->div, p,
-                               aff->v->el + 1, 1 + total, 1);
+                               aff->v->el + 1, 1 + total);
        if (isl_int_is_one(aff->v->el[0]))
                p = isl_printer_print_str(p, ")");
        else {
@@ -2244,7 +2044,7 @@ static __isl_give isl_printer *print_aff_isl(__isl_take isl_printer *p,
                goto error;
 
        if (isl_local_space_dim(aff->ls, isl_dim_param) > 0) {
-               p = print_tuple(aff->ls->dim, p, isl_dim_param, 0, 0, NULL);
+               p = print_tuple(aff->ls->dim, p, isl_dim_param, 0, NULL);
                p = isl_printer_print_str(p, " -> ");
        }
        p = isl_printer_print_str(p, "{ ");
@@ -2256,20 +2056,6 @@ error:
        return NULL;
 }
 
-void isl_aff_dump(__isl_keep isl_aff *aff)
-{
-       isl_printer *printer;
-
-       if (!aff)
-               return;
-
-       printer = isl_printer_to_file(isl_aff_get_ctx(aff), stderr);
-       printer = isl_printer_print_aff(printer, aff);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
-
 static __isl_give isl_printer *print_pw_aff_isl(__isl_take isl_printer *p,
        __isl_keep isl_pw_aff *pwaff)
 {
@@ -2278,8 +2064,8 @@ static __isl_give isl_printer *print_pw_aff_isl(__isl_take isl_printer *p,
        if (!pwaff)
                goto error;
 
-       if (isl_dim_size(pwaff->dim, isl_dim_param) > 0) {
-               p = print_tuple(pwaff->dim, p, isl_dim_param, 0, 0, NULL);
+       if (isl_space_dim(pwaff->dim, isl_dim_param) > 0) {
+               p = print_tuple(pwaff->dim, p, isl_dim_param, 0, NULL);
                p = isl_printer_print_str(p, " -> ");
        }
        p = isl_printer_print_str(p, "{ ");
@@ -2287,7 +2073,7 @@ static __isl_give isl_printer *print_pw_aff_isl(__isl_take isl_printer *p,
                if (i)
                        p = isl_printer_print_str(p, "; ");
                p = print_aff(p, pwaff->p[i].aff);
-               p = print_disjuncts((isl_map *)pwaff->p[i].set, p, 1, 0);
+               p = print_disjuncts((isl_map *)pwaff->p[i].set, p, 0);
        }
        p = isl_printer_print_str(p, " }");
        return p;
@@ -2311,7 +2097,7 @@ static __isl_give isl_printer *print_ls_name_c(__isl_take isl_printer *p,
        } else {
                const char *name;
 
-               name = isl_dim_get_name(ls->dim, type, pos);
+               name = isl_space_get_dim_name(ls->dim, type, pos);
                if (!name)
                        name = "UNNAMED";
                p = isl_printer_print_str(p, name);
@@ -2449,17 +2235,3 @@ error:
        isl_printer_free(p);
        return NULL;
 }
-
-void isl_pw_aff_dump(__isl_keep isl_pw_aff *pwaff)
-{
-       isl_printer *printer;
-
-       if (!pwaff)
-               return;
-
-       printer = isl_printer_to_file(isl_pw_aff_get_ctx(pwaff), stderr);
-       printer = isl_printer_print_pw_aff(printer, pwaff);
-       printer = isl_printer_end_line(printer);
-
-       isl_printer_free(printer);
-}
index e840162..53419be 100644 (file)
@@ -4,19 +4,19 @@
 #include <isl_sample.h>
 #include <isl_scan.h>
 #include <isl/seq.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 
 isl_ctx *isl_point_get_ctx(__isl_keep isl_point *pnt)
 {
-       return pnt ? isl_dim_get_ctx(pnt->dim) : NULL;
+       return pnt ? isl_space_get_ctx(pnt->dim) : NULL;
 }
 
-__isl_give isl_dim *isl_point_get_dim(__isl_keep isl_point *pnt)
+__isl_give isl_space *isl_point_get_space(__isl_keep isl_point *pnt)
 {
-       return pnt ? isl_dim_copy(pnt->dim) : NULL;
+       return pnt ? isl_space_copy(pnt->dim) : NULL;
 }
 
-__isl_give isl_point *isl_point_alloc(__isl_take isl_dim *dim,
+__isl_give isl_point *isl_point_alloc(__isl_take isl_space *dim,
        __isl_take isl_vec *vec)
 {
        struct isl_point *pnt;
@@ -24,11 +24,11 @@ __isl_give isl_point *isl_point_alloc(__isl_take isl_dim *dim,
        if (!dim || !vec)
                goto error;
 
-       if (vec->size > 1 + isl_dim_total(dim)) {
+       if (vec->size > 1 + isl_space_dim(dim, isl_dim_all)) {
                vec = isl_vec_cow(vec);
                if (!vec)
                        goto error;
-               vec->size = 1 + isl_dim_total(dim);
+               vec->size = 1 + isl_space_dim(dim, isl_dim_all);
        }
 
        pnt = isl_alloc_type(dim->ctx, struct isl_point);
@@ -41,25 +41,25 @@ __isl_give isl_point *isl_point_alloc(__isl_take isl_dim *dim,
 
        return pnt;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_vec_free(vec);
        return NULL;
 }
 
-__isl_give isl_point *isl_point_zero(__isl_take isl_dim *dim)
+__isl_give isl_point *isl_point_zero(__isl_take isl_space *dim)
 {
        isl_vec *vec;
 
        if (!dim)
                return NULL;
-       vec = isl_vec_alloc(dim->ctx, 1 + isl_dim_total(dim));
+       vec = isl_vec_alloc(dim->ctx, 1 + isl_space_dim(dim, isl_dim_all));
        if (!vec)
                goto error;
        isl_int_set_si(vec->el[0], 1);
        isl_seq_clr(vec->el + 1, vec->size - 1);
        return isl_point_alloc(dim, vec);
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -69,7 +69,7 @@ __isl_give isl_point *isl_point_dup(__isl_keep isl_point *pnt)
 
        if (!pnt)
                return NULL;
-       pnt2 = isl_point_alloc(isl_dim_copy(pnt->dim), isl_vec_copy(pnt->vec));
+       pnt2 = isl_point_alloc(isl_space_copy(pnt->dim), isl_vec_copy(pnt->vec));
        return pnt2;
 }
 
@@ -104,12 +104,12 @@ void isl_point_free(__isl_take isl_point *pnt)
        if (--pnt->ref > 0)
                return;
 
-       isl_dim_free(pnt->dim);
+       isl_space_free(pnt->dim);
        isl_vec_free(pnt->vec);
        free(pnt);
 }
 
-__isl_give isl_point *isl_point_void(__isl_take isl_dim *dim)
+__isl_give isl_point *isl_point_void(__isl_take isl_space *dim)
 {
        if (!dim)
                return NULL;
@@ -131,7 +131,7 @@ void isl_point_get_coordinate(__isl_keep isl_point *pnt,
        if (!pnt || isl_point_is_void(pnt))
                return;
        if (type == isl_dim_set)
-               pos += isl_dim_size(pnt->dim, isl_dim_param);
+               pos += isl_space_dim(pnt->dim, isl_dim_param);
        isl_int_set(*v, pnt->vec->el[1 + pos]);
 }
 
@@ -149,7 +149,7 @@ __isl_give isl_point *isl_point_set_coordinate(__isl_take isl_point *pnt,
                goto error;
 
        if (type == isl_dim_set)
-               pos += isl_dim_size(pnt->dim, isl_dim_param);
+               pos += isl_space_dim(pnt->dim, isl_dim_param);
 
        isl_int_set(pnt->vec->el[1 + pos], v);
 
@@ -173,7 +173,7 @@ __isl_give isl_point *isl_point_add_ui(__isl_take isl_point *pnt,
                goto error;
 
        if (type == isl_dim_set)
-               pos += isl_dim_size(pnt->dim, isl_dim_param);
+               pos += isl_space_dim(pnt->dim, isl_dim_param);
 
        isl_int_add_ui(pnt->vec->el[1 + pos], pnt->vec->el[1 + pos], val);
 
@@ -197,7 +197,7 @@ __isl_give isl_point *isl_point_sub_ui(__isl_take isl_point *pnt,
                goto error;
 
        if (type == isl_dim_set)
-               pos += isl_dim_size(pnt->dim, isl_dim_param);
+               pos += isl_space_dim(pnt->dim, isl_dim_param);
 
        isl_int_sub_ui(pnt->vec->el[1 + pos], pnt->vec->el[1 + pos], val);
 
@@ -211,7 +211,7 @@ struct isl_foreach_point {
        struct isl_scan_callback callback;
        int (*fn)(__isl_take isl_point *pnt, void *user);
        void *user;
-       isl_dim *dim;
+       isl_space *dim;
 };
 
 static int foreach_point(struct isl_scan_callback *cb, __isl_take isl_vec *sample)
@@ -219,7 +219,7 @@ static int foreach_point(struct isl_scan_callback *cb, __isl_take isl_vec *sampl
        struct isl_foreach_point *fp = (struct isl_foreach_point *)cb;
        isl_point *pnt;
 
-       pnt = isl_point_alloc(isl_dim_copy(fp->dim), sample);
+       pnt = isl_point_alloc(isl_space_copy(fp->dim), sample);
 
        return fp->fn(pnt, fp->user);
 }
@@ -233,7 +233,7 @@ int isl_set_foreach_point(__isl_keep isl_set *set,
        if (!set)
                return -1;
 
-       fp.dim = isl_set_get_dim(set);
+       fp.dim = isl_set_get_space(set);
        if (!fp.dim)
                return -1;
 
@@ -250,12 +250,12 @@ int isl_set_foreach_point(__isl_keep isl_set *set,
                        goto error;
 
        isl_set_free(set);
-       isl_dim_free(fp.dim);
+       isl_space_free(fp.dim);
 
        return 0;
 error:
        isl_set_free(set);
-       isl_dim_free(fp.dim);
+       isl_space_free(fp.dim);
        return -1;
 }
 
@@ -274,7 +274,7 @@ int isl_basic_map_contains_point(__isl_keep isl_basic_map *bmap,
 
        if (!bmap || !point)
                return -1;
-       isl_assert(bmap->ctx, isl_dim_equal(bmap->dim, point->dim), return -1);
+       isl_assert(bmap->ctx, isl_space_is_equal(bmap->dim, point->dim), return -1);
        if (bmap->n_div == 0)
                return isl_basic_map_contains(bmap, point->vec);
 
@@ -335,7 +335,7 @@ __isl_give isl_basic_set *isl_basic_set_from_point(__isl_take isl_point *pnt)
        isl_basic_set *bset;
        isl_basic_set *model;
 
-       model = isl_basic_set_empty(isl_dim_copy(pnt->dim));
+       model = isl_basic_set_empty(isl_space_copy(pnt->dim));
        bset = isl_basic_set_from_vec(isl_vec_copy(pnt->vec));
        bset = isl_basic_set_from_underlying_set(bset, model);
        isl_point_free(pnt);
@@ -365,10 +365,10 @@ __isl_give isl_basic_set *isl_basic_set_box_from_points(
                goto error;
 
        isl_assert(pnt1->dim->ctx,
-                       isl_dim_equal(pnt1->dim, pnt2->dim), goto error);
+                       isl_space_is_equal(pnt1->dim, pnt2->dim), goto error);
 
        if (isl_point_is_void(pnt1) && isl_point_is_void(pnt2)) {
-               isl_dim *dim = isl_dim_copy(pnt1->dim);
+               isl_space *dim = isl_space_copy(pnt1->dim);
                isl_point_free(pnt1);
                isl_point_free(pnt2);
                isl_int_clear(t);
@@ -385,8 +385,8 @@ __isl_give isl_basic_set *isl_basic_set_box_from_points(
                return isl_basic_set_from_point(pnt1);
        }
 
-       total = isl_dim_total(pnt1->dim);
-       bset = isl_basic_set_alloc_dim(isl_dim_copy(pnt1->dim), 0, 0, 2 * total);
+       total = isl_space_dim(pnt1->dim, isl_dim_all);
+       bset = isl_basic_set_alloc_space(isl_space_copy(pnt1->dim), 0, 0, 2 * total);
 
        for (i = 0; i < total; ++i) {
                isl_int_mul(t, pnt1->vec->el[1 + i], pnt2->vec->el[0]);
@@ -442,47 +442,52 @@ __isl_give isl_set *isl_set_box_from_points(__isl_take isl_point *pnt1,
        return isl_set_from_basic_set(bset);
 }
 
-void isl_point_print(__isl_keep isl_point *pnt, FILE *out)
+__isl_give isl_printer *isl_printer_print_point(
+       __isl_take isl_printer *p, __isl_keep isl_point *pnt)
 {
        int i;
        unsigned nparam;
        unsigned dim;
 
        if (!pnt)
-               return;
+               return p;
        if (isl_point_is_void(pnt)) {
-               fprintf(out, "void\n");
-               return;
+               p = isl_printer_print_str(p, "void");
+               return p;
        }
 
-       nparam = isl_dim_size(pnt->dim, isl_dim_param);
-       dim = isl_dim_size(pnt->dim, isl_dim_set);
+       nparam = isl_space_dim(pnt->dim, isl_dim_param);
+       dim = isl_space_dim(pnt->dim, isl_dim_set);
        if (nparam > 0) {
-               fprintf(out, "[");
+               p = isl_printer_print_str(p, "[");
                for (i = 0; i < nparam; ++i) {
                        const char *name;
                        if (i)
-                               fprintf(out, ", ");
-                       name = isl_dim_get_name(pnt->dim, isl_dim_param, i);
-                       if (name)
-                               fprintf(out, "%s = ", name);
-                       isl_int_print(out, pnt->vec->el[1 + i], 0);
+                               p = isl_printer_print_str(p, ", ");
+                       name = isl_space_get_dim_name(pnt->dim, isl_dim_param, i);
+                       if (name) {
+                               p = isl_printer_print_str(p, name);
+                               p = isl_printer_print_str(p, " = ");
+                       }
+                       p = isl_printer_print_isl_int(p, pnt->vec->el[1 + i]);
                        if (!isl_int_is_one(pnt->vec->el[0])) {
-                               fprintf(out, "/");
-                               isl_int_print(out, pnt->vec->el[0], 0);
+                               p = isl_printer_print_str(p, "/");
+                               p = isl_printer_print_isl_int(p, pnt->vec->el[0]);
                        }
                }
-               fprintf(out, "] -> ");
+               p = isl_printer_print_str(p, "]");
+               p = isl_printer_print_str(p, " -> ");
        }
-       fprintf(out, "[");
+       p = isl_printer_print_str(p, "[");
        for (i = 0; i < dim; ++i) {
                if (i)
-                       fprintf(out, ", ");
-               isl_int_print(out, pnt->vec->el[1 + nparam + i], 0);
+                       p = isl_printer_print_str(p, ", ");
+               p = isl_printer_print_isl_int(p, pnt->vec->el[1 + nparam + i]);
                if (!isl_int_is_one(pnt->vec->el[0])) {
-                       fprintf(out, "/");
-                       isl_int_print(out, pnt->vec->el[0], 0);
+                       p = isl_printer_print_str(p, "/");
+                       p = isl_printer_print_isl_int(p, pnt->vec->el[0]);
                }
        }
-       fprintf(out, "]\n");
+       p = isl_printer_print_str(p, "]");
+       return p;
 }
index 327f55f..305b81e 100644 (file)
@@ -1,12 +1,12 @@
-#include <isl/dim.h>
+#include <isl/space.h>
 #include <isl/point.h>
 #include <isl/vec.h>
 
 struct isl_point {
        int             ref;
-       struct isl_dim  *dim;
+       isl_space       *dim;
        struct isl_vec  *vec;
 };
 
-__isl_give isl_point *isl_point_alloc(__isl_take isl_dim *dim,
+__isl_give isl_point *isl_point_alloc(__isl_take isl_space *dim,
        __isl_take isl_vec *vec);
index 7e486a6..2341bab 100644 (file)
@@ -9,6 +9,7 @@
  */
 
 #include <stdlib.h>
+#define ISL_DIM_H
 #include <isl_ctx_private.h>
 #include <isl_map_private.h>
 #include <isl_factorization.h>
@@ -18,7 +19,7 @@
 #include <isl_constraint_private.h>
 #include <isl_polynomial_private.h>
 #include <isl_point_private.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl_div_private.h>
 #include <isl_mat_private.h>
 #include <isl_range.h>
@@ -26,7 +27,7 @@
 #include <isl_aff_private.h>
 #include <isl_config.h>
 
-static unsigned pos(__isl_keep isl_dim *dim, enum isl_dim_type type)
+static unsigned pos(__isl_keep isl_space *dim, enum isl_dim_type type)
 {
        switch (type) {
        case isl_dim_param:     return 0;
@@ -343,37 +344,70 @@ __isl_give struct isl_upoly_rec *isl_upoly_alloc_rec(struct isl_ctx *ctx,
        return rec;
 }
 
-__isl_give isl_qpolynomial *isl_qpolynomial_reset_dim(
-       __isl_take isl_qpolynomial *qp, __isl_take isl_dim *dim)
+__isl_give isl_qpolynomial *isl_qpolynomial_reset_domain_space(
+       __isl_take isl_qpolynomial *qp, __isl_take isl_space *dim)
 {
        qp = isl_qpolynomial_cow(qp);
        if (!qp || !dim)
                goto error;
 
-       isl_dim_free(qp->dim);
+       isl_space_free(qp->dim);
        qp->dim = dim;
 
        return qp;
 error:
        isl_qpolynomial_free(qp);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
+/* Reset the space of "qp".  This function is called from isl_pw_templ.c
+ * and doesn't know if the space of an element object is represented
+ * directly or through its domain.  It therefore passes along both.
+ */
+__isl_give isl_qpolynomial *isl_qpolynomial_reset_space_and_domain(
+       __isl_take isl_qpolynomial *qp, __isl_take isl_space *space,
+       __isl_take isl_space *domain)
+{
+       isl_space_free(space);
+       return isl_qpolynomial_reset_domain_space(qp, domain);
+}
+
 isl_ctx *isl_qpolynomial_get_ctx(__isl_keep isl_qpolynomial *qp)
 {
        return qp ? qp->dim->ctx : NULL;
 }
 
-__isl_give isl_dim *isl_qpolynomial_get_dim(__isl_keep isl_qpolynomial *qp)
+__isl_give isl_space *isl_qpolynomial_get_domain_space(
+       __isl_keep isl_qpolynomial *qp)
 {
-       return qp ? isl_dim_copy(qp->dim) : NULL;
+       return qp ? isl_space_copy(qp->dim) : NULL;
 }
 
+__isl_give isl_space *isl_qpolynomial_get_space(__isl_keep isl_qpolynomial *qp)
+{
+       isl_space *space;
+       if (!qp)
+               return NULL;
+       space = isl_space_copy(qp->dim);
+       space = isl_space_from_domain(space);
+       space = isl_space_add_dims(space, isl_dim_out, 1);
+       return space;
+}
+
+/* Externally, an isl_qpolynomial has a map space, but internally, the
+ * ls field corresponds to the domain of that space.
+ */
 unsigned isl_qpolynomial_dim(__isl_keep isl_qpolynomial *qp,
        enum isl_dim_type type)
 {
-       return qp ? isl_dim_size(qp->dim, type) : 0;
+       if (!qp)
+               return 0;
+       if (type == isl_dim_out)
+               return 1;
+       if (type == isl_dim_in)
+               type = isl_dim_set;
+       return isl_space_dim(qp->dim, type);
 }
 
 int isl_qpolynomial_is_zero(__isl_keep isl_qpolynomial *qp)
@@ -945,7 +979,7 @@ __isl_give struct isl_upoly *isl_upoly_pow(__isl_take struct isl_upoly *up,
        return res;
 }
 
-__isl_give isl_qpolynomial *isl_qpolynomial_alloc(__isl_take isl_dim *dim,
+__isl_give isl_qpolynomial *isl_qpolynomial_alloc(__isl_take isl_space *dim,
        unsigned n_div, __isl_take struct isl_upoly *up)
 {
        struct isl_qpolynomial *qp = NULL;
@@ -954,7 +988,11 @@ __isl_give isl_qpolynomial *isl_qpolynomial_alloc(__isl_take isl_dim *dim,
        if (!dim || !up)
                goto error;
 
-       total = isl_dim_total(dim);
+       if (!isl_space_is_set(dim))
+               isl_die(isl_space_get_ctx(dim), isl_error_invalid,
+                       "domain of polynomial should be a set", goto error);
+
+       total = isl_space_dim(dim, isl_dim_all);
 
        qp = isl_calloc_type(dim->ctx, struct isl_qpolynomial);
        if (!qp)
@@ -970,7 +1008,7 @@ __isl_give isl_qpolynomial *isl_qpolynomial_alloc(__isl_take isl_dim *dim,
 
        return qp;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_upoly_free(up);
        isl_qpolynomial_free(qp);
        return NULL;
@@ -992,7 +1030,7 @@ __isl_give isl_qpolynomial *isl_qpolynomial_dup(__isl_keep isl_qpolynomial *qp)
        if (!qp)
                return NULL;
 
-       dup = isl_qpolynomial_alloc(isl_dim_copy(qp->dim), qp->div->n_row,
+       dup = isl_qpolynomial_alloc(isl_space_copy(qp->dim), qp->div->n_row,
                                    isl_upoly_copy(qp->upoly));
        if (!dup)
                return NULL;
@@ -1018,19 +1056,20 @@ __isl_give isl_qpolynomial *isl_qpolynomial_cow(__isl_take isl_qpolynomial *qp)
        return isl_qpolynomial_dup(qp);
 }
 
-void isl_qpolynomial_free(__isl_take isl_qpolynomial *qp)
+void *isl_qpolynomial_free(__isl_take isl_qpolynomial *qp)
 {
        if (!qp)
-               return;
+               return NULL;
 
        if (--qp->ref > 0)
-               return;
+               return NULL;
 
-       isl_dim_free(qp->dim);
+       isl_space_free(qp->dim);
        isl_mat_free(qp->div);
        isl_upoly_free(qp->upoly);
 
        free(qp);
+       return NULL;
 }
 
 __isl_give struct isl_upoly *isl_upoly_var_pow(isl_ctx *ctx, int pos, int power)
@@ -1161,7 +1200,7 @@ static __isl_give isl_qpolynomial *sort_divs(__isl_take isl_qpolynomial *qp)
        if (qp->div->n_row <= 1)
                return qp;
 
-       div_pos = isl_dim_total(qp->dim);
+       div_pos = isl_space_dim(qp->dim, isl_dim_all);
 
        array = isl_alloc_array(qp->div->ctx, struct isl_div_sort_info,
                                qp->div->n_row);
@@ -1330,7 +1369,7 @@ __isl_give isl_qpolynomial *isl_qpolynomial_add(__isl_take isl_qpolynomial *qp1,
        if (qp1->div->n_row < qp2->div->n_row)
                return isl_qpolynomial_add(qp2, qp1);
 
-       isl_assert(qp1->dim->ctx, isl_dim_equal(qp1->dim, qp2->dim), goto error);
+       isl_assert(qp1->dim->ctx, isl_space_is_equal(qp1->dim, qp2->dim), goto error);
        if (!compatible_divs(qp1->div, qp2->div))
                return with_merged_divs(isl_qpolynomial_add, qp1, qp2);
 
@@ -1400,7 +1439,7 @@ __isl_give isl_qpolynomial *isl_qpolynomial_mul_isl_int(
 
        if (qp && isl_int_is_zero(v)) {
                isl_qpolynomial *zero;
-               zero = isl_qpolynomial_zero(isl_dim_copy(qp->dim));
+               zero = isl_qpolynomial_zero_on_domain(isl_space_copy(qp->dim));
                isl_qpolynomial_free(qp);
                return zero;
        }
@@ -1436,7 +1475,7 @@ __isl_give isl_qpolynomial *isl_qpolynomial_mul(__isl_take isl_qpolynomial *qp1,
        if (qp1->div->n_row < qp2->div->n_row)
                return isl_qpolynomial_mul(qp2, qp1);
 
-       isl_assert(qp1->dim->ctx, isl_dim_equal(qp1->dim, qp2->dim), goto error);
+       isl_assert(qp1->dim->ctx, isl_space_is_equal(qp1->dim, qp2->dim), goto error);
        if (!compatible_divs(qp1->div, qp2->div))
                return with_merged_divs(isl_qpolynomial_mul, qp1, qp2);
 
@@ -1471,42 +1510,69 @@ error:
        return NULL;
 }
 
-__isl_give isl_qpolynomial *isl_qpolynomial_zero(__isl_take isl_dim *dim)
+__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_pow(
+       __isl_take isl_pw_qpolynomial *pwqp, unsigned power)
+{
+       int i;
+
+       if (power == 1)
+               return pwqp;
+
+       pwqp = isl_pw_qpolynomial_cow(pwqp);
+       if (!pwqp)
+               return NULL;
+
+       for (i = 0; i < pwqp->n; ++i) {
+               pwqp->p[i].qp = isl_qpolynomial_pow(pwqp->p[i].qp, power);
+               if (!pwqp->p[i].qp)
+                       return isl_pw_qpolynomial_free(pwqp);
+       }
+
+       return pwqp;
+}
+
+__isl_give isl_qpolynomial *isl_qpolynomial_zero_on_domain(
+       __isl_take isl_space *dim)
 {
        if (!dim)
                return NULL;
        return isl_qpolynomial_alloc(dim, 0, isl_upoly_zero(dim->ctx));
 }
 
-__isl_give isl_qpolynomial *isl_qpolynomial_one(__isl_take isl_dim *dim)
+__isl_give isl_qpolynomial *isl_qpolynomial_one_on_domain(
+       __isl_take isl_space *dim)
 {
        if (!dim)
                return NULL;
        return isl_qpolynomial_alloc(dim, 0, isl_upoly_one(dim->ctx));
 }
 
-__isl_give isl_qpolynomial *isl_qpolynomial_infty(__isl_take isl_dim *dim)
+__isl_give isl_qpolynomial *isl_qpolynomial_infty_on_domain(
+       __isl_take isl_space *dim)
 {
        if (!dim)
                return NULL;
        return isl_qpolynomial_alloc(dim, 0, isl_upoly_infty(dim->ctx));
 }
 
-__isl_give isl_qpolynomial *isl_qpolynomial_neginfty(__isl_take isl_dim *dim)
+__isl_give isl_qpolynomial *isl_qpolynomial_neginfty_on_domain(
+       __isl_take isl_space *dim)
 {
        if (!dim)
                return NULL;
        return isl_qpolynomial_alloc(dim, 0, isl_upoly_neginfty(dim->ctx));
 }
 
-__isl_give isl_qpolynomial *isl_qpolynomial_nan(__isl_take isl_dim *dim)
+__isl_give isl_qpolynomial *isl_qpolynomial_nan_on_domain(
+       __isl_take isl_space *dim)
 {
        if (!dim)
                return NULL;
        return isl_qpolynomial_alloc(dim, 0, isl_upoly_nan(dim->ctx));
 }
 
-__isl_give isl_qpolynomial *isl_qpolynomial_cst(__isl_take isl_dim *dim,
+__isl_give isl_qpolynomial *isl_qpolynomial_cst_on_domain(
+       __isl_take isl_space *dim,
        isl_int v)
 {
        struct isl_qpolynomial *qp;
@@ -1649,7 +1715,7 @@ __isl_give isl_vec *isl_qpolynomial_extract_affine(
        if (!qp)
                return NULL;
 
-       d = isl_dim_total(qp->dim);
+       d = isl_space_dim(qp->dim, isl_dim_all);
        aff = isl_vec_alloc(qp->div->ctx, 2 + d + qp->div->n_row);
        if (!aff)
                return NULL;
@@ -1674,7 +1740,7 @@ int isl_qpolynomial_plain_is_equal(__isl_keep isl_qpolynomial *qp1,
        if (!qp1 || !qp2)
                return -1;
 
-       equal = isl_dim_equal(qp1->dim, qp2->dim);
+       equal = isl_space_is_equal(qp1->dim, qp2->dim);
        if (equal < 0 || !equal)
                return equal;
 
@@ -1715,8 +1781,8 @@ void isl_qpolynomial_get_den(__isl_keep isl_qpolynomial *qp, isl_int *d)
        upoly_update_den(qp->upoly, d);
 }
 
-__isl_give isl_qpolynomial *isl_qpolynomial_var_pow(__isl_take isl_dim *dim,
-       int pos, int power)
+__isl_give isl_qpolynomial *isl_qpolynomial_var_pow_on_domain(
+       __isl_take isl_space *dim, int pos, int power)
 {
        struct isl_ctx *ctx;
 
@@ -1728,21 +1794,21 @@ __isl_give isl_qpolynomial *isl_qpolynomial_var_pow(__isl_take isl_dim *dim,
        return isl_qpolynomial_alloc(dim, 0, isl_upoly_var_pow(ctx, pos, power));
 }
 
-__isl_give isl_qpolynomial *isl_qpolynomial_var(__isl_take isl_dim *dim,
+__isl_give isl_qpolynomial *isl_qpolynomial_var_on_domain(__isl_take isl_space *dim,
        enum isl_dim_type type, unsigned pos)
 {
        if (!dim)
                return NULL;
 
-       isl_assert(dim->ctx, isl_dim_size(dim, isl_dim_in) == 0, goto error);
-       isl_assert(dim->ctx, pos < isl_dim_size(dim, type), goto error);
+       isl_assert(dim->ctx, isl_space_dim(dim, isl_dim_in) == 0, goto error);
+       isl_assert(dim->ctx, pos < isl_space_dim(dim, type), goto error);
 
        if (type == isl_dim_set)
-               pos += isl_dim_size(dim, isl_dim_param);
+               pos += isl_space_dim(dim, isl_dim_param);
 
-       return isl_qpolynomial_var_pow(dim, pos, 1);
+       return isl_qpolynomial_var_pow_on_domain(dim, pos, 1);
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -1855,7 +1921,7 @@ static __isl_give isl_qpolynomial *substitute_div(
        if (!qp)
                goto error;
 
-       total = isl_dim_total(qp->dim);
+       total = isl_space_dim(qp->dim, isl_dim_all);
        qp->upoly = isl_upoly_subs(qp->upoly, total + div, 1, &s);
        if (!qp->upoly)
                goto error;
@@ -1896,7 +1962,7 @@ static __isl_give isl_qpolynomial *substitute_non_divs(
        if (!qp)
                return NULL;
 
-       total = isl_dim_total(qp->dim);
+       total = isl_space_dim(qp->dim, isl_dim_all);
        for (i = 0; qp && i < qp->div->n_row; ++i) {
                if (!isl_int_is_one(qp->div->row[i][0]))
                        continue;
@@ -2077,9 +2143,9 @@ __isl_give isl_qpolynomial *isl_qpolynomial_div_pow(__isl_take isl_div *div,
 
        d = div->line - div->bmap->div;
 
-       pos = isl_dim_total(div->bmap->dim) + d;
+       pos = isl_space_dim(div->bmap->dim, isl_dim_all) + d;
        rec = isl_upoly_alloc_rec(div->ctx, pos, 1 + power);
-       qp = isl_qpolynomial_alloc(isl_basic_map_get_dim(div->bmap),
+       qp = isl_qpolynomial_alloc(isl_basic_map_get_space(div->bmap),
                                   div->bmap->n_div, &rec->up);
        if (!qp)
                goto error;
@@ -2112,8 +2178,8 @@ __isl_give isl_qpolynomial *isl_qpolynomial_div(__isl_take isl_div *div)
        return isl_qpolynomial_div_pow(div, 1);
 }
 
-__isl_give isl_qpolynomial *isl_qpolynomial_rat_cst(__isl_take isl_dim *dim,
-       const isl_int n, const isl_int d)
+__isl_give isl_qpolynomial *isl_qpolynomial_rat_cst_on_domain(
+       __isl_take isl_space *dim, const isl_int n, const isl_int d)
 {
        struct isl_qpolynomial *qp;
        struct isl_upoly_cst *cst;
@@ -2157,7 +2223,7 @@ static int up_set_active(__isl_keep struct isl_upoly *up, int *active, int d)
 static int set_active(__isl_keep isl_qpolynomial *qp, int *active)
 {
        int i, j;
-       int d = isl_dim_total(qp->dim);
+       int d = isl_space_dim(qp->dim, isl_dim_all);
 
        if (!qp || !active)
                return -1;
@@ -2185,17 +2251,18 @@ int isl_qpolynomial_involves_dims(__isl_keep isl_qpolynomial *qp,
        if (n == 0)
                return 0;
 
-       isl_assert(qp->dim->ctx, first + n <= isl_dim_size(qp->dim, type),
-                       return -1);
+       isl_assert(qp->dim->ctx,
+                   first + n <= isl_qpolynomial_dim(qp, type), return -1);
        isl_assert(qp->dim->ctx, type == isl_dim_param ||
-                                type == isl_dim_set, return -1);
+                                type == isl_dim_in, return -1);
 
-       active = isl_calloc_array(qp->dim->ctx, int, isl_dim_total(qp->dim));
+       active = isl_calloc_array(qp->dim->ctx, int,
+                                       isl_space_dim(qp->dim, isl_dim_all));
        if (set_active(qp, active) < 0)
                goto error;
 
-       if (type == isl_dim_set)
-               first += isl_dim_size(qp->dim, isl_dim_param);
+       if (type == isl_dim_in)
+               first += isl_space_dim(qp->dim, isl_dim_param);
        for (i = 0; i < n; ++i)
                if (active[first + i]) {
                        involves = 1;
@@ -2231,7 +2298,7 @@ static __isl_give isl_qpolynomial *remove_redundant_divs(
        if (qp->div->n_row == 0)
                return qp;
 
-       d = isl_dim_total(qp->dim);
+       d = isl_space_dim(qp->dim, isl_dim_all);
        len = qp->div->n_col - 2;
        ctx = isl_qpolynomial_get_ctx(qp);
        active = isl_calloc_array(ctx, int, len);
@@ -2335,7 +2402,7 @@ __isl_give isl_qpolynomial *isl_qpolynomial_set_dim_name(
        qp = isl_qpolynomial_cow(qp);
        if (!qp)
                return NULL;
-       qp->dim = isl_dim_set_name(qp->dim, type, pos, s);
+       qp->dim = isl_space_set_dim_name(qp->dim, type, pos, s);
        if (!qp->dim)
                goto error;
        return qp;
@@ -2350,24 +2417,30 @@ __isl_give isl_qpolynomial *isl_qpolynomial_drop_dims(
 {
        if (!qp)
                return NULL;
-       if (n == 0 && !isl_dim_is_named_or_nested(qp->dim, type))
+       if (type == isl_dim_out)
+               isl_die(qp->dim->ctx, isl_error_invalid,
+                       "cannot drop output/set dimension",
+                       goto error);
+       if (type == isl_dim_in)
+               type = isl_dim_set;
+       if (n == 0 && !isl_space_is_named_or_nested(qp->dim, type))
                return qp;
 
        qp = isl_qpolynomial_cow(qp);
        if (!qp)
                return NULL;
 
-       isl_assert(qp->dim->ctx, first + n <= isl_dim_size(qp->dim, type),
+       isl_assert(qp->dim->ctx, first + n <= isl_space_dim(qp->dim, type),
                        goto error);
        isl_assert(qp->dim->ctx, type == isl_dim_param ||
                                 type == isl_dim_set, goto error);
 
-       qp->dim = isl_dim_drop(qp->dim, type, first, n);
+       qp->dim = isl_space_drop_dims(qp->dim, type, first, n);
        if (!qp->dim)
                goto error;
 
        if (type == isl_dim_set)
-               first += isl_dim_size(qp->dim, isl_dim_param);
+               first += isl_space_dim(qp->dim, isl_dim_param);
 
        qp->div = isl_mat_drop_cols(qp->div, 2 + first, n);
        if (!qp->div)
@@ -2383,6 +2456,31 @@ error:
        return NULL;
 }
 
+/* Project the domain of the quasi-polynomial onto its parameter space.
+ * The quasi-polynomial may not involve any of the domain dimensions.
+ */
+__isl_give isl_qpolynomial *isl_qpolynomial_project_domain_on_params(
+       __isl_take isl_qpolynomial *qp)
+{
+       isl_space *space;
+       unsigned n;
+       int involves;
+
+       n = isl_qpolynomial_dim(qp, isl_dim_in);
+       involves = isl_qpolynomial_involves_dims(qp, isl_dim_in, 0, n);
+       if (involves < 0)
+               return isl_qpolynomial_free(qp);
+       if (involves)
+               isl_die(isl_qpolynomial_get_ctx(qp), isl_error_invalid,
+                       "polynomial involves some of the domain dimensions",
+                       return isl_qpolynomial_free(qp));
+       qp = isl_qpolynomial_drop_dims(qp, isl_dim_in, 0, n);
+       space = isl_qpolynomial_get_domain_space(qp);
+       space = isl_space_params(space);
+       qp = isl_qpolynomial_reset_domain_space(qp, space);
+       return qp;
+}
+
 static __isl_give isl_qpolynomial *isl_qpolynomial_substitute_equalities_lifted(
        __isl_take isl_qpolynomial *qp, __isl_take isl_basic_set *eq)
 {
@@ -2406,7 +2504,7 @@ static __isl_give isl_qpolynomial *isl_qpolynomial_substitute_equalities_lifted(
        if (!qp->div)
                goto error;
 
-       total = 1 + isl_dim_total(eq->dim);
+       total = 1 + isl_space_dim(eq->dim, isl_dim_all);
        n_div = eq->n_div;
        isl_int_init(denom);
        for (i = 0; i < eq->n_eq; ++i) {
@@ -2507,7 +2605,7 @@ __isl_give isl_qpolynomial *isl_qpolynomial_gist(
                isl_basic_set *bset;
                context = isl_set_add_dims(context, isl_dim_set,
                                            qp->div->n_row);
-               bset = isl_basic_set_universe(isl_set_get_dim(context));
+               bset = isl_basic_set_universe(isl_set_get_space(context));
                bset = add_div_constraints(bset, isl_mat_copy(qp->div));
                context = isl_set_intersect(context,
                                            isl_set_from_basic_set(bset));
@@ -2521,6 +2619,23 @@ error:
        return NULL;
 }
 
+__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_from_qpolynomial(
+       __isl_take isl_qpolynomial *qp)
+{
+       isl_set *dom;
+
+       if (!qp)
+               return NULL;
+       if (isl_qpolynomial_is_zero(qp)) {
+               isl_space *dim = isl_qpolynomial_get_space(qp);
+               isl_qpolynomial_free(qp);
+               return isl_pw_qpolynomial_zero(dim);
+       }
+
+       dom = isl_set_universe(isl_qpolynomial_get_domain_space(qp));
+       return isl_pw_qpolynomial_alloc(dom, qp);
+}
+
 #undef PW
 #define PW isl_pw_qpolynomial
 #undef EL
@@ -2542,6 +2657,7 @@ error:
 #define PART isl_pw_qpolynomial
 #undef PARTS
 #define PARTS pw_qpolynomial
+#define ALIGN_DOMAIN
 
 #include <isl_union_templ.c>
 
@@ -2569,7 +2685,7 @@ __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_mul(
        if (!pwqp1 || !pwqp2)
                goto error;
 
-       isl_assert(pwqp1->dim->ctx, isl_dim_equal(pwqp1->dim, pwqp2->dim),
+       isl_assert(pwqp1->dim->ctx, isl_space_is_equal(pwqp1->dim, pwqp2->dim),
                        goto error);
 
        if (isl_pw_qpolynomial_is_zero(pwqp1)) {
@@ -2593,7 +2709,7 @@ __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_mul(
        }
 
        n = pwqp1->n * pwqp2->n;
-       res = isl_pw_qpolynomial_alloc_(isl_dim_copy(pwqp1->dim), n);
+       res = isl_pw_qpolynomial_alloc_size(isl_space_copy(pwqp1->dim), n);
 
        for (i = 0; i < pwqp1->n; ++i) {
                for (j = 0; j < pwqp2->n; ++j) {
@@ -2670,17 +2786,17 @@ __isl_give isl_qpolynomial *isl_qpolynomial_eval(
 {
        isl_vec *ext;
        struct isl_upoly *up;
-       isl_dim *dim;
+       isl_space *dim;
 
        if (!qp || !pnt)
                goto error;
-       isl_assert(pnt->dim->ctx, isl_dim_equal(pnt->dim, qp->dim), goto error);
+       isl_assert(pnt->dim->ctx, isl_space_is_equal(pnt->dim, qp->dim), goto error);
 
        if (qp->div->n_row == 0)
                ext = isl_vec_copy(pnt->vec);
        else {
                int i;
-               unsigned dim = isl_dim_total(qp->dim);
+               unsigned dim = isl_space_dim(qp->dim, isl_dim_all);
                ext = isl_vec_alloc(qp->dim->ctx, 1 + dim + qp->div->n_row);
                if (!ext)
                        goto error;
@@ -2698,7 +2814,7 @@ __isl_give isl_qpolynomial *isl_qpolynomial_eval(
        if (!up)
                goto error;
 
-       dim = isl_dim_copy(qp->dim);
+       dim = isl_space_copy(qp->dim);
        isl_qpolynomial_free(qp);
        isl_point_free(pnt);
 
@@ -2803,14 +2919,22 @@ __isl_give isl_qpolynomial *isl_qpolynomial_insert_dims(
        unsigned g_pos;
        int *exp;
 
-       if (n == 0 && !isl_dim_is_named_or_nested(qp->dim, type))
+       if (!qp)
+               return NULL;
+       if (type == isl_dim_out)
+               isl_die(qp->div->ctx, isl_error_invalid,
+                       "cannot insert output/set dimensions",
+                       goto error);
+       if (type == isl_dim_in)
+               type = isl_dim_set;
+       if (n == 0 && !isl_space_is_named_or_nested(qp->dim, type))
                return qp;
 
        qp = isl_qpolynomial_cow(qp);
        if (!qp)
                return NULL;
 
-       isl_assert(qp->div->ctx, first <= isl_dim_size(qp->dim, type),
+       isl_assert(qp->div->ctx, first <= isl_space_dim(qp->dim, type),
                    goto error);
 
        g_pos = pos(qp->dim, type) + first;
@@ -2833,7 +2957,7 @@ __isl_give isl_qpolynomial *isl_qpolynomial_insert_dims(
                        goto error;
        }
 
-       qp->dim = isl_dim_insert(qp->dim, type, first, n);
+       qp->dim = isl_space_insert_dims(qp->dim, type, first, n);
        if (!qp->dim)
                goto error;
 
@@ -2910,7 +3034,16 @@ __isl_give isl_qpolynomial *isl_qpolynomial_move_dims(
        if (!qp)
                return NULL;
 
-       isl_assert(qp->dim->ctx, src_pos + n <= isl_dim_size(qp->dim, src_type),
+       if (dst_type == isl_dim_out || src_type == isl_dim_out)
+               isl_die(qp->dim->ctx, isl_error_invalid,
+                       "cannot move output/set dimension",
+                       goto error);
+       if (dst_type == isl_dim_in)
+               dst_type = isl_dim_set;
+       if (src_type == isl_dim_in)
+               src_type = isl_dim_set;
+
+       isl_assert(qp->dim->ctx, src_pos + n <= isl_space_dim(qp->dim, src_type),
                goto error);
 
        g_dst_pos = pos(qp->dim, dst_type) + dst_pos;
@@ -2935,7 +3068,7 @@ __isl_give isl_qpolynomial *isl_qpolynomial_move_dims(
        if (!qp->upoly)
                goto error;
 
-       qp->dim = isl_dim_move(qp->dim, dst_type, dst_pos, src_type, src_pos, n);
+       qp->dim = isl_space_move_dims(qp->dim, dst_type, dst_pos, src_type, src_pos, n);
        if (!qp->dim)
                goto error;
 
@@ -2945,15 +3078,17 @@ error:
        return NULL;
 }
 
-__isl_give isl_qpolynomial *isl_qpolynomial_from_affine(__isl_take isl_dim *dim,
+__isl_give isl_qpolynomial *isl_qpolynomial_from_affine(__isl_take isl_space *dim,
        isl_int *f, isl_int denom)
 {
        struct isl_upoly *up;
 
+       dim = isl_space_domain(dim);
        if (!dim)
                return NULL;
 
-       up = isl_upoly_from_affine(dim->ctx, f, denom, 1 + isl_dim_total(dim));
+       up = isl_upoly_from_affine(dim->ctx, f, denom,
+                                       1 + isl_space_dim(dim, isl_dim_all));
 
        return isl_qpolynomial_alloc(dim, 0, up);
 }
@@ -2971,7 +3106,7 @@ __isl_give isl_qpolynomial *isl_qpolynomial_from_aff(__isl_take isl_aff *aff)
        up = isl_upoly_from_affine(ctx, aff->v->el + 1, aff->v->el[0],
                                    aff->v->size - 1);
 
-       qp = isl_qpolynomial_alloc(isl_aff_get_dim(aff),
+       qp = isl_qpolynomial_alloc(isl_aff_get_domain_space(aff),
                                    aff->ls->div->n_row, up);
        if (!qp)
                goto error;
@@ -2991,6 +3126,31 @@ error:
        return NULL;
 }
 
+__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_from_pw_aff(
+       __isl_take isl_pw_aff *pwaff)
+{
+       int i;
+       isl_pw_qpolynomial *pwqp;
+
+       if (!pwaff)
+               return NULL;
+
+       pwqp = isl_pw_qpolynomial_alloc_size(isl_pw_aff_get_space(pwaff),
+                                               pwaff->n);
+
+       for (i = 0; i < pwaff->n; ++i) {
+               isl_set *dom;
+               isl_qpolynomial *qp;
+
+               dom = isl_set_copy(pwaff->p[i].set);
+               qp = isl_qpolynomial_from_aff(isl_aff_copy(pwaff->p[i].aff));
+               pwqp = isl_pw_qpolynomial_add_piece(pwqp,  dom, qp);
+       }
+
+       isl_pw_aff_free(pwaff);
+       return pwqp;
+}
+
 __isl_give isl_qpolynomial *isl_qpolynomial_from_constraint(
        __isl_take isl_constraint *c, enum isl_dim_type type, unsigned pos)
 {
@@ -3018,15 +3178,23 @@ __isl_give isl_qpolynomial *isl_qpolynomial_substitute(
        qp = isl_qpolynomial_cow(qp);
        if (!qp)
                return NULL;
+
+       if (type == isl_dim_out)
+               isl_die(qp->dim->ctx, isl_error_invalid,
+                       "cannot substitute output/set dimension",
+                       goto error);
+       if (type == isl_dim_in)
+               type = isl_dim_set;
+
        for (i = 0; i < n; ++i)
                if (!subs[i])
                        goto error;
 
-       isl_assert(qp->dim->ctx, first + n <= isl_dim_size(qp->dim, type),
+       isl_assert(qp->dim->ctx, first + n <= isl_space_dim(qp->dim, type),
                        goto error);
 
        for (i = 0; i < n; ++i)
-               isl_assert(qp->dim->ctx, isl_dim_equal(qp->dim, subs[i]->dim),
+               isl_assert(qp->dim->ctx, isl_space_is_equal(qp->dim, subs[i]->dim),
                                goto error);
 
        isl_assert(qp->dim->ctx, qp->div->n_row == 0, goto error);
@@ -3064,7 +3232,7 @@ int isl_qpolynomial_as_polynomial_on_domain(__isl_keep isl_qpolynomial *qp,
        int (*fn)(__isl_take isl_basic_set *bset,
                  __isl_take isl_qpolynomial *poly, void *user), void *user)
 {
-       isl_dim *dim;
+       isl_space *dim;
        isl_mat *div;
        isl_qpolynomial *poly;
 
@@ -3075,8 +3243,8 @@ int isl_qpolynomial_as_polynomial_on_domain(__isl_keep isl_qpolynomial *qp,
                          user);
 
        div = isl_mat_copy(qp->div);
-       dim = isl_dim_copy(qp->dim);
-       dim = isl_dim_add(dim, isl_dim_set, qp->div->n_row);
+       dim = isl_space_copy(qp->dim);
+       dim = isl_space_add_dims(dim, isl_dim_set, qp->div->n_row);
        poly = isl_qpolynomial_alloc(dim, 0, isl_upoly_copy(qp->upoly));
        bset = isl_basic_set_copy(bset);
        bset = isl_basic_set_add(bset, isl_dim_set, qp->div->n_row);
@@ -3131,8 +3299,8 @@ int isl_qpolynomial_degree(__isl_keep isl_qpolynomial *poly)
        if (!poly)
                return -2;
 
-       ovar = isl_dim_offset(poly->dim, isl_dim_set);
-       nvar = isl_dim_size(poly->dim, isl_dim_set);
+       ovar = isl_space_offset(poly->dim, isl_dim_set);
+       nvar = isl_space_dim(poly->dim, isl_dim_set);
        return isl_upoly_degree(poly->upoly, ovar, ovar + nvar);
 }
 
@@ -3197,13 +3365,20 @@ __isl_give isl_qpolynomial *isl_qpolynomial_coeff(
        if (!qp)
                return NULL;
 
-       isl_assert(qp->div->ctx, t_pos < isl_dim_size(qp->dim, type),
+       if (type == isl_dim_out)
+               isl_die(qp->div->ctx, isl_error_invalid,
+                       "output/set dimension does not have a coefficient",
+                       return NULL);
+       if (type == isl_dim_in)
+               type = isl_dim_set;
+
+       isl_assert(qp->div->ctx, t_pos < isl_space_dim(qp->dim, type),
                        return NULL);
 
        g_pos = pos(qp->dim, type) + t_pos;
        up = isl_upoly_coeff(qp->upoly, g_pos, deg);
 
-       c = isl_qpolynomial_alloc(isl_dim_copy(qp->dim), qp->div->n_row, up);
+       c = isl_qpolynomial_alloc(isl_space_copy(qp->dim), qp->div->n_row, up);
        if (!c)
                return NULL;
        isl_mat_free(c->div);
@@ -3279,13 +3454,13 @@ __isl_give isl_qpolynomial *isl_qpolynomial_homogenize(
        if (deg < -1)
                goto error;
 
-       poly = isl_qpolynomial_insert_dims(poly, isl_dim_set, 0, 1);
+       poly = isl_qpolynomial_insert_dims(poly, isl_dim_in, 0, 1);
        poly = isl_qpolynomial_cow(poly);
        if (!poly)
                goto error;
 
-       ovar = isl_dim_offset(poly->dim, isl_dim_set);
-       nvar = isl_dim_size(poly->dim, isl_dim_set);
+       ovar = isl_space_offset(poly->dim, isl_dim_set);
+       nvar = isl_space_dim(poly->dim, isl_dim_set);
        poly->upoly = isl_upoly_homogenize(poly->upoly, 0, deg,
                                                ovar, ovar + nvar);
        if (!poly->upoly)
@@ -3297,7 +3472,7 @@ error:
        return NULL;
 }
 
-__isl_give isl_term *isl_term_alloc(__isl_take isl_dim *dim,
+__isl_give isl_term *isl_term_alloc(__isl_take isl_space *dim,
        __isl_take isl_mat *div)
 {
        isl_term *term;
@@ -3306,7 +3481,7 @@ __isl_give isl_term *isl_term_alloc(__isl_take isl_dim *dim,
        if (!dim || !div)
                goto error;
 
-       n = isl_dim_total(dim) + div->n_row;
+       n = isl_space_dim(dim, isl_dim_all) + div->n_row;
 
        term = isl_calloc(dim->ctx, struct isl_term,
                        sizeof(struct isl_term) + (n - 1) * sizeof(int));
@@ -3321,7 +3496,7 @@ __isl_give isl_term *isl_term_alloc(__isl_take isl_dim *dim,
        
        return term;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_mat_free(div);
        return NULL;
 }
@@ -3344,9 +3519,9 @@ __isl_give isl_term *isl_term_dup(__isl_keep isl_term *term)
        if (term)
                return NULL;
 
-       total = isl_dim_total(term->dim) + term->div->n_row;
+       total = isl_space_dim(term->dim, isl_dim_all) + term->div->n_row;
 
-       dup = isl_term_alloc(isl_dim_copy(term->dim), isl_mat_copy(term->div));
+       dup = isl_term_alloc(isl_space_copy(term->dim), isl_mat_copy(term->div));
        if (!dup)
                return NULL;
 
@@ -3378,7 +3553,7 @@ void isl_term_free(__isl_take isl_term *term)
        if (--term->ref > 0)
                return;
 
-       isl_dim_free(term->dim);
+       isl_space_free(term->dim);
        isl_mat_free(term->div);
        isl_int_clear(term->n);
        isl_int_clear(term->d);
@@ -3393,9 +3568,10 @@ unsigned isl_term_dim(__isl_keep isl_term *term, enum isl_dim_type type)
        switch (type) {
        case isl_dim_param:
        case isl_dim_in:
-       case isl_dim_out:       return isl_dim_size(term->dim, type);
+       case isl_dim_out:       return isl_space_dim(term->dim, type);
        case isl_dim_div:       return term->div->n_row;
-       case isl_dim_all:       return isl_dim_total(term->dim) + term->div->n_row;
+       case isl_dim_all:       return isl_space_dim(term->dim, isl_dim_all) +
+                                                               term->div->n_row;
        default:                return 0;
        }
 }
@@ -3428,9 +3604,9 @@ int isl_term_get_exp(__isl_keep isl_term *term,
        isl_assert(term->dim->ctx, pos < isl_term_dim(term, type), return -1);
 
        if (type >= isl_dim_set)
-               pos += isl_dim_size(term->dim, isl_dim_param);
+               pos += isl_space_dim(term->dim, isl_dim_param);
        if (type >= isl_dim_div)
-               pos += isl_dim_size(term->dim, isl_dim_set);
+               pos += isl_space_dim(term->dim, isl_dim_set);
 
        return term->pow[pos];
 }
@@ -3454,7 +3630,7 @@ __isl_give isl_div *isl_term_get_div(__isl_keep isl_term *term, unsigned pos)
                                        term->div->n_row) == -1,
                return NULL);
 
-       bmap = isl_basic_map_alloc_dim(isl_dim_copy(term->dim), 1, 0, 0);
+       bmap = isl_basic_map_alloc_space(isl_space_copy(term->dim), 1, 0, 0);
        if ((k = isl_basic_map_alloc_div(bmap)) < 0)
                goto error;
 
@@ -3527,7 +3703,7 @@ int isl_qpolynomial_foreach_term(__isl_keep isl_qpolynomial *qp,
        if (!qp)
                return -1;
 
-       term = isl_term_alloc(isl_dim_copy(qp->dim), isl_mat_copy(qp->div));
+       term = isl_term_alloc(isl_space_copy(qp->dim), isl_mat_copy(qp->div));
        if (!term)
                return -1;
 
@@ -3547,7 +3723,7 @@ __isl_give isl_qpolynomial *isl_qpolynomial_from_term(__isl_take isl_term *term)
        if (!term)
                return NULL;
 
-       n = isl_dim_total(term->dim) + term->div->n_row;
+       n = isl_space_dim(term->dim, isl_dim_all) + term->div->n_row;
 
        up = isl_upoly_rat_cst(term->dim->ctx, term->n, term->d);
        for (i = 0; i < n; ++i) {
@@ -3557,7 +3733,7 @@ __isl_give isl_qpolynomial *isl_qpolynomial_from_term(__isl_take isl_term *term)
                        isl_upoly_var_pow(term->dim->ctx, i, term->pow[i]));
        }
 
-       qp = isl_qpolynomial_alloc(isl_dim_copy(term->dim), term->div->n_row, up);
+       qp = isl_qpolynomial_alloc(isl_space_copy(term->dim), term->div->n_row, up);
        if (!qp)
                goto error;
        isl_mat_free(qp->div);
@@ -3574,7 +3750,7 @@ error:
 }
 
 __isl_give isl_qpolynomial *isl_qpolynomial_lift(__isl_take isl_qpolynomial *qp,
-       __isl_take isl_dim *dim)
+       __isl_take isl_space *dim)
 {
        int i;
        int extra;
@@ -3583,8 +3759,8 @@ __isl_give isl_qpolynomial *isl_qpolynomial_lift(__isl_take isl_qpolynomial *qp,
        if (!qp || !dim)
                goto error;
 
-       if (isl_dim_equal(qp->dim, dim)) {
-               isl_dim_free(dim);
+       if (isl_space_is_equal(qp->dim, dim)) {
+               isl_space_free(dim);
                return qp;
        }
 
@@ -3592,9 +3768,9 @@ __isl_give isl_qpolynomial *isl_qpolynomial_lift(__isl_take isl_qpolynomial *qp,
        if (!qp)
                goto error;
 
-       extra = isl_dim_size(dim, isl_dim_set) -
-                       isl_dim_size(qp->dim, isl_dim_set);
-       total = isl_dim_total(qp->dim);
+       extra = isl_space_dim(dim, isl_dim_set) -
+                       isl_space_dim(qp->dim, isl_dim_set);
+       total = isl_space_dim(qp->dim, isl_dim_all);
        if (qp->div->n_row) {
                int *exp;
 
@@ -3614,12 +3790,12 @@ __isl_give isl_qpolynomial *isl_qpolynomial_lift(__isl_take isl_qpolynomial *qp,
        for (i = 0; i < qp->div->n_row; ++i)
                isl_seq_clr(qp->div->row[i] + 2 + total, extra);
 
-       isl_dim_free(qp->dim);
+       isl_space_free(qp->dim);
        qp->dim = dim;
 
        return qp;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_qpolynomial_free(qp);
        return NULL;
 }
@@ -3639,7 +3815,7 @@ static __isl_give isl_set *fix_inactive(__isl_take isl_set *set,
        if (!set || !qp)
                goto error;
 
-       d = isl_dim_total(set->dim);
+       d = isl_space_dim(set->dim, isl_dim_all);
        active = isl_calloc_array(set->ctx, int, d);
        if (set_active(qp, active) < 0)
                goto error;
@@ -3653,8 +3829,8 @@ static __isl_give isl_set *fix_inactive(__isl_take isl_set *set,
                return set;
        }
 
-       nparam = isl_dim_size(set->dim, isl_dim_param);
-       nvar = isl_dim_size(set->dim, isl_dim_set);
+       nparam = isl_space_dim(set->dim, isl_dim_param);
+       nvar = isl_space_dim(set->dim, isl_dim_set);
        for (i = 0; i < nparam; ++i) {
                if (active[i])
                        continue;
@@ -3721,8 +3897,10 @@ __isl_give isl_qpolynomial *isl_qpolynomial_opt_on_domain(
        if (isl_set_foreach_point(set, opt_fn, &data) < 0)
                goto error;
 
-       if (data.first)
-               data.opt = isl_qpolynomial_zero(isl_qpolynomial_get_dim(qp));
+       if (data.first) {
+               isl_space *space = isl_qpolynomial_get_domain_space(qp);
+               data.opt = isl_qpolynomial_zero_on_domain(space);
+       }
 
        isl_set_free(set);
        isl_qpolynomial_free(qp);
@@ -3734,8 +3912,8 @@ error:
        return NULL;
 }
 
-__isl_give isl_qpolynomial *isl_qpolynomial_morph(__isl_take isl_qpolynomial *qp,
-       __isl_take isl_morph *morph)
+__isl_give isl_qpolynomial *isl_qpolynomial_morph_domain(
+       __isl_take isl_qpolynomial *qp, __isl_take isl_morph *morph)
 {
        int i;
        int n_sub;
@@ -3748,7 +3926,7 @@ __isl_give isl_qpolynomial *isl_qpolynomial_morph(__isl_take isl_qpolynomial *qp
                goto error;
 
        ctx = qp->dim->ctx;
-       isl_assert(ctx, isl_dim_equal(qp->dim, morph->dom->dim), goto error);
+       isl_assert(ctx, isl_space_is_equal(qp->dim, morph->dom->dim), goto error);
 
        n_sub = morph->inv->n_row - 1;
        if (morph->inv->n_row != morph->inv->n_col)
@@ -3774,8 +3952,8 @@ __isl_give isl_qpolynomial *isl_qpolynomial_morph(__isl_take isl_qpolynomial *qp
        mat = isl_mat_diagonal(isl_mat_identity(ctx, 1), isl_mat_copy(morph->inv));
        mat = isl_mat_diagonal(mat, isl_mat_identity(ctx, qp->div->n_row));
        qp->div = isl_mat_product(qp->div, mat);
-       isl_dim_free(qp->dim);
-       qp->dim = isl_dim_copy(morph->ran->dim);
+       isl_space_free(qp->dim);
+       qp->dim = isl_space_copy(morph->ran->dim);
 
        if (!qp->upoly || !qp->div || !qp->dim)
                goto error;
@@ -3831,7 +4009,7 @@ static int mul_entry(void **entry, void *user)
        isl_pw_qpolynomial *pwpq = *entry;
        int empty;
 
-       hash = isl_dim_get_hash(pwpq->dim);
+       hash = isl_space_get_hash(pwpq->dim);
        entry2 = isl_hash_table_find(data->u2->dim->ctx, &data->u2->table,
                                     hash, &has_dim, pwpq->dim, 0);
        if (!entry2)
@@ -3876,7 +4054,7 @@ static __isl_give isl_mat *reorder_divs(__isl_take isl_mat *div,
        if (!div || !r)
                goto error;
 
-       extra = isl_dim_total(r->dim) + div->n_row - r->len;
+       extra = isl_space_dim(r->dim, isl_dim_all) + div->n_row - r->len;
        mat = isl_mat_alloc(div->ctx, div->n_row, div->n_col + extra);
        if (!mat)
                goto error;
@@ -3900,7 +4078,7 @@ error:
 
 /* Reorder the dimension of "qp" according to the given reordering.
  */
-__isl_give isl_qpolynomial *isl_qpolynomial_realign(
+__isl_give isl_qpolynomial *isl_qpolynomial_realign_domain(
        __isl_take isl_qpolynomial *qp, __isl_take isl_reordering *r)
 {
        qp = isl_qpolynomial_cow(qp);
@@ -3919,7 +4097,7 @@ __isl_give isl_qpolynomial *isl_qpolynomial_realign(
        if (!qp->upoly)
                goto error;
 
-       qp = isl_qpolynomial_reset_dim(qp, isl_dim_copy(r->dim));
+       qp = isl_qpolynomial_reset_domain_space(qp, isl_space_copy(r->dim));
 
        isl_reordering_free(r);
        return qp;
@@ -3930,28 +4108,28 @@ error:
 }
 
 __isl_give isl_qpolynomial *isl_qpolynomial_align_params(
-       __isl_take isl_qpolynomial *qp, __isl_take isl_dim *model)
+       __isl_take isl_qpolynomial *qp, __isl_take isl_space *model)
 {
        if (!qp || !model)
                goto error;
 
-       if (!isl_dim_match(qp->dim, isl_dim_param, model, isl_dim_param)) {
+       if (!isl_space_match(qp->dim, isl_dim_param, model, isl_dim_param)) {
                isl_reordering *exp;
 
-               model = isl_dim_drop(model, isl_dim_in,
-                                       0, isl_dim_size(model, isl_dim_in));
-               model = isl_dim_drop(model, isl_dim_out,
-                                       0, isl_dim_size(model, isl_dim_out));
+               model = isl_space_drop_dims(model, isl_dim_in,
+                                       0, isl_space_dim(model, isl_dim_in));
+               model = isl_space_drop_dims(model, isl_dim_out,
+                                       0, isl_space_dim(model, isl_dim_out));
                exp = isl_parameter_alignment_reordering(qp->dim, model);
-               exp = isl_reordering_extend_dim(exp,
-                                               isl_qpolynomial_get_dim(qp));
-               qp = isl_qpolynomial_realign(qp, exp);
+               exp = isl_reordering_extend_space(exp,
+                                       isl_qpolynomial_get_domain_space(qp));
+               qp = isl_qpolynomial_realign_domain(qp, exp);
        }
 
-       isl_dim_free(model);
+       isl_space_free(model);
        return qp;
 error:
-       isl_dim_free(model);
+       isl_space_free(model);
        isl_qpolynomial_free(qp);
        return NULL;
 }
@@ -3971,7 +4149,7 @@ struct isl_split_periods_data {
  *     f - m v >= 0
  *     -f + m v + (m - 1) >= 0
  */
-static __isl_give isl_set *set_div_slice(__isl_take isl_dim *dim,
+static __isl_give isl_set *set_div_slice(__isl_take isl_space *dim,
        __isl_keep isl_qpolynomial *qp, int div, isl_int v)
 {
        int total;
@@ -3981,8 +4159,8 @@ static __isl_give isl_set *set_div_slice(__isl_take isl_dim *dim,
        if (!dim || !qp)
                goto error;
 
-       total = isl_dim_total(dim);
-       bset = isl_basic_set_alloc_dim(isl_dim_copy(dim), 0, 0, 2);
+       total = isl_space_dim(dim, isl_dim_all);
+       bset = isl_basic_set_alloc_space(isl_space_copy(dim), 0, 0, 2);
 
        k = isl_basic_set_alloc_inequality(bset);
        if (k < 0)
@@ -3998,11 +4176,11 @@ static __isl_give isl_set *set_div_slice(__isl_take isl_dim *dim,
        isl_int_add(bset->ineq[k][0], bset->ineq[k][0], qp->div->row[div][0]);
        isl_int_sub_ui(bset->ineq[k][0], bset->ineq[k][0], 1);
 
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return isl_set_from_basic_set(bset);
 error:
        isl_basic_set_free(bset);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -4022,13 +4200,13 @@ static int set_div(__isl_take isl_set *set,
        isl_set *slice;
        struct isl_upoly *cst;
 
-       slice = set_div_slice(isl_set_get_dim(set), qp, div, v);
+       slice = set_div_slice(isl_set_get_space(set), qp, div, v);
        set = isl_set_intersect(set, slice);
 
        if (!qp)
                goto error;
 
-       total = isl_dim_total(qp->dim);
+       total = isl_space_dim(qp->dim, isl_dim_all);
 
        for (i = div + 1; i < qp->div->n_row; ++i) {
                if (isl_int_is_zero(qp->div->row[i][2 + total + div]))
@@ -4101,7 +4279,7 @@ static int split_periods(__isl_take isl_set *set,
 
        isl_int_init(min);
        isl_int_init(max);
-       total = isl_dim_total(qp->dim);
+       total = isl_space_dim(qp->dim, isl_dim_all);
        for (i = 0; i < qp->div->n_row; ++i) {
                enum isl_lp_result lp_res;
 
@@ -4162,7 +4340,7 @@ __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_split_periods(
        struct isl_split_periods_data data;
 
        data.max_periods = max_periods;
-       data.res = isl_pw_qpolynomial_zero(isl_pw_qpolynomial_get_dim(pwqp));
+       data.res = isl_pw_qpolynomial_zero(isl_pw_qpolynomial_get_space(pwqp));
 
        if (isl_pw_qpolynomial_foreach_piece(pwqp, &split_periods, &data) < 0)
                goto error;
@@ -4185,20 +4363,20 @@ error:
 static __isl_give isl_pw_qpolynomial *constant_on_domain(
        __isl_take isl_basic_set *bset, int cst)
 {
-       isl_dim *dim;
+       isl_space *dim;
        isl_qpolynomial *qp;
 
        if (!bset)
                return NULL;
 
-       bset = isl_basic_map_domain(isl_basic_map_from_range(bset));
-       dim = isl_basic_set_get_dim(bset);
+       bset = isl_basic_set_params(bset);
+       dim = isl_basic_set_get_space(bset);
        if (cst < 0)
-               qp = isl_qpolynomial_infty(dim);
+               qp = isl_qpolynomial_infty_on_domain(dim);
        else if (cst == 0)
-               qp = isl_qpolynomial_zero(dim);
+               qp = isl_qpolynomial_zero_on_domain(dim);
        else
-               qp = isl_qpolynomial_one(dim);
+               qp = isl_qpolynomial_one_on_domain(dim);
        return isl_pw_qpolynomial_alloc(isl_set_from_basic_set(bset), qp);
 }
 
@@ -4213,7 +4391,7 @@ static __isl_give isl_pw_qpolynomial *compressed_multiplicative_call(
        __isl_give isl_pw_qpolynomial *(*fn)(__isl_take isl_basic_set *bset))
 {
        int i, n;
-       isl_dim *dim;
+       isl_space *dim;
        isl_set *set;
        isl_factorizer *f;
        isl_qpolynomial *qp;
@@ -4232,10 +4410,10 @@ static __isl_give isl_pw_qpolynomial *compressed_multiplicative_call(
        nparam = isl_basic_set_dim(bset, isl_dim_param);
        nvar = isl_basic_set_dim(bset, isl_dim_set);
 
-       dim = isl_basic_set_get_dim(bset);
-       dim = isl_dim_domain(dim);
-       set = isl_set_universe(isl_dim_copy(dim));
-       qp = isl_qpolynomial_one(dim);
+       dim = isl_basic_set_get_space(bset);
+       dim = isl_space_domain(dim);
+       set = isl_set_universe(isl_space_copy(dim));
+       qp = isl_qpolynomial_one_on_domain(dim);
        pwqp = isl_pw_qpolynomial_alloc(set, qp);
 
        bset = isl_morph_basic_set(isl_morph_copy(f->morph), bset);
@@ -4283,7 +4461,6 @@ __isl_give isl_pw_qpolynomial *isl_basic_set_multiplicative_call(
        int bounded;
        isl_morph *morph;
        isl_pw_qpolynomial *pwqp;
-       unsigned orig_nvar, final_nvar;
 
        if (!bset)
                return NULL;
@@ -4291,9 +4468,7 @@ __isl_give isl_pw_qpolynomial *isl_basic_set_multiplicative_call(
        if (isl_basic_set_plain_is_empty(bset))
                return constant_on_domain(bset, 0);
 
-       orig_nvar = isl_basic_set_dim(bset, isl_dim_set);
-
-       if (orig_nvar == 0)
+       if (isl_basic_set_dim(bset, isl_dim_set) == 0)
                return constant_on_domain(bset, 1);
 
        bounded = isl_basic_set_is_bounded(bset);
@@ -4308,15 +4483,13 @@ __isl_give isl_pw_qpolynomial *isl_basic_set_multiplicative_call(
        morph = isl_basic_set_full_compression(bset);
        bset = isl_morph_basic_set(isl_morph_copy(morph), bset);
 
-       final_nvar = isl_basic_set_dim(bset, isl_dim_set);
-
        pwqp = compressed_multiplicative_call(bset, fn);
 
-       morph = isl_morph_remove_dom_dims(morph, isl_dim_set, 0, orig_nvar);
-       morph = isl_morph_remove_ran_dims(morph, isl_dim_set, 0, final_nvar);
+       morph = isl_morph_dom_params(morph);
+       morph = isl_morph_ran_params(morph);
        morph = isl_morph_inverse(morph);
 
-       pwqp = isl_pw_qpolynomial_morph(pwqp, morph);
+       pwqp = isl_pw_qpolynomial_morph_domain(pwqp, morph);
 
        return pwqp;
 error:
@@ -4420,7 +4593,7 @@ static __isl_give isl_qpolynomial *make_divs_pos(__isl_take isl_qpolynomial *qp,
        if (!qp->div)
                goto error;
 
-       total = isl_dim_total(qp->dim);
+       total = isl_space_dim(qp->dim, isl_dim_all);
        v = isl_vec_alloc(qp->div->ctx, qp->div->n_col - 1);
 
        for (i = 0; i < qp->div->n_row; ++i) {
@@ -4537,7 +4710,7 @@ __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_to_polynomial(
                return NULL;
 
        data.sign = sign;
-       data.res = isl_pw_qpolynomial_zero(isl_pw_qpolynomial_get_dim(pwqp));
+       data.res = isl_pw_qpolynomial_zero(isl_pw_qpolynomial_get_space(pwqp));
 
        for (i = 0; i < pwqp->n; ++i) {
                if (pwqp->p[i].qp->div->n_row == 0) {
@@ -4594,7 +4767,7 @@ __isl_give isl_basic_map *isl_basic_map_from_qpolynomial(
        __isl_take isl_qpolynomial *qp)
 {
        int i, k;
-       isl_dim *dim;
+       isl_space *dim;
        isl_vec *aff = NULL;
        isl_basic_map *bmap = NULL;
        unsigned pos;
@@ -4608,12 +4781,10 @@ __isl_give isl_basic_map *isl_basic_map_from_qpolynomial(
        aff = isl_qpolynomial_extract_affine(qp);
        if (!aff)
                goto error;
-       dim = isl_qpolynomial_get_dim(qp);
-       dim = isl_dim_from_domain(dim);
-       pos = 1 + isl_dim_offset(dim, isl_dim_out);
-       dim = isl_dim_add(dim, isl_dim_out, 1);
+       dim = isl_qpolynomial_get_space(qp);
+       pos = 1 + isl_space_offset(dim, isl_dim_out);
        n_div = qp->div->n_row;
-       bmap = isl_basic_map_alloc_dim(dim, n_div, 1, 2 * n_div);
+       bmap = isl_basic_map_alloc_space(dim, n_div, 1, 2 * n_div);
 
        for (i = 0; i < n_div; ++i) {
                k = isl_basic_map_alloc_div(bmap);
index 8f6a7b7..54d5fe8 100644 (file)
@@ -27,10 +27,12 @@ struct isl_upoly_rec {
        struct isl_upoly *p[];
 };
 
+/* dim represents the domain space.
+ */
 struct isl_qpolynomial {
        int ref;
 
-       struct isl_dim *dim;
+       isl_space *dim;
        struct isl_mat *div;
        struct isl_upoly *upoly;
 };
@@ -41,7 +43,7 @@ struct isl_term {
        isl_int n;
        isl_int d;
 
-       struct isl_dim *dim;
+       isl_space *dim;
        struct isl_mat *div;
 
        int pow[1];
@@ -55,7 +57,7 @@ struct isl_pw_qpolynomial_piece {
 struct isl_pw_qpolynomial {
        int ref;
 
-       struct isl_dim *dim;
+       isl_space *dim;
 
        int n;
 
@@ -63,11 +65,13 @@ struct isl_pw_qpolynomial {
        struct isl_pw_qpolynomial_piece p[1];
 };
 
+/* dim represents the domain space.
+ */
 struct isl_qpolynomial_fold {
        int ref;
 
        enum isl_fold type;
-       struct isl_dim *dim;
+       isl_space *dim;
 
        int n;
 
@@ -84,7 +88,7 @@ struct isl_pw_qpolynomial_fold {
        int ref;
 
        enum isl_fold type;
-       struct isl_dim *dim;
+       isl_space *dim;
 
        int n;
 
@@ -112,14 +116,14 @@ __isl_give struct isl_upoly *isl_upoly_sum(__isl_take struct isl_upoly *up1,
 __isl_give struct isl_upoly *isl_upoly_mul_isl_int(
        __isl_take struct isl_upoly *up, isl_int v);
 
-__isl_give isl_qpolynomial *isl_qpolynomial_alloc(__isl_take isl_dim *dim,
+__isl_give isl_qpolynomial *isl_qpolynomial_alloc(__isl_take isl_space *dim,
        unsigned n_div, __isl_take struct isl_upoly *up);
 __isl_give isl_qpolynomial *isl_qpolynomial_cow(__isl_take isl_qpolynomial *qp);
 __isl_give isl_qpolynomial *isl_qpolynomial_dup(__isl_keep isl_qpolynomial *qp);
 
-__isl_give isl_qpolynomial *isl_qpolynomial_cst(__isl_take isl_dim *dim,
+__isl_give isl_qpolynomial *isl_qpolynomial_cst_on_domain(__isl_take isl_space *dim,
        isl_int v);
-__isl_give isl_qpolynomial *isl_qpolynomial_var_pow(__isl_take isl_dim *dim,
+__isl_give isl_qpolynomial *isl_qpolynomial_var_pow_on_domain(__isl_take isl_space *dim,
        int pos, int power);
 __isl_give isl_qpolynomial *isl_qpolynomial_div_pow(__isl_take isl_div *div,
        int power);
@@ -145,7 +149,7 @@ __isl_give isl_qpolynomial *isl_qpolynomial_coeff(
 
 __isl_give isl_vec *isl_qpolynomial_extract_affine(
        __isl_keep isl_qpolynomial *qp);
-__isl_give isl_qpolynomial *isl_qpolynomial_from_affine(__isl_take isl_dim *dim,
+__isl_give isl_qpolynomial *isl_qpolynomial_from_affine(__isl_take isl_space *dim,
        isl_int *f, isl_int denom);
 
 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_cow(
@@ -156,6 +160,10 @@ __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_add_piece(
        __isl_take isl_set *set, __isl_take isl_qpolynomial *qp);
 int isl_pw_qpolynomial_is_one(__isl_keep isl_pw_qpolynomial *pwqp);
 
+__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_project_out(
+       __isl_take isl_pw_qpolynomial *pwqp,
+       enum isl_dim_type type, unsigned first, unsigned n);
+
 __isl_give isl_qpolynomial *isl_qpolynomial_opt_on_domain(
        __isl_take isl_qpolynomial *qp, __isl_take isl_set *set, int max);
 
@@ -184,19 +192,19 @@ __isl_give isl_qpolynomial *isl_qpolynomial_fold_opt_on_domain(
 int isl_pw_qpolynomial_fold_covers(__isl_keep isl_pw_qpolynomial_fold *pwf1,
        __isl_keep isl_pw_qpolynomial_fold *pwf2);
 
-__isl_give isl_qpolynomial *isl_qpolynomial_morph(__isl_take isl_qpolynomial *qp,
-       __isl_take isl_morph *morph);
-__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_morph(
+__isl_give isl_qpolynomial *isl_qpolynomial_morph_domain(
+       __isl_take isl_qpolynomial *qp, __isl_take isl_morph *morph);
+__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_morph_domain(
        __isl_take isl_pw_qpolynomial *pwqp, __isl_take isl_morph *morph);
-__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_morph(
+__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_morph_domain(
        __isl_take isl_qpolynomial_fold *fold, __isl_take isl_morph *morph);
-__isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_morph(
+__isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_morph_domain(
        __isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_morph *morph);
 
 __isl_give isl_qpolynomial *isl_qpolynomial_lift(__isl_take isl_qpolynomial *qp,
-       __isl_take isl_dim *dim);
+       __isl_take isl_space *dim);
 __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_lift(
-       __isl_take isl_qpolynomial_fold *fold, __isl_take isl_dim *dim);
+       __isl_take isl_qpolynomial_fold *fold, __isl_take isl_space *dim);
 
 __isl_give isl_qpolynomial *isl_qpolynomial_substitute_equalities(
        __isl_take isl_qpolynomial *qp, __isl_take isl_basic_set *eq);
@@ -205,11 +213,24 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_substitute_equalities(
 __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_gist(
        __isl_take isl_qpolynomial_fold *fold, __isl_take isl_set *context);
 
-__isl_give isl_qpolynomial *isl_qpolynomial_realign(
+__isl_give isl_qpolynomial *isl_qpolynomial_realign_domain(
        __isl_take isl_qpolynomial *qp, __isl_take isl_reordering *r);
-__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_realign(
+__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_realign_domain(
        __isl_take isl_qpolynomial_fold *fold, __isl_take isl_reordering *r);
-__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_realign(
+__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_realign_domain(
        __isl_take isl_pw_qpolynomial *pwqp, __isl_take isl_reordering *r);
-__isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_realign(
+__isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_realign_domain(
        __isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_reordering *r);
+
+__isl_give isl_qpolynomial *isl_qpolynomial_reset_domain_space(
+       __isl_take isl_qpolynomial *qp, __isl_take isl_space *dim);
+__isl_give isl_qpolynomial *isl_qpolynomial_reset_space_and_domain(
+       __isl_take isl_qpolynomial *qp, __isl_take isl_space *space,
+       __isl_take isl_space *domain);
+__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_reset_domain_space(
+       __isl_take isl_qpolynomial_fold *fold, __isl_take isl_space *dim);
+__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_reset_space_and_domain(
+       __isl_take isl_qpolynomial_fold *fold, __isl_take isl_space *space,
+       __isl_take isl_space *domain);
+__isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_reset_domain_space(
+       __isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_space *dim);
index a446c43..ae9328d 100644 (file)
@@ -4,10 +4,10 @@
 #define S(TYPE,NAME) xS(TYPE,NAME)
 
 #ifdef HAS_TYPE
-static __isl_give PW *FN(PW,alloc_)(__isl_take isl_dim *dim,
+__isl_give PW *FN(PW,alloc_size)(__isl_take isl_space *dim,
        enum isl_fold type, int n)
 #else
-static __isl_give PW *FN(PW,alloc_)(__isl_take isl_dim *dim, int n)
+__isl_give PW *FN(PW,alloc_size)(__isl_take isl_space *dim, int n)
 #endif
 {
        isl_ctx *ctx;
@@ -15,7 +15,7 @@ static __isl_give PW *FN(PW,alloc_)(__isl_take isl_dim *dim, int n)
 
        if (!dim)
                return NULL;
-       ctx = isl_dim_get_ctx(dim);
+       ctx = isl_space_get_ctx(dim);
        isl_assert(ctx, n >= 0, goto error);
        pw = isl_alloc(ctx, struct PW,
                        sizeof(struct PW) + (n - 1) * sizeof(S(PW,piece)));
@@ -31,19 +31,19 @@ static __isl_give PW *FN(PW,alloc_)(__isl_take isl_dim *dim, int n)
        pw->dim = dim;
        return pw;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
 #ifdef HAS_TYPE
-__isl_give PW *FN(PW,ZERO)(__isl_take isl_dim *dim, enum isl_fold type)
+__isl_give PW *FN(PW,ZERO)(__isl_take isl_space *dim, enum isl_fold type)
 {
-       return FN(PW,alloc_)(dim, type, 0);
+       return FN(PW,alloc_size)(dim, type, 0);
 }
 #else
-__isl_give PW *FN(PW,ZERO)(__isl_take isl_dim *dim)
+__isl_give PW *FN(PW,ZERO)(__isl_take isl_space *dim)
 {
-       return FN(PW,alloc_)(dim, 0);
+       return FN(PW,alloc_size)(dim, 0);
 }
 #endif
 
@@ -51,7 +51,7 @@ __isl_give PW *FN(PW,add_piece)(__isl_take PW *pw,
        __isl_take isl_set *set, __isl_take EL *el)
 {
        isl_ctx *ctx;
-       isl_dim *el_dim = NULL;
+       isl_space *el_dim = NULL;
 
        if (!pw || !set || !el)
                goto error;
@@ -68,18 +68,18 @@ __isl_give PW *FN(PW,add_piece)(__isl_take PW *pw,
                isl_die(ctx, isl_error_invalid, "fold types don't match",
                        goto error);
 #endif
-       el_dim = FN(EL,get_dim(el));
-       isl_assert(ctx, isl_dim_equal(pw->dim, el_dim), goto error);
+       el_dim = FN(EL,get_space(el));
+       isl_assert(ctx, isl_space_is_equal(pw->dim, el_dim), goto error);
        isl_assert(ctx, pw->n < pw->size, goto error);
 
        pw->p[pw->n].set = set;
        pw->p[pw->n].FIELD = el;
        pw->n++;
        
-       isl_dim_free(el_dim);
+       isl_space_free(el_dim);
        return pw;
 error:
-       isl_dim_free(el_dim);
+       isl_space_free(el_dim);
        FN(PW,free)(pw);
        isl_set_free(set);
        FN(EL,free)(el);
@@ -99,9 +99,9 @@ __isl_give PW *FN(PW,alloc)(__isl_take isl_set *set, __isl_take EL *el)
                goto error;
 
 #ifdef HAS_TYPE
-       pw = FN(PW,alloc_)(isl_set_get_dim(set), type, 1);
+       pw = FN(PW,alloc_size)(FN(EL,get_space)(el), type, 1);
 #else
-       pw = FN(PW,alloc_)(isl_set_get_dim(set), 1);
+       pw = FN(PW,alloc_size)(FN(EL,get_space)(el), 1);
 #endif
 
        return FN(PW,add_piece)(pw, set, el);
@@ -120,9 +120,9 @@ __isl_give PW *FN(PW,dup)(__isl_keep PW *pw)
                return NULL;
 
 #ifdef HAS_TYPE
-       dup = FN(PW,alloc_)(isl_dim_copy(pw->dim), pw->type, pw->n);
+       dup = FN(PW,alloc_size)(isl_space_copy(pw->dim), pw->type, pw->n);
 #else
-       dup = FN(PW,alloc_)(isl_dim_copy(pw->dim), pw->n);
+       dup = FN(PW,alloc_size)(isl_space_copy(pw->dim), pw->n);
 #endif
        if (!dup)
                return NULL;
@@ -167,7 +167,7 @@ void *FN(PW,free)(__isl_take PW *pw)
                isl_set_free(pw->p[i].set);
                FN(EL,free)(pw->p[i].FIELD);
        }
-       isl_dim_free(pw->dim);
+       isl_space_free(pw->dim);
        free(pw);
 
        return NULL;
@@ -181,7 +181,124 @@ int FN(PW,IS_ZERO)(__isl_keep PW *pw)
        return pw->n == 0;
 }
 
-__isl_give PW *FN(PW,add)(__isl_take PW *pw1, __isl_take PW *pw2)
+#ifndef NO_REALIGN
+__isl_give PW *FN(PW,realign_domain)(__isl_take PW *pw,
+       __isl_take isl_reordering *exp)
+{
+       int i;
+
+       pw = FN(PW,cow)(pw);
+       if (!pw || !exp)
+               return NULL;
+
+       for (i = 0; i < pw->n; ++i) {
+               pw->p[i].set = isl_set_realign(pw->p[i].set,
+                                                   isl_reordering_copy(exp));
+               if (!pw->p[i].set)
+                       goto error;
+               pw->p[i].FIELD = FN(EL,realign_domain)(pw->p[i].FIELD,
+                                                   isl_reordering_copy(exp));
+               if (!pw->p[i].FIELD)
+                       goto error;
+       }
+
+       pw = FN(PW,reset_domain_space)(pw, isl_space_copy(exp->dim));
+
+       isl_reordering_free(exp);
+       return pw;
+error:
+       isl_reordering_free(exp);
+       FN(PW,free)(pw);
+       return NULL;
+}
+
+/* Align the parameters of "pw" to those of "model".
+ */
+__isl_give PW *FN(PW,align_params)(__isl_take PW *pw, __isl_take isl_space *model)
+{
+       isl_ctx *ctx;
+
+       if (!pw || !model)
+               goto error;
+
+       ctx = isl_space_get_ctx(model);
+       if (!isl_space_has_named_params(model))
+               isl_die(ctx, isl_error_invalid,
+                       "model has unnamed parameters", goto error);
+       if (!isl_space_has_named_params(pw->dim))
+               isl_die(ctx, isl_error_invalid,
+                       "input has unnamed parameters", goto error);
+       if (!isl_space_match(pw->dim, isl_dim_param, model, isl_dim_param)) {
+               isl_reordering *exp;
+
+               model = isl_space_drop_dims(model, isl_dim_in,
+                                       0, isl_space_dim(model, isl_dim_in));
+               model = isl_space_drop_dims(model, isl_dim_out,
+                                       0, isl_space_dim(model, isl_dim_out));
+               exp = isl_parameter_alignment_reordering(pw->dim, model);
+               exp = isl_reordering_extend_space(exp,
+                                       FN(PW,get_domain_space)(pw));
+               pw = FN(PW,realign_domain)(pw, exp);
+       }
+
+       isl_space_free(model);
+       return pw;
+error:
+       isl_space_free(model);
+       FN(PW,free)(pw);
+       return NULL;
+}
+
+static __isl_give PW *align_params_pw_pw_and(__isl_take PW *pw1,
+       __isl_take PW *pw2,
+       __isl_give PW *(*fn)(__isl_take PW *pw1, __isl_take PW *pw2))
+{
+       isl_ctx *ctx;
+
+       if (!pw1 || !pw2)
+               goto error;
+       if (isl_space_match(pw1->dim, isl_dim_param, pw2->dim, isl_dim_param))
+               return fn(pw1, pw2);
+       ctx = FN(PW,get_ctx)(pw1);
+       if (!isl_space_has_named_params(pw1->dim) ||
+           !isl_space_has_named_params(pw2->dim))
+               isl_die(ctx, isl_error_invalid,
+                       "unaligned unnamed parameters", goto error);
+       pw1 = FN(PW,align_params)(pw1, FN(PW,get_space)(pw2));
+       pw2 = FN(PW,align_params)(pw2, FN(PW,get_space)(pw1));
+       return fn(pw1, pw2);
+error:
+       FN(PW,free)(pw1);
+       FN(PW,free)(pw2);
+       return NULL;
+}
+
+static __isl_give PW *align_params_pw_set_and(__isl_take PW *pw,
+       __isl_take isl_set *set,
+       __isl_give PW *(*fn)(__isl_take PW *pw, __isl_take isl_set *set))
+{
+       isl_ctx *ctx;
+
+       if (!pw || !set)
+               goto error;
+       if (isl_space_match(pw->dim, isl_dim_param, set->dim, isl_dim_param))
+               return fn(pw, set);
+       ctx = FN(PW,get_ctx)(pw);
+       if (!isl_space_has_named_params(pw->dim) ||
+           !isl_space_has_named_params(set->dim))
+               isl_die(ctx, isl_error_invalid,
+                       "unaligned unnamed parameters", goto error);
+       pw = FN(PW,align_params)(pw, isl_set_get_space(set));
+       set = isl_set_align_params(set, FN(PW,get_space)(pw));
+       return fn(pw, set);
+error:
+       FN(PW,free)(pw);
+       isl_set_free(set);
+       return NULL;
+}
+#endif
+
+static __isl_give PW *FN(PW,add_aligned)(__isl_take PW *pw1, __isl_take PW *pw2)
 {
        int i, j, n;
        struct PW *res;
@@ -191,13 +308,13 @@ __isl_give PW *FN(PW,add)(__isl_take PW *pw1, __isl_take PW *pw2)
        if (!pw1 || !pw2)
                goto error;
 
-       ctx = isl_dim_get_ctx(pw1->dim);
+       ctx = isl_space_get_ctx(pw1->dim);
 #ifdef HAS_TYPE
        if (pw1->type != pw2->type)
                isl_die(ctx, isl_error_invalid,
                        "fold types don't match", goto error);
 #endif
-       isl_assert(ctx, isl_dim_equal(pw1->dim, pw2->dim), goto error);
+       isl_assert(ctx, isl_space_is_equal(pw1->dim, pw2->dim), goto error);
 
        if (FN(PW,IS_ZERO)(pw1)) {
                FN(PW,free)(pw1);
@@ -211,9 +328,9 @@ __isl_give PW *FN(PW,add)(__isl_take PW *pw1, __isl_take PW *pw2)
 
        n = (pw1->n + 1) * (pw2->n + 1);
 #ifdef HAS_TYPE
-       res = FN(PW,alloc_)(isl_dim_copy(pw1->dim), pw1->type, n);
+       res = FN(PW,alloc_size)(isl_space_copy(pw1->dim), pw1->type, n);
 #else
-       res = FN(PW,alloc_)(isl_dim_copy(pw1->dim), n);
+       res = FN(PW,alloc_size)(isl_space_copy(pw1->dim), n);
 #endif
 
        for (i = 0; i < pw1->n; ++i) {
@@ -257,22 +374,69 @@ error:
        return NULL;
 }
 
-__isl_give PW *FN(PW,add_disjoint)(__isl_take PW *pw1, __isl_take PW *pw2)
+__isl_give PW *FN(PW,add)(__isl_take PW *pw1, __isl_take PW *pw2)
+{
+       return align_params_pw_pw_and(pw1, pw2, &FN(PW,add_aligned));
+}
+
+/* Make sure "pw" has room for at least "n" more pieces.
+ *
+ * If there is only one reference to pw, we extend it in place.
+ * Otherwise, we create a new PW and copy the pieces.
+ */
+static __isl_give PW *FN(PW,grow)(__isl_take PW *pw, int n)
 {
        int i;
        isl_ctx *ctx;
        PW *res;
 
+       if (!pw)
+               return NULL;
+       if (pw->n + n <= pw->size)
+               return pw;
+       ctx = FN(PW,get_ctx)(pw);
+       n += pw->n;
+       if (pw->ref == 1) {
+               res = isl_realloc(ctx, pw, struct PW,
+                           sizeof(struct PW) + (n - 1) * sizeof(S(PW,piece)));
+               if (!res)
+                       return FN(PW,free)(pw);
+               res->size = n;
+               return res;
+       }
+#ifdef HAS_TYPE
+       res = FN(PW,alloc_size)(isl_space_copy(pw->dim), pw->type, n);
+#else
+       res = FN(PW,alloc_size)(isl_space_copy(pw->dim), n);
+#endif
+       if (!res)
+               return FN(PW,free)(pw);
+       for (i = 0; i < pw->n; ++i)
+               res = FN(PW,add_piece)(res, isl_set_copy(pw->p[i].set),
+                                           FN(EL,copy)(pw->p[i].FIELD));
+       FN(PW,free)(pw);
+       return res;
+}
+
+static __isl_give PW *FN(PW,add_disjoint_aligned)(__isl_take PW *pw1,
+       __isl_take PW *pw2)
+{
+       int i;
+       isl_ctx *ctx;
+
        if (!pw1 || !pw2)
                goto error;
 
-       ctx = isl_dim_get_ctx(pw1->dim);
+       if (pw1->size < pw1->n + pw2->n && pw1->n < pw2->n)
+               return FN(PW,add_disjoint_aligned)(pw2, pw1);
+
+       ctx = isl_space_get_ctx(pw1->dim);
 #ifdef HAS_TYPE
        if (pw1->type != pw2->type)
                isl_die(ctx, isl_error_invalid,
                        "fold types don't match", goto error);
 #endif
-       isl_assert(ctx, isl_dim_equal(pw1->dim, pw2->dim), goto error);
+       isl_assert(ctx, isl_space_is_equal(pw1->dim, pw2->dim), goto error);
 
        if (FN(PW,IS_ZERO)(pw1)) {
                FN(PW,free)(pw1);
@@ -284,32 +448,29 @@ __isl_give PW *FN(PW,add_disjoint)(__isl_take PW *pw1, __isl_take PW *pw2)
                return pw1;
        }
 
-#ifdef HAS_TYPE
-       res = FN(PW,alloc_)(isl_dim_copy(pw1->dim), pw1->type, pw1->n + pw2->n);
-#else
-       res = FN(PW,alloc_)(isl_dim_copy(pw1->dim), pw1->n + pw2->n);
-#endif
-
-       for (i = 0; i < pw1->n; ++i)
-               res = FN(PW,add_piece)(res,
-                               isl_set_copy(pw1->p[i].set),
-                               FN(EL,copy)(pw1->p[i].FIELD));
+       pw1 = FN(PW,grow)(pw1, pw2->n);
+       if (!pw1)
+               goto error;
 
        for (i = 0; i < pw2->n; ++i)
-               res = FN(PW,add_piece)(res,
+               pw1 = FN(PW,add_piece)(pw1,
                                isl_set_copy(pw2->p[i].set),
                                FN(EL,copy)(pw2->p[i].FIELD));
 
-       FN(PW,free)(pw1);
        FN(PW,free)(pw2);
 
-       return res;
+       return pw1;
 error:
        FN(PW,free)(pw1);
        FN(PW,free)(pw2);
        return NULL;
 }
 
+__isl_give PW *FN(PW,add_disjoint)(__isl_take PW *pw1, __isl_take PW *pw2)
+{
+       return align_params_pw_pw_and(pw1, pw2, &FN(PW,add_disjoint_aligned));
+}
+
 #ifndef NO_NEG
 __isl_give PW *FN(PW,neg)(__isl_take PW *pw)
 {
@@ -347,14 +508,14 @@ __isl_give isl_qpolynomial *FN(PW,eval)(__isl_take PW *pw,
        int i;
        int found = 0;
        isl_ctx *ctx;
-       isl_dim *pnt_dim = NULL;
+       isl_space *pnt_dim = NULL;
        isl_qpolynomial *qp;
 
        if (!pw || !pnt)
                goto error;
        ctx = isl_point_get_ctx(pnt);
-       pnt_dim = isl_point_get_dim(pnt);
-       isl_assert(ctx, isl_dim_equal(pnt_dim, pw->dim), goto error);
+       pnt_dim = isl_point_get_space(pnt);
+       isl_assert(ctx, isl_space_is_domain(pnt_dim, pw->dim), goto error);
 
        for (i = 0; i < pw->n; ++i) {
                found = isl_set_contains_point(pw->p[i].set, pnt);
@@ -367,14 +528,14 @@ __isl_give isl_qpolynomial *FN(PW,eval)(__isl_take PW *pw,
                qp = FN(EL,eval)(FN(EL,copy)(pw->p[i].FIELD),
                                            isl_point_copy(pnt));
        else
-               qp = isl_qpolynomial_zero(isl_dim_copy(pw->dim));
+               qp = isl_qpolynomial_zero_on_domain(FN(PW,get_domain_space)(pw));
        FN(PW,free)(pw);
-       isl_dim_free(pnt_dim);
+       isl_space_free(pnt_dim);
        isl_point_free(pnt);
        return qp;
 error:
        FN(PW,free)(pw);
-       isl_dim_free(pnt_dim);
+       isl_space_free(pnt_dim);
        isl_point_free(pnt);
        return NULL;
 }
@@ -388,7 +549,7 @@ __isl_give isl_set *FN(PW,domain)(__isl_take PW *pw)
        if (!pw)
                return NULL;
 
-       dom = isl_set_empty(isl_dim_copy(pw->dim));
+       dom = isl_set_empty(FN(PW,get_domain_space)(pw));
        for (i = 0; i < pw->n; ++i)
                dom = isl_set_union_disjoint(dom, isl_set_copy(pw->p[i].set));
 
@@ -397,7 +558,8 @@ __isl_give isl_set *FN(PW,domain)(__isl_take PW *pw)
        return dom;
 }
 
-__isl_give PW *FN(PW,intersect_domain)(__isl_take PW *pw, __isl_take isl_set *set)
+static __isl_give PW *FN(PW,intersect_domain_aligned)(__isl_take PW *pw,
+       __isl_take isl_set *set)
 {
        int i;
 
@@ -438,7 +600,15 @@ error:
        return NULL;
 }
 
-__isl_give PW *FN(PW,gist)(__isl_take PW *pw, __isl_take isl_set *context)
+__isl_give PW *FN(PW,intersect_domain)(__isl_take PW *pw,
+       __isl_take isl_set *context)
+{
+       return align_params_pw_set_and(pw, context,
+                                       &FN(PW,intersect_domain_aligned));
+}
+
+static __isl_give PW *FN(PW,gist_aligned)(__isl_take PW *pw,
+       __isl_take isl_set *context)
 {
        int i;
        isl_basic_set *hull = NULL;
@@ -451,6 +621,12 @@ __isl_give PW *FN(PW,gist)(__isl_take PW *pw, __isl_take isl_set *context)
                return pw;
        }
 
+       if (!isl_space_match(pw->dim, isl_dim_param,
+                               context->dim, isl_dim_param)) {
+               pw = FN(PW,align_params)(pw, isl_set_get_space(context));
+               context = isl_set_align_params(context, FN(PW,get_space)(pw));
+       }
+
        context = isl_set_compute_divs(context);
        hull = isl_set_simple_hull(isl_set_copy(context));
 
@@ -489,6 +665,11 @@ error:
        return NULL;
 }
 
+__isl_give PW *FN(PW,gist)(__isl_take PW *pw, __isl_take isl_set *context)
+{
+       return align_params_pw_set_and(pw, context, &FN(PW,gist_aligned));
+}
+
 __isl_give PW *FN(PW,coalesce)(__isl_take PW *pw)
 {
        int i, j;
@@ -526,7 +707,7 @@ error:
 
 isl_ctx *FN(PW,get_ctx)(__isl_keep PW *pw)
 {
-       return pw ? isl_dim_get_ctx(pw->dim) : NULL;
+       return pw ? isl_space_get_ctx(pw->dim) : NULL;
 }
 
 #ifndef NO_INVOLVES_DIMS
@@ -534,17 +715,22 @@ int FN(PW,involves_dims)(__isl_keep PW *pw, enum isl_dim_type type,
        unsigned first, unsigned n)
 {
        int i;
+       enum isl_dim_type set_type;
 
        if (!pw)
                return -1;
        if (pw->n == 0 || n == 0)
                return 0;
+
+       set_type = type == isl_dim_in ? isl_dim_set : type;
+
        for (i = 0; i < pw->n; ++i) {
                int involves = FN(EL,involves_dims)(pw->p[i].FIELD,
                                                        type, first, n);
                if (involves < 0 || involves)
                        return involves;
-               involves = isl_set_involves_dims(pw->p[i].set, type, first, n);
+               involves = isl_set_involves_dims(pw->p[i].set,
+                                                       set_type, first, n);
                if (involves < 0 || involves)
                        return involves;
        }
@@ -556,17 +742,21 @@ __isl_give PW *FN(PW,set_dim_name)(__isl_take PW *pw,
        enum isl_dim_type type, unsigned pos, const char *s)
 {
        int i;
+       enum isl_dim_type set_type;
 
        pw = FN(PW,cow)(pw);
        if (!pw)
                return NULL;
 
-       pw->dim = isl_dim_set_name(pw->dim, type, pos, s);
+       set_type = type == isl_dim_in ? isl_dim_set : type;
+
+       pw->dim = isl_space_set_dim_name(pw->dim, type, pos, s);
        if (!pw->dim)
                goto error;
 
        for (i = 0; i < pw->n; ++i) {
-               pw->p[i].set = isl_set_set_dim_name(pw->p[i].set, type, pos, s);
+               pw->p[i].set = isl_set_set_dim_name(pw->p[i].set,
+                                                       set_type, pos, s);
                if (!pw->p[i].set)
                        goto error;
                pw->p[i].FIELD = FN(EL,set_dim_name)(pw->p[i].FIELD, type, pos, s);
@@ -585,20 +775,63 @@ __isl_give PW *FN(PW,drop_dims)(__isl_take PW *pw,
        enum isl_dim_type type, unsigned first, unsigned n)
 {
        int i;
+       enum isl_dim_type set_type;
+
+       if (!pw)
+               return NULL;
+       if (n == 0 && !isl_space_get_tuple_name(pw->dim, type))
+               return pw;
+
+       set_type = type == isl_dim_in ? isl_dim_set : type;
+
+       pw = FN(PW,cow)(pw);
+       if (!pw)
+               return NULL;
+       pw->dim = isl_space_drop_dims(pw->dim, type, first, n);
+       if (!pw->dim)
+               goto error;
+       for (i = 0; i < pw->n; ++i) {
+               pw->p[i].set = isl_set_drop(pw->p[i].set, set_type, first, n);
+               if (!pw->p[i].set)
+                       goto error;
+               pw->p[i].FIELD = FN(EL,drop_dims)(pw->p[i].FIELD, type, first, n);
+               if (!pw->p[i].FIELD)
+                       goto error;
+       }
+
+       return pw;
+error:
+       FN(PW,free)(pw);
+       return NULL;
+}
+
+/* This function is very similar to drop_dims.
+ * The only difference is that the cells may still involve
+ * the specified dimensions.  They are removed using
+ * isl_set_project_out instead of isl_set_drop.
+ */
+__isl_give PW *FN(PW,project_out)(__isl_take PW *pw,
+       enum isl_dim_type type, unsigned first, unsigned n)
+{
+       int i;
+       enum isl_dim_type set_type;
 
        if (!pw)
                return NULL;
-       if (n == 0 && !isl_dim_get_tuple_name(pw->dim, type))
+       if (n == 0 && !isl_space_get_tuple_name(pw->dim, type))
                return pw;
 
+       set_type = type == isl_dim_in ? isl_dim_set : type;
+
        pw = FN(PW,cow)(pw);
        if (!pw)
                return NULL;
-       pw->dim = isl_dim_drop(pw->dim, type, first, n);
+       pw->dim = isl_space_drop_dims(pw->dim, type, first, n);
        if (!pw->dim)
                goto error;
        for (i = 0; i < pw->n; ++i) {
-               pw->p[i].set = isl_set_drop(pw->p[i].set, type, first, n);
+               pw->p[i].set = isl_set_project_out(pw->p[i].set,
+                                                       set_type, first, n);
                if (!pw->p[i].set)
                        goto error;
                pw->p[i].FIELD = FN(EL,drop_dims)(pw->p[i].FIELD, type, first, n);
@@ -611,6 +844,21 @@ error:
        FN(PW,free)(pw);
        return NULL;
 }
+
+/* Project the domain of pw onto its parameter space.
+ */
+__isl_give PW *FN(PW,project_domain_on_params)(__isl_take PW *pw)
+{
+       isl_space *space;
+       unsigned n;
+
+       n = FN(PW,dim)(pw, isl_dim_in);
+       pw = FN(PW,project_out)(pw, isl_dim_in, 0, n);
+       space = FN(PW,get_domain_space)(pw);
+       space = isl_space_params(space);
+       pw = FN(PW,reset_domain_space)(pw, space);
+       return pw;
+}
 #endif
 
 #ifndef NO_INSERT_DIMS
@@ -618,22 +866,26 @@ __isl_give PW *FN(PW,insert_dims)(__isl_take PW *pw, enum isl_dim_type type,
        unsigned first, unsigned n)
 {
        int i;
+       enum isl_dim_type set_type;
 
        if (!pw)
                return NULL;
-       if (n == 0 && !isl_dim_is_named_or_nested(pw->dim, type))
+       if (n == 0 && !isl_space_is_named_or_nested(pw->dim, type))
                return pw;
 
+       set_type = type == isl_dim_in ? isl_dim_set : type;
+
        pw = FN(PW,cow)(pw);
        if (!pw)
                return NULL;
 
-       pw->dim = isl_dim_insert(pw->dim, type, first, n);
+       pw->dim = isl_space_insert_dims(pw->dim, type, first, n);
        if (!pw->dim)
                goto error;
 
        for (i = 0; i < pw->n; ++i) {
-               pw->p[i].set = isl_set_insert(pw->p[i].set, type, first, n);
+               pw->p[i].set = isl_set_insert_dims(pw->p[i].set,
+                                                           set_type, first, n);
                if (!pw->p[i].set)
                        goto error;
                pw->p[i].FIELD = FN(EL,insert_dims)(pw->p[i].FIELD,
@@ -657,6 +909,9 @@ __isl_give PW *FN(PW,fix_dim)(__isl_take PW *pw,
        if (!pw)
                return NULL;
 
+       if (type == isl_dim_in)
+               type = isl_dim_set;
+
        pw = FN(PW,cow)(pw);
        if (!pw)
                return NULL;
@@ -674,7 +929,7 @@ error:
 
 unsigned FN(PW,dim)(__isl_keep PW *pw, enum isl_dim_type type)
 {
-       return pw ? isl_dim_size(pw->dim, type) : 0;
+       return pw ? isl_space_dim(pw->dim, type) : 0;
 }
 
 __isl_give PW *FN(PW,split_dims)(__isl_take PW *pw,
@@ -687,6 +942,9 @@ __isl_give PW *FN(PW,split_dims)(__isl_take PW *pw,
        if (n == 0)
                return pw;
 
+       if (type == isl_dim_in)
+               type = isl_dim_set;
+
        pw = FN(PW,cow)(pw);
        if (!pw)
                return NULL;
@@ -719,9 +977,9 @@ __isl_give isl_qpolynomial *FN(PW,opt)(__isl_take PW *pw, int max)
                return NULL;
 
        if (pw->n == 0) {
-               isl_dim *dim = isl_dim_copy(pw->dim);
+               isl_space *dim = isl_space_copy(pw->dim);
                FN(PW,free)(pw);
-               return isl_qpolynomial_zero(dim);
+               return isl_qpolynomial_zero_on_domain(dim);
        }
 
        opt = FN(EL,opt_on_domain)(FN(EL,copy)(pw->p[0].FIELD),
@@ -751,51 +1009,84 @@ __isl_give isl_qpolynomial *FN(PW,min)(__isl_take PW *pw)
 }
 #endif
 
-__isl_give isl_dim *FN(PW,get_dim)(__isl_keep PW *pw)
+__isl_give isl_space *FN(PW,get_space)(__isl_keep PW *pw)
 {
-       return pw ? isl_dim_copy(pw->dim) : NULL;
+       return pw ? isl_space_copy(pw->dim) : NULL;
+}
+
+__isl_give isl_space *FN(PW,get_domain_space)(__isl_keep PW *pw)
+{
+       return pw ? isl_space_domain(isl_space_copy(pw->dim)) : NULL;
 }
 
 #ifndef NO_RESET_DIM
-__isl_give PW *FN(PW,reset_dim)(__isl_take PW *pw, __isl_take isl_dim *dim)
+/* Reset the space of "pw".  Since we don't know if the elements
+ * represent the spaces themselves or their domains, we pass along
+ * both when we call their reset_space_and_domain.
+ */
+static __isl_give PW *FN(PW,reset_space_and_domain)(__isl_take PW *pw,
+       __isl_take isl_space *space, __isl_take isl_space *domain)
 {
        int i;
 
        pw = FN(PW,cow)(pw);
-       if (!pw || !dim)
+       if (!pw || !space || !domain)
                goto error;
 
        for (i = 0; i < pw->n; ++i) {
-               pw->p[i].set = isl_set_reset_dim(pw->p[i].set,
-                                                isl_dim_copy(dim));
+               pw->p[i].set = isl_set_reset_space(pw->p[i].set,
+                                                isl_space_copy(domain));
                if (!pw->p[i].set)
                        goto error;
-               pw->p[i].FIELD = FN(EL,reset_dim)(pw->p[i].FIELD,
-                                                 isl_dim_copy(dim));
+               pw->p[i].FIELD = FN(EL,reset_space_and_domain)(pw->p[i].FIELD,
+                             isl_space_copy(space), isl_space_copy(domain));
                if (!pw->p[i].FIELD)
                        goto error;
        }
-       isl_dim_free(pw->dim);
-       pw->dim = dim;
+
+       isl_space_free(domain);
+
+       isl_space_free(pw->dim);
+       pw->dim = space;
 
        return pw;
 error:
-       isl_dim_free(dim);
+       isl_space_free(domain);
+       isl_space_free(space);
        FN(PW,free)(pw);
        return NULL;
 }
+
+__isl_give PW *FN(PW,reset_domain_space)(__isl_take PW *pw,
+       __isl_take isl_space *domain)
+{
+       isl_space *space;
+
+       space = isl_space_extend_domain_with_range(isl_space_copy(domain),
+                                                  FN(PW,get_space)(pw));
+       return FN(PW,reset_space_and_domain)(pw, space, domain);
+}
+
+__isl_give PW *FN(PW,reset_space)(__isl_take PW *pw, __isl_take isl_space *dim)
+{
+       isl_space *domain;
+
+       domain = isl_space_domain(isl_space_copy(dim));
+       return FN(PW,reset_space_and_domain)(pw, dim, domain);
+}
 #endif
 
-int FN(PW,has_equal_dim)(__isl_keep PW *pw1, __isl_keep PW *pw2)
+int FN(PW,has_equal_space)(__isl_keep PW *pw1, __isl_keep PW *pw2)
 {
        if (!pw1 || !pw2)
                return -1;
 
-       return isl_dim_equal(pw1->dim, pw2->dim);
+       return isl_space_is_equal(pw1->dim, pw2->dim);
 }
 
 #ifndef NO_MORPH
-__isl_give PW *FN(PW,morph)(__isl_take PW *pw, __isl_take isl_morph *morph)
+__isl_give PW *FN(PW,morph_domain)(__isl_take PW *pw,
+       __isl_take isl_morph *morph)
 {
        int i;
        isl_ctx *ctx;
@@ -803,15 +1094,15 @@ __isl_give PW *FN(PW,morph)(__isl_take PW *pw, __isl_take isl_morph *morph)
        if (!pw || !morph)
                goto error;
 
-       ctx = isl_dim_get_ctx(pw->dim);
-       isl_assert(ctx, isl_dim_equal(pw->dim, morph->dom->dim),
+       ctx = isl_space_get_ctx(pw->dim);
+       isl_assert(ctx, isl_space_is_domain(morph->dom->dim, pw->dim),
                goto error);
 
        pw = FN(PW,cow)(pw);
        if (!pw)
                goto error;
-       isl_dim_free(pw->dim);
-       pw->dim = isl_dim_copy(morph->ran->dim);
+       pw->dim = isl_space_extend_domain_with_range(
+                       isl_space_copy(morph->ran->dim), pw->dim);
        if (!pw->dim)
                goto error;
 
@@ -819,7 +1110,7 @@ __isl_give PW *FN(PW,morph)(__isl_take PW *pw, __isl_take isl_morph *morph)
                pw->p[i].set = isl_morph_set(isl_morph_copy(morph), pw->p[i].set);
                if (!pw->p[i].set)
                        goto error;
-               pw->p[i].FIELD = FN(EL,morph)(pw->p[i].FIELD,
+               pw->p[i].FIELD = FN(EL,morph_domain)(pw->p[i].FIELD,
                                                isl_morph_copy(morph));
                if (!pw->p[i].FIELD)
                        goto error;
@@ -884,7 +1175,7 @@ static int foreach_lifted_subset(__isl_take isl_set *set, __isl_take EL *el,
                lift = isl_set_lift(lift);
 
                copy = FN(EL,copy)(el);
-               copy = FN(EL,lift)(copy, isl_set_get_dim(lift));
+               copy = FN(EL,lift)(copy, isl_set_get_space(lift));
 
                if (fn(lift, copy, user) < 0)
                        goto error;
@@ -939,91 +1230,32 @@ __isl_give PW *FN(PW,move_dims)(__isl_take PW *pw,
        if (!pw)
                return NULL;
 
-       pw->dim = isl_dim_move(pw->dim, dst_type, dst_pos, src_type, src_pos, n);
+       pw->dim = isl_space_move_dims(pw->dim, dst_type, dst_pos, src_type, src_pos, n);
        if (!pw->dim)
                goto error;
 
        for (i = 0; i < pw->n; ++i) {
-               pw->p[i].set = isl_set_move_dims(pw->p[i].set,
-                                               dst_type, dst_pos,
-                                               src_type, src_pos, n);
-               if (!pw->p[i].set)
-                       goto error;
                pw->p[i].FIELD = FN(EL,move_dims)(pw->p[i].FIELD,
                                        dst_type, dst_pos, src_type, src_pos, n);
                if (!pw->p[i].FIELD)
                        goto error;
        }
 
-       return pw;
-error:
-       FN(PW,free)(pw);
-       return NULL;
-}
-#endif
-
-#ifndef NO_REALIGN
-__isl_give PW *FN(PW,realign)(__isl_take PW *pw, __isl_take isl_reordering *exp)
-{
-       int i;
-
-       pw = FN(PW,cow)(pw);
-       if (!pw || !exp)
-               return NULL;
+       if (dst_type == isl_dim_in)
+               dst_type = isl_dim_set;
+       if (src_type == isl_dim_in)
+               src_type = isl_dim_set;
 
        for (i = 0; i < pw->n; ++i) {
-               pw->p[i].set = isl_set_realign(pw->p[i].set,
-                                                   isl_reordering_copy(exp));
+               pw->p[i].set = isl_set_move_dims(pw->p[i].set,
+                                               dst_type, dst_pos,
+                                               src_type, src_pos, n);
                if (!pw->p[i].set)
                        goto error;
-               pw->p[i].FIELD = FN(EL,realign)(pw->p[i].FIELD,
-                                                   isl_reordering_copy(exp));
-               if (!pw->p[i].FIELD)
-                       goto error;
-       }
-
-       pw = FN(PW,reset_dim)(pw, isl_dim_copy(exp->dim));
-
-       isl_reordering_free(exp);
-       return pw;
-error:
-       isl_reordering_free(exp);
-       FN(PW,free)(pw);
-       return NULL;
-}
-
-/* Align the parameters of "pw" to those of "model".
- */
-__isl_give PW *FN(PW,align_params)(__isl_take PW *pw, __isl_take isl_dim *model)
-{
-       isl_ctx *ctx;
-
-       if (!pw || !model)
-               goto error;
-
-       ctx = isl_dim_get_ctx(model);
-       if (!isl_dim_has_named_params(model))
-               isl_die(ctx, isl_error_invalid,
-                       "model has unnamed parameters", goto error);
-       if (!isl_dim_has_named_params(pw->dim))
-               isl_die(ctx, isl_error_invalid,
-                       "input has unnamed parameters", goto error);
-       if (!isl_dim_match(pw->dim, isl_dim_param, model, isl_dim_param)) {
-               isl_reordering *exp;
-
-               model = isl_dim_drop(model, isl_dim_in,
-                                       0, isl_dim_size(model, isl_dim_in));
-               model = isl_dim_drop(model, isl_dim_out,
-                                       0, isl_dim_size(model, isl_dim_out));
-               exp = isl_parameter_alignment_reordering(pw->dim, model);
-               exp = isl_reordering_extend_dim(exp, FN(PW,get_dim)(pw));
-               pw = FN(PW,realign)(pw, exp);
        }
 
-       isl_dim_free(model);
        return pw;
 error:
-       isl_dim_free(model);
        FN(PW,free)(pw);
        return NULL;
 }
@@ -1037,7 +1269,7 @@ __isl_give PW *FN(PW,mul_isl_int)(__isl_take PW *pw, isl_int v)
                return pw;
        if (pw && isl_int_is_zero(v)) {
                PW *zero;
-               isl_dim *dim = FN(PW,get_dim)(pw);
+               isl_space *dim = FN(PW,get_space)(pw);
 #ifdef HAS_TYPE
                zero = FN(PW,ZERO)(dim, pw->type);
 #else
index d31f277..2653fc4 100644 (file)
@@ -31,7 +31,7 @@ static int has_sign(__isl_keep isl_basic_set *bset,
        struct range_data data_m;
        unsigned nvar;
        unsigned nparam;
-       isl_dim *dim;
+       isl_space *dim;
        isl_qpolynomial *opt;
        int r;
        enum isl_fold type;
@@ -44,11 +44,13 @@ static int has_sign(__isl_keep isl_basic_set *bset,
 
        bset = isl_basic_set_move_dims(bset, isl_dim_set, 0,
                                        isl_dim_param, 0, nparam);
-       poly = isl_qpolynomial_move_dims(poly, isl_dim_set, 0,
+       poly = isl_qpolynomial_move_dims(poly, isl_dim_in, 0,
                                        isl_dim_param, 0, nparam);
 
-       dim = isl_qpolynomial_get_dim(poly);
-       dim = isl_dim_drop(dim, isl_dim_set, 0, isl_dim_size(dim, isl_dim_set));
+       dim = isl_qpolynomial_get_space(poly);
+       dim = isl_space_params(dim);
+       dim = isl_space_from_domain(dim);
+       dim = isl_space_add_dims(dim, isl_dim_out, 1);
 
        data_m.test_monotonicity = 0;
        data_m.signs = signs;
@@ -94,7 +96,7 @@ static int monotonicity(__isl_keep isl_basic_set *bset,
        __isl_keep isl_qpolynomial *poly, struct range_data *data)
 {
        isl_ctx *ctx;
-       isl_dim *dim;
+       isl_space *dim;
        isl_qpolynomial *sub = NULL;
        isl_qpolynomial *diff = NULL;
        int result = 0;
@@ -102,16 +104,16 @@ static int monotonicity(__isl_keep isl_basic_set *bset,
        unsigned nvar;
 
        ctx = isl_qpolynomial_get_ctx(poly);
-       dim = isl_qpolynomial_get_dim(poly);
+       dim = isl_qpolynomial_get_domain_space(poly);
 
        nvar = isl_basic_set_dim(bset, isl_dim_set);
 
-       sub = isl_qpolynomial_var(isl_dim_copy(dim), isl_dim_set, nvar - 1);
+       sub = isl_qpolynomial_var_on_domain(isl_space_copy(dim), isl_dim_set, nvar - 1);
        sub = isl_qpolynomial_add(sub,
-               isl_qpolynomial_rat_cst(dim, ctx->one, ctx->one));
+               isl_qpolynomial_rat_cst_on_domain(dim, ctx->one, ctx->one));
 
        diff = isl_qpolynomial_substitute(isl_qpolynomial_copy(poly),
-                       isl_dim_set, nvar - 1, 1, &sub);
+                       isl_dim_in, nvar - 1, 1, &sub);
        diff = isl_qpolynomial_sub(diff, isl_qpolynomial_copy(poly));
 
        s = has_sign(bset, diff, 1, data->signs);
@@ -138,15 +140,15 @@ error:
 }
 
 static __isl_give isl_qpolynomial *bound2poly(__isl_take isl_constraint *bound,
-       __isl_take isl_dim *dim, unsigned pos, int sign)
+       __isl_take isl_space *dim, unsigned pos, int sign)
 {
        if (!bound) {
                if (sign > 0)
-                       return isl_qpolynomial_infty(dim);
+                       return isl_qpolynomial_infty_on_domain(dim);
                else
-                       return isl_qpolynomial_neginfty(dim);
+                       return isl_qpolynomial_neginfty_on_domain(dim);
        }
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return isl_qpolynomial_from_constraint(bound, isl_dim_set, pos);
 }
 
@@ -229,8 +231,11 @@ static int collect_fixed_sign_terms(__isl_take isl_term *term, void *user)
 __isl_give isl_qpolynomial *isl_qpolynomial_terms_of_sign(
        __isl_keep isl_qpolynomial *poly, int *signs, int sign)
 {
+       isl_space *space;
        struct isl_fixed_sign_data data = { signs, sign };
-       data.poly = isl_qpolynomial_zero(isl_qpolynomial_get_dim(poly));
+
+       space = isl_qpolynomial_get_domain_space(poly);
+       data.poly = isl_qpolynomial_zero_on_domain(space);
 
        if (isl_qpolynomial_foreach_term(poly, collect_fixed_sign_terms, &data) < 0)
                goto error;
@@ -252,6 +257,9 @@ static int add_guarded_poly(__isl_take isl_basic_set *bset,
        isl_qpolynomial_fold *fold;
        isl_pw_qpolynomial_fold *pwf;
 
+       bset = isl_basic_set_params(bset);
+       poly = isl_qpolynomial_project_domain_on_params(poly);
+
        fold = isl_qpolynomial_fold_alloc(type, poly);
        set = isl_set_from_basic_set(bset);
        pwf = isl_pw_qpolynomial_fold_alloc(type, set, fold);
@@ -293,7 +301,7 @@ static int propagate_on_bound_pair(__isl_take isl_constraint *lower,
 
        if (data->monotonicity) {
                isl_qpolynomial *sub;
-               isl_dim *dim = isl_qpolynomial_get_dim(data->poly);
+               isl_space *dim = isl_qpolynomial_get_domain_space(data->poly);
                if (data->monotonicity * data->sign > 0) {
                        if (data->tight)
                                data->tight = bound_is_integer(upper, nvar);
@@ -306,30 +314,30 @@ static int propagate_on_bound_pair(__isl_take isl_constraint *lower,
                        isl_constraint_free(upper);
                }
                poly = isl_qpolynomial_copy(data->poly);
-               poly = isl_qpolynomial_substitute(poly, isl_dim_set, nvar, 1, &sub);
-               poly = isl_qpolynomial_drop_dims(poly, isl_dim_set, nvar, 1);
+               poly = isl_qpolynomial_substitute(poly, isl_dim_in, nvar, 1, &sub);
+               poly = isl_qpolynomial_drop_dims(poly, isl_dim_in, nvar, 1);
 
                isl_qpolynomial_free(sub);
        } else {
                isl_qpolynomial *l, *u;
                isl_qpolynomial *pos, *neg;
-               isl_dim *dim = isl_qpolynomial_get_dim(data->poly);
+               isl_space *dim = isl_qpolynomial_get_domain_space(data->poly);
                unsigned nparam = isl_basic_set_dim(bset, isl_dim_param);
                int sign = data->sign * data->signs[nparam + nvar];
 
                data->tight = 0;
 
-               u = bound2poly(upper, isl_dim_copy(dim), nvar, 1);
+               u = bound2poly(upper, isl_space_copy(dim), nvar, 1);
                l = bound2poly(lower, dim, nvar, -1);
 
                pos = isl_qpolynomial_terms_of_sign(data->poly, data->signs, sign);
                neg = isl_qpolynomial_terms_of_sign(data->poly, data->signs, -sign);
 
-               pos = isl_qpolynomial_substitute(pos, isl_dim_set, nvar, 1, &u);
-               neg = isl_qpolynomial_substitute(neg, isl_dim_set, nvar, 1, &l);
+               pos = isl_qpolynomial_substitute(pos, isl_dim_in, nvar, 1, &u);
+               neg = isl_qpolynomial_substitute(neg, isl_dim_in, nvar, 1, &l);
 
                poly = isl_qpolynomial_add(pos, neg);
-               poly = isl_qpolynomial_drop_dims(poly, isl_dim_set, nvar, 1);
+               poly = isl_qpolynomial_drop_dims(poly, isl_dim_in, nvar, 1);
 
                isl_qpolynomial_free(u);
                isl_qpolynomial_free(l);
@@ -365,7 +373,7 @@ static int propagate_on_domain(__isl_take isl_basic_set *bset,
 
        if (isl_qpolynomial_is_cst(poly, NULL, NULL)) {
                bset = isl_basic_set_project_out(bset, isl_dim_set, 0, d);
-               poly = isl_qpolynomial_drop_dims(poly, isl_dim_set, 0, d);
+               poly = isl_qpolynomial_drop_dims(poly, isl_dim_in, 0, d);
                return add_guarded_poly(bset, poly, data);
        }
 
index 392152f..d99d7ac 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #include <isl_ctx_private.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl_reordering.h>
 
 __isl_give isl_reordering *isl_reordering_alloc(isl_ctx *ctx, int len)
@@ -49,7 +49,7 @@ __isl_give isl_reordering *isl_reordering_dup(__isl_keep isl_reordering *r)
        if (!dup)
                return NULL;
 
-       dup->dim = isl_dim_copy(r->dim);
+       dup->dim = isl_space_copy(r->dim);
        if (!dup->dim)
                return isl_reordering_free(dup);
        for (i = 0; i < dup->len; ++i)
@@ -77,7 +77,7 @@ void *isl_reordering_free(__isl_take isl_reordering *exp)
        if (--exp->ref > 0)
                return NULL;
 
-       isl_dim_free(exp->dim);
+       isl_space_free(exp->dim);
        free(exp);
        return NULL;
 }
@@ -88,7 +88,7 @@ void *isl_reordering_free(__isl_take isl_reordering *exp)
  * any remaining parameters of "alignee" that do not occur in "aligner".
  */
 __isl_give isl_reordering *isl_parameter_alignment_reordering(
-       __isl_keep isl_dim *alignee, __isl_keep isl_dim *aligner)
+       __isl_keep isl_space *alignee, __isl_keep isl_space *aligner)
 {
        int i, j;
        isl_reordering *exp;
@@ -100,28 +100,30 @@ __isl_give isl_reordering *isl_parameter_alignment_reordering(
        if (!exp)
                return NULL;
 
-       exp->dim = isl_dim_copy(aligner);
+       exp->dim = isl_space_copy(aligner);
 
        for (i = 0; i < alignee->nparam; ++i) {
-               const char *name_i;
-               name_i = isl_dim_get_name(alignee, isl_dim_param, i);
-               if (!name_i)
+               isl_id *id_i;
+               id_i = isl_space_get_dim_id(alignee, isl_dim_param, i);
+               if (!id_i)
                        isl_die(alignee->ctx, isl_error_invalid,
                                "cannot align unnamed parameters", goto error);
                for (j = 0; j < aligner->nparam; ++j) {
-                       const char *name_j;
-                       name_j = isl_dim_get_name(aligner, isl_dim_param, j);
-                       if (name_i == name_j)
+                       isl_id *id_j;
+                       id_j = isl_space_get_dim_id(aligner, isl_dim_param, j);
+                       isl_id_free(id_j);
+                       if (id_i == id_j)
                                break;
                }
-               if (j < aligner->nparam)
+               if (j < aligner->nparam) {
                        exp->pos[i] = j;
-               else {
+                       isl_id_free(id_i);
+               } else {
                        int pos;
-                       pos = isl_dim_size(exp->dim, isl_dim_param);
-                       exp->dim = isl_dim_add(exp->dim, isl_dim_param, 1);
-                       exp->dim = isl_dim_set_name(exp->dim,
-                                               isl_dim_param, pos, name_i);
+                       pos = isl_space_dim(exp->dim, isl_dim_param);
+                       exp->dim = isl_space_add_dims(exp->dim, isl_dim_param, 1);
+                       exp->dim = isl_space_set_dim_id(exp->dim,
+                                               isl_dim_param, pos, id_i);
                        exp->pos[i] = pos;
                }
        }
@@ -144,11 +146,11 @@ __isl_give isl_reordering *isl_reordering_extend(__isl_take isl_reordering *exp,
        if (extra == 0)
                return exp;
 
-       offset = isl_dim_total(exp->dim) - exp->len;
+       offset = isl_space_dim(exp->dim, isl_dim_all) - exp->len;
        res = isl_reordering_alloc(exp->dim->ctx, exp->len + extra);
        if (!res)
                goto error;
-       res->dim = isl_dim_copy(exp->dim);
+       res->dim = isl_space_copy(exp->dim);
        for (i = 0; i < exp->len; ++i)
                res->pos[i] = exp->pos[i];
        for (i = exp->len; i < res->len; ++i)
@@ -162,8 +164,8 @@ error:
        return NULL;
 }
 
-__isl_give isl_reordering *isl_reordering_extend_dim(
-       __isl_take isl_reordering *exp, __isl_take isl_dim *dim)
+__isl_give isl_reordering *isl_reordering_extend_space(
+       __isl_take isl_reordering *exp, __isl_take isl_space *dim)
 {
        isl_reordering *res;
 
@@ -171,19 +173,19 @@ __isl_give isl_reordering *isl_reordering_extend_dim(
                goto error;
 
        res = isl_reordering_extend(isl_reordering_copy(exp),
-                                           isl_dim_total(dim) - exp->len);
+                                   isl_space_dim(dim, isl_dim_all) - exp->len);
        res = isl_reordering_cow(res);
        if (!res)
                goto error;
-       isl_dim_free(res->dim);
-       res->dim = isl_dim_replace(dim, isl_dim_param, exp->dim);
+       isl_space_free(res->dim);
+       res->dim = isl_space_replace(dim, isl_dim_param, exp->dim);
 
        isl_reordering_free(exp);
 
        return res;
 error:
        isl_reordering_free(exp);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
index 7560d3a..ac5b6fa 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef ISL_REORDERING_H
 #define ISL_REORDERING_H
 
-#include <isl/dim.h>
+#include <isl/space.h>
 
 /* pos maps original dimensions to new dimensions.
  * The final dimension is given by dim.
  */
 struct isl_reordering {
        int ref;
-       isl_dim *dim;
+       isl_space *dim;
        unsigned len;
        int pos[1];
 };
 typedef struct isl_reordering isl_reordering;
 
 __isl_give isl_reordering *isl_parameter_alignment_reordering(
-       __isl_keep isl_dim *alignee, __isl_keep isl_dim *aligner);
+       __isl_keep isl_space *alignee, __isl_keep isl_space *aligner);
 __isl_give isl_reordering *isl_reordering_copy(__isl_keep isl_reordering *exp);
 void *isl_reordering_free(__isl_take isl_reordering *exp);
-__isl_give isl_reordering *isl_reordering_extend_dim(
-       __isl_take isl_reordering *exp, __isl_take isl_dim *dim);
+__isl_give isl_reordering *isl_reordering_extend_space(
+       __isl_take isl_reordering *exp, __isl_take isl_space *dim);
 __isl_give isl_reordering *isl_reordering_extend(__isl_take isl_reordering *exp,
        unsigned extra);
 
index 9c9fb6d..c83fe57 100644 (file)
@@ -802,7 +802,7 @@ static struct isl_basic_set *shift_cone(struct isl_basic_set *cone,
 
        total = isl_basic_set_total_dim(cone);
 
-       shift = isl_basic_set_alloc_dim(isl_basic_set_get_dim(cone),
+       shift = isl_basic_set_alloc_space(isl_basic_set_get_space(cone),
                                        0, 0, cone->n_ineq);
 
        for (i = 0; i < cone->n_ineq; ++i) {
@@ -1321,9 +1321,9 @@ __isl_give isl_basic_set *isl_set_sample(__isl_take isl_set *set)
 __isl_give isl_point *isl_basic_set_sample_point(__isl_take isl_basic_set *bset)
 {
        isl_vec *vec;
-       isl_dim *dim;
+       isl_space *dim;
 
-       dim = isl_basic_set_get_dim(bset);
+       dim = isl_basic_set_get_space(bset);
        bset = isl_basic_set_underlying_set(bset);
        vec = isl_basic_set_sample_vec(bset);
 
@@ -1347,7 +1347,7 @@ __isl_give isl_point *isl_set_sample_point(__isl_take isl_set *set)
                isl_point_free(pnt);
        }
        if (i == set->n)
-               pnt = isl_point_void(isl_set_get_dim(set));
+               pnt = isl_point_void(isl_set_get_space(set));
 
        isl_set_free(set);
        return pnt;
index 320db6c..f14fbd9 100644 (file)
@@ -10,7 +10,7 @@
 
 #include <isl_ctx_private.h>
 #include <isl_map_private.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl/hash.h>
 #include <isl/constraint.h>
 #include <isl/schedule.h>
@@ -67,7 +67,7 @@
  * on_stack indicates whether the node is currently on the stack.
  */
 struct isl_sched_node {
-       isl_dim *dim;
+       isl_space *dim;
        isl_mat *sched;
        isl_map *sched_map;
        int      rank;
@@ -91,9 +91,9 @@ struct isl_sched_node {
 static int node_has_dim(const void *entry, const void *val)
 {
        struct isl_sched_node *node = (struct isl_sched_node *)entry;
-       isl_dim *dim = (isl_dim *)val;
+       isl_space *dim = (isl_space *)val;
 
-       return isl_dim_equal(node->dim, dim);
+       return isl_space_is_equal(node->dim, dim);
 }
 
 /* An edge in the dependence graph.  An edge may be used to
@@ -217,7 +217,7 @@ static int graph_init_table(isl_ctx *ctx, struct isl_sched_graph *graph)
                struct isl_hash_table_entry *entry;
                uint32_t hash;
 
-               hash = isl_dim_get_hash(graph->node[i].dim);
+               hash = isl_space_get_hash(graph->node[i].dim);
                entry = isl_hash_table_find(ctx, graph->node_table, hash,
                                            &node_has_dim,
                                            graph->node[i].dim, 1);
@@ -233,12 +233,12 @@ static int graph_init_table(isl_ctx *ctx, struct isl_sched_graph *graph)
  * or NULL if there is no such node.
  */
 static struct isl_sched_node *graph_find_node(isl_ctx *ctx,
-       struct isl_sched_graph *graph, __isl_keep isl_dim *dim)
+       struct isl_sched_graph *graph, __isl_keep isl_space *dim)
 {
        struct isl_hash_table_entry *entry;
        uint32_t hash;
 
-       hash = isl_dim_get_hash(dim);
+       hash = isl_space_get_hash(dim);
        entry = isl_hash_table_find(ctx, graph->node_table, hash,
                                    &node_has_dim, dim, 0);
 
@@ -291,7 +291,7 @@ static int graph_init_edge_table(isl_ctx *ctx, struct isl_sched_graph *graph)
 static int graph_has_edge(struct isl_sched_graph *graph,
        struct isl_sched_node *src, struct isl_sched_node *dst)
 {
-       isl_ctx *ctx = isl_dim_get_ctx(src->dim);
+       isl_ctx *ctx = isl_space_get_ctx(src->dim);
        struct isl_hash_table_entry *entry;
        uint32_t hash;
        struct isl_sched_edge temp = { .src = src, .dst = dst };
@@ -349,7 +349,7 @@ static void graph_free(isl_ctx *ctx, struct isl_sched_graph *graph)
        isl_hmap_map_basic_set_free(ctx, graph->inter_hmap);
 
        for (i = 0; i < graph->n; ++i) {
-               isl_dim_free(graph->node[i].dim);
+               isl_space_free(graph->node[i].dim);
                isl_mat_free(graph->node[i].sched);
                isl_map_free(graph->node[i].sched_map);
                isl_mat_free(graph->node[i].cmap);
@@ -377,16 +377,16 @@ static int extract_node(__isl_take isl_set *set, void *user)
 {
        int nvar, nparam;
        isl_ctx *ctx;
-       isl_dim *dim;
+       isl_space *dim;
        isl_mat *sched;
        struct isl_sched_graph *graph = user;
        int *band, *band_id, *zero;
 
        ctx = isl_set_get_ctx(set);
-       dim = isl_set_get_dim(set);
+       dim = isl_set_get_space(set);
        isl_set_free(set);
-       nvar = isl_dim_size(dim, isl_dim_set);
-       nparam = isl_dim_size(dim, isl_dim_param);
+       nvar = isl_space_dim(dim, isl_dim_set);
+       nparam = isl_space_dim(dim, isl_dim_param);
        if (!ctx->opt->schedule_parametric)
                nparam = 0;
        sched = isl_mat_alloc(ctx, 0, 1 + nparam + nvar);
@@ -423,14 +423,14 @@ static int extract_edge(__isl_take isl_map *map, void *user)
        isl_ctx *ctx = isl_map_get_ctx(map);
        struct isl_sched_graph *graph = user;
        struct isl_sched_node *src, *dst;
-       isl_dim *dim;
+       isl_space *dim;
 
-       dim = isl_dim_domain(isl_map_get_dim(map));
+       dim = isl_space_domain(isl_map_get_space(map));
        src = graph_find_node(ctx, graph, dim);
-       isl_dim_free(dim);
-       dim = isl_dim_range(isl_map_get_dim(map));
+       isl_space_free(dim);
+       dim = isl_space_range(isl_map_get_space(map));
        dst = graph_find_node(ctx, graph, dim);
-       isl_dim_free(dim);
+       isl_space_free(dim);
 
        if (!src || !dst) {
                isl_map_free(map);
@@ -674,31 +674,31 @@ static int add_intra_validity_constraints(struct isl_sched_graph *graph,
        unsigned total;
        isl_map *map = isl_map_copy(edge->map);
        isl_ctx *ctx = isl_map_get_ctx(map);
-       isl_dim *dim;
+       isl_space *dim;
        isl_dim_map *dim_map;
        isl_basic_set *coef;
        struct isl_sched_node *node = edge->src;
 
        coef = intra_coefficients(graph, map);
 
-       dim = isl_dim_domain(isl_dim_unwrap(isl_basic_set_get_dim(coef)));
+       dim = isl_space_domain(isl_space_unwrap(isl_basic_set_get_space(coef)));
 
        coef = isl_basic_set_transform_dims(coef, isl_dim_set,
-                   isl_dim_size(dim, isl_dim_set), isl_mat_copy(node->cmap));
+                   isl_space_dim(dim, isl_dim_set), isl_mat_copy(node->cmap));
 
        total = isl_basic_set_total_dim(graph->lp);
        dim_map = isl_dim_map_alloc(ctx, total);
        isl_dim_map_range(dim_map, node->start + 2 * node->nparam + 1, 2,
-                         isl_dim_size(dim, isl_dim_set), 1,
+                         isl_space_dim(dim, isl_dim_set), 1,
                          node->nvar, -1);
        isl_dim_map_range(dim_map, node->start + 2 * node->nparam + 2, 2,
-                         isl_dim_size(dim, isl_dim_set), 1,
+                         isl_space_dim(dim, isl_dim_set), 1,
                          node->nvar, 1);
        graph->lp = isl_basic_set_extend_constraints(graph->lp,
                        coef->n_eq, coef->n_ineq);
        graph->lp = isl_basic_set_add_constraints_dim_map(graph->lp,
                                                           coef, dim_map);
-       isl_dim_free(dim);
+       isl_space_free(dim);
 
        return 0;
 }
@@ -727,7 +727,7 @@ static int add_inter_validity_constraints(struct isl_sched_graph *graph,
        unsigned total;
        isl_map *map = isl_map_copy(edge->map);
        isl_ctx *ctx = isl_map_get_ctx(map);
-       isl_dim *dim;
+       isl_space *dim;
        isl_dim_map *dim_map;
        isl_basic_set *coef;
        struct isl_sched_node *src = edge->src;
@@ -735,12 +735,12 @@ static int add_inter_validity_constraints(struct isl_sched_graph *graph,
 
        coef = inter_coefficients(graph, map);
 
-       dim = isl_dim_domain(isl_dim_unwrap(isl_basic_set_get_dim(coef)));
+       dim = isl_space_domain(isl_space_unwrap(isl_basic_set_get_space(coef)));
 
        coef = isl_basic_set_transform_dims(coef, isl_dim_set,
-                   isl_dim_size(dim, isl_dim_set), isl_mat_copy(src->cmap));
+                   isl_space_dim(dim, isl_dim_set), isl_mat_copy(src->cmap));
        coef = isl_basic_set_transform_dims(coef, isl_dim_set,
-                   isl_dim_size(dim, isl_dim_set) + src->nvar,
+                   isl_space_dim(dim, isl_dim_set) + src->nvar,
                    isl_mat_copy(dst->cmap));
 
        total = isl_basic_set_total_dim(graph->lp);
@@ -750,20 +750,20 @@ static int add_inter_validity_constraints(struct isl_sched_graph *graph,
        isl_dim_map_range(dim_map, dst->start + 1, 2, 1, 1, dst->nparam, -1);
        isl_dim_map_range(dim_map, dst->start + 2, 2, 1, 1, dst->nparam, 1);
        isl_dim_map_range(dim_map, dst->start + 2 * dst->nparam + 1, 2,
-                         isl_dim_size(dim, isl_dim_set) + src->nvar, 1,
+                         isl_space_dim(dim, isl_dim_set) + src->nvar, 1,
                          dst->nvar, -1);
        isl_dim_map_range(dim_map, dst->start + 2 * dst->nparam + 2, 2,
-                         isl_dim_size(dim, isl_dim_set) + src->nvar, 1,
+                         isl_space_dim(dim, isl_dim_set) + src->nvar, 1,
                          dst->nvar, 1);
 
        isl_dim_map_range(dim_map, src->start, 0, 0, 0, 1, -1);
        isl_dim_map_range(dim_map, src->start + 1, 2, 1, 1, src->nparam, 1);
        isl_dim_map_range(dim_map, src->start + 2, 2, 1, 1, src->nparam, -1);
        isl_dim_map_range(dim_map, src->start + 2 * src->nparam + 1, 2,
-                         isl_dim_size(dim, isl_dim_set), 1,
+                         isl_space_dim(dim, isl_dim_set), 1,
                          src->nvar, 1);
        isl_dim_map_range(dim_map, src->start + 2 * src->nparam + 2, 2,
-                         isl_dim_size(dim, isl_dim_set), 1,
+                         isl_space_dim(dim, isl_dim_set), 1,
                          src->nvar, -1);
 
        edge->start = graph->lp->n_ineq;
@@ -771,7 +771,7 @@ static int add_inter_validity_constraints(struct isl_sched_graph *graph,
                        coef->n_eq, coef->n_ineq);
        graph->lp = isl_basic_set_add_constraints_dim_map(graph->lp,
                                                           coef, dim_map);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        edge->end = graph->lp->n_ineq;
 
        return 0;
@@ -813,35 +813,35 @@ static int add_intra_proximity_constraints(struct isl_sched_graph *graph,
        unsigned nparam;
        isl_map *map = isl_map_copy(edge->map);
        isl_ctx *ctx = isl_map_get_ctx(map);
-       isl_dim *dim;
+       isl_space *dim;
        isl_dim_map *dim_map;
        isl_basic_set *coef;
        struct isl_sched_node *node = edge->src;
 
        coef = intra_coefficients(graph, map);
 
-       dim = isl_dim_domain(isl_dim_unwrap(isl_basic_set_get_dim(coef)));
+       dim = isl_space_domain(isl_space_unwrap(isl_basic_set_get_space(coef)));
 
        coef = isl_basic_set_transform_dims(coef, isl_dim_set,
-                   isl_dim_size(dim, isl_dim_set), isl_mat_copy(node->cmap));
+                   isl_space_dim(dim, isl_dim_set), isl_mat_copy(node->cmap));
 
-       nparam = isl_dim_size(node->dim, isl_dim_param);
+       nparam = isl_space_dim(node->dim, isl_dim_param);
        total = isl_basic_set_total_dim(graph->lp);
        dim_map = isl_dim_map_alloc(ctx, total);
        isl_dim_map_range(dim_map, 1, 0, 0, 0, 1, 1);
        isl_dim_map_range(dim_map, 4, 2, 1, 1, nparam, -1);
        isl_dim_map_range(dim_map, 5, 2, 1, 1, nparam, 1);
        isl_dim_map_range(dim_map, node->start + 2 * node->nparam + 1, 2,
-                         isl_dim_size(dim, isl_dim_set), 1,
+                         isl_space_dim(dim, isl_dim_set), 1,
                          node->nvar, s);
        isl_dim_map_range(dim_map, node->start + 2 * node->nparam + 2, 2,
-                         isl_dim_size(dim, isl_dim_set), 1,
+                         isl_space_dim(dim, isl_dim_set), 1,
                          node->nvar, -s);
        graph->lp = isl_basic_set_extend_constraints(graph->lp,
                        coef->n_eq, coef->n_ineq);
        graph->lp = isl_basic_set_add_constraints_dim_map(graph->lp,
                                                           coef, dim_map);
-       isl_dim_free(dim);
+       isl_space_free(dim);
 
        return 0;
 }
@@ -888,7 +888,7 @@ static int add_inter_proximity_constraints(struct isl_sched_graph *graph,
        unsigned nparam;
        isl_map *map = isl_map_copy(edge->map);
        isl_ctx *ctx = isl_map_get_ctx(map);
-       isl_dim *dim;
+       isl_space *dim;
        isl_dim_map *dim_map;
        isl_basic_set *coef;
        struct isl_sched_node *src = edge->src;
@@ -896,15 +896,15 @@ static int add_inter_proximity_constraints(struct isl_sched_graph *graph,
 
        coef = inter_coefficients(graph, map);
 
-       dim = isl_dim_domain(isl_dim_unwrap(isl_basic_set_get_dim(coef)));
+       dim = isl_space_domain(isl_space_unwrap(isl_basic_set_get_space(coef)));
 
        coef = isl_basic_set_transform_dims(coef, isl_dim_set,
-                   isl_dim_size(dim, isl_dim_set), isl_mat_copy(src->cmap));
+                   isl_space_dim(dim, isl_dim_set), isl_mat_copy(src->cmap));
        coef = isl_basic_set_transform_dims(coef, isl_dim_set,
-                   isl_dim_size(dim, isl_dim_set) + src->nvar,
+                   isl_space_dim(dim, isl_dim_set) + src->nvar,
                    isl_mat_copy(dst->cmap));
 
-       nparam = isl_dim_size(src->dim, isl_dim_param);
+       nparam = isl_space_dim(src->dim, isl_dim_param);
        total = isl_basic_set_total_dim(graph->lp);
        dim_map = isl_dim_map_alloc(ctx, total);
 
@@ -916,27 +916,27 @@ static int add_inter_proximity_constraints(struct isl_sched_graph *graph,
        isl_dim_map_range(dim_map, dst->start + 1, 2, 1, 1, dst->nparam, s);
        isl_dim_map_range(dim_map, dst->start + 2, 2, 1, 1, dst->nparam, -s);
        isl_dim_map_range(dim_map, dst->start + 2 * dst->nparam + 1, 2,
-                         isl_dim_size(dim, isl_dim_set) + src->nvar, 1,
+                         isl_space_dim(dim, isl_dim_set) + src->nvar, 1,
                          dst->nvar, s);
        isl_dim_map_range(dim_map, dst->start + 2 * dst->nparam + 2, 2,
-                         isl_dim_size(dim, isl_dim_set) + src->nvar, 1,
+                         isl_space_dim(dim, isl_dim_set) + src->nvar, 1,
                          dst->nvar, -s);
 
        isl_dim_map_range(dim_map, src->start, 0, 0, 0, 1, s);
        isl_dim_map_range(dim_map, src->start + 1, 2, 1, 1, src->nparam, -s);
        isl_dim_map_range(dim_map, src->start + 2, 2, 1, 1, src->nparam, s);
        isl_dim_map_range(dim_map, src->start + 2 * src->nparam + 1, 2,
-                         isl_dim_size(dim, isl_dim_set), 1,
+                         isl_space_dim(dim, isl_dim_set), 1,
                          src->nvar, -s);
        isl_dim_map_range(dim_map, src->start + 2 * src->nparam + 2, 2,
-                         isl_dim_size(dim, isl_dim_set), 1,
+                         isl_space_dim(dim, isl_dim_set), 1,
                          src->nvar, s);
 
        graph->lp = isl_basic_set_extend_constraints(graph->lp,
                        coef->n_eq, coef->n_ineq);
        graph->lp = isl_basic_set_add_constraints_dim_map(graph->lp,
                                                           coef, dim_map);
-       isl_dim_free(dim);
+       isl_space_free(dim);
 
        return 0;
 }
@@ -1040,7 +1040,36 @@ static int node_update_cmap(struct isl_sched_node *node)
 }
 
 /* Count the number of equality and inequality constraints
- * that will be added.  If once is set, then we count
+ * that will be added for the given map.
+ * If once is set, then we count
+ * each edge exactly once.  Otherwise, we count as follows
+ * validity            -> 1 (>= 0)
+ * validity+proximity  -> 2 (>= 0 and upper bound)
+ * proximity           -> 2 (lower and upper bound)
+ */
+static int count_map_constraints(struct isl_sched_graph *graph,
+       struct isl_sched_edge *edge, __isl_take isl_map *map,
+       int *n_eq, int *n_ineq, int once)
+{
+       isl_basic_set *coef;
+       int f = once ? 1 : edge->proximity ? 2 : 1;
+
+       if (edge->src == edge->dst)
+               coef = intra_coefficients(graph, map);
+       else
+               coef = inter_coefficients(graph, map);
+       if (!coef)
+               return -1;
+       *n_eq += f * coef->n_eq;
+       *n_ineq += f * coef->n_ineq;
+       isl_basic_set_free(coef);
+
+       return 0;
+}
+
+/* Count the number of equality and inequality constraints
+ * that will be added to the main lp problem.
+ * If once is set, then we count
  * each edge exactly once.  Otherwise, we count as follows
  * validity            -> 1 (>= 0)
  * validity+proximity  -> 2 (>= 0 and upper bound)
@@ -1050,23 +1079,15 @@ static int count_constraints(struct isl_sched_graph *graph,
        int *n_eq, int *n_ineq, int once)
 {
        int i;
-       isl_basic_set *coef;
 
        *n_eq = *n_ineq = 0;
        for (i = 0; i < graph->n_edge; ++i) {
                struct isl_sched_edge *edge= &graph->edge[i];
                isl_map *map = isl_map_copy(edge->map);
-               int f = once ? 1 : edge->proximity ? 2 : 1;
 
-               if (edge->src == edge->dst)
-                       coef = intra_coefficients(graph, map);
-               else
-                       coef = inter_coefficients(graph, map);
-               if (!coef)
+               if (count_map_constraints(graph, edge, map,
+                                         n_eq, n_ineq, once) < 0)
                        return -1;
-               *n_eq += f * coef->n_eq;
-               *n_ineq += f * coef->n_ineq;
-               isl_basic_set_free(coef);
        }
 
        return 0;
@@ -1113,13 +1134,13 @@ static int setup_lp(isl_ctx *ctx, struct isl_sched_graph *graph,
        int k;
        unsigned nparam;
        unsigned total;
-       isl_dim *dim;
+       isl_space *dim;
        int parametric;
        int param_pos;
        int n_eq, n_ineq;
 
        parametric = ctx->opt->schedule_parametric;
-       nparam = isl_dim_size(graph->node[0].dim, isl_dim_param);
+       nparam = isl_space_dim(graph->node[0].dim, isl_dim_param);
        param_pos = 4;
        total = param_pos + 2 * nparam;
        for (i = 0; i < graph->n; ++i) {
@@ -1133,10 +1154,10 @@ static int setup_lp(isl_ctx *ctx, struct isl_sched_graph *graph,
        if (count_constraints(graph, &n_eq, &n_ineq, 0) < 0)
                return -1;
 
-       dim = isl_dim_set_alloc(ctx, 0, total);
+       dim = isl_space_set_alloc(ctx, 0, total);
        isl_basic_set_free(graph->lp);
        n_eq += 2 + parametric + force_zero;
-       graph->lp = isl_basic_set_alloc_dim(dim, 0, n_eq, n_ineq);
+       graph->lp = isl_basic_set_alloc_space(dim, 0, n_eq, n_ineq);
 
        k = isl_basic_set_alloc_equality(graph->lp);
        if (k < 0)
@@ -1366,7 +1387,7 @@ error:
 static __isl_give isl_map *node_extract_schedule(struct isl_sched_node *node)
 {
        int i, j;
-       isl_dim *dim;
+       isl_space *dim;
        isl_basic_map *bmap;
        isl_constraint *c;
        int nrow, ncol;
@@ -1377,14 +1398,14 @@ static __isl_give isl_map *node_extract_schedule(struct isl_sched_node *node)
 
        nrow = isl_mat_rows(node->sched);
        ncol = isl_mat_cols(node->sched) - 1;
-       dim = isl_dim_from_domain(isl_dim_copy(node->dim));
-       dim = isl_dim_add(dim, isl_dim_out, nrow);
-       bmap = isl_basic_map_universe(isl_dim_copy(dim));
+       dim = isl_space_from_domain(isl_space_copy(node->dim));
+       dim = isl_space_add_dims(dim, isl_dim_out, nrow);
+       bmap = isl_basic_map_universe(isl_space_copy(dim));
 
        isl_int_init(v);
 
        for (i = 0; i < nrow; ++i) {
-               c = isl_equality_alloc(isl_dim_copy(dim));
+               c = isl_equality_alloc(isl_space_copy(dim));
                isl_constraint_set_coefficient_si(c, isl_dim_out, i, -1);
                isl_mat_get_element(node->sched, i, 0, &v);
                isl_constraint_set_constant(c, v);
@@ -1402,7 +1423,7 @@ static __isl_give isl_map *node_extract_schedule(struct isl_sched_node *node)
 
        isl_int_clear(v);
 
-       isl_dim_free(dim);
+       isl_space_free(dim);
 
        node->sched_map = isl_map_from_basic_map(bmap);
        return isl_map_copy(node->sched_map);
@@ -1512,7 +1533,7 @@ static int sort_statements(isl_ctx *ctx, struct isl_sched_graph *graph)
  * in graph and with parameters specified by dim.
  */
 static __isl_give isl_schedule *extract_schedule(struct isl_sched_graph *graph,
-       __isl_take isl_dim *dim)
+       __isl_take isl_space *dim)
 {
        int i;
        isl_ctx *ctx;
@@ -1521,7 +1542,7 @@ static __isl_give isl_schedule *extract_schedule(struct isl_sched_graph *graph,
        if (!dim)
                return NULL;
 
-       ctx = isl_dim_get_ctx(dim);
+       ctx = isl_space_get_ctx(dim);
        sched = isl_calloc(ctx, struct isl_schedule,
                           sizeof(struct isl_schedule) +
                           (graph->n - 1) * sizeof(struct isl_schedule_node));
@@ -1567,7 +1588,7 @@ static __isl_give isl_schedule *extract_schedule(struct isl_sched_graph *graph,
 
        return sched;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_schedule_free(sched);
        return NULL;
 }
@@ -1584,7 +1605,7 @@ static int copy_nodes(struct isl_sched_graph *dst, struct isl_sched_graph *src,
        for (i = 0; i < src->n; ++i) {
                if (!node_pred(&src->node[i], data))
                        continue;
-               dst->node[dst->n].dim = isl_dim_copy(src->node[i].dim);
+               dst->node[dst->n].dim = isl_space_copy(src->node[i].dim);
                dst->node[dst->n].nvar = src->node[i].nvar;
                dst->node[dst->n].nparam = src->node[i].nparam;
                dst->node[dst->n].sched = isl_mat_copy(src->node[i].sched);
@@ -1898,9 +1919,10 @@ static int compute_next_band(isl_ctx *ctx, struct isl_sched_graph *graph)
        return compute_schedule(ctx, graph);
 }
 
-/* Add constraints to graph->lp that force the dependence of edge i
- * to be respected and attempt to carry it, where edge i is one from
- * a node j to itself.
+/* Add constraints to graph->lp that force the dependence "map" (which
+ * is part of the dependence relation of "edge")
+ * to be respected and attempt to carry it, where the edge is one from
+ * a node j to itself.  "pos" is the sequence number of the given map.
  * That is, add constraints that enforce
  *
  *     (c_j_0 + c_j_n n + c_j_x y) - (c_j_0 + c_j_n n + c_j_x x)
@@ -1912,42 +1934,42 @@ static int compute_next_band(isl_ctx *ctx, struct isl_sched_graph *graph)
  * with each coefficient in c_j_x represented as a pair of non-negative
  * coefficients.
  */
-static int add_intra_constraints(struct isl_sched_graph *graph, int i)
+static int add_intra_constraints(struct isl_sched_graph *graph,
+       struct isl_sched_edge *edge, __isl_take isl_map *map, int pos)
 {
        unsigned total;
-       struct isl_sched_edge *edge= &graph->edge[i];
-       isl_map *map = isl_map_copy(edge->map);
        isl_ctx *ctx = isl_map_get_ctx(map);
-       isl_dim *dim;
+       isl_space *dim;
        isl_dim_map *dim_map;
        isl_basic_set *coef;
        struct isl_sched_node *node = edge->src;
 
        coef = intra_coefficients(graph, map);
 
-       dim = isl_dim_domain(isl_dim_unwrap(isl_basic_set_get_dim(coef)));
+       dim = isl_space_domain(isl_space_unwrap(isl_basic_set_get_space(coef)));
 
        total = isl_basic_set_total_dim(graph->lp);
        dim_map = isl_dim_map_alloc(ctx, total);
-       isl_dim_map_range(dim_map, 3 + i, 0, 0, 0, 1, -1);
+       isl_dim_map_range(dim_map, 3 + pos, 0, 0, 0, 1, -1);
        isl_dim_map_range(dim_map, node->start + 2 * node->nparam + 1, 2,
-                         isl_dim_size(dim, isl_dim_set), 1,
+                         isl_space_dim(dim, isl_dim_set), 1,
                          node->nvar, -1);
        isl_dim_map_range(dim_map, node->start + 2 * node->nparam + 2, 2,
-                         isl_dim_size(dim, isl_dim_set), 1,
+                         isl_space_dim(dim, isl_dim_set), 1,
                          node->nvar, 1);
        graph->lp = isl_basic_set_extend_constraints(graph->lp,
                        coef->n_eq, coef->n_ineq);
        graph->lp = isl_basic_set_add_constraints_dim_map(graph->lp,
                                                           coef, dim_map);
-       isl_dim_free(dim);
+       isl_space_free(dim);
 
        return 0;
 }
 
-/* Add constraints to graph->lp that force the dependence of edge i
- * to be respected and attempt to carry it, where edge i is one from
- * node j to node k.
+/* Add constraints to graph->lp that force the dependence "map" (which
+ * is part of the dependence relation of "edge")
+ * to be respected and attempt to carry it, where the edge is one from
+ * node j to node k.  "pos" is the sequence number of the given map.
  * That is, add constraints that enforce
  *
  *     (c_k_0 + c_k_n n + c_k_x y) - (c_j_0 + c_j_n n + c_j_x x) >= e_i
@@ -1959,13 +1981,12 @@ static int add_intra_constraints(struct isl_sched_graph *graph, int i)
  * with each coefficient (except e_i, c_k_0 and c_j_0)
  * represented as a pair of non-negative coefficients.
  */
-static int add_inter_constraints(struct isl_sched_graph *graph, int i)
+static int add_inter_constraints(struct isl_sched_graph *graph,
+       struct isl_sched_edge *edge, __isl_take isl_map *map, int pos)
 {
        unsigned total;
-       struct isl_sched_edge *edge= &graph->edge[i];
-       isl_map *map = isl_map_copy(edge->map);
        isl_ctx *ctx = isl_map_get_ctx(map);
-       isl_dim *dim;
+       isl_space *dim;
        isl_dim_map *dim_map;
        isl_basic_set *coef;
        struct isl_sched_node *src = edge->src;
@@ -1973,38 +1994,38 @@ static int add_inter_constraints(struct isl_sched_graph *graph, int i)
 
        coef = inter_coefficients(graph, map);
 
-       dim = isl_dim_domain(isl_dim_unwrap(isl_basic_set_get_dim(coef)));
+       dim = isl_space_domain(isl_space_unwrap(isl_basic_set_get_space(coef)));
 
        total = isl_basic_set_total_dim(graph->lp);
        dim_map = isl_dim_map_alloc(ctx, total);
 
-       isl_dim_map_range(dim_map, 3 + i, 0, 0, 0, 1, -1);
+       isl_dim_map_range(dim_map, 3 + pos, 0, 0, 0, 1, -1);
 
        isl_dim_map_range(dim_map, dst->start, 0, 0, 0, 1, 1);
        isl_dim_map_range(dim_map, dst->start + 1, 2, 1, 1, dst->nparam, -1);
        isl_dim_map_range(dim_map, dst->start + 2, 2, 1, 1, dst->nparam, 1);
        isl_dim_map_range(dim_map, dst->start + 2 * dst->nparam + 1, 2,
-                         isl_dim_size(dim, isl_dim_set) + src->nvar, 1,
+                         isl_space_dim(dim, isl_dim_set) + src->nvar, 1,
                          dst->nvar, -1);
        isl_dim_map_range(dim_map, dst->start + 2 * dst->nparam + 2, 2,
-                         isl_dim_size(dim, isl_dim_set) + src->nvar, 1,
+                         isl_space_dim(dim, isl_dim_set) + src->nvar, 1,
                          dst->nvar, 1);
 
        isl_dim_map_range(dim_map, src->start, 0, 0, 0, 1, -1);
        isl_dim_map_range(dim_map, src->start + 1, 2, 1, 1, src->nparam, 1);
        isl_dim_map_range(dim_map, src->start + 2, 2, 1, 1, src->nparam, -1);
        isl_dim_map_range(dim_map, src->start + 2 * src->nparam + 1, 2,
-                         isl_dim_size(dim, isl_dim_set), 1,
+                         isl_space_dim(dim, isl_dim_set), 1,
                          src->nvar, 1);
        isl_dim_map_range(dim_map, src->start + 2 * src->nparam + 2, 2,
-                         isl_dim_size(dim, isl_dim_set), 1,
+                         isl_space_dim(dim, isl_dim_set), 1,
                          src->nvar, -1);
 
        graph->lp = isl_basic_set_extend_constraints(graph->lp,
                        coef->n_eq, coef->n_ineq);
        graph->lp = isl_basic_set_add_constraints_dim_map(graph->lp,
                                                           coef, dim_map);
-       isl_dim_free(dim);
+       isl_space_free(dim);
 
        return 0;
 }
@@ -2014,16 +2035,59 @@ static int add_inter_constraints(struct isl_sched_graph *graph, int i)
  */
 static int add_all_constraints(struct isl_sched_graph *graph)
 {
-       int i;
+       int i, j;
+       int pos;
 
+       pos = 0;
        for (i = 0; i < graph->n_edge; ++i) {
                struct isl_sched_edge *edge= &graph->edge[i];
-               if (edge->src == edge->dst &&
-                   add_intra_constraints(graph, i) < 0)
-                       return -1;
-               if (edge->src != edge->dst &&
-                   add_inter_constraints(graph, i) < 0)
-                       return -1;
+               for (j = 0; j < edge->map->n; ++j) {
+                       isl_basic_map *bmap;
+                       isl_map *map;
+
+                       bmap = isl_basic_map_copy(edge->map->p[j]);
+                       map = isl_map_from_basic_map(bmap);
+
+                       if (edge->src == edge->dst &&
+                           add_intra_constraints(graph, edge, map, pos) < 0)
+                               return -1;
+                       if (edge->src != edge->dst &&
+                           add_inter_constraints(graph, edge, map, pos) < 0)
+                               return -1;
+                       ++pos;
+               }
+       }
+
+       return 0;
+}
+
+/* Count the number of equality and inequality constraints
+ * that will be added to the carry_lp problem.
+ * If once is set, then we count
+ * each edge exactly once.  Otherwise, we count as follows
+ * validity            -> 1 (>= 0)
+ * validity+proximity  -> 2 (>= 0 and upper bound)
+ * proximity           -> 2 (lower and upper bound)
+ */
+static int count_all_constraints(struct isl_sched_graph *graph,
+       int *n_eq, int *n_ineq, int once)
+{
+       int i, j;
+
+       *n_eq = *n_ineq = 0;
+       for (i = 0; i < graph->n_edge; ++i) {
+               struct isl_sched_edge *edge= &graph->edge[i];
+               for (j = 0; j < edge->map->n; ++j) {
+                       isl_basic_map *bmap;
+                       isl_map *map;
+
+                       bmap = isl_basic_map_copy(edge->map->p[j]);
+                       map = isl_map_from_basic_map(bmap);
+
+                       if (count_map_constraints(graph, edge, map,
+                                                 n_eq, n_ineq, once) < 0)
+                                   return -1;
+               }
        }
 
        return 0;
@@ -2035,6 +2099,11 @@ static int add_all_constraints(struct isl_sched_graph *graph)
  * from below by e_i, with 0 <= e_i <= 1 and then maximize the sum
  * of all e_i's.  Dependence with e_i = 0 in the solution are simply
  * respected, while those with e_i > 0 (in practice e_i = 1) are carried.
+ * Note that if the dependence relation is a union of basic maps,
+ * then we have to consider each basic map individually as it may only
+ * be possible to carry the dependences expressed by some of those
+ * basic maps and not all off them.
+ * Below, we consider each of those basic maps as a separate "edge".
  *
  * All variables of the LP are non-negative.  The actual coefficients
  * may be negative, so each coefficient is represented as the difference
@@ -2060,34 +2129,39 @@ static int setup_carry_lp(isl_ctx *ctx, struct isl_sched_graph *graph)
 {
        int i, j;
        int k;
-       isl_dim *dim;
+       isl_space *dim;
        unsigned total;
        int n_eq, n_ineq;
+       int n_edge;
 
-       total = 3 + graph->n_edge;
+       n_edge = 0;
+       for (i = 0; i < graph->n_edge; ++i)
+               n_edge += graph->edge[i].map->n;
+
+       total = 3 + n_edge;
        for (i = 0; i < graph->n; ++i) {
                struct isl_sched_node *node = &graph->node[graph->sorted[i]];
                node->start = total;
                total += 1 + 2 * (node->nparam + node->nvar);
        }
 
-       if (count_constraints(graph, &n_eq, &n_ineq, 1) < 0)
+       if (count_all_constraints(graph, &n_eq, &n_ineq, 1) < 0)
                return -1;
 
-       dim = isl_dim_set_alloc(ctx, 0, total);
+       dim = isl_space_set_alloc(ctx, 0, total);
        isl_basic_set_free(graph->lp);
        n_eq += 3;
-       n_ineq += graph->n_edge;
-       graph->lp = isl_basic_set_alloc_dim(dim, 0, n_eq, n_ineq);
+       n_ineq += n_edge;
+       graph->lp = isl_basic_set_alloc_space(dim, 0, n_eq, n_ineq);
        graph->lp = isl_basic_set_set_rational(graph->lp);
 
        k = isl_basic_set_alloc_equality(graph->lp);
        if (k < 0)
                return -1;
        isl_seq_clr(graph->lp->eq[k], 1 +  total);
-       isl_int_set_si(graph->lp->eq[k][0], -graph->n_edge);
+       isl_int_set_si(graph->lp->eq[k][0], -n_edge);
        isl_int_set_si(graph->lp->eq[k][1], 1);
-       for (i = 0; i < graph->n_edge; ++i)
+       for (i = 0; i < n_edge; ++i)
                isl_int_set_si(graph->lp->eq[k][4 + i], 1);
 
        k = isl_basic_set_alloc_equality(graph->lp);
@@ -2115,7 +2189,7 @@ static int setup_carry_lp(isl_ctx *ctx, struct isl_sched_graph *graph)
                        isl_int_set_si(graph->lp->eq[k][pos + j], 1);
        }
 
-       for (i = 0; i < graph->n_edge; ++i) {
+       for (i = 0; i < n_edge; ++i) {
                k = isl_basic_set_alloc_inequality(graph->lp);
                if (k < 0)
                        return -1;
@@ -2194,9 +2268,15 @@ static int split_parallel(isl_ctx *ctx, struct isl_sched_graph *graph)
  */
 static int carry_dependences(isl_ctx *ctx, struct isl_sched_graph *graph)
 {
+       int i;
+       int n_edge;
        isl_vec *sol;
        isl_basic_set *lp;
 
+       n_edge = 0;
+       for (i = 0; i < graph->n_edge; ++i)
+               n_edge += graph->edge[i].map->n;
+
        if (setup_carry_lp(ctx, graph) < 0)
                return -1;
 
@@ -2211,7 +2291,7 @@ static int carry_dependences(isl_ctx *ctx, struct isl_sched_graph *graph)
                        "error in schedule construction", return -1);
        }
 
-       if (isl_int_cmp_si(sol->el[1], graph->n_edge) >= 0) {
+       if (isl_int_cmp_si(sol->el[1], n_edge) >= 0) {
                isl_vec_free(sol);
                isl_die(ctx, isl_error_unknown,
                        "unable to carry dependences", return -1);
@@ -2366,16 +2446,16 @@ __isl_give isl_schedule *isl_union_set_compute_schedule(
        __isl_take isl_union_map *proximity)
 {
        isl_ctx *ctx = isl_union_set_get_ctx(domain);
-       isl_dim *dim;
+       isl_space *dim;
        struct isl_sched_graph graph = { 0 };
        isl_schedule *sched;
 
        domain = isl_union_set_align_params(domain,
-                                           isl_union_map_get_dim(validity));
+                                           isl_union_map_get_space(validity));
        domain = isl_union_set_align_params(domain,
-                                           isl_union_map_get_dim(proximity));
-       dim = isl_union_set_get_dim(domain);
-       validity = isl_union_map_align_params(validity, isl_dim_copy(dim));
+                                           isl_union_map_get_space(proximity));
+       dim = isl_union_set_get_space(domain);
+       validity = isl_union_map_align_params(validity, isl_space_copy(dim));
        proximity = isl_union_map_align_params(proximity, dim);
 
        if (!domain)
@@ -2405,7 +2485,7 @@ __isl_give isl_schedule *isl_union_set_compute_schedule(
                goto error;
 
 empty:
-       sched = extract_schedule(&graph, isl_union_set_get_dim(domain));
+       sched = extract_schedule(&graph, isl_union_set_get_space(domain));
 
        graph_free(ctx, &graph);
        isl_union_set_free(domain);
@@ -2436,7 +2516,7 @@ void *isl_schedule_free(__isl_take isl_schedule *sched)
                free(sched->node[i].band_id);
                free(sched->node[i].zero);
        }
-       isl_dim_free(sched->dim);
+       isl_space_free(sched->dim);
        isl_band_list_free(sched->band_forest);
        free(sched);
        return NULL;
@@ -2444,7 +2524,7 @@ void *isl_schedule_free(__isl_take isl_schedule *sched)
 
 isl_ctx *isl_schedule_get_ctx(__isl_keep isl_schedule *schedule)
 {
-       return schedule ? isl_dim_get_ctx(schedule->dim) : NULL;
+       return schedule ? isl_space_get_ctx(schedule->dim) : NULL;
 }
 
 __isl_give isl_union_map *isl_schedule_get_map(__isl_keep isl_schedule *sched)
@@ -2455,7 +2535,7 @@ __isl_give isl_union_map *isl_schedule_get_map(__isl_keep isl_schedule *sched)
        if (!sched)
                return NULL;
 
-       umap = isl_union_map_empty(isl_dim_copy(sched->dim));
+       umap = isl_union_map_empty(isl_space_copy(sched->dim));
        for (i = 0; i < sched->n; ++i)
                umap = isl_union_map_add_map(umap,
                                            isl_map_copy(sched->node[i].sched));
@@ -2524,7 +2604,7 @@ static __isl_give isl_band *construct_band(__isl_keep isl_schedule *schedule,
        for (j = 0; j < band->n; ++j)
                band->zero[j] = schedule->node[i].zero[start + j];
 
-       band->map = isl_union_map_empty(isl_dim_copy(schedule->dim));
+       band->map = isl_union_map_empty(isl_space_copy(schedule->dim));
        for (i = 0; i < schedule->n; ++i) {
                isl_map *map;
                unsigned n_out;
index f5cf7d9..cbf1f9c 100644 (file)
@@ -34,7 +34,7 @@ struct isl_schedule {
        int n;
        int n_band;
        int n_total_row;
-       isl_dim *dim;
+       isl_space *dim;
 
        isl_band_list *band_forest;
 
diff --git a/isl_space.c b/isl_space.c
new file mode 100644 (file)
index 0000000..7bac578
--- /dev/null
@@ -0,0 +1,1649 @@
+/*
+ * Copyright 2008-2009 Katholieke Universiteit Leuven
+ * Copyright 2010      INRIA Saclay
+ *
+ * Use of this software is governed by the GNU LGPLv2.1 license
+ *
+ * Written by Sven Verdoolaege, K.U.Leuven, Departement
+ * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
+ * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
+ * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France 
+ */
+
+#include <stdlib.h>
+#include <isl_space_private.h>
+#include <isl_id_private.h>
+#include <isl_reordering.h>
+
+isl_ctx *isl_space_get_ctx(__isl_keep isl_space *dim)
+{
+       return dim ? dim->ctx : NULL;
+}
+
+__isl_give isl_space *isl_space_alloc(isl_ctx *ctx,
+                       unsigned nparam, unsigned n_in, unsigned n_out)
+{
+       isl_space *dim;
+
+       dim = isl_alloc_type(ctx, struct isl_space);
+       if (!dim)
+               return NULL;
+
+       dim->ctx = ctx;
+       isl_ctx_ref(ctx);
+       dim->ref = 1;
+       dim->nparam = nparam;
+       dim->n_in = n_in;
+       dim->n_out = n_out;
+
+       dim->tuple_id[0] = NULL;
+       dim->tuple_id[1] = NULL;
+
+       dim->nested[0] = NULL;
+       dim->nested[1] = NULL;
+
+       dim->n_id = 0;
+       dim->ids = NULL;
+
+       return dim;
+}
+
+/* Mark the space as being that of a set, by setting the domain tuple
+ * to isl_id_none.
+ */
+static __isl_give isl_space *mark_as_set(__isl_take isl_space *space)
+{
+       space = isl_space_cow(space);
+       if (!space)
+               return NULL;
+       space = isl_space_set_tuple_id(space, isl_dim_in, &isl_id_none);
+       return space;
+}
+
+/* Is the space that of a set?
+ */
+int isl_space_is_set(__isl_keep isl_space *space)
+{
+       if (!space)
+               return -1;
+       if (space->n_in != 0 || space->nested[0])
+               return 0;
+       if (space->tuple_id[0] != &isl_id_none)
+               return 0;
+       return 1;
+}
+
+__isl_give isl_space *isl_space_set_alloc(isl_ctx *ctx,
+                       unsigned nparam, unsigned dim)
+{
+       isl_space *space;
+       space = isl_space_alloc(ctx, nparam, 0, dim);
+       space = mark_as_set(space);
+       return space;
+}
+
+/* Mark the space as being that of a parameter domain, by setting
+ * both tuples to isl_id_none.
+ */
+static __isl_give isl_space *mark_as_params(isl_space *space)
+{
+       if (!space)
+               return NULL;
+       space = isl_space_set_tuple_id(space, isl_dim_in, &isl_id_none);
+       space = isl_space_set_tuple_id(space, isl_dim_out, &isl_id_none);
+       return space;
+}
+
+/* Is the space that of a parameter domain?
+ */
+int isl_space_is_params(__isl_keep isl_space *space)
+{
+       if (!space)
+               return -1;
+       if (space->n_in != 0 || space->nested[0] ||
+           space->n_out != 0 || space->nested[1])
+               return 0;
+       if (space->tuple_id[0] != &isl_id_none)
+               return 0;
+       if (space->tuple_id[1] != &isl_id_none)
+               return 0;
+       return 1;
+}
+
+/* Create a space for a parameter domain.
+ */
+__isl_give isl_space *isl_space_params_alloc(isl_ctx *ctx, unsigned nparam)
+{
+       isl_space *space;
+       space = isl_space_alloc(ctx, nparam, 0, 0);
+       space = mark_as_params(space);
+       return space;
+}
+
+static unsigned global_pos(__isl_keep isl_space *dim,
+                                enum isl_dim_type type, unsigned pos)
+{
+       struct isl_ctx *ctx = dim->ctx;
+
+       switch (type) {
+       case isl_dim_param:
+               isl_assert(ctx, pos < dim->nparam,
+                           return isl_space_dim(dim, isl_dim_all));
+               return pos;
+       case isl_dim_in:
+               isl_assert(ctx, pos < dim->n_in,
+                           return isl_space_dim(dim, isl_dim_all));
+               return pos + dim->nparam;
+       case isl_dim_out:
+               isl_assert(ctx, pos < dim->n_out,
+                           return isl_space_dim(dim, isl_dim_all));
+               return pos + dim->nparam + dim->n_in;
+       default:
+               isl_assert(ctx, 0, return isl_space_dim(dim, isl_dim_all));
+       }
+       return isl_space_dim(dim, isl_dim_all);
+}
+
+/* Extend length of ids array to the total number of dimensions.
+ */
+static __isl_give isl_space *extend_ids(__isl_take isl_space *dim)
+{
+       isl_id **ids;
+       int i;
+
+       if (isl_space_dim(dim, isl_dim_all) <= dim->n_id)
+               return dim;
+
+       if (!dim->ids) {
+               dim->ids = isl_calloc_array(dim->ctx,
+                               isl_id *, isl_space_dim(dim, isl_dim_all));
+               if (!dim->ids)
+                       goto error;
+       } else {
+               ids = isl_realloc_array(dim->ctx, dim->ids,
+                               isl_id *, isl_space_dim(dim, isl_dim_all));
+               if (!ids)
+                       goto error;
+               dim->ids = ids;
+               for (i = dim->n_id; i < isl_space_dim(dim, isl_dim_all); ++i)
+                       dim->ids[i] = NULL;
+       }
+
+       dim->n_id = isl_space_dim(dim, isl_dim_all);
+
+       return dim;
+error:
+       isl_space_free(dim);
+       return NULL;
+}
+
+static __isl_give isl_space *set_id(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
+{
+       dim = isl_space_cow(dim);
+
+       if (!dim)
+               goto error;
+
+       pos = global_pos(dim, type, pos);
+       if (pos == isl_space_dim(dim, isl_dim_all))
+               goto error;
+
+       if (pos >= dim->n_id) {
+               if (!id)
+                       return dim;
+               dim = extend_ids(dim);
+               if (!dim)
+                       goto error;
+       }
+
+       dim->ids[pos] = id;
+
+       return dim;
+error:
+       isl_id_free(id);
+       isl_space_free(dim);
+       return NULL;
+}
+
+static __isl_keep isl_id *get_id(__isl_keep isl_space *dim,
+                                enum isl_dim_type type, unsigned pos)
+{
+       if (!dim)
+               return NULL;
+
+       pos = global_pos(dim, type, pos);
+       if (pos == isl_space_dim(dim, isl_dim_all))
+               return NULL;
+       if (pos >= dim->n_id)
+               return NULL;
+       return dim->ids[pos];
+}
+
+static unsigned offset(__isl_keep isl_space *dim, enum isl_dim_type type)
+{
+       switch (type) {
+       case isl_dim_param:     return 0;
+       case isl_dim_in:        return dim->nparam;
+       case isl_dim_out:       return dim->nparam + dim->n_in;
+       default:                return 0;
+       }
+}
+
+static unsigned n(__isl_keep isl_space *dim, enum isl_dim_type type)
+{
+       switch (type) {
+       case isl_dim_param:     return dim->nparam;
+       case isl_dim_in:        return dim->n_in;
+       case isl_dim_out:       return dim->n_out;
+       case isl_dim_all:       return dim->nparam + dim->n_in + dim->n_out;
+       default:                return 0;
+       }
+}
+
+unsigned isl_space_dim(__isl_keep isl_space *dim, enum isl_dim_type type)
+{
+       if (!dim)
+               return 0;
+       return n(dim, type);
+}
+
+unsigned isl_space_offset(__isl_keep isl_space *dim, enum isl_dim_type type)
+{
+       if (!dim)
+               return 0;
+       return offset(dim, type);
+}
+
+static __isl_give isl_space *copy_ids(__isl_take isl_space *dst,
+       enum isl_dim_type dst_type, unsigned offset, __isl_keep isl_space *src,
+       enum isl_dim_type src_type)
+{
+       int i;
+       isl_id *id;
+
+       if (!dst)
+               return NULL;
+
+       for (i = 0; i < n(src, src_type); ++i) {
+               id = get_id(src, src_type, i);
+               if (!id)
+                       continue;
+               dst = set_id(dst, dst_type, offset + i, isl_id_copy(id));
+               if (!dst)
+                       return NULL;
+       }
+       return dst;
+}
+
+__isl_take isl_space *isl_space_dup(__isl_keep isl_space *dim)
+{
+       isl_space *dup;
+       if (!dim)
+               return NULL;
+       dup = isl_space_alloc(dim->ctx, dim->nparam, dim->n_in, dim->n_out);
+       if (dim->tuple_id[0] &&
+           !(dup->tuple_id[0] = isl_id_copy(dim->tuple_id[0])))
+               goto error;
+       if (dim->tuple_id[1] &&
+           !(dup->tuple_id[1] = isl_id_copy(dim->tuple_id[1])))
+               goto error;
+       if (dim->nested[0] && !(dup->nested[0] = isl_space_copy(dim->nested[0])))
+               goto error;
+       if (dim->nested[1] && !(dup->nested[1] = isl_space_copy(dim->nested[1])))
+               goto error;
+       if (!dim->ids)
+               return dup;
+       dup = copy_ids(dup, isl_dim_param, 0, dim, isl_dim_param);
+       dup = copy_ids(dup, isl_dim_in, 0, dim, isl_dim_in);
+       dup = copy_ids(dup, isl_dim_out, 0, dim, isl_dim_out);
+       return dup;
+error:
+       isl_space_free(dup);
+       return NULL;
+}
+
+__isl_give isl_space *isl_space_cow(__isl_take isl_space *dim)
+{
+       if (!dim)
+               return NULL;
+
+       if (dim->ref == 1)
+               return dim;
+       dim->ref--;
+       return isl_space_dup(dim);
+}
+
+__isl_give isl_space *isl_space_copy(__isl_keep isl_space *dim)
+{
+       if (!dim)
+               return NULL;
+
+       dim->ref++;
+       return dim;
+}
+
+void isl_space_free(__isl_take isl_space *dim)
+{
+       int i;
+
+       if (!dim)
+               return;
+
+       if (--dim->ref > 0)
+               return;
+
+       isl_id_free(dim->tuple_id[0]);
+       isl_id_free(dim->tuple_id[1]);
+
+       isl_space_free(dim->nested[0]);
+       isl_space_free(dim->nested[1]);
+
+       for (i = 0; i < dim->n_id; ++i)
+               isl_id_free(dim->ids[i]);
+       free(dim->ids);
+       isl_ctx_deref(dim->ctx);
+       
+       free(dim);
+}
+
+static int name_ok(isl_ctx *ctx, const char *s)
+{
+       char *p;
+       long dummy;
+
+       dummy = strtol(s, &p, 0);
+       if (p != s)
+               isl_die(ctx, isl_error_invalid, "name looks like a number",
+                       return 0);
+
+       return 1;
+}
+
+int isl_space_has_tuple_id(__isl_keep isl_space *dim, enum isl_dim_type type)
+{
+       if (!dim)
+               return -1;
+       if (isl_space_is_params(dim))
+               isl_die(dim->ctx, isl_error_invalid,
+                       "parameter spaces don't have tuple ids", return -1);
+       if (isl_space_is_set(dim) && type != isl_dim_set)
+               isl_die(dim->ctx, isl_error_invalid,
+                       "set spaces can only have a set id", return -1);
+       if (type != isl_dim_in && type != isl_dim_out)
+               isl_die(dim->ctx, isl_error_invalid,
+                       "only input, output and set tuples can have ids",
+                       return -1);
+       return dim->tuple_id[type - isl_dim_in] != NULL;
+}
+
+__isl_give isl_id *isl_space_get_tuple_id(__isl_keep isl_space *dim,
+       enum isl_dim_type type)
+{
+       int has_id;
+
+       if (!dim)
+               return NULL;
+       has_id = isl_space_has_tuple_id(dim, type);
+       if (has_id < 0)
+               return NULL;
+       if (!has_id)
+               isl_die(dim->ctx, isl_error_invalid,
+                       "tuple has no id", return NULL);
+       return isl_id_copy(dim->tuple_id[type - isl_dim_in]);
+}
+
+__isl_give isl_space *isl_space_set_tuple_id(__isl_take isl_space *dim,
+       enum isl_dim_type type, __isl_take isl_id *id)
+{
+       dim = isl_space_cow(dim);
+       if (!dim || !id)
+               goto error;
+       if (type != isl_dim_in && type != isl_dim_out)
+               isl_die(dim->ctx, isl_error_invalid,
+                       "only input, output and set tuples can have names",
+                       goto error);
+
+       isl_id_free(dim->tuple_id[type - isl_dim_in]);
+       dim->tuple_id[type - isl_dim_in] = id;
+
+       return dim;
+error:
+       isl_id_free(id);
+       isl_space_free(dim);
+       return NULL;
+}
+
+__isl_give isl_space *isl_space_reset_tuple_id(__isl_take isl_space *dim,
+       enum isl_dim_type type)
+{
+       dim = isl_space_cow(dim);
+       if (!dim)
+               return NULL;
+       if (type != isl_dim_in && type != isl_dim_out)
+               isl_die(dim->ctx, isl_error_invalid,
+                       "only input, output and set tuples can have names",
+                       goto error);
+
+       isl_id_free(dim->tuple_id[type - isl_dim_in]);
+       dim->tuple_id[type - isl_dim_in] = NULL;
+
+       return dim;
+error:
+       isl_space_free(dim);
+       return NULL;
+}
+
+__isl_give isl_space *isl_space_set_dim_id(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
+{
+       dim = isl_space_cow(dim);
+       if (!dim || !id)
+               goto error;
+       isl_id_free(get_id(dim, type, pos));
+       return set_id(dim, type, pos, id);
+error:
+       isl_id_free(id);
+       isl_space_free(dim);
+       return NULL;
+}
+
+int isl_space_has_dim_id(__isl_keep isl_space *dim,
+       enum isl_dim_type type, unsigned pos)
+{
+       if (!dim)
+               return -1;
+       return get_id(dim, type, pos) != NULL;
+}
+
+__isl_give isl_id *isl_space_get_dim_id(__isl_keep isl_space *dim,
+       enum isl_dim_type type, unsigned pos)
+{
+       if (!dim)
+               return NULL;
+       if (!get_id(dim, type, pos))
+               isl_die(dim->ctx, isl_error_invalid,
+                       "dim has no id", return NULL);
+       return isl_id_copy(get_id(dim, type, pos));
+}
+
+__isl_give isl_space *isl_space_set_tuple_name(__isl_take isl_space *dim,
+       enum isl_dim_type type, const char *s)
+{
+       isl_id *id;
+
+       if (!dim)
+               return NULL;
+
+       if (!s)
+               return isl_space_reset_tuple_id(dim, type);
+
+       if (!name_ok(dim->ctx, s))
+               goto error;
+
+       id = isl_id_alloc(dim->ctx, s, NULL);
+       return isl_space_set_tuple_id(dim, type, id);
+error:
+       isl_space_free(dim);
+       return NULL;
+}
+
+const char *isl_space_get_tuple_name(__isl_keep isl_space *dim,
+        enum isl_dim_type type)
+{
+       isl_id *id;
+       if (!dim)
+               return NULL;
+       if (type != isl_dim_in && type != isl_dim_out)
+               return NULL;
+       id = dim->tuple_id[type - isl_dim_in];
+       return id ? id->name : NULL;
+}
+
+__isl_give isl_space *isl_space_set_dim_name(__isl_take isl_space *dim,
+                                enum isl_dim_type type, unsigned pos,
+                                const char *s)
+{
+       isl_id *id;
+
+       if (!dim)
+               return NULL;
+       if (!name_ok(dim->ctx, s))
+               goto error;
+       id = isl_id_alloc(dim->ctx, s, NULL);
+       return isl_space_set_dim_id(dim, type, pos, id);
+error:
+       isl_space_free(dim);
+       return NULL;
+}
+
+__isl_keep const char *isl_space_get_dim_name(__isl_keep isl_space *dim,
+                                enum isl_dim_type type, unsigned pos)
+{
+       isl_id *id = get_id(dim, type, pos);
+       return id ? id->name : NULL;
+}
+
+int isl_space_find_dim_by_id(__isl_keep isl_space *dim, enum isl_dim_type type,
+       __isl_keep isl_id *id)
+{
+       int i;
+       int offset;
+       int n;
+
+       if (!dim || !id)
+               return -1;
+
+       offset = isl_space_offset(dim, type);
+       n = isl_space_dim(dim, type);
+       for (i = 0; i < n && offset + i < dim->n_id; ++i)
+               if (dim->ids[offset + i] == id)
+                       return i;
+
+       return -1;
+}
+
+static __isl_keep isl_id *tuple_id(__isl_keep isl_space *dim,
+       enum isl_dim_type type)
+{
+       if (!dim)
+               return NULL;
+       if (type == isl_dim_in)
+               return dim->tuple_id[0];
+       if (type == isl_dim_out)
+               return dim->tuple_id[1];
+       return NULL;
+}
+
+static __isl_keep isl_space *nested(__isl_keep isl_space *dim,
+       enum isl_dim_type type)
+{
+       if (!dim)
+               return NULL;
+       if (type == isl_dim_in)
+               return dim->nested[0];
+       if (type == isl_dim_out)
+               return dim->nested[1];
+       return NULL;
+}
+
+int isl_space_tuple_match(__isl_keep isl_space *dim1, enum isl_dim_type dim1_type,
+                       __isl_keep isl_space *dim2, enum isl_dim_type dim2_type)
+{
+       isl_id *id1, *id2;
+       isl_space *nested1, *nested2;
+
+       if (!dim1 || !dim2)
+               return -1;
+
+       if (dim1 == dim2 && dim1_type == dim2_type)
+               return 1;
+
+       if (n(dim1, dim1_type) != n(dim2, dim2_type))
+               return 0;
+       id1 = tuple_id(dim1, dim1_type);
+       id2 = tuple_id(dim2, dim2_type);
+       if (!id1 ^ !id2)
+               return 0;
+       if (id1 && id1 != id2)
+               return 0;
+       nested1 = nested(dim1, dim1_type);
+       nested2 = nested(dim2, dim2_type);
+       if (!nested1 ^ !nested2)
+               return 0;
+       if (nested1 && !isl_space_is_equal(nested1, nested2))
+               return 0;
+       return 1;
+}
+
+static int match(__isl_keep isl_space *dim1, enum isl_dim_type dim1_type,
+       __isl_keep isl_space *dim2, enum isl_dim_type dim2_type)
+{
+       int i;
+
+       if (dim1 == dim2 && dim1_type == dim2_type)
+               return 1;
+
+       if (!isl_space_tuple_match(dim1, dim1_type, dim2, dim2_type))
+               return 0;
+
+       if (!dim1->ids && !dim2->ids)
+               return 1;
+
+       for (i = 0; i < n(dim1, dim1_type); ++i) {
+               if (get_id(dim1, dim1_type, i) != get_id(dim2, dim2_type, i))
+                       return 0;
+       }
+       return 1;
+}
+
+int isl_space_match(__isl_keep isl_space *dim1, enum isl_dim_type dim1_type,
+       __isl_keep isl_space *dim2, enum isl_dim_type dim2_type)
+{
+       if (!dim1 || !dim2)
+               return -1;
+
+       return match(dim1, dim1_type, dim2, dim2_type);
+}
+
+static void get_ids(__isl_keep isl_space *dim, enum isl_dim_type type,
+       unsigned first, unsigned n, __isl_keep isl_id **ids)
+{
+       int i;
+
+       for (i = 0; i < n ; ++i)
+               ids[i] = get_id(dim, type, first + i);
+}
+
+__isl_give isl_space *isl_space_extend(__isl_take isl_space *dim,
+                       unsigned nparam, unsigned n_in, unsigned n_out)
+{
+       isl_id **ids = NULL;
+
+       if (!dim)
+               return NULL;
+       if (dim->nparam == nparam && dim->n_in == n_in && dim->n_out == n_out)
+               return dim;
+
+       isl_assert(dim->ctx, dim->nparam <= nparam, goto error);
+       isl_assert(dim->ctx, dim->n_in <= n_in, goto error);
+       isl_assert(dim->ctx, dim->n_out <= n_out, goto error);
+
+       dim = isl_space_cow(dim);
+
+       if (dim->ids) {
+               ids = isl_calloc_array(dim->ctx, isl_id *,
+                                        nparam + n_in + n_out);
+               if (!ids)
+                       goto error;
+               get_ids(dim, isl_dim_param, 0, dim->nparam, ids);
+               get_ids(dim, isl_dim_in, 0, dim->n_in, ids + nparam);
+               get_ids(dim, isl_dim_out, 0, dim->n_out, ids + nparam + n_in);
+               free(dim->ids);
+               dim->ids = ids;
+               dim->n_id = nparam + n_in + n_out;
+       }
+       dim->nparam = nparam;
+       dim->n_in = n_in;
+       dim->n_out = n_out;
+
+       return dim;
+error:
+       free(ids);
+       isl_space_free(dim);
+       return NULL;
+}
+
+__isl_give isl_space *isl_space_add_dims(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned n)
+{
+       if (!dim)
+               return NULL;
+       dim = isl_space_reset(dim, type);
+       switch (type) {
+       case isl_dim_param:
+               dim = isl_space_extend(dim,
+                                       dim->nparam + n, dim->n_in, dim->n_out);
+               if (dim && dim->nested[0] &&
+                   !(dim->nested[0] = isl_space_add_dims(dim->nested[0],
+                                                   isl_dim_param, n)))
+                       goto error;
+               if (dim && dim->nested[1] &&
+                   !(dim->nested[1] = isl_space_add_dims(dim->nested[1],
+                                                   isl_dim_param, n)))
+                       goto error;
+               return dim;
+       case isl_dim_in:
+               return isl_space_extend(dim,
+                                       dim->nparam, dim->n_in + n, dim->n_out);
+       case isl_dim_out:
+               return isl_space_extend(dim,
+                                       dim->nparam, dim->n_in, dim->n_out + n);
+       default:
+               isl_die(dim->ctx, isl_error_invalid,
+                       "cannot add dimensions of specified type", goto error);
+       }
+error:
+       isl_space_free(dim);
+       return NULL;
+}
+
+static int valid_dim_type(enum isl_dim_type type)
+{
+       switch (type) {
+       case isl_dim_param:
+       case isl_dim_in:
+       case isl_dim_out:
+               return 1;
+       default:
+               return 0;
+       }
+}
+
+__isl_give isl_space *isl_space_insert_dims(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned pos, unsigned n)
+{
+       isl_id **ids = NULL;
+
+       if (!dim)
+               return NULL;
+       if (n == 0)
+               return isl_space_reset(dim, type);
+
+       if (!valid_dim_type(type))
+               isl_die(dim->ctx, isl_error_invalid,
+                       "cannot insert dimensions of specified type",
+                       goto error);
+
+       isl_assert(dim->ctx, pos <= isl_space_dim(dim, type), goto error);
+
+       dim = isl_space_cow(dim);
+       if (!dim)
+               return NULL;
+
+       if (dim->ids) {
+               enum isl_dim_type t;
+               int off;
+               int s[3];
+               int *size = s - isl_dim_param;
+               ids = isl_calloc_array(dim->ctx, isl_id *,
+                                    dim->nparam + dim->n_in + dim->n_out + n);
+               if (!ids)
+                       goto error;
+               off = 0;
+               size[isl_dim_param] = dim->nparam;
+               size[isl_dim_in] = dim->n_in;
+               size[isl_dim_out] = dim->n_out;
+               for (t = isl_dim_param; t <= isl_dim_out; ++t) {
+                       if (t != type) {
+                               get_ids(dim, t, 0, size[t], ids + off);
+                               off += size[t];
+                       } else {
+                               get_ids(dim, t, 0, pos, ids + off);
+                               off += pos + n;
+                               get_ids(dim, t, pos, size[t] - pos, ids + off);
+                               off += size[t] - pos;
+                       }
+               }
+               free(dim->ids);
+               dim->ids = ids;
+               dim->n_id = dim->nparam + dim->n_in + dim->n_out + n;
+       }
+       switch (type) {
+       case isl_dim_param:     dim->nparam += n; break;
+       case isl_dim_in:        dim->n_in += n; break;
+       case isl_dim_out:       dim->n_out += n; break;
+       default:                ;
+       }
+       dim = isl_space_reset(dim, type);
+
+       return dim;
+error:
+       isl_space_free(dim);
+       return NULL;
+}
+
+__isl_give isl_space *isl_space_move_dims(__isl_take isl_space *dim,
+       enum isl_dim_type dst_type, unsigned dst_pos,
+       enum isl_dim_type src_type, unsigned src_pos, unsigned n)
+{
+       int i;
+
+       if (!dim)
+               return NULL;
+       if (n == 0)
+               return dim;
+
+       isl_assert(dim->ctx, src_pos + n <= isl_space_dim(dim, src_type),
+               goto error);
+
+       if (dst_type == src_type && dst_pos == src_pos)
+               return dim;
+
+       isl_assert(dim->ctx, dst_type != src_type, goto error);
+
+       dim = isl_space_reset(dim, src_type);
+       dim = isl_space_reset(dim, dst_type);
+
+       dim = isl_space_cow(dim);
+       if (!dim)
+               return NULL;
+
+       if (dim->ids) {
+               isl_id **ids;
+               enum isl_dim_type t;
+               int off;
+               int s[3];
+               int *size = s - isl_dim_param;
+               ids = isl_calloc_array(dim->ctx, isl_id *,
+                                        dim->nparam + dim->n_in + dim->n_out);
+               if (!ids)
+                       goto error;
+               off = 0;
+               size[isl_dim_param] = dim->nparam;
+               size[isl_dim_in] = dim->n_in;
+               size[isl_dim_out] = dim->n_out;
+               for (t = isl_dim_param; t <= isl_dim_out; ++t) {
+                       if (t == dst_type) {
+                               get_ids(dim, t, 0, dst_pos, ids + off);
+                               off += dst_pos;
+                               get_ids(dim, src_type, src_pos, n, ids + off);
+                               off += n;
+                               get_ids(dim, t, dst_pos, size[t] - dst_pos,
+                                               ids + off);
+                               off += size[t] - dst_pos;
+                       } else if (t == src_type) {
+                               get_ids(dim, t, 0, src_pos, ids + off);
+                               off += src_pos;
+                               get_ids(dim, t, src_pos + n,
+                                           size[t] - src_pos - n, ids + off);
+                               off += size[t] - src_pos - n;
+                       } else {
+                               get_ids(dim, t, 0, size[t], ids + off);
+                               off += size[t];
+                       }
+               }
+               free(dim->ids);
+               dim->ids = ids;
+               dim->n_id = dim->nparam + dim->n_in + dim->n_out;
+       }
+
+       switch (dst_type) {
+       case isl_dim_param:     dim->nparam += n; break;
+       case isl_dim_in:        dim->n_in += n; break;
+       case isl_dim_out:       dim->n_out += n; break;
+       default:                ;
+       }
+
+       switch (src_type) {
+       case isl_dim_param:     dim->nparam -= n; break;
+       case isl_dim_in:        dim->n_in -= n; break;
+       case isl_dim_out:       dim->n_out -= n; break;
+       default:                ;
+       }
+
+       if (dst_type != isl_dim_param && src_type != isl_dim_param)
+               return dim;
+
+       for (i = 0; i < 2; ++i) {
+               if (!dim->nested[i])
+                       continue;
+               dim->nested[i] = isl_space_replace(dim->nested[i],
+                                                isl_dim_param, dim);
+               if (!dim->nested[i])
+                       goto error;
+       }
+
+       return dim;
+error:
+       isl_space_free(dim);
+       return NULL;
+}
+
+__isl_give isl_space *isl_space_join(__isl_take isl_space *left,
+       __isl_take isl_space *right)
+{
+       isl_space *dim;
+
+       if (!left || !right)
+               goto error;
+
+       isl_assert(left->ctx, match(left, isl_dim_param, right, isl_dim_param),
+                       goto error);
+       isl_assert(left->ctx,
+               isl_space_tuple_match(left, isl_dim_out, right, isl_dim_in),
+               goto error);
+
+       dim = isl_space_alloc(left->ctx, left->nparam, left->n_in, right->n_out);
+       if (!dim)
+               goto error;
+
+       dim = copy_ids(dim, isl_dim_param, 0, left, isl_dim_param);
+       dim = copy_ids(dim, isl_dim_in, 0, left, isl_dim_in);
+       dim = copy_ids(dim, isl_dim_out, 0, right, isl_dim_out);
+
+       if (dim && left->tuple_id[0] &&
+           !(dim->tuple_id[0] = isl_id_copy(left->tuple_id[0])))
+               goto error;
+       if (dim && right->tuple_id[1] &&
+           !(dim->tuple_id[1] = isl_id_copy(right->tuple_id[1])))
+               goto error;
+       if (dim && left->nested[0] &&
+           !(dim->nested[0] = isl_space_copy(left->nested[0])))
+               goto error;
+       if (dim && right->nested[1] &&
+           !(dim->nested[1] = isl_space_copy(right->nested[1])))
+               goto error;
+
+       isl_space_free(left);
+       isl_space_free(right);
+
+       return dim;
+error:
+       isl_space_free(left);
+       isl_space_free(right);
+       return NULL;
+}
+
+__isl_give isl_space *isl_space_product(__isl_take isl_space *left,
+       __isl_take isl_space *right)
+{
+       isl_space *dom1, *dom2, *nest1, *nest2;
+
+       if (!left || !right)
+               goto error;
+
+       isl_assert(left->ctx, match(left, isl_dim_param, right, isl_dim_param),
+                       goto error);
+
+       dom1 = isl_space_domain(isl_space_copy(left));
+       dom2 = isl_space_domain(isl_space_copy(right));
+       nest1 = isl_space_wrap(isl_space_join(isl_space_reverse(dom1), dom2));
+
+       dom1 = isl_space_range(left);
+       dom2 = isl_space_range(right);
+       nest2 = isl_space_wrap(isl_space_join(isl_space_reverse(dom1), dom2));
+
+       return isl_space_join(isl_space_reverse(nest1), nest2);
+error:
+       isl_space_free(left);
+       isl_space_free(right);
+       return NULL;
+}
+
+/* Given two spaces { A -> C } and { B -> C }, construct the space
+ * { [A -> B] -> C }
+ */
+__isl_give isl_space *isl_space_domain_product(__isl_take isl_space *left,
+       __isl_take isl_space *right)
+{
+       isl_space *ran, *dom1, *dom2, *nest;
+
+       if (!left || !right)
+               goto error;
+
+       if (!match(left, isl_dim_param, right, isl_dim_param))
+               isl_die(left->ctx, isl_error_invalid,
+                       "parameters need to match", goto error);
+       if (!isl_space_tuple_match(left, isl_dim_out, right, isl_dim_out))
+               isl_die(left->ctx, isl_error_invalid,
+                       "ranges need to match", goto error);
+
+       ran = isl_space_range(isl_space_copy(left));
+
+       dom1 = isl_space_domain(left);
+       dom2 = isl_space_domain(right);
+       nest = isl_space_wrap(isl_space_join(isl_space_reverse(dom1), dom2));
+
+       return isl_space_join(isl_space_reverse(nest), ran);
+error:
+       isl_space_free(left);
+       isl_space_free(right);
+       return NULL;
+}
+
+__isl_give isl_space *isl_space_range_product(__isl_take isl_space *left,
+       __isl_take isl_space *right)
+{
+       isl_space *dom, *ran1, *ran2, *nest;
+
+       if (!left || !right)
+               goto error;
+
+       isl_assert(left->ctx, match(left, isl_dim_param, right, isl_dim_param),
+                       goto error);
+       if (!isl_space_tuple_match(left, isl_dim_in, right, isl_dim_in))
+               isl_die(left->ctx, isl_error_invalid,
+                       "domains need to match", goto error);
+
+       dom = isl_space_domain(isl_space_copy(left));
+
+       ran1 = isl_space_range(left);
+       ran2 = isl_space_range(right);
+       nest = isl_space_wrap(isl_space_join(isl_space_reverse(ran1), ran2));
+
+       return isl_space_join(isl_space_reverse(dom), nest);
+error:
+       isl_space_free(left);
+       isl_space_free(right);
+       return NULL;
+}
+
+__isl_give isl_space *isl_space_map_from_set(__isl_take isl_space *dim)
+{
+       isl_ctx *ctx;
+       isl_id **ids = NULL;
+
+       if (!dim)
+               return NULL;
+       ctx = isl_space_get_ctx(dim);
+       if (!isl_space_is_set(dim))
+               isl_die(ctx, isl_error_invalid, "not a set space", goto error);
+       dim = isl_space_cow(dim);
+       if (!dim)
+               return NULL;
+       if (dim->ids) {
+               ids = isl_calloc_array(dim->ctx, isl_id *,
+                                       dim->nparam + dim->n_out + dim->n_out);
+               if (!ids)
+                       goto error;
+               get_ids(dim, isl_dim_param, 0, dim->nparam, ids);
+               get_ids(dim, isl_dim_out, 0, dim->n_out, ids + dim->nparam);
+       }
+       dim->n_in = dim->n_out;
+       if (ids) {
+               free(dim->ids);
+               dim->ids = ids;
+               dim->n_id = dim->nparam + dim->n_out + dim->n_out;
+               dim = copy_ids(dim, isl_dim_out, 0, dim, isl_dim_in);
+       }
+       isl_id_free(dim->tuple_id[0]);
+       dim->tuple_id[0] = isl_id_copy(dim->tuple_id[1]);
+       isl_space_free(dim->nested[0]);
+       dim->nested[0] = isl_space_copy(dim->nested[1]);
+       return dim;
+error:
+       isl_space_free(dim);
+       return NULL;
+}
+
+static __isl_give isl_space *set_ids(__isl_take isl_space *dim,
+       enum isl_dim_type type,
+       unsigned first, unsigned n, __isl_take isl_id **ids)
+{
+       int i;
+
+       for (i = 0; i < n ; ++i)
+               dim = set_id(dim, type, first + i, ids[i]);
+
+       return dim;
+}
+
+__isl_give isl_space *isl_space_reverse(__isl_take isl_space *dim)
+{
+       unsigned t;
+       isl_space *nested;
+       isl_id **ids = NULL;
+       isl_id *id;
+
+       if (!dim)
+               return NULL;
+       if (match(dim, isl_dim_in, dim, isl_dim_out))
+               return dim;
+
+       dim = isl_space_cow(dim);
+       if (!dim)
+               return NULL;
+
+       id = dim->tuple_id[0];
+       dim->tuple_id[0] = dim->tuple_id[1];
+       dim->tuple_id[1] = id;
+
+       nested = dim->nested[0];
+       dim->nested[0] = dim->nested[1];
+       dim->nested[1] = nested;
+
+       if (dim->ids) {
+               ids = isl_alloc_array(dim->ctx, isl_id *,
+                                       dim->n_in + dim->n_out);
+               if (!ids)
+                       goto error;
+               get_ids(dim, isl_dim_in, 0, dim->n_in, ids);
+               get_ids(dim, isl_dim_out, 0, dim->n_out, ids + dim->n_in);
+       }
+
+       t = dim->n_in;
+       dim->n_in = dim->n_out;
+       dim->n_out = t;
+
+       if (dim->ids) {
+               dim = set_ids(dim, isl_dim_out, 0, dim->n_out, ids);
+               dim = set_ids(dim, isl_dim_in, 0, dim->n_in, ids + dim->n_out);
+               free(ids);
+       }
+
+       return dim;
+error:
+       free(ids);
+       isl_space_free(dim);
+       return NULL;
+}
+
+__isl_give isl_space *isl_space_drop_dims(__isl_take isl_space *dim,
+       enum isl_dim_type type, unsigned first, unsigned num)
+{
+       int i;
+
+       if (!dim)
+               return NULL;
+
+       if (num == 0)
+               return isl_space_reset(dim, type);
+
+       if (!valid_dim_type(type))
+               isl_die(dim->ctx, isl_error_invalid,
+                       "cannot drop dimensions of specified type", goto error);
+
+       isl_assert(dim->ctx, first + num <= n(dim, type), goto error);
+       dim = isl_space_cow(dim);
+       if (!dim)
+               goto error;
+       if (dim->ids) {
+               dim = extend_ids(dim);
+               if (!dim)
+                       goto error;
+               for (i = 0; i < num; ++i)
+                       isl_id_free(get_id(dim, type, first + i));
+               for (i = first+num; i < n(dim, type); ++i)
+                       set_id(dim, type, i - num, get_id(dim, type, i));
+               switch (type) {
+               case isl_dim_param:
+                       get_ids(dim, isl_dim_in, 0, dim->n_in,
+                               dim->ids + offset(dim, isl_dim_in) - num);
+               case isl_dim_in:
+                       get_ids(dim, isl_dim_out, 0, dim->n_out,
+                               dim->ids + offset(dim, isl_dim_out) - num);
+               default:
+                       ;
+               }
+               dim->n_id -= num;
+       }
+       switch (type) {
+       case isl_dim_param:     dim->nparam -= num; break;
+       case isl_dim_in:        dim->n_in -= num; break;
+       case isl_dim_out:       dim->n_out -= num; break;
+       default:                ;
+       }
+       dim = isl_space_reset(dim, type);
+       if (type == isl_dim_param) {
+               if (dim && dim->nested[0] &&
+                   !(dim->nested[0] = isl_space_drop_dims(dim->nested[0],
+                                                   isl_dim_param, first, num)))
+                       goto error;
+               if (dim && dim->nested[1] &&
+                   !(dim->nested[1] = isl_space_drop_dims(dim->nested[1],
+                                                   isl_dim_param, first, num)))
+                       goto error;
+       }
+       return dim;
+error:
+       isl_space_free(dim);
+       return NULL;
+}
+
+__isl_give isl_space *isl_space_drop_inputs(__isl_take isl_space *dim,
+               unsigned first, unsigned n)
+{
+       if (!dim)
+               return NULL;
+       return isl_space_drop_dims(dim, isl_dim_in, first, n);
+}
+
+__isl_give isl_space *isl_space_drop_outputs(__isl_take isl_space *dim,
+               unsigned first, unsigned n)
+{
+       if (!dim)
+               return NULL;
+       return isl_space_drop_dims(dim, isl_dim_out, first, n);
+}
+
+__isl_give isl_space *isl_space_domain(__isl_take isl_space *dim)
+{
+       if (!dim)
+               return NULL;
+       dim = isl_space_drop_outputs(dim, 0, dim->n_out);
+       dim = isl_space_reverse(dim);
+       dim = mark_as_set(dim);
+       return dim;
+}
+
+__isl_give isl_space *isl_space_from_domain(__isl_take isl_space *dim)
+{
+       if (!dim)
+               return NULL;
+       if (!isl_space_is_set(dim))
+               isl_die(isl_space_get_ctx(dim), isl_error_invalid,
+                       "not a set space", goto error);
+       dim = isl_space_reverse(dim);
+       dim = isl_space_reset(dim, isl_dim_out);
+       return dim;
+error:
+       isl_space_free(dim);
+       return NULL;
+}
+
+__isl_give isl_space *isl_space_range(__isl_take isl_space *dim)
+{
+       if (!dim)
+               return NULL;
+       dim = isl_space_drop_inputs(dim, 0, dim->n_in);
+       dim = mark_as_set(dim);
+       return dim;
+}
+
+__isl_give isl_space *isl_space_from_range(__isl_take isl_space *dim)
+{
+       if (!dim)
+               return NULL;
+       if (!isl_space_is_set(dim))
+               isl_die(isl_space_get_ctx(dim), isl_error_invalid,
+                       "not a set space", goto error);
+       return isl_space_reset(dim, isl_dim_in);
+error:
+       isl_space_free(dim);
+       return NULL;
+}
+
+__isl_give isl_space *isl_space_params(__isl_take isl_space *space)
+{
+       if (isl_space_is_params(space))
+               return space;
+       space = isl_space_drop_dims(space,
+                           isl_dim_in, 0, isl_space_dim(space, isl_dim_in));
+       space = isl_space_drop_dims(space,
+                           isl_dim_out, 0, isl_space_dim(space, isl_dim_out));
+       space = mark_as_params(space);
+       return space;
+}
+
+__isl_give isl_space *isl_space_as_set_space(__isl_take isl_space *dim)
+{
+       dim = isl_space_cow(dim);
+       if (!dim)
+               return NULL;
+
+       dim->n_out += dim->n_in;
+       dim->n_in = 0;
+       dim = isl_space_reset(dim, isl_dim_in);
+       dim = isl_space_reset(dim, isl_dim_out);
+
+       return dim;
+}
+
+__isl_give isl_space *isl_space_underlying(__isl_take isl_space *dim,
+       unsigned n_div)
+{
+       int i;
+
+       if (!dim)
+               return NULL;
+       if (n_div == 0 &&
+           dim->nparam == 0 && dim->n_in == 0 && dim->n_id == 0)
+               return isl_space_reset(isl_space_reset(dim, isl_dim_in), isl_dim_out);
+       dim = isl_space_cow(dim);
+       if (!dim)
+               return NULL;
+       dim->n_out += dim->nparam + dim->n_in + n_div;
+       dim->nparam = 0;
+       dim->n_in = 0;
+
+       for (i = 0; i < dim->n_id; ++i)
+               isl_id_free(get_id(dim, isl_dim_out, i));
+       dim->n_id = 0;
+       dim = isl_space_reset(dim, isl_dim_in);
+       dim = isl_space_reset(dim, isl_dim_out);
+
+       return dim;
+}
+
+int isl_space_is_equal(__isl_keep isl_space *dim1, __isl_keep isl_space *dim2)
+{
+       if (!dim1 || !dim2)
+               return -1;
+       if (dim1 == dim2)
+               return 1;
+       return match(dim1, isl_dim_param, dim2, isl_dim_param) &&
+              isl_space_tuple_match(dim1, isl_dim_in, dim2, isl_dim_in) &&
+              isl_space_tuple_match(dim1, isl_dim_out, dim2, isl_dim_out);
+}
+
+/* Is space1 equal to the domain of space2?
+ */
+int isl_space_is_domain(__isl_keep isl_space *space1,
+       __isl_keep isl_space *space2)
+{
+       if (!space1 || !space2)
+               return -1;
+       if (!isl_space_is_set(space1))
+               return 0;
+       return match(space1, isl_dim_param, space2, isl_dim_param) &&
+              isl_space_tuple_match(space1, isl_dim_set, space2, isl_dim_in);
+}
+
+int isl_space_compatible(__isl_keep isl_space *dim1,
+       __isl_keep isl_space *dim2)
+{
+       return dim1->nparam == dim2->nparam &&
+              dim1->n_in + dim1->n_out == dim2->n_in + dim2->n_out;
+}
+
+static uint32_t isl_hash_dim(uint32_t hash, __isl_keep isl_space *dim)
+{
+       int i;
+       isl_id *id;
+
+       if (!dim)
+               return hash;
+
+       hash = isl_hash_builtin(hash, dim->nparam);
+       hash = isl_hash_builtin(hash, dim->n_in);
+       hash = isl_hash_builtin(hash, dim->n_out);
+
+       for (i = 0; i < dim->nparam; ++i) {
+               id = get_id(dim, isl_dim_param, i);
+               hash = isl_hash_id(hash, id);
+       }
+
+       id = tuple_id(dim, isl_dim_in);
+       hash = isl_hash_id(hash, id);
+       id = tuple_id(dim, isl_dim_out);
+       hash = isl_hash_id(hash, id);
+
+       hash = isl_hash_dim(hash, dim->nested[0]);
+       hash = isl_hash_dim(hash, dim->nested[1]);
+
+       return hash;
+}
+
+uint32_t isl_space_get_hash(__isl_keep isl_space *dim)
+{
+       uint32_t hash;
+
+       if (!dim)
+               return 0;
+
+       hash = isl_hash_init();
+       hash = isl_hash_dim(hash, dim);
+
+       return hash;
+}
+
+int isl_space_is_wrapping(__isl_keep isl_space *dim)
+{
+       if (!dim)
+               return -1;
+
+       if (!isl_space_is_set(dim))
+               return 0;
+
+       return dim->nested[1] != NULL;
+}
+
+__isl_give isl_space *isl_space_wrap(__isl_take isl_space *dim)
+{
+       isl_space *wrap;
+
+       if (!dim)
+               return NULL;
+
+       wrap = isl_space_set_alloc(dim->ctx,
+                                   dim->nparam, dim->n_in + dim->n_out);
+
+       wrap = copy_ids(wrap, isl_dim_param, 0, dim, isl_dim_param);
+       wrap = copy_ids(wrap, isl_dim_set, 0, dim, isl_dim_in);
+       wrap = copy_ids(wrap, isl_dim_set, dim->n_in, dim, isl_dim_out);
+
+       if (!wrap)
+               goto error;
+
+       wrap->nested[1] = dim;
+
+       return wrap;
+error:
+       isl_space_free(dim);
+       return NULL;
+}
+
+__isl_give isl_space *isl_space_unwrap(__isl_take isl_space *dim)
+{
+       isl_space *unwrap;
+
+       if (!dim)
+               return NULL;
+
+       if (!isl_space_is_wrapping(dim))
+               isl_die(dim->ctx, isl_error_invalid, "not a wrapping dim",
+                       goto error);
+
+       unwrap = isl_space_copy(dim->nested[1]);
+       isl_space_free(dim);
+
+       return unwrap;
+error:
+       isl_space_free(dim);
+       return NULL;
+}
+
+int isl_space_is_named_or_nested(__isl_keep isl_space *dim, enum isl_dim_type type)
+{
+       if (type != isl_dim_in && type != isl_dim_out)
+               return 0;
+       if (!dim)
+               return -1;
+       if (dim->tuple_id[type - isl_dim_in])
+               return 1;
+       if (dim->nested[type - isl_dim_in])
+               return 1;
+       return 0;
+}
+
+int isl_space_may_be_set(__isl_keep isl_space *dim)
+{
+       if (!dim)
+               return -1;
+       if (isl_space_is_set(dim))
+               return 1;
+       if (isl_space_dim(dim, isl_dim_in) != 0)
+               return 0;
+       if (isl_space_is_named_or_nested(dim, isl_dim_in))
+               return 0;
+       return 1;
+}
+
+__isl_give isl_space *isl_space_reset(__isl_take isl_space *dim,
+       enum isl_dim_type type)
+{
+       if (!isl_space_is_named_or_nested(dim, type))
+               return dim;
+
+       dim = isl_space_cow(dim);
+       if (!dim)
+               return NULL;
+
+       isl_id_free(dim->tuple_id[type - isl_dim_in]);
+       dim->tuple_id[type - isl_dim_in] = NULL;
+       isl_space_free(dim->nested[type - isl_dim_in]);
+       dim->nested[type - isl_dim_in] = NULL;
+
+       return dim;
+}
+
+__isl_give isl_space *isl_space_flatten(__isl_take isl_space *dim)
+{
+       if (!dim)
+               return NULL;
+       if (!dim->nested[0] && !dim->nested[1])
+               return dim;
+
+       if (dim->nested[0])
+               dim = isl_space_reset(dim, isl_dim_in);
+       if (dim && dim->nested[1])
+               dim = isl_space_reset(dim, isl_dim_out);
+
+       return dim;
+}
+
+__isl_give isl_space *isl_space_flatten_domain(__isl_take isl_space *dim)
+{
+       if (!dim)
+               return NULL;
+       if (!dim->nested[0])
+               return dim;
+
+       return isl_space_reset(dim, isl_dim_in);
+}
+
+__isl_give isl_space *isl_space_flatten_range(__isl_take isl_space *dim)
+{
+       if (!dim)
+               return NULL;
+       if (!dim->nested[1])
+               return dim;
+
+       return isl_space_reset(dim, isl_dim_out);
+}
+
+/* Replace the dimensions of the given type of dst by those of src.
+ */
+__isl_give isl_space *isl_space_replace(__isl_take isl_space *dst,
+       enum isl_dim_type type, __isl_keep isl_space *src)
+{
+       dst = isl_space_cow(dst);
+
+       if (!dst || !src)
+               goto error;
+
+       dst = isl_space_drop_dims(dst, type, 0, isl_space_dim(dst, type));
+       dst = isl_space_add_dims(dst, type, isl_space_dim(src, type));
+       dst = copy_ids(dst, type, 0, src, type);
+
+       if (dst && type == isl_dim_param) {
+               int i;
+               for (i = 0; i <= 1; ++i) {
+                       if (!dst->nested[i])
+                               continue;
+                       dst->nested[i] = isl_space_replace(dst->nested[i],
+                                                        type, src);
+                       if (!dst->nested[i])
+                               goto error;
+               }
+       }
+
+       return dst;
+error:
+       isl_space_free(dst);
+       return NULL;
+}
+
+/* Given a dimension specification "dim" of a set, create a dimension
+ * specification for the lift of the set.  In particular, the result
+ * is of the form [dim -> local[..]], with n_local variables in the
+ * range of the wrapped map.
+ */
+__isl_give isl_space *isl_space_lift(__isl_take isl_space *dim, unsigned n_local)
+{
+       isl_space *local_dim;
+
+       if (!dim)
+               return NULL;
+
+       local_dim = isl_space_dup(dim);
+       local_dim = isl_space_drop_dims(local_dim, isl_dim_set, 0, dim->n_out);
+       local_dim = isl_space_add_dims(local_dim, isl_dim_set, n_local);
+       local_dim = isl_space_set_tuple_name(local_dim, isl_dim_set, "local");
+       dim = isl_space_join(isl_space_from_domain(dim),
+                           isl_space_from_range(local_dim));
+       dim = isl_space_wrap(dim);
+       dim = isl_space_set_tuple_name(dim, isl_dim_set, "lifted");
+
+       return dim;
+}
+
+int isl_space_can_zip(__isl_keep isl_space *dim)
+{
+       if (!dim)
+               return -1;
+
+       return dim->nested[0] && dim->nested[1];
+}
+
+__isl_give isl_space *isl_space_zip(__isl_take isl_space *dim)
+{
+       isl_space *dom, *ran;
+       isl_space *dom_dom, *dom_ran, *ran_dom, *ran_ran;
+
+       if (!isl_space_can_zip(dim))
+               isl_die(dim->ctx, isl_error_invalid, "dim cannot be zipped",
+                       goto error);
+
+       if (!dim)
+               return 0;
+       dom = isl_space_unwrap(isl_space_domain(isl_space_copy(dim)));
+       ran = isl_space_unwrap(isl_space_range(dim));
+       dom_dom = isl_space_domain(isl_space_copy(dom));
+       dom_ran = isl_space_range(dom);
+       ran_dom = isl_space_domain(isl_space_copy(ran));
+       ran_ran = isl_space_range(ran);
+       dom = isl_space_join(isl_space_from_domain(dom_dom),
+                          isl_space_from_range(ran_dom));
+       ran = isl_space_join(isl_space_from_domain(dom_ran),
+                          isl_space_from_range(ran_ran));
+       return isl_space_join(isl_space_from_domain(isl_space_wrap(dom)),
+                           isl_space_from_range(isl_space_wrap(ran)));
+error:
+       isl_space_free(dim);
+       return NULL;
+}
+
+int isl_space_has_named_params(__isl_keep isl_space *dim)
+{
+       int i;
+       unsigned off;
+
+       if (!dim)
+               return -1;
+       if (dim->nparam == 0)
+               return 1;
+       off = isl_space_offset(dim, isl_dim_param);
+       if (off + dim->nparam > dim->n_id)
+               return 0;
+       for (i = 0; i < dim->nparam; ++i)
+               if (!dim->ids[off + i])
+                       return 0;
+       return 1;
+}
+
+/* Align the initial parameters of dim1 to match the order in dim2.
+ */
+__isl_give isl_space *isl_space_align_params(__isl_take isl_space *dim1,
+       __isl_take isl_space *dim2)
+{
+       isl_reordering *exp;
+
+       if (!isl_space_has_named_params(dim1) || !isl_space_has_named_params(dim2))
+               isl_die(isl_space_get_ctx(dim1), isl_error_invalid,
+                       "parameter alignment requires named parameters",
+                       goto error);
+
+       dim2 = isl_space_params(dim2);
+       exp = isl_parameter_alignment_reordering(dim1, dim2);
+       exp = isl_reordering_extend_space(exp, dim1);
+       isl_space_free(dim2);
+       if (!exp)
+               return NULL;
+       dim1 = isl_space_copy(exp->dim);
+       isl_reordering_free(exp);
+       return dim1;
+error:
+       isl_space_free(dim1);
+       isl_space_free(dim2);
+       return NULL;
+}
+
+/* Given the space of set (domain), construct a space for a map
+ * with as domain the given space and as range the range of "model".
+ */
+__isl_give isl_space *isl_space_extend_domain_with_range(
+       __isl_take isl_space *domain, __isl_take isl_space *model)
+{
+       isl_space *space;
+
+       space = isl_space_from_domain(domain);
+       space = isl_space_add_dims(space, isl_dim_out,
+                                   isl_space_dim(model, isl_dim_out));
+       if (isl_space_has_tuple_id(model, isl_dim_out))
+               space = isl_space_set_tuple_id(space, isl_dim_out,
+                               isl_space_get_tuple_id(model, isl_dim_out));
+       isl_space_free(model);
+       return space;
+}
diff --git a/isl_space_private.h b/isl_space_private.h
new file mode 100644 (file)
index 0000000..73762de
--- /dev/null
@@ -0,0 +1,51 @@
+#include <isl/space.h>
+#include <isl/hash.h>
+#include <isl/id.h>
+
+struct isl_name;
+struct isl_space {
+       int ref;
+
+       struct isl_ctx *ctx;
+
+       unsigned nparam;
+       unsigned n_in;          /* zero for sets */
+       unsigned n_out;         /* dim for sets */
+
+       isl_id *tuple_id[2];
+       isl_space *nested[2];
+
+       unsigned n_id;
+       isl_id **ids;
+};
+
+__isl_give isl_space *isl_space_cow(__isl_take isl_space *dim);
+
+__isl_give isl_space *isl_space_underlying(__isl_take isl_space *dim,
+       unsigned n_div);
+
+uint32_t isl_space_get_hash(__isl_keep isl_space *dim);
+
+int isl_space_is_domain(__isl_keep isl_space *space1,
+       __isl_keep isl_space *space2);
+
+__isl_give isl_space *isl_space_as_set_space(__isl_take isl_space *dim);
+
+unsigned isl_space_offset(__isl_keep isl_space *dim, enum isl_dim_type type);
+
+int isl_space_may_be_set(__isl_keep isl_space *dim);
+int isl_space_is_named_or_nested(__isl_keep isl_space *dim, enum isl_dim_type type);
+int isl_space_has_named_params(__isl_keep isl_space *dim);
+__isl_give isl_space *isl_space_reset(__isl_take isl_space *dim,
+       enum isl_dim_type type);
+__isl_give isl_space *isl_space_flatten(__isl_take isl_space *dim);
+__isl_give isl_space *isl_space_flatten_domain(__isl_take isl_space *dim);
+__isl_give isl_space *isl_space_flatten_range(__isl_take isl_space *dim);
+
+__isl_give isl_space *isl_space_replace(__isl_take isl_space *dst,
+       enum isl_dim_type type, __isl_keep isl_space *src);
+
+__isl_give isl_space *isl_space_lift(__isl_take isl_space *dim, unsigned n_local);
+
+__isl_give isl_space *isl_space_extend_domain_with_range(
+       __isl_take isl_space *domain, __isl_take isl_space *model);
index c544149..01a2caa 100644 (file)
@@ -11,7 +11,9 @@
 #include <string.h>
 #include <strings.h>
 #include <isl/ctx.h>
-#include <isl/stream.h>
+#include <isl_stream_private.h>
+#include <isl/map.h>
+#include <isl/aff.h>
 
 struct isl_keyword {
        char                    *name;
@@ -64,7 +66,7 @@ enum isl_token_type isl_stream_register_keyword(struct isl_stream *s,
        return keyword->type;
 }
 
-static struct isl_token *isl_token_new(struct isl_ctx *ctx,
+struct isl_token *isl_token_new(isl_ctx *ctx,
        int line, int col, unsigned on_new_line)
 {
        struct isl_token *tok = isl_alloc_type(ctx, struct isl_token);
@@ -84,6 +86,10 @@ void isl_token_free(struct isl_token *tok)
                return;
        if (tok->type == ISL_TOKEN_VALUE)
                isl_int_clear(tok->u.v);
+       else if (tok->type == ISL_TOKEN_MAP)
+               isl_map_free(tok->u.map);
+       else if (tok->type == ISL_TOKEN_AFF)
+               isl_pw_aff_free(tok->u.pwaff);
        else
                free(tok->u.s);
        free(tok);
@@ -105,6 +111,20 @@ void isl_stream_error(struct isl_stream *s, struct isl_token *tok, char *msg)
                        fprintf(stderr, "got value '");
                        isl_int_print(stderr, tok->u.v, 0);
                        fprintf(stderr, "'\n");
+               } else if (tok->type == ISL_TOKEN_MAP) {
+                       isl_printer *p;
+                       fprintf(stderr, "got map '");
+                       p = isl_printer_to_file(s->ctx, stderr);
+                       p = isl_printer_print_map(p, tok->u.map);
+                       isl_printer_free(p);
+                       fprintf(stderr, "'\n");
+               } else if (tok->type == ISL_TOKEN_AFF) {
+                       isl_printer *p;
+                       fprintf(stderr, "got affine expression '");
+                       p = isl_printer_to_file(s->ctx, stderr);
+                       p = isl_printer_print_pw_aff(p, tok->u.pwaff);
+                       isl_printer_free(p);
+                       fprintf(stderr, "'\n");
                } else if (tok->u.s)
                        fprintf(stderr, "got token '%s'\n", tok->u.s);
                else
@@ -264,6 +284,8 @@ static enum isl_token_type check_keywords(struct isl_stream *s)
                return ISL_TOKEN_CEILD;
        if (!strcasecmp(s->buffer, "floord"))
                return ISL_TOKEN_FLOORD;
+       if (!strcasecmp(s->buffer, "mod"))
+               return ISL_TOKEN_MOD;
 
        if (!s->keywords)
                return ISL_TOKEN_IDENT;
@@ -330,6 +352,7 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line)
            c == '+' ||
            c == '*' ||
            c == '%' ||
+           c == '?' ||
            c == '^' ||
            c == '=' ||
            c == '@' ||
@@ -542,8 +565,16 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line)
                tok = isl_token_new(s->ctx, line, col, old_line != line);
                if (!tok)
                        return NULL;
-               tok->type = ISL_TOKEN_NOT;
-               tok->u.s = strdup("!");
+               if ((c = isl_stream_getc(s)) == '=') {
+                       tok->u.s = strdup("!=");
+                       tok->type = ISL_TOKEN_NE;
+                       return tok;
+               } else {
+                       tok->type = ISL_TOKEN_NOT;
+                       tok->u.s = strdup("!");
+               }
+               if (c != -1)
+                       isl_stream_ungetc(s, c);
                return tok;
        }
 
diff --git a/isl_stream_private.h b/isl_stream_private.h
new file mode 100644 (file)
index 0000000..5623251
--- /dev/null
@@ -0,0 +1,4 @@
+#include <isl/stream.h>
+
+struct isl_token *isl_token_new(isl_ctx *ctx,
+       int line, int col, unsigned on_new_line);
index 5151ab6..220f0b0 100644 (file)
--- a/isl_tab.c
+++ b/isl_tab.c
@@ -2184,8 +2184,8 @@ int isl_tab_add_div(struct isl_tab *tab, __isl_keep isl_vec *div,
        if (nonneg)
                tab->var[r].is_nonneg = 1;
 
-       tab->bmap = isl_basic_map_extend_dim(tab->bmap,
-               isl_basic_map_get_dim(tab->bmap), 1, 0, 2);
+       tab->bmap = isl_basic_map_extend_space(tab->bmap,
+               isl_basic_map_get_space(tab->bmap), 1, 0, 2);
        k = isl_basic_map_alloc_div(tab->bmap);
        if (k < 0)
                return -1;
index 2f39a08..6e57da2 100644 (file)
@@ -603,7 +603,7 @@ static void sol_map_add(struct isl_sol_map *sol,
        n_div = dom->n_div;
        nparam = isl_basic_set_total_dim(dom) - n_div;
        total = isl_map_dim(sol->map, isl_dim_all);
-       bmap = isl_basic_map_alloc_dim(isl_map_get_dim(sol->map),
+       bmap = isl_basic_map_alloc_space(isl_map_get_space(sol->map),
                                        n_div, n_eq, 2 * n_div + n_ineq);
        if (!bmap)
                goto error;
@@ -3091,8 +3091,8 @@ static int context_gbr_add_div(struct isl_context *context, struct isl_vec *div)
                if (isl_tab_allocate_var(cgbr->cone) <0)
                        return -1;
 
-               cgbr->cone->bmap = isl_basic_map_extend_dim(cgbr->cone->bmap,
-                       isl_basic_map_get_dim(cgbr->cone->bmap), 1, 0, 2);
+               cgbr->cone->bmap = isl_basic_map_extend_space(cgbr->cone->bmap,
+                       isl_basic_map_get_space(cgbr->cone->bmap), 1, 0, 2);
                k = isl_basic_map_alloc_div(cgbr->cone->bmap);
                if (k < 0)
                        return -1;
@@ -3309,7 +3309,7 @@ static struct isl_sol_map *sol_map_init(struct isl_basic_map *bmap,
        sol_map->sol.add = &sol_map_add_wrap;
        sol_map->sol.add_empty = track_empty ? &sol_map_add_empty_wrap : NULL;
        sol_map->sol.free = &sol_map_free_wrap;
-       sol_map->map = isl_map_alloc_dim(isl_basic_map_get_dim(bmap), 1,
+       sol_map->map = isl_map_alloc_space(isl_basic_map_get_space(bmap), 1,
                                            ISL_MAP_DISJOINT);
        if (!sol_map->map)
                goto error;
@@ -3319,7 +3319,7 @@ static struct isl_sol_map *sol_map_init(struct isl_basic_map *bmap,
                goto error;
 
        if (track_empty) {
-               sol_map->empty = isl_set_alloc_dim(isl_basic_set_get_dim(dom),
+               sol_map->empty = isl_set_alloc_space(isl_basic_set_get_space(dom),
                                                        1, ISL_SET_DISJOINT);
                if (!sol_map->empty)
                        goto error;
@@ -3877,8 +3877,8 @@ static int find_context_div(struct isl_basic_map *bmap,
        struct isl_basic_set *dom, unsigned div)
 {
        int i;
-       unsigned b_dim = isl_dim_total(bmap->dim);
-       unsigned d_dim = isl_dim_total(dom->dim);
+       unsigned b_dim = isl_space_dim(bmap->dim, isl_dim_all);
+       unsigned d_dim = isl_space_dim(dom->dim, isl_dim_all);
 
        if (isl_int_is_zero(dom->div[div][0]))
                return -1;
@@ -3923,7 +3923,7 @@ static struct isl_basic_map *align_context_divs(struct isl_basic_map *bmap,
                        common++;
        other = bmap->n_div - common;
        if (dom->n_div - common > 0) {
-               bmap = isl_basic_map_extend_dim(bmap, isl_dim_copy(bmap->dim),
+               bmap = isl_basic_map_extend_space(bmap, isl_space_copy(bmap->dim),
                                dom->n_div - common, 0, 0);
                if (!bmap)
                        return NULL;
@@ -4094,7 +4094,7 @@ error:
  *     b_i <= b_j      for j > i
  *     b_i <  b_j      for j < i
  */
-static __isl_give isl_set *set_minimum(__isl_take isl_dim *dim,
+static __isl_give isl_set *set_minimum(__isl_take isl_space *dim,
        __isl_take isl_mat *var)
 {
        int i, j, k;
@@ -4105,12 +4105,12 @@ static __isl_give isl_set *set_minimum(__isl_take isl_dim *dim,
        if (!dim || !var)
                goto error;
 
-       ctx = isl_dim_get_ctx(dim);
-       set = isl_set_alloc_dim(isl_dim_copy(dim),
+       ctx = isl_space_get_ctx(dim);
+       set = isl_set_alloc_space(isl_space_copy(dim),
                                var->n_row, ISL_SET_DISJOINT);
 
        for (i = 0; i < var->n_row; ++i) {
-               bset = isl_basic_set_alloc_dim(isl_dim_copy(dim), 0,
+               bset = isl_basic_set_alloc_space(isl_space_copy(dim), 0,
                                               1, var->n_row - 1);
                k = isl_basic_set_alloc_equality(bset);
                if (k < 0)
@@ -4135,13 +4135,13 @@ static __isl_give isl_set *set_minimum(__isl_take isl_dim *dim,
                set = isl_set_add_basic_set(set, bset);
        }
 
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_mat_free(var);
        return set;
 error:
        isl_basic_set_free(bset);
        isl_set_free(set);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_mat_free(var);
        return NULL;
 }
@@ -4216,15 +4216,15 @@ static __isl_give isl_set *split(__isl_take isl_set *empty,
 {
        int n_in;
        int i;
-       isl_dim *dim;
+       isl_space *dim;
        isl_set *res;
 
        if (!empty || !min_expr || !cst)
                goto error;
 
        n_in = isl_set_dim(empty, isl_dim_set);
-       dim = isl_set_get_dim(empty);
-       dim = isl_dim_drop(dim, isl_dim_set, n_in - 1, 1);
+       dim = isl_set_get_space(empty);
+       dim = isl_space_drop_dims(dim, isl_dim_set, n_in - 1, 1);
        res = isl_set_empty(dim);
 
        for (i = 0; i < empty->n; ++i) {
@@ -4262,15 +4262,15 @@ static __isl_give isl_map *split_domain(__isl_take isl_map *opt,
 {
        int n_in;
        int i;
-       isl_dim *dim;
+       isl_space *dim;
        isl_map *res;
 
        if (!opt || !min_expr || !cst)
                goto error;
 
        n_in = isl_map_dim(opt, isl_dim_in);
-       dim = isl_map_get_dim(opt);
-       dim = isl_dim_drop(dim, isl_dim_in, n_in - 1, 1);
+       dim = isl_map_get_space(opt);
+       dim = isl_space_drop_dims(dim, isl_dim_in, n_in - 1, 1);
        res = isl_map_empty(dim);
 
        for (i = 0; i < opt->n; ++i) {
@@ -4340,10 +4340,10 @@ static __isl_give isl_map *basic_map_partial_lexopt_symm(
        isl_mat *cst = NULL;
        isl_map *opt;
        isl_set *min_expr;
-       isl_dim *map_dim, *set_dim;
+       isl_space *map_dim, *set_dim;
 
-       map_dim = isl_basic_map_get_dim(bmap);
-       set_dim = empty ? isl_basic_set_get_dim(dom) : NULL;
+       map_dim = isl_basic_map_get_space(bmap);
+       set_dim = empty ? isl_basic_set_get_space(dom) : NULL;
 
        n_in = isl_basic_map_dim(bmap, isl_dim_param) +
               isl_basic_map_dim(bmap, isl_dim_in);
@@ -4399,7 +4399,7 @@ static __isl_give isl_map *basic_map_partial_lexopt_symm(
                isl_seq_clr(dom->ineq[k] + 1 + n_in + 1, n_div);
        }
 
-       min_expr = set_minimum(isl_basic_set_get_dim(dom), isl_mat_copy(cst));
+       min_expr = set_minimum(isl_basic_set_get_space(dom), isl_mat_copy(cst));
 
        isl_vec_free(var);
        free(list);
@@ -4409,16 +4409,16 @@ static __isl_give isl_map *basic_map_partial_lexopt_symm(
        if (empty) {
                *empty = split(*empty,
                               isl_set_copy(min_expr), isl_mat_copy(cst));
-               *empty = isl_set_reset_dim(*empty, set_dim);
+               *empty = isl_set_reset_space(*empty, set_dim);
        }
 
        opt = split_domain(opt, min_expr, cst);
-       opt = isl_map_reset_dim(opt, map_dim);
+       opt = isl_map_reset_space(opt, map_dim);
 
        return opt;
 error:
-       isl_dim_free(map_dim);
-       isl_dim_free(set_dim);
+       isl_space_free(map_dim);
+       isl_space_free(set_dim);
        isl_mat_free(cst);
        isl_vec_free(var);
        free(list);
@@ -4586,14 +4586,14 @@ static struct isl_sol_for *sol_for_init(struct isl_basic_map *bmap, int max,
        void *user)
 {
        struct isl_sol_for *sol_for = NULL;
-       struct isl_dim *dom_dim;
+       isl_space *dom_dim;
        struct isl_basic_set *dom = NULL;
 
        sol_for = isl_calloc_type(bmap->ctx, struct isl_sol_for);
        if (!sol_for)
                goto error;
 
-       dom_dim = isl_dim_domain(isl_dim_copy(bmap->dim));
+       dom_dim = isl_space_domain(isl_space_copy(bmap->dim));
        dom = isl_basic_set_universe(dom_dim);
 
        sol_for->sol.rational = ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL);
@@ -4661,6 +4661,14 @@ error:
        return -1;
 }
 
+int isl_basic_set_foreach_lexopt(__isl_keep isl_basic_set *bset, int max,
+       int (*fn)(__isl_take isl_basic_set *dom, __isl_take isl_aff_list *list,
+                 void *user),
+       void *user)
+{
+       return isl_basic_map_foreach_lexopt(bset, max, fn, user);
+}
+
 int isl_basic_map_foreach_lexmin(__isl_keep isl_basic_map *bmap,
        int (*fn)(__isl_take isl_basic_set *dom, __isl_take isl_aff_list *list,
                  void *user),
@@ -4859,7 +4867,7 @@ __isl_give isl_vec *isl_tab_basic_set_non_trivial_lexmin(
        struct isl_trivial *triv = NULL;
        int level, init;
 
-       tab = tab_for_lexmin(isl_basic_map_from_range(bset), NULL, 0, 0);
+       tab = tab_for_lexmin(bset, NULL, 0, 0);
        if (!tab)
                goto error;
        tab->conflict = conflict;
@@ -4967,14 +4975,14 @@ error:
  * assuming that all variables are non-negative.
  * If "bset" is empty, then return a zero-length vector.
  */
- __isl_give isl_vec *isl_tab_basic_set_non_neg_lexmin(
+__isl_give isl_vec *isl_tab_basic_set_non_neg_lexmin(
        __isl_take isl_basic_set *bset)
 {
        struct isl_tab *tab;
        isl_ctx *ctx = isl_basic_set_get_ctx(bset);
        isl_vec *sol;
 
-       tab = tab_for_lexmin(isl_basic_map_from_range(bset), NULL, 0, 0);
+       tab = tab_for_lexmin(bset, NULL, 0, 0);
        if (!tab)
                goto error;
        if (tab->empty)
index cf4fafb..411a4e2 100644 (file)
@@ -120,6 +120,26 @@ void test_parse(struct isl_ctx *ctx)
        str2 = "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
        test_parse_map_equal(ctx, str, str2);
 
+       str = "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
+       str2 = "{ [i,j] -> [min(i,j)] }";
+       test_parse_map_equal(ctx, str, str2);
+
+       str = "{ [i,j] : i != j }";
+       str2 = "{ [i,j] : i < j or i > j }";
+       test_parse_map_equal(ctx, str, str2);
+
+       str = "{ [i,j] : (i+1)*2 >= j }";
+       str2 = "{ [i, j] : j <= 2 + 2i }";
+       test_parse_map_equal(ctx, str, str2);
+
+       str = "{ [i] -> [i > 0 ? 4 : 5] }";
+       str2 = "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
+       test_parse_map_equal(ctx, str, str2);
+
+       str = "[N=2,M] -> { [i=[(M+N)/4]] }";
+       str2 = "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
+       test_parse_map_equal(ctx, str, str2);
+
        test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
        test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
 }
@@ -173,23 +193,23 @@ void test_bounded(struct isl_ctx *ctx)
 void test_construction(struct isl_ctx *ctx)
 {
        isl_int v;
-       struct isl_dim *dim;
+       isl_space *dim;
        struct isl_basic_set *bset;
        struct isl_constraint *c;
 
        isl_int_init(v);
 
-       dim = isl_dim_set_alloc(ctx, 1, 1);
+       dim = isl_space_set_alloc(ctx, 1, 1);
        bset = isl_basic_set_universe(dim);
 
-       c = isl_inequality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_inequality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, -1);
        isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
        isl_int_set_si(v, 1);
        isl_constraint_set_coefficient(c, isl_dim_param, 0, v);
        bset = isl_basic_set_add_constraint(bset, c);
 
-       c = isl_inequality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_inequality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, 1);
        isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
        isl_int_set_si(v, -5);
@@ -235,17 +255,17 @@ void test_dim(struct isl_ctx *ctx)
 void test_div(struct isl_ctx *ctx)
 {
        isl_int v;
-       struct isl_dim *dim;
+       isl_space *dim;
        struct isl_basic_set *bset;
        struct isl_constraint *c;
 
        isl_int_init(v);
 
        /* test 1 */
-       dim = isl_dim_set_alloc(ctx, 0, 3);
+       dim = isl_space_set_alloc(ctx, 0, 3);
        bset = isl_basic_set_universe(dim);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, -1);
        isl_constraint_set_constant(c, v);
        isl_int_set_si(v, 1);
@@ -254,7 +274,7 @@ void test_div(struct isl_ctx *ctx)
        isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
        bset = isl_basic_set_add_constraint(bset, c);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, 1);
        isl_constraint_set_constant(c, v);
        isl_int_set_si(v, -1);
@@ -269,10 +289,10 @@ void test_div(struct isl_ctx *ctx)
        isl_basic_set_free(bset);
 
        /* test 2 */
-       dim = isl_dim_set_alloc(ctx, 0, 3);
+       dim = isl_space_set_alloc(ctx, 0, 3);
        bset = isl_basic_set_universe(dim);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, 1);
        isl_constraint_set_constant(c, v);
        isl_int_set_si(v, -1);
@@ -281,7 +301,7 @@ void test_div(struct isl_ctx *ctx)
        isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
        bset = isl_basic_set_add_constraint(bset, c);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, -1);
        isl_constraint_set_constant(c, v);
        isl_int_set_si(v, 1);
@@ -296,10 +316,10 @@ void test_div(struct isl_ctx *ctx)
        isl_basic_set_free(bset);
 
        /* test 3 */
-       dim = isl_dim_set_alloc(ctx, 0, 3);
+       dim = isl_space_set_alloc(ctx, 0, 3);
        bset = isl_basic_set_universe(dim);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, 1);
        isl_constraint_set_constant(c, v);
        isl_int_set_si(v, -1);
@@ -308,7 +328,7 @@ void test_div(struct isl_ctx *ctx)
        isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
        bset = isl_basic_set_add_constraint(bset, c);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, -3);
        isl_constraint_set_constant(c, v);
        isl_int_set_si(v, 1);
@@ -323,10 +343,10 @@ void test_div(struct isl_ctx *ctx)
        isl_basic_set_free(bset);
 
        /* test 4 */
-       dim = isl_dim_set_alloc(ctx, 0, 3);
+       dim = isl_space_set_alloc(ctx, 0, 3);
        bset = isl_basic_set_universe(dim);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, 2);
        isl_constraint_set_constant(c, v);
        isl_int_set_si(v, -1);
@@ -335,7 +355,7 @@ void test_div(struct isl_ctx *ctx)
        isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
        bset = isl_basic_set_add_constraint(bset, c);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, -1);
        isl_constraint_set_constant(c, v);
        isl_int_set_si(v, 1);
@@ -350,17 +370,17 @@ void test_div(struct isl_ctx *ctx)
        isl_basic_set_free(bset);
 
        /* test 5 */
-       dim = isl_dim_set_alloc(ctx, 0, 3);
+       dim = isl_space_set_alloc(ctx, 0, 3);
        bset = isl_basic_set_universe(dim);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, -1);
        isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
        isl_int_set_si(v, 3);
        isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
        bset = isl_basic_set_add_constraint(bset, c);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, 1);
        isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
        isl_int_set_si(v, -3);
@@ -373,17 +393,17 @@ void test_div(struct isl_ctx *ctx)
        isl_basic_set_free(bset);
 
        /* test 6 */
-       dim = isl_dim_set_alloc(ctx, 0, 3);
+       dim = isl_space_set_alloc(ctx, 0, 3);
        bset = isl_basic_set_universe(dim);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, -1);
        isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
        isl_int_set_si(v, 6);
        isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
        bset = isl_basic_set_add_constraint(bset, c);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, 1);
        isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
        isl_int_set_si(v, -3);
@@ -405,10 +425,10 @@ void test_div(struct isl_ctx *ctx)
         * and we end up with the original equality and div again.
         * Perhaps we can avoid the introduction of this temporary div.
         */
-       dim = isl_dim_set_alloc(ctx, 0, 4);
+       dim = isl_space_set_alloc(ctx, 0, 4);
        bset = isl_basic_set_universe(dim);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, -1);
        isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
        isl_int_set_si(v, -3);
@@ -428,10 +448,10 @@ void test_div(struct isl_ctx *ctx)
        isl_basic_set_free(bset);
 
        /* test 8 */
-       dim = isl_dim_set_alloc(ctx, 0, 5);
+       dim = isl_space_set_alloc(ctx, 0, 5);
        bset = isl_basic_set_universe(dim);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, -1);
        isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
        isl_int_set_si(v, -3);
@@ -442,7 +462,7 @@ void test_div(struct isl_ctx *ctx)
        isl_constraint_set_coefficient(c, isl_dim_set, 4, v);
        bset = isl_basic_set_add_constraint(bset, c);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, -1);
        isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
        isl_int_set_si(v, 1);
@@ -460,10 +480,10 @@ void test_div(struct isl_ctx *ctx)
        isl_basic_set_free(bset);
 
        /* test 9 */
-       dim = isl_dim_set_alloc(ctx, 0, 4);
+       dim = isl_space_set_alloc(ctx, 0, 4);
        bset = isl_basic_set_universe(dim);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, 1);
        isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
        isl_int_set_si(v, -1);
@@ -472,7 +492,7 @@ void test_div(struct isl_ctx *ctx)
        isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
        bset = isl_basic_set_add_constraint(bset, c);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, -1);
        isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
        isl_int_set_si(v, 3);
@@ -490,10 +510,10 @@ void test_div(struct isl_ctx *ctx)
        isl_basic_set_free(bset);
 
        /* test 10 */
-       dim = isl_dim_set_alloc(ctx, 0, 3);
+       dim = isl_space_set_alloc(ctx, 0, 3);
        bset = isl_basic_set_universe(dim);
 
-       c = isl_equality_alloc(isl_basic_set_get_dim(bset));
+       c = isl_equality_alloc(isl_basic_set_get_space(bset));
        isl_int_set_si(v, 1);
        isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
        isl_int_set_si(v, -2);
@@ -1208,10 +1228,10 @@ void test_closure(struct isl_ctx *ctx)
 
 void test_lex(struct isl_ctx *ctx)
 {
-       isl_dim *dim;
+       isl_space *dim;
        isl_map *map;
 
-       dim = isl_dim_alloc(ctx, 0, 0, 0);
+       dim = isl_space_set_alloc(ctx, 0, 0);
        map = isl_map_lex_le(dim);
        assert(!isl_map_is_empty(map));
        isl_map_free(map);
@@ -1220,11 +1240,11 @@ void test_lex(struct isl_ctx *ctx)
 static int consume_lexmin(__isl_take isl_basic_set *dom,
        __isl_take isl_aff_list *list, void *user)
 {
-       isl_dim *dim;
+       isl_space *dim;
        isl_basic_map *bmap;
        isl_map **map = user;
 
-       dim = isl_basic_set_get_dim(dom);
+       dim = isl_basic_set_get_space(dom);
        bmap = isl_basic_map_from_aff_list(dim, list);
        bmap = isl_basic_map_intersect_domain(bmap, dom);
 
@@ -1300,7 +1320,7 @@ void test_lexmin(struct isl_ctx *ctx)
        str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
                                " 8i' <= i and 8i' >= -7 + i }";
        bmap = isl_basic_map_read_from_str(ctx, str, -1);
-       map2 = isl_map_empty(isl_basic_map_get_dim(bmap));
+       map2 = isl_map_empty(isl_basic_map_get_space(bmap));
        isl_basic_map_foreach_lexmin(bmap, &consume_lexmin, &map2);
        map = isl_map_from_basic_map(bmap);
        assert(isl_map_is_equal(map, map2));
@@ -1350,7 +1370,7 @@ static int map_is_equal(__isl_keep isl_map *map, const char *str)
 void test_dep(struct isl_ctx *ctx)
 {
        const char *str;
-       isl_dim *dim;
+       isl_space *dim;
        isl_map *map;
        isl_access_info *ai;
        isl_flow *flow;
@@ -1372,8 +1392,8 @@ void test_dep(struct isl_ctx *ctx)
        ai = isl_access_info_add_source(ai, map, 1, &depth);
 
        flow = isl_access_info_compute_flow(ai);
-       dim = isl_dim_alloc(ctx, 0, 3, 3);
-       mm.must = isl_map_empty(isl_dim_copy(dim));
+       dim = isl_space_alloc(ctx, 0, 3, 3);
+       mm.must = isl_map_empty(isl_space_copy(dim));
        mm.may = isl_map_empty(dim);
 
        isl_flow_foreach(flow, collect_must_may, &mm);
@@ -1402,8 +1422,8 @@ void test_dep(struct isl_ctx *ctx)
        ai = isl_access_info_add_source(ai, map, 0, &depth);
 
        flow = isl_access_info_compute_flow(ai);
-       dim = isl_dim_alloc(ctx, 0, 3, 3);
-       mm.must = isl_map_empty(isl_dim_copy(dim));
+       dim = isl_space_alloc(ctx, 0, 3, 3);
+       mm.must = isl_map_empty(isl_space_copy(dim));
        mm.may = isl_map_empty(dim);
 
        isl_flow_foreach(flow, collect_must_may, &mm);
@@ -1431,8 +1451,8 @@ void test_dep(struct isl_ctx *ctx)
        ai = isl_access_info_add_source(ai, map, 0, &depth);
 
        flow = isl_access_info_compute_flow(ai);
-       dim = isl_dim_alloc(ctx, 0, 3, 3);
-       mm.must = isl_map_empty(isl_dim_copy(dim));
+       dim = isl_space_alloc(ctx, 0, 3, 3);
+       mm.must = isl_map_empty(isl_space_copy(dim));
        mm.may = isl_map_empty(dim);
 
        isl_flow_foreach(flow, collect_must_may, &mm);
@@ -1461,8 +1481,8 @@ void test_dep(struct isl_ctx *ctx)
        ai = isl_access_info_add_source(ai, map, 0, &depth);
 
        flow = isl_access_info_compute_flow(ai);
-       dim = isl_dim_alloc(ctx, 0, 3, 3);
-       mm.must = isl_map_empty(isl_dim_copy(dim));
+       dim = isl_space_alloc(ctx, 0, 3, 3);
+       mm.must = isl_map_empty(isl_space_copy(dim));
        mm.may = isl_map_empty(dim);
 
        isl_flow_foreach(flow, collect_must_may, &mm);
@@ -1491,8 +1511,8 @@ void test_dep(struct isl_ctx *ctx)
        ai = isl_access_info_add_source(ai, map, 0, &depth);
 
        flow = isl_access_info_compute_flow(ai);
-       dim = isl_dim_alloc(ctx, 0, 3, 3);
-       mm.must = isl_map_empty(isl_dim_copy(dim));
+       dim = isl_space_alloc(ctx, 0, 3, 3);
+       mm.must = isl_map_empty(isl_space_copy(dim));
        mm.may = isl_map_empty(dim);
 
        isl_flow_foreach(flow, collect_must_may, &mm);
@@ -1519,8 +1539,8 @@ void test_dep(struct isl_ctx *ctx)
        ai = isl_access_info_add_source(ai, map, 1, &depth);
 
        flow = isl_access_info_compute_flow(ai);
-       dim = isl_dim_alloc(ctx, 0, 5, 5);
-       mm.must = isl_map_empty(isl_dim_copy(dim));
+       dim = isl_space_alloc(ctx, 0, 5, 5);
+       mm.must = isl_map_empty(isl_space_copy(dim));
        mm.may = isl_map_empty(dim);
 
        isl_flow_foreach(flow, collect_must_may, &mm);
@@ -1624,7 +1644,7 @@ void test_pwqp(struct isl_ctx *ctx)
        pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
 
        pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
-                                               isl_dim_set, 1, 1);
+                                               isl_dim_in, 1, 1);
 
        str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
        pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
@@ -1763,13 +1783,13 @@ void test_bound(isl_ctx *ctx)
        str = "{ [[a, b, c, d] -> [e]] -> 0 }";
        pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
        pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
-       assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_set) == 4);
+       assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in) == 4);
        isl_pw_qpolynomial_fold_free(pwf);
 
        str = "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
        pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
        pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
-       assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_set) == 1);
+       assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in) == 1);
        isl_pw_qpolynomial_fold_free(pwf);
 }
 
@@ -1879,7 +1899,7 @@ int test_one_schedule(isl_ctx *ctx, const char *d, const char *w,
        W = isl_union_map_intersect_domain(W, isl_union_set_copy(D));
        R = isl_union_map_intersect_domain(R, isl_union_set_copy(D));
 
-       empty = isl_union_map_empty(isl_union_map_get_dim(S));
+       empty = isl_union_map_empty(isl_union_map_get_space(S));
         isl_union_map_compute_flow(isl_union_map_copy(R),
                                   isl_union_map_copy(W), empty,
                                   isl_union_map_copy(S),
@@ -1924,19 +1944,19 @@ int test_one_schedule(isl_ctx *ctx, const char *d, const char *w,
        } else {
                delta_set = isl_set_from_union_set(delta);
 
-               slice = isl_set_universe(isl_set_get_dim(delta_set));
+               slice = isl_set_universe(isl_set_get_space(delta_set));
                for (i = 0; i < tilable; ++i)
                        slice = isl_set_lower_bound_si(slice, isl_dim_set, i, 0);
                is_tilable = isl_set_is_subset(delta_set, slice);
                isl_set_free(slice);
 
-               slice = isl_set_universe(isl_set_get_dim(delta_set));
+               slice = isl_set_universe(isl_set_get_space(delta_set));
                for (i = 0; i < parallel; ++i)
                        slice = isl_set_fix_si(slice, isl_dim_set, i, 0);
                is_parallel = isl_set_is_subset(delta_set, slice);
                isl_set_free(slice);
 
-               origin = isl_set_universe(isl_set_get_dim(delta_set));
+               origin = isl_set_universe(isl_set_get_space(delta_set));
                for (i = 0; i < isl_set_dim(origin, isl_dim_set); ++i)
                        origin = isl_set_fix_si(origin, isl_dim_set, i, 0);
 
@@ -2164,6 +2184,21 @@ int test_schedule(isl_ctx *ctx)
        if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
                return -1;
 
+       D = "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
+                               "k <= -1 + n and k >= 0 }";
+       W = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "                                                  "k <= -1 + n and k >= 0 }";
+       R = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
+                                       "k <= -1 + n and k >= 0; "
+                   "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
+                                       "k <= -1 + n and k >= 0; "
+                   "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
+                                       "k <= -1 + n and k >= 0 }";
+       S = "[n] -> { S_0[j, k] -> [2, j, k] }";
+       ctx->opt->schedule_outer_zero_distance = 1;
+       if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
+               return -1;
+       ctx->opt->schedule_outer_zero_distance = 0;
+
        return test_special_schedule(ctx);
 }
 
@@ -2222,22 +2257,22 @@ int test_aff(isl_ctx *ctx)
 {
        const char *str;
        isl_set *set;
-       isl_dim *dim;
+       isl_space *dim;
        isl_local_space *ls;
        isl_aff *aff;
        int zero;
 
-       dim = isl_dim_set_alloc(ctx, 0, 1);
-       ls = isl_local_space_from_dim(dim);
-       aff = isl_aff_zero(ls);
+       dim = isl_space_set_alloc(ctx, 0, 1);
+       ls = isl_local_space_from_space(dim);
+       aff = isl_aff_zero_on_domain(ls);
 
-       aff = isl_aff_add_coefficient_si(aff, isl_dim_set, 0, 1);
+       aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
        aff = isl_aff_scale_down_ui(aff, 3);
        aff = isl_aff_floor(aff);
-       aff = isl_aff_add_coefficient_si(aff, isl_dim_set, 0, 1);
+       aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
        aff = isl_aff_scale_down_ui(aff, 2);
        aff = isl_aff_floor(aff);
-       aff = isl_aff_add_coefficient_si(aff, isl_dim_set, 0, 1);
+       aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
 
        str = "{ [10] }";
        set = isl_set_read_from_str(ctx, str, 0);
@@ -2259,19 +2294,20 @@ int test_dim_max(isl_ctx *ctx)
 {
        int equal;
        const char *str;
-       isl_map *map, *map2;
+       isl_set *set1, *set2;
        isl_set *set;
+       isl_map *map;
        isl_pw_aff *pwaff;
 
        str = "[N] -> { [i] : 0 <= i <= min(N,10) }";
        set = isl_set_read_from_str(ctx, str, -1);
        pwaff = isl_set_dim_max(set, 0);
-       map = isl_map_from_pw_aff(pwaff);
-       str = "[N] -> { [] -> [10] : N >= 10; [] -> [N] : N <= 9 and N >= 0 }";
-       map2 = isl_map_read_from_str(ctx, str, -1);
-       equal = isl_map_is_equal(map, map2);
-       isl_map_free(map);
-       isl_map_free(map2);
+       set1 = isl_set_from_pw_aff(pwaff);
+       str = "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
+       set2 = isl_set_read_from_str(ctx, str, -1);
+       equal = isl_set_is_equal(set1, set2);
+       isl_set_free(set1);
+       isl_set_free(set2);
        if (equal < 0)
                return -1;
        if (!equal)
@@ -2280,12 +2316,12 @@ int test_dim_max(isl_ctx *ctx)
        str = "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
        set = isl_set_read_from_str(ctx, str, -1);
        pwaff = isl_set_dim_max(set, 0);
-       map = isl_map_from_pw_aff(pwaff);
-       str = "[N] -> { [] -> [6 + N] : -6 <= N <= 5; [] -> [2N] : N >= 6 }";
-       map2 = isl_map_read_from_str(ctx, str, -1);
-       equal = isl_map_is_equal(map, map2);
-       isl_map_free(map);
-       isl_map_free(map2);
+       set1 = isl_set_from_pw_aff(pwaff);
+       str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
+       set2 = isl_set_read_from_str(ctx, str, -1);
+       equal = isl_set_is_equal(set1, set2);
+       isl_set_free(set1);
+       isl_set_free(set2);
        if (equal < 0)
                return -1;
        if (!equal)
@@ -2294,12 +2330,12 @@ int test_dim_max(isl_ctx *ctx)
        str = "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
        set = isl_set_read_from_str(ctx, str, -1);
        pwaff = isl_set_dim_max(set, 0);
-       map = isl_map_from_pw_aff(pwaff);
-       str = "[N] -> { [] -> [6 + N] : -6 <= N <= 5; [] -> [2N] : N >= 6 }";
-       map2 = isl_map_read_from_str(ctx, str, -1);
-       equal = isl_map_is_equal(map, map2);
-       isl_map_free(map);
-       isl_map_free(map2);
+       set1 = isl_set_from_pw_aff(pwaff);
+       str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
+       set2 = isl_set_read_from_str(ctx, str, -1);
+       equal = isl_set_is_equal(set1, set2);
+       isl_set_free(set1);
+       isl_set_free(set2);
        if (equal < 0)
                return -1;
        if (!equal)
@@ -2311,21 +2347,21 @@ int test_dim_max(isl_ctx *ctx)
        set = isl_map_range(map);
 
        pwaff = isl_set_dim_max(isl_set_copy(set), 0);
-       map = isl_map_from_pw_aff(pwaff);
-       str = "[N,M] -> { [] -> [([(N-1)/16])] : M,N > 0 }";
-       map2 = isl_map_read_from_str(ctx, str, -1);
-       equal = isl_map_is_equal(map, map2);
-       isl_map_free(map);
-       isl_map_free(map2);
+       set1 = isl_set_from_pw_aff(pwaff);
+       str = "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
+       set2 = isl_set_read_from_str(ctx, str, -1);
+       equal = isl_set_is_equal(set1, set2);
+       isl_set_free(set1);
+       isl_set_free(set2);
 
        pwaff = isl_set_dim_max(isl_set_copy(set), 3);
-       map = isl_map_from_pw_aff(pwaff);
-       str = "[N,M] -> { [] -> [t] : t = min(M-1,15) and M,N > 0 }";
-       map2 = isl_map_read_from_str(ctx, str, -1);
+       set1 = isl_set_from_pw_aff(pwaff);
+       str = "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
+       set2 = isl_set_read_from_str(ctx, str, -1);
        if (equal >= 0 && equal)
-               equal = isl_map_is_equal(map, map2);
-       isl_map_free(map);
-       isl_map_free(map2);
+               equal = isl_set_is_equal(set1, set2);
+       isl_set_free(set1);
+       isl_set_free(set2);
 
        isl_set_free(set);
 
index 53f5d14..ef3e591 100644 (file)
@@ -12,7 +12,7 @@
 #include <isl_map_private.h>
 #include <isl/map.h>
 #include <isl/seq.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl/lp.h>
 #include <isl/union_map.h>
 #include <isl_mat_private.h>
@@ -51,7 +51,7 @@ int isl_union_map_is_transitively_closed(__isl_keep isl_union_map *umap)
 static __isl_give isl_map *set_path_length(__isl_take isl_map *map,
        int exactly, int length)
 {
-       struct isl_dim *dim;
+       isl_space *dim;
        struct isl_basic_map *bmap;
        unsigned d;
        unsigned nparam;
@@ -61,10 +61,10 @@ static __isl_give isl_map *set_path_length(__isl_take isl_map *map,
        if (!map)
                return NULL;
 
-       dim = isl_map_get_dim(map);
-       d = isl_dim_size(dim, isl_dim_in);
-       nparam = isl_dim_size(dim, isl_dim_param);
-       bmap = isl_basic_map_alloc_dim(dim, 0, 1, 1);
+       dim = isl_map_get_space(map);
+       d = isl_space_dim(dim, isl_dim_in);
+       nparam = isl_space_dim(dim, isl_dim_param);
+       bmap = isl_basic_map_alloc_space(dim, 0, 1, 1);
        if (exactly) {
                k = isl_basic_map_alloc_equality(bmap);
                c = bmap->eq[k];
@@ -176,7 +176,7 @@ static int check_exactness(__isl_take isl_map *map, __isl_take isl_map *app,
        app = isl_map_project_out(app, isl_dim_in, d, 1);
        app = isl_map_project_out(app, isl_dim_out, d, 1);
 
-       app = isl_map_reset_dim(app, isl_map_get_dim(map));
+       app = isl_map_reset_space(app, isl_map_get_space(map));
 
        test = isl_map_apply_range(isl_map_copy(map), isl_map_copy(app));
        test = isl_map_union(test, isl_map_copy(map));
@@ -210,7 +210,7 @@ static int check_exactness(__isl_take isl_map *map, __isl_take isl_map *app,
  * For any element in this relation, the number of steps taken
  * is equal to the difference in the final coordinates.
  */
-static __isl_give isl_map *path_along_steps(__isl_take isl_dim *dim,
+static __isl_give isl_map *path_along_steps(__isl_take isl_space *dim,
        __isl_keep isl_mat *steps)
 {
        int i, j, k;
@@ -222,11 +222,11 @@ static __isl_give isl_map *path_along_steps(__isl_take isl_dim *dim,
        if (!dim || !steps)
                goto error;
 
-       d = isl_dim_size(dim, isl_dim_in);
+       d = isl_space_dim(dim, isl_dim_in);
        n = steps->n_row;
-       nparam = isl_dim_size(dim, isl_dim_param);
+       nparam = isl_space_dim(dim, isl_dim_param);
 
-       path = isl_basic_map_alloc_dim(isl_dim_copy(dim), n, d, n);
+       path = isl_basic_map_alloc_space(isl_space_copy(dim), n, d, n);
 
        for (i = 0; i < n; ++i) {
                k = isl_basic_map_alloc_div(path);
@@ -260,13 +260,13 @@ static __isl_give isl_map *path_along_steps(__isl_take isl_dim *dim,
                isl_int_set_si(path->ineq[k][1 + nparam + 2 * d + i], 1);
        }
 
-       isl_dim_free(dim);
+       isl_space_free(dim);
 
        path = isl_basic_map_simplify(path);
        path = isl_basic_map_finalize(path);
        return isl_map_from_basic_map(path);
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_basic_map_free(path);
        return NULL;
 }
@@ -436,7 +436,7 @@ static int empty_path_is_identity(__isl_keep isl_basic_map *path, unsigned pos)
                goto error;
        isl_seq_clr(test->eq[k], 1 + isl_basic_map_total_dim(test));
        isl_int_set_si(test->eq[k][pos], 1);
-       id = isl_basic_map_identity(isl_basic_map_get_dim(path));
+       id = isl_basic_map_identity(isl_basic_map_get_space(path));
        is_id = isl_basic_map_is_equal(test, id);
        isl_basic_map_free(test);
        isl_basic_map_free(id);
@@ -556,7 +556,7 @@ error:
  *
  * to the constructed relation.
  */
-static __isl_give isl_map *path_along_delta(__isl_take isl_dim *dim,
+static __isl_give isl_map *path_along_delta(__isl_take isl_space *dim,
        __isl_take isl_basic_set *delta)
 {
        isl_basic_map *path = NULL;
@@ -574,7 +574,7 @@ static __isl_give isl_map *path_along_delta(__isl_take isl_dim *dim,
        n_div = isl_basic_set_dim(delta, isl_dim_div);
        d = isl_basic_set_dim(delta, isl_dim_set);
        nparam = isl_basic_set_dim(delta, isl_dim_param);
-       path = isl_basic_map_alloc_dim(isl_dim_copy(dim), n_div + d + 1,
+       path = isl_basic_map_alloc_space(isl_space_copy(dim), n_div + d + 1,
                        d + 1 + delta->n_eq, delta->n_eq + delta->n_ineq + 1);
        off = 1 + nparam + 2 * (d + 1) + n_div;
 
@@ -604,11 +604,11 @@ static __isl_give isl_map *path_along_delta(__isl_take isl_dim *dim,
        path = add_delta_constraints(path, delta, off, nparam, d,
                                     div_purity, 0, &impurity);
        if (impurity) {
-               isl_dim *dim = isl_basic_set_get_dim(delta);
+               isl_space *dim = isl_basic_set_get_space(delta);
                delta = isl_basic_set_project_out(delta,
                                                  isl_dim_param, 0, nparam);
                delta = isl_basic_set_add(delta, isl_dim_param, nparam);
-               delta = isl_basic_set_reset_dim(delta, dim);
+               delta = isl_basic_set_reset_space(delta, dim);
                if (!delta)
                        goto error;
                path = isl_basic_map_extend_constraints(path, delta->n_eq,
@@ -636,13 +636,13 @@ static __isl_give isl_map *path_along_delta(__isl_take isl_dim *dim,
        isl_basic_set_free(delta);
        path = isl_basic_map_finalize(path);
        if (is_id) {
-               isl_dim_free(dim);
+               isl_space_free(dim);
                return isl_map_from_basic_map(path);
        }
        return isl_basic_map_union(path, isl_basic_map_identity(dim));
 error:
        free(div_purity);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_basic_set_free(delta);
        isl_basic_map_free(path);
        return NULL;
@@ -655,7 +655,7 @@ error:
  *
  *     { [x,x_s] -> [y,y_s] : k = y_s - x_s > 0 }
  */
-static __isl_give isl_map *equate_parameter_to_length(__isl_take isl_dim *dim,
+static __isl_give isl_map *equate_parameter_to_length(__isl_take isl_space *dim,
        unsigned param)
 {
        struct isl_basic_map *bmap;
@@ -663,9 +663,9 @@ static __isl_give isl_map *equate_parameter_to_length(__isl_take isl_dim *dim,
        unsigned nparam;
        int k;
 
-       d = isl_dim_size(dim, isl_dim_in);
-       nparam = isl_dim_size(dim, isl_dim_param);
-       bmap = isl_basic_map_alloc_dim(dim, 0, 1, 1);
+       d = isl_space_dim(dim, isl_dim_in);
+       nparam = isl_space_dim(dim, isl_dim_param);
+       bmap = isl_basic_map_alloc_space(dim, 0, 1, 1);
        k = isl_basic_map_alloc_equality(bmap);
        if (k < 0)
                goto error;
@@ -744,7 +744,7 @@ static int is_acyclic(__isl_take isl_map *path)
  * Since each of these paths performs an addition, composition is
  * symmetric and we can simply compose all resulting paths in any order.
  */
-static __isl_give isl_map *construct_extended_path(__isl_take isl_dim *dim,
+static __isl_give isl_map *construct_extended_path(__isl_take isl_space *dim,
        __isl_keep isl_map *map, int *project)
 {
        struct isl_mat *steps = NULL;
@@ -754,7 +754,7 @@ static __isl_give isl_map *construct_extended_path(__isl_take isl_dim *dim,
 
        d = isl_map_dim(map, isl_dim_in);
 
-       path = isl_map_identity(isl_dim_copy(dim));
+       path = isl_map_identity(isl_space_copy(dim));
 
        steps = isl_mat_alloc(map->ctx, map->n, d);
        if (!steps)
@@ -782,7 +782,7 @@ static __isl_give isl_map *construct_extended_path(__isl_take isl_dim *dim,
 
                if (j < d) {
                        path = isl_map_apply_range(path,
-                               path_along_delta(isl_dim_copy(dim), delta));
+                               path_along_delta(isl_space_copy(dim), delta));
                        path = isl_map_coalesce(path);
                } else {
                        isl_basic_set_free(delta);
@@ -793,7 +793,7 @@ static __isl_give isl_map *construct_extended_path(__isl_take isl_dim *dim,
        if (n > 0) {
                steps->n_row = n;
                path = isl_map_apply_range(path,
-                               path_along_steps(isl_dim_copy(dim), steps));
+                               path_along_steps(isl_space_copy(dim), steps));
        }
 
        if (project && *project) {
@@ -802,11 +802,11 @@ static __isl_give isl_map *construct_extended_path(__isl_take isl_dim *dim,
                        goto error;
        }
 
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_mat_free(steps);
        return path;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_mat_free(steps);
        isl_map_free(path);
        return NULL;
@@ -817,7 +817,7 @@ static int isl_set_overlaps(__isl_keep isl_set *set1, __isl_keep isl_set *set2)
        isl_set *i;
        int no_overlap;
 
-       if (!isl_dim_tuple_match(set1->dim, isl_dim_set, set2->dim, isl_dim_set))
+       if (!isl_space_tuple_match(set1->dim, isl_dim_set, set2->dim, isl_dim_set))
                return 0;
 
        i = isl_set_intersect(isl_set_copy(set1), isl_set_copy(set2));
@@ -846,7 +846,7 @@ static int isl_set_overlaps(__isl_keep isl_set *set1, __isl_keep isl_set *set2)
  *                             x in dom R and x + d in ran R and
  *                             \sum_i k_i >= 1 }
  */
-static __isl_give isl_map *construct_component(__isl_take isl_dim *dim,
+static __isl_give isl_map *construct_component(__isl_take isl_space *dim,
        __isl_keep isl_map *map, int *exact, int project)
 {
        struct isl_set *domain = NULL;
@@ -861,7 +861,7 @@ static __isl_give isl_map *construct_component(__isl_take isl_dim *dim,
        if (!isl_set_overlaps(domain, range)) {
                isl_set_free(domain);
                isl_set_free(range);
-               isl_dim_free(dim);
+               isl_space_free(dim);
 
                map = isl_map_copy(map);
                map = isl_map_add_dims(map, isl_dim_in, 1);
@@ -873,7 +873,7 @@ static __isl_give isl_map *construct_component(__isl_take isl_dim *dim,
        app = isl_map_add_dims(app, isl_dim_in, 1);
        app = isl_map_add_dims(app, isl_dim_out, 1);
 
-       path = construct_extended_path(isl_dim_copy(dim), map,
+       path = construct_extended_path(isl_space_copy(dim), map,
                                        exact && *exact ? &project : NULL);
        app = isl_map_intersect(app, path);
 
@@ -882,11 +882,11 @@ static __isl_give isl_map *construct_component(__isl_take isl_dim *dim,
                                      project)) < 0)
                goto error;
 
-       isl_dim_free(dim);
+       isl_space_free(dim);
        app = set_path_length(app, 0, 1);
        return app;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_map_free(app);
        return NULL;
 }
@@ -895,7 +895,7 @@ error:
  * the final coordinates.
  */
 static __isl_give isl_map *construct_projected_component(
-       __isl_take isl_dim *dim,
+       __isl_take isl_space *dim,
        __isl_keep isl_map *map, int *exact, int project)
 {
        isl_map *app;
@@ -903,7 +903,7 @@ static __isl_give isl_map *construct_projected_component(
 
        if (!dim)
                return NULL;
-       d = isl_dim_size(dim, isl_dim_in);
+       d = isl_space_dim(dim, isl_dim_in);
 
        app = construct_component(dim, map, exact, project);
        if (project) {
@@ -918,7 +918,7 @@ static __isl_give isl_map *construct_projected_component(
  * with path lengths greater than or equal to zero and with
  * domain and range equal to "dom".
  */
-static __isl_give isl_map *q_closure(__isl_take isl_dim *dim,
+static __isl_give isl_map *q_closure(__isl_take isl_space *dim,
        __isl_take isl_set *dom, __isl_keep isl_basic_map *bmap, int *exact)
 {
        int project = 1;
@@ -1093,7 +1093,7 @@ static __isl_give isl_map *compose(__isl_keep isl_map *map, int i,
        int j;
        isl_map *comp;
 
-       comp = isl_map_empty(isl_map_get_dim(map));
+       comp = isl_map_empty(isl_map_get_space(map));
        for (j = 0; j < map->n; ++j) {
                isl_map *map_j;
 
@@ -1133,7 +1133,7 @@ static __isl_give isl_map *compose(__isl_keep isl_map *map, int i,
  * depending on whether left or right are NULL.
  */
 static __isl_give isl_map *compute_incremental(
-       __isl_take isl_dim *dim, __isl_keep isl_map *map,
+       __isl_take isl_space *dim, __isl_keep isl_map *map,
        int i, __isl_take isl_map *qc, int *left, int *right, int *exact)
 {
        isl_map *map_i;
@@ -1145,7 +1145,7 @@ static __isl_give isl_map *compute_incremental(
        isl_assert(map->ctx, left || right, goto error);
 
        map_i = isl_map_from_basic_map(isl_basic_map_copy(map->p[i]));
-       tc = construct_projected_component(isl_dim_copy(dim), map_i,
+       tc = construct_projected_component(isl_space_copy(dim), map_i,
                                                exact, 1);
        isl_map_free(map_i);
 
@@ -1153,26 +1153,26 @@ static __isl_give isl_map *compute_incremental(
                qc = isl_map_transitive_closure(qc, exact);
 
        if (!*exact) {
-               isl_dim_free(dim);
+               isl_space_free(dim);
                isl_map_free(tc);
                isl_map_free(qc);
-               return isl_map_universe(isl_map_get_dim(map));
+               return isl_map_universe(isl_map_get_space(map));
        }
 
        if (!left || !right)
                rtc = isl_map_union(isl_map_copy(tc),
-                                   isl_map_identity(isl_map_get_dim(tc)));
+                                   isl_map_identity(isl_map_get_space(tc)));
        if (!right)
                qc = isl_map_apply_range(rtc, qc);
        if (!left)
                qc = isl_map_apply_range(qc, rtc);
        qc = isl_map_union(tc, qc);
 
-       isl_dim_free(dim);
+       isl_space_free(dim);
 
        return qc;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_map_free(qc);
        return NULL;
 }
@@ -1192,7 +1192,7 @@ error:
  * after computing the integer divisions, is smaller than the number
  * of basic maps in the input map.
  */
-static int incemental_on_entire_domain(__isl_keep isl_dim *dim,
+static int incemental_on_entire_domain(__isl_keep isl_space *dim,
        __isl_keep isl_map *map,
        isl_set **dom, isl_set **ran, int *left, int *right,
        __isl_give isl_map **res)
@@ -1223,7 +1223,7 @@ static int incemental_on_entire_domain(__isl_keep isl_dim *dim,
                                        isl_basic_map_copy(map->p[i])));
                ran[i] = isl_set_from_basic_set(isl_basic_map_range(
                                        isl_basic_map_copy(map->p[i])));
-               qc = q_closure(isl_dim_copy(dim), isl_set_copy(C),
+               qc = q_closure(isl_space_copy(dim), isl_set_copy(C),
                                map->p[i], &exact_i);
                if (!qc)
                        goto error;
@@ -1250,7 +1250,7 @@ static int incemental_on_entire_domain(__isl_keep isl_dim *dim,
                        isl_map_free(qc);
                        continue;
                }
-               *res = compute_incremental(isl_dim_copy(dim), map, i, qc,
+               *res = compute_incremental(isl_space_copy(dim), map, i, qc,
                                left, right, &exact_i);
                if (!*res)
                        goto error;
@@ -1276,7 +1276,7 @@ error:
  * with C either the simple hull of the domain and range of the entire
  * map or the simple hull of domain and range of map_i.
  */
-static __isl_give isl_map *incremental_closure(__isl_take isl_dim *dim,
+static __isl_give isl_map *incremental_closure(__isl_take isl_space *dim,
        __isl_keep isl_map *map, int *exact, int project)
 {
        int i;
@@ -1339,7 +1339,7 @@ static __isl_give isl_map *incremental_closure(__isl_take isl_dim *dim,
                                goto error;
                        continue;
                }
-               qc = q_closure(isl_dim_copy(dim), C, map->p[i], &exact_i);
+               qc = q_closure(isl_space_copy(dim), C, map->p[i], &exact_i);
                if (!qc)
                        goto error;
                if (!exact_i) {
@@ -1364,7 +1364,7 @@ static __isl_give isl_map *incremental_closure(__isl_take isl_dim *dim,
                        isl_map_free(qc);
                        continue;
                }
-               res = compute_incremental(isl_dim_copy(dim), map, i, qc,
+               res = compute_incremental(isl_space_copy(dim), map, i, qc,
                                (comp & LEFT) ? left : NULL,
                                (comp & RIGHT) ? right : NULL, &exact_i);
                if (!res)
@@ -1385,7 +1385,7 @@ static __isl_give isl_map *incremental_closure(__isl_take isl_dim *dim,
        free(right);
 
        if (res) {
-               isl_dim_free(dim);
+               isl_space_free(dim);
                return res;
        }
 
@@ -1401,7 +1401,7 @@ error:
        free(ran);
        free(left);
        free(right);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -1454,7 +1454,7 @@ error:
 static int add_length(__isl_keep isl_map *map, isl_map ***grid, int n)
 {
        int i, j, k;
-       isl_dim *dim;
+       isl_space *dim;
        isl_basic_map *bstep;
        isl_map *step;
        unsigned nparam;
@@ -1462,13 +1462,13 @@ static int add_length(__isl_keep isl_map *map, isl_map ***grid, int n)
        if (!map)
                return -1;
 
-       dim = isl_map_get_dim(map);
-       nparam = isl_dim_size(dim, isl_dim_param);
-       dim = isl_dim_drop(dim, isl_dim_in, 0, isl_dim_size(dim, isl_dim_in));
-       dim = isl_dim_drop(dim, isl_dim_out, 0, isl_dim_size(dim, isl_dim_out));
-       dim = isl_dim_add(dim, isl_dim_in, 1);
-       dim = isl_dim_add(dim, isl_dim_out, 1);
-       bstep = isl_basic_map_alloc_dim(dim, 0, 1, 0);
+       dim = isl_map_get_space(map);
+       nparam = isl_space_dim(dim, isl_dim_param);
+       dim = isl_space_drop_dims(dim, isl_dim_in, 0, isl_space_dim(dim, isl_dim_in));
+       dim = isl_space_drop_dims(dim, isl_dim_out, 0, isl_space_dim(dim, isl_dim_out));
+       dim = isl_space_add_dims(dim, isl_dim_in, 1);
+       dim = isl_space_add_dims(dim, isl_dim_out, 1);
+       bstep = isl_basic_map_alloc_space(dim, 0, 1, 0);
        k = isl_basic_map_alloc_equality(bstep);
        if (k < 0) {
                isl_basic_map_free(bstep);
@@ -1552,7 +1552,7 @@ static void floyd_warshall_iterate(isl_map ***grid, int n, int *exact)
  * the input relation by the cross product with the unit length relation
  * { [i] -> [i + 1] }.
  */
-static __isl_give isl_map *floyd_warshall_with_groups(__isl_take isl_dim *dim,
+static __isl_give isl_map *floyd_warshall_with_groups(__isl_take isl_space *dim,
        __isl_keep isl_map *map, int *exact, int project, int *group, int n)
 {
        int i, j, k;
@@ -1575,7 +1575,7 @@ static __isl_give isl_map *floyd_warshall_with_groups(__isl_take isl_dim *dim,
                if (!grid[i])
                        goto error;
                for (j = 0; j < n; ++j)
-                       grid[i][j] = isl_map_empty(isl_map_get_dim(map));
+                       grid[i][j] = isl_map_empty(isl_map_get_space(map));
        }
 
        for (k = 0; k < map->n; ++k) {
@@ -1591,7 +1591,7 @@ static __isl_give isl_map *floyd_warshall_with_groups(__isl_take isl_dim *dim,
 
        floyd_warshall_iterate(grid, n, exact);
 
-       app = isl_map_empty(isl_map_get_dim(map));
+       app = isl_map_empty(isl_map_get_space(map));
 
        for (i = 0; i < n; ++i) {
                for (j = 0; j < n; ++j)
@@ -1601,7 +1601,7 @@ static __isl_give isl_map *floyd_warshall_with_groups(__isl_take isl_dim *dim,
        free(grid);
 
        free(group);
-       isl_dim_free(dim);
+       isl_space_free(dim);
 
        return app;
 error:
@@ -1615,7 +1615,7 @@ error:
                }
        free(grid);
        free(group);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -1691,7 +1691,7 @@ error:
  * calls inside the Floyd-Warshall algorithm typically result in
  * non-linear path lengths quite quickly.
  */
-static __isl_give isl_map *floyd_warshall(__isl_take isl_dim *dim,
+static __isl_give isl_map *floyd_warshall(__isl_take isl_space *dim,
        __isl_keep isl_map *map, int *exact, int project)
 {
        int i;
@@ -1715,7 +1715,7 @@ static __isl_give isl_map *floyd_warshall(__isl_take isl_dim *dim,
 
        return floyd_warshall_with_groups(dim, map, exact, project, group, n);
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -1822,7 +1822,7 @@ static int basic_map_follows(__isl_keep isl_basic_map *bmap1,
        struct isl_map *map21 = NULL;
        int subset;
 
-       if (!isl_dim_tuple_match(bmap1->dim, isl_dim_in, bmap2->dim, isl_dim_out))
+       if (!isl_space_tuple_match(bmap1->dim, isl_dim_in, bmap2->dim, isl_dim_out))
                return 0;
 
        map21 = isl_map_from_basic_map(
@@ -1837,8 +1837,8 @@ static int basic_map_follows(__isl_keep isl_basic_map *bmap1,
                return 0;
        }
 
-       if (!isl_dim_tuple_match(bmap1->dim, isl_dim_in, bmap1->dim, isl_dim_out) ||
-           !isl_dim_tuple_match(bmap2->dim, isl_dim_in, bmap2->dim, isl_dim_out)) {
+       if (!isl_space_tuple_match(bmap1->dim, isl_dim_in, bmap1->dim, isl_dim_out) ||
+           !isl_space_tuple_match(bmap2->dim, isl_dim_in, bmap2->dim, isl_dim_out)) {
                isl_map_free(map21);
                return 1;
        }
@@ -1973,7 +1973,7 @@ error:
  * order, at each join also taking in the union of both arguments
  * to allow for paths that do not go through one of the two arguments.
  */
-static __isl_give isl_map *construct_power_components(__isl_take isl_dim *dim,
+static __isl_give isl_map *construct_power_components(__isl_take isl_space *dim,
        __isl_keep isl_map *map, int *exact, int project)
 {
        int i, n, c;
@@ -1999,21 +1999,21 @@ static __isl_give isl_map *construct_power_components(__isl_take isl_dim *dim,
        i = 0;
        n = map->n;
        if (project)
-               path = isl_map_empty(isl_map_get_dim(map));
+               path = isl_map_empty(isl_map_get_space(map));
        else
-               path = isl_map_empty(isl_dim_copy(dim));
+               path = isl_map_empty(isl_space_copy(dim));
        path = anonymize(path);
        while (n) {
                struct isl_map *comp;
                isl_map *path_comp, *path_comb;
-               comp = isl_map_alloc_dim(isl_map_get_dim(map), n, 0);
+               comp = isl_map_alloc_space(isl_map_get_space(map), n, 0);
                while (s->order[i] != -1) {
                        comp = isl_map_add_basic_map(comp,
                                    isl_basic_map_copy(map->p[s->order[i]]));
                        --n;
                        ++i;
                }
-               path_comp = floyd_warshall(isl_dim_copy(dim),
+               path_comp = floyd_warshall(isl_space_copy(dim),
                                                comp, exact, project);
                path_comp = anonymize(path_comp);
                path_comb = isl_map_apply_range(isl_map_copy(path),
@@ -2039,12 +2039,12 @@ static __isl_give isl_map *construct_power_components(__isl_take isl_dim *dim,
        }
 
        basic_map_sort_free(s);
-       isl_dim_free(dim);
+       isl_space_free(dim);
 
        return path;
 error:
        basic_map_sort_free(s);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_map_free(path);
        return NULL;
 }
@@ -2082,22 +2082,22 @@ static __isl_give isl_map *construct_power(__isl_keep isl_map *map,
        int *exact, int project)
 {
        struct isl_map *app = NULL;
-       struct isl_dim *dim = NULL;
+       isl_space *dim = NULL;
        unsigned d;
 
        if (!map)
                return NULL;
 
-       dim = isl_map_get_dim(map);
+       dim = isl_map_get_space(map);
 
-       d = isl_dim_size(dim, isl_dim_in);
-       dim = isl_dim_add(dim, isl_dim_in, 1);
-       dim = isl_dim_add(dim, isl_dim_out, 1);
+       d = isl_space_dim(dim, isl_dim_in);
+       dim = isl_space_add_dims(dim, isl_dim_in, 1);
+       dim = isl_space_add_dims(dim, isl_dim_out, 1);
 
-       app = construct_power_components(isl_dim_copy(dim), map,
+       app = construct_power_components(isl_space_copy(dim), map,
                                        exact, project);
 
-       isl_dim_free(dim);
+       isl_space_free(dim);
 
        return app;
 }
@@ -2146,8 +2146,8 @@ error:
  */
 __isl_give isl_map *isl_map_power(__isl_take isl_map *map, int *exact)
 {
-       isl_dim *target_dim;
-       isl_dim *dim;
+       isl_space *target_dim;
+       isl_space *dim;
        isl_map *diff;
        unsigned d;
        unsigned param;
@@ -2168,15 +2168,15 @@ __isl_give isl_map *isl_map_power(__isl_take isl_map *map, int *exact)
                return map;
        }
 
-       target_dim = isl_map_get_dim(map);
-       target_dim = isl_dim_from_range(isl_dim_wrap(target_dim));
-       target_dim = isl_dim_add(target_dim, isl_dim_in, 1);
-       target_dim = isl_dim_set_name(target_dim, isl_dim_in, 0, "k");
+       target_dim = isl_map_get_space(map);
+       target_dim = isl_space_from_range(isl_space_wrap(target_dim));
+       target_dim = isl_space_add_dims(target_dim, isl_dim_in, 1);
+       target_dim = isl_space_set_dim_name(target_dim, isl_dim_in, 0, "k");
 
        map = map_power(map, exact, 0);
 
        map = isl_map_add_dims(map, isl_dim_param, 1);
-       dim = isl_map_get_dim(map);
+       dim = isl_map_get_space(map);
        diff = equate_parameter_to_length(dim, param);
        map = isl_map_intersect(map, diff);
        map = isl_map_project_out(map, isl_dim_in, d, 1);
@@ -2184,7 +2184,7 @@ __isl_give isl_map *isl_map_power(__isl_take isl_map *map, int *exact)
        map = isl_map_from_range(isl_map_wrap(map));
        map = isl_map_move_dims(map, isl_dim_in, 0, isl_dim_param, param, 1);
 
-       map = isl_map_reset_dim(map, target_dim);
+       map = isl_map_reset_space(map, target_dim);
 
        return map;
 }
@@ -2201,7 +2201,7 @@ __isl_give isl_map *isl_map_power(__isl_take isl_map *map, int *exact)
 __isl_give isl_map *isl_map_reaching_path_lengths(__isl_take isl_map *map,
        int *exact)
 {
-       isl_dim *dim;
+       isl_space *dim;
        isl_map *diff;
        unsigned d;
        unsigned param;
@@ -2226,7 +2226,7 @@ __isl_give isl_map *isl_map_reaching_path_lengths(__isl_take isl_map *map,
        map = map_power(map, exact, 0);
 
        map = isl_map_add_dims(map, isl_dim_param, 1);
-       dim = isl_map_get_dim(map);
+       dim = isl_map_get_space(map);
        diff = equate_parameter_to_length(dim, param);
        map = isl_map_intersect(map, diff);
        map = isl_map_project_out(map, isl_dim_in, 0, d + 1);
@@ -2321,7 +2321,7 @@ static __isl_give isl_map *box_closure_on_domain(__isl_take isl_map *map,
        unsigned d;
        unsigned nparam;
        unsigned total;
-       isl_dim *dim;
+       isl_space *dim;
        isl_set *delta;
        isl_map *app = NULL;
        isl_basic_set *aff = NULL;
@@ -2336,11 +2336,11 @@ static __isl_give isl_map *box_closure_on_domain(__isl_take isl_map *map,
        aff = isl_set_affine_hull(isl_set_copy(delta));
        if (!aff)
                goto error;
-       dim = isl_map_get_dim(map);
-       d = isl_dim_size(dim, isl_dim_in);
-       nparam = isl_dim_size(dim, isl_dim_param);
-       total = isl_dim_total(dim);
-       bmap = isl_basic_map_alloc_dim(dim,
+       dim = isl_map_get_space(map);
+       d = isl_space_dim(dim, isl_dim_in);
+       nparam = isl_space_dim(dim, isl_dim_param);
+       total = isl_space_dim(dim, isl_dim_all);
+       bmap = isl_basic_map_alloc_space(dim,
                                        aff->n_div + 1, aff->n_div, 2 * d + 1);
        for (i = 0; i < aff->n_div + 1; ++i) {
                k = isl_basic_map_alloc_div(bmap);
@@ -2663,7 +2663,7 @@ static __isl_give isl_map *transitive_closure_omega(__isl_take isl_map *map,
                if (!ok)
                        continue;
 
-               app = isl_map_alloc_dim(isl_map_get_dim(map), map->n - 1, 0);
+               app = isl_map_alloc_space(isl_map_get_space(map), map->n - 1, 0);
 
                for (j = 0; j < map->n; ++j) {
                        if (j == i)
@@ -2703,7 +2703,7 @@ error:
 __isl_give isl_map *isl_map_transitive_closure(__isl_take isl_map *map,
        int *exact)
 {
-       isl_dim *target_dim;
+       isl_space *target_dim;
        int closed;
 
        if (!map)
@@ -2723,9 +2723,9 @@ __isl_give isl_map *isl_map_transitive_closure(__isl_take isl_map *map,
                return map;
        }
 
-       target_dim = isl_map_get_dim(map);
+       target_dim = isl_map_get_space(map);
        map = map_power(map, exact, 1);
-       map = isl_map_reset_dim(map, target_dim);
+       map = isl_map_reset_space(map, target_dim);
 
        return map;
 error:
@@ -2793,10 +2793,10 @@ static __isl_give isl_union_map *union_floyd_warshall_on_list(isl_ctx *ctx,
                if (!grid[i])
                        goto error;
                for (j = 0; j < n_group; ++j) {
-                       isl_dim *dim1, *dim2, *dim;
-                       dim1 = isl_dim_reverse(isl_set_get_dim(set[i]));
-                       dim2 = isl_set_get_dim(set[j]);
-                       dim = isl_dim_join(dim1, dim2);
+                       isl_space *dim1, *dim2, *dim;
+                       dim1 = isl_space_reverse(isl_set_get_space(set[i]));
+                       dim2 = isl_set_get_space(set[j]);
+                       dim = isl_space_join(dim1, dim2);
                        grid[i][j] = isl_map_empty(dim);
                }
        }
@@ -2811,7 +2811,7 @@ static __isl_give isl_union_map *union_floyd_warshall_on_list(isl_ctx *ctx,
        
        floyd_warshall_iterate(grid, n_group, exact);
 
-       app = isl_union_map_empty(isl_map_get_dim(grid[0][0]));
+       app = isl_union_map_empty(isl_map_get_space(grid[0][0]));
 
        for (i = 0; i < n_group; ++i) {
                for (j = 0; j < n_group; ++j)
@@ -2934,11 +2934,11 @@ static __isl_give isl_union_map *union_components(
        c = 0;
        i = 0;
        l = n;
-       path = isl_union_map_empty(isl_union_map_get_dim(umap));
+       path = isl_union_map_empty(isl_union_map_get_space(umap));
        while (l) {
                isl_union_map *comp;
                isl_union_map *path_comp, *path_comb;
-               comp = isl_union_map_empty(isl_union_map_get_dim(umap));
+               comp = isl_union_map_empty(isl_union_map_get_space(umap));
                while (s->order[i] != -1) {
                        comp = isl_union_map_add_map(comp,
                                    isl_map_from_basic_map(
@@ -3035,14 +3035,14 @@ static int power(__isl_take isl_map *map, void *user)
 
 /* Construct a map [x] -> [x+1], with parameters prescribed by "dim".
  */
-static __isl_give isl_union_map *increment(__isl_take isl_dim *dim)
+static __isl_give isl_union_map *increment(__isl_take isl_space *dim)
 {
        int k;
        isl_basic_map *bmap;
 
-       dim = isl_dim_add(dim, isl_dim_in, 1);
-       dim = isl_dim_add(dim, isl_dim_out, 1);
-       bmap = isl_basic_map_alloc_dim(dim, 0, 1, 0);
+       dim = isl_space_add_dims(dim, isl_dim_in, 1);
+       dim = isl_space_add_dims(dim, isl_dim_out, 1);
+       bmap = isl_basic_map_alloc_space(dim, 0, 1, 0);
        k = isl_basic_map_alloc_equality(bmap);
        if (k < 0)
                goto error;
@@ -3058,12 +3058,12 @@ error:
 
 /* Construct a map [[x]->[y]] -> [y-x], with parameters prescribed by "dim".
  */
-static __isl_give isl_union_map *deltas_map(__isl_take isl_dim *dim)
+static __isl_give isl_union_map *deltas_map(__isl_take isl_space *dim)
 {
        isl_basic_map *bmap;
 
-       dim = isl_dim_add(dim, isl_dim_in, 1);
-       dim = isl_dim_add(dim, isl_dim_out, 1);
+       dim = isl_space_add_dims(dim, isl_dim_in, 1);
+       dim = isl_space_add_dims(dim, isl_dim_out, 1);
        bmap = isl_basic_map_universe(dim);
        bmap = isl_basic_map_deltas_map(bmap);
 
@@ -3092,11 +3092,11 @@ __isl_give isl_union_map *isl_union_map_power(__isl_take isl_union_map *umap,
                isl_union_map_free(umap);
                return up.pow;
        }
-       inc = increment(isl_union_map_get_dim(umap));
+       inc = increment(isl_union_map_get_space(umap));
        umap = isl_union_map_product(inc, umap);
        umap = isl_union_map_transitive_closure(umap, exact);
        umap = isl_union_map_zip(umap);
-       dm = deltas_map(isl_union_map_get_dim(umap));
+       dm = deltas_map(isl_union_map_get_space(umap));
        umap = isl_union_map_apply_domain(umap, dm);
        
        return umap;
index a5910fb..f12fd97 100644 (file)
@@ -8,16 +8,17 @@
  * 91893 Orsay, France 
  */
 
+#define ISL_DIM_H
 #include <isl_map_private.h>
 #include <isl/ctx.h>
 #include <isl/hash.h>
 #include <isl/map.h>
 #include <isl/set.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl_union_map_private.h>
 #include <isl/union_set.h>
 
-static __isl_give isl_union_map *isl_union_map_alloc(__isl_take isl_dim *dim,
+static __isl_give isl_union_map *isl_union_map_alloc(__isl_take isl_space *dim,
        int size)
 {
        isl_union_map *umap;
@@ -36,17 +37,17 @@ static __isl_give isl_union_map *isl_union_map_alloc(__isl_take isl_dim *dim,
 
        return umap;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        isl_union_map_free(umap);
        return NULL;
 }
 
-__isl_give isl_union_map *isl_union_map_empty(__isl_take isl_dim *dim)
+__isl_give isl_union_map *isl_union_map_empty(__isl_take isl_space *dim)
 {
        return isl_union_map_alloc(dim, 16);
 }
 
-__isl_give isl_union_set *isl_union_set_empty(__isl_take isl_dim *dim)
+__isl_give isl_union_set *isl_union_set_empty(__isl_take isl_space *dim)
 {
        return isl_union_map_empty(dim);
 }
@@ -61,16 +62,16 @@ isl_ctx *isl_union_set_get_ctx(__isl_keep isl_union_set *uset)
        return uset ? uset->dim->ctx : NULL;
 }
 
-__isl_give isl_dim *isl_union_map_get_dim(__isl_keep isl_union_map *umap)
+__isl_give isl_space *isl_union_map_get_space(__isl_keep isl_union_map *umap)
 {
        if (!umap)
                return NULL;
-       return isl_dim_copy(umap->dim);
+       return isl_space_copy(umap->dim);
 }
 
-__isl_give isl_dim *isl_union_set_get_dim(__isl_keep isl_union_set *uset)
+__isl_give isl_space *isl_union_set_get_space(__isl_keep isl_union_set *uset)
 {
-       return isl_union_map_get_dim(uset);
+       return isl_union_map_get_space(uset);
 }
 
 static int free_umap_entry(void **entry, void *user)
@@ -96,7 +97,7 @@ __isl_give isl_union_map *isl_union_map_dup(__isl_keep isl_union_map *umap)
        if (!umap)
                return NULL;
 
-       dup = isl_union_map_empty(isl_dim_copy(umap->dim));
+       dup = isl_union_map_empty(isl_space_copy(umap->dim));
        if (isl_union_map_foreach_map(umap, &add_map, &dup) < 0)
                goto error;
        return dup;
@@ -127,8 +128,8 @@ static int align_entry(void **entry, void *user)
        isl_reordering *exp;
        struct isl_union_align *data = user;
 
-       exp = isl_reordering_extend_dim(isl_reordering_copy(data->exp),
-                                   isl_map_get_dim(map));
+       exp = isl_reordering_extend_space(isl_reordering_copy(data->exp),
+                                   isl_map_get_space(map));
 
        data->res = isl_union_map_add_map(data->res,
                                        isl_map_realign(isl_map_copy(map), exp));
@@ -142,23 +143,24 @@ static int align_entry(void **entry, void *user)
  * umap that do not appear in model.
  */
 __isl_give isl_union_map *isl_union_map_align_params(
-       __isl_take isl_union_map *umap, __isl_take isl_dim *model)
+       __isl_take isl_union_map *umap, __isl_take isl_space *model)
 {
        struct isl_union_align data = { NULL, NULL };
 
        if (!umap || !model)
                goto error;
 
-       if (isl_dim_match(umap->dim, isl_dim_param, model, isl_dim_param)) {
-               isl_dim_free(model);
+       if (isl_space_match(umap->dim, isl_dim_param, model, isl_dim_param)) {
+               isl_space_free(model);
                return umap;
        }
 
+       model = isl_space_params(model);
        data.exp = isl_parameter_alignment_reordering(umap->dim, model);
        if (!data.exp)
                goto error;
 
-       data.res = isl_union_map_alloc(isl_dim_copy(data.exp->dim),
+       data.res = isl_union_map_alloc(isl_space_copy(data.exp->dim),
                                        umap->table.n);
        if (isl_hash_table_foreach(umap->dim->ctx, &umap->table,
                                        &align_entry, &data) < 0)
@@ -166,18 +168,18 @@ __isl_give isl_union_map *isl_union_map_align_params(
 
        isl_reordering_free(data.exp);
        isl_union_map_free(umap);
-       isl_dim_free(model);
+       isl_space_free(model);
        return data.res;
 error:
        isl_reordering_free(data.exp);
        isl_union_map_free(umap);
        isl_union_map_free(data.res);
-       isl_dim_free(model);
+       isl_space_free(model);
        return NULL;
 }
 
 __isl_give isl_union_set *isl_union_set_align_params(
-       __isl_take isl_union_set *uset, __isl_take isl_dim *model)
+       __isl_take isl_union_set *uset, __isl_take isl_space *model)
 {
        return isl_union_map_align_params(uset, model);
 }
@@ -185,8 +187,8 @@ __isl_give isl_union_set *isl_union_set_align_params(
 __isl_give isl_union_map *isl_union_map_union(__isl_take isl_union_map *umap1,
        __isl_take isl_union_map *umap2)
 {
-       umap1 = isl_union_map_align_params(umap1, isl_union_map_get_dim(umap2));
-       umap2 = isl_union_map_align_params(umap2, isl_union_map_get_dim(umap1));
+       umap1 = isl_union_map_align_params(umap1, isl_union_map_get_space(umap2));
+       umap2 = isl_union_map_align_params(umap2, isl_union_map_get_space(umap1));
 
        umap1 = isl_union_map_cow(umap1);
 
@@ -236,7 +238,7 @@ void *isl_union_map_free(__isl_take isl_union_map *umap)
        isl_hash_table_foreach(umap->dim->ctx, &umap->table,
                               &free_umap_entry, NULL);
        isl_hash_table_clear(&umap->table);
-       isl_dim_free(umap->dim);
+       isl_space_free(umap->dim);
        free(umap);
        return NULL;
 }
@@ -249,9 +251,9 @@ void *isl_union_set_free(__isl_take isl_union_set *uset)
 static int has_dim(const void *entry, const void *val)
 {
        isl_map *map = (isl_map *)entry;
-       isl_dim *dim = (isl_dim *)val;
+       isl_space *dim = (isl_space *)val;
 
-       return isl_dim_equal(map->dim, dim);
+       return isl_space_is_equal(map->dim, dim);
 }
 
 __isl_give isl_union_map *isl_union_map_add_map(__isl_take isl_union_map *umap,
@@ -260,20 +262,25 @@ __isl_give isl_union_map *isl_union_map_add_map(__isl_take isl_union_map *umap,
        uint32_t hash;
        struct isl_hash_table_entry *entry;
 
+       if (!map || !umap)
+               goto error;
+
        if (isl_map_plain_is_empty(map)) {
                isl_map_free(map);
                return umap;
        }
 
+       if (!isl_space_match(map->dim, isl_dim_param, umap->dim, isl_dim_param)) {
+               umap = isl_union_map_align_params(umap, isl_map_get_space(map));
+               map = isl_map_align_params(map, isl_union_map_get_space(umap));
+       }
+
        umap = isl_union_map_cow(umap);
 
        if (!map || !umap)
                goto error;
 
-       isl_assert(map->ctx, isl_dim_match(map->dim, isl_dim_param, umap->dim,
-                                          isl_dim_param), goto error);
-
-       hash = isl_dim_get_hash(map->dim);
+       hash = isl_space_get_hash(map->dim);
        entry = isl_hash_table_find(umap->dim->ctx, &umap->table, hash,
                                    &has_dim, map->dim, 1);
        if (!entry)
@@ -303,15 +310,14 @@ __isl_give isl_union_set *isl_union_set_add_set(__isl_take isl_union_set *uset,
 
 __isl_give isl_union_map *isl_union_map_from_map(__isl_take isl_map *map)
 {
-       isl_dim *dim;
+       isl_space *dim;
        isl_union_map *umap;
 
        if (!map)
                return NULL;
 
-       dim = isl_map_get_dim(map);
-       dim = isl_dim_drop(dim, isl_dim_in, 0, isl_dim_size(dim, isl_dim_in));
-       dim = isl_dim_drop(dim, isl_dim_out, 0, isl_dim_size(dim, isl_dim_out));
+       dim = isl_map_get_space(map);
+       dim = isl_space_params(dim);
        umap = isl_union_map_empty(dim);
        umap = isl_union_map_add_map(umap, map);
 
@@ -396,7 +402,7 @@ __isl_give isl_set *isl_set_from_union_set(__isl_take isl_union_set *uset)
 }
 
 __isl_give isl_map *isl_union_map_extract_map(__isl_keep isl_union_map *umap,
-       __isl_take isl_dim *dim)
+       __isl_take isl_space *dim)
 {
        uint32_t hash;
        struct isl_hash_table_entry *entry;
@@ -404,20 +410,20 @@ __isl_give isl_map *isl_union_map_extract_map(__isl_keep isl_union_map *umap,
        if (!umap || !dim)
                goto error;
 
-       hash = isl_dim_get_hash(dim);
+       hash = isl_space_get_hash(dim);
        entry = isl_hash_table_find(umap->dim->ctx, &umap->table, hash,
                                    &has_dim, dim, 0);
        if (!entry)
                return isl_map_empty(dim);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return isl_map_copy(entry->data);
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
 __isl_give isl_set *isl_union_set_extract_set(__isl_keep isl_union_set *uset,
-       __isl_take isl_dim *dim)
+       __isl_take isl_space *dim)
 {
        return (isl_set *)isl_union_map_extract_map(uset, dim);
 }
@@ -425,7 +431,7 @@ __isl_give isl_set *isl_union_set_extract_set(__isl_keep isl_union_set *uset,
 /* Check if umap contains a map in the given space.
  */
 __isl_give int isl_union_map_contains(__isl_keep isl_union_map *umap,
-       __isl_keep isl_dim *dim)
+       __isl_keep isl_space *dim)
 {
        uint32_t hash;
        struct isl_hash_table_entry *entry;
@@ -433,14 +439,14 @@ __isl_give int isl_union_map_contains(__isl_keep isl_union_map *umap,
        if (!umap || !dim)
                return -1;
 
-       hash = isl_dim_get_hash(dim);
+       hash = isl_space_get_hash(dim);
        entry = isl_hash_table_find(umap->dim->ctx, &umap->table, hash,
                                    &has_dim, dim, 0);
        return !!entry;
 }
 
 __isl_give int isl_union_set_contains(__isl_keep isl_union_set *uset,
-       __isl_keep isl_dim *dim)
+       __isl_keep isl_space *dim)
 {
        return isl_union_map_contains(uset, dim);
 }
@@ -487,7 +493,7 @@ static int subtract_entry(void **entry, void *user)
        struct isl_hash_table_entry *entry2;
        isl_map *map = *entry;
 
-       hash = isl_dim_get_hash(map->dim);
+       hash = isl_space_get_hash(map->dim);
        entry2 = isl_hash_table_find(data->umap2->dim->ctx, &data->umap2->table,
                                     hash, &has_dim, map->dim, 0);
        map = isl_map_copy(map);
@@ -515,14 +521,14 @@ static __isl_give isl_union_map *gen_bin_op(__isl_take isl_union_map *umap1,
 {
        struct isl_union_map_gen_bin_data data = { NULL, NULL };
 
-       umap1 = isl_union_map_align_params(umap1, isl_union_map_get_dim(umap2));
-       umap2 = isl_union_map_align_params(umap2, isl_union_map_get_dim(umap1));
+       umap1 = isl_union_map_align_params(umap1, isl_union_map_get_space(umap2));
+       umap2 = isl_union_map_align_params(umap2, isl_union_map_get_space(umap1));
 
        if (!umap1 || !umap2)
                goto error;
 
        data.umap2 = umap2;
-       data.res = isl_union_map_alloc(isl_dim_copy(umap1->dim),
+       data.res = isl_union_map_alloc(isl_space_copy(umap1->dim),
                                       umap1->table.n);
        if (isl_hash_table_foreach(umap1->dim->ctx, &umap1->table,
                                   fn, &data) < 0)
@@ -564,7 +570,7 @@ static int match_bin_entry(void **entry, void *user)
        isl_map *map = *entry;
        int empty;
 
-       hash = isl_dim_get_hash(map->dim);
+       hash = isl_space_get_hash(map->dim);
        entry2 = isl_hash_table_find(data->umap2->dim->ctx, &data->umap2->table,
                                     hash, &has_dim, map->dim, 0);
        if (!entry2)
@@ -594,14 +600,14 @@ static __isl_give isl_union_map *match_bin_op(__isl_take isl_union_map *umap1,
 {
        struct isl_union_map_match_bin_data data = { NULL, NULL, fn };
 
-       umap1 = isl_union_map_align_params(umap1, isl_union_map_get_dim(umap2));
-       umap2 = isl_union_map_align_params(umap2, isl_union_map_get_dim(umap1));
+       umap1 = isl_union_map_align_params(umap1, isl_union_map_get_space(umap2));
+       umap2 = isl_union_map_align_params(umap2, isl_union_map_get_space(umap1));
 
        if (!umap1 || !umap2)
                goto error;
 
        data.umap2 = umap2;
-       data.res = isl_union_map_alloc(isl_dim_copy(umap1->dim),
+       data.res = isl_union_map_alloc(isl_space_copy(umap1->dim),
                                       umap1->table.n);
        if (isl_hash_table_foreach(umap1->dim->ctx, &umap1->table,
                                   &match_bin_entry, &data) < 0)
@@ -694,16 +700,16 @@ static int intersect_domain_entry(void **entry, void *user)
        struct isl_union_map_gen_bin_data *data = user;
        uint32_t hash;
        struct isl_hash_table_entry *entry2;
-       isl_dim *dim;
+       isl_space *dim;
        isl_map *map = *entry;
        int empty;
 
-       dim = isl_map_get_dim(map);
-       dim = isl_dim_domain(dim);
-       hash = isl_dim_get_hash(dim);
+       dim = isl_map_get_space(map);
+       dim = isl_space_domain(dim);
+       hash = isl_space_get_hash(dim);
        entry2 = isl_hash_table_find(data->umap2->dim->ctx, &data->umap2->table,
                                     hash, &has_dim, dim, 0);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        if (!entry2)
                return 0;
 
@@ -736,16 +742,16 @@ static int intersect_range_entry(void **entry, void *user)
        struct isl_union_map_gen_bin_data *data = user;
        uint32_t hash;
        struct isl_hash_table_entry *entry2;
-       isl_dim *dim;
+       isl_space *dim;
        isl_map *map = *entry;
        int empty;
 
-       dim = isl_map_get_dim(map);
-       dim = isl_dim_range(dim);
-       hash = isl_dim_get_hash(dim);
+       dim = isl_map_get_space(map);
+       dim = isl_space_range(dim);
+       hash = isl_space_get_hash(dim);
        entry2 = isl_hash_table_find(data->umap2->dim->ctx, &data->umap2->table,
                                     hash, &has_dim, dim, 0);
-       isl_dim_free(dim);
+       isl_space_free(dim);
        if (!entry2)
                return 0;
 
@@ -786,7 +792,7 @@ static int apply_range_entry(void **entry, void *user)
        isl_map *map2 = *entry;
        int empty;
 
-       if (!isl_dim_tuple_match(data->map->dim, isl_dim_out,
+       if (!isl_space_tuple_match(data->map->dim, isl_dim_out,
                                 map2->dim, isl_dim_in))
                return 0;
 
@@ -825,14 +831,14 @@ static __isl_give isl_union_map *bin_op(__isl_take isl_union_map *umap1,
 {
        struct isl_union_map_bin_data data = { NULL, NULL, NULL, fn };
 
-       umap1 = isl_union_map_align_params(umap1, isl_union_map_get_dim(umap2));
-       umap2 = isl_union_map_align_params(umap2, isl_union_map_get_dim(umap1));
+       umap1 = isl_union_map_align_params(umap1, isl_union_map_get_space(umap2));
+       umap2 = isl_union_map_align_params(umap2, isl_union_map_get_space(umap1));
 
        if (!umap1 || !umap2)
                goto error;
 
        data.umap2 = umap2;
-       data.res = isl_union_map_alloc(isl_dim_copy(umap1->dim),
+       data.res = isl_union_map_alloc(isl_space_copy(umap1->dim),
                                       umap1->table.n);
        if (isl_hash_table_foreach(umap1->dim->ctx, &umap1->table,
                                   &bin_entry, &data) < 0)
@@ -873,7 +879,7 @@ static int map_lex_lt_entry(void **entry, void *user)
        struct isl_union_map_bin_data *data = user;
        isl_map *map2 = *entry;
 
-       if (!isl_dim_tuple_match(data->map->dim, isl_dim_out,
+       if (!isl_space_tuple_match(data->map->dim, isl_dim_out,
                                 map2->dim, isl_dim_out))
                return 0;
 
@@ -895,7 +901,7 @@ static int map_lex_le_entry(void **entry, void *user)
        struct isl_union_map_bin_data *data = user;
        isl_map *map2 = *entry;
 
-       if (!isl_dim_tuple_match(data->map->dim, isl_dim_out,
+       if (!isl_space_tuple_match(data->map->dim, isl_dim_out,
                                 map2->dim, isl_dim_out))
                return 0;
 
@@ -941,7 +947,7 @@ static int range_product_entry(void **entry, void *user)
        struct isl_union_map_bin_data *data = user;
        isl_map *map2 = *entry;
 
-       if (!isl_dim_tuple_match(data->map->dim, isl_dim_in,
+       if (!isl_space_tuple_match(data->map->dim, isl_dim_in,
                                 map2->dim, isl_dim_in))
                return 0;
 
@@ -964,7 +970,7 @@ static int flat_range_product_entry(void **entry, void *user)
        struct isl_union_map_bin_data *data = user;
        isl_map *map2 = *entry;
 
-       if (!isl_dim_tuple_match(data->map->dim, isl_dim_in,
+       if (!isl_space_tuple_match(data->map->dim, isl_dim_in,
                                 map2->dim, isl_dim_in))
                return 0;
 
@@ -982,10 +988,41 @@ __isl_give isl_union_map *isl_union_map_flat_range_product(
        return bin_op(umap1, umap2, &flat_range_product_entry);
 }
 
+static __isl_give isl_union_set *cond_un_op(__isl_take isl_union_map *umap,
+       int (*fn)(void **, void *))
+{
+       isl_union_set *res;
+
+       if (!umap)
+               return NULL;
+
+       res = isl_union_map_alloc(isl_space_copy(umap->dim), umap->table.n);
+       if (isl_hash_table_foreach(umap->dim->ctx, &umap->table, fn, &res) < 0)
+               goto error;
+
+       isl_union_map_free(umap);
+       return res;
+error:
+       isl_union_map_free(umap);
+       isl_union_set_free(res);
+       return NULL;
+}
+
+static int from_range_entry(void **entry, void *user)
+{
+       isl_map *set = *entry;
+       isl_union_set **res = user;
+
+       *res = isl_union_map_add_map(*res,
+                                       isl_map_from_range(isl_set_copy(set)));
+
+       return 0;
+}
+
 __isl_give isl_union_map *isl_union_map_from_range(
        __isl_take isl_union_set *uset)
 {
-       return uset;
+       return cond_un_op(uset, &from_range_entry);
 }
 
 __isl_give isl_union_map *isl_union_map_from_domain(
@@ -1191,32 +1228,12 @@ __isl_give isl_union_set *isl_union_set_lexmax(
        return isl_union_map_lexmax(uset);
 }
 
-static __isl_give isl_union_set *cond_un_op(__isl_take isl_union_map *umap,
-       int (*fn)(void **, void *))
-{
-       isl_union_set *res;
-
-       if (!umap)
-               return NULL;
-
-       res = isl_union_map_alloc(isl_dim_copy(umap->dim), umap->table.n);
-       if (isl_hash_table_foreach(umap->dim->ctx, &umap->table, fn, &res) < 0)
-               goto error;
-
-       isl_union_map_free(umap);
-       return res;
-error:
-       isl_union_map_free(umap);
-       isl_union_set_free(res);
-       return NULL;
-}
-
 static int universe_entry(void **entry, void *user)
 {
        isl_map *map = *entry;
        isl_union_map **res = user;
 
-       map = isl_map_universe(isl_map_get_dim(map));
+       map = isl_map_universe(isl_map_get_space(map));
        *res = isl_union_map_add_map(*res, map);
 
        return 0;
@@ -1316,7 +1333,7 @@ static int deltas_entry(void **entry, void *user)
        isl_map *map = *entry;
        isl_union_set **res = user;
 
-       if (!isl_dim_tuple_match(map->dim, isl_dim_in, map->dim, isl_dim_out))
+       if (!isl_space_tuple_match(map->dim, isl_dim_in, map->dim, isl_dim_out))
                return 0;
 
        *res = isl_union_set_add_set(*res, isl_map_deltas(isl_map_copy(map)));
@@ -1334,7 +1351,7 @@ static int deltas_map_entry(void **entry, void *user)
        isl_map *map = *entry;
        isl_union_map **res = user;
 
-       if (!isl_dim_tuple_match(map->dim, isl_dim_in, map->dim, isl_dim_out))
+       if (!isl_space_tuple_match(map->dim, isl_dim_in, map->dim, isl_dim_out))
                return 0;
 
        *res = isl_union_map_add_map(*res,
@@ -1409,7 +1426,7 @@ static int is_subset_entry(void **entry, void *user)
        struct isl_hash_table_entry *entry2;
        isl_map *map = *entry;
 
-       hash = isl_dim_get_hash(map->dim);
+       hash = isl_space_get_hash(map->dim);
        entry2 = isl_hash_table_find(data->umap2->dim->ctx, &data->umap2->table,
                                     hash, &has_dim, map->dim, 0);
        if (!entry2) {
@@ -1431,8 +1448,8 @@ int isl_union_map_is_subset(__isl_keep isl_union_map *umap1,
 
        umap1 = isl_union_map_copy(umap1);
        umap2 = isl_union_map_copy(umap2);
-       umap1 = isl_union_map_align_params(umap1, isl_union_map_get_dim(umap2));
-       umap2 = isl_union_map_align_params(umap2, isl_union_map_get_dim(umap1));
+       umap1 = isl_union_map_align_params(umap1, isl_union_map_get_space(umap2));
+       umap2 = isl_union_map_align_params(umap2, isl_union_map_get_space(umap1));
 
        if (!umap1 || !umap2)
                goto error;
@@ -1527,7 +1544,7 @@ __isl_give isl_basic_map *isl_union_map_sample(__isl_take isl_union_map *umap)
                goto error;
 
        if (!sample)
-               sample = isl_basic_map_empty(isl_union_map_get_dim(umap));
+               sample = isl_basic_map_empty(isl_union_map_get_space(umap));
 
        isl_union_map_free(umap);
 
@@ -1628,16 +1645,16 @@ int isl_union_set_is_empty(__isl_keep isl_union_set *uset)
 static int is_subset_of_identity(__isl_keep isl_map *map)
 {
        int is_subset;
-       isl_dim *dim;
+       isl_space *dim;
        isl_map *id;
 
        if (!map)
                return -1;
 
-       if (!isl_dim_tuple_match(map->dim, isl_dim_in, map->dim, isl_dim_out))
+       if (!isl_space_tuple_match(map->dim, isl_dim_in, map->dim, isl_dim_out))
                return 0;
 
-       dim = isl_map_get_dim(map);
+       dim = isl_map_get_space(map);
        id = isl_map_identity(dim);
 
        is_subset = isl_map_is_subset(map, id);
@@ -1771,7 +1788,7 @@ static int plain_injective_on_range(__isl_take isl_union_map *umap,
  * based on later dimensions.
  */
 static int separates(struct isl_fixed_map *v, int n,
-       __isl_take isl_dim *dim, int pos, int n_range)
+       __isl_take isl_space *dim, int pos, int n_range)
 {
        int i;
 
@@ -1792,7 +1809,7 @@ static int separates(struct isl_fixed_map *v, int n,
                if (j == i + 1)
                        continue;
 
-               part = isl_union_map_alloc(isl_dim_copy(dim), j - i);
+               part = isl_union_map_alloc(isl_space_copy(dim), j - i);
                for (k = i; k < j; ++k)
                        part = isl_union_map_add_map(part,
                                                     isl_map_copy(v[k].map));
@@ -1806,11 +1823,11 @@ static int separates(struct isl_fixed_map *v, int n,
                i = j - 1;
        }
 
-       isl_dim_free(dim);
+       isl_space_free(dim);
        free_isl_fixed_map_array(v, n);
        return i + 1 >= n;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        free_isl_fixed_map_array(v, n);
        return -1;
 }
@@ -1851,7 +1868,7 @@ static int plain_injective_on_range(__isl_take isl_union_map *umap,
        for (data.pos = first; data.pos < n_range; ++data.pos) {
                int fixed;
                int injective;
-               isl_dim *dim;
+               isl_space *dim;
 
                data.n = 0;
                fixed = union_map_forall_user(umap, &fixed_at_pos, &data);
@@ -1859,7 +1876,7 @@ static int plain_injective_on_range(__isl_take isl_union_map *umap,
                        goto error;
                if (!fixed)
                        continue;
-               dim = isl_union_map_get_dim(umap);
+               dim = isl_union_map_get_space(umap);
                injective = separates(data.v, n, dim, data.pos, n_range);
                isl_union_map_free(umap);
                return injective;
@@ -1976,14 +1993,14 @@ __isl_give isl_union_set *isl_union_set_coefficients(
        __isl_take isl_union_set *uset)
 {
        isl_ctx *ctx;
-       isl_dim *dim;
+       isl_space *dim;
        isl_union_set *res;
 
        if (!uset)
                return NULL;
 
        ctx = isl_union_set_get_ctx(uset);
-       dim = isl_dim_set_alloc(ctx, 0, 0);
+       dim = isl_space_set_alloc(ctx, 0, 0);
        res = isl_union_map_alloc(dim, uset->table.n);
        if (isl_hash_table_foreach(uset->dim->ctx, &uset->table,
                                   &coefficients_entry, &res) < 0)
@@ -2024,7 +2041,7 @@ __isl_give isl_union_set *isl_union_set_solutions(
                return NULL;
 
        if (uset->table.n == 0) {
-               res = isl_union_set_empty(isl_union_set_get_dim(uset));
+               res = isl_union_set_empty(isl_union_set_get_space(uset));
                isl_union_set_free(uset);
                return res;
        }
index 2abd4ff..c0266c0 100644 (file)
@@ -3,7 +3,7 @@
 
 struct isl_union_map {
        int ref;
-       isl_dim *dim;
+       isl_space *dim;
 
        struct isl_hash_table   table;
 };
index c06069d..1ee7d05 100644 (file)
@@ -18,7 +18,7 @@ struct UNION {
 #ifdef HAS_TYPE
        enum isl_fold type;
 #endif
-       isl_dim *dim;
+       isl_space *dim;
 
        struct isl_hash_table   table;
 };
@@ -30,22 +30,23 @@ isl_ctx *FN(UNION,get_ctx)(__isl_keep UNION *u)
        return u ? u->dim->ctx : NULL;
 }
 
-__isl_give isl_dim *FN(UNION,get_dim)(__isl_keep UNION *u)
+__isl_give isl_space *FN(UNION,get_space)(__isl_keep UNION *u)
 {
        if (!u)
                return NULL;
-       return isl_dim_copy(u->dim);
+       return isl_space_copy(u->dim);
 }
 
 #ifdef HAS_TYPE
-static __isl_give UNION *FN(UNION,alloc)(__isl_take isl_dim *dim,
+static __isl_give UNION *FN(UNION,alloc)(__isl_take isl_space *dim,
        enum isl_fold type, int size)
 #else
-static __isl_give UNION *FN(UNION,alloc)(__isl_take isl_dim *dim, int size)
+static __isl_give UNION *FN(UNION,alloc)(__isl_take isl_space *dim, int size)
 #endif
 {
        UNION *u;
 
+       dim = isl_space_params(dim);
        if (!dim)
                return NULL;
 
@@ -63,18 +64,18 @@ static __isl_give UNION *FN(UNION,alloc)(__isl_take isl_dim *dim, int size)
 
        return u;
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        FN(UNION,free)(u);
        return NULL;
 }
 
 #ifdef HAS_TYPE
-__isl_give UNION *FN(UNION,zero)(__isl_take isl_dim *dim, enum isl_fold type)
+__isl_give UNION *FN(UNION,zero)(__isl_take isl_space *dim, enum isl_fold type)
 {
        return FN(UNION,alloc)(dim, type, 16);
 }
 #else
-__isl_give UNION *FN(UNION,zero)(__isl_take isl_dim *dim)
+__isl_give UNION *FN(UNION,zero)(__isl_take isl_space *dim)
 {
        return FN(UNION,alloc)(dim, 16);
 }
@@ -118,13 +119,13 @@ int FN(FN(UNION,foreach),PARTS)(__isl_keep UNION *u,
 static int has_dim(const void *entry, const void *val)
 {
        PART *part = (PART *)entry;
-       isl_dim *dim = (isl_dim *)val;
+       isl_space *dim = (isl_space *)val;
 
-       return isl_dim_equal(part->dim, dim);
+       return isl_space_is_equal(part->dim, dim);
 }
 
 __isl_give PART *FN(FN(UNION,extract),PARTS)(__isl_keep UNION *u,
-       __isl_take isl_dim *dim)
+       __isl_take isl_space *dim)
 {
        uint32_t hash;
        struct isl_hash_table_entry *entry;
@@ -132,7 +133,7 @@ __isl_give PART *FN(FN(UNION,extract),PARTS)(__isl_keep UNION *u,
        if (!u || !dim)
                goto error;
 
-       hash = isl_dim_get_hash(dim);
+       hash = isl_space_get_hash(dim);
        entry = isl_hash_table_find(u->dim->ctx, &u->table, hash,
                                    &has_dim, dim, 0);
        if (!entry)
@@ -141,10 +142,10 @@ __isl_give PART *FN(FN(UNION,extract),PARTS)(__isl_keep UNION *u,
 #else
                return FN(PART,zero)(dim);
 #endif
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return FN(PART,copy)(entry->data);
 error:
-       isl_dim_free(dim);
+       isl_space_free(dim);
        return NULL;
 }
 
@@ -167,10 +168,10 @@ __isl_give UNION *FN(FN(UNION,add),PARTS)(__isl_take UNION *u,
        if (!u)
                goto error;
 
-       isl_assert(u->dim->ctx, isl_dim_match(part->dim, isl_dim_param, u->dim,
+       isl_assert(u->dim->ctx, isl_space_match(part->dim, isl_dim_param, u->dim,
                                              isl_dim_param), goto error);
 
-       hash = isl_dim_get_hash(part->dim);
+       hash = isl_space_get_hash(part->dim);
        entry = isl_hash_table_find(u->dim->ctx, &u->table, hash,
                                    &has_dim, part->dim, 1);
        if (!entry)
@@ -213,9 +214,9 @@ __isl_give UNION *FN(UNION,dup)(__isl_keep UNION *u)
                return NULL;
 
 #ifdef HAS_TYPE
-       dup = FN(UNION,zero)(isl_dim_copy(u->dim), u->type);
+       dup = FN(UNION,zero)(isl_space_copy(u->dim), u->type);
 #else
-       dup = FN(UNION,zero)(isl_dim_copy(u->dim));
+       dup = FN(UNION,zero)(isl_space_copy(u->dim));
 #endif
        if (FN(FN(UNION,foreach),PARTS)(u, &add_part, &dup) < 0)
                goto error;
@@ -253,7 +254,7 @@ void FN(UNION,free)(__isl_take UNION *u)
 
        isl_hash_table_foreach(u->dim->ctx, &u->table, &free_u_entry, NULL);
        isl_hash_table_clear(&u->table);
-       isl_dim_free(u->dim);
+       isl_space_free(u->dim);
        free(u);
 }
 
@@ -262,30 +263,46 @@ S(UNION,align) {
        UNION *res;
 };
 
+#ifdef ALIGN_DOMAIN
 static int align_entry(__isl_take PART *part, void *user)
 {
        isl_reordering *exp;
        S(UNION,align) *data = user;
 
-       exp = isl_reordering_extend_dim(isl_reordering_copy(data->exp),
-                                   FN(PART,get_dim)(part));
+       exp = isl_reordering_extend_space(isl_reordering_copy(data->exp),
+                                   FN(PART,get_domain_space)(part));
+
+       data->res = FN(FN(UNION,add),PARTS)(data->res,
+                                           FN(PART,realign_domain)(part, exp));
+
+       return 0;
+}
+#else
+static int align_entry(__isl_take PART *part, void *user)
+{
+       isl_reordering *exp;
+       S(UNION,align) *data = user;
+
+       exp = isl_reordering_extend_space(isl_reordering_copy(data->exp),
+                                   FN(PART,get_space)(part));
 
        data->res = FN(FN(UNION,add),PARTS)(data->res,
                                            FN(PART,realign)(part, exp));
 
        return 0;
 }
+#endif
 
 __isl_give UNION *FN(UNION,align_params)(__isl_take UNION *u,
-       __isl_take isl_dim *model)
+       __isl_take isl_space *model)
 {
        S(UNION,align) data = { NULL, NULL };
 
        if (!u || !model)
                goto error;
 
-       if (isl_dim_match(u->dim, isl_dim_param, model, isl_dim_param)) {
-               isl_dim_free(model);
+       if (isl_space_match(u->dim, isl_dim_param, model, isl_dim_param)) {
+               isl_space_free(model);
                return u;
        }
 
@@ -294,30 +311,30 @@ __isl_give UNION *FN(UNION,align_params)(__isl_take UNION *u,
                goto error;
 
 #ifdef HAS_TYPE
-       data.res = FN(UNION,alloc)(isl_dim_copy(data.exp->dim),
+       data.res = FN(UNION,alloc)(isl_space_copy(data.exp->dim),
                                                u->type, u->table.n);
 #else
-       data.res = FN(UNION,alloc)(isl_dim_copy(data.exp->dim), u->table.n);
+       data.res = FN(UNION,alloc)(isl_space_copy(data.exp->dim), u->table.n);
 #endif
        if (FN(FN(UNION,foreach),PARTS)(u, &align_entry, &data) < 0)
                goto error;
 
        isl_reordering_free(data.exp);
        FN(UNION,free)(u);
-       isl_dim_free(model);
+       isl_space_free(model);
        return data.res;
 error:
        isl_reordering_free(data.exp);
        FN(UNION,free)(u);
        FN(UNION,free)(data.res);
-       isl_dim_free(model);
+       isl_space_free(model);
        return NULL;
 }
 
 __isl_give UNION *FN(UNION,add)(__isl_take UNION *u1, __isl_take UNION *u2)
 {
-       u1 = FN(UNION,align_params)(u1, FN(UNION,get_dim)(u2));
-       u2 = FN(UNION,align_params)(u2, FN(UNION,get_dim)(u1));
+       u1 = FN(UNION,align_params)(u1, FN(UNION,get_space)(u2));
+       u2 = FN(UNION,align_params)(u2, FN(UNION,get_space)(u1));
 
        u1 = FN(UNION,cow)(u1);
 
@@ -338,15 +355,15 @@ error:
 
 __isl_give UNION *FN(FN(UNION,from),PARTS)(__isl_take PART *part)
 {
-       isl_dim *dim;
+       isl_space *dim;
        UNION *u;
 
        if (!part)
                return NULL;
 
-       dim = FN(PART,get_dim)(part);
-       dim = isl_dim_drop(dim, isl_dim_in, 0, isl_dim_size(dim, isl_dim_in));
-       dim = isl_dim_drop(dim, isl_dim_out, 0, isl_dim_size(dim, isl_dim_out));
+       dim = FN(PART,get_space)(part);
+       dim = isl_space_drop_dims(dim, isl_dim_in, 0, isl_space_dim(dim, isl_dim_in));
+       dim = isl_space_drop_dims(dim, isl_dim_out, 0, isl_space_dim(dim, isl_dim_out));
 #ifdef HAS_TYPE
        u = FN(UNION,zero)(dim, part->type);
 #else
@@ -373,17 +390,17 @@ static __isl_give UNION *match_bin_op(__isl_take UNION *u1,
 {
        S(UNION,match_bin_data) data = { NULL, NULL };
 
-       u1 = FN(UNION,align_params)(u1, FN(UNION,get_dim)(u2));
-       u2 = FN(UNION,align_params)(u2, FN(UNION,get_dim)(u1));
+       u1 = FN(UNION,align_params)(u1, FN(UNION,get_space)(u2));
+       u2 = FN(UNION,align_params)(u2, FN(UNION,get_space)(u1));
 
        if (!u1 || !u2)
                goto error;
 
        data.u2 = u2;
 #ifdef HAS_TYPE
-       data.res = FN(UNION,alloc)(isl_dim_copy(u1->dim), u1->type, u1->table.n);
+       data.res = FN(UNION,alloc)(isl_space_copy(u1->dim), u1->type, u1->table.n);
 #else
-       data.res = FN(UNION,alloc)(isl_dim_copy(u1->dim), u1->table.n);
+       data.res = FN(UNION,alloc)(isl_space_copy(u1->dim), u1->table.n);
 #endif
        if (isl_hash_table_foreach(u1->dim->ctx, &u1->table, fn, &data) < 0)
                goto error;
@@ -407,9 +424,9 @@ S(UNION,match_set_data) {
 static int set_has_dim(const void *entry, const void *val)
 {
        isl_set *set = (isl_set *)entry;
-       isl_dim *dim = (isl_dim *)val;
+       isl_space *dim = (isl_space *)val;
 
-       return isl_dim_equal(set->dim, dim);
+       return isl_space_is_equal(set->dim, dim);
 }
 
 static int match_set_entry(void **entry, void *user)
@@ -420,7 +437,7 @@ static int match_set_entry(void **entry, void *user)
        PW *pw = *entry;
        int empty;
 
-       hash = isl_dim_get_hash(pw->dim);
+       hash = isl_space_get_hash(pw->dim);
        entry2 = isl_hash_table_find(data->uset->dim->ctx, &data->uset->table,
                                     hash, &set_has_dim, pw->dim, 0);
        if (!entry2)
@@ -450,17 +467,17 @@ static __isl_give UNION *match_set_op(__isl_take UNION *u,
 {
        S(UNION,match_set_data) data = { NULL, NULL, fn };
 
-       u = FN(UNION,align_params)(u, isl_union_set_get_dim(uset));
-       uset = isl_union_set_align_params(uset, FN(UNION,get_dim)(u));
+       u = FN(UNION,align_params)(u, isl_union_set_get_space(uset));
+       uset = isl_union_set_align_params(uset, FN(UNION,get_space)(u));
 
        if (!u || !uset)
                goto error;
 
        data.uset = uset;
 #ifdef HAS_TYPE
-       data.res = FN(UNION,alloc)(isl_dim_copy(u->dim), u->type, u->table.n);
+       data.res = FN(UNION,alloc)(isl_space_copy(u->dim), u->type, u->table.n);
 #else
-       data.res = FN(UNION,alloc)(isl_dim_copy(u->dim), u->table.n);
+       data.res = FN(UNION,alloc)(isl_space_copy(u->dim), u->table.n);
 #endif
        if (isl_hash_table_foreach(u->dim->ctx, &u->table,
                                   &match_set_entry, &data) < 0)
@@ -493,16 +510,23 @@ __isl_give isl_qpolynomial *FN(UNION,eval)(__isl_take UNION *u,
 {
        uint32_t hash;
        struct isl_hash_table_entry *entry;
+       isl_space *space;
        isl_qpolynomial *qp;
 
        if (!u || !pnt)
                goto error;
 
-       hash = isl_dim_get_hash(pnt->dim);
+       space = isl_space_copy(pnt->dim);
+       space = isl_space_from_domain(space);
+       space = isl_space_add_dims(space, isl_dim_out, 1);
+       if (!space)
+               goto error;
+       hash = isl_space_get_hash(space);
        entry = isl_hash_table_find(u->dim->ctx, &u->table,
-                                   hash, &has_dim, pnt->dim, 0);
+                                   hash, &has_dim, space, 0);
+       isl_space_free(space);
        if (!entry) {
-               qp = isl_qpolynomial_zero(isl_dim_copy(pnt->dim));
+               qp = isl_qpolynomial_zero_on_domain(isl_space_copy(pnt->dim));
                isl_point_free(pnt);
        } else {
                qp = FN(PART,eval)(FN(PART,copy)(entry->data), pnt);
@@ -554,7 +578,7 @@ __isl_give isl_union_set *FN(UNION,domain)(__isl_take UNION *u)
 {
        isl_union_set *uset;
 
-       uset = isl_union_set_empty(FN(UNION,get_dim)(u));
+       uset = isl_union_set_empty(FN(UNION,get_space)(u));
        if (FN(FN(UNION,foreach),PARTS)(u, &domain, &uset) < 0)
                goto error;
 
@@ -586,7 +610,7 @@ __isl_give UNION *FN(UNION,mul_isl_int)(__isl_take UNION *u, isl_int v)
 
        if (u && isl_int_is_zero(v)) {
                UNION *zero;
-               isl_dim *dim = FN(UNION,get_dim)(u);
+               isl_space *dim = FN(UNION,get_space)(u);
 #ifdef HAS_TYPE
                zero = FN(UNION,zero)(dim, u->type);
 #else
index b0bd1a3..61bd57f 100644 (file)
--- a/isl_vec.c
+++ b/isl_vec.c
@@ -219,6 +219,15 @@ struct isl_vec *isl_vec_normalize(struct isl_vec *vec)
        return vec;
 }
 
+__isl_give isl_vec *isl_vec_neg(__isl_take isl_vec *vec)
+{
+       vec = isl_vec_cow(vec);
+       if (!vec)
+               return NULL;
+       isl_seq_neg(vec->el, vec->el, vec->size);
+       return vec;
+}
+
 __isl_give isl_vec *isl_vec_scale(__isl_take isl_vec *vec, isl_int m)
 {
        if (isl_int_is_one(m))
index 9611d6b..e7d849e 100644 (file)
@@ -12,7 +12,7 @@
 #include <isl/set.h>
 #include <isl/seq.h>
 #include <isl_tab.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
 #include <isl_morph.h>
 #include <isl_vertices_private.h>
 #include <isl_mat_private.h>
@@ -210,7 +210,7 @@ static __isl_give isl_vertices *vertices_0D(__isl_keep isl_basic_set *bset)
        vertices->c[0].vertices = isl_calloc_array(bset->ctx, int, 1);
        if (!vertices->c[0].vertices)
                goto error;
-       vertices->c[0].dom = isl_basic_set_copy(bset);
+       vertices->c[0].dom = isl_basic_set_params(isl_basic_set_copy(bset));
        if (!vertices->c[0].dom)
                goto error;
 
@@ -288,7 +288,7 @@ static int can_select(__isl_keep isl_basic_set *bset, int level,
        if (isl_tab_is_redundant(tab, level))
                return 0;
 
-       ovar = isl_dim_offset(bset->dim, isl_dim_set);
+       ovar = isl_space_offset(bset->dim, isl_dim_set);
 
        indep = is_independent(facets, selected, bset->ineq[level] + 1 + ovar);
        if (indep < 0)
@@ -861,7 +861,6 @@ static __isl_give isl_vertices *compute_chambers(__isl_take isl_basic_set *bset,
        isl_vec *sample = NULL;
        struct isl_tab *tab = NULL;
        struct isl_tab_undo *snap;
-       unsigned nvar;
        int *selection = NULL;
        int n_chambers = 0;
        struct isl_chamber_list *list = NULL;
@@ -875,8 +874,7 @@ static __isl_give isl_vertices *compute_chambers(__isl_take isl_basic_set *bset,
        if (!selection)
                goto error;
 
-       nvar = isl_basic_set_dim(bset, isl_dim_set);
-       bset = isl_basic_set_project_out(bset, isl_dim_set, 0, nvar);
+       bset = isl_basic_set_params(bset);
 
        tab = isl_tab_from_basic_set(bset);
        for (i = 0; i < bset->n_ineq; ++i)
diff --git a/pip.c b/pip.c
index 0d85f3a..9b2ae1d 100644 (file)
--- a/pip.c
+++ b/pip.c
@@ -73,8 +73,10 @@ static __isl_give isl_basic_set *set_bounds(__isl_take isl_basic_set *bset)
 
 static struct isl_basic_set *to_parameter_domain(struct isl_basic_set *context)
 {
-       return isl_basic_set_move_dims(context, isl_dim_param, 0, isl_dim_set, 0,
-                                      isl_basic_set_dim(context, isl_dim_set));
+       context = isl_basic_set_move_dims(context, isl_dim_param, 0,
+                   isl_dim_set, 0, isl_basic_set_dim(context, isl_dim_set));
+       context = isl_basic_set_params(context);
+       return context;
 }
 
 isl_basic_set *plug_in_parameters(isl_basic_set *bset, struct isl_vec *params)
@@ -195,7 +197,7 @@ static int scan_one(struct isl_scan_callback *callback,
 
        if (opt->size == 0) {
                isl_point *sample_pnt;
-               sample_pnt = isl_point_alloc(isl_set_get_dim(sp->empty), sample);
+               sample_pnt = isl_point_alloc(isl_set_get_space(sp->empty), sample);
                assert(isl_set_contains_point(sp->empty, sample_pnt));
                isl_point_free(sample_pnt);
                isl_vec_free(opt);
@@ -302,11 +304,11 @@ int main(int argc, char **argv)
        }
        if (!urs_parms)
                context = isl_basic_set_intersect(context,
-               isl_basic_set_positive_orthant(isl_basic_set_get_dim(context)));
+               isl_basic_set_positive_orthant(isl_basic_set_get_space(context)));
        context = to_parameter_domain(context);
        if (!urs_unknowns)
                bset = isl_basic_set_intersect(bset,
-               isl_basic_set_positive_orthant(isl_basic_set_get_dim(bset)));
+               isl_basic_set_positive_orthant(isl_basic_set_get_space(bset)));
 
        if (options->verify) {
                copy = isl_basic_set_copy(bset);
diff --git a/print.c b/print.c
new file mode 100644 (file)
index 0000000..b8396d6
--- /dev/null
+++ b/print.c
@@ -0,0 +1,71 @@
+#include <isl/ctx.h>
+#include <isl/id.h>
+#include <isl/space.h>
+#include <isl/local_space.h>
+#include <isl/set.h>
+#include <isl/map.h>
+#include <isl/union_set.h>
+#include <isl/union_map.h>
+#include <isl/polynomial.h>
+#include <isl/band.h>
+#include <isl/constraint.h>
+#include <isl/aff.h>
+#include <isl/printer.h>
+
+#undef BASE
+#define BASE id
+#include <print_templ.c>
+#undef BASE
+#define BASE space
+#include <print_templ.c>
+#undef BASE
+#define BASE local_space
+#include <print_templ.c>
+#undef BASE
+#define BASE basic_set
+#include <print_templ.c>
+#undef BASE
+#define BASE basic_map
+#include <print_templ.c>
+#undef BASE
+#define BASE set
+#include <print_templ.c>
+#undef BASE
+#define BASE map
+#include <print_templ.c>
+#undef BASE
+#define BASE union_set
+#include <print_templ.c>
+#undef BASE
+#define BASE union_map
+#include <print_templ.c>
+#undef BASE
+#define BASE qpolynomial
+#include <print_templ.c>
+#undef BASE
+#define BASE qpolynomial_fold
+#include <print_templ.c>
+#undef BASE
+#define BASE pw_qpolynomial
+#include <print_templ.c>
+#undef BASE
+#define BASE pw_qpolynomial_fold
+#include <print_templ.c>
+#undef BASE
+#define BASE union_pw_qpolynomial
+#include <print_templ.c>
+#undef BASE
+#define BASE union_pw_qpolynomial_fold
+#include <print_templ.c>
+#undef BASE
+#define BASE band
+#include <print_templ.c>
+#undef BASE
+#define BASE constraint
+#include <print_templ.c>
+#undef BASE
+#define BASE aff
+#include <print_templ.c>
+#undef BASE
+#define BASE pw_aff
+#include <print_templ.c>
diff --git a/print_templ.c b/print_templ.c
new file mode 100644 (file)
index 0000000..9dd9b86
--- /dev/null
@@ -0,0 +1,18 @@
+#define xCAT(A,B) A ## B
+#define CAT(A,B) xCAT(A,B)
+#undef TYPE
+#define TYPE CAT(isl_,BASE)
+#define xFN(TYPE,NAME) TYPE ## _ ## NAME
+#define FN(TYPE,NAME) xFN(TYPE,NAME)
+
+void FN(TYPE,dump)(__isl_keep TYPE *obj)
+{
+       isl_printer *p;
+
+       if (!obj)
+               return;
+       p = isl_printer_to_file(FN(TYPE,get_ctx)(obj), stderr);
+       p = FN(isl_printer_print,BASE)(p, obj);
+       p = isl_printer_end_line(p);
+       isl_printer_free(p);
+}