[llvm] a60405c - [LTO][Legacy] Add -debug-pass-manager option to enable pass run/skip trace.

Wael Yehia via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 29 05:18:33 PDT 2021


Author: Wael Yehia
Date: 2021-09-29T12:17:53Z
New Revision: a60405cf035dc114e7ee090139bed2577f4ea7ef

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

LOG: [LTO][Legacy] Add -debug-pass-manager option to enable pass run/skip trace.

Reviewed by: steven_wu, fhahn, tejohnson

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

Added: 
    llvm/test/tools/llvm-lto/lto-passes.ll

Modified: 
    llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h
    llvm/lib/LTO/LTO.cpp
    llvm/lib/LTO/LTOCodeGenerator.cpp
    llvm/lib/LTO/ThinLTOCodeGenerator.cpp
    llvm/tools/llvm-lto/llvm-lto.cpp
    llvm/tools/llvm-lto2/llvm-lto2.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h b/llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h
index b8daea9441e0d..062be3537e15a 100644
--- a/llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h
+++ b/llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h
@@ -229,9 +229,6 @@ class ThinLTOCodeGenerator {
   /// Enable or disable the new pass manager.
   void setUseNewPM(unsigned Enabled) { UseNewPM = Enabled; }
 
-  /// Enable or disable debug output for the new pass manager.
-  void setDebugPassManager(unsigned Enabled) { DebugPassManager = Enabled; }
-
   /// Disable CodeGen, only run the stages till codegen and stop. The output
   /// will be bitcode.
   void disableCodeGen(bool Disable) { DisableCodeGen = Disable; }
@@ -351,10 +348,6 @@ class ThinLTOCodeGenerator {
   /// Flag to indicate whether the new pass manager should be used for IR
   /// optimizations.
   bool UseNewPM = LLVM_ENABLE_NEW_PASS_MANAGER;
-
-  /// Flag to indicate whether debug output should be enabled for the new pass
-  /// manager.
-  bool DebugPassManager = false;
 };
 }
 #endif

diff  --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 111fdc8f939ea..841ed4de318bc 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -73,6 +73,12 @@ cl::opt<bool> EnableLTOInternalization(
     "enable-lto-internalization", cl::init(true), cl::Hidden,
     cl::desc("Enable global value internalization in LTO"));
 
+namespace llvm {
+cl::opt<bool>
+    DebugPassManager("debug-pass-manager", cl::init(false), cl::Hidden,
+                     cl::desc("Print pass management debugging information"));
+}
+
 // Computes a unique hash for the Module considering the current list of
 // export/import and other global analysis results.
 // The hash is produced in \p Key.

diff  --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index 7bffcbf01b03a..5d7252e63c148 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -117,6 +117,8 @@ cl::opt<std::string> LTOStatsFile(
     "lto-stats-file",
     cl::desc("Save statistics to the specified file"),
     cl::Hidden);
+
+extern cl::opt<bool> DebugPassManager;
 }
 
 LTOCodeGenerator::LTOCodeGenerator(LLVMContext &Context)
@@ -130,6 +132,7 @@ LTOCodeGenerator::LTOCodeGenerator(LLVMContext &Context)
   Config.PreCodeGenPassesHook = [](legacy::PassManager &PM) {
     PM.add(createObjCARCContractPass());
   };
+  Config.DebugPassManager = DebugPassManager;
 }
 
 LTOCodeGenerator::~LTOCodeGenerator() {}

diff  --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index e9602b3eb9d13..d1966ca9c1c3b 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -84,6 +84,7 @@ extern cl::opt<bool> RemarksWithHotness;
 extern cl::opt<Optional<uint64_t>, false, remarks::HotnessThresholdParser>
     RemarksHotnessThreshold;
 extern cl::opt<std::string> RemarksFormat;
