From 06c7a6b91e1d2c260ce8badf1d5eae39c6c9505f Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 13 Jun 2014 21:46:41 +0200 Subject: [PATCH] add isl_union_pw_*_set_dim_name Signed-off-by: Sven Verdoolaege --- doc/user.pod | 15 ++++++++++++ include/isl/aff.h | 4 ++++ include/isl/polynomial.h | 9 +++++++ isl_union_templ.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+) diff --git a/doc/user.pod b/doc/user.pod index f1f82a67..050a2b92 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -1188,6 +1188,11 @@ operations and may not be preserved across those operations. isl_multi_pw_aff_set_dim_name( __isl_take isl_multi_pw_aff *mpa, enum isl_dim_type type, unsigned pos, const char *s); + __isl_give isl_union_pw_multi_aff * + isl_union_pw_multi_aff_set_dim_name( + __isl_take isl_union_pw_multi_aff *upma, + enum isl_dim_type type, unsigned pos, + const char *s); const char *isl_aff_get_dim_name(__isl_keep isl_aff *aff, enum isl_dim_type type, unsigned pos); const char *isl_pw_aff_get_dim_name( @@ -1212,6 +1217,16 @@ operations and may not be preserved across those operations. __isl_take isl_pw_qpolynomial_fold *pwf, enum isl_dim_type type, unsigned pos, const char *s); + __isl_give isl_union_pw_qpolynomial * + isl_union_pw_qpolynomial_set_dim_name( + __isl_take isl_union_pw_qpolynomial *upwqp, + enum isl_dim_type type, unsigned pos, + const char *s); + __isl_give isl_union_pw_qpolynomial_fold * + isl_union_pw_qpolynomial_fold_set_dim_name( + __isl_take isl_union_pw_qpolynomial_fold *upwf, + enum isl_dim_type type, unsigned pos, + const char *s); Note that C returns a pointer to some internal data structure, so the result can only be used while the diff --git a/include/isl/aff.h b/include/isl/aff.h index 0cde4694..eaf1434c 100644 --- a/include/isl/aff.h +++ b/include/isl/aff.h @@ -551,6 +551,10 @@ __isl_give isl_space *isl_union_pw_multi_aff_get_space( unsigned isl_union_pw_multi_aff_dim(__isl_keep isl_union_pw_multi_aff *upma, enum isl_dim_type type); +__isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_set_dim_name( + __isl_take isl_union_pw_multi_aff *upma, + enum isl_dim_type type, unsigned pos, const char *s); + int isl_union_pw_multi_aff_find_dim_by_name( __isl_keep isl_union_pw_multi_aff *upma, enum isl_dim_type type, const char *name); diff --git a/include/isl/polynomial.h b/include/isl/polynomial.h index 7895fa6d..1068da9d 100644 --- a/include/isl/polynomial.h +++ b/include/isl/polynomial.h @@ -503,6 +503,10 @@ __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_subtract_domain( __isl_give isl_space *isl_union_pw_qpolynomial_get_space( __isl_keep isl_union_pw_qpolynomial *upwqp); +__isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_set_dim_name( + __isl_take isl_union_pw_qpolynomial *upwqp, + enum isl_dim_type type, unsigned pos, const char *s); + int isl_union_pw_qpolynomial_find_dim_by_name( __isl_keep isl_union_pw_qpolynomial *upwqp, enum isl_dim_type type, const char *name); @@ -593,6 +597,11 @@ enum isl_fold isl_union_pw_qpolynomial_fold_get_type( __isl_give isl_space *isl_union_pw_qpolynomial_fold_get_space( __isl_keep isl_union_pw_qpolynomial_fold *upwf); +__isl_give isl_union_pw_qpolynomial_fold * +isl_union_pw_qpolynomial_fold_set_dim_name( + __isl_take isl_union_pw_qpolynomial_fold *upwf, + enum isl_dim_type type, unsigned pos, const char *s); + int isl_union_pw_qpolynomial_fold_find_dim_by_name( __isl_keep isl_union_pw_qpolynomial_fold *upwf, enum isl_dim_type type, const char *name); diff --git a/isl_union_templ.c b/isl_union_templ.c index ea7873a2..c73470c6 100644 --- a/isl_union_templ.c +++ b/isl_union_templ.c @@ -1262,6 +1262,67 @@ __isl_give UNION *FN(UNION,drop_dims)( __isl_take UNION *u, return data.res; } +/* Internal data structure for isl_union_*_set_dim_name. + * pos is the position of the parameter that needs to be renamed. + * s is the new name. + * res collects the results. + */ +S(UNION,set_dim_name_data) { + unsigned pos; + const char *s; + + UNION *res; +}; + +/* Change the name of the parameter at position data->pos of "part" to data->s + * and add the result to data->res. + */ +static int FN(UNION,set_dim_name_entry)(__isl_take PART *part, void *user) +{ + S(UNION,set_dim_name_data) *data = user; + + part = FN(PART,set_dim_name)(part, isl_dim_param, data->pos, data->s); + data->res = FN(FN(UNION,add),PARTS)(data->res, part); + if (!data->res) + return -1; + + return 0; +} + +/* Change the name of the parameter at position "pos" to "s". + * That is, type is required to be isl_dim_param. + */ +__isl_give UNION *FN(UNION,set_dim_name)(__isl_take UNION *u, + enum isl_dim_type type, unsigned pos, const char *s) +{ + S(UNION,set_dim_name_data) data = { pos, s }; + isl_space *space; + + if (!u) + return NULL; + + if (type != isl_dim_param) + isl_die(FN(UNION,get_ctx)(u), isl_error_invalid, + "can only set parameter names", + return FN(UNION,free)(u)); + + space = FN(UNION,get_space)(u); + space = isl_space_set_dim_name(space, type, pos, s); +#ifdef HAS_TYPE + data.res = FN(UNION,alloc)(space, u->type, u->table.n); +#else + data.res = FN(UNION,alloc)(space, u->table.n); +#endif + + if (FN(FN(UNION,foreach),PARTS)(u, + &FN(UNION,set_dim_name_entry), &data) < 0) + data.res = FN(UNION,free)(data.res); + + FN(UNION,free)(u); + + return data.res; +} + /* Reset the user pointer on all identifiers of parameters and tuples * of the space of "part" and add the result to *res. */ -- 2.11.4.GIT