Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1 | //===- NewPMDriver.cpp - Driver for opt with new PM -----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// |
| 11 | /// This file is just a split of the code that logically belongs in opt.cpp but |
| 12 | /// that includes the new pass manager headers. |
| 13 | /// |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #include "NewPMDriver.h" |
Vedant Kumar | 775c7af | 2018-02-15 21:14:36 +0000 | [diff] [blame] | 17 | #include "PassPrinters.h" |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringRef.h" |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 19 | #include "llvm/Analysis/AliasAnalysis.h" |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 20 | #include "llvm/Analysis/CGSCCPassManager.h" |
Chandler Carruth | b7bdfd6 | 2014-01-13 07:38:24 +0000 | [diff] [blame] | 21 | #include "llvm/Bitcode/BitcodeWriterPass.h" |
Philip Pfaffe | 59d690b | 2017-08-04 09:28:09 +0000 | [diff] [blame] | 22 | #include "llvm/Config/config.h" |
Chandler Carruth | 64764b4 | 2015-01-14 10:19:28 +0000 | [diff] [blame] | 23 | #include "llvm/IR/Dominators.h" |
Chandler Carruth | b353c3f | 2014-01-13 05:16:45 +0000 | [diff] [blame] | 24 | #include "llvm/IR/IRPrintingPasses.h" |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 25 | #include "llvm/IR/LLVMContext.h" |
| 26 | #include "llvm/IR/Module.h" |
| 27 | #include "llvm/IR/PassManager.h" |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 28 | #include "llvm/IR/Verifier.h" |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 29 | #include "llvm/Passes/PassBuilder.h" |
Philip Pfaffe | 131fb97 | 2018-04-05 15:04:13 +0000 | [diff] [blame^] | 30 | #include "llvm/Passes/PassPlugin.h" |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 31 | #include "llvm/Support/CommandLine.h" |
Chandler Carruth | b353c3f | 2014-01-13 05:16:45 +0000 | [diff] [blame] | 32 | #include "llvm/Support/ErrorHandling.h" |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 33 | #include "llvm/Support/ToolOutputFile.h" |
Chandler Carruth | e038552 | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 34 | #include "llvm/Target/TargetMachine.h" |
Tim Shen | 6b411418 | 2017-06-01 01:02:12 +0000 | [diff] [blame] | 35 | #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h" |
Chandler Carruth | 3bab7e1 | 2017-01-11 09:43:56 +0000 | [diff] [blame] | 36 | #include "llvm/Transforms/Scalar/LoopPassManager.h" |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 37 | |
| 38 | using namespace llvm; |
Chandler Carruth | 949282e | 2014-01-13 03:08:40 +0000 | [diff] [blame] | 39 | using namespace opt_tool; |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 40 | |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 41 | static cl::opt<bool> |
| 42 | DebugPM("debug-pass-manager", cl::Hidden, |
| 43 | cl::desc("Print pass management debugging information")); |
| 44 | |
Philip Pfaffe | 131fb97 | 2018-04-05 15:04:13 +0000 | [diff] [blame^] | 45 | static cl::list<std::string> |
| 46 | PassPlugins("load-pass-plugin", |
| 47 | cl::desc("Load passes from plugin library")); |
| 48 | |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 49 | // This flag specifies a textual description of the alias analysis pipeline to |
| 50 | // use when querying for aliasing information. It only works in concert with |
| 51 | // the "passes" flag above. |
| 52 | static cl::opt<std::string> |
| 53 | AAPipeline("aa-pipeline", |
| 54 | cl::desc("A textual description of the alias analysis " |
| 55 | "pipeline for handling managed aliasing queries"), |
| 56 | cl::Hidden); |
| 57 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 58 | /// {{@ These options accept textual pipeline descriptions which will be |
| 59 | /// inserted into default pipelines at the respective extension points |
| 60 | static cl::opt<std::string> PeepholeEPPipeline( |
| 61 | "passes-ep-peephole", |
| 62 | cl::desc("A textual description of the function pass pipeline inserted at " |
| 63 | "the Peephole extension points into default pipelines"), |
| 64 | cl::Hidden); |
| 65 | static cl::opt<std::string> LateLoopOptimizationsEPPipeline( |
| 66 | "passes-ep-late-loop-optimizations", |
| 67 | cl::desc( |
| 68 | "A textual description of the loop pass pipeline inserted at " |
| 69 | "the LateLoopOptimizations extension point into default pipelines"), |
| 70 | cl::Hidden); |
| 71 | static cl::opt<std::string> LoopOptimizerEndEPPipeline( |
| 72 | "passes-ep-loop-optimizer-end", |
| 73 | cl::desc("A textual description of the loop pass pipeline inserted at " |
| 74 | "the LoopOptimizerEnd extension point into default pipelines"), |
| 75 | cl::Hidden); |
| 76 | static cl::opt<std::string> ScalarOptimizerLateEPPipeline( |
| 77 | "passes-ep-scalar-optimizer-late", |
| 78 | cl::desc("A textual description of the function pass pipeline inserted at " |
| 79 | "the ScalarOptimizerLate extension point into default pipelines"), |
| 80 | cl::Hidden); |
| 81 | static cl::opt<std::string> CGSCCOptimizerLateEPPipeline( |
| 82 | "passes-ep-cgscc-optimizer-late", |
| 83 | cl::desc("A textual description of the cgscc pass pipeline inserted at " |
| 84 | "the CGSCCOptimizerLate extension point into default pipelines"), |
| 85 | cl::Hidden); |
| 86 | static cl::opt<std::string> VectorizerStartEPPipeline( |
| 87 | "passes-ep-vectorizer-start", |
| 88 | cl::desc("A textual description of the function pass pipeline inserted at " |
| 89 | "the VectorizerStart extension point into default pipelines"), |
| 90 | cl::Hidden); |
David Blaikie | 0c64f5a | 2018-01-23 01:25:20 +0000 | [diff] [blame] | 91 | static cl::opt<std::string> PipelineStartEPPipeline( |
| 92 | "passes-ep-pipeline-start", |
| 93 | cl::desc("A textual description of the function pass pipeline inserted at " |
| 94 | "the PipelineStart extension point into default pipelines"), |
| 95 | cl::Hidden); |
Dehao Chen | 7b05a27 | 2017-07-26 02:00:43 +0000 | [diff] [blame] | 96 | enum PGOKind { NoPGO, InstrGen, InstrUse, SampleUse }; |
| 97 | static cl::opt<PGOKind> PGOKindFlag( |
| 98 | "pgo-kind", cl::init(NoPGO), cl::Hidden, |
| 99 | cl::desc("The kind of profile guided optimization"), |
| 100 | cl::values(clEnumValN(NoPGO, "nopgo", "Do not use PGO."), |
| 101 | clEnumValN(InstrGen, "new-pm-pgo-instr-gen-pipeline", |
| 102 | "Instrument the IR to generate profile."), |
| 103 | clEnumValN(InstrUse, "new-pm-pgo-instr-use-pipeline", |
| 104 | "Use instrumented profile to guide PGO."), |
| 105 | clEnumValN(SampleUse, "new-pm-pgo-sample-use-pipeline", |
| 106 | "Use sampled profile to guide PGO."))); |
| 107 | static cl::opt<std::string> ProfileFile( |
| 108 | "profile-file", cl::desc("Path to the profile."), cl::Hidden); |
Dehao Chen | e90d015 | 2017-07-26 15:01:20 +0000 | [diff] [blame] | 109 | static cl::opt<bool> DebugInfoForProfiling( |
| 110 | "new-pm-debug-info-for-profiling", cl::init(false), cl::Hidden, |
| 111 | cl::desc("Emit special debug info to enable PGO profile generation.")); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 112 | /// @}} |
| 113 | |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 114 | template <typename PassManagerT> |
| 115 | bool tryParsePipelineText(PassBuilder &PB, StringRef PipelineText) { |
| 116 | if (PipelineText.empty()) |
| 117 | return false; |
| 118 | |
| 119 | // Verify the pipeline is parseable: |
| 120 | PassManagerT PM; |
| 121 | if (PB.parsePassPipeline(PM, PipelineText)) |
| 122 | return true; |
| 123 | |
| 124 | errs() << "Could not parse pipeline '" << PipelineText |
| 125 | << "'. I'm going to igore it.\n"; |
| 126 | return false; |
| 127 | } |
| 128 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 129 | /// If one of the EPPipeline command line options was given, register callbacks |
| 130 | /// for parsing and inserting the given pipeline |
| 131 | static void registerEPCallbacks(PassBuilder &PB, bool VerifyEachPass, |
| 132 | bool DebugLogging) { |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 133 | if (tryParsePipelineText<FunctionPassManager>(PB, PeepholeEPPipeline)) |
Philip Pfaffe | a3b8416 | 2017-07-10 12:48:51 +0000 | [diff] [blame] | 134 | PB.registerPeepholeEPCallback([&PB, VerifyEachPass, DebugLogging]( |
| 135 | FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) { |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 136 | PB.parsePassPipeline(PM, PeepholeEPPipeline, VerifyEachPass, |
| 137 | DebugLogging); |
Philip Pfaffe | a3b8416 | 2017-07-10 12:48:51 +0000 | [diff] [blame] | 138 | }); |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 139 | if (tryParsePipelineText<LoopPassManager>(PB, |
| 140 | LateLoopOptimizationsEPPipeline)) |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 141 | PB.registerLateLoopOptimizationsEPCallback( |
Philip Pfaffe | a3b8416 | 2017-07-10 12:48:51 +0000 | [diff] [blame] | 142 | [&PB, VerifyEachPass, DebugLogging]( |
| 143 | LoopPassManager &PM, PassBuilder::OptimizationLevel Level) { |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 144 | PB.parsePassPipeline(PM, LateLoopOptimizationsEPPipeline, |
| 145 | VerifyEachPass, DebugLogging); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 146 | }); |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 147 | if (tryParsePipelineText<LoopPassManager>(PB, LoopOptimizerEndEPPipeline)) |
Philip Pfaffe | a3b8416 | 2017-07-10 12:48:51 +0000 | [diff] [blame] | 148 | PB.registerLoopOptimizerEndEPCallback([&PB, VerifyEachPass, DebugLogging]( |
| 149 | LoopPassManager &PM, PassBuilder::OptimizationLevel Level) { |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 150 | PB.parsePassPipeline(PM, LoopOptimizerEndEPPipeline, VerifyEachPass, |
| 151 | DebugLogging); |
Philip Pfaffe | a3b8416 | 2017-07-10 12:48:51 +0000 | [diff] [blame] | 152 | }); |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 153 | if (tryParsePipelineText<FunctionPassManager>(PB, |
| 154 | ScalarOptimizerLateEPPipeline)) |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 155 | PB.registerScalarOptimizerLateEPCallback( |
Philip Pfaffe | a3b8416 | 2017-07-10 12:48:51 +0000 | [diff] [blame] | 156 | [&PB, VerifyEachPass, DebugLogging]( |
| 157 | FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) { |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 158 | PB.parsePassPipeline(PM, ScalarOptimizerLateEPPipeline, |
| 159 | VerifyEachPass, DebugLogging); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 160 | }); |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 161 | if (tryParsePipelineText<CGSCCPassManager>(PB, CGSCCOptimizerLateEPPipeline)) |
Philip Pfaffe | a3b8416 | 2017-07-10 12:48:51 +0000 | [diff] [blame] | 162 | PB.registerCGSCCOptimizerLateEPCallback([&PB, VerifyEachPass, DebugLogging]( |
| 163 | CGSCCPassManager &PM, PassBuilder::OptimizationLevel Level) { |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 164 | PB.parsePassPipeline(PM, CGSCCOptimizerLateEPPipeline, VerifyEachPass, |
| 165 | DebugLogging); |
Philip Pfaffe | a3b8416 | 2017-07-10 12:48:51 +0000 | [diff] [blame] | 166 | }); |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 167 | if (tryParsePipelineText<FunctionPassManager>(PB, VectorizerStartEPPipeline)) |
Philip Pfaffe | a3b8416 | 2017-07-10 12:48:51 +0000 | [diff] [blame] | 168 | PB.registerVectorizerStartEPCallback([&PB, VerifyEachPass, DebugLogging]( |
| 169 | FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) { |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 170 | PB.parsePassPipeline(PM, VectorizerStartEPPipeline, VerifyEachPass, |
| 171 | DebugLogging); |
Philip Pfaffe | a3b8416 | 2017-07-10 12:48:51 +0000 | [diff] [blame] | 172 | }); |
David Blaikie | 0c64f5a | 2018-01-23 01:25:20 +0000 | [diff] [blame] | 173 | if (tryParsePipelineText<ModulePassManager>(PB, PipelineStartEPPipeline)) |
| 174 | PB.registerPipelineStartEPCallback( |
| 175 | [&PB, VerifyEachPass, DebugLogging](ModulePassManager &PM) { |
| 176 | PB.parsePassPipeline(PM, PipelineStartEPPipeline, VerifyEachPass, |
| 177 | DebugLogging); |
| 178 | }); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Philip Pfaffe | 59d690b | 2017-08-04 09:28:09 +0000 | [diff] [blame] | 181 | #ifdef LINK_POLLY_INTO_TOOLS |
| 182 | namespace polly { |
| 183 | void RegisterPollyPasses(PassBuilder &); |
| 184 | } |
| 185 | #endif |
| 186 | |
Tim Shen | 6b411418 | 2017-06-01 01:02:12 +0000 | [diff] [blame] | 187 | bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM, |
Reid Kleckner | 3fc649c | 2017-09-23 01:03:17 +0000 | [diff] [blame] | 188 | ToolOutputFile *Out, ToolOutputFile *ThinLTOLinkOut, |
| 189 | ToolOutputFile *OptRemarkFile, |
Chandler Carruth | e038552 | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 190 | StringRef PassPipeline, OutputKind OK, |
Duncan P. N. Exon Smith | 679db33 | 2015-04-15 00:34:24 +0000 | [diff] [blame] | 191 | VerifierKind VK, |
Duncan P. N. Exon Smith | 8a74f68 | 2015-04-15 02:38:06 +0000 | [diff] [blame] | 192 | bool ShouldPreserveAssemblyUseListOrder, |
Teresa Johnson | f93b246 | 2016-08-12 13:53:02 +0000 | [diff] [blame] | 193 | bool ShouldPreserveBitcodeUseListOrder, |
Vedant Kumar | 775c7af | 2018-02-15 21:14:36 +0000 | [diff] [blame] | 194 | bool EmitSummaryIndex, bool EmitModuleHash, |
| 195 | bool EnableDebugify) { |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 196 | bool VerifyEachPass = VK == VK_VerifyEachPass; |
Dehao Chen | 7b05a27 | 2017-07-26 02:00:43 +0000 | [diff] [blame] | 197 | |
| 198 | Optional<PGOOptions> P; |
| 199 | switch (PGOKindFlag) { |
| 200 | case InstrGen: |
| 201 | P = PGOOptions(ProfileFile, "", "", true); |
| 202 | break; |
| 203 | case InstrUse: |
| 204 | P = PGOOptions("", ProfileFile, "", false); |
| 205 | break; |
| 206 | case SampleUse: |
| 207 | P = PGOOptions("", "", ProfileFile, false); |
| 208 | break; |
| 209 | case NoPGO: |
Dehao Chen | e90d015 | 2017-07-26 15:01:20 +0000 | [diff] [blame] | 210 | if (DebugInfoForProfiling) |
| 211 | P = PGOOptions("", "", "", false, true); |
| 212 | else |
| 213 | P = None; |
Dehao Chen | 7b05a27 | 2017-07-26 02:00:43 +0000 | [diff] [blame] | 214 | } |
| 215 | PassBuilder PB(TM, P); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 216 | registerEPCallbacks(PB, VerifyEachPass, DebugPM); |
Chandler Carruth | 2dc92e9 | 2015-02-01 07:40:05 +0000 | [diff] [blame] | 217 | |
Philip Pfaffe | 131fb97 | 2018-04-05 15:04:13 +0000 | [diff] [blame^] | 218 | // Load requested pass plugins and let them register pass builder callbacks |
| 219 | for (auto &PluginFN : PassPlugins) { |
| 220 | auto PassPlugin = PassPlugin::Load(PluginFN); |
| 221 | if (!PassPlugin) { |
| 222 | errs() << "Failed to load passes from '" << PluginFN |
| 223 | << "'. Request ignored.\n"; |
| 224 | continue; |
| 225 | } |
| 226 | |
| 227 | PassPlugin->registerPassBuilderCallbacks(PB); |
| 228 | } |
| 229 | |
Vedant Kumar | 775c7af | 2018-02-15 21:14:36 +0000 | [diff] [blame] | 230 | // Register a callback that creates the debugify passes as needed. |
| 231 | PB.registerPipelineParsingCallback( |
| 232 | [](StringRef Name, ModulePassManager &MPM, |
| 233 | ArrayRef<PassBuilder::PipelineElement>) { |
| 234 | if (Name == "debugify") { |
| 235 | MPM.addPass(NewPMDebugifyPass()); |
| 236 | return true; |
| 237 | } else if (Name == "check-debugify") { |
| 238 | MPM.addPass(NewPMCheckDebugifyPass()); |
| 239 | return true; |
| 240 | } |
| 241 | return false; |
| 242 | }); |
| 243 | |
Philip Pfaffe | 59d690b | 2017-08-04 09:28:09 +0000 | [diff] [blame] | 244 | #ifdef LINK_POLLY_INTO_TOOLS |
| 245 | polly::RegisterPollyPasses(PB); |
| 246 | #endif |
| 247 | |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 248 | // Specially handle the alias analysis manager so that we can register |
| 249 | // a custom pipeline of AA passes with it. |
| 250 | AAManager AA; |
| 251 | if (!PB.parseAAPipeline(AA, AAPipeline)) { |
| 252 | errs() << Arg0 << ": unable to parse AA pipeline description.\n"; |
| 253 | return false; |
| 254 | } |
| 255 | |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 256 | LoopAnalysisManager LAM(DebugPM); |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 257 | FunctionAnalysisManager FAM(DebugPM); |
| 258 | CGSCCAnalysisManager CGAM(DebugPM); |
| 259 | ModuleAnalysisManager MAM(DebugPM); |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 260 | |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 261 | // Register the AA manager first so that our version is the one used. |
| 262 | FAM.registerPass([&] { return std::move(AA); }); |
| 263 | |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 264 | // Register all the basic analyses with the managers. |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 265 | PB.registerModuleAnalyses(MAM); |
| 266 | PB.registerCGSCCAnalyses(CGAM); |
| 267 | PB.registerFunctionAnalyses(FAM); |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 268 | PB.registerLoopAnalyses(LAM); |
Davide Italiano | b6ccd6b | 2016-05-14 23:21:50 +0000 | [diff] [blame] | 269 | PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); |
Chandler Carruth | c68d082 | 2014-02-06 04:25:13 +0000 | [diff] [blame] | 270 | |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 271 | ModulePassManager MPM(DebugPM); |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 272 | if (VK > VK_NoVerifier) |
| 273 | MPM.addPass(VerifierPass()); |
Vedant Kumar | 775c7af | 2018-02-15 21:14:36 +0000 | [diff] [blame] | 274 | if (EnableDebugify) |
| 275 | MPM.addPass(NewPMDebugifyPass()); |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 276 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 277 | if (!PB.parsePassPipeline(MPM, PassPipeline, VerifyEachPass, DebugPM)) { |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 278 | errs() << Arg0 << ": unable to parse pass pipeline description.\n"; |
| 279 | return false; |
| 280 | } |
| 281 | |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 282 | if (VK > VK_NoVerifier) |
| 283 | MPM.addPass(VerifierPass()); |
Vedant Kumar | 775c7af | 2018-02-15 21:14:36 +0000 | [diff] [blame] | 284 | if (EnableDebugify) |
| 285 | MPM.addPass(NewPMCheckDebugifyPass()); |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 286 | |
Chandler Carruth | b353c3f | 2014-01-13 05:16:45 +0000 | [diff] [blame] | 287 | // Add any relevant output pass at the end of the pipeline. |
| 288 | switch (OK) { |
| 289 | case OK_NoOutput: |
| 290 | break; // No output pass needed. |
| 291 | case OK_OutputAssembly: |
Duncan P. N. Exon Smith | 8a74f68 | 2015-04-15 02:38:06 +0000 | [diff] [blame] | 292 | MPM.addPass( |
| 293 | PrintModulePass(Out->os(), "", ShouldPreserveAssemblyUseListOrder)); |
Chandler Carruth | b353c3f | 2014-01-13 05:16:45 +0000 | [diff] [blame] | 294 | break; |
| 295 | case OK_OutputBitcode: |
Teresa Johnson | f93b246 | 2016-08-12 13:53:02 +0000 | [diff] [blame] | 296 | MPM.addPass(BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder, |
| 297 | EmitSummaryIndex, EmitModuleHash)); |
Chandler Carruth | b7bdfd6 | 2014-01-13 07:38:24 +0000 | [diff] [blame] | 298 | break; |
Tim Shen | 6b411418 | 2017-06-01 01:02:12 +0000 | [diff] [blame] | 299 | case OK_OutputThinLTOBitcode: |
| 300 | MPM.addPass(ThinLTOBitcodeWriterPass( |
| 301 | Out->os(), ThinLTOLinkOut ? &ThinLTOLinkOut->os() : nullptr)); |
| 302 | break; |
Chandler Carruth | b353c3f | 2014-01-13 05:16:45 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | // Before executing passes, print the final values of the LLVM options. |
| 306 | cl::PrintOptionValues(); |
| 307 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 308 | // Now that we have all of the passes ready, run them. |
Chandler Carruth | b47f801 | 2016-03-11 11:05:24 +0000 | [diff] [blame] | 309 | MPM.run(M, MAM); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 310 | |
| 311 | // Declare success. |
Tim Shen | 6b411418 | 2017-06-01 01:02:12 +0000 | [diff] [blame] | 312 | if (OK != OK_NoOutput) { |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 313 | Out->keep(); |
Tim Shen | 6b411418 | 2017-06-01 01:02:12 +0000 | [diff] [blame] | 314 | if (OK == OK_OutputThinLTOBitcode && ThinLTOLinkOut) |
| 315 | ThinLTOLinkOut->keep(); |
| 316 | } |
Sam Elliott | b0c9753 | 2017-08-20 01:30:45 +0000 | [diff] [blame] | 317 | |
| 318 | if (OptRemarkFile) |
| 319 | OptRemarkFile->keep(); |
| 320 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 321 | return true; |
| 322 | } |