Fix warning
[oota-llvm.git] / lib / Transforms / Scalar / ADCE.cpp
index 126a32b6f086071b7be4d0fd900ed8e38ef66a99..e2e9e86216cde540bbc4536f86660ad47cb47857 100644 (file)
 #include "llvm/Transforms/Utils/Local.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
 #include "llvm/Type.h"
-#include "llvm/Analysis/Dominators.h"
+#include "llvm/Analysis/PostDominators.h"
 #include "llvm/iTerminators.h"
 #include "llvm/iPHINode.h"
 #include "llvm/Constant.h"
 #include "llvm/Support/CFG.h"
 #include "Support/STLExtras.h"
 #include "Support/DepthFirstIterator.h"
-#include "Support/StatisticReporter.h"
+#include "Support/Statistic.h"
 #include <algorithm>
-#include <iostream>
 using std::cerr;
 using std::vector;
 
-static Statistic<> NumBlockRemoved("adce\t\t- Number of basic blocks removed");
-static Statistic<> NumInstRemoved ("adce\t\t- Number of instructions removed");
-
 namespace {
+  Statistic<> NumBlockRemoved("adce", "Number of basic blocks removed");
+  Statistic<> NumInstRemoved ("adce", "Number of instructions removed");
 
 //===----------------------------------------------------------------------===//
 // ADCE Class
@@ -55,8 +53,8 @@ public:
   // getAnalysisUsage - We require post dominance frontiers (aka Control
   // Dependence Graph)
   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-    AU.addRequired(PostDominatorTree::ID);
-    AU.addRequired(PostDominanceFrontier::ID);
+    AU.addRequired<PostDominatorTree>();
+    AU.addRequired<PostDominanceFrontier>();
   }
 
 
@@ -235,11 +233,15 @@ bool ADCE::doADCE() {
       dropReferencesOfDeadInstructionsInLiveBlock(I);
     
   } else {                                   // If there are some blocks dead...
-    // Insert a new entry node to eliminate the entry node as a special case.
-    BasicBlock *NewEntry = new BasicBlock();
-    NewEntry->getInstList().push_back(new BranchInst(&Func->front()));
-    Func->getBasicBlockList().push_front(NewEntry);
-    AliveBlocks.insert(NewEntry);    // This block is always alive!
+    // If the entry node is dead, insert a new entry node to eliminate the entry
+    // node as a special case.
+    //
+    if (!AliveBlocks.count(&Func->front())) {
+      BasicBlock *NewEntry = new BasicBlock();
+      NewEntry->getInstList().push_back(new BranchInst(&Func->front()));
+      Func->getBasicBlockList().push_front(NewEntry);
+      AliveBlocks.insert(NewEntry);    // This block is always alive!
+    }
     
     // Loop over all of the alive blocks in the function.  If any successor
     // blocks are not alive, we adjust the outgoing branches to branch to the
@@ -349,9 +351,8 @@ bool ADCE::doADCE() {
         // Delete the old terminator instruction...
         BB->getInstList().pop_back();
         const Type *RetTy = Func->getReturnType();
-        Instruction *New = new ReturnInst(RetTy != Type::VoidTy ?
-                                          Constant::getNullValue(RetTy) : 0);
-        BB->getInstList().push_back(New);
+        BB->getInstList().push_back(new ReturnInst(RetTy != Type::VoidTy ?
+                                           Constant::getNullValue(RetTy) : 0));
       }
 
       BB->dropAllReferences();