isl_multi_*_gist: add missing isl_multi_*_cow
[isl.git] / isl_multi_templ.c
blobf8f7db0dc756a2ec0663525705d79054ded89895
1 /*
2 * Copyright 2011 Sven Verdoolaege
3 * Copyright 2012 Ecole Normale Superieure
5 * Use of this software is governed by the MIT license
7 * Written by Sven Verdoolaege,
8 * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
9 */
11 #define xCAT(A,B) A ## B
12 #define CAT(A,B) xCAT(A,B)
13 #undef EL
14 #define EL CAT(isl_,BASE)
15 #define xFN(TYPE,NAME) TYPE ## _ ## NAME
16 #define FN(TYPE,NAME) xFN(TYPE,NAME)
17 #define xMULTI(BASE) isl_multi_ ## BASE
18 #define MULTI(BASE) xMULTI(BASE)
19 #define MULTI_NAME(BASE) "isl_multi_" #BASE
20 #define xLIST(EL) EL ## _list
21 #define LIST(EL) xLIST(EL)
23 isl_ctx *FN(MULTI(BASE),get_ctx)(__isl_keep MULTI(BASE) *multi)
25 return multi ? isl_space_get_ctx(multi->space) : NULL;
28 __isl_give isl_space *FN(MULTI(BASE),get_space)(__isl_keep MULTI(BASE) *multi)
30 return multi ? isl_space_copy(multi->space) : NULL;
33 __isl_give isl_space *FN(MULTI(BASE),get_domain_space)(
34 __isl_keep MULTI(BASE) *multi)
36 return multi ? isl_space_domain(isl_space_copy(multi->space)) : NULL;
39 __isl_give MULTI(BASE) *FN(MULTI(BASE),alloc)(__isl_take isl_space *space)
41 isl_ctx *ctx;
42 int n;
43 MULTI(BASE) *multi;
45 if (!space)
46 return NULL;
48 ctx = isl_space_get_ctx(space);
49 n = isl_space_dim(space, isl_dim_out);
50 multi = isl_calloc(ctx, MULTI(BASE),
51 sizeof(MULTI(BASE)) + (n - 1) * sizeof(struct EL *));
52 if (!multi)
53 goto error;
55 multi->space = space;
56 multi->n = n;
57 multi->ref = 1;
58 return multi;
59 error:
60 isl_space_free(space);
61 return NULL;
64 __isl_give MULTI(BASE) *FN(MULTI(BASE),dup)(__isl_keep MULTI(BASE) *multi)
66 int i;
67 MULTI(BASE) *dup;
69 if (!multi)
70 return NULL;
72 dup = FN(MULTI(BASE),alloc)(isl_space_copy(multi->space));
73 if (!dup)
74 return NULL;
76 for (i = 0; i < multi->n; ++i)
77 dup = FN(FN(MULTI(BASE),set),BASE)(dup, i,
78 FN(EL,copy)(multi->p[i]));
80 return dup;
83 __isl_give MULTI(BASE) *FN(MULTI(BASE),cow)(__isl_take MULTI(BASE) *multi)
85 if (!multi)
86 return NULL;
88 if (multi->ref == 1)
89 return multi;
91 multi->ref--;
92 return FN(MULTI(BASE),dup)(multi);
95 __isl_give MULTI(BASE) *FN(MULTI(BASE),copy)(__isl_keep MULTI(BASE) *multi)
97 if (!multi)
98 return NULL;
100 multi->ref++;
101 return multi;
104 void *FN(MULTI(BASE),free)(__isl_take MULTI(BASE) *multi)
106 int i;
108 if (!multi)
109 return NULL;
111 if (--multi->ref > 0)
112 return NULL;
114 isl_space_free(multi->space);
115 for (i = 0; i < multi->n; ++i)
116 FN(EL,free)(multi->p[i]);
117 free(multi);
119 return NULL;
122 __isl_give MULTI(BASE) *FN(MULTI(BASE),insert_dims)(
123 __isl_take MULTI(BASE) *multi,
124 enum isl_dim_type type, unsigned first, unsigned n)
126 int i;
128 if (!multi)
129 return NULL;
130 if (type == isl_dim_out)
131 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
132 "cannot insert output/set dimensions",
133 return FN(MULTI(BASE),free)(multi));
134 if (n == 0 && !isl_space_is_named_or_nested(multi->space, type))
135 return multi;
137 multi = FN(MULTI(BASE),cow)(multi);
138 if (!multi)
139 return NULL;
141 multi->space = isl_space_insert_dims(multi->space, type, first, n);
142 if (!multi->space)
143 return FN(MULTI(BASE),free)(multi);
145 for (i = 0; i < multi->n; ++i) {
146 multi->p[i] = FN(EL,insert_dims)(multi->p[i], type, first, n);
147 if (!multi->p[i])
148 return FN(MULTI(BASE),free)(multi);
151 return multi;
154 __isl_give MULTI(BASE) *FN(MULTI(BASE),add_dims)(__isl_take MULTI(BASE) *multi,
155 enum isl_dim_type type, unsigned n)
157 unsigned pos;
159 pos = FN(MULTI(BASE),dim)(multi, type);
161 return FN(MULTI(BASE),insert_dims)(multi, type, pos, n);
164 unsigned FN(MULTI(BASE),dim)(__isl_keep MULTI(BASE) *multi,
165 enum isl_dim_type type)
167 return multi ? isl_space_dim(multi->space, type) : 0;
170 __isl_give MULTI(BASE) *FN(MULTI(BASE),set_dim_name)(
171 __isl_take MULTI(BASE) *multi,
172 enum isl_dim_type type, unsigned pos, const char *s)
174 int i;
176 multi = FN(MULTI(BASE),cow)(multi);
177 if (!multi)
178 return NULL;
180 multi->space = isl_space_set_dim_name(multi->space, type, pos, s);
181 if (!multi->space)
182 return FN(MULTI(BASE),free)(multi);
184 if (type == isl_dim_out)
185 return multi;
186 for (i = 0; i < multi->n; ++i) {
187 multi->p[i] = FN(EL,set_dim_name)(multi->p[i], type, pos, s);
188 if (!multi->p[i])
189 return FN(MULTI(BASE),free)(multi);
192 return multi;
195 const char *FN(MULTI(BASE),get_tuple_name)(__isl_keep MULTI(BASE) *multi,
196 enum isl_dim_type type)
198 return multi ? isl_space_get_tuple_name(multi->space, type) : NULL;
201 __isl_give EL *FN(FN(MULTI(BASE),get),BASE)(__isl_keep MULTI(BASE) *multi,
202 int pos)
204 isl_ctx *ctx;
206 if (!multi)
207 return NULL;
208 ctx = FN(MULTI(BASE),get_ctx)(multi);
209 if (pos < 0 || pos >= multi->n)
210 isl_die(ctx, isl_error_invalid,
211 "index out of bounds", return NULL);
212 return FN(EL,copy)(multi->p[pos]);
215 __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),set),BASE)(
216 __isl_take MULTI(BASE) *multi, int pos, __isl_take EL *el)
218 isl_space *multi_space = NULL;
219 isl_space *el_space = NULL;
221 multi = FN(MULTI(BASE),cow)(multi);
222 if (!multi || !el)
223 goto error;
225 multi_space = FN(MULTI(BASE),get_space)(multi);
226 el_space = FN(EL,get_space)(el);
228 if (!isl_space_match(multi_space, isl_dim_param,
229 el_space, isl_dim_param))
230 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
231 "parameters don't match", goto error);
232 if (!isl_space_tuple_match(multi_space, isl_dim_in,
233 el_space, isl_dim_in))
234 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
235 "domains don't match", goto error);
237 if (pos < 0 || pos >= multi->n)
238 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
239 "index out of bounds", goto error);
241 FN(EL,free)(multi->p[pos]);
242 multi->p[pos] = el;
244 isl_space_free(multi_space);
245 isl_space_free(el_space);
247 return multi;
248 error:
249 FN(MULTI(BASE),free)(multi);
250 FN(EL,free)(el);
251 isl_space_free(multi_space);
252 isl_space_free(el_space);
253 return NULL;
256 /* Reset the space of "multi". This function is called from isl_pw_templ.c
257 * and doesn't know if the space of an element object is represented
258 * directly or through its domain. It therefore passes along both,
259 * which we pass along to the element function since we don't how
260 * that is represented either.
262 __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_space_and_domain)(
263 __isl_take MULTI(BASE) *multi, __isl_take isl_space *space,
264 __isl_take isl_space *domain)
266 int i;
268 multi = FN(MULTI(BASE),cow)(multi);
269 if (!multi || !space || !domain)
270 goto error;
272 for (i = 0; i < multi->n; ++i) {
273 multi->p[i] = FN(EL,reset_domain_space)(multi->p[i],
274 isl_space_copy(domain));
275 if (!multi->p[i])
276 goto error;
278 isl_space_free(domain);
279 isl_space_free(multi->space);
280 multi->space = space;
282 return multi;
283 error:
284 isl_space_free(domain);
285 isl_space_free(space);
286 FN(MULTI(BASE),free)(multi);
287 return NULL;
290 __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_domain_space)(
291 __isl_take MULTI(BASE) *multi, __isl_take isl_space *domain)
293 isl_space *space;
295 space = isl_space_extend_domain_with_range(isl_space_copy(domain),
296 isl_space_copy(multi->space));
297 return FN(MULTI(BASE),reset_space_and_domain)(multi, space, domain);
300 __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_space)(
301 __isl_take MULTI(BASE) *multi, __isl_take isl_space *space)
303 isl_space *domain;
305 domain = isl_space_domain(isl_space_copy(space));
306 return FN(MULTI(BASE),reset_space_and_domain)(multi, space, domain);
309 __isl_give MULTI(BASE) *FN(MULTI(BASE),set_tuple_name)(
310 __isl_keep MULTI(BASE) *multi, enum isl_dim_type type,
311 const char *s)
313 isl_space *space;
315 multi = FN(MULTI(BASE),cow)(multi);
316 if (!multi)
317 return NULL;
319 space = FN(MULTI(BASE),get_space)(multi);
320 space = isl_space_set_tuple_name(space, type, s);
322 return FN(MULTI(BASE),reset_space)(multi, space);
325 __isl_give MULTI(BASE) *FN(MULTI(BASE),set_tuple_id)(
326 __isl_keep MULTI(BASE) *multi, enum isl_dim_type type,
327 __isl_take isl_id *id)
329 isl_space *space;
331 multi = FN(MULTI(BASE),cow)(multi);
332 if (!multi)
333 return isl_id_free(id);
335 space = FN(MULTI(BASE),get_space)(multi);
336 space = isl_space_set_tuple_id(space, type, id);
338 return FN(MULTI(BASE),reset_space)(multi, space);
341 __isl_give MULTI(BASE) *FN(MULTI(BASE),realign_domain)(
342 __isl_take MULTI(BASE) *multi, __isl_take isl_reordering *exp)
344 int i;
346 multi = FN(MULTI(BASE),cow)(multi);
347 if (!multi || !exp)
348 goto error;
350 for (i = 0; i < multi->n; ++i) {
351 multi->p[i] = FN(EL,realign_domain)(multi->p[i],
352 isl_reordering_copy(exp));
353 if (!multi->p[i])
354 goto error;
357 multi = FN(MULTI(BASE),reset_domain_space)(multi,
358 isl_space_copy(exp->dim));
360 isl_reordering_free(exp);
361 return multi;
362 error:
363 isl_reordering_free(exp);
364 FN(MULTI(BASE),free)(multi);
365 return NULL;
368 /* Align the parameters of "multi" to those of "model".
370 __isl_give MULTI(BASE) *FN(MULTI(BASE),align_params)(
371 __isl_take MULTI(BASE) *multi, __isl_take isl_space *model)
373 isl_ctx *ctx;
375 if (!multi || !model)
376 goto error;
378 ctx = isl_space_get_ctx(model);
379 if (!isl_space_has_named_params(model))
380 isl_die(ctx, isl_error_invalid,
381 "model has unnamed parameters", goto error);
382 if (!isl_space_has_named_params(multi->space))
383 isl_die(ctx, isl_error_invalid,
384 "input has unnamed parameters", goto error);
385 if (!isl_space_match(multi->space, isl_dim_param,
386 model, isl_dim_param)) {
387 isl_reordering *exp;
389 model = isl_space_params(model);
390 exp = isl_parameter_alignment_reordering(multi->space, model);
391 exp = isl_reordering_extend_space(exp,
392 FN(MULTI(BASE),get_domain_space)(multi));
393 multi = FN(MULTI(BASE),realign_domain)(multi, exp);
396 isl_space_free(model);
397 return multi;
398 error:
399 isl_space_free(model);
400 FN(MULTI(BASE),free)(multi);
401 return NULL;
404 static __isl_give MULTI(BASE) *FN(MULTI(BASE),align_params_multi_set_and)(
405 __isl_take MULTI(BASE) *multi, __isl_take isl_set *set,
406 __isl_give MULTI(BASE) *(*fn)(__isl_take MULTI(BASE) *multi,
407 __isl_take isl_set *set))
409 isl_ctx *ctx;
411 if (!multi || !set)
412 goto error;
413 if (isl_space_match(multi->space, isl_dim_param,
414 set->dim, isl_dim_param))
415 return fn(multi, set);
416 ctx = FN(MULTI(BASE),get_ctx)(multi);
417 if (!isl_space_has_named_params(multi->space) ||
418 !isl_space_has_named_params(set->dim))
419 isl_die(ctx, isl_error_invalid,
420 "unaligned unnamed parameters", goto error);
421 multi = FN(MULTI(BASE),align_params)(multi, isl_set_get_space(set));
422 set = isl_set_align_params(set, FN(MULTI(BASE),get_space)(multi));
423 return fn(multi, set);
424 error:
425 FN(MULTI(BASE),free)(multi);
426 isl_set_free(set);
427 return NULL;
430 __isl_give MULTI(BASE) *FN(MULTI(BASE),gist_aligned)(
431 __isl_take MULTI(BASE) *multi, __isl_take isl_set *context)
433 int i;
435 multi = FN(MULTI(BASE),cow)(multi);
436 if (!multi || !context)
437 goto error;
439 for (i = 0; i < multi->n; ++i) {
440 multi->p[i] = FN(EL,gist)(multi->p[i], isl_set_copy(context));
441 if (!multi->p[i])
442 goto error;
445 isl_set_free(context);
446 return multi;
447 error:
448 isl_set_free(context);
449 FN(MULTI(BASE),free)(multi);
450 return NULL;
453 __isl_give MULTI(BASE) *FN(MULTI(BASE),gist)(__isl_take MULTI(BASE) *multi,
454 __isl_take isl_set *context)
456 return FN(MULTI(BASE),align_params_multi_set_and)(multi, context,
457 &FN(MULTI(BASE),gist_aligned));
460 __isl_give MULTI(BASE) *FN(MULTI(BASE),gist_params)(
461 __isl_take MULTI(BASE) *multi, __isl_take isl_set *context)
463 isl_space *space = FN(MULTI(BASE),get_domain_space)(multi);
464 isl_set *dom_context = isl_set_universe(space);
465 dom_context = isl_set_intersect_params(dom_context, context);
466 return FN(MULTI(BASE),gist)(multi, dom_context);
469 __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),from),LIST(BASE))(
470 __isl_take isl_space *space, __isl_take LIST(EL) *list)
472 int i;
473 int n;
474 isl_ctx *ctx;
475 MULTI(BASE) *multi;
477 if (!space || !list)
478 goto error;
480 ctx = isl_space_get_ctx(space);
481 n = FN(FN(LIST(EL),n),BASE)(list);
482 if (n != isl_space_dim(space, isl_dim_out))
483 isl_die(ctx, isl_error_invalid,
484 "invalid number of elements in list", goto error);
486 multi = FN(MULTI(BASE),alloc)(isl_space_copy(space));
487 for (i = 0; i < n; ++i) {
488 multi = FN(FN(MULTI(BASE),set),BASE)(multi, i,
489 FN(FN(LIST(EL),get),BASE)(list, i));
492 isl_space_free(space);
493 FN(LIST(EL),free)(list);
494 return multi;
495 error:
496 isl_space_free(space);
497 FN(LIST(EL),free)(list);
498 return NULL;
501 /* Create a multi expression in the given space that maps each
502 * input dimension to the corresponding output dimension.
504 __isl_give MULTI(BASE) *FN(MULTI(BASE),identity)(__isl_take isl_space *space)
506 int i, n;
507 isl_local_space *ls;
508 MULTI(BASE) *multi;
510 if (!space)
511 return NULL;
513 if (isl_space_is_set(space))
514 isl_die(isl_space_get_ctx(space), isl_error_invalid,
515 "expecting map space", goto error);
517 n = isl_space_dim(space, isl_dim_out);
518 if (n != isl_space_dim(space, isl_dim_in))
519 isl_die(isl_space_get_ctx(space), isl_error_invalid,
520 "number of input and output dimensions needs to be "
521 "the same", goto error);
523 multi = FN(MULTI(BASE),alloc)(isl_space_copy(space));
525 if (!n) {
526 isl_space_free(space);
527 return multi;
530 space = isl_space_domain(space);
531 ls = isl_local_space_from_space(space);
533 for (i = 0; i < n; ++i) {
534 EL *el;
535 el = FN(EL,var_on_domain)(isl_local_space_copy(ls),
536 isl_dim_set, i);
537 multi = FN(FN(MULTI(BASE),set),BASE)(multi, i, el);
540 isl_local_space_free(ls);
542 return multi;
543 error:
544 isl_space_free(space);
545 return NULL;
548 /* Construct a multi expression in the given space with value zero in
549 * each of the output dimensions.
551 __isl_give MULTI(BASE) *FN(MULTI(BASE),zero)(__isl_take isl_space *space)
553 int n;
554 MULTI(BASE) *multi;
556 if (!space)
557 return NULL;
559 n = isl_space_dim(space , isl_dim_out);
560 multi = FN(MULTI(BASE),alloc)(isl_space_copy(space));
562 if (!n)
563 isl_space_free(space);
564 else {
565 int i;
566 isl_local_space *ls;
567 EL *el;
569 space = isl_space_domain(space);
570 ls = isl_local_space_from_space(space);
571 el = FN(EL,zero_on_domain)(ls);
573 for (i = 0; i < n; ++i)
574 multi = FN(FN(MULTI(BASE),set),BASE)(multi, i,
575 FN(EL,copy)(el));
577 FN(EL,free)(el);
580 return multi;
583 __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),from),BASE)(__isl_take EL *el)
585 MULTI(BASE) *multi;
587 multi = FN(MULTI(BASE),alloc)(FN(EL,get_space)(el));
588 multi = FN(FN(MULTI(BASE),set),BASE)(multi, 0, el);
590 return multi;
593 __isl_give MULTI(BASE) *FN(MULTI(BASE),drop_dims)(
594 __isl_take MULTI(BASE) *multi,
595 enum isl_dim_type type, unsigned first, unsigned n)
597 int i;
598 unsigned dim;
600 multi = FN(MULTI(BASE),cow)(multi);
601 if (!multi)
602 return NULL;
604 dim = FN(MULTI(BASE),dim)(multi, type);
605 if (first + n > dim || first + n < first)
606 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
607 "index out of bounds",
608 return FN(MULTI(BASE),cow)(multi));
610 multi->space = isl_space_drop_dims(multi->space, type, first, n);
611 if (!multi->space)
612 return FN(MULTI(BASE),cow)(multi);
614 if (type == isl_dim_out) {
615 for (i = 0; i < n; ++i)
616 FN(EL,free)(multi->p[first + i]);
617 for (i = first; i + n < multi->n; ++i)
618 multi->p[i] = multi->p[i + n];
619 multi->n -= n;
621 return multi;
624 for (i = 0; i < multi->n; ++i) {
625 multi->p[i] = FN(EL,drop_dims)(multi->p[i], type, first, n);
626 if (!multi->p[i])
627 return FN(MULTI(BASE),cow)(multi);
630 return multi;
633 /* Given two MULTI(BASE)s A -> B and C -> D,
634 * construct a MULTI(BASE) (A * C) -> (B, D).
636 __isl_give MULTI(BASE) *FN(MULTI(BASE),range_product)(
637 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
639 int i, n1, n2;
640 EL *el;
641 isl_space *space;
642 MULTI(BASE) *res;
644 if (!multi1 || !multi2)
645 goto error;
647 space = isl_space_range_product(FN(MULTI(BASE),get_space)(multi1),
648 FN(MULTI(BASE),get_space)(multi2));
649 res = FN(MULTI(BASE),alloc)(space);
651 n1 = FN(MULTI(BASE),dim)(multi1, isl_dim_out);
652 n2 = FN(MULTI(BASE),dim)(multi2, isl_dim_out);
654 for (i = 0; i < n1; ++i) {
655 el = FN(FN(MULTI(BASE),get),BASE)(multi1, i);
656 res = FN(FN(MULTI(BASE),set),BASE)(res, i, el);
659 for (i = 0; i < n2; ++i) {
660 el = FN(FN(MULTI(BASE),get),BASE)(multi2, i);
661 res = FN(FN(MULTI(BASE),set),BASE)(res, n1 + i, el);
664 FN(MULTI(BASE),free)(multi1);
665 FN(MULTI(BASE),free)(multi2);
666 return res;
667 error:
668 FN(MULTI(BASE),free)(multi1);
669 FN(MULTI(BASE),free)(multi2);
670 return NULL;
673 __isl_give MULTI(BASE) *FN(MULTI(BASE),flatten_range)(
674 __isl_take MULTI(BASE) *multi)
676 if (!multi)
677 return NULL;
679 if (!multi->space->nested[1])
680 return multi;
682 multi = FN(MULTI(BASE),cow)(multi);
683 if (!multi)
684 return NULL;
686 multi->space = isl_space_flatten_range(multi->space);
687 if (!multi->space)
688 return FN(MULTI(BASE),free)(multi);
690 return multi;
693 /* Given two MULTI(BASE)s A -> B and C -> D,
694 * construct a MULTI(BASE) (A * C) -> [B -> D].
696 __isl_give MULTI(BASE) *FN(MULTI(BASE),flat_range_product)(
697 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
699 MULTI(BASE) *multi;
701 multi = FN(MULTI(BASE),range_product)(multi1, multi2);
702 multi = FN(MULTI(BASE),flatten_range)(multi);
703 return multi;
706 /* Given two multi expressions, "multi1"
708 * [A] -> [B1 B2]
710 * where B2 starts at position "pos", and "multi2"
712 * [A] -> [D]
714 * return the multi expression
716 * [A] -> [B1 D B2]
718 __isl_give MULTI(BASE) *FN(MULTI(BASE),range_splice)(
719 __isl_take MULTI(BASE) *multi1, unsigned pos,
720 __isl_take MULTI(BASE) *multi2)
722 MULTI(BASE) *res;
723 unsigned dim;
725 if (!multi1 || !multi2)
726 goto error;
728 dim = FN(MULTI(BASE),dim)(multi1, isl_dim_out);
729 if (pos > dim)
730 isl_die(FN(MULTI(BASE),get_ctx)(multi1), isl_error_invalid,
731 "index out of bounds", goto error);
733 res = FN(MULTI(BASE),copy)(multi1);
734 res = FN(MULTI(BASE),drop_dims)(res, isl_dim_out, pos, dim - pos);
735 multi1 = FN(MULTI(BASE),drop_dims)(multi1, isl_dim_out, 0, pos);
737 res = FN(MULTI(BASE),flat_range_product)(res, multi2);
738 res = FN(MULTI(BASE),flat_range_product)(res, multi1);
740 return res;
741 error:
742 FN(MULTI(BASE),free)(multi1);
743 FN(MULTI(BASE),free)(multi2);
744 return NULL;
747 /* Given two multi expressions, "multi1"
749 * [A1 A2] -> [B1 B2]
751 * where A2 starts at position "in_pos" and B2 starts at position "out_pos",
752 * and "multi2"
754 * [C] -> [D]
756 * return the multi expression
758 * [A1 C A2] -> [B1 D B2]
760 * We first insert input dimensions to obtain
762 * [A1 C A2] -> [B1 B2]
764 * and
766 * [A1 C A2] -> [D]
768 * and then apply range_splice.
770 __isl_give MULTI(BASE) *FN(MULTI(BASE),splice)(
771 __isl_take MULTI(BASE) *multi1, unsigned in_pos, unsigned out_pos,
772 __isl_take MULTI(BASE) *multi2)
774 unsigned n_in1;
775 unsigned n_in2;
777 if (!multi1 || !multi2)
778 goto error;
780 n_in1 = FN(MULTI(BASE),dim)(multi1, isl_dim_in);
781 if (in_pos > n_in1)
782 isl_die(FN(MULTI(BASE),get_ctx)(multi1), isl_error_invalid,
783 "index out of bounds", goto error);
785 n_in2 = FN(MULTI(BASE),dim)(multi2, isl_dim_in);
787 multi1 = FN(MULTI(BASE),insert_dims)(multi1, isl_dim_in, in_pos, n_in2);
788 multi2 = FN(MULTI(BASE),insert_dims)(multi2, isl_dim_in, n_in2,
789 n_in1 - in_pos);
790 multi2 = FN(MULTI(BASE),insert_dims)(multi2, isl_dim_in, 0, in_pos);
792 return FN(MULTI(BASE),range_splice)(multi1, out_pos, multi2);
793 error:
794 FN(MULTI(BASE),free)(multi1);
795 FN(MULTI(BASE),free)(multi2);
796 return NULL;