add isl_set_dim_has_{lower,upper}_bound
authorSven Verdoolaege <skimo@kotnet.org>
Fri, 29 Jul 2011 09:03:53 +0000 (11:03 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Fri, 29 Jul 2011 09:16:09 +0000 (11:16 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl/set.h
isl_map.c

index a90d8ca..c959e2a 100644 (file)
@@ -1319,6 +1319,14 @@ constraints.  Instead the following functions can be used.
        int isl_map_involves_dims(__isl_keep isl_map *map,
                enum isl_dim_type type, unsigned first, unsigned n);
 
+Similarly, the following functions can be used to check whether
+a given dimension is involved in any lower or upper bound.
+
+       int isl_set_dim_has_lower_bound(__isl_keep isl_set *set,
+               enum isl_dim_type type, unsigned pos);
+       int isl_set_dim_has_upper_bound(__isl_keep isl_set *set,
+               enum isl_dim_type type, unsigned pos);
+
 The identifiers or names of the domain and range spaces of a set
 or relation can be read off or set using the following functions.
 
index c2374d9..9390995 100644 (file)
@@ -326,6 +326,10 @@ int isl_set_plain_dim_has_fixed_lower_bound(__isl_keep isl_set *set,
        unsigned dim, isl_int *val);
 int isl_set_dim_is_bounded(__isl_keep isl_set *set,
        enum isl_dim_type type, unsigned pos);
+int isl_set_dim_has_lower_bound(__isl_keep isl_set *set,
+       enum isl_dim_type type, unsigned pos);
+int isl_set_dim_has_upper_bound(__isl_keep isl_set *set,
+       enum isl_dim_type type, unsigned pos);
 
 __isl_give isl_basic_set *isl_basic_set_gist(__isl_take isl_basic_set *bset,
                                            __isl_take isl_basic_set *context);
index 9171576..1ff2f6b 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -8116,11 +8116,13 @@ int isl_set_size(__isl_keep isl_set *set)
        return size;
 }
 
-int isl_basic_map_dim_is_bounded(__isl_keep isl_basic_map *bmap,
-       enum isl_dim_type type, unsigned pos)
+/* Check if there is any lower bound (if lower == 0) and/or upper
+ * bound (if upper == 0) on the specified dim.
+ */
+static int basic_map_dim_is_bounded(__isl_keep isl_basic_map *bmap,
+       enum isl_dim_type type, unsigned pos, int lower, int upper)
 {
        int i;
-       int lower, upper;
 
        if (!bmap)
                return -1;
@@ -8129,11 +8131,17 @@ int isl_basic_map_dim_is_bounded(__isl_keep isl_basic_map *bmap,
 
        pos += isl_basic_map_offset(bmap, type);
 
+       for (i = 0; i < bmap->n_div; ++i) {
+               if (isl_int_is_zero(bmap->div[i][0]))
+                       continue;
+               if (!isl_int_is_zero(bmap->div[i][1 + pos]))
+                       return 1;
+       }
+
        for (i = 0; i < bmap->n_eq; ++i)
                if (!isl_int_is_zero(bmap->eq[i][pos]))
                        return 1;
 
-       lower = upper = 0;
        for (i = 0; i < bmap->n_ineq; ++i) {
                int sgn = isl_int_sgn(bmap->ineq[i][pos]);
                if (sgn > 0)
@@ -8145,6 +8153,24 @@ int isl_basic_map_dim_is_bounded(__isl_keep isl_basic_map *bmap,
        return lower && upper;
 }
 
+int isl_basic_map_dim_is_bounded(__isl_keep isl_basic_map *bmap,
+       enum isl_dim_type type, unsigned pos)
+{
+       return basic_map_dim_is_bounded(bmap, type, pos, 0, 0);
+}
+
+int isl_basic_map_dim_has_lower_bound(__isl_keep isl_basic_map *bmap,
+       enum isl_dim_type type, unsigned pos)
+{
+       return basic_map_dim_is_bounded(bmap, type, pos, 0, 1);
+}
+
+int isl_basic_map_dim_has_upper_bound(__isl_keep isl_basic_map *bmap,
+       enum isl_dim_type type, unsigned pos)
+{
+       return basic_map_dim_is_bounded(bmap, type, pos, 1, 0);
+}
+
 int isl_map_dim_is_bounded(__isl_keep isl_map *map,
        enum isl_dim_type type, unsigned pos)
 {
@@ -8172,6 +8198,42 @@ 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,
+       enum isl_dim_type type, unsigned pos,
+       int (*fn)(__isl_keep isl_basic_map *bmap,
+                 enum isl_dim_type type, unsigned pos))
+{
+       int i;
+
+       if (!map)
+               return -1;
+
+       for (i = 0; i < map->n; ++i) {
+               int bounded;
+               bounded = fn(map->p[i], type, pos);
+               if (bounded < 0 || bounded)
+                       return bounded;
+       }
+
+       return 0;
+}
+
+/* Return 1 if the specified dim is involved in any lower bound.
+ */
+int isl_set_dim_has_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 1 if the specified dim is involved in any upper bound.
+ */
+int isl_set_dim_has_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);
+}
+
 /* For each of the "n" variables starting at "first", determine
  * the sign of the variable and put the results in the first "n"
  * elements of the array "signs".