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