X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=isl_map_simplify.c;h=9558a09e081ace1d7ac878672df3d615a17238e5;hb=890e13b4486f876822bfad8919864db8571b75b7;hp=e733cbd8bd59ce0f0de95379d2d12e7b9ee24ef1;hpb=f76aa4201b6c75734aaca36626bc8afbfdf7e155;p=platform%2Fupstream%2Fisl.git diff --git a/isl_map_simplify.c b/isl_map_simplify.c index e733cbd..9558a09 100644 --- a/isl_map_simplify.c +++ b/isl_map_simplify.c @@ -7,6 +7,7 @@ * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium */ +#include #include #include #include "isl_equalities.h" @@ -32,11 +33,6 @@ static void swap_inequality(struct isl_basic_map *bmap, int a, int b) } } -static void set_swap_inequality(struct isl_basic_set *bset, int a, int b) -{ - swap_inequality((struct isl_basic_map *)bset, a, b); -} - static void constraint_drop_vars(isl_int *c, unsigned n, unsigned rem) { isl_seq_cpy(c, c + n, rem); @@ -1024,12 +1020,14 @@ static struct isl_basic_map *remove_duplicate_constraints( int bits; unsigned total = isl_basic_map_total_dim(bmap); isl_int sum; + isl_ctx *ctx; if (!bmap || bmap->n_ineq <= 1) return bmap; size = round_up(4 * (bmap->n_ineq+1) / 3 - 1); bits = ffs(size) - 1; + ctx = isl_basic_map_get_ctx(bmap); index = isl_calloc_array(ctx, isl_int **, size); if (!index) return bmap; @@ -1466,12 +1464,14 @@ static struct isl_basic_set *remove_shifted_constraints( isl_int ***index; int bits; int k, h, l; + isl_ctx *ctx; if (!bset) return NULL; size = round_up(4 * (context->n_ineq+1) / 3 - 1); bits = ffs(size) - 1; + ctx = isl_basic_set_get_ctx(bset); index = isl_calloc_array(ctx, isl_int **, size); if (!index) return bset; @@ -1500,94 +1500,6 @@ error: return bset; } -/* Tighten (decrease) the constant terms of the inequalities based - * on the equalities, without removing any integer points. - * For example, if there is an equality - * - * i = 3 * j - * - * and an inequality - * - * i >= 1 - * - * then we want to replace the inequality by - * - * i >= 3 - * - * We do this by computing a variable compression and translating - * the constraints to the compressed space. - * If any constraint has coefficients (except the contant term) - * with a common factor "f", then we can replace the constant term "c" - * by - * - * f * floor(c/f) - * - * That is, we add - * - * f * floor(c/f) - c = -fract(c/f) - * - * and we can add the same value to the original constraint. - * - * In the example, the compressed space only contains "j", - * and the inequality translates to - * - * 3 * j - 1 >= 0 - * - * We add -fract(-1/3) = -2 to the original constraint to obtain - * - * i - 3 >= 0 - */ -static struct isl_basic_set *normalize_constraints_in_compressed_space( - struct isl_basic_set *bset) -{ - int i; - unsigned total; - struct isl_mat *B, *C; - isl_int gcd; - - if (!bset) - return NULL; - - if (ISL_F_ISSET(bset, ISL_BASIC_SET_RATIONAL)) - return bset; - - if (!bset->n_ineq) - return bset; - - bset = isl_basic_set_cow(bset); - if (!bset) - return NULL; - - total = isl_basic_set_total_dim(bset); - B = isl_mat_sub_alloc6(bset->ctx, bset->eq, 0, bset->n_eq, 0, 1 + total); - C = isl_mat_variable_compression(B, NULL); - if (!C) - return bset; - if (C->n_col == 0) { - isl_mat_free(C); - return isl_basic_set_set_to_empty(bset); - } - B = isl_mat_sub_alloc6(bset->ctx, bset->ineq, - 0, bset->n_ineq, 0, 1 + total); - C = isl_mat_product(B, C); - if (!C) - return bset; - - isl_int_init(gcd); - for (i = 0; i < bset->n_ineq; ++i) { - isl_seq_gcd(C->row[i] + 1, C->n_col - 1, &gcd); - if (isl_int_is_one(gcd)) - continue; - isl_int_fdiv_r(C->row[i][0], C->row[i][0], gcd); - isl_int_sub(bset->ineq[i][0], bset->ineq[i][0], C->row[i][0]); - } - isl_int_clear(gcd); - - isl_mat_free(C); - - return bset; -} - /* Remove all information from bset that is redundant in the context * of context. Both bset and context are assumed to be full-dimensional. * @@ -1724,7 +1636,7 @@ static __isl_give isl_basic_set *uset_gist(__isl_take isl_basic_set *bset, goto error; bset = isl_basic_set_intersect(bset, isl_basic_set_copy(context)); - if (isl_basic_set_fast_is_empty(bset)) { + if (isl_basic_set_plain_is_empty(bset)) { isl_basic_set_free(context); return bset; } @@ -1732,7 +1644,7 @@ static __isl_give isl_basic_set *uset_gist(__isl_take isl_basic_set *bset, aff = isl_basic_set_affine_hull(isl_basic_set_copy(bset)); if (!aff) goto error; - if (isl_basic_set_fast_is_empty(aff)) { + if (isl_basic_set_plain_is_empty(aff)) { isl_basic_set_free(aff); isl_basic_set_free(context); return bset; @@ -1824,13 +1736,13 @@ struct isl_basic_map *isl_basic_map_gist(struct isl_basic_map *bmap, isl_basic_map_free(context); return bmap; } - if (isl_basic_map_fast_is_empty(context)) { + if (isl_basic_map_plain_is_empty(context)) { struct isl_dim *dim = isl_dim_copy(bmap->dim); isl_basic_map_free(context); isl_basic_map_free(bmap); return isl_basic_map_universe(dim); } - if (isl_basic_map_fast_is_empty(bmap)) { + if (isl_basic_map_plain_is_empty(bmap)) { isl_basic_map_free(context); return bmap; } @@ -1865,7 +1777,7 @@ __isl_give isl_map *isl_map_gist_basic_map(__isl_take isl_map *map, if (!map || !context) goto error;; - if (isl_basic_map_fast_is_empty(context)) { + if (isl_basic_map_plain_is_empty(context)) { struct isl_dim *dim = isl_dim_copy(map->dim); isl_basic_map_free(context); isl_map_free(map); @@ -1885,7 +1797,7 @@ __isl_give isl_map *isl_map_gist_basic_map(__isl_take isl_map *map, isl_basic_map_copy(context)); if (!map->p[i]) goto error; - if (isl_basic_map_fast_is_empty(map->p[i])) { + if (isl_basic_map_plain_is_empty(map->p[i])) { isl_basic_map_free(map->p[i]); if (i != map->n - 1) map->p[i] = map->p[map->n - 1]; @@ -1901,13 +1813,19 @@ error: return NULL; } -__isl_give isl_map *isl_map_gist(__isl_take isl_map *map, +static __isl_give isl_map *map_gist(__isl_take isl_map *map, __isl_take isl_map *context) { context = isl_map_compute_divs(context); return isl_map_gist_basic_map(map, isl_map_simple_hull(context)); } +__isl_give isl_map *isl_map_gist(__isl_take isl_map *map, + __isl_take isl_map *context) +{ + return isl_map_align_params_map_map_and(map, context, &map_gist); +} + struct isl_basic_set *isl_basic_set_gist(struct isl_basic_set *bset, struct isl_basic_set *context) { @@ -1934,8 +1852,8 @@ __isl_give isl_set *isl_set_gist(__isl_take isl_set *set, * one basic map in the context of the equalities of the other * basic map and check if we get a contradiction. */ -int isl_basic_map_fast_is_disjoint(struct isl_basic_map *bmap1, - struct isl_basic_map *bmap2) +int isl_basic_map_plain_is_disjoint(__isl_keep isl_basic_map *bmap1, + __isl_keep isl_basic_map *bmap2) { struct isl_vec *v = NULL; int *elim = NULL; @@ -1999,26 +1917,27 @@ error: return -1; } -int isl_basic_set_fast_is_disjoint(struct isl_basic_set *bset1, - struct isl_basic_set *bset2) +int isl_basic_set_plain_is_disjoint(__isl_keep isl_basic_set *bset1, + __isl_keep isl_basic_set *bset2) { - return isl_basic_map_fast_is_disjoint((struct isl_basic_map *)bset1, + return isl_basic_map_plain_is_disjoint((struct isl_basic_map *)bset1, (struct isl_basic_map *)bset2); } -int isl_map_fast_is_disjoint(struct isl_map *map1, struct isl_map *map2) +int isl_map_plain_is_disjoint(__isl_keep isl_map *map1, + __isl_keep isl_map *map2) { int i, j; if (!map1 || !map2) return -1; - if (isl_map_fast_is_equal(map1, map2)) + if (isl_map_plain_is_equal(map1, map2)) return 0; for (i = 0; i < map1->n; ++i) { for (j = 0; j < map2->n; ++j) { - int d = isl_basic_map_fast_is_disjoint(map1->p[i], + int d = isl_basic_map_plain_is_disjoint(map1->p[i], map2->p[j]); if (d != 1) return d; @@ -2027,12 +1946,18 @@ int isl_map_fast_is_disjoint(struct isl_map *map1, struct isl_map *map2) return 1; } -int isl_set_fast_is_disjoint(struct isl_set *set1, struct isl_set *set2) +int isl_set_plain_is_disjoint(__isl_keep isl_set *set1, + __isl_keep isl_set *set2) { - return isl_map_fast_is_disjoint((struct isl_map *)set1, + return isl_map_plain_is_disjoint((struct isl_map *)set1, (struct isl_map *)set2); } +int isl_set_fast_is_disjoint(__isl_keep isl_set *set1, __isl_keep isl_set *set2) +{ + return isl_set_plain_is_disjoint(set1, set2); +} + /* Check if we can combine a given div with lower bound l and upper * bound u with some other div and if so return that other div. * Otherwise return -1.