diff options
author | Chris Lattner <sabre@nondot.org> | 2008-11-27 23:14:34 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-11-27 23:14:34 +0000 |
commit | 9252bc065ee1170b49c011c153c29cc2ed729548 (patch) | |
tree | a11072160742514d79e0165df7592ec971c625ac /lib/Transforms | |
parent | a7e72b6bd1c60ccc959884673ee0eacd54843808 (diff) | |
download | external_llvm-9252bc065ee1170b49c011c153c29cc2ed729548.zip external_llvm-9252bc065ee1170b49c011c153c29cc2ed729548.tar.gz external_llvm-9252bc065ee1170b49c011c153c29cc2ed729548.tar.bz2 |
Enhance RecursivelyDeleteTriviallyDeadInstructions to optionally
return a list of deleted instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60193 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Utils/Local.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp index e3a0917..1e1b386 100644 --- a/lib/Transforms/Utils/Local.cpp +++ b/lib/Transforms/Utils/Local.cpp @@ -176,7 +176,11 @@ bool llvm::isInstructionTriviallyDead(Instruction *I) { /// RecursivelyDeleteTriviallyDeadInstructions - If the specified value is a /// trivially dead instruction, delete it. If that makes any of its operands /// trivially dead, delete them too, recursively. -void llvm::RecursivelyDeleteTriviallyDeadInstructions(Value *V) { +/// +/// If DeadInst is specified, the vector is filled with the instructions that +/// are actually deleted. +void llvm::RecursivelyDeleteTriviallyDeadInstructions(Value *V, + SmallVectorImpl<Instruction*> *DeadInst) { Instruction *I = dyn_cast<Instruction>(V); if (!I || !I->use_empty()) return; @@ -186,12 +190,16 @@ void llvm::RecursivelyDeleteTriviallyDeadInstructions(Value *V) { while (!Insts.empty()) { I = *Insts.begin(); Insts.erase(I); - if (isInstructionTriviallyDead(I)) { - for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) - if (Instruction *U = dyn_cast<Instruction>(I->getOperand(i))) - Insts.insert(U); - I->eraseFromParent(); - } + if (!isInstructionTriviallyDead(I)) + continue; + + for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) + if (Instruction *U = dyn_cast<Instruction>(I->getOperand(i))) + Insts.insert(U); + I->eraseFromParent(); + + if (DeadInst) + DeadInst->push_back(I); } } |