From eba3288afd24ee3aeec159692be38775aae6188d Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 11 May 2011 18:01:59 +0200 Subject: [PATCH] add isl_{basic_,}map_may_be_set Sets and maps share the same internal representation, but only some of those internal representations can be sets. Add specific functions to test this condition, replacing some open coded variants. Signed-off-by: Sven Verdoolaege --- isl_dim.c | 11 +++++++++++ isl_dim_private.h | 1 + isl_map.c | 21 +++++++++++++++++++-- isl_map_private.h | 2 ++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/isl_dim.c b/isl_dim.c index f50e8ff..042b1fb 100644 --- a/isl_dim.c +++ b/isl_dim.c @@ -1126,6 +1126,17 @@ int isl_dim_is_named_or_nested(__isl_keep isl_dim *dim, enum isl_dim_type type) return 0; } +int isl_dim_may_be_set(__isl_keep isl_dim *dim) +{ + if (!dim) + return -1; + if (isl_dim_size(dim, isl_dim_in) != 0) + return 0; + if (isl_dim_is_named_or_nested(dim, isl_dim_in)) + return 0; + return 1; +} + __isl_give isl_dim *isl_dim_reset(__isl_take isl_dim *dim, enum isl_dim_type type) { diff --git a/isl_dim_private.h b/isl_dim_private.h index f150ef0..4f47eeb 100644 --- a/isl_dim_private.h +++ b/isl_dim_private.h @@ -24,6 +24,7 @@ __isl_give isl_dim *isl_dim_as_set_dim(__isl_take isl_dim *dim); unsigned isl_dim_offset(__isl_keep isl_dim *dim, enum isl_dim_type type); +int isl_dim_may_be_set(__isl_keep isl_dim *dim); int isl_dim_is_named_or_nested(__isl_keep isl_dim *dim, enum isl_dim_type type); int isl_dim_has_named_params(__isl_keep isl_dim *dim); __isl_give isl_dim *isl_dim_reset(__isl_take isl_dim *dim, diff --git a/isl_map.c b/isl_map.c index b648cec..128dce9 100644 --- a/isl_map.c +++ b/isl_map.c @@ -3851,8 +3851,19 @@ struct isl_basic_set *isl_basic_map_domain(struct isl_basic_map *bmap) return domain; } +int isl_basic_map_may_be_set(__isl_keep isl_basic_map *bmap) +{ + if (!bmap) + return -1; + return isl_dim_may_be_set(bmap->dim); +} + struct isl_basic_set *isl_basic_map_range(struct isl_basic_map *bmap) { + if (!bmap) + return NULL; + if (isl_basic_map_may_be_set(bmap)) + return bmap; return isl_basic_map_domain(isl_basic_map_reverse(bmap)); } @@ -3934,6 +3945,13 @@ error: return NULL; } +int isl_map_may_be_set(__isl_keep isl_map *map) +{ + if (!map) + return -1; + return isl_dim_may_be_set(map->dim); +} + struct isl_set *isl_map_range(struct isl_map *map) { int i; @@ -3941,8 +3959,7 @@ struct isl_set *isl_map_range(struct isl_map *map) if (!map) goto error; - if (isl_map_dim(map, isl_dim_in) == 0 && - !isl_dim_is_named_or_nested(map->dim, isl_dim_in)) + if (isl_map_may_be_set(map)) return (isl_set *)map; map = isl_map_cow(map); diff --git a/isl_map_private.h b/isl_map_private.h index 0ced8c6..415965f 100644 --- a/isl_map_private.h +++ b/isl_map_private.h @@ -114,6 +114,8 @@ unsigned isl_basic_map_offset(struct isl_basic_map *bmap, unsigned isl_basic_set_offset(struct isl_basic_set *bset, enum isl_dim_type type); +int isl_basic_map_may_be_set(__isl_keep isl_basic_map *bmap); +int isl_map_may_be_set(__isl_keep isl_map *map); int isl_map_compatible_domain(struct isl_map *map, struct isl_set *set); int isl_basic_map_compatible_domain(struct isl_basic_map *bmap, struct isl_basic_set *bset); -- 2.7.4