2 * Copyright 2010 INRIA Saclay
3 * Copyright 2013 Ecole Normale Superieure
5 * Use of this software is governed by the MIT license
7 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
8 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
10 * and Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
13 __isl_give UNION
*FN(UNION
,cow
)(__isl_take UNION
*u
);
15 isl_ctx
*FN(UNION
,get_ctx
)(__isl_keep UNION
*u
)
17 return u
? u
->space
->ctx
: NULL
;
20 __isl_give isl_space
*FN(UNION
,get_space
)(__isl_keep UNION
*u
)
24 return isl_space_copy(u
->space
);
27 /* Return the number of parameters of "u", where "type"
28 * is required to be set to isl_dim_param.
30 unsigned FN(UNION
,dim
)(__isl_keep UNION
*u
, enum isl_dim_type type
)
35 if (type
!= isl_dim_param
)
36 isl_die(FN(UNION
,get_ctx
)(u
), isl_error_invalid
,
37 "can only reference parameters", return 0);
39 return isl_space_dim(u
->space
, type
);
42 /* Return the position of the parameter with the given name
44 * Return -1 if no such dimension can be found.
46 int FN(UNION
,find_dim_by_name
)(__isl_keep UNION
*u
, enum isl_dim_type type
,
51 return isl_space_find_dim_by_name(u
->space
, type
, name
);
55 static __isl_give UNION
*FN(UNION
,alloc
)(__isl_take isl_space
*dim
,
56 enum isl_fold type
, int size
)
58 static __isl_give UNION
*FN(UNION
,alloc
)(__isl_take isl_space
*dim
, int size
)
63 dim
= isl_space_params(dim
);
67 u
= isl_calloc_type(dim
->ctx
, UNION
);
76 if (isl_hash_table_init(dim
->ctx
, &u
->table
, size
) < 0)
77 return FN(UNION
,free
)(u
);
86 __isl_give UNION
*FN(UNION
,ZERO
)(__isl_take isl_space
*dim
, enum isl_fold type
)
88 return FN(UNION
,alloc
)(dim
, type
, 16);
91 __isl_give UNION
*FN(UNION
,ZERO
)(__isl_take isl_space
*dim
)
93 return FN(UNION
,alloc
)(dim
, 16);
97 __isl_give UNION
*FN(UNION
,copy
)(__isl_keep UNION
*u
)
106 /* Extract the element of "u" living in "space" (ignoring parameters).
108 * Return the ZERO element if "u" does not contain any element
111 __isl_give PART
*FN(FN(UNION
,extract
),PARTS
)(__isl_keep UNION
*u
,
112 __isl_take isl_space
*space
)
114 struct isl_hash_table_entry
*entry
;
115 isl_bool equal_params
;
119 equal_params
= isl_space_has_equal_params(u
->space
, space
);
120 if (equal_params
< 0)
123 space
= isl_space_drop_dims(space
, isl_dim_param
,
124 0, isl_space_dim(space
, isl_dim_param
));
125 space
= isl_space_align_params(space
,
126 FN(UNION
,get_space
)(u
));
131 entry
= FN(UNION
,find_part_entry
)(u
, space
, 0);
134 if (entry
== isl_hash_table_entry_none
)
136 return FN(PART
,ZERO
)(space
, u
->type
);
138 return FN(PART
,ZERO
)(space
);
140 isl_space_free(space
);
141 return FN(PART
,copy
)(entry
->data
);
143 isl_space_free(space
);
147 /* Add "part" to "u".
148 * If "disjoint" is set, then "u" is not allowed to already have
149 * a part that is defined over a domain that overlaps with the domain
151 * Otherwise, compute the union sum of "part" and the part in "u"
152 * defined on the same space.
154 static __isl_give UNION
*FN(UNION
,add_part_generic
)(__isl_take UNION
*u
,
155 __isl_take PART
*part
, int disjoint
)
158 struct isl_hash_table_entry
*entry
;
163 empty
= FN(PART
,IS_ZERO
)(part
);
171 u
= FN(UNION
,align_params
)(u
, FN(PART
,get_space
)(part
));
172 part
= FN(PART
,align_params
)(part
, FN(UNION
,get_space
)(u
));
174 u
= FN(UNION
,cow
)(u
);
179 if (FN(UNION
,check_disjoint_domain_other
)(u
, part
) < 0)
181 entry
= FN(UNION
,find_part_entry
)(u
, part
->dim
, 1);
189 FN(UNION
,check_disjoint_domain
)(entry
->data
, part
) < 0)
191 entry
->data
= FN(PART
,union_add_
)(entry
->data
,
192 FN(PART
,copy
)(part
));
195 empty
= FN(PART
,IS_ZERO
)(part
);
199 u
= FN(UNION
,remove_part_entry
)(u
, entry
);
210 /* Add "part" to "u", where "u" is assumed not to already have
211 * a part that is defined on the same space as "part".
213 __isl_give UNION
*FN(FN(UNION
,add
),PARTS
)(__isl_take UNION
*u
,
214 __isl_take PART
*part
)
216 return FN(UNION
,add_part_generic
)(u
, part
, 1);
220 /* Allocate a UNION with the same type and the same size as "u" and
221 * with space "space".
223 static __isl_give UNION
*FN(UNION
,alloc_same_size_on_space
)(__isl_keep UNION
*u
,
224 __isl_take isl_space
*space
)
228 return FN(UNION
,alloc
)(space
, u
->type
, u
->table
.n
);
230 isl_space_free(space
);
234 /* Allocate a UNION with the same size as "u" and with space "space".
236 static __isl_give UNION
*FN(UNION
,alloc_same_size_on_space
)(__isl_keep UNION
*u
,
237 __isl_take isl_space
*space
)
241 return FN(UNION
,alloc
)(space
, u
->table
.n
);
243 isl_space_free(space
);
248 /* Allocate a UNION with the same space, the same type (if any) and
249 * the same size as "u".
251 static __isl_give UNION
*FN(UNION
,alloc_same_size
)(__isl_keep UNION
*u
)
253 return FN(UNION
,alloc_same_size_on_space
)(u
, FN(UNION
,get_space
)(u
));
256 /* Internal data structure for isl_union_*_transform_space.
257 * "fn' is applied to each entry in the input.
258 * "res" collects the results.
260 S(UNION
,transform_data
)
262 __isl_give PART
*(*fn
)(__isl_take PART
*part
, void *user
);
268 /* Apply data->fn to "part" and add the result to data->res.
270 static isl_stat
FN(UNION
,transform_entry
)(__isl_take PART
*part
, void *user
)
272 S(UNION
,transform_data
) *data
= (S(UNION
,transform_data
) *)user
;
274 part
= data
->fn(part
, data
->user
);
275 data
->res
= FN(FN(UNION
,add
),PARTS
)(data
->res
, part
);
277 return isl_stat_error
;
282 /* Return a UNION living in "space" that is obtained by applying "fn"
283 * to each of the entries in "u".
285 static __isl_give UNION
*FN(UNION
,transform_space
)(__isl_take UNION
*u
,
287 __isl_give PART
*(*fn
)(__isl_take PART
*part
, void *user
), void *user
)
289 S(UNION
,transform_data
) data
= { fn
, user
};
291 data
.res
= FN(UNION
,alloc_same_size_on_space
)(u
, space
);
292 if (FN(FN(UNION
,foreach
),PARTS
)(u
,
293 &FN(UNION
,transform_entry
), &data
) < 0)
294 data
.res
= FN(UNION
,free
)(data
.res
);
299 /* Return a UNION that lives in the same space as "u" and that is obtained
300 * by applying "fn" to each of the entries in "u".
302 static __isl_give UNION
*FN(UNION
,transform
)(__isl_take UNION
*u
,
303 __isl_give PART
*(*fn
)(__isl_take PART
*part
, void *user
), void *user
)
305 return FN(UNION
,transform_space
)(u
, FN(UNION
,get_space
)(u
), fn
, user
);
308 /* Apply data->fn to *part and store the result back into *part.
310 static isl_stat
FN(UNION
,transform_inplace_entry
)(void **part
, void *user
)
312 S(UNION
,transform_data
) *data
= (S(UNION
,transform_data
) *) user
;
314 *part
= data
->fn(*part
, data
->user
);
316 return isl_stat_error
;
320 /* Update "u" by applying "fn" to each entry.
321 * This operation is assumed not to change the number of entries nor
322 * the spaces of the entries.
324 * If there is only one reference to "u", then change "u" inplace.
325 * Otherwise, create a new UNION from "u" and discard the original.
327 static __isl_give UNION
*FN(UNION
,transform_inplace
)(__isl_take UNION
*u
,
328 __isl_give PART
*(*fn
)(__isl_take PART
*part
, void *user
), void *user
)
332 single_ref
= FN(UNION
,has_single_reference
)(u
);
334 return FN(UNION
,free
)(u
);
336 S(UNION
,transform_data
) data
= { fn
, user
};
337 if (FN(UNION
,foreach_inplace
)(u
,
338 &FN(UNION
,transform_inplace_entry
), &data
) < 0)
339 return FN(UNION
,free
)(u
);
342 return FN(UNION
,transform
)(u
, fn
, user
);
345 /* An isl_union_*_transform callback for use in isl_union_*_dup
346 * that simply returns "part".
348 static __isl_give PART
*FN(UNION
,copy_part
)(__isl_take PART
*part
, void *user
)
353 __isl_give UNION
*FN(UNION
,dup
)(__isl_keep UNION
*u
)
355 u
= FN(UNION
,copy
)(u
);
356 return FN(UNION
,transform
)(u
, &FN(UNION
,copy_part
), NULL
);
359 __isl_give UNION
*FN(UNION
,cow
)(__isl_take UNION
*u
)
367 return FN(UNION
,dup
)(u
);
370 __isl_null UNION
*FN(UNION
,free
)(__isl_take UNION
*u
)
378 isl_hash_table_foreach(u
->space
->ctx
, &u
->table
,
379 &FN(UNION
,free_u_entry
), NULL
);
380 isl_hash_table_clear(&u
->table
);
381 isl_space_free(u
->space
);
386 static __isl_give PART
*FN(UNION
,align_entry
)(__isl_take PART
*part
, void *user
)
388 isl_reordering
*exp
= user
;
390 exp
= isl_reordering_extend_space(isl_reordering_copy(exp
),
391 FN(PART
,get_domain_space
)(part
));
392 return FN(PART
,realign_domain
)(part
, exp
);
395 /* Reorder the parameters of "u" according to the given reordering.
397 static __isl_give UNION
*FN(UNION
,realign_domain
)(__isl_take UNION
*u
,
398 __isl_take isl_reordering
*r
)
405 space
= isl_space_copy(r
->dim
);
406 u
= FN(UNION
,transform_space
)(u
, space
, &FN(UNION
,align_entry
), r
);
407 isl_reordering_free(r
);
411 isl_reordering_free(r
);
415 /* Align the parameters of "u" to those of "model".
417 __isl_give UNION
*FN(UNION
,align_params
)(__isl_take UNION
*u
,
418 __isl_take isl_space
*model
)
420 isl_bool equal_params
;
426 equal_params
= isl_space_has_equal_params(u
->space
, model
);
427 if (equal_params
< 0)
430 isl_space_free(model
);
434 model
= isl_space_params(model
);
435 r
= isl_parameter_alignment_reordering(u
->space
, model
);
436 isl_space_free(model
);
438 return FN(UNION
,realign_domain
)(u
, r
);
440 isl_space_free(model
);
445 /* Add "part" to *u, taking the union sum if "u" already has
446 * a part defined on the same space as "part".
448 static isl_stat
FN(UNION
,union_add_part
)(__isl_take PART
*part
, void *user
)
450 UNION
**u
= (UNION
**)user
;
452 *u
= FN(UNION
,add_part_generic
)(*u
, part
, 0);
457 /* Compute the sum of "u1" and "u2" on the union of their domains,
458 * with the actual sum on the shared domain and
459 * the defined expression on the symmetric difference of the domains.
461 * This is an internal function that is exposed under different
462 * names depending on whether the base expressions have a zero default
464 * If they do, then this function is called "add".
465 * Otherwise, it is called "union_add".
467 static __isl_give UNION
*FN(UNION
,union_add_
)(__isl_take UNION
*u1
,
468 __isl_take UNION
*u2
)
470 u1
= FN(UNION
,align_params
)(u1
, FN(UNION
,get_space
)(u2
));
471 u2
= FN(UNION
,align_params
)(u2
, FN(UNION
,get_space
)(u1
));
473 u1
= FN(UNION
,cow
)(u1
);
478 if (FN(FN(UNION
,foreach
),PARTS
)(u2
, &FN(UNION
,union_add_part
), &u1
) < 0)
490 __isl_give UNION
*FN(FN(UNION
,from
),PARTS
)(__isl_take PART
*part
)
498 dim
= FN(PART
,get_space
)(part
);
499 dim
= isl_space_drop_dims(dim
, isl_dim_in
, 0, isl_space_dim(dim
, isl_dim_in
));
500 dim
= isl_space_drop_dims(dim
, isl_dim_out
, 0, isl_space_dim(dim
, isl_dim_out
));
502 u
= FN(UNION
,ZERO
)(dim
, part
->type
);
504 u
= FN(UNION
,ZERO
)(dim
);
506 u
= FN(FN(UNION
,add
),PARTS
)(u
, part
);
511 S(UNION
,match_bin_data
) {
514 __isl_give PART
*(*fn
)(__isl_take PART
*, __isl_take PART
*);
517 /* Check if data->u2 has an element living in the same space as "part".
518 * If so, call data->fn on the two elements and add the result to
521 static isl_stat
FN(UNION
,match_bin_entry
)(__isl_take PART
*part
, void *user
)
523 S(UNION
,match_bin_data
) *data
= user
;
524 struct isl_hash_table_entry
*entry2
;
528 space
= FN(PART
,get_space
)(part
);
529 entry2
= FN(UNION
,find_part_entry
)(data
->u2
, space
, 0);
530 isl_space_free(space
);
533 if (entry2
== isl_hash_table_entry_none
) {
538 part2
= entry2
->data
;
539 if (!isl_space_tuple_is_equal(part
->dim
, isl_dim_out
,
540 part2
->dim
, isl_dim_out
))
541 isl_die(FN(UNION
,get_ctx
)(data
->u2
), isl_error_invalid
,
542 "entries should have the same range space",
545 part
= data
->fn(part
, FN(PART
, copy
)(entry2
->data
));
547 data
->res
= FN(FN(UNION
,add
),PARTS
)(data
->res
, part
);
549 return isl_stat_error
;
554 return isl_stat_error
;
557 /* This function is currently only used from isl_polynomial.c
558 * and not from isl_fold.c.
560 static __isl_give UNION
*FN(UNION
,match_bin_op
)(__isl_take UNION
*u1
,
561 __isl_take UNION
*u2
,
562 __isl_give PART
*(*fn
)(__isl_take PART
*, __isl_take PART
*))
563 __attribute__ ((unused
));
564 /* For each pair of elements in "u1" and "u2" living in the same space,
565 * call "fn" and collect the results.
567 static __isl_give UNION
*FN(UNION
,match_bin_op
)(__isl_take UNION
*u1
,
568 __isl_take UNION
*u2
,
569 __isl_give PART
*(*fn
)(__isl_take PART
*, __isl_take PART
*))
571 S(UNION
,match_bin_data
) data
= { NULL
, NULL
, fn
};
573 u1
= FN(UNION
,align_params
)(u1
, FN(UNION
,get_space
)(u2
));
574 u2
= FN(UNION
,align_params
)(u2
, FN(UNION
,get_space
)(u1
));
580 data
.res
= FN(UNION
,alloc_same_size
)(u1
);
581 if (FN(FN(UNION
,foreach
),PARTS
)(u1
,
582 &FN(UNION
,match_bin_entry
), &data
) < 0)
591 FN(UNION
,free
)(data
.res
);
595 /* Compute the sum of "u1" and "u2".
597 * If the base expressions have a default zero value, then the sum
598 * is computed on the union of the domains of "u1" and "u2".
599 * Otherwise, it is computed on their shared domains.
601 __isl_give UNION
*FN(UNION
,add
)(__isl_take UNION
*u1
, __isl_take UNION
*u2
)
604 return FN(UNION
,union_add_
)(u1
, u2
);
606 return FN(UNION
,match_bin_op
)(u1
, u2
, &FN(PART
,add
));
611 /* Subtract "u2" from "u1" and return the result.
613 __isl_give UNION
*FN(UNION
,sub
)(__isl_take UNION
*u1
, __isl_take UNION
*u2
)
615 return FN(UNION
,match_bin_op
)(u1
, u2
, &FN(PART
,sub
));
619 S(UNION
,any_set_data
) {
621 __isl_give PW
*(*fn
)(__isl_take PW
*, __isl_take isl_set
*);
624 static __isl_give PART
*FN(UNION
,any_set_entry
)(__isl_take PART
*part
,
627 S(UNION
,any_set_data
) *data
= user
;
629 return data
->fn(part
, isl_set_copy(data
->set
));
632 /* Update each element of "u" by calling "fn" on the element and "set".
634 static __isl_give UNION
*FN(UNION
,any_set_op
)(__isl_take UNION
*u
,
635 __isl_take isl_set
*set
,
636 __isl_give PW
*(*fn
)(__isl_take PW
*, __isl_take isl_set
*))
638 S(UNION
,any_set_data
) data
= { NULL
, fn
};
640 u
= FN(UNION
,align_params
)(u
, isl_set_get_space(set
));
641 set
= isl_set_align_params(set
, FN(UNION
,get_space
)(u
));
647 u
= FN(UNION
,transform
)(u
, &FN(UNION
,any_set_entry
), &data
);
656 /* Intersect the domain of "u" with the parameter domain "context".
658 __isl_give UNION
*FN(UNION
,intersect_params
)(__isl_take UNION
*u
,
659 __isl_take isl_set
*set
)
661 return FN(UNION
,any_set_op
)(u
, set
, &FN(PW
,intersect_params
));
664 /* Compute the gist of the domain of "u" with respect to
665 * the parameter domain "context".
667 __isl_give UNION
*FN(UNION
,gist_params
)(__isl_take UNION
*u
,
668 __isl_take isl_set
*set
)
670 return FN(UNION
,any_set_op
)(u
, set
, &FN(PW
,gist_params
));
673 S(UNION
,match_domain_data
) {
676 __isl_give PW
*(*fn
)(__isl_take PW
*, __isl_take isl_set
*);
679 static int FN(UNION
,set_has_dim
)(const void *entry
, const void *val
)
681 isl_set
*set
= (isl_set
*)entry
;
682 isl_space
*dim
= (isl_space
*)val
;
684 return isl_space_is_equal(set
->dim
, dim
);
687 /* Find the set in data->uset that lives in the same space as the domain
688 * of "part", apply data->fn to *entry and this set (if any), and add
689 * the result to data->res.
691 static isl_stat
FN(UNION
,match_domain_entry
)(__isl_take PART
*part
, void *user
)
693 S(UNION
,match_domain_data
) *data
= user
;
695 struct isl_hash_table_entry
*entry2
;
698 space
= FN(PART
,get_domain_space
)(part
);
699 hash
= isl_space_get_hash(space
);
700 entry2
= isl_hash_table_find(data
->uset
->dim
->ctx
, &data
->uset
->table
,
701 hash
, &FN(UNION
,set_has_dim
), space
, 0);
702 isl_space_free(space
);
708 part
= data
->fn(part
, isl_set_copy(entry2
->data
));
710 data
->res
= FN(FN(UNION
,add
),PARTS
)(data
->res
, part
);
712 return isl_stat_error
;
717 /* Apply fn to each pair of PW in u and set in uset such that
718 * the set lives in the same space as the domain of PW
719 * and collect the results.
721 static __isl_give UNION
*FN(UNION
,match_domain_op
)(__isl_take UNION
*u
,
722 __isl_take isl_union_set
*uset
,
723 __isl_give PW
*(*fn
)(__isl_take PW
*, __isl_take isl_set
*))
725 S(UNION
,match_domain_data
) data
= { NULL
, NULL
, fn
};
727 u
= FN(UNION
,align_params
)(u
, isl_union_set_get_space(uset
));
728 uset
= isl_union_set_align_params(uset
, FN(UNION
,get_space
)(u
));
734 data
.res
= FN(UNION
,alloc_same_size
)(u
);
735 if (FN(FN(UNION
,foreach
),PARTS
)(u
,
736 &FN(UNION
,match_domain_entry
), &data
) < 0)
740 isl_union_set_free(uset
);
744 isl_union_set_free(uset
);
745 FN(UNION
,free
)(data
.res
);
749 /* Intersect the domain of "u" with "uset".
750 * If "uset" is a parameters domain, then intersect the parameter
751 * domain of "u" with this set.
753 __isl_give UNION
*FN(UNION
,intersect_domain
)(__isl_take UNION
*u
,
754 __isl_take isl_union_set
*uset
)
756 if (isl_union_set_is_params(uset
))
757 return FN(UNION
,intersect_params
)(u
,
758 isl_set_from_union_set(uset
));
759 return FN(UNION
,match_domain_op
)(u
, uset
, &FN(PW
,intersect_domain
));
762 /* Take the set (which may be empty) in data->uset that lives
763 * in the same space as the domain of "pw", subtract it from the domain
764 * of "part" and return the result.
766 static __isl_give PART
*FN(UNION
,subtract_domain_entry
)(__isl_take PART
*part
,
769 isl_union_set
*uset
= user
;
773 space
= FN(PART
,get_domain_space
)(part
);
774 set
= isl_union_set_extract_set(uset
, space
);
775 return FN(PART
,subtract_domain
)(part
, set
);
778 /* Subtract "uset' from the domain of "u".
780 __isl_give UNION
*FN(UNION
,subtract_domain
)(__isl_take UNION
*u
,
781 __isl_take isl_union_set
*uset
)
783 u
= FN(UNION
,transform
)(u
, &FN(UNION
,subtract_domain_entry
), uset
);
784 isl_union_set_free(uset
);
788 __isl_give UNION
*FN(UNION
,gist
)(__isl_take UNION
*u
,
789 __isl_take isl_union_set
*uset
)
791 if (isl_union_set_is_params(uset
))
792 return FN(UNION
,gist_params
)(u
, isl_set_from_union_set(uset
));
793 return FN(UNION
,match_domain_op
)(u
, uset
, &FN(PW
,gist
));
796 /* Coalesce an entry in a UNION. Coalescing is performed in-place.
797 * Since the UNION may have several references, the entry is only
798 * replaced if the coalescing is successful.
800 static isl_stat
FN(UNION
,coalesce_entry
)(void **entry
, void *user
)
802 PART
**part_p
= (PART
**) entry
;
805 part
= FN(PART
,copy
)(*part_p
);
806 part
= FN(PW
,coalesce
)(part
);
808 return isl_stat_error
;
809 FN(PART
,free
)(*part_p
);
815 __isl_give UNION
*FN(UNION
,coalesce
)(__isl_take UNION
*u
)
817 if (FN(UNION
,foreach_inplace
)(u
, &FN(UNION
,coalesce_entry
), NULL
) < 0)
826 static isl_stat
FN(UNION
,domain_entry
)(__isl_take PART
*part
, void *user
)
828 isl_union_set
**uset
= (isl_union_set
**)user
;
830 *uset
= isl_union_set_add_set(*uset
, FN(PART
,domain
)(part
));
835 __isl_give isl_union_set
*FN(UNION
,domain
)(__isl_take UNION
*u
)
839 uset
= isl_union_set_empty(FN(UNION
,get_space
)(u
));
840 if (FN(FN(UNION
,foreach
),PARTS
)(u
, &FN(UNION
,domain_entry
), &uset
) < 0)
847 isl_union_set_free(uset
);
853 /* Negate the type of "u".
855 static __isl_give UNION
*FN(UNION
,negate_type
)(__isl_take UNION
*u
)
857 u
= FN(UNION
,cow
)(u
);
860 u
->type
= isl_fold_type_negate(u
->type
);
864 /* Negate the type of "u".
865 * Since "u" does not have a type, do nothing.
867 static __isl_give UNION
*FN(UNION
,negate_type
)(__isl_take UNION
*u
)
873 static __isl_give PART
*FN(UNION
,mul_isl_int_entry
)(__isl_take PART
*part
,
878 return FN(PW
,mul_isl_int
)(part
, *v
);
881 __isl_give UNION
*FN(UNION
,mul_isl_int
)(__isl_take UNION
*u
, isl_int v
)
883 if (isl_int_is_one(v
))
886 if (DEFAULT_IS_ZERO
&& u
&& isl_int_is_zero(v
)) {
888 isl_space
*dim
= FN(UNION
,get_space
)(u
);
890 zero
= FN(UNION
,ZERO
)(dim
, u
->type
);
892 zero
= FN(UNION
,ZERO
)(dim
);
898 u
= FN(UNION
,transform_inplace
)(u
, &FN(UNION
,mul_isl_int_entry
), &v
);
899 if (isl_int_is_neg(v
))
900 u
= FN(UNION
,negate_type
)(u
);
905 /* Multiply "part" by the isl_val "user" and return the result.
907 static __isl_give PART
*FN(UNION
,scale_val_entry
)(__isl_take PART
*part
,
912 return FN(PART
,scale_val
)(part
, isl_val_copy(v
));
915 /* Multiply "u" by "v" and return the result.
917 __isl_give UNION
*FN(UNION
,scale_val
)(__isl_take UNION
*u
,
918 __isl_take isl_val
*v
)
922 if (isl_val_is_one(v
)) {
927 if (DEFAULT_IS_ZERO
&& u
&& isl_val_is_zero(v
)) {
929 isl_space
*space
= FN(UNION
,get_space
)(u
);
931 zero
= FN(UNION
,ZERO
)(space
, u
->type
);
933 zero
= FN(UNION
,ZERO
)(space
);
940 if (!isl_val_is_rat(v
))
941 isl_die(isl_val_get_ctx(v
), isl_error_invalid
,
942 "expecting rational factor", goto error
);
944 u
= FN(UNION
,transform_inplace
)(u
, &FN(UNION
,scale_val_entry
), v
);
945 if (isl_val_is_neg(v
))
946 u
= FN(UNION
,negate_type
)(u
);
956 /* Divide "part" by the isl_val "user" and return the result.
958 static __isl_give PART
*FN(UNION
,scale_down_val_entry
)(__isl_take PART
*part
,
963 return FN(PART
,scale_down_val
)(part
, isl_val_copy(v
));
966 /* Divide "u" by "v" and return the result.
968 __isl_give UNION
*FN(UNION
,scale_down_val
)(__isl_take UNION
*u
,
969 __isl_take isl_val
*v
)
973 if (isl_val_is_one(v
)) {
978 if (!isl_val_is_rat(v
))
979 isl_die(isl_val_get_ctx(v
), isl_error_invalid
,
980 "expecting rational factor", goto error
);
981 if (isl_val_is_zero(v
))
982 isl_die(isl_val_get_ctx(v
), isl_error_invalid
,
983 "cannot scale down by zero", goto error
);
985 u
= FN(UNION
,transform_inplace
)(u
, &FN(UNION
,scale_down_val_entry
), v
);
986 if (isl_val_is_neg(v
))
987 u
= FN(UNION
,negate_type
)(u
);
997 S(UNION
,plain_is_equal_data
)
1003 static isl_stat
FN(UNION
,plain_is_equal_entry
)(void **entry
, void *user
)
1005 S(UNION
,plain_is_equal_data
) *data
= user
;
1006 struct isl_hash_table_entry
*entry2
;
1009 entry2
= FN(UNION
,find_part_entry
)(data
->u2
, pw
->dim
, 0);
1010 if (!entry2
|| entry2
== isl_hash_table_entry_none
) {
1012 data
->is_equal
= isl_bool_error
;
1014 data
->is_equal
= isl_bool_false
;
1015 return isl_stat_error
;
1018 data
->is_equal
= FN(PW
,plain_is_equal
)(pw
, entry2
->data
);
1019 if (data
->is_equal
< 0 || !data
->is_equal
)
1020 return isl_stat_error
;
1025 isl_bool
FN(UNION
,plain_is_equal
)(__isl_keep UNION
*u1
, __isl_keep UNION
*u2
)
1027 S(UNION
,plain_is_equal_data
) data
= { NULL
, isl_bool_true
};
1031 return isl_bool_error
;
1033 return isl_bool_true
;
1034 if (u1
->table
.n
!= u2
->table
.n
)
1035 return isl_bool_false
;
1036 n1
= FN(FN(UNION
,n
),PARTS
)(u1
);
1037 n2
= FN(FN(UNION
,n
),PARTS
)(u2
);
1038 if (n1
< 0 || n2
< 0)
1039 return isl_bool_error
;
1041 return isl_bool_false
;
1043 u1
= FN(UNION
,copy
)(u1
);
1044 u2
= FN(UNION
,copy
)(u2
);
1045 u1
= FN(UNION
,align_params
)(u1
, FN(UNION
,get_space
)(u2
));
1046 u2
= FN(UNION
,align_params
)(u2
, FN(UNION
,get_space
)(u1
));
1051 if (FN(UNION
,foreach_inplace
)(u1
,
1052 &FN(UNION
,plain_is_equal_entry
), &data
) < 0 &&
1059 return data
.is_equal
;
1063 return isl_bool_error
;
1066 /* Check whether the element that "entry" points to involves any NaNs and
1067 * store the result in *nan.
1068 * Abort as soon as one such element has been found.
1070 static isl_stat
FN(UNION
,involves_nan_entry
)(void **entry
, void *user
)
1072 isl_bool
*nan
= user
;
1075 *nan
= FN(PW
,involves_nan
)(pw
);
1076 if (*nan
< 0 || !nan
)
1077 return isl_stat_error
;
1082 /* Does "u" involve any NaNs?
1084 isl_bool
FN(UNION
,involves_nan
)(__isl_keep UNION
*u
)
1086 isl_bool nan
= isl_bool_false
;
1089 return isl_bool_error
;
1091 if (FN(UNION
,foreach_inplace
)(u
,
1092 &FN(UNION
,involves_nan_entry
), &nan
) < 0 &&
1094 return isl_bool_error
;
1099 /* Internal data structure for isl_union_*_drop_dims.
1100 * type, first and n are passed to isl_*_drop_dims.
1102 S(UNION
,drop_dims_data
) {
1103 enum isl_dim_type type
;
1108 /* Drop the parameters specified by "data" from "part" and return the result.
1110 static __isl_give PART
*FN(UNION
,drop_dims_entry
)(__isl_take PART
*part
,
1113 S(UNION
,drop_dims_data
) *data
= user
;
1115 return FN(PART
,drop_dims
)(part
, data
->type
, data
->first
, data
->n
);
1118 /* Drop the specified parameters from "u".
1119 * That is, type is required to be isl_dim_param.
1121 __isl_give UNION
*FN(UNION
,drop_dims
)( __isl_take UNION
*u
,
1122 enum isl_dim_type type
, unsigned first
, unsigned n
)
1125 S(UNION
,drop_dims_data
) data
= { type
, first
, n
};
1130 if (type
!= isl_dim_param
)
1131 isl_die(FN(UNION
,get_ctx
)(u
), isl_error_invalid
,
1132 "can only project out parameters",
1133 return FN(UNION
,free
)(u
));
1135 space
= FN(UNION
,get_space
)(u
);
1136 space
= isl_space_drop_dims(space
, type
, first
, n
);
1137 return FN(UNION
,transform_space
)(u
, space
, &FN(UNION
,drop_dims_entry
),
1141 /* Internal data structure for isl_union_*_set_dim_name.
1142 * pos is the position of the parameter that needs to be renamed.
1143 * s is the new name.
1145 S(UNION
,set_dim_name_data
) {
1150 /* Change the name of the parameter at position data->pos of "part" to data->s
1151 * and return the result.
1153 static __isl_give PART
*FN(UNION
,set_dim_name_entry
)(__isl_take PART
*part
,
1156 S(UNION
,set_dim_name_data
) *data
= user
;
1158 return FN(PART
,set_dim_name
)(part
, isl_dim_param
, data
->pos
, data
->s
);
1161 /* Change the name of the parameter at position "pos" to "s".
1162 * That is, type is required to be isl_dim_param.
1164 __isl_give UNION
*FN(UNION
,set_dim_name
)(__isl_take UNION
*u
,
1165 enum isl_dim_type type
, unsigned pos
, const char *s
)
1167 S(UNION
,set_dim_name_data
) data
= { pos
, s
};
1173 if (type
!= isl_dim_param
)
1174 isl_die(FN(UNION
,get_ctx
)(u
), isl_error_invalid
,
1175 "can only set parameter names",
1176 return FN(UNION
,free
)(u
));
1178 space
= FN(UNION
,get_space
)(u
);
1179 space
= isl_space_set_dim_name(space
, type
, pos
, s
);
1180 return FN(UNION
,transform_space
)(u
, space
,
1181 &FN(UNION
,set_dim_name_entry
), &data
);
1184 /* Reset the user pointer on all identifiers of parameters and tuples
1185 * of the space of "part" and return the result.
1187 static __isl_give PART
*FN(UNION
,reset_user_entry
)(__isl_take PART
*part
,
1190 return FN(PART
,reset_user
)(part
);
1193 /* Reset the user pointer on all identifiers of parameters and tuples
1194 * of the spaces of "u".
1196 __isl_give UNION
*FN(UNION
,reset_user
)(__isl_take UNION
*u
)
1200 space
= FN(UNION
,get_space
)(u
);
1201 space
= isl_space_reset_user(space
);
1202 return FN(UNION
,transform_space
)(u
, space
, &FN(UNION
,reset_user_entry
),