Add a clear() method to PriorityQueue.
[oota-llvm.git] / lib / Transforms / IPO / PruneEH.cpp
index 4e621dc2f9377053e889d1229ee7589df081a062..d4194a1060eec96c76580b9ad51cb5abebf4c3c4 100644 (file)
@@ -25,7 +25,6 @@
 #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;
@@ -44,11 +43,12 @@ namespace {
     bool SimplifyFunction(Function *F);
     void DeleteBasicBlock(BasicBlock *BB);
   };
-
-  char PruneEH::ID = 0;
-  RegisterPass<PruneEH> X("prune-eh", "Remove unused exception handling info");
 }
 
+char PruneEH::ID = 0;
+static RegisterPass<PruneEH>
+X("prune-eh", "Remove unused exception handling info");
+
 Pass *llvm::createPruneEHPass() { return new PruneEH(); }
 
 
@@ -64,6 +64,8 @@ bool PruneEH::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
 
   // Next, check to see if any callees might throw or if there are any external
   // functions in this SCC: if so, we cannot prune any functions in this SCC.
+  // Definitions that are weak and not declared non-throwing might be 
+  // overridden at linktime with something that throws, so assume that.
   // If this SCC includes the unwind instruction, we KNOW it throws, so
   // obviously the SCC might throw.
   //
@@ -74,7 +76,7 @@ bool PruneEH::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
     if (F == 0) {
       SCCMightUnwind = true;
       SCCMightReturn = true;
-    } else if (F->isDeclaration()) {
+    } else if (F->isDeclaration() || F->hasWeakLinkage()) {
       SCCMightUnwind |= !F->doesNotThrow();
       SCCMightReturn |= !F->doesNotReturn();
     } else {
@@ -130,9 +132,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) {
@@ -157,8 +158,8 @@ bool PruneEH::SimplifyFunction(Function *F) {
       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());
@@ -171,7 +172,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();
@@ -202,8 +203,8 @@ bool PruneEH::SimplifyFunction(Function *F) {
           ++NumUnreach;
           break;
         }
-
   }
+
   return MadeChange;
 }