• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012      Ecole Normale Superieure
3  *
4  * Use of this software is governed by the MIT license
5  *
6  * Written by Sven Verdoolaege,
7  * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
8  */
9 
10 #include <isl_pw_macro.h>
11 
12 #undef SUFFIX
13 #define SUFFIX	multi_aff
14 #undef ARG1
15 #define ARG1	PW
16 #undef ARG2
17 #define ARG2	isl_multi_aff
18 
19 static
20 #include "isl_align_params_templ.c"
21 
22 #undef SUFFIX
23 #define SUFFIX	pw_multi_aff
24 #undef ARG1
25 #define ARG1	PW
26 #undef ARG2
27 #define ARG2	isl_pw_multi_aff
28 
29 static
30 #include "isl_align_params_templ.c"
31 
32 /* Compute the pullback of "pw" by the function represented by "ma".
33  * In other words, plug in "ma" in "pw".
34  */
FN(PW,pullback_multi_aff)35 __isl_give PW *FN(PW,pullback_multi_aff)(__isl_take PW *pw,
36 	__isl_take isl_multi_aff *ma)
37 {
38 	int i;
39 	isl_space *space = NULL;
40 
41 	FN(PW,align_params_multi_aff)(&pw, &ma);
42 	ma = isl_multi_aff_align_divs(ma);
43 	pw = FN(PW,cow)(pw);
44 	if (!pw || !ma)
45 		goto error;
46 
47 	space = isl_space_join(isl_multi_aff_get_space(ma),
48 				FN(PW,get_space)(pw));
49 
50 	for (i = 0; i < pw->n; ++i) {
51 		pw->p[i].set = isl_set_preimage_multi_aff(pw->p[i].set,
52 						    isl_multi_aff_copy(ma));
53 		if (!pw->p[i].set)
54 			goto error;
55 		pw->p[i].FIELD = FN(EL,pullback_multi_aff)(pw->p[i].FIELD,
56 						    isl_multi_aff_copy(ma));
57 		if (!pw->p[i].FIELD)
58 			goto error;
59 	}
60 
61 	pw = FN(PW,reset_space)(pw, space);
62 	isl_multi_aff_free(ma);
63 	return pw;
64 error:
65 	isl_space_free(space);
66 	isl_multi_aff_free(ma);
67 	FN(PW,free)(pw);
68 	return NULL;
69 }
70 
71 /* Compute the pullback of "pw" by the function represented by "pma".
72  * In other words, plug in "pma" in "pw".
73  */
FN(PW,pullback_pw_multi_aff_aligned)74 static __isl_give PW *FN(PW,pullback_pw_multi_aff_aligned)(__isl_take PW *pw,
75 	__isl_take isl_pw_multi_aff *pma)
76 {
77 	int i;
78 	PW *res;
79 
80 	if (!pma)
81 		goto error;
82 
83 	if (pma->n == 0) {
84 		isl_space *space;
85 		space = isl_space_join(isl_pw_multi_aff_get_space(pma),
86 					FN(PW,get_space)(pw));
87 		isl_pw_multi_aff_free(pma);
88 		res = FN(PW,empty)(space);
89 		FN(PW,free)(pw);
90 		return res;
91 	}
92 
93 	res = FN(PW,pullback_multi_aff)(FN(PW,copy)(pw),
94 					isl_multi_aff_copy(pma->p[0].maff));
95 	res = FN(PW,intersect_domain)(res, isl_set_copy(pma->p[0].set));
96 
97 	for (i = 1; i < pma->n; ++i) {
98 		PW *res_i;
99 
100 		res_i = FN(PW,pullback_multi_aff)(FN(PW,copy)(pw),
101 					isl_multi_aff_copy(pma->p[i].maff));
102 		res_i = FN(PW,intersect_domain)(res_i,
103 					isl_set_copy(pma->p[i].set));
104 		res = FN(PW,add_disjoint)(res, res_i);
105 	}
106 
107 	isl_pw_multi_aff_free(pma);
108 	FN(PW,free)(pw);
109 	return res;
110 error:
111 	isl_pw_multi_aff_free(pma);
112 	FN(PW,free)(pw);
113 	return NULL;
114 }
115 
FN(PW,pullback_pw_multi_aff)116 __isl_give PW *FN(PW,pullback_pw_multi_aff)(__isl_take PW *pw,
117 	__isl_take isl_pw_multi_aff *pma)
118 {
119 	FN(PW,align_params_pw_multi_aff)(&pw, &pma);
120 	return FN(PW,pullback_pw_multi_aff_aligned)(pw, pma);
121 }
122