Line data Source code
1 : /*
2 : * Copyright 2011 Sven Verdoolaege
3 : * Copyright 2012-2013 Ecole Normale Superieure
4 : *
5 : * Use of this software is governed by the MIT license
6 : *
7 : * Written by Sven Verdoolaege,
8 : * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
9 : */
10 :
11 : #include <isl_multi_macro.h>
12 :
13 : /* Does the space of "domain" correspond to that of the domain of "multi"?
14 : * The parameters do not need to be aligned.
15 : */
16 0 : static isl_bool FN(MULTI(BASE),compatible_domain)(
17 : __isl_keep MULTI(BASE) *multi, __isl_keep DOM *domain)
18 : {
19 : isl_bool ok;
20 : isl_space *space, *domain_space;
21 :
22 0 : domain_space = FN(DOM,get_space)(domain);
23 0 : space = FN(MULTI(BASE),get_space)(multi);
24 0 : ok = isl_space_has_domain_tuples(domain_space, space);
25 0 : isl_space_free(space);
26 0 : isl_space_free(domain_space);
27 :
28 0 : return ok;
29 : }
30 :
31 : /* Check that the space of "domain" corresponds to
32 : * that of the domain of "multi", ignoring parameters.
33 : */
34 0 : static isl_stat FN(MULTI(BASE),check_compatible_domain)(
35 : __isl_keep MULTI(BASE) *multi, __isl_keep DOM *domain)
36 : {
37 : isl_bool ok;
38 :
39 0 : ok = FN(MULTI(BASE),compatible_domain)(multi, domain);
40 0 : if (ok < 0)
41 0 : return isl_stat_error;
42 0 : if (!ok)
43 0 : isl_die(FN(DOM,get_ctx)(domain), isl_error_invalid,
44 : "incompatible spaces", return isl_stat_error);
45 :
46 0 : return isl_stat_ok;
47 : }
48 :
49 : /* Intersect the explicit domain of "multi" with "domain".
50 : *
51 : * The parameters of "multi" and "domain" are assumed to have been aligned.
52 : *
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".
58 : */
59 0 : static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect_aligned)(
60 : __isl_take MULTI(BASE) *multi, __isl_take DOM *domain)
61 : {
62 : isl_bool is_params;
63 : DOM *multi_dom;
64 :
65 0 : if (FN(MULTI(BASE),check_compatible_domain)(multi, domain) < 0)
66 0 : goto error;
67 0 : if (FN(MULTI(BASE),check_has_explicit_domain)(multi) < 0)
68 0 : goto error;
69 0 : is_params = FN(DOM,is_params)(multi->u.dom);
70 0 : if (is_params < 0)
71 0 : goto error;
72 0 : multi_dom = FN(MULTI(BASE),get_explicit_domain)(multi);
73 0 : if (!is_params) {
74 0 : domain = FN(DOM,intersect)(multi_dom, domain);
75 : } else {
76 : isl_set *params;
77 :
78 0 : params = FN(DOM,params)(multi_dom);
79 0 : domain = FN(DOM,intersect_params)(domain, params);
80 : }
81 0 : multi = FN(MULTI(BASE),set_explicit_domain)(multi, domain);
82 0 : return multi;
83 : error:
84 0 : FN(MULTI(BASE),free)(multi);
85 0 : FN(DOM,free)(domain);
86 0 : return NULL;
87 : }
88 :
89 : /* Intersect the explicit domain of "multi" with "domain".
90 : * First align the parameters, if needed.
91 : */
92 0 : static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect)(
93 : __isl_take MULTI(BASE) *multi, __isl_take DOM *domain)
94 : {
95 0 : return FN(FN(MULTI(BASE),align_params),DOMBASE)(multi, domain,
96 : FN(MULTI(BASE),domain_intersect_aligned));
97 : }
98 :
99 : /* Intersect the domain of "multi" with "domain".
100 : *
101 : * If "multi" has an explicit domain, then only this domain
102 : * needs to be intersected.
103 : */
104 0 : __isl_give MULTI(BASE) *FN(MULTI(BASE),intersect_domain)(
105 : __isl_take MULTI(BASE) *multi, __isl_take DOM *domain)
106 : {
107 0 : if (FN(MULTI(BASE),has_explicit_domain)(multi))
108 0 : return FN(MULTI(BASE),domain_intersect)(multi, domain);
109 0 : return FN(FN(MULTI(BASE),apply),DOMBASE)(multi, domain,
110 : &FN(EL,intersect_domain));
111 : }
112 :
113 : /* Intersect the parameter domain of the explicit domain of "multi"
114 : * with "domain".
115 : */
116 0 : static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect_params_aligned)(
117 : __isl_take MULTI(BASE) *multi, __isl_take isl_set *domain)
118 : {
119 : DOM *multi_dom;
120 :
121 0 : multi_dom = FN(MULTI(BASE),get_explicit_domain)(multi);
122 0 : multi_dom = FN(DOM,intersect_params)(multi_dom, domain);
123 0 : multi = FN(MULTI(BASE),set_explicit_domain)(multi, multi_dom);
124 :
125 0 : return multi;
126 : }
127 :
128 : /* Intersect the parameter domain of the explicit domain of "multi"
129 : * with "domain".
130 : * First align the parameters, if needed.
131 : */
132 0 : static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect_params)(
133 : __isl_take MULTI(BASE) *multi, __isl_take isl_set *domain)
134 : {
135 0 : return FN(FN(MULTI(BASE),align_params),set)(multi, domain,
136 : FN(MULTI(BASE),domain_intersect_params_aligned));
137 : }
138 :
139 : /* Intersect the parameter domain of "multi" with "domain".
140 : *
141 : * If "multi" has an explicit domain, then only this domain
142 : * needs to be intersected.
143 : */
144 0 : __isl_give MULTI(BASE) *FN(MULTI(BASE),intersect_params)(
145 : __isl_take MULTI(BASE) *multi, __isl_take isl_set *domain)
146 : {
147 0 : if (FN(MULTI(BASE),has_explicit_domain)(multi))
148 0 : return FN(MULTI(BASE),domain_intersect_params)(multi, domain);
149 0 : return FN(MULTI(BASE),apply_set)(multi, domain,
150 : &FN(EL,intersect_params));
151 : }
|