~mmach/netext73/isl

« back to all changes in this revision

Viewing changes to isl_multi_templ.c

  • Committer: mmach
  • Date: 2020-11-29 19:49:17 UTC
  • Revision ID: netbit73@gmail.com-20201129194917-qo0ok1xcw924ou1l
0.23

Show diffs side-by-side

added added

removed removed

Lines of Context:
258
258
        return FN(MULTI(BASE),set_at)(multi, pos, el);
259
259
}
260
260
 
 
261
/* Return the base expressions of "multi" as a list.
 
262
 */
 
263
__isl_give LIST(EL) *FN(MULTI(BASE),get_list)(
 
264
        __isl_keep MULTI(BASE) *multi)
 
265
{
 
266
        isl_size n;
 
267
        int i;
 
268
        LIST(EL) *list;
 
269
 
 
270
        n = FN(MULTI(BASE),size)(multi);
 
271
        if (n < 0)
 
272
                return NULL;
 
273
        list = FN(LIST(EL),alloc)(FN(MULTI(BASE),get_ctx(multi)), n);
 
274
        for (i = 0; i < n; ++i) {
 
275
                EL *el = FN(MULTI(BASE),get_at)(multi, i);
 
276
                list = FN(LIST(EL),add)(list, el);
 
277
        }
 
278
 
 
279
        return list;
 
280
}
 
281
 
261
282
/* Reset the space of "multi".  This function is called from isl_pw_templ.c
262
283
 * and doesn't know if the space of an element object is represented
263
284
 * directly or through its domain.  It therefore passes along both,
499
520
        return multi;
500
521
}
501
522
 
502
 
/* Align the parameters of "multi1" and "multi2" (if needed) and call "fn".
503
 
 */
504
 
static __isl_give MULTI(BASE) *FN(MULTI(BASE),align_params_multi_multi_and)(
505
 
        __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2,
506
 
        __isl_give MULTI(BASE) *(*fn)(__isl_take MULTI(BASE) *multi1,
507
 
                __isl_take MULTI(BASE) *multi2))
508
 
{
509
 
        isl_ctx *ctx;
510
 
        isl_bool equal_params;
 
523
#undef TYPE
 
524
#define TYPE MULTI(BASE)
511
525
 
512
 
        if (!multi1 || !multi2)
513
 
                goto error;
514
 
        equal_params = isl_space_has_equal_params(multi1->space, multi2->space);
515
 
        if (equal_params < 0)
516
 
                goto error;
517
 
        if (equal_params)
518
 
                return fn(multi1, multi2);
519
 
        ctx = FN(MULTI(BASE),get_ctx)(multi1);
520
 
        if (!isl_space_has_named_params(multi1->space) ||
521
 
            !isl_space_has_named_params(multi2->space))
522
 
                isl_die(ctx, isl_error_invalid,
523
 
                        "unaligned unnamed parameters", goto error);
524
 
        multi1 = FN(MULTI(BASE),align_params)(multi1,
525
 
                                            FN(MULTI(BASE),get_space)(multi2));
526
 
        multi2 = FN(MULTI(BASE),align_params)(multi2,
527
 
                                            FN(MULTI(BASE),get_space)(multi1));
528
 
        return fn(multi1, multi2);
529
 
error:
530
 
        FN(MULTI(BASE),free)(multi1);
531
 
        FN(MULTI(BASE),free)(multi2);
532
 
        return NULL;
533
 
}
 
526
#include "isl_check_named_params_templ.c"
 
527
static
 
528
#include "isl_align_params_bin_templ.c"
534
529
 
535
530
/* Given two MULTI(BASE)s A -> B and C -> D,
536
531
 * construct a MULTI(BASE) (A * C) -> [B -> D].
537
532
 *
538
 
 * The parameters are assumed to have been aligned.
539
 
 *
540
533
 * If "multi1" and/or "multi2" has an explicit domain, then
541
534
 * intersect the domain of the result with these explicit domains.
542
535
 */
543
 
