Coverage Report

Created: 2018-02-20 12:54

/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.63k
{
21
1.63k
  return cmp(FN(EL,copy)(el1), FN(EL,copy)(el2));
22
1.63k
}
isl_aff.c:isl_pw_aff_better
Line
Count
Source
20
374
{
21
374
  return cmp(FN(EL,copy)(el1), FN(EL,copy)(el2));
22
374
}
isl_aff.c:isl_pw_multi_aff_better
Line
Count
Source
20
1.25k
{
21
1.25k
  return cmp(FN(EL,copy)(el1), FN(EL,copy)(el2));
22
1.25k
}
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.39k
{
28
3.39k
  int i;
29
3.39k
  isl_ctx *ctx;
30
3.39k
  isl_set_list *list;
31
3.39k
32
3.39k
  if (!pw)
33
0
    return NULL;
34
3.39k
  ctx = FN(PW,get_ctx)(pw);
35
3.39k
  list = isl_set_list_alloc(ctx, pw->n);
36
8.02k
  for (i = 0; i < pw->n; 
++i4.63k
)
37
4.63k
    list = isl_set_list_add(list, isl_set_copy(pw->p[i].set));
38
3.39k
39
3.39k
  return list;
40
3.39k
}
isl_aff.c:isl_pw_aff_extract_domains
Line
Count
Source
27
730
{
28
730
  int i;
29
730
  isl_ctx *ctx;
30
730
  isl_set_list *list;
31
730
32
730
  if (!pw)
33
0
    return NULL;
34
730
  ctx = FN(PW,get_ctx)(pw);
35
730
  list = isl_set_list_alloc(ctx, pw->n);
36
1.49k
  for (i = 0; i < pw->n; 
++i769
)
37
769
    list = isl_set_list_add(list, isl_set_copy(pw->p[i].set));
38
730
39
730
  return list;
40
730
}
isl_aff.c:isl_pw_multi_aff_extract_domains
Line
Count
Source
27
2.66k
{
28
2.66k
  int i;
29
2.66k
  isl_ctx *ctx;
30
2.66k
  isl_set_list *list;
31
2.66k
32
2.66k
  if (!pw)
33
0
    return NULL;
34
2.66k
  ctx = FN(PW,get_ctx)(pw);
35
2.66k
  list = isl_set_list_alloc(ctx, pw->n);
36
6.53k
  for (i = 0; i < pw->n; 
++i3.86k
)
37
3.86k
    list = isl_set_list_add(list, isl_set_copy(pw->p[i].set));
38
2.66k
39
2.66k
  return list;
40
2.66k
}
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.63k
{
49
1.63k
  isl_set *set_better, *set_out;
50
1.63k
51
1.63k
  set_better = isl_set_intersect(isl_set_copy(set), isl_set_copy(better));
52
1.63k
  set_out = isl_set_subtract(isl_set_subtract(set, better), out);
53
1.63k
54
1.63k
  return isl_set_union(set_better, set_out);
55
1.63k
}
isl_aff.c:isl_pw_aff_better_or_out
Line
Count
Source
48
374
{
49
374
  isl_set *set_better, *set_out;
50
374
51
374
  set_better = isl_set_intersect(isl_set_copy(set), isl_set_copy(better));
52
374
  set_out = isl_set_subtract(isl_set_subtract(set, better), out);
53
374
54
374
  return isl_set_union(set_better, set_out);
55
374
}
isl_aff.c:isl_pw_multi_aff_better_or_out
Line
Count
Source
48
1.25k
{
49
1.25k
  isl_set *set_better, *set_out;
50
1.25k
51
1.25k
  set_better = isl_set_intersect(isl_set_copy(set), isl_set_copy(better));
52
1.25k
  set_out = isl_set_subtract(isl_set_subtract(set, better), out);
53
1.25k
54
1.25k
  return isl_set_union(set_better, set_out);
55
1.25k
}
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.63k
{
64
1.63k
  isl_set *set_worse, *set_out;
65
1.63k
66
1.63k
  set_worse = isl_set_subtract(isl_set_copy(set), isl_set_copy(better));
67
1.63k
  set_out = isl_set_subtract(isl_set_intersect(set, better), out);
68
1.63k
69
1.63k
  return isl_set_union(set_worse, set_out);
70
1.63k
}
isl_aff.c:isl_pw_aff_worse_or_out
Line
Count
Source
63
374
{
64
374
  isl_set *set_worse, *set_out;
65
374
66
374
  set_worse = isl_set_subtract(isl_set_copy(set), isl_set_copy(better));
67
374
  set_out = isl_set_subtract(isl_set_intersect(set, better), out);
68
374
69
374
  return isl_set_union(set_worse, set_out);
70
374
}
isl_aff.c:isl_pw_multi_aff_worse_or_out
Line
Count
Source
63
1.25k
{
64
1.25k
  isl_set *set_worse, *set_out;
65
1.25k
66
1.25k
  set_worse = isl_set_subtract(isl_set_copy(set), isl_set_copy(better));
67
1.25k
  set_out = isl_set_subtract(isl_set_intersect(set, better), out);
68
1.25k
69
1.25k
  return isl_set_union(set_worse, set_out);
70
1.25k
}
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.69k
{
90
1.69k
  int i, j;
91
1.69k
  PW *res;
92
1.69k
93
1.69k
  if (!pw1 || !pw2)
94
0
    goto error;
95
1.69k
96
1.69k
  res = FN(PW,alloc_size)(isl_space_copy(pw1->dim), pw1->n + pw2->n);
97
1.69k
98
1.69k
  i = 0; j = 0;
99
5.74k
  while (i < pw1->n || 
j < pw2->n2.41k
) {
100
4.04k
    int cmp;
101
4.04k
    isl_set *set;
102
4.04k
    EL *el;
103
4.04k
104
4.04k
    if (i < pw1->n && 
j < pw2->n3.33k
)
105
2.53k
      cmp = FN(EL,plain_cmp)(pw1->p[i].FIELD,
106
2.53k
            pw2->p[j].FIELD);
107
1.50k
    else
108
1.50k
      cmp = i < pw1->n ? 
-1796
:
1713
;
109
4.04k
110
4.04k
    if (cmp < 0) {
111
2.24k
      set = isl_set_list_get_set(list1, i);
112
2.24k
      el = FN(EL,copy)(pw1->p[i].FIELD);
113
2.24k
      ++i;
114
2.24k
    } else 
if (1.79k
cmp > 01.79k
) {
115
1.21k
      set = isl_set_list_get_set(list2, j);
116
1.21k
      el = FN(EL,copy)(pw2->p[j].FIELD);
117
1.21k
      ++j;
118
1.21k
    } else {
119
588
      set = isl_set_union(isl_set_list_get_set(list1, i),
120
588
              isl_set_list_get_set(list2, j));
121
588
      el = FN(EL,copy)(pw1->p[i].FIELD);
122
588
      ++i;
123
588
      ++j;
124
588
    }
125
4.04k
    res = FN(PW,add_piece)(res, set, el);
126
4.04k
  }
127
1.69k
128
1.69k
  isl_set_list_free(list1);
129
1.69k
  isl_set_list_free(list2);
130
1.69k
  FN(PW,free)(pw1);
131
1.69k
  FN(PW,free)(pw2);
132
1.69k
  return res;
133
1.69k
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.69k
}
isl_aff.c:isl_pw_aff_merge
Line
Count
Source
89
365
{
90
365
  int i, j;
91
365
  PW *res;
92
365
93
365
  if (!pw1 || !pw2)
94
0
    goto error;
95
365
96
365
  res = FN(PW,alloc_size)(isl_space_copy(pw1->dim), pw1->n + pw2->n);
97
365
98
365
  i = 0; j = 0;
99
1.12k
  while (i < pw1->n || 
j < pw2->n546
) {
100
755
    int cmp;
101
755
    isl_set *set;
102
755
    EL *el;
103
755
104
755
    if (i < pw1->n && 
j < pw2->n574
)
105
393
      cmp = FN(EL,plain_cmp)(pw1->p[i].FIELD,
106
393
            pw2->p[j].FIELD);
107
362
    else
108
362
      cmp = i < pw1->n ? 
-1181
:
1181
;
109
755
110
755
    if (cmp < 0) {
111
390
      set = isl_set_list_get_set(list1, i);
112
390
      el = FN(EL,copy)(pw1->p[i].FIELD);
113
390
      ++i;
114
390
    } else 
if (365
cmp > 0365
) {
115
351
      set = isl_set_list_get_set(list2, j);
116
351
      el = FN(EL,copy)(pw2->p[j].FIELD);
117
351
      ++j;
118
351
    } 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 = FN(EL,copy)(pw1->p[i].FIELD);
122
14
      ++i;
123
14
      ++j;
124
14
    }
125
755
    res = FN(PW,add_piece)(res, set, el);
126
755
  }
