/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/polly/lib/External/isl/isl_pw_union_opt.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2011 INRIA Saclay |
3 | | * Copyright 2012 Ecole Normale Superieure |
4 | | * |
5 | | * Use of this software is governed by the MIT license |
6 | | * |
7 | | * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France, |
8 | | * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod, |
9 | | * 91893 Orsay, France |
10 | | * and Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France |
11 | | */ |
12 | | |
13 | | #include <isl_pw_macro.h> |
14 | | |
15 | | /* Given a function "cmp" that returns the set of elements where |
16 | | * "el1" is "better" than "el2", return this set. |
17 | | */ |
18 | | static __isl_give isl_set *FN(PW,better)(__isl_keep EL *el1, __isl_keep EL *el2, |
19 | | __isl_give isl_set *(*cmp)(__isl_take EL *el1, __isl_take EL *el2)) |
20 | 1.73k | { |
21 | 1.73k | return cmp(FN(EL,copy)(el1), FN(EL,copy)(el2)); |
22 | 1.73k | } isl_aff.c:isl_pw_aff_better Line | Count | Source | 20 | 376 | { | 21 | 376 | return cmp(FN(EL,copy)(el1), FN(EL,copy)(el2)); | 22 | 376 | } |
isl_aff.c:isl_pw_multi_aff_better Line | Count | Source | 20 | 1.35k | { | 21 | 1.35k | return cmp(FN(EL,copy)(el1), FN(EL,copy)(el2)); | 22 | 1.35k | } |
|
23 | | |
24 | | /* Return a list containing the domains of the pieces of "pw". |
25 | | */ |
26 | | static __isl_give isl_set_list *FN(PW,extract_domains)(__isl_keep PW *pw) |
27 | 3.48k | { |
28 | 3.48k | int i; |
29 | 3.48k | isl_ctx *ctx; |
30 | 3.48k | isl_set_list *list; |
31 | 3.48k | |
32 | 3.48k | if (!pw) |
33 | 0 | return NULL; |
34 | 3.48k | ctx = FN(PW,get_ctx)(pw); |
35 | 3.48k | list = isl_set_list_alloc(ctx, pw->n); |
36 | 10.0k | for (i = 0; i < pw->n; ++i6.61k ) |
37 | 6.61k | list = isl_set_list_add(list, isl_set_copy(pw->p[i].set)); |
38 | 3.48k | |
39 | 3.48k | return list; |
40 | 3.48k | } isl_aff.c:isl_pw_aff_extract_domains Line | Count | Source | 27 | 734 | { | 28 | 734 | int i; | 29 | 734 | isl_ctx *ctx; | 30 | 734 | isl_set_list *list; | 31 | 734 | | 32 | 734 | if (!pw) | 33 | 0 | return NULL; | 34 | 734 | ctx = FN(PW,get_ctx)(pw); | 35 | 734 | list = isl_set_list_alloc(ctx, pw->n); | 36 | 1.51k | for (i = 0; i < pw->n; ++i776 ) | 37 | 776 | list = isl_set_list_add(list, isl_set_copy(pw->p[i].set)); | 38 | 734 | | 39 | 734 | return list; | 40 | 734 | } |
isl_aff.c:isl_pw_multi_aff_extract_domains Line | Count | Source | 27 | 2.74k | { | 28 | 2.74k | int i; | 29 | 2.74k | isl_ctx *ctx; | 30 | 2.74k | isl_set_list *list; | 31 | 2.74k | | 32 | 2.74k | if (!pw) | 33 | 0 | return NULL; | 34 | 2.74k | ctx = FN(PW,get_ctx)(pw); | 35 | 2.74k | list = isl_set_list_alloc(ctx, pw->n); | 36 | 8.58k | for (i = 0; i < pw->n; ++i5.84k ) | 37 | 5.84k | list = isl_set_list_add(list, isl_set_copy(pw->p[i].set)); | 38 | 2.74k | | 39 | 2.74k | return list; | 40 | 2.74k | } |
|
41 | | |
42 | | /* Given sets B ("set"), C ("better") and A' ("out"), return |
43 | | * |
44 | | * (B \cap C) \cup ((B \setminus C) \setminus A') |
45 | | */ |
46 | | static __isl_give isl_set *FN(PW,better_or_out)(__isl_take isl_set *set, |
47 | | __isl_take isl_set *better, __isl_take isl_set *out) |
48 | 1.73k | { |
49 | 1.73k | isl_set *set_better, *set_out; |
50 | 1.73k | |
51 | 1.73k | set_better = isl_set_intersect(isl_set_copy(set), isl_set_copy(better)); |
52 | 1.73k | set_out = isl_set_subtract(isl_set_subtract(set, better), out); |
53 | 1.73k | |
54 | 1.73k | return isl_set_union(set_better, set_out); |
55 | 1.73k | } isl_aff.c:isl_pw_aff_better_or_out Line | Count | Source | 48 | 376 | { | 49 | 376 | isl_set *set_better, *set_out; | 50 | 376 | | 51 | 376 | set_better = isl_set_intersect(isl_set_copy(set), isl_set_copy(better)); | 52 | 376 | set_out = isl_set_subtract(isl_set_subtract(set, better), out); | 53 | 376 | | 54 | 376 | return isl_set_union(set_better, set_out); | 55 | 376 | } |
isl_aff.c:isl_pw_multi_aff_better_or_out Line | Count | Source | 48 | 1.35k | { | 49 | 1.35k | isl_set *set_better, *set_out; | 50 | 1.35k | | 51 | 1.35k | set_better = isl_set_intersect(isl_set_copy(set), isl_set_copy(better)); | 52 | 1.35k | set_out = isl_set_subtract(isl_set_subtract(set, better), out); | 53 | 1.35k | | 54 | 1.35k | return isl_set_union(set_better, set_out); | 55 | 1.35k | } |
|
56 | | |
57 | | /* Given sets A ("set"), C ("better") and B' ("out"), return |
58 | | * |
59 | | * (A \setminus C) \cup ((A \cap C) \setminus B') |
60 | | */ |
61 | | static __isl_give isl_set *FN(PW,worse_or_out)(__isl_take isl_set *set, |
62 | | __isl_take isl_set *better, __isl_take isl_set *out) |
63 | 1.73k | { |
64 | 1.73k | isl_set *set_worse, *set_out; |
65 | 1.73k | |
66 | 1.73k | set_worse = isl_set_subtract(isl_set_copy(set), isl_set_copy(better)); |
67 | 1.73k | set_out = isl_set_subtract(isl_set_intersect(set, better), out); |
68 | 1.73k | |
69 | 1.73k | return isl_set_union(set_worse, set_out); |
70 | 1.73k | } isl_aff.c:isl_pw_aff_worse_or_out Line | Count | Source | 63 | 376 | { | 64 | 376 | isl_set *set_worse, *set_out; | 65 | 376 | | 66 | 376 | set_worse = isl_set_subtract(isl_set_copy(set), isl_set_copy(better)); | 67 | 376 | set_out = isl_set_subtract(isl_set_intersect(set, better), out); | 68 | 376 | | 69 | 376 | return isl_set_union(set_worse, set_out); | 70 | 376 | } |
isl_aff.c:isl_pw_multi_aff_worse_or_out Line | Count | Source | 63 | 1.35k | { | 64 | 1.35k | isl_set *set_worse, *set_out; | 65 | 1.35k | | 66 | 1.35k | set_worse = isl_set_subtract(isl_set_copy(set), isl_set_copy(better)); | 67 | 1.35k | set_out = isl_set_subtract(isl_set_intersect(set, better), out); | 68 | 1.35k | | 69 | 1.35k | return isl_set_union(set_worse, set_out); | 70 | 1.35k | } |
|
71 | | |
72 | | /* Given two piecewise expressions "pw1" and "pw2", replace their domains |
73 | | * by the sets in "list1" and "list2" and combine the results into |
74 | | * a single piecewise expression. |
75 | | * The pieces of "pw1" and "pw2" are assumed to have been sorted |
76 | | * according to the function value expressions. |
77 | | * The pieces of the result are also sorted in this way. |
78 | | * |
79 | | * Run through the pieces of "pw1" and "pw2" in order until they |
80 | | * have both been exhausted, picking the piece from "pw1" or "pw2" |
81 | | * depending on which should come first, together with the corresponding |
82 | | * domain from "list1" or "list2". In cases where the next pieces |
83 | | * in both "pw1" and "pw2" have the same function value expression, |
84 | | * construct only a single piece in the result with as domain |
85 | | * the union of the domains in "list1" and "list2". |
86 | | */ |
87 | | static __isl_give PW *FN(PW,merge)(__isl_take PW *pw1, __isl_take PW *pw2, |
88 | | __isl_take isl_set_list *list1, __isl_take isl_set_list *list2) |
89 | 1.74k | { |
90 | 1.74k | int i, j; |
91 | 1.74k | PW *res; |
92 | 1.74k | |
93 | 1.74k | if (!pw1 || !pw2) |
94 | 0 | goto error; |
95 | 1.74k | |
96 | 1.74k | res = FN(PW,alloc_size)(isl_space_copy(pw1->dim), pw1->n + pw2->n); |
97 | 1.74k | |
98 | 1.74k | i = 0; j = 0; |
99 | 7.81k | while (i < pw1->n || j < pw2->n2.43k ) { |
100 | 6.07k | int cmp; |
101 | 6.07k | isl_set *set; |
102 | 6.07k | EL *el; |
103 | 6.07k | |
104 | 6.07k | if (i < pw1->n && j < pw2->n5.37k ) |
105 | 3.60k | cmp = FN(EL,plain_cmp)(pw1->p[i].FIELD, |
106 | 3.60k | pw2->p[j].FIELD); |
107 | 2.47k | else |
108 | 2.47k | cmp = i < pw1->n ? -11.77k : 1693 ; |
109 | 6.07k | |
110 | 6.07k | if (cmp < 0) { |
111 | 4.22k | set = isl_set_list_get_set(list1, i); |
112 | 4.22k | el = FN(EL,copy)(pw1->p[i].FIELD); |
113 | 4.22k | ++i; |
114 | 4.22k | } else if (1.84k cmp > 01.84k ) { |
115 | 1.30k | set = isl_set_list_get_set(list2, j); |
116 | 1.30k | el = FN(EL,copy)(pw2->p[j].FIELD); |
117 | 1.30k | ++j; |
118 | 1.30k | } else { |
119 | 544 | set = isl_set_union(isl_set_list_get_set(list1, i), |
120 | 544 | isl_set_list_get_set(list2, j)); |
121 | 544 | el = FN(EL,copy)(pw1->p[i].FIELD); |
122 | 544 | ++i; |
123 | 544 | ++j; |
124 | 544 | } |
125 | 6.07k | res = FN(PW,add_piece)(res, set, el); |
126 | 6.07k | } |
127 | 1.74k | |
128 | 1.74k | isl_set_list_free(list1); |
129 | 1.74k | isl_set_list_free(list2); |
130 | 1.74k | FN(PW,free)(pw1); |
131 | 1.74k | FN(PW,free)(pw2); |
132 | 1.74k | return res; |
133 | 1.74k | error: |
134 | 0 | isl_set_list_free(list1); |
135 | 0 | isl_set_list_free(list2); |
136 | 0 | FN(PW,free)(pw1); |
137 | 0 | FN(PW,free)(pw2); |
138 | 0 | return NULL; |
139 | 1.74k | } isl_aff.c:isl_pw_aff_merge Line | Count | Source | 89 | 367 | { | 90 | 367 | int i, j; | 91 | 367 | PW *res; | 92 | 367 | | 93 | 367 | if (!pw1 || !pw2) | 94 | 0 | goto error; | 95 | 367 | | 96 | 367 | res = FN(PW,alloc_size)(isl_space_copy(pw1->dim), pw1->n + pw2->n); | 97 | 367 | | 98 | 367 | i = 0; j = 0; | 99 | 1.12k | while (i < pw1->n || j < pw2->n547 ) { | 100 | 758 | int cmp; | 101 | 758 | isl_set *set; | 102 | 758 | EL *el; | 103 | 758 | | 104 | 758 | if (i < pw1->n && j < pw2->n578 ) | 105 | 395 | cmp = FN(EL,plain_cmp)(pw1->p[i].FIELD, | 106 | 395 | pw2->p[j].FIELD); | 107 | 363 | else | 108 | 363 | cmp = i < pw1->n ? -1183 : 1180 ; | 109 | 758 | | 110 | 758 | if (cmp < 0) { | 111 | 391 | set = isl_set_list_get_set(list1, i); | 112 | 391 | el = FN(EL,copy)(pw1->p[i].FIELD); | 113 | 391 | ++i; | 114 | 391 | } else if (367 cmp > 0367 ) { | 115 | 349 | set = isl_set_list_get_set(list2, j); | 116 | 349 | el = FN(EL,copy)(pw2->p[j].FIELD); | 117 | 349 | ++j; | 118 | 349 | } else { | 119 | 18 | set = isl_set_union(isl_set_list_get_set(list1, i), | 120 | 18 | isl_set_list_get_set(list2, j)); | 121 | 18 | el = FN(EL,copy)(pw1->p[i].FIELD); | 122 | 18 | ++i; | 123 | 18 | ++j; | 124 | 18 | } | 125 | 758 | res = FN(PW,add_piece)(res, set, el); | 126 | 758 | } | 127 | 367 | | 128 | 367 | isl_set_list_free(list1); | 129 | 367 | isl_set_list_free(list2); | 130 | 367 | FN(PW,free)(pw1); | 131 | 367 | FN(PW,free)(pw2); | 132 | 367 | return res; | 133 | 367 | error: | 134 | 0 | isl_set_list_free(list1); | 135 | 0 | isl_set_list_free(list2); | 136 | 0 | FN(PW,free)(pw1); | 137 | 0 | FN(PW,free)(pw2); | 138 | 0 | return NULL; | 139 | 367 | } |
isl_aff.c:isl_pw_multi_aff_merge Line | Count | Source | 89 | 1.37k | { | 90 | 1.37k | int i, j; | 91 | 1.37k | PW *res; | 92 | 1.37k | | 93 | 1.37k | if (!pw1 || !pw2) | 94 | 0 | goto error; | 95 | 1.37k | | 96 | 1.37k | res = FN(PW,alloc_size)(isl_space_copy(pw1->dim), pw1->n + pw2->n); | 97 | 1.37k | | 98 | 1.37k | i = 0; j = 0; | 99 | 6.68k | while (i < pw1->n || j < pw2->n1.88k ) { | 100 | 5.31k | int cmp; | 101 | 5.31k | isl_set *set; | 102 | 5.31k | EL *el; | 103 | 5.31k | | 104 | 5.31k | if (i < pw1->n && j < pw2->n4.80k ) | 105 | 3.20k | cmp = FN(EL,plain_cmp)(pw1->p[i].FIELD, | 106 | 3.20k | pw2->p[j].FIELD); | 107 | 2.10k | else | 108 | 2.10k | cmp = i < pw1->n ? -11.59k : 1513 ; | 109 | 5.31k | | 110 | 5.31k | if (cmp < 0) { | 111 | 3.83k | set = isl_set_list_get_set(list1, i); | 112 | 3.83k | el = FN(EL,copy)(pw1->p[i].FIELD); | 113 | 3.83k | ++i; | 114 | 3.83k | } else if (1.48k cmp > 01.48k ) { | 115 | 954 | set = isl_set_list_get_set(list2, j); | 116 | 954 | el = FN(EL,copy)(pw2->p[j].FIELD); | 117 | 954 | ++j; | 118 | 954 | } else { | 119 | 526 | set = isl_set_union(isl_set_list_get_set(list1, i), | 120 | 526 | isl_set_list_get_set(list2, j)); | 121 | 526 | el = FN(EL,copy)(pw1->p[i].FIELD); | 122 | 526 | ++i; | 123 | 526 | ++j; | 124 | 526 | } | 125 | 5.31k | res = FN(PW,add_piece)(res, set, el); | 126 | 5.31k | } | 127 | 1.37k | | 128 | 1.37k | isl_set_list_free(list1); | 129 | 1.37k | isl_set_list_free(list2); | 130 | 1.37k | FN(PW,free)(pw1); | 131 | 1.37k | FN(PW,free)(pw2); | 132 | 1.37k | return res; | 133 | 1.37k | error: | 134 | 0 | isl_set_list_free(list1); | 135 | 0 | isl_set_list_free(list2); | 136 | 0 | FN(PW,free)(pw1); | 137 | 0 | FN(PW,free)(pw2); | 138 | 0 | return NULL; | 139 | 1.37k | } |
|
140 | | |
141 | | /* Given a function "cmp" that returns the set of elements where |
142 | | * "el1" is "better" than "el2", return a piecewise |
143 | | * expression defined on the union of the definition domains |
144 | | * of "pw1" and "pw2" that maps to the "best" of "pw1" and |
145 | | * "pw2" on each cell. If only one of the two input functions |
146 | | * is defined on a given cell, then it is considered the best. |
147 | | * |
148 | | * Run through all pairs of pieces in "pw1" and "pw2". |
149 | | * If the domains of these pieces intersect, then the intersection |
150 | | * needs to be distributed over the two pieces based on "cmp". |
151 | | * Let C be the set where the piece from "pw2" is better (according to "cmp") |
152 | | * than the piece from "pw1". Let A be the domain of the piece from "pw1" and |
153 | | * B the domain of the piece from "pw2". |
154 | | * |
155 | | * The elements in C need to be removed from A, except for those parts |
156 | | * that lie outside of B. That is, |
157 | | * |
158 | | * A <- (A \setminus C) \cup ((A \cap C) \setminus B') |
159 | | * |
160 | | * Conversely, the elements in B need to be restricted to C, except |
161 | | * for those parts that lie outside of A. That is |
162 | | * |
163 | | * B <- (B \cap C) \cup ((B \setminus C) \setminus A') |
164 | | * |
165 | | * Since all pairs of pieces are considered, the domains are updated |
166 | | * several times. A and B refer to these updated domains |
167 | | * (kept track of in "list1" and "list2"), while A' and B' refer |
168 | | * to the original domains of the pieces. It is safe to use these |
169 | | * original domains because the difference between, say, A' and A is |
170 | | * the domains of pw2-pieces that have been removed before and |
171 | | * those domains are disjoint from B. A' is used instead of A |
172 | | * because the continued updating of A may result in this domain |
173 | | * getting broken up into more disjuncts. |
174 | | * |
175 | | * After the updated domains have been computed, the result is constructed |
176 | | * from "pw1", "pw2", "list1" and "list2". If there are any pieces |
177 | | * in "pw1" and "pw2" with the same function value expression, then |
178 | | * they are combined into a single piece in the result. |
179 | | * In order to be able to do this efficiently, the pieces of "pw1" and |
180 | | * "pw2" are first sorted according to their function value expressions. |
181 | | */ |
182 | | static __isl_give PW *FN(PW,union_opt_cmp)( |
183 | | __isl_take PW *pw1, __isl_take PW *pw2, |
184 | | __isl_give isl_set *(*cmp)(__isl_take EL *el1, __isl_take EL *el2)) |
185 | 1.85k | { |
186 | 1.85k | int i, j; |
187 | 1.85k | PW *res = NULL; |
188 | 1.85k | isl_ctx *ctx; |
189 | 1.85k | isl_set *set = NULL; |
190 | 1.85k | isl_set_list *list1 = NULL, *list2 = NULL; |
191 | 1.85k | |
192 | 1.85k | if (!pw1 || !pw2) |
193 | 0 | goto error; |
194 | 1.85k | |
195 | 1.85k | ctx = isl_space_get_ctx(pw1->dim); |
196 | 1.85k | if (!isl_space_is_equal(pw1->dim, pw2->dim)) |
197 | 1.85k | isl_die0 (ctx, isl_error_invalid, |
198 | 1.85k | "arguments should live in the same space", goto error); |
199 | 1.85k | |
200 | 1.85k | if (FN(PW,is_empty)(pw1)) { |
201 | 107 | FN(PW,free)(pw1); |
202 | 107 | return pw2; |
203 | 107 | } |
204 | 1.75k | |
205 | 1.75k | if (FN(PW,is_empty)(pw2)) { |
206 | 10 | FN(PW,free)(pw2); |
207 | 10 | return pw1; |
208 | 10 | } |
209 | 1.74k | |
210 | 1.74k | pw1 = FN(PW,sort)(pw1); |
211 | 1.74k | pw2 = FN(PW,sort)(pw2); |
212 | 1.74k | if (!pw1 || !pw2) |
213 | 0 | goto error; |
214 | 1.74k | |
215 | 1.74k | list1 = FN(PW,extract_domains)(pw1); |
216 | 1.74k | list2 = FN(PW,extract_domains)(pw2); |
217 | 1.74k | |
218 | 6.50k | for (i = 0; i < pw1->n; ++i4.76k ) { |
219 | 9.89k | for (j = 0; j < pw2->n; ++j5.12k ) { |
220 | 5.12k | isl_bool disjoint; |
221 | 5.12k | isl_set *better, *set_i, *set_j; |
222 | 5.12k | |
223 | 5.12k | disjoint = isl_set_is_disjoint(pw1->p[i].set, |
224 | 5.12k | pw2->p[j].set); |
225 | 5.12k | if (disjoint < 0) |
226 | 0 | goto error; |
227 | 5.12k | if (disjoint) |
228 | 3.39k | continue; |
229 | 1.73k | better = FN(PW,better)(pw2->p[j].FIELD, |
230 | 1.73k | pw1->p[i].FIELD, cmp); |
231 | 1.73k | set_i = isl_set_list_get_set(list1, i); |
232 | 1.73k | set_j = isl_set_copy(pw2->p[j].set); |
233 | 1.73k | set_i = FN(PW,worse_or_out)(set_i, |
234 | 1.73k | isl_set_copy(better), set_j); |
235 | 1.73k | list1 = isl_set_list_set_set(list1, i, set_i); |
236 | 1.73k | set_i = isl_set_copy(pw1->p[i].set); |
237 | 1.73k | set_j = isl_set_list_get_set(list2, j); |
238 | 1.73k | set_j = FN(PW,better_or_out)(set_j, better, set_i); |
239 | 1.73k | list2 = isl_set_list_set_set(list2, j, set_j); |
240 | 1.73k | } |
241 | 4.76k | } |
242 | 1.74k | |
243 | 1.74k | res = FN(PW,merge)(pw1, pw2, list1, list2); |
244 | 1.74k | |
245 | 1.74k | return res; |
246 | 1.74k | error: |
247 | 0 | isl_set_list_free(list1); |
248 | 0 | isl_set_list_free(list2); |
249 | 0 | FN(PW,free)(pw1); |
250 | 0 | FN(PW,free)(pw2); |
251 | 0 | isl_set_free(set); |
252 | 0 | return FN(PW,free)(res); |
253 | 1.74k | } isl_aff.c:isl_pw_aff_union_opt_cmp Line | Count | Source | 185 | 367 | { | 186 | 367 | int i, j; | 187 | 367 | PW *res = NULL; | 188 | 367 | isl_ctx *ctx; | 189 | 367 | isl_set *set = NULL; | 190 | 367 | isl_set_list *list1 = NULL, *list2 = NULL; | 191 | 367 | | 192 | 367 | if (!pw1 || !pw2) | 193 | 0 | goto error; | 194 | 367 | | 195 | 367 | ctx = isl_space_get_ctx(pw1->dim); | 196 | 367 | if (!isl_space_is_equal(pw1->dim, pw2->dim)) | 197 | 367 | isl_die0 (ctx, isl_error_invalid, | 198 | 367 | "arguments should live in the same space", goto error); | 199 | 367 | | 200 | 367 | if (FN(PW,is_empty)(pw1)) { | 201 | 0 | FN(PW,free)(pw1); | 202 | 0 | return pw2; | 203 | 0 | } | 204 | 367 | | 205 | 367 | if (FN(PW,is_empty)(pw2)) { | 206 | 0 | FN(PW,free)(pw2); | 207 | 0 | return pw1; | 208 | 0 | } | 209 | 367 | | 210 | 367 | pw1 = FN(PW,sort)(pw1); | 211 | 367 | pw2 = FN(PW,sort)(pw2); | 212 | 367 | if (!pw1 || !pw2) | 213 | 0 | goto error; | 214 | 367 | | 215 | 367 | list1 = FN(PW,extract_domains)(pw1); | 216 | 367 | list2 = FN(PW,extract_domains)(pw2); | 217 | 367 | | 218 | 776 | for (i = 0; i < pw1->n; ++i409 ) { | 219 | 818 | for (j = 0; j < pw2->n; ++j409 ) { | 220 | 409 | isl_bool disjoint; | 221 | 409 | isl_set *better, *set_i, *set_j; | 222 | 409 | | 223 | 409 | disjoint = isl_set_is_disjoint(pw1->p[i].set, | 224 | 409 | pw2->p[j].set); | 225 | 409 | if (disjoint < 0) | 226 | 0 | goto error; | 227 | 409 | if (disjoint) | 228 | 33 | continue; | 229 | 376 | better = FN(PW,better)(pw2->p[j].FIELD, | 230 | 376 | pw1->p[i].FIELD, cmp); | 231 | 376 | set_i = isl_set_list_get_set(list1, i); | 232 | 376 | set_j = isl_set_copy(pw2->p[j].set); | 233 | 376 | set_i = FN(PW,worse_or_out)(set_i, | 234 | 376 | isl_set_copy(better), set_j); | 235 | 376 | list1 = isl_set_list_set_set(list1, i, set_i); | 236 | 376 | set_i = isl_set_copy(pw1->p[i].set); | 237 | 376 | set_j = isl_set_list_get_set(list2, j); | 238 | 376 | set_j = FN(PW,better_or_out)(set_j, better, set_i); | 239 | 376 | list2 = isl_set_list_set_set(list2, j, set_j); | 240 | 376 | } | 241 | 409 | } | 242 | 367 | | 243 | 367 | res = FN(PW,merge)(pw1, pw2, list1, list2); | 244 | 367 | | 245 | 367 | return res; | 246 | 367 | error: | 247 | 0 | isl_set_list_free(list1); | 248 | 0 | isl_set_list_free(list2); | 249 | 0 | FN(PW,free)(pw1); | 250 | 0 | FN(PW,free)(pw2); | 251 | 0 | isl_set_free(set); | 252 | 0 | return FN(PW,free)(res); | 253 | 367 | } |
isl_aff.c:isl_pw_multi_aff_union_opt_cmp Line | Count | Source | 185 | 1.49k | { | 186 | 1.49k | int i, j; | 187 | 1.49k | PW *res = NULL; | 188 | 1.49k | isl_ctx *ctx; | 189 | 1.49k | isl_set *set = NULL; | 190 | 1.49k | isl_set_list *list1 = NULL, *list2 = NULL; | 191 | 1.49k | | 192 | 1.49k | if (!pw1 || !pw2) | 193 | 0 | goto error; | 194 | 1.49k | | 195 | 1.49k | ctx = isl_space_get_ctx(pw1->dim); | 196 | 1.49k | if (!isl_space_is_equal(pw1->dim, pw2->dim)) | 197 | 1.49k | isl_die0 (ctx, isl_error_invalid, | 198 | 1.49k | "arguments should live in the same space", goto error); | 199 | 1.49k | | 200 | 1.49k | if (FN(PW,is_empty)(pw1)) { | 201 | 107 | FN(PW,free)(pw1); | 202 | 107 | return pw2; | 203 | 107 | } | 204 | 1.38k | | 205 | 1.38k | if (FN(PW,is_empty)(pw2)) { | 206 | 10 | FN(PW,free)(pw2); | 207 | 10 | return pw1; | 208 | 10 | } | 209 | 1.37k | | 210 | 1.37k | pw1 = FN(PW,sort)(pw1); | 211 | 1.37k | pw2 = FN(PW,sort)(pw2); | 212 | 1.37k | if (!pw1 || !pw2) | 213 | 0 | goto error; | 214 | 1.37k | | 215 | 1.37k | list1 = FN(PW,extract_domains)(pw1); | 216 | 1.37k | list2 = FN(PW,extract_domains)(pw2); | 217 | 1.37k | | 218 | 5.73k | for (i = 0; i < pw1->n; ++i4.36k ) { | 219 | 9.07k | for (j = 0; j < pw2->n; ++j4.71k ) { | 220 | 4.71k | isl_bool disjoint; | 221 | 4.71k | isl_set *better, *set_i, *set_j; | 222 | 4.71k | | 223 | 4.71k | disjoint = isl_set_is_disjoint(pw1->p[i].set, | 224 | 4.71k | pw2->p[j].set); | 225 | 4.71k | if (disjoint < 0) | 226 | 0 | goto error; | 227 | 4.71k | if (disjoint) | 228 | 3.36k | continue; | 229 | 1.35k | better = FN(PW,better)(pw2->p[j].FIELD, | 230 | 1.35k | pw1->p[i].FIELD, cmp); | 231 | 1.35k | set_i = isl_set_list_get_set(list1, i); | 232 | 1.35k | set_j = isl_set_copy(pw2->p[j].set); | 233 | 1.35k | set_i = FN(PW,worse_or_out)(set_i, | 234 | 1.35k | isl_set_copy(better), set_j); | 235 | 1.35k | list1 = isl_set_list_set_set(list1, i, set_i); | 236 | 1.35k | set_i = isl_set_copy(pw1->p[i].set); | 237 | 1.35k | set_j = isl_set_list_get_set(list2, j); | 238 | 1.35k | set_j = FN(PW,better_or_out)(set_j, better, set_i); | 239 | 1.35k | list2 = isl_set_list_set_set(list2, j, set_j); | 240 | 1.35k | } | 241 | 4.36k | } | 242 | 1.37k | | 243 | 1.37k | res = FN(PW,merge)(pw1, pw2, list1, list2); | 244 | 1.37k | | 245 | 1.37k | return res; | 246 | 1.37k | error: | 247 | 0 | isl_set_list_free(list1); | 248 | 0 | isl_set_list_free(list2); | 249 | 0 | FN(PW,free)(pw1); | 250 | 0 | FN(PW,free)(pw2); | 251 | 0 | isl_set_free(set); | 252 | 0 | return FN(PW,free)(res); | 253 | 1.37k | } |
|