add isl_constraint_get_bound
authorSven Verdoolaege <skimo@kotnet.org>
Wed, 11 May 2011 16:26:05 +0000 (18:26 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Mon, 16 May 2011 16:06:05 +0000 (18:06 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl/constraint.h
isl_constraint.c

index a082991..d03bf54 100644 (file)
@@ -2029,6 +2029,15 @@ Quasi affine expressions can be copied and free using
        __isl_give isl_aff *isl_aff_copy(__isl_keep isl_aff *aff);
        void *isl_aff_free(__isl_take isl_aff *aff);
 
+A (rational) bound on a dimension can be extracted from an C<isl_constraint>
+using the following function.  The constraint is required to have
+a non-zero coefficient for the specified dimension.
+
+       #include <isl/constraint.h>
+       __isl_give isl_aff *isl_constraint_get_bound(
+               __isl_keep isl_constraint *constraint,
+               enum isl_dim_type type, int pos);
+
 The expression can be inspected using
 
        #include <isl/aff.h>
index 974c37f..7d20bab 100644 (file)
@@ -10,6 +10,7 @@
 #ifndef ISL_CONSTRAINT_H
 #define ISL_CONSTRAINT_H
 
+#include <isl/aff.h>
 #include <isl/div.h>
 #include <isl/set.h>
 #include <isl/printer.h>
@@ -110,6 +111,9 @@ __isl_give isl_basic_map *isl_basic_map_from_constraint(
 struct isl_basic_set *isl_basic_set_from_constraint(
        struct isl_constraint *constraint);
 
+__isl_give isl_aff *isl_constraint_get_bound(
+       __isl_keep isl_constraint *constraint, enum isl_dim_type type, int pos);
+
 __isl_give isl_printer *isl_printer_print_constraint(__isl_take isl_printer *p,
        __isl_keep isl_constraint *c);
 void isl_constraint_dump(__isl_keep isl_constraint *c);
index 446fb95..ecc1a0d 100644 (file)
@@ -15,6 +15,7 @@
 #include <isl_dim_private.h>
 #include <isl_div_private.h>
 #include <isl/seq.h>
+#include <isl_aff_private.h>
 
 isl_ctx *isl_constraint_get_ctx(__isl_keep isl_constraint *c)
 {
@@ -965,3 +966,41 @@ error:
        isl_basic_set_free(context);
        return -1;
 }
+
+__isl_give isl_aff *isl_constraint_get_bound(
+       __isl_keep isl_constraint *constraint, enum isl_dim_type type, int pos)
+{
+       isl_aff *aff;
+       isl_local_space *ls;
+
+       if (!constraint)
+               return NULL;
+       if (pos >= isl_basic_set_dim(constraint->bmap, type))
+               isl_die(constraint->ctx, isl_error_invalid,
+                       "index out of bounds", return NULL);
+       if (!isl_basic_map_may_be_set(constraint->bmap))
+               isl_die(constraint->ctx, isl_error_invalid,
+                       "not a set constraint", return NULL);
+
+       pos += offset(constraint, type);
+       if (isl_int_is_zero(constraint->line[0][pos]))
+               isl_die(constraint->ctx, isl_error_invalid,
+                       "constraint does not define a bound on given dimension",
+                       return NULL);
+
+       ls = isl_basic_set_get_local_space(constraint->bmap);
+       aff = isl_aff_alloc(ls);
+       if (!aff)
+               return NULL;
+
+       if (isl_int_is_neg(constraint->line[0][pos]))
+               isl_seq_cpy(aff->v->el + 1, constraint->line[0],
+                           aff->v->size - 1);
+       else
+               isl_seq_neg(aff->v->el + 1, constraint->line[0],
+                           aff->v->size - 1);
+       isl_int_set_si(aff->v->el[1 + pos], 0);
+       isl_int_abs(aff->v->el[0], constraint->line[0][pos]);
+
+       return aff;
+}