1 /*
2 * Copyright 2017 Sven Verdoolaege
3 *
4 * Use of this software is governed by the MIT license
5 *
6 * Written by Sven Verdoolaege,
7 */
8
9 /* Align the parameters of "multi" and "domain" (if needed) and
10 * call "fn".
11 */
MULTI(BASE)12 static __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),align_params),ALIGN_DOMBASE)(
13 __isl_take MULTI(BASE) *multi, __isl_take ALIGN_DOM *domain,
14 __isl_give MULTI(BASE) *fn(__isl_take MULTI(BASE) *multi,
15 __isl_take ALIGN_DOM *domain))
16 {
17 isl_bool aligned;
18 isl_bool named;
19 isl_space *dom_space;
20
21 aligned = FN(ALIGN_DOM,space_has_equal_params)(domain, multi->space);
22 if (aligned < 0)
23 goto error;
24 if (aligned)
25 return fn(multi, domain);
26
27 dom_space = FN(ALIGN_DOM,peek_space)(domain);
28 named = isl_space_has_named_params(multi->space);
29 if (named >= 0 && named)
30 named = isl_space_has_named_params(dom_space);
31 if (named < 0)
32 goto error;
33 if (!named)
34 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
35 "unaligned unnamed parameters", goto error);
36 multi = FN(MULTI(BASE),align_params)(multi,
37 FN(ALIGN_DOM,get_space)(domain));
38 domain = FN(ALIGN_DOM,align_params)(domain,
39 FN(MULTI(BASE),get_space)(multi));
40 return fn(multi, domain);
41 error:
42 FN(MULTI(BASE),free)(multi);
43 FN(ALIGN_DOM,free)(domain);
44 return NULL;
45 }
46