Coverage Report

Created: 2017-06-28 17:40

/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.18k
{
21
1.18k
  return cmp(
FN1.18k
(EL,copy)(el1),
FN1.18k
(EL,copy)(el2));
22
1.18k
}
isl_aff.c:isl_pw_aff_better
Line
Count
Source
20
322
{
21
322
  return cmp(
FN322
(EL,copy)(el1),
FN322
(EL,copy)(el2));
22
322
}
isl_aff.c:isl_pw_multi_aff_better
Line
Count
Source
20
866
{
21
866
  return cmp(
FN866
(EL,copy)(el1),
FN866
(EL,copy)(el2));
22
866
}
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.37k
{
28
2.37k
  int i;
29
2.37k
  isl_ctx *ctx;
30
2.37k
  isl_set_list *list;
31
2.37k
32
2.37k
  if (!pw)
33
0
    return NULL;
34
2.37k
  
ctx = 2.37k
FN2.37k
(PW,get_ctx)(pw);
35
2.37k
  list = isl_set_list_alloc(ctx, pw->n);
36
5.68k
  for (i = 0; 
i < pw->n5.68k
;
++i3.31k
)
37
3.31k
    list = isl_set_list_add(list, isl_set_copy(pw->p[i].set));
38
2.37k
39
2.37k
  return list;
40
2.37k
}
isl_aff.c:isl_pw_aff_extract_domains
Line
Count
Source
27
626
{
28
626
  int i;
29
626
  isl_ctx *ctx;
30
626
  isl_set_list *list;
31
626
32
626
  if (!pw)
33
0
    return NULL;
34
626
  
ctx = 626
FN626
(PW,get_ctx)(pw);
35
626
  list = isl_set_list_alloc(ctx, pw->n);
36
1.29k
  for (i = 0; 
i < pw->n1.29k
;
++i665
)
37
665
    list = isl_set_list_add(list, isl_set_copy(pw->p[i].set));
38
626
39
626
  return list;
40
626
}
isl_aff.c:isl_pw_multi_aff_extract_domains
Line
Count
Source
27
1.75k
{
28
1.75k
  int i;
29
1.75k
  isl_ctx *ctx;
30
1.75k
  isl_set_list *list;
31
1.75k
32
1.75k
  if (!pw)
33
0
    return NULL;
34
1.75k
  
ctx = 1.75k
FN1.75k
(PW,get_ctx)(pw);
35
1.75k
  list = isl_set_list_alloc(ctx, pw->n);
36
4.39k
  for (i = 0; 
i < pw->n4.39k
;
++i2.64k
)
37
2.64k
    list = isl_set_list_add(list, isl_set_copy(pw->p[i].set));
38
1.75k
39
1.75k
  return list;
40
1.75k
}
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.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_multi_aff_better_or_out
Line
Count
Source
48
866
{
49
866
  isl_set *set_better, *set_out;
50
866
51
866
  set_better = isl_set_intersect(isl_set_copy(set), isl_set_copy(better));
52
866
  set_out = isl_set_subtract(isl_set_subtract(set, better), out);
53
866
54
866
  return isl_set_union(set_better, set_out);
55
866
}
isl_aff.c:isl_pw_aff_better_or_out
Line
Count
Source
48
322
{
49
322
  isl_set *set_better, *set_out;
50
322
51
322
  set_better = isl_set_intersect(isl_set_copy(set), isl_set_copy(better));
52
322
  set_out = isl_set_subtract(isl_set_subtract(set, better), out);
53
322
54
322
  return isl_set_union(set_better, set_out);
55
322
}
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.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
}
isl_aff.c:isl_pw_aff_worse_or_out
Line
Count
Source
63
322
{
64
322
  isl_set *set_worse, *set_out;
65
322
66
322
  set_worse = isl_set_subtract(isl_set_copy(set), isl_set_copy(better));
67
322
  set_out = isl_set_subtract(isl_set_intersect(set, better), out);
68
322
69
322
  return isl_set_union(set_worse, set_out);
70
322
}
isl_aff.c:isl_pw_multi_aff_worse_or_out
Line
Count
Source
63
866
{
64
866
  isl_set *set_worse, *set_out;
65
866
66
866
  set_worse = isl_set_subtract(isl_set_copy(set), isl_set_copy(better));
67
866
  set_out = isl_set_subtract(isl_set_intersect(set, better), out);
68
866
69
866
  return isl_set_union(set_worse, set_out);
70
866
}
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.18k
{
90
1.18k
  int i, j;
91
1.18k
  PW *res;
92
1.18k
93
1.18k
  if (
!pw1 || 1.18k
!pw21.18k
)
94
0
    goto error;
95
1.18k
96
1.18k
  
res = 1.18k
FN1.18k
(PW,alloc_size)(isl_space_copy(pw1->dim), pw1->n + pw2->n);
97
1.18k
98
1.18k
  i = 0; j = 0;
99
4.05k
  while (
i < pw1->n || 4.05k
j < pw2->n1.62k
)
{2.86k
100
2.86k
    int cmp;
101
2.86k
    isl_set *set;
102
2.86k
    EL *el;
103
2.86k
104
2.86k
    if (
i < pw1->n && 2.86k
j < pw2->n2.43k
)
105
1.64k
      
cmp = 1.64k
FN1.64k
(EL,plain_cmp)(pw1->p[i].
FIELD1.64k
,
106
1.64k
            pw2->p[j].FIELD);
107
2.86k
    else
108
1.22k
      
cmp = i < pw1->n ? 1.22k
-1785
:
1436
;
109
2.86k
110
2.86k
    if (
cmp < 02.86k
)
{1.62k
111
1.62k
      set = isl_set_list_get_set(list1, i);
112
1.62k
      el = 
FN1.62k
(EL,copy)(pw1->p[i].
FIELD1.62k
);
113
1.62k
      ++i;
114
1.24k
    } else 
if (1.24k
cmp > 01.24k
)
{804
115
804
      set = isl_set_list_get_set(list2, j);
116
804
      el = 
FN804
(EL,copy)(pw2->p[j].
FIELD804
);
117
804
      ++j;
118
443
    } else {
119
443
      set = isl_set_union(isl_set_list_get_set(list1, i),
120
443
              isl_set_list_get_set(list2, j));
121
443
      el = 
FN443
(EL,copy)(pw1->p[i].
FIELD443
);
122
443
      ++i;
123
443
      ++j;
124
443
    }
125
2.86k
    res = FN(PW,add_piece)(res, set, el);
126
2.86k
  }
127
1.18k
128
1.18k
  isl_set_list_free(list1);
129
1.18k
  isl_set_list_free(list2);
130
1.18k
  FN(PW,free)(pw1);
131
1.18k
  FN(PW,free)(pw2);
132
1.18k
  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.18k
}
isl_aff.c:isl_pw_aff_merge
Line
Count
Source
89
313
{
90
313
  int i, j;
91
313
  PW *res;
92
313
93
313
  if (
!pw1 || 313
!pw2313
)
94
0
    goto error;
95
313
96
313
  
res = 313
FN313
(PW,alloc_size)(isl_space_copy(pw1->dim), pw1->n + pw2->n);
97
313
98
313
  i = 0; j = 0;
99
964
  while (
i < pw1->n || 964
j < pw2->n470
)
{651
100
651
    int cmp;
101
651
    isl_set *set;
102
651
    EL *el;
103
651
104
651
    if (
i < pw1->n && 651
j < pw2->n494
)
105
341
      
cmp = 341
FN341
(EL,plain_cmp)(pw1->p[i].
FIELD341
,
106
341
            pw2->p[j].FIELD);
107
651
    else
108
310
      
cmp = i < pw1->n ? 310
-1153
:
1157
;
109
651
110
651
    if (
cmp < 0651
)
{338
111
338
      set = isl_set_list_get_set(list1, i);
112
338
      el = 
FN338
(EL,copy)(pw1->p[i].
FIELD338
);
113
338
      ++i;
114
313
    } else 
if (313
cmp > 0313
)
{299
115
299
      set = isl_set_list_get_set(list2, j);
116
299
      el = 
FN299
(EL,copy)(pw2->p[j].
FIELD299
);
117
299
      ++j;
118
14
    } 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
14
    }
125
651
    res = FN(PW,add_piece)(res, set, el);
126
651
  }
