return isl_basic_map_drop_equality((struct isl_basic_map *)bset, pos);
}
+/* Turn inequality "pos" of "bmap" into an equality.
+ *
+ * In particular, we move the inequality in front of the equalities
+ * and move the last inequality in the position of the moved inequality.
+ * Note that isl_tab_make_equalities_explicit depends on this particular
+ * change in the ordering of the constraints.
+ */
void isl_basic_map_inequality_to_equality(
struct isl_basic_map *bmap, unsigned pos)
{
unsigned dim;
unsigned nparam;
+ if (!bset)
+ return NULL;
+
nparam = isl_basic_set_n_param(bset);
dim = isl_basic_set_n_dim(bset);
isl_assert(bset->ctx, n <= dim, goto error);
__isl_take isl_map *map2)
{
unsigned flags = 0;
- struct isl_map *result;
+ isl_map *result;
int i, j;
if (!map1 || !map2)
isl_basic_map_copy(map1->p[i]),
isl_basic_map_copy(map2->p[j]));
if (isl_basic_map_is_empty(part) < 0)
- goto error;
+ part = isl_basic_map_free(part);
result = isl_map_add_basic_map(result, part);
if (!result)
goto error;
{
isl_space *space;
+ if (!bmap)
+ return NULL;
if (!isl_space_is_named_or_nested(bmap->dim, type))
return bmap;
res = isl_basic_map_set_rational(res);
if (isl_basic_map_plain_is_empty(bmap)) {
isl_basic_map_free(bmap);
+ free(dim_map);
return isl_basic_map_set_to_empty(res);
}
res = isl_basic_map_add_constraints_dim_map(res, bmap, dim_map);
isl_basic_map_dim(bmap, type), n);
}
-__isl_give isl_basic_set *isl_basic_set_add(__isl_take isl_basic_set *bset,
+__isl_give isl_basic_set *isl_basic_set_add_dims(__isl_take isl_basic_set *bset,
enum isl_dim_type type, unsigned n)
{
if (!bset)
res = isl_basic_map_alloc_space(isl_basic_map_get_space(bmap),
bmap->n_div, bmap->n_eq, bmap->n_ineq);
bmap = isl_basic_map_add_constraints_dim_map(res, bmap, dim_map);
+ if (!bmap)
+ goto error;
bmap->dim = isl_space_move_dims(bmap->dim, dst_type, dst_pos,
src_type, src_pos, n);
bmap = isl_basic_map_finalize(bmap);
return (struct isl_basic_set *)bmap;
error:
+ isl_basic_map_free(bmap);
return NULL;
}
bmap = isl_basic_map_extend_constraints(bmap,
0, 2 * like->n_div);
for (i = 0; i < like->n_div; ++i) {
+ if (!bmap)
+ break;
if (isl_int_is_zero(bmap->div[i][0]))
continue;
if (isl_basic_map_add_div_constraints(bmap, i) < 0)
- goto error;
+ bmap = isl_basic_map_free(bmap);
}
}
isl_basic_map_free(like);
return bset;
}
+/* Construct a zero-dimensional basic set with the given parameter domain.
+ */
+__isl_give isl_basic_set *isl_basic_set_from_params(
+ __isl_take isl_basic_set *bset)
+{
+ isl_space *space;
+ space = isl_basic_set_get_space(bset);
+ space = isl_space_set_from_params(space);
+ bset = isl_basic_set_reset_space(bset, space);
+ return bset;
+}
+
/* Compute the parameter domain of the given set.
*/
__isl_give isl_set *isl_set_params(__isl_take isl_set *set)
isl_pw_aff **pwaff = user;
isl_pw_aff *pwaff_i;
+ if (!list)
+ goto error;
if (isl_aff_list_n_aff(list) != 1)
isl_die(ctx, isl_error_internal,
"expecting single element list", goto error);
if (bset->n_eq == 0)
return isl_basic_set_lexmin(bset);
- isl_basic_set_gauss(bset, NULL);
+ bset = isl_basic_set_gauss(bset, NULL);
+ if (!bset)
+ return NULL;
+ if (isl_basic_set_plain_is_empty(bset))
+ return isl_set_from_basic_set(bset);
nparam = isl_basic_set_dim(bset, isl_dim_param);
n_div = isl_basic_set_dim(bset, isl_dim_div);
for (i = 0; i < dim; ++i) {
int j = isl_basic_map_alloc_equality(
(struct isl_basic_map *)bset);
- if (j < 0)
- goto error;
+ if (j < 0) {
+ bset = isl_basic_set_free(bset);
+ break;
+ }
isl_seq_clr(bset->eq[j], 1 + isl_basic_set_total_dim(bset));
isl_int_set_si(bset->eq[j][1+nparam+i], 1);
isl_int_set_si(bset->eq[j][1+nparam+dim+i], 1);
if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL)) {
struct isl_basic_map *copy = isl_basic_map_copy(bmap);
copy = isl_basic_map_remove_redundancies(copy);
- empty = ISL_F_ISSET(copy, ISL_BASIC_MAP_EMPTY);
+ empty = isl_basic_map_plain_is_empty(copy);
isl_basic_map_free(copy);
return empty;
}
isl_die(isl_mat_get_ctx(div), isl_error_invalid,
"not an expansion", goto error);
+ n_div = bset->n_div;
bset = isl_basic_map_extend_space(bset, isl_space_copy(bset->dim),
- div->n_row - bset->n_div, 0,
- 2 * (div->n_row - bset->n_div));
+ div->n_row - n_div, 0,
+ 2 * (div->n_row - n_div));
- n_div = bset->n_div;
for (i = n_div; i < div->n_row; ++i)
if (isl_basic_set_alloc_div(bset) < 0)
goto error;
total = isl_basic_map_total_dim(bmap1);
ctx = bmap1->ctx;
obj = isl_vec_alloc(ctx, 1 + total);
+ if (!obj)
+ goto error2;
isl_seq_clr(obj->block.data, 1 + total);
isl_int_set_si(obj->block.data[1+nparam+pos], 1);
isl_int_set_si(obj->block.data[1+nparam+pos+(dim1-pos)], -1);
- if (!obj)
- goto error;
res = isl_basic_map_solve_lp(bmap1, 1, obj->block.data, ctx->one,
opt, NULL, NULL);
isl_basic_map_free(bmap1);
isl_vec_free(obj);
return res;
error:
- isl_basic_map_free(bmap1);
isl_basic_map_free(bmap2);
+error2:
+ isl_basic_map_free(bmap1);
return isl_lp_error;
}
int l1, l2;
unsigned size = isl_min(c1->size, c2->size);
- l1 = isl_seq_last_non_zero(c1->c, size);
- l2 = isl_seq_last_non_zero(c2->c, size);
+ l1 = isl_seq_last_non_zero(c1->c + 1, size);
+ l2 = isl_seq_last_non_zero(c2->c + 1, size);
if (l1 != l2)
return l1 - l2;
- return isl_seq_cmp(c1->c, c2->c, size);
+ return isl_seq_cmp(c1->c + 1, c2->c + 1, size);
}
static struct isl_basic_map *isl_basic_map_sort_constraints(
return bmap;
bmap = isl_basic_map_remove_redundancies(bmap);
bmap = isl_basic_map_sort_constraints(bmap);
- ISL_F_SET(bmap, ISL_BASIC_MAP_NORMALIZED);
+ if (bmap)
+ ISL_F_SET(bmap, ISL_BASIC_MAP_NORMALIZED);
return bmap;
}
return isl_map_dim_is_bounded((isl_map *)set, type, pos);
}
+/* Does "map" have a bound (according to "fn") for any of its basic maps?
+ */
static int has_any_bound(__isl_keep isl_map *map,
enum isl_dim_type type, unsigned pos,
int (*fn)(__isl_keep isl_basic_map *bmap,
&isl_basic_map_dim_has_upper_bound);
}
+/* Does "map" have a bound (according to "fn") for all of its basic maps?
+ */
+static int has_bound(__isl_keep isl_map *map,
+ enum isl_dim_type type, unsigned pos,
+ int (*fn)(__isl_keep isl_basic_map *bmap,
+ enum isl_dim_type type, unsigned pos))
+{
+ int i;
+
+ if (!map)
+ return -1;
+
+ for (i = 0; i < map->n; ++i) {
+ int bounded;
+ bounded = fn(map->p[i], type, pos);
+ if (bounded < 0 || !bounded)
+ return bounded;
+ }
+
+ return 1;
+}
+
+/* Return 1 if the specified dim has a lower bound (in each of its basic sets).
+ */
+int isl_set_dim_has_lower_bound(__isl_keep isl_set *set,
+ enum isl_dim_type type, unsigned pos)
+{
+ return has_bound(set, type, pos, &isl_basic_map_dim_has_lower_bound);
+}
+
+/* Return 1 if the specified dim has an upper bound (in each of its basic sets).
+ */
+int isl_set_dim_has_upper_bound(__isl_keep isl_set *set,
+ enum isl_dim_type type, unsigned pos)
+{
+ return has_bound(set, type, pos, &isl_basic_map_dim_has_upper_bound);
+}
+
/* For each of the "n" variables starting at "first", determine
* the sign of the variable and put the results in the first "n"
* elements of the array "signs".
if (!isl_basic_map_can_curry(bmap))
isl_die(bmap->ctx, isl_error_invalid,
"basic map cannot be curried", goto error);
+ bmap = isl_basic_map_cow(bmap);
+ if (!bmap)
+ return NULL;
bmap->dim = isl_space_curry(bmap->dim);
if (!bmap->dim)
goto error;
isl_die(bmap->ctx, isl_error_invalid,
"basic map cannot be uncurried",
return isl_basic_map_free(bmap));
+ bmap = isl_basic_map_cow(bmap);
+ if (!bmap)
+ return NULL;
bmap->dim = isl_space_uncurry(bmap->dim);
if (!bmap->dim)
return isl_basic_map_free(bmap);
* are replaced by
*
* a f + d g
+ *
+ * We currently require that "subs" is an integral expression.
+ * Handling rational expressions may require us to add stride constraints
+ * as we do in isl_basic_set_preimage_multi_aff.
*/
__isl_give isl_basic_set *isl_basic_set_substitute(
__isl_take isl_basic_set *bset,
if (isl_local_space_dim(subs->ls, isl_dim_div) != 0)
isl_die(ctx, isl_error_unsupported,
"cannot handle divs yet", goto error);
+ if (!isl_int_is_one(subs->v->el[0]))
+ isl_die(ctx, isl_error_invalid,
+ "can only substitute integer expressions", goto error);
pos += isl_basic_set_offset(bset, type);