isl_ast_build_expr.c: add missing include
[isl.git] / isl_multi_pw_aff_explicit_domain.c
blobe9efea0bd0012437a5e8512c24c9456ba07e880b
1 /*
2 * Copyright 2017 Sven Verdoolaege
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege.
7 */
9 /* Initialize the explicit domain of "mpa".
11 * The explicit domain is initialized to a universe set
12 * in the domain space.
14 static __isl_give isl_multi_pw_aff *isl_multi_pw_aff_init_explicit_domain(
15 __isl_take isl_multi_pw_aff *mpa)
17 if (isl_multi_pw_aff_check_has_explicit_domain(mpa) < 0)
18 return isl_multi_pw_aff_free(mpa);
19 mpa->u.dom = isl_set_universe(isl_multi_pw_aff_get_domain_space(mpa));
20 if (!mpa->u.dom)
21 return isl_multi_pw_aff_free(mpa);
22 return mpa;
25 /* Intersect the domain of "dst" with the domain product
26 * of the explicit domains of "src1" and "src2".
27 * This function is only called if at least one of "src1" or "src2"
28 * has an explicit domain.
30 static __isl_give isl_multi_pw_aff *
31 isl_multi_pw_aff_intersect_explicit_domain_product(
32 __isl_take isl_multi_pw_aff *dst, __isl_keep isl_multi_pw_aff *src1,
33 __isl_keep isl_multi_pw_aff *src2)
35 isl_space *space;
36 isl_set *dom;
37 isl_map *map;
39 if (!src1 || !src2)
40 return FN(isl_multi_pw_aff,free)(dst);
41 space = isl_multi_pw_aff_get_domain_space(dst);
42 dom = isl_set_universe(space);
43 map = isl_set_unwrap(dom);
44 if (isl_multi_pw_aff_has_explicit_domain(src1)) {
45 dom = isl_set_copy(src1->u.dom);
46 map = isl_map_intersect_domain(map, dom);
48 if (isl_multi_pw_aff_has_explicit_domain(src2)) {
49 dom = isl_set_copy(src2->u.dom);
50 map = isl_map_intersect_range(map, dom);
52 dom = isl_map_wrap(map);
53 dst = isl_multi_pw_aff_intersect_domain(dst, dom);
54 return dst;
57 /* Check whether the explicit domain of "mpa" has non-zero coefficients
58 * for any dimension in the given range or if any of these dimensions appear
59 * with non-zero coefficients in any of the integer divisions involved.
61 isl_bool isl_multi_pw_aff_involves_explicit_domain_dims(
62 __isl_keep isl_multi_pw_aff *mpa,
63 enum isl_dim_type type, unsigned pos, unsigned n)
65 if (isl_multi_pw_aff_check_has_explicit_domain(mpa) < 0)
66 return isl_bool_error;
67 if (type == isl_dim_in)
68 type = isl_dim_set;
69 return isl_set_involves_dims(mpa->u.dom, type, pos, n);
72 /* Insert "n" dimensions of type "type" at position "pos"
73 * of the explicit domain of "mpa".
75 static __isl_give isl_multi_pw_aff *
76 isl_multi_pw_aff_insert_explicit_domain_dims(__isl_take isl_multi_pw_aff *mpa,
77 enum isl_dim_type type, unsigned pos, unsigned n)
79 if (isl_multi_pw_aff_check_has_explicit_domain(mpa) < 0)
80 return isl_multi_pw_aff_free(mpa);
81 mpa = isl_multi_pw_aff_cow(mpa);
82 if (!mpa)
83 return NULL;
84 if (type == isl_dim_in)
85 type = isl_dim_set;
86 mpa->u.dom = isl_set_insert_dims(mpa->u.dom, type, pos, n);
87 if (!mpa->u.dom)
88 return isl_multi_pw_aff_free(mpa);
89 return mpa;
92 /* Drop the "n" dimensions of type "type" starting at position "pos"
93 * of the explicit domain of "mpa".
95 static __isl_give isl_multi_pw_aff *
96 isl_multi_pw_aff_drop_explicit_domain_dims(__isl_take isl_multi_pw_aff *mpa,
97 enum isl_dim_type type, unsigned pos, unsigned n)
99 if (isl_multi_pw_aff_check_has_explicit_domain(mpa) < 0)
100 return isl_multi_pw_aff_free(mpa);
101 mpa = isl_multi_pw_aff_cow(mpa);
102 if (!mpa)
103 return NULL;
104 if (type == isl_dim_in)
105 type = isl_dim_set;
106 mpa->u.dom = isl_set_drop(mpa->u.dom, type, pos, n);
107 if (!mpa->u.dom)
108 return isl_multi_pw_aff_free(mpa);
109 return mpa;
112 /* Move the "n" dimensions of "src_type" starting at "src_pos" of
113 * of the explicit domain of "mpa" to dimensions of "dst_type" at "dst_pos".
115 static __isl_give isl_multi_pw_aff *isl_multi_pw_aff_move_explicit_domain_dims(
116 __isl_take isl_multi_pw_aff *mpa,
117 enum isl_dim_type dst_type, unsigned dst_pos,
118 enum isl_dim_type src_type, unsigned src_pos, unsigned n)
120 if (isl_multi_pw_aff_check_has_explicit_domain(mpa) < 0)
121 return isl_multi_pw_aff_free(mpa);
122 mpa = isl_multi_pw_aff_cow(mpa);
123 if (!mpa)
124 return NULL;
125 if (dst_type == isl_dim_in)
126 dst_type = isl_dim_set;
127 if (src_type == isl_dim_in)
128 src_type = isl_dim_set;
129 mpa->u.dom = isl_set_move_dims(mpa->u.dom, dst_type, dst_pos,
130 src_type, src_pos, n);
131 if (!mpa->u.dom)
132 return isl_multi_pw_aff_free(mpa);
133 return mpa;