isl_map_simplify.c: drop_unrelated_constraints: improve error handling
[isl.git] / isl_multi_apply_templ.c
blobd4f70b2f82e3b490ae77a52725218d098b2bbfe5
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_multi_macro.h>
13 /* Transform the elements of "multi" by applying "fn" to them
14 * with extra argument "set".
16 * The parameters of "multi" and "set" are assumed to have been aligned.
18 __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),apply_aligned),APPLY_DOMBASE)(
19 __isl_take MULTI(BASE) *multi, __isl_take APPLY_DOM *set,
20 __isl_give EL *(*fn)(EL *el, __isl_take APPLY_DOM *set))
22 int i;
24 if (!multi || !set)
25 goto error;
27 if (multi->n == 0) {
28 FN(APPLY_DOM,free)(set);
29 return multi;
32 multi = FN(MULTI(BASE),cow)(multi);
33 if (!multi)
34 goto error;
36 for (i = 0; i < multi->n; ++i) {
37 multi->p[i] = fn(multi->p[i], FN(APPLY_DOM,copy)(set));
38 if (!multi->p[i])
39 goto error;
42 FN(APPLY_DOM,free)(set);
43 return multi;
44 error:
45 FN(APPLY_DOM,free)(set);
46 FN(MULTI(BASE),free)(multi);
47 return NULL;
50 /* Transform the elements of "multi" by applying "fn" to them
51 * with extra argument "set".
53 * Align the parameters if needed and call apply_set_aligned.
55 static __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),apply),APPLY_DOMBASE)(
56 __isl_take MULTI(BASE) *multi, __isl_take APPLY_DOM *set,
57 __isl_give EL *(*fn)(EL *el, __isl_take APPLY_DOM *set))
59 isl_ctx *ctx;
61 if (!multi || !set)
62 goto error;
64 if (isl_space_match(multi->space, isl_dim_param,
65 set->dim, isl_dim_param))
66 return FN(FN(MULTI(BASE),apply_aligned),APPLY_DOMBASE)(multi,
67 set, fn);
68 ctx = FN(MULTI(BASE),get_ctx)(multi);
69 if (!isl_space_has_named_params(multi->space) ||
70 !isl_space_has_named_params(set->dim))
71 isl_die(ctx, isl_error_invalid,
72 "unaligned unnamed parameters", goto error);
73 multi = FN(MULTI(BASE),align_params)(multi,
74 FN(APPLY_DOM,get_space)(set));
75 set = FN(APPLY_DOM,align_params)(set, FN(MULTI(BASE),get_space)(multi));
76 return FN(FN(MULTI(BASE),apply_aligned),APPLY_DOMBASE)(multi, set, fn);
77 error:
78 FN(MULTI(BASE),free)(multi);
79 FN(APPLY_DOM,free)(set);
80 return NULL;