isl_stream_read_map: read_var_def: read var definition in "clean" basic map
authorSven Verdoolaege <skimo@kotnet.org>
Thu, 28 Oct 2010 18:49:06 +0000 (20:49 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Thu, 28 Oct 2010 18:50:24 +0000 (20:50 +0200)
The original code would mix up integer division already in bmap and newly
added integer divisions.

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

index ff8c1e5..6da79e6 100644 (file)
@@ -392,6 +392,8 @@ error:
 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)
 {
+       isl_dim *dim;
+       isl_basic_map *def = NULL;
        struct isl_vec *vec;
        int k;
        int n;
@@ -404,12 +406,14 @@ static __isl_give isl_basic_map *read_var_def(struct isl_stream *s,
        if (!vec)
                goto error;
 
-       bmap = add_divs(bmap, v);
-       bmap = isl_basic_map_extend_constraints(bmap, 1, 0);
-       k = isl_basic_map_alloc_equality(bmap);
+       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(bmap->eq[k], vec->el, vec->size);
-               isl_int_set_si(bmap->eq[k][1 + n - 1], -1);
+               isl_seq_cpy(def->eq[k], vec->el, vec->size);
+               isl_int_set_si(def->eq[k][1 + n - 1], -1);
        }
        isl_vec_free(vec);
        if (k < 0)
@@ -417,9 +421,13 @@ static __isl_give isl_basic_map *read_var_def(struct isl_stream *s,
 
        vars_drop(v, v->n - n);
 
+       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;
 }
 
@@ -470,8 +478,6 @@ static __isl_give isl_basic_map *read_var_list(struct isl_stream *s,
        if (tok)
                isl_stream_push_token(s, tok);
 
-       bmap = isl_basic_map_simplify(bmap);
-       bmap = isl_basic_map_finalize(bmap);
        return bmap;
 error:
        isl_token_free(tok);
index c4d8b51..3548c91 100644 (file)
@@ -30,7 +30,7 @@ void test_parse_map(isl_ctx *ctx, const char *str)
 
 void test_parse(struct isl_ctx *ctx)
 {
-       isl_map *map;
+       isl_map *map, *map2;
        const char *str;
 
        str = "{ [i] -> [-i] }";
@@ -44,6 +44,17 @@ void test_parse(struct isl_ctx *ctx)
        isl_map_free(map);
 
        test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
+
+       str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
+       map = isl_map_read_from_str(ctx, str, -1);
+       str = "{ [new, old] -> [o0, o1] : "
+              "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
+              "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
+              "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
+       map2 = isl_map_read_from_str(ctx, str, -1);
+       assert(isl_map_is_equal(map, map2));
+       isl_map_free(map);
+       isl_map_free(map2);
 }
 
 void test_read(struct isl_ctx *ctx)