* ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
*/
-#include <isl_constraint.h>
-#include <isl_dim_private.h>
-#include "isl_seq.h"
-#include "isl_map_private.h"
+#include <isl_map_private.h>
+#include <isl_constraint_private.h>
+#include <isl_space_private.h>
+#include <isl/seq.h>
+#include <isl_aff_private.h>
+#include <isl_local_space_private.h>
+
+isl_ctx *isl_constraint_get_ctx(__isl_keep isl_constraint *c)
+{
+ return c ? isl_local_space_get_ctx(c->ls) : NULL;
+}
static unsigned n(struct isl_constraint *c, enum isl_dim_type type)
{
- return isl_basic_map_dim(c->bmap, type);
+ return isl_local_space_dim(c->ls, type);
}
static unsigned offset(struct isl_constraint *c, enum isl_dim_type type)
{
- struct isl_dim *dim = c->bmap->dim;
- switch (type) {
- case isl_dim_param: return 1;
- case isl_dim_in: return 1 + dim->nparam;
- case isl_dim_out: return 1 + dim->nparam + dim->n_in;
- case isl_dim_div: return 1 + dim->nparam + dim->n_in + dim->n_out;
- default: return 0;
- }
+ return isl_local_space_offset(c->ls, type);
}
static unsigned basic_map_offset(__isl_keep isl_basic_map *bmap,
enum isl_dim_type type)
{
- return type == isl_dim_div ? 1 + isl_dim_total(bmap->dim)
- : 1 + isl_dim_offset(bmap->dim, type);
+ return type == isl_dim_div ? 1 + isl_space_dim(bmap->dim, isl_dim_all)
+ : 1 + isl_space_offset(bmap->dim, type);
}
static unsigned basic_set_offset(struct isl_basic_set *bset,
enum isl_dim_type type)
{
- struct isl_dim *dim = bset->dim;
+ isl_space *dim = bset->dim;
switch (type) {
case isl_dim_param: return 1;
case isl_dim_in: return 1 + dim->nparam;
}
}
-struct isl_constraint *isl_basic_map_constraint(struct isl_basic_map *bmap,
- isl_int **line)
+__isl_give isl_constraint *isl_constraint_alloc_vec(int eq,
+ __isl_take isl_local_space *ls, __isl_take isl_vec *v)
{
- struct isl_constraint *constraint;
+ isl_constraint *constraint;
- if (!bmap || !line)
+ if (!ls || !v)
goto error;
-
- constraint = isl_alloc_type(bmap->ctx, struct isl_constraint);
+
+ constraint = isl_alloc_type(isl_vec_get_ctx(v), isl_constraint);
if (!constraint)
goto error;
- constraint->ctx = bmap->ctx;
- isl_ctx_ref(constraint->ctx);
constraint->ref = 1;
- constraint->bmap = bmap;
- constraint->line = line;
+ constraint->eq = eq;
+ constraint->ls = ls;
+ constraint->v = v;
return constraint;
error:
- isl_basic_map_free(bmap);
+ isl_local_space_free(ls);
+ isl_vec_free(v);
return NULL;
}
-struct isl_constraint *isl_basic_set_constraint(struct isl_basic_set *bset,
- isl_int **line)
+__isl_give isl_constraint *isl_constraint_alloc(int eq,
+ __isl_take isl_local_space *ls)
{
- return isl_basic_map_constraint((struct isl_basic_map *)bset, line);
+ isl_ctx *ctx;
+ isl_vec *v;
+
+ if (!ls)
+ return NULL;
+
+ ctx = isl_local_space_get_ctx(ls);
+ v = isl_vec_alloc(ctx, 1 + isl_local_space_dim(ls, isl_dim_all));
+ v = isl_vec_clr(v);
+ return isl_constraint_alloc_vec(eq, ls, v);
}
-struct isl_constraint *isl_equality_alloc(struct isl_dim *dim)
+struct isl_constraint *isl_basic_map_constraint(struct isl_basic_map *bmap,
+ isl_int **line)
{
- struct isl_basic_map *bmap;
+ int eq;
+ isl_ctx *ctx;
+ isl_vec *v;
+ isl_local_space *ls = NULL;
+ isl_constraint *constraint;
- if (!dim)
- return NULL;
+ if (!bmap || !line)
+ goto error;
- bmap = isl_basic_map_alloc_dim(dim, 0, 1, 0);
- if (!bmap)
- return NULL;
+ eq = line >= bmap->eq;
+
+ ctx = isl_basic_map_get_ctx(bmap);
+ ls = isl_basic_map_get_local_space(bmap);
+ v = isl_vec_alloc(ctx, 1 + isl_local_space_dim(ls, isl_dim_all));
+ if (!v)
+ goto error;
+ isl_seq_cpy(v->el, line[0], v->size);
+ constraint = isl_constraint_alloc_vec(eq, ls, v);
- isl_basic_map_alloc_equality(bmap);
- isl_seq_clr(bmap->eq[0], 1 + isl_basic_map_total_dim(bmap));
- return isl_basic_map_constraint(bmap, &bmap->eq[0]);
+ isl_basic_map_free(bmap);
+ return constraint;
+error:
+ isl_local_space_free(ls);
+ isl_basic_map_free(bmap);
+ return NULL;
}
-struct isl_constraint *isl_inequality_alloc(struct isl_dim *dim)
+struct isl_constraint *isl_basic_set_constraint(struct isl_basic_set *bset,
+ isl_int **line)
{
- struct isl_basic_map *bmap;
-
- if (!dim)
- return NULL;
+ return isl_basic_map_constraint((struct isl_basic_map *)bset, line);
+}
- bmap = isl_basic_map_alloc_dim(dim, 0, 0, 1);
- if (!bmap)
- return NULL;
+__isl_give isl_constraint *isl_equality_alloc(__isl_take isl_local_space *ls)
+{
+ return isl_constraint_alloc(1, ls);
+}
- isl_basic_map_alloc_inequality(bmap);
- isl_seq_clr(bmap->ineq[0], 1 + isl_basic_map_total_dim(bmap));
- return isl_basic_map_constraint(bmap, &bmap->ineq[0]);
+__isl_give isl_constraint *isl_inequality_alloc(__isl_take isl_local_space *ls)
+{
+ return isl_constraint_alloc(0, ls);
}
struct isl_constraint *isl_constraint_dup(struct isl_constraint *c)
{
- struct isl_basic_map *bmap;
- int i;
- int eq;
-
if (!c)
return NULL;
- eq = c->line < c->bmap->eq + c->bmap->n_eq;
- i = eq ? c->line - c->bmap->eq : c->line - c->bmap->ineq;
- bmap = isl_basic_map_copy(c->bmap);
- if (!bmap)
- return NULL;
- return isl_basic_map_constraint(bmap, eq ? bmap->eq + i : bmap->ineq + i);
+ return isl_constraint_alloc_vec(c->eq, isl_local_space_copy(c->ls),
+ isl_vec_copy(c->v));
}
struct isl_constraint *isl_constraint_cow(struct isl_constraint *c)
return constraint;
}
-void isl_constraint_free(struct isl_constraint *c)
+void *isl_constraint_free(struct isl_constraint *c)
{
if (!c)
- return;
+ return NULL;
if (--c->ref > 0)
- return;
-
- isl_basic_map_free(c->bmap);
- isl_ctx_deref(c->ctx);
- free(c);
-}
-
-__isl_give isl_constraint *isl_basic_map_first_constraint(
- __isl_take isl_basic_map *bmap)
-{
- if (!bmap)
return NULL;
- if (bmap->n_eq > 0)
- return isl_basic_map_constraint(bmap, &bmap->eq[0]);
-
- if (bmap->n_ineq > 0)
- return isl_basic_map_constraint(bmap, &bmap->ineq[0]);
+ isl_local_space_free(c->ls);
+ isl_vec_free(c->v);
+ free(c);
- isl_basic_map_free(bmap);
return NULL;
}
-__isl_give isl_constraint *isl_basic_set_first_constraint(
- __isl_take isl_basic_set *bset)
+/* Return the number of constraints in "bset", i.e., the
+ * number of times isl_basic_set_foreach_constraint will
+ * call the callback.
+ */
+int isl_basic_set_n_constraint(__isl_keep isl_basic_set *bset)
{
- return isl_basic_map_first_constraint((struct isl_basic_map *)bset);
-}
+ if (!bset)
+ return -1;
-struct isl_constraint *isl_constraint_next(struct isl_constraint *c)
-{
- c = isl_constraint_cow(c);
- if (c->line >= c->bmap->eq) {
- c->line++;
- if (c->line < c->bmap->eq + c->bmap->n_eq)
- return c;
- c->line = c->bmap->ineq;
- } else
- c->line++;
- if (c->line < c->bmap->ineq + c->bmap->n_ineq)
- return c;
- isl_constraint_free(c);
- return NULL;
+ return bset->n_eq + bset->n_ineq;
}
int isl_basic_map_foreach_constraint(__isl_keep isl_basic_map *bmap,
int isl_constraint_is_equal(struct isl_constraint *constraint1,
struct isl_constraint *constraint2)
{
+ int equal;
+
if (!constraint1 || !constraint2)
return 0;
- return constraint1->bmap == constraint2->bmap &&
- constraint1->line == constraint2->line;
+ if (constraint1->eq != constraint2->eq)
+ return 0;
+ equal = isl_local_space_is_equal(constraint1->ls, constraint2->ls);
+ if (equal < 0 || !equal)
+ return equal;
+ return isl_vec_is_equal(constraint1->v, constraint2->v);
}
struct isl_basic_map *isl_basic_map_add_constraint(
struct isl_basic_map *bmap, struct isl_constraint *constraint)
{
+ isl_ctx *ctx;
+ isl_space *dim;
+ int equal_space;
+
if (!bmap || !constraint)
goto error;
- isl_assert(constraint->ctx,
- isl_dim_equal(bmap->dim, constraint->bmap->dim), goto error);
+ ctx = isl_constraint_get_ctx(constraint);
+ dim = isl_constraint_get_space(constraint);
+ equal_space = isl_space_is_equal(bmap->dim, dim);
+ isl_space_free(dim);
+ isl_assert(ctx, equal_space, goto error);
bmap = isl_basic_map_intersect(bmap,
isl_basic_map_from_constraint(constraint));
constraint);
}
-struct isl_constraint *isl_constraint_add_div(struct isl_constraint *constraint,
- struct isl_div *div, int *pos)
+__isl_give isl_map *isl_map_add_constraint(__isl_take isl_map *map,
+ __isl_take isl_constraint *constraint)
{
- if (!constraint || !div)
- goto error;
+ isl_basic_map *bmap;
- isl_assert(constraint->ctx,
- isl_dim_equal(div->bmap->dim, constraint->bmap->dim), goto error);
- isl_assert(constraint->ctx,
- constraint->bmap->n_eq + constraint->bmap->n_ineq == 1, goto error);
+ bmap = isl_basic_map_from_constraint(constraint);
+ map = isl_map_intersect(map, isl_map_from_basic_map(bmap));
- constraint->bmap = isl_basic_map_cow(constraint->bmap);
- constraint->bmap = isl_basic_map_extend_dim(constraint->bmap,
- isl_dim_copy(constraint->bmap->dim), 1, 0, 0);
- if (!constraint->bmap)
- goto error;
- constraint->line = &constraint->bmap->ineq[0];
- *pos = isl_basic_map_alloc_div(constraint->bmap);
- if (*pos < 0)
- goto error;
- isl_seq_cpy(constraint->bmap->div[*pos], div->line[0],
- 1 + 1 + isl_basic_map_total_dim(constraint->bmap));
- isl_div_free(div);
- return constraint;
-error:
- isl_constraint_free(constraint);
- isl_div_free(div);
- return NULL;
+ return map;
+}
+
+__isl_give isl_set *isl_set_add_constraint(__isl_take isl_set *set,
+ __isl_take isl_constraint *constraint)
+{
+ return isl_map_add_constraint(set, constraint);
+}
+
+__isl_give isl_space *isl_constraint_get_space(
+ __isl_keep isl_constraint *constraint)
+{
+ return constraint ? isl_local_space_get_space(constraint->ls) : NULL;
+}
+
+__isl_give isl_local_space *isl_constraint_get_local_space(
+ __isl_keep isl_constraint *constraint)
+{
+ return constraint ? isl_local_space_copy(constraint->ls) : NULL;
}
int isl_constraint_dim(struct isl_constraint *constraint,
return n(constraint, type);
}
+int isl_constraint_involves_dims(__isl_keep isl_constraint *constraint,
+ enum isl_dim_type type, unsigned first, unsigned n)
+{
+ int i;
+ isl_ctx *ctx;
+ int *active = NULL;
+ int involves = 0;
+
+ if (!constraint)
+ return -1;
+ if (n == 0)
+ return 0;
+
+ ctx = isl_constraint_get_ctx(constraint);
+ if (first + n > isl_constraint_dim(constraint, type))
+ isl_die(ctx, isl_error_invalid,
+ "range out of bounds", return -1);
+
+ active = isl_local_space_get_active(constraint->ls,
+ constraint->v->el + 1);
+ if (!active)
+ goto error;
+
+ first += isl_local_space_offset(constraint->ls, type) - 1;
+ for (i = 0; i < n; ++i)
+ if (active[first + i]) {
+ involves = 1;
+ break;
+ }
+
+ free(active);
+
+ return involves;
+error:
+ free(active);
+ return -1;
+}
+
+/* Does the given constraint represent a lower bound on the given
+ * dimension?
+ */
+int isl_constraint_is_lower_bound(__isl_keep isl_constraint *constraint,
+ enum isl_dim_type type, unsigned pos)
+{
+ if (!constraint)
+ return -1;
+
+ if (pos >= isl_local_space_dim(constraint->ls, type))
+ isl_die(isl_constraint_get_ctx(constraint), isl_error_invalid,
+ "position out of bounds", return -1);
+
+ pos += isl_local_space_offset(constraint->ls, type);
+ return isl_int_is_pos(constraint->v->el[pos]);
+}
+
+/* Does the given constraint represent an upper bound on the given
+ * dimension?
+ */
+int isl_constraint_is_upper_bound(__isl_keep isl_constraint *constraint,
+ enum isl_dim_type type, unsigned pos)
+{
+ if (!constraint)
+ return -1;
+
+ if (pos >= isl_local_space_dim(constraint->ls, type))
+ isl_die(isl_constraint_get_ctx(constraint), isl_error_invalid,
+ "position out of bounds", return -1);
+
+ pos += isl_local_space_offset(constraint->ls, type);
+ return isl_int_is_neg(constraint->v->el[pos]);
+}
+
const char *isl_constraint_get_dim_name(__isl_keep isl_constraint *constraint,
enum isl_dim_type type, unsigned pos)
{
return constraint ?
- isl_basic_map_get_dim_name(constraint->bmap, type, pos) : NULL;
+ isl_local_space_get_dim_name(constraint->ls, type, pos) : NULL;
}
void isl_constraint_get_constant(struct isl_constraint *constraint, isl_int *v)
{
if (!constraint)
return;
- isl_int_set(*v, constraint->line[0][0]);
+ isl_int_set(*v, constraint->v->el[0]);
}
void isl_constraint_get_coefficient(struct isl_constraint *constraint,
if (!constraint)
return;
- isl_assert(constraint->ctx, pos < n(constraint, type), return);
- isl_int_set(*v, constraint->line[0][offset(constraint, type) + pos]);
+ if (pos >= isl_local_space_dim(constraint->ls, type))
+ isl_die(constraint->v->ctx, isl_error_invalid,
+ "position out of bounds", return);
+
+ pos += isl_local_space_offset(constraint->ls, type);
+ isl_int_set(*v, constraint->v->el[pos]);
}
-struct isl_div *isl_constraint_div(struct isl_constraint *constraint, int pos)
+__isl_give isl_aff *isl_constraint_get_div(__isl_keep isl_constraint *constraint,
+ int pos)
{
if (!constraint)
return NULL;
- isl_assert(constraint->ctx, pos < n(constraint, isl_dim_div),
- return NULL);
- isl_assert(constraint->ctx,
- !isl_int_is_zero(constraint->bmap->div[pos][0]), return NULL);
- return isl_basic_map_div(isl_basic_map_copy(constraint->bmap), pos);
+ return isl_local_space_get_div(constraint->ls, pos);
}
-void isl_constraint_set_constant(struct isl_constraint *constraint, isl_int v)
+__isl_give isl_constraint *isl_constraint_set_constant(
+ __isl_take isl_constraint *constraint, isl_int v)
{
+ constraint = isl_constraint_cow(constraint);
if (!constraint)
- return;
- isl_int_set(constraint->line[0][0], v);
+ return NULL;
+
+ constraint->v = isl_vec_cow(constraint->v);
+ if (!constraint->v)
+ return isl_constraint_free(constraint);
+
+ isl_int_set(constraint->v->el[0], v);
+ return constraint;
}
-void isl_constraint_set_coefficient(struct isl_constraint *constraint,
- enum isl_dim_type type, int pos, isl_int v)
+__isl_give isl_constraint *isl_constraint_set_constant_si(
+ __isl_take isl_constraint *constraint, int v)
{
+ constraint = isl_constraint_cow(constraint);
if (!constraint)
- return;
+ return NULL;
+
+ constraint->v = isl_vec_cow(constraint->v);
+ if (!constraint->v)
+ return isl_constraint_free(constraint);
- isl_assert(constraint->ctx, pos < n(constraint, type), return);
- isl_int_set(constraint->line[0][offset(constraint, type) + pos], v);
+ isl_int_set_si(constraint->v->el[0], v);
+ return constraint;
}
-void isl_constraint_clear(struct isl_constraint *constraint)
+__isl_give isl_constraint *isl_constraint_set_coefficient(
+ __isl_take isl_constraint *constraint,
+ enum isl_dim_type type, int pos, isl_int v)
{
- unsigned total;
+ constraint = isl_constraint_cow(constraint);
+ if (!constraint)
+ return NULL;
+
+ if (pos >= isl_local_space_dim(constraint->ls, type))
+ isl_die(constraint->v->ctx, isl_error_invalid,
+ "position out of bounds",
+ return isl_constraint_free(constraint));
+ constraint = isl_constraint_cow(constraint);
if (!constraint)
- return;
- total = isl_basic_map_total_dim(constraint->bmap);
- isl_seq_clr(constraint->line[0], 1 + total);
+ return NULL;
+
+ constraint->v = isl_vec_cow(constraint->v);
+ if (!constraint->v)
+ return isl_constraint_free(constraint);
+
+ pos += isl_local_space_offset(constraint->ls, type);
+ isl_int_set(constraint->v->el[pos], v);
+
+ return constraint;
}
-struct isl_constraint *isl_constraint_negate(struct isl_constraint *constraint)
+__isl_give isl_constraint *isl_constraint_set_coefficient_si(
+ __isl_take isl_constraint *constraint,
+ enum isl_dim_type type, int pos, int v)
{
- unsigned total;
+ constraint = isl_constraint_cow(constraint);
+ if (!constraint)
+ return NULL;
+ if (pos >= isl_local_space_dim(constraint->ls, type))
+ isl_die(constraint->v->ctx, isl_error_invalid,
+ "position out of bounds",
+ return isl_constraint_free(constraint));
+
+ constraint = isl_constraint_cow(constraint);
if (!constraint)
return NULL;
- isl_assert(constraint->ctx, !isl_constraint_is_equality(constraint),
- goto error);
- isl_assert(constraint->ctx, constraint->bmap->ref == 1, goto error);
- total = isl_basic_map_total_dim(constraint->bmap);
- isl_seq_neg(constraint->line[0], constraint->line[0], 1 + total);
- isl_int_sub_ui(constraint->line[0][0], constraint->line[0][0], 1);
- ISL_F_CLR(constraint->bmap, ISL_BASIC_MAP_NORMALIZED);
+ constraint->v = isl_vec_cow(constraint->v);
+ if (!constraint->v)
+ return isl_constraint_free(constraint);
+
+ pos += isl_local_space_offset(constraint->ls, type);
+ isl_int_set_si(constraint->v->el[pos], v);
+
return constraint;
+}
+
+/* Drop any constraint from "bset" that is identical to "constraint".
+ * In particular, this means that the local spaces of "bset" and
+ * "constraint" need to be the same.
+ *
+ * Since the given constraint may actually be a pointer into the bset,
+ * we have to be careful not to reorder the constraints as the user
+ * may be holding on to other constraints from the same bset.
+ * This should be cleaned up when the internal representation of
+ * isl_constraint is changed to use isl_aff.
+ */
+__isl_give isl_basic_set *isl_basic_set_drop_constraint(
+ __isl_take isl_basic_set *bset, __isl_take isl_constraint *constraint)
+{
+ int i;
+ unsigned n;
+ isl_int **row;
+ unsigned total;
+ isl_local_space *ls1;
+ int equal;
+
+ if (!bset || !constraint)
+ goto error;
+
+ ls1 = isl_basic_set_get_local_space(bset);
+ equal = isl_local_space_is_equal(ls1, constraint->ls);
+ isl_local_space_free(ls1);
+ if (equal < 0)
+ goto error;
+ if (!equal) {
+ isl_constraint_free(constraint);
+ return bset;
+ }
+
+ if (isl_constraint_is_equality(constraint)) {
+ n = bset->n_eq;
+ row = bset->eq;
+ } else {
+ n = bset->n_ineq;
+ row = bset->ineq;
+ }
+
+ total = isl_constraint_dim(constraint, isl_dim_all);
+ for (i = 0; i < n; ++i)
+ if (isl_seq_eq(row[i], constraint->v->el, 1 + total))
+ isl_seq_clr(row[i], 1 + total);
+
+ isl_constraint_free(constraint);
+ return bset;
error:
isl_constraint_free(constraint);
+ isl_basic_set_free(bset);
return NULL;
}
+struct isl_constraint *isl_constraint_negate(struct isl_constraint *constraint)
+{
+ isl_ctx *ctx;
+
+ constraint = isl_constraint_cow(constraint);
+ if (!constraint)
+ return NULL;
+
+ ctx = isl_constraint_get_ctx(constraint);
+ if (isl_constraint_is_equality(constraint))
+ isl_die(ctx, isl_error_invalid, "cannot negate equality",
+ return isl_constraint_free(constraint));
+ constraint->v = isl_vec_neg(constraint->v);
+ constraint->v = isl_vec_cow(constraint->v);
+ if (!constraint->v)
+ return isl_constraint_free(constraint);
+ isl_int_sub_ui(constraint->v->el[0], constraint->v->el[0], 1);
+ return constraint;
+}
+
int isl_constraint_is_equality(struct isl_constraint *constraint)
{
if (!constraint)
return -1;
- return constraint->line >= constraint->bmap->eq;
+ return constraint->eq;
}
int isl_constraint_is_div_constraint(__isl_keep isl_constraint *constraint)
{
int i;
+ int n_div;
if (!constraint)
return -1;
if (isl_constraint_is_equality(constraint))
return 0;
- for (i = 0; i < constraint->bmap->n_div; ++i) {
- if (isl_int_is_zero(constraint->bmap->div[i][0]))
- continue;
- if (isl_basic_map_is_div_constraint(constraint->bmap,
- constraint->line[0], i))
+ n_div = isl_constraint_dim(constraint, isl_dim_div);
+ for (i = 0; i < n_div; ++i) {
+ if (isl_local_space_is_div_constraint(constraint->ls,
+ constraint->v->el, i))
return 1;
}
__isl_take isl_constraint *constraint)
{
int k;
+ isl_local_space *ls;
struct isl_basic_map *bmap;
isl_int *c;
unsigned total;
if (!constraint)
return NULL;
- if (constraint->bmap->n_eq == 1 && constraint->bmap->n_ineq == 0) {
- bmap = isl_basic_map_copy(constraint->bmap);
- isl_constraint_free(constraint);
- return bmap;
- }
-
- bmap = isl_basic_map_universe_like(constraint->bmap);
- bmap = isl_basic_map_align_divs(bmap, constraint->bmap);
- bmap = isl_basic_map_cow(bmap);
+ ls = isl_local_space_copy(constraint->ls);
+ bmap = isl_basic_map_from_local_space(ls);
bmap = isl_basic_map_extend_constraints(bmap, 1, 1);
if (isl_constraint_is_equality(constraint)) {
k = isl_basic_map_alloc_equality(bmap);
c = bmap->ineq[k];
}
total = isl_basic_map_total_dim(bmap);
- isl_seq_cpy(c, constraint->line[0], 1 + total);
+ isl_seq_cpy(c, constraint->v->el, 1 + total);
isl_constraint_free(constraint);
if (bmap)
ISL_F_SET(bmap, ISL_BASIC_SET_FINAL);
if (!constraint)
return NULL;
- isl_assert(constraint->ctx,n(constraint, isl_dim_in) == 0, goto error);
+ if (isl_constraint_dim(constraint, isl_dim_in) != 0)
+ isl_die(isl_constraint_get_ctx(constraint), isl_error_invalid,
+ "not a set constraint",
+ return isl_constraint_free(constraint));
return (isl_basic_set *)isl_basic_map_from_constraint(constraint);
-error:
- isl_constraint_free(constraint);
- return NULL;
}
int isl_basic_map_has_defining_equality(
lower = isl_basic_set_constraint(isl_basic_set_copy(bset),
&bset->eq[i]);
upper = isl_constraint_copy(lower);
- context = isl_basic_set_remove(isl_basic_set_copy(bset),
+ context = isl_basic_set_remove_dims(isl_basic_set_copy(bset),
type, pos, 1);
if (!lower || !upper || !context)
goto error;
isl_basic_set_free(context);
return -1;
}
+
+__isl_give isl_aff *isl_constraint_get_bound(
+ __isl_keep isl_constraint *constraint, enum isl_dim_type type, int pos)
+{
+ isl_aff *aff;
+ isl_ctx *ctx;
+
+ if (!constraint)
+ return NULL;
+ ctx = isl_constraint_get_ctx(constraint);
+ if (pos >= isl_constraint_dim(constraint, type))
+ isl_die(ctx, isl_error_invalid,
+ "index out of bounds", return NULL);
+ if (isl_constraint_dim(constraint, isl_dim_in) != 0)
+ isl_die(ctx, isl_error_invalid,
+ "not a set constraint", return NULL);
+
+ pos += offset(constraint, type);
+ if (isl_int_is_zero(constraint->v->el[pos]))
+ isl_die(ctx, isl_error_invalid,
+ "constraint does not define a bound on given dimension",
+ return NULL);
+
+ aff = isl_aff_alloc(isl_local_space_copy(constraint->ls));
+ if (!aff)
+ return NULL;
+
+ if (isl_int_is_neg(constraint->v->el[pos]))
+ isl_seq_cpy(aff->v->el + 1, constraint->v->el, aff->v->size - 1);
+ else
+ isl_seq_neg(aff->v->el + 1, constraint->v->el, aff->v->size - 1);
+ isl_int_set_si(aff->v->el[1 + pos], 0);
+ isl_int_abs(aff->v->el[0], constraint->v->el[pos]);
+
+ return aff;
+}
+
+/* For an inequality constraint
+ *
+ * f >= 0
+ *
+ * or an equality constraint
+ *
+ * f = 0
+ *
+ * return the affine expression f.
+ */
+__isl_give isl_aff *isl_constraint_get_aff(
+ __isl_keep isl_constraint *constraint)
+{
+ isl_aff *aff;
+
+ if (!constraint)
+ return NULL;
+
+ aff = isl_aff_alloc(isl_local_space_copy(constraint->ls));
+ if (!aff)
+ return NULL;
+
+ isl_seq_cpy(aff->v->el + 1, constraint->v->el, aff->v->size - 1);
+ isl_int_set_si(aff->v->el[0], 1);
+
+ return aff;
+}
+
+/* Construct an equality constraint equating the given affine expression
+ * to zero.
+ */
+__isl_give isl_constraint *isl_equality_from_aff(__isl_take isl_aff *aff)
+{
+ int k;
+ isl_local_space *ls;
+ isl_basic_set *bset;
+
+ if (!aff)
+ return NULL;
+
+ ls = isl_aff_get_domain_local_space(aff);
+ bset = isl_basic_set_from_local_space(ls);
+ bset = isl_basic_set_extend_constraints(bset, 1, 0);
+ k = isl_basic_set_alloc_equality(bset);
+ if (k < 0)
+ goto error;
+
+ isl_seq_cpy(bset->eq[k], aff->v->el + 1, aff->v->size - 1);
+ isl_aff_free(aff);
+
+ return isl_basic_set_constraint(bset, &bset->eq[k]);
+error:
+ isl_aff_free(aff);
+ isl_basic_set_free(bset);
+ return NULL;
+}
+
+/* Construct an inequality constraint enforcing the given affine expression
+ * to be non-negative.
+ */
+__isl_give isl_constraint *isl_inequality_from_aff(__isl_take isl_aff *aff)
+{
+ int k;
+ isl_local_space *ls;
+ isl_basic_set *bset;
+
+ if (!aff)
+ return NULL;
+
+ ls = isl_aff_get_domain_local_space(aff);
+ bset = isl_basic_set_from_local_space(ls);
+ bset = isl_basic_set_extend_constraints(bset, 0, 1);
+ k = isl_basic_set_alloc_inequality(bset);
+ if (k < 0)
+ goto error;
+
+ isl_seq_cpy(bset->ineq[k], aff->v->el + 1, aff->v->size - 1);
+ isl_aff_free(aff);
+
+ return isl_basic_set_constraint(bset, &bset->ineq[k]);
+error:
+ isl_aff_free(aff);
+ isl_basic_set_free(bset);
+ return NULL;
+}