isl_pw_*_un_op: use isl_pw_*_{take,restore}_base_at
[isl.git] / isl_pw_move_dims_templ.c
blob58e5cd6ab1c274c336b96e517aea98b7efba4d4b
1 /*
2 * Copyright 2010 INRIA Saclay
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
8 * 91893 Orsay, France
9 */
11 __isl_give PW *FN(PW,move_dims)(__isl_take PW *pw,
12 enum isl_dim_type dst_type, unsigned dst_pos,
13 enum isl_dim_type src_type, unsigned src_pos, unsigned n)
15 int i;
16 isl_size n_piece;
17 isl_space *space;
19 space = FN(PW,take_space)(pw);
20 space = isl_space_move_dims(space, dst_type, dst_pos,
21 src_type, src_pos, n);
22 pw = FN(PW,restore_space)(pw, space);
24 pw = FN(PW,cow)(pw);
25 n_piece = FN(PW,n_piece)(pw);
26 if (n_piece < 0)
27 return FN(PW,free)(pw);
29 for (i = 0; i < n_piece; ++i) {
30 EL *el;
32 el = FN(PW,take_base_at)(pw, i);
33 el = FN(EL,move_dims)(el,
34 dst_type, dst_pos, src_type, src_pos, n);
35 pw = FN(PW,restore_base_at)(pw, i, el);
36 if (!pw)
37 return NULL;
40 if (dst_type == isl_dim_in)
41 dst_type = isl_dim_set;
42 if (src_type == isl_dim_in)
43 src_type = isl_dim_set;
45 for (i = 0; i < n_piece; ++i) {
46 pw->p[i].set = isl_set_move_dims(pw->p[i].set,
47 dst_type, dst_pos,
48 src_type, src_pos, n);
49 if (!pw->p[i].set)
50 goto error;
53 return pw;
54 error:
55 FN(PW,free)(pw);
56 return NULL;