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
17 static void print_constraint_polylib(struct isl_basic_map
*bmap
,
19 FILE *out
, int indent
, const char *prefix
, const char *suffix
)
22 unsigned n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
23 unsigned n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
24 unsigned nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
25 isl_int
*c
= ineq
? bmap
->ineq
[n
] : bmap
->eq
[n
];
27 fprintf(out
, "%*s%s", indent
, "", prefix
? prefix
: "");
28 fprintf(out
, "%d", ineq
);
29 for (i
= 0; i
< n_out
; ++i
) {
31 isl_int_print(out
, c
[1+nparam
+n_in
+i
], 5);
33 for (i
= 0; i
< n_in
; ++i
) {
35 isl_int_print(out
, c
[1+nparam
+i
], 5);
37 for (i
= 0; i
< bmap
->n_div
; ++i
) {
39 isl_int_print(out
, c
[1+nparam
+n_in
+n_out
+i
], 5);
41 for (i
= 0; i
< nparam
; ++i
) {
43 isl_int_print(out
, c
[1+i
], 5);
46 isl_int_print(out
, c
[0], 5);
47 fprintf(out
, "%s\n", suffix
? suffix
: "");
50 static void print_constraints_polylib(struct isl_basic_map
*bmap
,
51 FILE *out
, int indent
, const char *prefix
, const char *suffix
)
55 for (i
= 0; i
< bmap
->n_eq
; ++i
)
56 print_constraint_polylib(bmap
, 0, i
, out
,
57 indent
, prefix
, suffix
);
58 for (i
= 0; i
< bmap
->n_ineq
; ++i
)
59 print_constraint_polylib(bmap
, 1, i
, out
,
60 indent
, prefix
, suffix
);
63 static void bset_print_constraints_polylib(struct isl_basic_set
*bset
,
64 FILE *out
, int indent
, const char *prefix
, const char *suffix
)
66 print_constraints_polylib((struct isl_basic_map
*)bset
,
67 out
, indent
, prefix
, suffix
);
70 static void isl_basic_map_print_polylib(struct isl_basic_map
*bmap
, FILE *out
,
71 int indent
, const char *prefix
, const char *suffix
)
73 unsigned total
= isl_basic_map_total_dim(bmap
);
74 fprintf(out
, "%*s%s", indent
, "", prefix
? prefix
: "");
75 fprintf(out
, "%d %d", bmap
->n_eq
+ bmap
->n_ineq
, 1 + total
+ 1);
76 fprintf(out
, "%s\n", suffix
? suffix
: "");
77 print_constraints_polylib(bmap
, out
, indent
, prefix
, suffix
);
80 static void isl_basic_set_print_polylib(struct isl_basic_set
*bset
, FILE *out
,
81 int indent
, const char *prefix
, const char *suffix
)
83 isl_basic_map_print_polylib((struct isl_basic_map
*)bset
, out
,
84 indent
, prefix
, suffix
);
87 static void isl_map_print_polylib(struct isl_map
*map
, FILE *out
, int indent
)
91 fprintf(out
, "%*s", indent
, "");
92 fprintf(out
, "%d\n", map
->n
);
93 for (i
= 0; i
< map
->n
; ++i
) {
95 isl_basic_map_print_polylib(map
->p
[i
], out
, indent
, NULL
, NULL
);
99 static void isl_set_print_polylib(struct isl_set
*set
, FILE *out
, int indent
)
101 isl_map_print_polylib((struct isl_map
*)set
, out
, indent
);
104 static int count_same_name(__isl_keep isl_dim
*dim
,
105 enum isl_dim_type type
, unsigned pos
, const char *name
)
111 for (t
= isl_dim_param
; t
<= type
&& t
<= isl_dim_out
; ++t
) {
112 s
= t
== type
? pos
: isl_dim_size(dim
, t
);
113 for (p
= 0; p
< s
; ++p
) {
114 const char *n
= isl_dim_get_name(dim
, t
, p
);
115 if (n
&& !strcmp(n
, name
))
122 static void print_name(struct isl_dim
*dim
, FILE *out
,
123 enum isl_dim_type type
, unsigned pos
, int set
)
129 name
= type
== isl_dim_div
? NULL
: isl_dim_get_name(dim
, type
, pos
);
133 if (type
== isl_dim_param
)
135 else if (type
== isl_dim_div
)
137 else if (set
|| type
== isl_dim_in
)
141 snprintf(buffer
, sizeof(buffer
), "%s%d", prefix
, pos
);
144 primes
= count_same_name(dim
, name
== buffer
? isl_dim_div
: type
,
146 fprintf(out
, "%s", name
);
151 static void print_var_list(struct isl_dim
*dim
, FILE *out
,
152 enum isl_dim_type type
, int set
)
156 for (i
= 0; i
< isl_dim_size(dim
, type
); ++i
) {
159 print_name(dim
, out
, type
, i
, set
);
163 static void print_tuple(__isl_keep isl_dim
*dim
, FILE *out
,
164 enum isl_dim_type type
, int set
)
167 print_var_list(dim
, out
, type
, set
);
171 static void print_omega_parameters(struct isl_dim
*dim
, FILE *out
,
172 int indent
, const char *prefix
, const char *suffix
)
174 if (isl_dim_size(dim
, isl_dim_param
) == 0)
177 fprintf(out
, "%*s%ssymbolic ", indent
, "", prefix
? prefix
: "");
178 print_var_list(dim
, out
, isl_dim_param
, 0);
179 fprintf(out
, ";%s\n", suffix
? suffix
: "");
182 static void print_term(__isl_keep isl_dim
*dim
,
183 isl_int c
, int pos
, FILE *out
, int set
)
185 enum isl_dim_type type
;
186 unsigned n_in
= isl_dim_size(dim
, isl_dim_in
);
187 unsigned n_out
= isl_dim_size(dim
, isl_dim_out
);
188 unsigned nparam
= isl_dim_size(dim
, isl_dim_param
);
191 isl_int_print(out
, c
, 0);
195 if (isl_int_is_one(c
))
197 else if (isl_int_is_negone(c
))
200 isl_int_print(out
, c
, 0);
201 if (pos
< 1 + nparam
) {
202 type
= isl_dim_param
;
204 } else if (pos
< 1 + nparam
+ n_in
) {
207 } else if (pos
< 1 + nparam
+ n_in
+ n_out
) {
209 pos
-= 1 + nparam
+ n_in
;
212 pos
-= 1 + nparam
+ n_in
+ n_out
;
214 print_name(dim
, out
, type
, pos
, set
);
217 static void print_affine(__isl_keep isl_basic_map
*bmap
,
218 __isl_keep isl_dim
*dim
, FILE *out
, isl_int
*c
, int set
)
222 unsigned len
= 1 + isl_basic_map_total_dim(bmap
);
224 for (i
= 0, first
= 1; i
< len
; ++i
) {
226 if (isl_int_is_zero(c
[i
]))
229 if (isl_int_is_neg(c
[i
])) {
231 isl_int_neg(c
[i
], c
[i
]);
237 print_term(dim
, c
[i
], i
, out
, set
);
239 isl_int_neg(c
[i
], c
[i
]);
245 static void print_constraint(struct isl_basic_map
*bmap
,
246 __isl_keep isl_dim
*dim
, FILE *out
,
247 isl_int
*c
, int last
, const char *op
, int first_constraint
, int set
)
249 if (!first_constraint
)
250 fprintf(out
, " and ");
252 isl_int_abs(c
[last
], c
[last
]);
254 print_term(dim
, c
[last
], last
, out
, set
);
256 fprintf(out
, " %s ", op
);
258 isl_int_set_si(c
[last
], 0);
259 print_affine(bmap
, dim
, out
, c
, set
);
262 static void print_constraints(__isl_keep isl_basic_map
*bmap
,
263 __isl_keep isl_dim
*dim
, FILE *out
, int set
)
267 unsigned total
= isl_basic_map_total_dim(bmap
);
269 c
= isl_vec_alloc(bmap
->ctx
, 1 + total
);
273 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
274 int l
= isl_seq_last_non_zero(bmap
->eq
[i
], 1 + total
);
275 isl_assert(bmap
->ctx
, l
>= 0, return);
276 if (isl_int_is_neg(bmap
->eq
[i
][l
]))
277 isl_seq_cpy(c
->el
, bmap
->eq
[i
], 1 + total
);
279 isl_seq_neg(c
->el
, bmap
->eq
[i
], 1 + total
);
280 print_constraint(bmap
, dim
, out
, c
->el
, l
,
281 "=", i
== bmap
->n_eq
- 1, set
);
283 for (i
= 0; i
< bmap
->n_ineq
; ++i
) {
284 int l
= isl_seq_last_non_zero(bmap
->ineq
[i
], 1 + total
);
286 isl_assert(bmap
->ctx
, l
>= 0, return);
287 s
= isl_int_sgn(bmap
->ineq
[i
][l
]);
289 isl_seq_cpy(c
->el
, bmap
->ineq
[i
], 1 + total
);
291 isl_seq_neg(c
->el
, bmap
->ineq
[i
], 1 + total
);
292 print_constraint(bmap
, dim
, out
, c
->el
, l
,
293 s
< 0 ? "<=" : ">=", !bmap
->n_eq
&& !i
, set
);
299 static void print_omega_constraints(__isl_keep isl_basic_map
*bmap
, FILE *out
,
302 if (bmap
->n_eq
+ bmap
->n_ineq
== 0)
306 if (bmap
->n_div
> 0) {
308 fprintf(out
, "exists (");
309 for (i
= 0; i
< bmap
->n_div
; ++i
) {
312 print_name(bmap
->dim
, out
, isl_dim_div
, i
, 0);
316 print_constraints(bmap
, bmap
->dim
, out
, set
);
321 static void basic_map_print_omega(struct isl_basic_map
*bmap
, FILE *out
)
324 print_var_list(bmap
->dim
, out
, isl_dim_in
, 0);
325 fprintf(out
, "] -> [");
326 print_var_list(bmap
->dim
, out
, isl_dim_out
, 0);
328 print_omega_constraints(bmap
, out
, 0);
332 static void isl_basic_map_print_omega(struct isl_basic_map
*bmap
, FILE *out
,
333 int indent
, const char *prefix
, const char *suffix
)
335 print_omega_parameters(bmap
->dim
, out
, indent
, prefix
, suffix
);
337 fprintf(out
, "%*s%s", indent
, "", prefix
? prefix
: "");
338 basic_map_print_omega(bmap
, out
);
339 fprintf(out
, "%s\n", suffix
? suffix
: "");
342 static void basic_set_print_omega(struct isl_basic_set
*bset
, FILE *out
)
345 print_var_list(bset
->dim
, out
, isl_dim_set
, 1);
347 print_omega_constraints((isl_basic_map
*)bset
, out
, 1);
351 static void isl_basic_set_print_omega(struct isl_basic_set
*bset
, FILE *out
,
352 int indent
, const char *prefix
, const char *suffix
)
354 print_omega_parameters(bset
->dim
, out
, indent
, prefix
, suffix
);
356 fprintf(out
, "%*s%s", indent
, "", prefix
? prefix
: "");
357 basic_set_print_omega(bset
, out
);
358 fprintf(out
, "%s\n", suffix
? suffix
: "");
361 static void isl_map_print_omega(struct isl_map
*map
, FILE *out
, int indent
)
365 print_omega_parameters(map
->dim
, out
, indent
, "", "");
367 fprintf(out
, "%*s", indent
, "");
368 for (i
= 0; i
< map
->n
; ++i
) {
370 fprintf(out
, " union ");
371 basic_map_print_omega(map
->p
[i
], out
);
376 static void isl_set_print_omega(struct isl_set
*set
, FILE *out
, int indent
)
380 print_omega_parameters(set
->dim
, out
, indent
, "", "");
382 fprintf(out
, "%*s", indent
, "");
383 for (i
= 0; i
< set
->n
; ++i
) {
385 fprintf(out
, " union ");
386 basic_set_print_omega(set
->p
[i
], out
);
391 static void print_disjunct(__isl_keep isl_basic_map
*bmap
,
392 __isl_keep isl_dim
*dim
, FILE *out
, int set
)
394 if (bmap
->n_div
> 0) {
396 fprintf(out
, "exists (");
397 for (i
= 0; i
< bmap
->n_div
; ++i
) {
400 print_name(dim
, out
, isl_dim_div
, i
, 0);
401 if (isl_int_is_zero(bmap
->div
[i
][0]))
403 fprintf(out
, " = [(");
404 print_affine(bmap
, dim
, out
, bmap
->div
[i
] + 1, set
);
406 isl_int_print(out
, bmap
->div
[i
][0], 0);
412 print_constraints(bmap
, dim
, out
, set
);
418 static void isl_basic_map_print_isl(__isl_keep isl_basic_map
*bmap
, FILE *out
,
419 int indent
, const char *prefix
, const char *suffix
)
423 fprintf(out
, "%*s%s", indent
, "", prefix
? prefix
: "");
424 if (isl_basic_map_dim(bmap
, isl_dim_param
) > 0) {
425 print_tuple(bmap
->dim
, out
, isl_dim_param
, 0);
426 fprintf(out
, " -> ");
429 print_tuple(bmap
->dim
, out
, isl_dim_in
, 0);
430 fprintf(out
, " -> ");
431 print_tuple(bmap
->dim
, out
, isl_dim_out
, 0);
433 print_disjunct(bmap
, bmap
->dim
, out
, 0);
434 fprintf(out
, " }%s\n", suffix
? suffix
: "");
437 static void isl_basic_set_print_isl(__isl_keep isl_basic_set
*bset
, FILE *out
,
438 int indent
, const char *prefix
, const char *suffix
)
442 fprintf(out
, "%*s%s", indent
, "", prefix
? prefix
: "");
443 if (isl_basic_set_dim(bset
, isl_dim_param
) > 0) {
444 print_tuple(bset
->dim
, out
, isl_dim_param
, 0);
445 fprintf(out
, " -> ");
448 print_tuple(bset
->dim
, out
, isl_dim_set
, 1);
450 print_disjunct((isl_basic_map
*)bset
, bset
->dim
, out
, 1);
451 fprintf(out
, " }%s\n", suffix
? suffix
: "");
454 static void isl_map_print_isl(__isl_keep isl_map
*map
, FILE *out
, int indent
)
458 fprintf(out
, "%*s", indent
, "");
459 if (isl_map_dim(map
, isl_dim_param
) > 0) {
460 print_tuple(map
->dim
, out
, isl_dim_param
, 0);
461 fprintf(out
, " -> ");
464 print_tuple(map
->dim
, out
, isl_dim_in
, 0);
465 fprintf(out
, " -> ");
466 print_tuple(map
->dim
, out
, isl_dim_out
, 0);
469 fprintf(out
, "1 = 0");
470 for (i
= 0; i
< map
->n
; ++i
) {
472 fprintf(out
, " or ");
473 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
475 print_disjunct(map
->p
[i
], map
->dim
, out
, 0);
476 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
479 fprintf(out
, " }\n");
482 static void isl_set_print_isl(__isl_keep isl_set
*set
, FILE *out
, int indent
)
486 fprintf(out
, "%*s", indent
, "");
487 if (isl_set_dim(set
, isl_dim_param
) > 0) {
488 print_tuple(set
->dim
, out
, isl_dim_param
, 0);
489 fprintf(out
, " -> ");
492 print_tuple(set
->dim
, out
, isl_dim_set
, 1);
495 fprintf(out
, "1 = 0");
496 for (i
= 0; i
< set
->n
; ++i
) {
498 fprintf(out
, " or ");
499 print_disjunct((isl_basic_map
*)set
->p
[i
], set
->dim
, out
, 1);
501 fprintf(out
, " }\n");
504 void isl_basic_map_print(__isl_keep isl_basic_map
*bmap
, FILE *out
, int indent
,
505 const char *prefix
, const char *suffix
, unsigned output_format
)
509 if (output_format
== ISL_FORMAT_ISL
)
510 isl_basic_map_print_isl(bmap
, out
, indent
, prefix
, suffix
);
511 else if (output_format
== ISL_FORMAT_OMEGA
)
512 isl_basic_map_print_omega(bmap
, out
, indent
, prefix
, suffix
);
514 isl_assert(bmap
->ctx
, 0, return);
517 void isl_basic_set_print(struct isl_basic_set
*bset
, FILE *out
, int indent
,
518 const char *prefix
, const char *suffix
, unsigned output_format
)
522 if (output_format
== ISL_FORMAT_ISL
)
523 isl_basic_set_print_isl(bset
, out
, indent
, prefix
, suffix
);
524 else if (output_format
== ISL_FORMAT_POLYLIB
)
525 isl_basic_set_print_polylib(bset
, out
, indent
, prefix
, suffix
);
526 else if (output_format
== ISL_FORMAT_POLYLIB_CONSTRAINTS
)
527 bset_print_constraints_polylib(bset
, out
, indent
, prefix
, suffix
);
528 else if (output_format
== ISL_FORMAT_OMEGA
)
529 isl_basic_set_print_omega(bset
, out
, indent
, prefix
, suffix
);
531 isl_assert(bset
->ctx
, 0, return);
534 void isl_set_print(struct isl_set
*set
, FILE *out
, int indent
,
535 unsigned output_format
)
539 if (output_format
== ISL_FORMAT_ISL
)
540 isl_set_print_isl(set
, out
, indent
);
541 else if (output_format
== ISL_FORMAT_POLYLIB
)
542 isl_set_print_polylib(set
, out
, indent
);
543 else if (output_format
== ISL_FORMAT_OMEGA
)
544 isl_set_print_omega(set
, out
, indent
);
546 isl_assert(set
->ctx
, 0, return);
549 void isl_map_print(__isl_keep isl_map
*map
, FILE *out
, int indent
,
550 unsigned output_format
)
554 if (output_format
== ISL_FORMAT_ISL
)
555 isl_map_print_isl(map
, out
, indent
);
556 else if (output_format
== ISL_FORMAT_POLYLIB
)
557 isl_map_print_polylib(map
, out
, indent
);
558 else if (output_format
== ISL_FORMAT_OMEGA
)
559 isl_map_print_omega(map
, out
, indent
);
561 isl_assert(map
->ctx
, 0, return);