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