[llvm] r369466 - [MemorySSA] Make Phi cleanups consistent.
Alina Sbirlea via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 20 15:47:59 PDT 2019
Author: asbirlea
Date: Tue Aug 20 15:47:58 2019
New Revision: 369466
URL: http://llvm.org/viewvc/llvm-project?rev=369466&view=rev
Log:
[MemorySSA] Make Phi cleanups consistent.
Summary:
Make Phi cleanups consistent: remove self as a trivial Phi and
recurse to potentially remove other trivial phis.
Reviewers: george.burgess.iv
Subscribers: Prazek, sanjoy.google, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66454
Modified:
llvm/trunk/include/llvm/Analysis/MemorySSAUpdater.h
llvm/trunk/lib/Analysis/MemorySSAUpdater.cpp
Modified: llvm/trunk/include/llvm/Analysis/MemorySSAUpdater.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/MemorySSAUpdater.h?rev=369466&r1=369465&r2=369466&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/MemorySSAUpdater.h (original)
+++ llvm/trunk/include/llvm/Analysis/MemorySSAUpdater.h Tue Aug 20 15:47:58 2019
@@ -275,6 +275,7 @@ private:
getPreviousDefRecursive(BasicBlock *,
DenseMap<BasicBlock *, TrackingVH<MemoryAccess>> &);
MemoryAccess *recursePhi(MemoryAccess *Phi);
+ MemoryAccess *tryRemoveTrivialPhi(MemoryPhi *Phi);
template <class RangeType>
MemoryAccess *tryRemoveTrivialPhi(MemoryPhi *Phi, RangeType &Operands);
void tryRemoveTrivialPhis(ArrayRef<WeakVH> UpdatedPHIs);
Modified: llvm/trunk/lib/Analysis/MemorySSAUpdater.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemorySSAUpdater.cpp?rev=369466&r1=369465&r2=369466&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemorySSAUpdater.cpp (original)
+++ llvm/trunk/lib/Analysis/MemorySSAUpdater.cpp Tue Aug 20 15:47:58 2019
@@ -173,12 +173,9 @@ MemoryAccess *MemorySSAUpdater::recurseP
TrackingVH<MemoryAccess> Res(Phi);
SmallVector<TrackingVH<Value>, 8> Uses;
std::copy(Phi->user_begin(), Phi->user_end(), std::back_inserter(Uses));
- for (auto &U : Uses) {
- if (MemoryPhi *UsePhi = dyn_cast<MemoryPhi>(&*U)) {
- auto OperRange = UsePhi->operands();
- tryRemoveTrivialPhi(UsePhi, OperRange);
- }
- }
+ for (auto &U : Uses)
+ if (MemoryPhi *UsePhi = dyn_cast<MemoryPhi>(&*U))
+ tryRemoveTrivialPhi(UsePhi);
return Res;
}
@@ -187,6 +184,11 @@ MemoryAccess *MemorySSAUpdater::recurseP
// argument.
// IE phi(a, a) or b = phi(a, b) or c = phi(a, a, c)
// We recursively try to remove them.
+MemoryAccess *MemorySSAUpdater::tryRemoveTrivialPhi(MemoryPhi *Phi) {
+ assert(Phi && "Can only remove concrete Phi.");
+ auto OperRange = Phi->operands();
+ return tryRemoveTrivialPhi(Phi, OperRange);
+}
template <class RangeType>
MemoryAccess *MemorySSAUpdater::tryRemoveTrivialPhi(MemoryPhi *Phi,
RangeType &Operands) {
@@ -490,8 +492,7 @@ void MemorySSAUpdater::fixupDefs(const S
void MemorySSAUpdater::removeEdge(BasicBlock *From, BasicBlock *To) {
if (MemoryPhi *MPhi = MSSA->getMemoryAccess(To)) {
MPhi->unorderedDeleteIncomingBlock(From);
- if (MPhi->getNumIncomingValues() == 1)
- removeMemoryAccess(MPhi);
+ tryRemoveTrivialPhi(MPhi);
}
}
@@ -507,8 +508,7 @@ void MemorySSAUpdater::removeDuplicatePh
Found = true;
return false;
});
- if (MPhi->getNumIncomingValues() == 1)
- removeMemoryAccess(MPhi);
+ tryRemoveTrivialPhi(MPhi);
}
}
@@ -617,8 +617,7 @@ void MemorySSAUpdater::updatePhisWhenIns
// If NewMPhi is a trivial phi, remove it. Its use in the header MPhi will be
// replaced with the unique value.
- if (HasUniqueIncomingValue)
- removeMemoryAccess(NewMPhi);
+ tryRemoveTrivialPhi(MPhi);
}
void MemorySSAUpdater::updateForClonedLoop(const LoopBlocksRPO &LoopBlocks,
@@ -1227,8 +1226,7 @@ void MemorySSAUpdater::wireOldPredecesso
return false;
});
Phi->addIncoming(NewPhi, New);
- if (onlySingleValue(NewPhi))
- removeMemoryAccess(NewPhi);
+ tryRemoveTrivialPhi(NewPhi);
}
}
@@ -1293,10 +1291,8 @@ void MemorySSAUpdater::removeMemoryAcces
unsigned PhisSize = PhisToOptimize.size();
while (PhisSize-- > 0)
if (MemoryPhi *MP =
- cast_or_null<MemoryPhi>(PhisToOptimize.pop_back_val())) {
- auto OperRange = MP->operands();
- tryRemoveTrivialPhi(MP, OperRange);
- }
+ cast_or_null<MemoryPhi>(PhisToOptimize.pop_back_val()))
+ tryRemoveTrivialPhi(MP);
}
}
@@ -1310,8 +1306,7 @@ void MemorySSAUpdater::removeBlocks(
if (!DeadBlocks.count(Succ))
if (MemoryPhi *MP = MSSA->getMemoryAccess(Succ)) {
MP->unorderedDeleteIncomingBlock(BB);
- if (MP->getNumIncomingValues() == 1)
- removeMemoryAccess(MP);
+ tryRemoveTrivialPhi(MP);
}
// Drop all references of all accesses in BB
if (MemorySSA::AccessList *Acc = MSSA->getWritableBlockAccesses(BB))
@@ -1335,10 +1330,8 @@ void MemorySSAUpdater::removeBlocks(
void MemorySSAUpdater::tryRemoveTrivialPhis(ArrayRef<WeakVH> UpdatedPHIs) {
for (auto &VH : UpdatedPHIs)
- if (auto *MPhi = cast_or_null<MemoryPhi>(VH)) {
- auto OperRange = MPhi->operands();
- tryRemoveTrivialPhi(MPhi, OperRange);
- }
+ if (auto *MPhi = cast_or_null<MemoryPhi>(VH))
+ tryRemoveTrivialPhi(MPhi);
}
void MemorySSAUpdater::changeToUnreachable(const Instruction *I) {
More information about the llvm-commits
mailing list