struct isl_basic_map *dst, struct isl_basic_map *src)
{
int i;
- unsigned total = isl_space_dim(src->dim, isl_dim_all);
+ unsigned total;
if (!dst || !src)
goto error;
src->n_div, 0, 2 * src->n_div);
if (!dst)
return NULL;
+ total = isl_space_dim(src->dim, isl_dim_all);
for (i = 0; i < src->n_div; ++i) {
int j = find_div(dst, src, i);
if (j < 0) {
* are replaced by
*
* a f + d g
+ *
+ * We currently require that "subs" is an integral expression.
+ * Handling rational expressions may require us to add stride constraints
+ * as we do in isl_basic_set_preimage_multi_aff.
*/
__isl_give isl_basic_set *isl_basic_set_substitute(
__isl_take isl_basic_set *bset,
if (isl_local_space_dim(subs->ls, isl_dim_div) != 0)
isl_die(ctx, isl_error_unsupported,
"cannot handle divs yet", goto error);
+ if (!isl_int_is_one(subs->v->el[0]))
+ isl_die(ctx, isl_error_invalid,
+ "can only substitute integer expressions", goto error);
pos += isl_basic_set_offset(bset, type);
isl_multi_aff_free(ma);
return isl_set_free(set);
}
+
+/* Compute the preimage of "set" under the function represented by "pma".
+ * In other words, plug in "pma" in "set. The result is a set
+ * that lives in the domain space of "pma".
+ */
+static __isl_give isl_set *set_preimage_pw_multi_aff(__isl_take isl_set *set,
+ __isl_take isl_pw_multi_aff *pma)
+{
+ int i;
+ isl_set *res;
+
+ if (!pma)
+ goto error;
+
+ if (pma->n == 0) {
+ isl_pw_multi_aff_free(pma);
+ res = isl_set_empty(isl_set_get_space(set));
+ isl_set_free(set);
+ return res;
+ }
+
+ res = isl_set_preimage_multi_aff(isl_set_copy(set),
+ isl_multi_aff_copy(pma->p[0].maff));
+ res = isl_set_intersect(res, isl_set_copy(pma->p[0].set));
+
+ for (i = 1; i < pma->n; ++i) {
+ isl_set *res_i;
+
+ res_i = isl_set_preimage_multi_aff(isl_set_copy(set),
+ isl_multi_aff_copy(pma->p[i].maff));
+ res_i = isl_set_intersect(res_i, isl_set_copy(pma->p[i].set));
+ res = isl_set_union(res, res_i);
+ }
+
+ isl_pw_multi_aff_free(pma);
+ isl_set_free(set);
+ return res;
+error:
+ isl_pw_multi_aff_free(pma);
+ isl_set_free(set);
+ return NULL;
+}
+
+__isl_give isl_set *isl_set_preimage_pw_multi_aff(__isl_take isl_set *set,
+ __isl_take isl_pw_multi_aff *pma)
+{
+ if (!set || !pma)
+ goto error;
+
+ if (isl_space_match(set->dim, isl_dim_param, pma->dim, isl_dim_param))
+ return set_preimage_pw_multi_aff(set, pma);
+
+ if (!isl_space_has_named_params(set->dim) ||
+ !isl_space_has_named_params(pma->dim))
+ isl_die(set->ctx, isl_error_invalid,
+ "unaligned unnamed parameters", goto error);
+ set = isl_set_align_params(set, isl_pw_multi_aff_get_space(pma));
+ pma = isl_pw_multi_aff_align_params(pma, isl_set_get_space(set));
+
+ return set_preimage_pw_multi_aff(set, pma);
+error:
+ isl_pw_multi_aff_free(pma);
+ return isl_set_free(set);
+}