+ // Stop when we hit a pad that generates real code or we unwind to caller.
+ // Catchpads are conditional branches that add real MBB destinations and
+ // continue the loop. EH "end" pads are not real BBs and simply continue.
+ SmallVector<MachineBasicBlock *, 1> UnwindDests;
+ while (EHPadBB) {
+ const Instruction *Pad = EHPadBB->getFirstNonPHI();
+ if (isa<CleanupPadInst>(Pad) || isa<LandingPadInst>(Pad)) {
+ assert(FuncInfo.MBBMap[EHPadBB]);
+ // Stop on cleanup pads and landingpads.
+ UnwindDests.push_back(FuncInfo.MBBMap[EHPadBB]);
+ break;
+ } else if (const auto *CPI = dyn_cast<CatchPadInst>(Pad)) {
+ // Add the catchpad handler to the possible destinations.
+ UnwindDests.push_back(FuncInfo.MBBMap[CPI->getNormalDest()]);
+ EHPadBB = CPI->getUnwindDest();
+ } else if (const auto *CEPI = dyn_cast<CatchEndPadInst>(Pad)) {
+ EHPadBB = CEPI->getUnwindDest();
+ } else if (const auto *CEPI = dyn_cast<CleanupEndPadInst>(Pad)) {
+ EHPadBB = CEPI->getUnwindDest();
+ }
+ }
+