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 isl_assert(ctx
, pos
!= isl_dim_total(dim
), goto error
);
123 if (pos
>= dim
->n_name
) {
126 dim
= extend_names(dim
);
131 dim
->names
[pos
] = name
;
135 isl_name_free(ctx
, name
);
140 static struct isl_name
*get_name(struct isl_dim
*dim
,
141 enum isl_dim_type type
, unsigned pos
)
146 pos
= global_pos(dim
, type
, pos
);
147 if (pos
== isl_dim_total(dim
))
149 if (pos
>= dim
->n_name
)
151 return dim
->names
[pos
];
154 static unsigned offset(struct isl_dim
*dim
, enum isl_dim_type type
)
157 case isl_dim_param
: return 0;
158 case isl_dim_in
: return dim
->nparam
;
159 case isl_dim_out
: return dim
->nparam
+ dim
->n_in
;
164 static unsigned n(struct isl_dim
*dim
, enum isl_dim_type type
)
167 case isl_dim_param
: return dim
->nparam
;
168 case isl_dim_in
: return dim
->n_in
;
169 case isl_dim_out
: return dim
->n_out
;
174 unsigned isl_dim_size(struct isl_dim
*dim
, enum isl_dim_type type
)
181 unsigned isl_dim_offset(__isl_keep isl_dim
*dim
, enum isl_dim_type type
)
185 return offset(dim
, type
);
188 static struct isl_dim
*copy_names(struct isl_dim
*dst
,
189 enum isl_dim_type dst_type
, unsigned offset
, struct isl_dim
*src
,
190 enum isl_dim_type src_type
)
193 struct isl_name
*name
;
198 for (i
= 0; i
< n(src
, src_type
); ++i
) {
199 name
= get_name(src
, src_type
, i
);
202 dst
= set_name(dst
, dst_type
, offset
+ i
,
203 isl_name_copy(dst
->ctx
, name
));
210 struct isl_dim
*isl_dim_dup(struct isl_dim
*dim
)
215 dup
= isl_dim_alloc(dim
->ctx
, dim
->nparam
, dim
->n_in
, dim
->n_out
);
216 if (dim
->tuple_name
[0] &&
217 !(dup
->tuple_name
[0] = isl_name_copy(dim
->ctx
, dim
->tuple_name
[0])))
219 if (dim
->tuple_name
[1] &&
220 !(dup
->tuple_name
[1] = isl_name_copy(dim
->ctx
, dim
->tuple_name
[1])))
222 if (dim
->nested
[0] && !(dup
->nested
[0] = isl_dim_copy(dim
->nested
[0])))
224 if (dim
->nested
[1] && !(dup
->nested
[1] = isl_dim_copy(dim
->nested
[1])))
228 dup
= copy_names(dup
, isl_dim_param
, 0, dim
, isl_dim_param
);
229 dup
= copy_names(dup
, isl_dim_in
, 0, dim
, isl_dim_in
);
230 dup
= copy_names(dup
, isl_dim_out
, 0, dim
, isl_dim_out
);
237 struct isl_dim
*isl_dim_cow(struct isl_dim
*dim
)
245 return isl_dim_dup(dim
);
248 struct isl_dim
*isl_dim_copy(struct isl_dim
*dim
)
257 void isl_dim_free(struct isl_dim
*dim
)
267 isl_name_free(dim
->ctx
, dim
->tuple_name
[0]);
268 isl_name_free(dim
->ctx
, dim
->tuple_name
[1]);
270 isl_dim_free(dim
->nested
[0]);
271 isl_dim_free(dim
->nested
[1]);
273 for (i
= 0; i
< dim
->n_name
; ++i
)
274 isl_name_free(dim
->ctx
, dim
->names
[i
]);
276 isl_ctx_deref(dim
->ctx
);
281 static int name_ok(isl_ctx
*ctx
, const char *s
)
286 dummy
= strtol(s
, &p
, 0);
288 isl_die(ctx
, isl_error_invalid
, "name looks like a number",
294 __isl_give isl_dim
*isl_dim_set_tuple_name(__isl_take isl_dim
*dim
,
295 enum isl_dim_type type
, const char *s
)
297 struct isl_name
*name
;
299 dim
= isl_dim_cow(dim
);
302 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
303 isl_die(dim
->ctx
, isl_error_invalid
,
304 "only input, output and set tuples can have names",
309 if (!name_ok(dim
->ctx
, s
))
311 name
= isl_name_get(dim
->ctx
, s
);
316 isl_name_free(dim
->ctx
, dim
->tuple_name
[type
- isl_dim_in
]);
317 dim
->tuple_name
[type
- isl_dim_in
] = name
;
325 const char *isl_dim_get_tuple_name(__isl_keep isl_dim
*dim
,
326 enum isl_dim_type type
)
328 struct isl_name
*name
;
331 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
333 name
= dim
->tuple_name
[type
- isl_dim_in
];
334 return name
? name
->name
: NULL
;
337 struct isl_dim
*isl_dim_set_name(struct isl_dim
*dim
,
338 enum isl_dim_type type
, unsigned pos
,
341 struct isl_name
*name
;
345 if (!name_ok(dim
->ctx
, s
))
347 name
= isl_name_get(dim
->ctx
, s
);
350 return set_name(dim
, type
, pos
, name
);
356 const char *isl_dim_get_name(struct isl_dim
*dim
,
357 enum isl_dim_type type
, unsigned pos
)
359 struct isl_name
*name
= get_name(dim
, type
, pos
);
360 return name
? name
->name
: NULL
;
363 static struct isl_name
*tuple_name(__isl_keep isl_dim
*dim
,
364 enum isl_dim_type type
)
368 if (type
== isl_dim_in
)
369 return dim
->tuple_name
[0];
370 if (type
== isl_dim_out
)
371 return dim
->tuple_name
[1];
375 static __isl_keep isl_dim
*nested(__isl_keep isl_dim
*dim
,
376 enum isl_dim_type type
)
380 if (type
== isl_dim_in
)
381 return dim
->nested
[0];
382 if (type
== isl_dim_out
)
383 return dim
->nested
[1];
387 int isl_dim_tuple_match(__isl_keep isl_dim
*dim1
, enum isl_dim_type dim1_type
,
388 __isl_keep isl_dim
*dim2
, enum isl_dim_type dim2_type
)
390 struct isl_name
*name1
, *name2
;
391 isl_dim
*nested1
, *nested2
;
393 if (n(dim1
, dim1_type
) != n(dim2
, dim2_type
))
395 name1
= tuple_name(dim1
, dim1_type
);
396 name2
= tuple_name(dim2
, dim2_type
);
399 if (name1
&& name1
->name
!= name2
->name
)
401 nested1
= nested(dim1
, dim1_type
);
402 nested2
= nested(dim2
, dim2_type
);
403 if (!nested1
^ !nested2
)
405 if (nested1
&& !isl_dim_equal(nested1
, nested2
))
410 static int match(struct isl_dim
*dim1
, enum isl_dim_type dim1_type
,
411 struct isl_dim
*dim2
, enum isl_dim_type dim2_type
)
415 if (!isl_dim_tuple_match(dim1
, dim1_type
, dim2
, dim2_type
))
418 if (!dim1
->names
&& !dim2
->names
)
421 for (i
= 0; i
< n(dim1
, dim1_type
); ++i
) {
422 if (get_name(dim1
, dim1_type
, i
) !=
423 get_name(dim2
, dim2_type
, i
))
429 int isl_dim_match(struct isl_dim
*dim1
, enum isl_dim_type dim1_type
,
430 struct isl_dim
*dim2
, enum isl_dim_type dim2_type
)
432 return match(dim1
, dim1_type
, dim2
, dim2_type
);
435 static void get_names(struct isl_dim
*dim
, enum isl_dim_type type
,
436 unsigned first
, unsigned n
, struct isl_name
**names
)
440 for (i
= 0; i
< n
; ++i
)
441 names
[i
] = get_name(dim
, type
, first
+i
);
444 struct isl_dim
*isl_dim_extend(struct isl_dim
*dim
,
445 unsigned nparam
, unsigned n_in
, unsigned n_out
)
447 struct isl_name
**names
= NULL
;
451 if (dim
->nparam
== nparam
&& dim
->n_in
== n_in
&& dim
->n_out
== n_out
)
454 isl_assert(dim
->ctx
, dim
->nparam
<= nparam
, goto error
);
455 isl_assert(dim
->ctx
, dim
->n_in
<= n_in
, goto error
);
456 isl_assert(dim
->ctx
, dim
->n_out
<= n_out
, goto error
);
458 dim
= isl_dim_cow(dim
);
461 names
= isl_calloc_array(dim
->ctx
, struct isl_name
*,
462 nparam
+ n_in
+ n_out
);
465 get_names(dim
, isl_dim_param
, 0, dim
->nparam
, names
);
466 get_names(dim
, isl_dim_in
, 0, dim
->n_in
, names
+ nparam
);
467 get_names(dim
, isl_dim_out
, 0, dim
->n_out
,
468 names
+ nparam
+ n_in
);
471 dim
->n_name
= nparam
+ n_in
+ n_out
;
473 dim
->nparam
= nparam
;
484 struct isl_dim
*isl_dim_add(struct isl_dim
*dim
, enum isl_dim_type type
,
489 dim
= isl_dim_reset(dim
, type
);
492 return isl_dim_extend(dim
,
493 dim
->nparam
+ n
, dim
->n_in
, dim
->n_out
);
495 return isl_dim_extend(dim
,
496 dim
->nparam
, dim
->n_in
+ n
, dim
->n_out
);
498 return isl_dim_extend(dim
,
499 dim
->nparam
, dim
->n_in
, dim
->n_out
+ n
);
504 __isl_give isl_dim
*isl_dim_insert(__isl_take isl_dim
*dim
,
505 enum isl_dim_type type
, unsigned pos
, unsigned n
)
507 struct isl_name
**names
= NULL
;
512 return isl_dim_reset(dim
, type
);
514 isl_assert(dim
->ctx
, pos
<= isl_dim_size(dim
, type
), goto error
);
516 dim
= isl_dim_cow(dim
);
524 names
= isl_calloc_array(dim
->ctx
, struct isl_name
*,
525 dim
->nparam
+ dim
->n_in
+ dim
->n_out
+ n
);
529 size
[isl_dim_param
] = dim
->nparam
;
530 size
[isl_dim_in
] = dim
->n_in
;
531 size
[isl_dim_out
] = dim
->n_out
;
532 for (t
= isl_dim_param
; t
<= isl_dim_out
; ++t
) {
534 get_names(dim
, t
, 0, size
[t
], names
+ off
);
537 get_names(dim
, t
, 0, pos
, names
+ off
);
539 get_names(dim
, t
, pos
, size
[t
]-pos
, names
+off
);
540 off
+= size
[t
] - pos
;
545 dim
->n_name
= dim
->nparam
+ dim
->n_in
+ dim
->n_out
+ n
;
548 case isl_dim_param
: dim
->nparam
+= n
; break;
549 case isl_dim_in
: dim
->n_in
+= n
; break;
550 case isl_dim_out
: dim
->n_out
+= n
; break;
552 dim
= isl_dim_reset(dim
, type
);
560 __isl_give isl_dim
*isl_dim_move(__isl_take isl_dim
*dim
,
561 enum isl_dim_type dst_type
, unsigned dst_pos
,
562 enum isl_dim_type src_type
, unsigned src_pos
, unsigned n
)
569 isl_assert(dim
->ctx
, src_pos
+ n
<= isl_dim_size(dim
, src_type
),
572 if (dst_type
== src_type
&& dst_pos
== src_pos
)
575 isl_assert(dim
->ctx
, dst_type
!= src_type
, goto error
);
577 dim
= isl_dim_reset(dim
, src_type
);
578 dim
= isl_dim_reset(dim
, dst_type
);
580 dim
= isl_dim_cow(dim
);
585 struct isl_name
**names
;
589 names
= isl_calloc_array(dim
->ctx
, struct isl_name
*,
590 dim
->nparam
+ dim
->n_in
+ dim
->n_out
);
594 size
[isl_dim_param
] = dim
->nparam
;
595 size
[isl_dim_in
] = dim
->n_in
;
596 size
[isl_dim_out
] = dim
->n_out
;
597 for (t
= isl_dim_param
; t
<= isl_dim_out
; ++t
) {
599 get_names(dim
, t
, 0, dst_pos
, names
+ off
);
601 get_names(dim
, src_type
, src_pos
, n
, names
+off
);
603 get_names(dim
, t
, dst_pos
, size
[t
] - dst_pos
,
605 off
+= size
[t
] - dst_pos
;
606 } else if (t
== src_type
) {
607 get_names(dim
, t
, 0, src_pos
, names
+ off
);
609 get_names(dim
, t
, src_pos
+ n
,
610 size
[t
] - src_pos
- n
, names
+ off
);
611 off
+= size
[t
] - src_pos
- n
;
613 get_names(dim
, t
, 0, size
[t
], names
+ off
);
619 dim
->n_name
= dim
->nparam
+ dim
->n_in
+ dim
->n_out
;
623 case isl_dim_param
: dim
->nparam
+= n
; break;
624 case isl_dim_in
: dim
->n_in
+= n
; break;
625 case isl_dim_out
: dim
->n_out
+= n
; break;
629 case isl_dim_param
: dim
->nparam
-= n
; break;
630 case isl_dim_in
: dim
->n_in
-= n
; break;
631 case isl_dim_out
: dim
->n_out
-= n
; break;
640 struct isl_dim
*isl_dim_join(struct isl_dim
*left
, struct isl_dim
*right
)
647 isl_assert(left
->ctx
, match(left
, isl_dim_param
, right
, isl_dim_param
),
649 isl_assert(left
->ctx
,
650 isl_dim_tuple_match(left
, isl_dim_out
, right
, isl_dim_in
),
653 dim
= isl_dim_alloc(left
->ctx
, left
->nparam
, left
->n_in
, right
->n_out
);
657 dim
= copy_names(dim
, isl_dim_param
, 0, left
, isl_dim_param
);
658 dim
= copy_names(dim
, isl_dim_in
, 0, left
, isl_dim_in
);
659 dim
= copy_names(dim
, isl_dim_out
, 0, right
, isl_dim_out
);
661 if (dim
&& left
->tuple_name
[0] &&
662 !(dim
->tuple_name
[0] = isl_name_copy(dim
->ctx
, left
->tuple_name
[0])))
664 if (dim
&& right
->tuple_name
[1] &&
665 !(dim
->tuple_name
[1] = isl_name_copy(dim
->ctx
, right
->tuple_name
[1])))
667 if (dim
&& left
->nested
[0] &&
668 !(dim
->nested
[0] = isl_dim_copy(left
->nested
[0])))
670 if (dim
&& right
->nested
[1] &&
671 !(dim
->nested
[1] = isl_dim_copy(right
->nested
[1])))
684 struct isl_dim
*isl_dim_product(struct isl_dim
*left
, struct isl_dim
*right
)
691 isl_assert(left
->ctx
, match(left
, isl_dim_param
, right
, isl_dim_param
),
694 dim
= isl_dim_alloc(left
->ctx
, left
->nparam
,
695 left
->n_in
+ right
->n_in
, left
->n_out
+ right
->n_out
);
699 dim
= copy_names(dim
, isl_dim_param
, 0, left
, isl_dim_param
);
700 dim
= copy_names(dim
, isl_dim_in
, 0, left
, isl_dim_in
);
701 dim
= copy_names(dim
, isl_dim_in
, left
->n_in
, right
, isl_dim_in
);
702 dim
= copy_names(dim
, isl_dim_out
, 0, left
, isl_dim_out
);
703 dim
= copy_names(dim
, isl_dim_out
, left
->n_out
, right
, isl_dim_out
);
715 struct isl_dim
*isl_dim_map(struct isl_dim
*dim
)
717 struct isl_name
**names
= NULL
;
721 isl_assert(dim
->ctx
, dim
->n_in
== 0, goto error
);
722 if (dim
->n_out
== 0 && !isl_dim_is_named_or_nested(dim
, isl_dim_out
))
724 dim
= isl_dim_cow(dim
);
728 names
= isl_calloc_array(dim
->ctx
, struct isl_name
*,
729 dim
->nparam
+ dim
->n_out
+ dim
->n_out
);
732 get_names(dim
, isl_dim_param
, 0, dim
->nparam
, names
);
733 get_names(dim
, isl_dim_out
, 0, dim
->n_out
, names
+ dim
->nparam
);
735 dim
->n_in
= dim
->n_out
;
739 dim
->n_name
= dim
->nparam
+ dim
->n_out
+ dim
->n_out
;
740 dim
= copy_names(dim
, isl_dim_out
, 0, dim
, isl_dim_in
);
742 isl_name_free(dim
->ctx
, dim
->tuple_name
[0]);
743 dim
->tuple_name
[0] = isl_name_copy(dim
->ctx
, dim
->tuple_name
[1]);
744 isl_dim_free(dim
->nested
[0]);
745 dim
->nested
[0] = isl_dim_copy(dim
->nested
[1]);
752 static struct isl_dim
*set_names(struct isl_dim
*dim
, enum isl_dim_type type
,
753 unsigned first
, unsigned n
, struct isl_name
**names
)
757 for (i
= 0; i
< n
; ++i
)
758 dim
= set_name(dim
, type
, first
+i
, names
[i
]);
763 struct isl_dim
*isl_dim_reverse(struct isl_dim
*dim
)
767 struct isl_name
**names
= NULL
;
768 struct isl_name
*name
;
772 if (match(dim
, isl_dim_in
, dim
, isl_dim_out
))
775 dim
= isl_dim_cow(dim
);
779 name
= dim
->tuple_name
[0];
780 dim
->tuple_name
[0] = dim
->tuple_name
[1];
781 dim
->tuple_name
[1] = name
;
783 nested
= dim
->nested
[0];
784 dim
->nested
[0] = dim
->nested
[1];
785 dim
->nested
[1] = nested
;
788 names
= isl_alloc_array(dim
->ctx
, struct isl_name
*,
789 dim
->n_in
+ dim
->n_out
);
792 get_names(dim
, isl_dim_in
, 0, dim
->n_in
, names
);
793 get_names(dim
, isl_dim_out
, 0, dim
->n_out
, names
+ dim
->n_in
);
797 dim
->n_in
= dim
->n_out
;
801 dim
= set_names(dim
, isl_dim_out
, 0, dim
->n_out
, names
);
802 dim
= set_names(dim
, isl_dim_in
, 0, dim
->n_in
, names
+ dim
->n_out
);
813 struct isl_dim
*isl_dim_drop(struct isl_dim
*dim
, enum isl_dim_type type
,
814 unsigned first
, unsigned num
)
822 return isl_dim_reset(dim
, type
);
824 isl_assert(dim
->ctx
, first
+ num
<= n(dim
, type
), goto error
);
825 dim
= isl_dim_cow(dim
);
829 dim
= extend_names(dim
);
832 for (i
= 0; i
< num
; ++i
)
833 isl_name_free(dim
->ctx
, get_name(dim
, type
, first
+i
));
834 for (i
= first
+num
; i
< n(dim
, type
); ++i
)
835 set_name(dim
, type
, i
- num
, get_name(dim
, type
, i
));
838 get_names(dim
, isl_dim_in
, 0, dim
->n_in
,
839 dim
->names
+ offset(dim
, isl_dim_in
) - num
);
841 get_names(dim
, isl_dim_out
, 0, dim
->n_out
,
842 dim
->names
+ offset(dim
, isl_dim_out
) - num
);
849 case isl_dim_param
: dim
->nparam
-= num
; break;
850 case isl_dim_in
: dim
->n_in
-= num
; break;
851 case isl_dim_out
: dim
->n_out
-= num
; break;
853 dim
= isl_dim_reset(dim
, type
);
860 struct isl_dim
*isl_dim_drop_inputs(struct isl_dim
*dim
,
861 unsigned first
, unsigned n
)
865 return isl_dim_drop(dim
, isl_dim_in
, first
, n
);
868 struct isl_dim
*isl_dim_drop_outputs(struct isl_dim
*dim
,
869 unsigned first
, unsigned n
)
873 return isl_dim_drop(dim
, isl_dim_out
, first
, n
);
876 struct isl_dim
*isl_dim_domain(struct isl_dim
*dim
)
880 dim
= isl_dim_drop_outputs(dim
, 0, dim
->n_out
);
881 return isl_dim_reverse(dim
);
884 struct isl_dim
*isl_dim_range(struct isl_dim
*dim
)
888 return isl_dim_drop_inputs(dim
, 0, dim
->n_in
);
891 __isl_give isl_dim
*isl_dim_as_set_dim(__isl_take isl_dim
*dim
)
893 dim
= isl_dim_cow(dim
);
897 dim
->n_out
+= dim
->n_in
;
899 dim
= isl_dim_reset(dim
, isl_dim_in
);
900 dim
= isl_dim_reset(dim
, isl_dim_out
);
905 struct isl_dim
*isl_dim_underlying(struct isl_dim
*dim
, unsigned n_div
)
912 dim
->nparam
== 0 && dim
->n_in
== 0 && dim
->n_name
== 0)
913 return isl_dim_reset(isl_dim_reset(dim
, isl_dim_in
), isl_dim_out
);
914 dim
= isl_dim_cow(dim
);
917 dim
->n_out
+= dim
->nparam
+ dim
->n_in
+ n_div
;
921 for (i
= 0; i
< dim
->n_name
; ++i
)
922 isl_name_free(dim
->ctx
, get_name(dim
, isl_dim_out
, i
));
924 dim
= isl_dim_reset(dim
, isl_dim_in
);
925 dim
= isl_dim_reset(dim
, isl_dim_out
);
930 unsigned isl_dim_total(struct isl_dim
*dim
)
932 return dim
->nparam
+ dim
->n_in
+ dim
->n_out
;
935 int isl_dim_equal(struct isl_dim
*dim1
, struct isl_dim
*dim2
)
937 return match(dim1
, isl_dim_param
, dim2
, isl_dim_param
) &&
938 isl_dim_tuple_match(dim1
, isl_dim_in
, dim2
, isl_dim_in
) &&
939 isl_dim_tuple_match(dim1
, isl_dim_out
, dim2
, isl_dim_out
);
942 int isl_dim_compatible(struct isl_dim
*dim1
, struct isl_dim
*dim2
)
944 return dim1
->nparam
== dim2
->nparam
&&
945 dim1
->n_in
+ dim1
->n_out
== dim2
->n_in
+ dim2
->n_out
;
948 static uint32_t isl_hash_dim(uint32_t hash
, __isl_keep isl_dim
*dim
)
951 struct isl_name
*name
;
956 hash
= isl_hash_builtin(hash
, dim
->nparam
);
957 hash
= isl_hash_builtin(hash
, dim
->n_in
);
958 hash
= isl_hash_builtin(hash
, dim
->n_out
);
960 for (i
= 0; i
< dim
->nparam
; ++i
) {
961 name
= get_name(dim
, isl_dim_param
, i
);
962 hash
= isl_hash_builtin(hash
, name
);
965 name
= tuple_name(dim
, isl_dim_in
);
966 hash
= isl_hash_builtin(hash
, name
);
967 name
= tuple_name(dim
, isl_dim_out
);
968 hash
= isl_hash_builtin(hash
, name
);
970 hash
= isl_hash_dim(hash
, dim
->nested
[0]);
971 hash
= isl_hash_dim(hash
, dim
->nested
[1]);
976 uint32_t isl_dim_get_hash(__isl_keep isl_dim
*dim
)
983 hash
= isl_hash_init();
984 hash
= isl_hash_dim(hash
, dim
);
989 int isl_dim_is_wrapping(__isl_keep isl_dim
*dim
)
994 if (dim
->n_in
!= 0 || dim
->tuple_name
[0] || dim
->nested
[0])
997 return dim
->nested
[1] != NULL
;
1000 __isl_give isl_dim
*isl_dim_wrap(__isl_take isl_dim
*dim
)
1007 wrap
= isl_dim_alloc(dim
->ctx
, dim
->nparam
, 0, dim
->n_in
+ dim
->n_out
);
1009 wrap
= copy_names(wrap
, isl_dim_param
, 0, dim
, isl_dim_param
);
1010 wrap
= copy_names(wrap
, isl_dim_set
, 0, dim
, isl_dim_in
);
1011 wrap
= copy_names(wrap
, isl_dim_set
, dim
->n_in
, dim
, isl_dim_out
);
1016 wrap
->nested
[1] = dim
;
1024 __isl_give isl_dim
*isl_dim_unwrap(__isl_take isl_dim
*dim
)
1031 if (!isl_dim_is_wrapping(dim
))
1032 isl_die(dim
->ctx
, isl_error_invalid
, "not a wrapping dim",
1035 unwrap
= isl_dim_copy(dim
->nested
[1]);
1044 int isl_dim_is_named_or_nested(__isl_keep isl_dim
*dim
, enum isl_dim_type type
)
1046 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
1050 if (dim
->tuple_name
[type
- isl_dim_in
])
1052 if (dim
->nested
[type
- isl_dim_in
])
1057 __isl_give isl_dim
*isl_dim_reset(__isl_take isl_dim
*dim
,
1058 enum isl_dim_type type
)
1060 if (!isl_dim_is_named_or_nested(dim
, type
))
1063 dim
= isl_dim_cow(dim
);
1067 isl_name_free(dim
->ctx
, dim
->tuple_name
[type
- isl_dim_in
]);
1068 dim
->tuple_name
[type
- isl_dim_in
] = NULL
;
1069 isl_dim_free(dim
->nested
[type
- isl_dim_in
]);
1070 dim
->nested
[type
- isl_dim_in
] = NULL
;