[llvm] [CaptureTracking] Compute results with and without return capture (PR #195857)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Thu May 7 07:14:33 PDT 2026


================
@@ -234,13 +236,13 @@ EarliestEscapeAnalysis::getCapturesBefore(const Value *Object,
 
   auto Iter = EarliestEscapes.try_emplace(Object);
   if (Iter.second) {
-    std::pair<Instruction *, CaptureComponents> EarliestCapture =
-        FindEarliestCapture(Object, *DT.getRoot()->getParent(),
-                            /*ReturnCaptures=*/false, DT,
+    std::pair<Instruction *, CaptureResult> EarliestCapture =
+        FindEarliestCapture(Object, *DT.getRoot()->getParent(), DT,
                             CaptureComponents::Provenance);
     if (EarliestCapture.first)
       Inst2Obj[EarliestCapture.first].push_back(Object);
-    Iter.first->second = EarliestCapture;
+    Iter.first->second = {EarliestCapture.first,
+                          EarliestCapture.second.WithoutRet};
----------------
antoniofrighetto wrote:

Sorry, didn't explain myself clearly. I meant caching `CaptureResult` internally and have a convenience wrapper as the existing `llvm::PointerMayBeCaptured(const Value *V, bool ReturnCaptures, unsigned MaxUsesToExplore)` for users:
```cpp
CaptureComponents llvm::PointerMayBeCaptured(
    const Value *V, bool ReturnCaptures, CaptureComponents Mask,
    function_ref<bool(CaptureComponents)> StopFn,
    unsigned MaxUsesToExplore) {
  CaptureResult Res = PointerMayBeCaptured(V, Mask, StopFn, MaxUsesToExplore);
  return ReturnCaptures ? Res.WithRet : Res.WithoutRet;
}
```

https://github.com/llvm/llvm-project/pull/195857


More information about the llvm-commits mailing list