127
313
128
313
  isl_set_list_free(list1);
129
313
  isl_set_list_free(list2);
130
313
  FN(PW,free)(pw1);
131
313
  FN(PW,free)(pw2);
132
313
  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
313
}
isl_aff.c:isl_pw_multi_aff_merge
Line
Count
Source
89
875
{
90
875
  int i, j;
91
875
  PW *res;
92
875
93
875
  if (
!pw1 || 875
!pw2875
)
94
0
    goto error;
95
875
96
875
  
res = 875
FN875
(PW,alloc_size)(isl_space_copy(pw1->dim), pw1->n + pw2->n);
97
875
98
875
  i = 0; j = 0;
99
3.09k
  while (
i < pw1->n || 3.09k
j < pw2->n1.15k
)
{2.21k
100
2.21k
    int cmp;
101
2.21k
    isl_set *set;
102
2.21k
    EL *el;
103
2.21k
104
2.21k
    if (
i < pw1->n && 2.21k
j < pw2->n1.93k
)
105
1.30k
      
cmp = 1.30k
FN1.30k
(EL,plain_cmp)(pw1->p[i].
FIELD1.30k
,
106
1.30k
            pw2->p[j].FIELD);
107
2.21k
    else
108
911
      
cmp = i < pw1->n ? 911
-1632
:
1279
;
109
2.21k
110
2.21k
    if (
cmp < 02.21k
)
{1.28k
111
1.28k
      set = isl_set_list_get_set(list1, i);
112
1.28k
      el = 
FN1.28k
(EL,copy)(pw1->p[i].
FIELD1.28k
);
113
1.28k
      ++i;
114
934
    } else 
if (934
cmp > 0934
)
{505
115
505
      set = isl_set_list_get_set(list2, j);
116
505
      el = 
FN505
(EL,copy)(pw2->p[j].
FIELD505
);
117
505
      ++j;
118
429
    } else {
119
429
      set = isl_set_union(isl_set_list_get_set(list1, i),
120
429
              isl_set_list_get_set(list2, j));
121
429
      el = 
FN429
(EL,copy)(pw1->p[i].
FIELD429
);
122
429
      ++i;
123
429
      ++j;
124
429
    }
125
2.21k
    res = FN(PW,add_piece)(res, set, el);
126
2.21k
  }
127
875
128
875
  isl_set_list_free(list1);
129
875
  isl_set_list_free(list2);
130
875
  FN(PW,free)(pw1);
131
875
  FN(PW,free)(pw2);
132
875
  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
875
}
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.45k
{
186
1.45k
  int i, j;
187
1.45k
  PW *res = NULL;
188
1.45k
  isl_ctx *ctx;
189
1.45k
  isl_set *set = NULL;
190
1.45k
  isl_set_list *list1 = NULL, *list2 = NULL;
191
1.45k
192
1.45k
  if (
!pw1 || 1.45k
!pw21.45k
)
193
0
    goto error;
194
1.45k
195
1.45k
  ctx = isl_space_get_ctx(pw1->dim);
196
1.45k
  if (!isl_space_is_equal(pw1->dim, pw2->dim))
197
0
    isl_die(ctx, isl_error_invalid,
198
1.45k
      "arguments should live in the same space", goto error);
199
1.45k
200
1.45k
  
if (1.45k
FN1.45k
(PW,is_empty)(pw1)1.45k
)
{241
201
241
    FN(PW,free)(pw1);
202
241
    return pw2;
203
241
  }
204
1.45k
205
1.21k
  
if (1.21k
FN1.21k
(PW,is_empty)(pw2)1.21k
)
{27
206
27
    FN(PW,free)(pw2);
207
27
    return pw1;
208
27
  }
209
1.21k
210
1.18k
  
pw1 = 1.18k
FN1.18k
(PW,sort)(pw1);
211
1.18k
  pw2 = FN(PW,sort)(pw2);
212
1.18k
  if (
!pw1 || 1.18k
!pw21.18k
)
213
0
    goto error;
214
1.18k
215
1.18k
  
list1 = 1.18k
FN1.18k
(PW,extract_domains)(pw1);
216
1.18k
  list2 = FN(PW,extract_domains)(pw2);
217
1.18k
218
3.25k
  for (i = 0; 
i < pw1->n3.25k
;
++i2.06k
)
{2.06k
219
4.51k
    for (j = 0; 
j < pw2->n4.51k
;
++j2.45k
)
{2.45k
220
2.45k
      isl_bool disjoint;
221
2.45k
      isl_set *better, *set_i, *set_j;
222
2.45k
223
2.45k
      disjoint = isl_set_is_disjoint(pw1->p[i].set,
224
2.45k
              pw2->p[j].set);
225
2.45k
      if (disjoint < 0)
226
0
        goto error;
227
2.45k
      
if (2.45k
disjoint2.45k
)
228
1.26k
        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
1.18k
      list2 = isl_set_list_set_set(list2, j, set_j);
240
1.18k
    }
241
2.06k
  }
242
1.18k
243
1.18k
  
res = 1.18k
FN1.18k
(PW,merge)(pw1, pw2, list1, list2);
244
1.18k
245
1.18k
  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.18k
}
isl_aff.c:isl_pw_aff_union_opt_cmp
Line
Count
Source
185
313
{
186
313
  int i, j;
187
313
  PW *res = NULL;
188
313
  isl_ctx *ctx;
189
313
  isl_set *set = NULL;
190
313
  isl_set_list *list1 = NULL, *list2 = NULL;
191
313
192
313
  if (
!pw1 || 313
!pw2313
)
193
0
    goto error;
194
313
195
313
  ctx = isl_space_get_ctx(pw1->dim);
196
313
  if (!isl_space_is_equal(pw1->dim, pw2->dim))
197
0
    isl_die(ctx, isl_error_invalid,
198
313
      "arguments should live in the same space", goto error);
199
313
200
313
  
if (313
FN313
(PW,is_empty)(pw1)313
)
{0
201
0
    FN(PW,free)(pw1);
202
0
    return pw2;
203
0
  }
204
313
205
313
  
if (313
FN313
(PW,is_empty)(pw2)313
)
{0
206
0
    FN(PW,free)(pw2);
207
0
    return pw1;
208
0
  }
209
313
210
313
  
pw1 = 313
FN313
(PW,sort)(pw1);
211
313
  pw2 = FN(PW,sort)(pw2);
212
313
  if (
!pw1 || 313
!pw2313
)
213
0
    goto error;
214
313
215
313
  
list1 = 313
FN313
(PW,extract_domains)(pw1);
216
313
  list2 = FN(PW,extract_domains)(pw2);
217
313
218
665
  for (i = 0; 
i < pw1->n665
;
++i352
)
{352
219
704
    for (j = 0; 
j < pw2->n704
;
++j352
)
{352
220
352
      isl_bool disjoint;
221
352
      isl_set *better, *set_i, *set_j;
222
352
223
352
      disjoint = isl_set_is_disjoint(pw1->p[i].set,
224
352
              pw2->p[j].set);
225
352
      if (disjoint < 0)
226
0
        goto error;
227
352
      
if (352
disjoint352
)
228
30
        continue;
229
322
      
better = 322
FN322
(PW,better)(pw2->p[j].
FIELD322
,
230
322
            pw1->p[i].FIELD, cmp);
231
322
      set_i = isl_set_list_get_set(list1, i);
232
322
      set_j = isl_set_copy(pw2->p[j].set);
233
322
      set_i = FN(PW,worse_or_out)(set_i,
234
322
            isl_set_copy(better), set_j);
235
322
      list1 = isl_set_list_set_set(list1, i, set_i);
236
322
      set_i = isl_set_copy(pw1->p[i].set);
237
322
      set_j = isl_set_list_get_set(list2, j);
238
322
      set_j = FN(PW,better_or_out)(set_j, better, set_i);
239
322
      list2 = isl_set_list_set_set(list2, j, set_j);
240
322
    }
241
352
  }
242
313
243
313
  
res = 313
FN313
(PW,merge)(pw1, pw2, list1, list2);
244
313
245
313
  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
313
}
isl_aff.c:isl_pw_multi_aff_union_opt_cmp
Line
Count
Source
185
1.14k
{
186
1.14k
  int i, j;
187
1.14k
  PW *res = NULL;
188
1.14k
  isl_ctx *ctx;
189
1.14k
  isl_set *set = NULL;
190
1.14k
  isl_set_list *list1 = NULL, *list2 = NULL;
191
1.14k
192
1.14k
  if (
!pw1 || 1.14k
!pw21.14k
)
193
0
    goto error;
194
1.14k
195
1.14k
  ctx = isl_space_get_ctx(pw1->dim);
196
1.14k
  if (!isl_space_is_equal(pw1->dim, pw2->dim))
197
0
    isl_die(ctx, isl_error_invalid,
198
1.14k
      "arguments should live in the same space", goto error);
199
1.14k
200
1.14k
  
if (1.14k
FN1.14k
(PW,is_empty)(pw1)1.14k
)
{241
201
241
    FN(PW,free)(pw1);
202
241
    return pw2;
203
241
  }
204
1.14k
205
902
  
if (902
FN902
(PW,is_empty)(pw2)902
)
{27
206
27
    FN(PW,free)(pw2);
207
27
    return pw1;
208
27
  }
209
902
210
875
  
pw1 = 875
FN875
(PW,sort)(pw1);
211
875
  pw2 = FN(PW,sort)(pw2);
212
875
  if (
!pw1 || 875
!pw2875
)
213
0
    goto error;
214
875
215
875
  
list1 = 875
FN875
(PW,extract_domains)(pw1);
216
875
  list2 = FN(PW,extract_domains)(pw2);
217
875
218
2.58k
  for (i = 0; 
i < pw1->n2.58k
;
++i1.71k
)
{1.71k
219
3.80k
    for (j = 0; 
j < pw2->n3.80k
;
++j2.09k
)
{2.09k
220
2.09k
      isl_bool disjoint;
221
2.09k
      isl_set *better, *set_i, *set_j;
222
2.09k
223
2.09k
      disjoint = isl_set_is_disjoint(pw1->p[i].set,
224
2.09k
              pw2->p[j].set);
225
2.09k
      if (disjoint < 0)
226
0
        goto error;
227
2.09k
      
if (2.09k
disjoint2.09k
)
228
1.23k
        continue;
229
866
      
better = 866
FN866
(PW,better)(pw2->p[j].
FIELD866
,
230
866
            pw1->p[i].FIELD, cmp);
231
866
      set_i = isl_set_list_get_set(list1, i);
232
866
      set_j = isl_set_copy(pw2->p[j].set);
233
866
      set_i = FN(PW,worse_or_out)(set_i,
234
866
            isl_set_copy(better), set_j);
235
866
      list1 = isl_set_list_set_set(list1, i, set_i);
236
866
      set_i = isl_set_copy(pw1->p[i].set);
237
866
      set_j = isl_set_list_get_set(list2, j);
238
866
      set_j = FN(PW,better_or_out)(set_j, better, set_i);
239
866
      list2 = isl_set_list_set_set(list2, j, set_j);
240
866
    }
241
1.71k
  }
242
875
243
875
  
res = 875
FN875
(PW,merge)(pw1, pw2, list1, list2);
244
875
245
875
  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
875
}