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
)
37 dim
= isl_space_add_dims(dim
, isl_dim_in
, len
);
38 dim
= isl_space_add_dims(dim
, isl_dim_out
, len
- n
);
39 bmap
= isl_basic_map_universe(isl_space_copy(dim
));
40 ls
= isl_local_space_from_space(dim
);
42 for (i
= 0, j
= 0; i
< len
; ++i
) {
43 if (i
>= first
&& i
< first
+ n
)
45 c
= isl_equality_alloc(isl_local_space_copy(ls
));
46 isl_int_set_si(v
, -1);
47 isl_constraint_set_coefficient(c
, isl_dim_in
, i
, v
);
49 isl_constraint_set_coefficient(c
, isl_dim_out
, j
, v
);
50 bmap
= isl_basic_map_add_constraint(bmap
, c
);
53 isl_local_space_free(ls
);
57 return isl_map_from_basic_map(bmap
);
60 /* Construct a projection that maps a src_len dimensional domain
61 * to its first dst_len coordinates.
62 * "dim" prescribes the parameters.
64 __isl_give isl_map
*projection(__isl_take isl_space
*dim
,
65 int src_len
, int dst_len
)
67 return project_out(dim
, src_len
, dst_len
, src_len
- dst_len
);
70 /* Extend "set" with unconstrained coordinates to a total length of "dst_len".
72 __isl_give isl_set
*extend(__isl_take isl_set
*set
, int dst_len
)
78 dim
= isl_set_get_space(set
);
79 n_set
= isl_space_dim(dim
, isl_dim_set
);
80 dim
= isl_space_drop_dims(dim
, isl_dim_set
, 0, n_set
);
81 map
= projection(dim
, dst_len
, n_set
);
82 map
= isl_map_reverse(map
);
84 return isl_set_apply(set
, map
);
87 /* Set max_out to the maximal number of output dimensions over
90 static int update_max_out(__isl_take isl_map
*map
, void *user
)
93 int n_out
= isl_map_dim(map
, isl_dim_out
);
102 struct align_range_data
{
107 /* Extend the dimension of the range of the given map to data->max_out and
108 * then add the result to data->res.
110 static int map_align_range(__isl_take isl_map
*map
, void *user
)
112 struct align_range_data
*data
= user
;
116 int n_out
= isl_map_dim(map
, isl_dim_out
);
118 dim
= isl_union_map_get_space(data
->res
);
119 proj
= isl_map_reverse(projection(dim
, data
->max_out
, n_out
));
120 for (i
= n_out
; i
< data
->max_out
; ++i
)
121 proj
= isl_map_fix_si(proj
, isl_dim_out
, i
, 0);
123 map
= isl_map_apply_range(map
, proj
);
125 data
->res
= isl_union_map_add_map(data
->res
, map
);
130 /* Extend the ranges of the maps in the union map such they all have
131 * the same dimension.
133 __isl_give isl_union_map
*align_range(__isl_take isl_union_map
*umap
)
135 struct align_range_data data
;
138 isl_union_map_foreach_map(umap
, &update_max_out
, &data
.max_out
);
140 data
.res
= isl_union_map_empty(isl_union_map_get_space(umap
));
141 isl_union_map_foreach_map(umap
, &map_align_range
, &data
);
143 isl_union_map_free(umap
);