continue;
}
- sum = FN(EL,ADD)(FN(EL,copy)(pw1->p[i].FIELD),
- FN(EL,copy)(pw2->p[j].FIELD));
+ sum = ADD(common, FN(EL,copy)(pw1->p[i].FIELD),
+ FN(EL,copy)(pw2->p[j].FIELD));
res = FN(PW,add_piece)(res, common, sum);
}
__isl_take isl_point *pnt)
{
int i;
- int found;
+ int found = 0;
isl_qpolynomial *qp;
if (!pw || !pnt)
goto error;
for (i = 0; i < pw->n; ++i) {
- pw->p[i].set = isl_set_gist(pw->p[i].set,
+ pw->p[i].set = isl_set_gist_basic_set(pw->p[i].set,
isl_basic_set_copy(hull));
if (!pw->p[i].set)
goto error;
FN(PW,free)(pw);
return NULL;
}
+
+__isl_give PW *FN(PW,fix_dim)(__isl_take PW *pw,
+ enum isl_dim_type type, unsigned pos, isl_int v)
+{
+ int i;
+
+ if (!pw)
+ return NULL;
+
+ pw = FN(PW,cow)(pw);
+ if (!pw)
+ return NULL;
+ for (i = 0; i < pw->n; ++i) {
+ pw->p[i].set = isl_set_fix(pw->p[i].set, type, pos, v);
+ if (!pw->p[i].set)
+ goto error;
+ }
+
+ return pw;
+error:
+ FN(PW,free)(pw);
+ return NULL;
+}
+
+unsigned FN(PW,dim)(__isl_keep PW *pw, enum isl_dim_type type)
+{
+ return pw ? isl_dim_size(pw->dim, type) : 0;
+}
+
+__isl_give PW *FN(PW,split_dims)(__isl_take PW *pw,
+ enum isl_dim_type type, unsigned first, unsigned n)
+{
+ int i;
+
+ if (!pw)
+ return NULL;
+ if (n == 0)
+ return pw;
+
+ pw = FN(PW,cow)(pw);
+ if (!pw)
+ return NULL;
+ if (!pw->dim)
+ goto error;
+ for (i = 0; i < pw->n; ++i) {
+ pw->p[i].set = isl_set_split_dims(pw->p[i].set, type, first, n);
+ if (!pw->p[i].set)
+ goto error;
+ }
+
+ return pw;
+error:
+ FN(PW,free)(pw);
+ return NULL;
+}
+
+/* Compute the maximal value attained by the piecewise quasipolynomial
+ * on its domain or zero if the domain is empty.
+ * In the worst case, the domain is scanned completely,
+ * so the domain is assumed to be bounded.
+ */
+__isl_give isl_qpolynomial *FN(PW,opt)(__isl_take PW *pw, int max)
+{
+ int i;
+ isl_qpolynomial *opt;
+
+ if (!pw)
+ return NULL;
+
+ if (pw->n == 0) {
+ isl_dim *dim = isl_dim_copy(pw->dim);
+ FN(PW,free)(pw);
+ return isl_qpolynomial_zero(dim);
+ }
+
+ opt = FN(EL,opt_on_domain)(FN(EL,copy)(pw->p[0].FIELD),
+ isl_set_copy(pw->p[0].set), max);
+ for (i = 1; i < pw->n; ++i) {
+ isl_qpolynomial *opt_i;
+ opt_i = FN(EL,opt_on_domain)(FN(EL,copy)(pw->p[i].FIELD),
+ isl_set_copy(pw->p[i].set), max);
+ if (max)
+ opt = isl_qpolynomial_max_cst(opt, opt_i);
+ else
+ opt = isl_qpolynomial_min_cst(opt, opt_i);
+ }
+
+ FN(PW,free)(pw);
+ return opt;
+}
+
+__isl_give isl_qpolynomial *FN(PW,max)(__isl_take PW *pw)
+{
+ return FN(PW,opt)(pw, 1);
+}
+
+__isl_give isl_qpolynomial *FN(PW,min)(__isl_take PW *pw)
+{
+ return FN(PW,opt)(pw, 0);
+}
+
+__isl_give isl_dim *FN(PW,get_dim)(__isl_keep PW *pw)
+{
+ return pw ? isl_dim_copy(pw->dim) : NULL;
+}
+
+__isl_give PW *FN(PW,morph)(__isl_take PW *pw, __isl_take isl_morph *morph)
+{
+ int i;
+
+ if (!pw || !morph)
+ goto error;
+
+ isl_assert(pw->dim->ctx, isl_dim_equal(pw->dim, morph->dom->dim),
+ goto error);
+
+ pw = FN(PW,cow)(pw);
+ if (!pw)
+ goto error;
+ isl_dim_free(pw->dim);
+ pw->dim = isl_dim_copy(morph->ran->dim);
+ if (!pw->dim)
+ goto error;
+
+ for (i = 0; i < pw->n; ++i) {
+ pw->p[i].set = isl_morph_set(isl_morph_copy(morph), pw->p[i].set);
+ if (!pw->p[i].set)
+ goto error;
+ pw->p[i].FIELD = FN(EL,morph)(pw->p[i].FIELD,
+ isl_morph_copy(morph));
+ if (!pw->p[i].FIELD)
+ goto error;
+ }
+
+ isl_morph_free(morph);
+
+ return pw;
+error:
+ FN(PW,free)(pw);
+ isl_morph_free(morph);
+ return NULL;
+}
+
+static int any_divs(__isl_keep isl_set *set)
+{
+ int i;
+
+ if (!set)
+ return -1;
+
+ for (i = 0; i < set->n; ++i)
+ if (set->p[i]->n_div > 0)
+ return 1;
+
+ return 0;
+}
+
+static int foreach_lifted_subset(__isl_take isl_set *set, __isl_take EL *el,
+ int (*fn)(__isl_take isl_set *set, __isl_take EL *el,
+ void *user), void *user)
+{
+ int i;
+
+ if (!set || !el)
+ goto error;
+
+ for (i = 0; i < set->n; ++i) {
+ isl_set *lift;
+ EL *copy;
+
+ lift = isl_set_from_basic_set(isl_basic_set_copy(set->p[i]));
+ lift = isl_set_lift(lift);
+
+ copy = FN(EL,copy)(el);
+ copy = FN(EL,lift)(copy, isl_set_get_dim(lift));
+
+ if (fn(lift, copy, user) < 0)
+ goto error;
+ }
+
+ isl_set_free(set);
+ FN(EL,free)(el);
+
+ return 0;
+error:
+ isl_set_free(set);
+ FN(EL,free)(el);
+ return -1;
+}
+
+int FN(PW,foreach_lifted_piece)(__isl_keep PW *pw,
+ int (*fn)(__isl_take isl_set *set, __isl_take EL *el,
+ void *user), void *user)
+{
+ int i;
+
+ if (!pw)
+ return -1;
+
+ for (i = 0; i < pw->n; ++i) {
+ isl_set *set;
+ EL *el;
+
+ set = isl_set_copy(pw->p[i].set);
+ el = FN(EL,copy)(pw->p[i].FIELD);
+ if (!any_divs(set)) {
+ if (fn(set, el, user) < 0)
+ return -1;
+ continue;
+ }
+ if (foreach_lifted_subset(set, el, fn, user) < 0)
+ return -1;
+ }
+
+ return 0;
+}
+
+__isl_give PW *FN(PW,move_dims)(__isl_take PW *pw,
+ enum isl_dim_type dst_type, unsigned dst_pos,
+ enum isl_dim_type src_type, unsigned src_pos, unsigned n)
+{
+ int i;
+
+ pw = FN(PW,cow)(pw);
+ if (!pw)
+ return NULL;
+
+ pw->dim = isl_dim_move(pw->dim, dst_type, dst_pos, src_type, src_pos, n);
+ if (!pw->dim)
+ goto error;
+
+ for (i = 0; i < pw->n; ++i) {
+ pw->p[i].set = isl_set_move_dims(pw->p[i].set,
+ dst_type, dst_pos,
+ src_type, src_pos, n);
+ if (!pw->p[i].set)
+ goto error;
+ pw->p[i].FIELD = FN(EL,move_dims)(pw->p[i].FIELD,
+ dst_type, dst_pos, src_type, src_pos, n);
+ if (!pw->p[i].FIELD)
+ goto error;
+ }
+
+ return pw;
+error:
+ FN(PW,free)(pw);
+ return NULL;
+}