summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-11-27 23:14:34 +0000
committerChris Lattner <sabre@nondot.org>2008-11-27 23:14:34 +0000
commit1cb4f72706dc16173c8747a848ca0205f79b347f (patch)
tree25c2279d2e0ec82ce1fedb763847eeb8ac936621 /llvm/lib/Transforms
parent96e2dbe00875554feabaa28e20a9275821d00070 (diff)
downloadbcm5719-llvm-1cb4f72706dc16173c8747a848ca0205f79b347f.tar.gz
bcm5719-llvm-1cb4f72706dc16173c8747a848ca0205f79b347f.zip
Enhance RecursivelyDeleteTriviallyDeadInstructions to optionally
return a list of deleted instructions. llvm-svn: 60193
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index e3a0917eb02..1e1b3869446 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/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);
}
}
OpenPOWER on IntegriCloud