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
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
)
29 !isl_space_is_named_or_nested(multi
->space
, src_type
) &&
30 !isl_space_is_named_or_nested(multi
->space
, dst_type
))
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
,
40 return FN(MULTI(BASE
),free
)(multi
));
41 if (src_pos
+ n
> isl_space_dim(multi
->space
, src_type
))
42 isl_die(FN(MULTI(BASE
),get_ctx
)(multi
), isl_error_invalid
,
43 "range out of bounds",
44 return FN(MULTI(BASE
),free
)(multi
));
45 if (dst_type
== src_type
)
46 isl_die(FN(MULTI(BASE
),get_ctx
)(multi
), isl_error_unsupported
,
47 "moving dims within the same type not supported",
48 return FN(MULTI(BASE
),free
)(multi
));
50 multi
= FN(MULTI(BASE
),cow
)(multi
);
54 multi
->space
= isl_space_move_dims(multi
->space
, dst_type
, dst_pos
,
55 src_type
, src_pos
, n
);
57 return FN(MULTI(BASE
),free
)(multi
);
58 if (FN(MULTI(BASE
),has_explicit_domain
)(multi
))
59 multi
= FN(MULTI(BASE
),move_explicit_domain_dims
)(multi
,
60 dst_type
, dst_pos
, src_type
, src_pos
, n
);
64 for (i
= 0; i
< multi
->n
; ++i
) {
65 multi
->u
.p
[i
] = FN(EL
,move_dims
)(multi
->u
.p
[i
],
67 src_type
, src_pos
, n
);
69 return FN(MULTI(BASE
),free
)(multi
);