isl_map_underlying_set: align divs before calling this function
authorSven Verdoolaege <skimo@kotnet.org>
Mon, 22 Dec 2008 15:21:34 +0000 (16:21 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Mon, 22 Dec 2008 15:21:34 +0000 (16:21 +0100)
We need to know the meaning of the variables of the set returned by
isl_map_underlying_set in order to add it back in isl_basic_map_overlying_set,
but the number and the order of the existentially quantified variables
may change during a call to isl_map_align_divs.
We therefore need to call isl_map_align_divs first and use one of
the resulting basic maps as a model in our call to isl_basic_map_overlying_set.

isl_convex_hull.c
isl_map.c

index 163ca60..a5d45da 100644 (file)
@@ -1153,6 +1153,7 @@ error:
 struct isl_basic_map *isl_map_convex_hull(struct isl_map *map)
 {
        struct isl_basic_set *bset;
+       struct isl_basic_map *model = NULL;
        struct isl_basic_set *affine_hull = NULL;
        struct isl_basic_map *convex_hull = NULL;
        struct isl_set *set = NULL;
@@ -1168,7 +1169,9 @@ struct isl_basic_map *isl_map_convex_hull(struct isl_map *map)
                return convex_hull;
        }
 
-       set = isl_map_underlying_set(isl_map_copy(map));
+       map = isl_map_align_divs(map);
+       model = isl_basic_map_copy(map->p[0]);
+       set = isl_map_underlying_set(map);
        if (!set)
                goto error;
 
@@ -1182,15 +1185,13 @@ struct isl_basic_map *isl_map_convex_hull(struct isl_map *map)
                bset = uset_convex_hull(set);
        }
 
-       convex_hull = isl_basic_map_overlying_set(bset,
-                       isl_basic_map_copy(map->p[0]));
+       convex_hull = isl_basic_map_overlying_set(bset, model);
 
-       isl_map_free(map);
        F_CLR(convex_hull, ISL_BASIC_MAP_RATIONAL);
        return convex_hull;
 error:
        isl_set_free(set);
-       isl_map_free(map);
+       isl_basic_map_free(model);
        return NULL;
 }
 
@@ -1202,10 +1203,15 @@ struct isl_basic_set *isl_set_convex_hull(struct isl_set *set)
 
 /* Compute a superset of the convex hull of map that is described
  * by only translates of the constraints in the constituents of map.
+ *
+ * The implementation is not very efficient.  In particular, if
+ * constraints with the same normal appear in more than one
+ * basic map, they will be (re)examined each time.
  */
 struct isl_basic_map *isl_map_simple_hull(struct isl_map *map)
 {
        struct isl_set *set = NULL;
+       struct isl_basic_map *model = NULL;
        struct isl_basic_map *hull;
        struct isl_basic_set *bset = NULL;
        int i, j;
@@ -1225,6 +1231,9 @@ struct isl_basic_map *isl_map_simple_hull(struct isl_map *map)
                return hull;
        }
 
+       map = isl_map_align_divs(map);
+       model = isl_basic_map_copy(map->p[0]);
+
        n_ineq = 0;
        for (i = 0; i < map->n; ++i) {
                if (!map->p[i])
@@ -1232,7 +1241,7 @@ struct isl_basic_map *isl_map_simple_hull(struct isl_map *map)
                n_ineq += map->p[i]->n_ineq;
        }
 
-       set = isl_map_underlying_set(isl_map_copy(map));
+       set = isl_map_underlying_set(map);
        if (!set)
                goto error;
 
@@ -1266,15 +1275,14 @@ struct isl_basic_map *isl_map_simple_hull(struct isl_map *map)
        bset = isl_basic_set_finalize(bset);
        bset = isl_basic_set_convex_hull(bset);
 
-       hull = isl_basic_map_overlying_set(bset, isl_basic_map_copy(map->p[0]));
+       hull = isl_basic_map_overlying_set(bset, isl_basic_map_copy(model));
 
        isl_set_free(set);
-       isl_map_free(map);
        return hull;
 error:
        isl_basic_set_free(bset);
        isl_set_free(set);
-       isl_map_free(map);
+       isl_basic_map_free(model);
        return NULL;
 }
 
index 2e702f0..e3d6fb7 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -2943,7 +2943,6 @@ struct isl_set *isl_map_underlying_set(struct isl_map *map)
 {
        int i;
 
-       map = isl_map_align_divs(map);
        map = isl_map_cow(map);
        if (!map)
                return NULL;
@@ -2951,6 +2950,9 @@ struct isl_set *isl_map_underlying_set(struct isl_map *map)
        if (!map->dim)
                goto error;
 
+       for (i = 1; i < map->n; ++i)
+               isl_assert(map->ctx, map->p[0]->n_div == map->p[i]->n_div,
+                               goto error);
        for (i = 0; i < map->n; ++i) {
                map->p[i] = (struct isl_basic_map *)
                                isl_basic_map_underlying_set(map->p[i]);