From 4d609134dc648d2bf30d22e1ed71094e8e9ac6ab Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 24 Dec 2020 14:13:40 +0100 Subject: [PATCH] extract out shared isl_bound_add{,_tight} This clarifies the code and will be reused in an upcoming commit. Signed-off-by: Sven Verdoolaege --- isl_bernstein.c | 6 ++---- isl_bound.c | 30 ++++++++++++++++++++++++------ isl_bound.h | 5 +++++ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/isl_bernstein.c b/isl_bernstein.c index 02f36889..dfe90540 100644 --- a/isl_bernstein.c +++ b/isl_bernstein.c @@ -582,11 +582,9 @@ isl_stat isl_qpolynomial_bound_on_domain_bernstein( pwf = bernstein_coefficients_base(bset, poly, &data, tp); if (tight) - bound->pwf_tight = isl_pw_qpolynomial_fold_fold(bound->pwf_tight, pwf); + return isl_bound_add_tight(bound, pwf); else - bound->pwf = isl_pw_qpolynomial_fold_fold(bound->pwf, pwf); - - return isl_stat_ok; + return isl_bound_add(bound, pwf); error: isl_basic_set_free(bset); isl_qpolynomial_free(poly); diff --git a/isl_bound.c b/isl_bound.c index 5f603c15..b47ee416 100644 --- a/isl_bound.c +++ b/isl_bound.c @@ -16,6 +16,26 @@ #include #include +/* Add the bound "pwf", which is not known to be tight, + * to the output of "bound". + */ +isl_stat isl_bound_add(struct isl_bound *bound, + __isl_take isl_pw_qpolynomial_fold *pwf) +{ + bound->pwf = isl_pw_qpolynomial_fold_fold(bound->pwf, pwf); + return isl_stat_non_null(bound->pwf); +} + +/* Add the bound "pwf", which is known to be tight, + * to the output of "bound". + */ +isl_stat isl_bound_add_tight(struct isl_bound *bound, + __isl_take isl_pw_qpolynomial_fold *pwf) +{ + bound->pwf_tight = isl_pw_qpolynomial_fold_fold(bound->pwf_tight, pwf); + return isl_stat_non_null(bound->pwf); +} + /* Compute a bound on the polynomial defined over the parametric polytope * using either range propagation or bernstein expansion and * store the result in bound->pwf and bound->pwf_tight. @@ -96,9 +116,8 @@ static isl_stat unwrapped_guarded_poly_bound(__isl_take isl_basic_set *bset, bound->pwf_tight = isl_pw_qpolynomial_fold_morph_domain( bound->pwf_tight, morph); - bound->pwf = isl_pw_qpolynomial_fold_fold(top_pwf, bound->pwf); - bound->pwf_tight = isl_pw_qpolynomial_fold_fold(top_pwf_tight, - bound->pwf_tight); + isl_bound_add(bound, top_pwf); + isl_bound_add_tight(bound, top_pwf_tight); return r; error: @@ -171,9 +190,8 @@ static isl_stat guarded_poly_bound(__isl_take isl_basic_set *bset, bound->pwf_tight = isl_pw_qpolynomial_fold_reset_space(bound->pwf_tight, isl_space_copy(bound->dim)); - bound->pwf = isl_pw_qpolynomial_fold_fold(top_pwf, bound->pwf); - bound->pwf_tight = isl_pw_qpolynomial_fold_fold(top_pwf_tight, - bound->pwf_tight); + isl_bound_add(bound, top_pwf); + isl_bound_add_tight(bound, top_pwf_tight); return r; error: diff --git a/isl_bound.h b/isl_bound.h index 1a9d390e..c05e5011 100644 --- a/isl_bound.h +++ b/isl_bound.h @@ -17,4 +17,9 @@ struct isl_bound { isl_pw_qpolynomial_fold *pwf_tight; }; +isl_stat isl_bound_add(struct isl_bound *bound, + __isl_take isl_pw_qpolynomial_fold *pwf); +isl_stat isl_bound_add_tight(struct isl_bound *bound, + __isl_take isl_pw_qpolynomial_fold *pwf); + #endif -- 2.11.4.GIT