1 | /* |
2 | * Copyright 2017 Sven Verdoolaege |
3 | * |
4 | * Use of this software is governed by the MIT license |
5 | * |
6 | * Written by Sven Verdoolaege. |
7 | */ |
8 | |
9 | /* Initialize the explicit domain of "mpa". |
10 | * |
11 | * The explicit domain is initialized to a universe set |
12 | * in the domain space. |
13 | */ |
14 | static __isl_give isl_multi_pw_aff *isl_multi_pw_aff_init_explicit_domain( |
15 | __isl_take isl_multi_pw_aff *mpa) |
16 | { |
17 | if (isl_multi_pw_aff_check_has_explicit_domain(multi: mpa) < 0) |
18 | return isl_multi_pw_aff_free(multi: mpa); |
19 | mpa->u.dom = isl_set_universe(space: isl_multi_pw_aff_get_domain_space(multi: mpa)); |
20 | if (!mpa->u.dom) |
21 | return isl_multi_pw_aff_free(multi: mpa); |
22 | return mpa; |
23 | } |
24 | |
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. |
29 | */ |
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) |
34 | { |
35 | isl_space *space; |
36 | isl_set *dom; |
37 | isl_map *map; |
38 | |
39 | if (!src1 || !src2) |
40 | return FN(isl_multi_pw_aff,free)(multi: dst); |
41 | space = isl_multi_pw_aff_get_domain_space(multi: dst); |
42 | dom = isl_set_universe(space); |
43 | map = isl_set_unwrap(set: dom); |
44 | if (isl_multi_pw_aff_has_explicit_domain(multi: src1)) { |
45 | dom = isl_set_copy(set: src1->u.dom); |
46 | map = isl_map_intersect_domain(map, set: dom); |
47 | } |
48 | if (isl_multi_pw_aff_has_explicit_domain(multi: src2)) { |
49 | dom = isl_set_copy(set: src2->u.dom); |
50 | map = isl_map_intersect_range(map, set: dom); |
51 | } |
52 | dom = isl_map_wrap(map); |
53 | dst = isl_multi_pw_aff_intersect_domain(mpa: dst, domain: dom); |
54 | return dst; |
55 | } |
56 | |
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. |
60 | */ |
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) |
64 | { |
65 | if (isl_multi_pw_aff_check_has_explicit_domain(multi: mpa) < 0) |
66 | return isl_bool_error; |
67 | if (type == isl_dim_in) |
68 | type = isl_dim_set; |
69 | return isl_set_involves_dims(set: mpa->u.dom, type, first: pos, n); |
70 | } |
71 | |
72 | /* Insert "n" dimensions of type "type" at position "pos" |
73 | * of the explicit domain of "mpa". |
74 | */ |
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) |
78 | { |
79 | if (isl_multi_pw_aff_check_has_explicit_domain(multi: mpa) < 0) |
80 | return isl_multi_pw_aff_free(multi: mpa); |
81 | mpa = isl_multi_pw_aff_cow(multi: 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(set: mpa->u.dom, type, pos, n); |
87 | if (!mpa->u.dom) |
88 | return isl_multi_pw_aff_free(multi: mpa); |
89 | return mpa; |
90 | } |
91 | |
92 | /* Drop the "n" dimensions of type "type" starting at position "pos" |
93 | * of the explicit domain of "mpa". |
94 | */ |
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) |
98 | { |
99 | if (isl_multi_pw_aff_check_has_explicit_domain(multi: mpa) < 0) |
100 | return isl_multi_pw_aff_free(multi: mpa); |
101 | mpa = isl_multi_pw_aff_cow(multi: 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(set: mpa->u.dom, type, first: pos, n); |
107 | if (!mpa->u.dom) |
108 | return isl_multi_pw_aff_free(multi: mpa); |
109 | return mpa; |
110 | } |
111 | |
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". |
114 | */ |
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) |
119 | { |
120 | if (isl_multi_pw_aff_check_has_explicit_domain(multi: mpa) < 0) |
121 | return isl_multi_pw_aff_free(multi: mpa); |
122 | mpa = isl_multi_pw_aff_cow(multi: 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(set: 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(multi: mpa); |
133 | return mpa; |
134 | } |
135 | |