xref: /netbsd-src/external/mit/isl/dist/isl_multi_add_constant_templ.c (revision 5971e316fdea024efff6be8f03536623db06833e)
1 /*
2  * Copyright 2019      Cerebras Systems
3  *
4  * Use of this software is governed by the MIT license
5  *
6  * Written by Sven Verdoolaege,
7  * Cerebras Systems, 175 S San Antonio Rd, Los Altos, CA, USA
8  */
9 
10 #include <isl_multi_macro.h>
11 
12 /* Add "v" to the constant terms of all the base expressions of "multi".
13  */
MULTI(BASE)14 __isl_give MULTI(BASE) *FN(MULTI(BASE),add_constant_val)(
15 	__isl_take MULTI(BASE) *multi, __isl_take isl_val *v)
16 {
17 	isl_bool zero;
18 
19 	zero = isl_val_is_zero(v);
20 	if (zero < 0)
21 		goto error;
22 	if (zero) {
23 		isl_val_free(v);
24 		return multi;
25 	}
26 
27 	return FN(MULTI(BASE),fn_val)(multi, &FN(EL,add_constant_val), v);
28 error:
29 	FN(MULTI(BASE),free)(multi);
30 	isl_val_free(v);
31 	return NULL;
32 }
33 
34 /* Add the elements of "mv" to the constant terms of
35  * the corresponding base expressions of "multi".
36  */
MULTI(BASE)37 __isl_give MULTI(BASE) *FN(MULTI(BASE),add_constant_multi_val)(
38 	__isl_take MULTI(BASE) *multi, __isl_take isl_multi_val *mv)
39 {
40 	isl_bool zero;
41 
42 	zero = isl_multi_val_is_zero(mv);
43 	if (zero < 0)
44 		goto error;
45 	if (zero) {
46 		isl_multi_val_free(mv);
47 		return multi;
48 	}
49 
50 	return FN(MULTI(BASE),fn_multi_val)(multi, &FN(EL,add_constant_val),
51 						mv);
52 
53 error:
54 	FN(MULTI(BASE),free)(multi);
55 	isl_multi_val_free(mv);
56 	return NULL;
57 }
58