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