X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=isl_constraint.c;h=7a06fa762fb8848b707b18b3614380009c2c1c14;hb=63fb8a7f484648c3caa25351c8c94ac2395ec563;hp=68971b3db9b4fc5dadd28c9e02bd3cbf708320d0;hpb=84da31deb7d751f5ca0b5b4626955e8a6ba12418;p=platform%2Fupstream%2Fisl.git diff --git a/isl_constraint.c b/isl_constraint.c index 68971b3..7a06fa7 100644 --- a/isl_constraint.c +++ b/isl_constraint.c @@ -2,7 +2,7 @@ * Copyright 2008-2009 Katholieke Universiteit Leuven * Copyright 2010 INRIA Saclay * - * Use of this software is governed by the GNU LGPLv2.1 license + * Use of this software is governed by the MIT license * * Written by Sven Verdoolaege, K.U.Leuven, Departement * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium @@ -16,6 +16,12 @@ #include #include #include +#include + +#undef BASE +#define BASE constraint + +#include isl_ctx *isl_constraint_get_ctx(__isl_keep isl_constraint *c) { @@ -303,6 +309,12 @@ __isl_give isl_space *isl_constraint_get_space( return constraint ? isl_local_space_get_space(constraint->ls) : NULL; } +__isl_give isl_local_space *isl_constraint_get_local_space( + __isl_keep isl_constraint *constraint) +{ + return constraint ? isl_local_space_copy(constraint->ls) : NULL; +} + int isl_constraint_dim(struct isl_constraint *constraint, enum isl_dim_type type) { @@ -349,6 +361,40 @@ error: return -1; } +/* Does the given constraint represent a lower bound on the given + * dimension? + */ +int isl_constraint_is_lower_bound(__isl_keep isl_constraint *constraint, + enum isl_dim_type type, unsigned pos) +{ + if (!constraint) + return -1; + + if (pos >= isl_local_space_dim(constraint->ls, type)) + isl_die(isl_constraint_get_ctx(constraint), isl_error_invalid, + "position out of bounds", return -1); + + pos += isl_local_space_offset(constraint->ls, type); + return isl_int_is_pos(constraint->v->el[pos]); +} + +/* Does the given constraint represent an upper bound on the given + * dimension? + */ +int isl_constraint_is_upper_bound(__isl_keep isl_constraint *constraint, + enum isl_dim_type type, unsigned pos) +{ + if (!constraint) + return -1; + + if (pos >= isl_local_space_dim(constraint->ls, type)) + isl_die(isl_constraint_get_ctx(constraint), isl_error_invalid, + "position out of bounds", return -1); + + pos += isl_local_space_offset(constraint->ls, type); + return isl_int_is_neg(constraint->v->el[pos]); +} + const char *isl_constraint_get_dim_name(__isl_keep isl_constraint *constraint, enum isl_dim_type type, unsigned pos) { @@ -363,6 +409,20 @@ void isl_constraint_get_constant(struct isl_constraint *constraint, isl_int *v) isl_int_set(*v, constraint->v->el[0]); } +/* Return the constant term of "constraint". + */ +__isl_give isl_val *isl_constraint_get_constant_val( + __isl_keep isl_constraint *constraint) +{ + isl_ctx *ctx; + + if (!constraint) + return NULL; + + ctx = isl_constraint_get_ctx(constraint); + return isl_val_int_from_isl_int(ctx, constraint->v->el[0]); +} + void isl_constraint_get_coefficient(struct isl_constraint *constraint, enum isl_dim_type type, int pos, isl_int *v) { @@ -377,6 +437,26 @@ void isl_constraint_get_coefficient(struct isl_constraint *constraint, isl_int_set(*v, constraint->v->el[pos]); } +/* Return the coefficient of the variable of type "type" at position "pos" + * of "constraint". + */ +__isl_give isl_val *isl_constraint_get_coefficient_val( + __isl_keep isl_constraint *constraint, enum isl_dim_type type, int pos) +{ + isl_ctx *ctx; + + if (!constraint) + return NULL; + + ctx = isl_constraint_get_ctx(constraint); + if (pos < 0 || pos >= isl_local_space_dim(constraint->ls, type)) + isl_die(ctx, isl_error_invalid, + "position out of bounds", return NULL); + + pos += isl_local_space_offset(constraint->ls, type); + return isl_val_int_from_isl_int(ctx, constraint->v->el[pos]); +} + __isl_give isl_aff *isl_constraint_get_div(__isl_keep isl_constraint *constraint, int pos) { @@ -401,6 +481,26 @@ __isl_give isl_constraint *isl_constraint_set_constant( return constraint; } +/* Replace the constant term of "constraint" by "v". + */ +__isl_give isl_constraint *isl_constraint_set_constant_val( + __isl_take isl_constraint *constraint, __isl_take isl_val *v) +{ + constraint = isl_constraint_cow(constraint); + if (!constraint || !v) + goto error; + if (!isl_val_is_int(v)) + isl_die(isl_constraint_get_ctx(constraint), isl_error_invalid, + "expecting integer value", goto error); + constraint->v = isl_vec_set_element_val(constraint->v, 0, v); + if (!constraint->v) + constraint = isl_constraint_free(constraint); + return constraint; +error: + isl_val_free(v); + return isl_constraint_free(constraint); +} + __isl_give isl_constraint *isl_constraint_set_constant_si( __isl_take isl_constraint *constraint, int v) { @@ -443,6 +543,34 @@ __isl_give isl_constraint *isl_constraint_set_coefficient( return constraint; } +/* Replace the coefficient of the variable of type "type" at position "pos" + * of "constraint" by "v". + */ +__isl_give isl_constraint *isl_constraint_set_coefficient_val( + __isl_take isl_constraint *constraint, + enum isl_dim_type type, int pos, isl_val *v) +{ + constraint = isl_constraint_cow(constraint); + if (!constraint || !v) + goto error; + if (!isl_val_is_int(v)) + isl_die(isl_constraint_get_ctx(constraint), isl_error_invalid, + "expecting integer value", goto error); + + if (pos >= isl_local_space_dim(constraint->ls, type)) + isl_die(isl_constraint_get_ctx(constraint), isl_error_invalid, + "position out of bounds", goto error); + + pos += isl_local_space_offset(constraint->ls, type); + constraint->v = isl_vec_set_element_val(constraint->v, pos, v); + if (!constraint->v) + constraint = isl_constraint_free(constraint); + return constraint; +error: + isl_val_free(v); + return isl_constraint_free(constraint); +} + __isl_give isl_constraint *isl_constraint_set_coefficient_si( __isl_take isl_constraint *constraint, enum isl_dim_type type, int pos, int v)