File: | tools/polly/lib/External/isl/isl_space.c |
Warning: | line 2459, column 8 Array access (via field 'ids') results in a null pointer dereference |
1 | /* | |||
2 | * Copyright 2008-2009 Katholieke Universiteit Leuven | |||
3 | * Copyright 2010 INRIA Saclay | |||
4 | * Copyright 2013-2014 Ecole Normale Superieure | |||
5 | * | |||
6 | * Use of this software is governed by the MIT license | |||
7 | * | |||
8 | * Written by Sven Verdoolaege, K.U.Leuven, Departement | |||
9 | * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium | |||
10 | * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite, | |||
11 | * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France | |||
12 | * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France | |||
13 | */ | |||
14 | ||||
15 | #include <stdlib.h> | |||
16 | #include <string.h> | |||
17 | #include <isl_space_private.h> | |||
18 | #include <isl_id_private.h> | |||
19 | #include <isl_reordering.h> | |||
20 | ||||
21 | isl_ctx *isl_space_get_ctx(__isl_keep isl_space *dim) | |||
22 | { | |||
23 | return dim ? dim->ctx : NULL((void*)0); | |||
24 | } | |||
25 | ||||
26 | __isl_give isl_space *isl_space_alloc(isl_ctx *ctx, | |||
27 | unsigned nparam, unsigned n_in, unsigned n_out) | |||
28 | { | |||
29 | isl_space *dim; | |||
30 | ||||
31 | dim = isl_alloc_type(ctx, struct isl_space)((struct isl_space *)isl_malloc_or_die(ctx, sizeof(struct isl_space ))); | |||
32 | if (!dim) | |||
33 | return NULL((void*)0); | |||
34 | ||||
35 | dim->ctx = ctx; | |||
36 | isl_ctx_ref(ctx); | |||
37 | dim->ref = 1; | |||
38 | dim->nparam = nparam; | |||
39 | dim->n_in = n_in; | |||
40 | dim->n_out = n_out; | |||
41 | ||||
42 | dim->tuple_id[0] = NULL((void*)0); | |||
43 | dim->tuple_id[1] = NULL((void*)0); | |||
44 | ||||
45 | dim->nested[0] = NULL((void*)0); | |||
46 | dim->nested[1] = NULL((void*)0); | |||
47 | ||||
48 | dim->n_id = 0; | |||
49 | dim->ids = NULL((void*)0); | |||
50 | ||||
51 | return dim; | |||
52 | } | |||
53 | ||||
54 | /* Mark the space as being that of a set, by setting the domain tuple | |||
55 | * to isl_id_none. | |||
56 | */ | |||
57 | static __isl_give isl_space *mark_as_set(__isl_take isl_space *space) | |||
58 | { | |||
59 | space = isl_space_cow(space); | |||
60 | if (!space) | |||
61 | return NULL((void*)0); | |||
62 | space = isl_space_set_tuple_id(space, isl_dim_in, &isl_id_none); | |||
63 | return space; | |||
64 | } | |||
65 | ||||
66 | /* Is the space that of a set? | |||
67 | */ | |||
68 | isl_bool isl_space_is_set(__isl_keep isl_space *space) | |||
69 | { | |||
70 | if (!space) | |||
71 | return isl_bool_error; | |||
72 | if (space->n_in != 0 || space->nested[0]) | |||
73 | return isl_bool_false; | |||
74 | if (space->tuple_id[0] != &isl_id_none) | |||
75 | return isl_bool_false; | |||
76 | return isl_bool_true; | |||
77 | } | |||
78 | ||||
79 | /* Is the given space that of a map? | |||
80 | */ | |||
81 | isl_bool isl_space_is_map(__isl_keep isl_space *space) | |||
82 | { | |||
83 | if (!space) | |||
84 | return isl_bool_error; | |||
85 | return space->tuple_id[0] != &isl_id_none && | |||
86 | space->tuple_id[1] != &isl_id_none; | |||
87 | } | |||
88 | ||||
89 | __isl_give isl_space *isl_space_set_alloc(isl_ctx *ctx, | |||
90 | unsigned nparam, unsigned dim) | |||
91 | { | |||
92 | isl_space *space; | |||
93 | space = isl_space_alloc(ctx, nparam, 0, dim); | |||
94 | space = mark_as_set(space); | |||
95 | return space; | |||
96 | } | |||
97 | ||||
98 | /* Mark the space as being that of a parameter domain, by setting | |||
99 | * both tuples to isl_id_none. | |||
100 | */ | |||
101 | static __isl_give isl_space *mark_as_params(isl_space *space) | |||
102 | { | |||
103 | if (!space) | |||
104 | return NULL((void*)0); | |||
105 | space = isl_space_set_tuple_id(space, isl_dim_in, &isl_id_none); | |||
106 | space = isl_space_set_tuple_id(space, isl_dim_out, &isl_id_none); | |||
107 | return space; | |||
108 | } | |||
109 | ||||
110 | /* Is the space that of a parameter domain? | |||
111 | */ | |||
112 | isl_bool isl_space_is_params(__isl_keep isl_space *space) | |||
113 | { | |||
114 | if (!space) | |||
115 | return isl_bool_error; | |||
116 | if (space->n_in != 0 || space->nested[0] || | |||
117 | space->n_out != 0 || space->nested[1]) | |||
118 | return isl_bool_false; | |||
119 | if (space->tuple_id[0] != &isl_id_none) | |||
120 | return isl_bool_false; | |||
121 | if (space->tuple_id[1] != &isl_id_none) | |||
122 | return isl_bool_false; | |||
123 | return isl_bool_true; | |||
124 | } | |||
125 | ||||
126 | /* Create a space for a parameter domain. | |||
127 | */ | |||
128 | __isl_give isl_space *isl_space_params_alloc(isl_ctx *ctx, unsigned nparam) | |||
129 | { | |||
130 | isl_space *space; | |||
131 | space = isl_space_alloc(ctx, nparam, 0, 0); | |||
132 | space = mark_as_params(space); | |||
133 | return space; | |||
134 | } | |||
135 | ||||
136 | static unsigned global_pos(__isl_keep isl_space *dim, | |||
137 | enum isl_dim_type type, unsigned pos) | |||
138 | { | |||
139 | struct isl_ctx *ctx = dim->ctx; | |||
140 | ||||
141 | switch (type) { | |||
142 | case isl_dim_param: | |||
143 | isl_assert(ctx, pos < dim->nparam,do { if (pos < dim->nparam) break; do { isl_handle_error (ctx, isl_error_unknown, "Assertion \"" "pos < dim->nparam" "\" failed", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 144); return isl_space_dim(dim, isl_dim_all); } while (0); } while (0) | |||
144 | return isl_space_dim(dim, isl_dim_all))do { if (pos < dim->nparam) break; do { isl_handle_error (ctx, isl_error_unknown, "Assertion \"" "pos < dim->nparam" "\" failed", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 144); return isl_space_dim(dim, isl_dim_all); } while (0); } while (0); | |||
145 | return pos; | |||
146 | case isl_dim_in: | |||
147 | isl_assert(ctx, pos < dim->n_in,do { if (pos < dim->n_in) break; do { isl_handle_error( ctx, isl_error_unknown, "Assertion \"" "pos < dim->n_in" "\" failed", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 148); return isl_space_dim(dim, isl_dim_all); } while (0); } while (0) | |||
148 | return isl_space_dim(dim, isl_dim_all))do { if (pos < dim->n_in) break; do { isl_handle_error( ctx, isl_error_unknown, "Assertion \"" "pos < dim->n_in" "\" failed", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 148); return isl_space_dim(dim, isl_dim_all); } while (0); } while (0); | |||
149 | return pos + dim->nparam; | |||
150 | case isl_dim_out: | |||
151 | isl_assert(ctx, pos < dim->n_out,do { if (pos < dim->n_out) break; do { isl_handle_error (ctx, isl_error_unknown, "Assertion \"" "pos < dim->n_out" "\" failed", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 152); return isl_space_dim(dim, isl_dim_all); } while (0); } while (0) | |||
152 | return isl_space_dim(dim, isl_dim_all))do { if (pos < dim->n_out) break; do { isl_handle_error (ctx, isl_error_unknown, "Assertion \"" "pos < dim->n_out" "\" failed", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 152); return isl_space_dim(dim, isl_dim_all); } while (0); } while (0); | |||
153 | return pos + dim->nparam + dim->n_in; | |||
154 | default: | |||
155 | isl_assert(ctx, 0, return isl_space_dim(dim, isl_dim_all))do { if (0) break; do { isl_handle_error(ctx, isl_error_unknown , "Assertion \"" "0" "\" failed", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 155); return isl_space_dim(dim, isl_dim_all); } while (0); } while (0); | |||
156 | } | |||
157 | return isl_space_dim(dim, isl_dim_all); | |||
158 | } | |||
159 | ||||
160 | /* Extend length of ids array to the total number of dimensions. | |||
161 | */ | |||
162 | static __isl_give isl_space *extend_ids(__isl_take isl_space *dim) | |||
163 | { | |||
164 | isl_id **ids; | |||
165 | int i; | |||
166 | ||||
167 | if (isl_space_dim(dim, isl_dim_all) <= dim->n_id) | |||
168 | return dim; | |||
169 | ||||
170 | if (!dim->ids) { | |||
171 | dim->ids = isl_calloc_array(dim->ctx,((isl_id * *)isl_calloc_or_die(dim->ctx, isl_space_dim(dim , isl_dim_all), sizeof(isl_id *))) | |||
172 | isl_id *, isl_space_dim(dim, isl_dim_all))((isl_id * *)isl_calloc_or_die(dim->ctx, isl_space_dim(dim , isl_dim_all), sizeof(isl_id *))); | |||
173 | if (!dim->ids) | |||
174 | goto error; | |||
175 | } else { | |||
176 | ids = isl_realloc_array(dim->ctx, dim->ids,((isl_id * *)isl_realloc_or_die(dim->ctx, dim->ids, (isl_space_dim (dim, isl_dim_all))*sizeof(isl_id *))) | |||
177 | isl_id *, isl_space_dim(dim, isl_dim_all))((isl_id * *)isl_realloc_or_die(dim->ctx, dim->ids, (isl_space_dim (dim, isl_dim_all))*sizeof(isl_id *))); | |||
178 | if (!ids) | |||
179 | goto error; | |||
180 | dim->ids = ids; | |||
181 | for (i = dim->n_id; i < isl_space_dim(dim, isl_dim_all); ++i) | |||
182 | dim->ids[i] = NULL((void*)0); | |||
183 | } | |||
184 | ||||
185 | dim->n_id = isl_space_dim(dim, isl_dim_all); | |||
186 | ||||
187 | return dim; | |||
188 | error: | |||
189 | isl_space_free(dim); | |||
190 | return NULL((void*)0); | |||
191 | } | |||
192 | ||||
193 | static __isl_give isl_space *set_id(__isl_take isl_space *dim, | |||
194 | enum isl_dim_type type, unsigned pos, __isl_take isl_id *id) | |||
195 | { | |||
196 | dim = isl_space_cow(dim); | |||
197 | ||||
198 | if (!dim) | |||
199 | goto error; | |||
200 | ||||
201 | pos = global_pos(dim, type, pos); | |||
202 | if (pos == isl_space_dim(dim, isl_dim_all)) | |||
203 | goto error; | |||
204 | ||||
205 | if (pos >= dim->n_id) { | |||
206 | if (!id) | |||
207 | return dim; | |||
208 | dim = extend_ids(dim); | |||
209 | if (!dim) | |||
210 | goto error; | |||
211 | } | |||
212 | ||||
213 | dim->ids[pos] = id; | |||
214 | ||||
215 | return dim; | |||
216 | error: | |||
217 | isl_id_free(id); | |||
218 | isl_space_free(dim); | |||
219 | return NULL((void*)0); | |||
220 | } | |||
221 | ||||
222 | static __isl_keep isl_id *get_id(__isl_keep isl_space *dim, | |||
223 | enum isl_dim_type type, unsigned pos) | |||
224 | { | |||
225 | if (!dim) | |||
226 | return NULL((void*)0); | |||
227 | ||||
228 | pos = global_pos(dim, type, pos); | |||
229 | if (pos == isl_space_dim(dim, isl_dim_all)) | |||
230 | return NULL((void*)0); | |||
231 | if (pos >= dim->n_id) | |||
232 | return NULL((void*)0); | |||
233 | return dim->ids[pos]; | |||
234 | } | |||
235 | ||||
236 | static unsigned offset(__isl_keep isl_space *dim, enum isl_dim_type type) | |||
237 | { | |||
238 | switch (type) { | |||
239 | case isl_dim_param: return 0; | |||
240 | case isl_dim_in: return dim->nparam; | |||
241 | case isl_dim_out: return dim->nparam + dim->n_in; | |||
242 | default: return 0; | |||
243 | } | |||
244 | } | |||
245 | ||||
246 | static unsigned n(__isl_keep isl_space *dim, enum isl_dim_type type) | |||
247 | { | |||
248 | switch (type) { | |||
249 | case isl_dim_param: return dim->nparam; | |||
250 | case isl_dim_in: return dim->n_in; | |||
251 | case isl_dim_out: return dim->n_out; | |||
252 | case isl_dim_all: return dim->nparam + dim->n_in + dim->n_out; | |||
253 | default: return 0; | |||
254 | } | |||
255 | } | |||
256 | ||||
257 | unsigned isl_space_dim(__isl_keep isl_space *dim, enum isl_dim_type type) | |||
258 | { | |||
259 | if (!dim) | |||
260 | return 0; | |||
261 | return n(dim, type); | |||
262 | } | |||
263 | ||||
264 | unsigned isl_space_offset(__isl_keep isl_space *dim, enum isl_dim_type type) | |||
265 | { | |||
266 | if (!dim) | |||
267 | return 0; | |||
268 | return offset(dim, type); | |||
269 | } | |||
270 | ||||
271 | static __isl_give isl_space *copy_ids(__isl_take isl_space *dst, | |||
272 | enum isl_dim_type dst_type, unsigned offset, __isl_keep isl_space *src, | |||
273 | enum isl_dim_type src_type) | |||
274 | { | |||
275 | int i; | |||
276 | isl_id *id; | |||
277 | ||||
278 | if (!dst) | |||
279 | return NULL((void*)0); | |||
280 | ||||
281 | for (i = 0; i < n(src, src_type); ++i) { | |||
282 | id = get_id(src, src_type, i); | |||
283 | if (!id) | |||
284 | continue; | |||
285 | dst = set_id(dst, dst_type, offset + i, isl_id_copy(id)); | |||
286 | if (!dst) | |||
287 | return NULL((void*)0); | |||
288 | } | |||
289 | return dst; | |||
290 | } | |||
291 | ||||
292 | __isl_take isl_space *isl_space_dup(__isl_keep isl_space *dim) | |||
293 | { | |||
294 | isl_space *dup; | |||
295 | if (!dim) | |||
296 | return NULL((void*)0); | |||
297 | dup = isl_space_alloc(dim->ctx, dim->nparam, dim->n_in, dim->n_out); | |||
298 | if (!dup) | |||
299 | return NULL((void*)0); | |||
300 | if (dim->tuple_id[0] && | |||
301 | !(dup->tuple_id[0] = isl_id_copy(dim->tuple_id[0]))) | |||
302 | goto error; | |||
303 | if (dim->tuple_id[1] && | |||
304 | !(dup->tuple_id[1] = isl_id_copy(dim->tuple_id[1]))) | |||
305 | goto error; | |||
306 | if (dim->nested[0] && !(dup->nested[0] = isl_space_copy(dim->nested[0]))) | |||
307 | goto error; | |||
308 | if (dim->nested[1] && !(dup->nested[1] = isl_space_copy(dim->nested[1]))) | |||
309 | goto error; | |||
310 | if (!dim->ids) | |||
311 | return dup; | |||
312 | dup = copy_ids(dup, isl_dim_param, 0, dim, isl_dim_param); | |||
313 | dup = copy_ids(dup, isl_dim_in, 0, dim, isl_dim_in); | |||
314 | dup = copy_ids(dup, isl_dim_out, 0, dim, isl_dim_out); | |||
315 | return dup; | |||
316 | error: | |||
317 | isl_space_free(dup); | |||
318 | return NULL((void*)0); | |||
319 | } | |||
320 | ||||
321 | __isl_give isl_space *isl_space_cow(__isl_take isl_space *dim) | |||
322 | { | |||
323 | if (!dim) | |||
324 | return NULL((void*)0); | |||
325 | ||||
326 | if (dim->ref == 1) | |||
327 | return dim; | |||
328 | dim->ref--; | |||
329 | return isl_space_dup(dim); | |||
330 | } | |||
331 | ||||
332 | __isl_give isl_space *isl_space_copy(__isl_keep isl_space *dim) | |||
333 | { | |||
334 | if (!dim) | |||
335 | return NULL((void*)0); | |||
336 | ||||
337 | dim->ref++; | |||
338 | return dim; | |||
339 | } | |||
340 | ||||
341 | __isl_null isl_space *isl_space_free(__isl_take isl_space *space) | |||
342 | { | |||
343 | int i; | |||
344 | ||||
345 | if (!space) | |||
346 | return NULL((void*)0); | |||
347 | ||||
348 | if (--space->ref > 0) | |||
349 | return NULL((void*)0); | |||
350 | ||||
351 | isl_id_free(space->tuple_id[0]); | |||
352 | isl_id_free(space->tuple_id[1]); | |||
353 | ||||
354 | isl_space_free(space->nested[0]); | |||
355 | isl_space_free(space->nested[1]); | |||
356 | ||||
357 | for (i = 0; i < space->n_id; ++i) | |||
358 | isl_id_free(space->ids[i]); | |||
359 | free(space->ids); | |||
360 | isl_ctx_deref(space->ctx); | |||
361 | ||||
362 | free(space); | |||
363 | ||||
364 | return NULL((void*)0); | |||
365 | } | |||
366 | ||||
367 | /* Check if "s" is a valid dimension or tuple name. | |||
368 | * We currently only forbid names that look like a number. | |||
369 | * | |||
370 | * s is assumed to be non-NULL. | |||
371 | */ | |||
372 | static int name_ok(isl_ctx *ctx, const char *s) | |||
373 | { | |||
374 | char *p; | |||
375 | long dummy; | |||
376 | ||||
377 | dummy = strtol(s, &p, 0); | |||
378 | if (p != s) | |||
379 | isl_die(ctx, isl_error_invalid, "name looks like a number",do { isl_handle_error(ctx, isl_error_invalid, "name looks like a number" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 380); return 0; } while (0) | |||
380 | return 0)do { isl_handle_error(ctx, isl_error_invalid, "name looks like a number" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 380); return 0; } while (0); | |||
381 | ||||
382 | return 1; | |||
383 | } | |||
384 | ||||
385 | /* Is it possible for the given dimension type to have a tuple id? | |||
386 | */ | |||
387 | static int space_can_have_id(__isl_keep isl_space *space, | |||
388 | enum isl_dim_type type) | |||
389 | { | |||
390 | if (!space) | |||
391 | return 0; | |||
392 | if (isl_space_is_params(space)) | |||
393 | isl_die(space->ctx, isl_error_invalid,do { isl_handle_error(space->ctx, isl_error_invalid, "parameter spaces don't have tuple ids" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 394); return 0; } while (0) | |||
394 | "parameter spaces don't have tuple ids", return 0)do { isl_handle_error(space->ctx, isl_error_invalid, "parameter spaces don't have tuple ids" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 394); return 0; } while (0); | |||
395 | if (isl_space_is_set(space) && type != isl_dim_set) | |||
396 | isl_die(space->ctx, isl_error_invalid,do { isl_handle_error(space->ctx, isl_error_invalid, "set spaces can only have a set id" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 397); return 0; } while (0) | |||
397 | "set spaces can only have a set id", return 0)do { isl_handle_error(space->ctx, isl_error_invalid, "set spaces can only have a set id" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 397); return 0; } while (0); | |||
398 | if (type != isl_dim_in && type != isl_dim_out) | |||
399 | isl_die(space->ctx, isl_error_invalid,do { isl_handle_error(space->ctx, isl_error_invalid, "only input, output and set tuples can have ids" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 401); return 0; } while (0) | |||
400 | "only input, output and set tuples can have ids",do { isl_handle_error(space->ctx, isl_error_invalid, "only input, output and set tuples can have ids" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 401); return 0; } while (0) | |||
401 | return 0)do { isl_handle_error(space->ctx, isl_error_invalid, "only input, output and set tuples can have ids" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 401); return 0; } while (0); | |||
402 | ||||
403 | return 1; | |||
404 | } | |||
405 | ||||
406 | /* Does the tuple have an id? | |||
407 | */ | |||
408 | isl_bool isl_space_has_tuple_id(__isl_keep isl_space *dim, | |||
409 | enum isl_dim_type type) | |||
410 | { | |||
411 | if (!space_can_have_id(dim, type)) | |||
412 | return isl_bool_error; | |||
413 | return dim->tuple_id[type - isl_dim_in] != NULL((void*)0); | |||
414 | } | |||
415 | ||||
416 | __isl_give isl_id *isl_space_get_tuple_id(__isl_keep isl_space *dim, | |||
417 | enum isl_dim_type type) | |||
418 | { | |||
419 | int has_id; | |||
420 | ||||
421 | if (!dim) | |||
422 | return NULL((void*)0); | |||
423 | has_id = isl_space_has_tuple_id(dim, type); | |||
424 | if (has_id < 0) | |||
425 | return NULL((void*)0); | |||
426 | if (!has_id) | |||
427 | isl_die(dim->ctx, isl_error_invalid,do { isl_handle_error(dim->ctx, isl_error_invalid, "tuple has no id" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 428); return ((void*)0); } while (0) | |||
428 | "tuple has no id", return NULL)do { isl_handle_error(dim->ctx, isl_error_invalid, "tuple has no id" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 428); return ((void*)0); } while (0); | |||
429 | return isl_id_copy(dim->tuple_id[type - isl_dim_in]); | |||
430 | } | |||
431 | ||||
432 | __isl_give isl_space *isl_space_set_tuple_id(__isl_take isl_space *dim, | |||
433 | enum isl_dim_type type, __isl_take isl_id *id) | |||
434 | { | |||
435 | dim = isl_space_cow(dim); | |||
436 | if (!dim || !id) | |||
437 | goto error; | |||
438 | if (type != isl_dim_in && type != isl_dim_out) | |||
439 | isl_die(dim->ctx, isl_error_invalid,do { isl_handle_error(dim->ctx, isl_error_invalid, "only input, output and set tuples can have names" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 441); goto error; } while (0) | |||
440 | "only input, output and set tuples can have names",do { isl_handle_error(dim->ctx, isl_error_invalid, "only input, output and set tuples can have names" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 441); goto error; } while (0) | |||
441 | goto error)do { isl_handle_error(dim->ctx, isl_error_invalid, "only input, output and set tuples can have names" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 441); goto error; } while (0); | |||
442 | ||||
443 | isl_id_free(dim->tuple_id[type - isl_dim_in]); | |||
444 | dim->tuple_id[type - isl_dim_in] = id; | |||
445 | ||||
446 | return dim; | |||
447 | error: | |||
448 | isl_id_free(id); | |||
449 | isl_space_free(dim); | |||
450 | return NULL((void*)0); | |||
451 | } | |||
452 | ||||
453 | __isl_give isl_space *isl_space_reset_tuple_id(__isl_take isl_space *dim, | |||
454 | enum isl_dim_type type) | |||
455 | { | |||
456 | dim = isl_space_cow(dim); | |||
457 | if (!dim) | |||
458 | return NULL((void*)0); | |||
459 | if (type != isl_dim_in && type != isl_dim_out) | |||
460 | isl_die(dim->ctx, isl_error_invalid,do { isl_handle_error(dim->ctx, isl_error_invalid, "only input, output and set tuples can have names" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 462); goto error; } while (0) | |||
461 | "only input, output and set tuples can have names",do { isl_handle_error(dim->ctx, isl_error_invalid, "only input, output and set tuples can have names" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 462); goto error; } while (0) | |||
462 | goto error)do { isl_handle_error(dim->ctx, isl_error_invalid, "only input, output and set tuples can have names" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 462); goto error; } while (0); | |||
463 | ||||
464 | isl_id_free(dim->tuple_id[type - isl_dim_in]); | |||
465 | dim->tuple_id[type - isl_dim_in] = NULL((void*)0); | |||
466 | ||||
467 | return dim; | |||
468 | error: | |||
469 | isl_space_free(dim); | |||
470 | return NULL((void*)0); | |||
471 | } | |||
472 | ||||
473 | /* Set the id of the given dimension of "space" to "id". | |||
474 | * If the dimension already has an id, then it is replaced. | |||
475 | * If the dimension is a parameter, then we need to change it | |||
476 | * in the nested spaces (if any) as well. | |||
477 | */ | |||
478 | __isl_give isl_space *isl_space_set_dim_id(__isl_take isl_space *space, | |||
479 | enum isl_dim_type type, unsigned pos, __isl_take isl_id *id) | |||
480 | { | |||
481 | space = isl_space_cow(space); | |||
482 | if (!space || !id) | |||
483 | goto error; | |||
484 | ||||
485 | if (type == isl_dim_param) { | |||
486 | int i; | |||
487 | ||||
488 | for (i = 0; i < 2; ++i) { | |||
489 | if (!space->nested[i]) | |||
490 | continue; | |||
491 | space->nested[i] = | |||
492 | isl_space_set_dim_id(space->nested[i], | |||
493 | type, pos, isl_id_copy(id)); | |||
494 | if (!space->nested[i]) | |||
495 | goto error; | |||
496 | } | |||
497 | } | |||
498 | ||||
499 | isl_id_free(get_id(space, type, pos)); | |||
500 | return set_id(space, type, pos, id); | |||
501 | error: | |||
502 | isl_id_free(id); | |||
503 | isl_space_free(space); | |||
504 | return NULL((void*)0); | |||
505 | } | |||
506 | ||||
507 | /* Reset the id of the given dimension of "space". | |||
508 | * If the dimension already has an id, then it is removed. | |||
509 | * If the dimension is a parameter, then we need to reset it | |||
510 | * in the nested spaces (if any) as well. | |||
511 | */ | |||
512 | __isl_give isl_space *isl_space_reset_dim_id(__isl_take isl_space *space, | |||
513 | enum isl_dim_type type, unsigned pos) | |||
514 | { | |||
515 | space = isl_space_cow(space); | |||
516 | if (!space) | |||
517 | goto error; | |||
518 | ||||
519 | if (type == isl_dim_param) { | |||
520 | int i; | |||
521 | ||||
522 | for (i = 0; i < 2; ++i) { | |||
523 | if (!space->nested[i]) | |||
524 | continue; | |||
525 | space->nested[i] = | |||
526 | isl_space_reset_dim_id(space->nested[i], | |||
527 | type, pos); | |||
528 | if (!space->nested[i]) | |||
529 | goto error; | |||
530 | } | |||
531 | } | |||
532 | ||||
533 | isl_id_free(get_id(space, type, pos)); | |||
534 | return set_id(space, type, pos, NULL((void*)0)); | |||
535 | error: | |||
536 | isl_space_free(space); | |||
537 | return NULL((void*)0); | |||
538 | } | |||
539 | ||||
540 | isl_bool isl_space_has_dim_id(__isl_keep isl_space *dim, | |||
541 | enum isl_dim_type type, unsigned pos) | |||
542 | { | |||
543 | if (!dim) | |||
544 | return isl_bool_error; | |||
545 | return get_id(dim, type, pos) != NULL((void*)0); | |||
546 | } | |||
547 | ||||
548 | __isl_give isl_id *isl_space_get_dim_id(__isl_keep isl_space *dim, | |||
549 | enum isl_dim_type type, unsigned pos) | |||
550 | { | |||
551 | if (!dim) | |||
552 | return NULL((void*)0); | |||
553 | if (!get_id(dim, type, pos)) | |||
554 | isl_die(dim->ctx, isl_error_invalid,do { isl_handle_error(dim->ctx, isl_error_invalid, "dim has no id" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 555); return ((void*)0); } while (0) | |||
555 | "dim has no id", return NULL)do { isl_handle_error(dim->ctx, isl_error_invalid, "dim has no id" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 555); return ((void*)0); } while (0); | |||
556 | return isl_id_copy(get_id(dim, type, pos)); | |||
557 | } | |||
558 | ||||
559 | __isl_give isl_space *isl_space_set_tuple_name(__isl_take isl_space *dim, | |||
560 | enum isl_dim_type type, const char *s) | |||
561 | { | |||
562 | isl_id *id; | |||
563 | ||||
564 | if (!dim) | |||
565 | return NULL((void*)0); | |||
566 | ||||
567 | if (!s) | |||
568 | return isl_space_reset_tuple_id(dim, type); | |||
569 | ||||
570 | if (!name_ok(dim->ctx, s)) | |||
571 | goto error; | |||
572 | ||||
573 | id = isl_id_alloc(dim->ctx, s, NULL((void*)0)); | |||
574 | return isl_space_set_tuple_id(dim, type, id); | |||
575 | error: | |||
576 | isl_space_free(dim); | |||
577 | return NULL((void*)0); | |||
578 | } | |||
579 | ||||
580 | /* Does the tuple have a name? | |||
581 | */ | |||
582 | isl_bool isl_space_has_tuple_name(__isl_keep isl_space *space, | |||
583 | enum isl_dim_type type) | |||
584 | { | |||
585 | isl_id *id; | |||
586 | ||||
587 | if (!space_can_have_id(space, type)) | |||
588 | return isl_bool_error; | |||
589 | id = space->tuple_id[type - isl_dim_in]; | |||
590 | return id && id->name; | |||
591 | } | |||
592 | ||||
593 | __isl_keep const char *isl_space_get_tuple_name(__isl_keep isl_space *dim, | |||
594 | enum isl_dim_type type) | |||
595 | { | |||
596 | isl_id *id; | |||
597 | if (!dim) | |||
598 | return NULL((void*)0); | |||
599 | if (type != isl_dim_in && type != isl_dim_out) | |||
600 | return NULL((void*)0); | |||
601 | id = dim->tuple_id[type - isl_dim_in]; | |||
602 | return id ? id->name : NULL((void*)0); | |||
603 | } | |||
604 | ||||
605 | __isl_give isl_space *isl_space_set_dim_name(__isl_take isl_space *dim, | |||
606 | enum isl_dim_type type, unsigned pos, | |||
607 | const char *s) | |||
608 | { | |||
609 | isl_id *id; | |||
610 | ||||
611 | if (!dim) | |||
612 | return NULL((void*)0); | |||
613 | if (!s) | |||
614 | return isl_space_reset_dim_id(dim, type, pos); | |||
615 | if (!name_ok(dim->ctx, s)) | |||
616 | goto error; | |||
617 | id = isl_id_alloc(dim->ctx, s, NULL((void*)0)); | |||
618 | return isl_space_set_dim_id(dim, type, pos, id); | |||
619 | error: | |||
620 | isl_space_free(dim); | |||
621 | return NULL((void*)0); | |||
622 | } | |||
623 | ||||
624 | /* Does the given dimension have a name? | |||
625 | */ | |||
626 | isl_bool isl_space_has_dim_name(__isl_keep isl_space *space, | |||
627 | enum isl_dim_type type, unsigned pos) | |||
628 | { | |||
629 | isl_id *id; | |||
630 | ||||
631 | if (!space) | |||
632 | return isl_bool_error; | |||
633 | id = get_id(space, type, pos); | |||
634 | return id && id->name; | |||
635 | } | |||
636 | ||||
637 | __isl_keep const char *isl_space_get_dim_name(__isl_keep isl_space *dim, | |||
638 | enum isl_dim_type type, unsigned pos) | |||
639 | { | |||
640 | isl_id *id = get_id(dim, type, pos); | |||
641 | return id ? id->name : NULL((void*)0); | |||
642 | } | |||
643 | ||||
644 | int isl_space_find_dim_by_id(__isl_keep isl_space *dim, enum isl_dim_type type, | |||
645 | __isl_keep isl_id *id) | |||
646 | { | |||
647 | int i; | |||
648 | int offset; | |||
649 | int n; | |||
650 | ||||
651 | if (!dim || !id) | |||
652 | return -1; | |||
653 | ||||
654 | offset = isl_space_offset(dim, type); | |||
655 | n = isl_space_dim(dim, type); | |||
656 | for (i = 0; i < n && offset + i < dim->n_id; ++i) | |||
657 | if (dim->ids[offset + i] == id) | |||
658 | return i; | |||
659 | ||||
660 | return -1; | |||
661 | } | |||
662 | ||||
663 | int isl_space_find_dim_by_name(__isl_keep isl_space *space, | |||
664 | enum isl_dim_type type, const char *name) | |||
665 | { | |||
666 | int i; | |||
667 | int offset; | |||
668 | int n; | |||
669 | ||||
670 | if (!space || !name) | |||
671 | return -1; | |||
672 | ||||
673 | offset = isl_space_offset(space, type); | |||
674 | n = isl_space_dim(space, type); | |||
675 | for (i = 0; i < n && offset + i < space->n_id; ++i) { | |||
676 | isl_id *id = get_id(space, type, i); | |||
677 | if (id && id->name && !strcmp(id->name, name)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (id->name) && __builtin_constant_p (name) && (__s1_len = __builtin_strlen (id->name), __s2_len = __builtin_strlen (name), (!((size_t)(const void *)((id->name) + 1) - (size_t )(const void *)(id->name) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((name) + 1) - (size_t)(const void * )(name) == 1) || __s2_len >= 4)) ? __builtin_strcmp (id-> name, name) : (__builtin_constant_p (id->name) && ( (size_t)(const void *)((id->name) + 1) - (size_t)(const void *)(id->name) == 1) && (__s1_len = __builtin_strlen (id->name), __s1_len < 4) ? (__builtin_constant_p (name ) && ((size_t)(const void *)((name) + 1) - (size_t)(const void *)(name) == 1) ? __builtin_strcmp (id->name, name) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (name); int __result = (((const unsigned char *) (const char *) (id->name))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (id->name))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (id->name))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (id->name))[3] - __s2[3]); } } __result ; }))) : (__builtin_constant_p (name) && ((size_t)(const void *)((name) + 1) - (size_t)(const void *)(name) == 1) && (__s2_len = __builtin_strlen (name), __s2_len < 4) ? (__builtin_constant_p (id->name) && ((size_t)(const void *)((id->name ) + 1) - (size_t)(const void *)(id->name) == 1) ? __builtin_strcmp (id->name, name) : -(__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (id->name) ; int __result = (((const unsigned char *) (const char *) (name ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (name ))[1] - __s2[1]); if (__s2_len > 1 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (name ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (name)) [3] - __s2[3]); } } __result; }))) : __builtin_strcmp (id-> name, name)))); })) | |||
678 | return i; | |||
679 | } | |||
680 | ||||
681 | return -1; | |||
682 | } | |||
683 | ||||
684 | /* Reset the user pointer on all identifiers of parameters and tuples | |||
685 | * of "space". | |||
686 | */ | |||
687 | __isl_give isl_space *isl_space_reset_user(__isl_take isl_space *space) | |||
688 | { | |||
689 | int i; | |||
690 | isl_ctx *ctx; | |||
691 | isl_id *id; | |||
692 | const char *name; | |||
693 | ||||
694 | if (!space) | |||
695 | return NULL((void*)0); | |||
696 | ||||
697 | ctx = isl_space_get_ctx(space); | |||
698 | ||||
699 | for (i = 0; i < space->nparam && i < space->n_id; ++i) { | |||
700 | if (!isl_id_get_user(space->ids[i])) | |||
701 | continue; | |||
702 | space = isl_space_cow(space); | |||
703 | if (!space) | |||
704 | return NULL((void*)0); | |||
705 | name = isl_id_get_name(space->ids[i]); | |||
706 | id = isl_id_alloc(ctx, name, NULL((void*)0)); | |||
707 | isl_id_free(space->ids[i]); | |||
708 | space->ids[i] = id; | |||
709 | if (!id) | |||
710 | return isl_space_free(space); | |||
711 | } | |||
712 | ||||
713 | for (i = 0; i < 2; ++i) { | |||
714 | if (!space->tuple_id[i]) | |||
715 | continue; | |||
716 | if (!isl_id_get_user(space->tuple_id[i])) | |||
717 | continue; | |||
718 | space = isl_space_cow(space); | |||
719 | if (!space) | |||
720 | return NULL((void*)0); | |||
721 | name = isl_id_get_name(space->tuple_id[i]); | |||
722 | id = isl_id_alloc(ctx, name, NULL((void*)0)); | |||
723 | isl_id_free(space->tuple_id[i]); | |||
724 | space->tuple_id[i] = id; | |||
725 | if (!id) | |||
726 | return isl_space_free(space); | |||
727 | } | |||
728 | ||||
729 | for (i = 0; i < 2; ++i) { | |||
730 | if (!space->nested[i]) | |||
731 | continue; | |||
732 | space = isl_space_cow(space); | |||
733 | if (!space) | |||
734 | return NULL((void*)0); | |||
735 | space->nested[i] = isl_space_reset_user(space->nested[i]); | |||
736 | if (!space->nested[i]) | |||
737 | return isl_space_free(space); | |||
738 | } | |||
739 | ||||
740 | return space; | |||
741 | } | |||
742 | ||||
743 | static __isl_keep isl_id *tuple_id(__isl_keep isl_space *dim, | |||
744 | enum isl_dim_type type) | |||
745 | { | |||
746 | if (!dim) | |||
747 | return NULL((void*)0); | |||
748 | if (type == isl_dim_in) | |||
749 | return dim->tuple_id[0]; | |||
750 | if (type == isl_dim_out) | |||
751 | return dim->tuple_id[1]; | |||
752 | return NULL((void*)0); | |||
753 | } | |||
754 | ||||
755 | static __isl_keep isl_space *nested(__isl_keep isl_space *dim, | |||
756 | enum isl_dim_type type) | |||
757 | { | |||
758 | if (!dim) | |||
759 | return NULL((void*)0); | |||
760 | if (type == isl_dim_in) | |||
761 | return dim->nested[0]; | |||
762 | if (type == isl_dim_out) | |||
763 | return dim->nested[1]; | |||
764 | return NULL((void*)0); | |||
765 | } | |||
766 | ||||
767 | /* Are the two spaces the same, apart from positions and names of parameters? | |||
768 | */ | |||
769 | isl_bool isl_space_has_equal_tuples(__isl_keep isl_space *space1, | |||
770 | __isl_keep isl_space *space2) | |||
771 | { | |||
772 | if (!space1 || !space2) | |||
773 | return isl_bool_error; | |||
774 | if (space1 == space2) | |||
775 | return isl_bool_true; | |||
776 | return isl_space_tuple_is_equal(space1, isl_dim_in, | |||
777 | space2, isl_dim_in) && | |||
778 | isl_space_tuple_is_equal(space1, isl_dim_out, | |||
779 | space2, isl_dim_out); | |||
780 | } | |||
781 | ||||
782 | /* Check if the tuple of type "type1" of "space1" is the same as | |||
783 | * the tuple of type "type2" of "space2". | |||
784 | * | |||
785 | * That is, check if the tuples have the same identifier, the same dimension | |||
786 | * and the same internal structure. | |||
787 | * The identifiers of the dimensions inside the tuples do not affect the result. | |||
788 | * | |||
789 | * Note that this function only checks the tuples themselves. | |||
790 | * If nested tuples are involved, then we need to be careful not | |||
791 | * to have result affected by possibly differing parameters | |||
792 | * in those nested tuples. | |||
793 | */ | |||
794 | isl_bool isl_space_tuple_is_equal(__isl_keep isl_space *space1, | |||
795 | enum isl_dim_type type1, __isl_keep isl_space *space2, | |||
796 | enum isl_dim_type type2) | |||
797 | { | |||
798 | isl_id *id1, *id2; | |||
799 | isl_space *nested1, *nested2; | |||
800 | ||||
801 | if (!space1 || !space2) | |||
802 | return isl_bool_error; | |||
803 | ||||
804 | if (space1 == space2 && type1 == type2) | |||
805 | return isl_bool_true; | |||
806 | ||||
807 | if (n(space1, type1) != n(space2, type2)) | |||
808 | return isl_bool_false; | |||
809 | id1 = tuple_id(space1, type1); | |||
810 | id2 = tuple_id(space2, type2); | |||
811 | if (!id1 ^ !id2) | |||
812 | return isl_bool_false; | |||
813 | if (id1 && id1 != id2) | |||
814 | return isl_bool_false; | |||
815 | nested1 = nested(space1, type1); | |||
816 | nested2 = nested(space2, type2); | |||
817 | if (!nested1 ^ !nested2) | |||
818 | return isl_bool_false; | |||
819 | if (nested1 && !isl_space_has_equal_tuples(nested1, nested2)) | |||
820 | return isl_bool_false; | |||
821 | return isl_bool_true; | |||
822 | } | |||
823 | ||||
824 | /* This is the old, undocumented, name for isl_space_tuple_is_equal. | |||
825 | * It will be removed at some point. | |||
826 | */ | |||
827 | int isl_space_tuple_match(__isl_keep isl_space *space1, enum isl_dim_type type1, | |||
828 | __isl_keep isl_space *space2, enum isl_dim_type type2) | |||
829 | { | |||
830 | return isl_space_tuple_is_equal(space1, type1, space2, type2); | |||
831 | } | |||
832 | ||||
833 | static isl_bool match(__isl_keep isl_space *space1, enum isl_dim_type type1, | |||
834 | __isl_keep isl_space *space2, enum isl_dim_type type2) | |||
835 | { | |||
836 | int i; | |||
837 | ||||
838 | if (space1 == space2 && type1 == type2) | |||
839 | return isl_bool_true; | |||
840 | ||||
841 | if (!isl_space_tuple_is_equal(space1, type1, space2, type2)) | |||
842 | return isl_bool_false; | |||
843 | ||||
844 | if (!space1->ids && !space2->ids) | |||
845 | return isl_bool_true; | |||
846 | ||||
847 | for (i = 0; i < n(space1, type1); ++i) { | |||
848 | if (get_id(space1, type1, i) != get_id(space2, type2, i)) | |||
849 | return isl_bool_false; | |||
850 | } | |||
851 | return isl_bool_true; | |||
852 | } | |||
853 | ||||
854 | /* Do "space1" and "space2" have the same parameters? | |||
855 | */ | |||
856 | isl_bool isl_space_has_equal_params(__isl_keep isl_space *space1, | |||
857 | __isl_keep isl_space *space2) | |||
858 | { | |||
859 | if (!space1 || !space2) | |||
860 | return isl_bool_error; | |||
861 | ||||
862 | return match(space1, isl_dim_param, space2, isl_dim_param); | |||
863 | } | |||
864 | ||||
865 | /* Do "space1" and "space2" have the same identifiers for all | |||
866 | * the tuple variables? | |||
867 | */ | |||
868 | isl_bool isl_space_has_equal_ids(__isl_keep isl_space *space1, | |||
869 | __isl_keep isl_space *space2) | |||
870 | { | |||
871 | isl_bool equal; | |||
872 | ||||
873 | if (!space1 || !space2) | |||
874 | return isl_bool_error; | |||
875 | ||||
876 | equal = match(space1, isl_dim_in, space2, isl_dim_in); | |||
877 | if (equal < 0 || !equal) | |||
878 | return equal; | |||
879 | return match(space1, isl_dim_out, space2, isl_dim_out); | |||
880 | } | |||
881 | ||||
882 | isl_bool isl_space_match(__isl_keep isl_space *space1, enum isl_dim_type type1, | |||
883 | __isl_keep isl_space *space2, enum isl_dim_type type2) | |||
884 | { | |||
885 | if (!space1 || !space2) | |||
886 | return isl_bool_error; | |||
887 | ||||
888 | return match(space1, type1, space2, type2); | |||
889 | } | |||
890 | ||||
891 | static void get_ids(__isl_keep isl_space *dim, enum isl_dim_type type, | |||
892 | unsigned first, unsigned n, __isl_keep isl_id **ids) | |||
893 | { | |||
894 | int i; | |||
895 | ||||
896 | for (i = 0; i < n ; ++i) | |||
897 | ids[i] = get_id(dim, type, first + i); | |||
898 | } | |||
899 | ||||
900 | static __isl_give isl_space *space_extend(__isl_take isl_space *space, | |||
901 | unsigned nparam, unsigned n_in, unsigned n_out) | |||
902 | { | |||
903 | isl_id **ids = NULL((void*)0); | |||
904 | ||||
905 | if (!space) | |||
906 | return NULL((void*)0); | |||
907 | if (space->nparam == nparam && | |||
908 | space->n_in == n_in && space->n_out == n_out) | |||
909 | return space; | |||
910 | ||||
911 | isl_assert(space->ctx, space->nparam <= nparam, goto error)do { if (space->nparam <= nparam) break; do { isl_handle_error (space->ctx, isl_error_unknown, "Assertion \"" "space->nparam <= nparam" "\" failed", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 911); goto error; } while (0); } while (0); | |||
912 | isl_assert(space->ctx, space->n_in <= n_in, goto error)do { if (space->n_in <= n_in) break; do { isl_handle_error (space->ctx, isl_error_unknown, "Assertion \"" "space->n_in <= n_in" "\" failed", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 912); goto error; } while (0); } while (0); | |||
913 | isl_assert(space->ctx, space->n_out <= n_out, goto error)do { if (space->n_out <= n_out) break; do { isl_handle_error (space->ctx, isl_error_unknown, "Assertion \"" "space->n_out <= n_out" "\" failed", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 913); goto error; } while (0); } while (0); | |||
914 | ||||
915 | space = isl_space_cow(space); | |||
916 | if (!space) | |||
917 | goto error; | |||
918 | ||||
919 | if (space->ids) { | |||
920 | unsigned n; | |||
921 | n = nparam + n_in + n_out; | |||
922 | if (n < nparam || n < n_in || n < n_out) | |||
923 | isl_die(isl_space_get_ctx(space), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "overflow in total number of dimensions", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 925); goto error; } while (0) | |||
924 | "overflow in total number of dimensions",do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "overflow in total number of dimensions", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 925); goto error; } while (0) | |||
925 | goto error)do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "overflow in total number of dimensions", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 925); goto error; } while (0); | |||
926 | ids = isl_calloc_array(space->ctx, isl_id *, n)((isl_id * *)isl_calloc_or_die(space->ctx, n, sizeof(isl_id *))); | |||
927 | if (!ids) | |||
928 | goto error; | |||
929 | get_ids(space, isl_dim_param, 0, space->nparam, ids); | |||
930 | get_ids(space, isl_dim_in, 0, space->n_in, ids + nparam); | |||
931 | get_ids(space, isl_dim_out, 0, space->n_out, | |||
932 | ids + nparam + n_in); | |||
933 | free(space->ids); | |||
934 | space->ids = ids; | |||
935 | space->n_id = nparam + n_in + n_out; | |||
936 | } | |||
937 | space->nparam = nparam; | |||
938 | space->n_in = n_in; | |||
939 | space->n_out = n_out; | |||
940 | ||||
941 | return space; | |||
942 | error: | |||
943 | free(ids); | |||
944 | isl_space_free(space); | |||
945 | return NULL((void*)0); | |||
946 | } | |||
947 | ||||
948 | __isl_give isl_space *isl_space_extend(__isl_take isl_space *space, | |||
949 | unsigned nparam, unsigned n_in, unsigned n_out) | |||
950 | { | |||
951 | return space_extend(space, nparam, n_in, n_out); | |||
952 | } | |||
953 | ||||
954 | __isl_give isl_space *isl_space_add_dims(__isl_take isl_space *space, | |||
955 | enum isl_dim_type type, unsigned n) | |||
956 | { | |||
957 | space = isl_space_reset(space, type); | |||
958 | if (!space) | |||
959 | return NULL((void*)0); | |||
960 | switch (type) { | |||
961 | case isl_dim_param: | |||
962 | space = space_extend(space, | |||
963 | space->nparam + n, space->n_in, space->n_out); | |||
964 | if (space && space->nested[0] && | |||
965 | !(space->nested[0] = isl_space_add_dims(space->nested[0], | |||
966 | isl_dim_param, n))) | |||
967 | goto error; | |||
968 | if (space && space->nested[1] && | |||
969 | !(space->nested[1] = isl_space_add_dims(space->nested[1], | |||
970 | isl_dim_param, n))) | |||
971 | goto error; | |||
972 | return space; | |||
973 | case isl_dim_in: | |||
974 | return space_extend(space, | |||
975 | space->nparam, space->n_in + n, space->n_out); | |||
976 | case isl_dim_out: | |||
977 | return space_extend(space, | |||
978 | space->nparam, space->n_in, space->n_out + n); | |||
979 | default: | |||
980 | isl_die(space->ctx, isl_error_invalid,do { isl_handle_error(space->ctx, isl_error_invalid, "cannot add dimensions of specified type" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 981); goto error; } while (0) | |||
981 | "cannot add dimensions of specified type", goto error)do { isl_handle_error(space->ctx, isl_error_invalid, "cannot add dimensions of specified type" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 981); goto error; } while (0); | |||
982 | } | |||
983 | error: | |||
984 | isl_space_free(space); | |||
985 | return NULL((void*)0); | |||
986 | } | |||
987 | ||||
988 | static int valid_dim_type(enum isl_dim_type type) | |||
989 | { | |||
990 | switch (type) { | |||
991 | case isl_dim_param: | |||
992 | case isl_dim_in: | |||
993 | case isl_dim_out: | |||
994 | return 1; | |||
995 | default: | |||
996 | return 0; | |||
997 | } | |||
998 | } | |||
999 | ||||
1000 | /* Insert "n" dimensions of type "type" at position "pos". | |||
1001 | * If we are inserting parameters, then they are also inserted in | |||
1002 | * any nested spaces. | |||
1003 | */ | |||
1004 | __isl_give isl_space *isl_space_insert_dims(__isl_take isl_space *dim, | |||
1005 | enum isl_dim_type type, unsigned pos, unsigned n) | |||
1006 | { | |||
1007 | isl_id **ids = NULL((void*)0); | |||
1008 | ||||
1009 | if (!dim) | |||
1010 | return NULL((void*)0); | |||
1011 | if (n == 0) | |||
1012 | return isl_space_reset(dim, type); | |||
1013 | ||||
1014 | if (!valid_dim_type(type)) | |||
1015 | isl_die(dim->ctx, isl_error_invalid,do { isl_handle_error(dim->ctx, isl_error_invalid, "cannot insert dimensions of specified type" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1017); goto error; } while (0) | |||
1016 | "cannot insert dimensions of specified type",do { isl_handle_error(dim->ctx, isl_error_invalid, "cannot insert dimensions of specified type" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1017); goto error; } while (0) | |||
1017 | goto error)do { isl_handle_error(dim->ctx, isl_error_invalid, "cannot insert dimensions of specified type" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1017); goto error; } while (0); | |||
1018 | ||||
1019 | isl_assert(dim->ctx, pos <= isl_space_dim(dim, type), goto error)do { if (pos <= isl_space_dim(dim, type)) break; do { isl_handle_error (dim->ctx, isl_error_unknown, "Assertion \"" "pos <= isl_space_dim(dim, type)" "\" failed", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1019); goto error; } while (0); } while (0); | |||
1020 | ||||
1021 | dim = isl_space_cow(dim); | |||
1022 | if (!dim) | |||
1023 | return NULL((void*)0); | |||
1024 | ||||
1025 | if (dim->ids) { | |||
1026 | enum isl_dim_type t, o = isl_dim_param; | |||
1027 | int off; | |||
1028 | int s[3]; | |||
1029 | ids = isl_calloc_array(dim->ctx, isl_id *,((isl_id * *)isl_calloc_or_die(dim->ctx, dim->nparam + dim ->n_in + dim->n_out + n, sizeof(isl_id *))) | |||
1030 | dim->nparam + dim->n_in + dim->n_out + n)((isl_id * *)isl_calloc_or_die(dim->ctx, dim->nparam + dim ->n_in + dim->n_out + n, sizeof(isl_id *))); | |||
1031 | if (!ids) | |||
1032 | goto error; | |||
1033 | off = 0; | |||
1034 | s[isl_dim_param - o] = dim->nparam; | |||
1035 | s[isl_dim_in - o] = dim->n_in; | |||
1036 | s[isl_dim_out - o] = dim->n_out; | |||
1037 | for (t = isl_dim_param; t <= isl_dim_out; ++t) { | |||
1038 | if (t != type) { | |||
1039 | get_ids(dim, t, 0, s[t - o], ids + off); | |||
1040 | off += s[t - o]; | |||
1041 | } else { | |||
1042 | get_ids(dim, t, 0, pos, ids + off); | |||
1043 | off += pos + n; | |||
1044 | get_ids(dim, t, pos, s[t - o] - pos, ids + off); | |||
1045 | off += s[t - o] - pos; | |||
1046 | } | |||
1047 | } | |||
1048 | free(dim->ids); | |||
1049 | dim->ids = ids; | |||
1050 | dim->n_id = dim->nparam + dim->n_in + dim->n_out + n; | |||
1051 | } | |||
1052 | switch (type) { | |||
1053 | case isl_dim_param: dim->nparam += n; break; | |||
1054 | case isl_dim_in: dim->n_in += n; break; | |||
1055 | case isl_dim_out: dim->n_out += n; break; | |||
1056 | default: ; | |||
1057 | } | |||
1058 | dim = isl_space_reset(dim, type); | |||
1059 | ||||
1060 | if (type == isl_dim_param) { | |||
1061 | if (dim && dim->nested[0] && | |||
1062 | !(dim->nested[0] = isl_space_insert_dims(dim->nested[0], | |||
1063 | isl_dim_param, pos, n))) | |||
1064 | goto error; | |||
1065 | if (dim && dim->nested[1] && | |||
1066 | !(dim->nested[1] = isl_space_insert_dims(dim->nested[1], | |||
1067 | isl_dim_param, pos, n))) | |||
1068 | goto error; | |||
1069 | } | |||
1070 | ||||
1071 | return dim; | |||
1072 | error: | |||
1073 | isl_space_free(dim); | |||
1074 | return NULL((void*)0); | |||
1075 | } | |||
1076 | ||||
1077 | __isl_give isl_space *isl_space_move_dims(__isl_take isl_space *space, | |||
1078 | enum isl_dim_type dst_type, unsigned dst_pos, | |||
1079 | enum isl_dim_type src_type, unsigned src_pos, unsigned n) | |||
1080 | { | |||
1081 | int i; | |||
1082 | ||||
1083 | space = isl_space_reset(space, src_type); | |||
1084 | space = isl_space_reset(space, dst_type); | |||
1085 | if (!space) | |||
1086 | return NULL((void*)0); | |||
1087 | if (n == 0) | |||
1088 | return space; | |||
1089 | ||||
1090 | isl_assert(space->ctx, src_pos + n <= isl_space_dim(space, src_type),do { if (src_pos + n <= isl_space_dim(space, src_type)) break ; do { isl_handle_error(space->ctx, isl_error_unknown, "Assertion \"" "src_pos + n <= isl_space_dim(space, src_type)" "\" failed" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1091); goto error; } while (0); } while (0) | |||
1091 | goto error)do { if (src_pos + n <= isl_space_dim(space, src_type)) break ; do { isl_handle_error(space->ctx, isl_error_unknown, "Assertion \"" "src_pos + n <= isl_space_dim(space, src_type)" "\" failed" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1091); goto error; } while (0); } while (0); | |||
1092 | ||||
1093 | if (dst_type == src_type && dst_pos == src_pos) | |||
1094 | return space; | |||
1095 | ||||
1096 | isl_assert(space->ctx, dst_type != src_type, goto error)do { if (dst_type != src_type) break; do { isl_handle_error(space ->ctx, isl_error_unknown, "Assertion \"" "dst_type != src_type" "\" failed", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1096); goto error; } while (0); } while (0); | |||
1097 | ||||
1098 | space = isl_space_cow(space); | |||
1099 | if (!space) | |||
1100 | return NULL((void*)0); | |||
1101 | ||||
1102 | if (space->ids) { | |||
1103 | isl_id **ids; | |||
1104 | enum isl_dim_type t, o = isl_dim_param; | |||
1105 | int off; | |||
1106 | int s[3]; | |||
1107 | ids = isl_calloc_array(space->ctx, isl_id *,((isl_id * *)isl_calloc_or_die(space->ctx, space->nparam + space->n_in + space->n_out, sizeof(isl_id *))) | |||
1108 | space->nparam + space->n_in + space->n_out)((isl_id * *)isl_calloc_or_die(space->ctx, space->nparam + space->n_in + space->n_out, sizeof(isl_id *))); | |||
1109 | if (!ids) | |||
1110 | goto error; | |||
1111 | off = 0; | |||
1112 | s[isl_dim_param - o] = space->nparam; | |||
1113 | s[isl_dim_in - o] = space->n_in; | |||
1114 | s[isl_dim_out - o] = space->n_out; | |||
1115 | for (t = isl_dim_param; t <= isl_dim_out; ++t) { | |||
1116 | if (t == dst_type) { | |||
1117 | get_ids(space, t, 0, dst_pos, ids + off); | |||
1118 | off += dst_pos; | |||
1119 | get_ids(space, src_type, src_pos, n, ids + off); | |||
1120 | off += n; | |||
1121 | get_ids(space, t, dst_pos, s[t - o] - dst_pos, | |||
1122 | ids + off); | |||
1123 | off += s[t - o] - dst_pos; | |||
1124 | } else if (t == src_type) { | |||
1125 | get_ids(space, t, 0, src_pos, ids + off); | |||
1126 | off += src_pos; | |||
1127 | get_ids(space, t, src_pos + n, | |||
1128 | s[t - o] - src_pos - n, ids + off); | |||
1129 | off += s[t - o] - src_pos - n; | |||
1130 | } else { | |||
1131 | get_ids(space, t, 0, s[t - o], ids + off); | |||
1132 | off += s[t - o]; | |||
1133 | } | |||
1134 | } | |||
1135 | free(space->ids); | |||
1136 | space->ids = ids; | |||
1137 | space->n_id = space->nparam + space->n_in + space->n_out; | |||
1138 | } | |||
1139 | ||||
1140 | switch (dst_type) { | |||
1141 | case isl_dim_param: space->nparam += n; break; | |||
1142 | case isl_dim_in: space->n_in += n; break; | |||
1143 | case isl_dim_out: space->n_out += n; break; | |||
1144 | default: ; | |||
1145 | } | |||
1146 | ||||
1147 | switch (src_type) { | |||
1148 | case isl_dim_param: space->nparam -= n; break; | |||
1149 | case isl_dim_in: space->n_in -= n; break; | |||
1150 | case isl_dim_out: space->n_out -= n; break; | |||
1151 | default: ; | |||
1152 | } | |||
1153 | ||||
1154 | if (dst_type != isl_dim_param && src_type != isl_dim_param) | |||
1155 | return space; | |||
1156 | ||||
1157 | for (i = 0; i < 2; ++i) { | |||
1158 | if (!space->nested[i]) | |||
1159 | continue; | |||
1160 | space->nested[i] = isl_space_replace(space->nested[i], | |||
1161 | isl_dim_param, space); | |||
1162 | if (!space->nested[i]) | |||
1163 | goto error; | |||
1164 | } | |||
1165 | ||||
1166 | return space; | |||
1167 | error: | |||
1168 | isl_space_free(space); | |||
1169 | return NULL((void*)0); | |||
1170 | } | |||
1171 | ||||
1172 | /* Check that "space1" and "space2" have the same parameters, | |||
1173 | * reporting an error if they do not. | |||
1174 | */ | |||
1175 | isl_stat isl_space_check_equal_params(__isl_keep isl_space *space1, | |||
1176 | __isl_keep isl_space *space2) | |||
1177 | { | |||
1178 | isl_bool equal; | |||
1179 | ||||
1180 | equal = isl_space_has_equal_params(space1, space2); | |||
1181 | if (equal < 0) | |||
1182 | return isl_stat_error; | |||
1183 | if (!equal) | |||
1184 | isl_die(isl_space_get_ctx(space1), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(space1), isl_error_invalid , "parameters need to match", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1185); return isl_stat_error; } while (0) | |||
1185 | "parameters need to match", return isl_stat_error)do { isl_handle_error(isl_space_get_ctx(space1), isl_error_invalid , "parameters need to match", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1185); return isl_stat_error; } while (0); | |||
1186 | return isl_stat_ok; | |||
1187 | } | |||
1188 | ||||
1189 | __isl_give isl_space *isl_space_join(__isl_take isl_space *left, | |||
1190 | __isl_take isl_space *right) | |||
1191 | { | |||
1192 | isl_space *dim; | |||
1193 | ||||
1194 | if (isl_space_check_equal_params(left, right) < 0) | |||
1195 | goto error; | |||
1196 | ||||
1197 | isl_assert(left->ctx,do { if (isl_space_tuple_is_equal(left, isl_dim_out, right, isl_dim_in )) break; do { isl_handle_error(left->ctx, isl_error_unknown , "Assertion \"" "isl_space_tuple_is_equal(left, isl_dim_out, right, isl_dim_in)" "\" failed", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1199); goto error; } while (0); } while (0) | |||
1198 | isl_space_tuple_is_equal(left, isl_dim_out, right, isl_dim_in),do { if (isl_space_tuple_is_equal(left, isl_dim_out, right, isl_dim_in )) break; do { isl_handle_error(left->ctx, isl_error_unknown , "Assertion \"" "isl_space_tuple_is_equal(left, isl_dim_out, right, isl_dim_in)" "\" failed", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1199); goto error; } while (0); } while (0) | |||
1199 | goto error)do { if (isl_space_tuple_is_equal(left, isl_dim_out, right, isl_dim_in )) break; do { isl_handle_error(left->ctx, isl_error_unknown , "Assertion \"" "isl_space_tuple_is_equal(left, isl_dim_out, right, isl_dim_in)" "\" failed", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1199); goto error; } while (0); } while (0); | |||
1200 | ||||
1201 | dim = isl_space_alloc(left->ctx, left->nparam, left->n_in, right->n_out); | |||
1202 | if (!dim) | |||
1203 | goto error; | |||
1204 | ||||
1205 | dim = copy_ids(dim, isl_dim_param, 0, left, isl_dim_param); | |||
1206 | dim = copy_ids(dim, isl_dim_in, 0, left, isl_dim_in); | |||
1207 | dim = copy_ids(dim, isl_dim_out, 0, right, isl_dim_out); | |||
1208 | ||||
1209 | if (dim && left->tuple_id[0] && | |||
1210 | !(dim->tuple_id[0] = isl_id_copy(left->tuple_id[0]))) | |||
1211 | goto error; | |||
1212 | if (dim && right->tuple_id[1] && | |||
1213 | !(dim->tuple_id[1] = isl_id_copy(right->tuple_id[1]))) | |||
1214 | goto error; | |||
1215 | if (dim && left->nested[0] && | |||
1216 | !(dim->nested[0] = isl_space_copy(left->nested[0]))) | |||
1217 | goto error; | |||
1218 | if (dim && right->nested[1] && | |||
1219 | !(dim->nested[1] = isl_space_copy(right->nested[1]))) | |||
1220 | goto error; | |||
1221 | ||||
1222 | isl_space_free(left); | |||
1223 | isl_space_free(right); | |||
1224 | ||||
1225 | return dim; | |||
1226 | error: | |||
1227 | isl_space_free(left); | |||
1228 | isl_space_free(right); | |||
1229 | return NULL((void*)0); | |||
1230 | } | |||
1231 | ||||
1232 | /* Given two map spaces { A -> C } and { B -> D }, construct the space | |||
1233 | * { [A -> B] -> [C -> D] }. | |||
1234 | * Given two set spaces { A } and { B }, construct the space { [A -> B] }. | |||
1235 | */ | |||
1236 | __isl_give isl_space *isl_space_product(__isl_take isl_space *left, | |||
1237 | __isl_take isl_space *right) | |||
1238 | { | |||
1239 | isl_space *dom1, *dom2, *nest1, *nest2; | |||
1240 | int is_set; | |||
1241 | ||||
1242 | if (!left || !right) | |||
1243 | goto error; | |||
1244 | ||||
1245 | is_set = isl_space_is_set(left); | |||
1246 | if (is_set != isl_space_is_set(right)) | |||
1247 | isl_die(isl_space_get_ctx(left), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(left), isl_error_invalid , "expecting either two set spaces or two map spaces", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1249); goto error; } while (0) | |||
1248 | "expecting either two set spaces or two map spaces",do { isl_handle_error(isl_space_get_ctx(left), isl_error_invalid , "expecting either two set spaces or two map spaces", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1249); goto error; } while (0) | |||
1249 | goto error)do { isl_handle_error(isl_space_get_ctx(left), isl_error_invalid , "expecting either two set spaces or two map spaces", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1249); goto error; } while (0); | |||
1250 | if (is_set) | |||
1251 | return isl_space_range_product(left, right); | |||
1252 | ||||
1253 | if (isl_space_check_equal_params(left, right) < 0) | |||
1254 | goto error; | |||
1255 | ||||
1256 | dom1 = isl_space_domain(isl_space_copy(left)); | |||
1257 | dom2 = isl_space_domain(isl_space_copy(right)); | |||
1258 | nest1 = isl_space_wrap(isl_space_join(isl_space_reverse(dom1), dom2)); | |||
1259 | ||||
1260 | dom1 = isl_space_range(left); | |||
1261 | dom2 = isl_space_range(right); | |||
1262 | nest2 = isl_space_wrap(isl_space_join(isl_space_reverse(dom1), dom2)); | |||
1263 | ||||
1264 | return isl_space_join(isl_space_reverse(nest1), nest2); | |||
1265 | error: | |||
1266 | isl_space_free(left); | |||
1267 | isl_space_free(right); | |||
1268 | return NULL((void*)0); | |||
1269 | } | |||
1270 | ||||
1271 | /* Given two spaces { A -> C } and { B -> C }, construct the space | |||
1272 | * { [A -> B] -> C } | |||
1273 | */ | |||
1274 | __isl_give isl_space *isl_space_domain_product(__isl_take isl_space *left, | |||
1275 | __isl_take isl_space *right) | |||
1276 | { | |||
1277 | isl_space *ran, *dom1, *dom2, *nest; | |||
1278 | ||||
1279 | if (isl_space_check_equal_params(left, right) < 0) | |||
1280 | goto error; | |||
1281 | ||||
1282 | if (!isl_space_tuple_is_equal(left, isl_dim_out, right, isl_dim_out)) | |||
1283 | isl_die(left->ctx, isl_error_invalid,do { isl_handle_error(left->ctx, isl_error_invalid, "ranges need to match" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1284); goto error; } while (0) | |||
1284 | "ranges need to match", goto error)do { isl_handle_error(left->ctx, isl_error_invalid, "ranges need to match" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1284); goto error; } while (0); | |||
1285 | ||||
1286 | ran = isl_space_range(isl_space_copy(left)); | |||
1287 | ||||
1288 | dom1 = isl_space_domain(left); | |||
1289 | dom2 = isl_space_domain(right); | |||
1290 | nest = isl_space_wrap(isl_space_join(isl_space_reverse(dom1), dom2)); | |||
1291 | ||||
1292 | return isl_space_join(isl_space_reverse(nest), ran); | |||
1293 | error: | |||
1294 | isl_space_free(left); | |||
1295 | isl_space_free(right); | |||
1296 | return NULL((void*)0); | |||
1297 | } | |||
1298 | ||||
1299 | __isl_give isl_space *isl_space_range_product(__isl_take isl_space *left, | |||
1300 | __isl_take isl_space *right) | |||
1301 | { | |||
1302 | isl_space *dom, *ran1, *ran2, *nest; | |||
1303 | ||||
1304 | if (isl_space_check_equal_params(left, right) < 0) | |||
1305 | goto error; | |||
1306 | ||||
1307 | if (!isl_space_tuple_is_equal(left, isl_dim_in, right, isl_dim_in)) | |||
1308 | isl_die(left->ctx, isl_error_invalid,do { isl_handle_error(left->ctx, isl_error_invalid, "domains need to match" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1309); goto error; } while (0) | |||
1309 | "domains need to match", goto error)do { isl_handle_error(left->ctx, isl_error_invalid, "domains need to match" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1309); goto error; } while (0); | |||
1310 | ||||
1311 | dom = isl_space_domain(isl_space_copy(left)); | |||
1312 | ||||
1313 | ran1 = isl_space_range(left); | |||
1314 | ran2 = isl_space_range(right); | |||
1315 | nest = isl_space_wrap(isl_space_join(isl_space_reverse(ran1), ran2)); | |||
1316 | ||||
1317 | return isl_space_join(isl_space_reverse(dom), nest); | |||
1318 | error: | |||
1319 | isl_space_free(left); | |||
1320 | isl_space_free(right); | |||
1321 | return NULL((void*)0); | |||
1322 | } | |||
1323 | ||||
1324 | /* Given a space of the form [A -> B] -> [C -> D], return the space A -> C. | |||
1325 | */ | |||
1326 | __isl_give isl_space *isl_space_factor_domain(__isl_take isl_space *space) | |||
1327 | { | |||
1328 | space = isl_space_domain_factor_domain(space); | |||
1329 | space = isl_space_range_factor_domain(space); | |||
1330 | return space; | |||
1331 | } | |||
1332 | ||||
1333 | /* Given a space of the form [A -> B] -> C, return the space A -> C. | |||
1334 | */ | |||
1335 | __isl_give isl_space *isl_space_domain_factor_domain( | |||
1336 | __isl_take isl_space *space) | |||
1337 | { | |||
1338 | isl_space *nested; | |||
1339 | isl_space *domain; | |||
1340 | ||||
1341 | if (!space) | |||
1342 | return NULL((void*)0); | |||
1343 | if (!isl_space_domain_is_wrapping(space)) | |||
1344 | isl_die(isl_space_get_ctx(space), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "domain not a product", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1345); return isl_space_free(space); } while (0) | |||
1345 | "domain not a product", return isl_space_free(space))do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "domain not a product", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1345); return isl_space_free(space); } while (0); | |||
1346 | ||||
1347 | nested = space->nested[0]; | |||
1348 | domain = isl_space_copy(space); | |||
1349 | domain = isl_space_drop_dims(domain, isl_dim_in, | |||
1350 | nested->n_in, nested->n_out); | |||
1351 | if (!domain) | |||
1352 | return isl_space_free(space); | |||
1353 | if (nested->tuple_id[0]) { | |||
1354 | domain->tuple_id[0] = isl_id_copy(nested->tuple_id[0]); | |||
1355 | if (!domain->tuple_id[0]) | |||
1356 | goto error; | |||
1357 | } | |||
1358 | if (nested->nested[0]) { | |||
1359 | domain->nested[0] = isl_space_copy(nested->nested[0]); | |||
1360 | if (!domain->nested[0]) | |||
1361 | goto error; | |||
1362 | } | |||
1363 | ||||
1364 | isl_space_free(space); | |||
1365 | return domain; | |||
1366 | error: | |||
1367 | isl_space_free(space); | |||
1368 | isl_space_free(domain); | |||
1369 | return NULL((void*)0); | |||
1370 | } | |||
1371 | ||||
1372 | /* Given a space of the form [A -> B] -> C, return the space B -> C. | |||
1373 | */ | |||
1374 | __isl_give isl_space *isl_space_domain_factor_range( | |||
1375 | __isl_take isl_space *space) | |||
1376 | { | |||
1377 | isl_space *nested; | |||
1378 | isl_space *range; | |||
1379 | ||||
1380 | if (!space) | |||
1381 | return NULL((void*)0); | |||
1382 | if (!isl_space_domain_is_wrapping(space)) | |||
1383 | isl_die(isl_space_get_ctx(space), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "domain not a product", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1384); return isl_space_free(space); } while (0) | |||
1384 | "domain not a product", return isl_space_free(space))do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "domain not a product", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1384); return isl_space_free(space); } while (0); | |||
1385 | ||||
1386 | nested = space->nested[0]; | |||
1387 | range = isl_space_copy(space); | |||
1388 | range = isl_space_drop_dims(range, isl_dim_in, 0, nested->n_in); | |||
1389 | if (!range) | |||
1390 | return isl_space_free(space); | |||
1391 | if (nested->tuple_id[1]) { | |||
1392 | range->tuple_id[0] = isl_id_copy(nested->tuple_id[1]); | |||
1393 | if (!range->tuple_id[0]) | |||
1394 | goto error; | |||
1395 | } | |||
1396 | if (nested->nested[1]) { | |||
1397 | range->nested[0] = isl_space_copy(nested->nested[1]); | |||
1398 | if (!range->nested[0]) | |||
1399 | goto error; | |||
1400 | } | |||
1401 | ||||
1402 | isl_space_free(space); | |||
1403 | return range; | |||
1404 | error: | |||
1405 | isl_space_free(space); | |||
1406 | isl_space_free(range); | |||
1407 | return NULL((void*)0); | |||
1408 | } | |||
1409 | ||||
1410 | /* Given a space of the form A -> [B -> C], return the space A -> B. | |||
1411 | */ | |||
1412 | __isl_give isl_space *isl_space_range_factor_domain( | |||
1413 | __isl_take isl_space *space) | |||
1414 | { | |||
1415 | isl_space *nested; | |||
1416 | isl_space *domain; | |||
1417 | ||||
1418 | if (!space) | |||
1419 | return NULL((void*)0); | |||
1420 | if (!isl_space_range_is_wrapping(space)) | |||
1421 | isl_die(isl_space_get_ctx(space), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "range not a product", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1422); return isl_space_free(space); } while (0) | |||
1422 | "range not a product", return isl_space_free(space))do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "range not a product", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1422); return isl_space_free(space); } while (0); | |||
1423 | ||||
1424 | nested = space->nested[1]; | |||
1425 | domain = isl_space_copy(space); | |||
1426 | domain = isl_space_drop_dims(domain, isl_dim_out, | |||
1427 | nested->n_in, nested->n_out); | |||
1428 | if (!domain) | |||
1429 | return isl_space_free(space); | |||
1430 | if (nested->tuple_id[0]) { | |||
1431 | domain->tuple_id[1] = isl_id_copy(nested->tuple_id[0]); | |||
1432 | if (!domain->tuple_id[1]) | |||
1433 | goto error; | |||
1434 | } | |||
1435 | if (nested->nested[0]) { | |||
1436 | domain->nested[1] = isl_space_copy(nested->nested[0]); | |||
1437 | if (!domain->nested[1]) | |||
1438 | goto error; | |||
1439 | } | |||
1440 | ||||
1441 | isl_space_free(space); | |||
1442 | return domain; | |||
1443 | error: | |||
1444 | isl_space_free(space); | |||
1445 | isl_space_free(domain); | |||
1446 | return NULL((void*)0); | |||
1447 | } | |||
1448 | ||||
1449 | /* Internal function that selects the range of the map that is | |||
1450 | * embedded in either a set space or the range of a map space. | |||
1451 | * In particular, given a space of the form [A -> B], return the space B. | |||
1452 | * Given a space of the form A -> [B -> C], return the space A -> C. | |||
1453 | */ | |||
1454 | static __isl_give isl_space *range_factor_range(__isl_take isl_space *space) | |||
1455 | { | |||
1456 | isl_space *nested; | |||
1457 | isl_space *range; | |||
1458 | ||||
1459 | if (!space) | |||
1460 | return NULL((void*)0); | |||
1461 | ||||
1462 | nested = space->nested[1]; | |||
1463 | range = isl_space_copy(space); | |||
1464 | range = isl_space_drop_dims(range, isl_dim_out, 0, nested->n_in); | |||
1465 | if (!range) | |||
1466 | return isl_space_free(space); | |||
1467 | if (nested->tuple_id[1]) { | |||
1468 | range->tuple_id[1] = isl_id_copy(nested->tuple_id[1]); | |||
1469 | if (!range->tuple_id[1]) | |||
1470 | goto error; | |||
1471 | } | |||
1472 | if (nested->nested[1]) { | |||
1473 | range->nested[1] = isl_space_copy(nested->nested[1]); | |||
1474 | if (!range->nested[1]) | |||
1475 | goto error; | |||
1476 | } | |||
1477 | ||||
1478 | isl_space_free(space); | |||
1479 | return range; | |||
1480 | error: | |||
1481 | isl_space_free(space); | |||
1482 | isl_space_free(range); | |||
1483 | return NULL((void*)0); | |||
1484 | } | |||
1485 | ||||
1486 | /* Given a space of the form A -> [B -> C], return the space A -> C. | |||
1487 | */ | |||
1488 | __isl_give isl_space *isl_space_range_factor_range( | |||
1489 | __isl_take isl_space *space) | |||
1490 | { | |||
1491 | if (!space) | |||
1492 | return NULL((void*)0); | |||
1493 | if (!isl_space_range_is_wrapping(space)) | |||
1494 | isl_die(isl_space_get_ctx(space), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "range not a product", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1495); return isl_space_free(space); } while (0) | |||
1495 | "range not a product", return isl_space_free(space))do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "range not a product", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1495); return isl_space_free(space); } while (0); | |||
1496 | ||||
1497 | return range_factor_range(space); | |||
1498 | } | |||
1499 | ||||
1500 | /* Given a space of the form [A -> B], return the space B. | |||
1501 | */ | |||
1502 | static __isl_give isl_space *set_factor_range(__isl_take isl_space *space) | |||
1503 | { | |||
1504 | if (!space) | |||
1505 | return NULL((void*)0); | |||
1506 | if (!isl_space_is_wrapping(space)) | |||
1507 | isl_die(isl_space_get_ctx(space), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "not a product", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1508); return isl_space_free(space); } while (0) | |||
1508 | "not a product", return isl_space_free(space))do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "not a product", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1508); return isl_space_free(space); } while (0); | |||
1509 | ||||
1510 | return range_factor_range(space); | |||
1511 | } | |||
1512 | ||||
1513 | /* Given a space of the form [A -> B] -> [C -> D], return the space B -> D. | |||
1514 | * Given a space of the form [A -> B], return the space B. | |||
1515 | */ | |||
1516 | __isl_give isl_space *isl_space_factor_range(__isl_take isl_space *space) | |||
1517 | { | |||
1518 | if (!space) | |||
1519 | return NULL((void*)0); | |||
1520 | if (isl_space_is_set(space)) | |||
1521 | return set_factor_range(space); | |||
1522 | space = isl_space_domain_factor_range(space); | |||
1523 | space = isl_space_range_factor_range(space); | |||
1524 | return space; | |||
1525 | } | |||
1526 | ||||
1527 | __isl_give isl_space *isl_space_map_from_set(__isl_take isl_space *space) | |||
1528 | { | |||
1529 | isl_ctx *ctx; | |||
1530 | isl_id **ids = NULL((void*)0); | |||
1531 | int n_id; | |||
1532 | ||||
1533 | if (!space) | |||
1534 | return NULL((void*)0); | |||
1535 | ctx = isl_space_get_ctx(space); | |||
1536 | if (!isl_space_is_set(space)) | |||
1537 | isl_die(ctx, isl_error_invalid, "not a set space", goto error)do { isl_handle_error(ctx, isl_error_invalid, "not a set space" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1537); goto error; } while (0); | |||
1538 | space = isl_space_cow(space); | |||
1539 | if (!space) | |||
1540 | return NULL((void*)0); | |||
1541 | n_id = space->nparam + space->n_out + space->n_out; | |||
1542 | if (n_id > 0 && space->ids) { | |||
1543 | ids = isl_calloc_array(space->ctx, isl_id *, n_id)((isl_id * *)isl_calloc_or_die(space->ctx, n_id, sizeof(isl_id *))); | |||
1544 | if (!ids) | |||
1545 | goto error; | |||
1546 | get_ids(space, isl_dim_param, 0, space->nparam, ids); | |||
1547 | get_ids(space, isl_dim_out, 0, space->n_out, | |||
1548 | ids + space->nparam); | |||
1549 | } | |||
1550 | space->n_in = space->n_out; | |||
1551 | if (ids) { | |||
1552 | free(space->ids); | |||
1553 | space->ids = ids; | |||
1554 | space->n_id = n_id; | |||
1555 | space = copy_ids(space, isl_dim_out, 0, space, isl_dim_in); | |||
1556 | } | |||
1557 | isl_id_free(space->tuple_id[0]); | |||
1558 | space->tuple_id[0] = isl_id_copy(space->tuple_id[1]); | |||
1559 | isl_space_free(space->nested[0]); | |||
1560 | space->nested[0] = isl_space_copy(space->nested[1]); | |||
1561 | return space; | |||
1562 | error: | |||
1563 | isl_space_free(space); | |||
1564 | return NULL((void*)0); | |||
1565 | } | |||
1566 | ||||
1567 | __isl_give isl_space *isl_space_map_from_domain_and_range( | |||
1568 | __isl_take isl_space *domain, __isl_take isl_space *range) | |||
1569 | { | |||
1570 | if (!domain || !range) | |||
1571 | goto error; | |||
1572 | if (!isl_space_is_set(domain)) | |||
1573 | isl_die(isl_space_get_ctx(domain), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(domain), isl_error_invalid , "domain is not a set space", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1574); goto error; } while (0) | |||
1574 | "domain is not a set space", goto error)do { isl_handle_error(isl_space_get_ctx(domain), isl_error_invalid , "domain is not a set space", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1574); goto error; } while (0); | |||
1575 | if (!isl_space_is_set(range)) | |||
1576 | isl_die(isl_space_get_ctx(range), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(range), isl_error_invalid , "range is not a set space", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1577); goto error; } while (0) | |||
1577 | "range is not a set space", goto error)do { isl_handle_error(isl_space_get_ctx(range), isl_error_invalid , "range is not a set space", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1577); goto error; } while (0); | |||
1578 | return isl_space_join(isl_space_reverse(domain), range); | |||
1579 | error: | |||
1580 | isl_space_free(domain); | |||
1581 | isl_space_free(range); | |||
1582 | return NULL((void*)0); | |||
1583 | } | |||
1584 | ||||
1585 | static __isl_give isl_space *set_ids(__isl_take isl_space *dim, | |||
1586 | enum isl_dim_type type, | |||
1587 | unsigned first, unsigned n, __isl_take isl_id **ids) | |||
1588 | { | |||
1589 | int i; | |||
1590 | ||||
1591 | for (i = 0; i < n ; ++i) | |||
1592 | dim = set_id(dim, type, first + i, ids[i]); | |||
1593 | ||||
1594 | return dim; | |||
1595 | } | |||
1596 | ||||
1597 | __isl_give isl_space *isl_space_reverse(__isl_take isl_space *dim) | |||
1598 | { | |||
1599 | unsigned t; | |||
1600 | isl_space *nested; | |||
1601 | isl_id **ids = NULL((void*)0); | |||
1602 | isl_id *id; | |||
1603 | ||||
1604 | if (!dim) | |||
1605 | return NULL((void*)0); | |||
1606 | if (match(dim, isl_dim_in, dim, isl_dim_out)) | |||
1607 | return dim; | |||
1608 | ||||
1609 | dim = isl_space_cow(dim); | |||
1610 | if (!dim) | |||
1611 | return NULL((void*)0); | |||
1612 | ||||
1613 | id = dim->tuple_id[0]; | |||
1614 | dim->tuple_id[0] = dim->tuple_id[1]; | |||
1615 | dim->tuple_id[1] = id; | |||
1616 | ||||
1617 | nested = dim->nested[0]; | |||
1618 | dim->nested[0] = dim->nested[1]; | |||
1619 | dim->nested[1] = nested; | |||
1620 | ||||
1621 | if (dim->ids) { | |||
1622 | int n_id = dim->n_in + dim->n_out; | |||
1623 | ids = isl_alloc_array(dim->ctx, isl_id *, n_id)((isl_id * *)isl_malloc_or_die(dim->ctx, (n_id)*sizeof(isl_id *))); | |||
1624 | if (n_id && !ids) | |||
1625 | goto error; | |||
1626 | get_ids(dim, isl_dim_in, 0, dim->n_in, ids); | |||
1627 | get_ids(dim, isl_dim_out, 0, dim->n_out, ids + dim->n_in); | |||
1628 | } | |||
1629 | ||||
1630 | t = dim->n_in; | |||
1631 | dim->n_in = dim->n_out; | |||
1632 | dim->n_out = t; | |||
1633 | ||||
1634 | if (dim->ids) { | |||
1635 | dim = set_ids(dim, isl_dim_out, 0, dim->n_out, ids); | |||
1636 | dim = set_ids(dim, isl_dim_in, 0, dim->n_in, ids + dim->n_out); | |||
1637 | free(ids); | |||
1638 | } | |||
1639 | ||||
1640 | return dim; | |||
1641 | error: | |||
1642 | free(ids); | |||
1643 | isl_space_free(dim); | |||
1644 | return NULL((void*)0); | |||
1645 | } | |||
1646 | ||||
1647 | __isl_give isl_space *isl_space_drop_dims(__isl_take isl_space *dim, | |||
1648 | enum isl_dim_type type, unsigned first, unsigned num) | |||
1649 | { | |||
1650 | int i; | |||
1651 | ||||
1652 | if (!dim) | |||
1653 | return NULL((void*)0); | |||
1654 | ||||
1655 | if (num == 0) | |||
1656 | return isl_space_reset(dim, type); | |||
1657 | ||||
1658 | if (!valid_dim_type(type)) | |||
1659 | isl_die(dim->ctx, isl_error_invalid,do { isl_handle_error(dim->ctx, isl_error_invalid, "cannot drop dimensions of specified type" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1660); goto error; } while (0) | |||
1660 | "cannot drop dimensions of specified type", goto error)do { isl_handle_error(dim->ctx, isl_error_invalid, "cannot drop dimensions of specified type" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1660); goto error; } while (0); | |||
1661 | ||||
1662 | if (first + num > n(dim, type) || first + num < first) | |||
1663 | isl_die(isl_space_get_ctx(dim), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(dim), isl_error_invalid , "index out of bounds", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1664); return isl_space_free(dim); } while (0) | |||
1664 | "index out of bounds", return isl_space_free(dim))do { isl_handle_error(isl_space_get_ctx(dim), isl_error_invalid , "index out of bounds", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1664); return isl_space_free(dim); } while (0); | |||
1665 | dim = isl_space_cow(dim); | |||
1666 | if (!dim) | |||
1667 | goto error; | |||
1668 | if (dim->ids) { | |||
1669 | dim = extend_ids(dim); | |||
1670 | if (!dim) | |||
1671 | goto error; | |||
1672 | for (i = 0; i < num; ++i) | |||
1673 | isl_id_free(get_id(dim, type, first + i)); | |||
1674 | for (i = first+num; i < n(dim, type); ++i) | |||
1675 | set_id(dim, type, i - num, get_id(dim, type, i)); | |||
1676 | switch (type) { | |||
1677 | case isl_dim_param: | |||
1678 | get_ids(dim, isl_dim_in, 0, dim->n_in, | |||
1679 | dim->ids + offset(dim, isl_dim_in) - num); | |||
1680 | case isl_dim_in: | |||
1681 | get_ids(dim, isl_dim_out, 0, dim->n_out, | |||
1682 | dim->ids + offset(dim, isl_dim_out) - num); | |||
1683 | default: | |||
1684 | ; | |||
1685 | } | |||
1686 | dim->n_id -= num; | |||
1687 | } | |||
1688 | switch (type) { | |||
1689 | case isl_dim_param: dim->nparam -= num; break; | |||
1690 | case isl_dim_in: dim->n_in -= num; break; | |||
1691 | case isl_dim_out: dim->n_out -= num; break; | |||
1692 | default: ; | |||
1693 | } | |||
1694 | dim = isl_space_reset(dim, type); | |||
1695 | if (type == isl_dim_param) { | |||
1696 | if (dim && dim->nested[0] && | |||
1697 | !(dim->nested[0] = isl_space_drop_dims(dim->nested[0], | |||
1698 | isl_dim_param, first, num))) | |||
1699 | goto error; | |||
1700 | if (dim && dim->nested[1] && | |||
1701 | !(dim->nested[1] = isl_space_drop_dims(dim->nested[1], | |||
1702 | isl_dim_param, first, num))) | |||
1703 | goto error; | |||
1704 | } | |||
1705 | return dim; | |||
1706 | error: | |||
1707 | isl_space_free(dim); | |||
1708 | return NULL((void*)0); | |||
1709 | } | |||
1710 | ||||
1711 | __isl_give isl_space *isl_space_drop_inputs(__isl_take isl_space *dim, | |||
1712 | unsigned first, unsigned n) | |||
1713 | { | |||
1714 | if (!dim) | |||
1715 | return NULL((void*)0); | |||
1716 | return isl_space_drop_dims(dim, isl_dim_in, first, n); | |||
1717 | } | |||
1718 | ||||
1719 | __isl_give isl_space *isl_space_drop_outputs(__isl_take isl_space *dim, | |||
1720 | unsigned first, unsigned n) | |||
1721 | { | |||
1722 | if (!dim) | |||
1723 | return NULL((void*)0); | |||
1724 | return isl_space_drop_dims(dim, isl_dim_out, first, n); | |||
1725 | } | |||
1726 | ||||
1727 | __isl_give isl_space *isl_space_domain(__isl_take isl_space *space) | |||
1728 | { | |||
1729 | if (!space) | |||
1730 | return NULL((void*)0); | |||
1731 | space = isl_space_drop_dims(space, isl_dim_out, 0, space->n_out); | |||
1732 | space = isl_space_reverse(space); | |||
1733 | space = mark_as_set(space); | |||
1734 | return space; | |||
1735 | } | |||
1736 | ||||
1737 | __isl_give isl_space *isl_space_from_domain(__isl_take isl_space *dim) | |||
1738 | { | |||
1739 | if (!dim) | |||
1740 | return NULL((void*)0); | |||
1741 | if (!isl_space_is_set(dim)) | |||
1742 | isl_die(isl_space_get_ctx(dim), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(dim), isl_error_invalid , "not a set space", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1743); goto error; } while (0) | |||
1743 | "not a set space", goto error)do { isl_handle_error(isl_space_get_ctx(dim), isl_error_invalid , "not a set space", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1743); goto error; } while (0); | |||
1744 | dim = isl_space_reverse(dim); | |||
1745 | dim = isl_space_reset(dim, isl_dim_out); | |||
1746 | return dim; | |||
1747 | error: | |||
1748 | isl_space_free(dim); | |||
1749 | return NULL((void*)0); | |||
1750 | } | |||
1751 | ||||
1752 | __isl_give isl_space *isl_space_range(__isl_take isl_space *space) | |||
1753 | { | |||
1754 | if (!space) | |||
1755 | return NULL((void*)0); | |||
1756 | space = isl_space_drop_dims(space, isl_dim_in, 0, space->n_in); | |||
1757 | space = mark_as_set(space); | |||
1758 | return space; | |||
1759 | } | |||
1760 | ||||
1761 | __isl_give isl_space *isl_space_from_range(__isl_take isl_space *dim) | |||
1762 | { | |||
1763 | if (!dim) | |||
1764 | return NULL((void*)0); | |||
1765 | if (!isl_space_is_set(dim)) | |||
1766 | isl_die(isl_space_get_ctx(dim), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(dim), isl_error_invalid , "not a set space", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1767); goto error; } while (0) | |||
1767 | "not a set space", goto error)do { isl_handle_error(isl_space_get_ctx(dim), isl_error_invalid , "not a set space", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1767); goto error; } while (0); | |||
1768 | return isl_space_reset(dim, isl_dim_in); | |||
1769 | error: | |||
1770 | isl_space_free(dim); | |||
1771 | return NULL((void*)0); | |||
1772 | } | |||
1773 | ||||
1774 | /* Given a map space A -> B, return the map space [A -> B] -> A. | |||
1775 | */ | |||
1776 | __isl_give isl_space *isl_space_domain_map(__isl_take isl_space *space) | |||
1777 | { | |||
1778 | isl_space *domain; | |||
1779 | ||||
1780 | domain = isl_space_from_range(isl_space_domain(isl_space_copy(space))); | |||
1781 | space = isl_space_from_domain(isl_space_wrap(space)); | |||
1782 | space = isl_space_join(space, domain); | |||
1783 | ||||
1784 | return space; | |||
1785 | } | |||
1786 | ||||
1787 | /* Given a map space A -> B, return the map space [A -> B] -> B. | |||
1788 | */ | |||
1789 | __isl_give isl_space *isl_space_range_map(__isl_take isl_space *space) | |||
1790 | { | |||
1791 | isl_space *range; | |||
1792 | ||||
1793 | range = isl_space_from_range(isl_space_range(isl_space_copy(space))); | |||
1794 | space = isl_space_from_domain(isl_space_wrap(space)); | |||
1795 | space = isl_space_join(space, range); | |||
1796 | ||||
1797 | return space; | |||
1798 | } | |||
1799 | ||||
1800 | __isl_give isl_space *isl_space_params(__isl_take isl_space *space) | |||
1801 | { | |||
1802 | if (isl_space_is_params(space)) | |||
1803 | return space; | |||
1804 | space = isl_space_drop_dims(space, | |||
1805 | isl_dim_in, 0, isl_space_dim(space, isl_dim_in)); | |||
1806 | space = isl_space_drop_dims(space, | |||
1807 | isl_dim_out, 0, isl_space_dim(space, isl_dim_out)); | |||
1808 | space = mark_as_params(space); | |||
1809 | return space; | |||
1810 | } | |||
1811 | ||||
1812 | __isl_give isl_space *isl_space_set_from_params(__isl_take isl_space *space) | |||
1813 | { | |||
1814 | if (!space) | |||
1815 | return NULL((void*)0); | |||
1816 | if (!isl_space_is_params(space)) | |||
1817 | isl_die(isl_space_get_ctx(space), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "not a parameter space", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1818); goto error; } while (0) | |||
1818 | "not a parameter space", goto error)do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "not a parameter space", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 1818); goto error; } while (0); | |||
1819 | return isl_space_reset(space, isl_dim_set); | |||
1820 | error: | |||
1821 | isl_space_free(space); | |||
1822 | return NULL((void*)0); | |||
1823 | } | |||
1824 | ||||
1825 | __isl_give isl_space *isl_space_underlying(__isl_take isl_space *dim, | |||
1826 | unsigned n_div) | |||
1827 | { | |||
1828 | int i; | |||
1829 | ||||
1830 | if (!dim) | |||
1831 | return NULL((void*)0); | |||
1832 | if (n_div == 0 && | |||
1833 | dim->nparam == 0 && dim->n_in == 0 && dim->n_id == 0) | |||
1834 | return isl_space_reset(isl_space_reset(dim, isl_dim_in), isl_dim_out); | |||
1835 | dim = isl_space_cow(dim); | |||
1836 | if (!dim) | |||
1837 | return NULL((void*)0); | |||
1838 | dim->n_out += dim->nparam + dim->n_in + n_div; | |||
1839 | dim->nparam = 0; | |||
1840 | dim->n_in = 0; | |||
1841 | ||||
1842 | for (i = 0; i < dim->n_id; ++i) | |||
1843 | isl_id_free(get_id(dim, isl_dim_out, i)); | |||
1844 | dim->n_id = 0; | |||
1845 | dim = isl_space_reset(dim, isl_dim_in); | |||
1846 | dim = isl_space_reset(dim, isl_dim_out); | |||
1847 | ||||
1848 | return dim; | |||
1849 | } | |||
1850 | ||||
1851 | /* Are the two spaces the same, including positions and names of parameters? | |||
1852 | */ | |||
1853 | isl_bool isl_space_is_equal(__isl_keep isl_space *space1, | |||
1854 | __isl_keep isl_space *space2) | |||
1855 | { | |||
1856 | isl_bool equal; | |||
1857 | ||||
1858 | if (!space1 || !space2) | |||
1859 | return isl_bool_error; | |||
1860 | if (space1 == space2) | |||
1861 | return isl_bool_true; | |||
1862 | equal = isl_space_has_equal_params(space1, space2); | |||
1863 | if (equal < 0 || !equal) | |||
1864 | return equal; | |||
1865 | return isl_space_has_equal_tuples(space1, space2); | |||
1866 | } | |||
1867 | ||||
1868 | /* Is space1 equal to the domain of space2? | |||
1869 | * | |||
1870 | * In the internal version we also allow space2 to be the space of a set, | |||
1871 | * provided space1 is a parameter space. | |||
1872 | */ | |||
1873 | isl_bool isl_space_is_domain_internal(__isl_keep isl_space *space1, | |||
1874 | __isl_keep isl_space *space2) | |||
1875 | { | |||
1876 | isl_bool equal_params; | |||
1877 | ||||
1878 | if (!space1 || !space2) | |||
1879 | return isl_bool_error; | |||
1880 | if (!isl_space_is_set(space1)) | |||
1881 | return isl_bool_false; | |||
1882 | equal_params = isl_space_has_equal_params(space1, space2); | |||
1883 | if (equal_params < 0 || !equal_params) | |||
1884 | return equal_params; | |||
1885 | return isl_space_tuple_is_equal(space1, isl_dim_set, | |||
1886 | space2, isl_dim_in); | |||
1887 | } | |||
1888 | ||||
1889 | /* Is space1 equal to the domain of space2? | |||
1890 | */ | |||
1891 | isl_bool isl_space_is_domain(__isl_keep isl_space *space1, | |||
1892 | __isl_keep isl_space *space2) | |||
1893 | { | |||
1894 | if (!space2) | |||
1895 | return isl_bool_error; | |||
1896 | if (!isl_space_is_map(space2)) | |||
1897 | return isl_bool_false; | |||
1898 | return isl_space_is_domain_internal(space1, space2); | |||
1899 | } | |||
1900 | ||||
1901 | /* Is space1 equal to the range of space2? | |||
1902 | * | |||
1903 | * In the internal version, space2 is allowed to be the space of a set, | |||
1904 | * in which case it should be equal to space1. | |||
1905 | */ | |||
1906 | isl_bool isl_space_is_range_internal(__isl_keep isl_space *space1, | |||
1907 | __isl_keep isl_space *space2) | |||
1908 | { | |||
1909 | isl_bool equal_params; | |||
1910 | ||||
1911 | if (!space1 || !space2) | |||
1912 | return isl_bool_error; | |||
1913 | if (!isl_space_is_set(space1)) | |||
1914 | return isl_bool_false; | |||
1915 | equal_params = isl_space_has_equal_params(space1, space2); | |||
1916 | if (equal_params < 0 || !equal_params) | |||
1917 | return equal_params; | |||
1918 | return isl_space_tuple_is_equal(space1, isl_dim_set, | |||
1919 | space2, isl_dim_out); | |||
1920 | } | |||
1921 | ||||
1922 | /* Is space1 equal to the range of space2? | |||
1923 | */ | |||
1924 | isl_bool isl_space_is_range(__isl_keep isl_space *space1, | |||
1925 | __isl_keep isl_space *space2) | |||
1926 | { | |||
1927 | if (!space2) | |||
1928 | return isl_bool_error; | |||
1929 | if (!isl_space_is_map(space2)) | |||
1930 | return isl_bool_false; | |||
1931 | return isl_space_is_range_internal(space1, space2); | |||
1932 | } | |||
1933 | ||||
1934 | /* Update "hash" by hashing in the parameters of "space". | |||
1935 | */ | |||
1936 | static uint32_t isl_hash_params(uint32_t hash, __isl_keep isl_space *space) | |||
1937 | { | |||
1938 | int i; | |||
1939 | isl_id *id; | |||
1940 | ||||
1941 | if (!space) | |||
1942 | return hash; | |||
1943 | ||||
1944 | isl_hash_byte(hash, space->nparam % 256)do { hash *= 16777619; hash ^= space->nparam % 256; } while (0); | |||
1945 | ||||
1946 | for (i = 0; i < space->nparam; ++i) { | |||
1947 | id = get_id(space, isl_dim_param, i); | |||
1948 | hash = isl_hash_id(hash, id); | |||
1949 | } | |||
1950 | ||||
1951 | return hash; | |||
1952 | } | |||
1953 | ||||
1954 | /* Update "hash" by hashing in the tuples of "space". | |||
1955 | * Changes in this function should be reflected in isl_hash_tuples_domain. | |||
1956 | */ | |||
1957 | static uint32_t isl_hash_tuples(uint32_t hash, __isl_keep isl_space *space) | |||
1958 | { | |||
1959 | isl_id *id; | |||
1960 | ||||
1961 | if (!space) | |||
1962 | return hash; | |||
1963 | ||||
1964 | isl_hash_byte(hash, space->n_in % 256)do { hash *= 16777619; hash ^= space->n_in % 256; } while( 0); | |||
1965 | isl_hash_byte(hash, space->n_out % 256)do { hash *= 16777619; hash ^= space->n_out % 256; } while (0); | |||
1966 | ||||
1967 | id = tuple_id(space, isl_dim_in); | |||
1968 | hash = isl_hash_id(hash, id); | |||
1969 | id = tuple_id(space, isl_dim_out); | |||
1970 | hash = isl_hash_id(hash, id); | |||
1971 | ||||
1972 | hash = isl_hash_tuples(hash, space->nested[0]); | |||
1973 | hash = isl_hash_tuples(hash, space->nested[1]); | |||
1974 | ||||
1975 | return hash; | |||
1976 | } | |||
1977 | ||||
1978 | /* Update "hash" by hashing in the domain tuple of "space". | |||
1979 | * The result of this function is equal to the result of applying | |||
1980 | * isl_hash_tuples to the domain of "space". | |||
1981 | */ | |||
1982 | static uint32_t isl_hash_tuples_domain(uint32_t hash, | |||
1983 | __isl_keep isl_space *space) | |||
1984 | { | |||
1985 | isl_id *id; | |||
1986 | ||||
1987 | if (!space) | |||
1988 | return hash; | |||
1989 | ||||
1990 | isl_hash_byte(hash, 0)do { hash *= 16777619; hash ^= 0; } while(0); | |||
1991 | isl_hash_byte(hash, space->n_in % 256)do { hash *= 16777619; hash ^= space->n_in % 256; } while( 0); | |||
1992 | ||||
1993 | hash = isl_hash_id(hash, &isl_id_none); | |||
1994 | id = tuple_id(space, isl_dim_in); | |||
1995 | hash = isl_hash_id(hash, id); | |||
1996 | ||||
1997 | hash = isl_hash_tuples(hash, space->nested[0]); | |||
1998 | ||||
1999 | return hash; | |||
2000 | } | |||
2001 | ||||
2002 | /* Return a hash value that digests the tuples of "space", | |||
2003 | * i.e., that ignores the parameters. | |||
2004 | */ | |||
2005 | uint32_t isl_space_get_tuple_hash(__isl_keep isl_space *space) | |||
2006 | { | |||
2007 | uint32_t hash; | |||
2008 | ||||
2009 | if (!space) | |||
2010 | return 0; | |||
2011 | ||||
2012 | hash = isl_hash_init()(2166136261u); | |||
2013 | hash = isl_hash_tuples(hash, space); | |||
2014 | ||||
2015 | return hash; | |||
2016 | } | |||
2017 | ||||
2018 | uint32_t isl_space_get_hash(__isl_keep isl_space *space) | |||
2019 | { | |||
2020 | uint32_t hash; | |||
2021 | ||||
2022 | if (!space) | |||
2023 | return 0; | |||
2024 | ||||
2025 | hash = isl_hash_init()(2166136261u); | |||
2026 | hash = isl_hash_params(hash, space); | |||
2027 | hash = isl_hash_tuples(hash, space); | |||
2028 | ||||
2029 | return hash; | |||
2030 | } | |||
2031 | ||||
2032 | /* Return the hash value of the domain of "space". | |||
2033 | * That is, isl_space_get_domain_hash(space) is equal to | |||
2034 | * isl_space_get_hash(isl_space_domain(space)). | |||
2035 | */ | |||
2036 | uint32_t isl_space_get_domain_hash(__isl_keep isl_space *space) | |||
2037 | { | |||
2038 | uint32_t hash; | |||
2039 | ||||
2040 | if (!space) | |||
2041 | return 0; | |||
2042 | ||||
2043 | hash = isl_hash_init()(2166136261u); | |||
2044 | hash = isl_hash_params(hash, space); | |||
2045 | hash = isl_hash_tuples_domain(hash, space); | |||
2046 | ||||
2047 | return hash; | |||
2048 | } | |||
2049 | ||||
2050 | isl_bool isl_space_is_wrapping(__isl_keep isl_space *dim) | |||
2051 | { | |||
2052 | if (!dim) | |||
2053 | return isl_bool_error; | |||
2054 | ||||
2055 | if (!isl_space_is_set(dim)) | |||
2056 | return isl_bool_false; | |||
2057 | ||||
2058 | return dim->nested[1] != NULL((void*)0); | |||
2059 | } | |||
2060 | ||||
2061 | /* Is "space" the space of a map where the domain is a wrapped map space? | |||
2062 | */ | |||
2063 | isl_bool isl_space_domain_is_wrapping(__isl_keep isl_space *space) | |||
2064 | { | |||
2065 | if (!space) | |||
2066 | return isl_bool_error; | |||
2067 | ||||
2068 | if (isl_space_is_set(space)) | |||
2069 | return isl_bool_false; | |||
2070 | ||||
2071 | return space->nested[0] != NULL((void*)0); | |||
2072 | } | |||
2073 | ||||
2074 | /* Is "space" the space of a map where the range is a wrapped map space? | |||
2075 | */ | |||
2076 | isl_bool isl_space_range_is_wrapping(__isl_keep isl_space *space) | |||
2077 | { | |||
2078 | if (!space) | |||
2079 | return isl_bool_error; | |||
2080 | ||||
2081 | if (isl_space_is_set(space)) | |||
2082 | return isl_bool_false; | |||
2083 | ||||
2084 | return space->nested[1] != NULL((void*)0); | |||
2085 | } | |||
2086 | ||||
2087 | /* Is "space" a product of two spaces? | |||
2088 | * That is, is it a wrapping set space or a map space | |||
2089 | * with wrapping domain and range? | |||
2090 | */ | |||
2091 | isl_bool isl_space_is_product(__isl_keep isl_space *space) | |||
2092 | { | |||
2093 | isl_bool is_set; | |||
2094 | isl_bool is_product; | |||
2095 | ||||
2096 | is_set = isl_space_is_set(space); | |||
2097 | if (is_set < 0) | |||
2098 | return isl_bool_error; | |||
2099 | if (is_set) | |||
2100 | return isl_space_is_wrapping(space); | |||
2101 | is_product = isl_space_domain_is_wrapping(space); | |||
2102 | if (is_product < 0 || !is_product) | |||
2103 | return is_product; | |||
2104 | return isl_space_range_is_wrapping(space); | |||
2105 | } | |||
2106 | ||||
2107 | __isl_give isl_space *isl_space_wrap(__isl_take isl_space *dim) | |||
2108 | { | |||
2109 | isl_space *wrap; | |||
2110 | ||||
2111 | if (!dim) | |||
2112 | return NULL((void*)0); | |||
2113 | ||||
2114 | wrap = isl_space_set_alloc(dim->ctx, | |||
2115 | dim->nparam, dim->n_in + dim->n_out); | |||
2116 | ||||
2117 | wrap = copy_ids(wrap, isl_dim_param, 0, dim, isl_dim_param); | |||
2118 | wrap = copy_ids(wrap, isl_dim_set, 0, dim, isl_dim_in); | |||
2119 | wrap = copy_ids(wrap, isl_dim_set, dim->n_in, dim, isl_dim_out); | |||
2120 | ||||
2121 | if (!wrap) | |||
2122 | goto error; | |||
2123 | ||||
2124 | wrap->nested[1] = dim; | |||
2125 | ||||
2126 | return wrap; | |||
2127 | error: | |||
2128 | isl_space_free(dim); | |||
2129 | return NULL((void*)0); | |||
2130 | } | |||
2131 | ||||
2132 | __isl_give isl_space *isl_space_unwrap(__isl_take isl_space *dim) | |||
2133 | { | |||
2134 | isl_space *unwrap; | |||
2135 | ||||
2136 | if (!dim) | |||
2137 | return NULL((void*)0); | |||
2138 | ||||
2139 | if (!isl_space_is_wrapping(dim)) | |||
2140 | isl_die(dim->ctx, isl_error_invalid, "not a wrapping space",do { isl_handle_error(dim->ctx, isl_error_invalid, "not a wrapping space" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 2141); goto error; } while (0) | |||
2141 | goto error)do { isl_handle_error(dim->ctx, isl_error_invalid, "not a wrapping space" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 2141); goto error; } while (0); | |||
2142 | ||||
2143 | unwrap = isl_space_copy(dim->nested[1]); | |||
2144 | isl_space_free(dim); | |||
2145 | ||||
2146 | return unwrap; | |||
2147 | error: | |||
2148 | isl_space_free(dim); | |||
2149 | return NULL((void*)0); | |||
2150 | } | |||
2151 | ||||
2152 | isl_bool isl_space_is_named_or_nested(__isl_keep isl_space *space, | |||
2153 | enum isl_dim_type type) | |||
2154 | { | |||
2155 | if (type != isl_dim_in && type != isl_dim_out) | |||
2156 | return isl_bool_false; | |||
2157 | if (!space) | |||
2158 | return isl_bool_error; | |||
2159 | if (space->tuple_id[type - isl_dim_in]) | |||
2160 | return isl_bool_true; | |||
2161 | if (space->nested[type - isl_dim_in]) | |||
2162 | return isl_bool_true; | |||
2163 | return isl_bool_false; | |||
2164 | } | |||
2165 | ||||
2166 | isl_bool isl_space_may_be_set(__isl_keep isl_space *space) | |||
2167 | { | |||
2168 | isl_bool nested; | |||
2169 | ||||
2170 | if (!space) | |||
2171 | return isl_bool_error; | |||
2172 | if (isl_space_is_set(space)) | |||
2173 | return isl_bool_true; | |||
2174 | if (isl_space_dim(space, isl_dim_in) != 0) | |||
2175 | return isl_bool_false; | |||
2176 | nested = isl_space_is_named_or_nested(space, isl_dim_in); | |||
2177 | if (nested < 0 || nested) | |||
2178 | return isl_bool_not(nested); | |||
2179 | return isl_bool_true; | |||
2180 | } | |||
2181 | ||||
2182 | __isl_give isl_space *isl_space_reset(__isl_take isl_space *dim, | |||
2183 | enum isl_dim_type type) | |||
2184 | { | |||
2185 | if (!isl_space_is_named_or_nested(dim, type)) | |||
2186 | return dim; | |||
2187 | ||||
2188 | dim = isl_space_cow(dim); | |||
2189 | if (!dim) | |||
2190 | return NULL((void*)0); | |||
2191 | ||||
2192 | isl_id_free(dim->tuple_id[type - isl_dim_in]); | |||
2193 | dim->tuple_id[type - isl_dim_in] = NULL((void*)0); | |||
2194 | isl_space_free(dim->nested[type - isl_dim_in]); | |||
2195 | dim->nested[type - isl_dim_in] = NULL((void*)0); | |||
2196 | ||||
2197 | return dim; | |||
2198 | } | |||
2199 | ||||
2200 | __isl_give isl_space *isl_space_flatten(__isl_take isl_space *dim) | |||
2201 | { | |||
2202 | if (!dim) | |||
2203 | return NULL((void*)0); | |||
2204 | if (!dim->nested[0] && !dim->nested[1]) | |||
2205 | return dim; | |||
2206 | ||||
2207 | if (dim->nested[0]) | |||
2208 | dim = isl_space_reset(dim, isl_dim_in); | |||
2209 | if (dim && dim->nested[1]) | |||
2210 | dim = isl_space_reset(dim, isl_dim_out); | |||
2211 | ||||
2212 | return dim; | |||
2213 | } | |||
2214 | ||||
2215 | __isl_give isl_space *isl_space_flatten_domain(__isl_take isl_space *dim) | |||
2216 | { | |||
2217 | if (!dim) | |||
2218 | return NULL((void*)0); | |||
2219 | if (!dim->nested[0]) | |||
2220 | return dim; | |||
2221 | ||||
2222 | return isl_space_reset(dim, isl_dim_in); | |||
2223 | } | |||
2224 | ||||
2225 | __isl_give isl_space *isl_space_flatten_range(__isl_take isl_space *dim) | |||
2226 | { | |||
2227 | if (!dim) | |||
2228 | return NULL((void*)0); | |||
2229 | if (!dim->nested[1]) | |||
2230 | return dim; | |||
2231 | ||||
2232 | return isl_space_reset(dim, isl_dim_out); | |||
2233 | } | |||
2234 | ||||
2235 | /* Replace the dimensions of the given type of dst by those of src. | |||
2236 | */ | |||
2237 | __isl_give isl_space *isl_space_replace(__isl_take isl_space *dst, | |||
2238 | enum isl_dim_type type, __isl_keep isl_space *src) | |||
2239 | { | |||
2240 | dst = isl_space_cow(dst); | |||
2241 | ||||
2242 | if (!dst || !src) | |||
2243 | goto error; | |||
2244 | ||||
2245 | dst = isl_space_drop_dims(dst, type, 0, isl_space_dim(dst, type)); | |||
2246 | dst = isl_space_add_dims(dst, type, isl_space_dim(src, type)); | |||
2247 | dst = copy_ids(dst, type, 0, src, type); | |||
2248 | ||||
2249 | if (dst && type == isl_dim_param) { | |||
2250 | int i; | |||
2251 | for (i = 0; i <= 1; ++i) { | |||
2252 | if (!dst->nested[i]) | |||
2253 | continue; | |||
2254 | dst->nested[i] = isl_space_replace(dst->nested[i], | |||
2255 | type, src); | |||
2256 | if (!dst->nested[i]) | |||
2257 | goto error; | |||
2258 | } | |||
2259 | } | |||
2260 | ||||
2261 | return dst; | |||
2262 | error: | |||
2263 | isl_space_free(dst); | |||
2264 | return NULL((void*)0); | |||
2265 | } | |||
2266 | ||||
2267 | /* Given a dimension specification "dim" of a set, create a dimension | |||
2268 | * specification for the lift of the set. In particular, the result | |||
2269 | * is of the form [dim -> local[..]], with n_local variables in the | |||
2270 | * range of the wrapped map. | |||
2271 | */ | |||
2272 | __isl_give isl_space *isl_space_lift(__isl_take isl_space *dim, unsigned n_local) | |||
2273 | { | |||
2274 | isl_space *local_dim; | |||
2275 | ||||
2276 | if (!dim) | |||
2277 | return NULL((void*)0); | |||
2278 | ||||
2279 | local_dim = isl_space_dup(dim); | |||
2280 | local_dim = isl_space_drop_dims(local_dim, isl_dim_set, 0, dim->n_out); | |||
2281 | local_dim = isl_space_add_dims(local_dim, isl_dim_set, n_local); | |||
2282 | local_dim = isl_space_set_tuple_name(local_dim, isl_dim_set, "local"); | |||
2283 | dim = isl_space_join(isl_space_from_domain(dim), | |||
2284 | isl_space_from_range(local_dim)); | |||
2285 | dim = isl_space_wrap(dim); | |||
2286 | dim = isl_space_set_tuple_name(dim, isl_dim_set, "lifted"); | |||
2287 | ||||
2288 | return dim; | |||
2289 | } | |||
2290 | ||||
2291 | isl_bool isl_space_can_zip(__isl_keep isl_space *space) | |||
2292 | { | |||
2293 | isl_bool is_set; | |||
2294 | ||||
2295 | is_set = isl_space_is_set(space); | |||
2296 | if (is_set < 0) | |||
2297 | return isl_bool_error; | |||
2298 | if (is_set) | |||
2299 | return isl_bool_false; | |||
2300 | return isl_space_is_product(space); | |||
2301 | } | |||
2302 | ||||
2303 | __isl_give isl_space *isl_space_zip(__isl_take isl_space *dim) | |||
2304 | { | |||
2305 | isl_space *dom, *ran; | |||
2306 | isl_space *dom_dom, *dom_ran, *ran_dom, *ran_ran; | |||
2307 | ||||
2308 | if (!isl_space_can_zip(dim)) | |||
2309 | isl_die(dim->ctx, isl_error_invalid, "dim cannot be zipped",do { isl_handle_error(dim->ctx, isl_error_invalid, "dim cannot be zipped" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 2310); goto error; } while (0) | |||
2310 | goto error)do { isl_handle_error(dim->ctx, isl_error_invalid, "dim cannot be zipped" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 2310); goto error; } while (0); | |||
2311 | ||||
2312 | if (!dim) | |||
2313 | return NULL((void*)0); | |||
2314 | dom = isl_space_unwrap(isl_space_domain(isl_space_copy(dim))); | |||
2315 | ran = isl_space_unwrap(isl_space_range(dim)); | |||
2316 | dom_dom = isl_space_domain(isl_space_copy(dom)); | |||
2317 | dom_ran = isl_space_range(dom); | |||
2318 | ran_dom = isl_space_domain(isl_space_copy(ran)); | |||
2319 | ran_ran = isl_space_range(ran); | |||
2320 | dom = isl_space_join(isl_space_from_domain(dom_dom), | |||
2321 | isl_space_from_range(ran_dom)); | |||
2322 | ran = isl_space_join(isl_space_from_domain(dom_ran), | |||
2323 | isl_space_from_range(ran_ran)); | |||
2324 | return isl_space_join(isl_space_from_domain(isl_space_wrap(dom)), | |||
2325 | isl_space_from_range(isl_space_wrap(ran))); | |||
2326 | error: | |||
2327 | isl_space_free(dim); | |||
2328 | return NULL((void*)0); | |||
2329 | } | |||
2330 | ||||
2331 | /* Can we apply isl_space_curry to "space"? | |||
2332 | * That is, does it have a nested relation in its domain? | |||
2333 | */ | |||
2334 | isl_bool isl_space_can_curry(__isl_keep isl_space *space) | |||
2335 | { | |||
2336 | if (!space) | |||
2337 | return isl_bool_error; | |||
2338 | ||||
2339 | return !!space->nested[0]; | |||
2340 | } | |||
2341 | ||||
2342 | /* Given a space (A -> B) -> C, return the corresponding space | |||
2343 | * A -> (B -> C). | |||
2344 | */ | |||
2345 | __isl_give isl_space *isl_space_curry(__isl_take isl_space *space) | |||
2346 | { | |||
2347 | isl_space *dom, *ran; | |||
2348 | isl_space *dom_dom, *dom_ran; | |||
2349 | ||||
2350 | if (!space) | |||
2351 | return NULL((void*)0); | |||
2352 | ||||
2353 | if (!isl_space_can_curry(space)) | |||
2354 | isl_die(space->ctx, isl_error_invalid,do { isl_handle_error(space->ctx, isl_error_invalid, "space cannot be curried" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 2355); goto error; } while (0) | |||
2355 | "space cannot be curried", goto error)do { isl_handle_error(space->ctx, isl_error_invalid, "space cannot be curried" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 2355); goto error; } while (0); | |||
2356 | ||||
2357 | dom = isl_space_unwrap(isl_space_domain(isl_space_copy(space))); | |||
2358 | ran = isl_space_range(space); | |||
2359 | dom_dom = isl_space_domain(isl_space_copy(dom)); | |||
2360 | dom_ran = isl_space_range(dom); | |||
2361 | ran = isl_space_join(isl_space_from_domain(dom_ran), | |||
2362 | isl_space_from_range(ran)); | |||
2363 | return isl_space_join(isl_space_from_domain(dom_dom), | |||
2364 | isl_space_from_range(isl_space_wrap(ran))); | |||
2365 | error: | |||
2366 | isl_space_free(space); | |||
2367 | return NULL((void*)0); | |||
2368 | } | |||
2369 | ||||
2370 | /* Can isl_space_range_curry be applied to "space"? | |||
2371 | * That is, does it have a nested relation in its range, | |||
2372 | * the domain of which is itself a nested relation? | |||
2373 | */ | |||
2374 | isl_bool isl_space_can_range_curry(__isl_keep isl_space *space) | |||
2375 | { | |||
2376 | isl_bool can; | |||
2377 | ||||
2378 | if (!space) | |||
2379 | return isl_bool_error; | |||
2380 | can = isl_space_range_is_wrapping(space); | |||
2381 | if (can < 0 || !can) | |||
2382 | return can; | |||
2383 | return isl_space_can_curry(space->nested[1]); | |||
2384 | } | |||
2385 | ||||
2386 | /* Given a space A -> ((B -> C) -> D), return the corresponding space | |||
2387 | * A -> (B -> (C -> D)). | |||
2388 | */ | |||
2389 | __isl_give isl_space *isl_space_range_curry(__isl_take isl_space *space) | |||
2390 | { | |||
2391 | if (!space) | |||
2392 | return NULL((void*)0); | |||
2393 | ||||
2394 | if (!isl_space_can_range_curry(space)) | |||
2395 | isl_die(isl_space_get_ctx(space), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "space range cannot be curried", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 2397); return isl_space_free(space); } while (0) | |||
2396 | "space range cannot be curried",do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "space range cannot be curried", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 2397); return isl_space_free(space); } while (0) | |||
2397 | return isl_space_free(space))do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "space range cannot be curried", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 2397); return isl_space_free(space); } while (0); | |||
2398 | ||||
2399 | space = isl_space_cow(space); | |||
2400 | if (!space) | |||
2401 | return NULL((void*)0); | |||
2402 | space->nested[1] = isl_space_curry(space->nested[1]); | |||
2403 | if (!space->nested[1]) | |||
2404 | return isl_space_free(space); | |||
2405 | ||||
2406 | return space; | |||
2407 | } | |||
2408 | ||||
2409 | /* Can we apply isl_space_uncurry to "space"? | |||
2410 | * That is, does it have a nested relation in its range? | |||
2411 | */ | |||
2412 | isl_bool isl_space_can_uncurry(__isl_keep isl_space *space) | |||
2413 | { | |||
2414 | if (!space) | |||
2415 | return isl_bool_error; | |||
2416 | ||||
2417 | return !!space->nested[1]; | |||
2418 | } | |||
2419 | ||||
2420 | /* Given a space A -> (B -> C), return the corresponding space | |||
2421 | * (A -> B) -> C. | |||
2422 | */ | |||
2423 | __isl_give isl_space *isl_space_uncurry(__isl_take isl_space *space) | |||
2424 | { | |||
2425 | isl_space *dom, *ran; | |||
2426 | isl_space *ran_dom, *ran_ran; | |||
2427 | ||||
2428 | if (!space) | |||
2429 | return NULL((void*)0); | |||
2430 | ||||
2431 | if (!isl_space_can_uncurry(space)) | |||
2432 | isl_die(space->ctx, isl_error_invalid,do { isl_handle_error(space->ctx, isl_error_invalid, "space cannot be uncurried" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 2434); return isl_space_free(space); } while (0) | |||
2433 | "space cannot be uncurried",do { isl_handle_error(space->ctx, isl_error_invalid, "space cannot be uncurried" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 2434); return isl_space_free(space); } while (0) | |||
2434 | return isl_space_free(space))do { isl_handle_error(space->ctx, isl_error_invalid, "space cannot be uncurried" , "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 2434); return isl_space_free(space); } while (0); | |||
2435 | ||||
2436 | dom = isl_space_domain(isl_space_copy(space)); | |||
2437 | ran = isl_space_unwrap(isl_space_range(space)); | |||
2438 | ran_dom = isl_space_domain(isl_space_copy(ran)); | |||
2439 | ran_ran = isl_space_range(ran); | |||
2440 | dom = isl_space_join(isl_space_from_domain(dom), | |||
2441 | isl_space_from_range(ran_dom)); | |||
2442 | return isl_space_join(isl_space_from_domain(isl_space_wrap(dom)), | |||
2443 | isl_space_from_range(ran_ran)); | |||
2444 | } | |||
2445 | ||||
2446 | isl_bool isl_space_has_named_params(__isl_keep isl_space *space) | |||
2447 | { | |||
2448 | int i; | |||
2449 | unsigned off; | |||
2450 | ||||
2451 | if (!space) | |||
2452 | return isl_bool_error; | |||
2453 | if (space->nparam == 0) | |||
2454 | return isl_bool_true; | |||
2455 | off = isl_space_offset(space, isl_dim_param); | |||
2456 | if (off + space->nparam > space->n_id) | |||
2457 | return isl_bool_false; | |||
2458 | for (i = 0; i < space->nparam; ++i) | |||
2459 | if (!space->ids[off + i]) | |||
| ||||
2460 | return isl_bool_false; | |||
2461 | return isl_bool_true; | |||
2462 | } | |||
2463 | ||||
2464 | /* Check that "space" has only named parameters, reporting an error | |||
2465 | * if it does not. | |||
2466 | */ | |||
2467 | isl_stat isl_space_check_named_params(__isl_keep isl_space *space) | |||
2468 | { | |||
2469 | isl_bool named; | |||
2470 | ||||
2471 | named = isl_space_has_named_params(space); | |||
2472 | if (named < 0) | |||
2473 | return isl_stat_error; | |||
2474 | if (!named) | |||
2475 | isl_die(isl_space_get_ctx(space), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "unaligned unnamed parameters", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 2476); return isl_stat_error; } while (0) | |||
2476 | "unaligned unnamed parameters", return isl_stat_error)do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid , "unaligned unnamed parameters", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 2476); return isl_stat_error; } while (0); | |||
2477 | ||||
2478 | return isl_stat_ok; | |||
2479 | } | |||
2480 | ||||
2481 | /* Align the initial parameters of dim1 to match the order in dim2. | |||
2482 | */ | |||
2483 | __isl_give isl_space *isl_space_align_params(__isl_take isl_space *dim1, | |||
2484 | __isl_take isl_space *dim2) | |||
2485 | { | |||
2486 | isl_reordering *exp; | |||
2487 | ||||
2488 | if (!isl_space_has_named_params(dim1) || !isl_space_has_named_params(dim2)) | |||
2489 | isl_die(isl_space_get_ctx(dim1), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(dim1), isl_error_invalid , "parameter alignment requires named parameters", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 2491); goto error; } while (0) | |||
2490 | "parameter alignment requires named parameters",do { isl_handle_error(isl_space_get_ctx(dim1), isl_error_invalid , "parameter alignment requires named parameters", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 2491); goto error; } while (0) | |||
2491 | goto error)do { isl_handle_error(isl_space_get_ctx(dim1), isl_error_invalid , "parameter alignment requires named parameters", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn306458/tools/polly/lib/External/isl/isl_space.c" , 2491); goto error; } while (0); | |||
2492 | ||||
2493 | dim2 = isl_space_params(dim2); | |||
2494 | exp = isl_parameter_alignment_reordering(dim1, dim2); | |||
2495 | exp = isl_reordering_extend_space(exp, dim1); | |||
2496 | isl_space_free(dim2); | |||
2497 | if (!exp) | |||
2498 | return NULL((void*)0); | |||
2499 | dim1 = isl_space_copy(exp->dim); | |||
2500 | isl_reordering_free(exp); | |||
2501 | return dim1; | |||
2502 | error: | |||
2503 | isl_space_free(dim1); | |||
2504 | isl_space_free(dim2); | |||
2505 | return NULL((void*)0); | |||
2506 | } | |||
2507 | ||||
2508 | /* Given the space of set (domain), construct a space for a map | |||
2509 | * with as domain the given space and as range the range of "model". | |||
2510 | */ | |||
2511 | __isl_give isl_space *isl_space_extend_domain_with_range( | |||
2512 | __isl_take isl_space *space, __isl_take isl_space *model) | |||
2513 | { | |||
2514 | if (!model) | |||
| ||||
2515 | goto error; | |||
2516 | ||||
2517 | space = isl_space_from_domain(space); | |||
2518 | space = isl_space_add_dims(space, isl_dim_out, | |||
2519 | isl_space_dim(model, isl_dim_out)); | |||
2520 | if (isl_space_has_tuple_id(model, isl_dim_out)) | |||
2521 | space = isl_space_set_tuple_id(space, isl_dim_out, | |||
2522 | isl_space_get_tuple_id(model, isl_dim_out)); | |||
2523 | if (!space) | |||
2524 | goto error; | |||
2525 | if (model->nested[1]) { | |||
2526 | isl_space *nested = isl_space_copy(model->nested[1]); | |||
2527 | int n_nested, n_space; | |||
2528 | nested = isl_space_align_params(nested, isl_space_copy(space)); | |||
2529 | n_nested = isl_space_dim(nested, isl_dim_param); | |||
2530 | n_space = isl_space_dim(space, isl_dim_param); | |||
2531 | if (n_nested > n_space) | |||
2532 | nested = isl_space_drop_dims(nested, isl_dim_param, | |||
2533 | n_space, n_nested - n_space); | |||
2534 | if (!nested) | |||
2535 | goto error; | |||
2536 | space->nested[1] = nested; | |||
2537 | } | |||
2538 | isl_space_free(model); | |||
2539 | return space; | |||
2540 | error: | |||
2541 | isl_space_free(model); | |||
2542 | isl_space_free(space); | |||
2543 | return NULL((void*)0); | |||
2544 | } | |||
2545 | ||||
2546 | /* Compare the "type" dimensions of two isl_spaces. | |||
2547 | * | |||
2548 | * The order is fairly arbitrary. | |||
2549 | */ | |||
2550 | static int isl_space_cmp_type(__isl_keep isl_space *space1, | |||
2551 | __isl_keep isl_space *space2, enum isl_dim_type type) | |||
2552 | { | |||
2553 | int cmp; | |||
2554 | isl_space *nested1, *nested2; | |||
2555 | ||||
2556 | if (isl_space_dim(space1, type) != isl_space_dim(space2, type)) | |||
2557 | return isl_space_dim(space1, type) - | |||
2558 | isl_space_dim(space2, type); | |||
2559 | ||||
2560 | cmp = isl_id_cmp(tuple_id(space1, type), tuple_id(space2, type)); | |||
2561 | if (cmp != 0) | |||
2562 | return cmp; | |||
2563 | ||||
2564 | nested1 = nested(space1, type); | |||
2565 | nested2 = nested(space2, type); | |||
2566 | if (!nested1 != !nested2) | |||
2567 | return !nested1 - !nested2; | |||
2568 | ||||
2569 | if (nested1) | |||
2570 | return isl_space_cmp(nested1, nested2); | |||
2571 | ||||
2572 | return 0; | |||
2573 | } | |||
2574 | ||||
2575 | /* Compare two isl_spaces. | |||
2576 | * | |||
2577 | * The order is fairly arbitrary. | |||
2578 | */ | |||
2579 | int isl_space_cmp(__isl_keep isl_space *space1, __isl_keep isl_space *space2) | |||
2580 | { | |||
2581 | int i; | |||
2582 | int cmp; | |||
2583 | ||||
2584 | if (space1 == space2) | |||
2585 | return 0; | |||
2586 | if (!space1) | |||
2587 | return -1; | |||
2588 | if (!space2) | |||
2589 | return 1; | |||
2590 | ||||
2591 | cmp = isl_space_cmp_type(space1, space2, isl_dim_param); | |||
2592 | if (cmp != 0) | |||
2593 | return cmp; | |||
2594 | cmp = isl_space_cmp_type(space1, space2, isl_dim_in); | |||
2595 | if (cmp != 0) | |||
2596 | return cmp; | |||
2597 | cmp = isl_space_cmp_type(space1, space2, isl_dim_out); | |||
2598 | if (cmp != 0) | |||
2599 | return cmp; | |||
2600 | ||||
2601 | if (!space1->ids && !space2->ids) | |||
2602 | return 0; | |||
2603 | ||||
2604 | for (i = 0; i < n(space1, isl_dim_param); ++i) { | |||
2605 | cmp = isl_id_cmp(get_id(space1, isl_dim_param, i), | |||
2606 | get_id(space2, isl_dim_param, i)); | |||
2607 | if (cmp != 0) | |||
2608 | return cmp; | |||
2609 | } | |||
2610 | ||||
2611 | return 0; | |||
2612 | } |