1*5971e316Smrg /*
2*5971e316Smrg * Copyright 2010 INRIA Saclay
3*5971e316Smrg *
4*5971e316Smrg * Use of this software is governed by the MIT license
5*5971e316Smrg *
6*5971e316Smrg * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7*5971e316Smrg * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
8*5971e316Smrg * 91893 Orsay, France
9*5971e316Smrg */
10*5971e316Smrg
11*5971e316Smrg #include <isl_union_macro.h>
12*5971e316Smrg
13*5971e316Smrg /* Evaluate "u" in the void point "pnt".
14*5971e316Smrg * In particular, return the value NaN.
15*5971e316Smrg */
FN(UNION,eval_void)16*5971e316Smrg static __isl_give isl_val *FN(UNION,eval_void)(__isl_take UNION *u,
17*5971e316Smrg __isl_take isl_point *pnt)
18*5971e316Smrg {
19*5971e316Smrg isl_ctx *ctx;
20*5971e316Smrg
21*5971e316Smrg ctx = isl_point_get_ctx(pnt);
22*5971e316Smrg FN(UNION,free)(u);
23*5971e316Smrg isl_point_free(pnt);
24*5971e316Smrg return isl_val_nan(ctx);
25*5971e316Smrg }
26*5971e316Smrg
27*5971e316Smrg /* Internal data structure for isl_union_*_eval.
28*5971e316Smrg *
29*5971e316Smrg * "pnt" is the point in which the function is evaluated.
30*5971e316Smrg * "v" stores the result and is initialized to zero.
31*5971e316Smrg */
S(UNION,eval_data)32*5971e316Smrg S(UNION,eval_data) {
33*5971e316Smrg isl_point *pnt;
34*5971e316Smrg isl_val *v;
35*5971e316Smrg };
36*5971e316Smrg
37*5971e316Smrg /* Update the evaluation in data->v based on the evaluation of "part".
38*5971e316Smrg *
39*5971e316Smrg * Only (at most) a single part on which this function is called
40*5971e316Smrg * is assumed to evaluate to anything other than zero.
41*5971e316Smrg * Since the value is initialized to zero, the evaluation of "part"
42*5971e316Smrg * can simply be added.
43*5971e316Smrg */
FN(UNION,eval_entry)44*5971e316Smrg static isl_stat FN(UNION,eval_entry)(__isl_take PART *part, void *user)
45*5971e316Smrg {
46*5971e316Smrg S(UNION,eval_data) *data = user;
47*5971e316Smrg isl_val *v;
48*5971e316Smrg
49*5971e316Smrg v = FN(PART,eval)(part, isl_point_copy(data->pnt));
50*5971e316Smrg data->v = isl_val_add(data->v, v);
51*5971e316Smrg
52*5971e316Smrg return isl_stat_non_null(data->v);
53*5971e316Smrg }
54*5971e316Smrg
55*5971e316Smrg /* Evaluate "u" in the point "pnt".
56*5971e316Smrg */
FN(UNION,eval)57*5971e316Smrg __isl_give isl_val *FN(UNION,eval)(__isl_take UNION *u,
58*5971e316Smrg __isl_take isl_point *pnt)
59*5971e316Smrg {
60*5971e316Smrg S(UNION,eval_data) data = { pnt };
61*5971e316Smrg isl_bool is_void;
62*5971e316Smrg isl_space *space;
63*5971e316Smrg
64*5971e316Smrg is_void = isl_point_is_void(pnt);
65*5971e316Smrg if (is_void < 0)
66*5971e316Smrg goto error;
67*5971e316Smrg if (is_void)
68*5971e316Smrg return FN(UNION,eval_void)(u, pnt);
69*5971e316Smrg
70*5971e316Smrg data.v = isl_val_zero(isl_point_get_ctx(pnt));
71*5971e316Smrg space = isl_point_peek_space(pnt);
72*5971e316Smrg if (FN(UNION,foreach_on_domain)(u, space,
73*5971e316Smrg &FN(UNION,eval_entry), &data) < 0)
74*5971e316Smrg data.v = isl_val_free(data.v);
75*5971e316Smrg FN(UNION,free)(u);
76*5971e316Smrg isl_point_free(pnt);
77*5971e316Smrg return data.v;
78*5971e316Smrg error:
79*5971e316Smrg FN(UNION,free)(u);
80*5971e316Smrg isl_point_free(pnt);
81*5971e316Smrg return NULL;
82*5971e316Smrg }
83