Bug Summary

File:tools/polly/lib/External/isl/isl_morph.c
Warning:line 759, column 56
Use of memory after it is freed

Annotated Source Code

[?] Use j/k keys for keyboard navigation

1/*
2 * Copyright 2010-2011 INRIA Saclay
3 * Copyright 2014 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_map_private.h>
14#include <isl_aff_private.h>
15#include <isl_morph.h>
16#include <isl_seq.h>
17#include <isl_mat_private.h>
18#include <isl_space_private.h>
19#include <isl_equalities.h>
20#include <isl_id_private.h>
21
22isl_ctx *isl_morph_get_ctx(__isl_keep isl_morph *morph)
23{
24 if (!morph)
25 return NULL((void*)0);
26 return isl_basic_set_get_ctx(morph->dom);
27}
28
29__isl_give isl_morph *isl_morph_alloc(
30 __isl_take isl_basic_setisl_basic_map *dom, __isl_take isl_basic_setisl_basic_map *ran,
31 __isl_take isl_mat *map, __isl_take isl_mat *inv)
32{
33 isl_morph *morph;
34
35 if (!dom || !ran || !map || !inv)
12
Assuming 'dom' is non-null
13
Assuming 'ran' is non-null
14
Assuming 'map' is non-null
15
Assuming 'inv' is non-null
16
Taking false branch
36 goto error;
37
38 morph = isl_alloc_type(dom->ctx, struct isl_morph)((struct isl_morph *)isl_malloc_or_die(dom->ctx, sizeof(struct
isl_morph)))
;
39 if (!morph)
17
Assuming 'morph' is non-null
18
Taking false branch
40 goto error;
41
42 morph->ref = 1;
43 morph->dom = dom;
44 morph->ran = ran;
45 morph->map = map;
46 morph->inv = inv;
47
48 return morph;
49error:
50 isl_basic_set_free(dom);
51 isl_basic_set_free(ran);
52 isl_mat_free(map);
53 isl_mat_free(inv);
54 return NULL((void*)0);
55}
56
57__isl_give isl_morph *isl_morph_copy(__isl_keep isl_morph *morph)
58{
59 if (!morph)
60 return NULL((void*)0);
61
62 morph->ref++;
63 return morph;
64}
65
66__isl_give isl_morph *isl_morph_dup(__isl_keep isl_morph *morph)
67{
68 if (!morph)
69 return NULL((void*)0);
70
71 return isl_morph_alloc(isl_basic_set_copy(morph->dom),
72 isl_basic_set_copy(morph->ran),
73 isl_mat_copy(morph->map), isl_mat_copy(morph->inv));
74}
75
76__isl_give isl_morph *isl_morph_cow(__isl_take isl_morph *morph)
77{
78 if (!morph)
79 return NULL((void*)0);
80
81 if (morph->ref == 1)
82 return morph;
83 morph->ref--;
84 return isl_morph_dup(morph);
85}
86
87__isl_null isl_morph *isl_morph_free(__isl_take isl_morph *morph)
88{
89 if (!morph)
43
Taking false branch
90 return NULL((void*)0);
91
92 if (--morph->ref > 0)
44
Assuming the condition is false
45
Taking false branch
93 return NULL((void*)0);
94
95 isl_basic_set_free(morph->dom);
96 isl_basic_set_free(morph->ran);
97 isl_mat_free(morph->map);
98 isl_mat_free(morph->inv);
99 free(morph);
46
Memory is released
100
101 return NULL((void*)0);
102}
103
104/* Is "morph" an identity on the parameters?
105 */
106static int identity_on_parameters(__isl_keep isl_morph *morph)
107{
108 int is_identity;
109 unsigned nparam;
110 isl_mat *sub;
111
112 nparam = isl_morph_dom_dim(morph, isl_dim_param);
113 if (nparam != isl_morph_ran_dim(morph, isl_dim_param))
114 return 0;
115 if (nparam == 0)
116 return 1;
117 sub = isl_mat_sub_alloc(morph->map, 0, 1 + nparam, 0, 1 + nparam);
118 is_identity = isl_mat_is_scaled_identity(sub);
119 isl_mat_free(sub);
120
121 return is_identity;
122}
123
124/* Return an affine expression of the variables of the range of "morph"
125 * in terms of the parameters and the variables of the domain on "morph".
126 *
127 * In order for the space manipulations to make sense, we require
128 * that the parameters are not modified by "morph".
129 */
130__isl_give isl_multi_aff *isl_morph_get_var_multi_aff(
131 __isl_keep isl_morph *morph)
132{
133 isl_space *dom, *ran, *space;
134 isl_local_space *ls;
135 isl_multi_aff *ma;
136 unsigned nparam, nvar;
137 int i;
138 int is_identity;
139
140 if (!morph)
141 return NULL((void*)0);
142
143 is_identity = identity_on_parameters(morph);
144 if (is_identity < 0)
145 return NULL((void*)0);
146 if (!is_identity)
147 isl_die(isl_morph_get_ctx(morph), isl_error_invalid,do { isl_handle_error(isl_morph_get_ctx(morph), isl_error_invalid
, "cannot handle parameter compression", "/build/llvm-toolchain-snapshot-6.0~svn321639/tools/polly/lib/External/isl/isl_morph.c"
, 148); return ((void*)0); } while (0)
148 "cannot handle parameter compression", return NULL)do { isl_handle_error(isl_morph_get_ctx(morph), isl_error_invalid
, "cannot handle parameter compression", "/build/llvm-toolchain-snapshot-6.0~svn321639/tools/polly/lib/External/isl/isl_morph.c"
, 148); return ((void*)0); } while (0)
;
149
150 dom = isl_morph_get_dom_space(morph);
151 ls = isl_local_space_from_space(isl_space_copy(dom));
152 ran = isl_morph_get_ran_space(morph);
153 space = isl_space_map_from_domain_and_range(dom, ran);
154 ma = isl_multi_aff_zero(space);
155
156 nparam = isl_multi_aff_dim(ma, isl_dim_param);
157 nvar = isl_multi_aff_dim(ma, isl_dim_out);
158 for (i = 0; i < nvar; ++i) {
159 isl_val *val;
160 isl_vec *v;
161 isl_aff *aff;
162
163 v = isl_mat_get_row(morph->map, 1 + nparam + i);
164 v = isl_vec_insert_els(v, 0, 1);
165 val = isl_mat_get_element_val(morph->map, 0, 0);
166 v = isl_vec_set_element_val(v, 0, val);
167 aff = isl_aff_alloc_vec(isl_local_space_copy(ls), v);
168 ma = isl_multi_aff_set_aff(ma, i, aff);
169 }
170
171 isl_local_space_free(ls);
172 return ma;
173}
174
175/* Return the domain space of "morph".
176 */
177__isl_give isl_space *isl_morph_get_dom_space(__isl_keep isl_morph *morph)
178{
179 if (!morph)
180 return NULL((void*)0);
181
182 return isl_basic_set_get_space(morph->dom);
183}
184
185__isl_give isl_space *isl_morph_get_ran_space(__isl_keep isl_morph *morph)
186{
187 if (!morph)
188 return NULL((void*)0);
189
190 return isl_space_copy(morph->ran->dim);
191}
192
193unsigned isl_morph_dom_dim(__isl_keep isl_morph *morph, enum isl_dim_type type)
194{
195 if (!morph)
196 return 0;
197
198 return isl_basic_set_dim(morph->dom, type);
199}
200
201unsigned isl_morph_ran_dim(__isl_keep isl_morph *morph, enum isl_dim_type type)
202{
203 if (!morph)
204 return 0;
205
206 return isl_basic_set_dim(morph->ran, type);
207}
208
209__isl_give isl_morph *isl_morph_remove_dom_dims(__isl_take isl_morph *morph,
210 enum isl_dim_type type, unsigned first, unsigned n)
211{
212 unsigned dom_offset;
213
214 if (n == 0)
215 return morph;
216
217 morph = isl_morph_cow(morph);
218 if (!morph)
219 return NULL((void*)0);
220
221 dom_offset = 1 + isl_space_offset(morph->dom->dim, type);
222
223 morph->dom = isl_basic_set_remove_dims(morph->dom, type, first, n);
224
225 morph->map = isl_mat_drop_cols(morph->map, dom_offset + first, n);
226
227 morph->inv = isl_mat_drop_rows(morph->inv, dom_offset + first, n);
228
229 if (morph->dom && morph->ran && morph->map && morph->inv)
230 return morph;
231
232 isl_morph_free(morph);
233 return NULL((void*)0);
234}
235
236__isl_give isl_morph *isl_morph_remove_ran_dims(__isl_take isl_morph *morph,
237 enum isl_dim_type type, unsigned first, unsigned n)
238{
239 unsigned ran_offset;
240
241 if (n == 0)
242 return morph;
243
244 morph = isl_morph_cow(morph);
245 if (!morph)
246 return NULL((void*)0);
247
248 ran_offset = 1 + isl_space_offset(morph->ran->dim, type);
249
250 morph->ran = isl_basic_set_remove_dims(morph->ran, type, first, n);
251
252 morph->map = isl_mat_drop_rows(morph->map, ran_offset + first, n);
253
254 morph->inv = isl_mat_drop_cols(morph->inv, ran_offset + first, n);
255
256 if (morph->dom && morph->ran && morph->map && morph->inv)
257 return morph;
258
259 isl_morph_free(morph);
260 return NULL((void*)0);
261}
262
263/* Project domain of morph onto its parameter domain.
264 */
265__isl_give isl_morph *isl_morph_dom_params(__isl_take isl_morph *morph)
266{
267 unsigned n;
268
269 morph = isl_morph_cow(morph);
270 if (!morph)
271 return NULL((void*)0);
272 n = isl_basic_set_dim(morph->dom, isl_dim_set);
273 morph = isl_morph_remove_dom_dims(morph, isl_dim_set, 0, n);
274 if (!morph)
275 return NULL((void*)0);
276 morph->dom = isl_basic_set_params(morph->dom);
277 if (morph->dom)
278 return morph;
279
280 isl_morph_free(morph);
281 return NULL((void*)0);
282}
283
284/* Project range of morph onto its parameter domain.
285 */
286__isl_give isl_morph *isl_morph_ran_params(__isl_take isl_morph *morph)
287{
288 unsigned n;
289
290 morph = isl_morph_cow(morph);
291 if (!morph)
292 return NULL((void*)0);
293 n = isl_basic_set_dim(morph->ran, isl_dim_set);
294 morph = isl_morph_remove_ran_dims(morph, isl_dim_set, 0, n);
295 if (!morph)
296 return NULL((void*)0);
297 morph->ran = isl_basic_set_params(morph->ran);
298 if (morph->ran)
299 return morph;
300
301 isl_morph_free(morph);
302 return NULL((void*)0);
303}
304
305void isl_morph_print_internal(__isl_take isl_morph *morph, FILE *out)
306{
307 if (!morph)
308 return;
309
310 isl_basic_set_dump(morph->dom);
311 isl_basic_set_dump(morph->ran);
312 isl_mat_print_internal(morph->map, out, 4);
313 isl_mat_print_internal(morph->inv, out, 4);
314}
315
316void isl_morph_dump(__isl_take isl_morph *morph)
317{
318 isl_morph_print_internal(morph, stderrstderr);
319}
320
321__isl_give isl_morph *isl_morph_identity(__isl_keep isl_basic_setisl_basic_map *bset)
322{
323 isl_mat *id;
324 isl_basic_setisl_basic_map *universe;
325 unsigned total;
326
327 if (!bset)
328 return NULL((void*)0);
329
330 total = isl_basic_set_total_dim(bset);
331 id = isl_mat_identity(bset->ctx, 1 + total);
332 universe = isl_basic_set_universe(isl_space_copy(bset->dim));
333
334 return isl_morph_alloc(universe, isl_basic_set_copy(universe),
335 id, isl_mat_copy(id));
336}
337
338/* Create a(n identity) morphism between empty sets of the same dimension
339 * a "bset".
340 */
341__isl_give isl_morph *isl_morph_empty(__isl_keep isl_basic_setisl_basic_map *bset)
342{
343 isl_mat *id;
344 isl_basic_setisl_basic_map *empty;
345 unsigned total;
346
347 if (!bset)
348 return NULL((void*)0);
349
350 total = isl_basic_set_total_dim(bset);
351 id = isl_mat_identity(bset->ctx, 1 + total);
352 empty = isl_basic_set_empty(isl_space_copy(bset->dim));
353
354 return isl_morph_alloc(empty, isl_basic_set_copy(empty),
355 id, isl_mat_copy(id));
356}
357
358/* Construct a basic set described by the "n" equalities of "bset" starting
359 * at "first".
360 */
361static __isl_give isl_basic_setisl_basic_map *copy_equalities(__isl_keep isl_basic_setisl_basic_map *bset,
362 unsigned first, unsigned n)
363{
364 int i, k;
365 isl_basic_setisl_basic_map *eq;
366 unsigned total;
367
368 isl_assert(bset->ctx, bset->n_div == 0, return NULL)do { if (bset->n_div == 0) break; do { isl_handle_error(bset
->ctx, isl_error_unknown, "Assertion \"" "bset->n_div == 0"
"\" failed", "/build/llvm-toolchain-snapshot-6.0~svn321639/tools/polly/lib/External/isl/isl_morph.c"
, 368); return ((void*)0); } while (0); } while (0)
;
369
370 total = isl_basic_set_total_dim(bset);
371 eq = isl_basic_set_alloc_space(isl_space_copy(bset->dim), 0, n, 0);
372 if (!eq)
373 return NULL((void*)0);
374 for (i = 0; i < n; ++i) {
375 k = isl_basic_set_alloc_equality(eq);
376 if (k < 0)
377 goto error;
378 isl_seq_cpy(eq->eq[k], bset->eq[first + i], 1 + total);
379 }
380
381 return eq;
382error:
383 isl_basic_set_free(eq);
384 return NULL((void*)0);
385}
386
387/* Given a basic set, exploit the equalities in the basic set to construct
388 * a morphism that maps the basic set to a lower-dimensional space
389 * with identifier "id".
390 * Specifically, the morphism reduces the number of dimensions of type "type".
391 *
392 * We first select the equalities of interest, that is those that involve
393 * variables of type "type" and no later variables.
394 * Denote those equalities as
395 *
396 * -C(p) + M x = 0
397 *
398 * where C(p) depends on the parameters if type == isl_dim_set and
399 * is a constant if type == isl_dim_param.
400 *
401 * Use isl_mat_final_variable_compression to construct a compression
402 *
403 * x = T x'
404 *
405 * x' = Q x
406 *
407 * If T is a zero-column matrix, then the set of equality constraints
408 * do not admit a solution. In this case, an empty morphism is returned.
409 *
410 * Both matrices are extended to map the full original space to the full
411 * compressed space.
412 */
413__isl_give isl_morph *isl_basic_set_variable_compression_with_id(
414 __isl_keep isl_basic_setisl_basic_map *bset, enum isl_dim_type type,
415 __isl_keep isl_id *id)
416{
417 unsigned otype;
418 unsigned ntype;
419 unsigned orest;
420 unsigned nrest;
421 int f_eq, n_eq;
422 isl_space *space;
423 isl_mat *E, *Q, *C;
424 isl_basic_setisl_basic_map *dom, *ran;
425
426 if (!bset)
427 return NULL((void*)0);
428
429 if (isl_basic_set_plain_is_empty(bset))
430 return isl_morph_empty(bset);
431
432 isl_assert(bset->ctx, bset->n_div == 0, return NULL)do { if (bset->n_div == 0) break; do { isl_handle_error(bset
->ctx, isl_error_unknown, "Assertion \"" "bset->n_div == 0"
"\" failed", "/build/llvm-toolchain-snapshot-6.0~svn321639/tools/polly/lib/External/isl/isl_morph.c"
, 432); return ((void*)0); } while (0); } while (0)
;
433
434 otype = 1 + isl_space_offset(bset->dim, type);
435 ntype = isl_basic_set_dim(bset, type);
436 orest = otype + ntype;
437 nrest = isl_basic_set_total_dim(bset) - (orest - 1);
438
439 for (f_eq = 0; f_eq < bset->n_eq; ++f_eq)
440 if (isl_seq_first_non_zero(bset->eq[f_eq] + orest, nrest) == -1)
441 break;
442 for (n_eq = 0; f_eq + n_eq < bset->n_eq; ++n_eq)
443 if (isl_seq_first_non_zero(bset->eq[f_eq + n_eq] + otype, ntype) == -1)
444 break;
445 if (n_eq == 0)
446 return isl_morph_identity(bset);
447
448 E = isl_mat_sub_alloc6(bset->ctx, bset->eq, f_eq, n_eq, 0, orest);
449 C = isl_mat_final_variable_compression(E, otype - 1, &Q);
450 if (!Q)
451 C = isl_mat_free(C);
452 if (C && C->n_col == 0) {
453 isl_mat_free(C);
454 isl_mat_free(Q);
455 return isl_morph_empty(bset);
456 }
457
458 Q = isl_mat_diagonal(Q, isl_mat_identity(bset->ctx, nrest));
459 C = isl_mat_diagonal(C, isl_mat_identity(bset->ctx, nrest));
460
461 space = isl_space_copy(bset->dim);
462 space = isl_space_drop_dims(space, type, 0, ntype);
463 space = isl_space_add_dims(space, type, ntype - n_eq);
464 space = isl_space_set_tuple_id(space, isl_dim_set, isl_id_copy(id));
465 ran = isl_basic_set_universe(space);
466 dom = copy_equalities(bset, f_eq, n_eq);
467
468 return isl_morph_alloc(dom, ran, Q, C);
469}
470
471/* Given a basic set, exploit the equalities in the basic set to construct
472 * a morphism that maps the basic set to a lower-dimensional space.
473 * Specifically, the morphism reduces the number of dimensions of type "type".
474 */
475__isl_give isl_morph *isl_basic_set_variable_compression(
476 __isl_keep isl_basic_setisl_basic_map *bset, enum isl_dim_type type)
477{
478 return isl_basic_set_variable_compression_with_id(bset, type,
479 &isl_id_none);
480}
481
482/* Construct a parameter compression for "bset".
483 * We basically just call isl_mat_parameter_compression with the right input
484 * and then extend the resulting matrix to include the variables.
485 *
486 * The implementation assumes that "bset" does not have any equalities
487 * that only involve the parameters and that isl_basic_set_gauss has
488 * been applied to "bset".
489 *
490 * Let the equalities be given as
491 *
492 * B(p) + A x = 0.
493 *
494 * We use isl_mat_parameter_compression_ext to compute the compression
495 *
496 * p = T p'.
497 */
498__isl_give isl_morph *isl_basic_set_parameter_compression(
499 __isl_keep isl_basic_setisl_basic_map *bset)
500{
501 unsigned nparam;
502 unsigned nvar;
503 unsigned n_div;
504 int n_eq;
505 isl_mat *H, *B;
506 isl_mat *map, *inv;
507 isl_basic_setisl_basic_map *dom, *ran;
508
509 if (!bset)
2
Assuming 'bset' is non-null
3
Taking false branch
510 return NULL((void*)0);
511
512 if (isl_basic_set_plain_is_empty(bset))
4
Assuming the condition is false
5
Taking false branch
513 return isl_morph_empty(bset);
514 if (bset->n_eq == 0)
6
Assuming the condition is false
7
Taking false branch
515 return isl_morph_identity(bset);
516
517 n_eq = bset->n_eq;
518 nparam = isl_basic_set_dim(bset, isl_dim_param);
519 nvar = isl_basic_set_dim(bset, isl_dim_set);
520 n_div = isl_basic_set_dim(bset, isl_dim_div);
521
522 if (isl_seq_first_non_zero(bset->eq[bset->n_eq - 1] + 1 + nparam,
8
Assuming the condition is false
9
Taking false branch
523 nvar + n_div) == -1)
524 isl_die(isl_basic_set_get_ctx(bset), isl_error_invalid,do { isl_handle_error(isl_basic_set_get_ctx(bset), isl_error_invalid
, "input not allowed to have parameter equalities", "/build/llvm-toolchain-snapshot-6.0~svn321639/tools/polly/lib/External/isl/isl_morph.c"
, 526); return ((void*)0); } while (0)
525 "input not allowed to have parameter equalities",do { isl_handle_error(isl_basic_set_get_ctx(bset), isl_error_invalid
, "input not allowed to have parameter equalities", "/build/llvm-toolchain-snapshot-6.0~svn321639/tools/polly/lib/External/isl/isl_morph.c"
, 526); return ((void*)0); } while (0)
526 return NULL)do { isl_handle_error(isl_basic_set_get_ctx(bset), isl_error_invalid
, "input not allowed to have parameter equalities", "/build/llvm-toolchain-snapshot-6.0~svn321639/tools/polly/lib/External/isl/isl_morph.c"
, 526); return ((void*)0); } while (0)
;
527 if (n_eq > nvar + n_div)
10
Taking false branch
528 isl_die(isl_basic_set_get_ctx(bset), isl_error_invalid,do { isl_handle_error(isl_basic_set_get_ctx(bset), isl_error_invalid
, "input not gaussed", "/build/llvm-toolchain-snapshot-6.0~svn321639/tools/polly/lib/External/isl/isl_morph.c"
, 529); return ((void*)0); } while (0)
529 "input not gaussed", return NULL)do { isl_handle_error(isl_basic_set_get_ctx(bset), isl_error_invalid
, "input not gaussed", "/build/llvm-toolchain-snapshot-6.0~svn321639/tools/polly/lib/External/isl/isl_morph.c"
, 529); return ((void*)0); } while (0)
;
530
531 B = isl_mat_sub_alloc6(bset->ctx, bset->eq, 0, n_eq, 0, 1 + nparam);
532 H = isl_mat_sub_alloc6(bset->ctx, bset->eq,
533 0, n_eq, 1 + nparam, nvar + n_div);
534 inv = isl_mat_parameter_compression_ext(B, H);
535 inv = isl_mat_diagonal(inv, isl_mat_identity(bset->ctx, nvar));
536 map = isl_mat_right_inverse(isl_mat_copy(inv));
537
538 dom = isl_basic_set_universe(isl_space_copy(bset->dim));
539 ran = isl_basic_set_universe(isl_space_copy(bset->dim));
540
541 return isl_morph_alloc(dom, ran, map, inv);
11
Calling 'isl_morph_alloc'
19
Returning from 'isl_morph_alloc'
542}
543
544/* Add stride constraints to "bset" based on the inverse mapping
545 * that was plugged in. In particular, if morph maps x' to x,
546 * the the constraints of the original input
547 *
548 * A x' + b >= 0
549 *
550 * have been rewritten to
551 *
552 * A inv x + b >= 0
553 *
554 * However, this substitution may loose information on the integrality of x',
555 * so we need to impose that
556 *
557 * inv x
558 *
559 * is integral. If inv = B/d, this means that we need to impose that
560 *
561 * B x = 0 mod d
562 *
563 * or
564 *
565 * exists alpha in Z^m: B x = d alpha
566 *
567 * This function is similar to add_strides in isl_affine_hull.c
568 */
569static __isl_give isl_basic_setisl_basic_map *add_strides(__isl_take isl_basic_setisl_basic_map *bset,
570 __isl_keep isl_morph *morph)
571{
572 int i, div, k;
573 isl_int gcd;
574
575 if (isl_int_is_one(morph->inv->row[0][0])(isl_sioimath_cmp_si(*(morph->inv->row[0][0]), 1) == 0))
576 return bset;
577
578 isl_int_init(gcd)isl_sioimath_init((gcd));
579
580 for (i = 0; 1 + i < morph->inv->n_row; ++i) {
581 isl_seq_gcd(morph->inv->row[1 + i], morph->inv->n_col, &gcd);
582 if (isl_int_is_divisible_by(gcd, morph->inv->row[0][0])isl_sioimath_is_divisible_by(*(gcd), *(morph->inv->row[
0][0]))
)
583 continue;
584 div = isl_basic_set_alloc_div(bset);
585 if (div < 0)
586 goto error;
587 isl_int_set_si(bset->div[div][0], 0)isl_sioimath_set_si((bset->div[div][0]), 0);
588 k = isl_basic_set_alloc_equality(bset);
589 if (k < 0)
590 goto error;
591 isl_seq_cpy(bset->eq[k], morph->inv->row[1 + i],
592 morph->inv->n_col);
593 isl_seq_clr(bset->eq[k] + morph->inv->n_col, bset->n_div);
594 isl_int_set(bset->eq[k][morph->inv->n_col + div],isl_sioimath_set((bset->eq[k][morph->inv->n_col + div
]), *(morph->inv->row[0][0]))
595 morph->inv->row[0][0])isl_sioimath_set((bset->eq[k][morph->inv->n_col + div
]), *(morph->inv->row[0][0]))
;
596 }
597
598 isl_int_clear(gcd)isl_sioimath_clear((gcd));
599
600 return bset;
601error:
602 isl_int_clear(gcd)isl_sioimath_clear((gcd));
603 isl_basic_set_free(bset);
604 return NULL((void*)0);
605}
606
607/* Apply the morphism to the basic set.
608 * We basically just compute the preimage of "bset" under the inverse mapping
609 * in morph, add in stride constraints and intersect with the range
610 * of the morphism.
611 */
612__isl_give isl_basic_setisl_basic_map *isl_morph_basic_set(__isl_take isl_morph *morph,
613 __isl_take isl_basic_setisl_basic_map *bset)
614{
615 isl_basic_setisl_basic_map *res = NULL((void*)0);
616 isl_mat *mat = NULL((void*)0);
617 int i, k;
618 int max_stride;
619
620 if (!morph || !bset)
24
Assuming 'bset' is non-null
25
Taking false branch
621 goto error;
622
623 isl_assert(bset->ctx, isl_space_is_equal(bset->dim, morph->dom->dim),do { if (isl_space_is_equal(bset->dim, morph->dom->dim
)) break; do { isl_handle_error(bset->ctx, isl_error_unknown
, "Assertion \"" "isl_space_is_equal(bset->dim, morph->dom->dim)"
"\" failed", "/build/llvm-toolchain-snapshot-6.0~svn321639/tools/polly/lib/External/isl/isl_morph.c"
, 624); goto error; } while (0); } while (0)
624 goto error)do { if (isl_space_is_equal(bset->dim, morph->dom->dim
)) break; do { isl_handle_error(bset->ctx, isl_error_unknown
, "Assertion \"" "isl_space_is_equal(bset->dim, morph->dom->dim)"
"\" failed", "/build/llvm-toolchain-snapshot-6.0~svn321639/tools/polly/lib/External/isl/isl_morph.c"
, 624); goto error; } while (0); } while (0)
;
625
626 max_stride = morph->inv->n_row - 1;
627 if (isl_int_is_one(morph->inv->row[0][0])(isl_sioimath_cmp_si(*(morph->inv->row[0][0]), 1) == 0))
26
Taking false branch
628 max_stride = 0;
629 res = isl_basic_set_alloc_space(isl_space_copy(morph->ran->dim),
630 bset->n_div + max_stride, bset->n_eq + max_stride, bset->n_ineq);
631
632 for (i = 0; i < bset->n_div; ++i)
27
Assuming the condition is false
28
Loop condition is false. Execution continues on line 636
633 if (isl_basic_set_alloc_div(res) < 0)
634 goto error;
635
636 mat = isl_mat_sub_alloc6(bset->ctx, bset->eq, 0, bset->n_eq,
637 0, morph->inv->n_row);
638 mat = isl_mat_product(mat, isl_mat_copy(morph->inv));
639 if (!mat)
29
Assuming 'mat' is non-null
30
Taking false branch
640 goto error;
641 for (i = 0; i < bset->n_eq; ++i) {
31
Assuming the condition is false
32
Loop condition is false. Execution continues on line 649
642 k = isl_basic_set_alloc_equality(res);
643 if (k < 0)
644 goto error;
645 isl_seq_cpy(res->eq[k], mat->row[i], mat->n_col);
646 isl_seq_scale(res->eq[k] + mat->n_col, bset->eq[i] + mat->n_col,
647 morph->inv->row[0][0], bset->n_div);
648 }
649 isl_mat_free(mat);
650
651 mat = isl_mat_sub_alloc6(bset->ctx, bset->ineq, 0, bset->n_ineq,
652 0, morph->inv->n_row);
653 mat = isl_mat_product(mat, isl_mat_copy(morph->inv));
654 if (!mat)
33
Assuming 'mat' is non-null
34
Taking false branch
655 goto error;
656 for (i = 0; i < bset->n_ineq; ++i) {
35
Assuming the condition is false
36
Loop condition is false. Execution continues on line 665
657 k = isl_basic_set_alloc_inequality(res);
658 if (k < 0)
659 goto error;
660 isl_seq_cpy(res->ineq[k], mat->row[i], mat->n_col);
661 isl_seq_scale(res->ineq[k] + mat->n_col,
662 bset->ineq[i] + mat->n_col,
663 morph->inv->row[0][0], bset->n_div);
664 }
665 isl_mat_free(mat);
666
667 mat = isl_mat_sub_alloc6(bset->ctx, bset->div, 0, bset->n_div,
668 1, morph->inv->n_row);
669 mat = isl_mat_product(mat, isl_mat_copy(morph->inv));
670 if (!mat)
37
Assuming 'mat' is non-null
38
Taking false branch
671 goto error;
672 for (i = 0; i < bset->n_div; ++i) {
39
Loop condition is false. Execution continues on line 680
673 isl_int_mul(res->div[i][0],isl_sioimath_mul((res->div[i][0]), *(morph->inv->row
[0][0]), *(bset->div[i][0]))
674 morph->inv->row[0][0], bset->div[i][0])isl_sioimath_mul((res->div[i][0]), *(morph->inv->row
[0][0]), *(bset->div[i][0]))
;
675 isl_seq_cpy(res->div[i] + 1, mat->row[i], mat->n_col);
676 isl_seq_scale(res->div[i] + 1 + mat->n_col,
677 bset->div[i] + 1 + mat->n_col,
678 morph->inv->row[0][0], bset->n_div);
679 }
680 isl_mat_free(mat);
681
682 res = add_strides(res, morph);
683
684 if (isl_basic_set_is_rational(bset))
40
Assuming the condition is false
41
Taking false branch
685 res = isl_basic_set_set_rational(res);
686
687 res = isl_basic_set_simplify(res);
688 res = isl_basic_set_finalize(res);
689
690 res = isl_basic_set_intersect(res, isl_basic_set_copy(morph->ran));
691
692 isl_morph_free(morph);
42
Calling 'isl_morph_free'
47
Returning; memory was released via 1st parameter
693 isl_basic_set_free(bset);
694 return res;
695error:
696 isl_mat_free(mat);
697 isl_morph_free(morph);
698 isl_basic_set_free(bset);
699 isl_basic_set_free(res);
700 return NULL((void*)0);
701}
702
703/* Apply the morphism to the set.
704 */
705__isl_give isl_setisl_map *isl_morph_set(__isl_take isl_morph *morph,
706 __isl_take isl_setisl_map *set)
707{
708 int i;
709
710 if (!morph || !set)
711 goto error;
712
713 isl_assert(set->ctx, isl_space_is_equal(set->dim, morph->dom->dim), goto error)do { if (isl_space_is_equal(set->dim, morph->dom->dim
)) break; do { isl_handle_error(set->ctx, isl_error_unknown
, "Assertion \"" "isl_space_is_equal(set->dim, morph->dom->dim)"
"\" failed", "/build/llvm-toolchain-snapshot-6.0~svn321639/tools/polly/lib/External/isl/isl_morph.c"
, 713); goto error; } while (0); } while (0)
;
714
715 set = isl_set_cow(set);
716 if (!set)
717 goto error;
718
719 isl_space_free(set->dim);
720 set->dim = isl_space_copy(morph->ran->dim);
721 if (!set->dim)
722 goto error;
723
724 for (i = 0; i < set->n; ++i) {
725 set->p[i] = isl_morph_basic_set(isl_morph_copy(morph), set->p[i]);
726 if (!set->p[i])
727 goto error;
728 }
729
730 isl_morph_free(morph);
731
732 ISL_F_CLR(set, ISL_SET_NORMALIZED)(((set)->flags) &= ~((1 << 1)));
733
734 return set;
735error:
736 isl_set_free(set);
737 isl_morph_free(morph);
738 return NULL((void*)0);
739}
740
741/* Construct a morphism that first does morph2 and then morph1.
742 */
743__isl_give isl_morph *isl_morph_compose(__isl_take isl_morph *morph1,
744 __isl_take isl_morph *morph2)
745{
746 isl_mat *map, *inv;
747 isl_basic_setisl_basic_map *dom, *ran;
748
749 if (!morph1 || !morph2)
22
Taking false branch
750 goto error;
751
752 map = isl_mat_product(isl_mat_copy(morph1->map), isl_mat_copy(morph2->map));
753 inv = isl_mat_product(isl_mat_copy(morph2->inv), isl_mat_copy(morph1->inv));
754 dom = isl_morph_basic_set(isl_morph_inverse(isl_morph_copy(morph2)),
755 isl_basic_set_copy(morph1->dom));
756 dom = isl_basic_set_intersect(dom, isl_basic_set_copy(morph2->dom));
757 ran = isl_morph_basic_set(isl_morph_copy(morph1),
23
Calling 'isl_morph_basic_set'
48
Returning; memory was released via 1st parameter
758 isl_basic_set_copy(morph2->ran));
759 ran = isl_basic_set_intersect(ran, isl_basic_set_copy(morph1->ran));
49
Use of memory after it is freed
760
761 isl_morph_free(morph1);
762 isl_morph_free(morph2);
763
764 return isl_morph_alloc(dom, ran, map, inv);
765error:
766 isl_morph_free(morph1);
767 isl_morph_free(morph2);
768 return NULL((void*)0);
769}
770
771__isl_give isl_morph *isl_morph_inverse(__isl_take isl_morph *morph)
772{
773 isl_basic_setisl_basic_map *bset;
774 isl_mat *mat;
775
776 morph = isl_morph_cow(morph);
777 if (!morph)
778 return NULL((void*)0);
779
780 bset = morph->dom;
781 morph->dom = morph->ran;
782 morph->ran = bset;
783
784 mat = morph->map;
785 morph->map = morph->inv;
786 morph->inv = mat;
787
788 return morph;
789}
790
791/* We detect all the equalities first to avoid implicit equalities
792 * being discovered during the computations. In particular,
793 * the compression on the variables could expose additional stride
794 * constraints on the parameters. This would result in existentially
795 * quantified variables after applying the resulting morph, which
796 * in turn could break invariants of the calling functions.
797 */
798__isl_give isl_morph *isl_basic_set_full_compression(
799 __isl_keep isl_basic_setisl_basic_map *bset)
800{
801 isl_morph *morph, *morph2;
802
803 bset = isl_basic_set_copy(bset);
804 bset = isl_basic_set_detect_equalities(bset);
805
806 morph = isl_basic_set_variable_compression(bset, isl_dim_param);
807 bset = isl_morph_basic_set(isl_morph_copy(morph), bset);
808
809 morph2 = isl_basic_set_parameter_compression(bset);
1
Calling 'isl_basic_set_parameter_compression'
20
Returning from 'isl_basic_set_parameter_compression'
810 bset = isl_morph_basic_set(isl_morph_copy(morph2), bset);
811
812 morph = isl_morph_compose(morph2, morph);
21
Calling 'isl_morph_compose'
813
814 morph2 = isl_basic_set_variable_compression(bset, isl_dim_set);
815 isl_basic_set_free(bset);
816
817 morph = isl_morph_compose(morph2, morph);
818
819 return morph;
820}
821
822__isl_give isl_vec *isl_morph_vec(__isl_take isl_morph *morph,
823 __isl_take isl_vec *vec)
824{
825 if (!morph)
826 goto error;
827
828 vec = isl_mat_vec_product(isl_mat_copy(morph->map), vec);
829
830 isl_morph_free(morph);
831 return vec;
832error:
833 isl_morph_free(morph);
834 isl_vec_free(vec);
835 return NULL((void*)0);
836}