2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
6 * Use of this software is governed by the MIT license
8 * Written by Sven Verdoolaege, K.U.Leuven, Departement
9 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
10 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
11 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
12 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
17 #include <isl_ctx_private.h>
18 #include <isl_map_private.h>
21 #include <isl_polynomial_private.h>
22 #include <isl_printer_private.h>
23 #include <isl_space_private.h>
24 #include <isl_mat_private.h>
25 #include <isl_vec_private.h>
26 #include <isl/union_set.h>
27 #include <isl/union_map.h>
28 #include <isl/constraint.h>
29 #include <isl_local_space_private.h>
30 #include <isl_aff_private.h>
31 #include <isl_val_private.h>
32 #include <isl_constraint_private.h>
33 #include <isl/ast_build.h>
35 #include <isl_output_private.h>
37 #include <bset_to_bmap.c>
38 #include <set_to_map.c>
39 #include <uset_to_umap.c>
41 static const char *s_to
[2] = { " -> ", " \\to " };
42 static const char *s_and
[2] = { " and ", " \\wedge " };
43 static const char *s_or
[2] = { " or ", " \\vee " };
44 static const char *s_le
[2] = { "<=", "\\le" };
45 static const char *s_ge
[2] = { ">=", "\\ge" };
46 static const char *s_open_set
[2] = { "{ ", "\\{\\, " };
47 static const char *s_close_set
[2] = { " }", " \\,\\}" };
48 static const char *s_open_list
[2] = { "[", "(" };
49 static const char *s_close_list
[2] = { "]", ")" };
50 static const char *s_such_that
[2] = { " : ", " \\mid " };
51 static const char *s_open_exists
[2] = { "exists (", "\\exists \\, " };
52 static const char *s_close_exists
[2] = { ")", "" };
53 static const char *s_div_prefix
[2] = { "e", "\\alpha_" };
54 static const char *s_mod
[2] = { "mod", "\\bmod" };
55 static const char *s_param_prefix
[2] = { "p", "p_" };
56 static const char *s_input_prefix
[2] = { "i", "i_" };
57 static const char *s_output_prefix
[2] = { "o", "o_" };
59 static __isl_give isl_printer
*print_constraint_polylib(
60 struct isl_basic_map
*bmap
, int ineq
, int n
, __isl_take isl_printer
*p
)
63 unsigned n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
64 unsigned n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
65 unsigned nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
66 isl_int
*c
= ineq
? bmap
->ineq
[n
] : bmap
->eq
[n
];
68 p
= isl_printer_start_line(p
);
69 p
= isl_printer_print_int(p
, ineq
);
70 for (i
= 0; i
< n_out
; ++i
) {
71 p
= isl_printer_print_str(p
, " ");
72 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+n_in
+i
]);
74 for (i
= 0; i
< n_in
; ++i
) {
75 p
= isl_printer_print_str(p
, " ");
76 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+i
]);
78 for (i
= 0; i
< bmap
->n_div
; ++i
) {
79 p
= isl_printer_print_str(p
, " ");
80 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+n_in
+n_out
+i
]);
82 for (i
= 0; i
< nparam
; ++i
) {
83 p
= isl_printer_print_str(p
, " ");
84 p
= isl_printer_print_isl_int(p
, c
[1+i
]);
86 p
= isl_printer_print_str(p
, " ");
87 p
= isl_printer_print_isl_int(p
, c
[0]);
88 p
= isl_printer_end_line(p
);
92 static __isl_give isl_printer
*print_constraints_polylib(
93 struct isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
97 p
= isl_printer_set_isl_int_width(p
, 5);
99 for (i
= 0; i
< bmap
->n_eq
; ++i
)
100 p
= print_constraint_polylib(bmap
, 0, i
, p
);
101 for (i
= 0; i
< bmap
->n_ineq
; ++i
)
102 p
= print_constraint_polylib(bmap
, 1, i
, p
);
107 static __isl_give isl_printer
*bset_print_constraints_polylib(
108 struct isl_basic_set
*bset
, __isl_take isl_printer
*p
)
110 return print_constraints_polylib(bset_to_bmap(bset
), p
);
113 static __isl_give isl_printer
*isl_basic_map_print_polylib(
114 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
, int ext
)
116 unsigned total
= isl_basic_map_total_dim(bmap
);
117 p
= isl_printer_start_line(p
);
118 p
= isl_printer_print_int(p
, bmap
->n_eq
+ bmap
->n_ineq
);
119 p
= isl_printer_print_str(p
, " ");
120 p
= isl_printer_print_int(p
, 1 + total
+ 1);
122 p
= isl_printer_print_str(p
, " ");
123 p
= isl_printer_print_int(p
,
124 isl_basic_map_dim(bmap
, isl_dim_out
));
125 p
= isl_printer_print_str(p
, " ");
126 p
= isl_printer_print_int(p
,
127 isl_basic_map_dim(bmap
, isl_dim_in
));
128 p
= isl_printer_print_str(p
, " ");
129 p
= isl_printer_print_int(p
,
130 isl_basic_map_dim(bmap
, isl_dim_div
));
131 p
= isl_printer_print_str(p
, " ");
132 p
= isl_printer_print_int(p
,
133 isl_basic_map_dim(bmap
, isl_dim_param
));
135 p
= isl_printer_end_line(p
);
136 return print_constraints_polylib(bmap
, p
);
139 static __isl_give isl_printer
*isl_basic_set_print_polylib(
140 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
, int ext
)
142 return isl_basic_map_print_polylib(bset_to_bmap(bset
), p
, ext
);
145 static __isl_give isl_printer
*isl_map_print_polylib(__isl_keep isl_map
*map
,
146 __isl_take isl_printer
*p
, int ext
)
150 p
= isl_printer_start_line(p
);
151 p
= isl_printer_print_int(p
, map
->n
);
152 p
= isl_printer_end_line(p
);
153 for (i
= 0; i
< map
->n
; ++i
) {
154 p
= isl_printer_start_line(p
);
155 p
= isl_printer_end_line(p
);
156 p
= isl_basic_map_print_polylib(map
->p
[i
], p
, ext
);
161 static __isl_give isl_printer
*isl_set_print_polylib(__isl_keep isl_set
*set
,
162 __isl_take isl_printer
*p
, int ext
)
164 return isl_map_print_polylib(set_to_map(set
), p
, ext
);
167 static int count_same_name(__isl_keep isl_space
*space
,
168 enum isl_dim_type type
, unsigned pos
, const char *name
)
174 for (t
= isl_dim_param
; t
<= type
&& t
<= isl_dim_out
; ++t
) {
175 s
= t
== type
? pos
: isl_space_dim(space
, t
);
176 for (p
= 0; p
< s
; ++p
) {
177 const char *n
= isl_space_get_dim_name(space
, t
, p
);
178 if (n
&& !strcmp(n
, name
))
185 /* Print the name of the variable of type "type" and position "pos"
188 static __isl_give isl_printer
*print_name(__isl_keep isl_space
*space
,
189 __isl_take isl_printer
*p
, enum isl_dim_type type
, unsigned pos
,
196 name
= type
== isl_dim_div
? NULL
197 : isl_space_get_dim_name(space
, type
, pos
);
201 if (type
== isl_dim_param
)
202 prefix
= s_param_prefix
[latex
];
203 else if (type
== isl_dim_div
)
204 prefix
= s_div_prefix
[latex
];
205 else if (isl_space_is_set(space
) || type
== isl_dim_in
)
206 prefix
= s_input_prefix
[latex
];
208 prefix
= s_output_prefix
[latex
];
209 snprintf(buffer
, sizeof(buffer
), "%s%d", prefix
, pos
);
212 primes
= count_same_name(space
, name
== buffer
? isl_dim_div
: type
,
214 p
= isl_printer_print_str(p
, name
);
216 p
= isl_printer_print_str(p
, "'");
220 static isl_stat
pos2type(__isl_keep isl_space
*space
,
221 enum isl_dim_type
*type
, unsigned *pos
)
223 unsigned n_in
= isl_space_dim(space
, isl_dim_in
);
224 unsigned n_out
= isl_space_dim(space
, isl_dim_out
);
225 unsigned nparam
= isl_space_dim(space
, isl_dim_param
);
227 if (*pos
< 1 + nparam
) {
228 *type
= isl_dim_param
;
230 } else if (*pos
< 1 + nparam
+ n_in
) {
233 } else if (*pos
< 1 + nparam
+ n_in
+ n_out
) {
235 *pos
-= 1 + nparam
+ n_in
;
238 *pos
-= 1 + nparam
+ n_in
+ n_out
;
244 /* Can the div expression of the integer division at position "row" of "div"
246 * In particular, are the div expressions available and does the selected
247 * variable have a known explicit representation?
248 * Furthermore, the Omega format does not allow any div expressions
251 static isl_bool
can_print_div_expr(__isl_keep isl_printer
*p
,
252 __isl_keep isl_mat
*div
, int pos
)
254 if (p
->output_format
== ISL_FORMAT_OMEGA
)
255 return isl_bool_false
;
257 return isl_bool_false
;
258 return !isl_int_is_zero(div
->row
[pos
][0]);
261 static __isl_give isl_printer
*print_div(__isl_keep isl_space
*dim
,
262 __isl_keep isl_mat
*div
, int pos
, __isl_take isl_printer
*p
);
264 static __isl_give isl_printer
*print_term(__isl_keep isl_space
*space
,
265 __isl_keep isl_mat
*div
,
266 isl_int c
, unsigned pos
, __isl_take isl_printer
*p
, int latex
)
268 enum isl_dim_type type
;
272 return isl_printer_free(p
);
275 return isl_printer_print_isl_int(p
, c
);
277 if (pos2type(space
, &type
, &pos
) < 0)
278 return isl_printer_free(p
);
279 print_div_def
= type
== isl_dim_div
&& can_print_div_expr(p
, div
, pos
);
281 if (isl_int_is_one(c
))
283 else if (isl_int_is_negone(c
))
284 p
= isl_printer_print_str(p
, "-");
286 p
= isl_printer_print_isl_int(p
, c
);
287 if (p
->output_format
== ISL_FORMAT_C
|| print_div_def
)
288 p
= isl_printer_print_str(p
, "*");
291 p
= print_div(space
, div
, pos
, p
);
293 p
= print_name(space
, p
, type
, pos
, latex
);
297 static __isl_give isl_printer
*print_affine_of_len(__isl_keep isl_space
*dim
,
298 __isl_keep isl_mat
*div
,
299 __isl_take isl_printer
*p
, isl_int
*c
, int len
)
304 for (i
= 0, first
= 1; i
< len
; ++i
) {
306 if (isl_int_is_zero(c
[i
]))
309 if (isl_int_is_neg(c
[i
])) {
311 isl_int_neg(c
[i
], c
[i
]);
312 p
= isl_printer_print_str(p
, " - ");
314 p
= isl_printer_print_str(p
, " + ");
317 p
= print_term(dim
, div
, c
[i
], i
, p
, 0);
319 isl_int_neg(c
[i
], c
[i
]);
322 p
= isl_printer_print_str(p
, "0");
326 /* Print an affine expression "c"
327 * to "p", with the variable names taken from "space" and
328 * the integer division definitions taken from "div".
330 static __isl_give isl_printer
*print_affine(__isl_take isl_printer
*p
,
331 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, isl_int
*c
)
337 return isl_printer_free(p
);
338 n_div
= isl_mat_rows(div
);
339 len
= 1 + isl_space_dim(space
, isl_dim_all
) + n_div
;
340 return print_affine_of_len(space
, div
, p
, c
, len
);
343 /* offset is the offset of local_space inside data->type of data->space.
345 static __isl_give isl_printer
*print_nested_var_list(__isl_take isl_printer
*p
,
346 __isl_keep isl_space
*local_space
, enum isl_dim_type local_type
,
347 struct isl_print_space_data
*data
, int offset
)
351 if (data
->space
!= local_space
&& local_type
== isl_dim_out
)
352 offset
+= local_space
->n_in
;
354 for (i
= 0; i
< isl_space_dim(local_space
, local_type
); ++i
) {
356 p
= isl_printer_print_str(p
, ", ");
358 p
= data
->print_dim(p
, data
, offset
+ i
);
360 p
= print_name(data
->space
, p
, data
->type
, offset
+ i
,
366 static __isl_give isl_printer
*print_var_list(__isl_take isl_printer
*p
,
367 __isl_keep isl_space
*space
, enum isl_dim_type type
)
369 struct isl_print_space_data data
= { .space
= space
, .type
= type
};
371 return print_nested_var_list(p
, space
, type
, &data
, 0);
374 static __isl_give isl_printer
*print_nested_map_dim(__isl_take isl_printer
*p
,
375 __isl_keep isl_space
*local_dim
,
376 struct isl_print_space_data
*data
, int offset
);
378 static __isl_give isl_printer
*print_nested_tuple(__isl_take isl_printer
*p
,
379 __isl_keep isl_space
*local_space
, enum isl_dim_type local_type
,
380 struct isl_print_space_data
*data
, int offset
)
382 const char *name
= NULL
;
383 unsigned n
= isl_space_dim(local_space
, local_type
);
384 if ((local_type
== isl_dim_in
|| local_type
== isl_dim_out
)) {
385 name
= isl_space_get_tuple_name(local_space
, local_type
);
388 p
= isl_printer_print_str(p
, "\\mathrm{");
389 p
= isl_printer_print_str(p
, name
);
391 p
= isl_printer_print_str(p
, "}");
394 if (!data
->latex
|| n
!= 1 || name
)
395 p
= isl_printer_print_str(p
, s_open_list
[data
->latex
]);
396 if ((local_type
== isl_dim_in
|| local_type
== isl_dim_out
) &&
397 local_space
->nested
[local_type
- isl_dim_in
]) {
398 if (data
->space
!= local_space
&& local_type
== isl_dim_out
)
399 offset
+= local_space
->n_in
;
400 p
= print_nested_map_dim(p
,
401 local_space
->nested
[local_type
- isl_dim_in
],
404 p
= print_nested_var_list(p
, local_space
, local_type
, data
,
406 if (!data
->latex
|| n
!= 1 || name
)
407 p
= isl_printer_print_str(p
, s_close_list
[data
->latex
]);
411 static __isl_give isl_printer
*print_tuple(__isl_keep isl_space
*dim
,
412 __isl_take isl_printer
*p
, enum isl_dim_type type
,
413 struct isl_print_space_data
*data
)
417 return print_nested_tuple(p
, dim
, type
, data
, 0);
420 static __isl_give isl_printer
*print_nested_map_dim(__isl_take isl_printer
*p
,
421 __isl_keep isl_space
*local_dim
,
422 struct isl_print_space_data
*data
, int offset
)
424 p
= print_nested_tuple(p
, local_dim
, isl_dim_in
, data
, offset
);
425 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
426 p
= print_nested_tuple(p
, local_dim
, isl_dim_out
, data
, offset
);
431 __isl_give isl_printer
*isl_print_space(__isl_keep isl_space
*space
,
432 __isl_take isl_printer
*p
, int rational
,
433 struct isl_print_space_data
*data
)
435 if (rational
&& !data
->latex
)
436 p
= isl_printer_print_str(p
, "rat: ");
437 if (isl_space_is_params(space
))
439 else if (isl_space_is_set(space
))
440 p
= print_tuple(space
, p
, isl_dim_set
, data
);
442 p
= print_tuple(space
, p
, isl_dim_in
, data
);
443 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
444 p
= print_tuple(space
, p
, isl_dim_out
, data
);
450 static __isl_give isl_printer
*print_omega_parameters(
451 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
)
453 if (isl_space_dim(space
, isl_dim_param
) == 0)
456 p
= isl_printer_start_line(p
);
457 p
= isl_printer_print_str(p
, "symbolic ");
458 p
= print_var_list(p
, space
, isl_dim_param
);
459 p
= isl_printer_print_str(p
, ";");
460 p
= isl_printer_end_line(p
);
464 /* Does the inequality constraint following "i" in "bmap"
465 * have an opposite value for the same last coefficient?
466 * "last" is the position of the last coefficient of inequality "i".
467 * If the next constraint is a div constraint, then it is ignored
468 * since div constraints are not printed.
470 static isl_bool
next_is_opposite(__isl_keep isl_basic_map
*bmap
, int i
,
473 unsigned total
= isl_basic_map_total_dim(bmap
);
474 unsigned o_div
= isl_basic_map_offset(bmap
, isl_dim_div
);
476 if (i
+ 1 >= bmap
->n_ineq
)
477 return isl_bool_false
;
478 if (isl_seq_last_non_zero(bmap
->ineq
[i
+ 1], 1 + total
) != last
)
479 return isl_bool_false
;
482 is_div
= isl_basic_map_is_div_constraint(bmap
,
483 bmap
->ineq
[i
+ 1], last
- o_div
);
485 return isl_bool_error
;
487 return isl_bool_false
;
489 return isl_int_abs_eq(bmap
->ineq
[i
][last
], bmap
->ineq
[i
+ 1][last
]) &&
490 !isl_int_eq(bmap
->ineq
[i
][last
], bmap
->ineq
[i
+ 1][last
]);
493 /* Return a string representation of the operator used when
494 * printing a constraint where the LHS is greater than or equal to the LHS
495 * (sign > 0) or smaller than or equal to the LHS (sign < 0).
496 * If "strict" is set, then return the strict version of the comparison
499 static const char *constraint_op(int sign
, int strict
, int latex
)
502 return sign
< 0 ? "<" : ">";
509 /* Print one side of a constraint "c" to "p", with
510 * the variable names taken from "space" and the integer division definitions
512 * "last" is the position of the last non-zero coefficient.
513 * Let c' be the result of zeroing out this coefficient, then
514 * the partial constraint
520 static __isl_give isl_printer
*print_half_constraint(__isl_take isl_printer
*p
,
521 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
522 isl_int
*c
, int last
, const char *op
, int latex
)
524 isl_int_set_si(c
[last
], 0);
525 p
= print_affine(p
, space
, div
, c
);
527 p
= isl_printer_print_str(p
, " ");
528 p
= isl_printer_print_str(p
, op
);
529 p
= isl_printer_print_str(p
, " ");
534 /* Print a constraint "c" to "p", with the variable names
535 * taken from "space" and the integer division definitions taken from "div".
536 * "last" is the position of the last non-zero coefficient, which is
537 * moreover assumed to be negative.
538 * Let c' be the result of zeroing out this coefficient, then
539 * the constraint is printed in the form
543 static __isl_give isl_printer
*print_constraint(__isl_take isl_printer
*p
,
544 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
545 isl_int
*c
, int last
, const char *op
, int latex
)
547 isl_int_abs(c
[last
], c
[last
]);
549 p
= print_term(space
, div
, c
[last
], last
, p
, latex
);
551 p
= isl_printer_print_str(p
, " ");
552 p
= isl_printer_print_str(p
, op
);
553 p
= isl_printer_print_str(p
, " ");
555 isl_int_set_si(c
[last
], 0);
556 p
= print_affine(p
, space
, div
, c
);
561 /* Given an integer division
565 * at position "pos" in "div", print the corresponding modulo expression
569 * to "p". The variable names are taken from "space", while any
570 * nested integer division definitions are taken from "div".
572 static __isl_give isl_printer
*print_mod(__isl_take isl_printer
*p
,
573 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int pos
,
577 return isl_printer_free(p
);
579 p
= isl_printer_print_str(p
, "(");
580 p
= print_affine_of_len(space
, div
, p
,
581 div
->row
[pos
] + 1, div
->n_col
- 1);
582 p
= isl_printer_print_str(p
, ") ");
583 p
= isl_printer_print_str(p
, s_mod
[latex
]);
584 p
= isl_printer_print_str(p
, " ");
585 p
= isl_printer_print_isl_int(p
, div
->row
[pos
][0]);
589 /* Can the equality constraints "c" be printed as a modulo constraint?
590 * In particular, is of the form
592 * f - a m floor(g/m) = 0,
594 * with c = -a m the coefficient at position "pos"?
595 * Return the position of the corresponding integer division if so.
596 * Return the number of integer divisions if not.
597 * Return -1 on error.
599 * Modulo constraints are currently not printed in C format.
600 * Other than that, "pos" needs to correspond to an integer division
601 * with explicit representation and "c" needs to be a multiple
602 * of the denominator of the integer division.
604 static int print_as_modulo_pos(__isl_keep isl_printer
*p
,
605 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, unsigned pos
,
610 enum isl_dim_type type
;
614 n_div
= isl_mat_rows(div
);
615 if (p
->output_format
== ISL_FORMAT_C
)
617 if (pos2type(space
, &type
, &pos
) < 0)
619 if (type
!= isl_dim_div
)
621 can_print
= can_print_div_expr(p
, div
, pos
);
626 if (!isl_int_is_divisible_by(c
, div
->row
[pos
][0]))
631 /* Print equality constraint "c" to "p" as a modulo constraint,
632 * with the variable names taken from "space" and
633 * the integer division definitions taken from "div".
634 * "last" is the position of the last non-zero coefficient, which is
635 * moreover assumed to be negative and a multiple of the denominator
636 * of the corresponding integer division. "div_pos" is the corresponding
637 * position in the sequence of integer divisions.
639 * The equality is of the form
641 * f - a m floor(g/m) = 0.
645 * a (g mod m) = -f + a g
647 static __isl_give isl_printer
*print_eq_mod_constraint(
648 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
,
649 __isl_keep isl_mat
*div
, unsigned div_pos
,
650 isl_int
*c
, int last
, int latex
)
655 ctx
= isl_printer_get_ctx(p
);
656 isl_int_divexact(c
[last
], c
[last
], div
->row
[div_pos
][0]);
657 isl_int_abs(c
[last
], c
[last
]);
658 multiple
= !isl_int_is_one(c
[last
]);
660 p
= isl_printer_print_isl_int(p
, c
[last
]);
661 p
= isl_printer_print_str(p
, "*(");
663 p
= print_mod(p
, space
, div
, div_pos
, latex
);
665 p
= isl_printer_print_str(p
, ")");
666 p
= isl_printer_print_str(p
, " = ");
667 isl_seq_combine(c
, ctx
->negone
, c
,
668 c
[last
], div
->row
[div_pos
] + 1, last
);
669 isl_int_set_si(c
[last
], 0);
670 p
= print_affine(p
, space
, div
, c
);
674 /* Print equality constraint "c" to "p", with the variable names
675 * taken from "space" and the integer division definitions taken from "div".
676 * "last" is the position of the last non-zero coefficient, which is
677 * moreover assumed to be negative.
679 * If possible, print the equality constraint as a modulo constraint.
681 static __isl_give isl_printer
*print_eq_constraint(__isl_take isl_printer
*p
,
682 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, isl_int
*c
,
688 n_div
= isl_mat_rows(div
);
689 div_pos
= print_as_modulo_pos(p
, space
, div
, last
, c
[last
]);
691 return isl_printer_free(p
);
693 return print_eq_mod_constraint(p
, space
, div
, div_pos
,
695 return print_constraint(p
, space
, div
, c
, last
, "=", latex
);
698 /* Print the constraints of "bmap" to "p".
699 * The names of the variables are taken from "space" and
700 * the integer division definitions are taken from "div".
701 * Div constraints are only printed in "dump" mode.
702 * The constraints are sorted prior to printing (except in "dump" mode).
704 * If x is the last variable with a non-zero coefficient,
713 * while an upper bound
721 * If the next constraint has an opposite sign for the same last coefficient,
722 * then it is printed as
730 * instead. In fact, the "a x" part is not printed explicitly, but
731 * reused from the next constraint, which is therefore treated as
732 * a first constraint in the conjunction.
734 * If the constant term of "f" is -1, then "f" is replaced by "f + 1" and
735 * the comparison operator is replaced by the strict variant.
736 * Essentially, ">= 1" is replaced by "> 0".
738 static __isl_give isl_printer
*print_constraints(__isl_keep isl_basic_map
*bmap
,
739 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
740 __isl_take isl_printer
*p
, int latex
)
744 int rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
745 unsigned total
= isl_basic_map_total_dim(bmap
);
746 unsigned o_div
= isl_basic_map_offset(bmap
, isl_dim_div
);
752 bmap
= isl_basic_map_copy(bmap
);
755 bmap
= isl_basic_map_sort_constraints(bmap
);
759 c
= isl_vec_alloc(bmap
->ctx
, 1 + total
);
763 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
764 int l
= isl_seq_last_non_zero(bmap
->eq
[i
], 1 + total
);
766 if (i
!= bmap
->n_eq
- 1)
767 p
= isl_printer_print_str(p
, s_and
[latex
]);
768 p
= isl_printer_print_str(p
, "0 = 0");
772 p
= isl_printer_print_str(p
, s_and
[latex
]);
773 if (isl_int_is_neg(bmap
->eq
[i
][l
]))
774 isl_seq_cpy(c
->el
, bmap
->eq
[i
], 1 + total
);
776 isl_seq_neg(c
->el
, bmap
->eq
[i
], 1 + total
);
777 p
= print_eq_constraint(p
, space
, div
, c
->el
, l
, latex
);
780 for (i
= 0; i
< bmap
->n_ineq
; ++i
) {
782 int l
= isl_seq_last_non_zero(bmap
->ineq
[i
], 1 + total
);
788 if (!dump
&& l
>= o_div
&&
789 can_print_div_expr(p
, div
, l
- o_div
)) {
791 is_div
= isl_basic_map_is_div_constraint(bmap
,
792 bmap
->ineq
[i
], l
- o_div
);
799 p
= isl_printer_print_str(p
, s_and
[latex
]);
800 s
= isl_int_sgn(bmap
->ineq
[i
][l
]);
801 strict
= !rational
&& isl_int_is_negone(bmap
->ineq
[i
][0]);
803 isl_seq_cpy(c
->el
, bmap
->ineq
[i
], 1 + total
);
805 isl_seq_neg(c
->el
, bmap
->ineq
[i
], 1 + total
);
807 isl_int_set_si(c
->el
[0], 0);
808 combine
= dump
? isl_bool_false
: next_is_opposite(bmap
, i
, l
);
812 op
= constraint_op(-s
, strict
, latex
);
813 p
= print_half_constraint(p
, space
, div
, c
->el
, l
,
817 op
= constraint_op(s
, strict
, latex
);
818 p
= print_constraint(p
, space
, div
, c
->el
, l
,
824 isl_basic_map_free(bmap
);
829 isl_basic_map_free(bmap
);
835 static __isl_give isl_printer
*print_div(__isl_keep isl_space
*dim
,
836 __isl_keep isl_mat
*div
, int pos
, __isl_take isl_printer
*p
)
841 return isl_printer_free(p
);
843 c
= p
->output_format
== ISL_FORMAT_C
;
844 p
= isl_printer_print_str(p
, c
? "floord(" : "floor((");
845 p
= print_affine_of_len(dim
, div
, p
,
846 div
->row
[pos
] + 1, div
->n_col
- 1);
847 p
= isl_printer_print_str(p
, c
? ", " : ")/");
848 p
= isl_printer_print_isl_int(p
, div
->row
[pos
][0]);
849 p
= isl_printer_print_str(p
, ")");
853 /* Print a comma separated list of div names, except those that have
854 * a definition that can be printed.
855 * If "print_defined_divs" is set, then those div names are printed
856 * as well, along with their definitions.
858 static __isl_give isl_printer
*print_div_list(__isl_take isl_printer
*p
,
859 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int latex
,
860 int print_defined_divs
)
866 if (!p
|| !space
|| !div
)
867 return isl_printer_free(p
);
869 n_div
= isl_mat_rows(div
);
871 for (i
= 0; i
< n_div
; ++i
) {
872 if (!print_defined_divs
&& can_print_div_expr(p
, div
, i
))
875 p
= isl_printer_print_str(p
, ", ");
876 p
= print_name(space
, p
, isl_dim_div
, i
, latex
);
878 if (!can_print_div_expr(p
, div
, i
))
880 p
= isl_printer_print_str(p
, " = ");
881 p
= print_div(space
, div
, i
, p
);
887 /* Does printing an object with local variables described by "div"
888 * require an "exists" clause?
889 * That is, are there any local variables without an explicit representation?
890 * An exists clause is also needed in "dump" mode because
891 * explicit div representations are not printed inline in that case.
893 static isl_bool
need_exists(__isl_keep isl_printer
*p
, __isl_keep isl_mat
*div
)
898 return isl_bool_error
;
899 n
= isl_mat_rows(div
);
901 return isl_bool_false
;
903 return isl_bool_true
;
904 for (i
= 0; i
< n
; ++i
)
905 if (!can_print_div_expr(p
, div
, i
))
906 return isl_bool_true
;
907 return isl_bool_false
;
910 /* Print the start of an exists clause, i.e.,
914 * In dump mode, local variables with an explicit definition are printed
915 * as well because they will not be printed inline.
917 static __isl_give isl_printer
*open_exists(__isl_take isl_printer
*p
,
918 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int latex
)
926 p
= isl_printer_print_str(p
, s_open_exists
[latex
]);
927 p
= print_div_list(p
, space
, div
, latex
, dump
);
928 p
= isl_printer_print_str(p
, ": ");
933 /* Remove the explicit representations of all local variables in "div".
935 static __isl_give isl_mat
*mark_all_unknown(__isl_take isl_mat
*div
)
942 n_div
= isl_mat_rows(div
);
943 for (i
= 0; i
< n_div
; ++i
)
944 div
= isl_mat_set_element_si(div
, i
, 0, 0);
948 /* Print the constraints of "bmap" to "p".
949 * The names of the variables are taken from "space".
950 * "latex" is set if the constraints should be printed in LaTeX format.
951 * Do not print inline explicit div representations in "dump" mode.
953 static __isl_give isl_printer
*print_disjunct(__isl_keep isl_basic_map
*bmap
,
954 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
963 div
= isl_basic_map_get_divs(bmap
);
964 exists
= need_exists(p
, div
);
965 if (exists
>= 0 && exists
)
966 p
= open_exists(p
, space
, div
, latex
);
969 div
= mark_all_unknown(div
);
970 p
= print_constraints(bmap
, space
, div
, p
, latex
);
973 if (exists
>= 0 && exists
)
974 p
= isl_printer_print_str(p
, s_close_exists
[latex
]);
978 /* Print a colon followed by the constraints of "bmap"
979 * to "p", provided there are any constraints.
980 * The names of the variables are taken from "space".
981 * "latex" is set if the constraints should be printed in LaTeX format.
983 static __isl_give isl_printer
*print_optional_disjunct(
984 __isl_keep isl_basic_map
*bmap
, __isl_keep isl_space
*space
,
985 __isl_take isl_printer
*p
, int latex
)
987 if (isl_basic_map_plain_is_universe(bmap
))
990 p
= isl_printer_print_str(p
, ": ");
991 p
= print_disjunct(bmap
, space
, p
, latex
);
996 static __isl_give isl_printer
*basic_map_print_omega(
997 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
999 p
= isl_printer_print_str(p
, "{ [");
1000 p
= print_var_list(p
, bmap
->dim
, isl_dim_in
);
1001 p
= isl_printer_print_str(p
, "] -> [");
1002 p
= print_var_list(p
, bmap
->dim
, isl_dim_out
);
1003 p
= isl_printer_print_str(p
, "] ");
1004 p
= print_optional_disjunct(bmap
, bmap
->dim
, p
, 0);
1005 p
= isl_printer_print_str(p
, " }");
1009 static __isl_give isl_printer
*basic_set_print_omega(
1010 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
)
1012 p
= isl_printer_print_str(p
, "{ [");
1013 p
= print_var_list(p
, bset
->dim
, isl_dim_set
);
1014 p
= isl_printer_print_str(p
, "] ");
1015 p
= print_optional_disjunct(bset
, bset
->dim
, p
, 0);
1016 p
= isl_printer_print_str(p
, " }");
1020 static __isl_give isl_printer
*isl_map_print_omega(__isl_keep isl_map
*map
,
1021 __isl_take isl_printer
*p
)
1025 for (i
= 0; i
< map
->n
; ++i
) {
1027 p
= isl_printer_print_str(p
, " union ");
1028 p
= basic_map_print_omega(map
->p
[i
], p
);
1033 static __isl_give isl_printer
*isl_set_print_omega(__isl_keep isl_set
*set
,
1034 __isl_take isl_printer
*p
)
1038 for (i
= 0; i
< set
->n
; ++i
) {
1040 p
= isl_printer_print_str(p
, " union ");
1041 p
= basic_set_print_omega(set
->p
[i
], p
);
1046 /* Print the list of parameters in "space", followed by an arrow, to "p",
1047 * if there are any parameters.
1049 static __isl_give isl_printer
*print_param_tuple(__isl_take isl_printer
*p
,
1050 __isl_keep isl_space
*space
, struct isl_print_space_data
*data
)
1053 return isl_printer_free(p
);
1054 if (isl_space_dim(space
, isl_dim_param
) == 0)
1057 p
= print_tuple(space
, p
, isl_dim_param
, data
);
1058 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
1063 static __isl_give isl_printer
*isl_basic_map_print_isl(
1064 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
,
1067 struct isl_print_space_data data
= { .latex
= latex
};
1068 int rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
1070 p
= print_param_tuple(p
, bmap
->dim
, &data
);
1071 p
= isl_printer_print_str(p
, "{ ");
1072 p
= isl_print_space(bmap
->dim
, p
, rational
, &data
);
1073 p
= isl_printer_print_str(p
, " : ");
1074 p
= print_disjunct(bmap
, bmap
->dim
, p
, latex
);
1075 p
= isl_printer_print_str(p
, " }");
1079 /* Print the disjuncts of a map (or set) "map" to "p".
1080 * The names of the variables are taken from "space".
1081 * "latex" is set if the constraints should be printed in LaTeX format.
1083 static __isl_give isl_printer
*print_disjuncts_core(__isl_keep isl_map
*map
,
1084 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
1089 p
= isl_printer_print_str(p
, "false");
1090 for (i
= 0; i
< map
->n
; ++i
) {
1092 p
= isl_printer_print_str(p
, s_or
[latex
]);
1093 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
1094 p
= isl_printer_print_str(p
, "(");
1095 p
= print_disjunct(map
->p
[i
], space
, p
, latex
);
1096 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
1097 p
= isl_printer_print_str(p
, ")");
1102 /* Print the disjuncts of a map (or set) "map" to "p".
1103 * The names of the variables are taken from "space".
1104 * "hull" describes constraints shared by all disjuncts of "map".
1105 * "latex" is set if the constraints should be printed in LaTeX format.
1107 * Print the disjuncts as a conjunction of "hull" and
1108 * the result of removing the constraints of "hull" from "map".
1109 * If this result turns out to be the universe, then simply print "hull".
1111 static __isl_give isl_printer
*print_disjuncts_in_hull(__isl_keep isl_map
*map
,
1112 __isl_keep isl_space
*space
, __isl_take isl_basic_map
*hull
,
1113 __isl_take isl_printer
*p
, int latex
)
1115 isl_bool is_universe
;
1117 p
= print_disjunct(hull
, space
, p
, latex
);
1118 map
= isl_map_plain_gist_basic_map(isl_map_copy(map
), hull
);
1119 is_universe
= isl_map_plain_is_universe(map
);
1120 if (is_universe
< 0)
1123 p
= isl_printer_print_str(p
, s_and
[latex
]);
1124 p
= isl_printer_print_str(p
, "(");
1125 p
= print_disjuncts_core(map
, space
, p
, latex
);
1126 p
= isl_printer_print_str(p
, ")");
1133 isl_printer_free(p
);
1137 /* Print the disjuncts of a map (or set) "map" to "p".
1138 * The names of the variables are taken from "space".
1139 * "latex" is set if the constraints should be printed in LaTeX format.
1141 * If there are at least two disjuncts and "dump" mode is not turned out,
1142 * check for any shared constraints among all disjuncts.
1143 * If there are any, then print them separately in print_disjuncts_in_hull.
1145 static __isl_give isl_printer
*print_disjuncts(__isl_keep isl_map
*map
,
1146 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
1148 if (isl_map_plain_is_universe(map
))
1151 p
= isl_printer_print_str(p
, s_such_that
[latex
]);
1155 if (!p
->dump
&& map
->n
>= 2) {
1156 isl_basic_map
*hull
;
1157 isl_bool is_universe
;
1159 hull
= isl_map_plain_unshifted_simple_hull(isl_map_copy(map
));
1160 is_universe
= isl_basic_map_plain_is_universe(hull
);
1161 if (is_universe
< 0)
1162 p
= isl_printer_free(p
);
1163 else if (!is_universe
)
1164 return print_disjuncts_in_hull(map
, space
, hull
,
1166 isl_basic_map_free(hull
);
1169 return print_disjuncts_core(map
, space
, p
, latex
);
1172 /* Print the disjuncts of a map (or set).
1173 * The names of the variables are taken from "space".
1174 * "latex" is set if the constraints should be printed in LaTeX format.
1176 * If the map turns out to be a universal parameter domain, then
1177 * we need to print the colon. Otherwise, the output looks identical
1180 static __isl_give isl_printer
*print_disjuncts_map(__isl_keep isl_map
*map
,
1181 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
1183 if (isl_map_plain_is_universe(map
) && isl_space_is_params(map
->dim
))
1184 return isl_printer_print_str(p
, s_such_that
[latex
]);
1186 return print_disjuncts(map
, space
, p
, latex
);
1189 /* Print the disjuncts of a set.
1190 * The names of the variables are taken from "space".
1191 * "latex" is set if the constraints should be printed in LaTeX format.
1193 static __isl_give isl_printer
*print_disjuncts_set(__isl_keep isl_set
*set
,
1194 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
1196 return print_disjuncts_map(set_to_map(set
), space
, p
, latex
);
1199 struct isl_aff_split
{
1204 static void free_split(__isl_take
struct isl_aff_split
*split
, int n
)
1211 for (i
= 0; i
< n
; ++i
) {
1212 isl_basic_map_free(split
[i
].aff
);
1213 isl_map_free(split
[i
].map
);
1219 static __isl_give isl_basic_map
*get_aff(__isl_take isl_basic_map
*bmap
)
1222 unsigned nparam
, n_in
, n_out
, total
;
1224 bmap
= isl_basic_map_cow(bmap
);
1227 if (isl_basic_map_free_inequality(bmap
, bmap
->n_ineq
) < 0)
1230 nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
1231 n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
1232 n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
1233 total
= isl_basic_map_dim(bmap
, isl_dim_all
);
1234 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1235 j
= isl_seq_last_non_zero(bmap
->eq
[i
] + 1, total
);
1236 if (j
>= nparam
&& j
< nparam
+ n_in
+ n_out
&&
1237 (isl_int_is_one(bmap
->eq
[i
][1 + j
]) ||
1238 isl_int_is_negone(bmap
->eq
[i
][1 + j
])))
1240 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1244 bmap
= isl_basic_map_finalize(bmap
);
1248 isl_basic_map_free(bmap
);
1252 static int aff_split_cmp(const void *p1
, const void *p2
, void *user
)
1254 const struct isl_aff_split
*s1
, *s2
;
1255 s1
= (const struct isl_aff_split
*) p1
;
1256 s2
= (const struct isl_aff_split
*) p2
;
1258 return isl_basic_map_plain_cmp(s1
->aff
, s2
->aff
);
1261 static __isl_give isl_basic_map
*drop_aff(__isl_take isl_basic_map
*bmap
,
1262 __isl_keep isl_basic_map
*aff
)
1270 total
= isl_space_dim(bmap
->dim
, isl_dim_all
);
1272 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1273 if (isl_seq_first_non_zero(bmap
->eq
[i
] + 1 + total
,
1276 for (j
= 0; j
< aff
->n_eq
; ++j
) {
1277 if (!isl_seq_eq(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
) &&
1278 !isl_seq_is_neg(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
))
1280 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1288 isl_basic_map_free(bmap
);
1292 static __isl_give
struct isl_aff_split
*split_aff(__isl_keep isl_map
*map
)
1295 struct isl_aff_split
*split
;
1298 ctx
= isl_map_get_ctx(map
);
1299 split
= isl_calloc_array(ctx
, struct isl_aff_split
, map
->n
);
1303 for (i
= 0; i
< map
->n
; ++i
) {
1304 isl_basic_map
*bmap
;
1305 split
[i
].aff
= get_aff(isl_basic_map_copy(map
->p
[i
]));
1306 bmap
= isl_basic_map_copy(map
->p
[i
]);
1307 bmap
= isl_basic_map_cow(bmap
);
1308 bmap
= drop_aff(bmap
, split
[i
].aff
);
1309 split
[i
].map
= isl_map_from_basic_map(bmap
);
1310 if (!split
[i
].aff
|| !split
[i
].map
)
1314 if (isl_sort(split
, map
->n
, sizeof(struct isl_aff_split
),
1315 &aff_split_cmp
, NULL
) < 0)
1319 for (i
= n
- 1; i
>= 1; --i
) {
1320 if (!isl_basic_map_plain_is_equal(split
[i
- 1].aff
,
1323 isl_basic_map_free(split
[i
].aff
);
1324 split
[i
- 1].map
= isl_map_union(split
[i
- 1].map
,
1327 split
[i
] = split
[n
- 1];
1328 split
[n
- 1].aff
= NULL
;
1329 split
[n
- 1].map
= NULL
;
1335 free_split(split
, map
->n
);
1339 static int defining_equality(__isl_keep isl_basic_map
*eq
,
1340 __isl_keep isl_space
*dim
, enum isl_dim_type type
, int pos
)
1348 pos
+= isl_space_offset(dim
, type
);
1349 total
= isl_basic_map_total_dim(eq
);
1351 for (i
= 0; i
< eq
->n_eq
; ++i
) {
1352 if (isl_seq_last_non_zero(eq
->eq
[i
] + 1, total
) != pos
)
1354 if (isl_int_is_one(eq
->eq
[i
][1 + pos
]))
1355 isl_seq_neg(eq
->eq
[i
], eq
->eq
[i
], 1 + total
);
1362 /* Print dimension "pos" of data->space to "p".
1364 * data->user is assumed to be an isl_basic_map keeping track of equalities.
1366 * If the current dimension is defined by these equalities, then print
1367 * the corresponding expression, assigned to the name of the dimension
1368 * if there is any. Otherwise, print the name of the dimension.
1370 static __isl_give isl_printer
*print_dim_eq(__isl_take isl_printer
*p
,
1371 struct isl_print_space_data
*data
, unsigned pos
)
1373 isl_basic_map
*eq
= data
->user
;
1376 j
= defining_equality(eq
, data
->space
, data
->type
, pos
);
1378 if (isl_space_has_dim_name(data
->space
, data
->type
, pos
)) {
1379 p
= print_name(data
->space
, p
, data
->type
, pos
,
1381 p
= isl_printer_print_str(p
, " = ");
1383 pos
+= 1 + isl_space_offset(data
->space
, data
->type
);
1384 p
= print_affine_of_len(data
->space
, NULL
, p
, eq
->eq
[j
], pos
);
1386 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
1392 static __isl_give isl_printer
*print_split_map(__isl_take isl_printer
*p
,
1393 struct isl_aff_split
*split
, int n
, __isl_keep isl_space
*space
)
1395 struct isl_print_space_data data
= { 0 };
1399 data
.print_dim
= &print_dim_eq
;
1400 for (i
= 0; i
< n
; ++i
) {
1403 rational
= split
[i
].map
->n
> 0 &&
1404 ISL_F_ISSET(split
[i
].map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1406 p
= isl_printer_print_str(p
, "; ");
1407 data
.user
= split
[i
].aff
;
1408 p
= isl_print_space(space
, p
, rational
, &data
);
1409 p
= print_disjuncts_map(split
[i
].map
, space
, p
, 0);
1415 static __isl_give isl_printer
*isl_map_print_isl_body(__isl_keep isl_map
*map
,
1416 __isl_take isl_printer
*p
)
1418 struct isl_print_space_data data
= { 0 };
1419 struct isl_aff_split
*split
= NULL
;
1423 return isl_printer_free(p
);
1424 if (!p
->dump
&& map
->n
> 0)
1425 split
= split_aff(map
);
1427 p
= print_split_map(p
, split
, map
->n
, map
->dim
);
1429 rational
= map
->n
> 0 &&
1430 ISL_F_ISSET(map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1431 p
= isl_print_space(map
->dim
, p
, rational
, &data
);
1432 p
= print_disjuncts_map(map
, map
->dim
, p
, 0);
1434 free_split(split
, map
->n
);
1438 static __isl_give isl_printer
*isl_map_print_isl(__isl_keep isl_map
*map
,
1439 __isl_take isl_printer
*p
)
1441 struct isl_print_space_data data
= { 0 };
1443 p
= print_param_tuple(p
, map
->dim
, &data
);
1444 p
= isl_printer_print_str(p
, s_open_set
[0]);
1445 p
= isl_map_print_isl_body(map
, p
);
1446 p
= isl_printer_print_str(p
, s_close_set
[0]);
1450 static __isl_give isl_printer
*print_latex_map(__isl_keep isl_map
*map
,
1451 __isl_take isl_printer
*p
, __isl_keep isl_basic_map
*aff
)
1453 struct isl_print_space_data data
= { 0 };
1456 p
= print_param_tuple(p
, map
->dim
, &data
);
1457 p
= isl_printer_print_str(p
, s_open_set
[1]);
1458 data
.print_dim
= &print_dim_eq
;
1460 p
= isl_print_space(map
->dim
, p
, 0, &data
);
1461 p
= print_disjuncts_map(map
, map
->dim
, p
, 1);
1462 p
= isl_printer_print_str(p
, s_close_set
[1]);
1467 static __isl_give isl_printer
*isl_map_print_latex(__isl_keep isl_map
*map
,
1468 __isl_take isl_printer
*p
)
1471 struct isl_aff_split
*split
= NULL
;
1474 split
= split_aff(map
);
1477 return print_latex_map(map
, p
, NULL
);
1479 for (i
= 0; i
< map
->n
; ++i
) {
1483 p
= isl_printer_print_str(p
, " \\cup ");
1484 p
= print_latex_map(split
[i
].map
, p
, split
[i
].aff
);
1487 free_split(split
, map
->n
);
1491 __isl_give isl_printer
*isl_printer_print_basic_map(__isl_take isl_printer
*p
,
1492 __isl_keep isl_basic_map
*bmap
)
1496 if (p
->output_format
== ISL_FORMAT_ISL
)
1497 return isl_basic_map_print_isl(bmap
, p
, 0);
1498 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1499 return basic_map_print_omega(bmap
, p
);
1500 isl_assert(bmap
->ctx
, 0, goto error
);
1502 isl_printer_free(p
);
1506 __isl_give isl_printer
*isl_printer_print_basic_set(__isl_take isl_printer
*p
,
1507 __isl_keep isl_basic_set
*bset
)
1512 if (p
->output_format
== ISL_FORMAT_ISL
)
1513 return isl_basic_map_print_isl(bset
, p
, 0);
1514 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1515 return isl_basic_set_print_polylib(bset
, p
, 0);
1516 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1517 return isl_basic_set_print_polylib(bset
, p
, 1);
1518 else if (p
->output_format
== ISL_FORMAT_POLYLIB_CONSTRAINTS
)
1519 return bset_print_constraints_polylib(bset
, p
);
1520 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1521 return basic_set_print_omega(bset
, p
);
1522 isl_assert(p
->ctx
, 0, goto error
);
1524 isl_printer_free(p
);
1528 __isl_give isl_printer
*isl_printer_print_set(__isl_take isl_printer
*p
,
1529 __isl_keep isl_set
*set
)
1533 if (p
->output_format
== ISL_FORMAT_ISL
)
1534 return isl_map_print_isl(set_to_map(set
), p
);
1535 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1536 return isl_set_print_polylib(set
, p
, 0);
1537 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1538 return isl_set_print_polylib(set
, p
, 1);
1539 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1540 return isl_set_print_omega(set
, p
);
1541 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1542 return isl_map_print_latex(set_to_map(set
), p
);
1543 isl_assert(set
->ctx
, 0, goto error
);
1545 isl_printer_free(p
);
1549 __isl_give isl_printer
*isl_printer_print_map(__isl_take isl_printer
*p
,
1550 __isl_keep isl_map
*map
)
1555 if (p
->output_format
== ISL_FORMAT_ISL
)
1556 return isl_map_print_isl(map
, p
);
1557 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1558 return isl_map_print_polylib(map
, p
, 0);
1559 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1560 return isl_map_print_polylib(map
, p
, 1);
1561 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1562 return isl_map_print_omega(map
, p
);
1563 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1564 return isl_map_print_latex(map
, p
);
1565 isl_assert(map
->ctx
, 0, goto error
);
1567 isl_printer_free(p
);
1571 struct isl_union_print_data
{
1576 static isl_stat
print_map_body(__isl_take isl_map
*map
, void *user
)
1578 struct isl_union_print_data
*data
;
1579 data
= (struct isl_union_print_data
*)user
;
1582 data
->p
= isl_printer_print_str(data
->p
, "; ");
1585 data
->p
= isl_map_print_isl_body(map
, data
->p
);
1591 /* Print the body of "umap" (everything except the parameter declarations)
1592 * to "p" in isl format.
1594 static __isl_give isl_printer
*isl_printer_print_union_map_isl_body(
1595 __isl_take isl_printer
*p
, __isl_keep isl_union_map
*umap
)
1597 struct isl_union_print_data data
;
1599 p
= isl_printer_print_str(p
, s_open_set
[0]);
1602 isl_union_map_foreach_map(umap
, &print_map_body
, &data
);
1604 p
= isl_printer_print_str(p
, s_close_set
[0]);
1608 /* Print the body of "uset" (everything except the parameter declarations)
1609 * to "p" in isl format.
1611 static __isl_give isl_printer
*isl_printer_print_union_set_isl_body(
1612 __isl_take isl_printer
*p
, __isl_keep isl_union_set
*uset
)
1614 return isl_printer_print_union_map_isl_body(p
, uset_to_umap(uset
));
1617 /* Print the isl_union_map "umap" to "p" in isl format.
1619 static __isl_give isl_printer
*isl_union_map_print_isl(
1620 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1622 struct isl_print_space_data space_data
= { 0 };
1625 space
= isl_union_map_get_space(umap
);
1626 p
= print_param_tuple(p
, space
, &space_data
);
1627 isl_space_free(space
);
1629 p
= isl_printer_print_union_map_isl_body(p
, umap
);
1634 static isl_stat
print_latex_map_body(__isl_take isl_map
*map
, void *user
)
1636 struct isl_union_print_data
*data
;
1637 data
= (struct isl_union_print_data
*)user
;
1640 data
->p
= isl_printer_print_str(data
->p
, " \\cup ");
1643 data
->p
= isl_map_print_latex(map
, data
->p
);
1649 static __isl_give isl_printer
*isl_union_map_print_latex(
1650 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1652 struct isl_union_print_data data
= { p
, 1 };
1653 isl_union_map_foreach_map(umap
, &print_latex_map_body
, &data
);
1658 __isl_give isl_printer
*isl_printer_print_union_map(__isl_take isl_printer
*p
,
1659 __isl_keep isl_union_map
*umap
)
1664 if (p
->output_format
== ISL_FORMAT_ISL
)
1665 return isl_union_map_print_isl(umap
, p
);
1666 if (p
->output_format
== ISL_FORMAT_LATEX
)
1667 return isl_union_map_print_latex(umap
, p
);
1669 isl_die(p
->ctx
, isl_error_invalid
,
1670 "invalid output format for isl_union_map", goto error
);
1672 isl_printer_free(p
);
1676 __isl_give isl_printer
*isl_printer_print_union_set(__isl_take isl_printer
*p
,
1677 __isl_keep isl_union_set
*uset
)
1682 if (p
->output_format
== ISL_FORMAT_ISL
)
1683 return isl_union_map_print_isl(uset_to_umap(uset
), p
);
1684 if (p
->output_format
== ISL_FORMAT_LATEX
)
1685 return isl_union_map_print_latex(uset_to_umap(uset
), p
);
1687 isl_die(p
->ctx
, isl_error_invalid
,
1688 "invalid output format for isl_union_set", goto error
);
1690 isl_printer_free(p
);
1694 static int poly_rec_n_non_zero(__isl_keep isl_poly_rec
*rec
)
1702 for (i
= 0, n
= 0; i
< rec
->n
; ++i
) {
1703 isl_bool is_zero
= isl_poly_is_zero(rec
->p
[i
]);
1714 static __isl_give isl_printer
*poly_print_cst(__isl_keep isl_poly
*poly
,
1715 __isl_take isl_printer
*p
, int first
)
1720 cst
= isl_poly_as_cst(poly
);
1723 neg
= !first
&& isl_int_is_neg(cst
->n
);
1725 p
= isl_printer_print_str(p
, neg
? " - " : " + ");
1727 isl_int_neg(cst
->n
, cst
->n
);
1728 if (isl_int_is_zero(cst
->d
)) {
1729 int sgn
= isl_int_sgn(cst
->n
);
1730 p
= isl_printer_print_str(p
, sgn
< 0 ? "-infty" :
1731 sgn
== 0 ? "NaN" : "infty");
1733 p
= isl_printer_print_isl_int(p
, cst
->n
);
1735 isl_int_neg(cst
->n
, cst
->n
);
1736 if (!isl_int_is_zero(cst
->d
) && !isl_int_is_one(cst
->d
)) {
1737 p
= isl_printer_print_str(p
, "/");
1738 p
= isl_printer_print_isl_int(p
, cst
->d
);
1742 isl_printer_free(p
);
1746 static __isl_give isl_printer
*print_base(__isl_take isl_printer
*p
,
1747 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int var
)
1751 total
= isl_space_dim(space
, isl_dim_all
);
1753 p
= print_term(space
, NULL
, space
->ctx
->one
, 1 + var
, p
, 0);
1755 p
= print_div(space
, div
, var
- total
, p
);
1759 static __isl_give isl_printer
*print_pow(__isl_take isl_printer
*p
,
1760 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
, int exp
)
1762 p
= print_base(p
, dim
, div
, var
);
1765 if (p
->output_format
== ISL_FORMAT_C
) {
1767 for (i
= 1; i
< exp
; ++i
) {
1768 p
= isl_printer_print_str(p
, "*");
1769 p
= print_base(p
, dim
, div
, var
);
1772 p
= isl_printer_print_str(p
, "^");
1773 p
= isl_printer_print_int(p
, exp
);
1778 /* Print the polynomial "poly" defined over the domain space "space" and
1779 * local variables defined by "div" to "p".
1781 static __isl_give isl_printer
*poly_print(__isl_keep isl_poly
*poly
,
1782 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
1783 __isl_take isl_printer
*p
)
1785 int i
, n
, first
, print_parens
;
1789 is_cst
= isl_poly_is_cst(poly
);
1790 if (!p
|| is_cst
< 0 || !space
|| !div
)
1794 return poly_print_cst(poly
, p
, 1);
1796 rec
= isl_poly_as_rec(poly
);
1797 n
= poly_rec_n_non_zero(rec
);
1799 return isl_printer_free(p
);
1800 print_parens
= n
> 1;
1802 p
= isl_printer_print_str(p
, "(");
1803 for (i
= 0, first
= 1; i
< rec
->n
; ++i
) {
1804 isl_bool is_zero
= isl_poly_is_zero(rec
->p
[i
]);
1805 isl_bool is_one
= isl_poly_is_one(rec
->p
[i
]);
1806 isl_bool is_negone
= isl_poly_is_negone(rec
->p
[i
]);
1807 isl_bool is_cst
= isl_poly_is_cst(rec
->p
[i
]);
1809 if (is_zero
< 0 || is_one
< 0 || is_negone
< 0)
1810 return isl_printer_free(p
);
1815 p
= isl_printer_print_str(p
, "-1");
1817 p
= isl_printer_print_str(p
, "-");
1819 p
= isl_printer_print_str(p
, " - ");
1820 } else if (is_cst
&& !is_one
)
1821 p
= poly_print_cst(rec
->p
[i
], p
, first
);
1824 p
= isl_printer_print_str(p
, " + ");
1825 if (i
== 0 || !is_one
)
1826 p
= poly_print(rec
->p
[i
], space
, div
, p
);
1831 if (!is_one
&& !is_negone
)
1832 p
= isl_printer_print_str(p
, " * ");
1833 p
= print_pow(p
, space
, div
, rec
->poly
.var
, i
);
1836 p
= isl_printer_print_str(p
, ")");
1839 isl_printer_free(p
);
1843 static __isl_give isl_printer
*print_qpolynomial(__isl_take isl_printer
*p
,
1844 __isl_keep isl_qpolynomial
*qp
)
1848 p
= poly_print(qp
->poly
, qp
->dim
, qp
->div
, p
);
1851 isl_printer_free(p
);
1855 static __isl_give isl_printer
*print_qpolynomial_isl(__isl_take isl_printer
*p
,
1856 __isl_keep isl_qpolynomial
*qp
)
1858 struct isl_print_space_data data
= { 0 };
1863 p
= print_param_tuple(p
, qp
->dim
, &data
);
1864 p
= isl_printer_print_str(p
, "{ ");
1865 if (!isl_space_is_params(qp
->dim
)) {
1866 p
= isl_print_space(qp
->dim
, p
, 0, &data
);
1867 p
= isl_printer_print_str(p
, " -> ");
1869 p
= print_qpolynomial(p
, qp
);
1870 p
= isl_printer_print_str(p
, " }");
1873 isl_printer_free(p
);
1877 /* Print the quasi-polynomial "qp" to "p" in C format, with the variable names
1878 * taken from the domain space "space".
1880 static __isl_give isl_printer
*print_qpolynomial_c(__isl_take isl_printer
*p
,
1881 __isl_keep isl_space
*space
, __isl_keep isl_qpolynomial
*qp
)
1886 den
= isl_qpolynomial_get_den(qp
);
1887 qp
= isl_qpolynomial_copy(qp
);
1888 qp
= isl_qpolynomial_scale_val(qp
, isl_val_copy(den
));
1889 is_one
= isl_val_is_one(den
);
1891 p
= isl_printer_free(p
);
1893 p
= isl_printer_print_str(p
, "(");
1895 p
= poly_print(qp
->poly
, space
, qp
->div
, p
);
1897 p
= isl_printer_free(p
);
1899 p
= isl_printer_print_str(p
, ")/");
1900 p
= isl_printer_print_val(p
, den
);
1902 isl_qpolynomial_free(qp
);
1907 __isl_give isl_printer
*isl_printer_print_qpolynomial(
1908 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial
*qp
)
1913 if (p
->output_format
== ISL_FORMAT_ISL
)
1914 return print_qpolynomial_isl(p
, qp
);
1915 else if (p
->output_format
== ISL_FORMAT_C
)
1916 return print_qpolynomial_c(p
, qp
->dim
, qp
);
1918 isl_die(qp
->dim
->ctx
, isl_error_unsupported
,
1919 "output format not supported for isl_qpolynomials",
1922 isl_printer_free(p
);
1926 void isl_qpolynomial_print(__isl_keep isl_qpolynomial
*qp
, FILE *out
,
1927 unsigned output_format
)
1934 isl_assert(qp
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1935 p
= isl_printer_to_file(qp
->dim
->ctx
, out
);
1936 p
= isl_printer_print_qpolynomial(p
, qp
);
1937 isl_printer_free(p
);
1940 static __isl_give isl_printer
*qpolynomial_fold_print(
1941 __isl_keep isl_qpolynomial_fold
*fold
, __isl_take isl_printer
*p
)
1945 if (fold
->type
== isl_fold_min
)
1946 p
= isl_printer_print_str(p
, "min");
1947 else if (fold
->type
== isl_fold_max
)
1948 p
= isl_printer_print_str(p
, "max");
1949 p
= isl_printer_print_str(p
, "(");
1950 for (i
= 0; i
< fold
->n
; ++i
) {
1952 p
= isl_printer_print_str(p
, ", ");
1953 p
= print_qpolynomial(p
, fold
->qp
[i
]);
1955 p
= isl_printer_print_str(p
, ")");
1959 void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold
*fold
,
1960 FILE *out
, unsigned output_format
)
1967 isl_assert(fold
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1969 p
= isl_printer_to_file(fold
->dim
->ctx
, out
);
1970 p
= isl_printer_print_qpolynomial_fold(p
, fold
);
1972 isl_printer_free(p
);
1975 static __isl_give isl_printer
*isl_pwqp_print_isl_body(
1976 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1978 struct isl_print_space_data data
= { 0 };
1981 for (i
= 0; i
< pwqp
->n
; ++i
) {
1985 p
= isl_printer_print_str(p
, "; ");
1986 space
= isl_qpolynomial_get_domain_space(pwqp
->p
[i
].qp
);
1987 if (!isl_space_is_params(space
)) {
1988 p
= isl_print_space(space
, p
, 0, &data
);
1989 p
= isl_printer_print_str(p
, " -> ");
1991 p
= print_qpolynomial(p
, pwqp
->p
[i
].qp
);
1992 p
= print_disjuncts(set_to_map(pwqp
->p
[i
].set
), space
, p
, 0);
1993 isl_space_free(space
);
1999 static __isl_give isl_printer
*print_pw_qpolynomial_isl(
2000 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2002 struct isl_print_space_data data
= { 0 };
2007 p
= print_param_tuple(p
, pwqp
->dim
, &data
);
2008 p
= isl_printer_print_str(p
, "{ ");
2010 if (!isl_space_is_set(pwqp
->dim
)) {
2011 p
= print_tuple(pwqp
->dim
, p
, isl_dim_in
, &data
);
2012 p
= isl_printer_print_str(p
, " -> ");
2014 p
= isl_printer_print_str(p
, "0");
2016 p
= isl_pwqp_print_isl_body(p
, pwqp
);
2017 p
= isl_printer_print_str(p
, " }");
2020 isl_printer_free(p
);
2024 void isl_pw_qpolynomial_print(__isl_keep isl_pw_qpolynomial
*pwqp
, FILE *out
,
2025 unsigned output_format
)
2032 p
= isl_printer_to_file(pwqp
->dim
->ctx
, out
);
2033 p
= isl_printer_set_output_format(p
, output_format
);
2034 p
= isl_printer_print_pw_qpolynomial(p
, pwqp
);
2036 isl_printer_free(p
);
2039 static __isl_give isl_printer
*isl_pwf_print_isl_body(
2040 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2042 struct isl_print_space_data data
= { 0 };
2045 for (i
= 0; i
< pwf
->n
; ++i
) {
2049 p
= isl_printer_print_str(p
, "; ");
2050 space
= isl_qpolynomial_fold_get_domain_space(pwf
->p
[i
].fold
);
2051 if (!isl_space_is_params(space
)) {
2052 p
= isl_print_space(space
, p
, 0, &data
);
2053 p
= isl_printer_print_str(p
, " -> ");
2055 p
= qpolynomial_fold_print(pwf
->p
[i
].fold
, p
);
2056 p
= print_disjuncts(set_to_map(pwf
->p
[i
].set
), space
, p
, 0);
2057 isl_space_free(space
);
2063 static __isl_give isl_printer
*print_pw_qpolynomial_fold_isl(
2064 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2066 struct isl_print_space_data data
= { 0 };
2068 p
= print_param_tuple(p
, pwf
->dim
, &data
);
2069 p
= isl_printer_print_str(p
, "{ ");
2071 if (!isl_space_is_set(pwf
->dim
)) {
2072 p
= print_tuple(pwf
->dim
, p
, isl_dim_in
, &data
);
2073 p
= isl_printer_print_str(p
, " -> ");
2075 p
= isl_printer_print_str(p
, "0");
2077 p
= isl_pwf_print_isl_body(p
, pwf
);
2078 p
= isl_printer_print_str(p
, " }");
2082 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2083 __isl_keep isl_local_space
*ls
, isl_int
*c
);
2085 /* We skip the constraint if it is implied by the div expression.
2087 * *first indicates whether this is the first constraint in the conjunction and
2088 * is updated if the constraint is actually printed.
2090 static __isl_give isl_printer
*print_constraint_c(__isl_take isl_printer
*p
,
2091 __isl_keep isl_local_space
*ls
, isl_int
*c
, const char *op
, int *first
)
2097 o_div
= isl_local_space_offset(ls
, isl_dim_div
);
2098 n_div
= isl_local_space_dim(ls
, isl_dim_div
);
2099 div
= isl_seq_last_non_zero(c
+ o_div
, n_div
);
2101 isl_bool is_div
= isl_local_space_is_div_constraint(ls
, c
, div
);
2103 return isl_printer_free(p
);
2109 p
= isl_printer_print_str(p
, " && ");
2111 p
= print_ls_affine_c(p
, ls
, c
);
2112 p
= isl_printer_print_str(p
, " ");
2113 p
= isl_printer_print_str(p
, op
);
2114 p
= isl_printer_print_str(p
, " 0");
2121 static __isl_give isl_printer
*print_ls_partial_affine_c(
2122 __isl_take isl_printer
*p
, __isl_keep isl_local_space
*ls
,
2123 isl_int
*c
, unsigned len
);
2125 static __isl_give isl_printer
*print_basic_set_c(__isl_take isl_printer
*p
,
2126 __isl_keep isl_space
*space
, __isl_keep isl_basic_set
*bset
)
2130 unsigned n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
2131 unsigned total
= isl_basic_set_total_dim(bset
) - n_div
;
2133 isl_local_space
*ls
;
2135 div
= isl_basic_set_get_divs(bset
);
2136 ls
= isl_local_space_alloc_div(isl_space_copy(space
), div
);
2137 for (i
= 0; i
< bset
->n_eq
; ++i
) {
2138 j
= isl_seq_last_non_zero(bset
->eq
[i
] + 1 + total
, n_div
);
2140 p
= print_constraint_c(p
, ls
,
2141 bset
->eq
[i
], "==", &first
);
2144 p
= isl_printer_print_str(p
, " && ");
2145 p
= isl_printer_print_str(p
, "(");
2146 p
= print_ls_partial_affine_c(p
, ls
, bset
->eq
[i
],
2148 p
= isl_printer_print_str(p
, ") % ");
2149 p
= isl_printer_print_isl_int(p
,
2150 bset
->eq
[i
][1 + total
+ j
]);
2151 p
= isl_printer_print_str(p
, " == 0");
2155 for (i
= 0; i
< bset
->n_ineq
; ++i
)
2156 p
= print_constraint_c(p
, ls
, bset
->ineq
[i
], ">=", &first
);
2157 isl_local_space_free(ls
);
2161 static __isl_give isl_printer
*print_set_c(__isl_take isl_printer
*p
,
2162 __isl_keep isl_space
*space
, __isl_keep isl_set
*set
)
2167 return isl_printer_free(p
);
2170 p
= isl_printer_print_str(p
, "0");
2172 for (i
= 0; i
< set
->n
; ++i
) {
2174 p
= isl_printer_print_str(p
, " || ");
2176 p
= isl_printer_print_str(p
, "(");
2177 p
= print_basic_set_c(p
, space
, set
->p
[i
]);
2179 p
= isl_printer_print_str(p
, ")");
2184 /* Print the piecewise quasi-polynomial "pwqp" to "p" in C format.
2186 static __isl_give isl_printer
*print_pw_qpolynomial_c(
2187 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2192 space
= isl_pw_qpolynomial_get_domain_space(pwqp
);
2193 if (pwqp
->n
== 1 && isl_set_plain_is_universe(pwqp
->p
[0].set
)) {
2194 p
= print_qpolynomial_c(p
, space
, pwqp
->p
[0].qp
);
2195 isl_space_free(space
);
2199 for (i
= 0; i
< pwqp
->n
; ++i
) {
2200 p
= isl_printer_print_str(p
, "(");
2201 p
= print_set_c(p
, space
, pwqp
->p
[i
].set
);
2202 p
= isl_printer_print_str(p
, ") ? (");
2203 p
= print_qpolynomial_c(p
, space
, pwqp
->p
[i
].qp
);
2204 p
= isl_printer_print_str(p
, ") : ");
2207 isl_space_free(space
);
2208 p
= isl_printer_print_str(p
, "0");
2212 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial(
2213 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2218 if (p
->output_format
== ISL_FORMAT_ISL
)
2219 return print_pw_qpolynomial_isl(p
, pwqp
);
2220 else if (p
->output_format
== ISL_FORMAT_C
)
2221 return print_pw_qpolynomial_c(p
, pwqp
);
2222 isl_assert(p
->ctx
, 0, goto error
);
2224 isl_printer_free(p
);
2228 static isl_stat
print_pwqp_body(__isl_take isl_pw_qpolynomial
*pwqp
, void *user
)
2230 struct isl_union_print_data
*data
;
2231 data
= (struct isl_union_print_data
*)user
;
2234 data
->p
= isl_printer_print_str(data
->p
, "; ");
2237 data
->p
= isl_pwqp_print_isl_body(data
->p
, pwqp
);
2238 isl_pw_qpolynomial_free(pwqp
);
2243 static __isl_give isl_printer
*print_union_pw_qpolynomial_isl(
2244 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2246 struct isl_union_print_data data
;
2247 struct isl_print_space_data space_data
= { 0 };
2250 space
= isl_union_pw_qpolynomial_get_space(upwqp
);
2251 p
= print_param_tuple(p
, space
, &space_data
);
2252 isl_space_free(space
);
2253 p
= isl_printer_print_str(p
, "{ ");
2256 isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp
, &print_pwqp_body
,
2259 p
= isl_printer_print_str(p
, " }");
2263 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial(
2264 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2269 if (p
->output_format
== ISL_FORMAT_ISL
)
2270 return print_union_pw_qpolynomial_isl(p
, upwqp
);
2271 isl_die(p
->ctx
, isl_error_invalid
,
2272 "invalid output format for isl_union_pw_qpolynomial",
2275 isl_printer_free(p
);
2279 /* Print the quasi-polynomial reduction "fold" to "p" in C format,
2280 * with the variable names taken from the domain space "space".
2282 static __isl_give isl_printer
*print_qpolynomial_fold_c(
2283 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
,
2284 __isl_keep isl_qpolynomial_fold
*fold
)
2288 for (i
= 0; i
< fold
->n
- 1; ++i
)
2289 if (fold
->type
== isl_fold_min
)
2290 p
= isl_printer_print_str(p
, "min(");
2291 else if (fold
->type
== isl_fold_max
)
2292 p
= isl_printer_print_str(p
, "max(");
2294 for (i
= 0; i
< fold
->n
; ++i
) {
2296 p
= isl_printer_print_str(p
, ", ");
2297 p
= print_qpolynomial_c(p
, space
, fold
->qp
[i
]);
2299 p
= isl_printer_print_str(p
, ")");
2304 __isl_give isl_printer
*isl_printer_print_qpolynomial_fold(
2305 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial_fold
*fold
)
2309 if (p
->output_format
== ISL_FORMAT_ISL
)
2310 return qpolynomial_fold_print(fold
, p
);
2311 else if (p
->output_format
== ISL_FORMAT_C
)
2312 return print_qpolynomial_fold_c(p
, fold
->dim
, fold
);
2313 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2316 isl_printer_free(p
);
2320 /* Print the piecewise quasi-polynomial reduction "pwf" to "p" in C format.
2322 static __isl_give isl_printer
*print_pw_qpolynomial_fold_c(
2323 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2328 space
= isl_pw_qpolynomial_fold_get_domain_space(pwf
);
2329 if (pwf
->n
== 1 && isl_set_plain_is_universe(pwf
->p
[0].set
)) {
2330 p
= print_qpolynomial_fold_c(p
, space
, pwf
->p
[0].fold
);
2331 isl_space_free(space
);
2335 for (i
= 0; i
< pwf
->n
; ++i
) {
2336 p
= isl_printer_print_str(p
, "(");
2337 p
= print_set_c(p
, space
, pwf
->p
[i
].set
);
2338 p
= isl_printer_print_str(p
, ") ? (");
2339 p
= print_qpolynomial_fold_c(p
, space
, pwf
->p
[i
].fold
);
2340 p
= isl_printer_print_str(p
, ") : ");
2343 isl_space_free(space
);
2344 p
= isl_printer_print_str(p
, "0");
2348 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial_fold(
2349 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2354 if (p
->output_format
== ISL_FORMAT_ISL
)
2355 return print_pw_qpolynomial_fold_isl(p
, pwf
);
2356 else if (p
->output_format
== ISL_FORMAT_C
)
2357 return print_pw_qpolynomial_fold_c(p
, pwf
);
2358 isl_assert(p
->ctx
, 0, goto error
);
2360 isl_printer_free(p
);
2364 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold
*pwf
,
2365 FILE *out
, unsigned output_format
)
2372 p
= isl_printer_to_file(pwf
->dim
->ctx
, out
);
2373 p
= isl_printer_set_output_format(p
, output_format
);
2374 p
= isl_printer_print_pw_qpolynomial_fold(p
, pwf
);
2376 isl_printer_free(p
);
2379 static isl_stat
print_pwf_body(__isl_take isl_pw_qpolynomial_fold
*pwf
,
2382 struct isl_union_print_data
*data
;
2383 data
= (struct isl_union_print_data
*)user
;
2386 data
->p
= isl_printer_print_str(data
->p
, "; ");
2389 data
->p
= isl_pwf_print_isl_body(data
->p
, pwf
);
2390 isl_pw_qpolynomial_fold_free(pwf
);
2395 static __isl_give isl_printer
*print_union_pw_qpolynomial_fold_isl(
2396 __isl_take isl_printer
*p
,
2397 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2399 struct isl_union_print_data data
;
2400 struct isl_print_space_data space_data
= { 0 };
2403 space
= isl_union_pw_qpolynomial_fold_get_space(upwf
);
2404 p
= print_param_tuple(p
, space
, &space_data
);
2405 isl_space_free(space
);
2406 p
= isl_printer_print_str(p
, "{ ");
2409 isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(upwf
,
2410 &print_pwf_body
, &data
);
2412 p
= isl_printer_print_str(p
, " }");
2416 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial_fold(
2417 __isl_take isl_printer
*p
,
2418 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2423 if (p
->output_format
== ISL_FORMAT_ISL
)
2424 return print_union_pw_qpolynomial_fold_isl(p
, upwf
);
2425 isl_die(p
->ctx
, isl_error_invalid
,
2426 "invalid output format for isl_union_pw_qpolynomial_fold",
2429 isl_printer_free(p
);
2433 /* Print the isl_constraint "c" to "p".
2435 __isl_give isl_printer
*isl_printer_print_constraint(__isl_take isl_printer
*p
,
2436 __isl_keep isl_constraint
*c
)
2438 struct isl_print_space_data data
= { 0 };
2439 isl_local_space
*ls
;
2446 ls
= isl_constraint_get_local_space(c
);
2448 return isl_printer_free(p
);
2449 space
= isl_local_space_get_space(ls
);
2450 p
= print_param_tuple(p
, space
, &data
);
2451 p
= isl_printer_print_str(p
, "{ ");
2452 p
= isl_print_space(space
, p
, 0, &data
);
2453 p
= isl_printer_print_str(p
, " : ");
2454 exists
= need_exists(p
, ls
->div
);
2456 p
= isl_printer_free(p
);
2457 if (exists
>= 0 && exists
)
2458 p
= open_exists(p
, space
, ls
->div
, 0);
2459 p
= print_affine_of_len(space
, ls
->div
, p
, c
->v
->el
, c
->v
->size
);
2460 if (isl_constraint_is_equality(c
))
2461 p
= isl_printer_print_str(p
, " = 0");
2463 p
= isl_printer_print_str(p
, " >= 0");
2464 if (exists
>= 0 && exists
)
2465 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2466 p
= isl_printer_print_str(p
, " }");
2467 isl_space_free(space
);
2468 isl_local_space_free(ls
);
2472 isl_printer_free(p
);
2476 static __isl_give isl_printer
*isl_printer_print_space_isl(
2477 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
)
2479 struct isl_print_space_data data
= { 0 };
2484 p
= print_param_tuple(p
, space
, &data
);
2486 p
= isl_printer_print_str(p
, "{ ");
2487 if (isl_space_is_params(space
))
2488 p
= isl_printer_print_str(p
, s_such_that
[0]);
2490 p
= isl_print_space(space
, p
, 0, &data
);
2491 p
= isl_printer_print_str(p
, " }");
2495 isl_printer_free(p
);
2499 __isl_give isl_printer
*isl_printer_print_space(__isl_take isl_printer
*p
,
2500 __isl_keep isl_space
*space
)
2503 return isl_printer_free(p
);
2504 if (p
->output_format
== ISL_FORMAT_ISL
)
2505 return isl_printer_print_space_isl(p
, space
);
2506 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
2507 return print_omega_parameters(space
, p
);
2509 isl_die(isl_space_get_ctx(space
), isl_error_unsupported
,
2510 "output format not supported for space",
2511 return isl_printer_free(p
));
2514 __isl_give isl_printer
*isl_printer_print_local_space(__isl_take isl_printer
*p
,
2515 __isl_keep isl_local_space
*ls
)
2517 struct isl_print_space_data data
= { 0 };
2523 p
= print_param_tuple(p
, ls
->dim
, &data
);
2524 p
= isl_printer_print_str(p
, "{ ");
2525 p
= isl_print_space(ls
->dim
, p
, 0, &data
);
2526 n_div
= isl_local_space_dim(ls
, isl_dim_div
);
2528 p
= isl_printer_print_str(p
, " : ");
2529 p
= isl_printer_print_str(p
, s_open_exists
[0]);
2530 p
= print_div_list(p
, ls
->dim
, ls
->div
, 0, 1);
2531 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2532 } else if (isl_space_is_params(ls
->dim
))
2533 p
= isl_printer_print_str(p
, s_such_that
[0]);
2534 p
= isl_printer_print_str(p
, " }");
2537 isl_printer_free(p
);
2541 /* Print the (potentially rational) affine expression "aff" to "p",
2542 * with the variable names taken from "space".
2544 static __isl_give isl_printer
*print_aff_body(__isl_take isl_printer
*p
,
2545 __isl_keep isl_space
*space
, __isl_keep isl_aff
*aff
)
2549 if (isl_aff_is_nan(aff
))
2550 return isl_printer_print_str(p
, "NaN");
2552 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2553 p
= isl_printer_print_str(p
, "(");
2554 p
= print_affine_of_len(space
, aff
->ls
->div
, p
,
2555 aff
->v
->el
+ 1, 1 + total
);
2556 if (isl_int_is_one(aff
->v
->el
[0]))
2557 p
= isl_printer_print_str(p
, ")");
2559 p
= isl_printer_print_str(p
, ")/");
2560 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2566 static __isl_give isl_printer
*print_aff(__isl_take isl_printer
*p
,
2567 __isl_keep isl_aff
*aff
)
2569 struct isl_print_space_data data
= { 0 };
2571 if (isl_space_is_params(aff
->ls
->dim
))
2574 p
= print_tuple(aff
->ls
->dim
, p
, isl_dim_set
, &data
);
2575 p
= isl_printer_print_str(p
, " -> ");
2577 p
= isl_printer_print_str(p
, "[");
2578 p
= print_aff_body(p
, aff
->ls
->dim
, aff
);
2579 p
= isl_printer_print_str(p
, "]");
2584 static __isl_give isl_printer
*print_aff_isl(__isl_take isl_printer
*p
,
2585 __isl_keep isl_aff
*aff
)
2587 struct isl_print_space_data data
= { 0 };
2592 p
= print_param_tuple(p
, aff
->ls
->dim
, &data
);
2593 p
= isl_printer_print_str(p
, "{ ");
2594 p
= print_aff(p
, aff
);
2595 p
= isl_printer_print_str(p
, " }");
2598 isl_printer_free(p
);
2602 /* Print the body of an isl_pw_aff, i.e., a semicolon delimited
2603 * sequence of affine expressions, each followed by constraints.
2605 static __isl_give isl_printer
*print_pw_aff_body(
2606 __isl_take isl_printer
*p
, __isl_keep isl_pw_aff
*pa
)
2611 return isl_printer_free(p
);
2613 for (i
= 0; i
< pa
->n
; ++i
) {
2617 p
= isl_printer_print_str(p
, "; ");
2618 p
= print_aff(p
, pa
->p
[i
].aff
);
2619 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
2620 p
= print_disjuncts(set_to_map(pa
->p
[i
].set
), space
, p
, 0);
2621 isl_space_free(space
);
2627 static __isl_give isl_printer
*print_pw_aff_isl(__isl_take isl_printer
*p
,
2628 __isl_keep isl_pw_aff
*pwaff
)
2630 struct isl_print_space_data data
= { 0 };
2635 p
= print_param_tuple(p
, pwaff
->dim
, &data
);
2636 p
= isl_printer_print_str(p
, "{ ");
2637 p
= print_pw_aff_body(p
, pwaff
);
2638 p
= isl_printer_print_str(p
, " }");
2641 isl_printer_free(p
);
2645 static __isl_give isl_printer
*print_ls_name_c(__isl_take isl_printer
*p
,
2646 __isl_keep isl_local_space
*ls
, enum isl_dim_type type
, unsigned pos
)
2648 if (type
== isl_dim_div
) {
2649 p
= isl_printer_print_str(p
, "floord(");
2650 p
= print_ls_affine_c(p
, ls
, ls
->div
->row
[pos
] + 1);
2651 p
= isl_printer_print_str(p
, ", ");
2652 p
= isl_printer_print_isl_int(p
, ls
->div
->row
[pos
][0]);
2653 p
= isl_printer_print_str(p
, ")");
2657 name
= isl_space_get_dim_name(ls
->dim
, type
, pos
);
2660 p
= isl_printer_print_str(p
, name
);
2665 static __isl_give isl_printer
*print_ls_term_c(__isl_take isl_printer
*p
,
2666 __isl_keep isl_local_space
*ls
, isl_int c
, unsigned pos
)
2668 enum isl_dim_type type
;
2671 return isl_printer_free(p
);
2674 return isl_printer_print_isl_int(p
, c
);
2676 if (isl_int_is_one(c
))
2678 else if (isl_int_is_negone(c
))
2679 p
= isl_printer_print_str(p
, "-");
2681 p
= isl_printer_print_isl_int(p
, c
);
2682 p
= isl_printer_print_str(p
, "*");
2684 if (pos2type(ls
->dim
, &type
, &pos
) < 0)
2685 return isl_printer_free(p
);
2686 p
= print_ls_name_c(p
, ls
, type
, pos
);
2690 static __isl_give isl_printer
*print_ls_partial_affine_c(
2691 __isl_take isl_printer
*p
, __isl_keep isl_local_space
*ls
,
2692 isl_int
*c
, unsigned len
)
2697 for (i
= 0, first
= 1; i
< len
; ++i
) {
2699 if (isl_int_is_zero(c
[i
]))
2702 if (isl_int_is_neg(c
[i
])) {
2704 isl_int_neg(c
[i
], c
[i
]);
2705 p
= isl_printer_print_str(p
, " - ");
2707 p
= isl_printer_print_str(p
, " + ");
2710 p
= print_ls_term_c(p
, ls
, c
[i
], i
);
2712 isl_int_neg(c
[i
], c
[i
]);
2715 p
= isl_printer_print_str(p
, "0");
2719 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2720 __isl_keep isl_local_space
*ls
, isl_int
*c
)
2722 unsigned len
= 1 + isl_local_space_dim(ls
, isl_dim_all
);
2723 return print_ls_partial_affine_c(p
, ls
, c
, len
);
2726 static __isl_give isl_printer
*print_aff_c(__isl_take isl_printer
*p
,
2727 __isl_keep isl_aff
*aff
)
2731 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2732 if (!isl_int_is_one(aff
->v
->el
[0]))
2733 p
= isl_printer_print_str(p
, "(");
2734 p
= print_ls_partial_affine_c(p
, aff
->ls
, aff
->v
->el
+ 1, 1 + total
);
2735 if (!isl_int_is_one(aff
->v
->el
[0])) {
2736 p
= isl_printer_print_str(p
, ")/");
2737 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2742 /* In the C format, we cannot express that "pwaff" may be undefined
2743 * on parts of the domain space. We therefore assume that the expression
2744 * will only be evaluated on its definition domain and compute the gist
2745 * of each cell with respect to this domain.
2747 static __isl_give isl_printer
*print_pw_aff_c(__isl_take isl_printer
*p
,
2748 __isl_keep isl_pw_aff
*pwaff
)
2751 isl_ast_build
*build
;
2755 isl_die(p
->ctx
, isl_error_unsupported
,
2756 "cannot print empty isl_pw_aff in C format",
2757 return isl_printer_free(p
));
2759 domain
= isl_pw_aff_domain(isl_pw_aff_copy(pwaff
));
2760 build
= isl_ast_build_from_context(domain
);
2761 expr
= isl_ast_build_expr_from_pw_aff(build
, isl_pw_aff_copy(pwaff
));
2762 p
= isl_printer_print_ast_expr(p
, expr
);
2763 isl_ast_expr_free(expr
);
2764 isl_ast_build_free(build
);
2769 __isl_give isl_printer
*isl_printer_print_aff(__isl_take isl_printer
*p
,
2770 __isl_keep isl_aff
*aff
)
2775 if (p
->output_format
== ISL_FORMAT_ISL
)
2776 return print_aff_isl(p
, aff
);
2777 else if (p
->output_format
== ISL_FORMAT_C
)
2778 return print_aff_c(p
, aff
);
2779 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2782 isl_printer_free(p
);
2786 __isl_give isl_printer
*isl_printer_print_pw_aff(__isl_take isl_printer
*p
,
2787 __isl_keep isl_pw_aff
*pwaff
)
2792 if (p
->output_format
== ISL_FORMAT_ISL
)
2793 return print_pw_aff_isl(p
, pwaff
);
2794 else if (p
->output_format
== ISL_FORMAT_C
)
2795 return print_pw_aff_c(p
, pwaff
);
2796 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2799 isl_printer_free(p
);
2803 /* Print "pa" in a sequence of isl_pw_affs delimited by semicolons.
2804 * Each isl_pw_aff itself is also printed as semicolon delimited
2805 * sequence of pieces.
2806 * If data->first = 1, then this is the first in the sequence.
2807 * Update data->first to tell the next element that it is not the first.
2809 static isl_stat
print_pw_aff_body_wrap(__isl_take isl_pw_aff
*pa
,
2812 struct isl_union_print_data
*data
;
2813 data
= (struct isl_union_print_data
*) user
;
2816 data
->p
= isl_printer_print_str(data
->p
, "; ");
2819 data
->p
= print_pw_aff_body(data
->p
, pa
);
2820 isl_pw_aff_free(pa
);
2822 return data
->p
? isl_stat_ok
: isl_stat_error
;
2825 /* Print the body of an isl_union_pw_aff, i.e., a semicolon delimited
2826 * sequence of affine expressions, each followed by constraints,
2827 * with the sequence enclosed in braces.
2829 static __isl_give isl_printer
*print_union_pw_aff_body(
2830 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2832 struct isl_union_print_data data
= { p
, 1 };
2834 p
= isl_printer_print_str(p
, s_open_set
[0]);
2836 if (isl_union_pw_aff_foreach_pw_aff(upa
,
2837 &print_pw_aff_body_wrap
, &data
) < 0)
2838 data
.p
= isl_printer_free(p
);
2840 p
= isl_printer_print_str(p
, s_close_set
[0]);
2845 /* Print the isl_union_pw_aff "upa" to "p" in isl format.
2847 * The individual isl_pw_affs are delimited by a semicolon.
2849 static __isl_give isl_printer
*print_union_pw_aff_isl(
2850 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2852 struct isl_print_space_data data
= { 0 };
2855 space
= isl_union_pw_aff_get_space(upa
);
2856 p
= print_param_tuple(p
, space
, &data
);
2857 isl_space_free(space
);
2858 p
= print_union_pw_aff_body(p
, upa
);
2862 /* Print the isl_union_pw_aff "upa" to "p".
2864 * We currently only support an isl format.
2866 __isl_give isl_printer
*isl_printer_print_union_pw_aff(
2867 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2870 return isl_printer_free(p
);
2872 if (p
->output_format
== ISL_FORMAT_ISL
)
2873 return print_union_pw_aff_isl(p
, upa
);
2874 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
2875 "unsupported output format", return isl_printer_free(p
));
2878 /* Print dimension "pos" of data->space to "p".
2880 * data->user is assumed to be an isl_multi_aff.
2882 * If the current dimension is an output dimension, then print
2883 * the corresponding expression. Otherwise, print the name of the dimension.
2885 static __isl_give isl_printer
*print_dim_ma(__isl_take isl_printer
*p
,
2886 struct isl_print_space_data
*data
, unsigned pos
)
2888 isl_multi_aff
*ma
= data
->user
;
2890 if (data
->type
== isl_dim_out
) {
2893 space
= isl_multi_aff_get_domain_space(ma
);
2894 p
= print_aff_body(p
, space
, ma
->u
.p
[pos
]);
2895 isl_space_free(space
);
2897 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2903 static __isl_give isl_printer
*print_multi_aff(__isl_take isl_printer
*p
,
2904 __isl_keep isl_multi_aff
*maff
)
2906 struct isl_print_space_data data
= { 0 };
2908 data
.print_dim
= &print_dim_ma
;
2910 return isl_print_space(maff
->space
, p
, 0, &data
);
2913 static __isl_give isl_printer
*print_multi_aff_isl(__isl_take isl_printer
*p
,
2914 __isl_keep isl_multi_aff
*maff
)
2916 struct isl_print_space_data data
= { 0 };
2921 p
= print_param_tuple(p
, maff
->space
, &data
);
2922 p
= isl_printer_print_str(p
, "{ ");
2923 p
= print_multi_aff(p
, maff
);
2924 p
= isl_printer_print_str(p
, " }");
2927 isl_printer_free(p
);
2931 __isl_give isl_printer
*isl_printer_print_multi_aff(__isl_take isl_printer
*p
,
2932 __isl_keep isl_multi_aff
*maff
)
2937 if (p
->output_format
== ISL_FORMAT_ISL
)
2938 return print_multi_aff_isl(p
, maff
);
2939 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2942 isl_printer_free(p
);
2946 static __isl_give isl_printer
*print_pw_multi_aff_body(
2947 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2954 for (i
= 0; i
< pma
->n
; ++i
) {
2958 p
= isl_printer_print_str(p
, "; ");
2959 p
= print_multi_aff(p
, pma
->p
[i
].maff
);
2960 space
= isl_multi_aff_get_domain_space(pma
->p
[i
].maff
);
2961 p
= print_disjuncts(set_to_map(pma
->p
[i
].set
), space
, p
, 0);
2962 isl_space_free(space
);
2966 isl_printer_free(p
);
2970 static __isl_give isl_printer
*print_pw_multi_aff_isl(__isl_take isl_printer
*p
,
2971 __isl_keep isl_pw_multi_aff
*pma
)
2973 struct isl_print_space_data data
= { 0 };
2978 p
= print_param_tuple(p
, pma
->dim
, &data
);
2979 p
= isl_printer_print_str(p
, "{ ");
2980 p
= print_pw_multi_aff_body(p
, pma
);
2981 p
= isl_printer_print_str(p
, " }");
2984 isl_printer_free(p
);
2988 /* Print the unnamed, single-dimensional piecewise multi affine expression "pma"
2991 static __isl_give isl_printer
*print_unnamed_pw_multi_aff_c(
2992 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2997 space
= isl_pw_multi_aff_get_domain_space(pma
);
2998 for (i
= 0; i
< pma
->n
- 1; ++i
) {
2999 p
= isl_printer_print_str(p
, "(");
3000 p
= print_set_c(p
, space
, pma
->p
[i
].set
);
3001 p
= isl_printer_print_str(p
, ") ? (");
3002 p
= print_aff_c(p
, pma
->p
[i
].maff
->u
.p
[0]);
3003 p
= isl_printer_print_str(p
, ") : ");
3005 isl_space_free(space
);
3007 return print_aff_c(p
, pma
->p
[pma
->n
- 1].maff
->u
.p
[0]);
3010 static __isl_give isl_printer
*print_pw_multi_aff_c(__isl_take isl_printer
*p
,
3011 __isl_keep isl_pw_multi_aff
*pma
)
3019 isl_die(p
->ctx
, isl_error_unsupported
,
3020 "cannot print empty isl_pw_multi_aff in C format",
3022 name
= isl_pw_multi_aff_get_tuple_name(pma
, isl_dim_out
);
3023 if (!name
&& isl_pw_multi_aff_dim(pma
, isl_dim_out
) == 1)
3024 return print_unnamed_pw_multi_aff_c(p
, pma
);
3026 isl_die(p
->ctx
, isl_error_unsupported
,
3027 "cannot print unnamed isl_pw_multi_aff in C format",
3030 p
= isl_printer_print_str(p
, name
);
3031 n
= isl_pw_multi_aff_dim(pma
, isl_dim_out
);
3033 isl_die(p
->ctx
, isl_error_unsupported
,
3034 "not supported yet", goto error
);
3038 isl_printer_free(p
);
3042 __isl_give isl_printer
*isl_printer_print_pw_multi_aff(
3043 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
3048 if (p
->output_format
== ISL_FORMAT_ISL
)
3049 return print_pw_multi_aff_isl(p
, pma
);
3050 if (p
->output_format
== ISL_FORMAT_C
)
3051 return print_pw_multi_aff_c(p
, pma
);
3052 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3055 isl_printer_free(p
);
3059 static isl_stat
print_pw_multi_aff_body_wrap(__isl_take isl_pw_multi_aff
*pma
,
3062 struct isl_union_print_data
*data
;
3063 data
= (struct isl_union_print_data
*) user
;
3066 data
->p
= isl_printer_print_str(data
->p
, "; ");
3069 data
->p
= print_pw_multi_aff_body(data
->p
, pma
);
3070 isl_pw_multi_aff_free(pma
);
3075 static __isl_give isl_printer
*print_union_pw_multi_aff_isl(
3076 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
3078 struct isl_union_print_data data
;
3079 struct isl_print_space_data space_data
= { 0 };
3082 space
= isl_union_pw_multi_aff_get_space(upma
);
3083 p
= print_param_tuple(p
, space
, &space_data
);
3084 isl_space_free(space
);
3085 p
= isl_printer_print_str(p
, s_open_set
[0]);
3088 isl_union_pw_multi_aff_foreach_pw_multi_aff(upma
,
3089 &print_pw_multi_aff_body_wrap
, &data
);
3091 p
= isl_printer_print_str(p
, s_close_set
[0]);
3095 __isl_give isl_printer
*isl_printer_print_union_pw_multi_aff(
3096 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
3101 if (p
->output_format
== ISL_FORMAT_ISL
)
3102 return print_union_pw_multi_aff_isl(p
, upma
);
3103 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3106 isl_printer_free(p
);
3110 /* Print dimension "pos" of data->space to "p".
3112 * data->user is assumed to be an isl_multi_pw_aff.
3114 * If the current dimension is an output dimension, then print
3115 * the corresponding piecewise affine expression.
3116 * Otherwise, print the name of the dimension.
3118 static __isl_give isl_printer
*print_dim_mpa(__isl_take isl_printer
*p
,
3119 struct isl_print_space_data
*data
, unsigned pos
)
3124 isl_multi_pw_aff
*mpa
= data
->user
;
3127 if (data
->type
!= isl_dim_out
)
3128 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
3132 return isl_printer_print_str(p
, "(0 : false)");
3134 need_parens
= pa
->n
!= 1 || !isl_set_plain_is_universe(pa
->p
[0].set
);
3136 p
= isl_printer_print_str(p
, "(");
3137 space
= isl_multi_pw_aff_get_domain_space(mpa
);
3138 for (i
= 0; i
< pa
->n
; ++i
) {
3141 p
= isl_printer_print_str(p
, "; ");
3142 p
= print_aff_body(p
, space
, pa
->p
[i
].aff
);
3143 p
= print_disjuncts(pa
->p
[i
].set
, space
, p
, 0);
3145 isl_space_free(space
);
3147 p
= isl_printer_print_str(p
, ")");
3152 /* Print "mpa" to "p" in isl format.
3154 * If "mpa" is zero-dimensional and has a non-trivial explicit domain,
3155 * then it is printed after the tuple of affine expressions.
3157 static __isl_give isl_printer
*print_multi_pw_aff_isl(__isl_take isl_printer
*p
,
3158 __isl_keep isl_multi_pw_aff
*mpa
)
3160 struct isl_print_space_data data
= { 0 };
3161 isl_bool has_domain
;
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 has_domain
= isl_multi_pw_aff_has_non_trivial_domain(mpa
);
3173 return isl_printer_free(p
);
3177 space
= isl_space_domain(isl_space_copy(mpa
->space
));
3178 p
= print_disjuncts_set(mpa
->u
.dom
, space
, p
, 0);
3179 isl_space_free(space
);
3181 p
= isl_printer_print_str(p
, " }");
3185 __isl_give isl_printer
*isl_printer_print_multi_pw_aff(
3186 __isl_take isl_printer
*p
, __isl_keep isl_multi_pw_aff
*mpa
)
3189 return isl_printer_free(p
);
3191 if (p
->output_format
== ISL_FORMAT_ISL
)
3192 return print_multi_pw_aff_isl(p
, mpa
);
3193 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3194 return isl_printer_free(p
));
3197 /* Print dimension "pos" of data->space to "p".
3199 * data->user is assumed to be an isl_multi_val.
3201 * If the current dimension is an output dimension, then print
3202 * the corresponding value. Otherwise, print the name of the dimension.
3204 static __isl_give isl_printer
*print_dim_mv(__isl_take isl_printer
*p
,
3205 struct isl_print_space_data
*data
, unsigned pos
)
3207 isl_multi_val
*mv
= data
->user
;
3209 if (data
->type
== isl_dim_out
)
3210 return isl_printer_print_val(p
, mv
->u
.p
[pos
]);
3212 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
3215 /* Print the isl_multi_val "mv" to "p" in isl format.
3217 static __isl_give isl_printer
*print_multi_val_isl(__isl_take isl_printer
*p
,
3218 __isl_keep isl_multi_val
*mv
)
3220 struct isl_print_space_data data
= { 0 };
3223 return isl_printer_free(p
);
3225 p
= print_param_tuple(p
, mv
->space
, &data
);
3226 p
= isl_printer_print_str(p
, "{ ");
3227 data
.print_dim
= &print_dim_mv
;
3229 p
= isl_print_space(mv
->space
, p
, 0, &data
);
3230 p
= isl_printer_print_str(p
, " }");
3234 /* Print the isl_multi_val "mv" to "p".
3236 * Currently only supported in isl format.
3238 __isl_give isl_printer
*isl_printer_print_multi_val(
3239 __isl_take isl_printer
*p
, __isl_keep isl_multi_val
*mv
)
3242 return isl_printer_free(p
);
3244 if (p
->output_format
== ISL_FORMAT_ISL
)
3245 return print_multi_val_isl(p
, mv
);
3246 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3247 return isl_printer_free(p
));
3250 /* Print dimension "pos" of data->space to "p".
3252 * data->user is assumed to be an isl_multi_union_pw_aff.
3254 * The current dimension is necessarily a set dimension, so
3255 * we print the corresponding isl_union_pw_aff, including
3258 static __isl_give isl_printer
*print_union_pw_aff_dim(__isl_take isl_printer
*p
,
3259 struct isl_print_space_data
*data
, unsigned pos
)
3261 isl_multi_union_pw_aff
*mupa
= data
->user
;
3262 isl_union_pw_aff
*upa
;
3264 upa
= isl_multi_union_pw_aff_get_union_pw_aff(mupa
, pos
);
3265 p
= print_union_pw_aff_body(p
, upa
);
3266 isl_union_pw_aff_free(upa
);
3271 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3273 * If "mupa" is zero-dimensional and has a non-trivial explicit domain,
3274 * then it is printed after the tuple of affine expressions.
3275 * In order to clarify that this domain belongs to the expression,
3276 * the tuple along with the domain are placed inside parentheses.
3277 * If "mupa" has any parameters, then the opening parenthesis
3278 * appears after the parameter declarations.
3280 static __isl_give isl_printer
*print_multi_union_pw_aff_isl(
3281 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3283 struct isl_print_space_data data
= { 0 };
3284 isl_bool has_domain
;
3288 return isl_printer_free(p
);
3289 has_domain
= isl_multi_union_pw_aff_has_non_trivial_domain(mupa
);
3291 return isl_printer_free(p
);
3293 space
= isl_multi_union_pw_aff_get_space(mupa
);
3294 p
= print_param_tuple(p
, space
, &data
);
3297 p
= isl_printer_print_str(p
, "(");
3299 data
.print_dim
= &print_union_pw_aff_dim
;
3302 p
= isl_print_space(space
, p
, 0, &data
);
3303 isl_space_free(space
);
3306 p
= isl_printer_print_str(p
, " : ");
3307 p
= isl_printer_print_union_set_isl_body(p
, mupa
->u
.dom
);
3308 p
= isl_printer_print_str(p
, ")");
3314 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3316 * We currently only support an isl format.
3318 __isl_give isl_printer
*isl_printer_print_multi_union_pw_aff(
3319 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3322 return isl_printer_free(p
);
3324 if (p
->output_format
== ISL_FORMAT_ISL
)
3325 return print_multi_union_pw_aff_isl(p
, mupa
);
3326 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
3327 "unsupported output format", return isl_printer_free(p
));