support nested isl_dims
authorSven Verdoolaege <skimo@kotnet.org>
Mon, 2 Aug 2010 14:56:35 +0000 (16:56 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Thu, 5 Aug 2010 15:14:38 +0000 (17:14 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
12 files changed:
doc/user.pod
include/isl_dim.h
include/isl_map.h
include/isl_union_map.h
isl_dim.c
isl_dim_private.h
isl_input.c
isl_map.c
isl_map_private.h
isl_output.c
isl_transitive_closure.c
isl_union_map.c

index 7364e3d..3329122 100644 (file)
@@ -449,6 +449,23 @@ data structure.
 Binary operations require the corresponding spaces of their arguments
 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.
+
 =head2 Input and Output
 
 C<isl> supports its own input/output format, which is similar
@@ -921,6 +938,15 @@ is already known to be empty.
 
        int isl_map_is_bijective(__isl_keep isl_map *map);
 
+=item * Wrapping
+
+The followning functions check whether the domain of the given
+(basic) set is a wrapped relation.
+
+       int isl_basic_set_is_wrapping(
+               __isl_keep isl_basic_set *bset);
+       int isl_set_is_wrapping(__isl_keep isl_set *set);
+
 =back
 
 =head3 Binary Properties
@@ -1134,6 +1160,21 @@ Note, however, that C<isl_map_lexmax> expects the maximum to be
 finite, so if the path lengths are unbounded (possibly due to
 the overapproximation), then you will get an error message.
 
+=item * Wrapping
+
+       __isl_give isl_basic_set *isl_basic_map_wrap(
+               __isl_take isl_basic_map *bmap);
+       __isl_give isl_set *isl_map_wrap(
+               __isl_take isl_map *map);
+       __isl_give isl_union_set *isl_union_map_wrap(
+               __isl_take isl_union_map *umap);
+       __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_union_map *isl_union_set_unwrap(
+               __isl_take isl_union_set *uset);
+
 =back
 
 =head2 Binary Operations
index c2ebdf8..99d5629 100644 (file)
@@ -71,6 +71,10 @@ struct isl_dim *isl_dim_domain(struct isl_dim *dim);
 struct isl_dim *isl_dim_range(struct isl_dim *dim);
 struct isl_dim *isl_dim_underlying(struct isl_dim *dim, unsigned n_div);
 
+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_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);
index ce41c43..ffac0d3 100644 (file)
@@ -356,6 +356,12 @@ struct isl_map *isl_map_remove(struct isl_map *map,
 struct isl_map *isl_map_remove_inputs(struct isl_map *map,
        unsigned first, unsigned n);
 
+int isl_basic_set_is_wrapping(__isl_keep isl_basic_set *bset);
+int isl_set_is_wrapping(__isl_keep isl_set *set);
+__isl_give isl_basic_set *isl_basic_map_wrap(__isl_take isl_basic_map *bmap);
+__isl_give isl_set *isl_map_wrap(__isl_take isl_map *map);
+__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_set *isl_map_domain(__isl_take isl_map *bmap);
 __isl_give isl_set *isl_map_range(__isl_take isl_map *map);
 __isl_give isl_map *isl_map_from_basic_map(__isl_take isl_basic_map *bmap);
index a96483e..23bed6b 100644 (file)
@@ -80,6 +80,9 @@ __isl_give isl_union_map *isl_union_map_transitive_closure(
 __isl_give isl_printer *isl_printer_print_union_map(__isl_take isl_printer *p,
        __isl_keep isl_union_map *umap);
 
+__isl_give isl_union_set *isl_union_map_wrap(__isl_take isl_union_map *umap);
+__isl_give isl_union_map *isl_union_set_unwrap(__isl_take isl_union_set *uset);
+
 #if defined(__cplusplus)
 }
 #endif
index 19a6bf9..2f06824 100644 (file)
--- a/isl_dim.c
+++ b/isl_dim.c
@@ -1,10 +1,13 @@
 /*
  * 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>
@@ -35,6 +38,9 @@ struct isl_dim *isl_dim_alloc(struct isl_ctx *ctx,
        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;
 
@@ -213,6 +219,10 @@ struct isl_dim *isl_dim_dup(struct isl_dim *dim)
        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);
@@ -257,6 +267,9 @@ void isl_dim_free(struct isl_dim *dim)
        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);
@@ -359,10 +372,23 @@ static struct isl_name *tuple_name(__isl_keep isl_dim *dim,
        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 (n(dim1, dim1_type) != n(dim2, dim2_type))
                return 0;
@@ -372,6 +398,12 @@ int isl_dim_tuple_match(__isl_keep isl_dim *dim1, enum isl_dim_type dim1_type,
                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;
 }
 
@@ -454,14 +486,7 @@ struct isl_dim *isl_dim_add(struct isl_dim *dim, enum isl_dim_type type,
 {
        if (!dim)
                return NULL;
-       if ((type == isl_dim_in || type == isl_dim_out) &&
-           dim->tuple_name[type - isl_dim_in]) {
-               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;
-       }
+       dim = isl_dim_reset(dim, type);
        switch (type) {
        case isl_dim_param:
                return isl_dim_extend(dim,
@@ -483,8 +508,8 @@ __isl_give isl_dim *isl_dim_insert(__isl_take isl_dim *dim,
 
        if (!dim)
                return NULL;
-       if (n == 0 && !isl_dim_get_tuple_name(dim, type))
-               return dim;
+       if (n == 0)
+               return isl_dim_reset(dim, type);
 
        isl_assert(dim->ctx, pos <= isl_dim_size(dim, type), goto error);
 
@@ -524,10 +549,7 @@ __isl_give isl_dim *isl_dim_insert(__isl_take isl_dim *dim,
        case isl_dim_in:        dim->n_in += n; break;
        case isl_dim_out:       dim->n_out += n; break;
        }
-       if (type == isl_dim_in || type == isl_dim_out) {
-               isl_name_free(dim->ctx, dim->tuple_name[type - isl_dim_in]);
-               dim->tuple_name[type - isl_dim_in] = NULL;
-       }
+       dim = isl_dim_reset(dim, type);
 
        return dim;
 error:
@@ -552,6 +574,9 @@ __isl_give isl_dim *isl_dim_move(__isl_take isl_dim *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;
@@ -639,6 +664,12 @@ struct isl_dim *isl_dim_join(struct isl_dim *left, struct isl_dim *right)
        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);
@@ -688,7 +719,7 @@ struct isl_dim *isl_dim_map(struct isl_dim *dim)
        if (!dim)
                return NULL;
        isl_assert(dim->ctx, dim->n_in == 0, goto error);
-       if (dim->n_out == 0 && !dim->tuple_name[1])
+       if (dim->n_out == 0 && !isl_dim_is_named_or_nested(dim, isl_dim_out))
                return dim;
        dim = isl_dim_cow(dim);
        if (!dim)
@@ -710,6 +741,8 @@ struct isl_dim *isl_dim_map(struct isl_dim *dim)
        }
        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);
@@ -730,6 +763,7 @@ static struct isl_dim *set_names(struct isl_dim *dim, enum isl_dim_type type,
 struct isl_dim *isl_dim_reverse(struct isl_dim *dim)
 {
        unsigned t;
+       isl_dim *nested;
        struct isl_name **names = NULL;
        struct isl_name *name;
 
@@ -746,6 +780,10 @@ struct isl_dim *isl_dim_reverse(struct isl_dim *dim)
        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);
@@ -780,8 +818,8 @@ struct isl_dim *isl_dim_drop(struct isl_dim *dim, enum isl_dim_type type,
        if (!dim)
                return NULL;
 
-       if (n == 0 && !isl_dim_get_tuple_name(dim, type))
-               return dim;
+       if (n == 0)
+               return isl_dim_reset(dim, type);
 
        isl_assert(dim->ctx, first + num <= n(dim, type), goto error);
        dim = isl_dim_cow(dim);
@@ -812,10 +850,7 @@ struct isl_dim *isl_dim_drop(struct isl_dim *dim, enum isl_dim_type type,
        case isl_dim_in:        dim->n_in -= num; break;
        case isl_dim_out:       dim->n_out -= num; break;
        }
-       if (type == isl_dim_in || type == isl_dim_out) {
-               isl_name_free(dim->ctx, dim->tuple_name[type - isl_dim_in]);
-               dim->tuple_name[type - isl_dim_in] = NULL;
-       }
+       dim = isl_dim_reset(dim, type);
        return dim;
 error:
        isl_dim_free(dim);
@@ -861,10 +896,8 @@ __isl_give isl_dim *isl_dim_as_set_dim(__isl_take isl_dim *dim)
 
        dim->n_out += dim->n_in;
        dim->n_in = 0;
-       isl_name_free(dim->ctx, dim->tuple_name[0]);
-       isl_name_free(dim->ctx, dim->tuple_name[1]);
-       dim->tuple_name[0] = NULL;
-       dim->tuple_name[1] = NULL;
+       dim = isl_dim_reset(dim, isl_dim_in);
+       dim = isl_dim_reset(dim, isl_dim_out);
 
        return dim;
 }
@@ -876,9 +909,8 @@ struct isl_dim *isl_dim_underlying(struct isl_dim *dim, unsigned n_div)
        if (!dim)
                return NULL;
        if (n_div == 0 &&
-           dim->nparam == 0 && dim->n_in == 0 && dim->n_name == 0 &&
-           !dim->tuple_name[1])
-               return dim;
+           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;
@@ -889,10 +921,8 @@ struct isl_dim *isl_dim_underlying(struct isl_dim *dim, unsigned n_div)
        for (i = 0; i < dim->n_name; ++i)
                isl_name_free(dim->ctx, get_name(dim, isl_dim_out, i));
        dim->n_name = 0;
-       isl_name_free(dim->ctx, dim->tuple_name[0]);
-       isl_name_free(dim->ctx, dim->tuple_name[1]);
-       dim->tuple_name[0] = NULL;
-       dim->tuple_name[1] = NULL;
+       dim = isl_dim_reset(dim, isl_dim_in);
+       dim = isl_dim_reset(dim, isl_dim_out);
 
        return dim;
 }
@@ -915,15 +945,13 @@ int isl_dim_compatible(struct isl_dim *dim1, struct isl_dim *dim2)
               dim1->n_in + dim1->n_out == dim2->n_in + dim2->n_out;
 }
 
-uint32_t isl_dim_get_hash(__isl_keep isl_dim *dim)
+static uint32_t isl_hash_dim(uint32_t hash, __isl_keep isl_dim *dim)
 {
        int i;
-       uint32_t hash;
        struct isl_name *name;
 
        if (!dim)
-               return 0;
-       hash = isl_hash_init();
+               return hash;
 
        hash = isl_hash_builtin(hash, dim->nparam);
        hash = isl_hash_builtin(hash, dim->n_in);
@@ -939,5 +967,107 @@ uint32_t isl_dim_get_hash(__isl_keep isl_dim *dim)
        name = tuple_name(dim, isl_dim_out);
        hash = isl_hash_builtin(hash, name);
 
+       hash = isl_hash_dim(hash, dim->nested[0]);
+       hash = isl_hash_dim(hash, dim->nested[1]);
+
        return hash;
 }
+
+uint32_t isl_dim_get_hash(__isl_keep isl_dim *dim)
+{
+       uint32_t hash;
+
+       if (!dim)
+               return 0;
+
+       hash = isl_hash_init();
+       hash = isl_hash_dim(hash, dim);
+
+       return hash;
+}
+
+int isl_dim_is_wrapping(__isl_keep isl_dim *dim)
+{
+       if (!dim)
+               return -1;
+
+       if (dim->n_in != 0 || dim->tuple_name[0] || dim->nested[0])
+               return 0;
+
+       return dim->nested[1] != NULL;
+}
+
+__isl_give isl_dim *isl_dim_wrap(__isl_take isl_dim *dim)
+{
+       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;
+}
+
+__isl_give isl_dim *isl_dim_unwrap(__isl_take isl_dim *dim)
+{
+       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;
+}
+
+int isl_dim_is_named_or_nested(__isl_keep isl_dim *dim, enum isl_dim_type type)
+{
+       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;
+}
+
+__isl_give isl_dim *isl_dim_reset(__isl_take isl_dim *dim,
+       enum isl_dim_type type)
+{
+       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;
+}
index 4972b08..50f63a5 100644 (file)
@@ -12,6 +12,7 @@ struct isl_dim {
        unsigned n_out;         /* dim for sets */
 
        struct isl_name *tuple_name[2];
+       struct isl_dim *nested[2];
 
        unsigned n_name;
        struct isl_name **names;
@@ -22,3 +23,7 @@ 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_is_named_or_nested(__isl_keep isl_dim *dim, enum isl_dim_type type);
+__isl_give isl_dim *isl_dim_reset(__isl_take isl_dim *dim,
+       enum isl_dim_type type);
index 71b4acf..32cb037 100644 (file)
@@ -539,6 +539,48 @@ error:
        return NULL;
 }
 
+static int next_is_tuple(struct isl_stream *s)
+{
+       struct isl_token *tok;
+       int is_tuple;
+
+       tok = isl_stream_next_token(s);
+       if (!tok)
+               return 0;
+       if (tok->type == '[') {
+               isl_stream_push_token(s, tok);
+               return 1;
+       }
+       if (tok->type != ISL_TOKEN_IDENT) {
+               isl_stream_push_token(s, tok);
+               return 0;
+       }
+
+       is_tuple = isl_stream_next_token_is(s, '[');
+
+       isl_stream_push_token(s, tok);
+
+       return is_tuple;
+}
+
+static __isl_give isl_dim *read_tuple(struct isl_stream *s,
+       __isl_take isl_dim *dim, enum isl_dim_type type, struct vars *v,
+       __isl_keep isl_mat **eq);
+
+static __isl_give isl_dim *read_nested_tuple(struct isl_stream *s,
+       __isl_take isl_dim *dim, struct vars *v, __isl_keep isl_mat **eq)
+{
+       dim = read_tuple(s, dim, isl_dim_in, v, eq);
+       if (isl_stream_eat(s, ISL_TOKEN_TO))
+               goto error;
+       dim = read_tuple(s, dim, isl_dim_out, v, eq);
+       dim = isl_dim_wrap(dim);
+       return dim;
+error:
+       isl_dim_free(dim);
+       return NULL;
+}
+
 static __isl_give isl_dim *read_tuple(struct isl_stream *s,
        __isl_take isl_dim *dim, enum isl_dim_type type, struct vars *v,
        __isl_keep isl_mat **eq)
@@ -559,7 +601,21 @@ static __isl_give isl_dim *read_tuple(struct isl_stream *s,
                goto error;
        }
        isl_token_free(tok);
-       dim = read_var_list(s, dim, type, v, eq);
+       if (type != isl_dim_param && next_is_tuple(s)) {
+               isl_dim *nested = isl_dim_copy(dim);
+               nested = isl_dim_drop(nested, isl_dim_in, 0,
+                                       isl_dim_size(nested, isl_dim_in));
+               nested = isl_dim_drop(nested, isl_dim_out, 0,
+                                       isl_dim_size(nested, isl_dim_out));
+               nested = read_nested_tuple(s, nested, v, eq);
+               if (type == isl_dim_in) {
+                       isl_dim_free(dim);
+                       dim = isl_dim_reverse(nested);
+               } else {
+                       dim = isl_dim_join(dim, nested);
+               }
+       } else
+               dim = read_var_list(s, dim, type, v, eq);
        tok = isl_stream_next_token(s);
        if (!tok || tok->type != ']') {
                isl_stream_error(s, tok, "expecting ']'");
@@ -1323,30 +1379,6 @@ static struct isl_obj obj_read_poly(struct isl_stream *s,
        return obj;
 }
 
-static int next_is_tuple(struct isl_stream *s)
-{
-       struct isl_token *tok;
-       int is_tuple;
-
-       tok = isl_stream_next_token(s);
-       if (!tok)
-               return 0;
-       if (tok->type == '[') {
-               isl_stream_push_token(s, tok);
-               return 1;
-       }
-       if (tok->type != ISL_TOKEN_IDENT) {
-               isl_stream_push_token(s, tok);
-               return 0;
-       }
-
-       is_tuple = isl_stream_next_token_is(s, '[');
-
-       isl_stream_push_token(s, tok);
-
-       return is_tuple;
-}
-
 static __isl_give isl_basic_map *add_equalities(__isl_take isl_basic_map *bmap,
        isl_mat *eq)
 {
index 1b0033f..de52699 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -7045,3 +7045,164 @@ int isl_set_is_box(__isl_keep isl_set *set)
 
        return isl_basic_set_is_box(set->p[0]);
 }
+
+int isl_basic_set_is_wrapping(__isl_keep isl_basic_set *bset)
+{
+       if (!bset)
+               return -1;
+       
+       return isl_dim_is_wrapping(bset->dim);
+}
+
+int isl_set_is_wrapping(__isl_keep isl_set *set)
+{
+       if (!set)
+               return -1;
+       
+       return isl_dim_is_wrapping(set->dim);
+}
+
+__isl_give isl_basic_set *isl_basic_map_wrap(__isl_take isl_basic_map *bmap)
+{
+       bmap = isl_basic_map_cow(bmap);
+       if (!bmap)
+               return NULL;
+
+       bmap->dim = isl_dim_wrap(bmap->dim);
+       if (!bmap->dim)
+               goto error;
+
+       bmap = isl_basic_map_finalize(bmap);
+
+       return (isl_basic_set *)bmap;
+error:
+       isl_basic_map_free(bmap);
+       return NULL;
+}
+
+__isl_give isl_set *isl_map_wrap(__isl_take isl_map *map)
+{
+       int i;
+
+       map = isl_map_cow(map);
+       if (!map)
+               return NULL;
+
+       for (i = 0; i < map->n; ++i) {
+               map->p[i] = (isl_basic_map *)isl_basic_map_wrap(map->p[i]);
+               if (!map->p[i])
+                       goto error;
+       }
+       map->dim = isl_dim_wrap(map->dim);
+       if (!map->dim)
+               goto error;
+
+       return (isl_set *)map;
+error:
+       isl_map_free(map);
+       return NULL;
+}
+
+__isl_give isl_basic_map *isl_basic_set_unwrap(__isl_take isl_basic_set *bset)
+{
+       bset = isl_basic_set_cow(bset);
+       if (!bset)
+               return NULL;
+
+       bset->dim = isl_dim_unwrap(bset->dim);
+       if (!bset->dim)
+               goto error;
+
+       bset = isl_basic_set_finalize(bset);
+
+       return (isl_basic_map *)bset;
+error:
+       isl_basic_set_free(bset);
+       return NULL;
+}
+
+__isl_give isl_map *isl_set_unwrap(__isl_take isl_set *set)
+{
+       int i;
+
+       if (!set)
+               return NULL;
+
+       if (!isl_set_is_wrapping(set))
+               isl_die(set->ctx, isl_error_invalid, "not a wrapping set",
+                       goto error);
+
+       set = isl_set_cow(set);
+       if (!set)
+               return NULL;
+
+       for (i = 0; i < set->n; ++i) {
+               set->p[i] = (isl_basic_set *)isl_basic_set_unwrap(set->p[i]);
+               if (!set->p[i])
+                       goto error;
+       }
+
+       set->dim = isl_dim_unwrap(set->dim);
+       if (!set->dim)
+               goto error;
+
+       return (isl_map *)set;
+error:
+       isl_set_free(set);
+       return NULL;
+}
+
+__isl_give isl_basic_map *isl_basic_map_reset(__isl_take isl_basic_map *bmap,
+       enum isl_dim_type type)
+{
+       if (!bmap)
+               return NULL;
+
+       if (!isl_dim_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);
+       if (!bmap->dim)
+               goto error;
+
+       bmap = isl_basic_map_finalize(bmap);
+
+       return bmap;
+error:
+       isl_basic_map_free(bmap);
+       return NULL;
+}
+
+__isl_give isl_map *isl_map_reset(__isl_take isl_map *map,
+       enum isl_dim_type type)
+{
+       int i;
+
+       if (!map)
+               return NULL;
+
+       if (!isl_dim_is_named_or_nested(map->dim, type))
+               return map;
+
+       map = isl_map_cow(map);
+       if (!map)
+               return NULL;
+
+       for (i = 0; i < map->n; ++i) {
+               map->p[i] = isl_basic_map_reset(map->p[i], type);
+               if (!map->p[i])
+                       goto error;
+       }
+       map->dim = isl_dim_reset(map->dim, type);
+       if (!map->dim)
+               goto error;
+
+       return map;
+error:
+       isl_map_free(map);
+       return NULL;
+}
index 5905e39..8053187 100644 (file)
@@ -11,6 +11,9 @@
 #include "isl_map.h"
 #include "isl_vec.h"
 
+__isl_give isl_map *isl_map_reset(__isl_take isl_map *map,
+       enum isl_dim_type type);
+
 __isl_give isl_map *isl_map_reset_dim(__isl_take isl_map *map,
        __isl_take isl_dim *dim);
 __isl_give isl_set *isl_set_reset_dim(__isl_take isl_set *set,
index 1880b29..20d7dc6 100644 (file)
@@ -259,7 +259,7 @@ static __isl_give isl_printer *print_affine(__isl_keep isl_basic_map *bmap,
 }
 
 static int defining_equality(__isl_keep isl_basic_map *eq,
-       enum isl_dim_type type, int pos)
+       __isl_keep isl_dim *dim, enum isl_dim_type type, int pos)
 {
        int i;
        unsigned total;
@@ -267,7 +267,7 @@ static int defining_equality(__isl_keep isl_basic_map *eq,
        if (!eq)
                return -1;
 
-       pos += isl_dim_offset(eq->dim, type);
+       pos += isl_dim_offset(dim, type);
        total = isl_basic_map_total_dim(eq);
 
        for (i = 0; i < eq->n_eq; ++i) {
@@ -281,33 +281,55 @@ static int defining_equality(__isl_keep isl_basic_map *eq,
        return -1;
 }
 
-static __isl_give isl_printer *print_var_list(__isl_keep isl_dim *dim,
-       __isl_take isl_printer *p, enum isl_dim_type type, int set, int latex,
-       __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)
 {
        int i, j;
 
-       for (i = 0; i < isl_dim_size(dim, type); ++i) {
+       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) {
                if (i)
                        p = isl_printer_print_str(p, ", ");
-               j = defining_equality(eq, type, i);
+               j = defining_equality(eq, global_dim, global_type, offset + i);
                if (j >= 0) {
-                       int pos = 1 + isl_dim_offset(dim, type) + i;
-                       p = print_affine_of_len(dim, p, eq->eq[j], pos, set);
-               } else
-                       p = print_name(dim, p, type, i, set, latex);
+                       int pos = 1 + isl_dim_offset(global_dim, global_type)
+                                   + offset + i;
+                       p = print_affine_of_len(eq->dim, p, eq->eq[j], pos, set);
+               } else {
+                       p = print_name(global_dim, p, global_type, offset + i,
+                                       set, latex);
+               }
        }
        return p;
 }
 
-static __isl_give isl_printer *print_tuple(__isl_keep isl_dim *dim,
-       __isl_take isl_printer *p, enum isl_dim_type type, int set, int latex,
-       __isl_keep isl_basic_map *eq)
+static __isl_give isl_printer *print_var_list(__isl_keep isl_dim *dim,
+       __isl_take isl_printer *p, enum isl_dim_type type,
+       int set, int latex, __isl_keep isl_basic_map *eq)
+{
+       return print_nested_var_list(p, dim, type, dim, type, set, 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);
+
+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)
 {
        const char *name = NULL;
-       unsigned n = isl_dim_size(dim, type);
-       if ((type == isl_dim_in || type == isl_dim_out)) {
-               name = isl_dim_get_tuple_name(dim, type);
+       unsigned n = isl_dim_size(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);
                if (name) {
                        if (latex)
                                p = isl_printer_print_str(p, "\\mathrm{");
@@ -318,19 +340,49 @@ static __isl_give isl_printer *print_tuple(__isl_keep isl_dim *dim,
        }
        if (!latex || n != 1 || name)
                p = isl_printer_print_str(p, s_open_list[latex]);
-       p = print_var_list(dim, p, type, set, latex, eq);
+       if ((local_type == isl_dim_in || local_type == isl_dim_out) &&
+           local_dim->nested[local_type - isl_dim_in]) {
+               if (global_dim != local_dim && local_type == isl_dim_out)
+                       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);
+       } else
+               p = print_nested_var_list(p, global_dim, global_type,
+                                local_dim, local_type, set, 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,
+       __isl_take isl_printer *p, enum isl_dim_type type,
+       int set, int latex, __isl_keep isl_basic_map *eq)
+{
+       return print_nested_tuple(p, dim, type, dim, type, set, 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)
+{
+       p = print_nested_tuple(p, global_dim, global_type,
+                       local_dim, isl_dim_in, set, latex, eq, offset);
+       p = isl_printer_print_str(p, s_to[0]);
+       p = print_nested_tuple(p, global_dim, global_type,
+                       local_dim, isl_dim_out, set, 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,
        __isl_keep isl_basic_map *eq)
 {
-       if (set) {
+       if (set)
                p = print_tuple(dim, p, isl_dim_set, 1, latex, eq);
-       else {
+       else {
                p = print_tuple(dim, p, isl_dim_in, 0, latex, eq);
                p = isl_printer_print_str(p, s_to[0]);
                p = print_tuple(dim, p, isl_dim_out, 0, latex, eq);
index 3bbf266..049a2f4 100644 (file)
@@ -1035,8 +1035,8 @@ static int composability(__isl_keep isl_set *C, int i,
 
 static __isl_give isl_map *anonymize(__isl_take isl_map *map)
 {
-       map = isl_map_set_tuple_name(map, isl_dim_in, NULL);
-       map = isl_map_set_tuple_name(map, isl_dim_out, NULL);
+       map = isl_map_reset(map, isl_dim_in);
+       map = isl_map_reset(map, isl_dim_out);
        return map;
 }
 
index 152dd81..999cd77 100644 (file)
@@ -790,7 +790,27 @@ __isl_give isl_union_set *isl_union_map_range(__isl_take isl_union_map *umap)
        return un_op(umap, &range_entry, 1);
 }
 
-static  int deltas_entry(void **entry, void *user)
+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 deltas_entry(void **entry, void *user)
 {
        isl_map *map = *entry;
        isl_union_set **res = user;
@@ -805,22 +825,39 @@ static  int deltas_entry(void **entry, void *user)
 
 __isl_give isl_union_set *isl_union_map_deltas(__isl_take isl_union_map *umap)
 {
-       isl_union_set *res;
+       return cond_un_op(umap, &deltas_entry);
+}
 
-       if (!umap)
-               return NULL;
+static int unwrap_entry(void **entry, void *user)
+{
+       isl_set *set = *entry;
+       isl_union_set **res = user;
 
-       res = isl_union_map_alloc(isl_dim_copy(umap->dim), umap->table.n);
-       if (isl_hash_table_foreach(umap->dim->ctx, &umap->table,
-                                  &deltas_entry, &res) < 0)
-               goto error;
+       if (!isl_set_is_wrapping(set))
+               return 0;
 
-       isl_union_map_free(umap);
-       return res;
-error:
-       isl_union_map_free(umap);
-       isl_union_set_free(res);
-       return NULL;
+       *res = isl_union_map_add_map(*res, isl_set_unwrap(isl_set_copy(set)));
+
+       return 0;
+}
+
+__isl_give isl_union_map *isl_union_set_unwrap(__isl_take isl_union_set *uset)
+{
+       return cond_un_op(uset, &unwrap_entry);
+}
+
+static int wrap_entry(void **entry, void *user)
+{
+       isl_map **map = (isl_map **)entry;
+
+       *map = (isl_map *)isl_map_wrap(*map);
+
+       return *map ? 0 : -1;
+}
+
+__isl_give isl_union_set *isl_union_map_wrap(__isl_take isl_union_map *umap)
+{
+       return un_op(umap, &wrap_entry, 1);
 }
 
 struct isl_union_map_is_subset_data {