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
)
1267 v_div
= isl_basic_map_var_offset(bmap
, isl_dim_div
);
1268 if (v_div
< 0 || !aff
)
1271 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1272 if (isl_seq_first_non_zero(bmap
->eq
[i
] + 1 + v_div
,
1275 for (j
= 0; j
< aff
->n_eq
; ++j
) {
1276 if (!isl_seq_eq(bmap
->eq
[i
], aff
->eq
[j
], 1 + v_div
) &&
1277 !isl_seq_is_neg(bmap
->eq
[i
], aff
->eq
[j
], 1 + v_div
))
1279 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1287 isl_basic_map_free(bmap
);
1291 static __isl_give
struct isl_aff_split
*split_aff(__isl_keep isl_map
*map
)
1294 struct isl_aff_split
*split
;
1297 ctx
= isl_map_get_ctx(map
);
1298 split
= isl_calloc_array(ctx
, struct isl_aff_split
, map
->n
);
1302 for (i
= 0; i
< map
->n
; ++i
) {
1303 isl_basic_map
*bmap
;
1304 split
[i
].aff
= get_aff(isl_basic_map_copy(map
->p
[i
]));
1305 bmap
= isl_basic_map_copy(map
->p
[i
]);
1306 bmap
= isl_basic_map_cow(bmap
);
1307 bmap
= drop_aff(bmap
, split
[i
].aff
);
1308 split
[i
].map
= isl_map_from_basic_map(bmap
);
1309 if (!split
[i
].aff
|| !split
[i
].map
)
1313 if (isl_sort(split
, map
->n
, sizeof(struct isl_aff_split
),
1314 &aff_split_cmp
, NULL
) < 0)
1318 for (i
= n
- 1; i
>= 1; --i
) {
1319 if (!isl_basic_map_plain_is_equal(split
[i
- 1].aff
,
1322 isl_basic_map_free(split
[i
].aff
);
1323 split
[i
- 1].map
= isl_map_union(split
[i
- 1].map
,
1326 split
[i
] = split
[n
- 1];
1327 split
[n
- 1].aff
= NULL
;
1328 split
[n
- 1].map
= NULL
;
1334 free_split(split
, map
->n
);
1338 static int defining_equality(__isl_keep isl_basic_map
*eq
,
1339 __isl_keep isl_space
*dim
, enum isl_dim_type type
, int pos
)
1347 pos
+= isl_space_offset(dim
, type
);
1348 total
= isl_basic_map_total_dim(eq
);
1350 for (i
= 0; i
< eq
->n_eq
; ++i
) {
1351 if (isl_seq_last_non_zero(eq
->eq
[i
] + 1, total
) != pos
)
1353 if (isl_int_is_one(eq
->eq
[i
][1 + pos
]))
1354 isl_seq_neg(eq
->eq
[i
], eq
->eq
[i
], 1 + total
);
1361 /* Print dimension "pos" of data->space to "p".
1363 * data->user is assumed to be an isl_basic_map keeping track of equalities.
1365 * If the current dimension is defined by these equalities, then print
1366 * the corresponding expression, assigned to the name of the dimension
1367 * if there is any. Otherwise, print the name of the dimension.
1369 static __isl_give isl_printer
*print_dim_eq(__isl_take isl_printer
*p
,
1370 struct isl_print_space_data
*data
, unsigned pos
)
1372 isl_basic_map
*eq
= data
->user
;
1375 j
= defining_equality(eq
, data
->space
, data
->type
, pos
);
1377 if (isl_space_has_dim_name(data
->space
, data
->type
, pos
)) {
1378 p
= print_name(data
->space
, p
, data
->type
, pos
,
1380 p
= isl_printer_print_str(p
, " = ");
1382 pos
+= 1 + isl_space_offset(data
->space
, data
->type
);
1383 p
= print_affine_of_len(data
->space
, NULL
, p
, eq
->eq
[j
], pos
);
1385 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
1391 static __isl_give isl_printer
*print_split_map(__isl_take isl_printer
*p
,
1392 struct isl_aff_split
*split
, int n
, __isl_keep isl_space
*space
)
1394 struct isl_print_space_data data
= { 0 };
1398 data
.print_dim
= &print_dim_eq
;
1399 for (i
= 0; i
< n
; ++i
) {
1402 rational
= split
[i
].map
->n
> 0 &&
1403 ISL_F_ISSET(split
[i
].map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1405 p
= isl_printer_print_str(p
, "; ");
1406 data
.user
= split
[i
].aff
;
1407 p
= isl_print_space(space
, p
, rational
, &data
);
1408 p
= print_disjuncts_map(split
[i
].map
, space
, p
, 0);
1414 static __isl_give isl_printer
*isl_map_print_isl_body(__isl_keep isl_map
*map
,
1415 __isl_take isl_printer
*p
)
1417 struct isl_print_space_data data
= { 0 };
1418 struct isl_aff_split
*split
= NULL
;
1422 return isl_printer_free(p
);
1423 if (!p
->dump
&& map
->n
> 0)
1424 split
= split_aff(map
);
1426 p
= print_split_map(p
, split
, map
->n
, map
->dim
);
1428 rational
= map
->n
> 0 &&
1429 ISL_F_ISSET(map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1430 p
= isl_print_space(map
->dim
, p
, rational
, &data
);
1431 p
= print_disjuncts_map(map
, map
->dim
, p
, 0);
1433 free_split(split
, map
->n
);
1437 static __isl_give isl_printer
*isl_map_print_isl(__isl_keep isl_map
*map
,
1438 __isl_take isl_printer
*p
)
1440 struct isl_print_space_data data
= { 0 };
1442 p
= print_param_tuple(p
, map
->dim
, &data
);
1443 p
= isl_printer_print_str(p
, s_open_set
[0]);
1444 p
= isl_map_print_isl_body(map
, p
);
1445 p
= isl_printer_print_str(p
, s_close_set
[0]);
1449 static __isl_give isl_printer
*print_latex_map(__isl_keep isl_map
*map
,
1450 __isl_take isl_printer
*p
, __isl_keep isl_basic_map
*aff
)
1452 struct isl_print_space_data data
= { 0 };
1455 p
= print_param_tuple(p
, map
->dim
, &data
);
1456 p
= isl_printer_print_str(p
, s_open_set
[1]);
1457 data
.print_dim
= &print_dim_eq
;
1459 p
= isl_print_space(map
->dim
, p
, 0, &data
);
1460 p
= print_disjuncts_map(map
, map
->dim
, p
, 1);
1461 p
= isl_printer_print_str(p
, s_close_set
[1]);
1466 static __isl_give isl_printer
*isl_map_print_latex(__isl_keep isl_map
*map
,
1467 __isl_take isl_printer
*p
)
1470 struct isl_aff_split
*split
= NULL
;
1473 split
= split_aff(map
);
1476 return print_latex_map(map
, p
, NULL
);
1478 for (i
= 0; i
< map
->n
; ++i
) {
1482 p
= isl_printer_print_str(p
, " \\cup ");
1483 p
= print_latex_map(split
[i
].map
, p
, split
[i
].aff
);
1486 free_split(split
, map
->n
);
1490 __isl_give isl_printer
*isl_printer_print_basic_map(__isl_take isl_printer
*p
,
1491 __isl_keep isl_basic_map
*bmap
)
1495 if (p
->output_format
== ISL_FORMAT_ISL
)
1496 return isl_basic_map_print_isl(bmap
, p
, 0);
1497 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1498 return basic_map_print_omega(bmap
, p
);
1499 isl_assert(bmap
->ctx
, 0, goto error
);
1501 isl_printer_free(p
);
1505 __isl_give isl_printer
*isl_printer_print_basic_set(__isl_take isl_printer
*p
,
1506 __isl_keep isl_basic_set
*bset
)
1511 if (p
->output_format
== ISL_FORMAT_ISL
)
1512 return isl_basic_map_print_isl(bset
, p
, 0);
1513 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1514 return isl_basic_set_print_polylib(bset
, p
, 0);
1515 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1516 return isl_basic_set_print_polylib(bset
, p
, 1);
1517 else if (p
->output_format
== ISL_FORMAT_POLYLIB_CONSTRAINTS
)
1518 return bset_print_constraints_polylib(bset
, p
);
1519 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1520 return basic_set_print_omega(bset
, p
);
1521 isl_assert(p
->ctx
, 0, goto error
);
1523 isl_printer_free(p
);
1527 __isl_give isl_printer
*isl_printer_print_set(__isl_take isl_printer
*p
,
1528 __isl_keep isl_set
*set
)
1532 if (p
->output_format
== ISL_FORMAT_ISL
)
1533 return isl_map_print_isl(set_to_map(set
), p
);
1534 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1535 return isl_set_print_polylib(set
, p
, 0);
1536 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1537 return isl_set_print_polylib(set
, p
, 1);
1538 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1539 return isl_set_print_omega(set
, p
);
1540 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1541 return isl_map_print_latex(set_to_map(set
), p
);
1542 isl_assert(set
->ctx
, 0, goto error
);
1544 isl_printer_free(p
);
1548 __isl_give isl_printer
*isl_printer_print_map(__isl_take isl_printer
*p
,
1549 __isl_keep isl_map
*map
)
1554 if (p
->output_format
== ISL_FORMAT_ISL
)
1555 return isl_map_print_isl(map
, p
);
1556 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1557 return isl_map_print_polylib(map
, p
, 0);
1558 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1559 return isl_map_print_polylib(map
, p
, 1);
1560 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1561 return isl_map_print_omega(map
, p
);
1562 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1563 return isl_map_print_latex(map
, p
);
1564 isl_assert(map
->ctx
, 0, goto error
);
1566 isl_printer_free(p
);
1570 struct isl_union_print_data
{
1575 static isl_stat
print_map_body(__isl_take isl_map
*map
, void *user
)
1577 struct isl_union_print_data
*data
;
1578 data
= (struct isl_union_print_data
*)user
;
1581 data
->p
= isl_printer_print_str(data
->p
, "; ");
1584 data
->p
= isl_map_print_isl_body(map
, data
->p
);
1590 /* Print the body of "umap" (everything except the parameter declarations)
1591 * to "p" in isl format.
1593 static __isl_give isl_printer
*isl_printer_print_union_map_isl_body(
1594 __isl_take isl_printer
*p
, __isl_keep isl_union_map
*umap
)
1596 struct isl_union_print_data data
;
1598 p
= isl_printer_print_str(p
, s_open_set
[0]);
1601 isl_union_map_foreach_map(umap
, &print_map_body
, &data
);
1603 p
= isl_printer_print_str(p
, s_close_set
[0]);
1607 /* Print the body of "uset" (everything except the parameter declarations)
1608 * to "p" in isl format.
1610 static __isl_give isl_printer
*isl_printer_print_union_set_isl_body(
1611 __isl_take isl_printer
*p
, __isl_keep isl_union_set
*uset
)
1613 return isl_printer_print_union_map_isl_body(p
, uset_to_umap(uset
));
1616 /* Print the isl_union_map "umap" to "p" in isl format.
1618 static __isl_give isl_printer
*isl_union_map_print_isl(
1619 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1621 struct isl_print_space_data space_data
= { 0 };
1624 space
= isl_union_map_get_space(umap
);
1625 p
= print_param_tuple(p
, space
, &space_data
);
1626 isl_space_free(space
);
1628 p
= isl_printer_print_union_map_isl_body(p
, umap
);
1633 static isl_stat
print_latex_map_body(__isl_take isl_map
*map
, void *user
)
1635 struct isl_union_print_data
*data
;
1636 data
= (struct isl_union_print_data
*)user
;
1639 data
->p
= isl_printer_print_str(data
->p
, " \\cup ");
1642 data
->p
= isl_map_print_latex(map
, data
->p
);
1648 static __isl_give isl_printer
*isl_union_map_print_latex(
1649 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1651 struct isl_union_print_data data
= { p
, 1 };
1652 isl_union_map_foreach_map(umap
, &print_latex_map_body
, &data
);
1657 __isl_give isl_printer
*isl_printer_print_union_map(__isl_take isl_printer
*p
,
1658 __isl_keep isl_union_map
*umap
)
1663 if (p
->output_format
== ISL_FORMAT_ISL
)
1664 return isl_union_map_print_isl(umap
, p
);
1665 if (p
->output_format
== ISL_FORMAT_LATEX
)
1666 return isl_union_map_print_latex(umap
, p
);
1668 isl_die(p
->ctx
, isl_error_invalid
,
1669 "invalid output format for isl_union_map", goto error
);
1671 isl_printer_free(p
);
1675 __isl_give isl_printer
*isl_printer_print_union_set(__isl_take isl_printer
*p
,
1676 __isl_keep isl_union_set
*uset
)
1681 if (p
->output_format
== ISL_FORMAT_ISL
)
1682 return isl_union_map_print_isl(uset_to_umap(uset
), p
);
1683 if (p
->output_format
== ISL_FORMAT_LATEX
)
1684 return isl_union_map_print_latex(uset_to_umap(uset
), p
);
1686 isl_die(p
->ctx
, isl_error_invalid
,
1687 "invalid output format for isl_union_set", goto error
);
1689 isl_printer_free(p
);
1693 static int poly_rec_n_non_zero(__isl_keep isl_poly_rec
*rec
)
1701 for (i
= 0, n
= 0; i
< rec
->n
; ++i
) {
1702 isl_bool is_zero
= isl_poly_is_zero(rec
->p
[i
]);
1713 static __isl_give isl_printer
*poly_print_cst(__isl_keep isl_poly
*poly
,
1714 __isl_take isl_printer
*p
, int first
)
1719 cst
= isl_poly_as_cst(poly
);
1722 neg
= !first
&& isl_int_is_neg(cst
->n
);
1724 p
= isl_printer_print_str(p
, neg
? " - " : " + ");
1726 isl_int_neg(cst
->n
, cst
->n
);
1727 if (isl_int_is_zero(cst
->d
)) {
1728 int sgn
= isl_int_sgn(cst
->n
);
1729 p
= isl_printer_print_str(p
, sgn
< 0 ? "-infty" :
1730 sgn
== 0 ? "NaN" : "infty");
1732 p
= isl_printer_print_isl_int(p
, cst
->n
);
1734 isl_int_neg(cst
->n
, cst
->n
);
1735 if (!isl_int_is_zero(cst
->d
) && !isl_int_is_one(cst
->d
)) {
1736 p
= isl_printer_print_str(p
, "/");
1737 p
= isl_printer_print_isl_int(p
, cst
->d
);
1741 isl_printer_free(p
);
1745 static __isl_give isl_printer
*print_base(__isl_take isl_printer
*p
,
1746 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int var
)
1750 total
= isl_space_dim(space
, isl_dim_all
);
1752 p
= print_term(space
, NULL
, space
->ctx
->one
, 1 + var
, p
, 0);
1754 p
= print_div(space
, div
, var
- total
, p
);
1758 static __isl_give isl_printer
*print_pow(__isl_take isl_printer
*p
,
1759 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
, int exp
)
1761 p
= print_base(p
, dim
, div
, var
);
1764 if (p
->output_format
== ISL_FORMAT_C
) {
1766 for (i
= 1; i
< exp
; ++i
) {
1767 p
= isl_printer_print_str(p
, "*");
1768 p
= print_base(p
, dim
, div
, var
);
1771 p
= isl_printer_print_str(p
, "^");
1772 p
= isl_printer_print_int(p
, exp
);
1777 /* Print the polynomial "poly" defined over the domain space "space" and
1778 * local variables defined by "div" to "p".
1780 static __isl_give isl_printer
*poly_print(__isl_keep isl_poly
*poly
,
1781 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
1782 __isl_take isl_printer
*p
)
1784 int i
, n
, first
, print_parens
;
1788 is_cst
= isl_poly_is_cst(poly
);
1789 if (!p
|| is_cst
< 0 || !space
|| !div
)
1793 return poly_print_cst(poly
, p
, 1);
1795 rec
= isl_poly_as_rec(poly
);
1796 n
= poly_rec_n_non_zero(rec
);
1798 return isl_printer_free(p
);
1799 print_parens
= n
> 1;
1801 p
= isl_printer_print_str(p
, "(");
1802 for (i
= 0, first
= 1; i
< rec
->n
; ++i
) {
1803 isl_bool is_zero
= isl_poly_is_zero(rec
->p
[i
]);
1804 isl_bool is_one
= isl_poly_is_one(rec
->p
[i
]);
1805 isl_bool is_negone
= isl_poly_is_negone(rec
->p
[i
]);
1806 isl_bool is_cst
= isl_poly_is_cst(rec
->p
[i
]);
1808 if (is_zero
< 0 || is_one
< 0 || is_negone
< 0)
1809 return isl_printer_free(p
);
1814 p
= isl_printer_print_str(p
, "-1");
1816 p
= isl_printer_print_str(p
, "-");
1818 p
= isl_printer_print_str(p
, " - ");
1819 } else if (is_cst
&& !is_one
)
1820 p
= poly_print_cst(rec
->p
[i
], p
, first
);
1823 p
= isl_printer_print_str(p
, " + ");
1824 if (i
== 0 || !is_one
)
1825 p
= poly_print(rec
->p
[i
], space
, div
, p
);
1830 if (!is_one
&& !is_negone
)
1831 p
= isl_printer_print_str(p
, " * ");
1832 p
= print_pow(p
, space
, div
, rec
->poly
.var
, i
);
1835 p
= isl_printer_print_str(p
, ")");
1838 isl_printer_free(p
);
1842 static __isl_give isl_printer
*print_qpolynomial(__isl_take isl_printer
*p
,
1843 __isl_keep isl_qpolynomial
*qp
)
1847 p
= poly_print(qp
->poly
, qp
->dim
, qp
->div
, p
);
1850 isl_printer_free(p
);
1854 static __isl_give isl_printer
*print_qpolynomial_isl(__isl_take isl_printer
*p
,
1855 __isl_keep isl_qpolynomial
*qp
)
1857 struct isl_print_space_data data
= { 0 };
1862 p
= print_param_tuple(p
, qp
->dim
, &data
);
1863 p
= isl_printer_print_str(p
, "{ ");
1864 if (!isl_space_is_params(qp
->dim
)) {
1865 p
= isl_print_space(qp
->dim
, p
, 0, &data
);
1866 p
= isl_printer_print_str(p
, " -> ");
1868 p
= print_qpolynomial(p
, qp
);
1869 p
= isl_printer_print_str(p
, " }");
1872 isl_printer_free(p
);
1876 /* Print the quasi-polynomial "qp" to "p" in C format, with the variable names
1877 * taken from the domain space "space".
1879 static __isl_give isl_printer
*print_qpolynomial_c(__isl_take isl_printer
*p
,
1880 __isl_keep isl_space
*space
, __isl_keep isl_qpolynomial
*qp
)
1885 den
= isl_qpolynomial_get_den(qp
);
1886 qp
= isl_qpolynomial_copy(qp
);
1887 qp
= isl_qpolynomial_scale_val(qp
, isl_val_copy(den
));
1888 is_one
= isl_val_is_one(den
);
1890 p
= isl_printer_free(p
);
1892 p
= isl_printer_print_str(p
, "(");
1894 p
= poly_print(qp
->poly
, space
, qp
->div
, p
);
1896 p
= isl_printer_free(p
);
1898 p
= isl_printer_print_str(p
, ")/");
1899 p
= isl_printer_print_val(p
, den
);
1901 isl_qpolynomial_free(qp
);
1906 __isl_give isl_printer
*isl_printer_print_qpolynomial(
1907 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial
*qp
)
1912 if (p
->output_format
== ISL_FORMAT_ISL
)
1913 return print_qpolynomial_isl(p
, qp
);
1914 else if (p
->output_format
== ISL_FORMAT_C
)
1915 return print_qpolynomial_c(p
, qp
->dim
, qp
);
1917 isl_die(qp
->dim
->ctx
, isl_error_unsupported
,
1918 "output format not supported for isl_qpolynomials",
1921 isl_printer_free(p
);
1925 void isl_qpolynomial_print(__isl_keep isl_qpolynomial
*qp
, FILE *out
,
1926 unsigned output_format
)
1933 isl_assert(qp
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1934 p
= isl_printer_to_file(qp
->dim
->ctx
, out
);
1935 p
= isl_printer_print_qpolynomial(p
, qp
);
1936 isl_printer_free(p
);
1939 static __isl_give isl_printer
*qpolynomial_fold_print(
1940 __isl_keep isl_qpolynomial_fold
*fold
, __isl_take isl_printer
*p
)
1944 if (fold
->type
== isl_fold_min
)
1945 p
= isl_printer_print_str(p
, "min");
1946 else if (fold
->type
== isl_fold_max
)
1947 p
= isl_printer_print_str(p
, "max");
1948 p
= isl_printer_print_str(p
, "(");
1949 for (i
= 0; i
< fold
->n
; ++i
) {
1951 p
= isl_printer_print_str(p
, ", ");
1952 p
= print_qpolynomial(p
, fold
->qp
[i
]);
1954 p
= isl_printer_print_str(p
, ")");
1958 void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold
*fold
,
1959 FILE *out
, unsigned output_format
)
1966 isl_assert(fold
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1968 p
= isl_printer_to_file(fold
->dim
->ctx
, out
);
1969 p
= isl_printer_print_qpolynomial_fold(p
, fold
);
1971 isl_printer_free(p
);
1974 static __isl_give isl_printer
*isl_pwqp_print_isl_body(
1975 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1977 struct isl_print_space_data data
= { 0 };
1980 for (i
= 0; i
< pwqp
->n
; ++i
) {
1984 p
= isl_printer_print_str(p
, "; ");
1985 space
= isl_qpolynomial_get_domain_space(pwqp
->p
[i
].qp
);
1986 if (!isl_space_is_params(space
)) {
1987 p
= isl_print_space(space
, p
, 0, &data
);
1988 p
= isl_printer_print_str(p
, " -> ");
1990 p
= print_qpolynomial(p
, pwqp
->p
[i
].qp
);
1991 p
= print_disjuncts(set_to_map(pwqp
->p
[i
].set
), space
, p
, 0);
1992 isl_space_free(space
);
1998 static __isl_give isl_printer
*print_pw_qpolynomial_isl(
1999 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2001 struct isl_print_space_data data
= { 0 };
2006 p
= print_param_tuple(p
, pwqp
->dim
, &data
);
2007 p
= isl_printer_print_str(p
, "{ ");
2009 if (!isl_space_is_set(pwqp
->dim
)) {
2010 p
= print_tuple(pwqp
->dim
, p
, isl_dim_in
, &data
);
2011 p
= isl_printer_print_str(p
, " -> ");
2013 p
= isl_printer_print_str(p
, "0");
2015 p
= isl_pwqp_print_isl_body(p
, pwqp
);
2016 p
= isl_printer_print_str(p
, " }");
2019 isl_printer_free(p
);
2023 void isl_pw_qpolynomial_print(__isl_keep isl_pw_qpolynomial
*pwqp
, FILE *out
,
2024 unsigned output_format
)
2031 p
= isl_printer_to_file(pwqp
->dim
->ctx
, out
);
2032 p
= isl_printer_set_output_format(p
, output_format
);
2033 p
= isl_printer_print_pw_qpolynomial(p
, pwqp
);
2035 isl_printer_free(p
);
2038 static __isl_give isl_printer
*isl_pwf_print_isl_body(
2039 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2041 struct isl_print_space_data data
= { 0 };
2044 for (i
= 0; i
< pwf
->n
; ++i
) {
2048 p
= isl_printer_print_str(p
, "; ");
2049 space
= isl_qpolynomial_fold_get_domain_space(pwf
->p
[i
].fold
);
2050 if (!isl_space_is_params(space
)) {
2051 p
= isl_print_space(space
, p
, 0, &data
);
2052 p
= isl_printer_print_str(p
, " -> ");
2054 p
= qpolynomial_fold_print(pwf
->p
[i
].fold
, p
);
2055 p
= print_disjuncts(set_to_map(pwf
->p
[i
].set
), space
, p
, 0);
2056 isl_space_free(space
);
2062 static __isl_give isl_printer
*print_pw_qpolynomial_fold_isl(
2063 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2065 struct isl_print_space_data data
= { 0 };
2067 p
= print_param_tuple(p
, pwf
->dim
, &data
);
2068 p
= isl_printer_print_str(p
, "{ ");
2070 if (!isl_space_is_set(pwf
->dim
)) {
2071 p
= print_tuple(pwf
->dim
, p
, isl_dim_in
, &data
);
2072 p
= isl_printer_print_str(p
, " -> ");
2074 p
= isl_printer_print_str(p
, "0");
2076 p
= isl_pwf_print_isl_body(p
, pwf
);
2077 p
= isl_printer_print_str(p
, " }");
2081 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2082 __isl_keep isl_local_space
*ls
, isl_int
*c
);
2084 /* We skip the constraint if it is implied by the div expression.
2086 * *first indicates whether this is the first constraint in the conjunction and
2087 * is updated if the constraint is actually printed.
2089 static __isl_give isl_printer
*print_constraint_c(__isl_take isl_printer
*p
,
2090 __isl_keep isl_local_space
*ls
, isl_int
*c
, const char *op
, int *first
)
2096 o_div
= isl_local_space_offset(ls
, isl_dim_div
);
2097 n_div
= isl_local_space_dim(ls
, isl_dim_div
);
2098 div
= isl_seq_last_non_zero(c
+ o_div
, n_div
);
2100 isl_bool is_div
= isl_local_space_is_div_constraint(ls
, c
, div
);
2102 return isl_printer_free(p
);
2108 p
= isl_printer_print_str(p
, " && ");
2110 p
= print_ls_affine_c(p
, ls
, c
);
2111 p
= isl_printer_print_str(p
, " ");
2112 p
= isl_printer_print_str(p
, op
);
2113 p
= isl_printer_print_str(p
, " 0");
2120 static __isl_give isl_printer
*print_ls_partial_affine_c(
2121 __isl_take isl_printer
*p
, __isl_keep isl_local_space
*ls
,
2122 isl_int
*c
, unsigned len
);
2124 static __isl_give isl_printer
*print_basic_set_c(__isl_take isl_printer
*p
,
2125 __isl_keep isl_space
*space
, __isl_keep isl_basic_set
*bset
)
2129 unsigned n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
2130 unsigned total
= isl_basic_set_total_dim(bset
) - n_div
;
2132 isl_local_space
*ls
;
2134 div
= isl_basic_set_get_divs(bset
);
2135 ls
= isl_local_space_alloc_div(isl_space_copy(space
), div
);
2136 for (i
= 0; i
< bset
->n_eq
; ++i
) {
2137 j
= isl_seq_last_non_zero(bset
->eq
[i
] + 1 + total
, n_div
);
2139 p
= print_constraint_c(p
, ls
,
2140 bset
->eq
[i
], "==", &first
);
2143 p
= isl_printer_print_str(p
, " && ");
2144 p
= isl_printer_print_str(p
, "(");
2145 p
= print_ls_partial_affine_c(p
, ls
, bset
->eq
[i
],
2147 p
= isl_printer_print_str(p
, ") % ");
2148 p
= isl_printer_print_isl_int(p
,
2149 bset
->eq
[i
][1 + total
+ j
]);
2150 p
= isl_printer_print_str(p
, " == 0");
2154 for (i
= 0; i
< bset
->n_ineq
; ++i
)
2155 p
= print_constraint_c(p
, ls
, bset
->ineq
[i
], ">=", &first
);
2156 isl_local_space_free(ls
);
2160 static __isl_give isl_printer
*print_set_c(__isl_take isl_printer
*p
,
2161 __isl_keep isl_space
*space
, __isl_keep isl_set
*set
)
2166 return isl_printer_free(p
);
2169 p
= isl_printer_print_str(p
, "0");
2171 for (i
= 0; i
< set
->n
; ++i
) {
2173 p
= isl_printer_print_str(p
, " || ");
2175 p
= isl_printer_print_str(p
, "(");
2176 p
= print_basic_set_c(p
, space
, set
->p
[i
]);
2178 p
= isl_printer_print_str(p
, ")");
2183 /* Print the piecewise quasi-polynomial "pwqp" to "p" in C format.
2185 static __isl_give isl_printer
*print_pw_qpolynomial_c(
2186 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2191 space
= isl_pw_qpolynomial_get_domain_space(pwqp
);
2192 if (pwqp
->n
== 1 && isl_set_plain_is_universe(pwqp
->p
[0].set
)) {
2193 p
= print_qpolynomial_c(p
, space
, pwqp
->p
[0].qp
);
2194 isl_space_free(space
);
2198 for (i
= 0; i
< pwqp
->n
; ++i
) {
2199 p
= isl_printer_print_str(p
, "(");
2200 p
= print_set_c(p
, space
, pwqp
->p
[i
].set
);
2201 p
= isl_printer_print_str(p
, ") ? (");
2202 p
= print_qpolynomial_c(p
, space
, pwqp
->p
[i
].qp
);
2203 p
= isl_printer_print_str(p
, ") : ");
2206 isl_space_free(space
);
2207 p
= isl_printer_print_str(p
, "0");
2211 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial(
2212 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2217 if (p
->output_format
== ISL_FORMAT_ISL
)
2218 return print_pw_qpolynomial_isl(p
, pwqp
);
2219 else if (p
->output_format
== ISL_FORMAT_C
)
2220 return print_pw_qpolynomial_c(p
, pwqp
);
2221 isl_assert(p
->ctx
, 0, goto error
);
2223 isl_printer_free(p
);
2227 static isl_stat
print_pwqp_body(__isl_take isl_pw_qpolynomial
*pwqp
, void *user
)
2229 struct isl_union_print_data
*data
;
2230 data
= (struct isl_union_print_data
*)user
;
2233 data
->p
= isl_printer_print_str(data
->p
, "; ");
2236 data
->p
= isl_pwqp_print_isl_body(data
->p
, pwqp
);
2237 isl_pw_qpolynomial_free(pwqp
);
2242 static __isl_give isl_printer
*print_union_pw_qpolynomial_isl(
2243 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2245 struct isl_union_print_data data
;
2246 struct isl_print_space_data space_data
= { 0 };
2249 space
= isl_union_pw_qpolynomial_get_space(upwqp
);
2250 p
= print_param_tuple(p
, space
, &space_data
);
2251 isl_space_free(space
);
2252 p
= isl_printer_print_str(p
, "{ ");
2255 isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp
, &print_pwqp_body
,
2258 p
= isl_printer_print_str(p
, " }");
2262 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial(
2263 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2268 if (p
->output_format
== ISL_FORMAT_ISL
)
2269 return print_union_pw_qpolynomial_isl(p
, upwqp
);
2270 isl_die(p
->ctx
, isl_error_invalid
,
2271 "invalid output format for isl_union_pw_qpolynomial",
2274 isl_printer_free(p
);
2278 /* Print the quasi-polynomial reduction "fold" to "p" in C format,
2279 * with the variable names taken from the domain space "space".
2281 static __isl_give isl_printer
*print_qpolynomial_fold_c(
2282 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
,
2283 __isl_keep isl_qpolynomial_fold
*fold
)
2287 for (i
= 0; i
< fold
->n
- 1; ++i
)
2288 if (fold
->type
== isl_fold_min
)
2289 p
= isl_printer_print_str(p
, "min(");
2290 else if (fold
->type
== isl_fold_max
)
2291 p
= isl_printer_print_str(p
, "max(");
2293 for (i
= 0; i
< fold
->n
; ++i
) {
2295 p
= isl_printer_print_str(p
, ", ");
2296 p
= print_qpolynomial_c(p
, space
, fold
->qp
[i
]);
2298 p
= isl_printer_print_str(p
, ")");
2303 __isl_give isl_printer
*isl_printer_print_qpolynomial_fold(
2304 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial_fold
*fold
)
2308 if (p
->output_format
== ISL_FORMAT_ISL
)
2309 return qpolynomial_fold_print(fold
, p
);
2310 else if (p
->output_format
== ISL_FORMAT_C
)
2311 return print_qpolynomial_fold_c(p
, fold
->dim
, fold
);
2312 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2315 isl_printer_free(p
);
2319 /* Print the piecewise quasi-polynomial reduction "pwf" to "p" in C format.
2321 static __isl_give isl_printer
*print_pw_qpolynomial_fold_c(
2322 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2327 space
= isl_pw_qpolynomial_fold_get_domain_space(pwf
);
2328 if (pwf
->n
== 1 && isl_set_plain_is_universe(pwf
->p
[0].set
)) {
2329 p
= print_qpolynomial_fold_c(p
, space
, pwf
->p
[0].fold
);
2330 isl_space_free(space
);
2334 for (i
= 0; i
< pwf
->n
; ++i
) {
2335 p
= isl_printer_print_str(p
, "(");
2336 p
= print_set_c(p
, space
, pwf
->p
[i
].set
);
2337 p
= isl_printer_print_str(p
, ") ? (");
2338 p
= print_qpolynomial_fold_c(p
, space
, pwf
->p
[i
].fold
);
2339 p
= isl_printer_print_str(p
, ") : ");
2342 isl_space_free(space
);
2343 p
= isl_printer_print_str(p
, "0");
2347 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial_fold(
2348 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2353 if (p
->output_format
== ISL_FORMAT_ISL
)
2354 return print_pw_qpolynomial_fold_isl(p
, pwf
);
2355 else if (p
->output_format
== ISL_FORMAT_C
)
2356 return print_pw_qpolynomial_fold_c(p
, pwf
);
2357 isl_assert(p
->ctx
, 0, goto error
);
2359 isl_printer_free(p
);
2363 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold
*pwf
,
2364 FILE *out
, unsigned output_format
)
2371 p
= isl_printer_to_file(pwf
->dim
->ctx
, out
);
2372 p
= isl_printer_set_output_format(p
, output_format
);
2373 p
= isl_printer_print_pw_qpolynomial_fold(p
, pwf
);
2375 isl_printer_free(p
);
2378 static isl_stat
print_pwf_body(__isl_take isl_pw_qpolynomial_fold
*pwf
,
2381 struct isl_union_print_data
*data
;
2382 data
= (struct isl_union_print_data
*)user
;
2385 data
->p
= isl_printer_print_str(data
->p
, "; ");
2388 data
->p
= isl_pwf_print_isl_body(data
->p
, pwf
);
2389 isl_pw_qpolynomial_fold_free(pwf
);
2394 static __isl_give isl_printer
*print_union_pw_qpolynomial_fold_isl(
2395 __isl_take isl_printer
*p
,
2396 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2398 struct isl_union_print_data data
;
2399 struct isl_print_space_data space_data
= { 0 };
2402 space
= isl_union_pw_qpolynomial_fold_get_space(upwf
);
2403 p
= print_param_tuple(p
, space
, &space_data
);
2404 isl_space_free(space
);
2405 p
= isl_printer_print_str(p
, "{ ");
2408 isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(upwf
,
2409 &print_pwf_body
, &data
);
2411 p
= isl_printer_print_str(p
, " }");
2415 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial_fold(
2416 __isl_take isl_printer
*p
,
2417 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2422 if (p
->output_format
== ISL_FORMAT_ISL
)
2423 return print_union_pw_qpolynomial_fold_isl(p
, upwf
);
2424 isl_die(p
->ctx
, isl_error_invalid
,
2425 "invalid output format for isl_union_pw_qpolynomial_fold",
2428 isl_printer_free(p
);
2432 /* Print the isl_constraint "c" to "p".
2434 __isl_give isl_printer
*isl_printer_print_constraint(__isl_take isl_printer
*p
,
2435 __isl_keep isl_constraint
*c
)
2437 struct isl_print_space_data data
= { 0 };
2438 isl_local_space
*ls
;
2445 ls
= isl_constraint_get_local_space(c
);
2447 return isl_printer_free(p
);
2448 space
= isl_local_space_get_space(ls
);
2449 p
= print_param_tuple(p
, space
, &data
);
2450 p
= isl_printer_print_str(p
, "{ ");
2451 p
= isl_print_space(space
, p
, 0, &data
);
2452 p
= isl_printer_print_str(p
, " : ");
2453 exists
= need_exists(p
, ls
->div
);
2455 p
= isl_printer_free(p
);
2456 if (exists
>= 0 && exists
)
2457 p
= open_exists(p
, space
, ls
->div
, 0);
2458 p
= print_affine_of_len(space
, ls
->div
, p
, c
->v
->el
, c
->v
->size
);
2459 if (isl_constraint_is_equality(c
))
2460 p
= isl_printer_print_str(p
, " = 0");
2462 p
= isl_printer_print_str(p
, " >= 0");
2463 if (exists
>= 0 && exists
)
2464 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2465 p
= isl_printer_print_str(p
, " }");
2466 isl_space_free(space
);
2467 isl_local_space_free(ls
);
2471 isl_printer_free(p
);
2475 static __isl_give isl_printer
*isl_printer_print_space_isl(
2476 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
)
2478 struct isl_print_space_data data
= { 0 };
2483 p
= print_param_tuple(p
, space
, &data
);
2485 p
= isl_printer_print_str(p
, "{ ");
2486 if (isl_space_is_params(space
))
2487 p
= isl_printer_print_str(p
, s_such_that
[0]);
2489 p
= isl_print_space(space
, p
, 0, &data
);
2490 p
= isl_printer_print_str(p
, " }");
2494 isl_printer_free(p
);
2498 __isl_give isl_printer
*isl_printer_print_space(__isl_take isl_printer
*p
,
2499 __isl_keep isl_space
*space
)
2502 return isl_printer_free(p
);
2503 if (p
->output_format
== ISL_FORMAT_ISL
)
2504 return isl_printer_print_space_isl(p
, space
);
2505 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
2506 return print_omega_parameters(space
, p
);
2508 isl_die(isl_space_get_ctx(space
), isl_error_unsupported
,
2509 "output format not supported for space",
2510 return isl_printer_free(p
));
2513 __isl_give isl_printer
*isl_printer_print_local_space(__isl_take isl_printer
*p
,
2514 __isl_keep isl_local_space
*ls
)
2516 struct isl_print_space_data data
= { 0 };
2522 p
= print_param_tuple(p
, ls
->dim
, &data
);
2523 p
= isl_printer_print_str(p
, "{ ");
2524 p
= isl_print_space(ls
->dim
, p
, 0, &data
);
2525 n_div
= isl_local_space_dim(ls
, isl_dim_div
);
2527 p
= isl_printer_print_str(p
, " : ");
2528 p
= isl_printer_print_str(p
, s_open_exists
[0]);
2529 p
= print_div_list(p
, ls
->dim
, ls
->div
, 0, 1);
2530 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2531 } else if (isl_space_is_params(ls
->dim
))
2532 p
= isl_printer_print_str(p
, s_such_that
[0]);
2533 p
= isl_printer_print_str(p
, " }");
2536 isl_printer_free(p
);
2540 /* Print the (potentially rational) affine expression "aff" to "p",
2541 * with the variable names taken from "space".
2543 static __isl_give isl_printer
*print_aff_body(__isl_take isl_printer
*p
,
2544 __isl_keep isl_space
*space
, __isl_keep isl_aff
*aff
)
2548 if (isl_aff_is_nan(aff
))
2549 return isl_printer_print_str(p
, "NaN");
2551 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2552 p
= isl_printer_print_str(p
, "(");
2553 p
= print_affine_of_len(space
, aff
->ls
->div
, p
,
2554 aff
->v
->el
+ 1, 1 + total
);
2555 if (isl_int_is_one(aff
->v
->el
[0]))
2556 p
= isl_printer_print_str(p
, ")");
2558 p
= isl_printer_print_str(p
, ")/");
2559 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2565 static __isl_give isl_printer
*print_aff(__isl_take isl_printer
*p
,
2566 __isl_keep isl_aff
*aff
)
2568 struct isl_print_space_data data
= { 0 };
2570 if (isl_space_is_params(aff
->ls
->dim
))
2573 p
= print_tuple(aff
->ls
->dim
, p
, isl_dim_set
, &data
);
2574 p
= isl_printer_print_str(p
, " -> ");
2576 p
= isl_printer_print_str(p
, "[");
2577 p
= print_aff_body(p
, aff
->ls
->dim
, aff
);
2578 p
= isl_printer_print_str(p
, "]");
2583 static __isl_give isl_printer
*print_aff_isl(__isl_take isl_printer
*p
,
2584 __isl_keep isl_aff
*aff
)
2586 struct isl_print_space_data data
= { 0 };
2591 p
= print_param_tuple(p
, aff
->ls
->dim
, &data
);
2592 p
= isl_printer_print_str(p
, "{ ");
2593 p
= print_aff(p
, aff
);
2594 p
= isl_printer_print_str(p
, " }");
2597 isl_printer_free(p
);
2601 /* Print the body of an isl_pw_aff, i.e., a semicolon delimited
2602 * sequence of affine expressions, each followed by constraints.
2604 static __isl_give isl_printer
*print_pw_aff_body(
2605 __isl_take isl_printer
*p
, __isl_keep isl_pw_aff
*pa
)
2610 return isl_printer_free(p
);
2612 for (i
= 0; i
< pa
->n
; ++i
) {
2616 p
= isl_printer_print_str(p
, "; ");
2617 p
= print_aff(p
, pa
->p
[i
].aff
);
2618 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
2619 p
= print_disjuncts(set_to_map(pa
->p
[i
].set
), space
, p
, 0);
2620 isl_space_free(space
);
2626 static __isl_give isl_printer
*print_pw_aff_isl(__isl_take isl_printer
*p
,
2627 __isl_keep isl_pw_aff
*pwaff
)
2629 struct isl_print_space_data data
= { 0 };
2634 p
= print_param_tuple(p
, pwaff
->dim
, &data
);
2635 p
= isl_printer_print_str(p
, "{ ");
2636 p
= print_pw_aff_body(p
, pwaff
);
2637 p
= isl_printer_print_str(p
, " }");
2640 isl_printer_free(p
);
2644 static __isl_give isl_printer
*print_ls_name_c(__isl_take isl_printer
*p
,
2645 __isl_keep isl_local_space
*ls
, enum isl_dim_type type
, unsigned pos
)
2647 if (type
== isl_dim_div
) {
2648 p
= isl_printer_print_str(p
, "floord(");
2649 p
= print_ls_affine_c(p
, ls
, ls
->div
->row
[pos
] + 1);
2650 p
= isl_printer_print_str(p
, ", ");
2651 p
= isl_printer_print_isl_int(p
, ls
->div
->row
[pos
][0]);
2652 p
= isl_printer_print_str(p
, ")");
2656 name
= isl_space_get_dim_name(ls
->dim
, type
, pos
);
2659 p
= isl_printer_print_str(p
, name
);
2664 static __isl_give isl_printer
*print_ls_term_c(__isl_take isl_printer
*p
,
2665 __isl_keep isl_local_space
*ls
, isl_int c
, unsigned pos
)
2667 enum isl_dim_type type
;
2670 return isl_printer_free(p
);
2673 return isl_printer_print_isl_int(p
, c
);
2675 if (isl_int_is_one(c
))
2677 else if (isl_int_is_negone(c
))
2678 p
= isl_printer_print_str(p
, "-");
2680 p
= isl_printer_print_isl_int(p
, c
);
2681 p
= isl_printer_print_str(p
, "*");
2683 if (pos2type(ls
->dim
, &type
, &pos
) < 0)
2684 return isl_printer_free(p
);
2685 p
= print_ls_name_c(p
, ls
, type
, pos
);
2689 static __isl_give isl_printer
*print_ls_partial_affine_c(
2690 __isl_take isl_printer
*p
, __isl_keep isl_local_space
*ls
,
2691 isl_int
*c
, unsigned len
)
2696 for (i
= 0, first
= 1; i
< len
; ++i
) {
2698 if (isl_int_is_zero(c
[i
]))
2701 if (isl_int_is_neg(c
[i
])) {
2703 isl_int_neg(c
[i
], c
[i
]);
2704 p
= isl_printer_print_str(p
, " - ");
2706 p
= isl_printer_print_str(p
, " + ");
2709 p
= print_ls_term_c(p
, ls
, c
[i
], i
);
2711 isl_int_neg(c
[i
], c
[i
]);
2714 p
= isl_printer_print_str(p
, "0");
2718 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2719 __isl_keep isl_local_space
*ls
, isl_int
*c
)
2721 unsigned len
= 1 + isl_local_space_dim(ls
, isl_dim_all
);
2722 return print_ls_partial_affine_c(p
, ls
, c
, len
);
2725 static __isl_give isl_printer
*print_aff_c(__isl_take isl_printer
*p
,
2726 __isl_keep isl_aff
*aff
)
2730 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2731 if (!isl_int_is_one(aff
->v
->el
[0]))
2732 p
= isl_printer_print_str(p
, "(");
2733 p
= print_ls_partial_affine_c(p
, aff
->ls
, aff
->v
->el
+ 1, 1 + total
);
2734 if (!isl_int_is_one(aff
->v
->el
[0])) {
2735 p
= isl_printer_print_str(p
, ")/");
2736 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2741 /* In the C format, we cannot express that "pwaff" may be undefined
2742 * on parts of the domain space. We therefore assume that the expression
2743 * will only be evaluated on its definition domain and compute the gist
2744 * of each cell with respect to this domain.
2746 static __isl_give isl_printer
*print_pw_aff_c(__isl_take isl_printer
*p
,
2747 __isl_keep isl_pw_aff
*pwaff
)
2750 isl_ast_build
*build
;
2754 isl_die(p
->ctx
, isl_error_unsupported
,
2755 "cannot print empty isl_pw_aff in C format",
2756 return isl_printer_free(p
));
2758 domain
= isl_pw_aff_domain(isl_pw_aff_copy(pwaff
));
2759 build
= isl_ast_build_from_context(domain
);
2760 expr
= isl_ast_build_expr_from_pw_aff(build
, isl_pw_aff_copy(pwaff
));
2761 p
= isl_printer_print_ast_expr(p
, expr
);
2762 isl_ast_expr_free(expr
);
2763 isl_ast_build_free(build
);
2768 __isl_give isl_printer
*isl_printer_print_aff(__isl_take isl_printer
*p
,
2769 __isl_keep isl_aff
*aff
)
2774 if (p
->output_format
== ISL_FORMAT_ISL
)
2775 return print_aff_isl(p
, aff
);
2776 else if (p
->output_format
== ISL_FORMAT_C
)
2777 return print_aff_c(p
, aff
);
2778 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2781 isl_printer_free(p
);
2785 __isl_give isl_printer
*isl_printer_print_pw_aff(__isl_take isl_printer
*p
,
2786 __isl_keep isl_pw_aff
*pwaff
)
2791 if (p
->output_format
== ISL_FORMAT_ISL
)
2792 return print_pw_aff_isl(p
, pwaff
);
2793 else if (p
->output_format
== ISL_FORMAT_C
)
2794 return print_pw_aff_c(p
, pwaff
);
2795 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2798 isl_printer_free(p
);
2802 /* Print "pa" in a sequence of isl_pw_affs delimited by semicolons.
2803 * Each isl_pw_aff itself is also printed as semicolon delimited
2804 * sequence of pieces.
2805 * If data->first = 1, then this is the first in the sequence.
2806 * Update data->first to tell the next element that it is not the first.
2808 static isl_stat
print_pw_aff_body_wrap(__isl_take isl_pw_aff
*pa
,
2811 struct isl_union_print_data
*data
;
2812 data
= (struct isl_union_print_data
*) user
;
2815 data
->p
= isl_printer_print_str(data
->p
, "; ");
2818 data
->p
= print_pw_aff_body(data
->p
, pa
);
2819 isl_pw_aff_free(pa
);
2821 return data
->p
? isl_stat_ok
: isl_stat_error
;
2824 /* Print the body of an isl_union_pw_aff, i.e., a semicolon delimited
2825 * sequence of affine expressions, each followed by constraints,
2826 * with the sequence enclosed in braces.
2828 static __isl_give isl_printer
*print_union_pw_aff_body(
2829 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2831 struct isl_union_print_data data
= { p
, 1 };
2833 p
= isl_printer_print_str(p
, s_open_set
[0]);
2835 if (isl_union_pw_aff_foreach_pw_aff(upa
,
2836 &print_pw_aff_body_wrap
, &data
) < 0)
2837 data
.p
= isl_printer_free(p
);
2839 p
= isl_printer_print_str(p
, s_close_set
[0]);
2844 /* Print the isl_union_pw_aff "upa" to "p" in isl format.
2846 * The individual isl_pw_affs are delimited by a semicolon.
2848 static __isl_give isl_printer
*print_union_pw_aff_isl(
2849 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2851 struct isl_print_space_data data
= { 0 };
2854 space
= isl_union_pw_aff_get_space(upa
);
2855 p
= print_param_tuple(p
, space
, &data
);
2856 isl_space_free(space
);
2857 p
= print_union_pw_aff_body(p
, upa
);
2861 /* Print the isl_union_pw_aff "upa" to "p".
2863 * We currently only support an isl format.
2865 __isl_give isl_printer
*isl_printer_print_union_pw_aff(
2866 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2869 return isl_printer_free(p
);
2871 if (p
->output_format
== ISL_FORMAT_ISL
)
2872 return print_union_pw_aff_isl(p
, upa
);
2873 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
2874 "unsupported output format", return isl_printer_free(p
));
2877 /* Print dimension "pos" of data->space to "p".
2879 * data->user is assumed to be an isl_multi_aff.
2881 * If the current dimension is an output dimension, then print
2882 * the corresponding expression. Otherwise, print the name of the dimension.
2884 static __isl_give isl_printer
*print_dim_ma(__isl_take isl_printer
*p
,
2885 struct isl_print_space_data
*data
, unsigned pos
)
2887 isl_multi_aff
*ma
= data
->user
;
2889 if (data
->type
== isl_dim_out
) {
2892 space
= isl_multi_aff_get_domain_space(ma
);
2893 p
= print_aff_body(p
, space
, ma
->u
.p
[pos
]);
2894 isl_space_free(space
);
2896 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2902 static __isl_give isl_printer
*print_multi_aff(__isl_take isl_printer
*p
,
2903 __isl_keep isl_multi_aff
*maff
)
2905 struct isl_print_space_data data
= { 0 };
2907 data
.print_dim
= &print_dim_ma
;
2909 return isl_print_space(maff
->space
, p
, 0, &data
);
2912 static __isl_give isl_printer
*print_multi_aff_isl(__isl_take isl_printer
*p
,
2913 __isl_keep isl_multi_aff
*maff
)
2915 struct isl_print_space_data data
= { 0 };
2920 p
= print_param_tuple(p
, maff
->space
, &data
);
2921 p
= isl_printer_print_str(p
, "{ ");
2922 p
= print_multi_aff(p
, maff
);
2923 p
= isl_printer_print_str(p
, " }");
2926 isl_printer_free(p
);
2930 __isl_give isl_printer
*isl_printer_print_multi_aff(__isl_take isl_printer
*p
,
2931 __isl_keep isl_multi_aff
*maff
)
2936 if (p
->output_format
== ISL_FORMAT_ISL
)
2937 return print_multi_aff_isl(p
, maff
);
2938 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2941 isl_printer_free(p
);
2945 static __isl_give isl_printer
*print_pw_multi_aff_body(
2946 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2953 for (i
= 0; i
< pma
->n
; ++i
) {
2957 p
= isl_printer_print_str(p
, "; ");
2958 p
= print_multi_aff(p
, pma
->p
[i
].maff
);
2959 space
= isl_multi_aff_get_domain_space(pma
->p
[i
].maff
);
2960 p
= print_disjuncts(set_to_map(pma
->p
[i
].set
), space
, p
, 0);
2961 isl_space_free(space
);
2965 isl_printer_free(p
);
2969 static __isl_give isl_printer
*print_pw_multi_aff_isl(__isl_take isl_printer
*p
,
2970 __isl_keep isl_pw_multi_aff
*pma
)
2972 struct isl_print_space_data data
= { 0 };
2977 p
= print_param_tuple(p
, pma
->dim
, &data
);
2978 p
= isl_printer_print_str(p
, "{ ");
2979 p
= print_pw_multi_aff_body(p
, pma
);
2980 p
= isl_printer_print_str(p
, " }");
2983 isl_printer_free(p
);
2987 /* Print the unnamed, single-dimensional piecewise multi affine expression "pma"
2990 static __isl_give isl_printer
*print_unnamed_pw_multi_aff_c(
2991 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2996 space
= isl_pw_multi_aff_get_domain_space(pma
);
2997 for (i
= 0; i
< pma
->n
- 1; ++i
) {
2998 p
= isl_printer_print_str(p
, "(");
2999 p
= print_set_c(p
, space
, pma
->p
[i
].set
);
3000 p
= isl_printer_print_str(p
, ") ? (");
3001 p
= print_aff_c(p
, pma
->p
[i
].maff
->u
.p
[0]);
3002 p
= isl_printer_print_str(p
, ") : ");
3004 isl_space_free(space
);
3006 return print_aff_c(p
, pma
->p
[pma
->n
- 1].maff
->u
.p
[0]);
3009 static __isl_give isl_printer
*print_pw_multi_aff_c(__isl_take isl_printer
*p
,
3010 __isl_keep isl_pw_multi_aff
*pma
)
3018 isl_die(p
->ctx
, isl_error_unsupported
,
3019 "cannot print empty isl_pw_multi_aff in C format",
3021 name
= isl_pw_multi_aff_get_tuple_name(pma
, isl_dim_out
);
3022 if (!name
&& isl_pw_multi_aff_dim(pma
, isl_dim_out
) == 1)
3023 return print_unnamed_pw_multi_aff_c(p
, pma
);
3025 isl_die(p
->ctx
, isl_error_unsupported
,
3026 "cannot print unnamed isl_pw_multi_aff in C format",
3029 p
= isl_printer_print_str(p
, name
);
3030 n
= isl_pw_multi_aff_dim(pma
, isl_dim_out
);
3032 isl_die(p
->ctx
, isl_error_unsupported
,
3033 "not supported yet", goto error
);
3037 isl_printer_free(p
);
3041 __isl_give isl_printer
*isl_printer_print_pw_multi_aff(
3042 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
3047 if (p
->output_format
== ISL_FORMAT_ISL
)
3048 return print_pw_multi_aff_isl(p
, pma
);
3049 if (p
->output_format
== ISL_FORMAT_C
)
3050 return print_pw_multi_aff_c(p
, pma
);
3051 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3054 isl_printer_free(p
);
3058 static isl_stat
print_pw_multi_aff_body_wrap(__isl_take isl_pw_multi_aff
*pma
,
3061 struct isl_union_print_data
*data
;
3062 data
= (struct isl_union_print_data
*) user
;
3065 data
->p
= isl_printer_print_str(data
->p
, "; ");
3068 data
->p
= print_pw_multi_aff_body(data
->p
, pma
);
3069 isl_pw_multi_aff_free(pma
);
3074 static __isl_give isl_printer
*print_union_pw_multi_aff_isl(
3075 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
3077 struct isl_union_print_data data
;
3078 struct isl_print_space_data space_data
= { 0 };
3081 space
= isl_union_pw_multi_aff_get_space(upma
);
3082 p
= print_param_tuple(p
, space
, &space_data
);
3083 isl_space_free(space
);
3084 p
= isl_printer_print_str(p
, s_open_set
[0]);
3087 isl_union_pw_multi_aff_foreach_pw_multi_aff(upma
,
3088 &print_pw_multi_aff_body_wrap
, &data
);
3090 p
= isl_printer_print_str(p
, s_close_set
[0]);
3094 __isl_give isl_printer
*isl_printer_print_union_pw_multi_aff(
3095 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
3100 if (p
->output_format
== ISL_FORMAT_ISL
)
3101 return print_union_pw_multi_aff_isl(p
, upma
);
3102 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3105 isl_printer_free(p
);
3109 /* Print dimension "pos" of data->space to "p".
3111 * data->user is assumed to be an isl_multi_pw_aff.
3113 * If the current dimension is an output dimension, then print
3114 * the corresponding piecewise affine expression.
3115 * Otherwise, print the name of the dimension.
3117 static __isl_give isl_printer
*print_dim_mpa(__isl_take isl_printer
*p
,
3118 struct isl_print_space_data
*data
, unsigned pos
)
3123 isl_multi_pw_aff
*mpa
= data
->user
;
3126 if (data
->type
!= isl_dim_out
)
3127 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
3131 return isl_printer_print_str(p
, "(0 : false)");
3133 need_parens
= pa
->n
!= 1 || !isl_set_plain_is_universe(pa
->p
[0].set
);
3135 p
= isl_printer_print_str(p
, "(");
3136 space
= isl_multi_pw_aff_get_domain_space(mpa
);
3137 for (i
= 0; i
< pa
->n
; ++i
) {
3140 p
= isl_printer_print_str(p
, "; ");
3141 p
= print_aff_body(p
, space
, pa
->p
[i
].aff
);
3142 p
= print_disjuncts(pa
->p
[i
].set
, space
, p
, 0);
3144 isl_space_free(space
);
3146 p
= isl_printer_print_str(p
, ")");
3151 /* Print "mpa" to "p" in isl format.
3153 * If "mpa" is zero-dimensional and has a non-trivial explicit domain,
3154 * then it is printed after the tuple of affine expressions.
3156 static __isl_give isl_printer
*print_multi_pw_aff_isl(__isl_take isl_printer
*p
,
3157 __isl_keep isl_multi_pw_aff
*mpa
)
3159 struct isl_print_space_data data
= { 0 };
3160 isl_bool has_domain
;
3163 return isl_printer_free(p
);
3165 p
= print_param_tuple(p
, mpa
->space
, &data
);
3166 p
= isl_printer_print_str(p
, "{ ");
3167 data
.print_dim
= &print_dim_mpa
;
3169 p
= isl_print_space(mpa
->space
, p
, 0, &data
);
3170 has_domain
= isl_multi_pw_aff_has_non_trivial_domain(mpa
);
3172 return isl_printer_free(p
);
3176 space
= isl_space_domain(isl_space_copy(mpa
->space
));
3177 p
= print_disjuncts_set(mpa
->u
.dom
, space
, p
, 0);
3178 isl_space_free(space
);
3180 p
= isl_printer_print_str(p
, " }");
3184 __isl_give isl_printer
*isl_printer_print_multi_pw_aff(
3185 __isl_take isl_printer
*p
, __isl_keep isl_multi_pw_aff
*mpa
)
3188 return isl_printer_free(p
);
3190 if (p
->output_format
== ISL_FORMAT_ISL
)
3191 return print_multi_pw_aff_isl(p
, mpa
);
3192 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3193 return isl_printer_free(p
));
3196 /* Print dimension "pos" of data->space to "p".
3198 * data->user is assumed to be an isl_multi_val.
3200 * If the current dimension is an output dimension, then print
3201 * the corresponding value. Otherwise, print the name of the dimension.
3203 static __isl_give isl_printer
*print_dim_mv(__isl_take isl_printer
*p
,
3204 struct isl_print_space_data
*data
, unsigned pos
)
3206 isl_multi_val
*mv
= data
->user
;
3208 if (data
->type
== isl_dim_out
)
3209 return isl_printer_print_val(p
, mv
->u
.p
[pos
]);
3211 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
3214 /* Print the isl_multi_val "mv" to "p" in isl format.
3216 static __isl_give isl_printer
*print_multi_val_isl(__isl_take isl_printer
*p
,
3217 __isl_keep isl_multi_val
*mv
)
3219 struct isl_print_space_data data
= { 0 };
3222 return isl_printer_free(p
);
3224 p
= print_param_tuple(p
, mv
->space
, &data
);
3225 p
= isl_printer_print_str(p
, "{ ");
3226 data
.print_dim
= &print_dim_mv
;
3228 p
= isl_print_space(mv
->space
, p
, 0, &data
);
3229 p
= isl_printer_print_str(p
, " }");
3233 /* Print the isl_multi_val "mv" to "p".
3235 * Currently only supported in isl format.
3237 __isl_give isl_printer
*isl_printer_print_multi_val(
3238 __isl_take isl_printer
*p
, __isl_keep isl_multi_val
*mv
)
3241 return isl_printer_free(p
);
3243 if (p
->output_format
== ISL_FORMAT_ISL
)
3244 return print_multi_val_isl(p
, mv
);
3245 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3246 return isl_printer_free(p
));
3249 /* Print dimension "pos" of data->space to "p".
3251 * data->user is assumed to be an isl_multi_union_pw_aff.
3253 * The current dimension is necessarily a set dimension, so
3254 * we print the corresponding isl_union_pw_aff, including
3257 static __isl_give isl_printer
*print_union_pw_aff_dim(__isl_take isl_printer
*p
,
3258 struct isl_print_space_data
*data
, unsigned pos
)
3260 isl_multi_union_pw_aff
*mupa
= data
->user
;
3261 isl_union_pw_aff
*upa
;
3263 upa
= isl_multi_union_pw_aff_get_union_pw_aff(mupa
, pos
);
3264 p
= print_union_pw_aff_body(p
, upa
);
3265 isl_union_pw_aff_free(upa
);
3270 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3272 * If "mupa" is zero-dimensional and has a non-trivial explicit domain,
3273 * then it is printed after the tuple of affine expressions.
3274 * In order to clarify that this domain belongs to the expression,
3275 * the tuple along with the domain are placed inside parentheses.
3276 * If "mupa" has any parameters, then the opening parenthesis
3277 * appears after the parameter declarations.
3279 static __isl_give isl_printer
*print_multi_union_pw_aff_isl(
3280 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3282 struct isl_print_space_data data
= { 0 };
3283 isl_bool has_domain
;
3287 return isl_printer_free(p
);
3288 has_domain
= isl_multi_union_pw_aff_has_non_trivial_domain(mupa
);
3290 return isl_printer_free(p
);
3292 space
= isl_multi_union_pw_aff_get_space(mupa
);
3293 p
= print_param_tuple(p
, space
, &data
);
3296 p
= isl_printer_print_str(p
, "(");
3298 data
.print_dim
= &print_union_pw_aff_dim
;
3301 p
= isl_print_space(space
, p
, 0, &data
);
3302 isl_space_free(space
);
3305 p
= isl_printer_print_str(p
, " : ");
3306 p
= isl_printer_print_union_set_isl_body(p
, mupa
->u
.dom
);
3307 p
= isl_printer_print_str(p
, ")");
3313 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3315 * We currently only support an isl format.
3317 __isl_give isl_printer
*isl_printer_print_multi_union_pw_aff(
3318 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3321 return isl_printer_free(p
);
3323 if (p
->output_format
== ISL_FORMAT_ISL
)
3324 return print_multi_union_pw_aff_isl(p
, mupa
);
3325 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
3326 "unsupported output format", return isl_printer_free(p
));