pet_expr: keep track of type_size
[pet.git] / aff.c
blob1be2506c205a9b2a7ade57e3ae89a66c9b261b8b
1 /*
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
7 * are met:
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
32 * Leiden University.
35 #include "aff.h"
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)
42 isl_pw_aff *pa;
43 pa = isl_set_indicator_function(set);
44 pa = isl_pw_aff_intersect_domain(pa, isl_set_coalesce(dom));
45 return pa;
48 /* Return the result of applying the comparison operator "type"
49 * to "pa1" and "pa2".
51 * In particular, construct an isl_pw_aff that is equal to 1
52 * on the subset of the shared domain of "pa1" and "pa2" where
53 * the comparison holds and 0 on the other part of the shared domain.
55 __isl_give isl_pw_aff *pet_comparison(enum pet_op_type type,
56 __isl_take isl_pw_aff *pa1, __isl_take isl_pw_aff *pa2)
58 isl_set *dom;
59 isl_set *cond;
60 isl_pw_aff *res;
62 dom = isl_pw_aff_domain(isl_pw_aff_copy(pa1));
63 dom = isl_set_intersect(dom, isl_pw_aff_domain(isl_pw_aff_copy(pa2)));
65 switch (type) {
66 case pet_op_lt:
67 cond = isl_pw_aff_lt_set(pa1, pa2);
68 break;
69 case pet_op_le:
70 cond = isl_pw_aff_le_set(pa1, pa2);
71 break;
72 case pet_op_gt:
73 cond = isl_pw_aff_gt_set(pa1, pa2);
74 break;
75 case pet_op_ge:
76 cond = isl_pw_aff_ge_set(pa1, pa2);
77 break;
78 case pet_op_eq:
79 cond = isl_pw_aff_eq_set(pa1, pa2);
80 break;
81 case pet_op_ne:
82 cond = isl_pw_aff_ne_set(pa1, pa2);
83 break;
84 default:
85 isl_die(isl_pw_aff_get_ctx(pa1), isl_error_internal,
86 "not a comparison operator", cond = NULL);
87 isl_pw_aff_free(pa1);
88 isl_pw_aff_free(pa2);
91 cond = isl_set_coalesce(cond);
92 res = indicator_function(cond, dom);
94 return res;