X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=isl_local_space.c;h=a8e5ebacb39a5cdb935a1099ee6d81aa9e850873;hb=6d28e7c5ff2b41ec88fa32664cc446807af5843d;hp=0759b132f5db4a93eb39de753a2fd7d5a7e6125b;hpb=34f4fdba988485e086db2c47e3529ded64c15d39;p=platform%2Fupstream%2Fisl.git diff --git a/isl_local_space.c b/isl_local_space.c index 0759b13..a8e5eba 100644 --- a/isl_local_space.c +++ b/isl_local_space.c @@ -219,6 +219,9 @@ __isl_give isl_aff *isl_local_space_get_div(__isl_keep isl_local_space *ls, if (isl_int_is_zero(ls->div->row[pos][0])) isl_die(isl_local_space_get_ctx(ls), isl_error_invalid, "expression of div unknown", return NULL); + if (!isl_local_space_is_set(ls)) + isl_die(isl_local_space_get_ctx(ls), isl_error_invalid, + "cannot represent divs of map spaces", return NULL); aff = isl_aff_alloc(isl_local_space_copy(ls)); if (!aff) @@ -725,7 +728,7 @@ __isl_give isl_local_space *isl_local_space_substitute_equalities( total = isl_space_dim(eq->dim, isl_dim_all); if (isl_local_space_dim(ls, isl_dim_all) != total) isl_die(isl_local_space_get_ctx(ls), isl_error_invalid, - "dimensions don't match", goto error); + "spaces don't match", goto error); total++; n_div = eq->n_div; for (i = 0; i < eq->n_eq; ++i) { @@ -750,14 +753,15 @@ error: return NULL; } -/* Plug in "subs" for dimension "type", "pos" in the integer divisions - * of "ls". +/* Plug in the affine expressions "subs" of length "subs_len" (including + * the denominator and the constant term) into the variable at position "pos" + * of the "n" div expressions starting at "first". * * Let i be the dimension to replace and let "subs" be of the form * * f/d * - * Any integer division with a non-zero coefficient for i, + * Any integer division starting at "first" with a non-zero coefficient for i, * * floor((a i + g)/m) * @@ -765,38 +769,35 @@ error: * * floor((a f + d g)/(m d)) */ -__isl_give isl_local_space *isl_local_space_substitute( +__isl_give isl_local_space *isl_local_space_substitute_seq( __isl_take isl_local_space *ls, - enum isl_dim_type type, unsigned pos, __isl_keep isl_aff *subs) + enum isl_dim_type type, unsigned pos, isl_int *subs, int subs_len, + int first, int n) { int i; isl_int v; + if (n == 0) + return ls; ls = isl_local_space_cow(ls); - if (!ls || !subs) + if (!ls) + return NULL; + ls->div = isl_mat_cow(ls->div); + if (!ls->div) return isl_local_space_free(ls); - if (!isl_space_is_equal(ls->dim, subs->ls->dim)) + if (first + n > ls->div->n_row) isl_die(isl_local_space_get_ctx(ls), isl_error_invalid, - "spaces don't match", return isl_local_space_free(ls)); - if (isl_local_space_dim(subs->ls, isl_dim_div) != 0) - isl_die(isl_local_space_get_ctx(ls), isl_error_unsupported, - "cannot handle divs yet", - return isl_local_space_free(ls)); + "index out of bounds", return isl_local_space_free(ls)); pos += isl_local_space_offset(ls, type); isl_int_init(v); - for (i = 0; i < ls->div->n_row; ++i) { + for (i = first; i < ls->div->n_row; ++i) { if (isl_int_is_zero(ls->div->row[i][1 + pos])) continue; - isl_int_set(v, ls->div->row[i][1 + pos]); - isl_int_set_si(ls->div->row[i][1 + pos], 0); - isl_seq_combine(ls->div->row[i] + 1, - subs->v->el[0], ls->div->row[i] + 1, - v, subs->v->el + 1, subs->v->size - 1); - isl_int_mul(ls->div->row[i][0], - ls->div->row[i][0], subs->v->el[0]); + isl_seq_substitute(ls->div->row[i], pos, subs, + ls->div->n_col, subs_len, v); normalize_div(ls, i); } isl_int_clear(v); @@ -804,6 +805,41 @@ __isl_give isl_local_space *isl_local_space_substitute( return ls; } +/* Plug in "subs" for dimension "type", "pos" in the integer divisions + * of "ls". + * + * Let i be the dimension to replace and let "subs" be of the form + * + * f/d + * + * Any integer division with a non-zero coefficient for i, + * + * floor((a i + g)/m) + * + * is replaced by + * + * floor((a f + d g)/(m d)) + */ +__isl_give isl_local_space *isl_local_space_substitute( + __isl_take isl_local_space *ls, + enum isl_dim_type type, unsigned pos, __isl_keep isl_aff *subs) +{ + ls = isl_local_space_cow(ls); + if (!ls || !subs) + return isl_local_space_free(ls); + + if (!isl_space_is_equal(ls->dim, subs->ls->dim)) + isl_die(isl_local_space_get_ctx(ls), isl_error_invalid, + "spaces don't match", return isl_local_space_free(ls)); + if (isl_local_space_dim(subs->ls, isl_dim_div) != 0) + isl_die(isl_local_space_get_ctx(ls), isl_error_unsupported, + "cannot handle divs yet", + return isl_local_space_free(ls)); + + return isl_local_space_substitute_seq(ls, type, pos, subs->v->el, + subs->v->size, 0, ls->div->n_row); +} + int isl_local_space_is_named_or_nested(__isl_keep isl_local_space *ls, enum isl_dim_type type) { @@ -1007,3 +1043,85 @@ __isl_give isl_basic_map *isl_local_space_lifting( return lifting; } + +/* Compute the preimage of "ls" under the function represented by "ma". + * In other words, plug in "ma" in "ls". The result is a local space + * that is part of the domain space of "ma". + * + * If the divs in "ls" are represented as + * + * floor((a_i(p) + b_i x + c_i(divs))/n_i) + * + * and ma is represented by + * + * x = D(p) + F(y) + G(divs') + * + * then the resulting divs are + * + * floor((a_i(p) + b_i D(p) + b_i F(y) + B_i G(divs') + c_i(divs))/n_i) + * + * We first copy over the divs from "ma" and then + * we add the modified divs from "ls". + */ +__isl_give isl_local_space *isl_local_space_preimage_multi_aff( + __isl_take isl_local_space *ls, __isl_take isl_multi_aff *ma) +{ + int i; + isl_space *space; + isl_local_space *res = NULL; + int n_div_ls, n_div_ma; + isl_int f, c1, c2, g; + + ma = isl_multi_aff_align_divs(ma); + if (!ls || !ma) + goto error; + if (!isl_space_is_range_internal(ls->dim, ma->space)) + isl_die(isl_local_space_get_ctx(ls), isl_error_invalid, + "spaces don't match", goto error); + + n_div_ls = isl_local_space_dim(ls, isl_dim_div); + n_div_ma = ma->n ? isl_aff_dim(ma->p[0], isl_dim_div) : 0; + + space = isl_space_domain(isl_multi_aff_get_space(ma)); + res = isl_local_space_alloc(space, n_div_ma + n_div_ls); + if (!res) + goto error; + + if (n_div_ma) { + isl_mat_free(res->div); + res->div = isl_mat_copy(ma->p[0]->ls->div); + res->div = isl_mat_add_zero_cols(res->div, n_div_ls); + res->div = isl_mat_add_rows(res->div, n_div_ls); + if (!res->div) + goto error; + } + + isl_int_init(f); + isl_int_init(c1); + isl_int_init(c2); + isl_int_init(g); + + for (i = 0; i < ls->div->n_row; ++i) { + if (isl_int_is_zero(ls->div->row[i][0])) { + isl_int_set_si(res->div->row[n_div_ma + i][0], 0); + continue; + } + isl_seq_preimage(res->div->row[n_div_ma + i], ls->div->row[i], + ma, 0, 0, n_div_ma, n_div_ls, f, c1, c2, g, 1); + normalize_div(res, n_div_ma + i); + } + + isl_int_clear(f); + isl_int_clear(c1); + isl_int_clear(c2); + isl_int_clear(g); + + isl_local_space_free(ls); + isl_multi_aff_free(ma); + return res; +error: + isl_local_space_free(ls); + isl_multi_aff_free(ma); + isl_local_space_free(res); + return NULL; +}