@@ -81,8 +81,8 @@ struct SimpleCaptureTracker : public CaptureTracker {
8181 Captured = true ;
8282 }
8383
84- Action captured (const Use *U, CaptureInfo CI) override {
85- // TODO(captures): Use CaptureInfo .
84+ Action captured (const Use *U, UseCaptureInfo CI) override {
85+ // TODO(captures): Use UseCaptureInfo .
8686 if (isa<ReturnInst>(U->getUser ()) && !ReturnCaptures)
8787 return ContinueIgnoringReturn;
8888
@@ -123,8 +123,8 @@ struct CapturesBefore : public CaptureTracker {
123123 return !isPotentiallyReachable (I, BeforeHere, nullptr , DT, LI);
124124 }
125125
126- Action captured (const Use *U, CaptureInfo CI) override {
127- // TODO(captures): Use CaptureInfo .
126+ Action captured (const Use *U, UseCaptureInfo CI) override {
127+ // TODO(captures): Use UseCaptureInfo .
128128 Instruction *I = cast<Instruction>(U->getUser ());
129129 if (isa<ReturnInst>(I) && !ReturnCaptures)
130130 return ContinueIgnoringReturn;
@@ -169,8 +169,8 @@ struct EarliestCaptures : public CaptureTracker {
169169 EarliestCapture = &*F.getEntryBlock ().begin ();
170170 }
171171
172- Action captured (const Use *U, CaptureInfo CI) override {
173- // TODO(captures): Use CaptureInfo .
172+ Action captured (const Use *U, UseCaptureInfo CI) override {
173+ // TODO(captures): Use UseCaptureInfo .
174174 Instruction *I = cast<Instruction>(U->getUser ());
175175 if (isa<ReturnInst>(I) && !ReturnCaptures)
176176 return ContinueIgnoringReturn;
@@ -279,14 +279,14 @@ Instruction *llvm::FindEarliestCapture(const Value *V, Function &F,
279279 return CB.EarliestCapture ;
280280}
281281
282- CaptureInfo llvm::DetermineUseCaptureKind (
282+ UseCaptureInfo llvm::DetermineUseCaptureKind (
283283 const Use &U, const Value *Base,
284284 function_ref<bool (Value *, const DataLayout &)> IsDereferenceableOrNull) {
285285 Instruction *I = dyn_cast<Instruction>(U.getUser ());
286286
287287 // TODO: Investigate non-instruction uses.
288288 if (!I)
289- return CaptureInfo::otherOnly () ;
289+ return CaptureComponents::All ;
290290
291291 switch (I->getOpcode ()) {
292292 case Instruction::Call:
@@ -298,21 +298,21 @@ CaptureInfo llvm::DetermineUseCaptureKind(
298298 // by throwing an exception or not depending on the input value).
299299 if (Call->onlyReadsMemory () && Call->doesNotThrow () &&
300300 Call->getType ()->isVoidTy ())
301- return CaptureInfo::none () ;
301+ return CaptureComponents::None ;
302302
303303 // The pointer is not captured if returned pointer is not captured.
304304 // NOTE: CaptureTracking users should not assume that only functions
305305 // marked with nocapture do not capture. This means that places like
306306 // getUnderlyingObject in ValueTracking or DecomposeGEPExpression
307307 // in BasicAA also need to know about this property.
308308 if (isIntrinsicReturningPointerAliasingArgumentWithoutCapturing (Call, true ))
309- return CaptureInfo::retOnly ();
309+ return UseCaptureInfo::passthrough ();
310310
311311 // Volatile operations effectively capture the memory location that they
312312 // load and store to.
313313 if (auto *MI = dyn_cast<MemIntrinsic>(Call))
314314 if (MI->isVolatile ())
315- return CaptureInfo::otherOnly () ;
315+ return CaptureComponents::All ;
316316
317317 // Calling a function pointer does not in itself cause the pointer to
318318 // be captured. This is a subtle point considering that (for example)
@@ -321,26 +321,27 @@ CaptureInfo llvm::DetermineUseCaptureKind(
321321 // captured, even though the loaded value might be the pointer itself
322322 // (think of self-referential objects).
323323 if (Call->isCallee (&U))
324- return CaptureInfo::none () ;
324+ return CaptureComponents::None ;
325325
326326 // Not captured if only passed via 'nocapture' arguments.
327327 assert (Call->isDataOperand (&U) && " Non-callee must be data operand" );
328- return Call->getCaptureInfo (Call->getDataOperandNo (&U));
328+ CaptureInfo CI = Call->getCaptureInfo (Call->getDataOperandNo (&U));
329+ return UseCaptureInfo (CI.getOtherComponents (), CI.getRetComponents ());
329330 }
330331 case Instruction::Load:
331332 // Volatile loads make the address observable.
332333 if (cast<LoadInst>(I)->isVolatile ())
333- return CaptureInfo::otherOnly () ;
334- return CaptureInfo::none () ;
334+ return CaptureComponents::All ;
335+ return CaptureComponents::None ;
335336 case Instruction::VAArg:
336337 // "va-arg" from a pointer does not cause it to be captured.
337- return CaptureInfo::none () ;
338+ return CaptureComponents::None ;
338339 case Instruction::Store:
339340 // Stored the pointer - conservatively assume it may be captured.
340341 // Volatile stores make the address observable.
341342 if (U.getOperandNo () == 0 || cast<StoreInst>(I)->isVolatile ())
342- return CaptureInfo::otherOnly () ;
343- return CaptureInfo::none () ;
343+ return CaptureComponents::All ;
344+ return CaptureComponents::None ;
344345 case Instruction::AtomicRMW: {
345346 // atomicrmw conceptually includes both a load and store from
346347 // the same location.
@@ -349,8 +350,8 @@ CaptureInfo llvm::DetermineUseCaptureKind(
349350 // Volatile stores make the address observable.
350351 auto *ARMWI = cast<AtomicRMWInst>(I);
351352 if (U.getOperandNo () == 1 || ARMWI->isVolatile ())
352- return CaptureInfo::otherOnly () ;
353- return CaptureInfo::none () ;
353+ return CaptureComponents::All ;
354+ return CaptureComponents::None ;
354355 }
355356 case Instruction::AtomicCmpXchg: {
356357 // cmpxchg conceptually includes both a load and store from
@@ -360,21 +361,21 @@ CaptureInfo llvm::DetermineUseCaptureKind(
360361 // Volatile stores make the address observable.
361362 auto *ACXI = cast<AtomicCmpXchgInst>(I);
362363 if (U.getOperandNo () == 1 || U.getOperandNo () == 2 || ACXI->isVolatile ())
363- return CaptureInfo::otherOnly () ;
364- return CaptureInfo::none () ;
364+ return CaptureComponents::All ;
365+ return CaptureComponents::None ;
365366 }
366367 case Instruction::GetElementPtr:
367368 // AA does not support pointers of vectors, so GEP vector splats need to
368369 // be considered as captures.
369370 if (I->getType ()->isVectorTy ())
370- return CaptureInfo::otherOnly () ;
371- return CaptureInfo::retOnly ();
371+ return CaptureComponents::All ;
372+ return UseCaptureInfo::passthrough ();
372373 case Instruction::BitCast:
373374 case Instruction::PHI:
374375 case Instruction::Select:
375376 case Instruction::AddrSpaceCast:
376377 // The original value is not captured via this if the new value isn't.
377- return CaptureInfo::retOnly ();
378+ return UseCaptureInfo::passthrough ();
378379 case Instruction::ICmp: {
379380 unsigned Idx = U.getOperandNo ();
380381 unsigned OtherIdx = 1 - Idx;
@@ -388,31 +389,31 @@ CaptureInfo llvm::DetermineUseCaptureKind(
388389 // with null, for example.
389390 if (U->getType ()->getPointerAddressSpace () == 0 )
390391 if (isNoAliasCall (U.get ()->stripPointerCasts ()))
391- return CaptureInfo::none () ;
392+ return CaptureComponents::None ;
392393 if (!I->getFunction ()->nullPointerIsDefined ()) {
393394 auto *O = I->getOperand (Idx)->stripPointerCastsSameRepresentation ();
394395 // Comparing a dereferenceable_or_null pointer against null cannot
395396 // lead to pointer escapes, because if it is not null it must be a
396397 // valid (in-bounds) pointer.
397398 const DataLayout &DL = I->getDataLayout ();
398399 if (IsDereferenceableOrNull && IsDereferenceableOrNull (O, DL))
399- return CaptureInfo::none () ;
400+ return CaptureComponents::None ;
400401 }
401402
402403 // Check whether this is a comparison of the base pointer against
403404 // null.
404405 if (U.get () == Base)
405- return CaptureInfo::otherOnly ( CaptureComponents::AddressIsNull) ;
406+ return CaptureComponents::AddressIsNull;
406407 }
407408
408409 // Otherwise, be conservative. There are crazy ways to capture pointers
409410 // using comparisons. However, only the address is captured, not the
410411 // provenance.
411- return CaptureInfo::otherOnly ( CaptureComponents::Address) ;
412+ return CaptureComponents::Address;
412413 }
413414 default :
414415 // Something else - be conservative and say it is captured.
415- return CaptureInfo::otherOnly () ;
416+ return CaptureComponents::All ;
416417 }
417418}
418419
@@ -450,29 +451,25 @@ void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
450451 };
451452 while (!Worklist.empty ()) {
452453 const Use *U = Worklist.pop_back_val ();
453- CaptureInfo CI = DetermineUseCaptureKind (*U, V, IsDereferenceableOrNull);
454- if (capturesNothing (CI))
455- continue ;
456- CaptureComponents OtherCC = CI.getOtherComponents ();
457- CaptureComponents RetCC = CI.getRetComponents ();
458- if (capturesAnything (OtherCC)) {
454+ UseCaptureInfo CI = DetermineUseCaptureKind (*U, V, IsDereferenceableOrNull);
455+ if (capturesAnything (CI.UseCC )) {
459456 switch (Tracker->captured (U, CI)) {
460457 case CaptureTracker::Stop:
461458 return ;
462459 case CaptureTracker::ContinueIgnoringReturn:
463460 continue ;
464461 case CaptureTracker::Continue:
465- // Fall through to passthrough handling, but only if RetCC contains
466- // additional components that OtherCC does not. We assume that a
462+ // Fall through to passthrough handling, but only if ResultCC contains
463+ // additional components that UseCC does not. We assume that a
467464 // capture at this point will be strictly more constraining than a
468465 // later capture from following the return value.
469- if (capturesNothing (RetCC & ~OtherCC ))
466+ if (capturesNothing (CI. ResultCC & ~CI. UseCC ))
470467 continue ;
471468 break ;
472469 }
473470 }
474- // TODO(captures): We could keep track of RetCC for the users.
475- if (capturesAnything (RetCC ) && !AddUses (U->getUser ()))
471+ // TODO(captures): We could keep track of ResultCC for the users.
472+ if (capturesAnything (CI. ResultCC ) && !AddUses (U->getUser ()))
476473 return ;
477474 }
478475
0 commit comments