[llvm-shlib] Fix the version naming style of libLLVM for Windows (#85710)
[llvm-project.git] / llvm / tools / opt / NewPMDriver.cpp
blob6ae3f87099afd64bc252d13cd1a7ac31dff4d31a
1 //===- NewPMDriver.cpp - Driver for opt with new PM -----------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 ///
10 /// This file is just a split of the code that logically belongs in opt.cpp but
11 /// that includes the new pass manager headers.
12 ///
13 //===----------------------------------------------------------------------===//
15 #include "NewPMDriver.h"
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Analysis/AliasAnalysis.h"
19 #include "llvm/Analysis/CGSCCPassManager.h"
20 #include "llvm/Analysis/TargetLibraryInfo.h"
21 #include "llvm/Bitcode/BitcodeWriterPass.h"
22 #include "llvm/Config/llvm-config.h"
23 #include "llvm/IR/Dominators.h"
24 #include "llvm/IR/LLVMContext.h"
25 #include "llvm/IR/Module.h"
26 #include "llvm/IR/PassManager.h"
27 #include "llvm/IR/Verifier.h"
28 #include "llvm/IRPrinter/IRPrintingPasses.h"
29 #include "llvm/Passes/PassBuilder.h"
30 #include "llvm/Passes/PassPlugin.h"
31 #include "llvm/Passes/StandardInstrumentations.h"
32 #include "llvm/Support/ErrorHandling.h"
33 #include "llvm/Support/ToolOutputFile.h"
34 #include "llvm/Support/VirtualFileSystem.h"
35 #include "llvm/Support/raw_ostream.h"
36 #include "llvm/Target/TargetMachine.h"
37 #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
38 #include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
39 #include "llvm/Transforms/Scalar/LoopPassManager.h"
40 #include "llvm/Transforms/Utils/Debugify.h"
42 using namespace llvm;
43 using namespace opt_tool;
45 namespace llvm {
46 cl::opt<bool> DebugifyEach(
47 "debugify-each",
48 cl::desc("Start each pass with debugify and end it with check-debugify"));
50 cl::opt<std::string>
51 DebugifyExport("debugify-export",
52 cl::desc("Export per-pass debugify statistics to this file"),
53 cl::value_desc("filename"));
55 cl::opt<bool> VerifyEachDebugInfoPreserve(
56 "verify-each-debuginfo-preserve",
57 cl::desc("Start each pass with collecting and end it with checking of "
58 "debug info preservation."));
60 cl::opt<std::string>
61 VerifyDIPreserveExport("verify-di-preserve-export",
62 cl::desc("Export debug info preservation failures into "
63 "specified (JSON) file (should be abs path as we use"
64 " append mode to insert new JSON objects)"),
65 cl::value_desc("filename"), cl::init(""));
67 } // namespace llvm
69 enum class DebugLogging { None, Normal, Verbose, Quiet };
71 static cl::opt<DebugLogging> DebugPM(
72 "debug-pass-manager", cl::Hidden, cl::ValueOptional,
73 cl::desc("Print pass management debugging information"),
74 cl::init(DebugLogging::None),
75 cl::values(
76 clEnumValN(DebugLogging::Normal, "", ""),
77 clEnumValN(DebugLogging::Quiet, "quiet",
78 "Skip printing info about analyses"),
79 clEnumValN(
80 DebugLogging::Verbose, "verbose",
81 "Print extra information about adaptors and pass managers")));
83 // This flag specifies a textual description of the alias analysis pipeline to
84 // use when querying for aliasing information. It only works in concert with
85 // the "passes" flag above.
86 static cl::opt<std::string>
87 AAPipeline("aa-pipeline",
88 cl::desc("A textual description of the alias analysis "
89 "pipeline for handling managed aliasing queries"),
90 cl::Hidden, cl::init("default"));
92 /// {{@ These options accept textual pipeline descriptions which will be
93 /// inserted into default pipelines at the respective extension points
94 static cl::opt<std::string> PeepholeEPPipeline(
95 "passes-ep-peephole",
96 cl::desc("A textual description of the function pass pipeline inserted at "
97 "the Peephole extension points into default pipelines"),
98 cl::Hidden);
99 static cl::opt<std::string> LateLoopOptimizationsEPPipeline(
100 "passes-ep-late-loop-optimizations",
101 cl::desc(
102 "A textual description of the loop pass pipeline inserted at "
103 "the LateLoopOptimizations extension point into default pipelines"),
104 cl::Hidden);
105 static cl::opt<std::string> LoopOptimizerEndEPPipeline(
106 "passes-ep-loop-optimizer-end",
107 cl::desc("A textual description of the loop pass pipeline inserted at "
108 "the LoopOptimizerEnd extension point into default pipelines"),
109 cl::Hidden);
110 static cl::opt<std::string> ScalarOptimizerLateEPPipeline(
111 "passes-ep-scalar-optimizer-late",
112 cl::desc("A textual description of the function pass pipeline inserted at "
113 "the ScalarOptimizerLate extension point into default pipelines"),
114 cl::Hidden);
115 static cl::opt<std::string> CGSCCOptimizerLateEPPipeline(
116 "passes-ep-cgscc-optimizer-late",
117 cl::desc("A textual description of the cgscc pass pipeline inserted at "
118 "the CGSCCOptimizerLate extension point into default pipelines"),
119 cl::Hidden);
120 static cl::opt<std::string> VectorizerStartEPPipeline(
121 "passes-ep-vectorizer-start",
122 cl::desc("A textual description of the function pass pipeline inserted at "
123 "the VectorizerStart extension point into default pipelines"),
124 cl::Hidden);
125 static cl::opt<std::string> PipelineStartEPPipeline(
126 "passes-ep-pipeline-start",
127 cl::desc("A textual description of the module pass pipeline inserted at "
128 "the PipelineStart extension point into default pipelines"),
129 cl::Hidden);
130 static cl::opt<std::string> PipelineEarlySimplificationEPPipeline(
131 "passes-ep-pipeline-early-simplification",
132 cl::desc("A textual description of the module pass pipeline inserted at "
133 "the EarlySimplification extension point into default pipelines"),
134 cl::Hidden);
135 static cl::opt<std::string> OptimizerEarlyEPPipeline(
136 "passes-ep-optimizer-early",
137 cl::desc("A textual description of the module pass pipeline inserted at "
138 "the OptimizerEarly extension point into default pipelines"),
139 cl::Hidden);
140 static cl::opt<std::string> OptimizerLastEPPipeline(
141 "passes-ep-optimizer-last",
142 cl::desc("A textual description of the module pass pipeline inserted at "
143 "the OptimizerLast extension point into default pipelines"),
144 cl::Hidden);
145 static cl::opt<std::string> FullLinkTimeOptimizationEarlyEPPipeline(
146 "passes-ep-full-link-time-optimization-early",
147 cl::desc("A textual description of the module pass pipeline inserted at "
148 "the FullLinkTimeOptimizationEarly extension point into default "
149 "pipelines"),
150 cl::Hidden);
151 static cl::opt<std::string> FullLinkTimeOptimizationLastEPPipeline(
152 "passes-ep-full-link-time-optimization-last",
153 cl::desc("A textual description of the module pass pipeline inserted at "
154 "the FullLinkTimeOptimizationLast extension point into default "
155 "pipelines"),
156 cl::Hidden);
157 /// @}}
159 static cl::opt<bool> DisablePipelineVerification(
160 "disable-pipeline-verification",
161 cl::desc("Only has an effect when specified with -print-pipeline-passes. "
162 "Disables verifying that the textual pipeline generated by "
163 "-print-pipeline-passes can be used to create a pipeline."),
164 cl::Hidden);
167 static cl::opt<PGOKind>
168 PGOKindFlag("pgo-kind", cl::init(NoPGO), cl::Hidden,
169 cl::desc("The kind of profile guided optimization"),
170 cl::values(clEnumValN(NoPGO, "nopgo", "Do not use PGO."),
171 clEnumValN(InstrGen, "pgo-instr-gen-pipeline",
172 "Instrument the IR to generate profile."),
173 clEnumValN(InstrUse, "pgo-instr-use-pipeline",
174 "Use instrumented profile to guide PGO."),
175 clEnumValN(SampleUse, "pgo-sample-use-pipeline",
176 "Use sampled profile to guide PGO.")));
177 static cl::opt<std::string> ProfileFile("profile-file",
178 cl::desc("Path to the profile."), cl::Hidden);
179 static cl::opt<std::string>
180 MemoryProfileFile("memory-profile-file",
181 cl::desc("Path to the memory profile."), cl::Hidden);
183 static cl::opt<CSPGOKind> CSPGOKindFlag(
184 "cspgo-kind", cl::init(NoCSPGO), cl::Hidden,
185 cl::desc("The kind of context sensitive profile guided optimization"),
186 cl::values(
187 clEnumValN(NoCSPGO, "nocspgo", "Do not use CSPGO."),
188 clEnumValN(
189 CSInstrGen, "cspgo-instr-gen-pipeline",
190 "Instrument (context sensitive) the IR to generate profile."),
191 clEnumValN(
192 CSInstrUse, "cspgo-instr-use-pipeline",
193 "Use instrumented (context sensitive) profile to guide PGO.")));
195 static cl::opt<std::string> CSProfileGenFile(
196 "cs-profilegen-file",
197 cl::desc("Path to the instrumented context sensitive profile."),
198 cl::Hidden);
200 static cl::opt<std::string>
201 ProfileRemappingFile("profile-remapping-file",
202 cl::desc("Path to the profile remapping file."),
203 cl::Hidden);
205 static cl::opt<bool> DebugInfoForProfiling(
206 "debug-info-for-profiling", cl::init(false), cl::Hidden,
207 cl::desc("Emit special debug info to enable PGO profile generation."));
209 static cl::opt<bool> PseudoProbeForProfiling(
210 "pseudo-probe-for-profiling", cl::init(false), cl::Hidden,
211 cl::desc("Emit pseudo probes to enable PGO profile generation."));
213 static cl::opt<bool> DisableLoopUnrolling(
214 "disable-loop-unrolling",
215 cl::desc("Disable loop unrolling in all relevant passes"), cl::init(false));
217 namespace llvm {
218 extern cl::opt<bool> PrintPipelinePasses;
219 } // namespace llvm
221 template <typename PassManagerT>
222 bool tryParsePipelineText(PassBuilder &PB,
223 const cl::opt<std::string> &PipelineOpt) {
224 if (PipelineOpt.empty())
225 return false;
227 // Verify the pipeline is parseable:
228 PassManagerT PM;
229 if (auto Err = PB.parsePassPipeline(PM, PipelineOpt)) {
230 errs() << "Could not parse -" << PipelineOpt.ArgStr
231 << " pipeline: " << toString(std::move(Err))
232 << "... I'm going to ignore it.\n";
233 return false;
235 return true;
238 /// If one of the EPPipeline command line options was given, register callbacks
239 /// for parsing and inserting the given pipeline
240 static void registerEPCallbacks(PassBuilder &PB) {
241 if (tryParsePipelineText<FunctionPassManager>(PB, PeepholeEPPipeline))
242 PB.registerPeepholeEPCallback(
243 [&PB](FunctionPassManager &PM, OptimizationLevel Level) {
244 ExitOnError Err("Unable to parse PeepholeEP pipeline: ");
245 Err(PB.parsePassPipeline(PM, PeepholeEPPipeline));
247 if (tryParsePipelineText<LoopPassManager>(PB,
248 LateLoopOptimizationsEPPipeline))
249 PB.registerLateLoopOptimizationsEPCallback(
250 [&PB](LoopPassManager &PM, OptimizationLevel Level) {
251 ExitOnError Err("Unable to parse LateLoopOptimizationsEP pipeline: ");
252 Err(PB.parsePassPipeline(PM, LateLoopOptimizationsEPPipeline));
254 if (tryParsePipelineText<LoopPassManager>(PB, LoopOptimizerEndEPPipeline))
255 PB.registerLoopOptimizerEndEPCallback(
256 [&PB](LoopPassManager &PM, OptimizationLevel Level) {
257 ExitOnError Err("Unable to parse LoopOptimizerEndEP pipeline: ");
258 Err(PB.parsePassPipeline(PM, LoopOptimizerEndEPPipeline));
260 if (tryParsePipelineText<FunctionPassManager>(PB,
261 ScalarOptimizerLateEPPipeline))
262 PB.registerScalarOptimizerLateEPCallback(
263 [&PB](FunctionPassManager &PM, OptimizationLevel Level) {
264 ExitOnError Err("Unable to parse ScalarOptimizerLateEP pipeline: ");
265 Err(PB.parsePassPipeline(PM, ScalarOptimizerLateEPPipeline));
267 if (tryParsePipelineText<CGSCCPassManager>(PB, CGSCCOptimizerLateEPPipeline))
268 PB.registerCGSCCOptimizerLateEPCallback(
269 [&PB](CGSCCPassManager &PM, OptimizationLevel Level) {
270 ExitOnError Err("Unable to parse CGSCCOptimizerLateEP pipeline: ");
271 Err(PB.parsePassPipeline(PM, CGSCCOptimizerLateEPPipeline));
273 if (tryParsePipelineText<FunctionPassManager>(PB, VectorizerStartEPPipeline))
274 PB.registerVectorizerStartEPCallback(
275 [&PB](FunctionPassManager &PM, OptimizationLevel Level) {
276 ExitOnError Err("Unable to parse VectorizerStartEP pipeline: ");
277 Err(PB.parsePassPipeline(PM, VectorizerStartEPPipeline));
279 if (tryParsePipelineText<ModulePassManager>(PB, PipelineStartEPPipeline))
280 PB.registerPipelineStartEPCallback(
281 [&PB](ModulePassManager &PM, OptimizationLevel) {
282 ExitOnError Err("Unable to parse PipelineStartEP pipeline: ");
283 Err(PB.parsePassPipeline(PM, PipelineStartEPPipeline));
285 if (tryParsePipelineText<ModulePassManager>(
286 PB, PipelineEarlySimplificationEPPipeline))
287 PB.registerPipelineEarlySimplificationEPCallback(
288 [&PB](ModulePassManager &PM, OptimizationLevel) {
289 ExitOnError Err("Unable to parse EarlySimplification pipeline: ");
290 Err(PB.parsePassPipeline(PM, PipelineEarlySimplificationEPPipeline));
292 if (tryParsePipelineText<ModulePassManager>(PB, OptimizerEarlyEPPipeline))
293 PB.registerOptimizerEarlyEPCallback(
294 [&PB](ModulePassManager &PM, OptimizationLevel) {
295 ExitOnError Err("Unable to parse OptimizerEarlyEP pipeline: ");
296 Err(PB.parsePassPipeline(PM, OptimizerEarlyEPPipeline));
298 if (tryParsePipelineText<ModulePassManager>(PB, OptimizerLastEPPipeline))
299 PB.registerOptimizerLastEPCallback(
300 [&PB](ModulePassManager &PM, OptimizationLevel) {
301 ExitOnError Err("Unable to parse OptimizerLastEP pipeline: ");
302 Err(PB.parsePassPipeline(PM, OptimizerLastEPPipeline));
304 if (tryParsePipelineText<ModulePassManager>(
305 PB, FullLinkTimeOptimizationEarlyEPPipeline))
306 PB.registerFullLinkTimeOptimizationEarlyEPCallback(
307 [&PB](ModulePassManager &PM, OptimizationLevel) {
308 ExitOnError Err(
309 "Unable to parse FullLinkTimeOptimizationEarlyEP pipeline: ");
310 Err(PB.parsePassPipeline(PM,
311 FullLinkTimeOptimizationEarlyEPPipeline));
313 if (tryParsePipelineText<ModulePassManager>(
314 PB, FullLinkTimeOptimizationLastEPPipeline))
315 PB.registerFullLinkTimeOptimizationLastEPCallback(
316 [&PB](ModulePassManager &PM, OptimizationLevel) {
317 ExitOnError Err(
318 "Unable to parse FullLinkTimeOptimizationLastEP pipeline: ");
319 Err(PB.parsePassPipeline(PM, FullLinkTimeOptimizationLastEPPipeline));
323 #define HANDLE_EXTENSION(Ext) \
324 llvm::PassPluginLibraryInfo get##Ext##PluginInfo();
325 #include "llvm/Support/Extension.def"
327 bool llvm::runPassPipeline(
328 StringRef Arg0, Module &M, TargetMachine *TM, TargetLibraryInfoImpl *TLII,
329 ToolOutputFile *Out, ToolOutputFile *ThinLTOLinkOut,
330 ToolOutputFile *OptRemarkFile, StringRef PassPipeline,
331 ArrayRef<PassPlugin> PassPlugins, OutputKind OK, VerifierKind VK,
332 bool ShouldPreserveAssemblyUseListOrder,
333 bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex,
334 bool EmitModuleHash, bool EnableDebugify, bool VerifyDIPreserve,
335 bool UnifiedLTO) {
336 bool VerifyEachPass = VK == VK_VerifyEachPass;
338 auto FS = vfs::getRealFileSystem();
339 std::optional<PGOOptions> P;
340 switch (PGOKindFlag) {
341 case InstrGen:
342 P = PGOOptions(ProfileFile, "", "", MemoryProfileFile, FS,
343 PGOOptions::IRInstr);
344 break;
345 case InstrUse:
346 P = PGOOptions(ProfileFile, "", ProfileRemappingFile, MemoryProfileFile, FS,
347 PGOOptions::IRUse);
348 break;
349 case SampleUse:
350 P = PGOOptions(ProfileFile, "", ProfileRemappingFile, MemoryProfileFile, FS,
351 PGOOptions::SampleUse);
352 break;
353 case NoPGO:
354 if (DebugInfoForProfiling || PseudoProbeForProfiling ||
355 !MemoryProfileFile.empty())
356 P = PGOOptions("", "", "", MemoryProfileFile, FS, PGOOptions::NoAction,
357 PGOOptions::NoCSAction, DebugInfoForProfiling,
358 PseudoProbeForProfiling);
359 else
360 P = std::nullopt;
362 if (CSPGOKindFlag != NoCSPGO) {
363 if (P && (P->Action == PGOOptions::IRInstr ||
364 P->Action == PGOOptions::SampleUse)) {
365 errs() << "CSPGOKind cannot be used with IRInstr or SampleUse";
366 return false;
368 if (CSPGOKindFlag == CSInstrGen) {
369 if (CSProfileGenFile.empty()) {
370 errs() << "CSInstrGen needs to specify CSProfileGenFile";
371 return false;
373 if (P) {
374 P->CSAction = PGOOptions::CSIRInstr;
375 P->CSProfileGenFile = CSProfileGenFile;
376 } else
377 P = PGOOptions("", CSProfileGenFile, ProfileRemappingFile,
378 /*MemoryProfile=*/"", FS, PGOOptions::NoAction,
379 PGOOptions::CSIRInstr);
380 } else /* CSPGOKindFlag == CSInstrUse */ {
381 if (!P) {
382 errs() << "CSInstrUse needs to be together with InstrUse";
383 return false;
385 P->CSAction = PGOOptions::CSIRUse;
388 if (TM)
389 TM->setPGOOption(P);
391 LoopAnalysisManager LAM;
392 FunctionAnalysisManager FAM;
393 CGSCCAnalysisManager CGAM;
394 ModuleAnalysisManager MAM;
396 PassInstrumentationCallbacks PIC;
397 PrintPassOptions PrintPassOpts;
398 PrintPassOpts.Verbose = DebugPM == DebugLogging::Verbose;
399 PrintPassOpts.SkipAnalyses = DebugPM == DebugLogging::Quiet;
400 StandardInstrumentations SI(M.getContext(), DebugPM != DebugLogging::None,
401 VerifyEachPass, PrintPassOpts);
402 SI.registerCallbacks(PIC, &MAM);
403 DebugifyEachInstrumentation Debugify;
404 DebugifyStatsMap DIStatsMap;
405 DebugInfoPerPass DebugInfoBeforePass;
406 if (DebugifyEach) {
407 Debugify.setDIStatsMap(DIStatsMap);
408 Debugify.setDebugifyMode(DebugifyMode::SyntheticDebugInfo);
409 Debugify.registerCallbacks(PIC, MAM);
410 } else if (VerifyEachDebugInfoPreserve) {
411 Debugify.setDebugInfoBeforePass(DebugInfoBeforePass);
412 Debugify.setDebugifyMode(DebugifyMode::OriginalDebugInfo);
413 Debugify.setOrigDIVerifyBugsReportFilePath(
414 VerifyDIPreserveExport);
415 Debugify.registerCallbacks(PIC, MAM);
418 PipelineTuningOptions PTO;
419 // LoopUnrolling defaults on to true and DisableLoopUnrolling is initialized
420 // to false above so we shouldn't necessarily need to check whether or not the
421 // option has been enabled.
422 PTO.LoopUnrolling = !DisableLoopUnrolling;
423 PTO.UnifiedLTO = UnifiedLTO;
424 PassBuilder PB(TM, PTO, P, &PIC);
425 registerEPCallbacks(PB);
427 // For any loaded plugins, let them register pass builder callbacks.
428 for (auto &PassPlugin : PassPlugins)
429 PassPlugin.registerPassBuilderCallbacks(PB);
431 #define HANDLE_EXTENSION(Ext) \
432 get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
433 #include "llvm/Support/Extension.def"
435 // Specially handle the alias analysis manager so that we can register
436 // a custom pipeline of AA passes with it.
437 AAManager AA;
438 if (auto Err = PB.parseAAPipeline(AA, AAPipeline)) {
439 errs() << Arg0 << ": " << toString(std::move(Err)) << "\n";
440 return false;
443 // Register the AA manager first so that our version is the one used.
444 FAM.registerPass([&] { return std::move(AA); });
445 // Register our TargetLibraryInfoImpl.
446 FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
448 // Register all the basic analyses with the managers.
449 PB.registerModuleAnalyses(MAM);
450 PB.registerCGSCCAnalyses(CGAM);
451 PB.registerFunctionAnalyses(FAM);
452 PB.registerLoopAnalyses(LAM);
453 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
455 ModulePassManager MPM;
456 if (EnableDebugify)
457 MPM.addPass(NewPMDebugifyPass());
458 if (VerifyDIPreserve)
459 MPM.addPass(NewPMDebugifyPass(DebugifyMode::OriginalDebugInfo, "",
460 &DebugInfoBeforePass));
462 // Add passes according to the -passes options.
463 if (!PassPipeline.empty()) {
464 if (auto Err = PB.parsePassPipeline(MPM, PassPipeline)) {
465 errs() << Arg0 << ": " << toString(std::move(Err)) << "\n";
466 return false;
470 if (VK > VK_NoVerifier)
471 MPM.addPass(VerifierPass());
472 if (EnableDebugify)
473 MPM.addPass(NewPMCheckDebugifyPass(false, "", &DIStatsMap));
474 if (VerifyDIPreserve)
475 MPM.addPass(NewPMCheckDebugifyPass(
476 false, "", nullptr, DebugifyMode::OriginalDebugInfo,
477 &DebugInfoBeforePass, VerifyDIPreserveExport));
479 // Add any relevant output pass at the end of the pipeline.
480 switch (OK) {
481 case OK_NoOutput:
482 break; // No output pass needed.
483 case OK_OutputAssembly:
484 MPM.addPass(PrintModulePass(
485 Out->os(), "", ShouldPreserveAssemblyUseListOrder, EmitSummaryIndex));
486 break;
487 case OK_OutputBitcode:
488 MPM.addPass(BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder,
489 EmitSummaryIndex, EmitModuleHash));
490 break;
491 case OK_OutputThinLTOBitcode:
492 MPM.addPass(ThinLTOBitcodeWriterPass(
493 Out->os(), ThinLTOLinkOut ? &ThinLTOLinkOut->os() : nullptr));
494 break;
497 // Before executing passes, print the final values of the LLVM options.
498 cl::PrintOptionValues();
500 // Print a textual, '-passes=' compatible, representation of pipeline if
501 // requested.
502 if (PrintPipelinePasses) {
503 std::string Pipeline;
504 raw_string_ostream SOS(Pipeline);
505 MPM.printPipeline(SOS, [&PIC](StringRef ClassName) {
506 auto PassName = PIC.getPassNameForClassName(ClassName);
507 return PassName.empty() ? ClassName : PassName;
509 outs() << Pipeline;
510 outs() << "\n";
512 if (!DisablePipelineVerification) {
513 // Check that we can parse the returned pipeline string as an actual
514 // pipeline.
515 ModulePassManager TempPM;
516 if (auto Err = PB.parsePassPipeline(TempPM, Pipeline)) {
517 errs() << "Could not parse dumped pass pipeline: "
518 << toString(std::move(Err)) << "\n";
519 return false;
523 return true;
526 // Now that we have all of the passes ready, run them.
527 MPM.run(M, MAM);
529 // Declare success.
530 if (OK != OK_NoOutput) {
531 Out->keep();
532 if (OK == OK_OutputThinLTOBitcode && ThinLTOLinkOut)
533 ThinLTOLinkOut->keep();
536 if (OptRemarkFile)
537 OptRemarkFile->keep();
539 if (DebugifyEach && !DebugifyExport.empty())
540 exportDebugifyStats(DebugifyExport, Debugify.getDebugifyStatsMap());
542 return true;
545 void llvm::printPasses(raw_ostream &OS) {
546 PassBuilder PB;
547 PB.printPassNames(OS);