Function.h is unnecessary when Module.h is included.
[oota-llvm.git] / lib / Transforms / Scalar / ADCE.cpp
index 062b52ff50c0e090e688854084d937fc684596a4..7d1d896bd226d6f1f353243a8c5a16fc72952eb5 100644 (file)
@@ -10,7 +10,7 @@
 #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"
@@ -235,11 +235,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 +353,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();