isl_map_coalesce: eliminate unit divs from wrapping constraints
[isl.git] / isl_pw_opt_templ.c
blob421b4d52e222035642bac154bbc15c3250d4e5aa
1 /*
2 * Copyright 2010 INRIA Saclay
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
8 * 91893 Orsay, France
9 */
11 /* Compute the maximal value attained by the piecewise quasipolynomial
12 * on its domain or zero if the domain is empty.
13 * In the worst case, the domain is scanned completely,
14 * so the domain is assumed to be bounded.
16 __isl_give isl_val *FN(PW,opt)(__isl_take PW *pw, int max)
18 int i;
19 isl_val *opt;
21 if (!pw)
22 return NULL;
24 if (pw->n == 0) {
25 opt = isl_val_zero(FN(PW,get_ctx)(pw));
26 FN(PW,free)(pw);
27 return opt;
30 opt = FN(EL,opt_on_domain)(FN(EL,copy)(pw->p[0].FIELD),
31 isl_set_copy(pw->p[0].set), max);
32 for (i = 1; i < pw->n; ++i) {
33 isl_val *opt_i;
34 opt_i = FN(EL,opt_on_domain)(FN(EL,copy)(pw->p[i].FIELD),
35 isl_set_copy(pw->p[i].set), max);
36 if (max)
37 opt = isl_val_max(opt, opt_i);
38 else
39 opt = isl_val_min(opt, opt_i);
42 FN(PW,free)(pw);
43 return opt;
46 __isl_give isl_val *FN(PW,max)(__isl_take PW *pw)
48 return FN(PW,opt)(pw, 1);
51 __isl_give isl_val *FN(PW,min)(__isl_take PW *pw)
53 return FN(PW,opt)(pw, 0);