isl_basic_map_align_params: extract out isl_basic_map_check_space
[isl.git] / isl_multi_explicit_domain.c
blob1ab769b06048a8e473780e4149949dba06d0106c
1 /*
2 * Copyright 2017 Sven Verdoolaege
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege.
7 */
9 /* These versions of the explicit domain functions are used
10 * when the multi expression may have an explicit domain.
13 #include <isl_multi_macro.h>
15 __isl_give MULTI(BASE) *FN(MULTI(BASE),cow)(__isl_take MULTI(BASE) *multi);
17 /* Does "multi" have an explicit domain?
19 * An explicit domain is only available if "multi" is zero-dimensional.
21 static int FN(MULTI(BASE),has_explicit_domain)(__isl_keep MULTI(BASE) *multi)
23 return multi && multi->n == 0;
26 /* Check that "multi" has an explicit domain.
28 static isl_stat FN(MULTI(BASE),check_has_explicit_domain)(
29 __isl_keep MULTI(BASE) *multi)
31 if (!multi)
32 return isl_stat_error;
33 if (!FN(MULTI(BASE),has_explicit_domain)(multi))
34 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_internal,
35 "expression does not have an explicit domain",
36 return isl_stat_error);
37 return isl_stat_ok;
40 /* Return the explicit domain of "multi", assuming it has one.
42 static __isl_give DOM *FN(MULTI(BASE),get_explicit_domain)(
43 __isl_keep MULTI(BASE) *multi)
45 if (FN(MULTI(BASE),check_has_explicit_domain)(multi) < 0)
46 return NULL;
47 return FN(DOM,copy)(multi->u.dom);
50 /* Replace the explicit domain of "multi" by "dom", assuming it has one.
52 static __isl_give MULTI(BASE) *FN(MULTI(BASE),set_explicit_domain)(
53 __isl_take MULTI(BASE) *multi, __isl_take DOM *dom)
55 if (FN(MULTI(BASE),check_has_explicit_domain)(multi) < 0)
56 goto error;
57 multi = FN(MULTI(BASE),cow)(multi);
58 if (!multi || !dom)
59 goto error;
60 FN(DOM,free)(multi->u.dom);
61 multi->u.dom = dom;
62 if (!multi->u.dom)
63 return FN(MULTI(BASE),free)(multi);
64 return multi;
65 error:
66 FN(MULTI(BASE),free)(multi);
67 FN(DOM,free)(dom);
68 return NULL;
71 /* Intersect the domain of "dst" with the explicit domain of "src".
73 static __isl_give MULTI(BASE) *FN(MULTI(BASE),intersect_explicit_domain)(
74 __isl_take MULTI(BASE) *dst, __isl_keep MULTI(BASE) *src)
76 DOM *dom;
78 dom = FN(MULTI(BASE),get_explicit_domain)(src);
79 dst = FN(MULTI(BASE),intersect_domain)(dst, dom);
81 return dst;
84 /* Set the explicit domain of "dst" to that of "src".
86 static __isl_give MULTI(BASE) *FN(MULTI(BASE),copy_explicit_domain)(
87 __isl_take MULTI(BASE) *dst, __isl_keep MULTI(BASE) *src)
89 DOM *dom;
91 dom = FN(MULTI(BASE),get_explicit_domain)(src);
92 dst = FN(MULTI(BASE),set_explicit_domain)(dst, dom);
94 return dst;
97 /* Align the parameters of the explicit domain of "multi" to those of "space".
99 static __isl_give MULTI(BASE) *FN(MULTI(BASE),align_explicit_domain_params)(
100 __isl_take MULTI(BASE) *multi, __isl_take isl_space *space)
102 DOM *dom;
104 dom = FN(MULTI(BASE),get_explicit_domain)(multi);
105 dom = FN(DOM,align_params)(dom, space);
106 multi = FN(MULTI(BASE),set_explicit_domain)(multi, dom);
108 return multi;
111 /* Replace the space of the explicit domain of "multi" by "space",
112 * without modifying its dimension.
114 static __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_explicit_domain_space)(
115 __isl_take MULTI(BASE) *multi, __isl_take isl_space *space)
117 DOM *dom;
119 dom = FN(MULTI(BASE),get_explicit_domain)(multi);
120 dom = FN(DOM,reset_equal_dim_space)(dom, space);
121 multi = FN(MULTI(BASE),set_explicit_domain)(multi, dom);
123 return multi;
126 /* Free the explicit domain of "multi".
128 static void FN(MULTI(BASE),free_explicit_domain)(__isl_keep MULTI(BASE) *multi)
130 if (FN(MULTI(BASE),check_has_explicit_domain)(multi) < 0)
131 return;
132 FN(DOM,free)(multi->u.dom);
135 /* Do "multi1" and "multi2" have the same explicit domain?
137 static isl_bool FN(MULTI(BASE),equal_explicit_domain)(
138 __isl_keep MULTI(BASE) *multi1, __isl_keep MULTI(BASE) *multi2)
140 DOM *dom1, *dom2;
141 isl_bool equal;
143 if (FN(MULTI(BASE),check_has_explicit_domain)(multi1) < 0 ||
144 FN(MULTI(BASE),check_has_explicit_domain)(multi2) < 0)
145 return isl_bool_error;
146 dom1 = FN(MULTI(BASE),get_explicit_domain)(multi1);
147 dom2 = FN(MULTI(BASE),get_explicit_domain)(multi2);
148 equal = FN(DOM,is_equal)(dom1, dom2);
149 FN(DOM,free)(dom1);
150 FN(DOM,free)(dom2);
152 return equal;
155 static isl_stat FN(MULTI(BASE),check_explicit_domain)(
156 __isl_keep MULTI(BASE) *multi) __attribute__ ((unused));
158 /* Debugging function to check that the explicit domain of "multi"
159 * has the correct space.
161 isl_stat FN(MULTI(BASE),check_explicit_domain)(__isl_keep MULTI(BASE) *multi)
163 isl_space *space1, *space2;
164 isl_bool equal;
166 if (FN(MULTI(BASE),check_has_explicit_domain)(multi) < 0)
167 return isl_stat_error;
168 space1 = isl_space_domain(isl_space_copy(multi->space));
169 space2 = FN(DOM,get_space)(multi->u.dom);
170 equal = isl_space_is_equal(space1, space2);
171 isl_space_free(space1);
172 isl_space_free(space2);
173 if (equal < 0)
174 return isl_stat_error;
175 if (!equal)
176 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_internal,
177 "check failed", return isl_stat_error);
178 return isl_stat_ok;