Coverage Report

Created: 2017-08-18 19:41

/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.26k
{
21
1.26k
  return cmp(
FN1.26k
(EL,copy)(el1),
FN1.26k
(EL,copy)(el2));
22
1.26k
}
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
911
{
21
911
  return cmp(
FN911
(EL,copy)(el1),
FN911
(EL,copy)(el2));
22
911
}
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
2.53k
{
28
2.53k
  int i;
29
2.53k
  isl_ctx *ctx;
30
2.53k
  isl_set_list *list;
31
2.53k
32
2.53k
  if (!pw)
33
0
    return NULL;
34
2.53k
  
ctx = 2.53k
FN2.53k
(PW,get_ctx)(pw);
35
2.53k
  list = isl_set_list_alloc(ctx, pw->n);
36
5.81k
  for (i = 0; 
i < pw->n5.81k
;
++i3.27k
)
37
3.27k
    list = isl_set_list_add(list, isl_set_copy(pw->p[i].set));
38
2.53k
39
2.53k
  return list;
40
2.53k
}
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
1.84k
{
28
1.84k
  int i;
29
1.84k
  isl_ctx *ctx;
30
1.84k
  isl_set_list *list;
31
1.84k
32
1.84k
  if (!pw)
33
0
    return NULL;
34
1.84k
  
ctx = 1.84k
FN1.84k
(PW,get_ctx)(pw);
35
1.84k
  list = isl_set_list_alloc(ctx, pw->n);
36
4.40k
  for (i = 0; 
i < pw->n4.40k
;
++i2.55k
)
37
2.55k
    list = isl_set_list_add(list, isl_set_copy(pw->p[i].set));
38
1.84k
39
1.84k
  return list;
40
1.84k
}
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.26k
{
49
1.26k
  isl_set *set_better, *set_out;
50
1.26k
51
1.26k
  set_better = isl_set_intersect(isl_set_copy(set), isl_set_copy(better));
52
1.26k
  set_out = isl_set_subtract(isl_set_subtract(set, better), out);
53
1.26k
54
1.26k
  return isl_set_union(set_better, set_out);
55
1.26k
}
isl_aff.c:isl_pw_multi_aff_better_or_out
Line
Count
Source
48
911
{
49
911
  isl_set *set_better, *set_out;
50
911
51
911
  set_better = isl_set_intersect(isl_set_copy(set), isl_set_copy(better));
52
911
  set_out = isl_set_subtract(isl_set_subtract(set, better), out);
53
911
54
911
  return isl_set_union(set_better, set_out);
55
911
}
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.26k
{
64
1.26k
  isl_set *set_worse, *set_out;
65
1.26k
66
1.26k
  set_worse = isl_set_subtract(isl_set_copy(set), isl_set_copy(better));
67
1.26k
  set_out = isl_set_subtract(isl_set_intersect(set, better), out);
68
1.26k
69
1.26k
  return isl_set_union(set_worse, set_out);
70
1.26k
}
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
911
{
64
911
  isl_set *set_worse, *set_out;
65
911
66
911
  set_worse = isl_set_subtract(isl_set_copy(set), isl_set_copy(better));
67
911
  set_out = isl_set_subtract(isl_set_intersect(set, better), out);
68
911
69
911
  return isl_set_union(set_worse, set_out);
70
911
}
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.26k
{
90
1.26k
  int i, j;
91
1.26k
  PW *res;
92
1.26k
93
1.26k
  if (
!pw1 || 1.26k
!pw21.26k
)
94
0
    goto error;
95
1.26k
96
1.26k
  
res = 1.26k
FN1.26k
(PW,alloc_size)(isl_space_copy(pw1->dim), pw1->n + pw2->n);
97
1.26k
98
1.26k
  i = 0; j = 0;
99
4.09k
  while (
i < pw1->n || 4.09k
j < pw2->n1.77k
)
{2.82k
100
2.82k
    int cmp;
101
2.82k
    isl_set *set;
102
2.82k
    EL *el;
103
2.82k
104
2.82k
    if (
i < pw1->n && 2.82k
j < pw2->n2.32k
)
105
1.68k
      
cmp = 1.68k
FN1.68k
(EL,plain_cmp)(pw1->p[i].
FIELD1.68k
,
106
1.68k
            pw2->p[j].FIELD);
107
2.82k
    else
108
1.14k
      
cmp = i < pw1->n ? 1.14k
-1636
:
1505
;
109
2.82k
110
2.82k
    if (
cmp < 02.82k
)
{1.51k
111
1.51k
      set = isl_set_list_get_set(list1, i);
112
1.51k
      el = 
FN1.51k
(EL,copy)(pw1->p[i].
FIELD1.51k
);
113
1.51k
      ++i;
114
2.82k
    } else 
if (1.30k
cmp > 01.30k
)
{857
115
857
      set = isl_set_list_get_set(list2, j);
116
857
      el = 
FN857
(EL,copy)(pw2->p[j].
FIELD857
);
117
857
      ++j;
118
1.30k
    } else {
119
451
      set = isl_set_union(isl_set_list_get_set(list1, i),
120
451
              isl_set_list_get_set(list2, j));
121
451
      el = 
FN451
(EL,copy)(pw1->p[i].
FIELD451
);
122
451
      ++i;
123
451
      ++j;
124
2.82k
    }
125
2.82k
    res = FN(PW,add_piece)(res, set, el);
126
2.82k
  }
127
1.26k
128
1.26k
  isl_set_list_free(list1);
129
1.26k
  isl_set_list_free(list2);
130
1.26k
  FN(PW,free)(pw1);
131
1.26k
  FN(PW,free)(pw2);
132
1.26k
  return res;
133
1.26k
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
1.26k
  return NULL;
139
1.26k
}
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
)
{711
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
)
{368
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
)
{329
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
14
      ++i;
123
14
      ++j;
124
711
    }
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
343
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
343
  return NULL;
