From 5ef446319801cc9de30fc7ca9b8d420ca7cfb788 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 15 Jul 2022 17:09:11 +0200 Subject: [PATCH] add exported isl_map_domain_reverse This complements the already exported isl_map_range_reverse and isl_set_wrapped_reverse. Signed-off-by: Sven Verdoolaege --- doc/user.pod | 2 ++ include/isl/map.h | 2 ++ isl_map.c | 25 +++++++++++++++++++++++++ isl_test2.cc | 9 +++++++++ 4 files changed, 38 insertions(+) diff --git a/doc/user.pod b/doc/user.pod index ac25da6b..278c47b2 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -5449,6 +5449,8 @@ earlier dimensions before those that involve later dimensions. __isl_take isl_basic_map *bmap); __isl_give isl_map *isl_map_reverse( __isl_take isl_map *map); + __isl_give isl_map *isl_map_domain_reverse( + __isl_take isl_map *map); __isl_give isl_map *isl_map_range_reverse( __isl_take isl_map *map); diff --git a/include/isl/map.h b/include/isl/map.h index f4a50a98..20da7a99 100644 --- a/include/isl/map.h +++ b/include/isl/map.h @@ -326,6 +326,8 @@ __isl_give isl_map *isl_map_copy(__isl_keep isl_map *map); __isl_export __isl_give isl_map *isl_map_reverse(__isl_take isl_map *map); __isl_export +__isl_give isl_map *isl_map_domain_reverse(__isl_take isl_map *map); +__isl_export __isl_give isl_map *isl_map_range_reverse(__isl_take isl_map *map); __isl_export __isl_give isl_map *isl_map_union( diff --git a/isl_map.c b/isl_map.c index 4a2f0f0b..fb33f885 100644 --- a/isl_map.c +++ b/isl_map.c @@ -6,6 +6,7 @@ * Copyright 2016 INRIA Paris * Copyright 2016 Sven Verdoolaege * Copyright 2018-2019 Cerebras Systems + * Copyright 2022 Cerebras Systems * * Use of this software is governed by the MIT license * @@ -4031,6 +4032,22 @@ static __isl_give isl_basic_map *isl_basic_map_reverse_wrapped( return bmap; } +/* Given a basic map (A -> B) -> C, return the corresponding basic map + * (B -> A) -> C. + */ +static __isl_give isl_basic_map *isl_basic_map_domain_reverse( + __isl_take isl_basic_map *bmap) +{ + isl_space *space; + + space = isl_basic_map_peek_space(bmap); + if (isl_space_check_domain_is_wrapping(space) < 0) + return isl_basic_map_free(bmap); + bmap = isl_basic_map_reverse_wrapped(bmap, isl_dim_in); + + return bmap; +} + /* Given a basic map A -> (B -> C), return the corresponding basic map * A -> (C -> B). */ @@ -7215,6 +7232,14 @@ __isl_give isl_map *isl_map_reverse(__isl_take isl_map *map) &isl_basic_map_reverse); } +/* Given a map (A -> B) -> C, return the corresponding map (B -> A) -> C. + */ +__isl_give isl_map *isl_map_domain_reverse(__isl_take isl_map *map) +{ + return isl_map_transform(map, &isl_space_domain_reverse, + &isl_basic_map_domain_reverse); +} + /* Given a map A -> (B -> C), return the corresponding map A -> (C -> B). */ __isl_give isl_map *isl_map_range_reverse(__isl_take isl_map *map) diff --git a/isl_test2.cc b/isl_test2.cc index ffb7cd8c..d8bcf2ba 100644 --- a/isl_test2.cc +++ b/isl_test2.cc @@ -504,6 +504,15 @@ static void test_reverse(isl::ctx ctx) "{ [B[y] -> A[x]] -> T[5*(x // 2) + 7*(y // 3) : x > y, 0] }" }, }); + C(&isl::map::domain_reverse, { + { "{ [A[] -> B[]] -> [C[] -> D[]] }", + "{ [B[] -> A[]] -> [C[] -> D[]] }" }, + { "{ N[B[] -> C[]] -> A[] }", + "{ [C[] -> B[]] -> A[] }" }, + { "{ N[B[x] -> B[y]] -> A[] }", + "{ N[B[*] -> B[*]] -> A[] }" }, + }); + C(&isl::union_map::range_reverse, { { "{ A[] -> [B[] -> C[]]; A[] -> B[]; A[0] -> N[B[1] -> B[2]] }", "{ A[] -> [C[] -> B[]]; A[0] -> N[B[2] -> B[1]] }" }, -- 2.11.4.GIT