[mlir] fix memory effects in GPU barrier elimination (#117432)
[llvm-project.git] / polly / lib / External / isl / isl_multi_pw_aff_pullback_templ.c
blobfc5aed2b3ffd845b0a9990edcf4e1b6808a79bf4
1 /*
2 * Copyright 2013 Ecole Normale Superieure
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege,
7 * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
8 */
10 #define xCAT(A,B) A ## B
11 #define CAT(A,B) xCAT(A,B)
12 #undef TYPE
13 #define TYPE CAT(isl_,BASE)
14 #define xFN(TYPE,NAME) TYPE ## _ ## NAME
15 #define FN(TYPE,NAME) xFN(TYPE,NAME)
17 #undef SUFFIX
18 #define SUFFIX BASE
19 #undef ARG1
20 #define ARG1 isl_multi_pw_aff
21 #undef ARG2
22 #define ARG2 TYPE
24 static
25 #include "isl_align_params_templ.c"
27 /* Compute the pullback of "mpa" by the function represented by "fn".
28 * In other words, plug in "fn" in "mpa".
30 * If "mpa" has an explicit domain, then it is this domain
31 * that needs to undergo a pullback, i.e., a preimage.
33 __isl_give isl_multi_pw_aff *FN(isl_multi_pw_aff_pullback,BASE)(
34 __isl_take isl_multi_pw_aff *mpa, __isl_take TYPE *fn)
36 int i;
37 isl_size n;
38 isl_space *space = NULL;
40 FN(isl_multi_pw_aff_align_params,BASE)(&mpa, &fn);
41 mpa = isl_multi_pw_aff_cow(mpa);
42 n = isl_multi_pw_aff_size(mpa);
43 if (n < 0 || !fn)
44 goto error;
46 space = isl_space_join(FN(TYPE,get_space)(fn),
47 isl_multi_pw_aff_get_space(mpa));
49 for (i = 0; i < n; ++i) {
50 isl_pw_aff *pa;
52 pa = isl_multi_pw_aff_take_at(mpa, i);
53 pa = FN(isl_pw_aff_pullback,BASE)(pa, FN(TYPE,copy)(fn));
54 mpa = isl_multi_pw_aff_restore_at(mpa, i, pa);
55 if (!mpa)
56 goto error;
58 if (isl_multi_pw_aff_has_explicit_domain(mpa)) {
59 mpa->u.dom = FN(isl_set_preimage,BASE)(mpa->u.dom,
60 FN(TYPE,copy)(fn));
61 if (!mpa->u.dom)
62 goto error;
65 FN(TYPE,free)(fn);
66 isl_multi_pw_aff_restore_space(mpa, space);
67 return mpa;
68 error:
69 isl_space_free(space);
70 isl_multi_pw_aff_free(mpa);
71 FN(TYPE,free)(fn);
72 return NULL;