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