From bf6b6b752381a58b0b9017f0e573b8d838a54339 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 6 May 2011 15:15:00 +0200 Subject: [PATCH] add isl_map_align_params Signed-off-by: Sven Verdoolaege --- doc/user.pod | 18 +++++++++++++++++- include/isl/map.h | 3 +++ include/isl/set.h | 3 +++ isl_dim.c | 18 ++++++++++++++++++ isl_dim_private.h | 1 + isl_map.c | 41 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 83 insertions(+), 1 deletion(-) diff --git a/doc/user.pod b/doc/user.pod index c7639f4..0b2f37d 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -1613,6 +1613,20 @@ existentially quantified variables. Given a relation with nested relations for domain and range, interchange the range of the domain with the domain of the range. +=item * Aligning parameters + + __isl_give isl_set *isl_set_align_params( + __isl_take isl_set *set, + __isl_take isl_dim *model); + __isl_give isl_map *isl_map_align_params( + __isl_take isl_map *map, + __isl_take isl_dim *model); + +Change the order of the parameters of the given set or relation +such that the first parameters match those of C. +This may involve the introduction of extra parameters. +All parameters need to be named. + =item * Dimension manipulation __isl_give isl_set *isl_set_add_dims( @@ -1625,7 +1639,9 @@ interchange the range of the domain with the domain of the range. It is usually not advisable to directly change the (input or output) space of a set or a relation as this removes the name and the internal structure of the space. However, the above functions can be useful -to add new parameters. +to add new parameters, assuming +C and C +are not sufficient. =back diff --git a/include/isl/map.h b/include/isl/map.h index 7c0bce1..7802f4e 100644 --- a/include/isl/map.h +++ b/include/isl/map.h @@ -438,6 +438,9 @@ __isl_give isl_map *isl_map_lex_ge_map(__isl_take isl_map *map1, __isl_give isl_map *isl_map_lex_gt_map(__isl_take isl_map *map1, __isl_take isl_map *map2); +__isl_give isl_map *isl_map_align_params(__isl_take isl_map *map, + __isl_take isl_dim *model); + __isl_give isl_mat *isl_basic_map_equalities_matrix( __isl_keep isl_basic_map *bmap, enum isl_dim_type c1, enum isl_dim_type c2, enum isl_dim_type c3, diff --git a/include/isl/set.h b/include/isl/set.h index 5d3955d..7f9402a 100644 --- a/include/isl/set.h +++ b/include/isl/set.h @@ -353,6 +353,9 @@ __isl_give isl_map *isl_set_lex_gt_set(__isl_take isl_set *set1, int isl_set_size(__isl_keep isl_set *set); +__isl_give isl_set *isl_set_align_params(__isl_take isl_set *set, + __isl_take isl_dim *model); + __isl_give isl_mat *isl_basic_set_equalities_matrix( __isl_keep isl_basic_set *bset, enum isl_dim_type c1, enum isl_dim_type c2, enum isl_dim_type c3, enum isl_dim_type c4); diff --git a/isl_dim.c b/isl_dim.c index 841b291..30825ed 100644 --- a/isl_dim.c +++ b/isl_dim.c @@ -1249,3 +1249,21 @@ error: isl_dim_free(dim); return NULL; } + +int isl_dim_has_named_params(__isl_keep isl_dim *dim) +{ + int i; + unsigned off; + + if (!dim) + return -1; + if (dim->nparam == 0) + return 1; + off = isl_dim_offset(dim, isl_dim_param); + if (off + dim->nparam > dim->n_name) + return 0; + for (i = 0; i < dim->nparam; ++i) + if (!dim->names[off + i]) + return 0; + return 1; +} diff --git a/isl_dim_private.h b/isl_dim_private.h index a8c6007..f150ef0 100644 --- a/isl_dim_private.h +++ b/isl_dim_private.h @@ -25,6 +25,7 @@ __isl_give isl_dim *isl_dim_as_set_dim(__isl_take isl_dim *dim); unsigned isl_dim_offset(__isl_keep isl_dim *dim, enum isl_dim_type type); int isl_dim_is_named_or_nested(__isl_keep isl_dim *dim, enum isl_dim_type type); +int isl_dim_has_named_params(__isl_keep isl_dim *dim); __isl_give isl_dim *isl_dim_reset(__isl_take isl_dim *dim, enum isl_dim_type type); __isl_give isl_dim *isl_dim_flatten(__isl_take isl_dim *dim); diff --git a/isl_map.c b/isl_map.c index c606d13..70af1c8 100644 --- a/isl_map.c +++ b/isl_map.c @@ -8273,6 +8273,47 @@ __isl_give isl_set *isl_set_realign(__isl_take isl_set *set, return (isl_set *)isl_map_realign((isl_map *)set, r); } +__isl_give isl_map *isl_map_align_params(__isl_take isl_map *map, + __isl_take isl_dim *model) +{ + isl_ctx *ctx; + + if (!map || !model) + goto error; + + ctx = isl_dim_get_ctx(model); + if (!isl_dim_has_named_params(model)) + isl_die(ctx, isl_error_invalid, + "model has unnamed parameters", goto error); + if (!isl_dim_has_named_params(map->dim)) + isl_die(ctx, isl_error_invalid, + "relation has unnamed parameters", goto error); + if (!isl_dim_match(map->dim, isl_dim_param, model, isl_dim_param)) { + isl_reordering *exp; + + model = isl_dim_drop(model, isl_dim_in, + 0, isl_dim_size(model, isl_dim_in)); + model = isl_dim_drop(model, isl_dim_out, + 0, isl_dim_size(model, isl_dim_out)); + exp = isl_parameter_alignment_reordering(map->dim, model); + exp = isl_reordering_extend_dim(exp, isl_map_get_dim(map)); + map = isl_map_realign(map, exp); + } + + isl_dim_free(model); + return map; +error: + isl_dim_free(model); + isl_map_free(map); + return NULL; +} + +__isl_give isl_set *isl_set_align_params(__isl_take isl_set *set, + __isl_take isl_dim *model) +{ + return isl_map_align_params(set, model); +} + __isl_give isl_mat *isl_basic_map_equalities_matrix( __isl_keep isl_basic_map *bmap, enum isl_dim_type c1, enum isl_dim_type c2, enum isl_dim_type c3, -- 2.7.4