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 /* Print the body of "umap" (everything except the parameter declarations)
1571 * to "p" in isl format.
1573 static __isl_give isl_printer
*isl_printer_print_union_map_isl_body(
1574 __isl_take isl_printer
*p
, __isl_keep isl_union_map
*umap
)
1576 struct isl_union_print_data data
;
1578 p
= isl_printer_print_str(p
, s_open_set
[0]);
1581 isl_union_map_foreach_map(umap
, &print_map_body
, &data
);
1583 p
= isl_printer_print_str(p
, s_close_set
[0]);
1587 /* Print the isl_union_map "umap" to "p" in isl format.
1589 static __isl_give isl_printer
*isl_union_map_print_isl(
1590 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1592 struct isl_print_space_data space_data
= { 0 };
1595 space
= isl_union_map_get_space(umap
);
1596 p
= print_param_tuple(p
, space
, &space_data
);
1597 isl_space_free(space
);
1599 p
= isl_printer_print_union_map_isl_body(p
, umap
);
1604 static isl_stat
print_latex_map_body(__isl_take isl_map
*map
, void *user
)
1606 struct isl_union_print_data
*data
;
1607 data
= (struct isl_union_print_data
*)user
;
1610 data
->p
= isl_printer_print_str(data
->p
, " \\cup ");
1613 data
->p
= isl_map_print_latex(map
, data
->p
);
1619 static __isl_give isl_printer
*isl_union_map_print_latex(
1620 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1622 struct isl_union_print_data data
= { p
, 1 };
1623 isl_union_map_foreach_map(umap
, &print_latex_map_body
, &data
);
1628 __isl_give isl_printer
*isl_printer_print_union_map(__isl_take isl_printer
*p
,
1629 __isl_keep isl_union_map
*umap
)
1634 if (p
->output_format
== ISL_FORMAT_ISL
)
1635 return isl_union_map_print_isl(umap
, p
);
1636 if (p
->output_format
== ISL_FORMAT_LATEX
)
1637 return isl_union_map_print_latex(umap
, p
);
1639 isl_die(p
->ctx
, isl_error_invalid
,
1640 "invalid output format for isl_union_map", goto error
);
1642 isl_printer_free(p
);
1646 __isl_give isl_printer
*isl_printer_print_union_set(__isl_take isl_printer
*p
,
1647 __isl_keep isl_union_set
*uset
)
1652 if (p
->output_format
== ISL_FORMAT_ISL
)
1653 return isl_union_map_print_isl(uset_to_umap(uset
), p
);
1654 if (p
->output_format
== ISL_FORMAT_LATEX
)
1655 return isl_union_map_print_latex(uset_to_umap(uset
), p
);
1657 isl_die(p
->ctx
, isl_error_invalid
,
1658 "invalid output format for isl_union_set", goto error
);
1660 isl_printer_free(p
);
1664 static int upoly_rec_n_non_zero(__isl_keep
struct isl_upoly_rec
*rec
)
1669 for (i
= 0, n
= 0; i
< rec
->n
; ++i
)
1670 if (!isl_upoly_is_zero(rec
->p
[i
]))
1676 static __isl_give isl_printer
*upoly_print_cst(__isl_keep
struct isl_upoly
*up
,
1677 __isl_take isl_printer
*p
, int first
)
1679 struct isl_upoly_cst
*cst
;
1682 cst
= isl_upoly_as_cst(up
);
1685 neg
= !first
&& isl_int_is_neg(cst
->n
);
1687 p
= isl_printer_print_str(p
, neg
? " - " : " + ");
1689 isl_int_neg(cst
->n
, cst
->n
);
1690 if (isl_int_is_zero(cst
->d
)) {
1691 int sgn
= isl_int_sgn(cst
->n
);
1692 p
= isl_printer_print_str(p
, sgn
< 0 ? "-infty" :
1693 sgn
== 0 ? "NaN" : "infty");
1695 p
= isl_printer_print_isl_int(p
, cst
->n
);
1697 isl_int_neg(cst
->n
, cst
->n
);
1698 if (!isl_int_is_zero(cst
->d
) && !isl_int_is_one(cst
->d
)) {
1699 p
= isl_printer_print_str(p
, "/");
1700 p
= isl_printer_print_isl_int(p
, cst
->d
);
1704 isl_printer_free(p
);
1708 static __isl_give isl_printer
*print_base(__isl_take isl_printer
*p
,
1709 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
)
1713 total
= isl_space_dim(dim
, isl_dim_all
);
1715 p
= print_term(dim
, NULL
, dim
->ctx
->one
, 1 + var
, p
, 0);
1717 p
= print_div(dim
, div
, var
- total
, p
);
1721 static __isl_give isl_printer
*print_pow(__isl_take isl_printer
*p
,
1722 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
, int exp
)
1724 p
= print_base(p
, dim
, div
, var
);
1727 if (p
->output_format
== ISL_FORMAT_C
) {
1729 for (i
= 1; i
< exp
; ++i
) {
1730 p
= isl_printer_print_str(p
, "*");
1731 p
= print_base(p
, dim
, div
, var
);
1734 p
= isl_printer_print_str(p
, "^");
1735 p
= isl_printer_print_int(p
, exp
);
1740 /* Print the polynomial "up" defined over the domain space "space" and
1741 * local variables defined by "div" to "p".
1743 static __isl_give isl_printer
*upoly_print(__isl_keep
struct isl_upoly
*up
,
1744 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
1745 __isl_take isl_printer
*p
)
1747 int i
, n
, first
, print_parens
;
1748 struct isl_upoly_rec
*rec
;
1750 if (!p
|| !up
|| !space
|| !div
)
1753 if (isl_upoly_is_cst(up
))
1754 return upoly_print_cst(up
, p
, 1);
1756 rec
= isl_upoly_as_rec(up
);
1759 n
= upoly_rec_n_non_zero(rec
);
1760 print_parens
= n
> 1;
1762 p
= isl_printer_print_str(p
, "(");
1763 for (i
= 0, first
= 1; i
< rec
->n
; ++i
) {
1764 if (isl_upoly_is_zero(rec
->p
[i
]))
1766 if (isl_upoly_is_negone(rec
->p
[i
])) {
1768 p
= isl_printer_print_str(p
, "-1");
1770 p
= isl_printer_print_str(p
, "-");
1772 p
= isl_printer_print_str(p
, " - ");
1773 } else if (isl_upoly_is_cst(rec
->p
[i
]) &&
1774 !isl_upoly_is_one(rec
->p
[i
]))
1775 p
= upoly_print_cst(rec
->p
[i
], p
, first
);
1778 p
= isl_printer_print_str(p
, " + ");
1779 if (i
== 0 || !isl_upoly_is_one(rec
->p
[i
]))
1780 p
= upoly_print(rec
->p
[i
], space
, div
, p
);
1785 if (!isl_upoly_is_one(rec
->p
[i
]) &&
1786 !isl_upoly_is_negone(rec
->p
[i
]))
1787 p
= isl_printer_print_str(p
, " * ");
1788 p
= print_pow(p
, space
, div
, rec
->up
.var
, i
);
1791 p
= isl_printer_print_str(p
, ")");
1794 isl_printer_free(p
);
1798 static __isl_give isl_printer
*print_qpolynomial(__isl_take isl_printer
*p
,
1799 __isl_keep isl_qpolynomial
*qp
)
1803 p
= upoly_print(qp
->upoly
, qp
->dim
, qp
->div
, p
);
1806 isl_printer_free(p
);
1810 static __isl_give isl_printer
*print_qpolynomial_isl(__isl_take isl_printer
*p
,
1811 __isl_keep isl_qpolynomial
*qp
)
1813 struct isl_print_space_data data
= { 0 };
1818 p
= print_param_tuple(p
, qp
->dim
, &data
);
1819 p
= isl_printer_print_str(p
, "{ ");
1820 if (!isl_space_is_params(qp
->dim
)) {
1821 p
= isl_print_space(qp
->dim
, p
, 0, &data
);
1822 p
= isl_printer_print_str(p
, " -> ");
1824 p
= print_qpolynomial(p
, qp
);
1825 p
= isl_printer_print_str(p
, " }");
1828 isl_printer_free(p
);
1832 /* Print the quasi-polynomial "qp" to "p" in C format, with the variable names
1833 * taken from the domain space "space".
1835 static __isl_give isl_printer
*print_qpolynomial_c(__isl_take isl_printer
*p
,
1836 __isl_keep isl_space
*space
, __isl_keep isl_qpolynomial
*qp
)
1841 isl_qpolynomial_get_den(qp
, &den
);
1842 if (!isl_int_is_one(den
)) {
1844 p
= isl_printer_print_str(p
, "(");
1845 qp
= isl_qpolynomial_copy(qp
);
1846 f
= isl_qpolynomial_rat_cst_on_domain(isl_space_copy(qp
->dim
),
1847 den
, qp
->dim
->ctx
->one
);
1848 qp
= isl_qpolynomial_mul(qp
, f
);
1851 p
= upoly_print(qp
->upoly
, space
, qp
->div
, p
);
1853 p
= isl_printer_free(p
);
1854 if (!isl_int_is_one(den
)) {
1855 p
= isl_printer_print_str(p
, ")/");
1856 p
= isl_printer_print_isl_int(p
, den
);
1857 isl_qpolynomial_free(qp
);
1863 __isl_give isl_printer
*isl_printer_print_qpolynomial(
1864 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial
*qp
)
1869 if (p
->output_format
== ISL_FORMAT_ISL
)
1870 return print_qpolynomial_isl(p
, qp
);
1871 else if (p
->output_format
== ISL_FORMAT_C
)
1872 return print_qpolynomial_c(p
, qp
->dim
, qp
);
1874 isl_die(qp
->dim
->ctx
, isl_error_unsupported
,
1875 "output format not supported for isl_qpolynomials",
1878 isl_printer_free(p
);
1882 void isl_qpolynomial_print(__isl_keep isl_qpolynomial
*qp
, FILE *out
,
1883 unsigned output_format
)
1890 isl_assert(qp
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1891 p
= isl_printer_to_file(qp
->dim
->ctx
, out
);
1892 p
= isl_printer_print_qpolynomial(p
, qp
);
1893 isl_printer_free(p
);
1896 static __isl_give isl_printer
*qpolynomial_fold_print(
1897 __isl_keep isl_qpolynomial_fold
*fold
, __isl_take isl_printer
*p
)
1901 if (fold
->type
== isl_fold_min
)
1902 p
= isl_printer_print_str(p
, "min");
1903 else if (fold
->type
== isl_fold_max
)
1904 p
= isl_printer_print_str(p
, "max");
1905 p
= isl_printer_print_str(p
, "(");
1906 for (i
= 0; i
< fold
->n
; ++i
) {
1908 p
= isl_printer_print_str(p
, ", ");
1909 p
= print_qpolynomial(p
, fold
->qp
[i
]);
1911 p
= isl_printer_print_str(p
, ")");
1915 void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold
*fold
,
1916 FILE *out
, unsigned output_format
)
1923 isl_assert(fold
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1925 p
= isl_printer_to_file(fold
->dim
->ctx
, out
);
1926 p
= isl_printer_print_qpolynomial_fold(p
, fold
);
1928 isl_printer_free(p
);
1931 static __isl_give isl_printer
*isl_pwqp_print_isl_body(
1932 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1934 struct isl_print_space_data data
= { 0 };
1937 for (i
= 0; i
< pwqp
->n
; ++i
) {
1941 p
= isl_printer_print_str(p
, "; ");
1942 space
= isl_qpolynomial_get_domain_space(pwqp
->p
[i
].qp
);
1943 if (!isl_space_is_params(space
)) {
1944 p
= isl_print_space(space
, p
, 0, &data
);
1945 p
= isl_printer_print_str(p
, " -> ");
1947 p
= print_qpolynomial(p
, pwqp
->p
[i
].qp
);
1948 p
= print_disjuncts(set_to_map(pwqp
->p
[i
].set
), space
, p
, 0);
1949 isl_space_free(space
);
1955 static __isl_give isl_printer
*print_pw_qpolynomial_isl(
1956 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1958 struct isl_print_space_data data
= { 0 };
1963 p
= print_param_tuple(p
, pwqp
->dim
, &data
);
1964 p
= isl_printer_print_str(p
, "{ ");
1966 if (!isl_space_is_set(pwqp
->dim
)) {
1967 p
= print_tuple(pwqp
->dim
, p
, isl_dim_in
, &data
);
1968 p
= isl_printer_print_str(p
, " -> ");
1970 p
= isl_printer_print_str(p
, "0");
1972 p
= isl_pwqp_print_isl_body(p
, pwqp
);
1973 p
= isl_printer_print_str(p
, " }");
1976 isl_printer_free(p
);
1980 void isl_pw_qpolynomial_print(__isl_keep isl_pw_qpolynomial
*pwqp
, FILE *out
,
1981 unsigned output_format
)
1988 p
= isl_printer_to_file(pwqp
->dim
->ctx
, out
);
1989 p
= isl_printer_set_output_format(p
, output_format
);
1990 p
= isl_printer_print_pw_qpolynomial(p
, pwqp
);
1992 isl_printer_free(p
);
1995 static __isl_give isl_printer
*isl_pwf_print_isl_body(
1996 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
1998 struct isl_print_space_data data
= { 0 };
2001 for (i
= 0; i
< pwf
->n
; ++i
) {
2005 p
= isl_printer_print_str(p
, "; ");
2006 space
= isl_qpolynomial_fold_get_domain_space(pwf
->p
[i
].fold
);
2007 if (!isl_space_is_params(space
)) {
2008 p
= isl_print_space(space
, p
, 0, &data
);
2009 p
= isl_printer_print_str(p
, " -> ");
2011 p
= qpolynomial_fold_print(pwf
->p
[i
].fold
, p
);
2012 p
= print_disjuncts(set_to_map(pwf
->p
[i
].set
), space
, p
, 0);
2013 isl_space_free(space
);
2019 static __isl_give isl_printer
*print_pw_qpolynomial_fold_isl(
2020 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2022 struct isl_print_space_data data
= { 0 };
2024 p
= print_param_tuple(p
, pwf
->dim
, &data
);
2025 p
= isl_printer_print_str(p
, "{ ");
2027 if (!isl_space_is_set(pwf
->dim
)) {
2028 p
= print_tuple(pwf
->dim
, p
, isl_dim_in
, &data
);
2029 p
= isl_printer_print_str(p
, " -> ");
2031 p
= isl_printer_print_str(p
, "0");
2033 p
= isl_pwf_print_isl_body(p
, pwf
);
2034 p
= isl_printer_print_str(p
, " }");
2038 static __isl_give isl_printer
*print_affine_c(__isl_take isl_printer
*p
,
2039 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
, isl_int
*c
);
2041 static __isl_give isl_printer
*print_name_c(__isl_take isl_printer
*p
,
2042 __isl_keep isl_space
*dim
,
2043 __isl_keep isl_basic_set
*bset
, enum isl_dim_type type
, unsigned pos
)
2045 if (type
== isl_dim_div
) {
2046 p
= isl_printer_print_str(p
, "floord(");
2047 p
= print_affine_c(p
, dim
, bset
, bset
->div
[pos
] + 1);
2048 p
= isl_printer_print_str(p
, ", ");
2049 p
= isl_printer_print_isl_int(p
, bset
->div
[pos
][0]);
2050 p
= isl_printer_print_str(p
, ")");
2054 name
= isl_space_get_dim_name(dim
, type
, pos
);
2057 p
= isl_printer_print_str(p
, name
);
2062 static __isl_give isl_printer
*print_term_c(__isl_take isl_printer
*p
,
2063 __isl_keep isl_space
*dim
,
2064 __isl_keep isl_basic_set
*bset
, isl_int c
, unsigned pos
)
2066 enum isl_dim_type type
;
2069 return isl_printer_print_isl_int(p
, c
);
2071 if (isl_int_is_one(c
))
2073 else if (isl_int_is_negone(c
))
2074 p
= isl_printer_print_str(p
, "-");
2076 p
= isl_printer_print_isl_int(p
, c
);
2077 p
= isl_printer_print_str(p
, "*");
2079 type
= pos2type(dim
, &pos
);
2080 p
= print_name_c(p
, dim
, bset
, type
, pos
);
2084 static __isl_give isl_printer
*print_partial_affine_c(__isl_take isl_printer
*p
,
2085 __isl_keep isl_space
*dim
,
2086 __isl_keep isl_basic_set
*bset
, isl_int
*c
, unsigned len
)
2091 for (i
= 0, first
= 1; i
< len
; ++i
) {
2093 if (isl_int_is_zero(c
[i
]))
2096 if (isl_int_is_neg(c
[i
])) {
2098 isl_int_neg(c
[i
], c
[i
]);
2099 p
= isl_printer_print_str(p
, " - ");
2101 p
= isl_printer_print_str(p
, " + ");
2104 p
= print_term_c(p
, dim
, bset
, c
[i
], i
);
2106 isl_int_neg(c
[i
], c
[i
]);
2109 p
= isl_printer_print_str(p
, "0");
2113 static __isl_give isl_printer
*print_affine_c(__isl_take isl_printer
*p
,
2114 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
, isl_int
*c
)
2116 unsigned len
= 1 + isl_basic_set_total_dim(bset
);
2117 return print_partial_affine_c(p
, dim
, bset
, c
, len
);
2120 /* We skip the constraint if it is implied by the div expression.
2122 * *first indicates whether this is the first constraint in the conjunction and
2123 * is updated if the constraint is actually printed.
2125 static __isl_give isl_printer
*print_constraint_c(__isl_take isl_printer
*p
,
2126 __isl_keep isl_space
*dim
,
2127 __isl_keep isl_basic_set
*bset
, isl_int
*c
, const char *op
, int *first
)
2133 o_div
= isl_basic_set_offset(bset
, isl_dim_div
);
2134 n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
2135 div
= isl_seq_last_non_zero(c
+ o_div
, n_div
);
2137 isl_bool is_div
= isl_basic_set_is_div_constraint(bset
, c
, div
);
2139 return isl_printer_free(p
);
2145 p
= isl_printer_print_str(p
, " && ");
2147 p
= print_affine_c(p
, dim
, bset
, c
);
2148 p
= isl_printer_print_str(p
, " ");
2149 p
= isl_printer_print_str(p
, op
);
2150 p
= isl_printer_print_str(p
, " 0");
2157 static __isl_give isl_printer
*print_basic_set_c(__isl_take isl_printer
*p
,
2158 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
)
2162 unsigned n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
2163 unsigned total
= isl_basic_set_total_dim(bset
) - n_div
;
2165 for (i
= 0; i
< bset
->n_eq
; ++i
) {
2166 j
= isl_seq_last_non_zero(bset
->eq
[i
] + 1 + total
, n_div
);
2168 p
= print_constraint_c(p
, dim
, bset
,
2169 bset
->eq
[i
], "==", &first
);
2172 p
= isl_printer_print_str(p
, " && ");
2173 p
= isl_printer_print_str(p
, "(");
2174 p
= print_partial_affine_c(p
, dim
, bset
, bset
->eq
[i
],
2176 p
= isl_printer_print_str(p
, ") % ");
2177 p
= isl_printer_print_isl_int(p
,
2178 bset
->eq
[i
][1 + total
+ j
]);
2179 p
= isl_printer_print_str(p
, " == 0");
2183 for (i
= 0; i
< bset
->n_ineq
; ++i
)
2184 p
= print_constraint_c(p
, dim
, bset
, bset
->ineq
[i
], ">=",
2189 static __isl_give isl_printer
*print_set_c(__isl_take isl_printer
*p
,
2190 __isl_keep isl_space
*dim
, __isl_keep isl_set
*set
)
2195 return isl_printer_free(p
);
2198 p
= isl_printer_print_str(p
, "0");
2200 for (i
= 0; i
< set
->n
; ++i
) {
2202 p
= isl_printer_print_str(p
, " || ");
2204 p
= isl_printer_print_str(p
, "(");
2205 p
= print_basic_set_c(p
, dim
, set
->p
[i
]);
2207 p
= isl_printer_print_str(p
, ")");
2212 /* Print the piecewise quasi-polynomial "pwqp" to "p" in C format.
2214 static __isl_give isl_printer
*print_pw_qpolynomial_c(
2215 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2220 space
= isl_pw_qpolynomial_get_domain_space(pwqp
);
2221 if (pwqp
->n
== 1 && isl_set_plain_is_universe(pwqp
->p
[0].set
)) {
2222 p
= print_qpolynomial_c(p
, space
, pwqp
->p
[0].qp
);
2223 isl_space_free(space
);
2227 for (i
= 0; i
< pwqp
->n
; ++i
) {
2228 p
= isl_printer_print_str(p
, "(");
2229 p
= print_set_c(p
, space
, pwqp
->p
[i
].set
);
2230 p
= isl_printer_print_str(p
, ") ? (");
2231 p
= print_qpolynomial_c(p
, space
, pwqp
->p
[i
].qp
);
2232 p
= isl_printer_print_str(p
, ") : ");
2235 isl_space_free(space
);
2236 p
= isl_printer_print_str(p
, "0");
2240 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial(
2241 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2246 if (p
->output_format
== ISL_FORMAT_ISL
)
2247 return print_pw_qpolynomial_isl(p
, pwqp
);
2248 else if (p
->output_format
== ISL_FORMAT_C
)
2249 return print_pw_qpolynomial_c(p
, pwqp
);
2250 isl_assert(p
->ctx
, 0, goto error
);
2252 isl_printer_free(p
);
2256 static isl_stat
print_pwqp_body(__isl_take isl_pw_qpolynomial
*pwqp
, void *user
)
2258 struct isl_union_print_data
*data
;
2259 data
= (struct isl_union_print_data
*)user
;
2262 data
->p
= isl_printer_print_str(data
->p
, "; ");
2265 data
->p
= isl_pwqp_print_isl_body(data
->p
, pwqp
);
2266 isl_pw_qpolynomial_free(pwqp
);
2271 static __isl_give isl_printer
*print_union_pw_qpolynomial_isl(
2272 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2274 struct isl_union_print_data data
;
2275 struct isl_print_space_data space_data
= { 0 };
2278 space
= isl_union_pw_qpolynomial_get_space(upwqp
);
2279 p
= print_param_tuple(p
, space
, &space_data
);
2280 isl_space_free(space
);
2281 p
= isl_printer_print_str(p
, "{ ");
2284 isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp
, &print_pwqp_body
,
2287 p
= isl_printer_print_str(p
, " }");
2291 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial(
2292 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2297 if (p
->output_format
== ISL_FORMAT_ISL
)
2298 return print_union_pw_qpolynomial_isl(p
, upwqp
);
2299 isl_die(p
->ctx
, isl_error_invalid
,
2300 "invalid output format for isl_union_pw_qpolynomial",
2303 isl_printer_free(p
);
2307 /* Print the quasi-polynomial reduction "fold" to "p" in C format,
2308 * with the variable names taken from the domain space "space".
2310 static __isl_give isl_printer
*print_qpolynomial_fold_c(
2311 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
,
2312 __isl_keep isl_qpolynomial_fold
*fold
)
2316 for (i
= 0; i
< fold
->n
- 1; ++i
)
2317 if (fold
->type
== isl_fold_min
)
2318 p
= isl_printer_print_str(p
, "min(");
2319 else if (fold
->type
== isl_fold_max
)
2320 p
= isl_printer_print_str(p
, "max(");
2322 for (i
= 0; i
< fold
->n
; ++i
) {
2324 p
= isl_printer_print_str(p
, ", ");
2325 p
= print_qpolynomial_c(p
, space
, fold
->qp
[i
]);
2327 p
= isl_printer_print_str(p
, ")");
2332 __isl_give isl_printer
*isl_printer_print_qpolynomial_fold(
2333 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial_fold
*fold
)
2337 if (p
->output_format
== ISL_FORMAT_ISL
)
2338 return qpolynomial_fold_print(fold
, p
);
2339 else if (p
->output_format
== ISL_FORMAT_C
)
2340 return print_qpolynomial_fold_c(p
, fold
->dim
, fold
);
2341 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2344 isl_printer_free(p
);
2348 /* Print the piecewise quasi-polynomial reduction "pwf" to "p" in C format.
2350 static __isl_give isl_printer
*print_pw_qpolynomial_fold_c(
2351 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2356 space
= isl_pw_qpolynomial_fold_get_domain_space(pwf
);
2357 if (pwf
->n
== 1 && isl_set_plain_is_universe(pwf
->p
[0].set
)) {
2358 p
= print_qpolynomial_fold_c(p
, space
, pwf
->p
[0].fold
);
2359 isl_space_free(space
);
2363 for (i
= 0; i
< pwf
->n
; ++i
) {
2364 p
= isl_printer_print_str(p
, "(");
2365 p
= print_set_c(p
, space
, pwf
->p
[i
].set
);
2366 p
= isl_printer_print_str(p
, ") ? (");
2367 p
= print_qpolynomial_fold_c(p
, space
, pwf
->p
[i
].fold
);
2368 p
= isl_printer_print_str(p
, ") : ");
2371 isl_space_free(space
);
2372 p
= isl_printer_print_str(p
, "0");
2376 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial_fold(
2377 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2382 if (p
->output_format
== ISL_FORMAT_ISL
)
2383 return print_pw_qpolynomial_fold_isl(p
, pwf
);
2384 else if (p
->output_format
== ISL_FORMAT_C
)
2385 return print_pw_qpolynomial_fold_c(p
, pwf
);
2386 isl_assert(p
->ctx
, 0, goto error
);
2388 isl_printer_free(p
);
2392 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold
*pwf
,
2393 FILE *out
, unsigned output_format
)
2400 p
= isl_printer_to_file(pwf
->dim
->ctx
, out
);
2401 p
= isl_printer_set_output_format(p
, output_format
);
2402 p
= isl_printer_print_pw_qpolynomial_fold(p
, pwf
);
2404 isl_printer_free(p
);
2407 static isl_stat
print_pwf_body(__isl_take isl_pw_qpolynomial_fold
*pwf
,
2410 struct isl_union_print_data
*data
;
2411 data
= (struct isl_union_print_data
*)user
;
2414 data
->p
= isl_printer_print_str(data
->p
, "; ");
2417 data
->p
= isl_pwf_print_isl_body(data
->p
, pwf
);
2418 isl_pw_qpolynomial_fold_free(pwf
);
2423 static __isl_give isl_printer
*print_union_pw_qpolynomial_fold_isl(
2424 __isl_take isl_printer
*p
,
2425 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2427 struct isl_union_print_data data
;
2428 struct isl_print_space_data space_data
= { 0 };
2431 space
= isl_union_pw_qpolynomial_fold_get_space(upwf
);
2432 p
= print_param_tuple(p
, space
, &space_data
);
2433 isl_space_free(space
);
2434 p
= isl_printer_print_str(p
, "{ ");
2437 isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(upwf
,
2438 &print_pwf_body
, &data
);
2440 p
= isl_printer_print_str(p
, " }");
2444 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial_fold(
2445 __isl_take isl_printer
*p
,
2446 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2451 if (p
->output_format
== ISL_FORMAT_ISL
)
2452 return print_union_pw_qpolynomial_fold_isl(p
, upwf
);
2453 isl_die(p
->ctx
, isl_error_invalid
,
2454 "invalid output format for isl_union_pw_qpolynomial_fold",
2457 isl_printer_free(p
);
2461 /* Print the isl_constraint "c" to "p".
2463 __isl_give isl_printer
*isl_printer_print_constraint(__isl_take isl_printer
*p
,
2464 __isl_keep isl_constraint
*c
)
2466 struct isl_print_space_data data
= { 0 };
2467 isl_local_space
*ls
;
2474 ls
= isl_constraint_get_local_space(c
);
2476 return isl_printer_free(p
);
2477 space
= isl_local_space_get_space(ls
);
2478 p
= print_param_tuple(p
, space
, &data
);
2479 p
= isl_printer_print_str(p
, "{ ");
2480 p
= isl_print_space(space
, p
, 0, &data
);
2481 p
= isl_printer_print_str(p
, " : ");
2482 exists
= need_exists(p
, ls
->div
);
2484 p
= isl_printer_free(p
);
2485 if (exists
>= 0 && exists
)
2486 p
= open_exists(p
, space
, ls
->div
, 0);
2487 p
= print_affine_of_len(space
, ls
->div
, p
, c
->v
->el
, c
->v
->size
);
2488 if (isl_constraint_is_equality(c
))
2489 p
= isl_printer_print_str(p
, " = 0");
2491 p
= isl_printer_print_str(p
, " >= 0");
2492 if (exists
>= 0 && exists
)
2493 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2494 p
= isl_printer_print_str(p
, " }");
2495 isl_space_free(space
);
2496 isl_local_space_free(ls
);
2500 isl_printer_free(p
);
2504 static __isl_give isl_printer
*isl_printer_print_space_isl(
2505 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
)
2507 struct isl_print_space_data data
= { 0 };
2512 p
= print_param_tuple(p
, space
, &data
);
2514 p
= isl_printer_print_str(p
, "{ ");
2515 if (isl_space_is_params(space
))
2516 p
= isl_printer_print_str(p
, s_such_that
[0]);
2518 p
= isl_print_space(space
, p
, 0, &data
);
2519 p
= isl_printer_print_str(p
, " }");
2523 isl_printer_free(p
);
2527 __isl_give isl_printer
*isl_printer_print_space(__isl_take isl_printer
*p
,
2528 __isl_keep isl_space
*space
)
2531 return isl_printer_free(p
);
2532 if (p
->output_format
== ISL_FORMAT_ISL
)
2533 return isl_printer_print_space_isl(p
, space
);
2534 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
2535 return print_omega_parameters(space
, p
);
2537 isl_die(isl_space_get_ctx(space
), isl_error_unsupported
,
2538 "output format not supported for space",
2539 return isl_printer_free(p
));
2542 __isl_give isl_printer
*isl_printer_print_local_space(__isl_take isl_printer
*p
,
2543 __isl_keep isl_local_space
*ls
)
2545 struct isl_print_space_data data
= { 0 };
2551 p
= print_param_tuple(p
, ls
->dim
, &data
);
2552 p
= isl_printer_print_str(p
, "{ ");
2553 p
= isl_print_space(ls
->dim
, p
, 0, &data
);
2554 n_div
= isl_local_space_dim(ls
, isl_dim_div
);
2556 p
= isl_printer_print_str(p
, " : ");
2557 p
= isl_printer_print_str(p
, s_open_exists
[0]);
2558 p
= print_div_list(p
, ls
->dim
, ls
->div
, 0, 1);
2559 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2560 } else if (isl_space_is_params(ls
->dim
))
2561 p
= isl_printer_print_str(p
, s_such_that
[0]);
2562 p
= isl_printer_print_str(p
, " }");
2565 isl_printer_free(p
);
2569 static __isl_give isl_printer
*print_aff_body(__isl_take isl_printer
*p
,
2570 __isl_keep isl_aff
*aff
)
2574 if (isl_aff_is_nan(aff
))
2575 return isl_printer_print_str(p
, "NaN");
2577 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2578 p
= isl_printer_print_str(p
, "(");
2579 p
= print_affine_of_len(aff
->ls
->dim
, aff
->ls
->div
, p
,
2580 aff
->v
->el
+ 1, 1 + total
);
2581 if (isl_int_is_one(aff
->v
->el
[0]))
2582 p
= isl_printer_print_str(p
, ")");
2584 p
= isl_printer_print_str(p
, ")/");
2585 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2591 static __isl_give isl_printer
*print_aff(__isl_take isl_printer
*p
,
2592 __isl_keep isl_aff
*aff
)
2594 struct isl_print_space_data data
= { 0 };
2596 if (isl_space_is_params(aff
->ls
->dim
))
2599 p
= print_tuple(aff
->ls
->dim
, p
, isl_dim_set
, &data
);
2600 p
= isl_printer_print_str(p
, " -> ");
2602 p
= isl_printer_print_str(p
, "[");
2603 p
= print_aff_body(p
, aff
);
2604 p
= isl_printer_print_str(p
, "]");
2609 static __isl_give isl_printer
*print_aff_isl(__isl_take isl_printer
*p
,
2610 __isl_keep isl_aff
*aff
)
2612 struct isl_print_space_data data
= { 0 };
2617 p
= print_param_tuple(p
, aff
->ls
->dim
, &data
);
2618 p
= isl_printer_print_str(p
, "{ ");
2619 p
= print_aff(p
, aff
);
2620 p
= isl_printer_print_str(p
, " }");
2623 isl_printer_free(p
);
2627 /* Print the body of an isl_pw_aff, i.e., a semicolon delimited
2628 * sequence of affine expressions, each followed by constraints.
2630 static __isl_give isl_printer
*print_pw_aff_body(
2631 __isl_take isl_printer
*p
, __isl_keep isl_pw_aff
*pa
)
2636 return isl_printer_free(p
);
2638 for (i
= 0; i
< pa
->n
; ++i
) {
2642 p
= isl_printer_print_str(p
, "; ");
2643 p
= print_aff(p
, pa
->p
[i
].aff
);
2644 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
2645 p
= print_disjuncts(set_to_map(pa
->p
[i
].set
), space
, p
, 0);
2646 isl_space_free(space
);
2652 static __isl_give isl_printer
*print_pw_aff_isl(__isl_take isl_printer
*p
,
2653 __isl_keep isl_pw_aff
*pwaff
)
2655 struct isl_print_space_data data
= { 0 };
2660 p
= print_param_tuple(p
, pwaff
->dim
, &data
);
2661 p
= isl_printer_print_str(p
, "{ ");
2662 p
= print_pw_aff_body(p
, pwaff
);
2663 p
= isl_printer_print_str(p
, " }");
2666 isl_printer_free(p
);
2670 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2671 __isl_keep isl_local_space
*ls
, isl_int
*c
);
2673 static __isl_give isl_printer
*print_ls_name_c(__isl_take isl_printer
*p
,
2674 __isl_keep isl_local_space
*ls
, enum isl_dim_type type
, unsigned pos
)
2676 if (type
== isl_dim_div
) {
2677 p
= isl_printer_print_str(p
, "floord(");
2678 p
= print_ls_affine_c(p
, ls
, ls
->div
->row
[pos
] + 1);
2679 p
= isl_printer_print_str(p
, ", ");
2680 p
= isl_printer_print_isl_int(p
, ls
->div
->row
[pos
][0]);
2681 p
= isl_printer_print_str(p
, ")");
2685 name
= isl_space_get_dim_name(ls
->dim
, type
, pos
);
2688 p
= isl_printer_print_str(p
, name
);
2693 static __isl_give isl_printer
*print_ls_term_c(__isl_take isl_printer
*p
,
2694 __isl_keep isl_local_space
*ls
, isl_int c
, unsigned pos
)
2696 enum isl_dim_type type
;
2699 return isl_printer_print_isl_int(p
, c
);
2701 if (isl_int_is_one(c
))
2703 else if (isl_int_is_negone(c
))
2704 p
= isl_printer_print_str(p
, "-");
2706 p
= isl_printer_print_isl_int(p
, c
);
2707 p
= isl_printer_print_str(p
, "*");
2709 type
= pos2type(ls
->dim
, &pos
);
2710 p
= print_ls_name_c(p
, ls
, type
, pos
);
2714 static __isl_give isl_printer
*print_ls_partial_affine_c(
2715 __isl_take isl_printer
*p
, __isl_keep isl_local_space
*ls
,
2716 isl_int
*c
, unsigned len
)
2721 for (i
= 0, first
= 1; i
< len
; ++i
) {
2723 if (isl_int_is_zero(c
[i
]))
2726 if (isl_int_is_neg(c
[i
])) {
2728 isl_int_neg(c
[i
], c
[i
]);
2729 p
= isl_printer_print_str(p
, " - ");
2731 p
= isl_printer_print_str(p
, " + ");
2734 p
= print_ls_term_c(p
, ls
, c
[i
], i
);
2736 isl_int_neg(c
[i
], c
[i
]);
2739 p
= isl_printer_print_str(p
, "0");
2743 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2744 __isl_keep isl_local_space
*ls
, isl_int
*c
)
2746 unsigned len
= 1 + isl_local_space_dim(ls
, isl_dim_all
);
2747 return print_ls_partial_affine_c(p
, ls
, c
, len
);
2750 static __isl_give isl_printer
*print_aff_c(__isl_take isl_printer
*p
,
2751 __isl_keep isl_aff
*aff
)
2755 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2756 if (!isl_int_is_one(aff
->v
->el
[0]))
2757 p
= isl_printer_print_str(p
, "(");
2758 p
= print_ls_partial_affine_c(p
, aff
->ls
, aff
->v
->el
+ 1, 1 + total
);
2759 if (!isl_int_is_one(aff
->v
->el
[0])) {
2760 p
= isl_printer_print_str(p
, ")/");
2761 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2766 /* In the C format, we cannot express that "pwaff" may be undefined
2767 * on parts of the domain space. We therefore assume that the expression
2768 * will only be evaluated on its definition domain and compute the gist
2769 * of each cell with respect to this domain.
2771 static __isl_give isl_printer
*print_pw_aff_c(__isl_take isl_printer
*p
,
2772 __isl_keep isl_pw_aff
*pwaff
)
2775 isl_ast_build
*build
;
2779 isl_die(p
->ctx
, isl_error_unsupported
,
2780 "cannot print empty isl_pw_aff in C format",
2781 return isl_printer_free(p
));
2783 domain
= isl_pw_aff_domain(isl_pw_aff_copy(pwaff
));
2784 build
= isl_ast_build_from_context(domain
);
2785 expr
= isl_ast_build_expr_from_pw_aff(build
, isl_pw_aff_copy(pwaff
));
2786 p
= isl_printer_print_ast_expr(p
, expr
);
2787 isl_ast_expr_free(expr
);
2788 isl_ast_build_free(build
);
2793 __isl_give isl_printer
*isl_printer_print_aff(__isl_take isl_printer
*p
,
2794 __isl_keep isl_aff
*aff
)
2799 if (p
->output_format
== ISL_FORMAT_ISL
)
2800 return print_aff_isl(p
, aff
);
2801 else if (p
->output_format
== ISL_FORMAT_C
)
2802 return print_aff_c(p
, aff
);
2803 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2806 isl_printer_free(p
);
2810 __isl_give isl_printer
*isl_printer_print_pw_aff(__isl_take isl_printer
*p
,
2811 __isl_keep isl_pw_aff
*pwaff
)
2816 if (p
->output_format
== ISL_FORMAT_ISL
)
2817 return print_pw_aff_isl(p
, pwaff
);
2818 else if (p
->output_format
== ISL_FORMAT_C
)
2819 return print_pw_aff_c(p
, pwaff
);
2820 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2823 isl_printer_free(p
);
2827 /* Print "pa" in a sequence of isl_pw_affs delimited by semicolons.
2828 * Each isl_pw_aff itself is also printed as semicolon delimited
2829 * sequence of pieces.
2830 * If data->first = 1, then this is the first in the sequence.
2831 * Update data->first to tell the next element that it is not the first.
2833 static isl_stat
print_pw_aff_body_wrap(__isl_take isl_pw_aff
*pa
,
2836 struct isl_union_print_data
*data
;
2837 data
= (struct isl_union_print_data
*) user
;
2840 data
->p
= isl_printer_print_str(data
->p
, "; ");
2843 data
->p
= print_pw_aff_body(data
->p
, pa
);
2844 isl_pw_aff_free(pa
);
2846 return data
->p
? isl_stat_ok
: isl_stat_error
;
2849 /* Print the body of an isl_union_pw_aff, i.e., a semicolon delimited
2850 * sequence of affine expressions, each followed by constraints,
2851 * with the sequence enclosed in braces.
2853 static __isl_give isl_printer
*print_union_pw_aff_body(
2854 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2856 struct isl_union_print_data data
= { p
, 1 };
2858 p
= isl_printer_print_str(p
, s_open_set
[0]);
2860 if (isl_union_pw_aff_foreach_pw_aff(upa
,
2861 &print_pw_aff_body_wrap
, &data
) < 0)
2862 data
.p
= isl_printer_free(p
);
2864 p
= isl_printer_print_str(p
, s_close_set
[0]);
2869 /* Print the isl_union_pw_aff "upa" to "p" in isl format.
2871 * The individual isl_pw_affs are delimited by a semicolon.
2873 static __isl_give isl_printer
*print_union_pw_aff_isl(
2874 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2876 struct isl_print_space_data data
= { 0 };
2879 space
= isl_union_pw_aff_get_space(upa
);
2880 p
= print_param_tuple(p
, space
, &data
);
2881 isl_space_free(space
);
2882 p
= print_union_pw_aff_body(p
, upa
);
2886 /* Print the isl_union_pw_aff "upa" to "p".
2888 * We currently only support an isl format.
2890 __isl_give isl_printer
*isl_printer_print_union_pw_aff(
2891 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2894 return isl_printer_free(p
);
2896 if (p
->output_format
== ISL_FORMAT_ISL
)
2897 return print_union_pw_aff_isl(p
, upa
);
2898 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
2899 "unsupported output format", return isl_printer_free(p
));
2902 /* Print dimension "pos" of data->space to "p".
2904 * data->user is assumed to be an isl_multi_aff.
2906 * If the current dimension is an output dimension, then print
2907 * the corresponding expression. Otherwise, print the name of the dimension.
2909 static __isl_give isl_printer
*print_dim_ma(__isl_take isl_printer
*p
,
2910 struct isl_print_space_data
*data
, unsigned pos
)
2912 isl_multi_aff
*ma
= data
->user
;
2914 if (data
->type
== isl_dim_out
)
2915 p
= print_aff_body(p
, ma
->u
.p
[pos
]);
2917 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2922 static __isl_give isl_printer
*print_multi_aff(__isl_take isl_printer
*p
,
2923 __isl_keep isl_multi_aff
*maff
)
2925 struct isl_print_space_data data
= { 0 };
2927 data
.print_dim
= &print_dim_ma
;
2929 return isl_print_space(maff
->space
, p
, 0, &data
);
2932 static __isl_give isl_printer
*print_multi_aff_isl(__isl_take isl_printer
*p
,
2933 __isl_keep isl_multi_aff
*maff
)
2935 struct isl_print_space_data data
= { 0 };
2940 p
= print_param_tuple(p
, maff
->space
, &data
);
2941 p
= isl_printer_print_str(p
, "{ ");
2942 p
= print_multi_aff(p
, maff
);
2943 p
= isl_printer_print_str(p
, " }");
2946 isl_printer_free(p
);
2950 __isl_give isl_printer
*isl_printer_print_multi_aff(__isl_take isl_printer
*p
,
2951 __isl_keep isl_multi_aff
*maff
)
2956 if (p
->output_format
== ISL_FORMAT_ISL
)
2957 return print_multi_aff_isl(p
, maff
);
2958 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2961 isl_printer_free(p
);
2965 static __isl_give isl_printer
*print_pw_multi_aff_body(
2966 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2973 for (i
= 0; i
< pma
->n
; ++i
) {
2977 p
= isl_printer_print_str(p
, "; ");
2978 p
= print_multi_aff(p
, pma
->p
[i
].maff
);
2979 space
= isl_multi_aff_get_domain_space(pma
->p
[i
].maff
);
2980 p
= print_disjuncts(set_to_map(pma
->p
[i
].set
), space
, p
, 0);
2981 isl_space_free(space
);
2985 isl_printer_free(p
);
2989 static __isl_give isl_printer
*print_pw_multi_aff_isl(__isl_take isl_printer
*p
,
2990 __isl_keep isl_pw_multi_aff
*pma
)
2992 struct isl_print_space_data data
= { 0 };
2997 p
= print_param_tuple(p
, pma
->dim
, &data
);
2998 p
= isl_printer_print_str(p
, "{ ");
2999 p
= print_pw_multi_aff_body(p
, pma
);
3000 p
= isl_printer_print_str(p
, " }");
3003 isl_printer_free(p
);
3007 /* Print the unnamed, single-dimensional piecewise multi affine expression "pma"
3010 static __isl_give isl_printer
*print_unnamed_pw_multi_aff_c(
3011 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
3016 space
= isl_pw_multi_aff_get_domain_space(pma
);
3017 for (i
= 0; i
< pma
->n
- 1; ++i
) {
3018 p
= isl_printer_print_str(p
, "(");
3019 p
= print_set_c(p
, space
, pma
->p
[i
].set
);
3020 p
= isl_printer_print_str(p
, ") ? (");
3021 p
= print_aff_c(p
, pma
->p
[i
].maff
->u
.p
[0]);
3022 p
= isl_printer_print_str(p
, ") : ");
3024 isl_space_free(space
);
3026 return print_aff_c(p
, pma
->p
[pma
->n
- 1].maff
->u
.p
[0]);
3029 static __isl_give isl_printer
*print_pw_multi_aff_c(__isl_take isl_printer
*p
,
3030 __isl_keep isl_pw_multi_aff
*pma
)
3038 isl_die(p
->ctx
, isl_error_unsupported
,
3039 "cannot print empty isl_pw_multi_aff in C format",
3041 name
= isl_pw_multi_aff_get_tuple_name(pma
, isl_dim_out
);
3042 if (!name
&& isl_pw_multi_aff_dim(pma
, isl_dim_out
) == 1)
3043 return print_unnamed_pw_multi_aff_c(p
, pma
);
3045 isl_die(p
->ctx
, isl_error_unsupported
,
3046 "cannot print unnamed isl_pw_multi_aff in C format",
3049 p
= isl_printer_print_str(p
, name
);
3050 n
= isl_pw_multi_aff_dim(pma
, isl_dim_out
);
3052 isl_die(p
->ctx
, isl_error_unsupported
,
3053 "not supported yet", goto error
);
3057 isl_printer_free(p
);
3061 __isl_give isl_printer
*isl_printer_print_pw_multi_aff(
3062 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
3067 if (p
->output_format
== ISL_FORMAT_ISL
)
3068 return print_pw_multi_aff_isl(p
, pma
);
3069 if (p
->output_format
== ISL_FORMAT_C
)
3070 return print_pw_multi_aff_c(p
, pma
);
3071 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3074 isl_printer_free(p
);
3078 static isl_stat
print_pw_multi_aff_body_wrap(__isl_take isl_pw_multi_aff
*pma
,
3081 struct isl_union_print_data
*data
;
3082 data
= (struct isl_union_print_data
*) user
;
3085 data
->p
= isl_printer_print_str(data
->p
, "; ");
3088 data
->p
= print_pw_multi_aff_body(data
->p
, pma
);
3089 isl_pw_multi_aff_free(pma
);
3094 static __isl_give isl_printer
*print_union_pw_multi_aff_isl(
3095 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
3097 struct isl_union_print_data data
;
3098 struct isl_print_space_data space_data
= { 0 };
3101 space
= isl_union_pw_multi_aff_get_space(upma
);
3102 p
= print_param_tuple(p
, space
, &space_data
);
3103 isl_space_free(space
);
3104 p
= isl_printer_print_str(p
, s_open_set
[0]);
3107 isl_union_pw_multi_aff_foreach_pw_multi_aff(upma
,
3108 &print_pw_multi_aff_body_wrap
, &data
);
3110 p
= isl_printer_print_str(p
, s_close_set
[0]);
3114 __isl_give isl_printer
*isl_printer_print_union_pw_multi_aff(
3115 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
3120 if (p
->output_format
== ISL_FORMAT_ISL
)
3121 return print_union_pw_multi_aff_isl(p
, upma
);
3122 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3125 isl_printer_free(p
);
3129 /* Print dimension "pos" of data->space to "p".
3131 * data->user is assumed to be an isl_multi_pw_aff.
3133 * If the current dimension is an output dimension, then print
3134 * the corresponding piecewise affine expression.
3135 * Otherwise, print the name of the dimension.
3137 static __isl_give isl_printer
*print_dim_mpa(__isl_take isl_printer
*p
,
3138 struct isl_print_space_data
*data
, unsigned pos
)
3142 isl_multi_pw_aff
*mpa
= data
->user
;
3145 if (data
->type
!= isl_dim_out
)
3146 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
3150 return isl_printer_print_str(p
, "(0 : false)");
3152 need_parens
= pa
->n
!= 1 || !isl_set_plain_is_universe(pa
->p
[0].set
);
3154 p
= isl_printer_print_str(p
, "(");
3155 for (i
= 0; i
< pa
->n
; ++i
) {
3159 p
= isl_printer_print_str(p
, "; ");
3160 p
= print_aff_body(p
, pa
->p
[i
].aff
);
3161 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
3162 p
= print_disjuncts(pa
->p
[i
].set
, space
, p
, 0);
3163 isl_space_free(space
);
3166 p
= isl_printer_print_str(p
, ")");
3171 /* Print "mpa" to "p" in isl format.
3173 static __isl_give isl_printer
*print_multi_pw_aff_isl(__isl_take isl_printer
*p
,
3174 __isl_keep isl_multi_pw_aff
*mpa
)
3176 struct isl_print_space_data data
= { 0 };
3179 return isl_printer_free(p
);
3181 p
= print_param_tuple(p
, mpa
->space
, &data
);
3182 p
= isl_printer_print_str(p
, "{ ");
3183 data
.print_dim
= &print_dim_mpa
;
3185 p
= isl_print_space(mpa
->space
, p
, 0, &data
);
3186 p
= isl_printer_print_str(p
, " }");
3190 __isl_give isl_printer
*isl_printer_print_multi_pw_aff(
3191 __isl_take isl_printer
*p
, __isl_keep isl_multi_pw_aff
*mpa
)
3194 return isl_printer_free(p
);
3196 if (p
->output_format
== ISL_FORMAT_ISL
)
3197 return print_multi_pw_aff_isl(p
, mpa
);
3198 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3199 return isl_printer_free(p
));
3202 /* Print dimension "pos" of data->space to "p".
3204 * data->user is assumed to be an isl_multi_val.
3206 * If the current dimension is an output dimension, then print
3207 * the corresponding value. Otherwise, print the name of the dimension.
3209 static __isl_give isl_printer
*print_dim_mv(__isl_take isl_printer
*p
,
3210 struct isl_print_space_data
*data
, unsigned pos
)
3212 isl_multi_val
*mv
= data
->user
;
3214 if (data
->type
== isl_dim_out
)
3215 return isl_printer_print_val(p
, mv
->u
.p
[pos
]);
3217 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
3220 /* Print the isl_multi_val "mv" to "p" in isl format.
3222 static __isl_give isl_printer
*print_multi_val_isl(__isl_take isl_printer
*p
,
3223 __isl_keep isl_multi_val
*mv
)
3225 struct isl_print_space_data data
= { 0 };
3228 return isl_printer_free(p
);
3230 p
= print_param_tuple(p
, mv
->space
, &data
);
3231 p
= isl_printer_print_str(p
, "{ ");
3232 data
.print_dim
= &print_dim_mv
;
3234 p
= isl_print_space(mv
->space
, p
, 0, &data
);
3235 p
= isl_printer_print_str(p
, " }");
3239 /* Print the isl_multi_val "mv" to "p".
3241 * Currently only supported in isl format.
3243 __isl_give isl_printer
*isl_printer_print_multi_val(
3244 __isl_take isl_printer
*p
, __isl_keep isl_multi_val
*mv
)
3247 return isl_printer_free(p
);
3249 if (p
->output_format
== ISL_FORMAT_ISL
)
3250 return print_multi_val_isl(p
, mv
);
3251 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3252 return isl_printer_free(p
));
3255 /* Print dimension "pos" of data->space to "p".
3257 * data->user is assumed to be an isl_multi_union_pw_aff.
3259 * The current dimension is necessarily a set dimension, so
3260 * we print the corresponding isl_union_pw_aff, including
3263 static __isl_give isl_printer
*print_union_pw_aff_dim(__isl_take isl_printer
*p
,
3264 struct isl_print_space_data
*data
, unsigned pos
)
3266 isl_multi_union_pw_aff
*mupa
= data
->user
;
3267 isl_union_pw_aff
*upa
;
3269 upa
= isl_multi_union_pw_aff_get_union_pw_aff(mupa
, pos
);
3270 p
= print_union_pw_aff_body(p
, upa
);
3271 isl_union_pw_aff_free(upa
);
3276 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3278 static __isl_give isl_printer
*print_multi_union_pw_aff_isl(
3279 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3281 struct isl_print_space_data data
= { 0 };
3284 space
= isl_multi_union_pw_aff_get_space(mupa
);
3285 p
= print_param_tuple(p
, space
, &data
);
3287 data
.print_dim
= &print_union_pw_aff_dim
;
3290 p
= isl_print_space(space
, p
, 0, &data
);
3291 isl_space_free(space
);
3296 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3298 * We currently only support an isl format.
3300 __isl_give isl_printer
*isl_printer_print_multi_union_pw_aff(
3301 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3304 return isl_printer_free(p
);
3306 if (p
->output_format
== ISL_FORMAT_ISL
)
3307 return print_multi_union_pw_aff_isl(p
, mupa
);
3308 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
3309 "unsupported output format", return isl_printer_free(p
));