From 86ddd36b481a96366b89a1dc13a01fbc3e83f607 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 12 Sep 2013 15:07:42 +0200 Subject: [PATCH] add isl_union_pw_aff_val_on_domain Signed-off-by: Sven Verdoolaege --- doc/user.pod | 8 ++++++-- include/isl/aff.h | 2 ++ isl_aff.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/doc/user.pod b/doc/user.pod index cf19c8c2..ddc6b1e7 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -2913,10 +2913,14 @@ can be created using the following functions. isl_union_pw_qpolynomial_from_pw_qpolynomial( __isl_take isl_pw_qpolynomial *pwqp); -The following function creates a base expression on each -of the sets in the union set and collects the results. +The following functions create a base expression on each +of the sets in the union set and collect the results. #include + __isl_give isl_union_pw_aff * + isl_union_pw_aff_val_on_domain( + __isl_take isl_union_set *domain, + __isl_take isl_val *v); __isl_give isl_union_pw_multi_aff * isl_union_pw_multi_aff_multi_val_on_domain( __isl_take isl_union_set *domain, diff --git a/include/isl/aff.h b/include/isl/aff.h index 5fff2d5e..2109d653 100644 --- a/include/isl/aff.h +++ b/include/isl/aff.h @@ -724,6 +724,8 @@ __isl_give isl_union_pw_aff *isl_union_pw_aff_empty( __isl_take isl_space *space); __isl_give isl_union_pw_aff *isl_union_pw_aff_from_pw_aff( __isl_take isl_pw_aff *pa); +__isl_give isl_union_pw_aff *isl_union_pw_aff_val_on_domain( + __isl_take isl_union_set *domain, __isl_take isl_val *v); __isl_give isl_union_pw_aff *isl_union_pw_aff_add_pw_aff( __isl_take isl_union_pw_aff *upa, __isl_take isl_pw_aff *pa); diff --git a/isl_aff.c b/isl_aff.c index 54269a43..9024e284 100644 --- a/isl_aff.c +++ b/isl_aff.c @@ -6931,3 +6931,50 @@ __isl_give isl_union_pw_aff *isl_union_pw_aff_floor( return upa; } + +/* Internal data structure for isl_union_pw_aff_val_on_domain. + * "v" is the value that the resulting isl_union_pw_aff needs to attain. + * "res" collects the results. + */ +struct isl_union_pw_aff_val_on_domain_data { + isl_val *v; + isl_union_pw_aff *res; +}; + +/* Construct a piecewise affine expression that is equal to data->v + * on "domain" and add the result to data->res. + */ +static int pw_aff_val_on_domain(__isl_take isl_set *domain, void *user) +{ + struct isl_union_pw_aff_val_on_domain_data *data = user; + isl_pw_aff *pa; + isl_val *v; + + v = isl_val_copy(data->v); + pa = isl_pw_aff_val_on_domain(domain, v); + data->res = isl_union_pw_aff_add_pw_aff(data->res, pa); + + return data->res ? 0 : -1; +} + +/* Return a union piecewise affine expression + * that is equal to "v" on "domain". + * + * Construct an isl_pw_aff on each of the sets in "domain" and + * collect the results. + */ +__isl_give isl_union_pw_aff *isl_union_pw_aff_val_on_domain( + __isl_take isl_union_set *domain, __isl_take isl_val *v) +{ + struct isl_union_pw_aff_val_on_domain_data data; + isl_space *space; + + space = isl_union_set_get_space(domain); + data.res = isl_union_pw_aff_empty(space); + data.v = v; + if (isl_union_set_foreach_set(domain, &pw_aff_val_on_domain, &data) < 0) + data.res = isl_union_pw_aff_free(data.res); + isl_union_set_free(domain); + isl_val_free(v); + return data.res; +} -- 2.11.4.GIT