Polly 19.0.0git
isl_pw_eval.c
Go to the documentation of this file.
1/*
2 * Copyright 2010 INRIA Saclay
3 * Copyright 2013 Ecole Normale Superieure
4 *
5 * Use of this software is governed by the MIT license
6 *
7 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
8 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
9 * 91893 Orsay, France
10 * and Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
11 */
12
13#include <isl/val.h>
14#include <isl_space_private.h>
15#include <isl_point_private.h>
16
17#include <isl_pw_macro.h>
18
19#undef SUFFIX
20#define SUFFIX point
21#undef ARG1
22#define ARG1 PW
23#undef ARG2
24#define ARG2 isl_point
25
26static
28
29/* Evaluate "pw" in the void point "pnt".
30 * In particular, return the value NaN.
31 */
34{
35 isl_ctx *ctx;
36
37 ctx = isl_point_get_ctx(pnt);
38 FN(PW,free)(pw);
39 isl_point_free(pnt);
40 return isl_val_nan(ctx);
41}
42
43/* Evaluate the piecewise function "pw" in "pnt".
44 * If the point is void, then return NaN.
45 * If the point lies outside the domain of "pw", then return 0 or NaN
46 * depending on whether 0 is the default value for this type of function.
47 *
48 * Align the parameters if needed, but "pnt" should specify a value
49 * for all parameters in "pw".
50 */
52{
53 int i;
54 isl_bool is_void;
55 isl_bool found;
56 isl_ctx *ctx;
57 isl_bool ok;
58 isl_space *pnt_space, *pw_space;
59 isl_val *v;
60
61 FN(PW,align_params_point)(&pw, &pnt);
62
63 pnt_space = isl_point_peek_space(pnt);
64 pw_space = FN(PW,peek_space)(pw);
65 ok = isl_space_is_domain_internal(pnt_space, pw_space);
66 if (ok < 0)
67 goto error;
68 ctx = isl_point_get_ctx(pnt);
69 if (!ok)
71 "incompatible spaces", goto error);
72 is_void = isl_point_is_void(pnt);
73 if (is_void < 0)
74 goto error;
75 if (is_void)
76 return FN(PW,eval_void)(pw, pnt);
77
78 found = isl_bool_false;
79 for (i = 0; i < pw->n; ++i) {
80 found = isl_set_contains_point(pw->p[i].set, pnt);
81 if (found < 0)
82 goto error;
83 if (found)
84 break;
85 }
86 if (found) {
87 v = FN(EL,eval)(FN(EL,copy)(pw->p[i].FIELD),
88 isl_point_copy(pnt));
89 } else if (DEFAULT_IS_ZERO) {
90 v = isl_val_zero(ctx);
91 } else {
92 v = isl_val_nan(ctx);
93 }
94 FN(PW,free)(pw);
95 isl_point_free(pnt);
96 return v;
97error:
98 FN(PW,free)(pw);
99 isl_point_free(pnt);
100 return NULL;
101}
#define FN(TYPE, NAME)
#define __isl_take
Definition: ctx.h:22
#define __isl_give
Definition: ctx.h:19
#define isl_die(ctx, errno, msg, code)
Definition: ctx.h:137
@ isl_error_invalid
Definition: ctx.h:80
isl_bool
Definition: ctx.h:89
@ isl_bool_false
Definition: ctx.h:91
static __isl_give isl_val * eval_void(__isl_take isl_aff *aff, __isl_take isl_point *pnt)
Definition: isl_aff.c:9943
#define DEFAULT_IS_ZERO
Definition: isl_aff.c:4594
#define PW
Definition: isl_aff.c:4582
static __isl_give isl_val * eval(__isl_keep isl_vec *aff, __isl_keep isl_vec *pnt)
Definition: isl_aff.c:9957
#define EL
isl_bool isl_set_contains_point(__isl_keep isl_set *set, __isl_keep isl_point *point)
Definition: isl_point.c:668
__isl_keep isl_space * isl_point_peek_space(__isl_keep isl_point *pnt)
Definition: isl_point.c:39
isl_bool isl_space_is_domain_internal(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition: isl_space.c:2599
isl_bool isl_point_is_void(__isl_keep isl_point *pnt)
Definition: isl_point.c:172
__isl_give isl_point * isl_point_copy(__isl_keep isl_point *pnt)
Definition: isl_point.c:141
__isl_null isl_point * isl_point_free(__isl_take isl_point *pnt)
Definition: isl_point.c:150
isl_ctx * isl_point_get_ctx(__isl_keep isl_point *pnt)
Definition: isl_point.c:32
__isl_export __isl_give isl_val * isl_val_zero(isl_ctx *ctx)
Definition: isl_val.c:41
__isl_export __isl_give isl_val * isl_val_nan(isl_ctx *ctx)
Definition: isl_val.c:62