File: isl_multi_intersect.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 (151 lines) | stat: -rw-r--r-- 4,621 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
/*
 * Copyright 2011      Sven Verdoolaege
 * Copyright 2012-2013 Ecole Normale Superieure
 *
 * Use of this software is governed by the MIT license
 *
 * Written by Sven Verdoolaege,
 * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
 */

#include <isl_multi_macro.h>

/* Does the space of "domain" correspond to that of the domain of "multi"?
 * The parameters do not need to be aligned.
 */
static isl_bool FN(MULTI(BASE),compatible_domain)(
	__isl_keep MULTI(BASE) *multi, __isl_keep DOM *domain)
{
	isl_bool ok;
	isl_space *space, *domain_space;

	domain_space = FN(DOM,get_space)(domain);
	space = FN(MULTI(BASE),get_space)(multi);
	ok = isl_space_has_domain_tuples(domain_space, space);
	isl_space_free(space);
	isl_space_free(domain_space);

	return ok;
}

/* Check that the space of "domain" corresponds to
 * that of the domain of "multi", ignoring parameters.
 */
static isl_stat FN(MULTI(BASE),check_compatible_domain)(
	__isl_keep MULTI(BASE) *multi, __isl_keep DOM *domain)
{
	isl_bool ok;

	ok = FN(MULTI(BASE),compatible_domain)(multi, domain);
	if (ok < 0)
		return isl_stat_error;
	if (!ok)
		isl_die(FN(DOM,get_ctx)(domain), isl_error_invalid,
			"incompatible spaces", return isl_stat_error);

	return isl_stat_ok;
}

/* Intersect the explicit domain of "multi" with "domain".
 *
 * The parameters of "multi" and "domain" are assumed to have been aligned.
 *
 * In the case of an isl_multi_union_pw_aff object, the explicit domain
 * is allowed to have only constraints on the parameters, while
 * "domain" contains actual domain elements.  In this case,
 * "domain" is intersected with those parameter constraints and
 * then used as the explicit domain of "multi".
 */
static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect_aligned)(
	__isl_take MULTI(BASE) *multi, __isl_take DOM *domain)
{
	isl_bool is_params;
	DOM *multi_dom;

	if (FN(MULTI(BASE),check_compatible_domain)(multi, domain) < 0)
		goto error;
	if (FN(MULTI(BASE),check_has_explicit_domain)(multi) < 0)
		goto error;
	is_params = FN(DOM,is_params)(multi->u.dom);
	if (is_params < 0)
		goto error;
	multi_dom = FN(MULTI(BASE),get_explicit_domain)(multi);
	if (!is_params) {
		domain = FN(DOM,intersect)(multi_dom, domain);
	} else {
		isl_set *params;

		params = FN(DOM,params)(multi_dom);
		domain = FN(DOM,intersect_params)(domain, params);
	}
	multi = FN(MULTI(BASE),set_explicit_domain)(multi, domain);
	return multi;
error:
	FN(MULTI(BASE),free)(multi);
	FN(DOM,free)(domain);
	return NULL;
}

/* Intersect the explicit domain of "multi" with "domain".
 * First align the parameters, if needed.
 */
static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect)(
	__isl_take MULTI(BASE) *multi, __isl_take DOM *domain)
{
	return FN(FN(MULTI(BASE),align_params),DOMBASE)(multi, domain,
				    FN(MULTI(BASE),domain_intersect_aligned));
}

/* Intersect the domain of "multi" with "domain".
 *
 * If "multi" has an explicit domain, then only this domain
 * needs to be intersected.
 */
__isl_give MULTI(BASE) *FN(MULTI(BASE),intersect_domain)(
	__isl_take MULTI(BASE) *multi, __isl_take DOM *domain)
{
	if (FN(MULTI(BASE),has_explicit_domain)(multi))
		return FN(MULTI(BASE),domain_intersect)(multi, domain);
	return FN(FN(MULTI(BASE),apply),DOMBASE)(multi, domain,
					&FN(EL,intersect_domain));
}

/* Intersect the parameter domain of the explicit domain of "multi"
 * with "domain".
 */
static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect_params_aligned)(
	__isl_take MULTI(BASE) *multi, __isl_take isl_set *domain)
{
	DOM *multi_dom;

	multi_dom = FN(MULTI(BASE),get_explicit_domain)(multi);
	multi_dom = FN(DOM,intersect_params)(multi_dom, domain);
	multi = FN(MULTI(BASE),set_explicit_domain)(multi, multi_dom);

	return multi;
}

/* Intersect the parameter domain of the explicit domain of "multi"
 * with "domain".
 * First align the parameters, if needed.
 */
static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect_params)(
	__isl_take MULTI(BASE) *multi, __isl_take isl_set *domain)
{
	return FN(FN(MULTI(BASE),align_params),set)(multi, domain,
			    FN(MULTI(BASE),domain_intersect_params_aligned));
}

/* Intersect the parameter domain of "multi" with "domain".
 *
 * If "multi" has an explicit domain, then only this domain
 * needs to be intersected.
 */
__isl_give MULTI(BASE) *FN(MULTI(BASE),intersect_params)(
	__isl_take MULTI(BASE) *multi, __isl_take isl_set *domain)
{
	if (FN(MULTI(BASE),has_explicit_domain)(multi))
		return FN(MULTI(BASE),domain_intersect_params)(multi, domain);
	return FN(MULTI(BASE),apply_set)(multi, domain,
					&FN(EL,intersect_params));
}