[polly] r256208 - ScopInfo: Polish the implementation of mapToDimension
Tobias Grosser via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 21 14:45:54 PST 2015
Author: grosser
Date: Mon Dec 21 16:45:53 2015
New Revision: 256208
URL: http://llvm.org/viewvc/llvm-project?rev=256208&view=rev
Log:
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.
Modified:
polly/trunk/lib/Analysis/ScopInfo.cpp
Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=256208&r1=256207&r2=256208&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Mon Dec 21 16:45:53 2015
@@ -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(__
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);
+
+ Data = {N, PwAff};
+
+ auto Res = isl_union_set_foreach_set(USet, &mapToDimension_AddSet, &Data);
+
+ assert(Res == isl_stat_ok);
- isl_union_set_free(Domain);
+ isl_union_set_free(USet);
return isl_multi_union_pw_aff_from_union_pw_multi_aff(Data.Res);
}
More information about the llvm-commits
mailing list