Revert "isl_input.c: read_tuple: construct isl_dim instead of isl_basic_map"
authorSven Verdoolaege <skimo@kotnet.org>
Wed, 22 Sep 2010 19:58:19 +0000 (21:58 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Wed, 22 Sep 2010 20:01:39 +0000 (22:01 +0200)
This reverts commit 6373465b50e93c0a8df20fdefe572a2eaebb8490.

It was thought that handling nested dims would be easier when
constructin isl_dims instead of isl_basic_maps during construction.
However, it turns out that using isl_basic_maps works just fine
and avoids carrying around the equalities separately.
Moreover, if we want to be able to parse integer divisions,
then we need to store their definitions somewhere and
an isl_basic_map is the most appropriate way to do so.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_input.c

index a9879bc..3d2f993 100644 (file)
@@ -140,24 +140,24 @@ static int vars_add_anon(struct vars *v)
        return 0;
 }
 
-static __isl_give isl_dim *set_name(__isl_take isl_dim *dim,
+static __isl_give isl_basic_map *set_name(__isl_take isl_basic_map *bmap,
        enum isl_dim_type type, unsigned pos, char *name)
 {
        char *prime;
 
-       if (!dim)
+       if (!bmap)
                return NULL;
        if (!name)
-               return dim;
+               return bmap;
 
        prime = strchr(name, '\'');
        if (prime)
                *prime = '\0';
-       dim = isl_dim_set_name(dim, type, pos, name);
+       bmap = isl_basic_map_set_dim_name(bmap, type, pos, name);
        if (prime)
                *prime = '\'';
 
-       return dim;
+       return bmap;
 }
 
 static int accept_cst_factor(struct isl_stream *s, isl_int *f)
@@ -330,32 +330,35 @@ error:
        return NULL;
 }
 
-static __isl_give isl_mat *read_var_def(struct isl_stream *s,
-       __isl_take isl_mat *eq, enum isl_dim_type type, struct vars *v)
+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)
 {
        struct isl_vec *vec;
+       int k;
 
        vec = accept_affine(s, v);
        if (!vec)
                goto error;
        if (vars_add_anon(v) < 0)
                goto error;
-       eq = isl_mat_add_rows(eq, 1);
-       if (eq) {
-               isl_seq_cpy(eq->row[eq->n_row - 1], vec->el, vec->size);
-               isl_int_set_si(eq->row[eq->n_row - 1][vec->size], -1);
+       bmap = isl_basic_map_extend_constraints(bmap, 1, 0);
+       k = isl_basic_map_alloc_equality(bmap);
+       if (k >= 0) {
+               isl_seq_cpy(bmap->eq[k], vec->el, vec->size);
+               isl_int_set_si(bmap->eq[k][vec->size], -1);
        }
        isl_vec_free(vec);
+       if (k < 0)
+               goto error;
 
-       return eq;
+       return bmap;
 error:
-       isl_mat_free(eq);
+       isl_basic_map_free(bmap);
        return NULL;
 }
 
-static __isl_give isl_dim *read_var_list(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_basic_map *read_var_list(struct isl_stream *s,
+       __isl_take isl_basic_map *bmap, enum isl_dim_type type, struct vars *v)
 {
        int i = 0;
        struct isl_token *tok;
@@ -372,10 +375,8 @@ static __isl_give isl_dim *read_var_list(struct isl_stream *s,
                }
 
                if (new_name) {
-                       dim = isl_dim_add(dim, type, 1);
-                       if (eq)
-                               *eq = isl_mat_add_zero_cols(*eq, 1);
-                       dim = set_name(dim, type, i, v->v->name);
+                       bmap = isl_basic_map_add(bmap, type, 1);
+                       bmap = set_name(bmap, type, i, v->v->name);
                        isl_token_free(tok);
                } else if (tok->type == ISL_TOKEN_IDENT ||
                           tok->type == ISL_TOKEN_VALUE ||
@@ -387,9 +388,8 @@ static __isl_give isl_dim *read_var_list(struct isl_stream *s,
                        }
                        isl_stream_push_token(s, tok);
                        tok = NULL;
-                       dim = isl_dim_add(dim, type, 1);
-                       *eq = isl_mat_add_zero_cols(*eq, 1);
-                       *eq = read_var_def(s, *eq, type, v);
+                       bmap = isl_basic_map_add(bmap, type, 1);
+                       bmap = read_var_def(s, bmap, type, v);
                } else
                        break;
 
@@ -403,10 +403,10 @@ static __isl_give isl_dim *read_var_list(struct isl_stream *s,
        if (tok)
                isl_stream_push_token(s, tok);
 
-       return dim;
+       return bmap;
 error:
        isl_token_free(tok);
-       isl_dim_free(dim);
+       isl_basic_map_free(bmap);
        return NULL;
 }
 
@@ -592,27 +592,25 @@ static int next_is_tuple(struct isl_stream *s)
        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_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_dim *read_nested_tuple(struct isl_stream *s,
-       __isl_take isl_dim *dim, struct vars *v, __isl_keep isl_mat **eq)
+static __isl_give isl_basic_map *read_nested_tuple(struct isl_stream *s,
+       __isl_take isl_basic_map *bmap, struct vars *v)
 {
-       dim = read_tuple(s, dim, isl_dim_in, v, eq);
+       bmap = read_tuple(s, bmap, isl_dim_in, v);
        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;
+       bmap = read_tuple(s, bmap, isl_dim_out, v);
+       bmap = isl_basic_map_from_range(isl_basic_map_wrap(bmap));
+       return bmap;
 error:
-       isl_dim_free(dim);
+       isl_basic_map_free(bmap);
        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)
+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)
 {
        struct isl_token *tok;
        char *name = NULL;
@@ -631,20 +629,22 @@ static __isl_give isl_dim *read_tuple(struct isl_stream *s,
        }
        isl_token_free(tok);
        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);
+               isl_dim *dim = isl_basic_map_get_dim(bmap);
+               isl_basic_map *nested;
+               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));
+               nested = isl_basic_map_alloc_dim(dim, 0, 0, 0);
+               nested = read_nested_tuple(s, nested, v);
                if (type == isl_dim_in) {
-                       isl_dim_free(dim);
-                       dim = isl_dim_reverse(nested);
+                       isl_basic_map_free(bmap);
+                       bmap = isl_basic_map_reverse(nested);
                } else {
-                       dim = isl_dim_join(dim, nested);
+                       bmap = isl_basic_map_apply_range(bmap, nested);
                }
        } else
