[llvm-commits] [llvm] r60196 - /llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp

Chris Lattner sabre at nondot.org
Thu Nov 27 15:25:45 PST 2008


Author: lattner
Date: Thu Nov 27 17:25:44 2008
New Revision: 60196

URL: http://llvm.org/viewvc/llvm-project?rev=60196&view=rev
Log:
delete ErasePossiblyDeadInstructionTree, replacing uses of it with
RecursivelyDeleteTriviallyDeadInstructions.

Modified:
    llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=60196&r1=60195&r2=60196&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Thu Nov 27 17:25:44 2008
@@ -494,40 +494,8 @@
   return false;
 }
 
-/// ErasePossiblyDeadInstructionTree - If the specified instruction is dead and
-/// has no side effects, nuke it.  If it uses any instructions that become dead
-/// because the instruction is now gone, nuke them too.
-static void ErasePossiblyDeadInstructionTree(Instruction *I) {
-  if (!isInstructionTriviallyDead(I)) return;
-  
-  SmallVector<Instruction*, 16> InstrsToInspect;
-  InstrsToInspect.push_back(I);
-
-  while (!InstrsToInspect.empty()) {
-    I = InstrsToInspect.back();
-    InstrsToInspect.pop_back();
-
-    if (!isInstructionTriviallyDead(I)) continue;
-
-    // If I is in the work list multiple times, remove previous instances.
-    for (unsigned i = 0, e = InstrsToInspect.size(); i != e; ++i)
-      if (InstrsToInspect[i] == I) {
-        InstrsToInspect.erase(InstrsToInspect.begin()+i);
-        --i, --e;
-      }
-
-    // Add operands of dead instruction to worklist.
-    for (User::op_iterator i = I->op_begin(), e = I->op_end(); i != e; ++i)
-      if (Instruction *OpI = dyn_cast<Instruction>(*i))
-        InstrsToInspect.push_back(OpI);
-
-    // Remove dead instruction.
-    I->eraseFromParent();
-  }
-}
-
-// isValueEqualityComparison - Return true if the specified terminator checks to
-// see if a value is equal to constant integer value.
+/// isValueEqualityComparison - Return true if the specified terminator checks
+/// to see if a value is equal to constant integer value.
 static Value *isValueEqualityComparison(TerminatorInst *TI) {
   if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
     // Do not permit merging of large switch instructions into their
@@ -548,8 +516,8 @@
   return 0;
 }
 
-// Given a value comparison instruction, decode all of the 'cases' that it
-// represents and return the 'default' block.
+/// Given a value comparison instruction, decode all of the 'cases' that it
+/// represents and return the 'default' block.
 static BasicBlock *
 GetValueEqualityComparisonCases(TerminatorInst *TI,
                                 std::vector<std::pair<ConstantInt*,
@@ -666,7 +634,7 @@
         TI->eraseFromParent();   // Nuke the old one.
         // If condition is now dead, nuke it.
         if (Instruction *CondI = dyn_cast<Instruction>(Cond))
-          ErasePossiblyDeadInstructionTree(CondI);
+          RecursivelyDeleteTriviallyDeadInstructions(CondI);
         return true;
 
       } else {
@@ -734,7 +702,7 @@
       Cond = dyn_cast<Instruction>(BI->getCondition());
     TI->eraseFromParent();   // Nuke the old one.
 
-    if (Cond) ErasePossiblyDeadInstructionTree(Cond);
+    if (Cond) RecursivelyDeleteTriviallyDeadInstructions(Cond);
     return true;
   }
   return false;
@@ -850,7 +818,7 @@
       Pred->getInstList().erase(PTI);
 
       // If the condition is dead now, remove the instruction tree.
-      if (DeadCond) ErasePossiblyDeadInstructionTree(DeadCond);
+      if (DeadCond) RecursivelyDeleteTriviallyDeadInstructions(DeadCond);
 
       // Okay, last check.  If BB is still a successor of PSI, then we must
       // have an infinite loop case.  If so, add an infinitely looping block
@@ -1425,7 +1393,7 @@
   BI->eraseFromParent();
   
   if (Instruction *BrCondI = dyn_cast<Instruction>(BrCond))
-    ErasePossiblyDeadInstructionTree(BrCondI);
+    RecursivelyDeleteTriviallyDeadInstructions(BrCondI);
   return true;
 }
 
@@ -2146,7 +2114,7 @@
 
           // Erase the potentially condition tree that was used to computed the
           // branch condition.
-          ErasePossiblyDeadInstructionTree(Cond);
+          RecursivelyDeleteTriviallyDeadInstructions(Cond);
           return true;
         }
       }





More information about the llvm-commits mailing list