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