isl_set_intersect: properly handle intersection with parameter domains
[platform/upstream/isl.git] / isl_affine_hull.c
index 0707bc1..96af313 100644 (file)
@@ -7,8 +7,8 @@
  * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
  */
 
+#include <isl_ctx_private.h>
 #include <isl_map_private.h>
-#include <isl/ctx.h>
 #include <isl/seq.h>
 #include <isl/set.h>
 #include <isl/lp.h>
@@ -461,7 +461,7 @@ static struct isl_basic_set *uset_affine_hull_bounded(struct isl_basic_set *bset
        struct isl_tab *tab = NULL;
        unsigned dim;
 
-       if (isl_basic_set_fast_is_empty(bset))
+       if (isl_basic_set_plain_is_empty(bset))
                return bset;
 
        dim = isl_basic_set_n_dim(bset);
@@ -524,7 +524,7 @@ error:
 }
 
 /* Given an unbounded tableau and an integer point satisfying the tableau,
- * construct an intial affine hull containing the recession cone
+ * construct an initial affine hull containing the recession cone
  * shifted to the given point.
  *
  * The unbounded directions are taken from the last rows of the basis,
@@ -576,7 +576,7 @@ error:
  * isl_tab_set_initial_basis_with_cone will add some additional
  * constraints to the tableau that have to be removed again.
  * In this case, we therefore rollback to the state before
- * any constraints were added and then add the eqaulities back in.
+ * any constraints were added and then add the equalities back in.
  */
 struct isl_tab *isl_tab_detect_equalities(struct isl_tab *tab,
        struct isl_tab *tab_cone)
@@ -697,7 +697,7 @@ static struct isl_basic_set *affine_hull_with_cone(struct isl_basic_set *bset,
        total = isl_basic_set_total_dim(cone);
        cone_dim = total - cone->n_eq;
 
-       M = isl_mat_sub_alloc(bset->ctx, cone->eq, 0, cone->n_eq, 1, total);
+       M = isl_mat_sub_alloc6(bset->ctx, cone->eq, 0, cone->n_eq, 1, total);
        M = isl_mat_left_hermite(M, 0, &U, &Q);
        if (!M)
                goto error;
@@ -764,7 +764,7 @@ static struct isl_basic_set *uset_affine_hull(struct isl_basic_set *bset)
 {
        struct isl_basic_set *cone;
 
-       if (isl_basic_set_fast_is_empty(bset))
+       if (isl_basic_set_plain_is_empty(bset))
                return bset;
 
        cone = isl_basic_set_recession_cone(isl_basic_set_copy(bset));
@@ -873,7 +873,7 @@ struct isl_basic_map *isl_basic_map_detect_equalities(
                isl_basic_set_free(hull);
                return isl_basic_map_set_to_empty(bmap);
        }
-       bmap = isl_basic_map_extend_dim(bmap, isl_dim_copy(bmap->dim), 0,
+       bmap = isl_basic_map_extend_space(bmap, isl_space_copy(bmap->dim), 0,
                                        hull->n_eq, 0);
        for (i = 0; i < hull->n_eq; ++i) {
                j = isl_basic_map_alloc_equality(bmap);
@@ -901,7 +901,8 @@ __isl_give isl_basic_set *isl_basic_set_detect_equalities(
                isl_basic_map_detect_equalities((isl_basic_map *)bset);
 }
 
-struct isl_map *isl_map_detect_equalities(struct isl_map *map)
+__isl_give isl_map *isl_map_inline_foreach_basic_map(__isl_take isl_map *map,
+       __isl_give isl_basic_map *(*fn)(__isl_take isl_basic_map *bmap))
 {
        struct isl_basic_map *bmap;
        int i;
@@ -911,7 +912,7 @@ struct isl_map *isl_map_detect_equalities(struct isl_map *map)
 
        for (i = 0; i < map->n; ++i) {
                bmap = isl_basic_map_copy(map->p[i]);
-               bmap = isl_basic_map_detect_equalities(bmap);
+               bmap = fn(bmap);
                if (!bmap)
                        goto error;
                isl_basic_map_free(map->p[i]);
@@ -924,6 +925,12 @@ error:
        return NULL;
 }
 
+__isl_give isl_map *isl_map_detect_equalities(__isl_take isl_map *map)
+{
+       return isl_map_inline_foreach_basic_map(map,
+                                           &isl_basic_map_detect_equalities);
+}
+
 __isl_give isl_set *isl_set_detect_equalities(__isl_take isl_set *set)
 {
        return (isl_set *)isl_map_detect_equalities((isl_map *)set);
@@ -939,6 +946,7 @@ struct isl_basic_map *isl_basic_map_affine_hull(struct isl_basic_map *bmap)
        bmap = isl_basic_map_cow(bmap);
        if (bmap)
                isl_basic_map_free_inequality(bmap, bmap->n_ineq);
+       bmap = isl_basic_map_finalize(bmap);
        return bmap;
 }