add tests/lexmin.README explaining origin of some of the lexmin inputs
[barvinok.git] / isl_param_util.c
blob5e203f35dabf879fb16ff3d8c9303a031e35bae1
1 #include <isl_aff_polylib.h>
2 #include <isl_set_polylib.h>
3 #include <isl/ctx.h>
4 #include <isl/space.h>
5 #include <isl/aff.h>
6 #include <isl/set.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;
15 Param_Vertices *V;
16 Polyhedron *D;
17 isl_basic_set *dom;
18 isl_multi_aff *expr;
19 isl_ctx *ctx;
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);
32 V->Facets = NULL;
33 V->next = NULL;
35 Polyhedron_Free(D);
36 isl_multi_aff_free(expr);
38 **next_V = V;
39 *next_V = &V->next;
41 isl_vertex_free(vertex);
43 return isl_stat_ok;
46 struct bv_add_chamber_data {
47 Param_Domain **next_D;
48 int vertex_len;
49 Param_Domain *dom;
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;
55 unsigned v;
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);
62 return isl_stat_ok;
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;
68 isl_ctx *ctx;
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);
87 isl_cell_free(cell);
89 return isl_stat_ok;
92 Param_Polyhedron *ISL_P2PP(Polyhedron *P, Polyhedron *C,
93 struct barvinok_options *options)
95 isl_ctx *ctx = isl_ctx_alloc();
96 isl_space *space;
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);
115 PP->Rays = NULL;
116 PP->nbV = isl_vertices_get_n_vertices(vertices);
117 PP->Constraints = Polyhedron2Constraints(P);
119 next_V = &PP->V;
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);
128 isl_ctx_free(ctx);
130 return PP;