[llvm] r327328 - Improve caching scheme in ProvenanceAnalysis.

Michael Zolotukhin via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 12 13:36:25 PDT 2018


Author: mzolotukhin
Date: Mon Mar 12 13:36:25 2018
New Revision: 327328

URL: http://llvm.org/viewvc/llvm-project?rev=327328&view=rev
Log:
Improve caching scheme in ProvenanceAnalysis.

Summary:
ProvenanceAnalysis::related(A, B) currently memoizes its results, and on big
tests the cache grows too large, and we're spending most of the time
growing/looking through DenseMap.

This patch reduces the size of the cache by normalizing keys first: we do that
by calling GetUnderlyingObjCPtr on the input values. The results of
GetUnderlyingObjCPtr are also memoized in a separate cache.

The patch doesn't bring noticable changes to compile time on CTMark, however
significantly helps one of our internal tests.

Reviewers: gottesmm

Subscribers: hiraditya, llvm-commits

Differential Revision: https://reviews.llvm.org/D44270

Modified:
    llvm/trunk/include/llvm/Analysis/ObjCARCAnalysisUtils.h
    llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp
    llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.h

Modified: llvm/trunk/include/llvm/Analysis/ObjCARCAnalysisUtils.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ObjCARCAnalysisUtils.h?rev=327328&r1=327327&r2=327328&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ObjCARCAnalysisUtils.h (original)
+++ llvm/trunk/include/llvm/Analysis/ObjCARCAnalysisUtils.h Mon Mar 12 13:36:25 2018
@@ -86,6 +86,16 @@ inline const Value *GetUnderlyingObjCPtr
   return V;
 }
 
+/// A wrapper for GetUnderlyingObjCPtr used for results memoization.
+inline const Value *
+GetUnderlyingObjCPtrCached(const Value *V, const DataLayout &DL,
+                           DenseMap<const Value *, const Value *> &Cache) {
+  if (auto InCache = Cache.lookup(V))
+    return InCache;
+
+  return Cache[V] = GetUnderlyingObjCPtr(V, DL);
+}
+
 /// The RCIdentity root of a value \p V is a dominating value U for which
 /// retaining or releasing U is equivalent to retaining or releasing V. In other
 /// words, ARC operations on \p V are equivalent to ARC operations on \p U.

Modified: llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp?rev=327328&r1=327327&r2=327328&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp (original)
+++ llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp Mon Mar 12 13:36:25 2018
@@ -115,14 +115,6 @@ static bool IsStoredObjCPointer(const Va
 
 bool ProvenanceAnalysis::relatedCheck(const Value *A, const Value *B,
                                       const DataLayout &DL) {
-  // Skip past provenance pass-throughs.
-  A = GetUnderlyingObjCPtr(A, DL);
-  B = GetUnderlyingObjCPtr(B, DL);
-
-  // Quick check.
-  if (A == B)
-    return true;
-
   // Ask regular AliasAnalysis, for a first approximation.
   switch (AA->alias(A, B)) {
   case NoAlias:
@@ -171,6 +163,13 @@ bool ProvenanceAnalysis::relatedCheck(co
 
 bool ProvenanceAnalysis::related(const Value *A, const Value *B,
                                  const DataLayout &DL) {
+  A = GetUnderlyingObjCPtrCached(A, DL, UnderlyingObjCPtrCache);
+  B = GetUnderlyingObjCPtrCached(B, DL, UnderlyingObjCPtrCache);
+
+  // Quick check.
+  if (A == B)
+    return true;
+
   // Begin by inserting a conservative value into the map. If the insertion
   // fails, we have the answer already. If it succeeds, leave it there until we
   // compute the real answer to guard against recursive queries.

Modified: llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.h?rev=327328&r1=327327&r2=327328&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.h (original)
+++ llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.h Mon Mar 12 13:36:25 2018
@@ -56,6 +56,8 @@ class ProvenanceAnalysis {
 
   CachedResultsTy CachedResults;
 
+  DenseMap<const Value *, const Value *> UnderlyingObjCPtrCache;
+
   bool relatedCheck(const Value *A, const Value *B, const DataLayout &DL);
   bool relatedSelect(const SelectInst *A, const Value *B);
   bool relatedPHI(const PHINode *A, const Value *B);
@@ -73,6 +75,7 @@ public:
 
   void clear() {
     CachedResults.clear();
+    UnderlyingObjCPtrCache.clear();
   }
 };
 




More information about the llvm-commits mailing list