Remove 'unwinds to' support from mainline. This patch undoes r47802 r47989
[oota-llvm.git] / lib / Transforms / IPO / PruneEH.cpp
index ec0558e80a945b6db865e4e4817e27271f0cd380..01816052569036882a41c9a21faa3c347aa7f42e 100644 (file)
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/ParamAttrsList.h"
 #include <set>
 #include <algorithm>
 using namespace llvm;
 
 STATISTIC(NumRemoved, "Number of invokes removed");
 STATISTIC(NumUnreach, "Number of noreturn calls optimized");
-STATISTIC(NumBBUnwind, "Number of unwind_to removed from blocks");
 
 namespace {
   struct VISIBILITY_HIDDEN PruneEH : public CallGraphSCCPass {
@@ -131,9 +129,8 @@ bool PruneEH::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
       if (!SCCMightReturn)
         NewAttributes |= ParamAttr::NoReturn;
 
-      const ParamAttrsList *PAL = SCC[i]->getFunction()->getParamAttrs();
-      PAL = ParamAttrsList::includeAttrs(PAL, 0, NewAttributes);
-      SCC[i]->getFunction()->setParamAttrs(PAL);
+      const PAListPtr &PAL = SCC[i]->getFunction()->getParamAttrs();
+      SCC[i]->getFunction()->setParamAttrs(PAL.addAttr(0, NewAttributes));
     }
 
   for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
@@ -154,14 +151,12 @@ bool PruneEH::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
 bool PruneEH::SimplifyFunction(Function *F) {
   bool MadeChange = false;
   for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
-    bool couldUnwind = false;
-
     if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator()))
       if (II->doesNotThrow()) {
         SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end());
         // Insert a call instruction before the invoke.
-        CallInst *Call = new CallInst(II->getCalledValue(),
-                                      Args.begin(), Args.end(), "", II);
+        CallInst *Call = CallInst::Create(II->getCalledValue(),
+                                          Args.begin(), Args.end(), "", II);
         Call->takeName(II);
         Call->setCallingConv(II->getCallingConv());
         Call->setParamAttrs(II->getParamAttrs());
@@ -174,7 +169,7 @@ bool PruneEH::SimplifyFunction(Function *F) {
 
         // Insert a branch to the normal destination right before the
         // invoke.
-        new BranchInst(II->getNormalDest(), II);
+        BranchInst::Create(II->getNormalDest(), II);
 
         // Finally, delete the invoke instruction!
         BB->getInstList().pop_back();
@@ -185,12 +180,10 @@ bool PruneEH::SimplifyFunction(Function *F) {
 
         ++NumRemoved;
         MadeChange = true;
-      } else {
-        couldUnwind = true;
       }
 
     for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; )
-      if (CallInst *CI = dyn_cast<CallInst>(I++)) {
+      if (CallInst *CI = dyn_cast<CallInst>(I++))
         if (CI->doesNotReturn() && !isa<UnreachableInst>(I)) {
           // This call calls a function that cannot return.  Insert an
           // unreachable instruction after it and simplify the code.  Do this
@@ -206,19 +199,9 @@ bool PruneEH::SimplifyFunction(Function *F) {
           MadeChange = true;
           ++NumUnreach;
           break;
-        } else if (!CI->doesNotThrow()) {
-          couldUnwind = true;
         }
-      }
-
-    // Strip 'unwindTo' off of BBs that have no calls/invokes without nounwind.
-    if (!couldUnwind && BB->getUnwindDest()) {
-      MadeChange = true;
-      ++NumBBUnwind;
-      BB->getUnwindDest()->removePredecessor(BB, false, true);
-      BB->setUnwindDest(NULL);
-    }
   }
+
   return MadeChange;
 }