export isl_pw_multi_aff_scale{_down,}_val
[isl.git] / isl_multi_dim_id_templ.c
blob80dd7db5878fd0c3ea064f50bcd78732aaaefb68
1 /*
2 * Copyright 2011 Sven Verdoolaege
3 * Copyright 2013 Ecole Normale Superieure
5 * Use of this software is governed by the MIT license
7 * Written by Sven Verdoolaege,
8 * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
9 */
11 #include <isl/space.h>
13 #include <isl_multi_macro.h>
15 /* Return the position of the dimension of the given type and name
16 * in "multi".
17 * Return -1 if no such dimension can be found.
19 int FN(MULTI(BASE),find_dim_by_name)(__isl_keep MULTI(BASE) *multi,
20 enum isl_dim_type type, const char *name)
22 if (!multi)
23 return -1;
24 return isl_space_find_dim_by_name(multi->space, type, name);
27 /* Return the position of the first dimension of "type" with id "id".
28 * Return -1 if there is no such dimension.
30 int FN(MULTI(BASE),find_dim_by_id)(__isl_keep MULTI(BASE) *multi,
31 enum isl_dim_type type, __isl_keep isl_id *id)
33 if (!multi)
34 return -1;
35 return isl_space_find_dim_by_id(multi->space, type, id);
38 /* Return the id of the given dimension.
40 __isl_give isl_id *FN(MULTI(BASE),get_dim_id)(__isl_keep MULTI(BASE) *multi,
41 enum isl_dim_type type, unsigned pos)
43 return multi ? isl_space_get_dim_id(multi->space, type, pos) : NULL;
46 __isl_give MULTI(BASE) *FN(MULTI(BASE),set_dim_name)(
47 __isl_take MULTI(BASE) *multi,
48 enum isl_dim_type type, unsigned pos, const char *s)
50 int i;
52 multi = FN(MULTI(BASE),cow)(multi);
53 if (!multi)
54 return NULL;
56 multi->space = isl_space_set_dim_name(multi->space, type, pos, s);
57 if (!multi->space)
58 return FN(MULTI(BASE),free)(multi);
60 if (type == isl_dim_out)
61 return multi;
62 for (i = 0; i < multi->n; ++i) {
63 multi->u.p[i] = FN(EL,set_dim_name)(multi->u.p[i],
64 type, pos, s);
65 if (!multi->u.p[i])
66 return FN(MULTI(BASE),free)(multi);
69 return multi;
72 /* Set the id of the given dimension of "multi" to "id".
74 __isl_give MULTI(BASE) *FN(MULTI(BASE),set_dim_id)(
75 __isl_take MULTI(BASE) *multi,
76 enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
78 isl_space *space;
80 multi = FN(MULTI(BASE),cow)(multi);
81 if (!multi || !id)
82 goto error;
84 space = FN(MULTI(BASE),get_space)(multi);
85 space = isl_space_set_dim_id(space, type, pos, id);
87 return FN(MULTI(BASE),reset_space)(multi, space);
88 error:
89 isl_id_free(id);
90 FN(MULTI(BASE),free)(multi);
91 return NULL;