X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=isl_map.c;h=878519d0d3fe5289db0ef97709ac9e84fb499aad;hb=97d5106768ad7edb30b1c958c98d1a0e6643292c;hp=b0f5100e40c06e13670b7076c9b316d57a84b024;hpb=160614ae24ac6bd45022adbb8d841cb1d1e2000d;p=platform%2Fupstream%2Fisl.git diff --git a/isl_map.c b/isl_map.c index b0f5100..878519d 100644 --- a/isl_map.c +++ b/isl_map.c @@ -122,6 +122,8 @@ unsigned isl_basic_set_n_param(__isl_keep isl_basic_set *bset) unsigned isl_basic_set_total_dim(const struct isl_basic_set *bset) { + if (!bset) + return 0; return isl_space_dim(bset->dim, isl_dim_all) + bset->n_div; } @@ -255,25 +257,42 @@ __isl_give isl_space *isl_basic_set_get_space(__isl_keep isl_basic_set *bset) return isl_space_copy(bset->dim); } -__isl_give isl_local_space *isl_basic_map_get_local_space( - __isl_keep isl_basic_map *bmap) +/* Extract the divs in "bmap" as a matrix. + */ +__isl_give isl_mat *isl_basic_map_get_divs(__isl_keep isl_basic_map *bmap) { int i; - isl_local_space *ls; + isl_ctx *ctx; + isl_mat *div; unsigned total; + unsigned cols; if (!bmap) return NULL; - total = isl_basic_map_total_dim(bmap); - ls = isl_local_space_alloc(isl_space_copy(bmap->dim), bmap->n_div); - if (!ls) + ctx = isl_basic_map_get_ctx(bmap); + total = isl_space_dim(bmap->dim, isl_dim_all); + cols = 1 + 1 + total + bmap->n_div; + div = isl_mat_alloc(ctx, bmap->n_div, cols); + if (!div) return NULL; for (i = 0; i < bmap->n_div; ++i) - isl_seq_cpy(ls->div->row[i], bmap->div[i], 2 + total); + isl_seq_cpy(div->row[i], bmap->div[i], cols); - return ls; + return div; +} + +__isl_give isl_local_space *isl_basic_map_get_local_space( + __isl_keep isl_basic_map *bmap) +{ + isl_mat *div; + + if (!bmap) + return NULL; + + div = isl_basic_map_get_divs(bmap); + return isl_local_space_alloc_div(isl_space_copy(bmap->dim), div); } __isl_give isl_local_space *isl_basic_set_get_local_space( @@ -489,6 +508,14 @@ const char *isl_set_get_dim_name(__isl_keep isl_set *set, return set ? isl_space_get_dim_name(set->dim, type, pos) : NULL; } +/* Does the given dimension have a name? + */ +int isl_set_has_dim_name(__isl_keep isl_set *set, + enum isl_dim_type type, unsigned pos) +{ + return set ? isl_space_has_dim_name(set->dim, type, pos) : -1; +} + __isl_give isl_basic_map *isl_basic_map_set_dim_name( __isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned pos, const char *s) @@ -2694,6 +2721,10 @@ __isl_give isl_basic_map *isl_basic_map_insert(__isl_take isl_basic_map *bmap, bmap->n_div, bmap->n_eq, bmap->n_ineq); if (isl_basic_map_is_rational(bmap)) res = isl_basic_map_set_rational(res); + if (isl_basic_map_plain_is_empty(bmap)) { + isl_basic_map_free(bmap); + return isl_basic_map_set_to_empty(res); + } res = isl_basic_map_add_constraints_dim_map(res, bmap, dim_map); return isl_basic_map_finalize(res); } @@ -4928,6 +4959,25 @@ struct isl_basic_set *isl_basic_set_fix_dim_si(struct isl_basic_set *bset, isl_dim_set, dim, value); } +static int remove_if_empty(__isl_keep isl_map *map, int i) +{ + int empty = isl_basic_map_plain_is_empty(map->p[i]); + + if (empty < 0) + return -1; + if (!empty) + return 0; + + isl_basic_map_free(map->p[i]); + if (i != map->n - 1) { + ISL_F_CLR(map, ISL_MAP_NORMALIZED); + map->p[i] = map->p[map->n - 1]; + } + map->n--; + + return 0; +} + struct isl_map *isl_map_fix_si(struct isl_map *map, enum isl_dim_type type, unsigned pos, int value) { @@ -4938,9 +4988,9 @@ struct isl_map *isl_map_fix_si(struct isl_map *map, return NULL; isl_assert(map->ctx, pos < isl_map_dim(map, type), goto error); - for (i = 0; i < map->n; ++i) { + for (i = map->n - 1; i >= 0; --i) { map->p[i] = isl_basic_map_fix_si(map->p[i], type, pos, value); - if (!map->p[i]) + if (remove_if_empty(map, i) < 0) goto error; } ISL_F_CLR(map, ISL_MAP_NORMALIZED); @@ -5102,6 +5152,92 @@ __isl_give isl_set *isl_set_upper_bound_si(__isl_take isl_set *set, return isl_map_upper_bound_si(set, type, pos, value); } +/* Bound the given variable of "bmap" from below (or above is "upper" + * is set) to "value". + */ +static __isl_give isl_basic_map *basic_map_bound( + __isl_take isl_basic_map *bmap, + enum isl_dim_type type, unsigned pos, isl_int value, int upper) +{ + int j; + + if (!bmap) + return NULL; + if (pos >= isl_basic_map_dim(bmap, type)) + isl_die(bmap->ctx, isl_error_invalid, + "index out of bounds", goto error); + pos += isl_basic_map_offset(bmap, type); + bmap = isl_basic_map_cow(bmap); + bmap = isl_basic_map_extend_constraints(bmap, 0, 1); + j = isl_basic_map_alloc_inequality(bmap); + if (j < 0) + goto error; + isl_seq_clr(bmap->ineq[j], 1 + isl_basic_map_total_dim(bmap)); + if (upper) { + isl_int_set_si(bmap->ineq[j][pos], -1); + isl_int_set(bmap->ineq[j][0], value); + } else { + isl_int_set_si(bmap->ineq[j][pos], 1); + isl_int_neg(bmap->ineq[j][0], value); + } + bmap = isl_basic_map_simplify(bmap); + return isl_basic_map_finalize(bmap); +error: + isl_basic_map_free(bmap); + return NULL; +} + +/* Bound the given variable of "map" from below (or above is "upper" + * is set) to "value". + */ +static __isl_give isl_map *map_bound(__isl_take isl_map *map, + enum isl_dim_type type, unsigned pos, isl_int value, int upper) +{ + int i; + + map = isl_map_cow(map); + if (!map) + return NULL; + + if (pos >= isl_map_dim(map, type)) + isl_die(map->ctx, isl_error_invalid, + "index out of bounds", goto error); + for (i = map->n - 1; i >= 0; --i) { + map->p[i] = basic_map_bound(map->p[i], type, pos, value, upper); + if (remove_if_empty(map, i) < 0) + goto error; + } + ISL_F_CLR(map, ISL_MAP_NORMALIZED); + return map; +error: + isl_map_free(map); + return NULL; +} + +__isl_give isl_map *isl_map_lower_bound(__isl_take isl_map *map, + enum isl_dim_type type, unsigned pos, isl_int value) +{ + return map_bound(map, type, pos, value, 0); +} + +__isl_give isl_map *isl_map_upper_bound(__isl_take isl_map *map, + enum isl_dim_type type, unsigned pos, isl_int value) +{ + return map_bound(map, type, pos, value, 1); +} + +__isl_give isl_set *isl_set_lower_bound(__isl_take isl_set *set, + enum isl_dim_type type, unsigned pos, isl_int value) +{ + return isl_map_lower_bound(set, type, pos, value); +} + +__isl_give isl_set *isl_set_upper_bound(__isl_take isl_set *set, + enum isl_dim_type type, unsigned pos, isl_int value) +{ + return isl_map_upper_bound(set, type, pos, value); +} + struct isl_set *isl_set_lower_bound_dim(struct isl_set *set, unsigned dim, isl_int value) { @@ -6316,7 +6452,7 @@ error: /* * returns range - domain */ -struct isl_set *isl_map_deltas(struct isl_map *map) +__isl_give isl_set *isl_map_deltas(__isl_take isl_map *map) { int i; isl_space *dim; @@ -6694,6 +6830,12 @@ int isl_basic_map_is_subset( return is_subset; } +int isl_basic_set_is_subset(__isl_keep isl_basic_set *bset1, + __isl_keep isl_basic_set *bset2) +{ + return isl_basic_map_is_subset(bset1, bset2); +} + int isl_basic_map_is_equal( struct isl_basic_map *bmap1, struct isl_basic_map *bmap2) { @@ -7197,16 +7339,8 @@ struct isl_map *isl_map_remove_empty_parts(struct isl_map *map) if (!map) return NULL; - for (i = map->n-1; i >= 0; --i) { - if (!ISL_F_ISSET(map->p[i], ISL_BASIC_MAP_EMPTY)) - continue; - isl_basic_map_free(map->p[i]); - if (i != map->n-1) { - ISL_F_CLR(map, ISL_MAP_NORMALIZED); - map->p[i] = map->p[map->n-1]; - } - map->n--; - } + for (i = map->n - 1; i >= 0; --i) + remove_if_empty(map, i); return map; } @@ -9719,6 +9853,17 @@ error: return NULL; } +/* Construct a map mapping the domain of the affine expression + * to a one-dimensional range prescribed by the affine expression. + */ +__isl_give isl_map *isl_map_from_aff(__isl_take isl_aff *aff) +{ + isl_basic_map *bmap; + + bmap = isl_basic_map_from_aff(aff); + return isl_map_from_basic_map(bmap); +} + /* Construct a basic map mapping the domain the multi-affine expression * to its range, with each dimension in the range equated to the * corresponding affine expression. @@ -9756,6 +9901,18 @@ __isl_give isl_basic_map *isl_basic_map_from_multi_aff( return bmap; } +/* Construct a map mapping the domain the multi-affine expression + * to its range, with each dimension in the range equated to the + * corresponding affine expression. + */ +__isl_give isl_map *isl_map_from_multi_aff(__isl_take isl_multi_aff *maff) +{ + isl_basic_map *bmap; + + bmap = isl_basic_map_from_multi_aff(maff); + return isl_map_from_basic_map(bmap); +} + /* Construct a basic map mapping a domain in the given space to * to an n-dimensional range, with n the number of elements in the list, * where each coordinate in the range is prescribed by the @@ -10001,14 +10158,8 @@ __isl_give isl_set *isl_set_substitute(__isl_take isl_set *set, for (i = set->n - 1; i >= 0; --i) { set->p[i] = isl_basic_set_substitute(set->p[i], type, pos, subs); - if (!set->p[i]) + if (remove_if_empty(set, i) < 0) goto error; - if (isl_basic_set_plain_is_empty(set->p[i])) { - isl_basic_set_free(set->p[i]); - if (i != set->n - 1) - set->p[i] = set->p[set->n - 1]; - set->n--; - } } return set;