From cbf7ae8fef4d40248f9b0ff9f2b56546395eebb6 Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Mon, 21 Dec 2015 22:45:53 +0000 Subject: [PATCH] ScopInfo: Polish the implementation of mapToDimension Besides improving the documentation and the code we now assert in case the input is invalid (N < 0) and also do not any more return a nullptr in case USet is empty. This should make the code more readable. llvm-svn: 256208 --- polly/lib/Analysis/ScopInfo.cpp | 52 +++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp index 71c180d..0714c37 100644 --- a/polly/lib/Analysis/ScopInfo.cpp +++ b/polly/lib/Analysis/ScopInfo.cpp @@ -3353,14 +3353,13 @@ struct MapToDimensionDataTy { }; // @brief Create a function that maps the elements of 'Set' to its N-th -// dimension. +// dimension and add it to User->Res. // -// The result is added to 'User->Res'. +// @param Set The input set. +// @param User->N The dimension to map to. +// @param User->Res The isl_union_pw_multi_aff to which to add the result. // -// @param Set The input set. -// @param N The dimension to map to. -// -// @returns Zero if no error occurred, non-zero otherwise. +// @returns isl_stat_ok if no error occured, othewise isl_stat_error. static isl_stat mapToDimension_AddSet(__isl_take isl_set *Set, void *User) { struct MapToDimensionDataTy *Data = (struct MapToDimensionDataTy *)User; int Dim; @@ -3380,28 +3379,41 @@ static isl_stat mapToDimension_AddSet(__isl_take isl_set *Set, void *User) { return isl_stat_ok; } -// @brief Create a function that maps the elements of Domain to their Nth -// dimension. +// @brief Create an isl_multi_union_aff that defines an identity mapping +// from the elements of USet to their N-th dimension. +// +// # Example: +// +// Domain: { A[i,j]; B[i,j,k] } +// N: 1 // -// @param Domain The set of elements to map. +// Resulting Mapping: { {A[i,j] -> [(j)]; B[i,j,k] -> [(j)] } +// +// @param USet A union set describing the elements for which to generate a +// mapping. // @param N The dimension to map to. +// @returns A mapping from USet to its N-th dimension. static __isl_give isl_multi_union_pw_aff * -mapToDimension(__isl_take isl_union_set *Domain, int N) { - if (N <= 0 || isl_union_set_is_empty(Domain)) { - isl_union_set_free(Domain); +mapToDimension(__isl_take isl_union_set *USet, int N) { + assert(N >= 0); + + if (!USet) return nullptr; - } + + assert(!isl_union_set_is_empty(USet)); struct MapToDimensionDataTy Data; - isl_space *Space; - Space = isl_union_set_get_space(Domain); - Data.N = N; - Data.Res = isl_union_pw_multi_aff_empty(Space); - if (isl_union_set_foreach_set(Domain, &mapToDimension_AddSet, &Data) < 0) - Data.Res = isl_union_pw_multi_aff_free(Data.Res); + auto *Space = isl_union_set_get_space(USet); + auto *PwAff = isl_union_pw_multi_aff_empty(Space); - isl_union_set_free(Domain); + Data = {N, PwAff}; + + auto Res = isl_union_set_foreach_set(USet, &mapToDimension_AddSet, &Data); + + assert(Res == isl_stat_ok); + + isl_union_set_free(USet); return isl_multi_union_pw_aff_from_union_pw_multi_aff(Data.Res); } -- 2.7.4