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_affine_c(__isl_take isl_printer
*p
,
2081 __isl_keep isl_space
*space
, __isl_keep isl_basic_set
*bset
,
2084 static __isl_give isl_printer
*print_name_c(__isl_take isl_printer
*p
,
2085 __isl_keep isl_space
*dim
,
2086 __isl_keep isl_basic_set
*bset
, enum isl_dim_type type
, unsigned pos
)
2088 if (type
== isl_dim_div
) {
2089 p
= isl_printer_print_str(p
, "floord(");
2090 p
= print_affine_c(p
, dim
, bset
, bset
->div
[pos
] + 1);
2091 p
= isl_printer_print_str(p
, ", ");
2092 p
= isl_printer_print_isl_int(p
, bset
->div
[pos
][0]);
2093 p
= isl_printer_print_str(p
, ")");
2097 name
= isl_space_get_dim_name(dim
, type
, pos
);
2100 p
= isl_printer_print_str(p
, name
);
2105 static __isl_give isl_printer
*print_term_c(__isl_take isl_printer
*p
,
2106 __isl_keep isl_space
*space
,
2107 __isl_keep isl_basic_set
*bset
, isl_int c
, unsigned pos
)
2109 enum isl_dim_type type
;
2112 return isl_printer_free(p
);
2115 return isl_printer_print_isl_int(p
, c
);
2117 if (isl_int_is_one(c
))
2119 else if (isl_int_is_negone(c
))
2120 p
= isl_printer_print_str(p
, "-");
2122 p
= isl_printer_print_isl_int(p
, c
);
2123 p
= isl_printer_print_str(p
, "*");
2125 type
= pos2type(space
, &pos
);
2126 p
= print_name_c(p
, space
, bset
, type
, pos
);
2130 static __isl_give isl_printer
*print_partial_affine_c(__isl_take isl_printer
*p
,
2131 __isl_keep isl_space
*dim
,
2132 __isl_keep isl_basic_set
*bset
, isl_int
*c
, unsigned len
)
2137 for (i
= 0, first
= 1; i
< len
; ++i
) {
2139 if (isl_int_is_zero(c
[i
]))
2142 if (isl_int_is_neg(c
[i
])) {
2144 isl_int_neg(c
[i
], c
[i
]);
2145 p
= isl_printer_print_str(p
, " - ");
2147 p
= isl_printer_print_str(p
, " + ");
2150 p
= print_term_c(p
, dim
, bset
, c
[i
], i
);
2152 isl_int_neg(c
[i
], c
[i
]);
2155 p
= isl_printer_print_str(p
, "0");
2159 static __isl_give isl_printer
*print_affine_c(__isl_take isl_printer
*p
,
2160 __isl_keep isl_space
*space
, __isl_keep isl_basic_set
*bset
, isl_int
*c
)
2162 unsigned len
= 1 + isl_basic_set_total_dim(bset
);
2163 return print_partial_affine_c(p
, space
, bset
, c
, len
);
2166 /* We skip the constraint if it is implied by the div expression.
2168 * *first indicates whether this is the first constraint in the conjunction and
2169 * is updated if the constraint is actually printed.
2171 static __isl_give isl_printer
*print_constraint_c(__isl_take isl_printer
*p
,
2172 __isl_keep isl_space
*dim
,
2173 __isl_keep isl_basic_set
*bset
, isl_int
*c
, const char *op
, int *first
)
2179 o_div
= isl_basic_set_offset(bset
, isl_dim_div
);
2180 n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
2181 div
= isl_seq_last_non_zero(c
+ o_div
, n_div
);
2183 isl_bool is_div
= isl_basic_set_is_div_constraint(bset
, c
, div
);
2185 return isl_printer_free(p
);
2191 p
= isl_printer_print_str(p
, " && ");
2193 p
= print_affine_c(p
, dim
, bset
, c
);
2194 p
= isl_printer_print_str(p
, " ");
2195 p
= isl_printer_print_str(p
, op
);
2196 p
= isl_printer_print_str(p
, " 0");
2203 static __isl_give isl_printer
*print_basic_set_c(__isl_take isl_printer
*p
,
2204 __isl_keep isl_space
*space
, __isl_keep isl_basic_set
*bset
)
2208 unsigned n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
2209 unsigned total
= isl_basic_set_total_dim(bset
) - n_div
;
2211 for (i
= 0; i
< bset
->n_eq
; ++i
) {
2212 j
= isl_seq_last_non_zero(bset
->eq
[i
] + 1 + total
, n_div
);
2214 p
= print_constraint_c(p
, space
, bset
,
2215 bset
->eq
[i
], "==", &first
);
2218 p
= isl_printer_print_str(p
, " && ");
2219 p
= isl_printer_print_str(p
, "(");
2220 p
= print_partial_affine_c(p
, space
, bset
, bset
->eq
[i
],
2222 p
= isl_printer_print_str(p
, ") % ");
2223 p
= isl_printer_print_isl_int(p
,
2224 bset
->eq
[i
][1 + total
+ j
]);
2225 p
= isl_printer_print_str(p
, " == 0");
2229 for (i
= 0; i
< bset
->n_ineq
; ++i
)
2230 p
= print_constraint_c(p
, space
, bset
, bset
->ineq
[i
], ">=",
2235 static __isl_give isl_printer
*print_set_c(__isl_take isl_printer
*p
,
2236 __isl_keep isl_space
*space
, __isl_keep isl_set
*set
)
2241 return isl_printer_free(p
);
2244 p
= isl_printer_print_str(p
, "0");
2246 for (i
= 0; i
< set
->n
; ++i
) {
2248 p
= isl_printer_print_str(p
, " || ");
2250 p
= isl_printer_print_str(p
, "(");
2251 p
= print_basic_set_c(p
, space
, set
->p
[i
]);
2253 p
= isl_printer_print_str(p
, ")");
2258 /* Print the piecewise quasi-polynomial "pwqp" to "p" in C format.
2260 static __isl_give isl_printer
*print_pw_qpolynomial_c(
2261 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2266 space
= isl_pw_qpolynomial_get_domain_space(pwqp
);
2267 if (pwqp
->n
== 1 && isl_set_plain_is_universe(pwqp
->p
[0].set
)) {
2268 p
= print_qpolynomial_c(p
, space
, pwqp
->p
[0].qp
);
2269 isl_space_free(space
);
2273 for (i
= 0; i
< pwqp
->n
; ++i
) {
2274 p
= isl_printer_print_str(p
, "(");
2275 p
= print_set_c(p
, space
, pwqp
->p
[i
].set
);
2276 p
= isl_printer_print_str(p
, ") ? (");
2277 p
= print_qpolynomial_c(p
, space
, pwqp
->p
[i
].qp
);
2278 p
= isl_printer_print_str(p
, ") : ");
2281 isl_space_free(space
);
2282 p
= isl_printer_print_str(p
, "0");
2286 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial(
2287 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2292 if (p
->output_format
== ISL_FORMAT_ISL
)
2293 return print_pw_qpolynomial_isl(p
, pwqp
);
2294 else if (p
->output_format
== ISL_FORMAT_C
)
2295 return print_pw_qpolynomial_c(p
, pwqp
);
2296 isl_assert(p
->ctx
, 0, goto error
);
2298 isl_printer_free(p
);
2302 static isl_stat
print_pwqp_body(__isl_take isl_pw_qpolynomial
*pwqp
, void *user
)
2304 struct isl_union_print_data
*data
;
2305 data
= (struct isl_union_print_data
*)user
;
2308 data
->p
= isl_printer_print_str(data
->p
, "; ");
2311 data
->p
= isl_pwqp_print_isl_body(data
->p
, pwqp
);
2312 isl_pw_qpolynomial_free(pwqp
);
2317 static __isl_give isl_printer
*print_union_pw_qpolynomial_isl(
2318 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2320 struct isl_union_print_data data
;
2321 struct isl_print_space_data space_data
= { 0 };
2324 space
= isl_union_pw_qpolynomial_get_space(upwqp
);
2325 p
= print_param_tuple(p
, space
, &space_data
);
2326 isl_space_free(space
);
2327 p
= isl_printer_print_str(p
, "{ ");
2330 isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp
, &print_pwqp_body
,
2333 p
= isl_printer_print_str(p
, " }");
2337 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial(
2338 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2343 if (p
->output_format
== ISL_FORMAT_ISL
)
2344 return print_union_pw_qpolynomial_isl(p
, upwqp
);
2345 isl_die(p
->ctx
, isl_error_invalid
,
2346 "invalid output format for isl_union_pw_qpolynomial",
2349 isl_printer_free(p
);
2353 /* Print the quasi-polynomial reduction "fold" to "p" in C format,
2354 * with the variable names taken from the domain space "space".
2356 static __isl_give isl_printer
*print_qpolynomial_fold_c(
2357 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
,
2358 __isl_keep isl_qpolynomial_fold
*fold
)
2362 for (i
= 0; i
< fold
->n
- 1; ++i
)
2363 if (fold
->type
== isl_fold_min
)
2364 p
= isl_printer_print_str(p
, "min(");
2365 else if (fold
->type
== isl_fold_max
)
2366 p
= isl_printer_print_str(p
, "max(");
2368 for (i
= 0; i
< fold
->n
; ++i
) {
2370 p
= isl_printer_print_str(p
, ", ");
2371 p
= print_qpolynomial_c(p
, space
, fold
->qp
[i
]);
2373 p
= isl_printer_print_str(p
, ")");
2378 __isl_give isl_printer
*isl_printer_print_qpolynomial_fold(
2379 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial_fold
*fold
)
2383 if (p
->output_format
== ISL_FORMAT_ISL
)
2384 return qpolynomial_fold_print(fold
, p
);
2385 else if (p
->output_format
== ISL_FORMAT_C
)
2386 return print_qpolynomial_fold_c(p
, fold
->dim
, fold
);
2387 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2390 isl_printer_free(p
);
2394 /* Print the piecewise quasi-polynomial reduction "pwf" to "p" in C format.
2396 static __isl_give isl_printer
*print_pw_qpolynomial_fold_c(
2397 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2402 space
= isl_pw_qpolynomial_fold_get_domain_space(pwf
);
2403 if (pwf
->n
== 1 && isl_set_plain_is_universe(pwf
->p
[0].set
)) {
2404 p
= print_qpolynomial_fold_c(p
, space
, pwf
->p
[0].fold
);
2405 isl_space_free(space
);
2409 for (i
= 0; i
< pwf
->n
; ++i
) {
2410 p
= isl_printer_print_str(p
, "(");
2411 p
= print_set_c(p
, space
, pwf
->p
[i
].set
);
2412 p
= isl_printer_print_str(p
, ") ? (");
2413 p
= print_qpolynomial_fold_c(p
, space
, pwf
->p
[i
].fold
);
2414 p
= isl_printer_print_str(p
, ") : ");
2417 isl_space_free(space
);
2418 p
= isl_printer_print_str(p
, "0");
2422 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial_fold(
2423 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2428 if (p
->output_format
== ISL_FORMAT_ISL
)
2429 return print_pw_qpolynomial_fold_isl(p
, pwf
);
2430 else if (p
->output_format
== ISL_FORMAT_C
)
2431 return print_pw_qpolynomial_fold_c(p
, pwf
);
2432 isl_assert(p
->ctx
, 0, goto error
);
2434 isl_printer_free(p
);
2438 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold
*pwf
,
2439 FILE *out
, unsigned output_format
)
2446 p
= isl_printer_to_file(pwf
->dim
->ctx
, out
);
2447 p
= isl_printer_set_output_format(p
, output_format
);
2448 p
= isl_printer_print_pw_qpolynomial_fold(p
, pwf
);
2450 isl_printer_free(p
);
2453 static isl_stat
print_pwf_body(__isl_take isl_pw_qpolynomial_fold
*pwf
,
2456 struct isl_union_print_data
*data
;
2457 data
= (struct isl_union_print_data
*)user
;
2460 data
->p
= isl_printer_print_str(data
->p
, "; ");
2463 data
->p
= isl_pwf_print_isl_body(data
->p
, pwf
);
2464 isl_pw_qpolynomial_fold_free(pwf
);
2469 static __isl_give isl_printer
*print_union_pw_qpolynomial_fold_isl(
2470 __isl_take isl_printer
*p
,
2471 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2473 struct isl_union_print_data data
;
2474 struct isl_print_space_data space_data
= { 0 };
2477 space
= isl_union_pw_qpolynomial_fold_get_space(upwf
);
2478 p
= print_param_tuple(p
, space
, &space_data
);
2479 isl_space_free(space
);
2480 p
= isl_printer_print_str(p
, "{ ");
2483 isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(upwf
,
2484 &print_pwf_body
, &data
);
2486 p
= isl_printer_print_str(p
, " }");
2490 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial_fold(
2491 __isl_take isl_printer
*p
,
2492 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2497 if (p
->output_format
== ISL_FORMAT_ISL
)
2498 return print_union_pw_qpolynomial_fold_isl(p
, upwf
);
2499 isl_die(p
->ctx
, isl_error_invalid
,
2500 "invalid output format for isl_union_pw_qpolynomial_fold",
2503 isl_printer_free(p
);
2507 /* Print the isl_constraint "c" to "p".
2509 __isl_give isl_printer
*isl_printer_print_constraint(__isl_take isl_printer
*p
,
2510 __isl_keep isl_constraint
*c
)
2512 struct isl_print_space_data data
= { 0 };
2513 isl_local_space
*ls
;
2520 ls
= isl_constraint_get_local_space(c
);
2522 return isl_printer_free(p
);
2523 space
= isl_local_space_get_space(ls
);
2524 p
= print_param_tuple(p
, space
, &data
);
2525 p
= isl_printer_print_str(p
, "{ ");
2526 p
= isl_print_space(space
, p
, 0, &data
);
2527 p
= isl_printer_print_str(p
, " : ");
2528 exists
= need_exists(p
, ls
->div
);
2530 p
= isl_printer_free(p
);
2531 if (exists
>= 0 && exists
)
2532 p
= open_exists(p
, space
, ls
->div
, 0);
2533 p
= print_affine_of_len(space
, ls
->div
, p
, c
->v
->el
, c
->v
->size
);
2534 if (isl_constraint_is_equality(c
))
2535 p
= isl_printer_print_str(p
, " = 0");
2537 p
= isl_printer_print_str(p
, " >= 0");
2538 if (exists
>= 0 && exists
)
2539 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2540 p
= isl_printer_print_str(p
, " }");
2541 isl_space_free(space
);
2542 isl_local_space_free(ls
);
2546 isl_printer_free(p
);
2550 static __isl_give isl_printer
*isl_printer_print_space_isl(
2551 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
)
2553 struct isl_print_space_data data
= { 0 };
2558 p
= print_param_tuple(p
, space
, &data
);
2560 p
= isl_printer_print_str(p
, "{ ");
2561 if (isl_space_is_params(space
))
2562 p
= isl_printer_print_str(p
, s_such_that
[0]);
2564 p
= isl_print_space(space
, p
, 0, &data
);
2565 p
= isl_printer_print_str(p
, " }");
2569 isl_printer_free(p
);
2573 __isl_give isl_printer
*isl_printer_print_space(__isl_take isl_printer
*p
,
2574 __isl_keep isl_space
*space
)
2577 return isl_printer_free(p
);
2578 if (p
->output_format
== ISL_FORMAT_ISL
)
2579 return isl_printer_print_space_isl(p
, space
);
2580 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
2581 return print_omega_parameters(space
, p
);
2583 isl_die(isl_space_get_ctx(space
), isl_error_unsupported
,
2584 "output format not supported for space",
2585 return isl_printer_free(p
));
2588 __isl_give isl_printer
*isl_printer_print_local_space(__isl_take isl_printer
*p
,
2589 __isl_keep isl_local_space
*ls
)
2591 struct isl_print_space_data data
= { 0 };
2597 p
= print_param_tuple(p
, ls
->dim
, &data
);
2598 p
= isl_printer_print_str(p
, "{ ");
2599 p
= isl_print_space(ls
->dim
, p
, 0, &data
);
2600 n_div
= isl_local_space_dim(ls
, isl_dim_div
);
2602 p
= isl_printer_print_str(p
, " : ");
2603 p
= isl_printer_print_str(p
, s_open_exists
[0]);
2604 p
= print_div_list(p
, ls
->dim
, ls
->div
, 0, 1);
2605 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2606 } else if (isl_space_is_params(ls
->dim
))
2607 p
= isl_printer_print_str(p
, s_such_that
[0]);
2608 p
= isl_printer_print_str(p
, " }");
2611 isl_printer_free(p
);
2615 /* Print the (potentially rational) affine expression "aff" to "p",
2616 * with the variable names taken from "space".
2618 static __isl_give isl_printer
*print_aff_body(__isl_take isl_printer
*p
,
2619 __isl_keep isl_space
*space
, __isl_keep isl_aff
*aff
)
2623 if (isl_aff_is_nan(aff
))
2624 return isl_printer_print_str(p
, "NaN");
2626 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2627 p
= isl_printer_print_str(p
, "(");
2628 p
= print_affine_of_len(space
, aff
->ls
->div
, p
,
2629 aff
->v
->el
+ 1, 1 + total
);
2630 if (isl_int_is_one(aff
->v
->el
[0]))
2631 p
= isl_printer_print_str(p
, ")");
2633 p
= isl_printer_print_str(p
, ")/");
2634 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2640 static __isl_give isl_printer
*print_aff(__isl_take isl_printer
*p
,
2641 __isl_keep isl_aff
*aff
)
2643 struct isl_print_space_data data
= { 0 };
2645 if (isl_space_is_params(aff
->ls
->dim
))
2648 p
= print_tuple(aff
->ls
->dim
, p
, isl_dim_set
, &data
);
2649 p
= isl_printer_print_str(p
, " -> ");
2651 p
= isl_printer_print_str(p
, "[");
2652 p
= print_aff_body(p
, aff
->ls
->dim
, aff
);
2653 p
= isl_printer_print_str(p
, "]");
2658 static __isl_give isl_printer
*print_aff_isl(__isl_take isl_printer
*p
,
2659 __isl_keep isl_aff
*aff
)
2661 struct isl_print_space_data data
= { 0 };
2666 p
= print_param_tuple(p
, aff
->ls
->dim
, &data
);
2667 p
= isl_printer_print_str(p
, "{ ");
2668 p
= print_aff(p
, aff
);
2669 p
= isl_printer_print_str(p
, " }");
2672 isl_printer_free(p
);
2676 /* Print the body of an isl_pw_aff, i.e., a semicolon delimited
2677 * sequence of affine expressions, each followed by constraints.
2679 static __isl_give isl_printer
*print_pw_aff_body(
2680 __isl_take isl_printer
*p
, __isl_keep isl_pw_aff
*pa
)
2685 return isl_printer_free(p
);
2687 for (i
= 0; i
< pa
->n
; ++i
) {
2691 p
= isl_printer_print_str(p
, "; ");
2692 p
= print_aff(p
, pa
->p
[i
].aff
);
2693 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
2694 p
= print_disjuncts(set_to_map(pa
->p
[i
].set
), space
, p
, 0);
2695 isl_space_free(space
);
2701 static __isl_give isl_printer
*print_pw_aff_isl(__isl_take isl_printer
*p
,
2702 __isl_keep isl_pw_aff
*pwaff
)
2704 struct isl_print_space_data data
= { 0 };
2709 p
= print_param_tuple(p
, pwaff
->dim
, &data
);
2710 p
= isl_printer_print_str(p
, "{ ");
2711 p
= print_pw_aff_body(p
, pwaff
);
2712 p
= isl_printer_print_str(p
, " }");
2715 isl_printer_free(p
);
2719 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2720 __isl_keep isl_local_space
*ls
, isl_int
*c
);
2722 static __isl_give isl_printer
*print_ls_name_c(__isl_take isl_printer
*p
,
2723 __isl_keep isl_local_space
*ls
, enum isl_dim_type type
, unsigned pos
)
2725 if (type
== isl_dim_div
) {
2726 p
= isl_printer_print_str(p
, "floord(");
2727 p
= print_ls_affine_c(p
, ls
, ls
->div
->row
[pos
] + 1);
2728 p
= isl_printer_print_str(p
, ", ");
2729 p
= isl_printer_print_isl_int(p
, ls
->div
->row
[pos
][0]);
2730 p
= isl_printer_print_str(p
, ")");
2734 name
= isl_space_get_dim_name(ls
->dim
, type
, pos
);
2737 p
= isl_printer_print_str(p
, name
);
2742 static __isl_give isl_printer
*print_ls_term_c(__isl_take isl_printer
*p
,
2743 __isl_keep isl_local_space
*ls
, isl_int c
, unsigned pos
)
2745 enum isl_dim_type type
;
2748 return isl_printer_free(p
);
2751 return isl_printer_print_isl_int(p
, c
);
2753 if (isl_int_is_one(c
))
2755 else if (isl_int_is_negone(c
))
2756 p
= isl_printer_print_str(p
, "-");
2758 p
= isl_printer_print_isl_int(p
, c
);
2759 p
= isl_printer_print_str(p
, "*");
2761 type
= pos2type(ls
->dim
, &pos
);
2762 p
= print_ls_name_c(p
, ls
, type
, pos
);
2766 static __isl_give isl_printer
*print_ls_partial_affine_c(
2767 __isl_take isl_printer
*p
, __isl_keep isl_local_space
*ls
,
2768 isl_int
*c
, unsigned len
)
2773 for (i
= 0, first
= 1; i
< len
; ++i
) {
2775 if (isl_int_is_zero(c
[i
]))
2778 if (isl_int_is_neg(c
[i
])) {
2780 isl_int_neg(c
[i
], c
[i
]);
2781 p
= isl_printer_print_str(p
, " - ");
2783 p
= isl_printer_print_str(p
, " + ");
2786 p
= print_ls_term_c(p
, ls
, c
[i
], i
);
2788 isl_int_neg(c
[i
], c
[i
]);
2791 p
= isl_printer_print_str(p
, "0");
2795 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2796 __isl_keep isl_local_space
*ls
, isl_int
*c
)
2798 unsigned len
= 1 + isl_local_space_dim(ls
, isl_dim_all
);
2799 return print_ls_partial_affine_c(p
, ls
, c
, len
);
2802 static __isl_give isl_printer
*print_aff_c(__isl_take isl_printer
*p
,
2803 __isl_keep isl_aff
*aff
)
2807 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2808 if (!isl_int_is_one(aff
->v
->el
[0]))
2809 p
= isl_printer_print_str(p
, "(");
2810 p
= print_ls_partial_affine_c(p
, aff
->ls
, aff
->v
->el
+ 1, 1 + total
);
2811 if (!isl_int_is_one(aff
->v
->el
[0])) {
2812 p
= isl_printer_print_str(p
, ")/");
2813 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2818 /* In the C format, we cannot express that "pwaff" may be undefined
2819 * on parts of the domain space. We therefore assume that the expression
2820 * will only be evaluated on its definition domain and compute the gist
2821 * of each cell with respect to this domain.
2823 static __isl_give isl_printer
*print_pw_aff_c(__isl_take isl_printer
*p
,
2824 __isl_keep isl_pw_aff
*pwaff
)
2827 isl_ast_build
*build
;
2831 isl_die(p
->ctx
, isl_error_unsupported
,
2832 "cannot print empty isl_pw_aff in C format",
2833 return isl_printer_free(p
));
2835 domain
= isl_pw_aff_domain(isl_pw_aff_copy(pwaff
));
2836 build
= isl_ast_build_from_context(domain
);
2837 expr
= isl_ast_build_expr_from_pw_aff(build
, isl_pw_aff_copy(pwaff
));
2838 p
= isl_printer_print_ast_expr(p
, expr
);
2839 isl_ast_expr_free(expr
);
2840 isl_ast_build_free(build
);
2845 __isl_give isl_printer
*isl_printer_print_aff(__isl_take isl_printer
*p
,
2846 __isl_keep isl_aff
*aff
)
2851 if (p
->output_format
== ISL_FORMAT_ISL
)
2852 return print_aff_isl(p
, aff
);
2853 else if (p
->output_format
== ISL_FORMAT_C
)
2854 return print_aff_c(p
, aff
);
2855 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2858 isl_printer_free(p
);
2862 __isl_give isl_printer
*isl_printer_print_pw_aff(__isl_take isl_printer
*p
,
2863 __isl_keep isl_pw_aff
*pwaff
)
2868 if (p
->output_format
== ISL_FORMAT_ISL
)
2869 return print_pw_aff_isl(p
, pwaff
);
2870 else if (p
->output_format
== ISL_FORMAT_C
)
2871 return print_pw_aff_c(p
, pwaff
);
2872 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2875 isl_printer_free(p
);
2879 /* Print "pa" in a sequence of isl_pw_affs delimited by semicolons.
2880 * Each isl_pw_aff itself is also printed as semicolon delimited
2881 * sequence of pieces.
2882 * If data->first = 1, then this is the first in the sequence.
2883 * Update data->first to tell the next element that it is not the first.
2885 static isl_stat
print_pw_aff_body_wrap(__isl_take isl_pw_aff
*pa
,
2888 struct isl_union_print_data
*data
;
2889 data
= (struct isl_union_print_data
*) user
;
2892 data
->p
= isl_printer_print_str(data
->p
, "; ");
2895 data
->p
= print_pw_aff_body(data
->p
, pa
);
2896 isl_pw_aff_free(pa
);
2898 return data
->p
? isl_stat_ok
: isl_stat_error
;
2901 /* Print the body of an isl_union_pw_aff, i.e., a semicolon delimited
2902 * sequence of affine expressions, each followed by constraints,
2903 * with the sequence enclosed in braces.
2905 static __isl_give isl_printer
*print_union_pw_aff_body(
2906 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2908 struct isl_union_print_data data
= { p
, 1 };
2910 p
= isl_printer_print_str(p
, s_open_set
[0]);
2912 if (isl_union_pw_aff_foreach_pw_aff(upa
,
2913 &print_pw_aff_body_wrap
, &data
) < 0)
2914 data
.p
= isl_printer_free(p
);
2916 p
= isl_printer_print_str(p
, s_close_set
[0]);
2921 /* Print the isl_union_pw_aff "upa" to "p" in isl format.
2923 * The individual isl_pw_affs are delimited by a semicolon.
2925 static __isl_give isl_printer
*print_union_pw_aff_isl(
2926 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2928 struct isl_print_space_data data
= { 0 };
2931 space
= isl_union_pw_aff_get_space(upa
);
2932 p
= print_param_tuple(p
, space
, &data
);
2933 isl_space_free(space
);
2934 p
= print_union_pw_aff_body(p
, upa
);
2938 /* Print the isl_union_pw_aff "upa" to "p".
2940 * We currently only support an isl format.
2942 __isl_give isl_printer
*isl_printer_print_union_pw_aff(
2943 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2946 return isl_printer_free(p
);
2948 if (p
->output_format
== ISL_FORMAT_ISL
)
2949 return print_union_pw_aff_isl(p
, upa
);
2950 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
2951 "unsupported output format", return isl_printer_free(p
));
2954 /* Print dimension "pos" of data->space to "p".
2956 * data->user is assumed to be an isl_multi_aff.
2958 * If the current dimension is an output dimension, then print
2959 * the corresponding expression. Otherwise, print the name of the dimension.
2961 static __isl_give isl_printer
*print_dim_ma(__isl_take isl_printer
*p
,
2962 struct isl_print_space_data
*data
, unsigned pos
)
2964 isl_multi_aff
*ma
= data
->user
;
2966 if (data
->type
== isl_dim_out
) {
2969 space
= isl_multi_aff_get_domain_space(ma
);
2970 p
= print_aff_body(p
, space
, ma
->u
.p
[pos
]);
2971 isl_space_free(space
);
2973 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2979 static __isl_give isl_printer
*print_multi_aff(__isl_take isl_printer
*p
,
2980 __isl_keep isl_multi_aff
*maff
)
2982 struct isl_print_space_data data
= { 0 };
2984 data
.print_dim
= &print_dim_ma
;
2986 return isl_print_space(maff
->space
, p
, 0, &data
);
2989 static __isl_give isl_printer
*print_multi_aff_isl(__isl_take isl_printer
*p
,
2990 __isl_keep isl_multi_aff
*maff
)
2992 struct isl_print_space_data data
= { 0 };
2997 p
= print_param_tuple(p
, maff
->space
, &data
);
2998 p
= isl_printer_print_str(p
, "{ ");
2999 p
= print_multi_aff(p
, maff
);
3000 p
= isl_printer_print_str(p
, " }");
3003 isl_printer_free(p
);
3007 __isl_give isl_printer
*isl_printer_print_multi_aff(__isl_take isl_printer
*p
,
3008 __isl_keep isl_multi_aff
*maff
)
3013 if (p
->output_format
== ISL_FORMAT_ISL
)
3014 return print_multi_aff_isl(p
, maff
);
3015 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3018 isl_printer_free(p
);
3022 static __isl_give isl_printer
*print_pw_multi_aff_body(
3023 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
3030 for (i
= 0; i
< pma
->n
; ++i
) {
3034 p
= isl_printer_print_str(p
, "; ");
3035 p
= print_multi_aff(p
, pma
->p
[i
].maff
);
3036 space
= isl_multi_aff_get_domain_space(pma
->p
[i
].maff
);
3037 p
= print_disjuncts(set_to_map(pma
->p
[i
].set
), space
, p
, 0);
3038 isl_space_free(space
);
3042 isl_printer_free(p
);
3046 static __isl_give isl_printer
*print_pw_multi_aff_isl(__isl_take isl_printer
*p
,
3047 __isl_keep isl_pw_multi_aff
*pma
)
3049 struct isl_print_space_data data
= { 0 };
3054 p
= print_param_tuple(p
, pma
->dim
, &data
);
3055 p
= isl_printer_print_str(p
, "{ ");
3056 p
= print_pw_multi_aff_body(p
, pma
);
3057 p
= isl_printer_print_str(p
, " }");
3060 isl_printer_free(p
);
3064 /* Print the unnamed, single-dimensional piecewise multi affine expression "pma"
3067 static __isl_give isl_printer
*print_unnamed_pw_multi_aff_c(
3068 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
3073 space
= isl_pw_multi_aff_get_domain_space(pma
);
3074 for (i
= 0; i
< pma
->n
- 1; ++i
) {
3075 p
= isl_printer_print_str(p
, "(");
3076 p
= print_set_c(p
, space
, pma
->p
[i
].set
);
3077 p
= isl_printer_print_str(p
, ") ? (");
3078 p
= print_aff_c(p
, pma
->p
[i
].maff
->u
.p
[0]);
3079 p
= isl_printer_print_str(p
, ") : ");
3081 isl_space_free(space
);
3083 return print_aff_c(p
, pma
->p
[pma
->n
- 1].maff
->u
.p
[0]);
3086 static __isl_give isl_printer
*print_pw_multi_aff_c(__isl_take isl_printer
*p
,
3087 __isl_keep isl_pw_multi_aff
*pma
)
3095 isl_die(p
->ctx
, isl_error_unsupported
,
3096 "cannot print empty isl_pw_multi_aff in C format",
3098 name
= isl_pw_multi_aff_get_tuple_name(pma
, isl_dim_out
);
3099 if (!name
&& isl_pw_multi_aff_dim(pma
, isl_dim_out
) == 1)
3100 return print_unnamed_pw_multi_aff_c(p
, pma
);
3102 isl_die(p
->ctx
, isl_error_unsupported
,
3103 "cannot print unnamed isl_pw_multi_aff in C format",
3106 p
= isl_printer_print_str(p
, name
);
3107 n
= isl_pw_multi_aff_dim(pma
, isl_dim_out
);
3109 isl_die(p
->ctx
, isl_error_unsupported
,
3110 "not supported yet", goto error
);
3114 isl_printer_free(p
);
3118 __isl_give isl_printer
*isl_printer_print_pw_multi_aff(
3119 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
3124 if (p
->output_format
== ISL_FORMAT_ISL
)
3125 return print_pw_multi_aff_isl(p
, pma
);
3126 if (p
->output_format
== ISL_FORMAT_C
)
3127 return print_pw_multi_aff_c(p
, pma
);
3128 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3131 isl_printer_free(p
);
3135 static isl_stat
print_pw_multi_aff_body_wrap(__isl_take isl_pw_multi_aff
*pma
,
3138 struct isl_union_print_data
*data
;
3139 data
= (struct isl_union_print_data
*) user
;
3142 data
->p
= isl_printer_print_str(data
->p
, "; ");
3145 data
->p
= print_pw_multi_aff_body(data
->p
, pma
);
3146 isl_pw_multi_aff_free(pma
);
3151 static __isl_give isl_printer
*print_union_pw_multi_aff_isl(
3152 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
3154 struct isl_union_print_data data
;
3155 struct isl_print_space_data space_data
= { 0 };
3158 space
= isl_union_pw_multi_aff_get_space(upma
);
3159 p
= print_param_tuple(p
, space
, &space_data
);
3160 isl_space_free(space
);
3161 p
= isl_printer_print_str(p
, s_open_set
[0]);
3164 isl_union_pw_multi_aff_foreach_pw_multi_aff(upma
,
3165 &print_pw_multi_aff_body_wrap
, &data
);
3167 p
= isl_printer_print_str(p
, s_close_set
[0]);
3171 __isl_give isl_printer
*isl_printer_print_union_pw_multi_aff(
3172 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
3177 if (p
->output_format
== ISL_FORMAT_ISL
)
3178 return print_union_pw_multi_aff_isl(p
, upma
);
3179 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3182 isl_printer_free(p
);
3186 /* Print dimension "pos" of data->space to "p".
3188 * data->user is assumed to be an isl_multi_pw_aff.
3190 * If the current dimension is an output dimension, then print
3191 * the corresponding piecewise affine expression.
3192 * Otherwise, print the name of the dimension.
3194 static __isl_give isl_printer
*print_dim_mpa(__isl_take isl_printer
*p
,
3195 struct isl_print_space_data
*data
, unsigned pos
)
3200 isl_multi_pw_aff
*mpa
= data
->user
;
3203 if (data
->type
!= isl_dim_out
)
3204 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
3208 return isl_printer_print_str(p
, "(0 : false)");
3210 need_parens
= pa
->n
!= 1 || !isl_set_plain_is_universe(pa
->p
[0].set
);
3212 p
= isl_printer_print_str(p
, "(");
3213 space
= isl_multi_pw_aff_get_domain_space(mpa
);
3214 for (i
= 0; i
< pa
->n
; ++i
) {
3217 p
= isl_printer_print_str(p
, "; ");
3218 p
= print_aff_body(p
, space
, pa
->p
[i
].aff
);
3219 p
= print_disjuncts(pa
->p
[i
].set
, space
, p
, 0);
3221 isl_space_free(space
);
3223 p
= isl_printer_print_str(p
, ")");
3228 /* Print "mpa" to "p" in isl format.
3230 * If "mpa" is zero-dimensional and has a non-trivial explicit domain,
3231 * then it is printed after the tuple of affine expressions.
3233 static __isl_give isl_printer
*print_multi_pw_aff_isl(__isl_take isl_printer
*p
,
3234 __isl_keep isl_multi_pw_aff
*mpa
)
3236 struct isl_print_space_data data
= { 0 };
3237 isl_bool has_domain
;
3240 return isl_printer_free(p
);
3242 p
= print_param_tuple(p
, mpa
->space
, &data
);
3243 p
= isl_printer_print_str(p
, "{ ");
3244 data
.print_dim
= &print_dim_mpa
;
3246 p
= isl_print_space(mpa
->space
, p
, 0, &data
);
3247 has_domain
= isl_multi_pw_aff_has_non_trivial_domain(mpa
);
3249 return isl_printer_free(p
);
3253 space
= isl_space_domain(isl_space_copy(mpa
->space
));
3254 p
= print_disjuncts_set(mpa
->u
.dom
, space
, p
, 0);
3255 isl_space_free(space
);
3257 p
= isl_printer_print_str(p
, " }");
3261 __isl_give isl_printer
*isl_printer_print_multi_pw_aff(
3262 __isl_take isl_printer
*p
, __isl_keep isl_multi_pw_aff
*mpa
)
3265 return isl_printer_free(p
);
3267 if (p
->output_format
== ISL_FORMAT_ISL
)
3268 return print_multi_pw_aff_isl(p
, mpa
);
3269 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3270 return isl_printer_free(p
));
3273 /* Print dimension "pos" of data->space to "p".
3275 * data->user is assumed to be an isl_multi_val.
3277 * If the current dimension is an output dimension, then print
3278 * the corresponding value. Otherwise, print the name of the dimension.
3280 static __isl_give isl_printer
*print_dim_mv(__isl_take isl_printer
*p
,
3281 struct isl_print_space_data
*data
, unsigned pos
)
3283 isl_multi_val
*mv
= data
->user
;
3285 if (data
->type
== isl_dim_out
)
3286 return isl_printer_print_val(p
, mv
->u
.p
[pos
]);
3288 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
3291 /* Print the isl_multi_val "mv" to "p" in isl format.
3293 static __isl_give isl_printer
*print_multi_val_isl(__isl_take isl_printer
*p
,
3294 __isl_keep isl_multi_val
*mv
)
3296 struct isl_print_space_data data
= { 0 };
3299 return isl_printer_free(p
);
3301 p
= print_param_tuple(p
, mv
->space
, &data
);
3302 p
= isl_printer_print_str(p
, "{ ");
3303 data
.print_dim
= &print_dim_mv
;
3305 p
= isl_print_space(mv
->space
, p
, 0, &data
);
3306 p
= isl_printer_print_str(p
, " }");
3310 /* Print the isl_multi_val "mv" to "p".
3312 * Currently only supported in isl format.
3314 __isl_give isl_printer
*isl_printer_print_multi_val(
3315 __isl_take isl_printer
*p
, __isl_keep isl_multi_val
*mv
)
3318 return isl_printer_free(p
);
3320 if (p
->output_format
== ISL_FORMAT_ISL
)
3321 return print_multi_val_isl(p
, mv
);
3322 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3323 return isl_printer_free(p
));
3326 /* Print dimension "pos" of data->space to "p".
3328 * data->user is assumed to be an isl_multi_union_pw_aff.
3330 * The current dimension is necessarily a set dimension, so
3331 * we print the corresponding isl_union_pw_aff, including
3334 static __isl_give isl_printer
*print_union_pw_aff_dim(__isl_take isl_printer
*p
,
3335 struct isl_print_space_data
*data
, unsigned pos
)
3337 isl_multi_union_pw_aff
*mupa
= data
->user
;
3338 isl_union_pw_aff
*upa
;
3340 upa
= isl_multi_union_pw_aff_get_union_pw_aff(mupa
, pos
);
3341 p
= print_union_pw_aff_body(p
, upa
);
3342 isl_union_pw_aff_free(upa
);
3347 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3349 * If "mupa" is zero-dimensional and has a non-trivial explicit domain,
3350 * then it is printed after the tuple of affine expressions.
3351 * In order to clarify that this domain belongs to the expression,
3352 * the tuple along with the domain are placed inside parentheses.
3353 * If "mupa" has any parameters, then the opening parenthesis
3354 * appears after the parameter declarations.
3356 static __isl_give isl_printer
*print_multi_union_pw_aff_isl(
3357 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3359 struct isl_print_space_data data
= { 0 };
3360 isl_bool has_domain
;
3364 return isl_printer_free(p
);
3365 has_domain
= isl_multi_union_pw_aff_has_non_trivial_domain(mupa
);
3367 return isl_printer_free(p
);
3369 space
= isl_multi_union_pw_aff_get_space(mupa
);
3370 p
= print_param_tuple(p
, space
, &data
);
3373 p
= isl_printer_print_str(p
, "(");
3375 data
.print_dim
= &print_union_pw_aff_dim
;
3378 p
= isl_print_space(space
, p
, 0, &data
);
3379 isl_space_free(space
);
3382 p
= isl_printer_print_str(p
, " : ");
3383 p
= isl_printer_print_union_set_isl_body(p
, mupa
->u
.dom
);
3384 p
= isl_printer_print_str(p
, ")");
3390 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3392 * We currently only support an isl format.
3394 __isl_give isl_printer
*isl_printer_print_multi_union_pw_aff(
3395 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3398 return isl_printer_free(p
);
3400 if (p
->output_format
== ISL_FORMAT_ISL
)
3401 return print_multi_union_pw_aff_isl(p
, mupa
);
3402 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
3403 "unsupported output format", return isl_printer_free(p
));