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 (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
);
52 multi
->space
= isl_space_move_dims(multi
->space
, dst_type
, dst_pos
,
53 src_type
, src_pos
, n
);
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
);
62 for (i
= 0; i
< multi
->n
; ++i
) {
63 multi
->u
.p
[i
] = FN(EL
,move_dims
)(multi
->u
.p
[i
],
65 src_type
, src_pos
, n
);
67 return FN(MULTI(BASE
),free
)(multi
);