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