extract out shared isl_schedule_node_grandchild
[isl.git] / isl_multi_bind_templ.c
blobce2508c4517f15a0d931b55687de212e8359687f
1 /*
2 * Copyright 2018 Cerebras Systems
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege,
7 * Cerebras Systems, 175 S San Antonio Rd, Los Altos, CA, USA
8 */
10 /* Bind the expressions of "multi" to parameters with identifiers
11 * specified by "tuple", living in the same space as
12 * (the target space of) "multi",
13 * returning the elements in the domain where the expressions
14 * are equal to the parameters.
16 __isl_give DOM *FN(MULTI(BASE),bind)(__isl_take MULTI(BASE) *multi,
17 __isl_take isl_multi_id *tuple)
19 int i;
20 isl_id *id;
21 isl_stat r;
22 isl_size n;
23 isl_space *multi_space, *tuple_space;
24 EL *el;
25 DOM *bnd;
27 multi_space = isl_space_range(FN(MULTI(BASE),get_space)(multi));
28 tuple_space = isl_multi_id_peek_space(tuple);
29 r = isl_space_check_equal_tuples(multi_space, tuple_space);
30 isl_space_free(multi_space);
31 if (r < 0)
32 goto error;
33 n = FN(MULTI(BASE),dim)(multi, isl_dim_set);
34 if (n < 0)
35 goto error;
37 if (n == 0) {
38 isl_multi_id_free(tuple);
39 return FN(MULTI(BASE),domain)(multi);
42 el = FN(MULTI(BASE),get_at)(multi, 0);
43 id = isl_multi_id_get_at(tuple, 0);
44 bnd = FN(EL,bind_id)(el, id);
46 for (i = 1; i < n; ++i) {
47 DOM *bnd_i;
49 el = FN(MULTI(BASE),get_at)(multi, i);
50 id = isl_multi_id_get_at(tuple, i);
51 bnd_i = FN(EL,bind_id)(el, id);
53 bnd_i = FN(DOM,align_params)(bnd_i, FN(DOM,get_space)(bnd));
54 bnd = FN(DOM,align_params)(bnd, FN(DOM,get_space)(bnd_i));
55 bnd = FN(DOM,intersect)(bnd, bnd_i);
58 FN(MULTI(BASE),free)(multi);
59 isl_multi_id_free(tuple);
60 return bnd;
61 error:
62 FN(MULTI(BASE),free)(multi);
63 isl_multi_id_free(tuple);
64 return NULL;