add isl_basic_map_equate
authorSven Verdoolaege <skimo@kotnet.org>
Wed, 29 Feb 2012 11:39:01 +0000 (12:39 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Sun, 6 May 2012 12:33:06 +0000 (14:33 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl/map.h
isl_map.c

index 9c09f4f..9926195 100644 (file)
@@ -1949,6 +1949,10 @@ dimension has a value bounded by the fixed given value.
        __isl_give isl_set *isl_set_equate(__isl_take isl_set *set,
                enum isl_dim_type type1, int pos1,
                enum isl_dim_type type2, int pos2);
+       __isl_give isl_basic_map *isl_basic_map_equate(
+               __isl_take isl_basic_map *bmap,
+               enum isl_dim_type type1, int pos1,
+               enum isl_dim_type type2, int pos2);
        __isl_give isl_map *isl_map_equate(__isl_take isl_map *map,
                enum isl_dim_type type1, int pos1,
                enum isl_dim_type type2, int pos2);
index 39578d6..a8c1497 100644 (file)
@@ -415,6 +415,8 @@ __isl_give isl_map *isl_map_remove_dims(__isl_take isl_map *map,
 struct isl_map *isl_map_remove_inputs(struct isl_map *map,
        unsigned first, unsigned n);
 
+__isl_give isl_basic_map *isl_basic_map_equate(__isl_take isl_basic_map *bmap,
+       enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2);
 __isl_give isl_map *isl_map_equate(__isl_take isl_map *map,
        enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2);
 __isl_give isl_map *isl_map_oppose(__isl_take isl_map *map,
index 0e4c6c9..64f27c4 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -10044,25 +10044,25 @@ __isl_give isl_set *isl_set_equate(__isl_take isl_set *set,
        return isl_map_equate(set, type1, pos1, type2, pos2);
 }
 
-/* Add a constraint imposing that the given two dimensions are equal.
+/* Construct a basic map where the given dimensions are equal to each other.
  */
-__isl_give isl_map *isl_map_equate(__isl_take isl_map *map,
+static __isl_give isl_basic_map *equator(__isl_take isl_space *space,
        enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
 {
        isl_basic_map *bmap = NULL;
        int i;
 
-       if (!map)
+       if (!space)
                return NULL;
 
-       if (pos1 >= isl_map_dim(map, type1))
-               isl_die(map->ctx, isl_error_invalid,
+       if (pos1 >= isl_space_dim(space, type1))
+               isl_die(isl_space_get_ctx(space), isl_error_invalid,
                        "index out of bounds", goto error);
-       if (pos2 >= isl_map_dim(map, type2))
-               isl_die(map->ctx, isl_error_invalid,
+       if (pos2 >= isl_space_dim(space, type2))
+               isl_die(isl_space_get_ctx(space), isl_error_invalid,
                        "index out of bounds", goto error);
 
-       bmap = isl_basic_map_alloc_space(isl_map_get_space(map), 0, 1, 0);
+       bmap = isl_basic_map_alloc_space(isl_space_copy(space), 0, 1, 0);
        i = isl_basic_map_alloc_equality(bmap);
        if (i < 0)
                goto error;
@@ -10072,14 +10072,40 @@ __isl_give isl_map *isl_map_equate(__isl_take isl_map *map,
        isl_int_set_si(bmap->eq[i][pos1], -1);
        isl_int_set_si(bmap->eq[i][pos2], 1);
        bmap = isl_basic_map_finalize(bmap);
+       isl_space_free(space);
+       return bmap;
+error:
+       isl_space_free(space);
+       isl_basic_map_free(bmap);
+       return NULL;
+}
+
+/* Add a constraint imposing that the given two dimensions are equal.
+ */
+__isl_give isl_basic_map *isl_basic_map_equate(__isl_take isl_basic_map *bmap,
+       enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
+{
+       isl_basic_map *eq;
+
+       eq = equator(isl_basic_map_get_space(bmap), type1, pos1, type2, pos2);
+
+       bmap = isl_basic_map_intersect(bmap, eq);
+
+       return bmap;
+}
+
+/* Add a constraint imposing that the given two dimensions are equal.
+ */
+__isl_give isl_map *isl_map_equate(__isl_take isl_map *map,
+       enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
+{
+       isl_basic_map *bmap;
+
+       bmap = equator(isl_map_get_space(map), type1, pos1, type2, pos2);
 
        map = isl_map_intersect(map, isl_map_from_basic_map(bmap));
 
        return map;
-error:
-       isl_basic_map_free(bmap);
-       isl_map_free(map);
-       return NULL;
 }
 
 /* Add a constraint imposing that the given two dimensions have opposite values.