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
18 #include <isl_ctx_private.h>
19 #include <isl_map_private.h>
20 #include <isl_id_private.h>
23 #include <isl_stream_private.h>
25 #include "isl_polynomial_private.h"
26 #include <isl/union_set.h>
27 #include <isl/union_map.h>
28 #include <isl_mat_private.h>
29 #include <isl_aff_private.h>
30 #include <isl_vec_private.h>
32 #include <isl_val_private.h>
37 struct variable
*next
;
46 static struct vars
*vars_new(struct isl_ctx
*ctx
)
49 v
= isl_alloc_type(ctx
, struct vars
);
58 static void variable_free(struct variable
*var
)
61 struct variable
*next
= var
->next
;
68 static void vars_free(struct vars
*v
)
76 static void vars_drop(struct vars
*v
, int n
)
87 struct variable
*next
= var
->next
;
95 static struct variable
*variable_new(struct vars
*v
, const char *name
, int len
,
99 var
= isl_calloc_type(v
->ctx
, struct variable
);
102 var
->name
= strdup(name
);
103 var
->name
[len
] = '\0';
112 static int vars_pos(struct vars
*v
, const char *s
, int len
)
119 for (q
= v
->v
; q
; q
= q
->next
) {
120 if (strncmp(q
->name
, s
, len
) == 0 && q
->name
[len
] == '\0')
127 v
->v
= variable_new(v
, s
, len
, v
->n
);
135 static int vars_add_anon(struct vars
*v
)
137 v
->v
= variable_new(v
, "", 0, v
->n
);
146 /* Obtain next token, with some preprocessing.
147 * In particular, evaluate expressions of the form x^y,
148 * with x and y values.
150 static struct isl_token
*next_token(__isl_keep isl_stream
*s
)
152 struct isl_token
*tok
, *tok2
;
154 tok
= isl_stream_next_token(s
);
155 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
)
157 if (!isl_stream_eat_if_available(s
, '^'))
159 tok2
= isl_stream_next_token(s
);
160 if (!tok2
|| tok2
->type
!= ISL_TOKEN_VALUE
) {
161 isl_stream_error(s
, tok2
, "expecting constant value");
165 isl_int_pow_ui(tok
->u
.v
, tok
->u
.v
, isl_int_get_ui(tok2
->u
.v
));
167 isl_token_free(tok2
);
171 isl_token_free(tok2
);
175 /* Read an isl_val from "s".
177 * The following token sequences are recognized
180 * "-" "infty" -> -infty
185 * where n, d and v are integer constants.
187 __isl_give isl_val
*isl_stream_read_val(__isl_keep isl_stream
*s
)
189 struct isl_token
*tok
= NULL
;
190 struct isl_token
*tok2
= NULL
;
195 isl_stream_error(s
, NULL
, "unexpected EOF");
198 if (tok
->type
== ISL_TOKEN_INFTY
) {
200 return isl_val_infty(s
->ctx
);
202 if (tok
->type
== '-' &&
203 isl_stream_eat_if_available(s
, ISL_TOKEN_INFTY
)) {
205 return isl_val_neginfty(s
->ctx
);
207 if (tok
->type
== ISL_TOKEN_NAN
) {
209 return isl_val_nan(s
->ctx
);
211 if (tok
->type
!= ISL_TOKEN_VALUE
) {
212 isl_stream_error(s
, tok
, "expecting value");
216 if (isl_stream_eat_if_available(s
, '/')) {
217 tok2
= next_token(s
);
219 isl_stream_error(s
, NULL
, "unexpected EOF");
222 if (tok2
->type
!= ISL_TOKEN_VALUE
) {
223 isl_stream_error(s
, tok2
, "expecting value");
226 val
= isl_val_rat_from_isl_int(s
->ctx
, tok
->u
.v
, tok2
->u
.v
);
227 val
= isl_val_normalize(val
);
229 val
= isl_val_int_from_isl_int(s
->ctx
, tok
->u
.v
);
233 isl_token_free(tok2
);
237 isl_token_free(tok2
);
241 /* Read an isl_val from "str".
243 struct isl_val
*isl_val_read_from_str(struct isl_ctx
*ctx
,
247 isl_stream
*s
= isl_stream_new_str(ctx
, str
);
250 val
= isl_stream_read_val(s
);
255 static int accept_cst_factor(__isl_keep isl_stream
*s
, isl_int
*f
)
257 struct isl_token
*tok
;
260 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
261 isl_stream_error(s
, tok
, "expecting constant value");
265 isl_int_mul(*f
, *f
, tok
->u
.v
);
269 if (isl_stream_eat_if_available(s
, '*'))
270 return accept_cst_factor(s
, f
);
278 /* Given an affine expression aff, return an affine expression
279 * for aff % d, with d the next token on the stream, which is
280 * assumed to be a constant.
282 * We introduce an integer division q = [aff/d] and the result
283 * is set to aff - d q.
285 static __isl_give isl_pw_aff
*affine_mod(__isl_keep isl_stream
*s
,
286 struct vars
*v
, __isl_take isl_pw_aff
*aff
)
288 struct isl_token
*tok
;
292 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
293 isl_stream_error(s
, tok
, "expecting constant value");
297 q
= isl_pw_aff_copy(aff
);
298 q
= isl_pw_aff_scale_down(q
, tok
->u
.v
);
299 q
= isl_pw_aff_floor(q
);
300 q
= isl_pw_aff_scale(q
, tok
->u
.v
);
302 aff
= isl_pw_aff_sub(aff
, q
);
307 isl_pw_aff_free(aff
);
312 static __isl_give isl_pw_aff
*accept_affine(__isl_keep isl_stream
*s
,
313 __isl_take isl_space
*space
, struct vars
*v
);
314 static __isl_give isl_pw_aff_list
*accept_affine_list(__isl_keep isl_stream
*s
,
315 __isl_take isl_space
*dim
, struct vars
*v
);
317 static __isl_give isl_pw_aff
*accept_minmax(__isl_keep isl_stream
*s
,
318 __isl_take isl_space
*dim
, struct vars
*v
)
320 struct isl_token
*tok
;
321 isl_pw_aff_list
*list
= NULL
;
324 tok
= isl_stream_next_token(s
);
327 min
= tok
->type
== ISL_TOKEN_MIN
;
330 if (isl_stream_eat(s
, '('))
333 list
= accept_affine_list(s
, isl_space_copy(dim
), v
);
337 if (isl_stream_eat(s
, ')'))
341 return min
? isl_pw_aff_list_min(list
) : isl_pw_aff_list_max(list
);
344 isl_pw_aff_list_free(list
);
348 /* Is "tok" the start of an integer division?
350 static int is_start_of_div(struct isl_token
*tok
)
354 if (tok
->type
== '[')
356 if (tok
->type
== ISL_TOKEN_FLOOR
)
358 if (tok
->type
== ISL_TOKEN_CEIL
)
360 if (tok
->type
== ISL_TOKEN_FLOORD
)
362 if (tok
->type
== ISL_TOKEN_CEILD
)
367 /* Read an integer division from "s" and return it as an isl_pw_aff.
369 * The integer division can be of the form
371 * [<affine expression>]
372 * floor(<affine expression>)
373 * ceil(<affine expression>)
374 * floord(<affine expression>,<denominator>)
375 * ceild(<affine expression>,<denominator>)
377 static __isl_give isl_pw_aff
*accept_div(__isl_keep isl_stream
*s
,
378 __isl_take isl_space
*dim
, struct vars
*v
)
380 struct isl_token
*tok
;
384 isl_pw_aff
*pwaff
= NULL
;
386 if (isl_stream_eat_if_available(s
, ISL_TOKEN_FLOORD
))
388 else if (isl_stream_eat_if_available(s
, ISL_TOKEN_CEILD
))
390 else if (isl_stream_eat_if_available(s
, ISL_TOKEN_FLOOR
))
392 else if (isl_stream_eat_if_available(s
, ISL_TOKEN_CEIL
))
395 if (isl_stream_eat(s
, '('))
398 if (isl_stream_eat(s
, '['))
402 pwaff
= accept_affine(s
, isl_space_copy(dim
), v
);
405 if (isl_stream_eat(s
, ','))
411 if (tok
->type
!= ISL_TOKEN_VALUE
) {
412 isl_stream_error(s
, tok
, "expected denominator");
413 isl_stream_push_token(s
, tok
);
416 pwaff
= isl_pw_aff_scale_down(pwaff
, tok
->u
.v
);
421 pwaff
= isl_pw_aff_ceil(pwaff
);
423 pwaff
= isl_pw_aff_floor(pwaff
);
426 if (isl_stream_eat(s
, ')'))
429 if (isl_stream_eat(s
, ']'))
437 isl_pw_aff_free(pwaff
);
441 static __isl_give isl_pw_aff
*accept_affine_factor(__isl_keep isl_stream
*s
,
442 __isl_take isl_space
*dim
, struct vars
*v
)
444 struct isl_token
*tok
= NULL
;
445 isl_pw_aff
*res
= NULL
;
449 isl_stream_error(s
, NULL
, "unexpected EOF");
453 if (tok
->type
== ISL_TOKEN_AFF
) {
454 res
= isl_pw_aff_copy(tok
->u
.pwaff
);
456 } else if (tok
->type
== ISL_TOKEN_IDENT
) {
458 int pos
= vars_pos(v
, tok
->u
.s
, -1);
464 vars_drop(v
, v
->n
- n
);
465 isl_stream_error(s
, tok
, "unknown identifier");
469 aff
= isl_aff_zero_on_domain(isl_local_space_from_space(isl_space_copy(dim
)));
472 isl_int_set_si(aff
->v
->el
[2 + pos
], 1);
473 res
= isl_pw_aff_from_aff(aff
);
475 } else if (tok
->type
== ISL_TOKEN_VALUE
) {
476 if (isl_stream_eat_if_available(s
, '*')) {
477 res
= accept_affine_factor(s
, isl_space_copy(dim
), v
);
478 res
= isl_pw_aff_scale(res
, tok
->u
.v
);
482 ls
= isl_local_space_from_space(isl_space_copy(dim
));
483 aff
= isl_aff_zero_on_domain(ls
);
484 aff
= isl_aff_add_constant(aff
, tok
->u
.v
);
485 res
= isl_pw_aff_from_aff(aff
);
488 } else if (tok
->type
== '(') {
491 res
= accept_affine(s
, isl_space_copy(dim
), v
);
494 if (isl_stream_eat(s
, ')'))
496 } else if (is_start_of_div(tok
)) {
497 isl_stream_push_token(s
, tok
);
499 res
= accept_div(s
, isl_space_copy(dim
), v
);
500 } else if (tok
->type
== ISL_TOKEN_MIN
|| tok
->type
== ISL_TOKEN_MAX
) {
501 isl_stream_push_token(s
, tok
);
503 res
= accept_minmax(s
, isl_space_copy(dim
), v
);
505 isl_stream_error(s
, tok
, "expecting factor");
508 if (isl_stream_eat_if_available(s
, '%') ||
509 isl_stream_eat_if_available(s
, ISL_TOKEN_MOD
)) {
511 return affine_mod(s
, v
, res
);
513 if (isl_stream_eat_if_available(s
, '*')) {
516 isl_int_set_si(f
, 1);
517 if (accept_cst_factor(s
, &f
) < 0) {
521 res
= isl_pw_aff_scale(res
, f
);
524 if (isl_stream_eat_if_available(s
, '/')) {
527 isl_int_set_si(f
, 1);
528 if (accept_cst_factor(s
, &f
) < 0) {
532 res
= isl_pw_aff_scale_down(res
, f
);
541 isl_pw_aff_free(res
);
546 static __isl_give isl_pw_aff
*add_cst(__isl_take isl_pw_aff
*pwaff
, isl_int v
)
551 space
= isl_pw_aff_get_domain_space(pwaff
);
552 aff
= isl_aff_zero_on_domain(isl_local_space_from_space(space
));
553 aff
= isl_aff_add_constant(aff
, v
);
555 return isl_pw_aff_add(pwaff
, isl_pw_aff_from_aff(aff
));
558 /* Return a piecewise affine expression defined on the specified domain
559 * that represents NaN.
561 static __isl_give isl_pw_aff
*nan_on_domain(__isl_keep isl_space
*space
)
565 ls
= isl_local_space_from_space(isl_space_copy(space
));
566 return isl_pw_aff_nan_on_domain(ls
);
569 static __isl_give isl_pw_aff
*accept_affine(__isl_keep isl_stream
*s
,
570 __isl_take isl_space
*space
, struct vars
*v
)
572 struct isl_token
*tok
= NULL
;
577 ls
= isl_local_space_from_space(isl_space_copy(space
));
578 res
= isl_pw_aff_from_aff(isl_aff_zero_on_domain(ls
));
585 isl_stream_error(s
, NULL
, "unexpected EOF");
588 if (tok
->type
== '-') {
593 if (tok
->type
== '(' || is_start_of_div(tok
) ||
594 tok
->type
== ISL_TOKEN_MIN
|| tok
->type
== ISL_TOKEN_MAX
||
595 tok
->type
== ISL_TOKEN_IDENT
||
596 tok
->type
== ISL_TOKEN_AFF
) {
598 isl_stream_push_token(s
, tok
);
600 term
= accept_affine_factor(s
,
601 isl_space_copy(space
), v
);
603 res
= isl_pw_aff_sub(res
, term
);
605 res
= isl_pw_aff_add(res
, term
);
609 } else if (tok
->type
== ISL_TOKEN_VALUE
) {
611 isl_int_neg(tok
->u
.v
, tok
->u
.v
);
612 if (isl_stream_eat_if_available(s
, '*') ||
613 isl_stream_next_token_is(s
, ISL_TOKEN_IDENT
)) {
615 term
= accept_affine_factor(s
,
616 isl_space_copy(space
), v
);
617 term
= isl_pw_aff_scale(term
, tok
->u
.v
);
618 res
= isl_pw_aff_add(res
, term
);
622 res
= add_cst(res
, tok
->u
.v
);
625 } else if (tok
->type
== ISL_TOKEN_NAN
) {
626 res
= isl_pw_aff_add(res
, nan_on_domain(space
));
628 isl_stream_error(s
, tok
, "unexpected isl_token");
629 isl_stream_push_token(s
, tok
);
630 isl_pw_aff_free(res
);
631 isl_space_free(space
);
637 if (tok
&& tok
->type
== '-') {
640 } else if (tok
&& tok
->type
== '+') {
643 } else if (tok
&& tok
->type
== ISL_TOKEN_VALUE
&&
644 isl_int_is_neg(tok
->u
.v
)) {
645 isl_stream_push_token(s
, tok
);
648 isl_stream_push_token(s
, tok
);
653 isl_space_free(space
);
656 isl_space_free(space
);
658 isl_pw_aff_free(res
);
662 /* Is "type" the type of a comparison operator between lists
663 * of affine expressions?
665 static int is_list_comparator_type(int type
)
668 case ISL_TOKEN_LEX_LT
:
669 case ISL_TOKEN_LEX_GT
:
670 case ISL_TOKEN_LEX_LE
:
671 case ISL_TOKEN_LEX_GE
:
678 static int is_comparator(struct isl_token
*tok
)
682 if (is_list_comparator_type(tok
->type
))
698 static __isl_give isl_map
*read_formula(__isl_keep isl_stream
*s
,
699 struct vars
*v
, __isl_take isl_map
*map
, int rational
);
700 static __isl_give isl_pw_aff
*accept_extended_affine(__isl_keep isl_stream
*s
,
701 __isl_take isl_space
*dim
, struct vars
*v
, int rational
);
703 /* Accept a ternary operator, given the first argument.
705 static __isl_give isl_pw_aff
*accept_ternary(__isl_keep isl_stream
*s
,
706 __isl_take isl_map
*cond
, struct vars
*v
, int rational
)
709 isl_pw_aff
*pwaff1
= NULL
, *pwaff2
= NULL
, *pa_cond
;
714 if (isl_stream_eat(s
, '?'))
717 dim
= isl_space_wrap(isl_map_get_space(cond
));
718 pwaff1
= accept_extended_affine(s
, dim
, v
, rational
);
722 if (isl_stream_eat(s
, ':'))
725 dim
= isl_pw_aff_get_domain_space(pwaff1
);
726 pwaff2
= accept_extended_affine(s
, dim
, v
, rational
);
730 pa_cond
= isl_set_indicator_function(isl_map_wrap(cond
));
731 return isl_pw_aff_cond(pa_cond
, pwaff1
, pwaff2
);
734 isl_pw_aff_free(pwaff1
);
735 isl_pw_aff_free(pwaff2
);
739 /* Set *line and *col to those of the next token, if any.
741 static void set_current_line_col(__isl_keep isl_stream
*s
, int *line
, int *col
)
743 struct isl_token
*tok
;
745 tok
= isl_stream_next_token(s
);
751 isl_stream_push_token(s
, tok
);
754 /* Push a token encapsulating "pa" onto "s", with the given
757 static int push_aff(__isl_keep isl_stream
*s
, int line
, int col
,
758 __isl_take isl_pw_aff
*pa
)
760 struct isl_token
*tok
;
762 tok
= isl_token_new(s
->ctx
, line
, col
, 0);
765 tok
->type
= ISL_TOKEN_AFF
;
767 isl_stream_push_token(s
, tok
);
775 /* Accept an affine expression that may involve ternary operators.
776 * We first read an affine expression.
777 * If it is not followed by a comparison operator, we simply return it.
778 * Otherwise, we assume the affine expression is part of the first
779 * argument of a ternary operator and try to parse that.
781 static __isl_give isl_pw_aff
*accept_extended_affine(__isl_keep isl_stream
*s
,
782 __isl_take isl_space
*dim
, struct vars
*v
, int rational
)
787 struct isl_token
*tok
;
788 int line
= -1, col
= -1;
791 set_current_line_col(s
, &line
, &col
);
793 pwaff
= accept_affine(s
, dim
, v
);
795 pwaff
= isl_pw_aff_set_rational(pwaff
);
799 tok
= isl_stream_next_token(s
);
801 return isl_pw_aff_free(pwaff
);
803 is_comp
= is_comparator(tok
);
804 isl_stream_push_token(s
, tok
);
808 space
= isl_pw_aff_get_domain_space(pwaff
);
809 cond
= isl_map_universe(isl_space_unwrap(space
));
811 if (push_aff(s
, line
, col
, pwaff
) < 0)
812 cond
= isl_map_free(cond
);
816 cond
= read_formula(s
, v
, cond
, rational
);
818 return accept_ternary(s
, cond
, v
, rational
);
821 static __isl_give isl_map
*read_var_def(__isl_keep isl_stream
*s
,
822 __isl_take isl_map
*map
, enum isl_dim_type type
, struct vars
*v
,
829 if (type
== isl_dim_param
)
830 pos
= isl_map_dim(map
, isl_dim_param
);
832 pos
= isl_map_dim(map
, isl_dim_in
);
833 if (type
== isl_dim_out
) {
834 isl_size n_out
= isl_map_dim(map
, isl_dim_out
);
835 if (pos
< 0 || n_out
< 0)
836 return isl_map_free(map
);
842 return isl_map_free(map
);
845 def
= accept_extended_affine(s
, isl_space_wrap(isl_map_get_space(map
)),
847 def_map
= isl_map_from_pw_aff(def
);
848 def_map
= isl_map_equate(def_map
, type
, pos
, isl_dim_out
, 0);
849 def_map
= isl_set_unwrap(isl_map_domain(def_map
));
851 map
= isl_map_intersect(map
, def_map
);
856 static __isl_give isl_pw_aff_list
*accept_affine_list(__isl_keep isl_stream
*s
,
857 __isl_take isl_space
*dim
, struct vars
*v
)
860 isl_pw_aff_list
*list
;
861 struct isl_token
*tok
= NULL
;
863 pwaff
= accept_affine(s
, isl_space_copy(dim
), v
);
864 list
= isl_pw_aff_list_from_pw_aff(pwaff
);
869 tok
= isl_stream_next_token(s
);
871 isl_stream_error(s
, NULL
, "unexpected EOF");
874 if (tok
->type
!= ',') {
875 isl_stream_push_token(s
, tok
);
880 pwaff
= accept_affine(s
, isl_space_copy(dim
), v
);
881 list
= isl_pw_aff_list_concat(list
,
882 isl_pw_aff_list_from_pw_aff(pwaff
));
891 isl_pw_aff_list_free(list
);
895 static __isl_give isl_map
*read_defined_var_list(__isl_keep isl_stream
*s
,
896 struct vars
*v
, __isl_take isl_map
*map
, int rational
)
898 struct isl_token
*tok
;
900 while ((tok
= isl_stream_next_token(s
)) != NULL
) {
904 if (tok
->type
!= ISL_TOKEN_IDENT
)
907 p
= vars_pos(v
, tok
->u
.s
, -1);
911 isl_stream_error(s
, tok
, "expecting unique identifier");
915 map
= isl_map_add_dims(map
, isl_dim_out
, 1);
918 tok
= isl_stream_next_token(s
);
919 if (tok
&& tok
->type
== '=') {
921 map
= read_var_def(s
, map
, isl_dim_out
, v
, rational
);
922 tok
= isl_stream_next_token(s
);
925 if (!tok
|| tok
->type
!= ',')
931 isl_stream_push_token(s
, tok
);
940 static int next_is_tuple(__isl_keep isl_stream
*s
)
942 struct isl_token
*tok
;
945 tok
= isl_stream_next_token(s
);
948 if (tok
->type
== '[') {
949 isl_stream_push_token(s
, tok
);
952 if (tok
->type
!= ISL_TOKEN_IDENT
&& !tok
->is_keyword
) {
953 isl_stream_push_token(s
, tok
);
957 is_tuple
= isl_stream_next_token_is(s
, '[');
959 isl_stream_push_token(s
, tok
);
964 /* Is "pa" an expression in term of earlier dimensions?
965 * The alternative is that the dimension is defined to be equal to itself,
966 * meaning that it has a universe domain and an expression that depends
967 * on itself. "i" is the position of the expression in a sequence
968 * of "n" expressions. The final dimensions of "pa" correspond to
969 * these "n" expressions.
971 static isl_bool
pw_aff_is_expr(__isl_keep isl_pw_aff
*pa
, int i
, int n
)
976 return isl_bool_error
;
978 return isl_bool_true
;
979 if (!isl_set_plain_is_universe(pa
->p
[0].set
))
980 return isl_bool_true
;
983 if (isl_int_is_zero(aff
->v
->el
[aff
->v
->size
- n
+ i
]))
984 return isl_bool_true
;
985 return isl_bool_false
;
988 /* Does the tuple contain any dimensions that are defined
989 * in terms of earlier dimensions?
991 static isl_bool
tuple_has_expr(__isl_keep isl_multi_pw_aff
*tuple
)
995 isl_bool has_expr
= isl_bool_false
;
998 n
= isl_multi_pw_aff_dim(tuple
, isl_dim_out
);
1000 return isl_bool_error
;
1001 for (i
= 0; i
< n
; ++i
) {
1002 pa
= isl_multi_pw_aff_get_pw_aff(tuple
, i
);
1003 has_expr
= pw_aff_is_expr(pa
, i
, n
);
1004 isl_pw_aff_free(pa
);
1005 if (has_expr
< 0 || has_expr
)
1012 /* Set the name of dimension "pos" in "space" to "name".
1013 * During printing, we add primes if the same name appears more than once
1014 * to distinguish the occurrences. Here, we remove those primes from "name"
1015 * before setting the name of the dimension.
1017 static __isl_give isl_space
*space_set_dim_name(__isl_take isl_space
*space
,
1018 int pos
, char *name
)
1025 prime
= strchr(name
, '\'');
1028 space
= isl_space_set_dim_name(space
, isl_dim_out
, pos
, name
);
1035 /* Accept a piecewise affine expression.
1037 * At the outer level, the piecewise affine expression may be of the form
1039 * aff1 : condition1; aff2 : conditions2; ...
1045 * each of the affine expressions may in turn include ternary operators.
1047 * There may be parentheses around some subexpression of "aff1"
1048 * around "aff1" itself, around "aff1 : condition1" and/or
1049 * around the entire piecewise affine expression.
1050 * We therefore remove the opening parenthesis (if any) from the stream
1051 * in case the closing parenthesis follows the colon, but if the closing
1052 * parenthesis is the first thing in the stream after the parsed affine
1053 * expression, we push the parsed expression onto the stream and parse
1054 * again in case the parentheses enclose some subexpression of "aff1".
1056 static __isl_give isl_pw_aff
*accept_piecewise_affine(__isl_keep isl_stream
*s
,
1057 __isl_take isl_space
*space
, struct vars
*v
, int rational
)
1060 isl_space
*res_space
;
1062 res_space
= isl_space_from_domain(isl_space_copy(space
));
1063 res_space
= isl_space_add_dims(res_space
, isl_dim_out
, 1);
1064 res
= isl_pw_aff_empty(res_space
);
1068 int line
= -1, col
= -1;
1070 set_current_line_col(s
, &line
, &col
);
1071 seen_paren
= isl_stream_eat_if_available(s
, '(');
1073 pa
= accept_piecewise_affine(s
, isl_space_copy(space
),
1076 pa
= accept_extended_affine(s
, isl_space_copy(space
),
1078 if (seen_paren
&& isl_stream_eat_if_available(s
, ')')) {
1080 if (push_aff(s
, line
, col
, pa
) < 0)
1082 pa
= accept_extended_affine(s
, isl_space_copy(space
),
1085 if (isl_stream_eat_if_available(s
, ':')) {
1086 isl_space
*dom_space
;
1089 dom_space
= isl_pw_aff_get_domain_space(pa
);
1090 dom
= isl_set_universe(dom_space
);
1091 dom
= read_formula(s
, v
, dom
, rational
);
1092 pa
= isl_pw_aff_intersect_domain(pa
, dom
);
1095 res
= isl_pw_aff_union_add(res
, pa
);
1097 if (seen_paren
&& isl_stream_eat(s
, ')'))
1099 } while (isl_stream_eat_if_available(s
, ';'));
1101 isl_space_free(space
);
1105 isl_space_free(space
);
1106 return isl_pw_aff_free(res
);
1109 /* Read an affine expression from "s" for use in read_tuple.
1111 * accept_extended_affine requires a wrapped space as input.
1112 * read_tuple on the other hand expects each isl_pw_aff
1113 * to have an anonymous space. We therefore adjust the space
1114 * of the isl_pw_aff before returning it.
1116 static __isl_give isl_pw_aff
*read_tuple_var_def(__isl_keep isl_stream
*s
,
1117 struct vars
*v
, int rational
)
1122 space
= isl_space_wrap(isl_space_alloc(s
->ctx
, 0, v
->n
, 0));
1124 def
= accept_piecewise_affine(s
, space
, v
, rational
);
1126 space
= isl_space_set_alloc(s
->ctx
, 0, v
->n
);
1127 def
= isl_pw_aff_reset_domain_space(def
, space
);
1132 /* Read a list of tuple elements by calling "read_el" on each of them and
1133 * return a space with the same number of set dimensions derived from
1134 * the parameter space "space" and possibly updated by "read_el".
1135 * The elements in the list are separated by either "," or "][".
1136 * If "comma" is set then only "," is allowed.
1138 static __isl_give isl_space
*read_tuple_list(__isl_keep isl_stream
*s
,
1139 struct vars
*v
, __isl_take isl_space
*space
, int rational
, int comma
,
1140 __isl_give isl_space
*(*read_el
)(__isl_keep isl_stream
*s
,
1141 struct vars
*v
, __isl_take isl_space
*space
, int rational
,
1148 space
= isl_space_set_from_params(space
);
1150 if (isl_stream_next_token_is(s
, ']'))
1154 struct isl_token
*tok
;
1156 space
= isl_space_add_dims(space
, isl_dim_set
, 1);
1158 space
= read_el(s
, v
, space
, rational
, user
);
1162 tok
= isl_stream_next_token(s
);
1163 if (!comma
&& tok
&& tok
->type
== ']' &&
1164 isl_stream_next_token_is(s
, '[')) {
1165 isl_token_free(tok
);
1166 tok
= isl_stream_next_token(s
);
1167 } else if (!tok
|| tok
->type
!= ',') {
1169 isl_stream_push_token(s
, tok
);
1173 isl_token_free(tok
);
1179 /* Read a tuple space from "s" derived from the parameter space "space".
1180 * Call "read_el" on each element in the tuples.
1182 static __isl_give isl_space
*read_tuple_space(__isl_keep isl_stream
*s
,
1183 struct vars
*v
, __isl_take isl_space
*space
, int rational
, int comma
,
1184 __isl_give isl_space
*(*read_el
)(__isl_keep isl_stream
*s
,
1185 struct vars
*v
, __isl_take isl_space
*space
, int rational
,
1189 struct isl_token
*tok
;
1191 isl_space
*res
= NULL
;
1193 tok
= isl_stream_next_token(s
);
1196 if (tok
->type
== ISL_TOKEN_IDENT
|| tok
->is_keyword
) {
1197 name
= strdup(tok
->u
.s
);
1198 isl_token_free(tok
);
1202 isl_stream_push_token(s
, tok
);
1203 if (isl_stream_eat(s
, '['))
1205 if (next_is_tuple(s
)) {
1207 res
= read_tuple_space(s
, v
, isl_space_copy(space
),
1208 rational
, comma
, read_el
, user
);
1209 if (isl_stream_eat(s
, ISL_TOKEN_TO
))
1211 out
= read_tuple_space(s
, v
, isl_space_copy(space
),
1212 rational
, comma
, read_el
, user
);
1213 res
= isl_space_product(res
, out
);
1215 res
= read_tuple_list(s
, v
, isl_space_copy(space
),
1216 rational
, comma
, read_el
, user
);
1217 if (isl_stream_eat(s
, ']'))
1221 res
= isl_space_set_tuple_name(res
, isl_dim_set
, name
);
1225 isl_space_free(space
);
1229 isl_space_free(res
);
1230 isl_space_free(space
);
1234 /* Construct an isl_pw_aff defined on a space with v->n variables
1235 * that is equal to the last of those variables.
1237 static __isl_give isl_pw_aff
*identity_tuple_el(struct vars
*v
)
1242 space
= isl_space_set_alloc(v
->ctx
, 0, v
->n
);
1243 aff
= isl_aff_zero_on_domain(isl_local_space_from_space(space
));
1244 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, v
->n
- 1, 1);
1245 return isl_pw_aff_from_aff(aff
);
1248 /* This function is called for each element in a tuple inside read_tuple.
1249 * Add a new variable to "v" and construct a corresponding isl_pw_aff defined
1250 * over a space containing all variables in "v" defined so far.
1251 * The isl_pw_aff expresses the new variable in terms of earlier variables
1252 * if a definition is provided. Otherwise, it is represented as being
1254 * Add the isl_pw_aff to *list.
1255 * If the new variable was named, then adjust "space" accordingly and
1256 * return the updated space.
1258 static __isl_give isl_space
*read_tuple_pw_aff_el(__isl_keep isl_stream
*s
,
1259 struct vars
*v
, __isl_take isl_space
*space
, int rational
, void *user
)
1261 isl_pw_aff_list
**list
= (isl_pw_aff_list
**) user
;
1263 struct isl_token
*tok
;
1266 tok
= next_token(s
);
1268 isl_stream_error(s
, NULL
, "unexpected EOF");
1269 return isl_space_free(space
);
1272 if (tok
->type
== ISL_TOKEN_IDENT
) {
1274 int p
= vars_pos(v
, tok
->u
.s
, -1);
1280 if (tok
->type
== '*') {
1281 if (vars_add_anon(v
) < 0)
1283 isl_token_free(tok
);
1284 pa
= identity_tuple_el(v
);
1285 } else if (new_name
) {
1286 isl_size pos
= isl_space_dim(space
, isl_dim_out
);
1290 space
= space_set_dim_name(space
, pos
, v
->v
->name
);
1291 isl_token_free(tok
);
1292 if (isl_stream_eat_if_available(s
, '='))
1293 pa
= read_tuple_var_def(s
, v
, rational
);
1295 pa
= identity_tuple_el(v
);
1297 isl_stream_push_token(s
, tok
);
1299 if (vars_add_anon(v
) < 0)
1301 pa
= read_tuple_var_def(s
, v
, rational
);
1304 *list
= isl_pw_aff_list_add(*list
, pa
);
1306 return isl_space_free(space
);
1310 isl_token_free(tok
);
1311 return isl_space_free(space
);
1314 /* Read a tuple and represent it as an isl_multi_pw_aff.
1315 * The range space of the isl_multi_pw_aff is the space of the tuple.
1316 * The domain space is an anonymous space
1317 * with a dimension for each variable in the set of variables in "v",
1318 * including the variables in the range.
1319 * If a given dimension is not defined in terms of earlier dimensions in
1320 * the input, then the corresponding isl_pw_aff is set equal to one time
1321 * the variable corresponding to the dimension being defined.
1323 * The elements in the tuple are collected in a list by read_tuple_pw_aff_el.
1324 * Each element in this list is defined over a space representing
1325 * the variables defined so far. We need to adjust the earlier
1326 * elements to have as many variables in the domain as the final
1327 * element in the list.
1329 static __isl_give isl_multi_pw_aff
*read_tuple(__isl_keep isl_stream
*s
,
1330 struct vars
*v
, int rational
, int comma
)
1335 isl_pw_aff_list
*list
;
1337 space
= isl_space_params_alloc(v
->ctx
, 0);
1338 list
= isl_pw_aff_list_alloc(s
->ctx
, 0);
1339 space
= read_tuple_space(s
, v
, space
, rational
, comma
,
1340 &read_tuple_pw_aff_el
, &list
);
1341 n
= isl_space_dim(space
, isl_dim_set
);
1343 space
= isl_space_free(space
);
1344 for (i
= 0; i
+ 1 < n
; ++i
) {
1347 pa
= isl_pw_aff_list_get_pw_aff(list
, i
);
1348 pa
= isl_pw_aff_add_dims(pa
, isl_dim_in
, n
- (i
+ 1));
1349 list
= isl_pw_aff_list_set_pw_aff(list
, i
, pa
);
1352 space
= isl_space_from_range(space
);
1353 space
= isl_space_add_dims(space
, isl_dim_in
, v
->n
);
1354 return isl_multi_pw_aff_from_pw_aff_list(space
, list
);
1357 /* Add the tuple represented by the isl_multi_pw_aff "tuple" to "map".
1358 * We first create the appropriate space in "map" based on the range
1359 * space of this isl_multi_pw_aff. Then, we add equalities based
1360 * on the affine expressions. These live in an anonymous space,
1361 * however, so we first need to reset the space to that of "map".
1363 static __isl_give isl_map
*map_from_tuple(__isl_take isl_multi_pw_aff
*tuple
,
1364 __isl_take isl_map
*map
, enum isl_dim_type type
, struct vars
*v
,
1370 isl_space
*space
= NULL
;
1372 n
= isl_multi_pw_aff_dim(tuple
, isl_dim_out
);
1375 ctx
= isl_multi_pw_aff_get_ctx(tuple
);
1376 space
= isl_space_range(isl_multi_pw_aff_get_space(tuple
));
1380 if (type
== isl_dim_param
) {
1381 if (isl_space_has_tuple_name(space
, isl_dim_set
) ||
1382 isl_space_is_wrapping(space
)) {
1383 isl_die(ctx
, isl_error_invalid
,
1384 "parameter tuples cannot be named or nested",
1387 map
= isl_map_add_dims(map
, type
, n
);
1388 for (i
= 0; i
< n
; ++i
) {
1390 if (!isl_space_has_dim_name(space
, isl_dim_set
, i
))
1391 isl_die(ctx
, isl_error_invalid
,
1392 "parameters must be named",
1394 id
= isl_space_get_dim_id(space
, isl_dim_set
, i
);
1395 map
= isl_map_set_dim_id(map
, isl_dim_param
, i
, id
);
1397 } else if (type
== isl_dim_in
) {
1400 set
= isl_set_universe(isl_space_copy(space
));
1402 set
= isl_set_set_rational(set
);
1403 set
= isl_set_intersect_params(set
, isl_map_params(map
));
1404 map
= isl_map_from_domain(set
);
1408 set
= isl_set_universe(isl_space_copy(space
));
1410 set
= isl_set_set_rational(set
);
1411 map
= isl_map_from_domain_and_range(isl_map_domain(map
), set
);
1414 for (i
= 0; i
< n
; ++i
) {
1421 pa
= isl_multi_pw_aff_get_pw_aff(tuple
, i
);
1422 space
= isl_pw_aff_get_domain_space(pa
);
1423 aff
= isl_aff_zero_on_domain(isl_local_space_from_space(space
));
1424 aff
= isl_aff_add_coefficient_si(aff
,
1425 isl_dim_in
, v
->n
- n
+ i
, -1);
1426 pa
= isl_pw_aff_add(pa
, isl_pw_aff_from_aff(aff
));
1428 pa
= isl_pw_aff_set_rational(pa
);
1429 set
= isl_pw_aff_zero_set(pa
);
1430 map_i
= isl_map_from_range(set
);
1431 map_i
= isl_map_reset_space(map_i
, isl_map_get_space(map
));
1432 map
= isl_map_intersect(map
, map_i
);
1435 isl_space_free(space
);
1436 isl_multi_pw_aff_free(tuple
);
1439 isl_space_free(space
);
1440 isl_multi_pw_aff_free(tuple
);
1445 /* Read a tuple from "s" and add it to "map".
1446 * The tuple is initially represented as an isl_multi_pw_aff and
1447 * then added to "map".
1449 static __isl_give isl_map
*read_map_tuple(__isl_keep isl_stream
*s
,
1450 __isl_take isl_map
*map
, enum isl_dim_type type
, struct vars
*v
,
1451 int rational
, int comma
)
1453 isl_multi_pw_aff
*tuple
;
1455 tuple
= read_tuple(s
, v
, rational
, comma
);
1457 return isl_map_free(map
);
1459 return map_from_tuple(tuple
, map
, type
, v
, rational
);
1462 /* Given two equal-length lists of piecewise affine expression with the space
1463 * of "set" as domain, construct a set in the same space that expresses
1464 * that "left" and "right" satisfy the comparison "type".
1466 * A space is constructed of the same dimension as the number of elements
1467 * in the two lists. The comparison is then expressed in a map from
1468 * this space to itself and wrapped into a set. Finally the two lists
1469 * of piecewise affine expressions are plugged into this set.
1471 * Let S be the space of "set" and T the constructed space.
1472 * The lists are first changed into two isl_multi_pw_affs in S -> T and
1473 * then combined into an isl_multi_pw_aff in S -> [T -> T],
1474 * while the comparison is first expressed in T -> T, then [T -> T]
1477 static __isl_give isl_set
*list_cmp(__isl_keep isl_set
*set
, int type
,
1478 __isl_take isl_pw_aff_list
*left
, __isl_take isl_pw_aff_list
*right
)
1482 isl_multi_pw_aff
*mpa1
, *mpa2
;
1484 n
= isl_pw_aff_list_n_pw_aff(left
);
1485 if (!set
|| n
< 0 || !right
)
1488 space
= isl_set_get_space(set
);
1489 space
= isl_space_from_domain(space
);
1490 space
= isl_space_add_dims(space
, isl_dim_out
, n
);
1491 mpa1
= isl_multi_pw_aff_from_pw_aff_list(isl_space_copy(space
), left
);
1492 mpa2
= isl_multi_pw_aff_from_pw_aff_list(isl_space_copy(space
), right
);
1493 mpa1
= isl_multi_pw_aff_range_product(mpa1
, mpa2
);
1495 space
= isl_space_range(space
);
1497 case ISL_TOKEN_LEX_LT
:
1498 set
= isl_map_wrap(isl_map_lex_lt(space
));
1500 case ISL_TOKEN_LEX_GT
:
1501 set
= isl_map_wrap(isl_map_lex_gt(space
));
1503 case ISL_TOKEN_LEX_LE
:
1504 set
= isl_map_wrap(isl_map_lex_le(space
));
1506 case ISL_TOKEN_LEX_GE
:
1507 set
= isl_map_wrap(isl_map_lex_ge(space
));
1510 isl_multi_pw_aff_free(mpa1
);
1511 isl_space_free(space
);
1512 isl_die(isl_set_get_ctx(set
), isl_error_internal
,
1513 "unhandled list comparison type", return NULL
);
1515 set
= isl_set_preimage_multi_pw_aff(set
, mpa1
);
1518 isl_pw_aff_list_free(left
);
1519 isl_pw_aff_list_free(right
);
1523 /* Construct constraints of the form
1527 * where a is an element in "left", op is an operator of type "type" and
1528 * b is an element in "right", add the constraints to "set" and return
1530 * "rational" is set if the constraints should be treated as
1531 * a rational constraints.
1533 * If "type" is the type of a comparison operator between lists
1534 * of affine expressions, then a single (compound) constraint
1535 * is constructed by list_cmp instead.
1537 static __isl_give isl_set
*construct_constraints(
1538 __isl_take isl_set
*set
, int type
,
1539 __isl_keep isl_pw_aff_list
*left
, __isl_keep isl_pw_aff_list
*right
,
1544 left
= isl_pw_aff_list_copy(left
);
1545 right
= isl_pw_aff_list_copy(right
);
1547 left
= isl_pw_aff_list_set_rational(left
);
1548 right
= isl_pw_aff_list_set_rational(right
);
1550 if (is_list_comparator_type(type
))
1551 cond
= list_cmp(set
, type
, left
, right
);
1552 else if (type
== ISL_TOKEN_LE
)
1553 cond
= isl_pw_aff_list_le_set(left
, right
);
1554 else if (type
== ISL_TOKEN_GE
)
1555 cond
= isl_pw_aff_list_ge_set(left
, right
);
1556 else if (type
== ISL_TOKEN_LT
)
1557 cond
= isl_pw_aff_list_lt_set(left
, right
);
1558 else if (type
== ISL_TOKEN_GT
)
1559 cond
= isl_pw_aff_list_gt_set(left
, right
);
1560 else if (type
== ISL_TOKEN_NE
)
1561 cond
= isl_pw_aff_list_ne_set(left
, right
);
1563 cond
= isl_pw_aff_list_eq_set(left
, right
);
1565 return isl_set_intersect(set
, cond
);
1568 /* Read a constraint from "s", add it to "map" and return the result.
1569 * "v" contains a description of the identifiers parsed so far.
1570 * "rational" is set if the constraint should be treated as
1571 * a rational constraint.
1572 * The constraint read from "s" may be applied to multiple pairs
1573 * of affine expressions and may be chained.
1574 * In particular, a list of affine expressions is read, followed
1575 * by a comparison operator and another list of affine expressions.
1576 * The comparison operator is then applied to each pair of elements
1577 * in the two lists and the results are added to "map".
1578 * However, if the operator expects two lists of affine expressions,
1579 * then it is applied directly to those lists and the two lists
1580 * are required to have the same length.
1581 * If the next token is another comparison operator, then another
1582 * list of affine expressions is read and the process repeats.
1584 * The processing is performed on a wrapped copy of "map" because
1585 * an affine expression cannot have a binary relation as domain.
1587 static __isl_give isl_map
*add_constraint(__isl_keep isl_stream
*s
,
1588 struct vars
*v
, __isl_take isl_map
*map
, int rational
)
1590 struct isl_token
*tok
;
1592 isl_pw_aff_list
*list1
= NULL
, *list2
= NULL
;
1596 set
= isl_map_wrap(map
);
1597 list1
= accept_affine_list(s
, isl_set_get_space(set
), v
);
1600 tok
= isl_stream_next_token(s
);
1601 if (!is_comparator(tok
)) {
1602 isl_stream_error(s
, tok
, "missing operator");
1604 isl_stream_push_token(s
, tok
);
1608 isl_token_free(tok
);
1610 list2
= accept_affine_list(s
, isl_set_get_space(set
), v
);
1611 n1
= isl_pw_aff_list_n_pw_aff(list1
);
1612 n2
= isl_pw_aff_list_n_pw_aff(list2
);
1613 if (n1
< 0 || n2
< 0)
1615 if (is_list_comparator_type(type
) && n1
!= n2
) {
1616 isl_stream_error(s
, NULL
,
1617 "list arguments not of same size");
1621 set
= construct_constraints(set
, type
, list1
, list2
, rational
);
1622 isl_pw_aff_list_free(list1
);
1625 tok
= isl_stream_next_token(s
);
1626 if (!is_comparator(tok
)) {
1628 isl_stream_push_token(s
, tok
);
1632 isl_token_free(tok
);
1634 isl_pw_aff_list_free(list1
);
1636 return isl_set_unwrap(set
);
1638 isl_pw_aff_list_free(list1
);
1639 isl_pw_aff_list_free(list2
);
1644 static __isl_give isl_map
*read_exists(__isl_keep isl_stream
*s
,
1645 struct vars
*v
, __isl_take isl_map
*map
, int rational
)
1648 int seen_paren
= isl_stream_eat_if_available(s
, '(');
1650 map
= isl_map_from_domain(isl_map_wrap(map
));
1651 map
= read_defined_var_list(s
, v
, map
, rational
);
1653 if (isl_stream_eat(s
, ':'))
1656 map
= read_formula(s
, v
, map
, rational
);
1657 map
= isl_set_unwrap(isl_map_domain(map
));
1659 vars_drop(v
, v
->n
- n
);
1660 if (seen_paren
&& isl_stream_eat(s
, ')'))
1669 /* Parse an expression between parentheses and push the result
1670 * back on the stream.
1672 * The parsed expression may be either an affine expression
1673 * or a condition. The first type is pushed onto the stream
1674 * as an isl_pw_aff, while the second is pushed as an isl_map.
1676 * If the initial token indicates the start of a condition,
1677 * we parse it as such.
1678 * Otherwise, we first parse an affine expression and push
1679 * that onto the stream. If the affine expression covers the
1680 * entire expression between parentheses, we return.
1681 * Otherwise, we assume that the affine expression is the
1682 * start of a condition and continue parsing.
1684 static int resolve_paren_expr(__isl_keep isl_stream
*s
,
1685 struct vars
*v
, __isl_take isl_map
*map
, int rational
)
1687 struct isl_token
*tok
, *tok2
;
1691 tok
= isl_stream_next_token(s
);
1692 if (!tok
|| tok
->type
!= '(')
1695 if (isl_stream_next_token_is(s
, '('))
1696 if (resolve_paren_expr(s
, v
, isl_map_copy(map
), rational
))
1699 if (isl_stream_next_token_is(s
, ISL_TOKEN_EXISTS
) ||
1700 isl_stream_next_token_is(s
, ISL_TOKEN_NOT
) ||
1701 isl_stream_next_token_is(s
, ISL_TOKEN_TRUE
) ||
1702 isl_stream_next_token_is(s
, ISL_TOKEN_FALSE
) ||
1703 isl_stream_next_token_is(s
, ISL_TOKEN_MAP
)) {
1704 map
= read_formula(s
, v
, map
, rational
);
1705 if (isl_stream_eat(s
, ')'))
1707 tok
->type
= ISL_TOKEN_MAP
;
1709 isl_stream_push_token(s
, tok
);
1713 tok2
= isl_stream_next_token(s
);
1718 isl_stream_push_token(s
, tok2
);
1720 pwaff
= accept_affine(s
, isl_space_wrap(isl_map_get_space(map
)), v
);
1724 tok2
= isl_token_new(s
->ctx
, line
, col
, 0);
1727 tok2
->type
= ISL_TOKEN_AFF
;
1728 tok2
->u
.pwaff
= pwaff
;
1730 if (isl_stream_eat_if_available(s
, ')')) {
1731 isl_stream_push_token(s
, tok2
);
1732 isl_token_free(tok
);
1737 isl_stream_push_token(s
, tok2
);
1739 map
= read_formula(s
, v
, map
, rational
);
1740 if (isl_stream_eat(s
, ')'))
1743 tok
->type
= ISL_TOKEN_MAP
;
1745 isl_stream_push_token(s
, tok
);
1749 isl_pw_aff_free(pwaff
);
1751 isl_token_free(tok
);
1756 static __isl_give isl_map
*read_conjunct(__isl_keep isl_stream
*s
,
1757 struct vars
*v
, __isl_take isl_map
*map
, int rational
)
1759 if (isl_stream_next_token_is(s
, '('))
1760 if (resolve_paren_expr(s
, v
, isl_map_copy(map
), rational
))
1763 if (isl_stream_next_token_is(s
, ISL_TOKEN_MAP
)) {
1764 struct isl_token
*tok
;
1765 tok
= isl_stream_next_token(s
);
1769 map
= isl_map_copy(tok
->u
.map
);
1770 isl_token_free(tok
);
1774 if (isl_stream_eat_if_available(s
, ISL_TOKEN_EXISTS
))
1775 return read_exists(s
, v
, map
, rational
);
1777 if (isl_stream_eat_if_available(s
, ISL_TOKEN_TRUE
))
1780 if (isl_stream_eat_if_available(s
, ISL_TOKEN_FALSE
)) {
1781 isl_space
*dim
= isl_map_get_space(map
);
1783 return isl_map_empty(dim
);
1786 return add_constraint(s
, v
, map
, rational
);
1792 static __isl_give isl_map
*read_conjuncts(__isl_keep isl_stream
*s
,
1793 struct vars
*v
, __isl_take isl_map
*map
, int rational
)
1798 negate
= isl_stream_eat_if_available(s
, ISL_TOKEN_NOT
);
1799 res
= read_conjunct(s
, v
, isl_map_copy(map
), rational
);
1801 res
= isl_map_subtract(isl_map_copy(map
), res
);
1803 while (res
&& isl_stream_eat_if_available(s
, ISL_TOKEN_AND
)) {
1806 negate
= isl_stream_eat_if_available(s
, ISL_TOKEN_NOT
);
1807 res_i
= read_conjunct(s
, v
, isl_map_copy(map
), rational
);
1809 res
= isl_map_subtract(res
, res_i
);
1811 res
= isl_map_intersect(res
, res_i
);
1818 static struct isl_map
*read_disjuncts(__isl_keep isl_stream
*s
,
1819 struct vars
*v
, __isl_take isl_map
*map
, int rational
)
1823 if (isl_stream_next_token_is(s
, '}'))
1826 res
= read_conjuncts(s
, v
, isl_map_copy(map
), rational
);
1827 while (isl_stream_eat_if_available(s
, ISL_TOKEN_OR
)) {
1830 res_i
= read_conjuncts(s
, v
, isl_map_copy(map
), rational
);
1831 res
= isl_map_union(res
, res_i
);
1838 /* Read a first order formula from "s", add the corresponding
1839 * constraints to "map" and return the result.
1841 * In particular, read a formula of the form
1849 * where a and b are disjunctions.
1851 * In the first case, map is replaced by
1853 * map \cap { [..] : a }
1855 * In the second case, it is replaced by
1857 * (map \setminus { [..] : a}) \cup (map \cap { [..] : b })
1859 static __isl_give isl_map
*read_formula(__isl_keep isl_stream
*s
,
1860 struct vars
*v
, __isl_take isl_map
*map
, int rational
)
1864 res
= read_disjuncts(s
, v
, isl_map_copy(map
), rational
);
1866 if (isl_stream_eat_if_available(s
, ISL_TOKEN_IMPLIES
)) {
1869 res
= isl_map_subtract(isl_map_copy(map
), res
);
1870 res2
= read_disjuncts(s
, v
, map
, rational
);
1871 res
= isl_map_union(res
, res2
);
1878 static isl_size
polylib_pos_to_isl_pos(__isl_keep isl_basic_map
*bmap
, int pos
)
1880 isl_size n_out
, n_in
, n_param
, n_div
;
1882 n_param
= isl_basic_map_dim(bmap
, isl_dim_param
);
1883 n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
1884 n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
1885 n_div
= isl_basic_map_dim(bmap
, isl_dim_div
);
1886 if (n_param
< 0 || n_in
< 0 || n_out
< 0 || n_div
< 0)
1887 return isl_size_error
;
1890 return 1 + n_param
+ n_in
+ pos
;
1894 return 1 + n_param
+ pos
;
1898 return 1 + n_param
+ n_in
+ n_out
+ pos
;
1907 static __isl_give isl_basic_map
*basic_map_read_polylib_constraint(
1908 __isl_keep isl_stream
*s
, __isl_take isl_basic_map
*bmap
)
1911 struct isl_token
*tok
;
1920 tok
= isl_stream_next_token(s
);
1921 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
1922 isl_stream_error(s
, tok
, "expecting coefficient");
1924 isl_stream_push_token(s
, tok
);
1927 if (!tok
->on_new_line
) {
1928 isl_stream_error(s
, tok
, "coefficient should appear on new line");
1929 isl_stream_push_token(s
, tok
);
1933 type
= isl_int_get_si(tok
->u
.v
);
1934 isl_token_free(tok
);
1936 isl_assert(s
->ctx
, type
== 0 || type
== 1, goto error
);
1938 k
= isl_basic_map_alloc_equality(bmap
);
1941 k
= isl_basic_map_alloc_inequality(bmap
);
1947 total
= isl_basic_map_dim(bmap
, isl_dim_all
);
1949 return isl_basic_map_free(bmap
);
1950 for (j
= 0; j
< 1 + total
; ++j
) {
1952 tok
= isl_stream_next_token(s
);
1953 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
1954 isl_stream_error(s
, tok
, "expecting coefficient");
1956 isl_stream_push_token(s
, tok
);
1959 if (tok
->on_new_line
) {
1960 isl_stream_error(s
, tok
,
1961 "coefficient should not appear on new line");
1962 isl_stream_push_token(s
, tok
);
1965 pos
= polylib_pos_to_isl_pos(bmap
, j
);
1967 isl_int_set(c
[pos
], tok
->u
.v
);
1968 isl_token_free(tok
);
1970 return isl_basic_map_free(bmap
);
1975 isl_basic_map_free(bmap
);
1979 static __isl_give isl_basic_map
*basic_map_read_polylib(
1980 __isl_keep isl_stream
*s
)
1983 struct isl_token
*tok
;
1984 struct isl_token
*tok2
;
1987 unsigned in
= 0, out
, local
= 0;
1988 struct isl_basic_map
*bmap
= NULL
;
1991 tok
= isl_stream_next_token(s
);
1993 isl_stream_error(s
, NULL
, "unexpected EOF");
1996 tok2
= isl_stream_next_token(s
);
1998 isl_token_free(tok
);
1999 isl_stream_error(s
, NULL
, "unexpected EOF");
2002 if (tok
->type
!= ISL_TOKEN_VALUE
|| tok2
->type
!= ISL_TOKEN_VALUE
) {
2003 isl_stream_push_token(s
, tok2
);
2004 isl_stream_push_token(s
, tok
);
2005 isl_stream_error(s
, NULL
,
2006 "expecting constraint matrix dimensions");
2009 n_row
= isl_int_get_si(tok
->u
.v
);
2010 n_col
= isl_int_get_si(tok2
->u
.v
);
2011 on_new_line
= tok2
->on_new_line
;
2012 isl_token_free(tok2
);
2013 isl_token_free(tok
);
2014 isl_assert(s
->ctx
, !on_new_line
, return NULL
);
2015 isl_assert(s
->ctx
, n_row
>= 0, return NULL
);
2016 isl_assert(s
->ctx
, n_col
>= 2 + nparam
, return NULL
);
2017 tok
= isl_stream_next_token_on_same_line(s
);
2019 if (tok
->type
!= ISL_TOKEN_VALUE
) {
2020 isl_stream_error(s
, tok
,
2021 "expecting number of output dimensions");
2022 isl_stream_push_token(s
, tok
);
2025 out
= isl_int_get_si(tok
->u
.v
);
2026 isl_token_free(tok
);
2028 tok
= isl_stream_next_token_on_same_line(s
);
2029 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
2030 isl_stream_error(s
, tok
,
2031 "expecting number of input dimensions");
2033 isl_stream_push_token(s
, tok
);
2036 in
= isl_int_get_si(tok
->u
.v
);
2037 isl_token_free(tok
);
2039 tok
= isl_stream_next_token_on_same_line(s
);
2040 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
2041 isl_stream_error(s
, tok
,
2042 "expecting number of existentials");
2044 isl_stream_push_token(s
, tok
);
2047 local
= isl_int_get_si(tok
->u
.v
);
2048 isl_token_free(tok
);
2050 tok
= isl_stream_next_token_on_same_line(s
);
2051 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
2052 isl_stream_error(s
, tok
,
2053 "expecting number of parameters");
2055 isl_stream_push_token(s
, tok
);
2058 nparam
= isl_int_get_si(tok
->u
.v
);
2059 isl_token_free(tok
);
2060 if (n_col
!= 1 + out
+ in
+ local
+ nparam
+ 1) {
2061 isl_stream_error(s
, NULL
,
2062 "dimensions don't match");
2066 out
= n_col
- 2 - nparam
;
2067 bmap
= isl_basic_map_alloc(s
->ctx
, nparam
, in
, out
, local
, n_row
, n_row
);
2071 for (i
= 0; i
< local
; ++i
) {
2072 int k
= isl_basic_map_alloc_div(bmap
);
2075 isl_seq_clr(bmap
->div
[k
], 1 + 1 + nparam
+ in
+ out
+ local
);
2078 for (i
= 0; i
< n_row
; ++i
)
2079 bmap
= basic_map_read_polylib_constraint(s
, bmap
);
2081 tok
= isl_stream_next_token_on_same_line(s
);
2083 isl_stream_error(s
, tok
, "unexpected extra token on line");
2084 isl_stream_push_token(s
, tok
);
2088 bmap
= isl_basic_map_simplify(bmap
);
2089 bmap
= isl_basic_map_finalize(bmap
);
2092 isl_basic_map_free(bmap
);
2096 static struct isl_map
*map_read_polylib(__isl_keep isl_stream
*s
)
2098 struct isl_token
*tok
;
2099 struct isl_token
*tok2
;
2101 struct isl_map
*map
;
2103 tok
= isl_stream_next_token(s
);
2105 isl_stream_error(s
, NULL
, "unexpected EOF");
2108 tok2
= isl_stream_next_token_on_same_line(s
);
2109 if (tok2
&& tok2
->type
== ISL_TOKEN_VALUE
) {
2110 isl_stream_push_token(s
, tok2
);
2111 isl_stream_push_token(s
, tok
);
2112 return isl_map_from_basic_map(basic_map_read_polylib(s
));
2115 isl_stream_error(s
, tok2
, "unexpected token");
2116 isl_stream_push_token(s
, tok2
);
2117 isl_stream_push_token(s
, tok
);
2120 n
= isl_int_get_si(tok
->u
.v
);
2121 isl_token_free(tok
);
2123 isl_assert(s
->ctx
, n
>= 1, return NULL
);
2125 map
= isl_map_from_basic_map(basic_map_read_polylib(s
));
2127 for (i
= 1; map
&& i
< n
; ++i
)
2128 map
= isl_map_union(map
,
2129 isl_map_from_basic_map(basic_map_read_polylib(s
)));
2134 static int optional_power(__isl_keep isl_stream
*s
)
2137 struct isl_token
*tok
;
2139 tok
= isl_stream_next_token(s
);
2142 if (tok
->type
!= '^') {
2143 isl_stream_push_token(s
, tok
);
2146 isl_token_free(tok
);
2147 tok
= isl_stream_next_token(s
);
2148 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
2149 isl_stream_error(s
, tok
, "expecting exponent");
2151 isl_stream_push_token(s
, tok
);
2154 pow
= isl_int_get_si(tok
->u
.v
);
2155 isl_token_free(tok
);
2159 static __isl_give isl_pw_qpolynomial
*read_term(__isl_keep isl_stream
*s
,
2160 __isl_keep isl_map
*map
, struct vars
*v
);
2162 static __isl_give isl_pw_qpolynomial
*read_factor(__isl_keep isl_stream
*s
,
2163 __isl_keep isl_map
*map
, struct vars
*v
)
2165 isl_pw_qpolynomial
*pwqp
;
2166 struct isl_token
*tok
;
2168 tok
= next_token(s
);
2170 isl_stream_error(s
, NULL
, "unexpected EOF");
2173 if (tok
->type
== '(') {
2176 isl_token_free(tok
);
2177 pwqp
= read_term(s
, map
, v
);
2180 if (isl_stream_eat(s
, ')'))
2182 pow
= optional_power(s
);
2183 pwqp
= isl_pw_qpolynomial_pow(pwqp
, pow
);
2184 } else if (tok
->type
== ISL_TOKEN_VALUE
) {
2185 struct isl_token
*tok2
;
2186 isl_qpolynomial
*qp
;
2188 tok2
= isl_stream_next_token(s
);
2189 if (tok2
&& tok2
->type
== '/') {
2190 isl_token_free(tok2
);
2191 tok2
= next_token(s
);
2192 if (!tok2
|| tok2
->type
!= ISL_TOKEN_VALUE
) {
2193 isl_stream_error(s
, tok2
, "expected denominator");
2194 isl_token_free(tok
);
2195 isl_token_free(tok2
);
2198 qp
= isl_qpolynomial_rat_cst_on_domain(isl_map_get_space(map
),
2199 tok
->u
.v
, tok2
->u
.v
);
2200 isl_token_free(tok2
);
2202 isl_stream_push_token(s
, tok2
);
2203 qp
= isl_qpolynomial_cst_on_domain(isl_map_get_space(map
),
2206 isl_token_free(tok
);
2207 pwqp
= isl_pw_qpolynomial_from_qpolynomial(qp
);
2208 } else if (tok
->type
== ISL_TOKEN_INFTY
) {
2209 isl_qpolynomial
*qp
;
2210 isl_token_free(tok
);
2211 qp
= isl_qpolynomial_infty_on_domain(isl_map_get_space(map
));
2212 pwqp
= isl_pw_qpolynomial_from_qpolynomial(qp
);
2213 } else if (tok
->type
== ISL_TOKEN_NAN
) {
2214 isl_qpolynomial
*qp
;
2215 isl_token_free(tok
);
2216 qp
= isl_qpolynomial_nan_on_domain(isl_map_get_space(map
));
2217 pwqp
= isl_pw_qpolynomial_from_qpolynomial(qp
);
2218 } else if (tok
->type
== ISL_TOKEN_IDENT
) {
2220 int pos
= vars_pos(v
, tok
->u
.s
, -1);
2222 isl_qpolynomial
*qp
;
2224 isl_token_free(tok
);
2228 vars_drop(v
, v
->n
- n
);
2229 isl_stream_error(s
, tok
, "unknown identifier");
2230 isl_token_free(tok
);
2233 isl_token_free(tok
);
2234 pow
= optional_power(s
);
2235 qp
= isl_qpolynomial_var_pow_on_domain(isl_map_get_space(map
), pos
, pow
);
2236 pwqp
= isl_pw_qpolynomial_from_qpolynomial(qp
);
2237 } else if (is_start_of_div(tok
)) {
2241 isl_stream_push_token(s
, tok
);
2242 pwaff
= accept_div(s
, isl_map_get_space(map
), v
);
2243 pow
= optional_power(s
);
2244 pwqp
= isl_pw_qpolynomial_from_pw_aff(pwaff
);
2245 pwqp
= isl_pw_qpolynomial_pow(pwqp
, pow
);
2246 } else if (tok
->type
== '-') {
2247 isl_token_free(tok
);
2248 pwqp
= read_factor(s
, map
, v
);
2249 pwqp
= isl_pw_qpolynomial_neg(pwqp
);
2251 isl_stream_error(s
, tok
, "unexpected isl_token");
2252 isl_stream_push_token(s
, tok
);
2256 if (isl_stream_eat_if_available(s
, '*') ||
2257 isl_stream_next_token_is(s
, ISL_TOKEN_IDENT
)) {
2258 isl_pw_qpolynomial
*pwqp2
;
2260 pwqp2
= read_factor(s
, map
, v
);
2261 pwqp
= isl_pw_qpolynomial_mul(pwqp
, pwqp2
);
2266 isl_pw_qpolynomial_free(pwqp
);
2270 static __isl_give isl_pw_qpolynomial
*read_term(__isl_keep isl_stream
*s
,
2271 __isl_keep isl_map
*map
, struct vars
*v
)
2273 struct isl_token
*tok
;
2274 isl_pw_qpolynomial
*pwqp
;
2276 pwqp
= read_factor(s
, map
, v
);
2279 tok
= next_token(s
);
2283 if (tok
->type
== '+') {
2284 isl_pw_qpolynomial
*pwqp2
;
2286 isl_token_free(tok
);
2287 pwqp2
= read_factor(s
, map
, v
);
2288 pwqp
= isl_pw_qpolynomial_add(pwqp
, pwqp2
);
2289 } else if (tok
->type
== '-') {
2290 isl_pw_qpolynomial
*pwqp2
;
2292 isl_token_free(tok
);
2293 pwqp2
= read_factor(s
, map
, v
);
2294 pwqp
= isl_pw_qpolynomial_sub(pwqp
, pwqp2
);
2295 } else if (tok
->type
== ISL_TOKEN_VALUE
&&
2296 isl_int_is_neg(tok
->u
.v
)) {
2297 isl_pw_qpolynomial
*pwqp2
;
2299 isl_stream_push_token(s
, tok
);
2300 pwqp2
= read_factor(s
, map
, v
);
2301 pwqp
= isl_pw_qpolynomial_add(pwqp
, pwqp2
);
2303 isl_stream_push_token(s
, tok
);
2311 static __isl_give isl_map
*read_optional_formula(__isl_keep isl_stream
*s
,
2312 __isl_take isl_map
*map
, struct vars
*v
, int rational
)
2314 struct isl_token
*tok
;
2316 tok
= isl_stream_next_token(s
);
2318 isl_stream_error(s
, NULL
, "unexpected EOF");
2321 if (tok
->type
== ':' ||
2322 (tok
->type
== ISL_TOKEN_OR
&& !strcmp(tok
->u
.s
, "|"))) {
2323 isl_token_free(tok
);
2324 map
= read_formula(s
, v
, map
, rational
);
2326 isl_stream_push_token(s
, tok
);
2334 static struct isl_obj
obj_read_poly(__isl_keep isl_stream
*s
,
2335 __isl_take isl_map
*map
, struct vars
*v
, int n
)
2337 struct isl_obj obj
= { isl_obj_pw_qpolynomial
, NULL
};
2338 isl_pw_qpolynomial
*pwqp
;
2339 struct isl_set
*set
;
2341 pwqp
= read_term(s
, map
, v
);
2342 map
= read_optional_formula(s
, map
, v
, 0);
2343 set
= isl_map_range(map
);
2345 pwqp
= isl_pw_qpolynomial_intersect_domain(pwqp
, set
);
2347 vars_drop(v
, v
->n
- n
);
2353 static struct isl_obj
obj_read_poly_or_fold(__isl_keep isl_stream
*s
,
2354 __isl_take isl_set
*set
, struct vars
*v
, int n
)
2356 struct isl_obj obj
= { isl_obj_pw_qpolynomial_fold
, NULL
};
2357 isl_pw_qpolynomial
*pwqp
;
2358 isl_pw_qpolynomial_fold
*pwf
= NULL
;
2360 if (!isl_stream_eat_if_available(s
, ISL_TOKEN_MAX
))
2361 return obj_read_poly(s
, set
, v
, n
);
2363 if (isl_stream_eat(s
, '('))
2366 pwqp
= read_term(s
, set
, v
);
2367 pwf
= isl_pw_qpolynomial_fold_from_pw_qpolynomial(isl_fold_max
, pwqp
);
2369 while (isl_stream_eat_if_available(s
, ',')) {
2370 isl_pw_qpolynomial_fold
*pwf_i
;
2371 pwqp
= read_term(s
, set
, v
);
2372 pwf_i
= isl_pw_qpolynomial_fold_from_pw_qpolynomial(isl_fold_max
,
2374 pwf
= isl_pw_qpolynomial_fold_fold(pwf
, pwf_i
);
2377 if (isl_stream_eat(s
, ')'))
2380 set
= read_optional_formula(s
, set
, v
, 0);
2381 pwf
= isl_pw_qpolynomial_fold_intersect_domain(pwf
, set
);
2383 vars_drop(v
, v
->n
- n
);
2389 isl_pw_qpolynomial_fold_free(pwf
);
2390 obj
.type
= isl_obj_none
;
2394 static int is_rational(__isl_keep isl_stream
*s
)
2396 struct isl_token
*tok
;
2398 tok
= isl_stream_next_token(s
);
2401 if (tok
->type
== ISL_TOKEN_RAT
&& isl_stream_next_token_is(s
, ':')) {
2402 isl_token_free(tok
);
2403 isl_stream_eat(s
, ':');
2407 isl_stream_push_token(s
, tok
);
2412 static struct isl_obj
obj_read_body(__isl_keep isl_stream
*s
,
2413 __isl_take isl_map
*map
, struct vars
*v
)
2415 struct isl_token
*tok
;
2416 struct isl_obj obj
= { isl_obj_set
, NULL
};
2420 rational
= is_rational(s
);
2422 map
= isl_map_set_rational(map
);
2424 if (isl_stream_next_token_is(s
, ':')) {
2425 obj
.type
= isl_obj_set
;
2426 obj
.v
= read_optional_formula(s
, map
, v
, rational
);
2430 if (!next_is_tuple(s
))
2431 return obj_read_poly_or_fold(s
, map
, v
, n
);
2433 map
= read_map_tuple(s
, map
, isl_dim_in
, v
, rational
, 0);
2436 tok
= isl_stream_next_token(s
);
2439 if (tok
->type
== ISL_TOKEN_TO
) {
2440 obj
.type
= isl_obj_map
;
2441 isl_token_free(tok
);
2442 if (!next_is_tuple(s
)) {
2443 isl_set
*set
= isl_map_domain(map
);
2444 return obj_read_poly_or_fold(s
, set
, v
, n
);
2446 map
= read_map_tuple(s
, map
, isl_dim_out
, v
, rational
, 0);
2450 map
= isl_map_domain(map
);
2451 isl_stream_push_token(s
, tok
);
2454 map
= read_optional_formula(s
, map
, v
, rational
);
2456 vars_drop(v
, v
->n
- n
);
2462 obj
.type
= isl_obj_none
;
2466 static struct isl_obj
to_union(isl_ctx
*ctx
, struct isl_obj obj
)
2468 if (obj
.type
== isl_obj_map
) {
2469 obj
.v
= isl_union_map_from_map(obj
.v
);
2470 obj
.type
= isl_obj_union_map
;
2471 } else if (obj
.type
== isl_obj_set
) {
2472 obj
.v
= isl_union_set_from_set(obj
.v
);
2473 obj
.type
= isl_obj_union_set
;
2474 } else if (obj
.type
== isl_obj_pw_qpolynomial
) {
2475 obj
.v
= isl_union_pw_qpolynomial_from_pw_qpolynomial(obj
.v
);
2476 obj
.type
= isl_obj_union_pw_qpolynomial
;
2477 } else if (obj
.type
== isl_obj_pw_qpolynomial_fold
) {
2478 obj
.v
= isl_union_pw_qpolynomial_fold_from_pw_qpolynomial_fold(obj
.v
);
2479 obj
.type
= isl_obj_union_pw_qpolynomial_fold
;
2481 isl_assert(ctx
, 0, goto error
);
2484 obj
.type
->free(obj
.v
);
2485 obj
.type
= isl_obj_none
;
2489 static struct isl_obj
obj_add(__isl_keep isl_stream
*s
,
2490 struct isl_obj obj1
, struct isl_obj obj2
)
2492 if (obj2
.type
== isl_obj_none
|| !obj2
.v
)
2494 if (obj1
.type
== isl_obj_set
&& obj2
.type
== isl_obj_union_set
)
2495 obj1
= to_union(s
->ctx
, obj1
);
2496 if (obj1
.type
== isl_obj_union_set
&& obj2
.type
== isl_obj_set
)
2497 obj2
= to_union(s
->ctx
, obj2
);
2498 if (obj1
.type
== isl_obj_map
&& obj2
.type
== isl_obj_union_map
)
2499 obj1
= to_union(s
->ctx
, obj1
);
2500 if (obj1
.type
== isl_obj_union_map
&& obj2
.type
== isl_obj_map
)
2501 obj2
= to_union(s
->ctx
, obj2
);
2502 if (obj1
.type
== isl_obj_pw_qpolynomial
&&
2503 obj2
.type
== isl_obj_union_pw_qpolynomial
)
2504 obj1
= to_union(s
->ctx
, obj1
);
2505 if (obj1
.type
== isl_obj_union_pw_qpolynomial
&&
2506 obj2
.type
== isl_obj_pw_qpolynomial
)
2507 obj2
= to_union(s
->ctx
, obj2
);
2508 if (obj1
.type
== isl_obj_pw_qpolynomial_fold
&&
2509 obj2
.type
== isl_obj_union_pw_qpolynomial_fold
)
2510 obj1
= to_union(s
->ctx
, obj1
);
2511 if (obj1
.type
== isl_obj_union_pw_qpolynomial_fold
&&
2512 obj2
.type
== isl_obj_pw_qpolynomial_fold
)
2513 obj2
= to_union(s
->ctx
, obj2
);
2514 if (obj1
.type
!= obj2
.type
) {
2515 isl_stream_error(s
, NULL
,
2516 "attempt to combine incompatible objects");
2519 if (!obj1
.type
->add
)
2520 isl_die(s
->ctx
, isl_error_internal
,
2521 "combination not supported on object type", goto error
);
2522 if (obj1
.type
== isl_obj_map
&& !isl_map_has_equal_space(obj1
.v
, obj2
.v
)) {
2523 obj1
= to_union(s
->ctx
, obj1
);
2524 obj2
= to_union(s
->ctx
, obj2
);
2526 if (obj1
.type
== isl_obj_set
&& !isl_set_has_equal_space(obj1
.v
, obj2
.v
)) {
2527 obj1
= to_union(s
->ctx
, obj1
);
2528 obj2
= to_union(s
->ctx
, obj2
);
2530 if (obj1
.type
== isl_obj_pw_qpolynomial
&&
2531 !isl_pw_qpolynomial_has_equal_space(obj1
.v
, obj2
.v
)) {
2532 obj1
= to_union(s
->ctx
, obj1
);
2533 obj2
= to_union(s
->ctx
, obj2
);
2535 if (obj1
.type
== isl_obj_pw_qpolynomial_fold
&&
2536 !isl_pw_qpolynomial_fold_has_equal_space(obj1
.v
, obj2
.v
)) {
2537 obj1
= to_union(s
->ctx
, obj1
);
2538 obj2
= to_union(s
->ctx
, obj2
);
2540 obj1
.v
= obj1
.type
->add(obj1
.v
, obj2
.v
);
2543 obj1
.type
->free(obj1
.v
);
2544 obj2
.type
->free(obj2
.v
);
2545 obj1
.type
= isl_obj_none
;
2550 /* Are the first two tokens on "s", "domain" (either as a string
2551 * or as an identifier) followed by ":"?
2553 static int next_is_domain_colon(__isl_keep isl_stream
*s
)
2555 struct isl_token
*tok
;
2559 tok
= isl_stream_next_token(s
);
2562 if (tok
->type
!= ISL_TOKEN_IDENT
&& tok
->type
!= ISL_TOKEN_STRING
) {
2563 isl_stream_push_token(s
, tok
);
2567 name
= isl_token_get_str(s
->ctx
, tok
);
2568 res
= !strcmp(name
, "domain") && isl_stream_next_token_is(s
, ':');
2571 isl_stream_push_token(s
, tok
);
2576 /* Do the first tokens on "s" look like a schedule?
2578 * The root of a schedule is always a domain node, so the first thing
2579 * we expect in the stream is a domain key, i.e., "domain" followed
2580 * by ":". If the schedule was printed in YAML flow style, then
2581 * we additionally expect a "{" to open the outer mapping.
2583 static int next_is_schedule(__isl_keep isl_stream
*s
)
2585 struct isl_token
*tok
;
2588 tok
= isl_stream_next_token(s
);
2591 if (tok
->type
!= '{') {
2592 isl_stream_push_token(s
, tok
);
2593 return next_is_domain_colon(s
);
2596 is_schedule
= next_is_domain_colon(s
);
2597 isl_stream_push_token(s
, tok
);
2602 /* Read an isl_schedule from "s" and store it in an isl_obj.
2604 static struct isl_obj
schedule_read(__isl_keep isl_stream
*s
)
2608 obj
.type
= isl_obj_schedule
;
2609 obj
.v
= isl_stream_read_schedule(s
);
2614 /* Read a disjunction of object bodies from "s".
2615 * That is, read the inside of the braces, but not the braces themselves.
2616 * "v" contains a description of the identifiers parsed so far.
2617 * "map" contains information about the parameters.
2619 static struct isl_obj
obj_read_disjuncts(__isl_keep isl_stream
*s
,
2620 struct vars
*v
, __isl_keep isl_map
*map
)
2622 struct isl_obj obj
= { isl_obj_set
, NULL
};
2624 if (isl_stream_next_token_is(s
, '}')) {
2625 obj
.type
= isl_obj_union_set
;
2626 obj
.v
= isl_union_set_empty(isl_map_get_space(map
));
2632 o
= obj_read_body(s
, isl_map_copy(map
), v
);
2636 obj
= obj_add(s
, obj
, o
);
2637 if (obj
.type
== isl_obj_none
|| !obj
.v
)
2639 if (!isl_stream_eat_if_available(s
, ';'))
2641 if (isl_stream_next_token_is(s
, '}'))
2648 static struct isl_obj
obj_read(__isl_keep isl_stream
*s
)
2650 isl_map
*map
= NULL
;
2651 struct isl_token
*tok
;
2652 struct vars
*v
= NULL
;
2653 struct isl_obj obj
= { isl_obj_set
, NULL
};
2655 if (next_is_schedule(s
))
2656 return schedule_read(s
);
2658 tok
= next_token(s
);
2660 isl_stream_error(s
, NULL
, "unexpected EOF");
2663 if (tok
->type
== ISL_TOKEN_VALUE
) {
2664 struct isl_token
*tok2
;
2665 struct isl_map
*map
;
2667 tok2
= isl_stream_next_token(s
);
2668 if (!tok2
|| tok2
->type
!= ISL_TOKEN_VALUE
||
2669 isl_int_is_neg(tok2
->u
.v
)) {
2671 isl_stream_push_token(s
, tok2
);
2672 obj
.type
= isl_obj_val
;
2673 obj
.v
= isl_val_int_from_isl_int(s
->ctx
, tok
->u
.v
);
2674 isl_token_free(tok
);
2677 isl_stream_push_token(s
, tok2
);
2678 isl_stream_push_token(s
, tok
);
2679 map
= map_read_polylib(s
);
2682 if (isl_map_may_be_set(map
))
2683 obj
.v
= isl_map_range(map
);
2685 obj
.type
= isl_obj_map
;
2690 v
= vars_new(s
->ctx
);
2692 isl_stream_push_token(s
, tok
);
2695 map
= isl_map_universe(isl_space_params_alloc(s
->ctx
, 0));
2696 if (tok
->type
== '[') {
2697 isl_stream_push_token(s
, tok
);
2698 map
= read_map_tuple(s
, map
, isl_dim_param
, v
, 0, 0);
2701 tok
= isl_stream_next_token(s
);
2702 if (!tok
|| tok
->type
!= ISL_TOKEN_TO
) {
2703 isl_stream_error(s
, tok
, "expecting '->'");
2705 isl_stream_push_token(s
, tok
);
2708 isl_token_free(tok
);
2709 tok
= isl_stream_next_token(s
);
2711 if (!tok
|| tok
->type
!= '{') {
2712 isl_stream_error(s
, tok
, "expecting '{'");
2714 isl_stream_push_token(s
, tok
);
2717 isl_token_free(tok
);
2719 tok
= isl_stream_next_token(s
);
2722 else if (tok
->type
== ISL_TOKEN_IDENT
&& !strcmp(tok
->u
.s
, "Sym")) {
2723 isl_token_free(tok
);
2724 if (isl_stream_eat(s
, '='))
2726 map
= read_map_tuple(s
, map
, isl_dim_param
, v
, 0, 1);
2730 isl_stream_push_token(s
, tok
);
2732 obj
= obj_read_disjuncts(s
, v
, map
);
2733 if (obj
.type
== isl_obj_none
|| !obj
.v
)
2736 tok
= isl_stream_next_token(s
);
2737 if (tok
&& tok
->type
== '}') {
2738 isl_token_free(tok
);
2740 isl_stream_error(s
, tok
, "unexpected isl_token");
2742 isl_token_free(tok
);
2752 obj
.type
->free(obj
.v
);
2759 struct isl_obj
isl_stream_read_obj(__isl_keep isl_stream
*s
)
2764 __isl_give isl_map
*isl_stream_read_map(__isl_keep isl_stream
*s
)
2770 isl_assert(s
->ctx
, obj
.type
== isl_obj_map
||
2771 obj
.type
== isl_obj_set
, goto error
);
2773 if (obj
.type
== isl_obj_set
)
2774 obj
.v
= isl_map_from_range(obj
.v
);
2778 obj
.type
->free(obj
.v
);
2782 __isl_give isl_set
*isl_stream_read_set(__isl_keep isl_stream
*s
)
2788 if (obj
.type
== isl_obj_map
&& isl_map_may_be_set(obj
.v
)) {
2789 obj
.v
= isl_map_range(obj
.v
);
2790 obj
.type
= isl_obj_set
;
2792 isl_assert(s
->ctx
, obj
.type
== isl_obj_set
, goto error
);
2797 obj
.type
->free(obj
.v
);
2801 __isl_give isl_union_map
*isl_stream_read_union_map(__isl_keep isl_stream
*s
)
2806 if (obj
.type
== isl_obj_map
) {
2807 obj
.type
= isl_obj_union_map
;
2808 obj
.v
= isl_union_map_from_map(obj
.v
);
2810 if (obj
.type
== isl_obj_set
) {
2811 obj
.type
= isl_obj_union_set
;
2812 obj
.v
= isl_union_set_from_set(obj
.v
);
2814 if (obj
.v
&& obj
.type
== isl_obj_union_set
&&
2815 isl_union_set_is_empty(obj
.v
))
2816 obj
.type
= isl_obj_union_map
;
2817 if (obj
.v
&& obj
.type
!= isl_obj_union_map
)
2818 isl_die(s
->ctx
, isl_error_invalid
, "invalid input", goto error
);
2822 obj
.type
->free(obj
.v
);
2826 /* Extract an isl_union_set from "obj".
2827 * This only works if the object was detected as either a set
2828 * (in which case it is converted to a union set) or a union set.
2830 static __isl_give isl_union_set
*extract_union_set(isl_ctx
*ctx
,
2833 if (obj
.type
== isl_obj_set
) {
2834 obj
.type
= isl_obj_union_set
;
2835 obj
.v
= isl_union_set_from_set(obj
.v
);
2838 isl_assert(ctx
, obj
.type
== isl_obj_union_set
, goto error
);
2842 obj
.type
->free(obj
.v
);
2846 /* Read an isl_union_set from "s".
2847 * First read a generic object and then try and extract
2848 * an isl_union_set from that.
2850 __isl_give isl_union_set
*isl_stream_read_union_set(__isl_keep isl_stream
*s
)
2855 return extract_union_set(s
->ctx
, obj
);
2858 static __isl_give isl_basic_map
*basic_map_read(__isl_keep isl_stream
*s
)
2861 struct isl_map
*map
;
2862 struct isl_basic_map
*bmap
;
2865 if (obj
.v
&& (obj
.type
!= isl_obj_map
&& obj
.type
!= isl_obj_set
))
2866 isl_die(s
->ctx
, isl_error_invalid
, "not a (basic) set or map",
2873 isl_die(s
->ctx
, isl_error_invalid
,
2874 "set or map description involves "
2875 "more than one disjunct", goto error
);
2878 bmap
= isl_basic_map_empty(isl_map_get_space(map
));
2880 bmap
= isl_basic_map_copy(map
->p
[0]);
2886 obj
.type
->free(obj
.v
);
2890 static __isl_give isl_basic_set
*basic_set_read(__isl_keep isl_stream
*s
)
2892 isl_basic_map
*bmap
;
2893 bmap
= basic_map_read(s
);
2896 if (!isl_basic_map_may_be_set(bmap
))
2897 isl_die(s
->ctx
, isl_error_invalid
,
2898 "input is not a set", goto error
);
2899 return isl_basic_map_range(bmap
);
2901 isl_basic_map_free(bmap
);
2905 __isl_give isl_basic_map
*isl_basic_map_read_from_file(isl_ctx
*ctx
,
2908 struct isl_basic_map
*bmap
;
2909 isl_stream
*s
= isl_stream_new_file(ctx
, input
);
2912 bmap
= basic_map_read(s
);
2917 __isl_give isl_basic_set
*isl_basic_set_read_from_file(isl_ctx
*ctx
,
2920 isl_basic_set
*bset
;
2921 isl_stream
*s
= isl_stream_new_file(ctx
, input
);
2924 bset
= basic_set_read(s
);
2929 struct isl_basic_map
*isl_basic_map_read_from_str(struct isl_ctx
*ctx
,
2932 struct isl_basic_map
*bmap
;
2933 isl_stream
*s
= isl_stream_new_str(ctx
, str
);
2936 bmap
= basic_map_read(s
);
2941 struct isl_basic_set
*isl_basic_set_read_from_str(struct isl_ctx
*ctx
,
2944 isl_basic_set
*bset
;
2945 isl_stream
*s
= isl_stream_new_str(ctx
, str
);
2948 bset
= basic_set_read(s
);
2953 __isl_give isl_map
*isl_map_read_from_file(struct isl_ctx
*ctx
,
2956 struct isl_map
*map
;
2957 isl_stream
*s
= isl_stream_new_file(ctx
, input
);
2960 map
= isl_stream_read_map(s
);
2965 __isl_give isl_map
*isl_map_read_from_str(struct isl_ctx
*ctx
,
2968 struct isl_map
*map
;
2969 isl_stream
*s
= isl_stream_new_str(ctx
, str
);
2972 map
= isl_stream_read_map(s
);
2977 __isl_give isl_set
*isl_set_read_from_file(struct isl_ctx
*ctx
,
2981 isl_stream
*s
= isl_stream_new_file(ctx
, input
);
2984 set
= isl_stream_read_set(s
);
2989 struct isl_set
*isl_set_read_from_str(struct isl_ctx
*ctx
,
2993 isl_stream
*s
= isl_stream_new_str(ctx
, str
);
2996 set
= isl_stream_read_set(s
);
3001 __isl_give isl_union_map
*isl_union_map_read_from_file(isl_ctx
*ctx
,
3004 isl_union_map
*umap
;
3005 isl_stream
*s
= isl_stream_new_file(ctx
, input
);
3008 umap
= isl_stream_read_union_map(s
);
3013 __isl_give isl_union_map
*isl_union_map_read_from_str(struct isl_ctx
*ctx
,
3016 isl_union_map
*umap
;
3017 isl_stream
*s
= isl_stream_new_str(ctx
, str
);
3020 umap
= isl_stream_read_union_map(s
);
3025 __isl_give isl_union_set
*isl_union_set_read_from_file(isl_ctx
*ctx
,
3028 isl_union_set
*uset
;
3029 isl_stream
*s
= isl_stream_new_file(ctx
, input
);
3032 uset
= isl_stream_read_union_set(s
);
3037 __isl_give isl_union_set
*isl_union_set_read_from_str(struct isl_ctx
*ctx
,
3040 isl_union_set
*uset
;
3041 isl_stream
*s
= isl_stream_new_str(ctx
, str
);
3044 uset
= isl_stream_read_union_set(s
);
3049 static __isl_give isl_vec
*isl_vec_read_polylib(__isl_keep isl_stream
*s
)
3051 struct isl_vec
*vec
= NULL
;
3052 struct isl_token
*tok
;
3056 tok
= isl_stream_next_token(s
);
3057 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
3058 isl_stream_error(s
, tok
, "expecting vector length");
3062 size
= isl_int_get_si(tok
->u
.v
);
3063 isl_token_free(tok
);
3065 vec
= isl_vec_alloc(s
->ctx
, size
);
3067 for (j
= 0; j
< size
; ++j
) {
3068 tok
= isl_stream_next_token(s
);
3069 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
3070 isl_stream_error(s
, tok
, "expecting constant value");
3073 isl_int_set(vec
->el
[j
], tok
->u
.v
);
3074 isl_token_free(tok
);
3079 isl_token_free(tok
);
3084 static __isl_give isl_vec
*vec_read(__isl_keep isl_stream
*s
)
3086 return isl_vec_read_polylib(s
);
3089 __isl_give isl_vec
*isl_vec_read_from_file(isl_ctx
*ctx
, FILE *input
)
3092 isl_stream
*s
= isl_stream_new_file(ctx
, input
);
3100 __isl_give isl_pw_qpolynomial
*isl_stream_read_pw_qpolynomial(
3101 __isl_keep isl_stream
*s
)
3107 isl_assert(s
->ctx
, obj
.type
== isl_obj_pw_qpolynomial
,
3112 obj
.type
->free(obj
.v
);
3116 __isl_give isl_pw_qpolynomial
*isl_pw_qpolynomial_read_from_str(isl_ctx
*ctx
,
3119 isl_pw_qpolynomial
*pwqp
;
3120 isl_stream
*s
= isl_stream_new_str(ctx
, str
);
3123 pwqp
= isl_stream_read_pw_qpolynomial(s
);
3128 __isl_give isl_pw_qpolynomial
*isl_pw_qpolynomial_read_from_file(isl_ctx
*ctx
,
3131 isl_pw_qpolynomial
*pwqp
;
3132 isl_stream
*s
= isl_stream_new_file(ctx
, input
);
3135 pwqp
= isl_stream_read_pw_qpolynomial(s
);
3140 /* Is the next token an identifer not in "v"?
3142 static int next_is_fresh_ident(__isl_keep isl_stream
*s
, struct vars
*v
)
3146 struct isl_token
*tok
;
3148 tok
= isl_stream_next_token(s
);
3151 fresh
= tok
->type
== ISL_TOKEN_IDENT
&& vars_pos(v
, tok
->u
.s
, -1) >= n
;
3152 isl_stream_push_token(s
, tok
);
3154 vars_drop(v
, v
->n
- n
);
3159 /* First read the domain of the affine expression, which may be
3160 * a parameter space or a set.
3161 * The tricky part is that we don't know if the domain is a set or not,
3162 * so when we are trying to read the domain, we may actually be reading
3163 * the affine expression itself (defined on a parameter domains)
3164 * If the tuple we are reading is named, we assume it's the domain.
3165 * Also, if inside the tuple, the first thing we find is a nested tuple
3166 * or a new identifier, we again assume it's the domain.
3167 * Finally, if the tuple is empty, then it must be the domain
3168 * since it does not contain an affine expression.
3169 * Otherwise, we assume we are reading an affine expression.
3171 static __isl_give isl_set
*read_aff_domain(__isl_keep isl_stream
*s
,
3172 __isl_take isl_set
*dom
, struct vars
*v
)
3174 struct isl_token
*tok
, *tok2
;
3177 tok
= isl_stream_next_token(s
);
3178 if (tok
&& (tok
->type
== ISL_TOKEN_IDENT
|| tok
->is_keyword
)) {
3179 isl_stream_push_token(s
, tok
);
3180 return read_map_tuple(s
, dom
, isl_dim_set
, v
, 0, 0);
3182 if (!tok
|| tok
->type
!= '[') {
3183 isl_stream_error(s
, tok
, "expecting '['");
3186 tok2
= isl_stream_next_token(s
);
3187 is_empty
= tok2
&& tok2
->type
== ']';
3189 isl_stream_push_token(s
, tok2
);
3190 if (is_empty
|| next_is_tuple(s
) || next_is_fresh_ident(s
, v
)) {
3191 isl_stream_push_token(s
, tok
);
3192 dom
= read_map_tuple(s
, dom
, isl_dim_set
, v
, 0, 0);
3194 isl_stream_push_token(s
, tok
);
3199 isl_stream_push_token(s
, tok
);
3204 /* Read an affine expression from "s".
3206 __isl_give isl_aff
*isl_stream_read_aff(__isl_keep isl_stream
*s
)
3212 ma
= isl_stream_read_multi_aff(s
);
3213 dim
= isl_multi_aff_dim(ma
, isl_dim_out
);
3217 isl_die(s
->ctx
, isl_error_invalid
,
3218 "expecting single affine expression",
3221 aff
= isl_multi_aff_get_aff(ma
, 0);
3222 isl_multi_aff_free(ma
);
3225 isl_multi_aff_free(ma
);
3229 /* Read a piecewise affine expression from "s" with domain (space) "dom".
3231 static __isl_give isl_pw_aff
*read_pw_aff_with_dom(__isl_keep isl_stream
*s
,
3232 __isl_take isl_set
*dom
, struct vars
*v
)
3234 isl_pw_aff
*pwaff
= NULL
;
3236 if (!isl_set_is_params(dom
) && isl_stream_eat(s
, ISL_TOKEN_TO
))
3239 if (isl_stream_eat(s
, '['))
3242 pwaff
= accept_affine(s
, isl_set_get_space(dom
), v
);
3244 if (isl_stream_eat(s
, ']'))
3247 dom
= read_optional_formula(s
, dom
, v
, 0);
3248 pwaff
= isl_pw_aff_intersect_domain(pwaff
, dom
);
3253 isl_pw_aff_free(pwaff
);
3257 __isl_give isl_pw_aff
*isl_stream_read_pw_aff(__isl_keep isl_stream
*s
)
3260 isl_set
*dom
= NULL
;
3262 isl_pw_aff
*pa
= NULL
;
3265 v
= vars_new(s
->ctx
);
3269 dom
= isl_set_universe(isl_space_params_alloc(s
->ctx
, 0));
3270 if (next_is_tuple(s
)) {
3271 dom
= read_map_tuple(s
, dom
, isl_dim_param
, v
, 1, 0);
3272 if (isl_stream_eat(s
, ISL_TOKEN_TO
))
3275 if (isl_stream_eat(s
, '{'))
3279 aff_dom
= read_aff_domain(s
, isl_set_copy(dom
), v
);
3280 pa
= read_pw_aff_with_dom(s
, aff_dom
, v
);
3281 vars_drop(v
, v
->n
- n
);
3283 while (isl_stream_eat_if_available(s
, ';')) {
3287 aff_dom
= read_aff_domain(s
, isl_set_copy(dom
), v
);
3288 pa_i
= read_pw_aff_with_dom(s
, aff_dom
, v
);
3289 vars_drop(v
, v
->n
- n
);
3291 pa
= isl_pw_aff_union_add(pa
, pa_i
);
3294 if (isl_stream_eat(s
, '}'))
3303 isl_pw_aff_free(pa
);
3307 __isl_give isl_aff
*isl_aff_read_from_str(isl_ctx
*ctx
, const char *str
)
3310 isl_stream
*s
= isl_stream_new_str(ctx
, str
);
3313 aff
= isl_stream_read_aff(s
);
3318 __isl_give isl_pw_aff
*isl_pw_aff_read_from_str(isl_ctx
*ctx
, const char *str
)
3321 isl_stream
*s
= isl_stream_new_str(ctx
, str
);
3324 pa
= isl_stream_read_pw_aff(s
);
3329 /* Extract an isl_multi_pw_aff with domain space "dom_space"
3330 * from a tuple "tuple" read by read_tuple.
3332 * Note that the function read_tuple accepts tuples where some output or
3333 * set dimensions are defined in terms of other output or set dimensions
3334 * since this function is also used to read maps. As a special case,
3335 * read_tuple also accept dimensions that are defined in terms of themselves
3336 * (i.e., that are not defined).
3337 * These cases are not allowed when extracting an isl_multi_pw_aff so check
3338 * that the definitions of the output/set dimensions do not involve any
3339 * output/set dimensions.
3340 * Finally, drop the output dimensions from the domain of the result
3341 * of read_tuple (which is of the form [input, output] -> [output],
3342 * with anonymous domain) and reset the space.
3344 static __isl_give isl_multi_pw_aff
*extract_mpa_from_tuple(
3345 __isl_take isl_space
*dom_space
, __isl_keep isl_multi_pw_aff
*tuple
)
3350 isl_multi_pw_aff
*mpa
;
3352 n
= isl_multi_pw_aff_dim(tuple
, isl_dim_out
);
3353 dim
= isl_space_dim(dom_space
, isl_dim_all
);
3354 if (n
< 0 || dim
< 0)
3355 dom_space
= isl_space_free(dom_space
);
3356 space
= isl_space_range(isl_multi_pw_aff_get_space(tuple
));
3357 space
= isl_space_align_params(space
, isl_space_copy(dom_space
));
3358 if (!isl_space_is_params(dom_space
))
3359 space
= isl_space_map_from_domain_and_range(
3360 isl_space_copy(dom_space
), space
);
3361 isl_space_free(dom_space
);
3362 mpa
= isl_multi_pw_aff_alloc(space
);
3364 for (i
= 0; i
< n
; ++i
) {
3366 pa
= isl_multi_pw_aff_get_pw_aff(tuple
, i
);
3368 return isl_multi_pw_aff_free(mpa
);
3369 if (isl_pw_aff_involves_dims(pa
, isl_dim_in
, dim
, i
+ 1)) {
3370 isl_ctx
*ctx
= isl_pw_aff_get_ctx(pa
);
3371 isl_pw_aff_free(pa
);
3372 isl_die(ctx
, isl_error_invalid
,
3373 "not an affine expression",
3374 return isl_multi_pw_aff_free(mpa
));
3376 pa
= isl_pw_aff_drop_dims(pa
, isl_dim_in
, dim
, n
);
3377 space
= isl_multi_pw_aff_get_domain_space(mpa
);
3378 pa
= isl_pw_aff_reset_domain_space(pa
, space
);
3379 mpa
= isl_multi_pw_aff_set_pw_aff(mpa
, i
, pa
);
3385 /* Read a tuple of affine expressions, together with optional constraints
3386 * on the domain from "s". "dom" represents the initial constraints
3389 * The isl_multi_aff may live in either a set or a map space.
3390 * First read the first tuple and check if it is followed by a "->".
3391 * If so, convert the tuple into the domain of the isl_multi_pw_aff and
3392 * read in the next tuple. This tuple (or the first tuple if it was
3393 * not followed by a "->") is then converted into an isl_multi_pw_aff
3394 * through a call to extract_mpa_from_tuple.
3395 * The result is converted to an isl_pw_multi_aff and
3396 * its domain is intersected with the domain.
3398 static __isl_give isl_pw_multi_aff
*read_conditional_multi_aff(
3399 __isl_keep isl_stream
*s
, __isl_take isl_set
*dom
, struct vars
*v
)
3401 isl_multi_pw_aff
*tuple
;
3402 isl_multi_pw_aff
*mpa
;
3403 isl_pw_multi_aff
*pma
;
3406 tuple
= read_tuple(s
, v
, 0, 0);
3409 if (isl_stream_eat_if_available(s
, ISL_TOKEN_TO
)) {
3410 isl_map
*map
= map_from_tuple(tuple
, dom
, isl_dim_in
, v
, 0);
3411 dom
= isl_map_domain(map
);
3412 tuple
= read_tuple(s
, v
, 0, 0);
3417 dom
= read_optional_formula(s
, dom
, v
, 0);
3419 vars_drop(v
, v
->n
- n
);
3421 mpa
= extract_mpa_from_tuple(isl_set_get_space(dom
), tuple
);
3422 isl_multi_pw_aff_free(tuple
);
3423 pma
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
3424 pma
= isl_pw_multi_aff_intersect_domain(pma
, dom
);
3432 /* Read an isl_pw_multi_aff from "s".
3434 * In particular, first read the parameters and then read a sequence
3435 * of one or more tuples of affine expressions with optional conditions and
3438 __isl_give isl_pw_multi_aff
*isl_stream_read_pw_multi_aff(
3439 __isl_keep isl_stream
*s
)
3443 isl_pw_multi_aff
*pma
= NULL
;
3445 v
= vars_new(s
->ctx
);
3449 dom
= isl_set_universe(isl_space_params_alloc(s
->ctx
, 0));
3450 if (next_is_tuple(s
)) {
3451 dom
= read_map_tuple(s
, dom
, isl_dim_param
, v
, 1, 0);
3452 if (isl_stream_eat(s
, ISL_TOKEN_TO
))
3455 if (isl_stream_eat(s
, '{'))
3458 pma
= read_conditional_multi_aff(s
, isl_set_copy(dom
), v
);
3460 while (isl_stream_eat_if_available(s
, ';')) {
3461 isl_pw_multi_aff
*pma2
;
3463 pma2
= read_conditional_multi_aff(s
, isl_set_copy(dom
), v
);
3464 pma
= isl_pw_multi_aff_union_add(pma
, pma2
);
3469 if (isl_stream_eat(s
, '}'))
3476 isl_pw_multi_aff_free(pma
);
3482 __isl_give isl_pw_multi_aff
*isl_pw_multi_aff_read_from_str(isl_ctx
*ctx
,
3485 isl_pw_multi_aff
*pma
;
3486 isl_stream
*s
= isl_stream_new_str(ctx
, str
);
3489 pma
= isl_stream_read_pw_multi_aff(s
);
3494 /* Read an isl_union_pw_multi_aff from "s".
3495 * We currently read a generic object and if it turns out to be a set or
3496 * a map, we convert that to an isl_union_pw_multi_aff.
3497 * It would be more efficient if we were to construct
3498 * the isl_union_pw_multi_aff directly.
3500 __isl_give isl_union_pw_multi_aff
*isl_stream_read_union_pw_multi_aff(
3501 __isl_keep isl_stream
*s
)
3509 if (obj
.type
== isl_obj_map
|| obj
.type
== isl_obj_set
)
3510 obj
= to_union(s
->ctx
, obj
);
3511 if (obj
.type
== isl_obj_union_map
)
3512 return isl_union_pw_multi_aff_from_union_map(obj
.v
);
3513 if (obj
.type
== isl_obj_union_set
)
3514 return isl_union_pw_multi_aff_from_union_set(obj
.v
);
3516 obj
.type
->free(obj
.v
);
3517 isl_die(s
->ctx
, isl_error_invalid
, "unexpected object type",
3521 /* Read an isl_union_pw_multi_aff from "str".
3523 __isl_give isl_union_pw_multi_aff
*isl_union_pw_multi_aff_read_from_str(
3524 isl_ctx
*ctx
, const char *str
)
3526 isl_union_pw_multi_aff
*upma
;
3527 isl_stream
*s
= isl_stream_new_str(ctx
, str
);
3530 upma
= isl_stream_read_union_pw_multi_aff(s
);
3535 /* Assuming "pa" represents a single affine expression defined on a universe
3536 * domain, extract this affine expression.
3538 static __isl_give isl_aff
*aff_from_pw_aff(__isl_take isl_pw_aff
*pa
)
3545 isl_die(isl_pw_aff_get_ctx(pa
), isl_error_invalid
,
3546 "expecting single affine expression",
3548 if (!isl_set_plain_is_universe(pa
->p
[0].set
))
3549 isl_die(isl_pw_aff_get_ctx(pa
), isl_error_invalid
,
3550 "expecting universe domain",
3553 aff
= isl_aff_copy(pa
->p
[0].aff
);
3554 isl_pw_aff_free(pa
);
3557 isl_pw_aff_free(pa
);
3564 #include <isl_multi_read_no_explicit_domain_templ.c>
3569 #include <isl_multi_read_no_explicit_domain_templ.c>
3571 /* Read a multi-affine expression from "s".
3572 * If the multi-affine expression has a domain, then the tuple
3573 * representing this domain cannot involve any affine expressions.
3574 * The tuple representing the actual expressions needs to consist
3575 * of only affine expressions. Moreover, these expressions can
3576 * only depend on parameters and input dimensions and not on other
3577 * output dimensions.
3579 __isl_give isl_multi_aff
*isl_stream_read_multi_aff(__isl_keep isl_stream
*s
)
3582 isl_set
*dom
= NULL
;
3583 isl_multi_pw_aff
*tuple
= NULL
;
3586 isl_space
*space
, *dom_space
;
3587 isl_multi_aff
*ma
= NULL
;
3589 v
= vars_new(s
->ctx
);
3593 dom
= isl_set_universe(isl_space_params_alloc(s
->ctx
, 0));
3594 if (next_is_tuple(s
)) {
3595 dom
= read_map_tuple(s
, dom
, isl_dim_param
, v
, 1, 0);
3596 if (isl_stream_eat(s
, ISL_TOKEN_TO
))
3599 if (!isl_set_plain_is_universe(dom
))
3600 isl_die(s
->ctx
, isl_error_invalid
,
3601 "expecting universe parameter domain", goto error
);
3602 if (isl_stream_eat(s
, '{'))
3605 tuple
= read_tuple(s
, v
, 0, 0);
3608 if (isl_stream_eat_if_available(s
, ISL_TOKEN_TO
)) {
3613 has_expr
= tuple_has_expr(tuple
);
3617 isl_die(s
->ctx
, isl_error_invalid
,
3618 "expecting universe domain", goto error
);
3619 space
= isl_space_range(isl_multi_pw_aff_get_space(tuple
));
3620 set
= isl_set_universe(space
);
3621 dom
= isl_set_intersect_params(set
, dom
);
3622 isl_multi_pw_aff_free(tuple
);
3623 tuple
= read_tuple(s
, v
, 0, 0);
3628 if (isl_stream_eat(s
, '}'))
3631 n
= isl_multi_pw_aff_dim(tuple
, isl_dim_out
);
3632 dim
= isl_set_dim(dom
, isl_dim_all
);
3633 if (n
< 0 || dim
< 0)
3635 dom_space
= isl_set_get_space(dom
);
3636 space
= isl_space_range(isl_multi_pw_aff_get_space(tuple
));
3637 space
= isl_space_align_params(space
, isl_space_copy(dom_space
));
3638 if (!isl_space_is_params(dom_space
))
3639 space
= isl_space_map_from_domain_and_range(
3640 isl_space_copy(dom_space
), space
);
3641 isl_space_free(dom_space
);
3642 ma
= isl_multi_aff_alloc(space
);
3644 for (i
= 0; i
< n
; ++i
) {
3647 pa
= isl_multi_pw_aff_get_pw_aff(tuple
, i
);
3648 aff
= aff_from_pw_aff(pa
);
3651 if (isl_aff_involves_dims(aff
, isl_dim_in
, dim
, i
+ 1)) {
3653 isl_die(s
->ctx
, isl_error_invalid
,
3654 "not an affine expression", goto error
);
3656 aff
= isl_aff_drop_dims(aff
, isl_dim_in
, dim
, n
);
3657 space
= isl_multi_aff_get_domain_space(ma
);
3658 aff
= isl_aff_reset_domain_space(aff
, space
);
3659 ma
= isl_multi_aff_set_aff(ma
, i
, aff
);
3662 isl_multi_pw_aff_free(tuple
);
3667 isl_multi_pw_aff_free(tuple
);
3670 isl_multi_aff_free(ma
);
3674 __isl_give isl_multi_aff
*isl_multi_aff_read_from_str(isl_ctx
*ctx
,
3677 isl_multi_aff
*maff
;
3678 isl_stream
*s
= isl_stream_new_str(ctx
, str
);
3681 maff
= isl_stream_read_multi_aff(s
);
3686 /* Read an isl_multi_pw_aff from "s".
3688 * The input format is similar to that of map, except that any conditions
3689 * on the domains should be specified inside the tuple since each
3690 * piecewise affine expression may have a different domain.
3691 * However, additional, shared conditions can also be specified.
3692 * This is especially useful for setting the explicit domain
3693 * of a zero-dimensional isl_multi_pw_aff.
3695 * Since we do not know in advance if the isl_multi_pw_aff lives
3696 * in a set or a map space, we first read the first tuple and check
3697 * if it is followed by a "->". If so, we convert the tuple into
3698 * the domain of the isl_multi_pw_aff and read in the next tuple.
3699 * This tuple (or the first tuple if it was not followed by a "->")
3700 * is then converted into the isl_multi_pw_aff through a call
3701 * to extract_mpa_from_tuple and the domain of the result
3702 * is intersected with the domain.
3704 __isl_give isl_multi_pw_aff
*isl_stream_read_multi_pw_aff(
3705 __isl_keep isl_stream
*s
)
3708 isl_set
*dom
= NULL
;
3709 isl_multi_pw_aff
*tuple
= NULL
;
3710 isl_multi_pw_aff
*mpa
= NULL
;
3712 v
= vars_new(s
->ctx
);
3716 dom
= isl_set_universe(isl_space_params_alloc(s
->ctx
, 0));
3717 if (next_is_tuple(s
)) {
3718 dom
= read_map_tuple(s
, dom
, isl_dim_param
, v
, 1, 0);
3719 if (isl_stream_eat(s
, ISL_TOKEN_TO
))
3722 if (isl_stream_eat(s
, '{'))
3725 tuple
= read_tuple(s
, v
, 0, 0);
3728 if (isl_stream_eat_if_available(s
, ISL_TOKEN_TO
)) {
3729 isl_map
*map
= map_from_tuple(tuple
, dom
, isl_dim_in
, v
, 0);
3730 dom
= isl_map_domain(map
);
3731 tuple
= read_tuple(s
, v
, 0, 0);
3736 if (isl_stream_eat_if_available(s
, ':'))
3737 dom
= read_formula(s
, v
, dom
, 0);
3739 if (isl_stream_eat(s
, '}'))
3742 mpa
= extract_mpa_from_tuple(isl_set_get_space(dom
), tuple
);
3744 isl_multi_pw_aff_free(tuple
);
3746 mpa
= isl_multi_pw_aff_intersect_domain(mpa
, dom
);
3749 isl_multi_pw_aff_free(tuple
);
3752 isl_multi_pw_aff_free(mpa
);
3756 /* Read an isl_multi_pw_aff from "str".
3758 __isl_give isl_multi_pw_aff
*isl_multi_pw_aff_read_from_str(isl_ctx
*ctx
,
3761 isl_multi_pw_aff
*mpa
;
3762 isl_stream
*s
= isl_stream_new_str(ctx
, str
);
3765 mpa
= isl_stream_read_multi_pw_aff(s
);
3770 /* Read the body of an isl_union_pw_aff from "s" with parameter domain "dom".
3772 static __isl_give isl_union_pw_aff
*read_union_pw_aff_with_dom(
3773 __isl_keep isl_stream
*s
, __isl_take isl_set
*dom
, struct vars
*v
)
3776 isl_union_pw_aff
*upa
= NULL
;
3781 aff_dom
= read_aff_domain(s
, isl_set_copy(dom
), v
);
3782 pa
= read_pw_aff_with_dom(s
, aff_dom
, v
);
3783 vars_drop(v
, v
->n
- n
);
3785 upa
= isl_union_pw_aff_from_pw_aff(pa
);
3787 while (isl_stream_eat_if_available(s
, ';')) {
3789 isl_union_pw_aff
*upa_i
;
3792 aff_dom
= read_aff_domain(s
, isl_set_copy(dom
), v
);
3793 pa_i
= read_pw_aff_with_dom(s
, aff_dom
, v
);
3794 vars_drop(v
, v
->n
- n
);
3796 upa_i
= isl_union_pw_aff_from_pw_aff(pa_i
);
3797 upa
= isl_union_pw_aff_union_add(upa
, upa_i
);
3804 /* Read an isl_union_pw_aff from "s".
3806 * First check if there are any paramters, then read in the opening brace
3807 * and use read_union_pw_aff_with_dom to read in the body of
3808 * the isl_union_pw_aff. Finally, read the closing brace.
3810 __isl_give isl_union_pw_aff
*isl_stream_read_union_pw_aff(
3811 __isl_keep isl_stream
*s
)
3815 isl_union_pw_aff
*upa
= NULL
;
3817 v
= vars_new(s
->ctx
);
3821 dom
= isl_set_universe(isl_space_params_alloc(s
->ctx
, 0));
3822 if (next_is_tuple(s
)) {
3823 dom
= read_map_tuple(s
, dom
, isl_dim_param
, v
, 1, 0);
3824 if (isl_stream_eat(s
, ISL_TOKEN_TO
))
3827 if (isl_stream_eat(s
, '{'))
3830 upa
= read_union_pw_aff_with_dom(s
, isl_set_copy(dom
), v
);
3832 if (isl_stream_eat(s
, '}'))
3841 isl_union_pw_aff_free(upa
);
3845 /* Read an isl_union_pw_aff from "str".
3847 __isl_give isl_union_pw_aff
*isl_union_pw_aff_read_from_str(isl_ctx
*ctx
,
3850 isl_union_pw_aff
*upa
;
3851 isl_stream
*s
= isl_stream_new_str(ctx
, str
);
3854 upa
= isl_stream_read_union_pw_aff(s
);
3859 /* This function is called for each element in a tuple inside
3860 * isl_stream_read_multi_union_pw_aff.
3862 * Read a '{', the union piecewise affine expression body and a '}' and
3863 * add the isl_union_pw_aff to *list.
3865 static __isl_give isl_space
*read_union_pw_aff_el(__isl_keep isl_stream
*s
,
3866 struct vars
*v
, __isl_take isl_space
*space
, int rational
, void *user
)
3869 isl_union_pw_aff
*upa
;
3870 isl_union_pw_aff_list
**list
= (isl_union_pw_aff_list
**) user
;
3872 dom
= isl_set_universe(isl_space_params(isl_space_copy(space
)));
3873 if (isl_stream_eat(s
, '{'))
3875 upa
= read_union_pw_aff_with_dom(s
, dom
, v
);
3876 *list
= isl_union_pw_aff_list_add(*list
, upa
);
3877 if (isl_stream_eat(s
, '}'))
3878 return isl_space_free(space
);
3880 return isl_space_free(space
);
3884 return isl_space_free(space
);
3887 /* Do the next tokens in "s" correspond to an empty tuple?
3888 * In particular, does the stream start with a '[', followed by a ']',
3889 * not followed by a "->"?
3891 static int next_is_empty_tuple(__isl_keep isl_stream
*s
)
3893 struct isl_token
*tok
, *tok2
, *tok3
;
3894 int is_empty_tuple
= 0;
3896 tok
= isl_stream_next_token(s
);
3899 if (tok
->type
!= '[') {
3900 isl_stream_push_token(s
, tok
);
3904 tok2
= isl_stream_next_token(s
);
3905 if (tok2
&& tok2
->type
== ']') {
3906 tok3
= isl_stream_next_token(s
);
3907 is_empty_tuple
= !tok
|| tok
->type
!= ISL_TOKEN_TO
;
3909 isl_stream_push_token(s
, tok3
);
3912 isl_stream_push_token(s
, tok2
);
3913 isl_stream_push_token(s
, tok
);
3915 return is_empty_tuple
;
3918 /* Do the next tokens in "s" correspond to a tuple of parameters?
3919 * In particular, does the stream start with a '[' that is not
3920 * followed by a '{' or a nested tuple?
3922 static int next_is_param_tuple(__isl_keep isl_stream
*s
)
3924 struct isl_token
*tok
, *tok2
;
3927 tok
= isl_stream_next_token(s
);
3930 if (tok
->type
!= '[' || next_is_tuple(s
)) {
3931 isl_stream_push_token(s
, tok
);
3935 tok2
= isl_stream_next_token(s
);
3936 is_tuple
= tok2
&& tok2
->type
!= '{';
3938 isl_stream_push_token(s
, tok2
);
3939 isl_stream_push_token(s
, tok
);
3944 /* Read the core of a body of an isl_multi_union_pw_aff from "s",
3945 * i.e., everything except the parameter specification and
3946 * without shared domain constraints.
3947 * "v" contains a description of the identifiers parsed so far.
3948 * The parameters, if any, are specified by "space".
3950 * The body is of the form
3952 * [{ [..] : ... ; [..] : ... }, { [..] : ... ; [..] : ... }]
3954 * Read the tuple, collecting the individual isl_union_pw_aff
3955 * elements in a list and construct the result from the tuple space and
3958 static __isl_give isl_multi_union_pw_aff
*read_multi_union_pw_aff_body_core(
3959 __isl_keep isl_stream
*s
, struct vars
*v
, __isl_take isl_space
*space
)
3961 isl_union_pw_aff_list
*list
;
3962 isl_multi_union_pw_aff
*mupa
;
3964 list
= isl_union_pw_aff_list_alloc(s
->ctx
, 0);
3965 space
= read_tuple_space(s
, v
, space
, 1, 0,
3966 &read_union_pw_aff_el
, &list
);
3967 mupa
= isl_multi_union_pw_aff_from_union_pw_aff_list(space
, list
);
3972 /* Read the body of an isl_union_set from "s",
3973 * i.e., everything except the parameter specification.
3974 * "v" contains a description of the identifiers parsed so far.
3975 * The parameters, if any, are specified by "space".
3977 * First read a generic disjunction of object bodies and then try and extract
3978 * an isl_union_set from that.
3980 static __isl_give isl_union_set
*read_union_set_body(__isl_keep isl_stream
*s
,
3981 struct vars
*v
, __isl_take isl_space
*space
)
3983 struct isl_obj obj
= { isl_obj_set
, NULL
};
3986 map
= isl_set_universe(space
);
3987 if (isl_stream_eat(s
, '{') < 0)
3989 obj
= obj_read_disjuncts(s
, v
, map
);
3990 if (isl_stream_eat(s
, '}') < 0)
3994 return extract_union_set(s
->ctx
, obj
);
3996 obj
.type
->free(obj
.v
);
4001 /* Read the body of an isl_multi_union_pw_aff from "s",
4002 * i.e., everything except the parameter specification.
4003 * "v" contains a description of the identifiers parsed so far.
4004 * The parameters, if any, are specified by "space".
4006 * In particular, handle the special case with shared domain constraints.
4007 * These are specified as
4011 * and are especially useful for setting the explicit domain
4012 * of a zero-dimensional isl_multi_union_pw_aff.
4013 * The core isl_multi_union_pw_aff body ([...]) is read by
4014 * read_multi_union_pw_aff_body_core.
4016 static __isl_give isl_multi_union_pw_aff
*read_multi_union_pw_aff_body(
4017 __isl_keep isl_stream
*s
, struct vars
*v
, __isl_take isl_space
*space
)
4019 isl_multi_union_pw_aff
*mupa
;
4021 if (!isl_stream_next_token_is(s
, '('))
4022 return read_multi_union_pw_aff_body_core(s
, v
, space
);
4024 if (isl_stream_eat(s
, '(') < 0)
4026 mupa
= read_multi_union_pw_aff_body_core(s
, v
, isl_space_copy(space
));
4027 if (isl_stream_eat_if_available(s
, ':')) {
4030 dom
= read_union_set_body(s
, v
, space
);
4031 mupa
= isl_multi_union_pw_aff_intersect_domain(mupa
, dom
);
4033 isl_space_free(space
);
4035 if (isl_stream_eat(s
, ')') < 0)
4036 return isl_multi_union_pw_aff_free(mupa
);
4040 isl_space_free(space
);
4044 /* Read an isl_multi_union_pw_aff from "s".
4046 * The input has the form
4048 * [{ [..] : ... ; [..] : ... }, { [..] : ... ; [..] : ... }]
4052 * [..] -> [{ [..] : ... ; [..] : ... }, { [..] : ... ; [..] : ... }]
4054 * Additionally, a shared domain may be specified as
4060 * [..] -> ([..] : ...)
4062 * The first case is handled by the caller, the second case
4063 * is handled by read_multi_union_pw_aff_body.
4065 * We first check for the special case of an empty tuple "[]".
4066 * Then we check if there are any parameters.
4067 * Finally, read the tuple and construct the result.
4069 static __isl_give isl_multi_union_pw_aff
*read_multi_union_pw_aff_core(
4070 __isl_keep isl_stream
*s
)
4073 isl_set
*dom
= NULL
;
4075 isl_multi_union_pw_aff
*mupa
= NULL
;
4077 if (next_is_empty_tuple(s
)) {
4078 if (isl_stream_eat(s
, '['))
4080 if (isl_stream_eat(s
, ']'))
4082 space
= isl_space_set_alloc(s
->ctx
, 0, 0);
4083 return isl_multi_union_pw_aff_zero(space
);
4086 v
= vars_new(s
->ctx
);
4090 dom
= isl_set_universe(isl_space_params_alloc(s
->ctx
, 0));
4091 if (next_is_param_tuple(s
)) {
4092 dom
= read_map_tuple(s
, dom
, isl_dim_param
, v
, 1, 0);
4093 if (isl_stream_eat(s
, ISL_TOKEN_TO
))
4096 space
= isl_set_get_space(dom
);
4098 mupa
= read_multi_union_pw_aff_body(s
, v
, space
);
4106 isl_multi_union_pw_aff_free(mupa
);
4110 /* Read an isl_multi_union_pw_aff from "s".
4112 * In particular, handle the special case with shared domain constraints.
4113 * These are specified as
4117 * and are especially useful for setting the explicit domain
4118 * of a zero-dimensional isl_multi_union_pw_aff.
4119 * The core isl_multi_union_pw_aff ([...]) is read by
4120 * read_multi_union_pw_aff_core.
4122 __isl_give isl_multi_union_pw_aff
*isl_stream_read_multi_union_pw_aff(
4123 __isl_keep isl_stream
*s
)
4125 isl_multi_union_pw_aff
*mupa
;
4127 if (!isl_stream_next_token_is(s
, '('))
4128 return read_multi_union_pw_aff_core(s
);
4130 if (isl_stream_eat(s
, '(') < 0)
4132 mupa
= read_multi_union_pw_aff_core(s
);
4133 if (isl_stream_eat_if_available(s
, ':')) {
4136 dom
= isl_stream_read_union_set(s
);
4137 mupa
= isl_multi_union_pw_aff_intersect_domain(mupa
, dom
);
4139 if (isl_stream_eat(s
, ')') < 0)
4140 return isl_multi_union_pw_aff_free(mupa
);
4144 /* Read an isl_multi_union_pw_aff from "str".
4146 __isl_give isl_multi_union_pw_aff
*isl_multi_union_pw_aff_read_from_str(
4147 isl_ctx
*ctx
, const char *str
)
4149 isl_multi_union_pw_aff
*mupa
;
4150 isl_stream
*s
= isl_stream_new_str(ctx
, str
);
4153 mupa
= isl_stream_read_multi_union_pw_aff(s
);
4158 __isl_give isl_union_pw_qpolynomial
*isl_stream_read_union_pw_qpolynomial(
4159 __isl_keep isl_stream
*s
)
4164 if (obj
.type
== isl_obj_pw_qpolynomial
) {
4165 obj
.type
= isl_obj_union_pw_qpolynomial
;
4166 obj
.v
= isl_union_pw_qpolynomial_from_pw_qpolynomial(obj
.v
);
4169 isl_assert(s
->ctx
, obj
.type
== isl_obj_union_pw_qpolynomial
,
4174 obj
.type
->free(obj
.v
);
4178 __isl_give isl_union_pw_qpolynomial
*isl_union_pw_qpolynomial_read_from_str(
4179 isl_ctx
*ctx
, const char *str
)
4181 isl_union_pw_qpolynomial
*upwqp
;
4182 isl_stream
*s
= isl_stream_new_str(ctx
, str
);
4185 upwqp
= isl_stream_read_union_pw_qpolynomial(s
);