2 * Copyright 2011 INRIA Saclay
3 * Copyright 2012-2014 Ecole Normale Superieure
4 * Copyright 2019 Cerebras Systems
6 * Use of this software is governed by the MIT license
8 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
9 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
11 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
12 * and Cerebras Systems, 175 S San Antonio Rd, Los Altos, CA, USA
15 #include <isl_ctx_private.h>
17 #include <isl_map_private.h>
18 #include <isl_local_space_private.h>
19 #include <isl_space_private.h>
20 #include <isl_mat_private.h>
21 #include <isl_aff_private.h>
22 #include <isl_vec_private.h>
23 #include <isl_point_private.h>
25 #include <isl_local.h>
27 isl_ctx
*isl_local_space_get_ctx(__isl_keep isl_local_space
*ls
)
29 return ls
? ls
->dim
->ctx
: NULL
;
32 /* Return a hash value that digests "ls".
34 uint32_t isl_local_space_get_hash(__isl_keep isl_local_space
*ls
)
36 uint32_t hash
, space_hash
, div_hash
;
41 hash
= isl_hash_init();
42 space_hash
= isl_space_get_full_hash(isl_local_space_peek_space(ls
));
43 isl_hash_hash(hash
, space_hash
);
44 div_hash
= isl_mat_get_hash(ls
->div
);
45 isl_hash_hash(hash
, div_hash
);
50 __isl_give isl_local_space
*isl_local_space_alloc_div(
51 __isl_take isl_space
*space
, __isl_take isl_mat
*div
)
54 isl_local_space
*ls
= NULL
;
59 ctx
= isl_space_get_ctx(space
);
60 ls
= isl_calloc_type(ctx
, struct isl_local_space
);
71 isl_space_free(space
);
72 isl_local_space_free(ls
);
76 __isl_give isl_local_space
*isl_local_space_alloc(__isl_take isl_space
*space
,
86 total
= isl_space_dim(space
, isl_dim_all
);
88 return isl_local_space_from_space(isl_space_free(space
));
90 ctx
= isl_space_get_ctx(space
);
91 div
= isl_mat_alloc(ctx
, n_div
, 1 + 1 + total
+ n_div
);
92 return isl_local_space_alloc_div(space
, div
);
95 __isl_give isl_local_space
*isl_local_space_from_space(
96 __isl_take isl_space
*space
)
98 return isl_local_space_alloc(space
, 0);
101 __isl_give isl_local_space
*isl_local_space_copy(__isl_keep isl_local_space
*ls
)
110 __isl_give isl_local_space
*isl_local_space_dup(__isl_keep isl_local_space
*ls
)
115 return isl_local_space_alloc_div(isl_space_copy(ls
->dim
),
116 isl_mat_copy(ls
->div
));
120 __isl_give isl_local_space
*isl_local_space_cow(__isl_take isl_local_space
*ls
)
128 return isl_local_space_dup(ls
);
131 __isl_null isl_local_space
*isl_local_space_free(
132 __isl_take isl_local_space
*ls
)
140 isl_space_free(ls
->dim
);
141 isl_mat_free(ls
->div
);
148 /* Is the local space that of a parameter domain?
150 isl_bool
isl_local_space_is_params(__isl_keep isl_local_space
*ls
)
153 return isl_bool_error
;
154 return isl_space_is_params(ls
->dim
);
157 /* Is the local space that of a set?
159 isl_bool
isl_local_space_is_set(__isl_keep isl_local_space
*ls
)
161 return ls
? isl_space_is_set(ls
->dim
) : isl_bool_error
;
165 #define TYPE isl_local_space
167 #include "isl_type_has_equal_space_bin_templ.c"
168 #include "isl_type_has_space_templ.c"
170 /* Check that the space of "ls" is equal to "space".
172 static isl_stat
isl_local_space_check_has_space(__isl_keep isl_local_space
*ls
,
173 __isl_keep isl_space
*space
)
177 ok
= isl_local_space_has_space(ls
, space
);
179 return isl_stat_error
;
181 isl_die(isl_local_space_get_ctx(ls
), isl_error_invalid
,
182 "spaces don't match", return isl_stat_error
);
186 /* Return true if the two local spaces are identical, with identical
187 * expressions for the integer divisions.
189 isl_bool
isl_local_space_is_equal(__isl_keep isl_local_space
*ls1
,
190 __isl_keep isl_local_space
*ls2
)
194 equal
= isl_local_space_has_equal_space(ls1
, ls2
);
195 if (equal
< 0 || !equal
)
198 if (!isl_local_space_divs_known(ls1
))
199 return isl_bool_false
;
200 if (!isl_local_space_divs_known(ls2
))
201 return isl_bool_false
;
203 return isl_mat_is_equal(ls1
->div
, ls2
->div
);
206 /* Compare two isl_local_spaces.
208 * Return -1 if "ls1" is "smaller" than "ls2", 1 if "ls1" is "greater"
209 * than "ls2" and 0 if they are equal.
211 int isl_local_space_cmp(__isl_keep isl_local_space
*ls1
,
212 __isl_keep isl_local_space
*ls2
)
223 cmp
= isl_space_cmp(ls1
->dim
, ls2
->dim
);
227 return isl_local_cmp(ls1
->div
, ls2
->div
);
230 isl_size
isl_local_space_dim(__isl_keep isl_local_space
*ls
,
231 enum isl_dim_type type
)
234 return isl_size_error
;
235 if (type
== isl_dim_div
)
236 return ls
->div
->n_row
;
237 if (type
== isl_dim_all
) {
238 isl_size dim
= isl_space_dim(ls
->dim
, isl_dim_all
);
240 return isl_size_error
;
241 return dim
+ ls
->div
->n_row
;
243 return isl_space_dim(ls
->dim
, type
);
247 #define TYPE isl_local_space
248 #include "check_type_range_templ.c"
250 /* Return the position of the variables of the given type
251 * within the sequence of variables of "ls".
253 isl_size
isl_local_space_var_offset(__isl_keep isl_local_space
*ls
,
254 enum isl_dim_type type
)
258 space
= isl_local_space_peek_space(ls
);
260 return isl_size_error
;
264 case isl_dim_out
: return isl_space_offset(space
, type
);
265 case isl_dim_div
: return isl_space_dim(space
, isl_dim_all
);
268 isl_die(isl_local_space_get_ctx(ls
), isl_error_invalid
,
269 "invalid dimension type", return isl_size_error
);
273 /* Return the position of the coefficients of the variables of the given type
274 * within the sequence of coefficients of "ls".
276 unsigned isl_local_space_offset(__isl_keep isl_local_space
*ls
,
277 enum isl_dim_type type
)
283 case isl_dim_cst
: return 0;
287 case isl_dim_div
: return 1 + isl_local_space_var_offset(ls
, type
);
292 /* Return the position of the dimension of the given type and name
294 * Return -1 if no such dimension can be found.
296 int isl_local_space_find_dim_by_name(__isl_keep isl_local_space
*ls
,
297 enum isl_dim_type type
, const char *name
)
301 if (type
== isl_dim_div
)
303 return isl_space_find_dim_by_name(ls
->dim
, type
, name
);
306 /* Does the given dimension have a name?
308 isl_bool
isl_local_space_has_dim_name(__isl_keep isl_local_space
*ls
,
309 enum isl_dim_type type
, unsigned pos
)
311 return ls
? isl_space_has_dim_name(ls
->dim
, type
, pos
) : isl_bool_error
;
314 const char *isl_local_space_get_dim_name(__isl_keep isl_local_space
*ls
,
315 enum isl_dim_type type
, unsigned pos
)
317 return ls
? isl_space_get_dim_name(ls
->dim
, type
, pos
) : NULL
;
320 isl_bool
isl_local_space_has_dim_id(__isl_keep isl_local_space
*ls
,
321 enum isl_dim_type type
, unsigned pos
)
323 return ls
? isl_space_has_dim_id(ls
->dim
, type
, pos
) : isl_bool_error
;
326 __isl_give isl_id
*isl_local_space_get_dim_id(__isl_keep isl_local_space
*ls
,
327 enum isl_dim_type type
, unsigned pos
)
329 return ls
? isl_space_get_dim_id(ls
->dim
, type
, pos
) : NULL
;
332 /* Return the argument of the integer division at position "pos" in "ls".
333 * All local variables in "ls" are known to have a (complete) explicit
336 static __isl_give isl_aff
*extract_div(__isl_keep isl_local_space
*ls
, int pos
)
340 aff
= isl_aff_alloc(isl_local_space_copy(ls
));
343 isl_seq_cpy(aff
->v
->el
, ls
->div
->row
[pos
], aff
->v
->size
);
347 /* Return the argument of the integer division at position "pos" in "ls".
348 * The integer division at that position is known to have a complete
349 * explicit representation, but some of the others do not.
350 * Remove them first because the domain of an isl_aff
351 * is not allowed to have unknown local variables.
353 static __isl_give isl_aff
*drop_unknown_divs_and_extract_div(
354 __isl_keep isl_local_space
*ls
, int pos
)
361 n
= isl_local_space_dim(ls
, isl_dim_div
);
364 ls
= isl_local_space_copy(ls
);
365 for (i
= n
- 1; i
>= 0; --i
) {
366 unknown
= isl_local_space_div_is_marked_unknown(ls
, i
);
368 ls
= isl_local_space_free(ls
);
371 ls
= isl_local_space_drop_dims(ls
, isl_dim_div
, i
, 1);
375 aff
= extract_div(ls
, pos
);
376 isl_local_space_free(ls
);
380 /* Return the argument of the integer division at position "pos" in "ls".
381 * The integer division is assumed to have a complete explicit
382 * representation. If some of the other integer divisions
383 * do not have an explicit representation, then they need
384 * to be removed first because the domain of an isl_aff
385 * is not allowed to have unknown local variables.
387 __isl_give isl_aff
*isl_local_space_get_div(__isl_keep isl_local_space
*ls
,
395 if (pos
< 0 || pos
>= ls
->div
->n_row
)
396 isl_die(isl_local_space_get_ctx(ls
), isl_error_invalid
,
397 "index out of bounds", return NULL
);
399 known
= isl_local_space_div_is_known(ls
, pos
);
403 isl_die(isl_local_space_get_ctx(ls
), isl_error_invalid
,
404 "expression of div unknown", return NULL
);
405 if (!isl_local_space_is_set(ls
))
406 isl_die(isl_local_space_get_ctx(ls
), isl_error_invalid
,
407 "cannot represent divs of map spaces", return NULL
);
409 known
= isl_local_space_divs_known(ls
);
413 return extract_div(ls
, pos
);
415 return drop_unknown_divs_and_extract_div(ls
, pos
);
418 /* Return the space of "ls".
420 __isl_keep isl_space
*isl_local_space_peek_space(__isl_keep isl_local_space
*ls
)
428 __isl_give isl_space
*isl_local_space_get_space(__isl_keep isl_local_space
*ls
)
430 return isl_space_copy(isl_local_space_peek_space(ls
));
433 /* Return the space of "ls".
434 * This may be either a copy or the space itself
435 * if there is only one reference to "ls".
436 * This allows the space to be modified inplace
437 * if both the local space and its space have only a single reference.
438 * The caller is not allowed to modify "ls" between this call and
439 * a subsequent call to isl_local_space_restore_space.
440 * The only exception is that isl_local_space_free can be called instead.
442 __isl_give isl_space
*isl_local_space_take_space(__isl_keep isl_local_space
*ls
)
449 return isl_local_space_get_space(ls
);
455 /* Set the space of "ls" to "space", where the space of "ls" may be missing
456 * due to a preceding call to isl_local_space_take_space.
457 * However, in this case, "ls" only has a single reference and
458 * then the call to isl_local_space_cow has no effect.
460 __isl_give isl_local_space
*isl_local_space_restore_space(
461 __isl_take isl_local_space
*ls
, __isl_take isl_space
*space
)
466 if (ls
->dim
== space
) {
467 isl_space_free(space
);
471 ls
= isl_local_space_cow(ls
);
474 isl_space_free(ls
->dim
);
479 isl_local_space_free(ls
);
480 isl_space_free(space
);
484 /* Return the local variables of "ls".
486 __isl_keep isl_local
*isl_local_space_peek_local(__isl_keep isl_local_space
*ls
)
488 return ls
? ls
->div
: NULL
;
491 /* Return a copy of the local variables of "ls".
493 __isl_keep isl_local
*isl_local_space_get_local(__isl_keep isl_local_space
*ls
)
495 return isl_local_copy(isl_local_space_peek_local(ls
));
498 /* Return the local variables of "ls".
499 * This may be either a copy or the local variables itself
500 * if there is only one reference to "ls".
501 * This allows the local variables to be modified inplace
502 * if both the local space and its local variables have only a single reference.
503 * The caller is not allowed to modify "ls" between this call and
504 * the subsequent call to isl_local_space_restore_local.
505 * The only exception is that isl_local_space_free can be called instead.
507 static __isl_give isl_local
*isl_local_space_take_local(
508 __isl_keep isl_local_space
*ls
)
515 return isl_local_space_get_local(ls
);
521 /* Set the local variables of "ls" to "local",
522 * where the local variables of "ls" may be missing
523 * due to a preceding call to isl_local_space_take_local.
524 * However, in this case, "ls" only has a single reference and
525 * then the call to isl_local_space_cow has no effect.
527 static __isl_give isl_local_space
*isl_local_space_restore_local(
528 __isl_take isl_local_space
*ls
, __isl_take isl_local
*local
)
533 if (ls
->div
== local
) {
534 isl_local_free(local
);
538 ls
= isl_local_space_cow(ls
);
541 isl_local_free(ls
->div
);
546 isl_local_space_free(ls
);
547 isl_local_free(local
);
551 /* Replace the identifier of the tuple of type "type" by "id".
553 __isl_give isl_local_space
*isl_local_space_set_tuple_id(
554 __isl_take isl_local_space
*ls
,
555 enum isl_dim_type type
, __isl_take isl_id
*id
)
557 ls
= isl_local_space_cow(ls
);
560 ls
->dim
= isl_space_set_tuple_id(ls
->dim
, type
, id
);
562 return isl_local_space_free(ls
);
569 __isl_give isl_local_space
*isl_local_space_set_dim_name(
570 __isl_take isl_local_space
*ls
,
571 enum isl_dim_type type
, unsigned pos
, const char *s
)
573 ls
= isl_local_space_cow(ls
);
576 ls
->dim
= isl_space_set_dim_name(ls
->dim
, type
, pos
, s
);
578 return isl_local_space_free(ls
);
583 __isl_give isl_local_space
*isl_local_space_set_dim_id(
584 __isl_take isl_local_space
*ls
,
585 enum isl_dim_type type
, unsigned pos
, __isl_take isl_id
*id
)
587 ls
= isl_local_space_cow(ls
);
590 ls
->dim
= isl_space_set_dim_id(ls
->dim
, type
, pos
, id
);
592 return isl_local_space_free(ls
);
600 /* Construct a zero-dimensional local space with the given parameter domain.
602 __isl_give isl_local_space
*isl_local_space_set_from_params(
603 __isl_take isl_local_space
*ls
)
607 space
= isl_local_space_take_space(ls
);
608 space
= isl_space_set_from_params(space
);
609 ls
= isl_local_space_restore_space(ls
, space
);
614 __isl_give isl_local_space
*isl_local_space_reset_space(
615 __isl_take isl_local_space
*ls
, __isl_take isl_space
*space
)
617 ls
= isl_local_space_cow(ls
);
621 isl_space_free(ls
->dim
);
626 isl_local_space_free(ls
);
627 isl_space_free(space
);
631 /* Reorder the dimensions of "ls" according to the given reordering.
632 * The reordering r is assumed to have been extended with the local
633 * variables, leaving them in the same order.
635 __isl_give isl_local_space
*isl_local_space_realign(
636 __isl_take isl_local_space
*ls
, __isl_take isl_reordering
*r
)
640 local
= isl_local_space_take_local(ls
);
641 local
= isl_local_reorder(local
, isl_reordering_copy(r
));
642 ls
= isl_local_space_restore_local(ls
, local
);
644 ls
= isl_local_space_reset_space(ls
, isl_reordering_get_space(r
));
646 isl_reordering_free(r
);
650 __isl_give isl_local_space
*isl_local_space_add_div(
651 __isl_take isl_local_space
*ls
, __isl_take isl_vec
*div
)
653 ls
= isl_local_space_cow(ls
);
657 if (ls
->div
->n_col
!= div
->size
)
658 isl_die(isl_local_space_get_ctx(ls
), isl_error_invalid
,
659 "incompatible dimensions", goto error
);
661 ls
->div
= isl_mat_add_zero_cols(ls
->div
, 1);
662 ls
->div
= isl_mat_add_rows(ls
->div
, 1);
666 isl_seq_cpy(ls
->div
->row
[ls
->div
->n_row
- 1], div
->el
, div
->size
);
667 isl_int_set_si(ls
->div
->row
[ls
->div
->n_row
- 1][div
->size
], 0);
672 isl_local_space_free(ls
);
677 __isl_give isl_local_space
*isl_local_space_replace_divs(
678 __isl_take isl_local_space
*ls
, __isl_take isl_mat
*div
)
680 ls
= isl_local_space_cow(ls
);
685 isl_mat_free(ls
->div
);
690 isl_local_space_free(ls
);
694 /* Copy row "s" of "src" to row "d" of "dst", applying the expansion
697 static void expand_row(__isl_keep isl_mat
*dst
, int d
,
698 __isl_keep isl_mat
*src
, int s
, int *exp
)
701 unsigned c
= src
->n_col
- src
->n_row
;
703 isl_seq_cpy(dst
->row
[d
], src
->row
[s
], c
);
704 isl_seq_clr(dst
->row
[d
] + c
, dst
->n_col
- c
);
706 for (i
= 0; i
< s
; ++i
)
707 isl_int_set(dst
->row
[d
][c
+ exp
[i
]], src
->row
[s
][c
+ i
]);
710 /* Compare (known) divs.
711 * Return non-zero if at least one of the two divs is unknown.
712 * In particular, if both divs are unknown, we respect their
713 * current order. Otherwise, we sort the known div after the unknown
714 * div only if the known div depends on the unknown div.
716 static int cmp_row(isl_int
*row_i
, isl_int
*row_j
, int i
, int j
,
717 unsigned n_row
, unsigned n_col
)
720 int unknown_i
, unknown_j
;
722 unknown_i
= isl_int_is_zero(row_i
[0]);
723 unknown_j
= isl_int_is_zero(row_j
[0]);
725 if (unknown_i
&& unknown_j
)
729 li
= n_col
- n_row
+ i
;
731 li
= isl_seq_last_non_zero(row_i
, n_col
);
733 lj
= n_col
- n_row
+ j
;
735 lj
= isl_seq_last_non_zero(row_j
, n_col
);
740 return isl_seq_cmp(row_i
, row_j
, n_col
);
743 /* Call cmp_row for divs in a matrix.
745 int isl_mat_cmp_div(__isl_keep isl_mat
*div
, int i
, int j
)
747 return cmp_row(div
->row
[i
], div
->row
[j
], i
, j
, div
->n_row
, div
->n_col
);
750 /* Call cmp_row for divs in a basic map.
752 static int bmap_cmp_row(__isl_keep isl_basic_map
*bmap
, int i
, int j
,
755 return cmp_row(bmap
->div
[i
], bmap
->div
[j
], i
, j
, bmap
->n_div
, total
);
758 /* Sort the divs in "bmap".
760 * We first make sure divs are placed after divs on which they depend.
761 * Then we perform a simple insertion sort based on the same ordering
762 * that is used in isl_merge_divs.
764 __isl_give isl_basic_map
*isl_basic_map_sort_divs(
765 __isl_take isl_basic_map
*bmap
)
770 bmap
= isl_basic_map_order_divs(bmap
);
773 if (bmap
->n_div
<= 1)
776 total
= isl_basic_map_dim(bmap
, isl_dim_all
);
778 return isl_basic_map_free(bmap
);
779 for (i
= 1; i
< bmap
->n_div
; ++i
) {
780 for (j
= i
- 1; j
>= 0; --j
) {
781 if (bmap_cmp_row(bmap
, j
, j
+ 1, 2 + total
) <= 0)
783 bmap
= isl_basic_map_swap_div(bmap
, j
, j
+ 1);
792 /* Sort the divs in the basic maps of "map".
794 __isl_give isl_map
*isl_map_sort_divs(__isl_take isl_map
*map
)
796 return isl_map_inline_foreach_basic_map(map
, &isl_basic_map_sort_divs
);
799 /* Combine the two lists of divs into a single list.
800 * For each row i in div1, exp1[i] is set to the position of the corresponding
801 * row in the result. Similarly for div2 and exp2.
802 * This function guarantees
804 * exp1[i+1] > exp1[i]
805 * For optimal merging, the two input list should have been sorted.
807 __isl_give isl_mat
*isl_merge_divs(__isl_keep isl_mat
*div1
,
808 __isl_keep isl_mat
*div2
, int *exp1
, int *exp2
)
817 d
= div1
->n_col
- div1
->n_row
;
818 div
= isl_mat_alloc(div1
->ctx
, 1 + div1
->n_row
+ div2
->n_row
,
819 d
+ div1
->n_row
+ div2
->n_row
);
823 for (i
= 0, j
= 0, k
= 0; i
< div1
->n_row
&& j
< div2
->n_row
; ++k
) {
826 expand_row(div
, k
, div1
, i
, exp1
);
827 expand_row(div
, k
+ 1, div2
, j
, exp2
);
829 cmp
= isl_mat_cmp_div(div
, k
, k
+ 1);
833 } else if (cmp
< 0) {
837 isl_seq_cpy(div
->row
[k
], div
->row
[k
+ 1], div
->n_col
);
840 for (; i
< div1
->n_row
; ++i
, ++k
) {
841 expand_row(div
, k
, div1
, i
, exp1
);
844 for (; j
< div2
->n_row
; ++j
, ++k
) {
845 expand_row(div
, k
, div2
, j
, exp2
);
855 /* Swap divs "a" and "b" in "ls".
857 __isl_give isl_local_space
*isl_local_space_swap_div(
858 __isl_take isl_local_space
*ls
, int a
, int b
)
862 ls
= isl_local_space_cow(ls
);
865 if (a
< 0 || a
>= ls
->div
->n_row
|| b
< 0 || b
>= ls
->div
->n_row
)
866 isl_die(isl_local_space_get_ctx(ls
), isl_error_invalid
,
867 "index out of bounds", return isl_local_space_free(ls
));
868 offset
= ls
->div
->n_col
- ls
->div
->n_row
;
869 ls
->div
= isl_mat_swap_cols(ls
->div
, offset
+ a
, offset
+ b
);
870 ls
->div
= isl_mat_swap_rows(ls
->div
, a
, b
);
872 return isl_local_space_free(ls
);
876 /* Construct a local space that contains all the divs in either
879 __isl_give isl_local_space
*isl_local_space_intersect(
880 __isl_take isl_local_space
*ls1
, __isl_take isl_local_space
*ls2
)
891 ctx
= isl_local_space_get_ctx(ls1
);
892 if (!isl_space_is_equal(ls1
->dim
, ls2
->dim
))
893 isl_die(ctx
, isl_error_invalid
,
894 "spaces should be identical", goto error
);
896 if (ls2
->div
->n_row
== 0) {
897 isl_local_space_free(ls2
);
901 if (ls1
->div
->n_row
== 0) {
902 isl_local_space_free(ls1
);
906 exp1
= isl_alloc_array(ctx
, int, ls1
->div
->n_row
);
907 exp2
= isl_alloc_array(ctx
, int, ls2
->div
->n_row
);
911 div
= isl_merge_divs(ls1
->div
, ls2
->div
, exp1
, exp2
);
915 equal
= isl_mat_is_equal(ls1
->div
, div
);
919 ls1
= isl_local_space_cow(ls1
);
925 isl_local_space_free(ls2
);
926 isl_mat_free(ls1
->div
);
934 isl_local_space_free(ls1
);
935 isl_local_space_free(ls2
);
939 /* Is the local variable "div" of "ls" marked as not having
940 * an explicit representation?
941 * Note that even if this variable is not marked in this way and therefore
942 * does have an explicit representation, this representation may still
943 * depend (indirectly) on other local variables that do not
944 * have an explicit representation.
946 isl_bool
isl_local_space_div_is_marked_unknown(__isl_keep isl_local_space
*ls
,
950 return isl_bool_error
;
951 return isl_local_div_is_marked_unknown(ls
->div
, div
);
954 /* Does "ls" have a complete explicit representation for div "div"?
956 isl_bool
isl_local_space_div_is_known(__isl_keep isl_local_space
*ls
, int div
)
959 return isl_bool_error
;
960 return isl_local_div_is_known(ls
->div
, div
);
963 /* Does "ls" have an explicit representation for all local variables?
965 isl_bool
isl_local_space_divs_known(__isl_keep isl_local_space
*ls
)
968 return isl_bool_error
;
969 return isl_local_divs_known(ls
->div
);
972 __isl_give isl_local_space
*isl_local_space_domain(
973 __isl_take isl_local_space
*ls
)
977 n_out
= isl_local_space_dim(ls
, isl_dim_out
);
979 return isl_local_space_free(ls
);
980 ls
= isl_local_space_drop_dims(ls
, isl_dim_out
, 0, n_out
);
981 ls
= isl_local_space_cow(ls
);
984 ls
->dim
= isl_space_domain(ls
->dim
);
986 return isl_local_space_free(ls
);
990 __isl_give isl_local_space
*isl_local_space_range(
991 __isl_take isl_local_space
*ls
)
995 n_in
= isl_local_space_dim(ls
, isl_dim_in
);
997 return isl_local_space_free(ls
);
998 ls
= isl_local_space_drop_dims(ls
, isl_dim_in
, 0, n_in
);
999 ls
= isl_local_space_cow(ls
);
1003 ls
->dim
= isl_space_range(ls
->dim
);
1005 return isl_local_space_free(ls
);
1009 /* Construct a local space for a map that has the given local
1010 * space as domain and that has a zero-dimensional range.
1012 __isl_give isl_local_space
*isl_local_space_from_domain(
1013 __isl_take isl_local_space
*ls
)
1015 ls
= isl_local_space_cow(ls
);
1018 ls
->dim
= isl_space_from_domain(ls
->dim
);
1020 return isl_local_space_free(ls
);
1024 __isl_give isl_local_space
*isl_local_space_add_dims(
1025 __isl_take isl_local_space
*ls
, enum isl_dim_type type
, unsigned n
)
1029 pos
= isl_local_space_dim(ls
, type
);
1031 return isl_local_space_free(ls
);
1032 return isl_local_space_insert_dims(ls
, type
, pos
, n
);
1035 /* Lift the basic set "bset", living in the space of "ls"
1036 * to live in a space with extra coordinates corresponding
1037 * to the local variables of "ls".
1039 __isl_give isl_basic_set
*isl_local_space_lift_basic_set(
1040 __isl_take isl_local_space
*ls
, __isl_take isl_basic_set
*bset
)
1044 isl_basic_set
*ls_bset
;
1046 n_local
= isl_local_space_dim(ls
, isl_dim_div
);
1047 space
= isl_basic_set_peek_space(bset
);
1049 isl_local_space_check_has_space(ls
, space
) < 0)
1053 isl_local_space_free(ls
);
1057 bset
= isl_basic_set_add_dims(bset
, isl_dim_set
, n_local
);
1058 ls_bset
= isl_basic_set_from_local_space(ls
);
1059 ls_bset
= isl_basic_set_lift(ls_bset
);
1060 ls_bset
= isl_basic_set_flatten(ls_bset
);
1061 bset
= isl_basic_set_intersect(bset
, ls_bset
);
1065 isl_local_space_free(ls
);
1066 isl_basic_set_free(bset
);
1070 /* Lift the set "set", living in the space of "ls"
1071 * to live in a space with extra coordinates corresponding
1072 * to the local variables of "ls".
1074 __isl_give isl_set
*isl_local_space_lift_set(__isl_take isl_local_space
*ls
,
1075 __isl_take isl_set
*set
)
1078 isl_basic_set
*bset
;
1080 n_local
= isl_local_space_dim(ls
, isl_dim_div
);
1082 isl_local_space_check_has_space(ls
, isl_set_peek_space(set
)) < 0)
1086 isl_local_space_free(ls
);
1090 set
= isl_set_add_dims(set
, isl_dim_set
, n_local
);
1091 bset
= isl_basic_set_from_local_space(ls
);
1092 bset
= isl_basic_set_lift(bset
);
1093 bset
= isl_basic_set_flatten(bset
);
1094 set
= isl_set_intersect(set
, isl_set_from_basic_set(bset
));
1098 isl_local_space_free(ls
);
1103 /* Remove common factor of non-constant terms and denominator.
1105 static __isl_give isl_local_space
*normalize_div(
1106 __isl_take isl_local_space
*ls
, int div
)
1108 isl_ctx
*ctx
= ls
->div
->ctx
;
1109 unsigned total
= ls
->div
->n_col
- 2;
1111 isl_seq_gcd(ls
->div
->row
[div
] + 2, total
, &ctx
->normalize_gcd
);
1112 isl_int_gcd(ctx
->normalize_gcd
,
1113 ctx
->normalize_gcd
, ls
->div
->row
[div
][0]);
1114 if (isl_int_is_one(ctx
->normalize_gcd
))
1117 isl_seq_scale_down(ls
->div
->row
[div
] + 2, ls
->div
->row
[div
] + 2,
1118 ctx
->normalize_gcd
, total
);
1119 isl_int_divexact(ls
->div
->row
[div
][0], ls
->div
->row
[div
][0],
1120 ctx
->normalize_gcd
);
1121 isl_int_fdiv_q(ls
->div
->row
[div
][1], ls
->div
->row
[div
][1],
1122 ctx
->normalize_gcd
);
1127 /* Exploit the equalities in "eq" to simplify the expressions of
1128 * the integer divisions in "ls".
1129 * The integer divisions in "ls" are assumed to appear as regular
1130 * dimensions in "eq".
1132 __isl_give isl_local_space
*isl_local_space_substitute_equalities(
1133 __isl_take isl_local_space
*ls
, __isl_take isl_basic_set
*eq
)
1136 isl_size total
, dim
;
1142 total
= isl_space_dim(eq
->dim
, isl_dim_all
);
1143 dim
= isl_local_space_dim(ls
, isl_dim_all
);
1144 if (dim
< 0 || total
< 0)
1147 isl_die(isl_local_space_get_ctx(ls
), isl_error_invalid
,
1148 "spaces don't match", goto error
);
1151 for (i
= 0; i
< eq
->n_eq
; ++i
) {
1152 j
= isl_seq_last_non_zero(eq
->eq
[i
], total
+ n_div
);
1153 if (j
< 0 || j
== 0 || j
>= total
)
1156 for (k
= 0; k
< ls
->div
->n_row
; ++k
) {
1157 if (isl_int_is_zero(ls
->div
->row
[k
][1 + j
]))
1159 ls
= isl_local_space_cow(ls
);
1162 ls
->div
= isl_mat_cow(ls
->div
);
1165 isl_seq_elim(ls
->div
->row
[k
] + 1, eq
->eq
[i
], j
, total
,
1166 &ls
->div
->row
[k
][0]);
1167 ls
= normalize_div(ls
, k
);
1173 isl_basic_set_free(eq
);
1176 isl_basic_set_free(eq
);
1177 isl_local_space_free(ls
);
1181 /* Plug in the affine expressions "subs" of length "subs_len" (including
1182 * the denominator and the constant term) into the variable at position "pos"
1183 * of the "n" div expressions starting at "first".
1185 * Let i be the dimension to replace and let "subs" be of the form
1189 * Any integer division starting at "first" with a non-zero coefficient for i,
1191 * floor((a i + g)/m)
1195 * floor((a f + d g)/(m d))
1197 __isl_give isl_local_space
*isl_local_space_substitute_seq(
1198 __isl_take isl_local_space
*ls
,
1199 enum isl_dim_type type
, unsigned pos
, isl_int
*subs
, int subs_len
,
1207 ls
= isl_local_space_cow(ls
);
1210 ls
->div
= isl_mat_cow(ls
->div
);
1212 return isl_local_space_free(ls
);
1214 if (first
+ n
> ls
->div
->n_row
)
1215 isl_die(isl_local_space_get_ctx(ls
), isl_error_invalid
,
1216 "index out of bounds", return isl_local_space_free(ls
));
1218 pos
+= isl_local_space_offset(ls
, type
);
1221 for (i
= first
; i
< first
+ n
; ++i
) {
1222 if (isl_int_is_zero(ls
->div
->row
[i
][1 + pos
]))
1224 isl_seq_substitute(ls
->div
->row
[i
], pos
, subs
,
1225 ls
->div
->n_col
, subs_len
, v
);
1226 ls
= normalize_div(ls
, i
);
1235 /* Plug in "subs" for dimension "type", "pos" in the integer divisions
1238 * Let i be the dimension to replace and let "subs" be of the form
1242 * Any integer division with a non-zero coefficient for i,
1244 * floor((a i + g)/m)
1248 * floor((a f + d g)/(m d))
1250 __isl_give isl_local_space
*isl_local_space_substitute(
1251 __isl_take isl_local_space
*ls
,
1252 enum isl_dim_type type
, unsigned pos
, __isl_keep isl_aff
*subs
)
1256 ls
= isl_local_space_cow(ls
);
1258 return isl_local_space_free(ls
);
1260 if (!isl_space_is_equal(ls
->dim
, subs
->ls
->dim
))
1261 isl_die(isl_local_space_get_ctx(ls
), isl_error_invalid
,
1262 "spaces don't match", return isl_local_space_free(ls
));
1263 n_div
= isl_local_space_dim(subs
->ls
, isl_dim_div
);
1265 return isl_local_space_free(ls
);
1267 isl_die(isl_local_space_get_ctx(ls
), isl_error_unsupported
,
1268 "cannot handle divs yet",
1269 return isl_local_space_free(ls
));
1271 return isl_local_space_substitute_seq(ls
, type
, pos
, subs
->v
->el
,
1272 subs
->v
->size
, 0, ls
->div
->n_row
);
1275 isl_bool
isl_local_space_is_named_or_nested(__isl_keep isl_local_space
*ls
,
1276 enum isl_dim_type type
)
1279 return isl_bool_error
;
1280 return isl_space_is_named_or_nested(ls
->dim
, type
);
1283 __isl_give isl_local_space
*isl_local_space_drop_dims(
1284 __isl_take isl_local_space
*ls
,
1285 enum isl_dim_type type
, unsigned first
, unsigned n
)
1289 if (n
== 0 && !isl_local_space_is_named_or_nested(ls
, type
))
1292 if (isl_local_space_check_range(ls
, type
, first
, n
) < 0)
1293 return isl_local_space_free(ls
);
1295 ls
= isl_local_space_cow(ls
);
1299 if (type
== isl_dim_div
) {
1300 ls
->div
= isl_mat_drop_rows(ls
->div
, first
, n
);
1302 ls
->dim
= isl_space_drop_dims(ls
->dim
, type
, first
, n
);
1304 return isl_local_space_free(ls
);
1307 first
+= 1 + isl_local_space_offset(ls
, type
);
1308 ls
->div
= isl_mat_drop_cols(ls
->div
, first
, n
);
1310 return isl_local_space_free(ls
);
1315 __isl_give isl_local_space
*isl_local_space_insert_dims(
1316 __isl_take isl_local_space
*ls
,
1317 enum isl_dim_type type
, unsigned first
, unsigned n
)
1321 if (n
== 0 && !isl_local_space_is_named_or_nested(ls
, type
))
1324 if (isl_local_space_check_range(ls
, type
, first
, 0) < 0)
1325 return isl_local_space_free(ls
);
1327 ls
= isl_local_space_cow(ls
);
1331 if (type
== isl_dim_div
) {
1332 ls
->div
= isl_mat_insert_zero_rows(ls
->div
, first
, n
);
1334 ls
->dim
= isl_space_insert_dims(ls
->dim
, type
, first
, n
);
1336 return isl_local_space_free(ls
);
1339 first
+= 1 + isl_local_space_offset(ls
, type
);
1340 ls
->div
= isl_mat_insert_zero_cols(ls
->div
, first
, n
);
1342 return isl_local_space_free(ls
);
1347 /* Does the linear part of "constraint" correspond to
1348 * integer division "div" in "ls"?
1350 * That is, given div = floor((c + f)/m), is the constraint of the form
1352 * f - m d + c' >= 0 [sign = 1]
1354 * -f + m d + c'' >= 0 [sign = -1]
1356 * If so, set *sign to the corresponding value.
1358 static isl_bool
is_linear_div_constraint(__isl_keep isl_local_space
*ls
,
1359 isl_int
*constraint
, unsigned div
, int *sign
)
1364 unknown
= isl_local_space_div_is_marked_unknown(ls
, div
);
1366 return isl_bool_error
;
1368 return isl_bool_false
;
1370 pos
= isl_local_space_offset(ls
, isl_dim_div
) + div
;
1372 if (isl_int_eq(constraint
[pos
], ls
->div
->row
[div
][0])) {
1374 if (!isl_seq_is_neg(constraint
+ 1,
1375 ls
->div
->row
[div
] + 2, pos
- 1))
1376 return isl_bool_false
;
1377 } else if (isl_int_abs_eq(constraint
[pos
], ls
->div
->row
[div
][0])) {
1379 if (!isl_seq_eq(constraint
+ 1, ls
->div
->row
[div
] + 2, pos
- 1))
1380 return isl_bool_false
;
1382 return isl_bool_false
;
1384 if (isl_seq_first_non_zero(constraint
+ pos
+ 1,
1385 ls
->div
->n_row
- div
- 1) != -1)
1386 return isl_bool_false
;
1387 return isl_bool_true
;
1390 /* Check if the constraints pointed to by "constraint" is a div
1391 * constraint corresponding to div "div" in "ls".
1393 * That is, if div = floor(f/m), then check if the constraint is
1397 * -(f-(m-1)) + m d >= 0
1399 * First check if the linear part is of the right form and
1400 * then check the constant term.
1402 isl_bool
isl_local_space_is_div_constraint(__isl_keep isl_local_space
*ls
,
1403 isl_int
*constraint
, unsigned div
)
1408 linear
= is_linear_div_constraint(ls
, constraint
, div
, &sign
);
1409 if (linear
< 0 || !linear
)
1414 isl_int_sub(ls
->div
->row
[div
][1],
1415 ls
->div
->row
[div
][1], ls
->div
->row
[div
][0]);
1416 isl_int_add_ui(ls
->div
->row
[div
][1], ls
->div
->row
[div
][1], 1);
1417 neg
= isl_seq_is_neg(constraint
, ls
->div
->row
[div
] + 1, 1);
1418 isl_int_sub_ui(ls
->div
->row
[div
][1], ls
->div
->row
[div
][1], 1);
1419 isl_int_add(ls
->div
->row
[div
][1],
1420 ls
->div
->row
[div
][1], ls
->div
->row
[div
][0]);
1422 return isl_bool_false
;
1424 if (!isl_int_eq(constraint
[0], ls
->div
->row
[div
][1]))
1425 return isl_bool_false
;
1428 return isl_bool_true
;
1431 /* Is the constraint pointed to by "constraint" one
1432 * of an equality that corresponds to integer division "div" in "ls"?
1434 * That is, given an integer division of the form
1436 * a = floor((f + c)/m)
1438 * is the equality of the form
1442 * Note that the constant term is not checked explicitly, but given
1443 * that this is a valid equality constraint, the constant c' necessarily
1444 * has a value close to -c.
1446 isl_bool
isl_local_space_is_div_equality(__isl_keep isl_local_space
*ls
,
1447 isl_int
*constraint
, unsigned div
)
1452 linear
= is_linear_div_constraint(ls
, constraint
, div
, &sign
);
1453 if (linear
< 0 || !linear
)
1456 return isl_bool_ok(sign
< 0);
1460 * Set active[i] to 1 if the dimension at position i is involved
1461 * in the linear expression l.
1463 int *isl_local_space_get_active(__isl_keep isl_local_space
*ls
, isl_int
*l
)
1471 ctx
= isl_local_space_get_ctx(ls
);
1472 total
= isl_local_space_dim(ls
, isl_dim_all
);
1475 active
= isl_calloc_array(ctx
, int, total
);
1476 if (total
&& !active
)
1479 for (i
= 0; i
< total
; ++i
)
1480 active
[i
] = !isl_int_is_zero(l
[i
]);
1482 offset
= isl_local_space_offset(ls
, isl_dim_div
) - 1;
1483 for (i
= ls
->div
->n_row
- 1; i
>= 0; --i
) {
1484 if (!active
[offset
+ i
])
1486 for (j
= 0; j
< total
; ++j
)
1487 active
[j
] |= !isl_int_is_zero(ls
->div
->row
[i
][2 + j
]);
1493 /* Given a local space "ls" of a set, create a local space
1494 * for the lift of the set. In particular, the result
1495 * is of the form [dim -> local[..]], with ls->div->n_row variables in the
1496 * range of the wrapped map.
1498 __isl_give isl_local_space
*isl_local_space_lift(
1499 __isl_take isl_local_space
*ls
)
1501 ls
= isl_local_space_cow(ls
);
1505 ls
->dim
= isl_space_lift(ls
->dim
, ls
->div
->n_row
);
1506 ls
->div
= isl_mat_drop_rows(ls
->div
, 0, ls
->div
->n_row
);
1507 if (!ls
->dim
|| !ls
->div
)
1508 return isl_local_space_free(ls
);
1513 /* Construct a basic map that maps a set living in local space "ls"
1514 * to the corresponding lifted local space.
1516 __isl_give isl_basic_map
*isl_local_space_lifting(
1517 __isl_take isl_local_space
*ls
)
1519 isl_basic_map
*lifting
;
1520 isl_basic_set
*bset
;
1524 if (!isl_local_space_is_set(ls
))
1525 isl_die(isl_local_space_get_ctx(ls
), isl_error_invalid
,
1526 "lifting only defined on set spaces", goto error
);
1528 bset
= isl_basic_set_from_local_space(ls
);
1529 lifting
= isl_basic_set_unwrap(isl_basic_set_lift(bset
));
1530 lifting
= isl_basic_map_domain_map(lifting
);
1531 lifting
= isl_basic_map_reverse(lifting
);
1535 isl_local_space_free(ls
);
1539 /* Compute the preimage of "ls" under the function represented by "ma".
1540 * In other words, plug in "ma" in "ls". The result is a local space
1541 * that is part of the domain space of "ma".
1543 * If the divs in "ls" are represented as
1545 * floor((a_i(p) + b_i x + c_i(divs))/n_i)
1547 * and ma is represented by
1549 * x = D(p) + F(y) + G(divs')
1551 * then the resulting divs are
1553 * floor((a_i(p) + b_i D(p) + b_i F(y) + B_i G(divs') + c_i(divs))/n_i)
1555 * We first copy over the divs from "ma" and then
1556 * we add the modified divs from "ls".
1558 __isl_give isl_local_space
*isl_local_space_preimage_multi_aff(
1559 __isl_take isl_local_space
*ls
, __isl_take isl_multi_aff
*ma
)
1563 isl_local_space
*res
= NULL
;
1564 isl_size n_div_ls
, n_div_ma
;
1565 isl_int f
, c1
, c2
, g
;
1567 ma
= isl_multi_aff_align_divs(ma
);
1570 if (!isl_space_is_range_internal(ls
->dim
, ma
->space
))
1571 isl_die(isl_local_space_get_ctx(ls
), isl_error_invalid
,
1572 "spaces don't match", goto error
);
1574 n_div_ls
= isl_local_space_dim(ls
, isl_dim_div
);
1575 n_div_ma
= ma
->n
? isl_aff_dim(ma
->u
.p
[0], isl_dim_div
) : 0;
1576 if (n_div_ls
< 0 || n_div_ma
< 0)
1579 space
= isl_space_domain(isl_multi_aff_get_space(ma
));
1580 res
= isl_local_space_alloc(space
, n_div_ma
+ n_div_ls
);
1585 isl_mat_free(res
->div
);
1586 res
->div
= isl_mat_copy(ma
->u
.p
[0]->ls
->div
);
1587 res
->div
= isl_mat_add_zero_cols(res
->div
, n_div_ls
);
1588 res
->div
= isl_mat_add_rows(res
->div
, n_div_ls
);
1598 for (i
= 0; i
< ls
->div
->n_row
; ++i
) {
1599 if (isl_int_is_zero(ls
->div
->row
[i
][0])) {
1600 isl_int_set_si(res
->div
->row
[n_div_ma
+ i
][0], 0);
1603 if (isl_seq_preimage(res
->div
->row
[n_div_ma
+ i
],
1605 ma
, 0, 0, n_div_ma
, n_div_ls
, f
, c1
, c2
, g
, 1) < 0)
1606 res
= isl_local_space_free(res
);
1607 res
= normalize_div(res
, n_div_ma
+ i
);
1617 isl_local_space_free(ls
);
1618 isl_multi_aff_free(ma
);
1621 isl_local_space_free(ls
);
1622 isl_multi_aff_free(ma
);
1623 isl_local_space_free(res
);
1627 /* Move the "n" dimensions of "src_type" starting at "src_pos" of "ls"
1628 * to dimensions of "dst_type" at "dst_pos".
1630 * Moving to/from local dimensions is not allowed.
1631 * We currently assume that the dimension type changes.
1633 __isl_give isl_local_space
*isl_local_space_move_dims(
1634 __isl_take isl_local_space
*ls
,
1635 enum isl_dim_type dst_type
, unsigned dst_pos
,
1636 enum isl_dim_type src_type
, unsigned src_pos
, unsigned n
)
1640 isl_size v_src
, v_dst
;
1647 !isl_local_space_is_named_or_nested(ls
, src_type
) &&
1648 !isl_local_space_is_named_or_nested(ls
, dst_type
))
1651 if (isl_local_space_check_range(ls
, src_type
, src_pos
, n
) < 0)
1652 return isl_local_space_free(ls
);
1653 if (isl_local_space_check_range(ls
, dst_type
, dst_pos
, 0) < 0)
1654 return isl_local_space_free(ls
);
1655 if (src_type
== isl_dim_div
)
1656 isl_die(isl_local_space_get_ctx(ls
), isl_error_invalid
,
1657 "cannot move divs", return isl_local_space_free(ls
));
1658 if (dst_type
== isl_dim_div
)
1659 isl_die(isl_local_space_get_ctx(ls
), isl_error_invalid
,
1660 "cannot move to divs", return isl_local_space_free(ls
));
1661 if (dst_type
== src_type
&& dst_pos
== src_pos
)
1663 if (dst_type
== src_type
)
1664 isl_die(isl_local_space_get_ctx(ls
), isl_error_unsupported
,
1665 "moving dims within the same type not supported",
1666 return isl_local_space_free(ls
));
1668 v_src
= isl_local_space_var_offset(ls
, src_type
);
1669 v_dst
= isl_local_space_var_offset(ls
, dst_type
);
1670 if (v_src
< 0 || v_dst
< 0)
1671 return isl_local_space_free(ls
);
1672 g_src_pos
= v_src
+ src_pos
;
1673 g_dst_pos
= v_dst
+ dst_pos
;
1674 if (dst_type
> src_type
)
1677 local
= isl_local_space_take_local(ls
);
1678 local
= isl_local_move_vars(local
, g_dst_pos
, g_src_pos
, n
);
1679 ls
= isl_local_space_restore_local(ls
, local
);
1681 space
= isl_local_space_take_space(ls
);
1682 space
= isl_space_move_dims(space
, dst_type
, dst_pos
,
1683 src_type
, src_pos
, n
);
1684 ls
= isl_local_space_restore_space(ls
, space
);
1689 /* Given a local space (A -> B), return the corresponding local space
1692 __isl_give isl_local_space
*isl_local_space_wrapped_reverse(
1693 __isl_take isl_local_space
*ls
)
1697 isl_size n_in
, n_out
;
1700 space
= isl_local_space_peek_space(ls
);
1701 offset
= isl_space_offset(space
, isl_dim_set
);
1702 n_in
= isl_space_wrapped_dim(space
, isl_dim_set
, isl_dim_in
);
1703 n_out
= isl_space_wrapped_dim(space
, isl_dim_set
, isl_dim_out
);
1704 if (n_in
< 0 || n_out
< 0)
1705 return isl_local_space_free(ls
);
1707 space
= isl_local_space_take_space(ls
);
1708 space
= isl_space_wrapped_reverse(space
);
1709 ls
= isl_local_space_restore_space(ls
, space
);
1711 local
= isl_local_space_take_local(ls
);
1712 local
= isl_local_move_vars(local
, offset
, offset
+ n_in
, n_out
);
1713 ls
= isl_local_space_restore_local(ls
, local
);
1718 /* Remove any internal structure of the domain of "ls".
1719 * If there is any such internal structure in the input,
1720 * then the name of the corresponding space is also removed.
1722 __isl_give isl_local_space
*isl_local_space_flatten_domain(
1723 __isl_take isl_local_space
*ls
)
1728 if (!ls
->dim
->nested
[0])
1731 ls
= isl_local_space_cow(ls
);
1735 ls
->dim
= isl_space_flatten_domain(ls
->dim
);
1737 return isl_local_space_free(ls
);
1742 /* Remove any internal structure of the range of "ls".
1743 * If there is any such internal structure in the input,
1744 * then the name of the corresponding space is also removed.
1746 __isl_give isl_local_space
*isl_local_space_flatten_range(
1747 __isl_take isl_local_space
*ls
)
1752 if (!ls
->dim
->nested
[1])
1755 ls
= isl_local_space_cow(ls
);
1759 ls
->dim
= isl_space_flatten_range(ls
->dim
);
1761 return isl_local_space_free(ls
);
1766 /* Given the local space "ls" of a map, return the local space of a set
1767 * that lives in a space that wraps the space of "ls" and that has
1770 __isl_give isl_local_space
*isl_local_space_wrap(__isl_take isl_local_space
*ls
)
1772 ls
= isl_local_space_cow(ls
);
1776 ls
->dim
= isl_space_wrap(ls
->dim
);
1778 return isl_local_space_free(ls
);
1783 /* Lift the point "pnt", living in the (set) space of "ls"
1784 * to live in a space with extra coordinates corresponding
1785 * to the local variables of "ls".
1787 __isl_give isl_point
*isl_local_space_lift_point(__isl_take isl_local_space
*ls
,
1788 __isl_take isl_point
*pnt
)
1795 if (isl_local_space_check_has_space(ls
, isl_point_peek_space(pnt
)) < 0)
1798 local
= isl_local_space_peek_local(ls
);
1799 n_local
= isl_local_space_dim(ls
, isl_dim_div
);
1803 space
= isl_point_take_space(pnt
);
1804 vec
= isl_point_take_vec(pnt
);
1806 space
= isl_space_lift(space
, n_local
);
1807 vec
= isl_local_extend_point_vec(local
, vec
);
1809 pnt
= isl_point_restore_vec(pnt
, vec
);
1810 pnt
= isl_point_restore_space(pnt
, space
);
1812 isl_local_space_free(ls
);
1816 isl_local_space_free(ls
);
1817 isl_point_free(pnt
);