139
343
}
isl_aff.c:isl_pw_multi_aff_merge
Line
Count
Source
89
924
{
90
924
  int i, j;
91
924
  PW *res;
92
924
93
924
  if (
!pw1 || 924
!pw2924
)
94
0
    goto error;
95
924
96
924
  
res = 924
FN924
(PW,alloc_size)(isl_space_copy(pw1->dim), pw1->n + pw2->n);
97
924
98
924
  i = 0; j = 0;
99
3.04k
  while (
i < pw1->n || 3.04k
j < pw2->n1.25k
)
{2.11k
100
2.11k
    int cmp;
101
2.11k
    isl_set *set;
102
2.11k
    EL *el;
103
2.11k
104
2.11k
    if (
i < pw1->n && 2.11k
j < pw2->n1.78k
)
105
1.31k
      
cmp = 1.31k
FN1.31k
(EL,plain_cmp)(pw1->p[i].
FIELD1.31k
,
106
1.31k
            pw2->p[j].FIELD);
107
2.11k
    else
108
801
      
cmp = i < pw1->n ? 801
-1467
:
1334
;
109
2.11k
110
2.11k
    if (
cmp < 02.11k
)
{1.15k
111
1.15k
      set = isl_set_list_get_set(list1, i);
112
1.15k
      el = 
FN1.15k
(EL,copy)(pw1->p[i].
FIELD1.15k
);
113
1.15k
      ++i;
114
2.11k
    } else 
if (965
cmp > 0965
)
{528
115
528
      set = isl_set_list_get_set(list2, j);
116
528
      el = 
FN528
(EL,copy)(pw2->p[j].
FIELD528
);
117
528
      ++j;
118
965
    } else {
119
437
      set = isl_set_union(isl_set_list_get_set(list1, i),
120
437
              isl_set_list_get_set(list2, j));
121
437
      el = 
FN437
(EL,copy)(pw1->p[i].
FIELD437
);
122
437
      ++i;
123
437
      ++j;
124
2.11k
    }
125
2.11k
    res = FN(PW,add_piece)(res, set, el);
126
2.11k
  }
127
924
128
924
  isl_set_list_free(list1);
129
924
  isl_set_list_free(list2);
130
924
  FN(PW,free)(pw1);
131
924
  FN(PW,free)(pw2);
132
924
  return res;
133
924
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
924
  return NULL;
139
924
}
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.51k
{
186
1.51k
  int i, j;
187
1.51k
  PW *res = NULL;
188
1.51k
  isl_ctx *ctx;
189
1.51k
  isl_set *set = NULL;
190
1.51k
  isl_set_list *list1 = NULL, *list2 = NULL;
191
1.51k
192
1.51k
  if (
!pw1 || 1.51k
!pw21.51k
)
193
0
    goto error;
194
1.51k
195
1.51k
  ctx = isl_space_get_ctx(pw1->dim);
196
1.51k
  if (!isl_space_is_equal(pw1->dim, pw2->dim))
197
0
    isl_die(ctx, isl_error_invalid,
198
1.51k
      "arguments should live in the same space", goto error);
199
1.51k
200
1.51k
  
if (1.51k
FN1.51k
(PW,is_empty)(pw1)1.51k
)
{232
201
232
    FN(PW,free)(pw1);
202
232
    return pw2;
203
1.51k
  }
204
1.51k
205
1.28k
  
if (1.28k
FN1.28k
(PW,is_empty)(pw2)1.28k
)
{15
206
15
    FN(PW,free)(pw2);
207
15
    return pw1;
208
1.28k
  }
209
1.28k
210
1.26k
  
pw1 = 1.26k
FN1.26k
(PW,sort)(pw1);
211
1.26k
  pw2 = FN(PW,sort)(pw2);
212
1.26k
  if (
!pw1 || 1.26k
!pw21.26k
)
213
0
    goto error;
214
1.26k
215
1.26k
  
list1 = 1.26k
FN1.26k
(PW,extract_domains)(pw1);
216
1.26k
  list2 = FN(PW,extract_domains)(pw2);
217
1.26k
218
3.23k
  for (i = 0; 
i < pw1->n3.23k
;
++i1.97k
)
{1.97k
219
4.01k
    for (j = 0; 
j < pw2->n4.01k
;
++j2.04k
)
{2.04k
220
2.04k
      isl_bool disjoint;
221
2.04k
      isl_set *better, *set_i, *set_j;
222
2.04k
223
2.04k
      disjoint = isl_set_is_disjoint(pw1->p[i].set,
224
2.04k
              pw2->p[j].set);
225
2.04k
      if (disjoint < 0)
226
0
        goto error;
227
2.04k
      
if (2.04k
disjoint2.04k
)
228
785
        continue;
229
1.26k
      
better = 1.26k
FN1.26k
(PW,better)(pw2->p[j].
FIELD1.26k
,
230
1.26k
            pw1->p[i].FIELD, cmp);
231
1.26k
      set_i = isl_set_list_get_set(list1, i);
232
1.26k
      set_j = isl_set_copy(pw2->p[j].set);
233
1.26k
      set_i = FN(PW,worse_or_out)(set_i,
234
1.26k
            isl_set_copy(better), set_j);
235
1.26k
      list1 = isl_set_list_set_set(list1, i, set_i);
236
1.26k
      set_i = isl_set_copy(pw1->p[i].set);
237
1.26k
      set_j = isl_set_list_get_set(list2, j);
238
1.26k
      set_j = FN(PW,better_or_out)(set_j, better, set_i);
239
1.26k
      list2 = isl_set_list_set_set(list2, j, set_j);
240
1.97k
    }
241
1.97k
  }
242
1.26k
243
1.26k
  
res = 1.26k
FN1.26k
(PW,merge)(pw1, pw2, list1, list2);
244
1.26k
245
1.26k
  return res;
246
1.26k
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.51k
}
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
)
{0
201
0
    FN(PW,free)(pw1);
202
0
    return pw2;
203
343
  }
