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_n_map(__isl_keep isl_union_map
*umap
)
342 return umap
? umap
->table
.n
: 0;
345 int isl_union_set_n_set(__isl_keep isl_union_set
*uset
)
347 return uset
? uset
->table
.n
: 0;
350 int isl_union_map_foreach_map(__isl_keep isl_union_map
*umap
,
351 int (*fn
)(__isl_take isl_map
*map
, void *user
), void *user
)
353 struct isl_union_map_foreach_data data
= { fn
, user
};
358 return isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
,
359 &call_on_copy
, &data
);
362 __isl_give isl_map
*isl_union_map_extract_map(__isl_keep isl_union_map
*umap
,
363 __isl_take isl_dim
*dim
)
366 struct isl_hash_table_entry
*entry
;
371 hash
= isl_dim_get_hash(dim
);
372 entry
= isl_hash_table_find(umap
->dim
->ctx
, &umap
->table
, hash
,
375 return isl_map_empty(dim
);
377 return isl_map_copy(entry
->data
);
383 __isl_give isl_set
*isl_union_set_extract_set(__isl_keep isl_union_set
*uset
,
384 __isl_take isl_dim
*dim
)
386 return (isl_set
*)isl_union_map_extract_map(uset
, dim
);
389 int isl_union_set_foreach_set(__isl_keep isl_union_set
*uset
,
390 int (*fn
)(__isl_take isl_set
*set
, void *user
), void *user
)
392 return isl_union_map_foreach_map(uset
,
393 (int(*)(__isl_take isl_map
*, void*))fn
, user
);
396 struct isl_union_set_foreach_point_data
{
397 int (*fn
)(__isl_take isl_point
*pnt
, void *user
);
401 static int foreach_point(__isl_take isl_set
*set
, void *user
)
403 struct isl_union_set_foreach_point_data
*data
= user
;
406 r
= isl_set_foreach_point(set
, data
->fn
, data
->user
);
412 int isl_union_set_foreach_point(__isl_keep isl_union_set
*uset
,
413 int (*fn
)(__isl_take isl_point
*pnt
, void *user
), void *user
)
415 struct isl_union_set_foreach_point_data data
= { fn
, user
};
416 return isl_union_set_foreach_set(uset
, &foreach_point
, &data
);
419 struct isl_union_map_gen_bin_data
{
420 isl_union_map
*umap2
;
424 static int subtract_entry(void **entry
, void *user
)
426 struct isl_union_map_gen_bin_data
*data
= user
;
428 struct isl_hash_table_entry
*entry2
;
429 isl_map
*map
= *entry
;
431 hash
= isl_dim_get_hash(map
->dim
);
432 entry2
= isl_hash_table_find(data
->umap2
->dim
->ctx
, &data
->umap2
->table
,
433 hash
, &has_dim
, map
->dim
, 0);
434 map
= isl_map_copy(map
);
437 map
= isl_map_subtract(map
, isl_map_copy(entry2
->data
));
439 empty
= isl_map_is_empty(map
);
449 data
->res
= isl_union_map_add_map(data
->res
, map
);
454 static __isl_give isl_union_map
*gen_bin_op(__isl_take isl_union_map
*umap1
,
455 __isl_take isl_union_map
*umap2
, int (*fn
)(void **, void *))
457 struct isl_union_map_gen_bin_data data
= { NULL
, NULL
};
459 umap1
= isl_union_map_align_params(umap1
, isl_union_map_get_dim(umap2
));
460 umap2
= isl_union_map_align_params(umap2
, isl_union_map_get_dim(umap1
));
462 if (!umap1
|| !umap2
)
466 data
.res
= isl_union_map_alloc(isl_dim_copy(umap1
->dim
),
468 if (isl_hash_table_foreach(umap1
->dim
->ctx
, &umap1
->table
,
472 isl_union_map_free(umap1
);
473 isl_union_map_free(umap2
);
476 isl_union_map_free(umap1
);
477 isl_union_map_free(umap2
);
478 isl_union_map_free(data
.res
);
482 __isl_give isl_union_map
*isl_union_map_subtract(
483 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
485 return gen_bin_op(umap1
, umap2
, &subtract_entry
);
488 __isl_give isl_union_set
*isl_union_set_subtract(
489 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
491 return isl_union_map_subtract(uset1
, uset2
);
494 struct isl_union_map_match_bin_data
{
495 isl_union_map
*umap2
;
497 __isl_give isl_map
*(*fn
)(__isl_take isl_map
*, __isl_take isl_map
*);
500 static int match_bin_entry(void **entry
, void *user
)
502 struct isl_union_map_match_bin_data
*data
= user
;
504 struct isl_hash_table_entry
*entry2
;
505 isl_map
*map
= *entry
;
508 hash
= isl_dim_get_hash(map
->dim
);
509 entry2
= isl_hash_table_find(data
->umap2
->dim
->ctx
, &data
->umap2
->table
,
510 hash
, &has_dim
, map
->dim
, 0);
514 map
= isl_map_copy(map
);
515 map
= data
->fn(map
, isl_map_copy(entry2
->data
));
517 empty
= isl_map_is_empty(map
);
527 data
->res
= isl_union_map_add_map(data
->res
, map
);
532 static __isl_give isl_union_map
*match_bin_op(__isl_take isl_union_map
*umap1
,
533 __isl_take isl_union_map
*umap2
,
534 __isl_give isl_map
*(*fn
)(__isl_take isl_map
*, __isl_take isl_map
*))
536 struct isl_union_map_match_bin_data data
= { NULL
, NULL
, fn
};
538 umap1
= isl_union_map_align_params(umap1
, isl_union_map_get_dim(umap2
));
539 umap2
= isl_union_map_align_params(umap2
, isl_union_map_get_dim(umap1
));
541 if (!umap1
|| !umap2
)
545 data
.res
= isl_union_map_alloc(isl_dim_copy(umap1
->dim
),
547 if (isl_hash_table_foreach(umap1
->dim
->ctx
, &umap1
->table
,
548 &match_bin_entry
, &data
) < 0)
551 isl_union_map_free(umap1
);
552 isl_union_map_free(umap2
);
555 isl_union_map_free(umap1
);
556 isl_union_map_free(umap2
);
557 isl_union_map_free(data
.res
);
561 __isl_give isl_union_map
*isl_union_map_intersect(
562 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
564 return match_bin_op(umap1
, umap2
, &isl_map_intersect
);
567 __isl_give isl_union_set
*isl_union_set_intersect(
568 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
570 return isl_union_map_intersect(uset1
, uset2
);
573 __isl_give isl_union_map
*isl_union_map_gist(__isl_take isl_union_map
*umap
,
574 __isl_take isl_union_map
*context
)
576 return match_bin_op(umap
, context
, &isl_map_gist
);
579 __isl_give isl_union_set
*isl_union_set_gist(__isl_take isl_union_set
*uset
,
580 __isl_take isl_union_set
*context
)
582 return isl_union_map_gist(uset
, context
);
585 static __isl_give isl_map
*lex_le_set(__isl_take isl_map
*set1
,
586 __isl_take isl_map
*set2
)
588 return isl_set_lex_le_set((isl_set
*)set1
, (isl_set
*)set2
);
591 static __isl_give isl_map
*lex_lt_set(__isl_take isl_map
*set1
,
592 __isl_take isl_map
*set2
)
594 return isl_set_lex_lt_set((isl_set
*)set1
, (isl_set
*)set2
);
597 __isl_give isl_union_map
*isl_union_set_lex_lt_union_set(
598 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
600 return match_bin_op(uset1
, uset2
, &lex_lt_set
);
603 __isl_give isl_union_map
*isl_union_set_lex_le_union_set(
604 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
606 return match_bin_op(uset1
, uset2
, &lex_le_set
);
609 __isl_give isl_union_map
*isl_union_set_lex_gt_union_set(
610 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
612 return isl_union_set_lex_lt_union_set(uset2
, uset1
);
615 __isl_give isl_union_map
*isl_union_set_lex_ge_union_set(
616 __isl_take isl_union_set
*uset1
, __isl_take isl_union_set
*uset2
)
618 return isl_union_set_lex_le_union_set(uset2
, uset1
);
621 __isl_give isl_union_map
*isl_union_map_lex_gt_union_map(
622 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
624 return isl_union_map_lex_lt_union_map(umap2
, umap1
);
627 __isl_give isl_union_map
*isl_union_map_lex_ge_union_map(
628 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
630 return isl_union_map_lex_le_union_map(umap2
, umap1
);
633 static int intersect_domain_entry(void **entry
, void *user
)
635 struct isl_union_map_gen_bin_data
*data
= user
;
637 struct isl_hash_table_entry
*entry2
;
639 isl_map
*map
= *entry
;
642 dim
= isl_map_get_dim(map
);
643 dim
= isl_dim_domain(dim
);
644 hash
= isl_dim_get_hash(dim
);
645 entry2
= isl_hash_table_find(data
->umap2
->dim
->ctx
, &data
->umap2
->table
,
646 hash
, &has_dim
, dim
, 0);
651 map
= isl_map_copy(map
);
652 map
= isl_map_intersect_domain(map
, isl_set_copy(entry2
->data
));
654 empty
= isl_map_is_empty(map
);
664 data
->res
= isl_union_map_add_map(data
->res
, map
);
669 __isl_give isl_union_map
*isl_union_map_intersect_domain(
670 __isl_take isl_union_map
*umap
, __isl_take isl_union_set
*uset
)
672 return gen_bin_op(umap
, uset
, &intersect_domain_entry
);
675 struct isl_union_map_bin_data
{
676 isl_union_map
*umap2
;
679 int (*fn
)(void **entry
, void *user
);
682 static int apply_range_entry(void **entry
, void *user
)
684 struct isl_union_map_bin_data
*data
= user
;
685 isl_map
*map2
= *entry
;
688 if (!isl_dim_tuple_match(data
->map
->dim
, isl_dim_out
,
689 map2
->dim
, isl_dim_in
))
692 map2
= isl_map_apply_range(isl_map_copy(data
->map
), isl_map_copy(map2
));
694 empty
= isl_map_is_empty(map2
);
704 data
->res
= isl_union_map_add_map(data
->res
, map2
);
709 static int bin_entry(void **entry
, void *user
)
711 struct isl_union_map_bin_data
*data
= user
;
712 isl_map
*map
= *entry
;
715 if (isl_hash_table_foreach(data
->umap2
->dim
->ctx
, &data
->umap2
->table
,
722 static __isl_give isl_union_map
*bin_op(__isl_take isl_union_map
*umap1
,
723 __isl_take isl_union_map
*umap2
, int (*fn
)(void **entry
, void *user
))
725 struct isl_union_map_bin_data data
= { NULL
, NULL
, NULL
, fn
};
727 umap1
= isl_union_map_align_params(umap1
, isl_union_map_get_dim(umap2
));
728 umap2
= isl_union_map_align_params(umap2
, isl_union_map_get_dim(umap1
));
730 if (!umap1
|| !umap2
)
734 data
.res
= isl_union_map_alloc(isl_dim_copy(umap1
->dim
),
736 if (isl_hash_table_foreach(umap1
->dim
->ctx
, &umap1
->table
,
737 &bin_entry
, &data
) < 0)
740 isl_union_map_free(umap1
);
741 isl_union_map_free(umap2
);
744 isl_union_map_free(umap1
);
745 isl_union_map_free(umap2
);
746 isl_union_map_free(data
.res
);
750 __isl_give isl_union_map
*isl_union_map_apply_range(
751 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
753 return bin_op(umap1
, umap2
, &apply_range_entry
);
756 __isl_give isl_union_map
*isl_union_map_apply_domain(
757 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
759 umap1
= isl_union_map_reverse(umap1
);
760 umap1
= isl_union_map_apply_range(umap1
, umap2
);
761 return isl_union_map_reverse(umap1
);
764 __isl_give isl_union_set
*isl_union_set_apply(
765 __isl_take isl_union_set
*uset
, __isl_take isl_union_map
*umap
)
767 return isl_union_map_apply_range(uset
, umap
);
770 static int map_lex_lt_entry(void **entry
, void *user
)
772 struct isl_union_map_bin_data
*data
= user
;
773 isl_map
*map2
= *entry
;
775 if (!isl_dim_tuple_match(data
->map
->dim
, isl_dim_out
,
776 map2
->dim
, isl_dim_out
))
779 map2
= isl_map_lex_lt_map(isl_map_copy(data
->map
), isl_map_copy(map2
));
781 data
->res
= isl_union_map_add_map(data
->res
, map2
);
786 __isl_give isl_union_map
*isl_union_map_lex_lt_union_map(
787 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
789 return bin_op(umap1
, umap2
, &map_lex_lt_entry
);
792 static int map_lex_le_entry(void **entry
, void *user
)
794 struct isl_union_map_bin_data
*data
= user
;
795 isl_map
*map2
= *entry
;
797 if (!isl_dim_tuple_match(data
->map
->dim
, isl_dim_out
,
798 map2
->dim
, isl_dim_out
))
801 map2
= isl_map_lex_le_map(isl_map_copy(data
->map
), isl_map_copy(map2
));
803 data
->res
= isl_union_map_add_map(data
->res
, map2
);
808 __isl_give isl_union_map
*isl_union_map_lex_le_union_map(
809 __isl_take isl_union_map
*umap1
, __isl_take isl_union_map
*umap2
)
811 return bin_op(umap1
, umap2
, &map_lex_le_entry
);
814 static int product_entry(void **entry
, void *user
)
816 struct isl_union_map_bin_data
*data
= user
;
817 isl_map
*map2
= *entry
;
819 map2
= isl_map_product(isl_map_copy(data
->map
), isl_map_copy(map2
));
821 data
->res
= isl_union_map_add_map(data
->res
, map2
);
826 __isl_give isl_union_map
*isl_union_map_product(__isl_take isl_union_map
*umap1
,
827 __isl_take isl_union_map
*umap2
)
829 return bin_op(umap1
, umap2
, &product_entry
);
832 __isl_give isl_union_set
*isl_union_set_product(__isl_take isl_union_set
*uset1
,
833 __isl_take isl_union_set
*uset2
)
835 return isl_union_map_product(uset1
, uset2
);
838 __isl_give isl_union_map
*isl_union_map_from_range(
839 __isl_take isl_union_set
*uset
)
844 __isl_give isl_union_map
*isl_union_map_from_domain(
845 __isl_take isl_union_set
*uset
)
847 return isl_union_map_reverse(isl_union_map_from_range(uset
));
850 __isl_give isl_union_map
*isl_union_map_from_domain_and_range(
851 __isl_take isl_union_set
*domain
, __isl_take isl_union_set
*range
)
853 return isl_union_map_apply_range(isl_union_map_from_domain(domain
),
854 isl_union_map_from_range(range
));
857 static __isl_give isl_union_map
*un_op(__isl_take isl_union_map
*umap
,
858 int (*fn
)(void **, void *), int cow
)
861 umap
= isl_union_map_cow(umap
);
865 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
, fn
, NULL
) < 0)
870 isl_union_map_free(umap
);
874 static int affine_entry(void **entry
, void *user
)
876 isl_map
**map
= (isl_map
**)entry
;
878 *map
= isl_map_from_basic_map(isl_map_affine_hull(*map
));
880 return *map
? 0 : -1;
883 __isl_give isl_union_map
*isl_union_map_affine_hull(
884 __isl_take isl_union_map
*umap
)
886 return un_op(umap
, &affine_entry
, 1);
889 __isl_give isl_union_set
*isl_union_set_affine_hull(
890 __isl_take isl_union_set
*uset
)
892 return isl_union_map_affine_hull(uset
);
895 static int coalesce_entry(void **entry
, void *user
)
897 isl_map
**map
= (isl_map
**)entry
;
899 *map
= isl_map_coalesce(*map
);
901 return *map
? 0 : -1;
904 __isl_give isl_union_map
*isl_union_map_coalesce(
905 __isl_take isl_union_map
*umap
)
907 return un_op(umap
, &coalesce_entry
, 0);
910 __isl_give isl_union_set
*isl_union_set_coalesce(
911 __isl_take isl_union_set
*uset
)
913 return isl_union_map_coalesce(uset
);
916 static int compute_divs_entry(void **entry
, void *user
)
918 isl_map
**map
= (isl_map
**)entry
;
920 *map
= isl_map_compute_divs(*map
);
922 return *map
? 0 : -1;
925 __isl_give isl_union_map
*isl_union_map_compute_divs(
926 __isl_take isl_union_map
*umap
)
928 return un_op(umap
, &compute_divs_entry
, 0);
931 __isl_give isl_union_set
*isl_union_set_compute_divs(
932 __isl_take isl_union_set
*uset
)
934 return isl_union_map_compute_divs(uset
);
937 static int lexmin_entry(void **entry
, void *user
)
939 isl_map
**map
= (isl_map
**)entry
;
941 *map
= isl_map_lexmin(*map
);
943 return *map
? 0 : -1;
946 __isl_give isl_union_map
*isl_union_map_lexmin(
947 __isl_take isl_union_map
*umap
)
949 return un_op(umap
, &lexmin_entry
, 1);
952 __isl_give isl_union_set
*isl_union_set_lexmin(
953 __isl_take isl_union_set
*uset
)
955 return isl_union_map_lexmin(uset
);
958 static int lexmax_entry(void **entry
, void *user
)
960 isl_map
**map
= (isl_map
**)entry
;
962 *map
= isl_map_lexmax(*map
);
964 return *map
? 0 : -1;
967 __isl_give isl_union_map
*isl_union_map_lexmax(
968 __isl_take isl_union_map
*umap
)
970 return un_op(umap
, &lexmax_entry
, 1);
973 __isl_give isl_union_set
*isl_union_set_lexmax(
974 __isl_take isl_union_set
*uset
)
976 return isl_union_map_lexmax(uset
);
979 static __isl_give isl_union_set
*cond_un_op(__isl_take isl_union_map
*umap
,
980 int (*fn
)(void **, void *))
987 res
= isl_union_map_alloc(isl_dim_copy(umap
->dim
), umap
->table
.n
);
988 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
, fn
, &res
) < 0)
991 isl_union_map_free(umap
);
994 isl_union_map_free(umap
);
995 isl_union_set_free(res
);
999 static int reverse_entry(void **entry
, void *user
)
1001 isl_map
*map
= *entry
;
1002 isl_union_map
**res
= user
;
1004 *res
= isl_union_map_add_map(*res
, isl_map_reverse(isl_map_copy(map
)));
1009 __isl_give isl_union_map
*isl_union_map_reverse(__isl_take isl_union_map
*umap
)
1011 return cond_un_op(umap
, &reverse_entry
);
1014 static int domain_entry(void **entry
, void *user
)
1016 isl_map
*map
= *entry
;
1017 isl_union_set
**res
= user
;
1019 *res
= isl_union_set_add_set(*res
, isl_map_domain(isl_map_copy(map
)));
1024 __isl_give isl_union_set
*isl_union_map_domain(__isl_take isl_union_map
*umap
)
1026 return cond_un_op(umap
, &domain_entry
);
1029 static int range_entry(void **entry
, void *user
)
1031 isl_map
*map
= *entry
;
1032 isl_union_set
**res
= user
;
1034 *res
= isl_union_set_add_set(*res
, isl_map_range(isl_map_copy(map
)));
1039 __isl_give isl_union_set
*isl_union_map_range(__isl_take isl_union_map
*umap
)
1041 return cond_un_op(umap
, &range_entry
);
1044 static int domain_map_entry(void **entry
, void *user
)
1046 isl_map
*map
= *entry
;
1047 isl_union_set
**res
= user
;
1049 *res
= isl_union_map_add_map(*res
,
1050 isl_map_domain_map(isl_map_copy(map
)));
1055 __isl_give isl_union_map
*isl_union_map_domain_map(
1056 __isl_take isl_union_map
*umap
)
1058 return cond_un_op(umap
, &domain_map_entry
);
1061 static int range_map_entry(void **entry
, void *user
)
1063 isl_map
*map
= *entry
;
1064 isl_union_set
**res
= user
;
1066 *res
= isl_union_map_add_map(*res
,
1067 isl_map_range_map(isl_map_copy(map
)));
1072 __isl_give isl_union_map
*isl_union_map_range_map(
1073 __isl_take isl_union_map
*umap
)
1075 return cond_un_op(umap
, &range_map_entry
);
1078 static int deltas_entry(void **entry
, void *user
)
1080 isl_map
*map
= *entry
;
1081 isl_union_set
**res
= user
;
1083 if (!isl_dim_tuple_match(map
->dim
, isl_dim_in
, map
->dim
, isl_dim_out
))
1086 *res
= isl_union_set_add_set(*res
, isl_map_deltas(isl_map_copy(map
)));
1091 __isl_give isl_union_set
*isl_union_map_deltas(__isl_take isl_union_map
*umap
)
1093 return cond_un_op(umap
, &deltas_entry
);
1096 static int unwrap_entry(void **entry
, void *user
)
1098 isl_set
*set
= *entry
;
1099 isl_union_set
**res
= user
;
1101 if (!isl_set_is_wrapping(set
))
1104 *res
= isl_union_map_add_map(*res
, isl_set_unwrap(isl_set_copy(set
)));
1109 __isl_give isl_union_map
*isl_union_set_unwrap(__isl_take isl_union_set
*uset
)
1111 return cond_un_op(uset
, &unwrap_entry
);
1114 static int wrap_entry(void **entry
, void *user
)
1116 isl_map
*map
= *entry
;
1117 isl_union_set
**res
= user
;
1119 *res
= isl_union_set_add_set(*res
, isl_map_wrap(isl_map_copy(map
)));
1124 __isl_give isl_union_set
*isl_union_map_wrap(__isl_take isl_union_map
*umap
)
1126 return cond_un_op(umap
, &wrap_entry
);
1129 struct isl_union_map_is_subset_data
{
1130 isl_union_map
*umap2
;
1134 static int is_subset_entry(void **entry
, void *user
)
1136 struct isl_union_map_is_subset_data
*data
= user
;
1138 struct isl_hash_table_entry
*entry2
;
1139 isl_map
*map
= *entry
;
1141 hash
= isl_dim_get_hash(map
->dim
);
1142 entry2
= isl_hash_table_find(data
->umap2
->dim
->ctx
, &data
->umap2
->table
,
1143 hash
, &has_dim
, map
->dim
, 0);
1145 data
->is_subset
= 0;
1149 data
->is_subset
= isl_map_is_subset(map
, entry2
->data
);
1150 if (data
->is_subset
< 0 || !data
->is_subset
)
1156 int isl_union_map_is_subset(__isl_keep isl_union_map
*umap1
,
1157 __isl_keep isl_union_map
*umap2
)
1159 struct isl_union_map_is_subset_data data
= { NULL
, 1 };
1161 umap1
= isl_union_map_copy(umap1
);
1162 umap2
= isl_union_map_copy(umap2
);
1163 umap1
= isl_union_map_align_params(umap1
, isl_union_map_get_dim(umap2
));
1164 umap2
= isl_union_map_align_params(umap2
, isl_union_map_get_dim(umap1
));
1166 if (!umap1
|| !umap2
)
1170 if (isl_hash_table_foreach(umap1
->dim
->ctx
, &umap1
->table
,
1171 &is_subset_entry
, &data
) < 0 &&
1175 isl_union_map_free(umap1
);
1176 isl_union_map_free(umap2
);
1178 return data
.is_subset
;
1180 isl_union_map_free(umap1
);
1181 isl_union_map_free(umap2
);
1185 int isl_union_map_is_equal(__isl_keep isl_union_map
*umap1
,
1186 __isl_keep isl_union_map
*umap2
)
1190 if (!umap1
|| !umap2
)
1192 is_subset
= isl_union_map_is_subset(umap1
, umap2
);
1195 is_subset
= isl_union_map_is_subset(umap2
, umap1
);
1199 int isl_union_map_is_strict_subset(__isl_keep isl_union_map
*umap1
,
1200 __isl_keep isl_union_map
*umap2
)
1204 if (!umap1
|| !umap2
)
1206 is_subset
= isl_union_map_is_subset(umap1
, umap2
);
1209 is_subset
= isl_union_map_is_subset(umap2
, umap1
);
1210 if (is_subset
== -1)
1215 static int sample_entry(void **entry
, void *user
)
1217 isl_basic_map
**sample
= (isl_basic_map
**)user
;
1218 isl_map
*map
= *entry
;
1220 *sample
= isl_map_sample(isl_map_copy(map
));
1223 if (!isl_basic_map_fast_is_empty(*sample
))
1228 __isl_give isl_basic_map
*isl_union_map_sample(__isl_take isl_union_map
*umap
)
1230 isl_basic_map
*sample
= NULL
;
1235 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
,
1236 &sample_entry
, &sample
) < 0 &&
1240 isl_union_map_free(umap
);
1244 isl_union_map_free(umap
);
1248 __isl_give isl_basic_set
*isl_union_set_sample(__isl_take isl_union_set
*uset
)
1250 return (isl_basic_set
*)isl_union_map_sample(uset
);
1253 static int empty_entry(void **entry
, void *user
)
1256 isl_map
*map
= *entry
;
1258 if (isl_map_is_empty(map
))
1266 __isl_give
int isl_union_map_is_empty(__isl_keep isl_union_map
*umap
)
1273 if (isl_hash_table_foreach(umap
->dim
->ctx
, &umap
->table
,
1274 &empty_entry
, &empty
) < 0 && empty
)
1280 int isl_union_set_is_empty(__isl_keep isl_union_set
*uset
)
1282 return isl_union_map_is_empty(uset
);