[llvm] 26e455b - [lld][LTO] Teach LTO to print pipeline passes (#101018)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 29 12:56:46 PDT 2024


Author: macurtis-amd
Date: 2024-07-29T15:56:43-04:00
New Revision: 26e455bac0c44d75cb5d544c35e7c8326c91b4f3

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

LOG: [lld][LTO] Teach LTO to print pipeline passes (#101018)

I found this useful while debugging code generation differences between
old and new offloading drivers.
No functional change (intended).

Added: 
    llvm/test/LTO/X86/print-pipeline-passes.ll

Modified: 
    llvm/include/llvm/Passes/PassBuilder.h
    llvm/lib/LTO/LTOBackend.cpp
    llvm/tools/llc/NewPMDriver.cpp
    llvm/tools/opt/NewPMDriver.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h
index 474a19531ff5d..e1d78a8685aed 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -944,6 +944,10 @@ class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
     return Result();
   }
 };
+
+/// Common option used by multiple tools to print pipeline passes
+extern cl::opt<bool> PrintPipelinePasses;
+
 }
 
 #endif

diff  --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index d5d642f0d25e6..effaed2d9bfb6 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -335,6 +335,16 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
   if (!Conf.DisableVerify)
     MPM.addPass(VerifierPass());
 
+  if (PrintPipelinePasses) {
+    std::string PipelineStr;
+    raw_string_ostream OS(PipelineStr);
+    MPM.printPipeline(OS, [&PIC](StringRef ClassName) {
+      auto PassName = PIC.getPassNameForClassName(ClassName);
+      return PassName.empty() ? ClassName : PassName;
+    });
+    outs() << "pipeline-passes: " << PipelineStr << '\n';
+  }
+
   MPM.run(Mod, MAM);
 }
 

diff  --git a/llvm/test/LTO/X86/print-pipeline-passes.ll b/llvm/test/LTO/X86/print-pipeline-passes.ll
new file mode 100644
index 0000000000000..b24e3869c0a63
--- /dev/null
+++ b/llvm/test/LTO/X86/print-pipeline-passes.ll
@@ -0,0 +1,13 @@
+; RUN: llvm-as < %s >%t.bc
+; RUN: llvm-lto -print-pipeline-passes -exported-symbol=_f -o /dev/null %t.bc 2>&1 | FileCheck %s
+
+; CHECK: pipeline-passes: verify,{{.*}},verify
+
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.10.0"
+
+
+define void @f() {
+entry:
+  ret void
+}

diff  --git a/llvm/tools/llc/NewPMDriver.cpp b/llvm/tools/llc/NewPMDriver.cpp
index 31c089e6344d0..c8088da49a278 100644
--- a/llvm/tools/llc/NewPMDriver.cpp
+++ b/llvm/tools/llc/NewPMDriver.cpp
@@ -45,10 +45,6 @@
 #include "llvm/Transforms/Scalar/LoopPassManager.h"
 #include "llvm/Transforms/Utils/Cloning.h"
 
-namespace llvm {
-extern cl::opt<bool> PrintPipelinePasses;
-} // namespace llvm
-
 using namespace llvm;
 
 static cl::opt<std::string>

diff  --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp
index 374698083763b..91ec905e58f12 100644
--- a/llvm/tools/opt/NewPMDriver.cpp
+++ b/llvm/tools/opt/NewPMDriver.cpp
@@ -227,10 +227,6 @@ static cl::opt<bool> DisableLoopUnrolling(
     "disable-loop-unrolling",
     cl::desc("Disable loop unrolling in all relevant passes"), cl::init(false));
 
-namespace llvm {
-extern cl::opt<bool> PrintPipelinePasses;
-} // namespace llvm
-
 template <typename PassManagerT>
 bool tryParsePipelineText(PassBuilder &PB,
                           const cl::opt<std::string> &PipelineOpt) {


        


More information about the llvm-commits mailing list