X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=isl_dim.c;h=914d666b38ee5f0d2c5817bf740dd5c5295b050a;hb=de51a9bc4da5dd3f1f9f57c2362da6f9752c44e0;hp=71b0c47457650858a27685ce51bc59856d57f1f9;hpb=1e63b4e5d3b17d182983d7ca8fd1a6cc814da398;p=platform%2Fupstream%2Fisl.git diff --git a/isl_dim.c b/isl_dim.c index 71b0c47..914d666 100644 --- a/isl_dim.c +++ b/isl_dim.c @@ -1,502 +1,258 @@ -#include "isl_dim.h" -#include "isl_name.h" +#include +#include +#include +#include +#include -struct isl_dim *isl_dim_alloc(struct isl_ctx *ctx, - unsigned nparam, unsigned n_in, unsigned n_out) +isl_ctx *isl_dim_get_ctx(__isl_keep isl_space *dim) { - struct isl_dim *dim; - - dim = isl_alloc_type(ctx, struct isl_dim); - if (!dim) - return NULL; - - dim->ctx = ctx; - isl_ctx_ref(ctx); - dim->ref = 1; - dim->nparam = nparam; - dim->n_in = n_in; - dim->n_out = n_out; - - dim->n_name = 0; - dim->names = NULL; - - return dim; + return isl_space_get_ctx(dim); } -struct isl_dim *isl_dim_set_alloc(struct isl_ctx *ctx, - unsigned nparam, unsigned dim) +__isl_give isl_space *isl_dim_alloc(isl_ctx *ctx, + unsigned nparam, unsigned n_in, unsigned n_out) { - return isl_dim_alloc(ctx, nparam, 0, dim); + return isl_space_alloc(ctx, nparam, n_in, n_out); } - -static unsigned global_pos(struct isl_dim *dim, - enum isl_dim_type type, unsigned pos) +__isl_give isl_space *isl_dim_set_alloc(isl_ctx *ctx, + unsigned nparam, unsigned dim) { - struct isl_ctx *ctx = dim->ctx; - - switch (type) { - case isl_dim_param: - isl_assert(ctx, pos < dim->nparam, return isl_dim_total(dim)); - return pos; - case isl_dim_in: - isl_assert(ctx, pos < dim->n_in, return isl_dim_total(dim)); - return pos + dim->nparam; - case isl_dim_out: - isl_assert(ctx, pos < dim->n_out, return isl_dim_total(dim)); - return pos + dim->nparam + dim->n_in; - default: - isl_assert(ctx, 0, goto error); - } - return isl_dim_total(dim); + return isl_space_set_alloc(ctx, nparam, dim); } - -static struct isl_dim *set_name(struct isl_dim *dim, - enum isl_dim_type type, unsigned pos, - struct isl_name *name) +__isl_give isl_space *isl_dim_copy(__isl_keep isl_space *dim) { - struct isl_ctx *ctx = dim->ctx; - dim = isl_dim_cow(dim); - - if (!dim) - goto error; - - pos = global_pos(dim, type, pos); - isl_assert(ctx, pos != isl_dim_total(dim), goto error); - - if (pos >= dim->n_name) { - if (!name) - return dim; - if (!dim->names) { - dim->names = isl_calloc_array(dim->ctx, - struct isl_name *, isl_dim_total(dim)); - if (!dim->names) - goto error; - } else { - int i; - dim->names = isl_realloc_array(dim->ctx, dim->names, - struct isl_name *, isl_dim_total(dim)); - if (!dim->names) - goto error; - for (i = dim->n_name; i < isl_dim_total(dim); ++i) - dim->names[i] = NULL; - } - dim->n_name = isl_dim_total(dim); - } - - dim->names[pos] = name; - - return dim; -error: - isl_name_free(ctx, name); - isl_dim_free(dim); - return NULL; + return isl_space_copy(dim); } - -static struct isl_name *get_name(struct isl_dim *dim, - enum isl_dim_type type, unsigned pos) +void isl_dim_free(__isl_take isl_space *dim) { - if (!dim) - return NULL; - - pos = global_pos(dim, type, pos); - if (pos == isl_dim_total(dim)) - return NULL; - if (pos >= dim->n_name) - return NULL; - return dim->names[pos]; + isl_space_free(dim); } -static unsigned n(struct isl_dim *dim, enum isl_dim_type type) +unsigned isl_dim_size(__isl_keep isl_space *dim, enum isl_dim_type type) { - switch (type) { - case isl_dim_param: return dim->nparam; - case isl_dim_in: return dim->n_in; - case isl_dim_out: return dim->n_out; - } + return isl_space_dim(dim, type); } -static struct isl_dim *copy_names(struct isl_dim *dst, - enum isl_dim_type dst_type, struct isl_dim *src, - enum isl_dim_type src_type) +__isl_give isl_space *isl_dim_set_dim_id(__isl_take isl_space *dim, + enum isl_dim_type type, unsigned pos, __isl_take isl_id *id) { - int i; - struct isl_name *name; - - for (i = 0; i < n(dst, dst_type); ++i) { - name = get_name(src, src_type, i); - if (!name) - continue; - dst = set_name(dst, dst_type, i, isl_name_copy(dst->ctx, name)); - if (!dst) - return NULL; - } - return dst; + return isl_space_set_dim_id(dim, type, pos, id); } - -struct isl_dim *isl_dim_dup(struct isl_dim *dim) +int isl_dim_has_dim_id(__isl_keep isl_space *dim, + enum isl_dim_type type, unsigned pos) { - struct isl_dim *dup; - dup = isl_dim_alloc(dim->ctx, dim->nparam, dim->n_in, dim->n_out); - if (!dim->names) - return dup; - dup = copy_names(dup, isl_dim_param, dim, isl_dim_param); - dup = copy_names(dup, isl_dim_in, dim, isl_dim_in); - dup = copy_names(dup, isl_dim_out, dim, isl_dim_out); - return dup; + return isl_space_has_dim_id(dim, type, pos); } - -struct isl_dim *isl_dim_cow(struct isl_dim *dim) +__isl_give isl_id *isl_dim_get_dim_id(__isl_keep isl_space *dim, + enum isl_dim_type type, unsigned pos) { - if (!dim) - return NULL; - - if (dim->ref == 1) - return dim; - dim->ref--; - return isl_dim_dup(dim); + return isl_space_get_dim_id(dim, type, pos); } -struct isl_dim *isl_dim_copy(struct isl_dim *dim) +int isl_dim_find_dim_by_id(__isl_keep isl_space *dim, + enum isl_dim_type type, __isl_keep isl_id *id) { - if (!dim) - return NULL; - - dim->ref++; - return dim; + return isl_space_find_dim_by_id(dim, type, id); } -void isl_dim_free(struct isl_dim *dim) +__isl_give isl_space *isl_dim_set_tuple_id(__isl_take isl_space *dim, + enum isl_dim_type type, __isl_take isl_id *id) { - int i; - - if (!dim) - return; - - if (--dim->ref > 0) - return; - - for (i = 0; i < dim->n_name; ++i) - isl_name_free(dim->ctx, dim->names[i]); - free(dim->names); - isl_ctx_deref(dim->ctx); - - free(dim); + return isl_space_set_tuple_id(dim, type, id); } - -struct isl_dim *isl_dim_set_name(struct isl_dim *dim, - enum isl_dim_type type, unsigned pos, - const char *s) -{ - struct isl_name *name; - if (!dim) - return NULL; - name = isl_name_get(dim->ctx, s); - if (!name) - goto error; - return set_name(dim, type, pos, name); -error: - isl_dim_free(dim); - return NULL; +__isl_give isl_space *isl_dim_reset_tuple_id(__isl_take isl_space *dim, + enum isl_dim_type type) +{ + return isl_space_reset_tuple_id(dim, type); } - -const char *isl_dim_get_name(struct isl_dim *dim, - enum isl_dim_type type, unsigned pos) +int isl_dim_has_tuple_id(__isl_keep isl_space *dim, enum isl_dim_type type) { - struct isl_name *name = get_name(dim, type, pos); - return name ? name->name : NULL; + return isl_space_has_tuple_id(dim, type); } - -static int match(struct isl_dim *dim1, enum isl_dim_type dim1_type, - struct isl_dim *dim2, enum isl_dim_type dim2_type) +__isl_give isl_id *isl_dim_get_tuple_id(__isl_keep isl_space *dim, + enum isl_dim_type type) { - int i; - - if (n(dim1, dim1_type) != n(dim2, dim2_type)) - return 0; - - if (!dim1->names && !dim2->names) - return 1; - - for (i = 0; i < n(dim1, dim1_type); ++i) { - if (get_name(dim1, dim1_type, i) != - get_name(dim2, dim2_type, i)) - return 0; - } - return 1; + return isl_space_get_tuple_id(dim, type); } -static void get_names(struct isl_dim *dim, enum isl_dim_type type, - unsigned first, unsigned n, struct isl_name **names) +__isl_give isl_space *isl_dim_set_name(__isl_take isl_space *dim, + enum isl_dim_type type, unsigned pos, __isl_keep const char *name) { - int i; - - for (i = 0; i < n ; ++i) - names[i] = get_name(dim, type, first+i); + return isl_space_set_dim_name(dim, type, pos, name); } - -struct isl_dim *isl_dim_extend(struct isl_dim *dim, - unsigned nparam, unsigned n_in, unsigned n_out) +__isl_keep const char *isl_dim_get_name(__isl_keep isl_space *dim, + enum isl_dim_type type, unsigned pos) { - struct isl_name **names = NULL; - - if (!dim) - return NULL; - if (dim->nparam == nparam && dim->n_in == n_in && dim->n_out == n_out) - return dim; - - isl_assert(dim->ctx, dim->nparam <= nparam, goto error); - isl_assert(dim->ctx, dim->n_in <= n_in, goto error); - isl_assert(dim->ctx, dim->n_out <= n_out, goto error); - - dim = isl_dim_cow(dim); - - if (dim->names) { - names = isl_calloc_array(dim->ctx, struct isl_name *, - nparam + n_in + n_out); - if (!names) - goto error; - get_names(dim, isl_dim_param, 0, dim->nparam, names); - get_names(dim, isl_dim_in, 0, dim->n_in, names + nparam); - get_names(dim, isl_dim_out, 0, dim->n_out, - names + nparam + n_in); - free(dim->names); - dim->names = names; - dim->n_name = nparam + n_in + n_out; - } - dim->nparam = nparam; - dim->n_in = n_in; - dim->n_out = n_out; - - return dim; -error: - free(names); - isl_dim_free(dim); - return NULL; + return isl_space_get_dim_name(dim, type, pos); } -struct isl_dim *isl_dim_join(struct isl_dim *left, struct isl_dim *right) +__isl_give isl_space *isl_dim_set_tuple_name(__isl_take isl_space *dim, + enum isl_dim_type type, const char *s) { - struct isl_dim *dim; - - if (!left || !right) - goto error; - - isl_assert(left->ctx, match(left, isl_dim_param, right, isl_dim_param), - goto error); - isl_assert(left->ctx, match(left, isl_dim_out, right, isl_dim_in), - goto error); - - dim = isl_dim_alloc(left->ctx, left->nparam, left->n_in, right->n_out); - if (!dim) - goto error; - - dim = copy_names(dim, isl_dim_param, left, isl_dim_param); - dim = copy_names(dim, isl_dim_in, left, isl_dim_in); - dim = copy_names(dim, isl_dim_out, right, isl_dim_out); - - isl_dim_free(left); - isl_dim_free(right); - - return dim; -error: - isl_dim_free(left); - isl_dim_free(right); - return NULL; + return isl_space_set_tuple_name(dim, type, s); } - -struct isl_dim *isl_dim_map(struct isl_dim *dim) +const char *isl_dim_get_tuple_name(__isl_keep isl_space *dim, + enum isl_dim_type type) { - struct isl_name **names = NULL; - - if (!dim) - return NULL; - isl_assert(dim->ctx, dim->n_in == 0, goto error); - if (dim->n_out == 0) - return dim; - dim = isl_dim_cow(dim); - if (!dim) - return NULL; - if (dim->names) { - names = isl_calloc_array(dim->ctx, struct isl_name *, - dim->nparam + dim->n_out + dim->n_out); - if (!names) - goto error; - get_names(dim, isl_dim_param, 0, dim->nparam, names); - get_names(dim, isl_dim_out, 0, dim->n_out, names + dim->nparam); - } - dim->n_in = dim->n_out; - if (names) { - copy_names(dim, isl_dim_out, dim, isl_dim_in); - free(dim->names); - dim->names = names; - dim->n_name = dim->nparam + dim->n_out + dim->n_out; - } - return dim; -error: - isl_dim_free(dim); - return NULL; + return isl_space_get_tuple_name(dim, type); } -static struct isl_dim *set_names(struct isl_dim *dim, enum isl_dim_type type, - unsigned first, unsigned n, struct isl_name **names) +int isl_dim_is_wrapping(__isl_keep isl_space *dim) { - int i; - - for (i = 0; i < n ; ++i) - dim = set_name(dim, type, first+i, names[i]); - - return dim; + return isl_space_is_wrapping(dim); } - -struct isl_dim *isl_dim_reverse(struct isl_dim *dim) +__isl_give isl_space *isl_dim_wrap(__isl_take isl_space *dim) { - unsigned t; - struct isl_name **names = NULL; - - if (!dim) - return NULL; - if (match(dim, isl_dim_in, dim, isl_dim_out)) - return dim; - - dim = isl_dim_cow(dim); - if (!dim) - return NULL; - - if (dim->names) { - names = isl_alloc_array(dim->ctx, struct isl_name *, - dim->n_in + dim->n_out); - if (!names) - goto error; - get_names(dim, isl_dim_in, 0, dim->n_in, names); - get_names(dim, isl_dim_out, 0, dim->n_out, names + dim->n_in); - } - - t = dim->n_in; - dim->n_in = dim->n_out; - dim->n_out = t; - - if (dim->names) { - dim = set_names(dim, isl_dim_out, 0, dim->n_out, names); - dim = set_names(dim, isl_dim_in, 0, dim->n_in, names + dim->n_out); - free(names); - } - - return dim; -error: - free(names); - isl_dim_free(dim); - return NULL; + return isl_space_wrap(dim); } - -struct isl_dim *isl_dim_drop_inputs(struct isl_dim *dim, - unsigned first, unsigned n) +__isl_give isl_space *isl_dim_unwrap(__isl_take isl_space *dim) { - int i; - - if (!dim) - return NULL; - - if (n == 0) - return dim; - - isl_assert(dim->ctx, first + n <= dim->n_in, goto error); - dim = isl_dim_cow(dim); - if (!dim) - goto error; - if (dim->names) { - for (i = 0; i < n; ++i) { - isl_name_free(dim->ctx, - get_name(dim, isl_dim_in, first+i)); - } - for (i = first+n; i < dim->n_in; ++i) - set_name(dim, isl_dim_in, i - n, - get_name(dim, isl_dim_in, i)); - get_names(dim, isl_dim_out, 0, dim->n_out, - dim->names + dim->nparam + dim->n_in - n); - } - dim->n_in -= n; - return dim; -error: - isl_dim_free(dim); - return NULL; + return isl_space_unwrap(dim); } -struct isl_dim *isl_dim_drop_outputs(struct isl_dim *dim, - unsigned first, unsigned n) +__isl_give isl_space *isl_dim_domain(__isl_take isl_space *dim) { - int i; - - if (!dim) - return NULL; - - if (n == 0) - return dim; - - isl_assert(dim->ctx, first + n <= dim->n_out, goto error); - dim = isl_dim_cow(dim); - if (!dim) - goto error; - if (dim->names) { - for (i = 0; i < n; ++i) { - isl_name_free(dim->ctx, - get_name(dim, isl_dim_out, first+i)); - } - for (i = first+n; i < dim->n_out; ++i) - set_name(dim, isl_dim_out, i - n, - get_name(dim, isl_dim_out, i)); - } - dim->n_out -= n; - return dim; -error: - isl_dim_free(dim); - return NULL; + return isl_space_domain(dim); } - -struct isl_dim *isl_dim_domain(struct isl_dim *dim) +__isl_give isl_space *isl_dim_from_domain(__isl_take isl_space *dim) +{ + return isl_space_from_domain(dim); +} +__isl_give isl_space *isl_dim_range(__isl_take isl_space *dim) +{ + return isl_space_range(dim); +} +__isl_give isl_space *isl_dim_from_range(__isl_take isl_space *dim) +{ + return isl_space_from_range(dim); +} +__isl_give isl_space *isl_dim_reverse(__isl_take isl_space *dim) +{ + return isl_space_reverse(dim); +} +__isl_give isl_space *isl_dim_join(__isl_take isl_space *left, + __isl_take isl_space *right) +{ + return isl_space_join(left, right); +} +__isl_give isl_space *isl_dim_align_params(__isl_take isl_space *dim1, + __isl_take isl_space *dim2) +{ + return isl_space_align_params(dim1, dim2); +} +__isl_give isl_space *isl_dim_insert(__isl_take isl_space *dim, + enum isl_dim_type type, unsigned pos, unsigned n) +{ + return isl_space_insert_dims(dim, type, pos, n); +} +__isl_give isl_space *isl_dim_add(__isl_take isl_space *dim, + enum isl_dim_type type, unsigned n) +{ + return isl_space_add_dims(dim, type, n); +} +__isl_give isl_space *isl_dim_drop(__isl_take isl_space *dim, + enum isl_dim_type type, unsigned first, unsigned n) { - if (!dim) - return NULL; - dim = isl_dim_drop_outputs(dim, 0, dim->n_out); - return isl_dim_reverse(dim); + return isl_space_drop_dims(dim, type, first, n); +} +__isl_give isl_space *isl_dim_move(__isl_take isl_space *dim, + enum isl_dim_type dst_type, unsigned dst_pos, + enum isl_dim_type src_type, unsigned src_pos, unsigned n) +{ + return isl_space_move_dims(dim, dst_type, dst_pos, src_type, src_pos, n); +} +__isl_give isl_space *isl_dim_map_from_set(__isl_take isl_space *dim) +{ + return isl_space_map_from_set(dim); +} +__isl_give isl_space *isl_dim_zip(__isl_take isl_space *dim) +{ + return isl_space_zip(dim); } -struct isl_dim *isl_dim_underlying(struct isl_dim *dim, unsigned n_div) +__isl_give isl_local_space *isl_local_space_from_dim( + __isl_take isl_space *dim) { - int i; + return isl_local_space_from_space(dim); +} +__isl_give isl_space *isl_local_space_get_dim( + __isl_keep isl_local_space *ls) +{ + return isl_local_space_get_space(ls); +} - if (!dim) - return NULL; - if (n_div == 0 && - dim->nparam == 0 && dim->n_in == 0 && dim->n_name == 0) - return dim; - dim = isl_dim_cow(dim); - if (!dim) - return NULL; - dim->n_out += dim->nparam + dim->n_in + n_div; - dim->nparam = 0; - dim->n_in = 0; +__isl_give isl_space *isl_aff_get_dim(__isl_keep isl_aff *aff) +{ + return isl_aff_get_space(aff); +} +__isl_give isl_space *isl_pw_aff_get_dim(__isl_keep isl_pw_aff *pwaff) +{ + return isl_pw_aff_get_space(pwaff); +} - for (i = 0; i < dim->n_name; ++i) - isl_name_free(dim->ctx, get_name(dim, isl_dim_out, i)); - dim->n_name = 0; +__isl_give isl_space *isl_constraint_get_dim( + __isl_keep isl_constraint *constraint) +{ + return isl_constraint_get_space(constraint); +} - return dim; +__isl_give isl_space *isl_basic_map_get_dim(__isl_keep isl_basic_map *bmap) +{ + return isl_basic_map_get_space(bmap); +} +__isl_give isl_space *isl_map_get_dim(__isl_keep isl_map *map) +{ + return isl_map_get_space(map); +} +__isl_give isl_space *isl_union_map_get_dim(__isl_keep isl_union_map *umap) +{ + return isl_union_map_get_space(umap); } -unsigned isl_dim_total(struct isl_dim *dim) +__isl_give isl_space *isl_basic_set_get_dim(__isl_keep isl_basic_set *bset) { - return dim->nparam + dim->n_in + dim->n_out; + return isl_basic_set_get_space(bset); +} +__isl_give isl_space *isl_set_get_dim(__isl_keep isl_set *set) +{ + return isl_set_get_space(set); +} +__isl_give isl_space *isl_union_set_get_dim(__isl_keep isl_union_set *uset) +{ + return isl_union_set_get_space(uset); } -int isl_dim_equal(struct isl_dim *dim1, struct isl_dim *dim2) +__isl_give isl_space *isl_point_get_dim(__isl_keep isl_point *pnt) { - return match(dim1, isl_dim_param, dim2, isl_dim_param) && - match(dim1, isl_dim_in, dim2, isl_dim_in) && - match(dim1, isl_dim_out, dim2, isl_dim_out); + return isl_point_get_space(pnt); } -int isl_dim_compatible(struct isl_dim *dim1, struct isl_dim *dim2) +__isl_give isl_space *isl_qpolynomial_get_dim(__isl_keep isl_qpolynomial *qp) +{ + return isl_qpolynomial_get_space(qp); +} +__isl_give isl_space *isl_pw_qpolynomial_get_dim( + __isl_keep isl_pw_qpolynomial *pwqp) +{ + return isl_pw_qpolynomial_get_space(pwqp); +} +__isl_give isl_space *isl_qpolynomial_fold_get_dim( + __isl_keep isl_qpolynomial_fold *fold) +{ + return isl_qpolynomial_fold_get_space(fold); +} +__isl_give isl_space *isl_pw_qpolynomial_fold_get_dim( + __isl_keep isl_pw_qpolynomial_fold *pwf) +{ + return isl_pw_qpolynomial_fold_get_space(pwf); +} +__isl_give isl_space *isl_union_pw_qpolynomial_get_dim( + __isl_keep isl_union_pw_qpolynomial *upwqp) +{ + return isl_union_pw_qpolynomial_get_space(upwqp); +} +__isl_give isl_space *isl_union_pw_qpolynomial_fold_get_dim( + __isl_keep isl_union_pw_qpolynomial_fold *upwf) { - return dim1->nparam == dim2->nparam && - dim1->n_in + dim1->n_out == dim2->n_in + dim2->n_out; + return isl_union_pw_qpolynomial_fold_get_space(upwf); }