isl_bool_not: avoid implicit enum conversion warning
[isl.git] / isl_multi_move_dims_templ.c
blob9c880857948b6979b5938b34aec5d35a76368305
1 /*
2 * Copyright 2013 Ecole Normale Superieure
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege,
7 * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
8 */
10 #include <isl/space.h>
12 #include <isl_multi_macro.h>
14 /* Move the "n" dimensions of "src_type" starting at "src_pos" of "multi"
15 * to dimensions of "dst_type" at "dst_pos".
17 * We only support moving input dimensions to parameters and vice versa.
19 __isl_give MULTI(BASE) *FN(MULTI(BASE),move_dims)(__isl_take MULTI(BASE) *multi,
20 enum isl_dim_type dst_type, unsigned dst_pos,
21 enum isl_dim_type src_type, unsigned src_pos, unsigned n)
23 int i;
25 if (!multi)
26 return NULL;
28 if (n == 0 &&
29 !isl_space_is_named_or_nested(multi->space, src_type) &&
30 !isl_space_is_named_or_nested(multi->space, dst_type))
31 return multi;
33 if (dst_type == isl_dim_out || src_type == isl_dim_out)
34 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
35 "cannot move output/set dimension",
36 return FN(MULTI(BASE),free)(multi));
37 if (dst_type == isl_dim_div || src_type == isl_dim_div)
38 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
39 "cannot move divs",
40 return FN(MULTI(BASE),free)(multi));
41 if (FN(MULTI(BASE),check_range)(multi, src_type, src_pos, n) < 0)
42 return FN(MULTI(BASE),free)(multi);
43 if (dst_type == src_type)
44 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_unsupported,
45 "moving dims within the same type not supported",
46 return FN(MULTI(BASE),free)(multi));
48 multi = FN(MULTI(BASE),cow)(multi);
49 if (!multi)
50 return NULL;
52 multi->space = isl_space_move_dims(multi->space, dst_type, dst_pos,
53 src_type, src_pos, n);
54 if (!multi->space)
55 return FN(MULTI(BASE),free)(multi);
56 if (FN(MULTI(BASE),has_explicit_domain)(multi))
57 multi = FN(MULTI(BASE),move_explicit_domain_dims)(multi,
58 dst_type, dst_pos, src_type, src_pos, n);
59 if (!multi)
60 return NULL;
62 for (i = 0; i < multi->n; ++i) {
63 multi->u.p[i] = FN(EL,move_dims)(multi->u.p[i],
64 dst_type, dst_pos,
65 src_type, src_pos, n);
66 if (!multi->u.p[i])
67 return FN(MULTI(BASE),free)(multi);
70 return multi;