Bug Summary

File:tools/polly/lib/External/isl/isl_space.c
Warning:line 233, column 9
Array access (via field 'ids') results in a null pointer dereference

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name isl_space.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-7/lib/clang/7.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/polly/lib/External -I /build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External -I /build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/pet/include -I /build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/ppcg/include -I /build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/ppcg/imath -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/polly/lib/External/ppcg -I /build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl -I /build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/include -I /build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/imath -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/polly/lib/External/isl -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/polly/include -I /usr/include/jsoncpp -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/polly/lib/External/isl/include -I /build/llvm-toolchain-snapshot-7~svn338205/tools/polly/include -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn338205/include -U NDEBUG -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/lib/gcc/x86_64-linux-gnu/8/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=gnu99 -fconst-strings -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/polly/lib/External -fdebug-prefix-map=/build/llvm-toolchain-snapshot-7~svn338205=. -ferror-limit 19 -fmessage-length 0 -stack-protector 2 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-07-29-043837-17923-1 -x c /build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c -faddrsig
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
21isl_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 */
57static __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 */
68isl_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 */
81isl_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 */
101static __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 */
112isl_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
136static 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) {
109
Control jumps to 'case isl_dim_param:' at line 142
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", "/build/llvm-toolchain-snapshot-7~svn338205/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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 144); return isl_space_dim(dim, isl_dim_all); } while (0); }
while (0)
;
145 return pos;
110
Returning without writing to 'dim->ids'
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", "/build/llvm-toolchain-snapshot-7~svn338205/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", "/build/llvm-toolchain-snapshot-7~svn338205/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", "/build/llvm-toolchain-snapshot-7~svn338205/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", "/build/llvm-toolchain-snapshot-7~svn338205/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", "/build/llvm-toolchain-snapshot-7~svn338205/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 */
162static __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;
188error:
189 isl_space_free(dim);
190 return NULL((void*)0);
191}
192
193static __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;
216error:
217 isl_id_free(id);
218 isl_space_free(dim);
219 return NULL((void*)0);
220}
221
222static __isl_keep isl_id *get_id(__isl_keep isl_space *dim,
223 enum isl_dim_type type, unsigned pos)
224{
225 if (!dim)
107
Taking false branch
226 return NULL((void*)0);
227
228 pos = global_pos(dim, type, pos);
108
Calling 'global_pos'
111
Returning from 'global_pos'
229 if (pos == isl_space_dim(dim, isl_dim_all))
112
Calling 'isl_space_dim'
119
Returning from 'isl_space_dim'
120
Assuming the condition is false
121
Taking false branch
230 return NULL((void*)0);
231 if (pos >= dim->n_id)
122
Assuming the condition is false
123
Taking false branch
232 return NULL((void*)0);
233 return dim->ids[pos];
124
Array access (via field 'ids') results in a null pointer dereference
234}
235
236static 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
246static unsigned n(__isl_keep isl_space *dim, enum isl_dim_type type)
247{
248 switch (type) {
18
Control jumps to 'case isl_dim_param:' at line 249
48
Control jumps to 'case isl_dim_in:' at line 250
78
Control jumps to 'case isl_dim_out:' at line 251
88
Control jumps to 'case isl_dim_out:' at line 251
101
Control jumps to 'case isl_dim_param:' at line 249
115
Control jumps to 'case isl_dim_all:' at line 252
249 case isl_dim_param: return dim->nparam;
19
Returning without writing to 'dim->ids'
102
Returning without writing to 'dim->ids'
250 case isl_dim_in: return dim->n_in;
49
Returning without writing to 'dim->ids'
251 case isl_dim_out: return dim->n_out;
79
Returning without writing to 'dim->ids'
89
Returning without writing to 'dim->ids'
252 case isl_dim_all: return dim->nparam + dim->n_in + dim->n_out;
116
Returning without writing to 'dim->ids'
253 default: return 0;
254 }
255}
256
257unsigned isl_space_dim(__isl_keep isl_space *dim, enum isl_dim_type type)
258{
259 if (!dim)
16
Taking false branch
46
Taking false branch
76
Taking false branch
86
Taking false branch
113
Taking false branch
260 return 0;
261 return n(dim, type);
17
Calling 'n'
20
Returning from 'n'
21
Returning without writing to 'dim->ids'
47
Calling 'n'
50
Returning from 'n'
51
Returning without writing to 'dim->ids'
77
Calling 'n'
80
Returning from 'n'
81
Returning without writing to 'dim->ids'
87
Calling 'n'
90
Returning from 'n'
91
Returning without writing to 'dim->ids'
114
Calling 'n'
117
Returning from 'n'
118
Returning without writing to 'dim->ids'
262}
263
264unsigned 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
271static __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;
316error:
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 */
372static 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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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 */
387static 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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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 */
408isl_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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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;
447error:
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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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;
468error:
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);
501error:
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));
535error:
536 isl_space_free(space);
537 return NULL((void*)0);
538}
539
540isl_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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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"
, "/build/llvm-toolchain-snapshot-7~svn338205/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);
575error:
576 isl_space_free(dim);
577 return NULL((void*)0);
578}
579
580/* Does the tuple have a name?
581 */
582isl_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);
619error:
620 isl_space_free(dim);
621 return NULL((void*)0);
622}
623
624/* Does the given dimension have a name?
625 */
626isl_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
644int 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
663int 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))
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
743static __isl_keep isl_id *tuple_id(__isl_keep isl_space *dim,
744 enum isl_dim_type type)
745{
746 if (!dim)
26
Taking false branch
56
Taking false branch
747 return NULL((void*)0);
748 if (type == isl_dim_in)
27
Taking false branch
57
Taking true branch
749 return dim->tuple_id[0];
58
Returning without writing to 'dim->ids'
750 if (type == isl_dim_out)
28
Taking false branch
751 return dim->tuple_id[1];
752 return NULL((void*)0);
29
Returning without writing to 'dim->ids'
753}
754
755static __isl_keep isl_space *nested(__isl_keep isl_space *dim,
756 enum isl_dim_type type)
757{
758 if (!dim)
34
Taking false branch
63
Taking false branch
759 return NULL((void*)0);
760 if (type == isl_dim_in)
35
Taking false branch
64
Taking true branch
761 return dim->nested[0];
65
Returning without writing to 'dim->ids'
762 if (type == isl_dim_out)
36
Taking false branch
763 return dim->nested[1];
764 return NULL((void*)0);
37
Returning without writing to 'dim->ids'
765}
766
767/* Are the two spaces the same, apart from positions and names of parameters?
768 */
769isl_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 */
794isl_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
824static isl_bool match(__isl_keep isl_space *space1, enum isl_dim_type type1,
825 __isl_keep isl_space *space2, enum isl_dim_type type2)
826{
827 int i;
828
829 if (space1 == space2 && type1 == type2)
830 return isl_bool_true;
831
832 if (!isl_space_tuple_is_equal(space1, type1, space2, type2))
833 return isl_bool_false;
834
835 if (!space1->ids && !space2->ids)
836 return isl_bool_true;
837
838 for (i = 0; i < n(space1, type1); ++i) {
839 if (get_id(space1, type1, i) != get_id(space2, type2, i))
840 return isl_bool_false;
841 }
842 return isl_bool_true;
843}
844
845/* Do "space1" and "space2" have the same parameters?
846 */
847isl_bool isl_space_has_equal_params(__isl_keep isl_space *space1,
848 __isl_keep isl_space *space2)
849{
850 if (!space1 || !space2)
851 return isl_bool_error;
852
853 return match(space1, isl_dim_param, space2, isl_dim_param);
854}
855
856/* Do "space1" and "space2" have the same identifiers for all
857 * the tuple variables?
858 */
859isl_bool isl_space_has_equal_ids(__isl_keep isl_space *space1,
860 __isl_keep isl_space *space2)
861{
862 isl_bool equal;
863
864 if (!space1 || !space2)
865 return isl_bool_error;
866
867 equal = match(space1, isl_dim_in, space2, isl_dim_in);
868 if (equal < 0 || !equal)
869 return equal;
870 return match(space1, isl_dim_out, space2, isl_dim_out);
871}
872
873isl_bool isl_space_match(__isl_keep isl_space *space1, enum isl_dim_type type1,
874 __isl_keep isl_space *space2, enum isl_dim_type type2)
875{
876 if (!space1 || !space2)
877 return isl_bool_error;
878
879 return match(space1, type1, space2, type2);
880}
881
882static void get_ids(__isl_keep isl_space *dim, enum isl_dim_type type,
883 unsigned first, unsigned n, __isl_keep isl_id **ids)
884{
885 int i;
886
887 for (i = 0; i < n ; ++i)
888 ids[i] = get_id(dim, type, first + i);
889}
890
891static __isl_give isl_space *space_extend(__isl_take isl_space *space,
892 unsigned nparam, unsigned n_in, unsigned n_out)
893{
894 isl_id **ids = NULL((void*)0);
895
896 if (!space)
897 return NULL((void*)0);
898 if (space->nparam == nparam &&
899 space->n_in == n_in && space->n_out == n_out)
900 return space;
901
902 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 902); goto error; } while (0); } while (0)
;
903 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 903); goto error; } while (0); } while (0)
;
904 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 904); goto error; } while (0); } while (0)
;
905
906 space = isl_space_cow(space);
907 if (!space)
908 goto error;
909
910 if (space->ids) {
911 unsigned n;
912 n = nparam + n_in + n_out;
913 if (n < nparam || n < n_in || n < n_out)
914 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 916); goto error; } while (0)
915 "overflow in total number of dimensions",do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid
, "overflow in total number of dimensions", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 916); goto error; } while (0)
916 goto error)do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid
, "overflow in total number of dimensions", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 916); goto error; } while (0)
;
917 ids = isl_calloc_array(space->ctx, isl_id *, n)((isl_id * *)isl_calloc_or_die(space->ctx, n, sizeof(isl_id
*)))
;
918 if (!ids)
919 goto error;
920 get_ids(space, isl_dim_param, 0, space->nparam, ids);
921 get_ids(space, isl_dim_in, 0, space->n_in, ids + nparam);
922 get_ids(space, isl_dim_out, 0, space->n_out,
923 ids + nparam + n_in);
924 free(space->ids);
925 space->ids = ids;
926 space->n_id = nparam + n_in + n_out;
927 }
928 space->nparam = nparam;
929 space->n_in = n_in;
930 space->n_out = n_out;
931
932 return space;
933error:
934 free(ids);
935 isl_space_free(space);
936 return NULL((void*)0);
937}
938
939__isl_give isl_space *isl_space_extend(__isl_take isl_space *space,
940 unsigned nparam, unsigned n_in, unsigned n_out)
941{
942 return space_extend(space, nparam, n_in, n_out);
943}
944
945__isl_give isl_space *isl_space_add_dims(__isl_take isl_space *space,
946 enum isl_dim_type type, unsigned n)
947{
948 space = isl_space_reset(space, type);
949 if (!space)
950 return NULL((void*)0);
951 switch (type) {
952 case isl_dim_param:
953 space = space_extend(space,
954 space->nparam + n, space->n_in, space->n_out);
955 if (space && space->nested[0] &&
956 !(space->nested[0] = isl_space_add_dims(space->nested[0],
957 isl_dim_param, n)))
958 goto error;
959 if (space && space->nested[1] &&
960 !(space->nested[1] = isl_space_add_dims(space->nested[1],
961 isl_dim_param, n)))
962 goto error;
963 return space;
964 case isl_dim_in:
965 return space_extend(space,
966 space->nparam, space->n_in + n, space->n_out);
967 case isl_dim_out:
968 return space_extend(space,
969 space->nparam, space->n_in, space->n_out + n);
970 default:
971 isl_die(space->ctx, isl_error_invalid,do { isl_handle_error(space->ctx, isl_error_invalid, "cannot add dimensions of specified type"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 972); goto error; } while (0)
972 "cannot add dimensions of specified type", goto error)do { isl_handle_error(space->ctx, isl_error_invalid, "cannot add dimensions of specified type"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 972); goto error; } while (0)
;
973 }
974error:
975 isl_space_free(space);
976 return NULL((void*)0);
977}
978
979/* Add a parameter with identifier "id" to "space", provided
980 * it does not already appear in "space".
981 */
982__isl_give isl_space *isl_space_add_param_id(__isl_take isl_space *space,
983 __isl_take isl_id *id)
984{
985 int pos;
986
987 if (!space || !id)
988 goto error;
989
990 if (isl_space_find_dim_by_id(space, isl_dim_param, id) >= 0) {
991 isl_id_free(id);
992 return space;
993 }
994
995 pos = isl_space_dim(space, isl_dim_param);
996 space = isl_space_add_dims(space, isl_dim_param, 1);
997 space = isl_space_set_dim_id(space, isl_dim_param, pos, id);
998
999 return space;
1000error:
1001 isl_space_free(space);
1002 isl_id_free(id);
1003 return NULL((void*)0);
1004}
1005
1006static int valid_dim_type(enum isl_dim_type type)
1007{
1008 switch (type) {
1009 case isl_dim_param:
1010 case isl_dim_in:
1011 case isl_dim_out:
1012 return 1;
1013 default:
1014 return 0;
1015 }
1016}
1017
1018/* Insert "n" dimensions of type "type" at position "pos".
1019 * If we are inserting parameters, then they are also inserted in
1020 * any nested spaces.
1021 */
1022__isl_give isl_space *isl_space_insert_dims(__isl_take isl_space *dim,
1023 enum isl_dim_type type, unsigned pos, unsigned n)
1024{
1025 isl_id **ids = NULL((void*)0);
1026
1027 if (!dim)
1028 return NULL((void*)0);
1029 if (n == 0)
1030 return isl_space_reset(dim, type);
1031
1032 if (!valid_dim_type(type))
1033 isl_die(dim->ctx, isl_error_invalid,do { isl_handle_error(dim->ctx, isl_error_invalid, "cannot insert dimensions of specified type"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1035); goto error; } while (0)
1034 "cannot insert dimensions of specified type",do { isl_handle_error(dim->ctx, isl_error_invalid, "cannot insert dimensions of specified type"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1035); goto error; } while (0)
1035 goto error)do { isl_handle_error(dim->ctx, isl_error_invalid, "cannot insert dimensions of specified type"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1035); goto error; } while (0)
;
1036
1037 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1037); goto error; } while (0); } while (0)
;
1038
1039 dim = isl_space_cow(dim);
1040 if (!dim)
1041 return NULL((void*)0);
1042
1043 if (dim->ids) {
1044 enum isl_dim_type t, o = isl_dim_param;
1045 int off;
1046 int s[3];
1047 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 *)))
1048 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 *)))
;
1049 if (!ids)
1050 goto error;
1051 off = 0;
1052 s[isl_dim_param - o] = dim->nparam;
1053 s[isl_dim_in - o] = dim->n_in;
1054 s[isl_dim_out - o] = dim->n_out;
1055 for (t = isl_dim_param; t <= isl_dim_out; ++t) {
1056 if (t != type) {
1057 get_ids(dim, t, 0, s[t - o], ids + off);
1058 off += s[t - o];
1059 } else {
1060 get_ids(dim, t, 0, pos, ids + off);
1061 off += pos + n;
1062 get_ids(dim, t, pos, s[t - o] - pos, ids + off);
1063 off += s[t - o] - pos;
1064 }
1065 }
1066 free(dim->ids);
1067 dim->ids = ids;
1068 dim->n_id = dim->nparam + dim->n_in + dim->n_out + n;
1069 }
1070 switch (type) {
1071 case isl_dim_param: dim->nparam += n; break;
1072 case isl_dim_in: dim->n_in += n; break;
1073 case isl_dim_out: dim->n_out += n; break;
1074 default: ;
1075 }
1076 dim = isl_space_reset(dim, type);
1077
1078 if (type == isl_dim_param) {
1079 if (dim && dim->nested[0] &&
1080 !(dim->nested[0] = isl_space_insert_dims(dim->nested[0],
1081 isl_dim_param, pos, n)))
1082 goto error;
1083 if (dim && dim->nested[1] &&
1084 !(dim->nested[1] = isl_space_insert_dims(dim->nested[1],
1085 isl_dim_param, pos, n)))
1086 goto error;
1087 }
1088
1089 return dim;
1090error:
1091 isl_space_free(dim);
1092 return NULL((void*)0);
1093}
1094
1095__isl_give isl_space *isl_space_move_dims(__isl_take isl_space *space,
1096 enum isl_dim_type dst_type, unsigned dst_pos,
1097 enum isl_dim_type src_type, unsigned src_pos, unsigned n)
1098{
1099 int i;
1100
1101 space = isl_space_reset(space, src_type);
1102 space = isl_space_reset(space, dst_type);
1103 if (!space)
1104 return NULL((void*)0);
1105 if (n == 0)
1106 return space;
1107
1108 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"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1109); goto error; } while (0); } while (0)
1109 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"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1109); goto error; } while (0); } while (0)
;
1110
1111 if (dst_type == src_type && dst_pos == src_pos)
1112 return space;
1113
1114 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1114); goto error; } while (0); } while (0)
;
1115
1116 space = isl_space_cow(space);
1117 if (!space)
1118 return NULL((void*)0);
1119
1120 if (space->ids) {
1121 isl_id **ids;
1122 enum isl_dim_type t, o = isl_dim_param;
1123 int off;
1124 int s[3];
1125 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 *)))
1126 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 *)))
;
1127 if (!ids)
1128 goto error;
1129 off = 0;
1130 s[isl_dim_param - o] = space->nparam;
1131 s[isl_dim_in - o] = space->n_in;
1132 s[isl_dim_out - o] = space->n_out;
1133 for (t = isl_dim_param; t <= isl_dim_out; ++t) {
1134 if (t == dst_type) {
1135 get_ids(space, t, 0, dst_pos, ids + off);
1136 off += dst_pos;
1137 get_ids(space, src_type, src_pos, n, ids + off);
1138 off += n;
1139 get_ids(space, t, dst_pos, s[t - o] - dst_pos,
1140 ids + off);
1141 off += s[t - o] - dst_pos;
1142 } else if (t == src_type) {
1143 get_ids(space, t, 0, src_pos, ids + off);
1144 off += src_pos;
1145 get_ids(space, t, src_pos + n,
1146 s[t - o] - src_pos - n, ids + off);
1147 off += s[t - o] - src_pos - n;
1148 } else {
1149 get_ids(space, t, 0, s[t - o], ids + off);
1150 off += s[t - o];
1151 }
1152 }
1153 free(space->ids);
1154 space->ids = ids;
1155 space->n_id = space->nparam + space->n_in + space->n_out;
1156 }
1157
1158 switch (dst_type) {
1159 case isl_dim_param: space->nparam += n; break;
1160 case isl_dim_in: space->n_in += n; break;
1161 case isl_dim_out: space->n_out += n; break;
1162 default: ;
1163 }
1164
1165 switch (src_type) {
1166 case isl_dim_param: space->nparam -= n; break;
1167 case isl_dim_in: space->n_in -= n; break;
1168 case isl_dim_out: space->n_out -= n; break;
1169 default: ;
1170 }
1171
1172 if (dst_type != isl_dim_param && src_type != isl_dim_param)
1173 return space;
1174
1175 for (i = 0; i < 2; ++i) {
1176 if (!space->nested[i])
1177 continue;
1178 space->nested[i] = isl_space_replace_params(space->nested[i],
1179 space);
1180 if (!space->nested[i])
1181 goto error;
1182 }
1183
1184 return space;
1185error:
1186 isl_space_free(space);
1187 return NULL((void*)0);
1188}
1189
1190/* Check that "space1" and "space2" have the same parameters,
1191 * reporting an error if they do not.
1192 */
1193isl_stat isl_space_check_equal_params(__isl_keep isl_space *space1,
1194 __isl_keep isl_space *space2)
1195{
1196 isl_bool equal;
1197
1198 equal = isl_space_has_equal_params(space1, space2);
1199 if (equal < 0)
1200 return isl_stat_error;
1201 if (!equal)
1202 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1203); return isl_stat_error; } while (0)
1203 "parameters need to match", return isl_stat_error)do { isl_handle_error(isl_space_get_ctx(space1), isl_error_invalid
, "parameters need to match", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1203); return isl_stat_error; } while (0)
;
1204 return isl_stat_ok;
1205}
1206
1207__isl_give isl_space *isl_space_join(__isl_take isl_space *left,
1208 __isl_take isl_space *right)
1209{
1210 isl_space *dim;
1211
1212 if (isl_space_check_equal_params(left, right) < 0)
1213 goto error;
1214
1215 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1217); goto error; } while (0); } while (0)
1216 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1217); goto error; } while (0); } while (0)
1217 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1217); goto error; } while (0); } while (0)
;
1218
1219 dim = isl_space_alloc(left->ctx, left->nparam, left->n_in, right->n_out);
1220 if (!dim)
1221 goto error;
1222
1223 dim = copy_ids(dim, isl_dim_param, 0, left, isl_dim_param);
1224 dim = copy_ids(dim, isl_dim_in, 0, left, isl_dim_in);
1225 dim = copy_ids(dim, isl_dim_out, 0, right, isl_dim_out);
1226
1227 if (dim && left->tuple_id[0] &&
1228 !(dim->tuple_id[0] = isl_id_copy(left->tuple_id[0])))
1229 goto error;
1230 if (dim && right->tuple_id[1] &&
1231 !(dim->tuple_id[1] = isl_id_copy(right->tuple_id[1])))
1232 goto error;
1233 if (dim && left->nested[0] &&
1234 !(dim->nested[0] = isl_space_copy(left->nested[0])))
1235 goto error;
1236 if (dim && right->nested[1] &&
1237 !(dim->nested[1] = isl_space_copy(right->nested[1])))
1238 goto error;
1239
1240 isl_space_free(left);
1241 isl_space_free(right);
1242
1243 return dim;
1244error:
1245 isl_space_free(left);
1246 isl_space_free(right);
1247 return NULL((void*)0);
1248}
1249
1250/* Given two map spaces { A -> C } and { B -> D }, construct the space
1251 * { [A -> B] -> [C -> D] }.
1252 * Given two set spaces { A } and { B }, construct the space { [A -> B] }.
1253 */
1254__isl_give isl_space *isl_space_product(__isl_take isl_space *left,
1255 __isl_take isl_space *right)
1256{
1257 isl_space *dom1, *dom2, *nest1, *nest2;
1258 int is_set;
1259
1260 if (!left || !right)
1261 goto error;
1262
1263 is_set = isl_space_is_set(left);
1264 if (is_set != isl_space_is_set(right))
1265 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1267); goto error; } while (0)
1266 "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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1267); goto error; } while (0)
1267 goto error)do { isl_handle_error(isl_space_get_ctx(left), isl_error_invalid
, "expecting either two set spaces or two map spaces", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1267); goto error; } while (0)
;
1268 if (is_set)
1269 return isl_space_range_product(left, right);
1270
1271 if (isl_space_check_equal_params(left, right) < 0)
1272 goto error;
1273
1274 dom1 = isl_space_domain(isl_space_copy(left));
1275 dom2 = isl_space_domain(isl_space_copy(right));
1276 nest1 = isl_space_wrap(isl_space_join(isl_space_reverse(dom1), dom2));
1277
1278 dom1 = isl_space_range(left);
1279 dom2 = isl_space_range(right);
1280 nest2 = isl_space_wrap(isl_space_join(isl_space_reverse(dom1), dom2));
1281
1282 return isl_space_join(isl_space_reverse(nest1), nest2);
1283error:
1284 isl_space_free(left);
1285 isl_space_free(right);
1286 return NULL((void*)0);
1287}
1288
1289/* Given two spaces { A -> C } and { B -> C }, construct the space
1290 * { [A -> B] -> C }
1291 */
1292__isl_give isl_space *isl_space_domain_product(__isl_take isl_space *left,
1293 __isl_take isl_space *right)
1294{
1295 isl_space *ran, *dom1, *dom2, *nest;
1296
1297 if (isl_space_check_equal_params(left, right) < 0)
1298 goto error;
1299
1300 if (!isl_space_tuple_is_equal(left, isl_dim_out, right, isl_dim_out))
1301 isl_die(left->ctx, isl_error_invalid,do { isl_handle_error(left->ctx, isl_error_invalid, "ranges need to match"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1302); goto error; } while (0)
1302 "ranges need to match", goto error)do { isl_handle_error(left->ctx, isl_error_invalid, "ranges need to match"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1302); goto error; } while (0)
;
1303
1304 ran = isl_space_range(isl_space_copy(left));
1305
1306 dom1 = isl_space_domain(left);
1307 dom2 = isl_space_domain(right);
1308 nest = isl_space_wrap(isl_space_join(isl_space_reverse(dom1), dom2));
1309
1310 return isl_space_join(isl_space_reverse(nest), ran);
1311error:
1312 isl_space_free(left);
1313 isl_space_free(right);
1314 return NULL((void*)0);
1315}
1316
1317__isl_give isl_space *isl_space_range_product(__isl_take isl_space *left,
1318 __isl_take isl_space *right)
1319{
1320 isl_space *dom, *ran1, *ran2, *nest;
1321
1322 if (isl_space_check_equal_params(left, right) < 0)
1323 goto error;
1324
1325 if (!isl_space_tuple_is_equal(left, isl_dim_in, right, isl_dim_in))
1326 isl_die(left->ctx, isl_error_invalid,do { isl_handle_error(left->ctx, isl_error_invalid, "domains need to match"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1327); goto error; } while (0)
1327 "domains need to match", goto error)do { isl_handle_error(left->ctx, isl_error_invalid, "domains need to match"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1327); goto error; } while (0)
;
1328
1329 dom = isl_space_domain(isl_space_copy(left));
1330
1331 ran1 = isl_space_range(left);
1332 ran2 = isl_space_range(right);
1333 nest = isl_space_wrap(isl_space_join(isl_space_reverse(ran1), ran2));
1334
1335 return isl_space_join(isl_space_reverse(dom), nest);
1336error:
1337 isl_space_free(left);
1338 isl_space_free(right);
1339 return NULL((void*)0);
1340}
1341
1342/* Given a space of the form [A -> B] -> C, return the space A -> C.
1343 */
1344__isl_give isl_space *isl_space_domain_factor_domain(
1345 __isl_take isl_space *space)
1346{
1347 isl_space *nested;
1348 isl_space *domain;
1349
1350 if (!space)
1351 return NULL((void*)0);
1352 if (!isl_space_domain_is_wrapping(space))
1353 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1354); return isl_space_free(space); } while (0)
1354 "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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1354); return isl_space_free(space); } while (0)
;
1355
1356 nested = space->nested[0];
1357 domain = isl_space_copy(space);
1358 domain = isl_space_drop_dims(domain, isl_dim_in,
1359 nested->n_in, nested->n_out);
1360 if (!domain)
1361 return isl_space_free(space);
1362 if (nested->tuple_id[0]) {
1363 domain->tuple_id[0] = isl_id_copy(nested->tuple_id[0]);
1364 if (!domain->tuple_id[0])
1365 goto error;
1366 }
1367 if (nested->nested[0]) {
1368 domain->nested[0] = isl_space_copy(nested->nested[0]);
1369 if (!domain->nested[0])
1370 goto error;
1371 }
1372
1373 isl_space_free(space);
1374 return domain;
1375error:
1376 isl_space_free(space);
1377 isl_space_free(domain);
1378 return NULL((void*)0);
1379}
1380
1381/* Given a space of the form [A -> B] -> C, return the space B -> C.
1382 */
1383__isl_give isl_space *isl_space_domain_factor_range(
1384 __isl_take isl_space *space)
1385{
1386 isl_space *nested;
1387 isl_space *range;
1388
1389 if (!space)
1390 return NULL((void*)0);
1391 if (!isl_space_domain_is_wrapping(space))
1392 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1393); return isl_space_free(space); } while (0)
1393 "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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1393); return isl_space_free(space); } while (0)
;
1394
1395 nested = space->nested[0];
1396 range = isl_space_copy(space);
1397 range = isl_space_drop_dims(range, isl_dim_in, 0, nested->n_in);
1398 if (!range)
1399 return isl_space_free(space);
1400 if (nested->tuple_id[1]) {
1401 range->tuple_id[0] = isl_id_copy(nested->tuple_id[1]);
1402 if (!range->tuple_id[0])
1403 goto error;
1404 }
1405 if (nested->nested[1]) {
1406 range->nested[0] = isl_space_copy(nested->nested[1]);
1407 if (!range->nested[0])
1408 goto error;
1409 }
1410
1411 isl_space_free(space);
1412 return range;
1413error:
1414 isl_space_free(space);
1415 isl_space_free(range);
1416 return NULL((void*)0);
1417}
1418
1419/* Internal function that selects the domain of the map that is
1420 * embedded in either a set space or the range of a map space.
1421 * In particular, given a space of the form [A -> B], return the space A.
1422 * Given a space of the form A -> [B -> C], return the space A -> B.
1423 */
1424static __isl_give isl_space *range_factor_domain(__isl_take isl_space *space)
1425{
1426 isl_space *nested;
1427 isl_space *domain;
1428
1429 if (!space)
1430 return NULL((void*)0);
1431
1432 nested = space->nested[1];
1433 domain = isl_space_copy(space);
1434 domain = isl_space_drop_dims(domain, isl_dim_out,
1435 nested->n_in, nested->n_out);
1436 if (!domain)
1437 return isl_space_free(space);
1438 if (nested->tuple_id[0]) {
1439 domain->tuple_id[1] = isl_id_copy(nested->tuple_id[0]);
1440 if (!domain->tuple_id[1])
1441 goto error;
1442 }
1443 if (nested->nested[0]) {
1444 domain->nested[1] = isl_space_copy(nested->nested[0]);
1445 if (!domain->nested[1])
1446 goto error;
1447 }
1448
1449 isl_space_free(space);
1450 return domain;
1451error:
1452 isl_space_free(space);
1453 isl_space_free(domain);
1454 return NULL((void*)0);
1455}
1456
1457/* Given a space of the form A -> [B -> C], return the space A -> B.
1458 */
1459__isl_give isl_space *isl_space_range_factor_domain(
1460 __isl_take isl_space *space)
1461{
1462 if (!space)
1463 return NULL((void*)0);
1464 if (!isl_space_range_is_wrapping(space))
1465 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1466); return isl_space_free(space); } while (0)
1466 "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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1466); return isl_space_free(space); } while (0)
;
1467
1468 return range_factor_domain(space);
1469}
1470
1471/* Given a space of the form [A -> B], return the space A.
1472 */
1473static __isl_give isl_space *set_factor_domain(__isl_take isl_space *space)
1474{
1475 if (!space)
1476 return NULL((void*)0);
1477 if (!isl_space_is_wrapping(space))
1478 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1479); return isl_space_free(space); } while (0)
1479 "not a product", return isl_space_free(space))do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid
, "not a product", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1479); return isl_space_free(space); } while (0)
;
1480
1481 return range_factor_domain(space);
1482}
1483
1484/* Given a space of the form [A -> B] -> [C -> D], return the space A -> C.
1485 * Given a space of the form [A -> B], return the space A.
1486 */
1487__isl_give isl_space *isl_space_factor_domain(__isl_take isl_space *space)
1488{
1489 if (!space)
1490 return NULL((void*)0);
1491 if (isl_space_is_set(space))
1492 return set_factor_domain(space);
1493 space = isl_space_domain_factor_domain(space);
1494 space = isl_space_range_factor_domain(space);
1495 return space;
1496}
1497
1498/* Internal function that selects the range of the map that is
1499 * embedded in either a set space or the range of a map space.
1500 * In particular, given a space of the form [A -> B], return the space B.
1501 * Given a space of the form A -> [B -> C], return the space A -> C.
1502 */
1503static __isl_give isl_space *range_factor_range(__isl_take isl_space *space)
1504{
1505 isl_space *nested;
1506 isl_space *range;
1507
1508 if (!space)
1509 return NULL((void*)0);
1510
1511 nested = space->nested[1];
1512 range = isl_space_copy(space);
1513 range = isl_space_drop_dims(range, isl_dim_out, 0, nested->n_in);
1514 if (!range)
1515 return isl_space_free(space);
1516 if (nested->tuple_id[1]) {
1517 range->tuple_id[1] = isl_id_copy(nested->tuple_id[1]);
1518 if (!range->tuple_id[1])
1519 goto error;
1520 }
1521 if (nested->nested[1]) {
1522 range->nested[1] = isl_space_copy(nested->nested[1]);
1523 if (!range->nested[1])
1524 goto error;
1525 }
1526
1527 isl_space_free(space);
1528 return range;
1529error:
1530 isl_space_free(space);
1531 isl_space_free(range);
1532 return NULL((void*)0);
1533}
1534
1535/* Given a space of the form A -> [B -> C], return the space A -> C.
1536 */
1537__isl_give isl_space *isl_space_range_factor_range(
1538 __isl_take isl_space *space)
1539{
1540 if (!space)
1541 return NULL((void*)0);
1542 if (!isl_space_range_is_wrapping(space))
1543 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1544); return isl_space_free(space); } while (0)
1544 "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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1544); return isl_space_free(space); } while (0)
;
1545
1546 return range_factor_range(space);
1547}
1548
1549/* Given a space of the form [A -> B], return the space B.
1550 */
1551static __isl_give isl_space *set_factor_range(__isl_take isl_space *space)
1552{
1553 if (!space)
1554 return NULL((void*)0);
1555 if (!isl_space_is_wrapping(space))
1556 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1557); return isl_space_free(space); } while (0)
1557 "not a product", return isl_space_free(space))do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid
, "not a product", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1557); return isl_space_free(space); } while (0)
;
1558
1559 return range_factor_range(space);
1560}
1561
1562/* Given a space of the form [A -> B] -> [C -> D], return the space B -> D.
1563 * Given a space of the form [A -> B], return the space B.
1564 */
1565__isl_give isl_space *isl_space_factor_range(__isl_take isl_space *space)
1566{
1567 if (!space)
1568 return NULL((void*)0);
1569 if (isl_space_is_set(space))
1570 return set_factor_range(space);
1571 space = isl_space_domain_factor_range(space);
1572 space = isl_space_range_factor_range(space);
1573 return space;
1574}
1575
1576__isl_give isl_space *isl_space_map_from_set(__isl_take isl_space *space)
1577{
1578 isl_ctx *ctx;
1579 isl_id **ids = NULL((void*)0);
1580 int n_id;
1581
1582 if (!space)
1583 return NULL((void*)0);
1584 ctx = isl_space_get_ctx(space);
1585 if (!isl_space_is_set(space))
1586 isl_die(ctx, isl_error_invalid, "not a set space", goto error)do { isl_handle_error(ctx, isl_error_invalid, "not a set space"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1586); goto error; } while (0)
;
1587 space = isl_space_cow(space);
1588 if (!space)
1589 return NULL((void*)0);
1590 n_id = space->nparam + space->n_out + space->n_out;
1591 if (n_id > 0 && space->ids) {
1592 ids = isl_calloc_array(space->ctx, isl_id *, n_id)((isl_id * *)isl_calloc_or_die(space->ctx, n_id, sizeof(isl_id
*)))
;
1593 if (!ids)
1594 goto error;
1595 get_ids(space, isl_dim_param, 0, space->nparam, ids);
1596 get_ids(space, isl_dim_out, 0, space->n_out,
1597 ids + space->nparam);
1598 }
1599 space->n_in = space->n_out;
1600 if (ids) {
1601 free(space->ids);
1602 space->ids = ids;
1603 space->n_id = n_id;
1604 space = copy_ids(space, isl_dim_out, 0, space, isl_dim_in);
1605 }
1606 isl_id_free(space->tuple_id[0]);
1607 space->tuple_id[0] = isl_id_copy(space->tuple_id[1]);
1608 isl_space_free(space->nested[0]);
1609 space->nested[0] = isl_space_copy(space->nested[1]);
1610 return space;
1611error:
1612 isl_space_free(space);
1613 return NULL((void*)0);
1614}
1615
1616__isl_give isl_space *isl_space_map_from_domain_and_range(
1617 __isl_take isl_space *domain, __isl_take isl_space *range)
1618{
1619 if (!domain || !range)
1620 goto error;
1621 if (!isl_space_is_set(domain))
1622 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1623); goto error; } while (0)
1623 "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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1623); goto error; } while (0)
;
1624 if (!isl_space_is_set(range))
1625 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1626); goto error; } while (0)
1626 "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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1626); goto error; } while (0)
;
1627 return isl_space_join(isl_space_reverse(domain), range);
1628error:
1629 isl_space_free(domain);
1630 isl_space_free(range);
1631 return NULL((void*)0);
1632}
1633
1634static __isl_give isl_space *set_ids(__isl_take isl_space *dim,
1635 enum isl_dim_type type,
1636 unsigned first, unsigned n, __isl_take isl_id **ids)
1637{
1638 int i;
1639
1640 for (i = 0; i < n ; ++i)
1641 dim = set_id(dim, type, first + i, ids[i]);
1642
1643 return dim;
1644}
1645
1646__isl_give isl_space *isl_space_reverse(__isl_take isl_space *dim)
1647{
1648 unsigned t;
1649 isl_space *nested;
1650 isl_id **ids = NULL((void*)0);
1651 isl_id *id;
1652
1653 if (!dim)
1654 return NULL((void*)0);
1655 if (match(dim, isl_dim_in, dim, isl_dim_out))
1656 return dim;
1657
1658 dim = isl_space_cow(dim);
1659 if (!dim)
1660 return NULL((void*)0);
1661
1662 id = dim->tuple_id[0];
1663 dim->tuple_id[0] = dim->tuple_id[1];
1664 dim->tuple_id[1] = id;
1665
1666 nested = dim->nested[0];
1667 dim->nested[0] = dim->nested[1];
1668 dim->nested[1] = nested;
1669
1670 if (dim->ids) {
1671 int n_id = dim->n_in + dim->n_out;
1672 ids = isl_alloc_array(dim->ctx, isl_id *, n_id)((isl_id * *)isl_malloc_or_die(dim->ctx, (n_id)*sizeof(isl_id
*)))
;
1673 if (n_id && !ids)
1674 goto error;
1675 get_ids(dim, isl_dim_in, 0, dim->n_in, ids);
1676 get_ids(dim, isl_dim_out, 0, dim->n_out, ids + dim->n_in);
1677 }
1678
1679 t = dim->n_in;
1680 dim->n_in = dim->n_out;
1681 dim->n_out = t;
1682
1683 if (dim->ids) {
1684 dim = set_ids(dim, isl_dim_out, 0, dim->n_out, ids);
1685 dim = set_ids(dim, isl_dim_in, 0, dim->n_in, ids + dim->n_out);
1686 free(ids);
1687 }
1688
1689 return dim;
1690error:
1691 free(ids);
1692 isl_space_free(dim);
1693 return NULL((void*)0);
1694}
1695
1696__isl_give isl_space *isl_space_drop_dims(__isl_take isl_space *dim,
1697 enum isl_dim_type type, unsigned first, unsigned num)
1698{
1699 int i;
1700
1701 if (!dim)
1702 return NULL((void*)0);
1703
1704 if (num == 0)
1705 return isl_space_reset(dim, type);
1706
1707 if (!valid_dim_type(type))
1708 isl_die(dim->ctx, isl_error_invalid,do { isl_handle_error(dim->ctx, isl_error_invalid, "cannot drop dimensions of specified type"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1709); goto error; } while (0)
1709 "cannot drop dimensions of specified type", goto error)do { isl_handle_error(dim->ctx, isl_error_invalid, "cannot drop dimensions of specified type"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1709); goto error; } while (0)
;
1710
1711 if (first + num > n(dim, type) || first + num < first)
1712 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1713); return isl_space_free(dim); } while (0)
1713 "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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1713); return isl_space_free(dim); } while (0)
;
1714 dim = isl_space_cow(dim);
1715 if (!dim)
1716 goto error;
1717 if (dim->ids) {
1718 dim = extend_ids(dim);
1719 if (!dim)
1720 goto error;
1721 for (i = 0; i < num; ++i)
1722 isl_id_free(get_id(dim, type, first + i));
1723 for (i = first+num; i < n(dim, type); ++i)
1724 set_id(dim, type, i - num, get_id(dim, type, i));
1725 switch (type) {
1726 case isl_dim_param:
1727 get_ids(dim, isl_dim_in, 0, dim->n_in,
1728 dim->ids + offset(dim, isl_dim_in) - num);
1729 case isl_dim_in:
1730 get_ids(dim, isl_dim_out, 0, dim->n_out,
1731 dim->ids + offset(dim, isl_dim_out) - num);
1732 default:
1733 ;
1734 }
1735 dim->n_id -= num;
1736 }
1737 switch (type) {
1738 case isl_dim_param: dim->nparam -= num; break;
1739 case isl_dim_in: dim->n_in -= num; break;
1740 case isl_dim_out: dim->n_out -= num; break;
1741 default: ;
1742 }
1743 dim = isl_space_reset(dim, type);
1744 if (type == isl_dim_param) {
1745 if (dim && dim->nested[0] &&
1746 !(dim->nested[0] = isl_space_drop_dims(dim->nested[0],
1747 isl_dim_param, first, num)))
1748 goto error;
1749 if (dim && dim->nested[1] &&
1750 !(dim->nested[1] = isl_space_drop_dims(dim->nested[1],
1751 isl_dim_param, first, num)))
1752 goto error;
1753 }
1754 return dim;
1755error:
1756 isl_space_free(dim);
1757 return NULL((void*)0);
1758}
1759
1760__isl_give isl_space *isl_space_drop_inputs(__isl_take isl_space *dim,
1761 unsigned first, unsigned n)
1762{
1763 if (!dim)
1764 return NULL((void*)0);
1765 return isl_space_drop_dims(dim, isl_dim_in, first, n);
1766}
1767
1768__isl_give isl_space *isl_space_drop_outputs(__isl_take isl_space *dim,
1769 unsigned first, unsigned n)
1770{
1771 if (!dim)
1772 return NULL((void*)0);
1773 return isl_space_drop_dims(dim, isl_dim_out, first, n);
1774}
1775
1776__isl_give isl_space *isl_space_domain(__isl_take isl_space *space)
1777{
1778 if (!space)
1779 return NULL((void*)0);
1780 space = isl_space_drop_dims(space, isl_dim_out, 0, space->n_out);
1781 space = isl_space_reverse(space);
1782 space = mark_as_set(space);
1783 return space;
1784}
1785
1786__isl_give isl_space *isl_space_from_domain(__isl_take isl_space *dim)
1787{
1788 if (!dim)
1789 return NULL((void*)0);
1790 if (!isl_space_is_set(dim))
1791 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1792); goto error; } while (0)
1792 "not a set space", goto error)do { isl_handle_error(isl_space_get_ctx(dim), isl_error_invalid
, "not a set space", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1792); goto error; } while (0)
;
1793 dim = isl_space_reverse(dim);
1794 dim = isl_space_reset(dim, isl_dim_out);
1795 return dim;
1796error:
1797 isl_space_free(dim);
1798 return NULL((void*)0);
1799}
1800
1801__isl_give isl_space *isl_space_range(__isl_take isl_space *space)
1802{
1803 if (!space)
1804 return NULL((void*)0);
1805 space = isl_space_drop_dims(space, isl_dim_in, 0, space->n_in);
1806 space = mark_as_set(space);
1807 return space;
1808}
1809
1810__isl_give isl_space *isl_space_from_range(__isl_take isl_space *dim)
1811{
1812 if (!dim)
1813 return NULL((void*)0);
1814 if (!isl_space_is_set(dim))
1815 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1816); goto error; } while (0)
1816 "not a set space", goto error)do { isl_handle_error(isl_space_get_ctx(dim), isl_error_invalid
, "not a set space", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1816); goto error; } while (0)
;
1817 return isl_space_reset(dim, isl_dim_in);
1818error:
1819 isl_space_free(dim);
1820 return NULL((void*)0);
1821}
1822
1823/* Given a map space A -> B, return the map space [A -> B] -> A.
1824 */
1825__isl_give isl_space *isl_space_domain_map(__isl_take isl_space *space)
1826{
1827 isl_space *domain;
1828
1829 domain = isl_space_from_range(isl_space_domain(isl_space_copy(space)));
1830 space = isl_space_from_domain(isl_space_wrap(space));
1831 space = isl_space_join(space, domain);
1832
1833 return space;
1834}
1835
1836/* Given a map space A -> B, return the map space [A -> B] -> B.
1837 */
1838__isl_give isl_space *isl_space_range_map(__isl_take isl_space *space)
1839{
1840 isl_space *range;
1841
1842 range = isl_space_from_range(isl_space_range(isl_space_copy(space)));
1843 space = isl_space_from_domain(isl_space_wrap(space));
1844 space = isl_space_join(space, range);
1845
1846 return space;
1847}
1848
1849__isl_give isl_space *isl_space_params(__isl_take isl_space *space)
1850{
1851 if (isl_space_is_params(space))
1852 return space;
1853 space = isl_space_drop_dims(space,
1854 isl_dim_in, 0, isl_space_dim(space, isl_dim_in));
1855 space = isl_space_drop_dims(space,
1856 isl_dim_out, 0, isl_space_dim(space, isl_dim_out));
1857 space = mark_as_params(space);
1858 return space;
1859}
1860
1861__isl_give isl_space *isl_space_set_from_params(__isl_take isl_space *space)
1862{
1863 if (!space)
1864 return NULL((void*)0);
1865 if (!isl_space_is_params(space))
1866 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1867); goto error; } while (0)
1867 "not a parameter space", goto error)do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid
, "not a parameter space", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 1867); goto error; } while (0)
;
1868 return isl_space_reset(space, isl_dim_set);
1869error:
1870 isl_space_free(space);
1871 return NULL((void*)0);
1872}
1873
1874__isl_give isl_space *isl_space_underlying(__isl_take isl_space *dim,
1875 unsigned n_div)
1876{
1877 int i;
1878
1879 if (!dim)
1880 return NULL((void*)0);
1881 if (n_div == 0 &&
1882 dim->nparam == 0 && dim->n_in == 0 && dim->n_id == 0)
1883 return isl_space_reset(isl_space_reset(dim, isl_dim_in), isl_dim_out);
1884 dim = isl_space_cow(dim);
1885 if (!dim)
1886 return NULL((void*)0);
1887 dim->n_out += dim->nparam + dim->n_in + n_div;
1888 dim->nparam = 0;
1889 dim->n_in = 0;
1890
1891 for (i = 0; i < dim->n_id; ++i)
1892 isl_id_free(get_id(dim, isl_dim_out, i));
1893 dim->n_id = 0;
1894 dim = isl_space_reset(dim, isl_dim_in);
1895 dim = isl_space_reset(dim, isl_dim_out);
1896
1897 return dim;
1898}
1899
1900/* Are the two spaces the same, including positions and names of parameters?
1901 */
1902isl_bool isl_space_is_equal(__isl_keep isl_space *space1,
1903 __isl_keep isl_space *space2)
1904{
1905 isl_bool equal;
1906
1907 if (!space1 || !space2)
1908 return isl_bool_error;
1909 if (space1 == space2)
1910 return isl_bool_true;
1911 equal = isl_space_has_equal_params(space1, space2);
1912 if (equal < 0 || !equal)
1913 return equal;
1914 return isl_space_has_equal_tuples(space1, space2);
1915}
1916
1917/* Do the tuples of "space1" correspond to those of the domain of "space2"?
1918 * That is, is "space1" eqaul to the domain of "space2", ignoring parameters.
1919 *
1920 * "space2" is allowed to be a set space, in which case "space1"
1921 * should be a parameter space.
1922 */
1923isl_bool isl_space_has_domain_tuples(__isl_keep isl_space *space1,
1924 __isl_keep isl_space *space2)
1925{
1926 isl_bool is_set;
1927
1928 is_set = isl_space_is_set(space1);
1929 if (is_set < 0 || !is_set)
1930 return is_set;
1931 return isl_space_tuple_is_equal(space1, isl_dim_set,
1932 space2, isl_dim_in);
1933}
1934
1935/* Is space1 equal to the domain of space2?
1936 *
1937 * In the internal version we also allow space2 to be the space of a set,
1938 * provided space1 is a parameter space.
1939 */
1940isl_bool isl_space_is_domain_internal(__isl_keep isl_space *space1,
1941 __isl_keep isl_space *space2)
1942{
1943 isl_bool equal_params;
1944
1945 if (!space1 || !space2)
1946 return isl_bool_error;
1947 equal_params = isl_space_has_equal_params(space1, space2);
1948 if (equal_params < 0 || !equal_params)
1949 return equal_params;
1950 return isl_space_has_domain_tuples(space1, space2);
1951}
1952
1953/* Is space1 equal to the domain of space2?
1954 */
1955isl_bool isl_space_is_domain(__isl_keep isl_space *space1,
1956 __isl_keep isl_space *space2)
1957{
1958 if (!space2)
1959 return isl_bool_error;
1960 if (!isl_space_is_map(space2))
1961 return isl_bool_false;
1962 return isl_space_is_domain_internal(space1, space2);
1963}
1964
1965/* Is space1 equal to the range of space2?
1966 *
1967 * In the internal version, space2 is allowed to be the space of a set,
1968 * in which case it should be equal to space1.
1969 */
1970isl_bool isl_space_is_range_internal(__isl_keep isl_space *space1,
1971 __isl_keep isl_space *space2)
1972{
1973 isl_bool equal_params;
1974
1975 if (!space1 || !space2)
1976 return isl_bool_error;
1977 if (!isl_space_is_set(space1))
1978 return isl_bool_false;
1979 equal_params = isl_space_has_equal_params(space1, space2);
1980 if (equal_params < 0 || !equal_params)
1981 return equal_params;
1982 return isl_space_tuple_is_equal(space1, isl_dim_set,
1983 space2, isl_dim_out);
1984}
1985
1986/* Is space1 equal to the range of space2?
1987 */
1988isl_bool isl_space_is_range(__isl_keep isl_space *space1,
1989 __isl_keep isl_space *space2)
1990{
1991 if (!space2)
1992 return isl_bool_error;
1993 if (!isl_space_is_map(space2))
1994 return isl_bool_false;
1995 return isl_space_is_range_internal(space1, space2);
1996}
1997
1998/* Update "hash" by hashing in the parameters of "space".
1999 */
2000static uint32_t isl_hash_params(uint32_t hash, __isl_keep isl_space *space)
2001{
2002 int i;
2003 isl_id *id;
2004
2005 if (!space)
2006 return hash;
2007
2008 isl_hash_byte(hash, space->nparam % 256)do { hash *= 16777619; hash ^= space->nparam % 256; } while
(0)
;
2009
2010 for (i = 0; i < space->nparam; ++i) {
2011 id = get_id(space, isl_dim_param, i);
2012 hash = isl_hash_id(hash, id);
2013 }
2014
2015 return hash;
2016}
2017
2018/* Update "hash" by hashing in the tuples of "space".
2019 * Changes in this function should be reflected in isl_hash_tuples_domain.
2020 */
2021static uint32_t isl_hash_tuples(uint32_t hash, __isl_keep isl_space *space)
2022{
2023 isl_id *id;
2024
2025 if (!space)
2026 return hash;
2027
2028 isl_hash_byte(hash, space->n_in % 256)do { hash *= 16777619; hash ^= space->n_in % 256; } while(
0)
;
2029 isl_hash_byte(hash, space->n_out % 256)do { hash *= 16777619; hash ^= space->n_out % 256; } while
(0)
;
2030
2031 id = tuple_id(space, isl_dim_in);
2032 hash = isl_hash_id(hash, id);
2033 id = tuple_id(space, isl_dim_out);
2034 hash = isl_hash_id(hash, id);
2035
2036 hash = isl_hash_tuples(hash, space->nested[0]);
2037 hash = isl_hash_tuples(hash, space->nested[1]);
2038
2039 return hash;
2040}
2041
2042/* Update "hash" by hashing in the domain tuple of "space".
2043 * The result of this function is equal to the result of applying
2044 * isl_hash_tuples to the domain of "space".
2045 */
2046static uint32_t isl_hash_tuples_domain(uint32_t hash,
2047 __isl_keep isl_space *space)
2048{
2049 isl_id *id;
2050
2051 if (!space)
2052 return hash;
2053
2054 isl_hash_byte(hash, 0)do { hash *= 16777619; hash ^= 0; } while(0);
2055 isl_hash_byte(hash, space->n_in % 256)do { hash *= 16777619; hash ^= space->n_in % 256; } while(
0)
;
2056
2057 hash = isl_hash_id(hash, &isl_id_none);
2058 id = tuple_id(space, isl_dim_in);
2059 hash = isl_hash_id(hash, id);
2060
2061 hash = isl_hash_tuples(hash, space->nested[0]);
2062
2063 return hash;
2064}
2065
2066/* Return a hash value that digests the tuples of "space",
2067 * i.e., that ignores the parameters.
2068 */
2069uint32_t isl_space_get_tuple_hash(__isl_keep isl_space *space)
2070{
2071 uint32_t hash;
2072
2073 if (!space)
2074 return 0;
2075
2076 hash = isl_hash_init()(2166136261u);
2077 hash = isl_hash_tuples(hash, space);
2078
2079 return hash;
2080}
2081
2082uint32_t isl_space_get_hash(__isl_keep isl_space *space)
2083{
2084 uint32_t hash;
2085
2086 if (!space)
2087 return 0;
2088
2089 hash = isl_hash_init()(2166136261u);
2090 hash = isl_hash_params(hash, space);
2091 hash = isl_hash_tuples(hash, space);
2092
2093 return hash;
2094}
2095
2096/* Return the hash value of the domain of "space".
2097 * That is, isl_space_get_domain_hash(space) is equal to
2098 * isl_space_get_hash(isl_space_domain(space)).
2099 */
2100uint32_t isl_space_get_domain_hash(__isl_keep isl_space *space)
2101{
2102 uint32_t hash;
2103
2104 if (!space)
2105 return 0;
2106
2107 hash = isl_hash_init()(2166136261u);
2108 hash = isl_hash_params(hash, space);
2109 hash = isl_hash_tuples_domain(hash, space);
2110
2111 return hash;
2112}
2113
2114isl_bool isl_space_is_wrapping(__isl_keep isl_space *dim)
2115{
2116 if (!dim)
2117 return isl_bool_error;
2118
2119 if (!isl_space_is_set(dim))
2120 return isl_bool_false;
2121
2122 return dim->nested[1] != NULL((void*)0);
2123}
2124
2125/* Is "space" the space of a map where the domain is a wrapped map space?
2126 */
2127isl_bool isl_space_domain_is_wrapping(__isl_keep isl_space *space)
2128{
2129 if (!space)
2130 return isl_bool_error;
2131
2132 if (isl_space_is_set(space))
2133 return isl_bool_false;
2134
2135 return space->nested[0] != NULL((void*)0);
2136}
2137
2138/* Is "space" the space of a map where the range is a wrapped map space?
2139 */
2140isl_bool isl_space_range_is_wrapping(__isl_keep isl_space *space)
2141{
2142 if (!space)
2143 return isl_bool_error;
2144
2145 if (isl_space_is_set(space))
2146 return isl_bool_false;
2147
2148 return space->nested[1] != NULL((void*)0);
2149}
2150
2151/* Is "space" a product of two spaces?
2152 * That is, is it a wrapping set space or a map space
2153 * with wrapping domain and range?
2154 */
2155isl_bool isl_space_is_product(__isl_keep isl_space *space)
2156{
2157 isl_bool is_set;
2158 isl_bool is_product;
2159
2160 is_set = isl_space_is_set(space);
2161 if (is_set < 0)
2162 return isl_bool_error;
2163 if (is_set)
2164 return isl_space_is_wrapping(space);
2165 is_product = isl_space_domain_is_wrapping(space);
2166 if (is_product < 0 || !is_product)
2167 return is_product;
2168 return isl_space_range_is_wrapping(space);
2169}
2170
2171__isl_give isl_space *isl_space_wrap(__isl_take isl_space *dim)
2172{
2173 isl_space *wrap;
2174
2175 if (!dim)
2176 return NULL((void*)0);
2177
2178 wrap = isl_space_set_alloc(dim->ctx,
2179 dim->nparam, dim->n_in + dim->n_out);
2180
2181 wrap = copy_ids(wrap, isl_dim_param, 0, dim, isl_dim_param);
2182 wrap = copy_ids(wrap, isl_dim_set, 0, dim, isl_dim_in);
2183 wrap = copy_ids(wrap, isl_dim_set, dim->n_in, dim, isl_dim_out);
2184
2185 if (!wrap)
2186 goto error;
2187
2188 wrap->nested[1] = dim;
2189
2190 return wrap;
2191error:
2192 isl_space_free(dim);
2193 return NULL((void*)0);
2194}
2195
2196__isl_give isl_space *isl_space_unwrap(__isl_take isl_space *dim)
2197{
2198 isl_space *unwrap;
2199
2200 if (!dim)
2201 return NULL((void*)0);
2202
2203 if (!isl_space_is_wrapping(dim))
2204 isl_die(dim->ctx, isl_error_invalid, "not a wrapping space",do { isl_handle_error(dim->ctx, isl_error_invalid, "not a wrapping space"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 2205); goto error; } while (0)
2205 goto error)do { isl_handle_error(dim->ctx, isl_error_invalid, "not a wrapping space"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 2205); goto error; } while (0)
;
2206
2207 unwrap = isl_space_copy(dim->nested[1]);
2208 isl_space_free(dim);
2209
2210 return unwrap;
2211error:
2212 isl_space_free(dim);
2213 return NULL((void*)0);
2214}
2215
2216isl_bool isl_space_is_named_or_nested(__isl_keep isl_space *space,
2217 enum isl_dim_type type)
2218{
2219 if (type != isl_dim_in && type != isl_dim_out)
2220 return isl_bool_false;
2221 if (!space)
2222 return isl_bool_error;
2223 if (space->tuple_id[type - isl_dim_in])
2224 return isl_bool_true;
2225 if (space->nested[type - isl_dim_in])
2226 return isl_bool_true;
2227 return isl_bool_false;
2228}
2229
2230isl_bool isl_space_may_be_set(__isl_keep isl_space *space)
2231{
2232 isl_bool nested;
2233
2234 if (!space)
2235 return isl_bool_error;
2236 if (isl_space_is_set(space))
2237 return isl_bool_true;
2238 if (isl_space_dim(space, isl_dim_in) != 0)
2239 return isl_bool_false;
2240 nested = isl_space_is_named_or_nested(space, isl_dim_in);
2241 if (nested < 0 || nested)
2242 return isl_bool_not(nested);
2243 return isl_bool_true;
2244}
2245
2246__isl_give isl_space *isl_space_reset(__isl_take isl_space *dim,
2247 enum isl_dim_type type)
2248{
2249 if (!isl_space_is_named_or_nested(dim, type))
2250 return dim;
2251
2252 dim = isl_space_cow(dim);
2253 if (!dim)
2254 return NULL((void*)0);
2255
2256 isl_id_free(dim->tuple_id[type - isl_dim_in]);
2257 dim->tuple_id[type - isl_dim_in] = NULL((void*)0);
2258 isl_space_free(dim->nested[type - isl_dim_in]);
2259 dim->nested[type - isl_dim_in] = NULL((void*)0);
2260
2261 return dim;
2262}
2263
2264__isl_give isl_space *isl_space_flatten(__isl_take isl_space *dim)
2265{
2266 if (!dim)
2267 return NULL((void*)0);
2268 if (!dim->nested[0] && !dim->nested[1])
2269 return dim;
2270
2271 if (dim->nested[0])
2272 dim = isl_space_reset(dim, isl_dim_in);
2273 if (dim && dim->nested[1])
2274 dim = isl_space_reset(dim, isl_dim_out);
2275
2276 return dim;
2277}
2278
2279__isl_give isl_space *isl_space_flatten_domain(__isl_take isl_space *space)
2280{
2281 if (!space)
2282 return NULL((void*)0);
2283 if (!space->nested[0])
2284 return space;
2285
2286 return isl_space_reset(space, isl_dim_in);
2287}
2288
2289__isl_give isl_space *isl_space_flatten_range(__isl_take isl_space *space)
2290{
2291 if (!space)
2292 return NULL((void*)0);
2293 if (!space->nested[1])
2294 return space;
2295
2296 return isl_space_reset(space, isl_dim_out);
2297}
2298
2299/* Replace the parameters of dst by those of src.
2300 */
2301__isl_give isl_space *isl_space_replace_params(__isl_take isl_space *dst,
2302 __isl_keep isl_space *src)
2303{
2304 isl_bool equal_params;
2305 enum isl_dim_type type = isl_dim_param;
2306
2307 equal_params = isl_space_has_equal_params(dst, src);
2308 if (equal_params < 0)
2309 return isl_space_free(dst);
2310 if (equal_params)
2311 return dst;
2312
2313 dst = isl_space_cow(dst);
2314
2315 if (!dst || !src)
2316 goto error;
2317
2318 dst = isl_space_drop_dims(dst, type, 0, isl_space_dim(dst, type));
2319 dst = isl_space_add_dims(dst, type, isl_space_dim(src, type));
2320 dst = copy_ids(dst, type, 0, src, type);
2321
2322 if (dst) {
2323 int i;
2324 for (i = 0; i <= 1; ++i) {
2325 if (!dst->nested[i])
2326 continue;
2327 dst->nested[i] = isl_space_replace_params(
2328 dst->nested[i], src);
2329 if (!dst->nested[i])
2330 goto error;
2331 }
2332 }
2333
2334 return dst;
2335error:
2336 isl_space_free(dst);
2337 return NULL((void*)0);
2338}
2339
2340/* Given a dimension specification "dim" of a set, create a dimension
2341 * specification for the lift of the set. In particular, the result
2342 * is of the form [dim -> local[..]], with n_local variables in the
2343 * range of the wrapped map.
2344 */
2345__isl_give isl_space *isl_space_lift(__isl_take isl_space *dim, unsigned n_local)
2346{
2347 isl_space *local_dim;
2348
2349 if (!dim)
2350 return NULL((void*)0);
2351
2352 local_dim = isl_space_dup(dim);
2353 local_dim = isl_space_drop_dims(local_dim, isl_dim_set, 0, dim->n_out);
2354 local_dim = isl_space_add_dims(local_dim, isl_dim_set, n_local);
2355 local_dim = isl_space_set_tuple_name(local_dim, isl_dim_set, "local");
2356 dim = isl_space_join(isl_space_from_domain(dim),
2357 isl_space_from_range(local_dim));
2358 dim = isl_space_wrap(dim);
2359 dim = isl_space_set_tuple_name(dim, isl_dim_set, "lifted");
2360
2361 return dim;
2362}
2363
2364isl_bool isl_space_can_zip(__isl_keep isl_space *space)
2365{
2366 isl_bool is_set;
2367
2368 is_set = isl_space_is_set(space);
2369 if (is_set < 0)
2370 return isl_bool_error;
2371 if (is_set)
2372 return isl_bool_false;
2373 return isl_space_is_product(space);
2374}
2375
2376__isl_give isl_space *isl_space_zip(__isl_take isl_space *dim)
2377{
2378 isl_space *dom, *ran;
2379 isl_space *dom_dom, *dom_ran, *ran_dom, *ran_ran;
2380
2381 if (!isl_space_can_zip(dim))
2382 isl_die(dim->ctx, isl_error_invalid, "dim cannot be zipped",do { isl_handle_error(dim->ctx, isl_error_invalid, "dim cannot be zipped"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 2383); goto error; } while (0)
2383 goto error)do { isl_handle_error(dim->ctx, isl_error_invalid, "dim cannot be zipped"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 2383); goto error; } while (0)
;
2384
2385 if (!dim)
2386 return NULL((void*)0);
2387 dom = isl_space_unwrap(isl_space_domain(isl_space_copy(dim)));
2388 ran = isl_space_unwrap(isl_space_range(dim));
2389 dom_dom = isl_space_domain(isl_space_copy(dom));
2390 dom_ran = isl_space_range(dom);
2391 ran_dom = isl_space_domain(isl_space_copy(ran));
2392 ran_ran = isl_space_range(ran);
2393 dom = isl_space_join(isl_space_from_domain(dom_dom),
2394 isl_space_from_range(ran_dom));
2395 ran = isl_space_join(isl_space_from_domain(dom_ran),
2396 isl_space_from_range(ran_ran));
2397 return isl_space_join(isl_space_from_domain(isl_space_wrap(dom)),
2398 isl_space_from_range(isl_space_wrap(ran)));
2399error:
2400 isl_space_free(dim);
2401 return NULL((void*)0);
2402}
2403
2404/* Can we apply isl_space_curry to "space"?
2405 * That is, does it have a nested relation in its domain?
2406 */
2407isl_bool isl_space_can_curry(__isl_keep isl_space *space)
2408{
2409 if (!space)
2410 return isl_bool_error;
2411
2412 return !!space->nested[0];
2413}
2414
2415/* Given a space (A -> B) -> C, return the corresponding space
2416 * A -> (B -> C).
2417 */
2418__isl_give isl_space *isl_space_curry(__isl_take isl_space *space)
2419{
2420 isl_space *dom, *ran;
2421 isl_space *dom_dom, *dom_ran;
2422
2423 if (!space)
2424 return NULL((void*)0);
2425
2426 if (!isl_space_can_curry(space))
2427 isl_die(space->ctx, isl_error_invalid,do { isl_handle_error(space->ctx, isl_error_invalid, "space cannot be curried"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 2428); goto error; } while (0)
2428 "space cannot be curried", goto error)do { isl_handle_error(space->ctx, isl_error_invalid, "space cannot be curried"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 2428); goto error; } while (0)
;
2429
2430 dom = isl_space_unwrap(isl_space_domain(isl_space_copy(space)));
2431 ran = isl_space_range(space);
2432 dom_dom = isl_space_domain(isl_space_copy(dom));
2433 dom_ran = isl_space_range(dom);
2434 ran = isl_space_join(isl_space_from_domain(dom_ran),
2435 isl_space_from_range(ran));
2436 return isl_space_join(isl_space_from_domain(dom_dom),
2437 isl_space_from_range(isl_space_wrap(ran)));
2438error:
2439 isl_space_free(space);
2440 return NULL((void*)0);
2441}
2442
2443/* Can isl_space_range_curry be applied to "space"?
2444 * That is, does it have a nested relation in its range,
2445 * the domain of which is itself a nested relation?
2446 */
2447isl_bool isl_space_can_range_curry(__isl_keep isl_space *space)
2448{
2449 isl_bool can;
2450
2451 if (!space)
2452 return isl_bool_error;
2453 can = isl_space_range_is_wrapping(space);
2454 if (can < 0 || !can)
2455 return can;
2456 return isl_space_can_curry(space->nested[1]);
2457}
2458
2459/* Given a space A -> ((B -> C) -> D), return the corresponding space
2460 * A -> (B -> (C -> D)).
2461 */
2462__isl_give isl_space *isl_space_range_curry(__isl_take isl_space *space)
2463{
2464 if (!space)
2465 return NULL((void*)0);
2466
2467 if (!isl_space_can_range_curry(space))
2468 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", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 2470); return isl_space_free(space); } while (0)
2469 "space range cannot be curried",do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid
, "space range cannot be curried", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 2470); return isl_space_free(space); } while (0)
2470 return isl_space_free(space))do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid
, "space range cannot be curried", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 2470); return isl_space_free(space); } while (0)
;
2471
2472 space = isl_space_cow(space);
2473 if (!space)
2474 return NULL((void*)0);
2475 space->nested[1] = isl_space_curry(space->nested[1]);
2476 if (!space->nested[1])
2477 return isl_space_free(space);
2478
2479 return space;
2480}
2481
2482/* Can we apply isl_space_uncurry to "space"?
2483 * That is, does it have a nested relation in its range?
2484 */
2485isl_bool isl_space_can_uncurry(__isl_keep isl_space *space)
2486{
2487 if (!space)
2488 return isl_bool_error;
2489
2490 return !!space->nested[1];
2491}
2492
2493/* Given a space A -> (B -> C), return the corresponding space
2494 * (A -> B) -> C.
2495 */
2496__isl_give isl_space *isl_space_uncurry(__isl_take isl_space *space)
2497{
2498 isl_space *dom, *ran;
2499 isl_space *ran_dom, *ran_ran;
2500
2501 if (!space)
2502 return NULL((void*)0);
2503
2504 if (!isl_space_can_uncurry(space))
2505 isl_die(space->ctx, isl_error_invalid,do { isl_handle_error(space->ctx, isl_error_invalid, "space cannot be uncurried"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 2507); return isl_space_free(space); } while (0)
2506 "space cannot be uncurried",do { isl_handle_error(space->ctx, isl_error_invalid, "space cannot be uncurried"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 2507); return isl_space_free(space); } while (0)
2507 return isl_space_free(space))do { isl_handle_error(space->ctx, isl_error_invalid, "space cannot be uncurried"
, "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 2507); return isl_space_free(space); } while (0)
;
2508
2509 dom = isl_space_domain(isl_space_copy(space));
2510 ran = isl_space_unwrap(isl_space_range(space));
2511 ran_dom = isl_space_domain(isl_space_copy(ran));
2512 ran_ran = isl_space_range(ran);
2513 dom = isl_space_join(isl_space_from_domain(dom),
2514 isl_space_from_range(ran_dom));
2515 return isl_space_join(isl_space_from_domain(isl_space_wrap(dom)),
2516 isl_space_from_range(ran_ran));
2517}
2518
2519isl_bool isl_space_has_named_params(__isl_keep isl_space *space)
2520{
2521 int i;
2522 unsigned off;
2523
2524 if (!space)
2525 return isl_bool_error;
2526 if (space->nparam == 0)
2527 return isl_bool_true;
2528 off = isl_space_offset(space, isl_dim_param);
2529 if (off + space->nparam > space->n_id)
2530 return isl_bool_false;
2531 for (i = 0; i < space->nparam; ++i)
2532 if (!space->ids[off + i])
2533 return isl_bool_false;
2534 return isl_bool_true;
2535}
2536
2537/* Check that "space" has only named parameters, reporting an error
2538 * if it does not.
2539 */
2540isl_stat isl_space_check_named_params(__isl_keep isl_space *space)
2541{
2542 isl_bool named;
2543
2544 named = isl_space_has_named_params(space);
2545 if (named < 0)
2546 return isl_stat_error;
2547 if (!named)
2548 isl_die(isl_space_get_ctx(space), isl_error_invalid,do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid
, "unexpected unnamed parameters", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 2549); return isl_stat_error; } while (0)
2549 "unexpected unnamed parameters", return isl_stat_error)do { isl_handle_error(isl_space_get_ctx(space), isl_error_invalid
, "unexpected unnamed parameters", "/build/llvm-toolchain-snapshot-7~svn338205/tools/polly/lib/External/isl/isl_space.c"
, 2549); return isl_stat_error; } while (0)
;
2550
2551 return isl_stat_ok;
2552}
2553
2554/* Align the initial parameters of space1 to match the order in space2.
2555 */
2556__isl_give isl_space *isl_space_align_params(__isl_take isl_space *space1,
2557 __isl_take isl_space *space2)
2558{
2559 isl_reordering *exp;
2560
2561 if (isl_space_check_named_params(space1) < 0 ||
2562 isl_space_check_named_params(space2) < 0)
2563 goto error;
2564
2565 exp = isl_parameter_alignment_reordering(space1, space2);
2566 exp = isl_reordering_extend_space(exp, space1);
2567 isl_space_free(space2);
2568 space1 = isl_reordering_get_space(exp);
2569 isl_reordering_free(exp);
2570 return space1;
2571error:
2572 isl_space_free(space1);
2573 isl_space_free(space2);
2574 return NULL((void*)0);
2575}
2576
2577/* Given the space of set (domain), construct a space for a map
2578 * with as domain the given space and as range the range of "model".
2579 */
2580__isl_give isl_space *isl_space_extend_domain_with_range(
2581 __isl_take isl_space *space, __isl_take isl_space *model)
2582{
2583 if (!model)
2584 goto error;
2585
2586 space = isl_space_from_domain(space);
2587 space = isl_space_add_dims(space, isl_dim_out,
2588 isl_space_dim(model, isl_dim_out));
2589 if (isl_space_has_tuple_id(model, isl_dim_out))
2590 space = isl_space_set_tuple_id(space, isl_dim_out,
2591 isl_space_get_tuple_id(model, isl_dim_out));
2592 if (!space)
2593 goto error;
2594 if (model->nested[1]) {
2595 isl_space *nested = isl_space_copy(model->nested[1]);
2596 int n_nested, n_space;
2597 nested = isl_space_align_params(nested, isl_space_copy(space));
2598 n_nested = isl_space_dim(nested, isl_dim_param);
2599 n_space = isl_space_dim(space, isl_dim_param);
2600 if (n_nested > n_space)
2601 nested = isl_space_drop_dims(nested, isl_dim_param,
2602 n_space, n_nested - n_space);
2603 if (!nested)
2604 goto error;
2605 space->nested[1] = nested;
2606 }
2607 isl_space_free(model);
2608 return space;
2609error:
2610 isl_space_free(model);
2611 isl_space_free(space);
2612 return NULL((void*)0);
2613}
2614
2615/* Compare the "type" dimensions of two isl_spaces.
2616 *
2617 * The order is fairly arbitrary.
2618 */
2619static int isl_space_cmp_type(__isl_keep isl_space *space1,
2620 __isl_keep isl_space *space2, enum isl_dim_type type)
2621{
2622 int cmp;
2623 isl_space *nested1, *nested2;
2624
2625 if (isl_space_dim(space1, type) != isl_space_dim(space2, type))
1
Assuming the condition is false
2
Taking false branch
15
Calling 'isl_space_dim'
22
Returning from 'isl_space_dim'
23
Assuming the condition is false
24
Taking false branch
45
Calling 'isl_space_dim'
52
Returning from 'isl_space_dim'
53
Assuming the condition is false
54
Taking false branch
75
Calling 'isl_space_dim'
82
Returning from 'isl_space_dim'
83
Assuming the condition is true
84
Taking true branch
2626 return isl_space_dim(space1, type) -
85
Calling 'isl_space_dim'
92
Returning from 'isl_space_dim'
93
Returning without writing to 'space1->ids'
2627 isl_space_dim(space2, type);
2628
2629 cmp = isl_id_cmp(tuple_id(space1, type), tuple_id(space2, type));
25
Calling 'tuple_id'
30
Returning from 'tuple_id'
55
Calling 'tuple_id'
59
Returning from 'tuple_id'
2630 if (cmp != 0)
3
Assuming 'cmp' is equal to 0
4
Taking false branch
31
Assuming 'cmp' is equal to 0
32
Taking false branch
60
Assuming 'cmp' is equal to 0
61
Taking false branch
2631 return cmp;
2632
2633 nested1 = nested(space1, type);
33
Calling 'nested'
38
Returning from 'nested'
62
Calling 'nested'
66
Returning from 'nested'
2634 nested2 = nested(space2, type);
2635 if (!nested1 != !nested2)
5
Assuming 'nested1' is non-null
6
Assuming 'nested2' is non-null
7
Taking false branch
39
Taking false branch
67
Assuming 'nested1' is non-null
68
Assuming 'nested2' is non-null
69
Taking false branch
2636 return !nested1 - !nested2;
2637
2638 if (nested1)
8
Taking true branch
40
Taking false branch
70
Taking true branch
2639 return isl_space_cmp(nested1, nested2);
9
Calling 'isl_space_cmp'
71
Returning without writing to 'space1->ids'
2640
2641 return 0;
41
Returning without writing to 'space1->ids'
2642}
2643
2644/* Compare two isl_spaces.
2645 *
2646 * The order is fairly arbitrary.
2647 */
2648int isl_space_cmp(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
2649{
2650 int i;
2651 int cmp;
2652
2653 if (space1 == space2)
10
Assuming 'space1' is not equal to 'space2'
11
Taking false branch
2654 return 0;
2655 if (!space1)
12
Taking false branch
2656 return -1;
2657 if (!space2)
13
Taking false branch
2658 return 1;
2659
2660 cmp = isl_space_cmp_type(space1, space2, isl_dim_param);
14
Calling 'isl_space_cmp_type'
42
Returning from 'isl_space_cmp_type'
2661 if (cmp != 0)
43
Taking false branch
2662 return cmp;
2663 cmp = isl_space_cmp_type(space1, space2, isl_dim_in);
44
Calling 'isl_space_cmp_type'
72
Returning from 'isl_space_cmp_type'
2664 if (cmp != 0)
73
Taking false branch
2665 return cmp;
2666 cmp = isl_space_cmp_type(space1, space2, isl_dim_out);
74
Calling 'isl_space_cmp_type'
94
Returning from 'isl_space_cmp_type'
2667 if (cmp != 0)
95
Assuming 'cmp' is equal to 0
96
Taking false branch
2668 return cmp;
2669
2670 if (!space1->ids && !space2->ids)
97
Assuming pointer value is null
98
Assuming the condition is false
99
Taking false branch
2671 return 0;
2672
2673 for (i = 0; i < n(space1, isl_dim_param); ++i) {
100
Calling 'n'
103
Returning from 'n'
104
Assuming the condition is true
105
Loop condition is true. Entering loop body
2674 cmp = isl_id_cmp(get_id(space1, isl_dim_param, i),
106
Calling 'get_id'
2675 get_id(space2, isl_dim_param, i));
2676 if (cmp != 0)
2677 return cmp;
2678 }
2679
2680 return 0;
2681}