add isl_aff_var_on_domain
authorSven Verdoolaege <skimo@kotnet.org>
Sat, 25 Aug 2012 08:37:02 +0000 (10:37 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Mon, 17 Sep 2012 15:15:49 +0000 (17:15 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl/aff.h
isl_aff.c

index d696d9f..0d6e1a0 100644 (file)
@@ -3147,12 +3147,16 @@ the original and the kernel (in that order) is the zero matrix.
 
 =head2 Piecewise Quasi Affine Expressions
 
-The zero quasi affine expression on a given domain can be created using
+The zero quasi affine expression or the quasi affine expression
+that is equal to a specified dimension on a given domain can be created using
 
        __isl_give isl_aff *isl_aff_zero_on_domain(
                __isl_take isl_local_space *ls);
+       __isl_give isl_aff *isl_aff_var_on_domain(
+               __isl_take isl_local_space *ls,
+               enum isl_dim_type type, unsigned pos);
 
-Note that the space in which the resulting object lives is a map space
+Note that the space in which the resulting objects live is a map space
 with the given space as domain and a one-dimensional range.
 
 An empty piecewise quasi affine expression (one with no cells)
index 81d1369..2ae0710 100644 (file)
@@ -14,6 +14,8 @@ extern "C" {
 #endif
 
 __isl_give isl_aff *isl_aff_zero_on_domain(__isl_take isl_local_space *ls);
+__isl_give isl_aff *isl_aff_var_on_domain(__isl_take isl_local_space *ls,
+       enum isl_dim_type type, unsigned pos);
 
 __isl_give isl_aff *isl_aff_copy(__isl_keep isl_aff *aff);
 void *isl_aff_free(__isl_take isl_aff *aff);
index 4d6a314..7017391 100644 (file)
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -88,6 +88,46 @@ __isl_give isl_aff *isl_aff_zero_on_domain(__isl_take isl_local_space *ls)
        return aff;
 }
 
+/* Return an affine expression that is equal to the specified dimension
+ * in "ls".
+ */
+__isl_give isl_aff *isl_aff_var_on_domain(__isl_take isl_local_space *ls,
+       enum isl_dim_type type, unsigned pos)
+{
+       isl_space *space;
+       isl_aff *aff;
+
+       if (!ls)
+               return NULL;
+
+       space = isl_local_space_get_space(ls);
+       if (!space)
+               goto error;
+       if (isl_space_is_map(space))
+               isl_die(isl_space_get_ctx(space), isl_error_invalid,
+                       "expecting (parameter) set space", goto error);
+       if (pos >= isl_local_space_dim(ls, type))
+               isl_die(isl_space_get_ctx(space), isl_error_invalid,
+                       "position out of bounds", goto error);
+
+       isl_space_free(space);
+       aff = isl_aff_alloc(ls);
+       if (!aff)
+               return NULL;
+
+       pos += isl_local_space_offset(aff->ls, type);
+
+       isl_int_set_si(aff->v->el[0], 1);
+       isl_seq_clr(aff->v->el + 1, aff->v->size - 1);
+       isl_int_set_si(aff->v->el[1 + pos], 1);
+
+       return aff;
+error:
+       isl_local_space_free(ls);
+       isl_space_free(space);
+       return NULL;
+}
+
 __isl_give isl_aff *isl_aff_copy(__isl_keep isl_aff *aff)
 {
        if (!aff)