diff options
author | Alina Sbirlea <asbirlea@google.com> | 2020-01-23 14:21:08 -0800 |
---|---|---|
committer | Alina Sbirlea <asbirlea@google.com> | 2020-01-23 16:04:57 -0800 |
commit | 9e66c4ec127ef6e73f1bafe06fe3fba45d59feee (patch) | |
tree | 680cddd0ef06a249261dbd39c67b932b6b2765a3 /llvm/lib/Transforms/Utils/Local.cpp | |
parent | 2af74e27ed7d0832cbdde9cb969aaca7a42e99f9 (diff) | |
download | llvm-9e66c4ec127ef6e73f1bafe06fe3fba45d59feee.zip llvm-9e66c4ec127ef6e73f1bafe06fe3fba45d59feee.tar.gz llvm-9e66c4ec127ef6e73f1bafe06fe3fba45d59feee.tar.bz2 |
[Utils] Use WeakTrackingVH in vector used as scratch storage.
The utility method RecursivelyDeleteTriviallyDeadInstructions receives
as input a vector of Instructions, where all inputs are valid
instructions. This same vector is used as a scratch storage (per the
header comment) to recursively delete instructions. If an instruction is
added as an operand of multiple other instructions, it may be added twice,
then deleted once, then the second reference in the vector is invalid.
Switch to using a Vector<WeakTrackingVH>.
This change facilitates a clean-up in LoopStrengthReduction.
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 5b188fc..10afed3 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -443,7 +443,7 @@ bool llvm::RecursivelyDeleteTriviallyDeadInstructions( if (!I || !isInstructionTriviallyDead(I, TLI)) return false; - SmallVector<Instruction*, 16> DeadInsts; + SmallVector<WeakTrackingVH, 16> DeadInsts; DeadInsts.push_back(I); RecursivelyDeleteTriviallyDeadInstructions(DeadInsts, TLI, MSSAU); @@ -451,21 +451,24 @@ bool llvm::RecursivelyDeleteTriviallyDeadInstructions( } void llvm::RecursivelyDeleteTriviallyDeadInstructions( - SmallVectorImpl<Instruction *> &DeadInsts, const TargetLibraryInfo *TLI, + SmallVectorImpl<WeakTrackingVH> &DeadInsts, const TargetLibraryInfo *TLI, MemorySSAUpdater *MSSAU) { // Process the dead instruction list until empty. while (!DeadInsts.empty()) { - Instruction &I = *DeadInsts.pop_back_val(); - assert(I.use_empty() && "Instructions with uses are not dead."); - assert(isInstructionTriviallyDead(&I, TLI) && + Value *V = DeadInsts.pop_back_val(); + Instruction *I = cast_or_null<Instruction>(V); + if (!I) + continue; + assert(isInstructionTriviallyDead(I, TLI) && "Live instruction found in dead worklist!"); + assert(I->use_empty() && "Instructions with uses are not dead."); // Don't lose the debug info while deleting the instructions. - salvageDebugInfo(I); + salvageDebugInfo(*I); // Null out all of the instruction's operands to see if any operand becomes // dead as we go. - for (Use &OpU : I.operands()) { + for (Use &OpU : I->operands()) { Value *OpV = OpU.get(); OpU.set(nullptr); @@ -480,9 +483,9 @@ void llvm::RecursivelyDeleteTriviallyDeadInstructions( DeadInsts.push_back(OpI); } if (MSSAU) - MSSAU->removeMemoryAccess(&I); + MSSAU->removeMemoryAccess(I); - I.eraseFromParent(); + I->eraseFromParent(); } } |