From 1ee9b728532426ee40bdf725ba02a9d6f0284482 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 12 Jun 2011 12:14:51 +0200 Subject: [PATCH] add isl_basic_map_from_aff and isl_basic_map_from_aff_list Signed-off-by: Sven Verdoolaege --- doc/user.pod | 13 ++++++++++ include/isl/map.h | 6 +++++ isl_map.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) diff --git a/doc/user.pod b/doc/user.pod index 15e14a1..6456461 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -1015,6 +1015,19 @@ C and C for sets and of C, C, C, C and C for relations. +A basic relation can also be constructed from an affine expression +or a list of affine expressions (See L<"Quasi Affine Expressions">). + + __isl_give isl_basic_map *isl_basic_map_from_aff( + __isl_take isl_aff *aff); + __isl_give isl_basic_map *isl_basic_map_from_aff_list( + __isl_take isl_dim *domain_dim, + __isl_take isl_aff_list *list); + +The C argument describes the domain of the resulting +basic relation. It is required because the C may consist +of zero affine expressions. + =head2 Inspecting Sets and Relations Usually, the user should not have to care about the actual constraints diff --git a/include/isl/map.h b/include/isl/map.h index d0ce21a..7c37ec5 100644 --- a/include/isl/map.h +++ b/include/isl/map.h @@ -21,6 +21,8 @@ #include #include #include +#include +#include #if defined(__cplusplus) extern "C" { @@ -466,6 +468,10 @@ __isl_give isl_basic_map *isl_basic_map_from_constraint_matrices( enum isl_dim_type c2, enum isl_dim_type c3, enum isl_dim_type c4, enum isl_dim_type c5); +__isl_give isl_basic_map *isl_basic_map_from_aff(__isl_take isl_aff *aff); +__isl_give isl_basic_map *isl_basic_map_from_aff_list( + __isl_take isl_dim *domain_dim, __isl_take isl_aff_list *list); + #if defined(__cplusplus) } #endif diff --git a/isl_map.c b/isl_map.c index e31c70d..706d0ec 100644 --- a/isl_map.c +++ b/isl_map.c @@ -29,6 +29,7 @@ #include #include #include +#include static unsigned n(struct isl_dim *dim, enum isl_dim_type type) { @@ -8733,3 +8734,74 @@ error: isl_map_free(map); return NULL; } + +/* Construct a basic map mapping the domain of the affine expression + * to a one-dimensional range prescribed by the affine expression. + */ +__isl_give isl_basic_map *isl_basic_map_from_aff(__isl_take isl_aff *aff) +{ + int k; + int pos; + isl_local_space *ls; + isl_basic_map *bmap; + + if (!aff) + return NULL; + + ls = isl_aff_get_local_space(aff); + ls = isl_local_space_from_domain(ls); + ls = isl_local_space_add_dim(ls, isl_dim_out, 1); + bmap = isl_basic_map_from_local_space(ls); + bmap = isl_basic_map_extend_constraints(bmap, 1, 0); + k = isl_basic_map_alloc_equality(bmap); + if (k < 0) + goto error; + + pos = isl_basic_map_offset(bmap, isl_dim_out); + isl_seq_cpy(bmap->eq[k], aff->v->el + 1, pos); + isl_int_neg(bmap->eq[k][pos], aff->v->el[0]); + isl_seq_cpy(bmap->eq[k] + pos + 1, aff->v->el + 1 + pos, + aff->v->size - (pos + 1)); + + isl_aff_free(aff); + bmap = isl_basic_map_finalize(bmap); + return bmap; +error: + isl_aff_free(aff); + isl_basic_map_free(bmap); + return NULL; +} + +/* Construct a basic map mapping a domain in the given space to + * to an n-dimensional range, with n the number of elements in the list, + * where each coordinate in the range is prescribed by the + * corresponding affine expression. + * The domains of all affine expressions in the list are assumed to match + * domain_dim. + */ +__isl_give isl_basic_map *isl_basic_map_from_aff_list( + __isl_take isl_dim *domain_dim, __isl_take isl_aff_list *list) +{ + int i; + isl_dim *dim; + isl_basic_map *bmap; + + if (!list) + return NULL; + + dim = isl_dim_from_domain(domain_dim); + bmap = isl_basic_map_universe(dim); + + for (i = 0; i < list->n; ++i) { + isl_aff *aff; + isl_basic_map *bmap_i; + + aff = isl_aff_copy(list->p[i]); + bmap_i = isl_basic_map_from_aff(aff); + + bmap = isl_basic_map_flat_range_product(bmap, bmap_i); + } + + isl_aff_list_free(list); + return bmap; +} -- 2.7.4