Polly 20.0.0git
isl_multi_intersect.c
Go to the documentation of this file.
1/*
2 * Copyright 2011 Sven Verdoolaege
3 * Copyright 2012-2013 Ecole Normale Superieure
4 *
5 * Use of this software is governed by the MIT license
6 *
7 * Written by Sven Verdoolaege,
8 * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
9 */
10
11#include <isl_multi_macro.h>
12
13/* Does the space of "domain" correspond to that of the domain of "multi"?
14 * The parameters do not need to be aligned.
15 */
16static isl_bool FN(MULTI(BASE),compatible_domain)(
18{
19 isl_bool ok;
20 isl_space *space, *domain_space;
21
22 domain_space = FN(DOM,get_space)(domain);
23 space = FN(MULTI(BASE),get_space)(multi);
24 ok = isl_space_has_domain_tuples(domain_space, space);
25 isl_space_free(space);
26 isl_space_free(domain_space);
27
28 return ok;
29}
30
31/* Check that the space of "domain" corresponds to
32 * that of the domain of "multi", ignoring parameters.
33 */
34static isl_stat FN(MULTI(BASE),check_compatible_domain)(
36{
37 isl_bool ok;
38
39 ok = FN(MULTI(BASE),compatible_domain)(multi, domain);
40 if (ok < 0)
41 return isl_stat_error;
42 if (!ok)
44 "incompatible spaces", return isl_stat_error);
45
46 return isl_stat_ok;
47}
48
49/* Intersect the explicit domain of "multi" with "domain".
50 *
51 * The parameters of "multi" and "domain" are assumed to have been aligned.
52 *
53 * In the case of an isl_multi_union_pw_aff object, the explicit domain
54 * is allowed to have only constraints on the parameters, while
55 * "domain" contains actual domain elements. In this case,
56 * "domain" is intersected with those parameter constraints and
57 * then used as the explicit domain of "multi".
58 */
59static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect_aligned)(
61{
62 isl_bool is_params;
63 DOM *multi_dom;
64
65 if (FN(MULTI(BASE),check_compatible_domain)(multi, domain) < 0)
66 goto error;
67 if (FN(MULTI(BASE),check_has_explicit_domain)(multi) < 0)
68 goto error;
69 is_params = FN(DOM,is_params)(multi->u.dom);
70 if (is_params < 0)
71 goto error;
72 multi_dom = FN(MULTI(BASE),get_explicit_domain)(multi);
73 if (!is_params) {
74 domain = FN(DOM,intersect)(multi_dom, domain);
75 } else {
77
78 params = FN(DOM,params)(multi_dom);
79 domain = FN(DOM,intersect_params)(domain, params);
80 }
81 multi = FN(MULTI(BASE),set_explicit_domain)(multi, domain);
82 return multi;
83error:
84 FN(MULTI(BASE),free)(multi);
85 FN(DOM,free)(domain);
86 return NULL;
87}
88
89/* Intersect the explicit domain of "multi" with "domain".
90 * First align the parameters, if needed.
91 */
92static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect)(
94{
95 return FN(FN(MULTI(BASE),align_params),DOMBASE)(multi, domain,
96 FN(MULTI(BASE),domain_intersect_aligned));
97}
98
99/* Intersect the domain of "multi" with "domain".
100 *
101 * If "multi" has an explicit domain, then only this domain
102 * needs to be intersected.
103 */
104__isl_give MULTI(BASE) *FN(MULTI(BASE),intersect_domain)(
106{
107 if (FN(MULTI(BASE),has_explicit_domain)(multi))
108 return FN(MULTI(BASE),domain_intersect)(multi, domain);
109 return FN(FN(MULTI(BASE),apply),DOMBASE)(multi, domain,
110 &FN(EL,intersect_domain));
111}
112
113/* Intersect the parameter domain of the explicit domain of "multi"
114 * with "domain".
115 */
116static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect_params_aligned)(
118{
119 DOM *multi_dom;
120
121 multi_dom = FN(MULTI(BASE),get_explicit_domain)(multi);
122 multi_dom = FN(DOM,intersect_params)(multi_dom, domain);
123 multi = FN(MULTI(BASE),set_explicit_domain)(multi, multi_dom);
124
125 return multi;
126}
127
128/* Intersect the parameter domain of the explicit domain of "multi"
129 * with "domain".
130 * First align the parameters, if needed.
131 */
132static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect_params)(
134{
135 return FN(FN(MULTI(BASE),align_params),set)(multi, domain,
136 FN(MULTI(BASE),domain_intersect_params_aligned));
137}
138
139/* Intersect the parameter domain of "multi" with "domain".
140 *
141 * If "multi" has an explicit domain, then only this domain
142 * needs to be intersected.
143 */
144__isl_give MULTI(BASE) *FN(MULTI(BASE),intersect_params)(
146{
147 if (FN(MULTI(BASE),has_explicit_domain)(multi))
148 return FN(MULTI(BASE),domain_intersect_params)(multi, domain);
149 return FN(MULTI(BASE),apply_set)(multi, domain,
150 &FN(EL,intersect_params));
151}
#define FN(TYPE, NAME)
#define __isl_take
Definition: ctx.h:22
isl_stat
Definition: ctx.h:84
@ isl_stat_error
Definition: ctx.h:85
@ isl_stat_ok
Definition: ctx.h:86
#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_keep
Definition: ctx.h:25
isl_bool
Definition: ctx.h:89
#define BASE
Definition: flow_cmp.c:49
#define DOMBASE
Definition: isl_aff.c:8600
#define EL
#define MULTI(BASE)
#define DOM
static __isl_give isl_schedule_node * align_params(__isl_take isl_schedule_node *node, void *user)
Definition: isl_schedule.c:311
isl_bool isl_space_has_domain_tuples(__isl_keep isl_space *space1, __isl_keep isl_space *space2)
Definition: isl_space.c:2532
const char * set
Definition: isl_test.c:1356
struct isl_set isl_set
Definition: map_type.h:26
__isl_null isl_space * isl_space_free(__isl_take isl_space *space)
Definition: isl_space.c:445
static Kind params
static TupleKindPtr apply(const TupleKindPtr tuple, const Substitution &subs)
Definition: template_cpp.cc:82
static Signature domain
static std::vector< std::string > intersect(const std::vector< std::string > &v1, const std::vector< std::string > &v2)