2 * Copyright 2010-2011 INRIA Saclay
3 * Copyright 2013-2014 Ecole Normale Superieure
4 * Copyright 2014 INRIA Rocquencourt
5 * Copyright 2016-2017 Sven Verdoolaege
7 * Use of this software is governed by the MIT license
9 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
10 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
12 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
13 * B.P. 105 - 78153 Le Chesnay, France
17 #include <isl_map_private.h>
18 #include <isl_union_map_private.h>
24 #include <isl_space_private.h>
25 #include <isl/union_set.h>
26 #include <isl_maybe_map.h>
28 #include <bset_from_bmap.c>
29 #include <set_to_map.c>
30 #include <set_from_map.c>
31 #include <uset_to_umap.c>
33 /* Return the number of parameters of "umap", where "type"
34 * is required to be set to isl_dim_param.
36 unsigned isl_union_map_dim(__isl_keep isl_union_map
*umap
,
37 enum isl_dim_type type
)
42 if (type
!= isl_dim_param
)
43 isl_die(isl_union_map_get_ctx(umap
), isl_error_invalid
,
44 "can only reference parameters", return 0);
46 return isl_space_dim(umap
->dim
, type
);
49 /* Return the number of parameters of "uset", where "type"
50 * is required to be set to isl_dim_param.
52 unsigned isl_union_set_dim(__isl_keep isl_union_set
*uset
,
53 enum isl_dim_type type
)
55 return isl_union_map_dim(uset
, type
);
58 /* Return the id of the specified dimension.
60 __isl_give isl_id
*isl_union_map_get_dim_id(__isl_keep isl_union_map
*umap
,
61 enum isl_dim_type type
, unsigned pos
)
66 if (type
!= isl_dim_param
)
67 isl_die(isl_union_map_get_ctx(umap
), isl_error_invalid
,
68 "can only reference parameters", return NULL
);
70 return isl_space_get_dim_id(umap
->dim
, type
, pos
);
73 /* Is this union set a parameter domain?
75 isl_bool
isl_union_set_is_params(__isl_keep isl_union_set
*uset
)
81 return isl_bool_error
;
82 if (uset
->table
.n
!= 1)
83 return isl_bool_false
;
85 set
= isl_set_from_union_set(isl_union_set_copy(uset
));
86 params
= isl_set_is_params(set
);
91 static __isl_give isl_union_map
*isl_union_map_alloc(
92 __isl_take isl_space
*space
, int size
)
96 space
= isl_space_params(space
);
100 umap
= isl_calloc_type(space
->ctx
, isl_union_map
);
102 isl_space_free(space
);
108 if (isl_hash_table_init(space
->ctx
, &umap
->table
, size
) < 0)
109 return isl_union_map_free(umap
);
114 __isl_give isl_union_map
*isl_union_map_empty(__isl_take isl_space
*space
)
116 return isl_union_map_alloc(space
, 16);
119 __isl_give isl_union_set
*isl_union_set_empty(__isl_take isl_space
*space
)
121 return isl_union_map_empty(space
);
124 isl_ctx
*isl_union_map_get_ctx(__isl_keep isl_union_map
*umap
)
126 return umap
? umap
->dim
->ctx
: NULL
;
129 isl_ctx
*isl_union_set_get_ctx(__isl_keep isl_union_set
*uset
)
131 return uset
? uset
->dim
->ctx
: NULL
;
134 /* Return the space of "umap".
136 __isl_keep isl_space
*isl_union_map_peek_space(__isl_keep isl_union_map
*umap
)
138 return umap
? umap
->dim
: NULL
;
141 __isl_give isl_space
*isl_union_map_get_space(__isl_keep isl_union_map
*umap
)
143 return isl_space_copy(isl_union_map_peek_space(umap
));
146 /* Return the position of the parameter with the given name
148 * Return -1 if no such dimension can be found.
150 int isl_union_map_find_dim_by_name(__isl_keep isl_union_map
*umap
,
151 enum isl_dim_type type
, const char *name
)
155 return isl_space_find_dim_by_name(umap
->dim
, type
, name
);
158 __isl_give isl_space
*isl_union_set_get_space(__isl_keep isl_union_set
*uset
)
160 return isl_union_map_get_space(uset
);
163 static isl_stat
free_umap_entry(void **entry
, void *user
)
165 isl_map
*map
= *entry
;
170 static isl_stat
add_map(__isl_take isl_map
*map
, void *user
)
172 isl_union_map
**umap
= (isl_union_map
**)user
;
174 *umap
= isl_union_map_add_map(*umap
, map
);
179 __isl_give isl_union_map
*isl_union_map_dup(__isl_keep isl_union_map
*umap
)
186 dup
= isl_union_map_empty(isl_space_copy(umap
->dim
));
187 if (isl_union_map_foreach_map(umap
, &add_map
, &dup
) < 0)
191 isl_union_map_free(dup
);
195 __isl_give isl_union_map
*isl_union_map_cow(__isl_take isl_union_map
*umap
)
203 return isl_union_map_dup(umap
);
206 struct isl_union_align
{
211 static isl_stat
align_entry(void **entry
, void *user
)
213 isl_map
*map
= *entry
;
215 struct isl_union_align
*data
= user
;
217 exp
= isl_reordering_extend_space(isl_reordering_copy(data
->exp
),
218 isl_map_get_space(map
));
220 data
->res
= isl_union_map_add_map(data
->res
,
221 isl_map_realign(isl_map_copy(map
), exp
));
226 /* Align the parameters of umap along those of model.
227 * The result has the parameters of model first, in the same order
228 * as they appear in model, followed by any remaining parameters of
229 * umap that do not appear in model.
231 __isl_give isl_union_map
*isl_union_map_align_params(
232 __isl_take isl_union_map
*umap
, __isl_take isl_space
*model
)
234 struct isl_union_align data
= { NULL
, NULL
};
235 isl_bool equal_params
;
240 equal_params
= isl_space_has_equal_params(umap
->dim
, model
);
241 if (equal_params
< 0)
244 isl_space_free(model
);
248 model
= isl_space_params(model
);
249 data
.exp
= isl_parameter_alignment_reordering(umap
->dim
, model
);
253 data
.res
= isl_union_map_alloc(isl_space_copy(data
.exp
->dim
),
255 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
,
256 &align_entry
, &data
) < 0)
259 isl_reordering_free(data
.exp
);
260 isl_union_map_free(umap
);
261 isl_space_free(model
);
264 isl_reordering_free(data
.exp
);
265 isl_union_map_free(umap
);
266 isl_union_map_free(data
.res
);
267 isl_space_free(model
);
271 __isl_give isl_union_set
*isl_union_set_align_params(
272 __isl_take isl_union_set
*uset
, __isl_take isl_space
*model
)
274 return isl_union_map_align_params(uset
, model
);
277 __isl_give isl_union_map
*isl_union_map_union(__isl_take isl_union_map
*umap1
,
278 __isl_take isl_union_map
*umap2
)
280 umap1
= isl_union_map_align_params(umap1
, isl_union_map_get_space(umap2
));
281 umap2
= isl_union_map_align_params(umap2
, isl_union_map_get_space(umap1
));
283 umap1
= isl_union_map_cow(umap1
);
285 if (!umap1
|| !umap2
)
288 if (isl_union_map_foreach_map(umap2
, &add_map
, &umap1
) < 0)
291 isl_union_map_free(umap2
);
295 isl_union_map_free(umap1
);
296 isl_union_map_free(umap2
);
300 __isl_give isl_union_set
*isl_union_set_union(__isl_take isl_union_set
*uset1
,
301 __isl_take isl_union_set
*uset2
)
303 return isl_union_map_union(uset1
, uset2
);
306 __isl_give isl_union_map
*isl_union_map_copy(__isl_keep isl_union_map
*umap
)
315 __isl_give isl_union_set
*isl_union_set_copy(__isl_keep isl_union_set
*uset
)
317 return isl_union_map_copy(uset
);
320 __isl_null isl_union_map
*isl_union_map_free(__isl_take isl_union_map
*umap
)
328 isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
,
329 &free_umap_entry
, NULL
);
330 isl_hash_table_clear(&umap
->table
);
331 isl_space_free(umap
->dim
);
336 __isl_null isl_union_set
*isl_union_set_free(__isl_take isl_union_set
*uset
)
338 return isl_union_map_free(uset
);
341 /* Do "umap" and "space" have the same parameters?
343 isl_bool
isl_union_map_space_has_equal_params(__isl_keep isl_union_map
*umap
,
344 __isl_keep isl_space
*space
)
346 isl_space
*umap_space
;
348 umap_space
= isl_union_map_peek_space(umap
);
349 return isl_space_has_equal_params(umap_space
, space
);
352 /* Do "uset" and "space" have the same parameters?
354 isl_bool
isl_union_set_space_has_equal_params(__isl_keep isl_union_set
*uset
,
355 __isl_keep isl_space
*space
)
357 return isl_union_map_space_has_equal_params(uset_to_umap(uset
), space
);
360 static int has_space(const void *entry
, const void *val
)
362 isl_map
*map
= (isl_map
*)entry
;
363 isl_space
*space
= (isl_space
*) val
;
365 return isl_space_is_equal(map
->dim
, space
);
368 __isl_give isl_union_map
*isl_union_map_add_map(__isl_take isl_union_map
*umap
,
369 __isl_take isl_map
*map
)
372 struct isl_hash_table_entry
*entry
;
378 if (isl_map_plain_is_empty(map
)) {
383 aligned
= isl_map_space_has_equal_params(map
, umap
->dim
);
387 umap
= isl_union_map_align_params(umap
, isl_map_get_space(map
));
388 map
= isl_map_align_params(map
, isl_union_map_get_space(umap
));
391 umap
= isl_union_map_cow(umap
);
396 hash
= isl_space_get_hash(map
->dim
);
397 entry
= isl_hash_table_find(umap
->dim
->ctx
, &umap
->table
, hash
,
398 &has_space
, map
->dim
, 1);
405 entry
->data
= isl_map_union(entry
->data
, isl_map_copy(map
));
414 isl_union_map_free(umap
);
418 __isl_give isl_union_set
*isl_union_set_add_set(__isl_take isl_union_set
*uset
,
419 __isl_take isl_set
*set
)
421 return isl_union_map_add_map(uset
, set_to_map(set
));
424 __isl_give isl_union_map
*isl_union_map_from_map(__isl_take isl_map
*map
)
432 dim
= isl_map_get_space(map
);
433 dim
= isl_space_params(dim
);
434 umap
= isl_union_map_empty(dim
);
435 umap
= isl_union_map_add_map(umap
, map
);
440 __isl_give isl_union_set
*isl_union_set_from_set(__isl_take isl_set
*set
)
442 return isl_union_map_from_map(set_to_map(set
));
445 __isl_give isl_union_map
*isl_union_map_from_basic_map(
446 __isl_take isl_basic_map
*bmap
)
448 return isl_union_map_from_map(isl_map_from_basic_map(bmap
));
451 __isl_give isl_union_set
*isl_union_set_from_basic_set(
452 __isl_take isl_basic_set
*bset
)
454 return isl_union_map_from_basic_map(bset
);
457 struct isl_union_map_foreach_data
459 isl_stat (*fn
)(__isl_take isl_map
*map
, void *user
);
463 static isl_stat
call_on_copy(void **entry
, void *user
)
465 isl_map
*map
= *entry
;
466 struct isl_union_map_foreach_data
*data
;
467 data
= (struct isl_union_map_foreach_data
*)user
;
469 return data
->fn(isl_map_copy(map
), data
->user
);
472 int isl_union_map_n_map(__isl_keep isl_union_map
*umap
)
474 return umap
? umap
->table
.n
: 0;
477 int isl_union_set_n_set(__isl_keep isl_union_set
*uset
)
479 return uset
? uset
->table
.n
: 0;
482 isl_stat
isl_union_map_foreach_map(__isl_keep isl_union_map
*umap
,
483 isl_stat (*fn
)(__isl_take isl_map
*map
, void *user
), void *user
)
485 struct isl_union_map_foreach_data data
= { fn
, user
};
488 return isl_stat_error
;
490 return isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
,
491 &call_on_copy
, &data
);
494 /* Internal data structure for isl_union_map_every_map.
496 * "test" is the user-specified callback function.
497 * "user" is the user-specified callback function argument.
499 * "failed" is initialized to 0 and set to 1 if "test" fails
502 struct isl_union_map_every_data
{
503 isl_bool (*test
)(__isl_keep isl_map
*map
, void *user
);
508 /* Call data->test on "map".
509 * If this fails, then set data->failed and abort.
511 static isl_stat
call_every(void **entry
, void *user
)
513 isl_map
*map
= *entry
;
514 struct isl_union_map_every_data
*data
= user
;
517 r
= data
->test(map
, data
->user
);
519 return isl_stat_error
;
523 return isl_stat_error
;
526 /* Does "test" succeed on every map in "umap"?
528 isl_bool
isl_union_map_every_map(__isl_keep isl_union_map
*umap
,
529 isl_bool (*test
)(__isl_keep isl_map
*map
, void *user
), void *user
)
531 struct isl_union_map_every_data data
= { test
, user
, 0 };
535 return isl_bool_error
;
537 r
= isl_hash_table_foreach(isl_union_map_get_ctx(umap
), &umap
->table
,
540 return isl_bool_true
;
542 return isl_bool_false
;
543 return isl_bool_error
;
546 static isl_stat
copy_map(void **entry
, void *user
)
548 isl_map
*map
= *entry
;
549 isl_map
**map_p
= user
;
551 *map_p
= isl_map_copy(map
);
553 return isl_stat_error
;
556 __isl_give isl_map
*isl_map_from_union_map(__isl_take isl_union_map
*umap
)
563 ctx
= isl_union_map_get_ctx(umap
);
564 if (umap
->table
.n
!= 1)
565 isl_die(ctx
, isl_error_invalid
,
566 "union map needs to contain elements in exactly "
567 "one space", goto error
);
569 isl_hash_table_foreach(ctx
, &umap
->table
, ©_map
, &map
);
571 isl_union_map_free(umap
);
575 isl_union_map_free(umap
);
579 __isl_give isl_set
*isl_set_from_union_set(__isl_take isl_union_set
*uset
)
581 return isl_map_from_union_map(uset
);
584 /* Extract the map in "umap" that lives in the given space (ignoring
587 __isl_give isl_map
*isl_union_map_extract_map(__isl_keep isl_union_map
*umap
,
588 __isl_take isl_space
*space
)
591 struct isl_hash_table_entry
*entry
;
593 space
= isl_space_drop_dims(space
, isl_dim_param
,
594 0, isl_space_dim(space
, isl_dim_param
));
595 space
= isl_space_align_params(space
, isl_union_map_get_space(umap
));
599 hash
= isl_space_get_hash(space
);
600 entry
= isl_hash_table_find(umap
->dim
->ctx
, &umap
->table
, hash
,
601 &has_space
, space
, 0);
603 return isl_map_empty(space
);
604 isl_space_free(space
);
605 return isl_map_copy(entry
->data
);
607 isl_space_free(space
);
611 __isl_give isl_set
*isl_union_set_extract_set(__isl_keep isl_union_set
*uset
,
612 __isl_take isl_space
*dim
)
614 return set_from_map(isl_union_map_extract_map(uset
, dim
));
617 /* Check if umap contains a map in the given space.
619 isl_bool
isl_union_map_contains(__isl_keep isl_union_map
*umap
,
620 __isl_keep isl_space
*space
)
623 struct isl_hash_table_entry
*entry
;
626 return isl_bool_error
;
628 hash
= isl_space_get_hash(space
);
629 entry
= isl_hash_table_find(umap
->dim
->ctx
, &umap
->table
, hash
,
630 &has_space
, space
, 0);
634 isl_bool
isl_union_set_contains(__isl_keep isl_union_set
*uset
,
635 __isl_keep isl_space
*space
)
637 return isl_union_map_contains(uset
, space
);
640 isl_stat
isl_union_set_foreach_set(__isl_keep isl_union_set
*uset
,
641 isl_stat (*fn
)(__isl_take isl_set
*set
, void *user
), void *user
)
643 return isl_union_map_foreach_map(uset
,
644 (isl_stat(*)(__isl_take isl_map
*, void*))fn
, user
);
647 struct isl_union_set_foreach_point_data
{
648 isl_stat (*fn
)(__isl_take isl_point
*pnt
, void *user
);
652 static isl_stat
foreach_point(__isl_take isl_set
*set
, void *user
)
654 struct isl_union_set_foreach_point_data
*data
= user
;
657 r
= isl_set_foreach_point(set
, data
->fn
, data
->user
);
663 isl_stat
isl_union_set_foreach_point(__isl_keep isl_union_set
*uset
,
664 isl_stat (*fn
)(__isl_take isl_point
*pnt
, void *user
), void *user
)
666 struct isl_union_set_foreach_point_data data
= { fn
, user
};
667 return isl_union_set_foreach_set(uset
, &foreach_point
, &data
);
670 /* Data structure that specifies how gen_bin_op should
671 * construct results from the inputs.
673 * If "subtract" is set, then a map in the first input is copied to the result
674 * if there is no corresponding map in the second input.
675 * Otherwise, a map in the first input with no corresponding map
676 * in the second input is ignored.
677 * If "filter" is not NULL, then it specifies which maps in the first
678 * input may have a matching map in the second input.
679 * In particular, it makes sure that "match_space" can be called
680 * on the space of the map.
681 * "match_space" specifies how to transform the space of a map
682 * in the first input to the space of the corresponding map
683 * in the second input.
684 * "fn_map" specifies how the matching maps, one from each input,
685 * should be combined to form a map in the result.
687 struct isl_bin_op_control
{
689 isl_bool (*filter
)(__isl_keep isl_map
*map
);
690 __isl_give isl_space
*(*match_space
)(__isl_take isl_space
*space
);
691 __isl_give isl_map
*(*fn_map
)(__isl_take isl_map
*map1
,
692 __isl_take isl_map
*map2
);
695 /* Internal data structure for gen_bin_op.
696 * "control" specifies how the maps in the result should be constructed.
697 * "umap2" is a pointer to the second argument.
698 * "res" collects the results.
700 struct isl_union_map_gen_bin_data
{
701 struct isl_bin_op_control
*control
;
702 isl_union_map
*umap2
;
706 /* Add a copy of "map" to "res" and return the result.
708 static __isl_give isl_union_map
*bin_add_map(__isl_take isl_union_map
*res
,
709 __isl_keep isl_map
*map
)
711 return isl_union_map_add_map(res
, isl_map_copy(map
));
714 /* Combine "map1" and "map2", add the result to "res" and return the result.
715 * Check whether the result is empty before adding it to "res".
717 static __isl_give isl_union_map
*bin_add_pair(__isl_take isl_union_map
*res
,
718 __isl_keep isl_map
*map1
, __isl_keep isl_map
*map2
,
719 struct isl_union_map_gen_bin_data
*data
)
724 map
= data
->control
->fn_map(isl_map_copy(map1
), isl_map_copy(map2
));
725 empty
= isl_map_is_empty(map
);
726 if (empty
< 0 || empty
) {
729 return isl_union_map_free(res
);
732 return isl_union_map_add_map(res
, map
);
735 /* Dummy match_space function that simply returns the input space.
737 static __isl_give isl_space
*identity(__isl_take isl_space
*space
)
742 /* Look for the map in data->umap2 that corresponds to "map", if any.
743 * Return (isl_bool_true, matching map) if there is one,
744 * (isl_bool_false, NULL) if there is no matching map and
745 * (isl_bool_error, NULL) on error.
747 * If not NULL, then data->control->filter specifies whether "map"
748 * can have any matching map. If so,
749 * data->control->match_space specifies which map in data->umap2
750 * corresponds to "map".
752 static __isl_keep isl_maybe_isl_map
bin_try_get_match(
753 struct isl_union_map_gen_bin_data
*data
, __isl_keep isl_map
*map
)
756 struct isl_hash_table_entry
*entry2
;
758 isl_maybe_isl_map res
= { isl_bool_error
, NULL
};
760 if (data
->control
->filter
) {
761 res
.valid
= data
->control
->filter(map
);
762 if (res
.valid
< 0 || !res
.valid
)
764 res
.valid
= isl_bool_error
;
767 space
= isl_map_get_space(map
);
768 if (data
->control
->match_space
!= &identity
)
769 space
= data
->control
->match_space(space
);
772 hash
= isl_space_get_hash(space
);
773 entry2
= isl_hash_table_find(isl_union_map_get_ctx(data
->umap2
),
774 &data
->umap2
->table
, hash
,
775 &has_space
, space
, 0);
776 isl_space_free(space
);
777 res
.valid
= entry2
!= NULL
;
779 res
.value
= entry2
->data
;
784 /* isl_hash_table_foreach callback for gen_bin_op.
785 * Look for the map in data->umap2 that corresponds
786 * to the map that "entry" points to, apply the binary operation and
787 * add the result to data->res.
789 * If no corresponding map can be found, then the effect depends
790 * on data->control->subtract. If it is set, then the current map
791 * is added directly to the result. Otherwise, it is ignored.
793 static isl_stat
gen_bin_entry(void **entry
, void *user
)
795 struct isl_union_map_gen_bin_data
*data
= user
;
796 isl_map
*map
= *entry
;
799 m
= bin_try_get_match(data
, map
);
801 return isl_stat_error
;
802 if (!m
.valid
&& !data
->control
->subtract
)
806 data
->res
= bin_add_map(data
->res
, map
);
808 data
->res
= bin_add_pair(data
->res
, map
, m
.value
, data
);
810 return isl_stat_error
;
815 /* Apply a binary operation to "umap1" and "umap2" based on "control".
816 * Run over all maps in "umap1" and look for the corresponding map in "umap2"
819 static __isl_give isl_union_map
*gen_bin_op(__isl_take isl_union_map
*umap1
,
820 __isl_take isl_union_map
*umap2
, struct isl_bin_op_control
*control
)
822 struct isl_union_map_gen_bin_data data
= { control
, NULL
, NULL
};
824 umap1
= isl_union_map_align_params(umap1
, isl_union_map_get_space(umap2
));
825 umap2
= isl_union_map_align_params(umap2
, isl_union_map_get_space(umap1
));
827 if (!umap1
|| !umap2
)
831 data
.res
= isl_union_map_alloc(isl_space_copy(umap1
->dim
),
833 if (isl_hash_table_foreach(umap1
->dim
->ctx
, &umap1
->table
,
834 &gen_bin_entry
, &data
) < 0)
837 isl_union_map_free(umap1
);
838 isl_union_map_free(umap2
);
841 isl_union_map_free(umap1
);
842 isl_union_map_free(umap2
);
843 isl_union_map_free(data
.res
);
847 __isl_give isl_union_map
*isl_union_map_subtract(
848 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
850 struct isl_bin_op_control control
= {
852 .match_space
= &identity
,
853 .fn_map
= &isl_map_subtract
,
856 return gen_bin_op(umap1
, umap2
, &control
);
859 __isl_give isl_union_set
*isl_union_set_subtract(
860 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
862 return isl_union_map_subtract(uset1
, uset2
);
865 struct isl_union_map_gen_bin_set_data
{
870 static isl_stat
intersect_params_entry(void **entry
, void *user
)
872 struct isl_union_map_gen_bin_set_data
*data
= user
;
873 isl_map
*map
= *entry
;
876 map
= isl_map_copy(map
);
877 map
= isl_map_intersect_params(map
, isl_set_copy(data
->set
));
879 empty
= isl_map_is_empty(map
);
882 return isl_stat_error
;
885 data
->res
= isl_union_map_add_map(data
->res
, map
);
890 static __isl_give isl_union_map
*gen_bin_set_op(__isl_take isl_union_map
*umap
,
891 __isl_take isl_set
*set
, isl_stat (*fn
)(void **, void *))
893 struct isl_union_map_gen_bin_set_data data
= { NULL
, NULL
};
895 umap
= isl_union_map_align_params(umap
, isl_set_get_space(set
));
896 set
= isl_set_align_params(set
, isl_union_map_get_space(umap
));
902 data
.res
= isl_union_map_alloc(isl_space_copy(umap
->dim
),
904 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
,
908 isl_union_map_free(umap
);
912 isl_union_map_free(umap
);
914 isl_union_map_free(data
.res
);
918 /* Intersect "umap" with the parameter domain "set".
920 * If "set" does not have any constraints, then we can return immediately.
922 __isl_give isl_union_map
*isl_union_map_intersect_params(
923 __isl_take isl_union_map
*umap
, __isl_take isl_set
*set
)
927 is_universe
= isl_set_plain_is_universe(set
);
935 return gen_bin_set_op(umap
, set
, &intersect_params_entry
);
937 isl_union_map_free(umap
);
942 __isl_give isl_union_set
*isl_union_set_intersect_params(
943 __isl_take isl_union_set
*uset
, __isl_take isl_set
*set
)
945 return isl_union_map_intersect_params(uset
, set
);
948 static __isl_give isl_union_map
*union_map_intersect_params(
949 __isl_take isl_union_map
*umap
, __isl_take isl_union_set
*uset
)
951 return isl_union_map_intersect_params(umap
,
952 isl_set_from_union_set(uset
));
955 static __isl_give isl_union_map
*union_map_gist_params(
956 __isl_take isl_union_map
*umap
, __isl_take isl_union_set
*uset
)
958 return isl_union_map_gist_params(umap
, isl_set_from_union_set(uset
));
961 struct isl_union_map_match_bin_data
{
962 isl_union_map
*umap2
;
964 __isl_give isl_map
*(*fn
)(__isl_take isl_map
*, __isl_take isl_map
*);
967 static isl_stat
match_bin_entry(void **entry
, void *user
)
969 struct isl_union_map_match_bin_data
*data
= user
;
971 struct isl_hash_table_entry
*entry2
;
972 isl_map
*map
= *entry
;
975 hash
= isl_space_get_hash(map
->dim
);
976 entry2
= isl_hash_table_find(data
->umap2
->dim
->ctx
, &data
->umap2
->table
,
977 hash
, &has_space
, map
->dim
, 0);
981 map
= isl_map_copy(map
);
982 map
= data
->fn(map
, isl_map_copy(entry2
->data
));
984 empty
= isl_map_is_empty(map
);
987 return isl_stat_error
;
994 data
->res
= isl_union_map_add_map(data
->res
, map
);
999 static __isl_give isl_union_map
*match_bin_op(__isl_take isl_union_map
*umap1
,
1000 __isl_take isl_union_map
*umap2
,
1001 __isl_give isl_map
*(*fn
)(__isl_take isl_map
*, __isl_take isl_map
*))
1003 struct isl_union_map_match_bin_data data
= { NULL
, NULL
, fn
};
1005 umap1
= isl_union_map_align_params(umap1
, isl_union_map_get_space(umap2
));
1006 umap2
= isl_union_map_align_params(umap2
, isl_union_map_get_space(umap1
));
1008 if (!umap1
|| !umap2
)
1012 data
.res
= isl_union_map_alloc(isl_space_copy(umap1
->dim
),
1014 if (isl_hash_table_foreach(umap1
->dim
->ctx
, &umap1
->table
,
1015 &match_bin_entry
, &data
) < 0)
1018 isl_union_map_free(umap1
);
1019 isl_union_map_free(umap2
);
1022 isl_union_map_free(umap1
);
1023 isl_union_map_free(umap2
);
1024 isl_union_map_free(data
.res
);
1028 __isl_give isl_union_map
*isl_union_map_intersect(
1029 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
1031 return match_bin_op(umap1
, umap2
, &isl_map_intersect
);
1034 /* Compute the intersection of the two union_sets.
1035 * As a special case, if exactly one of the two union_sets
1036 * is a parameter domain, then intersect the parameter domain
1037 * of the other one with this set.
1039 __isl_give isl_union_set
*isl_union_set_intersect(
1040 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
1044 p1
= isl_union_set_is_params(uset1
);
1045 p2
= isl_union_set_is_params(uset2
);
1046 if (p1
< 0 || p2
< 0)
1049 return union_map_intersect_params(uset1
, uset2
);
1051 return union_map_intersect_params(uset2
, uset1
);
1052 return isl_union_map_intersect(uset1
, uset2
);
1054 isl_union_set_free(uset1
);
1055 isl_union_set_free(uset2
);
1059 static isl_stat
gist_params_entry(void **entry
, void *user
)
1061 struct isl_union_map_gen_bin_set_data
*data
= user
;
1062 isl_map
*map
= *entry
;
1065 map
= isl_map_copy(map
);
1066 map
= isl_map_gist_params(map
, isl_set_copy(data
->set
));
1068 empty
= isl_map_is_empty(map
);
1071 return isl_stat_error
;
1074 data
->res
= isl_union_map_add_map(data
->res
, map
);
1079 __isl_give isl_union_map
*isl_union_map_gist_params(
1080 __isl_take isl_union_map
*umap
, __isl_take isl_set
*set
)
1082 return gen_bin_set_op(umap
, set
, &gist_params_entry
);
1085 __isl_give isl_union_set
*isl_union_set_gist_params(
1086 __isl_take isl_union_set
*uset
, __isl_take isl_set
*set
)
1088 return isl_union_map_gist_params(uset
, set
);
1091 __isl_give isl_union_map
*isl_union_map_gist(__isl_take isl_union_map
*umap
,
1092 __isl_take isl_union_map
*context
)
1094 return match_bin_op(umap
, context
, &isl_map_gist
);
1097 __isl_give isl_union_set
*isl_union_set_gist(__isl_take isl_union_set
*uset
,
1098 __isl_take isl_union_set
*context
)
1100 if (isl_union_set_is_params(context
))
1101 return union_map_gist_params(uset
, context
);
1102 return isl_union_map_gist(uset
, context
);
1105 /* For each map in "umap", remove the constraints in the corresponding map
1107 * Each map in "context" is assumed to consist of a single disjunct and
1108 * to have explicit representations for all local variables.
1110 __isl_give isl_union_map
*isl_union_map_plain_gist(
1111 __isl_take isl_union_map
*umap
, __isl_take isl_union_map
*context
)
1113 return match_bin_op(umap
, context
, &isl_map_plain_gist
);
1116 /* For each set in "uset", remove the constraints in the corresponding set
1118 * Each set in "context" is assumed to consist of a single disjunct and
1119 * to have explicit representations for all local variables.
1121 __isl_give isl_union_set
*isl_union_set_plain_gist(
1122 __isl_take isl_union_set
*uset
, __isl_take isl_union_set
*context
)
1124 return isl_union_map_plain_gist(uset
, context
);
1127 static __isl_give isl_map
*lex_le_set(__isl_take isl_map
*set1
,
1128 __isl_take isl_map
*set2
)
1130 return isl_set_lex_le_set(set_from_map(set1
), set_from_map(set2
));
1133 static __isl_give isl_map
*lex_lt_set(__isl_take isl_map
*set1
,
1134 __isl_take isl_map
*set2
)
1136 return isl_set_lex_lt_set(set_from_map(set1
), set_from_map(set2
));
1139 __isl_give isl_union_map
*isl_union_set_lex_lt_union_set(
1140 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
1142 return match_bin_op(uset1
, uset2
, &lex_lt_set
);
1145 __isl_give isl_union_map
*isl_union_set_lex_le_union_set(
1146 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
1148 return match_bin_op(uset1
, uset2
, &lex_le_set
);
1151 __isl_give isl_union_map
*isl_union_set_lex_gt_union_set(
1152 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
1154 return isl_union_map_reverse(isl_union_set_lex_lt_union_set(uset2
, uset1
));
1157 __isl_give isl_union_map
*isl_union_set_lex_ge_union_set(
1158 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
1160 return isl_union_map_reverse(isl_union_set_lex_le_union_set(uset2
, uset1
));
1163 __isl_give isl_union_map
*isl_union_map_lex_gt_union_map(
1164 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
1166 return isl_union_map_reverse(isl_union_map_lex_lt_union_map(umap2
, umap1
));
1169 __isl_give isl_union_map
*isl_union_map_lex_ge_union_map(
1170 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
1172 return isl_union_map_reverse(isl_union_map_lex_le_union_map(umap2
, umap1
));
1175 /* Intersect the domain of "umap" with "uset".
1177 static __isl_give isl_union_map
*union_map_intersect_domain(
1178 __isl_take isl_union_map
*umap
, __isl_take isl_union_set
*uset
)
1180 struct isl_bin_op_control control
= {
1181 .match_space
= &isl_space_domain
,
1182 .fn_map
= &isl_map_intersect_domain
,
1185 return gen_bin_op(umap
, uset
, &control
);
1188 /* Intersect the domain of "umap" with "uset".
1189 * If "uset" is a parameters domain, then intersect the parameter
1190 * domain of "umap" with this set.
1192 __isl_give isl_union_map
*isl_union_map_intersect_domain(
1193 __isl_take isl_union_map
*umap
, __isl_take isl_union_set
*uset
)
1195 if (isl_union_set_is_params(uset
))
1196 return union_map_intersect_params(umap
, uset
);
1198 return union_map_intersect_domain(umap
, uset
);
1201 /* Remove the elements of "uset" from the domain of "umap".
1203 __isl_give isl_union_map
*isl_union_map_subtract_domain(
1204 __isl_take isl_union_map
*umap
, __isl_take isl_union_set
*dom
)
1206 struct isl_bin_op_control control
= {
1208 .match_space
= &isl_space_domain
,
1209 .fn_map
= &isl_map_subtract_domain
,
1212 return gen_bin_op(umap
, dom
, &control
);
1215 /* Remove the elements of "uset" from the range of "umap".
1217 __isl_give isl_union_map
*isl_union_map_subtract_range(
1218 __isl_take isl_union_map
*umap
, __isl_take isl_union_set
*dom
)
1220 struct isl_bin_op_control control
= {
1222 .match_space
= &isl_space_range
,
1223 .fn_map
= &isl_map_subtract_range
,
1226 return gen_bin_op(umap
, dom
, &control
);
1229 /* Compute the gist of "umap" with respect to the domain "uset".
1231 static __isl_give isl_union_map
*union_map_gist_domain(
1232 __isl_take isl_union_map
*umap
, __isl_take isl_union_set
*uset
)
1234 struct isl_bin_op_control control
= {
1235 .match_space
= &isl_space_domain
,
1236 .fn_map
= &isl_map_gist_domain
,
1239 return gen_bin_op(umap
, uset
, &control
);
1242 /* Compute the gist of "umap" with respect to the domain "uset".
1243 * If "uset" is a parameters domain, then compute the gist
1244 * with respect to this parameter domain.
1246 __isl_give isl_union_map
*isl_union_map_gist_domain(
1247 __isl_take isl_union_map
*umap
, __isl_take isl_union_set
*uset
)
1249 if (isl_union_set_is_params(uset
))
1250 return union_map_gist_params(umap
, uset
);
1252 return union_map_gist_domain(umap
, uset
);
1255 /* Compute the gist of "umap" with respect to the range "uset".
1257 __isl_give isl_union_map
*isl_union_map_gist_range(
1258 __isl_take isl_union_map
*umap
, __isl_take isl_union_set
*uset
)
1260 struct isl_bin_op_control control
= {
1261 .match_space
= &isl_space_range
,
1262 .fn_map
= &isl_map_gist_range
,
1265 return gen_bin_op(umap
, uset
, &control
);
1268 __isl_give isl_union_map
*isl_union_map_intersect_range(
1269 __isl_take isl_union_map
*umap
, __isl_take isl_union_set
*uset
)
1271 struct isl_bin_op_control control
= {
1272 .match_space
= &isl_space_range
,
1273 .fn_map
= &isl_map_intersect_range
,
1276 return gen_bin_op(umap
, uset
, &control
);
1279 /* Intersect each map in "umap" in a space A -> [B -> C]
1280 * with the corresponding map in "factor" in the space A -> C and
1281 * collect the results.
1283 __isl_give isl_union_map
*isl_union_map_intersect_range_factor_range(
1284 __isl_take isl_union_map
*umap
, __isl_take isl_union_map
*factor
)
1286 struct isl_bin_op_control control
= {
1287 .filter
= &isl_map_range_is_wrapping
,
1288 .match_space
= &isl_space_range_factor_range
,
1289 .fn_map
= &isl_map_intersect_range_factor_range
,
1292 return gen_bin_op(umap
, factor
, &control
);
1295 struct isl_union_map_bin_data
{
1296 isl_union_map
*umap2
;
1299 isl_stat (*fn
)(void **entry
, void *user
);
1302 static isl_stat
apply_range_entry(void **entry
, void *user
)
1304 struct isl_union_map_bin_data
*data
= user
;
1305 isl_map
*map2
= *entry
;
1308 if (!isl_space_tuple_is_equal(data
->map
->dim
, isl_dim_out
,
1309 map2
->dim
, isl_dim_in
))
1312 map2
= isl_map_apply_range(isl_map_copy(data
->map
), isl_map_copy(map2
));
1314 empty
= isl_map_is_empty(map2
);
1317 return isl_stat_error
;
1324 data
->res
= isl_union_map_add_map(data
->res
, map2
);
1329 static isl_stat
bin_entry(void **entry
, void *user
)
1331 struct isl_union_map_bin_data
*data
= user
;
1332 isl_map
*map
= *entry
;
1335 if (isl_hash_table_foreach(data
->umap2
->dim
->ctx
, &data
->umap2
->table
,
1336 data
->fn
, data
) < 0)
1337 return isl_stat_error
;
1342 static __isl_give isl_union_map
*bin_op(__isl_take isl_union_map
*umap1
,
1343 __isl_take isl_union_map
*umap2
,
1344 isl_stat (*fn
)(void **entry
, void *user
))
1346 struct isl_union_map_bin_data data
= { NULL
, NULL
, NULL
, fn
};
1348 umap1
= isl_union_map_align_params(umap1
, isl_union_map_get_space(umap2
));
1349 umap2
= isl_union_map_align_params(umap2
, isl_union_map_get_space(umap1
));
1351 if (!umap1
|| !umap2
)
1355 data
.res
= isl_union_map_alloc(isl_space_copy(umap1
->dim
),
1357 if (isl_hash_table_foreach(umap1
->dim
->ctx
, &umap1
->table
,
1358 &bin_entry
, &data
) < 0)
1361 isl_union_map_free(umap1
);
1362 isl_union_map_free(umap2
);
1365 isl_union_map_free(umap1
);
1366 isl_union_map_free(umap2
);
1367 isl_union_map_free(data
.res
);
1371 __isl_give isl_union_map
*isl_union_map_apply_range(
1372 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
1374 return bin_op(umap1
, umap2
, &apply_range_entry
);
1377 __isl_give isl_union_map
*isl_union_map_apply_domain(
1378 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
1380 umap1
= isl_union_map_reverse(umap1
);
1381 umap1
= isl_union_map_apply_range(umap1
, umap2
);
1382 return isl_union_map_reverse(umap1
);
1385 __isl_give isl_union_set
*isl_union_set_apply(
1386 __isl_take isl_union_set
*uset
, __isl_take isl_union_map
*umap
)
1388 return isl_union_map_apply_range(uset
, umap
);
1391 static isl_stat
map_lex_lt_entry(void **entry
, void *user
)
1393 struct isl_union_map_bin_data
*data
= user
;
1394 isl_map
*map2
= *entry
;
1396 if (!isl_space_tuple_is_equal(data
->map
->dim
, isl_dim_out
,
1397 map2
->dim
, isl_dim_out
))
1400 map2
= isl_map_lex_lt_map(isl_map_copy(data
->map
), isl_map_copy(map2
));
1402 data
->res
= isl_union_map_add_map(data
->res
, map2
);
1407 __isl_give isl_union_map
*isl_union_map_lex_lt_union_map(
1408 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
1410 return bin_op(umap1
, umap2
, &map_lex_lt_entry
);
1413 static isl_stat
map_lex_le_entry(void **entry
, void *user
)
1415 struct isl_union_map_bin_data
*data
= user
;
1416 isl_map
*map2
= *entry
;
1418 if (!isl_space_tuple_is_equal(data
->map
->dim
, isl_dim_out
,
1419 map2
->dim
, isl_dim_out
))
1422 map2
= isl_map_lex_le_map(isl_map_copy(data
->map
), isl_map_copy(map2
));
1424 data
->res
= isl_union_map_add_map(data
->res
, map2
);
1429 __isl_give isl_union_map
*isl_union_map_lex_le_union_map(
1430 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
1432 return bin_op(umap1
, umap2
, &map_lex_le_entry
);
1435 static isl_stat
product_entry(void **entry
, void *user
)
1437 struct isl_union_map_bin_data
*data
= user
;
1438 isl_map
*map2
= *entry
;
1440 map2
= isl_map_product(isl_map_copy(data
->map
), isl_map_copy(map2
));
1442 data
->res
= isl_union_map_add_map(data
->res
, map2
);
1447 __isl_give isl_union_map
*isl_union_map_product(__isl_take isl_union_map
*umap1
,
1448 __isl_take isl_union_map
*umap2
)
1450 return bin_op(umap1
, umap2
, &product_entry
);
1453 static isl_stat
set_product_entry(void **entry
, void *user
)
1455 struct isl_union_map_bin_data
*data
= user
;
1456 isl_set
*set2
= *entry
;
1458 set2
= isl_set_product(isl_set_copy(data
->map
), isl_set_copy(set2
));
1460 data
->res
= isl_union_set_add_set(data
->res
, set2
);
1465 __isl_give isl_union_set
*isl_union_set_product(__isl_take isl_union_set
*uset1
,
1466 __isl_take isl_union_set
*uset2
)
1468 return bin_op(uset1
, uset2
, &set_product_entry
);
1471 static isl_stat
domain_product_entry(void **entry
, void *user
)
1473 struct isl_union_map_bin_data
*data
= user
;
1474 isl_map
*map2
= *entry
;
1476 if (!isl_space_tuple_is_equal(data
->map
->dim
, isl_dim_out
,
1477 map2
->dim
, isl_dim_out
))
1480 map2
= isl_map_domain_product(isl_map_copy(data
->map
),
1481 isl_map_copy(map2
));
1483 data
->res
= isl_union_map_add_map(data
->res
, map2
);
1488 /* Given two maps A -> B and C -> D, construct a map [A -> C] -> (B * D)
1490 __isl_give isl_union_map
*isl_union_map_domain_product(
1491 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
1493 return bin_op(umap1
, umap2
, &domain_product_entry
);
1496 static isl_stat
range_product_entry(void **entry
, void *user
)
1498 struct isl_union_map_bin_data
*data
= user
;
1499 isl_map
*map2
= *entry
;
1501 if (!isl_space_tuple_is_equal(data
->map
->dim
, isl_dim_in
,
1502 map2
->dim
, isl_dim_in
))
1505 map2
= isl_map_range_product(isl_map_copy(data
->map
),
1506 isl_map_copy(map2
));
1508 data
->res
= isl_union_map_add_map(data
->res
, map2
);
1513 __isl_give isl_union_map
*isl_union_map_range_product(
1514 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
1516 return bin_op(umap1
, umap2
, &range_product_entry
);
1519 /* If data->map A -> B and "map2" C -> D have the same range space,
1520 * then add (A, C) -> (B * D) to data->res.
1522 static isl_stat
flat_domain_product_entry(void **entry
, void *user
)
1524 struct isl_union_map_bin_data
*data
= user
;
1525 isl_map
*map2
= *entry
;
1527 if (!isl_space_tuple_is_equal(data
->map
->dim
, isl_dim_out
,
1528 map2
->dim
, isl_dim_out
))
1531 map2
= isl_map_flat_domain_product(isl_map_copy(data
->map
),
1532 isl_map_copy(map2
));
1534 data
->res
= isl_union_map_add_map(data
->res
, map2
);
1539 /* Given two maps A -> B and C -> D, construct a map (A, C) -> (B * D).
1541 __isl_give isl_union_map
*isl_union_map_flat_domain_product(
1542 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
1544 return bin_op(umap1
, umap2
, &flat_domain_product_entry
);
1547 static isl_stat
flat_range_product_entry(void **entry
, void *user
)
1549 struct isl_union_map_bin_data
*data
= user
;
1550 isl_map
*map2
= *entry
;
1552 if (!isl_space_tuple_is_equal(data
->map
->dim
, isl_dim_in
,
1553 map2
->dim
, isl_dim_in
))
1556 map2
= isl_map_flat_range_product(isl_map_copy(data
->map
),
1557 isl_map_copy(map2
));
1559 data
->res
= isl_union_map_add_map(data
->res
, map2
);
1564 __isl_give isl_union_map
*isl_union_map_flat_range_product(
1565 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
1567 return bin_op(umap1
, umap2
, &flat_range_product_entry
);
1570 /* Data structure that specifies how un_op should modify
1571 * the maps in the union map.
1573 * If "inplace" is set, then the maps in the input union map
1574 * are modified in place. This means that "fn_map" should not
1575 * change the meaning of the map or that the union map only
1576 * has a single reference.
1577 * If "total" is set, then all maps need to be modified and
1578 * the results need to live in the same space.
1579 * Otherwise, a new union map is constructed to store the results.
1580 * If "filter" is not NULL, then only the input maps that satisfy "filter"
1581 * are taken into account. "filter_user" is passed as the second argument
1582 * to "filter". No filter can be set if "inplace" or
1584 * "fn_map" specifies how the maps (selected by "filter")
1585 * should be transformed.
1587 struct isl_un_op_control
{
1590 isl_bool (*filter
)(__isl_keep isl_map
*map
, void *user
);
1592 __isl_give isl_map
*(*fn_map
)(__isl_take isl_map
*map
);
1595 /* Data structure for wrapping the data for un_op_filter_drop_user.
1596 * "filter" is the function that is being wrapped.
1598 struct isl_un_op_drop_user_data
{
1599 isl_bool (*filter
)(__isl_keep isl_map
*map
);
1602 /* Wrapper for isl_un_op_control filters that do not require
1603 * a second argument.
1604 * Simply call data->filter without the second argument.
1606 static isl_bool
un_op_filter_drop_user(__isl_keep isl_map
*map
, void *user
)
1608 struct isl_un_op_drop_user_data
*data
= user
;
1609 return data
->filter(map
);
1612 /* Internal data structure for "un_op".
1613 * "control" specifies how the maps in the union map should be modified.
1614 * "res" collects the results.
1616 struct isl_union_map_un_data
{
1617 struct isl_un_op_control
*control
;
1621 /* isl_hash_table_foreach callback for un_op.
1622 * Handle the map that "entry" points to.
1624 * If control->filter is set, then check if this map satisfies the filter.
1625 * If so (or if control->filter is not set), modify the map
1626 * by calling control->fn_map and either add the result to data->res or
1627 * replace the original entry by the result (if control->inplace is set).
1629 static isl_stat
un_entry(void **entry
, void *user
)
1631 struct isl_union_map_un_data
*data
= user
;
1632 isl_map
*map
= *entry
;
1634 if (data
->control
->filter
) {
1637 ok
= data
->control
->filter(map
, data
->control
->filter_user
);
1639 return isl_stat_error
;
1644 map
= data
->control
->fn_map(isl_map_copy(map
));
1646 return isl_stat_error
;
1647 if (data
->control
->inplace
) {
1648 isl_map_free(*entry
);
1651 data
->res
= isl_union_map_add_map(data
->res
, map
);
1653 return isl_stat_error
;
1659 /* Modify the maps in "umap" based on "control".
1660 * If control->inplace is set, then modify the maps in "umap" in-place.
1661 * Otherwise, create a new union map to hold the results.
1662 * If control->total is set, then perform an inplace computation
1663 * if "umap" is only referenced once. Otherwise, create a new union map
1664 * to store the results.
1666 static __isl_give isl_union_map
*un_op(__isl_take isl_union_map
*umap
,
1667 struct isl_un_op_control
*control
)
1669 struct isl_union_map_un_data data
= { control
};
1673 if ((control
->inplace
|| control
->total
) && control
->filter
)
1674 isl_die(isl_union_map_get_ctx(umap
), isl_error_invalid
,
1675 "inplace/total modification cannot be filtered",
1676 return isl_union_map_free(umap
));
1678 if (control
->total
&& umap
->ref
== 1)
1679 control
->inplace
= 1;
1680 if (control
->inplace
) {
1685 space
= isl_union_map_get_space(umap
);
1686 data
.res
= isl_union_map_alloc(space
, umap
->table
.n
);
1688 if (isl_hash_table_foreach(isl_union_map_get_ctx(umap
),
1689 &umap
->table
, &un_entry
, &data
) < 0)
1690 data
.res
= isl_union_map_free(data
.res
);
1692 if (control
->inplace
)
1694 isl_union_map_free(umap
);
1698 __isl_give isl_union_map
*isl_union_map_from_range(
1699 __isl_take isl_union_set
*uset
)
1701 struct isl_un_op_control control
= {
1702 .fn_map
= &isl_map_from_range
,
1704 return un_op(uset
, &control
);
1707 __isl_give isl_union_map
*isl_union_map_from_domain(
1708 __isl_take isl_union_set
*uset
)
1710 return isl_union_map_reverse(isl_union_map_from_range(uset
));
1713 __isl_give isl_union_map
*isl_union_map_from_domain_and_range(
1714 __isl_take isl_union_set
*domain
, __isl_take isl_union_set
*range
)
1716 return isl_union_map_apply_range(isl_union_map_from_domain(domain
),
1717 isl_union_map_from_range(range
));
1720 /* Modify the maps in "umap" by applying "fn" on them.
1721 * "fn" should apply to all maps in "umap" and should not modify the space.
1723 static __isl_give isl_union_map
*total(__isl_take isl_union_map
*umap
,
1724 __isl_give isl_map
*(*fn
)(__isl_take isl_map
*))
1726 struct isl_un_op_control control
= {
1731 return un_op(umap
, &control
);
1734 /* Compute the affine hull of "map" and return the result as an isl_map.
1736 static __isl_give isl_map
*isl_map_affine_hull_map(__isl_take isl_map
*map
)
1738 return isl_map_from_basic_map(isl_map_affine_hull(map
));
1741 __isl_give isl_union_map
*isl_union_map_affine_hull(
1742 __isl_take isl_union_map
*umap
)
1744 return total(umap
, &isl_map_affine_hull_map
);
1747 __isl_give isl_union_set
*isl_union_set_affine_hull(
1748 __isl_take isl_union_set
*uset
)
1750 return isl_union_map_affine_hull(uset
);
1753 /* Wrapper around isl_set_combined_lineality_space
1754 * that returns the combined lineality space in the form of an isl_set
1755 * instead of an isl_basic_set.
1757 static __isl_give isl_set
*combined_lineality_space(__isl_take isl_set
*set
)
1759 return isl_set_from_basic_set(isl_set_combined_lineality_space(set
));
1762 /* For each set in "uset", compute the (linear) hull
1763 * of the lineality spaces of its basic sets and
1764 * collect and return the results.
1766 __isl_give isl_union_set
*isl_union_set_combined_lineality_space(
1767 __isl_take isl_union_set
*uset
)
1769 struct isl_un_op_control control
= {
1770 .fn_map
= &combined_lineality_space
,
1772 return un_op(uset
, &control
);
1775 /* Compute the polyhedral hull of "map" and return the result as an isl_map.
1777 static __isl_give isl_map
*isl_map_polyhedral_hull_map(__isl_take isl_map
*map
)
1779 return isl_map_from_basic_map(isl_map_polyhedral_hull(map
));
1782 __isl_give isl_union_map
*isl_union_map_polyhedral_hull(
1783 __isl_take isl_union_map
*umap
)
1785 return total(umap
, &isl_map_polyhedral_hull_map
);
1788 __isl_give isl_union_set
*isl_union_set_polyhedral_hull(
1789 __isl_take isl_union_set
*uset
)
1791 return isl_union_map_polyhedral_hull(uset
);
1794 /* Compute a superset of the convex hull of "map" that is described
1795 * by only translates of the constraints in the constituents of "map" and
1796 * return the result as an isl_map.
1798 static __isl_give isl_map
*isl_map_simple_hull_map(__isl_take isl_map
*map
)
1800 return isl_map_from_basic_map(isl_map_simple_hull(map
));
1803 __isl_give isl_union_map
*isl_union_map_simple_hull(
1804 __isl_take isl_union_map
*umap
)
1806 return total(umap
, &isl_map_simple_hull_map
);
1809 __isl_give isl_union_set
*isl_union_set_simple_hull(
1810 __isl_take isl_union_set
*uset
)
1812 return isl_union_map_simple_hull(uset
);
1815 static __isl_give isl_union_map
*inplace(__isl_take isl_union_map
*umap
,
1816 __isl_give isl_map
*(*fn
)(__isl_take isl_map
*))
1818 struct isl_un_op_control control
= {
1823 return un_op(umap
, &control
);
1826 /* Remove redundant constraints in each of the basic maps of "umap".
1827 * Since removing redundant constraints does not change the meaning
1828 * or the space, the operation can be performed in-place.
1830 __isl_give isl_union_map
*isl_union_map_remove_redundancies(
1831 __isl_take isl_union_map
*umap
)
1833 return inplace(umap
, &isl_map_remove_redundancies
);
1836 /* Remove redundant constraints in each of the basic sets of "uset".
1838 __isl_give isl_union_set
*isl_union_set_remove_redundancies(
1839 __isl_take isl_union_set
*uset
)
1841 return isl_union_map_remove_redundancies(uset
);
1844 __isl_give isl_union_map
*isl_union_map_coalesce(
1845 __isl_take isl_union_map
*umap
)
1847 return inplace(umap
, &isl_map_coalesce
);
1850 __isl_give isl_union_set
*isl_union_set_coalesce(
1851 __isl_take isl_union_set
*uset
)
1853 return isl_union_map_coalesce(uset
);
1856 __isl_give isl_union_map
*isl_union_map_detect_equalities(
1857 __isl_take isl_union_map
*umap
)
1859 return inplace(umap
, &isl_map_detect_equalities
);
1862 __isl_give isl_union_set
*isl_union_set_detect_equalities(
1863 __isl_take isl_union_set
*uset
)
1865 return isl_union_map_detect_equalities(uset
);
1868 __isl_give isl_union_map
*isl_union_map_compute_divs(
1869 __isl_take isl_union_map
*umap
)
1871 return inplace(umap
, &isl_map_compute_divs
);
1874 __isl_give isl_union_set
*isl_union_set_compute_divs(
1875 __isl_take isl_union_set
*uset
)
1877 return isl_union_map_compute_divs(uset
);
1880 __isl_give isl_union_map
*isl_union_map_lexmin(
1881 __isl_take isl_union_map
*umap
)
1883 return total(umap
, &isl_map_lexmin
);
1886 __isl_give isl_union_set
*isl_union_set_lexmin(
1887 __isl_take isl_union_set
*uset
)
1889 return isl_union_map_lexmin(uset
);
1892 __isl_give isl_union_map
*isl_union_map_lexmax(
1893 __isl_take isl_union_map
*umap
)
1895 return total(umap
, &isl_map_lexmax
);
1898 __isl_give isl_union_set
*isl_union_set_lexmax(
1899 __isl_take isl_union_set
*uset
)
1901 return isl_union_map_lexmax(uset
);
1904 /* Return the universe in the space of "map".
1906 static __isl_give isl_map
*universe(__isl_take isl_map
*map
)
1910 space
= isl_map_get_space(map
);
1912 return isl_map_universe(space
);
1915 __isl_give isl_union_map
*isl_union_map_universe(__isl_take isl_union_map
*umap
)
1917 struct isl_un_op_control control
= {
1918 .fn_map
= &universe
,
1920 return un_op(umap
, &control
);
1923 __isl_give isl_union_set
*isl_union_set_universe(__isl_take isl_union_set
*uset
)
1925 return isl_union_map_universe(uset
);
1928 __isl_give isl_union_map
*isl_union_map_reverse(__isl_take isl_union_map
*umap
)
1930 struct isl_un_op_control control
= {
1931 .fn_map
= &isl_map_reverse
,
1933 return un_op(umap
, &control
);
1936 /* Compute the parameter domain of the given union map.
1938 __isl_give isl_set
*isl_union_map_params(__isl_take isl_union_map
*umap
)
1940 struct isl_un_op_control control
= {
1941 .fn_map
= &isl_map_params
,
1945 empty
= isl_union_map_is_empty(umap
);
1950 space
= isl_union_map_get_space(umap
);
1951 isl_union_map_free(umap
);
1952 return isl_set_empty(space
);
1954 return isl_set_from_union_set(un_op(umap
, &control
));
1956 isl_union_map_free(umap
);
1960 /* Compute the parameter domain of the given union set.
1962 __isl_give isl_set
*isl_union_set_params(__isl_take isl_union_set
*uset
)
1964 return isl_union_map_params(uset
);
1967 __isl_give isl_union_set
*isl_union_map_domain(__isl_take isl_union_map
*umap
)
1969 struct isl_un_op_control control
= {
1970 .fn_map
= &isl_map_domain
,
1972 return un_op(umap
, &control
);
1975 __isl_give isl_union_set
*isl_union_map_range(__isl_take isl_union_map
*umap
)
1977 struct isl_un_op_control control
= {
1978 .fn_map
= &isl_map_range
,
1980 return un_op(umap
, &control
);
1983 __isl_give isl_union_map
*isl_union_map_domain_map(
1984 __isl_take isl_union_map
*umap
)
1986 struct isl_un_op_control control
= {
1987 .fn_map
= &isl_map_domain_map
,
1989 return un_op(umap
, &control
);
1992 /* Construct an isl_pw_multi_aff that maps "map" to its domain and
1993 * add the result to "res".
1995 static isl_stat
domain_map_upma(__isl_take isl_map
*map
, void *user
)
1997 isl_union_pw_multi_aff
**res
= user
;
1999 isl_pw_multi_aff
*pma
;
2001 ma
= isl_multi_aff_domain_map(isl_map_get_space(map
));
2002 pma
= isl_pw_multi_aff_alloc(isl_map_wrap(map
), ma
);
2003 *res
= isl_union_pw_multi_aff_add_pw_multi_aff(*res
, pma
);
2005 return *res
? isl_stat_ok
: isl_stat_error
;
2009 /* Return an isl_union_pw_multi_aff that maps a wrapped copy of "umap"
2012 __isl_give isl_union_pw_multi_aff
*isl_union_map_domain_map_union_pw_multi_aff(
2013 __isl_take isl_union_map
*umap
)
2015 isl_union_pw_multi_aff
*res
;
2017 res
= isl_union_pw_multi_aff_empty(isl_union_map_get_space(umap
));
2018 if (isl_union_map_foreach_map(umap
, &domain_map_upma
, &res
) < 0)
2019 res
= isl_union_pw_multi_aff_free(res
);
2021 isl_union_map_free(umap
);
2025 __isl_give isl_union_map
*isl_union_map_range_map(
2026 __isl_take isl_union_map
*umap
)
2028 struct isl_un_op_control control
= {
2029 .fn_map
= &isl_map_range_map
,
2031 return un_op(umap
, &control
);
2034 /* Given a collection of wrapped maps of the form A[B -> C],
2035 * return the collection of maps A[B -> C] -> B.
2037 __isl_give isl_union_map
*isl_union_set_wrapped_domain_map(
2038 __isl_take isl_union_set
*uset
)
2040 struct isl_un_op_drop_user_data data
= { &isl_set_is_wrapping
};
2041 struct isl_un_op_control control
= {
2042 .filter
= &un_op_filter_drop_user
,
2043 .filter_user
= &data
,
2044 .fn_map
= &isl_set_wrapped_domain_map
,
2046 return un_op(uset
, &control
);
2049 /* Does "map" relate elements from the same space?
2051 static isl_bool
equal_tuples(__isl_keep isl_map
*map
, void *user
)
2053 return isl_space_tuple_is_equal(map
->dim
, isl_dim_in
,
2054 map
->dim
, isl_dim_out
);
2057 __isl_give isl_union_set
*isl_union_map_deltas(__isl_take isl_union_map
*umap
)
2059 struct isl_un_op_control control
= {
2060 .filter
= &equal_tuples
,
2061 .fn_map
= &isl_map_deltas
,
2063 return un_op(umap
, &control
);
2066 __isl_give isl_union_map
*isl_union_map_deltas_map(
2067 __isl_take isl_union_map
*umap
)
2069 struct isl_un_op_control control
= {
2070 .filter
= &equal_tuples
,
2071 .fn_map
= &isl_map_deltas_map
,
2073 return un_op(umap
, &control
);
2076 __isl_give isl_union_map
*isl_union_set_identity(__isl_take isl_union_set
*uset
)
2078 struct isl_un_op_control control
= {
2079 .fn_map
= &isl_set_identity
,
2081 return un_op(uset
, &control
);
2084 /* Construct an identity isl_pw_multi_aff on "set" and add it to *res.
2086 static isl_stat
identity_upma(__isl_take isl_set
*set
, void *user
)
2088 isl_union_pw_multi_aff
**res
= user
;
2090 isl_pw_multi_aff
*pma
;
2092 space
= isl_space_map_from_set(isl_set_get_space(set
));
2093 pma
= isl_pw_multi_aff_identity(space
);
2094 pma
= isl_pw_multi_aff_intersect_domain(pma
, set
);
2095 *res
= isl_union_pw_multi_aff_add_pw_multi_aff(*res
, pma
);
2097 return *res
? isl_stat_ok
: isl_stat_error
;
2100 /* Return an identity function on "uset" in the form
2101 * of an isl_union_pw_multi_aff.
2103 __isl_give isl_union_pw_multi_aff
*isl_union_set_identity_union_pw_multi_aff(
2104 __isl_take isl_union_set
*uset
)
2106 isl_union_pw_multi_aff
*res
;
2108 res
= isl_union_pw_multi_aff_empty(isl_union_set_get_space(uset
));
2109 if (isl_union_set_foreach_set(uset
, &identity_upma
, &res
) < 0)
2110 res
= isl_union_pw_multi_aff_free(res
);
2112 isl_union_set_free(uset
);
2116 /* For each map in "umap" of the form [A -> B] -> C,
2117 * construct the map A -> C and collect the results.
2119 __isl_give isl_union_map
*isl_union_map_domain_factor_domain(
2120 __isl_take isl_union_map
*umap
)
2122 struct isl_un_op_drop_user_data data
= { &isl_map_domain_is_wrapping
};
2123 struct isl_un_op_control control
= {
2124 .filter
= &un_op_filter_drop_user
,
2125 .filter_user
= &data
,
2126 .fn_map
= &isl_map_domain_factor_domain
,
2128 return un_op(umap
, &control
);
2131 /* For each map in "umap" of the form [A -> B] -> C,
2132 * construct the map B -> C and collect the results.
2134 __isl_give isl_union_map
*isl_union_map_domain_factor_range(
2135 __isl_take isl_union_map
*umap
)
2137 struct isl_un_op_drop_user_data data
= { &isl_map_domain_is_wrapping
};
2138 struct isl_un_op_control control
= {
2139 .filter
= &un_op_filter_drop_user
,
2140 .filter_user
= &data
,
2141 .fn_map
= &isl_map_domain_factor_range
,
2143 return un_op(umap
, &control
);
2146 /* For each map in "umap" of the form A -> [B -> C],
2147 * construct the map A -> B and collect the results.
2149 __isl_give isl_union_map
*isl_union_map_range_factor_domain(
2150 __isl_take isl_union_map
*umap
)
2152 struct isl_un_op_drop_user_data data
= { &isl_map_range_is_wrapping
};
2153 struct isl_un_op_control control
= {
2154 .filter
= &un_op_filter_drop_user
,
2155 .filter_user
= &data
,
2156 .fn_map
= &isl_map_range_factor_domain
,
2158 return un_op(umap
, &control
);
2161 /* For each map in "umap" of the form A -> [B -> C],
2162 * construct the map A -> C and collect the results.
2164 __isl_give isl_union_map
*isl_union_map_range_factor_range(
2165 __isl_take isl_union_map
*umap
)
2167 struct isl_un_op_drop_user_data data
= { &isl_map_range_is_wrapping
};
2168 struct isl_un_op_control control
= {
2169 .filter
= &un_op_filter_drop_user
,
2170 .filter_user
= &data
,
2171 .fn_map
= &isl_map_range_factor_range
,
2173 return un_op(umap
, &control
);
2176 /* For each map in "umap" of the form [A -> B] -> [C -> D],
2177 * construct the map A -> C and collect the results.
2179 __isl_give isl_union_map
*isl_union_map_factor_domain(
2180 __isl_take isl_union_map
*umap
)
2182 struct isl_un_op_drop_user_data data
= { &isl_map_is_product
};
2183 struct isl_un_op_control control
= {
2184 .filter
= &un_op_filter_drop_user
,
2185 .filter_user
= &data
,
2186 .fn_map
= &isl_map_factor_domain
,
2188 return un_op(umap
, &control
);
2191 /* For each map in "umap" of the form [A -> B] -> [C -> D],
2192 * construct the map B -> D and collect the results.
2194 __isl_give isl_union_map
*isl_union_map_factor_range(
2195 __isl_take isl_union_map
*umap
)
2197 struct isl_un_op_drop_user_data data
= { &isl_map_is_product
};
2198 struct isl_un_op_control control
= {
2199 .filter
= &un_op_filter_drop_user
,
2200 .filter_user
= &data
,
2201 .fn_map
= &isl_map_factor_range
,
2203 return un_op(umap
, &control
);
2206 __isl_give isl_union_map
*isl_union_set_unwrap(__isl_take isl_union_set
*uset
)
2208 struct isl_un_op_drop_user_data data
= { &isl_set_is_wrapping
};
2209 struct isl_un_op_control control
= {
2210 .filter
= &un_op_filter_drop_user
,
2211 .filter_user
= &data
,
2212 .fn_map
= &isl_set_unwrap
,
2214 return un_op(uset
, &control
);
2217 __isl_give isl_union_set
*isl_union_map_wrap(__isl_take isl_union_map
*umap
)
2219 struct isl_un_op_control control
= {
2220 .fn_map
= &isl_map_wrap
,
2222 return un_op(umap
, &control
);
2225 struct isl_union_map_is_subset_data
{
2226 isl_union_map
*umap2
;
2230 static isl_stat
is_subset_entry(void **entry
, void *user
)
2232 struct isl_union_map_is_subset_data
*data
= user
;
2234 struct isl_hash_table_entry
*entry2
;
2235 isl_map
*map
= *entry
;
2237 hash
= isl_space_get_hash(map
->dim
);
2238 entry2
= isl_hash_table_find(data
->umap2
->dim
->ctx
, &data
->umap2
->table
,
2239 hash
, &has_space
, map
->dim
, 0);
2241 int empty
= isl_map_is_empty(map
);
2243 return isl_stat_error
;
2246 data
->is_subset
= 0;
2247 return isl_stat_error
;
2250 data
->is_subset
= isl_map_is_subset(map
, entry2
->data
);
2251 if (data
->is_subset
< 0 || !data
->is_subset
)
2252 return isl_stat_error
;
2257 isl_bool
isl_union_map_is_subset(__isl_keep isl_union_map
*umap1
,
2258 __isl_keep isl_union_map
*umap2
)
2260 struct isl_union_map_is_subset_data data
= { NULL
, isl_bool_true
};
2262 umap1
= isl_union_map_copy(umap1
);
2263 umap2
= isl_union_map_copy(umap2
);
2264 umap1
= isl_union_map_align_params(umap1
, isl_union_map_get_space(umap2
));
2265 umap2
= isl_union_map_align_params(umap2
, isl_union_map_get_space(umap1
));
2267 if (!umap1
|| !umap2
)
2271 if (isl_hash_table_foreach(umap1
->dim
->ctx
, &umap1
->table
,
2272 &is_subset_entry
, &data
) < 0 &&
2276 isl_union_map_free(umap1
);
2277 isl_union_map_free(umap2
);
2279 return data
.is_subset
;
2281 isl_union_map_free(umap1
);
2282 isl_union_map_free(umap2
);
2283 return isl_bool_error
;
2286 isl_bool
isl_union_set_is_subset(__isl_keep isl_union_set
*uset1
,
2287 __isl_keep isl_union_set
*uset2
)
2289 return isl_union_map_is_subset(uset1
, uset2
);
2292 isl_bool
isl_union_map_is_equal(__isl_keep isl_union_map
*umap1
,
2293 __isl_keep isl_union_map
*umap2
)
2297 if (!umap1
|| !umap2
)
2298 return isl_bool_error
;
2299 is_subset
= isl_union_map_is_subset(umap1
, umap2
);
2300 if (is_subset
!= isl_bool_true
)
2302 is_subset
= isl_union_map_is_subset(umap2
, umap1
);
2306 isl_bool
isl_union_set_is_equal(__isl_keep isl_union_set
*uset1
,
2307 __isl_keep isl_union_set
*uset2
)
2309 return isl_union_map_is_equal(uset1
, uset2
);
2312 isl_bool
isl_union_map_is_strict_subset(__isl_keep isl_union_map
*umap1
,
2313 __isl_keep isl_union_map
*umap2
)
2317 if (!umap1
|| !umap2
)
2318 return isl_bool_error
;
2319 is_subset
= isl_union_map_is_subset(umap1
, umap2
);
2320 if (is_subset
!= isl_bool_true
)
2322 is_subset
= isl_union_map_is_subset(umap2
, umap1
);
2323 if (is_subset
== isl_bool_error
)
2328 isl_bool
isl_union_set_is_strict_subset(__isl_keep isl_union_set
*uset1
,
2329 __isl_keep isl_union_set
*uset2
)
2331 return isl_union_map_is_strict_subset(uset1
, uset2
);
2334 /* Internal data structure for isl_union_map_is_disjoint.
2335 * umap2 is the union map with which we are comparing.
2336 * is_disjoint is initialized to 1 and is set to 0 as soon
2337 * as the union maps turn out not to be disjoint.
2339 struct isl_union_map_is_disjoint_data
{
2340 isl_union_map
*umap2
;
2341 isl_bool is_disjoint
;
2344 /* Check if "map" is disjoint from data->umap2 and abort
2345 * the search if it is not.
2347 static isl_stat
is_disjoint_entry(void **entry
, void *user
)
2349 struct isl_union_map_is_disjoint_data
*data
= user
;
2351 struct isl_hash_table_entry
*entry2
;
2352 isl_map
*map
= *entry
;
2354 hash
= isl_space_get_hash(map
->dim
);
2355 entry2
= isl_hash_table_find(data
->umap2
->dim
->ctx
, &data
->umap2
->table
,
2356 hash
, &has_space
, map
->dim
, 0);
2360 data
->is_disjoint
= isl_map_is_disjoint(map
, entry2
->data
);
2361 if (data
->is_disjoint
< 0 || !data
->is_disjoint
)
2362 return isl_stat_error
;
2367 /* Are "umap1" and "umap2" disjoint?
2369 isl_bool
isl_union_map_is_disjoint(__isl_keep isl_union_map
*umap1
,
2370 __isl_keep isl_union_map
*umap2
)
2372 struct isl_union_map_is_disjoint_data data
= { NULL
, isl_bool_true
};
2374 umap1
= isl_union_map_copy(umap1
);
2375 umap2
= isl_union_map_copy(umap2
);
2376 umap1
= isl_union_map_align_params(umap1
,
2377 isl_union_map_get_space(umap2
));
2378 umap2
= isl_union_map_align_params(umap2
,
2379 isl_union_map_get_space(umap1
));
2381 if (!umap1
|| !umap2
)
2385 if (isl_hash_table_foreach(umap1
->dim
->ctx
, &umap1
->table
,
2386 &is_disjoint_entry
, &data
) < 0 &&
2390 isl_union_map_free(umap1
);
2391 isl_union_map_free(umap2
);
2393 return data
.is_disjoint
;
2395 isl_union_map_free(umap1
);
2396 isl_union_map_free(umap2
);
2397 return isl_bool_error
;
2400 /* Are "uset1" and "uset2" disjoint?
2402 isl_bool
isl_union_set_is_disjoint(__isl_keep isl_union_set
*uset1
,
2403 __isl_keep isl_union_set
*uset2
)
2405 return isl_union_map_is_disjoint(uset1
, uset2
);
2408 static isl_stat
sample_entry(void **entry
, void *user
)
2410 isl_basic_map
**sample
= (isl_basic_map
**)user
;
2411 isl_map
*map
= *entry
;
2413 *sample
= isl_map_sample(isl_map_copy(map
));
2415 return isl_stat_error
;
2416 if (!isl_basic_map_plain_is_empty(*sample
))
2417 return isl_stat_error
;
2421 __isl_give isl_basic_map
*isl_union_map_sample(__isl_take isl_union_map
*umap
)
2423 isl_basic_map
*sample
= NULL
;
2428 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
,
2429 &sample_entry
, &sample
) < 0 &&
2434 sample
= isl_basic_map_empty(isl_union_map_get_space(umap
));
2436 isl_union_map_free(umap
);
2440 isl_union_map_free(umap
);
2444 __isl_give isl_basic_set
*isl_union_set_sample(__isl_take isl_union_set
*uset
)
2446 return bset_from_bmap(isl_union_map_sample(uset
));
2449 /* Return an element in "uset" in the form of an isl_point.
2450 * Return a void isl_point if "uset" is empty.
2452 __isl_give isl_point
*isl_union_set_sample_point(__isl_take isl_union_set
*uset
)
2454 return isl_basic_set_sample_point(isl_union_set_sample(uset
));
2457 struct isl_forall_data
{
2459 isl_bool (*fn
)(__isl_keep isl_map
*map
);
2462 static isl_stat
forall_entry(void **entry
, void *user
)
2464 struct isl_forall_data
*data
= user
;
2465 isl_map
*map
= *entry
;
2467 data
->res
= data
->fn(map
);
2469 return isl_stat_error
;
2472 return isl_stat_error
;
2477 static isl_bool
union_map_forall(__isl_keep isl_union_map
*umap
,
2478 isl_bool (*fn
)(__isl_keep isl_map
*map
))
2480 struct isl_forall_data data
= { isl_bool_true
, fn
};
2483 return isl_bool_error
;
2485 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
,
2486 &forall_entry
, &data
) < 0 && data
.res
)
2487 return isl_bool_error
;
2492 struct isl_forall_user_data
{
2494 isl_bool (*fn
)(__isl_keep isl_map
*map
, void *user
);
2498 static isl_stat
forall_user_entry(void **entry
, void *user
)
2500 struct isl_forall_user_data
*data
= user
;
2501 isl_map
*map
= *entry
;
2503 data
->res
= data
->fn(map
, data
->user
);
2505 return isl_stat_error
;
2508 return isl_stat_error
;
2513 /* Check if fn(map, user) returns true for all maps "map" in umap.
2515 static isl_bool
union_map_forall_user(__isl_keep isl_union_map
*umap
,
2516 isl_bool (*fn
)(__isl_keep isl_map
*map
, void *user
), void *user
)
2518 struct isl_forall_user_data data
= { isl_bool_true
, fn
, user
};
2521 return isl_bool_error
;
2523 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
,
2524 &forall_user_entry
, &data
) < 0 && data
.res
)
2525 return isl_bool_error
;
2530 /* Is "umap" obviously empty?
2532 isl_bool
isl_union_map_plain_is_empty(__isl_keep isl_union_map
*umap
)
2535 return isl_bool_error
;
2536 return isl_union_map_n_map(umap
) == 0;
2539 isl_bool
isl_union_map_is_empty(__isl_keep isl_union_map
*umap
)
2541 return union_map_forall(umap
, &isl_map_is_empty
);
2544 isl_bool
isl_union_set_is_empty(__isl_keep isl_union_set
*uset
)
2546 return isl_union_map_is_empty(uset
);
2549 static isl_bool
is_subset_of_identity(__isl_keep isl_map
*map
)
2556 return isl_bool_error
;
2558 if (!isl_space_tuple_is_equal(map
->dim
, isl_dim_in
,
2559 map
->dim
, isl_dim_out
))
2560 return isl_bool_false
;
2562 dim
= isl_map_get_space(map
);
2563 id
= isl_map_identity(dim
);
2565 is_subset
= isl_map_is_subset(map
, id
);
2572 /* Given an isl_union_map that consists of a single map, check
2573 * if it is single-valued.
2575 static isl_bool
single_map_is_single_valued(__isl_keep isl_union_map
*umap
)
2580 umap
= isl_union_map_copy(umap
);
2581 map
= isl_map_from_union_map(umap
);
2582 sv
= isl_map_is_single_valued(map
);
2588 /* Internal data structure for single_valued_on_domain.
2590 * "umap" is the union map to be tested.
2591 * "sv" is set to 1 as long as "umap" may still be single-valued.
2593 struct isl_union_map_is_sv_data
{
2594 isl_union_map
*umap
;
2598 /* Check if the data->umap is single-valued on "set".
2600 * If data->umap consists of a single map on "set", then test it
2603 * Otherwise, compute
2607 * check if the result is a subset of the identity mapping and
2608 * store the result in data->sv.
2610 * Terminate as soon as data->umap has been determined not to
2613 static isl_stat
single_valued_on_domain(__isl_take isl_set
*set
, void *user
)
2615 struct isl_union_map_is_sv_data
*data
= user
;
2616 isl_union_map
*umap
, *test
;
2618 umap
= isl_union_map_copy(data
->umap
);
2619 umap
= isl_union_map_intersect_domain(umap
,
2620 isl_union_set_from_set(set
));
2622 if (isl_union_map_n_map(umap
) == 1) {
2623 data
->sv
= single_map_is_single_valued(umap
);
2624 isl_union_map_free(umap
);
2626 test
= isl_union_map_reverse(isl_union_map_copy(umap
));
2627 test
= isl_union_map_apply_range(test
, umap
);
2629 data
->sv
= union_map_forall(test
, &is_subset_of_identity
);
2631 isl_union_map_free(test
);
2634 if (data
->sv
< 0 || !data
->sv
)
2635 return isl_stat_error
;
2639 /* Check if the given map is single-valued.
2641 * If the union map consists of a single map, then test it as an isl_map.
2642 * Otherwise, check if the union map is single-valued on each of its
2645 isl_bool
isl_union_map_is_single_valued(__isl_keep isl_union_map
*umap
)
2647 isl_union_map
*universe
;
2648 isl_union_set
*domain
;
2649 struct isl_union_map_is_sv_data data
;
2651 if (isl_union_map_n_map(umap
) == 1)
2652 return single_map_is_single_valued(umap
);
2654 universe
= isl_union_map_universe(isl_union_map_copy(umap
));
2655 domain
= isl_union_map_domain(universe
);
2657 data
.sv
= isl_bool_true
;
2659 if (isl_union_set_foreach_set(domain
,
2660 &single_valued_on_domain
, &data
) < 0 && data
.sv
)
2661 data
.sv
= isl_bool_error
;
2662 isl_union_set_free(domain
);
2667 isl_bool
isl_union_map_is_injective(__isl_keep isl_union_map
*umap
)
2671 umap
= isl_union_map_copy(umap
);
2672 umap
= isl_union_map_reverse(umap
);
2673 in
= isl_union_map_is_single_valued(umap
);
2674 isl_union_map_free(umap
);
2679 /* Is "map" obviously not an identity relation because
2680 * it maps elements from one space to another space?
2681 * Update *non_identity accordingly.
2683 * In particular, if the domain and range spaces are the same,
2684 * then the map is not considered to obviously not be an identity relation.
2685 * Otherwise, the map is considered to obviously not be an identity relation
2686 * if it is is non-empty.
2688 * If "map" is determined to obviously not be an identity relation,
2689 * then the search is aborted.
2691 static isl_stat
map_plain_is_not_identity(__isl_take isl_map
*map
, void *user
)
2693 isl_bool
*non_identity
= user
;
2697 space
= isl_map_get_space(map
);
2698 equal
= isl_space_tuple_is_equal(space
, isl_dim_in
, space
, isl_dim_out
);
2699 if (equal
>= 0 && !equal
)
2700 *non_identity
= isl_bool_not(isl_map_is_empty(map
));
2702 *non_identity
= isl_bool_not(equal
);
2703 isl_space_free(space
);
2706 if (*non_identity
< 0 || *non_identity
)
2707 return isl_stat_error
;
2712 /* Is "umap" obviously not an identity relation because
2713 * it maps elements from one space to another space?
2715 * As soon as a map has been found that maps elements to a different space,
2716 * non_identity is changed and the search is aborted.
2718 static isl_bool
isl_union_map_plain_is_not_identity(
2719 __isl_keep isl_union_map
*umap
)
2721 isl_bool non_identity
;
2723 non_identity
= isl_bool_false
;
2724 if (isl_union_map_foreach_map(umap
, &map_plain_is_not_identity
,
2725 &non_identity
) < 0 &&
2726 non_identity
== isl_bool_false
)
2727 return isl_bool_error
;
2729 return non_identity
;
2732 /* Does "map" only map elements to themselves?
2733 * Update *identity accordingly.
2735 * If "map" is determined not to be an identity relation,
2736 * then the search is aborted.
2738 static isl_stat
map_is_identity(__isl_take isl_map
*map
, void *user
)
2740 isl_bool
*identity
= user
;
2742 *identity
= isl_map_is_identity(map
);
2745 if (*identity
< 0 || !*identity
)
2746 return isl_stat_error
;
2751 /* Does "umap" only map elements to themselves?
2753 * First check if there are any maps that map elements to different spaces.
2754 * If not, then check that all the maps (between identical spaces)
2755 * are identity relations.
2757 isl_bool
isl_union_map_is_identity(__isl_keep isl_union_map
*umap
)
2759 isl_bool non_identity
;
2762 non_identity
= isl_union_map_plain_is_not_identity(umap
);
2763 if (non_identity
< 0 || non_identity
)
2764 return isl_bool_not(non_identity
);
2766 identity
= isl_bool_true
;
2767 if (isl_union_map_foreach_map(umap
, &map_is_identity
, &identity
) < 0 &&
2768 identity
== isl_bool_true
)
2769 return isl_bool_error
;
2774 /* Represents a map that has a fixed value (v) for one of its
2776 * The map in this structure is not reference counted, so it
2777 * is only valid while the isl_union_map from which it was
2778 * obtained is still alive.
2780 struct isl_fixed_map
{
2785 static struct isl_fixed_map
*alloc_isl_fixed_map_array(isl_ctx
*ctx
,
2789 struct isl_fixed_map
*v
;
2791 v
= isl_calloc_array(ctx
, struct isl_fixed_map
, n
);
2794 for (i
= 0; i
< n
; ++i
)
2795 isl_int_init(v
[i
].v
);
2799 static void free_isl_fixed_map_array(struct isl_fixed_map
*v
, int n
)
2805 for (i
= 0; i
< n
; ++i
)
2806 isl_int_clear(v
[i
].v
);
2810 /* Compare the "v" field of two isl_fixed_map structs.
2812 static int qsort_fixed_map_cmp(const void *p1
, const void *p2
)
2814 const struct isl_fixed_map
*e1
= (const struct isl_fixed_map
*) p1
;
2815 const struct isl_fixed_map
*e2
= (const struct isl_fixed_map
*) p2
;
2817 return isl_int_cmp(e1
->v
, e2
->v
);
2820 /* Internal data structure used while checking whether all maps
2821 * in a union_map have a fixed value for a given output dimension.
2822 * v is the list of maps, with the fixed value for the dimension
2823 * n is the number of maps considered so far
2824 * pos is the output dimension under investigation
2826 struct isl_fixed_dim_data
{
2827 struct isl_fixed_map
*v
;
2832 static isl_bool
fixed_at_pos(__isl_keep isl_map
*map
, void *user
)
2834 struct isl_fixed_dim_data
*data
= user
;
2836 data
->v
[data
->n
].map
= map
;
2837 return isl_map_plain_is_fixed(map
, isl_dim_out
, data
->pos
,
2838 &data
->v
[data
->n
++].v
);
2841 static isl_bool
plain_injective_on_range(__isl_take isl_union_map
*umap
,
2842 int first
, int n_range
);
2844 /* Given a list of the maps, with their fixed values at output dimension "pos",
2845 * check whether the ranges of the maps form an obvious partition.
2847 * We first sort the maps according to their fixed values.
2848 * If all maps have a different value, then we know the ranges form
2850 * Otherwise, we collect the maps with the same fixed value and
2851 * check whether each such collection is obviously injective
2852 * based on later dimensions.
2854 static int separates(struct isl_fixed_map
*v
, int n
,
2855 __isl_take isl_space
*dim
, int pos
, int n_range
)
2862 qsort(v
, n
, sizeof(*v
), &qsort_fixed_map_cmp
);
2864 for (i
= 0; i
+ 1 < n
; ++i
) {
2866 isl_union_map
*part
;
2869 for (j
= i
+ 1; j
< n
; ++j
)
2870 if (isl_int_ne(v
[i
].v
, v
[j
].v
))
2876 part
= isl_union_map_alloc(isl_space_copy(dim
), j
- i
);
2877 for (k
= i
; k
< j
; ++k
)
2878 part
= isl_union_map_add_map(part
,
2879 isl_map_copy(v
[k
].map
));
2881 injective
= plain_injective_on_range(part
, pos
+ 1, n_range
);
2890 isl_space_free(dim
);
2891 free_isl_fixed_map_array(v
, n
);
2894 isl_space_free(dim
);
2895 free_isl_fixed_map_array(v
, n
);
2899 /* Check whether the maps in umap have obviously distinct ranges.
2900 * In particular, check for an output dimension in the range
2901 * [first,n_range) for which all maps have a fixed value
2902 * and then check if these values, possibly along with fixed values
2903 * at later dimensions, entail distinct ranges.
2905 static isl_bool
plain_injective_on_range(__isl_take isl_union_map
*umap
,
2906 int first
, int n_range
)
2910 struct isl_fixed_dim_data data
= { NULL
};
2912 ctx
= isl_union_map_get_ctx(umap
);
2914 n
= isl_union_map_n_map(umap
);
2919 isl_union_map_free(umap
);
2920 return isl_bool_true
;
2923 if (first
>= n_range
) {
2924 isl_union_map_free(umap
);
2925 return isl_bool_false
;
2928 data
.v
= alloc_isl_fixed_map_array(ctx
, n
);
2932 for (data
.pos
= first
; data
.pos
< n_range
; ++data
.pos
) {
2938 fixed
= union_map_forall_user(umap
, &fixed_at_pos
, &data
);
2943 dim
= isl_union_map_get_space(umap
);
2944 injective
= separates(data
.v
, n
, dim
, data
.pos
, n_range
);
2945 isl_union_map_free(umap
);
2949 free_isl_fixed_map_array(data
.v
, n
);
2950 isl_union_map_free(umap
);
2952 return isl_bool_false
;
2954 free_isl_fixed_map_array(data
.v
, n
);
2955 isl_union_map_free(umap
);
2956 return isl_bool_error
;
2959 /* Check whether the maps in umap that map to subsets of "ran"
2960 * have obviously distinct ranges.
2962 static isl_bool
plain_injective_on_range_wrap(__isl_keep isl_set
*ran
,
2965 isl_union_map
*umap
= user
;
2967 umap
= isl_union_map_copy(umap
);
2968 umap
= isl_union_map_intersect_range(umap
,
2969 isl_union_set_from_set(isl_set_copy(ran
)));
2970 return plain_injective_on_range(umap
, 0, isl_set_dim(ran
, isl_dim_set
));
2973 /* Check if the given union_map is obviously injective.
2975 * In particular, we first check if all individual maps are obviously
2976 * injective and then check if all the ranges of these maps are
2977 * obviously disjoint.
2979 isl_bool
isl_union_map_plain_is_injective(__isl_keep isl_union_map
*umap
)
2982 isl_union_map
*univ
;
2985 in
= union_map_forall(umap
, &isl_map_plain_is_injective
);
2987 return isl_bool_error
;
2989 return isl_bool_false
;
2991 univ
= isl_union_map_universe(isl_union_map_copy(umap
));
2992 ran
= isl_union_map_range(univ
);
2994 in
= union_map_forall_user(ran
, &plain_injective_on_range_wrap
, umap
);
2996 isl_union_set_free(ran
);
3001 isl_bool
isl_union_map_is_bijective(__isl_keep isl_union_map
*umap
)
3005 sv
= isl_union_map_is_single_valued(umap
);
3009 return isl_union_map_is_injective(umap
);
3012 __isl_give isl_union_map
*isl_union_map_zip(__isl_take isl_union_map
*umap
)
3014 struct isl_un_op_drop_user_data data
= { &isl_map_can_zip
};
3015 struct isl_un_op_control control
= {
3016 .filter
= &un_op_filter_drop_user
,
3017 .filter_user
= &data
,
3018 .fn_map
= &isl_map_zip
,
3020 return un_op(umap
, &control
);
3023 /* Given a union map, take the maps of the form A -> (B -> C) and
3024 * return the union of the corresponding maps (A -> B) -> C.
3026 __isl_give isl_union_map
*isl_union_map_uncurry(__isl_take isl_union_map
*umap
)
3028 struct isl_un_op_drop_user_data data
= { &isl_map_can_uncurry
};
3029 struct isl_un_op_control control
= {
3030 .filter
= &un_op_filter_drop_user
,
3031 .filter_user
= &data
,
3032 .fn_map
= &isl_map_uncurry
,
3034 return un_op(umap
, &control
);
3037 /* Given a union map, take the maps of the form (A -> B) -> C and
3038 * return the union of the corresponding maps A -> (B -> C).
3040 __isl_give isl_union_map
*isl_union_map_curry(__isl_take isl_union_map
*umap
)
3042 struct isl_un_op_drop_user_data data
= { &isl_map_can_curry
};
3043 struct isl_un_op_control control
= {
3044 .filter
= &un_op_filter_drop_user
,
3045 .filter_user
= &data
,
3046 .fn_map
= &isl_map_curry
,
3048 return un_op(umap
, &control
);
3051 /* Given a union map, take the maps of the form A -> ((B -> C) -> D) and
3052 * return the union of the corresponding maps A -> (B -> (C -> D)).
3054 __isl_give isl_union_map
*isl_union_map_range_curry(
3055 __isl_take isl_union_map
*umap
)
3057 struct isl_un_op_drop_user_data data
= { &isl_map_can_range_curry
};
3058 struct isl_un_op_control control
= {
3059 .filter
= &un_op_filter_drop_user
,
3060 .filter_user
= &data
,
3061 .fn_map
= &isl_map_range_curry
,
3063 return un_op(umap
, &control
);
3066 __isl_give isl_union_set
*isl_union_set_lift(__isl_take isl_union_set
*uset
)
3068 struct isl_un_op_control control
= {
3069 .fn_map
= &isl_set_lift
,
3071 return un_op(uset
, &control
);
3074 static isl_stat
coefficients_entry(void **entry
, void *user
)
3076 isl_set
*set
= *entry
;
3077 isl_union_set
**res
= user
;
3079 set
= isl_set_copy(set
);
3080 set
= isl_set_from_basic_set(isl_set_coefficients(set
));
3081 *res
= isl_union_set_add_set(*res
, set
);
3086 __isl_give isl_union_set
*isl_union_set_coefficients(
3087 __isl_take isl_union_set
*uset
)
3096 ctx
= isl_union_set_get_ctx(uset
);
3097 dim
= isl_space_set_alloc(ctx
, 0, 0);
3098 res
= isl_union_map_alloc(dim
, uset
->table
.n
);
3099 if (isl_hash_table_foreach(uset
->dim
->ctx
, &uset
->table
,
3100 &coefficients_entry
, &res
) < 0)
3103 isl_union_set_free(uset
);
3106 isl_union_set_free(uset
);
3107 isl_union_set_free(res
);
3111 static isl_stat
solutions_entry(void **entry
, void *user
)
3113 isl_set
*set
= *entry
;
3114 isl_union_set
**res
= user
;
3116 set
= isl_set_copy(set
);
3117 set
= isl_set_from_basic_set(isl_set_solutions(set
));
3119 *res
= isl_union_set_from_set(set
);
3121 *res
= isl_union_set_add_set(*res
, set
);
3124 return isl_stat_error
;
3129 __isl_give isl_union_set
*isl_union_set_solutions(
3130 __isl_take isl_union_set
*uset
)
3132 isl_union_set
*res
= NULL
;
3137 if (uset
->table
.n
== 0) {
3138 res
= isl_union_set_empty(isl_union_set_get_space(uset
));
3139 isl_union_set_free(uset
);
3143 if (isl_hash_table_foreach(uset
->dim
->ctx
, &uset
->table
,
3144 &solutions_entry
, &res
) < 0)
3147 isl_union_set_free(uset
);
3150 isl_union_set_free(uset
);
3151 isl_union_set_free(res
);
3155 /* Is the domain space of "map" equal to "space"?
3157 static int domain_match(__isl_keep isl_map
*map
, __isl_keep isl_space
*space
)
3159 return isl_space_tuple_is_equal(map
->dim
, isl_dim_in
,
3160 space
, isl_dim_out
);
3163 /* Is the range space of "map" equal to "space"?
3165 static int range_match(__isl_keep isl_map
*map
, __isl_keep isl_space
*space
)
3167 return isl_space_tuple_is_equal(map
->dim
, isl_dim_out
,
3168 space
, isl_dim_out
);
3171 /* Is the set space of "map" equal to "space"?
3173 static int set_match(__isl_keep isl_map
*map
, __isl_keep isl_space
*space
)
3175 return isl_space_tuple_is_equal(map
->dim
, isl_dim_set
,
3176 space
, isl_dim_out
);
3179 /* Internal data structure for preimage_pw_multi_aff.
3181 * "pma" is the function under which the preimage should be taken.
3182 * "space" is the space of "pma".
3183 * "res" collects the results.
3184 * "fn" computes the preimage for a given map.
3185 * "match" returns true if "fn" can be called.
3187 struct isl_union_map_preimage_data
{
3189 isl_pw_multi_aff
*pma
;
3191 int (*match
)(__isl_keep isl_map
*map
, __isl_keep isl_space
*space
);
3192 __isl_give isl_map
*(*fn
)(__isl_take isl_map
*map
,
3193 __isl_take isl_pw_multi_aff
*pma
);
3196 /* Call data->fn to compute the preimage of the domain or range of *entry
3197 * under the function represented by data->pma, provided the domain/range
3198 * space of *entry matches the target space of data->pma
3199 * (as given by data->match), and add the result to data->res.
3201 static isl_stat
preimage_entry(void **entry
, void *user
)
3204 isl_map
*map
= *entry
;
3205 struct isl_union_map_preimage_data
*data
= user
;
3208 m
= data
->match(map
, data
->space
);
3210 return isl_stat_error
;
3214 map
= isl_map_copy(map
);
3215 map
= data
->fn(map
, isl_pw_multi_aff_copy(data
->pma
));
3217 empty
= isl_map_is_empty(map
);
3218 if (empty
< 0 || empty
) {
3220 return empty
< 0 ? isl_stat_error
: isl_stat_ok
;
3223 data
->res
= isl_union_map_add_map(data
->res
, map
);
3228 /* Compute the preimage of the domain or range of "umap" under the function
3229 * represented by "pma".
3230 * In other words, plug in "pma" in the domain or range of "umap".
3231 * The function "fn" performs the actual preimage computation on a map,
3232 * while "match" determines to which maps the function should be applied.
3234 static __isl_give isl_union_map
*preimage_pw_multi_aff(
3235 __isl_take isl_union_map
*umap
, __isl_take isl_pw_multi_aff
*pma
,
3236 int (*match
)(__isl_keep isl_map
*map
, __isl_keep isl_space
*space
),
3237 __isl_give isl_map
*(*fn
)(__isl_take isl_map
*map
,
3238 __isl_take isl_pw_multi_aff
*pma
))
3242 struct isl_union_map_preimage_data data
;
3244 umap
= isl_union_map_align_params(umap
,
3245 isl_pw_multi_aff_get_space(pma
));
3246 pma
= isl_pw_multi_aff_align_params(pma
, isl_union_map_get_space(umap
));
3251 ctx
= isl_union_map_get_ctx(umap
);
3252 space
= isl_union_map_get_space(umap
);
3253 data
.space
= isl_pw_multi_aff_get_space(pma
);
3255 data
.res
= isl_union_map_alloc(space
, umap
->table
.n
);
3258 if (isl_hash_table_foreach(ctx
, &umap
->table
, &preimage_entry
,
3260 data
.res
= isl_union_map_free(data
.res
);
3262 isl_space_free(data
.space
);
3263 isl_union_map_free(umap
);
3264 isl_pw_multi_aff_free(pma
);
3267 isl_union_map_free(umap
);
3268 isl_pw_multi_aff_free(pma
);
3272 /* Compute the preimage of the domain of "umap" under the function
3273 * represented by "pma".
3274 * In other words, plug in "pma" in the domain of "umap".
3275 * The result contains maps that live in the same spaces as the maps of "umap"
3276 * with domain space equal to the target space of "pma",
3277 * except that the domain has been replaced by the domain space of "pma".
3279 __isl_give isl_union_map
*isl_union_map_preimage_domain_pw_multi_aff(
3280 __isl_take isl_union_map
*umap
, __isl_take isl_pw_multi_aff
*pma
)
3282 return preimage_pw_multi_aff(umap
, pma
, &domain_match
,
3283 &isl_map_preimage_domain_pw_multi_aff
);
3286 /* Compute the preimage of the range of "umap" under the function
3287 * represented by "pma".
3288 * In other words, plug in "pma" in the range of "umap".
3289 * The result contains maps that live in the same spaces as the maps of "umap"
3290 * with range space equal to the target space of "pma",
3291 * except that the range has been replaced by the domain space of "pma".
3293 __isl_give isl_union_map
*isl_union_map_preimage_range_pw_multi_aff(
3294 __isl_take isl_union_map
*umap
, __isl_take isl_pw_multi_aff
*pma
)
3296 return preimage_pw_multi_aff(umap
, pma
, &range_match
,
3297 &isl_map_preimage_range_pw_multi_aff
);
3300 /* Compute the preimage of "uset" under the function represented by "pma".
3301 * In other words, plug in "pma" in "uset".
3302 * The result contains sets that live in the same spaces as the sets of "uset"
3303 * with space equal to the target space of "pma",
3304 * except that the space has been replaced by the domain space of "pma".
3306 __isl_give isl_union_set
*isl_union_set_preimage_pw_multi_aff(
3307 __isl_take isl_union_set
*uset
, __isl_take isl_pw_multi_aff
*pma
)
3309 return preimage_pw_multi_aff(uset
, pma
, &set_match
,
3310 &isl_set_preimage_pw_multi_aff
);
3313 /* Compute the preimage of the domain of "umap" under the function
3314 * represented by "ma".
3315 * In other words, plug in "ma" in the domain of "umap".
3316 * The result contains maps that live in the same spaces as the maps of "umap"
3317 * with domain space equal to the target space of "ma",
3318 * except that the domain has been replaced by the domain space of "ma".
3320 __isl_give isl_union_map
*isl_union_map_preimage_domain_multi_aff(
3321 __isl_take isl_union_map
*umap
, __isl_take isl_multi_aff
*ma
)
3323 return isl_union_map_preimage_domain_pw_multi_aff(umap
,
3324 isl_pw_multi_aff_from_multi_aff(ma
));
3327 /* Compute the preimage of the range of "umap" under the function
3328 * represented by "ma".
3329 * In other words, plug in "ma" in the range of "umap".
3330 * The result contains maps that live in the same spaces as the maps of "umap"
3331 * with range space equal to the target space of "ma",
3332 * except that the range has been replaced by the domain space of "ma".
3334 __isl_give isl_union_map
*isl_union_map_preimage_range_multi_aff(
3335 __isl_take isl_union_map
*umap
, __isl_take isl_multi_aff
*ma
)
3337 return isl_union_map_preimage_range_pw_multi_aff(umap
,
3338 isl_pw_multi_aff_from_multi_aff(ma
));
3341 /* Compute the preimage of "uset" under the function represented by "ma".
3342 * In other words, plug in "ma" in "uset".
3343 * The result contains sets that live in the same spaces as the sets of "uset"
3344 * with space equal to the target space of "ma",
3345 * except that the space has been replaced by the domain space of "ma".
3347 __isl_give isl_union_map
*isl_union_set_preimage_multi_aff(
3348 __isl_take isl_union_set
*uset
, __isl_take isl_multi_aff
*ma
)
3350 return isl_union_set_preimage_pw_multi_aff(uset
,
3351 isl_pw_multi_aff_from_multi_aff(ma
));
3354 /* Internal data structure for preimage_multi_pw_aff.
3356 * "mpa" is the function under which the preimage should be taken.
3357 * "space" is the space of "mpa".
3358 * "res" collects the results.
3359 * "fn" computes the preimage for a given map.
3360 * "match" returns true if "fn" can be called.
3362 struct isl_union_map_preimage_mpa_data
{
3364 isl_multi_pw_aff
*mpa
;
3366 int (*match
)(__isl_keep isl_map
*map
, __isl_keep isl_space
*space
);
3367 __isl_give isl_map
*(*fn
)(__isl_take isl_map
*map
,
3368 __isl_take isl_multi_pw_aff
*mpa
);
3371 /* Call data->fn to compute the preimage of the domain or range of *entry
3372 * under the function represented by data->mpa, provided the domain/range
3373 * space of *entry matches the target space of data->mpa
3374 * (as given by data->match), and add the result to data->res.
3376 static isl_stat
preimage_mpa_entry(void **entry
, void *user
)
3379 isl_map
*map
= *entry
;
3380 struct isl_union_map_preimage_mpa_data
*data
= user
;
3383 m
= data
->match(map
, data
->space
);
3385 return isl_stat_error
;
3389 map
= isl_map_copy(map
);
3390 map
= data
->fn(map
, isl_multi_pw_aff_copy(data
->mpa
));
3392 empty
= isl_map_is_empty(map
);
3393 if (empty
< 0 || empty
) {
3395 return empty
< 0 ? isl_stat_error
: isl_stat_ok
;
3398 data
->res
= isl_union_map_add_map(data
->res
, map
);
3403 /* Compute the preimage of the domain or range of "umap" under the function
3404 * represented by "mpa".
3405 * In other words, plug in "mpa" in the domain or range of "umap".
3406 * The function "fn" performs the actual preimage computation on a map,
3407 * while "match" determines to which maps the function should be applied.
3409 static __isl_give isl_union_map
*preimage_multi_pw_aff(
3410 __isl_take isl_union_map
*umap
, __isl_take isl_multi_pw_aff
*mpa
,
3411 int (*match
)(__isl_keep isl_map
*map
, __isl_keep isl_space
*space
),
3412 __isl_give isl_map
*(*fn
)(__isl_take isl_map
*map
,
3413 __isl_take isl_multi_pw_aff
*mpa
))
3417 struct isl_union_map_preimage_mpa_data data
;
3419 umap
= isl_union_map_align_params(umap
,
3420 isl_multi_pw_aff_get_space(mpa
));
3421 mpa
= isl_multi_pw_aff_align_params(mpa
, isl_union_map_get_space(umap
));
3426 ctx
= isl_union_map_get_ctx(umap
);
3427 space
= isl_union_map_get_space(umap
);
3428 data
.space
= isl_multi_pw_aff_get_space(mpa
);
3430 data
.res
= isl_union_map_alloc(space
, umap
->table
.n
);
3433 if (isl_hash_table_foreach(ctx
, &umap
->table
, &preimage_mpa_entry
,
3435 data
.res
= isl_union_map_free(data
.res
);
3437 isl_space_free(data
.space
);
3438 isl_union_map_free(umap
);
3439 isl_multi_pw_aff_free(mpa
);
3442 isl_union_map_free(umap
);
3443 isl_multi_pw_aff_free(mpa
);
3447 /* Compute the preimage of the domain of "umap" under the function
3448 * represented by "mpa".
3449 * In other words, plug in "mpa" in the domain of "umap".
3450 * The result contains maps that live in the same spaces as the maps of "umap"
3451 * with domain space equal to the target space of "mpa",
3452 * except that the domain has been replaced by the domain space of "mpa".
3454 __isl_give isl_union_map
*isl_union_map_preimage_domain_multi_pw_aff(
3455 __isl_take isl_union_map
*umap
, __isl_take isl_multi_pw_aff
*mpa
)
3457 return preimage_multi_pw_aff(umap
, mpa
, &domain_match
,
3458 &isl_map_preimage_domain_multi_pw_aff
);
3461 /* Internal data structure for preimage_upma.
3463 * "umap" is the map of which the preimage should be computed.
3464 * "res" collects the results.
3465 * "fn" computes the preimage for a given piecewise multi-affine function.
3467 struct isl_union_map_preimage_upma_data
{
3468 isl_union_map
*umap
;
3470 __isl_give isl_union_map
*(*fn
)(__isl_take isl_union_map
*umap
,
3471 __isl_take isl_pw_multi_aff
*pma
);
3474 /* Call data->fn to compute the preimage of the domain or range of data->umap
3475 * under the function represented by pma and add the result to data->res.
3477 static isl_stat
preimage_upma(__isl_take isl_pw_multi_aff
*pma
, void *user
)
3479 struct isl_union_map_preimage_upma_data
*data
= user
;
3480 isl_union_map
*umap
;
3482 umap
= isl_union_map_copy(data
->umap
);
3483 umap
= data
->fn(umap
, pma
);
3484 data
->res
= isl_union_map_union(data
->res
, umap
);
3486 return data
->res
? isl_stat_ok
: isl_stat_error
;
3489 /* Compute the preimage of the domain or range of "umap" under the function
3490 * represented by "upma".
3491 * In other words, plug in "upma" in the domain or range of "umap".
3492 * The function "fn" performs the actual preimage computation
3493 * on a piecewise multi-affine function.
3495 static __isl_give isl_union_map
*preimage_union_pw_multi_aff(
3496 __isl_take isl_union_map
*umap
,
3497 __isl_take isl_union_pw_multi_aff
*upma
,
3498 __isl_give isl_union_map
*(*fn
)(__isl_take isl_union_map
*umap
,
3499 __isl_take isl_pw_multi_aff
*pma
))
3501 struct isl_union_map_preimage_upma_data data
;
3504 data
.res
= isl_union_map_empty(isl_union_map_get_space(umap
));
3506 if (isl_union_pw_multi_aff_foreach_pw_multi_aff(upma
,
3507 &preimage_upma
, &data
) < 0)
3508 data
.res
= isl_union_map_free(data
.res
);
3510 isl_union_map_free(umap
);
3511 isl_union_pw_multi_aff_free(upma
);
3516 /* Compute the preimage of the domain of "umap" under the function
3517 * represented by "upma".
3518 * In other words, plug in "upma" in the domain of "umap".
3519 * The result contains maps that live in the same spaces as the maps of "umap"
3520 * with domain space equal to one of the target spaces of "upma",
3521 * except that the domain has been replaced by one of the domain spaces that
3522 * correspond to that target space of "upma".
3524 __isl_give isl_union_map
*isl_union_map_preimage_domain_union_pw_multi_aff(
3525 __isl_take isl_union_map
*umap
,
3526 __isl_take isl_union_pw_multi_aff
*upma
)
3528 return preimage_union_pw_multi_aff(umap
, upma
,
3529 &isl_union_map_preimage_domain_pw_multi_aff
);
3532 /* Compute the preimage of the range of "umap" under the function
3533 * represented by "upma".
3534 * In other words, plug in "upma" in the range of "umap".
3535 * The result contains maps that live in the same spaces as the maps of "umap"
3536 * with range space equal to one of the target spaces of "upma",
3537 * except that the range has been replaced by one of the domain spaces that
3538 * correspond to that target space of "upma".
3540 __isl_give isl_union_map
*isl_union_map_preimage_range_union_pw_multi_aff(
3541 __isl_take isl_union_map
*umap
,
3542 __isl_take isl_union_pw_multi_aff
*upma
)
3544 return preimage_union_pw_multi_aff(umap
, upma
,
3545 &isl_union_map_preimage_range_pw_multi_aff
);
3548 /* Compute the preimage of "uset" under the function represented by "upma".
3549 * In other words, plug in "upma" in the range of "uset".
3550 * The result contains sets that live in the same spaces as the sets of "uset"
3551 * with space equal to one of the target spaces of "upma",
3552 * except that the space has been replaced by one of the domain spaces that
3553 * correspond to that target space of "upma".
3555 __isl_give isl_union_set
*isl_union_set_preimage_union_pw_multi_aff(
3556 __isl_take isl_union_set
*uset
,
3557 __isl_take isl_union_pw_multi_aff
*upma
)
3559 return preimage_union_pw_multi_aff(uset
, upma
,
3560 &isl_union_set_preimage_pw_multi_aff
);
3563 /* Reset the user pointer on all identifiers of parameters and tuples
3564 * of the spaces of "umap".
3566 __isl_give isl_union_map
*isl_union_map_reset_user(
3567 __isl_take isl_union_map
*umap
)
3569 umap
= isl_union_map_cow(umap
);
3572 umap
->dim
= isl_space_reset_user(umap
->dim
);
3574 return isl_union_map_free(umap
);
3575 return total(umap
, &isl_map_reset_user
);
3578 /* Reset the user pointer on all identifiers of parameters and tuples
3579 * of the spaces of "uset".
3581 __isl_give isl_union_set
*isl_union_set_reset_user(
3582 __isl_take isl_union_set
*uset
)
3584 return isl_union_map_reset_user(uset
);
3587 /* Remove all existentially quantified variables and integer divisions
3588 * from "umap" using Fourier-Motzkin elimination.
3590 __isl_give isl_union_map
*isl_union_map_remove_divs(
3591 __isl_take isl_union_map
*umap
)
3593 return total(umap
, &isl_map_remove_divs
);
3596 /* Remove all existentially quantified variables and integer divisions
3597 * from "uset" using Fourier-Motzkin elimination.
3599 __isl_give isl_union_set
*isl_union_set_remove_divs(
3600 __isl_take isl_union_set
*uset
)
3602 return isl_union_map_remove_divs(uset
);
3605 /* Internal data structure for isl_union_map_project_out.
3606 * "type", "first" and "n" are the arguments for the isl_map_project_out
3608 * "res" collects the results.
3610 struct isl_union_map_project_out_data
{
3611 enum isl_dim_type type
;
3618 /* Turn the data->n dimensions of type data->type, starting at data->first
3619 * into existentially quantified variables and add the result to data->res.
3621 static isl_stat
project_out(__isl_take isl_map
*map
, void *user
)
3623 struct isl_union_map_project_out_data
*data
= user
;
3625 map
= isl_map_project_out(map
, data
->type
, data
->first
, data
->n
);
3626 data
->res
= isl_union_map_add_map(data
->res
, map
);
3631 /* Turn the "n" dimensions of type "type", starting at "first"
3632 * into existentially quantified variables.
3633 * Since the space of an isl_union_map only contains parameters,
3634 * type is required to be equal to isl_dim_param.
3636 __isl_give isl_union_map
*isl_union_map_project_out(
3637 __isl_take isl_union_map
*umap
,
3638 enum isl_dim_type type
, unsigned first
, unsigned n
)
3641 struct isl_union_map_project_out_data data
= { type
, first
, n
};
3646 if (type
!= isl_dim_param
)
3647 isl_die(isl_union_map_get_ctx(umap
), isl_error_invalid
,
3648 "can only project out parameters",
3649 return isl_union_map_free(umap
));
3651 space
= isl_union_map_get_space(umap
);
3652 space
= isl_space_drop_dims(space
, type
, first
, n
);
3653 data
.res
= isl_union_map_empty(space
);
3654 if (isl_union_map_foreach_map(umap
, &project_out
, &data
) < 0)
3655 data
.res
= isl_union_map_free(data
.res
);
3657 isl_union_map_free(umap
);
3662 /* Project out all parameters from "umap" by existentially quantifying
3665 __isl_give isl_union_map
*isl_union_map_project_out_all_params(
3666 __isl_take isl_union_map
*umap
)
3672 n
= isl_union_map_dim(umap
, isl_dim_param
);
3673 return isl_union_map_project_out(umap
, isl_dim_param
, 0, n
);
3676 /* Turn the "n" dimensions of type "type", starting at "first"
3677 * into existentially quantified variables.
3678 * Since the space of an isl_union_set only contains parameters,
3679 * "type" is required to be equal to isl_dim_param.
3681 __isl_give isl_union_set
*isl_union_set_project_out(
3682 __isl_take isl_union_set
*uset
,
3683 enum isl_dim_type type
, unsigned first
, unsigned n
)
3685 return isl_union_map_project_out(uset
, type
, first
, n
);
3688 /* Internal data structure for isl_union_map_involves_dims.
3689 * "first" and "n" are the arguments for the isl_map_involves_dims calls.
3691 struct isl_union_map_involves_dims_data
{
3696 /* Does "map" _not_ involve the data->n parameters starting at data->first?
3698 static isl_bool
map_excludes(__isl_keep isl_map
*map
, void *user
)
3700 struct isl_union_map_involves_dims_data
*data
= user
;
3703 involves
= isl_map_involves_dims(map
,
3704 isl_dim_param
, data
->first
, data
->n
);
3706 return isl_bool_error
;
3710 /* Does "umap" involve any of the n parameters starting at first?
3711 * "type" is required to be set to isl_dim_param.
3713 * "umap" involves any of those parameters if any of its maps
3714 * involve the parameters. In other words, "umap" does not
3715 * involve any of the parameters if all its maps to not
3716 * involve the parameters.
3718 isl_bool
isl_union_map_involves_dims(__isl_keep isl_union_map
*umap
,
3719 enum isl_dim_type type
, unsigned first
, unsigned n
)
3721 struct isl_union_map_involves_dims_data data
= { first
, n
};
3724 if (type
!= isl_dim_param
)
3725 isl_die(isl_union_map_get_ctx(umap
), isl_error_invalid
,
3726 "can only reference parameters", return isl_bool_error
);
3728 excludes
= union_map_forall_user(umap
, &map_excludes
, &data
);
3731 return isl_bool_error
;
3736 /* Internal data structure for isl_union_map_reset_range_space.
3737 * "range" is the space from which to set the range space.
3738 * "res" collects the results.
3740 struct isl_union_map_reset_range_space_data
{
3745 /* Replace the range space of "map" by the range space of data->range and
3746 * add the result to data->res.
3748 static isl_stat
reset_range_space(__isl_take isl_map
*map
, void *user
)
3750 struct isl_union_map_reset_range_space_data
*data
= user
;
3753 space
= isl_map_get_space(map
);
3754 space
= isl_space_domain(space
);
3755 space
= isl_space_extend_domain_with_range(space
,
3756 isl_space_copy(data
->range
));
3757 map
= isl_map_reset_space(map
, space
);
3758 data
->res
= isl_union_map_add_map(data
->res
, map
);
3760 return data
->res
? isl_stat_ok
: isl_stat_error
;
3763 /* Replace the range space of all the maps in "umap" by
3764 * the range space of "space".
3766 * This assumes that all maps have the same output dimension.
3767 * This function should therefore not be made publicly available.
3769 * Since the spaces of the maps change, so do their hash value.
3770 * We therefore need to create a new isl_union_map.
3772 __isl_give isl_union_map
*isl_union_map_reset_range_space(
3773 __isl_take isl_union_map
*umap
, __isl_take isl_space
*space
)
3775 struct isl_union_map_reset_range_space_data data
= { space
};
3777 data
.res
= isl_union_map_empty(isl_union_map_get_space(umap
));
3778 if (isl_union_map_foreach_map(umap
, &reset_range_space
, &data
) < 0)
3779 data
.res
= isl_union_map_free(data
.res
);
3781 isl_space_free(space
);
3782 isl_union_map_free(umap
);
3786 /* Internal data structure for isl_union_map_order_at_multi_union_pw_aff.
3787 * "mupa" is the function from which the isl_multi_pw_affs are extracted.
3788 * "order" is applied to the extracted isl_multi_pw_affs that correspond
3789 * to the domain and the range of each map.
3790 * "res" collects the results.
3792 struct isl_union_order_at_data
{
3793 isl_multi_union_pw_aff
*mupa
;
3794 __isl_give isl_map
*(*order
)(__isl_take isl_multi_pw_aff
*mpa1
,
3795 __isl_take isl_multi_pw_aff
*mpa2
);
3799 /* Intersect "map" with the result of applying data->order to
3800 * the functions in data->mupa that apply to the domain and the range
3801 * of "map" and add the result to data->res.
3803 static isl_stat
order_at(__isl_take isl_map
*map
, void *user
)
3805 struct isl_union_order_at_data
*data
= user
;
3807 isl_multi_pw_aff
*mpa1
, *mpa2
;
3810 space
= isl_space_domain(isl_map_get_space(map
));
3811 mpa1
= isl_multi_union_pw_aff_extract_multi_pw_aff(data
->mupa
, space
);
3812 space
= isl_space_range(isl_map_get_space(map
));
3813 mpa2
= isl_multi_union_pw_aff_extract_multi_pw_aff(data
->mupa
, space
);
3814 order
= data
->order(mpa1
, mpa2
);
3815 map
= isl_map_intersect(map
, order
);
3816 data
->res
= isl_union_map_add_map(data
->res
, map
);
3818 return data
->res
? isl_stat_ok
: isl_stat_error
;
3821 /* Intersect each map in "umap" with the result of calling "order"
3822 * on the functions is "mupa" that apply to the domain and the range
3825 static __isl_give isl_union_map
*isl_union_map_order_at_multi_union_pw_aff(
3826 __isl_take isl_union_map
*umap
, __isl_take isl_multi_union_pw_aff
*mupa
,
3827 __isl_give isl_map
*(*order
)(__isl_take isl_multi_pw_aff
*mpa1
,
3828 __isl_take isl_multi_pw_aff
*mpa2
))
3830 struct isl_union_order_at_data data
;
3832 umap
= isl_union_map_align_params(umap
,
3833 isl_multi_union_pw_aff_get_space(mupa
));
3834 mupa
= isl_multi_union_pw_aff_align_params(mupa
,
3835 isl_union_map_get_space(umap
));
3838 data
.res
= isl_union_map_empty(isl_union_map_get_space(umap
));
3839 if (isl_union_map_foreach_map(umap
, &order_at
, &data
) < 0)
3840 data
.res
= isl_union_map_free(data
.res
);
3842 isl_multi_union_pw_aff_free(mupa
);
3843 isl_union_map_free(umap
);
3847 /* Return the subset of "umap" where the domain and the range
3848 * have equal "mupa" values.
3850 __isl_give isl_union_map
*isl_union_map_eq_at_multi_union_pw_aff(
3851 __isl_take isl_union_map
*umap
,
3852 __isl_take isl_multi_union_pw_aff
*mupa
)
3854 return isl_union_map_order_at_multi_union_pw_aff(umap
, mupa
,
3855 &isl_multi_pw_aff_eq_map
);
3858 /* Return the subset of "umap" where the domain has a lexicographically
3859 * smaller "mupa" value than the range.
3861 __isl_give isl_union_map
*isl_union_map_lex_lt_at_multi_union_pw_aff(
3862 __isl_take isl_union_map
*umap
,
3863 __isl_take isl_multi_union_pw_aff
*mupa
)
3865 return isl_union_map_order_at_multi_union_pw_aff(umap
, mupa
,
3866 &isl_multi_pw_aff_lex_lt_map
);
3869 /* Return the subset of "umap" where the domain has a lexicographically
3870 * greater "mupa" value than the range.
3872 __isl_give isl_union_map
*isl_union_map_lex_gt_at_multi_union_pw_aff(
3873 __isl_take isl_union_map
*umap
,
3874 __isl_take isl_multi_union_pw_aff
*mupa
)
3876 return isl_union_map_order_at_multi_union_pw_aff(umap
, mupa
,
3877 &isl_multi_pw_aff_lex_gt_map
);
3880 /* Return the union of the elements in the list "list".
3882 __isl_give isl_union_set
*isl_union_set_list_union(
3883 __isl_take isl_union_set_list
*list
)
3893 ctx
= isl_union_set_list_get_ctx(list
);
3894 space
= isl_space_params_alloc(ctx
, 0);
3895 res
= isl_union_set_empty(space
);
3897 n
= isl_union_set_list_n_union_set(list
);
3898 for (i
= 0; i
< n
; ++i
) {
3899 isl_union_set
*uset_i
;
3901 uset_i
= isl_union_set_list_get_union_set(list
, i
);
3902 res
= isl_union_set_union(res
, uset_i
);
3905 isl_union_set_list_free(list
);
3909 /* Update *hash with the hash value of "map".
3911 static isl_stat
add_hash(__isl_take isl_map
*map
, void *user
)
3913 uint32_t *hash
= user
;
3916 map_hash
= isl_map_get_hash(map
);
3917 isl_hash_hash(*hash
, map_hash
);
3923 /* Return a hash value that digests "umap".
3925 uint32_t isl_union_map_get_hash(__isl_keep isl_union_map
*umap
)
3932 hash
= isl_hash_init();
3933 if (isl_union_map_foreach_map(umap
, &add_hash
, &hash
) < 0)
3939 /* Return a hash value that digests "uset".
3941 uint32_t isl_union_set_get_hash(__isl_keep isl_union_set
*uset
)
3943 return isl_union_map_get_hash(uset
);
3946 /* Add the number of basic sets in "set" to "n".
3948 static isl_stat
add_n(__isl_take isl_set
*set
, void *user
)
3952 *n
+= isl_set_n_basic_set(set
);
3958 /* Return the total number of basic sets in "uset".
3960 int isl_union_set_n_basic_set(__isl_keep isl_union_set
*uset
)
3964 if (isl_union_set_foreach_set(uset
, &add_n
, &n
) < 0)
3970 /* Add the basic sets in "set" to "list".
3972 static isl_stat
add_list(__isl_take isl_set
*set
, void *user
)
3974 isl_basic_set_list
**list
= user
;
3975 isl_basic_set_list
*list_i
;
3977 list_i
= isl_set_get_basic_set_list(set
);
3978 *list
= isl_basic_set_list_concat(*list
, list_i
);
3982 return isl_stat_error
;
3986 /* Return a list containing all the basic sets in "uset".
3988 * First construct a list of the appropriate size and
3989 * then add all the elements.
3991 __isl_give isl_basic_set_list
*isl_union_set_get_basic_set_list(
3992 __isl_keep isl_union_set
*uset
)
3996 isl_basic_set_list
*list
;
4000 ctx
= isl_union_set_get_ctx(uset
);
4001 n
= isl_union_set_n_basic_set(uset
);
4004 list
= isl_basic_set_list_alloc(ctx
, n
);
4005 if (isl_union_set_foreach_set(uset
, &add_list
, &list
) < 0)
4006 list
= isl_basic_set_list_free(list
);
4011 /* Internal data structure for isl_union_map_remove_map_if.
4012 * "fn" and "user" are the arguments to isl_union_map_remove_map_if.
4014 struct isl_union_map_remove_map_if_data
{
4015 isl_bool (*fn
)(__isl_keep isl_map
*map
, void *user
);
4019 /* isl_un_op_control filter that negates the result of data->fn
4022 static isl_bool
not(__isl_keep isl_map
*map
, void *user
)
4024 struct isl_union_map_remove_map_if_data
*data
= user
;
4026 return isl_bool_not(data
->fn(map
, data
->user
));
4029 /* Dummy isl_un_op_control transformation callback that
4030 * simply returns the input.
4032 static __isl_give isl_map
*map_id(__isl_take isl_map
*map
)
4037 /* Call "fn" on every map in "umap" and remove those maps
4038 * for which the callback returns true.
4040 * Use un_op to keep only those maps that are not filtered out,
4041 * applying an identity transformation on them.
4043 __isl_give isl_union_map
*isl_union_map_remove_map_if(
4044 __isl_take isl_union_map
*umap
,
4045 isl_bool (*fn
)(__isl_keep isl_map
*map
, void *user
), void *user
)
4047 struct isl_union_map_remove_map_if_data data
= { fn
, user
};
4048 struct isl_un_op_control control
= {
4050 .filter_user
= &data
,
4053 return un_op(umap
, &control
);