2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
6 * Use of this software is governed by the MIT license
8 * Written by Sven Verdoolaege, K.U.Leuven, Departement
9 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
10 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
11 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
12 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
17 #include <isl_ctx_private.h>
18 #include <isl_map_private.h>
21 #include <isl_polynomial_private.h>
22 #include <isl_printer_private.h>
23 #include <isl_space_private.h>
24 #include <isl_mat_private.h>
25 #include <isl_vec_private.h>
26 #include <isl/union_set.h>
27 #include <isl/union_map.h>
28 #include <isl/constraint.h>
29 #include <isl_local_space_private.h>
30 #include <isl_aff_private.h>
31 #include <isl_val_private.h>
32 #include <isl_constraint_private.h>
33 #include <isl/ast_build.h>
35 #include <isl_output_private.h>
37 #include <bset_to_bmap.c>
38 #include <set_to_map.c>
39 #include <uset_to_umap.c>
41 static const char *s_to
[2] = { " -> ", " \\to " };
42 static const char *s_and
[2] = { " and ", " \\wedge " };
43 static const char *s_or
[2] = { " or ", " \\vee " };
44 static const char *s_le
[2] = { "<=", "\\le" };
45 static const char *s_ge
[2] = { ">=", "\\ge" };
46 static const char *s_open_set
[2] = { "{ ", "\\{\\, " };
47 static const char *s_close_set
[2] = { " }", " \\,\\}" };
48 static const char *s_open_list
[2] = { "[", "(" };
49 static const char *s_close_list
[2] = { "]", ")" };
50 static const char *s_such_that
[2] = { " : ", " \\mid " };
51 static const char *s_open_exists
[2] = { "exists (", "\\exists \\, " };
52 static const char *s_close_exists
[2] = { ")", "" };
53 static const char *s_div_prefix
[2] = { "e", "\\alpha_" };
54 static const char *s_mod
[2] = { "mod", "\\bmod" };
55 static const char *s_param_prefix
[2] = { "p", "p_" };
56 static const char *s_input_prefix
[2] = { "i", "i_" };
57 static const char *s_output_prefix
[2] = { "o", "o_" };
59 static __isl_give isl_printer
*print_constraint_polylib(
60 struct isl_basic_map
*bmap
, int ineq
, int n
, __isl_take isl_printer
*p
)
63 unsigned n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
64 unsigned n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
65 unsigned nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
66 isl_int
*c
= ineq
? bmap
->ineq
[n
] : bmap
->eq
[n
];
68 p
= isl_printer_start_line(p
);
69 p
= isl_printer_print_int(p
, ineq
);
70 for (i
= 0; i
< n_out
; ++i
) {
71 p
= isl_printer_print_str(p
, " ");
72 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+n_in
+i
]);
74 for (i
= 0; i
< n_in
; ++i
) {
75 p
= isl_printer_print_str(p
, " ");
76 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+i
]);
78 for (i
= 0; i
< bmap
->n_div
; ++i
) {
79 p
= isl_printer_print_str(p
, " ");
80 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+n_in
+n_out
+i
]);
82 for (i
= 0; i
< nparam
; ++i
) {
83 p
= isl_printer_print_str(p
, " ");
84 p
= isl_printer_print_isl_int(p
, c
[1+i
]);
86 p
= isl_printer_print_str(p
, " ");
87 p
= isl_printer_print_isl_int(p
, c
[0]);
88 p
= isl_printer_end_line(p
);
92 static __isl_give isl_printer
*print_constraints_polylib(
93 struct isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
97 p
= isl_printer_set_isl_int_width(p
, 5);
99 for (i
= 0; i
< bmap
->n_eq
; ++i
)
100 p
= print_constraint_polylib(bmap
, 0, i
, p
);
101 for (i
= 0; i
< bmap
->n_ineq
; ++i
)
102 p
= print_constraint_polylib(bmap
, 1, i
, p
);
107 static __isl_give isl_printer
*bset_print_constraints_polylib(
108 struct isl_basic_set
*bset
, __isl_take isl_printer
*p
)
110 return print_constraints_polylib(bset_to_bmap(bset
), p
);
113 static __isl_give isl_printer
*isl_basic_map_print_polylib(
114 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
, int ext
)
116 unsigned total
= isl_basic_map_total_dim(bmap
);
117 p
= isl_printer_start_line(p
);
118 p
= isl_printer_print_int(p
, bmap
->n_eq
+ bmap
->n_ineq
);
119 p
= isl_printer_print_str(p
, " ");
120 p
= isl_printer_print_int(p
, 1 + total
+ 1);
122 p
= isl_printer_print_str(p
, " ");
123 p
= isl_printer_print_int(p
,
124 isl_basic_map_dim(bmap
, isl_dim_out
));
125 p
= isl_printer_print_str(p
, " ");
126 p
= isl_printer_print_int(p
,
127 isl_basic_map_dim(bmap
, isl_dim_in
));
128 p
= isl_printer_print_str(p
, " ");
129 p
= isl_printer_print_int(p
,
130 isl_basic_map_dim(bmap
, isl_dim_div
));
131 p
= isl_printer_print_str(p
, " ");
132 p
= isl_printer_print_int(p
,
133 isl_basic_map_dim(bmap
, isl_dim_param
));
135 p
= isl_printer_end_line(p
);
136 return print_constraints_polylib(bmap
, p
);
139 static __isl_give isl_printer
*isl_basic_set_print_polylib(
140 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
, int ext
)
142 return isl_basic_map_print_polylib(bset_to_bmap(bset
), p
, ext
);
145 static __isl_give isl_printer
*isl_map_print_polylib(__isl_keep isl_map
*map
,
146 __isl_take isl_printer
*p
, int ext
)
150 p
= isl_printer_start_line(p
);
151 p
= isl_printer_print_int(p
, map
->n
);
152 p
= isl_printer_end_line(p
);
153 for (i
= 0; i
< map
->n
; ++i
) {
154 p
= isl_printer_start_line(p
);
155 p
= isl_printer_end_line(p
);
156 p
= isl_basic_map_print_polylib(map
->p
[i
], p
, ext
);
161 static __isl_give isl_printer
*isl_set_print_polylib(__isl_keep isl_set
*set
,
162 __isl_take isl_printer
*p
, int ext
)
164 return isl_map_print_polylib(set_to_map(set
), p
, ext
);
167 static int count_same_name(__isl_keep isl_space
*space
,
168 enum isl_dim_type type
, unsigned pos
, const char *name
)
174 for (t
= isl_dim_param
; t
<= type
&& t
<= isl_dim_out
; ++t
) {
175 s
= t
== type
? pos
: isl_space_dim(space
, t
);
176 for (p
= 0; p
< s
; ++p
) {
177 const char *n
= isl_space_get_dim_name(space
, t
, p
);
178 if (n
&& !strcmp(n
, name
))
185 /* Print the name of the variable of type "type" and position "pos"
188 static __isl_give isl_printer
*print_name(__isl_keep isl_space
*space
,
189 __isl_take isl_printer
*p
, enum isl_dim_type type
, unsigned pos
,
196 name
= type
== isl_dim_div
? NULL
197 : isl_space_get_dim_name(space
, type
, pos
);
201 if (type
== isl_dim_param
)
202 prefix
= s_param_prefix
[latex
];
203 else if (type
== isl_dim_div
)
204 prefix
= s_div_prefix
[latex
];
205 else if (isl_space_is_set(space
) || type
== isl_dim_in
)
206 prefix
= s_input_prefix
[latex
];
208 prefix
= s_output_prefix
[latex
];
209 snprintf(buffer
, sizeof(buffer
), "%s%d", prefix
, pos
);
212 primes
= count_same_name(space
, name
== buffer
? isl_dim_div
: type
,
214 p
= isl_printer_print_str(p
, name
);
216 p
= isl_printer_print_str(p
, "'");
220 static enum isl_dim_type
pos2type(__isl_keep isl_space
*space
, unsigned *pos
)
222 enum isl_dim_type type
;
223 unsigned n_in
= isl_space_dim(space
, isl_dim_in
);
224 unsigned n_out
= isl_space_dim(space
, isl_dim_out
);
225 unsigned nparam
= isl_space_dim(space
, isl_dim_param
);
227 if (*pos
< 1 + nparam
) {
228 type
= isl_dim_param
;
230 } else if (*pos
< 1 + nparam
+ n_in
) {
233 } else if (*pos
< 1 + nparam
+ n_in
+ n_out
) {
235 *pos
-= 1 + nparam
+ n_in
;
238 *pos
-= 1 + nparam
+ n_in
+ n_out
;
244 /* Can the div expression of the integer division at position "row" of "div"
246 * In particular, are the div expressions available and does the selected
247 * variable have a known explicit representation?
248 * Furthermore, the Omega format does not allow any div expressions
251 static isl_bool
can_print_div_expr(__isl_keep isl_printer
*p
,
252 __isl_keep isl_mat
*div
, int pos
)
254 if (p
->output_format
== ISL_FORMAT_OMEGA
)
255 return isl_bool_false
;
257 return isl_bool_false
;
258 return !isl_int_is_zero(div
->row
[pos
][0]);
261 static __isl_give isl_printer
*print_div(__isl_keep isl_space
*dim
,
262 __isl_keep isl_mat
*div
, int pos
, __isl_take isl_printer
*p
);
264 static __isl_give isl_printer
*print_term(__isl_keep isl_space
*space
,
265 __isl_keep isl_mat
*div
,
266 isl_int c
, unsigned pos
, __isl_take isl_printer
*p
, int latex
)
268 enum isl_dim_type type
;
272 return isl_printer_free(p
);
275 return isl_printer_print_isl_int(p
, c
);
277 type
= pos2type(space
, &pos
);
278 print_div_def
= type
== isl_dim_div
&& can_print_div_expr(p
, div
, pos
);
280 if (isl_int_is_one(c
))
282 else if (isl_int_is_negone(c
))
283 p
= isl_printer_print_str(p
, "-");
285 p
= isl_printer_print_isl_int(p
, c
);
286 if (p
->output_format
== ISL_FORMAT_C
|| print_div_def
)
287 p
= isl_printer_print_str(p
, "*");
290 p
= print_div(space
, div
, pos
, p
);
292 p
= print_name(space
, p
, type
, pos
, latex
);
296 static __isl_give isl_printer
*print_affine_of_len(__isl_keep isl_space
*dim
,
297 __isl_keep isl_mat
*div
,
298 __isl_take isl_printer
*p
, isl_int
*c
, int len
)
303 for (i
= 0, first
= 1; i
< len
; ++i
) {
305 if (isl_int_is_zero(c
[i
]))
308 if (isl_int_is_neg(c
[i
])) {
310 isl_int_neg(c
[i
], c
[i
]);
311 p
= isl_printer_print_str(p
, " - ");
313 p
= isl_printer_print_str(p
, " + ");
316 p
= print_term(dim
, div
, c
[i
], i
, p
, 0);
318 isl_int_neg(c
[i
], c
[i
]);
321 p
= isl_printer_print_str(p
, "0");
325 /* Print an affine expression "c"
326 * to "p", with the variable names taken from "space" and
327 * the integer division definitions taken from "div".
329 static __isl_give isl_printer
*print_affine(__isl_take isl_printer
*p
,
330 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, isl_int
*c
)
336 return isl_printer_free(p
);
337 n_div
= isl_mat_rows(div
);
338 len
= 1 + isl_space_dim(space
, isl_dim_all
) + n_div
;
339 return print_affine_of_len(space
, div
, p
, c
, len
);
342 /* offset is the offset of local_space inside data->type of data->space.
344 static __isl_give isl_printer
*print_nested_var_list(__isl_take isl_printer
*p
,
345 __isl_keep isl_space
*local_space
, enum isl_dim_type local_type
,
346 struct isl_print_space_data
*data
, int offset
)
350 if (data
->space
!= local_space
&& local_type
== isl_dim_out
)
351 offset
+= local_space
->n_in
;
353 for (i
= 0; i
< isl_space_dim(local_space
, local_type
); ++i
) {
355 p
= isl_printer_print_str(p
, ", ");
357 p
= data
->print_dim(p
, data
, offset
+ i
);
359 p
= print_name(data
->space
, p
, data
->type
, offset
+ i
,
365 static __isl_give isl_printer
*print_var_list(__isl_take isl_printer
*p
,
366 __isl_keep isl_space
*space
, enum isl_dim_type type
)
368 struct isl_print_space_data data
= { .space
= space
, .type
= type
};
370 return print_nested_var_list(p
, space
, type
, &data
, 0);
373 static __isl_give isl_printer
*print_nested_map_dim(__isl_take isl_printer
*p
,
374 __isl_keep isl_space
*local_dim
,
375 struct isl_print_space_data
*data
, int offset
);
377 static __isl_give isl_printer
*print_nested_tuple(__isl_take isl_printer
*p
,
378 __isl_keep isl_space
*local_space
, enum isl_dim_type local_type
,
379 struct isl_print_space_data
*data
, int offset
)
381 const char *name
= NULL
;
382 unsigned n
= isl_space_dim(local_space
, local_type
);
383 if ((local_type
== isl_dim_in
|| local_type
== isl_dim_out
)) {
384 name
= isl_space_get_tuple_name(local_space
, local_type
);
387 p
= isl_printer_print_str(p
, "\\mathrm{");
388 p
= isl_printer_print_str(p
, name
);
390 p
= isl_printer_print_str(p
, "}");
393 if (!data
->latex
|| n
!= 1 || name
)
394 p
= isl_printer_print_str(p
, s_open_list
[data
->latex
]);
395 if ((local_type
== isl_dim_in
|| local_type
== isl_dim_out
) &&
396 local_space
->nested
[local_type
- isl_dim_in
]) {
397 if (data
->space
!= local_space
&& local_type
== isl_dim_out
)
398 offset
+= local_space
->n_in
;
399 p
= print_nested_map_dim(p
,
400 local_space
->nested
[local_type
- isl_dim_in
],
403 p
= print_nested_var_list(p
, local_space
, local_type
, data
,
405 if (!data
->latex
|| n
!= 1 || name
)
406 p
= isl_printer_print_str(p
, s_close_list
[data
->latex
]);
410 static __isl_give isl_printer
*print_tuple(__isl_keep isl_space
*dim
,
411 __isl_take isl_printer
*p
, enum isl_dim_type type
,
412 struct isl_print_space_data
*data
)
416 return print_nested_tuple(p
, dim
, type
, data
, 0);
419 static __isl_give isl_printer
*print_nested_map_dim(__isl_take isl_printer
*p
,
420 __isl_keep isl_space
*local_dim
,
421 struct isl_print_space_data
*data
, int offset
)
423 p
= print_nested_tuple(p
, local_dim
, isl_dim_in
, data
, offset
);
424 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
425 p
= print_nested_tuple(p
, local_dim
, isl_dim_out
, data
, offset
);
430 __isl_give isl_printer
*isl_print_space(__isl_keep isl_space
*space
,
431 __isl_take isl_printer
*p
, int rational
,
432 struct isl_print_space_data
*data
)
434 if (rational
&& !data
->latex
)
435 p
= isl_printer_print_str(p
, "rat: ");
436 if (isl_space_is_params(space
))
438 else if (isl_space_is_set(space
))
439 p
= print_tuple(space
, p
, isl_dim_set
, data
);
441 p
= print_tuple(space
, p
, isl_dim_in
, data
);
442 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
443 p
= print_tuple(space
, p
, isl_dim_out
, data
);
449 static __isl_give isl_printer
*print_omega_parameters(
450 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
)
452 if (isl_space_dim(space
, isl_dim_param
) == 0)
455 p
= isl_printer_start_line(p
);
456 p
= isl_printer_print_str(p
, "symbolic ");
457 p
= print_var_list(p
, space
, isl_dim_param
);
458 p
= isl_printer_print_str(p
, ";");
459 p
= isl_printer_end_line(p
);
463 /* Does the inequality constraint following "i" in "bmap"
464 * have an opposite value for the same last coefficient?
465 * "last" is the position of the last coefficient of inequality "i".
466 * If the next constraint is a div constraint, then it is ignored
467 * since div constraints are not printed.
469 static isl_bool
next_is_opposite(__isl_keep isl_basic_map
*bmap
, int i
,
472 unsigned total
= isl_basic_map_total_dim(bmap
);
473 unsigned o_div
= isl_basic_map_offset(bmap
, isl_dim_div
);
475 if (i
+ 1 >= bmap
->n_ineq
)
476 return isl_bool_false
;
477 if (isl_seq_last_non_zero(bmap
->ineq
[i
+ 1], 1 + total
) != last
)
478 return isl_bool_false
;
481 is_div
= isl_basic_map_is_div_constraint(bmap
,
482 bmap
->ineq
[i
+ 1], last
- o_div
);
484 return isl_bool_error
;
486 return isl_bool_false
;
488 return isl_int_abs_eq(bmap
->ineq
[i
][last
], bmap
->ineq
[i
+ 1][last
]) &&
489 !isl_int_eq(bmap
->ineq
[i
][last
], bmap
->ineq
[i
+ 1][last
]);
492 /* Return a string representation of the operator used when
493 * printing a constraint where the LHS is greater than or equal to the LHS
494 * (sign > 0) or smaller than or equal to the LHS (sign < 0).
495 * If "strict" is set, then return the strict version of the comparison
498 static const char *constraint_op(int sign
, int strict
, int latex
)
501 return sign
< 0 ? "<" : ">";
508 /* Print one side of a constraint "c" to "p", with
509 * the variable names taken from "space" and the integer division definitions
511 * "last" is the position of the last non-zero coefficient.
512 * Let c' be the result of zeroing out this coefficient, then
513 * the partial constraint
519 static __isl_give isl_printer
*print_half_constraint(__isl_take isl_printer
*p
,
520 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
521 isl_int
*c
, int last
, const char *op
, int latex
)
523 isl_int_set_si(c
[last
], 0);
524 p
= print_affine(p
, space
, div
, c
);
526 p
= isl_printer_print_str(p
, " ");
527 p
= isl_printer_print_str(p
, op
);
528 p
= isl_printer_print_str(p
, " ");
533 /* Print a constraint "c" to "p", with the variable names
534 * taken from "space" and the integer division definitions taken from "div".
535 * "last" is the position of the last non-zero coefficient, which is
536 * moreover assumed to be negative.
537 * Let c' be the result of zeroing out this coefficient, then
538 * the constraint is printed in the form
542 static __isl_give isl_printer
*print_constraint(__isl_take isl_printer
*p
,
543 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
544 isl_int
*c
, int last
, const char *op
, int latex
)
546 isl_int_abs(c
[last
], c
[last
]);
548 p
= print_term(space
, div
, c
[last
], last
, p
, latex
);
550 p
= isl_printer_print_str(p
, " ");
551 p
= isl_printer_print_str(p
, op
);
552 p
= isl_printer_print_str(p
, " ");
554 isl_int_set_si(c
[last
], 0);
555 p
= print_affine(p
, space
, div
, c
);
560 /* Given an integer division
564 * at position "pos" in "div", print the corresponding modulo expression
568 * to "p". The variable names are taken from "space", while any
569 * nested integer division definitions are taken from "div".
571 static __isl_give isl_printer
*print_mod(__isl_take isl_printer
*p
,
572 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int pos
,
576 return isl_printer_free(p
);
578 p
= isl_printer_print_str(p
, "(");
579 p
= print_affine_of_len(space
, div
, p
,
580 div
->row
[pos
] + 1, div
->n_col
- 1);
581 p
= isl_printer_print_str(p
, ") ");
582 p
= isl_printer_print_str(p
, s_mod
[latex
]);
583 p
= isl_printer_print_str(p
, " ");
584 p
= isl_printer_print_isl_int(p
, div
->row
[pos
][0]);
588 /* Can the equality constraints "c" be printed as a modulo constraint?
589 * In particular, is of the form
591 * f - a m floor(g/m) = 0,
593 * with c = -a m the coefficient at position "pos"?
594 * Return the position of the corresponding integer division if so.
595 * Return the number of integer divisions if not.
596 * Return -1 on error.
598 * Modulo constraints are currently not printed in C format.
599 * Other than that, "pos" needs to correspond to an integer division
600 * with explicit representation and "c" needs to be a multiple
601 * of the denominator of the integer division.
603 static int print_as_modulo_pos(__isl_keep isl_printer
*p
,
604 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, unsigned pos
,
609 enum isl_dim_type type
;
613 n_div
= isl_mat_rows(div
);
614 if (p
->output_format
== ISL_FORMAT_C
)
616 type
= pos2type(space
, &pos
);
617 if (type
!= isl_dim_div
)
619 can_print
= can_print_div_expr(p
, div
, pos
);
624 if (!isl_int_is_divisible_by(c
, div
->row
[pos
][0]))
629 /* Print equality constraint "c" to "p" as a modulo constraint,
630 * with the variable names taken from "space" and
631 * the integer division definitions taken from "div".
632 * "last" is the position of the last non-zero coefficient, which is
633 * moreover assumed to be negative and a multiple of the denominator
634 * of the corresponding integer division. "div_pos" is the corresponding
635 * position in the sequence of integer divisions.
637 * The equality is of the form
639 * f - a m floor(g/m) = 0.
643 * a (g mod m) = -f + a g
645 static __isl_give isl_printer
*print_eq_mod_constraint(
646 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
,
647 __isl_keep isl_mat
*div
, unsigned div_pos
,
648 isl_int
*c
, int last
, int latex
)
653 ctx
= isl_printer_get_ctx(p
);
654 isl_int_divexact(c
[last
], c
[last
], div
->row
[div_pos
][0]);
655 isl_int_abs(c
[last
], c
[last
]);
656 multiple
= !isl_int_is_one(c
[last
]);
658 p
= isl_printer_print_isl_int(p
, c
[last
]);
659 p
= isl_printer_print_str(p
, "*(");
661 p
= print_mod(p
, space
, div
, div_pos
, latex
);
663 p
= isl_printer_print_str(p
, ")");
664 p
= isl_printer_print_str(p
, " = ");
665 isl_seq_combine(c
, ctx
->negone
, c
,
666 c
[last
], div
->row
[div_pos
] + 1, last
);
667 isl_int_set_si(c
[last
], 0);
668 p
= print_affine(p
, space
, div
, c
);
672 /* Print equality constraint "c" to "p", with the variable names
673 * taken from "space" and the integer division definitions taken from "div".
674 * "last" is the position of the last non-zero coefficient, which is
675 * moreover assumed to be negative.
677 * If possible, print the equality constraint as a modulo constraint.
679 static __isl_give isl_printer
*print_eq_constraint(__isl_take isl_printer
*p
,
680 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, isl_int
*c
,
686 n_div
= isl_mat_rows(div
);
687 div_pos
= print_as_modulo_pos(p
, space
, div
, last
, c
[last
]);
689 return isl_printer_free(p
);
691 return print_eq_mod_constraint(p
, space
, div
, div_pos
,
693 return print_constraint(p
, space
, div
, c
, last
, "=", latex
);
696 /* Print the constraints of "bmap" to "p".
697 * The names of the variables are taken from "space" and
698 * the integer division definitions are taken from "div".
699 * Div constraints are only printed in "dump" mode.
700 * The constraints are sorted prior to printing (except in "dump" mode).
702 * If x is the last variable with a non-zero coefficient,
711 * while an upper bound
719 * If the next constraint has an opposite sign for the same last coefficient,
720 * then it is printed as
728 * instead. In fact, the "a x" part is not printed explicitly, but
729 * reused from the next constraint, which is therefore treated as
730 * a first constraint in the conjunction.
732 * If the constant term of "f" is -1, then "f" is replaced by "f + 1" and
733 * the comparison operator is replaced by the strict variant.
734 * Essentially, ">= 1" is replaced by "> 0".
736 static __isl_give isl_printer
*print_constraints(__isl_keep isl_basic_map
*bmap
,
737 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
738 __isl_take isl_printer
*p
, int latex
)
742 int rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
743 unsigned total
= isl_basic_map_total_dim(bmap
);
744 unsigned o_div
= isl_basic_map_offset(bmap
, isl_dim_div
);
750 bmap
= isl_basic_map_copy(bmap
);
753 bmap
= isl_basic_map_sort_constraints(bmap
);
757 c
= isl_vec_alloc(bmap
->ctx
, 1 + total
);
761 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
762 int l
= isl_seq_last_non_zero(bmap
->eq
[i
], 1 + total
);
764 if (i
!= bmap
->n_eq
- 1)
765 p
= isl_printer_print_str(p
, s_and
[latex
]);
766 p
= isl_printer_print_str(p
, "0 = 0");
770 p
= isl_printer_print_str(p
, s_and
[latex
]);
771 if (isl_int_is_neg(bmap
->eq
[i
][l
]))
772 isl_seq_cpy(c
->el
, bmap
->eq
[i
], 1 + total
);
774 isl_seq_neg(c
->el
, bmap
->eq
[i
], 1 + total
);
775 p
= print_eq_constraint(p
, space
, div
, c
->el
, l
, latex
);
778 for (i
= 0; i
< bmap
->n_ineq
; ++i
) {
780 int l
= isl_seq_last_non_zero(bmap
->ineq
[i
], 1 + total
);
786 if (!dump
&& l
>= o_div
&&
787 can_print_div_expr(p
, div
, l
- o_div
)) {
789 is_div
= isl_basic_map_is_div_constraint(bmap
,
790 bmap
->ineq
[i
], l
- o_div
);
797 p
= isl_printer_print_str(p
, s_and
[latex
]);
798 s
= isl_int_sgn(bmap
->ineq
[i
][l
]);
799 strict
= !rational
&& isl_int_is_negone(bmap
->ineq
[i
][0]);
801 isl_seq_cpy(c
->el
, bmap
->ineq
[i
], 1 + total
);
803 isl_seq_neg(c
->el
, bmap
->ineq
[i
], 1 + total
);
805 isl_int_set_si(c
->el
[0], 0);
806 combine
= dump
? isl_bool_false
: next_is_opposite(bmap
, i
, l
);
810 op
= constraint_op(-s
, strict
, latex
);
811 p
= print_half_constraint(p
, space
, div
, c
->el
, l
,
815 op
= constraint_op(s
, strict
, latex
);
816 p
= print_constraint(p
, space
, div
, c
->el
, l
,
822 isl_basic_map_free(bmap
);
827 isl_basic_map_free(bmap
);
833 static __isl_give isl_printer
*print_div(__isl_keep isl_space
*dim
,
834 __isl_keep isl_mat
*div
, int pos
, __isl_take isl_printer
*p
)
839 return isl_printer_free(p
);
841 c
= p
->output_format
== ISL_FORMAT_C
;
842 p
= isl_printer_print_str(p
, c
? "floord(" : "floor((");
843 p
= print_affine_of_len(dim
, div
, p
,
844 div
->row
[pos
] + 1, div
->n_col
- 1);
845 p
= isl_printer_print_str(p
, c
? ", " : ")/");
846 p
= isl_printer_print_isl_int(p
, div
->row
[pos
][0]);
847 p
= isl_printer_print_str(p
, ")");
851 /* Print a comma separated list of div names, except those that have
852 * a definition that can be printed.
853 * If "print_defined_divs" is set, then those div names are printed
854 * as well, along with their definitions.
856 static __isl_give isl_printer
*print_div_list(__isl_take isl_printer
*p
,
857 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int latex
,
858 int print_defined_divs
)
864 if (!p
|| !space
|| !div
)
865 return isl_printer_free(p
);
867 n_div
= isl_mat_rows(div
);
869 for (i
= 0; i
< n_div
; ++i
) {
870 if (!print_defined_divs
&& can_print_div_expr(p
, div
, i
))
873 p
= isl_printer_print_str(p
, ", ");
874 p
= print_name(space
, p
, isl_dim_div
, i
, latex
);
876 if (!can_print_div_expr(p
, div
, i
))
878 p
= isl_printer_print_str(p
, " = ");
879 p
= print_div(space
, div
, i
, p
);
885 /* Does printing an object with local variables described by "div"
886 * require an "exists" clause?
887 * That is, are there any local variables without an explicit representation?
888 * An exists clause is also needed in "dump" mode because
889 * explicit div representations are not printed inline in that case.
891 static isl_bool
need_exists(__isl_keep isl_printer
*p
, __isl_keep isl_mat
*div
)
896 return isl_bool_error
;
897 n
= isl_mat_rows(div
);
899 return isl_bool_false
;
901 return isl_bool_true
;
902 for (i
= 0; i
< n
; ++i
)
903 if (!can_print_div_expr(p
, div
, i
))
904 return isl_bool_true
;
905 return isl_bool_false
;
908 /* Print the start of an exists clause, i.e.,
912 * In dump mode, local variables with an explicit definition are printed
913 * as well because they will not be printed inline.
915 static __isl_give isl_printer
*open_exists(__isl_take isl_printer
*p
,
916 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int latex
)
924 p
= isl_printer_print_str(p
, s_open_exists
[latex
]);
925 p
= print_div_list(p
, space
, div
, latex
, dump
);
926 p
= isl_printer_print_str(p
, ": ");
931 /* Remove the explicit representations of all local variables in "div".
933 static __isl_give isl_mat
*mark_all_unknown(__isl_take isl_mat
*div
)
940 n_div
= isl_mat_rows(div
);
941 for (i
= 0; i
< n_div
; ++i
)
942 div
= isl_mat_set_element_si(div
, i
, 0, 0);
946 /* Print the constraints of "bmap" to "p".
947 * The names of the variables are taken from "space".
948 * "latex" is set if the constraints should be printed in LaTeX format.
949 * Do not print inline explicit div representations in "dump" mode.
951 static __isl_give isl_printer
*print_disjunct(__isl_keep isl_basic_map
*bmap
,
952 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
961 div
= isl_basic_map_get_divs(bmap
);
962 exists
= need_exists(p
, div
);
963 if (exists
>= 0 && exists
)
964 p
= open_exists(p
, space
, div
, latex
);
967 div
= mark_all_unknown(div
);
968 p
= print_constraints(bmap
, space
, div
, p
, latex
);
971 if (exists
>= 0 && exists
)
972 p
= isl_printer_print_str(p
, s_close_exists
[latex
]);
976 /* Print a colon followed by the constraints of "bmap"
977 * to "p", provided there are any constraints.
978 * The names of the variables are taken from "space".
979 * "latex" is set if the constraints should be printed in LaTeX format.
981 static __isl_give isl_printer
*print_optional_disjunct(
982 __isl_keep isl_basic_map
*bmap
, __isl_keep isl_space
*space
,
983 __isl_take isl_printer
*p
, int latex
)
985 if (isl_basic_map_plain_is_universe(bmap
))
988 p
= isl_printer_print_str(p
, ": ");
989 p
= print_disjunct(bmap
, space
, p
, latex
);
994 static __isl_give isl_printer
*basic_map_print_omega(
995 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
997 p
= isl_printer_print_str(p
, "{ [");
998 p
= print_var_list(p
, bmap
->dim
, isl_dim_in
);
999 p
= isl_printer_print_str(p
, "] -> [");
1000 p
= print_var_list(p
, bmap
->dim
, isl_dim_out
);
1001 p
= isl_printer_print_str(p
, "] ");
1002 p
= print_optional_disjunct(bmap
, bmap
->dim
, p
, 0);
1003 p
= isl_printer_print_str(p
, " }");
1007 static __isl_give isl_printer
*basic_set_print_omega(
1008 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
)
1010 p
= isl_printer_print_str(p
, "{ [");
1011 p
= print_var_list(p
, bset
->dim
, isl_dim_set
);
1012 p
= isl_printer_print_str(p
, "] ");
1013 p
= print_optional_disjunct(bset
, bset
->dim
, p
, 0);
1014 p
= isl_printer_print_str(p
, " }");
1018 static __isl_give isl_printer
*isl_map_print_omega(__isl_keep isl_map
*map
,
1019 __isl_take isl_printer
*p
)
1023 for (i
= 0; i
< map
->n
; ++i
) {
1025 p
= isl_printer_print_str(p
, " union ");
1026 p
= basic_map_print_omega(map
->p
[i
], p
);
1031 static __isl_give isl_printer
*isl_set_print_omega(__isl_keep isl_set
*set
,
1032 __isl_take isl_printer
*p
)
1036 for (i
= 0; i
< set
->n
; ++i
) {
1038 p
= isl_printer_print_str(p
, " union ");
1039 p
= basic_set_print_omega(set
->p
[i
], p
);
1044 /* Print the list of parameters in "space", followed by an arrow, to "p",
1045 * if there are any parameters.
1047 static __isl_give isl_printer
*print_param_tuple(__isl_take isl_printer
*p
,
1048 __isl_keep isl_space
*space
, struct isl_print_space_data
*data
)
1051 return isl_printer_free(p
);
1052 if (isl_space_dim(space
, isl_dim_param
) == 0)
1055 p
= print_tuple(space
, p
, isl_dim_param
, data
);
1056 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
1061 static __isl_give isl_printer
*isl_basic_map_print_isl(
1062 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
,
1065 struct isl_print_space_data data
= { .latex
= latex
};
1066 int rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
1068 p
= print_param_tuple(p
, bmap
->dim
, &data
);
1069 p
= isl_printer_print_str(p
, "{ ");
1070 p
= isl_print_space(bmap
->dim
, p
, rational
, &data
);
1071 p
= isl_printer_print_str(p
, " : ");
1072 p
= print_disjunct(bmap
, bmap
->dim
, p
, latex
);
1073 p
= isl_printer_print_str(p
, " }");
1077 /* Print the disjuncts of a map (or set) "map" to "p".
1078 * The names of the variables are taken from "space".
1079 * "latex" is set if the constraints should be printed in LaTeX format.
1081 static __isl_give isl_printer
*print_disjuncts_core(__isl_keep isl_map
*map
,
1082 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
1087 p
= isl_printer_print_str(p
, "false");
1088 for (i
= 0; i
< map
->n
; ++i
) {
1090 p
= isl_printer_print_str(p
, s_or
[latex
]);
1091 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
1092 p
= isl_printer_print_str(p
, "(");
1093 p
= print_disjunct(map
->p
[i
], space
, p
, latex
);
1094 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
1095 p
= isl_printer_print_str(p
, ")");
1100 /* Print the disjuncts of a map (or set) "map" to "p".
1101 * The names of the variables are taken from "space".
1102 * "hull" describes constraints shared by all disjuncts of "map".
1103 * "latex" is set if the constraints should be printed in LaTeX format.
1105 * Print the disjuncts as a conjunction of "hull" and
1106 * the result of removing the constraints of "hull" from "map".
1107 * If this result turns out to be the universe, then simply print "hull".
1109 static __isl_give isl_printer
*print_disjuncts_in_hull(__isl_keep isl_map
*map
,
1110 __isl_keep isl_space
*space
, __isl_take isl_basic_map
*hull
,
1111 __isl_take isl_printer
*p
, int latex
)
1113 isl_bool is_universe
;
1115 p
= print_disjunct(hull
, space
, p
, latex
);
1116 map
= isl_map_plain_gist_basic_map(isl_map_copy(map
), hull
);
1117 is_universe
= isl_map_plain_is_universe(map
);
1118 if (is_universe
< 0)
1121 p
= isl_printer_print_str(p
, s_and
[latex
]);
1122 p
= isl_printer_print_str(p
, "(");
1123 p
= print_disjuncts_core(map
, space
, p
, latex
);
1124 p
= isl_printer_print_str(p
, ")");
1131 isl_printer_free(p
);
1135 /* Print the disjuncts of a map (or set) "map" to "p".
1136 * The names of the variables are taken from "space".
1137 * "latex" is set if the constraints should be printed in LaTeX format.
1139 * If there are at least two disjuncts and "dump" mode is not turned out,
1140 * check for any shared constraints among all disjuncts.
1141 * If there are any, then print them separately in print_disjuncts_in_hull.
1143 static __isl_give isl_printer
*print_disjuncts(__isl_keep isl_map
*map
,
1144 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
1146 if (isl_map_plain_is_universe(map
))
1149 p
= isl_printer_print_str(p
, s_such_that
[latex
]);
1153 if (!p
->dump
&& map
->n
>= 2) {
1154 isl_basic_map
*hull
;
1155 isl_bool is_universe
;
1157 hull
= isl_map_plain_unshifted_simple_hull(isl_map_copy(map
));
1158 is_universe
= isl_basic_map_plain_is_universe(hull
);
1159 if (is_universe
< 0)
1160 p
= isl_printer_free(p
);
1161 else if (!is_universe
)
1162 return print_disjuncts_in_hull(map
, space
, hull
,
1164 isl_basic_map_free(hull
);
1167 return print_disjuncts_core(map
, space
, p
, latex
);
1170 /* Print the disjuncts of a map (or set).
1171 * The names of the variables are taken from "space".
1172 * "latex" is set if the constraints should be printed in LaTeX format.
1174 * If the map turns out to be a universal parameter domain, then
1175 * we need to print the colon. Otherwise, the output looks identical
1178 static __isl_give isl_printer
*print_disjuncts_map(__isl_keep isl_map
*map
,
1179 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
1181 if (isl_map_plain_is_universe(map
) && isl_space_is_params(map
->dim
))
1182 return isl_printer_print_str(p
, s_such_that
[latex
]);
1184 return print_disjuncts(map
, space
, p
, latex
);
1187 /* Print the disjuncts of a set.
1188 * The names of the variables are taken from "space".
1189 * "latex" is set if the constraints should be printed in LaTeX format.
1191 static __isl_give isl_printer
*print_disjuncts_set(__isl_keep isl_set
*set
,
1192 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
1194 return print_disjuncts_map(set_to_map(set
), space
, p
, latex
);
1197 struct isl_aff_split
{
1202 static void free_split(__isl_take
struct isl_aff_split
*split
, int n
)
1209 for (i
= 0; i
< n
; ++i
) {
1210 isl_basic_map_free(split
[i
].aff
);
1211 isl_map_free(split
[i
].map
);
1217 static __isl_give isl_basic_map
*get_aff(__isl_take isl_basic_map
*bmap
)
1220 unsigned nparam
, n_in
, n_out
, total
;
1222 bmap
= isl_basic_map_cow(bmap
);
1225 if (isl_basic_map_free_inequality(bmap
, bmap
->n_ineq
) < 0)
1228 nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
1229 n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
1230 n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
1231 total
= isl_basic_map_dim(bmap
, isl_dim_all
);
1232 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1233 j
= isl_seq_last_non_zero(bmap
->eq
[i
] + 1, total
);
1234 if (j
>= nparam
&& j
< nparam
+ n_in
+ n_out
&&
1235 (isl_int_is_one(bmap
->eq
[i
][1 + j
]) ||
1236 isl_int_is_negone(bmap
->eq
[i
][1 + j
])))
1238 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1242 bmap
= isl_basic_map_finalize(bmap
);
1246 isl_basic_map_free(bmap
);
1250 static int aff_split_cmp(const void *p1
, const void *p2
, void *user
)
1252 const struct isl_aff_split
*s1
, *s2
;
1253 s1
= (const struct isl_aff_split
*) p1
;
1254 s2
= (const struct isl_aff_split
*) p2
;
1256 return isl_basic_map_plain_cmp(s1
->aff
, s2
->aff
);
1259 static __isl_give isl_basic_map
*drop_aff(__isl_take isl_basic_map
*bmap
,
1260 __isl_keep isl_basic_map
*aff
)
1268 total
= isl_space_dim(bmap
->dim
, isl_dim_all
);
1270 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1271 if (isl_seq_first_non_zero(bmap
->eq
[i
] + 1 + total
,
1274 for (j
= 0; j
< aff
->n_eq
; ++j
) {
1275 if (!isl_seq_eq(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
) &&
1276 !isl_seq_is_neg(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
))
1278 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1286 isl_basic_map_free(bmap
);
1290 static __isl_give
struct isl_aff_split
*split_aff(__isl_keep isl_map
*map
)
1293 struct isl_aff_split
*split
;
1296 ctx
= isl_map_get_ctx(map
);
1297 split
= isl_calloc_array(ctx
, struct isl_aff_split
, map
->n
);
1301 for (i
= 0; i
< map
->n
; ++i
) {
1302 isl_basic_map
*bmap
;
1303 split
[i
].aff
= get_aff(isl_basic_map_copy(map
->p
[i
]));
1304 bmap
= isl_basic_map_copy(map
->p
[i
]);
1305 bmap
= isl_basic_map_cow(bmap
);
1306 bmap
= drop_aff(bmap
, split
[i
].aff
);
1307 split
[i
].map
= isl_map_from_basic_map(bmap
);
1308 if (!split
[i
].aff
|| !split
[i
].map
)
1312 if (isl_sort(split
, map
->n
, sizeof(struct isl_aff_split
),
1313 &aff_split_cmp
, NULL
) < 0)
1317 for (i
= n
- 1; i
>= 1; --i
) {
1318 if (!isl_basic_map_plain_is_equal(split
[i
- 1].aff
,
1321 isl_basic_map_free(split
[i
].aff
);
1322 split
[i
- 1].map
= isl_map_union(split
[i
- 1].map
,
1325 split
[i
] = split
[n
- 1];
1326 split
[n
- 1].aff
= NULL
;
1327 split
[n
- 1].map
= NULL
;
1333 free_split(split
, map
->n
);
1337 static int defining_equality(__isl_keep isl_basic_map
*eq
,
1338 __isl_keep isl_space
*dim
, enum isl_dim_type type
, int pos
)
1346 pos
+= isl_space_offset(dim
, type
);
1347 total
= isl_basic_map_total_dim(eq
);
1349 for (i
= 0; i
< eq
->n_eq
; ++i
) {
1350 if (isl_seq_last_non_zero(eq
->eq
[i
] + 1, total
) != pos
)
1352 if (isl_int_is_one(eq
->eq
[i
][1 + pos
]))
1353 isl_seq_neg(eq
->eq
[i
], eq
->eq
[i
], 1 + total
);
1360 /* Print dimension "pos" of data->space to "p".
1362 * data->user is assumed to be an isl_basic_map keeping track of equalities.
1364 * If the current dimension is defined by these equalities, then print
1365 * the corresponding expression, assigned to the name of the dimension
1366 * if there is any. Otherwise, print the name of the dimension.
1368 static __isl_give isl_printer
*print_dim_eq(__isl_take isl_printer
*p
,
1369 struct isl_print_space_data
*data
, unsigned pos
)
1371 isl_basic_map
*eq
= data
->user
;
1374 j
= defining_equality(eq
, data
->space
, data
->type
, pos
);
1376 if (isl_space_has_dim_name(data
->space
, data
->type
, pos
)) {
1377 p
= print_name(data
->space
, p
, data
->type
, pos
,
1379 p
= isl_printer_print_str(p
, " = ");
1381 pos
+= 1 + isl_space_offset(data
->space
, data
->type
);
1382 p
= print_affine_of_len(data
->space
, NULL
, p
, eq
->eq
[j
], pos
);
1384 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
1390 static __isl_give isl_printer
*print_split_map(__isl_take isl_printer
*p
,
1391 struct isl_aff_split
*split
, int n
, __isl_keep isl_space
*space
)
1393 struct isl_print_space_data data
= { 0 };
1397 data
.print_dim
= &print_dim_eq
;
1398 for (i
= 0; i
< n
; ++i
) {
1401 rational
= split
[i
].map
->n
> 0 &&
1402 ISL_F_ISSET(split
[i
].map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1404 p
= isl_printer_print_str(p
, "; ");
1405 data
.user
= split
[i
].aff
;
1406 p
= isl_print_space(space
, p
, rational
, &data
);
1407 p
= print_disjuncts_map(split
[i
].map
, space
, p
, 0);
1413 static __isl_give isl_printer
*isl_map_print_isl_body(__isl_keep isl_map
*map
,
1414 __isl_take isl_printer
*p
)
1416 struct isl_print_space_data data
= { 0 };
1417 struct isl_aff_split
*split
= NULL
;
1421 return isl_printer_free(p
);
1422 if (!p
->dump
&& map
->n
> 0)
1423 split
= split_aff(map
);
1425 p
= print_split_map(p
, split
, map
->n
, map
->dim
);
1427 rational
= map
->n
> 0 &&
1428 ISL_F_ISSET(map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1429 p
= isl_print_space(map
->dim
, p
, rational
, &data
);
1430 p
= print_disjuncts_map(map
, map
->dim
, p
, 0);
1432 free_split(split
, map
->n
);
1436 static __isl_give isl_printer
*isl_map_print_isl(__isl_keep isl_map
*map
,
1437 __isl_take isl_printer
*p
)
1439 struct isl_print_space_data data
= { 0 };
1441 p
= print_param_tuple(p
, map
->dim
, &data
);
1442 p
= isl_printer_print_str(p
, s_open_set
[0]);
1443 p
= isl_map_print_isl_body(map
, p
);
1444 p
= isl_printer_print_str(p
, s_close_set
[0]);
1448 static __isl_give isl_printer
*print_latex_map(__isl_keep isl_map
*map
,
1449 __isl_take isl_printer
*p
, __isl_keep isl_basic_map
*aff
)
1451 struct isl_print_space_data data
= { 0 };
1454 p
= print_param_tuple(p
, map
->dim
, &data
);
1455 p
= isl_printer_print_str(p
, s_open_set
[1]);
1456 data
.print_dim
= &print_dim_eq
;
1458 p
= isl_print_space(map
->dim
, p
, 0, &data
);
1459 p
= print_disjuncts_map(map
, map
->dim
, p
, 1);
1460 p
= isl_printer_print_str(p
, s_close_set
[1]);
1465 static __isl_give isl_printer
*isl_map_print_latex(__isl_keep isl_map
*map
,
1466 __isl_take isl_printer
*p
)
1469 struct isl_aff_split
*split
= NULL
;
1472 split
= split_aff(map
);
1475 return print_latex_map(map
, p
, NULL
);
1477 for (i
= 0; i
< map
->n
; ++i
) {
1481 p
= isl_printer_print_str(p
, " \\cup ");
1482 p
= print_latex_map(split
[i
].map
, p
, split
[i
].aff
);
1485 free_split(split
, map
->n
);
1489 __isl_give isl_printer
*isl_printer_print_basic_map(__isl_take isl_printer
*p
,
1490 __isl_keep isl_basic_map
*bmap
)
1494 if (p
->output_format
== ISL_FORMAT_ISL
)
1495 return isl_basic_map_print_isl(bmap
, p
, 0);
1496 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1497 return basic_map_print_omega(bmap
, p
);
1498 isl_assert(bmap
->ctx
, 0, goto error
);
1500 isl_printer_free(p
);
1504 __isl_give isl_printer
*isl_printer_print_basic_set(__isl_take isl_printer
*p
,
1505 __isl_keep isl_basic_set
*bset
)
1510 if (p
->output_format
== ISL_FORMAT_ISL
)
1511 return isl_basic_map_print_isl(bset
, p
, 0);
1512 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1513 return isl_basic_set_print_polylib(bset
, p
, 0);
1514 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1515 return isl_basic_set_print_polylib(bset
, p
, 1);
1516 else if (p
->output_format
== ISL_FORMAT_POLYLIB_CONSTRAINTS
)
1517 return bset_print_constraints_polylib(bset
, p
);
1518 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1519 return basic_set_print_omega(bset
, p
);
1520 isl_assert(p
->ctx
, 0, goto error
);
1522 isl_printer_free(p
);
1526 __isl_give isl_printer
*isl_printer_print_set(__isl_take isl_printer
*p
,
1527 __isl_keep isl_set
*set
)
1531 if (p
->output_format
== ISL_FORMAT_ISL
)
1532 return isl_map_print_isl(set_to_map(set
), p
);
1533 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1534 return isl_set_print_polylib(set
, p
, 0);
1535 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1536 return isl_set_print_polylib(set
, p
, 1);
1537 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1538 return isl_set_print_omega(set
, p
);
1539 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1540 return isl_map_print_latex(set_to_map(set
), p
);
1541 isl_assert(set
->ctx
, 0, goto error
);
1543 isl_printer_free(p
);
1547 __isl_give isl_printer
*isl_printer_print_map(__isl_take isl_printer
*p
,
1548 __isl_keep isl_map
*map
)
1553 if (p
->output_format
== ISL_FORMAT_ISL
)
1554 return isl_map_print_isl(map
, p
);
1555 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1556 return isl_map_print_polylib(map
, p
, 0);
1557 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1558 return isl_map_print_polylib(map
, p
, 1);
1559 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1560 return isl_map_print_omega(map
, p
);
1561 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1562 return isl_map_print_latex(map
, p
);
1563 isl_assert(map
->ctx
, 0, goto error
);
1565 isl_printer_free(p
);
1569 struct isl_union_print_data
{
1574 static isl_stat
print_map_body(__isl_take isl_map
*map
, void *user
)
1576 struct isl_union_print_data
*data
;
1577 data
= (struct isl_union_print_data
*)user
;
1580 data
->p
= isl_printer_print_str(data
->p
, "; ");
1583 data
->p
= isl_map_print_isl_body(map
, data
->p
);
1589 /* Print the body of "umap" (everything except the parameter declarations)
1590 * to "p" in isl format.
1592 static __isl_give isl_printer
*isl_printer_print_union_map_isl_body(
1593 __isl_take isl_printer
*p
, __isl_keep isl_union_map
*umap
)
1595 struct isl_union_print_data data
;
1597 p
= isl_printer_print_str(p
, s_open_set
[0]);
1600 isl_union_map_foreach_map(umap
, &print_map_body
, &data
);
1602 p
= isl_printer_print_str(p
, s_close_set
[0]);
1606 /* Print the body of "uset" (everything except the parameter declarations)
1607 * to "p" in isl format.
1609 static __isl_give isl_printer
*isl_printer_print_union_set_isl_body(
1610 __isl_take isl_printer
*p
, __isl_keep isl_union_set
*uset
)
1612 return isl_printer_print_union_map_isl_body(p
, uset_to_umap(uset
));
1615 /* Print the isl_union_map "umap" to "p" in isl format.
1617 static __isl_give isl_printer
*isl_union_map_print_isl(
1618 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1620 struct isl_print_space_data space_data
= { 0 };
1623 space
= isl_union_map_get_space(umap
);
1624 p
= print_param_tuple(p
, space
, &space_data
);
1625 isl_space_free(space
);
1627 p
= isl_printer_print_union_map_isl_body(p
, umap
);
1632 static isl_stat
print_latex_map_body(__isl_take isl_map
*map
, void *user
)
1634 struct isl_union_print_data
*data
;
1635 data
= (struct isl_union_print_data
*)user
;
1638 data
->p
= isl_printer_print_str(data
->p
, " \\cup ");
1641 data
->p
= isl_map_print_latex(map
, data
->p
);
1647 static __isl_give isl_printer
*isl_union_map_print_latex(
1648 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1650 struct isl_union_print_data data
= { p
, 1 };
1651 isl_union_map_foreach_map(umap
, &print_latex_map_body
, &data
);
1656 __isl_give isl_printer
*isl_printer_print_union_map(__isl_take isl_printer
*p
,
1657 __isl_keep isl_union_map
*umap
)
1662 if (p
->output_format
== ISL_FORMAT_ISL
)
1663 return isl_union_map_print_isl(umap
, p
);
1664 if (p
->output_format
== ISL_FORMAT_LATEX
)
1665 return isl_union_map_print_latex(umap
, p
);
1667 isl_die(p
->ctx
, isl_error_invalid
,
1668 "invalid output format for isl_union_map", goto error
);
1670 isl_printer_free(p
);
1674 __isl_give isl_printer
*isl_printer_print_union_set(__isl_take isl_printer
*p
,
1675 __isl_keep isl_union_set
*uset
)
1680 if (p
->output_format
== ISL_FORMAT_ISL
)
1681 return isl_union_map_print_isl(uset_to_umap(uset
), p
);
1682 if (p
->output_format
== ISL_FORMAT_LATEX
)
1683 return isl_union_map_print_latex(uset_to_umap(uset
), p
);
1685 isl_die(p
->ctx
, isl_error_invalid
,
1686 "invalid output format for isl_union_set", goto error
);
1688 isl_printer_free(p
);
1692 static int poly_rec_n_non_zero(__isl_keep isl_poly_rec
*rec
)
1700 for (i
= 0, n
= 0; i
< rec
->n
; ++i
) {
1701 isl_bool is_zero
= isl_poly_is_zero(rec
->p
[i
]);
1712 static __isl_give isl_printer
*poly_print_cst(__isl_keep isl_poly
*poly
,
1713 __isl_take isl_printer
*p
, int first
)
1718 cst
= isl_poly_as_cst(poly
);
1721 neg
= !first
&& isl_int_is_neg(cst
->n
);
1723 p
= isl_printer_print_str(p
, neg
? " - " : " + ");
1725 isl_int_neg(cst
->n
, cst
->n
);
1726 if (isl_int_is_zero(cst
->d
)) {
1727 int sgn
= isl_int_sgn(cst
->n
);
1728 p
= isl_printer_print_str(p
, sgn
< 0 ? "-infty" :
1729 sgn
== 0 ? "NaN" : "infty");
1731 p
= isl_printer_print_isl_int(p
, cst
->n
);
1733 isl_int_neg(cst
->n
, cst
->n
);
1734 if (!isl_int_is_zero(cst
->d
) && !isl_int_is_one(cst
->d
)) {
1735 p
= isl_printer_print_str(p
, "/");
1736 p
= isl_printer_print_isl_int(p
, cst
->d
);
1740 isl_printer_free(p
);
1744 static __isl_give isl_printer
*print_base(__isl_take isl_printer
*p
,
1745 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int var
)
1749 total
= isl_space_dim(space
, isl_dim_all
);
1751 p
= print_term(space
, NULL
, space
->ctx
->one
, 1 + var
, p
, 0);
1753 p
= print_div(space
, div
, var
- total
, p
);
1757 static __isl_give isl_printer
*print_pow(__isl_take isl_printer
*p
,
1758 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
, int exp
)
1760 p
= print_base(p
, dim
, div
, var
);
1763 if (p
->output_format
== ISL_FORMAT_C
) {
1765 for (i
= 1; i
< exp
; ++i
) {
1766 p
= isl_printer_print_str(p
, "*");
1767 p
= print_base(p
, dim
, div
, var
);
1770 p
= isl_printer_print_str(p
, "^");
1771 p
= isl_printer_print_int(p
, exp
);
1776 /* Print the polynomial "poly" defined over the domain space "space" and
1777 * local variables defined by "div" to "p".
1779 static __isl_give isl_printer
*poly_print(__isl_keep isl_poly
*poly
,
1780 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
1781 __isl_take isl_printer
*p
)
1783 int i
, n
, first
, print_parens
;
1787 is_cst
= isl_poly_is_cst(poly
);
1788 if (!p
|| is_cst
< 0 || !space
|| !div
)
1792 return poly_print_cst(poly
, p
, 1);
1794 rec
= isl_poly_as_rec(poly
);
1795 n
= poly_rec_n_non_zero(rec
);
1797 return isl_printer_free(p
);
1798 print_parens
= n
> 1;
1800 p
= isl_printer_print_str(p
, "(");
1801 for (i
= 0, first
= 1; i
< rec
->n
; ++i
) {
1802 isl_bool is_zero
= isl_poly_is_zero(rec
->p
[i
]);
1803 isl_bool is_one
= isl_poly_is_one(rec
->p
[i
]);
1804 isl_bool is_negone
= isl_poly_is_negone(rec
->p
[i
]);
1805 isl_bool is_cst
= isl_poly_is_cst(rec
->p
[i
]);
1807 if (is_zero
< 0 || is_one
< 0 || is_negone
< 0)
1808 return isl_printer_free(p
);
1813 p
= isl_printer_print_str(p
, "-1");
1815 p
= isl_printer_print_str(p
, "-");
1817 p
= isl_printer_print_str(p
, " - ");
1818 } else if (is_cst
&& !is_one
)
1819 p
= poly_print_cst(rec
->p
[i
], p
, first
);
1822 p
= isl_printer_print_str(p
, " + ");
1823 if (i
== 0 || !is_one
)
1824 p
= poly_print(rec
->p
[i
], space
, div
, p
);
1829 if (!is_one
&& !is_negone
)
1830 p
= isl_printer_print_str(p
, " * ");
1831 p
= print_pow(p
, space
, div
, rec
->poly
.var
, i
);
1834 p
= isl_printer_print_str(p
, ")");
1837 isl_printer_free(p
);
1841 static __isl_give isl_printer
*print_qpolynomial(__isl_take isl_printer
*p
,
1842 __isl_keep isl_qpolynomial
*qp
)
1846 p
= poly_print(qp
->poly
, qp
->dim
, qp
->div
, p
);
1849 isl_printer_free(p
);
1853 static __isl_give isl_printer
*print_qpolynomial_isl(__isl_take isl_printer
*p
,
1854 __isl_keep isl_qpolynomial
*qp
)
1856 struct isl_print_space_data data
= { 0 };
1861 p
= print_param_tuple(p
, qp
->dim
, &data
);
1862 p
= isl_printer_print_str(p
, "{ ");
1863 if (!isl_space_is_params(qp
->dim
)) {
1864 p
= isl_print_space(qp
->dim
, p
, 0, &data
);
1865 p
= isl_printer_print_str(p
, " -> ");
1867 p
= print_qpolynomial(p
, qp
);
1868 p
= isl_printer_print_str(p
, " }");
1871 isl_printer_free(p
);
1875 /* Print the quasi-polynomial "qp" to "p" in C format, with the variable names
1876 * taken from the domain space "space".
1878 static __isl_give isl_printer
*print_qpolynomial_c(__isl_take isl_printer
*p
,
1879 __isl_keep isl_space
*space
, __isl_keep isl_qpolynomial
*qp
)
1884 den
= isl_qpolynomial_get_den(qp
);
1885 qp
= isl_qpolynomial_copy(qp
);
1886 qp
= isl_qpolynomial_scale_val(qp
, isl_val_copy(den
));
1887 is_one
= isl_val_is_one(den
);
1889 p
= isl_printer_free(p
);
1891 p
= isl_printer_print_str(p
, "(");
1893 p
= poly_print(qp
->poly
, space
, qp
->div
, p
);
1895 p
= isl_printer_free(p
);
1897 p
= isl_printer_print_str(p
, ")/");
1898 p
= isl_printer_print_val(p
, den
);
1900 isl_qpolynomial_free(qp
);
1905 __isl_give isl_printer
*isl_printer_print_qpolynomial(
1906 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial
*qp
)
1911 if (p
->output_format
== ISL_FORMAT_ISL
)
1912 return print_qpolynomial_isl(p
, qp
);
1913 else if (p
->output_format
== ISL_FORMAT_C
)
1914 return print_qpolynomial_c(p
, qp
->dim
, qp
);
1916 isl_die(qp
->dim
->ctx
, isl_error_unsupported
,
1917 "output format not supported for isl_qpolynomials",
1920 isl_printer_free(p
);
1924 void isl_qpolynomial_print(__isl_keep isl_qpolynomial
*qp
, FILE *out
,
1925 unsigned output_format
)
1932 isl_assert(qp
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1933 p
= isl_printer_to_file(qp
->dim
->ctx
, out
);
1934 p
= isl_printer_print_qpolynomial(p
, qp
);
1935 isl_printer_free(p
);
1938 static __isl_give isl_printer
*qpolynomial_fold_print(
1939 __isl_keep isl_qpolynomial_fold
*fold
, __isl_take isl_printer
*p
)
1943 if (fold
->type
== isl_fold_min
)
1944 p
= isl_printer_print_str(p
, "min");
1945 else if (fold
->type
== isl_fold_max
)
1946 p
= isl_printer_print_str(p
, "max");
1947 p
= isl_printer_print_str(p
, "(");
1948 for (i
= 0; i
< fold
->n
; ++i
) {
1950 p
= isl_printer_print_str(p
, ", ");
1951 p
= print_qpolynomial(p
, fold
->qp
[i
]);
1953 p
= isl_printer_print_str(p
, ")");
1957 void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold
*fold
,
1958 FILE *out
, unsigned output_format
)
1965 isl_assert(fold
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1967 p
= isl_printer_to_file(fold
->dim
->ctx
, out
);
1968 p
= isl_printer_print_qpolynomial_fold(p
, fold
);
1970 isl_printer_free(p
);
1973 static __isl_give isl_printer
*isl_pwqp_print_isl_body(
1974 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1976 struct isl_print_space_data data
= { 0 };
1979 for (i
= 0; i
< pwqp
->n
; ++i
) {
1983 p
= isl_printer_print_str(p
, "; ");
1984 space
= isl_qpolynomial_get_domain_space(pwqp
->p
[i
].qp
);
1985 if (!isl_space_is_params(space
)) {
1986 p
= isl_print_space(space
, p
, 0, &data
);
1987 p
= isl_printer_print_str(p
, " -> ");
1989 p
= print_qpolynomial(p
, pwqp
->p
[i
].qp
);
1990 p
= print_disjuncts(set_to_map(pwqp
->p
[i
].set
), space
, p
, 0);
1991 isl_space_free(space
);
1997 static __isl_give isl_printer
*print_pw_qpolynomial_isl(
1998 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2000 struct isl_print_space_data data
= { 0 };
2005 p
= print_param_tuple(p
, pwqp
->dim
, &data
);
2006 p
= isl_printer_print_str(p
, "{ ");
2008 if (!isl_space_is_set(pwqp
->dim
)) {
2009 p
= print_tuple(pwqp
->dim
, p
, isl_dim_in
, &data
);
2010 p
= isl_printer_print_str(p
, " -> ");
2012 p
= isl_printer_print_str(p
, "0");
2014 p
= isl_pwqp_print_isl_body(p
, pwqp
);
2015 p
= isl_printer_print_str(p
, " }");
2018 isl_printer_free(p
);
2022 void isl_pw_qpolynomial_print(__isl_keep isl_pw_qpolynomial
*pwqp
, FILE *out
,
2023 unsigned output_format
)
2030 p
= isl_printer_to_file(pwqp
->dim
->ctx
, out
);
2031 p
= isl_printer_set_output_format(p
, output_format
);
2032 p
= isl_printer_print_pw_qpolynomial(p
, pwqp
);
2034 isl_printer_free(p
);
2037 static __isl_give isl_printer
*isl_pwf_print_isl_body(
2038 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2040 struct isl_print_space_data data
= { 0 };
2043 for (i
= 0; i
< pwf
->n
; ++i
) {
2047 p
= isl_printer_print_str(p
, "; ");
2048 space
= isl_qpolynomial_fold_get_domain_space(pwf
->p
[i
].fold
);
2049 if (!isl_space_is_params(space
)) {
2050 p
= isl_print_space(space
, p
, 0, &data
);
2051 p
= isl_printer_print_str(p
, " -> ");
2053 p
= qpolynomial_fold_print(pwf
->p
[i
].fold
, p
);
2054 p
= print_disjuncts(set_to_map(pwf
->p
[i
].set
), space
, p
, 0);
2055 isl_space_free(space
);
2061 static __isl_give isl_printer
*print_pw_qpolynomial_fold_isl(
2062 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2064 struct isl_print_space_data data
= { 0 };
2066 p
= print_param_tuple(p
, pwf
->dim
, &data
);
2067 p
= isl_printer_print_str(p
, "{ ");
2069 if (!isl_space_is_set(pwf
->dim
)) {
2070 p
= print_tuple(pwf
->dim
, p
, isl_dim_in
, &data
);
2071 p
= isl_printer_print_str(p
, " -> ");
2073 p
= isl_printer_print_str(p
, "0");
2075 p
= isl_pwf_print_isl_body(p
, pwf
);
2076 p
= isl_printer_print_str(p
, " }");
2080 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2081 __isl_keep isl_local_space
*ls
, isl_int
*c
);
2083 /* We skip the constraint if it is implied by the div expression.
2085 * *first indicates whether this is the first constraint in the conjunction and
2086 * is updated if the constraint is actually printed.
2088 static __isl_give isl_printer
*print_constraint_c(__isl_take isl_printer
*p
,
2089 __isl_keep isl_local_space
*ls
, isl_int
*c
, const char *op
, int *first
)
2095 o_div
= isl_local_space_offset(ls
, isl_dim_div
);
2096 n_div
= isl_local_space_dim(ls
, isl_dim_div
);
2097 div
= isl_seq_last_non_zero(c
+ o_div
, n_div
);
2099 isl_bool is_div
= isl_local_space_is_div_constraint(ls
, c
, div
);
2101 return isl_printer_free(p
);
2107 p
= isl_printer_print_str(p
, " && ");
2109 p
= print_ls_affine_c(p
, ls
, c
);
2110 p
= isl_printer_print_str(p
, " ");
2111 p
= isl_printer_print_str(p
, op
);
2112 p
= isl_printer_print_str(p
, " 0");
2119 static __isl_give isl_printer
*print_ls_partial_affine_c(
2120 __isl_take isl_printer
*p
, __isl_keep isl_local_space
*ls
,
2121 isl_int
*c
, unsigned len
);
2123 static __isl_give isl_printer
*print_basic_set_c(__isl_take isl_printer
*p
,
2124 __isl_keep isl_space
*space
, __isl_keep isl_basic_set
*bset
)
2128 unsigned n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
2129 unsigned total
= isl_basic_set_total_dim(bset
) - n_div
;
2131 isl_local_space
*ls
;
2133 div
= isl_basic_set_get_divs(bset
);
2134 ls
= isl_local_space_alloc_div(isl_space_copy(space
), div
);
2135 for (i
= 0; i
< bset
->n_eq
; ++i
) {
2136 j
= isl_seq_last_non_zero(bset
->eq
[i
] + 1 + total
, n_div
);
2138 p
= print_constraint_c(p
, ls
,
2139 bset
->eq
[i
], "==", &first
);
2142 p
= isl_printer_print_str(p
, " && ");
2143 p
= isl_printer_print_str(p
, "(");
2144 p
= print_ls_partial_affine_c(p
, ls
, bset
->eq
[i
],
2146 p
= isl_printer_print_str(p
, ") % ");
2147 p
= isl_printer_print_isl_int(p
,
2148 bset
->eq
[i
][1 + total
+ j
]);
2149 p
= isl_printer_print_str(p
, " == 0");
2153 for (i
= 0; i
< bset
->n_ineq
; ++i
)
2154 p
= print_constraint_c(p
, ls
, bset
->ineq
[i
], ">=", &first
);
2155 isl_local_space_free(ls
);
2159 static __isl_give isl_printer
*print_set_c(__isl_take isl_printer
*p
,
2160 __isl_keep isl_space
*space
, __isl_keep isl_set
*set
)
2165 return isl_printer_free(p
);
2168 p
= isl_printer_print_str(p
, "0");
2170 for (i
= 0; i
< set
->n
; ++i
) {
2172 p
= isl_printer_print_str(p
, " || ");
2174 p
= isl_printer_print_str(p
, "(");
2175 p
= print_basic_set_c(p
, space
, set
->p
[i
]);
2177 p
= isl_printer_print_str(p
, ")");
2182 /* Print the piecewise quasi-polynomial "pwqp" to "p" in C format.
2184 static __isl_give isl_printer
*print_pw_qpolynomial_c(
2185 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2190 space
= isl_pw_qpolynomial_get_domain_space(pwqp
);
2191 if (pwqp
->n
== 1 && isl_set_plain_is_universe(pwqp
->p
[0].set
)) {
2192 p
= print_qpolynomial_c(p
, space
, pwqp
->p
[0].qp
);
2193 isl_space_free(space
);
2197 for (i
= 0; i
< pwqp
->n
; ++i
) {
2198 p
= isl_printer_print_str(p
, "(");
2199 p
= print_set_c(p
, space
, pwqp
->p
[i
].set
);
2200 p
= isl_printer_print_str(p
, ") ? (");
2201 p
= print_qpolynomial_c(p
, space
, pwqp
->p
[i
].qp
);
2202 p
= isl_printer_print_str(p
, ") : ");
2205 isl_space_free(space
);
2206 p
= isl_printer_print_str(p
, "0");
2210 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial(
2211 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2216 if (p
->output_format
== ISL_FORMAT_ISL
)
2217 return print_pw_qpolynomial_isl(p
, pwqp
);
2218 else if (p
->output_format
== ISL_FORMAT_C
)
2219 return print_pw_qpolynomial_c(p
, pwqp
);
2220 isl_assert(p
->ctx
, 0, goto error
);
2222 isl_printer_free(p
);
2226 static isl_stat
print_pwqp_body(__isl_take isl_pw_qpolynomial
*pwqp
, void *user
)
2228 struct isl_union_print_data
*data
;
2229 data
= (struct isl_union_print_data
*)user
;
2232 data
->p
= isl_printer_print_str(data
->p
, "; ");
2235 data
->p
= isl_pwqp_print_isl_body(data
->p
, pwqp
);
2236 isl_pw_qpolynomial_free(pwqp
);
2241 static __isl_give isl_printer
*print_union_pw_qpolynomial_isl(
2242 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2244 struct isl_union_print_data data
;
2245 struct isl_print_space_data space_data
= { 0 };
2248 space
= isl_union_pw_qpolynomial_get_space(upwqp
);
2249 p
= print_param_tuple(p
, space
, &space_data
);
2250 isl_space_free(space
);
2251 p
= isl_printer_print_str(p
, "{ ");
2254 isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp
, &print_pwqp_body
,
2257 p
= isl_printer_print_str(p
, " }");
2261 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial(
2262 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2267 if (p
->output_format
== ISL_FORMAT_ISL
)
2268 return print_union_pw_qpolynomial_isl(p
, upwqp
);
2269 isl_die(p
->ctx
, isl_error_invalid
,
2270 "invalid output format for isl_union_pw_qpolynomial",
2273 isl_printer_free(p
);
2277 /* Print the quasi-polynomial reduction "fold" to "p" in C format,
2278 * with the variable names taken from the domain space "space".
2280 static __isl_give isl_printer
*print_qpolynomial_fold_c(
2281 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
,
2282 __isl_keep isl_qpolynomial_fold
*fold
)
2286 for (i
= 0; i
< fold
->n
- 1; ++i
)
2287 if (fold
->type
== isl_fold_min
)
2288 p
= isl_printer_print_str(p
, "min(");
2289 else if (fold
->type
== isl_fold_max
)
2290 p
= isl_printer_print_str(p
, "max(");
2292 for (i
= 0; i
< fold
->n
; ++i
) {
2294 p
= isl_printer_print_str(p
, ", ");
2295 p
= print_qpolynomial_c(p
, space
, fold
->qp
[i
]);
2297 p
= isl_printer_print_str(p
, ")");
2302 __isl_give isl_printer
*isl_printer_print_qpolynomial_fold(
2303 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial_fold
*fold
)
2307 if (p
->output_format
== ISL_FORMAT_ISL
)
2308 return qpolynomial_fold_print(fold
, p
);
2309 else if (p
->output_format
== ISL_FORMAT_C
)
2310 return print_qpolynomial_fold_c(p
, fold
->dim
, fold
);
2311 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2314 isl_printer_free(p
);
2318 /* Print the piecewise quasi-polynomial reduction "pwf" to "p" in C format.
2320 static __isl_give isl_printer
*print_pw_qpolynomial_fold_c(
2321 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2326 space
= isl_pw_qpolynomial_fold_get_domain_space(pwf
);
2327 if (pwf
->n
== 1 && isl_set_plain_is_universe(pwf
->p
[0].set
)) {
2328 p
= print_qpolynomial_fold_c(p
, space
, pwf
->p
[0].fold
);
2329 isl_space_free(space
);
2333 for (i
= 0; i
< pwf
->n
; ++i
) {
2334 p
= isl_printer_print_str(p
, "(");
2335 p
= print_set_c(p
, space
, pwf
->p
[i
].set
);
2336 p
= isl_printer_print_str(p
, ") ? (");
2337 p
= print_qpolynomial_fold_c(p
, space
, pwf
->p
[i
].fold
);
2338 p
= isl_printer_print_str(p
, ") : ");
2341 isl_space_free(space
);
2342 p
= isl_printer_print_str(p
, "0");
2346 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial_fold(
2347 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2352 if (p
->output_format
== ISL_FORMAT_ISL
)
2353 return print_pw_qpolynomial_fold_isl(p
, pwf
);
2354 else if (p
->output_format
== ISL_FORMAT_C
)
2355 return print_pw_qpolynomial_fold_c(p
, pwf
);
2356 isl_assert(p
->ctx
, 0, goto error
);
2358 isl_printer_free(p
);
2362 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold
*pwf
,
2363 FILE *out
, unsigned output_format
)
2370 p
= isl_printer_to_file(pwf
->dim
->ctx
, out
);
2371 p
= isl_printer_set_output_format(p
, output_format
);
2372 p
= isl_printer_print_pw_qpolynomial_fold(p
, pwf
);
2374 isl_printer_free(p
);
2377 static isl_stat
print_pwf_body(__isl_take isl_pw_qpolynomial_fold
*pwf
,
2380 struct isl_union_print_data
*data
;
2381 data
= (struct isl_union_print_data
*)user
;
2384 data
->p
= isl_printer_print_str(data
->p
, "; ");
2387 data
->p
= isl_pwf_print_isl_body(data
->p
, pwf
);
2388 isl_pw_qpolynomial_fold_free(pwf
);
2393 static __isl_give isl_printer
*print_union_pw_qpolynomial_fold_isl(
2394 __isl_take isl_printer
*p
,
2395 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2397 struct isl_union_print_data data
;
2398 struct isl_print_space_data space_data
= { 0 };
2401 space
= isl_union_pw_qpolynomial_fold_get_space(upwf
);
2402 p
= print_param_tuple(p
, space
, &space_data
);
2403 isl_space_free(space
);
2404 p
= isl_printer_print_str(p
, "{ ");
2407 isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(upwf
,
2408 &print_pwf_body
, &data
);
2410 p
= isl_printer_print_str(p
, " }");
2414 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial_fold(
2415 __isl_take isl_printer
*p
,
2416 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2421 if (p
->output_format
== ISL_FORMAT_ISL
)
2422 return print_union_pw_qpolynomial_fold_isl(p
, upwf
);
2423 isl_die(p
->ctx
, isl_error_invalid
,
2424 "invalid output format for isl_union_pw_qpolynomial_fold",
2427 isl_printer_free(p
);
2431 /* Print the isl_constraint "c" to "p".
2433 __isl_give isl_printer
*isl_printer_print_constraint(__isl_take isl_printer
*p
,
2434 __isl_keep isl_constraint
*c
)
2436 struct isl_print_space_data data
= { 0 };
2437 isl_local_space
*ls
;
2444 ls
= isl_constraint_get_local_space(c
);
2446 return isl_printer_free(p
);
2447 space
= isl_local_space_get_space(ls
);
2448 p
= print_param_tuple(p
, space
, &data
);
2449 p
= isl_printer_print_str(p
, "{ ");
2450 p
= isl_print_space(space
, p
, 0, &data
);
2451 p
= isl_printer_print_str(p
, " : ");
2452 exists
= need_exists(p
, ls
->div
);
2454 p
= isl_printer_free(p
);
2455 if (exists
>= 0 && exists
)
2456 p
= open_exists(p
, space
, ls
->div
, 0);
2457 p
= print_affine_of_len(space
, ls
->div
, p
, c
->v
->el
, c
->v
->size
);
2458 if (isl_constraint_is_equality(c
))
2459 p
= isl_printer_print_str(p
, " = 0");
2461 p
= isl_printer_print_str(p
, " >= 0");
2462 if (exists
>= 0 && exists
)
2463 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2464 p
= isl_printer_print_str(p
, " }");
2465 isl_space_free(space
);
2466 isl_local_space_free(ls
);
2470 isl_printer_free(p
);
2474 static __isl_give isl_printer
*isl_printer_print_space_isl(
2475 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
)
2477 struct isl_print_space_data data
= { 0 };
2482 p
= print_param_tuple(p
, space
, &data
);
2484 p
= isl_printer_print_str(p
, "{ ");
2485 if (isl_space_is_params(space
))
2486 p
= isl_printer_print_str(p
, s_such_that
[0]);
2488 p
= isl_print_space(space
, p
, 0, &data
);
2489 p
= isl_printer_print_str(p
, " }");
2493 isl_printer_free(p
);
2497 __isl_give isl_printer
*isl_printer_print_space(__isl_take isl_printer
*p
,
2498 __isl_keep isl_space
*space
)
2501 return isl_printer_free(p
);
2502 if (p
->output_format
== ISL_FORMAT_ISL
)
2503 return isl_printer_print_space_isl(p
, space
);
2504 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
2505 return print_omega_parameters(space
, p
);
2507 isl_die(isl_space_get_ctx(space
), isl_error_unsupported
,
2508 "output format not supported for space",
2509 return isl_printer_free(p
));
2512 __isl_give isl_printer
*isl_printer_print_local_space(__isl_take isl_printer
*p
,
2513 __isl_keep isl_local_space
*ls
)
2515 struct isl_print_space_data data
= { 0 };
2521 p
= print_param_tuple(p
, ls
->dim
, &data
);
2522 p
= isl_printer_print_str(p
, "{ ");
2523 p
= isl_print_space(ls
->dim
, p
, 0, &data
);
2524 n_div
= isl_local_space_dim(ls
, isl_dim_div
);
2526 p
= isl_printer_print_str(p
, " : ");
2527 p
= isl_printer_print_str(p
, s_open_exists
[0]);
2528 p
= print_div_list(p
, ls
->dim
, ls
->div
, 0, 1);
2529 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2530 } else if (isl_space_is_params(ls
->dim
))
2531 p
= isl_printer_print_str(p
, s_such_that
[0]);
2532 p
= isl_printer_print_str(p
, " }");
2535 isl_printer_free(p
);
2539 /* Print the (potentially rational) affine expression "aff" to "p",
2540 * with the variable names taken from "space".
2542 static __isl_give isl_printer
*print_aff_body(__isl_take isl_printer
*p
,
2543 __isl_keep isl_space
*space
, __isl_keep isl_aff
*aff
)
2547 if (isl_aff_is_nan(aff
))
2548 return isl_printer_print_str(p
, "NaN");
2550 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2551 p
= isl_printer_print_str(p
, "(");
2552 p
= print_affine_of_len(space
, aff
->ls
->div
, p
,
2553 aff
->v
->el
+ 1, 1 + total
);
2554 if (isl_int_is_one(aff
->v
->el
[0]))
2555 p
= isl_printer_print_str(p
, ")");
2557 p
= isl_printer_print_str(p
, ")/");
2558 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2564 static __isl_give isl_printer
*print_aff(__isl_take isl_printer
*p
,
2565 __isl_keep isl_aff
*aff
)
2567 struct isl_print_space_data data
= { 0 };
2569 if (isl_space_is_params(aff
->ls
->dim
))
2572 p
= print_tuple(aff
->ls
->dim
, p
, isl_dim_set
, &data
);
2573 p
= isl_printer_print_str(p
, " -> ");
2575 p
= isl_printer_print_str(p
, "[");
2576 p
= print_aff_body(p
, aff
->ls
->dim
, aff
);
2577 p
= isl_printer_print_str(p
, "]");
2582 static __isl_give isl_printer
*print_aff_isl(__isl_take isl_printer
*p
,
2583 __isl_keep isl_aff
*aff
)
2585 struct isl_print_space_data data
= { 0 };
2590 p
= print_param_tuple(p
, aff
->ls
->dim
, &data
);
2591 p
= isl_printer_print_str(p
, "{ ");
2592 p
= print_aff(p
, aff
);
2593 p
= isl_printer_print_str(p
, " }");
2596 isl_printer_free(p
);
2600 /* Print the body of an isl_pw_aff, i.e., a semicolon delimited
2601 * sequence of affine expressions, each followed by constraints.
2603 static __isl_give isl_printer
*print_pw_aff_body(
2604 __isl_take isl_printer
*p
, __isl_keep isl_pw_aff
*pa
)
2609 return isl_printer_free(p
);
2611 for (i
= 0; i
< pa
->n
; ++i
) {
2615 p
= isl_printer_print_str(p
, "; ");
2616 p
= print_aff(p
, pa
->p
[i
].aff
);
2617 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
2618 p
= print_disjuncts(set_to_map(pa
->p
[i
].set
), space
, p
, 0);
2619 isl_space_free(space
);
2625 static __isl_give isl_printer
*print_pw_aff_isl(__isl_take isl_printer
*p
,
2626 __isl_keep isl_pw_aff
*pwaff
)
2628 struct isl_print_space_data data
= { 0 };
2633 p
= print_param_tuple(p
, pwaff
->dim
, &data
);
2634 p
= isl_printer_print_str(p
, "{ ");
2635 p
= print_pw_aff_body(p
, pwaff
);
2636 p
= isl_printer_print_str(p
, " }");
2639 isl_printer_free(p
);
2643 static __isl_give isl_printer
*print_ls_name_c(__isl_take isl_printer
*p
,
2644 __isl_keep isl_local_space
*ls
, enum isl_dim_type type
, unsigned pos
)
2646 if (type
== isl_dim_div
) {
2647 p
= isl_printer_print_str(p
, "floord(");
2648 p
= print_ls_affine_c(p
, ls
, ls
->div
->row
[pos
] + 1);
2649 p
= isl_printer_print_str(p
, ", ");
2650 p
= isl_printer_print_isl_int(p
, ls
->div
->row
[pos
][0]);
2651 p
= isl_printer_print_str(p
, ")");
2655 name
= isl_space_get_dim_name(ls
->dim
, type
, pos
);
2658 p
= isl_printer_print_str(p
, name
);
2663 static __isl_give isl_printer
*print_ls_term_c(__isl_take isl_printer
*p
,
2664 __isl_keep isl_local_space
*ls
, isl_int c
, unsigned pos
)
2666 enum isl_dim_type type
;
2669 return isl_printer_free(p
);
2672 return isl_printer_print_isl_int(p
, c
);
2674 if (isl_int_is_one(c
))
2676 else if (isl_int_is_negone(c
))
2677 p
= isl_printer_print_str(p
, "-");
2679 p
= isl_printer_print_isl_int(p
, c
);
2680 p
= isl_printer_print_str(p
, "*");
2682 type
= pos2type(ls
->dim
, &pos
);
2683 p
= print_ls_name_c(p
, ls
, type
, pos
);
2687 static __isl_give isl_printer
*print_ls_partial_affine_c(
2688 __isl_take isl_printer
*p
, __isl_keep isl_local_space
*ls
,
2689 isl_int
*c
, unsigned len
)
2694 for (i
= 0, first
= 1; i
< len
; ++i
) {
2696 if (isl_int_is_zero(c
[i
]))
2699 if (isl_int_is_neg(c
[i
])) {
2701 isl_int_neg(c
[i
], c
[i
]);
2702 p
= isl_printer_print_str(p
, " - ");
2704 p
= isl_printer_print_str(p
, " + ");
2707 p
= print_ls_term_c(p
, ls
, c
[i
], i
);
2709 isl_int_neg(c
[i
], c
[i
]);
2712 p
= isl_printer_print_str(p
, "0");
2716 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2717 __isl_keep isl_local_space
*ls
, isl_int
*c
)
2719 unsigned len
= 1 + isl_local_space_dim(ls
, isl_dim_all
);
2720 return print_ls_partial_affine_c(p
, ls
, c
, len
);
2723 static __isl_give isl_printer
*print_aff_c(__isl_take isl_printer
*p
,
2724 __isl_keep isl_aff
*aff
)
2728 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2729 if (!isl_int_is_one(aff
->v
->el
[0]))
2730 p
= isl_printer_print_str(p
, "(");
2731 p
= print_ls_partial_affine_c(p
, aff
->ls
, aff
->v
->el
+ 1, 1 + total
);
2732 if (!isl_int_is_one(aff
->v
->el
[0])) {
2733 p
= isl_printer_print_str(p
, ")/");
2734 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2739 /* In the C format, we cannot express that "pwaff" may be undefined
2740 * on parts of the domain space. We therefore assume that the expression
2741 * will only be evaluated on its definition domain and compute the gist
2742 * of each cell with respect to this domain.
2744 static __isl_give isl_printer
*print_pw_aff_c(__isl_take isl_printer
*p
,
2745 __isl_keep isl_pw_aff
*pwaff
)
2748 isl_ast_build
*build
;
2752 isl_die(p
->ctx
, isl_error_unsupported
,
2753 "cannot print empty isl_pw_aff in C format",
2754 return isl_printer_free(p
));
2756 domain
= isl_pw_aff_domain(isl_pw_aff_copy(pwaff
));
2757 build
= isl_ast_build_from_context(domain
);
2758 expr
= isl_ast_build_expr_from_pw_aff(build
, isl_pw_aff_copy(pwaff
));
2759 p
= isl_printer_print_ast_expr(p
, expr
);
2760 isl_ast_expr_free(expr
);
2761 isl_ast_build_free(build
);
2766 __isl_give isl_printer
*isl_printer_print_aff(__isl_take isl_printer
*p
,
2767 __isl_keep isl_aff
*aff
)
2772 if (p
->output_format
== ISL_FORMAT_ISL
)
2773 return print_aff_isl(p
, aff
);
2774 else if (p
->output_format
== ISL_FORMAT_C
)
2775 return print_aff_c(p
, aff
);
2776 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2779 isl_printer_free(p
);
2783 __isl_give isl_printer
*isl_printer_print_pw_aff(__isl_take isl_printer
*p
,
2784 __isl_keep isl_pw_aff
*pwaff
)
2789 if (p
->output_format
== ISL_FORMAT_ISL
)
2790 return print_pw_aff_isl(p
, pwaff
);
2791 else if (p
->output_format
== ISL_FORMAT_C
)
2792 return print_pw_aff_c(p
, pwaff
);
2793 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2796 isl_printer_free(p
);
2800 /* Print "pa" in a sequence of isl_pw_affs delimited by semicolons.
2801 * Each isl_pw_aff itself is also printed as semicolon delimited
2802 * sequence of pieces.
2803 * If data->first = 1, then this is the first in the sequence.
2804 * Update data->first to tell the next element that it is not the first.
2806 static isl_stat
print_pw_aff_body_wrap(__isl_take isl_pw_aff
*pa
,
2809 struct isl_union_print_data
*data
;
2810 data
= (struct isl_union_print_data
*) user
;
2813 data
->p
= isl_printer_print_str(data
->p
, "; ");
2816 data
->p
= print_pw_aff_body(data
->p
, pa
);
2817 isl_pw_aff_free(pa
);
2819 return data
->p
? isl_stat_ok
: isl_stat_error
;
2822 /* Print the body of an isl_union_pw_aff, i.e., a semicolon delimited
2823 * sequence of affine expressions, each followed by constraints,
2824 * with the sequence enclosed in braces.
2826 static __isl_give isl_printer
*print_union_pw_aff_body(
2827 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2829 struct isl_union_print_data data
= { p
, 1 };
2831 p
= isl_printer_print_str(p
, s_open_set
[0]);
2833 if (isl_union_pw_aff_foreach_pw_aff(upa
,
2834 &print_pw_aff_body_wrap
, &data
) < 0)
2835 data
.p
= isl_printer_free(p
);
2837 p
= isl_printer_print_str(p
, s_close_set
[0]);
2842 /* Print the isl_union_pw_aff "upa" to "p" in isl format.
2844 * The individual isl_pw_affs are delimited by a semicolon.
2846 static __isl_give isl_printer
*print_union_pw_aff_isl(
2847 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2849 struct isl_print_space_data data
= { 0 };
2852 space
= isl_union_pw_aff_get_space(upa
);
2853 p
= print_param_tuple(p
, space
, &data
);
2854 isl_space_free(space
);
2855 p
= print_union_pw_aff_body(p
, upa
);
2859 /* Print the isl_union_pw_aff "upa" to "p".
2861 * We currently only support an isl format.
2863 __isl_give isl_printer
*isl_printer_print_union_pw_aff(
2864 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2867 return isl_printer_free(p
);
2869 if (p
->output_format
== ISL_FORMAT_ISL
)
2870 return print_union_pw_aff_isl(p
, upa
);
2871 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
2872 "unsupported output format", return isl_printer_free(p
));
2875 /* Print dimension "pos" of data->space to "p".
2877 * data->user is assumed to be an isl_multi_aff.
2879 * If the current dimension is an output dimension, then print
2880 * the corresponding expression. Otherwise, print the name of the dimension.
2882 static __isl_give isl_printer
*print_dim_ma(__isl_take isl_printer
*p
,
2883 struct isl_print_space_data
*data
, unsigned pos
)
2885 isl_multi_aff
*ma
= data
->user
;
2887 if (data
->type
== isl_dim_out
) {
2890 space
= isl_multi_aff_get_domain_space(ma
);
2891 p
= print_aff_body(p
, space
, ma
->u
.p
[pos
]);
2892 isl_space_free(space
);
2894 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2900 static __isl_give isl_printer
*print_multi_aff(__isl_take isl_printer
*p
,
2901 __isl_keep isl_multi_aff
*maff
)
2903 struct isl_print_space_data data
= { 0 };
2905 data
.print_dim
= &print_dim_ma
;
2907 return isl_print_space(maff
->space
, p
, 0, &data
);
2910 static __isl_give isl_printer
*print_multi_aff_isl(__isl_take isl_printer
*p
,
2911 __isl_keep isl_multi_aff
*maff
)
2913 struct isl_print_space_data data
= { 0 };
2918 p
= print_param_tuple(p
, maff
->space
, &data
);
2919 p
= isl_printer_print_str(p
, "{ ");
2920 p
= print_multi_aff(p
, maff
);
2921 p
= isl_printer_print_str(p
, " }");
2924 isl_printer_free(p
);
2928 __isl_give isl_printer
*isl_printer_print_multi_aff(__isl_take isl_printer
*p
,
2929 __isl_keep isl_multi_aff
*maff
)
2934 if (p
->output_format
== ISL_FORMAT_ISL
)
2935 return print_multi_aff_isl(p
, maff
);
2936 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2939 isl_printer_free(p
);
2943 static __isl_give isl_printer
*print_pw_multi_aff_body(
2944 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2951 for (i
= 0; i
< pma
->n
; ++i
) {
2955 p
= isl_printer_print_str(p
, "; ");
2956 p
= print_multi_aff(p
, pma
->p
[i
].maff
);
2957 space
= isl_multi_aff_get_domain_space(pma
->p
[i
].maff
);
2958 p
= print_disjuncts(set_to_map(pma
->p
[i
].set
), space
, p
, 0);
2959 isl_space_free(space
);
2963 isl_printer_free(p
);
2967 static __isl_give isl_printer
*print_pw_multi_aff_isl(__isl_take isl_printer
*p
,
2968 __isl_keep isl_pw_multi_aff
*pma
)
2970 struct isl_print_space_data data
= { 0 };
2975 p
= print_param_tuple(p
, pma
->dim
, &data
);
2976 p
= isl_printer_print_str(p
, "{ ");
2977 p
= print_pw_multi_aff_body(p
, pma
);
2978 p
= isl_printer_print_str(p
, " }");
2981 isl_printer_free(p
);
2985 /* Print the unnamed, single-dimensional piecewise multi affine expression "pma"
2988 static __isl_give isl_printer
*print_unnamed_pw_multi_aff_c(
2989 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2994 space
= isl_pw_multi_aff_get_domain_space(pma
);
2995 for (i
= 0; i
< pma
->n
- 1; ++i
) {
2996 p
= isl_printer_print_str(p
, "(");
2997 p
= print_set_c(p
, space
, pma
->p
[i
].set
);
2998 p
= isl_printer_print_str(p
, ") ? (");
2999 p
= print_aff_c(p
, pma
->p
[i
].maff
->u
.p
[0]);
3000 p
= isl_printer_print_str(p
, ") : ");
3002 isl_space_free(space
);
3004 return print_aff_c(p
, pma
->p
[pma
->n
- 1].maff
->u
.p
[0]);
3007 static __isl_give isl_printer
*print_pw_multi_aff_c(__isl_take isl_printer
*p
,
3008 __isl_keep isl_pw_multi_aff
*pma
)
3016 isl_die(p
->ctx
, isl_error_unsupported
,
3017 "cannot print empty isl_pw_multi_aff in C format",
3019 name
= isl_pw_multi_aff_get_tuple_name(pma
, isl_dim_out
);
3020 if (!name
&& isl_pw_multi_aff_dim(pma
, isl_dim_out
) == 1)
3021 return print_unnamed_pw_multi_aff_c(p
, pma
);
3023 isl_die(p
->ctx
, isl_error_unsupported
,
3024 "cannot print unnamed isl_pw_multi_aff in C format",
3027 p
= isl_printer_print_str(p
, name
);
3028 n
= isl_pw_multi_aff_dim(pma
, isl_dim_out
);
3030 isl_die(p
->ctx
, isl_error_unsupported
,
3031 "not supported yet", goto error
);
3035 isl_printer_free(p
);
3039 __isl_give isl_printer
*isl_printer_print_pw_multi_aff(
3040 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
3045 if (p
->output_format
== ISL_FORMAT_ISL
)
3046 return print_pw_multi_aff_isl(p
, pma
);
3047 if (p
->output_format
== ISL_FORMAT_C
)
3048 return print_pw_multi_aff_c(p
, pma
);
3049 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3052 isl_printer_free(p
);
3056 static isl_stat
print_pw_multi_aff_body_wrap(__isl_take isl_pw_multi_aff
*pma
,
3059 struct isl_union_print_data
*data
;
3060 data
= (struct isl_union_print_data
*) user
;
3063 data
->p
= isl_printer_print_str(data
->p
, "; ");
3066 data
->p
= print_pw_multi_aff_body(data
->p
, pma
);
3067 isl_pw_multi_aff_free(pma
);
3072 static __isl_give isl_printer
*print_union_pw_multi_aff_isl(
3073 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
3075 struct isl_union_print_data data
;
3076 struct isl_print_space_data space_data
= { 0 };
3079 space
= isl_union_pw_multi_aff_get_space(upma
);
3080 p
= print_param_tuple(p
, space
, &space_data
);
3081 isl_space_free(space
);
3082 p
= isl_printer_print_str(p
, s_open_set
[0]);
3085 isl_union_pw_multi_aff_foreach_pw_multi_aff(upma
,
3086 &print_pw_multi_aff_body_wrap
, &data
);
3088 p
= isl_printer_print_str(p
, s_close_set
[0]);
3092 __isl_give isl_printer
*isl_printer_print_union_pw_multi_aff(
3093 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
3098 if (p
->output_format
== ISL_FORMAT_ISL
)
3099 return print_union_pw_multi_aff_isl(p
, upma
);
3100 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3103 isl_printer_free(p
);
3107 /* Print dimension "pos" of data->space to "p".
3109 * data->user is assumed to be an isl_multi_pw_aff.
3111 * If the current dimension is an output dimension, then print
3112 * the corresponding piecewise affine expression.
3113 * Otherwise, print the name of the dimension.
3115 static __isl_give isl_printer
*print_dim_mpa(__isl_take isl_printer
*p
,
3116 struct isl_print_space_data
*data
, unsigned pos
)
3121 isl_multi_pw_aff
*mpa
= data
->user
;
3124 if (data
->type
!= isl_dim_out
)
3125 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
3129 return isl_printer_print_str(p
, "(0 : false)");
3131 need_parens
= pa
->n
!= 1 || !isl_set_plain_is_universe(pa
->p
[0].set
);
3133 p
= isl_printer_print_str(p
, "(");
3134 space
= isl_multi_pw_aff_get_domain_space(mpa
);
3135 for (i
= 0; i
< pa
->n
; ++i
) {
3138 p
= isl_printer_print_str(p
, "; ");
3139 p
= print_aff_body(p
, space
, pa
->p
[i
].aff
);
3140 p
= print_disjuncts(pa
->p
[i
].set
, space
, p
, 0);
3142 isl_space_free(space
);
3144 p
= isl_printer_print_str(p
, ")");
3149 /* Print "mpa" to "p" in isl format.
3151 * If "mpa" is zero-dimensional and has a non-trivial explicit domain,
3152 * then it is printed after the tuple of affine expressions.
3154 static __isl_give isl_printer
*print_multi_pw_aff_isl(__isl_take isl_printer
*p
,
3155 __isl_keep isl_multi_pw_aff
*mpa
)
3157 struct isl_print_space_data data
= { 0 };
3158 isl_bool has_domain
;
3161 return isl_printer_free(p
);
3163 p
= print_param_tuple(p
, mpa
->space
, &data
);
3164 p
= isl_printer_print_str(p
, "{ ");
3165 data
.print_dim
= &print_dim_mpa
;
3167 p
= isl_print_space(mpa
->space
, p
, 0, &data
);
3168 has_domain
= isl_multi_pw_aff_has_non_trivial_domain(mpa
);
3170 return isl_printer_free(p
);
3174 space
= isl_space_domain(isl_space_copy(mpa
->space
));
3175 p
= print_disjuncts_set(mpa
->u
.dom
, space
, p
, 0);
3176 isl_space_free(space
);
3178 p
= isl_printer_print_str(p
, " }");
3182 __isl_give isl_printer
*isl_printer_print_multi_pw_aff(
3183 __isl_take isl_printer
*p
, __isl_keep isl_multi_pw_aff
*mpa
)
3186 return isl_printer_free(p
);
3188 if (p
->output_format
== ISL_FORMAT_ISL
)
3189 return print_multi_pw_aff_isl(p
, mpa
);
3190 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3191 return isl_printer_free(p
));
3194 /* Print dimension "pos" of data->space to "p".
3196 * data->user is assumed to be an isl_multi_val.
3198 * If the current dimension is an output dimension, then print
3199 * the corresponding value. Otherwise, print the name of the dimension.
3201 static __isl_give isl_printer
*print_dim_mv(__isl_take isl_printer
*p
,
3202 struct isl_print_space_data
*data
, unsigned pos
)
3204 isl_multi_val
*mv
= data
->user
;
3206 if (data
->type
== isl_dim_out
)
3207 return isl_printer_print_val(p
, mv
->u
.p
[pos
]);
3209 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
3212 /* Print the isl_multi_val "mv" to "p" in isl format.
3214 static __isl_give isl_printer
*print_multi_val_isl(__isl_take isl_printer
*p
,
3215 __isl_keep isl_multi_val
*mv
)
3217 struct isl_print_space_data data
= { 0 };
3220 return isl_printer_free(p
);
3222 p
= print_param_tuple(p
, mv
->space
, &data
);
3223 p
= isl_printer_print_str(p
, "{ ");
3224 data
.print_dim
= &print_dim_mv
;
3226 p
= isl_print_space(mv
->space
, p
, 0, &data
);
3227 p
= isl_printer_print_str(p
, " }");
3231 /* Print the isl_multi_val "mv" to "p".
3233 * Currently only supported in isl format.
3235 __isl_give isl_printer
*isl_printer_print_multi_val(
3236 __isl_take isl_printer
*p
, __isl_keep isl_multi_val
*mv
)
3239 return isl_printer_free(p
);
3241 if (p
->output_format
== ISL_FORMAT_ISL
)
3242 return print_multi_val_isl(p
, mv
);
3243 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3244 return isl_printer_free(p
));
3247 /* Print dimension "pos" of data->space to "p".
3249 * data->user is assumed to be an isl_multi_union_pw_aff.
3251 * The current dimension is necessarily a set dimension, so
3252 * we print the corresponding isl_union_pw_aff, including
3255 static __isl_give isl_printer
*print_union_pw_aff_dim(__isl_take isl_printer
*p
,
3256 struct isl_print_space_data
*data
, unsigned pos
)
3258 isl_multi_union_pw_aff
*mupa
= data
->user
;
3259 isl_union_pw_aff
*upa
;
3261 upa
= isl_multi_union_pw_aff_get_union_pw_aff(mupa
, pos
);
3262 p
= print_union_pw_aff_body(p
, upa
);
3263 isl_union_pw_aff_free(upa
);
3268 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3270 * If "mupa" is zero-dimensional and has a non-trivial explicit domain,
3271 * then it is printed after the tuple of affine expressions.
3272 * In order to clarify that this domain belongs to the expression,
3273 * the tuple along with the domain are placed inside parentheses.
3274 * If "mupa" has any parameters, then the opening parenthesis
3275 * appears after the parameter declarations.
3277 static __isl_give isl_printer
*print_multi_union_pw_aff_isl(
3278 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3280 struct isl_print_space_data data
= { 0 };
3281 isl_bool has_domain
;
3285 return isl_printer_free(p
);
3286 has_domain
= isl_multi_union_pw_aff_has_non_trivial_domain(mupa
);
3288 return isl_printer_free(p
);
3290 space
= isl_multi_union_pw_aff_get_space(mupa
);
3291 p
= print_param_tuple(p
, space
, &data
);
3294 p
= isl_printer_print_str(p
, "(");
3296 data
.print_dim
= &print_union_pw_aff_dim
;
3299 p
= isl_print_space(space
, p
, 0, &data
);
3300 isl_space_free(space
);
3303 p
= isl_printer_print_str(p
, " : ");
3304 p
= isl_printer_print_union_set_isl_body(p
, mupa
->u
.dom
);
3305 p
= isl_printer_print_str(p
, ")");
3311 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3313 * We currently only support an isl format.
3315 __isl_give isl_printer
*isl_printer_print_multi_union_pw_aff(
3316 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3319 return isl_printer_free(p
);
3321 if (p
->output_format
== ISL_FORMAT_ISL
)
3322 return print_multi_union_pw_aff_isl(p
, mupa
);
3323 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
3324 "unsupported output format", return isl_printer_free(p
));