From: Sven Verdoolaege Date: Tue, 16 Aug 2011 16:46:37 +0000 (+0200) Subject: add isl_pw_multi_aff_from_map X-Git-Tag: isl-0.08~36 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=99be448e39a8d8687b794946648c3cfa30e832b9;p=platform%2Fupstream%2Fisl.git add isl_pw_multi_aff_from_map Signed-off-by: Sven Verdoolaege --- diff --git a/doc/user.pod b/doc/user.pod index f624ff1..9e54f96 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -2955,6 +2955,15 @@ be created using the following functions. __isl_take isl_set *set, __isl_take isl_multi_aff *maff); +A piecewise multiple quasi affine expression can also be initialized +from an C or C, provided the C is a singleton +and the C is single-valued. + + __isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_set( + __isl_take isl_set *set); + __isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_map( + __isl_take isl_map *map); + Multiple quasi affine expressions can be copied and freed using #include diff --git a/include/isl/aff.h b/include/isl/aff.h index 2bc5037..8815caf 100644 --- a/include/isl/aff.h +++ b/include/isl/aff.h @@ -305,6 +305,9 @@ __isl_give isl_set *isl_set_from_pw_multi_aff(__isl_take isl_pw_multi_aff *pma); __isl_give isl_printer *isl_printer_print_pw_multi_aff(__isl_take isl_printer *p, __isl_keep isl_pw_multi_aff *pma); +__isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_set(__isl_take isl_set *set); +__isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_map(__isl_take isl_map *map); + void isl_pw_multi_aff_dump(__isl_keep isl_pw_multi_aff *pma); #if defined(__cplusplus) diff --git a/isl_aff.c b/isl_aff.c index 59216bb..a4b2790 100644 --- a/isl_aff.c +++ b/isl_aff.c @@ -2159,6 +2159,54 @@ __isl_give isl_set *isl_set_from_pw_multi_aff(__isl_take isl_pw_multi_aff *pma) return isl_map_from_pw_multi_aff(pma); } +/* Try and create an isl_pw_multi_aff that is equivalent to the given isl_map. + * This obivously only works if the input "map" is single-valued. + * If so, we compute the lexicographic minimum of the image in the form + * of an isl_pw_multi_aff. Since the image is unique, it is equal + * to its lexicographic minimum. + * If the input is not single-valued, we produce an error. + */ +__isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_map(__isl_take isl_map *map) +{ + int i; + int sv; + isl_pw_multi_aff *pma; + + if (!map) + return NULL; + + sv = isl_map_is_single_valued(map); + if (sv < 0) + goto error; + if (!sv) + isl_die(isl_map_get_ctx(map), isl_error_invalid, + "map is not single-valued", goto error); + map = isl_map_make_disjoint(map); + if (!map) + return NULL; + + pma = isl_pw_multi_aff_empty(isl_map_get_space(map)); + + for (i = 0; i < map->n; ++i) { + isl_pw_multi_aff *pma_i; + isl_basic_map *bmap; + bmap = isl_basic_map_copy(map->p[i]); + pma_i = isl_basic_map_lexmin_pw_multi_aff(bmap); + pma = isl_pw_multi_aff_add_disjoint(pma, pma_i); + } + + isl_map_free(map); + return pma; +error: + isl_map_free(map); + return NULL; +} + +__isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_set(__isl_take isl_set *set) +{ + return isl_pw_multi_aff_from_map(set); +} + /* Plug in "subs" for dimension "type", "pos" of "aff". * * Let i be the dimension to replace and let "subs" be of the form