Bug Summary

File:polly/lib/External/isl/isl_multi_templ.c
Warning:line 167, column 2
Value stored to 'ctx' is never read

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_val.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -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 -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=none -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-11/lib/clang/11.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/tools/polly/lib/External -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/pet/include -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/ppcg/include -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/ppcg/imath -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/tools/polly/lib/External/ppcg -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/include -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/imath -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/tools/polly/lib/External/isl -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/tools/polly/include -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/tools/polly/lib/External/isl/include -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/include -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/include -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include -U NDEBUG -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-11/lib/clang/11.0.0/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-11~++20200309111110+2c36c23f347/build-llvm/tools/polly/lib/External -fdebug-prefix-map=/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347=. -ferror-limit 19 -fmessage-length 0 -stack-protector 2 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -o /tmp/scan-build-2020-03-09-184146-41876-1 -x c /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_val.c
1/*
2 * Copyright 2011 Sven Verdoolaege
3 * Copyright 2012-2014 Ecole Normale Superieure
4 *
5 * Use of this software is governed by the MIT license
6 *
7 * Written by Sven Verdoolaege,
8 * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
9 */
10
11#include <isl/id.h>
12#include <isl_space_private.h>
13#include <isl/set.h>
14#include <isl_reordering.h>
15
16#include <isl_multi_macro.h>
17
18#define MULTI_NAME(BASE)"isl_multi_" "BASE" "isl_multi_" #BASEval
19
20isl_ctx *FN(MULTI(BASE),get_ctx)isl_multi_val_get_ctx(__isl_keep MULTI(BASE)isl_multi_val *multi)
21{
22 return multi ? isl_space_get_ctx(multi->space) : NULL((void*)0);
23}
24
25/* Return the space of "multi".
26 */
27__isl_keep isl_space *FN(MULTI(BASE),peek_space)isl_multi_val_peek_space(__isl_keep MULTI(BASE)isl_multi_val *multi)
28{
29 return multi ? multi->space : NULL((void*)0);
30}
31
32__isl_give isl_space *FN(MULTI(BASE),get_space)isl_multi_val_get_space(__isl_keep MULTI(BASE)isl_multi_val *multi)
33{
34 return isl_space_copy(FN(MULTI(BASE),peek_space)isl_multi_val_peek_space(multi));
35}
36
37__isl_give isl_space *FN(MULTI(BASE),get_domain_space)isl_multi_val_get_domain_space(
38 __isl_keep MULTI(BASE)isl_multi_val *multi)
39{
40 return multi ? isl_space_domain(isl_space_copy(multi->space)) : NULL((void*)0);
41}
42
43/* Allocate a multi expression living in "space".
44 *
45 * If the number of base expressions is zero, then make sure
46 * there is enough room in the structure for the explicit domain,
47 * in case the type supports such an explicit domain.
48 */
49__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),alloc)isl_multi_val_alloc(__isl_take isl_space *space)
50{
51 isl_ctx *ctx;
52 isl_size n;
53 MULTI(BASE)isl_multi_val *multi;
54
55 n = isl_space_dim(space, isl_dim_out);
56 if (n < 0)
57 goto error;
58
59 ctx = isl_space_get_ctx(space);
60 if (n > 0)
61 multi = isl_calloc(ctx, MULTI(BASE),((isl_multi_val *)isl_calloc_or_die(ctx, 1, sizeof(isl_multi_val
) + (n - 1) * sizeof(struct isl_val *)))
62 sizeof(MULTI(BASE)) + (n - 1) * sizeof(struct EL *))((isl_multi_val *)isl_calloc_or_die(ctx, 1, sizeof(isl_multi_val
) + (n - 1) * sizeof(struct isl_val *)))
;
63 else
64 multi = isl_calloc(ctx, MULTI(BASE), sizeof(MULTI(BASE)))((isl_multi_val *)isl_calloc_or_die(ctx, 1, sizeof(isl_multi_val
)))
;
65 if (!multi)
66 goto error;
67
68 multi->space = space;
69 multi->n = n;
70 multi->ref = 1;
71 if (FN(MULTI(BASE),has_explicit_domain)isl_multi_val_has_explicit_domain(multi))
72 multi = FN(MULTI(BASE),init_explicit_domain)isl_multi_val_init_explicit_domain(multi);
73 return multi;
74error:
75 isl_space_free(space);
76 return NULL((void*)0);
77}
78
79__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),dup)isl_multi_val_dup(__isl_keep MULTI(BASE)isl_multi_val *multi)
80{
81 int i;
82 MULTI(BASE)isl_multi_val *dup;
83
84 if (!multi)
85 return NULL((void*)0);
86
87 dup = FN(MULTI(BASE),alloc)isl_multi_val_alloc(isl_space_copy(multi->space));
88 if (!dup)
89 return NULL((void*)0);
90
91 for (i = 0; i < multi->n; ++i)
92 dup = FN(FN(MULTI(BASE),set),BASE)isl_multi_val_set_val(dup, i,
93 FN(EL,copy)isl_val_copy(multi->u.p[i]));
94 if (FN(MULTI(BASE),has_explicit_domain)isl_multi_val_has_explicit_domain(multi))
95 dup = FN(MULTI(BASE),copy_explicit_domain)isl_multi_val_copy_explicit_domain(dup, multi);
96
97 return dup;
98}
99
100__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),cow)isl_multi_val_cow(__isl_take MULTI(BASE)isl_multi_val *multi)
101{
102 if (!multi)
103 return NULL((void*)0);
104
105 if (multi->ref == 1)
106 return multi;
107
108 multi->ref--;
109 return FN(MULTI(BASE),dup)isl_multi_val_dup(multi);
110}
111
112__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),copy)isl_multi_val_copy(__isl_keep MULTI(BASE)isl_multi_val *multi)
113{
114 if (!multi)
115 return NULL((void*)0);
116
117 multi->ref++;
118 return multi;
119}
120
121__isl_null MULTI(BASE)isl_multi_val *FN(MULTI(BASE),free)isl_multi_val_free(__isl_take MULTI(BASE)isl_multi_val *multi)
122{
123 int i;
124
125 if (!multi)
126 return NULL((void*)0);
127
128 if (--multi->ref > 0)
129 return NULL((void*)0);
130
131 isl_space_free(multi->space);
132 for (i = 0; i < multi->n; ++i)
133 FN(EL,free)isl_val_free(multi->u.p[i]);
134 if (FN(MULTI(BASE),has_explicit_domain)isl_multi_val_has_explicit_domain(multi))
135 FN(MULTI(BASE),free_explicit_domain)isl_multi_val_free_explicit_domain(multi);
136 free(multi);
137
138 return NULL((void*)0);
139}
140
141isl_size FN(MULTI(BASE),dim)isl_multi_val_dim(__isl_keep MULTI(BASE)isl_multi_val *multi,
142 enum isl_dim_type type)
143{
144 return isl_space_dim(FN(MULTI(BASE),peek_space)isl_multi_val_peek_space(multi), type);
145}
146
147/* Return the number of base expressions in "multi".
148 */
149isl_size FN(MULTI(BASE),size)isl_multi_val_size(__isl_keep MULTI(BASE)isl_multi_val *multi)
150{
151 return multi ? multi->n : isl_size_error((int) -1);
152}
153
154#undef TYPEisl_multi_val
155#define TYPEisl_multi_val MULTI(BASE)isl_multi_val
156static
157#include "check_type_range_templ.c"
158
159/* Return a copy of the base expression at position "pos" in "multi".
160 */
161__isl_give ELisl_val *FN(MULTI(BASE),get_at)isl_multi_val_get_at(__isl_keep MULTI(BASE)isl_multi_val *multi, int pos)
162{
163 isl_ctx *ctx;
164
165 if (FN(MULTI(BASE),check_range)isl_multi_val_check_range(multi, isl_dim_out, pos, 1) < 0)
166 return NULL((void*)0);
167 ctx = FN(MULTI(BASE),get_ctx)isl_multi_val_get_ctx(multi);
Value stored to 'ctx' is never read
168 return FN(EL,copy)isl_val_copy(multi->u.p[pos]);
169}
170
171/* This is an alternative name for the function above.
172 */
173__isl_give ELisl_val *FN(FN(MULTI(BASE),get),BASE)isl_multi_val_get_val(__isl_keep MULTI(BASE)isl_multi_val *multi,
174 int pos)
175{
176 return FN(MULTI(BASE),get_at)isl_multi_val_get_at(multi, pos);
177}
178
179/* Set the element at position "pos" of "multi" to "el",
180 * where the position may be empty if "multi" has only a single reference.
181 */
182static __isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),restore)isl_multi_val_restore(
183 __isl_take MULTI(BASE)isl_multi_val *multi, int pos, __isl_take ELisl_val *el)
184{
185 multi = FN(MULTI(BASE),cow)isl_multi_val_cow(multi);
186 if (!multi || !el)
187 goto error;
188
189 if (FN(MULTI(BASE),check_range)isl_multi_val_check_range(multi, isl_dim_out, pos, 1) < 0)
190 goto error;
191
192 FN(EL,free)isl_val_free(multi->u.p[pos]);
193 multi->u.p[pos] = el;
194
195 return multi;
196error:
197 FN(MULTI(BASE),free)isl_multi_val_free(multi);
198 FN(EL,free)isl_val_free(el);
199 return NULL((void*)0);
200}
201
202/* Set the element at position "pos" of "multi" to "el",
203 * where the position may be empty if "multi" has only a single reference.
204 * However, the space of "multi" is available and is checked
205 * for compatibility with "el".
206 */
207static __isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),restore_check_space)isl_multi_val_restore_check_space(
208 __isl_take MULTI(BASE)isl_multi_val *multi, int pos, __isl_take ELisl_val *el)
209{
210 isl_space *space;
211
212 space = FN(MULTI(BASE),peek_space)isl_multi_val_peek_space(multi);
213 if (FN(EL,check_match_domain_space)isl_val_check_match_domain_space(el, space) < 0)
214 multi = FN(MULTI(BASE),free)isl_multi_val_free(multi);
215 return FN(MULTI(BASE),restore)isl_multi_val_restore(multi, pos, el);
216}
217
218/* Replace the base expression at position "pos" in "multi" with "el".
219 */
220__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),set_at)isl_multi_val_set_at(
221 __isl_take MULTI(BASE)isl_multi_val *multi, int pos, __isl_take ELisl_val *el)
222{
223 isl_space *multi_space = NULL((void*)0);
224 isl_space *el_space = NULL((void*)0);
225 isl_bool match;
226
227 multi_space = FN(MULTI(BASE),get_space)isl_multi_val_get_space(multi);
228 match = FN(EL,matching_params)isl_val_matching_params(el, multi_space);
229 if (match < 0)
230 goto error;
231 if (!match) {
232 multi = FN(MULTI(BASE),align_params)isl_multi_val_align_params(multi,
233 FN(EL,get_space)isl_val_get_space(el));
234 isl_space_free(multi_space);
235 multi_space = FN(MULTI(BASE),get_space)isl_multi_val_get_space(multi);
236 el = FN(EL,align_params)isl_val_align_params(el, isl_space_copy(multi_space));
237 }
238
239 multi = FN(MULTI(BASE),restore_check_space)isl_multi_val_restore_check_space(multi, pos, el);
240
241 isl_space_free(multi_space);
242 isl_space_free(el_space);
243
244 return multi;
245error:
246 FN(MULTI(BASE),free)isl_multi_val_free(multi);
247 FN(EL,free)isl_val_free(el);
248 isl_space_free(multi_space);
249 isl_space_free(el_space);
250 return NULL((void*)0);
251}
252
253/* This is an alternative name for the function above.
254 */
255__isl_give MULTI(BASE)isl_multi_val *FN(FN(MULTI(BASE),set),BASE)isl_multi_val_set_val(
256 __isl_take MULTI(BASE)isl_multi_val *multi, int pos, __isl_take ELisl_val *el)
257{
258 return FN(MULTI(BASE),set_at)isl_multi_val_set_at(multi, pos, el);
259}
260
261/* Reset the space of "multi". This function is called from isl_pw_templ.c
262 * and doesn't know if the space of an element object is represented
263 * directly or through its domain. It therefore passes along both,
264 * which we pass along to the element function since we don't know how
265 * that is represented either.
266 *
267 * If "multi" has an explicit domain, then the caller is expected
268 * to make sure that any modification that would change the dimensions
269 * of the explicit domain has bee applied before this function is called.
270 */
271__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),reset_space_and_domain)isl_multi_val_reset_space_and_domain(
272 __isl_take MULTI(BASE)isl_multi_val *multi, __isl_take isl_space *space,
273 __isl_take isl_space *domain)
274{
275 int i;
276
277 multi = FN(MULTI(BASE),cow)isl_multi_val_cow(multi);
278 if (!multi || !space || !domain)
279 goto error;
280
281 for (i = 0; i < multi->n; ++i) {
282 multi->u.p[i] = FN(EL,reset_domain_space)isl_val_reset_domain_space(multi->u.p[i],
283 isl_space_copy(domain));
284 if (!multi->u.p[i])
285 goto error;
286 }
287 if (FN(MULTI(BASE),has_explicit_domain)isl_multi_val_has_explicit_domain(multi)) {
288 multi = FN(MULTI(BASE),reset_explicit_domain_space)isl_multi_val_reset_explicit_domain_space(multi,
289 isl_space_copy(domain));
290 if (!multi)
291 goto error;
292 }
293 isl_space_free(domain);
294 isl_space_free(multi->space);
295 multi->space = space;
296
297 return multi;
298error:
299 isl_space_free(domain);
300 isl_space_free(space);
301 FN(MULTI(BASE),free)isl_multi_val_free(multi);
302 return NULL((void*)0);
303}
304
305__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),reset_domain_space)isl_multi_val_reset_domain_space(
306 __isl_take MULTI(BASE)isl_multi_val *multi, __isl_take isl_space *domain)
307{
308 isl_space *space;
309
310 space = isl_space_extend_domain_with_range(isl_space_copy(domain),
311 isl_space_copy(multi->space));
312 return FN(MULTI(BASE),reset_space_and_domain)isl_multi_val_reset_space_and_domain(multi, space, domain);
313}
314
315__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),reset_space)isl_multi_val_reset_space(
316 __isl_take MULTI(BASE)isl_multi_val *multi, __isl_take isl_space *space)
317{
318 isl_space *domain;
319
320 domain = isl_space_domain(isl_space_copy(space));
321 return FN(MULTI(BASE),reset_space_and_domain)isl_multi_val_reset_space_and_domain(multi, space, domain);
322}
323
324/* Reset the user pointer on all identifiers of parameters and tuples
325 * of the space of "multi".
326 */
327__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),reset_user)isl_multi_val_reset_user(
328 __isl_take MULTI(BASE)isl_multi_val *multi)
329{
330 isl_space *space;
331
332 space = FN(MULTI(BASE),get_space)isl_multi_val_get_space(multi);
333 space = isl_space_reset_user(space);
334
335 return FN(MULTI(BASE),reset_space)isl_multi_val_reset_space(multi, space);
336}
337
338__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),realign_domain)isl_multi_val_realign_domain(
339 __isl_take MULTI(BASE)isl_multi_val *multi, __isl_take isl_reordering *exp)
340{
341 int i;
342 isl_space *space;
343
344 multi = FN(MULTI(BASE),cow)isl_multi_val_cow(multi);
345 if (!multi || !exp)
346 goto error;
347
348 for (i = 0; i < multi->n; ++i) {
349 multi->u.p[i] = FN(EL,realign_domain)isl_val_realign_domain(multi->u.p[i],
350 isl_reordering_copy(exp));
351 if (!multi->u.p[i])
352 goto error;
353 }
354
355 space = isl_reordering_get_space(exp);
356 multi = FN(MULTI(BASE),reset_domain_space)isl_multi_val_reset_domain_space(multi, space);
357
358 isl_reordering_free(exp);
359 return multi;
360error:
361 isl_reordering_free(exp);
362 FN(MULTI(BASE),free)isl_multi_val_free(multi);
363 return NULL((void*)0);
364}
365
366/* Align the parameters of "multi" to those of "model".
367 *
368 * If "multi" has an explicit domain, then align the parameters
369 * of the domain first.
370 */
371__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),align_params)isl_multi_val_align_params(
372 __isl_take MULTI(BASE)isl_multi_val *multi, __isl_take isl_space *model)
373{
374 isl_ctx *ctx;
375 isl_bool equal_params;
376 isl_reordering *exp;
377
378 if (!multi || !model)
379 goto error;
380
381 equal_params = isl_space_has_equal_params(multi->space, model);
382 if (equal_params < 0)
383 goto error;
384 if (equal_params) {
385 isl_space_free(model);
386 return multi;
387 }
388
389 ctx = isl_space_get_ctx(model);
390 if (!isl_space_has_named_params(model))
391 isl_die(ctx, isl_error_invalid,do { isl_handle_error(ctx, isl_error_invalid, "model has unnamed parameters"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_multi_templ.c"
, 392); goto error; } while (0)
392 "model has unnamed parameters", goto error)do { isl_handle_error(ctx, isl_error_invalid, "model has unnamed parameters"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_multi_templ.c"
, 392); goto error; } while (0)
;
393 if (!isl_space_has_named_params(multi->space))
394 isl_die(ctx, isl_error_invalid,do { isl_handle_error(ctx, isl_error_invalid, "input has unnamed parameters"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_multi_templ.c"
, 395); goto error; } while (0)
395 "input has unnamed parameters", goto error)do { isl_handle_error(ctx, isl_error_invalid, "input has unnamed parameters"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_multi_templ.c"
, 395); goto error; } while (0)
;
396
397 if (FN(MULTI(BASE),has_explicit_domain)isl_multi_val_has_explicit_domain(multi)) {
398 multi = FN(MULTI(BASE),align_explicit_domain_params)isl_multi_val_align_explicit_domain_params(multi,
399 isl_space_copy(model));
400 if (!multi)
401 goto error;
402 }
403 exp = isl_parameter_alignment_reordering(multi->space, model);
404 exp = isl_reordering_extend_space(exp,
405 FN(MULTI(BASE),get_domain_space)isl_multi_val_get_domain_space(multi));
406 multi = FN(MULTI(BASE),realign_domain)isl_multi_val_realign_domain(multi, exp);
407
408 isl_space_free(model);
409 return multi;
410error:
411 isl_space_free(model);
412 FN(MULTI(BASE),free)isl_multi_val_free(multi);
413 return NULL((void*)0);
414}
415
416/* Create a multi expression in the given space with the elements of "list"
417 * as base expressions.
418 *
419 * Since isl_multi_*_restore_* assumes that the element and
420 * the multi expression have matching spaces, the alignment
421 * (if any) needs to be performed beforehand.
422 */
423__isl_give MULTI(BASE)isl_multi_val *FN(FN(MULTI(BASE),from),LIST(BASE))isl_multi_val_from_val_list(
424 __isl_take isl_space *space, __isl_take LIST(EL)isl_val_list *list)
425{
426 int i;
427 isl_size n, dim;
428 isl_ctx *ctx;
429 MULTI(BASE)isl_multi_val *multi;
430
431 dim = isl_space_dim(space, isl_dim_out);
432 n = FN(FN(LIST(EL),n),BASE)isl_val_list_n_val(list);
433 if (dim < 0 || n < 0)
434 goto error;
435
436 ctx = isl_space_get_ctx(space);
437 if (n != dim)
438 isl_die(ctx, isl_error_invalid,do { isl_handle_error(ctx, isl_error_invalid, "invalid number of elements in list"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_multi_templ.c"
, 439); goto error; } while (0)
439 "invalid number of elements in list", goto error)do { isl_handle_error(ctx, isl_error_invalid, "invalid number of elements in list"
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_multi_templ.c"
, 439); goto error; } while (0)
;
440
441 for (i = 0; i < n; ++i) {
442 ELisl_val *el = FN(LIST(EL),peek)isl_val_list_peek(list, i);
443 space = isl_space_align_params(space, FN(EL,get_space)isl_val_get_space(el));
444 }
445 multi = FN(MULTI(BASE),alloc)isl_multi_val_alloc(isl_space_copy(space));
446 for (i = 0; i < n; ++i) {
447 ELisl_val *el = FN(FN(LIST(EL),get),BASE)isl_val_list_get_val(list, i);
448 el = FN(EL,align_params)isl_val_align_params(el, isl_space_copy(space));
449 multi = FN(MULTI(BASE),restore_check_space)isl_multi_val_restore_check_space(multi, i, el);
450 }
451
452 isl_space_free(space);
453 FN(LIST(EL),free)isl_val_list_free(list);
454 return multi;
455error:
456 isl_space_free(space);
457 FN(LIST(EL),free)isl_val_list_free(list);
458 return NULL((void*)0);
459}
460
461__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),drop_dims)isl_multi_val_drop_dims(
462 __isl_take MULTI(BASE)isl_multi_val *multi,
463 enum isl_dim_type type, unsigned first, unsigned n)
464{
465 int i;
466
467 multi = FN(MULTI(BASE),cow)isl_multi_val_cow(multi);
468 if (FN(MULTI(BASE),check_range)isl_multi_val_check_range(multi, type, first, n) < 0)
469 return FN(MULTI(BASE),free)isl_multi_val_free(multi);
470
471 multi->space = isl_space_drop_dims(multi->space, type, first, n);
472 if (!multi->space)
473 return FN(MULTI(BASE),free)isl_multi_val_free(multi);
474
475 if (type == isl_dim_out) {
476 for (i = 0; i < n; ++i)
477 FN(EL,free)isl_val_free(multi->u.p[first + i]);
478 for (i = first; i + n < multi->n; ++i)
479 multi->u.p[i] = multi->u.p[i + n];
480 multi->n -= n;
481 if (n > 0 && FN(MULTI(BASE),has_explicit_domain)isl_multi_val_has_explicit_domain(multi))
482 multi = FN(MULTI(BASE),init_explicit_domain)isl_multi_val_init_explicit_domain(multi);
483
484 return multi;
485 }
486
487 if (FN(MULTI(BASE),has_explicit_domain)isl_multi_val_has_explicit_domain(multi))
488 multi = FN(MULTI(BASE),drop_explicit_domain_dims)isl_multi_val_drop_explicit_domain_dims(multi,
489 type, first, n);
490 if (!multi)
491 return NULL((void*)0);
492
493 for (i = 0; i < multi->n; ++i) {
494 multi->u.p[i] = FN(EL,drop_dims)isl_val_drop_dims(multi->u.p[i], type, first, n);
495 if (!multi->u.p[i])
496 return FN(MULTI(BASE),free)isl_multi_val_free(multi);
497 }
498
499 return multi;
500}
501
502#undef TYPEisl_multi_val
503#define TYPEisl_multi_val MULTI(BASE)isl_multi_val
504
505#include "isl_check_named_params_templ.c"
506static
507#include "isl_align_params_bin_templ.c"
508
509/* Given two MULTI(BASE)s A -> B and C -> D,
510 * construct a MULTI(BASE) (A * C) -> [B -> D].
511 *
512 * If "multi1" and/or "multi2" has an explicit domain, then
513 * intersect the domain of the result with these explicit domains.
514 */
515__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),range_product)isl_multi_val_range_product(
516 __isl_take MULTI(BASE)isl_multi_val *multi1, __isl_take MULTI(BASE)isl_multi_val *multi2)
517{
518 int i;
519 isl_size n1, n2;
520 ELisl_val *el;
521 isl_space *space;
522 MULTI(BASE)isl_multi_val *res;
523
524 FN(MULTI(BASE),align_params_bin)isl_multi_val_align_params_bin(&multi1, &multi2);
525 n1 = FN(MULTI(BASE),size)isl_multi_val_size(multi1);
526 n2 = FN(MULTI(BASE),size)isl_multi_val_size(multi2);
527 if (n1 < 0 || n2 < 0)
528 goto error;
529
530 space = isl_space_range_product(FN(MULTI(BASE),get_space)isl_multi_val_get_space(multi1),
531 FN(MULTI(BASE),get_space)isl_multi_val_get_space(multi2));
532 res = FN(MULTI(BASE),alloc)isl_multi_val_alloc(space);
533
534 for (i = 0; i < n1; ++i) {
535 el = FN(FN(MULTI(BASE),get),BASE)isl_multi_val_get_val(multi1, i);
536 res = FN(FN(MULTI(BASE),set),BASE)isl_multi_val_set_val(res, i, el);
537 }
538
539 for (i = 0; i < n2; ++i) {
540 el = FN(FN(MULTI(BASE),get),BASE)isl_multi_val_get_val(multi2, i);
541 res = FN(FN(MULTI(BASE),set),BASE)isl_multi_val_set_val(res, n1 + i, el);
542 }
543
544 if (FN(MULTI(BASE),has_explicit_domain)isl_multi_val_has_explicit_domain(multi1))
545 res = FN(MULTI(BASE),intersect_explicit_domain)isl_multi_val_intersect_explicit_domain(res, multi1);
546 if (FN(MULTI(BASE),has_explicit_domain)isl_multi_val_has_explicit_domain(multi2))
547 res = FN(MULTI(BASE),intersect_explicit_domain)isl_multi_val_intersect_explicit_domain(res, multi2);
548
549 FN(MULTI(BASE),free)isl_multi_val_free(multi1);
550 FN(MULTI(BASE),free)isl_multi_val_free(multi2);
551 return res;
552error:
553 FN(MULTI(BASE),free)isl_multi_val_free(multi1);
554 FN(MULTI(BASE),free)isl_multi_val_free(multi2);
555 return NULL((void*)0);
556}
557
558/* Is the range of "multi" a wrapped relation?
559 */
560isl_bool FN(MULTI(BASE),range_is_wrapping)isl_multi_val_range_is_wrapping(__isl_keep MULTI(BASE)isl_multi_val *multi)
561{
562 if (!multi)
563 return isl_bool_error;
564 return isl_space_range_is_wrapping(multi->space);
565}
566
567/* Given a function A -> [B -> C], extract the function A -> B.
568 */
569__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),range_factor_domain)isl_multi_val_range_factor_domain(
570 __isl_take MULTI(BASE)isl_multi_val *multi)
571{
572 isl_space *space;
573 isl_size total, keep;
574
575 total = FN(MULTI(BASE),dim)isl_multi_val_dim(multi, isl_dim_out);
576 if (total < 0)
577 return FN(MULTI(BASE),free)isl_multi_val_free(multi);
578 if (!isl_space_range_is_wrapping(multi->space))
579 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,do { isl_handle_error(isl_multi_val_get_ctx(multi), isl_error_invalid
, "range is not a product", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_multi_templ.c"
, 581); return isl_multi_val_free(multi); } while (0)
580 "range is not a product",do { isl_handle_error(isl_multi_val_get_ctx(multi), isl_error_invalid
, "range is not a product", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_multi_templ.c"
, 581); return isl_multi_val_free(multi); } while (0)
581 return FN(MULTI(BASE),free)(multi))do { isl_handle_error(isl_multi_val_get_ctx(multi), isl_error_invalid
, "range is not a product", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_multi_templ.c"
, 581); return isl_multi_val_free(multi); } while (0)
;
582
583 space = FN(MULTI(BASE),get_space)isl_multi_val_get_space(multi);
584 space = isl_space_range_factor_domain(space);
585 keep = isl_space_dim(space, isl_dim_out);
586 if (keep < 0)
587 multi = FN(MULTI(BASE),free)isl_multi_val_free(multi);
588 multi = FN(MULTI(BASE),drop_dims)isl_multi_val_drop_dims(multi,
589 isl_dim_out, keep, total - keep);
590 multi = FN(MULTI(BASE),reset_space)isl_multi_val_reset_space(multi, space);
591
592 return multi;
593}
594
595/* Given a function A -> [B -> C], extract the function A -> C.
596 */
597__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),range_factor_range)isl_multi_val_range_factor_range(
598 __isl_take MULTI(BASE)isl_multi_val *multi)
599{
600 isl_space *space;
601 isl_size total, keep;
602
603 total = FN(MULTI(BASE),dim)isl_multi_val_dim(multi, isl_dim_out);
604 if (total < 0)
605 return FN(MULTI(BASE),free)isl_multi_val_free(multi);
606 if (!isl_space_range_is_wrapping(multi->space))
607 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,do { isl_handle_error(isl_multi_val_get_ctx(multi), isl_error_invalid
, "range is not a product", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_multi_templ.c"
, 609); return isl_multi_val_free(multi); } while (0)
608 "range is not a product",do { isl_handle_error(isl_multi_val_get_ctx(multi), isl_error_invalid
, "range is not a product", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_multi_templ.c"
, 609); return isl_multi_val_free(multi); } while (0)
609 return FN(MULTI(BASE),free)(multi))do { isl_handle_error(isl_multi_val_get_ctx(multi), isl_error_invalid
, "range is not a product", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_multi_templ.c"
, 609); return isl_multi_val_free(multi); } while (0)
;
610
611 space = FN(MULTI(BASE),get_space)isl_multi_val_get_space(multi);
612 space = isl_space_range_factor_range(space);
613 keep = isl_space_dim(space, isl_dim_out);
614 if (keep < 0)
615 multi = FN(MULTI(BASE),free)isl_multi_val_free(multi);
616 multi = FN(MULTI(BASE),drop_dims)isl_multi_val_drop_dims(multi, isl_dim_out, 0, total - keep);
617 multi = FN(MULTI(BASE),reset_space)isl_multi_val_reset_space(multi, space);
618
619 return multi;
620}
621
622/* Given a function [B -> C], extract the function C.
623 */
624__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),factor_range)isl_multi_val_factor_range(
625 __isl_take MULTI(BASE)isl_multi_val *multi)
626{
627 isl_space *space;
628 isl_size total, keep;
629
630 total = FN(MULTI(BASE),dim)isl_multi_val_dim(multi, isl_dim_set);
631 if (total < 0)
632 return FN(MULTI(BASE),free)isl_multi_val_free(multi);
633 if (!isl_space_is_wrapping(multi->space))
634 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,do { isl_handle_error(isl_multi_val_get_ctx(multi), isl_error_invalid
, "not a product", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_multi_templ.c"
, 635); return isl_multi_val_free(multi); } while (0)
635 "not a product", return FN(MULTI(BASE),free)(multi))do { isl_handle_error(isl_multi_val_get_ctx(multi), isl_error_invalid
, "not a product", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_multi_templ.c"
, 635); return isl_multi_val_free(multi); } while (0)
;
636
637 space = FN(MULTI(BASE),get_space)isl_multi_val_get_space(multi);
638 space = isl_space_factor_range(space);
639 keep = isl_space_dim(space, isl_dim_set);
640 if (keep < 0)
641 multi = FN(MULTI(BASE),free)isl_multi_val_free(multi);
642 multi = FN(MULTI(BASE),drop_dims)isl_multi_val_drop_dims(multi, isl_dim_set, 0, total - keep);
643 multi = FN(MULTI(BASE),reset_space)isl_multi_val_reset_space(multi, space);
644
645 return multi;
646}
647
648__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),flatten_range)isl_multi_val_flatten_range(
649 __isl_take MULTI(BASE)isl_multi_val *multi)
650{
651 if (!multi)
652 return NULL((void*)0);
653
654 if (!multi->space->nested[1])
655 return multi;
656
657 multi = FN(MULTI(BASE),cow)isl_multi_val_cow(multi);
658 if (!multi)
659 return NULL((void*)0);
660
661 multi->space = isl_space_flatten_range(multi->space);
662 if (!multi->space)
663 return FN(MULTI(BASE),free)isl_multi_val_free(multi);
664
665 return multi;
666}
667
668/* Given two MULTI(BASE)s A -> B and C -> D,
669 * construct a MULTI(BASE) (A * C) -> (B, D).
670 */
671__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),flat_range_product)isl_multi_val_flat_range_product(
672 __isl_take MULTI(BASE)isl_multi_val *multi1, __isl_take MULTI(BASE)isl_multi_val *multi2)
673{
674 MULTI(BASE)isl_multi_val *multi;
675
676 multi = FN(MULTI(BASE),range_product)isl_multi_val_range_product(multi1, multi2);
677 multi = FN(MULTI(BASE),flatten_range)isl_multi_val_flatten_range(multi);
678 return multi;
679}
680
681/* Given two multi expressions, "multi1"
682 *
683 * [A] -> [B1 B2]
684 *
685 * where B2 starts at position "pos", and "multi2"
686 *
687 * [A] -> [D]
688 *
689 * return the multi expression
690 *
691 * [A] -> [B1 D B2]
692 */
693__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),range_splice)isl_multi_val_range_splice(
694 __isl_take MULTI(BASE)isl_multi_val *multi1, unsigned pos,
695 __isl_take MULTI(BASE)isl_multi_val *multi2)
696{
697 MULTI(BASE)isl_multi_val *res;
698 isl_size dim;
699
700 dim = FN(MULTI(BASE),size)isl_multi_val_size(multi1);
701 if (dim < 0 || !multi2)
702 goto error;
703
704 if (FN(MULTI(BASE),check_range)isl_multi_val_check_range(multi1, isl_dim_out, pos, 0) < 0)
705 goto error;
706
707 res = FN(MULTI(BASE),copy)isl_multi_val_copy(multi1);
708 res = FN(MULTI(BASE),drop_dims)isl_multi_val_drop_dims(res, isl_dim_out, pos, dim - pos);
709 multi1 = FN(MULTI(BASE),drop_dims)isl_multi_val_drop_dims(multi1, isl_dim_out, 0, pos);
710
711 res = FN(MULTI(BASE),flat_range_product)isl_multi_val_flat_range_product(res, multi2);
712 res = FN(MULTI(BASE),flat_range_product)isl_multi_val_flat_range_product(res, multi1);
713
714 return res;
715error:
716 FN(MULTI(BASE),free)isl_multi_val_free(multi1);
717 FN(MULTI(BASE),free)isl_multi_val_free(multi2);
718 return NULL((void*)0);
719}
720
721#undef TYPEisl_multi_val
722#define TYPEisl_multi_val MULTI(BASE)isl_multi_val
723
724static
725#include "isl_type_has_equal_space_bin_templ.c"
726static
727#include "isl_type_check_equal_space_templ.c"
728
729/* This function is currently only used from isl_aff.c
730 */
731static __isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),bin_op)isl_multi_val_bin_op(
732 __isl_take MULTI(BASE)isl_multi_val *multi1, __isl_take MULTI(BASE)isl_multi_val *multi2,
733 __isl_give ELisl_val *(*fn)(__isl_take ELisl_val *, __isl_take ELisl_val *))
734 __attribute__ ((unused));
735
736/* Pairwise perform "fn" to the elements of "multi1" and "multi2" and
737 * return the result.
738 *
739 * If "multi2" has an explicit domain, then
740 * intersect the domain of the result with this explicit domain.
741 */
742static __isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),bin_op)isl_multi_val_bin_op(
743 __isl_take MULTI(BASE)isl_multi_val *multi1, __isl_take MULTI(BASE)isl_multi_val *multi2,
744 __isl_give ELisl_val *(*fn)(__isl_take ELisl_val *, __isl_take ELisl_val *))
745{
746 int i;
747
748 multi1 = FN(MULTI(BASE),cow)isl_multi_val_cow(multi1);
749 if (FN(MULTI(BASE),check_equal_space)isl_multi_val_check_equal_space(multi1, multi2) < 0)
750 goto error;
751
752 for (i = 0; i < multi1->n; ++i) {
753 multi1->u.p[i] = fn(multi1->u.p[i],
754 FN(EL,copy)isl_val_copy(multi2->u.p[i]));
755 if (!multi1->u.p[i])
756 goto error;
757 }
758
759 if (FN(MULTI(BASE),has_explicit_domain)isl_multi_val_has_explicit_domain(multi2))
760 multi1 = FN(MULTI(BASE),intersect_explicit_domain)isl_multi_val_intersect_explicit_domain(multi1,
761 multi2);
762
763 FN(MULTI(BASE),free)isl_multi_val_free(multi2);
764 return multi1;
765error:
766 FN(MULTI(BASE),free)isl_multi_val_free(multi1);
767 FN(MULTI(BASE),free)isl_multi_val_free(multi2);
768 return NULL((void*)0);
769}
770
771/* Only used on some multi-expressions.
772 */
773static isl_bool FN(MULTI(BASE),any)isl_multi_val_any(__isl_keep MULTI(BASE)isl_multi_val *multi,
774 isl_bool (*test)(__isl_keep ELisl_val *)) __attribute__ ((unused));
775
776/* Does "test" succeed on any base expression of "multi"?
777 */
778static isl_bool FN(MULTI(BASE),any)isl_multi_val_any(__isl_keep MULTI(BASE)isl_multi_val *multi,
779 isl_bool (*test)(__isl_keep ELisl_val *))
780{
781 isl_size n;
782 int i;
783
784 n = FN(MULTI(BASE),size)isl_multi_val_size(multi);
785 if (n < 0)
786 return isl_bool_error;
787
788 for (i = 0; i < n; ++i) {
789 isl_bool any = test(multi->u.p[i]);
790 if (any < 0 || any)
791 return any;
792 }
793
794 return isl_bool_false;
795}
796
797/* Only used on some multi-expressions.
798 */
799static isl_bool FN(MULTI(BASE),every)isl_multi_val_every(__isl_keep MULTI(BASE)isl_multi_val *multi,
800 isl_bool (*test)(__isl_keep ELisl_val *)) __attribute__ ((unused));
801
802/* Does "test" succeed on every base expression of "multi"?
803 */
804static isl_bool FN(MULTI(BASE),every)isl_multi_val_every(__isl_keep MULTI(BASE)isl_multi_val *multi,
805 isl_bool (*test)(__isl_keep ELisl_val *))
806{
807 isl_size n;
808 int i;
809
810 n = FN(MULTI(BASE),size)isl_multi_val_size(multi);
811 if (n < 0)
812 return isl_bool_error;
813
814 for (i = 0; i < n; ++i) {
815 isl_bool every = test(multi->u.p[i]);
816 if (every < 0 || !every)
817 return every;
818 }
819
820 return isl_bool_true;
821}
822
823/* Convert a multiple expression defined over a parameter domain
824 * into one that is defined over a zero-dimensional set.
825 */
826__isl_give MULTI(BASE)isl_multi_val *FN(MULTI(BASE),from_range)isl_multi_val_from_range(
827 __isl_take MULTI(BASE)isl_multi_val *multi)
828{
829 isl_space *space;
830
831 if (!multi)
832 return NULL((void*)0);
833 if (!isl_space_is_set(multi->space))
834 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,do { isl_handle_error(isl_multi_val_get_ctx(multi), isl_error_invalid
, "not living in a set space", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_multi_templ.c"
, 836); return isl_multi_val_free(multi); } while (0)
835 "not living in a set space",do { isl_handle_error(isl_multi_val_get_ctx(multi), isl_error_invalid
, "not living in a set space", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_multi_templ.c"
, 836); return isl_multi_val_free(multi); } while (0)
836 return FN(MULTI(BASE),free)(multi))do { isl_handle_error(isl_multi_val_get_ctx(multi), isl_error_invalid
, "not living in a set space", "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/polly/lib/External/isl/isl_multi_templ.c"
, 836); return isl_multi_val_free(multi); } while (0)
;
837
838 space = FN(MULTI(BASE),get_space)isl_multi_val_get_space(multi);
839 space = isl_space_from_range(space);
840 multi = FN(MULTI(BASE),reset_space)isl_multi_val_reset_space(multi, space);
841
842 return multi;
843}
844
845/* Are "multi1" and "multi2" obviously equal?
846 */
847isl_bool FN(MULTI(BASE),plain_is_equal)isl_multi_val_plain_is_equal(__isl_keep MULTI(BASE)isl_multi_val *multi1,
848 __isl_keep MULTI(BASE)isl_multi_val *multi2)
849{
850 int i;
851 isl_bool equal;
852
853 if (!multi1 || !multi2)
854 return isl_bool_error;
855 if (multi1->n != multi2->n)
856 return isl_bool_false;
857 equal = isl_space_is_equal(multi1->space, multi2->space);
858 if (equal < 0 || !equal)
859 return equal;
860
861 for (i = 0; i < multi1->n; ++i) {
862 equal = FN(EL,plain_is_equal)isl_val_plain_is_equal(multi1->u.p[i], multi2->u.p[i]);
863 if (equal < 0 || !equal)
864 return equal;
865 }
866
867 if (FN(MULTI(BASE),has_explicit_domain)isl_multi_val_has_explicit_domain(multi1) ||
868 FN(MULTI(BASE),has_explicit_domain)isl_multi_val_has_explicit_domain(multi2)) {
869 equal = FN(MULTI(BASE),equal_explicit_domain)isl_multi_val_equal_explicit_domain(multi1, multi2);
870 if (equal < 0 || !equal)
871 return equal;
872 }
873
874 return isl_bool_true;
875}