From b324c0c32e39997b3e044d2aa69de00a2f4fc5da Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Mon, 28 May 2018 11:08:31 +0200 Subject: [PATCH] Add, document and test isl_union_map_get_map_list As with the previous commit, the same motivation applies: It is sometimes more convenient to manipulate a list of maps rather than to iterate over them individually. Sorting elements (e.g., dependences relations, memory accesses relations) according to some priority function is one use case where lists are more convenient to use than the foreach callback. Signed-off-by: Tobias Grosser Signed-off-by: Sven Verdoolaege --- doc/user.pod | 7 ++++++- include/isl/union_map.h | 2 ++ isl_test.c | 39 +++++++++++++++++++++++++++++++++++++++ isl_union_map.c | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) diff --git a/doc/user.pod b/doc/user.pod index 8a1f7e45..492670bc 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -2278,7 +2278,8 @@ from int isl_map_n_basic_map(__isl_keep isl_map *map); It is also possible to obtain a list of basic sets from a set -or union set and a list of basic maps from a map. +or union set, a list of basic maps from a map and a list of maps from a union +map. #include __isl_give isl_basic_set_list *isl_set_get_basic_set_list( @@ -2293,6 +2294,10 @@ or union set and a list of basic maps from a map. __isl_give isl_basic_map_list *isl_map_get_basic_map_list( __isl_keep isl_map *map); + #include + __isl_give isl_map_list *isl_union_map_get_map_list( + __isl_keep isl_union_map *umap); + The returned list can be manipulated using the functions in L<"Lists">. To iterate over the constraints of a basic set or map, use diff --git a/include/isl/union_map.h b/include/isl/union_map.h index 86fa4953..18db9af4 100644 --- a/include/isl/union_map.h +++ b/include/isl/union_map.h @@ -235,6 +235,8 @@ int isl_union_map_n_map(__isl_keep isl_union_map *umap); __isl_export isl_stat isl_union_map_foreach_map(__isl_keep isl_union_map *umap, isl_stat (*fn)(__isl_take isl_map *map, void *user), void *user); +__isl_give isl_map_list *isl_union_map_get_map_list( + __isl_keep isl_union_map *umap); isl_bool isl_union_map_every_map(__isl_keep isl_union_map *umap, isl_bool (*test)(__isl_keep isl_map *map, void *user), void *user); __isl_give isl_union_map *isl_union_map_remove_map_if( diff --git a/isl_test.c b/isl_test.c index 397f2e26..bf5f83c2 100644 --- a/isl_test.c +++ b/isl_test.c @@ -3495,6 +3495,43 @@ static isl_stat test_get_list_bmap_from_map(isl_ctx *ctx) return isl_stat_ok; } +/* Check that the conversion from 'union map' to 'map list' works as expected. + */ +static isl_stat test_get_list_map_from_umap(isl_ctx *ctx) +{ + int i; + isl_bool equal; + isl_union_map *umap, *umap2; + isl_map_list *map_list; + + umap = isl_union_map_read_from_str(ctx, + "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }"); + map_list = isl_union_map_get_map_list(umap); + + umap2 = isl_union_map_empty(isl_union_map_get_space(umap)); + + for (i = 0; i < isl_map_list_n_map(map_list); i++) { + isl_map *map; + map = isl_map_list_get_map(map_list, i); + umap2 = isl_union_map_union(umap2, isl_union_map_from_map(map)); + } + + equal = isl_union_map_is_equal(umap, umap2); + + isl_union_map_free(umap); + isl_union_map_free(umap2); + isl_map_list_free(map_list); + + if (equal < 0) + return isl_stat_error; + + if (!equal) + isl_die(ctx, isl_error_unknown, "union maps are not equal", + return isl_stat_error); + + return isl_stat_ok; +} + /* Check that the conversion from isl objects to lists works as expected. */ static int test_get_list(isl_ctx *ctx) @@ -3505,6 +3542,8 @@ static int test_get_list(isl_ctx *ctx) return -1; if (test_get_list_bmap_from_map(ctx)) return -1; + if (test_get_list_map_from_umap(ctx)) + return -1; return 0; } diff --git a/isl_union_map.c b/isl_union_map.c index 1041fe9c..d760dd9c 100644 --- a/isl_union_map.c +++ b/isl_union_map.c @@ -551,6 +551,43 @@ isl_bool isl_union_map_every_map(__isl_keep isl_union_map *umap, return isl_bool_error; } +/* Add "map" to "list". + */ +static isl_stat add_list_map(__isl_take isl_map *map, void *user) +{ + isl_map_list **list = user; + + *list = isl_map_list_add(*list, map); + + if (!*list) + return isl_stat_error; + return isl_stat_ok; +} + +/* Return the maps in "umap" as a list. + * + * First construct a list of the appropriate size and then add all the + * elements. + */ +__isl_give isl_map_list *isl_union_map_get_map_list( + __isl_keep isl_union_map *umap) +{ + int n_maps; + isl_ctx *ctx; + isl_map_list *list; + + if (!umap) + return NULL; + ctx = isl_union_map_get_ctx(umap); + n_maps = isl_union_map_n_map(umap); + list = isl_map_list_alloc(ctx, n_maps); + + if (isl_union_map_foreach_map(umap, &add_list_map, &list) < 0) + list = isl_map_list_free(list); + + return list; +} + static isl_stat copy_map(void **entry, void *user) { isl_map *map = *entry; -- 2.11.4.GIT