update pet for rename of pet_scop_collect_* to pet_scop_get_*
[barvinok/uuh.git] / isl_param_util.c
blob0f093146135cfc86c15d7ad539839b9a260716af
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 int j;
51 struct bv_add_chamber_data *data = (struct bv_add_chamber_data *)user;
52 unsigned v;
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);
59 return isl_stat_ok;
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;
65 isl_ctx *ctx;
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);
84 isl_cell_free(cell);
86 return isl_stat_ok;
89 Param_Polyhedron *ISL_P2PP(Polyhedron *P, Polyhedron *C,
90 struct barvinok_options *options)
92 int i, j;
93 isl_ctx *ctx = isl_ctx_alloc();
94 isl_space *dim;
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);
113 PP->Rays = NULL;
114 PP->nbV = isl_vertices_get_n_vertices(vertices);
115 PP->Constraints = Polyhedron2Constraints(P);
117 next_V = &PP->V;
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);
126 isl_ctx_free(ctx);
128 return PP;