static __isl_give MULTI(BASE) *FN(MULTI(BASE),range_product_aligned)(
 
536
__isl_give MULTI(BASE) *FN(MULTI(BASE),range_product)(
544
537
        __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
545
538
{
546
539
        int i;
549
542
        isl_space *space;
550
543
        MULTI(BASE) *res;
551
544
 
 
545
        FN(MULTI(BASE),align_params_bin)(&multi1, &multi2);
552
546
        n1 = FN(MULTI(BASE),size)(multi1);
553
547
        n2 = FN(MULTI(BASE),size)(multi2);
554
548
        if (n1 < 0 || n2 < 0)
582
576
        return NULL;
583
577
}
584
578
 
585
 
/* Given two MULTI(BASE)s A -> B and C -> D,
586
 
 * construct a MULTI(BASE) (A * C) -> [B -> D].
587
 
 */
588
 
__isl_give MULTI(BASE) *FN(MULTI(BASE),range_product)(
589
 
        __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
590
 
{
591
 
        return FN(MULTI(BASE),align_params_multi_multi_and)(multi1, multi2,
592
 
                                        &FN(MULTI(BASE),range_product_aligned));
593
 
}
594
 
 
595
579
/* Is the range of "multi" a wrapped relation?
596
580
 */
597
581
isl_bool FN(MULTI(BASE),range_is_wrapping)(__isl_keep MULTI(BASE) *multi)
755
739
        return NULL;
756
740
}
757
741
 
758
 
/* Check that "multi1" and "multi2" live in the same space,
759
 
 * reporting an error if they do not.
760
 
 */
761
 
static isl_stat FN(MULTI(BASE),check_equal_space)(
762
 
        __isl_keep MULTI(BASE) *multi1, __isl_keep MULTI(BASE) *multi2)
763
 
{
764
 
        isl_bool equal;
765
 
 
766
 
        if (!multi1 || !multi2)
767
 
                return isl_stat_error;
768
 
 
769
 
        equal = isl_space_is_equal(multi1->space, multi2->space);
770
 
        if (equal < 0)
771
 
                return isl_stat_error;
772
 
        if (!equal)
773
 
                isl_die(FN(MULTI(BASE),get_ctx)(multi1), isl_error_invalid,
774
 
                        "spaces don't match", return isl_stat_error);
775
 
 
776
 
        return isl_stat_ok;
777
 
}
 
742
#undef TYPE
 
743
#define TYPE    MULTI(BASE)
 
744
 
 
745
static
 
746
#include "isl_type_has_equal_space_bin_templ.c"
 
747
static
 
748
#include "isl_type_check_equal_space_templ.c"
778
749
 
779
750
/* This function is currently only used from isl_aff.c
780
751
 */
795
766
{
796
767
        int i;
797
768
 
 
769
        FN(MULTI(BASE),align_params_bin)(&multi1, &multi2);
798
770
        multi1 = FN(MULTI(BASE),cow)(multi1);
799
771
        if (FN(MULTI(BASE),check_equal_space)(multi1, multi2) < 0)
800
772
                goto error;
844
816
        return isl_bool_false;
845
817
}
846
818
 
 
819
/* Only used on some multi-expressions.
 
820
 */
 
821
static isl_bool FN(MULTI(BASE),every)(__isl_keep MULTI(BASE) *multi,
 
822
        isl_bool (*test)(__isl_keep EL *)) __attribute__ ((unused));
 
823
 
 
824
/* Does "test" succeed on every base expression of "multi"?
 
825
 */
 
826
static isl_bool FN(MULTI(BASE),every)(__isl_keep MULTI(BASE) *multi,
 
827
        isl_bool (*test)(__isl_keep EL *))
 
828
{
 
829
        isl_size n;
 
830
        int i;
 
831
 
 
832
        n = FN(MULTI(BASE),size)(multi);
 
833
        if (n < 0)
 
834
                return isl_bool_error;
 
835
 
 
836
        for (i = 0; i < n; ++i) {
 
837
                isl_bool every = test(multi->u.p[i]);
 
838
                if (every < 0 || !every)
 
839
                        return every;
 
840
        }
 
841
 
 
842
        return isl_bool_true;
 
843
}
 
844
 
847
845
/* Convert a multiple expression defined over a parameter domain
848
846
 * into one that is defined over a zero-dimensional set.
849
847
 */