findAllocaForValue uses AllocaForValue to cache resolved values.
The function is used only to resolve arguments of lifetime
intrinsic which usually are not fare for allocas. So result reuse
is likely unnoticeable.
In followup patches I'd like to replace the function with
GetUnderlyingObjects.
Depends on D84616.
Differential Revision: https://reviews.llvm.org/D84617
const DataLayout &DL);
/// Finds alloca where the value comes from.
- AllocaInst *
- findAllocaForValue(Value *V, DenseMap<Value *, AllocaInst *> &AllocaForValue);
+ AllocaInst *findAllocaForValue(Value *V);
+ inline const AllocaInst *findAllocaForValue(const Value *V) {
+ return findAllocaForValue(const_cast<Value *>(V));
+ }
/// Return true if the only users of this pointer are lifetime markers.
bool onlyUsedByLifetimeMarkers(const Value *V);
return true;
}
-AllocaInst *
-llvm::findAllocaForValue(Value *V,
- DenseMap<Value *, AllocaInst *> &AllocaForValue) {
+static AllocaInst *
+findAllocaForValue(Value *V, DenseMap<Value *, AllocaInst *> &AllocaForValue) {
if (AllocaInst *AI = dyn_cast<AllocaInst>(V))
return AI;
// See if we've already calculated (or started to calculate) alloca for a
return Res;
}
+AllocaInst *llvm::findAllocaForValue(Value *V) {
+ DenseMap<Value *, AllocaInst *> AllocaForValue;
+ return ::findAllocaForValue(V, AllocaForValue);
+}
+
static bool onlyUsedByLifetimeMarkersOrDroppableInstsHelper(
const Value *V, bool AllowLifetime, bool AllowDroppable) {
for (const User *U : V->users()) {
MapVector<AllocaInst *, AllocaInfo> Allocas; // need stable iteration order
SmallVector<Instruction *, 8> RetVec;
- DenseMap<Value *, AllocaInst *> AllocaForValue;
SmallVector<Instruction *, 4> UnrecognizedLifetimes;
for (auto &BB : *F) {
auto *II = dyn_cast<IntrinsicInst>(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;
AllocaInst *DynamicAllocaLayout = nullptr;
IntrinsicInst *LocalEscapeCall = nullptr;
- // Maps Value to an AllocaInst from which the Value is originated.
- using AllocaForValueMapTy = DenseMap<Value *, AllocaInst *>;
- AllocaForValueMapTy AllocaForValue;
-
bool HasInlineAsm = false;
bool HasReturnsTwiceCall = false;
!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;
void handleLifetimeStart(IntrinsicInst &I) {
if (!PoisonStack)
return;
- DenseMap<Value *, AllocaInst *> 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));