isl_aff_add_constant_val: extract out isl_aff_add_rat_constant_val
[isl.git] / isl_union_eval.c
blob0eaef638b54231ab8f4b2bfc12a9ed4503b043b9
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 #include <isl_union_macro.h>
13 /* Evaluate "u" in the void point "pnt".
14 * In particular, return the value NaN.
16 static __isl_give isl_val *FN(UNION,eval_void)(__isl_take UNION *u,
17 __isl_take isl_point *pnt)
19 isl_ctx *ctx;
21 ctx = isl_point_get_ctx(pnt);
22 FN(UNION,free)(u);
23 isl_point_free(pnt);
24 return isl_val_nan(ctx);
27 /* Do the tuples of "space" correspond to those of the domain of "part"?
28 * That is, is the domain space of "part" equal to "space", ignoring parameters?
30 static isl_bool FN(UNION,has_domain_space_tuples)(const void *entry,
31 const void *val)
33 PART *part = (PART *)entry;
34 isl_space *space = (isl_space *) val;
36 return FN(PART,has_domain_space_tuples)(part, space);
39 __isl_give isl_val *FN(UNION,eval)(__isl_take UNION *u,
40 __isl_take isl_point *pnt)
42 uint32_t hash;
43 struct isl_hash_table_entry *entry;
44 isl_bool is_void;
45 isl_space *space;
46 isl_val *v;
48 if (!u || !pnt)
49 goto error;
50 is_void = isl_point_is_void(pnt);
51 if (is_void < 0)
52 goto error;
53 if (is_void)
54 return FN(UNION,eval_void)(u, pnt);
56 space = isl_point_peek_space(pnt);
57 if (!space)
58 goto error;
59 hash = isl_space_get_hash(space);
60 entry = isl_hash_table_find(FN(UNION,get_ctx)(u), &u->table,
61 hash, &FN(UNION,has_domain_space_tuples),
62 space, 0);
63 if (!entry)
64 goto error;
65 if (entry == isl_hash_table_entry_none) {
66 v = isl_val_zero(isl_point_get_ctx(pnt));
67 isl_point_free(pnt);
68 } else {
69 v = FN(PART,eval)(FN(PART,copy)(entry->data), pnt);
71 FN(UNION,free)(u);
72 return v;
73 error:
74 FN(UNION,free)(u);
75 isl_point_free(pnt);
76 return NULL;