Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/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.53k
{
21
1.53k
  return cmp(
FN1.53k
(EL,copy)(el1),
FN1.53k
(EL,copy)(el2));
22
1.53k
}
isl_aff.c:isl_pw_aff_better
Line
Count
Source
20
352
{
21
352
  return cmp(
FN352
(EL,copy)(el1),
FN352
(EL,copy)(el2));
22
352
}
isl_aff.c:isl_pw_multi_aff_better
Line
Count
Source
20
1.18k
{
21
1.18k
  return cmp(
FN1.18k
(EL,copy)(el1),
FN1.18k
(EL,copy)(el2));
22
1.18k
}
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.02k
{
28
3.02k
  int i;
29
3.02k
  isl_ctx *ctx;
30
3.02k
  isl_set_list *list;
31
3.02k
32
3.02k
  if (!pw)
33
0
    return NULL;
34
3.02k
  
ctx = 3.02k
FN3.02k
(PW,get_ctx)(pw);
35
3.02k
  list = isl_set_list_alloc(ctx, pw->n);
36
7.34k
  for (i = 0; 
i < pw->n7.34k
;
++i4.32k
)
37
4.32k
    list = isl_set_list_add(list, isl_set_copy(pw->p[i].set));
38
3.02k
39
3.02k
  return list;
40
3.02k
}
isl_aff.c:isl_pw_aff_extract_domains
Line
Count
Source
27
686
{
28
686
  int i;
29
686
  isl_ctx *ctx;
30
686
  isl_set_list *list;
31
686
32
686
  if (!pw)
33
0
    return NULL;
34
686
  
ctx = 686
FN686
(PW,get_ctx)(pw);
35
686
  list = isl_set_list_alloc(ctx, pw->n);
36
1.41k
  for (i = 0; 
i < pw->n1.41k
;
++i725
)
37
725
    list = isl_set_list_add(list, isl_set_copy(pw->p[i].set));
38
686
39
686
  return list;
40
686
}
isl_aff.c:isl_pw_multi_aff_extract_domains
Line
Count
Source
27
2.33k
{
28
2.33k
  int i;
29
2.33k
  isl_ctx *ctx;
30
2.33k
  isl_set_list *list;
31
2.33k
32
2.33k
  if (!pw)
33
0
    return NULL;
34
2.33k
  
ctx = 2.33k
FN2.33k
(PW,get_ctx)(pw);
35
2.33k
  list = isl_set_list_alloc(ctx, pw->n);
36
5.93k
  for (i = 0; 
i < pw->n5.93k
;
++i3.60k
)
37
3.60k
    list = isl_set_list_add(list, isl_set_copy(pw->p[i].set));
38
2.33k
39
2.33k
  return list;
40
2.33k
}
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.53k
{
49
1.53k
  isl_set *set_better, *set_out;
50
1.53k
51
1.53k
  set_better = isl_set_intersect(isl_set_copy(set), isl_set_copy(better));
52
1.53k
  set_out = isl_set_subtract(isl_set_subtract(set, better), out);
53
1.53k
54
1.53k
  return isl_set_union(set_better, set_out);
55
1.53k
}
isl_aff.c:isl_pw_multi_aff_better_or_out
Line
Count
Source
48
1.18k
{
49
1.18k
  isl_set *set_better, *set_out;
50
1.18k
51
1.18k
  set_better = isl_set_intersect(isl_set_copy(set), isl_set_copy(better));
52
1.18k
  set_out = isl_set_subtract(isl_set_subtract(set, better), out);
53
1.18k
54
1.18k
  return isl_set_union(set_better, set_out);
55
1.18k
}
isl_aff.c:isl_pw_aff_better_or_out
Line
Count
Source
48
352
{
49
352
  isl_set *set_better, *set_out;
50
352
51
352
  set_better = isl_set_intersect(isl_set_copy(set), isl_set_copy(better));
52
352
  set_out = isl_set_subtract(isl_set_subtract(set, better), out);
53
352
54
352
  return isl_set_union(set_better, set_out);
55
352
}
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.53k
{
64
1.53k
  isl_set *set_worse, *set_out;
65
1.53k
66
1.53k
  set_worse = isl_set_subtract(isl_set_copy(set), isl_set_copy(better));
67
1.53k
  set_out = isl_set_subtract(isl_set_intersect(set, better), out);
68
1.53k
69
1.53k
  return isl_set_union(set_worse, set_out);
70
1.53k
}
isl_aff.c:isl_pw_aff_worse_or_out
Line
Count
Source
63
352
{
64
352
  isl_set *set_worse, *set_out;
65
352
66
352
  set_worse = isl_set_subtract(isl_set_copy(set), isl_set_copy(better));
67
352
  set_out = isl_set_subtract(isl_set_intersect(set, better), out);
68
352
69
352
  return isl_set_union(set_worse, set_out);
70
352
}
isl_aff.c:isl_pw_multi_aff_worse_or_out
Line
Count
Source
63
1.18k
{
64
1.18k
  isl_set *set_worse, *set_out;
65
1.18k
66
1.18k
  set_worse = isl_set_subtract(isl_set_copy(set), isl_set_copy(better));
67
1.18k
  set_out = isl_set_subtract(isl_set_intersect(set, better), out);
68
1.18k
69
1.18k
  return isl_set_union(set_worse, set_out);
70
1.18k
}
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.51k
{
90
1.51k
  int i, j;
91
1.51k
  PW *res;
92
1.51k
93
1.51k
  if (
!pw1 || 1.51k
!pw21.51k
)
94
0
    goto error;
95
1.51k
96
1.51k
  
res = 1.51k
FN1.51k
(PW,alloc_size)(isl_space_copy(pw1->dim), pw1->n + pw2->n);
97
1.51k
98
1.51k
  i = 0; j = 0;
99
5.26k
  while (
i < pw1->n || 5.26k
j < pw2->n2.07k
) {
100
3.75k
    int cmp;
101
3.75k
    isl_set *set;
102
3.75k
    EL *el;
103
3.75k
104
3.75k
    if (
i < pw1->n && 3.75k
j < pw2->n3.19k
)
105
2.20k
      
cmp = 2.20k
FN2.20k
(EL,plain_cmp)(pw1->p[i].
FIELD2.20k
,
106
2.20k
            pw2->p[j].FIELD);
107
3.75k
    else
108
1.55k
      
cmp = i < pw1->n ? 1.55k
-1993
:
1558
;
109
3.75k
110
3.75k
    if (
cmp < 03.75k
) {
111
2.18k
      set = isl_set_list_get_set(list1, i);
112
2.18k
      el = 
FN2.18k
(EL,copy)(pw1->p[i].
FIELD2.18k
);
113
2.18k
      ++i;
114
3.75k
    } else 
if (1.56k
cmp > 01.56k
) {
115
995
      set = isl_set_list_get_set(list2, j);
116
995
      el = 
FN995
(EL,copy)(pw2->p[j].
FIELD995
);
117
995
      ++j;
118
1.56k
    } else {
119
574
      set = isl_set_union(isl_set_list_get_set(list1, i),
120
574
              isl_set_list_get_set(list2, j));
121
574
      el = 
FN574
(EL,copy)(pw1->p[i].
FIELD574
);
122
1.56k
      ++i;
123
1.56k
      ++j;
124
1.56k
    }
125
3.75k
    res = FN(PW,add_piece)(res, set, el);
126
3.75k
  }
127
1.51k
128
1.51k
  isl_set_list_free(list1);
129
1.51k
  isl_set_list_free(list2);
130
1.51k
  FN(PW,free)(pw1);
131
1.51k
  FN(PW,free)(pw2);
132
1.51k
  return res;
133
0
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.51k
}
isl_aff.c:isl_pw_aff_merge
Line
Count
Source
89
343
{
90
343
  int i, j;
91
343
  PW *res;
92
343
93
343
  if (
!pw1 || 343
!pw2343
)
94
0
    goto error;
95
343
96
343
  
res = 343
FN343
(PW,alloc_size)(isl_space_copy(pw1->dim), pw1->n + pw2->n);
97
343
98
343
  i = 0; j = 0;
99
1.05k
  while (
i < pw1->n || 1.05k
j < pw2->n514
) {
100
711
    int cmp;
101
711
    isl_set *set;
102
711
    EL *el;
103
711
104
711
    if (
i < pw1->n && 711
j < pw2->n540
)
105
371
      
cmp = 371
FN371
(EL,plain_cmp)(pw1->p[i].
FIELD371
,
106
371
            pw2->p[j].FIELD);
107
711
    else
108
340
      
cmp = i < pw1->n ? 340
-1169
:
1171
;
109
711
110
711
    if (
cmp < 0711
) {
111
368
      set = isl_set_list_get_set(list1, i);
112
368
      el = 
FN368
(EL,copy)(pw1->p[i].
FIELD368
);
113
368
      ++i;
114
711
    } else 
if (343
cmp > 0343
) {
115
329
      set = isl_set_list_get_set(list2, j);
116
329
      el = 
FN329
(EL,copy)(pw2->p[j].
FIELD329
);
117
329
      ++j;
118
343
    } else {
119
14
      set = isl_set_union(isl_set_list_get_set(list1, i),
120
14
              isl_set_list_get_set(list2, j));
121
14
      el = 
FN14
(EL,copy)(pw1->p[i].
FIELD14
);
122
343
      ++i;
123
343
      ++j;
124
343
    }
125
711
    res = FN(PW,add_piece)(res, set, el);
126
711
  }
127
343
128
343
  isl_set_list_free(list1);
129
343
  isl_set_list_free(list2);
130
343
  FN(PW,free)(pw1);
131
343
  FN(PW,free)(pw2);
132
343
  return res;
133
0
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
343
}
isl_aff.c:isl_pw_multi_aff_merge
Line
Count
Source
89
1.16k
{
90
1.16k
  int i, j;
91
1.16k
  PW *res;
92
1.16k
93
1.16k
  if (
!pw1 || 1.16k
!pw21.16k
)
94
0
    goto error;
95
1.16k
96
1.16k
  
res = 1.16k
FN1.16k
(PW,alloc_size)(isl_space_copy(pw1->dim), pw1->n + pw2->n);
97
1.16k
98
1.16k
  i = 0; j = 0;
99
4.20k
  while (
i < pw1->n || 4.20k
j < pw2->n1.55k
) {
100
3.04k
    int cmp;
101
3.04k
    isl_set *set;
102
3.04k
    EL *el;
103
3.04k
104
3.04k
    if (
i < pw1->n && 3.04k
j < pw2->n2.65k
)
105
1.82k
      
cmp = 1.82k
FN1.82k
(EL,plain_cmp)(pw1->p[i].
FIELD1.82k
,
106
1.82k
            pw2->p[j].FIELD);
107
3.04k
    else
108
1.21k
      
cmp = i < pw1->n ? 1.21k
-1824
:
1387
;
109
3.04k
110
3.04k
    if (
cmp < 03.04k
) {
111
1.81k
      set = isl_set_list_get_set(list1, i);
112
1.81k
      el = 
FN1.81k
(EL,copy)(pw1->p[i].
FIELD1.81k
);
113
1.81k
      ++i;
114
3.04k
    } else 
if (1.22k
cmp > 01.22k
) {
115
666
      set = isl_set_list_get_set(list2, j);
116
666
      el = 
FN666
(EL,copy)(pw2->p[j].
FIELD666
);
117
666
      ++j;
118
1.22k
    } else {
119
560
      set = isl_set_union(isl_set_list_get_set(list1, i),
120
560
              isl_set_list_get_set(list2, j));
121
560
      el = 
FN560
(EL,copy)(pw1->p[i].
FIELD560
);
122
1.22k
      ++i;
123
1.22k
      ++j;
124
1.22k
    }
125
3.04k
    res = FN(PW,add_piece)(res, set, el);
126
3.04k
  }
127
1.16k
128
1.16k
  isl_set_list_free(list1);
129
1.16k
  isl_set_list_free(list2);
130
1.16k
  FN(PW,free)(pw1);
131
1.16k
  FN(PW,free)(pw2);
132
1.16k
  return res;
133
0
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.16k
}
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.76k
{
186
1.76k
  int i, j;
187
1.76k
  PW *res = NULL;
188
1.76k
  isl_ctx *ctx;
189
1.76k
  isl_set *set = NULL;
190
1.76k
  isl_set_list *list1 = NULL, *list2 = NULL;
191
1.76k
192
1.76k
  if (
!pw1 || 1.76k
!pw21.76k
)
193
0
    goto error;
194
1.76k
195
1.76k
  ctx = isl_space_get_ctx(pw1->dim);
196
1.76k
  if (!isl_space_is_equal(pw1->dim, pw2->dim))
197
0
    isl_die(ctx, isl_error_invalid,
198
1.76k
      "arguments should live in the same space", goto error);
199
1.76k
200
1.76k
  
if (1.76k
FN1.76k
(PW,is_empty)(pw1)1.76k
) {
201
240
    FN(PW,free)(pw1);
202
240
    return pw2;
203
240
  }
204
1.76k
205
1.52k
  
if (1.52k
FN1.52k
(PW,is_empty)(pw2)1.52k
) {
206
16
    FN(PW,free)(pw2);
207
16
    return pw1;
208
16
  }
209
1.52k
210
1.51k
  
pw1 = 1.51k
FN1.51k
(PW,sort)(pw1);
211
1.51k
  pw2 = FN(PW,sort)(pw2);
212
1.51k
  if (
!pw1 || 1.51k
!pw21.51k
)
213
0
    goto error;
214
1.51k
215
1.51k
  
list1 = 1.51k
FN1.51k
(PW,extract_domains)(pw1);
216
1.51k
  list2 = FN(PW,extract_domains)(pw2);
217
1.51k
218
4.26k
  for (i = 0; 
i < pw1->n4.26k
;
++i2.75k
) {
219
5.62k
    for (j = 0; 
j < pw2->n5.62k
;
++j2.87k
) {
220
2.87k
      isl_bool disjoint;
221
2.87k
      isl_set *better, *set_i, *set_j;
222
2.87k
223
2.87k
      disjoint = isl_set_is_disjoint(pw1->p[i].set,
224
2.87k
              pw2->p[j].set);
225
2.87k
      if (disjoint < 0)
226
0
        goto error;
227
2.87k
      
if (2.87k
disjoint2.87k
)
228
1.34k
        continue;
229
1.53k
      
better = 1.53k
FN1.53k
(PW,better)(pw2->p[j].
FIELD1.53k
,
230
1.53k
            pw1->p[i].FIELD, cmp);
231
1.53k
      set_i = isl_set_list_get_set(list1, i);
232
1.53k
      set_j = isl_set_copy(pw2->p[j].set);
233
1.53k
      set_i = FN(PW,worse_or_out)(set_i,
234
1.53k
            isl_set_copy(better), set_j);
235
1.53k
      list1 = isl_set_list_set_set(list1, i, set_i);
236
1.53k
      set_i = isl_set_copy(pw1->p[i].set);
237
1.53k
      set_j = isl_set_list_get_set(list2, j);
238
1.53k
      set_j = FN(PW,better_or_out)(set_j, better, set_i);
239
2.87k
      list2 = isl_set_list_set_set(list2, j, set_j);
240
2.87k
    }
241
2.75k
  }
242
1.51k
243
1.51k
  
res = 1.51k
FN1.51k
(PW,merge)(pw1, pw2, list1, list2);
244
1.51k
245
1.51k
  return res;
246
0
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.76k
}
isl_aff.c:isl_pw_aff_union_opt_cmp
Line
Count
Source
185
343
{
186
343
  int i, j;
187
343
  PW *res = NULL;
188
343
  isl_ctx *ctx;
189
343
  isl_set *set = NULL;
190
343
  isl_set_list *list1 = NULL, *list2 = NULL;
191
343
192
343
  if (
!pw1 || 343
!pw2343
)
193
0
    goto error;
194
343
195
343
  ctx = isl_space_get_ctx(pw1->dim);
196
343
  if (!isl_space_is_equal(pw1->dim, pw2->dim))
197
0
    isl_die(ctx, isl_error_invalid,
198
343
      "arguments should live in the same space", goto error);
199
343
200
343
  
if (343
FN343
(PW,is_empty)(pw1)343
) {
201
0
    FN(PW,free)(pw1);
202
0
    return pw2;
203
0
  }
204
343
205
343
  
if (343
FN343
(PW,is_empty)(pw2)343
) {
206
0
    FN(PW,free)(pw2);
207
0
    return pw1;
208
0
  }
209
343
210
343
  
pw1 = 343
FN343
(PW,sort)(pw1);
211
343
  pw2 = FN(PW,sort)(pw2);
212
343
  if (
!pw1 || 343
!pw2343
)
213
0
    goto error;
214
343
215
343
  
list1 = 343
FN343
(PW,extract_domains)(pw1);
216
343
  list2 = FN(PW,extract_domains)(pw2);
217
343
218
725
  for (i = 0; 
i < pw1->n725
;
++i382
) {
219
764
    for (j = 0; 
j < pw2->n764
;
++j382
) {
220
382
      isl_bool disjoint;
221
382
      isl_set *better, *set_i, *set_j;
222
382
223
382
      disjoint = isl_set_is_disjoint(pw1->p[i].set,
224
382
              pw2->p[j].set);
225
382
      if (disjoint < 0)
226
0
        goto error;
227
382
      
if (382
disjoint382
)
228
30
        continue;
229
352
      
better = 352
FN352
(PW,better)(pw2->p[j].
FIELD352
,
230
352
            pw1->p[i].FIELD, cmp);
231
352
      set_i = isl_set_list_get_set(list1, i);
232
352
      set_j = isl_set_copy(pw2->p[j].set);
233
352
      set_i = FN(PW,worse_or_out)(set_i,
234
352
            isl_set_copy(better), set_j);
235
352
      list1 = isl_set_list_set_set(list1, i, set_i);
236
352
      set_i = isl_set_copy(pw1->p[i].set);
237
352
      set_j = isl_set_list_get_set(list2, j);
238
352
      set_j = FN(PW,better_or_out)(set_j, better, set_i);
239
382
      list2 = isl_set_list_set_set(list2, j, set_j);
240
382
    }
241
382
  }
242
343
243
343
  
res = 343
FN343
(PW,merge)(pw1, pw2, list1, list2);
244
343
245
343
  return res;
246
0
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
343
}
isl_aff.c:isl_pw_multi_aff_union_opt_cmp
Line
Count
Source
185
1.42k
{
186
1.42k
  int i, j;
187
1.42k
  PW *res = NULL;
188
1.42k
  isl_ctx *ctx;
189
1.42k
  isl_set *set = NULL;
190
1.42k
  isl_set_list *list1 = NULL, *list2 = NULL;
191
1.42k
192
1.42k
  if (
!pw1 || 1.42k
!pw21.42k
)
193
0
    goto error;
194
1.42k
195
1.42k
  ctx = isl_space_get_ctx(pw1->dim);
196
1.42k
  if (!isl_space_is_equal(pw1->dim, pw2->dim))
197
0
    isl_die(ctx, isl_error_invalid,
198
1.42k
      "arguments should live in the same space", goto error);
199
1.42k
200
1.42k
  
if (1.42k
FN1.42k
(PW,is_empty)(pw1)1.42k
) {
201
240
    FN(PW,free)(pw1);
202
240
    return pw2;
203
240
  }
204
1.42k
205
1.18k
  
if (1.18k
FN1.18k
(PW,is_empty)(pw2)1.18k
) {
206
16
    FN(PW,free)(pw2);
207
16
    return pw1;
208
16
  }
209
1.18k
210
1.16k
  
pw1 = 1.16k
FN1.16k
(PW,sort)(pw1);
211
1.16k
  pw2 = FN(PW,sort)(pw2);
212
1.16k
  if (
!pw1 || 1.16k
!pw21.16k
)
213
0
    goto error;
214
1.16k
215
1.16k
  
list1 = 1.16k
FN1.16k
(PW,extract_domains)(pw1);
216
1.16k
  list2 = FN(PW,extract_domains)(pw2);
217
1.16k
218
3.54k
  for (i = 0; 
i < pw1->n3.54k
;
++i2.37k
) {
219
4.86k
    for (j = 0; 
j < pw2->n4.86k
;
++j2.49k
) {
220
2.49k
      isl_bool disjoint;
221
2.49k
      isl_set *better, *set_i, *set_j;
222
2.49k
223
2.49k
      disjoint = isl_set_is_disjoint(pw1->p[i].set,
224
2.49k
              pw2->p[j].set);
225
2.49k
      if (disjoint < 0)
226
0
        goto error;
227
2.49k
      
if (2.49k
disjoint2.49k
)
228
1.31k
        continue;
229
1.18k
      
better = 1.18k
FN1.18k
(PW,better)(pw2->p[j].
FIELD1.18k
,
230
1.18k
            pw1->p[i].FIELD, cmp);
231
1.18k
      set_i = isl_set_list_get_set(list1, i);
232
1.18k
      set_j = isl_set_copy(pw2->p[j].set);
233
1.18k
      set_i = FN(PW,worse_or_out)(set_i,
234
1.18k
            isl_set_copy(better), set_j);
235
1.18k
      list1 = isl_set_list_set_set(list1, i, set_i);
236
1.18k
      set_i = isl_set_copy(pw1->p[i].set);
237
1.18k
      set_j = isl_set_list_get_set(list2, j);
238
1.18k
      set_j = FN(PW,better_or_out)(set_j, better, set_i);
239
2.49k
      list2 = isl_set_list_set_set(list2, j, set_j);
240
2.49k
    }
241
2.37k
  }
242
1.16k
243
1.16k
  
res = 1.16k
FN1.16k
(PW,merge)(pw1, pw2, list1, list2);
244
1.16k
245
1.16k
  return res;
246
0
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.42k
}