1 #include <isl_aff_polylib.h>
2 #include <isl_set_polylib.h>
7 #include <isl/vertices.h>
8 #include "isl_param_util.h"
10 #define INT_BITS (sizeof(unsigned) * 8)
12 static isl_stat
add_vertex(__isl_take isl_vertex
*vertex
, void *user
)
14 Param_Vertices
***next_V
= (Param_Vertices
***) user
;
21 ctx
= isl_vertex_get_ctx(vertex
);
23 dom
= isl_vertex_get_domain(vertex
);
24 D
= isl_basic_set_to_polylib(dom
);
25 isl_basic_set_free(dom
);
27 expr
= isl_vertex_get_expr(vertex
);
29 V
= isl_alloc_type(ctx
, Param_Vertices
);
30 V
->Vertex
= isl_multi_aff_to_polylib(expr
);
31 V
->Domain
= Polyhedron2Constraints(D
);
36 isl_multi_aff_free(expr
);
41 isl_vertex_free(vertex
);
46 struct bv_add_chamber_data
{
47 Param_Domain
**next_D
;
52 static isl_stat
add_chamber_vertex(__isl_take isl_vertex
*vertex
, void *user
)
54 struct bv_add_chamber_data
*data
= (struct bv_add_chamber_data
*)user
;
57 v
= isl_vertex_get_id(vertex
);
58 data
->dom
->F
[v
/ INT_BITS
] |= 1u << (INT_BITS
- (v
% INT_BITS
) - 1);
60 isl_vertex_free(vertex
);
65 static isl_stat
add_chamber(__isl_take isl_cell
*cell
, void *user
)
67 struct bv_add_chamber_data
*data
= (struct bv_add_chamber_data
*)user
;
69 isl_basic_set
*domain
;
71 ctx
= isl_cell_get_ctx(cell
);
73 domain
= isl_cell_get_domain(cell
);
75 data
->dom
= isl_alloc_type(ctx
, Param_Domain
);
76 data
->dom
->Domain
= isl_basic_set_to_polylib(domain
);
77 data
->dom
->F
= isl_calloc_array(ctx
, unsigned, data
->vertex_len
);
78 data
->dom
->next
= NULL
;
80 isl_basic_set_free(domain
);
82 *data
->next_D
= data
->dom
;
83 data
->next_D
= &data
->dom
->next
;
85 isl_cell_foreach_vertex(cell
, &add_chamber_vertex
, data
);
92 Param_Polyhedron
*ISL_P2PP(Polyhedron
*P
, Polyhedron
*C
,
93 struct barvinok_options
*options
)
95 isl_ctx
*ctx
= isl_ctx_alloc();
97 isl_basic_set
*bset
, *context
;
98 isl_vertices
*vertices
;
99 unsigned nparam
= C
->Dimension
;
100 unsigned nvar
= P
->Dimension
- nparam
;
101 Param_Polyhedron
*PP
= isl_calloc_type(ctx
, Param_Polyhedron
);
102 Param_Vertices
**next_V
;
103 struct bv_add_chamber_data data
;
105 space
= isl_space_set_alloc(ctx
, nparam
, nvar
);
106 bset
= isl_basic_set_new_from_polylib(P
, space
);
107 space
= isl_space_params_alloc(ctx
, nparam
);
108 context
= isl_basic_set_new_from_polylib(C
, space
);
110 bset
= isl_basic_set_intersect_params(bset
, context
);
112 vertices
= isl_basic_set_compute_vertices(bset
);
113 isl_basic_set_free(bset
);
116 PP
->nbV
= isl_vertices_get_n_vertices(vertices
);
117 PP
->Constraints
= Polyhedron2Constraints(P
);
120 isl_vertices_foreach_vertex(vertices
, &add_vertex
, &next_V
);
122 data
.next_D
= &PP
->D
;
123 data
.vertex_len
= (PP
->nbV
+ INT_BITS
- 1)/INT_BITS
;
124 isl_vertices_foreach_cell(vertices
, &add_chamber
, &data
);
126 isl_vertices_free(vertices
);