add isl_pw_qpolynomial_fold_foreach_lifted_piece
authorSven Verdoolaege <skimo@kotnet.org>
Mon, 24 May 2010 15:04:26 +0000 (17:04 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 12 Jun 2010 11:16:36 +0000 (13:16 +0200)
include/isl_polynomial.h
isl_fold.c
isl_polynomial.c
isl_polynomial_private.h
isl_pw_templ.c

index c53b31c..a39ecc4 100644 (file)
@@ -264,6 +264,11 @@ __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_move_dims(
 __isl_give isl_qpolynomial *isl_pw_qpolynomial_fold_eval(
        __isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_point *pnt);
 
+int isl_pw_qpolynomial_fold_foreach_lifted_piece(
+       __isl_keep isl_pw_qpolynomial_fold *pwf,
+       int (*fn)(__isl_take isl_set *set, __isl_take isl_qpolynomial_fold *fold,
+                   void *user), void *user);
+
 __isl_give isl_printer *isl_printer_print_pw_qpolynomial_fold(
        __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf);
 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold *pwf,
index ac22387..a0d241b 100644 (file)
@@ -764,6 +764,45 @@ enum isl_fold isl_qpolynomial_fold_get_type(__isl_keep isl_qpolynomial_fold *fol
        return fold->type;
 }
 
+__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_lift(
+       __isl_take isl_qpolynomial_fold *fold, __isl_take isl_dim *dim)
+{
+       int i;
+       isl_ctx *ctx;
+
+       if (!fold || !dim)
+               goto error;
+
+       if (isl_dim_equal(fold->dim, dim)) {
+               isl_dim_free(dim);
+               return fold;
+       }
+
+       fold = isl_qpolynomial_fold_cow(fold);
+       if (!fold)
+               goto error;
+
+       isl_dim_free(fold->dim);
+       fold->dim = isl_dim_copy(dim);
+       if (!fold->dim)
+               goto error;
+
+       for (i = 0; i < fold->n; ++i) {
+               fold->qp[i] = isl_qpolynomial_lift(fold->qp[i],
+                                               isl_dim_copy(dim));
+               if (!fold->qp[i])
+                       goto error;
+       }
+
+       isl_dim_free(dim);
+
+       return fold;
+error:
+       isl_qpolynomial_fold_free(fold);
+       isl_dim_free(dim);
+       return NULL;
+}
+
 __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_move_dims(
        __isl_take isl_qpolynomial_fold *fold,
        enum isl_dim_type dst_type, unsigned dst_pos,
index 8eb7e3d..7d86fd3 100644 (file)
@@ -2723,20 +2723,6 @@ int isl_pw_qpolynomial_foreach_piece(__isl_keep isl_pw_qpolynomial *pwqp,
        return 0;
 }
 
-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;
-}
-
 __isl_give isl_qpolynomial *isl_qpolynomial_lift(__isl_take isl_qpolynomial *qp,
        __isl_take isl_dim *dim)
 {
@@ -2787,67 +2773,6 @@ error:
        return NULL;
 }
 
-static int foreach_lifted_subset(__isl_take isl_set *set,
-       __isl_take isl_qpolynomial *qp,
-       int (*fn)(__isl_take isl_set *set, __isl_take isl_qpolynomial *qp,
-                   void *user), void *user)
-{
-       int i;
-
-       if (!set || !qp)
-               goto error;
-
-       for (i = 0; i < set->n; ++i) {
-               isl_set *lift;
-               isl_qpolynomial *copy;
-
-               lift = isl_set_from_basic_set(isl_basic_set_copy(set->p[i]));
-               lift = isl_set_lift(lift);
-
-               copy = isl_qpolynomial_copy(qp);
-               copy = isl_qpolynomial_lift(copy, isl_set_get_dim(lift));
-
-               if (fn(lift, copy, user) < 0)
-                       goto error;
-       }
-
-       isl_set_free(set);
-       isl_qpolynomial_free(qp);
-
-       return 0;
-error:
-       isl_set_free(set);
-       isl_qpolynomial_free(qp);
-       return -1;
-}
-
-int isl_pw_qpolynomial_foreach_lifted_piece(__isl_keep isl_pw_qpolynomial *pwqp,
-       int (*fn)(__isl_take isl_set *set, __isl_take isl_qpolynomial *qp,
-                   void *user), void *user)
-{
-       int i;
-
-       if (!pwqp)
-               return -1;
-
-       for (i = 0; i < pwqp->n; ++i) {
-               isl_set *set;
-               isl_qpolynomial *qp;
-
-               set = isl_set_copy(pwqp->p[i].set);
-               qp = isl_qpolynomial_copy(pwqp->p[i].qp);
-               if (!any_divs(set)) {
-                       if (fn(set, qp, user) < 0)
-                               return -1;
-                       continue;
-               }
-               if (foreach_lifted_subset(set, qp, fn, user) < 0)
-                       return -1;
-       }
-
-       return 0;
-}
-
 /* For each parameter or variable that does not appear in qp,
  * first eliminate the variable from all constraints and then set it to zero.
  */
index a91574b..bcbd47a 100644 (file)
@@ -165,3 +165,8 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_morph(
        __isl_take isl_qpolynomial_fold *fold, __isl_take isl_morph *morph);
 __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_morph(
        __isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_morph *morph);
+
+__isl_give isl_qpolynomial *isl_qpolynomial_lift(__isl_take isl_qpolynomial *qp,
+       __isl_take isl_dim *dim);
+__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_lift(
+       __isl_take isl_qpolynomial_fold *fold, __isl_take isl_dim *dim);
index d470d6f..0957d38 100644 (file)
@@ -592,6 +592,80 @@ error:
        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)