-               dim = read_var_list(s, dim, type, v, eq);
+               bmap = read_var_list(s, bmap, type, v);
        tok = isl_stream_next_token(s);
        if (!tok || tok->type != ']') {
                isl_stream_error(s, tok, "expecting ']'");
@@ -653,15 +653,15 @@ static __isl_give isl_dim *read_tuple(struct isl_stream *s,
        isl_token_free(tok);
 
        if (name) {
-               dim = isl_dim_set_tuple_name(dim, type, name);
+               bmap = isl_basic_map_set_tuple_name(bmap, type, name);
                free(name);
        }
 
-       return dim;
+       return bmap;
 error:
        if (tok)
                isl_token_free(tok);
-       isl_dim_free(dim);
+       isl_basic_map_free(bmap);
        return NULL;
 }
 
@@ -1457,77 +1457,37 @@ error:
        return obj;
 }
 
-static __isl_give isl_basic_map *add_equalities(__isl_take isl_basic_map *bmap,
-       isl_mat *eq)
-{
-       int i, k;
-       unsigned total = 1 + isl_basic_map_total_dim(bmap);
-
-       if (!bmap || !eq)
-               goto error;
-
-       bmap = isl_basic_map_extend_constraints(bmap, eq->n_row, 0);
-
-       for (i = 0; i < eq->n_row; ++i) {
-               k = isl_basic_map_alloc_equality(bmap);
-               if (k < 0)
-                       goto error;
-               isl_seq_cpy(bmap->eq[k], eq->row[i], eq->n_col);
-               isl_seq_clr(bmap->eq[k] + eq->n_col, total - eq->n_col);
-       }
-
-       isl_mat_free(eq);
-       bmap = isl_basic_map_gauss(bmap, NULL);
-       bmap = isl_basic_map_finalize(bmap);
-       return bmap;
-error:
-       isl_mat_free(eq);
-       isl_basic_map_free(bmap);
-       return NULL;
-}
-
 static struct isl_obj obj_read_body(struct isl_stream *s,
-       __isl_take isl_dim *dim, struct vars *v)
+       __isl_take isl_basic_map *bmap, struct vars *v)
 {
        struct isl_map *map = NULL;
        struct isl_token *tok;
        struct isl_obj obj = { isl_obj_set, NULL };
        int n = v->n;
-       isl_mat *eq = NULL;
-       isl_basic_map *bmap;
 
-       if (!next_is_tuple(s)) {
-               bmap = isl_basic_map_alloc_dim(dim, 0, 0, 0);
+       if (!next_is_tuple(s))
                return obj_read_poly_or_fold(s, bmap, v, n);
-       }
-
-       eq = isl_mat_alloc(s->ctx, 0, 1 + n);
 
-       dim = read_tuple(s, dim, isl_dim_in, v, &eq);
-       if (!dim)
+       bmap = read_tuple(s, bmap, isl_dim_in, v);
+       if (!bmap)
                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_alloc_dim(dim, 0, 0, 0);
-                       bmap = add_equalities(bmap, eq);
                        bmap = isl_basic_map_reverse(bmap);
                        return obj_read_poly_or_fold(s, bmap, v, n);
                }
