2 * Copyright 2011 Leiden University. All rights reserved.
3 * Copyright 2012-2014 Ecole Normale Superieure. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials provided
15 * with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY LEIDEN UNIVERSITY ''AS IS'' AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LEIDEN UNIVERSITY OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * The views and conclusions contained in the software and documentation
30 * are those of the authors and should not be interpreted as
31 * representing official policies, either expressed or implied, of
37 /* Return the piecewise affine expression "set ? 1 : 0" defined on "dom".
39 static __isl_give isl_pw_aff
*indicator_function(__isl_take isl_set
*set
,
40 __isl_take isl_set
*dom
)
43 pa
= isl_set_indicator_function(set
);
44 pa
= isl_pw_aff_intersect_domain(pa
, isl_set_coalesce(dom
));
48 /* Return "lhs && rhs", defined on the shared definition domain.
50 __isl_give isl_pw_aff
*pet_and(__isl_take isl_pw_aff
*lhs
,
51 __isl_take isl_pw_aff
*rhs
)
56 dom
= isl_set_intersect(isl_pw_aff_domain(isl_pw_aff_copy(lhs
)),
57 isl_pw_aff_domain(isl_pw_aff_copy(rhs
)));
58 cond
= isl_set_intersect(isl_pw_aff_non_zero_set(lhs
),
59 isl_pw_aff_non_zero_set(rhs
));
60 return indicator_function(cond
, dom
);
63 /* Return "!pa", defined on the domain of "pa".
65 __isl_give isl_pw_aff
*pet_not(__isl_take isl_pw_aff
*pa
)
69 dom
= isl_pw_aff_domain(isl_pw_aff_copy(pa
));
70 cond
= isl_pw_aff_zero_set(pa
);
71 pa
= indicator_function(cond
, dom
);
76 /* Return "!!pa", i.e., a function that is equal to 1 when "pa"
77 * is non-zero and equal to 0 when "pa" is equal to zero,
78 * on the domain of "pa".
80 __isl_give isl_pw_aff
*pet_to_bool(__isl_take isl_pw_aff
*pa
)
84 dom
= isl_pw_aff_domain(isl_pw_aff_copy(pa
));
85 cond
= isl_pw_aff_non_zero_set(pa
);
86 pa
= indicator_function(cond
, dom
);
91 /* Return the result of applying the comparison operator "type"
94 * In particular, construct an isl_pw_aff that is equal to 1
95 * on the subset of the shared domain of "pa1" and "pa2" where
96 * the comparison holds and 0 on the other part of the shared domain.
98 __isl_give isl_pw_aff
*pet_comparison(enum pet_op_type type
,
99 __isl_take isl_pw_aff
*pa1
, __isl_take isl_pw_aff
*pa2
)
105 dom
= isl_pw_aff_domain(isl_pw_aff_copy(pa1
));
106 dom
= isl_set_intersect(dom
, isl_pw_aff_domain(isl_pw_aff_copy(pa2
)));
110 cond
= isl_pw_aff_lt_set(pa1
, pa2
);
113 cond
= isl_pw_aff_le_set(pa1
, pa2
);
116 cond
= isl_pw_aff_gt_set(pa1
, pa2
);
119 cond
= isl_pw_aff_ge_set(pa1
, pa2
);
122 cond
= isl_pw_aff_eq_set(pa1
, pa2
);
125 cond
= isl_pw_aff_ne_set(pa1
, pa2
);
128 isl_die(isl_pw_aff_get_ctx(pa1
), isl_error_internal
,
129 "not a comparison operator", cond
= NULL
);
130 isl_pw_aff_free(pa1
);
131 isl_pw_aff_free(pa2
);
134 cond
= isl_set_coalesce(cond
);
135 res
= indicator_function(cond
, dom
);