diff options
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Utils/InlineFunction.cpp | 13 | ||||
-rw-r--r-- | lib/Transforms/Utils/SimplifyCFG.cpp | 10 |
2 files changed, 22 insertions, 1 deletions
diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp index 64e6056..9ccc918 100644 --- a/lib/Transforms/Utils/InlineFunction.cpp +++ b/lib/Transforms/Utils/InlineFunction.cpp @@ -202,6 +202,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) { BasicBlock *OrigBB = TheCall->getParent(); Function *Caller = OrigBB->getParent(); + BasicBlock *UnwindBB = OrigBB->getUnwindDest(); // GC poses two hazards to inlining, which only occur when the callee has GC: // 1. If the caller has no GC, then the callee's GC must be propagated to the @@ -419,6 +420,18 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) { } } + // If we are inlining a function that unwinds into a BB with an unwind dest, + // turn the inlined unwinds into branches to the unwind dest. + if (InlinedFunctionInfo.ContainsUnwinds && UnwindBB && isa<CallInst>(TheCall)) + for (Function::iterator BB = FirstNewBlock, E = Caller->end(); + BB != E; ++BB) { + TerminatorInst *Term = BB->getTerminator(); + if (isa<UnwindInst>(Term)) { + new BranchInst(UnwindBB, Term); + BB->getInstList().erase(Term); + } + } + // If we are inlining for an invoke instruction, we must make sure to rewrite // any inlined 'unwind' instructions into branches to the invoke exception // destination, and call instructions into invoke instructions. diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 2092c8b..61da0d9 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1237,6 +1237,8 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { SmallVector<BasicBlock*, 8> UncondBranchPreds; SmallVector<BranchInst*, 8> CondBranchPreds; for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { + if ((*PI)->getUnwindDest() == BB) continue; + TerminatorInst *PTI = (*PI)->getTerminator(); if (BranchInst *BI = dyn_cast<BranchInst>(PTI)) { if (BI->isUnconditional()) @@ -1788,6 +1790,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { BasicBlock *OnlySucc = 0; if (OnlyPred && OnlyPred != BB && // Don't break self loops + OnlyPred->getUnwindDest() != BB && OnlyPred->getTerminator()->getOpcode() != Instruction::Invoke) { // Check to see if there is only one distinct successor... succ_iterator SI(succ_begin(OnlyPred)), SE(succ_end(OnlyPred)); @@ -1799,7 +1802,8 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { } } - if (OnlySucc) { + if (OnlySucc && (BB->getUnwindDest() == OnlyPred->getUnwindDest() || + !BB->getUnwindDest() || !OnlyPred->getUnwindDest())) { DOUT << "Merging: " << *BB << "into: " << *OnlyPred; // Resolve any PHI nodes at the start of the block. They are all @@ -1819,6 +1823,10 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { // Move all definitions in the successor to the predecessor. OnlyPred->getInstList().splice(OnlyPred->end(), BB->getInstList()); + // Move the unwind_to block + if (!OnlyPred->getUnwindDest() && BB->getUnwindDest()) + OnlyPred->setUnwindDest(BB->getUnwindDest()); + // Make all PHI nodes that referred to BB now refer to Pred as their // source. BB->replaceAllUsesWith(OnlyPred); |