From 4b57f9d6660b240312365704dc2d2bb8e0392dce Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 28 Jun 2011 23:31:59 +0200 Subject: [PATCH] add isl_local_space_insert_dims Signed-off-by: Sven Verdoolaege --- doc/user.pod | 3 +++ include/isl/local_space.h | 3 +++ isl_local_space.c | 60 ++++++++++++++++++++++++++++++----------------- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/doc/user.pod b/doc/user.pod index 647adcd3..32be3713 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -626,6 +626,9 @@ using the following functions. __isl_give isl_local_space *isl_local_space_add_dims( __isl_take isl_local_space *ls, enum isl_dim_type type, unsigned n); + __isl_give isl_local_space *isl_local_space_insert_dims( + __isl_take isl_local_space *ls, + enum isl_dim_type type, unsigned first, unsigned n); __isl_give isl_local_space *isl_local_space_drop_dims( __isl_take isl_local_space *ls, enum isl_dim_type type, unsigned first, unsigned n); diff --git a/include/isl/local_space.h b/include/isl/local_space.h index 46368717..3faa0416 100644 --- a/include/isl/local_space.h +++ b/include/isl/local_space.h @@ -37,6 +37,9 @@ __isl_give isl_local_space *isl_local_space_add_dims( __isl_give isl_local_space *isl_local_space_drop_dims( __isl_take isl_local_space *ls, enum isl_dim_type type, unsigned first, unsigned n); +__isl_give isl_local_space *isl_local_space_insert_dims( + __isl_take isl_local_space *ls, + enum isl_dim_type type, unsigned first, unsigned n); int isl_local_space_is_equal(__isl_keep isl_local_space *ls1, __isl_keep isl_local_space *ls2); diff --git a/isl_local_space.c b/isl_local_space.c index 8a6b9193..a57b31eb 100644 --- a/isl_local_space.c +++ b/isl_local_space.c @@ -373,30 +373,10 @@ __isl_give isl_local_space *isl_local_space_add_dims( { int pos; - if (n == 0) - return ls; - - ls = isl_local_space_cow(ls); if (!ls) return NULL; - - pos = isl_local_space_offset(ls, type); - pos += isl_local_space_dim(ls, type); - - ls->div = isl_mat_insert_zero_cols(ls->div, 1 + pos, n); - - if (type == isl_dim_div) { - ls->div = isl_mat_add_zero_rows(ls->div, n); - } else { - ls->dim = isl_dim_add(ls->dim, type, n); - if (!ls->dim) - return isl_local_space_free(ls); - } - - if (!ls->div) - return isl_local_space_free(ls); - - return ls; + pos = isl_local_space_dim(ls, type); + return isl_local_space_insert_dims(ls, type, pos, n); } /* Remove common factor of non-constant terms and denominator. @@ -507,3 +487,39 @@ __isl_give isl_local_space *isl_local_space_drop_dims( return ls; } + +__isl_give isl_local_space *isl_local_space_insert_dims( + __isl_take isl_local_space *ls, + enum isl_dim_type type, unsigned first, unsigned n) +{ + isl_ctx *ctx; + + if (!ls) + return NULL; + if (n == 0 && !isl_local_space_is_named_or_nested(ls, type)) + return ls; + + ctx = isl_local_space_get_ctx(ls); + if (first > isl_local_space_dim(ls, type)) + isl_die(ctx, isl_error_invalid, "position out of bounds", + return isl_local_space_free(ls)); + + ls = isl_local_space_cow(ls); + if (!ls) + return NULL; + + if (type == isl_dim_div) { + ls->div = isl_mat_insert_zero_rows(ls->div, first, n); + } else { + ls->dim = isl_dim_insert(ls->dim, type, first, n); + if (!ls->dim) + return isl_local_space_free(ls); + } + + first += 1 + isl_local_space_offset(ls, type); + ls->div = isl_mat_insert_zero_cols(ls->div, first, n); + if (!ls->div) + return isl_local_space_free(ls); + + return ls; +} -- 2.11.4.GIT