bmap->dim->nparam == bset->dim->nparam;
}
+struct isl_dim *isl_basic_set_get_dim(struct isl_basic_set *bset)
+{
+ if (!bset)
+ return NULL;
+ return isl_dim_copy(bset->dim);
+}
+
+struct isl_dim *isl_set_get_dim(struct isl_set *set)
+{
+ if (!set)
+ return NULL;
+ return isl_dim_copy(set->dim);
+}
+
static struct isl_basic_map *basic_map_init(struct isl_ctx *ctx,
struct isl_basic_map *bmap, unsigned extra,
unsigned n_eq, unsigned n_ineq)
bmap->n_div, bmap->n_eq, bmap->n_ineq);
if (!dup)
return NULL;
- dup->flags = bmap->flags;
dup_constraints(dup, bmap);
- dup->sample = isl_vec_copy(bmap->ctx, bmap->sample);
+ dup->flags = bmap->flags;
+ dup->sample = isl_vec_copy(bmap->sample);
return dup;
}
isl_blk_free(bmap->ctx, bmap->block2);
free(bmap->ineq);
isl_blk_free(bmap->ctx, bmap->block);
- isl_vec_free(bmap->ctx, bmap->sample);
+ isl_vec_free(bmap->sample);
isl_dim_free(bmap->dim);
free(bmap);
}
isl_basic_map_free((struct isl_basic_map *)bset);
}
+static int room_for_con(struct isl_basic_map *bmap, unsigned n)
+{
+ return bmap->n_eq + bmap->n_ineq + n <= bmap->c_size;
+}
+
int isl_basic_map_alloc_equality(struct isl_basic_map *bmap)
{
struct isl_ctx *ctx;
if (!bmap)
return -1;
ctx = bmap->ctx;
- isl_assert(ctx, bmap->n_eq + bmap->n_ineq < bmap->c_size, return -1);
+ isl_assert(ctx, room_for_con(bmap, 1), return -1);
isl_assert(ctx, (bmap->eq - bmap->ineq) + bmap->n_eq <= bmap->c_size,
return -1);
+ ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED);
+ ISL_F_CLR(bmap, ISL_BASIC_MAP_NO_REDUNDANT);
+ ISL_F_CLR(bmap, ISL_BASIC_MAP_NO_IMPLICIT);
+ ISL_F_CLR(bmap, ISL_BASIC_MAP_ALL_EQUALITIES);
ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED_DIVS);
if ((bmap->eq - bmap->ineq) + bmap->n_eq == bmap->c_size) {
isl_int *t;
return 0;
}
+int isl_basic_set_free_equality(struct isl_basic_set *bset, unsigned n)
+{
+ return isl_basic_map_free_equality((struct isl_basic_map *)bset, n);
+}
+
int isl_basic_map_drop_equality(struct isl_basic_map *bmap, unsigned pos)
{
isl_int *t;
bmap->n_eq++;
bmap->n_ineq--;
bmap->eq--;
+ ISL_F_CLR(bmap, ISL_BASIC_MAP_NO_REDUNDANT);
ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED);
ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED_DIVS);
ISL_F_CLR(bmap, ISL_BASIC_MAP_ALL_EQUALITIES);
}
+static int room_for_ineq(struct isl_basic_map *bmap, unsigned n)
+{
+ return bmap->n_ineq + n <= bmap->eq - bmap->ineq;
+}
+
int isl_basic_map_alloc_inequality(struct isl_basic_map *bmap)
{
struct isl_ctx *ctx;
if (!bmap)
return -1;
ctx = bmap->ctx;
- isl_assert(ctx, bmap->n_ineq < bmap->eq - bmap->ineq, return -1);
+ isl_assert(ctx, room_for_ineq(bmap, 1), return -1);
ISL_F_CLR(bmap, ISL_BASIC_MAP_NO_IMPLICIT);
ISL_F_CLR(bmap, ISL_BASIC_MAP_NO_REDUNDANT);
ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED);
return bmap->n_div++;
}
+int isl_basic_set_alloc_div(struct isl_basic_set *bset)
+{
+ return isl_basic_map_alloc_div((struct isl_basic_map *)bset);
+}
+
int isl_basic_map_free_div(struct isl_basic_map *bmap, unsigned n)
{
if (!bmap)
if (!dim)
goto error;
- base = isl_basic_map_cow(base);
if (!base)
goto error;
dims_ok = isl_dim_equal(base->dim, dim) &&
base->extra >= base->n_div + extra;
- if (dims_ok && n_eq == 0 && n_ineq == 0) {
+ if (dims_ok && room_for_con(base, n_eq + n_ineq) &&
+ room_for_ineq(base, n_ineq)) {
isl_dim_free(dim);
return base;
}
isl_assert(bset->ctx,
isl_basic_map_compatible_domain(bmap, bset), goto error);
+ bmap = isl_basic_map_cow(bmap);
bmap = isl_basic_map_extend_dim(bmap, isl_dim_copy(bmap->dim),
bset->n_div, bset->n_eq, bset->n_ineq);
if (!bmap)
isl_assert(bset->ctx,
isl_basic_map_compatible_range(bmap, bset), goto error);
+ bmap = isl_basic_map_cow(bmap);
bmap = isl_basic_map_extend_dim(bmap, isl_dim_copy(bmap->dim),
bset->n_div, bset->n_eq, bset->n_ineq);
if (!bmap)
isl_int_init(s);
for (i = 0; i < bmap->n_eq; ++i) {
- isl_seq_inner_product(vec->block.data, bmap->eq[i], total, &s);
+ isl_seq_inner_product(vec->el, bmap->eq[i], total, &s);
if (!isl_int_is_zero(s)) {
isl_int_clear(s);
return 0;
}
for (i = 0; i < bmap->n_ineq; ++i) {
- isl_seq_inner_product(vec->block.data, bmap->ineq[i], total, &s);
+ isl_seq_inner_product(vec->el, bmap->ineq[i], total, &s);
if (isl_int_is_neg(s)) {
isl_int_clear(s);
return 0;
return 1;
}
+int isl_basic_set_contains(struct isl_basic_set *bset, struct isl_vec *vec)
+{
+ return basic_map_contains((struct isl_basic_map *)bset, vec);
+}
+
struct isl_basic_map *isl_basic_map_intersect(
struct isl_basic_map *bmap1, struct isl_basic_map *bmap2)
{
if (bmap1->sample &&
basic_map_contains(bmap1, bmap1->sample) > 0 &&
basic_map_contains(bmap2, bmap1->sample) > 0)
- sample = isl_vec_copy(bmap1->ctx, bmap1->sample);
+ sample = isl_vec_copy(bmap1->sample);
else if (bmap2->sample &&
basic_map_contains(bmap1, bmap2->sample) > 0 &&
basic_map_contains(bmap2, bmap2->sample) > 0)
- sample = isl_vec_copy(bmap2->ctx, bmap2->sample);
+ sample = isl_vec_copy(bmap2->sample);
+ bmap1 = isl_basic_map_cow(bmap1);
bmap1 = isl_basic_map_extend_dim(bmap1, isl_dim_copy(bmap1->dim),
bmap2->n_div, bmap2->n_eq, bmap2->n_ineq);
if (!bmap1)
bmap1 = add_constraints(bmap1, bmap2, 0, 0);
if (sample) {
- isl_vec_free(bmap1->ctx, bmap1->sample);
+ isl_vec_free(bmap1->sample);
bmap1->sample = sample;
}
return isl_basic_map_finalize(bmap1);
error:
if (sample)
- isl_vec_free(bmap1->ctx, sample);
+ isl_vec_free(sample);
isl_basic_map_free(bmap1);
isl_basic_map_free(bmap2);
return NULL;
return NULL;
}
-struct isl_basic_map *add_divs(struct isl_basic_map *bmap, unsigned n)
+static struct isl_basic_map *add_divs(struct isl_basic_map *bmap, unsigned n)
{
int i, j;
return isl_set_empty(isl_dim_copy(model->dim));
}
+struct isl_map *isl_map_universe(struct isl_dim *dim)
+{
+ struct isl_map *map;
+ if (!dim)
+ return NULL;
+ map = isl_map_alloc_dim(isl_dim_copy(dim), 1, ISL_MAP_DISJOINT);
+ map = isl_map_add(map, isl_basic_map_universe(dim));
+ return map;
+}
+
struct isl_set *isl_set_universe(struct isl_dim *dim)
{
struct isl_set *set;
return NULL;
}
+/* If bmap contains any unknown divs, then compute explicit
+ * expressions for them. However, this computation may be
+ * quite expensive, so first try to remove divs that aren't
+ * strictly needed.
+ */
struct isl_map *isl_basic_map_compute_divs(struct isl_basic_map *bmap)
{
int i;
off = isl_dim_total(bmap->dim);
for (i = 0; i < bmap->n_div; ++i) {
if (isl_int_is_zero(bmap->div[i][0]))
- return isl_pip_basic_map_compute_divs(bmap);
+ break;
isl_assert(bmap->ctx, isl_int_is_zero(bmap->div[i][1+1+off+i]),
goto error);
}
- return isl_map_from_basic_map(bmap);
+ if (i == bmap->n_div)
+ return isl_map_from_basic_map(bmap);
+ bmap = isl_basic_map_drop_redundant_divs(bmap);
+ if (!bmap)
+ goto error;
+ for (i = 0; i < bmap->n_div; ++i)
+ if (isl_int_is_zero(bmap->div[i][0]))
+ break;
+ if (i == bmap->n_div)
+ return isl_map_from_basic_map(bmap);
+ struct isl_map *map = isl_pip_basic_map_compute_divs(bmap);
+ return map;
error:
isl_basic_map_free(bmap);
return NULL;
nparam = isl_basic_map_n_param(bmap);
isl_assert(bmap->ctx, dim == isl_basic_map_n_out(bmap), goto error);
bset = isl_basic_set_from_basic_map(bmap);
+ bset = isl_basic_set_cow(bset);
bset = isl_basic_set_extend(bset, nparam, 3*dim, 0, dim, 0);
bset = isl_basic_set_swap_vars(bset, 2*dim);
for (i = 0; i < dim; ++i) {
return bmap->n_eq == 0 && bmap->n_ineq == 0;
}
+int isl_basic_set_is_universe(struct isl_basic_set *bset)
+{
+ if (!bset)
+ return -1;
+ return bset->n_eq == 0 && bset->n_ineq == 0;
+}
+
int isl_basic_map_is_empty(struct isl_basic_map *bmap)
{
struct isl_basic_set *bset = NULL;
if (contains)
return 0;
}
+ isl_vec_free(bmap->sample);
+ bmap->sample = NULL;
bset = isl_basic_map_underlying_set(isl_basic_map_copy(bmap));
if (!bset)
return -1;
if (!sample)
return -1;
empty = sample->size == 0;
- if (bmap->sample)
- isl_vec_free(bmap->ctx, bmap->sample);
+ isl_vec_free(bmap->sample);
bmap->sample = sample;
+ if (empty)
+ ISL_F_SET(bmap, ISL_BASIC_MAP_EMPTY);
return empty;
}
+int isl_basic_map_fast_is_empty(struct isl_basic_map *bmap)
+{
+ if (!bmap)
+ return -1;
+ return ISL_F_ISSET(bmap, ISL_BASIC_MAP_EMPTY);
+}
+
+int isl_basic_set_fast_is_empty(struct isl_basic_set *bset)
+{
+ if (!bset)
+ return -1;
+ return ISL_F_ISSET(bset, ISL_BASIC_SET_EMPTY);
+}
+
int isl_basic_set_is_empty(struct isl_basic_set *bset)
{
return isl_basic_map_is_empty((struct isl_basic_map *)bset);
bmap->n_div-i);
if (pos == -1)
continue;
- swap_div(bmap, i, pos);
+ swap_div(bmap, i, i + pos);
--i;
}
return bmap;
isl_assert(src->ctx, !isl_int_is_zero(src->div[i][0]), goto error);
src = order_divs(src);
+ dst = isl_basic_map_cow(dst);
dst = isl_basic_map_extend_dim(dst, isl_dim_copy(dst->dim),
src->n_div, 0, 2 * src->n_div);
if (!dst)
return map;
}
+struct isl_set *isl_set_align_divs(struct isl_set *set)
+{
+ return (struct isl_set *)isl_map_align_divs((struct isl_map *)set);
+}
+
static struct isl_map *add_cut_constraint(struct isl_map *dst,
struct isl_basic_map *src, isl_int *c,
unsigned len, int oppose)
bmap2 = isl_basic_map_from_basic_set(isl_basic_set_copy(bset2), dims);
if (!bmap1 || !bmap2)
goto error;
+ bmap1 = isl_basic_map_cow(bmap1);
bmap1 = isl_basic_map_extend(bmap1, nparam,
pos, (dim1 - pos) + (dim2 - pos),
bmap2->n_div, bmap2->n_eq, bmap2->n_ineq);
isl_int_clear(num);
isl_int_clear(den);
isl_basic_map_free(bmap1);
- isl_vec_free(ctx, obj);
+ isl_vec_free(obj);
return cmp;
error:
isl_basic_map_free(bmap1);
return NULL;
}
+/* Given two set A and B, construct its Cartesian product A x B.
+ */
+struct isl_set *isl_set_product(struct isl_set *set1, struct isl_set *set2)
+{
+ return (struct isl_set *)isl_map_product((struct isl_map *)set1,
+ (struct isl_map *)set2);
+}
+
uint32_t isl_basic_set_get_hash(struct isl_basic_set *bset)
{
int i;