add isl_basic_map_order_ge
[platform/upstream/isl.git] / isl_map.c
index 56b99d8..9a5f5ea 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -3,7 +3,7 @@
  * Copyright 2010      INRIA Saclay
  * Copyright 2012      Ecole Normale Superieure
  *
- * Use of this software is governed by the GNU LGPLv2.1 license
+ * Use of this software is governed by the MIT license
  *
  * Written by Sven Verdoolaege, K.U.Leuven, Departement
  * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
@@ -926,13 +926,13 @@ struct isl_map *isl_map_copy(struct isl_map *map)
        return map;
 }
 
-void isl_basic_map_free(struct isl_basic_map *bmap)
+void *isl_basic_map_free(__isl_take isl_basic_map *bmap)
 {
        if (!bmap)
-               return;
+               return NULL;
 
        if (--bmap->ref > 0)
-               return;
+               return NULL;
 
        isl_ctx_deref(bmap->ctx);
        free(bmap->div);
@@ -942,11 +942,13 @@ void isl_basic_map_free(struct isl_basic_map *bmap)
        isl_vec_free(bmap->sample);
        isl_space_free(bmap->dim);
        free(bmap);
+
+       return NULL;
 }
 
-void isl_basic_set_free(struct isl_basic_set *bset)
+void *isl_basic_set_free(struct isl_basic_set *bset)
 {
-       isl_basic_map_free((struct isl_basic_map *)bset);
+       return isl_basic_map_free((struct isl_basic_map *)bset);
 }
 
 static int room_for_con(struct isl_basic_map *bmap, unsigned n)
@@ -2821,10 +2823,9 @@ static __isl_give isl_map *map_intersect_internal(__isl_take isl_map *map1,
                        part = isl_basic_map_intersect(
                                    isl_basic_map_copy(map1->p[i]),
                                    isl_basic_map_copy(map2->p[j]));
-                       if (isl_basic_map_is_empty(part))
-                               isl_basic_map_free(part);
-                       else
-                               result = isl_map_add_basic_map(result, part);
+                       if (isl_basic_map_is_empty(part) < 0)
+                               goto error;
+                       result = isl_map_add_basic_map(result, part);
                        if (!result)
                                goto error;
                }
@@ -5058,21 +5059,23 @@ error:
        return NULL;
 }
 
-void isl_map_free(struct isl_map *map)
+void *isl_map_free(struct isl_map *map)
 {
        int i;
 
        if (!map)
-               return;
+               return NULL;
 
        if (--map->ref > 0)
-               return;
+               return NULL;
 
        isl_ctx_deref(map->ctx);
        for (i = 0; i < map->n; ++i)
                isl_basic_map_free(map->p[i]);
        isl_space_free(map->dim);
        free(map);
+
+       return NULL;
 }
 
 struct isl_map *isl_map_extend(struct isl_map *base,
@@ -6784,7 +6787,7 @@ error:
        return NULL;
 }
 
-__isl_give struct isl_basic_map *basic_map_identity(__isl_take isl_space *dims)
+static __isl_give isl_basic_map *basic_map_identity(__isl_take isl_space *dims)
 {
        struct isl_basic_map *bmap;
        unsigned nparam;
@@ -9037,7 +9040,7 @@ int isl_set_dim_is_bounded(__isl_keep isl_set *set,
        return isl_map_dim_is_bounded((isl_map *)set, type, pos);
 }
 
-static int has_bound(__isl_keep isl_map *map,
+static int has_any_bound(__isl_keep isl_map *map,
        enum isl_dim_type type, unsigned pos,
        int (*fn)(__isl_keep isl_basic_map *bmap,
                  enum isl_dim_type type, unsigned pos))
@@ -9059,18 +9062,20 @@ static int has_bound(__isl_keep isl_map *map,
 
 /* Return 1 if the specified dim is involved in any lower bound.
  */
-int isl_set_dim_has_lower_bound(__isl_keep isl_set *set,
+int isl_set_dim_has_any_lower_bound(__isl_keep isl_set *set,
        enum isl_dim_type type, unsigned pos)
 {
-       return has_bound(set, type, pos, &isl_basic_map_dim_has_lower_bound);
+       return has_any_bound(set, type, pos,
+                               &isl_basic_map_dim_has_lower_bound);
 }
 
 /* Return 1 if the specified dim is involved in any upper bound.
  */
-int isl_set_dim_has_upper_bound(__isl_keep isl_set *set,
+int isl_set_dim_has_any_upper_bound(__isl_keep isl_set *set,
        enum isl_dim_type type, unsigned pos)
 {
-       return has_bound(set, type, pos, &isl_basic_map_dim_has_upper_bound);
+       return has_any_bound(set, type, pos,
+                               &isl_basic_map_dim_has_upper_bound);
 }
 
 /* For each of the "n" variables starting at "first", determine
@@ -10453,6 +10458,37 @@ error:
 }
 
 /* Add a constraint imposing that the value of the first dimension is
+ * greater than or equal to that of the second.
+ */
+__isl_give isl_basic_map *isl_basic_map_order_ge(__isl_take isl_basic_map *bmap,
+       enum isl_dim_type type1, int pos1, enum isl_dim_type type2, int pos2)
+{
+       isl_constraint *c;
+       isl_local_space *ls;
+
+       if (!bmap)
+               return NULL;
+
+       if (pos1 >= isl_basic_map_dim(bmap, type1))
+               isl_die(bmap->ctx, isl_error_invalid,
+                       "index out of bounds", return isl_basic_map_free(bmap));
+       if (pos2 >= isl_basic_map_dim(bmap, type2))
+               isl_die(bmap->ctx, isl_error_invalid,
+                       "index out of bounds", return isl_basic_map_free(bmap));
+
+       if (type1 == type2 && pos1 == pos2)
+               return bmap;
+
+       ls = isl_local_space_from_space(isl_basic_map_get_space(bmap));
+       c = isl_inequality_alloc(ls);
+       c = isl_constraint_set_coefficient_si(c, type1, pos1, 1);
+       c = isl_constraint_set_coefficient_si(c, type2, pos2, -1);
+       bmap = isl_basic_map_add_constraint(bmap, c);
+
+       return bmap;
+}
+
+/* Add a constraint imposing that the value of the first dimension is
  * greater than that of the second.
  */
 __isl_give isl_map *isl_map_order_gt(__isl_take isl_map *map,