2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
5 * Use of this software is governed by the GNU LGPLv2.1 license
7 * Written by Sven Verdoolaege, K.U.Leuven, Departement
8 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
9 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
10 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
14 #include <isl_dim_private.h>
17 isl_ctx *isl_dim_get_ctx(__isl_keep isl_dim *dim)
19 return dim ? dim->ctx : NULL;
22 struct isl_dim *isl_dim_alloc(struct isl_ctx *ctx,
23 unsigned nparam, unsigned n_in, unsigned n_out)
27 dim = isl_alloc_type(ctx, struct isl_dim);
38 dim->tuple_name[0] = NULL;
39 dim->tuple_name[1] = NULL;
41 dim->nested[0] = NULL;
42 dim->nested[1] = NULL;
50 struct isl_dim *isl_dim_set_alloc(struct isl_ctx *ctx,
51 unsigned nparam, unsigned dim)
53 return isl_dim_alloc(ctx, nparam, 0, dim);
56 static unsigned global_pos(struct isl_dim *dim,
57 enum isl_dim_type type, unsigned pos)
59 struct isl_ctx *ctx = dim->ctx;
63 isl_assert(ctx, pos < dim->nparam, return isl_dim_total(dim));
66 isl_assert(ctx, pos < dim->n_in, return isl_dim_total(dim));
67 return pos + dim->nparam;
69 isl_assert(ctx, pos < dim->n_out, return isl_dim_total(dim));
70 return pos + dim->nparam + dim->n_in;
72 isl_assert(ctx, 0, return isl_dim_total(dim));
74 return isl_dim_total(dim);
77 /* Extend length of names array to the total number of dimensions.
79 static __isl_give isl_dim *extend_names(__isl_take isl_dim *dim)
81 struct isl_name **names;
84 if (isl_dim_total(dim) <= dim->n_name)
88 dim->names = isl_calloc_array(dim->ctx,
89 struct isl_name *, isl_dim_total(dim));
93 names = isl_realloc_array(dim->ctx, dim->names,
94 struct isl_name *, isl_dim_total(dim));
98 for (i = dim->n_name; i < isl_dim_total(dim); ++i)
102 dim->n_name = isl_dim_total(dim);
110 static struct isl_dim *set_name(struct isl_dim *dim,
111 enum isl_dim_type type, unsigned pos,
112 struct isl_name *name)
114 struct isl_ctx *ctx = dim->ctx;
115 dim = isl_dim_cow(dim);
120 pos = global_pos(dim, type, pos);
121 if (pos == isl_dim_total(dim))
124 if (pos >= dim->n_name) {
127 dim = extend_names(dim);
132 dim->names[pos] = name;
136 isl_name_free(ctx, name);
141 static struct isl_name *get_name(struct isl_dim *dim,
142 enum isl_dim_type type, unsigned pos)
147 pos = global_pos(dim, type, pos);
148 if (pos == isl_dim_total(dim))
150 if (pos >= dim->n_name)
152 return dim->names[pos];
155 static unsigned offset(struct isl_dim *dim, enum isl_dim_type type)
158 case isl_dim_param: return 0;
159 case isl_dim_in: return dim->nparam;
160 case isl_dim_out: return dim->nparam + dim->n_in;
165 static unsigned n(struct isl_dim *dim, enum isl_dim_type type)
168 case isl_dim_param: return dim->nparam;
169 case isl_dim_in: return dim->n_in;
170 case isl_dim_out: return dim->n_out;
175 unsigned isl_dim_size(struct isl_dim *dim, enum isl_dim_type type)
182 unsigned isl_dim_offset(__isl_keep isl_dim *dim, enum isl_dim_type type)
186 return offset(dim, type);
189 static struct isl_dim *copy_names(struct isl_dim *dst,
190 enum isl_dim_type dst_type, unsigned offset, struct isl_dim *src,
191 enum isl_dim_type src_type)
194 struct isl_name *name;
199 for (i = 0; i < n(src, src_type); ++i) {
200 name = get_name(src, src_type, i);
203 dst = set_name(dst, dst_type, offset + i,
204 isl_name_copy(dst->ctx, name));
211 struct isl_dim *isl_dim_dup(struct isl_dim *dim)
216 dup = isl_dim_alloc(dim->ctx, dim->nparam, dim->n_in, dim->n_out);
217 if (dim->tuple_name[0] &&
218 !(dup->tuple_name[0] = isl_name_copy(dim->ctx, dim->tuple_name[0])))
220 if (dim->tuple_name[1] &&
221 !(dup->tuple_name[1] = isl_name_copy(dim->ctx, dim->tuple_name[1])))
223 if (dim->nested[0] && !(dup->nested[0] = isl_dim_copy(dim->nested[0])))
225 if (dim->nested[1] && !(dup->nested[1] = isl_dim_copy(dim->nested[1])))
229 dup = copy_names(dup, isl_dim_param, 0, dim, isl_dim_param);
230 dup = copy_names(dup, isl_dim_in, 0, dim, isl_dim_in);
231 dup = copy_names(dup, isl_dim_out, 0, dim, isl_dim_out);
238 struct isl_dim *isl_dim_cow(struct isl_dim *dim)
246 return isl_dim_dup(dim);
249 struct isl_dim *isl_dim_copy(struct isl_dim *dim)
258 void isl_dim_free(struct isl_dim *dim)
268 isl_name_free(dim->ctx, dim->tuple_name[0]);
269 isl_name_free(dim->ctx, dim->tuple_name[1]);
271 isl_dim_free(dim->nested[0]);
272 isl_dim_free(dim->nested[1]);
274 for (i = 0; i < dim->n_name; ++i)
275 isl_name_free(dim->ctx, dim->names[i]);
277 isl_ctx_deref(dim->ctx);
282 static int name_ok(isl_ctx *ctx, const char *s)
287 dummy = strtol(s, &p, 0);
289 isl_die(ctx, isl_error_invalid, "name looks like a number",
295 __isl_give isl_dim *isl_dim_set_tuple_name(__isl_take isl_dim *dim,
296 enum isl_dim_type type, const char *s)
298 struct isl_name *name;
300 dim = isl_dim_cow(dim);
303 if (type != isl_dim_in && type != isl_dim_out)
304 isl_die(dim->ctx, isl_error_invalid,
305 "only input, output and set tuples can have names",
310 if (!name_ok(dim->ctx, s))
312 name = isl_name_get(dim->ctx, s);
317 isl_name_free(dim->ctx, dim->tuple_name[type - isl_dim_in]);
318 dim->tuple_name[type - isl_dim_in] = name;
326 const char *isl_dim_get_tuple_name(__isl_keep isl_dim *dim,
327 enum isl_dim_type type)
329 struct isl_name *name;
332 if (type != isl_dim_in && type != isl_dim_out)
334 name = dim->tuple_name[type - isl_dim_in];
335 return name ? name->name : NULL;
338 struct isl_dim *isl_dim_set_name(struct isl_dim *dim,
339 enum isl_dim_type type, unsigned pos,
342 struct isl_name *name;
346 if (!name_ok(dim->ctx, s))
348 isl_name_free(dim->ctx, get_name(dim, type, pos));
349 name = isl_name_get(dim->ctx, s);
352 return set_name(dim, type, pos, name);
358 const char *isl_dim_get_name(struct isl_dim *dim,
359 enum isl_dim_type type, unsigned pos)
361 struct isl_name *name = get_name(dim, type, pos);
362 return name ? name->name : NULL;
365 static struct isl_name *tuple_name(__isl_keep isl_dim *dim,
366 enum isl_dim_type type)
370 if (type == isl_dim_in)
371 return dim->tuple_name[0];
372 if (type == isl_dim_out)
373 return dim->tuple_name[1];
377 static __isl_keep isl_dim *nested(__isl_keep isl_dim *dim,
378 enum isl_dim_type type)
382 if (type == isl_dim_in)
383 return dim->nested[0];
384 if (type == isl_dim_out)
385 return dim->nested[1];
389 int isl_dim_tuple_match(__isl_keep isl_dim *dim1, enum isl_dim_type dim1_type,
390 __isl_keep isl_dim *dim2, enum isl_dim_type dim2_type)
392 struct isl_name *name1, *name2;
393 isl_dim *nested1, *nested2;
395 if (n(dim1, dim1_type) != n(dim2, dim2_type))
397 name1 = tuple_name(dim1, dim1_type);
398 name2 = tuple_name(dim2, dim2_type);
401 if (name1 && name1->name != name2->name)
403 nested1 = nested(dim1, dim1_type);
404 nested2 = nested(dim2, dim2_type);
405 if (!nested1 ^ !nested2)
407 if (nested1 && !isl_dim_equal(nested1, nested2))
412 static int match(struct isl_dim *dim1, enum isl_dim_type dim1_type,
413 struct isl_dim *dim2, enum isl_dim_type dim2_type)
417 if (!isl_dim_tuple_match(dim1, dim1_type, dim2, dim2_type))
420 if (!dim1->names && !dim2->names)
423 for (i = 0; i < n(dim1, dim1_type); ++i) {
424 if (get_name(dim1, dim1_type, i) !=
425 get_name(dim2, dim2_type, i))
431 int isl_dim_match(struct isl_dim *dim1, enum isl_dim_type dim1_type,
432 struct isl_dim *dim2, enum isl_dim_type dim2_type)
434 return match(dim1, dim1_type, dim2, dim2_type);
437 static void get_names(struct isl_dim *dim, enum isl_dim_type type,
438 unsigned first, unsigned n, struct isl_name **names)
442 for (i = 0; i < n ; ++i)
443 names[i] = get_name(dim, type, first+i);
446 struct isl_dim *isl_dim_extend(struct isl_dim *dim,
447 unsigned nparam, unsigned n_in, unsigned n_out)
449 struct isl_name **names = NULL;
453 if (dim->nparam == nparam && dim->n_in == n_in && dim->n_out == n_out)
456 isl_assert(dim->ctx, dim->nparam <= nparam, goto error);
457 isl_assert(dim->ctx, dim->n_in <= n_in, goto error);
458 isl_assert(dim->ctx, dim->n_out <= n_out, goto error);
460 dim = isl_dim_cow(dim);
463 names = isl_calloc_array(dim->ctx, struct isl_name *,
464 nparam + n_in + n_out);
467 get_names(dim, isl_dim_param, 0, dim->nparam, names);
468 get_names(dim, isl_dim_in, 0, dim->n_in, names + nparam);
469 get_names(dim, isl_dim_out, 0, dim->n_out,
470 names + nparam + n_in);
473 dim->n_name = nparam + n_in + n_out;
475 dim->nparam = nparam;
486 struct isl_dim *isl_dim_add(struct isl_dim *dim, enum isl_dim_type type,
491 dim = isl_dim_reset(dim, type);
494 dim = isl_dim_extend(dim,
495 dim->nparam + n, dim->n_in, dim->n_out);
496 if (dim && dim->nested[0] &&
497 !(dim->nested[0] = isl_dim_add(dim->nested[0],
500 if (dim && dim->nested[1] &&
501 !(dim->nested[1] = isl_dim_add(dim->nested[1],
506 return isl_dim_extend(dim,
507 dim->nparam, dim->n_in + n, dim->n_out);
509 return isl_dim_extend(dim,
510 dim->nparam, dim->n_in, dim->n_out + n);
518 __isl_give isl_dim *isl_dim_insert(__isl_take isl_dim *dim,
519 enum isl_dim_type type, unsigned pos, unsigned n)
521 struct isl_name **names = NULL;
526 return isl_dim_reset(dim, type);
528 isl_assert(dim->ctx, pos <= isl_dim_size(dim, type), goto error);
530 dim = isl_dim_cow(dim);
538 int *size = s - isl_dim_param;
539 names = isl_calloc_array(dim->ctx, struct isl_name *,
540 dim->nparam + dim->n_in + dim->n_out + n);
544 size[isl_dim_param] = dim->nparam;
545 size[isl_dim_in] = dim->n_in;
546 size[isl_dim_out] = dim->n_out;
547 for (t = isl_dim_param; t <= isl_dim_out; ++t) {
549 get_names(dim, t, 0, size[t], names + off);
552 get_names(dim, t, 0, pos, names + off);
554 get_names(dim, t, pos, size[t]-pos, names+off);
555 off += size[t] - pos;
560 dim->n_name = dim->nparam + dim->n_in + dim->n_out + n;
563 case isl_dim_param: dim->nparam += n; break;
564 case isl_dim_in: dim->n_in += n; break;
565 case isl_dim_out: dim->n_out += n; break;
567 dim = isl_dim_reset(dim, type);
575 __isl_give isl_dim *isl_dim_move(__isl_take isl_dim *dim,
576 enum isl_dim_type dst_type, unsigned dst_pos,
577 enum isl_dim_type src_type, unsigned src_pos, unsigned n)
584 isl_assert(dim->ctx, src_pos + n <= isl_dim_size(dim, src_type),
587 if (dst_type == src_type && dst_pos == src_pos)
590 isl_assert(dim->ctx, dst_type != src_type, goto error);
592 dim = isl_dim_reset(dim, src_type);
593 dim = isl_dim_reset(dim, dst_type);
595 dim = isl_dim_cow(dim);
600 struct isl_name **names;
604 int *size = s - isl_dim_param;
605 names = isl_calloc_array(dim->ctx, struct isl_name *,
606 dim->nparam + dim->n_in + dim->n_out);
610 size[isl_dim_param] = dim->nparam;
611 size[isl_dim_in] = dim->n_in;
612 size[isl_dim_out] = dim->n_out;
613 for (t = isl_dim_param; t <= isl_dim_out; ++t) {
615 get_names(dim, t, 0, dst_pos, names + off);
617 get_names(dim, src_type, src_pos, n, names+off);
619 get_names(dim, t, dst_pos, size[t] - dst_pos,
621 off += size[t] - dst_pos;
622 } else if (t == src_type) {
623 get_names(dim, t, 0, src_pos, names + off);
625 get_names(dim, t, src_pos + n,
626 size[t] - src_pos - n, names + off);
627 off += size[t] - src_pos - n;
629 get_names(dim, t, 0, size[t], names + off);
635 dim->n_name = dim->nparam + dim->n_in + dim->n_out;
639 case isl_dim_param: dim->nparam += n; break;
640 case isl_dim_in: dim->n_in += n; break;
641 case isl_dim_out: dim->n_out += n; break;
645 case isl_dim_param: dim->nparam -= n; break;
646 case isl_dim_in: dim->n_in -= n; break;
647 case isl_dim_out: dim->n_out -= n; break;
656 struct isl_dim *isl_dim_join(struct isl_dim *left, struct isl_dim *right)
663 isl_assert(left->ctx, match(left, isl_dim_param, right, isl_dim_param),
665 isl_assert(left->ctx,
666 isl_dim_tuple_match(left, isl_dim_out, right, isl_dim_in),
669 dim = isl_dim_alloc(left->ctx, left->nparam, left->n_in, right->n_out);
673 dim = copy_names(dim, isl_dim_param, 0, left, isl_dim_param);
674 dim = copy_names(dim, isl_dim_in, 0, left, isl_dim_in);
675 dim = copy_names(dim, isl_dim_out, 0, right, isl_dim_out);
677 if (dim && left->tuple_name[0] &&
678 !(dim->tuple_name[0] = isl_name_copy(dim->ctx, left->tuple_name[0])))
680 if (dim && right->tuple_name[1] &&
681 !(dim->tuple_name[1] = isl_name_copy(dim->ctx, right->tuple_name[1])))
683 if (dim && left->nested[0] &&
684 !(dim->nested[0] = isl_dim_copy(left->nested[0])))
686 if (dim && right->nested[1] &&
687 !(dim->nested[1] = isl_dim_copy(right->nested[1])))
700 struct isl_dim *isl_dim_product(struct isl_dim *left, struct isl_dim *right)
702 isl_dim *dom1, *dom2, *nest1, *nest2;
707 isl_assert(left->ctx, match(left, isl_dim_param, right, isl_dim_param),
710 dom1 = isl_dim_domain(isl_dim_copy(left));
711 dom2 = isl_dim_domain(isl_dim_copy(right));
712 nest1 = isl_dim_wrap(isl_dim_join(isl_dim_reverse(dom1), dom2));
714 dom1 = isl_dim_range(left);
715 dom2 = isl_dim_range(right);
716 nest2 = isl_dim_wrap(isl_dim_join(isl_dim_reverse(dom1), dom2));
718 return isl_dim_join(isl_dim_reverse(nest1), nest2);
725 struct isl_dim *isl_dim_map(struct isl_dim *dim)
727 struct isl_name **names = NULL;
731 isl_assert(dim->ctx, dim->n_in == 0, goto error);
732 if (dim->n_out == 0 && !isl_dim_is_named_or_nested(dim, isl_dim_out))
734 dim = isl_dim_cow(dim);
738 names = isl_calloc_array(dim->ctx, struct isl_name *,
739 dim->nparam + dim->n_out + dim->n_out);
742 get_names(dim, isl_dim_param, 0, dim->nparam, names);
743 get_names(dim, isl_dim_out, 0, dim->n_out, names + dim->nparam);
745 dim->n_in = dim->n_out;
749 dim->n_name = dim->nparam + dim->n_out + dim->n_out;
750 dim = copy_names(dim, isl_dim_out, 0, dim, isl_dim_in);
752 isl_name_free(dim->ctx, dim->tuple_name[0]);
753 dim->tuple_name[0] = isl_name_copy(dim->ctx, dim->tuple_name[1]);
754 isl_dim_free(dim->nested[0]);
755 dim->nested[0] = isl_dim_copy(dim->nested[1]);
762 static struct isl_dim *set_names(struct isl_dim *dim, enum isl_dim_type type,
763 unsigned first, unsigned n, struct isl_name **names)
767 for (i = 0; i < n ; ++i)
768 dim = set_name(dim, type, first+i, names[i]);
773 struct isl_dim *isl_dim_reverse(struct isl_dim *dim)
777 struct isl_name **names = NULL;
778 struct isl_name *name;
782 if (match(dim, isl_dim_in, dim, isl_dim_out))
785 dim = isl_dim_cow(dim);
789 name = dim->tuple_name[0];
790 dim->tuple_name[0] = dim->tuple_name[1];
791 dim->tuple_name[1] = name;
793 nested = dim->nested[0];
794 dim->nested[0] = dim->nested[1];
795 dim->nested[1] = nested;
798 names = isl_alloc_array(dim->ctx, struct isl_name *,
799 dim->n_in + dim->n_out);
802 get_names(dim, isl_dim_in, 0, dim->n_in, names);
803 get_names(dim, isl_dim_out, 0, dim->n_out, names + dim->n_in);
807 dim->n_in = dim->n_out;
811 dim = set_names(dim, isl_dim_out, 0, dim->n_out, names);
812 dim = set_names(dim, isl_dim_in, 0, dim->n_in, names + dim->n_out);
823 struct isl_dim *isl_dim_drop(struct isl_dim *dim, enum isl_dim_type type,
824 unsigned first, unsigned num)
832 return isl_dim_reset(dim, type);
834 isl_assert(dim->ctx, first + num <= n(dim, type), goto error);
835 dim = isl_dim_cow(dim);
839 dim = extend_names(dim);
842 for (i = 0; i < num; ++i)
843 isl_name_free(dim->ctx, get_name(dim, type, first+i));
844 for (i = first+num; i < n(dim, type); ++i)
845 set_name(dim, type, i - num, get_name(dim, type, i));
848 get_names(dim, isl_dim_in, 0, dim->n_in,
849 dim->names + offset(dim, isl_dim_in) - num);
851 get_names(dim, isl_dim_out, 0, dim->n_out,
852 dim->names + offset(dim, isl_dim_out) - num);
859 case isl_dim_param: dim->nparam -= num; break;
860 case isl_dim_in: dim->n_in -= num; break;
861 case isl_dim_out: dim->n_out -= num; break;
863 dim = isl_dim_reset(dim, type);
864 if (type == isl_dim_param) {
865 if (dim && dim->nested[0] &&
866 !(dim->nested[0] = isl_dim_drop(dim->nested[0],
867 isl_dim_param, first, num)))
869 if (dim && dim->nested[1] &&
870 !(dim->nested[1] = isl_dim_drop(dim->nested[1],
871 isl_dim_param, first, num)))
880 struct isl_dim *isl_dim_drop_inputs(struct isl_dim *dim,
881 unsigned first, unsigned n)
885 return isl_dim_drop(dim, isl_dim_in, first, n);
888 struct isl_dim *isl_dim_drop_outputs(struct isl_dim *dim,
889 unsigned first, unsigned n)
893 return isl_dim_drop(dim, isl_dim_out, first, n);
896 struct isl_dim *isl_dim_domain(struct isl_dim *dim)
900 dim = isl_dim_drop_outputs(dim, 0, dim->n_out);
901 return isl_dim_reverse(dim);
904 __isl_give isl_dim *isl_dim_from_domain(__isl_take isl_dim *dim)
906 return isl_dim_reverse(dim);
909 struct isl_dim *isl_dim_range(struct isl_dim *dim)
913 return isl_dim_drop_inputs(dim, 0, dim->n_in);
916 __isl_give isl_dim *isl_dim_from_range(__isl_take isl_dim *dim)
921 __isl_give isl_dim *isl_dim_as_set_dim(__isl_take isl_dim *dim)
923 dim = isl_dim_cow(dim);
927 dim->n_out += dim->n_in;
929 dim = isl_dim_reset(dim, isl_dim_in);
930 dim = isl_dim_reset(dim, isl_dim_out);
935 struct isl_dim *isl_dim_underlying(struct isl_dim *dim, unsigned n_div)
942 dim->nparam == 0 && dim->n_in == 0 && dim->n_name == 0)
943 return isl_dim_reset(isl_dim_reset(dim, isl_dim_in), isl_dim_out);
944 dim = isl_dim_cow(dim);
947 dim->n_out += dim->nparam + dim->n_in + n_div;
951 for (i = 0; i < dim->n_name; ++i)
952 isl_name_free(dim->ctx, get_name(dim, isl_dim_out, i));
954 dim = isl_dim_reset(dim, isl_dim_in);
955 dim = isl_dim_reset(dim, isl_dim_out);
960 unsigned isl_dim_total(struct isl_dim *dim)
962 return dim ? dim->nparam + dim->n_in + dim->n_out : 0;
965 int isl_dim_equal(struct isl_dim *dim1, struct isl_dim *dim2)
967 return match(dim1, isl_dim_param, dim2, isl_dim_param) &&
968 isl_dim_tuple_match(dim1, isl_dim_in, dim2, isl_dim_in) &&
969 isl_dim_tuple_match(dim1, isl_dim_out, dim2, isl_dim_out);
972 int isl_dim_compatible(struct isl_dim *dim1, struct isl_dim *dim2)
974 return dim1->nparam == dim2->nparam &&
975 dim1->n_in + dim1->n_out == dim2->n_in + dim2->n_out;
978 static uint32_t isl_hash_dim(uint32_t hash, __isl_keep isl_dim *dim)
981 struct isl_name *name;
986 hash = isl_hash_builtin(hash, dim->nparam);
987 hash = isl_hash_builtin(hash, dim->n_in);
988 hash = isl_hash_builtin(hash, dim->n_out);
990 for (i = 0; i < dim->nparam; ++i) {
991 name = get_name(dim, isl_dim_param, i);
992 hash = isl_hash_name(hash, name);
995 name = tuple_name(dim, isl_dim_in);
996 hash = isl_hash_name(hash, name);
997 name = tuple_name(dim, isl_dim_out);
998 hash = isl_hash_name(hash, name);
1000 hash = isl_hash_dim(hash, dim->nested[0]);
1001 hash = isl_hash_dim(hash, dim->nested[1]);
1006 uint32_t isl_dim_get_hash(__isl_keep isl_dim *dim)
1013 hash = isl_hash_init();
1014 hash = isl_hash_dim(hash, dim);
1019 int isl_dim_is_wrapping(__isl_keep isl_dim *dim)
1024 if (dim->n_in != 0 || dim->tuple_name[0] || dim->nested[0])
1027 return dim->nested[1] != NULL;
1030 __isl_give isl_dim *isl_dim_wrap(__isl_take isl_dim *dim)
1037 wrap = isl_dim_alloc(dim->ctx, dim->nparam, 0, dim->n_in + dim->n_out);
1039 wrap = copy_names(wrap, isl_dim_param, 0, dim, isl_dim_param);
1040 wrap = copy_names(wrap, isl_dim_set, 0, dim, isl_dim_in);
1041 wrap = copy_names(wrap, isl_dim_set, dim->n_in, dim, isl_dim_out);
1046 wrap->nested[1] = dim;
1054 __isl_give isl_dim *isl_dim_unwrap(__isl_take isl_dim *dim)
1061 if (!isl_dim_is_wrapping(dim))
1062 isl_die(dim->ctx, isl_error_invalid, "not a wrapping dim",
1065 unwrap = isl_dim_copy(dim->nested[1]);
1074 int isl_dim_is_named_or_nested(__isl_keep isl_dim *dim, enum isl_dim_type type)
1076 if (type != isl_dim_in && type != isl_dim_out)
1080 if (dim->tuple_name[type - isl_dim_in])
1082 if (dim->nested[type - isl_dim_in])
1087 __isl_give isl_dim *isl_dim_reset(__isl_take isl_dim *dim,
1088 enum isl_dim_type type)
1090 if (!isl_dim_is_named_or_nested(dim, type))
1093 dim = isl_dim_cow(dim);
1097 isl_name_free(dim->ctx, dim->tuple_name[type - isl_dim_in]);
1098 dim->tuple_name[type - isl_dim_in] = NULL;
1099 isl_dim_free(dim->nested[type - isl_dim_in]);
1100 dim->nested[type - isl_dim_in] = NULL;
1105 __isl_give isl_dim *isl_dim_flatten(__isl_take isl_dim *dim)
1109 if (!dim->nested[0] && !dim->nested[1])
1113 dim = isl_dim_reset(dim, isl_dim_in);
1114 if (dim && dim->nested[1])
1115 dim = isl_dim_reset(dim, isl_dim_out);
1120 /* Replace the dimensions of the given type of dst by those of src.
1122 __isl_give isl_dim *isl_dim_replace(__isl_take isl_dim *dst,
1123 enum isl_dim_type type, __isl_keep isl_dim *src)
1125 dst = isl_dim_cow(dst);
1130 dst = isl_dim_drop(dst, type, 0, isl_dim_size(dst, type));
1131 dst = isl_dim_add(dst, type, isl_dim_size(src, type));
1132 dst = copy_names(dst, type, 0, src, type);
1134 if (dst && type == isl_dim_param) {
1136 for (i = 0; i <= 1; ++i) {
1137 if (!dst->nested[i])
1139 dst->nested[i] = isl_dim_replace(dst->nested[i],
1141 if (!dst->nested[i])