X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTransforms%2FUtils%2FInlineFunction.cpp;h=e9f0e28ad6506b900bb991909b5ceea9721d7b13;hb=f48509787acfcfc3f9eee2fb3084c2e8c7b4a009;hp=3e1022ef8c7af2a44bf3cc588bcede7401a4f520;hpb=d9ff8c83d137586d8c06f98bdf8adbf0d1fa79ca;p=oota-llvm.git diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp index 3e1022ef8c7..e9f0e28ad65 100644 --- a/lib/Transforms/Utils/InlineFunction.cpp +++ b/lib/Transforms/Utils/InlineFunction.cpp @@ -82,7 +82,8 @@ namespace { /// a simple branch. When there is more than one predecessor, we need to /// split the landing pad block after the landingpad instruction and jump /// to there. - void forwardResume(ResumeInst *RI, BasicBlock *FirstNewBlock); + void forwardResume(ResumeInst *RI, + SmallPtrSet &InlinedLPads); /// addIncomingPHIValuesFor - Add incoming-PHI values to the unwind /// destination block for the given basic block, using the values for the @@ -141,7 +142,7 @@ BasicBlock *InvokeInliningInfo::getInnerResumeDest() { /// branch. When there is more than one predecessor, we need to split the /// landing pad block after the landingpad instruction and jump to there. void InvokeInliningInfo::forwardResume(ResumeInst *RI, - BasicBlock *FirstNewBlock) { + SmallPtrSet &InlinedLPads) { BasicBlock *Dest = getInnerResumeDest(); LandingPadInst *OuterLPad = getLandingPadInst(); BasicBlock *Src = RI->getParent(); @@ -155,34 +156,14 @@ void InvokeInliningInfo::forwardResume(ResumeInst *RI, InnerEHValuesPHI->addIncoming(RI->getOperand(0), Src); RI->eraseFromParent(); - // Get all of the inlined landing pad instructions. - SmallPtrSet InlinedLPads; - Function *Caller = FirstNewBlock->getParent(); - for (Function::iterator I = FirstNewBlock, E = Caller->end(); I != E; ++I) - if (InvokeInst *II = dyn_cast(I->getTerminator())) { - LandingPadInst *LPI = II->getLandingPadInst(); - if (!LPI->hasCatchAll()) - InlinedLPads.insert(LPI); - } - - // Merge the catch clauses from the outer landing pad instruction into the - // inlined landing pad instructions. + // Append the clauses from the outer landing pad instruction into the inlined + // landing pad instructions. for (SmallPtrSet::iterator I = InlinedLPads.begin(), E = InlinedLPads.end(); I != E; ++I) { LandingPadInst *InlinedLPad = *I; for (unsigned OuterIdx = 0, OuterNum = OuterLPad->getNumClauses(); - OuterIdx != OuterNum; ++OuterIdx) { - bool hasClause = false; - if (OuterLPad->isFilter(OuterIdx)) continue; - Value *OuterClause = OuterLPad->getClause(OuterIdx); - for (unsigned Idx = 0, N = InlinedLPad->getNumClauses(); Idx != N; ++Idx) - if (OuterClause == InlinedLPad->getClause(Idx)) { - hasClause = true; - break; - } - if (!hasClause) - InlinedLPad->addClause(OuterClause); - } + OuterIdx != OuterNum; ++OuterIdx) + InlinedLPad->addClause(OuterLPad->getClause(OuterIdx)); } } @@ -264,6 +245,12 @@ static void HandleInlinedInvoke(InvokeInst *II, BasicBlock *FirstNewBlock, // rewrite. InvokeInliningInfo Invoke(II); + // Get all of the inlined landing pad instructions. + SmallPtrSet InlinedLPads; + for (Function::iterator I = FirstNewBlock, E = Caller->end(); I != E; ++I) + if (InvokeInst *II = dyn_cast(I->getTerminator())) + InlinedLPads.insert(II->getLandingPadInst()); + for (Function::iterator BB = FirstNewBlock, E = Caller->end(); BB != E; ++BB){ if (InlinedCodeInfo.ContainsCalls) if (HandleCallsInBlockInlinedThroughInvoke(BB, Invoke)) { @@ -274,7 +261,7 @@ static void HandleInlinedInvoke(InvokeInst *II, BasicBlock *FirstNewBlock, // Forward any resumes that are remaining here. if (ResumeInst *RI = dyn_cast(BB->getTerminator())) - Invoke.forwardResume(RI, FirstNewBlock); + Invoke.forwardResume(RI, InlinedLPads); } // Now that everything is happy, we have one final detail. The PHI nodes in @@ -771,8 +758,10 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI, // If the call site was an invoke instruction, add a branch to the normal // destination. - if (InvokeInst *II = dyn_cast(TheCall)) - BranchInst::Create(II->getNormalDest(), TheCall); + if (InvokeInst *II = dyn_cast(TheCall)) { + BranchInst *NewBr = BranchInst::Create(II->getNormalDest(), TheCall); + NewBr->setDebugLoc(Returns[0]->getDebugLoc()); + } // If the return instruction returned a value, replace uses of the call with // uses of the returned value. @@ -800,15 +789,16 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI, // "starter" and "ender" blocks. How we accomplish this depends on whether // this is an invoke instruction or a call instruction. BasicBlock *AfterCallBB; + BranchInst *CreatedBranchToNormalDest = NULL; if (InvokeInst *II = dyn_cast(TheCall)) { // Add an unconditional branch to make this look like the CallInst case... - BranchInst *NewBr = BranchInst::Create(II->getNormalDest(), TheCall); + CreatedBranchToNormalDest = BranchInst::Create(II->getNormalDest(), TheCall); // Split the basic block. This guarantees that no PHI nodes will have to be // updated due to new incoming edges, and make the invoke case more // symmetric to the call case. - AfterCallBB = OrigBB->splitBasicBlock(NewBr, + AfterCallBB = OrigBB->splitBasicBlock(CreatedBranchToNormalDest, CalledFunc->getName()+".exit"); } else { // It's a call @@ -887,6 +877,9 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI, AfterCallBB->getInstList().splice(AfterCallBB->begin(), ReturnBB->getInstList()); + if (CreatedBranchToNormalDest) + CreatedBranchToNormalDest->setDebugLoc(Returns[0]->getDebugLoc()); + // Delete the return instruction now and empty ReturnBB now. Returns[0]->eraseFromParent(); ReturnBB->eraseFromParent();