Skip to content

Commit c59a904

Browse files
committed
[AA] Merge isNonEscapingLocalObject() into SimpleCaptureAnalysis (NFC)
isNonEscapingLocalObject() is only used by SimpleCaptureAnalysis and tightly integrated with its implementation (in particular its cache), so inline and simplify the implementation.
1 parent 100a1d0 commit c59a904

File tree

3 files changed

+11
-31
lines changed

3 files changed

+11
-31
lines changed

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/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)