diff options
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index c4a8843..d3bb8907 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -2762,6 +2762,23 @@ bool llvm::replaceAllDbgUsesWith(Instruction &From, Value &To, return false; } +bool llvm::handleUnreachableTerminator( + Instruction *I, SmallVectorImpl<Value *> &PoisonedValues) { + bool Changed = false; + // RemoveDIs: erase debug-info on this instruction manually. + I->dropDbgValues(); + for (Use &U : I->operands()) { + Value *Op = U.get(); + if (isa<Instruction>(Op) && !Op->getType()->isTokenTy()) { + U.set(PoisonValue::get(Op->getType())); + PoisonedValues.push_back(Op); + Changed = true; + } + } + + return Changed; +} + std::pair<unsigned, unsigned> llvm::removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB) { unsigned NumDeadInst = 0; @@ -2769,8 +2786,9 @@ llvm::removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB) { // Delete the instructions backwards, as it has a reduced likelihood of // having to update as many def-use and use-def chains. Instruction *EndInst = BB->getTerminator(); // Last not to be deleted. - // RemoveDIs: erasing debug-info must be done manually. - EndInst->dropDbgValues(); + SmallVector<Value *> Uses; + handleUnreachableTerminator(EndInst, Uses); + while (EndInst != &BB->front()) { // Delete the next to last instruction. Instruction *Inst = &*--EndInst->getIterator(); |