isl_multi_templ.c: extract out isl_multi_dims.c
[isl.git] / isl_multi_dims.c
blob3e954153afc01325067387f80a0317844b0b61ec
1 /*
2 * Copyright 2011 Sven Verdoolaege
3 * Copyright 2012-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_private.h>
13 #include <isl_multi_macro.h>
15 /* Check whether "multi" has non-zero coefficients for any dimension
16 * in the given range or if any of these dimensions appear
17 * with non-zero coefficients in any of the integer divisions involved.
19 isl_bool FN(MULTI(BASE),involves_dims)(__isl_keep MULTI(BASE) *multi,
20 enum isl_dim_type type, unsigned first, unsigned n)
22 int i;
24 if (!multi)
25 return isl_bool_error;
26 if (multi->n == 0 || n == 0)
27 return isl_bool_false;
29 for (i = 0; i < multi->n; ++i) {
30 isl_bool involves;
32 involves = FN(EL,involves_dims)(multi->p[i], type, first, n);
33 if (involves < 0 || involves)
34 return involves;
37 return isl_bool_false;
40 __isl_give MULTI(BASE) *FN(MULTI(BASE),insert_dims)(
41 __isl_take MULTI(BASE) *multi,
42 enum isl_dim_type type, unsigned first, unsigned n)
44 int i;
46 if (!multi)
47 return NULL;
48 if (type == isl_dim_out)
49 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
50 "cannot insert output/set dimensions",
51 return FN(MULTI(BASE),free)(multi));
52 if (n == 0 && !isl_space_is_named_or_nested(multi->space, type))
53 return multi;
55 multi = FN(MULTI(BASE),cow)(multi);
56 if (!multi)
57 return NULL;
59 multi->space = isl_space_insert_dims(multi->space, type, first, n);
60 if (!multi->space)
61 return FN(MULTI(BASE),free)(multi);
63 for (i = 0; i < multi->n; ++i) {
64 multi->p[i] = FN(EL,insert_dims)(multi->p[i], type, first, n);
65 if (!multi->p[i])
66 return FN(MULTI(BASE),free)(multi);
69 return multi;
72 __isl_give MULTI(BASE) *FN(MULTI(BASE),add_dims)(__isl_take MULTI(BASE) *multi,
73 enum isl_dim_type type, unsigned n)
75 unsigned pos;
77 pos = FN(MULTI(BASE),dim)(multi, type);
79 return FN(MULTI(BASE),insert_dims)(multi, type, pos, n);