[PATCH] D84906: [NFC] Use GetUnderlyingObjects in findAllocaForValue
Vitaly Buka via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 29 19:50:10 PDT 2020
vitalybuka created this revision.
vitalybuka added reviewers: eugenis, glider.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
vitalybuka requested review of this revision.
Depends on D84621 <https://reviews.llvm.org/D84621>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D84906
Files:
llvm/lib/Analysis/ValueTracking.cpp
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -4299,47 +4299,12 @@
return true;
}
-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
- // given value.
- auto I = AllocaForValue.find(V);
- if (I != AllocaForValue.end())
- return I->second;
- // Store 0 while we're calculating alloca for value V to avoid
- // infinite recursion if the value references itself.
- AllocaForValue[V] = nullptr;
- AllocaInst *Res = nullptr;
- if (CastInst *CI = dyn_cast<CastInst>(V))
- Res = findAllocaForValue(CI->getOperand(0), AllocaForValue);
- else if (PHINode *PN = dyn_cast<PHINode>(V)) {
- for (Value *IncValue : PN->incoming_values()) {
- // Allow self-referencing phi-nodes.
- if (IncValue == PN)
- continue;
- AllocaInst *IncValueAI = findAllocaForValue(IncValue, AllocaForValue);
- // AI for incoming values should exist and should all be equal.
- if (IncValueAI == nullptr || (Res != nullptr && IncValueAI != Res))
- return nullptr;
- Res = IncValueAI;
- }
- } else if (GetElementPtrInst *EP = dyn_cast<GetElementPtrInst>(V)) {
- Res = findAllocaForValue(EP->getPointerOperand(), AllocaForValue);
- } else {
-#ifndef NDEBUG
- dbgs() << "Alloca search cancelled on unknown instruction: " << *V << "\n";
-#endif
- }
- if (Res)
- AllocaForValue[V] = Res;
- return Res;
-}
-
AllocaInst *llvm::findAllocaForValue(Value *V) {
- DenseMap<Value *, AllocaInst *> AllocaForValue;
- return ::findAllocaForValue(V, AllocaForValue);
+ SmallVector<const Value *, 16> Objects;
+ GetUnderlyingObjects(V, Objects);
+ if (Objects.size() != 1)
+ return nullptr;
+ return const_cast<AllocaInst *>(dyn_cast<AllocaInst>(Objects.front()));
}
static bool onlyUsedByLifetimeMarkersOrDroppableInstsHelper(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84906.281784.patch
Type: text/x-patch
Size: 2113 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200730/bdf973db/attachment.bin>
More information about the llvm-commits
mailing list