From a1f4aabe7a8c1849e80a8684a37e0d3d70796ef5 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 11 Mar 2010 15:26:38 +0100 Subject: [PATCH] add isl_pw_*_intersect_domain --- doc/user.pod | 3 +++ include/isl_polynomial.h | 4 ++++ isl_polynomial.c | 12 ------------ isl_polynomial_private.h | 6 ++++++ isl_pw_templ.c | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 12 deletions(-) diff --git a/doc/user.pod b/doc/user.pod index e309e26f..c0b17401 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -1292,6 +1292,9 @@ are returned in C<*n> and C<*d>, respectively. __isl_give isl_set *isl_pw_qpolynomial_domain( __isl_take isl_pw_qpolynomial *pwqp); + __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_intersect_domain( + __isl_take isl_pw_qpolynomial *pwpq, + __isl_take isl_set *set); =head2 Dependence Analysis diff --git a/include/isl_polynomial.h b/include/isl_polynomial.h index fa887252..5861fdb1 100644 --- a/include/isl_polynomial.h +++ b/include/isl_polynomial.h @@ -73,6 +73,8 @@ unsigned isl_pw_qpolynomial_dim(__isl_keep isl_pw_qpolynomial *pwqp, enum isl_dim_type type); __isl_give isl_set *isl_pw_qpolynomial_domain(__isl_take isl_pw_qpolynomial *pwqp); +__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_intersect_domain( + __isl_take isl_pw_qpolynomial *pwpq, __isl_take isl_set *set); __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_add( __isl_take isl_pw_qpolynomial *pwqp1, @@ -153,6 +155,8 @@ __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_zero( __isl_give isl_set *isl_pw_qpolynomial_fold_domain( __isl_take isl_pw_qpolynomial_fold *pwf); +__isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_intersect_domain( + __isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_set *set); __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_add( __isl_take isl_pw_qpolynomial_fold *pwf1, diff --git a/isl_polynomial.c b/isl_polynomial.c index 1a4772de..0b063adc 100644 --- a/isl_polynomial.c +++ b/isl_polynomial.c @@ -1319,18 +1319,6 @@ int isl_pw_qpolynomial_is_one(__isl_keep isl_pw_qpolynomial *pwqp) return isl_qpolynomial_is_one(pwqp->p[0].qp); } -__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_cow( - __isl_take isl_pw_qpolynomial *pwqp) -{ - if (!pwqp) - return NULL; - - if (pwqp->ref == 1) - return pwqp; - pwqp->ref--; - return isl_pw_qpolynomial_dup(pwqp); -} - __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_mul( __isl_take isl_pw_qpolynomial *pwqp1, __isl_take isl_pw_qpolynomial *pwqp2) diff --git a/isl_polynomial_private.h b/isl_polynomial_private.h index d3d3f2fb..b13b86ee 100644 --- a/isl_polynomial_private.h +++ b/isl_polynomial_private.h @@ -125,8 +125,14 @@ __isl_give isl_qpolynomial *isl_qpolynomial_div_pow(__isl_take isl_div *div, int isl_qpolynomial_is_zero(__isl_keep isl_qpolynomial *qp); int isl_qpolynomial_is_one(__isl_keep isl_qpolynomial *qp); +__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_cow( + __isl_take isl_pw_qpolynomial *pwqp); + __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_add_piece( __isl_take isl_pw_qpolynomial *pwqp, __isl_take isl_set *set, __isl_take isl_qpolynomial *qp); int isl_pw_qpolynomial_is_zero(__isl_keep isl_pw_qpolynomial *pwqp); int isl_pw_qpolynomial_is_one(__isl_keep isl_pw_qpolynomial *pwqp); + +__isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_cow( + __isl_take isl_pw_qpolynomial_fold *pwf); diff --git a/isl_pw_templ.c b/isl_pw_templ.c index ef6dc0c8..0f742637 100644 --- a/isl_pw_templ.c +++ b/isl_pw_templ.c @@ -95,6 +95,17 @@ error: return NULL; } +__isl_give PW *FN(PW,cow)(__isl_take PW *pw) +{ + if (!pw) + return NULL; + + if (pw->ref == 1) + return pw; + pw->ref--; + return FN(PW,dup)(pw); +} + __isl_give PW *FN(PW,copy)(__isl_keep PW *pw) { if (!pw) @@ -283,3 +294,33 @@ __isl_give isl_set *FN(PW,domain)(__isl_take PW *pw) return dom; } + +__isl_give PW *FN(PW,intersect_domain)(__isl_take PW *pw, __isl_take isl_set *set) +{ + int i; + + if (!pw || !set) + goto error; + + if (pw->n == 0) { + isl_set_free(set); + return pw; + } + + pw = FN(PW,cow)(pw); + if (!pw) + goto error; + + for (i = 0; i < pw->n; ++i) { + pw->p[i].set = isl_set_intersect(pw->p[i].set, isl_set_copy(set)); + if (!pw->p[i].set) + goto error; + } + + isl_set_free(set); + return pw; +error: + isl_set_free(set); + FN(PW,free)(pw); + return NULL; +} -- 2.11.4.GIT