From: Bill Wendling Date: Mon, 14 Sep 2009 20:52:37 +0000 (+0000) Subject: Pull the creation of the "RewindFunction" function out of the loop. It's only X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=43488710a8dc76b39f9f3b628c2fdd5d34aa0dbb;p=oota-llvm.git Pull the creation of the "RewindFunction" function out of the loop. It's only created once, so shouldn't be stuck in the middle of the loop. Also early exit if there are no uses of UnwindInst in the function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81785 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/DwarfEHPrepare.cpp b/lib/CodeGen/DwarfEHPrepare.cpp index a2e6068ff87..be6205e174a 100644 --- a/lib/CodeGen/DwarfEHPrepare.cpp +++ b/lib/CodeGen/DwarfEHPrepare.cpp @@ -219,29 +219,40 @@ bool DwarfEHPrepare::NormalizeLandingPads() { /// at runtime if there is no such exception: using unwind to throw a new /// exception is currently not supported. bool DwarfEHPrepare::LowerUnwinds() { - bool Changed = false; + SmallVector UnwindInsts; for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) { TerminatorInst *TI = I->getTerminator(); - if (!isa(TI)) - continue; + if (isa(TI)) + UnwindInsts.push_back(TI); + } + + if (UnwindInsts.empty()) return false; + + // Find the rewind function if we didn't already. + if (!RewindFunction) { + LLVMContext &Ctx = UnwindInsts[0]->getContext(); + std::vector + Params(1, PointerType::getUnqual(Type::getInt8Ty(Ctx))); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), + Params, false); + const char *RewindName = TLI->getLibcallName(RTLIB::UNWIND_RESUME); + RewindFunction = F->getParent()->getOrInsertFunction(RewindName, FTy); + } + + bool Changed = false; + + for (SmallVectorImpl::iterator + I = UnwindInsts.begin(), E = UnwindInsts.end(); I != E; ++I) { + TerminatorInst *TI = *I; // Replace the unwind instruction with a call to _Unwind_Resume (or the // appropriate target equivalent) followed by an UnreachableInst. - // Find the rewind function if we didn't already. - if (!RewindFunction) { - std::vector Params(1, - PointerType::getUnqual(Type::getInt8Ty(TI->getContext()))); - FunctionType *FTy = FunctionType::get(Type::getVoidTy(TI->getContext()), - Params, false); - const char *RewindName = TLI->getLibcallName(RTLIB::UNWIND_RESUME); - RewindFunction = F->getParent()->getOrInsertFunction(RewindName, FTy); - } - // Create the call... CallInst *CI = CallInst::Create(RewindFunction, - CreateReadOfExceptionValue(I), "", TI); + CreateReadOfExceptionValue(TI->getParent()), + "", TI); CI->setCallingConv(TLI->getLibcallCallingConv(RTLIB::UNWIND_RESUME)); // ...followed by an UnreachableInst. new UnreachableInst(TI->getContext(), TI);