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