gpu.c: update_may_persist_at_band: return isl_stat
[ppcg.git] / util.c
blob0a67bc34d47a02de5b5d0fc16a49cbb5393497af
1 /*
2 * Copyright 2012-2013 Ecole Normale Superieure
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege,
7 * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
8 */
10 #include <isl/space.h>
11 #include <isl/val.h>
12 #include <isl/aff.h>
13 #include <isl/set.h>
15 #include "util.h"
17 /* Construct an isl_multi_val living in "space" with all values equal to "val".
19 __isl_give isl_multi_val *ppcg_multi_val_from_int(__isl_take isl_space *space,
20 int val)
22 int i, n;
23 isl_ctx *ctx;
24 isl_val *v;
25 isl_multi_val *mv;
27 if (!space)
28 return NULL;
30 ctx = isl_space_get_ctx(space);
31 n = isl_space_dim(space, isl_dim_set);
32 mv = isl_multi_val_zero(space);
33 v = isl_val_int_from_si(ctx, val);
34 for (i = 0; i < n; ++i)
35 mv = isl_multi_val_set_val(mv, i, isl_val_copy(v));
36 isl_val_free(v);
38 return mv;
41 /* Construct an isl_multi_val living in "space" with values specified
42 * by "list". "list" is assumed to have at least as many entries
43 * as the set dimension of "space".
45 __isl_give isl_multi_val *ppcg_multi_val_from_int_list(
46 __isl_take isl_space *space, int *list)
48 int i, n;
49 isl_ctx *ctx;
50 isl_multi_val *mv;
52 if (!space)
53 return NULL;
55 ctx = isl_space_get_ctx(space);
56 n = isl_space_dim(space, isl_dim_set);
57 mv = isl_multi_val_zero(space);
58 for (i = 0; i < n; ++i) {
59 isl_val *v;
61 v = isl_val_int_from_si(ctx, list[i]);
62 mv = isl_multi_val_set_val(mv, i, v);
65 return mv;
68 /* Compute the size of a bounding box around the origin and "set",
69 * where "set" is assumed to contain only non-negative elements.
70 * In particular, compute the maximal value of "set" in each direction
71 * and add one.
73 __isl_give isl_multi_pw_aff *ppcg_size_from_extent(__isl_take isl_set *set)
75 int i, n;
76 isl_multi_pw_aff *mpa;
78 n = isl_set_dim(set, isl_dim_set);
79 mpa = isl_multi_pw_aff_zero(isl_set_get_space(set));
80 for (i = 0; i < n; ++i) {
81 isl_space *space;
82 isl_aff *one;
83 isl_pw_aff *bound;
85 if (!isl_set_dim_has_upper_bound(set, isl_dim_set, i)) {
86 const char *name;
87 name = isl_set_get_tuple_name(set);
88 if (!name)
89 name = "";
90 fprintf(stderr, "unable to determine extent of '%s' "
91 "in dimension %d\n", name, i);
92 set = isl_set_free(set);
94 bound = isl_set_dim_max(isl_set_copy(set), i);
96 space = isl_pw_aff_get_domain_space(bound);
97 one = isl_aff_zero_on_domain(isl_local_space_from_space(space));
98 one = isl_aff_add_constant_si(one, 1);
99 bound = isl_pw_aff_add(bound, isl_pw_aff_from_aff(one));
100 mpa = isl_multi_pw_aff_set_pw_aff(mpa, i, bound);
102 isl_set_free(set);
104 return mpa;