From 26374bbf83218c813954f7300f0057723d3b509c Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Mon, 28 May 2018 11:08:30 +0200 Subject: [PATCH] Expose, document and test isl_map_get_basic_map_list This matches isl_set_get_basic_set_list, which was exposed in d25e556 (add isl_set_get_basic_set_list, Wed Apr 29 13:41:45 2015 +0200) with the following motivation: "It is sometimes more convenient to manipulate a list of basic sets rather than to iterate over them individually." For isl maps the same motivation exists. Even though often higher-level operations reduce the need to inspect the specific basic maps, there are certain uses (e.g., inspecting how "complex" a map is or writing a custom printer for a map) which require the inspection and sometimes sorting of basic maps. Especially sorting is more easily expressed on a list of basic maps. Hence, functionality to obtain a basic map list from a map is exposed. Signed-off-by: Tobias Grosser Signed-off-by: Sven Verdoolaege --- doc/user.pod | 6 +++++- include/isl/map.h | 2 ++ isl_map_private.h | 3 --- isl_test.c | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/doc/user.pod b/doc/user.pod index fd8d787c..8a1f7e45 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -2278,7 +2278,7 @@ 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 +or union set and a list of basic maps from a map. #include __isl_give isl_basic_set_list *isl_set_get_basic_set_list( @@ -2289,6 +2289,10 @@ or union set isl_union_set_get_basic_set_list( __isl_keep isl_union_set *uset); + #include + __isl_give isl_basic_map_list *isl_map_get_basic_map_list( + __isl_keep isl_map *map); + 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/map.h b/include/isl/map.h index 0a855ed4..6728e3f5 100644 --- a/include/isl/map.h +++ b/include/isl/map.h @@ -620,6 +620,8 @@ int isl_map_n_basic_map(__isl_keep isl_map *map); __isl_export isl_stat isl_map_foreach_basic_map(__isl_keep isl_map *map, isl_stat (*fn)(__isl_take isl_basic_map *bmap, void *user), void *user); +__isl_give isl_basic_map_list *isl_map_get_basic_map_list( + __isl_keep isl_map *map); __isl_give isl_map *isl_map_fixed_power_val(__isl_take isl_map *map, __isl_take isl_val *exp); diff --git a/isl_map_private.h b/isl_map_private.h index b132619a..bccafd50 100644 --- a/isl_map_private.h +++ b/isl_map_private.h @@ -534,9 +534,6 @@ __isl_give isl_basic_map *isl_basic_map_reduce_coefficients( __isl_give isl_basic_map *isl_basic_map_shift_div( __isl_take isl_basic_map *bmap, int div, int pos, isl_int shift); -__isl_give isl_basic_map_list *isl_map_get_basic_map_list( - __isl_keep isl_map *map); - int isl_basic_set_count_upto(__isl_keep isl_basic_set *bset, isl_int max, isl_int *count); int isl_set_count_upto(__isl_keep isl_set *set, isl_int max, isl_int *count); diff --git a/isl_test.c b/isl_test.c index 957f1234..397f2e26 100644 --- a/isl_test.c +++ b/isl_test.c @@ -3458,6 +3458,43 @@ static isl_stat test_get_list_bset_from_uset(isl_ctx *ctx) 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) +{ + int i; + isl_bool equal; + isl_map *map, *map2; + isl_basic_map_list *bmap_list; + + map = isl_map_read_from_str(ctx, + "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }"); + bmap_list = isl_map_get_basic_map_list(map); + + map2 = isl_map_empty(isl_map_get_space(map)); + + for (i = 0; i < isl_basic_map_list_n_basic_map(bmap_list); i++) { + isl_basic_map *bmap; + bmap = isl_basic_map_list_get_basic_map(bmap_list, i); + map2 = isl_map_union(map2, isl_map_from_basic_map(bmap)); + } + + equal = isl_map_is_equal(map, map2); + + isl_map_free(map); + isl_map_free(map2); + isl_basic_map_list_free(bmap_list); + + if (equal < 0) + return isl_stat_error; + + if (!equal) + isl_die(ctx, isl_error_unknown, "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) @@ -3466,6 +3503,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_bmap_from_map(ctx)) + return -1; return 0; } -- 2.11.4.GIT