2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
10 #include <isl_map_private.h>
15 #include <isl_point_private.h>
16 #include <isl_vec_private.h>
18 #include <set_to_map.c>
19 #include <set_from_map.c>
21 /* Expand the constraint "c" into "v". The initial "dim" dimensions
22 * are the same, but "v" may have more divs than "c" and the divs of "c"
23 * may appear in different positions in "v".
24 * The number of divs in "c" is given by "n_div" and the mapping
25 * of divs in "c" to divs in "v" is given by "div_map".
27 * Although it shouldn't happen in practice, it is theoretically
28 * possible that two or more divs in "c" are mapped to the same div in "v".
29 * These divs are then necessarily the same, so we simply add their
32 static void expand_constraint(isl_vec
*v
, unsigned dim
,
33 isl_int
*c
, int *div_map
, unsigned n_div
)
37 isl_seq_cpy(v
->el
, c
, 1 + dim
);
38 isl_seq_clr(v
->el
+ 1 + dim
, v
->size
- (1 + dim
));
40 for (i
= 0; i
< n_div
; ++i
) {
41 int pos
= 1 + dim
+ div_map
[i
];
42 isl_int_add(v
->el
[pos
], v
->el
[pos
], c
[1 + dim
+ i
]);
46 /* Add all constraints of bmap to tab. The equalities of bmap
47 * are added as a pair of inequalities.
49 static isl_stat
tab_add_constraints(struct isl_tab
*tab
,
50 __isl_keep isl_basic_map
*bmap
, int *div_map
)
60 return isl_stat_error
;
62 tab_total
= isl_basic_map_dim(tab
->bmap
, isl_dim_all
);
63 bmap_total
= isl_basic_map_dim(bmap
, isl_dim_all
);
64 bmap_n_div
= isl_basic_map_dim(bmap
, isl_dim_div
);
65 dim
= bmap_total
- bmap_n_div
;
66 if (tab_total
< 0 || bmap_total
< 0 || bmap_n_div
< 0)
67 return isl_stat_error
;
69 if (isl_tab_extend_cons(tab
, 2 * bmap
->n_eq
+ bmap
->n_ineq
) < 0)
70 return isl_stat_error
;
72 v
= isl_vec_alloc(bmap
->ctx
, 1 + tab_total
);
74 return isl_stat_error
;
76 for (i
= 0; i
< bmap
->n_eq
; ++i
) {
77 expand_constraint(v
, dim
, bmap
->eq
[i
], div_map
, bmap_n_div
);
78 if (isl_tab_add_ineq(tab
, v
->el
) < 0)
80 isl_seq_neg(bmap
->eq
[i
], bmap
->eq
[i
], 1 + bmap_total
);
81 expand_constraint(v
, dim
, bmap
->eq
[i
], div_map
, bmap_n_div
);
82 if (isl_tab_add_ineq(tab
, v
->el
) < 0)
84 isl_seq_neg(bmap
->eq
[i
], bmap
->eq
[i
], 1 + bmap_total
);
89 for (i
= 0; i
< bmap
->n_ineq
; ++i
) {
90 expand_constraint(v
, dim
, bmap
->ineq
[i
], div_map
, bmap_n_div
);
91 if (isl_tab_add_ineq(tab
, v
->el
) < 0)
101 return isl_stat_error
;
104 /* Add a specific constraint of bmap (or its opposite) to tab.
105 * The position of the constraint is specified by "c", where
106 * the equalities of bmap are counted twice, once for the inequality
107 * that is equal to the equality, and once for its negation.
109 * Each of these constraints has been added to "tab" before by
110 * tab_add_constraints (and later removed again), so there should
111 * already be a row available for the constraint.
113 static isl_stat
tab_add_constraint(struct isl_tab
*tab
,
114 __isl_keep isl_basic_map
*bmap
, int *div_map
, int c
, int oppose
)
124 return isl_stat_error
;
126 tab_total
= isl_basic_map_dim(tab
->bmap
, isl_dim_all
);
127 bmap_total
= isl_basic_map_dim(bmap
, isl_dim_all
);
128 bmap_n_div
= isl_basic_map_dim(bmap
, isl_dim_div
);
129 dim
= bmap_total
- bmap_n_div
;
130 if (tab_total
< 0 || bmap_total
< 0 || bmap_n_div
< 0)
131 return isl_stat_error
;
133 v
= isl_vec_alloc(bmap
->ctx
, 1 + tab_total
);
135 return isl_stat_error
;
137 if (c
< 2 * bmap
->n_eq
) {
138 if ((c
% 2) != oppose
)
139 isl_seq_neg(bmap
->eq
[c
/2], bmap
->eq
[c
/2],
142 isl_int_sub_ui(bmap
->eq
[c
/2][0], bmap
->eq
[c
/2][0], 1);
143 expand_constraint(v
, dim
, bmap
->eq
[c
/2], div_map
, bmap_n_div
);
144 r
= isl_tab_add_ineq(tab
, v
->el
);
146 isl_int_add_ui(bmap
->eq
[c
/2][0], bmap
->eq
[c
/2][0], 1);
147 if ((c
% 2) != oppose
)
148 isl_seq_neg(bmap
->eq
[c
/2], bmap
->eq
[c
/2],
153 isl_seq_neg(bmap
->ineq
[c
], bmap
->ineq
[c
],
155 isl_int_sub_ui(bmap
->ineq
[c
][0], bmap
->ineq
[c
][0], 1);
157 expand_constraint(v
, dim
, bmap
->ineq
[c
], div_map
, bmap_n_div
);
158 r
= isl_tab_add_ineq(tab
, v
->el
);
160 isl_int_add_ui(bmap
->ineq
[c
][0], bmap
->ineq
[c
][0], 1);
161 isl_seq_neg(bmap
->ineq
[c
], bmap
->ineq
[c
],
170 static isl_stat
tab_add_divs(struct isl_tab
*tab
,
171 __isl_keep isl_basic_map
*bmap
, int **div_map
)
179 return isl_stat_error
;
184 *div_map
= isl_alloc_array(bmap
->ctx
, int, bmap
->n_div
);
186 return isl_stat_error
;
188 total
= isl_basic_map_dim(tab
->bmap
, isl_dim_all
);
190 return isl_stat_error
;
191 dim
= total
- tab
->bmap
->n_div
;
192 vec
= isl_vec_alloc(bmap
->ctx
, 2 + total
+ bmap
->n_div
);
194 return isl_stat_error
;
196 for (i
= 0; i
< bmap
->n_div
; ++i
) {
197 isl_seq_cpy(vec
->el
, bmap
->div
[i
], 2 + dim
);
198 isl_seq_clr(vec
->el
+ 2 + dim
, tab
->bmap
->n_div
);
199 for (j
= 0; j
< i
; ++j
)
200 isl_int_add(vec
->el
[2 + dim
+ (*div_map
)[j
]],
201 vec
->el
[2 + dim
+ (*div_map
)[j
]],
202 bmap
->div
[i
][2 + dim
+ j
]);
203 for (j
= 0; j
< tab
->bmap
->n_div
; ++j
)
204 if (isl_seq_eq(tab
->bmap
->div
[j
],
205 vec
->el
, 2 + dim
+ tab
->bmap
->n_div
))
208 if (j
== tab
->bmap
->n_div
) {
209 vec
->size
= 2 + dim
+ tab
->bmap
->n_div
;
210 if (isl_tab_add_div(tab
, vec
) < 0)
221 return isl_stat_error
;
224 /* Freeze all constraints of tableau tab.
226 static int tab_freeze_constraints(struct isl_tab
*tab
)
230 for (i
= 0; i
< tab
->n_con
; ++i
)
231 if (isl_tab_freeze_constraint(tab
, i
) < 0)
237 /* Check for redundant constraints starting at offset.
238 * Put the indices of the redundant constraints in index
239 * and return the number of redundant constraints.
241 static int n_non_redundant(isl_ctx
*ctx
, struct isl_tab
*tab
,
242 int offset
, int **index
)
245 int n_test
= tab
->n_con
- offset
;
247 if (isl_tab_detect_redundant(tab
) < 0)
253 *index
= isl_alloc_array(ctx
, int, n_test
);
257 for (n
= 0, i
= 0; i
< n_test
; ++i
) {
259 r
= isl_tab_is_redundant(tab
, offset
+ i
);
270 /* basic_map_collect_diff calls add on each of the pieces of
271 * the set difference between bmap and map until the add method
272 * return a negative value.
274 struct isl_diff_collector
{
275 isl_stat (*add
)(struct isl_diff_collector
*dc
,
276 __isl_take isl_basic_map
*bmap
);
279 /* Compute the set difference between bmap and map and call
280 * dc->add on each of the piece until this function returns
282 * Return 0 on success and -1 on error. dc->add returning
283 * a negative value is treated as an error, but the calling
284 * function can interpret the results based on the state of dc.
286 * Assumes that map has known divs.
288 * The difference is computed by a backtracking algorithm.
289 * Each level corresponds to a basic map in "map".
290 * When a node in entered for the first time, we check
291 * if the corresonding basic map intersects the current piece
292 * of "bmap". If not, we move to the next level.
293 * Otherwise, we split the current piece into as many
294 * pieces as there are non-redundant constraints of the current
295 * basic map in the intersection. Each of these pieces is
296 * handled by a child of the current node.
297 * In particular, if there are n non-redundant constraints,
298 * then for each 0 <= i < n, a piece is cut off by adding
299 * constraints 0 <= j < i and adding the opposite of constraint i.
300 * If there are no non-redundant constraints, meaning that the current
301 * piece is a subset of the current basic map, then we simply backtrack.
303 * In the leaves, we check if the remaining piece has any integer points
304 * and if so, pass it along to dc->add. As a special case, if nothing
305 * has been removed when we end up in a leaf, we simply pass along
306 * the original basic map.
308 static isl_stat
basic_map_collect_diff(__isl_take isl_basic_map
*bmap
,
309 __isl_take isl_map
*map
, struct isl_diff_collector
*dc
)
317 struct isl_tab
*tab
= NULL
;
318 struct isl_tab_undo
**snap
= NULL
;
322 int **div_map
= NULL
;
324 empty
= isl_basic_map_is_empty(bmap
);
326 isl_basic_map_free(bmap
);
328 return empty
< 0 ? isl_stat_error
: isl_stat_ok
;
331 bmap
= isl_basic_map_cow(bmap
);
332 map
= isl_map_cow(map
);
338 snap
= isl_alloc_array(map
->ctx
, struct isl_tab_undo
*, map
->n
);
339 k
= isl_alloc_array(map
->ctx
, int, map
->n
);
340 n
= isl_alloc_array(map
->ctx
, int, map
->n
);
341 index
= isl_calloc_array(map
->ctx
, int *, map
->n
);
342 div_map
= isl_calloc_array(map
->ctx
, int *, map
->n
);
343 if (!snap
|| !k
|| !n
|| !index
|| !div_map
)
346 bmap
= isl_basic_map_order_divs(bmap
);
347 map
= isl_map_order_divs(map
);
349 tab
= isl_tab_from_basic_map(bmap
, 1);
358 if (level
>= map
->n
) {
360 struct isl_basic_map
*bm
;
362 if (dc
->add(dc
, isl_basic_map_copy(bmap
)) < 0)
366 bm
= isl_basic_map_copy(tab
->bmap
);
367 bm
= isl_basic_map_cow(bm
);
368 bm
= isl_basic_map_update_from_tab(bm
, tab
);
369 bm
= isl_basic_map_simplify(bm
);
370 bm
= isl_basic_map_finalize(bm
);
371 empty
= isl_basic_map_is_empty(bm
);
373 isl_basic_map_free(bm
);
374 else if (dc
->add(dc
, bm
) < 0)
384 struct isl_tab_undo
*snap2
;
385 snap2
= isl_tab_snap(tab
);
386 if (tab_add_divs(tab
, map
->p
[level
],
387 &div_map
[level
]) < 0)
390 snap
[level
] = isl_tab_snap(tab
);
391 if (tab_freeze_constraints(tab
) < 0)
393 if (tab_add_constraints(tab
, map
->p
[level
],
399 if (isl_tab_rollback(tab
, snap2
) < 0)
405 n
[level
] = n_non_redundant(ctx
, tab
, offset
,
414 if (isl_tab_rollback(tab
, snap
[level
]) < 0)
416 if (tab_add_constraint(tab
, map
->p
[level
],
417 div_map
[level
], index
[level
][0], 1) < 0)
422 if (k
[level
] + 1 >= n
[level
]) {
426 if (isl_tab_rollback(tab
, snap
[level
]) < 0)
428 if (tab_add_constraint(tab
, map
->p
[level
],
430 index
[level
][k
[level
]], 0) < 0)
432 snap
[level
] = isl_tab_snap(tab
);
434 if (tab_add_constraint(tab
, map
->p
[level
],
436 index
[level
][k
[level
]], 1) < 0)
448 for (i
= 0; index
&& i
< map
->n
; ++i
)
451 for (i
= 0; div_map
&& i
< map
->n
; ++i
)
455 isl_basic_map_free(bmap
);
464 for (i
= 0; index
&& i
< map
->n
; ++i
)
467 for (i
= 0; div_map
&& i
< map
->n
; ++i
)
470 isl_basic_map_free(bmap
);
472 return isl_stat_error
;
475 /* A diff collector that actually collects all parts of the
476 * set difference in the field diff.
478 struct isl_subtract_diff_collector
{
479 struct isl_diff_collector dc
;
480 struct isl_map
*diff
;
483 /* isl_subtract_diff_collector callback.
485 static isl_stat
basic_map_subtract_add(struct isl_diff_collector
*dc
,
486 __isl_take isl_basic_map
*bmap
)
488 struct isl_subtract_diff_collector
*sdc
;
489 sdc
= (struct isl_subtract_diff_collector
*)dc
;
491 sdc
->diff
= isl_map_union_disjoint(sdc
->diff
,
492 isl_map_from_basic_map(bmap
));
494 return sdc
->diff
? isl_stat_ok
: isl_stat_error
;
497 /* Return the set difference between bmap and map.
499 static __isl_give isl_map
*basic_map_subtract(__isl_take isl_basic_map
*bmap
,
500 __isl_take isl_map
*map
)
502 struct isl_subtract_diff_collector sdc
;
503 sdc
.dc
.add
= &basic_map_subtract_add
;
504 sdc
.diff
= isl_map_empty(isl_basic_map_get_space(bmap
));
505 if (basic_map_collect_diff(bmap
, map
, &sdc
.dc
) < 0) {
506 isl_map_free(sdc
.diff
);
512 /* Return an empty map living in the same space as "map1" and "map2".
514 static __isl_give isl_map
*replace_pair_by_empty( __isl_take isl_map
*map1
,
515 __isl_take isl_map
*map2
)
519 space
= isl_map_get_space(map1
);
522 return isl_map_empty(space
);
525 /* Return the set difference between map1 and map2.
526 * (U_i A_i) \ (U_j B_j) is computed as U_i (A_i \ (U_j B_j))
528 * If "map1" and "map2" are obviously equal to each other,
529 * then return an empty map in the same space.
531 * If "map1" and "map2" are disjoint, then simply return "map1".
533 static __isl_give isl_map
*map_subtract( __isl_take isl_map
*map1
,
534 __isl_take isl_map
*map2
)
538 struct isl_map
*diff
;
543 isl_assert(map1
->ctx
, isl_space_is_equal(map1
->dim
, map2
->dim
), goto error
);
545 equal
= isl_map_plain_is_equal(map1
, map2
);
549 return replace_pair_by_empty(map1
, map2
);
551 disjoint
= isl_map_is_disjoint(map1
, map2
);
559 map1
= isl_map_compute_divs(map1
);
560 map2
= isl_map_compute_divs(map2
);
564 map1
= isl_map_remove_empty_parts(map1
);
565 map2
= isl_map_remove_empty_parts(map2
);
567 diff
= isl_map_empty(isl_map_get_space(map1
));
568 for (i
= 0; i
< map1
->n
; ++i
) {
570 d
= basic_map_subtract(isl_basic_map_copy(map1
->p
[i
]),
572 if (ISL_F_ISSET(map1
, ISL_MAP_DISJOINT
))
573 diff
= isl_map_union_disjoint(diff
, d
);
575 diff
= isl_map_union(diff
, d
);
588 __isl_give isl_map
*isl_map_subtract( __isl_take isl_map
*map1
,
589 __isl_take isl_map
*map2
)
591 return isl_map_align_params_map_map_and(map1
, map2
, &map_subtract
);
594 struct isl_set
*isl_set_subtract(struct isl_set
*set1
, struct isl_set
*set2
)
596 return set_from_map(isl_map_subtract(set_to_map(set1
),
600 /* Remove the elements of "dom" from the domain of "map".
602 static __isl_give isl_map
*map_subtract_domain(__isl_take isl_map
*map
,
603 __isl_take isl_set
*dom
)
608 ok
= isl_map_compatible_domain(map
, dom
);
612 isl_die(isl_set_get_ctx(dom
), isl_error_invalid
,
613 "incompatible spaces", goto error
);
615 ext_dom
= isl_map_universe(isl_map_get_space(map
));
616 ext_dom
= isl_map_intersect_domain(ext_dom
, dom
);
617 return isl_map_subtract(map
, ext_dom
);
624 __isl_give isl_map
*isl_map_subtract_domain(__isl_take isl_map
*map
,
625 __isl_take isl_set
*dom
)
627 return isl_map_align_params_map_map_and(map
, dom
, &map_subtract_domain
);
630 /* Remove the elements of "dom" from the range of "map".
632 static __isl_give isl_map
*map_subtract_range(__isl_take isl_map
*map
,
633 __isl_take isl_set
*dom
)
638 ok
= isl_map_compatible_range(map
, dom
);
642 isl_die(isl_set_get_ctx(dom
), isl_error_invalid
,
643 "incompatible spaces", goto error
);
645 ext_dom
= isl_map_universe(isl_map_get_space(map
));
646 ext_dom
= isl_map_intersect_range(ext_dom
, dom
);
647 return isl_map_subtract(map
, ext_dom
);
654 __isl_give isl_map
*isl_map_subtract_range(__isl_take isl_map
*map
,
655 __isl_take isl_set
*dom
)
657 return isl_map_align_params_map_map_and(map
, dom
, &map_subtract_range
);
660 /* A diff collector that aborts as soon as its add function is called,
661 * setting empty to 0.
663 struct isl_is_empty_diff_collector
{
664 struct isl_diff_collector dc
;
668 /* isl_is_empty_diff_collector callback.
670 static isl_stat
basic_map_is_empty_add(struct isl_diff_collector
*dc
,
671 __isl_take isl_basic_map
*bmap
)
673 struct isl_is_empty_diff_collector
*edc
;
674 edc
= (struct isl_is_empty_diff_collector
*)dc
;
676 edc
->empty
= isl_bool_false
;
678 isl_basic_map_free(bmap
);
679 return isl_stat_error
;
682 /* Check if bmap \ map is empty by computing this set difference
683 * and breaking off as soon as the difference is known to be non-empty.
685 static isl_bool
basic_map_diff_is_empty(__isl_keep isl_basic_map
*bmap
,
686 __isl_keep isl_map
*map
)
690 struct isl_is_empty_diff_collector edc
;
692 empty
= isl_basic_map_plain_is_empty(bmap
);
696 edc
.dc
.add
= &basic_map_is_empty_add
;
697 edc
.empty
= isl_bool_true
;
698 r
= basic_map_collect_diff(isl_basic_map_copy(bmap
),
699 isl_map_copy(map
), &edc
.dc
);
701 return isl_bool_false
;
703 return r
< 0 ? isl_bool_error
: isl_bool_true
;
706 /* Check if map1 \ map2 is empty by checking if the set difference is empty
707 * for each of the basic maps in map1.
709 static isl_bool
map_diff_is_empty(__isl_keep isl_map
*map1
,
710 __isl_keep isl_map
*map2
)
713 isl_bool is_empty
= isl_bool_true
;
716 return isl_bool_error
;
718 for (i
= 0; i
< map1
->n
; ++i
) {
719 is_empty
= basic_map_diff_is_empty(map1
->p
[i
], map2
);
720 if (is_empty
< 0 || !is_empty
)
727 /* Return true if "bmap" contains a single element.
729 isl_bool
isl_basic_map_plain_is_singleton(__isl_keep isl_basic_map
*bmap
)
734 return isl_bool_error
;
736 return isl_bool_false
;
738 return isl_bool_false
;
739 total
= isl_basic_map_dim(bmap
, isl_dim_all
);
741 return isl_bool_error
;
742 return bmap
->n_eq
== total
;
745 /* Return true if "map" contains a single element.
747 isl_bool
isl_map_plain_is_singleton(__isl_keep isl_map
*map
)
750 return isl_bool_error
;
752 return isl_bool_false
;
754 return isl_basic_map_plain_is_singleton(map
->p
[0]);
757 /* Given a singleton basic map, extract the single element
760 static __isl_give isl_point
*singleton_extract_point(
761 __isl_keep isl_basic_map
*bmap
)
765 struct isl_vec
*point
;
768 dim
= isl_basic_map_dim(bmap
, isl_dim_all
);
772 isl_assert(bmap
->ctx
, bmap
->n_eq
== dim
, return NULL
);
773 point
= isl_vec_alloc(bmap
->ctx
, 1 + dim
);
779 isl_int_set_si(point
->el
[0], 1);
780 for (j
= 0; j
< bmap
->n_eq
; ++j
) {
782 isl_assert(bmap
->ctx
,
783 isl_seq_first_non_zero(bmap
->eq
[j
] + 1, i
) == -1,
785 isl_assert(bmap
->ctx
,
786 isl_int_is_one(bmap
->eq
[j
][1 + i
]) ||
787 isl_int_is_negone(bmap
->eq
[j
][1 + i
]),
789 isl_assert(bmap
->ctx
,
790 isl_seq_first_non_zero(bmap
->eq
[j
]+1+i
+1, dim
-i
-1) == -1,
793 isl_int_gcd(m
, point
->el
[0], bmap
->eq
[j
][1 + i
]);
794 isl_int_divexact(m
, bmap
->eq
[j
][1 + i
], m
);
796 isl_seq_scale(point
->el
, point
->el
, m
, 1 + i
);
797 isl_int_divexact(m
, point
->el
[0], bmap
->eq
[j
][1 + i
]);
799 isl_int_mul(point
->el
[1 + i
], m
, bmap
->eq
[j
][0]);
803 return isl_point_alloc(isl_basic_map_get_space(bmap
), point
);
810 /* Return isl_bool_true if the singleton map "map1" is a subset of "map2",
811 * i.e., if the single element of "map1" is also an element of "map2".
812 * Assumes "map2" has known divs.
814 static isl_bool
map_is_singleton_subset(__isl_keep isl_map
*map1
,
815 __isl_keep isl_map
*map2
)
818 isl_bool is_subset
= isl_bool_false
;
819 struct isl_point
*point
;
822 return isl_bool_error
;
824 isl_die(isl_map_get_ctx(map1
), isl_error_invalid
,
825 "expecting single-disjunct input",
826 return isl_bool_error
);
828 point
= singleton_extract_point(map1
->p
[0]);
830 return isl_bool_error
;
832 for (i
= 0; i
< map2
->n
; ++i
) {
833 is_subset
= isl_basic_map_contains_point(map2
->p
[i
], point
);
838 isl_point_free(point
);
842 static isl_bool
map_is_subset(__isl_keep isl_map
*map1
,
843 __isl_keep isl_map
*map2
)
845 isl_bool is_subset
= isl_bool_false
;
846 isl_bool empty
, single
;
850 return isl_bool_error
;
852 if (!isl_map_has_equal_space(map1
, map2
))
853 return isl_bool_false
;
855 empty
= isl_map_is_empty(map1
);
857 return isl_bool_error
;
859 return isl_bool_true
;
861 empty
= isl_map_is_empty(map2
);
863 return isl_bool_error
;
865 return isl_bool_false
;
867 rat1
= isl_map_has_rational(map1
);
868 rat2
= isl_map_has_rational(map2
);
869 if (rat1
< 0 || rat2
< 0)
870 return isl_bool_error
;
872 return isl_bool_false
;
874 if (isl_map_plain_is_universe(map2
))
875 return isl_bool_true
;
877 single
= isl_map_plain_is_singleton(map1
);
879 return isl_bool_error
;
880 map2
= isl_map_compute_divs(isl_map_copy(map2
));
882 is_subset
= map_is_singleton_subset(map1
, map2
);
886 is_subset
= map_diff_is_empty(map1
, map2
);
892 isl_bool
isl_map_is_subset(__isl_keep isl_map
*map1
, __isl_keep isl_map
*map2
)
894 return isl_map_align_params_map_map_and_test(map1
, map2
,
898 isl_bool
isl_set_is_subset(__isl_keep isl_set
*set1
, __isl_keep isl_set
*set2
)
900 return isl_map_is_subset(set_to_map(set1
), set_to_map(set2
));
903 __isl_give isl_map
*isl_map_make_disjoint(__isl_take isl_map
*map
)
906 struct isl_subtract_diff_collector sdc
;
907 sdc
.dc
.add
= &basic_map_subtract_add
;
911 if (ISL_F_ISSET(map
, ISL_MAP_DISJOINT
))
916 map
= isl_map_compute_divs(map
);
917 map
= isl_map_remove_empty_parts(map
);
919 if (!map
|| map
->n
<= 1)
922 sdc
.diff
= isl_map_from_basic_map(isl_basic_map_copy(map
->p
[0]));
924 for (i
= 1; i
< map
->n
; ++i
) {
925 struct isl_basic_map
*bmap
= isl_basic_map_copy(map
->p
[i
]);
926 struct isl_map
*copy
= isl_map_copy(sdc
.diff
);
927 if (basic_map_collect_diff(bmap
, copy
, &sdc
.dc
) < 0) {
928 isl_map_free(sdc
.diff
);
939 __isl_give isl_set
*isl_set_make_disjoint(__isl_take isl_set
*set
)
941 return set_from_map(isl_map_make_disjoint(set_to_map(set
)));
944 __isl_give isl_map
*isl_map_complement(__isl_take isl_map
*map
)
951 universe
= isl_map_universe(isl_map_get_space(map
));
953 return isl_map_subtract(universe
, map
);
956 __isl_give isl_set
*isl_set_complement(__isl_take isl_set
*set
)
958 return isl_map_complement(set
);