From: Sven Verdoolaege Date: Fri, 7 Dec 2012 12:20:15 +0000 (+0100) Subject: isl_map_inline_foreach_basic_map: drop basic maps that have become empty X-Git-Tag: isl-0.12~217 X-Git-Url: https://repo.or.cz/w/isl.git/commitdiff_plain/8eb82109cb862a4fdd9d0168c978c9d547c315ba isl_map_inline_foreach_basic_map: drop basic maps that have become empty In particular, drop basic maps that have become empty in isl_map_detect_equalities (which calls isl_map_inline_foreach_basic_map). Signed-off-by: Sven Verdoolaege --- diff --git a/isl_affine_hull.c b/isl_affine_hull.c index e71bc104..edfefe4e 100644 --- a/isl_affine_hull.c +++ b/isl_affine_hull.c @@ -1126,30 +1126,6 @@ __isl_give isl_basic_set *isl_basic_set_detect_equalities( isl_basic_map_detect_equalities((isl_basic_map *)bset); } -__isl_give isl_map *isl_map_inline_foreach_basic_map(__isl_take isl_map *map, - __isl_give isl_basic_map *(*fn)(__isl_take isl_basic_map *bmap)) -{ - struct isl_basic_map *bmap; - int i; - - if (!map) - return NULL; - - for (i = 0; i < map->n; ++i) { - bmap = isl_basic_map_copy(map->p[i]); - bmap = fn(bmap); - if (!bmap) - goto error; - isl_basic_map_free(map->p[i]); - map->p[i] = bmap; - } - - return map; -error: - isl_map_free(map); - return NULL; -} - __isl_give isl_map *isl_map_detect_equalities(__isl_take isl_map *map) { return isl_map_inline_foreach_basic_map(map, diff --git a/isl_map.c b/isl_map.c index 51a8600b..b0554cff 100644 --- a/isl_map.c +++ b/isl_map.c @@ -5331,6 +5331,39 @@ static int remove_if_empty(__isl_keep isl_map *map, int i) return 0; } +/* Perform "fn" on each basic map of "map", where we may not be holding + * the only reference to "map". + * In particular, "fn" should be a semantics preserving operation + * that we want to apply to all copies of "map". We therefore need + * to be careful not to modify "map" in a way that breaks "map" + * in case anything goes wrong. + */ +__isl_give isl_map *isl_map_inline_foreach_basic_map(__isl_take isl_map *map, + __isl_give isl_basic_map *(*fn)(__isl_take isl_basic_map *bmap)) +{ + struct isl_basic_map *bmap; + int i; + + if (!map) + return NULL; + + for (i = map->n - 1; i >= 0; --i) { + bmap = isl_basic_map_copy(map->p[i]); + bmap = fn(bmap); + if (!bmap) + goto error; + isl_basic_map_free(map->p[i]); + map->p[i] = bmap; + if (remove_if_empty(map, i) < 0) + goto error; + } + + return map; +error: + isl_map_free(map); + return NULL; +} + struct isl_map *isl_map_fix_si(struct isl_map *map, enum isl_dim_type type, unsigned pos, int value) {