2 * Copyright 2010-2011 INRIA Saclay
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
17 #include <isl/constraint.h>
21 /* Construct a map that maps a domain of dimensionality "len"
22 * to another domain of the same dimensionality such that
23 * coordinate "first" of the range is equal to the sum of the "wave_len"
24 * coordinates starting at "first" in the domain.
25 * The remaining coordinates in the range are equal to the corresponding ones
27 * "dim" prescribes the parameters.
29 __isl_give isl_map
*wavefront(__isl_take isl_space
*dim
, int len
,
30 int first
, int wave_len
)
39 dim
= isl_space_add_dims(dim
, isl_dim_in
, len
);
40 dim
= isl_space_add_dims(dim
, isl_dim_out
, len
);
41 bmap
= isl_basic_map_universe(isl_space_copy(dim
));
43 for (i
= 0; i
< len
; ++i
) {
47 c
= isl_equality_alloc(isl_space_copy(dim
));
48 isl_int_set_si(v
, -1);
49 isl_constraint_set_coefficient(c
, isl_dim_in
, i
, v
);
51 isl_constraint_set_coefficient(c
, isl_dim_out
, i
, v
);
52 bmap
= isl_basic_map_add_constraint(bmap
, c
);
55 c
= isl_equality_alloc(isl_space_copy(dim
));
56 isl_int_set_si(v
, -1);
57 for (i
= 0; i
< wave_len
; ++i
)
58 isl_constraint_set_coefficient(c
, isl_dim_in
, first
+ i
, v
);
60 isl_constraint_set_coefficient(c
, isl_dim_out
, first
, v
);
61 bmap
= isl_basic_map_add_constraint(bmap
, c
);
66 return isl_map_from_basic_map(bmap
);
69 /* Construct a map from a len-dimensional domain to
70 * a (len-n)-dimensional domain that projects out the n coordinates
72 * "dim" prescribes the parameters.
74 __isl_give isl_map
*project_out(__isl_take isl_space
*dim
,
75 int len
, int first
, int n
)
84 dim
= isl_space_add_dims(dim
, isl_dim_in
, len
);
85 dim
= isl_space_add_dims(dim
, isl_dim_out
, len
- n
);
86 bmap
= isl_basic_map_universe(isl_space_copy(dim
));
88 for (i
= 0, j
= 0; i
< len
; ++i
) {
89 if (i
>= first
&& i
< first
+ n
)
91 c
= isl_equality_alloc(isl_space_copy(dim
));
92 isl_int_set_si(v
, -1);
93 isl_constraint_set_coefficient(c
, isl_dim_in
, i
, v
);
95 isl_constraint_set_coefficient(c
, isl_dim_out
, j
, v
);
96 bmap
= isl_basic_map_add_constraint(bmap
, c
);
103 return isl_map_from_basic_map(bmap
);
106 /* Construct a projection that maps a src_len dimensional domain
107 * to its first dst_len coordinates.
108 * "dim" prescribes the parameters.
110 __isl_give isl_map
*projection(__isl_take isl_space
*dim
,
111 int src_len
, int dst_len
)
113 return project_out(dim
, src_len
, dst_len
, src_len
- dst_len
);
116 /* Extend "set" with unconstrained coordinates to a total length of "dst_len".
118 __isl_give isl_set
*extend(__isl_take isl_set
*set
, int dst_len
)
124 dim
= isl_set_get_space(set
);
125 n_set
= isl_space_dim(dim
, isl_dim_set
);
126 dim
= isl_space_drop_dims(dim
, isl_dim_set
, 0, n_set
);
127 map
= projection(dim
, dst_len
, n_set
);
128 map
= isl_map_reverse(map
);
130 return isl_set_apply(set
, map
);