diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h --- a/llvm/include/llvm/Analysis/ValueTracking.h +++ b/llvm/include/llvm/Analysis/ValueTracking.h @@ -415,8 +415,10 @@ const DataLayout &DL); /// Finds alloca where the value comes from. - AllocaInst * - findAllocaForValue(Value *V, DenseMap &AllocaForValue); + AllocaInst *findAllocaForValue(Value *V); + inline const AllocaInst *findAllocaForValue(const Value *V) { + return findAllocaForValue(const_cast(V)); + } /// Return true if the only users of this pointer are lifetime markers. bool onlyUsedByLifetimeMarkers(const Value *V); diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -4313,9 +4313,8 @@ return true; } -AllocaInst * -llvm::findAllocaForValue(Value *V, - DenseMap &AllocaForValue) { +static AllocaInst * +findAllocaForValue(Value *V, DenseMap &AllocaForValue) { if (AllocaInst *AI = dyn_cast(V)) return AI; // See if we've already calculated (or started to calculate) alloca for a @@ -4348,6 +4347,11 @@ return Res; } +AllocaInst *llvm::findAllocaForValue(Value *V) { + DenseMap AllocaForValue; + return ::findAllocaForValue(V, AllocaForValue); +} + static bool onlyUsedByLifetimeMarkersOrDroppableInstsHelper( const Value *V, bool AllowLifetime, bool AllowDroppable) { for (const User *U : V->users()) { diff --git a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp --- a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp +++ b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp @@ -544,7 +544,6 @@ MapVector Allocas; // need stable iteration order SmallVector RetVec; - DenseMap AllocaForValue; SmallVector UnrecognizedLifetimes; for (auto &BB : *F) { @@ -566,8 +565,7 @@ auto *II = dyn_cast(I); if (II && (II->getIntrinsicID() == Intrinsic::lifetime_start || II->getIntrinsicID() == Intrinsic::lifetime_end)) { - AllocaInst *AI = - llvm::findAllocaForValue(II->getArgOperand(1), AllocaForValue); + AllocaInst *AI = findAllocaForValue(II->getArgOperand(1)); if (!AI) { UnrecognizedLifetimes.push_back(I); continue; diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -911,10 +911,6 @@ AllocaInst *DynamicAllocaLayout = nullptr; IntrinsicInst *LocalEscapeCall = nullptr; - // Maps Value to an AllocaInst from which the Value is originated. - using AllocaForValueMapTy = DenseMap; - AllocaForValueMapTy AllocaForValue; - bool HasInlineAsm = false; bool HasReturnsTwiceCall = false; @@ -1065,8 +1061,7 @@ !ConstantInt::isValueValidForType(IntptrTy, SizeValue)) return; // Find alloca instruction that corresponds to llvm.lifetime argument. - AllocaInst *AI = - llvm::findAllocaForValue(II.getArgOperand(1), AllocaForValue); + AllocaInst *AI = findAllocaForValue(II.getArgOperand(1)); if (!AI) { HasUntracedLifetimeIntrinsic = true; return; diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -2693,9 +2693,7 @@ void handleLifetimeStart(IntrinsicInst &I) { if (!PoisonStack) return; - DenseMap AllocaForValue; - AllocaInst *AI = - llvm::findAllocaForValue(I.getArgOperand(1), AllocaForValue); + AllocaInst *AI = llvm::findAllocaForValue(I.getArgOperand(1)); if (!AI) InstrumentLifetimeStart = false; LifetimeStartList.push_back(std::make_pair(&I, AI));