From 5be958ad278ceb11a2fb61964c8026f611f53837 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 26 Sep 2008 11:49:56 +0200 Subject: [PATCH] add isl_map_remove_inputs --- include/isl_map.h | 2 ++ isl_map.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/include/isl_map.h b/include/isl_map.h index 43ca895..aea9090 100644 --- a/include/isl_map.h +++ b/include/isl_map.h @@ -196,6 +196,8 @@ struct isl_basic_set *isl_basic_map_deltas(struct isl_basic_map *bmap); struct isl_set *isl_map_deltas(struct isl_map *map); struct isl_set *isl_map_range(struct isl_map *map); struct isl_basic_map *isl_map_affine_hull(struct isl_map *map); +struct isl_map *isl_map_remove_inputs(struct isl_map *map, + unsigned first, unsigned n); struct isl_set *isl_map_domain(struct isl_map *bmap); struct isl_map *isl_map_from_basic_map(struct isl_basic_map *bmap); diff --git a/isl_map.c b/isl_map.c index f405b96..b339455 100644 --- a/isl_map.c +++ b/isl_map.c @@ -657,6 +657,7 @@ struct isl_basic_set *isl_basic_set_drop_dims( bset->dim -= n; bset->extra += n; + bset = isl_basic_set_simplify(bset); return isl_basic_set_finalize(bset); error: isl_basic_set_free(bset); @@ -692,6 +693,74 @@ error: return NULL; } +struct isl_basic_map *isl_basic_map_drop_inputs( + struct isl_basic_map *bmap, unsigned first, unsigned n) +{ + int i; + + if (!bmap) + goto error; + + isl_assert(bmap->ctx, first + n <= bmap->n_in, goto error); + + if (n == 0) + return bmap; + + bmap = isl_basic_map_cow(bmap); + if (!bmap) + return NULL; + + for (i = 0; i < bmap->n_eq; ++i) + constraint_drop_vars(bmap->eq[i]+1+bmap->nparam+first, n, + (bmap->n_in-first-n)+bmap->n_out+bmap->extra); + + for (i = 0; i < bmap->n_ineq; ++i) + constraint_drop_vars(bmap->ineq[i]+1+bmap->nparam+first, n, + (bmap->n_in-first-n)+bmap->n_out+bmap->extra); + + for (i = 0; i < bmap->n_div; ++i) + constraint_drop_vars(bmap->div[i]+1+1+bmap->nparam+first, n, + (bmap->n_in-first-n)+bmap->n_out+bmap->extra); + + bmap->n_in -= n; + bmap->extra += n; + + bmap = isl_basic_map_simplify(bmap); + return isl_basic_map_finalize(bmap); +error: + isl_basic_map_free(bmap); + return NULL; +} + +static struct isl_map *isl_map_drop_inputs( + struct isl_map *map, unsigned first, unsigned n) +{ + int i; + + if (!map) + goto error; + + isl_assert(map->ctx, first + n <= map->n_in, goto error); + + if (n == 0) + return map; + map = isl_map_cow(map); + if (!map) + goto error; + + for (i = 0; i < map->n; ++i) { + map->p[i] = isl_basic_map_drop_inputs(map->p[i], first, n); + if (!map->p[i]) + goto error; + } + map->n_in -= n; + + return map; +error: + isl_map_free(map); + return NULL; +} + /* * We don't cow, as the div is assumed to be redundant. */ @@ -1276,6 +1345,33 @@ error: return NULL; } +/* Project out n inputs starting at first using Fourier-Motzkin */ +struct isl_map *isl_map_remove_inputs(struct isl_map *map, + unsigned first, unsigned n) +{ + int i; + + if (n == 0) + return map; + + map = isl_map_cow(map); + if (!map) + return NULL; + isl_assert(map->ctx, first+n <= map->n_in, goto error); + + for (i = 0; i < map->n; ++i) { + map->p[i] = isl_basic_map_eliminate_vars(map->p[i], + map->nparam + first, n); + if (!map->p[i]) + goto error; + } + map = isl_map_drop_inputs(map, first, n); + return map; +error: + isl_map_free(map); + return NULL; +} + /* Project out n dimensions starting at first using Fourier-Motzkin */ struct isl_basic_set *isl_basic_set_remove_dims(struct isl_basic_set *bset, unsigned first, unsigned n) -- 2.7.4