2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2013-2014 Ecole Normale Superieure
6 * Use of this software is governed by the MIT license
8 * Written by Sven Verdoolaege, K.U.Leuven, Departement
9 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
10 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
11 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
12 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
17 #include <isl_space_private.h>
18 #include <isl_id_private.h>
19 #include <isl_reordering.h>
21 isl_ctx
*isl_space_get_ctx(__isl_keep isl_space
*space
)
23 return space
? space
->ctx
: NULL
;
26 __isl_give isl_space
*isl_space_alloc(isl_ctx
*ctx
,
27 unsigned nparam
, unsigned n_in
, unsigned n_out
)
31 space
= isl_alloc_type(ctx
, struct isl_space
);
38 space
->nparam
= nparam
;
42 space
->tuple_id
[0] = NULL
;
43 space
->tuple_id
[1] = NULL
;
45 space
->nested
[0] = NULL
;
46 space
->nested
[1] = NULL
;
54 /* Mark the space as being that of a set, by setting the domain tuple
57 static __isl_give isl_space
*mark_as_set(__isl_take isl_space
*space
)
59 space
= isl_space_cow(space
);
62 space
= isl_space_set_tuple_id(space
, isl_dim_in
, &isl_id_none
);
66 /* Is the space that of a set?
68 isl_bool
isl_space_is_set(__isl_keep isl_space
*space
)
71 return isl_bool_error
;
72 if (space
->n_in
!= 0 || space
->nested
[0])
73 return isl_bool_false
;
74 if (space
->tuple_id
[0] != &isl_id_none
)
75 return isl_bool_false
;
79 /* Is the given space that of a map?
81 isl_bool
isl_space_is_map(__isl_keep isl_space
*space
)
84 return isl_bool_error
;
85 return space
->tuple_id
[0] != &isl_id_none
&&
86 space
->tuple_id
[1] != &isl_id_none
;
89 __isl_give isl_space
*isl_space_set_alloc(isl_ctx
*ctx
,
90 unsigned nparam
, unsigned dim
)
93 space
= isl_space_alloc(ctx
, nparam
, 0, dim
);
94 space
= mark_as_set(space
);
98 /* Mark the space as being that of a parameter domain, by setting
99 * both tuples to isl_id_none.
101 static __isl_give isl_space
*mark_as_params(isl_space
*space
)
105 space
= isl_space_set_tuple_id(space
, isl_dim_in
, &isl_id_none
);
106 space
= isl_space_set_tuple_id(space
, isl_dim_out
, &isl_id_none
);
110 /* Is the space that of a parameter domain?
112 isl_bool
isl_space_is_params(__isl_keep isl_space
*space
)
115 return isl_bool_error
;
116 if (space
->n_in
!= 0 || space
->nested
[0] ||
117 space
->n_out
!= 0 || space
->nested
[1])
118 return isl_bool_false
;
119 if (space
->tuple_id
[0] != &isl_id_none
)
120 return isl_bool_false
;
121 if (space
->tuple_id
[1] != &isl_id_none
)
122 return isl_bool_false
;
123 return isl_bool_true
;
126 /* Create a space for a parameter domain.
128 __isl_give isl_space
*isl_space_params_alloc(isl_ctx
*ctx
, unsigned nparam
)
131 space
= isl_space_alloc(ctx
, nparam
, 0, 0);
132 space
= mark_as_params(space
);
136 static unsigned global_pos(__isl_keep isl_space
*space
,
137 enum isl_dim_type type
, unsigned pos
)
139 struct isl_ctx
*ctx
= space
->ctx
;
143 isl_assert(ctx
, pos
< space
->nparam
,
144 return isl_space_dim(space
, isl_dim_all
));
147 isl_assert(ctx
, pos
< space
->n_in
,
148 return isl_space_dim(space
, isl_dim_all
));
149 return pos
+ space
->nparam
;
151 isl_assert(ctx
, pos
< space
->n_out
,
152 return isl_space_dim(space
, isl_dim_all
));
153 return pos
+ space
->nparam
+ space
->n_in
;
155 isl_assert(ctx
, 0, return isl_space_dim(space
, isl_dim_all
));
157 return isl_space_dim(space
, isl_dim_all
);
160 /* Extend length of ids array to the total number of dimensions.
162 static __isl_give isl_space
*extend_ids(__isl_take isl_space
*space
)
167 if (isl_space_dim(space
, isl_dim_all
) <= space
->n_id
)
171 space
->ids
= isl_calloc_array(space
->ctx
,
172 isl_id
*, isl_space_dim(space
, isl_dim_all
));
176 ids
= isl_realloc_array(space
->ctx
, space
->ids
,
177 isl_id
*, isl_space_dim(space
, isl_dim_all
));
181 for (i
= space
->n_id
; i
< isl_space_dim(space
, isl_dim_all
); ++i
)
182 space
->ids
[i
] = NULL
;
185 space
->n_id
= isl_space_dim(space
, isl_dim_all
);
189 isl_space_free(space
);
193 static __isl_give isl_space
*set_id(__isl_take isl_space
*space
,
194 enum isl_dim_type type
, unsigned pos
, __isl_take isl_id
*id
)
196 space
= isl_space_cow(space
);
201 pos
= global_pos(space
, type
, pos
);
202 if (pos
== isl_space_dim(space
, isl_dim_all
))
205 if (pos
>= space
->n_id
) {
208 space
= extend_ids(space
);
213 space
->ids
[pos
] = id
;
218 isl_space_free(space
);
222 static __isl_keep isl_id
*get_id(__isl_keep isl_space
*space
,
223 enum isl_dim_type type
, unsigned pos
)
228 pos
= global_pos(space
, type
, pos
);
229 if (pos
== isl_space_dim(space
, isl_dim_all
))
231 if (pos
>= space
->n_id
)
233 return space
->ids
[pos
];
236 static unsigned offset(__isl_keep isl_space
*space
, enum isl_dim_type type
)
239 case isl_dim_param
: return 0;
240 case isl_dim_in
: return space
->nparam
;
241 case isl_dim_out
: return space
->nparam
+ space
->n_in
;
246 static unsigned n(__isl_keep isl_space
*space
, enum isl_dim_type type
)
249 case isl_dim_param
: return space
->nparam
;
250 case isl_dim_in
: return space
->n_in
;
251 case isl_dim_out
: return space
->n_out
;
253 return space
->nparam
+ space
->n_in
+ space
->n_out
;
258 unsigned isl_space_dim(__isl_keep isl_space
*space
, enum isl_dim_type type
)
262 return n(space
, type
);
265 unsigned isl_space_offset(__isl_keep isl_space
*dim
, enum isl_dim_type type
)
269 return offset(dim
, type
);
272 static __isl_give isl_space
*copy_ids(__isl_take isl_space
*dst
,
273 enum isl_dim_type dst_type
, unsigned offset
, __isl_keep isl_space
*src
,
274 enum isl_dim_type src_type
)
282 for (i
= 0; i
< n(src
, src_type
); ++i
) {
283 id
= get_id(src
, src_type
, i
);
286 dst
= set_id(dst
, dst_type
, offset
+ i
, isl_id_copy(id
));
293 __isl_take isl_space
*isl_space_dup(__isl_keep isl_space
*space
)
298 dup
= isl_space_alloc(space
->ctx
,
299 space
->nparam
, space
->n_in
, space
->n_out
);
302 if (space
->tuple_id
[0] &&
303 !(dup
->tuple_id
[0] = isl_id_copy(space
->tuple_id
[0])))
305 if (space
->tuple_id
[1] &&
306 !(dup
->tuple_id
[1] = isl_id_copy(space
->tuple_id
[1])))
308 if (space
->nested
[0] &&
309 !(dup
->nested
[0] = isl_space_copy(space
->nested
[0])))
311 if (space
->nested
[1] &&
312 !(dup
->nested
[1] = isl_space_copy(space
->nested
[1])))
316 dup
= copy_ids(dup
, isl_dim_param
, 0, space
, isl_dim_param
);
317 dup
= copy_ids(dup
, isl_dim_in
, 0, space
, isl_dim_in
);
318 dup
= copy_ids(dup
, isl_dim_out
, 0, space
, isl_dim_out
);
325 __isl_give isl_space
*isl_space_cow(__isl_take isl_space
*space
)
333 return isl_space_dup(space
);
336 __isl_give isl_space
*isl_space_copy(__isl_keep isl_space
*dim
)
345 __isl_null isl_space
*isl_space_free(__isl_take isl_space
*space
)
352 if (--space
->ref
> 0)
355 isl_id_free(space
->tuple_id
[0]);
356 isl_id_free(space
->tuple_id
[1]);
358 isl_space_free(space
->nested
[0]);
359 isl_space_free(space
->nested
[1]);
361 for (i
= 0; i
< space
->n_id
; ++i
)
362 isl_id_free(space
->ids
[i
]);
364 isl_ctx_deref(space
->ctx
);
371 /* Check if "s" is a valid dimension or tuple name.
372 * We currently only forbid names that look like a number.
374 * s is assumed to be non-NULL.
376 static int name_ok(isl_ctx
*ctx
, const char *s
)
381 dummy
= strtol(s
, &p
, 0);
383 isl_die(ctx
, isl_error_invalid
, "name looks like a number",
389 /* Is it possible for the given dimension type to have a tuple id?
391 static int space_can_have_id(__isl_keep isl_space
*space
,
392 enum isl_dim_type type
)
396 if (isl_space_is_params(space
))
397 isl_die(space
->ctx
, isl_error_invalid
,
398 "parameter spaces don't have tuple ids", return 0);
399 if (isl_space_is_set(space
) && type
!= isl_dim_set
)
400 isl_die(space
->ctx
, isl_error_invalid
,
401 "set spaces can only have a set id", return 0);
402 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
403 isl_die(space
->ctx
, isl_error_invalid
,
404 "only input, output and set tuples can have ids",
410 /* Does the tuple have an id?
412 isl_bool
isl_space_has_tuple_id(__isl_keep isl_space
*space
,
413 enum isl_dim_type type
)
415 if (!space_can_have_id(space
, type
))
416 return isl_bool_error
;
417 return space
->tuple_id
[type
- isl_dim_in
] != NULL
;
420 __isl_give isl_id
*isl_space_get_tuple_id(__isl_keep isl_space
*space
,
421 enum isl_dim_type type
)
427 has_id
= isl_space_has_tuple_id(space
, type
);
431 isl_die(space
->ctx
, isl_error_invalid
,
432 "tuple has no id", return NULL
);
433 return isl_id_copy(space
->tuple_id
[type
- isl_dim_in
]);
436 __isl_give isl_space
*isl_space_set_tuple_id(__isl_take isl_space
*space
,
437 enum isl_dim_type type
, __isl_take isl_id
*id
)
439 space
= isl_space_cow(space
);
442 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
443 isl_die(space
->ctx
, isl_error_invalid
,
444 "only input, output and set tuples can have names",
447 isl_id_free(space
->tuple_id
[type
- isl_dim_in
]);
448 space
->tuple_id
[type
- isl_dim_in
] = id
;
453 isl_space_free(space
);
457 __isl_give isl_space
*isl_space_reset_tuple_id(__isl_take isl_space
*space
,
458 enum isl_dim_type type
)
460 space
= isl_space_cow(space
);
463 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
464 isl_die(space
->ctx
, isl_error_invalid
,
465 "only input, output and set tuples can have names",
468 isl_id_free(space
->tuple_id
[type
- isl_dim_in
]);
469 space
->tuple_id
[type
- isl_dim_in
] = NULL
;
473 isl_space_free(space
);
477 /* Set the id of the given dimension of "space" to "id".
478 * If the dimension already has an id, then it is replaced.
479 * If the dimension is a parameter, then we need to change it
480 * in the nested spaces (if any) as well.
482 __isl_give isl_space
*isl_space_set_dim_id(__isl_take isl_space
*space
,
483 enum isl_dim_type type
, unsigned pos
, __isl_take isl_id
*id
)
485 space
= isl_space_cow(space
);
489 if (type
== isl_dim_param
) {
492 for (i
= 0; i
< 2; ++i
) {
493 if (!space
->nested
[i
])
496 isl_space_set_dim_id(space
->nested
[i
],
497 type
, pos
, isl_id_copy(id
));
498 if (!space
->nested
[i
])
503 isl_id_free(get_id(space
, type
, pos
));
504 return set_id(space
, type
, pos
, id
);
507 isl_space_free(space
);
511 /* Reset the id of the given dimension of "space".
512 * If the dimension already has an id, then it is removed.
513 * If the dimension is a parameter, then we need to reset it
514 * in the nested spaces (if any) as well.
516 __isl_give isl_space
*isl_space_reset_dim_id(__isl_take isl_space
*space
,
517 enum isl_dim_type type
, unsigned pos
)
519 space
= isl_space_cow(space
);
523 if (type
== isl_dim_param
) {
526 for (i
= 0; i
< 2; ++i
) {
527 if (!space
->nested
[i
])
530 isl_space_reset_dim_id(space
->nested
[i
],
532 if (!space
->nested
[i
])
537 isl_id_free(get_id(space
, type
, pos
));
538 return set_id(space
, type
, pos
, NULL
);
540 isl_space_free(space
);
544 isl_bool
isl_space_has_dim_id(__isl_keep isl_space
*space
,
545 enum isl_dim_type type
, unsigned pos
)
548 return isl_bool_error
;
549 return get_id(space
, type
, pos
) != NULL
;
552 __isl_give isl_id
*isl_space_get_dim_id(__isl_keep isl_space
*space
,
553 enum isl_dim_type type
, unsigned pos
)
557 if (!get_id(space
, type
, pos
))
558 isl_die(space
->ctx
, isl_error_invalid
,
559 "dim has no id", return NULL
);
560 return isl_id_copy(get_id(space
, type
, pos
));
563 __isl_give isl_space
*isl_space_set_tuple_name(__isl_take isl_space
*space
,
564 enum isl_dim_type type
, const char *s
)
572 return isl_space_reset_tuple_id(space
, type
);
574 if (!name_ok(space
->ctx
, s
))
577 id
= isl_id_alloc(space
->ctx
, s
, NULL
);
578 return isl_space_set_tuple_id(space
, type
, id
);
580 isl_space_free(space
);
584 /* Does the tuple have a name?
586 isl_bool
isl_space_has_tuple_name(__isl_keep isl_space
*space
,
587 enum isl_dim_type type
)
591 if (!space_can_have_id(space
, type
))
592 return isl_bool_error
;
593 id
= space
->tuple_id
[type
- isl_dim_in
];
594 return id
&& id
->name
;
597 __isl_keep
const char *isl_space_get_tuple_name(__isl_keep isl_space
*space
,
598 enum isl_dim_type type
)
603 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
605 id
= space
->tuple_id
[type
- isl_dim_in
];
606 return id
? id
->name
: NULL
;
609 __isl_give isl_space
*isl_space_set_dim_name(__isl_take isl_space
*space
,
610 enum isl_dim_type type
, unsigned pos
,
618 return isl_space_reset_dim_id(space
, type
, pos
);
619 if (!name_ok(space
->ctx
, s
))
621 id
= isl_id_alloc(space
->ctx
, s
, NULL
);
622 return isl_space_set_dim_id(space
, type
, pos
, id
);
624 isl_space_free(space
);
628 /* Does the given dimension have a name?
630 isl_bool
isl_space_has_dim_name(__isl_keep isl_space
*space
,
631 enum isl_dim_type type
, unsigned pos
)
636 return isl_bool_error
;
637 id
= get_id(space
, type
, pos
);
638 return id
&& id
->name
;
641 __isl_keep
const char *isl_space_get_dim_name(__isl_keep isl_space
*space
,
642 enum isl_dim_type type
, unsigned pos
)
644 isl_id
*id
= get_id(space
, type
, pos
);
645 return id
? id
->name
: NULL
;
648 int isl_space_find_dim_by_id(__isl_keep isl_space
*space
,
649 enum isl_dim_type type
, __isl_keep isl_id
*id
)
658 offset
= isl_space_offset(space
, type
);
659 n
= isl_space_dim(space
, type
);
660 for (i
= 0; i
< n
&& offset
+ i
< space
->n_id
; ++i
)
661 if (space
->ids
[offset
+ i
] == id
)
667 int isl_space_find_dim_by_name(__isl_keep isl_space
*space
,
668 enum isl_dim_type type
, const char *name
)
677 offset
= isl_space_offset(space
, type
);
678 n
= isl_space_dim(space
, type
);
679 for (i
= 0; i
< n
&& offset
+ i
< space
->n_id
; ++i
) {
680 isl_id
*id
= get_id(space
, type
, i
);
681 if (id
&& id
->name
&& !strcmp(id
->name
, name
))
688 /* Reset the user pointer on all identifiers of parameters and tuples
691 __isl_give isl_space
*isl_space_reset_user(__isl_take isl_space
*space
)
701 ctx
= isl_space_get_ctx(space
);
703 for (i
= 0; i
< space
->nparam
&& i
< space
->n_id
; ++i
) {
704 if (!isl_id_get_user(space
->ids
[i
]))
706 space
= isl_space_cow(space
);
709 name
= isl_id_get_name(space
->ids
[i
]);
710 id
= isl_id_alloc(ctx
, name
, NULL
);
711 isl_id_free(space
->ids
[i
]);
714 return isl_space_free(space
);
717 for (i
= 0; i
< 2; ++i
) {
718 if (!space
->tuple_id
[i
])
720 if (!isl_id_get_user(space
->tuple_id
[i
]))
722 space
= isl_space_cow(space
);
725 name
= isl_id_get_name(space
->tuple_id
[i
]);
726 id
= isl_id_alloc(ctx
, name
, NULL
);
727 isl_id_free(space
->tuple_id
[i
]);
728 space
->tuple_id
[i
] = id
;
730 return isl_space_free(space
);
733 for (i
= 0; i
< 2; ++i
) {
734 if (!space
->nested
[i
])
736 space
= isl_space_cow(space
);
739 space
->nested
[i
] = isl_space_reset_user(space
->nested
[i
]);
740 if (!space
->nested
[i
])
741 return isl_space_free(space
);
747 static __isl_keep isl_id
*tuple_id(__isl_keep isl_space
*dim
,
748 enum isl_dim_type type
)
752 if (type
== isl_dim_in
)
753 return dim
->tuple_id
[0];
754 if (type
== isl_dim_out
)
755 return dim
->tuple_id
[1];
759 static __isl_keep isl_space
*nested(__isl_keep isl_space
*dim
,
760 enum isl_dim_type type
)
764 if (type
== isl_dim_in
)
765 return dim
->nested
[0];
766 if (type
== isl_dim_out
)
767 return dim
->nested
[1];
771 /* Are the two spaces the same, apart from positions and names of parameters?
773 isl_bool
isl_space_has_equal_tuples(__isl_keep isl_space
*space1
,
774 __isl_keep isl_space
*space2
)
776 if (!space1
|| !space2
)
777 return isl_bool_error
;
778 if (space1
== space2
)
779 return isl_bool_true
;
780 return isl_space_tuple_is_equal(space1
, isl_dim_in
,
781 space2
, isl_dim_in
) &&
782 isl_space_tuple_is_equal(space1
, isl_dim_out
,
783 space2
, isl_dim_out
);
786 /* Check if the tuple of type "type1" of "space1" is the same as
787 * the tuple of type "type2" of "space2".
789 * That is, check if the tuples have the same identifier, the same dimension
790 * and the same internal structure.
791 * The identifiers of the dimensions inside the tuples do not affect the result.
793 * Note that this function only checks the tuples themselves.
794 * If nested tuples are involved, then we need to be careful not
795 * to have result affected by possibly differing parameters
796 * in those nested tuples.
798 isl_bool
isl_space_tuple_is_equal(__isl_keep isl_space
*space1
,
799 enum isl_dim_type type1
, __isl_keep isl_space
*space2
,
800 enum isl_dim_type type2
)
803 isl_space
*nested1
, *nested2
;
805 if (!space1
|| !space2
)
806 return isl_bool_error
;
808 if (space1
== space2
&& type1
== type2
)
809 return isl_bool_true
;
811 if (n(space1
, type1
) != n(space2
, type2
))
812 return isl_bool_false
;
813 id1
= tuple_id(space1
, type1
);
814 id2
= tuple_id(space2
, type2
);
816 return isl_bool_false
;
817 if (id1
&& id1
!= id2
)
818 return isl_bool_false
;
819 nested1
= nested(space1
, type1
);
820 nested2
= nested(space2
, type2
);
821 if (!nested1
^ !nested2
)
822 return isl_bool_false
;
823 if (nested1
&& !isl_space_has_equal_tuples(nested1
, nested2
))
824 return isl_bool_false
;
825 return isl_bool_true
;
828 static isl_bool
match(__isl_keep isl_space
*space1
, enum isl_dim_type type1
,
829 __isl_keep isl_space
*space2
, enum isl_dim_type type2
)
833 if (space1
== space2
&& type1
== type2
)
834 return isl_bool_true
;
836 if (!isl_space_tuple_is_equal(space1
, type1
, space2
, type2
))
837 return isl_bool_false
;
839 if (!space1
->ids
&& !space2
->ids
)
840 return isl_bool_true
;
842 for (i
= 0; i
< n(space1
, type1
); ++i
) {
843 if (get_id(space1
, type1
, i
) != get_id(space2
, type2
, i
))
844 return isl_bool_false
;
846 return isl_bool_true
;
849 /* Do "space1" and "space2" have the same parameters?
851 isl_bool
isl_space_has_equal_params(__isl_keep isl_space
*space1
,
852 __isl_keep isl_space
*space2
)
854 if (!space1
|| !space2
)
855 return isl_bool_error
;
857 return match(space1
, isl_dim_param
, space2
, isl_dim_param
);
860 /* Do "space1" and "space2" have the same identifiers for all
861 * the tuple variables?
863 isl_bool
isl_space_has_equal_ids(__isl_keep isl_space
*space1
,
864 __isl_keep isl_space
*space2
)
868 if (!space1
|| !space2
)
869 return isl_bool_error
;
871 equal
= match(space1
, isl_dim_in
, space2
, isl_dim_in
);
872 if (equal
< 0 || !equal
)
874 return match(space1
, isl_dim_out
, space2
, isl_dim_out
);
877 isl_bool
isl_space_match(__isl_keep isl_space
*space1
, enum isl_dim_type type1
,
878 __isl_keep isl_space
*space2
, enum isl_dim_type type2
)
880 if (!space1
|| !space2
)
881 return isl_bool_error
;
883 return match(space1
, type1
, space2
, type2
);
886 static void get_ids(__isl_keep isl_space
*dim
, enum isl_dim_type type
,
887 unsigned first
, unsigned n
, __isl_keep isl_id
**ids
)
891 for (i
= 0; i
< n
; ++i
)
892 ids
[i
] = get_id(dim
, type
, first
+ i
);
895 static __isl_give isl_space
*space_extend(__isl_take isl_space
*space
,
896 unsigned nparam
, unsigned n_in
, unsigned n_out
)
902 if (space
->nparam
== nparam
&&
903 space
->n_in
== n_in
&& space
->n_out
== n_out
)
906 isl_assert(space
->ctx
, space
->nparam
<= nparam
, goto error
);
907 isl_assert(space
->ctx
, space
->n_in
<= n_in
, goto error
);
908 isl_assert(space
->ctx
, space
->n_out
<= n_out
, goto error
);
910 space
= isl_space_cow(space
);
916 n
= nparam
+ n_in
+ n_out
;
917 if (n
< nparam
|| n
< n_in
|| n
< n_out
)
918 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
919 "overflow in total number of dimensions",
921 ids
= isl_calloc_array(space
->ctx
, isl_id
*, n
);
924 get_ids(space
, isl_dim_param
, 0, space
->nparam
, ids
);
925 get_ids(space
, isl_dim_in
, 0, space
->n_in
, ids
+ nparam
);
926 get_ids(space
, isl_dim_out
, 0, space
->n_out
,
927 ids
+ nparam
+ n_in
);
930 space
->n_id
= nparam
+ n_in
+ n_out
;
932 space
->nparam
= nparam
;
934 space
->n_out
= n_out
;
939 isl_space_free(space
);
943 __isl_give isl_space
*isl_space_extend(__isl_take isl_space
*space
,
944 unsigned nparam
, unsigned n_in
, unsigned n_out
)
946 return space_extend(space
, nparam
, n_in
, n_out
);
949 __isl_give isl_space
*isl_space_add_dims(__isl_take isl_space
*space
,
950 enum isl_dim_type type
, unsigned n
)
952 space
= isl_space_reset(space
, type
);
957 space
= space_extend(space
,
958 space
->nparam
+ n
, space
->n_in
, space
->n_out
);
959 if (space
&& space
->nested
[0] &&
960 !(space
->nested
[0] = isl_space_add_dims(space
->nested
[0],
963 if (space
&& space
->nested
[1] &&
964 !(space
->nested
[1] = isl_space_add_dims(space
->nested
[1],
969 return space_extend(space
,
970 space
->nparam
, space
->n_in
+ n
, space
->n_out
);
972 return space_extend(space
,
973 space
->nparam
, space
->n_in
, space
->n_out
+ n
);
975 isl_die(space
->ctx
, isl_error_invalid
,
976 "cannot add dimensions of specified type", goto error
);
979 isl_space_free(space
);
983 /* Add a parameter with identifier "id" to "space", provided
984 * it does not already appear in "space".
986 __isl_give isl_space
*isl_space_add_param_id(__isl_take isl_space
*space
,
987 __isl_take isl_id
*id
)
994 if (isl_space_find_dim_by_id(space
, isl_dim_param
, id
) >= 0) {
999 pos
= isl_space_dim(space
, isl_dim_param
);
1000 space
= isl_space_add_dims(space
, isl_dim_param
, 1);
1001 space
= isl_space_set_dim_id(space
, isl_dim_param
, pos
, id
);
1005 isl_space_free(space
);
1010 static int valid_dim_type(enum isl_dim_type type
)
1022 /* Insert "n" dimensions of type "type" at position "pos".
1023 * If we are inserting parameters, then they are also inserted in
1024 * any nested spaces.
1026 __isl_give isl_space
*isl_space_insert_dims(__isl_take isl_space
*space
,
1027 enum isl_dim_type type
, unsigned pos
, unsigned n
)
1030 isl_id
**ids
= NULL
;
1036 return isl_space_reset(space
, type
);
1038 ctx
= isl_space_get_ctx(space
);
1039 if (!valid_dim_type(type
))
1040 isl_die(ctx
, isl_error_invalid
,
1041 "cannot insert dimensions of specified type",
1044 total
= isl_space_dim(space
, isl_dim_all
);
1045 if (total
+ n
< total
)
1046 isl_die(ctx
, isl_error_invalid
,
1047 "overflow in total number of dimensions",
1048 return isl_space_free(space
));
1049 isl_assert(ctx
, pos
<= isl_space_dim(space
, type
), goto error
);
1051 space
= isl_space_cow(space
);
1056 enum isl_dim_type t
, o
= isl_dim_param
;
1059 ids
= isl_calloc_array(ctx
, isl_id
*,
1060 space
->nparam
+ space
->n_in
+ space
->n_out
+ n
);
1064 s
[isl_dim_param
- o
] = space
->nparam
;
1065 s
[isl_dim_in
- o
] = space
->n_in
;
1066 s
[isl_dim_out
- o
] = space
->n_out
;
1067 for (t
= isl_dim_param
; t
<= isl_dim_out
; ++t
) {
1069 get_ids(space
, t
, 0, s
[t
- o
], ids
+ off
);
1072 get_ids(space
, t
, 0, pos
, ids
+ off
);
1074 get_ids(space
, t
, pos
, s
[t
- o
] - pos
,
1076 off
+= s
[t
- o
] - pos
;
1081 space
->n_id
= space
->nparam
+ space
->n_in
+ space
->n_out
+ n
;
1084 case isl_dim_param
: space
->nparam
+= n
; break;
1085 case isl_dim_in
: space
->n_in
+= n
; break;
1086 case isl_dim_out
: space
->n_out
+= n
; break;
1089 space
= isl_space_reset(space
, type
);
1091 if (type
== isl_dim_param
) {
1092 if (space
&& space
->nested
[0] &&
1093 !(space
->nested
[0] = isl_space_insert_dims(space
->nested
[0],
1094 isl_dim_param
, pos
, n
)))
1096 if (space
&& space
->nested
[1] &&
1097 !(space
->nested
[1] = isl_space_insert_dims(space
->nested
[1],
1098 isl_dim_param
, pos
, n
)))
1104 isl_space_free(space
);
1108 __isl_give isl_space
*isl_space_move_dims(__isl_take isl_space
*space
,
1109 enum isl_dim_type dst_type
, unsigned dst_pos
,
1110 enum isl_dim_type src_type
, unsigned src_pos
, unsigned n
)
1114 space
= isl_space_reset(space
, src_type
);
1115 space
= isl_space_reset(space
, dst_type
);
1121 isl_assert(space
->ctx
, src_pos
+ n
<= isl_space_dim(space
, src_type
),
1124 if (dst_type
== src_type
&& dst_pos
== src_pos
)
1127 isl_assert(space
->ctx
, dst_type
!= src_type
, goto error
);
1129 space
= isl_space_cow(space
);
1135 enum isl_dim_type t
, o
= isl_dim_param
;
1138 ids
= isl_calloc_array(space
->ctx
, isl_id
*,
1139 space
->nparam
+ space
->n_in
+ space
->n_out
);
1143 s
[isl_dim_param
- o
] = space
->nparam
;
1144 s
[isl_dim_in
- o
] = space
->n_in
;
1145 s
[isl_dim_out
- o
] = space
->n_out
;
1146 for (t
= isl_dim_param
; t
<= isl_dim_out
; ++t
) {
1147 if (t
== dst_type
) {
1148 get_ids(space
, t
, 0, dst_pos
, ids
+ off
);
1150 get_ids(space
, src_type
, src_pos
, n
, ids
+ off
);
1152 get_ids(space
, t
, dst_pos
, s
[t
- o
] - dst_pos
,
1154 off
+= s
[t
- o
] - dst_pos
;
1155 } else if (t
== src_type
) {
1156 get_ids(space
, t
, 0, src_pos
, ids
+ off
);
1158 get_ids(space
, t
, src_pos
+ n
,
1159 s
[t
- o
] - src_pos
- n
, ids
+ off
);
1160 off
+= s
[t
- o
] - src_pos
- n
;
1162 get_ids(space
, t
, 0, s
[t
- o
], ids
+ off
);
1168 space
->n_id
= space
->nparam
+ space
->n_in
+ space
->n_out
;
1172 case isl_dim_param
: space
->nparam
+= n
; break;
1173 case isl_dim_in
: space
->n_in
+= n
; break;
1174 case isl_dim_out
: space
->n_out
+= n
; break;
1179 case isl_dim_param
: space
->nparam
-= n
; break;
1180 case isl_dim_in
: space
->n_in
-= n
; break;
1181 case isl_dim_out
: space
->n_out
-= n
; break;
1185 if (dst_type
!= isl_dim_param
&& src_type
!= isl_dim_param
)
1188 for (i
= 0; i
< 2; ++i
) {
1189 if (!space
->nested
[i
])
1191 space
->nested
[i
] = isl_space_replace_params(space
->nested
[i
],
1193 if (!space
->nested
[i
])
1199 isl_space_free(space
);
1203 /* Check that "space1" and "space2" have the same parameters,
1204 * reporting an error if they do not.
1206 isl_stat
isl_space_check_equal_params(__isl_keep isl_space
*space1
,
1207 __isl_keep isl_space
*space2
)
1211 equal
= isl_space_has_equal_params(space1
, space2
);
1213 return isl_stat_error
;
1215 isl_die(isl_space_get_ctx(space1
), isl_error_invalid
,
1216 "parameters need to match", return isl_stat_error
);
1220 __isl_give isl_space
*isl_space_join(__isl_take isl_space
*left
,
1221 __isl_take isl_space
*right
)
1225 if (isl_space_check_equal_params(left
, right
) < 0)
1228 isl_assert(left
->ctx
,
1229 isl_space_tuple_is_equal(left
, isl_dim_out
, right
, isl_dim_in
),
1232 space
= isl_space_alloc(left
->ctx
,
1233 left
->nparam
, left
->n_in
, right
->n_out
);
1237 space
= copy_ids(space
, isl_dim_param
, 0, left
, isl_dim_param
);
1238 space
= copy_ids(space
, isl_dim_in
, 0, left
, isl_dim_in
);
1239 space
= copy_ids(space
, isl_dim_out
, 0, right
, isl_dim_out
);
1241 if (space
&& left
->tuple_id
[0] &&
1242 !(space
->tuple_id
[0] = isl_id_copy(left
->tuple_id
[0])))
1244 if (space
&& right
->tuple_id
[1] &&
1245 !(space
->tuple_id
[1] = isl_id_copy(right
->tuple_id
[1])))
1247 if (space
&& left
->nested
[0] &&
1248 !(space
->nested
[0] = isl_space_copy(left
->nested
[0])))
1250 if (space
&& right
->nested
[1] &&
1251 !(space
->nested
[1] = isl_space_copy(right
->nested
[1])))
1254 isl_space_free(left
);
1255 isl_space_free(right
);
1259 isl_space_free(left
);
1260 isl_space_free(right
);
1264 /* Given two map spaces { A -> C } and { B -> D }, construct the space
1265 * { [A -> B] -> [C -> D] }.
1266 * Given two set spaces { A } and { B }, construct the space { [A -> B] }.
1268 __isl_give isl_space
*isl_space_product(__isl_take isl_space
*left
,
1269 __isl_take isl_space
*right
)
1271 isl_space
*dom1
, *dom2
, *nest1
, *nest2
;
1274 if (!left
|| !right
)
1277 is_set
= isl_space_is_set(left
);
1278 if (is_set
!= isl_space_is_set(right
))
1279 isl_die(isl_space_get_ctx(left
), isl_error_invalid
,
1280 "expecting either two set spaces or two map spaces",
1283 return isl_space_range_product(left
, right
);
1285 if (isl_space_check_equal_params(left
, right
) < 0)
1288 dom1
= isl_space_domain(isl_space_copy(left
));
1289 dom2
= isl_space_domain(isl_space_copy(right
));
1290 nest1
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1292 dom1
= isl_space_range(left
);
1293 dom2
= isl_space_range(right
);
1294 nest2
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1296 return isl_space_join(isl_space_reverse(nest1
), nest2
);
1298 isl_space_free(left
);
1299 isl_space_free(right
);
1303 /* Given two spaces { A -> C } and { B -> C }, construct the space
1306 __isl_give isl_space
*isl_space_domain_product(__isl_take isl_space
*left
,
1307 __isl_take isl_space
*right
)
1309 isl_space
*ran
, *dom1
, *dom2
, *nest
;
1311 if (isl_space_check_equal_params(left
, right
) < 0)
1314 if (!isl_space_tuple_is_equal(left
, isl_dim_out
, right
, isl_dim_out
))
1315 isl_die(left
->ctx
, isl_error_invalid
,
1316 "ranges need to match", goto error
);
1318 ran
= isl_space_range(isl_space_copy(left
));
1320 dom1
= isl_space_domain(left
);
1321 dom2
= isl_space_domain(right
);
1322 nest
= isl_space_wrap(isl_space_join(isl_space_reverse(dom1
), dom2
));
1324 return isl_space_join(isl_space_reverse(nest
), ran
);
1326 isl_space_free(left
);
1327 isl_space_free(right
);
1331 __isl_give isl_space
*isl_space_range_product(__isl_take isl_space
*left
,
1332 __isl_take isl_space
*right
)
1334 isl_space
*dom
, *ran1
, *ran2
, *nest
;
1336 if (isl_space_check_equal_params(left
, right
) < 0)
1339 if (!isl_space_tuple_is_equal(left
, isl_dim_in
, right
, isl_dim_in
))
1340 isl_die(left
->ctx
, isl_error_invalid
,
1341 "domains need to match", goto error
);
1343 dom
= isl_space_domain(isl_space_copy(left
));
1345 ran1
= isl_space_range(left
);
1346 ran2
= isl_space_range(right
);
1347 nest
= isl_space_wrap(isl_space_join(isl_space_reverse(ran1
), ran2
));
1349 return isl_space_join(isl_space_reverse(dom
), nest
);
1351 isl_space_free(left
);
1352 isl_space_free(right
);
1356 /* Given a space of the form [A -> B] -> C, return the space A -> C.
1358 __isl_give isl_space
*isl_space_domain_factor_domain(
1359 __isl_take isl_space
*space
)
1366 if (!isl_space_domain_is_wrapping(space
))
1367 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1368 "domain not a product", return isl_space_free(space
));
1370 nested
= space
->nested
[0];
1371 domain
= isl_space_copy(space
);
1372 domain
= isl_space_drop_dims(domain
, isl_dim_in
,
1373 nested
->n_in
, nested
->n_out
);
1375 return isl_space_free(space
);
1376 if (nested
->tuple_id
[0]) {
1377 domain
->tuple_id
[0] = isl_id_copy(nested
->tuple_id
[0]);
1378 if (!domain
->tuple_id
[0])
1381 if (nested
->nested
[0]) {
1382 domain
->nested
[0] = isl_space_copy(nested
->nested
[0]);
1383 if (!domain
->nested
[0])
1387 isl_space_free(space
);
1390 isl_space_free(space
);
1391 isl_space_free(domain
);
1395 /* Given a space of the form [A -> B] -> C, return the space B -> C.
1397 __isl_give isl_space
*isl_space_domain_factor_range(
1398 __isl_take isl_space
*space
)
1405 if (!isl_space_domain_is_wrapping(space
))
1406 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1407 "domain not a product", return isl_space_free(space
));
1409 nested
= space
->nested
[0];
1410 range
= isl_space_copy(space
);
1411 range
= isl_space_drop_dims(range
, isl_dim_in
, 0, nested
->n_in
);
1413 return isl_space_free(space
);
1414 if (nested
->tuple_id
[1]) {
1415 range
->tuple_id
[0] = isl_id_copy(nested
->tuple_id
[1]);
1416 if (!range
->tuple_id
[0])
1419 if (nested
->nested
[1]) {
1420 range
->nested
[0] = isl_space_copy(nested
->nested
[1]);
1421 if (!range
->nested
[0])
1425 isl_space_free(space
);
1428 isl_space_free(space
);
1429 isl_space_free(range
);
1433 /* Internal function that selects the domain of the map that is
1434 * embedded in either a set space or the range of a map space.
1435 * In particular, given a space of the form [A -> B], return the space A.
1436 * Given a space of the form A -> [B -> C], return the space A -> B.
1438 static __isl_give isl_space
*range_factor_domain(__isl_take isl_space
*space
)
1446 nested
= space
->nested
[1];
1447 domain
= isl_space_copy(space
);
1448 domain
= isl_space_drop_dims(domain
, isl_dim_out
,
1449 nested
->n_in
, nested
->n_out
);
1451 return isl_space_free(space
);
1452 if (nested
->tuple_id
[0]) {
1453 domain
->tuple_id
[1] = isl_id_copy(nested
->tuple_id
[0]);
1454 if (!domain
->tuple_id
[1])
1457 if (nested
->nested
[0]) {
1458 domain
->nested
[1] = isl_space_copy(nested
->nested
[0]);
1459 if (!domain
->nested
[1])
1463 isl_space_free(space
);
1466 isl_space_free(space
);
1467 isl_space_free(domain
);
1471 /* Given a space of the form A -> [B -> C], return the space A -> B.
1473 __isl_give isl_space
*isl_space_range_factor_domain(
1474 __isl_take isl_space
*space
)
1478 if (!isl_space_range_is_wrapping(space
))
1479 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1480 "range not a product", return isl_space_free(space
));
1482 return range_factor_domain(space
);
1485 /* Given a space of the form [A -> B], return the space A.
1487 static __isl_give isl_space
*set_factor_domain(__isl_take isl_space
*space
)
1491 if (!isl_space_is_wrapping(space
))
1492 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1493 "not a product", return isl_space_free(space
));
1495 return range_factor_domain(space
);
1498 /* Given a space of the form [A -> B] -> [C -> D], return the space A -> C.
1499 * Given a space of the form [A -> B], return the space A.
1501 __isl_give isl_space
*isl_space_factor_domain(__isl_take isl_space
*space
)
1505 if (isl_space_is_set(space
))
1506 return set_factor_domain(space
);
1507 space
= isl_space_domain_factor_domain(space
);
1508 space
= isl_space_range_factor_domain(space
);
1512 /* Internal function that selects the range of the map that is
1513 * embedded in either a set space or the range of a map space.
1514 * In particular, given a space of the form [A -> B], return the space B.
1515 * Given a space of the form A -> [B -> C], return the space A -> C.
1517 static __isl_give isl_space
*range_factor_range(__isl_take isl_space
*space
)
1525 nested
= space
->nested
[1];
1526 range
= isl_space_copy(space
);
1527 range
= isl_space_drop_dims(range
, isl_dim_out
, 0, nested
->n_in
);
1529 return isl_space_free(space
);
1530 if (nested
->tuple_id
[1]) {
1531 range
->tuple_id
[1] = isl_id_copy(nested
->tuple_id
[1]);
1532 if (!range
->tuple_id
[1])
1535 if (nested
->nested
[1]) {
1536 range
->nested
[1] = isl_space_copy(nested
->nested
[1]);
1537 if (!range
->nested
[1])
1541 isl_space_free(space
);
1544 isl_space_free(space
);
1545 isl_space_free(range
);
1549 /* Given a space of the form A -> [B -> C], return the space A -> C.
1551 __isl_give isl_space
*isl_space_range_factor_range(
1552 __isl_take isl_space
*space
)
1556 if (!isl_space_range_is_wrapping(space
))
1557 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1558 "range not a product", return isl_space_free(space
));
1560 return range_factor_range(space
);
1563 /* Given a space of the form [A -> B], return the space B.
1565 static __isl_give isl_space
*set_factor_range(__isl_take isl_space
*space
)
1569 if (!isl_space_is_wrapping(space
))
1570 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1571 "not a product", return isl_space_free(space
));
1573 return range_factor_range(space
);
1576 /* Given a space of the form [A -> B] -> [C -> D], return the space B -> D.
1577 * Given a space of the form [A -> B], return the space B.
1579 __isl_give isl_space
*isl_space_factor_range(__isl_take isl_space
*space
)
1583 if (isl_space_is_set(space
))
1584 return set_factor_range(space
);
1585 space
= isl_space_domain_factor_range(space
);
1586 space
= isl_space_range_factor_range(space
);
1590 __isl_give isl_space
*isl_space_map_from_set(__isl_take isl_space
*space
)
1593 isl_id
**ids
= NULL
;
1598 ctx
= isl_space_get_ctx(space
);
1599 if (!isl_space_is_set(space
))
1600 isl_die(ctx
, isl_error_invalid
, "not a set space", goto error
);
1601 space
= isl_space_cow(space
);
1604 n_id
= space
->nparam
+ space
->n_out
+ space
->n_out
;
1605 if (n_id
> 0 && space
->ids
) {
1606 ids
= isl_calloc_array(space
->ctx
, isl_id
*, n_id
);
1609 get_ids(space
, isl_dim_param
, 0, space
->nparam
, ids
);
1610 get_ids(space
, isl_dim_out
, 0, space
->n_out
,
1611 ids
+ space
->nparam
);
1613 space
->n_in
= space
->n_out
;
1618 space
= copy_ids(space
, isl_dim_out
, 0, space
, isl_dim_in
);
1620 isl_id_free(space
->tuple_id
[0]);
1621 space
->tuple_id
[0] = isl_id_copy(space
->tuple_id
[1]);
1622 isl_space_free(space
->nested
[0]);
1623 space
->nested
[0] = isl_space_copy(space
->nested
[1]);
1626 isl_space_free(space
);
1630 __isl_give isl_space
*isl_space_map_from_domain_and_range(
1631 __isl_take isl_space
*domain
, __isl_take isl_space
*range
)
1633 if (!domain
|| !range
)
1635 if (!isl_space_is_set(domain
))
1636 isl_die(isl_space_get_ctx(domain
), isl_error_invalid
,
1637 "domain is not a set space", goto error
);
1638 if (!isl_space_is_set(range
))
1639 isl_die(isl_space_get_ctx(range
), isl_error_invalid
,
1640 "range is not a set space", goto error
);
1641 return isl_space_join(isl_space_reverse(domain
), range
);
1643 isl_space_free(domain
);
1644 isl_space_free(range
);
1648 static __isl_give isl_space
*set_ids(__isl_take isl_space
*dim
,
1649 enum isl_dim_type type
,
1650 unsigned first
, unsigned n
, __isl_take isl_id
**ids
)
1654 for (i
= 0; i
< n
; ++i
)
1655 dim
= set_id(dim
, type
, first
+ i
, ids
[i
]);
1660 __isl_give isl_space
*isl_space_reverse(__isl_take isl_space
*space
)
1664 isl_id
**ids
= NULL
;
1669 if (match(space
, isl_dim_in
, space
, isl_dim_out
))
1672 space
= isl_space_cow(space
);
1676 id
= space
->tuple_id
[0];
1677 space
->tuple_id
[0] = space
->tuple_id
[1];
1678 space
->tuple_id
[1] = id
;
1680 nested
= space
->nested
[0];
1681 space
->nested
[0] = space
->nested
[1];
1682 space
->nested
[1] = nested
;
1685 int n_id
= space
->n_in
+ space
->n_out
;
1686 ids
= isl_alloc_array(space
->ctx
, isl_id
*, n_id
);
1689 get_ids(space
, isl_dim_in
, 0, space
->n_in
, ids
);
1690 get_ids(space
, isl_dim_out
, 0, space
->n_out
, ids
+ space
->n_in
);
1694 space
->n_in
= space
->n_out
;
1698 space
= set_ids(space
, isl_dim_out
, 0, space
->n_out
, ids
);
1699 space
= set_ids(space
, isl_dim_in
, 0, space
->n_in
,
1700 ids
+ space
->n_out
);
1707 isl_space_free(space
);
1711 __isl_give isl_space
*isl_space_drop_dims(__isl_take isl_space
*space
,
1712 enum isl_dim_type type
, unsigned first
, unsigned num
)
1720 return isl_space_reset(space
, type
);
1722 if (!valid_dim_type(type
))
1723 isl_die(space
->ctx
, isl_error_invalid
,
1724 "cannot drop dimensions of specified type", goto error
);
1726 if (first
+ num
> n(space
, type
) || first
+ num
< first
)
1727 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1728 "index out of bounds", return isl_space_free(space
));
1729 space
= isl_space_cow(space
);
1733 space
= extend_ids(space
);
1736 for (i
= 0; i
< num
; ++i
)
1737 isl_id_free(get_id(space
, type
, first
+ i
));
1738 for (i
= first
+num
; i
< n(space
, type
); ++i
)
1739 set_id(space
, type
, i
- num
, get_id(space
, type
, i
));
1742 get_ids(space
, isl_dim_in
, 0, space
->n_in
,
1743 space
->ids
+ offset(space
, isl_dim_in
) - num
);
1745 get_ids(space
, isl_dim_out
, 0, space
->n_out
,
1746 space
->ids
+ offset(space
, isl_dim_out
) - num
);
1753 case isl_dim_param
: space
->nparam
-= num
; break;
1754 case isl_dim_in
: space
->n_in
-= num
; break;
1755 case isl_dim_out
: space
->n_out
-= num
; break;
1758 space
= isl_space_reset(space
, type
);
1759 if (type
== isl_dim_param
) {
1760 if (space
&& space
->nested
[0] &&
1761 !(space
->nested
[0] = isl_space_drop_dims(space
->nested
[0],
1762 isl_dim_param
, first
, num
)))
1764 if (space
&& space
->nested
[1] &&
1765 !(space
->nested
[1] = isl_space_drop_dims(space
->nested
[1],
1766 isl_dim_param
, first
, num
)))
1771 isl_space_free(space
);
1775 __isl_give isl_space
*isl_space_drop_inputs(__isl_take isl_space
*dim
,
1776 unsigned first
, unsigned n
)
1780 return isl_space_drop_dims(dim
, isl_dim_in
, first
, n
);
1783 __isl_give isl_space
*isl_space_drop_outputs(__isl_take isl_space
*dim
,
1784 unsigned first
, unsigned n
)
1788 return isl_space_drop_dims(dim
, isl_dim_out
, first
, n
);
1791 __isl_give isl_space
*isl_space_domain(__isl_take isl_space
*space
)
1795 space
= isl_space_drop_dims(space
, isl_dim_out
, 0, space
->n_out
);
1796 space
= isl_space_reverse(space
);
1797 space
= mark_as_set(space
);
1801 __isl_give isl_space
*isl_space_from_domain(__isl_take isl_space
*space
)
1805 if (!isl_space_is_set(space
))
1806 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1807 "not a set space", goto error
);
1808 space
= isl_space_reverse(space
);
1809 space
= isl_space_reset(space
, isl_dim_out
);
1812 isl_space_free(space
);
1816 __isl_give isl_space
*isl_space_range(__isl_take isl_space
*space
)
1820 space
= isl_space_drop_dims(space
, isl_dim_in
, 0, space
->n_in
);
1821 space
= mark_as_set(space
);
1825 __isl_give isl_space
*isl_space_from_range(__isl_take isl_space
*space
)
1829 if (!isl_space_is_set(space
))
1830 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1831 "not a set space", goto error
);
1832 return isl_space_reset(space
, isl_dim_in
);
1834 isl_space_free(space
);
1838 /* Given a map space A -> B, return the map space [A -> B] -> A.
1840 __isl_give isl_space
*isl_space_domain_map(__isl_take isl_space
*space
)
1844 domain
= isl_space_from_range(isl_space_domain(isl_space_copy(space
)));
1845 space
= isl_space_from_domain(isl_space_wrap(space
));
1846 space
= isl_space_join(space
, domain
);
1851 /* Given a map space A -> B, return the map space [A -> B] -> B.
1853 __isl_give isl_space
*isl_space_range_map(__isl_take isl_space
*space
)
1857 range
= isl_space_from_range(isl_space_range(isl_space_copy(space
)));
1858 space
= isl_space_from_domain(isl_space_wrap(space
));
1859 space
= isl_space_join(space
, range
);
1864 __isl_give isl_space
*isl_space_params(__isl_take isl_space
*space
)
1866 if (isl_space_is_params(space
))
1868 space
= isl_space_drop_dims(space
,
1869 isl_dim_in
, 0, isl_space_dim(space
, isl_dim_in
));
1870 space
= isl_space_drop_dims(space
,
1871 isl_dim_out
, 0, isl_space_dim(space
, isl_dim_out
));
1872 space
= mark_as_params(space
);
1876 __isl_give isl_space
*isl_space_set_from_params(__isl_take isl_space
*space
)
1880 if (!isl_space_is_params(space
))
1881 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
1882 "not a parameter space", goto error
);
1883 return isl_space_reset(space
, isl_dim_set
);
1885 isl_space_free(space
);
1889 __isl_give isl_space
*isl_space_underlying(__isl_take isl_space
*space
,
1897 space
->nparam
== 0 && space
->n_in
== 0 && space
->n_id
== 0)
1898 return isl_space_reset(isl_space_reset(space
, isl_dim_in
),
1900 space
= isl_space_cow(space
);
1903 space
->n_out
+= space
->nparam
+ space
->n_in
+ n_div
;
1907 for (i
= 0; i
< space
->n_id
; ++i
)
1908 isl_id_free(get_id(space
, isl_dim_out
, i
));
1910 space
= isl_space_reset(space
, isl_dim_in
);
1911 space
= isl_space_reset(space
, isl_dim_out
);
1916 /* Are the two spaces the same, including positions and names of parameters?
1918 isl_bool
isl_space_is_equal(__isl_keep isl_space
*space1
,
1919 __isl_keep isl_space
*space2
)
1923 if (!space1
|| !space2
)
1924 return isl_bool_error
;
1925 if (space1
== space2
)
1926 return isl_bool_true
;
1927 equal
= isl_space_has_equal_params(space1
, space2
);
1928 if (equal
< 0 || !equal
)
1930 return isl_space_has_equal_tuples(space1
, space2
);
1933 /* Do the tuples of "space1" correspond to those of the domain of "space2"?
1934 * That is, is "space1" eqaul to the domain of "space2", ignoring parameters.
1936 * "space2" is allowed to be a set space, in which case "space1"
1937 * should be a parameter space.
1939 isl_bool
isl_space_has_domain_tuples(__isl_keep isl_space
*space1
,
1940 __isl_keep isl_space
*space2
)
1944 is_set
= isl_space_is_set(space1
);
1945 if (is_set
< 0 || !is_set
)
1947 return isl_space_tuple_is_equal(space1
, isl_dim_set
,
1948 space2
, isl_dim_in
);
1951 /* Is space1 equal to the domain of space2?
1953 * In the internal version we also allow space2 to be the space of a set,
1954 * provided space1 is a parameter space.
1956 isl_bool
isl_space_is_domain_internal(__isl_keep isl_space
*space1
,
1957 __isl_keep isl_space
*space2
)
1959 isl_bool equal_params
;
1961 if (!space1
|| !space2
)
1962 return isl_bool_error
;
1963 equal_params
= isl_space_has_equal_params(space1
, space2
);
1964 if (equal_params
< 0 || !equal_params
)
1965 return equal_params
;
1966 return isl_space_has_domain_tuples(space1
, space2
);
1969 /* Is space1 equal to the domain of space2?
1971 isl_bool
isl_space_is_domain(__isl_keep isl_space
*space1
,
1972 __isl_keep isl_space
*space2
)
1975 return isl_bool_error
;
1976 if (!isl_space_is_map(space2
))
1977 return isl_bool_false
;
1978 return isl_space_is_domain_internal(space1
, space2
);
1981 /* Is space1 equal to the range of space2?
1983 * In the internal version, space2 is allowed to be the space of a set,
1984 * in which case it should be equal to space1.
1986 isl_bool
isl_space_is_range_internal(__isl_keep isl_space
*space1
,
1987 __isl_keep isl_space
*space2
)
1989 isl_bool equal_params
;
1991 if (!space1
|| !space2
)
1992 return isl_bool_error
;
1993 if (!isl_space_is_set(space1
))
1994 return isl_bool_false
;
1995 equal_params
= isl_space_has_equal_params(space1
, space2
);
1996 if (equal_params
< 0 || !equal_params
)
1997 return equal_params
;
1998 return isl_space_tuple_is_equal(space1
, isl_dim_set
,
1999 space2
, isl_dim_out
);
2002 /* Is space1 equal to the range of space2?
2004 isl_bool
isl_space_is_range(__isl_keep isl_space
*space1
,
2005 __isl_keep isl_space
*space2
)
2008 return isl_bool_error
;
2009 if (!isl_space_is_map(space2
))
2010 return isl_bool_false
;
2011 return isl_space_is_range_internal(space1
, space2
);
2014 /* Update "hash" by hashing in the parameters of "space".
2016 static uint32_t isl_hash_params(uint32_t hash
, __isl_keep isl_space
*space
)
2024 isl_hash_byte(hash
, space
->nparam
% 256);
2026 for (i
= 0; i
< space
->nparam
; ++i
) {
2027 id
= get_id(space
, isl_dim_param
, i
);
2028 hash
= isl_hash_id(hash
, id
);
2034 /* Update "hash" by hashing in the tuples of "space".
2035 * Changes in this function should be reflected in isl_hash_tuples_domain.
2037 static uint32_t isl_hash_tuples(uint32_t hash
, __isl_keep isl_space
*space
)
2044 isl_hash_byte(hash
, space
->n_in
% 256);
2045 isl_hash_byte(hash
, space
->n_out
% 256);
2047 id
= tuple_id(space
, isl_dim_in
);
2048 hash
= isl_hash_id(hash
, id
);
2049 id
= tuple_id(space
, isl_dim_out
);
2050 hash
= isl_hash_id(hash
, id
);
2052 hash
= isl_hash_tuples(hash
, space
->nested
[0]);
2053 hash
= isl_hash_tuples(hash
, space
->nested
[1]);
2058 /* Update "hash" by hashing in the domain tuple of "space".
2059 * The result of this function is equal to the result of applying
2060 * isl_hash_tuples to the domain of "space".
2062 static uint32_t isl_hash_tuples_domain(uint32_t hash
,
2063 __isl_keep isl_space
*space
)
2070 isl_hash_byte(hash
, 0);
2071 isl_hash_byte(hash
, space
->n_in
% 256);
2073 hash
= isl_hash_id(hash
, &isl_id_none
);
2074 id
= tuple_id(space
, isl_dim_in
);
2075 hash
= isl_hash_id(hash
, id
);
2077 hash
= isl_hash_tuples(hash
, space
->nested
[0]);
2082 /* Return a hash value that digests the tuples of "space",
2083 * i.e., that ignores the parameters.
2085 uint32_t isl_space_get_tuple_hash(__isl_keep isl_space
*space
)
2092 hash
= isl_hash_init();
2093 hash
= isl_hash_tuples(hash
, space
);
2098 uint32_t isl_space_get_hash(__isl_keep isl_space
*space
)
2105 hash
= isl_hash_init();
2106 hash
= isl_hash_params(hash
, space
);
2107 hash
= isl_hash_tuples(hash
, space
);
2112 /* Return the hash value of the domain of "space".
2113 * That is, isl_space_get_domain_hash(space) is equal to
2114 * isl_space_get_hash(isl_space_domain(space)).
2116 uint32_t isl_space_get_domain_hash(__isl_keep isl_space
*space
)
2123 hash
= isl_hash_init();
2124 hash
= isl_hash_params(hash
, space
);
2125 hash
= isl_hash_tuples_domain(hash
, space
);
2130 isl_bool
isl_space_is_wrapping(__isl_keep isl_space
*space
)
2133 return isl_bool_error
;
2135 if (!isl_space_is_set(space
))
2136 return isl_bool_false
;
2138 return space
->nested
[1] != NULL
;
2141 /* Is "space" the space of a map where the domain is a wrapped map space?
2143 isl_bool
isl_space_domain_is_wrapping(__isl_keep isl_space
*space
)
2146 return isl_bool_error
;
2148 if (isl_space_is_set(space
))
2149 return isl_bool_false
;
2151 return space
->nested
[0] != NULL
;
2154 /* Is "space" the space of a map where the range is a wrapped map space?
2156 isl_bool
isl_space_range_is_wrapping(__isl_keep isl_space
*space
)
2159 return isl_bool_error
;
2161 if (isl_space_is_set(space
))
2162 return isl_bool_false
;
2164 return space
->nested
[1] != NULL
;
2167 /* Is "space" a product of two spaces?
2168 * That is, is it a wrapping set space or a map space
2169 * with wrapping domain and range?
2171 isl_bool
isl_space_is_product(__isl_keep isl_space
*space
)
2174 isl_bool is_product
;
2176 is_set
= isl_space_is_set(space
);
2178 return isl_bool_error
;
2180 return isl_space_is_wrapping(space
);
2181 is_product
= isl_space_domain_is_wrapping(space
);
2182 if (is_product
< 0 || !is_product
)
2184 return isl_space_range_is_wrapping(space
);
2187 __isl_give isl_space
*isl_space_wrap(__isl_take isl_space
*space
)
2194 wrap
= isl_space_set_alloc(space
->ctx
,
2195 space
->nparam
, space
->n_in
+ space
->n_out
);
2197 wrap
= copy_ids(wrap
, isl_dim_param
, 0, space
, isl_dim_param
);
2198 wrap
= copy_ids(wrap
, isl_dim_set
, 0, space
, isl_dim_in
);
2199 wrap
= copy_ids(wrap
, isl_dim_set
, space
->n_in
, space
, isl_dim_out
);
2204 wrap
->nested
[1] = space
;
2208 isl_space_free(space
);
2212 __isl_give isl_space
*isl_space_unwrap(__isl_take isl_space
*space
)
2219 if (!isl_space_is_wrapping(space
))
2220 isl_die(space
->ctx
, isl_error_invalid
, "not a wrapping space",
2223 unwrap
= isl_space_copy(space
->nested
[1]);
2224 isl_space_free(space
);
2228 isl_space_free(space
);
2232 isl_bool
isl_space_is_named_or_nested(__isl_keep isl_space
*space
,
2233 enum isl_dim_type type
)
2235 if (type
!= isl_dim_in
&& type
!= isl_dim_out
)
2236 return isl_bool_false
;
2238 return isl_bool_error
;
2239 if (space
->tuple_id
[type
- isl_dim_in
])
2240 return isl_bool_true
;
2241 if (space
->nested
[type
- isl_dim_in
])
2242 return isl_bool_true
;
2243 return isl_bool_false
;
2246 isl_bool
isl_space_may_be_set(__isl_keep isl_space
*space
)
2251 return isl_bool_error
;
2252 if (isl_space_is_set(space
))
2253 return isl_bool_true
;
2254 if (isl_space_dim(space
, isl_dim_in
) != 0)
2255 return isl_bool_false
;
2256 nested
= isl_space_is_named_or_nested(space
, isl_dim_in
);
2257 if (nested
< 0 || nested
)
2258 return isl_bool_not(nested
);
2259 return isl_bool_true
;
2262 __isl_give isl_space
*isl_space_reset(__isl_take isl_space
*space
,
2263 enum isl_dim_type type
)
2265 if (!isl_space_is_named_or_nested(space
, type
))
2268 space
= isl_space_cow(space
);
2272 isl_id_free(space
->tuple_id
[type
- isl_dim_in
]);
2273 space
->tuple_id
[type
- isl_dim_in
] = NULL
;
2274 isl_space_free(space
->nested
[type
- isl_dim_in
]);
2275 space
->nested
[type
- isl_dim_in
] = NULL
;
2280 __isl_give isl_space
*isl_space_flatten(__isl_take isl_space
*space
)
2284 if (!space
->nested
[0] && !space
->nested
[1])
2287 if (space
->nested
[0])
2288 space
= isl_space_reset(space
, isl_dim_in
);
2289 if (space
&& space
->nested
[1])
2290 space
= isl_space_reset(space
, isl_dim_out
);
2295 __isl_give isl_space
*isl_space_flatten_domain(__isl_take isl_space
*space
)
2299 if (!space
->nested
[0])
2302 return isl_space_reset(space
, isl_dim_in
);
2305 __isl_give isl_space
*isl_space_flatten_range(__isl_take isl_space
*space
)
2309 if (!space
->nested
[1])
2312 return isl_space_reset(space
, isl_dim_out
);
2315 /* Replace the parameters of dst by those of src.
2317 __isl_give isl_space
*isl_space_replace_params(__isl_take isl_space
*dst
,
2318 __isl_keep isl_space
*src
)
2320 isl_bool equal_params
;
2321 enum isl_dim_type type
= isl_dim_param
;
2323 equal_params
= isl_space_has_equal_params(dst
, src
);
2324 if (equal_params
< 0)
2325 return isl_space_free(dst
);
2329 dst
= isl_space_cow(dst
);
2334 dst
= isl_space_drop_dims(dst
, type
, 0, isl_space_dim(dst
, type
));
2335 dst
= isl_space_add_dims(dst
, type
, isl_space_dim(src
, type
));
2336 dst
= copy_ids(dst
, type
, 0, src
, type
);
2340 for (i
= 0; i
<= 1; ++i
) {
2341 if (!dst
->nested
[i
])
2343 dst
->nested
[i
] = isl_space_replace_params(
2344 dst
->nested
[i
], src
);
2345 if (!dst
->nested
[i
])
2352 isl_space_free(dst
);
2356 /* Given a dimension specification "dim" of a set, create a dimension
2357 * specification for the lift of the set. In particular, the result
2358 * is of the form [dim -> local[..]], with n_local variables in the
2359 * range of the wrapped map.
2361 __isl_give isl_space
*isl_space_lift(__isl_take isl_space
*space
,
2364 isl_space
*local_space
;
2369 local_space
= isl_space_dup(space
);
2370 local_space
= isl_space_drop_dims(local_space
, isl_dim_set
, 0,
2372 local_space
= isl_space_add_dims(local_space
, isl_dim_set
, n_local
);
2373 local_space
= isl_space_set_tuple_name(local_space
,
2374 isl_dim_set
, "local");
2375 space
= isl_space_join(isl_space_from_domain(space
),
2376 isl_space_from_range(local_space
));
2377 space
= isl_space_wrap(space
);
2378 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "lifted");
2383 isl_bool
isl_space_can_zip(__isl_keep isl_space
*space
)
2387 is_set
= isl_space_is_set(space
);
2389 return isl_bool_error
;
2391 return isl_bool_false
;
2392 return isl_space_is_product(space
);
2395 __isl_give isl_space
*isl_space_zip(__isl_take isl_space
*space
)
2397 isl_space
*dom
, *ran
;
2398 isl_space
*dom_dom
, *dom_ran
, *ran_dom
, *ran_ran
;
2400 if (!isl_space_can_zip(space
))
2401 isl_die(space
->ctx
, isl_error_invalid
, "dim cannot be zipped",
2406 dom
= isl_space_unwrap(isl_space_domain(isl_space_copy(space
)));
2407 ran
= isl_space_unwrap(isl_space_range(space
));
2408 dom_dom
= isl_space_domain(isl_space_copy(dom
));
2409 dom_ran
= isl_space_range(dom
);
2410 ran_dom
= isl_space_domain(isl_space_copy(ran
));
2411 ran_ran
= isl_space_range(ran
);
2412 dom
= isl_space_join(isl_space_from_domain(dom_dom
),
2413 isl_space_from_range(ran_dom
));
2414 ran
= isl_space_join(isl_space_from_domain(dom_ran
),
2415 isl_space_from_range(ran_ran
));
2416 return isl_space_join(isl_space_from_domain(isl_space_wrap(dom
)),
2417 isl_space_from_range(isl_space_wrap(ran
)));
2419 isl_space_free(space
);
2423 /* Can we apply isl_space_curry to "space"?
2424 * That is, does it have a nested relation in its domain?
2426 isl_bool
isl_space_can_curry(__isl_keep isl_space
*space
)
2429 return isl_bool_error
;
2431 return !!space
->nested
[0];
2434 /* Given a space (A -> B) -> C, return the corresponding space
2437 __isl_give isl_space
*isl_space_curry(__isl_take isl_space
*space
)
2439 isl_space
*dom
, *ran
;
2440 isl_space
*dom_dom
, *dom_ran
;
2445 if (!isl_space_can_curry(space
))
2446 isl_die(space
->ctx
, isl_error_invalid
,
2447 "space cannot be curried", goto error
);
2449 dom
= isl_space_unwrap(isl_space_domain(isl_space_copy(space
)));
2450 ran
= isl_space_range(space
);
2451 dom_dom
= isl_space_domain(isl_space_copy(dom
));
2452 dom_ran
= isl_space_range(dom
);
2453 ran
= isl_space_join(isl_space_from_domain(dom_ran
),
2454 isl_space_from_range(ran
));
2455 return isl_space_join(isl_space_from_domain(dom_dom
),
2456 isl_space_from_range(isl_space_wrap(ran
)));
2458 isl_space_free(space
);
2462 /* Can isl_space_range_curry be applied to "space"?
2463 * That is, does it have a nested relation in its range,
2464 * the domain of which is itself a nested relation?
2466 isl_bool
isl_space_can_range_curry(__isl_keep isl_space
*space
)
2471 return isl_bool_error
;
2472 can
= isl_space_range_is_wrapping(space
);
2473 if (can
< 0 || !can
)
2475 return isl_space_can_curry(space
->nested
[1]);
2478 /* Given a space A -> ((B -> C) -> D), return the corresponding space
2479 * A -> (B -> (C -> D)).
2481 __isl_give isl_space
*isl_space_range_curry(__isl_take isl_space
*space
)
2486 if (!isl_space_can_range_curry(space
))
2487 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
2488 "space range cannot be curried",
2489 return isl_space_free(space
));
2491 space
= isl_space_cow(space
);
2494 space
->nested
[1] = isl_space_curry(space
->nested
[1]);
2495 if (!space
->nested
[1])
2496 return isl_space_free(space
);
2501 /* Can we apply isl_space_uncurry to "space"?
2502 * That is, does it have a nested relation in its range?
2504 isl_bool
isl_space_can_uncurry(__isl_keep isl_space
*space
)
2507 return isl_bool_error
;
2509 return !!space
->nested
[1];
2512 /* Given a space A -> (B -> C), return the corresponding space
2515 __isl_give isl_space
*isl_space_uncurry(__isl_take isl_space
*space
)
2517 isl_space
*dom
, *ran
;
2518 isl_space
*ran_dom
, *ran_ran
;
2523 if (!isl_space_can_uncurry(space
))
2524 isl_die(space
->ctx
, isl_error_invalid
,
2525 "space cannot be uncurried",
2526 return isl_space_free(space
));
2528 dom
= isl_space_domain(isl_space_copy(space
));
2529 ran
= isl_space_unwrap(isl_space_range(space
));
2530 ran_dom
= isl_space_domain(isl_space_copy(ran
));
2531 ran_ran
= isl_space_range(ran
);
2532 dom
= isl_space_join(isl_space_from_domain(dom
),
2533 isl_space_from_range(ran_dom
));
2534 return isl_space_join(isl_space_from_domain(isl_space_wrap(dom
)),
2535 isl_space_from_range(ran_ran
));
2538 isl_bool
isl_space_has_named_params(__isl_keep isl_space
*space
)
2544 return isl_bool_error
;
2545 if (space
->nparam
== 0)
2546 return isl_bool_true
;
2547 off
= isl_space_offset(space
, isl_dim_param
);
2548 if (off
+ space
->nparam
> space
->n_id
)
2549 return isl_bool_false
;
2550 for (i
= 0; i
< space
->nparam
; ++i
)
2551 if (!space
->ids
[off
+ i
])
2552 return isl_bool_false
;
2553 return isl_bool_true
;
2556 /* Check that "space" has only named parameters, reporting an error
2559 isl_stat
isl_space_check_named_params(__isl_keep isl_space
*space
)
2563 named
= isl_space_has_named_params(space
);
2565 return isl_stat_error
;
2567 isl_die(isl_space_get_ctx(space
), isl_error_invalid
,
2568 "unexpected unnamed parameters", return isl_stat_error
);
2573 /* Align the initial parameters of space1 to match the order in space2.
2575 __isl_give isl_space
*isl_space_align_params(__isl_take isl_space
*space1
,
2576 __isl_take isl_space
*space2
)
2578 isl_reordering
*exp
;
2580 if (isl_space_check_named_params(space1
) < 0 ||
2581 isl_space_check_named_params(space2
) < 0)
2584 exp
= isl_parameter_alignment_reordering(space1
, space2
);
2585 exp
= isl_reordering_extend_space(exp
, space1
);
2586 isl_space_free(space2
);
2587 space1
= isl_reordering_get_space(exp
);
2588 isl_reordering_free(exp
);
2591 isl_space_free(space1
);
2592 isl_space_free(space2
);
2596 /* Given the space of set (domain), construct a space for a map
2597 * with as domain the given space and as range the range of "model".
2599 __isl_give isl_space
*isl_space_extend_domain_with_range(
2600 __isl_take isl_space
*space
, __isl_take isl_space
*model
)
2605 space
= isl_space_from_domain(space
);
2606 space
= isl_space_add_dims(space
, isl_dim_out
,
2607 isl_space_dim(model
, isl_dim_out
));
2608 if (isl_space_has_tuple_id(model
, isl_dim_out
))
2609 space
= isl_space_set_tuple_id(space
, isl_dim_out
,
2610 isl_space_get_tuple_id(model
, isl_dim_out
));
2613 if (model
->nested
[1]) {
2614 isl_space
*nested
= isl_space_copy(model
->nested
[1]);
2615 int n_nested
, n_space
;
2616 nested
= isl_space_align_params(nested
, isl_space_copy(space
));
2617 n_nested
= isl_space_dim(nested
, isl_dim_param
);
2618 n_space
= isl_space_dim(space
, isl_dim_param
);
2619 if (n_nested
> n_space
)
2620 nested
= isl_space_drop_dims(nested
, isl_dim_param
,
2621 n_space
, n_nested
- n_space
);
2624 space
->nested
[1] = nested
;
2626 isl_space_free(model
);
2629 isl_space_free(model
);
2630 isl_space_free(space
);
2634 /* Compare the "type" dimensions of two isl_spaces.
2636 * The order is fairly arbitrary.
2638 static int isl_space_cmp_type(__isl_keep isl_space
*space1
,
2639 __isl_keep isl_space
*space2
, enum isl_dim_type type
)
2642 isl_space
*nested1
, *nested2
;
2644 if (isl_space_dim(space1
, type
) != isl_space_dim(space2
, type
))
2645 return isl_space_dim(space1
, type
) -
2646 isl_space_dim(space2
, type
);
2648 cmp
= isl_id_cmp(tuple_id(space1
, type
), tuple_id(space2
, type
));
2652 nested1
= nested(space1
, type
);
2653 nested2
= nested(space2
, type
);
2654 if (!nested1
!= !nested2
)
2655 return !nested1
- !nested2
;
2658 return isl_space_cmp(nested1
, nested2
);
2663 /* Compare two isl_spaces.
2665 * The order is fairly arbitrary.
2667 int isl_space_cmp(__isl_keep isl_space
*space1
, __isl_keep isl_space
*space2
)
2672 if (space1
== space2
)
2679 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_param
);
2682 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_in
);
2685 cmp
= isl_space_cmp_type(space1
, space2
, isl_dim_out
);
2689 if (!space1
->ids
&& !space2
->ids
)
2692 for (i
= 0; i
< n(space1
, isl_dim_param
); ++i
) {
2693 cmp
= isl_id_cmp(get_id(space1
, isl_dim_param
, i
),
2694 get_id(space2
, isl_dim_param
, i
));