Skip to content

Commit 10dd83d

Browse files
authored
[AA] Merge isNonEscapingLocalObject() into SimpleCaptureAnalysis (NFC) (#142971)
isNonEscapingLocalObject() is only used by SimpleCaptureAnalysis and tightly integrated with its implementation (in particular its cache), so inline and simplify the implementation.
1 parent b2266d6 commit 10dd83d

File tree

5 files changed

+14
-34
lines changed

5 files changed

+14
-34
lines changed

llvm/include/llvm/Analysis/AliasAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ LLVM_ABI bool isIdentifiedFunctionLocal(const Value *V);
912912
LLVM_ABI bool isBaseOfObject(const Value *V);
913913

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

918918
/// Return true if Object memory is not visible after an unwind, in the sense

llvm/include/llvm/Analysis/CaptureTracking.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,6 @@ namespace llvm {
195195
/// implicit captures such as for external globals.
196196
LLVM_ABI void PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
197197
unsigned MaxUsesToExplore = 0);
198-
199-
/// Returns true if the pointer is to a function-local object that never
200-
/// escapes from the function.
201-
LLVM_ABI bool isNonEscapingLocalObject(
202-
const Value *V,
203-
SmallDenseMap<const Value *, bool, 8> *IsCapturedCache = nullptr);
204198
} // end namespace llvm
205199

206200
#endif

llvm/lib/Analysis/AliasAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,13 +857,13 @@ bool llvm::isEscapeSource(const Value *V) {
857857
return !CB->hasArgumentWithAdditionalReturnCaptureComponents();
858858
}
859859

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

866-
// The inttoptr case works because isNonEscapingLocalObject considers all
866+
// The inttoptr case works because isNotCapturedBefore considers all
867867
// means of converting or equating a pointer to an int (ptrtoint, ptr store
868868
// which could be followed by an integer load, ptr<->int compare) as
869869
// escaping, and objects located at well-known addresses via platform-specific

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,17 @@ CaptureAnalysis::~CaptureAnalysis() = default;
199199
bool SimpleCaptureAnalysis::isNotCapturedBefore(const Value *Object,
200200
const Instruction *I,
201201
bool OrAt) {
202-
return isNonEscapingLocalObject(Object, &IsCapturedCache);
202+
if (!isIdentifiedFunctionLocal(Object))
203+
return false;
204+
205+
auto [CacheIt, Inserted] = IsCapturedCache.insert({Object, false});
206+
if (!Inserted)
207+
return CacheIt->second;
208+
209+
bool Ret = !capturesAnything(PointerMayBeCaptured(
210+
Object, /*ReturnCaptures=*/false, CaptureComponents::Provenance));
211+
CacheIt->second = Ret;
212+
return Ret;
203213
}
204214

205215
static bool isNotInCycle(const Instruction *I, const DominatorTree *DT,

llvm/lib/Analysis/CaptureTracking.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -447,27 +447,3 @@ void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
447447

448448
// All uses examined.
449449
}
450-
451-
bool llvm::isNonEscapingLocalObject(
452-
const Value *V, SmallDenseMap<const Value *, bool, 8> *IsCapturedCache) {
453-
SmallDenseMap<const Value *, bool, 8>::iterator CacheIt;
454-
if (IsCapturedCache) {
455-
bool Inserted;
456-
std::tie(CacheIt, Inserted) = IsCapturedCache->insert({V, false});
457-
if (!Inserted)
458-
// Found cached result, return it!
459-
return CacheIt->second;
460-
}
461-
462-
// If this is an identified function-local object, check to see if it escapes.
463-
// We only care about provenance here, not address capture.
464-
if (isIdentifiedFunctionLocal(V)) {
465-
bool Ret = !capturesAnything(PointerMayBeCaptured(
466-
V, /*ReturnCaptures=*/false, CaptureComponents::Provenance));
467-
if (IsCapturedCache)
468-
CacheIt->second = Ret;
469-
return Ret;
470-
}
471-
472-
return false;
473-
}

0 commit comments

Comments
 (0)