From aed62aeb62d864a349551712b0e10a759356ff68 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 25 Aug 2012 10:37:02 +0200 Subject: [PATCH] add isl_aff_var_on_domain Signed-off-by: Sven Verdoolaege --- doc/user.pod | 8 ++++++-- include/isl/aff.h | 2 ++ isl_aff.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/doc/user.pod b/doc/user.pod index d696d9f..0d6e1a0 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -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) diff --git a/include/isl/aff.h b/include/isl/aff.h index 81d1369..2ae0710 100644 --- a/include/isl/aff.h +++ b/include/isl/aff.h @@ -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); diff --git a/isl_aff.c b/isl_aff.c index 4d6a314..7017391 100644 --- 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) -- 2.7.4