From 022d4b951afc3c4a17fcfbcb884026afe22d510b Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 27 Feb 2012 11:53:54 +0100 Subject: [PATCH] add isl_space_has_tuple_name Signed-off-by: Sven Verdoolaege --- doc/user.pod | 2 ++ include/isl/space.h | 2 ++ isl_space.c | 48 +++++++++++++++++++++++++++++++++++++----------- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/doc/user.pod b/doc/user.pod index 4988f64a..b4271516 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -731,6 +731,8 @@ using the following functions. __isl_give isl_space *isl_space_set_tuple_name( __isl_take isl_space *space, enum isl_dim_type type, const char *s); + int isl_space_has_tuple_name(__isl_keep isl_space *space, + enum isl_dim_type type); const char *isl_space_get_tuple_name(__isl_keep isl_space *space, enum isl_dim_type type); diff --git a/include/isl/space.h b/include/isl/space.h index 14746d00..45aee976 100644 --- a/include/isl/space.h +++ b/include/isl/space.h @@ -45,6 +45,8 @@ int isl_space_is_set(__isl_keep isl_space *space); __isl_give isl_space *isl_space_set_tuple_name(__isl_take isl_space *dim, enum isl_dim_type type, const char *s); +int isl_space_has_tuple_name(__isl_keep isl_space *space, + enum isl_dim_type type); const char *isl_space_get_tuple_name(__isl_keep isl_space *dim, enum isl_dim_type type); __isl_give isl_space *isl_space_set_tuple_id(__isl_take isl_space *dim, diff --git a/isl_space.c b/isl_space.c index 0c717240..aae979a3 100644 --- a/isl_space.c +++ b/isl_space.c @@ -360,20 +360,33 @@ static int name_ok(isl_ctx *ctx, const char *s) return 1; } -int isl_space_has_tuple_id(__isl_keep isl_space *dim, enum isl_dim_type type) +/* Is it possible for the given dimension type to have a tuple id? + */ +static int space_can_have_id(__isl_keep isl_space *space, + enum isl_dim_type type) { - if (!dim) - return -1; - if (isl_space_is_params(dim)) - isl_die(dim->ctx, isl_error_invalid, - "parameter spaces don't have tuple ids", return -1); - if (isl_space_is_set(dim) && type != isl_dim_set) - isl_die(dim->ctx, isl_error_invalid, - "set spaces can only have a set id", return -1); + if (!space) + return 0; + if (isl_space_is_params(space)) + isl_die(space->ctx, isl_error_invalid, + "parameter spaces don't have tuple ids", return 0); + if (isl_space_is_set(space) && type != isl_dim_set) + isl_die(space->ctx, isl_error_invalid, + "set spaces can only have a set id", return 0); if (type != isl_dim_in && type != isl_dim_out) - isl_die(dim->ctx, isl_error_invalid, + isl_die(space->ctx, isl_error_invalid, "only input, output and set tuples can have ids", - return -1); + return 0); + + return 1; +} + +/* Does the tuple have an id? + */ +int isl_space_has_tuple_id(__isl_keep isl_space *dim, enum isl_dim_type type) +{ + if (!space_can_have_id(dim, type)) + return -1; return dim->tuple_id[type - isl_dim_in] != NULL; } @@ -508,6 +521,19 @@ error: return NULL; } +/* Does the tuple have a name? + */ +int isl_space_has_tuple_name(__isl_keep isl_space *space, + enum isl_dim_type type) +{ + isl_id *id; + + if (!space_can_have_id(space, type)) + return -1; + id = space->tuple_id[type - isl_dim_in]; + return id && id->name; +} + const char *isl_space_get_tuple_name(__isl_keep isl_space *dim, enum isl_dim_type type) { -- 2.11.4.GIT