From 255383228e7276889e2b90fd3fef61466d4c7704 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 16 Mar 2010 12:47:28 +0100 Subject: [PATCH] add isl_map_insert --- include/isl_dim.h | 2 ++ include/isl_map.h | 2 ++ isl_dim.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ isl_map.c | 56 +++++++++++++++++++++++++++++++++++++++---------------- 4 files changed, 97 insertions(+), 16 deletions(-) diff --git a/include/isl_dim.h b/include/isl_dim.h index b602296..4961199 100644 --- a/include/isl_dim.h +++ b/include/isl_dim.h @@ -58,6 +58,8 @@ struct isl_dim *isl_dim_extend(struct isl_dim *dim, unsigned nparam, unsigned n_in, unsigned n_out); struct isl_dim *isl_dim_add(struct isl_dim *dim, enum isl_dim_type type, unsigned n); +__isl_give isl_dim *isl_dim_insert(__isl_take isl_dim *dim, + enum isl_dim_type type, unsigned pos, unsigned n); struct isl_dim *isl_dim_join(struct isl_dim *left, struct isl_dim *right); struct isl_dim *isl_dim_product(struct isl_dim *left, struct isl_dim *right); struct isl_dim *isl_dim_map(struct isl_dim *dim); diff --git a/include/isl_map.h b/include/isl_map.h index 986e2d7..53ae6d0 100644 --- a/include/isl_map.h +++ b/include/isl_map.h @@ -317,6 +317,8 @@ __isl_give isl_basic_map *isl_basic_map_add(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned n); __isl_give isl_map *isl_map_add(__isl_take isl_map *map, enum isl_dim_type type, unsigned n); +__isl_give isl_map *isl_map_insert(__isl_take isl_map *map, + enum isl_dim_type type, unsigned pos, unsigned n); __isl_give isl_map *isl_map_move(__isl_take isl_map *map, enum isl_dim_type dst_type, unsigned dst_pos, enum isl_dim_type src_type, unsigned src_pos, unsigned n); diff --git a/isl_dim.c b/isl_dim.c index c364c8b..13a68b8 100644 --- a/isl_dim.c +++ b/isl_dim.c @@ -344,6 +344,59 @@ struct isl_dim *isl_dim_add(struct isl_dim *dim, enum isl_dim_type type, return dim; } +__isl_give isl_dim *isl_dim_insert(__isl_take isl_dim *dim, + enum isl_dim_type type, unsigned pos, unsigned n) +{ + struct isl_name **names = NULL; + + if (!dim) + return NULL; + if (n == 0) + return dim; + + isl_assert(dim->ctx, pos <= isl_dim_size(dim, type), goto error); + + dim = isl_dim_cow(dim); + + if (dim->names) { + enum isl_dim_type t; + int off; + int size[3]; + names = isl_calloc_array(dim->ctx, struct isl_name *, + dim->nparam + dim->n_in + dim->n_out + n); + if (!names) + goto error; + off = 0; + size[isl_dim_param] = dim->nparam; + size[isl_dim_in] = dim->n_in; + size[isl_dim_out] = dim->n_out; + for (t = isl_dim_param; t <= isl_dim_out; ++t) { + if (t != type) { + get_names(dim, t, 0, size[t], names + off); + off += size[t]; + } else { + get_names(dim, t, 0, pos, names + off); + off += pos + n; + get_names(dim, t, pos, size[t]-pos, names+off); + off += size[t] - pos; + } + } + free(dim->names); + dim->names = names; + dim->n_name = dim->nparam + dim->n_in + dim->n_out + n; + } + switch (type) { + case isl_dim_param: dim->nparam += n; break; + case isl_dim_in: dim->n_in += n; break; + case isl_dim_out: dim->n_out += n; break; + } + + return dim; +error: + isl_dim_free(dim); + return NULL; +} + __isl_give isl_dim *isl_dim_move(__isl_take isl_dim *dim, enum isl_dim_type dst_type, unsigned dst_pos, enum isl_dim_type src_type, unsigned src_pos, unsigned n) diff --git a/isl_map.c b/isl_map.c index 4f818bf..b99c2f9 100644 --- a/isl_map.c +++ b/isl_map.c @@ -1990,13 +1990,14 @@ struct isl_basic_map *isl_basic_map_reverse(struct isl_basic_map *bmap) return isl_basic_map_from_basic_set(bset, dim); } -__isl_give isl_basic_map *isl_basic_map_add(__isl_take isl_basic_map *bmap, - enum isl_dim_type type, unsigned n) +__isl_give isl_basic_map *isl_basic_map_insert(__isl_take isl_basic_map *bmap, + enum isl_dim_type type, unsigned pos, unsigned n) { struct isl_dim *res_dim; struct isl_basic_map *res; struct isl_dim_map *dim_map; - unsigned total, pos; + unsigned total, off; + enum isl_dim_type t; if (n == 0) return bmap; @@ -2004,18 +2005,24 @@ __isl_give isl_basic_map *isl_basic_map_add(__isl_take isl_basic_map *bmap, if (!bmap) return NULL; - res_dim = isl_dim_add(isl_basic_map_get_dim(bmap), type, n); + res_dim = isl_dim_insert(isl_basic_map_get_dim(bmap), type, pos, n); total = isl_basic_map_total_dim(bmap) + n; dim_map = isl_dim_map_alloc(bmap->ctx, total); - pos = 0; - isl_dim_map_dim(dim_map, bmap->dim, isl_dim_param, pos); - pos += isl_dim_size(res_dim, isl_dim_param); - isl_dim_map_dim(dim_map, bmap->dim, isl_dim_in, pos); - pos += isl_dim_size(res_dim, isl_dim_in); - isl_dim_map_dim(dim_map, bmap->dim, isl_dim_out, pos); - pos += isl_dim_size(res_dim, isl_dim_out); - isl_dim_map_div(dim_map, bmap, pos); + off = 0; + for (t = isl_dim_param; t <= isl_dim_out; ++t) { + if (t != type) { + isl_dim_map_dim(dim_map, bmap->dim, t, off); + } else { + unsigned size = isl_basic_map_dim(bmap, t); + isl_dim_map_dim_range(dim_map, bmap->dim, t, + 0, pos, off); + isl_dim_map_dim_range(dim_map, bmap->dim, t, + pos, size - pos, off + pos + n); + } + off += isl_dim_size(res_dim, t); + } + isl_dim_map_div(dim_map, bmap, off); res = isl_basic_map_alloc_dim(res_dim, bmap->n_div, bmap->n_eq, bmap->n_ineq); @@ -2024,6 +2031,15 @@ __isl_give isl_basic_map *isl_basic_map_add(__isl_take isl_basic_map *bmap, return isl_basic_map_finalize(res); } +__isl_give isl_basic_map *isl_basic_map_add(__isl_take isl_basic_map *bmap, + enum isl_dim_type type, unsigned n) +{ + if (!bmap) + return NULL; + return isl_basic_map_insert(bmap, type, + isl_basic_map_dim(bmap, type), n); +} + __isl_give isl_basic_set *isl_basic_set_add(__isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned n) { @@ -2036,8 +2052,8 @@ error: return NULL; } -__isl_give isl_map *isl_map_add(__isl_take isl_map *map, - enum isl_dim_type type, unsigned n) +__isl_give isl_map *isl_map_insert(__isl_take isl_map *map, + enum isl_dim_type type, unsigned pos, unsigned n) { int i; @@ -2048,12 +2064,12 @@ __isl_give isl_map *isl_map_add(__isl_take isl_map *map, if (!map) return NULL; - map->dim = isl_dim_add(map->dim, type, n); + map->dim = isl_dim_insert(map->dim, type, pos, n); if (!map->dim) goto error; for (i = 0; i < map->n; ++i) { - map->p[i] = isl_basic_map_add(map->p[i], type, n); + map->p[i] = isl_basic_map_insert(map->p[i], type, pos, n); if (!map->p[i]) goto error; } @@ -2064,6 +2080,14 @@ error: return NULL; } +__isl_give isl_map *isl_map_add(__isl_take isl_map *map, + enum isl_dim_type type, unsigned n) +{ + if (!map) + return NULL; + return isl_map_insert(map, type, isl_map_dim(map, type), n); +} + __isl_give isl_set *isl_set_add(__isl_take isl_set *set, enum isl_dim_type type, unsigned n) { -- 2.7.4