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