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
)
50 struct bv_add_chamber_data
*data
= (struct bv_add_chamber_data
*)user
;
53 v
= isl_vertex_get_id(vertex
);
54 data
->dom
->F
[v
/ INT_BITS
] |= 1u << (INT_BITS
- (v
% INT_BITS
) - 1);
56 isl_vertex_free(vertex
);
61 static isl_stat
add_chamber(__isl_take isl_cell
*cell
, void *user
)
63 struct bv_add_chamber_data
*data
= (struct bv_add_chamber_data
*)user
;
65 isl_basic_set
*domain
;
67 ctx
= isl_cell_get_ctx(cell
);
69 domain
= isl_cell_get_domain(cell
);
71 data
->dom
= isl_alloc_type(ctx
, Param_Domain
);
72 data
->dom
->Domain
= isl_basic_set_to_polylib(domain
);
73 data
->dom
->F
= isl_calloc_array(ctx
, unsigned, data
->vertex_len
);
74 data
->dom
->next
= NULL
;
76 isl_basic_set_free(domain
);
78 *data
->next_D
= data
->dom
;
79 data
->next_D
= &data
->dom
->next
;
81 isl_cell_foreach_vertex(cell
, &add_chamber_vertex
, data
);
88 Param_Polyhedron
*ISL_P2PP(Polyhedron
*P
, Polyhedron
*C
,
89 struct barvinok_options
*options
)
91 isl_ctx
*ctx
= isl_ctx_alloc();
93 isl_basic_set
*bset
, *context
;
94 isl_vertices
*vertices
;
95 unsigned nparam
= C
->Dimension
;
96 unsigned nvar
= P
->Dimension
- nparam
;
97 Param_Polyhedron
*PP
= isl_calloc_type(ctx
, Param_Polyhedron
);
98 Param_Vertices
**next_V
;
99 struct bv_add_chamber_data data
;
101 space
= isl_space_set_alloc(ctx
, nparam
, nvar
);
102 bset
= isl_basic_set_new_from_polylib(P
, space
);
103 space
= isl_space_params_alloc(ctx
, nparam
);
104 context
= isl_basic_set_new_from_polylib(C
, space
);
106 bset
= isl_basic_set_intersect_params(bset
, context
);
108 vertices
= isl_basic_set_compute_vertices(bset
);
109 isl_basic_set_free(bset
);
112 PP
->nbV
= isl_vertices_get_n_vertices(vertices
);
113 PP
->Constraints
= Polyhedron2Constraints(P
);
116 isl_vertices_foreach_vertex(vertices
, &add_vertex
, &next_V
);
118 data
.next_D
= &PP
->D
;
119 data
.vertex_len
= (PP
->nbV
+ INT_BITS
- 1)/INT_BITS
;
120 isl_vertices_foreach_cell(vertices
, &add_chamber
, &data
);
122 isl_vertices_free(vertices
);