xref: /llvm-project/polly/lib/External/isl/isl_pw_un_op_templ.c (revision a749e09e184b2b0b6dde71af01c82dd427b3e3e2)
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 /* Apply "fn" to each of the base expressions of "pw".
14  * The function is assumed to have no effect on the default value
15  * (i.e., zero for those objects with a default value).
16  */
FN(PW,un_op)17 static __isl_give PW *FN(PW,un_op)(__isl_take PW *pw,
18 	__isl_give EL *(*fn)(__isl_take EL *el))
19 {
20 	isl_size n;
21 	int i;
22 
23 	n = FN(PW,n_piece)(pw);
24 	if (n < 0)
25 		return FN(PW,free)(pw);
26 
27 	for (i = 0; i < n; ++i) {
28 		EL *el;
29 
30 		el = FN(PW,take_base_at)(pw, i);
31 		el = fn(el);
32 		pw = FN(PW,restore_base_at)(pw, i, el);
33 	}
34 
35 	return pw;
36 }
37