2 * Copyright 2017 Sven Verdoolaege
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege.
9 /* These versions of the explicit domain functions are used
10 * when the multi expression may have an explicit domain.
13 #include <isl_multi_macro.h>
15 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),cow
)(__isl_take
MULTI(BASE
) *multi
);
17 /* Does "multi" have an explicit domain?
19 * An explicit domain is only available if "multi" is zero-dimensional.
21 static int FN(MULTI(BASE
),has_explicit_domain
)(__isl_keep
MULTI(BASE
) *multi
)
23 return multi
&& multi
->n
== 0;
26 /* Check that "multi" has an explicit domain.
28 static isl_stat
FN(MULTI(BASE
),check_has_explicit_domain
)(
29 __isl_keep
MULTI(BASE
) *multi
)
32 return isl_stat_error
;
33 if (!FN(MULTI(BASE
),has_explicit_domain
)(multi
))
34 isl_die(FN(MULTI(BASE
),get_ctx
)(multi
), isl_error_internal
,
35 "expression does not have an explicit domain",
36 return isl_stat_error
);
40 /* Return the explicit domain of "multi", assuming it has one.
42 static __isl_give DOM
*FN(MULTI(BASE
),get_explicit_domain
)(
43 __isl_keep
MULTI(BASE
) *multi
)
45 if (FN(MULTI(BASE
),check_has_explicit_domain
)(multi
) < 0)
47 return FN(DOM
,copy
)(multi
->u
.dom
);
50 /* Replace the explicit domain of "multi" by "dom", assuming it has one.
52 static __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),set_explicit_domain
)(
53 __isl_take
MULTI(BASE
) *multi
, __isl_take DOM
*dom
)
55 if (FN(MULTI(BASE
),check_has_explicit_domain
)(multi
) < 0)
57 multi
= FN(MULTI(BASE
),cow
)(multi
);
60 FN(DOM
,free
)(multi
->u
.dom
);
63 return FN(MULTI(BASE
),free
)(multi
);
66 FN(MULTI(BASE
),free
)(multi
);
71 /* Intersect the domain of "dst" with the explicit domain of "src".
73 static __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),intersect_explicit_domain
)(
74 __isl_take
MULTI(BASE
) *dst
, __isl_keep
MULTI(BASE
) *src
)
78 dom
= FN(MULTI(BASE
),get_explicit_domain
)(src
);
79 dst
= FN(MULTI(BASE
),intersect_domain
)(dst
, dom
);
84 /* Set the explicit domain of "dst" to that of "src".
86 static __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),copy_explicit_domain
)(
87 __isl_take
MULTI(BASE
) *dst
, __isl_keep
MULTI(BASE
) *src
)
91 dom
= FN(MULTI(BASE
),get_explicit_domain
)(src
);
92 dst
= FN(MULTI(BASE
),set_explicit_domain
)(dst
, dom
);
97 /* Align the parameters of the explicit domain of "multi" to those of "space".
99 static __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),align_explicit_domain_params
)(
100 __isl_take
MULTI(BASE
) *multi
, __isl_take isl_space
*space
)
104 dom
= FN(MULTI(BASE
),get_explicit_domain
)(multi
);
105 dom
= FN(DOM
,align_params
)(dom
, space
);
106 multi
= FN(MULTI(BASE
),set_explicit_domain
)(multi
, dom
);
111 /* Replace the space of the explicit domain of "multi" by "space",
112 * without modifying its dimension.
114 static __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),reset_explicit_domain_space
)(
115 __isl_take
MULTI(BASE
) *multi
, __isl_take isl_space
*space
)
119 dom
= FN(MULTI(BASE
),get_explicit_domain
)(multi
);
120 dom
= FN(DOM
,reset_equal_dim_space
)(dom
, space
);
121 multi
= FN(MULTI(BASE
),set_explicit_domain
)(multi
, dom
);
126 /* Free the explicit domain of "multi".
128 static void FN(MULTI(BASE
),free_explicit_domain
)(__isl_keep
MULTI(BASE
) *multi
)
130 if (FN(MULTI(BASE
),check_has_explicit_domain
)(multi
) < 0)
132 FN(DOM
,free
)(multi
->u
.dom
);
135 /* Do "multi1" and "multi2" have the same explicit domain?
137 static isl_bool
FN(MULTI(BASE
),equal_explicit_domain
)(
138 __isl_keep
MULTI(BASE
) *multi1
, __isl_keep
MULTI(BASE
) *multi2
)
143 if (FN(MULTI(BASE
),check_has_explicit_domain
)(multi1
) < 0 ||
144 FN(MULTI(BASE
),check_has_explicit_domain
)(multi2
) < 0)
145 return isl_bool_error
;
146 dom1
= FN(MULTI(BASE
),get_explicit_domain
)(multi1
);
147 dom2
= FN(MULTI(BASE
),get_explicit_domain
)(multi2
);
148 equal
= FN(DOM
,is_equal
)(dom1
, dom2
);
155 static isl_stat
FN(MULTI(BASE
),check_explicit_domain
)(
156 __isl_keep
MULTI(BASE
) *multi
) __attribute__ ((unused
));
158 /* Debugging function to check that the explicit domain of "multi"
159 * has the correct space.
161 isl_stat
FN(MULTI(BASE
),check_explicit_domain
)(__isl_keep
MULTI(BASE
) *multi
)
163 isl_space
*space1
, *space2
;
166 if (FN(MULTI(BASE
),check_has_explicit_domain
)(multi
) < 0)
167 return isl_stat_error
;
168 space1
= isl_space_domain(isl_space_copy(multi
->space
));
169 space2
= FN(DOM
,get_space
)(multi
->u
.dom
);
170 equal
= isl_space_is_equal(space1
, space2
);
171 isl_space_free(space1
);
172 isl_space_free(space2
);
174 return isl_stat_error
;
176 isl_die(FN(MULTI(BASE
),get_ctx
)(multi
), isl_error_internal
,
177 "check failed", return isl_stat_error
);