[llvm] r213582 - Match semantics of PointerMayBeCapturedBefore to its name by default

Hal Finkel hfinkel at anl.gov
Mon Jul 21 14:30:22 PDT 2014


Author: hfinkel
Date: Mon Jul 21 16:30:22 2014
New Revision: 213582

URL: http://llvm.org/viewvc/llvm-project?rev=213582&view=rev
Log:
Match semantics of PointerMayBeCapturedBefore to its name by default

As it turns out, the capture tracker named CaptureBefore used by AA, and now
available via the PointerMayBeCapturedBefore function, would have been
more-aptly named CapturedBeforeOrAt, because it considers captures at the
instruction provided. This is not always what one wants, and it is difficult to
get the strictly-before behavior given only the current interface. This adds an
additional parameter which controls whether or not you want to include
captures at the provided instruction. The default is not to include the
instruction provided, so that 'Before' matches its name.

No functionality change intended.

Modified:
    llvm/trunk/include/llvm/Analysis/CaptureTracking.h
    llvm/trunk/lib/Analysis/AliasAnalysis.cpp
    llvm/trunk/lib/Analysis/CaptureTracking.cpp

Modified: llvm/trunk/include/llvm/Analysis/CaptureTracking.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/CaptureTracking.h?rev=213582&r1=213581&r2=213582&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/CaptureTracking.h (original)
+++ llvm/trunk/include/llvm/Analysis/CaptureTracking.h Mon Jul 21 16:30:22 2014
@@ -40,10 +40,11 @@ namespace llvm {
   /// returning the value (or part of it) from the function counts as capturing
   /// it or not.  The boolean StoreCaptures specified whether storing the value
   /// (or part of it) into memory anywhere automatically counts as capturing it
-  /// or not.
+  /// or not. Captures by the provided instruction are considered if the
+  /// final parameter is true.
   bool PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures,
                                   bool StoreCaptures, const Instruction *I,
-                                  DominatorTree *DT);
+                                  DominatorTree *DT, bool IncludeI = false);
 
   /// This callback is used in conjunction with PointerMayBeCaptured. In
   /// addition to the interface here, you'll need to provide your own getters

Modified: llvm/trunk/lib/Analysis/AliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/AliasAnalysis.cpp?rev=213582&r1=213581&r2=213582&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/AliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/AliasAnalysis.cpp Mon Jul 21 16:30:22 2014
@@ -408,7 +408,8 @@ AliasAnalysis::callCapturesBefore(const
     return AliasAnalysis::ModRef;
 
   if (llvm::PointerMayBeCapturedBefore(Object, /* ReturnCaptures */ true,
-                                       /* StoreCaptures */ true, I, DT))
+                                       /* StoreCaptures */ true, I, DT,
+                                       /* include Object */ true))
     return AliasAnalysis::ModRef;
 
   unsigned ArgNo = 0;

Modified: llvm/trunk/lib/Analysis/CaptureTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CaptureTracking.cpp?rev=213582&r1=213581&r2=213582&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CaptureTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/CaptureTracking.cpp Mon Jul 21 16:30:22 2014
@@ -57,14 +57,18 @@ namespace {
   /// Only support the case where the Value is defined in the same basic block
   /// as the given instruction and the use.
   struct CapturesBefore : public CaptureTracker {
-    CapturesBefore(bool ReturnCaptures, const Instruction *I, DominatorTree *DT)
+    CapturesBefore(bool ReturnCaptures, const Instruction *I, DominatorTree *DT,
+                   bool IncludeI)
       : BeforeHere(I), DT(DT), ReturnCaptures(ReturnCaptures),
-        Captured(false) {}
+        IncludeI(IncludeI), Captured(false) {}
 
     void tooManyUses() override { Captured = true; }
 
     bool shouldExplore(const Use *U) override {
       Instruction *I = cast<Instruction>(U->getUser());
+      if (BeforeHere == I && !IncludeI)
+        return false;
+
       BasicBlock *BB = I->getParent();
       // We explore this usage only if the usage can reach "BeforeHere".
       // If use is not reachable from entry, there is no need to explore.
@@ -84,6 +88,9 @@ namespace {
         return false;
 
       Instruction *I = cast<Instruction>(U->getUser());
+      if (BeforeHere == I && !IncludeI)
+        return false;
+
       BasicBlock *BB = I->getParent();
       // Same logic as in shouldExplore.
       if (BeforeHere != I && !DT->isReachableFromEntry(BB))
@@ -99,6 +106,7 @@ namespace {
     DominatorTree *DT;
 
     bool ReturnCaptures;
+    bool IncludeI;
 
     bool Captured;
   };
@@ -138,7 +146,7 @@ bool llvm::PointerMayBeCaptured(const Va
 /// or not.
 bool llvm::PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures,
                                       bool StoreCaptures, const Instruction *I,
-                                      DominatorTree *DT) {
+                                      DominatorTree *DT, bool IncludeI) {
   assert(!isa<GlobalValue>(V) &&
          "It doesn't make sense to ask whether a global is captured.");
 
@@ -148,7 +156,7 @@ bool llvm::PointerMayBeCapturedBefore(co
   // TODO: See comment in PointerMayBeCaptured regarding what could be done
   // with StoreCaptures.
 
-  CapturesBefore CB(ReturnCaptures, I, DT);
+  CapturesBefore CB(ReturnCaptures, I, DT, IncludeI);
   PointerMayBeCaptured(V, &CB);
   return CB.Captured;
 }





More information about the llvm-commits mailing list