proper implementation of isl_union_map_from_range
authorSven Verdoolaege <skimo@kotnet.org>
Sat, 27 Aug 2011 15:41:45 +0000 (17:41 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 3 Sep 2011 19:43:07 +0000 (21:43 +0200)
The original implementation would just return the input
because isl_sets and isl_maps have the same internal representation.
This will change in the near future, however, and so we need
to actually compute the range of all the elements in the input.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_union_map.c

index 082025e..f12fd97 100644 (file)
@@ -988,10 +988,41 @@ __isl_give isl_union_map *isl_union_map_flat_range_product(
        return bin_op(umap1, umap2, &flat_range_product_entry);
 }
 
+static __isl_give isl_union_set *cond_un_op(__isl_take isl_union_map *umap,
+       int (*fn)(void **, void *))
+{
+       isl_union_set *res;
+
+       if (!umap)
+               return NULL;
+
+       res = isl_union_map_alloc(isl_space_copy(umap->dim), umap->table.n);
+       if (isl_hash_table_foreach(umap->dim->ctx, &umap->table, fn, &res) < 0)
+               goto error;
+
+       isl_union_map_free(umap);
+       return res;
+error:
+       isl_union_map_free(umap);
+       isl_union_set_free(res);
+       return NULL;
+}
+
+static int from_range_entry(void **entry, void *user)
+{
+       isl_map *set = *entry;
+       isl_union_set **res = user;
+
+       *res = isl_union_map_add_map(*res,
+                                       isl_map_from_range(isl_set_copy(set)));
+
+       return 0;
+}
+
 __isl_give isl_union_map *isl_union_map_from_range(
        __isl_take isl_union_set *uset)
 {
-       return uset;
+       return cond_un_op(uset, &from_range_entry);
 }
 
 __isl_give isl_union_map *isl_union_map_from_domain(
@@ -1197,26 +1228,6 @@ __isl_give isl_union_set *isl_union_set_lexmax(
        return isl_union_map_lexmax(uset);
 }
 
-static __isl_give isl_union_set *cond_un_op(__isl_take isl_union_map *umap,
-       int (*fn)(void **, void *))
-{
-       isl_union_set *res;
-
-       if (!umap)
-               return NULL;
-
-       res = isl_union_map_alloc(isl_space_copy(umap->dim), umap->table.n);
-       if (isl_hash_table_foreach(umap->dim->ctx, &umap->table, fn, &res) < 0)
-               goto error;
-
-       isl_union_map_free(umap);
-       return res;
-error:
-       isl_union_map_free(umap);
-       isl_union_set_free(res);
-       return NULL;
-}
-
 static int universe_entry(void **entry, void *user)
 {
        isl_map *map = *entry;