2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
6 * Use of this software is governed by the MIT license
8 * Written by Sven Verdoolaege, K.U.Leuven, Departement
9 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
10 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
11 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
12 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
17 #include <isl_ctx_private.h>
18 #include <isl_map_private.h>
21 #include <isl_polynomial_private.h>
22 #include <isl_printer_private.h>
23 #include <isl_space_private.h>
24 #include <isl_mat_private.h>
25 #include <isl_vec_private.h>
26 #include <isl/union_map.h>
27 #include <isl/constraint.h>
28 #include <isl_local_space_private.h>
29 #include <isl_aff_private.h>
30 #include <isl_val_private.h>
31 #include <isl/ast_build.h>
33 #include <isl_output_private.h>
35 #include <bset_to_bmap.c>
36 #include <set_to_map.c>
38 static const char *s_to
[2] = { " -> ", " \\to " };
39 static const char *s_and
[2] = { " and ", " \\wedge " };
40 static const char *s_or
[2] = { " or ", " \\vee " };
41 static const char *s_le
[2] = { "<=", "\\le" };
42 static const char *s_ge
[2] = { ">=", "\\ge" };
43 static const char *s_open_set
[2] = { "{ ", "\\{\\, " };
44 static const char *s_close_set
[2] = { " }", " \\,\\}" };
45 static const char *s_open_list
[2] = { "[", "(" };
46 static const char *s_close_list
[2] = { "]", ")" };
47 static const char *s_such_that
[2] = { " : ", " \\mid " };
48 static const char *s_open_exists
[2] = { "exists (", "\\exists \\, " };
49 static const char *s_close_exists
[2] = { ")", "" };
50 static const char *s_div_prefix
[2] = { "e", "\\alpha_" };
51 static const char *s_param_prefix
[2] = { "p", "p_" };
52 static const char *s_input_prefix
[2] = { "i", "i_" };
53 static const char *s_output_prefix
[2] = { "o", "o_" };
55 static __isl_give isl_printer
*print_constraint_polylib(
56 struct isl_basic_map
*bmap
, int ineq
, int n
, __isl_take isl_printer
*p
)
59 unsigned n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
60 unsigned n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
61 unsigned nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
62 isl_int
*c
= ineq
? bmap
->ineq
[n
] : bmap
->eq
[n
];
64 p
= isl_printer_start_line(p
);
65 p
= isl_printer_print_int(p
, ineq
);
66 for (i
= 0; i
< n_out
; ++i
) {
67 p
= isl_printer_print_str(p
, " ");
68 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+n_in
+i
]);
70 for (i
= 0; i
< n_in
; ++i
) {
71 p
= isl_printer_print_str(p
, " ");
72 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+i
]);
74 for (i
= 0; i
< bmap
->n_div
; ++i
) {
75 p
= isl_printer_print_str(p
, " ");
76 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+n_in
+n_out
+i
]);
78 for (i
= 0; i
< nparam
; ++i
) {
79 p
= isl_printer_print_str(p
, " ");
80 p
= isl_printer_print_isl_int(p
, c
[1+i
]);
82 p
= isl_printer_print_str(p
, " ");
83 p
= isl_printer_print_isl_int(p
, c
[0]);
84 p
= isl_printer_end_line(p
);
88 static __isl_give isl_printer
*print_constraints_polylib(
89 struct isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
93 p
= isl_printer_set_isl_int_width(p
, 5);
95 for (i
= 0; i
< bmap
->n_eq
; ++i
)
96 p
= print_constraint_polylib(bmap
, 0, i
, p
);
97 for (i
= 0; i
< bmap
->n_ineq
; ++i
)
98 p
= print_constraint_polylib(bmap
, 1, i
, p
);
103 static __isl_give isl_printer
*bset_print_constraints_polylib(
104 struct isl_basic_set
*bset
, __isl_take isl_printer
*p
)
106 return print_constraints_polylib(bset_to_bmap(bset
), p
);
109 static __isl_give isl_printer
*isl_basic_map_print_polylib(
110 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
, int ext
)
112 unsigned total
= isl_basic_map_total_dim(bmap
);
113 p
= isl_printer_start_line(p
);
114 p
= isl_printer_print_int(p
, bmap
->n_eq
+ bmap
->n_ineq
);
115 p
= isl_printer_print_str(p
, " ");
116 p
= isl_printer_print_int(p
, 1 + total
+ 1);
118 p
= isl_printer_print_str(p
, " ");
119 p
= isl_printer_print_int(p
,
120 isl_basic_map_dim(bmap
, isl_dim_out
));
121 p
= isl_printer_print_str(p
, " ");
122 p
= isl_printer_print_int(p
,
123 isl_basic_map_dim(bmap
, isl_dim_in
));
124 p
= isl_printer_print_str(p
, " ");
125 p
= isl_printer_print_int(p
,
126 isl_basic_map_dim(bmap
, isl_dim_div
));
127 p
= isl_printer_print_str(p
, " ");
128 p
= isl_printer_print_int(p
,
129 isl_basic_map_dim(bmap
, isl_dim_param
));
131 p
= isl_printer_end_line(p
);
132 return print_constraints_polylib(bmap
, p
);
135 static __isl_give isl_printer
*isl_basic_set_print_polylib(
136 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
, int ext
)
138 return isl_basic_map_print_polylib(bset_to_bmap(bset
), p
, ext
);
141 static __isl_give isl_printer
*isl_map_print_polylib(__isl_keep isl_map
*map
,
142 __isl_take isl_printer
*p
, int ext
)
146 p
= isl_printer_start_line(p
);
147 p
= isl_printer_print_int(p
, map
->n
);
148 p
= isl_printer_end_line(p
);
149 for (i
= 0; i
< map
->n
; ++i
) {
150 p
= isl_printer_start_line(p
);
151 p
= isl_printer_end_line(p
);
152 p
= isl_basic_map_print_polylib(map
->p
[i
], p
, ext
);
157 static __isl_give isl_printer
*isl_set_print_polylib(__isl_keep isl_set
*set
,
158 __isl_take isl_printer
*p
, int ext
)
160 return isl_map_print_polylib(set_to_map(set
), p
, ext
);
163 static int count_same_name(__isl_keep isl_space
*dim
,
164 enum isl_dim_type type
, unsigned pos
, const char *name
)
170 for (t
= isl_dim_param
; t
<= type
&& t
<= isl_dim_out
; ++t
) {
171 s
= t
== type
? pos
: isl_space_dim(dim
, t
);
172 for (p
= 0; p
< s
; ++p
) {
173 const char *n
= isl_space_get_dim_name(dim
, t
, p
);
174 if (n
&& !strcmp(n
, name
))
181 /* Print the name of the variable of type "type" and position "pos"
184 static __isl_give isl_printer
*print_name(__isl_keep isl_space
*space
,
185 __isl_take isl_printer
*p
, enum isl_dim_type type
, unsigned pos
,
192 name
= type
== isl_dim_div
? NULL
193 : isl_space_get_dim_name(space
, type
, pos
);
197 if (type
== isl_dim_param
)
198 prefix
= s_param_prefix
[latex
];
199 else if (type
== isl_dim_div
)
200 prefix
= s_div_prefix
[latex
];
201 else if (isl_space_is_set(space
) || type
== isl_dim_in
)
202 prefix
= s_input_prefix
[latex
];
204 prefix
= s_output_prefix
[latex
];
205 snprintf(buffer
, sizeof(buffer
), "%s%d", prefix
, pos
);
208 primes
= count_same_name(space
, name
== buffer
? isl_dim_div
: type
,
210 p
= isl_printer_print_str(p
, name
);
212 p
= isl_printer_print_str(p
, "'");
216 static enum isl_dim_type
pos2type(__isl_keep isl_space
*dim
, unsigned *pos
)
218 enum isl_dim_type type
;
219 unsigned n_in
= isl_space_dim(dim
, isl_dim_in
);
220 unsigned n_out
= isl_space_dim(dim
, isl_dim_out
);
221 unsigned nparam
= isl_space_dim(dim
, isl_dim_param
);
223 if (*pos
< 1 + nparam
) {
224 type
= isl_dim_param
;
226 } else if (*pos
< 1 + nparam
+ n_in
) {
229 } else if (*pos
< 1 + nparam
+ n_in
+ n_out
) {
231 *pos
-= 1 + nparam
+ n_in
;
234 *pos
-= 1 + nparam
+ n_in
+ n_out
;
240 /* Can the div expression of the integer division at position "row" of "div"
242 * In particular, are the div expressions available and does the selected
243 * variable have a known explicit representation?
244 * Furthermore, the Omega format does not allow any div expressions
247 static isl_bool
can_print_div_expr(__isl_keep isl_printer
*p
,
248 __isl_keep isl_mat
*div
, int pos
)
250 if (p
->output_format
== ISL_FORMAT_OMEGA
)
251 return isl_bool_false
;
253 return isl_bool_false
;
254 return !isl_int_is_zero(div
->row
[pos
][0]);
257 static __isl_give isl_printer
*print_div(__isl_keep isl_space
*dim
,
258 __isl_keep isl_mat
*div
, int pos
, __isl_take isl_printer
*p
);
260 static __isl_give isl_printer
*print_term(__isl_keep isl_space
*space
,
261 __isl_keep isl_mat
*div
,
262 isl_int c
, unsigned pos
, __isl_take isl_printer
*p
, int latex
)
264 enum isl_dim_type type
;
268 return isl_printer_print_isl_int(p
, c
);
270 type
= pos2type(space
, &pos
);
271 print_div_def
= type
== isl_dim_div
&& can_print_div_expr(p
, div
, pos
);
273 if (isl_int_is_one(c
))
275 else if (isl_int_is_negone(c
))
276 p
= isl_printer_print_str(p
, "-");
278 p
= isl_printer_print_isl_int(p
, c
);
279 if (p
->output_format
== ISL_FORMAT_C
|| print_div_def
)
280 p
= isl_printer_print_str(p
, "*");
283 p
= print_div(space
, div
, pos
, p
);
285 p
= print_name(space
, p
, type
, pos
, latex
);
289 static __isl_give isl_printer
*print_affine_of_len(__isl_keep isl_space
*dim
,
290 __isl_keep isl_mat
*div
,
291 __isl_take isl_printer
*p
, isl_int
*c
, int len
)
296 for (i
= 0, first
= 1; i
< len
; ++i
) {
298 if (isl_int_is_zero(c
[i
]))
301 if (isl_int_is_neg(c
[i
])) {
303 isl_int_neg(c
[i
], c
[i
]);
304 p
= isl_printer_print_str(p
, " - ");
306 p
= isl_printer_print_str(p
, " + ");
309 p
= print_term(dim
, div
, c
[i
], i
, p
, 0);
311 isl_int_neg(c
[i
], c
[i
]);
314 p
= isl_printer_print_str(p
, "0");
318 /* Print an affine expression "c" corresponding to a constraint in "bmap"
319 * to "p", with the variable names taken from "space" and
320 * the integer division definitions taken from "div".
322 static __isl_give isl_printer
*print_affine(__isl_keep isl_basic_map
*bmap
,
323 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
324 __isl_take isl_printer
*p
, isl_int
*c
)
326 unsigned len
= 1 + isl_basic_map_total_dim(bmap
);
327 return print_affine_of_len(space
, div
, p
, c
, len
);
330 /* offset is the offset of local_dim inside data->type of data->space.
332 static __isl_give isl_printer
*print_nested_var_list(__isl_take isl_printer
*p
,
333 __isl_keep isl_space
*local_dim
, enum isl_dim_type local_type
,
334 struct isl_print_space_data
*data
, int offset
)
338 if (data
->space
!= local_dim
&& local_type
== isl_dim_out
)
339 offset
+= local_dim
->n_in
;
341 for (i
= 0; i
< isl_space_dim(local_dim
, local_type
); ++i
) {
343 p
= isl_printer_print_str(p
, ", ");
345 p
= data
->print_dim(p
, data
, offset
+ i
);
347 p
= print_name(data
->space
, p
, data
->type
, offset
+ i
,
353 static __isl_give isl_printer
*print_var_list(__isl_take isl_printer
*p
,
354 __isl_keep isl_space
*space
, enum isl_dim_type type
)
356 struct isl_print_space_data data
= { .space
= space
, .type
= type
};
358 return print_nested_var_list(p
, space
, type
, &data
, 0);
361 static __isl_give isl_printer
*print_nested_map_dim(__isl_take isl_printer
*p
,
362 __isl_keep isl_space
*local_dim
,
363 struct isl_print_space_data
*data
, int offset
);
365 static __isl_give isl_printer
*print_nested_tuple(__isl_take isl_printer
*p
,
366 __isl_keep isl_space
*local_dim
, enum isl_dim_type local_type
,
367 struct isl_print_space_data
*data
, int offset
)
369 const char *name
= NULL
;
370 unsigned n
= isl_space_dim(local_dim
, local_type
);
371 if ((local_type
== isl_dim_in
|| local_type
== isl_dim_out
)) {
372 name
= isl_space_get_tuple_name(local_dim
, local_type
);
375 p
= isl_printer_print_str(p
, "\\mathrm{");
376 p
= isl_printer_print_str(p
, name
);
378 p
= isl_printer_print_str(p
, "}");
381 if (!data
->latex
|| n
!= 1 || name
)
382 p
= isl_printer_print_str(p
, s_open_list
[data
->latex
]);
383 if ((local_type
== isl_dim_in
|| local_type
== isl_dim_out
) &&
384 local_dim
->nested
[local_type
- isl_dim_in
]) {
385 if (data
->space
!= local_dim
&& local_type
== isl_dim_out
)
386 offset
+= local_dim
->n_in
;
387 p
= print_nested_map_dim(p
,
388 local_dim
->nested
[local_type
- isl_dim_in
],
391 p
= print_nested_var_list(p
, local_dim
, local_type
, data
,
393 if (!data
->latex
|| n
!= 1 || name
)
394 p
= isl_printer_print_str(p
, s_close_list
[data
->latex
]);
398 static __isl_give isl_printer
*print_tuple(__isl_keep isl_space
*dim
,
399 __isl_take isl_printer
*p
, enum isl_dim_type type
,
400 struct isl_print_space_data
*data
)
404 return print_nested_tuple(p
, dim
, type
, data
, 0);
407 static __isl_give isl_printer
*print_nested_map_dim(__isl_take isl_printer
*p
,
408 __isl_keep isl_space
*local_dim
,
409 struct isl_print_space_data
*data
, int offset
)
411 p
= print_nested_tuple(p
, local_dim
, isl_dim_in
, data
, offset
);
412 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
413 p
= print_nested_tuple(p
, local_dim
, isl_dim_out
, data
, offset
);
418 __isl_give isl_printer
*isl_print_space(__isl_keep isl_space
*space
,
419 __isl_take isl_printer
*p
, int rational
,
420 struct isl_print_space_data
*data
)
422 if (rational
&& !data
->latex
)
423 p
= isl_printer_print_str(p
, "rat: ");
424 if (isl_space_is_params(space
))
426 else if (isl_space_is_set(space
))
427 p
= print_tuple(space
, p
, isl_dim_set
, data
);
429 p
= print_tuple(space
, p
, isl_dim_in
, data
);
430 p
= isl_printer_print_str(p
, s_to
[data
->latex
]);
431 p
= print_tuple(space
, p
, isl_dim_out
, data
);
437 static __isl_give isl_printer
*print_omega_parameters(__isl_keep isl_space
*dim
,
438 __isl_take isl_printer
*p
)
440 if (isl_space_dim(dim
, isl_dim_param
) == 0)
443 p
= isl_printer_start_line(p
);
444 p
= isl_printer_print_str(p
, "symbolic ");
445 p
= print_var_list(p
, dim
, isl_dim_param
);
446 p
= isl_printer_print_str(p
, ";");
447 p
= isl_printer_end_line(p
);
451 /* Does the inequality constraint following "i" in "bmap"
452 * have an opposite value for the same last coefficient?
453 * "last" is the position of the last coefficient of inequality "i".
454 * If the next constraint is a div constraint, then it is ignored
455 * since div constraints are not printed.
457 static int next_is_opposite(__isl_keep isl_basic_map
*bmap
, int i
, int last
)
459 unsigned total
= isl_basic_map_total_dim(bmap
);
460 unsigned o_div
= isl_basic_map_offset(bmap
, isl_dim_div
);
462 if (i
+ 1 >= bmap
->n_ineq
)
464 if (isl_seq_last_non_zero(bmap
->ineq
[i
+ 1], 1 + total
) != last
)
467 isl_basic_map_is_div_constraint(bmap
, bmap
->ineq
[i
+ 1],
470 return isl_int_abs_eq(bmap
->ineq
[i
][last
], bmap
->ineq
[i
+ 1][last
]) &&
471 !isl_int_eq(bmap
->ineq
[i
][last
], bmap
->ineq
[i
+ 1][last
]);
474 /* Return a string representation of the operator used when
475 * printing a constraint where the LHS is greater than or equal to the LHS
476 * (sign > 0) or smaller than or equal to the LHS (sign < 0).
477 * If "strict" is set, then return the strict version of the comparison
480 static const char *constraint_op(int sign
, int strict
, int latex
)
483 return sign
< 0 ? "<" : ">";
490 /* Print one side of a constraint "c" from "bmap" to "p", with
491 * the variable names taken from "space" and the integer division definitions
493 * "last" is the position of the last non-zero coefficient.
494 * Let c' be the result of zeroing out this coefficient, then
495 * the partial constraint
500 * "first_constraint" is set if this is the first constraint
501 * in the conjunction.
503 static __isl_give isl_printer
*print_half_constraint(struct isl_basic_map
*bmap
,
504 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
505 __isl_take isl_printer
*p
, isl_int
*c
, int last
, const char *op
,
506 int first_constraint
, int latex
)
508 if (!first_constraint
)
509 p
= isl_printer_print_str(p
, s_and
[latex
]);
511 isl_int_set_si(c
[last
], 0);
512 p
= print_affine(bmap
, space
, div
, p
, c
);
514 p
= isl_printer_print_str(p
, " ");
515 p
= isl_printer_print_str(p
, op
);
516 p
= isl_printer_print_str(p
, " ");
521 /* Print a constraint "c" from "bmap" to "p", with the variable names
522 * taken from "space" and the integer division definitions taken from "div".
523 * "last" is the position of the last non-zero coefficient, which is
524 * moreover assumed to be negative.
525 * Let c' be the result of zeroing out this coefficient, then
526 * the constraint is printed in the form
530 * "first_constraint" is set if this is the first constraint
531 * in the conjunction.
533 static __isl_give isl_printer
*print_constraint(struct isl_basic_map
*bmap
,
534 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
535 __isl_take isl_printer
*p
,
536 isl_int
*c
, int last
, const char *op
, int first_constraint
, int latex
)
538 if (!first_constraint
)
539 p
= isl_printer_print_str(p
, s_and
[latex
]);
541 isl_int_abs(c
[last
], c
[last
]);
543 p
= print_term(space
, div
, c
[last
], last
, p
, latex
);
545 p
= isl_printer_print_str(p
, " ");
546 p
= isl_printer_print_str(p
, op
);
547 p
= isl_printer_print_str(p
, " ");
549 isl_int_set_si(c
[last
], 0);
550 p
= print_affine(bmap
, space
, div
, p
, c
);
555 /* Print the constraints of "bmap" to "p".
556 * The names of the variables are taken from "space" and
557 * the integer division definitions are taken from "div".
558 * Div constraints are only printed in "dump" mode.
559 * The constraints are sorted prior to printing (except in "dump" mode).
561 * If x is the last variable with a non-zero coefficient,
570 * while an upper bound
578 * If the next constraint has an opposite sign for the same last coefficient,
579 * then it is printed as
587 * instead. In fact, the "a x" part is not printed explicitly, but
588 * reused from the next constraint, which is therefore treated as
589 * a first constraint in the conjunction.
591 * If the constant term of "f" is -1, then "f" is replaced by "f + 1" and
592 * the comparison operator is replaced by the strict variant.
593 * Essentially, ">= 1" is replaced by "> 0".
595 static __isl_give isl_printer
*print_constraints(__isl_keep isl_basic_map
*bmap
,
596 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
597 __isl_take isl_printer
*p
, int latex
)
601 int rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
602 unsigned total
= isl_basic_map_total_dim(bmap
);
603 unsigned o_div
= isl_basic_map_offset(bmap
, isl_dim_div
);
609 bmap
= isl_basic_map_copy(bmap
);
612 bmap
= isl_basic_map_sort_constraints(bmap
);
616 c
= isl_vec_alloc(bmap
->ctx
, 1 + total
);
620 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
621 int l
= isl_seq_last_non_zero(bmap
->eq
[i
], 1 + total
);
623 if (i
!= bmap
->n_eq
- 1)
624 p
= isl_printer_print_str(p
, s_and
[latex
]);
625 p
= isl_printer_print_str(p
, "0 = 0");
628 if (isl_int_is_neg(bmap
->eq
[i
][l
]))
629 isl_seq_cpy(c
->el
, bmap
->eq
[i
], 1 + total
);
631 isl_seq_neg(c
->el
, bmap
->eq
[i
], 1 + total
);
632 p
= print_constraint(bmap
, space
, div
, p
, c
->el
, l
,
636 for (i
= 0; i
< bmap
->n_ineq
; ++i
) {
637 int l
= isl_seq_last_non_zero(bmap
->ineq
[i
], 1 + total
);
643 if (!dump
&& l
>= o_div
&&
644 can_print_div_expr(p
, div
, l
- o_div
) &&
645 isl_basic_map_is_div_constraint(bmap
, bmap
->ineq
[i
],
648 s
= isl_int_sgn(bmap
->ineq
[i
][l
]);
649 strict
= !rational
&& isl_int_is_negone(bmap
->ineq
[i
][0]);
651 isl_seq_cpy(c
->el
, bmap
->ineq
[i
], 1 + total
);
653 isl_seq_neg(c
->el
, bmap
->ineq
[i
], 1 + total
);
655 isl_int_set_si(c
->el
[0], 0);
656 if (!dump
&& next_is_opposite(bmap
, i
, l
)) {
657 op
= constraint_op(-s
, strict
, latex
);
658 p
= print_half_constraint(bmap
, space
, div
, p
, c
->el
, l
,
662 op
= constraint_op(s
, strict
, latex
);
663 p
= print_constraint(bmap
, space
, div
, p
, c
->el
, l
,
669 isl_basic_map_free(bmap
);
674 isl_basic_map_free(bmap
);
680 static __isl_give isl_printer
*print_div(__isl_keep isl_space
*dim
,
681 __isl_keep isl_mat
*div
, int pos
, __isl_take isl_printer
*p
)
686 return isl_printer_free(p
);
688 c
= p
->output_format
== ISL_FORMAT_C
;
689 p
= isl_printer_print_str(p
, c
? "floord(" : "floor((");
690 p
= print_affine_of_len(dim
, div
, p
,
691 div
->row
[pos
] + 1, div
->n_col
- 1);
692 p
= isl_printer_print_str(p
, c
? ", " : ")/");
693 p
= isl_printer_print_isl_int(p
, div
->row
[pos
][0]);
694 p
= isl_printer_print_str(p
, ")");
698 /* Print a comma separated list of div names, except those that have
699 * a definition that can be printed.
700 * If "print_defined_divs" is set, then those div names are printed
701 * as well, along with their definitions.
703 static __isl_give isl_printer
*print_div_list(__isl_take isl_printer
*p
,
704 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
, int latex
,
705 int print_defined_divs
)
711 if (!p
|| !space
|| !div
)
712 return isl_printer_free(p
);
714 n_div
= isl_mat_rows(div
);
716 for (i
= 0; i
< n_div
; ++i
) {
717 if (!print_defined_divs
&& can_print_div_expr(p
, div
, i
))
720 p
= isl_printer_print_str(p
, ", ");
721 p
= print_name(space
, p
, isl_dim_div
, i
, latex
);
723 if (!can_print_div_expr(p
, div
, i
))
725 p
= isl_printer_print_str(p
, " = ");
726 p
= print_div(space
, div
, i
, p
);
732 /* Does printing "bmap" require an "exists" clause?
733 * That is, are there any local variables without an explicit representation?
735 static isl_bool
need_exists(__isl_keep isl_printer
*p
,
736 __isl_keep isl_basic_map
*bmap
, __isl_keep isl_mat
*div
)
741 return isl_bool_error
;
742 if (bmap
->n_div
== 0)
743 return isl_bool_false
;
744 for (i
= 0; i
< bmap
->n_div
; ++i
)
745 if (!can_print_div_expr(p
, div
, i
))
746 return isl_bool_true
;
747 return isl_bool_false
;
750 /* Print the constraints of "bmap" to "p".
751 * The names of the variables are taken from "space".
752 * "latex" is set if the constraints should be printed in LaTeX format.
753 * Do not print inline explicit div representations in "dump" mode.
755 static __isl_give isl_printer
*print_disjunct(__isl_keep isl_basic_map
*bmap
,
756 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
765 div
= isl_basic_map_get_divs(bmap
);
767 exists
= bmap
->n_div
> 0;
769 exists
= need_exists(p
, bmap
, div
);
770 if (exists
>= 0 && exists
) {
771 p
= isl_printer_print_str(p
, s_open_exists
[latex
]);
772 p
= print_div_list(p
, space
, div
, latex
, dump
);
773 p
= isl_printer_print_str(p
, ": ");
777 div
= isl_mat_free(div
);
778 p
= print_constraints(bmap
, space
, div
, p
, latex
);
781 if (exists
>= 0 && exists
)
782 p
= isl_printer_print_str(p
, s_close_exists
[latex
]);
786 /* Print a colon followed by the constraints of "bmap"
787 * to "p", provided there are any constraints.
788 * The names of the variables are taken from "space".
789 * "latex" is set if the constraints should be printed in LaTeX format.
791 static __isl_give isl_printer
*print_optional_disjunct(
792 __isl_keep isl_basic_map
*bmap
, __isl_keep isl_space
*space
,
793 __isl_take isl_printer
*p
, int latex
)
795 if (isl_basic_map_plain_is_universe(bmap
))
798 p
= isl_printer_print_str(p
, ": ");
799 p
= print_disjunct(bmap
, space
, p
, latex
);
804 static __isl_give isl_printer
*basic_map_print_omega(
805 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
807 p
= isl_printer_print_str(p
, "{ [");
808 p
= print_var_list(p
, bmap
->dim
, isl_dim_in
);
809 p
= isl_printer_print_str(p
, "] -> [");
810 p
= print_var_list(p
, bmap
->dim
, isl_dim_out
);
811 p
= isl_printer_print_str(p
, "] ");
812 p
= print_optional_disjunct(bmap
, bmap
->dim
, p
, 0);
813 p
= isl_printer_print_str(p
, " }");
817 static __isl_give isl_printer
*basic_set_print_omega(
818 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
)
820 p
= isl_printer_print_str(p
, "{ [");
821 p
= print_var_list(p
, bset
->dim
, isl_dim_set
);
822 p
= isl_printer_print_str(p
, "] ");
823 p
= print_optional_disjunct(bset
, bset
->dim
, p
, 0);
824 p
= isl_printer_print_str(p
, " }");
828 static __isl_give isl_printer
*isl_map_print_omega(__isl_keep isl_map
*map
,
829 __isl_take isl_printer
*p
)
833 for (i
= 0; i
< map
->n
; ++i
) {
835 p
= isl_printer_print_str(p
, " union ");
836 p
= basic_map_print_omega(map
->p
[i
], p
);
841 static __isl_give isl_printer
*isl_set_print_omega(__isl_keep isl_set
*set
,
842 __isl_take isl_printer
*p
)
846 for (i
= 0; i
< set
->n
; ++i
) {
848 p
= isl_printer_print_str(p
, " union ");
849 p
= basic_set_print_omega(set
->p
[i
], p
);
854 static __isl_give isl_printer
*isl_basic_map_print_isl(
855 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
,
858 struct isl_print_space_data data
= { .latex
= latex
};
859 int rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
861 if (isl_basic_map_dim(bmap
, isl_dim_param
) > 0) {
862 p
= print_tuple(bmap
->dim
, p
, isl_dim_param
, &data
);
863 p
= isl_printer_print_str(p
, " -> ");
865 p
= isl_printer_print_str(p
, "{ ");
866 p
= isl_print_space(bmap
->dim
, p
, rational
, &data
);
867 p
= isl_printer_print_str(p
, " : ");
868 p
= print_disjunct(bmap
, bmap
->dim
, p
, latex
);
869 p
= isl_printer_print_str(p
, " }");
873 /* Print the disjuncts of a map (or set) "map" to "p".
874 * The names of the variables are taken from "space".
875 * "latex" is set if the constraints should be printed in LaTeX format.
877 static __isl_give isl_printer
*print_disjuncts_core(__isl_keep isl_map
*map
,
878 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
883 p
= isl_printer_print_str(p
, "1 = 0");
884 for (i
= 0; i
< map
->n
; ++i
) {
886 p
= isl_printer_print_str(p
, s_or
[latex
]);
887 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
888 p
= isl_printer_print_str(p
, "(");
889 p
= print_disjunct(map
->p
[i
], space
, p
, latex
);
890 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
891 p
= isl_printer_print_str(p
, ")");
896 /* Print the disjuncts of a map (or set) "map" to "p".
897 * The names of the variables are taken from "space".
898 * "hull" describes constraints shared by all disjuncts of "map".
899 * "latex" is set if the constraints should be printed in LaTeX format.
901 * Print the disjuncts as a conjunction of "hull" and
902 * the result of removing the constraints of "hull" from "map".
903 * If this result turns out to be the universe, then simply print "hull".
905 static __isl_give isl_printer
*print_disjuncts_in_hull(__isl_keep isl_map
*map
,
906 __isl_keep isl_space
*space
, __isl_take isl_basic_map
*hull
,
907 __isl_take isl_printer
*p
, int latex
)
909 isl_bool is_universe
;
911 p
= print_disjunct(hull
, space
, p
, latex
);
912 map
= isl_map_plain_gist_basic_map(isl_map_copy(map
), hull
);
913 is_universe
= isl_map_plain_is_universe(map
);
917 p
= isl_printer_print_str(p
, s_and
[latex
]);
918 p
= isl_printer_print_str(p
, "(");
919 p
= print_disjuncts_core(map
, space
, p
, latex
);
920 p
= isl_printer_print_str(p
, ")");
931 /* Print the disjuncts of a map (or set) "map" to "p".
932 * The names of the variables are taken from "space".
933 * "latex" is set if the constraints should be printed in LaTeX format.
935 * If there are at least two disjuncts and "dump" mode is not turned out,
936 * check for any shared constraints among all disjuncts.
937 * If there are any, then print them separately in print_disjuncts_in_hull.
939 static __isl_give isl_printer
*print_disjuncts(__isl_keep isl_map
*map
,
940 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
942 if (isl_map_plain_is_universe(map
))
945 p
= isl_printer_print_str(p
, s_such_that
[latex
]);
949 if (!p
->dump
&& map
->n
>= 2) {
951 isl_bool is_universe
;
953 hull
= isl_map_plain_unshifted_simple_hull(isl_map_copy(map
));
954 is_universe
= isl_basic_map_plain_is_universe(hull
);
956 p
= isl_printer_free(p
);
957 else if (!is_universe
)
958 return print_disjuncts_in_hull(map
, space
, hull
,
960 isl_basic_map_free(hull
);
963 return print_disjuncts_core(map
, space
, p
, latex
);
966 /* Print the disjuncts of a map (or set).
967 * The names of the variables are taken from "space".
968 * "latex" is set if the constraints should be printed in LaTeX format.
970 * If the map turns out to be a universal parameter domain, then
971 * we need to print the colon. Otherwise, the output looks identical
974 static __isl_give isl_printer
*print_disjuncts_map(__isl_keep isl_map
*map
,
975 __isl_keep isl_space
*space
, __isl_take isl_printer
*p
, int latex
)
977 if (isl_map_plain_is_universe(map
) && isl_space_is_params(map
->dim
))
978 return isl_printer_print_str(p
, s_such_that
[latex
]);
980 return print_disjuncts(map
, space
, p
, latex
);
983 struct isl_aff_split
{
988 static void free_split(__isl_take
struct isl_aff_split
*split
, int n
)
995 for (i
= 0; i
< n
; ++i
) {
996 isl_basic_map_free(split
[i
].aff
);
997 isl_map_free(split
[i
].map
);
1003 static __isl_give isl_basic_map
*get_aff(__isl_take isl_basic_map
*bmap
)
1006 unsigned nparam
, n_in
, n_out
, total
;
1008 bmap
= isl_basic_map_cow(bmap
);
1011 if (isl_basic_map_free_inequality(bmap
, bmap
->n_ineq
) < 0)
1014 nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
1015 n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
1016 n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
1017 total
= isl_basic_map_dim(bmap
, isl_dim_all
);
1018 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1019 j
= isl_seq_last_non_zero(bmap
->eq
[i
] + 1, total
);
1020 if (j
>= nparam
&& j
< nparam
+ n_in
+ n_out
&&
1021 (isl_int_is_one(bmap
->eq
[i
][1 + j
]) ||
1022 isl_int_is_negone(bmap
->eq
[i
][1 + j
])))
1024 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1028 bmap
= isl_basic_map_finalize(bmap
);
1032 isl_basic_map_free(bmap
);
1036 static int aff_split_cmp(const void *p1
, const void *p2
, void *user
)
1038 const struct isl_aff_split
*s1
, *s2
;
1039 s1
= (const struct isl_aff_split
*) p1
;
1040 s2
= (const struct isl_aff_split
*) p2
;
1042 return isl_basic_map_plain_cmp(s1
->aff
, s2
->aff
);
1045 static __isl_give isl_basic_map
*drop_aff(__isl_take isl_basic_map
*bmap
,
1046 __isl_keep isl_basic_map
*aff
)
1054 total
= isl_space_dim(bmap
->dim
, isl_dim_all
);
1056 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
1057 if (isl_seq_first_non_zero(bmap
->eq
[i
] + 1 + total
,
1060 for (j
= 0; j
< aff
->n_eq
; ++j
) {
1061 if (!isl_seq_eq(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
) &&
1062 !isl_seq_is_neg(bmap
->eq
[i
], aff
->eq
[j
], 1 + total
))
1064 if (isl_basic_map_drop_equality(bmap
, i
) < 0)
1072 isl_basic_map_free(bmap
);
1076 static __isl_give
struct isl_aff_split
*split_aff(__isl_keep isl_map
*map
)
1079 struct isl_aff_split
*split
;
1082 ctx
= isl_map_get_ctx(map
);
1083 split
= isl_calloc_array(ctx
, struct isl_aff_split
, map
->n
);
1087 for (i
= 0; i
< map
->n
; ++i
) {
1088 isl_basic_map
*bmap
;
1089 split
[i
].aff
= get_aff(isl_basic_map_copy(map
->p
[i
]));
1090 bmap
= isl_basic_map_copy(map
->p
[i
]);
1091 bmap
= isl_basic_map_cow(bmap
);
1092 bmap
= drop_aff(bmap
, split
[i
].aff
);
1093 split
[i
].map
= isl_map_from_basic_map(bmap
);
1094 if (!split
[i
].aff
|| !split
[i
].map
)
1098 if (isl_sort(split
, map
->n
, sizeof(struct isl_aff_split
),
1099 &aff_split_cmp
, NULL
) < 0)
1103 for (i
= n
- 1; i
>= 1; --i
) {
1104 if (!isl_basic_map_plain_is_equal(split
[i
- 1].aff
,
1107 isl_basic_map_free(split
[i
].aff
);
1108 split
[i
- 1].map
= isl_map_union(split
[i
- 1].map
,
1111 split
[i
] = split
[n
- 1];
1112 split
[n
- 1].aff
= NULL
;
1113 split
[n
- 1].map
= NULL
;
1119 free_split(split
, map
->n
);
1123 static int defining_equality(__isl_keep isl_basic_map
*eq
,
1124 __isl_keep isl_space
*dim
, enum isl_dim_type type
, int pos
)
1132 pos
+= isl_space_offset(dim
, type
);
1133 total
= isl_basic_map_total_dim(eq
);
1135 for (i
= 0; i
< eq
->n_eq
; ++i
) {
1136 if (isl_seq_last_non_zero(eq
->eq
[i
] + 1, total
) != pos
)
1138 if (isl_int_is_one(eq
->eq
[i
][1 + pos
]))
1139 isl_seq_neg(eq
->eq
[i
], eq
->eq
[i
], 1 + total
);
1146 /* Print dimension "pos" of data->space to "p".
1148 * data->user is assumed to be an isl_basic_map keeping track of equalities.
1150 * If the current dimension is defined by these equalities, then print
1151 * the corresponding expression, assigned to the name of the dimension
1152 * if there is any. Otherwise, print the name of the dimension.
1154 static __isl_give isl_printer
*print_dim_eq(__isl_take isl_printer
*p
,
1155 struct isl_print_space_data
*data
, unsigned pos
)
1157 isl_basic_map
*eq
= data
->user
;
1160 j
= defining_equality(eq
, data
->space
, data
->type
, pos
);
1162 if (isl_space_has_dim_name(data
->space
, data
->type
, pos
)) {
1163 p
= print_name(data
->space
, p
, data
->type
, pos
,
1165 p
= isl_printer_print_str(p
, " = ");
1167 pos
+= 1 + isl_space_offset(data
->space
, data
->type
);
1168 p
= print_affine_of_len(data
->space
, NULL
, p
, eq
->eq
[j
], pos
);
1170 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
1176 static __isl_give isl_printer
*print_split_map(__isl_take isl_printer
*p
,
1177 struct isl_aff_split
*split
, int n
, __isl_keep isl_space
*space
)
1179 struct isl_print_space_data data
= { 0 };
1183 data
.print_dim
= &print_dim_eq
;
1184 for (i
= 0; i
< n
; ++i
) {
1187 rational
= split
[i
].map
->n
> 0 &&
1188 ISL_F_ISSET(split
[i
].map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1190 p
= isl_printer_print_str(p
, "; ");
1191 data
.user
= split
[i
].aff
;
1192 p
= isl_print_space(space
, p
, rational
, &data
);
1193 p
= print_disjuncts_map(split
[i
].map
, space
, p
, 0);
1199 static __isl_give isl_printer
*isl_map_print_isl_body(__isl_keep isl_map
*map
,
1200 __isl_take isl_printer
*p
)
1202 struct isl_print_space_data data
= { 0 };
1203 struct isl_aff_split
*split
= NULL
;
1207 return isl_printer_free(p
);
1208 if (!p
->dump
&& map
->n
> 0)
1209 split
= split_aff(map
);
1211 p
= print_split_map(p
, split
, map
->n
, map
->dim
);
1213 rational
= map
->n
> 0 &&
1214 ISL_F_ISSET(map
->p
[0], ISL_BASIC_MAP_RATIONAL
);
1215 p
= isl_print_space(map
->dim
, p
, rational
, &data
);
1216 p
= print_disjuncts_map(map
, map
->dim
, p
, 0);
1218 free_split(split
, map
->n
);
1222 static __isl_give isl_printer
*isl_map_print_isl(__isl_keep isl_map
*map
,
1223 __isl_take isl_printer
*p
)
1225 struct isl_print_space_data data
= { 0 };
1227 if (isl_map_dim(map
, isl_dim_param
) > 0) {
1228 p
= print_tuple(map
->dim
, p
, isl_dim_param
, &data
);
1229 p
= isl_printer_print_str(p
, s_to
[0]);
1231 p
= isl_printer_print_str(p
, s_open_set
[0]);
1232 p
= isl_map_print_isl_body(map
, p
);
1233 p
= isl_printer_print_str(p
, s_close_set
[0]);
1237 static __isl_give isl_printer
*print_latex_map(__isl_keep isl_map
*map
,
1238 __isl_take isl_printer
*p
, __isl_keep isl_basic_map
*aff
)
1240 struct isl_print_space_data data
= { 0 };
1243 if (isl_map_dim(map
, isl_dim_param
) > 0) {
1244 p
= print_tuple(map
->dim
, p
, isl_dim_param
, &data
);
1245 p
= isl_printer_print_str(p
, s_to
[1]);
1247 p
= isl_printer_print_str(p
, s_open_set
[1]);
1248 data
.print_dim
= &print_dim_eq
;
1250 p
= isl_print_space(map
->dim
, p
, 0, &data
);
1251 p
= print_disjuncts_map(map
, map
->dim
, p
, 1);
1252 p
= isl_printer_print_str(p
, s_close_set
[1]);
1257 static __isl_give isl_printer
*isl_map_print_latex(__isl_keep isl_map
*map
,
1258 __isl_take isl_printer
*p
)
1261 struct isl_aff_split
*split
= NULL
;
1264 split
= split_aff(map
);
1267 return print_latex_map(map
, p
, NULL
);
1269 for (i
= 0; i
< map
->n
; ++i
) {
1273 p
= isl_printer_print_str(p
, " \\cup ");
1274 p
= print_latex_map(split
[i
].map
, p
, split
[i
].aff
);
1277 free_split(split
, map
->n
);
1281 __isl_give isl_printer
*isl_printer_print_basic_map(__isl_take isl_printer
*p
,
1282 __isl_keep isl_basic_map
*bmap
)
1286 if (p
->output_format
== ISL_FORMAT_ISL
)
1287 return isl_basic_map_print_isl(bmap
, p
, 0);
1288 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1289 return basic_map_print_omega(bmap
, p
);
1290 isl_assert(bmap
->ctx
, 0, goto error
);
1292 isl_printer_free(p
);
1296 __isl_give isl_printer
*isl_printer_print_basic_set(__isl_take isl_printer
*p
,
1297 __isl_keep isl_basic_set
*bset
)
1302 if (p
->output_format
== ISL_FORMAT_ISL
)
1303 return isl_basic_map_print_isl(bset
, p
, 0);
1304 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1305 return isl_basic_set_print_polylib(bset
, p
, 0);
1306 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1307 return isl_basic_set_print_polylib(bset
, p
, 1);
1308 else if (p
->output_format
== ISL_FORMAT_POLYLIB_CONSTRAINTS
)
1309 return bset_print_constraints_polylib(bset
, p
);
1310 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1311 return basic_set_print_omega(bset
, p
);
1312 isl_assert(p
->ctx
, 0, goto error
);
1314 isl_printer_free(p
);
1318 __isl_give isl_printer
*isl_printer_print_set(__isl_take isl_printer
*p
,
1319 __isl_keep isl_set
*set
)
1323 if (p
->output_format
== ISL_FORMAT_ISL
)
1324 return isl_map_print_isl(set_to_map(set
), p
);
1325 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1326 return isl_set_print_polylib(set
, p
, 0);
1327 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1328 return isl_set_print_polylib(set
, p
, 1);
1329 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1330 return isl_set_print_omega(set
, p
);
1331 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1332 return isl_map_print_latex(set_to_map(set
), p
);
1333 isl_assert(set
->ctx
, 0, goto error
);
1335 isl_printer_free(p
);
1339 __isl_give isl_printer
*isl_printer_print_map(__isl_take isl_printer
*p
,
1340 __isl_keep isl_map
*map
)
1345 if (p
->output_format
== ISL_FORMAT_ISL
)
1346 return isl_map_print_isl(map
, p
);
1347 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
1348 return isl_map_print_polylib(map
, p
, 0);
1349 else if (p
->output_format
== ISL_FORMAT_EXT_POLYLIB
)
1350 return isl_map_print_polylib(map
, p
, 1);
1351 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
1352 return isl_map_print_omega(map
, p
);
1353 else if (p
->output_format
== ISL_FORMAT_LATEX
)
1354 return isl_map_print_latex(map
, p
);
1355 isl_assert(map
->ctx
, 0, goto error
);
1357 isl_printer_free(p
);
1361 struct isl_union_print_data
{
1366 static isl_stat
print_map_body(__isl_take isl_map
*map
, void *user
)
1368 struct isl_union_print_data
*data
;
1369 data
= (struct isl_union_print_data
*)user
;
1372 data
->p
= isl_printer_print_str(data
->p
, "; ");
1375 data
->p
= isl_map_print_isl_body(map
, data
->p
);
1381 static __isl_give isl_printer
*isl_union_map_print_isl(
1382 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1384 struct isl_union_print_data data
;
1385 struct isl_print_space_data space_data
= { 0 };
1388 dim
= isl_union_map_get_space(umap
);
1389 if (isl_space_dim(dim
, isl_dim_param
) > 0) {
1390 p
= print_tuple(dim
, p
, isl_dim_param
, &space_data
);
1391 p
= isl_printer_print_str(p
, s_to
[0]);
1393 isl_space_free(dim
);
1394 p
= isl_printer_print_str(p
, s_open_set
[0]);
1397 isl_union_map_foreach_map(umap
, &print_map_body
, &data
);
1399 p
= isl_printer_print_str(p
, s_close_set
[0]);
1403 static isl_stat
print_latex_map_body(__isl_take isl_map
*map
, void *user
)
1405 struct isl_union_print_data
*data
;
1406 data
= (struct isl_union_print_data
*)user
;
1409 data
->p
= isl_printer_print_str(data
->p
, " \\cup ");
1412 data
->p
= isl_map_print_latex(map
, data
->p
);
1418 static __isl_give isl_printer
*isl_union_map_print_latex(
1419 __isl_keep isl_union_map
*umap
, __isl_take isl_printer
*p
)
1421 struct isl_union_print_data data
= { p
, 1 };
1422 isl_union_map_foreach_map(umap
, &print_latex_map_body
, &data
);
1427 __isl_give isl_printer
*isl_printer_print_union_map(__isl_take isl_printer
*p
,
1428 __isl_keep isl_union_map
*umap
)
1433 if (p
->output_format
== ISL_FORMAT_ISL
)
1434 return isl_union_map_print_isl(umap
, p
);
1435 if (p
->output_format
== ISL_FORMAT_LATEX
)
1436 return isl_union_map_print_latex(umap
, p
);
1438 isl_die(p
->ctx
, isl_error_invalid
,
1439 "invalid output format for isl_union_map", goto error
);
1441 isl_printer_free(p
);
1445 __isl_give isl_printer
*isl_printer_print_union_set(__isl_take isl_printer
*p
,
1446 __isl_keep isl_union_set
*uset
)
1451 if (p
->output_format
== ISL_FORMAT_ISL
)
1452 return isl_union_map_print_isl((isl_union_map
*)uset
, p
);
1453 if (p
->output_format
== ISL_FORMAT_LATEX
)
1454 return isl_union_map_print_latex((isl_union_map
*)uset
, p
);
1456 isl_die(p
->ctx
, isl_error_invalid
,
1457 "invalid output format for isl_union_set", goto error
);
1459 isl_printer_free(p
);
1463 static int upoly_rec_n_non_zero(__isl_keep
struct isl_upoly_rec
*rec
)
1468 for (i
= 0, n
= 0; i
< rec
->n
; ++i
)
1469 if (!isl_upoly_is_zero(rec
->p
[i
]))
1475 static __isl_give isl_printer
*upoly_print_cst(__isl_keep
struct isl_upoly
*up
,
1476 __isl_take isl_printer
*p
, int first
)
1478 struct isl_upoly_cst
*cst
;
1481 cst
= isl_upoly_as_cst(up
);
1484 neg
= !first
&& isl_int_is_neg(cst
->n
);
1486 p
= isl_printer_print_str(p
, neg
? " - " : " + ");
1488 isl_int_neg(cst
->n
, cst
->n
);
1489 if (isl_int_is_zero(cst
->d
)) {
1490 int sgn
= isl_int_sgn(cst
->n
);
1491 p
= isl_printer_print_str(p
, sgn
< 0 ? "-infty" :
1492 sgn
== 0 ? "NaN" : "infty");
1494 p
= isl_printer_print_isl_int(p
, cst
->n
);
1496 isl_int_neg(cst
->n
, cst
->n
);
1497 if (!isl_int_is_zero(cst
->d
) && !isl_int_is_one(cst
->d
)) {
1498 p
= isl_printer_print_str(p
, "/");
1499 p
= isl_printer_print_isl_int(p
, cst
->d
);
1503 isl_printer_free(p
);
1507 static __isl_give isl_printer
*print_base(__isl_take isl_printer
*p
,
1508 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
)
1512 total
= isl_space_dim(dim
, isl_dim_all
);
1514 p
= print_term(dim
, NULL
, dim
->ctx
->one
, 1 + var
, p
, 0);
1516 p
= print_div(dim
, div
, var
- total
, p
);
1520 static __isl_give isl_printer
*print_pow(__isl_take isl_printer
*p
,
1521 __isl_keep isl_space
*dim
, __isl_keep isl_mat
*div
, int var
, int exp
)
1523 p
= print_base(p
, dim
, div
, var
);
1526 if (p
->output_format
== ISL_FORMAT_C
) {
1528 for (i
= 1; i
< exp
; ++i
) {
1529 p
= isl_printer_print_str(p
, "*");
1530 p
= print_base(p
, dim
, div
, var
);
1533 p
= isl_printer_print_str(p
, "^");
1534 p
= isl_printer_print_int(p
, exp
);
1539 /* Print the polynomial "up" defined over the domain space "space" and
1540 * local variables defined by "div" to "p".
1541 * If "outer" is set, then "up" is not nested inside another polynomial.
1543 static __isl_give isl_printer
*upoly_print(__isl_keep
struct isl_upoly
*up
,
1544 __isl_keep isl_space
*space
, __isl_keep isl_mat
*div
,
1545 __isl_take isl_printer
*p
, int outer
)
1547 int i
, n
, first
, print_parens
;
1548 struct isl_upoly_rec
*rec
;
1550 if (!p
|| !up
|| !space
|| !div
)
1553 if (isl_upoly_is_cst(up
))
1554 return upoly_print_cst(up
, p
, 1);
1556 rec
= isl_upoly_as_rec(up
);
1559 n
= upoly_rec_n_non_zero(rec
);
1560 print_parens
= n
> 1 ||
1561 (outer
&& rec
->up
.var
>= isl_space_dim(space
, isl_dim_all
));
1563 p
= isl_printer_print_str(p
, "(");
1564 for (i
= 0, first
= 1; i
< rec
->n
; ++i
) {
1565 if (isl_upoly_is_zero(rec
->p
[i
]))
1567 if (isl_upoly_is_negone(rec
->p
[i
])) {
1569 p
= isl_printer_print_str(p
, "-1");
1571 p
= isl_printer_print_str(p
, "-");
1573 p
= isl_printer_print_str(p
, " - ");
1574 } else if (isl_upoly_is_cst(rec
->p
[i
]) &&
1575 !isl_upoly_is_one(rec
->p
[i
]))
1576 p
= upoly_print_cst(rec
->p
[i
], p
, first
);
1579 p
= isl_printer_print_str(p
, " + ");
1580 if (i
== 0 || !isl_upoly_is_one(rec
->p
[i
]))
1581 p
= upoly_print(rec
->p
[i
], space
, div
, p
, 0);
1586 if (!isl_upoly_is_one(rec
->p
[i
]) &&
1587 !isl_upoly_is_negone(rec
->p
[i
]))
1588 p
= isl_printer_print_str(p
, " * ");
1589 p
= print_pow(p
, space
, div
, rec
->up
.var
, i
);
1592 p
= isl_printer_print_str(p
, ")");
1595 isl_printer_free(p
);
1599 static __isl_give isl_printer
*print_qpolynomial(__isl_take isl_printer
*p
,
1600 __isl_keep isl_qpolynomial
*qp
)
1604 p
= upoly_print(qp
->upoly
, qp
->dim
, qp
->div
, p
, 1);
1607 isl_printer_free(p
);
1611 static __isl_give isl_printer
*print_qpolynomial_isl(__isl_take isl_printer
*p
,
1612 __isl_keep isl_qpolynomial
*qp
)
1614 struct isl_print_space_data data
= { 0 };
1619 if (isl_space_dim(qp
->dim
, isl_dim_param
) > 0) {
1620 p
= print_tuple(qp
->dim
, p
, isl_dim_param
, &data
);
1621 p
= isl_printer_print_str(p
, " -> ");
1623 p
= isl_printer_print_str(p
, "{ ");
1624 if (!isl_space_is_params(qp
->dim
)) {
1625 p
= isl_print_space(qp
->dim
, p
, 0, &data
);
1626 p
= isl_printer_print_str(p
, " -> ");
1628 p
= print_qpolynomial(p
, qp
);
1629 p
= isl_printer_print_str(p
, " }");
1632 isl_printer_free(p
);
1636 /* Print the quasi-polynomial "qp" to "p" in C format, with the variable names
1637 * taken from the domain space "space".
1639 static __isl_give isl_printer
*print_qpolynomial_c(__isl_take isl_printer
*p
,
1640 __isl_keep isl_space
*space
, __isl_keep isl_qpolynomial
*qp
)
1645 isl_qpolynomial_get_den(qp
, &den
);
1646 if (!isl_int_is_one(den
)) {
1648 p
= isl_printer_print_str(p
, "(");
1649 qp
= isl_qpolynomial_copy(qp
);
1650 f
= isl_qpolynomial_rat_cst_on_domain(isl_space_copy(qp
->dim
),
1651 den
, qp
->dim
->ctx
->one
);
1652 qp
= isl_qpolynomial_mul(qp
, f
);
1655 p
= upoly_print(qp
->upoly
, space
, qp
->div
, p
, 0);
1657 p
= isl_printer_free(p
);
1658 if (!isl_int_is_one(den
)) {
1659 p
= isl_printer_print_str(p
, ")/");
1660 p
= isl_printer_print_isl_int(p
, den
);
1661 isl_qpolynomial_free(qp
);
1667 __isl_give isl_printer
*isl_printer_print_qpolynomial(
1668 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial
*qp
)
1673 if (p
->output_format
== ISL_FORMAT_ISL
)
1674 return print_qpolynomial_isl(p
, qp
);
1675 else if (p
->output_format
== ISL_FORMAT_C
)
1676 return print_qpolynomial_c(p
, qp
->dim
, qp
);
1678 isl_die(qp
->dim
->ctx
, isl_error_unsupported
,
1679 "output format not supported for isl_qpolynomials",
1682 isl_printer_free(p
);
1686 void isl_qpolynomial_print(__isl_keep isl_qpolynomial
*qp
, FILE *out
,
1687 unsigned output_format
)
1694 isl_assert(qp
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1695 p
= isl_printer_to_file(qp
->dim
->ctx
, out
);
1696 p
= isl_printer_print_qpolynomial(p
, qp
);
1697 isl_printer_free(p
);
1700 static __isl_give isl_printer
*qpolynomial_fold_print(
1701 __isl_keep isl_qpolynomial_fold
*fold
, __isl_take isl_printer
*p
)
1705 if (fold
->type
== isl_fold_min
)
1706 p
= isl_printer_print_str(p
, "min");
1707 else if (fold
->type
== isl_fold_max
)
1708 p
= isl_printer_print_str(p
, "max");
1709 p
= isl_printer_print_str(p
, "(");
1710 for (i
= 0; i
< fold
->n
; ++i
) {
1712 p
= isl_printer_print_str(p
, ", ");
1713 p
= print_qpolynomial(p
, fold
->qp
[i
]);
1715 p
= isl_printer_print_str(p
, ")");
1719 void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold
*fold
,
1720 FILE *out
, unsigned output_format
)
1727 isl_assert(fold
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
1729 p
= isl_printer_to_file(fold
->dim
->ctx
, out
);
1730 p
= isl_printer_print_qpolynomial_fold(p
, fold
);
1732 isl_printer_free(p
);
1735 static __isl_give isl_printer
*isl_pwqp_print_isl_body(
1736 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1738 struct isl_print_space_data data
= { 0 };
1741 for (i
= 0; i
< pwqp
->n
; ++i
) {
1745 p
= isl_printer_print_str(p
, "; ");
1746 space
= isl_qpolynomial_get_domain_space(pwqp
->p
[i
].qp
);
1747 if (!isl_space_is_params(space
)) {
1748 p
= isl_print_space(space
, p
, 0, &data
);
1749 p
= isl_printer_print_str(p
, " -> ");
1751 p
= print_qpolynomial(p
, pwqp
->p
[i
].qp
);
1752 p
= print_disjuncts(set_to_map(pwqp
->p
[i
].set
), space
, p
, 0);
1753 isl_space_free(space
);
1759 static __isl_give isl_printer
*print_pw_qpolynomial_isl(
1760 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
1762 struct isl_print_space_data data
= { 0 };
1767 if (isl_space_dim(pwqp
->dim
, isl_dim_param
) > 0) {
1768 p
= print_tuple(pwqp
->dim
, p
, isl_dim_param
, &data
);
1769 p
= isl_printer_print_str(p
, " -> ");
1771 p
= isl_printer_print_str(p
, "{ ");
1773 if (!isl_space_is_set(pwqp
->dim
)) {
1774 p
= print_tuple(pwqp
->dim
, p
, isl_dim_in
, &data
);
1775 p
= isl_printer_print_str(p
, " -> ");
1777 p
= isl_printer_print_str(p
, "0");
1779 p
= isl_pwqp_print_isl_body(p
, pwqp
);
1780 p
= isl_printer_print_str(p
, " }");
1783 isl_printer_free(p
);
1787 void isl_pw_qpolynomial_print(__isl_keep isl_pw_qpolynomial
*pwqp
, FILE *out
,
1788 unsigned output_format
)
1795 p
= isl_printer_to_file(pwqp
->dim
->ctx
, out
);
1796 p
= isl_printer_set_output_format(p
, output_format
);
1797 p
= isl_printer_print_pw_qpolynomial(p
, pwqp
);
1799 isl_printer_free(p
);
1802 static __isl_give isl_printer
*isl_pwf_print_isl_body(
1803 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
1805 struct isl_print_space_data data
= { 0 };
1808 for (i
= 0; i
< pwf
->n
; ++i
) {
1812 p
= isl_printer_print_str(p
, "; ");
1813 space
= isl_qpolynomial_fold_get_domain_space(pwf
->p
[i
].fold
);
1814 if (!isl_space_is_params(space
)) {
1815 p
= isl_print_space(space
, p
, 0, &data
);
1816 p
= isl_printer_print_str(p
, " -> ");
1818 p
= qpolynomial_fold_print(pwf
->p
[i
].fold
, p
);
1819 p
= print_disjuncts(set_to_map(pwf
->p
[i
].set
), space
, p
, 0);
1820 isl_space_free(space
);
1826 static __isl_give isl_printer
*print_pw_qpolynomial_fold_isl(
1827 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
1829 struct isl_print_space_data data
= { 0 };
1831 if (isl_space_dim(pwf
->dim
, isl_dim_param
) > 0) {
1832 p
= print_tuple(pwf
->dim
, p
, isl_dim_param
, &data
);
1833 p
= isl_printer_print_str(p
, " -> ");
1835 p
= isl_printer_print_str(p
, "{ ");
1837 if (!isl_space_is_set(pwf
->dim
)) {
1838 p
= print_tuple(pwf
->dim
, p
, isl_dim_in
, &data
);
1839 p
= isl_printer_print_str(p
, " -> ");
1841 p
= isl_printer_print_str(p
, "0");
1843 p
= isl_pwf_print_isl_body(p
, pwf
);
1844 p
= isl_printer_print_str(p
, " }");
1848 static __isl_give isl_printer
*print_affine_c(__isl_take isl_printer
*p
,
1849 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
, isl_int
*c
);
1851 static __isl_give isl_printer
*print_name_c(__isl_take isl_printer
*p
,
1852 __isl_keep isl_space
*dim
,
1853 __isl_keep isl_basic_set
*bset
, enum isl_dim_type type
, unsigned pos
)
1855 if (type
== isl_dim_div
) {
1856 p
= isl_printer_print_str(p
, "floord(");
1857 p
= print_affine_c(p
, dim
, bset
, bset
->div
[pos
] + 1);
1858 p
= isl_printer_print_str(p
, ", ");
1859 p
= isl_printer_print_isl_int(p
, bset
->div
[pos
][0]);
1860 p
= isl_printer_print_str(p
, ")");
1864 name
= isl_space_get_dim_name(dim
, type
, pos
);
1867 p
= isl_printer_print_str(p
, name
);
1872 static __isl_give isl_printer
*print_term_c(__isl_take isl_printer
*p
,
1873 __isl_keep isl_space
*dim
,
1874 __isl_keep isl_basic_set
*bset
, isl_int c
, unsigned pos
)
1876 enum isl_dim_type type
;
1879 return isl_printer_print_isl_int(p
, c
);
1881 if (isl_int_is_one(c
))
1883 else if (isl_int_is_negone(c
))
1884 p
= isl_printer_print_str(p
, "-");
1886 p
= isl_printer_print_isl_int(p
, c
);
1887 p
= isl_printer_print_str(p
, "*");
1889 type
= pos2type(dim
, &pos
);
1890 p
= print_name_c(p
, dim
, bset
, type
, pos
);
1894 static __isl_give isl_printer
*print_partial_affine_c(__isl_take isl_printer
*p
,
1895 __isl_keep isl_space
*dim
,
1896 __isl_keep isl_basic_set
*bset
, isl_int
*c
, unsigned len
)
1901 for (i
= 0, first
= 1; i
< len
; ++i
) {
1903 if (isl_int_is_zero(c
[i
]))
1906 if (isl_int_is_neg(c
[i
])) {
1908 isl_int_neg(c
[i
], c
[i
]);
1909 p
= isl_printer_print_str(p
, " - ");
1911 p
= isl_printer_print_str(p
, " + ");
1914 p
= print_term_c(p
, dim
, bset
, c
[i
], i
);
1916 isl_int_neg(c
[i
], c
[i
]);
1919 p
= isl_printer_print_str(p
, "0");
1923 static __isl_give isl_printer
*print_affine_c(__isl_take isl_printer
*p
,
1924 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
, isl_int
*c
)
1926 unsigned len
= 1 + isl_basic_set_total_dim(bset
);
1927 return print_partial_affine_c(p
, dim
, bset
, c
, len
);
1930 /* We skip the constraint if it is implied by the div expression.
1932 * *first indicates whether this is the first constraint in the conjunction and
1933 * is updated if the constraint is actually printed.
1935 static __isl_give isl_printer
*print_constraint_c(__isl_take isl_printer
*p
,
1936 __isl_keep isl_space
*dim
,
1937 __isl_keep isl_basic_set
*bset
, isl_int
*c
, const char *op
, int *first
)
1943 o_div
= isl_basic_set_offset(bset
, isl_dim_div
);
1944 n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
1945 div
= isl_seq_last_non_zero(c
+ o_div
, n_div
);
1946 if (div
>= 0 && isl_basic_set_is_div_constraint(bset
, c
, div
))
1950 p
= isl_printer_print_str(p
, " && ");
1952 p
= print_affine_c(p
, dim
, bset
, c
);
1953 p
= isl_printer_print_str(p
, " ");
1954 p
= isl_printer_print_str(p
, op
);
1955 p
= isl_printer_print_str(p
, " 0");
1962 static __isl_give isl_printer
*print_basic_set_c(__isl_take isl_printer
*p
,
1963 __isl_keep isl_space
*dim
, __isl_keep isl_basic_set
*bset
)
1967 unsigned n_div
= isl_basic_set_dim(bset
, isl_dim_div
);
1968 unsigned total
= isl_basic_set_total_dim(bset
) - n_div
;
1970 for (i
= 0; i
< bset
->n_eq
; ++i
) {
1971 j
= isl_seq_last_non_zero(bset
->eq
[i
] + 1 + total
, n_div
);
1973 p
= print_constraint_c(p
, dim
, bset
,
1974 bset
->eq
[i
], "==", &first
);
1977 p
= isl_printer_print_str(p
, " && ");
1978 p
= isl_printer_print_str(p
, "(");
1979 p
= print_partial_affine_c(p
, dim
, bset
, bset
->eq
[i
],
1981 p
= isl_printer_print_str(p
, ") % ");
1982 p
= isl_printer_print_isl_int(p
,
1983 bset
->eq
[i
][1 + total
+ j
]);
1984 p
= isl_printer_print_str(p
, " == 0");
1988 for (i
= 0; i
< bset
->n_ineq
; ++i
)
1989 p
= print_constraint_c(p
, dim
, bset
, bset
->ineq
[i
], ">=",
1994 static __isl_give isl_printer
*print_set_c(__isl_take isl_printer
*p
,
1995 __isl_keep isl_space
*dim
, __isl_keep isl_set
*set
)
2000 return isl_printer_free(p
);
2003 p
= isl_printer_print_str(p
, "0");
2005 for (i
= 0; i
< set
->n
; ++i
) {
2007 p
= isl_printer_print_str(p
, " || ");
2009 p
= isl_printer_print_str(p
, "(");
2010 p
= print_basic_set_c(p
, dim
, set
->p
[i
]);
2012 p
= isl_printer_print_str(p
, ")");
2017 /* Print the piecewise quasi-polynomial "pwqp" to "p" in C format.
2019 static __isl_give isl_printer
*print_pw_qpolynomial_c(
2020 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2025 space
= isl_pw_qpolynomial_get_domain_space(pwqp
);
2026 if (pwqp
->n
== 1 && isl_set_plain_is_universe(pwqp
->p
[0].set
)) {
2027 p
= print_qpolynomial_c(p
, space
, pwqp
->p
[0].qp
);
2028 isl_space_free(space
);
2032 for (i
= 0; i
< pwqp
->n
; ++i
) {
2033 p
= isl_printer_print_str(p
, "(");
2034 p
= print_set_c(p
, space
, pwqp
->p
[i
].set
);
2035 p
= isl_printer_print_str(p
, ") ? (");
2036 p
= print_qpolynomial_c(p
, space
, pwqp
->p
[i
].qp
);
2037 p
= isl_printer_print_str(p
, ") : ");
2040 isl_space_free(space
);
2041 p
= isl_printer_print_str(p
, "0");
2045 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial(
2046 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
2051 if (p
->output_format
== ISL_FORMAT_ISL
)
2052 return print_pw_qpolynomial_isl(p
, pwqp
);
2053 else if (p
->output_format
== ISL_FORMAT_C
)
2054 return print_pw_qpolynomial_c(p
, pwqp
);
2055 isl_assert(p
->ctx
, 0, goto error
);
2057 isl_printer_free(p
);
2061 static isl_stat
print_pwqp_body(__isl_take isl_pw_qpolynomial
*pwqp
, void *user
)
2063 struct isl_union_print_data
*data
;
2064 data
= (struct isl_union_print_data
*)user
;
2067 data
->p
= isl_printer_print_str(data
->p
, "; ");
2070 data
->p
= isl_pwqp_print_isl_body(data
->p
, pwqp
);
2071 isl_pw_qpolynomial_free(pwqp
);
2076 static __isl_give isl_printer
*print_union_pw_qpolynomial_isl(
2077 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2079 struct isl_union_print_data data
;
2080 struct isl_print_space_data space_data
= { 0 };
2083 dim
= isl_union_pw_qpolynomial_get_space(upwqp
);
2084 if (isl_space_dim(dim
, isl_dim_param
) > 0) {
2085 p
= print_tuple(dim
, p
, isl_dim_param
, &space_data
);
2086 p
= isl_printer_print_str(p
, " -> ");
2088 isl_space_free(dim
);
2089 p
= isl_printer_print_str(p
, "{ ");
2092 isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp
, &print_pwqp_body
,
2095 p
= isl_printer_print_str(p
, " }");
2099 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial(
2100 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_qpolynomial
*upwqp
)
2105 if (p
->output_format
== ISL_FORMAT_ISL
)
2106 return print_union_pw_qpolynomial_isl(p
, upwqp
);
2107 isl_die(p
->ctx
, isl_error_invalid
,
2108 "invalid output format for isl_union_pw_qpolynomial",
2111 isl_printer_free(p
);
2115 /* Print the quasi-polynomial reduction "fold" to "p" in C format,
2116 * with the variable names taken from the domain space "space".
2118 static __isl_give isl_printer
*print_qpolynomial_fold_c(
2119 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
,
2120 __isl_keep isl_qpolynomial_fold
*fold
)
2124 for (i
= 0; i
< fold
->n
- 1; ++i
)
2125 if (fold
->type
== isl_fold_min
)
2126 p
= isl_printer_print_str(p
, "min(");
2127 else if (fold
->type
== isl_fold_max
)
2128 p
= isl_printer_print_str(p
, "max(");
2130 for (i
= 0; i
< fold
->n
; ++i
) {
2132 p
= isl_printer_print_str(p
, ", ");
2133 p
= print_qpolynomial_c(p
, space
, fold
->qp
[i
]);
2135 p
= isl_printer_print_str(p
, ")");
2140 __isl_give isl_printer
*isl_printer_print_qpolynomial_fold(
2141 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial_fold
*fold
)
2145 if (p
->output_format
== ISL_FORMAT_ISL
)
2146 return qpolynomial_fold_print(fold
, p
);
2147 else if (p
->output_format
== ISL_FORMAT_C
)
2148 return print_qpolynomial_fold_c(p
, fold
->dim
, fold
);
2149 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2152 isl_printer_free(p
);
2156 /* Print the piecewise quasi-polynomial reduction "pwf" to "p" in C format.
2158 static __isl_give isl_printer
*print_pw_qpolynomial_fold_c(
2159 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2164 space
= isl_pw_qpolynomial_fold_get_domain_space(pwf
);
2165 if (pwf
->n
== 1 && isl_set_plain_is_universe(pwf
->p
[0].set
)) {
2166 p
= print_qpolynomial_fold_c(p
, space
, pwf
->p
[0].fold
);
2167 isl_space_free(space
);
2171 for (i
= 0; i
< pwf
->n
; ++i
) {
2172 p
= isl_printer_print_str(p
, "(");
2173 p
= print_set_c(p
, space
, pwf
->p
[i
].set
);
2174 p
= isl_printer_print_str(p
, ") ? (");
2175 p
= print_qpolynomial_fold_c(p
, space
, pwf
->p
[i
].fold
);
2176 p
= isl_printer_print_str(p
, ") : ");
2179 isl_space_free(space
);
2180 p
= isl_printer_print_str(p
, "0");
2184 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial_fold(
2185 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
2190 if (p
->output_format
== ISL_FORMAT_ISL
)
2191 return print_pw_qpolynomial_fold_isl(p
, pwf
);
2192 else if (p
->output_format
== ISL_FORMAT_C
)
2193 return print_pw_qpolynomial_fold_c(p
, pwf
);
2194 isl_assert(p
->ctx
, 0, goto error
);
2196 isl_printer_free(p
);
2200 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold
*pwf
,
2201 FILE *out
, unsigned output_format
)
2208 p
= isl_printer_to_file(pwf
->dim
->ctx
, out
);
2209 p
= isl_printer_set_output_format(p
, output_format
);
2210 p
= isl_printer_print_pw_qpolynomial_fold(p
, pwf
);
2212 isl_printer_free(p
);
2215 static isl_stat
print_pwf_body(__isl_take isl_pw_qpolynomial_fold
*pwf
,
2218 struct isl_union_print_data
*data
;
2219 data
= (struct isl_union_print_data
*)user
;
2222 data
->p
= isl_printer_print_str(data
->p
, "; ");
2225 data
->p
= isl_pwf_print_isl_body(data
->p
, pwf
);
2226 isl_pw_qpolynomial_fold_free(pwf
);
2231 static __isl_give isl_printer
*print_union_pw_qpolynomial_fold_isl(
2232 __isl_take isl_printer
*p
,
2233 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2235 struct isl_union_print_data data
;
2236 struct isl_print_space_data space_data
= { 0 };
2239 dim
= isl_union_pw_qpolynomial_fold_get_space(upwf
);
2240 if (isl_space_dim(dim
, isl_dim_param
) > 0) {
2241 p
= print_tuple(dim
, p
, isl_dim_param
, &space_data
);
2242 p
= isl_printer_print_str(p
, " -> ");
2244 isl_space_free(dim
);
2245 p
= isl_printer_print_str(p
, "{ ");
2248 isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(upwf
,
2249 &print_pwf_body
, &data
);
2251 p
= isl_printer_print_str(p
, " }");
2255 __isl_give isl_printer
*isl_printer_print_union_pw_qpolynomial_fold(
2256 __isl_take isl_printer
*p
,
2257 __isl_keep isl_union_pw_qpolynomial_fold
*upwf
)
2262 if (p
->output_format
== ISL_FORMAT_ISL
)
2263 return print_union_pw_qpolynomial_fold_isl(p
, upwf
);
2264 isl_die(p
->ctx
, isl_error_invalid
,
2265 "invalid output format for isl_union_pw_qpolynomial_fold",
2268 isl_printer_free(p
);
2272 __isl_give isl_printer
*isl_printer_print_constraint(__isl_take isl_printer
*p
,
2273 __isl_keep isl_constraint
*c
)
2275 isl_basic_map
*bmap
;
2280 bmap
= isl_basic_map_from_constraint(isl_constraint_copy(c
));
2281 p
= isl_printer_print_basic_map(p
, bmap
);
2282 isl_basic_map_free(bmap
);
2285 isl_printer_free(p
);
2289 static __isl_give isl_printer
*isl_printer_print_space_isl(
2290 __isl_take isl_printer
*p
, __isl_keep isl_space
*space
)
2292 struct isl_print_space_data data
= { 0 };
2297 if (isl_space_dim(space
, isl_dim_param
) > 0) {
2298 p
= print_tuple(space
, p
, isl_dim_param
, &data
);
2299 p
= isl_printer_print_str(p
, " -> ");
2302 p
= isl_printer_print_str(p
, "{ ");
2303 if (isl_space_is_params(space
))
2304 p
= isl_printer_print_str(p
, s_such_that
[0]);
2306 p
= isl_print_space(space
, p
, 0, &data
);
2307 p
= isl_printer_print_str(p
, " }");
2311 isl_printer_free(p
);
2315 __isl_give isl_printer
*isl_printer_print_space(__isl_take isl_printer
*p
,
2316 __isl_keep isl_space
*space
)
2319 return isl_printer_free(p
);
2320 if (p
->output_format
== ISL_FORMAT_ISL
)
2321 return isl_printer_print_space_isl(p
, space
);
2322 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
2323 return print_omega_parameters(space
, p
);
2325 isl_die(isl_space_get_ctx(space
), isl_error_unsupported
,
2326 "output format not supported for space",
2327 return isl_printer_free(p
));
2330 __isl_give isl_printer
*isl_printer_print_local_space(__isl_take isl_printer
*p
,
2331 __isl_keep isl_local_space
*ls
)
2333 struct isl_print_space_data data
= { 0 };
2339 if (isl_local_space_dim(ls
, isl_dim_param
) > 0) {
2340 p
= print_tuple(ls
->dim
, p
, isl_dim_param
, &data
);
2341 p
= isl_printer_print_str(p
, " -> ");
2343 p
= isl_printer_print_str(p
, "{ ");
2344 p
= isl_print_space(ls
->dim
, p
, 0, &data
);
2345 n_div
= isl_local_space_dim(ls
, isl_dim_div
);
2347 p
= isl_printer_print_str(p
, " : ");
2348 p
= isl_printer_print_str(p
, s_open_exists
[0]);
2349 p
= print_div_list(p
, ls
->dim
, ls
->div
, 0, 1);
2350 p
= isl_printer_print_str(p
, s_close_exists
[0]);
2351 } else if (isl_space_is_params(ls
->dim
))
2352 p
= isl_printer_print_str(p
, s_such_that
[0]);
2353 p
= isl_printer_print_str(p
, " }");
2356 isl_printer_free(p
);
2360 static __isl_give isl_printer
*print_aff_body(__isl_take isl_printer
*p
,
2361 __isl_keep isl_aff
*aff
)
2365 if (isl_aff_is_nan(aff
))
2366 return isl_printer_print_str(p
, "NaN");
2368 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2369 p
= isl_printer_print_str(p
, "(");
2370 p
= print_affine_of_len(aff
->ls
->dim
, aff
->ls
->div
, p
,
2371 aff
->v
->el
+ 1, 1 + total
);
2372 if (isl_int_is_one(aff
->v
->el
[0]))
2373 p
= isl_printer_print_str(p
, ")");
2375 p
= isl_printer_print_str(p
, ")/");
2376 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2382 static __isl_give isl_printer
*print_aff(__isl_take isl_printer
*p
,
2383 __isl_keep isl_aff
*aff
)
2385 struct isl_print_space_data data
= { 0 };
2387 if (isl_space_is_params(aff
->ls
->dim
))
2390 p
= print_tuple(aff
->ls
->dim
, p
, isl_dim_set
, &data
);
2391 p
= isl_printer_print_str(p
, " -> ");
2393 p
= isl_printer_print_str(p
, "[");
2394 p
= print_aff_body(p
, aff
);
2395 p
= isl_printer_print_str(p
, "]");
2400 static __isl_give isl_printer
*print_aff_isl(__isl_take isl_printer
*p
,
2401 __isl_keep isl_aff
*aff
)
2403 struct isl_print_space_data data
= { 0 };
2408 if (isl_local_space_dim(aff
->ls
, isl_dim_param
) > 0) {
2409 p
= print_tuple(aff
->ls
->dim
, p
, isl_dim_param
, &data
);
2410 p
= isl_printer_print_str(p
, " -> ");
2412 p
= isl_printer_print_str(p
, "{ ");
2413 p
= print_aff(p
, aff
);
2414 p
= isl_printer_print_str(p
, " }");
2417 isl_printer_free(p
);
2421 /* Print the body of an isl_pw_aff, i.e., a semicolon delimited
2422 * sequence of affine expressions, each followed by constraints.
2424 static __isl_give isl_printer
*print_pw_aff_body(
2425 __isl_take isl_printer
*p
, __isl_keep isl_pw_aff
*pa
)
2430 return isl_printer_free(p
);
2432 for (i
= 0; i
< pa
->n
; ++i
) {
2436 p
= isl_printer_print_str(p
, "; ");
2437 p
= print_aff(p
, pa
->p
[i
].aff
);
2438 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
2439 p
= print_disjuncts(set_to_map(pa
->p
[i
].set
), space
, p
, 0);
2440 isl_space_free(space
);
2446 static __isl_give isl_printer
*print_pw_aff_isl(__isl_take isl_printer
*p
,
2447 __isl_keep isl_pw_aff
*pwaff
)
2449 struct isl_print_space_data data
= { 0 };
2454 if (isl_space_dim(pwaff
->dim
, isl_dim_param
) > 0) {
2455 p
= print_tuple(pwaff
->dim
, p
, isl_dim_param
, &data
);
2456 p
= isl_printer_print_str(p
, " -> ");
2458 p
= isl_printer_print_str(p
, "{ ");
2459 p
= print_pw_aff_body(p
, pwaff
);
2460 p
= isl_printer_print_str(p
, " }");
2463 isl_printer_free(p
);
2467 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2468 __isl_keep isl_local_space
*ls
, isl_int
*c
);
2470 static __isl_give isl_printer
*print_ls_name_c(__isl_take isl_printer
*p
,
2471 __isl_keep isl_local_space
*ls
, enum isl_dim_type type
, unsigned pos
)
2473 if (type
== isl_dim_div
) {
2474 p
= isl_printer_print_str(p
, "floord(");
2475 p
= print_ls_affine_c(p
, ls
, ls
->div
->row
[pos
] + 1);
2476 p
= isl_printer_print_str(p
, ", ");
2477 p
= isl_printer_print_isl_int(p
, ls
->div
->row
[pos
][0]);
2478 p
= isl_printer_print_str(p
, ")");
2482 name
= isl_space_get_dim_name(ls
->dim
, type
, pos
);
2485 p
= isl_printer_print_str(p
, name
);
2490 static __isl_give isl_printer
*print_ls_term_c(__isl_take isl_printer
*p
,
2491 __isl_keep isl_local_space
*ls
, isl_int c
, unsigned pos
)
2493 enum isl_dim_type type
;
2496 return isl_printer_print_isl_int(p
, c
);
2498 if (isl_int_is_one(c
))
2500 else if (isl_int_is_negone(c
))
2501 p
= isl_printer_print_str(p
, "-");
2503 p
= isl_printer_print_isl_int(p
, c
);
2504 p
= isl_printer_print_str(p
, "*");
2506 type
= pos2type(ls
->dim
, &pos
);
2507 p
= print_ls_name_c(p
, ls
, type
, pos
);
2511 static __isl_give isl_printer
*print_ls_partial_affine_c(
2512 __isl_take isl_printer
*p
, __isl_keep isl_local_space
*ls
,
2513 isl_int
*c
, unsigned len
)
2518 for (i
= 0, first
= 1; i
< len
; ++i
) {
2520 if (isl_int_is_zero(c
[i
]))
2523 if (isl_int_is_neg(c
[i
])) {
2525 isl_int_neg(c
[i
], c
[i
]);
2526 p
= isl_printer_print_str(p
, " - ");
2528 p
= isl_printer_print_str(p
, " + ");
2531 p
= print_ls_term_c(p
, ls
, c
[i
], i
);
2533 isl_int_neg(c
[i
], c
[i
]);
2536 p
= isl_printer_print_str(p
, "0");
2540 static __isl_give isl_printer
*print_ls_affine_c(__isl_take isl_printer
*p
,
2541 __isl_keep isl_local_space
*ls
, isl_int
*c
)
2543 unsigned len
= 1 + isl_local_space_dim(ls
, isl_dim_all
);
2544 return print_ls_partial_affine_c(p
, ls
, c
, len
);
2547 static __isl_give isl_printer
*print_aff_c(__isl_take isl_printer
*p
,
2548 __isl_keep isl_aff
*aff
)
2552 total
= isl_local_space_dim(aff
->ls
, isl_dim_all
);
2553 if (!isl_int_is_one(aff
->v
->el
[0]))
2554 p
= isl_printer_print_str(p
, "(");
2555 p
= print_ls_partial_affine_c(p
, aff
->ls
, aff
->v
->el
+ 1, 1 + total
);
2556 if (!isl_int_is_one(aff
->v
->el
[0])) {
2557 p
= isl_printer_print_str(p
, ")/");
2558 p
= isl_printer_print_isl_int(p
, aff
->v
->el
[0]);
2563 /* In the C format, we cannot express that "pwaff" may be undefined
2564 * on parts of the domain space. We therefore assume that the expression
2565 * will only be evaluated on its definition domain and compute the gist
2566 * of each cell with respect to this domain.
2568 static __isl_give isl_printer
*print_pw_aff_c(__isl_take isl_printer
*p
,
2569 __isl_keep isl_pw_aff
*pwaff
)
2572 isl_ast_build
*build
;
2576 isl_die(p
->ctx
, isl_error_unsupported
,
2577 "cannot print empty isl_pw_aff in C format",
2578 return isl_printer_free(p
));
2580 domain
= isl_pw_aff_domain(isl_pw_aff_copy(pwaff
));
2581 build
= isl_ast_build_from_context(domain
);
2582 expr
= isl_ast_build_expr_from_pw_aff(build
, isl_pw_aff_copy(pwaff
));
2583 p
= isl_printer_print_ast_expr(p
, expr
);
2584 isl_ast_expr_free(expr
);
2585 isl_ast_build_free(build
);
2590 __isl_give isl_printer
*isl_printer_print_aff(__isl_take isl_printer
*p
,
2591 __isl_keep isl_aff
*aff
)
2596 if (p
->output_format
== ISL_FORMAT_ISL
)
2597 return print_aff_isl(p
, aff
);
2598 else if (p
->output_format
== ISL_FORMAT_C
)
2599 return print_aff_c(p
, aff
);
2600 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2603 isl_printer_free(p
);
2607 __isl_give isl_printer
*isl_printer_print_pw_aff(__isl_take isl_printer
*p
,
2608 __isl_keep isl_pw_aff
*pwaff
)
2613 if (p
->output_format
== ISL_FORMAT_ISL
)
2614 return print_pw_aff_isl(p
, pwaff
);
2615 else if (p
->output_format
== ISL_FORMAT_C
)
2616 return print_pw_aff_c(p
, pwaff
);
2617 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2620 isl_printer_free(p
);
2624 /* Print "pa" in a sequence of isl_pw_affs delimited by semicolons.
2625 * Each isl_pw_aff itself is also printed as semicolon delimited
2626 * sequence of pieces.
2627 * If data->first = 1, then this is the first in the sequence.
2628 * Update data->first to tell the next element that it is not the first.
2630 static isl_stat
print_pw_aff_body_wrap(__isl_take isl_pw_aff
*pa
,
2633 struct isl_union_print_data
*data
;
2634 data
= (struct isl_union_print_data
*) user
;
2637 data
->p
= isl_printer_print_str(data
->p
, "; ");
2640 data
->p
= print_pw_aff_body(data
->p
, pa
);
2641 isl_pw_aff_free(pa
);
2643 return data
->p
? isl_stat_ok
: isl_stat_error
;
2646 /* Print the body of an isl_union_pw_aff, i.e., a semicolon delimited
2647 * sequence of affine expressions, each followed by constraints,
2648 * with the sequence enclosed in braces.
2650 static __isl_give isl_printer
*print_union_pw_aff_body(
2651 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2653 struct isl_union_print_data data
= { p
, 1 };
2655 p
= isl_printer_print_str(p
, s_open_set
[0]);
2657 if (isl_union_pw_aff_foreach_pw_aff(upa
,
2658 &print_pw_aff_body_wrap
, &data
) < 0)
2659 data
.p
= isl_printer_free(p
);
2661 p
= isl_printer_print_str(p
, s_close_set
[0]);
2666 /* Print the isl_union_pw_aff "upa" to "p" in isl format.
2668 * The individual isl_pw_affs are delimited by a semicolon.
2670 static __isl_give isl_printer
*print_union_pw_aff_isl(
2671 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2673 struct isl_print_space_data data
= { 0 };
2676 space
= isl_union_pw_aff_get_space(upa
);
2677 if (isl_space_dim(space
, isl_dim_param
) > 0) {
2678 p
= print_tuple(space
, p
, isl_dim_param
, &data
);
2679 p
= isl_printer_print_str(p
, s_to
[0]);
2681 isl_space_free(space
);
2682 p
= print_union_pw_aff_body(p
, upa
);
2686 /* Print the isl_union_pw_aff "upa" to "p".
2688 * We currently only support an isl format.
2690 __isl_give isl_printer
*isl_printer_print_union_pw_aff(
2691 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_aff
*upa
)
2694 return isl_printer_free(p
);
2696 if (p
->output_format
== ISL_FORMAT_ISL
)
2697 return print_union_pw_aff_isl(p
, upa
);
2698 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
2699 "unsupported output format", return isl_printer_free(p
));
2702 /* Print dimension "pos" of data->space to "p".
2704 * data->user is assumed to be an isl_multi_aff.
2706 * If the current dimension is an output dimension, then print
2707 * the corresponding expression. Otherwise, print the name of the dimension.
2709 static __isl_give isl_printer
*print_dim_ma(__isl_take isl_printer
*p
,
2710 struct isl_print_space_data
*data
, unsigned pos
)
2712 isl_multi_aff
*ma
= data
->user
;
2714 if (data
->type
== isl_dim_out
)
2715 p
= print_aff_body(p
, ma
->p
[pos
]);
2717 p
= print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2722 static __isl_give isl_printer
*print_multi_aff(__isl_take isl_printer
*p
,
2723 __isl_keep isl_multi_aff
*maff
)
2725 struct isl_print_space_data data
= { 0 };
2727 data
.print_dim
= &print_dim_ma
;
2729 return isl_print_space(maff
->space
, p
, 0, &data
);
2732 static __isl_give isl_printer
*print_multi_aff_isl(__isl_take isl_printer
*p
,
2733 __isl_keep isl_multi_aff
*maff
)
2735 struct isl_print_space_data data
= { 0 };
2740 if (isl_space_dim(maff
->space
, isl_dim_param
) > 0) {
2741 p
= print_tuple(maff
->space
, p
, isl_dim_param
, &data
);
2742 p
= isl_printer_print_str(p
, " -> ");
2744 p
= isl_printer_print_str(p
, "{ ");
2745 p
= print_multi_aff(p
, maff
);
2746 p
= isl_printer_print_str(p
, " }");
2749 isl_printer_free(p
);
2753 __isl_give isl_printer
*isl_printer_print_multi_aff(__isl_take isl_printer
*p
,
2754 __isl_keep isl_multi_aff
*maff
)
2759 if (p
->output_format
== ISL_FORMAT_ISL
)
2760 return print_multi_aff_isl(p
, maff
);
2761 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2764 isl_printer_free(p
);
2768 static __isl_give isl_printer
*print_pw_multi_aff_body(
2769 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2776 for (i
= 0; i
< pma
->n
; ++i
) {
2780 p
= isl_printer_print_str(p
, "; ");
2781 p
= print_multi_aff(p
, pma
->p
[i
].maff
);
2782 space
= isl_multi_aff_get_domain_space(pma
->p
[i
].maff
);
2783 p
= print_disjuncts(set_to_map(pma
->p
[i
].set
), space
, p
, 0);
2784 isl_space_free(space
);
2788 isl_printer_free(p
);
2792 static __isl_give isl_printer
*print_pw_multi_aff_isl(__isl_take isl_printer
*p
,
2793 __isl_keep isl_pw_multi_aff
*pma
)
2795 struct isl_print_space_data data
= { 0 };
2800 if (isl_space_dim(pma
->dim
, isl_dim_param
) > 0) {
2801 p
= print_tuple(pma
->dim
, p
, isl_dim_param
, &data
);
2802 p
= isl_printer_print_str(p
, " -> ");
2804 p
= isl_printer_print_str(p
, "{ ");
2805 p
= print_pw_multi_aff_body(p
, pma
);
2806 p
= isl_printer_print_str(p
, " }");
2809 isl_printer_free(p
);
2813 /* Print the unnamed, single-dimensional piecewise multi affine expression "pma"
2816 static __isl_give isl_printer
*print_unnamed_pw_multi_aff_c(
2817 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2822 space
= isl_pw_multi_aff_get_domain_space(pma
);
2823 for (i
= 0; i
< pma
->n
- 1; ++i
) {
2824 p
= isl_printer_print_str(p
, "(");
2825 p
= print_set_c(p
, space
, pma
->p
[i
].set
);
2826 p
= isl_printer_print_str(p
, ") ? (");
2827 p
= print_aff_c(p
, pma
->p
[i
].maff
->p
[0]);
2828 p
= isl_printer_print_str(p
, ") : ");
2830 isl_space_free(space
);
2832 return print_aff_c(p
, pma
->p
[pma
->n
- 1].maff
->p
[0]);
2835 static __isl_give isl_printer
*print_pw_multi_aff_c(__isl_take isl_printer
*p
,
2836 __isl_keep isl_pw_multi_aff
*pma
)
2844 isl_die(p
->ctx
, isl_error_unsupported
,
2845 "cannot print empty isl_pw_multi_aff in C format",
2847 name
= isl_pw_multi_aff_get_tuple_name(pma
, isl_dim_out
);
2848 if (!name
&& isl_pw_multi_aff_dim(pma
, isl_dim_out
) == 1)
2849 return print_unnamed_pw_multi_aff_c(p
, pma
);
2851 isl_die(p
->ctx
, isl_error_unsupported
,
2852 "cannot print unnamed isl_pw_multi_aff in C format",
2855 p
= isl_printer_print_str(p
, name
);
2856 n
= isl_pw_multi_aff_dim(pma
, isl_dim_out
);
2858 isl_die(p
->ctx
, isl_error_unsupported
,
2859 "not supported yet", goto error
);
2863 isl_printer_free(p
);
2867 __isl_give isl_printer
*isl_printer_print_pw_multi_aff(
2868 __isl_take isl_printer
*p
, __isl_keep isl_pw_multi_aff
*pma
)
2873 if (p
->output_format
== ISL_FORMAT_ISL
)
2874 return print_pw_multi_aff_isl(p
, pma
);
2875 if (p
->output_format
== ISL_FORMAT_C
)
2876 return print_pw_multi_aff_c(p
, pma
);
2877 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2880 isl_printer_free(p
);
2884 static isl_stat
print_pw_multi_aff_body_wrap(__isl_take isl_pw_multi_aff
*pma
,
2887 struct isl_union_print_data
*data
;
2888 data
= (struct isl_union_print_data
*) user
;
2891 data
->p
= isl_printer_print_str(data
->p
, "; ");
2894 data
->p
= print_pw_multi_aff_body(data
->p
, pma
);
2895 isl_pw_multi_aff_free(pma
);
2900 static __isl_give isl_printer
*print_union_pw_multi_aff_isl(
2901 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
2903 struct isl_union_print_data data
;
2904 struct isl_print_space_data space_data
= { 0 };
2907 space
= isl_union_pw_multi_aff_get_space(upma
);
2908 if (isl_space_dim(space
, isl_dim_param
) > 0) {
2909 p
= print_tuple(space
, p
, isl_dim_param
, &space_data
);
2910 p
= isl_printer_print_str(p
, s_to
[0]);
2912 isl_space_free(space
);
2913 p
= isl_printer_print_str(p
, s_open_set
[0]);
2916 isl_union_pw_multi_aff_foreach_pw_multi_aff(upma
,
2917 &print_pw_multi_aff_body_wrap
, &data
);
2919 p
= isl_printer_print_str(p
, s_close_set
[0]);
2923 __isl_give isl_printer
*isl_printer_print_union_pw_multi_aff(
2924 __isl_take isl_printer
*p
, __isl_keep isl_union_pw_multi_aff
*upma
)
2929 if (p
->output_format
== ISL_FORMAT_ISL
)
2930 return print_union_pw_multi_aff_isl(p
, upma
);
2931 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
2934 isl_printer_free(p
);
2938 /* Print dimension "pos" of data->space to "p".
2940 * data->user is assumed to be an isl_multi_pw_aff.
2942 * If the current dimension is an output dimension, then print
2943 * the corresponding piecewise affine expression.
2944 * Otherwise, print the name of the dimension.
2946 static __isl_give isl_printer
*print_dim_mpa(__isl_take isl_printer
*p
,
2947 struct isl_print_space_data
*data
, unsigned pos
)
2951 isl_multi_pw_aff
*mpa
= data
->user
;
2954 if (data
->type
!= isl_dim_out
)
2955 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
2959 return isl_printer_print_str(p
, "(0 : 1 = 0)");
2961 need_parens
= pa
->n
!= 1 || !isl_set_plain_is_universe(pa
->p
[0].set
);
2963 p
= isl_printer_print_str(p
, "(");
2964 for (i
= 0; i
< pa
->n
; ++i
) {
2968 p
= isl_printer_print_str(p
, "; ");
2969 p
= print_aff_body(p
, pa
->p
[i
].aff
);
2970 space
= isl_aff_get_domain_space(pa
->p
[i
].aff
);
2971 p
= print_disjuncts(pa
->p
[i
].set
, space
, p
, 0);
2972 isl_space_free(space
);
2975 p
= isl_printer_print_str(p
, ")");
2980 /* Print "mpa" to "p" in isl format.
2982 static __isl_give isl_printer
*print_multi_pw_aff_isl(__isl_take isl_printer
*p
,
2983 __isl_keep isl_multi_pw_aff
*mpa
)
2985 struct isl_print_space_data data
= { 0 };
2988 return isl_printer_free(p
);
2990 if (isl_space_dim(mpa
->space
, isl_dim_param
) > 0) {
2991 p
= print_tuple(mpa
->space
, p
, isl_dim_param
, &data
);
2992 p
= isl_printer_print_str(p
, " -> ");
2994 p
= isl_printer_print_str(p
, "{ ");
2995 data
.print_dim
= &print_dim_mpa
;
2997 p
= isl_print_space(mpa
->space
, p
, 0, &data
);
2998 p
= isl_printer_print_str(p
, " }");
3002 __isl_give isl_printer
*isl_printer_print_multi_pw_aff(
3003 __isl_take isl_printer
*p
, __isl_keep isl_multi_pw_aff
*mpa
)
3006 return isl_printer_free(p
);
3008 if (p
->output_format
== ISL_FORMAT_ISL
)
3009 return print_multi_pw_aff_isl(p
, mpa
);
3010 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3011 return isl_printer_free(p
));
3014 /* Print dimension "pos" of data->space to "p".
3016 * data->user is assumed to be an isl_multi_val.
3018 * If the current dimension is an output dimension, then print
3019 * the corresponding value. Otherwise, print the name of the dimension.
3021 static __isl_give isl_printer
*print_dim_mv(__isl_take isl_printer
*p
,
3022 struct isl_print_space_data
*data
, unsigned pos
)
3024 isl_multi_val
*mv
= data
->user
;
3026 if (data
->type
== isl_dim_out
)
3027 return isl_printer_print_val(p
, mv
->p
[pos
]);
3029 return print_name(data
->space
, p
, data
->type
, pos
, data
->latex
);
3032 /* Print the isl_multi_val "mv" to "p" in isl format.
3034 static __isl_give isl_printer
*print_multi_val_isl(__isl_take isl_printer
*p
,
3035 __isl_keep isl_multi_val
*mv
)
3037 struct isl_print_space_data data
= { 0 };
3040 return isl_printer_free(p
);
3042 if (isl_space_dim(mv
->space
, isl_dim_param
) > 0) {
3043 p
= print_tuple(mv
->space
, p
, isl_dim_param
, &data
);
3044 p
= isl_printer_print_str(p
, " -> ");
3046 p
= isl_printer_print_str(p
, "{ ");
3047 data
.print_dim
= &print_dim_mv
;
3049 p
= isl_print_space(mv
->space
, p
, 0, &data
);
3050 p
= isl_printer_print_str(p
, " }");
3054 /* Print the isl_multi_val "mv" to "p".
3056 * Currently only supported in isl format.
3058 __isl_give isl_printer
*isl_printer_print_multi_val(
3059 __isl_take isl_printer
*p
, __isl_keep isl_multi_val
*mv
)
3062 return isl_printer_free(p
);
3064 if (p
->output_format
== ISL_FORMAT_ISL
)
3065 return print_multi_val_isl(p
, mv
);
3066 isl_die(p
->ctx
, isl_error_unsupported
, "unsupported output format",
3067 return isl_printer_free(p
));
3070 /* Print dimension "pos" of data->space to "p".
3072 * data->user is assumed to be an isl_multi_union_pw_aff.
3074 * The current dimension is necessarily a set dimension, so
3075 * we print the corresponding isl_union_pw_aff, including
3078 static __isl_give isl_printer
*print_union_pw_aff_dim(__isl_take isl_printer
*p
,
3079 struct isl_print_space_data
*data
, unsigned pos
)
3081 isl_multi_union_pw_aff
*mupa
= data
->user
;
3082 isl_union_pw_aff
*upa
;
3084 upa
= isl_multi_union_pw_aff_get_union_pw_aff(mupa
, pos
);
3085 p
= print_union_pw_aff_body(p
, upa
);
3086 isl_union_pw_aff_free(upa
);
3091 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3093 static __isl_give isl_printer
*print_multi_union_pw_aff_isl(
3094 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3096 struct isl_print_space_data data
= { 0 };
3099 space
= isl_multi_union_pw_aff_get_space(mupa
);
3100 if (isl_space_dim(space
, isl_dim_param
) > 0) {
3101 struct isl_print_space_data space_data
= { 0 };
3102 p
= print_tuple(space
, p
, isl_dim_param
, &space_data
);
3103 p
= isl_printer_print_str(p
, s_to
[0]);
3106 data
.print_dim
= &print_union_pw_aff_dim
;
3109 p
= isl_print_space(space
, p
, 0, &data
);
3110 isl_space_free(space
);
3115 /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format.
3117 * We currently only support an isl format.
3119 __isl_give isl_printer
*isl_printer_print_multi_union_pw_aff(
3120 __isl_take isl_printer
*p
, __isl_keep isl_multi_union_pw_aff
*mupa
)
3123 return isl_printer_free(p
);
3125 if (p
->output_format
== ISL_FORMAT_ISL
)
3126 return print_multi_union_pw_aff_isl(p
, mupa
);
3127 isl_die(isl_printer_get_ctx(p
), isl_error_unsupported
,
3128 "unsupported output format", return isl_printer_free(p
));