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 from a len-dimensional domain to
22 * a (len-n)-dimensional domain that projects out the n coordinates
24 * "dim" prescribes the parameters.
26 __isl_give isl_map
*project_out(__isl_take isl_space
*dim
,
27 int len
, int first
, int n
)
32 dim
= isl_space_add_dims(dim
, isl_dim_in
, len
);
33 dim
= isl_space_add_dims(dim
, isl_dim_out
, len
- n
);
34 bmap
= isl_basic_map_universe(dim
);
36 for (i
= 0, j
= 0; i
< len
; ++i
) {
37 if (i
>= first
&& i
< first
+ n
)
39 bmap
= isl_basic_map_equate(bmap
, isl_dim_in
, i
, isl_dim_out
, j
);
43 return isl_map_from_basic_map(bmap
);
46 /* Construct a projection that maps a src_len dimensional domain
47 * to its first dst_len coordinates.
48 * "dim" prescribes the parameters.
50 __isl_give isl_map
*projection(__isl_take isl_space
*dim
,
51 int src_len
, int dst_len
)
53 return project_out(dim
, src_len
, dst_len
, src_len
- dst_len
);
56 /* Extend "set" with unconstrained coordinates to a total length of "dst_len".
58 __isl_give isl_set
*extend(__isl_take isl_set
*set
, int dst_len
)
64 dim
= isl_set_get_space(set
);
65 n_set
= isl_space_dim(dim
, isl_dim_set
);
66 dim
= isl_space_drop_dims(dim
, isl_dim_set
, 0, n_set
);
67 map
= projection(dim
, dst_len
, n_set
);
68 map
= isl_map_reverse(map
);
70 return isl_set_apply(set
, map
);
73 /* Set max_out to the maximal number of output dimensions over
76 static int update_max_out(__isl_take isl_map
*map
, void *user
)
79 int n_out
= isl_map_dim(map
, isl_dim_out
);
88 struct align_range_data
{
93 /* Extend the dimension of the range of the given map to data->max_out and
94 * then add the result to data->res.
96 static int map_align_range(__isl_take isl_map
*map
, void *user
)
98 struct align_range_data
*data
= user
;
102 int n_out
= isl_map_dim(map
, isl_dim_out
);
104 dim
= isl_union_map_get_space(data
->res
);
105 proj
= isl_map_reverse(projection(dim
, data
->max_out
, n_out
));
106 for (i
= n_out
; i
< data
->max_out
; ++i
)
107 proj
= isl_map_fix_si(proj
, isl_dim_out
, i
, 0);
109 map
= isl_map_apply_range(map
, proj
);
111 data
->res
= isl_union_map_add_map(data
->res
, map
);
116 /* Extend the ranges of the maps in the union map such they all have
117 * the same dimension.
119 __isl_give isl_union_map
*align_range(__isl_take isl_union_map
*umap
)
121 struct align_range_data data
;
124 isl_union_map_foreach_map(umap
, &update_max_out
, &data
.max_out
);
126 data
.res
= isl_union_map_empty(isl_union_map_get_space(umap
));
127 isl_union_map_foreach_map(umap
, &map_align_range
, &data
);
129 isl_union_map_free(umap
);