isl_test.c: before_for: explicitly check that depth has not become negative
[isl.git] / isl_union_eval.c
blob4ddaeef431c811d579b188512b70df0b83bdf059
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_space_copy(pnt->dim);
57 if (!space)
58 goto error;
59 hash = isl_space_get_hash(space);
60 entry = isl_hash_table_find(u->space->ctx, &u->table,
61 hash, &FN(UNION,has_domain_space_tuples),
62 space, 0);
63 isl_space_free(space);
64 if (!entry)
65 goto error;
66 if (entry == isl_hash_table_entry_none) {
67 v = isl_val_zero(isl_point_get_ctx(pnt));
68 isl_point_free(pnt);
69 } else {
70 v = FN(PART,eval)(FN(PART,copy)(entry->data), pnt);
72 FN(UNION,free)(u);
73 return v;
74 error:
75 FN(UNION,free)(u);
76 isl_point_free(pnt);
77 return NULL;