2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
5 * Use of this software is governed by the GNU LGPLv2.1 license
7 * Written by Sven Verdoolaege, K.U.Leuven, Departement
8 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
9 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
10 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
16 static void print_constraint_polylib(struct isl_basic_set *bset,
18 FILE *out, int indent, const char *prefix, const char *suffix)
21 unsigned dim = isl_basic_set_n_dim(bset);
22 unsigned nparam = isl_basic_set_n_param(bset);
23 isl_int *c = ineq ? bset->ineq[n] : bset->eq[n];
25 fprintf(out, "%*s%s", indent, "", prefix ? prefix : "");
26 fprintf(out, "%d", ineq);
27 for (i = 0; i < dim; ++i) {
29 isl_int_print(out, c[1+nparam+i], 5);
31 for (i = 0; i < bset->n_div; ++i) {
33 isl_int_print(out, c[1+nparam+dim+i], 5);
35 for (i = 0; i < nparam; ++i) {
37 isl_int_print(out, c[1+i], 5);
40 isl_int_print(out, c[0], 5);
41 fprintf(out, "%s\n", suffix ? suffix : "");
44 static void print_constraints_polylib(struct isl_basic_set *bset,
45 FILE *out, int indent, const char *prefix, const char *suffix)
49 for (i = 0; i < bset->n_eq; ++i)
50 print_constraint_polylib(bset, 0, i, out,
51 indent, prefix, suffix);
52 for (i = 0; i < bset->n_ineq; ++i)
53 print_constraint_polylib(bset, 1, i, out,
54 indent, prefix, suffix);
57 static void isl_basic_set_print_polylib(struct isl_basic_set *bset, FILE *out,
58 int indent, const char *prefix, const char *suffix)
60 unsigned total = isl_basic_set_total_dim(bset);
61 fprintf(out, "%*s%s", indent, "", prefix ? prefix : "");
62 fprintf(out, "%d %d", bset->n_eq + bset->n_ineq, 1 + total + 1);
63 fprintf(out, "%s\n", suffix ? suffix : "");
64 print_constraints_polylib(bset, out, indent, prefix, suffix);
67 static void isl_set_print_polylib(struct isl_set *set, FILE *out, int indent)
71 fprintf(out, "%*s", indent, "");
72 fprintf(out, "%d\n", set->n);
73 for (i = 0; i < set->n; ++i) {
75 isl_basic_set_print_polylib(set->p[i], out, indent, NULL, NULL);
79 static print_name(struct isl_dim *dim, FILE *out,
80 enum isl_dim_type type, unsigned pos, int set)
84 name = type == isl_dim_div ? NULL : isl_dim_get_name(dim, type, pos);
87 fprintf(out, "%s", name);
90 if (type == isl_dim_param)
92 else if (type == isl_dim_div)
94 else if (set || type == isl_dim_in)
98 fprintf(out, "%s%d", prefix, pos);
102 static void print_var_list(struct isl_dim *dim, FILE *out,
103 enum isl_dim_type type, int set)
107 for (i = 0; i < isl_dim_size(dim, type); ++i) {
110 print_name(dim, out, type, i, set);
114 static void print_tuple(__isl_keep isl_dim *dim, FILE *out,
115 enum isl_dim_type type, int set)
118 print_var_list(dim, out, type, set);
122 static void print_omega_parameters(struct isl_dim *dim, FILE *out,
123 int indent, const char *prefix, const char *suffix)
125 if (isl_dim_size(dim, isl_dim_param) == 0)
128 fprintf(out, "%*s%ssymbolic ", indent, "", prefix ? prefix : "");
129 print_var_list(dim, out, isl_dim_param, 0);
130 fprintf(out, ";%s\n", suffix ? suffix : "");
133 static void print_term(__isl_keep isl_dim *dim,
134 isl_int c, int pos, FILE *out, int set)
136 enum isl_dim_type type;
137 unsigned n_in = isl_dim_size(dim, isl_dim_in);
138 unsigned n_out = isl_dim_size(dim, isl_dim_out);
139 unsigned nparam = isl_dim_size(dim, isl_dim_param);
142 isl_int_print(out, c, 0);
146 if (isl_int_is_one(c))
148 else if (isl_int_is_negone(c))
151 isl_int_print(out, c, 0);
152 if (pos < 1 + nparam) {
153 type = isl_dim_param;
155 } else if (pos < 1 + nparam + n_in) {
158 } else if (pos < 1 + nparam + n_in + n_out) {
160 pos -= 1 + nparam + n_in;
163 pos -= 1 + nparam + n_in + n_out;
165 print_name(dim, out, type, pos, set);
168 static void print_affine(__isl_keep isl_basic_map *bmap, FILE *out,
173 unsigned len = 1 + isl_basic_map_total_dim(bmap);
175 for (i = 0, first = 1; i < len; ++i) {
177 if (isl_int_is_zero(c[i]))
180 if (isl_int_is_neg(c[i])) {
182 isl_int_neg(c[i], c[i]);
188 print_term(bmap->dim, c[i], i, out, set);
190 isl_int_neg(c[i], c[i]);
196 static void print_constraint(struct isl_basic_map *bmap, FILE *out,
197 isl_int *c, int last, const char *op, int first_constraint, int set)
199 if (!first_constraint)
200 fprintf(out, " and ");
202 isl_int_abs(c[last], c[last]);
204 print_term(bmap->dim, c[last], last, out, set);
206 fprintf(out, " %s ", op);
208 isl_int_set_si(c[last], 0);
209 print_affine(bmap, out, c, set);
212 static void print_constraints(__isl_keep isl_basic_map *bmap, FILE *out,
217 unsigned total = isl_basic_map_total_dim(bmap);
219 c = isl_vec_alloc(bmap->ctx, 1 + total);
223 for (i = bmap->n_eq - 1; i >= 0; --i) {
224 int l = isl_seq_last_non_zero(bmap->eq[i], 1 + total);
225 isl_assert(bmap->ctx, l >= 0, return);
226 if (isl_int_is_neg(bmap->eq[i][l]))
227 isl_seq_cpy(c->el, bmap->eq[i], 1 + total);
229 isl_seq_neg(c->el, bmap->eq[i], 1 + total);
230 print_constraint(bmap, out, c->el, l,
231 "=", i == bmap->n_eq - 1, set);
233 for (i = 0; i < bmap->n_ineq; ++i) {
234 int l = isl_seq_last_non_zero(bmap->ineq[i], 1 + total);
236 isl_assert(bmap->ctx, l >= 0, return);
237 s = isl_int_sgn(bmap->ineq[i][l]);
239 isl_seq_cpy(c->el, bmap->ineq[i], 1 + total);
241 isl_seq_neg(c->el, bmap->ineq[i], 1 + total);
242 print_constraint(bmap, out, c->el, l,
243 s < 0 ? "<=" : ">=", !bmap->n_eq && !i, set);
249 static void print_omega_constraints(__isl_keep isl_basic_map *bmap, FILE *out,
252 if (bmap->n_eq + bmap->n_ineq == 0)
256 if (bmap->n_div > 0) {
258 fprintf(out, "exists (");
259 for (i = 0; i < bmap->n_div; ++i) {
262 print_name(bmap->dim, out, isl_dim_div, i, 0);
266 print_constraints(bmap, out, set);
271 static void basic_map_print_omega(struct isl_basic_map *bmap, FILE *out)
274 print_var_list(bmap->dim, out, isl_dim_in, 0);
275 fprintf(out, "] -> [");
276 print_var_list(bmap->dim, out, isl_dim_out, 0);
278 print_omega_constraints(bmap, out, 0);
282 static void isl_basic_map_print_omega(struct isl_basic_map *bmap, FILE *out,
283 int indent, const char *prefix, const char *suffix)
285 print_omega_parameters(bmap->dim, out, indent, prefix, suffix);
287 fprintf(out, "%*s%s", indent, "", prefix ? prefix : "");
288 basic_map_print_omega(bmap, out);
289 fprintf(out, "%s\n", suffix ? suffix : "");
292 static void basic_set_print_omega(struct isl_basic_set *bset, FILE *out)
295 print_var_list(bset->dim, out, isl_dim_set, 1);
297 print_omega_constraints((isl_basic_map *)bset, out, 1);
301 static void isl_basic_set_print_omega(struct isl_basic_set *bset, FILE *out,
302 int indent, const char *prefix, const char *suffix)
304 print_omega_parameters(bset->dim, out, indent, prefix, suffix);
306 fprintf(out, "%*s%s", indent, "", prefix ? prefix : "");
307 basic_set_print_omega(bset, out);
308 fprintf(out, "%s\n", suffix ? suffix : "");
311 static void isl_map_print_omega(struct isl_map *map, FILE *out, int indent)
315 print_omega_parameters(map->dim, out, indent, "", "");
317 fprintf(out, "%*s", indent, "");
318 for (i = 0; i < map->n; ++i) {
320 fprintf(out, " union ");
321 basic_map_print_omega(map->p[i], out);
326 static void isl_set_print_omega(struct isl_set *set, FILE *out, int indent)
330 print_omega_parameters(set->dim, out, indent, "", "");
332 fprintf(out, "%*s", indent, "");
333 for (i = 0; i < set->n; ++i) {
335 fprintf(out, " union ");
336 basic_set_print_omega(set->p[i], out);
341 static void print_disjunct(__isl_keep isl_basic_map *bmap, FILE *out, int set)
343 if (bmap->n_div > 0) {
345 fprintf(out, "exists (");
346 for (i = 0; i < bmap->n_div; ++i) {
349 print_name(bmap->dim, out, isl_dim_div, i, 0);
350 if (isl_int_is_zero(bmap->div[i][0]))
352 fprintf(out, " = [(");
353 print_affine(bmap, out, bmap->div[i] + 1, set);
355 isl_int_print(out, bmap->div[i][0], 0);
361 print_constraints(bmap, out, set);
367 static void isl_basic_map_print_isl(__isl_keep isl_basic_map *bmap, FILE *out,
368 int indent, const char *prefix, const char *suffix)
372 fprintf(out, "%*s%s", indent, "", prefix ? prefix : "");
373 if (isl_basic_map_dim(bmap, isl_dim_param) > 0) {
374 print_tuple(bmap->dim, out, isl_dim_param, 0);
375 fprintf(out, " -> ");
378 print_tuple(bmap->dim, out, isl_dim_in, 0);
379 fprintf(out, " -> ");
380 print_tuple(bmap->dim, out, isl_dim_out, 0);
382 print_disjunct(bmap, out, 0);
383 fprintf(out, " }%s\n", suffix ? suffix : "");
386 static void isl_basic_set_print_isl(__isl_keep isl_basic_set *bset, FILE *out,
387 int indent, const char *prefix, const char *suffix)
391 fprintf(out, "%*s%s", indent, "", prefix ? prefix : "");
392 if (isl_basic_set_dim(bset, isl_dim_param) > 0) {
393 print_tuple(bset->dim, out, isl_dim_param, 0);
394 fprintf(out, " -> ");
397 print_tuple(bset->dim, out, isl_dim_set, 1);
399 print_disjunct((isl_basic_map *)bset, out, 1);
400 fprintf(out, " }%s\n", suffix ? suffix : "");
403 static void isl_map_print_isl(__isl_keep isl_map *map, FILE *out, int indent)
407 fprintf(out, "%*s", indent, "");
408 if (isl_map_dim(map, isl_dim_param) > 0) {
409 print_tuple(map->dim, out, isl_dim_param, 0);
410 fprintf(out, " -> ");
413 print_tuple(map->dim, out, isl_dim_in, 0);
414 fprintf(out, " -> ");
415 print_tuple(map->dim, out, isl_dim_out, 0);
418 fprintf(out, "1 = 0");
419 for (i = 0; i < map->n; ++i) {
421 fprintf(out, " or ");
422 if (map->n > 1 && map->p[i]->n_eq + map->p[i]->n_ineq > 1)
424 print_disjunct(map->p[i], out, 0);
425 if (map->n > 1 && map->p[i]->n_eq + map->p[i]->n_ineq > 1)
428 fprintf(out, " }\n");
431 static void isl_set_print_isl(__isl_keep isl_set *set, FILE *out, int indent)
435 fprintf(out, "%*s", indent, "");
436 if (isl_set_dim(set, isl_dim_param) > 0) {
437 print_tuple(set->dim, out, isl_dim_param, 0);
438 fprintf(out, " -> ");
441 print_tuple(set->dim, out, isl_dim_set, 1);
444 fprintf(out, "1 = 0");
445 for (i = 0; i < set->n; ++i) {
447 fprintf(out, " or ");
448 print_disjunct((isl_basic_map *)set->p[i], out, 1);
450 fprintf(out, " }\n");
453 void isl_basic_map_print(__isl_keep isl_basic_map *bmap, FILE *out, int indent,
454 const char *prefix, const char *suffix, unsigned output_format)
458 if (output_format == ISL_FORMAT_ISL)
459 isl_basic_map_print_isl(bmap, out, indent, prefix, suffix);
460 else if (output_format == ISL_FORMAT_OMEGA)
461 isl_basic_map_print_omega(bmap, out, indent, prefix, suffix);
463 isl_assert(bmap->ctx, 0, return);
466 void isl_basic_set_print(struct isl_basic_set *bset, FILE *out, int indent,
467 const char *prefix, const char *suffix, unsigned output_format)
471 if (output_format == ISL_FORMAT_ISL)
472 isl_basic_set_print_isl(bset, out, indent, prefix, suffix);
473 else if (output_format == ISL_FORMAT_POLYLIB)
474 isl_basic_set_print_polylib(bset, out, indent, prefix, suffix);
475 else if (output_format == ISL_FORMAT_POLYLIB_CONSTRAINTS)
476 print_constraints_polylib(bset, out, indent, prefix, suffix);
477 else if (output_format == ISL_FORMAT_OMEGA)
478 isl_basic_set_print_omega(bset, out, indent, prefix, suffix);
480 isl_assert(bset->ctx, 0, return);
483 void isl_set_print(struct isl_set *set, FILE *out, int indent,
484 unsigned output_format)
488 if (output_format == ISL_FORMAT_ISL)
489 isl_set_print_isl(set, out, indent);
490 else if (output_format == ISL_FORMAT_POLYLIB)
491 isl_set_print_polylib(set, out, indent);
492 else if (output_format == ISL_FORMAT_OMEGA)
493 isl_set_print_omega(set, out, indent);
495 isl_assert(set->ctx, 0, return);
498 void isl_map_print(__isl_keep isl_map *map, FILE *out, int indent,
499 unsigned output_format)
503 if (output_format == ISL_FORMAT_ISL)
504 isl_map_print_isl(map, out, indent);
505 else if (output_format == ISL_FORMAT_OMEGA)
506 isl_map_print_omega(map, out, indent);
508 isl_assert(map->ctx, 0, return);