• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018      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 #undef TYPE
12 #define TYPE CAT(isl_,BASE)
13 
14 /* Check that "map" and "multi" live in the same space, ignoring parameters.
15  */
FN(check_map_equal_tuples_multi,BASE)16 static isl_stat FN(check_map_equal_tuples_multi,BASE)(__isl_keep isl_map *map,
17 	__isl_keep MULTI(BASE) *multi)
18 {
19 	isl_space *map_space, *multi_space;
20 
21 	map_space = isl_map_peek_space(map);
22 	multi_space = FN(MULTI(BASE),peek_space)(multi);
23 	return isl_space_check_equal_tuples(map_space, multi_space);
24 }
25 
26 /* Apply "map_bound" to "map" with the corresponding value in "bound"
27  * for each output dimension.
28  */
FN(map_bound_multi,BASE)29 static __isl_give isl_map *FN(map_bound_multi,BASE)(__isl_take isl_map *map,
30 	__isl_take MULTI(BASE) *bound,
31 	__isl_give isl_map *map_bound(__isl_take isl_map *map,
32 		unsigned pos, __isl_take TYPE *value))
33 {
34 	int i;
35 	isl_size dim;
36 
37 	dim = isl_map_dim(map, isl_dim_out);
38 	if (dim < 0 || FN(check_map_equal_tuples_multi,BASE)(map, bound) < 0)
39 		goto error;
40 
41 	for (i = 0; i < dim; ++i) {
42 		TYPE *el;
43 
44 		el = FN(MULTI(BASE),get_at)(bound, i);
45 		map = map_bound(map, i, el);
46 	}
47 	FN(MULTI(BASE),free)(bound);
48 	return map;
49 error:
50 	isl_map_free(map);
51 	FN(MULTI(BASE),free)(bound);
52 	return NULL;
53 }
54