isl 0.27
[isl.git] / isl_multi_product_templ.c
blob5640326fd826f5258e76b0b3f7c68d3cb9b2cecd
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 * If "multi1" and/or "multi2" has an explicit domain, then
18 * intersect the domain of the result with these explicit domains.
20 __isl_give MULTI(BASE) *FN(MULTI(BASE),product)(
21 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
23 int i;
24 EL *el;
25 isl_space *space;
26 MULTI(BASE) *res;
27 isl_size in1, in2, out1, out2;
29 FN(MULTI(BASE),align_params_bin)(&multi1, &multi2);
30 in1 = FN(MULTI(BASE),dim)(multi1, isl_dim_in);
31 in2 = FN(MULTI(BASE),dim)(multi2, isl_dim_in);
32 out1 = FN(MULTI(BASE),dim)(multi1, isl_dim_out);
33 out2 = FN(MULTI(BASE),dim)(multi2, isl_dim_out);
34 if (in1 < 0 || in2 < 0 || out1 < 0 || out2 < 0)
35 goto error;
36 space = isl_space_product(FN(MULTI(BASE),get_space)(multi1),
37 FN(MULTI(BASE),get_space)(multi2));
38 res = FN(MULTI(BASE),alloc)(isl_space_copy(space));
39 space = isl_space_domain(space);
41 for (i = 0; i < out1; ++i) {
42 el = FN(FN(MULTI(BASE),get),BASE)(multi1, i);
43 el = FN(EL,insert_dims)(el, isl_dim_in, in1, in2);
44 el = FN(EL,reset_domain_space)(el, isl_space_copy(space));
45 res = FN(FN(MULTI(BASE),set),BASE)(res, i, el);
48 for (i = 0; i < out2; ++i) {
49 el = FN(FN(MULTI(BASE),get),BASE)(multi2, i);
50 el = FN(EL,insert_dims)(el, isl_dim_in, 0, in1);
51 el = FN(EL,reset_domain_space)(el, isl_space_copy(space));
52 res = FN(FN(MULTI(BASE),set),BASE)(res, out1 + i, el);
55 if (FN(MULTI(BASE),has_explicit_domain)(multi1) ||
56 FN(MULTI(BASE),has_explicit_domain)(multi2))
57 res = FN(MULTI(BASE),intersect_explicit_domain_product)(res,
58 multi1, multi2);
60 isl_space_free(space);
61 FN(MULTI(BASE),free)(multi1);
62 FN(MULTI(BASE),free)(multi2);
63 return res;
64 error:
65 FN(MULTI(BASE),free)(multi1);
66 FN(MULTI(BASE),free)(multi2);
67 return NULL;