change calling conventions of isl_basic_set_has_defining_{,in}equalit{y,ies}
[platform/upstream/isl.git] / isl_convex_hull.c
index 4d09999..a5d45da 100644 (file)
@@ -891,9 +891,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(set->ctx, 0, 0);
+               convex_hull = isl_basic_set_empty(isl_dim_copy(set->dim));
        else
-               convex_hull = isl_basic_set_universe(set->ctx, 0, 0);
+               convex_hull = isl_basic_set_universe(isl_dim_copy(set->dim));
        isl_set_free(set);
        return convex_hull;
 }
@@ -1048,11 +1048,6 @@ static struct isl_basic_set *uset_convex_hull(struct isl_set *set)
        set = isl_set_remove_empty_parts(set);
        if (!set)
                return NULL;
-       if (isl_set_n_dim(set) == 0) {
-               convex_hull = isl_basic_set_empty(set->ctx, 0, 0);
-               isl_set_free(set);
-               return convex_hull;
-       }
        if (set->n == 1) {
                convex_hull = isl_basic_set_copy(set->p[0]);
                isl_set_free(set);
@@ -1086,7 +1081,7 @@ static struct isl_basic_set *uset_convex_hull_wrap(struct isl_set *set)
        struct isl_mat *bounds;
 
        if (isl_set_n_dim(set) == 0) {
-               convex_hull = isl_basic_set_universe(set->ctx, 0, 0);
+               convex_hull = isl_basic_set_universe(isl_dim_copy(set->dim));
                isl_set_free(set);
                convex_hull = isl_basic_set_set_rational(convex_hull);
                return convex_hull;
@@ -1158,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;
@@ -1173,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;
 
@@ -1187,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;
 }
 
@@ -1207,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;
@@ -1230,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])
@@ -1237,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;
 
@@ -1271,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;
 }