From e6668cbe4a90948344a19582ce081f420d894810 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 18 Sep 2011 16:29:30 +0200 Subject: [PATCH] add isl_union_pw_*_plain_is_equal Signed-off-by: Sven Verdoolaege --- doc/user.pod | 16 +++++++++++++ include/isl/polynomial.h | 8 +++++++ isl_union_templ.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/doc/user.pod b/doc/user.pod index 9694842..ca813c1 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -3139,6 +3139,13 @@ If C is a constant and if C and C are not C then the numerator and denominator of the constant are returned in C<*n> and C<*d>, respectively. +To check whether two union piecewise quasipolynomials are +obviously equal, use + + int isl_union_pw_qpolynomial_plain_is_equal( + __isl_keep isl_union_pw_qpolynomial *upwqp1, + __isl_keep isl_union_pw_qpolynomial *upwqp2); + =head3 Operations on (Piecewise) Quasipolynomials __isl_give isl_qpolynomial *isl_qpolynomial_scale( @@ -3349,6 +3356,15 @@ To iterate over all quasipolynomials in a reduction, use int (*fn)(__isl_take isl_qpolynomial *qp, void *user), void *user); +=head3 Properties of Piecewise Quasipolynomial Reductions + +To check whether two union piecewise quasipolynomial reductions are +obviously equal, use + + int isl_union_pw_qpolynomial_fold_plain_is_equal( + __isl_keep isl_union_pw_qpolynomial_fold *upwf1, + __isl_keep isl_union_pw_qpolynomial_fold *upwf2); + =head3 Operations on Piecewise Quasipolynomial Reductions __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_scale( diff --git a/include/isl/polynomial.h b/include/isl/polynomial.h index 1c5dcdb..7b2a9c1 100644 --- a/include/isl/polynomial.h +++ b/include/isl/polynomial.h @@ -417,6 +417,10 @@ __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_to_polynomial( isl_ctx *isl_union_pw_qpolynomial_get_ctx( __isl_keep isl_union_pw_qpolynomial *upwqp); +int isl_union_pw_qpolynomial_plain_is_equal( + __isl_keep isl_union_pw_qpolynomial *upwqp1, + __isl_keep isl_union_pw_qpolynomial *upwqp2); + __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_from_pw_qpolynomial(__isl_take isl_pw_qpolynomial *pwqp); __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_zero( __isl_take isl_space *dim); @@ -473,6 +477,10 @@ __isl_give isl_printer *isl_printer_print_union_pw_qpolynomial( isl_ctx *isl_union_pw_qpolynomial_fold_get_ctx( __isl_keep isl_union_pw_qpolynomial_fold *upwf); +int isl_union_pw_qpolynomial_fold_plain_is_equal( + __isl_keep isl_union_pw_qpolynomial_fold *upwf1, + __isl_keep isl_union_pw_qpolynomial_fold *upwf2); + __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_fold_from_pw_qpolynomial_fold(__isl_take isl_pw_qpolynomial_fold *pwf); __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_fold_zero( __isl_take isl_space *dim, enum isl_fold type); diff --git a/isl_union_templ.c b/isl_union_templ.c index 1ee7d05..eb33acc 100644 --- a/isl_union_templ.c +++ b/isl_union_templ.c @@ -636,3 +636,65 @@ error: FN(UNION,free)(u); return NULL; } + +S(UNION,plain_is_equal_data) +{ + UNION *u2; + int is_equal; +}; + +static int plain_is_equal_entry(void **entry, void *user) +{ + S(UNION,plain_is_equal_data) *data = user; + uint32_t hash; + struct isl_hash_table_entry *entry2; + PW *pw = *entry; + + hash = isl_space_get_hash(pw->dim); + entry2 = isl_hash_table_find(data->u2->dim->ctx, &data->u2->table, + hash, &has_dim, pw->dim, 0); + if (!entry2) { + data->is_equal = 0; + return -1; + } + + data->is_equal = FN(PW,plain_is_equal)(pw, entry2->data); + if (data->is_equal < 0 || !data->is_equal) + return -1; + + return 0; +} + +int FN(UNION,plain_is_equal)(__isl_keep UNION *u1, __isl_keep UNION *u2) +{ + S(UNION,plain_is_equal_data) data = { NULL, 1 }; + + if (!u1 || !u2) + return -1; + if (u1 == u2) + return 1; + if (u1->table.n != u2->table.n) + return 0; + + u1 = FN(UNION,copy)(u1); + u2 = FN(UNION,copy)(u2); + u1 = FN(UNION,align_params)(u1, FN(UNION,get_space)(u2)); + u2 = FN(UNION,align_params)(u2, FN(UNION,get_space)(u1)); + if (!u1 || !u2) + goto error; + + data.u2 = u2; + if (isl_hash_table_foreach(u1->dim->ctx, &u1->table, + &plain_is_equal_entry, &data) < 0 && + data.is_equal) + goto error; + + FN(UNION,free)(u1); + FN(UNION,free)(u2); + + return data.is_equal; +error: + FN(UNION,free)(u1); + FN(UNION,free)(u2); + return -1; +} -- 2.7.4