return pw;
}
+ context = isl_set_compute_divs(context);
hull = isl_set_simple_hull(isl_set_copy(context));
pw = FN(PW,cow)(pw);
if (!pw)
goto error;
- for (i = 0; i < pw->n; ++i) {
+ for (i = pw->n - 1; i >= 0; --i) {
+ pw->p[i].set = isl_set_intersect(pw->p[i].set,
+ isl_set_copy(context));
+ if (!pw->p[i].set)
+ goto error;
+ pw->p[i].FIELD = FN(EL,gist)(pw->p[i].FIELD,
+ isl_set_copy(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;
+ if (isl_set_fast_is_empty(pw->p[i].set)) {
+ isl_set_free(pw->p[i].set);
+ FN(EL,free)(pw->p[i].FIELD);
+ if (i != pw->n - 1)
+ pw->p[i] = pw->p[pw->n - 1];
+ pw->n--;
+ }
}
isl_basic_set_free(hull);
return 0;
}
+__isl_give PW *FN(PW,set_dim_name)(__isl_take PW *pw,
+ enum isl_dim_type type, unsigned pos, const char *s)
+{
+ int i;
+
+ pw = FN(PW,cow)(pw);
+ if (!pw)
+ return NULL;
+
+ pw->dim = isl_dim_set_name(pw->dim, type, pos, s);
+ if (!pw->dim)
+ goto error;
+
+ for (i = 0; i < pw->n; ++i) {
+ pw->p[i].set = isl_set_set_dim_name(pw->p[i].set, type, pos, s);
+ if (!pw->p[i].set)
+ goto error;
+ pw->p[i].FIELD = FN(EL,set_dim_name)(pw->p[i].FIELD, type, pos, s);
+ if (!pw->p[i].FIELD)
+ goto error;
+ }
+
+ return pw;
+error:
+ FN(PW,free)(pw);
+ return NULL;
+}
+
__isl_give PW *FN(PW,drop_dims)(__isl_take PW *pw,
enum isl_dim_type type, unsigned first, unsigned n)
{
FN(PW,free)(pw);
return NULL;
}
+
+__isl_give PW *FN(PW,realign)(__isl_take PW *pw, __isl_take isl_reordering *exp)
+{
+ int i;
+
+ pw = FN(PW,cow)(pw);
+ if (!pw || !exp)
+ return NULL;
+
+ for (i = 0; i < pw->n; ++i) {
+ pw->p[i].set = isl_set_realign(pw->p[i].set,
+ isl_reordering_copy(exp));
+ if (!pw->p[i].set)
+ goto error;
+ pw->p[i].FIELD = FN(EL,realign)(pw->p[i].FIELD,
+ isl_reordering_copy(exp));
+ if (!pw->p[i].FIELD)
+ goto error;
+ }
+
+ pw = FN(PW,reset_dim)(pw, isl_dim_copy(exp->dim));
+
+ isl_reordering_free(exp);
+ return pw;
+error:
+ isl_reordering_free(exp);
+ FN(PW,free)(pw);
+ return NULL;
+}
+
+__isl_give PW *FN(PW,mul_isl_int)(__isl_take PW *pw, isl_int v)
+{
+ int i;
+
+ if (isl_int_is_one(v))
+ return pw;
+ if (pw && isl_int_is_zero(v)) {
+ PW *zero;
+ isl_dim *dim = FN(PW,get_dim)(pw);
+#ifdef HAS_TYPE
+ zero = FN(PW,zero)(dim, pw->type);
+#else
+ zero = FN(PW,zero)(dim);
+#endif
+ FN(PW,free)(pw);
+ return zero;
+ }
+ pw = FN(PW,cow)(pw);
+ if (!pw)
+ return NULL;
+ if (pw->n == 0)
+ return pw;
+
+#ifdef HAS_TYPE
+ if (isl_int_is_neg(v))
+ pw->type = isl_fold_type_negate(pw->type);
+#endif
+ for (i = 0; i < pw->n; ++i) {
+ pw->p[i].FIELD = FN(EL,mul_isl_int)(pw->p[i].FIELD, v);
+ if (!pw->p[i].FIELD)
+ goto error;
+ }
+
+ return pw;
+error:
+ FN(PW,free)(pw);
+ return NULL;
+}