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_map.h>
27 #include <isl/constraint.h>
28 #include <isl_local_space_private.h>
29 #include <isl_aff_private.h>
30 #include <isl_val_private.h>
31 #include <isl_constraint_private.h>
32 #include <isl/ast_build.h>
34 #include <isl_output_private.h>
36 #include <bset_to_bmap.c>
37 #include <set_to_map.c>
38 #include <uset_to_umap.c>
40 static const char *s_to
[2] = { " -> ", " \\to " };
41 static const char *s_and
[2] = { " and ", " \\wedge " };
42 static const char *s_or
[2] = { " or ", " \\vee " };
43 static const char *s_le
[2] = { "<=", "\\le" };
44 static const char *s_ge
[2] = { ">=", "\\ge" };
45 static const char *s_open_set
[2] = { "{ ", "\\{\\, " };
46 static const char *s_close_set
[2] = { " }", " \\,\\}" };
47 static const char *s_open_list
[2] = { "[", "(" };
48 static const char *s_close_list
[2] = { "]", ")" };
49 static const char *s_such_that
[2] = { " : ", " \\mid " };
50 static const char *s_open_exists
[2] = { "exists (", "\\exists \\, " };
51 static const char *s_close_exists
[2] = { ")", "" };
52 static const char *s_div_prefix
[2] = { "e", "\\alpha_" };
53 static const char *s_mod
[2] = { "mod", "\\bmod" };
54 static const char *s_param_prefix
[2] = { "p", "p_" };
55 static const char *s_input_prefix
[2] = { "i", "i_" };
56 static const char *s_output_prefix
[2] = { "o", "o_" };
58 static __isl_give isl_printer
*print_constraint_polylib(
59 struct isl_basic_map
*bmap
, int ineq
, int n
, __isl_take isl_printer
*p
)
62 unsigned n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
63 unsigned n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
64 unsigned nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
65 isl_int
*c
= ineq
? bmap
->ineq
[n
] : bmap
->eq
[n
];
67 p
= isl_printer_start_line(p
);
68 p
= isl_printer_print_int(p
, ineq
);
69 for (i
= 0; i
< n_out
; ++i
) {
70 p
= isl_printer_print_str(p
, " ");
71 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+n_in
+i
]);
73 for (i
= 0; i
< n_in
; ++i
) {
74 p
= isl_printer_print_str(p
, " ");
75 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+i
]);
77 for (i
= 0; i
< bmap
->n_div
; ++i
) {
78 p
= isl_printer_print_str(p
, " ");
79 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+n_in
+n_out
+i
]);
81 for (i
= 0; i
< nparam
; ++i
) {
82 p
= isl_printer_print_str(p
, " ");
83 p
= isl_printer_print_isl_int(p
, c
[1+i
]);
85 p
= isl_printer_print_str(p
, " ");
86 p
= isl_printer_print_isl_int(p
, c
[0]);
87 p
= isl_printer_end_line(p
);
91 static __isl_give isl_printer
*print_constraints_polylib(
92 struct isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
96 p
= isl_printer_set_isl_int_width(p
, 5);
98 for (i
= 0; i
< bmap
->n_eq
; ++i
)
99 p
= print_constraint_polylib(bmap
, 0, i
, p
);
100 for (i
= 0; i
< bmap
->n_ineq
; ++i
)
101 p
= print_constraint_polylib(bmap
, 1, i
, p
);
106 static __isl_give isl_printer
*bset_print_constraints_polylib(
107 struct isl_basic_set
*bset
, __isl_take isl_printer
*p
)
109 return print_constraints_polylib(bset_to_bmap(bset
), p
);
112 static __isl_give isl_printer
*isl_basic_map_print_polylib(
113 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
, int ext
)
115 unsigned total
= isl_basic_map_total_dim(bmap
);
116 p
= isl_printer_start_line(p
);
117 p
= isl_printer_print_int(p
, bmap
->n_eq
+ bmap
->n_ineq
);
118 p
= isl_printer_print_str(p
, " ");
119 p
= isl_printer_print_int(p
, 1 + total
+ 1);
121 p
= isl_printer_print_str(p
, " ");
122 p
= isl_printer_print_int(p
,
123 isl_basic_map_dim(bmap
, isl_dim_out
));
124 p
= isl_printer_print_str(p
, " ");
125 p
= isl_printer_print_int(p
,
126 isl_basic_map_dim(bmap
, isl_dim_in
));
127 p
= isl_printer_print_str(p
, " ");
128 p
= isl_printer_print_int(p
,
129 isl_basic_map_dim(bmap
, isl_dim_div
));
130 p
= isl_printer_print_str(p
, " ");
131 p
= isl_printer_print_int(p
,
132 isl_basic_map_dim(bmap
, isl_dim_param
));
134 p
= isl_printer_end_line(p
);
135 return print_constraints_polylib(bmap
, p
);
138 static __isl_give isl_printer
*isl_basic_set_print_polylib(
139 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
, int ext
)
141 return isl_basic_map_print_polylib(bset_to_bmap(bset
), p
, ext
);
144 static __isl_give isl_printer
*isl_map_print_polylib(__isl_keep isl_map
*map
,
145 __isl_take isl_printer
*p
, int ext
)
149 p
= isl_printer_start_line(p
);
150 p
= isl_printer_print_int(p
, map
->n
);
151 p
= isl_printer_end_line(p
);
152 for (i
= 0; i
< map
->n
; ++i
) {
153 p
= isl_printer_start_line(p
);
154 p
= isl_printer_end_line(p
);
155 p
= isl_basic_map_print_polylib(map
->p
[i
], p
, ext
);
160 static __isl_give isl_printer
*isl_set_print_polylib(__isl_keep isl_set
*set
,
161 __isl_take isl_printer
*p
, int ext
)
163 return isl_map_print_polylib(set_to_map(set
), p
, ext
);
166 static int count_same_name(__isl_keep isl_space
*dim
,
167 enum isl_dim_type type
, unsigned pos
, const char *name
)
173 for (t
= isl_dim_param
; t
<= type
&& t
<= isl_dim_out
; ++t
) {
174 s
= t
== type
? pos
: isl_space_dim(dim
, t
);
175 for (p
= 0; p
< s
; ++p
) {
176 const char *n
= isl_space_get_dim_name(dim
, t
, p
);
177 if (n
&& !strcmp(n
, name
))
184 /* Print the name of the variable of type "type" and position "pos"
187 static __isl_give isl_printer
*print_name(__isl_keep isl_space
*space
,
188 __isl_take isl_printer
*p
, enum isl_dim_type type
, unsigned pos
,
195 name
= type
== isl_dim_div
? NULL
196 : isl_space_get_dim_name(space
, type
, pos
);
200 if (type
== isl_dim_param
)
201 prefix
= s_param_prefix
[latex
];
202 else if (type
== isl_dim_div
)
203 prefix
= s_div_prefix
[latex
];
204 else if (isl_space_is_set(space
) || type
== isl_dim_in
)
205 prefix
= s_input_prefix
[latex
];
207 prefix
= s_output_prefix
[latex
];
208 snprintf(buffer
, sizeof(buffer
), "%s%d", prefix
, pos
);
211 primes
= count_same_name(space
, name
== buffer
? isl_dim_div
: type
,
213 p
= isl_printer_print_str(p
, name
);
215 p
= isl_printer_print_str(p
, "'");
219 static enum isl_dim_type
pos2type(__isl_keep isl_space
*dim
, unsigned *pos
)
221 enum isl_dim_type type
;
222 unsigned n_in
= isl_space_dim(dim
, isl_dim_in
);
223 unsigned n_out
= isl_space_dim(dim
, isl_dim_out
);
224 unsigned nparam
= isl_space_dim(dim
, isl_dim_param
);
226 if (*pos
< 1 + nparam
) {
227 type
= isl_dim_param
;
229 } else if (*pos
< 1 + nparam
+ n_in
) {
232 } else if (*pos
< 1 + nparam
+ n_in
+ n_out
) {
234 *pos
-= 1 + nparam
+ n_in
;
237 *pos
-= 1 + nparam
+ n_in
+ n_out
;
243 /* Can the div expression of the integer division at position "row" of "div"
245 * In particular, are the div expressions available and does the selected
246 * variable have a known explicit representation?
247 * Furthermore, the Omega format does not allow any div expressions
250 static isl_bool
can_print_div_expr(__isl_keep isl_printer
*p
,
251 __isl_keep isl_mat
*div
, int pos
)
253 if (p
->output_format
== ISL_FORMAT_OMEGA
)
254 return isl_bool_false
;
256 return isl_bool_false
;
257 return !isl_int_is_zero(div
->row
[pos
][0]);
260 static __isl_give isl_printer
*print_div(__isl_keep isl_space
*dim
,
261 __isl_keep isl_mat
*div
, int pos
, __isl_take isl_printer
*p
);
263 static __isl_give isl_printer
*print_term(__isl_keep isl_space
*space
,
264 __isl_keep isl_mat
*div
,
265 isl_int c
, unsigned pos
, __isl_take isl_printer
*p
, int latex
)
267 enum isl_dim_type type
;
271 return isl_printer_print_isl_int(p
, c
);
273 type
= pos2type(space
, &pos
);
274 print_div_def
= type
== isl_dim_div
&& can_print_div_expr(p
, div
, pos
);
276 if (isl_int_is_one(c
))
278 else if (isl_int_is_negone(c
))
279 p
= isl_printer_print_str(p
, "-");
281 p
= isl_printer_print_isl_int(p
, c
);
282 if (p
->output_format
== ISL_FORMAT_C
|| print_div_def
)
283 p
= isl_printer_print_str(p
, "*");
286 p
= print_div(space
, div
, pos
, p
);
288 p
= print_name(space
, p
, type
, pos
, latex
);
292 static __isl_give isl_printer
*print_affine_of_len(__isl_keep isl_space
*dim
,
293 __isl_keep isl_mat
*div
,
294 __isl_take isl_printer
*p
, isl_int
*c
, int len
)
299 for (i
= 0, first
= 1; i
< len
; ++i
) {
301 if (isl_int_is_zero(c
[i
]))
304 if (isl_int_is_neg(c
[i
])) {
306 isl_int_neg(c
[i
], c
[i
]);
307 p
= isl_printer_print_str(p
, " - ");
309 p
= isl_printer_print_str(p
, " + ");
312 p
= print_term(dim
, div
, c
[i
], i
, p
, 0);
314 isl_int_neg(c
[i
], c
[i
]);
317 p
= isl_printer_print_str(p
, "0");
321 /* Print an affine expression "c"
322 * to "p", with the variable names taken from "space" and
323 * the integer division definitions taken from "div".
325 static __isl_give isl_printer
*print_affine(__isl_take isl_printer
*p
,
326 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, isl_int
*c
)
332 return isl_printer_free(p
);
333 n_div
= isl_mat_rows(div
);
334 len
= 1 + isl_space_dim(space
, isl_dim_all
) + n_div
;
335 return print_affine_of_len(space
, div
, p
, c
, len
);
338 /* offset is the offset of local_dim inside data->type of data->space.
340 static __isl_give isl_printer
*print_nested_var_list(__isl_take isl_printer
*p
,
341 __isl_keep isl_space
*local_dim
, enum isl_dim_type local_type
,
342 struct isl_print_space_data
*data
, int offset
)
346 if (data
->space
!= local_dim
&& local_type
== isl_dim_out
)
347 offset
+= local_dim
->n_in
;
349 for (i
= 0; i
< isl_space_dim(local_dim
, local_type
); ++i
) {
351 p
= isl_printer_print_str(p
, ", ");
353 p
= data
->print_dim(p
, data
, offset
+ i
);
355 p
= print_name(data
->space
, p
, data
->type
, offset
+ i
,
361 static __isl_give isl_printer
*print_var_list(__isl_take isl_printer
*p
,
362 __isl_keep isl_space
*space
, enum isl_dim_type type
)
364 struct isl_print_space_data data
= { .space
= space
, .type
= type
};
366 return print_nested_var_list(p
, space
, type
, &data
, 0);
369 static __isl_give isl_printer
*print_nested_map_dim(__isl_take isl_printer
*p
,
370 __isl_keep isl_space
*local_dim
,
371 struct isl_print_space_data
*data
, int offset
);
373 static __isl_give isl_printer
*print_nested_tuple(__isl_take isl_printer
*p
,
374 __isl_keep isl_space
*local_dim
, enum isl_dim_type local_type
,
375 struct isl_print_space_data
*data
, int offset
)
377 const char *name
= NULL
;
378 unsigned n
= isl_space_dim(local_dim
, local_type
);
379 if ((local_type
== isl_dim_in
|| local_type
== isl_dim_out
)) {
380 name
= isl_space_get_tuple_name(local_dim
, local_type
);
383 p
= isl_printer_print_str(p
, "\\mathrm{");
384 p
= isl_printer_print_str(p
, name
);
386 p
= isl_printer_print_str(p
, "}");
389 if (!data
->latex
|| n
!= 1 || name
)
390 p
= isl_printer_print_str(p
, s_open_list
[data
->latex
]);
391 if ((local_type
== isl_dim_in
|| local_type
== isl_dim_out
) &&
392 local_dim
->nested
[local_type
- isl_dim_in
]) {
393 if (data
->space
!= local_dim
&& local_type
== isl_dim_out
)
394 offset
+= local_dim
->n_in
;
395 p
= print_nested_map_dim(p
,
396 local_dim
->nested
[local_type
- isl_dim_in
],
399 p
= print_nested_var_list(p
, local_dim
, local_type
, data
,
401 if (!data
->latex
|| n
!= 1 || name
)
402 p
= isl_printer_print_str(p
, s_close_list
[data
->latex
]);
406 static __isl_give isl_printer
*print_tuple(__isl_keep isl_space
*dim
,
407 __isl_take isl_printer
*p
, enum isl_dim_type type
,
408 struct isl_print_space_data
*data
)
412 return print_nested_tuple(p
, dim
, type
, data
, 0);
415 static __isl_give isl_printer
*print_nested_map_dim(__isl_take isl_printer
*p
,
416 __isl_keep isl_space
*local_dim
,
417 struct isl_print_space_data
*data
, int offset
)
419 p
= print_nested_tuple(p
, local_dim
, isl_dim_in
, data
, offset
);
420 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
421 p
= print_nested_tuple(p
, local_dim
, isl_dim_out
, data
, offset
);
426 __isl_give isl_printer
*isl_print_space(__isl_keep isl_space
*space
,
427 __isl_take isl_printer
*p
, int rational
,
428 struct isl_print_space_data
*data
)
430 if (rational
&& !data
->latex
)
431 p
= isl_printer_print_str(p
, "rat: ");
432 if (isl_space_is_params(space
))
434 else if (isl_space_is_set(space
))
435 p
= print_tuple(space
, p
, isl_dim_set
, data
);
437 p
= print_tuple(space
, p
, isl_dim_in
, data
);
438 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
439 p
= print_tuple(space
, p
, isl_dim_out
, data
);
445 static __isl_give isl_printer
*print_omega_parameters(__isl_keep isl_space
*dim
,
446 __isl_take isl_printer
*p
)
448 if (isl_space_dim(dim
, isl_dim_param
) == 0)
451 p
= isl_printer_start_line(p
);
452 p
= isl_printer_print_str(p
, "symbolic ");
453 p
= print_var_list(p
, dim
, isl_dim_param
);
454 p
= isl_printer_print_str(p
, ";");
455 p
= isl_printer_end_line(p
);
459 /* Does the inequality constraint following "i" in "bmap"
460 * have an opposite value for the same last coefficient?
461 * "last" is the position of the last coefficient of inequality "i".
462 * If the next constraint is a div constraint, then it is ignored
463 * since div constraints are not printed.
465 static int next_is_opposite(__isl_keep isl_basic_map
*bmap
, int i
, int last
)
467 unsigned total
= isl_basic_map_total_dim(bmap
);
468 unsigned o_div
= isl_basic_map_offset(bmap
, isl_dim_div
);
470 if (i
+ 1 >= bmap
->n_ineq
)
472 if (isl_seq_last_non_zero(bmap
->ineq
[i
+ 1], 1 + total
) != last
)
476 is_div
= isl_basic_map_is_div_constraint(bmap
,
477 bmap
->ineq
[i
+ 1], last
- o_div
);
483 return isl_int_abs_eq(bmap
->ineq
[i
][last
], bmap
->ineq
[i
+ 1][last
]) &&
484 !isl_int_eq(bmap
->ineq
[i
][last
], bmap
->ineq
[i
+ 1][last
]);
487 /* Return a string representation of the operator used when
488 * printing a constraint where the LHS is greater than or equal to the LHS
489 * (sign > 0) or smaller than or equal to the LHS (sign < 0).
490 * If "strict" is set, then return the strict version of the comparison
493 static const char *constraint_op(int sign
, int strict
, int latex
)
496 return sign
< 0 ? "<" : ">";
503 /* Print one side of a constraint "c" to "p", with
504 * the variable names taken from "space" and the integer division definitions
506 * "last" is the position of the last non-zero coefficient.
507 * Let c' be the result of zeroing out this coefficient, then
508 * the partial constraint
514 static __isl_give isl_printer
*print_half_constraint(__isl_take isl_printer
*p
,
515 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
516 isl_int
*c
, int last
, const char *op
, int latex
)
518 isl_int_set_si(c
[last
], 0);
519 p
= print_affine(p
, space
, div
, c
);
521 p
= isl_printer_print_str(p
, " ");
522 p
= isl_printer_print_str(p
, op
);
523 p
= isl_printer_print_str(p
, " ");
528 /* Print a constraint "c" to "p", with the variable names
529 * taken from "space" and the integer division definitions taken from "div".
530 * "last" is the position of the last non-zero coefficient, which is
531 * moreover assumed to be negative.
532 * Let c' be the result of zeroing out this coefficient, then
533 * the constraint is printed in the form
537 static __isl_give isl_printer
*print_constraint(__isl_take isl_printer
*p
,
538 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
539 isl_int
*c
, int last
, const char *op
, int latex
)
541 isl_int_abs(c
[last
], c
[last
]);
543 p
= print_term(space
, div
, c
[last
], last
, p
, latex
);
545 p
= isl_printer_print_str(p
, " ");
546 p
= isl_printer_print_str(p
, op
);
547 p
= isl_printer_print_str(p
, " ");
549 isl_int_set_si(c
[last
], 0);
550 p
= print_affine(p
, space
, div
, c
);
555 /* Given an integer division
559 * at position "pos" in "div", print the corresponding modulo expression
563 * to "p". The variable names are taken from "space", while any
564 * nested integer division definitions are taken from "div".
566 static __isl_give isl_printer
*print_mod(__isl_take isl_printer
*p
,
567 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int pos
,
571 return isl_printer_free(p
);
573 p
= isl_printer_print_str(p
, "(");
574 p
= print_affine_of_len(space
, div
, p
,
575 div
->row
[pos
] + 1, div
->n_col
- 1);
576 p
= isl_printer_print_str(p
, ") ");
577 p
= isl_printer_print_str(p
, s_mod
[latex
]);
578 p
= isl_printer_print_str(p
, " ");
579 p
= isl_printer_print_isl_int(p
, div
->row
[pos
][0]);
583 /* Can the equality constraints "c" be printed as a modulo constraint?
584 * In particular, is of the form
586 * f - a m floor(g/m) = 0,
588 * with c = -a m the coefficient at position "pos"?
589 * Return the position of the corresponding integer division if so.
590 * Return the number of integer divisions if not.
591 * Return -1 on error.
593 * Modulo constraints are currently not printed in C format.
594 * Other than that, "pos" needs to correspond to an integer division
595 * with explicit representation and "c" needs to be a multiple
596 * of the denominator of the integer division.
598 static int print_as_modulo_pos(__isl_keep isl_printer
*p
,
599 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, unsigned pos
,
604 enum isl_dim_type type
;
608 n_div
= isl_mat_rows(div
);
609 if (p
->output_format
== ISL_FORMAT_C
)
611 type
= pos2type(space
, &pos
);
612 if (type
!= isl_dim_div
)
614 can_print
= can_print_div_expr(p
, div
, pos
);
619 if (!isl_int_is_divisible_by(c
, div
->row
[pos
][0]))
624 /* Print equality constraint "c" to "p" as a modulo constraint,
625 * with the variable names taken from "space" and
626 * the integer division definitions taken from "div".
627 * "last" is the position of the last non-zero coefficient, which is
628 * moreover assumed to be negative and a multiple of the denominator
629 * of the corresponding integer division. "div_pos" is the corresponding
630 * position in the sequence of integer divisions.
632 * The equality is of the form
634 * f - a m floor(g/m) = 0.
638 * a (g mod m) = -f + a g
640 static __isl_give isl_printer
*print_eq_mod_constraint(
641 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
,
642 __isl_keep isl_mat
*div
, unsigned div_pos
,
643 isl_int
*c
, int last
, int latex
)
648 ctx
= isl_printer_get_ctx(p
);
649 isl_int_divexact(c
[last
], c
[last
], div
->row
[div_pos
][0]);
650 isl_int_abs(c
[last
], c
[last
]);
651 multiple
= !isl_int_is_one(c
[last
]);
653 p
= isl_printer_print_isl_int(p
, c
[last
]);
654 p
= isl_printer_print_str(p
, "*(");
656 p
= print_mod(p
, space
, div
, div_pos
, latex
);
658 p
= isl_printer_print_str(p
, ")");
659 p
= isl_printer_print_str(p
, " = ");
660 isl_seq_combine(c
, ctx
->negone
, c
,
661 c
[last
], div
->row
[div_pos
] + 1, last
);
662 isl_int_set_si(c
[last
], 0);
663 p
= print_affine(p
, space
, div
, c
);
667 /* Print equality constraint "c" to "p", with the variable names
668 * taken from "space" and the integer division definitions taken from "div".
669 * "last" is the position of the last non-zero coefficient, which is
670 * moreover assumed to be negative.
672 * If possible, print the equality constraint as a modulo constraint.
674 static __isl_give isl_printer
*print_eq_constraint(__isl_take isl_printer
*p
,
675 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, isl_int
*c
,
681 n_div
= isl_mat_rows(div
);
682 div_pos
= print_as_modulo_pos(p
, space
, div
, last
, c
[last
]);
684 return isl_printer_free(p
);
686 return print_eq_mod_constraint(p
, space
, div
, div_pos
,
688 return print_constraint(p
, space
, div
, c
, last
, "=", latex
);
691 /* Print the constraints of "bmap" to "p".
692 * The names of the variables are taken from "space" and
693 * the integer division definitions are taken from "div".
694 * Div constraints are only printed in "dump" mode.
695 * The constraints are sorted prior to printing (except in "dump" mode).
697 * If x is the last variable with a non-zero coefficient,
706 * while an upper bound
714 * If the next constraint has an opposite sign for the same last coefficient,
715 * then it is printed as
723 * instead. In fact, the "a x" part is not printed explicitly, but
724 * reused from the next constraint, which is therefore treated as
725 * a first constraint in the conjunction.
727 * If the constant term of "f" is -1, then "f" is replaced by "f + 1" and
728 * the comparison operator is replaced by the strict variant.
729 * Essentially, ">= 1" is replaced by "> 0".
731 static __isl_give isl_printer
*print_constraints(__isl_keep isl_basic_map
*bmap
,
732 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
733 __isl_take isl_printer
*p
, int latex
)
737 int rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
738 unsigned total
= isl_basic_map_total_dim(bmap
);
739 unsigned o_div
= isl_basic_map_offset(bmap
, isl_dim_div
);
745 bmap
= isl_basic_map_copy(bmap
);
748 bmap
= isl_basic_map_sort_constraints(bmap
);
752 c
= isl_vec_alloc(bmap
->ctx
, 1 + total
);
756 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
757 int l
= isl_seq_last_non_zero(bmap
->eq
[i
], 1 + total
);
759 if (i
!= bmap
->n_eq
- 1)
760 p
= isl_printer_print_str(p
, s_and
[latex
]);
761 p
= isl_printer_print_str(p
, "0 = 0");
765 p
= isl_printer_print_str(p
, s_and
[latex
]);
766 if (isl_int_is_neg(bmap
->eq
[i
][l
]))
767 isl_seq_cpy(c
->el
, bmap
->eq
[i
], 1 + total
);
769 isl_seq_neg(c
->el
, bmap
->eq
[i
], 1 + total
);
770 p
= print_eq_constraint(p
, space
, div
, c
->el
, l
, latex
);
773 for (i
= 0; i
< bmap
->n_ineq
; ++i
) {
774 int l
= isl_seq_last_non_zero(bmap
->ineq
[i
], 1 + total
);
780 if (!dump
&& l
>= o_div
&&
781 can_print_div_expr(p
, div
, l
- o_div
)) {
783 is_div
= isl_basic_map_is_div_constraint(bmap
,
784 bmap
->ineq
[i
], l
- o_div
);
791 p
= isl_printer_print_str(p
, s_and
[latex
]);
792 s
= isl_int_sgn(bmap
->ineq
[i
][l
]);
793 strict
= !rational
&& isl_int_is_negone(bmap
->ineq
[i
][0]);
795 isl_seq_cpy(c
->el
, bmap
->ineq
[i
], 1 + total
);
797 isl_seq_neg(c
->el
, bmap
->ineq
[i
], 1 + total
);
799 isl_int_set_si(c
->el
[0], 0);
800 if (!dump
&& next_is_opposite(bmap
, i
, l
)) {
801 op
= constraint_op(-s
, strict
, latex
);
802 p
= print_half_constraint(p
, space
, div
, c
->el
, l
,
806 op
= constraint_op(s
, strict
, latex
);
807 p
= print_constraint(p
, space
, div
, c
->el
, l
,
813 isl_basic_map_free(bmap
);
818 isl_basic_map_free(bmap
);
824 static __isl_give isl_printer
*print_div(__isl_keep isl_space
*dim
,
825 __isl_keep isl_mat
*div
, int pos
, __isl_take isl_printer
*p
)
830 return isl_printer_free(p
);
832 c
= p
->output_format
== ISL_FORMAT_C
;
833 p
= isl_printer_print_str(p
, c
? "floord(" : "floor((");
834 p
= print_affine_of_len(dim
, div
, p
,
835 div
->row
[pos
] + 1, div
->n_col
- 1);
836 p
= isl_printer_print_str(p
, c
? ", " : ")/");
837 p
= isl_printer_print_isl_int(p
, div
->row
[pos
][0]);
838 p
= isl_printer_print_str(p
, ")");
842 /* Print a comma separated list of div names, except those that have
843 * a definition that can be printed.
844 * If "print_defined_divs" is set, then those div names are printed
845 * as well, along with their definitions.
847 static __isl_give isl_printer
*print_div_list(__isl_take isl_printer
*p
,
848 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int latex
,
849 int print_defined_divs
)
855 if (!p
|| !space
|| !div
)
856 return isl_printer_free(p
);
858 n_div
= isl_mat_rows(div
);
860 for (i
= 0; i
< n_div
; ++i
) {
861 if (!print_defined_divs
&& can_print_div_expr(p
, div
, i
))
864 p
= isl_printer_print_str(p
, ", ");
865 p
= print_name(space
, p
, isl_dim_div
, i
, latex
);
867 if (!can_print_div_expr(p
, div
, i
))
869 p
= isl_printer_print_str(p
, " = ");
870 p
= print_div(space
, div
, i
, p
);
876 /* Does printing an object with local variables described by "div"
877 * require an "exists" clause?
878 * That is, are there any local variables without an explicit representation?
879 * An exists clause is also needed in "dump" mode because
880 * explicit div representations are not printed inline in that case.
882 static isl_bool
need_exists(__isl_keep isl_printer
*p
, __isl_keep isl_mat
*div
)
887 return isl_bool_error
;
888 n
= isl_mat_rows(div
);
890 return isl_bool_false
;
892 return isl_bool_true
;
893 for (i
= 0; i
< n
; ++i
)
894 if (!can_print_div_expr(p
, div
, i
))
895 return isl_bool_true
;
896 return isl_bool_false
;
899 /* Print the start of an exists clause, i.e.,
903 * In dump mode, local variables with an explicit definition are printed
904 * as well because they will not be printed inline.
906 static __isl_give isl_printer
*open_exists(__isl_take isl_printer
*p
,
907 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int latex
)
915 p
= isl_printer_print_str(p
, s_open_exists
[latex
]);
916 p
= print_div_list(p
, space
, div
, latex
, dump
);
917 p
= isl_printer_print_str(p
, ": ");
922 /* Remove the explicit representations of all local variables in "div".
924 static __isl_give isl_mat
*mark_all_unknown(__isl_take isl_mat
*div
)
931 n_div
= isl_mat_rows(div
);
932 for (i
= 0; i
< n_div
; ++i
)
933 div
= isl_mat_set_element_si(div
, i
, 0, 0);
937 /* Print the constraints of "bmap" to "p".
938 * The names of the variables are taken from "space".
939 * "latex" is set if the constraints should be printed in LaTeX format.
940 * Do not print inline explicit div representations in "dump" mode.
942 static __isl_give isl_printer
*print_disjunct(__isl_keep isl_basic_map
*bmap
,
943 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
952 div
= isl_basic_map_get_divs(bmap
);
953 exists
= need_exists(p
, div
);
954 if (exists
>= 0 && exists
)
955 p
= open_exists(p
, space
, div
, latex
);
958 div
= mark_all_unknown(div
);
959 p
= print_constraints(bmap
, space
, div
, p
, latex
);
962 if (exists
>= 0 && exists
)
963 p
= isl_printer_print_str(p
, s_close_exists
[latex
]);
967 /* Print a colon followed by the constraints of "bmap"
968 * to "p", provided there are any constraints.
969 * The names of the variables are taken from "space".
970 * "latex" is set if the constraints should be printed in LaTeX format.
972 static __isl_give isl_printer
*print_optional_disjunct(
973 __isl_keep isl_basic_map
*bmap
, __isl_keep isl_space
*space
,
974 __isl_take isl_printer
*p
, int latex
)
976 if (isl_basic_map_plain_is_universe(bmap
))
979 p
= isl_printer_print_str(p
, ": ");
980 p
= print_disjunct(bmap
, space
, p
, latex
);
985 static __isl_give isl_printer
*basic_map_print_omega(
986 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
988 p
= isl_printer_print_str(p
, "{ [");
989 p
= print_var_list(p
, bmap
->dim
, isl_dim_in
);
990 p
= isl_printer_print_str(p
, "] -> [");
991 p
= print_var_list(p
, bmap
->dim
, isl_dim_out
);
992 p
= isl_printer_print_str(p
, "] ");
993 p
= print_optional_disjunct(bmap
, bmap
->dim
, p
, 0);
994 p
= isl_printer_print_str(p
, " }");
998 static __isl_give isl_printer
*basic_set_print_omega(
999 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
)
1001 p
= isl_printer_print_str(p
, "{ [");
1002 p
= print_var_list(p
, bset
->dim
, isl_dim_set
);
1003 p
= isl_printer_print_str(p
, "] ");
1004 p
= print_optional_disjunct(bset
, bset
->dim
, p
, 0);
1005 p
= isl_printer_print_str(p
, " }");
1009 static __isl_give isl_printer
*isl_map_print_omega(__isl_keep isl_map
*map
,
1010 __isl_take isl_printer
*p
)
1014 for (i
= 0; i
< map
->n
; ++i
) {
1016 p
= isl_printer_print_str(p
, " union ");
1017 p
= basic_map_print_omega(map
->p
[i
], p
);
1022 static __isl_give isl_printer
*isl_set_print_omega(__isl_keep isl_set
*set
,
1023 __isl_take isl_printer
*p
)
1027 for (i
= 0; i
< set
->n
; ++i
) {
1029 p
= isl_printer_print_str(p
, " union ");
1030 p
= basic_set_print_omega(set
->p
[i
], p
);
1035 /* Print the list of parameters in "space", followed by an arrow, to "p",
1036 * if there are any parameters.
1038 static __isl_give isl_printer
*print_param_tuple(__isl_take isl_printer
*p
,
1039 __isl_keep isl_space
*space
, struct isl_print_space_data
*data
)
1042 return isl_printer_free(p
);
1043 if (isl_space_dim(space
, isl_dim_param
) == 0)
1046 p
= print_tuple(space
, p
, isl_dim_param
, data
);
1047 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
1052 static __isl_give isl_printer
*isl_basic_map_print_isl(
1053 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
,
1056 struct isl_print_space_data data
= { .latex
= latex
};
1057 int rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
1059 p
= print_param_tuple(p
, bmap
->dim
, &data
);
1060 p
= isl_printer_print_str(p
, "{ ");
1061 p
= isl_print_space(bmap
->dim
, p
, rational
, &data
);
1062 p
= isl_printer_print_str(p
, " : ");
1063 p
= print_disjunct(bmap
, bmap
->dim
, p
, latex
);
1064 p
= isl_printer_print_str(p
, " }");
1068 /* Print the disjuncts of a map (or set) "map" to "p".
1069 * The names of the variables are taken from "space".
1070 * "latex" is set if the constraints should be printed in LaTeX format.
1072 static __isl_give isl_printer
*print_disjuncts_core(__isl_keep isl_map
*map
,
1073 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
1078 p
= isl_printer_print_str(p
, "false");
1079 for (i
= 0; i
< map
->n
; ++i
) {
1081 p
= isl_printer_print_str(p
, s_or
[latex
]);
1082 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
1083 p
= isl_printer_print_str(p
, "(");
1084 p
= print_disjunct(map
->p
[i
], space
, p
, latex
);
1085 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
1086 p
= isl_printer_print_str(p
, ")");
1091 /* Print the disjuncts of a map (or set) "map" to "p".
1092 * The names of the variables are taken from "space".
1093 * "hull" describes constraints shared by all disjuncts of "map".
1094 * "latex" is set if the constraints should be printed in LaTeX format.
1096 * Print the disjuncts as a conjunction of "hull" and
1097 * the result of removing the constraints of "hull" from "map".
1098 * If this result turns out to be the universe, then simply print "hull".
1100 static __isl_give isl_printer
*print_disjuncts_in_hull(__isl_keep isl_map
*map
,
1101 __isl_keep isl_space
*space
, __isl_take isl_basic_map
*hull
,
1102 __isl_take isl_printer
*p
, int latex
)
1104 isl_bool is_universe
;
1106 p
= print_disjunct(hull
, space
, p
, latex
);
1107 map
= isl_map_plain_gist_basic_map(isl_map_copy(map
), hull
);
1108 is_universe
= isl_map_plain_is_universe(map
);
1109 if (is_universe
< 0)
1112 p
= isl_printer_print_str(p
, s_and
[latex
]);
1113 p
= isl_printer_print_str(p
, "(");
1114 p
= print_disjuncts_core(map
, space
, p
, latex
);
1115 p
= isl_printer_print_str(p
, ")");
1122 isl_printer_free(p
);
1126 /* Print the disjuncts of a map (or set) "map" to "p".
1127 * The names of the variables are taken from "space".
1128 * "latex" is set if the constraints should be printed in LaTeX format.
1130 * If there are at least two disjuncts and "dump" mode is not turned out,
1131 * check for any shared constraints among all disjuncts.
1132 * If there are any, then print them separately in print_disjuncts_in_hull.
1134 static __isl_give isl_printer
*print_disjuncts(__isl_keep isl_map
*map
,
1135 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
1137 if (isl_map_plain_is_universe(map
))
1140 p
= isl_printer_print_str(p
, s_such_that
[latex
]);
1144 if (!p
->dump
&& map
->n
>= 2) {
1145 isl_basic_map
*hull
;
1146 isl_bool is_universe
;
1148 hull
= isl_map_plain_unshifted_simple_hull(isl_map_copy(map
));
1149 is_universe
= isl_basic_map_plain_is_universe(hull
);
1150 if (is_universe
< 0)
1151 p
= isl_printer_free(p
);
1152 else if (!is_universe
)
1153 return print_disjuncts_in_hull(map
, space
, hull
,
1155 isl_basic_map_free(hull
);
1158 return print_disjuncts_core(map
, space
, p
, latex
);
1161 /* Print the disjuncts of a map (or set).
1162 * The names of the variables are taken from "space".
1163 * "latex" is set if the constraints should be printed in LaTeX format.
1165 * If the map turns out to be a universal parameter domain, then
1166 * we need to print the colon. Otherwise, the output looks identical
1169 static __isl_give isl_printer
*print_disjuncts_map(__isl_keep isl_map
*map
,
1170 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
1172 if (isl_map_plain_is_universe(map
) && isl_space_is_params(map
->dim
))
1173 return isl_printer_print_str(p
, s_such_that
[latex
]);
1175 return print_disjuncts(map
, space
, p
, latex
);
1178 struct isl_aff_split
{
1183 static void free_split(__isl_take
struct isl_aff_split
*split
, int n
)
1190 for (i
= 0; i
< n
; ++i
) {
1191 isl_basic_map_free(split
[i
].aff
);
1192 isl_map_free(split
[i
].map
);
1198 static __isl_give isl_basic_map
*get_aff(__isl_take isl_basic_map
*bmap
)
1201 unsigned nparam
, n_in
, n_out
, total
;
1203 bmap
= isl_basic_map_cow(bmap
);
1206 if (isl_basic_map_free_inequality(bmap
, bmap
->n_ineq
) < 0)
1209 nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
1210 n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
1211 n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
1212 total
= isl_basic_map_dim(bmap
, isl_dim_all
);
1213 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1214 j
= isl_seq_last_non_zero(bmap
->eq
[i
] + 1, total
);
1215 if (j
>= nparam
&& j
< nparam
+ n_in
+ n_out
&&
1216 (isl_int_is_one(bmap
->eq
[i
][1 + j
]) ||
1217 isl_int_is_negone(bmap
->eq
[i
][1 + j
])))
1219 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1223 bmap
= isl_basic_map_finalize(bmap
);
1227 isl_basic_map_free(bmap
);
1231 static int aff_split_cmp(const void *p1
, const void *p2
, void *user
)
1233 const struct isl_aff_split
*s1
, *s2
;
1234 s1
= (const struct isl_aff_split
*) p1
;
1235 s2
= (const struct isl_aff_split
*) p2
;
1237 return isl_basic_map_plain_cmp(s1
->aff
, s2
->aff
);
1240 static __isl_give isl_basic_map
*drop_aff(__isl_take isl_basic_map
*bmap
,
1241 __isl_keep isl_basic_map
*aff
)
1249 total
= isl_space_dim(bmap
->dim
, isl_dim_all
);
1251 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1252 if (isl_seq_first_non_zero(bmap
->eq
[i
] + 1 + total
,
1255 for (j
= 0; j
< aff
->n_eq
; ++j
) {
1256 if (!isl_seq_eq(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
) &&
1257 !isl_seq_is_neg(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
))
1259 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1267 isl_basic_map_free(bmap
);
1271 static __isl_give
struct isl_aff_split
*split_aff(__isl_keep isl_map
*map
)
1274 struct isl_aff_split
*split
;
1277 ctx
= isl_map_get_ctx(map
);
1278 split
= isl_calloc_array(ctx
, struct isl_aff_split
, map
->n
);
1282 for (i
= 0; i
< map
->n
; ++i
) {
1283 isl_basic_map
*bmap
;
1284 split
[i
].aff
= get_aff(isl_basic_map_copy(map
->p
[i
]));
1285 bmap
= isl_basic_map_copy(map
->p
[i
]);
1286 bmap
= isl_basic_map_cow(bmap
);
1287 bmap
= drop_aff(bmap
, split
[i
].aff
);
1288 split
[i
].map
= isl_map_from_basic_map(bmap
);
1289 if (!split
[i
].aff
|| !split
[i
].map
)
1293 if (isl_sort(split
, map
->n
, sizeof(struct isl_aff_split
),
1294 &aff_split_cmp
, NULL
) < 0)
1298 for (i
= n
- 1; i
>= 1; --i
) {
1299 if (!isl_basic_map_plain_is_equal(split
[i
- 1].aff
,
1302 isl_basic_map_free(split
[i
].aff
);
1303 split
[i
- 1].map
= isl_map_union(split
[i
- 1].map
,
1306 split
[i
] = split
[n
- 1];
1307 split
[n
- 1].aff
= NULL
;
1308 split
[n
- 1].map
= NULL
;
1314 free_split(split
, map
->n
);
1318 static int defining_equality(__isl_keep isl_basic_map
*eq
,
1319 __isl_keep isl_space
*dim
, enum isl_dim_type type
, int pos
)
1327 pos
+= isl_space_offset(dim
, type
);
1328 total
= isl_basic_map_total_dim(eq
);
1330 for (i
= 0; i
< eq
->n_eq
; ++i
) {
1331 if (isl_seq_last_non_zero(eq
->eq
[i
] + 1, total
) != pos
)
1333 if (isl_int_is_one(eq
->eq
[i
][1 + pos
]))
1334 isl_seq_neg(eq
->eq
[i
], eq
->eq
[i
], 1 + total
);
1341 /* Print dimension "pos" of data->space to "p".
1343 * data->user is assumed to be an isl_basic_map keeping track of equalities.
1345 * If the current dimension is defined by these equalities, then print
1346 * the corresponding expression, assigned to the name of the dimension
1347 * if there is any. Otherwise, print the name of the dimension.
1349 static __isl_give isl_printer
*print_dim_eq(__isl_take isl_printer
*p
,
1350 struct isl_print_space_data
*data
, unsigned pos
)
1352 isl_basic_map
*eq
= data
->user
;
1355 j
= defining_equality(eq
, data
->space
, data
->type
, pos
);
1357 if (isl_space_has_dim_name(data
->space
, data
->type
, pos
)) {
1358 p
= print_name(data
->space
, p
, data
->type
, pos
,
1360 p
= isl_printer_print_str(p
, " = ");
1362 pos
+= 1 + isl_space_offset(data
->space
, data
->type
);
1363 p
= print_affine_of_len(data
->space
, NULL
, p
, eq
->eq
[j
], pos
);
1365 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
1371 static __isl_give isl_printer
*print_split_map(__isl_take isl_printer
*p
,
1372 struct isl_aff_split
*split
, int n
, __isl_keep isl_space
*space
)
1374 struct isl_print_space_data data
= { 0 };
1378 data
.print_dim
= &print_dim_eq
;
1379 for (i
= 0; i
< n
; ++i
) {
1382 rational
= split
[i
].map
->n
> 0 &&
1383 ISL_F_ISSET(split
[i
].map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1385 p
= isl_printer_print_str(p
, "; ");
1386 data
.user
= split
[i
].aff
;
1387 p
= isl_print_space(space
, p
, rational
, &data
);
1388 p
= print_disjuncts_map(split
[i
].map
, space
, p
, 0);
1394 static __isl_give isl_printer
*isl_map_print_isl_body(__isl_keep isl_map
*map
,
1395 __isl_take isl_printer
*p
)
1397 struct isl_print_space_data data
= { 0 };
1398 struct isl_aff_split
*split
= NULL
;
1402 return isl_printer_free(p
);
1403 if (!p
->dump
&& map
->n
> 0)
1404 split
= split_aff(map
);
1406 p
= print_split_map(p
, split
, map
->n
, map
->dim
);
1408 rational
= map
->n
> 0 &&
1409 ISL_F_ISSET(map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1410 p
= isl_print_space(map
->dim
, p
, rational
, &data
);
1411 p
= print_disjuncts_map(map
, map
->dim
, p
, 0);
1413 free_split(split
, map
->n
);
1417 static __isl_give isl_printer
*isl_map_print_isl(__isl_keep isl_map
*map
,
1418 __isl_take isl_printer
*p
)
1420 struct isl_print_space_data data
= { 0 };
1422 p
= print_param_tuple(p
, map
->dim
, &data
);
1423 p
= isl_printer_print_str(p
, s_open_set
[0]);
1424 p
= isl_map_print_isl_body(map
, p
);
1425 p
= isl_printer_print_str(p
, s_close_set
[0]);
1429 static __isl_give isl_printer
*print_latex_map(__isl_keep isl_map
*map
,
1430 __isl_take isl_printer
*p
, __isl_keep isl_basic_map
*aff
)
1432 struct isl_print_space_data data
= { 0 };
1435 p
= print_param_tuple(p
, map
->dim
, &data
);
1436 p
= isl_printer_print_str(p
, s_open_set
[1]);
1437 data
.print_dim
= &print_dim_eq
;
1439 p
= isl_print_space(map
->dim
, p
, 0, &data
);
1440 p
= print_disjuncts_map(map
, map
->dim
, p
, 1);
1441 p
= isl_printer_print_str(p
, s_close_set
[1]);
1446 static __isl_give isl_printer
*isl_map_print_latex(__isl_keep isl_map
*map
,
1447 __isl_take isl_printer
*p
)
1450 struct isl_aff_split
*split
= NULL
;
1453 split
= split_aff(map
);
1456 return print_latex_map(map
, p
, NULL
);
1458 for (i
= 0; i
< map
->n
; ++i
) {
1462 p
= isl_printer_print_str(p
, " \\cup ");
1463 p
= print_latex_map(split
[i
].map
, p
, split
[i
].aff
);
1466 free_split(split
, map
->n
);
1470 __isl_give isl_printer
*isl_printer_print_basic_map(__isl_take isl_printer
*p
,
1471 __isl_keep isl_basic_map
*bmap
)
1475 if (p
->output_format
== ISL_FORMAT_ISL
)
1476 return isl_basic_map_print_isl(bmap
, p
, 0);
1477 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1478 return basic_map_print_omega(bmap
, p
);
1479 isl_assert(bmap
->ctx
, 0, goto error
);
1481 isl_printer_free(p
);
1485 __isl_give isl_printer
*isl_printer_print_basic_set(__isl_take isl_printer
*p
,
1486 __isl_keep isl_basic_set
*bset
)
1491 if (p
->output_format
== ISL_FORMAT_ISL
)
1492 return isl_basic_map_print_isl(bset
, p
, 0);
1493 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1494 return isl_basic_set_print_polylib(bset
, p
, 0);
1495 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1496 return isl_basic_set_print_polylib(bset
, p
, 1);
1497 else if (p
->output_format
== ISL_FORMAT_POLYLIB_CONSTRAINTS
)
1498 return bset_print_constraints_polylib(bset
, p
);
1499 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1500 return basic_set_print_omega(bset
, p
);
1501 isl_assert(p
->ctx
, 0, goto error
);
1503 isl_printer_free(p
);
1507 __isl_give isl_printer
*isl_printer_print_set(__isl_take isl_printer
*p
,
1508 __isl_keep isl_set
*set
)
1512 if (p
->output_format
== ISL_FORMAT_ISL
)
1513 return isl_map_print_isl(set_to_map(set
), p
);
1514 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1515 return isl_set_print_polylib(set
, p
, 0);
1516 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1517 return isl_set_print_polylib(set
, p
, 1);
1518 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1519 return isl_set_print_omega(set
, p
);
1520 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1521 return isl_map_print_latex(set_to_map(set
), p
);
1522 isl_assert(set
->ctx
, 0, goto error
);
1524 isl_printer_free(p
);
1528 __isl_give isl_printer
*isl_printer_print_map(__isl_take isl_printer
*p
,
1529 __isl_keep isl_map
*map
)
1534 if (p
->output_format
== ISL_FORMAT_ISL
)
1535 return isl_map_print_isl(map
, p
);
1536 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1537 return isl_map_print_polylib(map
, p
, 0);
1538 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1539 return isl_map_print_polylib(map
, p
, 1);
1540 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1541 return isl_map_print_omega(map
, p
);
1542 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1543 return isl_map_print_latex(map
, p
);
1544 isl_assert(map
->ctx
, 0, goto error
);
1546 isl_printer_free(p
);
1550 struct isl_union_print_data
{
1555 static isl_stat
print_map_body(__isl_take isl_map
*map
, void *user
)
1557 struct isl_union_print_data
*data
;
1558 data
= (struct isl_union_print_data
*)user
;
1561 data
->p
= isl_printer_print_str(data
->p
, "; ");
1564 data
->p
= isl_map_print_isl_body(map
, data
->p
);
1570 static __isl_give isl_printer
*isl_union_map_print_isl(
1571 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1573 struct isl_union_print_data data
;
1574 struct isl_print_space_data space_data
= { 0 };
1577 space
= isl_union_map_get_space(umap
);
1578 p
= print_param_tuple(p
, space
, &space_data
);
1579 isl_space_free(space
);
1580 p
= isl_printer_print_str(p
, s_open_set
[0]);
1583 isl_union_map_foreach_map(umap
, &print_map_body
, &data
);
1585 p
= isl_printer_print_str(p
, s_close_set
[0]);
1589 static isl_stat
print_latex_map_body(__isl_take isl_map
*map
, void *user
)
1591 struct isl_union_print_data
*data
;
1592 data
= (struct isl_union_print_data
*)user
;
1595 data
->p
= isl_printer_print_str(data
->p
, " \\cup ");
1598 data
->p
= isl_map_print_latex(map
, data
->p
);
1604 static __isl_give isl_printer
*isl_union_map_print_latex(
1605 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1607 struct isl_union_print_data data
= { p
, 1 };
1608 isl_union_map_foreach_map(umap
, &print_latex_map_body
, &data
);
1613 __isl_give isl_printer
*isl_printer_print_union_map(__isl_take isl_printer
*p
,
1614 __isl_keep isl_union_map
*umap
)
1619 if (p
->output_format
== ISL_FORMAT_ISL
)
1620 return isl_union_map_print_isl(umap
, p
);
1621 if (p
->output_format
== ISL_FORMAT_LATEX
)
1622 return isl_union_map_print_latex(umap
, p
);
1624 isl_die(p
->ctx
, isl_error_invalid
,
1625 "invalid output format for isl_union_map", goto error
);
1627 isl_printer_free(p
);
1631 __isl_give isl_printer
*isl_printer_print_union_set(__isl_take isl_printer
*p
,
1632 __isl_keep isl_union_set
*uset
)
1637 if (p
->output_format
== ISL_FORMAT_ISL
)
1638 return isl_union_map_print_isl(uset_to_umap(uset
), p
);
1639 if (p
->output_format
== ISL_FORMAT_LATEX
)
1640 return isl_union_map_print_latex(uset_to_umap(uset
), p
);
1642 isl_die(p
->ctx
, isl_error_invalid
,
1643 "invalid output format for isl_union_set", goto error
);
1645 isl_printer_free(p
);
1649 static int upoly_rec_n_non_zero(__isl_keep
struct isl_upoly_rec
*rec
)
1654 for (i
= 0, n
= 0; i
< rec
->n
; ++i
)
1655 if (!isl_upoly_is_zero(rec
->p
[i
]))
1661 static __isl_give isl_printer
*upoly_print_cst(__isl_keep
struct isl_upoly
*up
,
1662 __isl_take isl_printer
*p
, int first
)
1664 struct isl_upoly_cst
*cst
;
1667 cst
= isl_upoly_as_cst(up
);
1670 neg
= !first
&& isl_int_is_neg(cst
->n
);
1672 p
= isl_printer_print_str(p
, neg
? " - " : " + ");
1674 isl_int_neg(cst
->n
, cst
->n
);
1675 if (isl_int_is_zero(cst
->d
)) {
1676 int sgn
= isl_int_sgn(cst
->n
);
1677 p
= isl_printer_print_str(p
, sgn
< 0 ? "-infty" :
1678 sgn
== 0 ? "NaN" : "infty");
1680 p
= isl_printer_print_isl_int(p
, cst
->n
);
1682 isl_int_neg(cst
->n
, cst
->n
);
1683 if (!isl_int_is_zero(cst
->d
) && !isl_int_is_one(cst
->d
)) {
1684 p
= isl_printer_print_str(p
, "/");
1685 p
= isl_printer_print_isl_int(p
, cst
->d
);
1689 isl_printer_free(p
);
1693 static __isl_give isl_printer
*print_base(__isl_take isl_printer
*p
,
1694 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
)
1698 total
= isl_space_dim(dim
, isl_dim_all
);
1700 p
= print_term(dim
, NULL
, dim
->ctx
->one
, 1 + var
, p
, 0);
1702 p
= print_div(dim
, div
, var
- total
, p
);
1706 static __isl_give isl_printer
*print_pow(__isl_take isl_printer
*p
,
1707 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
, int exp
)
1709 p
= print_base(p
, dim
, div
, var
);
1712 if (p
->output_format
== ISL_FORMAT_C
) {
1714 for (i
= 1; i
< exp
; ++i
) {
1715 p
= isl_printer_print_str(p
, "*");
1716 p
= print_base(p
, dim
, div
, var
);
1719 p
= isl_printer_print_str(p
, "^");
1720 p
= isl_printer_print_int(p
, exp
);
1725 /* Print the polynomial "up" defined over the domain space "space" and
1726 * local variables defined by "div" to "p".
1728 static __isl_give isl_printer
*upoly_print(__isl_keep
struct isl_upoly
*up
,
1729 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
1730 __isl_take isl_printer
*p
)
1732 int i
, n
, first
, print_parens
;
1733 struct isl_upoly_rec
*rec
;
1735 if (!p
|| !up
|| !space
|| !div
)
1738 if (isl_upoly_is_cst(up
))
1739 return upoly_print_cst(up
, p
, 1);
1741 rec
= isl_upoly_as_rec(up
);
1744 n
= upoly_rec_n_non_zero(rec
);
1745 print_parens
= n
> 1;
1747 p
= isl_printer_print_str(p
, "(");
1748 for (i
= 0, first
= 1; i
< rec
->n
; ++i
) {
1749 if (isl_upoly_is_zero(rec
->p
[i
]))
1751 if (isl_upoly_is_negone(rec
->p
[i
])) {
1753 p
= isl_printer_print_str(p
, "-1");
1755 p
= isl_printer_print_str(p
, "-");
1757 p
= isl_printer_print_str(p
, " - ");
1758 } else if (isl_upoly_is_cst(rec
->p
[i
]) &&
1759 !isl_upoly_is_one(rec
->p
[i
]))
1760 p
= upoly_print_cst(rec
->p
[i
], p
, first
);
1763 p
= isl_printer_print_str(p
, " + ");
1764 if (i
== 0 || !isl_upoly_is_one(rec
->p
[i
]))
1765 p
= upoly_print(rec
->p
[i
], space
, div
, p
);
1770 if (!isl_upoly_is_one(rec
->p
[i
]) &&
1771 !isl_upoly_is_negone(rec
->p
[i
]))
1772 p
= isl_printer_print_str(p
, " * ");
1773 p
= print_pow(p
, space
, div
, rec
->up
.var
, i
);
1776 p
= isl_printer_print_str(p
, ")");
1779 isl_printer_free(p
);
1783 static __isl_give isl_printer
*print_qpolynomial(__isl_take isl_printer
*p
,
1784 __isl_keep isl_qpolynomial
*qp
)
1788 p
= upoly_print(qp
->upoly
, qp
->dim
, qp
->div
, p
);
1791 isl_printer_free(p
);
1795 static __isl_give isl_printer
*print_qpolynomial_isl(__isl_take isl_printer
*p
,
1796 __isl_keep isl_qpolynomial
*qp
)
1798 struct isl_print_space_data data
= { 0 };
1803 p
= print_param_tuple(p
, qp
->dim
, &data
);
1804 p
= isl_printer_print_str(p
, "{ ");
1805 if (!isl_space_is_params(qp
->dim
)) {
1806 p
= isl_print_space(qp
->dim
, p
, 0, &data
);
1807 p
= isl_printer_print_str(p
, " -> ");
1809 p
= print_qpolynomial(p
, qp
);
1810 p
= isl_printer_print_str(p
, " }");
1813 isl_printer_free(p
);
1817 /* Print the quasi-polynomial "qp" to "p" in C format, with the variable names
1818 * taken from the domain space "space".
1820 static __isl_give isl_printer
*print_qpolynomial_c(__isl_take isl_printer
*p
,
1821 __isl_keep isl_space
*space
, __isl_keep isl_qpolynomial
*qp
)
1826 isl_qpolynomial_get_den(qp
, &den
);
1827 if (!isl_int_is_one(den
)) {
1829 p
= isl_printer_print_str(p
, "(");
1830 qp
= isl_qpolynomial_copy(qp
);
1831 f
= isl_qpolynomial_rat_cst_on_domain(isl_space_copy(qp
->dim
),
1832 den
, qp
->dim
->ctx
->one
);
1833 qp
= isl_qpolynomial_mul(qp
, f
);
1836 p
= upoly_print(qp
->upoly
, space
, qp
->div
, p
);
1838 p
= isl_printer_free(p
);
1839 if (!isl_int_is_one(den
)) {
1840 p
= isl_printer_print_str(p
, ")/");
1841 p
= isl_printer_print_isl_int(p
, den
);
1842 isl_qpolynomial_free(qp
);
1848 __isl_give isl_printer
*isl_printer_print_qpolynomial(
1849 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial
*qp
)
1854 if (p
->output_format
== ISL_FORMAT_ISL
)
1855 return print_qpolynomial_isl(p
, qp
);
1856 else if (p
->output_format
== ISL_FORMAT_C
)
1857 return print_qpolynomial_c(p
, qp
->dim
, qp
);
1859 isl_die(qp
->dim
->ctx
, isl_error_unsupported
,
1860 "output format not supported for isl_qpolynomials",
1863 isl_printer_free(p
);
1867 void isl_qpolynomial_print(__isl_keep isl_qpolynomial
*qp
, FILE *out
,
1868 unsigned output_format
)
1875 isl_assert(qp
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1876 p
= isl_printer_to_file(qp
->dim
->ctx
, out
);
1877 p
= isl_printer_print_qpolynomial(p
, qp
);
1878 isl_printer_free(p
);
1881 static __isl_give isl_printer
*qpolynomial_fold_print(
1882 __isl_keep isl_qpolynomial_fold
*fold
, __isl_take isl_printer
*p
)
1886 if (fold
->type
== isl_fold_min
)
1887 p
= isl_printer_print_str(p
, "min");
1888 else if (fold
->type
== isl_fold_max
)
1889 p
= isl_printer_print_str(p
, "max");
1890 p
= isl_printer_print_str(p
, "(");
1891 for (i
= 0; i
< fold
->n
; ++i
) {
1893 p
= isl_printer_print_str(p
, ", ");
1894 p
= print_qpolynomial(p
, fold
->qp
[i
]);
1896 p
= isl_printer_print_str(p
, ")");
1900 void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold
*fold
,
1901 FILE *out
, unsigned output_format
)
1908 isl_assert(fold
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1910 p
= isl_printer_to_file(fold
->dim
->ctx
, out
);
1911 p
= isl_printer_print_qpolynomial_fold(p
, fold
);
1913 isl_printer_free(p
);
1916 static __isl_give isl_printer
*isl_pwqp_print_isl_body(
1917 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1919 struct isl_print_space_data data
= { 0 };
1922 for (i
= 0; i
< pwqp
->n
; ++i
) {
1926 p
= isl_printer_print_str(p
, "; ");
1927 space
= isl_qpolynomial_get_domain_space(pwqp
->p
[i
].qp
);
1928 if (!isl_space_is_params(space
)) {
1929 p
= isl_print_space(space
, p
, 0, &data
);
1930 p
= isl_printer_print_str(p
, " -> ");
1932 p
= print_qpolynomial(p
, pwqp
->p
[i
].qp
);
1933 p
= print_disjuncts(set_to_map(pwqp
->p
[i
].set
), space
, p
, 0);
1934 isl_space_free(space
);
1940 static __isl_give isl_printer
*print_pw_qpolynomial_isl(
1941 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1943 struct isl_print_space_data data
= { 0 };
1948 p
= print_param_tuple(p
, pwqp
->dim
, &data
);
1949 p
= isl_printer_print_str(p
, "{ ");
1951 if (!isl_space_is_set(pwqp
->dim
)) {
1952 p
= print_tuple(pwqp
->dim
, p
, isl_dim_in
, &data
);
1953 p
= isl_printer_print_str(p
, " -> ");
1955 p
= isl_printer_print_str(p
, "0");
1957 p
= isl_pwqp_print_isl_body(p
, pwqp
);
1958 p
= isl_printer_print_str(p
, " }");
1961 isl_printer_free(p
);
1965 void isl_pw_qpolynomial_print(__isl_keep isl_pw_qpolynomial
*pwqp
, FILE *out
,
1966 unsigned output_format
)
1973 p
= isl_printer_to_file(pwqp
->dim
->ctx
, out
);
1974 p
= isl_printer_set_output_format(p
, output_format
);
1975 p
= isl_printer_print_pw_qpolynomial(p
, pwqp
);
1977 isl_printer_free(p
);
1980 static __isl_give isl_printer
*isl_pwf_print_isl_body(
1981 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
1983 struct isl_print_space_data data
= { 0 };
1986 for (i
= 0; i
< pwf
->n
; ++i
) {
1990 p
= isl_printer_print_str(p
, "; ");
1991 space
= isl_qpolynomial_fold_get_domain_space(pwf
->p
[i
].fold
);
1992 if (!isl_space_is_params(space
)) {
1993 p
= isl_print_space(space
, p
, 0, &data
);
1994 p
= isl_printer_print_str(p
, " -> ");
1996 p
= qpolynomial_fold_print(pwf
->p
[i
].fold
, p
);
1997 p
= print_disjuncts(set_to_map(pwf
->p
[i
].set
), space
, p
, 0);
1998 isl_space_free(space
);
2004 static __isl_give isl_printer
*print_pw_qpolynomial_fold_isl(
2005 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2007 struct isl_print_space_data data
= { 0 };
2009 p
= print_param_tuple(p
, pwf
->dim
, &data
);
2010 p
= isl_printer_print_str(p
, "{ ");
2012 if (!isl_space_is_set(pwf
->dim
)) {
2013 p
= print_tuple(pwf
->dim
, p
, isl_dim_in
, &data
);
2014 p
= isl_printer_print_str(p
, " -> ");
2016 p
= isl_printer_print_str(p
, "0");
2018 p
= isl_pwf_print_isl_body(p
, pwf
);
2019 p
= isl_printer_print_str(p
, " }");
2023 static __isl_give isl_printer
*print_affine_c(__isl_take isl_printer
*p
,
2024 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
, isl_int
*c
);
2026 static __isl_give isl_printer
*print_name_c(__isl_take isl_printer
*p
,
2027 __isl_keep isl_space
*dim
,
2028 __isl_keep isl_basic_set
*bset
, enum isl_dim_type type
, unsigned pos
)
2030 if (type
== isl_dim_div
) {
2031 p
= isl_printer_print_str(p
, "floord(");
2032 p
= print_affine_c(p
, dim
, bset
, bset
->div
[pos
] + 1);
2033 p
= isl_printer_print_str(p
, ", ");
2034 p
= isl_printer_print_isl_int(p
, bset
->div
[pos
][0]);
2035 p
= isl_printer_print_str(p
, ")");
2039 name
= isl_space_get_dim_name(dim
, type
, pos
);
2042 p
= isl_printer_print_str(p
, name
);
2047 static __isl_give isl_printer
*print_term_c(__isl_take isl_printer
*p
,
2048 __isl_keep isl_space
*dim
,
2049 __isl_keep isl_basic_set
*bset
, isl_int c
, unsigned pos
)
2051 enum isl_dim_type type
;
2054 return isl_printer_print_isl_int(p
, c
);
2056 if (isl_int_is_one(c
))
2058 else if (isl_int_is_negone(c
))
2059 p
= isl_printer_print_str(p
, "-");
2061 p
= isl_printer_print_isl_int(p
, c
);
2062 p
= isl_printer_print_str(p
, "*");
2064 type
= pos2type(dim
, &pos
);
2065 p
= print_name_c(p
, dim
, bset
, type
, pos
);
2069 static __isl_give isl_printer
*print_partial_affine_c(__isl_take isl_printer
*p
,
2070 __isl_keep isl_space
*dim
,
2071 __isl_keep isl_basic_set
*bset
, isl_int
*c
, unsigned len
)
2076 for (i
= 0, first
= 1; i
< len
; ++i
) {
2078 if (isl_int_is_zero(c
[i
]))
2081 if (isl_int_is_neg(c
[i
])) {
2083 isl_int_neg(c
[i
], c
[i
]);
2084 p
= isl_printer_print_str(p
, " - ");
2086 p
= isl_printer_print_str(p
, " + ");
2089 p
= print_term_c(p
, dim
, bset
, c
[i
], i
);
2091 isl_int_neg(c
[i
], c
[i
]);
2094 p
= isl_printer_print_str(p
, "0");
2098 static __isl_give isl_printer
*print_affine_c(__isl_take isl_printer
*p
,
2099 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
, isl_int
*c
)
2101 unsigned len
= 1 + isl_basic_set_total_dim(bset
);
2102 return print_partial_affine_c(p
, dim
, bset
, c
, len
);
2105 /* We skip the constraint if it is implied by the div expression.
2107 * *first indicates whether this is the first constraint in the conjunction and
2108 * is updated if the constraint is actually printed.
2110 static __isl_give isl_printer
*print_constraint_c(__isl_take isl_printer
*p
,
2111 __isl_keep isl_space
*dim
,
2112 __isl_keep isl_basic_set
*bset
, isl_int
*c
, const char *op
, int *first
)
2118 o_div
= isl_basic_set_offset(bset
, isl_dim_div
);
2119 n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
2120 div
= isl_seq_last_non_zero(c
+ o_div
, n_div
);
2122 isl_bool is_div
= isl_basic_set_is_div_constraint(bset
, c
, div
);
2124 return isl_printer_free(p
);
2130 p
= isl_printer_print_str(p
, " && ");
2132 p
= print_affine_c(p
, dim
, bset
, c
);
2133 p
= isl_printer_print_str(p
, " ");
2134 p
= isl_printer_print_str(p
, op
);
2135 p
= isl_printer_print_str(p
, " 0");
2142 static __isl_give isl_printer
*print_basic_set_c(__isl_take isl_printer
*p
,
2143 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
)
2147 unsigned n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
2148 unsigned total
= isl_basic_set_total_dim(bset
) - n_div
;
2150 for (i
= 0; i
< bset
->n_eq
; ++i
) {
2151 j
= isl_seq_last_non_zero(bset
->eq
[i
] + 1 + total
, n_div
);
2153 p
= print_constraint_c(p
, dim
, bset
,
2154 bset
->eq
[i
], "==", &first
);
2157 p
= isl_printer_print_str(p
, " && ");
2158 p
= isl_printer_print_str(p
, "(");
2159 p
= print_partial_affine_c(p
, dim
, bset
, bset
->eq
[i
],
2161 p
= isl_printer_print_str(p
, ") % ");
2162 p
= isl_printer_print_isl_int(p
,
2163 bset
->eq
[i
][1 + total
+ j
]);
2164 p
= isl_printer_print_str(p
, " == 0");
2168 for (i
= 0; i
< bset
->n_ineq
; ++i
)
2169 p
= print_constraint_c(p
, dim
, bset
, bset
->ineq
[i
], ">=",
2174 static __isl_give isl_printer
*print_set_c(__isl_take isl_printer
*p
,
2175 __isl_keep isl_space
*dim
, __isl_keep isl_set
*set
)
2180 return isl_printer_free(p
);
2183 p
= isl_printer_print_str(p
, "0");
2185 for (i
= 0; i
< set
->n
; ++i
) {
2187 p
= isl_printer_print_str(p
, " || ");
2189 p
= isl_printer_print_str(p
, "(");
2190 p
= print_basic_set_c(p
, dim
, set
->p
[i
]);
2192 p
= isl_printer_print_str(p
, ")");
2197 /* Print the piecewise quasi-polynomial "pwqp" to "p" in C format.
2199 static __isl_give isl_printer
*print_pw_qpolynomial_c(
2200 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2205 space
= isl_pw_qpolynomial_get_domain_space(pwqp
);
2206 if (pwqp
->n
== 1 && isl_set_plain_is_universe(pwqp
->p
[0].set
)) {
2207 p
= print_qpolynomial_c(p
, space
, pwqp
->p
[0].qp
);
2208 isl_space_free(space
);
2212 for (i
= 0; i
< pwqp
->n
; ++i
) {
2213 p
= isl_printer_print_str(p
, "(");
2214 p
= print_set_c(p
, space
, pwqp
->p
[i
].set
);
2215 p
= isl_printer_print_str(p
, ") ? (");
2216 p
= print_qpolynomial_c(p
, space
, pwqp
->p
[i
].qp
);
2217 p
= isl_printer_print_str(p
, ") : ");
2220 isl_space_free(space
);
2221 p
= isl_printer_print_str(p
, "0");
2225 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial(
2226 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2231 if (p
->output_format
== ISL_FORMAT_ISL
)
2232 return print_pw_qpolynomial_isl(p
, pwqp
);
2233 else if (p
->output_format
== ISL_FORMAT_C
)
2234 return print_pw_qpolynomial_c(p
, pwqp
);
2235 isl_assert(p
->ctx
, 0, goto error
);
2237 isl_printer_free(p
);
2241 static isl_stat
print_pwqp_body(__isl_take isl_pw_qpolynomial
*pwqp
, void *user
)
2243 struct isl_union_print_data
*data
;
2244 data
= (struct isl_union_print_data
*)user
;
2247 data
->p
= isl_printer_print_str(data
->p
, "; ");
2250 data
->p
= isl_pwqp_print_isl_body(data
->p
, pwqp
);
2251 isl_pw_qpolynomial_free(pwqp
);
2256 static __isl_give isl_printer
*print_union_pw_qpolynomial_isl(
2257 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2259 struct isl_union_print_data data
;
2260 struct isl_print_space_data space_data
= { 0 };
2263 space
= isl_union_pw_qpolynomial_get_space(upwqp
);
2264 p
= print_param_tuple(p
, space
, &space_data
);
2265 isl_space_free(space
);
2266 p
= isl_printer_print_str(p
, "{ ");
2269 isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp
, &print_pwqp_body
,
2272 p
= isl_printer_print_str(p
, " }");
2276 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial(
2277 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2282 if (p
->output_format
== ISL_FORMAT_ISL
)
2283 return print_union_pw_qpolynomial_isl(p
, upwqp
);
2284 isl_die(p
->ctx
, isl_error_invalid
,
2285 "invalid output format for isl_union_pw_qpolynomial",
2288 isl_printer_free(p
);
2292 /* Print the quasi-polynomial reduction "fold" to "p" in C format,
2293 * with the variable names taken from the domain space "space".
2295 static __isl_give isl_printer
*print_qpolynomial_fold_c(
2296 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
,
2297 __isl_keep isl_qpolynomial_fold
*fold
)
2301 for (i
= 0; i
< fold
->n
- 1; ++i
)
2302 if (fold
->type
== isl_fold_min
)
2303 p
= isl_printer_print_str(p
, "min(");
2304 else if (fold
->type
== isl_fold_max
)
2305 p
= isl_printer_print_str(p
, "max(");
2307 for (i
= 0; i
< fold
->n
; ++i
) {
2309 p
= isl_printer_print_str(p
, ", ");
2310 p
= print_qpolynomial_c(p
, space
, fold
->qp
[i
]);
2312 p
= isl_printer_print_str(p
, ")");
2317 __isl_give isl_printer
*isl_printer_print_qpolynomial_fold(
2318 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial_fold
*fold
)
2322 if (p
->output_format
== ISL_FORMAT_ISL
)
2323 return qpolynomial_fold_print(fold
, p
);
2324 else if (p
->output_format
== ISL_FORMAT_C
)
2325 return print_qpolynomial_fold_c(p
, fold
->dim
, fold
);
2326 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2329 isl_printer_free(p
);
2333 /* Print the piecewise quasi-polynomial reduction "pwf" to "p" in C format.
2335 static __isl_give isl_printer
*print_pw_qpolynomial_fold_c(
2336 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2341 space
= isl_pw_qpolynomial_fold_get_domain_space(pwf
);
2342 if (pwf
->n
== 1 && isl_set_plain_is_universe(pwf
->p
[0].set
)) {
2343 p
= print_qpolynomial_fold_c(p
, space
, pwf
->p
[0].fold
);
2344 isl_space_free(space
);
2348 for (i
= 0; i
< pwf
->n
; ++i
) {
2349 p
= isl_printer_print_str(p
, "(");
2350 p
= print_set_c(p
, space
, pwf
->p
[i
].set
);
2351 p
= isl_printer_print_str(p
, ") ? (");
2352 p
= print_qpolynomial_fold_c(p
, space
, pwf
->p
[i
].fold
);
2353 p
= isl_printer_print_str(p
, ") : ");
2356 isl_space_free(space
);
2357 p
= isl_printer_print_str(p
, "0");
2361 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial_fold(
2362 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2367 if (p
->output_format
== ISL_FORMAT_ISL
)
2368 return print_pw_qpolynomial_fold_isl(p
, pwf
);
2369 else if (p
->output_format
== ISL_FORMAT_C
)
2370 return print_pw_qpolynomial_fold_c(p
, pwf
);
2371 isl_assert(p
->ctx
, 0, goto error
);
2373 isl_printer_free(p
);
2377 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold
*pwf
,
2378 FILE *out
, unsigned output_format
)
2385 p
= isl_printer_to_file(pwf
->dim
->ctx
, out
);
2386 p
= isl_printer_set_output_format(p
, output_format
);
2387 p
= isl_printer_print_pw_qpolynomial_fold(p
, pwf
);
2389 isl_printer_free(p
);
2392 static isl_stat
print_pwf_body(__isl_take isl_pw_qpolynomial_fold
*pwf
,
2395 struct isl_union_print_data
*data
;
2396 data
= (struct isl_union_print_data
*)user
;
2399 data
->p
= isl_printer_print_str(data
->p
, "; ");
2402 data
->p
= isl_pwf_print_isl_body(data
->p
, pwf
);
2403 isl_pw_qpolynomial_fold_free(pwf
);
2408 static __isl_give isl_printer
*print_union_pw_qpolynomial_fold_isl(
2409 __isl_take isl_printer
*p
,
2410 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2412 struct isl_union_print_data data
;
2413 struct isl_print_space_data space_data
= { 0 };
2416 space
= isl_union_pw_qpolynomial_fold_get_space(upwf
);
2417 p
= print_param_tuple(p
, space
, &space_data
);
2418 isl_space_free(space
);
2419 p
= isl_printer_print_str(p
, "{ ");
2422 isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(upwf
,
2423 &print_pwf_body
, &data
);
2425 p
= isl_printer_print_str(p
, " }");
2429 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial_fold(
2430 __isl_take isl_printer
*p
,
2431 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2436 if (p
->output_format
== ISL_FORMAT_ISL
)
2437 return print_union_pw_qpolynomial_fold_isl(p
, upwf
);
2438 isl_die(p
->ctx
, isl_error_invalid
,
2439 "invalid output format for isl_union_pw_qpolynomial_fold",
2442 isl_printer_free(p
);
2446 /* Print the isl_constraint "c" to "p".
2448 __isl_give isl_printer
*isl_printer_print_constraint(__isl_take isl_printer
*p
,
2449 __isl_keep isl_constraint
*c
)
2451 struct isl_print_space_data data
= { 0 };
2452 isl_local_space
*ls
;
2459 ls
= isl_constraint_get_local_space(c
);
2461 return isl_printer_free(p
);
2462 space
= isl_local_space_get_space(ls
);
2463 p
= print_param_tuple(p
, space
, &data
);
2464 p
= isl_printer_print_str(p
, "{ ");
2465 p
= isl_print_space(space
, p
, 0, &data
);
2466 p
= isl_printer_print_str(p
, " : ");
2467 exists
= need_exists(p
, ls
->div
);
2469 p
= isl_printer_free(p
);
2470 if (exists
>= 0 && exists
)
2471 p
= open_exists(p
, space
, ls
->div
, 0);
2472 p
= print_affine_of_len(space
, ls
->div
, p
, c
->v
->el
, c
->v
->size
);
2473 if (isl_constraint_is_equality(c
))
2474 p
= isl_printer_print_str(p
, " = 0");
2476 p
= isl_printer_print_str(p
, " >= 0");
2477 if (exists
>= 0 && exists
)
2478 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2479 p
= isl_printer_print_str(p
, " }");
2480 isl_space_free(space
);
2481 isl_local_space_free(ls
);
2485 isl_printer_free(p
);
2489 static __isl_give isl_printer
*isl_printer_print_space_isl(
2490 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
)
2492 struct isl_print_space_data data
= { 0 };
2497 p
= print_param_tuple(p
, space
, &data
);
2499 p
= isl_printer_print_str(p
, "{ ");
2500 if (isl_space_is_params(space
))
2501 p
= isl_printer_print_str(p
, s_such_that
[0]);
2503 p
= isl_print_space(space
, p
, 0, &data
);
2504 p
= isl_printer_print_str(p
, " }");
2508 isl_printer_free(p
);
2512 __isl_give isl_printer
*isl_printer_print_space(__isl_take isl_printer
*p
,
2513 __isl_keep isl_space
*space
)
2516 return isl_printer_free(p
);
2517 if (p
->output_format
== ISL_FORMAT_ISL
)
2518 return isl_printer_print_space_isl(p
, space
);
2519 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
2520 return print_omega_parameters(space
, p
);
2522 isl_die(isl_space_get_ctx(space
), isl_error_unsupported
,
2523 "output format not supported for space",
2524 return isl_printer_free(p
));
2527 __isl_give isl_printer
*isl_printer_print_local_space(__isl_take isl_printer
*p
,
2528 __isl_keep isl_local_space
*ls
)
2530 struct isl_print_space_data data
= { 0 };
2536 p
= print_param_tuple(p
, ls
->dim
, &data
);
2537 p
= isl_printer_print_str(p
, "{ ");
2538 p
= isl_print_space(ls
->dim
, p
, 0, &data
);
2539 n_div
= isl_local_space_dim(ls
, isl_dim_div
);
2541 p
= isl_printer_print_str(p
, " : ");
2542 p
= isl_printer_print_str(p
, s_open_exists
[0]);
2543 p
= print_div_list(p
, ls
->dim
, ls
->div
, 0, 1);
2544 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2545 } else if (isl_space_is_params(ls
->dim
))
2546 p
= isl_printer_print_str(p
, s_such_that
[0]);
2547 p
= isl_printer_print_str(p
, " }");
2550 isl_printer_free(p
);
2554 static __isl_give isl_printer
*print_aff_body(__isl_take isl_printer
*p
,
2555 __isl_keep isl_aff
*aff
)
2559 if (isl_aff_is_nan(aff
))
2560 return isl_printer_print_str(p
, "NaN");
2562 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2563 p
= isl_printer_print_str(p
, "(");
2564 p
= print_affine_of_len(aff
->ls
->dim
, aff
->ls
->div
, p
,
2565 aff
->v
->el
+ 1, 1 + total
);
2566 if (isl_int_is_one(aff
->v
->el
[0]))
2567 p
= isl_printer_print_str(p
, ")");
2569 p
= isl_printer_print_str(p
, ")/");
2570 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2576 static __isl_give isl_printer
*print_aff(__isl_take isl_printer
*p
,
2577 __isl_keep isl_aff
*aff
)
2579 struct isl_print_space_data data
= { 0 };
2581 if (isl_space_is_params(aff
->ls
->dim
))
2584 p
= print_tuple(aff
->ls
->dim
, p
, isl_dim_set
, &data
);
2585 p
= isl_printer_print_str(p
, " -> ");
2587 p
= isl_printer_print_str(p
, "[");
2588 p
= print_aff_body(p
, aff
);
2589 p
= isl_printer_print_str(p
, "]");
2594 static __isl_give isl_printer
*print_aff_isl(__isl_take isl_printer
*p
,
2595 __isl_keep isl_aff
*aff
)
2597 struct isl_print_space_data data
= { 0 };
2602 p
= print_param_tuple(p
, aff
->ls
->dim
, &data
);
2603 p
= isl_printer_print_str(p
, "{ ");
2604 p
= print_aff(p
, aff
);
2605 p
= isl_printer_print_str(p
, " }");
2608 isl_printer_free(p
);
2612 /* Print the body of an isl_pw_aff, i.e., a semicolon delimited
2613 * sequence of affine expressions, each followed by constraints.
2615 static __isl_give isl_printer
*print_pw_aff_body(
2616 __isl_take isl_printer
*p
, __isl_keep isl_pw_aff
*pa
)
2621 return isl_printer_free(p
);
2623 for (i
= 0; i
< pa
->n
; ++i
) {
2627 p
= isl_printer_print_str(p
, "; ");
2628 p
= print_aff(p
, pa
->p
[i
].aff
);
2629 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
2630 p
= print_disjuncts(set_to_map(pa
->p
[i
].set
), space
, p
, 0);
2631 isl_space_free(space
);
2637 static __isl_give isl_printer
*print_pw_aff_isl(__isl_take isl_printer
*p
,
2638 __isl_keep isl_pw_aff
*pwaff
)
2640 struct isl_print_space_data data
= { 0 };
2645 p
= print_param_tuple(p
, pwaff
->dim
, &data
);
2646 p
= isl_printer_print_str(p
, "{ ");
2647 p
= print_pw_aff_body(p
, pwaff
);
2648 p
= isl_printer_print_str(p
, " }");
2651 isl_printer_free(p
);
2655 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2656 __isl_keep isl_local_space
*ls
, isl_int
*c
);
2658 static __isl_give isl_printer
*print_ls_name_c(__isl_take isl_printer
*p
,
2659 __isl_keep isl_local_space
*ls
, enum isl_dim_type type
, unsigned pos
)
2661 if (type
== isl_dim_div
) {
2662 p
= isl_printer_print_str(p
, "floord(");
2663 p
= print_ls_affine_c(p
, ls
, ls
->div
->row
[pos
] + 1);
2664 p
= isl_printer_print_str(p
, ", ");
2665 p
= isl_printer_print_isl_int(p
, ls
->div
->row
[pos
][0]);
2666 p
= isl_printer_print_str(p
, ")");
2670 name
= isl_space_get_dim_name(ls
->dim
, type
, pos
);
2673 p
= isl_printer_print_str(p
, name
);
2678 static __isl_give isl_printer
*print_ls_term_c(__isl_take isl_printer
*p
,
2679 __isl_keep isl_local_space
*ls
, isl_int c
, unsigned pos
)
2681 enum isl_dim_type type
;
2684 return isl_printer_print_isl_int(p
, c
);
2686 if (isl_int_is_one(c
))
2688 else if (isl_int_is_negone(c
))
2689 p
= isl_printer_print_str(p
, "-");
2691 p
= isl_printer_print_isl_int(p
, c
);
2692 p
= isl_printer_print_str(p
, "*");
2694 type
= pos2type(ls
->dim
, &pos
);
2695 p
= print_ls_name_c(p
, ls
, type
, pos
);
2699 static __isl_give isl_printer
*print_ls_partial_affine_c(
2700 __isl_take isl_printer
*p
, __isl_keep isl_local_space
*ls
,
2701 isl_int
*c
, unsigned len
)
2706 for (i
= 0, first
= 1; i
< len
; ++i
) {
2708 if (isl_int_is_zero(c
[i
]))
2711 if (isl_int_is_neg(c
[i
])) {
2713 isl_int_neg(c
[i
], c
[i
]);
2714 p
= isl_printer_print_str(p
, " - ");
2716 p
= isl_printer_print_str(p
, " + ");
2719 p
= print_ls_term_c(p
, ls
, c
[i
], i
);
2721 isl_int_neg(c
[i
], c
[i
]);
2724 p
= isl_printer_print_str(p
, "0");
2728 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2729 __isl_keep isl_local_space
*ls
, isl_int
*c
)
2731 unsigned len
= 1 + isl_local_space_dim(ls
, isl_dim_all
);
2732 return print_ls_partial_affine_c(p
, ls
, c
, len
);
2735 static __isl_give isl_printer
*print_aff_c(__isl_take isl_printer
*p
,
2736 __isl_keep isl_aff
*aff
)
2740 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2741 if (!isl_int_is_one(aff
->v
->el
[0]))
2742 p
= isl_printer_print_str(p
, "(");
2743 p
= print_ls_partial_affine_c(p
, aff
->ls
, aff
->v
->el
+ 1, 1 + total
);
2744 if (!isl_int_is_one(aff
->v
->el
[0])) {
2745 p
= isl_printer_print_str(p
, ")/");
2746 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2751 /* In the C format, we cannot express that "pwaff" may be undefined
2752 * on parts of the domain space. We therefore assume that the expression
2753 * will only be evaluated on its definition domain and compute the gist
2754 * of each cell with respect to this domain.
2756 static __isl_give isl_printer
*print_pw_aff_c(__isl_take isl_printer
*p
,
2757 __isl_keep isl_pw_aff
*pwaff
)
2760 isl_ast_build
*build
;
2764 isl_die(p
->ctx
, isl_error_unsupported
,
2765 "cannot print empty isl_pw_aff in C format",
2766 return isl_printer_free(p
));
2768 domain
= isl_pw_aff_domain(isl_pw_aff_copy(pwaff
));
2769 build
= isl_ast_build_from_context(domain
);
2770 expr
= isl_ast_build_expr_from_pw_aff(build
, isl_pw_aff_copy(pwaff
));
2771 p
= isl_printer_print_ast_expr(p
, expr
);
2772 isl_ast_expr_free(expr
);
2773 isl_ast_build_free(build
);
2778 __isl_give isl_printer
*isl_printer_print_aff(__isl_take isl_printer
*p
,
2779 __isl_keep isl_aff
*aff
)
2784 if (p
->output_format
== ISL_FORMAT_ISL
)
2785 return print_aff_isl(p
, aff
);
2786 else if (p
->output_format
== ISL_FORMAT_C
)
2787 return print_aff_c(p
, aff
);
2788 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2791 isl_printer_free(p
);
2795 __isl_give isl_printer
*isl_printer_print_pw_aff(__isl_take isl_printer
*p
,
2796 __isl_keep isl_pw_aff
*pwaff
)
2801 if (p
->output_format
== ISL_FORMAT_ISL
)
2802 return print_pw_aff_isl(p
, pwaff
);
2803 else if (p
->output_format
== ISL_FORMAT_C
)
2804 return print_pw_aff_c(p
, pwaff
);
2805 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2808 isl_printer_free(p
);
2812 /* Print "pa" in a sequence of isl_pw_affs delimited by semicolons.
2813 * Each isl_pw_aff itself is also printed as semicolon delimited
2814 * sequence of pieces.
2815 * If data->first = 1, then this is the first in the sequence.
2816 * Update data->first to tell the next element that it is not the first.
2818 static isl_stat
print_pw_aff_body_wrap(__isl_take isl_pw_aff
*pa
,
2821 struct isl_union_print_data
*data
;
2822 data
= (struct isl_union_print_data
*) user
;
2825 data
->p
= isl_printer_print_str(data
->p
, "; ");
2828 data
->p
= print_pw_aff_body(data
->p
, pa
);
2829 isl_pw_aff_free(pa
);
2831 return data
->p
? isl_stat_ok
: isl_stat_error
;
2834 /* Print the body of an isl_union_pw_aff, i.e., a semicolon delimited
2835 * sequence of affine expressions, each followed by constraints,
2836 * with the sequence enclosed in braces.
2838 static __isl_give isl_printer
*print_union_pw_aff_body(
2839 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2841 struct isl_union_print_data data
= { p
, 1 };
2843 p
= isl_printer_print_str(p
, s_open_set
[0]);
2845 if (isl_union_pw_aff_foreach_pw_aff(upa
,
2846 &print_pw_aff_body_wrap
, &data
) < 0)
2847 data
.p
= isl_printer_free(p
);
2849 p
= isl_printer_print_str(p
, s_close_set
[0]);
2854 /* Print the isl_union_pw_aff "upa" to "p" in isl format.
2856 * The individual isl_pw_affs are delimited by a semicolon.
2858 static __isl_give isl_printer
*print_union_pw_aff_isl(
2859 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2861 struct isl_print_space_data data
= { 0 };
2864 space
= isl_union_pw_aff_get_space(upa
);
2865 p
= print_param_tuple(p
, space
, &data
);
2866 isl_space_free(space
);
2867 p
= print_union_pw_aff_body(p
, upa
);
2871 /* Print the isl_union_pw_aff "upa" to "p".
2873 * We currently only support an isl format.
2875 __isl_give isl_printer
*isl_printer_print_union_pw_aff(
2876 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2879 return isl_printer_free(p
);
2881 if (p
->output_format
== ISL_FORMAT_ISL
)
2882 return print_union_pw_aff_isl(p
, upa
);
2883 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
2884 "unsupported output format", return isl_printer_free(p
));
2887 /* Print dimension "pos" of data->space to "p".
2889 * data->user is assumed to be an isl_multi_aff.
2891 * If the current dimension is an output dimension, then print
2892 * the corresponding expression. Otherwise, print the name of the dimension.
2894 static __isl_give isl_printer
*print_dim_ma(__isl_take isl_printer
*p
,
2895 struct isl_print_space_data
*data
, unsigned pos
)
2897 isl_multi_aff
*ma
= data
->user
;
2899 if (data
->type
== isl_dim_out
)
2900 p
= print_aff_body(p
, ma
->p
[pos
]);
2902 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2907 static __isl_give isl_printer
*print_multi_aff(__isl_take isl_printer
*p
,
2908 __isl_keep isl_multi_aff
*maff
)
2910 struct isl_print_space_data data
= { 0 };
2912 data
.print_dim
= &print_dim_ma
;
2914 return isl_print_space(maff
->space
, p
, 0, &data
);
2917 static __isl_give isl_printer
*print_multi_aff_isl(__isl_take isl_printer
*p
,
2918 __isl_keep isl_multi_aff
*maff
)
2920 struct isl_print_space_data data
= { 0 };
2925 p
= print_param_tuple(p
, maff
->space
, &data
);
2926 p
= isl_printer_print_str(p
, "{ ");
2927 p
= print_multi_aff(p
, maff
);
2928 p
= isl_printer_print_str(p
, " }");
2931 isl_printer_free(p
);
2935 __isl_give isl_printer
*isl_printer_print_multi_aff(__isl_take isl_printer
*p
,
2936 __isl_keep isl_multi_aff
*maff
)
2941 if (p
->output_format
== ISL_FORMAT_ISL
)
2942 return print_multi_aff_isl(p
, maff
);
2943 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2946 isl_printer_free(p
);
2950 static __isl_give isl_printer
*print_pw_multi_aff_body(
2951 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2958 for (i
= 0; i
< pma
->n
; ++i
) {
2962 p
= isl_printer_print_str(p
, "; ");
2963 p
= print_multi_aff(p
, pma
->p
[i
].maff
);
2964 space
= isl_multi_aff_get_domain_space(pma
->p
[i
].maff
);
2965 p
= print_disjuncts(set_to_map(pma
->p
[i
].set
), space
, p
, 0);
2966 isl_space_free(space
);
2970 isl_printer_free(p
);
2974 static __isl_give isl_printer
*print_pw_multi_aff_isl(__isl_take isl_printer
*p
,
2975 __isl_keep isl_pw_multi_aff
*pma
)
2977 struct isl_print_space_data data
= { 0 };
2982 p
= print_param_tuple(p
, pma
->dim
, &data
);
2983 p
= isl_printer_print_str(p
, "{ ");
2984 p
= print_pw_multi_aff_body(p
, pma
);
2985 p
= isl_printer_print_str(p
, " }");
2988 isl_printer_free(p
);
2992 /* Print the unnamed, single-dimensional piecewise multi affine expression "pma"
2995 static __isl_give isl_printer
*print_unnamed_pw_multi_aff_c(
2996 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
3001 space
= isl_pw_multi_aff_get_domain_space(pma
);
3002 for (i
= 0; i
< pma
->n
- 1; ++i
) {
3003 p
= isl_printer_print_str(p
, "(");
3004 p
= print_set_c(p
, space
, pma
->p
[i
].set
);
3005 p
= isl_printer_print_str(p
, ") ? (");
3006 p
= print_aff_c(p
, pma
->p
[i
].maff
->p
[0]);
3007 p
= isl_printer_print_str(p
, ") : ");
3009 isl_space_free(space
);
3011 return print_aff_c(p
, pma
->p
[pma
->n
- 1].maff
->p
[0]);
3014 static __isl_give isl_printer
*print_pw_multi_aff_c(__isl_take isl_printer
*p
,
3015 __isl_keep isl_pw_multi_aff
*pma
)
3023 isl_die(p
->ctx
, isl_error_unsupported
,
3024 "cannot print empty isl_pw_multi_aff in C format",
3026 name
= isl_pw_multi_aff_get_tuple_name(pma
, isl_dim_out
);
3027 if (!name
&& isl_pw_multi_aff_dim(pma
, isl_dim_out
) == 1)
3028 return print_unnamed_pw_multi_aff_c(p
, pma
);
3030 isl_die(p
->ctx
, isl_error_unsupported
,
3031 "cannot print unnamed isl_pw_multi_aff in C format",
3034 p
= isl_printer_print_str(p
, name
);
3035 n
= isl_pw_multi_aff_dim(pma
, isl_dim_out
);
3037 isl_die(p
->ctx
, isl_error_unsupported
,
3038 "not supported yet", goto error
);
3042 isl_printer_free(p
);
3046 __isl_give isl_printer
*isl_printer_print_pw_multi_aff(
3047 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
3052 if (p
->output_format
== ISL_FORMAT_ISL
)
3053 return print_pw_multi_aff_isl(p
, pma
);
3054 if (p
->output_format
== ISL_FORMAT_C
)
3055 return print_pw_multi_aff_c(p
, pma
);
3056 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3059 isl_printer_free(p
);
3063 static isl_stat
print_pw_multi_aff_body_wrap(__isl_take isl_pw_multi_aff
*pma
,
3066 struct isl_union_print_data
*data
;
3067 data
= (struct isl_union_print_data
*) user
;
3070 data
->p
= isl_printer_print_str(data
->p
, "; ");
3073 data
->p
= print_pw_multi_aff_body(data
->p
, pma
);
3074 isl_pw_multi_aff_free(pma
);
3079 static __isl_give isl_printer
*print_union_pw_multi_aff_isl(
3080 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
3082 struct isl_union_print_data data
;
3083 struct isl_print_space_data space_data
= { 0 };
3086 space
= isl_union_pw_multi_aff_get_space(upma
);
3087 p
= print_param_tuple(p
, space
, &space_data
);
3088 isl_space_free(space
);
3089 p
= isl_printer_print_str(p
, s_open_set
[0]);
3092 isl_union_pw_multi_aff_foreach_pw_multi_aff(upma
,
3093 &print_pw_multi_aff_body_wrap
, &data
);
3095 p
= isl_printer_print_str(p
, s_close_set
[0]);
3099 __isl_give isl_printer
*isl_printer_print_union_pw_multi_aff(
3100 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
3105 if (p
->output_format
== ISL_FORMAT_ISL
)
3106 return print_union_pw_multi_aff_isl(p
, upma
);
3107 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3110 isl_printer_free(p
);
3114 /* Print dimension "pos" of data->space to "p".
3116 * data->user is assumed to be an isl_multi_pw_aff.
3118 * If the current dimension is an output dimension, then print
3119 * the corresponding piecewise affine expression.
3120 * Otherwise, print the name of the dimension.
3122 static __isl_give isl_printer
*print_dim_mpa(__isl_take isl_printer
*p
,
3123 struct isl_print_space_data
*data
, unsigned pos
)
3127 isl_multi_pw_aff
*mpa
= data
->user
;
3130 if (data
->type
!= isl_dim_out
)
3131 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
3135 return isl_printer_print_str(p
, "(0 : false)");
3137 need_parens
= pa
->n
!= 1 || !isl_set_plain_is_universe(pa
->p
[0].set
);
3139 p
= isl_printer_print_str(p
, "(");
3140 for (i
= 0; i
< pa
->n
; ++i
) {
3144 p
= isl_printer_print_str(p
, "; ");
3145 p
= print_aff_body(p
, pa
->p
[i
].aff
);
3146 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
3147 p
= print_disjuncts(pa
->p
[i
].set
, space
, p
, 0);
3148 isl_space_free(space
);
3151 p
= isl_printer_print_str(p
, ")");
3156 /* Print "mpa" to "p" in isl format.
3158 static __isl_give isl_printer
*print_multi_pw_aff_isl(__isl_take isl_printer
*p
,
3159 __isl_keep isl_multi_pw_aff
*mpa
)
3161 struct isl_print_space_data data
= { 0 };
3164 return isl_printer_free(p
);
3166 p
= print_param_tuple(p
, mpa
->space
, &data
);
3167 p
= isl_printer_print_str(p
, "{ ");
3168 data
.print_dim
= &print_dim_mpa
;
3170 p
= isl_print_space(mpa
->space
, p
, 0, &data
);
3171 p
= isl_printer_print_str(p
, " }");
3175 __isl_give isl_printer
*isl_printer_print_multi_pw_aff(
3176 __isl_take isl_printer
*p
, __isl_keep isl_multi_pw_aff
*mpa
)
3179 return isl_printer_free(p
);
3181 if (p
->output_format
== ISL_FORMAT_ISL
)
3182 return print_multi_pw_aff_isl(p
, mpa
);
3183 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3184 return isl_printer_free(p
));
3187 /* Print dimension "pos" of data->space to "p".
3189 * data->user is assumed to be an isl_multi_val.
3191 * If the current dimension is an output dimension, then print
3192 * the corresponding value. Otherwise, print the name of the dimension.
3194 static __isl_give isl_printer
*print_dim_mv(__isl_take isl_printer
*p
,
3195 struct isl_print_space_data
*data
, unsigned pos
)
3197 isl_multi_val
*mv
= data
->user
;
3199 if (data
->type
== isl_dim_out
)
3200 return isl_printer_print_val(p
, mv
->p
[pos
]);
3202 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
3205 /* Print the isl_multi_val "mv" to "p" in isl format.
3207 static __isl_give isl_printer
*print_multi_val_isl(__isl_take isl_printer
*p
,
3208 __isl_keep isl_multi_val
*mv
)
3210 struct isl_print_space_data data
= { 0 };
3213 return isl_printer_free(p
);
3215 p
= print_param_tuple(p
, mv
->space
, &data
);
3216 p
= isl_printer_print_str(p
, "{ ");
3217 data
.print_dim
= &print_dim_mv
;
3219 p
= isl_print_space(mv
->space
, p
, 0, &data
);
3220 p
= isl_printer_print_str(p
, " }");
3224 /* Print the isl_multi_val "mv" to "p".
3226 * Currently only supported in isl format.
3228 __isl_give isl_printer
*isl_printer_print_multi_val(
3229 __isl_take isl_printer
*p
, __isl_keep isl_multi_val
*mv
)
3232 return isl_printer_free(p
);
3234 if (p
->output_format
== ISL_FORMAT_ISL
)
3235 return print_multi_val_isl(p
, mv
);
3236 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3237 return isl_printer_free(p
));
3240 /* Print dimension "pos" of data->space to "p".
3242 * data->user is assumed to be an isl_multi_union_pw_aff.
3244 * The current dimension is necessarily a set dimension, so
3245 * we print the corresponding isl_union_pw_aff, including
3248 static __isl_give isl_printer
*print_union_pw_aff_dim(__isl_take isl_printer
*p
,
3249 struct isl_print_space_data
*data
, unsigned pos
)
3251 isl_multi_union_pw_aff
*mupa
= data
->user
;
3252 isl_union_pw_aff
*upa
;
3254 upa
= isl_multi_union_pw_aff_get_union_pw_aff(mupa
, pos
);
3255 p
= print_union_pw_aff_body(p
, upa
);
3256 isl_union_pw_aff_free(upa
);
3261 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3263 static __isl_give isl_printer
*print_multi_union_pw_aff_isl(
3264 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3266 struct isl_print_space_data data
= { 0 };
3269 space
= isl_multi_union_pw_aff_get_space(mupa
);
3270 p
= print_param_tuple(p
, space
, &data
);
3272 data
.print_dim
= &print_union_pw_aff_dim
;
3275 p
= isl_print_space(space
, p
, 0, &data
);
3276 isl_space_free(space
);
3281 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3283 * We currently only support an isl format.
3285 __isl_give isl_printer
*isl_printer_print_multi_union_pw_aff(
3286 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3289 return isl_printer_free(p
);
3291 if (p
->output_format
== ISL_FORMAT_ISL
)
3292 return print_multi_union_pw_aff_isl(p
, mupa
);
3293 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
3294 "unsupported output format", return isl_printer_free(p
));