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
;
118 if (!isl_space_match(u
->space
, isl_dim_param
, space
, isl_dim_param
)) {
119 space
= isl_space_drop_dims(space
, isl_dim_param
,
120 0, isl_space_dim(space
, isl_dim_param
));
121 space
= isl_space_align_params(space
,
122 FN(UNION
,get_space
)(u
));
127 entry
= FN(UNION
,find_part_entry
)(u
, space
, 0);
130 if (entry
== isl_hash_table_entry_none
)
132 return FN(PART
,ZERO
)(space
, u
->type
);
134 return FN(PART
,ZERO
)(space
);
136 isl_space_free(space
);
137 return FN(PART
,copy
)(entry
->data
);
139 isl_space_free(space
);
143 /* Add "part" to "u".
144 * If "disjoint" is set, then "u" is not allowed to already have
145 * a part that is defined over a domain that overlaps with the domain
147 * Otherwise, compute the union sum of "part" and the part in "u"
148 * defined on the same space.
150 static __isl_give UNION
*FN(UNION
,add_part_generic
)(__isl_take UNION
*u
,
151 __isl_take PART
*part
, int disjoint
)
154 struct isl_hash_table_entry
*entry
;
159 empty
= FN(PART
,IS_ZERO
)(part
);
167 u
= FN(UNION
,align_params
)(u
, FN(PART
,get_space
)(part
));
168 part
= FN(PART
,align_params
)(part
, FN(UNION
,get_space
)(u
));
170 u
= FN(UNION
,cow
)(u
);
175 if (FN(UNION
,check_disjoint_domain_other
)(u
, part
) < 0)
177 entry
= FN(UNION
,find_part_entry
)(u
, part
->dim
, 1);
185 FN(UNION
,check_disjoint_domain
)(entry
->data
, part
) < 0)
187 entry
->data
= FN(PART
,union_add_
)(entry
->data
,
188 FN(PART
,copy
)(part
));
191 empty
= FN(PART
,IS_ZERO
)(part
);
195 u
= FN(UNION
,remove_part_entry
)(u
, entry
);
206 /* Add "part" to "u", where "u" is assumed not to already have
207 * a part that is defined on the same space as "part".
209 __isl_give UNION
*FN(FN(UNION
,add
),PARTS
)(__isl_take UNION
*u
,
210 __isl_take PART
*part
)
212 return FN(UNION
,add_part_generic
)(u
, part
, 1);
216 /* Allocate a UNION with the same type and the same size as "u" and
217 * with space "space".
219 static __isl_give UNION
*FN(UNION
,alloc_same_size_on_space
)(__isl_keep UNION
*u
,
220 __isl_take isl_space
*space
)
223 space
= isl_space_free(space
);
224 return FN(UNION
,alloc
)(space
, u
->type
, u
->table
.n
);
227 /* Allocate a UNION with the same size as "u" and with space "space".
229 static __isl_give UNION
*FN(UNION
,alloc_same_size_on_space
)(__isl_keep UNION
*u
,
230 __isl_take isl_space
*space
)
233 space
= isl_space_free(space
);
234 return FN(UNION
,alloc
)(space
, u
->table
.n
);
238 /* Allocate a UNION with the same space, the same type (if any) and
239 * the same size as "u".
241 static __isl_give UNION
*FN(UNION
,alloc_same_size
)(__isl_keep UNION
*u
)
243 return FN(UNION
,alloc_same_size_on_space
)(u
, FN(UNION
,get_space
)(u
));
246 /* Internal data structure for isl_union_*_transform_space.
247 * "fn' is applied to each entry in the input.
248 * "res" collects the results.
250 S(UNION
,transform_data
)
252 __isl_give PART
*(*fn
)(__isl_take PART
*part
, void *user
);
258 /* Apply data->fn to "part" and add the result to data->res.
260 static isl_stat
FN(UNION
,transform_entry
)(__isl_take PART
*part
, void *user
)
262 S(UNION
,transform_data
) *data
= (S(UNION
,transform_data
) *)user
;
264 part
= data
->fn(part
, data
->user
);
265 data
->res
= FN(FN(UNION
,add
),PARTS
)(data
->res
, part
);
267 return isl_stat_error
;
272 /* Return a UNION living in "space" that is obtained by applying "fn"
273 * to each of the entries in "u".
275 static __isl_give UNION
*FN(UNION
,transform_space
)(__isl_take UNION
*u
,
277 __isl_give PART
*(*fn
)(__isl_take PART
*part
, void *user
), void *user
)
279 S(UNION
,transform_data
) data
= { fn
, user
};
281 data
.res
= FN(UNION
,alloc_same_size_on_space
)(u
, space
);
282 if (FN(FN(UNION
,foreach
),PARTS
)(u
,
283 &FN(UNION
,transform_entry
), &data
) < 0)
284 data
.res
= FN(UNION
,free
)(data
.res
);
289 /* Return a UNION that lives in the same space as "u" and that is obtained
290 * by applying "fn" to each of the entries in "u".
292 static __isl_give UNION
*FN(UNION
,transform
)(__isl_take UNION
*u
,
293 __isl_give PART
*(*fn
)(__isl_take PART
*part
, void *user
), void *user
)
295 return FN(UNION
,transform_space
)(u
, FN(UNION
,get_space
)(u
), fn
, user
);
298 /* Apply data->fn to *part and store the result back into *part.
300 static isl_stat
FN(UNION
,transform_inplace_entry
)(void **part
, void *user
)
302 S(UNION
,transform_data
) *data
= (S(UNION
,transform_data
) *) user
;
304 *part
= data
->fn(*part
, data
->user
);
306 return isl_stat_error
;
310 /* Update "u" by applying "fn" to each entry.
311 * This operation is assumed not to change the number of entries nor
312 * the spaces of the entries.
314 * If there is only one reference to "u", then change "u" inplace.
315 * Otherwise, create a new UNION from "u" and discard the original.
317 static __isl_give UNION
*FN(UNION
,transform_inplace
)(__isl_take UNION
*u
,
318 __isl_give PART
*(*fn
)(__isl_take PART
*part
, void *user
), void *user
)
322 single_ref
= FN(UNION
,has_single_reference
)(u
);
324 return FN(UNION
,free
)(u
);
326 S(UNION
,transform_data
) data
= { fn
, user
};
327 if (FN(UNION
,foreach_inplace
)(u
,
328 &FN(UNION
,transform_inplace_entry
), &data
) < 0)
329 return FN(UNION
,free
)(u
);
332 return FN(UNION
,transform
)(u
, fn
, user
);
335 /* An isl_union_*_transform callback for use in isl_union_*_dup
336 * that simply returns "part".
338 static __isl_give PART
*FN(UNION
,copy_part
)(__isl_take PART
*part
, void *user
)
343 __isl_give UNION
*FN(UNION
,dup
)(__isl_keep UNION
*u
)
345 u
= FN(UNION
,copy
)(u
);
346 return FN(UNION
,transform
)(u
, &FN(UNION
,copy_part
), NULL
);
349 __isl_give UNION
*FN(UNION
,cow
)(__isl_take UNION
*u
)
357 return FN(UNION
,dup
)(u
);
360 __isl_null UNION
*FN(UNION
,free
)(__isl_take UNION
*u
)
368 isl_hash_table_foreach(u
->space
->ctx
, &u
->table
,
369 &FN(UNION
,free_u_entry
), NULL
);
370 isl_hash_table_clear(&u
->table
);
371 isl_space_free(u
->space
);
376 static __isl_give PART
*FN(UNION
,align_entry
)(__isl_take PART
*part
, void *user
)
378 isl_reordering
*exp
= user
;
380 exp
= isl_reordering_extend_space(isl_reordering_copy(exp
),
381 FN(PART
,get_domain_space
)(part
));
382 return FN(PART
,realign_domain
)(part
, exp
);
385 /* Reorder the parameters of "u" according to the given reordering.
387 static __isl_give UNION
*FN(UNION
,realign_domain
)(__isl_take UNION
*u
,
388 __isl_take isl_reordering
*r
)
395 space
= isl_space_copy(r
->dim
);
396 u
= FN(UNION
,transform_space
)(u
, space
, &FN(UNION
,align_entry
), r
);
397 isl_reordering_free(r
);
401 isl_reordering_free(r
);
405 /* Align the parameters of "u" to those of "model".
407 __isl_give UNION
*FN(UNION
,align_params
)(__isl_take UNION
*u
,
408 __isl_take isl_space
*model
)
415 if (isl_space_match(u
->space
, isl_dim_param
, model
, isl_dim_param
)) {
416 isl_space_free(model
);
420 model
= isl_space_params(model
);
421 r
= isl_parameter_alignment_reordering(u
->space
, model
);
422 isl_space_free(model
);
424 return FN(UNION
,realign_domain
)(u
, r
);
426 isl_space_free(model
);
431 /* Add "part" to *u, taking the union sum if "u" already has
432 * a part defined on the same space as "part".
434 static isl_stat
FN(UNION
,union_add_part
)(__isl_take PART
*part
, void *user
)
436 UNION
**u
= (UNION
**)user
;
438 *u
= FN(UNION
,add_part_generic
)(*u
, part
, 0);
443 /* Compute the sum of "u1" and "u2" on the union of their domains,
444 * with the actual sum on the shared domain and
445 * the defined expression on the symmetric difference of the domains.
447 * This is an internal function that is exposed under different
448 * names depending on whether the base expressions have a zero default
450 * If they do, then this function is called "add".
451 * Otherwise, it is called "union_add".
453 static __isl_give UNION
*FN(UNION
,union_add_
)(__isl_take UNION
*u1
,
454 __isl_take UNION
*u2
)
456 u1
= FN(UNION
,align_params
)(u1
, FN(UNION
,get_space
)(u2
));
457 u2
= FN(UNION
,align_params
)(u2
, FN(UNION
,get_space
)(u1
));
459 u1
= FN(UNION
,cow
)(u1
);
464 if (FN(FN(UNION
,foreach
),PARTS
)(u2
, &FN(UNION
,union_add_part
), &u1
) < 0)
476 __isl_give UNION
*FN(FN(UNION
,from
),PARTS
)(__isl_take PART
*part
)
484 dim
= FN(PART
,get_space
)(part
);
485 dim
= isl_space_drop_dims(dim
, isl_dim_in
, 0, isl_space_dim(dim
, isl_dim_in
));
486 dim
= isl_space_drop_dims(dim
, isl_dim_out
, 0, isl_space_dim(dim
, isl_dim_out
));
488 u
= FN(UNION
,ZERO
)(dim
, part
->type
);
490 u
= FN(UNION
,ZERO
)(dim
);
492 u
= FN(FN(UNION
,add
),PARTS
)(u
, part
);
497 S(UNION
,match_bin_data
) {
500 __isl_give PART
*(*fn
)(__isl_take PART
*, __isl_take PART
*);
503 /* Check if data->u2 has an element living in the same space as "part".
504 * If so, call data->fn on the two elements and add the result to
507 static isl_stat
FN(UNION
,match_bin_entry
)(__isl_take PART
*part
, void *user
)
509 S(UNION
,match_bin_data
) *data
= user
;
510 struct isl_hash_table_entry
*entry2
;
514 space
= FN(PART
,get_space
)(part
);
515 entry2
= FN(UNION
,find_part_entry
)(data
->u2
, space
, 0);
516 isl_space_free(space
);
519 if (entry2
== isl_hash_table_entry_none
) {
524 part2
= entry2
->data
;
525 if (!isl_space_tuple_is_equal(part
->dim
, isl_dim_out
,
526 part2
->dim
, isl_dim_out
))
527 isl_die(FN(UNION
,get_ctx
)(data
->u2
), isl_error_invalid
,
528 "entries should have the same range space",
531 part
= data
->fn(part
, FN(PART
, copy
)(entry2
->data
));
533 data
->res
= FN(FN(UNION
,add
),PARTS
)(data
->res
, part
);
535 return isl_stat_error
;
540 return isl_stat_error
;
543 /* This function is currently only used from isl_polynomial.c
544 * and not from isl_fold.c.
546 static __isl_give UNION
*FN(UNION
,match_bin_op
)(__isl_take UNION
*u1
,
547 __isl_take UNION
*u2
,
548 __isl_give PART
*(*fn
)(__isl_take PART
*, __isl_take PART
*))
549 __attribute__ ((unused
));
550 /* For each pair of elements in "u1" and "u2" living in the same space,
551 * call "fn" and collect the results.
553 static __isl_give UNION
*FN(UNION
,match_bin_op
)(__isl_take UNION
*u1
,
554 __isl_take UNION
*u2
,
555 __isl_give PART
*(*fn
)(__isl_take PART
*, __isl_take PART
*))
557 S(UNION
,match_bin_data
) data
= { NULL
, NULL
, fn
};
559 u1
= FN(UNION
,align_params
)(u1
, FN(UNION
,get_space
)(u2
));
560 u2
= FN(UNION
,align_params
)(u2
, FN(UNION
,get_space
)(u1
));
566 data
.res
= FN(UNION
,alloc_same_size
)(u1
);
567 if (FN(FN(UNION
,foreach
),PARTS
)(u1
,
568 &FN(UNION
,match_bin_entry
), &data
) < 0)
577 FN(UNION
,free
)(data
.res
);
581 /* Compute the sum of "u1" and "u2".
583 * If the base expressions have a default zero value, then the sum
584 * is computed on the union of the domains of "u1" and "u2".
585 * Otherwise, it is computed on their shared domains.
587 __isl_give UNION
*FN(UNION
,add
)(__isl_take UNION
*u1
, __isl_take UNION
*u2
)
590 return FN(UNION
,union_add_
)(u1
, u2
);
592 return FN(UNION
,match_bin_op
)(u1
, u2
, &FN(PART
,add
));
597 /* Subtract "u2" from "u1" and return the result.
599 __isl_give UNION
*FN(UNION
,sub
)(__isl_take UNION
*u1
, __isl_take UNION
*u2
)
601 return FN(UNION
,match_bin_op
)(u1
, u2
, &FN(PART
,sub
));
605 S(UNION
,any_set_data
) {
607 __isl_give PW
*(*fn
)(__isl_take PW
*, __isl_take isl_set
*);
610 static __isl_give PART
*FN(UNION
,any_set_entry
)(__isl_take PART
*part
,
613 S(UNION
,any_set_data
) *data
= user
;
615 return data
->fn(part
, isl_set_copy(data
->set
));
618 /* Update each element of "u" by calling "fn" on the element and "set".
620 static __isl_give UNION
*FN(UNION
,any_set_op
)(__isl_take UNION
*u
,
621 __isl_take isl_set
*set
,
622 __isl_give PW
*(*fn
)(__isl_take PW
*, __isl_take isl_set
*))
624 S(UNION
,any_set_data
) data
= { NULL
, fn
};
626 u
= FN(UNION
,align_params
)(u
, isl_set_get_space(set
));
627 set
= isl_set_align_params(set
, FN(UNION
,get_space
)(u
));
633 u
= FN(UNION
,transform
)(u
, &FN(UNION
,any_set_entry
), &data
);
642 /* Intersect the domain of "u" with the parameter domain "context".
644 __isl_give UNION
*FN(UNION
,intersect_params
)(__isl_take UNION
*u
,
645 __isl_take isl_set
*set
)
647 return FN(UNION
,any_set_op
)(u
, set
, &FN(PW
,intersect_params
));
650 /* Compute the gist of the domain of "u" with respect to
651 * the parameter domain "context".
653 __isl_give UNION
*FN(UNION
,gist_params
)(__isl_take UNION
*u
,
654 __isl_take isl_set
*set
)
656 return FN(UNION
,any_set_op
)(u
, set
, &FN(PW
,gist_params
));
659 S(UNION
,match_domain_data
) {
662 __isl_give PW
*(*fn
)(__isl_take PW
*, __isl_take isl_set
*);
665 static int FN(UNION
,set_has_dim
)(const void *entry
, const void *val
)
667 isl_set
*set
= (isl_set
*)entry
;
668 isl_space
*dim
= (isl_space
*)val
;
670 return isl_space_is_equal(set
->dim
, dim
);
673 /* Find the set in data->uset that lives in the same space as the domain
674 * of "part", apply data->fn to *entry and this set (if any), and add
675 * the result to data->res.
677 static isl_stat
FN(UNION
,match_domain_entry
)(__isl_take PART
*part
, void *user
)
679 S(UNION
,match_domain_data
) *data
= user
;
681 struct isl_hash_table_entry
*entry2
;
684 space
= FN(PART
,get_domain_space
)(part
);
685 hash
= isl_space_get_hash(space
);
686 entry2
= isl_hash_table_find(data
->uset
->dim
->ctx
, &data
->uset
->table
,
687 hash
, &FN(UNION
,set_has_dim
), space
, 0);
688 isl_space_free(space
);
694 part
= data
->fn(part
, isl_set_copy(entry2
->data
));
696 data
->res
= FN(FN(UNION
,add
),PARTS
)(data
->res
, part
);
698 return isl_stat_error
;
703 /* Apply fn to each pair of PW in u and set in uset such that
704 * the set lives in the same space as the domain of PW
705 * and collect the results.
707 static __isl_give UNION
*FN(UNION
,match_domain_op
)(__isl_take UNION
*u
,
708 __isl_take isl_union_set
*uset
,
709 __isl_give PW
*(*fn
)(__isl_take PW
*, __isl_take isl_set
*))
711 S(UNION
,match_domain_data
) data
= { NULL
, NULL
, fn
};
713 u
= FN(UNION
,align_params
)(u
, isl_union_set_get_space(uset
));
714 uset
= isl_union_set_align_params(uset
, FN(UNION
,get_space
)(u
));
720 data
.res
= FN(UNION
,alloc_same_size
)(u
);
721 if (FN(FN(UNION
,foreach
),PARTS
)(u
,
722 &FN(UNION
,match_domain_entry
), &data
) < 0)
726 isl_union_set_free(uset
);
730 isl_union_set_free(uset
);
731 FN(UNION
,free
)(data
.res
);
735 /* Intersect the domain of "u" with "uset".
736 * If "uset" is a parameters domain, then intersect the parameter
737 * domain of "u" with this set.
739 __isl_give UNION
*FN(UNION
,intersect_domain
)(__isl_take UNION
*u
,
740 __isl_take isl_union_set
*uset
)
742 if (isl_union_set_is_params(uset
))
743 return FN(UNION
,intersect_params
)(u
,
744 isl_set_from_union_set(uset
));
745 return FN(UNION
,match_domain_op
)(u
, uset
, &FN(PW
,intersect_domain
));
748 /* Take the set (which may be empty) in data->uset that lives
749 * in the same space as the domain of "pw", subtract it from the domain
750 * of "part" and return the result.
752 static __isl_give PART
*FN(UNION
,subtract_domain_entry
)(__isl_take PART
*part
,
755 isl_union_set
*uset
= user
;
759 space
= FN(PART
,get_domain_space
)(part
);
760 set
= isl_union_set_extract_set(uset
, space
);
761 return FN(PART
,subtract_domain
)(part
, set
);
764 /* Subtract "uset' from the domain of "u".
766 __isl_give UNION
*FN(UNION
,subtract_domain
)(__isl_take UNION
*u
,
767 __isl_take isl_union_set
*uset
)
769 u
= FN(UNION
,transform
)(u
, &FN(UNION
,subtract_domain_entry
), uset
);
770 isl_union_set_free(uset
);
774 __isl_give UNION
*FN(UNION
,gist
)(__isl_take UNION
*u
,
775 __isl_take isl_union_set
*uset
)
777 if (isl_union_set_is_params(uset
))
778 return FN(UNION
,gist_params
)(u
, isl_set_from_union_set(uset
));
779 return FN(UNION
,match_domain_op
)(u
, uset
, &FN(PW
,gist
));
782 /* Coalesce an entry in a UNION. Coalescing is performed in-place.
783 * Since the UNION may have several references, the entry is only
784 * replaced if the coalescing is successful.
786 static isl_stat
FN(UNION
,coalesce_entry
)(void **entry
, void *user
)
788 PART
**part_p
= (PART
**) entry
;
791 part
= FN(PART
,copy
)(*part_p
);
792 part
= FN(PW
,coalesce
)(part
);
794 return isl_stat_error
;
795 FN(PART
,free
)(*part_p
);
801 __isl_give UNION
*FN(UNION
,coalesce
)(__isl_take UNION
*u
)
803 if (FN(UNION
,foreach_inplace
)(u
, &FN(UNION
,coalesce_entry
), NULL
) < 0)
812 static isl_stat
FN(UNION
,domain_entry
)(__isl_take PART
*part
, void *user
)
814 isl_union_set
**uset
= (isl_union_set
**)user
;
816 *uset
= isl_union_set_add_set(*uset
, FN(PART
,domain
)(part
));
821 __isl_give isl_union_set
*FN(UNION
,domain
)(__isl_take UNION
*u
)
825 uset
= isl_union_set_empty(FN(UNION
,get_space
)(u
));
826 if (FN(FN(UNION
,foreach
),PARTS
)(u
, &FN(UNION
,domain_entry
), &uset
) < 0)
833 isl_union_set_free(uset
);
839 /* Negate the type of "u".
841 static __isl_give UNION
*FN(UNION
,negate_type
)(__isl_take UNION
*u
)
843 u
= FN(UNION
,cow
)(u
);
846 u
->type
= isl_fold_type_negate(u
->type
);
850 /* Negate the type of "u".
851 * Since "u" does not have a type, do nothing.
853 static __isl_give UNION
*FN(UNION
,negate_type
)(__isl_take UNION
*u
)
859 static __isl_give PART
*FN(UNION
,mul_isl_int_entry
)(__isl_take PART
*part
,
864 return FN(PW
,mul_isl_int
)(part
, *v
);
867 __isl_give UNION
*FN(UNION
,mul_isl_int
)(__isl_take UNION
*u
, isl_int v
)
869 if (isl_int_is_one(v
))
872 if (DEFAULT_IS_ZERO
&& u
&& isl_int_is_zero(v
)) {
874 isl_space
*dim
= FN(UNION
,get_space
)(u
);
876 zero
= FN(UNION
,ZERO
)(dim
, u
->type
);
878 zero
= FN(UNION
,ZERO
)(dim
);
884 u
= FN(UNION
,transform_inplace
)(u
, &FN(UNION
,mul_isl_int_entry
), &v
);
885 if (isl_int_is_neg(v
))
886 u
= FN(UNION
,negate_type
)(u
);
891 /* Multiply "part" by the isl_val "user" and return the result.
893 static __isl_give PART
*FN(UNION
,scale_val_entry
)(__isl_take PART
*part
,
898 return FN(PART
,scale_val
)(part
, isl_val_copy(v
));
901 /* Multiply "u" by "v" and return the result.
903 __isl_give UNION
*FN(UNION
,scale_val
)(__isl_take UNION
*u
,
904 __isl_take isl_val
*v
)
908 if (isl_val_is_one(v
)) {
913 if (DEFAULT_IS_ZERO
&& u
&& isl_val_is_zero(v
)) {
915 isl_space
*space
= FN(UNION
,get_space
)(u
);
917 zero
= FN(UNION
,ZERO
)(space
, u
->type
);
919 zero
= FN(UNION
,ZERO
)(space
);
926 if (!isl_val_is_rat(v
))
927 isl_die(isl_val_get_ctx(v
), isl_error_invalid
,
928 "expecting rational factor", goto error
);
930 u
= FN(UNION
,transform_inplace
)(u
, &FN(UNION
,scale_val_entry
), v
);
931 if (isl_val_is_neg(v
))
932 u
= FN(UNION
,negate_type
)(u
);
942 /* Divide "part" by the isl_val "user" and return the result.
944 static __isl_give PART
*FN(UNION
,scale_down_val_entry
)(__isl_take PART
*part
,
949 return FN(PART
,scale_down_val
)(part
, isl_val_copy(v
));
952 /* Divide "u" by "v" and return the result.
954 __isl_give UNION
*FN(UNION
,scale_down_val
)(__isl_take UNION
*u
,
955 __isl_take isl_val
*v
)
959 if (isl_val_is_one(v
)) {
964 if (!isl_val_is_rat(v
))
965 isl_die(isl_val_get_ctx(v
), isl_error_invalid
,
966 "expecting rational factor", goto error
);
967 if (isl_val_is_zero(v
))
968 isl_die(isl_val_get_ctx(v
), isl_error_invalid
,
969 "cannot scale down by zero", goto error
);
971 u
= FN(UNION
,transform_inplace
)(u
, &FN(UNION
,scale_down_val_entry
), v
);
972 if (isl_val_is_neg(v
))
973 u
= FN(UNION
,negate_type
)(u
);
983 S(UNION
,plain_is_equal_data
)
989 static isl_stat
FN(UNION
,plain_is_equal_entry
)(void **entry
, void *user
)
991 S(UNION
,plain_is_equal_data
) *data
= user
;
992 struct isl_hash_table_entry
*entry2
;
995 entry2
= FN(UNION
,find_part_entry
)(data
->u2
, pw
->dim
, 0);
996 if (!entry2
|| entry2
== isl_hash_table_entry_none
) {
998 data
->is_equal
= isl_bool_error
;
1000 data
->is_equal
= isl_bool_false
;
1001 return isl_stat_error
;
1004 data
->is_equal
= FN(PW
,plain_is_equal
)(pw
, entry2
->data
);
1005 if (data
->is_equal
< 0 || !data
->is_equal
)
1006 return isl_stat_error
;
1011 isl_bool
FN(UNION
,plain_is_equal
)(__isl_keep UNION
*u1
, __isl_keep UNION
*u2
)
1013 S(UNION
,plain_is_equal_data
) data
= { NULL
, isl_bool_true
};
1017 return isl_bool_error
;
1019 return isl_bool_true
;
1020 if (u1
->table
.n
!= u2
->table
.n
)
1021 return isl_bool_false
;
1022 n1
= FN(FN(UNION
,n
),PARTS
)(u1
);
1023 n2
= FN(FN(UNION
,n
),PARTS
)(u2
);
1024 if (n1
< 0 || n2
< 0)
1025 return isl_bool_error
;
1027 return isl_bool_false
;
1029 u1
= FN(UNION
,copy
)(u1
);
1030 u2
= FN(UNION
,copy
)(u2
);
1031 u1
= FN(UNION
,align_params
)(u1
, FN(UNION
,get_space
)(u2
));
1032 u2
= FN(UNION
,align_params
)(u2
, FN(UNION
,get_space
)(u1
));
1037 if (FN(UNION
,foreach_inplace
)(u1
,
1038 &FN(UNION
,plain_is_equal_entry
), &data
) < 0 &&
1045 return data
.is_equal
;
1049 return isl_bool_error
;
1052 /* Internal data structure for isl_union_*_drop_dims.
1053 * type, first and n are passed to isl_*_drop_dims.
1055 S(UNION
,drop_dims_data
) {
1056 enum isl_dim_type type
;
1061 /* Drop the parameters specified by "data" from "part" and return the result.
1063 static __isl_give PART
*FN(UNION
,drop_dims_entry
)(__isl_take PART
*part
,
1066 S(UNION
,drop_dims_data
) *data
= user
;
1068 return FN(PART
,drop_dims
)(part
, data
->type
, data
->first
, data
->n
);
1071 /* Drop the specified parameters from "u".
1072 * That is, type is required to be isl_dim_param.
1074 __isl_give UNION
*FN(UNION
,drop_dims
)( __isl_take UNION
*u
,
1075 enum isl_dim_type type
, unsigned first
, unsigned n
)
1078 S(UNION
,drop_dims_data
) data
= { type
, first
, n
};
1083 if (type
!= isl_dim_param
)
1084 isl_die(FN(UNION
,get_ctx
)(u
), isl_error_invalid
,
1085 "can only project out parameters",
1086 return FN(UNION
,free
)(u
));
1088 space
= FN(UNION
,get_space
)(u
);
1089 space
= isl_space_drop_dims(space
, type
, first
, n
);
1090 return FN(UNION
,transform_space
)(u
, space
, &FN(UNION
,drop_dims_entry
),
1094 /* Internal data structure for isl_union_*_set_dim_name.
1095 * pos is the position of the parameter that needs to be renamed.
1096 * s is the new name.
1098 S(UNION
,set_dim_name_data
) {
1103 /* Change the name of the parameter at position data->pos of "part" to data->s
1104 * and return the result.
1106 static __isl_give PART
*FN(UNION
,set_dim_name_entry
)(__isl_take PART
*part
,
1109 S(UNION
,set_dim_name_data
) *data
= user
;
1111 return FN(PART
,set_dim_name
)(part
, isl_dim_param
, data
->pos
, data
->s
);
1114 /* Change the name of the parameter at position "pos" to "s".
1115 * That is, type is required to be isl_dim_param.
1117 __isl_give UNION
*FN(UNION
,set_dim_name
)(__isl_take UNION
*u
,
1118 enum isl_dim_type type
, unsigned pos
, const char *s
)
1120 S(UNION
,set_dim_name_data
) data
= { pos
, s
};
1126 if (type
!= isl_dim_param
)
1127 isl_die(FN(UNION
,get_ctx
)(u
), isl_error_invalid
,
1128 "can only set parameter names",
1129 return FN(UNION
,free
)(u
));
1131 space
= FN(UNION
,get_space
)(u
);
1132 space
= isl_space_set_dim_name(space
, type
, pos
, s
);
1133 return FN(UNION
,transform_space
)(u
, space
,
1134 &FN(UNION
,set_dim_name_entry
), &data
);
1137 /* Reset the user pointer on all identifiers of parameters and tuples
1138 * of the space of "part" and return the result.
1140 static __isl_give PART
*FN(UNION
,reset_user_entry
)(__isl_take PART
*part
,
1143 return FN(PART
,reset_user
)(part
);
1146 /* Reset the user pointer on all identifiers of parameters and tuples
1147 * of the spaces of "u".
1149 __isl_give UNION
*FN(UNION
,reset_user
)(__isl_take UNION
*u
)
1153 space
= FN(UNION
,get_space
)(u
);
1154 space
= isl_space_reset_user(space
);
1155 return FN(UNION
,transform_space
)(u
, space
, &FN(UNION
,reset_user_entry
),