blob: efe0bec35d72aa21a8c45bcfa533476e9bc2f0e2 [file] [log] [blame]
Chandler Carruth66445382014-01-11 08:16:35 +00001//===- NewPMDriver.cpp - Driver for opt with new PM -----------------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Chandler Carruth66445382014-01-11 08:16:35 +00006//
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"
Fedor Sergeev662e5682018-09-24 16:08:15 +000016#include "Debugify.h"
Vedant Kumar775c7af2018-02-15 21:14:36 +000017#include "PassPrinters.h"
Chandler Carruth66445382014-01-11 08:16:35 +000018#include "llvm/ADT/StringRef.h"
Chandler Carruthedf59962016-02-18 09:45:17 +000019#include "llvm/Analysis/AliasAnalysis.h"
Chandler Carruth572e3402014-04-21 11:12:00 +000020#include "llvm/Analysis/CGSCCPassManager.h"
Chandler Carruthb7bdfd62014-01-13 07:38:24 +000021#include "llvm/Bitcode/BitcodeWriterPass.h"
Nico Weber432a3882018-04-30 14:59:11 +000022#include "llvm/Config/llvm-config.h"
Chandler Carruth64764b42015-01-14 10:19:28 +000023#include "llvm/IR/Dominators.h"
Chandler Carruthb353c3f2014-01-13 05:16:45 +000024#include "llvm/IR/IRPrintingPasses.h"
Chandler Carruth66445382014-01-11 08:16:35 +000025#include "llvm/IR/LLVMContext.h"
26#include "llvm/IR/Module.h"
27#include "llvm/IR/PassManager.h"
Chandler Carruth4d356312014-01-20 11:34:08 +000028#include "llvm/IR/Verifier.h"
Chandler Carruth1ff77242015-03-07 09:02:36 +000029#include "llvm/Passes/PassBuilder.h"
Philip Pfaffe131fb972018-04-05 15:04:13 +000030#include "llvm/Passes/PassPlugin.h"
Fedor Sergeev662e5682018-09-24 16:08:15 +000031#include "llvm/Passes/StandardInstrumentations.h"
Chandler Carruth66445382014-01-11 08:16:35 +000032#include "llvm/Support/CommandLine.h"
Chandler Carruthb353c3f2014-01-13 05:16:45 +000033#include "llvm/Support/ErrorHandling.h"
Chandler Carruth66445382014-01-11 08:16:35 +000034#include "llvm/Support/ToolOutputFile.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000035#include "llvm/Target/TargetMachine.h"
Tim Shen6b4114182017-06-01 01:02:12 +000036#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
Chandler Carruth3bab7e12017-01-11 09:43:56 +000037#include "llvm/Transforms/Scalar/LoopPassManager.h"
Chandler Carruth66445382014-01-11 08:16:35 +000038
39using namespace llvm;
Chandler Carruth949282e2014-01-13 03:08:40 +000040using namespace opt_tool;
Chandler Carruth66445382014-01-11 08:16:35 +000041
Chandler Carruth14a759e2015-01-13 22:42:38 +000042static cl::opt<bool>
43 DebugPM("debug-pass-manager", cl::Hidden,
44 cl::desc("Print pass management debugging information"));
45
Philip Pfaffe131fb972018-04-05 15:04:13 +000046static cl::list<std::string>
47 PassPlugins("load-pass-plugin",
48 cl::desc("Load passes from plugin library"));
49
Chandler Carruthedf59962016-02-18 09:45:17 +000050// This flag specifies a textual description of the alias analysis pipeline to
51// use when querying for aliasing information. It only works in concert with
52// the "passes" flag above.
53static cl::opt<std::string>
54 AAPipeline("aa-pipeline",
55 cl::desc("A textual description of the alias analysis "
56 "pipeline for handling managed aliasing queries"),
57 cl::Hidden);
58
Philip Pfaffe730f2f92017-07-10 10:57:55 +000059/// {{@ These options accept textual pipeline descriptions which will be
60/// inserted into default pipelines at the respective extension points
61static cl::opt<std::string> PeepholeEPPipeline(
62 "passes-ep-peephole",
63 cl::desc("A textual description of the function pass pipeline inserted at "
64 "the Peephole extension points into default pipelines"),
65 cl::Hidden);
66static cl::opt<std::string> LateLoopOptimizationsEPPipeline(
67 "passes-ep-late-loop-optimizations",
68 cl::desc(
69 "A textual description of the loop pass pipeline inserted at "
70 "the LateLoopOptimizations extension point into default pipelines"),
71 cl::Hidden);
72static cl::opt<std::string> LoopOptimizerEndEPPipeline(
73 "passes-ep-loop-optimizer-end",
74 cl::desc("A textual description of the loop pass pipeline inserted at "
75 "the LoopOptimizerEnd extension point into default pipelines"),
76 cl::Hidden);
77static cl::opt<std::string> ScalarOptimizerLateEPPipeline(
78 "passes-ep-scalar-optimizer-late",
79 cl::desc("A textual description of the function pass pipeline inserted at "
80 "the ScalarOptimizerLate extension point into default pipelines"),
81 cl::Hidden);
82static cl::opt<std::string> CGSCCOptimizerLateEPPipeline(
83 "passes-ep-cgscc-optimizer-late",
84 cl::desc("A textual description of the cgscc pass pipeline inserted at "
85 "the CGSCCOptimizerLate extension point into default pipelines"),
86 cl::Hidden);
87static cl::opt<std::string> VectorizerStartEPPipeline(
88 "passes-ep-vectorizer-start",
89 cl::desc("A textual description of the function pass pipeline inserted at "
90 "the VectorizerStart extension point into default pipelines"),
91 cl::Hidden);
David Blaikie0c64f5a2018-01-23 01:25:20 +000092static cl::opt<std::string> PipelineStartEPPipeline(
93 "passes-ep-pipeline-start",
94 cl::desc("A textual description of the function pass pipeline inserted at "
95 "the PipelineStart extension point into default pipelines"),
96 cl::Hidden);
Philip Pfaffe2d4effb2018-11-12 11:17:07 +000097static cl::opt<std::string> OptimizerLastEPPipeline(
98 "passes-ep-optimizer-last",
99 cl::desc("A textual description of the function pass pipeline inserted at "
100 "the OptimizerLast extension point into default pipelines"),
101 cl::Hidden);
102
Wei Mic876e3d2019-01-16 23:19:02 +0000103extern cl::opt<PGOKind> PGOKindFlag;
104extern cl::opt<std::string> ProfileFile;
Rong Xudb29a3a2019-03-04 20:21:27 +0000105extern cl::opt<CSPGOKind> CSPGOKindFlag;
106extern cl::opt<std::string> CSProfileGenFile;
107
Richard Smith6c676622018-10-10 23:13:47 +0000108static cl::opt<std::string>
109 ProfileRemappingFile("profile-remapping-file",
110 cl::desc("Path to the profile remapping file."),
111 cl::Hidden);
Dehao Chene90d0152017-07-26 15:01:20 +0000112static cl::opt<bool> DebugInfoForProfiling(
113 "new-pm-debug-info-for-profiling", cl::init(false), cl::Hidden,
114 cl::desc("Emit special debug info to enable PGO profile generation."));
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000115/// @}}
116
Philip Pfaffeb4d500f2017-07-11 11:17:44 +0000117template <typename PassManagerT>
Fedor Sergeevbd6b2132018-10-17 10:36:23 +0000118bool tryParsePipelineText(PassBuilder &PB,
119 const cl::opt<std::string> &PipelineOpt) {
120 if (PipelineOpt.empty())
Philip Pfaffeb4d500f2017-07-11 11:17:44 +0000121 return false;
122
123 // Verify the pipeline is parseable:
124 PassManagerT PM;
Fedor Sergeevbd6b2132018-10-17 10:36:23 +0000125 if (auto Err = PB.parsePassPipeline(PM, PipelineOpt)) {
126 errs() << "Could not parse -" << PipelineOpt.ArgStr
127 << " pipeline: " << toString(std::move(Err))
128 << "... I'm going to ignore it.\n";
129 return false;
130 }
131 return true;
Philip Pfaffeb4d500f2017-07-11 11:17:44 +0000132}
133
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000134/// If one of the EPPipeline command line options was given, register callbacks
135/// for parsing and inserting the given pipeline
136static void registerEPCallbacks(PassBuilder &PB, bool VerifyEachPass,
137 bool DebugLogging) {
Philip Pfaffeb4d500f2017-07-11 11:17:44 +0000138 if (tryParsePipelineText<FunctionPassManager>(PB, PeepholeEPPipeline))
Fedor Sergeevbd6b2132018-10-17 10:36:23 +0000139 PB.registerPeepholeEPCallback(
140 [&PB, VerifyEachPass, DebugLogging](
141 FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) {
142 ExitOnError Err("Unable to parse PeepholeEP pipeline: ");
143 Err(PB.parsePassPipeline(PM, PeepholeEPPipeline, VerifyEachPass,
144 DebugLogging));
145 });
Philip Pfaffeb4d500f2017-07-11 11:17:44 +0000146 if (tryParsePipelineText<LoopPassManager>(PB,
147 LateLoopOptimizationsEPPipeline))
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000148 PB.registerLateLoopOptimizationsEPCallback(
Philip Pfaffea3b84162017-07-10 12:48:51 +0000149 [&PB, VerifyEachPass, DebugLogging](
150 LoopPassManager &PM, PassBuilder::OptimizationLevel Level) {
Fedor Sergeevbd6b2132018-10-17 10:36:23 +0000151 ExitOnError Err("Unable to parse LateLoopOptimizationsEP pipeline: ");
152 Err(PB.parsePassPipeline(PM, LateLoopOptimizationsEPPipeline,
153 VerifyEachPass, DebugLogging));
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000154 });
Philip Pfaffeb4d500f2017-07-11 11:17:44 +0000155 if (tryParsePipelineText<LoopPassManager>(PB, LoopOptimizerEndEPPipeline))
Fedor Sergeevbd6b2132018-10-17 10:36:23 +0000156 PB.registerLoopOptimizerEndEPCallback(
157 [&PB, VerifyEachPass, DebugLogging](
158 LoopPassManager &PM, PassBuilder::OptimizationLevel Level) {
159 ExitOnError Err("Unable to parse LoopOptimizerEndEP pipeline: ");
160 Err(PB.parsePassPipeline(PM, LoopOptimizerEndEPPipeline,
161 VerifyEachPass, DebugLogging));
162 });
Philip Pfaffeb4d500f2017-07-11 11:17:44 +0000163 if (tryParsePipelineText<FunctionPassManager>(PB,
164 ScalarOptimizerLateEPPipeline))
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000165 PB.registerScalarOptimizerLateEPCallback(
Philip Pfaffea3b84162017-07-10 12:48:51 +0000166 [&PB, VerifyEachPass, DebugLogging](
167 FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) {
Fedor Sergeevbd6b2132018-10-17 10:36:23 +0000168 ExitOnError Err("Unable to parse ScalarOptimizerLateEP pipeline: ");
169 Err(PB.parsePassPipeline(PM, ScalarOptimizerLateEPPipeline,
170 VerifyEachPass, DebugLogging));
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000171 });
Philip Pfaffeb4d500f2017-07-11 11:17:44 +0000172 if (tryParsePipelineText<CGSCCPassManager>(PB, CGSCCOptimizerLateEPPipeline))
Fedor Sergeevbd6b2132018-10-17 10:36:23 +0000173 PB.registerCGSCCOptimizerLateEPCallback(
174 [&PB, VerifyEachPass, DebugLogging](
175 CGSCCPassManager &PM, PassBuilder::OptimizationLevel Level) {
176 ExitOnError Err("Unable to parse CGSCCOptimizerLateEP pipeline: ");
177 Err(PB.parsePassPipeline(PM, CGSCCOptimizerLateEPPipeline,
178 VerifyEachPass, DebugLogging));
179 });
Philip Pfaffeb4d500f2017-07-11 11:17:44 +0000180 if (tryParsePipelineText<FunctionPassManager>(PB, VectorizerStartEPPipeline))
Fedor Sergeevbd6b2132018-10-17 10:36:23 +0000181 PB.registerVectorizerStartEPCallback(
182 [&PB, VerifyEachPass, DebugLogging](
183 FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) {
184 ExitOnError Err("Unable to parse VectorizerStartEP pipeline: ");
185 Err(PB.parsePassPipeline(PM, VectorizerStartEPPipeline,
186 VerifyEachPass, DebugLogging));
187 });
David Blaikie0c64f5a2018-01-23 01:25:20 +0000188 if (tryParsePipelineText<ModulePassManager>(PB, PipelineStartEPPipeline))
189 PB.registerPipelineStartEPCallback(
190 [&PB, VerifyEachPass, DebugLogging](ModulePassManager &PM) {
Fedor Sergeevbd6b2132018-10-17 10:36:23 +0000191 ExitOnError Err("Unable to parse PipelineStartEP pipeline: ");
192 Err(PB.parsePassPipeline(PM, PipelineStartEPPipeline, VerifyEachPass,
193 DebugLogging));
David Blaikie0c64f5a2018-01-23 01:25:20 +0000194 });
Philip Pfaffe2d4effb2018-11-12 11:17:07 +0000195 if (tryParsePipelineText<FunctionPassManager>(PB, OptimizerLastEPPipeline))
196 PB.registerOptimizerLastEPCallback(
197 [&PB, VerifyEachPass, DebugLogging](FunctionPassManager &PM,
198 PassBuilder::OptimizationLevel) {
Philip Pfaffee194c022018-11-12 12:27:58 +0000199 ExitOnError Err("Unable to parse OptimizerLastEP pipeline: ");
200 Err(PB.parsePassPipeline(PM, OptimizerLastEPPipeline, VerifyEachPass,
201 DebugLogging));
Philip Pfaffe2d4effb2018-11-12 11:17:07 +0000202 });
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000203}
204
Philip Pfaffe59d690b2017-08-04 09:28:09 +0000205#ifdef LINK_POLLY_INTO_TOOLS
206namespace polly {
207void RegisterPollyPasses(PassBuilder &);
208}
209#endif
210
Tim Shen6b4114182017-06-01 01:02:12 +0000211bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
Reid Kleckner3fc649c2017-09-23 01:03:17 +0000212 ToolOutputFile *Out, ToolOutputFile *ThinLTOLinkOut,
213 ToolOutputFile *OptRemarkFile,
Chandler Carruthe0385522015-02-01 10:11:22 +0000214 StringRef PassPipeline, OutputKind OK,
Duncan P. N. Exon Smith679db332015-04-15 00:34:24 +0000215 VerifierKind VK,
Duncan P. N. Exon Smith8a74f682015-04-15 02:38:06 +0000216 bool ShouldPreserveAssemblyUseListOrder,
Teresa Johnsonf93b2462016-08-12 13:53:02 +0000217 bool ShouldPreserveBitcodeUseListOrder,
Vedant Kumar775c7af2018-02-15 21:14:36 +0000218 bool EmitSummaryIndex, bool EmitModuleHash,
219 bool EnableDebugify) {
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000220 bool VerifyEachPass = VK == VK_VerifyEachPass;
Dehao Chen7b05a272017-07-26 02:00:43 +0000221
222 Optional<PGOOptions> P;
223 switch (PGOKindFlag) {
224 case InstrGen:
Rong Xudb29a3a2019-03-04 20:21:27 +0000225 P = PGOOptions(ProfileFile, "", "", PGOOptions::IRInstr);
Dehao Chen7b05a272017-07-26 02:00:43 +0000226 break;
227 case InstrUse:
Rong Xudb29a3a2019-03-04 20:21:27 +0000228 P = PGOOptions(ProfileFile, "", ProfileRemappingFile, PGOOptions::IRUse);
Dehao Chen7b05a272017-07-26 02:00:43 +0000229 break;
230 case SampleUse:
Rong Xudb29a3a2019-03-04 20:21:27 +0000231 P = PGOOptions(ProfileFile, "", ProfileRemappingFile,
232 PGOOptions::SampleUse);
Dehao Chen7b05a272017-07-26 02:00:43 +0000233 break;
234 case NoPGO:
Dehao Chene90d0152017-07-26 15:01:20 +0000235 if (DebugInfoForProfiling)
Rong Xudb29a3a2019-03-04 20:21:27 +0000236 P = PGOOptions("", "", "", PGOOptions::NoAction, PGOOptions::NoCSAction,
237 true);
Dehao Chene90d0152017-07-26 15:01:20 +0000238 else
239 P = None;
Rong Xudb29a3a2019-03-04 20:21:27 +0000240 }
241 if (CSPGOKindFlag != NoCSPGO) {
242 if (P && (P->Action == PGOOptions::IRInstr ||
243 P->Action == PGOOptions::SampleUse))
244 errs() << "CSPGOKind cannot be used with IRInstr or SampleUse";
245 if (CSPGOKindFlag == CSInstrGen) {
246 if (CSProfileGenFile.empty())
247 errs() << "CSInstrGen needs to specify CSProfileGenFile";
248 if (P) {
249 P->CSAction = PGOOptions::CSIRInstr;
250 P->CSProfileGenFile = CSProfileGenFile;
251 } else
252 P = PGOOptions("", CSProfileGenFile, ProfileRemappingFile,
253 PGOOptions::NoAction, PGOOptions::CSIRInstr);
254 } else /* CSPGOKindFlag == CSInstrUse */ {
255 if (!P)
256 errs() << "CSInstrUse needs to be together with InstrUse";
257 P->CSAction = PGOOptions::CSIRUse;
258 }
259 }
Fedor Sergeev662e5682018-09-24 16:08:15 +0000260 PassInstrumentationCallbacks PIC;
261 StandardInstrumentations SI;
262 SI.registerCallbacks(PIC);
263
Alina Sbirlea0499a2f2019-04-19 16:11:59 +0000264 PassBuilder PB(TM, PipelineTuningOptions(), P, &PIC);
Philip Pfaffe730f2f92017-07-10 10:57:55 +0000265 registerEPCallbacks(PB, VerifyEachPass, DebugPM);
Chandler Carruth2dc92e92015-02-01 07:40:05 +0000266
Philip Pfaffe131fb972018-04-05 15:04:13 +0000267 // Load requested pass plugins and let them register pass builder callbacks
268 for (auto &PluginFN : PassPlugins) {
269 auto PassPlugin = PassPlugin::Load(PluginFN);
270 if (!PassPlugin) {
271 errs() << "Failed to load passes from '" << PluginFN
272 << "'. Request ignored.\n";
273 continue;
274 }
275
276 PassPlugin->registerPassBuilderCallbacks(PB);
277 }
278
Vedant Kumar775c7af2018-02-15 21:14:36 +0000279 // Register a callback that creates the debugify passes as needed.
280 PB.registerPipelineParsingCallback(
281 [](StringRef Name, ModulePassManager &MPM,
282 ArrayRef<PassBuilder::PipelineElement>) {
283 if (Name == "debugify") {
284 MPM.addPass(NewPMDebugifyPass());
285 return true;
286 } else if (Name == "check-debugify") {
287 MPM.addPass(NewPMCheckDebugifyPass());
288 return true;
289 }
290 return false;
291 });
292
Philip Pfaffe59d690b2017-08-04 09:28:09 +0000293#ifdef LINK_POLLY_INTO_TOOLS
294 polly::RegisterPollyPasses(PB);
295#endif
296
Chandler Carruthedf59962016-02-18 09:45:17 +0000297 // Specially handle the alias analysis manager so that we can register
298 // a custom pipeline of AA passes with it.
299 AAManager AA;
Fedor Sergeevbd6b2132018-10-17 10:36:23 +0000300 if (auto Err = PB.parseAAPipeline(AA, AAPipeline)) {
301 errs() << Arg0 << ": " << toString(std::move(Err)) << "\n";
Chandler Carruthedf59962016-02-18 09:45:17 +0000302 return false;
303 }
304
Justin Bognereecc3c82016-02-25 07:23:08 +0000305 LoopAnalysisManager LAM(DebugPM);
Chandler Carruth14a759e2015-01-13 22:42:38 +0000306 FunctionAnalysisManager FAM(DebugPM);
307 CGSCCAnalysisManager CGAM(DebugPM);
308 ModuleAnalysisManager MAM(DebugPM);
Chandler Carruth4d356312014-01-20 11:34:08 +0000309
Chandler Carruthedf59962016-02-18 09:45:17 +0000310 // Register the AA manager first so that our version is the one used.
311 FAM.registerPass([&] { return std::move(AA); });
312
Chandler Carruthb70f6732015-01-06 02:21:37 +0000313 // Register all the basic analyses with the managers.
Chandler Carruth1ff77242015-03-07 09:02:36 +0000314 PB.registerModuleAnalyses(MAM);
315 PB.registerCGSCCAnalyses(CGAM);
316 PB.registerFunctionAnalyses(FAM);
Justin Bognereecc3c82016-02-25 07:23:08 +0000317 PB.registerLoopAnalyses(LAM);
Davide Italianob6ccd6b2016-05-14 23:21:50 +0000318 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
Chandler Carruthc68d0822014-02-06 04:25:13 +0000319
Chandler Carruth14a759e2015-01-13 22:42:38 +0000320 ModulePassManager MPM(DebugPM);
Chandler Carruth4d356312014-01-20 11:34:08 +0000321 if (VK > VK_NoVerifier)
322 MPM.addPass(VerifierPass());
Vedant Kumar775c7af2018-02-15 21:14:36 +0000323 if (EnableDebugify)
324 MPM.addPass(NewPMDebugifyPass());
Chandler Carruth4d356312014-01-20 11:34:08 +0000325
Fedor Sergeevbd6b2132018-10-17 10:36:23 +0000326 if (auto Err =
327 PB.parsePassPipeline(MPM, PassPipeline, VerifyEachPass, DebugPM)) {
328 errs() << Arg0 << ": " << toString(std::move(Err)) << "\n";
Chandler Carruth66445382014-01-11 08:16:35 +0000329 return false;
330 }
331
Chandler Carruth4d356312014-01-20 11:34:08 +0000332 if (VK > VK_NoVerifier)
333 MPM.addPass(VerifierPass());
Vedant Kumar775c7af2018-02-15 21:14:36 +0000334 if (EnableDebugify)
335 MPM.addPass(NewPMCheckDebugifyPass());
Chandler Carruth4d356312014-01-20 11:34:08 +0000336
Chandler Carruthb353c3f2014-01-13 05:16:45 +0000337 // Add any relevant output pass at the end of the pipeline.
338 switch (OK) {
339 case OK_NoOutput:
340 break; // No output pass needed.
341 case OK_OutputAssembly:
Duncan P. N. Exon Smith8a74f682015-04-15 02:38:06 +0000342 MPM.addPass(
343 PrintModulePass(Out->os(), "", ShouldPreserveAssemblyUseListOrder));
Chandler Carruthb353c3f2014-01-13 05:16:45 +0000344 break;
345 case OK_OutputBitcode:
Teresa Johnsonf93b2462016-08-12 13:53:02 +0000346 MPM.addPass(BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder,
347 EmitSummaryIndex, EmitModuleHash));
Chandler Carruthb7bdfd62014-01-13 07:38:24 +0000348 break;
Tim Shen6b4114182017-06-01 01:02:12 +0000349 case OK_OutputThinLTOBitcode:
350 MPM.addPass(ThinLTOBitcodeWriterPass(
351 Out->os(), ThinLTOLinkOut ? &ThinLTOLinkOut->os() : nullptr));
352 break;
Chandler Carruthb353c3f2014-01-13 05:16:45 +0000353 }
354
355 // Before executing passes, print the final values of the LLVM options.
356 cl::PrintOptionValues();
357
Chandler Carruth66445382014-01-11 08:16:35 +0000358 // Now that we have all of the passes ready, run them.
Chandler Carruthb47f8012016-03-11 11:05:24 +0000359 MPM.run(M, MAM);
Chandler Carruth66445382014-01-11 08:16:35 +0000360
361 // Declare success.
Tim Shen6b4114182017-06-01 01:02:12 +0000362 if (OK != OK_NoOutput) {
Chandler Carruth66445382014-01-11 08:16:35 +0000363 Out->keep();
Tim Shen6b4114182017-06-01 01:02:12 +0000364 if (OK == OK_OutputThinLTOBitcode && ThinLTOLinkOut)
365 ThinLTOLinkOut->keep();
366 }
Sam Elliottb0c97532017-08-20 01:30:45 +0000367
368 if (OptRemarkFile)
369 OptRemarkFile->keep();
370
Chandler Carruth66445382014-01-11 08:16:35 +0000371 return true;
372}