204
343
205
343
  
if (343
FN343
(PW,is_empty)(pw2)343
)
{0
206
0
    FN(PW,free)(pw2);
207
0
    return pw1;
208
343
  }
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
)
{382
219
764
    for (j = 0; 
j < pw2->n764
;
++j382
)
{382
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
352
      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
343
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.17k
{
186
1.17k
  int i, j;
187
1.17k
  PW *res = NULL;
188
1.17k
  isl_ctx *ctx;
189
1.17k
  isl_set *set = NULL;
190
1.17k
  isl_set_list *list1 = NULL, *list2 = NULL;
191
1.17k
192
1.17k
  if (
!pw1 || 1.17k
!pw21.17k
)
193
0
    goto error;
194
1.17k
195
1.17k
  ctx = isl_space_get_ctx(pw1->dim);
196
1.17k
  if (!isl_space_is_equal(pw1->dim, pw2->dim))
197
0
    isl_die(ctx, isl_error_invalid,
198
1.17k
      "arguments should live in the same space", goto error);
199
1.17k
200
1.17k
  
if (1.17k
FN1.17k
(PW,is_empty)(pw1)1.17k
)
{232
201
232
    FN(PW,free)(pw1);
202
232
    return pw2;
203
1.17k
  }
204
1.17k
205
939
  
if (939
FN939
(PW,is_empty)(pw2)939
)
{15
206
15
    FN(PW,free)(pw2);
207
15
    return pw1;
208
939
  }
209
939
210
924
  
pw1 = 924
FN924
(PW,sort)(pw1);
211
924
  pw2 = FN(PW,sort)(pw2);
212
924
  if (
!pw1 || 924
!pw2924
)
213
0
    goto error;
214
924
215
924
  
list1 = 924
FN924
(PW,extract_domains)(pw1);
216
924
  list2 = FN(PW,extract_domains)(pw2);
217
924
218
2.51k
  for (i = 0; 
i < pw1->n2.51k
;
++i1.58k
)
{1.58k
219
3.25k
    for (j = 0; 
j < pw2->n3.25k
;
++j1.66k
)
{1.66k
220
1.66k
      isl_bool disjoint;
221
1.66k
      isl_set *better, *set_i, *set_j;
222
1.66k
223
1.66k
      disjoint = isl_set_is_disjoint(pw1->p[i].set,
224
1.66k
              pw2->p[j].set);
225
1.66k
      if (disjoint < 0)
226
0
        goto error;
227
1.66k
      
if (1.66k
disjoint1.66k
)
228
755
        continue;
229
911
      
better = 911
FN911
(PW,better)(pw2->p[j].
FIELD911
,
230
911
            pw1->p[i].FIELD, cmp);
231
911
      set_i = isl_set_list_get_set(list1, i);
232
911
      set_j = isl_set_copy(pw2->p[j].set);
233
911
      set_i = FN(PW,worse_or_out)(set_i,
234
911
            isl_set_copy(better), set_j);
235
911
      list1 = isl_set_list_set_set(list1, i, set_i);
236
911
      set_i = isl_set_copy(pw1->p[i].set);
237
911
      set_j = isl_set_list_get_set(list2, j);
238
911
      set_j = FN(PW,better_or_out)(set_j, better, set_i);
239
911
      list2 = isl_set_list_set_set(list2, j, set_j);
240
1.58k
    }
241
1.58k
  }
242
924
243
924
  
res = 924
FN924
(PW,merge)(pw1, pw2, list1, list2);
244
924
245
924
  return res;
246
924
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.17k
}