1 #include <isl_aff_polylib.h>
2 #include <isl_set_polylib.h>
3 #include <isl/vertices.h>
4 #include "isl_param_util.h"
6 #define INT_BITS (sizeof(unsigned) * 8)
8 static isl_stat
add_vertex(__isl_take isl_vertex
*vertex
, void *user
)
10 Param_Vertices
***next_V
= (Param_Vertices
***) user
;
17 ctx
= isl_vertex_get_ctx(vertex
);
19 dom
= isl_vertex_get_domain(vertex
);
20 D
= isl_basic_set_to_polylib(dom
);
21 isl_basic_set_free(dom
);
23 expr
= isl_vertex_get_expr(vertex
);
25 V
= isl_alloc_type(ctx
, Param_Vertices
);
26 V
->Vertex
= isl_multi_aff_to_polylib(expr
);
27 V
->Domain
= Polyhedron2Constraints(D
);
32 isl_multi_aff_free(expr
);
37 isl_vertex_free(vertex
);
42 struct bv_add_chamber_data
{
43 Param_Domain
**next_D
;
48 static isl_stat
add_chamber_vertex(__isl_take isl_vertex
*vertex
, void *user
)
51 struct bv_add_chamber_data
*data
= (struct bv_add_chamber_data
*)user
;
54 v
= isl_vertex_get_id(vertex
);
55 data
->dom
->F
[v
/ INT_BITS
] |= 1u << (INT_BITS
- (v
% INT_BITS
) - 1);
57 isl_vertex_free(vertex
);
62 static isl_stat
add_chamber(__isl_take isl_cell
*cell
, void *user
)
64 struct bv_add_chamber_data
*data
= (struct bv_add_chamber_data
*)user
;
66 isl_basic_set
*domain
;
68 ctx
= isl_cell_get_ctx(cell
);
70 domain
= isl_cell_get_domain(cell
);
72 data
->dom
= isl_alloc_type(ctx
, Param_Domain
);
73 data
->dom
->Domain
= isl_basic_set_to_polylib(domain
);
74 data
->dom
->F
= isl_calloc_array(ctx
, unsigned, data
->vertex_len
);
75 data
->dom
->next
= NULL
;
77 isl_basic_set_free(domain
);
79 *data
->next_D
= data
->dom
;
80 data
->next_D
= &data
->dom
->next
;
82 isl_cell_foreach_vertex(cell
, &add_chamber_vertex
, data
);
89 Param_Polyhedron
*ISL_P2PP(Polyhedron
*P
, Polyhedron
*C
,
90 struct barvinok_options
*options
)
93 isl_ctx
*ctx
= isl_ctx_alloc();
95 isl_basic_set
*bset
, *context
;
96 isl_vertices
*vertices
;
97 unsigned nparam
= C
->Dimension
;
98 unsigned nvar
= P
->Dimension
- nparam
;
99 Param_Polyhedron
*PP
= isl_calloc_type(ctx
, Param_Polyhedron
);
100 Param_Vertices
**next_V
;
101 struct bv_add_chamber_data data
;
103 dim
= isl_space_set_alloc(ctx
, nparam
, nvar
);
104 bset
= isl_basic_set_new_from_polylib(P
, dim
);
105 dim
= isl_space_set_alloc(ctx
, nparam
, 0);
106 context
= isl_basic_set_new_from_polylib(C
, dim
);
108 bset
= isl_basic_set_intersect(bset
, context
);
110 vertices
= isl_basic_set_compute_vertices(bset
);
111 isl_basic_set_free(bset
);
114 PP
->nbV
= isl_vertices_get_n_vertices(vertices
);
115 PP
->Constraints
= Polyhedron2Constraints(P
);
118 isl_vertices_foreach_vertex(vertices
, &add_vertex
, &next_V
);
120 data
.next_D
= &PP
->D
;
121 data
.vertex_len
= (PP
->nbV
+ INT_BITS
- 1)/INT_BITS
;
122 isl_vertices_foreach_cell(vertices
, &add_chamber
, &data
);
124 isl_vertices_free(vertices
);