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_map
*bmap
,
18 FILE *out
, int indent
, const char *prefix
, const char *suffix
)
21 unsigned n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
22 unsigned n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
23 unsigned nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
24 isl_int
*c
= ineq
? bmap
->ineq
[n
] : bmap
->eq
[n
];
26 fprintf(out
, "%*s%s", indent
, "", prefix
? prefix
: "");
27 fprintf(out
, "%d", ineq
);
28 for (i
= 0; i
< n_out
; ++i
) {
30 isl_int_print(out
, c
[1+nparam
+n_in
+i
], 5);
32 for (i
= 0; i
< n_in
; ++i
) {
34 isl_int_print(out
, c
[1+nparam
+i
], 5);
36 for (i
= 0; i
< bmap
->n_div
; ++i
) {
38 isl_int_print(out
, c
[1+nparam
+n_in
+n_out
+i
], 5);
40 for (i
= 0; i
< nparam
; ++i
) {
42 isl_int_print(out
, c
[1+i
], 5);
45 isl_int_print(out
, c
[0], 5);
46 fprintf(out
, "%s\n", suffix
? suffix
: "");
49 static void print_constraints_polylib(struct isl_basic_map
*bmap
,
50 FILE *out
, int indent
, const char *prefix
, const char *suffix
)
54 for (i
= 0; i
< bmap
->n_eq
; ++i
)
55 print_constraint_polylib(bmap
, 0, i
, out
,
56 indent
, prefix
, suffix
);
57 for (i
= 0; i
< bmap
->n_ineq
; ++i
)
58 print_constraint_polylib(bmap
, 1, i
, out
,
59 indent
, prefix
, suffix
);
62 static void bset_print_constraints_polylib(struct isl_basic_set
*bset
,
63 FILE *out
, int indent
, const char *prefix
, const char *suffix
)
65 print_constraints_polylib((struct isl_basic_map
*)bset
,
66 out
, indent
, prefix
, suffix
);
69 static void isl_basic_map_print_polylib(struct isl_basic_map
*bmap
, FILE *out
,
70 int indent
, const char *prefix
, const char *suffix
)
72 unsigned total
= isl_basic_map_total_dim(bmap
);
73 fprintf(out
, "%*s%s", indent
, "", prefix
? prefix
: "");
74 fprintf(out
, "%d %d", bmap
->n_eq
+ bmap
->n_ineq
, 1 + total
+ 1);
75 fprintf(out
, "%s\n", suffix
? suffix
: "");
76 print_constraints_polylib(bmap
, out
, indent
, prefix
, suffix
);
79 static void isl_basic_set_print_polylib(struct isl_basic_set
*bset
, FILE *out
,
80 int indent
, const char *prefix
, const char *suffix
)
82 isl_basic_map_print_polylib((struct isl_basic_map
*)bset
, out
,
83 indent
, prefix
, suffix
);
86 static void isl_map_print_polylib(struct isl_map
*map
, FILE *out
, int indent
)
90 fprintf(out
, "%*s", indent
, "");
91 fprintf(out
, "%d\n", map
->n
);
92 for (i
= 0; i
< map
->n
; ++i
) {
94 isl_basic_map_print_polylib(map
->p
[i
], out
, indent
, NULL
, NULL
);
98 static void isl_set_print_polylib(struct isl_set
*set
, FILE *out
, int indent
)
100 isl_map_print_polylib((struct isl_map
*)set
, out
, indent
);
103 static print_name(struct isl_dim
*dim
, FILE *out
,
104 enum isl_dim_type type
, unsigned pos
, int set
)
108 name
= type
== isl_dim_div
? NULL
: isl_dim_get_name(dim
, type
, pos
);
111 fprintf(out
, "%s", name
);
114 if (type
== isl_dim_param
)
116 else if (type
== isl_dim_div
)
118 else if (set
|| type
== isl_dim_in
)
122 fprintf(out
, "%s%d", prefix
, pos
);
126 static void print_var_list(struct isl_dim
*dim
, FILE *out
,
127 enum isl_dim_type type
, int set
)
131 for (i
= 0; i
< isl_dim_size(dim
, type
); ++i
) {
134 print_name(dim
, out
, type
, i
, set
);
138 static void print_tuple(__isl_keep isl_dim
*dim
, FILE *out
,
139 enum isl_dim_type type
, int set
)
142 print_var_list(dim
, out
, type
, set
);
146 static void print_omega_parameters(struct isl_dim
*dim
, FILE *out
,
147 int indent
, const char *prefix
, const char *suffix
)
149 if (isl_dim_size(dim
, isl_dim_param
) == 0)
152 fprintf(out
, "%*s%ssymbolic ", indent
, "", prefix
? prefix
: "");
153 print_var_list(dim
, out
, isl_dim_param
, 0);
154 fprintf(out
, ";%s\n", suffix
? suffix
: "");
157 static void print_term(__isl_keep isl_dim
*dim
,
158 isl_int c
, int pos
, FILE *out
, int set
)
160 enum isl_dim_type type
;
161 unsigned n_in
= isl_dim_size(dim
, isl_dim_in
);
162 unsigned n_out
= isl_dim_size(dim
, isl_dim_out
);
163 unsigned nparam
= isl_dim_size(dim
, isl_dim_param
);
166 isl_int_print(out
, c
, 0);
170 if (isl_int_is_one(c
))
172 else if (isl_int_is_negone(c
))
175 isl_int_print(out
, c
, 0);
176 if (pos
< 1 + nparam
) {
177 type
= isl_dim_param
;
179 } else if (pos
< 1 + nparam
+ n_in
) {
182 } else if (pos
< 1 + nparam
+ n_in
+ n_out
) {
184 pos
-= 1 + nparam
+ n_in
;
187 pos
-= 1 + nparam
+ n_in
+ n_out
;
189 print_name(dim
, out
, type
, pos
, set
);
192 static void print_affine(__isl_keep isl_basic_map
*bmap
, FILE *out
,
197 unsigned len
= 1 + isl_basic_map_total_dim(bmap
);
199 for (i
= 0, first
= 1; i
< len
; ++i
) {
201 if (isl_int_is_zero(c
[i
]))
204 if (isl_int_is_neg(c
[i
])) {
206 isl_int_neg(c
[i
], c
[i
]);
212 print_term(bmap
->dim
, c
[i
], i
, out
, set
);
214 isl_int_neg(c
[i
], c
[i
]);
220 static void print_constraint(struct isl_basic_map
*bmap
, FILE *out
,
221 isl_int
*c
, int last
, const char *op
, int first_constraint
, int set
)
223 if (!first_constraint
)
224 fprintf(out
, " and ");
226 isl_int_abs(c
[last
], c
[last
]);
228 print_term(bmap
->dim
, c
[last
], last
, out
, set
);
230 fprintf(out
, " %s ", op
);
232 isl_int_set_si(c
[last
], 0);
233 print_affine(bmap
, out
, c
, set
);
236 static void print_constraints(__isl_keep isl_basic_map
*bmap
, FILE *out
,
241 unsigned total
= isl_basic_map_total_dim(bmap
);
243 c
= isl_vec_alloc(bmap
->ctx
, 1 + total
);
247 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
248 int l
= isl_seq_last_non_zero(bmap
->eq
[i
], 1 + total
);
249 isl_assert(bmap
->ctx
, l
>= 0, return);
250 if (isl_int_is_neg(bmap
->eq
[i
][l
]))
251 isl_seq_cpy(c
->el
, bmap
->eq
[i
], 1 + total
);
253 isl_seq_neg(c
->el
, bmap
->eq
[i
], 1 + total
);
254 print_constraint(bmap
, out
, c
->el
, l
,
255 "=", i
== bmap
->n_eq
- 1, set
);
257 for (i
= 0; i
< bmap
->n_ineq
; ++i
) {
258 int l
= isl_seq_last_non_zero(bmap
->ineq
[i
], 1 + total
);
260 isl_assert(bmap
->ctx
, l
>= 0, return);
261 s
= isl_int_sgn(bmap
->ineq
[i
][l
]);
263 isl_seq_cpy(c
->el
, bmap
->ineq
[i
], 1 + total
);
265 isl_seq_neg(c
->el
, bmap
->ineq
[i
], 1 + total
);
266 print_constraint(bmap
, out
, c
->el
, l
,
267 s
< 0 ? "<=" : ">=", !bmap
->n_eq
&& !i
, set
);
273 static void print_omega_constraints(__isl_keep isl_basic_map
*bmap
, FILE *out
,
276 if (bmap
->n_eq
+ bmap
->n_ineq
== 0)
280 if (bmap
->n_div
> 0) {
282 fprintf(out
, "exists (");
283 for (i
= 0; i
< bmap
->n_div
; ++i
) {
286 print_name(bmap
->dim
, out
, isl_dim_div
, i
, 0);
290 print_constraints(bmap
, out
, set
);
295 static void basic_map_print_omega(struct isl_basic_map
*bmap
, FILE *out
)
298 print_var_list(bmap
->dim
, out
, isl_dim_in
, 0);
299 fprintf(out
, "] -> [");
300 print_var_list(bmap
->dim
, out
, isl_dim_out
, 0);
302 print_omega_constraints(bmap
, out
, 0);
306 static void isl_basic_map_print_omega(struct isl_basic_map
*bmap
, FILE *out
,
307 int indent
, const char *prefix
, const char *suffix
)
309 print_omega_parameters(bmap
->dim
, out
, indent
, prefix
, suffix
);
311 fprintf(out
, "%*s%s", indent
, "", prefix
? prefix
: "");
312 basic_map_print_omega(bmap
, out
);
313 fprintf(out
, "%s\n", suffix
? suffix
: "");
316 static void basic_set_print_omega(struct isl_basic_set
*bset
, FILE *out
)
319 print_var_list(bset
->dim
, out
, isl_dim_set
, 1);
321 print_omega_constraints((isl_basic_map
*)bset
, out
, 1);
325 static void isl_basic_set_print_omega(struct isl_basic_set
*bset
, FILE *out
,
326 int indent
, const char *prefix
, const char *suffix
)
328 print_omega_parameters(bset
->dim
, out
, indent
, prefix
, suffix
);
330 fprintf(out
, "%*s%s", indent
, "", prefix
? prefix
: "");
331 basic_set_print_omega(bset
, out
);
332 fprintf(out
, "%s\n", suffix
? suffix
: "");
335 static void isl_map_print_omega(struct isl_map
*map
, FILE *out
, int indent
)
339 print_omega_parameters(map
->dim
, out
, indent
, "", "");
341 fprintf(out
, "%*s", indent
, "");
342 for (i
= 0; i
< map
->n
; ++i
) {
344 fprintf(out
, " union ");
345 basic_map_print_omega(map
->p
[i
], out
);
350 static void isl_set_print_omega(struct isl_set
*set
, FILE *out
, int indent
)
354 print_omega_parameters(set
->dim
, out
, indent
, "", "");
356 fprintf(out
, "%*s", indent
, "");
357 for (i
= 0; i
< set
->n
; ++i
) {
359 fprintf(out
, " union ");
360 basic_set_print_omega(set
->p
[i
], out
);
365 static void print_disjunct(__isl_keep isl_basic_map
*bmap
, FILE *out
, int set
)
367 if (bmap
->n_div
> 0) {
369 fprintf(out
, "exists (");
370 for (i
= 0; i
< bmap
->n_div
; ++i
) {
373 print_name(bmap
->dim
, out
, isl_dim_div
, i
, 0);
374 if (isl_int_is_zero(bmap
->div
[i
][0]))
376 fprintf(out
, " = [(");
377 print_affine(bmap
, out
, bmap
->div
[i
] + 1, set
);
379 isl_int_print(out
, bmap
->div
[i
][0], 0);
385 print_constraints(bmap
, out
, set
);
391 static void isl_basic_map_print_isl(__isl_keep isl_basic_map
*bmap
, FILE *out
,
392 int indent
, const char *prefix
, const char *suffix
)
396 fprintf(out
, "%*s%s", indent
, "", prefix
? prefix
: "");
397 if (isl_basic_map_dim(bmap
, isl_dim_param
) > 0) {
398 print_tuple(bmap
->dim
, out
, isl_dim_param
, 0);
399 fprintf(out
, " -> ");
402 print_tuple(bmap
->dim
, out
, isl_dim_in
, 0);
403 fprintf(out
, " -> ");
404 print_tuple(bmap
->dim
, out
, isl_dim_out
, 0);
406 print_disjunct(bmap
, out
, 0);
407 fprintf(out
, " }%s\n", suffix
? suffix
: "");
410 static void isl_basic_set_print_isl(__isl_keep isl_basic_set
*bset
, FILE *out
,
411 int indent
, const char *prefix
, const char *suffix
)
415 fprintf(out
, "%*s%s", indent
, "", prefix
? prefix
: "");
416 if (isl_basic_set_dim(bset
, isl_dim_param
) > 0) {
417 print_tuple(bset
->dim
, out
, isl_dim_param
, 0);
418 fprintf(out
, " -> ");
421 print_tuple(bset
->dim
, out
, isl_dim_set
, 1);
423 print_disjunct((isl_basic_map
*)bset
, out
, 1);
424 fprintf(out
, " }%s\n", suffix
? suffix
: "");
427 static void isl_map_print_isl(__isl_keep isl_map
*map
, FILE *out
, int indent
)
431 fprintf(out
, "%*s", indent
, "");
432 if (isl_map_dim(map
, isl_dim_param
) > 0) {
433 print_tuple(map
->dim
, out
, isl_dim_param
, 0);
434 fprintf(out
, " -> ");
437 print_tuple(map
->dim
, out
, isl_dim_in
, 0);
438 fprintf(out
, " -> ");
439 print_tuple(map
->dim
, out
, isl_dim_out
, 0);
442 fprintf(out
, "1 = 0");
443 for (i
= 0; i
< map
->n
; ++i
) {
445 fprintf(out
, " or ");
446 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
448 print_disjunct(map
->p
[i
], out
, 0);
449 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
452 fprintf(out
, " }\n");
455 static void isl_set_print_isl(__isl_keep isl_set
*set
, FILE *out
, int indent
)
459 fprintf(out
, "%*s", indent
, "");
460 if (isl_set_dim(set
, isl_dim_param
) > 0) {
461 print_tuple(set
->dim
, out
, isl_dim_param
, 0);
462 fprintf(out
, " -> ");
465 print_tuple(set
->dim
, out
, isl_dim_set
, 1);
468 fprintf(out
, "1 = 0");
469 for (i
= 0; i
< set
->n
; ++i
) {
471 fprintf(out
, " or ");
472 print_disjunct((isl_basic_map
*)set
->p
[i
], out
, 1);
474 fprintf(out
, " }\n");
477 void isl_basic_map_print(__isl_keep isl_basic_map
*bmap
, FILE *out
, int indent
,
478 const char *prefix
, const char *suffix
, unsigned output_format
)
482 if (output_format
== ISL_FORMAT_ISL
)
483 isl_basic_map_print_isl(bmap
, out
, indent
, prefix
, suffix
);
484 else if (output_format
== ISL_FORMAT_OMEGA
)
485 isl_basic_map_print_omega(bmap
, out
, indent
, prefix
, suffix
);
487 isl_assert(bmap
->ctx
, 0, return);
490 void isl_basic_set_print(struct isl_basic_set
*bset
, FILE *out
, int indent
,
491 const char *prefix
, const char *suffix
, unsigned output_format
)
495 if (output_format
== ISL_FORMAT_ISL
)
496 isl_basic_set_print_isl(bset
, out
, indent
, prefix
, suffix
);
497 else if (output_format
== ISL_FORMAT_POLYLIB
)
498 isl_basic_set_print_polylib(bset
, out
, indent
, prefix
, suffix
);
499 else if (output_format
== ISL_FORMAT_POLYLIB_CONSTRAINTS
)
500 bset_print_constraints_polylib(bset
, out
, indent
, prefix
, suffix
);
501 else if (output_format
== ISL_FORMAT_OMEGA
)
502 isl_basic_set_print_omega(bset
, out
, indent
, prefix
, suffix
);
504 isl_assert(bset
->ctx
, 0, return);
507 void isl_set_print(struct isl_set
*set
, FILE *out
, int indent
,
508 unsigned output_format
)
512 if (output_format
== ISL_FORMAT_ISL
)
513 isl_set_print_isl(set
, out
, indent
);
514 else if (output_format
== ISL_FORMAT_POLYLIB
)
515 isl_set_print_polylib(set
, out
, indent
);
516 else if (output_format
== ISL_FORMAT_OMEGA
)
517 isl_set_print_omega(set
, out
, indent
);
519 isl_assert(set
->ctx
, 0, return);
522 void isl_map_print(__isl_keep isl_map
*map
, FILE *out
, int indent
,
523 unsigned output_format
)
527 if (output_format
== ISL_FORMAT_ISL
)
528 isl_map_print_isl(map
, out
, indent
);
529 else if (output_format
== ISL_FORMAT_POLYLIB
)
530 isl_map_print_polylib(map
, out
, indent
);
531 else if (output_format
== ISL_FORMAT_OMEGA
)
532 isl_map_print_omega(map
, out
, indent
);
534 isl_assert(map
->ctx
, 0, return);