[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 04:11:49 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:

> I'll change this in the PR that will use the additional result.

Thinking on this again while looking at the users, could it be cleaner (and possibly easier for a follow-up change) not to expose `CaptureResult` in the public APIs? Meaning that we would just have an additional boolean `/*ReturnCaptures=*/` in getCapturesBefore(), EEA would cache the full CaptureResult and returning a CC, either `Iter.first->second.second.WithRet` or the other depending on the boolean? Not strong on this, possibly just an implementation detail; though, I feel like it would be nice to continue exposing `CaptureComponents` rather than `CaptureResult` (make the whole APIs easier to reason on what is captured).

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


More information about the llvm-commits mailing list