-               dim = read_tuple(s, dim, isl_dim_out, v, &eq);
-               if (!dim)
+               bmap = read_tuple(s, bmap, isl_dim_out, v);
+               if (!bmap)
                        goto error;
        } else {
-               dim = isl_dim_reverse(dim);
+               bmap = isl_basic_map_reverse(bmap);
                if (tok)
                        isl_stream_push_token(s, tok);
        }
 
-       bmap = isl_basic_map_alloc_dim(dim, 0, 0, 0);
-       bmap = add_equalities(bmap, eq);
-
        map = read_optional_disjuncts(s, bmap, v);
 
        vars_drop(v, v->n - n);
@@ -1535,8 +1495,7 @@ static struct isl_obj obj_read_body(struct isl_stream *s,
        obj.v = map;
        return obj;
 error:
-       isl_mat_free(eq);
-       isl_dim_free(dim);
+       isl_basic_map_free(bmap);
        obj.type = isl_obj_none;
        return obj;
 }
@@ -1618,7 +1577,7 @@ error:
 
 static struct isl_obj obj_read(struct isl_stream *s, int nparam)
 {
-       isl_dim *dim = NULL;
+       isl_basic_map *bmap = NULL;
        struct isl_token *tok;
        struct vars *v = NULL;
        struct isl_obj obj = { isl_obj_set, NULL };
@@ -1644,11 +1603,11 @@ static struct isl_obj obj_read(struct isl_stream *s, int nparam)
                isl_stream_push_token(s, tok);
                goto error;
        }
-       dim = isl_dim_alloc(s->ctx, 0, 0, 0);
+       bmap = isl_basic_map_alloc(s->ctx, 0, 0, 0, 0, 0, 0);
        if (tok->type == '[') {
                isl_stream_push_token(s, tok);
-               dim = read_tuple(s, dim, isl_dim_param, v, NULL);
-               if (!dim)
+               bmap = read_tuple(s, bmap, isl_dim_param, v);
+               if (!bmap)
                        goto error;
                if (nparam >= 0)
                        isl_assert(s->ctx, nparam == v->n, goto error);
@@ -1662,7 +1621,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)
-               dim = isl_dim_add(dim, isl_dim_param, nparam);
+               bmap = isl_basic_map_add(bmap, isl_dim_param, nparam);
        if (!tok || tok->type != '{') {
                isl_stream_error(s, tok, "expecting '{'");
                if (tok)
@@ -1678,14 +1637,14 @@ static struct isl_obj obj_read(struct isl_stream *s, int nparam)
                isl_token_free(tok);
                if (isl_stream_eat(s, '='))
                        goto error;
-               dim = read_tuple(s, dim, isl_dim_param, v, NULL);
-               if (!dim)
+               bmap = read_tuple(s, bmap, isl_dim_param, v);
+               if (!bmap)
                        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_dim_copy(dim));
+               obj.v = isl_union_set_empty(isl_basic_map_get_dim(bmap));
                isl_token_free(tok);
                goto done;
        } else
@@ -1694,7 +1653,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_dim_copy(dim), v);
+               o = obj_read_body(s, isl_basic_map_copy(bmap), v);
                if (o.type == isl_obj_none || !o.v)
                        goto error;
                if (!obj.v)
@@ -1720,11 +1679,11 @@ static struct isl_obj obj_read(struct isl_stream *s, int nparam)
        }
 done:
        vars_free(v);
-       isl_dim_free(dim);
+       isl_basic_map_free(bmap);
 
        return obj;
 error:
-       isl_dim_free(dim);
+       isl_basic_map_free(bmap);
        obj.type->free(obj.v);
        if (v)
                vars_free(v);