From 591e80b37aa76168b16cf5470f82292887688456 Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Mon, 28 May 2018 11:08:33 +0200 Subject: [PATCH] Add, document and test isl_union_set_get_set_list As with the previous commit, the same motivation applies: It is sometimes more convenient to manipulate a list of sets rather than to iterate over them individually. Sorting elements (e.g., dependence distances, access offsets) 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 --- Makefile.am | 1 + doc/user.pod | 4 +++- include/isl/union_set.h | 2 ++ isl_test.c | 38 ++++++++++++++++++++++++++++++++++++++ isl_union_map.c | 10 ++++++++++ set_list_from_map_list_inl.c | 9 +++++++++ 6 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 set_list_from_map_list_inl.c diff --git a/Makefile.am b/Makefile.am index e60fdd6a..9b73a167 100644 --- a/Makefile.am +++ b/Makefile.am @@ -379,6 +379,7 @@ EXTRA_DIST = \ read_in_string_templ.c \ set_to_map.c \ set_from_map.c \ + set_list_from_map_list_inl.c \ isl_tab_lexopt_templ.c \ uset_to_umap.c \ uset_from_umap.c \ diff --git a/doc/user.pod b/doc/user.pod index 492670bc..c5fa0f7f 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -2277,7 +2277,7 @@ from #include 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 +It is also possible to obtain a list of (basic) sets from a set or union set, a list of basic maps from a map and a list of maps from a union map. @@ -2289,6 +2289,8 @@ map. __isl_give isl_basic_set_list * isl_union_set_get_basic_set_list( __isl_keep isl_union_set *uset); + __isl_give isl_set_list *isl_union_set_get_set_list( + __isl_keep isl_union_set *uset); #include __isl_give isl_basic_map_list *isl_map_get_basic_map_list( diff --git a/include/isl/union_set.h b/include/isl/union_set.h index 289693b8..0e6fc984 100644 --- a/include/isl/union_set.h +++ b/include/isl/union_set.h @@ -121,6 +121,8 @@ isl_stat isl_union_set_foreach_set(__isl_keep isl_union_set *uset, isl_stat (*fn)(__isl_take isl_set *set, void *user), void *user); __isl_give isl_basic_set_list *isl_union_set_get_basic_set_list( __isl_keep isl_union_set *uset); +__isl_give isl_set_list *isl_union_set_get_set_list( + __isl_keep isl_union_set *uset); isl_bool isl_union_set_contains(__isl_keep isl_union_set *uset, __isl_keep isl_space *space); __isl_give isl_set *isl_union_set_extract_set(__isl_keep isl_union_set *uset, diff --git a/isl_test.c b/isl_test.c index bf5f83c2..80292643 100644 --- a/isl_test.c +++ b/isl_test.c @@ -3458,6 +3458,42 @@ static isl_stat test_get_list_bset_from_uset(isl_ctx *ctx) return isl_stat_ok; } +/* Check that the conversion from 'union set' to 'set list' works as expected. + */ +static isl_stat test_get_list_set_from_uset(isl_ctx *ctx) +{ + int i; + isl_bool equal; + isl_union_set *uset, *uset2; + isl_set_list *set_list; + + uset = isl_union_set_read_from_str(ctx, "{ A[0]; A[2]; B[3] }"); + set_list = isl_union_set_get_set_list(uset); + + uset2 = isl_union_set_empty(isl_union_set_get_space(uset)); + + for (i = 0; i < isl_set_list_n_set(set_list); i++) { + isl_set *set; + set = isl_set_list_get_set(set_list, i); + uset2 = isl_union_set_union(uset2, isl_union_set_from_set(set)); + } + + equal = isl_union_set_is_equal(uset, uset2); + + isl_union_set_free(uset); + isl_union_set_free(uset2); + isl_set_list_free(set_list); + + if (equal < 0) + return isl_stat_error; + + if (!equal) + isl_die(ctx, isl_error_unknown, "union sets are not equal", + return isl_stat_error); + + return isl_stat_ok; +} + /* Check that the conversion from 'map' to 'basic map list' works as expected. */ static isl_stat test_get_list_bmap_from_map(isl_ctx *ctx) @@ -3540,6 +3576,8 @@ static int test_get_list(isl_ctx *ctx) return -1; if (test_get_list_bset_from_uset(ctx)) return -1; + if (test_get_list_set_from_uset(ctx)) + return -1; if (test_get_list_bmap_from_map(ctx)) return -1; if (test_get_list_map_from_umap(ctx)) diff --git a/isl_union_map.c b/isl_union_map.c index d760dd9c..5ea7c400 100644 --- a/isl_union_map.c +++ b/isl_union_map.c @@ -29,6 +29,7 @@ #include #include #include +#include /* Return the number of parameters of "umap", where "type" * is required to be set to isl_dim_param. @@ -588,6 +589,15 @@ __isl_give isl_map_list *isl_union_map_get_map_list( return list; } +/* Return the sets in "uset" as a list. + */ +__isl_give isl_set_list *isl_union_set_get_set_list( + __isl_keep isl_union_set *uset) +{ + return set_list_from_map_list( + isl_union_map_get_map_list(uset_to_umap(uset))); +} + static isl_stat copy_map(void **entry, void *user) { isl_map *map = *entry; diff --git a/set_list_from_map_list_inl.c b/set_list_from_map_list_inl.c new file mode 100644 index 00000000..108c5347 --- /dev/null +++ b/set_list_from_map_list_inl.c @@ -0,0 +1,9 @@ +#include + +/* Return the set list that was treated as the map list "list". + */ +static __isl_give isl_set_list *set_list_from_map_list( + __isl_take isl_map_list *list) +{ + return (isl_set_list *) list; +} -- 2.11.4.GIT