Skip to content

[AA] Merge isNonEscapingLocalObject() into SimpleCaptureAnalysis (NFC) #142971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/AliasAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ LLVM_ABI bool isIdentifiedFunctionLocal(const Value *V);
LLVM_ABI bool isBaseOfObject(const Value *V);

/// Returns true if the pointer is one which would have been considered an
/// escape by isNonEscapingLocalObject.
/// escape by isNotCapturedBefore.
LLVM_ABI bool isEscapeSource(const Value *V);

/// Return true if Object memory is not visible after an unwind, in the sense
Expand Down
6 changes: 0 additions & 6 deletions llvm/include/llvm/Analysis/CaptureTracking.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,6 @@ namespace llvm {
/// implicit captures such as for external globals.
LLVM_ABI void PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
unsigned MaxUsesToExplore = 0);

/// Returns true if the pointer is to a function-local object that never
/// escapes from the function.
LLVM_ABI bool isNonEscapingLocalObject(
const Value *V,
SmallDenseMap<const Value *, bool, 8> *IsCapturedCache = nullptr);
} // end namespace llvm

#endif
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/AliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,13 +857,13 @@ bool llvm::isEscapeSource(const Value *V) {
return !CB->hasArgumentWithAdditionalReturnCaptureComponents();
}

// The load case works because isNonEscapingLocalObject considers all
// The load case works because isNotCapturedBefore considers all
// stores to be escapes (it passes true for the StoreCaptures argument
// to PointerMayBeCaptured).
if (isa<LoadInst>(V))
return true;

// The inttoptr case works because isNonEscapingLocalObject considers all
// The inttoptr case works because isNotCapturedBefore considers all
// means of converting or equating a pointer to an int (ptrtoint, ptr store
// which could be followed by an integer load, ptr<->int compare) as
// escaping, and objects located at well-known addresses via platform-specific
Expand Down
12 changes: 11 additions & 1 deletion llvm/lib/Analysis/BasicAliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,17 @@ CaptureAnalysis::~CaptureAnalysis() = default;
bool SimpleCaptureAnalysis::isNotCapturedBefore(const Value *Object,
const Instruction *I,
bool OrAt) {
return isNonEscapingLocalObject(Object, &IsCapturedCache);
if (!isIdentifiedFunctionLocal(Object))
return false;

auto [CacheIt, Inserted] = IsCapturedCache.insert({Object, false});
if (!Inserted)
return CacheIt->second;

bool Ret = !capturesAnything(PointerMayBeCaptured(
Object, /*ReturnCaptures=*/false, CaptureComponents::Provenance));
CacheIt->second = Ret;
return Ret;
}

static bool isNotInCycle(const Instruction *I, const DominatorTree *DT,
Expand Down
24 changes: 0 additions & 24 deletions llvm/lib/Analysis/CaptureTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,27 +447,3 @@ void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,

// All uses examined.
}

bool llvm::isNonEscapingLocalObject(
const Value *V, SmallDenseMap<const Value *, bool, 8> *IsCapturedCache) {
SmallDenseMap<const Value *, bool, 8>::iterator CacheIt;
if (IsCapturedCache) {
bool Inserted;
std::tie(CacheIt, Inserted) = IsCapturedCache->insert({V, false});
if (!Inserted)
// Found cached result, return it!
return CacheIt->second;
}

// If this is an identified function-local object, check to see if it escapes.
// We only care about provenance here, not address capture.
if (isIdentifiedFunctionLocal(V)) {
bool Ret = !capturesAnything(PointerMayBeCaptured(
V, /*ReturnCaptures=*/false, CaptureComponents::Provenance));
if (IsCapturedCache)
CacheIt->second = Ret;
return Ret;
}

return false;
}