[polly] r252893 - ScopInfo: Use lambda functions to reduce code duplication.
Tobias Grosser via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 12 06:07:09 PST 2015
Author: grosser
Date: Thu Nov 12 08:07:09 2015
New Revision: 252893
URL: http://llvm.org/viewvc/llvm-project?rev=252893&view=rev
Log:
ScopInfo: Use lambda functions to reduce code duplication.
Modified:
polly/trunk/include/polly/ScopInfo.h
polly/trunk/lib/Analysis/ScopInfo.cpp
Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=252893&r1=252892&r2=252893&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Thu Nov 12 08:07:09 2015
@@ -1332,6 +1332,15 @@ private:
Region *R,
DenseMap<Loop *, std::pair<isl_schedule *, unsigned>> &LoopSchedules);
+ /// @brief Collect all memory access relations of a given type.
+ ///
+ /// @param Predicate A predicate function that returns true if an access is
+ /// of a given type.
+ ///
+ /// @returns The set of memory accesses in the scop that match the predicate.
+ __isl_give isl_union_map *
+ getAccessesOfType(std::function<bool(MemoryAccess &)> Predicate);
+
/// @name Helper function for printing the Scop.
///
///{
Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=252893&r1=252892&r2=252893&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Thu Nov 12 08:07:09 2015
@@ -3119,73 +3119,38 @@ __isl_give isl_union_set *Scop::getDomai
return Domain;
}
-__isl_give isl_union_map *Scop::getMustWrites() {
- isl_union_map *Write = isl_union_map_empty(getParamSpace());
+__isl_give isl_union_map *
+Scop::getAccessesOfType(std::function<bool(MemoryAccess &)> Predicate) {
+ isl_union_map *Accesses = isl_union_map_empty(getParamSpace());
for (ScopStmt &Stmt : *this) {
for (MemoryAccess *MA : Stmt) {
- if (!MA->isMustWrite())
+ if (!Predicate(*MA))
continue;
isl_set *Domain = Stmt.getDomain();
isl_map *AccessDomain = MA->getAccessRelation();
AccessDomain = isl_map_intersect_domain(AccessDomain, Domain);
- Write = isl_union_map_add_map(Write, AccessDomain);
+ Accesses = isl_union_map_add_map(Accesses, AccessDomain);
}
}
- return isl_union_map_coalesce(Write);
+ return isl_union_map_coalesce(Accesses);
}
-__isl_give isl_union_map *Scop::getMayWrites() {
- isl_union_map *Write = isl_union_map_empty(getParamSpace());
-
- for (ScopStmt &Stmt : *this) {
- for (MemoryAccess *MA : Stmt) {
- if (!MA->isMayWrite())
- continue;
+__isl_give isl_union_map *Scop::getMustWrites() {
+ return getAccessesOfType([](MemoryAccess &MA) { return MA.isMustWrite(); });
+}
- isl_set *Domain = Stmt.getDomain();
- isl_map *AccessDomain = MA->getAccessRelation();
- AccessDomain = isl_map_intersect_domain(AccessDomain, Domain);
- Write = isl_union_map_add_map(Write, AccessDomain);
- }
- }
- return isl_union_map_coalesce(Write);
+__isl_give isl_union_map *Scop::getMayWrites() {
+ return getAccessesOfType([](MemoryAccess &MA) { return MA.isMayWrite(); });
}
__isl_give isl_union_map *Scop::getWrites() {
- isl_union_map *Write = isl_union_map_empty(getParamSpace());
-
- for (ScopStmt &Stmt : *this) {
- for (MemoryAccess *MA : Stmt) {
- if (!MA->isWrite())
- continue;
-
- isl_set *Domain = Stmt.getDomain();
- isl_map *AccessDomain = MA->getAccessRelation();
- AccessDomain = isl_map_intersect_domain(AccessDomain, Domain);
- Write = isl_union_map_add_map(Write, AccessDomain);
- }
- }
- return isl_union_map_coalesce(Write);
+ return getAccessesOfType([](MemoryAccess &MA) { return MA.isWrite(); });
}
__isl_give isl_union_map *Scop::getReads() {
- isl_union_map *Read = isl_union_map_empty(getParamSpace());
-
- for (ScopStmt &Stmt : *this) {
- for (MemoryAccess *MA : Stmt) {
- if (!MA->isRead())
- continue;
-
- isl_set *Domain = Stmt.getDomain();
- isl_map *AccessDomain = MA->getAccessRelation();
-
- AccessDomain = isl_map_intersect_domain(AccessDomain, Domain);
- Read = isl_union_map_add_map(Read, AccessDomain);
- }
- }
- return isl_union_map_coalesce(Read);
+ return getAccessesOfType([](MemoryAccess &MA) { return MA.isRead(); });
}
__isl_give isl_union_map *Scop::getSchedule() const {
More information about the llvm-commits
mailing list