127
365
128
365
  isl_set_list_free(list1);
129
365
  isl_set_list_free(list2);
130
365
  FN(PW,free)(pw1);
131
365
  FN(PW,free)(pw2);
132
365
  return res;
133
365
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
365
}
isl_aff.c:isl_pw_multi_aff_merge
Line
Count
Source
89
1.33k
{
90
1.33k
  int i, j;
91
1.33k
  PW *res;
92
1.33k
93
1.33k
  if (!pw1 || !pw2)
94
0
    goto error;
95
1.33k
96
1.33k
  res = FN(PW,alloc_size)(isl_space_copy(pw1->dim), pw1->n + pw2->n);
97
1.33k
98
1.33k
  i = 0; j = 0;
99
4.62k
  while (i < pw1->n || 
j < pw2->n1.86k
) {
100
3.28k
    int cmp;
101
3.28k
    isl_set *set;
102
3.28k
    EL *el;
103
3.28k
104
3.28k
    if (i < pw1->n && 
j < pw2->n2.75k
)
105
2.14k
      cmp = FN(EL,plain_cmp)(pw1->p[i].FIELD,
106
2.14k
            pw2->p[j].FIELD);
107
1.14k
    else
108
1.14k
      cmp = i < pw1->n ? 
-1615
:
1532
;
109
3.28k
110
3.28k
    if (cmp < 0) {
111
1.85k
      set = isl_set_list_get_set(list1, i);
112
1.85k
      el = FN(EL,copy)(pw1->p[i].FIELD);
113
1.85k
      ++i;
114
1.85k
    } else 
if (1.43k
cmp > 01.43k
) {
115
860
      set = isl_set_list_get_set(list2, j);
116
860
      el = FN(EL,copy)(pw2->p[j].FIELD);
117
860
      ++j;
118
860
    } 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 = FN(EL,copy)(pw1->p[i].FIELD);
122
574
      ++i;
123
574
      ++j;
124
574
    }
125
3.28k
    res = FN(PW,add_piece)(res, set, el);
126
3.28k
  }
