From: Sven Verdoolaege Date: Wed, 30 Sep 2009 19:17:11 +0000 (+0200) Subject: add isl_set_lifting X-Git-Tag: isl-0.02~283 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7280665c102d3a8443728485da9edb9a7ac4f2f4;p=platform%2Fupstream%2Fisl.git add isl_set_lifting --- diff --git a/include/isl_map.h b/include/isl_map.h index 887393c..636e593 100644 --- a/include/isl_map.h +++ b/include/isl_map.h @@ -307,6 +307,8 @@ int isl_map_fast_is_equal(__isl_keep isl_map *map1, __isl_keep isl_map *map2); int isl_map_foreach_basic_map(__isl_keep isl_map *map, int (*fn)(__isl_take isl_basic_map *bmap, void *user), void *user); +__isl_give isl_map *isl_set_lifting(__isl_take isl_set *set); + #if defined(__cplusplus) } #endif diff --git a/isl_map.c b/isl_map.c index 5d7a01c..2de215e 100644 --- a/isl_map.c +++ b/isl_map.c @@ -4271,6 +4271,10 @@ struct isl_map *isl_map_align_divs(struct isl_map *map) { int i; + if (!map) + return NULL; + if (map->n == 0) + return map; map = isl_map_compute_divs(map); map = isl_map_cow(map); if (!map) @@ -5310,3 +5314,62 @@ int isl_map_foreach_basic_map(__isl_keep isl_map *map, return 0; } + +__isl_give isl_map *isl_set_lifting(__isl_take isl_set *set) +{ + struct isl_dim *dim; + struct isl_basic_map *bmap; + unsigned n_set; + unsigned n_div; + unsigned n_param; + unsigned total; + int i, k, l; + + set = isl_set_align_divs(set); + + if (!set) + return NULL; + + dim = isl_set_get_dim(set); + if (set->n == 0 || set->p[0]->n_div == 0) { + isl_set_free(set); + return isl_map_identity(dim); + } + + n_div = set->p[0]->n_div; + dim = isl_dim_map(dim); + n_param = isl_dim_size(dim, isl_dim_param); + n_set = isl_dim_size(dim, isl_dim_in); + dim = isl_dim_extend(dim, n_param, n_set, n_set + n_div); + bmap = isl_basic_map_alloc_dim(dim, 0, n_set, 2 * n_div); + for (i = 0; i < n_set; ++i) + bmap = var_equal(bmap, i); + + total = n_param + n_set + n_set + n_div; + for (i = 0; i < n_div; ++i) { + k = isl_basic_map_alloc_inequality(bmap); + if (k < 0) + goto error; + isl_seq_cpy(bmap->ineq[k], set->p[0]->div[i]+1, 1+n_param); + isl_seq_clr(bmap->ineq[k]+1+n_param, n_set); + isl_seq_cpy(bmap->ineq[k]+1+n_param+n_set, + set->p[0]->div[i]+1+1+n_param, n_set + n_div); + isl_int_neg(bmap->ineq[k][1+n_param+n_set+n_set+i], + set->p[0]->div[i][0]); + + l = isl_basic_map_alloc_inequality(bmap); + if (l < 0) + goto error; + isl_seq_neg(bmap->ineq[l], bmap->ineq[k], 1 + total); + isl_int_add(bmap->ineq[l][0], bmap->ineq[l][0], + set->p[0]->div[i][0]); + isl_int_sub_ui(bmap->ineq[l][0], bmap->ineq[l][0], 1); + } + + isl_set_free(set); + return isl_map_from_basic_map(bmap); +error: + isl_set_free(set); + isl_basic_map_free(bmap); + return NULL; +}