File: isl_multi_explicit_domain.c

package info (click to toggle)
isl 0.20-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 12,708 kB
  • sloc: ansic: 125,702; python: 5,770; sh: 4,291; cpp: 1,057; makefile: 497; lisp: 54; perl: 9
file content (205 lines) | stat: -rw-r--r-- 5,715 bytes parent folder | download | duplicates (12)
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
/*
 * Copyright 2017      Sven Verdoolaege
 *
 * Use of this software is governed by the MIT license
 *
 * Written by Sven Verdoolaege.
 */

/* These versions of the explicit domain functions are used
 * when the multi expression may have an explicit domain.
 */

#include <isl_multi_macro.h>

__isl_give MULTI(BASE) *FN(MULTI(BASE),cow)(__isl_take MULTI(BASE) *multi);

/* Does "multi" have an explicit domain?
 *
 * An explicit domain is only available if "multi" is zero-dimensional.
 */
static int FN(MULTI(BASE),has_explicit_domain)(__isl_keep MULTI(BASE) *multi)
{
	return multi && multi->n == 0;
}

/* Check that "multi" has an explicit domain.
 */
static isl_stat FN(MULTI(BASE),check_has_explicit_domain)(
	__isl_keep MULTI(BASE) *multi)
{
	if (!multi)
		return isl_stat_error;
	if (!FN(MULTI(BASE),has_explicit_domain)(multi))
		isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_internal,
			"expression does not have an explicit domain",
			return isl_stat_error);
	return isl_stat_ok;
}

/* Return the explicit domain of "multi", assuming it has one.
 */
static __isl_keep DOM *FN(MULTI(BASE),peek_explicit_domain)(
	__isl_keep MULTI(BASE) *multi)
{
	if (FN(MULTI(BASE),check_has_explicit_domain)(multi) < 0)
		return NULL;
	return multi->u.dom;
}

/* Return a copy of the explicit domain of "multi", assuming it has one.
 */
static __isl_give DOM *FN(MULTI(BASE),get_explicit_domain)(
	__isl_keep MULTI(BASE) *multi)
{
	return FN(DOM,copy)(FN(MULTI(BASE),peek_explicit_domain)(multi));
}

/* Replace the explicit domain of "multi" by "dom", assuming it has one.
 */
static __isl_give MULTI(BASE) *FN(MULTI(BASE),set_explicit_domain)(
	__isl_take MULTI(BASE) *multi, __isl_take DOM *dom)
{
	if (FN(MULTI(BASE),check_has_explicit_domain)(multi) < 0)
		goto error;
	multi = FN(MULTI(BASE),cow)(multi);
	if (!multi || !dom)
		goto error;
	FN(DOM,free)(multi->u.dom);
	multi->u.dom = dom;
	if (!multi->u.dom)
		return FN(MULTI(BASE),free)(multi);
	return multi;
error:
	FN(MULTI(BASE),free)(multi);
	FN(DOM,free)(dom);
	return NULL;
}

/* Intersect the domain of "dst" with the explicit domain of "src".
 *
 * In the case of isl_multi_union_pw_aff objects, the explicit domain
 * of "src" is allowed to have only constraints on the parameters, even
 * if the domain of "dst" contains actual domain elements.  In this case,
 * the domain of "dst" is intersected with those parameter constraints.
 */
static __isl_give MULTI(BASE) *FN(MULTI(BASE),intersect_explicit_domain)(
	__isl_take MULTI(BASE) *dst, __isl_keep MULTI(BASE) *src)
{
	isl_bool is_params;
	DOM *dom;

	dom = FN(MULTI(BASE),peek_explicit_domain)(src);
	is_params = FN(DOM,is_params)(dom);
	if (is_params < 0)
		return FN(MULTI(BASE),free)(dst);

	dom = FN(DOM,copy)(dom);
	if (!is_params) {
		dst = FN(MULTI(BASE),intersect_domain)(dst, dom);
	} else {
		isl_set *params;

		params = FN(DOM,params)(dom);
		dst = FN(MULTI(BASE),intersect_params)(dst, params);
	}

	return dst;
}

/* Set the explicit domain of "dst" to that of "src".
 */
static __isl_give MULTI(BASE) *FN(MULTI(BASE),copy_explicit_domain)(
	__isl_take MULTI(BASE) *dst, __isl_keep MULTI(BASE) *src)
{
	DOM *dom;

	dom = FN(MULTI(BASE),get_explicit_domain)(src);
	dst = FN(MULTI(BASE),set_explicit_domain)(dst, dom);

	return dst;
}

/* Align the parameters of the explicit domain of "multi" to those of "space".
 */
static __isl_give MULTI(BASE) *FN(MULTI(BASE),align_explicit_domain_params)(
	__isl_take MULTI(BASE) *multi, __isl_take isl_space *space)
{
	DOM *dom;

	dom = FN(MULTI(BASE),get_explicit_domain)(multi);
	dom = FN(DOM,align_params)(dom, space);
	multi = FN(MULTI(BASE),set_explicit_domain)(multi, dom);

	return multi;
}

/* Replace the space of the explicit domain of "multi" by "space",
 * without modifying its dimension.
 */
static __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_explicit_domain_space)(
	__isl_take MULTI(BASE) *multi, __isl_take isl_space *space)
{
	DOM *dom;

	dom = FN(MULTI(BASE),get_explicit_domain)(multi);
	dom = FN(DOM,reset_equal_dim_space)(dom, space);
	multi = FN(MULTI(BASE),set_explicit_domain)(multi, dom);

	return multi;
}

/* Free the explicit domain of "multi".
 */
static void FN(MULTI(BASE),free_explicit_domain)(__isl_keep MULTI(BASE) *multi)
{
	if (FN(MULTI(BASE),check_has_explicit_domain)(multi) < 0)
		return;
	FN(DOM,free)(multi->u.dom);
}

/* Do "multi1" and "multi2" have the same explicit domain?
 */
static isl_bool FN(MULTI(BASE),equal_explicit_domain)(
	__isl_keep MULTI(BASE) *multi1, __isl_keep MULTI(BASE) *multi2)
{
	DOM *dom1, *dom2;
	isl_bool equal;

	if (FN(MULTI(BASE),check_has_explicit_domain)(multi1) < 0 ||
	    FN(MULTI(BASE),check_has_explicit_domain)(multi2) < 0)
		return isl_bool_error;
	dom1 = FN(MULTI(BASE),get_explicit_domain)(multi1);
	dom2 = FN(MULTI(BASE),get_explicit_domain)(multi2);
	equal = FN(DOM,is_equal)(dom1, dom2);
	FN(DOM,free)(dom1);
	FN(DOM,free)(dom2);

	return equal;
}

static isl_stat FN(MULTI(BASE),check_explicit_domain)(
	__isl_keep MULTI(BASE) *multi) __attribute__ ((unused));

/* Debugging function to check that the explicit domain of "multi"
 * has the correct space.
 */
isl_stat FN(MULTI(BASE),check_explicit_domain)(__isl_keep MULTI(BASE) *multi)
{
	isl_space *space1, *space2;
	isl_bool equal;

	if (FN(MULTI(BASE),check_has_explicit_domain)(multi) < 0)
		return isl_stat_error;
	space1 = isl_space_domain(isl_space_copy(multi->space));
	space2 = FN(DOM,get_space)(multi->u.dom);
	equal = isl_space_is_equal(space1, space2);
	isl_space_free(space1);
	isl_space_free(space2);
	if (equal < 0)
		return isl_stat_error;
	if (!equal)
		isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_internal,
			"check failed", return isl_stat_error);
	return isl_stat_ok;
}