2 * Copyright 2010 INRIA Saclay
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
15 #include <isl_dim_private.h>
16 #include <isl_map_private.h>
17 #include <isl_union_map_private.h>
18 #include <isl_union_set.h>
20 static __isl_give isl_union_map
*isl_union_map_alloc(__isl_take isl_dim
*dim
,
28 umap
= isl_calloc_type(dim
->ctx
, isl_union_map
);
34 if (isl_hash_table_init(dim
->ctx
, &umap
->table
, size
) < 0)
40 isl_union_map_free(umap
);
44 __isl_give isl_union_map
*isl_union_map_empty(__isl_take isl_dim
*dim
)
46 return isl_union_map_alloc(dim
, 16);
49 __isl_give isl_union_set
*isl_union_set_empty(__isl_take isl_dim
*dim
)
51 return isl_union_map_empty(dim
);
54 isl_ctx
*isl_union_map_get_ctx(__isl_keep isl_union_map
*umap
)
56 return umap
? umap
->dim
->ctx
: NULL
;
59 isl_ctx
*isl_union_set_get_ctx(__isl_keep isl_union_set
*uset
)
61 return uset
? uset
->dim
->ctx
: NULL
;
64 __isl_give isl_dim
*isl_union_map_get_dim(__isl_keep isl_union_map
*umap
)
68 return isl_dim_copy(umap
->dim
);
71 __isl_give isl_dim
*isl_union_set_get_dim(__isl_keep isl_union_set
*uset
)
73 return isl_union_map_get_dim(uset
);
76 static int free_umap_entry(void **entry
, void *user
)
78 isl_map
*map
= *entry
;
83 static int add_map(__isl_take isl_map
*map
, void *user
)
85 isl_union_map
**umap
= (isl_union_map
**)user
;
87 *umap
= isl_union_map_add_map(*umap
, map
);
92 __isl_give isl_union_map
*isl_union_map_dup(__isl_keep isl_union_map
*umap
)
99 dup
= isl_union_map_empty(isl_dim_copy(umap
->dim
));
100 if (isl_union_map_foreach_map(umap
, &add_map
, &dup
) < 0)
104 isl_union_map_free(dup
);
108 __isl_give isl_union_map
*isl_union_map_cow(__isl_take isl_union_map
*umap
)
116 return isl_union_map_dup(umap
);
119 struct isl_union_align
{
124 static int align_entry(void **entry
, void *user
)
126 isl_map
*map
= *entry
;
128 struct isl_union_align
*data
= user
;
130 exp
= isl_reordering_extend_dim(isl_reordering_copy(data
->exp
),
131 isl_map_get_dim(map
));
133 data
->res
= isl_union_map_add_map(data
->res
,
134 isl_map_realign(isl_map_copy(map
), exp
));
139 /* Align the parameters of umap along those of model.
140 * The result has the parameters of model first, in the same order
141 * as they appear in model, followed by any remaining parameters of
142 * umap that do not appear in model.
144 __isl_give isl_union_map
*isl_union_map_align_params(
145 __isl_take isl_union_map
*umap
, __isl_take isl_dim
*model
)
147 struct isl_union_align data
= { NULL
, NULL
};
152 if (isl_dim_match(umap
->dim
, isl_dim_param
, model
, isl_dim_param
)) {
157 data
.exp
= isl_parameter_alignment_reordering(umap
->dim
, model
);
161 data
.res
= isl_union_map_alloc(isl_dim_copy(data
.exp
->dim
),
163 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
,
164 &align_entry
, &data
) < 0)
167 isl_reordering_free(data
.exp
);
168 isl_union_map_free(umap
);
172 isl_reordering_free(data
.exp
);
173 isl_union_map_free(umap
);
174 isl_union_map_free(data
.res
);
179 __isl_give isl_union_set
*isl_union_set_align_params(
180 __isl_take isl_union_set
*uset
, __isl_take isl_dim
*model
)
182 return isl_union_map_align_params(uset
, model
);
185 __isl_give isl_union_map
*isl_union_map_union(__isl_take isl_union_map
*umap1
,
186 __isl_take isl_union_map
*umap2
)
188 umap1
= isl_union_map_align_params(umap1
, isl_union_map_get_dim(umap2
));
189 umap2
= isl_union_map_align_params(umap2
, isl_union_map_get_dim(umap1
));
191 umap1
= isl_union_map_cow(umap1
);
193 if (!umap1
|| !umap2
)
196 if (isl_union_map_foreach_map(umap2
, &add_map
, &umap1
) < 0)
199 isl_union_map_free(umap2
);
203 isl_union_map_free(umap1
);
204 isl_union_map_free(umap2
);
208 __isl_give isl_union_set
*isl_union_set_union(__isl_take isl_union_set
*uset1
,
209 __isl_take isl_union_set
*uset2
)
211 return isl_union_map_union(uset1
, uset2
);
214 __isl_give isl_union_map
*isl_union_map_copy(__isl_keep isl_union_map
*umap
)
223 __isl_give isl_union_set
*isl_union_set_copy(__isl_keep isl_union_set
*uset
)
225 return isl_union_map_copy(uset
);
228 void isl_union_map_free(__isl_take isl_union_map
*umap
)
236 isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
,
237 &free_umap_entry
, NULL
);
238 isl_hash_table_clear(&umap
->table
);
239 isl_dim_free(umap
->dim
);
243 void isl_union_set_free(__isl_take isl_union_set
*uset
)
245 isl_union_map_free(uset
);
248 static int has_dim(const void *entry
, const void *val
)
250 isl_map
*map
= (isl_map
*)entry
;
251 isl_dim
*dim
= (isl_dim
*)val
;
253 return isl_dim_equal(map
->dim
, dim
);
256 __isl_give isl_union_map
*isl_union_map_add_map(__isl_take isl_union_map
*umap
,
257 __isl_take isl_map
*map
)
260 struct isl_hash_table_entry
*entry
;
262 if (isl_map_fast_is_empty(map
)) {
267 umap
= isl_union_map_cow(umap
);
272 isl_assert(map
->ctx
, isl_dim_match(map
->dim
, isl_dim_param
, umap
->dim
,
273 isl_dim_param
), goto error
);
275 hash
= isl_dim_get_hash(map
->dim
);
276 entry
= isl_hash_table_find(umap
->dim
->ctx
, &umap
->table
, hash
,
277 &has_dim
, map
->dim
, 1);
284 entry
->data
= isl_map_union(entry
->data
, isl_map_copy(map
));
293 isl_union_map_free(umap
);
297 __isl_give isl_union_set
*isl_union_set_add_set(__isl_take isl_union_set
*uset
,
298 __isl_take isl_set
*set
)
300 return isl_union_map_add_map(uset
, (isl_map
*)set
);
303 __isl_give isl_union_map
*isl_union_map_from_map(__isl_take isl_map
*map
)
311 dim
= isl_map_get_dim(map
);
312 dim
= isl_dim_drop(dim
, isl_dim_in
, 0, isl_dim_size(dim
, isl_dim_in
));
313 dim
= isl_dim_drop(dim
, isl_dim_out
, 0, isl_dim_size(dim
, isl_dim_out
));
314 umap
= isl_union_map_empty(dim
);
315 umap
= isl_union_map_add_map(umap
, map
);
320 __isl_give isl_union_set
*isl_union_set_from_set(__isl_take isl_set
*set
)
322 return isl_union_map_from_map((isl_map
*)set
);
325 struct isl_union_map_foreach_data
327 int (*fn
)(__isl_take isl_map
*map
, void *user
);
331 static int call_on_copy(void **entry
, void *user
)
333 isl_map
*map
= *entry
;
334 struct isl_union_map_foreach_data
*data
;
335 data
= (struct isl_union_map_foreach_data
*)user
;
337 return data
->fn(isl_map_copy(map
), data
->user
);
340 int isl_union_map_foreach_map(__isl_keep isl_union_map
*umap
,
341 int (*fn
)(__isl_take isl_map
*map
, void *user
), void *user
)
343 struct isl_union_map_foreach_data data
= { fn
, user
};
348 return isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
,
349 &call_on_copy
, &data
);
352 int isl_union_set_foreach_set(__isl_keep isl_union_set
*uset
,
353 int (*fn
)(__isl_take isl_set
*set
, void *user
), void *user
)
355 return isl_union_map_foreach_map(uset
,
356 (int(*)(__isl_take isl_map
*, void*))fn
, user
);
359 struct isl_union_set_foreach_point_data
{
360 int (*fn
)(__isl_take isl_point
*pnt
, void *user
);
364 static int foreach_point(__isl_take isl_set
*set
, void *user
)
366 struct isl_union_set_foreach_point_data
*data
= user
;
369 r
= isl_set_foreach_point(set
, data
->fn
, data
->user
);
375 int isl_union_set_foreach_point(__isl_keep isl_union_set
*uset
,
376 int (*fn
)(__isl_take isl_point
*pnt
, void *user
), void *user
)
378 struct isl_union_set_foreach_point_data data
= { fn
, user
};
379 return isl_union_set_foreach_set(uset
, &foreach_point
, &data
);
382 struct isl_union_map_gen_bin_data
{
383 isl_union_map
*umap2
;
387 static int subtract_entry(void **entry
, void *user
)
389 struct isl_union_map_gen_bin_data
*data
= user
;
391 struct isl_hash_table_entry
*entry2
;
392 isl_map
*map
= *entry
;
394 hash
= isl_dim_get_hash(map
->dim
);
395 entry2
= isl_hash_table_find(data
->umap2
->dim
->ctx
, &data
->umap2
->table
,
396 hash
, &has_dim
, map
->dim
, 0);
397 map
= isl_map_copy(map
);
400 map
= isl_map_subtract(map
, isl_map_copy(entry2
->data
));
402 empty
= isl_map_is_empty(map
);
412 data
->res
= isl_union_map_add_map(data
->res
, map
);
417 static __isl_give isl_union_map
*gen_bin_op(__isl_take isl_union_map
*umap1
,
418 __isl_take isl_union_map
*umap2
, int (*fn
)(void **, void *))
420 struct isl_union_map_gen_bin_data data
= { NULL
, NULL
};
422 umap1
= isl_union_map_align_params(umap1
, isl_union_map_get_dim(umap2
));
423 umap2
= isl_union_map_align_params(umap2
, isl_union_map_get_dim(umap1
));
425 if (!umap1
|| !umap2
)
429 data
.res
= isl_union_map_alloc(isl_dim_copy(umap1
->dim
),
431 if (isl_hash_table_foreach(umap1
->dim
->ctx
, &umap1
->table
,
435 isl_union_map_free(umap1
);
436 isl_union_map_free(umap2
);
439 isl_union_map_free(umap1
);
440 isl_union_map_free(umap2
);
441 isl_union_map_free(data
.res
);
445 __isl_give isl_union_map
*isl_union_map_subtract(
446 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
448 return gen_bin_op(umap1
, umap2
, &subtract_entry
);
451 __isl_give isl_union_set
*isl_union_set_subtract(
452 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
454 return isl_union_map_subtract(uset1
, uset2
);
457 struct isl_union_map_match_bin_data
{
458 isl_union_map
*umap2
;
460 __isl_give isl_map
*(*fn
)(__isl_take isl_map
*, __isl_take isl_map
*);
463 static int match_bin_entry(void **entry
, void *user
)
465 struct isl_union_map_match_bin_data
*data
= user
;
467 struct isl_hash_table_entry
*entry2
;
468 isl_map
*map
= *entry
;
471 hash
= isl_dim_get_hash(map
->dim
);
472 entry2
= isl_hash_table_find(data
->umap2
->dim
->ctx
, &data
->umap2
->table
,
473 hash
, &has_dim
, map
->dim
, 0);
477 map
= isl_map_copy(map
);
478 map
= data
->fn(map
, isl_map_copy(entry2
->data
));
480 empty
= isl_map_is_empty(map
);
490 data
->res
= isl_union_map_add_map(data
->res
, map
);
495 static __isl_give isl_union_map
*match_bin_op(__isl_take isl_union_map
*umap1
,
496 __isl_take isl_union_map
*umap2
,
497 __isl_give isl_map
*(*fn
)(__isl_take isl_map
*, __isl_take isl_map
*))
499 struct isl_union_map_match_bin_data data
= { NULL
, NULL
, fn
};
501 umap1
= isl_union_map_align_params(umap1
, isl_union_map_get_dim(umap2
));
502 umap2
= isl_union_map_align_params(umap2
, isl_union_map_get_dim(umap1
));
504 if (!umap1
|| !umap2
)
508 data
.res
= isl_union_map_alloc(isl_dim_copy(umap1
->dim
),
510 if (isl_hash_table_foreach(umap1
->dim
->ctx
, &umap1
->table
,
511 &match_bin_entry
, &data
) < 0)
514 isl_union_map_free(umap1
);
515 isl_union_map_free(umap2
);
518 isl_union_map_free(umap1
);
519 isl_union_map_free(umap2
);
520 isl_union_map_free(data
.res
);
524 __isl_give isl_union_map
*isl_union_map_intersect(
525 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
527 return match_bin_op(umap1
, umap2
, &isl_map_intersect
);
530 __isl_give isl_union_set
*isl_union_set_intersect(
531 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
533 return isl_union_map_intersect(uset1
, uset2
);
536 __isl_give isl_union_map
*isl_union_map_gist(__isl_take isl_union_map
*umap
,
537 __isl_take isl_union_map
*context
)
539 return match_bin_op(umap
, context
, &isl_map_gist
);
542 __isl_give isl_union_set
*isl_union_set_gist(__isl_take isl_union_set
*uset
,
543 __isl_take isl_union_set
*context
)
545 return isl_union_map_gist(uset
, context
);
548 static int intersect_domain_entry(void **entry
, void *user
)
550 struct isl_union_map_gen_bin_data
*data
= user
;
552 struct isl_hash_table_entry
*entry2
;
554 isl_map
*map
= *entry
;
557 dim
= isl_map_get_dim(map
);
558 dim
= isl_dim_domain(dim
);
559 hash
= isl_dim_get_hash(dim
);
560 entry2
= isl_hash_table_find(data
->umap2
->dim
->ctx
, &data
->umap2
->table
,
561 hash
, &has_dim
, dim
, 0);
566 map
= isl_map_copy(map
);
567 map
= isl_map_intersect_domain(map
, isl_set_copy(entry2
->data
));
569 empty
= isl_map_is_empty(map
);
579 data
->res
= isl_union_map_add_map(data
->res
, map
);
584 __isl_give isl_union_map
*isl_union_map_intersect_domain(
585 __isl_take isl_union_map
*umap
, __isl_take isl_union_set
*uset
)
587 return gen_bin_op(umap
, uset
, &intersect_domain_entry
);
590 struct isl_union_map_bin_data
{
591 isl_union_map
*umap2
;
594 int (*fn
)(void **entry
, void *user
);
597 static int apply_range_entry(void **entry
, void *user
)
599 struct isl_union_map_bin_data
*data
= user
;
600 isl_map
*map2
= *entry
;
603 if (!isl_dim_tuple_match(data
->map
->dim
, isl_dim_out
,
604 map2
->dim
, isl_dim_in
))
607 map2
= isl_map_apply_range(isl_map_copy(data
->map
), isl_map_copy(map2
));
609 empty
= isl_map_is_empty(map2
);
619 data
->res
= isl_union_map_add_map(data
->res
, map2
);
624 static int bin_entry(void **entry
, void *user
)
626 struct isl_union_map_bin_data
*data
= user
;
627 isl_map
*map
= *entry
;
630 if (isl_hash_table_foreach(data
->umap2
->dim
->ctx
, &data
->umap2
->table
,
637 static __isl_give isl_union_map
*bin_op(__isl_take isl_union_map
*umap1
,
638 __isl_take isl_union_map
*umap2
, int (*fn
)(void **entry
, void *user
))
640 struct isl_union_map_bin_data data
= { NULL
, NULL
, NULL
, fn
};
642 umap1
= isl_union_map_align_params(umap1
, isl_union_map_get_dim(umap2
));
643 umap2
= isl_union_map_align_params(umap2
, isl_union_map_get_dim(umap1
));
645 if (!umap1
|| !umap2
)
649 data
.res
= isl_union_map_alloc(isl_dim_copy(umap1
->dim
),
651 if (isl_hash_table_foreach(umap1
->dim
->ctx
, &umap1
->table
,
652 &bin_entry
, &data
) < 0)
655 isl_union_map_free(umap1
);
656 isl_union_map_free(umap2
);
659 isl_union_map_free(umap1
);
660 isl_union_map_free(umap2
);
661 isl_union_map_free(data
.res
);
665 __isl_give isl_union_map
*isl_union_map_apply_range(
666 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
668 return bin_op(umap1
, umap2
, &apply_range_entry
);
671 __isl_give isl_union_set
*isl_union_set_apply(
672 __isl_take isl_union_set
*uset
, __isl_take isl_union_map
*umap
)
674 return isl_union_map_apply_range(uset
, umap
);
677 static int product_entry(void **entry
, void *user
)
679 struct isl_union_map_bin_data
*data
= user
;
680 isl_map
*map2
= *entry
;
682 map2
= isl_map_product(isl_map_copy(data
->map
), isl_map_copy(map2
));
684 data
->res
= isl_union_map_add_map(data
->res
, map2
);
689 __isl_give isl_union_map
*isl_union_map_product(__isl_take isl_union_map
*umap1
,
690 __isl_take isl_union_map
*umap2
)
692 return bin_op(umap1
, umap2
, &product_entry
);
695 __isl_give isl_union_set
*isl_union_set_product(__isl_take isl_union_set
*uset1
,
696 __isl_take isl_union_set
*uset2
)
698 return isl_union_map_product(uset1
, uset2
);
701 __isl_give isl_union_map
*isl_union_map_from_range(
702 __isl_take isl_union_set
*uset
)
707 __isl_give isl_union_map
*isl_union_map_from_domain(
708 __isl_take isl_union_set
*uset
)
710 return isl_union_map_reverse(isl_union_map_from_range(uset
));
713 __isl_give isl_union_map
*isl_union_map_from_domain_and_range(
714 __isl_take isl_union_set
*domain
, __isl_take isl_union_set
*range
)
716 return isl_union_map_apply_range(isl_union_map_from_domain(domain
),
717 isl_union_map_from_range(range
));
720 static __isl_give isl_union_map
*un_op(__isl_take isl_union_map
*umap
,
721 int (*fn
)(void **, void *), int cow
)
724 umap
= isl_union_map_cow(umap
);
728 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
, fn
, NULL
) < 0)
733 isl_union_map_free(umap
);
737 static int affine_entry(void **entry
, void *user
)
739 isl_map
**map
= (isl_map
**)entry
;
741 *map
= isl_map_from_basic_map(isl_map_affine_hull(*map
));
743 return *map
? 0 : -1;
746 __isl_give isl_union_map
*isl_union_map_affine_hull(
747 __isl_take isl_union_map
*umap
)
749 return un_op(umap
, &affine_entry
, 1);
752 __isl_give isl_union_set
*isl_union_set_affine_hull(
753 __isl_take isl_union_set
*uset
)
755 return isl_union_map_affine_hull(uset
);
758 static int coalesce_entry(void **entry
, void *user
)
760 isl_map
**map
= (isl_map
**)entry
;
762 *map
= isl_map_coalesce(*map
);
764 return *map
? 0 : -1;
767 __isl_give isl_union_map
*isl_union_map_coalesce(
768 __isl_take isl_union_map
*umap
)
770 return un_op(umap
, &coalesce_entry
, 0);
773 __isl_give isl_union_set
*isl_union_set_coalesce(
774 __isl_take isl_union_set
*uset
)
776 return isl_union_map_coalesce(uset
);
779 static int compute_divs_entry(void **entry
, void *user
)
781 isl_map
**map
= (isl_map
**)entry
;
783 *map
= isl_map_compute_divs(*map
);
785 return *map
? 0 : -1;
788 __isl_give isl_union_map
*isl_union_map_compute_divs(
789 __isl_take isl_union_map
*umap
)
791 return un_op(umap
, &compute_divs_entry
, 0);
794 __isl_give isl_union_set
*isl_union_set_compute_divs(
795 __isl_take isl_union_set
*uset
)
797 return isl_union_map_compute_divs(uset
);
800 static int lexmin_entry(void **entry
, void *user
)
802 isl_map
**map
= (isl_map
**)entry
;
804 *map
= isl_map_lexmin(*map
);
806 return *map
? 0 : -1;
809 __isl_give isl_union_map
*isl_union_map_lexmin(
810 __isl_take isl_union_map
*umap
)
812 return un_op(umap
, &lexmin_entry
, 1);
815 __isl_give isl_union_set
*isl_union_set_lexmin(
816 __isl_take isl_union_set
*uset
)
818 return isl_union_map_lexmin(uset
);
821 static int lexmax_entry(void **entry
, void *user
)
823 isl_map
**map
= (isl_map
**)entry
;
825 *map
= isl_map_lexmax(*map
);
827 return *map
? 0 : -1;
830 __isl_give isl_union_map
*isl_union_map_lexmax(
831 __isl_take isl_union_map
*umap
)
833 return un_op(umap
, &lexmax_entry
, 1);
836 __isl_give isl_union_set
*isl_union_set_lexmax(
837 __isl_take isl_union_set
*uset
)
839 return isl_union_map_lexmax(uset
);
842 static __isl_give isl_union_set
*cond_un_op(__isl_take isl_union_map
*umap
,
843 int (*fn
)(void **, void *))
850 res
= isl_union_map_alloc(isl_dim_copy(umap
->dim
), umap
->table
.n
);
851 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
, fn
, &res
) < 0)
854 isl_union_map_free(umap
);
857 isl_union_map_free(umap
);
858 isl_union_set_free(res
);
862 static int reverse_entry(void **entry
, void *user
)
864 isl_map
*map
= *entry
;
865 isl_union_map
**res
= user
;
867 *res
= isl_union_map_add_map(*res
, isl_map_reverse(isl_map_copy(map
)));
872 __isl_give isl_union_map
*isl_union_map_reverse(__isl_take isl_union_map
*umap
)
874 return cond_un_op(umap
, &reverse_entry
);
877 static int domain_entry(void **entry
, void *user
)
879 isl_map
*map
= *entry
;
880 isl_union_set
**res
= user
;
882 *res
= isl_union_set_add_set(*res
, isl_map_domain(isl_map_copy(map
)));
887 __isl_give isl_union_set
*isl_union_map_domain(__isl_take isl_union_map
*umap
)
889 return cond_un_op(umap
, &domain_entry
);
892 static int range_entry(void **entry
, void *user
)
894 isl_map
*map
= *entry
;
895 isl_union_set
**res
= user
;
897 *res
= isl_union_set_add_set(*res
, isl_map_range(isl_map_copy(map
)));
902 __isl_give isl_union_set
*isl_union_map_range(__isl_take isl_union_map
*umap
)
904 return cond_un_op(umap
, &range_entry
);
907 static int deltas_entry(void **entry
, void *user
)
909 isl_map
*map
= *entry
;
910 isl_union_set
**res
= user
;
912 if (!isl_dim_tuple_match(map
->dim
, isl_dim_in
, map
->dim
, isl_dim_out
))
915 *res
= isl_union_set_add_set(*res
, isl_map_deltas(isl_map_copy(map
)));
920 __isl_give isl_union_set
*isl_union_map_deltas(__isl_take isl_union_map
*umap
)
922 return cond_un_op(umap
, &deltas_entry
);
925 static int unwrap_entry(void **entry
, void *user
)
927 isl_set
*set
= *entry
;
928 isl_union_set
**res
= user
;
930 if (!isl_set_is_wrapping(set
))
933 *res
= isl_union_map_add_map(*res
, isl_set_unwrap(isl_set_copy(set
)));
938 __isl_give isl_union_map
*isl_union_set_unwrap(__isl_take isl_union_set
*uset
)
940 return cond_un_op(uset
, &unwrap_entry
);
943 static int wrap_entry(void **entry
, void *user
)
945 isl_map
*map
= *entry
;
946 isl_union_set
**res
= user
;
948 *res
= isl_union_set_add_set(*res
, isl_map_wrap(isl_map_copy(map
)));
953 __isl_give isl_union_set
*isl_union_map_wrap(__isl_take isl_union_map
*umap
)
955 return cond_un_op(umap
, &wrap_entry
);
958 struct isl_union_map_is_subset_data
{
959 isl_union_map
*umap2
;
963 static int is_subset_entry(void **entry
, void *user
)
965 struct isl_union_map_is_subset_data
*data
= user
;
967 struct isl_hash_table_entry
*entry2
;
968 isl_map
*map
= *entry
;
970 hash
= isl_dim_get_hash(map
->dim
);
971 entry2
= isl_hash_table_find(data
->umap2
->dim
->ctx
, &data
->umap2
->table
,
972 hash
, &has_dim
, map
->dim
, 0);
978 data
->is_subset
= isl_map_is_subset(map
, entry2
->data
);
979 if (data
->is_subset
< 0 || !data
->is_subset
)
985 int isl_union_map_is_subset(__isl_keep isl_union_map
*umap1
,
986 __isl_keep isl_union_map
*umap2
)
988 struct isl_union_map_is_subset_data data
= { NULL
, 1 };
990 umap1
= isl_union_map_copy(umap1
);
991 umap2
= isl_union_map_copy(umap2
);
992 umap1
= isl_union_map_align_params(umap1
, isl_union_map_get_dim(umap2
));
993 umap2
= isl_union_map_align_params(umap2
, isl_union_map_get_dim(umap1
));
995 if (!umap1
|| !umap2
)
999 if (isl_hash_table_foreach(umap1
->dim
->ctx
, &umap1
->table
,
1000 &is_subset_entry
, &data
) < 0 &&
1004 isl_union_map_free(umap1
);
1005 isl_union_map_free(umap2
);
1007 return data
.is_subset
;
1009 isl_union_map_free(umap1
);
1010 isl_union_map_free(umap2
);
1014 int isl_union_map_is_equal(__isl_keep isl_union_map
*umap1
,
1015 __isl_keep isl_union_map
*umap2
)
1019 if (!umap1
|| !umap2
)
1021 is_subset
= isl_union_map_is_subset(umap1
, umap2
);
1024 is_subset
= isl_union_map_is_subset(umap2
, umap1
);
1028 int isl_union_map_is_strict_subset(__isl_keep isl_union_map
*umap1
,
1029 __isl_keep isl_union_map
*umap2
)
1033 if (!umap1
|| !umap2
)
1035 is_subset
= isl_union_map_is_subset(umap1
, umap2
);
1038 is_subset
= isl_union_map_is_subset(umap2
, umap1
);
1039 if (is_subset
== -1)
1044 static int sample_entry(void **entry
, void *user
)
1046 isl_basic_map
**sample
= (isl_basic_map
**)user
;
1047 isl_map
*map
= *entry
;
1049 *sample
= isl_map_sample(isl_map_copy(map
));
1052 if (!isl_basic_map_fast_is_empty(*sample
))
1057 __isl_give isl_basic_map
*isl_union_map_sample(__isl_take isl_union_map
*umap
)
1059 isl_basic_map
*sample
= NULL
;
1064 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
,
1065 &sample_entry
, &sample
) < 0 &&
1069 isl_union_map_free(umap
);
1073 isl_union_map_free(umap
);
1077 __isl_give isl_basic_set
*isl_union_set_sample(__isl_take isl_union_set
*uset
)
1079 return (isl_basic_set
*)isl_union_map_sample(uset
);
1082 static int empty_entry(void **entry
, void *user
)
1085 isl_map
*map
= *entry
;
1087 if (isl_map_is_empty(map
))
1095 __isl_give
int isl_union_map_is_empty(__isl_keep isl_union_map
*umap
)
1102 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
,
1103 &empty_entry
, &empty
) < 0 && empty
)
1109 int isl_union_set_is_empty(__isl_keep isl_union_set
*uset
)
1111 return isl_union_map_is_empty(uset
);