From 03a3e2b393c9bf40504fe2b44e91005b5abec0c6 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 11 Jul 2014 23:22:29 +0200 Subject: [PATCH] generalize isl_union_pw_qpolynomial_neg Signed-off-by: Sven Verdoolaege --- doc/user.pod | 3 +++ include/isl/aff.h | 3 +++ isl_polynomial.c | 26 -------------------------- isl_union_templ.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/doc/user.pod b/doc/user.pod index 2eb0223f..3d9d738b 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -4722,6 +4722,9 @@ All parameters need to be named. __isl_take isl_pw_multi_aff *pma); __isl_give isl_multi_pw_aff *isl_multi_pw_aff_neg( __isl_take isl_multi_pw_aff *mpa); + __isl_give isl_union_pw_multi_aff * + isl_union_pw_multi_aff_neg( + __isl_take isl_union_pw_multi_aff *upma); __isl_give isl_aff *isl_aff_ceil( __isl_take isl_aff *aff); __isl_give isl_pw_aff *isl_pw_aff_ceil( diff --git a/include/isl/aff.h b/include/isl/aff.h index 88ff2094..a0f9e2f0 100644 --- a/include/isl/aff.h +++ b/include/isl/aff.h @@ -573,6 +573,9 @@ int isl_union_pw_multi_aff_plain_is_equal( __isl_give isl_union_set *isl_union_pw_multi_aff_domain( __isl_take isl_union_pw_multi_aff *upma); +__isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_neg( + __isl_take isl_union_pw_multi_aff *upma); + __isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_add( __isl_take isl_union_pw_multi_aff *upma1, __isl_take isl_union_pw_multi_aff *upma2); diff --git a/isl_polynomial.c b/isl_polynomial.c index 6b73bb39..28c6badb 100644 --- a/isl_polynomial.c +++ b/isl_polynomial.c @@ -4060,32 +4060,6 @@ error: return NULL; } -static int neg_entry(void **entry, void *user) -{ - isl_pw_qpolynomial **pwqp = (isl_pw_qpolynomial **)entry; - - *pwqp = isl_pw_qpolynomial_neg(*pwqp); - - return *pwqp ? 0 : -1; -} - -__isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_neg( - __isl_take isl_union_pw_qpolynomial *upwqp) -{ - upwqp = isl_union_pw_qpolynomial_cow(upwqp); - if (!upwqp) - return NULL; - - if (isl_hash_table_foreach(upwqp->space->ctx, &upwqp->table, - &neg_entry, NULL) < 0) - goto error; - - return upwqp; -error: - isl_union_pw_qpolynomial_free(upwqp); - return NULL; -} - __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_mul( __isl_take isl_union_pw_qpolynomial *upwqp1, __isl_take isl_union_pw_qpolynomial *upwqp2) diff --git a/isl_union_templ.c b/isl_union_templ.c index ed7404e7..b051bff7 100644 --- a/isl_union_templ.c +++ b/isl_union_templ.c @@ -1162,3 +1162,33 @@ error: FN(UNION,free)(u2); return -1; } + +#ifndef NO_NEG +/* Replace *entry by its opposite. + * + * Return 0 on success and -1 on error. + */ +static int FN(UNION,neg_entry)(void **entry, void *user) +{ + PW **pw = (PW **) entry; + + *pw = FN(PW,neg)(*pw); + + return *pw ? 0 : -1; +} + +/* Return the opposite of "u". + */ +__isl_give UNION *FN(UNION,neg)(__isl_take UNION *u) +{ + u = FN(UNION,cow)(u); + if (!u) + return NULL; + + if (isl_hash_table_foreach(u->space->ctx, &u->table, + &FN(UNION,neg_entry), NULL) < 0) + return FN(UNION,free)(u); + + return u; +} +#endif -- 2.11.4.GIT