[llvm-commits] [llvm] r60193 - in /llvm/trunk: include/llvm/Transforms/Utils/Local.h lib/Transforms/Utils/Local.cpp
Chris Lattner
sabre at nondot.org
Thu Nov 27 15:14:34 PST 2008
Author: lattner
Date: Thu Nov 27 17:14:34 2008
New Revision: 60193
URL: http://llvm.org/viewvc/llvm-project?rev=60193&view=rev
Log:
Enhance RecursivelyDeleteTriviallyDeadInstructions to optionally
return a list of deleted instructions.
Modified:
llvm/trunk/include/llvm/Transforms/Utils/Local.h
llvm/trunk/lib/Transforms/Utils/Local.cpp
Modified: llvm/trunk/include/llvm/Transforms/Utils/Local.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/Local.h?rev=60193&r1=60192&r2=60193&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/Local.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/Local.h Thu Nov 27 17:14:34 2008
@@ -24,7 +24,7 @@
class AllocaInst;
class ConstantExpr;
class TargetData;
-
+
//===----------------------------------------------------------------------===//
// Local constant propagation.
//
@@ -49,7 +49,11 @@
/// 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 RecursivelyDeleteTriviallyDeadInstructions(Value *V);
+///
+/// If DeadInst is specified, the vector is filled with the instructions that
+/// are actually deleted.
+void RecursivelyDeleteTriviallyDeadInstructions(Value *V,
+ SmallVectorImpl<Instruction*> *DeadInst = 0);
//===----------------------------------------------------------------------===//
// Control Flow Graph Restructuring...
Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=60193&r1=60192&r2=60193&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Thu Nov 27 17:14:34 2008
@@ -176,7 +176,11 @@
/// 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 @@
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);
}
}
More information about the llvm-commits
mailing list