From e8ce880f1a66dffcad7955868be5193e782c09ca Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 28 Jul 2011 02:40:13 +0000 Subject: Automatically merge the landingpad clauses when we come across a callee's landingpad. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136329 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/InlineFunction.cpp | 40 ++++++++++----------------------- 1 file changed, 12 insertions(+), 28 deletions(-) (limited to 'lib/Transforms/Utils/InlineFunction.cpp') diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp index 135455e081..8eda3e0b0d 100644 --- a/lib/Transforms/Utils/InlineFunction.cpp +++ b/lib/Transforms/Utils/InlineFunction.cpp @@ -250,7 +250,7 @@ namespace { PHINode *InnerSelectorPHI; SmallVector UnwindDestPHIValues; - SmallVector CalleeLPads; + PHINode *InnerEHValuesPHI; LandingPadInst *CallerLPad; BasicBlock *SplitLPad; @@ -258,7 +258,7 @@ namespace { InvokeInliningInfo(InvokeInst *II) : OuterUnwindDest(II->getUnwindDest()), OuterSelector(0), InnerUnwindDest(0), InnerExceptionPHI(0), InnerSelectorPHI(0), - CallerLPad(0), SplitLPad(0) { + InnerEHValuesPHI(0), CallerLPad(0), SplitLPad(0) { // If there are PHI nodes in the unwind destination block, we // need to keep track of which values came into them from the // invoke before removing the edge from this block. @@ -289,10 +289,6 @@ namespace { BasicBlock *getInnerUnwindDest(); - void addCalleeLandingPad(LandingPadInst *LPI) { - CalleeLPads.push_back(LPI); - } - LandingPadInst *getLandingPadInst() const { return CallerLPad; } BasicBlock *getSplitLandingPad() { if (SplitLPad) return SplitLPad; @@ -311,11 +307,6 @@ namespace { /// to there. void forwardResume(ResumeInst *RI); - /// mergeLandingPadClauses - Visit all of the landing pad instructions which - /// supply the value for the ResumeInst, and merge the clauses from the new - /// destination (the caller's landing pad). - void mergeLandingPadClauses(ResumeInst *RI); - /// addIncomingPHIValuesFor - Add incoming-PHI values to the unwind /// destination block for the given basic block, using the values for the /// original invoke's source block. @@ -436,16 +427,6 @@ bool InvokeInliningInfo::forwardEHResume(CallInst *call, BasicBlock *src) { return true; } -/// mergeLandingPadClauses - Visit all of the landing pad instructions merge the -/// clauses from the new destination (the caller's landing pad). -void InvokeInliningInfo::mergeLandingPadClauses(ResumeInst *RI) { - for (SmallVectorImpl::iterator - I = CalleeLPads.begin(), E = CalleeLPads.end(); I != E; ++I) - for (unsigned i = 0, e = CallerLPad->getNumClauses(); i != e; ++i) - (*I)->addClause(CallerLPad->getClauseType(i), - CallerLPad->getClauseValue(i)); -} - /// forwardResume - Forward the 'resume' instruction to the caller's landing pad /// block. When the landing pad block has only one predecessor, this is a simple /// branch. When there is more than one predecessor, we need to split the @@ -498,15 +479,19 @@ static bool isCleanupOnlySelector(EHSelectorInst *selector) { /// Returns true to indicate that the next block should be skipped. static bool HandleCallsInBlockInlinedThroughInvoke(BasicBlock *BB, InvokeInliningInfo &Invoke) { + LandingPadInst *LPI = Invoke.getLandingPadInst(); + for (BasicBlock::iterator BBI = BB->begin(), E = BB->end(); BBI != E; ) { Instruction *I = BBI++; - // Collect the callee's landingpad instructions. - if (LandingPadInst *LPI = dyn_cast(I)) { - Invoke.addCalleeLandingPad(LPI); - continue; - } - + if (LPI) // FIXME: This won't be NULL in the new EH. + if (LandingPadInst *L = dyn_cast(I)) { + unsigned NumClauses = LPI->getNumClauses(); + L->reserveClauses(NumClauses); + for (unsigned i = 0; i != NumClauses; ++i) + L->addClause(LPI->getClauseType(i), LPI->getClauseValue(i)); + } + // We only need to check for function calls: inlined invoke // instructions require no special handling. CallInst *CI = dyn_cast(I); @@ -642,7 +627,6 @@ static void HandleInlinedInvoke(InvokeInst *II, BasicBlock *FirstNewBlock, } if (ResumeInst *RI = dyn_cast(BB->getTerminator())) { - Invoke.mergeLandingPadClauses(RI); Invoke.forwardResume(RI); } } -- cgit v1.2.3