+
+ // Get all of the inlined landing pad instructions.
+ SmallPtrSet<LandingPadInst*, 16> InlinedLPads;
+ Function *Caller = FirstNewBlock->getParent();
+ for (Function::iterator I = FirstNewBlock, E = Caller->end(); I != E; ++I)
+ if (InvokeInst *II = dyn_cast<InvokeInst>(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.
+ for (SmallPtrSet<LandingPadInst*, 16>::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);
+ }
+ }