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 name = isl_name_get(dim->ctx, s);
351 return set_name(dim, type, pos, name);
357 const char *isl_dim_get_name(struct isl_dim *dim,
358 enum isl_dim_type type, unsigned pos)
360 struct isl_name *name = get_name(dim, type, pos);
361 return name ? name->name : NULL;
364 static struct isl_name *tuple_name(__isl_keep isl_dim *dim,
365 enum isl_dim_type type)
369 if (type == isl_dim_in)
370 return dim->tuple_name[0];
371 if (type == isl_dim_out)
372 return dim->tuple_name[1];
376 static __isl_keep isl_dim *nested(__isl_keep isl_dim *dim,
377 enum isl_dim_type type)
381 if (type == isl_dim_in)
382 return dim->nested[0];
383 if (type == isl_dim_out)
384 return dim->nested[1];
388 int isl_dim_tuple_match(__isl_keep isl_dim *dim1, enum isl_dim_type dim1_type,
389 __isl_keep isl_dim *dim2, enum isl_dim_type dim2_type)
391 struct isl_name *name1, *name2;
392 isl_dim *nested1, *nested2;
394 if (n(dim1, dim1_type) != n(dim2, dim2_type))
396 name1 = tuple_name(dim1, dim1_type);
397 name2 = tuple_name(dim2, dim2_type);
400 if (name1 && name1->name != name2->name)
402 nested1 = nested(dim1, dim1_type);
403 nested2 = nested(dim2, dim2_type);
404 if (!nested1 ^ !nested2)
406 if (nested1 && !isl_dim_equal(nested1, nested2))
411 static int match(struct isl_dim *dim1, enum isl_dim_type dim1_type,
412 struct isl_dim *dim2, enum isl_dim_type dim2_type)
416 if (!isl_dim_tuple_match(dim1, dim1_type, dim2, dim2_type))
419 if (!dim1->names && !dim2->names)
422 for (i = 0; i < n(dim1, dim1_type); ++i) {
423 if (get_name(dim1, dim1_type, i) !=
424 get_name(dim2, dim2_type, i))
430 int isl_dim_match(struct isl_dim *dim1, enum isl_dim_type dim1_type,
431 struct isl_dim *dim2, enum isl_dim_type dim2_type)
433 return match(dim1, dim1_type, dim2, dim2_type);
436 static void get_names(struct isl_dim *dim, enum isl_dim_type type,
437 unsigned first, unsigned n, struct isl_name **names)
441 for (i = 0; i < n ; ++i)
442 names[i] = get_name(dim, type, first+i);
445 struct isl_dim *isl_dim_extend(struct isl_dim *dim,
446 unsigned nparam, unsigned n_in, unsigned n_out)
448 struct isl_name **names = NULL;
452 if (dim->nparam == nparam && dim->n_in == n_in && dim->n_out == n_out)
455 isl_assert(dim->ctx, dim->nparam <= nparam, goto error);
456 isl_assert(dim->ctx, dim->n_in <= n_in, goto error);
457 isl_assert(dim->ctx, dim->n_out <= n_out, goto error);
459 dim = isl_dim_cow(dim);
462 names = isl_calloc_array(dim->ctx, struct isl_name *,
463 nparam + n_in + n_out);
466 get_names(dim, isl_dim_param, 0, dim->nparam, names);
467 get_names(dim, isl_dim_in, 0, dim->n_in, names + nparam);
468 get_names(dim, isl_dim_out, 0, dim->n_out,
469 names + nparam + n_in);
472 dim->n_name = nparam + n_in + n_out;
474 dim->nparam = nparam;
485 struct isl_dim *isl_dim_add(struct isl_dim *dim, enum isl_dim_type type,
490 dim = isl_dim_reset(dim, type);
493 dim = isl_dim_extend(dim,
494 dim->nparam + n, dim->n_in, dim->n_out);
495 if (dim && dim->nested[0] &&
496 !(dim->nested[0] = isl_dim_add(dim->nested[0],
499 if (dim && dim->nested[1] &&
500 !(dim->nested[1] = isl_dim_add(dim->nested[1],
505 return isl_dim_extend(dim,
506 dim->nparam, dim->n_in + n, dim->n_out);
508 return isl_dim_extend(dim,
509 dim->nparam, dim->n_in, dim->n_out + n);
517 __isl_give isl_dim *isl_dim_insert(__isl_take isl_dim *dim,
518 enum isl_dim_type type, unsigned pos, unsigned n)
520 struct isl_name **names = NULL;
525 return isl_dim_reset(dim, type);
527 isl_assert(dim->ctx, pos <= isl_dim_size(dim, type), goto error);
529 dim = isl_dim_cow(dim);
537 int *size = s - isl_dim_param;
538 names = isl_calloc_array(dim->ctx, struct isl_name *,
539 dim->nparam + dim->n_in + dim->n_out + n);
543 size[isl_dim_param] = dim->nparam;
544 size[isl_dim_in] = dim->n_in;
545 size[isl_dim_out] = dim->n_out;
546 for (t = isl_dim_param; t <= isl_dim_out; ++t) {
548 get_names(dim, t, 0, size[t], names + off);
551 get_names(dim, t, 0, pos, names + off);
553 get_names(dim, t, pos, size[t]-pos, names+off);
554 off += size[t] - pos;
559 dim->n_name = dim->nparam + dim->n_in + dim->n_out + n;
562 case isl_dim_param: dim->nparam += n; break;
563 case isl_dim_in: dim->n_in += n; break;
564 case isl_dim_out: dim->n_out += n; break;
566 dim = isl_dim_reset(dim, type);
574 __isl_give isl_dim *isl_dim_move(__isl_take isl_dim *dim,
575 enum isl_dim_type dst_type, unsigned dst_pos,
576 enum isl_dim_type src_type, unsigned src_pos, unsigned n)
583 isl_assert(dim->ctx, src_pos + n <= isl_dim_size(dim, src_type),
586 if (dst_type == src_type && dst_pos == src_pos)
589 isl_assert(dim->ctx, dst_type != src_type, goto error);
591 dim = isl_dim_reset(dim, src_type);
592 dim = isl_dim_reset(dim, dst_type);
594 dim = isl_dim_cow(dim);
599 struct isl_name **names;
603 int *size = s - isl_dim_param;
604 names = isl_calloc_array(dim->ctx, struct isl_name *,
605 dim->nparam + dim->n_in + dim->n_out);
609 size[isl_dim_param] = dim->nparam;
610 size[isl_dim_in] = dim->n_in;
611 size[isl_dim_out] = dim->n_out;
612 for (t = isl_dim_param; t <= isl_dim_out; ++t) {
614 get_names(dim, t, 0, dst_pos, names + off);
616 get_names(dim, src_type, src_pos, n, names+off);
618 get_names(dim, t, dst_pos, size[t] - dst_pos,
620 off += size[t] - dst_pos;
621 } else if (t == src_type) {
622 get_names(dim, t, 0, src_pos, names + off);
624 get_names(dim, t, src_pos + n,
625 size[t] - src_pos - n, names + off);
626 off += size[t] - src_pos - n;
628 get_names(dim, t, 0, size[t], names + off);
634 dim->n_name = dim->nparam + dim->n_in + dim->n_out;
638 case isl_dim_param: dim->nparam += n; break;
639 case isl_dim_in: dim->n_in += n; break;
640 case isl_dim_out: dim->n_out += n; break;
644 case isl_dim_param: dim->nparam -= n; break;
645 case isl_dim_in: dim->n_in -= n; break;
646 case isl_dim_out: dim->n_out -= n; break;
655 struct isl_dim *isl_dim_join(struct isl_dim *left, struct isl_dim *right)
662 isl_assert(left->ctx, match(left, isl_dim_param, right, isl_dim_param),
664 isl_assert(left->ctx,
665 isl_dim_tuple_match(left, isl_dim_out, right, isl_dim_in),
668 dim = isl_dim_alloc(left->ctx, left->nparam, left->n_in, right->n_out);
672 dim = copy_names(dim, isl_dim_param, 0, left, isl_dim_param);
673 dim = copy_names(dim, isl_dim_in, 0, left, isl_dim_in);
674 dim = copy_names(dim, isl_dim_out, 0, right, isl_dim_out);
676 if (dim && left->tuple_name[0] &&
677 !(dim->tuple_name[0] = isl_name_copy(dim->ctx, left->tuple_name[0])))
679 if (dim && right->tuple_name[1] &&
680 !(dim->tuple_name[1] = isl_name_copy(dim->ctx, right->tuple_name[1])))
682 if (dim && left->nested[0] &&
683 !(dim->nested[0] = isl_dim_copy(left->nested[0])))
685 if (dim && right->nested[1] &&
686 !(dim->nested[1] = isl_dim_copy(right->nested[1])))
699 struct isl_dim *isl_dim_product(struct isl_dim *left, struct isl_dim *right)
701 isl_dim *dom1, *dom2, *nest1, *nest2;
706 isl_assert(left->ctx, match(left, isl_dim_param, right, isl_dim_param),
709 dom1 = isl_dim_domain(isl_dim_copy(left));
710 dom2 = isl_dim_domain(isl_dim_copy(right));
711 nest1 = isl_dim_wrap(isl_dim_join(isl_dim_reverse(dom1), dom2));
713 dom1 = isl_dim_range(left);
714 dom2 = isl_dim_range(right);
715 nest2 = isl_dim_wrap(isl_dim_join(isl_dim_reverse(dom1), dom2));
717 return isl_dim_join(isl_dim_reverse(nest1), nest2);
724 struct isl_dim *isl_dim_map(struct isl_dim *dim)
726 struct isl_name **names = NULL;
730 isl_assert(dim->ctx, dim->n_in == 0, goto error);
731 if (dim->n_out == 0 && !isl_dim_is_named_or_nested(dim, isl_dim_out))
733 dim = isl_dim_cow(dim);
737 names = isl_calloc_array(dim->ctx, struct isl_name *,
738 dim->nparam + dim->n_out + dim->n_out);
741 get_names(dim, isl_dim_param, 0, dim->nparam, names);
742 get_names(dim, isl_dim_out, 0, dim->n_out, names + dim->nparam);
744 dim->n_in = dim->n_out;
748 dim->n_name = dim->nparam + dim->n_out + dim->n_out;
749 dim = copy_names(dim, isl_dim_out, 0, dim, isl_dim_in);
751 isl_name_free(dim->ctx, dim->tuple_name[0]);
752 dim->tuple_name[0] = isl_name_copy(dim->ctx, dim->tuple_name[1]);
753 isl_dim_free(dim->nested[0]);
754 dim->nested[0] = isl_dim_copy(dim->nested[1]);
761 static struct isl_dim *set_names(struct isl_dim *dim, enum isl_dim_type type,
762 unsigned first, unsigned n, struct isl_name **names)
766 for (i = 0; i < n ; ++i)
767 dim = set_name(dim, type, first+i, names[i]);
772 struct isl_dim *isl_dim_reverse(struct isl_dim *dim)
776 struct isl_name **names = NULL;
777 struct isl_name *name;
781 if (match(dim, isl_dim_in, dim, isl_dim_out))
784 dim = isl_dim_cow(dim);
788 name = dim->tuple_name[0];
789 dim->tuple_name[0] = dim->tuple_name[1];
790 dim->tuple_name[1] = name;
792 nested = dim->nested[0];
793 dim->nested[0] = dim->nested[1];
794 dim->nested[1] = nested;
797 names = isl_alloc_array(dim->ctx, struct isl_name *,
798 dim->n_in + dim->n_out);
801 get_names(dim, isl_dim_in, 0, dim->n_in, names);
802 get_names(dim, isl_dim_out, 0, dim->n_out, names + dim->n_in);
806 dim->n_in = dim->n_out;
810 dim = set_names(dim, isl_dim_out, 0, dim->n_out, names);
811 dim = set_names(dim, isl_dim_in, 0, dim->n_in, names + dim->n_out);
822 struct isl_dim *isl_dim_drop(struct isl_dim *dim, enum isl_dim_type type,
823 unsigned first, unsigned num)
831 return isl_dim_reset(dim, type);
833 isl_assert(dim->ctx, first + num <= n(dim, type), goto error);
834 dim = isl_dim_cow(dim);
838 dim = extend_names(dim);
841 for (i = 0; i < num; ++i)
842 isl_name_free(dim->ctx, get_name(dim, type, first+i));
843 for (i = first+num; i < n(dim, type); ++i)
844 set_name(dim, type, i - num, get_name(dim, type, i));
847 get_names(dim, isl_dim_in, 0, dim->n_in,
848 dim->names + offset(dim, isl_dim_in) - num);
850 get_names(dim, isl_dim_out, 0, dim->n_out,
851 dim->names + offset(dim, isl_dim_out) - num);
858 case isl_dim_param: dim->nparam -= num; break;
859 case isl_dim_in: dim->n_in -= num; break;
860 case isl_dim_out: dim->n_out -= num; break;
862 dim = isl_dim_reset(dim, type);
863 if (type == isl_dim_param) {
864 if (dim && dim->nested[0] &&
865 !(dim->nested[0] = isl_dim_drop(dim->nested[0],
866 isl_dim_param, first, num)))
868 if (dim && dim->nested[1] &&
869 !(dim->nested[1] = isl_dim_drop(dim->nested[1],
870 isl_dim_param, first, num)))
879 struct isl_dim *isl_dim_drop_inputs(struct isl_dim *dim,
880 unsigned first, unsigned n)
884 return isl_dim_drop(dim, isl_dim_in, first, n);
887 struct isl_dim *isl_dim_drop_outputs(struct isl_dim *dim,
888 unsigned first, unsigned n)
892 return isl_dim_drop(dim, isl_dim_out, first, n);
895 struct isl_dim *isl_dim_domain(struct isl_dim *dim)
899 dim = isl_dim_drop_outputs(dim, 0, dim->n_out);
900 return isl_dim_reverse(dim);
903 __isl_give isl_dim *isl_dim_from_domain(__isl_take isl_dim *dim)
905 return isl_dim_reverse(dim);
908 struct isl_dim *isl_dim_range(struct isl_dim *dim)
912 return isl_dim_drop_inputs(dim, 0, dim->n_in);
915 __isl_give isl_dim *isl_dim_from_range(__isl_take isl_dim *dim)
920 __isl_give isl_dim *isl_dim_as_set_dim(__isl_take isl_dim *dim)
922 dim = isl_dim_cow(dim);
926 dim->n_out += dim->n_in;
928 dim = isl_dim_reset(dim, isl_dim_in);
929 dim = isl_dim_reset(dim, isl_dim_out);
934 struct isl_dim *isl_dim_underlying(struct isl_dim *dim, unsigned n_div)
941 dim->nparam == 0 && dim->n_in == 0 && dim->n_name == 0)
942 return isl_dim_reset(isl_dim_reset(dim, isl_dim_in), isl_dim_out);
943 dim = isl_dim_cow(dim);
946 dim->n_out += dim->nparam + dim->n_in + n_div;
950 for (i = 0; i < dim->n_name; ++i)
951 isl_name_free(dim->ctx, get_name(dim, isl_dim_out, i));
953 dim = isl_dim_reset(dim, isl_dim_in);
954 dim = isl_dim_reset(dim, isl_dim_out);
959 unsigned isl_dim_total(struct isl_dim *dim)
961 return dim ? dim->nparam + dim->n_in + dim->n_out : 0;
964 int isl_dim_equal(struct isl_dim *dim1, struct isl_dim *dim2)
966 return match(dim1, isl_dim_param, dim2, isl_dim_param) &&
967 isl_dim_tuple_match(dim1, isl_dim_in, dim2, isl_dim_in) &&
968 isl_dim_tuple_match(dim1, isl_dim_out, dim2, isl_dim_out);
971 int isl_dim_compatible(struct isl_dim *dim1, struct isl_dim *dim2)
973 return dim1->nparam == dim2->nparam &&
974 dim1->n_in + dim1->n_out == dim2->n_in + dim2->n_out;
977 static uint32_t isl_hash_dim(uint32_t hash, __isl_keep isl_dim *dim)
980 struct isl_name *name;
985 hash = isl_hash_builtin(hash, dim->nparam);
986 hash = isl_hash_builtin(hash, dim->n_in);
987 hash = isl_hash_builtin(hash, dim->n_out);
989 for (i = 0; i < dim->nparam; ++i) {
990 name = get_name(dim, isl_dim_param, i);
991 hash = isl_hash_builtin(hash, name);
994 name = tuple_name(dim, isl_dim_in);
995 hash = isl_hash_builtin(hash, name);
996 name = tuple_name(dim, isl_dim_out);
997 hash = isl_hash_builtin(hash, name);
999 hash = isl_hash_dim(hash, dim->nested[0]);
1000 hash = isl_hash_dim(hash, dim->nested[1]);
1005 uint32_t isl_dim_get_hash(__isl_keep isl_dim *dim)
1012 hash = isl_hash_init();
1013 hash = isl_hash_dim(hash, dim);
1018 int isl_dim_is_wrapping(__isl_keep isl_dim *dim)
1023 if (dim->n_in != 0 || dim->tuple_name[0] || dim->nested[0])
1026 return dim->nested[1] != NULL;
1029 __isl_give isl_dim *isl_dim_wrap(__isl_take isl_dim *dim)
1036 wrap = isl_dim_alloc(dim->ctx, dim->nparam, 0, dim->n_in + dim->n_out);
1038 wrap = copy_names(wrap, isl_dim_param, 0, dim, isl_dim_param);
1039 wrap = copy_names(wrap, isl_dim_set, 0, dim, isl_dim_in);
1040 wrap = copy_names(wrap, isl_dim_set, dim->n_in, dim, isl_dim_out);
1045 wrap->nested[1] = dim;
1053 __isl_give isl_dim *isl_dim_unwrap(__isl_take isl_dim *dim)
1060 if (!isl_dim_is_wrapping(dim))
1061 isl_die(dim->ctx, isl_error_invalid, "not a wrapping dim",
1064 unwrap = isl_dim_copy(dim->nested[1]);
1073 int isl_dim_is_named_or_nested(__isl_keep isl_dim *dim, enum isl_dim_type type)
1075 if (type != isl_dim_in && type != isl_dim_out)
1079 if (dim->tuple_name[type - isl_dim_in])
1081 if (dim->nested[type - isl_dim_in])
1086 __isl_give isl_dim *isl_dim_reset(__isl_take isl_dim *dim,
1087 enum isl_dim_type type)
1089 if (!isl_dim_is_named_or_nested(dim, type))
1092 dim = isl_dim_cow(dim);
1096 isl_name_free(dim->ctx, dim->tuple_name[type - isl_dim_in]);
1097 dim->tuple_name[type - isl_dim_in] = NULL;
1098 isl_dim_free(dim->nested[type - isl_dim_in]);
1099 dim->nested[type - isl_dim_in] = NULL;
1104 __isl_give isl_dim *isl_dim_flatten(__isl_take isl_dim *dim)
1108 if (!dim->nested[0] && !dim->nested[1])
1112 dim = isl_dim_reset(dim, isl_dim_in);
1113 if (dim && dim->nested[1])
1114 dim = isl_dim_reset(dim, isl_dim_out);
1119 /* Replace the dimensions of the given type of dst by those of src.
1121 __isl_give isl_dim *isl_dim_replace(__isl_take isl_dim *dst,
1122 enum isl_dim_type type, __isl_keep isl_dim *src)
1124 dst = isl_dim_cow(dst);
1129 dst = isl_dim_drop(dst, type, 0, isl_dim_size(dst, type));
1130 dst = isl_dim_add(dst, type, isl_dim_size(src, type));
1131 dst = copy_names(dst, type, 0, src, type);
1133 if (dst && type == isl_dim_param) {
1135 for (i = 0; i <= 1; ++i) {
1136 if (!dst->nested[i])
1138 dst->nested[i] = isl_dim_replace(dst->nested[i],
1140 if (!dst->nested[i])