From 91f0376fe758d2921854d2e9863599426dfc4fce Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 3 Dec 2013 13:25:44 +0100 Subject: [PATCH] add isl_union_map_project_out Signed-off-by: Sven Verdoolaege --- doc/user.pod | 6 ++++++ include/isl/union_map.h | 4 ++++ isl_union_map.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/doc/user.pod b/doc/user.pod index ce7f45a6..cd2bb5f8 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -2220,6 +2220,9 @@ change over different versions of C. __isl_take isl_union_set *uset); #include + __isl_give isl_union_map *isl_union_map_project_out( + __isl_take isl_union_map *umap, + enum isl_dim_type type, unsigned first, unsigned n); __isl_give isl_set *isl_union_map_params( __isl_take isl_union_map *umap); __isl_give isl_union_set *isl_union_map_domain( @@ -2227,6 +2230,9 @@ change over different versions of C. __isl_give isl_union_set *isl_union_map_range( __isl_take isl_union_map *umap); +The function C can only project out +parameters. + #include __isl_give isl_basic_map *isl_basic_map_domain_map( __isl_take isl_basic_map *bmap); diff --git a/include/isl/union_map.h b/include/isl/union_map.h index feaaf2fb..61611f64 100644 --- a/include/isl/union_map.h +++ b/include/isl/union_map.h @@ -144,6 +144,10 @@ __isl_give isl_union_map *isl_union_map_deltas_map( __isl_export __isl_give isl_union_map *isl_union_set_identity(__isl_take isl_union_set *uset); +__isl_give isl_union_map *isl_union_map_project_out( + __isl_take isl_union_map *umap, + enum isl_dim_type type, unsigned first, unsigned n); + __isl_export int isl_union_map_is_empty(__isl_keep isl_union_map *umap); __isl_export diff --git a/isl_union_map.c b/isl_union_map.c index 0047a5b5..bd229038 100644 --- a/isl_union_map.c +++ b/isl_union_map.c @@ -2984,3 +2984,60 @@ __isl_give isl_union_set *isl_union_set_reset_user( { return isl_union_map_reset_user(uset); } + +/* Internal data structure for isl_union_map_project_out. + * "type", "first" and "n" are the arguments for the isl_map_project_out + * call. + * "res" collects the results. + */ +struct isl_union_map_project_out_data { + enum isl_dim_type type; + unsigned first; + unsigned n; + + isl_union_map *res; +}; + +/* Turn the data->n dimensions of type data->type, starting at data->first + * into existentially quantified variables and add the result to data->res. + */ +static int project_out(__isl_take isl_map *map, void *user) +{ + struct isl_union_map_project_out_data *data = user; + + map = isl_map_project_out(map, data->type, data->first, data->n); + data->res = isl_union_map_add_map(data->res, map); + + return 0; +} + +/* Turn the "n" dimensions of type "type", starting at "first" + * into existentially quantified variables. + * Since the space of an isl_union_map only contains parameters, + * type is required to be equal to isl_dim_param. + */ +__isl_give isl_union_map *isl_union_map_project_out( + __isl_take isl_union_map *umap, + enum isl_dim_type type, unsigned first, unsigned n) +{ + isl_space *space; + struct isl_union_map_project_out_data data = { type, first, n }; + + if (!umap) + return NULL; + + if (type != isl_dim_param) + isl_die(isl_union_map_get_ctx(umap), isl_error_invalid, + "can only project out parameters", + return isl_union_map_free(umap)); + + space = isl_union_map_get_space(umap); + space = isl_space_drop_dims(space, type, first, n); + data.res = isl_union_map_empty(space); + if (isl_union_map_foreach_map(umap, &project_out, &data) < 0) + data.res = isl_union_map_free(data.res); + + isl_union_map_free(umap); + + return data.res; +} -- 2.11.4.GIT