2 #include <isl_val_private.h>
4 #define xFN(TYPE,NAME) TYPE ## _ ## NAME
5 #define FN(TYPE,NAME) xFN(TYPE,NAME)
6 #define xS(TYPE,NAME) struct TYPE ## _ ## NAME
7 #define S(TYPE,NAME) xS(TYPE,NAME)
10 __isl_give PW
*FN(PW
,alloc_size
)(__isl_take isl_space
*dim
,
11 enum isl_fold type
, int n
)
13 __isl_give PW
*FN(PW
,alloc_size
)(__isl_take isl_space
*dim
, int n
)
21 ctx
= isl_space_get_ctx(dim
);
22 isl_assert(ctx
, n
>= 0, goto error
);
23 pw
= isl_alloc(ctx
, struct PW
,
24 sizeof(struct PW
) + (n
- 1) * sizeof(S(PW
,piece
)));
42 __isl_give PW
*FN(PW
,ZERO
)(__isl_take isl_space
*dim
, enum isl_fold type
)
44 return FN(PW
,alloc_size
)(dim
, type
, 0);
47 __isl_give PW
*FN(PW
,ZERO
)(__isl_take isl_space
*dim
)
49 return FN(PW
,alloc_size
)(dim
, 0);
53 __isl_give PW
*FN(PW
,add_piece
)(__isl_take PW
*pw
,
54 __isl_take isl_set
*set
, __isl_take EL
*el
)
57 isl_space
*el_dim
= NULL
;
59 if (!pw
|| !set
|| !el
)
62 if (isl_set_plain_is_empty(set
) || FN(EL
,EL_IS_ZERO
)(el
)) {
68 ctx
= isl_set_get_ctx(set
);
70 if (pw
->type
!= el
->type
)
71 isl_die(ctx
, isl_error_invalid
, "fold types don't match",
74 el_dim
= FN(EL
,get_space(el
));
75 isl_assert(ctx
, isl_space_is_equal(pw
->dim
, el_dim
), goto error
);
76 isl_assert(ctx
, pw
->n
< pw
->size
, goto error
);
78 pw
->p
[pw
->n
].set
= set
;
79 pw
->p
[pw
->n
].FIELD
= el
;
82 isl_space_free(el_dim
);
85 isl_space_free(el_dim
);
93 __isl_give PW
*FN(PW
,alloc
)(enum isl_fold type
,
94 __isl_take isl_set
*set
, __isl_take EL
*el
)
96 __isl_give PW
*FN(PW
,alloc
)(__isl_take isl_set
*set
, __isl_take EL
*el
)
105 pw
= FN(PW
,alloc_size
)(FN(EL
,get_space
)(el
), type
, 1);
107 pw
= FN(PW
,alloc_size
)(FN(EL
,get_space
)(el
), 1);
110 return FN(PW
,add_piece
)(pw
, set
, el
);
117 __isl_give PW
*FN(PW
,dup
)(__isl_keep PW
*pw
)
126 dup
= FN(PW
,alloc_size
)(isl_space_copy(pw
->dim
), pw
->type
, pw
->n
);
128 dup
= FN(PW
,alloc_size
)(isl_space_copy(pw
->dim
), pw
->n
);
133 for (i
= 0; i
< pw
->n
; ++i
)
134 dup
= FN(PW
,add_piece
)(dup
, isl_set_copy(pw
->p
[i
].set
),
135 FN(EL
,copy
)(pw
->p
[i
].FIELD
));
140 __isl_give PW
*FN(PW
,cow
)(__isl_take PW
*pw
)
148 return FN(PW
,dup
)(pw
);
151 __isl_give PW
*FN(PW
,copy
)(__isl_keep PW
*pw
)
160 void *FN(PW
,free
)(__isl_take PW
*pw
)
169 for (i
= 0; i
< pw
->n
; ++i
) {
170 isl_set_free(pw
->p
[i
].set
);
171 FN(EL
,free
)(pw
->p
[i
].FIELD
);
173 isl_space_free(pw
->dim
);
179 const char *FN(PW
,get_dim_name
)(__isl_keep PW
*pw
, enum isl_dim_type type
,
182 return pw
? isl_space_get_dim_name(pw
->dim
, type
, pos
) : NULL
;
185 int FN(PW
,has_dim_id
)(__isl_keep PW
*pw
, enum isl_dim_type type
, unsigned pos
)
187 return pw
? isl_space_has_dim_id(pw
->dim
, type
, pos
) : -1;
190 __isl_give isl_id
*FN(PW
,get_dim_id
)(__isl_keep PW
*pw
, enum isl_dim_type type
,
193 return pw
? isl_space_get_dim_id(pw
->dim
, type
, pos
) : NULL
;
196 int FN(PW
,has_tuple_name
)(__isl_keep PW
*pw
, enum isl_dim_type type
)
198 return pw
? isl_space_has_tuple_name(pw
->dim
, type
) : -1;
201 const char *FN(PW
,get_tuple_name
)(__isl_keep PW
*pw
, enum isl_dim_type type
)
203 return pw
? isl_space_get_tuple_name(pw
->dim
, type
) : NULL
;
206 int FN(PW
,has_tuple_id
)(__isl_keep PW
*pw
, enum isl_dim_type type
)
208 return pw
? isl_space_has_tuple_id(pw
->dim
, type
) : -1;
211 __isl_give isl_id
*FN(PW
,get_tuple_id
)(__isl_keep PW
*pw
, enum isl_dim_type type
)
213 return pw
? isl_space_get_tuple_id(pw
->dim
, type
) : NULL
;
216 int FN(PW
,IS_ZERO
)(__isl_keep PW
*pw
)
225 __isl_give PW
*FN(PW
,realign_domain
)(__isl_take PW
*pw
,
226 __isl_take isl_reordering
*exp
)
234 for (i
= 0; i
< pw
->n
; ++i
) {
235 pw
->p
[i
].set
= isl_set_realign(pw
->p
[i
].set
,
236 isl_reordering_copy(exp
));
239 pw
->p
[i
].FIELD
= FN(EL
,realign_domain
)(pw
->p
[i
].FIELD
,
240 isl_reordering_copy(exp
));
245 pw
= FN(PW
,reset_domain_space
)(pw
, isl_space_copy(exp
->dim
));
247 isl_reordering_free(exp
);
250 isl_reordering_free(exp
);
255 /* Align the parameters of "pw" to those of "model".
257 __isl_give PW
*FN(PW
,align_params
)(__isl_take PW
*pw
, __isl_take isl_space
*model
)
264 ctx
= isl_space_get_ctx(model
);
265 if (!isl_space_has_named_params(model
))
266 isl_die(ctx
, isl_error_invalid
,
267 "model has unnamed parameters", goto error
);
268 if (!isl_space_has_named_params(pw
->dim
))
269 isl_die(ctx
, isl_error_invalid
,
270 "input has unnamed parameters", goto error
);
271 if (!isl_space_match(pw
->dim
, isl_dim_param
, model
, isl_dim_param
)) {
274 model
= isl_space_drop_dims(model
, isl_dim_in
,
275 0, isl_space_dim(model
, isl_dim_in
));
276 model
= isl_space_drop_dims(model
, isl_dim_out
,
277 0, isl_space_dim(model
, isl_dim_out
));
278 exp
= isl_parameter_alignment_reordering(pw
->dim
, model
);
279 exp
= isl_reordering_extend_space(exp
,
280 FN(PW
,get_domain_space
)(pw
));
281 pw
= FN(PW
,realign_domain
)(pw
, exp
);
284 isl_space_free(model
);
287 isl_space_free(model
);
292 static __isl_give PW
*FN(PW
,align_params_pw_pw_and
)(__isl_take PW
*pw1
,
294 __isl_give PW
*(*fn
)(__isl_take PW
*pw1
, __isl_take PW
*pw2
))
300 if (isl_space_match(pw1
->dim
, isl_dim_param
, pw2
->dim
, isl_dim_param
))
302 ctx
= FN(PW
,get_ctx
)(pw1
);
303 if (!isl_space_has_named_params(pw1
->dim
) ||
304 !isl_space_has_named_params(pw2
->dim
))
305 isl_die(ctx
, isl_error_invalid
,
306 "unaligned unnamed parameters", goto error
);
307 pw1
= FN(PW
,align_params
)(pw1
, FN(PW
,get_space
)(pw2
));
308 pw2
= FN(PW
,align_params
)(pw2
, FN(PW
,get_space
)(pw1
));
316 static __isl_give PW
*FN(PW
,align_params_pw_set_and
)(__isl_take PW
*pw
,
317 __isl_take isl_set
*set
,
318 __isl_give PW
*(*fn
)(__isl_take PW
*pw
, __isl_take isl_set
*set
))
324 if (isl_space_match(pw
->dim
, isl_dim_param
, set
->dim
, isl_dim_param
))
326 ctx
= FN(PW
,get_ctx
)(pw
);
327 if (!isl_space_has_named_params(pw
->dim
) ||
328 !isl_space_has_named_params(set
->dim
))
329 isl_die(ctx
, isl_error_invalid
,
330 "unaligned unnamed parameters", goto error
);
331 pw
= FN(PW
,align_params
)(pw
, isl_set_get_space(set
));
332 set
= isl_set_align_params(set
, FN(PW
,get_space
)(pw
));
341 static __isl_give PW
*FN(PW
,union_add_aligned
)(__isl_take PW
*pw1
,
352 ctx
= isl_space_get_ctx(pw1
->dim
);
354 if (pw1
->type
!= pw2
->type
)
355 isl_die(ctx
, isl_error_invalid
,
356 "fold types don't match", goto error
);
358 isl_assert(ctx
, isl_space_is_equal(pw1
->dim
, pw2
->dim
), goto error
);
360 if (FN(PW
,IS_ZERO
)(pw1
)) {
365 if (FN(PW
,IS_ZERO
)(pw2
)) {
370 n
= (pw1
->n
+ 1) * (pw2
->n
+ 1);
372 res
= FN(PW
,alloc_size
)(isl_space_copy(pw1
->dim
), pw1
->type
, n
);
374 res
= FN(PW
,alloc_size
)(isl_space_copy(pw1
->dim
), n
);
377 for (i
= 0; i
< pw1
->n
; ++i
) {
378 set
= isl_set_copy(pw1
->p
[i
].set
);
379 for (j
= 0; j
< pw2
->n
; ++j
) {
380 struct isl_set
*common
;
382 common
= isl_set_intersect(isl_set_copy(pw1
->p
[i
].set
),
383 isl_set_copy(pw2
->p
[j
].set
));
384 if (isl_set_plain_is_empty(common
)) {
385 isl_set_free(common
);
388 set
= isl_set_subtract(set
,
389 isl_set_copy(pw2
->p
[j
].set
));
391 sum
= FN(EL
,add_on_domain
)(common
,
392 FN(EL
,copy
)(pw1
->p
[i
].FIELD
),
393 FN(EL
,copy
)(pw2
->p
[j
].FIELD
));
395 res
= FN(PW
,add_piece
)(res
, common
, sum
);
397 res
= FN(PW
,add_piece
)(res
, set
, FN(EL
,copy
)(pw1
->p
[i
].FIELD
));
400 for (j
= 0; j
< pw2
->n
; ++j
) {
401 set
= isl_set_copy(pw2
->p
[j
].set
);
402 for (i
= 0; i
< pw1
->n
; ++i
)
403 set
= isl_set_subtract(set
,
404 isl_set_copy(pw1
->p
[i
].set
));
405 res
= FN(PW
,add_piece
)(res
, set
, FN(EL
,copy
)(pw2
->p
[j
].FIELD
));
418 /* Private version of "union_add". For isl_pw_qpolynomial and
419 * isl_pw_qpolynomial_fold, we prefer to simply call it "add".
421 static __isl_give PW
*FN(PW
,union_add_
)(__isl_take PW
*pw1
, __isl_take PW
*pw2
)
423 return FN(PW
,align_params_pw_pw_and
)(pw1
, pw2
,
424 &FN(PW
,union_add_aligned
));
427 /* Make sure "pw" has room for at least "n" more pieces.
429 * If there is only one reference to pw, we extend it in place.
430 * Otherwise, we create a new PW and copy the pieces.
432 static __isl_give PW
*FN(PW
,grow
)(__isl_take PW
*pw
, int n
)
440 if (pw
->n
+ n
<= pw
->size
)
442 ctx
= FN(PW
,get_ctx
)(pw
);
445 res
= isl_realloc(ctx
, pw
, struct PW
,
446 sizeof(struct PW
) + (n
- 1) * sizeof(S(PW
,piece
)));
448 return FN(PW
,free
)(pw
);
453 res
= FN(PW
,alloc_size
)(isl_space_copy(pw
->dim
), pw
->type
, n
);
455 res
= FN(PW
,alloc_size
)(isl_space_copy(pw
->dim
), n
);
458 return FN(PW
,free
)(pw
);
459 for (i
= 0; i
< pw
->n
; ++i
)
460 res
= FN(PW
,add_piece
)(res
, isl_set_copy(pw
->p
[i
].set
),
461 FN(EL
,copy
)(pw
->p
[i
].FIELD
));
466 static __isl_give PW
*FN(PW
,add_disjoint_aligned
)(__isl_take PW
*pw1
,
475 if (pw1
->size
< pw1
->n
+ pw2
->n
&& pw1
->n
< pw2
->n
)
476 return FN(PW
,add_disjoint_aligned
)(pw2
, pw1
);
478 ctx
= isl_space_get_ctx(pw1
->dim
);
480 if (pw1
->type
!= pw2
->type
)
481 isl_die(ctx
, isl_error_invalid
,
482 "fold types don't match", goto error
);
484 isl_assert(ctx
, isl_space_is_equal(pw1
->dim
, pw2
->dim
), goto error
);
486 if (FN(PW
,IS_ZERO
)(pw1
)) {
491 if (FN(PW
,IS_ZERO
)(pw2
)) {
496 pw1
= FN(PW
,grow
)(pw1
, pw2
->n
);
500 for (i
= 0; i
< pw2
->n
; ++i
)
501 pw1
= FN(PW
,add_piece
)(pw1
,
502 isl_set_copy(pw2
->p
[i
].set
),
503 FN(EL
,copy
)(pw2
->p
[i
].FIELD
));
514 __isl_give PW
*FN(PW
,add_disjoint
)(__isl_take PW
*pw1
, __isl_take PW
*pw2
)
516 return FN(PW
,align_params_pw_pw_and
)(pw1
, pw2
,
517 &FN(PW
,add_disjoint_aligned
));
520 /* This function is currently only used from isl_aff.c
522 static __isl_give PW
*FN(PW
,on_shared_domain_in
)(__isl_take PW
*pw1
,
523 __isl_take PW
*pw2
, __isl_take isl_space
*space
,
524 __isl_give EL
*(*fn
)(__isl_take EL
*el1
, __isl_take EL
*el2
))
525 __attribute__ ((unused
));
527 /* Apply "fn" to pairs of elements from pw1 and pw2 on shared domains.
528 * The result of "fn" (and therefore also of this function) lives in "space".
530 static __isl_give PW
*FN(PW
,on_shared_domain_in
)(__isl_take PW
*pw1
,
531 __isl_take PW
*pw2
, __isl_take isl_space
*space
,
532 __isl_give EL
*(*fn
)(__isl_take EL
*el1
, __isl_take EL
*el2
))
542 res
= FN(PW
,alloc_size
)(isl_space_copy(space
), pw1
->type
, n
);
544 res
= FN(PW
,alloc_size
)(isl_space_copy(space
), n
);
547 for (i
= 0; i
< pw1
->n
; ++i
) {
548 for (j
= 0; j
< pw2
->n
; ++j
) {
553 common
= isl_set_intersect(
554 isl_set_copy(pw1
->p
[i
].set
),
555 isl_set_copy(pw2
->p
[j
].set
));
556 empty
= isl_set_plain_is_empty(common
);
557 if (empty
< 0 || empty
) {
558 isl_set_free(common
);
564 res_ij
= fn(FN(EL
,copy
)(pw1
->p
[i
].FIELD
),
565 FN(EL
,copy
)(pw2
->p
[j
].FIELD
));
566 res_ij
= FN(EL
,gist
)(res_ij
, isl_set_copy(common
));
568 res
= FN(PW
,add_piece
)(res
, common
, res_ij
);
572 isl_space_free(space
);
577 isl_space_free(space
);
584 /* This function is currently only used from isl_aff.c
586 static __isl_give PW
*FN(PW
,on_shared_domain
)(__isl_take PW
*pw1
,
588 __isl_give EL
*(*fn
)(__isl_take EL
*el1
, __isl_take EL
*el2
))
589 __attribute__ ((unused
));
591 /* Apply "fn" to pairs of elements from pw1 and pw2 on shared domains.
592 * The result of "fn" is assumed to live in the same space as "pw1" and "pw2".
594 static __isl_give PW
*FN(PW
,on_shared_domain
)(__isl_take PW
*pw1
,
596 __isl_give EL
*(*fn
)(__isl_take EL
*el1
, __isl_take EL
*el2
))
603 space
= isl_space_copy(pw1
->dim
);
604 return FN(PW
,on_shared_domain_in
)(pw1
, pw2
, space
, fn
);
612 __isl_give PW
*FN(PW
,neg
)(__isl_take PW
*pw
)
619 if (FN(PW
,IS_ZERO
)(pw
))
626 for (i
= 0; i
< pw
->n
; ++i
) {
627 pw
->p
[i
].FIELD
= FN(EL
,neg
)(pw
->p
[i
].FIELD
);
629 return FN(PW
,free
)(pw
);
635 __isl_give PW
*FN(PW
,sub
)(__isl_take PW
*pw1
, __isl_take PW
*pw2
)
637 return FN(PW
,add
)(pw1
, FN(PW
,neg
)(pw2
));
642 __isl_give isl_val
*FN(PW
,eval
)(__isl_take PW
*pw
, __isl_take isl_point
*pnt
)
647 isl_space
*pnt_dim
= NULL
;
652 ctx
= isl_point_get_ctx(pnt
);
653 pnt_dim
= isl_point_get_space(pnt
);
654 isl_assert(ctx
, isl_space_is_domain_internal(pnt_dim
, pw
->dim
),
657 for (i
= 0; i
< pw
->n
; ++i
) {
658 found
= isl_set_contains_point(pw
->p
[i
].set
, pnt
);
665 v
= FN(EL
,eval
)(FN(EL
,copy
)(pw
->p
[i
].FIELD
),
666 isl_point_copy(pnt
));
668 v
= isl_val_zero(ctx
);
670 isl_space_free(pnt_dim
);
675 isl_space_free(pnt_dim
);
681 __isl_give isl_set
*FN(PW
,domain
)(__isl_take PW
*pw
)
689 dom
= isl_set_empty(FN(PW
,get_domain_space
)(pw
));
690 for (i
= 0; i
< pw
->n
; ++i
)
691 dom
= isl_set_union_disjoint(dom
, isl_set_copy(pw
->p
[i
].set
));
698 /* Exploit the equalities in the domain of piece "i" of "pw"
699 * to simplify the associated function.
700 * If the domain of piece "i" is empty, then remove it entirely,
701 * replacing it with the final piece.
703 static int FN(PW
,exploit_equalities_and_remove_if_empty
)(__isl_keep PW
*pw
,
707 int empty
= isl_set_plain_is_empty(pw
->p
[i
].set
);
712 isl_set_free(pw
->p
[i
].set
);
713 FN(EL
,free
)(pw
->p
[i
].FIELD
);
715 pw
->p
[i
] = pw
->p
[pw
->n
- 1];
721 aff
= isl_set_affine_hull(isl_set_copy(pw
->p
[i
].set
));
722 pw
->p
[i
].FIELD
= FN(EL
,substitute_equalities
)(pw
->p
[i
].FIELD
, aff
);
729 /* Restrict the domain of "pw" by combining each cell
730 * with "set" through a call to "fn", where "fn" may be
731 * isl_set_intersect or isl_set_intersect_params.
733 static __isl_give PW
*FN(PW
,intersect_aligned
)(__isl_take PW
*pw
,
734 __isl_take isl_set
*set
,
735 __isl_give isl_set
*(*fn
)(__isl_take isl_set
*set1
,
736 __isl_take isl_set
*set2
))
752 for (i
= pw
->n
- 1; i
>= 0; --i
) {
753 pw
->p
[i
].set
= fn(pw
->p
[i
].set
, isl_set_copy(set
));
754 if (FN(PW
,exploit_equalities_and_remove_if_empty
)(pw
, i
) < 0)
766 static __isl_give PW
*FN(PW
,intersect_domain_aligned
)(__isl_take PW
*pw
,
767 __isl_take isl_set
*set
)
769 return FN(PW
,intersect_aligned
)(pw
, set
, &isl_set_intersect
);
772 __isl_give PW
*FN(PW
,intersect_domain
)(__isl_take PW
*pw
,
773 __isl_take isl_set
*context
)
775 return FN(PW
,align_params_pw_set_and
)(pw
, context
,
776 &FN(PW
,intersect_domain_aligned
));
779 static __isl_give PW
*FN(PW
,intersect_params_aligned
)(__isl_take PW
*pw
,
780 __isl_take isl_set
*set
)
782 return FN(PW
,intersect_aligned
)(pw
, set
, &isl_set_intersect_params
);
785 /* Intersect the domain of "pw" with the parameter domain "context".
787 __isl_give PW
*FN(PW
,intersect_params
)(__isl_take PW
*pw
,
788 __isl_take isl_set
*context
)
790 return FN(PW
,align_params_pw_set_and
)(pw
, context
,
791 &FN(PW
,intersect_params_aligned
));
794 static __isl_give PW
*FN(PW
,gist_aligned
)(__isl_take PW
*pw
,
795 __isl_take isl_set
*context
,
796 __isl_give EL
*(*fn_el
)(__isl_take EL
*el
,
797 __isl_take isl_set
*set
),
798 __isl_give isl_set
*(*fn_dom
)(__isl_take isl_set
*set
,
799 __isl_take isl_basic_set
*bset
))
802 isl_basic_set
*hull
= NULL
;
808 isl_set_free(context
);
812 if (!isl_space_match(pw
->dim
, isl_dim_param
,
813 context
->dim
, isl_dim_param
)) {
814 pw
= FN(PW
,align_params
)(pw
, isl_set_get_space(context
));
815 context
= isl_set_align_params(context
, FN(PW
,get_space
)(pw
));
818 context
= isl_set_compute_divs(context
);
819 hull
= isl_set_simple_hull(isl_set_copy(context
));
825 for (i
= pw
->n
- 1; i
>= 0; --i
) {
829 set_i
= isl_set_intersect(isl_set_copy(pw
->p
[i
].set
),
830 isl_set_copy(context
));
831 empty
= isl_set_plain_is_empty(set_i
);
832 pw
->p
[i
].FIELD
= fn_el(pw
->p
[i
].FIELD
, set_i
);
833 pw
->p
[i
].set
= fn_dom(pw
->p
[i
].set
, isl_basic_set_copy(hull
));
834 if (!pw
->p
[i
].FIELD
|| !pw
->p
[i
].set
)
837 isl_set_free(pw
->p
[i
].set
);
838 FN(EL
,free
)(pw
->p
[i
].FIELD
);
840 pw
->p
[i
] = pw
->p
[pw
->n
- 1];
845 isl_basic_set_free(hull
);
846 isl_set_free(context
);
851 isl_basic_set_free(hull
);
852 isl_set_free(context
);
856 static __isl_give PW
*FN(PW
,gist_domain_aligned
)(__isl_take PW
*pw
,
857 __isl_take isl_set
*set
)
859 return FN(PW
,gist_aligned
)(pw
, set
, &FN(EL
,gist
),
860 &isl_set_gist_basic_set
);
863 __isl_give PW
*FN(PW
,gist
)(__isl_take PW
*pw
, __isl_take isl_set
*context
)
865 return FN(PW
,align_params_pw_set_and
)(pw
, context
,
866 &FN(PW
,gist_domain_aligned
));
869 static __isl_give PW
*FN(PW
,gist_params_aligned
)(__isl_take PW
*pw
,
870 __isl_take isl_set
*set
)
872 return FN(PW
,gist_aligned
)(pw
, set
, &FN(EL
,gist_params
),
873 &isl_set_gist_params_basic_set
);
876 __isl_give PW
*FN(PW
,gist_params
)(__isl_take PW
*pw
,
877 __isl_take isl_set
*context
)
879 return FN(PW
,align_params_pw_set_and
)(pw
, context
,
880 &FN(PW
,gist_params_aligned
));
883 __isl_give PW
*FN(PW
,coalesce
)(__isl_take PW
*pw
)
892 for (i
= pw
->n
- 1; i
>= 0; --i
) {
893 for (j
= i
- 1; j
>= 0; --j
) {
894 if (!FN(EL
,plain_is_equal
)(pw
->p
[i
].FIELD
,
897 pw
->p
[j
].set
= isl_set_union(pw
->p
[j
].set
,
899 FN(EL
,free
)(pw
->p
[i
].FIELD
);
901 pw
->p
[i
] = pw
->p
[pw
->n
- 1];
907 pw
->p
[i
].set
= isl_set_coalesce(pw
->p
[i
].set
);
918 isl_ctx
*FN(PW
,get_ctx
)(__isl_keep PW
*pw
)
920 return pw
? isl_space_get_ctx(pw
->dim
) : NULL
;
923 #ifndef NO_INVOLVES_DIMS
924 int FN(PW
,involves_dims
)(__isl_keep PW
*pw
, enum isl_dim_type type
,
925 unsigned first
, unsigned n
)
928 enum isl_dim_type set_type
;
932 if (pw
->n
== 0 || n
== 0)
935 set_type
= type
== isl_dim_in
? isl_dim_set
: type
;
937 for (i
= 0; i
< pw
->n
; ++i
) {
938 int involves
= FN(EL
,involves_dims
)(pw
->p
[i
].FIELD
,
940 if (involves
< 0 || involves
)
942 involves
= isl_set_involves_dims(pw
->p
[i
].set
,
944 if (involves
< 0 || involves
)
951 __isl_give PW
*FN(PW
,set_dim_name
)(__isl_take PW
*pw
,
952 enum isl_dim_type type
, unsigned pos
, const char *s
)
955 enum isl_dim_type set_type
;
961 set_type
= type
== isl_dim_in
? isl_dim_set
: type
;
963 pw
->dim
= isl_space_set_dim_name(pw
->dim
, type
, pos
, s
);
967 for (i
= 0; i
< pw
->n
; ++i
) {
968 pw
->p
[i
].set
= isl_set_set_dim_name(pw
->p
[i
].set
,
972 pw
->p
[i
].FIELD
= FN(EL
,set_dim_name
)(pw
->p
[i
].FIELD
, type
, pos
, s
);
984 __isl_give PW
*FN(PW
,drop_dims
)(__isl_take PW
*pw
,
985 enum isl_dim_type type
, unsigned first
, unsigned n
)
988 enum isl_dim_type set_type
;
992 if (n
== 0 && !isl_space_get_tuple_name(pw
->dim
, type
))
995 set_type
= type
== isl_dim_in
? isl_dim_set
: type
;
1000 pw
->dim
= isl_space_drop_dims(pw
->dim
, type
, first
, n
);
1003 for (i
= 0; i
< pw
->n
; ++i
) {
1004 pw
->p
[i
].FIELD
= FN(EL
,drop_dims
)(pw
->p
[i
].FIELD
, type
, first
, n
);
1005 if (!pw
->p
[i
].FIELD
)
1007 if (type
== isl_dim_out
)
1009 pw
->p
[i
].set
= isl_set_drop(pw
->p
[i
].set
, set_type
, first
, n
);
1020 /* This function is very similar to drop_dims.
1021 * The only difference is that the cells may still involve
1022 * the specified dimensions. They are removed using
1023 * isl_set_project_out instead of isl_set_drop.
1025 __isl_give PW
*FN(PW
,project_out
)(__isl_take PW
*pw
,
1026 enum isl_dim_type type
, unsigned first
, unsigned n
)
1029 enum isl_dim_type set_type
;
1033 if (n
== 0 && !isl_space_get_tuple_name(pw
->dim
, type
))
1036 set_type
= type
== isl_dim_in
? isl_dim_set
: type
;
1038 pw
= FN(PW
,cow
)(pw
);
1041 pw
->dim
= isl_space_drop_dims(pw
->dim
, type
, first
, n
);
1044 for (i
= 0; i
< pw
->n
; ++i
) {
1045 pw
->p
[i
].set
= isl_set_project_out(pw
->p
[i
].set
,
1046 set_type
, first
, n
);
1049 pw
->p
[i
].FIELD
= FN(EL
,drop_dims
)(pw
->p
[i
].FIELD
, type
, first
, n
);
1050 if (!pw
->p
[i
].FIELD
)
1060 /* Project the domain of pw onto its parameter space.
1062 __isl_give PW
*FN(PW
,project_domain_on_params
)(__isl_take PW
*pw
)
1067 n
= FN(PW
,dim
)(pw
, isl_dim_in
);
1068 pw
= FN(PW
,project_out
)(pw
, isl_dim_in
, 0, n
);
1069 space
= FN(PW
,get_domain_space
)(pw
);
1070 space
= isl_space_params(space
);
1071 pw
= FN(PW
,reset_domain_space
)(pw
, space
);
1076 #ifndef NO_INSERT_DIMS
1077 __isl_give PW
*FN(PW
,insert_dims
)(__isl_take PW
*pw
, enum isl_dim_type type
,
1078 unsigned first
, unsigned n
)
1081 enum isl_dim_type set_type
;
1085 if (n
== 0 && !isl_space_is_named_or_nested(pw
->dim
, type
))
1088 set_type
= type
== isl_dim_in
? isl_dim_set
: type
;
1090 pw
= FN(PW
,cow
)(pw
);
1094 pw
->dim
= isl_space_insert_dims(pw
->dim
, type
, first
, n
);
1098 for (i
= 0; i
< pw
->n
; ++i
) {
1099 pw
->p
[i
].set
= isl_set_insert_dims(pw
->p
[i
].set
,
1100 set_type
, first
, n
);
1103 pw
->p
[i
].FIELD
= FN(EL
,insert_dims
)(pw
->p
[i
].FIELD
,
1105 if (!pw
->p
[i
].FIELD
)
1116 __isl_give PW
*FN(PW
,fix_dim
)(__isl_take PW
*pw
,
1117 enum isl_dim_type type
, unsigned pos
, isl_int v
)
1124 if (type
== isl_dim_in
)
1127 pw
= FN(PW
,cow
)(pw
);
1130 for (i
= 0; i
< pw
->n
; ++i
) {
1131 pw
->p
[i
].set
= isl_set_fix(pw
->p
[i
].set
, type
, pos
, v
);
1132 if (FN(PW
,exploit_equalities_and_remove_if_empty
)(pw
, i
) < 0)
1133 return FN(PW
,free
)(pw
);
1139 /* Fix the value of the variable at position "pos" of type "type" of "pw"
1140 * to be equal to "v".
1142 __isl_give PW
*FN(PW
,fix_val
)(__isl_take PW
*pw
,
1143 enum isl_dim_type type
, unsigned pos
, __isl_take isl_val
*v
)
1146 return FN(PW
,free
)(pw
);
1147 if (!isl_val_is_int(v
))
1148 isl_die(FN(PW
,get_ctx
)(pw
), isl_error_invalid
,
1149 "expecting integer value", goto error
);
1151 pw
= FN(PW
,fix_dim
)(pw
, type
, pos
, v
->n
);
1157 return FN(PW
,free
)(pw
);
1160 unsigned FN(PW
,dim
)(__isl_keep PW
*pw
, enum isl_dim_type type
)
1162 return pw
? isl_space_dim(pw
->dim
, type
) : 0;
1165 __isl_give PW
*FN(PW
,split_dims
)(__isl_take PW
*pw
,
1166 enum isl_dim_type type
, unsigned first
, unsigned n
)
1175 if (type
== isl_dim_in
)
1178 pw
= FN(PW
,cow
)(pw
);
1183 for (i
= 0; i
< pw
->n
; ++i
) {
1184 pw
->p
[i
].set
= isl_set_split_dims(pw
->p
[i
].set
, type
, first
, n
);
1196 /* Compute the maximal value attained by the piecewise quasipolynomial
1197 * on its domain or zero if the domain is empty.
1198 * In the worst case, the domain is scanned completely,
1199 * so the domain is assumed to be bounded.
1201 __isl_give isl_val
*FN(PW
,opt
)(__isl_take PW
*pw
, int max
)
1210 opt
= isl_val_zero(FN(PW
,get_ctx
)(pw
));
1215 opt
= FN(EL
,opt_on_domain
)(FN(EL
,copy
)(pw
->p
[0].FIELD
),
1216 isl_set_copy(pw
->p
[0].set
), max
);
1217 for (i
= 1; i
< pw
->n
; ++i
) {
1219 opt_i
= FN(EL
,opt_on_domain
)(FN(EL
,copy
)(pw
->p
[i
].FIELD
),
1220 isl_set_copy(pw
->p
[i
].set
), max
);
1222 opt
= isl_val_max(opt
, opt_i
);
1224 opt
= isl_val_min(opt
, opt_i
);
1231 __isl_give isl_val
*FN(PW
,max
)(__isl_take PW
*pw
)
1233 return FN(PW
,opt
)(pw
, 1);
1236 __isl_give isl_val
*FN(PW
,min
)(__isl_take PW
*pw
)
1238 return FN(PW
,opt
)(pw
, 0);
1242 __isl_give isl_space
*FN(PW
,get_space
)(__isl_keep PW
*pw
)
1244 return pw
? isl_space_copy(pw
->dim
) : NULL
;
1247 __isl_give isl_space
*FN(PW
,get_domain_space
)(__isl_keep PW
*pw
)
1249 return pw
? isl_space_domain(isl_space_copy(pw
->dim
)) : NULL
;
1252 #ifndef NO_RESET_DIM
1253 /* Reset the space of "pw". Since we don't know if the elements
1254 * represent the spaces themselves or their domains, we pass along
1255 * both when we call their reset_space_and_domain.
1257 static __isl_give PW
*FN(PW
,reset_space_and_domain
)(__isl_take PW
*pw
,
1258 __isl_take isl_space
*space
, __isl_take isl_space
*domain
)
1262 pw
= FN(PW
,cow
)(pw
);
1263 if (!pw
|| !space
|| !domain
)
1266 for (i
= 0; i
< pw
->n
; ++i
) {
1267 pw
->p
[i
].set
= isl_set_reset_space(pw
->p
[i
].set
,
1268 isl_space_copy(domain
));
1271 pw
->p
[i
].FIELD
= FN(EL
,reset_space_and_domain
)(pw
->p
[i
].FIELD
,
1272 isl_space_copy(space
), isl_space_copy(domain
));
1273 if (!pw
->p
[i
].FIELD
)
1277 isl_space_free(domain
);
1279 isl_space_free(pw
->dim
);
1284 isl_space_free(domain
);
1285 isl_space_free(space
);
1290 __isl_give PW
*FN(PW
,reset_domain_space
)(__isl_take PW
*pw
,
1291 __isl_take isl_space
*domain
)
1295 space
= isl_space_extend_domain_with_range(isl_space_copy(domain
),
1296 FN(PW
,get_space
)(pw
));
1297 return FN(PW
,reset_space_and_domain
)(pw
, space
, domain
);
1300 __isl_give PW
*FN(PW
,reset_space
)(__isl_take PW
*pw
, __isl_take isl_space
*dim
)
1304 domain
= isl_space_domain(isl_space_copy(dim
));
1305 return FN(PW
,reset_space_and_domain
)(pw
, dim
, domain
);
1308 __isl_give PW
*FN(PW
,set_tuple_id
)(__isl_keep PW
*pw
, enum isl_dim_type type
,
1309 __isl_take isl_id
*id
)
1313 pw
= FN(PW
,cow
)(pw
);
1315 return isl_id_free(id
);
1317 space
= FN(PW
,get_space
)(pw
);
1318 space
= isl_space_set_tuple_id(space
, type
, id
);
1320 return FN(PW
,reset_space
)(pw
, space
);
1323 __isl_give PW
*FN(PW
,set_dim_id
)(__isl_take PW
*pw
,
1324 enum isl_dim_type type
, unsigned pos
, __isl_take isl_id
*id
)
1326 pw
= FN(PW
,cow
)(pw
);
1328 return isl_id_free(id
);
1329 pw
->dim
= isl_space_set_dim_id(pw
->dim
, type
, pos
, id
);
1330 return FN(PW
,reset_space
)(pw
, isl_space_copy(pw
->dim
));
1334 int FN(PW
,has_equal_space
)(__isl_keep PW
*pw1
, __isl_keep PW
*pw2
)
1339 return isl_space_is_equal(pw1
->dim
, pw2
->dim
);
1343 __isl_give PW
*FN(PW
,morph_domain
)(__isl_take PW
*pw
,
1344 __isl_take isl_morph
*morph
)
1352 ctx
= isl_space_get_ctx(pw
->dim
);
1353 isl_assert(ctx
, isl_space_is_domain_internal(morph
->dom
->dim
, pw
->dim
),
1356 pw
= FN(PW
,cow
)(pw
);
1359 pw
->dim
= isl_space_extend_domain_with_range(
1360 isl_space_copy(morph
->ran
->dim
), pw
->dim
);
1364 for (i
= 0; i
< pw
->n
; ++i
) {
1365 pw
->p
[i
].set
= isl_morph_set(isl_morph_copy(morph
), pw
->p
[i
].set
);
1368 pw
->p
[i
].FIELD
= FN(EL
,morph_domain
)(pw
->p
[i
].FIELD
,
1369 isl_morph_copy(morph
));
1370 if (!pw
->p
[i
].FIELD
)
1374 isl_morph_free(morph
);
1379 isl_morph_free(morph
);
1384 int FN(PW
,n_piece
)(__isl_keep PW
*pw
)
1386 return pw
? pw
->n
: 0;
1389 int FN(PW
,foreach_piece
)(__isl_keep PW
*pw
,
1390 int (*fn
)(__isl_take isl_set
*set
, __isl_take EL
*el
, void *user
),
1398 for (i
= 0; i
< pw
->n
; ++i
)
1399 if (fn(isl_set_copy(pw
->p
[i
].set
),
1400 FN(EL
,copy
)(pw
->p
[i
].FIELD
), user
) < 0)
1407 static int any_divs(__isl_keep isl_set
*set
)
1414 for (i
= 0; i
< set
->n
; ++i
)
1415 if (set
->p
[i
]->n_div
> 0)
1421 static int foreach_lifted_subset(__isl_take isl_set
*set
, __isl_take EL
*el
,
1422 int (*fn
)(__isl_take isl_set
*set
, __isl_take EL
*el
,
1423 void *user
), void *user
)
1430 for (i
= 0; i
< set
->n
; ++i
) {
1434 lift
= isl_set_from_basic_set(isl_basic_set_copy(set
->p
[i
]));
1435 lift
= isl_set_lift(lift
);
1437 copy
= FN(EL
,copy
)(el
);
1438 copy
= FN(EL
,lift
)(copy
, isl_set_get_space(lift
));
1440 if (fn(lift
, copy
, user
) < 0)
1454 int FN(PW
,foreach_lifted_piece
)(__isl_keep PW
*pw
,
1455 int (*fn
)(__isl_take isl_set
*set
, __isl_take EL
*el
,
1456 void *user
), void *user
)
1463 for (i
= 0; i
< pw
->n
; ++i
) {
1467 set
= isl_set_copy(pw
->p
[i
].set
);
1468 el
= FN(EL
,copy
)(pw
->p
[i
].FIELD
);
1469 if (!any_divs(set
)) {
1470 if (fn(set
, el
, user
) < 0)
1474 if (foreach_lifted_subset(set
, el
, fn
, user
) < 0)
1482 #ifndef NO_MOVE_DIMS
1483 __isl_give PW
*FN(PW
,move_dims
)(__isl_take PW
*pw
,
1484 enum isl_dim_type dst_type
, unsigned dst_pos
,
1485 enum isl_dim_type src_type
, unsigned src_pos
, unsigned n
)
1489 pw
= FN(PW
,cow
)(pw
);
1493 pw
->dim
= isl_space_move_dims(pw
->dim
, dst_type
, dst_pos
, src_type
, src_pos
, n
);
1497 for (i
= 0; i
< pw
->n
; ++i
) {
1498 pw
->p
[i
].FIELD
= FN(EL
,move_dims
)(pw
->p
[i
].FIELD
,
1499 dst_type
, dst_pos
, src_type
, src_pos
, n
);
1500 if (!pw
->p
[i
].FIELD
)
1504 if (dst_type
== isl_dim_in
)
1505 dst_type
= isl_dim_set
;
1506 if (src_type
== isl_dim_in
)
1507 src_type
= isl_dim_set
;
1509 for (i
= 0; i
< pw
->n
; ++i
) {
1510 pw
->p
[i
].set
= isl_set_move_dims(pw
->p
[i
].set
,
1512 src_type
, src_pos
, n
);
1524 __isl_give PW
*FN(PW
,mul_isl_int
)(__isl_take PW
*pw
, isl_int v
)
1528 if (isl_int_is_one(v
))
1530 if (pw
&& DEFAULT_IS_ZERO
&& isl_int_is_zero(v
)) {
1532 isl_space
*dim
= FN(PW
,get_space
)(pw
);
1534 zero
= FN(PW
,ZERO
)(dim
, pw
->type
);
1536 zero
= FN(PW
,ZERO
)(dim
);
1541 pw
= FN(PW
,cow
)(pw
);
1548 if (isl_int_is_neg(v
))
1549 pw
->type
= isl_fold_type_negate(pw
->type
);
1551 for (i
= 0; i
< pw
->n
; ++i
) {
1552 pw
->p
[i
].FIELD
= FN(EL
,scale
)(pw
->p
[i
].FIELD
, v
);
1553 if (!pw
->p
[i
].FIELD
)
1563 /* Multiply the pieces of "pw" by "v" and return the result.
1565 __isl_give PW
*FN(PW
,scale_val
)(__isl_take PW
*pw
, __isl_take isl_val
*v
)
1572 if (isl_val_is_one(v
)) {
1576 if (pw
&& DEFAULT_IS_ZERO
&& isl_val_is_zero(v
)) {
1578 isl_space
*space
= FN(PW
,get_space
)(pw
);
1580 zero
= FN(PW
,ZERO
)(space
, pw
->type
);
1582 zero
= FN(PW
,ZERO
)(space
);
1592 pw
= FN(PW
,cow
)(pw
);
1597 if (isl_val_is_neg(v
))
1598 pw
->type
= isl_fold_type_negate(pw
->type
);
1600 for (i
= 0; i
< pw
->n
; ++i
) {
1601 pw
->p
[i
].FIELD
= FN(EL
,scale_val
)(pw
->p
[i
].FIELD
,
1603 if (!pw
->p
[i
].FIELD
)
1615 __isl_give PW
*FN(PW
,scale
)(__isl_take PW
*pw
, isl_int v
)
1617 return FN(PW
,mul_isl_int
)(pw
, v
);
1620 static int FN(PW
,qsort_set_cmp
)(const void *p1
, const void *p2
)
1622 isl_set
*set1
= *(isl_set
* const *)p1
;
1623 isl_set
*set2
= *(isl_set
* const *)p2
;
1625 return isl_set_plain_cmp(set1
, set2
);
1628 /* We normalize in place, but if anything goes wrong we need
1629 * to return NULL, so we need to make sure we don't change the
1630 * meaning of any possible other copies of map.
1632 __isl_give PW
*FN(PW
,normalize
)(__isl_take PW
*pw
)
1639 for (i
= 0; i
< pw
->n
; ++i
) {
1640 set
= isl_set_normalize(isl_set_copy(pw
->p
[i
].set
));
1642 return FN(PW
,free
)(pw
);
1643 isl_set_free(pw
->p
[i
].set
);
1646 qsort(pw
->p
, pw
->n
, sizeof(pw
->p
[0]), &FN(PW
,qsort_set_cmp
));
1647 for (i
= pw
->n
- 1; i
>= 1; --i
) {
1648 if (!isl_set_plain_is_equal(pw
->p
[i
- 1].set
, pw
->p
[i
].set
))
1650 if (!FN(EL
,plain_is_equal
)(pw
->p
[i
- 1].FIELD
, pw
->p
[i
].FIELD
))
1652 set
= isl_set_union(isl_set_copy(pw
->p
[i
- 1].set
),
1653 isl_set_copy(pw
->p
[i
].set
));
1655 return FN(PW
,free
)(pw
);
1656 isl_set_free(pw
->p
[i
].set
);
1657 FN(EL
,free
)(pw
->p
[i
].FIELD
);
1658 isl_set_free(pw
->p
[i
- 1].set
);
1659 pw
->p
[i
- 1].set
= set
;
1660 for (j
= i
+ 1; j
< pw
->n
; ++j
)
1661 pw
->p
[j
- 1] = pw
->p
[j
];
1668 /* Is pw1 obviously equal to pw2?
1669 * That is, do they have obviously identical cells and obviously identical
1670 * elements on each cell?
1672 int FN(PW
,plain_is_equal
)(__isl_keep PW
*pw1
, __isl_keep PW
*pw2
)
1682 if (!isl_space_is_equal(pw1
->dim
, pw2
->dim
))
1685 pw1
= FN(PW
,copy
)(pw1
);
1686 pw2
= FN(PW
,copy
)(pw2
);
1687 pw1
= FN(PW
,normalize
)(pw1
);
1688 pw2
= FN(PW
,normalize
)(pw2
);
1692 equal
= pw1
->n
== pw2
->n
;
1693 for (i
= 0; equal
&& i
< pw1
->n
; ++i
) {
1694 equal
= isl_set_plain_is_equal(pw1
->p
[i
].set
, pw2
->p
[i
].set
);
1699 equal
= FN(EL
,plain_is_equal
)(pw1
->p
[i
].FIELD
, pw2
->p
[i
].FIELD
);
1714 static __isl_give PW
*FN(PW
,align_params_pw_multi_aff_and
)(__isl_take PW
*pw
,
1715 __isl_take isl_multi_aff
*ma
,
1716 __isl_give PW
*(*fn
)(__isl_take PW
*pw
, __isl_take isl_multi_aff
*ma
))
1719 isl_space
*ma_space
;
1721 ma_space
= isl_multi_aff_get_space(ma
);
1722 if (!pw
|| !ma
|| !ma_space
)
1724 if (isl_space_match(pw
->dim
, isl_dim_param
, ma_space
, isl_dim_param
)) {
1725 isl_space_free(ma_space
);
1728 ctx
= FN(PW
,get_ctx
)(pw
);
1729 if (!isl_space_has_named_params(pw
->dim
) ||
1730 !isl_space_has_named_params(ma_space
))
1731 isl_die(ctx
, isl_error_invalid
,
1732 "unaligned unnamed parameters", goto error
);
1733 pw
= FN(PW
,align_params
)(pw
, ma_space
);
1734 ma
= isl_multi_aff_align_params(ma
, FN(PW
,get_space
)(pw
));
1737 isl_space_free(ma_space
);
1739 isl_multi_aff_free(ma
);
1743 static __isl_give PW
*FN(PW
,align_params_pw_pw_multi_aff_and
)(__isl_take PW
*pw
,
1744 __isl_take isl_pw_multi_aff
*pma
,
1745 __isl_give PW
*(*fn
)(__isl_take PW
*pw
,
1746 __isl_take isl_pw_multi_aff
*ma
))
1749 isl_space
*pma_space
;
1751 pma_space
= isl_pw_multi_aff_get_space(pma
);
1752 if (!pw
|| !pma
|| !pma_space
)
1754 if (isl_space_match(pw
->dim
, isl_dim_param
, pma_space
, isl_dim_param
)) {
1755 isl_space_free(pma_space
);
1758 ctx
= FN(PW
,get_ctx
)(pw
);
1759 if (!isl_space_has_named_params(pw
->dim
) ||
1760 !isl_space_has_named_params(pma_space
))
1761 isl_die(ctx
, isl_error_invalid
,
1762 "unaligned unnamed parameters", goto error
);
1763 pw
= FN(PW
,align_params
)(pw
, pma_space
);
1764 pma
= isl_pw_multi_aff_align_params(pma
, FN(PW
,get_space
)(pw
));
1767 isl_space_free(pma_space
);
1769 isl_pw_multi_aff_free(pma
);
1773 /* Compute the pullback of "pw" by the function represented by "ma".
1774 * In other words, plug in "ma" in "pw".
1776 static __isl_give PW
*FN(PW
,pullback_multi_aff_aligned
)(__isl_take PW
*pw
,
1777 __isl_take isl_multi_aff
*ma
)
1780 isl_space
*space
= NULL
;
1782 ma
= isl_multi_aff_align_divs(ma
);
1783 pw
= FN(PW
,cow
)(pw
);
1787 space
= isl_space_join(isl_multi_aff_get_space(ma
),
1788 FN(PW
,get_space
)(pw
));
1790 for (i
= 0; i
< pw
->n
; ++i
) {
1791 pw
->p
[i
].set
= isl_set_preimage_multi_aff(pw
->p
[i
].set
,
1792 isl_multi_aff_copy(ma
));
1795 pw
->p
[i
].FIELD
= FN(EL
,pullback_multi_aff
)(pw
->p
[i
].FIELD
,
1796 isl_multi_aff_copy(ma
));
1797 if (!pw
->p
[i
].FIELD
)
1801 pw
= FN(PW
,reset_space
)(pw
, space
);
1802 isl_multi_aff_free(ma
);
1805 isl_space_free(space
);
1806 isl_multi_aff_free(ma
);
1811 __isl_give PW
*FN(PW
,pullback_multi_aff
)(__isl_take PW
*pw
,
1812 __isl_take isl_multi_aff
*ma
)
1814 return FN(PW
,align_params_pw_multi_aff_and
)(pw
, ma
,
1815 &FN(PW
,pullback_multi_aff_aligned
));
1818 /* Compute the pullback of "pw" by the function represented by "pma".
1819 * In other words, plug in "pma" in "pw".
1821 static __isl_give PW
*FN(PW
,pullback_pw_multi_aff_aligned
)(__isl_take PW
*pw
,
1822 __isl_take isl_pw_multi_aff
*pma
)
1831 isl_pw_multi_aff_free(pma
);
1832 res
= FN(PW
,empty
)(FN(PW
,get_space
)(pw
));
1837 res
= FN(PW
,pullback_multi_aff
)(FN(PW
,copy
)(pw
),
1838 isl_multi_aff_copy(pma
->p
[0].maff
));
1839 res
= FN(PW
,intersect_domain
)(res
, isl_set_copy(pma
->p
[0].set
));
1841 for (i
= 1; i
< pma
->n
; ++i
) {
1844 res_i
= FN(PW
,pullback_multi_aff
)(FN(PW
,copy
)(pw
),
1845 isl_multi_aff_copy(pma
->p
[i
].maff
));
1846 res_i
= FN(PW
,intersect_domain
)(res_i
,
1847 isl_set_copy(pma
->p
[i
].set
));
1848 res
= FN(PW
,add_disjoint
)(res
, res_i
);
1851 isl_pw_multi_aff_free(pma
);
1855 isl_pw_multi_aff_free(pma
);
1860 __isl_give PW
*FN(PW
,pullback_pw_multi_aff
)(__isl_take PW
*pw
,
1861 __isl_take isl_pw_multi_aff
*pma
)
1863 return FN(PW
,align_params_pw_pw_multi_aff_and
)(pw
, pma
,
1864 &FN(PW
,pullback_pw_multi_aff_aligned
));