2 * Copyright 2012 Ecole Normale Superieure
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege,
7 * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
10 #include <isl/space.h>
12 #include <isl_multi_macro.h>
14 /* Given two MULTI(BASE)s A -> B and C -> D,
15 * construct a MULTI(BASE) [A -> C] -> [B -> D].
17 * The parameters are assumed to have been aligned.
19 * If "multi1" and/or "multi2" has an explicit domain, then
20 * intersect the domain of the result with these explicit domains.
22 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),product_aligned
)(
23 __isl_take
MULTI(BASE
) *multi1
, __isl_take
MULTI(BASE
) *multi2
)
29 isl_size in1
, in2
, out1
, out2
;
31 in1
= FN(MULTI(BASE
),dim
)(multi1
, isl_dim_in
);
32 in2
= FN(MULTI(BASE
),dim
)(multi2
, isl_dim_in
);
33 out1
= FN(MULTI(BASE
),dim
)(multi1
, isl_dim_out
);
34 out2
= FN(MULTI(BASE
),dim
)(multi2
, isl_dim_out
);
35 if (in1
< 0 || in2
< 0 || out1
< 0 || out2
< 0)
37 space
= isl_space_product(FN(MULTI(BASE
),get_space
)(multi1
),
38 FN(MULTI(BASE
),get_space
)(multi2
));
39 res
= FN(MULTI(BASE
),alloc
)(isl_space_copy(space
));
40 space
= isl_space_domain(space
);
42 for (i
= 0; i
< out1
; ++i
) {
43 el
= FN(FN(MULTI(BASE
),get
),BASE
)(multi1
, i
);
44 el
= FN(EL
,insert_dims
)(el
, isl_dim_in
, in1
, in2
);
45 el
= FN(EL
,reset_domain_space
)(el
, isl_space_copy(space
));
46 res
= FN(FN(MULTI(BASE
),set
),BASE
)(res
, i
, el
);
49 for (i
= 0; i
< out2
; ++i
) {
50 el
= FN(FN(MULTI(BASE
),get
),BASE
)(multi2
, i
);
51 el
= FN(EL
,insert_dims
)(el
, isl_dim_in
, 0, in1
);
52 el
= FN(EL
,reset_domain_space
)(el
, isl_space_copy(space
));
53 res
= FN(FN(MULTI(BASE
),set
),BASE
)(res
, out1
+ i
, el
);
56 if (FN(MULTI(BASE
),has_explicit_domain
)(multi1
) ||
57 FN(MULTI(BASE
),has_explicit_domain
)(multi2
))
58 res
= FN(MULTI(BASE
),intersect_explicit_domain_product
)(res
,
61 isl_space_free(space
);
62 FN(MULTI(BASE
),free
)(multi1
);
63 FN(MULTI(BASE
),free
)(multi2
);
66 FN(MULTI(BASE
),free
)(multi1
);
67 FN(MULTI(BASE
),free
)(multi2
);
71 /* Given two MULTI(BASE)s A -> B and C -> D,
72 * construct a MULTI(BASE) [A -> C] -> [B -> D].
74 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),product
)(
75 __isl_take
MULTI(BASE
) *multi1
, __isl_take
MULTI(BASE
) *multi2
)
77 return FN(MULTI(BASE
),align_params_multi_multi_and
)(multi1
, multi2
,
78 &FN(MULTI(BASE
),product_aligned
));