aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2020-07-30 18:22:59 -0700
committerVitaly Buka <vitalybuka@google.com>2020-07-30 18:22:59 -0700
commit61cab352e377d5a37d47555bc56e11f052d7eb8b (patch)
treed3b96e92e1c284eb429c4d8c3ed8f5b7f49b9a76 /llvm/lib/Analysis/ValueTracking.cpp
parent8218eee269c382472b9809cb3cce7a98eed7a31b (diff)
downloadllvm-61cab352e377d5a37d47555bc56e11f052d7eb8b.zip
llvm-61cab352e377d5a37d47555bc56e11f052d7eb8b.tar.gz
llvm-61cab352e377d5a37d47555bc56e11f052d7eb8b.tar.bz2
[NFC] Move findAllocaForValue into ValueTracking.h
Differential Revision: https://reviews.llvm.org/D84616
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 3b8c0fc..6fb36fa 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4313,6 +4313,41 @@ bool llvm::getUnderlyingObjectsForCodeGen(const Value *V,
return true;
}
+AllocaInst *
+llvm::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);
+ }
+ if (Res)
+ AllocaForValue[V] = Res;
+ return Res;
+}
+
static bool onlyUsedByLifetimeMarkersOrDroppableInstsHelper(
const Value *V, bool AllowLifetime, bool AllowDroppable) {
for (const User *U : V->users()) {