summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/MemorySSAUpdater.cpp
diff options
context:
space:
mode:
authorAlina Sbirlea <asbirlea@google.com>2019-05-08 17:05:36 +0000
committerAlina Sbirlea <asbirlea@google.com>2019-05-08 17:05:36 +0000
commitf31eba649422082783a19bb6b373f31f10f55de9 (patch)
treeb0f73d40cc275dfaacb603f9987a26247249d11a /llvm/lib/Analysis/MemorySSAUpdater.cpp
parent9f15718b3dd405adb2477a121e1030a0e81d00fd (diff)
downloadbcm5719-llvm-f31eba649422082783a19bb6b373f31f10f55de9.tar.gz
bcm5719-llvm-f31eba649422082783a19bb6b373f31f10f55de9.zip
[MemorySSA] Teach LoopSimplify to preserve MemorySSA.
Summary: Preserve MemorySSA in LoopSimplify, in the old pass manager, if the analysis is available. Do not preserve it in the new pass manager. Update tests. Subscribers: nemanjai, jlebar, javed.absar, Prazek, kbarton, zzheng, jsji, llvm-commits, george.burgess.iv, chandlerc Tags: #llvm Differential Revision: https://reviews.llvm.org/D60833 llvm-svn: 360270
Diffstat (limited to 'llvm/lib/Analysis/MemorySSAUpdater.cpp')
-rw-r--r--llvm/lib/Analysis/MemorySSAUpdater.cpp81
1 files changed, 79 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp
index 8fe7c685102..b0f7dc69e5a 100644
--- a/llvm/lib/Analysis/MemorySSAUpdater.cpp
+++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp
@@ -463,8 +463,8 @@ void MemorySSAUpdater::removeEdge(BasicBlock *From, BasicBlock *To) {
}
}
-void MemorySSAUpdater::removeDuplicatePhiEdgesBetween(BasicBlock *From,
- BasicBlock *To) {
+void MemorySSAUpdater::removeDuplicatePhiEdgesBetween(const BasicBlock *From,
+ const BasicBlock *To) {
if (MemoryPhi *MPhi = MSSA->getMemoryAccess(To)) {
bool Found = false;
MPhi->unorderedDeleteIncomingIf([&](const MemoryAccess *, BasicBlock *B) {
@@ -522,6 +522,46 @@ void MemorySSAUpdater::cloneUsesAndDefs(BasicBlock *BB, BasicBlock *NewBB,
}
}
+void MemorySSAUpdater::updatePhisWhenInsertingUniqueBackedgeBlock(
+ BasicBlock *Header, BasicBlock *Preheader, BasicBlock *BEBlock) {
+ auto *MPhi = MSSA->getMemoryAccess(Header);
+ if (!MPhi)
+ return;
+
+ // Create phi node in the backedge block and populate it with the same
+ // incoming values as MPhi. Skip incoming values coming from Preheader.
+ auto *NewMPhi = MSSA->createMemoryPhi(BEBlock);
+ bool HasUniqueIncomingValue = true;
+ MemoryAccess *UniqueValue = nullptr;
+ for (unsigned I = 0, E = MPhi->getNumIncomingValues(); I != E; ++I) {
+ BasicBlock *IBB = MPhi->getIncomingBlock(I);
+ MemoryAccess *IV = MPhi->getIncomingValue(I);
+ if (IBB != Preheader) {
+ NewMPhi->addIncoming(IV, IBB);
+ if (HasUniqueIncomingValue) {
+ if (!UniqueValue)
+ UniqueValue = IV;
+ else if (UniqueValue != IV)
+ HasUniqueIncomingValue = false;
+ }
+ }
+ }
+
+ // Update incoming edges into MPhi. Remove all but the incoming edge from
+ // Preheader. Add an edge from NewMPhi
+ auto *AccFromPreheader = MPhi->getIncomingValueForBlock(Preheader);
+ MPhi->setIncomingValue(0, AccFromPreheader);
+ MPhi->setIncomingBlock(0, Preheader);
+ for (unsigned I = MPhi->getNumIncomingValues() - 1; I >= 1; --I)
+ MPhi->unorderedDeleteIncoming(I);
+ MPhi->addIncoming(NewMPhi, BEBlock);
+
+ // 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);
+}
+
void MemorySSAUpdater::updateForClonedLoop(const LoopBlocksRPO &LoopBlocks,
ArrayRef<BasicBlock *> ExitBlocks,
const ValueToValueMapTy &VMap,
@@ -1223,6 +1263,43 @@ void MemorySSAUpdater::tryRemoveTrivialPhis(ArrayRef<WeakVH> UpdatedPHIs) {
}
}
+void MemorySSAUpdater::changeToUnreachable(const Instruction *I) {
+ const BasicBlock *BB = I->getParent();
+ // Remove memory accesses in BB for I and all following instructions.
+ auto BBI = I->getIterator(), BBE = BB->end();
+ // FIXME: If this becomes too expensive, iterate until the first instruction
+ // with a memory access, then iterate over MemoryAccesses.
+ while (BBI != BBE)
+ removeMemoryAccess(&*(BBI++));
+ // Update phis in BB's successors to remove BB.
+ SmallVector<WeakVH, 16> UpdatedPHIs;
+ for (const BasicBlock *Successor : successors(BB)) {
+ removeDuplicatePhiEdgesBetween(BB, Successor);
+ if (MemoryPhi *MPhi = MSSA->getMemoryAccess(Successor)) {
+ MPhi->unorderedDeleteIncomingBlock(BB);
+ UpdatedPHIs.push_back(MPhi);
+ }
+ }
+ // Optimize trivial phis.
+ tryRemoveTrivialPhis(UpdatedPHIs);
+}
+
+void MemorySSAUpdater::changeCondBranchToUnconditionalTo(const BranchInst *BI,
+ const BasicBlock *To) {
+ const BasicBlock *BB = BI->getParent();
+ SmallVector<WeakVH, 16> UpdatedPHIs;
+ for (const BasicBlock *Succ : successors(BB)) {
+ removeDuplicatePhiEdgesBetween(BB, Succ);
+ if (Succ != To)
+ if (auto *MPhi = MSSA->getMemoryAccess(Succ)) {
+ MPhi->unorderedDeleteIncomingBlock(BB);
+ UpdatedPHIs.push_back(MPhi);
+ }
+ }
+ // Optimize trivial phis.
+ tryRemoveTrivialPhis(UpdatedPHIs);
+}
+
MemoryAccess *MemorySSAUpdater::createMemoryAccessInBB(
Instruction *I, MemoryAccess *Definition, const BasicBlock *BB,
MemorySSA::InsertionPlace Point) {
OpenPOWER on IntegriCloud