127
1.33k
128
1.33k
  isl_set_list_free(list1);
129
1.33k
  isl_set_list_free(list2);
130
1.33k
  FN(PW,free)(pw1);
131
1.33k
  FN(PW,free)(pw2);
132
1.33k
  return res;
133
1.33k
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.33k
}
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.95k
{
186
1.95k
  int i, j;
187
1.95k
  PW *res = NULL;
188
1.95k
  isl_ctx *ctx;
189
1.95k
  isl_set *set = NULL;
190
1.95k
  isl_set_list *list1 = NULL, *list2 = NULL;
191
1.95k
192
1.95k
  if (!pw1 || !pw2)
193
0
    goto error;
194
1.95k
195
1.95k
  ctx = isl_space_get_ctx(pw1->dim);
196
1.95k
  if (!isl_space_is_equal(pw1->dim, pw2->dim))
197
1.95k
    
isl_die0
(ctx, isl_error_invalid,
198
1.95k
      "arguments should live in the same space", goto error);
199
1.95k
200
1.95k
  if (FN(PW,is_empty)(pw1)) {
201
243
    FN(PW,free)(pw1);
202
243
    return pw2;
203
243
  }
204
1.71k
205
1.71k
  if (FN(PW,is_empty)(pw2)) {
206
16
    FN(PW,free)(pw2);
207
16
    return pw1;
208
16
  }
209
1.69k
210
1.69k
  pw1 = FN(PW,sort)(pw1);
211
1.69k
  pw2 = FN(PW,sort)(pw2);
212
1.69k
  if (!pw1 || !pw2)
213
0
    goto error;
214
1.69k
215
1.69k
  list1 = FN(PW,extract_domains)(pw1);
216
1.69k
  list2 = FN(PW,extract_domains)(pw2);
217
1.69k
218
4.53k
  for (i = 0; i < pw1->n; 
++i2.83k
) {
219
5.89k
    for (j = 0; j < pw2->n; 
++j3.06k
) {
220
3.06k
      isl_bool disjoint;
221
3.06k
      isl_set *better, *set_i, *set_j;
222
3.06k
223
3.06k
      disjoint = isl_set_is_disjoint(pw1->p[i].set,
224
3.06k
              pw2->p[j].set);
225
3.06k
      if (disjoint < 0)
226
0
        goto error;
227
3.06k
      if (disjoint)
228
1.43k
        continue;
229
1.63k
      better = FN(PW,better)(pw2->p[j].FIELD,
230
1.63k
            pw1->p[i].FIELD, cmp);
231
1.63k
      set_i = isl_set_list_get_set(list1, i);
232
1.63k
      set_j = isl_set_copy(pw2->p[j].set);
233
1.63k
      set_i = FN(PW,worse_or_out)(set_i,
234
1.63k
            isl_set_copy(better), set_j);
235
1.63k
      list1 = isl_set_list_set_set(list1, i, set_i);
236
1.63k
      set_i = isl_set_copy(pw1->p[i].set);
237
1.63k
      set_j = isl_set_list_get_set(list2, j);
238
1.63k
      set_j = FN(PW,better_or_out)(set_j, better, set_i);
239
1.63k
      list2 = isl_set_list_set_set(list2, j, set_j);
240
1.63k
    }
241
2.83k
  }
242
1.69k
243
1.69k
  res = FN(PW,merge)(pw1, pw2, list1, list2);
244
1.69k
245
1.69k
  return res;
246
1.69k
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.69k
}
isl_aff.c:isl_pw_aff_union_opt_cmp
Line
Count
Source
185
365
{
186
365
  int i, j;
187
365
  PW *res = NULL;
188
365
  isl_ctx *ctx;
189
365
  isl_set *set = NULL;
190
365
  isl_set_list *list1 = NULL, *list2 = NULL;
191
365
192
365
  if (!pw1 || !pw2)
193
0
    goto error;
194
365
195
365
  ctx = isl_space_get_ctx(pw1->dim);
196
365
  if (!isl_space_is_equal(pw1->dim, pw2->dim))
197
365
    
isl_die0
(ctx, isl_error_invalid,
198
365
      "arguments should live in the same space", goto error);
199
365
200
365
  if (FN(PW,is_empty)(pw1)) {
201
0
    FN(PW,free)(pw1);
202
0
    return pw2;
203
0
  }
204
365
205
365
  if (FN(PW,is_empty)(pw2)) {
206
0
    FN(PW,free)(pw2);
207
0
    return pw1;
208
0
  }
209
365
210
365
  pw1 = FN(PW,sort)(pw1);
211
365
  pw2 = FN(PW,sort)(pw2);
212
365
  if (!pw1 || !pw2)
213
0
    goto error;
214
365
215
365
  list1 = FN(PW,extract_domains)(pw1);
216
365
  list2 = FN(PW,extract_domains)(pw2);
217
365
218
769
  for (i = 0; i < pw1->n; 
++i404
) {
219
808
    for (j = 0; j < pw2->n; 
++j404
) {
220
404
      isl_bool disjoint;
221
404
      isl_set *better, *set_i, *set_j;
222
404
223
404
      disjoint = isl_set_is_disjoint(pw1->p[i].set,
224
404
              pw2->p[j].set);
225
404
      if (disjoint < 0)
226
0
        goto error;
227
404
      if (disjoint)
228
30
        continue;
229
374
      better = FN(PW,better)(pw2->p[j].FIELD,
230
374
            pw1->p[i].FIELD, cmp);
231
374
      set_i = isl_set_list_get_set(list1, i);
232
374
      set_j = isl_set_copy(pw2->p[j].set);
233
374
      set_i = FN(PW,worse_or_out)(set_i,
234
374
            isl_set_copy(better), set_j);
235
374
      list1 = isl_set_list_set_set(list1, i, set_i);
236
374
      set_i = isl_set_copy(pw1->p[i].set);
237
374
      set_j = isl_set_list_get_set(list2, j);
238
374
      set_j = FN(PW,better_or_out)(set_j, better, set_i);
239
374
      list2 = isl_set_list_set_set(list2, j, set_j);
240
374
    }
241
404
  }
242
365
243
365
  res = FN(PW,merge)(pw1, pw2, list1, list2);
244
365
245
365
  return res;
246
365
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
365
}
isl_aff.c:isl_pw_multi_aff_union_opt_cmp
Line
Count
Source
185
1.59k
{
186
1.59k
  int i, j;
187
1.59k
  PW *res = NULL;
188
1.59k
  isl_ctx *ctx;
189
1.59k
  isl_set *set = NULL;
190
1.59k
  isl_set_list *list1 = NULL, *list2 = NULL;
191
1.59k
192
1.59k
  if (!pw1 || !pw2)
193
0
    goto error;
194
1.59k
195
1.59k
  ctx = isl_space_get_ctx(pw1->dim);
196
1.59k
  if (!isl_space_is_equal(pw1->dim, pw2->dim))
197
1.59k
    
isl_die0
(ctx, isl_error_invalid,
198
1.59k
      "arguments should live in the same space", goto error);
199
1.59k
200
1.59k
  if (FN(PW,is_empty)(pw1)) {
201
243
    FN(PW,free)(pw1);
202
243
    return pw2;
203
243
  }
204
1.35k
205
1.35k
  if (FN(PW,is_empty)(pw2)) {
206
16
    FN(PW,free)(pw2);
207
16
    return pw1;
208
16
  }
209
1.33k
210
1.33k
  pw1 = FN(PW,sort)(pw1);
211
1.33k
  pw2 = FN(PW,sort)(pw2);
212
1.33k
  if (!pw1 || !pw2)
213
0
    goto error;
214
1.33k
215
1.33k
  list1 = FN(PW,extract_domains)(pw1);
216
1.33k
  list2 = FN(PW,extract_domains)(pw2);
217
1.33k
218
3.76k
  for (i = 0; i < pw1->n; 
++i2.42k
) {
219
5.08k
    for (j = 0; j < pw2->n; 
++j2.65k
) {
220
2.65k
      isl_bool disjoint;
221
2.65k
      isl_set *better, *set_i, *set_j;
222
2.65k
223
2.65k
      disjoint = isl_set_is_disjoint(pw1->p[i].set,
224
2.65k
              pw2->p[j].set);
225
2.65k
      if (disjoint < 0)
226
0
        goto error;
227
2.65k
      if (disjoint)
228
1.40k
        continue;
229
1.25k
      better = FN(PW,better)(pw2->p[j].FIELD,
230
1.25k
            pw1->p[i].FIELD, cmp);
231
1.25k
      set_i = isl_set_list_get_set(list1, i);
232
1.25k
      set_j = isl_set_copy(pw2->p[j].set);
233
1.25k
      set_i = FN(PW,worse_or_out)(set_i,
234
1.25k
            isl_set_copy(better), set_j);
235
1.25k
      list1 = isl_set_list_set_set(list1, i, set_i);
236
1.25k
      set_i = isl_set_copy(pw1->p[i].set);
237
1.25k
      set_j = isl_set_list_get_set(list2, j);
238
1.25k
      set_j = FN(PW,better_or_out)(set_j, better, set_i);
239
1.25k
      list2 = isl_set_list_set_set(list2, j, set_j);
240
1.25k
    }
241
2.42k
  }
242
1.33k
243
1.33k
  res = FN(PW,merge)(pw1, pw2, list1, list2);
244
1.33k
245
1.33k
  return res;
246
1.33k
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.33k
}