Update the inliner and simplifycfg to handle unwind_to.
[oota-llvm.git] / lib / Transforms / Utils / InlineFunction.cpp
index 64e6056b73fb455193c0fab298538912f2a54fcf..9ccc918aca4853d63ca0a9a9a749c9c0efc182e5 100644 (file)
@@ -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.