xref: /netbsd-src/external/mit/isl/dist/isl_pw_un_op_templ.c (revision 5971e316fdea024efff6be8f03536623db06833e)
1 /*
2  * Copyright 2010      INRIA Saclay
3  *
4  * Use of this software is governed by the MIT license
5  *
6  * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7  * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
8  * 91893 Orsay, France
9  */
10 
11 #include <isl_pw_macro.h>
12 
13 /* Data structure that specifies how isl_pw_*_un_op should
14  * modify its input.
15  *
16  * If "fn_space" is set, then it is applied to the space.
17  *
18  * If "fn_domain" is set, then it is applied to the cells.
19  *
20  * "fn_base" is applied to each base expression.
21  * This function is assumed to have no effect on the default value
22  * (i.e., zero for those objects with a default value).
23  */
S(PW,un_op_control)24 S(PW,un_op_control) {
25 	__isl_give isl_space *(*fn_space)(__isl_take isl_space *space);
26 	__isl_give isl_set *(*fn_domain)(__isl_take isl_set *domain);
27 	__isl_give EL *(*fn_base)(__isl_take EL *el);
28 };
29 
30 /* Modify "pw" based on "control".
31  *
32  * If the cells are modified, then the corresponding base expressions
33  * may need to be adjusted to the possibly modified equality constraints.
34  */
FN(PW,un_op)35 static __isl_give PW *FN(PW,un_op)(__isl_take PW *pw,
36 	S(PW,un_op_control) *control)
37 {
38 	isl_space *space;
39 	isl_size n;
40 	int i;
41 
42 	n = FN(PW,n_piece)(pw);
43 	if (n < 0)
44 		return FN(PW,free)(pw);
45 
46 	for (i = n - 1; i >= 0; --i) {
47 		EL *el;
48 		isl_set *domain;
49 
50 		el = FN(PW,take_base_at)(pw, i);
51 		el = control->fn_base(el);
52 		pw = FN(PW,restore_base_at)(pw, i, el);
53 
54 		if (!control->fn_domain)
55 			continue;
56 
57 		domain = FN(PW,take_domain_at)(pw, i);
58 		domain = control->fn_domain(domain);
59 		pw = FN(PW,restore_domain_at)(pw, i, domain);
60 
61 		pw = FN(PW,exploit_equalities_and_remove_if_empty)(pw, i);
62 	}
63 
64 	if (!control->fn_space)
65 		return pw;
66 
67 	space = FN(PW,take_space)(pw);
68 	space = control->fn_space(space);
69 	pw = FN(PW,restore_space)(pw, space);
70 
71 	return pw;
72 }
73