1/*
2 * Copyright 2012 Ecole Normale Superieure
3 *
4 * Use of this software is governed by the MIT license
5 *
6 * Written by Sven Verdoolaege,
7 * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
8 */
9
10#include <isl/space.h>
11
12#include <isl_multi_macro.h>
13
14/* Given two MULTI(BASE)s A -> B and C -> D,
15 * construct a MULTI(BASE) [A -> C] -> [B -> D].
16 *
17 * If "multi1" and/or "multi2" has an explicit domain, then
18 * intersect the domain of the result with these explicit domains.
19 */
20__isl_give MULTI(BASE) *FN(MULTI(BASE),product)(
21 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
22{
23 int i;
24 EL *el;
25 isl_space *space;
26 MULTI(BASE) *res;
27 isl_size in1, in2, out1, out2;
28
29 FN(MULTI(BASE),align_params_bin)(obj1: &multi1, obj2: &multi2);
30 in1 = FN(MULTI(BASE),dim)(multi: multi1, type: isl_dim_in);
31 in2 = FN(MULTI(BASE),dim)(multi: multi2, type: isl_dim_in);
32 out1 = FN(MULTI(BASE),dim)(multi: multi1, type: isl_dim_out);
33 out2 = FN(MULTI(BASE),dim)(multi: multi2, type: 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)(multi: multi1),
37 FN(MULTI(BASE),get_space)(multi: multi2));
38 res = FN(MULTI(BASE),alloc)(space: isl_space_copy(space));
39 space = isl_space_domain(space);
40
41 for (i = 0; i < out1; ++i) {
42 el = FN(FN(MULTI(BASE),get),BASE)(multi: multi1, pos: i);
43 el = FN(EL,insert_dims)(aff: el, type: isl_dim_in, first: in1, n: in2);
44 el = FN(EL,reset_domain_space)(aff: el, space: isl_space_copy(space));
45 res = FN(FN(MULTI(BASE),set),BASE)(multi: res, pos: i, el);
46 }
47
48 for (i = 0; i < out2; ++i) {
49 el = FN(FN(MULTI(BASE),get),BASE)(multi: multi2, pos: i);
50 el = FN(EL,insert_dims)(aff: el, type: isl_dim_in, first: 0, n: in1);
51 el = FN(EL,reset_domain_space)(aff: el, space: isl_space_copy(space));
52 res = FN(FN(MULTI(BASE),set),BASE)(multi: res, pos: out1 + i, el);
53 }
54
55 if (FN(MULTI(BASE),has_explicit_domain)(multi: multi1) ||
56 FN(MULTI(BASE),has_explicit_domain)(multi: multi2))
57 res = FN(MULTI(BASE),intersect_explicit_domain_product)(dst: res,
58 src1: multi1, src2: multi2);
59
60 isl_space_free(space);
61 FN(MULTI(BASE),free)(multi: multi1);
62 FN(MULTI(BASE),free)(multi: multi2);
63 return res;
64error:
65 FN(MULTI(BASE),free)(multi: multi1);
66 FN(MULTI(BASE),free)(multi: multi2);
67 return NULL;
68}
69

source code of polly/lib/External/isl/isl_multi_product_templ.c