aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/CodeGenPrepare.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2020-09-11 11:24:08 +0200
committerBenjamin Kramer <benny.kra@googlemail.com>2020-09-11 11:24:08 +0200
commit5405ee553a631dd8cd18eed8ed9e76ec318febcb (patch)
tree59a2daee1212b65f22a5d66f85282a7e00a24547 /llvm/lib/CodeGen/CodeGenPrepare.cpp
parenta0e0d30a29841fe6cc854f3949f12bb523814d7a (diff)
downloadllvm-5405ee553a631dd8cd18eed8ed9e76ec318febcb.zip
llvm-5405ee553a631dd8cd18eed8ed9e76ec318febcb.tar.gz
llvm-5405ee553a631dd8cd18eed8ed9e76ec318febcb.tar.bz2
[CodeGenPrepare] Simplify code. NFCI.
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp21
1 files changed, 5 insertions, 16 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 9a4ed2f..3e5dcec 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -5274,22 +5274,11 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
// If we have no uses, recursively delete the value and all dead instructions
// using it.
if (Repl->use_empty()) {
- // This can cause recursive deletion, which can invalidate our iterator.
- // Use a WeakTrackingVH to hold onto it in case this happens.
- Value *CurValue = &*CurInstIterator;
- WeakTrackingVH IterHandle(CurValue);
- BasicBlock *BB = CurInstIterator->getParent();
-
- RecursivelyDeleteTriviallyDeadInstructions(
- Repl, TLInfo, nullptr,
- [&](Value *V) { removeAllAssertingVHReferences(V); });
-
- if (IterHandle != CurValue) {
- // If the iterator instruction was recursively deleted, start over at the
- // start of the block.
- CurInstIterator = BB->begin();
- SunkAddrs.clear();
- }
+ resetIteratorIfInvalidatedWhileCalling(CurInstIterator->getParent(), [&]() {
+ RecursivelyDeleteTriviallyDeadInstructions(
+ Repl, TLInfo, nullptr,
+ [&](Value *V) { removeAllAssertingVHReferences(V); });
+ });
}
++NumMemoryInsts;
return true;