Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1 | //===- Passes.cpp - Parsing, selection, and running of passes -------------===// |
| 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 provides the infrastructure to parse and build a custom pass |
| 12 | /// manager based on a commandline flag. It also provides helpers to aid in |
| 13 | /// analyzing, debugging, and testing pass structures. |
| 14 | /// |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
| 17 | #include "Passes.h" |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 18 | #include "llvm/Analysis/CGSCCPassManager.h" |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 19 | #include "llvm/Analysis/LazyCallGraph.h" |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 20 | #include "llvm/IR/IRPrintingPasses.h" |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 21 | #include "llvm/IR/PassManager.h" |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 22 | #include "llvm/IR/Verifier.h" |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Debug.h" |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 24 | |
| 25 | using namespace llvm; |
| 26 | |
| 27 | namespace { |
| 28 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 29 | /// \brief No-op module pass which does nothing. |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 30 | struct NoOpModulePass { |
Chandler Carruth | d174ce4 | 2015-01-05 02:47:05 +0000 | [diff] [blame] | 31 | PreservedAnalyses run(Module &M) { return PreservedAnalyses::all(); } |
Chandler Carruth | a13f27c | 2014-01-11 11:52:05 +0000 | [diff] [blame] | 32 | static StringRef name() { return "NoOpModulePass"; } |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 33 | }; |
| 34 | |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame^] | 35 | /// \brief No-op module analysis. |
| 36 | struct NoOpModuleAnalysis { |
| 37 | struct Result {}; |
| 38 | Result run(Module &) { return Result(); } |
| 39 | static StringRef name() { return "NoOpModuleAnalysis"; } |
| 40 | static void *ID() { return (void *)&PassID; } |
| 41 | private: |
| 42 | static char PassID; |
| 43 | }; |
| 44 | |
| 45 | char NoOpModuleAnalysis::PassID; |
| 46 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 47 | /// \brief No-op CGSCC pass which does nothing. |
| 48 | struct NoOpCGSCCPass { |
Chandler Carruth | d174ce4 | 2015-01-05 02:47:05 +0000 | [diff] [blame] | 49 | PreservedAnalyses run(LazyCallGraph::SCC &C) { |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 50 | return PreservedAnalyses::all(); |
| 51 | } |
| 52 | static StringRef name() { return "NoOpCGSCCPass"; } |
| 53 | }; |
| 54 | |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame^] | 55 | /// \brief No-op CGSCC analysis. |
| 56 | struct NoOpCGSCCAnalysis { |
| 57 | struct Result {}; |
| 58 | Result run(LazyCallGraph::SCC &) { return Result(); } |
| 59 | static StringRef name() { return "NoOpCGSCCAnalysis"; } |
| 60 | static void *ID() { return (void *)&PassID; } |
| 61 | private: |
| 62 | static char PassID; |
| 63 | }; |
| 64 | |
| 65 | char NoOpCGSCCAnalysis::PassID; |
| 66 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 67 | /// \brief No-op function pass which does nothing. |
| 68 | struct NoOpFunctionPass { |
Chandler Carruth | d174ce4 | 2015-01-05 02:47:05 +0000 | [diff] [blame] | 69 | PreservedAnalyses run(Function &F) { return PreservedAnalyses::all(); } |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 70 | static StringRef name() { return "NoOpFunctionPass"; } |
| 71 | }; |
| 72 | |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame^] | 73 | /// \brief No-op function analysis. |
| 74 | struct NoOpFunctionAnalysis { |
| 75 | struct Result {}; |
| 76 | Result run(Function &) { return Result(); } |
| 77 | static StringRef name() { return "NoOpFunctionAnalysis"; } |
| 78 | static void *ID() { return (void *)&PassID; } |
| 79 | private: |
| 80 | static char PassID; |
| 81 | }; |
| 82 | |
| 83 | char NoOpFunctionAnalysis::PassID; |
| 84 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 85 | } // End anonymous namespace. |
| 86 | |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 87 | void llvm::registerModuleAnalyses(ModuleAnalysisManager &MAM) { |
| 88 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
| 89 | MAM.registerPass(CREATE_PASS); |
| 90 | #include "PassRegistry.def" |
| 91 | } |
| 92 | |
| 93 | void llvm::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) { |
| 94 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
| 95 | CGAM.registerPass(CREATE_PASS); |
| 96 | #include "PassRegistry.def" |
| 97 | } |
| 98 | |
| 99 | void llvm::registerFunctionAnalyses(FunctionAnalysisManager &FAM) { |
| 100 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
| 101 | FAM.registerPass(CREATE_PASS); |
| 102 | #include "PassRegistry.def" |
| 103 | } |
| 104 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 105 | static bool isModulePassName(StringRef Name) { |
Chandler Carruth | 5894418 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 106 | #define MODULE_PASS(NAME, CREATE_PASS) if (Name == NAME) return true; |
| 107 | #include "PassRegistry.def" |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 108 | |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 109 | // We also support building a require pass around any analysis. |
| 110 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
| 111 | if (Name == "require<" NAME ">") \ |
| 112 | return true; |
| 113 | #include "PassRegistry.def" |
| 114 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 115 | return false; |
| 116 | } |
| 117 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 118 | static bool isCGSCCPassName(StringRef Name) { |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 119 | #define CGSCC_PASS(NAME, CREATE_PASS) if (Name == NAME) return true; |
| 120 | #include "PassRegistry.def" |
| 121 | |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 122 | // We also support building a require pass around any analysis. |
| 123 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
| 124 | if (Name == "require<" NAME ">") \ |
| 125 | return true; |
| 126 | #include "PassRegistry.def" |
| 127 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 128 | return false; |
| 129 | } |
| 130 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 131 | static bool isFunctionPassName(StringRef Name) { |
Chandler Carruth | 5894418 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 132 | #define FUNCTION_PASS(NAME, CREATE_PASS) if (Name == NAME) return true; |
| 133 | #include "PassRegistry.def" |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 134 | |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 135 | // We also support building a require pass around any analysis. |
| 136 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
| 137 | if (Name == "require<" NAME ">") \ |
| 138 | return true; |
| 139 | #include "PassRegistry.def" |
| 140 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 141 | return false; |
| 142 | } |
| 143 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 144 | static bool parseModulePassName(ModulePassManager &MPM, StringRef Name) { |
Chandler Carruth | 5894418 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 145 | #define MODULE_PASS(NAME, CREATE_PASS) \ |
| 146 | if (Name == NAME) { \ |
| 147 | MPM.addPass(CREATE_PASS); \ |
| 148 | return true; \ |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 149 | } |
Chandler Carruth | 5894418 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 150 | #include "PassRegistry.def" |
| 151 | |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 152 | // We also support building a require pass around any analysis. |
| 153 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
| 154 | if (Name == "require<" NAME ">") { \ |
| 155 | MPM.addPass(NoopAnalysisRequirementPass<decltype(CREATE_PASS)>()); \ |
| 156 | return true; \ |
| 157 | } |
| 158 | #include "PassRegistry.def" |
| 159 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 160 | return false; |
| 161 | } |
| 162 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 163 | static bool parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) { |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 164 | #define CGSCC_PASS(NAME, CREATE_PASS) \ |
| 165 | if (Name == NAME) { \ |
| 166 | CGPM.addPass(CREATE_PASS); \ |
| 167 | return true; \ |
| 168 | } |
| 169 | #include "PassRegistry.def" |
| 170 | |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 171 | // We also support building a require pass around any analysis. |
| 172 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
| 173 | if (Name == "require<" NAME ">") { \ |
| 174 | CGPM.addPass(NoopAnalysisRequirementPass<decltype(CREATE_PASS)>()); \ |
| 175 | return true; \ |
| 176 | } |
| 177 | #include "PassRegistry.def" |
| 178 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 179 | return false; |
| 180 | } |
| 181 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 182 | static bool parseFunctionPassName(FunctionPassManager &FPM, StringRef Name) { |
Chandler Carruth | 5894418 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 183 | #define FUNCTION_PASS(NAME, CREATE_PASS) \ |
| 184 | if (Name == NAME) { \ |
| 185 | FPM.addPass(CREATE_PASS); \ |
| 186 | return true; \ |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 187 | } |
Chandler Carruth | 5894418 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 188 | #include "PassRegistry.def" |
| 189 | |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 190 | // We also support building a require pass around any analysis. |
| 191 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
| 192 | if (Name == "require<" NAME ">") { \ |
| 193 | FPM.addPass(NoopAnalysisRequirementPass<decltype(CREATE_PASS)>()); \ |
| 194 | return true; \ |
| 195 | } |
| 196 | #include "PassRegistry.def" |
| 197 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 198 | return false; |
| 199 | } |
| 200 | |
| 201 | static bool parseFunctionPassPipeline(FunctionPassManager &FPM, |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 202 | StringRef &PipelineText, |
| 203 | bool VerifyEachPass) { |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 204 | for (;;) { |
| 205 | // Parse nested pass managers by recursing. |
| 206 | if (PipelineText.startswith("function(")) { |
| 207 | FunctionPassManager NestedFPM; |
| 208 | |
| 209 | // Parse the inner pipeline inte the nested manager. |
| 210 | PipelineText = PipelineText.substr(strlen("function(")); |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 211 | if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass) || |
Chandler Carruth | 6546cb6 | 2014-01-12 10:02:02 +0000 | [diff] [blame] | 212 | PipelineText.empty()) |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 213 | return false; |
Chandler Carruth | 6546cb6 | 2014-01-12 10:02:02 +0000 | [diff] [blame] | 214 | assert(PipelineText[0] == ')'); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 215 | PipelineText = PipelineText.substr(1); |
| 216 | |
| 217 | // Add the nested pass manager with the appropriate adaptor. |
Chandler Carruth | c3f3da3 | 2014-03-09 11:49:53 +0000 | [diff] [blame] | 218 | FPM.addPass(std::move(NestedFPM)); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 219 | } else { |
| 220 | // Otherwise try to parse a pass name. |
| 221 | size_t End = PipelineText.find_first_of(",)"); |
| 222 | if (!parseFunctionPassName(FPM, PipelineText.substr(0, End))) |
| 223 | return false; |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 224 | if (VerifyEachPass) |
| 225 | FPM.addPass(VerifierPass()); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 226 | |
| 227 | PipelineText = PipelineText.substr(End); |
| 228 | } |
| 229 | |
| 230 | if (PipelineText.empty() || PipelineText[0] == ')') |
| 231 | return true; |
| 232 | |
| 233 | assert(PipelineText[0] == ','); |
| 234 | PipelineText = PipelineText.substr(1); |
| 235 | } |
| 236 | } |
| 237 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 238 | static bool parseCGSCCPassPipeline(CGSCCPassManager &CGPM, |
| 239 | StringRef &PipelineText, |
| 240 | bool VerifyEachPass) { |
| 241 | for (;;) { |
| 242 | // Parse nested pass managers by recursing. |
| 243 | if (PipelineText.startswith("cgscc(")) { |
| 244 | CGSCCPassManager NestedCGPM; |
| 245 | |
| 246 | // Parse the inner pipeline into the nested manager. |
| 247 | PipelineText = PipelineText.substr(strlen("cgscc(")); |
| 248 | if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass) || |
| 249 | PipelineText.empty()) |
| 250 | return false; |
| 251 | assert(PipelineText[0] == ')'); |
| 252 | PipelineText = PipelineText.substr(1); |
| 253 | |
| 254 | // Add the nested pass manager with the appropriate adaptor. |
| 255 | CGPM.addPass(std::move(NestedCGPM)); |
| 256 | } else if (PipelineText.startswith("function(")) { |
| 257 | FunctionPassManager NestedFPM; |
| 258 | |
| 259 | // Parse the inner pipeline inte the nested manager. |
| 260 | PipelineText = PipelineText.substr(strlen("function(")); |
| 261 | if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass) || |
| 262 | PipelineText.empty()) |
| 263 | return false; |
| 264 | assert(PipelineText[0] == ')'); |
| 265 | PipelineText = PipelineText.substr(1); |
| 266 | |
| 267 | // Add the nested pass manager with the appropriate adaptor. |
| 268 | CGPM.addPass(createCGSCCToFunctionPassAdaptor(std::move(NestedFPM))); |
| 269 | } else { |
| 270 | // Otherwise try to parse a pass name. |
| 271 | size_t End = PipelineText.find_first_of(",)"); |
| 272 | if (!parseCGSCCPassName(CGPM, PipelineText.substr(0, End))) |
| 273 | return false; |
| 274 | // FIXME: No verifier support for CGSCC passes! |
| 275 | |
| 276 | PipelineText = PipelineText.substr(End); |
| 277 | } |
| 278 | |
| 279 | if (PipelineText.empty() || PipelineText[0] == ')') |
| 280 | return true; |
| 281 | |
| 282 | assert(PipelineText[0] == ','); |
| 283 | PipelineText = PipelineText.substr(1); |
| 284 | } |
| 285 | } |
| 286 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 287 | static bool parseModulePassPipeline(ModulePassManager &MPM, |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 288 | StringRef &PipelineText, |
| 289 | bool VerifyEachPass) { |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 290 | for (;;) { |
| 291 | // Parse nested pass managers by recursing. |
| 292 | if (PipelineText.startswith("module(")) { |
Chandler Carruth | 258dbb3 | 2014-01-11 12:06:47 +0000 | [diff] [blame] | 293 | ModulePassManager NestedMPM; |
| 294 | |
| 295 | // Parse the inner pipeline into the nested manager. |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 296 | PipelineText = PipelineText.substr(strlen("module(")); |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 297 | if (!parseModulePassPipeline(NestedMPM, PipelineText, VerifyEachPass) || |
Chandler Carruth | 6546cb6 | 2014-01-12 10:02:02 +0000 | [diff] [blame] | 298 | PipelineText.empty()) |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 299 | return false; |
Chandler Carruth | 6546cb6 | 2014-01-12 10:02:02 +0000 | [diff] [blame] | 300 | assert(PipelineText[0] == ')'); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 301 | PipelineText = PipelineText.substr(1); |
Chandler Carruth | 258dbb3 | 2014-01-11 12:06:47 +0000 | [diff] [blame] | 302 | |
| 303 | // Now add the nested manager as a module pass. |
Chandler Carruth | c3f3da3 | 2014-03-09 11:49:53 +0000 | [diff] [blame] | 304 | MPM.addPass(std::move(NestedMPM)); |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 305 | } else if (PipelineText.startswith("cgscc(")) { |
| 306 | CGSCCPassManager NestedCGPM; |
| 307 | |
| 308 | // Parse the inner pipeline inte the nested manager. |
| 309 | PipelineText = PipelineText.substr(strlen("cgscc(")); |
| 310 | if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass) || |
| 311 | PipelineText.empty()) |
| 312 | return false; |
| 313 | assert(PipelineText[0] == ')'); |
| 314 | PipelineText = PipelineText.substr(1); |
| 315 | |
| 316 | // Add the nested pass manager with the appropriate adaptor. |
| 317 | MPM.addPass( |
| 318 | createModuleToPostOrderCGSCCPassAdaptor(std::move(NestedCGPM))); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 319 | } else if (PipelineText.startswith("function(")) { |
| 320 | FunctionPassManager NestedFPM; |
| 321 | |
| 322 | // Parse the inner pipeline inte the nested manager. |
| 323 | PipelineText = PipelineText.substr(strlen("function(")); |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 324 | if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass) || |
Chandler Carruth | 6546cb6 | 2014-01-12 10:02:02 +0000 | [diff] [blame] | 325 | PipelineText.empty()) |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 326 | return false; |
Chandler Carruth | 6546cb6 | 2014-01-12 10:02:02 +0000 | [diff] [blame] | 327 | assert(PipelineText[0] == ')'); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 328 | PipelineText = PipelineText.substr(1); |
| 329 | |
| 330 | // Add the nested pass manager with the appropriate adaptor. |
Chandler Carruth | c3f3da3 | 2014-03-09 11:49:53 +0000 | [diff] [blame] | 331 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(NestedFPM))); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 332 | } else { |
| 333 | // Otherwise try to parse a pass name. |
| 334 | size_t End = PipelineText.find_first_of(",)"); |
| 335 | if (!parseModulePassName(MPM, PipelineText.substr(0, End))) |
| 336 | return false; |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 337 | if (VerifyEachPass) |
| 338 | MPM.addPass(VerifierPass()); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 339 | |
| 340 | PipelineText = PipelineText.substr(End); |
| 341 | } |
| 342 | |
| 343 | if (PipelineText.empty() || PipelineText[0] == ')') |
| 344 | return true; |
| 345 | |
| 346 | assert(PipelineText[0] == ','); |
| 347 | PipelineText = PipelineText.substr(1); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | // Primary pass pipeline description parsing routine. |
| 352 | // FIXME: Should this routine accept a TargetMachine or require the caller to |
| 353 | // pre-populate the analysis managers with target-specific stuff? |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 354 | bool llvm::parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText, |
| 355 | bool VerifyEachPass) { |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 356 | // Look at the first entry to figure out which layer to start parsing at. |
| 357 | if (PipelineText.startswith("module(")) |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 358 | return parseModulePassPipeline(MPM, PipelineText, VerifyEachPass) && |
| 359 | PipelineText.empty(); |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 360 | if (PipelineText.startswith("cgscc(")) { |
| 361 | CGSCCPassManager CGPM; |
| 362 | if (!parseCGSCCPassPipeline(CGPM, PipelineText, VerifyEachPass) || |
| 363 | !PipelineText.empty()) |
| 364 | return false; |
| 365 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM))); |
| 366 | return true; |
| 367 | } |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 368 | if (PipelineText.startswith("function(")) { |
| 369 | FunctionPassManager FPM; |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 370 | if (!parseFunctionPassPipeline(FPM, PipelineText, VerifyEachPass) || |
| 371 | !PipelineText.empty()) |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 372 | return false; |
Chandler Carruth | c3f3da3 | 2014-03-09 11:49:53 +0000 | [diff] [blame] | 373 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 374 | return true; |
| 375 | } |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 376 | |
| 377 | // This isn't a direct pass manager name, look for the end of a pass name. |
Chandler Carruth | 6546cb6 | 2014-01-12 10:02:02 +0000 | [diff] [blame] | 378 | StringRef FirstName = |
| 379 | PipelineText.substr(0, PipelineText.find_first_of(",)")); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 380 | if (isModulePassName(FirstName)) |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 381 | return parseModulePassPipeline(MPM, PipelineText, VerifyEachPass) && |
| 382 | PipelineText.empty(); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 383 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 384 | if (isCGSCCPassName(FirstName)) { |
| 385 | CGSCCPassManager CGPM; |
| 386 | if (!parseCGSCCPassPipeline(CGPM, PipelineText, VerifyEachPass) || |
| 387 | !PipelineText.empty()) |
| 388 | return false; |
| 389 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM))); |
| 390 | return true; |
| 391 | } |
| 392 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 393 | if (isFunctionPassName(FirstName)) { |
| 394 | FunctionPassManager FPM; |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 395 | if (!parseFunctionPassPipeline(FPM, PipelineText, VerifyEachPass) || |
| 396 | !PipelineText.empty()) |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 397 | return false; |
Chandler Carruth | c3f3da3 | 2014-03-09 11:49:53 +0000 | [diff] [blame] | 398 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 399 | return true; |
| 400 | } |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 401 | |
| 402 | return false; |
| 403 | } |