[llvm-branch-commits] [llvm-branch] r90911 - /llvm/branches/Apple/Zoidberg/lib/Analysis/CaptureTracking.cpp

Dan Gohman gohman at apple.com
Tue Dec 8 16:34:40 PST 2009


Author: djg
Date: Tue Dec  8 18:34:40 2009
New Revision: 90911

URL: http://llvm.org/viewvc/llvm-project?rev=90911&view=rev
Log:
$ svn merge -c 90905 https://djg@llvm.org/svn/llvm-project/llvm/trunk
--- Merging r90905 into '.':
U    lib/Analysis/CaptureTracking.cpp
$ svn merge -c 90910 https://djg@llvm.org/svn/llvm-project/llvm/trunk
--- Merging r90910 into '.':
G    lib/Analysis/CaptureTracking.cpp

Modified:
    llvm/branches/Apple/Zoidberg/lib/Analysis/CaptureTracking.cpp

Modified: llvm/branches/Apple/Zoidberg/lib/Analysis/CaptureTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Zoidberg/lib/Analysis/CaptureTracking.cpp?rev=90911&r1=90910&r2=90911&view=diff

==============================================================================
--- llvm/branches/Apple/Zoidberg/lib/Analysis/CaptureTracking.cpp (original)
+++ llvm/branches/Apple/Zoidberg/lib/Analysis/CaptureTracking.cpp Tue Dec  8 18:34:40 2009
@@ -25,6 +25,16 @@
 #include "llvm/Support/CallSite.h"
 using namespace llvm;
 
+/// As its comment mentions, PointerMayBeCaptured can be expensive.
+/// However, it's not easy for BasicAA to cache the result, because
+/// it's an ImmutablePass. To work around this, bound queries at a
+/// fixed number of uses.
+///
+/// TODO: Write a new FunctionPass AliasAnalysis so that it can keep
+/// a cache. Then we can move the code from BasicAliasAnalysis into
+/// that path, and remove this threshold.
+static int const Threshold = 20;
+
 /// PointerMayBeCaptured - Return true if this pointer value may be captured
 /// by the enclosing function (which is required to exist).  This routine can
 /// be expensive, so consider caching the results.  The boolean ReturnCaptures
@@ -35,11 +45,17 @@
 bool llvm::PointerMayBeCaptured(const Value *V,
                                 bool ReturnCaptures, bool StoreCaptures) {
   assert(isa<PointerType>(V->getType()) && "Capture is for pointers only!");
-  SmallVector<Use*, 16> Worklist;
-  SmallSet<Use*, 16> Visited;
+  SmallVector<Use*, 20> Worklist;
+  SmallSet<Use*, 20> Visited;
+  int Count = 0;
 
   for (Value::use_const_iterator UI = V->use_begin(), UE = V->use_end();
        UI != UE; ++UI) {
+    // If there are lots of uses, conservatively say that the value
+    // is captured to avoid taking too much compile time.
+    if (Count++ >= Threshold)
+      return true;
+
     Use *U = &UI.getUse();
     Visited.insert(U);
     Worklist.push_back(U);





More information about the llvm-branch-commits mailing list