isl_multi_templ.c: extract out isl_multi_product_templ.c
[isl.git] / isl_multi_product_templ.c
blobf27b6e2ef0b77ae656f5bd9bdf05277ac92d256c
1 /*
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
8 */
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)
25 int i;
26 EL *el;
27 isl_space *space;
28 MULTI(BASE) *res;
29 int 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 space = isl_space_product(FN(MULTI(BASE),get_space)(multi1),
36 FN(MULTI(BASE),get_space)(multi2));
37 res = FN(MULTI(BASE),alloc)(isl_space_copy(space));
38 space = isl_space_domain(space);
40 for (i = 0; i < out1; ++i) {
41 el = FN(FN(MULTI(BASE),get),BASE)(multi1, i);
42 el = FN(EL,insert_dims)(el, isl_dim_in, in1, in2);
43 el = FN(EL,reset_domain_space)(el, isl_space_copy(space));
44 res = FN(FN(MULTI(BASE),set),BASE)(res, i, el);
47 for (i = 0; i < out2; ++i) {
48 el = FN(FN(MULTI(BASE),get),BASE)(multi2, i);
49 el = FN(EL,insert_dims)(el, isl_dim_in, 0, in1);
50 el = FN(EL,reset_domain_space)(el, isl_space_copy(space));
51 res = FN(FN(MULTI(BASE),set),BASE)(res, out1 + i, el);
54 if (FN(MULTI(BASE),has_explicit_domain)(multi1) ||
55 FN(MULTI(BASE),has_explicit_domain)(multi2))
56 res = FN(MULTI(BASE),intersect_explicit_domain_product)(res,
57 multi1, multi2);
59 isl_space_free(space);
60 FN(MULTI(BASE),free)(multi1);
61 FN(MULTI(BASE),free)(multi2);
62 return res;
65 /* Given two MULTI(BASE)s A -> B and C -> D,
66 * construct a MULTI(BASE) [A -> C] -> [B -> D].
68 __isl_give MULTI(BASE) *FN(MULTI(BASE),product)(
69 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
71 return FN(MULTI(BASE),align_params_multi_multi_and)(multi1, multi2,
72 &FN(MULTI(BASE),product_aligned));