Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 1 | //===- Parsing, selection, and construction of pass pipelines -------------===// |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 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 | /// |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 11 | /// This file provides the implementation of the PassBuilder based on our |
| 12 | /// static pass registry as well as related functionality. It also provides |
| 13 | /// helpers to aid in analyzing, debugging, and testing passes and pass |
| 14 | /// pipelines. |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 15 | /// |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 18 | #include "llvm/Passes/PassBuilder.h" |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringSwitch.h" |
Chandler Carruth | 6f5770b10 | 2016-02-13 23:32:00 +0000 | [diff] [blame] | 20 | #include "llvm/Analysis/AliasAnalysis.h" |
Chandler Carruth | 4f846a5 | 2016-02-20 03:46:03 +0000 | [diff] [blame] | 21 | #include "llvm/Analysis/AliasAnalysisEvaluator.h" |
Chandler Carruth | df8b223 | 2015-01-22 21:53:09 +0000 | [diff] [blame] | 22 | #include "llvm/Analysis/AssumptionCache.h" |
Chandler Carruth | bece8d5 | 2016-02-13 23:46:24 +0000 | [diff] [blame] | 23 | #include "llvm/Analysis/BasicAliasAnalysis.h" |
Chandler Carruth | 342c671 | 2016-02-20 03:52:02 +0000 | [diff] [blame] | 24 | #include "llvm/Analysis/CFLAliasAnalysis.h" |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 25 | #include "llvm/Analysis/CGSCCPassManager.h" |
Chandler Carruth | 4c660f7 | 2016-03-10 11:24:11 +0000 | [diff] [blame^] | 26 | #include "llvm/Analysis/CallGraph.h" |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 27 | #include "llvm/Analysis/DominanceFrontier.h" |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 28 | #include "llvm/Analysis/LazyCallGraph.h" |
Chandler Carruth | aaf0b4c | 2015-01-20 10:58:50 +0000 | [diff] [blame] | 29 | #include "llvm/Analysis/LoopInfo.h" |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 30 | #include "llvm/Analysis/MemoryDependenceAnalysis.h" |
Hongbin Zheng | 3f97840 | 2016-02-25 17:54:07 +0000 | [diff] [blame] | 31 | #include "llvm/Analysis/PostDominators.h" |
Hongbin Zheng | bc53977 | 2016-02-25 17:54:25 +0000 | [diff] [blame] | 32 | #include "llvm/Analysis/RegionInfo.h" |
Chandler Carruth | 2f1fd16 | 2015-08-17 02:08:17 +0000 | [diff] [blame] | 33 | #include "llvm/Analysis/ScalarEvolution.h" |
Chandler Carruth | 2b3d044 | 2016-02-20 04:01:45 +0000 | [diff] [blame] | 34 | #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" |
Chandler Carruth | d6091a0 | 2016-02-20 04:03:06 +0000 | [diff] [blame] | 35 | #include "llvm/Analysis/ScopedNoAliasAA.h" |
Chandler Carruth | 8ca4322 | 2015-01-15 11:39:46 +0000 | [diff] [blame] | 36 | #include "llvm/Analysis/TargetLibraryInfo.h" |
Chandler Carruth | e038552 | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 37 | #include "llvm/Analysis/TargetTransformInfo.h" |
Chandler Carruth | c1dc384 | 2016-02-20 04:04:52 +0000 | [diff] [blame] | 38 | #include "llvm/Analysis/TypeBasedAliasAnalysis.h" |
Chandler Carruth | 64764b4 | 2015-01-14 10:19:28 +0000 | [diff] [blame] | 39 | #include "llvm/IR/Dominators.h" |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 40 | #include "llvm/IR/IRPrintingPasses.h" |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 41 | #include "llvm/IR/PassManager.h" |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 42 | #include "llvm/IR/Verifier.h" |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 43 | #include "llvm/Support/Debug.h" |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 44 | #include "llvm/Support/Regex.h" |
Chandler Carruth | e038552 | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 45 | #include "llvm/Target/TargetMachine.h" |
Chandler Carruth | f49f1a87 | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 46 | #include "llvm/Transforms/IPO/ForceFunctionAttrs.h" |
Chandler Carruth | 9c4ed17 | 2016-02-18 11:03:11 +0000 | [diff] [blame] | 47 | #include "llvm/Transforms/IPO/FunctionAttrs.h" |
Chandler Carruth | 3a040e6 | 2015-12-27 08:41:34 +0000 | [diff] [blame] | 48 | #include "llvm/Transforms/IPO/InferFunctionAttrs.h" |
Justin Bogner | 21e1537 | 2015-10-30 23:28:12 +0000 | [diff] [blame] | 49 | #include "llvm/Transforms/IPO/StripDeadPrototypes.h" |
Chandler Carruth | f49f1a87 | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 50 | #include "llvm/Transforms/InstCombine/InstCombine.h" |
Justin Bogner | 19b6799 | 2015-10-30 23:13:18 +0000 | [diff] [blame] | 51 | #include "llvm/Transforms/Scalar/ADCE.h" |
Chandler Carruth | e8c686a | 2015-02-01 10:51:23 +0000 | [diff] [blame] | 52 | #include "llvm/Transforms/Scalar/EarlyCSE.h" |
Chandler Carruth | 43e590e | 2015-01-24 11:13:02 +0000 | [diff] [blame] | 53 | #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h" |
Chandler Carruth | 29a18a4 | 2015-09-12 09:09:14 +0000 | [diff] [blame] | 54 | #include "llvm/Transforms/Scalar/SROA.h" |
Chandler Carruth | f49f1a87 | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 55 | #include "llvm/Transforms/Scalar/SimplifyCFG.h" |
Chandler Carruth | 58dde8c | 2016-02-26 12:17:54 +0000 | [diff] [blame] | 56 | #include <type_traits> |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 57 | |
| 58 | using namespace llvm; |
| 59 | |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 60 | static Regex DefaultAliasRegex("^(default|lto-pre-link|lto)<(O[0123sz])>$"); |
| 61 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 62 | namespace { |
| 63 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 64 | /// \brief No-op module pass which does nothing. |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 65 | struct NoOpModulePass { |
Chandler Carruth | d174ce4 | 2015-01-05 02:47:05 +0000 | [diff] [blame] | 66 | PreservedAnalyses run(Module &M) { return PreservedAnalyses::all(); } |
Chandler Carruth | a13f27c | 2014-01-11 11:52:05 +0000 | [diff] [blame] | 67 | static StringRef name() { return "NoOpModulePass"; } |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 70 | /// \brief No-op module analysis. |
Chandler Carruth | 3a63435 | 2016-02-26 11:44:45 +0000 | [diff] [blame] | 71 | struct NoOpModuleAnalysis : AnalysisBase<NoOpModuleAnalysis> { |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 72 | struct Result {}; |
| 73 | Result run(Module &) { return Result(); } |
| 74 | static StringRef name() { return "NoOpModuleAnalysis"; } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 77 | /// \brief No-op CGSCC pass which does nothing. |
| 78 | struct NoOpCGSCCPass { |
Chandler Carruth | d174ce4 | 2015-01-05 02:47:05 +0000 | [diff] [blame] | 79 | PreservedAnalyses run(LazyCallGraph::SCC &C) { |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 80 | return PreservedAnalyses::all(); |
| 81 | } |
| 82 | static StringRef name() { return "NoOpCGSCCPass"; } |
| 83 | }; |
| 84 | |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 85 | /// \brief No-op CGSCC analysis. |
Chandler Carruth | 3a63435 | 2016-02-26 11:44:45 +0000 | [diff] [blame] | 86 | struct NoOpCGSCCAnalysis : AnalysisBase<NoOpCGSCCAnalysis> { |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 87 | struct Result {}; |
| 88 | Result run(LazyCallGraph::SCC &) { return Result(); } |
| 89 | static StringRef name() { return "NoOpCGSCCAnalysis"; } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 92 | /// \brief No-op function pass which does nothing. |
| 93 | struct NoOpFunctionPass { |
Chandler Carruth | d174ce4 | 2015-01-05 02:47:05 +0000 | [diff] [blame] | 94 | PreservedAnalyses run(Function &F) { return PreservedAnalyses::all(); } |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 95 | static StringRef name() { return "NoOpFunctionPass"; } |
| 96 | }; |
| 97 | |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 98 | /// \brief No-op function analysis. |
Chandler Carruth | 3a63435 | 2016-02-26 11:44:45 +0000 | [diff] [blame] | 99 | struct NoOpFunctionAnalysis : AnalysisBase<NoOpFunctionAnalysis> { |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 100 | struct Result {}; |
| 101 | Result run(Function &) { return Result(); } |
| 102 | static StringRef name() { return "NoOpFunctionAnalysis"; } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 105 | /// \brief No-op loop pass which does nothing. |
| 106 | struct NoOpLoopPass { |
| 107 | PreservedAnalyses run(Loop &L) { return PreservedAnalyses::all(); } |
| 108 | static StringRef name() { return "NoOpLoopPass"; } |
| 109 | }; |
| 110 | |
| 111 | /// \brief No-op loop analysis. |
Chandler Carruth | 3a63435 | 2016-02-26 11:44:45 +0000 | [diff] [blame] | 112 | struct NoOpLoopAnalysis : AnalysisBase<NoOpLoopAnalysis> { |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 113 | struct Result {}; |
| 114 | Result run(Loop &) { return Result(); } |
| 115 | static StringRef name() { return "NoOpLoopAnalysis"; } |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 116 | }; |
| 117 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 118 | } // End anonymous namespace. |
| 119 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 120 | void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) { |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 121 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 122 | MAM.registerPass([&] { return CREATE_PASS; }); |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 123 | #include "PassRegistry.def" |
| 124 | } |
| 125 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 126 | void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) { |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 127 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 128 | CGAM.registerPass([&] { return CREATE_PASS; }); |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 129 | #include "PassRegistry.def" |
| 130 | } |
| 131 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 132 | void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) { |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 133 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 134 | FAM.registerPass([&] { return CREATE_PASS; }); |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 135 | #include "PassRegistry.def" |
| 136 | } |
| 137 | |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 138 | void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) { |
| 139 | #define LOOP_ANALYSIS(NAME, CREATE_PASS) \ |
| 140 | LAM.registerPass([&] { return CREATE_PASS; }); |
| 141 | #include "PassRegistry.def" |
| 142 | } |
| 143 | |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 144 | void PassBuilder::addPerModuleDefaultPipeline(ModulePassManager &MPM, |
| 145 | OptimizationLevel Level, |
| 146 | bool DebugLogging) { |
| 147 | // FIXME: Finish fleshing this out to match the legacy pipelines. |
| 148 | FunctionPassManager EarlyFPM(DebugLogging); |
| 149 | EarlyFPM.addPass(SimplifyCFGPass()); |
| 150 | EarlyFPM.addPass(SROA()); |
| 151 | EarlyFPM.addPass(EarlyCSEPass()); |
| 152 | EarlyFPM.addPass(LowerExpectIntrinsicPass()); |
| 153 | |
| 154 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM))); |
| 155 | } |
| 156 | |
| 157 | void PassBuilder::addLTOPreLinkDefaultPipeline(ModulePassManager &MPM, |
| 158 | OptimizationLevel Level, |
| 159 | bool DebugLogging) { |
| 160 | // FIXME: We should use a customized pre-link pipeline! |
| 161 | addPerModuleDefaultPipeline(MPM, Level, DebugLogging); |
| 162 | } |
| 163 | |
| 164 | void PassBuilder::addLTODefaultPipeline(ModulePassManager &MPM, |
| 165 | OptimizationLevel Level, |
| 166 | bool DebugLogging) { |
| 167 | // FIXME: Finish fleshing this out to match the legacy LTO pipelines. |
| 168 | FunctionPassManager LateFPM(DebugLogging); |
| 169 | LateFPM.addPass(InstCombinePass()); |
| 170 | LateFPM.addPass(SimplifyCFGPass()); |
| 171 | |
| 172 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(LateFPM))); |
| 173 | } |
| 174 | |
Chandler Carruth | 9d2e58f | 2015-01-06 09:10:47 +0000 | [diff] [blame] | 175 | #ifndef NDEBUG |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 176 | static bool isModulePassName(StringRef Name) { |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 177 | // Manually handle aliases for pre-configured pipeline fragments. |
| 178 | if (Name.startswith("default") || Name.startswith("lto")) |
| 179 | return DefaultAliasRegex.match(Name); |
| 180 | |
Chandler Carruth | 5894418 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 181 | #define MODULE_PASS(NAME, CREATE_PASS) if (Name == NAME) return true; |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 182 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 183 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 184 | return true; |
| 185 | #include "PassRegistry.def" |
| 186 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 187 | return false; |
| 188 | } |
Chandler Carruth | 9d2e58f | 2015-01-06 09:10:47 +0000 | [diff] [blame] | 189 | #endif |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 190 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 191 | static bool isCGSCCPassName(StringRef Name) { |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 192 | #define CGSCC_PASS(NAME, CREATE_PASS) if (Name == NAME) return true; |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 193 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 194 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 195 | return true; |
| 196 | #include "PassRegistry.def" |
| 197 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 198 | return false; |
| 199 | } |
| 200 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 201 | static bool isFunctionPassName(StringRef Name) { |
Chandler Carruth | 5894418 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 202 | #define FUNCTION_PASS(NAME, CREATE_PASS) if (Name == NAME) return true; |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 203 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 204 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 205 | return true; |
| 206 | #include "PassRegistry.def" |
| 207 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 208 | return false; |
| 209 | } |
| 210 | |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 211 | static bool isLoopPassName(StringRef Name) { |
| 212 | #define LOOP_PASS(NAME, CREATE_PASS) if (Name == NAME) return true; |
| 213 | #define LOOP_ANALYSIS(NAME, CREATE_PASS) \ |
| 214 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
| 215 | return true; |
| 216 | #include "PassRegistry.def" |
| 217 | |
| 218 | return false; |
| 219 | } |
| 220 | |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 221 | bool PassBuilder::parseModulePassName(ModulePassManager &MPM, StringRef Name, |
| 222 | bool DebugLogging) { |
| 223 | // Manually handle aliases for pre-configured pipeline fragments. |
| 224 | if (Name.startswith("default") || Name.startswith("lto")) { |
| 225 | SmallVector<StringRef, 3> Matches; |
| 226 | if (!DefaultAliasRegex.match(Name, &Matches)) |
| 227 | return false; |
| 228 | assert(Matches.size() == 3 && "Must capture two matched strings!"); |
| 229 | |
| 230 | auto L = StringSwitch<OptimizationLevel>(Matches[2]) |
| 231 | .Case("O0", O0) |
| 232 | .Case("O1", O1) |
| 233 | .Case("O2", O2) |
| 234 | .Case("O3", O3) |
| 235 | .Case("Os", Os) |
| 236 | .Case("Oz", Oz); |
| 237 | |
| 238 | if (Matches[1] == "default") { |
| 239 | addPerModuleDefaultPipeline(MPM, L, DebugLogging); |
| 240 | } else if (Matches[1] == "lto-pre-link") { |
| 241 | addLTOPreLinkDefaultPipeline(MPM, L, DebugLogging); |
| 242 | } else { |
| 243 | assert(Matches[1] == "lto" && "Not one of the matched options!"); |
| 244 | addLTODefaultPipeline(MPM, L, DebugLogging); |
| 245 | } |
| 246 | return true; |
| 247 | } |
| 248 | |
Chandler Carruth | 5894418 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 249 | #define MODULE_PASS(NAME, CREATE_PASS) \ |
| 250 | if (Name == NAME) { \ |
| 251 | MPM.addPass(CREATE_PASS); \ |
| 252 | return true; \ |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 253 | } |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 254 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
| 255 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 256 | MPM.addPass(RequireAnalysisPass< \ |
| 257 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 258 | return true; \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 259 | } \ |
| 260 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 261 | MPM.addPass(InvalidateAnalysisPass< \ |
| 262 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 263 | return true; \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 264 | } |
| 265 | #include "PassRegistry.def" |
| 266 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 267 | return false; |
| 268 | } |
| 269 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 270 | bool PassBuilder::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) { |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 271 | #define CGSCC_PASS(NAME, CREATE_PASS) \ |
| 272 | if (Name == NAME) { \ |
| 273 | CGPM.addPass(CREATE_PASS); \ |
| 274 | return true; \ |
| 275 | } |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 276 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
| 277 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 278 | CGPM.addPass(RequireAnalysisPass< \ |
| 279 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 280 | return true; \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 281 | } \ |
| 282 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 283 | CGPM.addPass(InvalidateAnalysisPass< \ |
| 284 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 285 | return true; \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 286 | } |
| 287 | #include "PassRegistry.def" |
| 288 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 289 | return false; |
| 290 | } |
| 291 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 292 | bool PassBuilder::parseFunctionPassName(FunctionPassManager &FPM, |
| 293 | StringRef Name) { |
Chandler Carruth | 5894418 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 294 | #define FUNCTION_PASS(NAME, CREATE_PASS) \ |
| 295 | if (Name == NAME) { \ |
| 296 | FPM.addPass(CREATE_PASS); \ |
| 297 | return true; \ |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 298 | } |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 299 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
| 300 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 301 | FPM.addPass(RequireAnalysisPass< \ |
| 302 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 303 | return true; \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 304 | } \ |
| 305 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 306 | FPM.addPass(InvalidateAnalysisPass< \ |
| 307 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 308 | return true; \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 309 | } |
| 310 | #include "PassRegistry.def" |
| 311 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 312 | return false; |
| 313 | } |
| 314 | |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 315 | bool PassBuilder::parseLoopPassName(LoopPassManager &FPM, |
| 316 | StringRef Name) { |
| 317 | #define LOOP_PASS(NAME, CREATE_PASS) \ |
| 318 | if (Name == NAME) { \ |
| 319 | FPM.addPass(CREATE_PASS); \ |
| 320 | return true; \ |
| 321 | } |
| 322 | #define LOOP_ANALYSIS(NAME, CREATE_PASS) \ |
| 323 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 324 | FPM.addPass(RequireAnalysisPass< \ |
| 325 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 326 | return true; \ |
| 327 | } \ |
| 328 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 329 | FPM.addPass(InvalidateAnalysisPass< \ |
| 330 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 331 | return true; \ |
| 332 | } |
| 333 | #include "PassRegistry.def" |
| 334 | |
| 335 | return false; |
| 336 | } |
| 337 | |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 338 | bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) { |
| 339 | #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \ |
| 340 | if (Name == NAME) { \ |
Chandler Carruth | 58dde8c | 2016-02-26 12:17:54 +0000 | [diff] [blame] | 341 | AA.registerFunctionAnalysis< \ |
| 342 | std::remove_reference<decltype(CREATE_PASS)>::type>(); \ |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 343 | return true; \ |
| 344 | } |
| 345 | #include "PassRegistry.def" |
| 346 | |
| 347 | return false; |
| 348 | } |
| 349 | |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 350 | bool PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM, |
| 351 | StringRef &PipelineText, |
| 352 | bool VerifyEachPass, |
| 353 | bool DebugLogging) { |
| 354 | for (;;) { |
| 355 | // Parse nested pass managers by recursing. |
| 356 | if (PipelineText.startswith("loop(")) { |
| 357 | LoopPassManager NestedLPM(DebugLogging); |
| 358 | |
| 359 | // Parse the inner pipeline inte the nested manager. |
| 360 | PipelineText = PipelineText.substr(strlen("loop(")); |
| 361 | if (!parseLoopPassPipeline(NestedLPM, PipelineText, VerifyEachPass, |
| 362 | DebugLogging) || |
| 363 | PipelineText.empty()) |
| 364 | return false; |
| 365 | assert(PipelineText[0] == ')'); |
| 366 | PipelineText = PipelineText.substr(1); |
| 367 | |
| 368 | // Add the nested pass manager with the appropriate adaptor. |
| 369 | LPM.addPass(std::move(NestedLPM)); |
| 370 | } else { |
| 371 | // Otherwise try to parse a pass name. |
| 372 | size_t End = PipelineText.find_first_of(",)"); |
| 373 | if (!parseLoopPassName(LPM, PipelineText.substr(0, End))) |
| 374 | return false; |
| 375 | // TODO: Ideally, we would run a LoopVerifierPass() here in the |
| 376 | // VerifyEachPass case, but we don't have such a verifier yet. |
| 377 | |
| 378 | PipelineText = PipelineText.substr(End); |
| 379 | } |
| 380 | |
| 381 | if (PipelineText.empty() || PipelineText[0] == ')') |
| 382 | return true; |
| 383 | |
| 384 | assert(PipelineText[0] == ','); |
| 385 | PipelineText = PipelineText.substr(1); |
| 386 | } |
| 387 | } |
| 388 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 389 | bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM, |
| 390 | StringRef &PipelineText, |
| 391 | bool VerifyEachPass, |
| 392 | bool DebugLogging) { |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 393 | for (;;) { |
| 394 | // Parse nested pass managers by recursing. |
| 395 | if (PipelineText.startswith("function(")) { |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 396 | FunctionPassManager NestedFPM(DebugLogging); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 397 | |
| 398 | // Parse the inner pipeline inte the nested manager. |
| 399 | PipelineText = PipelineText.substr(strlen("function(")); |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 400 | if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass, |
| 401 | DebugLogging) || |
Chandler Carruth | 6546cb6 | 2014-01-12 10:02:02 +0000 | [diff] [blame] | 402 | PipelineText.empty()) |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 403 | return false; |
Chandler Carruth | 6546cb6 | 2014-01-12 10:02:02 +0000 | [diff] [blame] | 404 | assert(PipelineText[0] == ')'); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 405 | PipelineText = PipelineText.substr(1); |
| 406 | |
| 407 | // Add the nested pass manager with the appropriate adaptor. |
Chandler Carruth | c3f3da3 | 2014-03-09 11:49:53 +0000 | [diff] [blame] | 408 | FPM.addPass(std::move(NestedFPM)); |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 409 | } else if (PipelineText.startswith("loop(")) { |
| 410 | LoopPassManager NestedLPM(DebugLogging); |
| 411 | |
| 412 | // Parse the inner pipeline inte the nested manager. |
| 413 | PipelineText = PipelineText.substr(strlen("loop(")); |
| 414 | if (!parseLoopPassPipeline(NestedLPM, PipelineText, VerifyEachPass, |
| 415 | DebugLogging) || |
| 416 | PipelineText.empty()) |
| 417 | return false; |
| 418 | assert(PipelineText[0] == ')'); |
| 419 | PipelineText = PipelineText.substr(1); |
| 420 | |
| 421 | // Add the nested pass manager with the appropriate adaptor. |
| 422 | FPM.addPass(createFunctionToLoopPassAdaptor(std::move(NestedLPM))); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 423 | } else { |
| 424 | // Otherwise try to parse a pass name. |
| 425 | size_t End = PipelineText.find_first_of(",)"); |
| 426 | if (!parseFunctionPassName(FPM, PipelineText.substr(0, End))) |
| 427 | return false; |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 428 | if (VerifyEachPass) |
| 429 | FPM.addPass(VerifierPass()); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 430 | |
| 431 | PipelineText = PipelineText.substr(End); |
| 432 | } |
| 433 | |
| 434 | if (PipelineText.empty() || PipelineText[0] == ')') |
| 435 | return true; |
| 436 | |
| 437 | assert(PipelineText[0] == ','); |
| 438 | PipelineText = PipelineText.substr(1); |
| 439 | } |
| 440 | } |
| 441 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 442 | bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM, |
| 443 | StringRef &PipelineText, |
| 444 | bool VerifyEachPass, |
| 445 | bool DebugLogging) { |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 446 | for (;;) { |
| 447 | // Parse nested pass managers by recursing. |
| 448 | if (PipelineText.startswith("cgscc(")) { |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 449 | CGSCCPassManager NestedCGPM(DebugLogging); |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 450 | |
| 451 | // Parse the inner pipeline into the nested manager. |
| 452 | PipelineText = PipelineText.substr(strlen("cgscc(")); |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 453 | if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass, |
| 454 | DebugLogging) || |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 455 | PipelineText.empty()) |
| 456 | return false; |
| 457 | assert(PipelineText[0] == ')'); |
| 458 | PipelineText = PipelineText.substr(1); |
| 459 | |
| 460 | // Add the nested pass manager with the appropriate adaptor. |
| 461 | CGPM.addPass(std::move(NestedCGPM)); |
| 462 | } else if (PipelineText.startswith("function(")) { |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 463 | FunctionPassManager NestedFPM(DebugLogging); |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 464 | |
| 465 | // Parse the inner pipeline inte the nested manager. |
| 466 | PipelineText = PipelineText.substr(strlen("function(")); |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 467 | if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass, |
| 468 | DebugLogging) || |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 469 | PipelineText.empty()) |
| 470 | return false; |
| 471 | assert(PipelineText[0] == ')'); |
| 472 | PipelineText = PipelineText.substr(1); |
| 473 | |
| 474 | // Add the nested pass manager with the appropriate adaptor. |
| 475 | CGPM.addPass(createCGSCCToFunctionPassAdaptor(std::move(NestedFPM))); |
| 476 | } else { |
| 477 | // Otherwise try to parse a pass name. |
| 478 | size_t End = PipelineText.find_first_of(",)"); |
| 479 | if (!parseCGSCCPassName(CGPM, PipelineText.substr(0, End))) |
| 480 | return false; |
| 481 | // FIXME: No verifier support for CGSCC passes! |
| 482 | |
| 483 | PipelineText = PipelineText.substr(End); |
| 484 | } |
| 485 | |
| 486 | if (PipelineText.empty() || PipelineText[0] == ')') |
| 487 | return true; |
| 488 | |
| 489 | assert(PipelineText[0] == ','); |
| 490 | PipelineText = PipelineText.substr(1); |
| 491 | } |
| 492 | } |
| 493 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 494 | bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM, |
| 495 | StringRef &PipelineText, |
| 496 | bool VerifyEachPass, |
| 497 | bool DebugLogging) { |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 498 | for (;;) { |
| 499 | // Parse nested pass managers by recursing. |
| 500 | if (PipelineText.startswith("module(")) { |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 501 | ModulePassManager NestedMPM(DebugLogging); |
Chandler Carruth | 258dbb3 | 2014-01-11 12:06:47 +0000 | [diff] [blame] | 502 | |
| 503 | // Parse the inner pipeline into the nested manager. |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 504 | PipelineText = PipelineText.substr(strlen("module(")); |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 505 | if (!parseModulePassPipeline(NestedMPM, PipelineText, VerifyEachPass, |
| 506 | DebugLogging) || |
Chandler Carruth | 6546cb6 | 2014-01-12 10:02:02 +0000 | [diff] [blame] | 507 | PipelineText.empty()) |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 508 | return false; |
Chandler Carruth | 6546cb6 | 2014-01-12 10:02:02 +0000 | [diff] [blame] | 509 | assert(PipelineText[0] == ')'); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 510 | PipelineText = PipelineText.substr(1); |
Chandler Carruth | 258dbb3 | 2014-01-11 12:06:47 +0000 | [diff] [blame] | 511 | |
| 512 | // Now add the nested manager as a module pass. |
Chandler Carruth | c3f3da3 | 2014-03-09 11:49:53 +0000 | [diff] [blame] | 513 | MPM.addPass(std::move(NestedMPM)); |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 514 | } else if (PipelineText.startswith("cgscc(")) { |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 515 | CGSCCPassManager NestedCGPM(DebugLogging); |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 516 | |
| 517 | // Parse the inner pipeline inte the nested manager. |
| 518 | PipelineText = PipelineText.substr(strlen("cgscc(")); |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 519 | if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass, |
| 520 | DebugLogging) || |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 521 | PipelineText.empty()) |
| 522 | return false; |
| 523 | assert(PipelineText[0] == ')'); |
| 524 | PipelineText = PipelineText.substr(1); |
| 525 | |
| 526 | // Add the nested pass manager with the appropriate adaptor. |
| 527 | MPM.addPass( |
| 528 | createModuleToPostOrderCGSCCPassAdaptor(std::move(NestedCGPM))); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 529 | } else if (PipelineText.startswith("function(")) { |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 530 | FunctionPassManager NestedFPM(DebugLogging); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 531 | |
| 532 | // Parse the inner pipeline inte the nested manager. |
| 533 | PipelineText = PipelineText.substr(strlen("function(")); |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 534 | if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass, |
| 535 | DebugLogging) || |
Chandler Carruth | 6546cb6 | 2014-01-12 10:02:02 +0000 | [diff] [blame] | 536 | PipelineText.empty()) |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 537 | return false; |
Chandler Carruth | 6546cb6 | 2014-01-12 10:02:02 +0000 | [diff] [blame] | 538 | assert(PipelineText[0] == ')'); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 539 | PipelineText = PipelineText.substr(1); |
| 540 | |
| 541 | // Add the nested pass manager with the appropriate adaptor. |
Chandler Carruth | c3f3da3 | 2014-03-09 11:49:53 +0000 | [diff] [blame] | 542 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(NestedFPM))); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 543 | } else { |
| 544 | // Otherwise try to parse a pass name. |
| 545 | size_t End = PipelineText.find_first_of(",)"); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 546 | if (!parseModulePassName(MPM, PipelineText.substr(0, End), DebugLogging)) |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 547 | return false; |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 548 | if (VerifyEachPass) |
| 549 | MPM.addPass(VerifierPass()); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 550 | |
| 551 | PipelineText = PipelineText.substr(End); |
| 552 | } |
| 553 | |
| 554 | if (PipelineText.empty() || PipelineText[0] == ')') |
| 555 | return true; |
| 556 | |
| 557 | assert(PipelineText[0] == ','); |
| 558 | PipelineText = PipelineText.substr(1); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // Primary pass pipeline description parsing routine. |
| 563 | // FIXME: Should this routine accept a TargetMachine or require the caller to |
| 564 | // pre-populate the analysis managers with target-specific stuff? |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 565 | bool PassBuilder::parsePassPipeline(ModulePassManager &MPM, |
| 566 | StringRef PipelineText, bool VerifyEachPass, |
| 567 | bool DebugLogging) { |
Chandler Carruth | ea368f1 | 2015-01-06 08:37:58 +0000 | [diff] [blame] | 568 | // By default, try to parse the pipeline as-if it were within an implicit |
| 569 | // 'module(...)' pass pipeline. If this will parse at all, it needs to |
| 570 | // consume the entire string. |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 571 | if (parseModulePassPipeline(MPM, PipelineText, VerifyEachPass, DebugLogging)) |
Chandler Carruth | ea368f1 | 2015-01-06 08:37:58 +0000 | [diff] [blame] | 572 | return PipelineText.empty(); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 573 | |
Chandler Carruth | ea368f1 | 2015-01-06 08:37:58 +0000 | [diff] [blame] | 574 | // This isn't parsable as a module pipeline, look for the end of a pass name |
| 575 | // and directly drop down to that layer. |
Chandler Carruth | 6546cb6 | 2014-01-12 10:02:02 +0000 | [diff] [blame] | 576 | StringRef FirstName = |
| 577 | PipelineText.substr(0, PipelineText.find_first_of(",)")); |
Chandler Carruth | ea368f1 | 2015-01-06 08:37:58 +0000 | [diff] [blame] | 578 | assert(!isModulePassName(FirstName) && |
| 579 | "Already handled all module pipeline options."); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 580 | |
Chandler Carruth | ea368f1 | 2015-01-06 08:37:58 +0000 | [diff] [blame] | 581 | // If this looks like a CGSCC pass, parse the whole thing as a CGSCC |
| 582 | // pipeline. |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 583 | if (PipelineText.startswith("cgscc(") || isCGSCCPassName(FirstName)) { |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 584 | CGSCCPassManager CGPM(DebugLogging); |
| 585 | if (!parseCGSCCPassPipeline(CGPM, PipelineText, VerifyEachPass, |
| 586 | DebugLogging) || |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 587 | !PipelineText.empty()) |
| 588 | return false; |
| 589 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM))); |
| 590 | return true; |
| 591 | } |
| 592 | |
Chandler Carruth | ea368f1 | 2015-01-06 08:37:58 +0000 | [diff] [blame] | 593 | // Similarly, if this looks like a Function pass, parse the whole thing as |
| 594 | // a Function pipelien. |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 595 | if (PipelineText.startswith("function(") || isFunctionPassName(FirstName)) { |
Chandler Carruth | 14a759e | 2015-01-13 22:42:38 +0000 | [diff] [blame] | 596 | FunctionPassManager FPM(DebugLogging); |
| 597 | if (!parseFunctionPassPipeline(FPM, PipelineText, VerifyEachPass, |
| 598 | DebugLogging) || |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 599 | !PipelineText.empty()) |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 600 | return false; |
Chandler Carruth | c3f3da3 | 2014-03-09 11:49:53 +0000 | [diff] [blame] | 601 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 602 | return true; |
| 603 | } |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 604 | |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 605 | // If this looks like a Loop pass, parse the whole thing as a Loop pipeline. |
| 606 | if (PipelineText.startswith("loop(") || isLoopPassName(FirstName)) { |
| 607 | LoopPassManager LPM(DebugLogging); |
| 608 | if (!parseLoopPassPipeline(LPM, PipelineText, VerifyEachPass, |
| 609 | DebugLogging) || |
| 610 | !PipelineText.empty()) |
| 611 | return false; |
| 612 | FunctionPassManager FPM(DebugLogging); |
| 613 | FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM))); |
| 614 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
| 615 | return true; |
| 616 | } |
| 617 | |
| 618 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 619 | return false; |
| 620 | } |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 621 | |
| 622 | bool PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) { |
| 623 | while (!PipelineText.empty()) { |
| 624 | StringRef Name; |
| 625 | std::tie(Name, PipelineText) = PipelineText.split(','); |
| 626 | if (!parseAAPassName(AA, Name)) |
| 627 | return false; |
| 628 | } |
| 629 | |
| 630 | return true; |
| 631 | } |