@@ -81,16 +81,15 @@ struct SimpleCaptureTracker : public CaptureTracker {
8181 Captured = true ;
8282 }
8383
84- std::optional<CaptureComponents> captured (const Use *U,
85- CaptureInfo CI) override {
84+ Action captured (const Use *U, CaptureInfo CI) override {
8685 // TODO(captures): Use CaptureInfo.
8786 if (isa<ReturnInst>(U->getUser ()) && !ReturnCaptures)
88- return continueIgnoringReturn () ;
87+ return ContinueIgnoringReturn ;
8988
9089 LLVM_DEBUG (dbgs () << " Captured by: " << *U->getUser () << " \n " );
9190
9291 Captured = true ;
93- return stop () ;
92+ return Stop ;
9493 }
9594
9695 bool ReturnCaptures;
@@ -124,22 +123,21 @@ struct CapturesBefore : public CaptureTracker {
124123 return !isPotentiallyReachable (I, BeforeHere, nullptr , DT, LI);
125124 }
126125
127- std::optional<CaptureComponents> captured (const Use *U,
128- CaptureInfo CI) override {
126+ Action captured (const Use *U, CaptureInfo CI) override {
129127 // TODO(captures): Use CaptureInfo.
130128 Instruction *I = cast<Instruction>(U->getUser ());
131129 if (isa<ReturnInst>(I) && !ReturnCaptures)
132- return continueIgnoringReturn () ;
130+ return ContinueIgnoringReturn ;
133131
134132 // Check isSafeToPrune() here rather than in shouldExplore() to avoid
135133 // an expensive reachability query for every instruction we look at.
136134 // Instead we only do one for actual capturing candidates.
137135 if (isSafeToPrune (I))
138136 // If the use is not reachable, the instruction result isn't either.
139- return continueIgnoringReturn () ;
137+ return ContinueIgnoringReturn ;
140138
141139 Captured = true ;
142- return stop () ;
140+ return Stop ;
143141 }
144142
145143 const Instruction *BeforeHere;
@@ -171,12 +169,11 @@ struct EarliestCaptures : public CaptureTracker {
171169 EarliestCapture = &*F.getEntryBlock ().begin ();
172170 }
173171
174- std::optional<CaptureComponents> captured (const Use *U,
175- CaptureInfo CI) override {
172+ Action captured (const Use *U, CaptureInfo CI) override {
176173 // TODO(captures): Use CaptureInfo.
177174 Instruction *I = cast<Instruction>(U->getUser ());
178175 if (isa<ReturnInst>(I) && !ReturnCaptures)
179- return continueIgnoringReturn () ;
176+ return ContinueIgnoringReturn ;
180177
181178 if (!EarliestCapture)
182179 EarliestCapture = I;
@@ -187,7 +184,7 @@ struct EarliestCaptures : public CaptureTracker {
187184 // Continue analysis, as we need to see all potential captures. However,
188185 // we do not need to follow the instruction result, as this use will
189186 // dominate any captures made through the instruction result..
190- return continueIgnoringReturn () ;
187+ return ContinueIgnoringReturn ;
191188 }
192189
193190 Instruction *EarliestCapture = nullptr ;
@@ -451,17 +448,24 @@ void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
451448 CaptureInfo CI = DetermineUseCaptureKind (*U, IsDereferenceableOrNull);
452449 if (capturesNothing (CI))
453450 continue ;
451+ CaptureComponents OtherCC = CI.getOtherComponents ();
454452 CaptureComponents RetCC = CI.getRetComponents ();
455- if (! capturesNothing (CI. getOtherComponents () )) {
456- std::optional<CaptureComponents> Res = Tracker->captured (U, CI);
457- if (!Res)
453+ if (capturesAnything (OtherCC )) {
454+ switch ( Tracker->captured (U, CI)) {
455+ case CaptureTracker::Stop:
458456 return ;
459- assert (capturesNothing (*Res & ~RetCC) &&
460- " captures() result must be subset of getRetComponents()" );
461- RetCC = *Res;
457+ case CaptureTracker::ContinueIgnoringReturn:
458+ continue ;
459+ case CaptureTracker::Continue:
460+ // Fall through to passthrough handling, but only if RetCC contains
461+ // additional components that OtherCC does not.
462+ if (capturesNothing (RetCC & ~OtherCC))
463+ continue ;
464+ break ;
465+ }
462466 }
463467 // TODO(captures): We could keep track of RetCC for the users.
464- if (! capturesNothing (RetCC) && !AddUses (U->getUser ()))
468+ if (capturesAnything (RetCC) && !AddUses (U->getUser ()))
465469 return ;
466470 }
467471
0 commit comments