Skip to content

Commit 26e455b

Browse files
authored
[lld][LTO] Teach LTO to print pipeline passes (llvm#101018)
I found this useful while debugging code generation differences between old and new offloading drivers. No functional change (intended).
1 parent 2a612a1 commit 26e455b

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed

llvm/include/llvm/Passes/PassBuilder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,10 @@ class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
944944
return Result();
945945
}
946946
};
947+
948+
/// Common option used by multiple tools to print pipeline passes
949+
extern cl::opt<bool> PrintPipelinePasses;
950+
947951
}
948952

949953
#endif

llvm/lib/LTO/LTOBackend.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,16 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
335335
if (!Conf.DisableVerify)
336336
MPM.addPass(VerifierPass());
337337

338+
if (PrintPipelinePasses) {
339+
std::string PipelineStr;
340+
raw_string_ostream OS(PipelineStr);
341+
MPM.printPipeline(OS, [&PIC](StringRef ClassName) {
342+
auto PassName = PIC.getPassNameForClassName(ClassName);
343+
return PassName.empty() ? ClassName : PassName;
344+
});
345+
outs() << "pipeline-passes: " << PipelineStr << '\n';
346+
}
347+
338348
MPM.run(Mod, MAM);
339349
}
340350

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; RUN: llvm-as < %s >%t.bc
2+
; RUN: llvm-lto -print-pipeline-passes -exported-symbol=_f -o /dev/null %t.bc 2>&1 | FileCheck %s
3+
4+
; CHECK: pipeline-passes: verify,{{.*}},verify
5+
6+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
7+
target triple = "x86_64-apple-macosx10.10.0"
8+
9+
10+
define void @f() {
11+
entry:
12+
ret void
13+
}

llvm/tools/llc/NewPMDriver.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@
4545
#include "llvm/Transforms/Scalar/LoopPassManager.h"
4646
#include "llvm/Transforms/Utils/Cloning.h"
4747

48-
namespace llvm {
49-
extern cl::opt<bool> PrintPipelinePasses;
50-
} // namespace llvm
51-
5248
using namespace llvm;
5349

5450
static cl::opt<std::string>

llvm/tools/opt/NewPMDriver.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,6 @@ static cl::opt<bool> DisableLoopUnrolling(
227227
"disable-loop-unrolling",
228228
cl::desc("Disable loop unrolling in all relevant passes"), cl::init(false));
229229

230-
namespace llvm {
231-
extern cl::opt<bool> PrintPipelinePasses;
232-
} // namespace llvm
233-
234230
template <typename PassManagerT>
235231
bool tryParsePipelineText(PassBuilder &PB,
236232
const cl::opt<std::string> &PipelineOpt) {

0 commit comments

Comments
 (0)