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); |
Philip Pfaffe | 2d4effb | 2018-11-12 11:17:07 +0000 | [diff] [blame] | 98 | static cl::opt<std::string> OptimizerLastEPPipeline( |
| 99 | "passes-ep-optimizer-last", |
| 100 | cl::desc("A textual description of the function pass pipeline inserted at " |
| 101 | "the OptimizerLast extension point into default pipelines"), |
| 102 | cl::Hidden); |
| 103 | |
Wei Mi | c876e3d | 2019-01-16 23:19:02 +0000 | [diff] [blame^] | 104 | extern cl::opt<PGOKind> PGOKindFlag; |
| 105 | extern cl::opt<std::string> ProfileFile; |
Richard Smith | 6c67662 | 2018-10-10 23:13:47 +0000 | [diff] [blame] | 106 | static cl::opt<std::string> |
| 107 | ProfileRemappingFile("profile-remapping-file", |
| 108 | cl::desc("Path to the profile remapping file."), |
| 109 | cl::Hidden); |
Dehao Chen | e90d015 | 2017-07-26 15:01:20 +0000 | [diff] [blame] | 110 | static cl::opt<bool> DebugInfoForProfiling( |
| 111 | "new-pm-debug-info-for-profiling", cl::init(false), cl::Hidden, |
| 112 | cl::desc("Emit special debug info to enable PGO profile generation.")); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 113 | /// @}} |
| 114 | |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 115 | template <typename PassManagerT> |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 116 | bool tryParsePipelineText(PassBuilder &PB, |
| 117 | const cl::opt<std::string> &PipelineOpt) { |
| 118 | if (PipelineOpt.empty()) |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 119 | return false; |
| 120 | |
| 121 | // Verify the pipeline is parseable: |
| 122 | PassManagerT PM; |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 123 | if (auto Err = PB.parsePassPipeline(PM, PipelineOpt)) { |
| 124 | errs() << "Could not parse -" << PipelineOpt.ArgStr |
| 125 | << " pipeline: " << toString(std::move(Err)) |
| 126 | << "... I'm going to ignore it.\n"; |
| 127 | return false; |
| 128 | } |
| 129 | return true; |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 132 | /// If one of the EPPipeline command line options was given, register callbacks |
| 133 | /// for parsing and inserting the given pipeline |
| 134 | static void registerEPCallbacks(PassBuilder &PB, bool VerifyEachPass, |
| 135 | bool DebugLogging) { |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 136 | if (tryParsePipelineText<FunctionPassManager>(PB, PeepholeEPPipeline)) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 137 | PB.registerPeepholeEPCallback( |
| 138 | [&PB, VerifyEachPass, DebugLogging]( |
| 139 | FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) { |
| 140 | ExitOnError Err("Unable to parse PeepholeEP pipeline: "); |
| 141 | Err(PB.parsePassPipeline(PM, PeepholeEPPipeline, VerifyEachPass, |
| 142 | DebugLogging)); |
| 143 | }); |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 144 | if (tryParsePipelineText<LoopPassManager>(PB, |
| 145 | LateLoopOptimizationsEPPipeline)) |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 146 | PB.registerLateLoopOptimizationsEPCallback( |
Philip Pfaffe | a3b8416 | 2017-07-10 12:48:51 +0000 | [diff] [blame] | 147 | [&PB, VerifyEachPass, DebugLogging]( |
| 148 | LoopPassManager &PM, PassBuilder::OptimizationLevel Level) { |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 149 | ExitOnError Err("Unable to parse LateLoopOptimizationsEP pipeline: "); |
| 150 | Err(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)) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 154 | PB.registerLoopOptimizerEndEPCallback( |
| 155 | [&PB, VerifyEachPass, DebugLogging]( |
| 156 | LoopPassManager &PM, PassBuilder::OptimizationLevel Level) { |
| 157 | ExitOnError Err("Unable to parse LoopOptimizerEndEP pipeline: "); |
| 158 | Err(PB.parsePassPipeline(PM, LoopOptimizerEndEPPipeline, |
| 159 | VerifyEachPass, DebugLogging)); |
| 160 | }); |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 161 | if (tryParsePipelineText<FunctionPassManager>(PB, |
| 162 | ScalarOptimizerLateEPPipeline)) |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 163 | PB.registerScalarOptimizerLateEPCallback( |
Philip Pfaffe | a3b8416 | 2017-07-10 12:48:51 +0000 | [diff] [blame] | 164 | [&PB, VerifyEachPass, DebugLogging]( |
| 165 | FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) { |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 166 | ExitOnError Err("Unable to parse ScalarOptimizerLateEP pipeline: "); |
| 167 | Err(PB.parsePassPipeline(PM, ScalarOptimizerLateEPPipeline, |
| 168 | VerifyEachPass, DebugLogging)); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 169 | }); |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 170 | if (tryParsePipelineText<CGSCCPassManager>(PB, CGSCCOptimizerLateEPPipeline)) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 171 | PB.registerCGSCCOptimizerLateEPCallback( |
| 172 | [&PB, VerifyEachPass, DebugLogging]( |
| 173 | CGSCCPassManager &PM, PassBuilder::OptimizationLevel Level) { |
| 174 | ExitOnError Err("Unable to parse CGSCCOptimizerLateEP pipeline: "); |
| 175 | Err(PB.parsePassPipeline(PM, CGSCCOptimizerLateEPPipeline, |
| 176 | VerifyEachPass, DebugLogging)); |
| 177 | }); |
Philip Pfaffe | b4d500f | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 178 | if (tryParsePipelineText<FunctionPassManager>(PB, VectorizerStartEPPipeline)) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 179 | PB.registerVectorizerStartEPCallback( |
| 180 | [&PB, VerifyEachPass, DebugLogging]( |
| 181 | FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) { |
| 182 | ExitOnError Err("Unable to parse VectorizerStartEP pipeline: "); |
| 183 | Err(PB.parsePassPipeline(PM, VectorizerStartEPPipeline, |
| 184 | VerifyEachPass, DebugLogging)); |
| 185 | }); |
David Blaikie | 0c64f5a | 2018-01-23 01:25:20 +0000 | [diff] [blame] | 186 | if (tryParsePipelineText<ModulePassManager>(PB, PipelineStartEPPipeline)) |
| 187 | PB.registerPipelineStartEPCallback( |
| 188 | [&PB, VerifyEachPass, DebugLogging](ModulePassManager &PM) { |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 189 | ExitOnError Err("Unable to parse PipelineStartEP pipeline: "); |
| 190 | Err(PB.parsePassPipeline(PM, PipelineStartEPPipeline, VerifyEachPass, |
| 191 | DebugLogging)); |
David Blaikie | 0c64f5a | 2018-01-23 01:25:20 +0000 | [diff] [blame] | 192 | }); |
Philip Pfaffe | 2d4effb | 2018-11-12 11:17:07 +0000 | [diff] [blame] | 193 | if (tryParsePipelineText<FunctionPassManager>(PB, OptimizerLastEPPipeline)) |
| 194 | PB.registerOptimizerLastEPCallback( |
| 195 | [&PB, VerifyEachPass, DebugLogging](FunctionPassManager &PM, |
| 196 | PassBuilder::OptimizationLevel) { |
Philip Pfaffe | e194c02 | 2018-11-12 12:27:58 +0000 | [diff] [blame] | 197 | ExitOnError Err("Unable to parse OptimizerLastEP pipeline: "); |
| 198 | Err(PB.parsePassPipeline(PM, OptimizerLastEPPipeline, VerifyEachPass, |
| 199 | DebugLogging)); |
Philip Pfaffe | 2d4effb | 2018-11-12 11:17:07 +0000 | [diff] [blame] | 200 | }); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Philip Pfaffe | 59d690b | 2017-08-04 09:28:09 +0000 | [diff] [blame] | 203 | #ifdef LINK_POLLY_INTO_TOOLS |
| 204 | namespace polly { |
| 205 | void RegisterPollyPasses(PassBuilder &); |
| 206 | } |
| 207 | #endif |
| 208 | |
Tim Shen | 6b411418 | 2017-06-01 01:02:12 +0000 | [diff] [blame] | 209 | bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM, |
Reid Kleckner | 3fc649c | 2017-09-23 01:03:17 +0000 | [diff] [blame] | 210 | ToolOutputFile *Out, ToolOutputFile *ThinLTOLinkOut, |
| 211 | ToolOutputFile *OptRemarkFile, |
Chandler Carruth | e038552 | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 212 | StringRef PassPipeline, OutputKind OK, |
Duncan P. N. Exon Smith | 679db33 | 2015-04-15 00:34:24 +0000 | [diff] [blame] | 213 | VerifierKind VK, |
Duncan P. N. Exon Smith | 8a74f68 | 2015-04-15 02:38:06 +0000 | [diff] [blame] | 214 | bool ShouldPreserveAssemblyUseListOrder, |
Teresa Johnson | f93b246 | 2016-08-12 13:53:02 +0000 | [diff] [blame] | 215 | bool ShouldPreserveBitcodeUseListOrder, |
Vedant Kumar | 775c7af | 2018-02-15 21:14:36 +0000 | [diff] [blame] | 216 | bool EmitSummaryIndex, bool EmitModuleHash, |
| 217 | bool EnableDebugify) { |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 218 | bool VerifyEachPass = VK == VK_VerifyEachPass; |
Dehao Chen | 7b05a27 | 2017-07-26 02:00:43 +0000 | [diff] [blame] | 219 | |
| 220 | Optional<PGOOptions> P; |
| 221 | switch (PGOKindFlag) { |
| 222 | case InstrGen: |
Richard Smith | 6c67662 | 2018-10-10 23:13:47 +0000 | [diff] [blame] | 223 | P = PGOOptions(ProfileFile, "", "", "", true); |
Dehao Chen | 7b05a27 | 2017-07-26 02:00:43 +0000 | [diff] [blame] | 224 | break; |
| 225 | case InstrUse: |
Richard Smith | 6c67662 | 2018-10-10 23:13:47 +0000 | [diff] [blame] | 226 | P = PGOOptions("", ProfileFile, "", ProfileRemappingFile, false); |
Dehao Chen | 7b05a27 | 2017-07-26 02:00:43 +0000 | [diff] [blame] | 227 | break; |
| 228 | case SampleUse: |
Richard Smith | 6c67662 | 2018-10-10 23:13:47 +0000 | [diff] [blame] | 229 | P = PGOOptions("", "", ProfileFile, ProfileRemappingFile, false); |
Dehao Chen | 7b05a27 | 2017-07-26 02:00:43 +0000 | [diff] [blame] | 230 | break; |
| 231 | case NoPGO: |
Dehao Chen | e90d015 | 2017-07-26 15:01:20 +0000 | [diff] [blame] | 232 | if (DebugInfoForProfiling) |
Richard Smith | 6c67662 | 2018-10-10 23:13:47 +0000 | [diff] [blame] | 233 | P = PGOOptions("", "", "", "", false, true); |
Dehao Chen | e90d015 | 2017-07-26 15:01:20 +0000 | [diff] [blame] | 234 | else |
| 235 | P = None; |
Dehao Chen | 7b05a27 | 2017-07-26 02:00:43 +0000 | [diff] [blame] | 236 | } |
Fedor Sergeev | 662e568 | 2018-09-24 16:08:15 +0000 | [diff] [blame] | 237 | PassInstrumentationCallbacks PIC; |
| 238 | StandardInstrumentations SI; |
| 239 | SI.registerCallbacks(PIC); |
| 240 | |
| 241 | PassBuilder PB(TM, P, &PIC); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 242 | registerEPCallbacks(PB, VerifyEachPass, DebugPM); |
Chandler Carruth | 2dc92e9 | 2015-02-01 07:40:05 +0000 | [diff] [blame] | 243 | |
Philip Pfaffe | 131fb97 | 2018-04-05 15:04:13 +0000 | [diff] [blame] | 244 | // Load requested pass plugins and let them register pass builder callbacks |
| 245 | for (auto &PluginFN : PassPlugins) { |
| 246 | auto PassPlugin = PassPlugin::Load(PluginFN); |
| 247 | if (!PassPlugin) { |
| 248 | errs() << "Failed to load passes from '" << PluginFN |
| 249 | << "'. Request ignored.\n"; |
| 250 | continue; |
| 251 | } |
| 252 | |
| 253 | PassPlugin->registerPassBuilderCallbacks(PB); |
| 254 | } |
| 255 | |
Vedant Kumar | 775c7af | 2018-02-15 21:14:36 +0000 | [diff] [blame] | 256 | // Register a callback that creates the debugify passes as needed. |
| 257 | PB.registerPipelineParsingCallback( |
| 258 | [](StringRef Name, ModulePassManager &MPM, |
| 259 | ArrayRef<PassBuilder::PipelineElement>) { |
| 260 | if (Name == "debugify") { |
| 261 | MPM.addPass(NewPMDebugifyPass()); |
| 262 | return true; |
| 263 | } else if (Name == "check-debugify") { |
| 264 | MPM.addPass(NewPMCheckDebugifyPass()); |
| 265 | return true; |
| 266 | } |
| 267 | return false; |
| 268 | }); |
| 269 | |
Philip Pfaffe | 59d690b | 2017-08-04 09:28:09 +0000 | [diff] [blame] | 270 | #ifdef LINK_POLLY_INTO_TOOLS |
| 271 | polly::RegisterPollyPasses(PB); |
| 272 | #endif |
| 273 | |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 274 | // Specially handle the alias analysis manager so that we can register |
| 275 | // a custom pipeline of AA passes with it. |
| 276 | AAManager AA; |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 277 | if (auto Err = PB.parseAAPipeline(AA, AAPipeline)) { |
| 278 | errs() << Arg0 << ": " << toString(std::move(Err)) << "\n"; |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 279 | return false; |
| 280 | } |
| 281 | |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 282 | LoopAnalysisManager LAM(DebugPM); |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 283 | FunctionAnalysisManager FAM(DebugPM); |
| 284 | CGSCCAnalysisManager CGAM(DebugPM); |
| 285 | ModuleAnalysisManager MAM(DebugPM); |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 286 | |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 287 | // Register the AA manager first so that our version is the one used. |
| 288 | FAM.registerPass([&] { return std::move(AA); }); |
| 289 | |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 290 | // Register all the basic analyses with the managers. |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 291 | PB.registerModuleAnalyses(MAM); |
| 292 | PB.registerCGSCCAnalyses(CGAM); |
| 293 | PB.registerFunctionAnalyses(FAM); |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 294 | PB.registerLoopAnalyses(LAM); |
Davide Italiano | b6ccd6b | 2016-05-14 23:21:50 +0000 | [diff] [blame] | 295 | PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); |
Chandler Carruth | c68d082 | 2014-02-06 04:25:13 +0000 | [diff] [blame] | 296 | |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 297 | ModulePassManager MPM(DebugPM); |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 298 | if (VK > VK_NoVerifier) |
| 299 | MPM.addPass(VerifierPass()); |
Vedant Kumar | 775c7af | 2018-02-15 21:14:36 +0000 | [diff] [blame] | 300 | if (EnableDebugify) |
| 301 | MPM.addPass(NewPMDebugifyPass()); |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 302 | |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 303 | if (auto Err = |
| 304 | PB.parsePassPipeline(MPM, PassPipeline, VerifyEachPass, DebugPM)) { |
| 305 | errs() << Arg0 << ": " << toString(std::move(Err)) << "\n"; |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 306 | return false; |
| 307 | } |
| 308 | |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 309 | if (VK > VK_NoVerifier) |
| 310 | MPM.addPass(VerifierPass()); |
Vedant Kumar | 775c7af | 2018-02-15 21:14:36 +0000 | [diff] [blame] | 311 | if (EnableDebugify) |
| 312 | MPM.addPass(NewPMCheckDebugifyPass()); |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 313 | |
Chandler Carruth | b353c3f | 2014-01-13 05:16:45 +0000 | [diff] [blame] | 314 | // Add any relevant output pass at the end of the pipeline. |
| 315 | switch (OK) { |
| 316 | case OK_NoOutput: |
| 317 | break; // No output pass needed. |
| 318 | case OK_OutputAssembly: |
Duncan P. N. Exon Smith | 8a74f68 | 2015-04-15 02:38:06 +0000 | [diff] [blame] | 319 | MPM.addPass( |
| 320 | PrintModulePass(Out->os(), "", ShouldPreserveAssemblyUseListOrder)); |
Chandler Carruth | b353c3f | 2014-01-13 05:16:45 +0000 | [diff] [blame] | 321 | break; |
| 322 | case OK_OutputBitcode: |
Teresa Johnson | f93b246 | 2016-08-12 13:53:02 +0000 | [diff] [blame] | 323 | MPM.addPass(BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder, |
| 324 | EmitSummaryIndex, EmitModuleHash)); |
Chandler Carruth | b7bdfd6 | 2014-01-13 07:38:24 +0000 | [diff] [blame] | 325 | break; |
Tim Shen | 6b411418 | 2017-06-01 01:02:12 +0000 | [diff] [blame] | 326 | case OK_OutputThinLTOBitcode: |
| 327 | MPM.addPass(ThinLTOBitcodeWriterPass( |
| 328 | Out->os(), ThinLTOLinkOut ? &ThinLTOLinkOut->os() : nullptr)); |
| 329 | break; |
Chandler Carruth | b353c3f | 2014-01-13 05:16:45 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | // Before executing passes, print the final values of the LLVM options. |
| 333 | cl::PrintOptionValues(); |
| 334 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 335 | // Now that we have all of the passes ready, run them. |
Chandler Carruth | b47f801 | 2016-03-11 11:05:24 +0000 | [diff] [blame] | 336 | MPM.run(M, MAM); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 337 | |
| 338 | // Declare success. |
Tim Shen | 6b411418 | 2017-06-01 01:02:12 +0000 | [diff] [blame] | 339 | if (OK != OK_NoOutput) { |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 340 | Out->keep(); |
Tim Shen | 6b411418 | 2017-06-01 01:02:12 +0000 | [diff] [blame] | 341 | if (OK == OK_OutputThinLTOBitcode && ThinLTOLinkOut) |
| 342 | ThinLTOLinkOut->keep(); |
| 343 | } |
Sam Elliott | b0c9753 | 2017-08-20 01:30:45 +0000 | [diff] [blame] | 344 | |
| 345 | if (OptRemarkFile) |
| 346 | OptRemarkFile->keep(); |
| 347 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 348 | return true; |
| 349 | } |