isl_multi_templ.c: extract out isl_multi_product_templ.c
[isl.git] / isl_multi_intersect.c
bloba147ec8e3238e9f59d00ca38dc95071e47403c57
1 /*
2 * Copyright 2011 Sven Verdoolaege
3 * Copyright 2012-2013 Ecole Normale Superieure
5 * Use of this software is governed by the MIT license
7 * Written by Sven Verdoolaege,
8 * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
9 */
11 #include <isl_multi_macro.h>
13 /* Does the space of "domain" correspond to that of the domain of "multi"?
14 * The parameters do not need to be aligned.
16 static isl_bool FN(MULTI(BASE),compatible_domain)(
17 __isl_keep MULTI(BASE) *multi, __isl_keep DOM *domain)
19 isl_bool ok;
20 isl_space *space, *domain_space;
22 domain_space = FN(DOM,get_space)(domain);
23 space = FN(MULTI(BASE),get_space)(multi);
24 ok = isl_space_has_domain_tuples(domain_space, space);
25 isl_space_free(space);
26 isl_space_free(domain_space);
28 return ok;
31 /* Check that the space of "domain" corresponds to
32 * that of the domain of "multi", ignoring parameters.
34 static isl_stat FN(MULTI(BASE),check_compatible_domain)(
35 __isl_keep MULTI(BASE) *multi, __isl_keep DOM *domain)
37 isl_bool ok;
39 ok = FN(MULTI(BASE),compatible_domain)(multi, domain);
40 if (ok < 0)
41 return isl_stat_error;
42 if (!ok)
43 isl_die(FN(DOM,get_ctx)(domain), isl_error_invalid,
44 "incompatible spaces", return isl_stat_error);
46 return isl_stat_ok;
49 /* Intersect the explicit domain of "multi" with "domain".
51 * The parameters of "multi" and "domain" are assumed to have been aligned.
53 * In the case of an isl_multi_union_pw_aff object, the explicit domain
54 * is allowed to have only constraints on the parameters, while
55 * "domain" contains actual domain elements. In this case,
56 * "domain" is intersected with those parameter constraints and
57 * then used as the explicit domain of "multi".
59 static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect_aligned)(
60 __isl_take MULTI(BASE) *multi, __isl_take DOM *domain)
62 isl_bool is_params;
63 DOM *multi_dom;
65 if (FN(MULTI(BASE),check_compatible_domain)(multi, domain) < 0)
66 goto error;
67 if (FN(MULTI(BASE),check_has_explicit_domain)(multi) < 0)
68 goto error;
69 is_params = FN(DOM,is_params)(multi->u.dom);
70 if (is_params < 0)
71 goto error;
72 multi_dom = FN(MULTI(BASE),get_explicit_domain)(multi);
73 if (!is_params) {
74 domain = FN(DOM,intersect)(multi_dom, domain);
75 } else {
76 isl_set *params;
78 params = FN(DOM,params)(multi_dom);
79 domain = FN(DOM,intersect_params)(domain, params);
81 multi = FN(MULTI(BASE),set_explicit_domain)(multi, domain);
82 return multi;
83 error:
84 FN(MULTI(BASE),free)(multi);
85 FN(DOM,free)(domain);
86 return NULL;
89 /* Intersect the explicit domain of "multi" with "domain".
90 * First align the parameters, if needed.
92 static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect)(
93 __isl_take MULTI(BASE) *multi, __isl_take DOM *domain)
95 return FN(FN(MULTI(BASE),align_params),DOMBASE)(multi, domain,
96 FN(MULTI(BASE),domain_intersect_aligned));
99 /* Intersect the domain of "multi" with "domain".
101 * If "multi" has an explicit domain, then only this domain
102 * needs to be intersected.
104 __isl_give MULTI(BASE) *FN(MULTI(BASE),intersect_domain)(
105 __isl_take MULTI(BASE) *multi, __isl_take DOM *domain)
107 if (FN(MULTI(BASE),has_explicit_domain)(multi))
108 return FN(MULTI(BASE),domain_intersect)(multi, domain);
109 return FN(FN(MULTI(BASE),apply),DOMBASE)(multi, domain,
110 &FN(EL,intersect_domain));
113 /* Intersect the parameter domain of the explicit domain of "multi"
114 * with "domain".
116 static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect_params_aligned)(
117 __isl_take MULTI(BASE) *multi, __isl_take isl_set *domain)
119 DOM *multi_dom;
121 multi_dom = FN(MULTI(BASE),get_explicit_domain)(multi);
122 multi_dom = FN(DOM,intersect_params)(multi_dom, domain);
123 multi = FN(MULTI(BASE),set_explicit_domain)(multi, multi_dom);
125 return multi;
128 /* Intersect the parameter domain of the explicit domain of "multi"
129 * with "domain".
130 * First align the parameters, if needed.
132 static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect_params)(
133 __isl_take MULTI(BASE) *multi, __isl_take isl_set *domain)
135 return FN(FN(MULTI(BASE),align_params),set)(multi, domain,
136 FN(MULTI(BASE),domain_intersect_params_aligned));
139 /* Intersect the parameter domain of "multi" with "domain".
141 * If "multi" has an explicit domain, then only this domain
142 * needs to be intersected.
144 __isl_give MULTI(BASE) *FN(MULTI(BASE),intersect_params)(
145 __isl_take MULTI(BASE) *multi, __isl_take isl_set *domain)
147 if (FN(MULTI(BASE),has_explicit_domain)(multi))
148 return FN(MULTI(BASE),domain_intersect_params)(multi, domain);
149 return FN(MULTI(BASE),apply_set)(multi, domain,
150 &FN(EL,intersect_params));