[llvm] 507cba2 - [StandardInstrumentations][NFC] Minor code cleanup

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 14 10:04:48 PDT 2023


Author: Arthur Eubanks
Date: 2023-03-14T10:04:33-07:00
New Revision: 507cba21c382ced5fc075ac74637847fbc2a4c07

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

LOG: [StandardInstrumentations][NFC] Minor code cleanup

Added: 
    

Modified: 
    llvm/include/llvm/Passes/StandardInstrumentations.h
    llvm/lib/Passes/StandardInstrumentations.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Passes/StandardInstrumentations.h b/llvm/include/llvm/Passes/StandardInstrumentations.h
index c8614ec496883..3b748f5e9f44c 100644
--- a/llvm/include/llvm/Passes/StandardInstrumentations.h
+++ b/llvm/include/llvm/Passes/StandardInstrumentations.h
@@ -152,7 +152,6 @@ class PreservedCFGCheckerInstrumentation {
   SmallVector<StringRef, 8> PassStack;
 #endif
 
-  static cl::opt<bool> VerifyPreservedCFG;
   void registerCallbacks(PassInstrumentationCallbacks &PIC,
                          FunctionAnalysisManager &FAM);
 };

diff  --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 065f85f4e11fb..3a782601bd3c3 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -43,14 +43,13 @@
 
 using namespace llvm;
 
-cl::opt<bool> PreservedCFGCheckerInstrumentation::VerifyPreservedCFG(
-    "verify-cfg-preserved", cl::Hidden,
+static cl::opt<bool> VerifyPreservedCFG("verify-cfg-preserved", cl::Hidden,
 #ifdef NDEBUG
-    cl::init(false)
+                                        cl::init(false)
 #else
-    cl::init(true)
+                                        cl::init(true)
 #endif
-    );
+);
 
 // An option that supports the -print-changed option.  See
 // the description for -print-changed for an explanation of the use
@@ -1064,19 +1063,6 @@ void PreservedCFGCheckerInstrumentation::registerCallbacks(
 
   FAM.registerPass([&] { return PreservedCFGCheckerAnalysis(); });
 
-  auto checkCFG = [](StringRef Pass, StringRef FuncName, const CFG &GraphBefore,
-                     const CFG &GraphAfter) {
-    if (GraphAfter == GraphBefore)
-      return;
-
-    dbgs() << "Error: " << Pass
-           << " does not invalidate CFG analyses but CFG changes detected in "
-              "function @"
-           << FuncName << ":\n";
-    CFG::printDiff(dbgs(), GraphBefore, GraphAfter);
-    report_fatal_error(Twine("CFG unexpectedly changed by ", Pass));
-  };
-
   PIC.registerBeforeNonSkippedPassCallback(
       [this, &FAM](StringRef P, Any IR) {
 #ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
@@ -1100,9 +1086,8 @@ void PreservedCFGCheckerInstrumentation::registerCallbacks(
         (void)this;
       });
 
-  PIC.registerAfterPassCallback([this, &FAM,
-                                 checkCFG](StringRef P, Any IR,
-                                           const PreservedAnalyses &PassPA) {
+  PIC.registerAfterPassCallback([this, &FAM](StringRef P, Any IR,
+                                             const PreservedAnalyses &PassPA) {
 #ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
     assert(PassStack.pop_back_val() == P &&
            "Before and After callbacks must correspond");
@@ -1117,9 +1102,22 @@ void PreservedCFGCheckerInstrumentation::registerCallbacks(
         !PassPA.allAnalysesInSetPreserved<AllAnalysesOn<Function>>())
       return;
 
+    auto CheckCFG = [](StringRef Pass, StringRef FuncName,
+                       const CFG &GraphBefore, const CFG &GraphAfter) {
+      if (GraphAfter == GraphBefore)
+        return;
+
+      dbgs() << "Error: " << Pass
+             << " does not invalidate CFG analyses but CFG changes detected in "
+                "function @"
+             << FuncName << ":\n";
+      CFG::printDiff(dbgs(), GraphBefore, GraphAfter);
+      report_fatal_error(Twine("CFG unexpectedly changed by ", Pass));
+    };
+
     if (auto *GraphBefore = FAM.getCachedResult<PreservedCFGCheckerAnalysis>(
             *const_cast<Function *>(*F)))
-      checkCFG(P, (*F)->getName(), *GraphBefore,
+      CheckCFG(P, (*F)->getName(), *GraphBefore,
                CFG(*F, /* TrackBBLifetime */ false));
   });
 }


        


More information about the llvm-commits mailing list