sbcl 2.1.11 rebuild
[arch-packages.git] / cloog / trunk / cloog-0.18.1-isl-compat.patch
blob82e6bb07e84143bf92abff1a9e053c9ec958fa64
2 diff --git a/source/isl/domain.c b/source/isl/domain.c
3 index d11da7b..620584d 100644
4 --- a/source/isl/domain.c
5 +++ b/source/isl/domain.c
6 @@ -1389,20 +1389,20 @@ CloogDomain *cloog_domain_cube(CloogState *state,
7 int dim, cloog_int_t min, cloog_int_t max)
9 int i;
10 - struct isl_basic_set *cube;
11 - struct isl_basic_set *interval;
12 - struct isl_basic_set_list *list;
13 + isl_space *space;
14 + isl_set *cube;
16 if (dim == 0)
17 return cloog_domain_universe(state, dim);
19 - interval = isl_basic_set_interval(state->backend->ctx, min, max);
20 - list = isl_basic_set_list_alloc(state->backend->ctx, dim);
21 - for (i = 0; i < dim; ++i)
22 - list = isl_basic_set_list_add(list, isl_basic_set_copy(interval));
23 - isl_basic_set_free(interval);
24 - cube = isl_basic_set_list_product(list);
25 - return cloog_domain_from_isl_set(isl_set_from_basic_set(cube));
26 + space = isl_space_set_alloc(state->backend->ctx, 0, dim);
27 + cube = isl_set_universe(space);
28 + for (i = 0; i < dim; ++i) {
29 + cube = isl_set_lower_bound(cube, isl_dim_set, i, min);
30 + cube = isl_set_upper_bound(cube, isl_dim_set, i, max);
31 + }
33 + return cloog_domain_from_isl_set(cube);
37 diff --git a/include/cloog/isl/constraintset.h b/include/cloog/isl/constraintset.h
38 index c3c2eed..5d48cdb 100644
39 --- a/include/cloog/isl/constraintset.h
40 +++ b/include/cloog/isl/constraintset.h
41 @@ -27,6 +27,12 @@ CloogConstraintSet *cloog_constraint_set_from_isl_basic_set(struct isl_basic_set
42 CloogConstraint *cloog_constraint_from_isl_constraint(struct isl_constraint *constraint);
43 isl_constraint *cloog_constraint_to_isl(CloogConstraint *constraint);
45 +__isl_give isl_val *cloog_int_to_isl_val(isl_ctx* ctx, cloog_int_t c);
46 +void isl_val_to_cloog_int(__isl_keep isl_val *val, cloog_int_t *cint);
48 +__isl_give isl_val *cloog_constraint_coefficient_get_val(CloogConstraint *constraint,
49 + int var);
51 #if defined(__cplusplus)
53 #endif
54 diff --git a/source/isl/constraints.c b/source/isl/constraints.c
55 index e860000..73d72df 100644
56 --- a/source/isl/constraints.c
57 +++ b/source/isl/constraints.c
58 @@ -5,11 +5,51 @@
59 #include <cloog/isl/backend.h>
60 #include <isl/aff.h>
61 #include <isl/set.h>
62 +#include <isl/val.h>
63 +#include <isl/val_gmp.h>
66 #define ALLOC(type) (type*)malloc(sizeof(type))
67 #define ALLOCN(type,n) (type*)malloc((n)*sizeof(type))
69 +__isl_give isl_val *cloog_int_to_isl_val(isl_ctx* ctx, cloog_int_t c)
71 + isl_val *v;
72 +#if defined(CLOOG_INT_INT)
73 + v = isl_val_int_from_si(ctx, c);
74 +#elif defined(CLOOG_INT_LONG)
75 + v = isl_val_int_from_si(ctx, c);
76 +#elif defined(CLOOG_INT_LONG_LONG)
77 + v = isl_val_int_from_si(ctx, c);
78 +#elif defined(CLOOG_INT_GMP)
79 + v = isl_val_int_from_gmp(ctx, c);
80 +#else
81 +#error "No integer type defined"
82 +#endif
83 + return v;
86 +/*
87 + * CLooG'll be dealing in integers so we expect numerator/1 form
88 + * from isl_val. Thus get numerator to assign to cloog_int
89 + */
90 +void isl_val_to_cloog_int(__isl_keep isl_val *val, cloog_int_t *cint)
92 + assert(isl_val_is_int(val));
93 +#if defined(CLOOG_INT_INT)
94 + *cint = isl_val_get_num_si(val);
95 +#elif defined(CLOOG_INT_LONG)
96 + *cint = isl_val_get_num_si(val);
97 +#elif defined(CLOOG_INT_LONG_LONG)
98 + *cint = isl_val_get_num_si(val);
99 +#elif defined(CLOOG_INT_GMP)
100 + isl_val_get_num_gmp(val, *cint);
101 +#else
102 +#error "No integer type defined"
103 +#endif
107 CloogConstraintSet *cloog_constraint_set_from_isl_basic_set(struct isl_basic_set *bset)
109 return (CloogConstraintSet *)bset;
110 @@ -266,53 +306,65 @@ int cloog_equal_count(CloogEqualities *equal)
111 static int cloog_constraint_equal_type(CloogConstraint *cc, int level)
113 int i;
114 - isl_int c;
115 + isl_val *c;
116 int type = EQTYPE_NONE;
117 struct isl_constraint *constraint = cloog_constraint_to_isl(cc);
119 - isl_int_init(c);
120 - isl_constraint_get_constant(constraint, &c);
121 - if (!isl_int_is_zero(c))
122 + c = isl_constraint_get_constant_val(constraint);
123 + if (!isl_val_is_zero(c))
124 type = EQTYPE_CONSTANT;
125 - isl_constraint_get_coefficient(constraint, isl_dim_set, level - 1, &c);
126 - if (!isl_int_is_one(c) && !isl_int_is_negone(c))
127 + isl_val_free(c);
128 + c = isl_constraint_get_coefficient_val(constraint, isl_dim_set, level - 1);
129 + if (!isl_val_is_one(c) && !isl_val_is_negone(c))
130 type = EQTYPE_EXAFFINE;
131 + isl_val_free(c);
132 for (i = 0; i < isl_constraint_dim(constraint, isl_dim_param); ++i) {
133 - isl_constraint_get_coefficient(constraint, isl_dim_param, i, &c);
134 - if (isl_int_is_zero(c))
135 + c = isl_constraint_get_coefficient_val(constraint, isl_dim_param, i);
136 + if (isl_val_is_zero(c)){
137 + isl_val_free(c);
138 continue;
139 - if ((!isl_int_is_one(c) && !isl_int_is_negone(c)) ||
141 + if ((!isl_val_is_one(c) && !isl_val_is_negone(c)) ||
142 type != EQTYPE_NONE) {
143 type = EQTYPE_EXAFFINE;
144 + isl_val_free(c);
145 break;
147 type = EQTYPE_PUREITEM;
148 + isl_val_free(c);
150 for (i = 0; i < isl_constraint_dim(constraint, isl_dim_set); ++i) {
151 if (i == level - 1)
152 continue;
153 - isl_constraint_get_coefficient(constraint, isl_dim_set, i, &c);
154 - if (isl_int_is_zero(c))
155 + c = isl_constraint_get_coefficient_val(constraint, isl_dim_set, i);
156 + if (isl_val_is_zero(c)){
157 + isl_val_free(c);
158 continue;
159 - if ((!isl_int_is_one(c) && !isl_int_is_negone(c)) ||
161 + if ((!isl_val_is_one(c) && !isl_val_is_negone(c)) ||
162 type != EQTYPE_NONE) {
163 type = EQTYPE_EXAFFINE;
164 + isl_val_free(c);
165 break;
167 type = EQTYPE_PUREITEM;
168 + isl_val_free(c);
170 for (i = 0; i < isl_constraint_dim(constraint, isl_dim_div); ++i) {
171 - isl_constraint_get_coefficient(constraint, isl_dim_div, i, &c);
172 - if (isl_int_is_zero(c))
173 + c = isl_constraint_get_coefficient_val(constraint, isl_dim_div, i);
174 + if (isl_val_is_zero(c)){
175 + isl_val_free(c);
176 continue;
177 - if ((!isl_int_is_one(c) && !isl_int_is_negone(c)) ||
179 + if ((!isl_val_is_one(c) && !isl_val_is_negone(c)) ||
180 type != EQTYPE_NONE) {
181 type = EQTYPE_EXAFFINE;
182 + isl_val_free(c);
183 break;
185 type = EQTYPE_PUREITEM;
186 + isl_val_free(c);
188 - isl_int_clear(c);
190 if (type == EQTYPE_NONE)
191 type = EQTYPE_CONSTANT;
192 @@ -447,27 +499,31 @@ static struct clast_expr *div_expr(CloogConstraint *constraint, int pos,
194 int i, nb_elts;
195 unsigned dim = cloog_constraint_total_dimension(constraint);
196 - cloog_int_t c;
197 + isl_val *c;
198 struct clast_reduction *r;
199 struct clast_expr *e = NULL;
200 isl_aff *div;
201 + cloog_int_t cint;
203 + cloog_int_init(cint);
204 div = isl_constraint_get_div(cloog_constraint_to_isl(constraint), pos);
206 - cloog_int_init(c);
207 for (i = 0, nb_elts = 0; i < dim; ++i) {
208 struct cloog_isl_dim dim;
210 dim = constraint_cloog_dim_to_isl_dim(constraint, i);
211 if (dim.type == isl_dim_set)
212 dim.type = isl_dim_in;
213 - isl_aff_get_coefficient(div, dim.type, dim.pos, &c);
214 - if (!cloog_int_is_zero(c))
215 + c = isl_aff_get_coefficient_val(div, dim.type, dim.pos);
216 + if (!isl_val_is_zero(c))
217 ++nb_elts;
219 + isl_val_free(c);
221 - isl_aff_get_constant(div, &c);
222 - if (!cloog_int_is_zero(c))
223 + c = isl_aff_get_constant_val(div);
224 + if (!isl_val_is_zero(c))
225 ++nb_elts;
226 + isl_val_free(c);
228 r = new_clast_reduction(clast_red_sum, nb_elts);
229 for (i = 0, nb_elts = 0; i < dim; ++i) {
230 @@ -477,22 +533,35 @@ static struct clast_expr *div_expr(CloogConstraint *constraint, int pos,
231 dim = constraint_cloog_dim_to_isl_dim(constraint, i);
232 if (dim.type == isl_dim_set)
233 dim.type = isl_dim_in;
234 - isl_aff_get_coefficient(div, dim.type, dim.pos, &c);
235 - if (cloog_int_is_zero(c))
236 + c = isl_aff_get_coefficient_val(div, dim.type, dim.pos);
237 + if (isl_val_is_zero(c)){
238 + isl_val_free(c);
239 continue;
242 v = cloog_constraint_variable_expr(constraint, 1 + i, names);
244 - r->elts[nb_elts++] = &new_clast_term(c, v)->expr;
245 + /* We are interested only in the numerator */
246 + cloog_int_set_si(cint, isl_val_get_num_si(c));
247 + r->elts[nb_elts++] = &new_clast_term(cint, v)->expr;
249 + isl_val_free(c);
252 + c = isl_aff_get_constant_val(div);
253 + if (!isl_val_is_zero(c)) {
254 + /* We are interested only in the numerator */
255 + cloog_int_set_si(cint, isl_val_get_num_si(c));
256 + r->elts[nb_elts++] = &new_clast_term(cint, NULL)->expr;
258 - isl_aff_get_constant(div, &c);
259 - if (!cloog_int_is_zero(c))
260 - r->elts[nb_elts++] = &new_clast_term(c, NULL)->expr;
261 + isl_val_free(c);
263 - isl_aff_get_denominator(div, &c);
264 - e = &new_clast_binary(clast_bin_fdiv, &r->expr, c)->expr;
265 + c = isl_aff_get_denominator_val(div);
266 + isl_val_to_cloog_int(c, &cint);
267 + isl_val_free(c);
268 + e = &new_clast_binary(clast_bin_fdiv, &r->expr, cint)->expr;
270 - cloog_int_clear(c);
271 + cloog_int_clear(cint);
273 isl_aff_free(div);
275 @@ -529,37 +598,34 @@ struct clast_expr *cloog_constraint_variable_expr(CloogConstraint *constraint,
277 int cloog_constraint_involves(CloogConstraint *constraint, int v)
279 - isl_int c;
280 + isl_val *c;
281 int res;
283 - isl_int_init(c);
284 - cloog_constraint_coefficient_get(constraint, v, &c);
285 - res = !isl_int_is_zero(c);
286 - isl_int_clear(c);
287 + c = cloog_constraint_coefficient_get_val(constraint, v);
288 + res = !isl_val_is_zero(c);
289 + isl_val_free(c);
290 return res;
293 int cloog_constraint_is_lower_bound(CloogConstraint *constraint, int v)
295 - isl_int c;
296 + isl_val *c;
297 int res;
299 - isl_int_init(c);
300 - cloog_constraint_coefficient_get(constraint, v, &c);
301 - res = isl_int_is_pos(c);
302 - isl_int_clear(c);
303 + c = cloog_constraint_coefficient_get_val(constraint, v);
304 + res = isl_val_is_pos(c);
305 + isl_val_free(c);
306 return res;
309 int cloog_constraint_is_upper_bound(CloogConstraint *constraint, int v)
311 - isl_int c;
312 + isl_val *c;
313 int res;
315 - isl_int_init(c);
316 - cloog_constraint_coefficient_get(constraint, v, &c);
317 - res = isl_int_is_neg(c);
318 - isl_int_clear(c);
319 + c = cloog_constraint_coefficient_get_val(constraint, v);
320 + res = isl_val_is_neg(c);
321 + isl_val_free(c);
322 return res;
325 @@ -585,15 +651,37 @@ void cloog_constraint_coefficient_get(CloogConstraint *constraint,
327 struct cloog_isl_dim dim;
328 isl_constraint *c;
329 + isl_val *ival;
331 + if (!constraint)
332 + val = NULL;
334 + dim = constraint_cloog_dim_to_isl_dim(constraint, var);
335 + c = cloog_constraint_to_isl(constraint);
336 + ival = isl_constraint_get_coefficient_val(c, dim.type, dim.pos);
338 + isl_val_to_cloog_int(ival, val);
339 + isl_val_free(ival);
342 +isl_val *cloog_constraint_coefficient_get_val(CloogConstraint *constraint,
343 + int var)
345 + struct cloog_isl_dim dim;
346 + isl_constraint *c;
347 + isl_val *val;
349 if (!constraint)
350 - return;
351 + return NULL;
353 dim = constraint_cloog_dim_to_isl_dim(constraint, var);
354 c = cloog_constraint_to_isl(constraint);
355 - isl_constraint_get_coefficient(c, dim.type, dim.pos, val);
356 + val = isl_constraint_get_coefficient_val(c, dim.type, dim.pos);
357 + return val;
362 void cloog_constraint_coefficient_set(CloogConstraint *constraint,
363 int var, cloog_int_t val)
365 @@ -604,14 +692,26 @@ void cloog_constraint_coefficient_set(CloogConstraint *constraint,
367 dim = constraint_cloog_dim_to_isl_dim(constraint, var);
368 c = cloog_constraint_to_isl(constraint);
369 - isl_constraint_set_coefficient(c, dim.type, dim.pos, val);
370 + isl_constraint_set_coefficient_val(c, dim.type, dim.pos,
371 + cloog_int_to_isl_val(isl_constraint_get_ctx(c), val));
374 void cloog_constraint_constant_get(CloogConstraint *constraint, cloog_int_t *val)
376 - isl_constraint_get_constant(cloog_constraint_to_isl(constraint), val);
377 + isl_val *ival;
378 + ival = isl_constraint_get_constant_val(cloog_constraint_to_isl(constraint));
379 + isl_val_to_cloog_int(ival, val);
380 + isl_val_free(ival);
384 +__isl_give isl_val *cloog_constraint_constant_get_val(CloogConstraint *constraint)
386 + return isl_constraint_get_constant_val(cloog_constraint_to_isl(constraint));
392 * Copy the coefficient of constraint c into dst in PolyLib order,
393 * i.e., first the coefficients of the variables, then the coefficients
394 @@ -700,15 +800,11 @@ CloogConstraintSet *cloog_constraint_set_for_reduction(CloogConstraint *upper,
396 static int add_constant_term(CloogConstraint *c, void *user)
398 - isl_int *bound = (isl_int *)user;
399 - isl_int v;
401 - isl_int_init(v);
403 - cloog_constraint_constant_get(c, &v);
404 - isl_int_add(*bound, *bound, v);
405 + isl_val **bound = (isl_val **)user;
406 + isl_val *v;
408 - isl_int_clear(v);
409 + v = cloog_constraint_constant_get_val(c);
410 + *bound = isl_val_add(*bound, v);
412 return 0;
414 @@ -822,11 +918,14 @@ CloogConstraintSet *cloog_constraint_set_reduce(CloogConstraintSet *constraints,
415 c = isl_constraint_set_coefficient_si(c, isl_dim_set, dim.pos, -1);
416 bset = isl_basic_set_add_constraint(bset, c);
418 - isl_int_set_si(*bound, 0);
419 + cloog_int_set_si(*bound, 0);
420 + isl_val *v = cloog_int_to_isl_val(isl_basic_set_get_ctx(bset), *bound);
421 constraints = cloog_constraint_set_from_isl_basic_set(bset);
422 cloog_constraint_set_foreach_constraint(constraints,
423 - add_constant_term, bound);
424 + add_constant_term, &v);
425 + isl_val_to_cloog_int(v, bound); //return the value to bound
427 + isl_val_free(v);
428 isl_basic_set_free(orig);
429 return cloog_constraint_set_from_isl_basic_set(bset);
431 @@ -896,31 +995,27 @@ static isl_aff *extract_stride_offset(__isl_keep isl_constraint *c,
432 isl_space *dim = isl_constraint_get_space(c);
433 isl_local_space *ls = isl_local_space_from_space(dim);
434 isl_aff *offset = isl_aff_zero_on_domain(ls);
435 - isl_int u;
436 + isl_val *u;
437 unsigned nparam, nvar;
439 - isl_int_init(u);
441 nparam = isl_constraint_dim(c, isl_dim_param);
442 nvar = isl_constraint_dim(c, isl_dim_set);
444 for (i = 0; i < nparam; ++i) {
445 - isl_constraint_get_coefficient(c, isl_dim_param, i, &u);
446 - isl_int_mul(u, u, stride->factor);
447 - offset = isl_aff_set_coefficient(offset, isl_dim_param, i, u);
448 + u = isl_constraint_get_coefficient_val(c, isl_dim_param, i);
449 + u = isl_val_mul(u, cloog_int_to_isl_val(isl_constraint_get_ctx(c), stride->factor));
450 + offset = isl_aff_set_coefficient_val(offset, isl_dim_param, i, u);
452 for (i = 0; i < nvar; ++i) {
453 if (i == level - 1)
454 continue;
455 - isl_constraint_get_coefficient(c, isl_dim_set, i, &u);
456 - isl_int_mul(u, u, stride->factor);
457 - offset = isl_aff_set_coefficient(offset, isl_dim_in, i, u);
458 + u = isl_constraint_get_coefficient_val(c, isl_dim_set, i);
459 + u = isl_val_mul(u, cloog_int_to_isl_val(isl_constraint_get_ctx(c), stride->factor));
460 + offset = isl_aff_set_coefficient_val(offset, isl_dim_in, i, u);
462 - isl_constraint_get_constant(c, &u);
463 - isl_int_mul(u, u, stride->factor);
464 - offset = isl_aff_set_constant(offset, u);
466 - isl_int_clear(u);
467 + u = isl_constraint_get_constant_val(c);
468 + u = isl_val_mul(u, cloog_int_to_isl_val(isl_constraint_get_ctx(c), stride->factor));
469 + offset = isl_aff_set_constant_val(offset, u);
471 return offset;
473 @@ -953,9 +1048,9 @@ CloogConstraint *cloog_constraint_stride_lower_bound(CloogConstraint *c,
474 offset = extract_stride_offset(stride_c, level, stride);
476 lower = isl_aff_sub(lower, isl_aff_copy(offset));
477 - lower = isl_aff_scale_down(lower, stride->stride);
478 + lower = isl_aff_scale_down_val(lower, cloog_int_to_isl_val(isl_constraint_get_ctx(stride_c), stride->stride));
479 lower = isl_aff_ceil(lower);
480 - lower = isl_aff_scale(lower, stride->stride);
481 + lower = isl_aff_scale_val(lower, cloog_int_to_isl_val(isl_constraint_get_ctx(stride_c), stride->stride));
482 lower = isl_aff_add(lower, offset);
483 lower = isl_aff_neg(lower);
484 lower = isl_aff_add_coefficient_si(lower, isl_dim_in, level - 1, 1);
485 diff --git a/source/isl/domain.c b/source/isl/domain.c
486 index 620584d..dc81a96 100644
487 --- a/source/isl/domain.c
488 +++ b/source/isl/domain.c
489 @@ -7,7 +7,11 @@
490 #include <isl/list.h>
491 #include <isl/constraint.h>
492 #include <isl/ilp.h>
493 +#include <isl/lp.h>
494 #include <isl/aff.h>
495 +#include <isl/map.h>
496 +#include <isl/val.h>
497 +#include <isl/val_gmp.h>
499 #ifdef OSL_SUPPORT
500 #include <osl/macros.h>
501 @@ -510,15 +514,18 @@ static struct isl_constraint *isl_constraint_read_from_matrix(
502 else
503 constraint = isl_inequality_alloc(ls);
505 - for (j = 0; j < nvariables; ++j)
506 - isl_constraint_set_coefficient(constraint, isl_dim_out, j,
507 - row[1 + j]);
508 + for (j = 0; j < nvariables; ++j) {
509 + isl_val *val = cloog_int_to_isl_val(isl_constraint_get_ctx(constraint), row[1 + j]);
510 + isl_constraint_set_coefficient_val(constraint, isl_dim_out, j, val);
513 - for (j = 0; j < nparam; ++j)
514 - isl_constraint_set_coefficient(constraint, isl_dim_param, j,
515 - row[1 + nvariables + j]);
516 + for (j = 0; j < nparam; ++j) {
517 + isl_val *val = cloog_int_to_isl_val(isl_constraint_get_ctx(constraint), row[1 + nvariables + j]);
518 + isl_constraint_set_coefficient_val(constraint, isl_dim_param, j, val);
521 - isl_constraint_set_constant(constraint, row[1 + nvariables + nparam]);
522 + isl_val *val = cloog_int_to_isl_val(isl_constraint_get_ctx(constraint), row[1 + nvariables + nparam]);
523 + isl_constraint_set_constant_val(constraint, val);
525 return constraint;
527 @@ -631,7 +638,6 @@ CloogDomain *cloog_domain_from_osl_relation(CloogState *state,
528 return domain;
533 * Converts an openscop scattering relation to a CLooG scattering.
534 * \param[in,out] state CLooG state.
535 @@ -779,10 +785,22 @@ int cloog_domain_is_otl(CloogDomain *domain, int level)
536 void cloog_domain_stride(CloogDomain *domain, int strided_level,
537 cloog_int_t *stride, cloog_int_t *offset)
539 + int ret = -1;
540 isl_set *set = isl_set_from_cloog_domain(domain);
541 - isl_set_dim_residue_class(set, strided_level - 1, stride, offset);
542 - if (!isl_int_is_zero(*offset))
543 - isl_int_sub(*offset, *stride, *offset);
544 + isl_val *stride_val = NULL;
545 + isl_val *offset_val = NULL;
546 + ret = isl_set_dim_residue_class_val(set, strided_level - 1, &stride_val, &offset_val);
547 + if (ret != 0)
548 + cloog_die("failure to compute stride.\n");
549 + isl_val_to_cloog_int(stride_val, stride);
550 + isl_val_to_cloog_int(offset_val, offset);
552 + if (!cloog_int_is_zero(*offset))
553 + cloog_int_sub(*offset, *stride, *offset);
555 + isl_val_free(stride_val);
556 + isl_val_free(offset_val);
558 return;
561 @@ -796,7 +814,7 @@ static int constraint_can_stride(__isl_take isl_constraint *c, void *user)
563 struct cloog_can_stride *ccs = (struct cloog_can_stride *)user;
564 int i;
565 - isl_int v;
566 + isl_val *v;
567 unsigned n_div;
569 if (isl_constraint_is_equality(c)) {
570 @@ -804,21 +822,22 @@ static int constraint_can_stride(__isl_take isl_constraint *c, void *user)
571 return 0;
574 - isl_int_init(v);
575 - isl_constraint_get_coefficient(c, isl_dim_set, ccs->level - 1, &v);
576 - if (isl_int_is_pos(v)) {
577 + v = isl_constraint_get_coefficient_val(c, isl_dim_set, ccs->level - 1);
578 + if (isl_val_is_pos(v)) {
579 n_div = isl_constraint_dim(c, isl_dim_div);
581 for (i = 0; i < n_div; ++i) {
582 - isl_constraint_get_coefficient(c, isl_dim_div, i, &v);
583 - if (!isl_int_is_zero(v))
584 + isl_val_free(v);
585 + v = isl_constraint_get_coefficient_val(c, isl_dim_div, i);
586 + if (!isl_val_is_zero(v))
587 break;
589 if (i < n_div)
590 ccs->can_stride = 0;
592 - isl_int_clear(v);
593 - isl_constraint_free(c);
594 + isl_val_free(v);
596 + isl_constraint_free(c);
597 return 0;
600 @@ -903,7 +922,7 @@ struct cloog_stride_lower {
601 static int constraint_stride_lower(__isl_take isl_constraint *c, void *user)
603 struct cloog_stride_lower *csl = (struct cloog_stride_lower *)user;
604 - isl_int v;
605 + isl_val *v;
606 isl_constraint *bound;
607 isl_aff *b;
609 @@ -912,31 +931,31 @@ static int constraint_stride_lower(__isl_take isl_constraint *c, void *user)
610 return 0;
613 - isl_int_init(v);
614 - isl_constraint_get_coefficient(c, isl_dim_set, csl->level - 1, &v);
615 - if (!isl_int_is_pos(v)) {
616 - isl_int_clear(v);
617 + v = isl_constraint_get_coefficient_val(c, isl_dim_set, csl->level - 1);
618 + if (!isl_val_is_pos(v)) {
619 + isl_val_free(v);
620 isl_constraint_free(c);
622 return 0;
624 + isl_val_free(v);
626 b = isl_constraint_get_bound(c, isl_dim_set, csl->level - 1);
628 b = isl_aff_neg(b);
629 - b = isl_aff_add_constant(b, csl->stride->offset);
630 - b = isl_aff_scale_down(b, csl->stride->stride);
631 + b = isl_aff_add_constant_val(b, cloog_int_to_isl_val(isl_constraint_get_ctx(c), csl->stride->offset));
632 + b = isl_aff_scale_down_val(b, cloog_int_to_isl_val(isl_constraint_get_ctx(c), csl->stride->stride));
633 b = isl_aff_floor(b);
634 - b = isl_aff_scale(b, csl->stride->stride);
635 - isl_int_neg(v, csl->stride->offset);
636 - b = isl_aff_add_constant(b, v);
637 + b = isl_aff_scale_val(b, cloog_int_to_isl_val(isl_constraint_get_ctx(c), csl->stride->stride));
638 + v = cloog_int_to_isl_val(isl_constraint_get_ctx(c), csl->stride->offset);
639 + v = isl_val_neg(v);
640 + b = isl_aff_add_constant_val(b, v);
641 b = isl_aff_add_coefficient_si(b, isl_dim_in, csl->level - 1, 1);
643 bound = isl_inequality_from_aff(b);
645 csl->bounds = isl_basic_set_add_constraint(csl->bounds, bound);
647 - isl_int_clear(v);
648 isl_constraint_free(c);
650 return 0;
651 @@ -960,7 +979,7 @@ static int constraint_stride_lower(__isl_take isl_constraint *c, void *user)
652 static int constraint_stride_lower_c(__isl_take isl_constraint *c, void *user)
654 struct cloog_stride_lower *csl = (struct cloog_stride_lower *)user;
655 - isl_int v;
656 + isl_val *v;
657 isl_constraint *bound;
658 isl_constraint *csl_c;
659 isl_aff *d, *b;
660 @@ -970,10 +989,9 @@ static int constraint_stride_lower_c(__isl_take isl_constraint *c, void *user)
661 return 0;
664 - isl_int_init(v);
665 - isl_constraint_get_coefficient(c, isl_dim_set, csl->level - 1, &v);
666 - if (!isl_int_is_pos(v)) {
667 - isl_int_clear(v);
668 + v = isl_constraint_get_coefficient_val(c, isl_dim_set, csl->level - 1);
669 + if (!isl_val_is_pos(v)) {
670 + isl_val_free(v);
671 isl_constraint_free(c);
673 return 0;
674 @@ -984,15 +1002,15 @@ static int constraint_stride_lower_c(__isl_take isl_constraint *c, void *user)
675 d = isl_constraint_get_aff(csl_c);
676 d = isl_aff_drop_dims(d, isl_dim_div, 0, isl_aff_dim(d, isl_dim_div));
677 d = isl_aff_set_coefficient_si(d, isl_dim_in, csl->level - 1, 0);
678 - d = isl_aff_scale(d, csl->stride->factor);
679 + d = isl_aff_scale_val(d, cloog_int_to_isl_val(isl_constraint_get_ctx(csl_c), csl->stride->factor));
681 b = isl_constraint_get_bound(c, isl_dim_set, csl->level - 1);
683 b = isl_aff_neg(b);
684 b = isl_aff_add(b, isl_aff_copy(d));
685 - b = isl_aff_scale_down(b, csl->stride->stride);
686 + b = isl_aff_scale_down_val(b, cloog_int_to_isl_val(isl_constraint_get_ctx(csl_c), csl->stride->stride));
687 b = isl_aff_floor(b);
688 - b = isl_aff_scale(b, csl->stride->stride);
689 + b = isl_aff_scale_val(b, cloog_int_to_isl_val(isl_constraint_get_ctx(csl_c), csl->stride->stride));
690 b = isl_aff_sub(b, d);
691 b = isl_aff_add_coefficient_si(b, isl_dim_in, csl->level - 1, 1);
693 @@ -1000,7 +1018,7 @@ static int constraint_stride_lower_c(__isl_take isl_constraint *c, void *user)
695 csl->bounds = isl_basic_set_add_constraint(csl->bounds, bound);
697 - isl_int_clear(v);
698 + isl_val_free(v);
699 isl_constraint_free(c);
701 return 0;
702 @@ -1090,28 +1108,30 @@ struct cloog_bound_split {
703 static int constraint_bound_split(__isl_take isl_constraint *c, void *user)
705 struct cloog_bound_split *cbs = (struct cloog_bound_split *)user;
706 - isl_int v;
707 + isl_val *v;
708 int i;
709 int handle = 0;
711 - isl_int_init(v);
712 - isl_constraint_get_coefficient(c, isl_dim_set, cbs->level - 1, &v);
713 - if (!cbs->lower && isl_int_is_pos(v))
714 + v = isl_constraint_get_coefficient_val(c, isl_dim_set, cbs->level - 1);
715 + if (!cbs->lower && isl_val_is_pos(v))
716 cbs->lower = handle = 1;
717 - else if (!cbs->upper && isl_int_is_neg(v))
718 + else if (!cbs->upper && isl_val_is_neg(v))
719 cbs->upper = handle = 1;
721 if (handle) {
722 for (i = 0; i < isl_set_dim(cbs->set, isl_dim_param); ++i) {
723 - isl_constraint_get_coefficient(c, isl_dim_param, i, &v);
724 - if (isl_int_is_zero(v))
725 + isl_val_free(v);
726 + v = isl_constraint_get_coefficient_val(c, isl_dim_param, i);
727 + if (isl_val_is_zero(v))
728 continue;
730 cbs->set = isl_set_split_dims(cbs->set,
731 isl_dim_param, i, 1);
734 - isl_int_clear(v);
735 - isl_constraint_free(c);
736 + isl_val_free(v);
738 + isl_constraint_free(c);
739 return (cbs->lower && cbs->upper) ? -1 : 0;
742 @@ -1203,7 +1223,7 @@ static int injective_scattering(CloogScatteringList *list)
743 * - scattdims is the total number of scattering dimentions.
745 int cloog_scattering_lazy_block(CloogScattering *s1, CloogScattering *s2,
746 - CloogScatteringList *scattering, int scattdims)
747 + CloogScatteringList *scattering, int scattdims)
749 int i;
750 struct isl_space *dim;
751 @@ -1211,8 +1231,8 @@ int cloog_scattering_lazy_block(CloogScattering *s1, CloogScattering *s2,
752 struct isl_set *delta;
753 isl_map *map1 = isl_map_from_cloog_scattering(s1);
754 isl_map *map2 = isl_map_from_cloog_scattering(s2);
755 - int fixed, block;
756 - isl_int cst;
757 + int block;
758 + isl_val *cst;
759 unsigned n_scat;
761 n_scat = isl_map_dim(map1, isl_dim_out);
762 @@ -1225,22 +1245,33 @@ int cloog_scattering_lazy_block(CloogScattering *s1, CloogScattering *s2,
763 rel = isl_map_apply_domain(rel, isl_map_copy(map1));
764 rel = isl_map_apply_range(rel, isl_map_copy(map2));
765 delta = isl_map_deltas(rel);
766 - isl_int_init(cst);
767 + cst = NULL;
768 for (i = 0; i < n_scat; ++i) {
769 - fixed = isl_set_fast_dim_is_fixed(delta, i, &cst);
770 - if (fixed != 1)
771 + cst = isl_set_plain_get_val_if_fixed(delta, isl_dim_set, i);
772 + if (!cst){
773 + isl_val_free(cst);
774 break;
775 - if (isl_int_is_zero(cst))
777 + if (isl_val_is_zero(cst)){
778 + isl_val_free(cst);
779 continue;
780 - if (i + 1 < n_scat)
782 + if (i + 1 < n_scat){
783 + isl_val_free(cst);
784 break;
785 - if (!isl_int_is_one(cst))
787 + if (!isl_val_is_one(cst)){
788 + isl_val_free(cst);
789 break;
790 - if (!injective_scattering(scattering))
792 + if (!injective_scattering(scattering)){
793 + isl_val_free(cst);
794 break;
797 + isl_val_free(cst);
799 block = i >= n_scat;
800 - isl_int_clear(cst);
801 isl_set_free(delta);
802 return block;
804 @@ -1345,10 +1376,25 @@ CloogDomain *cloog_domain_simplify_union(CloogDomain *domain)
805 * If value is not NULL, then it is set to the constant value of dimension.
807 int cloog_scattering_lazy_isscalar(CloogScattering *scatt, int dimension,
808 - cloog_int_t *value)
809 + cloog_int_t *value)
811 isl_map *map = isl_map_from_cloog_scattering(scatt);
812 - return isl_map_fast_is_fixed(map, isl_dim_out, dimension, value);
813 + isl_val *v = isl_map_plain_get_val_if_fixed(map, isl_dim_out, dimension);
814 + if (v != NULL) {
815 + if (!isl_val_is_nan(v)){
816 + if (value != NULL)
817 + isl_val_to_cloog_int(v, value);
819 + isl_val_free(v);
820 + return 1;
822 + else {
823 + isl_val_free(v);
824 + return 0;
828 + return 0;
832 @@ -1362,7 +1408,22 @@ int cloog_domain_lazy_isconstant(CloogDomain *domain, int dimension,
833 cloog_int_t *value)
835 isl_set *set = isl_set_from_cloog_domain(domain);
836 - return isl_set_fast_dim_is_fixed(set, dimension, value);
837 + isl_val *cst = isl_set_plain_get_val_if_fixed(set, isl_dim_set, dimension);
838 + if (cst != NULL) {
839 + if (!isl_val_is_nan(cst)){
840 + if (value != NULL)
841 + isl_val_to_cloog_int(cst, value);
843 + isl_val_free(cst);
844 + return 1;
846 + else {
847 + isl_val_free(cst);
848 + return 0;
852 + return 0;
856 @@ -1391,6 +1452,8 @@ CloogDomain *cloog_domain_cube(CloogState *state,
857 int i;
858 isl_space *space;
859 isl_set *cube;
860 + isl_val *min_v;
861 + isl_val *max_v;
863 if (dim == 0)
864 return cloog_domain_universe(state, dim);
865 @@ -1398,8 +1461,10 @@ CloogDomain *cloog_domain_cube(CloogState *state,
866 space = isl_space_set_alloc(state->backend->ctx, 0, dim);
867 cube = isl_set_universe(space);
868 for (i = 0; i < dim; ++i) {
869 - cube = isl_set_lower_bound(cube, isl_dim_set, i, min);
870 - cube = isl_set_upper_bound(cube, isl_dim_set, i, max);
871 + min_v = cloog_int_to_isl_val(isl_set_get_ctx(cube), min);
872 + max_v = cloog_int_to_isl_val(isl_set_get_ctx(cube), max);
873 + cube = isl_set_lower_bound_val(cube, isl_dim_set, i, min_v);
874 + cube = isl_set_upper_bound_val(cube, isl_dim_set, i, max_v);
877 return cloog_domain_from_isl_set(cube);
878 @@ -1595,7 +1660,7 @@ static void Euclid(cloog_int_t a, cloog_int_t b,
879 cloog_int_mul(tmp, tmp, d);
880 cloog_int_sub(c, c, tmp);
881 cloog_int_swap(c, d);
882 - cloog_int_swap(e, f);
883 + cloog_int_swap(e, f);
885 cloog_int_set(*g, c);
886 if (cloog_int_is_zero(a))
887 @@ -1631,49 +1696,70 @@ static void Euclid(cloog_int_t a, cloog_int_t b,
888 static CloogStride *construct_stride(isl_constraint *c, int level)
890 int i, n, sign;
891 - isl_int v, m, gcd, stride, factor;
892 + isl_val *v, *m, *gcd, *stride;
893 + isl_val *v_copy, *m_copy, *gcd_copy;
894 + cloog_int_t c_v, c_m, c_gcd, c_stride, c_factor;
895 CloogStride *s;
896 + isl_ctx *ctx = isl_constraint_get_ctx(c);;
898 if (!c)
899 return NULL;
901 - isl_int_init(v);
902 - isl_int_init(m);
903 - isl_int_init(gcd);
904 - isl_int_init(factor);
905 - isl_int_init(stride);
906 + v = isl_constraint_get_coefficient_val(c, isl_dim_set, level - 1);
908 - isl_constraint_get_coefficient(c, isl_dim_set, level - 1, &v);
909 - sign = isl_int_sgn(v);
910 - isl_int_abs(m, v);
911 + sign = isl_val_sgn(v);
912 + m = isl_val_abs(v); /* *takes* v. */
914 - isl_int_set_si(gcd, 0);
915 + gcd = isl_val_int_from_si(ctx, 0);
916 n = isl_constraint_dim(c, isl_dim_div);
917 for (i = 0; i < n; ++i) {
918 - isl_constraint_get_coefficient(c, isl_dim_div, i, &v);
919 - isl_int_gcd(gcd, gcd, v);
920 + v = isl_constraint_get_coefficient_val(c, isl_dim_div, i);
921 + gcd = isl_val_gcd(gcd, v);
924 - isl_int_gcd(v, m, gcd);
925 - isl_int_divexact(stride, gcd, v);
926 + m_copy = isl_val_copy(m);
927 + gcd_copy = isl_val_copy(gcd);
929 - if (isl_int_is_zero(stride) || isl_int_is_one(stride))
930 + v = isl_val_gcd(m, gcd);
932 + v_copy = isl_val_copy(v);
933 + gcd = isl_val_copy(gcd_copy);
934 + stride = isl_val_div(gcd, v);
936 + if (isl_val_is_zero(stride) || isl_val_is_one(stride))
937 s = NULL;
938 else {
939 - Euclid(m, stride, &factor, &v, &gcd);
940 + cloog_int_init(c_m);
941 + cloog_int_init(c_stride);
942 + cloog_int_init(c_v);
943 + cloog_int_init(c_gcd);
944 + cloog_int_init(c_factor);
946 + isl_val_to_cloog_int(m_copy, &c_m);
947 + isl_val_to_cloog_int(stride, &c_stride);
948 + isl_val_to_cloog_int(v_copy, &c_v);
949 + isl_val_to_cloog_int(gcd_copy, &c_gcd);
951 + Euclid(c_m, c_stride, &c_factor, &c_v, &c_gcd);
952 if (sign > 0)
953 - isl_int_neg(factor, factor);
954 + cloog_int_neg(c_factor, c_factor);
956 c = isl_constraint_copy(c);
957 - s = cloog_stride_alloc_from_constraint(stride,
958 - cloog_constraint_from_isl_constraint(c), factor);
959 + s = cloog_stride_alloc_from_constraint(c_stride,
960 + cloog_constraint_from_isl_constraint(c), c_factor);
963 + cloog_int_clear(c_m);
964 + cloog_int_clear(c_stride);
965 + cloog_int_clear(c_v);
966 + cloog_int_clear(c_gcd);
967 + cloog_int_clear(c_factor);
970 - isl_int_clear(stride);
971 - isl_int_clear(factor);
972 - isl_int_clear(gcd);
973 - isl_int_clear(m);
974 - isl_int_clear(v);
975 + isl_val_free(stride);
976 + isl_val_free(gcd_copy);
977 + isl_val_free(m_copy);
978 + isl_val_free(v_copy);
980 return s;
982 @@ -1694,7 +1780,7 @@ static int find_stride(__isl_take isl_constraint *c, void *user)
984 struct cloog_isl_find_stride_data *data;
985 int n;
986 - isl_int v;
987 + isl_val *v;
989 if (!isl_constraint_is_equality(c)) {
990 isl_constraint_free(c);
991 @@ -1714,13 +1800,11 @@ static int find_stride(__isl_take isl_constraint *c, void *user)
992 return 0;
995 - isl_int_init(v);
997 - isl_constraint_get_coefficient(c, isl_dim_set, data->level - 1, &v);
998 - if (!isl_int_is_zero(v))
999 + v = isl_constraint_get_coefficient_val(c, isl_dim_set, data->level - 1);
1000 + if (!isl_val_is_zero(v))
1001 data->stride = construct_stride(c, data->level);
1003 - isl_int_clear(v);
1004 + isl_val_free(v);
1006 isl_constraint_free(c);
1008 @@ -1769,7 +1853,7 @@ struct cloog_can_unroll {
1009 int level;
1010 isl_constraint *c;
1011 isl_set *set;
1012 - isl_int *n;
1013 + isl_val *n;
1017 @@ -1782,11 +1866,11 @@ struct cloog_can_unroll {
1018 * with l the given lower bound and i the iterator identified by level.
1020 static int is_valid_unrolling_lower_bound(struct cloog_can_unroll *ccu,
1021 - __isl_keep isl_constraint *c, isl_int *v)
1022 + __isl_keep isl_constraint *c, isl_val **v)
1024 unsigned n_div;
1025 isl_aff *aff;
1026 - enum isl_lp_result res;
1027 + enum isl_lp_result;
1029 n_div = isl_constraint_dim(c, isl_dim_div);
1030 if (isl_constraint_involves_dims(c, isl_dim_div, 0, n_div))
1031 @@ -1796,15 +1880,19 @@ static int is_valid_unrolling_lower_bound(struct cloog_can_unroll *ccu,
1032 aff = isl_aff_ceil(aff);
1033 aff = isl_aff_neg(aff);
1034 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, ccu->level - 1, 1);
1035 - res = isl_set_max(ccu->set, aff, v);
1036 + *v = isl_set_max_val(ccu->set, aff);
1037 isl_aff_free(aff);
1039 - if (res == isl_lp_unbounded)
1040 - return 0;
1041 + if (!*v || isl_val_is_nan(*v))
1042 + cloog_die("Fail to decide about unrolling (cannot find max)");
1044 - assert(res == isl_lp_ok);
1045 + if (isl_val_is_infty(*v) || isl_val_is_neginfty(*v)){
1046 + isl_val_free(*v);
1047 + *v = NULL;
1048 + return 0;
1051 - cloog_int_add_ui(*v, *v, 1);
1052 + *v = isl_val_add_ui(*v, 1);
1054 return 1;
1056 @@ -1818,21 +1906,21 @@ static int is_valid_unrolling_lower_bound(struct cloog_can_unroll *ccu,
1057 static int constraint_can_unroll(__isl_take isl_constraint *c, void *user)
1059 struct cloog_can_unroll *ccu = (struct cloog_can_unroll *)user;
1060 - isl_int v;
1061 - isl_int count;
1063 - isl_int_init(v);
1064 - isl_int_init(count);
1065 - isl_constraint_get_coefficient(c, isl_dim_set, ccu->level - 1, &v);
1066 - if (isl_int_is_pos(v) &&
1067 - is_valid_unrolling_lower_bound(ccu, c, &count) &&
1068 - (!ccu->c || isl_int_lt(count, *ccu->n))) {
1069 + isl_val *v;
1070 + isl_val *count = NULL;
1072 + v = isl_constraint_get_coefficient_val(c, isl_dim_set, ccu->level - 1);
1073 + if (isl_val_is_pos(v) &&
1074 + is_valid_unrolling_lower_bound(ccu, c, &count) &&
1075 + (!ccu->c || (isl_val_lt(count, ccu->n))) ) {
1076 isl_constraint_free(ccu->c);
1077 ccu->c = isl_constraint_copy(c);
1078 - isl_int_set(*ccu->n, count);
1079 + if (ccu->n)
1080 + isl_val_free(ccu->n);
1081 + ccu->n = isl_val_copy(count);
1083 - isl_int_clear(count);
1084 - isl_int_clear(v);
1085 + isl_val_free(count);
1086 + isl_val_free(v);
1087 isl_constraint_free(c);
1089 return 0;
1090 @@ -1872,7 +1960,8 @@ int cloog_domain_can_unroll(CloogDomain *domain, int level, cloog_int_t *n,
1091 CloogConstraint **lb)
1093 isl_set *set = isl_set_from_cloog_domain(domain);
1094 - struct cloog_can_unroll ccu = { 1, level, NULL, set, n };
1095 + isl_val *v = cloog_int_to_isl_val(isl_set_get_ctx(set), *n);
1096 + struct cloog_can_unroll ccu = { 1, level, NULL, set, v };
1097 int r;
1099 *lb = NULL;
1100 @@ -1887,6 +1976,11 @@ int cloog_domain_can_unroll(CloogDomain *domain, int level, cloog_int_t *n,
1102 *lb = cloog_constraint_from_isl_constraint(ccu.c);
1104 + isl_val_to_cloog_int(ccu.n, n);
1105 + /* Note: we have to free ccu.n and not v because v has been
1106 + * freed and replaced in ccu during isl_set_foreach_basic_set
1107 + */
1108 + isl_val_free(ccu.n);
1109 return ccu.can_unroll;
1112 @@ -1904,6 +1998,7 @@ CloogDomain *cloog_domain_fixed_offset(CloogDomain *domain,
1114 isl_aff *aff;
1115 isl_set *set = isl_set_from_cloog_domain(domain);
1116 + isl_ctx *ctx = isl_set_get_ctx(set);
1117 isl_constraint *c;
1118 isl_constraint *eq;
1120 @@ -1911,7 +2006,7 @@ CloogDomain *cloog_domain_fixed_offset(CloogDomain *domain,
1121 aff = isl_constraint_get_bound(c, isl_dim_set, level - 1);
1122 aff = isl_aff_ceil(aff);
1123 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, level - 1, -1);
1124 - aff = isl_aff_add_constant(aff, offset);
1125 + aff = isl_aff_add_constant_val(aff, cloog_int_to_isl_val(ctx, offset));
1126 eq = isl_equality_from_aff(aff);
1127 set = isl_set_add_constraint(set, eq);
1129 diff --git a/test/reservoir/QR.c b/test/reservoir/QR.c
1130 index 8818d9f..1a47f0a 100644
1131 --- a/test/reservoir/QR.c
1132 +++ b/test/reservoir/QR.c
1133 @@ -1,6 +1,12 @@
1134 /* Generated from ./reservoir/QR.cloog by CLooG 0.18.1-2-g43fc508 gmp bits in 0.07s. */
1135 if (N >= 1) {
1136 S1(0) ;
1137 + if ((M <= 0) && (N >= 2)) {
1138 + S3(0);
1139 + S10(0);
1140 + S1(1);
1141 + S5(0);
1143 if ((M >= 1) && (N == 1)) {
1144 for (c4=0;c4<=M-1;c4++) {
1145 S2(0,c4) ;
1146 @@ -29,12 +35,6 @@ if (N >= 1) {
1147 S1(1) ;
1148 S5(0) ;
1150 - if ((M <= 0) && (N >= 2)) {
1151 - S3(0) ;
1152 - S10(0) ;
1153 - S1(1) ;
1154 - S5(0) ;
1156 for (c2=2;c2<=min(M,N-1);c2++) {
1157 for (c4=c2-1;c4<=N-1;c4++) {
1158 S6((c2-2),c4);