2 * Copyright 2017 Sven Verdoolaege
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege.
9 #include <isl_multi_macro.h>
11 /* Compute the sum of "multi1" and "multi2" on the union of their domains,
12 * with the actual sum on the shared domain and
13 * the defined expression on the symmetric difference of the domains.
15 * We simply iterate over the elements in both arguments and
16 * call isl_union_pw_aff_union_add on each of them, if there is
17 * at least one element.
19 * Otherwise, the two expressions have an explicit domain and
20 * the union of these explicit domains is computed.
21 * This assumes that the explicit domains are either both in terms
22 * of specific domains elements or both in terms of parameters.
23 * However, if one of the expressions does not have any constraints
24 * on its explicit domain, then this is allowed as well and the result
25 * is the expression with no constraints on its explicit domain.
27 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),union_add
)(
28 __isl_take
MULTI(BASE
) *multi1
, __isl_take
MULTI(BASE
) *multi2
)
30 isl_bool has_domain
, is_params1
, is_params2
;
35 return FN(MULTI(BASE
),bin_op
)(multi1
, multi2
,
37 FN(MULTI(BASE
),align_params_bin
)(&multi1
, &multi2
);
38 if (FN(MULTI(BASE
),check_equal_space
)(multi1
, multi2
) < 0)
40 if (FN(MULTI(BASE
),check_has_explicit_domain
)(multi1
) < 0 ||
41 FN(MULTI(BASE
),check_has_explicit_domain
)(multi2
) < 0)
44 has_domain
= FN(MULTI(BASE
),has_non_trivial_domain
)(multi1
);
48 FN(MULTI(BASE
),free
)(multi2
);
51 has_domain
= FN(MULTI(BASE
),has_non_trivial_domain
)(multi2
);
55 FN(MULTI(BASE
),free
)(multi1
);
59 is_params1
= FN(DOM
,is_params
)(multi1
->u
.dom
);
60 is_params2
= FN(DOM
,is_params
)(multi2
->u
.dom
);
61 if (is_params1
< 0 || is_params2
< 0)
63 if (is_params1
!= is_params2
)
64 isl_die(FN(MULTI(BASE
),get_ctx
)(multi1
),
66 "cannot compute union of concrete domain and "
67 "parameter constraints", goto error
);
68 multi1
= FN(MULTI(BASE
),cow
)(multi1
);
71 multi1
->u
.dom
= FN(DOM
,union)(multi1
->u
.dom
,
72 FN(DOM
,copy
)(multi2
->u
.dom
));
75 FN(MULTI(BASE
),free
)(multi2
);
78 FN(MULTI(BASE
),free
)(multi1
);
79 FN(MULTI(BASE
),free
)(multi2
);