Enhance RecursivelyDeleteTriviallyDeadInstructions to optionally
authorChris Lattner <sabre@nondot.org>
Thu, 27 Nov 2008 23:14:34 +0000 (23:14 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 27 Nov 2008 23:14:34 +0000 (23:14 +0000)
return a list of deleted instructions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60193 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/Utils/Local.h
lib/Transforms/Utils/Local.cpp

index 65438aa5e4ad595218a2cb4d231122359d6e5290..3fb05357233281c346e8ca57afc55c253cae6a66 100644 (file)
@@ -24,7 +24,7 @@ class PHINode;
 class AllocaInst;
 class ConstantExpr;
 class TargetData;
-
+  
 //===----------------------------------------------------------------------===//
 //  Local constant propagation.
 //
@@ -49,7 +49,11 @@ bool 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 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...
index e3a0917eb02bd2275477331f58372ca0a3521d9e..1e1b3869446ecb930230260f507a0c9543e10e13 100644 (file)
@@ -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);
   }
 }