Expose the low level DCE mechanism to external users
authorChris Lattner <sabre@nondot.org>
Thu, 1 Nov 2001 07:00:27 +0000 (07:00 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 1 Nov 2001 07:00:27 +0000 (07:00 +0000)
Refactor code to support it

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

lib/Transforms/Scalar/DCE.cpp

index 71a7f5ae26b6f0dcacf5390953302c21c99ab5d8..ac3ae7b66baf32e8920c2a96bfce2c62e5c1f9c9 100644 (file)
 #include "llvm/Assembly/Writer.h"
 #include <algorithm>
 
-static bool RemoveUnusedDefs(BasicBlock::InstListType &Vals) {
+// dceInstruction - Inspect the instruction at *BBI and figure out if it's
+// [trivially] dead.  If so, remove the instruction and update the iterator
+// to point to the instruction that immediately succeeded the original
+// instruction.
+//
+bool opt::DeadCodeElimination::dceInstruction(BasicBlock::InstListType &BBIL,
+                                              BasicBlock::iterator &BBI) {
+  // Look for un"used" definitions...
+  if ((*BBI)->use_empty() && !(*BBI)->hasSideEffects() && 
+      !isa<TerminatorInst>(*BBI)) {
+    delete BBIL.remove(BBI);   // Bye bye
+    return true;
+  }
+  return false;
+}
+
+static inline bool RemoveUnusedDefs(BasicBlock::InstListType &Vals) {
   bool Changed = false;
   for (BasicBlock::InstListType::iterator DI = Vals.begin(); 
-       DI != Vals.end()-1; ) {
-    // Look for un"used" definitions...
-    if ((*DI)->use_empty() && !(*DI)->hasSideEffects()) {
-      // Bye bye
-      //cerr << "Removing: " << *DI;
-      delete Vals.remove(DI);
+       DI != Vals.end(); )
+    if (opt::DeadCodeElimination::dceInstruction(Vals, DI))
       Changed = true;
-    } else {
+    else
       ++DI;
-    }
-  }
   return Changed;
 }