return bmap;
tab = isl_tab_from_basic_map(bmap);
- tab = isl_tab_detect_implicit_equalities(tab);
+ if (isl_tab_detect_implicit_equalities(tab) < 0)
+ goto error;
if (isl_tab_detect_redundant(tab) < 0)
goto error;
bmap = isl_basic_map_update_from_tab(bmap, tab);
int i;
unsigned dim;
+ if (!bset)
+ return NULL;
+
if (ISL_F_ISSET(bset, ISL_BASIC_SET_EMPTY))
return bset;
isl_int *facet, isl_int *ridge)
{
int i;
+ isl_ctx *ctx;
struct isl_mat *T = NULL;
struct isl_basic_set *lp = NULL;
struct isl_vec *obj;
isl_int num, den;
unsigned dim;
+ if (!set)
+ return NULL;
+ ctx = set->ctx;
set = isl_set_copy(set);
set = isl_set_set_rational(set);
dim = 1 + isl_set_n_dim(set);
- T = isl_mat_alloc(set->ctx, 3, dim);
+ T = isl_mat_alloc(ctx, 3, dim);
if (!T)
goto error;
isl_int_set_si(T->row[0][0], 1);
if (!set)
goto error;
lp = wrap_constraints(set);
- obj = isl_vec_alloc(set->ctx, 1 + dim*set->n);
+ obj = isl_vec_alloc(ctx, 1 + dim*set->n);
if (!obj)
goto error;
isl_int_set_si(obj->block.data[0], 0);
isl_int_init(num);
isl_int_init(den);
res = isl_basic_set_solve_lp(lp, 0,
- obj->block.data, set->ctx->one, &num, &den, NULL);
+ obj->block.data, ctx->one, &num, &den, NULL);
if (res == isl_lp_ok) {
isl_int_neg(num, num);
isl_seq_combine(facet, num, facet, den, ridge, dim);
isl_vec_free(obj);
isl_basic_set_free(lp);
isl_set_free(set);
- isl_assert(set->ctx, res == isl_lp_ok || res == isl_lp_unbounded,
+ if (res == isl_lp_error)
+ return NULL;
+ isl_assert(ctx, res == isl_lp_ok || res == isl_lp_unbounded,
return NULL);
return facet;
error:
{
struct isl_set *slice = NULL;
struct isl_basic_set *face = NULL;
- struct isl_mat *m, *U, *Q;
int i;
unsigned dim = isl_set_n_dim(set);
int is_bound;
set = isl_set_preimage(set, U);
facet = uset_convex_hull_wrap_bounded(set);
facet = isl_basic_set_preimage(facet, Q);
- isl_assert(ctx, facet->n_eq == 0, goto error);
+ if (facet)
+ isl_assert(ctx, facet->n_eq == 0, goto error);
return facet;
error:
isl_basic_set_free(facet);
return NULL;
}
-static int isl_basic_set_is_bounded(struct isl_basic_set *bset)
+/* Is the set bounded for each value of the parameters?
+ */
+int isl_basic_set_is_bounded(__isl_keep isl_basic_set *bset)
{
struct isl_tab *tab;
int bounded;
- tab = isl_tab_from_recession_cone(bset);
+ if (!bset)
+ return -1;
+ if (isl_basic_set_fast_is_empty(bset))
+ return 1;
+
+ tab = isl_tab_from_recession_cone(bset, 1);
bounded = isl_tab_cone_is_bounded(tab);
isl_tab_free(tab);
return bounded;
}
-static int isl_set_is_bounded(struct isl_set *set)
+/* Is the set bounded for each value of the parameters?
+ */
+int isl_set_is_bounded(__isl_keep isl_set *set)
{
int i;
+ if (!set)
+ return -1;
+
for (i = 0; i < set->n; ++i) {
int bounded = isl_basic_set_is_bounded(set->p[i]);
if (!bounded || bounded < 0)
return NULL;
}
+static struct isl_basic_set *uset_convex_hull_wrap(struct isl_set *set);
+static struct isl_basic_set *modulo_affine_hull(
+ struct isl_set *set, struct isl_basic_set *affine_hull);
+
/* Compute the convex hull of a pair of basic sets without any parameters or
* integer divisions.
*
+ * This function is called from uset_convex_hull_unbounded, which
+ * means that the complete convex hull is unbounded. Some pairs
+ * of basic sets may still be bounded, though.
+ * They may even lie inside a lower dimensional space, in which
+ * case they need to be handled inside their affine hull since
+ * the main algorithm assumes that the result is full-dimensional.
+ *
* If the convex hull of the two basic sets would have a non-trivial
* lineality space, we first project out this lineality space.
*/
static struct isl_basic_set *convex_hull_pair(struct isl_basic_set *bset1,
struct isl_basic_set *bset2)
{
- struct isl_basic_set *lin;
+ isl_basic_set *lin, *aff;
+ int bounded1, bounded2;
+
+ aff = isl_set_affine_hull(isl_basic_set_union(isl_basic_set_copy(bset1),
+ isl_basic_set_copy(bset2)));
+ if (!aff)
+ goto error;
+ if (aff->n_eq != 0)
+ return modulo_affine_hull(isl_basic_set_union(bset1, bset2), aff);
+ isl_basic_set_free(aff);
+
+ bounded1 = isl_basic_set_is_bounded(bset1);
+ bounded2 = isl_basic_set_is_bounded(bset2);
+
+ if (bounded1 < 0 || bounded2 < 0)
+ goto error;
- if (isl_basic_set_is_bounded(bset1) || isl_basic_set_is_bounded(bset2))
+ if (bounded1 && bounded2)
+ uset_convex_hull_wrap(isl_basic_set_union(bset1, bset2));
+
+ if (bounded1 || bounded2)
return convex_hull_pair_pointed(bset1, bset2);
lin = induced_lineality_space(isl_basic_set_copy(bset1),
{
struct isl_basic_set *convex_hull = NULL;
+ if (!set)
+ goto error;
+
if (isl_set_n_dim(set) == 0) {
convex_hull = isl_basic_set_universe(isl_dim_copy(set->dim));
isl_set_free(set);
}
set = isl_set_set_rational(set);
-
- if (!set)
- goto error;
set = isl_set_coalesce(set);
if (!set)
goto error;
* convex hull of the transformed set and then add the equalities back
* (after performing the inverse transformation.
*/
-static struct isl_basic_set *modulo_affine_hull(struct isl_ctx *ctx,
+static struct isl_basic_set *modulo_affine_hull(
struct isl_set *set, struct isl_basic_set *affine_hull)
{
struct isl_mat *T;
if (!affine_hull)
goto error;
if (affine_hull->n_eq != 0)
- bset = modulo_affine_hull(ctx, set, affine_hull);
+ bset = modulo_affine_hull(set, affine_hull);
else {
isl_basic_set_free(affine_hull);
bset = uset_convex_hull(set);
}
convex_hull = isl_basic_map_overlying_set(bset, model);
+ if (!convex_hull)
+ return NULL;
ISL_F_SET(convex_hull, ISL_BASIC_MAP_NO_IMPLICIT);
ISL_F_SET(convex_hull, ISL_BASIC_MAP_ALL_EQUALITIES);
isl_int_clear(opt);
- return res == isl_lp_ok ? 1 :
+ return (res == isl_lp_ok || res == isl_lp_empty) ? 1 :
res == isl_lp_unbounded ? 0 : -1;
}
for (j = 0; j < set->p[i]->n_eq; ++j) {
for (k = 0; k < 2; ++k) {
isl_seq_neg(set->p[i]->eq[j], set->p[i]->eq[j], 1+dim);
- add_bound(bset, data, set, i, set->p[i]->eq[j]);
+ bset = add_bound(bset, data, set, i, set->p[i]->eq[j]);
}
}
for (j = 0; j < set->p[i]->n_ineq; ++j)
- add_bound(bset, data, set, i, set->p[i]->ineq[j]);
+ bset = add_bound(bset, data, set, i, set->p[i]->ineq[j]);
return bset;
}