add private isl_*_list_dup
[platform/upstream/isl.git] / isl_pw_templ.c
index da4b53e..e89d4a3 100644 (file)
@@ -10,12 +10,14 @@ static __isl_give PW *FN(PW,alloc_)(__isl_take isl_dim *dim,
 static __isl_give PW *FN(PW,alloc_)(__isl_take isl_dim *dim, int n)
 #endif
 {
+       isl_ctx *ctx;
        struct PW *pw;
 
        if (!dim)
                return NULL;
-       isl_assert(dim->ctx, n >= 0, goto error);
-       pw = isl_alloc(dim->ctx, struct PW,
+       ctx = isl_dim_get_ctx(dim);
+       isl_assert(ctx, n >= 0, goto error);
+       pw = isl_alloc(ctx, struct PW,
                        sizeof(struct PW) + (n - 1) * sizeof(S(PW,piece)));
        if (!pw)
                goto error;
@@ -34,12 +36,12 @@ error:
 }
 
 #ifdef HAS_TYPE
-__isl_give PW *FN(PW,zero)(__isl_take isl_dim *dim, enum isl_fold type)
+__isl_give PW *FN(PW,ZERO)(__isl_take isl_dim *dim, enum isl_fold type)
 {
        return FN(PW,alloc_)(dim, type, 0);
 }
 #else
-__isl_give PW *FN(PW,zero)(__isl_take isl_dim *dim)
+__isl_give PW *FN(PW,ZERO)(__isl_take isl_dim *dim)
 {
        return FN(PW,alloc_)(dim, 0);
 }
@@ -48,29 +50,36 @@ __isl_give PW *FN(PW,zero)(__isl_take isl_dim *dim)
 __isl_give PW *FN(PW,add_piece)(__isl_take PW *pw,
        __isl_take isl_set *set, __isl_take EL *el)
 {
+       isl_ctx *ctx;
+       isl_dim *el_dim = NULL;
+
        if (!pw || !set || !el)
                goto error;
 
-       if (isl_set_fast_is_empty(set) || FN(EL,IS_ZERO)(el)) {
+       if (isl_set_plain_is_empty(set) || FN(EL,EL_IS_ZERO)(el)) {
                isl_set_free(set);
                FN(EL,free)(el);
                return pw;
        }
 
+       ctx = isl_set_get_ctx(set);
 #ifdef HAS_TYPE
        if (pw->type != el->type)
-               isl_die(set->ctx, isl_error_invalid, "fold types don't match",
+               isl_die(ctx, isl_error_invalid, "fold types don't match",
                        goto error);
 #endif
-       isl_assert(set->ctx, isl_dim_equal(pw->dim, el->dim), goto error);
-       isl_assert(set->ctx, pw->n < pw->size, goto error);
+       el_dim = FN(EL,get_dim(el));
+       isl_assert(ctx, isl_dim_equal(pw->dim, el_dim), goto error);
+       isl_assert(ctx, pw->n < pw->size, goto error);
 
        pw->p[pw->n].set = set;
        pw->p[pw->n].FIELD = el;
        pw->n++;
        
+       isl_dim_free(el_dim);
        return pw;
 error:
+       isl_dim_free(el_dim);
        FN(PW,free)(pw);
        isl_set_free(set);
        FN(EL,free)(el);
@@ -123,9 +132,6 @@ __isl_give PW *FN(PW,dup)(__isl_keep PW *pw)
                                            FN(EL,copy)(pw->p[i].FIELD));
 
        return dup;
-error:
-       FN(PW,free)(dup);
-       return NULL;
 }
 
 __isl_give PW *FN(PW,cow)(__isl_take PW *pw)
@@ -148,14 +154,14 @@ __isl_give PW *FN(PW,copy)(__isl_keep PW *pw)
        return pw;
 }
 
-void FN(PW,free)(__isl_take PW *pw)
+void *FN(PW,free)(__isl_take PW *pw)
 {
        int i;
 
        if (!pw)
-               return;
+               return NULL;
        if (--pw->ref > 0)
-               return;
+               return NULL;
 
        for (i = 0; i < pw->n; ++i) {
                isl_set_free(pw->p[i].set);
@@ -163,9 +169,11 @@ void FN(PW,free)(__isl_take PW *pw)
        }
        isl_dim_free(pw->dim);
        free(pw);
+
+       return NULL;
 }
 
-int FN(PW,is_zero)(__isl_keep PW *pw)
+int FN(PW,IS_ZERO)(__isl_keep PW *pw)
 {
        if (!pw)
                return -1;
@@ -177,24 +185,26 @@ __isl_give PW *FN(PW,add)(__isl_take PW *pw1, __isl_take PW *pw2)
 {
        int i, j, n;
        struct PW *res;
+       isl_ctx *ctx;
        isl_set *set;
 
        if (!pw1 || !pw2)
                goto error;
 
+       ctx = isl_dim_get_ctx(pw1->dim);
 #ifdef HAS_TYPE
        if (pw1->type != pw2->type)
-               isl_die(pw1->dim->ctx, isl_error_invalid,
+               isl_die(ctx, isl_error_invalid,
                        "fold types don't match", goto error);
 #endif
-       isl_assert(pw1->dim->ctx, isl_dim_equal(pw1->dim, pw2->dim), goto error);
+       isl_assert(ctx, isl_dim_equal(pw1->dim, pw2->dim), goto error);
 
-       if (FN(PW,is_zero)(pw1)) {
+       if (FN(PW,IS_ZERO)(pw1)) {
                FN(PW,free)(pw1);
                return pw2;
        }
 
-       if (FN(PW,is_zero)(pw2)) {
+       if (FN(PW,IS_ZERO)(pw2)) {
                FN(PW,free)(pw2);
                return pw1;
        }
@@ -215,7 +225,7 @@ __isl_give PW *FN(PW,add)(__isl_take PW *pw1, __isl_take PW *pw2)
                                        isl_set_copy(pw2->p[j].set));
                        common = isl_set_intersect(isl_set_copy(pw1->p[i].set),
                                                isl_set_copy(pw2->p[j].set));
-                       if (isl_set_fast_is_empty(common)) {
+                       if (isl_set_plain_is_empty(common)) {
                                isl_set_free(common);
                                continue;
                        }
@@ -250,24 +260,26 @@ error:
 __isl_give PW *FN(PW,add_disjoint)(__isl_take PW *pw1, __isl_take PW *pw2)
 {
        int i;
+       isl_ctx *ctx;
        PW *res;
 
        if (!pw1 || !pw2)
                goto error;
 
+       ctx = isl_dim_get_ctx(pw1->dim);
 #ifdef HAS_TYPE
        if (pw1->type != pw2->type)
-               isl_die(pw1->dim->ctx, isl_error_invalid,
+               isl_die(ctx, isl_error_invalid,
                        "fold types don't match", goto error);
 #endif
-       isl_assert(pw1->dim->ctx, isl_dim_equal(pw1->dim, pw2->dim), goto error);
+       isl_assert(ctx, isl_dim_equal(pw1->dim, pw2->dim), goto error);
 
-       if (FN(PW,is_zero)(pw1)) {
+       if (FN(PW,IS_ZERO)(pw1)) {
                FN(PW,free)(pw1);
                return pw2;
        }
 
-       if (FN(PW,is_zero)(pw2)) {
+       if (FN(PW,IS_ZERO)(pw2)) {
                FN(PW,free)(pw2);
                return pw1;
        }
@@ -298,16 +310,46 @@ error:
        return NULL;
 }
 
+#ifndef NO_NEG
+__isl_give PW *FN(PW,neg)(__isl_take PW *pw)
+{
+       int i;
+
+       if (!pw)
+               return NULL;
+
+       if (FN(PW,IS_ZERO)(pw))
+               return pw;
+
+       pw = FN(PW,cow)(pw);
+       if (!pw)
+               return NULL;
+
+       for (i = 0; i < pw->n; ++i) {
+               pw->p[i].FIELD = FN(EL,neg)(pw->p[i].FIELD);
+               if (!pw->p[i].FIELD)
+                       return FN(PW,free)(pw);
+       }
+
+       return pw;
+}
+#endif
+
+#ifndef NO_EVAL
 __isl_give isl_qpolynomial *FN(PW,eval)(__isl_take PW *pw,
        __isl_take isl_point *pnt)
 {
        int i;
        int found = 0;
+       isl_ctx *ctx;
+       isl_dim *pnt_dim = NULL;
        isl_qpolynomial *qp;
 
        if (!pw || !pnt)
                goto error;
-       isl_assert(pnt->dim->ctx, isl_dim_equal(pnt->dim, pw->dim), goto error);
+       ctx = isl_point_get_ctx(pnt);
+       pnt_dim = isl_point_get_dim(pnt);
+       isl_assert(ctx, isl_dim_equal(pnt_dim, pw->dim), goto error);
 
        for (i = 0; i < pw->n; ++i) {
                found = isl_set_contains_point(pw->p[i].set, pnt);
@@ -322,13 +364,16 @@ __isl_give isl_qpolynomial *FN(PW,eval)(__isl_take PW *pw,
        else
                qp = isl_qpolynomial_zero(isl_dim_copy(pw->dim));
        FN(PW,free)(pw);
+       isl_dim_free(pnt_dim);
        isl_point_free(pnt);
        return qp;
 error:
        FN(PW,free)(pw);
+       isl_dim_free(pnt_dim);
        isl_point_free(pnt);
        return NULL;
 }
+#endif
 
 __isl_give isl_set *FN(PW,domain)(__isl_take PW *pw)
 {
@@ -371,7 +416,7 @@ __isl_give PW *FN(PW,intersect_domain)(__isl_take PW *pw, __isl_take isl_set *se
                aff = isl_set_affine_hull(isl_set_copy(pw->p[i].set));
                pw->p[i].FIELD = FN(EL,substitute_equalities)(pw->p[i].FIELD,
                                                                aff);
-               if (isl_set_fast_is_empty(pw->p[i].set)) {
+               if (isl_set_plain_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)
@@ -419,7 +464,7 @@ __isl_give PW *FN(PW,gist)(__isl_take PW *pw, __isl_take isl_set *context)
                                                isl_basic_set_copy(hull));
                if (!pw->p[i].set)
                        goto error;
-               if (isl_set_fast_is_empty(pw->p[i].set)) {
+               if (isl_set_plain_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)
@@ -450,7 +495,8 @@ __isl_give PW *FN(PW,coalesce)(__isl_take PW *pw)
 
        for (i = pw->n - 1; i >= 0; --i) {
                for (j = i - 1; j >= 0; --j) {
-                       if (!FN(EL,is_equal)(pw->p[i].FIELD, pw->p[j].FIELD))
+                       if (!FN(EL,plain_is_equal)(pw->p[i].FIELD,
+                                                       pw->p[j].FIELD))
                                continue;
                        pw->p[j].set = isl_set_union(pw->p[j].set,
                                                        pw->p[i].set);
@@ -475,9 +521,10 @@ error:
 
 isl_ctx *FN(PW,get_ctx)(__isl_keep PW *pw)
 {
-       return pw ? pw->dim->ctx : NULL;
+       return pw ? isl_dim_get_ctx(pw->dim) : NULL;
 }
 
+#ifndef NO_INVOLVES_DIMS
 int FN(PW,involves_dims)(__isl_keep PW *pw, enum isl_dim_type type,
        unsigned first, unsigned n)
 {
@@ -492,9 +539,13 @@ int FN(PW,involves_dims)(__isl_keep PW *pw, enum isl_dim_type type,
                                                        type, first, n);
                if (involves < 0 || involves)
                        return involves;
+               involves = isl_set_involves_dims(pw->p[i].set, type, first, n);
+               if (involves < 0 || involves)
+                       return involves;
        }
        return 0;
 }
+#endif
 
 __isl_give PW *FN(PW,set_dim_name)(__isl_take PW *pw,
        enum isl_dim_type type, unsigned pos, const char *s)
@@ -524,6 +575,7 @@ error:
        return NULL;
 }
 
+#ifndef NO_DROP_DIMS
 __isl_give PW *FN(PW,drop_dims)(__isl_take PW *pw,
        enum isl_dim_type type, unsigned first, unsigned n)
 {
@@ -554,7 +606,9 @@ error:
        FN(PW,free)(pw);
        return NULL;
 }
+#endif
 
+#ifndef NO_INSERT_DIMS
 __isl_give PW *FN(PW,insert_dims)(__isl_take PW *pw, enum isl_dim_type type,
        unsigned first, unsigned n)
 {
@@ -588,6 +642,7 @@ error:
        FN(PW,free)(pw);
        return NULL;
 }
+#endif
 
 __isl_give PW *FN(PW,fix_dim)(__isl_take PW *pw,
        enum isl_dim_type type, unsigned pos, isl_int v)
@@ -644,6 +699,7 @@ error:
        return NULL;
 }
 
+#ifndef NO_OPT
 /* 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,
@@ -688,12 +744,14 @@ __isl_give isl_qpolynomial *FN(PW,min)(__isl_take PW *pw)
 {
        return FN(PW,opt)(pw, 0);
 }
+#endif
 
 __isl_give isl_dim *FN(PW,get_dim)(__isl_keep PW *pw)
 {
        return pw ? isl_dim_copy(pw->dim) : NULL;
 }
 
+#ifndef NO_RESET_DIM
 __isl_give PW *FN(PW,reset_dim)(__isl_take PW *pw, __isl_take isl_dim *dim)
 {
        int i;
@@ -721,6 +779,7 @@ error:
        FN(PW,free)(pw);
        return NULL;
 }
+#endif
 
 int FN(PW,has_equal_dim)(__isl_keep PW *pw1, __isl_keep PW *pw2)
 {
@@ -730,14 +789,17 @@ int FN(PW,has_equal_dim)(__isl_keep PW *pw1, __isl_keep PW *pw2)
        return isl_dim_equal(pw1->dim, pw2->dim);
 }
 
+#ifndef NO_MORPH
 __isl_give PW *FN(PW,morph)(__isl_take PW *pw, __isl_take isl_morph *morph)
 {
        int i;
+       isl_ctx *ctx;
 
        if (!pw || !morph)
                goto error;
 
-       isl_assert(pw->dim->ctx, isl_dim_equal(pw->dim, morph->dom->dim),
+       ctx = isl_dim_get_ctx(pw->dim);
+       isl_assert(ctx, isl_dim_equal(pw->dim, morph->dom->dim),
                goto error);
 
        pw = FN(PW,cow)(pw);
@@ -766,6 +828,7 @@ error:
        isl_morph_free(morph);
        return NULL;
 }
+#endif
 
 int FN(PW,foreach_piece)(__isl_keep PW *pw,
        int (*fn)(__isl_take isl_set *set, __isl_take EL *el, void *user),
@@ -784,6 +847,7 @@ int FN(PW,foreach_piece)(__isl_keep PW *pw,
        return 0;
 }
 
+#ifndef NO_LIFT
 static int any_divs(__isl_keep isl_set *set)
 {
        int i;
@@ -857,7 +921,9 @@ int FN(PW,foreach_lifted_piece)(__isl_keep PW *pw,
 
        return 0;
 }
+#endif
 
+#ifndef NO_MOVE_DIMS
 __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)
@@ -889,7 +955,9 @@ error:
        FN(PW,free)(pw);
        return NULL;
 }
+#endif
 
+#ifndef NO_REALIGN
 __isl_give PW *FN(PW,realign)(__isl_take PW *pw, __isl_take isl_reordering *exp)
 {
        int i;
@@ -918,6 +986,7 @@ error:
        FN(PW,free)(pw);
        return NULL;
 }
+#endif
 
 __isl_give PW *FN(PW,mul_isl_int)(__isl_take PW *pw, isl_int v)
 {
@@ -929,9 +998,9 @@ __isl_give PW *FN(PW,mul_isl_int)(__isl_take PW *pw, isl_int v)
                PW *zero;
                isl_dim *dim = FN(PW,get_dim)(pw);
 #ifdef HAS_TYPE
-               zero = FN(PW,zero)(dim, pw->type);
+               zero = FN(PW,ZERO)(dim, pw->type);
 #else
-               zero = FN(PW,zero)(dim);
+               zero = FN(PW,ZERO)(dim);
 #endif
                FN(PW,free)(pw);
                return zero;
@@ -947,7 +1016,7 @@ __isl_give PW *FN(PW,mul_isl_int)(__isl_take PW *pw, isl_int 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);
+               pw->p[i].FIELD = FN(EL,scale)(pw->p[i].FIELD, v);
                if (!pw->p[i].FIELD)
                        goto error;
        }