Chandler Carruth | 4e728be | 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 | a7c2370 | 2018-09-24 16:08:15 +0000 | [diff] [blame] | 17 | #include "Debugify.h" |
Vedant Kumar | b8c067b | 2018-02-15 21:14:36 +0000 | [diff] [blame] | 18 | #include "PassPrinters.h" |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringRef.h" |
Chandler Carruth | 67a41f0 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 20 | #include "llvm/Analysis/AliasAnalysis.h" |
Chandler Carruth | 57418d8 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 21 | #include "llvm/Analysis/CGSCCPassManager.h" |
Chandler Carruth | e2dc71d | 2014-01-13 07:38:24 +0000 | [diff] [blame] | 22 | #include "llvm/Bitcode/BitcodeWriterPass.h" |
Nico Weber | 0f38c60 | 2018-04-30 14:59:11 +0000 | [diff] [blame] | 23 | #include "llvm/Config/llvm-config.h" |
Chandler Carruth | 8c3a02f | 2015-01-14 10:19:28 +0000 | [diff] [blame] | 24 | #include "llvm/IR/Dominators.h" |
Chandler Carruth | 085c07f | 2014-01-13 05:16:45 +0000 | [diff] [blame] | 25 | #include "llvm/IR/IRPrintingPasses.h" |
Chandler Carruth | 4e728be | 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 | 1d9ab25 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 29 | #include "llvm/IR/Verifier.h" |
Chandler Carruth | 2349136 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 30 | #include "llvm/Passes/PassBuilder.h" |
Philip Pfaffe | 5301677 | 2018-04-05 15:04:13 +0000 | [diff] [blame] | 31 | #include "llvm/Passes/PassPlugin.h" |
Fedor Sergeev | a7c2370 | 2018-09-24 16:08:15 +0000 | [diff] [blame] | 32 | #include "llvm/Passes/StandardInstrumentations.h" |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 33 | #include "llvm/Support/CommandLine.h" |
Chandler Carruth | 085c07f | 2014-01-13 05:16:45 +0000 | [diff] [blame] | 34 | #include "llvm/Support/ErrorHandling.h" |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 35 | #include "llvm/Support/ToolOutputFile.h" |
Chandler Carruth | 7724e8e | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 36 | #include "llvm/Target/TargetMachine.h" |
Tim Shen | 2e37885 | 2017-06-01 01:02:12 +0000 | [diff] [blame] | 37 | #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h" |
Chandler Carruth | c68d25f | 2017-01-11 09:43:56 +0000 | [diff] [blame] | 38 | #include "llvm/Transforms/Scalar/LoopPassManager.h" |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 39 | |
| 40 | using namespace llvm; |
Chandler Carruth | 4a76032 | 2014-01-13 03:08:40 +0000 | [diff] [blame] | 41 | using namespace opt_tool; |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 42 | |
Chandler Carruth | 3c95d9c | 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 | 5301677 | 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 | 67a41f0 | 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 | 1904561 | 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 | 0ac8747 | 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 | 0c20a4d | 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 | |
Dehao Chen | c87493d | 2017-07-26 02:00:43 +0000 | [diff] [blame] | 104 | enum PGOKind { NoPGO, InstrGen, InstrUse, SampleUse }; |
| 105 | static cl::opt<PGOKind> PGOKindFlag( |
| 106 | "pgo-kind", cl::init(NoPGO), cl::Hidden, |
| 107 | cl::desc("The kind of profile guided optimization"), |
| 108 | cl::values(clEnumValN(NoPGO, "nopgo", "Do not use PGO."), |
| 109 | clEnumValN(InstrGen, "new-pm-pgo-instr-gen-pipeline", |
| 110 | "Instrument the IR to generate profile."), |
| 111 | clEnumValN(InstrUse, "new-pm-pgo-instr-use-pipeline", |
| 112 | "Use instrumented profile to guide PGO."), |
| 113 | clEnumValN(SampleUse, "new-pm-pgo-sample-use-pipeline", |
| 114 | "Use sampled profile to guide PGO."))); |
| 115 | static cl::opt<std::string> ProfileFile( |
| 116 | "profile-file", cl::desc("Path to the profile."), cl::Hidden); |
Richard Smith | 63ec256 | 2018-10-10 23:13:47 +0000 | [diff] [blame] | 117 | static cl::opt<std::string> |
| 118 | ProfileRemappingFile("profile-remapping-file", |
| 119 | cl::desc("Path to the profile remapping file."), |
| 120 | cl::Hidden); |
Dehao Chen | d2fb04a | 2017-07-26 15:01:20 +0000 | [diff] [blame] | 121 | static cl::opt<bool> DebugInfoForProfiling( |
| 122 | "new-pm-debug-info-for-profiling", cl::init(false), cl::Hidden, |
| 123 | cl::desc("Emit special debug info to enable PGO profile generation.")); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 124 | /// @}} |
| 125 | |
Philip Pfaffe | eb75f90 | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 126 | template <typename PassManagerT> |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 127 | bool tryParsePipelineText(PassBuilder &PB, |
| 128 | const cl::opt<std::string> &PipelineOpt) { |
| 129 | if (PipelineOpt.empty()) |
Philip Pfaffe | eb75f90 | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 130 | return false; |
| 131 | |
| 132 | // Verify the pipeline is parseable: |
| 133 | PassManagerT PM; |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 134 | if (auto Err = PB.parsePassPipeline(PM, PipelineOpt)) { |
| 135 | errs() << "Could not parse -" << PipelineOpt.ArgStr |
| 136 | << " pipeline: " << toString(std::move(Err)) |
| 137 | << "... I'm going to ignore it.\n"; |
| 138 | return false; |
| 139 | } |
| 140 | return true; |
Philip Pfaffe | eb75f90 | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 143 | /// If one of the EPPipeline command line options was given, register callbacks |
| 144 | /// for parsing and inserting the given pipeline |
| 145 | static void registerEPCallbacks(PassBuilder &PB, bool VerifyEachPass, |
| 146 | bool DebugLogging) { |
Philip Pfaffe | eb75f90 | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 147 | if (tryParsePipelineText<FunctionPassManager>(PB, PeepholeEPPipeline)) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 148 | PB.registerPeepholeEPCallback( |
| 149 | [&PB, VerifyEachPass, DebugLogging]( |
| 150 | FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) { |
| 151 | ExitOnError Err("Unable to parse PeepholeEP pipeline: "); |
| 152 | Err(PB.parsePassPipeline(PM, PeepholeEPPipeline, VerifyEachPass, |
| 153 | DebugLogging)); |
| 154 | }); |
Philip Pfaffe | eb75f90 | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 155 | if (tryParsePipelineText<LoopPassManager>(PB, |
| 156 | LateLoopOptimizationsEPPipeline)) |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 157 | PB.registerLateLoopOptimizationsEPCallback( |
Philip Pfaffe | 45074ea | 2017-07-10 12:48:51 +0000 | [diff] [blame] | 158 | [&PB, VerifyEachPass, DebugLogging]( |
| 159 | LoopPassManager &PM, PassBuilder::OptimizationLevel Level) { |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 160 | ExitOnError Err("Unable to parse LateLoopOptimizationsEP pipeline: "); |
| 161 | Err(PB.parsePassPipeline(PM, LateLoopOptimizationsEPPipeline, |
| 162 | VerifyEachPass, DebugLogging)); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 163 | }); |
Philip Pfaffe | eb75f90 | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 164 | if (tryParsePipelineText<LoopPassManager>(PB, LoopOptimizerEndEPPipeline)) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 165 | PB.registerLoopOptimizerEndEPCallback( |
| 166 | [&PB, VerifyEachPass, DebugLogging]( |
| 167 | LoopPassManager &PM, PassBuilder::OptimizationLevel Level) { |
| 168 | ExitOnError Err("Unable to parse LoopOptimizerEndEP pipeline: "); |
| 169 | Err(PB.parsePassPipeline(PM, LoopOptimizerEndEPPipeline, |
| 170 | VerifyEachPass, DebugLogging)); |
| 171 | }); |
Philip Pfaffe | eb75f90 | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 172 | if (tryParsePipelineText<FunctionPassManager>(PB, |
| 173 | ScalarOptimizerLateEPPipeline)) |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 174 | PB.registerScalarOptimizerLateEPCallback( |
Philip Pfaffe | 45074ea | 2017-07-10 12:48:51 +0000 | [diff] [blame] | 175 | [&PB, VerifyEachPass, DebugLogging]( |
| 176 | FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) { |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 177 | ExitOnError Err("Unable to parse ScalarOptimizerLateEP pipeline: "); |
| 178 | Err(PB.parsePassPipeline(PM, ScalarOptimizerLateEPPipeline, |
| 179 | VerifyEachPass, DebugLogging)); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 180 | }); |
Philip Pfaffe | eb75f90 | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 181 | if (tryParsePipelineText<CGSCCPassManager>(PB, CGSCCOptimizerLateEPPipeline)) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 182 | PB.registerCGSCCOptimizerLateEPCallback( |
| 183 | [&PB, VerifyEachPass, DebugLogging]( |
| 184 | CGSCCPassManager &PM, PassBuilder::OptimizationLevel Level) { |
| 185 | ExitOnError Err("Unable to parse CGSCCOptimizerLateEP pipeline: "); |
| 186 | Err(PB.parsePassPipeline(PM, CGSCCOptimizerLateEPPipeline, |
| 187 | VerifyEachPass, DebugLogging)); |
| 188 | }); |
Philip Pfaffe | eb75f90 | 2017-07-11 11:17:44 +0000 | [diff] [blame] | 189 | if (tryParsePipelineText<FunctionPassManager>(PB, VectorizerStartEPPipeline)) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 190 | PB.registerVectorizerStartEPCallback( |
| 191 | [&PB, VerifyEachPass, DebugLogging]( |
| 192 | FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) { |
| 193 | ExitOnError Err("Unable to parse VectorizerStartEP pipeline: "); |
| 194 | Err(PB.parsePassPipeline(PM, VectorizerStartEPPipeline, |
| 195 | VerifyEachPass, DebugLogging)); |
| 196 | }); |
David Blaikie | 0ac8747 | 2018-01-23 01:25:20 +0000 | [diff] [blame] | 197 | if (tryParsePipelineText<ModulePassManager>(PB, PipelineStartEPPipeline)) |
| 198 | PB.registerPipelineStartEPCallback( |
| 199 | [&PB, VerifyEachPass, DebugLogging](ModulePassManager &PM) { |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 200 | ExitOnError Err("Unable to parse PipelineStartEP pipeline: "); |
| 201 | Err(PB.parsePassPipeline(PM, PipelineStartEPPipeline, VerifyEachPass, |
| 202 | DebugLogging)); |
David Blaikie | 0ac8747 | 2018-01-23 01:25:20 +0000 | [diff] [blame] | 203 | }); |
Philip Pfaffe | 0c20a4d | 2018-11-12 11:17:07 +0000 | [diff] [blame] | 204 | if (tryParsePipelineText<FunctionPassManager>(PB, OptimizerLastEPPipeline)) |
| 205 | PB.registerOptimizerLastEPCallback( |
| 206 | [&PB, VerifyEachPass, DebugLogging](FunctionPassManager &PM, |
| 207 | PassBuilder::OptimizationLevel) { |
Philip Pfaffe | d3733c2 | 2018-11-12 12:27:58 +0000 | [diff] [blame] | 208 | ExitOnError Err("Unable to parse OptimizerLastEP pipeline: "); |
| 209 | Err(PB.parsePassPipeline(PM, OptimizerLastEPPipeline, VerifyEachPass, |
| 210 | DebugLogging)); |
Philip Pfaffe | 0c20a4d | 2018-11-12 11:17:07 +0000 | [diff] [blame] | 211 | }); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Philip Pfaffe | 3898809 | 2017-08-04 09:28:09 +0000 | [diff] [blame] | 214 | #ifdef LINK_POLLY_INTO_TOOLS |
| 215 | namespace polly { |
| 216 | void RegisterPollyPasses(PassBuilder &); |
| 217 | } |
| 218 | #endif |
| 219 | |
Tim Shen | 2e37885 | 2017-06-01 01:02:12 +0000 | [diff] [blame] | 220 | bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM, |
Reid Kleckner | 97ca964 | 2017-09-23 01:03:17 +0000 | [diff] [blame] | 221 | ToolOutputFile *Out, ToolOutputFile *ThinLTOLinkOut, |
| 222 | ToolOutputFile *OptRemarkFile, |
Chandler Carruth | 7724e8e | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 223 | StringRef PassPipeline, OutputKind OK, |
Duncan P. N. Exon Smith | e005d71 | 2015-04-15 00:34:24 +0000 | [diff] [blame] | 224 | VerifierKind VK, |
Duncan P. N. Exon Smith | 2c7f24d | 2015-04-15 02:38:06 +0000 | [diff] [blame] | 225 | bool ShouldPreserveAssemblyUseListOrder, |
Teresa Johnson | 3143f33 | 2016-08-12 13:53:02 +0000 | [diff] [blame] | 226 | bool ShouldPreserveBitcodeUseListOrder, |
Vedant Kumar | b8c067b | 2018-02-15 21:14:36 +0000 | [diff] [blame] | 227 | bool EmitSummaryIndex, bool EmitModuleHash, |
| 228 | bool EnableDebugify) { |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 229 | bool VerifyEachPass = VK == VK_VerifyEachPass; |
Dehao Chen | c87493d | 2017-07-26 02:00:43 +0000 | [diff] [blame] | 230 | |
| 231 | Optional<PGOOptions> P; |
| 232 | switch (PGOKindFlag) { |
| 233 | case InstrGen: |
Richard Smith | 63ec256 | 2018-10-10 23:13:47 +0000 | [diff] [blame] | 234 | P = PGOOptions(ProfileFile, "", "", "", true); |
Dehao Chen | c87493d | 2017-07-26 02:00:43 +0000 | [diff] [blame] | 235 | break; |
| 236 | case InstrUse: |
Richard Smith | 63ec256 | 2018-10-10 23:13:47 +0000 | [diff] [blame] | 237 | P = PGOOptions("", ProfileFile, "", ProfileRemappingFile, false); |
Dehao Chen | c87493d | 2017-07-26 02:00:43 +0000 | [diff] [blame] | 238 | break; |
| 239 | case SampleUse: |
Richard Smith | 63ec256 | 2018-10-10 23:13:47 +0000 | [diff] [blame] | 240 | P = PGOOptions("", "", ProfileFile, ProfileRemappingFile, false); |
Dehao Chen | c87493d | 2017-07-26 02:00:43 +0000 | [diff] [blame] | 241 | break; |
| 242 | case NoPGO: |
Dehao Chen | d2fb04a | 2017-07-26 15:01:20 +0000 | [diff] [blame] | 243 | if (DebugInfoForProfiling) |
Richard Smith | 63ec256 | 2018-10-10 23:13:47 +0000 | [diff] [blame] | 244 | P = PGOOptions("", "", "", "", false, true); |
Dehao Chen | d2fb04a | 2017-07-26 15:01:20 +0000 | [diff] [blame] | 245 | else |
| 246 | P = None; |
Dehao Chen | c87493d | 2017-07-26 02:00:43 +0000 | [diff] [blame] | 247 | } |
Fedor Sergeev | a7c2370 | 2018-09-24 16:08:15 +0000 | [diff] [blame] | 248 | PassInstrumentationCallbacks PIC; |
| 249 | StandardInstrumentations SI; |
| 250 | SI.registerCallbacks(PIC); |
| 251 | |
| 252 | PassBuilder PB(TM, P, &PIC); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 253 | registerEPCallbacks(PB, VerifyEachPass, DebugPM); |
Chandler Carruth | 581ef38 | 2015-02-01 07:40:05 +0000 | [diff] [blame] | 254 | |
Philip Pfaffe | 5301677 | 2018-04-05 15:04:13 +0000 | [diff] [blame] | 255 | // Load requested pass plugins and let them register pass builder callbacks |
| 256 | for (auto &PluginFN : PassPlugins) { |
| 257 | auto PassPlugin = PassPlugin::Load(PluginFN); |
| 258 | if (!PassPlugin) { |
| 259 | errs() << "Failed to load passes from '" << PluginFN |
| 260 | << "'. Request ignored.\n"; |
| 261 | continue; |
| 262 | } |
| 263 | |
| 264 | PassPlugin->registerPassBuilderCallbacks(PB); |
| 265 | } |
| 266 | |
Vedant Kumar | b8c067b | 2018-02-15 21:14:36 +0000 | [diff] [blame] | 267 | // Register a callback that creates the debugify passes as needed. |
| 268 | PB.registerPipelineParsingCallback( |
| 269 | [](StringRef Name, ModulePassManager &MPM, |
| 270 | ArrayRef<PassBuilder::PipelineElement>) { |
| 271 | if (Name == "debugify") { |
| 272 | MPM.addPass(NewPMDebugifyPass()); |
| 273 | return true; |
| 274 | } else if (Name == "check-debugify") { |
| 275 | MPM.addPass(NewPMCheckDebugifyPass()); |
| 276 | return true; |
| 277 | } |
| 278 | return false; |
| 279 | }); |
| 280 | |
Philip Pfaffe | 3898809 | 2017-08-04 09:28:09 +0000 | [diff] [blame] | 281 | #ifdef LINK_POLLY_INTO_TOOLS |
| 282 | polly::RegisterPollyPasses(PB); |
| 283 | #endif |
| 284 | |
Chandler Carruth | 67a41f0 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 285 | // Specially handle the alias analysis manager so that we can register |
| 286 | // a custom pipeline of AA passes with it. |
| 287 | AAManager AA; |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 288 | if (auto Err = PB.parseAAPipeline(AA, AAPipeline)) { |
| 289 | errs() << Arg0 << ": " << toString(std::move(Err)) << "\n"; |
Chandler Carruth | 67a41f0 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 290 | return false; |
| 291 | } |
| 292 | |
Justin Bogner | da5e924 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 293 | LoopAnalysisManager LAM(DebugPM); |
Chandler Carruth | 3c95d9c | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 294 | FunctionAnalysisManager FAM(DebugPM); |
| 295 | CGSCCAnalysisManager CGAM(DebugPM); |
| 296 | ModuleAnalysisManager MAM(DebugPM); |
Chandler Carruth | 1d9ab25 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 297 | |
Chandler Carruth | 67a41f0 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 298 | // Register the AA manager first so that our version is the one used. |
| 299 | FAM.registerPass([&] { return std::move(AA); }); |
| 300 | |
Chandler Carruth | 2bbc5ab | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 301 | // Register all the basic analyses with the managers. |
Chandler Carruth | 2349136 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 302 | PB.registerModuleAnalyses(MAM); |
| 303 | PB.registerCGSCCAnalyses(CGAM); |
| 304 | PB.registerFunctionAnalyses(FAM); |
Justin Bogner | da5e924 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 305 | PB.registerLoopAnalyses(LAM); |
Davide Italiano | d1aa4ea | 2016-05-14 23:21:50 +0000 | [diff] [blame] | 306 | PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); |
Chandler Carruth | d8e62b6 | 2014-02-06 04:25:13 +0000 | [diff] [blame] | 307 | |
Chandler Carruth | 3c95d9c | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 308 | ModulePassManager MPM(DebugPM); |
Chandler Carruth | 1d9ab25 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 309 | if (VK > VK_NoVerifier) |
| 310 | MPM.addPass(VerifierPass()); |
Vedant Kumar | b8c067b | 2018-02-15 21:14:36 +0000 | [diff] [blame] | 311 | if (EnableDebugify) |
| 312 | MPM.addPass(NewPMDebugifyPass()); |
Chandler Carruth | 1d9ab25 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 313 | |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 314 | if (auto Err = |
| 315 | PB.parsePassPipeline(MPM, PassPipeline, VerifyEachPass, DebugPM)) { |
| 316 | errs() << Arg0 << ": " << toString(std::move(Err)) << "\n"; |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 317 | return false; |
| 318 | } |
| 319 | |
Chandler Carruth | 1d9ab25 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 320 | if (VK > VK_NoVerifier) |
| 321 | MPM.addPass(VerifierPass()); |
Vedant Kumar | b8c067b | 2018-02-15 21:14:36 +0000 | [diff] [blame] | 322 | if (EnableDebugify) |
| 323 | MPM.addPass(NewPMCheckDebugifyPass()); |
Chandler Carruth | 1d9ab25 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 324 | |
Chandler Carruth | 085c07f | 2014-01-13 05:16:45 +0000 | [diff] [blame] | 325 | // Add any relevant output pass at the end of the pipeline. |
| 326 | switch (OK) { |
| 327 | case OK_NoOutput: |
| 328 | break; // No output pass needed. |
| 329 | case OK_OutputAssembly: |
Duncan P. N. Exon Smith | 2c7f24d | 2015-04-15 02:38:06 +0000 | [diff] [blame] | 330 | MPM.addPass( |
| 331 | PrintModulePass(Out->os(), "", ShouldPreserveAssemblyUseListOrder)); |
Chandler Carruth | 085c07f | 2014-01-13 05:16:45 +0000 | [diff] [blame] | 332 | break; |
| 333 | case OK_OutputBitcode: |
Teresa Johnson | 3143f33 | 2016-08-12 13:53:02 +0000 | [diff] [blame] | 334 | MPM.addPass(BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder, |
| 335 | EmitSummaryIndex, EmitModuleHash)); |
Chandler Carruth | e2dc71d | 2014-01-13 07:38:24 +0000 | [diff] [blame] | 336 | break; |
Tim Shen | 2e37885 | 2017-06-01 01:02:12 +0000 | [diff] [blame] | 337 | case OK_OutputThinLTOBitcode: |
| 338 | MPM.addPass(ThinLTOBitcodeWriterPass( |
| 339 | Out->os(), ThinLTOLinkOut ? &ThinLTOLinkOut->os() : nullptr)); |
| 340 | break; |
Chandler Carruth | 085c07f | 2014-01-13 05:16:45 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | // Before executing passes, print the final values of the LLVM options. |
| 344 | cl::PrintOptionValues(); |
| 345 | |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 346 | // Now that we have all of the passes ready, run them. |
Chandler Carruth | 8e27cb2 | 2016-03-11 11:05:24 +0000 | [diff] [blame] | 347 | MPM.run(M, MAM); |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 348 | |
| 349 | // Declare success. |
Tim Shen | 2e37885 | 2017-06-01 01:02:12 +0000 | [diff] [blame] | 350 | if (OK != OK_NoOutput) { |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 351 | Out->keep(); |
Tim Shen | 2e37885 | 2017-06-01 01:02:12 +0000 | [diff] [blame] | 352 | if (OK == OK_OutputThinLTOBitcode && ThinLTOLinkOut) |
| 353 | ThinLTOLinkOut->keep(); |
| 354 | } |
Sam Elliott | 74a34d9 | 2017-08-20 01:30:45 +0000 | [diff] [blame] | 355 | |
| 356 | if (OptRemarkFile) |
| 357 | OptRemarkFile->keep(); |
| 358 | |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 359 | return true; |
| 360 | } |