update isl to version 0.17.1
[ppcg.git] / util.c
blob2bb7cf6eb8b4c23b531ebefb4e240ac33cc4bde9
1 /*
2 * Copyright 2012 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 /* Compute the size of a bounding box around the origin and "set",
42 * where "set" is assumed to contain only non-negative elements.
43 * In particular, compute the maximal value of "set" in each direction
44 * and add one.
46 __isl_give isl_multi_pw_aff *ppcg_size_from_extent(__isl_take isl_set *set)
48 int i, n;
49 isl_multi_pw_aff *mpa;
51 n = isl_set_dim(set, isl_dim_set);
52 mpa = isl_multi_pw_aff_zero(isl_set_get_space(set));
53 for (i = 0; i < n; ++i) {
54 isl_space *space;
55 isl_aff *one;
56 isl_pw_aff *bound;
58 if (!isl_set_dim_has_upper_bound(set, isl_dim_set, i)) {
59 const char *name;
60 name = isl_set_get_tuple_name(set);
61 if (!name)
62 name = "";
63 fprintf(stderr, "unable to determine extent of '%s' "
64 "in dimension %d\n", name, i);
65 set = isl_set_free(set);
67 bound = isl_set_dim_max(isl_set_copy(set), i);
69 space = isl_pw_aff_get_domain_space(bound);
70 one = isl_aff_zero_on_domain(isl_local_space_from_space(space));
71 one = isl_aff_add_constant_si(one, 1);
72 bound = isl_pw_aff_add(bound, isl_pw_aff_from_aff(one));
73 mpa = isl_multi_pw_aff_set_pw_aff(mpa, i, bound);
75 isl_set_free(set);
77 return mpa;