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