[llvm] a7b6269 - [NFC] [DwarfEHPrepare] Add additional stats for EH

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 23 17:13:55 PDT 2021


Author: modimo
Date: 2021-06-23T17:09:30-07:00
New Revision: a7b62699c8dcdcf14bac9560eb970da4296ce993

URL: https://github.com/llvm/llvm-project/commit/a7b62699c8dcdcf14bac9560eb970da4296ce993
DIFF: https://github.com/llvm/llvm-project/commit/a7b62699c8dcdcf14bac9560eb970da4296ce993.diff

LOG: [NFC] [DwarfEHPrepare] Add additional stats for EH

Stats added:

1. NumCleanupLandingPadsUnreachable: how many cleanup landing pads were optimized as unreachable
1. NumCleanupLandingPadsRemaining: how many cleanup landing pads remain
1. NumNoUnwind: Number of functions with nounwind attribute
1. NumUnwind: Number of functions with unwind attribute

DwarfEHPrepare is always run a single time as part of `TargetPassConfig::addISelPasses()` which makes it an ideal place near the end of the pipeline to record this information.

Example output from clang built with exceptions cumulative during thinLTO backend (NumCleanupLandingPadsUnreachable was not incremented):

	"dwarfehprepare.NumCleanupLandingPadsRemaining": 123660,
	"dwarfehprepare.NumNoUnwind": 323836,
	"dwarfehprepare.NumUnwind": 472893,

Reviewed By: wenlei

Differential Revision: https://reviews.llvm.org/D104161

Added: 
    

Modified: 
    llvm/lib/CodeGen/DwarfEHPrepare.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/DwarfEHPrepare.cpp b/llvm/lib/CodeGen/DwarfEHPrepare.cpp
index 99d2522548c3..5ca1e91cc5f4 100644
--- a/llvm/lib/CodeGen/DwarfEHPrepare.cpp
+++ b/llvm/lib/CodeGen/DwarfEHPrepare.cpp
@@ -42,6 +42,12 @@ using namespace llvm;
 #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 +169,10 @@ size_t DwarfEHPrepare::pruneUnreachableResumes(
 bool DwarfEHPrepare::InsertUnwindResumeCalls() {
   SmallVector<ResumeInst *, 16> Resumes;
   SmallVector<LandingPadInst *, 16> CleanupLPads;
+  if (F.doesNotThrow())
+    NumNoUnwind++;
+  else
+    NumUnwind++;
   for (BasicBlock &BB : F) {
     if (auto *RI = dyn_cast<ResumeInst>(BB.getTerminator()))
       Resumes.push_back(RI);
@@ -171,6 +181,8 @@ bool DwarfEHPrepare::InsertUnwindResumeCalls() {
         CleanupLPads.push_back(LP);
   }
 
+  NumCleanupLandingPadsRemaining += CleanupLPads.size();
+
   if (Resumes.empty())
     return false;
 
@@ -182,8 +194,19 @@ bool DwarfEHPrepare::InsertUnwindResumeCalls() {
   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.


        


More information about the llvm-commits mailing list