//
// The LLVM Compiler Infrastructure
//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
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(); }
// 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.
//
if (F == 0) {
SCCMightUnwind = true;
SCCMightReturn = true;
- } else if (F->isDeclaration()) {
+ } else if (F->isDeclaration() || F->hasWeakLinkage()) {
SCCMightUnwind |= !F->doesNotThrow();
SCCMightReturn |= !F->doesNotReturn();
} else {
// If the SCC doesn't unwind or doesn't throw, note this fact.
if (!SCCMightUnwind || !SCCMightReturn)
for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
- const ParamAttrsList *PAL = SCC[i]->getFunction()->getParamAttrs();
- uint16_t RAttributes = PAL ? PAL->getParamAttrs(0) : 0;
+ ParameterAttributes NewAttributes = ParamAttr::None;
if (!SCCMightUnwind)
- RAttributes |= ParamAttr::NoUnwind;
+ NewAttributes |= ParamAttr::NoUnwind;
if (!SCCMightReturn)
- RAttributes |= ParamAttr::NoReturn;
+ NewAttributes |= ParamAttr::NoReturn;
- ParamAttrsVector modVec;
- modVec.push_back(ParamAttrsWithIndex::get(0, RAttributes));
- PAL = ParamAttrsList::getModified(PAL, modVec);
- 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) {
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());
// 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();
++NumUnreach;
break;
}
-
}
+
return MadeChange;
}