isl_map_coalesce: avoid ignoring constraints redundant wrt implicit equalities
[isl.git] / isl_opt_mpa_templ.c
blobe4245435d49646e2b005aa58cad1e62e8bf4a07f
1 /*
2 * Copyright 2018 Cerebras Systems
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege,
7 * Cerebras Systems, 175 S San Antonio Rd, Los Altos, CA, USA
8 */
10 #undef TYPE
11 #define TYPE CAT(isl_,BASE)
12 #define xFN(TYPE,NAME) TYPE ## _ ## NAME
13 #define FN(TYPE,NAME) xFN(TYPE,NAME)
15 /* Compute the optima of the set or output dimensions as a function of the
16 * parameters (and input dimensions), but independently of
17 * the other set or output dimensions,
18 * given a function "opt" that computes this optimum
19 * for a single dimension.
21 * If the resulting multi piecewise affine expression has
22 * an explicit domain, then assign it the (parameter) domain of the input.
23 * In other cases, the (parameter) domain is stored in the individual elements.
25 static __isl_give isl_multi_pw_aff *FN(BASE,opt_mpa)(__isl_take TYPE *obj,
26 __isl_give isl_pw_aff *(*opt)(__isl_take TYPE *obj, int pos))
28 int i;
29 isl_size n;
30 isl_multi_pw_aff *mpa;
32 mpa = isl_multi_pw_aff_alloc(FN(TYPE,get_space)(obj));
33 n = isl_multi_pw_aff_size(mpa);
34 if (n < 0)
35 mpa = isl_multi_pw_aff_free(mpa);
36 for (i = 0; i < n; ++i) {
37 isl_pw_aff *pa;
39 pa = opt(FN(TYPE,copy)(obj), i);
40 mpa = isl_multi_pw_aff_set_pw_aff(mpa, i, pa);
42 if (isl_multi_pw_aff_has_explicit_domain(mpa)) {
43 isl_set *dom;
45 dom = FN(TYPE,domain)(FN(TYPE,copy)(obj));
46 mpa = isl_multi_pw_aff_intersect_domain(mpa, dom);
48 FN(TYPE,free)(obj);
50 return mpa;