add union_pw_*_intersect_params
authorSven Verdoolaege <skimo@kotnet.org>
Wed, 2 Nov 2011 10:28:38 +0000 (11:28 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Wed, 2 Nov 2011 15:35:37 +0000 (16:35 +0100)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl/polynomial.h
isl_union_templ.c

index 2044701..26ac1cf 100644 (file)
@@ -3516,6 +3516,10 @@ obviously equal, use
        __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_intersect_domain(
                __isl_take isl_union_pw_qpolynomial *upwpq,
                __isl_take isl_union_set *uset);
+       __isl_give isl_union_pw_qpolynomial *
+       isl_union_pw_qpolynomial_intersect_params(
+               __isl_take isl_union_pw_qpolynomial *upwpq,
+               __isl_take isl_set *set);
 
        __isl_give isl_qpolynomial *isl_qpolynomial_align_params(
                __isl_take isl_qpolynomial *qp,
@@ -3706,6 +3710,10 @@ obviously equal, use
        __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_fold_intersect_domain(
                __isl_take isl_union_pw_qpolynomial_fold *upwf,
                __isl_take isl_union_set *uset);
+       __isl_give isl_union_pw_qpolynomial_fold *
+       isl_union_pw_qpolynomial_fold_intersect_params(
+               __isl_take isl_union_pw_qpolynomial_fold *upwf,
+               __isl_take isl_set *set);
 
        __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_project_domain_on_params(
                __isl_take isl_pw_qpolynomial_fold *pwf);
index 96c435b..2903875 100644 (file)
@@ -457,6 +457,9 @@ __isl_give isl_union_set *isl_union_pw_qpolynomial_domain(
 __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_intersect_domain(
        __isl_take isl_union_pw_qpolynomial *upwpq,
        __isl_take isl_union_set *uset);
+__isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_intersect_params(
+       __isl_take isl_union_pw_qpolynomial *upwpq,
+       __isl_take isl_set *set);
 
 __isl_give isl_space *isl_union_pw_qpolynomial_get_space(
        __isl_keep isl_union_pw_qpolynomial *upwqp);
@@ -515,6 +518,10 @@ __isl_give isl_union_set *isl_union_pw_qpolynomial_fold_domain(
 __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_fold_intersect_domain(
        __isl_take isl_union_pw_qpolynomial_fold *upwf,
        __isl_take isl_union_set *uset);
+__isl_give isl_union_pw_qpolynomial_fold *
+isl_union_pw_qpolynomial_fold_intersect_params(
+       __isl_take isl_union_pw_qpolynomial_fold *upwf,
+       __isl_take isl_set *set);
 
 enum isl_fold isl_union_pw_qpolynomial_fold_get_type(
        __isl_keep isl_union_pw_qpolynomial_fold *upwf);
index eb33acc..93d004d 100644 (file)
@@ -415,6 +415,78 @@ error:
        return NULL;
 }
 
+S(UNION,any_set_data) {
+       isl_set *set;
+       UNION *res;
+       __isl_give PW *(*fn)(__isl_take PW*, __isl_take isl_set*);
+};
+
+static int any_set_entry(void **entry, void *user)
+{
+       S(UNION,any_set_data) *data = user;
+       PW *pw = *entry;
+       int empty;
+
+       pw = FN(PW,copy)(pw);
+       pw = data->fn(pw, isl_set_copy(data->set));
+
+       empty = FN(PW,is_zero)(pw);
+       if (empty < 0) {
+               FN(PW,free)(pw);
+               return -1;
+       }
+       if (empty) {
+               FN(PW,free)(pw);
+               return 0;
+       }
+
+       data->res = FN(FN(UNION,add),PARTS)(data->res, pw);
+
+       return 0;
+}
+
+/* Update each element of "u" by calling "fn" on the element and "set".
+ */
+static __isl_give UNION *any_set_op(__isl_take UNION *u,
+       __isl_take isl_set *set,
+       __isl_give PW *(*fn)(__isl_take PW*, __isl_take isl_set*))
+{
+       S(UNION,any_set_data) data = { NULL, NULL, fn };
+
+       u = FN(UNION,align_params)(u, isl_set_get_space(set));
+       set = isl_set_align_params(set, FN(UNION,get_space)(u));
+
+       if (!u || !set)
+               goto error;
+
+       data.set = set;
+#ifdef HAS_TYPE
+       data.res = FN(UNION,alloc)(isl_space_copy(u->dim), u->type, u->table.n);
+#else
+       data.res = FN(UNION,alloc)(isl_space_copy(u->dim), u->table.n);
+#endif
+       if (isl_hash_table_foreach(u->dim->ctx, &u->table,
+                                  &any_set_entry, &data) < 0)
+               goto error;
+
+       FN(UNION,free)(u);
+       isl_set_free(set);
+       return data.res;
+error:
+       FN(UNION,free)(u);
+       isl_set_free(set);
+       FN(UNION,free)(data.res);
+       return NULL;
+}
+
+/* Intersect the domain of "u" with the parameter domain "context".
+ */
+__isl_give UNION *FN(UNION,intersect_params)(__isl_take UNION *u,
+       __isl_take isl_set *set)
+{
+       return any_set_op(u, set, &FN(PW,intersect_params));
+}
+
 S(UNION,match_set_data) {
        isl_union_set *uset;
        UNION *res;