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 __isl_give isl_map
*lex_le_set(__isl_take isl_map
*set1
,
549 __isl_take isl_map
*set2
)
551 return isl_set_lex_le_set((isl_set
*)set1
, (isl_set
*)set2
);
554 static __isl_give isl_map
*lex_lt_set(__isl_take isl_map
*set1
,
555 __isl_take isl_map
*set2
)
557 return isl_set_lex_lt_set((isl_set
*)set1
, (isl_set
*)set2
);
560 __isl_give isl_union_set
*isl_union_set_lex_lt_union_set(
561 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
563 return match_bin_op(uset1
, uset2
, &lex_lt_set
);
566 __isl_give isl_union_set
*isl_union_set_lex_le_union_set(
567 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
569 return match_bin_op(uset1
, uset2
, &lex_le_set
);
572 __isl_give isl_union_set
*isl_union_set_lex_gt_union_set(
573 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
575 return isl_union_set_lex_lt_union_set(uset2
, uset1
);
578 __isl_give isl_union_set
*isl_union_set_lex_ge_union_set(
579 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
581 return isl_union_set_lex_le_union_set(uset2
, uset1
);
584 __isl_give isl_union_map
*isl_union_map_lex_gt_union_map(
585 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
587 return isl_union_map_lex_lt_union_map(umap2
, umap1
);
590 __isl_give isl_union_map
*isl_union_map_lex_ge_union_map(
591 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
593 return isl_union_map_lex_le_union_map(umap2
, umap1
);
596 static int intersect_domain_entry(void **entry
, void *user
)
598 struct isl_union_map_gen_bin_data
*data
= user
;
600 struct isl_hash_table_entry
*entry2
;
602 isl_map
*map
= *entry
;
605 dim
= isl_map_get_dim(map
);
606 dim
= isl_dim_domain(dim
);
607 hash
= isl_dim_get_hash(dim
);
608 entry2
= isl_hash_table_find(data
->umap2
->dim
->ctx
, &data
->umap2
->table
,
609 hash
, &has_dim
, dim
, 0);
614 map
= isl_map_copy(map
);
615 map
= isl_map_intersect_domain(map
, isl_set_copy(entry2
->data
));
617 empty
= isl_map_is_empty(map
);
627 data
->res
= isl_union_map_add_map(data
->res
, map
);
632 __isl_give isl_union_map
*isl_union_map_intersect_domain(
633 __isl_take isl_union_map
*umap
, __isl_take isl_union_set
*uset
)
635 return gen_bin_op(umap
, uset
, &intersect_domain_entry
);
638 struct isl_union_map_bin_data
{
639 isl_union_map
*umap2
;
642 int (*fn
)(void **entry
, void *user
);
645 static int apply_range_entry(void **entry
, void *user
)
647 struct isl_union_map_bin_data
*data
= user
;
648 isl_map
*map2
= *entry
;
651 if (!isl_dim_tuple_match(data
->map
->dim
, isl_dim_out
,
652 map2
->dim
, isl_dim_in
))
655 map2
= isl_map_apply_range(isl_map_copy(data
->map
), isl_map_copy(map2
));
657 empty
= isl_map_is_empty(map2
);
667 data
->res
= isl_union_map_add_map(data
->res
, map2
);
672 static int bin_entry(void **entry
, void *user
)
674 struct isl_union_map_bin_data
*data
= user
;
675 isl_map
*map
= *entry
;
678 if (isl_hash_table_foreach(data
->umap2
->dim
->ctx
, &data
->umap2
->table
,
685 static __isl_give isl_union_map
*bin_op(__isl_take isl_union_map
*umap1
,
686 __isl_take isl_union_map
*umap2
, int (*fn
)(void **entry
, void *user
))
688 struct isl_union_map_bin_data data
= { NULL
, NULL
, NULL
, fn
};
690 umap1
= isl_union_map_align_params(umap1
, isl_union_map_get_dim(umap2
));
691 umap2
= isl_union_map_align_params(umap2
, isl_union_map_get_dim(umap1
));
693 if (!umap1
|| !umap2
)
697 data
.res
= isl_union_map_alloc(isl_dim_copy(umap1
->dim
),
699 if (isl_hash_table_foreach(umap1
->dim
->ctx
, &umap1
->table
,
700 &bin_entry
, &data
) < 0)
703 isl_union_map_free(umap1
);
704 isl_union_map_free(umap2
);
707 isl_union_map_free(umap1
);
708 isl_union_map_free(umap2
);
709 isl_union_map_free(data
.res
);
713 __isl_give isl_union_map
*isl_union_map_apply_range(
714 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
716 return bin_op(umap1
, umap2
, &apply_range_entry
);
719 __isl_give isl_union_set
*isl_union_set_apply(
720 __isl_take isl_union_set
*uset
, __isl_take isl_union_map
*umap
)
722 return isl_union_map_apply_range(uset
, umap
);
725 static int map_lex_lt_entry(void **entry
, void *user
)
727 struct isl_union_map_bin_data
*data
= user
;
728 isl_map
*map2
= *entry
;
730 if (!isl_dim_tuple_match(data
->map
->dim
, isl_dim_out
,
731 map2
->dim
, isl_dim_out
))
734 map2
= isl_map_lex_lt_map(isl_map_copy(data
->map
), isl_map_copy(map2
));
736 data
->res
= isl_union_map_add_map(data
->res
, map2
);
741 __isl_give isl_union_map
*isl_union_map_lex_lt_union_map(
742 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
744 return bin_op(umap1
, umap2
, &map_lex_lt_entry
);
747 static int map_lex_le_entry(void **entry
, void *user
)
749 struct isl_union_map_bin_data
*data
= user
;
750 isl_map
*map2
= *entry
;
752 if (!isl_dim_tuple_match(data
->map
->dim
, isl_dim_out
,
753 map2
->dim
, isl_dim_out
))
756 map2
= isl_map_lex_le_map(isl_map_copy(data
->map
), isl_map_copy(map2
));
758 data
->res
= isl_union_map_add_map(data
->res
, map2
);
763 __isl_give isl_union_map
*isl_union_map_lex_le_union_map(
764 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
766 return bin_op(umap1
, umap2
, &map_lex_le_entry
);
769 static int product_entry(void **entry
, void *user
)
771 struct isl_union_map_bin_data
*data
= user
;
772 isl_map
*map2
= *entry
;
774 map2
= isl_map_product(isl_map_copy(data
->map
), isl_map_copy(map2
));
776 data
->res
= isl_union_map_add_map(data
->res
, map2
);
781 __isl_give isl_union_map
*isl_union_map_product(__isl_take isl_union_map
*umap1
,
782 __isl_take isl_union_map
*umap2
)
784 return bin_op(umap1
, umap2
, &product_entry
);
787 __isl_give isl_union_set
*isl_union_set_product(__isl_take isl_union_set
*uset1
,
788 __isl_take isl_union_set
*uset2
)
790 return isl_union_map_product(uset1
, uset2
);
793 __isl_give isl_union_map
*isl_union_map_from_range(
794 __isl_take isl_union_set
*uset
)
799 __isl_give isl_union_map
*isl_union_map_from_domain(
800 __isl_take isl_union_set
*uset
)
802 return isl_union_map_reverse(isl_union_map_from_range(uset
));
805 __isl_give isl_union_map
*isl_union_map_from_domain_and_range(
806 __isl_take isl_union_set
*domain
, __isl_take isl_union_set
*range
)
808 return isl_union_map_apply_range(isl_union_map_from_domain(domain
),
809 isl_union_map_from_range(range
));
812 static __isl_give isl_union_map
*un_op(__isl_take isl_union_map
*umap
,
813 int (*fn
)(void **, void *), int cow
)
816 umap
= isl_union_map_cow(umap
);
820 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
, fn
, NULL
) < 0)
825 isl_union_map_free(umap
);
829 static int affine_entry(void **entry
, void *user
)
831 isl_map
**map
= (isl_map
**)entry
;
833 *map
= isl_map_from_basic_map(isl_map_affine_hull(*map
));
835 return *map
? 0 : -1;
838 __isl_give isl_union_map
*isl_union_map_affine_hull(
839 __isl_take isl_union_map
*umap
)
841 return un_op(umap
, &affine_entry
, 1);
844 __isl_give isl_union_set
*isl_union_set_affine_hull(
845 __isl_take isl_union_set
*uset
)
847 return isl_union_map_affine_hull(uset
);
850 static int coalesce_entry(void **entry
, void *user
)
852 isl_map
**map
= (isl_map
**)entry
;
854 *map
= isl_map_coalesce(*map
);
856 return *map
? 0 : -1;
859 __isl_give isl_union_map
*isl_union_map_coalesce(
860 __isl_take isl_union_map
*umap
)
862 return un_op(umap
, &coalesce_entry
, 0);
865 __isl_give isl_union_set
*isl_union_set_coalesce(
866 __isl_take isl_union_set
*uset
)
868 return isl_union_map_coalesce(uset
);
871 static int compute_divs_entry(void **entry
, void *user
)
873 isl_map
**map
= (isl_map
**)entry
;
875 *map
= isl_map_compute_divs(*map
);
877 return *map
? 0 : -1;
880 __isl_give isl_union_map
*isl_union_map_compute_divs(
881 __isl_take isl_union_map
*umap
)
883 return un_op(umap
, &compute_divs_entry
, 0);
886 __isl_give isl_union_set
*isl_union_set_compute_divs(
887 __isl_take isl_union_set
*uset
)
889 return isl_union_map_compute_divs(uset
);
892 static int lexmin_entry(void **entry
, void *user
)
894 isl_map
**map
= (isl_map
**)entry
;
896 *map
= isl_map_lexmin(*map
);
898 return *map
? 0 : -1;
901 __isl_give isl_union_map
*isl_union_map_lexmin(
902 __isl_take isl_union_map
*umap
)
904 return un_op(umap
, &lexmin_entry
, 1);
907 __isl_give isl_union_set
*isl_union_set_lexmin(
908 __isl_take isl_union_set
*uset
)
910 return isl_union_map_lexmin(uset
);
913 static int lexmax_entry(void **entry
, void *user
)
915 isl_map
**map
= (isl_map
**)entry
;
917 *map
= isl_map_lexmax(*map
);
919 return *map
? 0 : -1;
922 __isl_give isl_union_map
*isl_union_map_lexmax(
923 __isl_take isl_union_map
*umap
)
925 return un_op(umap
, &lexmax_entry
, 1);
928 __isl_give isl_union_set
*isl_union_set_lexmax(
929 __isl_take isl_union_set
*uset
)
931 return isl_union_map_lexmax(uset
);
934 static __isl_give isl_union_set
*cond_un_op(__isl_take isl_union_map
*umap
,
935 int (*fn
)(void **, void *))
942 res
= isl_union_map_alloc(isl_dim_copy(umap
->dim
), umap
->table
.n
);
943 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
, fn
, &res
) < 0)
946 isl_union_map_free(umap
);
949 isl_union_map_free(umap
);
950 isl_union_set_free(res
);
954 static int reverse_entry(void **entry
, void *user
)
956 isl_map
*map
= *entry
;
957 isl_union_map
**res
= user
;
959 *res
= isl_union_map_add_map(*res
, isl_map_reverse(isl_map_copy(map
)));
964 __isl_give isl_union_map
*isl_union_map_reverse(__isl_take isl_union_map
*umap
)
966 return cond_un_op(umap
, &reverse_entry
);
969 static int domain_entry(void **entry
, void *user
)
971 isl_map
*map
= *entry
;
972 isl_union_set
**res
= user
;
974 *res
= isl_union_set_add_set(*res
, isl_map_domain(isl_map_copy(map
)));
979 __isl_give isl_union_set
*isl_union_map_domain(__isl_take isl_union_map
*umap
)
981 return cond_un_op(umap
, &domain_entry
);
984 static int range_entry(void **entry
, void *user
)
986 isl_map
*map
= *entry
;
987 isl_union_set
**res
= user
;
989 *res
= isl_union_set_add_set(*res
, isl_map_range(isl_map_copy(map
)));
994 __isl_give isl_union_set
*isl_union_map_range(__isl_take isl_union_map
*umap
)
996 return cond_un_op(umap
, &range_entry
);
999 static int deltas_entry(void **entry
, void *user
)
1001 isl_map
*map
= *entry
;
1002 isl_union_set
**res
= user
;
1004 if (!isl_dim_tuple_match(map
->dim
, isl_dim_in
, map
->dim
, isl_dim_out
))
1007 *res
= isl_union_set_add_set(*res
, isl_map_deltas(isl_map_copy(map
)));
1012 __isl_give isl_union_set
*isl_union_map_deltas(__isl_take isl_union_map
*umap
)
1014 return cond_un_op(umap
, &deltas_entry
);
1017 static int unwrap_entry(void **entry
, void *user
)
1019 isl_set
*set
= *entry
;
1020 isl_union_set
**res
= user
;
1022 if (!isl_set_is_wrapping(set
))
1025 *res
= isl_union_map_add_map(*res
, isl_set_unwrap(isl_set_copy(set
)));
1030 __isl_give isl_union_map
*isl_union_set_unwrap(__isl_take isl_union_set
*uset
)
1032 return cond_un_op(uset
, &unwrap_entry
);
1035 static int wrap_entry(void **entry
, void *user
)
1037 isl_map
*map
= *entry
;
1038 isl_union_set
**res
= user
;
1040 *res
= isl_union_set_add_set(*res
, isl_map_wrap(isl_map_copy(map
)));
1045 __isl_give isl_union_set
*isl_union_map_wrap(__isl_take isl_union_map
*umap
)
1047 return cond_un_op(umap
, &wrap_entry
);
1050 struct isl_union_map_is_subset_data
{
1051 isl_union_map
*umap2
;
1055 static int is_subset_entry(void **entry
, void *user
)
1057 struct isl_union_map_is_subset_data
*data
= user
;
1059 struct isl_hash_table_entry
*entry2
;
1060 isl_map
*map
= *entry
;
1062 hash
= isl_dim_get_hash(map
->dim
);
1063 entry2
= isl_hash_table_find(data
->umap2
->dim
->ctx
, &data
->umap2
->table
,
1064 hash
, &has_dim
, map
->dim
, 0);
1066 data
->is_subset
= 0;
1070 data
->is_subset
= isl_map_is_subset(map
, entry2
->data
);
1071 if (data
->is_subset
< 0 || !data
->is_subset
)
1077 int isl_union_map_is_subset(__isl_keep isl_union_map
*umap1
,
1078 __isl_keep isl_union_map
*umap2
)
1080 struct isl_union_map_is_subset_data data
= { NULL
, 1 };
1082 umap1
= isl_union_map_copy(umap1
);
1083 umap2
= isl_union_map_copy(umap2
);
1084 umap1
= isl_union_map_align_params(umap1
, isl_union_map_get_dim(umap2
));
1085 umap2
= isl_union_map_align_params(umap2
, isl_union_map_get_dim(umap1
));
1087 if (!umap1
|| !umap2
)
1091 if (isl_hash_table_foreach(umap1
->dim
->ctx
, &umap1
->table
,
1092 &is_subset_entry
, &data
) < 0 &&
1096 isl_union_map_free(umap1
);
1097 isl_union_map_free(umap2
);
1099 return data
.is_subset
;
1101 isl_union_map_free(umap1
);
1102 isl_union_map_free(umap2
);
1106 int isl_union_map_is_equal(__isl_keep isl_union_map
*umap1
,
1107 __isl_keep isl_union_map
*umap2
)
1111 if (!umap1
|| !umap2
)
1113 is_subset
= isl_union_map_is_subset(umap1
, umap2
);
1116 is_subset
= isl_union_map_is_subset(umap2
, umap1
);
1120 int isl_union_map_is_strict_subset(__isl_keep isl_union_map
*umap1
,
1121 __isl_keep isl_union_map
*umap2
)
1125 if (!umap1
|| !umap2
)
1127 is_subset
= isl_union_map_is_subset(umap1
, umap2
);
1130 is_subset
= isl_union_map_is_subset(umap2
, umap1
);
1131 if (is_subset
== -1)
1136 static int sample_entry(void **entry
, void *user
)
1138 isl_basic_map
**sample
= (isl_basic_map
**)user
;
1139 isl_map
*map
= *entry
;
1141 *sample
= isl_map_sample(isl_map_copy(map
));
1144 if (!isl_basic_map_fast_is_empty(*sample
))
1149 __isl_give isl_basic_map
*isl_union_map_sample(__isl_take isl_union_map
*umap
)
1151 isl_basic_map
*sample
= NULL
;
1156 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
,
1157 &sample_entry
, &sample
) < 0 &&
1161 isl_union_map_free(umap
);
1165 isl_union_map_free(umap
);
1169 __isl_give isl_basic_set
*isl_union_set_sample(__isl_take isl_union_set
*uset
)
1171 return (isl_basic_set
*)isl_union_map_sample(uset
);
1174 static int empty_entry(void **entry
, void *user
)
1177 isl_map
*map
= *entry
;
1179 if (isl_map_is_empty(map
))
1187 __isl_give
int isl_union_map_is_empty(__isl_keep isl_union_map
*umap
)
1194 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
,
1195 &empty_entry
, &empty
) < 0 && empty
)
1201 int isl_union_set_is_empty(__isl_keep isl_union_set
*uset
)
1203 return isl_union_map_is_empty(uset
);