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