[llvm] f63ab18 - [CaptureTracking] Early abort on too many uses (NFCI)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 7 02:55:04 PST 2020


Author: Nikita Popov
Date: 2020-11-07T11:52:08+01:00
New Revision: f63ab188c63be12871da75bfc5801a7fc752769b

URL: https://github.com/llvm/llvm-project/commit/f63ab188c63be12871da75bfc5801a7fc752769b
DIFF: https://github.com/llvm/llvm-project/commit/f63ab188c63be12871da75bfc5801a7fc752769b.diff

LOG: [CaptureTracking] Early abort on too many uses (NFCI)

If there are too many uses, we should directly return -- there's
no point in inspecting the remaining uses in the worklist, as we
have to conservatively assume a capture anyway. This also means
that tooManyUses() gets called exactly once, rather than
potentially many times.

This restores the behavior prior to e9832dfdf366ddffba68164adb6855d17c9f87c1,
where this was accidentally changed while moving the AddUses logic
into a closure, thus making the return a return from the closure
rather than the whole function.

Added: 
    

Modified: 
    llvm/lib/Analysis/CaptureTracking.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/CaptureTracking.cpp b/llvm/lib/Analysis/CaptureTracking.cpp
index ec997f8326f8..6ff7cbc048f2 100644
--- a/llvm/lib/Analysis/CaptureTracking.cpp
+++ b/llvm/lib/Analysis/CaptureTracking.cpp
@@ -240,16 +240,20 @@ void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
     for (const Use &U : V->uses()) {
       // If there are lots of uses, conservatively say that the value
       // is captured to avoid taking too much compile time.
-      if (Count++ >= MaxUsesToExplore)
-        return Tracker->tooManyUses();
+      if (Count++ >= MaxUsesToExplore) {
+        Tracker->tooManyUses();
+        return false;
+      }
       if (!Visited.insert(&U).second)
         continue;
       if (!Tracker->shouldExplore(&U))
         continue;
       Worklist.push_back(&U);
     }
+    return true;
   };
-  AddUses(V);
+  if (!AddUses(V))
+    return;
 
   while (!Worklist.empty()) {
     const Use *U = Worklist.pop_back_val();
@@ -273,7 +277,8 @@ void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
       // in BasicAA also need to know about this property.
       if (isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(Call,
                                                                       true)) {
-        AddUses(Call);
+        if (!AddUses(Call))
+          return;
         break;
       }
 
@@ -346,7 +351,8 @@ void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
     case Instruction::Select:
     case Instruction::AddrSpaceCast:
       // The original value is not captured via this if the new value isn't.
-      AddUses(I);
+      if (!AddUses(I))
+        return;
       break;
     case Instruction::ICmp: {
       unsigned Idx = U->getOperandNo();


        


More information about the llvm-commits mailing list