Polly 19.0.0git
isl_pw_add_disjoint_templ.c
Go to the documentation of this file.
1/*
2 * Copyright 2010 INRIA Saclay
3 * Copyright 2011 Sven Verdoolaege
4 *
5 * Use of this software is governed by the MIT license
6 *
7 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
8 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
9 * 91893 Orsay, France
10 */
11
12#include <isl_pw_macro.h>
13
14/* Make sure "pw" has room for at least "n" more pieces.
15 *
16 * If there is only one reference to pw, we extend it in place.
17 * Otherwise, we create a new PW and copy the pieces.
18 */
19static __isl_give PW *FN(PW,grow)(__isl_take PW *pw, int n)
20{
21 int i;
22 isl_ctx *ctx;
23 PW *res;
24
25 if (!pw)
26 return NULL;
27 if (pw->n + n <= pw->size)
28 return pw;
29 ctx = FN(PW,get_ctx)(pw);
30 n += pw->n;
31 if (pw->ref == 1) {
32 res = isl_realloc(ctx, pw, struct PW,
33 sizeof(struct PW) + (n - 1) * sizeof(S(PW,piece)));
34 if (!res)
35 return FN(PW,free)(pw);
36 res->size = n;
37 return res;
38 }
39 res = FN(PW,alloc_size)(isl_space_copy(pw->dim) OPT_TYPE_ARG(pw->), n);
40 if (!res)
41 return FN(PW,free)(pw);
42 for (i = 0; i < pw->n; ++i)
43 res = FN(PW,add_piece)(res, isl_set_copy(pw->p[i].set),
44 FN(EL,copy)(pw->p[i].FIELD));
45 FN(PW,free)(pw);
46 return res;
47}
48
49__isl_give PW *FN(PW,add_disjoint)(__isl_take PW *pw1, __isl_take PW *pw2)
50{
51 int i;
52 isl_ctx *ctx;
53
54 if (FN(PW,align_params_bin)(&pw1, &pw2) < 0)
55 goto error;
56
57 if (pw1->size < pw1->n + pw2->n && pw1->n < pw2->n)
58 return FN(PW,add_disjoint)(pw2, pw1);
59
60 ctx = isl_space_get_ctx(pw1->dim);
61 if (!OPT_EQUAL_TYPES(pw1->, pw2->))
63 "fold types don't match", goto error);
64 if (FN(PW,check_equal_space)(pw1, pw2) < 0)
65 goto error;
66
67 if (FN(PW,IS_ZERO)(pw1)) {
68 FN(PW,free)(pw1);
69 return pw2;
70 }
71
72 if (FN(PW,IS_ZERO)(pw2)) {
73 FN(PW,free)(pw2);
74 return pw1;
75 }
76
77 pw1 = FN(PW,grow)(pw1, pw2->n);
78 if (!pw1)
79 goto error;
80
81 for (i = 0; i < pw2->n; ++i)
82 pw1 = FN(PW,add_piece)(pw1,
83 isl_set_copy(pw2->p[i].set),
84 FN(EL,copy)(pw2->p[i].FIELD));
85
86 FN(PW,free)(pw2);
87
88 return pw1;
89error:
90 FN(PW,free)(pw1);
91 FN(PW,free)(pw2);
92 return NULL;
93}
#define FN(TYPE, NAME)
#define __isl_take
Definition: ctx.h:22
#define __isl_give
Definition: ctx.h:19
#define isl_die(ctx, errno, msg, code)
Definition: ctx.h:137
@ isl_error_invalid
Definition: ctx.h:80
#define isl_realloc(ctx, ptr, type, size)
Definition: ctx.h:126
#define IS_ZERO
Definition: isl_aff.c:4590
#define PW
Definition: isl_aff.c:4582
#define EL
#define S(TYPE, NAME)
const char * res
Definition: isl_test.c:775
const char * size
Definition: isl_test.c:1570
#define OPT_TYPE_ARG(loc)
Definition: opt_type.h:12
#define OPT_EQUAL_TYPES(loc1, loc2)
Definition: opt_type.h:15
__isl_give isl_set * isl_set_copy(__isl_keep isl_set *set)
Definition: isl_map.c:1470
isl_ctx * isl_space_get_ctx(__isl_keep isl_space *space)
Definition: isl_space.c:23
__isl_give isl_space * isl_space_copy(__isl_keep isl_space *space)
Definition: isl_space.c:436
n
Definition: youcefn.c:8