[PATCH] D57627: [BasicAA] Cache nonEscapingLocalObjects for alias() calls.
Alina Sbirlea via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 4 11:40:29 PST 2019
asbirlea updated this revision to Diff 185109.
asbirlea marked 4 inline comments as done.
asbirlea added a comment.
Address comments.
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57627/new/
https://reviews.llvm.org/D57627
Files:
include/llvm/Analysis/BasicAliasAnalysis.h
lib/Analysis/BasicAliasAnalysis.cpp
Index: lib/Analysis/BasicAliasAnalysis.cpp
===================================================================
--- lib/Analysis/BasicAliasAnalysis.cpp
+++ lib/Analysis/BasicAliasAnalysis.cpp
@@ -116,26 +116,44 @@
/// Returns true if the pointer is to a function-local object that never
/// escapes from the function.
-static bool isNonEscapingLocalObject(const Value *V) {
+static bool isNonEscapingLocalObject(
+ const Value *V,
+ SmallDenseMap<const Value *, bool, 8> *IsCapturedCache = nullptr) {
+ if (IsCapturedCache) {
+ auto CacheIt = IsCapturedCache->find(V);
+ if (CacheIt != IsCapturedCache->end())
+ return CacheIt->second;
+ }
+
// If this is a local allocation, check to see if it escapes.
- if (isa<AllocaInst>(V) || isNoAliasCall(V))
+ if (isa<AllocaInst>(V) || isNoAliasCall(V)) {
// Set StoreCaptures to True so that we can assume in our callers that the
// pointer is not the result of a load instruction. Currently
// PointerMayBeCaptured doesn't have any special analysis for the
// StoreCaptures=false case; if it did, our callers could be refined to be
// more precise.
- return !PointerMayBeCaptured(V, false, /*StoreCaptures=*/true);
+ auto Ret = !PointerMayBeCaptured(V, false, /*StoreCaptures=*/true);
+ if (IsCapturedCache)
+ IsCapturedCache->insert({V, Ret});
+ return Ret;
+ }
// If this is an argument that corresponds to a byval or noalias argument,
// then it has not escaped before entering the function. Check if it escapes
// inside the function.
if (const Argument *A = dyn_cast<Argument>(V))
- if (A->hasByValAttr() || A->hasNoAliasAttr())
+ if (A->hasByValAttr() || A->hasNoAliasAttr()) {
// Note even if the argument is marked nocapture, we still need to check
// for copies made inside the function. The nocapture attribute only
// specifies that there are no copies made that outlive the function.
- return !PointerMayBeCaptured(V, false, /*StoreCaptures=*/true);
+ auto Ret = !PointerMayBeCaptured(V, false, /*StoreCaptures=*/true);
+ if (IsCapturedCache)
+ IsCapturedCache->insert({V, Ret});
+ return Ret;
+ }
+ if (IsCapturedCache)
+ IsCapturedCache->insert({V, false});
return false;
}
@@ -816,6 +834,7 @@
// SmallDenseMap if it ever grows larger.
// FIXME: This should really be shrink_to_inline_capacity_and_clear().
AliasCache.shrink_and_clear();
+ IsCapturedCache.shrink_and_clear();
VisitedPhiBBs.clear();
return Alias;
}
@@ -1754,9 +1773,9 @@
// temporary store the nocapture argument's value in a temporary memory
// location if that memory location doesn't escape. Or it may pass a
// nocapture value to other functions as long as they don't capture it.
- if (isEscapeSource(O1) && isNonEscapingLocalObject(O2))
+ if (isEscapeSource(O1) && isNonEscapingLocalObject(O2, &IsCapturedCache))
return NoAlias;
- if (isEscapeSource(O2) && isNonEscapingLocalObject(O1))
+ if (isEscapeSource(O2) && isNonEscapingLocalObject(O1, &IsCapturedCache))
return NoAlias;
}
Index: include/llvm/Analysis/BasicAliasAnalysis.h
===================================================================
--- include/llvm/Analysis/BasicAliasAnalysis.h
+++ include/llvm/Analysis/BasicAliasAnalysis.h
@@ -144,6 +144,8 @@
using LocPair = std::pair<MemoryLocation, MemoryLocation>;
using AliasCacheTy = SmallDenseMap<LocPair, AliasResult, 8>;
AliasCacheTy AliasCache;
+ using IsCapturedCacheTy = SmallDenseMap<const Value *, bool, 8>;
+ IsCapturedCacheTy IsCapturedCache;
/// Tracks phi nodes we have visited.
///
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57627.185109.patch
Type: text/x-patch
Size: 3669 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190204/b3b7d415/attachment.bin>
More information about the llvm-commits
mailing list