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(NumFunctionsProcessed, "Number of functions processed"); +STATISTIC(NumCleanupLandingPads, "Number of cleanup landing pads in program"); +STATISTIC(NumCleanupLandingPadsUnreachable, + "Number of cleanup landing pads found unreachable"); +STATISTIC(NumNoUnwind, "Number of functions with nounwind"); namespace { @@ -163,6 +168,9 @@ bool DwarfEHPrepare::InsertUnwindResumeCalls() { SmallVector Resumes; SmallVector CleanupLPads; + NumFunctionsProcessed++; + if (F.doesNotThrow()) + NumNoUnwind++; for (BasicBlock &BB : F) { if (auto *RI = dyn_cast(BB.getTerminator())) Resumes.push_back(RI); @@ -171,6 +179,8 @@ CleanupLPads.push_back(LP); } + NumCleanupLandingPads += CleanupLPads.size(); + if (Resumes.empty()) return false; @@ -182,8 +192,18 @@ 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; +#endif + } if (ResumesLeft == 0) return true; // We pruned them all.