* We were forgetting to pass varargs arguments through a call
[oota-llvm.git] / lib / Transforms / Scalar / DCE.cpp
index 2c9c8b3b0d5fcc848dcf965d1c65b62915158b51..e3fc8de396c9f05616f62a7905519f50a2790b18 100644 (file)
@@ -1,4 +1,11 @@
 //===- DCE.cpp - Code to perform dead code elimination --------------------===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
 //
 // This file implements dead inst elimination and dead code elimination.
 //
 #include "llvm/Instruction.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/InstIterator.h"
-#include "Support/StatisticReporter.h"
+#include "Support/Statistic.h"
 #include <set>
 
-static Statistic<> DIEEliminated("die\t\t- Number of insts removed");
-static Statistic<> DCEEliminated("dce\t\t- Number of insts removed");
+namespace {
+  Statistic<> DIEEliminated("die", "Number of insts removed");
+  Statistic<> DCEEliminated("dce", "Number of insts removed");
 
-//===----------------------------------------------------------------------===//
-// DeadInstElimination pass implementation
-//
+  //===--------------------------------------------------------------------===//
+  // DeadInstElimination pass implementation
+  //
 
-namespace {
   struct DeadInstElimination : public BasicBlockPass {
-    const char *getPassName() const { return "Dead Instruction Elimination"; }
-    
-    virtual bool runOnBasicBlock(BasicBlock *BB) {
-      BasicBlock::InstListType &Vals = BB->getInstList();
+    virtual bool runOnBasicBlock(BasicBlock &BB) {
       bool Changed = false;
-      for (BasicBlock::iterator DI = Vals.begin(); DI != Vals.end(); )
-        if (dceInstruction(Vals, DI)) {
+      for (BasicBlock::iterator DI = BB.begin(); DI != BB.end(); )
+        if (dceInstruction(DI)) {
           Changed = true;
           ++DIEEliminated;
         } else
@@ -41,9 +45,11 @@ namespace {
     }
 
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      AU.preservesCFG();
+      AU.setPreservesCFG();
     }
   };
+  
+  RegisterOpt<DeadInstElimination> X("die", "Dead Instruction Elimination");
 }
 
 Pass *createDeadInstEliminationPass() {
@@ -58,17 +64,17 @@ Pass *createDeadInstEliminationPass() {
 
 namespace {
   struct DCE : public FunctionPass {
-    const char *getPassName() const { return "Dead Code Elimination"; }
-
-    virtual bool runOnFunction(Function *F);
+    virtual bool runOnFunction(Function &F);
 
      virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      AU.preservesCFG();
+      AU.setPreservesCFG();
     }
  };
+
+  RegisterOpt<DCE> Y("dce", "Dead Code Elimination");
 }
 
-bool DCE::runOnFunction(Function *F) {
+bool DCE::runOnFunction(Function &F) {
   // Start out with all of the instructions in the worklist...
   std::vector<Instruction*> WorkList(inst_begin(F), inst_end(F));
   std::set<Instruction*> DeadInsts;
@@ -103,16 +109,14 @@ bool DCE::runOnFunction(Function *F) {
   if (DeadInsts.empty()) return false;
 
   // Otherwise, loop over the program, removing and deleting the instructions...
-  for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
-    BasicBlock::InstListType &BBIL = (*I)->getInstList();
-    for (BasicBlock::iterator BI = BBIL.begin(); BI != BBIL.end(); )
-      if (DeadInsts.count(*BI)) {            // Is this instruction dead?
-        delete BBIL.remove(BI);              // Yup, remove and delete inst
+  for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
+    for (BasicBlock::iterator BI = I->begin(); BI != I->end(); )
+      if (DeadInsts.count(BI)) {             // Is this instruction dead?
+        BI = I->getInstList().erase(BI);     // Yup, remove and delete inst
         ++DCEEliminated;
       } else {                               // This instruction is not dead
         ++BI;                                // Continue on to the next one...
       }
-  }
 
   return true;
 }