isl_map_affine_hull: detect equalities of integer affine hull before cowing
authorSven Verdoolaege <skimo@kotnet.org>
Tue, 10 Mar 2009 12:45:31 +0000 (13:45 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Fri, 20 Mar 2009 14:21:06 +0000 (15:21 +0100)
include/isl_map.h
isl_affine_hull.c

index 6615dd2..42069ae 100644 (file)
@@ -239,6 +239,7 @@ struct isl_map *isl_map_fix_si(struct isl_map *map,
 struct isl_basic_set *isl_basic_map_deltas(struct isl_basic_map *bmap);
 struct isl_set *isl_map_deltas(struct isl_map *map);
 struct isl_set *isl_map_range(struct isl_map *map);
+struct isl_map *isl_map_detect_equalities(struct isl_map *map);
 struct isl_basic_map *isl_map_affine_hull(struct isl_map *map);
 struct isl_map *isl_map_remove(struct isl_map *map,
        enum isl_dim_type type, unsigned first, unsigned n);
index e3794d1..746a34e 100644 (file)
@@ -394,6 +394,29 @@ error:
        return NULL;
 }
 
+struct isl_map *isl_map_detect_equalities(struct isl_map *map)
+{
+       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 = isl_basic_map_detect_equalities(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;
+}
+
 /* After computing the rational affine hull (by detecting the implicit
  * equalities), we compute the additional equalities satisfied by
  * the integer points (if any) and add the original equalities back in.
@@ -402,35 +425,10 @@ struct isl_basic_map *isl_basic_map_affine_hull(struct isl_basic_map *bmap)
 {
        struct isl_basic_set *hull = NULL;
 
-       bmap = isl_basic_map_implicit_equalities(bmap);
-       if (!bmap)
-               return NULL;
-       if (bmap->n_ineq == 0)
-               return bmap;
-
-       if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL)) {
-               bmap = isl_basic_map_cow(bmap);
-               isl_basic_map_free_inequality(bmap, bmap->n_ineq);
-               return bmap;
-       }
-
-       hull = equalities_in_underlying_set(isl_basic_map_copy(bmap));
-       if (!hull)
-               goto error;
-
+       bmap = isl_basic_map_detect_equalities(bmap);
        bmap = isl_basic_map_cow(bmap);
-       if (!bmap)
-               goto error;
        isl_basic_map_free_inequality(bmap, bmap->n_ineq);
-       bmap = isl_basic_map_intersect(bmap,
-                                       isl_basic_map_overlying_set(hull,
-                                               isl_basic_map_copy(bmap)));
-
-       return isl_basic_map_finalize(bmap);
-error:
-       isl_basic_set_free(hull);
-       isl_basic_map_free(bmap);
-       return NULL;
+       return bmap;
 }
 
 struct isl_basic_set *isl_basic_set_affine_hull(struct isl_basic_set *bset)
@@ -455,7 +453,10 @@ struct isl_basic_map *isl_map_affine_hull(struct isl_map *map)
                return hull;
        }
 
+       map = isl_map_detect_equalities(map);
        map = isl_map_align_divs(map);
+       if (!map)
+               return NULL;
        model = isl_basic_map_copy(map->p[0]);
        set = isl_map_underlying_set(map);
        set = isl_set_cow(set);