Skip to content

Commit 57fd63e

Browse files
committed
[lld][LTO] Teach LTO to print pipeline passes
1 parent 102f322 commit 57fd63e

File tree

7 files changed

+36
-2
lines changed

7 files changed

+36
-2
lines changed

lld/ELF/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ struct Config {
260260
bool ignoreFunctionAddressEquality;
261261
bool ltoCSProfileGenerate;
262262
bool ltoPGOWarnMismatch;
263+
bool ltoPrintPipelinePasses;
263264
bool ltoDebugPassManager;
264265
bool ltoEmitAsm;
265266
bool ltoUniqueBasicBlockSectionNames;

lld/ELF/Driver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,7 @@ static void readConfigs(opt::InputArgList &args) {
13131313
config->ltoCSProfileFile = args.getLastArgValue(OPT_lto_cs_profile_file);
13141314
config->ltoPGOWarnMismatch = args.hasFlag(OPT_lto_pgo_warn_mismatch,
13151315
OPT_no_lto_pgo_warn_mismatch, true);
1316+
config->ltoPrintPipelinePasses = args.hasArg(OPT_lto_print_pipeline_passes);
13161317
config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);
13171318
config->ltoEmitAsm = args.hasArg(OPT_lto_emit_asm);
13181319
config->ltoNewPmPasses = args.getLastArgValue(OPT_lto_newpm_passes);

lld/ELF/LTO.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ static lto::Config createConfig() {
127127
c.SampleProfile = std::string(config->ltoSampleProfile);
128128
for (StringRef pluginFn : config->passPlugins)
129129
c.PassPlugins.push_back(std::string(pluginFn));
130+
c.PrintPipelinePasses = config->ltoPrintPipelinePasses;
130131
c.DebugPassManager = config->ltoDebugPassManager;
131132
c.DwoDir = std::string(config->dwoDir);
132133

lld/ELF/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ def lto: JJ<"lto=">, HelpText<"Set LTO backend">,
610610
MetaVarName<"[full,thin]">;
611611
def lto_aa_pipeline: JJ<"lto-aa-pipeline=">,
612612
HelpText<"AA pipeline to run during LTO. Used in conjunction with -lto-newpm-passes">;
613+
def lto_print_pipeline_passes: FF<"lto-print-pipeline-passes">,
614+
HelpText<"Print a '-passes' compatible string describing the LTO pipeline (best-effort only).">;
613615
def lto_debug_pass_manager: FF<"lto-debug-pass-manager">,
614616
HelpText<"Debug new pass manager">;
615617
def lto_emit_asm: FF<"lto-emit-asm">,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; REQUIRES: x86
2+
3+
; RUN: llvm-as %s -o %t.o
4+
; RUN: ld.lld --lto-print-pipeline-passes -o %t.out.o %t.o 2>&1 | FileCheck %s
5+
6+
; CHECK: pipeline-passes: verify,{{.*}},verify
7+
8+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
9+
target triple = "x86_64-unknown-linux-gnu"
10+
11+
@llvm.compiler.used = appending global [1 x ptr] [ptr @main], section "llvm.metadata"
12+
13+
define hidden void @main() {
14+
ret void
15+
}

llvm/include/llvm/LTO/Config.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ struct Config {
165165
/// Whether to emit the pass manager debuggging informations.
166166
bool DebugPassManager = false;
167167

168+
/// Print a '-passes' compatible string describing the pipeline (best-effort
169+
/// only).
170+
bool PrintPipelinePasses = false;
171+
168172
/// Statistics output file path.
169173
std::string StatsFile;
170174

@@ -302,7 +306,7 @@ struct LTOLLVMContext : LLVMContext {
302306
DiagnosticHandlerFunction DiagHandler;
303307
};
304308

305-
}
306-
}
309+
} // namespace lto
310+
} // namespace llvm
307311

308312
#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 (Conf.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

0 commit comments

Comments
 (0)