6 #include "isl_map_private.h"
7 #include "isl_equalities.h"
8 #include "isl_sample.h"
11 struct isl_basic_map *isl_basic_map_implicit_equalities(
12 struct isl_basic_map *bmap)
19 bmap = isl_basic_map_gauss(bmap, NULL);
20 if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_EMPTY))
22 if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_NO_IMPLICIT))
24 if (bmap->n_ineq <= 1)
27 tab = isl_tab_from_basic_map(bmap);
28 tab = isl_tab_detect_implicit_equalities(tab);
29 bmap = isl_basic_map_update_from_tab(bmap, tab);
31 bmap = isl_basic_map_gauss(bmap, NULL);
32 ISL_F_SET(bmap, ISL_BASIC_MAP_NO_IMPLICIT);
36 struct isl_basic_set *isl_basic_set_implicit_equalities(
37 struct isl_basic_set *bset)
39 return (struct isl_basic_set *)
40 isl_basic_map_implicit_equalities((struct isl_basic_map*)bset);
43 struct isl_map *isl_map_implicit_equalities(struct isl_map *map)
50 for (i = 0; i < map->n; ++i) {
51 map->p[i] = isl_basic_map_implicit_equalities(map->p[i]);
62 /* Make eq[row][col] of both bmaps equal so we can add the row
63 * add the column to the common matrix.
64 * Note that because of the echelon form, the columns of row row
65 * after column col are zero.
67 static void set_common_multiple(
68 struct isl_basic_set *bset1, struct isl_basic_set *bset2,
69 unsigned row, unsigned col)
73 if (isl_int_eq(bset1->eq[row][col], bset2->eq[row][col]))
78 isl_int_lcm(m, bset1->eq[row][col], bset2->eq[row][col]);
79 isl_int_divexact(c, m, bset1->eq[row][col]);
80 isl_seq_scale(bset1->eq[row], bset1->eq[row], c, col+1);
81 isl_int_divexact(c, m, bset2->eq[row][col]);
82 isl_seq_scale(bset2->eq[row], bset2->eq[row], c, col+1);
87 /* Delete a given equality, moving all the following equalities one up.
89 static void delete_row(struct isl_basic_set *bset, unsigned row)
96 for (r = row; r < bset->n_eq; ++r)
97 bset->eq[r] = bset->eq[r+1];
98 bset->eq[bset->n_eq] = t;
101 /* Make first row entries in column col of bset1 identical to
102 * those of bset2, using the fact that entry bset1->eq[row][col]=a
103 * is non-zero. Initially, these elements of bset1 are all zero.
104 * For each row i < row, we set
105 * A[i] = a * A[i] + B[i][col] * A[row]
108 * A[i][col] = B[i][col] = a * old(B[i][col])
110 static void construct_column(
111 struct isl_basic_set *bset1, struct isl_basic_set *bset2,
112 unsigned row, unsigned col)
121 total = 1 + isl_basic_set_n_dim(bset1);
122 for (r = 0; r < row; ++r) {
123 if (isl_int_is_zero(bset2->eq[r][col]))
125 isl_int_gcd(b, bset2->eq[r][col], bset1->eq[row][col]);
126 isl_int_divexact(a, bset1->eq[row][col], b);
127 isl_int_divexact(b, bset2->eq[r][col], b);
128 isl_seq_combine(bset1->eq[r], a, bset1->eq[r],
129 b, bset1->eq[row], total);
130 isl_seq_scale(bset2->eq[r], bset2->eq[r], a, total);
134 delete_row(bset1, row);
137 /* Make first row entries in column col of bset1 identical to
138 * those of bset2, using only these entries of the two matrices.
139 * Let t be the last row with different entries.
140 * For each row i < t, we set
141 * A[i] = (A[t][col]-B[t][col]) * A[i] + (B[i][col]-A[i][col) * A[t]
142 * B[i] = (A[t][col]-B[t][col]) * B[i] + (B[i][col]-A[i][col) * B[t]
144 * A[i][col] = B[i][col] = old(A[t][col]*B[i][col]-A[i][col]*B[t][col])
146 static int transform_column(
147 struct isl_basic_set *bset1, struct isl_basic_set *bset2,
148 unsigned row, unsigned col)
154 for (t = row-1; t >= 0; --t)
155 if (isl_int_ne(bset1->eq[t][col], bset2->eq[t][col]))
160 total = 1 + isl_basic_set_n_dim(bset1);
164 isl_int_sub(b, bset1->eq[t][col], bset2->eq[t][col]);
165 for (i = 0; i < t; ++i) {
166 isl_int_sub(a, bset2->eq[i][col], bset1->eq[i][col]);
167 isl_int_gcd(g, a, b);
168 isl_int_divexact(a, a, g);
169 isl_int_divexact(g, b, g);
170 isl_seq_combine(bset1->eq[i], g, bset1->eq[i], a, bset1->eq[t],
172 isl_seq_combine(bset2->eq[i], g, bset2->eq[i], a, bset2->eq[t],
178 delete_row(bset1, t);
179 delete_row(bset2, t);
183 /* The implementation is based on Section 5.2 of Michael Karr,
184 * "Affine Relationships Among Variables of a Program",
185 * except that the echelon form we use starts from the last column
186 * and that we are dealing with integer coefficients.
188 static struct isl_basic_set *affine_hull(
189 struct isl_basic_set *bset1, struct isl_basic_set *bset2)
195 total = 1 + isl_basic_set_n_dim(bset1);
198 for (col = total-1; col >= 0; --col) {
199 int is_zero1 = row >= bset1->n_eq ||
200 isl_int_is_zero(bset1->eq[row][col]);
201 int is_zero2 = row >= bset2->n_eq ||
202 isl_int_is_zero(bset2->eq[row][col]);
203 if (!is_zero1 && !is_zero2) {
204 set_common_multiple(bset1, bset2, row, col);
206 } else if (!is_zero1 && is_zero2) {
207 construct_column(bset1, bset2, row, col);
208 } else if (is_zero1 && !is_zero2) {
209 construct_column(bset2, bset1, row, col);
211 if (transform_column(bset1, bset2, row, col))
215 isl_basic_set_free(bset2);
216 isl_assert(bset1->ctx, row == bset1->n_eq, goto error);
217 bset1 = isl_basic_set_normalize_constraints(bset1);
220 isl_basic_set_free(bset1);
224 /* Find an integer point in the set represented by "tab"
225 * that lies outside of the equality "eq" e(x) = 0.
226 * If "up" is true, look for a point satisfying e(x) - 1 >= 0.
227 * Otherwise, look for a point satisfying -e(x) - 1 >= 0 (i.e., e(x) <= -1).
228 * The point, if found, is returned.
229 * If no point can be found, a zero-length vector is returned.
231 * Before solving an ILP problem, we first check if simply
232 * adding the normal of the constraint to one of the known
233 * integer points in the basic set represented by "tab"
234 * yields another point inside the basic set.
236 * The caller of this function ensures that the tableau is bounded or
237 * that tab->basis and tab->n_unbounded have been set appropriately.
239 static struct isl_vec *outside_point(struct isl_tab *tab, isl_int *eq, int up)
242 struct isl_vec *sample = NULL;
243 struct isl_tab_undo *snap;
252 sample = isl_vec_alloc(ctx, 1 + dim);
255 isl_int_set_si(sample->el[0], 1);
256 isl_seq_combine(sample->el + 1,
257 ctx->one, tab->bset->sample->el + 1,
258 up ? ctx->one : ctx->negone, eq + 1, dim);
259 if (isl_basic_set_contains(tab->bset, sample))
261 isl_vec_free(sample);
264 snap = isl_tab_snap(tab);
267 isl_seq_neg(eq, eq, 1 + dim);
268 isl_int_sub_ui(eq[0], eq[0], 1);
270 if (isl_tab_extend_cons(tab, 1) < 0)
272 if (isl_tab_add_ineq(tab, eq) < 0)
275 sample = isl_tab_sample(tab);
277 isl_int_add_ui(eq[0], eq[0], 1);
279 isl_seq_neg(eq, eq, 1 + dim);
281 if (isl_tab_rollback(tab, snap) < 0)
286 isl_vec_free(sample);
290 struct isl_basic_set *isl_basic_set_recession_cone(struct isl_basic_set *bset)
294 bset = isl_basic_set_cow(bset);
297 isl_assert(bset->ctx, bset->n_div == 0, goto error);
299 for (i = 0; i < bset->n_eq; ++i)
300 isl_int_set_si(bset->eq[i][0], 0);
302 for (i = 0; i < bset->n_ineq; ++i)
303 isl_int_set_si(bset->ineq[i][0], 0);
305 ISL_F_CLR(bset, ISL_BASIC_SET_NO_IMPLICIT);
306 return isl_basic_set_implicit_equalities(bset);
308 isl_basic_set_free(bset);
312 /* Extend an initial (under-)approximation of the affine hull of basic
313 * set represented by the tableau "tab"
314 * by looking for points that do not satisfy one of the equalities
315 * in the current approximation and adding them to that approximation
316 * until no such points can be found any more.
318 * The caller of this function ensures that "tab" is bounded or
319 * that tab->basis and tab->n_unbounded have been set appropriately.
321 static struct isl_basic_set *extend_affine_hull(struct isl_tab *tab,
322 struct isl_basic_set *hull)
332 if (isl_tab_extend_cons(tab, 2 * dim + 1) < 0)
335 for (i = 0; i < dim; ++i) {
336 struct isl_vec *sample;
337 struct isl_basic_set *point;
338 for (j = 0; j < hull->n_eq; ++j) {
339 sample = outside_point(tab, hull->eq[j], 1);
342 if (sample->size > 0)
344 isl_vec_free(sample);
345 sample = outside_point(tab, hull->eq[j], 0);
348 if (sample->size > 0)
350 isl_vec_free(sample);
352 tab = isl_tab_add_eq(tab, hull->eq[j]);
359 tab = isl_tab_add_sample(tab, isl_vec_copy(sample));
362 point = isl_basic_set_from_vec(sample);
363 hull = affine_hull(hull, point);
368 isl_basic_set_free(hull);
372 /* Drop all constraints in bset that involve any of the dimensions
373 * first to first+n-1.
375 static struct isl_basic_set *drop_constraints_involving
376 (struct isl_basic_set *bset, unsigned first, unsigned n)
383 bset = isl_basic_set_cow(bset);
385 for (i = bset->n_eq - 1; i >= 0; --i) {
386 if (isl_seq_first_non_zero(bset->eq[i] + 1 + first, n) == -1)
388 isl_basic_set_drop_equality(bset, i);
391 for (i = bset->n_ineq - 1; i >= 0; --i) {
392 if (isl_seq_first_non_zero(bset->ineq[i] + 1 + first, n) == -1)
394 isl_basic_set_drop_inequality(bset, i);
400 /* Look for all equalities satisfied by the integer points in bset,
401 * which is assumed to be bounded.
403 * The equalities are obtained by successively looking for
404 * a point that is affinely independent of the points found so far.
405 * In particular, for each equality satisfied by the points so far,
406 * we check if there is any point on a hyperplane parallel to the
407 * corresponding hyperplane shifted by at least one (in either direction).
409 static struct isl_basic_set *uset_affine_hull_bounded(struct isl_basic_set *bset)
411 struct isl_vec *sample = NULL;
412 struct isl_basic_set *hull;
413 struct isl_tab *tab = NULL;
416 if (isl_basic_set_fast_is_empty(bset))
419 dim = isl_basic_set_n_dim(bset);
421 if (bset->sample && bset->sample->size == 1 + dim) {
422 int contains = isl_basic_set_contains(bset, bset->sample);
428 sample = isl_vec_copy(bset->sample);
430 isl_vec_free(bset->sample);
435 tab = isl_tab_from_basic_set(bset);
438 tab->bset = isl_basic_set_copy(bset);
441 struct isl_tab_undo *snap;
442 snap = isl_tab_snap(tab);
443 sample = isl_tab_sample(tab);
444 if (isl_tab_rollback(tab, snap) < 0)
446 isl_vec_free(tab->bset->sample);
447 tab->bset->sample = isl_vec_copy(sample);
452 if (sample->size == 0) {
454 isl_vec_free(sample);
455 return isl_basic_set_set_to_empty(bset);
458 hull = isl_basic_set_from_vec(sample);
460 isl_basic_set_free(bset);
461 hull = extend_affine_hull(tab, hull);
466 isl_vec_free(sample);
468 isl_basic_set_free(bset);
472 /* Given an unbounded tableau and an integer point satisfying the tableau,
473 * construct an intial affine hull containing the recession cone
474 * shifted to the given point.
476 * The unbounded directions are taken from the last rows of the basis,
477 * which is assumed to have been initialized appropriately.
479 static __isl_give isl_basic_set *initial_hull(struct isl_tab *tab,
480 __isl_take isl_vec *vec)
484 struct isl_basic_set *bset = NULL;
491 isl_assert(ctx, vec->size != 0, goto error);
493 bset = isl_basic_set_alloc(ctx, 0, vec->size - 1, 0, vec->size - 1, 0);
496 dim = isl_basic_set_n_dim(bset) - tab->n_unbounded;
497 for (i = 0; i < dim; ++i) {
498 k = isl_basic_set_alloc_equality(bset);
501 isl_seq_cpy(bset->eq[k] + 1, tab->basis->row[1 + i] + 1,
503 isl_seq_inner_product(bset->eq[k] + 1, vec->el +1,
504 vec->size - 1, &bset->eq[k][0]);
505 isl_int_neg(bset->eq[k][0], bset->eq[k][0]);
508 bset = isl_basic_set_gauss(bset, NULL);
512 isl_basic_set_free(bset);
517 /* Given a tableau of a set and a tableau of the corresponding
518 * recession cone, detect and add all equalities to the tableau.
519 * If the tableau is bounded, then we can simply keep the
520 * tableau in its state after the return from extend_affine_hull.
521 * However, if the tableau is unbounded, then
522 * isl_tab_set_initial_basis_with_cone will add some additional
523 * constraints to the tableau that have to be removed again.
524 * In this case, we therefore rollback to the state before
525 * any constraints were added and then add the eqaulities back in.
527 struct isl_tab *isl_tab_detect_equalities(struct isl_tab *tab,
528 struct isl_tab *tab_cone)
531 struct isl_vec *sample;
532 struct isl_basic_set *hull;
533 struct isl_tab_undo *snap;
535 if (!tab || !tab_cone)
538 snap = isl_tab_snap(tab);
540 isl_mat_free(tab->basis);
543 isl_assert(tab->mat->ctx, tab->bset, goto error);
544 isl_assert(tab->mat->ctx, tab->samples, goto error);
545 isl_assert(tab->mat->ctx, tab->samples->n_col == 1 + tab->n_var, goto error);
546 isl_assert(tab->mat->ctx, tab->n_sample > tab->n_outside, goto error);
548 if (isl_tab_set_initial_basis_with_cone(tab, tab_cone) < 0)
551 sample = isl_vec_alloc(tab->mat->ctx, 1 + tab->n_var);
555 isl_seq_cpy(sample->el, tab->samples->row[tab->n_outside], sample->size);
557 isl_vec_free(tab->bset->sample);
558 tab->bset->sample = isl_vec_copy(sample);
560 if (tab->n_unbounded == 0)
561 hull = isl_basic_set_from_vec(isl_vec_copy(sample));
563 hull = initial_hull(tab, isl_vec_copy(sample));
565 for (j = tab->n_outside + 1; j < tab->n_sample; ++j) {
566 isl_seq_cpy(sample->el, tab->samples->row[j], sample->size);
567 hull = affine_hull(hull,
568 isl_basic_set_from_vec(isl_vec_copy(sample)));
571 isl_vec_free(sample);
573 hull = extend_affine_hull(tab, hull);
577 if (tab->n_unbounded == 0) {
578 isl_basic_set_free(hull);
582 if (isl_tab_rollback(tab, snap) < 0)
585 if (hull->n_eq > tab->n_zero) {
586 for (j = 0; j < hull->n_eq; ++j) {
587 isl_seq_normalize(tab->mat->ctx, hull->eq[j], 1 + tab->n_var);
588 tab = isl_tab_add_eq(tab, hull->eq[j]);
592 isl_basic_set_free(hull);
600 /* Compute the affine hull of "bset", where "cone" is the recession cone
603 * We first compute a unimodular transformation that puts the unbounded
604 * directions in the last dimensions. In particular, we take a transformation
605 * that maps all equalities to equalities (in HNF) on the first dimensions.
606 * Let x be the original dimensions and y the transformed, with y_1 bounded
609 * [ y_1 ] [ y_1 ] [ Q_1 ]
610 * x = U [ y_2 ] [ y_2 ] = [ Q_2 ] x
612 * Let's call the input basic set S. We compute S' = preimage(S, U)
613 * and drop the final dimensions including any constraints involving them.
614 * This results in set S''.
615 * Then we compute the affine hull A'' of S''.
616 * Let F y_1 >= g be the constraint system of A''. In the transformed
617 * space the y_2 are unbounded, so we can add them back without any constraints,
621 * [ F 0 ] [ y_2 ] >= g
624 * [ F 0 ] [ Q_2 ] x >= g
628 * The affine hull in the original space is then obtained as
629 * A = preimage(A'', Q_1).
631 static struct isl_basic_set *affine_hull_with_cone(struct isl_basic_set *bset,
632 struct isl_basic_set *cone)
636 struct isl_basic_set *hull;
637 struct isl_mat *M, *U, *Q;
642 total = isl_basic_set_total_dim(cone);
643 cone_dim = total - cone->n_eq;
645 M = isl_mat_sub_alloc(bset->ctx, cone->eq, 0, cone->n_eq, 1, total);
646 M = isl_mat_left_hermite(M, 0, &U, &Q);
651 U = isl_mat_lin_to_aff(U);
652 bset = isl_basic_set_preimage(bset, isl_mat_copy(U));
654 bset = drop_constraints_involving(bset, total - cone_dim, cone_dim);
655 bset = isl_basic_set_drop_dims(bset, total - cone_dim, cone_dim);
657 Q = isl_mat_lin_to_aff(Q);
658 Q = isl_mat_drop_rows(Q, 1 + total - cone_dim, cone_dim);
660 if (bset && bset->sample && bset->sample->size == 1 + total)
661 bset->sample = isl_mat_vec_product(isl_mat_copy(Q), bset->sample);
663 hull = uset_affine_hull_bounded(bset);
668 struct isl_vec *sample = isl_vec_copy(hull->sample);
669 U = isl_mat_drop_cols(U, 1 + total - cone_dim, cone_dim);
670 if (sample && sample->size > 0)
671 sample = isl_mat_vec_product(U, sample);
674 hull = isl_basic_set_preimage(hull, Q);
675 isl_vec_free(hull->sample);
676 hull->sample = sample;
679 isl_basic_set_free(cone);
683 isl_basic_set_free(bset);
684 isl_basic_set_free(cone);
688 /* Look for all equalities satisfied by the integer points in bset,
689 * which is assumed not to have any explicit equalities.
691 * The equalities are obtained by successively looking for
692 * a point that is affinely independent of the points found so far.
693 * In particular, for each equality satisfied by the points so far,
694 * we check if there is any point on a hyperplane parallel to the
695 * corresponding hyperplane shifted by at least one (in either direction).
697 * Before looking for any outside points, we first compute the recession
698 * cone. The directions of this recession cone will always be part
699 * of the affine hull, so there is no need for looking for any points
700 * in these directions.
701 * In particular, if the recession cone is full-dimensional, then
702 * the affine hull is simply the whole universe.
704 static struct isl_basic_set *uset_affine_hull(struct isl_basic_set *bset)
706 struct isl_basic_set *cone;
708 if (isl_basic_set_fast_is_empty(bset))
711 cone = isl_basic_set_recession_cone(isl_basic_set_copy(bset));
714 if (cone->n_eq == 0) {
715 struct isl_basic_set *hull;
716 isl_basic_set_free(cone);
717 hull = isl_basic_set_universe_like(bset);
718 isl_basic_set_free(bset);
722 if (cone->n_eq < isl_basic_set_total_dim(cone))
723 return affine_hull_with_cone(bset, cone);
725 isl_basic_set_free(cone);
726 return uset_affine_hull_bounded(bset);
728 isl_basic_set_free(bset);
732 /* Look for all equalities satisfied by the integer points in bmap
733 * that are independent of the equalities already explicitly available
736 * We first remove all equalities already explicitly available,
737 * then look for additional equalities in the reduced space
738 * and then transform the result to the original space.
739 * The original equalities are _not_ added to this set. This is
740 * the responsibility of the calling function.
741 * The resulting basic set has all meaning about the dimensions removed.
742 * In particular, dimensions that correspond to existential variables
743 * in bmap and that are found to be fixed are not removed.
745 static struct isl_basic_set *equalities_in_underlying_set(
746 struct isl_basic_map *bmap)
748 struct isl_mat *T1 = NULL;
749 struct isl_mat *T2 = NULL;
750 struct isl_basic_set *bset = NULL;
751 struct isl_basic_set *hull = NULL;
753 bset = isl_basic_map_underlying_set(bmap);
757 bset = isl_basic_set_remove_equalities(bset, &T1, &T2);
761 hull = uset_affine_hull(bset);
768 struct isl_vec *sample = isl_vec_copy(hull->sample);
769 if (sample && sample->size > 0)
770 sample = isl_mat_vec_product(T1, sample);
773 hull = isl_basic_set_preimage(hull, T2);
774 isl_vec_free(hull->sample);
775 hull->sample = sample;
781 isl_basic_set_free(bset);
782 isl_basic_set_free(hull);
786 /* Detect and make explicit all equalities satisfied by the (integer)
789 struct isl_basic_map *isl_basic_map_detect_equalities(
790 struct isl_basic_map *bmap)
793 struct isl_basic_set *hull = NULL;
797 if (bmap->n_ineq == 0)
799 if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_EMPTY))
801 if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_ALL_EQUALITIES))
803 if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL))
804 return isl_basic_map_implicit_equalities(bmap);
806 hull = equalities_in_underlying_set(isl_basic_map_copy(bmap));
809 if (ISL_F_ISSET(hull, ISL_BASIC_SET_EMPTY)) {
810 isl_basic_set_free(hull);
811 return isl_basic_map_set_to_empty(bmap);
813 bmap = isl_basic_map_extend_dim(bmap, isl_dim_copy(bmap->dim), 0,
815 for (i = 0; i < hull->n_eq; ++i) {
816 j = isl_basic_map_alloc_equality(bmap);
819 isl_seq_cpy(bmap->eq[j], hull->eq[i],
820 1 + isl_basic_set_total_dim(hull));
822 isl_vec_free(bmap->sample);
823 bmap->sample = isl_vec_copy(hull->sample);
824 isl_basic_set_free(hull);
825 ISL_F_SET(bmap, ISL_BASIC_MAP_NO_IMPLICIT | ISL_BASIC_MAP_ALL_EQUALITIES);
826 bmap = isl_basic_map_simplify(bmap);
827 return isl_basic_map_finalize(bmap);
829 isl_basic_set_free(hull);
830 isl_basic_map_free(bmap);
834 __isl_give isl_basic_set *isl_basic_set_detect_equalities(
835 __isl_take isl_basic_set *bset)
837 return (isl_basic_set *)
838 isl_basic_map_detect_equalities((isl_basic_map *)bset);
841 struct isl_map *isl_map_detect_equalities(struct isl_map *map)
843 struct isl_basic_map *bmap;
849 for (i = 0; i < map->n; ++i) {
850 bmap = isl_basic_map_copy(map->p[i]);
851 bmap = isl_basic_map_detect_equalities(bmap);
854 isl_basic_map_free(map->p[i]);
864 __isl_give isl_set *isl_set_detect_equalities(__isl_take isl_set *set)
866 return (isl_set *)isl_map_detect_equalities((isl_map *)set);
869 /* After computing the rational affine hull (by detecting the implicit
870 * equalities), we compute the additional equalities satisfied by
871 * the integer points (if any) and add the original equalities back in.
873 struct isl_basic_map *isl_basic_map_affine_hull(struct isl_basic_map *bmap)
875 bmap = isl_basic_map_detect_equalities(bmap);
876 bmap = isl_basic_map_cow(bmap);
877 isl_basic_map_free_inequality(bmap, bmap->n_ineq);
881 struct isl_basic_set *isl_basic_set_affine_hull(struct isl_basic_set *bset)
883 return (struct isl_basic_set *)
884 isl_basic_map_affine_hull((struct isl_basic_map *)bset);
887 struct isl_basic_map *isl_map_affine_hull(struct isl_map *map)
890 struct isl_basic_map *model = NULL;
891 struct isl_basic_map *hull = NULL;
898 hull = isl_basic_map_empty_like_map(map);
903 map = isl_map_detect_equalities(map);
904 map = isl_map_align_divs(map);
907 model = isl_basic_map_copy(map->p[0]);
908 set = isl_map_underlying_set(map);
909 set = isl_set_cow(set);
913 for (i = 0; i < set->n; ++i) {
914 set->p[i] = isl_basic_set_cow(set->p[i]);
915 set->p[i] = isl_basic_set_affine_hull(set->p[i]);
916 set->p[i] = isl_basic_set_gauss(set->p[i], NULL);
920 set = isl_set_remove_empty_parts(set);
922 hull = isl_basic_map_empty_like(model);
923 isl_basic_map_free(model);
925 struct isl_basic_set *bset;
927 set->p[0] = affine_hull(set->p[0], set->p[--set->n]);
931 bset = isl_basic_set_copy(set->p[0]);
932 hull = isl_basic_map_overlying_set(bset, model);
935 hull = isl_basic_map_simplify(hull);
936 return isl_basic_map_finalize(hull);
938 isl_basic_map_free(model);
943 struct isl_basic_set *isl_set_affine_hull(struct isl_set *set)
945 return (struct isl_basic_set *)
946 isl_map_affine_hull((struct isl_map *)set);