+extern cl::opt<bool> DebugPassManager;
 }
 
 namespace {
@@ -269,7 +270,6 @@ static void optimizeModule(Module &TheModule, TargetMachine &TM,
 
 static void optimizeModuleNewPM(Module &TheModule, TargetMachine &TM,
                                 unsigned OptLevel, bool Freestanding,
-                                bool DebugPassManager,
                                 ModuleSummaryIndex *Index) {
   Optional<PGOOptions> PGOOpt;
   LoopAnalysisManager LAM;
@@ -489,7 +489,7 @@ ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index,
                      const ThinLTOCodeGenerator::CachingOptions &CacheOptions,
                      bool DisableCodeGen, StringRef SaveTempsDir,
                      bool Freestanding, unsigned OptLevel, unsigned count,
-                     bool UseNewPM, bool DebugPassManager) {
+                     bool UseNewPM) {
 
   // "Benchmark"-like optimization: single-source case
   bool SingleModule = (ModuleMap.size() == 1);
@@ -530,8 +530,7 @@ ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index,
   }
 
   if (UseNewPM)
-    optimizeModuleNewPM(TheModule, TM, OptLevel, Freestanding, DebugPassManager,
-                        &Index);
+    optimizeModuleNewPM(TheModule, TM, OptLevel, Freestanding, &Index);
   else
     optimizeModule(TheModule, TM, OptLevel, Freestanding, &Index);
 
@@ -1219,7 +1218,7 @@ void ThinLTOCodeGenerator::run() {
             ExportList, GUIDPreservedSymbols,
             ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions,
             DisableCodeGen, SaveTempsDir, Freestanding, OptLevel, count,
-            UseNewPM, DebugPassManager);
+            UseNewPM);
 
         // Commit to the cache (if enabled)
         CacheEntry.write(*OutputBuffer);

diff  --git a/llvm/test/tools/llvm-lto/lto-passes.ll b/llvm/test/tools/llvm-lto/lto-passes.ll
new file mode 100644
index 0000000000000..c8424ec4f3d8b
--- /dev/null
+++ b/llvm/test/tools/llvm-lto/lto-passes.ll
@@ -0,0 +1,12 @@
+; Test that -debug-pass-manager works in LTOCodeGenerator. The actual list of
+; passes that is run during LTO is tested in:
+;    llvm/test/Other/new-pm-lto-defaults.ll
+;
+; RUN: llvm-as < %s > %t.bc
+; RUN: llvm-lto %t.bc -O0 --debug-pass-manager 2>&1 | FileCheck %s
+; CHECK: Running pass: WholeProgramDevirtPass
+
+define i32 @main() {
+entry:
+  ret i32 42
+}

diff  --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp
index 45cca0f976118..dbf0b18a9efb9 100644
--- a/llvm/tools/llvm-lto/llvm-lto.cpp
+++ b/llvm/tools/llvm-lto/llvm-lto.cpp
@@ -259,11 +259,6 @@ static cl::opt<bool> UseNewPM(
     "use-new-pm", cl::desc("Run LTO passes using the new pass manager"),
     cl::init(LLVM_ENABLE_NEW_PASS_MANAGER), cl::Hidden, cl::cat(LTOCategory));
 
-static cl::opt<bool>
-    DebugPassManager("debug-pass-manager", cl::init(false), cl::Hidden,
-                     cl::desc("Print pass management debugging information"),
-                     cl::cat(LTOCategory));
-
 namespace {
 
 struct ModuleInfo {
@@ -604,7 +599,6 @@ class ThinLTOProcessing {
     ThinGenerator.setCacheMaxSizeBytes(ThinLTOCacheMaxSizeBytes);
     ThinGenerator.setFreestanding(EnableFreestanding);
     ThinGenerator.setUseNewPM(UseNewPM);
-    ThinGenerator.setDebugPassManager(DebugPassManager);
 
     // Add all the exported symbols to the table of symbols to preserve.
     for (unsigned i = 0; i < ExportedSymbols.size(); ++i)

diff  --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp b/llvm/tools/llvm-lto2/llvm-lto2.cpp
index c0bff1eabee27..d6c69bc62e9ed 100644
--- a/llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -147,10 +147,6 @@ static cl::opt<bool>
              cl::desc("Run LTO passes using the new pass manager"),
              cl::init(LLVM_ENABLE_NEW_PASS_MANAGER), cl::Hidden);
 
-static cl::opt<bool>
-    DebugPassManager("debug-pass-manager", cl::init(false), cl::Hidden,
-                     cl::desc("Print pass management debugging information"));
-
 static cl::opt<std::string>
     StatsFile("stats-file", cl::desc("Filename to write statistics to"));
 
@@ -172,6 +168,10 @@ static void check(Error E, std::string Msg) {
   exit(1);
 }
 
+namespace llvm {
+extern cl::opt<bool> DebugPassManager;
+}
+
 template <typename T> static T check(Expected<T> E, std::string Msg) {
   if (E)
     return std::move(*E);


        


More information about the llvm-commits mailing list