From 7b4f3390d2b12878337ab6758ecdeb108a057706 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 24 Sep 2011 11:01:01 +0200 Subject: [PATCH] add isl_space_find_dim_by_name Signed-off-by: Sven Verdoolaege --- doc/user.pod | 4 +++- include/isl/space.h | 2 ++ isl_space.c | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/doc/user.pod b/doc/user.pod index f9522fa2..675d8a9a 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -634,12 +634,14 @@ arguments may have different parameters (as long as they are named), in which case the result will have as parameters the union of the parameters of the arguments. -Given the identifier of a dimension (typically a parameter), +Given the identifier or name of a dimension (typically a parameter), its position can be obtained from the following function. #include int isl_space_find_dim_by_id(__isl_keep isl_space *space, enum isl_dim_type type, __isl_keep isl_id *id); + int isl_space_find_dim_by_name(__isl_keep isl_space *space, + enum isl_dim_type type, const char *name); The identifiers or names of entire spaces may be set or read off using the following functions. diff --git a/include/isl/space.h b/include/isl/space.h index 77aea980..d3496e0b 100644 --- a/include/isl/space.h +++ b/include/isl/space.h @@ -64,6 +64,8 @@ __isl_give isl_id *isl_space_get_dim_id(__isl_keep isl_space *dim, int isl_space_find_dim_by_id(__isl_keep isl_space *dim, enum isl_dim_type type, __isl_keep isl_id *id); +int isl_space_find_dim_by_name(__isl_keep isl_space *space, + enum isl_dim_type type, const char *name); __isl_give isl_space *isl_space_set_dim_name(__isl_take isl_space *dim, enum isl_dim_type type, unsigned pos, diff --git a/isl_space.c b/isl_space.c index 2b092043..ae68013b 100644 --- a/isl_space.c +++ b/isl_space.c @@ -543,6 +543,26 @@ int isl_space_find_dim_by_id(__isl_keep isl_space *dim, enum isl_dim_type type, return -1; } +int isl_space_find_dim_by_name(__isl_keep isl_space *space, + enum isl_dim_type type, const char *name) +{ + int i; + int offset; + int n; + + if (!space || !name) + return -1; + + offset = isl_space_offset(space, type); + n = isl_space_dim(space, type); + for (i = 0; i < n && offset + i < space->n_id; ++i) + if (space->ids[offset + i]->name && + !strcmp(space->ids[offset + i]->name, name)) + return i; + + return -1; +} + static __isl_keep isl_id *tuple_id(__isl_keep isl_space *dim, enum isl_dim_type type) { -- 2.11.4.GIT