-
Notifications
You must be signed in to change notification settings - Fork 0
/
isl_map.c
12925 lines (11118 loc) · 318 KB
/
isl_map.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2008-2009 Katholieke Universiteit Leuven
* Copyright 2010 INRIA Saclay
* Copyright 2012-2014 Ecole Normale Superieure
* Copyright 2014 INRIA Rocquencourt
*
* Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege, K.U.Leuven, Departement
* Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
* and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
* ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
* and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
* and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
* B.P. 105 - 78153 Le Chesnay, France
*/
#include <string.h>
#include <isl_ctx_private.h>
#include <isl_map_private.h>
#include <isl_blk.h>
#include "isl_space_private.h"
#include "isl_equalities.h"
#include <isl_lp_private.h>
#include <isl_seq.h>
#include <isl/set.h>
#include <isl/map.h>
#include <isl_reordering.h>
#include "isl_sample.h"
#include <isl_sort.h>
#include "isl_tab.h"
#include <isl/vec.h>
#include <isl_mat_private.h>
#include <isl_vec_private.h>
#include <isl_dim_map.h>
#include <isl_local_space_private.h>
#include <isl_aff_private.h>
#include <isl_options_private.h>
#include <isl_morph.h>
#include <isl_val_private.h>
#include <isl/deprecated/map_int.h>
#include <isl/deprecated/set_int.h>
static unsigned n(__isl_keep isl_space *dim, enum isl_dim_type type)
{
switch (type) {
case isl_dim_param: return dim->nparam;
case isl_dim_in: return dim->n_in;
case isl_dim_out: return dim->n_out;
case isl_dim_all: return dim->nparam + dim->n_in + dim->n_out;
default: return 0;
}
}
static unsigned pos(__isl_keep isl_space *dim, enum isl_dim_type type)
{
switch (type) {
case isl_dim_param: return 1;
case isl_dim_in: return 1 + dim->nparam;
case isl_dim_out: return 1 + dim->nparam + dim->n_in;
default: return 0;
}
}
unsigned isl_basic_map_dim(__isl_keep isl_basic_map *bmap,
enum isl_dim_type type)
{
if (!bmap)
return 0;
switch (type) {
case isl_dim_cst: return 1;
case isl_dim_param:
case isl_dim_in:
case isl_dim_out: return isl_space_dim(bmap->dim, type);
case isl_dim_div: return bmap->n_div;
case isl_dim_all: return isl_basic_map_total_dim(bmap);
default: return 0;
}
}
unsigned isl_map_dim(__isl_keep isl_map *map, enum isl_dim_type type)
{
return map ? n(map->dim, type) : 0;
}
unsigned isl_set_dim(__isl_keep isl_set *set, enum isl_dim_type type)
{
return set ? n(set->dim, type) : 0;
}
unsigned isl_basic_map_offset(struct isl_basic_map *bmap,
enum isl_dim_type type)
{
isl_space *dim = bmap->dim;
switch (type) {
case isl_dim_cst: return 0;
case isl_dim_param: return 1;
case isl_dim_in: return 1 + dim->nparam;
case isl_dim_out: return 1 + dim->nparam + dim->n_in;
case isl_dim_div: return 1 + dim->nparam + dim->n_in + dim->n_out;
default: return 0;
}
}
unsigned isl_basic_set_offset(struct isl_basic_set *bset,
enum isl_dim_type type)
{
return isl_basic_map_offset(bset, type);
}
static unsigned map_offset(struct isl_map *map, enum isl_dim_type type)
{
return pos(map->dim, type);
}
unsigned isl_basic_set_dim(__isl_keep isl_basic_set *bset,
enum isl_dim_type type)
{
return isl_basic_map_dim(bset, type);
}
unsigned isl_basic_set_n_dim(__isl_keep isl_basic_set *bset)
{
return isl_basic_set_dim(bset, isl_dim_set);
}
unsigned isl_basic_set_n_param(__isl_keep isl_basic_set *bset)
{
return isl_basic_set_dim(bset, isl_dim_param);
}
unsigned isl_basic_set_total_dim(const struct isl_basic_set *bset)
{
if (!bset)
return 0;
return isl_space_dim(bset->dim, isl_dim_all) + bset->n_div;
}
unsigned isl_set_n_dim(__isl_keep isl_set *set)
{
return isl_set_dim(set, isl_dim_set);
}
unsigned isl_set_n_param(__isl_keep isl_set *set)
{
return isl_set_dim(set, isl_dim_param);
}
unsigned isl_basic_map_n_in(const struct isl_basic_map *bmap)
{
return bmap ? bmap->dim->n_in : 0;
}
unsigned isl_basic_map_n_out(const struct isl_basic_map *bmap)
{
return bmap ? bmap->dim->n_out : 0;
}
unsigned isl_basic_map_n_param(const struct isl_basic_map *bmap)
{
return bmap ? bmap->dim->nparam : 0;
}
unsigned isl_basic_map_n_div(const struct isl_basic_map *bmap)
{
return bmap ? bmap->n_div : 0;
}
unsigned isl_basic_map_total_dim(const struct isl_basic_map *bmap)
{
return bmap ? isl_space_dim(bmap->dim, isl_dim_all) + bmap->n_div : 0;
}
unsigned isl_map_n_in(const struct isl_map *map)
{
return map ? map->dim->n_in : 0;
}
unsigned isl_map_n_out(const struct isl_map *map)
{
return map ? map->dim->n_out : 0;
}
unsigned isl_map_n_param(const struct isl_map *map)
{
return map ? map->dim->nparam : 0;
}
int isl_map_compatible_domain(struct isl_map *map, struct isl_set *set)
{
int m;
if (!map || !set)
return -1;
m = isl_space_match(map->dim, isl_dim_param, set->dim, isl_dim_param);
if (m < 0 || !m)
return m;
return isl_space_tuple_is_equal(map->dim, isl_dim_in,
set->dim, isl_dim_set);
}
int isl_basic_map_compatible_domain(struct isl_basic_map *bmap,
struct isl_basic_set *bset)
{
int m;
if (!bmap || !bset)
return -1;
m = isl_space_match(bmap->dim, isl_dim_param, bset->dim, isl_dim_param);
if (m < 0 || !m)
return m;
return isl_space_tuple_is_equal(bmap->dim, isl_dim_in,
bset->dim, isl_dim_set);
}
int isl_map_compatible_range(__isl_keep isl_map *map, __isl_keep isl_set *set)
{
int m;
if (!map || !set)
return -1;
m = isl_space_match(map->dim, isl_dim_param, set->dim, isl_dim_param);
if (m < 0 || !m)
return m;
return isl_space_tuple_is_equal(map->dim, isl_dim_out,
set->dim, isl_dim_set);
}
int isl_basic_map_compatible_range(struct isl_basic_map *bmap,
struct isl_basic_set *bset)
{
int m;
if (!bmap || !bset)
return -1;
m = isl_space_match(bmap->dim, isl_dim_param, bset->dim, isl_dim_param);
if (m < 0 || !m)
return m;
return isl_space_tuple_is_equal(bmap->dim, isl_dim_out,
bset->dim, isl_dim_set);
}
isl_ctx *isl_basic_map_get_ctx(__isl_keep isl_basic_map *bmap)
{
return bmap ? bmap->ctx : NULL;
}
isl_ctx *isl_basic_set_get_ctx(__isl_keep isl_basic_set *bset)
{
return bset ? bset->ctx : NULL;
}
isl_ctx *isl_map_get_ctx(__isl_keep isl_map *map)
{
return map ? map->ctx : NULL;
}
isl_ctx *isl_set_get_ctx(__isl_keep isl_set *set)
{
return set ? set->ctx : NULL;
}
__isl_give isl_space *isl_basic_map_get_space(__isl_keep isl_basic_map *bmap)
{
if (!bmap)
return NULL;
return isl_space_copy(bmap->dim);
}
__isl_give isl_space *isl_basic_set_get_space(__isl_keep isl_basic_set *bset)
{
if (!bset)
return NULL;
return isl_space_copy(bset->dim);
}
/* Extract the divs in "bmap" as a matrix.
*/
__isl_give isl_mat *isl_basic_map_get_divs(__isl_keep isl_basic_map *bmap)
{
int i;
isl_ctx *ctx;
isl_mat *div;
unsigned total;
unsigned cols;
if (!bmap)
return NULL;
ctx = isl_basic_map_get_ctx(bmap);
total = isl_space_dim(bmap->dim, isl_dim_all);
cols = 1 + 1 + total + bmap->n_div;
div = isl_mat_alloc(ctx, bmap->n_div, cols);
if (!div)
return NULL;
for (i = 0; i < bmap->n_div; ++i)
isl_seq_cpy(div->row[i], bmap->div[i], cols);
return div;
}
/* Extract the divs in "bset" as a matrix.
*/
__isl_give isl_mat *isl_basic_set_get_divs(__isl_keep isl_basic_set *bset)
{
return isl_basic_map_get_divs(bset);
}
__isl_give isl_local_space *isl_basic_map_get_local_space(
__isl_keep isl_basic_map *bmap)
{
isl_mat *div;
if (!bmap)
return NULL;
div = isl_basic_map_get_divs(bmap);
return isl_local_space_alloc_div(isl_space_copy(bmap->dim), div);
}
__isl_give isl_local_space *isl_basic_set_get_local_space(
__isl_keep isl_basic_set *bset)
{
return isl_basic_map_get_local_space(bset);
}
__isl_give isl_basic_map *isl_basic_map_from_local_space(
__isl_take isl_local_space *ls)
{
int i;
int n_div;
isl_basic_map *bmap;
if (!ls)
return NULL;
n_div = isl_local_space_dim(ls, isl_dim_div);
bmap = isl_basic_map_alloc_space(isl_local_space_get_space(ls),
n_div, 0, 2 * n_div);
for (i = 0; i < n_div; ++i)
if (isl_basic_map_alloc_div(bmap) < 0)
goto error;
for (i = 0; i < n_div; ++i) {
isl_seq_cpy(bmap->div[i], ls->div->row[i], ls->div->n_col);
if (isl_basic_map_add_div_constraints(bmap, i) < 0)
goto error;
}
isl_local_space_free(ls);
return bmap;
error:
isl_local_space_free(ls);
isl_basic_map_free(bmap);
return NULL;
}
__isl_give isl_basic_set *isl_basic_set_from_local_space(
__isl_take isl_local_space *ls)
{
return isl_basic_map_from_local_space(ls);
}
__isl_give isl_space *isl_map_get_space(__isl_keep isl_map *map)
{
if (!map)
return NULL;
return isl_space_copy(map->dim);
}
__isl_give isl_space *isl_set_get_space(__isl_keep isl_set *set)
{
if (!set)
return NULL;
return isl_space_copy(set->dim);
}
__isl_give isl_basic_map *isl_basic_map_set_tuple_name(
__isl_take isl_basic_map *bmap, enum isl_dim_type type, const char *s)
{
bmap = isl_basic_map_cow(bmap);
if (!bmap)
return NULL;
bmap->dim = isl_space_set_tuple_name(bmap->dim, type, s);
if (!bmap->dim)
goto error;
bmap = isl_basic_map_finalize(bmap);
return bmap;
error:
isl_basic_map_free(bmap);
return NULL;
}
__isl_give isl_basic_set *isl_basic_set_set_tuple_name(
__isl_take isl_basic_set *bset, const char *s)
{
return isl_basic_map_set_tuple_name(bset, isl_dim_set, s);
}
const char *isl_basic_map_get_tuple_name(__isl_keep isl_basic_map *bmap,
enum isl_dim_type type)
{
return bmap ? isl_space_get_tuple_name(bmap->dim, type) : NULL;
}
__isl_give isl_map *isl_map_set_tuple_name(__isl_take isl_map *map,
enum isl_dim_type type, const char *s)
{
int i;
map = isl_map_cow(map);
if (!map)
return NULL;
map->dim = isl_space_set_tuple_name(map->dim, type, s);
if (!map->dim)
goto error;
for (i = 0; i < map->n; ++i) {
map->p[i] = isl_basic_map_set_tuple_name(map->p[i], type, s);
if (!map->p[i])
goto error;
}
return map;
error:
isl_map_free(map);
return NULL;
}
/* Replace the identifier of the tuple of type "type" by "id".
*/
__isl_give isl_basic_map *isl_basic_map_set_tuple_id(
__isl_take isl_basic_map *bmap,
enum isl_dim_type type, __isl_take isl_id *id)
{
bmap = isl_basic_map_cow(bmap);
if (!bmap)
goto error;
bmap->dim = isl_space_set_tuple_id(bmap->dim, type, id);
if (!bmap->dim)
return isl_basic_map_free(bmap);
bmap = isl_basic_map_finalize(bmap);
return bmap;
error:
isl_id_free(id);
return NULL;
}
/* Replace the identifier of the tuple by "id".
*/
__isl_give isl_basic_set *isl_basic_set_set_tuple_id(
__isl_take isl_basic_set *bset, __isl_take isl_id *id)
{
return isl_basic_map_set_tuple_id(bset, isl_dim_set, id);
}
/* Does the input or output tuple have a name?
*/
int isl_map_has_tuple_name(__isl_keep isl_map *map, enum isl_dim_type type)
{
return map ? isl_space_has_tuple_name(map->dim, type) : -1;
}
const char *isl_map_get_tuple_name(__isl_keep isl_map *map,
enum isl_dim_type type)
{
return map ? isl_space_get_tuple_name(map->dim, type) : NULL;
}
__isl_give isl_set *isl_set_set_tuple_name(__isl_take isl_set *set,
const char *s)
{
return (isl_set *)isl_map_set_tuple_name((isl_map *)set, isl_dim_set, s);
}
__isl_give isl_map *isl_map_set_tuple_id(__isl_take isl_map *map,
enum isl_dim_type type, __isl_take isl_id *id)
{
map = isl_map_cow(map);
if (!map)
goto error;
map->dim = isl_space_set_tuple_id(map->dim, type, id);
return isl_map_reset_space(map, isl_space_copy(map->dim));
error:
isl_id_free(id);
return NULL;
}
__isl_give isl_set *isl_set_set_tuple_id(__isl_take isl_set *set,
__isl_take isl_id *id)
{
return isl_map_set_tuple_id(set, isl_dim_set, id);
}
__isl_give isl_map *isl_map_reset_tuple_id(__isl_take isl_map *map,
enum isl_dim_type type)
{
map = isl_map_cow(map);
if (!map)
return NULL;
map->dim = isl_space_reset_tuple_id(map->dim, type);
return isl_map_reset_space(map, isl_space_copy(map->dim));
}
__isl_give isl_set *isl_set_reset_tuple_id(__isl_take isl_set *set)
{
return isl_map_reset_tuple_id(set, isl_dim_set);
}
int isl_map_has_tuple_id(__isl_keep isl_map *map, enum isl_dim_type type)
{
return map ? isl_space_has_tuple_id(map->dim, type) : -1;
}
__isl_give isl_id *isl_map_get_tuple_id(__isl_keep isl_map *map,
enum isl_dim_type type)
{
return map ? isl_space_get_tuple_id(map->dim, type) : NULL;
}
int isl_set_has_tuple_id(__isl_keep isl_set *set)
{
return isl_map_has_tuple_id(set, isl_dim_set);
}
__isl_give isl_id *isl_set_get_tuple_id(__isl_keep isl_set *set)
{
return isl_map_get_tuple_id(set, isl_dim_set);
}
/* Does the set tuple have a name?
*/
int isl_set_has_tuple_name(__isl_keep isl_set *set)
{
return set ? isl_space_has_tuple_name(set->dim, isl_dim_set) : -1;
}
const char *isl_basic_set_get_tuple_name(__isl_keep isl_basic_set *bset)
{
return bset ? isl_space_get_tuple_name(bset->dim, isl_dim_set) : NULL;
}
const char *isl_set_get_tuple_name(__isl_keep isl_set *set)
{
return set ? isl_space_get_tuple_name(set->dim, isl_dim_set) : NULL;
}
const char *isl_basic_map_get_dim_name(__isl_keep isl_basic_map *bmap,
enum isl_dim_type type, unsigned pos)
{
return bmap ? isl_space_get_dim_name(bmap->dim, type, pos) : NULL;
}
const char *isl_basic_set_get_dim_name(__isl_keep isl_basic_set *bset,
enum isl_dim_type type, unsigned pos)
{
return bset ? isl_space_get_dim_name(bset->dim, type, pos) : NULL;
}
/* Does the given dimension have a name?
*/
int isl_map_has_dim_name(__isl_keep isl_map *map,
enum isl_dim_type type, unsigned pos)
{
return map ? isl_space_has_dim_name(map->dim, type, pos) : -1;
}
const char *isl_map_get_dim_name(__isl_keep isl_map *map,
enum isl_dim_type type, unsigned pos)
{
return map ? isl_space_get_dim_name(map->dim, type, pos) : NULL;
}
const char *isl_set_get_dim_name(__isl_keep isl_set *set,
enum isl_dim_type type, unsigned pos)
{
return set ? isl_space_get_dim_name(set->dim, type, pos) : NULL;
}
/* Does the given dimension have a name?
*/
int isl_set_has_dim_name(__isl_keep isl_set *set,
enum isl_dim_type type, unsigned pos)
{
return set ? isl_space_has_dim_name(set->dim, type, pos) : -1;
}
__isl_give isl_basic_map *isl_basic_map_set_dim_name(
__isl_take isl_basic_map *bmap,
enum isl_dim_type type, unsigned pos, const char *s)
{
bmap = isl_basic_map_cow(bmap);
if (!bmap)
return NULL;
bmap->dim = isl_space_set_dim_name(bmap->dim, type, pos, s);
if (!bmap->dim)
goto error;
return isl_basic_map_finalize(bmap);
error:
isl_basic_map_free(bmap);
return NULL;
}
__isl_give isl_map *isl_map_set_dim_name(__isl_take isl_map *map,
enum isl_dim_type type, unsigned pos, const char *s)
{
int i;
map = isl_map_cow(map);
if (!map)
return NULL;
map->dim = isl_space_set_dim_name(map->dim, type, pos, s);
if (!map->dim)
goto error;
for (i = 0; i < map->n; ++i) {
map->p[i] = isl_basic_map_set_dim_name(map->p[i], type, pos, s);
if (!map->p[i])
goto error;
}
return map;
error:
isl_map_free(map);
return NULL;
}
__isl_give isl_basic_set *isl_basic_set_set_dim_name(
__isl_take isl_basic_set *bset,
enum isl_dim_type type, unsigned pos, const char *s)
{
return (isl_basic_set *)isl_basic_map_set_dim_name(
(isl_basic_map *)bset, type, pos, s);
}
__isl_give isl_set *isl_set_set_dim_name(__isl_take isl_set *set,
enum isl_dim_type type, unsigned pos, const char *s)
{
return (isl_set *)isl_map_set_dim_name((isl_map *)set, type, pos, s);
}
int isl_basic_map_has_dim_id(__isl_keep isl_basic_map *bmap,
enum isl_dim_type type, unsigned pos)
{
return bmap ? isl_space_has_dim_id(bmap->dim, type, pos) : -1;
}
__isl_give isl_id *isl_basic_set_get_dim_id(__isl_keep isl_basic_set *bset,
enum isl_dim_type type, unsigned pos)
{
return bset ? isl_space_get_dim_id(bset->dim, type, pos) : NULL;
}
int isl_map_has_dim_id(__isl_keep isl_map *map,
enum isl_dim_type type, unsigned pos)
{
return map ? isl_space_has_dim_id(map->dim, type, pos) : -1;
}
__isl_give isl_id *isl_map_get_dim_id(__isl_keep isl_map *map,
enum isl_dim_type type, unsigned pos)
{
return map ? isl_space_get_dim_id(map->dim, type, pos) : NULL;
}
int isl_set_has_dim_id(__isl_keep isl_set *set,
enum isl_dim_type type, unsigned pos)
{
return isl_map_has_dim_id(set, type, pos);
}
__isl_give isl_id *isl_set_get_dim_id(__isl_keep isl_set *set,
enum isl_dim_type type, unsigned pos)
{
return isl_map_get_dim_id(set, type, pos);
}
__isl_give isl_map *isl_map_set_dim_id(__isl_take isl_map *map,
enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
{
map = isl_map_cow(map);
if (!map)
goto error;
map->dim = isl_space_set_dim_id(map->dim, type, pos, id);
return isl_map_reset_space(map, isl_space_copy(map->dim));
error:
isl_id_free(id);
return NULL;
}
__isl_give isl_set *isl_set_set_dim_id(__isl_take isl_set *set,
enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
{
return isl_map_set_dim_id(set, type, pos, id);
}
int isl_map_find_dim_by_id(__isl_keep isl_map *map, enum isl_dim_type type,
__isl_keep isl_id *id)
{
if (!map)
return -1;
return isl_space_find_dim_by_id(map->dim, type, id);
}
int isl_set_find_dim_by_id(__isl_keep isl_set *set, enum isl_dim_type type,
__isl_keep isl_id *id)
{
return isl_map_find_dim_by_id(set, type, id);
}
/* Return the position of the dimension of the given type and name
* in "bmap".
* Return -1 if no such dimension can be found.
*/
int isl_basic_map_find_dim_by_name(__isl_keep isl_basic_map *bmap,
enum isl_dim_type type, const char *name)
{
if (!bmap)
return -1;
return isl_space_find_dim_by_name(bmap->dim, type, name);
}
int isl_map_find_dim_by_name(__isl_keep isl_map *map, enum isl_dim_type type,
const char *name)
{
if (!map)
return -1;
return isl_space_find_dim_by_name(map->dim, type, name);
}
int isl_set_find_dim_by_name(__isl_keep isl_set *set, enum isl_dim_type type,
const char *name)
{
return isl_map_find_dim_by_name(set, type, name);
}
/* Reset the user pointer on all identifiers of parameters and tuples
* of the space of "map".
*/
__isl_give isl_map *isl_map_reset_user(__isl_take isl_map *map)
{
isl_space *space;
space = isl_map_get_space(map);
space = isl_space_reset_user(space);
map = isl_map_reset_space(map, space);
return map;
}
/* Reset the user pointer on all identifiers of parameters and tuples
* of the space of "set".
*/
__isl_give isl_set *isl_set_reset_user(__isl_take isl_set *set)
{
return isl_map_reset_user(set);
}
int isl_basic_map_is_rational(__isl_keep isl_basic_map *bmap)
{
if (!bmap)
return -1;
return ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL);
}
int isl_basic_set_is_rational(__isl_keep isl_basic_set *bset)
{
return isl_basic_map_is_rational(bset);
}
/* Does "bmap" contain any rational points?
*
* If "bmap" has an equality for each dimension, equating the dimension
* to an integer constant, then it has no rational points, even if it
* is marked as rational.
*/
int isl_basic_map_has_rational(__isl_keep isl_basic_map *bmap)
{
int has_rational = 1;
unsigned total;
if (!bmap)
return -1;
if (isl_basic_map_plain_is_empty(bmap))
return 0;
if (!isl_basic_map_is_rational(bmap))
return 0;
bmap = isl_basic_map_copy(bmap);
bmap = isl_basic_map_implicit_equalities(bmap);
if (!bmap)
return -1;
total = isl_basic_map_total_dim(bmap);
if (bmap->n_eq == total) {
int i, j;
for (i = 0; i < bmap->n_eq; ++i) {
j = isl_seq_first_non_zero(bmap->eq[i] + 1, total);
if (j < 0)
break;
if (!isl_int_is_one(bmap->eq[i][1 + j]) &&
!isl_int_is_negone(bmap->eq[i][1 + j]))
break;
j = isl_seq_first_non_zero(bmap->eq[i] + 1 + j + 1,
total - j - 1);
if (j >= 0)
break;
}
if (i == bmap->n_eq)
has_rational = 0;
}
isl_basic_map_free(bmap);
return has_rational;
}
/* Does "map" contain any rational points?
*/
int isl_map_has_rational(__isl_keep isl_map *map)
{
int i;
int has_rational;
if (!map)
return -1;
for (i = 0; i < map->n; ++i) {
has_rational = isl_basic_map_has_rational(map->p[i]);
if (has_rational < 0)
return -1;
if (has_rational)
return 1;
}
return 0;
}
/* Does "set" contain any rational points?
*/
int isl_set_has_rational(__isl_keep isl_set *set)
{
return isl_map_has_rational(set);
}
/* Is this basic set a parameter domain?
*/
int isl_basic_set_is_params(__isl_keep isl_basic_set *bset)
{
if (!bset)
return -1;
return isl_space_is_params(bset->dim);
}
/* Is this set a parameter domain?
*/
int isl_set_is_params(__isl_keep isl_set *set)
{
if (!set)
return -1;
return isl_space_is_params(set->dim);
}
/* Is this map actually a parameter domain?
* Users should never call this function. Outside of isl,
* a map can never be a parameter domain.
*/
int isl_map_is_params(__isl_keep isl_map *map)
{
if (!map)
return -1;
return isl_space_is_params(map->dim);
}
static struct isl_basic_map *basic_map_init(struct isl_ctx *ctx,
struct isl_basic_map *bmap, unsigned extra,
unsigned n_eq, unsigned n_ineq)
{
int i;
size_t row_size = 1 + isl_space_dim(bmap->dim, isl_dim_all) + extra;
bmap->ctx = ctx;
isl_ctx_ref(ctx);
bmap->block = isl_blk_alloc(ctx, (n_ineq + n_eq) * row_size);
if (isl_blk_is_error(bmap->block))
goto error;
bmap->ineq = isl_alloc_array(ctx, isl_int *, n_ineq + n_eq);
if ((n_ineq + n_eq) && !bmap->ineq)
goto error;
if (extra == 0) {
bmap->block2 = isl_blk_empty();
bmap->div = NULL;
} else {
bmap->block2 = isl_blk_alloc(ctx, extra * (1 + row_size));
if (isl_blk_is_error(bmap->block2))
goto error;
bmap->div = isl_alloc_array(ctx, isl_int *, extra);
if (!bmap->div)
goto error;
}
for (i = 0; i < n_ineq + n_eq; ++i)
bmap->ineq[i] = bmap->block.data + i * row_size;
for (i = 0; i < extra; ++i)
bmap->div[i] = bmap->block2.data + i * (1 + row_size);
bmap->ref = 1;
bmap->flags = 0;
bmap->c_size = n_eq + n_ineq;
bmap->eq = bmap->ineq + n_ineq;
bmap->extra = extra;
bmap->n_eq = 0;
bmap->n_ineq = 0;
bmap->n_div = 0;
bmap->sample = NULL;
return bmap;
error:
isl_basic_map_free(bmap);
return NULL;
}
struct isl_basic_set *isl_basic_set_alloc(struct isl_ctx *ctx,
unsigned nparam, unsigned dim, unsigned extra,
unsigned n_eq, unsigned n_ineq)
{
struct isl_basic_map *bmap;
isl_space *space;
space = isl_space_set_alloc(ctx, nparam, dim);
if (!space)
return NULL;
bmap = isl_basic_map_alloc_space(space, extra, n_eq, n_ineq);
return (struct isl_basic_set *)bmap;
}
struct isl_basic_set *isl_basic_set_alloc_space(__isl_take isl_space *dim,
unsigned extra, unsigned n_eq, unsigned n_ineq)
{
struct isl_basic_map *bmap;
if (!dim)
return NULL;
isl_assert(dim->ctx, dim->n_in == 0, goto error);
bmap = isl_basic_map_alloc_space(dim, extra, n_eq, n_ineq);
return (struct isl_basic_set *)bmap;
error:
isl_space_free(dim);
return NULL;
}
struct isl_basic_map *isl_basic_map_alloc_space(__isl_take isl_space *dim,
unsigned extra, unsigned n_eq, unsigned n_ineq)
{
struct isl_basic_map *bmap;
if (!dim)
return NULL;
bmap = isl_calloc_type(dim->ctx, struct isl_basic_map);
if (!bmap)
goto error;
bmap->dim = dim;
return basic_map_init(dim->ctx, bmap, extra, n_eq, n_ineq);
error:
isl_space_free(dim);
return NULL;
}
struct isl_basic_map *isl_basic_map_alloc(struct isl_ctx *ctx,
unsigned nparam, unsigned in, unsigned out, unsigned extra,
unsigned n_eq, unsigned n_ineq)
{
struct isl_basic_map *bmap;
isl_space *dim;
dim = isl_space_alloc(ctx, nparam, in, out);
if (!dim)
return NULL;
bmap = isl_basic_map_alloc_space(dim, extra, n_eq, n_ineq);
return bmap;
}
static void dup_constraints(
struct isl_basic_map *dst, struct isl_basic_map *src)
{
int i;
unsigned total = isl_basic_map_total_dim(src);
for (i = 0; i < src->n_eq; ++i) {
int j = isl_basic_map_alloc_equality(dst);
isl_seq_cpy(dst->eq[j], src->eq[i], 1+total);