barvinok.cc: ienumerator::ienumerator: drop redundant argument
[barvinok.git] / isl_param_util.c
blobe6c107069fac0867050a71020705fc40f76001fb
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;
11 Param_Vertices *V;
12 Polyhedron *D;
13 isl_basic_set *dom;
14 isl_multi_aff *expr;
15 isl_ctx *ctx;
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);
28 V->Facets = NULL;
29 V->next = NULL;
31 Polyhedron_Free(D);
32 isl_multi_aff_free(expr);
34 **next_V = V;
35 *next_V = &V->next;
37 isl_vertex_free(vertex);
39 return isl_stat_ok;
42 struct bv_add_chamber_data {
43 Param_Domain **next_D;
44 int vertex_len;
45 Param_Domain *dom;
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;
51 unsigned v;
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);
58 return isl_stat_ok;
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;
64 isl_ctx *ctx;
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);
83 isl_cell_free(cell);
85 return isl_stat_ok;
88 Param_Polyhedron *ISL_P2PP(Polyhedron *P, Polyhedron *C,
89 struct barvinok_options *options)
91 isl_ctx *ctx = isl_ctx_alloc();
92 isl_space *space;
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);
111 PP->Rays = NULL;
112 PP->nbV = isl_vertices_get_n_vertices(vertices);
113 PP->Constraints = Polyhedron2Constraints(P);
115 next_V = &PP->V;
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);
124 isl_ctx_free(ctx);
126 return PP;