3 #include <isl/constraint.h>
10 typedef std::vector
<Variable_ID
> varvector
;
12 static void max_index(Constraint_Handle c
, varvector
& vv
, varvector
& params
)
14 for (Constr_Vars_Iter
cvi(c
); cvi
; ++cvi
) {
15 Variable_ID var
= (*cvi
).var
;
16 if (find(vv
.begin(), vv
.end(), var
) == vv
.end() &&
17 find(params
.begin(), params
.end(), var
) == params
.end())
22 static void set_constraint(isl_constraint
*c
, Constraint_Handle h
,
23 varvector
&vv
, varvector
¶ms
)
29 for (int i
= 0; i
< vv
.size(); ++i
) {
30 isl_int_set_si(v
, h
.get_coef(vv
[i
]));
31 isl_constraint_set_coefficient(c
, isl_dim_set
, i
, v
);
33 for (int i
= 0; i
< params
.size(); ++i
) {
34 isl_int_set_si(v
, h
.get_coef(params
[i
]));
35 isl_constraint_set_coefficient(c
, isl_dim_param
, i
, v
);
37 isl_int_set_si(v
, h
.get_const());
38 isl_constraint_set_constant(c
, v
);
43 static isl_basic_set
*disjunct2basic_set(DNF_Iterator
&di
, isl_space
*dim
,
44 varvector
&vv
, varvector
¶ms
)
51 for (EQ_Iterator ei
= (*di
)->EQs(); ei
; ++ei
)
52 max_index((*ei
), vv
, params
);
53 for (GEQ_Iterator gi
= (*di
)->GEQs(); gi
; ++gi
)
54 max_index((*gi
), vv
, params
);
56 dim
= isl_space_add_dims(dim
, isl_dim_set
, vv
.size() - d
);
57 bset
= isl_basic_set_universe(isl_space_copy(dim
));
58 ls
= isl_local_space_from_space(dim
);
60 for (EQ_Iterator ei
= (*di
)->EQs(); ei
; ++ei
) {
61 c
= isl_equality_alloc(isl_local_space_copy(ls
));
62 set_constraint(c
, (*ei
), vv
, params
);
63 bset
= isl_basic_set_add_constraint(bset
, c
);
65 for (GEQ_Iterator gi
= (*di
)->GEQs(); gi
; ++gi
) {
66 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
67 set_constraint(c
, (*gi
), vv
, params
);
68 bset
= isl_basic_set_add_constraint(bset
, c
);
71 isl_local_space_free(ls
);
73 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, d
, vv
.size() - d
);
79 __isl_give isl_map
*relation2map(isl_ctx
*ctx
, Relation
&r
)
87 for (int j
= 1; j
<= r
.n_inp(); ++j
)
88 vv
.push_back(r
.input_var(j
));
89 for (int j
= 1; j
<= r
.n_out(); ++j
)
90 vv
.push_back(r
.output_var(j
));
92 const Variable_ID_Tuple
*globals
= r
.global_decls();
93 dim
= isl_space_alloc(ctx
, globals
->size(), r
.n_inp(), r
.n_out());
94 for (int i
= 0; i
< globals
->size(); ++i
) {
95 Variable_ID v
= r
.get_local((*globals
)[i
+1]);
97 dim
= isl_space_set_dim_name(dim
, isl_dim_param
, i
, v
->base_name
);
100 dim_set
= isl_space_set_alloc(ctx
, params
.size(), vv
.size());
101 map
= isl_map_empty(isl_space_copy(dim
));
103 for (DNF_Iterator
di(r
.query_DNF()); di
; ++di
) {
107 bset
= disjunct2basic_set(di
, isl_space_copy(dim_set
), vv
, params
);
108 bmap
= isl_basic_map_from_basic_set(bset
, isl_space_copy(dim
));
109 map
= isl_map_union(map
, isl_map_from_basic_map(bmap
));
112 isl_space_free(dim_set
);
118 __isl_give isl_set
*relation2set(isl_ctx
*ctx
, Relation
&r
)
125 for (int j
= 1; j
<= r
.n_set(); ++j
)
126 vv
.push_back(r
.set_var(j
));
128 const Variable_ID_Tuple
*globals
= r
.global_decls();
129 dim
= isl_space_set_alloc(ctx
, globals
->size(), r
.n_set());
130 for (int i
= 0; i
< globals
->size(); ++i
) {
131 Variable_ID v
= r
.get_local((*globals
)[i
+1]);
133 dim
= isl_space_set_dim_name(dim
, isl_dim_param
, i
, v
->base_name
);
136 set
= isl_set_empty(isl_space_copy(dim
));
138 for (DNF_Iterator
di(r
.query_DNF()); di
; ++di
) {
141 bset
= disjunct2basic_set(di
, isl_space_copy(dim
), vv
, params
);
142 set
= isl_set_union(set
, isl_set_from_basic_set(bset
));