From e86cc5df44a995c19ff1ed75145186717ce37cb1 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 28 Dec 2017 10:07:39 +0100 Subject: [PATCH] add isl_space_add_param_id This convenience function allows parameters to be added to a space without having to resort to first adding an unnamed parameter and then changing its identifier. Unnamed parameters and changing the names/identifiers of parameters should in general be discouraged. This function will also be used in the next commit. Signed-off-by: Sven Verdoolaege --- doc/user.pod | 10 ++++++++++ include/isl/space.h | 3 +++ isl_space.c | 27 +++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/doc/user.pod b/doc/user.pod index 32d453fd..21bc4eb9 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -1168,6 +1168,16 @@ an C and an C only have parameters. +Additional parameters can be added to a space using the following function. + + #include + __isl_give isl_space *isl_space_add_param_id( + __isl_take isl_space *space, + __isl_take isl_id *id); + +If a parameter with the given identifier already appears in the space, +then it is not added again. + The identifiers or names of the individual dimensions of spaces may be set or read off using the following functions on spaces or objects that live in spaces. diff --git a/include/isl/space.h b/include/isl/space.h index 1a477cdf..fa089e22 100644 --- a/include/isl/space.h +++ b/include/isl/space.h @@ -44,6 +44,9 @@ isl_bool isl_space_is_params(__isl_keep isl_space *space); isl_bool isl_space_is_set(__isl_keep isl_space *space); isl_bool isl_space_is_map(__isl_keep isl_space *space); +__isl_give isl_space *isl_space_add_param_id(__isl_take isl_space *space, + __isl_take isl_id *id); + __isl_give isl_space *isl_space_set_tuple_name(__isl_take isl_space *dim, enum isl_dim_type type, const char *s); isl_bool isl_space_has_tuple_name(__isl_keep isl_space *space, diff --git a/isl_space.c b/isl_space.c index ff4b9aaf..c4682a7e 100644 --- a/isl_space.c +++ b/isl_space.c @@ -985,6 +985,33 @@ error: return NULL; } +/* Add a parameter with identifier "id" to "space", provided + * it does not already appear in "space". + */ +__isl_give isl_space *isl_space_add_param_id(__isl_take isl_space *space, + __isl_take isl_id *id) +{ + int pos; + + if (!space || !id) + goto error; + + if (isl_space_find_dim_by_id(space, isl_dim_param, id) >= 0) { + isl_id_free(id); + return space; + } + + pos = isl_space_dim(space, isl_dim_param); + space = isl_space_add_dims(space, isl_dim_param, 1); + space = isl_space_set_dim_id(space, isl_dim_param, pos, id); + + return space; +error: + isl_space_free(space); + isl_id_free(id); + return NULL; +} + static int valid_dim_type(enum isl_dim_type type) { switch (type) { -- 2.11.4.GIT