2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
5 * Use of this software is governed by the GNU LGPLv2.1 license
7 * Written by Sven Verdoolaege, K.U.Leuven, Departement
8 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
9 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
10 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
13 #include <isl_constraint.h>
15 #include "isl_map_private.h"
17 static unsigned n(struct isl_constraint
*c
, enum isl_dim_type type
)
19 return isl_basic_map_dim(c
->bmap
, type
);
22 static unsigned offset(struct isl_constraint
*c
, enum isl_dim_type type
)
24 struct isl_dim
*dim
= c
->bmap
->dim
;
26 case isl_dim_param
: return 1;
27 case isl_dim_in
: return 1 + dim
->nparam
;
28 case isl_dim_out
: return 1 + dim
->nparam
+ dim
->n_in
;
29 case isl_dim_div
: return 1 + dim
->nparam
+ dim
->n_in
+ dim
->n_out
;
34 static unsigned basic_set_offset(struct isl_basic_set
*bset
,
35 enum isl_dim_type type
)
37 struct isl_dim
*dim
= bset
->dim
;
39 case isl_dim_param
: return 1;
40 case isl_dim_in
: return 1 + dim
->nparam
;
41 case isl_dim_out
: return 1 + dim
->nparam
+ dim
->n_in
;
42 case isl_dim_div
: return 1 + dim
->nparam
+ dim
->n_in
+ dim
->n_out
;
47 struct isl_constraint
*isl_basic_map_constraint(struct isl_basic_map
*bmap
,
50 struct isl_constraint
*constraint
;
55 constraint
= isl_alloc_type(bmap
->ctx
, struct isl_constraint
);
59 constraint
->ctx
= bmap
->ctx
;
60 isl_ctx_ref(constraint
->ctx
);
62 constraint
->bmap
= bmap
;
63 constraint
->line
= line
;
67 isl_basic_map_free(bmap
);
71 struct isl_constraint
*isl_basic_set_constraint(struct isl_basic_set
*bset
,
74 return isl_basic_map_constraint((struct isl_basic_map
*)bset
, line
);
77 struct isl_constraint
*isl_equality_alloc(struct isl_dim
*dim
)
79 struct isl_basic_map
*bmap
;
84 bmap
= isl_basic_map_alloc_dim(dim
, 0, 1, 0);
88 isl_basic_map_alloc_equality(bmap
);
89 isl_seq_clr(bmap
->eq
[0], 1 + isl_basic_map_total_dim(bmap
));
90 return isl_basic_map_constraint(bmap
, &bmap
->eq
[0]);
93 struct isl_constraint
*isl_inequality_alloc(struct isl_dim
*dim
)
95 struct isl_basic_map
*bmap
;
100 bmap
= isl_basic_map_alloc_dim(dim
, 0, 0, 1);
104 isl_basic_map_alloc_inequality(bmap
);
105 isl_seq_clr(bmap
->ineq
[0], 1 + isl_basic_map_total_dim(bmap
));
106 return isl_basic_map_constraint(bmap
, &bmap
->ineq
[0]);
109 struct isl_constraint
*isl_constraint_dup(struct isl_constraint
*c
)
111 struct isl_basic_map
*bmap
;
118 eq
= c
->line
< c
->bmap
->eq
+ c
->bmap
->n_eq
;
119 i
= eq
? c
->line
- c
->bmap
->eq
: c
->line
- c
->bmap
->ineq
;
120 bmap
= isl_basic_map_copy(c
->bmap
);
123 return isl_basic_map_constraint(bmap
, eq
? bmap
->eq
+ i
: bmap
->ineq
+ i
);
126 struct isl_constraint
*isl_constraint_cow(struct isl_constraint
*c
)
134 return isl_constraint_dup(c
);
137 struct isl_constraint
*isl_constraint_copy(struct isl_constraint
*constraint
)
146 void isl_constraint_free(struct isl_constraint
*c
)
154 isl_basic_map_free(c
->bmap
);
155 isl_ctx_deref(c
->ctx
);
159 __isl_give isl_constraint
*isl_basic_map_first_constraint(
160 __isl_take isl_basic_map
*bmap
)
166 return isl_basic_map_constraint(bmap
, &bmap
->eq
[0]);
168 if (bmap
->n_ineq
> 0)
169 return isl_basic_map_constraint(bmap
, &bmap
->ineq
[0]);
171 isl_basic_map_free(bmap
);
175 __isl_give isl_constraint
*isl_basic_set_first_constraint(
176 __isl_take isl_basic_set
*bset
)
178 return isl_basic_map_first_constraint((struct isl_basic_map
*)bset
);
181 struct isl_constraint
*isl_constraint_next(struct isl_constraint
*c
)
183 c
= isl_constraint_cow(c
);
184 if (c
->line
>= c
->bmap
->eq
) {
186 if (c
->line
< c
->bmap
->eq
+ c
->bmap
->n_eq
)
188 c
->line
= c
->bmap
->ineq
;
191 if (c
->line
< c
->bmap
->ineq
+ c
->bmap
->n_ineq
)
193 isl_constraint_free(c
);
197 int isl_basic_map_foreach_constraint(__isl_keep isl_basic_map
*bmap
,
198 int (*fn
)(__isl_take isl_constraint
*c
, void *user
), void *user
)
201 struct isl_constraint
*c
;
206 isl_assert(bmap
->ctx
, ISL_F_ISSET(bmap
, ISL_BASIC_MAP_FINAL
),
209 for (i
= 0; i
< bmap
->n_eq
; ++i
) {
210 c
= isl_basic_map_constraint(isl_basic_map_copy(bmap
),
218 for (i
= 0; i
< bmap
->n_ineq
; ++i
) {
219 c
= isl_basic_map_constraint(isl_basic_map_copy(bmap
),
230 int isl_basic_set_foreach_constraint(__isl_keep isl_basic_set
*bset
,
231 int (*fn
)(__isl_take isl_constraint
*c
, void *user
), void *user
)
233 return isl_basic_map_foreach_constraint((isl_basic_map
*)bset
, fn
, user
);
236 int isl_constraint_is_equal(struct isl_constraint
*constraint1
,
237 struct isl_constraint
*constraint2
)
239 if (!constraint1
|| !constraint2
)
241 return constraint1
->bmap
== constraint2
->bmap
&&
242 constraint1
->line
== constraint2
->line
;
245 struct isl_basic_map
*isl_basic_map_add_constraint(
246 struct isl_basic_map
*bmap
, struct isl_constraint
*constraint
)
248 if (!bmap
|| !constraint
)
251 isl_assert(constraint
->ctx
,
252 isl_dim_equal(bmap
->dim
, constraint
->bmap
->dim
), goto error
);
254 bmap
= isl_basic_map_intersect(bmap
,
255 isl_basic_map_from_constraint(constraint
));
258 isl_basic_map_free(bmap
);
259 isl_constraint_free(constraint
);
263 struct isl_basic_set
*isl_basic_set_add_constraint(
264 struct isl_basic_set
*bset
, struct isl_constraint
*constraint
)
266 return (struct isl_basic_set
*)
267 isl_basic_map_add_constraint((struct isl_basic_map
*)bset
,
271 struct isl_constraint
*isl_constraint_add_div(struct isl_constraint
*constraint
,
272 struct isl_div
*div
, int *pos
)
274 if (!constraint
|| !div
)
277 isl_assert(constraint
->ctx
,
278 isl_dim_equal(div
->bmap
->dim
, constraint
->bmap
->dim
), goto error
);
279 isl_assert(constraint
->ctx
,
280 constraint
->bmap
->n_eq
+ constraint
->bmap
->n_ineq
== 1, goto error
);
282 constraint
->bmap
= isl_basic_map_cow(constraint
->bmap
);
283 constraint
->bmap
= isl_basic_map_extend_dim(constraint
->bmap
,
284 isl_dim_copy(constraint
->bmap
->dim
), 1, 0, 0);
285 if (!constraint
->bmap
)
287 constraint
->line
= &constraint
->bmap
->eq
[0];
288 *pos
= isl_basic_map_alloc_div(constraint
->bmap
);
291 isl_seq_cpy(constraint
->bmap
->div
[*pos
], div
->line
[0],
292 1 + 1 + isl_basic_map_total_dim(constraint
->bmap
));
296 isl_constraint_free(constraint
);
301 int isl_constraint_dim(struct isl_constraint
*constraint
,
302 enum isl_dim_type type
)
306 return n(constraint
, type
);
309 void isl_constraint_get_constant(struct isl_constraint
*constraint
, isl_int
*v
)
313 isl_int_set(*v
, constraint
->line
[0][0]);
316 void isl_constraint_get_coefficient(struct isl_constraint
*constraint
,
317 enum isl_dim_type type
, int pos
, isl_int
*v
)
322 isl_assert(constraint
->ctx
, pos
< n(constraint
, type
), return);
323 isl_int_set(*v
, constraint
->line
[0][offset(constraint
, type
) + pos
]);
326 struct isl_div
*isl_constraint_div(struct isl_constraint
*constraint
, int pos
)
331 isl_assert(constraint
->ctx
, pos
< n(constraint
, isl_dim_div
),
333 isl_assert(constraint
->ctx
,
334 !isl_int_is_zero(constraint
->bmap
->div
[pos
][0]), return NULL
);
335 return isl_basic_map_div(isl_basic_map_copy(constraint
->bmap
), pos
);
338 void isl_constraint_set_constant(struct isl_constraint
*constraint
, isl_int v
)
342 isl_int_set(constraint
->line
[0][0], v
);
345 void isl_constraint_set_coefficient(struct isl_constraint
*constraint
,
346 enum isl_dim_type type
, int pos
, isl_int v
)
351 isl_assert(constraint
->ctx
, pos
< n(constraint
, type
), return);
352 isl_int_set(constraint
->line
[0][offset(constraint
, type
) + pos
], v
);
355 void isl_constraint_clear(struct isl_constraint
*constraint
)
361 total
= isl_basic_map_total_dim(constraint
->bmap
);
362 isl_seq_clr(constraint
->line
[0], 1 + total
);
365 struct isl_constraint
*isl_constraint_negate(struct isl_constraint
*constraint
)
372 isl_assert(constraint
->ctx
, !isl_constraint_is_equality(constraint
),
374 isl_assert(constraint
->ctx
, constraint
->bmap
->ref
== 1, goto error
);
375 total
= isl_basic_map_total_dim(constraint
->bmap
);
376 isl_seq_neg(constraint
->line
[0], constraint
->line
[0], 1 + total
);
377 isl_int_sub_ui(constraint
->line
[0][0], constraint
->line
[0][0], 1);
378 ISL_F_CLR(constraint
->bmap
, ISL_BASIC_MAP_NORMALIZED
);
381 isl_constraint_free(constraint
);
385 int isl_constraint_is_equality(struct isl_constraint
*constraint
)
389 return constraint
->line
>= constraint
->bmap
->eq
;
392 __isl_give isl_basic_map
*isl_basic_map_from_constraint(
393 __isl_take isl_constraint
*constraint
)
396 struct isl_basic_map
*bmap
;
403 if (constraint
->bmap
->n_eq
+ constraint
->bmap
->n_ineq
== 1) {
404 bmap
= isl_basic_map_copy(constraint
->bmap
);
405 isl_constraint_free(constraint
);
409 bmap
= isl_basic_map_universe_like(constraint
->bmap
);
410 bmap
= isl_basic_map_align_divs(bmap
, constraint
->bmap
);
411 bmap
= isl_basic_map_cow(bmap
);
412 bmap
= isl_basic_map_extend_constraints(bmap
, 1, 1);
413 if (isl_constraint_is_equality(constraint
)) {
414 k
= isl_basic_map_alloc_equality(bmap
);
420 k
= isl_basic_map_alloc_inequality(bmap
);
425 total
= isl_basic_map_total_dim(bmap
);
426 isl_seq_cpy(c
, constraint
->line
[0], 1 + total
);
427 isl_constraint_free(constraint
);
428 bmap
= isl_basic_map_finalize(bmap
);
431 isl_constraint_free(constraint
);
432 isl_basic_map_free(bmap
);
436 struct isl_basic_set
*isl_basic_set_from_constraint(
437 struct isl_constraint
*constraint
)
442 isl_assert(constraint
->ctx
,n(constraint
, isl_dim_in
) == 0, goto error
);
443 return (isl_basic_set
*)isl_basic_map_from_constraint(constraint
);
445 isl_constraint_free(constraint
);
449 int isl_basic_set_has_defining_equality(
450 struct isl_basic_set
*bset
, enum isl_dim_type type
, int pos
,
451 struct isl_constraint
**c
)
459 offset
= basic_set_offset(bset
, type
);
460 total
= isl_basic_set_total_dim(bset
);
461 isl_assert(bset
->ctx
, pos
< isl_basic_set_dim(bset
, type
), return -1);
462 for (i
= 0; i
< bset
->n_eq
; ++i
)
463 if (!isl_int_is_zero(bset
->eq
[i
][offset
+ pos
]) &&
464 isl_seq_first_non_zero(bset
->eq
[i
]+offset
+pos
+1,
465 1+total
-offset
-pos
-1) == -1) {
466 *c
= isl_basic_set_constraint(isl_basic_set_copy(bset
),
473 int isl_basic_set_has_defining_inequalities(
474 struct isl_basic_set
*bset
, enum isl_dim_type type
, int pos
,
475 struct isl_constraint
**lower
,
476 struct isl_constraint
**upper
)
482 isl_int
**lower_line
, **upper_line
;
486 offset
= basic_set_offset(bset
, type
);
487 total
= isl_basic_set_total_dim(bset
);
488 isl_assert(bset
->ctx
, pos
< isl_basic_set_dim(bset
, type
), return -1);
490 for (i
= 0; i
< bset
->n_ineq
; ++i
) {
491 if (isl_int_is_zero(bset
->ineq
[i
][offset
+ pos
]))
493 if (isl_int_is_one(bset
->ineq
[i
][offset
+ pos
]))
495 if (isl_int_is_negone(bset
->ineq
[i
][offset
+ pos
]))
497 if (isl_seq_first_non_zero(bset
->ineq
[i
]+offset
+pos
+1,
498 1+total
-offset
-pos
-1) != -1)
500 for (j
= i
+ 1; j
< bset
->n_ineq
; ++j
) {
501 if (!isl_seq_is_neg(bset
->ineq
[i
]+1, bset
->ineq
[j
]+1,
504 isl_int_add(m
, bset
->ineq
[i
][0], bset
->ineq
[j
][0]);
505 if (isl_int_abs_ge(m
, bset
->ineq
[i
][offset
+pos
]))
508 if (isl_int_is_pos(bset
->ineq
[i
][offset
+pos
])) {
509 lower_line
= &bset
->ineq
[i
];
510 upper_line
= &bset
->ineq
[j
];
512 lower_line
= &bset
->ineq
[j
];
513 upper_line
= &bset
->ineq
[i
];
515 *lower
= isl_basic_set_constraint(
516 isl_basic_set_copy(bset
), lower_line
);
517 *upper
= isl_basic_set_constraint(
518 isl_basic_set_copy(bset
), upper_line
);
529 /* Given two constraints "a" and "b" on the variable at position "abs_pos"
530 * (in "a" and "b"), add a constraint to "bset" that ensures that the
531 * bound implied by "a" is (strictly) larger than the bound implied by "b".
533 * If both constraints imply lower bounds, then this means that "a" is
534 * active in the result.
535 * If both constraints imply upper bounds, then this means that "b" is
536 * active in the result.
538 static __isl_give isl_basic_set
*add_larger_bound_constraint(
539 __isl_take isl_basic_set
*bset
, isl_int
*a
, isl_int
*b
,
540 unsigned abs_pos
, int strict
)
546 k
= isl_basic_set_alloc_inequality(bset
);
550 total
= isl_basic_set_dim(bset
, isl_dim_all
);
553 isl_int_neg(t
, b
[1 + abs_pos
]);
555 isl_seq_combine(bset
->ineq
[k
], t
, a
, a
[1 + abs_pos
], b
, 1 + abs_pos
);
556 isl_seq_combine(bset
->ineq
[k
] + 1 + abs_pos
,
557 t
, a
+ 1 + abs_pos
+ 1, a
[1 + abs_pos
], b
+ 1 + abs_pos
+ 1,
561 isl_int_sub_ui(bset
->ineq
[k
][0], bset
->ineq
[k
][0], 1);
567 isl_basic_set_free(bset
);
571 /* Add constraints to "context" that ensure that "u" is the smallest
572 * (and therefore active) upper bound on "abs_pos" in "bset" and return
573 * the resulting basic set.
575 static __isl_give isl_basic_set
*set_smallest_upper_bound(
576 __isl_keep isl_basic_set
*context
,
577 __isl_keep isl_basic_set
*bset
, unsigned abs_pos
, int n_upper
, int u
)
581 context
= isl_basic_set_copy(context
);
582 context
= isl_basic_set_cow(context
);
584 context
= isl_basic_set_extend_constraints(context
, 0, n_upper
- 1);
586 for (j
= 0; j
< bset
->n_ineq
; ++j
) {
589 if (!isl_int_is_neg(bset
->ineq
[j
][1 + abs_pos
]))
591 context
= add_larger_bound_constraint(context
,
592 bset
->ineq
[j
], bset
->ineq
[u
], abs_pos
, j
> u
);
595 context
= isl_basic_set_simplify(context
);
596 context
= isl_basic_set_finalize(context
);
601 /* Add constraints to "context" that ensure that "u" is the largest
602 * (and therefore active) upper bound on "abs_pos" in "bset" and return
603 * the resulting basic set.
605 static __isl_give isl_basic_set
*set_largest_lower_bound(
606 __isl_keep isl_basic_set
*context
,
607 __isl_keep isl_basic_set
*bset
, unsigned abs_pos
, int n_lower
, int l
)
611 context
= isl_basic_set_copy(context
);
612 context
= isl_basic_set_cow(context
);
614 context
= isl_basic_set_extend_constraints(context
, 0, n_lower
- 1);
616 for (j
= 0; j
< bset
->n_ineq
; ++j
) {
619 if (!isl_int_is_pos(bset
->ineq
[j
][1 + abs_pos
]))
621 context
= add_larger_bound_constraint(context
,
622 bset
->ineq
[l
], bset
->ineq
[j
], abs_pos
, j
> l
);
625 context
= isl_basic_set_simplify(context
);
626 context
= isl_basic_set_finalize(context
);
631 static int foreach_upper_bound(__isl_keep isl_basic_set
*bset
,
632 enum isl_dim_type type
, unsigned abs_pos
,
633 __isl_take isl_basic_set
*context
, int n_upper
,
634 int (*fn
)(__isl_take isl_constraint
*lower
,
635 __isl_take isl_constraint
*upper
,
636 __isl_take isl_basic_set
*bset
, void *user
), void *user
)
638 isl_basic_set
*context_i
;
639 isl_constraint
*upper
= NULL
;
642 for (i
= 0; i
< bset
->n_ineq
; ++i
) {
643 if (isl_int_is_zero(bset
->ineq
[i
][1 + abs_pos
]))
646 context_i
= set_smallest_upper_bound(context
, bset
,
647 abs_pos
, n_upper
, i
);
648 if (isl_basic_set_is_empty(context_i
)) {
649 isl_basic_set_free(context_i
);
652 upper
= isl_basic_set_constraint(isl_basic_set_copy(bset
),
654 if (!upper
|| !context_i
)
656 if (fn(NULL
, upper
, context_i
, user
) < 0)
660 isl_basic_set_free(context
);
662 if (i
< bset
->n_ineq
)
667 isl_constraint_free(upper
);
668 isl_basic_set_free(context_i
);
669 isl_basic_set_free(context
);
673 static int foreach_lower_bound(__isl_keep isl_basic_set
*bset
,
674 enum isl_dim_type type
, unsigned abs_pos
,
675 __isl_take isl_basic_set
*context
, int n_lower
,
676 int (*fn
)(__isl_take isl_constraint
*lower
,
677 __isl_take isl_constraint
*upper
,
678 __isl_take isl_basic_set
*bset
, void *user
), void *user
)
680 isl_basic_set
*context_i
;
681 isl_constraint
*lower
= NULL
;
684 for (i
= 0; i
< bset
->n_ineq
; ++i
) {
685 if (isl_int_is_zero(bset
->ineq
[i
][1 + abs_pos
]))
688 context_i
= set_largest_lower_bound(context
, bset
,
689 abs_pos
, n_lower
, i
);
690 if (isl_basic_set_is_empty(context_i
)) {
691 isl_basic_set_free(context_i
);
694 lower
= isl_basic_set_constraint(isl_basic_set_copy(bset
),
696 if (!lower
|| !context_i
)
698 if (fn(lower
, NULL
, context_i
, user
) < 0)
702 isl_basic_set_free(context
);
704 if (i
< bset
->n_ineq
)
709 isl_constraint_free(lower
);
710 isl_basic_set_free(context_i
);
711 isl_basic_set_free(context
);
715 static int foreach_bound_pair(__isl_keep isl_basic_set
*bset
,
716 enum isl_dim_type type
, unsigned abs_pos
,
717 __isl_take isl_basic_set
*context
, int n_lower
, int n_upper
,
718 int (*fn
)(__isl_take isl_constraint
*lower
,
719 __isl_take isl_constraint
*upper
,
720 __isl_take isl_basic_set
*bset
, void *user
), void *user
)
722 isl_basic_set
*context_i
, *context_j
;
723 isl_constraint
*lower
= NULL
;
724 isl_constraint
*upper
= NULL
;
727 for (i
= 0; i
< bset
->n_ineq
; ++i
) {
728 if (!isl_int_is_pos(bset
->ineq
[i
][1 + abs_pos
]))
731 context_i
= set_largest_lower_bound(context
, bset
,
732 abs_pos
, n_lower
, i
);
733 if (isl_basic_set_is_empty(context_i
)) {
734 isl_basic_set_free(context_i
);
738 for (j
= 0; j
< bset
->n_ineq
; ++j
) {
739 if (!isl_int_is_neg(bset
->ineq
[j
][1 + abs_pos
]))
742 context_j
= set_smallest_upper_bound(context_i
, bset
,
743 abs_pos
, n_upper
, j
);
744 context_j
= isl_basic_set_extend_constraints(context_j
,
746 context_j
= add_larger_bound_constraint(context_j
,
747 bset
->ineq
[i
], bset
->ineq
[j
], abs_pos
, 0);
748 context_j
= isl_basic_set_simplify(context_j
);
749 context_j
= isl_basic_set_finalize(context_j
);
750 if (isl_basic_set_is_empty(context_j
)) {
751 isl_basic_set_free(context_j
);
754 lower
= isl_basic_set_constraint(isl_basic_set_copy(bset
),
756 upper
= isl_basic_set_constraint(isl_basic_set_copy(bset
),
758 if (!lower
|| !upper
|| !context_j
)
760 if (fn(lower
, upper
, context_j
, user
) < 0)
764 isl_basic_set_free(context_i
);
766 if (j
< bset
->n_ineq
)
770 isl_basic_set_free(context
);
772 if (i
< bset
->n_ineq
)
777 isl_constraint_free(lower
);
778 isl_constraint_free(upper
);
779 isl_basic_set_free(context_i
);
780 isl_basic_set_free(context_j
);
781 isl_basic_set_free(context
);
785 /* For each pair of lower and upper bounds on the variable "pos"
786 * of type "type", call "fn" with these lower and upper bounds and the
787 * set of constraints on the remaining variables where these bounds
788 * are active, i.e., (stricly) larger/smaller than the other lower/upper bounds.
790 * If the designated variable is equal to an affine combination of the
791 * other variables then fn is called with both lower and upper
792 * set to the corresponding equality.
794 * If there is no lower (or upper) bound, then NULL is passed
795 * as the corresponding bound.
797 * We first check if the variable is involved in any equality.
798 * If not, we count the number of lower and upper bounds and
801 int isl_basic_set_foreach_bound_pair(__isl_keep isl_basic_set
*bset
,
802 enum isl_dim_type type
, unsigned pos
,
803 int (*fn
)(__isl_take isl_constraint
*lower
,
804 __isl_take isl_constraint
*upper
,
805 __isl_take isl_basic_set
*bset
, void *user
), void *user
)
808 isl_constraint
*lower
= NULL
;
809 isl_constraint
*upper
= NULL
;
810 isl_basic_set
*context
= NULL
;
812 int n_lower
, n_upper
;
816 isl_assert(bset
->ctx
, pos
< isl_basic_set_dim(bset
, type
), return -1);
817 isl_assert(bset
->ctx
, type
== isl_dim_param
|| type
== isl_dim_set
,
821 if (type
== isl_dim_set
)
822 abs_pos
+= isl_basic_set_dim(bset
, isl_dim_param
);
824 for (i
= 0; i
< bset
->n_eq
; ++i
) {
825 if (isl_int_is_zero(bset
->eq
[i
][1 + abs_pos
]))
828 lower
= isl_basic_set_constraint(isl_basic_set_copy(bset
),
830 upper
= isl_constraint_copy(lower
);
831 context
= isl_basic_set_remove(isl_basic_set_copy(bset
),
833 if (!lower
|| !upper
|| !context
)
835 return fn(lower
, upper
, context
, user
);
840 for (i
= 0; i
< bset
->n_ineq
; ++i
) {
841 if (isl_int_is_pos(bset
->ineq
[i
][1 + abs_pos
]))
843 else if (isl_int_is_neg(bset
->ineq
[i
][1 + abs_pos
]))
847 context
= isl_basic_set_copy(bset
);
848 context
= isl_basic_set_cow(context
);
851 for (i
= context
->n_ineq
- 1; i
>= 0; --i
)
852 if (!isl_int_is_zero(context
->ineq
[i
][1 + abs_pos
]))
853 isl_basic_set_drop_inequality(context
, i
);
855 context
= isl_basic_set_drop(context
, type
, pos
, 1);
856 if (!n_lower
&& !n_upper
)
857 return fn(NULL
, NULL
, context
, user
);
859 return foreach_upper_bound(bset
, type
, abs_pos
, context
, n_upper
,
862 return foreach_lower_bound(bset
, type
, abs_pos
, context
, n_lower
,
864 return foreach_bound_pair(bset
, type
, abs_pos
, context
, n_lower
, n_upper
,
867 isl_constraint_free(lower
);
868 isl_constraint_free(upper
);
869 isl_basic_set_free(context
);