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
*dim
,
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(dim
, t
);
176 for (p
= 0; p
< s
; ++p
) {
177 const char *n
= isl_space_get_dim_name(dim
, t
, p
);
178 if (n
&& !strcmp(n
, name
))
185 /* Print the name of the variable of type "type" and position "pos"
188 static __isl_give isl_printer
*print_name(__isl_keep isl_space
*space
,
189 __isl_take isl_printer
*p
, enum isl_dim_type type
, unsigned pos
,
196 name
= type
== isl_dim_div
? NULL
197 : isl_space_get_dim_name(space
, type
, pos
);
201 if (type
== isl_dim_param
)
202 prefix
= s_param_prefix
[latex
];
203 else if (type
== isl_dim_div
)
204 prefix
= s_div_prefix
[latex
];
205 else if (isl_space_is_set(space
) || type
== isl_dim_in
)
206 prefix
= s_input_prefix
[latex
];
208 prefix
= s_output_prefix
[latex
];
209 snprintf(buffer
, sizeof(buffer
), "%s%d", prefix
, pos
);
212 primes
= count_same_name(space
, name
== buffer
? isl_dim_div
: type
,
214 p
= isl_printer_print_str(p
, name
);
216 p
= isl_printer_print_str(p
, "'");
220 static enum isl_dim_type
pos2type(__isl_keep isl_space
*dim
, unsigned *pos
)
222 enum isl_dim_type type
;
223 unsigned n_in
= isl_space_dim(dim
, isl_dim_in
);
224 unsigned n_out
= isl_space_dim(dim
, isl_dim_out
);
225 unsigned nparam
= isl_space_dim(dim
, 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_print_isl_int(p
, c
);
274 type
= pos2type(space
, &pos
);
275 print_div_def
= type
== isl_dim_div
&& can_print_div_expr(p
, div
, pos
);
277 if (isl_int_is_one(c
))
279 else if (isl_int_is_negone(c
))
280 p
= isl_printer_print_str(p
, "-");
282 p
= isl_printer_print_isl_int(p
, c
);
283 if (p
->output_format
== ISL_FORMAT_C
|| print_div_def
)
284 p
= isl_printer_print_str(p
, "*");
287 p
= print_div(space
, div
, pos
, p
);
289 p
= print_name(space
, p
, type
, pos
, latex
);
293 static __isl_give isl_printer
*print_affine_of_len(__isl_keep isl_space
*dim
,
294 __isl_keep isl_mat
*div
,
295 __isl_take isl_printer
*p
, isl_int
*c
, int len
)
300 for (i
= 0, first
= 1; i
< len
; ++i
) {
302 if (isl_int_is_zero(c
[i
]))
305 if (isl_int_is_neg(c
[i
])) {
307 isl_int_neg(c
[i
], c
[i
]);
308 p
= isl_printer_print_str(p
, " - ");
310 p
= isl_printer_print_str(p
, " + ");
313 p
= print_term(dim
, div
, c
[i
], i
, p
, 0);
315 isl_int_neg(c
[i
], c
[i
]);
318 p
= isl_printer_print_str(p
, "0");
322 /* Print an affine expression "c"
323 * to "p", with the variable names taken from "space" and
324 * the integer division definitions taken from "div".
326 static __isl_give isl_printer
*print_affine(__isl_take isl_printer
*p
,
327 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, isl_int
*c
)
333 return isl_printer_free(p
);
334 n_div
= isl_mat_rows(div
);
335 len
= 1 + isl_space_dim(space
, isl_dim_all
) + n_div
;
336 return print_affine_of_len(space
, div
, p
, c
, len
);
339 /* offset is the offset of local_dim inside data->type of data->space.
341 static __isl_give isl_printer
*print_nested_var_list(__isl_take isl_printer
*p
,
342 __isl_keep isl_space
*local_dim
, enum isl_dim_type local_type
,
343 struct isl_print_space_data
*data
, int offset
)
347 if (data
->space
!= local_dim
&& local_type
== isl_dim_out
)
348 offset
+= local_dim
->n_in
;
350 for (i
= 0; i
< isl_space_dim(local_dim
, local_type
); ++i
) {
352 p
= isl_printer_print_str(p
, ", ");
354 p
= data
->print_dim(p
, data
, offset
+ i
);
356 p
= print_name(data
->space
, p
, data
->type
, offset
+ i
,
362 static __isl_give isl_printer
*print_var_list(__isl_take isl_printer
*p
,
363 __isl_keep isl_space
*space
, enum isl_dim_type type
)
365 struct isl_print_space_data data
= { .space
= space
, .type
= type
};
367 return print_nested_var_list(p
, space
, type
, &data
, 0);
370 static __isl_give isl_printer
*print_nested_map_dim(__isl_take isl_printer
*p
,
371 __isl_keep isl_space
*local_dim
,
372 struct isl_print_space_data
*data
, int offset
);
374 static __isl_give isl_printer
*print_nested_tuple(__isl_take isl_printer
*p
,
375 __isl_keep isl_space
*local_dim
, enum isl_dim_type local_type
,
376 struct isl_print_space_data
*data
, int offset
)
378 const char *name
= NULL
;
379 unsigned n
= isl_space_dim(local_dim
, local_type
);
380 if ((local_type
== isl_dim_in
|| local_type
== isl_dim_out
)) {
381 name
= isl_space_get_tuple_name(local_dim
, local_type
);
384 p
= isl_printer_print_str(p
, "\\mathrm{");
385 p
= isl_printer_print_str(p
, name
);
387 p
= isl_printer_print_str(p
, "}");
390 if (!data
->latex
|| n
!= 1 || name
)
391 p
= isl_printer_print_str(p
, s_open_list
[data
->latex
]);
392 if ((local_type
== isl_dim_in
|| local_type
== isl_dim_out
) &&
393 local_dim
->nested
[local_type
- isl_dim_in
]) {
394 if (data
->space
!= local_dim
&& local_type
== isl_dim_out
)
395 offset
+= local_dim
->n_in
;
396 p
= print_nested_map_dim(p
,
397 local_dim
->nested
[local_type
- isl_dim_in
],
400 p
= print_nested_var_list(p
, local_dim
, local_type
, data
,
402 if (!data
->latex
|| n
!= 1 || name
)
403 p
= isl_printer_print_str(p
, s_close_list
[data
->latex
]);
407 static __isl_give isl_printer
*print_tuple(__isl_keep isl_space
*dim
,
408 __isl_take isl_printer
*p
, enum isl_dim_type type
,
409 struct isl_print_space_data
*data
)
413 return print_nested_tuple(p
, dim
, type
, data
, 0);
416 static __isl_give isl_printer
*print_nested_map_dim(__isl_take isl_printer
*p
,
417 __isl_keep isl_space
*local_dim
,
418 struct isl_print_space_data
*data
, int offset
)
420 p
= print_nested_tuple(p
, local_dim
, isl_dim_in
, data
, offset
);
421 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
422 p
= print_nested_tuple(p
, local_dim
, isl_dim_out
, data
, offset
);
427 __isl_give isl_printer
*isl_print_space(__isl_keep isl_space
*space
,
428 __isl_take isl_printer
*p
, int rational
,
429 struct isl_print_space_data
*data
)
431 if (rational
&& !data
->latex
)
432 p
= isl_printer_print_str(p
, "rat: ");
433 if (isl_space_is_params(space
))
435 else if (isl_space_is_set(space
))
436 p
= print_tuple(space
, p
, isl_dim_set
, data
);
438 p
= print_tuple(space
, p
, isl_dim_in
, data
);
439 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
440 p
= print_tuple(space
, p
, isl_dim_out
, data
);
446 static __isl_give isl_printer
*print_omega_parameters(__isl_keep isl_space
*dim
,
447 __isl_take isl_printer
*p
)
449 if (isl_space_dim(dim
, isl_dim_param
) == 0)
452 p
= isl_printer_start_line(p
);
453 p
= isl_printer_print_str(p
, "symbolic ");
454 p
= print_var_list(p
, dim
, isl_dim_param
);
455 p
= isl_printer_print_str(p
, ";");
456 p
= isl_printer_end_line(p
);
460 /* Does the inequality constraint following "i" in "bmap"
461 * have an opposite value for the same last coefficient?
462 * "last" is the position of the last coefficient of inequality "i".
463 * If the next constraint is a div constraint, then it is ignored
464 * since div constraints are not printed.
466 static int next_is_opposite(__isl_keep isl_basic_map
*bmap
, int i
, int last
)
468 unsigned total
= isl_basic_map_total_dim(bmap
);
469 unsigned o_div
= isl_basic_map_offset(bmap
, isl_dim_div
);
471 if (i
+ 1 >= bmap
->n_ineq
)
473 if (isl_seq_last_non_zero(bmap
->ineq
[i
+ 1], 1 + total
) != last
)
477 is_div
= isl_basic_map_is_div_constraint(bmap
,
478 bmap
->ineq
[i
+ 1], last
- o_div
);
484 return isl_int_abs_eq(bmap
->ineq
[i
][last
], bmap
->ineq
[i
+ 1][last
]) &&
485 !isl_int_eq(bmap
->ineq
[i
][last
], bmap
->ineq
[i
+ 1][last
]);
488 /* Return a string representation of the operator used when
489 * printing a constraint where the LHS is greater than or equal to the LHS
490 * (sign > 0) or smaller than or equal to the LHS (sign < 0).
491 * If "strict" is set, then return the strict version of the comparison
494 static const char *constraint_op(int sign
, int strict
, int latex
)
497 return sign
< 0 ? "<" : ">";
504 /* Print one side of a constraint "c" to "p", with
505 * the variable names taken from "space" and the integer division definitions
507 * "last" is the position of the last non-zero coefficient.
508 * Let c' be the result of zeroing out this coefficient, then
509 * the partial constraint
515 static __isl_give isl_printer
*print_half_constraint(__isl_take isl_printer
*p
,
516 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
517 isl_int
*c
, int last
, const char *op
, int latex
)
519 isl_int_set_si(c
[last
], 0);
520 p
= print_affine(p
, space
, div
, c
);
522 p
= isl_printer_print_str(p
, " ");
523 p
= isl_printer_print_str(p
, op
);
524 p
= isl_printer_print_str(p
, " ");
529 /* Print a constraint "c" to "p", with the variable names
530 * taken from "space" and the integer division definitions taken from "div".
531 * "last" is the position of the last non-zero coefficient, which is
532 * moreover assumed to be negative.
533 * Let c' be the result of zeroing out this coefficient, then
534 * the constraint is printed in the form
538 static __isl_give isl_printer
*print_constraint(__isl_take isl_printer
*p
,
539 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
540 isl_int
*c
, int last
, const char *op
, int latex
)
542 isl_int_abs(c
[last
], c
[last
]);
544 p
= print_term(space
, div
, c
[last
], last
, p
, latex
);
546 p
= isl_printer_print_str(p
, " ");
547 p
= isl_printer_print_str(p
, op
);
548 p
= isl_printer_print_str(p
, " ");
550 isl_int_set_si(c
[last
], 0);
551 p
= print_affine(p
, space
, div
, c
);
556 /* Given an integer division
560 * at position "pos" in "div", print the corresponding modulo expression
564 * to "p". The variable names are taken from "space", while any
565 * nested integer division definitions are taken from "div".
567 static __isl_give isl_printer
*print_mod(__isl_take isl_printer
*p
,
568 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int pos
,
572 return isl_printer_free(p
);
574 p
= isl_printer_print_str(p
, "(");
575 p
= print_affine_of_len(space
, div
, p
,
576 div
->row
[pos
] + 1, div
->n_col
- 1);
577 p
= isl_printer_print_str(p
, ") ");
578 p
= isl_printer_print_str(p
, s_mod
[latex
]);
579 p
= isl_printer_print_str(p
, " ");
580 p
= isl_printer_print_isl_int(p
, div
->row
[pos
][0]);
584 /* Can the equality constraints "c" be printed as a modulo constraint?
585 * In particular, is of the form
587 * f - a m floor(g/m) = 0,
589 * with c = -a m the coefficient at position "pos"?
590 * Return the position of the corresponding integer division if so.
591 * Return the number of integer divisions if not.
592 * Return -1 on error.
594 * Modulo constraints are currently not printed in C format.
595 * Other than that, "pos" needs to correspond to an integer division
596 * with explicit representation and "c" needs to be a multiple
597 * of the denominator of the integer division.
599 static int print_as_modulo_pos(__isl_keep isl_printer
*p
,
600 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, unsigned pos
,
605 enum isl_dim_type type
;
609 n_div
= isl_mat_rows(div
);
610 if (p
->output_format
== ISL_FORMAT_C
)
612 type
= pos2type(space
, &pos
);
613 if (type
!= isl_dim_div
)
615 can_print
= can_print_div_expr(p
, div
, pos
);
620 if (!isl_int_is_divisible_by(c
, div
->row
[pos
][0]))
625 /* Print equality constraint "c" to "p" as a modulo constraint,
626 * with the variable names taken from "space" and
627 * the integer division definitions taken from "div".
628 * "last" is the position of the last non-zero coefficient, which is
629 * moreover assumed to be negative and a multiple of the denominator
630 * of the corresponding integer division. "div_pos" is the corresponding
631 * position in the sequence of integer divisions.
633 * The equality is of the form
635 * f - a m floor(g/m) = 0.
639 * a (g mod m) = -f + a g
641 static __isl_give isl_printer
*print_eq_mod_constraint(
642 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
,
643 __isl_keep isl_mat
*div
, unsigned div_pos
,
644 isl_int
*c
, int last
, int latex
)
649 ctx
= isl_printer_get_ctx(p
);
650 isl_int_divexact(c
[last
], c
[last
], div
->row
[div_pos
][0]);
651 isl_int_abs(c
[last
], c
[last
]);
652 multiple
= !isl_int_is_one(c
[last
]);
654 p
= isl_printer_print_isl_int(p
, c
[last
]);
655 p
= isl_printer_print_str(p
, "*(");
657 p
= print_mod(p
, space
, div
, div_pos
, latex
);
659 p
= isl_printer_print_str(p
, ")");
660 p
= isl_printer_print_str(p
, " = ");
661 isl_seq_combine(c
, ctx
->negone
, c
,
662 c
[last
], div
->row
[div_pos
] + 1, last
);
663 isl_int_set_si(c
[last
], 0);
664 p
= print_affine(p
, space
, div
, c
);
668 /* Print equality constraint "c" to "p", with the variable names
669 * taken from "space" and the integer division definitions taken from "div".
670 * "last" is the position of the last non-zero coefficient, which is
671 * moreover assumed to be negative.
673 * If possible, print the equality constraint as a modulo constraint.
675 static __isl_give isl_printer
*print_eq_constraint(__isl_take isl_printer
*p
,
676 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, isl_int
*c
,
682 n_div
= isl_mat_rows(div
);
683 div_pos
= print_as_modulo_pos(p
, space
, div
, last
, c
[last
]);
685 return isl_printer_free(p
);
687 return print_eq_mod_constraint(p
, space
, div
, div_pos
,
689 return print_constraint(p
, space
, div
, c
, last
, "=", latex
);
692 /* Print the constraints of "bmap" to "p".
693 * The names of the variables are taken from "space" and
694 * the integer division definitions are taken from "div".
695 * Div constraints are only printed in "dump" mode.
696 * The constraints are sorted prior to printing (except in "dump" mode).
698 * If x is the last variable with a non-zero coefficient,
707 * while an upper bound
715 * If the next constraint has an opposite sign for the same last coefficient,
716 * then it is printed as
724 * instead. In fact, the "a x" part is not printed explicitly, but
725 * reused from the next constraint, which is therefore treated as
726 * a first constraint in the conjunction.
728 * If the constant term of "f" is -1, then "f" is replaced by "f + 1" and
729 * the comparison operator is replaced by the strict variant.
730 * Essentially, ">= 1" is replaced by "> 0".
732 static __isl_give isl_printer
*print_constraints(__isl_keep isl_basic_map
*bmap
,
733 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
734 __isl_take isl_printer
*p
, int latex
)
738 int rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
739 unsigned total
= isl_basic_map_total_dim(bmap
);
740 unsigned o_div
= isl_basic_map_offset(bmap
, isl_dim_div
);
746 bmap
= isl_basic_map_copy(bmap
);
749 bmap
= isl_basic_map_sort_constraints(bmap
);
753 c
= isl_vec_alloc(bmap
->ctx
, 1 + total
);
757 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
758 int l
= isl_seq_last_non_zero(bmap
->eq
[i
], 1 + total
);
760 if (i
!= bmap
->n_eq
- 1)
761 p
= isl_printer_print_str(p
, s_and
[latex
]);
762 p
= isl_printer_print_str(p
, "0 = 0");
766 p
= isl_printer_print_str(p
, s_and
[latex
]);
767 if (isl_int_is_neg(bmap
->eq
[i
][l
]))
768 isl_seq_cpy(c
->el
, bmap
->eq
[i
], 1 + total
);
770 isl_seq_neg(c
->el
, bmap
->eq
[i
], 1 + total
);
771 p
= print_eq_constraint(p
, space
, div
, c
->el
, l
, latex
);
774 for (i
= 0; i
< bmap
->n_ineq
; ++i
) {
775 int l
= isl_seq_last_non_zero(bmap
->ineq
[i
], 1 + total
);
781 if (!dump
&& l
>= o_div
&&
782 can_print_div_expr(p
, div
, l
- o_div
)) {
784 is_div
= isl_basic_map_is_div_constraint(bmap
,
785 bmap
->ineq
[i
], l
- o_div
);
792 p
= isl_printer_print_str(p
, s_and
[latex
]);
793 s
= isl_int_sgn(bmap
->ineq
[i
][l
]);
794 strict
= !rational
&& isl_int_is_negone(bmap
->ineq
[i
][0]);
796 isl_seq_cpy(c
->el
, bmap
->ineq
[i
], 1 + total
);
798 isl_seq_neg(c
->el
, bmap
->ineq
[i
], 1 + total
);
800 isl_int_set_si(c
->el
[0], 0);
801 if (!dump
&& next_is_opposite(bmap
, i
, l
)) {
802 op
= constraint_op(-s
, strict
, latex
);
803 p
= print_half_constraint(p
, space
, div
, c
->el
, l
,
807 op
= constraint_op(s
, strict
, latex
);
808 p
= print_constraint(p
, space
, div
, c
->el
, l
,
814 isl_basic_map_free(bmap
);
819 isl_basic_map_free(bmap
);
825 static __isl_give isl_printer
*print_div(__isl_keep isl_space
*dim
,
826 __isl_keep isl_mat
*div
, int pos
, __isl_take isl_printer
*p
)
831 return isl_printer_free(p
);
833 c
= p
->output_format
== ISL_FORMAT_C
;
834 p
= isl_printer_print_str(p
, c
? "floord(" : "floor((");
835 p
= print_affine_of_len(dim
, div
, p
,
836 div
->row
[pos
] + 1, div
->n_col
- 1);
837 p
= isl_printer_print_str(p
, c
? ", " : ")/");
838 p
= isl_printer_print_isl_int(p
, div
->row
[pos
][0]);
839 p
= isl_printer_print_str(p
, ")");
843 /* Print a comma separated list of div names, except those that have
844 * a definition that can be printed.
845 * If "print_defined_divs" is set, then those div names are printed
846 * as well, along with their definitions.
848 static __isl_give isl_printer
*print_div_list(__isl_take isl_printer
*p
,
849 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int latex
,
850 int print_defined_divs
)
856 if (!p
|| !space
|| !div
)
857 return isl_printer_free(p
);
859 n_div
= isl_mat_rows(div
);
861 for (i
= 0; i
< n_div
; ++i
) {
862 if (!print_defined_divs
&& can_print_div_expr(p
, div
, i
))
865 p
= isl_printer_print_str(p
, ", ");
866 p
= print_name(space
, p
, isl_dim_div
, i
, latex
);
868 if (!can_print_div_expr(p
, div
, i
))
870 p
= isl_printer_print_str(p
, " = ");
871 p
= print_div(space
, div
, i
, p
);
877 /* Does printing an object with local variables described by "div"
878 * require an "exists" clause?
879 * That is, are there any local variables without an explicit representation?
880 * An exists clause is also needed in "dump" mode because
881 * explicit div representations are not printed inline in that case.
883 static isl_bool
need_exists(__isl_keep isl_printer
*p
, __isl_keep isl_mat
*div
)
888 return isl_bool_error
;
889 n
= isl_mat_rows(div
);
891 return isl_bool_false
;
893 return isl_bool_true
;
894 for (i
= 0; i
< n
; ++i
)
895 if (!can_print_div_expr(p
, div
, i
))
896 return isl_bool_true
;
897 return isl_bool_false
;
900 /* Print the start of an exists clause, i.e.,
904 * In dump mode, local variables with an explicit definition are printed
905 * as well because they will not be printed inline.
907 static __isl_give isl_printer
*open_exists(__isl_take isl_printer
*p
,
908 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int latex
)
916 p
= isl_printer_print_str(p
, s_open_exists
[latex
]);
917 p
= print_div_list(p
, space
, div
, latex
, dump
);
918 p
= isl_printer_print_str(p
, ": ");
923 /* Remove the explicit representations of all local variables in "div".
925 static __isl_give isl_mat
*mark_all_unknown(__isl_take isl_mat
*div
)
932 n_div
= isl_mat_rows(div
);
933 for (i
= 0; i
< n_div
; ++i
)
934 div
= isl_mat_set_element_si(div
, i
, 0, 0);
938 /* Print the constraints of "bmap" to "p".
939 * The names of the variables are taken from "space".
940 * "latex" is set if the constraints should be printed in LaTeX format.
941 * Do not print inline explicit div representations in "dump" mode.
943 static __isl_give isl_printer
*print_disjunct(__isl_keep isl_basic_map
*bmap
,
944 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
953 div
= isl_basic_map_get_divs(bmap
);
954 exists
= need_exists(p
, div
);
955 if (exists
>= 0 && exists
)
956 p
= open_exists(p
, space
, div
, latex
);
959 div
= mark_all_unknown(div
);
960 p
= print_constraints(bmap
, space
, div
, p
, latex
);
963 if (exists
>= 0 && exists
)
964 p
= isl_printer_print_str(p
, s_close_exists
[latex
]);
968 /* Print a colon followed by the constraints of "bmap"
969 * to "p", provided there are any constraints.
970 * The names of the variables are taken from "space".
971 * "latex" is set if the constraints should be printed in LaTeX format.
973 static __isl_give isl_printer
*print_optional_disjunct(
974 __isl_keep isl_basic_map
*bmap
, __isl_keep isl_space
*space
,
975 __isl_take isl_printer
*p
, int latex
)
977 if (isl_basic_map_plain_is_universe(bmap
))
980 p
= isl_printer_print_str(p
, ": ");
981 p
= print_disjunct(bmap
, space
, p
, latex
);
986 static __isl_give isl_printer
*basic_map_print_omega(
987 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
989 p
= isl_printer_print_str(p
, "{ [");
990 p
= print_var_list(p
, bmap
->dim
, isl_dim_in
);
991 p
= isl_printer_print_str(p
, "] -> [");
992 p
= print_var_list(p
, bmap
->dim
, isl_dim_out
);
993 p
= isl_printer_print_str(p
, "] ");
994 p
= print_optional_disjunct(bmap
, bmap
->dim
, p
, 0);
995 p
= isl_printer_print_str(p
, " }");
999 static __isl_give isl_printer
*basic_set_print_omega(
1000 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
)
1002 p
= isl_printer_print_str(p
, "{ [");
1003 p
= print_var_list(p
, bset
->dim
, isl_dim_set
);
1004 p
= isl_printer_print_str(p
, "] ");
1005 p
= print_optional_disjunct(bset
, bset
->dim
, p
, 0);
1006 p
= isl_printer_print_str(p
, " }");
1010 static __isl_give isl_printer
*isl_map_print_omega(__isl_keep isl_map
*map
,
1011 __isl_take isl_printer
*p
)
1015 for (i
= 0; i
< map
->n
; ++i
) {
1017 p
= isl_printer_print_str(p
, " union ");
1018 p
= basic_map_print_omega(map
->p
[i
], p
);
1023 static __isl_give isl_printer
*isl_set_print_omega(__isl_keep isl_set
*set
,
1024 __isl_take isl_printer
*p
)
1028 for (i
= 0; i
< set
->n
; ++i
) {
1030 p
= isl_printer_print_str(p
, " union ");
1031 p
= basic_set_print_omega(set
->p
[i
], p
);
1036 /* Print the list of parameters in "space", followed by an arrow, to "p",
1037 * if there are any parameters.
1039 static __isl_give isl_printer
*print_param_tuple(__isl_take isl_printer
*p
,
1040 __isl_keep isl_space
*space
, struct isl_print_space_data
*data
)
1043 return isl_printer_free(p
);
1044 if (isl_space_dim(space
, isl_dim_param
) == 0)
1047 p
= print_tuple(space
, p
, isl_dim_param
, data
);
1048 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
1053 static __isl_give isl_printer
*isl_basic_map_print_isl(
1054 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
,
1057 struct isl_print_space_data data
= { .latex
= latex
};
1058 int rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
1060 p
= print_param_tuple(p
, bmap
->dim
, &data
);
1061 p
= isl_printer_print_str(p
, "{ ");
1062 p
= isl_print_space(bmap
->dim
, p
, rational
, &data
);
1063 p
= isl_printer_print_str(p
, " : ");
1064 p
= print_disjunct(bmap
, bmap
->dim
, p
, latex
);
1065 p
= isl_printer_print_str(p
, " }");
1069 /* Print the disjuncts of a map (or set) "map" to "p".
1070 * The names of the variables are taken from "space".
1071 * "latex" is set if the constraints should be printed in LaTeX format.
1073 static __isl_give isl_printer
*print_disjuncts_core(__isl_keep isl_map
*map
,
1074 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
1079 p
= isl_printer_print_str(p
, "false");
1080 for (i
= 0; i
< map
->n
; ++i
) {
1082 p
= isl_printer_print_str(p
, s_or
[latex
]);
1083 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
1084 p
= isl_printer_print_str(p
, "(");
1085 p
= print_disjunct(map
->p
[i
], space
, p
, latex
);
1086 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
1087 p
= isl_printer_print_str(p
, ")");
1092 /* Print the disjuncts of a map (or set) "map" to "p".
1093 * The names of the variables are taken from "space".
1094 * "hull" describes constraints shared by all disjuncts of "map".
1095 * "latex" is set if the constraints should be printed in LaTeX format.
1097 * Print the disjuncts as a conjunction of "hull" and
1098 * the result of removing the constraints of "hull" from "map".
1099 * If this result turns out to be the universe, then simply print "hull".
1101 static __isl_give isl_printer
*print_disjuncts_in_hull(__isl_keep isl_map
*map
,
1102 __isl_keep isl_space
*space
, __isl_take isl_basic_map
*hull
,
1103 __isl_take isl_printer
*p
, int latex
)
1105 isl_bool is_universe
;
1107 p
= print_disjunct(hull
, space
, p
, latex
);
1108 map
= isl_map_plain_gist_basic_map(isl_map_copy(map
), hull
);
1109 is_universe
= isl_map_plain_is_universe(map
);
1110 if (is_universe
< 0)
1113 p
= isl_printer_print_str(p
, s_and
[latex
]);
1114 p
= isl_printer_print_str(p
, "(");
1115 p
= print_disjuncts_core(map
, space
, p
, latex
);
1116 p
= isl_printer_print_str(p
, ")");
1123 isl_printer_free(p
);
1127 /* Print the disjuncts of a map (or set) "map" to "p".
1128 * The names of the variables are taken from "space".
1129 * "latex" is set if the constraints should be printed in LaTeX format.
1131 * If there are at least two disjuncts and "dump" mode is not turned out,
1132 * check for any shared constraints among all disjuncts.
1133 * If there are any, then print them separately in print_disjuncts_in_hull.
1135 static __isl_give isl_printer
*print_disjuncts(__isl_keep isl_map
*map
,
1136 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
1138 if (isl_map_plain_is_universe(map
))
1141 p
= isl_printer_print_str(p
, s_such_that
[latex
]);
1145 if (!p
->dump
&& map
->n
>= 2) {
1146 isl_basic_map
*hull
;
1147 isl_bool is_universe
;
1149 hull
= isl_map_plain_unshifted_simple_hull(isl_map_copy(map
));
1150 is_universe
= isl_basic_map_plain_is_universe(hull
);
1151 if (is_universe
< 0)
1152 p
= isl_printer_free(p
);
1153 else if (!is_universe
)
1154 return print_disjuncts_in_hull(map
, space
, hull
,
1156 isl_basic_map_free(hull
);
1159 return print_disjuncts_core(map
, space
, p
, latex
);
1162 /* Print the disjuncts of a map (or set).
1163 * The names of the variables are taken from "space".
1164 * "latex" is set if the constraints should be printed in LaTeX format.
1166 * If the map turns out to be a universal parameter domain, then
1167 * we need to print the colon. Otherwise, the output looks identical
1170 static __isl_give isl_printer
*print_disjuncts_map(__isl_keep isl_map
*map
,
1171 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
1173 if (isl_map_plain_is_universe(map
) && isl_space_is_params(map
->dim
))
1174 return isl_printer_print_str(p
, s_such_that
[latex
]);
1176 return print_disjuncts(map
, space
, p
, latex
);
1179 /* Print the disjuncts of a set.
1180 * The names of the variables are taken from "space".
1181 * "latex" is set if the constraints should be printed in LaTeX format.
1183 static __isl_give isl_printer
*print_disjuncts_set(__isl_keep isl_set
*set
,
1184 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
1186 return print_disjuncts_map(set_to_map(set
), space
, p
, latex
);
1189 struct isl_aff_split
{
1194 static void free_split(__isl_take
struct isl_aff_split
*split
, int n
)
1201 for (i
= 0; i
< n
; ++i
) {
1202 isl_basic_map_free(split
[i
].aff
);
1203 isl_map_free(split
[i
].map
);
1209 static __isl_give isl_basic_map
*get_aff(__isl_take isl_basic_map
*bmap
)
1212 unsigned nparam
, n_in
, n_out
, total
;
1214 bmap
= isl_basic_map_cow(bmap
);
1217 if (isl_basic_map_free_inequality(bmap
, bmap
->n_ineq
) < 0)
1220 nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
1221 n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
1222 n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
1223 total
= isl_basic_map_dim(bmap
, isl_dim_all
);
1224 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1225 j
= isl_seq_last_non_zero(bmap
->eq
[i
] + 1, total
);
1226 if (j
>= nparam
&& j
< nparam
+ n_in
+ n_out
&&
1227 (isl_int_is_one(bmap
->eq
[i
][1 + j
]) ||
1228 isl_int_is_negone(bmap
->eq
[i
][1 + j
])))
1230 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1234 bmap
= isl_basic_map_finalize(bmap
);
1238 isl_basic_map_free(bmap
);
1242 static int aff_split_cmp(const void *p1
, const void *p2
, void *user
)
1244 const struct isl_aff_split
*s1
, *s2
;
1245 s1
= (const struct isl_aff_split
*) p1
;
1246 s2
= (const struct isl_aff_split
*) p2
;
1248 return isl_basic_map_plain_cmp(s1
->aff
, s2
->aff
);
1251 static __isl_give isl_basic_map
*drop_aff(__isl_take isl_basic_map
*bmap
,
1252 __isl_keep isl_basic_map
*aff
)
1260 total
= isl_space_dim(bmap
->dim
, isl_dim_all
);
1262 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1263 if (isl_seq_first_non_zero(bmap
->eq
[i
] + 1 + total
,
1266 for (j
= 0; j
< aff
->n_eq
; ++j
) {
1267 if (!isl_seq_eq(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
) &&
1268 !isl_seq_is_neg(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
))
1270 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1278 isl_basic_map_free(bmap
);
1282 static __isl_give
struct isl_aff_split
*split_aff(__isl_keep isl_map
*map
)
1285 struct isl_aff_split
*split
;
1288 ctx
= isl_map_get_ctx(map
);
1289 split
= isl_calloc_array(ctx
, struct isl_aff_split
, map
->n
);
1293 for (i
= 0; i
< map
->n
; ++i
) {
1294 isl_basic_map
*bmap
;
1295 split
[i
].aff
= get_aff(isl_basic_map_copy(map
->p
[i
]));
1296 bmap
= isl_basic_map_copy(map
->p
[i
]);
1297 bmap
= isl_basic_map_cow(bmap
);
1298 bmap
= drop_aff(bmap
, split
[i
].aff
);
1299 split
[i
].map
= isl_map_from_basic_map(bmap
);
1300 if (!split
[i
].aff
|| !split
[i
].map
)
1304 if (isl_sort(split
, map
->n
, sizeof(struct isl_aff_split
),
1305 &aff_split_cmp
, NULL
) < 0)
1309 for (i
= n
- 1; i
>= 1; --i
) {
1310 if (!isl_basic_map_plain_is_equal(split
[i
- 1].aff
,
1313 isl_basic_map_free(split
[i
].aff
);
1314 split
[i
- 1].map
= isl_map_union(split
[i
- 1].map
,
1317 split
[i
] = split
[n
- 1];
1318 split
[n
- 1].aff
= NULL
;
1319 split
[n
- 1].map
= NULL
;
1325 free_split(split
, map
->n
);
1329 static int defining_equality(__isl_keep isl_basic_map
*eq
,
1330 __isl_keep isl_space
*dim
, enum isl_dim_type type
, int pos
)
1338 pos
+= isl_space_offset(dim
, type
);
1339 total
= isl_basic_map_total_dim(eq
);
1341 for (i
= 0; i
< eq
->n_eq
; ++i
) {
1342 if (isl_seq_last_non_zero(eq
->eq
[i
] + 1, total
) != pos
)
1344 if (isl_int_is_one(eq
->eq
[i
][1 + pos
]))
1345 isl_seq_neg(eq
->eq
[i
], eq
->eq
[i
], 1 + total
);
1352 /* Print dimension "pos" of data->space to "p".
1354 * data->user is assumed to be an isl_basic_map keeping track of equalities.
1356 * If the current dimension is defined by these equalities, then print
1357 * the corresponding expression, assigned to the name of the dimension
1358 * if there is any. Otherwise, print the name of the dimension.
1360 static __isl_give isl_printer
*print_dim_eq(__isl_take isl_printer
*p
,
1361 struct isl_print_space_data
*data
, unsigned pos
)
1363 isl_basic_map
*eq
= data
->user
;
1366 j
= defining_equality(eq
, data
->space
, data
->type
, pos
);
1368 if (isl_space_has_dim_name(data
->space
, data
->type
, pos
)) {
1369 p
= print_name(data
->space
, p
, data
->type
, pos
,
1371 p
= isl_printer_print_str(p
, " = ");
1373 pos
+= 1 + isl_space_offset(data
->space
, data
->type
);
1374 p
= print_affine_of_len(data
->space
, NULL
, p
, eq
->eq
[j
], pos
);
1376 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
1382 static __isl_give isl_printer
*print_split_map(__isl_take isl_printer
*p
,
1383 struct isl_aff_split
*split
, int n
, __isl_keep isl_space
*space
)
1385 struct isl_print_space_data data
= { 0 };
1389 data
.print_dim
= &print_dim_eq
;
1390 for (i
= 0; i
< n
; ++i
) {
1393 rational
= split
[i
].map
->n
> 0 &&
1394 ISL_F_ISSET(split
[i
].map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1396 p
= isl_printer_print_str(p
, "; ");
1397 data
.user
= split
[i
].aff
;
1398 p
= isl_print_space(space
, p
, rational
, &data
);
1399 p
= print_disjuncts_map(split
[i
].map
, space
, p
, 0);
1405 static __isl_give isl_printer
*isl_map_print_isl_body(__isl_keep isl_map
*map
,
1406 __isl_take isl_printer
*p
)
1408 struct isl_print_space_data data
= { 0 };
1409 struct isl_aff_split
*split
= NULL
;
1413 return isl_printer_free(p
);
1414 if (!p
->dump
&& map
->n
> 0)
1415 split
= split_aff(map
);
1417 p
= print_split_map(p
, split
, map
->n
, map
->dim
);
1419 rational
= map
->n
> 0 &&
1420 ISL_F_ISSET(map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1421 p
= isl_print_space(map
->dim
, p
, rational
, &data
);
1422 p
= print_disjuncts_map(map
, map
->dim
, p
, 0);
1424 free_split(split
, map
->n
);
1428 static __isl_give isl_printer
*isl_map_print_isl(__isl_keep isl_map
*map
,
1429 __isl_take isl_printer
*p
)
1431 struct isl_print_space_data data
= { 0 };
1433 p
= print_param_tuple(p
, map
->dim
, &data
);
1434 p
= isl_printer_print_str(p
, s_open_set
[0]);
1435 p
= isl_map_print_isl_body(map
, p
);
1436 p
= isl_printer_print_str(p
, s_close_set
[0]);
1440 static __isl_give isl_printer
*print_latex_map(__isl_keep isl_map
*map
,
1441 __isl_take isl_printer
*p
, __isl_keep isl_basic_map
*aff
)
1443 struct isl_print_space_data data
= { 0 };
1446 p
= print_param_tuple(p
, map
->dim
, &data
);
1447 p
= isl_printer_print_str(p
, s_open_set
[1]);
1448 data
.print_dim
= &print_dim_eq
;
1450 p
= isl_print_space(map
->dim
, p
, 0, &data
);
1451 p
= print_disjuncts_map(map
, map
->dim
, p
, 1);
1452 p
= isl_printer_print_str(p
, s_close_set
[1]);
1457 static __isl_give isl_printer
*isl_map_print_latex(__isl_keep isl_map
*map
,
1458 __isl_take isl_printer
*p
)
1461 struct isl_aff_split
*split
= NULL
;
1464 split
= split_aff(map
);
1467 return print_latex_map(map
, p
, NULL
);
1469 for (i
= 0; i
< map
->n
; ++i
) {
1473 p
= isl_printer_print_str(p
, " \\cup ");
1474 p
= print_latex_map(split
[i
].map
, p
, split
[i
].aff
);
1477 free_split(split
, map
->n
);
1481 __isl_give isl_printer
*isl_printer_print_basic_map(__isl_take isl_printer
*p
,
1482 __isl_keep isl_basic_map
*bmap
)
1486 if (p
->output_format
== ISL_FORMAT_ISL
)
1487 return isl_basic_map_print_isl(bmap
, p
, 0);
1488 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1489 return basic_map_print_omega(bmap
, p
);
1490 isl_assert(bmap
->ctx
, 0, goto error
);
1492 isl_printer_free(p
);
1496 __isl_give isl_printer
*isl_printer_print_basic_set(__isl_take isl_printer
*p
,
1497 __isl_keep isl_basic_set
*bset
)
1502 if (p
->output_format
== ISL_FORMAT_ISL
)
1503 return isl_basic_map_print_isl(bset
, p
, 0);
1504 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1505 return isl_basic_set_print_polylib(bset
, p
, 0);
1506 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1507 return isl_basic_set_print_polylib(bset
, p
, 1);
1508 else if (p
->output_format
== ISL_FORMAT_POLYLIB_CONSTRAINTS
)
1509 return bset_print_constraints_polylib(bset
, p
);
1510 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1511 return basic_set_print_omega(bset
, p
);
1512 isl_assert(p
->ctx
, 0, goto error
);
1514 isl_printer_free(p
);
1518 __isl_give isl_printer
*isl_printer_print_set(__isl_take isl_printer
*p
,
1519 __isl_keep isl_set
*set
)
1523 if (p
->output_format
== ISL_FORMAT_ISL
)
1524 return isl_map_print_isl(set_to_map(set
), p
);
1525 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1526 return isl_set_print_polylib(set
, p
, 0);
1527 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1528 return isl_set_print_polylib(set
, p
, 1);
1529 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1530 return isl_set_print_omega(set
, p
);
1531 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1532 return isl_map_print_latex(set_to_map(set
), p
);
1533 isl_assert(set
->ctx
, 0, goto error
);
1535 isl_printer_free(p
);
1539 __isl_give isl_printer
*isl_printer_print_map(__isl_take isl_printer
*p
,
1540 __isl_keep isl_map
*map
)
1545 if (p
->output_format
== ISL_FORMAT_ISL
)
1546 return isl_map_print_isl(map
, p
);
1547 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1548 return isl_map_print_polylib(map
, p
, 0);
1549 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1550 return isl_map_print_polylib(map
, p
, 1);
1551 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1552 return isl_map_print_omega(map
, p
);
1553 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1554 return isl_map_print_latex(map
, p
);
1555 isl_assert(map
->ctx
, 0, goto error
);
1557 isl_printer_free(p
);
1561 struct isl_union_print_data
{
1566 static isl_stat
print_map_body(__isl_take isl_map
*map
, void *user
)
1568 struct isl_union_print_data
*data
;
1569 data
= (struct isl_union_print_data
*)user
;
1572 data
->p
= isl_printer_print_str(data
->p
, "; ");
1575 data
->p
= isl_map_print_isl_body(map
, data
->p
);
1581 /* Print the body of "umap" (everything except the parameter declarations)
1582 * to "p" in isl format.
1584 static __isl_give isl_printer
*isl_printer_print_union_map_isl_body(
1585 __isl_take isl_printer
*p
, __isl_keep isl_union_map
*umap
)
1587 struct isl_union_print_data data
;
1589 p
= isl_printer_print_str(p
, s_open_set
[0]);
1592 isl_union_map_foreach_map(umap
, &print_map_body
, &data
);
1594 p
= isl_printer_print_str(p
, s_close_set
[0]);
1598 /* Print the body of "uset" (everything except the parameter declarations)
1599 * to "p" in isl format.
1601 static __isl_give isl_printer
*isl_printer_print_union_set_isl_body(
1602 __isl_take isl_printer
*p
, __isl_keep isl_union_set
*uset
)
1604 return isl_printer_print_union_map_isl_body(p
, uset_to_umap(uset
));
1607 /* Print the isl_union_map "umap" to "p" in isl format.
1609 static __isl_give isl_printer
*isl_union_map_print_isl(
1610 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1612 struct isl_print_space_data space_data
= { 0 };
1615 space
= isl_union_map_get_space(umap
);
1616 p
= print_param_tuple(p
, space
, &space_data
);
1617 isl_space_free(space
);
1619 p
= isl_printer_print_union_map_isl_body(p
, umap
);
1624 static isl_stat
print_latex_map_body(__isl_take isl_map
*map
, void *user
)
1626 struct isl_union_print_data
*data
;
1627 data
= (struct isl_union_print_data
*)user
;
1630 data
->p
= isl_printer_print_str(data
->p
, " \\cup ");
1633 data
->p
= isl_map_print_latex(map
, data
->p
);
1639 static __isl_give isl_printer
*isl_union_map_print_latex(
1640 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1642 struct isl_union_print_data data
= { p
, 1 };
1643 isl_union_map_foreach_map(umap
, &print_latex_map_body
, &data
);
1648 __isl_give isl_printer
*isl_printer_print_union_map(__isl_take isl_printer
*p
,
1649 __isl_keep isl_union_map
*umap
)
1654 if (p
->output_format
== ISL_FORMAT_ISL
)
1655 return isl_union_map_print_isl(umap
, p
);
1656 if (p
->output_format
== ISL_FORMAT_LATEX
)
1657 return isl_union_map_print_latex(umap
, p
);
1659 isl_die(p
->ctx
, isl_error_invalid
,
1660 "invalid output format for isl_union_map", goto error
);
1662 isl_printer_free(p
);
1666 __isl_give isl_printer
*isl_printer_print_union_set(__isl_take isl_printer
*p
,
1667 __isl_keep isl_union_set
*uset
)
1672 if (p
->output_format
== ISL_FORMAT_ISL
)
1673 return isl_union_map_print_isl(uset_to_umap(uset
), p
);
1674 if (p
->output_format
== ISL_FORMAT_LATEX
)
1675 return isl_union_map_print_latex(uset_to_umap(uset
), p
);
1677 isl_die(p
->ctx
, isl_error_invalid
,
1678 "invalid output format for isl_union_set", goto error
);
1680 isl_printer_free(p
);
1684 static int upoly_rec_n_non_zero(__isl_keep
struct isl_upoly_rec
*rec
)
1689 for (i
= 0, n
= 0; i
< rec
->n
; ++i
)
1690 if (!isl_upoly_is_zero(rec
->p
[i
]))
1696 static __isl_give isl_printer
*upoly_print_cst(__isl_keep
struct isl_upoly
*up
,
1697 __isl_take isl_printer
*p
, int first
)
1699 struct isl_upoly_cst
*cst
;
1702 cst
= isl_upoly_as_cst(up
);
1705 neg
= !first
&& isl_int_is_neg(cst
->n
);
1707 p
= isl_printer_print_str(p
, neg
? " - " : " + ");
1709 isl_int_neg(cst
->n
, cst
->n
);
1710 if (isl_int_is_zero(cst
->d
)) {
1711 int sgn
= isl_int_sgn(cst
->n
);
1712 p
= isl_printer_print_str(p
, sgn
< 0 ? "-infty" :
1713 sgn
== 0 ? "NaN" : "infty");
1715 p
= isl_printer_print_isl_int(p
, cst
->n
);
1717 isl_int_neg(cst
->n
, cst
->n
);
1718 if (!isl_int_is_zero(cst
->d
) && !isl_int_is_one(cst
->d
)) {
1719 p
= isl_printer_print_str(p
, "/");
1720 p
= isl_printer_print_isl_int(p
, cst
->d
);
1724 isl_printer_free(p
);
1728 static __isl_give isl_printer
*print_base(__isl_take isl_printer
*p
,
1729 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
)
1733 total
= isl_space_dim(dim
, isl_dim_all
);
1735 p
= print_term(dim
, NULL
, dim
->ctx
->one
, 1 + var
, p
, 0);
1737 p
= print_div(dim
, div
, var
- total
, p
);
1741 static __isl_give isl_printer
*print_pow(__isl_take isl_printer
*p
,
1742 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
, int exp
)
1744 p
= print_base(p
, dim
, div
, var
);
1747 if (p
->output_format
== ISL_FORMAT_C
) {
1749 for (i
= 1; i
< exp
; ++i
) {
1750 p
= isl_printer_print_str(p
, "*");
1751 p
= print_base(p
, dim
, div
, var
);
1754 p
= isl_printer_print_str(p
, "^");
1755 p
= isl_printer_print_int(p
, exp
);
1760 /* Print the polynomial "up" defined over the domain space "space" and
1761 * local variables defined by "div" to "p".
1763 static __isl_give isl_printer
*upoly_print(__isl_keep
struct isl_upoly
*up
,
1764 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
1765 __isl_take isl_printer
*p
)
1767 int i
, n
, first
, print_parens
;
1768 struct isl_upoly_rec
*rec
;
1770 if (!p
|| !up
|| !space
|| !div
)
1773 if (isl_upoly_is_cst(up
))
1774 return upoly_print_cst(up
, p
, 1);
1776 rec
= isl_upoly_as_rec(up
);
1779 n
= upoly_rec_n_non_zero(rec
);
1780 print_parens
= n
> 1;
1782 p
= isl_printer_print_str(p
, "(");
1783 for (i
= 0, first
= 1; i
< rec
->n
; ++i
) {
1784 if (isl_upoly_is_zero(rec
->p
[i
]))
1786 if (isl_upoly_is_negone(rec
->p
[i
])) {
1788 p
= isl_printer_print_str(p
, "-1");
1790 p
= isl_printer_print_str(p
, "-");
1792 p
= isl_printer_print_str(p
, " - ");
1793 } else if (isl_upoly_is_cst(rec
->p
[i
]) &&
1794 !isl_upoly_is_one(rec
->p
[i
]))
1795 p
= upoly_print_cst(rec
->p
[i
], p
, first
);
1798 p
= isl_printer_print_str(p
, " + ");
1799 if (i
== 0 || !isl_upoly_is_one(rec
->p
[i
]))
1800 p
= upoly_print(rec
->p
[i
], space
, div
, p
);
1805 if (!isl_upoly_is_one(rec
->p
[i
]) &&
1806 !isl_upoly_is_negone(rec
->p
[i
]))
1807 p
= isl_printer_print_str(p
, " * ");
1808 p
= print_pow(p
, space
, div
, rec
->up
.var
, i
);
1811 p
= isl_printer_print_str(p
, ")");
1814 isl_printer_free(p
);
1818 static __isl_give isl_printer
*print_qpolynomial(__isl_take isl_printer
*p
,
1819 __isl_keep isl_qpolynomial
*qp
)
1823 p
= upoly_print(qp
->upoly
, qp
->dim
, qp
->div
, p
);
1826 isl_printer_free(p
);
1830 static __isl_give isl_printer
*print_qpolynomial_isl(__isl_take isl_printer
*p
,
1831 __isl_keep isl_qpolynomial
*qp
)
1833 struct isl_print_space_data data
= { 0 };
1838 p
= print_param_tuple(p
, qp
->dim
, &data
);
1839 p
= isl_printer_print_str(p
, "{ ");
1840 if (!isl_space_is_params(qp
->dim
)) {
1841 p
= isl_print_space(qp
->dim
, p
, 0, &data
);
1842 p
= isl_printer_print_str(p
, " -> ");
1844 p
= print_qpolynomial(p
, qp
);
1845 p
= isl_printer_print_str(p
, " }");
1848 isl_printer_free(p
);
1852 /* Print the quasi-polynomial "qp" to "p" in C format, with the variable names
1853 * taken from the domain space "space".
1855 static __isl_give isl_printer
*print_qpolynomial_c(__isl_take isl_printer
*p
,
1856 __isl_keep isl_space
*space
, __isl_keep isl_qpolynomial
*qp
)
1861 isl_qpolynomial_get_den(qp
, &den
);
1862 if (!isl_int_is_one(den
)) {
1864 p
= isl_printer_print_str(p
, "(");
1865 qp
= isl_qpolynomial_copy(qp
);
1866 f
= isl_qpolynomial_rat_cst_on_domain(isl_space_copy(qp
->dim
),
1867 den
, qp
->dim
->ctx
->one
);
1868 qp
= isl_qpolynomial_mul(qp
, f
);
1871 p
= upoly_print(qp
->upoly
, space
, qp
->div
, p
);
1873 p
= isl_printer_free(p
);
1874 if (!isl_int_is_one(den
)) {
1875 p
= isl_printer_print_str(p
, ")/");
1876 p
= isl_printer_print_isl_int(p
, den
);
1877 isl_qpolynomial_free(qp
);
1883 __isl_give isl_printer
*isl_printer_print_qpolynomial(
1884 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial
*qp
)
1889 if (p
->output_format
== ISL_FORMAT_ISL
)
1890 return print_qpolynomial_isl(p
, qp
);
1891 else if (p
->output_format
== ISL_FORMAT_C
)
1892 return print_qpolynomial_c(p
, qp
->dim
, qp
);
1894 isl_die(qp
->dim
->ctx
, isl_error_unsupported
,
1895 "output format not supported for isl_qpolynomials",
1898 isl_printer_free(p
);
1902 void isl_qpolynomial_print(__isl_keep isl_qpolynomial
*qp
, FILE *out
,
1903 unsigned output_format
)
1910 isl_assert(qp
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1911 p
= isl_printer_to_file(qp
->dim
->ctx
, out
);
1912 p
= isl_printer_print_qpolynomial(p
, qp
);
1913 isl_printer_free(p
);
1916 static __isl_give isl_printer
*qpolynomial_fold_print(
1917 __isl_keep isl_qpolynomial_fold
*fold
, __isl_take isl_printer
*p
)
1921 if (fold
->type
== isl_fold_min
)
1922 p
= isl_printer_print_str(p
, "min");
1923 else if (fold
->type
== isl_fold_max
)
1924 p
= isl_printer_print_str(p
, "max");
1925 p
= isl_printer_print_str(p
, "(");
1926 for (i
= 0; i
< fold
->n
; ++i
) {
1928 p
= isl_printer_print_str(p
, ", ");
1929 p
= print_qpolynomial(p
, fold
->qp
[i
]);
1931 p
= isl_printer_print_str(p
, ")");
1935 void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold
*fold
,
1936 FILE *out
, unsigned output_format
)
1943 isl_assert(fold
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1945 p
= isl_printer_to_file(fold
->dim
->ctx
, out
);
1946 p
= isl_printer_print_qpolynomial_fold(p
, fold
);
1948 isl_printer_free(p
);
1951 static __isl_give isl_printer
*isl_pwqp_print_isl_body(
1952 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1954 struct isl_print_space_data data
= { 0 };
1957 for (i
= 0; i
< pwqp
->n
; ++i
) {
1961 p
= isl_printer_print_str(p
, "; ");
1962 space
= isl_qpolynomial_get_domain_space(pwqp
->p
[i
].qp
);
1963 if (!isl_space_is_params(space
)) {
1964 p
= isl_print_space(space
, p
, 0, &data
);
1965 p
= isl_printer_print_str(p
, " -> ");
1967 p
= print_qpolynomial(p
, pwqp
->p
[i
].qp
);
1968 p
= print_disjuncts(set_to_map(pwqp
->p
[i
].set
), space
, p
, 0);
1969 isl_space_free(space
);
1975 static __isl_give isl_printer
*print_pw_qpolynomial_isl(
1976 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1978 struct isl_print_space_data data
= { 0 };
1983 p
= print_param_tuple(p
, pwqp
->dim
, &data
);
1984 p
= isl_printer_print_str(p
, "{ ");
1986 if (!isl_space_is_set(pwqp
->dim
)) {
1987 p
= print_tuple(pwqp
->dim
, p
, isl_dim_in
, &data
);
1988 p
= isl_printer_print_str(p
, " -> ");
1990 p
= isl_printer_print_str(p
, "0");
1992 p
= isl_pwqp_print_isl_body(p
, pwqp
);
1993 p
= isl_printer_print_str(p
, " }");
1996 isl_printer_free(p
);
2000 void isl_pw_qpolynomial_print(__isl_keep isl_pw_qpolynomial
*pwqp
, FILE *out
,
2001 unsigned output_format
)
2008 p
= isl_printer_to_file(pwqp
->dim
->ctx
, out
);
2009 p
= isl_printer_set_output_format(p
, output_format
);
2010 p
= isl_printer_print_pw_qpolynomial(p
, pwqp
);
2012 isl_printer_free(p
);
2015 static __isl_give isl_printer
*isl_pwf_print_isl_body(
2016 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2018 struct isl_print_space_data data
= { 0 };
2021 for (i
= 0; i
< pwf
->n
; ++i
) {
2025 p
= isl_printer_print_str(p
, "; ");
2026 space
= isl_qpolynomial_fold_get_domain_space(pwf
->p
[i
].fold
);
2027 if (!isl_space_is_params(space
)) {
2028 p
= isl_print_space(space
, p
, 0, &data
);
2029 p
= isl_printer_print_str(p
, " -> ");
2031 p
= qpolynomial_fold_print(pwf
->p
[i
].fold
, p
);
2032 p
= print_disjuncts(set_to_map(pwf
->p
[i
].set
), space
, p
, 0);
2033 isl_space_free(space
);
2039 static __isl_give isl_printer
*print_pw_qpolynomial_fold_isl(
2040 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2042 struct isl_print_space_data data
= { 0 };
2044 p
= print_param_tuple(p
, pwf
->dim
, &data
);
2045 p
= isl_printer_print_str(p
, "{ ");
2047 if (!isl_space_is_set(pwf
->dim
)) {
2048 p
= print_tuple(pwf
->dim
, p
, isl_dim_in
, &data
);
2049 p
= isl_printer_print_str(p
, " -> ");
2051 p
= isl_printer_print_str(p
, "0");
2053 p
= isl_pwf_print_isl_body(p
, pwf
);
2054 p
= isl_printer_print_str(p
, " }");
2058 static __isl_give isl_printer
*print_affine_c(__isl_take isl_printer
*p
,
2059 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
, isl_int
*c
);
2061 static __isl_give isl_printer
*print_name_c(__isl_take isl_printer
*p
,
2062 __isl_keep isl_space
*dim
,
2063 __isl_keep isl_basic_set
*bset
, enum isl_dim_type type
, unsigned pos
)
2065 if (type
== isl_dim_div
) {
2066 p
= isl_printer_print_str(p
, "floord(");
2067 p
= print_affine_c(p
, dim
, bset
, bset
->div
[pos
] + 1);
2068 p
= isl_printer_print_str(p
, ", ");
2069 p
= isl_printer_print_isl_int(p
, bset
->div
[pos
][0]);
2070 p
= isl_printer_print_str(p
, ")");
2074 name
= isl_space_get_dim_name(dim
, type
, pos
);
2077 p
= isl_printer_print_str(p
, name
);
2082 static __isl_give isl_printer
*print_term_c(__isl_take isl_printer
*p
,
2083 __isl_keep isl_space
*dim
,
2084 __isl_keep isl_basic_set
*bset
, isl_int c
, unsigned pos
)
2086 enum isl_dim_type type
;
2089 return isl_printer_print_isl_int(p
, c
);
2091 if (isl_int_is_one(c
))
2093 else if (isl_int_is_negone(c
))
2094 p
= isl_printer_print_str(p
, "-");
2096 p
= isl_printer_print_isl_int(p
, c
);
2097 p
= isl_printer_print_str(p
, "*");
2099 type
= pos2type(dim
, &pos
);
2100 p
= print_name_c(p
, dim
, bset
, type
, pos
);
2104 static __isl_give isl_printer
*print_partial_affine_c(__isl_take isl_printer
*p
,
2105 __isl_keep isl_space
*dim
,
2106 __isl_keep isl_basic_set
*bset
, isl_int
*c
, unsigned len
)
2111 for (i
= 0, first
= 1; i
< len
; ++i
) {
2113 if (isl_int_is_zero(c
[i
]))
2116 if (isl_int_is_neg(c
[i
])) {
2118 isl_int_neg(c
[i
], c
[i
]);
2119 p
= isl_printer_print_str(p
, " - ");
2121 p
= isl_printer_print_str(p
, " + ");
2124 p
= print_term_c(p
, dim
, bset
, c
[i
], i
);
2126 isl_int_neg(c
[i
], c
[i
]);
2129 p
= isl_printer_print_str(p
, "0");
2133 static __isl_give isl_printer
*print_affine_c(__isl_take isl_printer
*p
,
2134 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
, isl_int
*c
)
2136 unsigned len
= 1 + isl_basic_set_total_dim(bset
);
2137 return print_partial_affine_c(p
, dim
, bset
, c
, len
);
2140 /* We skip the constraint if it is implied by the div expression.
2142 * *first indicates whether this is the first constraint in the conjunction and
2143 * is updated if the constraint is actually printed.
2145 static __isl_give isl_printer
*print_constraint_c(__isl_take isl_printer
*p
,
2146 __isl_keep isl_space
*dim
,
2147 __isl_keep isl_basic_set
*bset
, isl_int
*c
, const char *op
, int *first
)
2153 o_div
= isl_basic_set_offset(bset
, isl_dim_div
);
2154 n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
2155 div
= isl_seq_last_non_zero(c
+ o_div
, n_div
);
2157 isl_bool is_div
= isl_basic_set_is_div_constraint(bset
, c
, div
);
2159 return isl_printer_free(p
);
2165 p
= isl_printer_print_str(p
, " && ");
2167 p
= print_affine_c(p
, dim
, bset
, c
);
2168 p
= isl_printer_print_str(p
, " ");
2169 p
= isl_printer_print_str(p
, op
);
2170 p
= isl_printer_print_str(p
, " 0");
2177 static __isl_give isl_printer
*print_basic_set_c(__isl_take isl_printer
*p
,
2178 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
)
2182 unsigned n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
2183 unsigned total
= isl_basic_set_total_dim(bset
) - n_div
;
2185 for (i
= 0; i
< bset
->n_eq
; ++i
) {
2186 j
= isl_seq_last_non_zero(bset
->eq
[i
] + 1 + total
, n_div
);
2188 p
= print_constraint_c(p
, dim
, bset
,
2189 bset
->eq
[i
], "==", &first
);
2192 p
= isl_printer_print_str(p
, " && ");
2193 p
= isl_printer_print_str(p
, "(");
2194 p
= print_partial_affine_c(p
, dim
, bset
, bset
->eq
[i
],
2196 p
= isl_printer_print_str(p
, ") % ");
2197 p
= isl_printer_print_isl_int(p
,
2198 bset
->eq
[i
][1 + total
+ j
]);
2199 p
= isl_printer_print_str(p
, " == 0");
2203 for (i
= 0; i
< bset
->n_ineq
; ++i
)
2204 p
= print_constraint_c(p
, dim
, bset
, bset
->ineq
[i
], ">=",
2209 static __isl_give isl_printer
*print_set_c(__isl_take isl_printer
*p
,
2210 __isl_keep isl_space
*dim
, __isl_keep isl_set
*set
)
2215 return isl_printer_free(p
);
2218 p
= isl_printer_print_str(p
, "0");
2220 for (i
= 0; i
< set
->n
; ++i
) {
2222 p
= isl_printer_print_str(p
, " || ");
2224 p
= isl_printer_print_str(p
, "(");
2225 p
= print_basic_set_c(p
, dim
, set
->p
[i
]);
2227 p
= isl_printer_print_str(p
, ")");
2232 /* Print the piecewise quasi-polynomial "pwqp" to "p" in C format.
2234 static __isl_give isl_printer
*print_pw_qpolynomial_c(
2235 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2240 space
= isl_pw_qpolynomial_get_domain_space(pwqp
);
2241 if (pwqp
->n
== 1 && isl_set_plain_is_universe(pwqp
->p
[0].set
)) {
2242 p
= print_qpolynomial_c(p
, space
, pwqp
->p
[0].qp
);
2243 isl_space_free(space
);
2247 for (i
= 0; i
< pwqp
->n
; ++i
) {
2248 p
= isl_printer_print_str(p
, "(");
2249 p
= print_set_c(p
, space
, pwqp
->p
[i
].set
);
2250 p
= isl_printer_print_str(p
, ") ? (");
2251 p
= print_qpolynomial_c(p
, space
, pwqp
->p
[i
].qp
);
2252 p
= isl_printer_print_str(p
, ") : ");
2255 isl_space_free(space
);
2256 p
= isl_printer_print_str(p
, "0");
2260 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial(
2261 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2266 if (p
->output_format
== ISL_FORMAT_ISL
)
2267 return print_pw_qpolynomial_isl(p
, pwqp
);
2268 else if (p
->output_format
== ISL_FORMAT_C
)
2269 return print_pw_qpolynomial_c(p
, pwqp
);
2270 isl_assert(p
->ctx
, 0, goto error
);
2272 isl_printer_free(p
);
2276 static isl_stat
print_pwqp_body(__isl_take isl_pw_qpolynomial
*pwqp
, void *user
)
2278 struct isl_union_print_data
*data
;
2279 data
= (struct isl_union_print_data
*)user
;
2282 data
->p
= isl_printer_print_str(data
->p
, "; ");
2285 data
->p
= isl_pwqp_print_isl_body(data
->p
, pwqp
);
2286 isl_pw_qpolynomial_free(pwqp
);
2291 static __isl_give isl_printer
*print_union_pw_qpolynomial_isl(
2292 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2294 struct isl_union_print_data data
;
2295 struct isl_print_space_data space_data
= { 0 };
2298 space
= isl_union_pw_qpolynomial_get_space(upwqp
);
2299 p
= print_param_tuple(p
, space
, &space_data
);
2300 isl_space_free(space
);
2301 p
= isl_printer_print_str(p
, "{ ");
2304 isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp
, &print_pwqp_body
,
2307 p
= isl_printer_print_str(p
, " }");
2311 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial(
2312 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2317 if (p
->output_format
== ISL_FORMAT_ISL
)
2318 return print_union_pw_qpolynomial_isl(p
, upwqp
);
2319 isl_die(p
->ctx
, isl_error_invalid
,
2320 "invalid output format for isl_union_pw_qpolynomial",
2323 isl_printer_free(p
);
2327 /* Print the quasi-polynomial reduction "fold" to "p" in C format,
2328 * with the variable names taken from the domain space "space".
2330 static __isl_give isl_printer
*print_qpolynomial_fold_c(
2331 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
,
2332 __isl_keep isl_qpolynomial_fold
*fold
)
2336 for (i
= 0; i
< fold
->n
- 1; ++i
)
2337 if (fold
->type
== isl_fold_min
)
2338 p
= isl_printer_print_str(p
, "min(");
2339 else if (fold
->type
== isl_fold_max
)
2340 p
= isl_printer_print_str(p
, "max(");
2342 for (i
= 0; i
< fold
->n
; ++i
) {
2344 p
= isl_printer_print_str(p
, ", ");
2345 p
= print_qpolynomial_c(p
, space
, fold
->qp
[i
]);
2347 p
= isl_printer_print_str(p
, ")");
2352 __isl_give isl_printer
*isl_printer_print_qpolynomial_fold(
2353 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial_fold
*fold
)
2357 if (p
->output_format
== ISL_FORMAT_ISL
)
2358 return qpolynomial_fold_print(fold
, p
);
2359 else if (p
->output_format
== ISL_FORMAT_C
)
2360 return print_qpolynomial_fold_c(p
, fold
->dim
, fold
);
2361 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2364 isl_printer_free(p
);
2368 /* Print the piecewise quasi-polynomial reduction "pwf" to "p" in C format.
2370 static __isl_give isl_printer
*print_pw_qpolynomial_fold_c(
2371 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2376 space
= isl_pw_qpolynomial_fold_get_domain_space(pwf
);
2377 if (pwf
->n
== 1 && isl_set_plain_is_universe(pwf
->p
[0].set
)) {
2378 p
= print_qpolynomial_fold_c(p
, space
, pwf
->p
[0].fold
);
2379 isl_space_free(space
);
2383 for (i
= 0; i
< pwf
->n
; ++i
) {
2384 p
= isl_printer_print_str(p
, "(");
2385 p
= print_set_c(p
, space
, pwf
->p
[i
].set
);
2386 p
= isl_printer_print_str(p
, ") ? (");
2387 p
= print_qpolynomial_fold_c(p
, space
, pwf
->p
[i
].fold
);
2388 p
= isl_printer_print_str(p
, ") : ");
2391 isl_space_free(space
);
2392 p
= isl_printer_print_str(p
, "0");
2396 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial_fold(
2397 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2402 if (p
->output_format
== ISL_FORMAT_ISL
)
2403 return print_pw_qpolynomial_fold_isl(p
, pwf
);
2404 else if (p
->output_format
== ISL_FORMAT_C
)
2405 return print_pw_qpolynomial_fold_c(p
, pwf
);
2406 isl_assert(p
->ctx
, 0, goto error
);
2408 isl_printer_free(p
);
2412 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold
*pwf
,
2413 FILE *out
, unsigned output_format
)
2420 p
= isl_printer_to_file(pwf
->dim
->ctx
, out
);
2421 p
= isl_printer_set_output_format(p
, output_format
);
2422 p
= isl_printer_print_pw_qpolynomial_fold(p
, pwf
);
2424 isl_printer_free(p
);
2427 static isl_stat
print_pwf_body(__isl_take isl_pw_qpolynomial_fold
*pwf
,
2430 struct isl_union_print_data
*data
;
2431 data
= (struct isl_union_print_data
*)user
;
2434 data
->p
= isl_printer_print_str(data
->p
, "; ");
2437 data
->p
= isl_pwf_print_isl_body(data
->p
, pwf
);
2438 isl_pw_qpolynomial_fold_free(pwf
);
2443 static __isl_give isl_printer
*print_union_pw_qpolynomial_fold_isl(
2444 __isl_take isl_printer
*p
,
2445 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2447 struct isl_union_print_data data
;
2448 struct isl_print_space_data space_data
= { 0 };
2451 space
= isl_union_pw_qpolynomial_fold_get_space(upwf
);
2452 p
= print_param_tuple(p
, space
, &space_data
);
2453 isl_space_free(space
);
2454 p
= isl_printer_print_str(p
, "{ ");
2457 isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(upwf
,
2458 &print_pwf_body
, &data
);
2460 p
= isl_printer_print_str(p
, " }");
2464 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial_fold(
2465 __isl_take isl_printer
*p
,
2466 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2471 if (p
->output_format
== ISL_FORMAT_ISL
)
2472 return print_union_pw_qpolynomial_fold_isl(p
, upwf
);
2473 isl_die(p
->ctx
, isl_error_invalid
,
2474 "invalid output format for isl_union_pw_qpolynomial_fold",
2477 isl_printer_free(p
);
2481 /* Print the isl_constraint "c" to "p".
2483 __isl_give isl_printer
*isl_printer_print_constraint(__isl_take isl_printer
*p
,
2484 __isl_keep isl_constraint
*c
)
2486 struct isl_print_space_data data
= { 0 };
2487 isl_local_space
*ls
;
2494 ls
= isl_constraint_get_local_space(c
);
2496 return isl_printer_free(p
);
2497 space
= isl_local_space_get_space(ls
);
2498 p
= print_param_tuple(p
, space
, &data
);
2499 p
= isl_printer_print_str(p
, "{ ");
2500 p
= isl_print_space(space
, p
, 0, &data
);
2501 p
= isl_printer_print_str(p
, " : ");
2502 exists
= need_exists(p
, ls
->div
);
2504 p
= isl_printer_free(p
);
2505 if (exists
>= 0 && exists
)
2506 p
= open_exists(p
, space
, ls
->div
, 0);
2507 p
= print_affine_of_len(space
, ls
->div
, p
, c
->v
->el
, c
->v
->size
);
2508 if (isl_constraint_is_equality(c
))
2509 p
= isl_printer_print_str(p
, " = 0");
2511 p
= isl_printer_print_str(p
, " >= 0");
2512 if (exists
>= 0 && exists
)
2513 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2514 p
= isl_printer_print_str(p
, " }");
2515 isl_space_free(space
);
2516 isl_local_space_free(ls
);
2520 isl_printer_free(p
);
2524 static __isl_give isl_printer
*isl_printer_print_space_isl(
2525 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
)
2527 struct isl_print_space_data data
= { 0 };
2532 p
= print_param_tuple(p
, space
, &data
);
2534 p
= isl_printer_print_str(p
, "{ ");
2535 if (isl_space_is_params(space
))
2536 p
= isl_printer_print_str(p
, s_such_that
[0]);
2538 p
= isl_print_space(space
, p
, 0, &data
);
2539 p
= isl_printer_print_str(p
, " }");
2543 isl_printer_free(p
);
2547 __isl_give isl_printer
*isl_printer_print_space(__isl_take isl_printer
*p
,
2548 __isl_keep isl_space
*space
)
2551 return isl_printer_free(p
);
2552 if (p
->output_format
== ISL_FORMAT_ISL
)
2553 return isl_printer_print_space_isl(p
, space
);
2554 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
2555 return print_omega_parameters(space
, p
);
2557 isl_die(isl_space_get_ctx(space
), isl_error_unsupported
,
2558 "output format not supported for space",
2559 return isl_printer_free(p
));
2562 __isl_give isl_printer
*isl_printer_print_local_space(__isl_take isl_printer
*p
,
2563 __isl_keep isl_local_space
*ls
)
2565 struct isl_print_space_data data
= { 0 };
2571 p
= print_param_tuple(p
, ls
->dim
, &data
);
2572 p
= isl_printer_print_str(p
, "{ ");
2573 p
= isl_print_space(ls
->dim
, p
, 0, &data
);
2574 n_div
= isl_local_space_dim(ls
, isl_dim_div
);
2576 p
= isl_printer_print_str(p
, " : ");
2577 p
= isl_printer_print_str(p
, s_open_exists
[0]);
2578 p
= print_div_list(p
, ls
->dim
, ls
->div
, 0, 1);
2579 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2580 } else if (isl_space_is_params(ls
->dim
))
2581 p
= isl_printer_print_str(p
, s_such_that
[0]);
2582 p
= isl_printer_print_str(p
, " }");
2585 isl_printer_free(p
);
2589 /* Print the (potentially rational) affine expression "aff" to "p",
2590 * with the variable names taken from "space".
2592 static __isl_give isl_printer
*print_aff_body(__isl_take isl_printer
*p
,
2593 __isl_keep isl_space
*space
, __isl_keep isl_aff
*aff
)
2597 if (isl_aff_is_nan(aff
))
2598 return isl_printer_print_str(p
, "NaN");
2600 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2601 p
= isl_printer_print_str(p
, "(");
2602 p
= print_affine_of_len(space
, aff
->ls
->div
, p
,
2603 aff
->v
->el
+ 1, 1 + total
);
2604 if (isl_int_is_one(aff
->v
->el
[0]))
2605 p
= isl_printer_print_str(p
, ")");
2607 p
= isl_printer_print_str(p
, ")/");
2608 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2614 static __isl_give isl_printer
*print_aff(__isl_take isl_printer
*p
,
2615 __isl_keep isl_aff
*aff
)
2617 struct isl_print_space_data data
= { 0 };
2619 if (isl_space_is_params(aff
->ls
->dim
))
2622 p
= print_tuple(aff
->ls
->dim
, p
, isl_dim_set
, &data
);
2623 p
= isl_printer_print_str(p
, " -> ");
2625 p
= isl_printer_print_str(p
, "[");
2626 p
= print_aff_body(p
, aff
->ls
->dim
, aff
);
2627 p
= isl_printer_print_str(p
, "]");
2632 static __isl_give isl_printer
*print_aff_isl(__isl_take isl_printer
*p
,
2633 __isl_keep isl_aff
*aff
)
2635 struct isl_print_space_data data
= { 0 };
2640 p
= print_param_tuple(p
, aff
->ls
->dim
, &data
);
2641 p
= isl_printer_print_str(p
, "{ ");
2642 p
= print_aff(p
, aff
);
2643 p
= isl_printer_print_str(p
, " }");
2646 isl_printer_free(p
);
2650 /* Print the body of an isl_pw_aff, i.e., a semicolon delimited
2651 * sequence of affine expressions, each followed by constraints.
2653 static __isl_give isl_printer
*print_pw_aff_body(
2654 __isl_take isl_printer
*p
, __isl_keep isl_pw_aff
*pa
)
2659 return isl_printer_free(p
);
2661 for (i
= 0; i
< pa
->n
; ++i
) {
2665 p
= isl_printer_print_str(p
, "; ");
2666 p
= print_aff(p
, pa
->p
[i
].aff
);
2667 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
2668 p
= print_disjuncts(set_to_map(pa
->p
[i
].set
), space
, p
, 0);
2669 isl_space_free(space
);
2675 static __isl_give isl_printer
*print_pw_aff_isl(__isl_take isl_printer
*p
,
2676 __isl_keep isl_pw_aff
*pwaff
)
2678 struct isl_print_space_data data
= { 0 };
2683 p
= print_param_tuple(p
, pwaff
->dim
, &data
);
2684 p
= isl_printer_print_str(p
, "{ ");
2685 p
= print_pw_aff_body(p
, pwaff
);
2686 p
= isl_printer_print_str(p
, " }");
2689 isl_printer_free(p
);
2693 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2694 __isl_keep isl_local_space
*ls
, isl_int
*c
);
2696 static __isl_give isl_printer
*print_ls_name_c(__isl_take isl_printer
*p
,
2697 __isl_keep isl_local_space
*ls
, enum isl_dim_type type
, unsigned pos
)
2699 if (type
== isl_dim_div
) {
2700 p
= isl_printer_print_str(p
, "floord(");
2701 p
= print_ls_affine_c(p
, ls
, ls
->div
->row
[pos
] + 1);
2702 p
= isl_printer_print_str(p
, ", ");
2703 p
= isl_printer_print_isl_int(p
, ls
->div
->row
[pos
][0]);
2704 p
= isl_printer_print_str(p
, ")");
2708 name
= isl_space_get_dim_name(ls
->dim
, type
, pos
);
2711 p
= isl_printer_print_str(p
, name
);
2716 static __isl_give isl_printer
*print_ls_term_c(__isl_take isl_printer
*p
,
2717 __isl_keep isl_local_space
*ls
, isl_int c
, unsigned pos
)
2719 enum isl_dim_type type
;
2722 return isl_printer_print_isl_int(p
, c
);
2724 if (isl_int_is_one(c
))
2726 else if (isl_int_is_negone(c
))
2727 p
= isl_printer_print_str(p
, "-");
2729 p
= isl_printer_print_isl_int(p
, c
);
2730 p
= isl_printer_print_str(p
, "*");
2732 type
= pos2type(ls
->dim
, &pos
);
2733 p
= print_ls_name_c(p
, ls
, type
, pos
);
2737 static __isl_give isl_printer
*print_ls_partial_affine_c(
2738 __isl_take isl_printer
*p
, __isl_keep isl_local_space
*ls
,
2739 isl_int
*c
, unsigned len
)
2744 for (i
= 0, first
= 1; i
< len
; ++i
) {
2746 if (isl_int_is_zero(c
[i
]))
2749 if (isl_int_is_neg(c
[i
])) {
2751 isl_int_neg(c
[i
], c
[i
]);
2752 p
= isl_printer_print_str(p
, " - ");
2754 p
= isl_printer_print_str(p
, " + ");
2757 p
= print_ls_term_c(p
, ls
, c
[i
], i
);
2759 isl_int_neg(c
[i
], c
[i
]);
2762 p
= isl_printer_print_str(p
, "0");
2766 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2767 __isl_keep isl_local_space
*ls
, isl_int
*c
)
2769 unsigned len
= 1 + isl_local_space_dim(ls
, isl_dim_all
);
2770 return print_ls_partial_affine_c(p
, ls
, c
, len
);
2773 static __isl_give isl_printer
*print_aff_c(__isl_take isl_printer
*p
,
2774 __isl_keep isl_aff
*aff
)
2778 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2779 if (!isl_int_is_one(aff
->v
->el
[0]))
2780 p
= isl_printer_print_str(p
, "(");
2781 p
= print_ls_partial_affine_c(p
, aff
->ls
, aff
->v
->el
+ 1, 1 + total
);
2782 if (!isl_int_is_one(aff
->v
->el
[0])) {
2783 p
= isl_printer_print_str(p
, ")/");
2784 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2789 /* In the C format, we cannot express that "pwaff" may be undefined
2790 * on parts of the domain space. We therefore assume that the expression
2791 * will only be evaluated on its definition domain and compute the gist
2792 * of each cell with respect to this domain.
2794 static __isl_give isl_printer
*print_pw_aff_c(__isl_take isl_printer
*p
,
2795 __isl_keep isl_pw_aff
*pwaff
)
2798 isl_ast_build
*build
;
2802 isl_die(p
->ctx
, isl_error_unsupported
,
2803 "cannot print empty isl_pw_aff in C format",
2804 return isl_printer_free(p
));
2806 domain
= isl_pw_aff_domain(isl_pw_aff_copy(pwaff
));
2807 build
= isl_ast_build_from_context(domain
);
2808 expr
= isl_ast_build_expr_from_pw_aff(build
, isl_pw_aff_copy(pwaff
));
2809 p
= isl_printer_print_ast_expr(p
, expr
);
2810 isl_ast_expr_free(expr
);
2811 isl_ast_build_free(build
);
2816 __isl_give isl_printer
*isl_printer_print_aff(__isl_take isl_printer
*p
,
2817 __isl_keep isl_aff
*aff
)
2822 if (p
->output_format
== ISL_FORMAT_ISL
)
2823 return print_aff_isl(p
, aff
);
2824 else if (p
->output_format
== ISL_FORMAT_C
)
2825 return print_aff_c(p
, aff
);
2826 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2829 isl_printer_free(p
);
2833 __isl_give isl_printer
*isl_printer_print_pw_aff(__isl_take isl_printer
*p
,
2834 __isl_keep isl_pw_aff
*pwaff
)
2839 if (p
->output_format
== ISL_FORMAT_ISL
)
2840 return print_pw_aff_isl(p
, pwaff
);
2841 else if (p
->output_format
== ISL_FORMAT_C
)
2842 return print_pw_aff_c(p
, pwaff
);
2843 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2846 isl_printer_free(p
);
2850 /* Print "pa" in a sequence of isl_pw_affs delimited by semicolons.
2851 * Each isl_pw_aff itself is also printed as semicolon delimited
2852 * sequence of pieces.
2853 * If data->first = 1, then this is the first in the sequence.
2854 * Update data->first to tell the next element that it is not the first.
2856 static isl_stat
print_pw_aff_body_wrap(__isl_take isl_pw_aff
*pa
,
2859 struct isl_union_print_data
*data
;
2860 data
= (struct isl_union_print_data
*) user
;
2863 data
->p
= isl_printer_print_str(data
->p
, "; ");
2866 data
->p
= print_pw_aff_body(data
->p
, pa
);
2867 isl_pw_aff_free(pa
);
2869 return data
->p
? isl_stat_ok
: isl_stat_error
;
2872 /* Print the body of an isl_union_pw_aff, i.e., a semicolon delimited
2873 * sequence of affine expressions, each followed by constraints,
2874 * with the sequence enclosed in braces.
2876 static __isl_give isl_printer
*print_union_pw_aff_body(
2877 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2879 struct isl_union_print_data data
= { p
, 1 };
2881 p
= isl_printer_print_str(p
, s_open_set
[0]);
2883 if (isl_union_pw_aff_foreach_pw_aff(upa
,
2884 &print_pw_aff_body_wrap
, &data
) < 0)
2885 data
.p
= isl_printer_free(p
);
2887 p
= isl_printer_print_str(p
, s_close_set
[0]);
2892 /* Print the isl_union_pw_aff "upa" to "p" in isl format.
2894 * The individual isl_pw_affs are delimited by a semicolon.
2896 static __isl_give isl_printer
*print_union_pw_aff_isl(
2897 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2899 struct isl_print_space_data data
= { 0 };
2902 space
= isl_union_pw_aff_get_space(upa
);
2903 p
= print_param_tuple(p
, space
, &data
);
2904 isl_space_free(space
);
2905 p
= print_union_pw_aff_body(p
, upa
);
2909 /* Print the isl_union_pw_aff "upa" to "p".
2911 * We currently only support an isl format.
2913 __isl_give isl_printer
*isl_printer_print_union_pw_aff(
2914 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2917 return isl_printer_free(p
);
2919 if (p
->output_format
== ISL_FORMAT_ISL
)
2920 return print_union_pw_aff_isl(p
, upa
);
2921 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
2922 "unsupported output format", return isl_printer_free(p
));
2925 /* Print dimension "pos" of data->space to "p".
2927 * data->user is assumed to be an isl_multi_aff.
2929 * If the current dimension is an output dimension, then print
2930 * the corresponding expression. Otherwise, print the name of the dimension.
2932 static __isl_give isl_printer
*print_dim_ma(__isl_take isl_printer
*p
,
2933 struct isl_print_space_data
*data
, unsigned pos
)
2935 isl_multi_aff
*ma
= data
->user
;
2937 if (data
->type
== isl_dim_out
) {
2940 space
= isl_multi_aff_get_domain_space(ma
);
2941 p
= print_aff_body(p
, space
, ma
->u
.p
[pos
]);
2942 isl_space_free(space
);
2944 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2950 static __isl_give isl_printer
*print_multi_aff(__isl_take isl_printer
*p
,
2951 __isl_keep isl_multi_aff
*maff
)
2953 struct isl_print_space_data data
= { 0 };
2955 data
.print_dim
= &print_dim_ma
;
2957 return isl_print_space(maff
->space
, p
, 0, &data
);
2960 static __isl_give isl_printer
*print_multi_aff_isl(__isl_take isl_printer
*p
,
2961 __isl_keep isl_multi_aff
*maff
)
2963 struct isl_print_space_data data
= { 0 };
2968 p
= print_param_tuple(p
, maff
->space
, &data
);
2969 p
= isl_printer_print_str(p
, "{ ");
2970 p
= print_multi_aff(p
, maff
);
2971 p
= isl_printer_print_str(p
, " }");
2974 isl_printer_free(p
);
2978 __isl_give isl_printer
*isl_printer_print_multi_aff(__isl_take isl_printer
*p
,
2979 __isl_keep isl_multi_aff
*maff
)
2984 if (p
->output_format
== ISL_FORMAT_ISL
)
2985 return print_multi_aff_isl(p
, maff
);
2986 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2989 isl_printer_free(p
);
2993 static __isl_give isl_printer
*print_pw_multi_aff_body(
2994 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
3001 for (i
= 0; i
< pma
->n
; ++i
) {
3005 p
= isl_printer_print_str(p
, "; ");
3006 p
= print_multi_aff(p
, pma
->p
[i
].maff
);
3007 space
= isl_multi_aff_get_domain_space(pma
->p
[i
].maff
);
3008 p
= print_disjuncts(set_to_map(pma
->p
[i
].set
), space
, p
, 0);
3009 isl_space_free(space
);
3013 isl_printer_free(p
);
3017 static __isl_give isl_printer
*print_pw_multi_aff_isl(__isl_take isl_printer
*p
,
3018 __isl_keep isl_pw_multi_aff
*pma
)
3020 struct isl_print_space_data data
= { 0 };
3025 p
= print_param_tuple(p
, pma
->dim
, &data
);
3026 p
= isl_printer_print_str(p
, "{ ");
3027 p
= print_pw_multi_aff_body(p
, pma
);
3028 p
= isl_printer_print_str(p
, " }");
3031 isl_printer_free(p
);
3035 /* Print the unnamed, single-dimensional piecewise multi affine expression "pma"
3038 static __isl_give isl_printer
*print_unnamed_pw_multi_aff_c(
3039 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
3044 space
= isl_pw_multi_aff_get_domain_space(pma
);
3045 for (i
= 0; i
< pma
->n
- 1; ++i
) {
3046 p
= isl_printer_print_str(p
, "(");
3047 p
= print_set_c(p
, space
, pma
->p
[i
].set
);
3048 p
= isl_printer_print_str(p
, ") ? (");
3049 p
= print_aff_c(p
, pma
->p
[i
].maff
->u
.p
[0]);
3050 p
= isl_printer_print_str(p
, ") : ");
3052 isl_space_free(space
);
3054 return print_aff_c(p
, pma
->p
[pma
->n
- 1].maff
->u
.p
[0]);
3057 static __isl_give isl_printer
*print_pw_multi_aff_c(__isl_take isl_printer
*p
,
3058 __isl_keep isl_pw_multi_aff
*pma
)
3066 isl_die(p
->ctx
, isl_error_unsupported
,
3067 "cannot print empty isl_pw_multi_aff in C format",
3069 name
= isl_pw_multi_aff_get_tuple_name(pma
, isl_dim_out
);
3070 if (!name
&& isl_pw_multi_aff_dim(pma
, isl_dim_out
) == 1)
3071 return print_unnamed_pw_multi_aff_c(p
, pma
);
3073 isl_die(p
->ctx
, isl_error_unsupported
,
3074 "cannot print unnamed isl_pw_multi_aff in C format",
3077 p
= isl_printer_print_str(p
, name
);
3078 n
= isl_pw_multi_aff_dim(pma
, isl_dim_out
);
3080 isl_die(p
->ctx
, isl_error_unsupported
,
3081 "not supported yet", goto error
);
3085 isl_printer_free(p
);
3089 __isl_give isl_printer
*isl_printer_print_pw_multi_aff(
3090 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
3095 if (p
->output_format
== ISL_FORMAT_ISL
)
3096 return print_pw_multi_aff_isl(p
, pma
);
3097 if (p
->output_format
== ISL_FORMAT_C
)
3098 return print_pw_multi_aff_c(p
, pma
);
3099 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3102 isl_printer_free(p
);
3106 static isl_stat
print_pw_multi_aff_body_wrap(__isl_take isl_pw_multi_aff
*pma
,
3109 struct isl_union_print_data
*data
;
3110 data
= (struct isl_union_print_data
*) user
;
3113 data
->p
= isl_printer_print_str(data
->p
, "; ");
3116 data
->p
= print_pw_multi_aff_body(data
->p
, pma
);
3117 isl_pw_multi_aff_free(pma
);
3122 static __isl_give isl_printer
*print_union_pw_multi_aff_isl(
3123 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
3125 struct isl_union_print_data data
;
3126 struct isl_print_space_data space_data
= { 0 };
3129 space
= isl_union_pw_multi_aff_get_space(upma
);
3130 p
= print_param_tuple(p
, space
, &space_data
);
3131 isl_space_free(space
);
3132 p
= isl_printer_print_str(p
, s_open_set
[0]);
3135 isl_union_pw_multi_aff_foreach_pw_multi_aff(upma
,
3136 &print_pw_multi_aff_body_wrap
, &data
);
3138 p
= isl_printer_print_str(p
, s_close_set
[0]);
3142 __isl_give isl_printer
*isl_printer_print_union_pw_multi_aff(
3143 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
3148 if (p
->output_format
== ISL_FORMAT_ISL
)
3149 return print_union_pw_multi_aff_isl(p
, upma
);
3150 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3153 isl_printer_free(p
);
3157 /* Print dimension "pos" of data->space to "p".
3159 * data->user is assumed to be an isl_multi_pw_aff.
3161 * If the current dimension is an output dimension, then print
3162 * the corresponding piecewise affine expression.
3163 * Otherwise, print the name of the dimension.
3165 static __isl_give isl_printer
*print_dim_mpa(__isl_take isl_printer
*p
,
3166 struct isl_print_space_data
*data
, unsigned pos
)
3171 isl_multi_pw_aff
*mpa
= data
->user
;
3174 if (data
->type
!= isl_dim_out
)
3175 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
3179 return isl_printer_print_str(p
, "(0 : false)");
3181 need_parens
= pa
->n
!= 1 || !isl_set_plain_is_universe(pa
->p
[0].set
);
3183 p
= isl_printer_print_str(p
, "(");
3184 space
= isl_multi_pw_aff_get_domain_space(mpa
);
3185 for (i
= 0; i
< pa
->n
; ++i
) {
3188 p
= isl_printer_print_str(p
, "; ");
3189 p
= print_aff_body(p
, space
, pa
->p
[i
].aff
);
3190 p
= print_disjuncts(pa
->p
[i
].set
, space
, p
, 0);
3192 isl_space_free(space
);
3194 p
= isl_printer_print_str(p
, ")");
3199 /* Print "mpa" to "p" in isl format.
3201 * If "mpa" is zero-dimensional and has a non-trivial explicit domain,
3202 * then it is printed after the tuple of affine expressions.
3204 static __isl_give isl_printer
*print_multi_pw_aff_isl(__isl_take isl_printer
*p
,
3205 __isl_keep isl_multi_pw_aff
*mpa
)
3207 struct isl_print_space_data data
= { 0 };
3208 isl_bool has_domain
;
3211 return isl_printer_free(p
);
3213 p
= print_param_tuple(p
, mpa
->space
, &data
);
3214 p
= isl_printer_print_str(p
, "{ ");
3215 data
.print_dim
= &print_dim_mpa
;
3217 p
= isl_print_space(mpa
->space
, p
, 0, &data
);
3218 has_domain
= isl_multi_pw_aff_has_non_trivial_domain(mpa
);
3220 return isl_printer_free(p
);
3224 space
= isl_space_domain(isl_space_copy(mpa
->space
));
3225 p
= print_disjuncts_set(mpa
->u
.dom
, space
, p
, 0);
3226 isl_space_free(space
);
3228 p
= isl_printer_print_str(p
, " }");
3232 __isl_give isl_printer
*isl_printer_print_multi_pw_aff(
3233 __isl_take isl_printer
*p
, __isl_keep isl_multi_pw_aff
*mpa
)
3236 return isl_printer_free(p
);
3238 if (p
->output_format
== ISL_FORMAT_ISL
)
3239 return print_multi_pw_aff_isl(p
, mpa
);
3240 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3241 return isl_printer_free(p
));
3244 /* Print dimension "pos" of data->space to "p".
3246 * data->user is assumed to be an isl_multi_val.
3248 * If the current dimension is an output dimension, then print
3249 * the corresponding value. Otherwise, print the name of the dimension.
3251 static __isl_give isl_printer
*print_dim_mv(__isl_take isl_printer
*p
,
3252 struct isl_print_space_data
*data
, unsigned pos
)
3254 isl_multi_val
*mv
= data
->user
;
3256 if (data
->type
== isl_dim_out
)
3257 return isl_printer_print_val(p
, mv
->u
.p
[pos
]);
3259 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
3262 /* Print the isl_multi_val "mv" to "p" in isl format.
3264 static __isl_give isl_printer
*print_multi_val_isl(__isl_take isl_printer
*p
,
3265 __isl_keep isl_multi_val
*mv
)
3267 struct isl_print_space_data data
= { 0 };
3270 return isl_printer_free(p
);
3272 p
= print_param_tuple(p
, mv
->space
, &data
);
3273 p
= isl_printer_print_str(p
, "{ ");
3274 data
.print_dim
= &print_dim_mv
;
3276 p
= isl_print_space(mv
->space
, p
, 0, &data
);
3277 p
= isl_printer_print_str(p
, " }");
3281 /* Print the isl_multi_val "mv" to "p".
3283 * Currently only supported in isl format.
3285 __isl_give isl_printer
*isl_printer_print_multi_val(
3286 __isl_take isl_printer
*p
, __isl_keep isl_multi_val
*mv
)
3289 return isl_printer_free(p
);
3291 if (p
->output_format
== ISL_FORMAT_ISL
)
3292 return print_multi_val_isl(p
, mv
);
3293 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3294 return isl_printer_free(p
));
3297 /* Print dimension "pos" of data->space to "p".
3299 * data->user is assumed to be an isl_multi_union_pw_aff.
3301 * The current dimension is necessarily a set dimension, so
3302 * we print the corresponding isl_union_pw_aff, including
3305 static __isl_give isl_printer
*print_union_pw_aff_dim(__isl_take isl_printer
*p
,
3306 struct isl_print_space_data
*data
, unsigned pos
)
3308 isl_multi_union_pw_aff
*mupa
= data
->user
;
3309 isl_union_pw_aff
*upa
;
3311 upa
= isl_multi_union_pw_aff_get_union_pw_aff(mupa
, pos
);
3312 p
= print_union_pw_aff_body(p
, upa
);
3313 isl_union_pw_aff_free(upa
);
3318 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3320 * If "mupa" is zero-dimensional and has a non-trivial explicit domain,
3321 * then it is printed after the tuple of affine expressions.
3322 * In order to clarify that this domain belongs to the expression,
3323 * the tuple along with the domain are placed inside parentheses.
3324 * If "mupa" has any parameters, then the opening parenthesis
3325 * appears after the parameter declarations.
3327 static __isl_give isl_printer
*print_multi_union_pw_aff_isl(
3328 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3330 struct isl_print_space_data data
= { 0 };
3331 isl_bool has_domain
;
3335 return isl_printer_free(p
);
3336 has_domain
= isl_multi_union_pw_aff_has_non_trivial_domain(mupa
);
3338 return isl_printer_free(p
);
3340 space
= isl_multi_union_pw_aff_get_space(mupa
);
3341 p
= print_param_tuple(p
, space
, &data
);
3344 p
= isl_printer_print_str(p
, "(");
3346 data
.print_dim
= &print_union_pw_aff_dim
;
3349 p
= isl_print_space(space
, p
, 0, &data
);
3350 isl_space_free(space
);
3353 p
= isl_printer_print_str(p
, " : ");
3354 p
= isl_printer_print_union_set_isl_body(p
, mupa
->u
.dom
);
3355 p
= isl_printer_print_str(p
, ")");
3361 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3363 * We currently only support an isl format.
3365 __isl_give isl_printer
*isl_printer_print_multi_union_pw_aff(
3366 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3369 return isl_printer_free(p
);
3371 if (p
->output_format
== ISL_FORMAT_ISL
)
3372 return print_multi_union_pw_aff_isl(p
, mupa
);
3373 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
3374 "unsupported output format", return isl_printer_free(p
));