From e99083d6ab70ab8def75e805860c1c866f8e576e Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 6 Apr 2013 13:45:02 +0200 Subject: [PATCH] add isl_constraint_set_coefficient_val Signed-off-by: Sven Verdoolaege --- doc/user.pod | 4 ++++ include/isl/constraint.h | 3 +++ isl_constraint.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/doc/user.pod b/doc/user.pod index a1663573..dea020b6 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -1518,6 +1518,10 @@ using the following functions. __isl_give isl_constraint *isl_constraint_set_coefficient_si( __isl_take isl_constraint *constraint, enum isl_dim_type type, int pos, int 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); __isl_give isl_basic_map *isl_basic_map_add_constraint( __isl_take isl_basic_map *bmap, __isl_take isl_constraint *constraint); diff --git a/include/isl/constraint.h b/include/isl/constraint.h index 86ca763d..0515e912 100644 --- a/include/isl/constraint.h +++ b/include/isl/constraint.h @@ -98,6 +98,9 @@ __isl_give isl_constraint *isl_constraint_set_coefficient( __isl_give isl_constraint *isl_constraint_set_coefficient_si( __isl_take isl_constraint *constraint, enum isl_dim_type type, int pos, int 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); __isl_give isl_aff *isl_constraint_get_div(__isl_keep isl_constraint *constraint, int pos); diff --git a/isl_constraint.c b/isl_constraint.c index 82e8ef79..d72a6fe0 100644 --- a/isl_constraint.c +++ b/isl_constraint.c @@ -508,6 +508,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) -- 2.11.4.GIT