Index: llvm/lib/CodeGen/DwarfEHPrepare.cpp =================================================================== --- llvm/lib/CodeGen/DwarfEHPrepare.cpp +++ llvm/lib/CodeGen/DwarfEHPrepare.cpp @@ -42,6 +42,11 @@ #define DEBUG_TYPE "dwarfehprepare" STATISTIC(NumResumesLowered, "Number of resume calls lowered"); +STATISTIC(NumCleanupLandingPadsUnreachable, + "Number of cleanup landing pads found unreachable"); +STATISTIC(NumCleanupLandingPadsRemaining, "Number of cleanup landing pads remaining"); +STATISTIC(NumNoUnwind, "Number of functions with nounwind"); +STATISTIC(NumUnwind, "Number of functions with unwind"); namespace { @@ -163,6 +168,10 @@ bool DwarfEHPrepare::InsertUnwindResumeCalls() { SmallVector Resumes; SmallVector CleanupLPads; + if (F.doesNotThrow()) + NumNoUnwind++; + else + NumUnwind++; for (BasicBlock &BB : F) { if (auto *RI = dyn_cast(BB.getTerminator())) Resumes.push_back(RI); @@ -171,6 +180,8 @@ CleanupLPads.push_back(LP); } + NumCleanupLandingPadsRemaining += CleanupLPads.size(); + if (Resumes.empty()) return false; @@ -182,8 +193,19 @@ LLVMContext &Ctx = F.getContext(); size_t ResumesLeft = Resumes.size(); - if (OptLevel != CodeGenOpt::None) + if (OptLevel != CodeGenOpt::None) { ResumesLeft = pruneUnreachableResumes(Resumes, CleanupLPads); +#if LLVM_ENABLE_STATS + unsigned NumRemainingLPs = 0; + for (BasicBlock &BB : F) { + if (auto *LP = BB.getLandingPadInst()) + if (LP->isCleanup()) + NumRemainingLPs++; + } + NumCleanupLandingPadsUnreachable += CleanupLPads.size() - NumRemainingLPs; + NumCleanupLandingPadsRemaining -= CleanupLPads.size() - NumRemainingLPs; +#endif + } if (ResumesLeft == 0) return true; // We pruned them all.