#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 {
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) {
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());
// 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();
++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
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;
}