2 * Copyright 2011 Sven Verdoolaege
3 * Copyright 2012-2013 Ecole Normale Superieure
5 * Use of this software is governed by the MIT license
7 * Written by Sven Verdoolaege,
8 * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
12 #include <isl_space_private.h>
13 #include <isl_val_private.h>
15 #include <isl_reordering.h>
17 #include <isl_multi_macro.h>
19 #define MULTI_NAME(BASE) "isl_multi_" #BASE
20 #define xLIST(EL) EL ## _list
21 #define LIST(EL) xLIST(EL)
23 isl_ctx
*FN(MULTI(BASE
),get_ctx
)(__isl_keep
MULTI(BASE
) *multi
)
25 return multi
? isl_space_get_ctx(multi
->space
) : NULL
;
28 __isl_give isl_space
*FN(MULTI(BASE
),get_space
)(__isl_keep
MULTI(BASE
) *multi
)
30 return multi
? isl_space_copy(multi
->space
) : NULL
;
33 /* Return the position of the dimension of the given type and name
35 * Return -1 if no such dimension can be found.
37 int FN(MULTI(BASE
),find_dim_by_name
)(__isl_keep
MULTI(BASE
) *multi
,
38 enum isl_dim_type type
, const char *name
)
42 return isl_space_find_dim_by_name(multi
->space
, type
, name
);
45 __isl_give isl_space
*FN(MULTI(BASE
),get_domain_space
)(
46 __isl_keep
MULTI(BASE
) *multi
)
48 return multi
? isl_space_domain(isl_space_copy(multi
->space
)) : NULL
;
51 /* Allocate a multi expression living in "space".
53 * If the number of base expressions is zero, then make sure
54 * there is enough room in the structure for the explicit domain,
55 * in case the type supports such an explicit domain.
57 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),alloc
)(__isl_take isl_space
*space
)
66 ctx
= isl_space_get_ctx(space
);
67 n
= isl_space_dim(space
, isl_dim_out
);
69 multi
= isl_calloc(ctx
, MULTI(BASE
),
70 sizeof(MULTI(BASE
)) + (n
- 1) * sizeof(struct EL
*));
72 multi
= isl_calloc(ctx
, MULTI(BASE
), sizeof(MULTI(BASE
)));
79 if (FN(MULTI(BASE
),has_explicit_domain
)(multi
))
80 multi
= FN(MULTI(BASE
),init_explicit_domain
)(multi
);
83 isl_space_free(space
);
87 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),dup
)(__isl_keep
MULTI(BASE
) *multi
)
95 dup
= FN(MULTI(BASE
),alloc
)(isl_space_copy(multi
->space
));
99 for (i
= 0; i
< multi
->n
; ++i
)
100 dup
= FN(FN(MULTI(BASE
),set
),BASE
)(dup
, i
,
101 FN(EL
,copy
)(multi
->u
.p
[i
]));
102 if (FN(MULTI(BASE
),has_explicit_domain
)(multi
))
103 dup
= FN(MULTI(BASE
),copy_explicit_domain
)(dup
, multi
);
108 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),cow
)(__isl_take
MULTI(BASE
) *multi
)
117 return FN(MULTI(BASE
),dup
)(multi
);
120 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),copy
)(__isl_keep
MULTI(BASE
) *multi
)
129 __isl_null
MULTI(BASE
) *FN(MULTI(BASE
),free
)(__isl_take
MULTI(BASE
) *multi
)
136 if (--multi
->ref
> 0)
139 isl_space_free(multi
->space
);
140 for (i
= 0; i
< multi
->n
; ++i
)
141 FN(EL
,free
)(multi
->u
.p
[i
]);
142 if (FN(MULTI(BASE
),has_explicit_domain
)(multi
))
143 FN(MULTI(BASE
),free_explicit_domain
)(multi
);
149 unsigned FN(MULTI(BASE
),dim
)(__isl_keep
MULTI(BASE
) *multi
,
150 enum isl_dim_type type
)
152 return multi
? isl_space_dim(multi
->space
, type
) : 0;
155 /* Return the position of the first dimension of "type" with id "id".
156 * Return -1 if there is no such dimension.
158 int FN(MULTI(BASE
),find_dim_by_id
)(__isl_keep
MULTI(BASE
) *multi
,
159 enum isl_dim_type type
, __isl_keep isl_id
*id
)
163 return isl_space_find_dim_by_id(multi
->space
, type
, id
);
166 /* Return the id of the given dimension.
168 __isl_give isl_id
*FN(MULTI(BASE
),get_dim_id
)(__isl_keep
MULTI(BASE
) *multi
,
169 enum isl_dim_type type
, unsigned pos
)
171 return multi
? isl_space_get_dim_id(multi
->space
, type
, pos
) : NULL
;
174 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),set_dim_name
)(
175 __isl_take
MULTI(BASE
) *multi
,
176 enum isl_dim_type type
, unsigned pos
, const char *s
)
180 multi
= FN(MULTI(BASE
),cow
)(multi
);
184 multi
->space
= isl_space_set_dim_name(multi
->space
, type
, pos
, s
);
186 return FN(MULTI(BASE
),free
)(multi
);
188 if (type
== isl_dim_out
)
190 for (i
= 0; i
< multi
->n
; ++i
) {
191 multi
->u
.p
[i
] = FN(EL
,set_dim_name
)(multi
->u
.p
[i
],
194 return FN(MULTI(BASE
),free
)(multi
);
200 const char *FN(MULTI(BASE
),get_tuple_name
)(__isl_keep
MULTI(BASE
) *multi
,
201 enum isl_dim_type type
)
203 return multi
? isl_space_get_tuple_name(multi
->space
, type
) : NULL
;
206 /* Does the specified tuple have an id?
208 isl_bool
FN(MULTI(BASE
),has_tuple_id
)(__isl_keep
MULTI(BASE
) *multi
,
209 enum isl_dim_type type
)
212 return isl_bool_error
;
213 return isl_space_has_tuple_id(multi
->space
, type
);
216 /* Return the id of the specified tuple.
218 __isl_give isl_id
*FN(MULTI(BASE
),get_tuple_id
)(__isl_keep
MULTI(BASE
) *multi
,
219 enum isl_dim_type type
)
221 return multi
? isl_space_get_tuple_id(multi
->space
, type
) : NULL
;
224 __isl_give EL
*FN(FN(MULTI(BASE
),get
),BASE
)(__isl_keep
MULTI(BASE
) *multi
,
231 ctx
= FN(MULTI(BASE
),get_ctx
)(multi
);
232 if (pos
< 0 || pos
>= multi
->n
)
233 isl_die(ctx
, isl_error_invalid
,
234 "index out of bounds", return NULL
);
235 return FN(EL
,copy
)(multi
->u
.p
[pos
]);
238 /* Set the element at position "pos" of "multi" to "el",
239 * where the position may be empty if "multi" has only a single reference.
241 static __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),restore
)(
242 __isl_take
MULTI(BASE
) *multi
, int pos
, __isl_take EL
*el
)
244 multi
= FN(MULTI(BASE
),cow
)(multi
);
248 if (pos
< 0 || pos
>= multi
->n
)
249 isl_die(FN(MULTI(BASE
),get_ctx
)(multi
), isl_error_invalid
,
250 "index out of bounds", goto error
);
252 FN(EL
,free
)(multi
->u
.p
[pos
]);
253 multi
->u
.p
[pos
] = el
;
257 FN(MULTI(BASE
),free
)(multi
);
262 __isl_give
MULTI(BASE
) *FN(FN(MULTI(BASE
),set
),BASE
)(
263 __isl_take
MULTI(BASE
) *multi
, int pos
, __isl_take EL
*el
)
265 isl_space
*multi_space
= NULL
;
266 isl_space
*el_space
= NULL
;
269 multi_space
= FN(MULTI(BASE
),get_space
)(multi
);
270 match
= FN(EL
,matching_params
)(el
, multi_space
);
274 multi
= FN(MULTI(BASE
),align_params
)(multi
,
275 FN(EL
,get_space
)(el
));
276 isl_space_free(multi_space
);
277 multi_space
= FN(MULTI(BASE
),get_space
)(multi
);
278 el
= FN(EL
,align_params
)(el
, isl_space_copy(multi_space
));
280 if (FN(EL
,check_match_domain_space
)(el
, multi_space
) < 0)
283 multi
= FN(MULTI(BASE
),restore
)(multi
, pos
, el
);
285 isl_space_free(multi_space
);
286 isl_space_free(el_space
);
290 FN(MULTI(BASE
),free
)(multi
);
292 isl_space_free(multi_space
);
293 isl_space_free(el_space
);
297 /* Reset the space of "multi". This function is called from isl_pw_templ.c
298 * and doesn't know if the space of an element object is represented
299 * directly or through its domain. It therefore passes along both,
300 * which we pass along to the element function since we don't know how
301 * that is represented either.
303 * If "multi" has an explicit domain, then the caller is expected
304 * to make sure that any modification that would change the dimensions
305 * of the explicit domain has bee applied before this function is called.
307 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),reset_space_and_domain
)(
308 __isl_take
MULTI(BASE
) *multi
, __isl_take isl_space
*space
,
309 __isl_take isl_space
*domain
)
313 multi
= FN(MULTI(BASE
),cow
)(multi
);
314 if (!multi
|| !space
|| !domain
)
317 for (i
= 0; i
< multi
->n
; ++i
) {
318 multi
->u
.p
[i
] = FN(EL
,reset_domain_space
)(multi
->u
.p
[i
],
319 isl_space_copy(domain
));
323 if (FN(MULTI(BASE
),has_explicit_domain
)(multi
)) {
324 multi
= FN(MULTI(BASE
),reset_explicit_domain_space
)(multi
,
325 isl_space_copy(domain
));
329 isl_space_free(domain
);
330 isl_space_free(multi
->space
);
331 multi
->space
= space
;
335 isl_space_free(domain
);
336 isl_space_free(space
);
337 FN(MULTI(BASE
),free
)(multi
);
341 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),reset_domain_space
)(
342 __isl_take
MULTI(BASE
) *multi
, __isl_take isl_space
*domain
)
346 space
= isl_space_extend_domain_with_range(isl_space_copy(domain
),
347 isl_space_copy(multi
->space
));
348 return FN(MULTI(BASE
),reset_space_and_domain
)(multi
, space
, domain
);
351 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),reset_space
)(
352 __isl_take
MULTI(BASE
) *multi
, __isl_take isl_space
*space
)
356 domain
= isl_space_domain(isl_space_copy(space
));
357 return FN(MULTI(BASE
),reset_space_and_domain
)(multi
, space
, domain
);
360 /* Set the id of the given dimension of "multi" to "id".
362 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),set_dim_id
)(
363 __isl_take
MULTI(BASE
) *multi
,
364 enum isl_dim_type type
, unsigned pos
, __isl_take isl_id
*id
)
368 multi
= FN(MULTI(BASE
),cow
)(multi
);
372 space
= FN(MULTI(BASE
),get_space
)(multi
);
373 space
= isl_space_set_dim_id(space
, type
, pos
, id
);
375 return FN(MULTI(BASE
),reset_space
)(multi
, space
);
378 FN(MULTI(BASE
),free
)(multi
);
382 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),set_tuple_name
)(
383 __isl_keep
MULTI(BASE
) *multi
, enum isl_dim_type type
,
388 multi
= FN(MULTI(BASE
),cow
)(multi
);
392 space
= FN(MULTI(BASE
),get_space
)(multi
);
393 space
= isl_space_set_tuple_name(space
, type
, s
);
395 return FN(MULTI(BASE
),reset_space
)(multi
, space
);
398 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),set_tuple_id
)(
399 __isl_take
MULTI(BASE
) *multi
, enum isl_dim_type type
,
400 __isl_take isl_id
*id
)
404 multi
= FN(MULTI(BASE
),cow
)(multi
);
408 space
= FN(MULTI(BASE
),get_space
)(multi
);
409 space
= isl_space_set_tuple_id(space
, type
, id
);
411 return FN(MULTI(BASE
),reset_space
)(multi
, space
);
417 /* Drop the id on the specified tuple.
419 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),reset_tuple_id
)(
420 __isl_take
MULTI(BASE
) *multi
, enum isl_dim_type type
)
426 if (!FN(MULTI(BASE
),has_tuple_id
)(multi
, type
))
429 multi
= FN(MULTI(BASE
),cow
)(multi
);
433 space
= FN(MULTI(BASE
),get_space
)(multi
);
434 space
= isl_space_reset_tuple_id(space
, type
);
436 return FN(MULTI(BASE
),reset_space
)(multi
, space
);
439 /* Reset the user pointer on all identifiers of parameters and tuples
440 * of the space of "multi".
442 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),reset_user
)(
443 __isl_take
MULTI(BASE
) *multi
)
447 space
= FN(MULTI(BASE
),get_space
)(multi
);
448 space
= isl_space_reset_user(space
);
450 return FN(MULTI(BASE
),reset_space
)(multi
, space
);
453 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),realign_domain
)(
454 __isl_take
MULTI(BASE
) *multi
, __isl_take isl_reordering
*exp
)
459 multi
= FN(MULTI(BASE
),cow
)(multi
);
463 for (i
= 0; i
< multi
->n
; ++i
) {
464 multi
->u
.p
[i
] = FN(EL
,realign_domain
)(multi
->u
.p
[i
],
465 isl_reordering_copy(exp
));
470 space
= isl_reordering_get_space(exp
);
471 multi
= FN(MULTI(BASE
),reset_domain_space
)(multi
, space
);
473 isl_reordering_free(exp
);
476 isl_reordering_free(exp
);
477 FN(MULTI(BASE
),free
)(multi
);
481 /* Align the parameters of "multi" to those of "model".
483 * If "multi" has an explicit domain, then align the parameters
484 * of the domain first.
486 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),align_params
)(
487 __isl_take
MULTI(BASE
) *multi
, __isl_take isl_space
*model
)
490 isl_bool equal_params
;
493 if (!multi
|| !model
)
496 equal_params
= isl_space_has_equal_params(multi
->space
, model
);
497 if (equal_params
< 0)
500 isl_space_free(model
);
504 ctx
= isl_space_get_ctx(model
);
505 if (!isl_space_has_named_params(model
))
506 isl_die(ctx
, isl_error_invalid
,
507 "model has unnamed parameters", goto error
);
508 if (!isl_space_has_named_params(multi
->space
))
509 isl_die(ctx
, isl_error_invalid
,
510 "input has unnamed parameters", goto error
);
512 if (FN(MULTI(BASE
),has_explicit_domain
)(multi
)) {
513 multi
= FN(MULTI(BASE
),align_explicit_domain_params
)(multi
,
514 isl_space_copy(model
));
518 exp
= isl_parameter_alignment_reordering(multi
->space
, model
);
519 exp
= isl_reordering_extend_space(exp
,
520 FN(MULTI(BASE
),get_domain_space
)(multi
));
521 multi
= FN(MULTI(BASE
),realign_domain
)(multi
, exp
);
523 isl_space_free(model
);
526 isl_space_free(model
);
527 FN(MULTI(BASE
),free
)(multi
);
531 /* Create a multi expression in the given space with the elements of "list"
532 * as base expressions.
534 * Since isl_multi_*_restore_* assumes that the element and
535 * the multi expression have matching spaces, the alignment
536 * (if any) needs to be performed beforehand.
538 __isl_give
MULTI(BASE
) *FN(FN(MULTI(BASE
),from
),LIST(BASE
))(
539 __isl_take isl_space
*space
, __isl_take
LIST(EL
) *list
)
549 ctx
= isl_space_get_ctx(space
);
550 n
= FN(FN(LIST(EL
),n
),BASE
)(list
);
551 if (n
!= isl_space_dim(space
, isl_dim_out
))
552 isl_die(ctx
, isl_error_invalid
,
553 "invalid number of elements in list", goto error
);
555 for (i
= 0; i
< n
; ++i
) {
556 EL
*el
= FN(LIST(EL
),peek
)(list
, i
);
557 space
= isl_space_align_params(space
, FN(EL
,get_space
)(el
));
559 multi
= FN(MULTI(BASE
),alloc
)(isl_space_copy(space
));
560 for (i
= 0; i
< n
; ++i
) {
561 EL
*el
= FN(FN(LIST(EL
),get
),BASE
)(list
, i
);
562 el
= FN(EL
,align_params
)(el
, isl_space_copy(space
));
563 multi
= FN(MULTI(BASE
),restore
)(multi
, i
, el
);
566 isl_space_free(space
);
567 FN(LIST(EL
),free
)(list
);
570 isl_space_free(space
);
571 FN(LIST(EL
),free
)(list
);
576 /* Create a multi expression in the given space that maps each
577 * input dimension to the corresponding output dimension.
579 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),identity
)(__isl_take isl_space
*space
)
588 if (isl_space_is_set(space
))
589 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
590 "expecting map space", goto error
);
592 n
= isl_space_dim(space
, isl_dim_out
);
593 if (n
!= isl_space_dim(space
, isl_dim_in
))
594 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
595 "number of input and output dimensions needs to be "
596 "the same", goto error
);
598 multi
= FN(MULTI(BASE
),alloc
)(isl_space_copy(space
));
601 isl_space_free(space
);
605 space
= isl_space_domain(space
);
606 ls
= isl_local_space_from_space(space
);
608 for (i
= 0; i
< n
; ++i
) {
610 el
= FN(EL
,var_on_domain
)(isl_local_space_copy(ls
),
612 multi
= FN(FN(MULTI(BASE
),set
),BASE
)(multi
, i
, el
);
615 isl_local_space_free(ls
);
619 isl_space_free(space
);
625 /* Construct a multi expression in the given space with value zero in
626 * each of the output dimensions.
628 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),zero
)(__isl_take isl_space
*space
)
636 n
= isl_space_dim(space
, isl_dim_out
);
637 multi
= FN(MULTI(BASE
),alloc
)(isl_space_copy(space
));
640 isl_space_free(space
);
646 space
= isl_space_domain(space
);
647 ls
= isl_local_space_from_space(space
);
648 el
= FN(EL
,zero_on_domain
)(ls
);
650 for (i
= 0; i
< n
; ++i
)
651 multi
= FN(FN(MULTI(BASE
),set
),BASE
)(multi
, i
,
662 /* Create a multiple expression with a single output/set dimension
664 * For most multiple expression types, the base type has a single
665 * output/set dimension and the space of the result is therefore
666 * the same as the space of the input.
667 * In the case of isl_multi_union_pw_aff, however, the base type
668 * lives in a parameter space and we therefore need to add
669 * a single set dimension.
671 __isl_give
MULTI(BASE
) *FN(FN(MULTI(BASE
),from
),BASE
)(__isl_take EL
*el
)
676 space
= FN(EL
,get_space(el
));
677 if (isl_space_is_params(space
)) {
678 space
= isl_space_set_from_params(space
);
679 space
= isl_space_add_dims(space
, isl_dim_set
, 1);
681 multi
= FN(MULTI(BASE
),alloc
)(space
);
682 multi
= FN(FN(MULTI(BASE
),set
),BASE
)(multi
, 0, el
);
688 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),drop_dims
)(
689 __isl_take
MULTI(BASE
) *multi
,
690 enum isl_dim_type type
, unsigned first
, unsigned n
)
695 multi
= FN(MULTI(BASE
),cow
)(multi
);
699 dim
= FN(MULTI(BASE
),dim
)(multi
, type
);
700 if (first
+ n
> dim
|| first
+ n
< first
)
701 isl_die(FN(MULTI(BASE
),get_ctx
)(multi
), isl_error_invalid
,
702 "index out of bounds",
703 return FN(MULTI(BASE
),free
)(multi
));
705 multi
->space
= isl_space_drop_dims(multi
->space
, type
, first
, n
);
707 return FN(MULTI(BASE
),free
)(multi
);
709 if (type
== isl_dim_out
) {
710 for (i
= 0; i
< n
; ++i
)
711 FN(EL
,free
)(multi
->u
.p
[first
+ i
]);
712 for (i
= first
; i
+ n
< multi
->n
; ++i
)
713 multi
->u
.p
[i
] = multi
->u
.p
[i
+ n
];
715 if (n
> 0 && FN(MULTI(BASE
),has_explicit_domain
)(multi
))
716 multi
= FN(MULTI(BASE
),init_explicit_domain
)(multi
);
721 if (FN(MULTI(BASE
),has_explicit_domain
)(multi
))
722 multi
= FN(MULTI(BASE
),drop_explicit_domain_dims
)(multi
,
727 for (i
= 0; i
< multi
->n
; ++i
) {
728 multi
->u
.p
[i
] = FN(EL
,drop_dims
)(multi
->u
.p
[i
], type
, first
, n
);
730 return FN(MULTI(BASE
),free
)(multi
);
736 /* Align the parameters of "multi1" and "multi2" (if needed) and call "fn".
738 static __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),align_params_multi_multi_and
)(
739 __isl_take
MULTI(BASE
) *multi1
, __isl_take
MULTI(BASE
) *multi2
,
740 __isl_give
MULTI(BASE
) *(*fn
)(__isl_take
MULTI(BASE
) *multi1
,
741 __isl_take
MULTI(BASE
) *multi2
))
744 isl_bool equal_params
;
746 if (!multi1
|| !multi2
)
748 equal_params
= isl_space_has_equal_params(multi1
->space
, multi2
->space
);
749 if (equal_params
< 0)
752 return fn(multi1
, multi2
);
753 ctx
= FN(MULTI(BASE
),get_ctx
)(multi1
);
754 if (!isl_space_has_named_params(multi1
->space
) ||
755 !isl_space_has_named_params(multi2
->space
))
756 isl_die(ctx
, isl_error_invalid
,
757 "unaligned unnamed parameters", goto error
);
758 multi1
= FN(MULTI(BASE
),align_params
)(multi1
,
759 FN(MULTI(BASE
),get_space
)(multi2
));
760 multi2
= FN(MULTI(BASE
),align_params
)(multi2
,
761 FN(MULTI(BASE
),get_space
)(multi1
));
762 return fn(multi1
, multi2
);
764 FN(MULTI(BASE
),free
)(multi1
);
765 FN(MULTI(BASE
),free
)(multi2
);
769 /* Given two MULTI(BASE)s A -> B and C -> D,
770 * construct a MULTI(BASE) (A * C) -> [B -> D].
772 * The parameters are assumed to have been aligned.
774 * If "multi1" and/or "multi2" has an explicit domain, then
775 * intersect the domain of the result with these explicit domains.
777 static __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),range_product_aligned
)(
778 __isl_take
MULTI(BASE
) *multi1
, __isl_take
MULTI(BASE
) *multi2
)
785 if (!multi1
|| !multi2
)
788 space
= isl_space_range_product(FN(MULTI(BASE
),get_space
)(multi1
),
789 FN(MULTI(BASE
),get_space
)(multi2
));
790 res
= FN(MULTI(BASE
),alloc
)(space
);
792 n1
= FN(MULTI(BASE
),dim
)(multi1
, isl_dim_out
);
793 n2
= FN(MULTI(BASE
),dim
)(multi2
, isl_dim_out
);
795 for (i
= 0; i
< n1
; ++i
) {
796 el
= FN(FN(MULTI(BASE
),get
),BASE
)(multi1
, i
);
797 res
= FN(FN(MULTI(BASE
),set
),BASE
)(res
, i
, el
);
800 for (i
= 0; i
< n2
; ++i
) {
801 el
= FN(FN(MULTI(BASE
),get
),BASE
)(multi2
, i
);
802 res
= FN(FN(MULTI(BASE
),set
),BASE
)(res
, n1
+ i
, el
);
805 if (FN(MULTI(BASE
),has_explicit_domain
)(multi1
))
806 res
= FN(MULTI(BASE
),intersect_explicit_domain
)(res
, multi1
);
807 if (FN(MULTI(BASE
),has_explicit_domain
)(multi2
))
808 res
= FN(MULTI(BASE
),intersect_explicit_domain
)(res
, multi2
);
810 FN(MULTI(BASE
),free
)(multi1
);
811 FN(MULTI(BASE
),free
)(multi2
);
814 FN(MULTI(BASE
),free
)(multi1
);
815 FN(MULTI(BASE
),free
)(multi2
);
819 /* Given two MULTI(BASE)s A -> B and C -> D,
820 * construct a MULTI(BASE) (A * C) -> [B -> D].
822 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),range_product
)(
823 __isl_take
MULTI(BASE
) *multi1
, __isl_take
MULTI(BASE
) *multi2
)
825 return FN(MULTI(BASE
),align_params_multi_multi_and
)(multi1
, multi2
,
826 &FN(MULTI(BASE
),range_product_aligned
));
829 /* Is the range of "multi" a wrapped relation?
831 isl_bool
FN(MULTI(BASE
),range_is_wrapping
)(__isl_keep
MULTI(BASE
) *multi
)
834 return isl_bool_error
;
835 return isl_space_range_is_wrapping(multi
->space
);
838 /* Given a function A -> [B -> C], extract the function A -> B.
840 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),range_factor_domain
)(
841 __isl_take
MULTI(BASE
) *multi
)
848 if (!isl_space_range_is_wrapping(multi
->space
))
849 isl_die(FN(MULTI(BASE
),get_ctx
)(multi
), isl_error_invalid
,
850 "range is not a product",
851 return FN(MULTI(BASE
),free
)(multi
));
853 space
= FN(MULTI(BASE
),get_space
)(multi
);
854 total
= isl_space_dim(space
, isl_dim_out
);
855 space
= isl_space_range_factor_domain(space
);
856 keep
= isl_space_dim(space
, isl_dim_out
);
857 multi
= FN(MULTI(BASE
),drop_dims
)(multi
,
858 isl_dim_out
, keep
, total
- keep
);
859 multi
= FN(MULTI(BASE
),reset_space
)(multi
, space
);
864 /* Given a function A -> [B -> C], extract the function A -> C.
866 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),range_factor_range
)(
867 __isl_take
MULTI(BASE
) *multi
)
874 if (!isl_space_range_is_wrapping(multi
->space
))
875 isl_die(FN(MULTI(BASE
),get_ctx
)(multi
), isl_error_invalid
,
876 "range is not a product",
877 return FN(MULTI(BASE
),free
)(multi
));
879 space
= FN(MULTI(BASE
),get_space
)(multi
);
880 total
= isl_space_dim(space
, isl_dim_out
);
881 space
= isl_space_range_factor_range(space
);
882 keep
= isl_space_dim(space
, isl_dim_out
);
883 multi
= FN(MULTI(BASE
),drop_dims
)(multi
, isl_dim_out
, 0, total
- keep
);
884 multi
= FN(MULTI(BASE
),reset_space
)(multi
, space
);
889 /* Given a function [B -> C], extract the function C.
891 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),factor_range
)(
892 __isl_take
MULTI(BASE
) *multi
)
899 if (!isl_space_is_wrapping(multi
->space
))
900 isl_die(FN(MULTI(BASE
),get_ctx
)(multi
), isl_error_invalid
,
901 "not a product", return FN(MULTI(BASE
),free
)(multi
));
903 space
= FN(MULTI(BASE
),get_space
)(multi
);
904 total
= isl_space_dim(space
, isl_dim_out
);
905 space
= isl_space_factor_range(space
);
906 keep
= isl_space_dim(space
, isl_dim_out
);
907 multi
= FN(MULTI(BASE
),drop_dims
)(multi
, isl_dim_out
, 0, total
- keep
);
908 multi
= FN(MULTI(BASE
),reset_space
)(multi
, space
);
914 /* Given two MULTI(BASE)s A -> B and C -> D,
915 * construct a MULTI(BASE) [A -> C] -> [B -> D].
917 * The parameters are assumed to have been aligned.
919 * If "multi1" and/or "multi2" has an explicit domain, then
920 * intersect the domain of the result with these explicit domains.
922 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),product_aligned
)(
923 __isl_take
MULTI(BASE
) *multi1
, __isl_take
MULTI(BASE
) *multi2
)
929 int in1
, in2
, out1
, out2
;
931 in1
= FN(MULTI(BASE
),dim
)(multi1
, isl_dim_in
);
932 in2
= FN(MULTI(BASE
),dim
)(multi2
, isl_dim_in
);
933 out1
= FN(MULTI(BASE
),dim
)(multi1
, isl_dim_out
);
934 out2
= FN(MULTI(BASE
),dim
)(multi2
, isl_dim_out
);
935 space
= isl_space_product(FN(MULTI(BASE
),get_space
)(multi1
),
936 FN(MULTI(BASE
),get_space
)(multi2
));
937 res
= FN(MULTI(BASE
),alloc
)(isl_space_copy(space
));
938 space
= isl_space_domain(space
);
940 for (i
= 0; i
< out1
; ++i
) {
941 el
= FN(FN(MULTI(BASE
),get
),BASE
)(multi1
, i
);
942 el
= FN(EL
,insert_dims
)(el
, isl_dim_in
, in1
, in2
);
943 el
= FN(EL
,reset_domain_space
)(el
, isl_space_copy(space
));
944 res
= FN(FN(MULTI(BASE
),set
),BASE
)(res
, i
, el
);
947 for (i
= 0; i
< out2
; ++i
) {
948 el
= FN(FN(MULTI(BASE
),get
),BASE
)(multi2
, i
);
949 el
= FN(EL
,insert_dims
)(el
, isl_dim_in
, 0, in1
);
950 el
= FN(EL
,reset_domain_space
)(el
, isl_space_copy(space
));
951 res
= FN(FN(MULTI(BASE
),set
),BASE
)(res
, out1
+ i
, el
);
954 if (FN(MULTI(BASE
),has_explicit_domain
)(multi1
) ||
955 FN(MULTI(BASE
),has_explicit_domain
)(multi2
))
956 res
= FN(MULTI(BASE
),intersect_explicit_domain_product
)(res
,
959 isl_space_free(space
);
960 FN(MULTI(BASE
),free
)(multi1
);
961 FN(MULTI(BASE
),free
)(multi2
);
965 /* Given two MULTI(BASE)s A -> B and C -> D,
966 * construct a MULTI(BASE) [A -> C] -> [B -> D].
968 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),product
)(
969 __isl_take
MULTI(BASE
) *multi1
, __isl_take
MULTI(BASE
) *multi2
)
971 return FN(MULTI(BASE
),align_params_multi_multi_and
)(multi1
, multi2
,
972 &FN(MULTI(BASE
),product_aligned
));
976 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),flatten_range
)(
977 __isl_take
MULTI(BASE
) *multi
)
982 if (!multi
->space
->nested
[1])
985 multi
= FN(MULTI(BASE
),cow
)(multi
);
989 multi
->space
= isl_space_flatten_range(multi
->space
);
991 return FN(MULTI(BASE
),free
)(multi
);
996 /* Given two MULTI(BASE)s A -> B and C -> D,
997 * construct a MULTI(BASE) (A * C) -> (B, D).
999 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),flat_range_product
)(
1000 __isl_take
MULTI(BASE
) *multi1
, __isl_take
MULTI(BASE
) *multi2
)
1004 multi
= FN(MULTI(BASE
),range_product
)(multi1
, multi2
);
1005 multi
= FN(MULTI(BASE
),flatten_range
)(multi
);
1009 /* Given two multi expressions, "multi1"
1013 * where B2 starts at position "pos", and "multi2"
1017 * return the multi expression
1021 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),range_splice
)(
1022 __isl_take
MULTI(BASE
) *multi1
, unsigned pos
,
1023 __isl_take
MULTI(BASE
) *multi2
)
1028 if (!multi1
|| !multi2
)
1031 dim
= FN(MULTI(BASE
),dim
)(multi1
, isl_dim_out
);
1033 isl_die(FN(MULTI(BASE
),get_ctx
)(multi1
), isl_error_invalid
,
1034 "index out of bounds", goto error
);
1036 res
= FN(MULTI(BASE
),copy
)(multi1
);
1037 res
= FN(MULTI(BASE
),drop_dims
)(res
, isl_dim_out
, pos
, dim
- pos
);
1038 multi1
= FN(MULTI(BASE
),drop_dims
)(multi1
, isl_dim_out
, 0, pos
);
1040 res
= FN(MULTI(BASE
),flat_range_product
)(res
, multi2
);
1041 res
= FN(MULTI(BASE
),flat_range_product
)(res
, multi1
);
1045 FN(MULTI(BASE
),free
)(multi1
);
1046 FN(MULTI(BASE
),free
)(multi2
);
1051 /* Given two multi expressions, "multi1"
1053 * [A1 A2] -> [B1 B2]
1055 * where A2 starts at position "in_pos" and B2 starts at position "out_pos",
1060 * return the multi expression
1062 * [A1 C A2] -> [B1 D B2]
1064 * We first insert input dimensions to obtain
1066 * [A1 C A2] -> [B1 B2]
1072 * and then apply range_splice.
1074 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),splice
)(
1075 __isl_take
MULTI(BASE
) *multi1
, unsigned in_pos
, unsigned out_pos
,
1076 __isl_take
MULTI(BASE
) *multi2
)
1081 if (!multi1
|| !multi2
)
1084 n_in1
= FN(MULTI(BASE
),dim
)(multi1
, isl_dim_in
);
1086 isl_die(FN(MULTI(BASE
),get_ctx
)(multi1
), isl_error_invalid
,
1087 "index out of bounds", goto error
);
1089 n_in2
= FN(MULTI(BASE
),dim
)(multi2
, isl_dim_in
);
1091 multi1
= FN(MULTI(BASE
),insert_dims
)(multi1
, isl_dim_in
, in_pos
, n_in2
);
1092 multi2
= FN(MULTI(BASE
),insert_dims
)(multi2
, isl_dim_in
, n_in2
,
1094 multi2
= FN(MULTI(BASE
),insert_dims
)(multi2
, isl_dim_in
, 0, in_pos
);
1096 return FN(MULTI(BASE
),range_splice
)(multi1
, out_pos
, multi2
);
1098 FN(MULTI(BASE
),free
)(multi1
);
1099 FN(MULTI(BASE
),free
)(multi2
);
1104 /* Check that "multi1" and "multi2" live in the same space,
1105 * reporting an error if they do not.
1107 static isl_stat
FN(MULTI(BASE
),check_equal_space
)(
1108 __isl_keep
MULTI(BASE
) *multi1
, __isl_keep
MULTI(BASE
) *multi2
)
1112 if (!multi1
|| !multi2
)
1113 return isl_stat_error
;
1115 equal
= isl_space_is_equal(multi1
->space
, multi2
->space
);
1117 return isl_stat_error
;
1119 isl_die(FN(MULTI(BASE
),get_ctx
)(multi1
), isl_error_invalid
,
1120 "spaces don't match", return isl_stat_error
);
1125 /* This function is currently only used from isl_aff.c
1127 static __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),bin_op
)(
1128 __isl_take
MULTI(BASE
) *multi1
, __isl_take
MULTI(BASE
) *multi2
,
1129 __isl_give EL
*(*fn
)(__isl_take EL
*, __isl_take EL
*))
1130 __attribute__ ((unused
));
1132 /* Pairwise perform "fn" to the elements of "multi1" and "multi2" and
1133 * return the result.
1135 * If "multi2" has an explicit domain, then
1136 * intersect the domain of the result with this explicit domain.
1138 static __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),bin_op
)(
1139 __isl_take
MULTI(BASE
) *multi1
, __isl_take
MULTI(BASE
) *multi2
,
1140 __isl_give EL
*(*fn
)(__isl_take EL
*, __isl_take EL
*))
1144 multi1
= FN(MULTI(BASE
),cow
)(multi1
);
1145 if (FN(MULTI(BASE
),check_equal_space
)(multi1
, multi2
) < 0)
1148 for (i
= 0; i
< multi1
->n
; ++i
) {
1149 multi1
->u
.p
[i
] = fn(multi1
->u
.p
[i
],
1150 FN(EL
,copy
)(multi2
->u
.p
[i
]));
1151 if (!multi1
->u
.p
[i
])
1155 if (FN(MULTI(BASE
),has_explicit_domain
)(multi2
))
1156 multi1
= FN(MULTI(BASE
),intersect_explicit_domain
)(multi1
,
1159 FN(MULTI(BASE
),free
)(multi2
);
1162 FN(MULTI(BASE
),free
)(multi1
);
1163 FN(MULTI(BASE
),free
)(multi2
);
1167 /* Add "multi2" from "multi1" and return the result.
1169 * The parameters of "multi1" and "multi2" are assumed to have been aligned.
1171 static __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),add_aligned
)(
1172 __isl_take
MULTI(BASE
) *multi1
, __isl_take
MULTI(BASE
) *multi2
)
1174 return FN(MULTI(BASE
),bin_op
)(multi1
, multi2
, &FN(EL
,add
));
1177 /* Add "multi2" from "multi1" and return the result.
1179 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),add
)(__isl_take
MULTI(BASE
) *multi1
,
1180 __isl_take
MULTI(BASE
) *multi2
)
1182 return FN(MULTI(BASE
),align_params_multi_multi_and
)(multi1
, multi2
,
1183 &FN(MULTI(BASE
),add_aligned
));
1186 /* Subtract "multi2" from "multi1" and return the result.
1188 * The parameters of "multi1" and "multi2" are assumed to have been aligned.
1190 static __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),sub_aligned
)(
1191 __isl_take
MULTI(BASE
) *multi1
, __isl_take
MULTI(BASE
) *multi2
)
1193 return FN(MULTI(BASE
),bin_op
)(multi1
, multi2
, &FN(EL
,sub
));
1196 /* Subtract "multi2" from "multi1" and return the result.
1198 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),sub
)(__isl_take
MULTI(BASE
) *multi1
,
1199 __isl_take
MULTI(BASE
) *multi2
)
1201 return FN(MULTI(BASE
),align_params_multi_multi_and
)(multi1
, multi2
,
1202 &FN(MULTI(BASE
),sub_aligned
));
1205 /* Multiply the elements of "multi" by "v" and return the result.
1207 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),scale_val
)(__isl_take
MULTI(BASE
) *multi
,
1208 __isl_take isl_val
*v
)
1215 if (isl_val_is_one(v
)) {
1220 if (!isl_val_is_rat(v
))
1221 isl_die(isl_val_get_ctx(v
), isl_error_invalid
,
1222 "expecting rational factor", goto error
);
1224 multi
= FN(MULTI(BASE
),cow
)(multi
);
1228 for (i
= 0; i
< multi
->n
; ++i
) {
1229 multi
->u
.p
[i
] = FN(EL
,scale_val
)(multi
->u
.p
[i
],
1239 return FN(MULTI(BASE
),free
)(multi
);
1242 /* Divide the elements of "multi" by "v" and return the result.
1244 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),scale_down_val
)(
1245 __isl_take
MULTI(BASE
) *multi
, __isl_take isl_val
*v
)
1252 if (isl_val_is_one(v
)) {
1257 if (!isl_val_is_rat(v
))
1258 isl_die(isl_val_get_ctx(v
), isl_error_invalid
,
1259 "expecting rational factor", goto error
);
1260 if (isl_val_is_zero(v
))
1261 isl_die(isl_val_get_ctx(v
), isl_error_invalid
,
1262 "cannot scale down by zero", goto error
);
1264 multi
= FN(MULTI(BASE
),cow
)(multi
);
1268 for (i
= 0; i
< multi
->n
; ++i
) {
1269 multi
->u
.p
[i
] = FN(EL
,scale_down_val
)(multi
->u
.p
[i
],
1279 return FN(MULTI(BASE
),free
)(multi
);
1282 /* Multiply the elements of "multi" by the corresponding element of "mv"
1283 * and return the result.
1285 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),scale_multi_val
)(
1286 __isl_take
MULTI(BASE
) *multi
, __isl_take isl_multi_val
*mv
)
1293 if (!isl_space_tuple_is_equal(multi
->space
, isl_dim_out
,
1294 mv
->space
, isl_dim_set
))
1295 isl_die(isl_multi_val_get_ctx(mv
), isl_error_invalid
,
1296 "spaces don't match", goto error
);
1298 multi
= FN(MULTI(BASE
),cow
)(multi
);
1302 for (i
= 0; i
< multi
->n
; ++i
) {
1305 v
= isl_multi_val_get_val(mv
, i
);
1306 multi
->u
.p
[i
] = FN(EL
,scale_val
)(multi
->u
.p
[i
], v
);
1311 isl_multi_val_free(mv
);
1314 isl_multi_val_free(mv
);
1315 return FN(MULTI(BASE
),free
)(multi
);
1318 /* Divide the elements of "multi" by the corresponding element of "mv"
1319 * and return the result.
1321 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),scale_down_multi_val
)(
1322 __isl_take
MULTI(BASE
) *multi
, __isl_take isl_multi_val
*mv
)
1329 if (!isl_space_tuple_is_equal(multi
->space
, isl_dim_out
,
1330 mv
->space
, isl_dim_set
))
1331 isl_die(isl_multi_val_get_ctx(mv
), isl_error_invalid
,
1332 "spaces don't match", goto error
);
1334 multi
= FN(MULTI(BASE
),cow
)(multi
);
1338 for (i
= 0; i
< multi
->n
; ++i
) {
1341 v
= isl_multi_val_get_val(mv
, i
);
1342 multi
->u
.p
[i
] = FN(EL
,scale_down_val
)(multi
->u
.p
[i
], v
);
1347 isl_multi_val_free(mv
);
1350 isl_multi_val_free(mv
);
1351 return FN(MULTI(BASE
),free
)(multi
);
1354 /* Compute the residues of the elements of "multi" modulo
1355 * the corresponding element of "mv" and return the result.
1357 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),mod_multi_val
)(
1358 __isl_take
MULTI(BASE
) *multi
, __isl_take isl_multi_val
*mv
)
1365 if (!isl_space_tuple_is_equal(multi
->space
, isl_dim_out
,
1366 mv
->space
, isl_dim_set
))
1367 isl_die(isl_multi_val_get_ctx(mv
), isl_error_invalid
,
1368 "spaces don't match", goto error
);
1370 multi
= FN(MULTI(BASE
),cow
)(multi
);
1374 for (i
= 0; i
< multi
->n
; ++i
) {
1377 v
= isl_multi_val_get_val(mv
, i
);
1378 multi
->u
.p
[i
] = FN(EL
,mod_val
)(multi
->u
.p
[i
], v
);
1383 isl_multi_val_free(mv
);
1386 isl_multi_val_free(mv
);
1387 return FN(MULTI(BASE
),free
)(multi
);
1390 #ifndef NO_MOVE_DIMS
1391 /* Move the "n" dimensions of "src_type" starting at "src_pos" of "multi"
1392 * to dimensions of "dst_type" at "dst_pos".
1394 * We only support moving input dimensions to parameters and vice versa.
1396 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),move_dims
)(__isl_take
MULTI(BASE
) *multi
,
1397 enum isl_dim_type dst_type
, unsigned dst_pos
,
1398 enum isl_dim_type src_type
, unsigned src_pos
, unsigned n
)
1406 !isl_space_is_named_or_nested(multi
->space
, src_type
) &&
1407 !isl_space_is_named_or_nested(multi
->space
, dst_type
))
1410 if (dst_type
== isl_dim_out
|| src_type
== isl_dim_out
)
1411 isl_die(FN(MULTI(BASE
),get_ctx
)(multi
), isl_error_invalid
,
1412 "cannot move output/set dimension",
1413 return FN(MULTI(BASE
),free
)(multi
));
1414 if (dst_type
== isl_dim_div
|| src_type
== isl_dim_div
)
1415 isl_die(FN(MULTI(BASE
),get_ctx
)(multi
), isl_error_invalid
,
1417 return FN(MULTI(BASE
),free
)(multi
));
1418 if (src_pos
+ n
> isl_space_dim(multi
->space
, src_type
))
1419 isl_die(FN(MULTI(BASE
),get_ctx
)(multi
), isl_error_invalid
,
1420 "range out of bounds",
1421 return FN(MULTI(BASE
),free
)(multi
));
1422 if (dst_type
== src_type
)
1423 isl_die(FN(MULTI(BASE
),get_ctx
)(multi
), isl_error_unsupported
,
1424 "moving dims within the same type not supported",
1425 return FN(MULTI(BASE
),free
)(multi
));
1427 multi
= FN(MULTI(BASE
),cow
)(multi
);
1431 multi
->space
= isl_space_move_dims(multi
->space
, dst_type
, dst_pos
,
1432 src_type
, src_pos
, n
);
1434 return FN(MULTI(BASE
),free
)(multi
);
1435 if (FN(MULTI(BASE
),has_explicit_domain
)(multi
))
1436 multi
= FN(MULTI(BASE
),move_explicit_domain_dims
)(multi
,
1437 dst_type
, dst_pos
, src_type
, src_pos
, n
);
1441 for (i
= 0; i
< multi
->n
; ++i
) {
1442 multi
->u
.p
[i
] = FN(EL
,move_dims
)(multi
->u
.p
[i
],
1444 src_type
, src_pos
, n
);
1446 return FN(MULTI(BASE
),free
)(multi
);
1453 /* Convert a multiple expression defined over a parameter domain
1454 * into one that is defined over a zero-dimensional set.
1456 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),from_range
)(
1457 __isl_take
MULTI(BASE
) *multi
)
1463 if (!isl_space_is_set(multi
->space
))
1464 isl_die(FN(MULTI(BASE
),get_ctx
)(multi
), isl_error_invalid
,
1465 "not living in a set space",
1466 return FN(MULTI(BASE
),free
)(multi
));
1468 space
= FN(MULTI(BASE
),get_space
)(multi
);
1469 space
= isl_space_from_range(space
);
1470 multi
= FN(MULTI(BASE
),reset_space
)(multi
, space
);
1475 /* Are "multi1" and "multi2" obviously equal?
1477 isl_bool
FN(MULTI(BASE
),plain_is_equal
)(__isl_keep
MULTI(BASE
) *multi1
,
1478 __isl_keep
MULTI(BASE
) *multi2
)
1483 if (!multi1
|| !multi2
)
1484 return isl_bool_error
;
1485 if (multi1
->n
!= multi2
->n
)
1486 return isl_bool_false
;
1487 equal
= isl_space_is_equal(multi1
->space
, multi2
->space
);
1488 if (equal
< 0 || !equal
)
1491 for (i
= 0; i
< multi1
->n
; ++i
) {
1492 equal
= FN(EL
,plain_is_equal
)(multi1
->u
.p
[i
], multi2
->u
.p
[i
]);
1493 if (equal
< 0 || !equal
)
1497 if (FN(MULTI(BASE
),has_explicit_domain
)(multi1
) ||
1498 FN(MULTI(BASE
),has_explicit_domain
)(multi2
)) {
1499 equal
= FN(MULTI(BASE
),equal_explicit_domain
)(multi1
, multi2
);
1500 if (equal
< 0 || !equal
)
1504 return isl_bool_true
;
1507 /* Does "multi" involve any NaNs?
1509 isl_bool
FN(MULTI(BASE
),involves_nan
)(__isl_keep
MULTI(BASE
) *multi
)
1514 return isl_bool_error
;
1516 return isl_bool_false
;
1518 for (i
= 0; i
< multi
->n
; ++i
) {
1519 isl_bool has_nan
= FN(EL
,involves_nan
)(multi
->u
.p
[i
]);
1520 if (has_nan
< 0 || has_nan
)
1524 return isl_bool_false
;
1528 /* Return the shared domain of the elements of "multi".
1530 * If "multi" has an explicit domain, then return this domain.
1532 __isl_give isl_set
*FN(MULTI(BASE
),domain
)(__isl_take
MULTI(BASE
) *multi
)
1540 if (FN(MULTI(BASE
),has_explicit_domain
)(multi
)) {
1541 dom
= FN(MULTI(BASE
),get_explicit_domain
)(multi
);
1542 FN(MULTI(BASE
),free
)(multi
);
1546 dom
= isl_set_universe(FN(MULTI(BASE
),get_domain_space
)(multi
));
1547 for (i
= 0; i
< multi
->n
; ++i
) {
1550 dom_i
= FN(EL
,domain
)(FN(FN(MULTI(BASE
),get
),BASE
)(multi
, i
));
1551 dom
= isl_set_intersect(dom
, dom_i
);
1554 FN(MULTI(BASE
),free
)(multi
);
1560 /* Return the opposite of "multi".
1562 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),neg
)(__isl_take
MULTI(BASE
) *multi
)
1566 multi
= FN(MULTI(BASE
),cow
)(multi
);
1570 for (i
= 0; i
< multi
->n
; ++i
) {
1571 multi
->u
.p
[i
] = FN(EL
,neg
)(multi
->u
.p
[i
]);
1573 return FN(MULTI(BASE
),free
)(multi
);