diff options
author | Alina Sbirlea <asbirlea@google.com> | 2018-08-16 21:58:44 +0000 |
---|---|---|
committer | Alina Sbirlea <asbirlea@google.com> | 2018-08-16 21:58:44 +0000 |
commit | 2ab544bcf5c1e38de51661956b1bfa7b1a19b586 (patch) | |
tree | f8c07d1ff49b4e1e2498fcf816bd2bdf8a1211b5 /llvm/lib/Transforms/Utils | |
parent | 628e766ca3c4732907e9f35c26f0466babe3f5a1 (diff) | |
download | bcm5719-llvm-2ab544bcf5c1e38de51661956b1bfa7b1a19b586.tar.gz bcm5719-llvm-2ab544bcf5c1e38de51661956b1bfa7b1a19b586.zip |
Update MemorySSA in Local utils removing blocks.
Summary: Extend Local utils to update MemorySSA.
Subscribers: sanjoy, jlebar, Prazek, george.burgess.iv, llvm-commits
Differential Revision: https://reviews.llvm.org/D48790
llvm-svn: 339951
Diffstat (limited to 'llvm/lib/Transforms/Utils')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 7e607f17fc0..b8aa21be5c5 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -31,6 +31,7 @@ #include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/LazyValueInfo.h" #include "llvm/Analysis/MemoryBuiltins.h" +#include "llvm/Analysis/MemorySSAUpdater.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/BinaryFormat/Dwarf.h" @@ -426,22 +427,22 @@ bool llvm::wouldInstructionBeTriviallyDead(Instruction *I, /// trivially dead instruction, delete it. If that makes any of its operands /// trivially dead, delete them too, recursively. Return true if any /// instructions were deleted. -bool -llvm::RecursivelyDeleteTriviallyDeadInstructions(Value *V, - const TargetLibraryInfo *TLI) { +bool llvm::RecursivelyDeleteTriviallyDeadInstructions( + Value *V, const TargetLibraryInfo *TLI, MemorySSAUpdater *MSSAU) { Instruction *I = dyn_cast<Instruction>(V); if (!I || !I->use_empty() || !isInstructionTriviallyDead(I, TLI)) return false; SmallVector<Instruction*, 16> DeadInsts; DeadInsts.push_back(I); - RecursivelyDeleteTriviallyDeadInstructions(DeadInsts, TLI); + RecursivelyDeleteTriviallyDeadInstructions(DeadInsts, TLI, MSSAU); return true; } void llvm::RecursivelyDeleteTriviallyDeadInstructions( - SmallVectorImpl<Instruction *> &DeadInsts, const TargetLibraryInfo *TLI) { + SmallVectorImpl<Instruction *> &DeadInsts, const TargetLibraryInfo *TLI, + MemorySSAUpdater *MSSAU) { // Process the dead instruction list until empty. while (!DeadInsts.empty()) { Instruction &I = *DeadInsts.pop_back_val(); @@ -468,6 +469,8 @@ void llvm::RecursivelyDeleteTriviallyDeadInstructions( if (isInstructionTriviallyDead(OpI, TLI)) DeadInsts.push_back(OpI); } + if (MSSAU) + MSSAU->removeMemoryAccess(&I); I.eraseFromParent(); } @@ -655,7 +658,7 @@ void llvm::RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred, } /// MergeBasicBlockIntoOnlyPred - DestBB is a block with one predecessor and its -/// predecessor is known to have one successor (DestBB!). Eliminate the edge +/// predecessor is known to have one successor (DestBB!). Eliminate the edge /// between them, moving the instructions in the predecessor into DestBB and /// deleting the predecessor block. void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB, @@ -2213,7 +2216,8 @@ void llvm::removeUnwindEdge(BasicBlock *BB, DomTreeUpdater *DTU) { /// otherwise. If `LVI` is passed, this function preserves LazyValueInfo /// after modifying the CFG. bool llvm::removeUnreachableBlocks(Function &F, LazyValueInfo *LVI, - DomTreeUpdater *DTU) { + DomTreeUpdater *DTU, + MemorySSAUpdater *MSSAU) { SmallPtrSet<BasicBlock*, 16> Reachable; bool Changed = markAliveBlocks(F, Reachable, DTU); @@ -2224,15 +2228,23 @@ bool llvm::removeUnreachableBlocks(Function &F, LazyValueInfo *LVI, assert(Reachable.size() < F.size()); NumRemoved += F.size()-Reachable.size(); - // Loop over all of the basic blocks that are not reachable, dropping all of - // their internal references. Update DTU and LVI if available. - std::vector <DominatorTree::UpdateType> Updates; + SmallPtrSet<BasicBlock *, 16> DeadBlockSet; for (Function::iterator I = ++F.begin(), E = F.end(); I != E; ++I) { auto *BB = &*I; if (Reachable.count(BB)) continue; + DeadBlockSet.insert(BB); + } + + if (MSSAU) + MSSAU->removeBlocks(DeadBlockSet); + + // Loop over all of the basic blocks that are not reachable, dropping all of + // their internal references. Update DTU and LVI if available. + std::vector<DominatorTree::UpdateType> Updates; + for (auto *BB : DeadBlockSet) { for (BasicBlock *Successor : successors(BB)) { - if (Reachable.count(Successor)) + if (!DeadBlockSet.count(Successor)) Successor->removePredecessor(BB); if (DTU) Updates.push_back({DominatorTree::Delete, BB, Successor}); @@ -2241,7 +2253,6 @@ bool llvm::removeUnreachableBlocks(Function &F, LazyValueInfo *LVI, LVI->eraseBlock(BB); BB->dropAllReferences(); } - SmallVector<BasicBlock *, 8> ToDeleteBBs; for (Function::iterator I = ++F.begin(); I != F.end();) { auto *BB = &*I; if (Reachable.count(BB)) { @@ -2249,8 +2260,6 @@ bool llvm::removeUnreachableBlocks(Function &F, LazyValueInfo *LVI, continue; } if (DTU) { - ToDeleteBBs.push_back(BB); - // Remove the TerminatorInst of BB to clear the successor list of BB. if (BB->getTerminator()) BB->getInstList().pop_back(); @@ -2266,7 +2275,7 @@ bool llvm::removeUnreachableBlocks(Function &F, LazyValueInfo *LVI, if (DTU) { DTU->applyUpdates(Updates, /*ForceRemoveDuplicates*/ true); bool Deleted = false; - for (auto *BB : ToDeleteBBs) { + for (auto *BB : DeadBlockSet) { if (DTU->isBBPendingDeletion(BB)) --NumRemoved; else |