1 /*
2  * Copyright 2013      Ecole Normale Superieure
3  *
4  * Use of this software is governed by the MIT license
5  *
6  * Written by Sven Verdoolaege,
7  * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
8  */
9 
10 #include <isl/set.h>
11 
12 #include <isl_multi_macro.h>
13 
14 /* Return the shared domain of the elements of "multi".
15  *
16  * If "multi" has an explicit domain, then return this domain.
17  */
FN(MULTI (BASE),domain)18 __isl_give isl_set *FN(MULTI(BASE),domain)(__isl_take MULTI(BASE) *multi)
19 {
20 	int i;
21 	isl_set *dom;
22 
23 	if (!multi)
24 		return NULL;
25 
26 	if (FN(MULTI(BASE),has_explicit_domain)(multi)) {
27 		dom = FN(MULTI(BASE),get_explicit_domain)(multi);
28 		FN(MULTI(BASE),free)(multi);
29 		return dom;
30 	}
31 
32 	dom = isl_set_universe(FN(MULTI(BASE),get_domain_space)(multi));
33 	for (i = 0; i < multi->n; ++i) {
34 		isl_set *dom_i;
35 
36 		dom_i = FN(EL,domain)(FN(FN(MULTI(BASE),get),BASE)(multi, i));
37 		dom = isl_set_intersect(dom, dom_i);
38 	}
39 
40 	FN(MULTI(BASE),free)(multi);
41 	return dom;
42 }
43