Add comment.
[oota-llvm.git] / lib / Transforms / Scalar / SimplifyCFG.cpp
index 9d0757a7146e0200af636714af071d65445e2f3d..5cb2b4086b8af4cf05f3cb78323ff0813cbdb1b4 100644 (file)
@@ -26,7 +26,6 @@
 #include "llvm/Transforms/Utils/Local.h"
 #include "llvm/Constants.h"
 #include "llvm/Instructions.h"
-#include "llvm/Intrinsics.h"
 #include "llvm/Module.h"
 #include "llvm/ParameterAttributes.h"
 #include "llvm/Support/CFG.h"
@@ -155,33 +154,23 @@ static bool RemoveUnreachableBlocks(Function &F) {
   bool Changed = MarkAliveBlocks(F.begin(), Reachable);
   
   // If there are unreachable blocks in the CFG...
-  if (Reachable.size() == F.size()) {
-    if (F.size() == 1) {
-      // If the function has only one block with an "unreachable" instruction,
-      // then we should create *some* code for it. Issue a "trap" instead.
-      BasicBlock &BB = F.front();
-
-      if (BB.size() == 1 && dyn_cast<UnreachableInst>(&BB.front()))
-        new CallInst(Intrinsic::getDeclaration(F.getParent(),
-                                               Intrinsic::trap),
-                     "", &BB.front());
-    }
-
+  if (Reachable.size() == F.size())
     return Changed;
-  }
   
   assert(Reachable.size() < F.size());
   NumSimpl += F.size()-Reachable.size();
   
   // Loop over all of the basic blocks that are not reachable, dropping all of
   // their internal references...
-  for (Function::iterator BB = ++F.begin(), E = F.end(); BB != E; ++BB)
-    if (!Reachable.count(BB)) {
-      for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI!=SE; ++SI)
-        if (Reachable.count(*SI))
-          (*SI)->removePredecessor(BB);
-      BB->dropAllReferences();
-    }
+  for (Function::iterator BB = ++F.begin(), E = F.end(); BB != E; ++BB) {
+    if (Reachable.count(BB))
+      continue;
+    
+    for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI)
+      if (Reachable.count(*SI))
+        (*SI)->removePredecessor(BB);
+    BB->dropAllReferences();
+  }
   
   for (Function::iterator I = ++F.begin(); I != F.end();)
     if (!Reachable.count(I))