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" |
Daniel Jasper | aec2fa3 | 2016-12-19 08:22:17 +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" |
Mehdi Amini | 27d2379 | 2016-09-16 16:56:30 +0000 | [diff] [blame] | 27 | #include "llvm/Analysis/CFGPrinter.h" |
George Burgess IV | bfa401e | 2016-07-06 00:26:41 +0000 | [diff] [blame] | 28 | #include "llvm/Analysis/CFLAndersAliasAnalysis.h" |
| 29 | #include "llvm/Analysis/CFLSteensAliasAnalysis.h" |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 30 | #include "llvm/Analysis/CGSCCPassManager.h" |
Chandler Carruth | 4c660f7 | 2016-03-10 11:24:11 +0000 | [diff] [blame] | 31 | #include "llvm/Analysis/CallGraph.h" |
Michael Kuperstein | de16b44 | 2016-04-18 23:55:01 +0000 | [diff] [blame] | 32 | #include "llvm/Analysis/DemandedBits.h" |
Chandler Carruth | 49c2219 | 2016-05-12 22:19:39 +0000 | [diff] [blame] | 33 | #include "llvm/Analysis/DependenceAnalysis.h" |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 34 | #include "llvm/Analysis/DominanceFrontier.h" |
Chandler Carruth | 45a9c20 | 2016-03-11 09:15:11 +0000 | [diff] [blame] | 35 | #include "llvm/Analysis/GlobalsModRef.h" |
Dehao Chen | 1a44452 | 2016-07-16 22:51:33 +0000 | [diff] [blame] | 36 | #include "llvm/Analysis/IVUsers.h" |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 37 | #include "llvm/Analysis/LazyCallGraph.h" |
Sean Silva | 687019f | 2016-06-13 22:01:25 +0000 | [diff] [blame] | 38 | #include "llvm/Analysis/LazyValueInfo.h" |
Xinliang David Li | 8a02131 | 2016-07-02 21:18:40 +0000 | [diff] [blame] | 39 | #include "llvm/Analysis/LoopAccessAnalysis.h" |
Chandler Carruth | aaf0b4c | 2015-01-20 10:58:50 +0000 | [diff] [blame] | 40 | #include "llvm/Analysis/LoopInfo.h" |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 41 | #include "llvm/Analysis/MemoryDependenceAnalysis.h" |
Teresa Johnson | f93b246 | 2016-08-12 13:53:02 +0000 | [diff] [blame] | 42 | #include "llvm/Analysis/ModuleSummaryAnalysis.h" |
Adam Nemet | 79ac42a | 2016-07-18 16:29:21 +0000 | [diff] [blame] | 43 | #include "llvm/Analysis/OptimizationDiagnosticInfo.h" |
Hongbin Zheng | 3f97840 | 2016-02-25 17:54:07 +0000 | [diff] [blame] | 44 | #include "llvm/Analysis/PostDominators.h" |
Easwaran Raman | 019e0bf | 2016-06-03 22:54:26 +0000 | [diff] [blame] | 45 | #include "llvm/Analysis/ProfileSummaryInfo.h" |
Hongbin Zheng | bc53977 | 2016-02-25 17:54:25 +0000 | [diff] [blame] | 46 | #include "llvm/Analysis/RegionInfo.h" |
Chandler Carruth | 2f1fd16 | 2015-08-17 02:08:17 +0000 | [diff] [blame] | 47 | #include "llvm/Analysis/ScalarEvolution.h" |
Chandler Carruth | 2b3d044 | 2016-02-20 04:01:45 +0000 | [diff] [blame] | 48 | #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" |
Chandler Carruth | d6091a0 | 2016-02-20 04:03:06 +0000 | [diff] [blame] | 49 | #include "llvm/Analysis/ScopedNoAliasAA.h" |
Chandler Carruth | 8ca4322 | 2015-01-15 11:39:46 +0000 | [diff] [blame] | 50 | #include "llvm/Analysis/TargetLibraryInfo.h" |
Chandler Carruth | e038552 | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 51 | #include "llvm/Analysis/TargetTransformInfo.h" |
Chandler Carruth | c1dc384 | 2016-02-20 04:04:52 +0000 | [diff] [blame] | 52 | #include "llvm/Analysis/TypeBasedAliasAnalysis.h" |
Michael Kuperstein | 82d5da5 | 2016-06-24 20:13:42 +0000 | [diff] [blame] | 53 | #include "llvm/CodeGen/PreISelIntrinsicLowering.h" |
Wei Mi | 90d195a | 2016-07-08 03:32:49 +0000 | [diff] [blame] | 54 | #include "llvm/CodeGen/UnreachableBlockElim.h" |
Chandler Carruth | 64764b4 | 2015-01-14 10:19:28 +0000 | [diff] [blame] | 55 | #include "llvm/IR/Dominators.h" |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 56 | #include "llvm/IR/IRPrintingPasses.h" |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 57 | #include "llvm/IR/PassManager.h" |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 58 | #include "llvm/IR/Verifier.h" |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 59 | #include "llvm/Support/Debug.h" |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 60 | #include "llvm/Support/Regex.h" |
Chandler Carruth | e038552 | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 61 | #include "llvm/Target/TargetMachine.h" |
Xinliang David Li | 64dbb29 | 2016-06-05 05:12:23 +0000 | [diff] [blame] | 62 | #include "llvm/Transforms/GCOVProfiler.h" |
Chandler Carruth | 67fc52f | 2016-08-17 02:56:20 +0000 | [diff] [blame] | 63 | #include "llvm/Transforms/IPO/AlwaysInliner.h" |
Davide Italiano | 164b9bc | 2016-05-05 00:51:09 +0000 | [diff] [blame] | 64 | #include "llvm/Transforms/IPO/ConstantMerge.h" |
Davide Italiano | 92b933a | 2016-07-09 03:25:35 +0000 | [diff] [blame] | 65 | #include "llvm/Transforms/IPO/CrossDSOCFI.h" |
Sean Silva | e3bb457 | 2016-06-12 09:16:39 +0000 | [diff] [blame] | 66 | #include "llvm/Transforms/IPO/DeadArgumentElimination.h" |
Davide Italiano | 344e838 | 2016-05-05 02:37:32 +0000 | [diff] [blame] | 67 | #include "llvm/Transforms/IPO/ElimAvailExtern.h" |
Chandler Carruth | f49f1a87 | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 68 | #include "llvm/Transforms/IPO/ForceFunctionAttrs.h" |
Chandler Carruth | 9c4ed17 | 2016-02-18 11:03:11 +0000 | [diff] [blame] | 69 | #include "llvm/Transforms/IPO/FunctionAttrs.h" |
Teresa Johnson | 2124157 | 2016-07-18 21:22:24 +0000 | [diff] [blame] | 70 | #include "llvm/Transforms/IPO/FunctionImport.h" |
Davide Italiano | 66228c4 | 2016-05-03 19:39:15 +0000 | [diff] [blame] | 71 | #include "llvm/Transforms/IPO/GlobalDCE.h" |
Justin Bogner | 1a07501 | 2016-04-26 00:28:01 +0000 | [diff] [blame] | 72 | #include "llvm/Transforms/IPO/GlobalOpt.h" |
Davide Italiano | 2ae76dd | 2016-11-21 00:28:23 +0000 | [diff] [blame] | 73 | #include "llvm/Transforms/IPO/GlobalSplit.h" |
Chandler Carruth | 3a040e6 | 2015-12-27 08:41:34 +0000 | [diff] [blame] | 74 | #include "llvm/Transforms/IPO/InferFunctionAttrs.h" |
Chandler Carruth | 1d96311 | 2016-12-20 03:15:32 +0000 | [diff] [blame] | 75 | #include "llvm/Transforms/IPO/Inliner.h" |
Justin Bogner | 4563a06 | 2016-04-26 20:15:52 +0000 | [diff] [blame] | 76 | #include "llvm/Transforms/IPO/Internalize.h" |
Davide Italiano | e8ae0b5 | 2016-07-11 18:10:06 +0000 | [diff] [blame] | 77 | #include "llvm/Transforms/IPO/LowerTypeTests.h" |
Easwaran Raman | 1832bf6 | 2016-06-27 16:50:18 +0000 | [diff] [blame] | 78 | #include "llvm/Transforms/IPO/PartialInlining.h" |
Davide Italiano | f54f2f0 | 2016-05-05 21:05:36 +0000 | [diff] [blame] | 79 | #include "llvm/Transforms/IPO/SCCP.h" |
Justin Bogner | 21e1537 | 2015-10-30 23:28:12 +0000 | [diff] [blame] | 80 | #include "llvm/Transforms/IPO/StripDeadPrototypes.h" |
Davide Italiano | d737dd2 | 2016-06-14 21:44:19 +0000 | [diff] [blame] | 81 | #include "llvm/Transforms/IPO/WholeProgramDevirt.h" |
Chandler Carruth | f49f1a87 | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 82 | #include "llvm/Transforms/InstCombine/InstCombine.h" |
Xinliang David Li | e6b8929 | 2016-04-18 17:47:38 +0000 | [diff] [blame] | 83 | #include "llvm/Transforms/InstrProfiling.h" |
Xinliang David Li | 8aebf44 | 2016-05-06 05:49:19 +0000 | [diff] [blame] | 84 | #include "llvm/Transforms/PGOInstrumentation.h" |
Xinliang David Li | d38392e | 2016-05-27 23:20:16 +0000 | [diff] [blame] | 85 | #include "llvm/Transforms/SampleProfile.h" |
Justin Bogner | 19b6799 | 2015-10-30 23:13:18 +0000 | [diff] [blame] | 86 | #include "llvm/Transforms/Scalar/ADCE.h" |
Sean Silva | a4c2d15 | 2016-06-15 06:18:01 +0000 | [diff] [blame] | 87 | #include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h" |
Davide Italiano | 655a145 | 2016-05-25 01:57:04 +0000 | [diff] [blame] | 88 | #include "llvm/Transforms/Scalar/BDCE.h" |
Adam Nemet | 3beef41 | 2016-07-18 16:29:17 +0000 | [diff] [blame] | 89 | #include "llvm/Transforms/Scalar/ConstantHoisting.h" |
Sean Silva | b025d37 | 2016-07-06 23:26:29 +0000 | [diff] [blame] | 90 | #include "llvm/Transforms/Scalar/CorrelatedValuePropagation.h" |
Justin Bogner | 395c212 | 2016-04-22 19:40:41 +0000 | [diff] [blame] | 91 | #include "llvm/Transforms/Scalar/DCE.h" |
Justin Bogner | 594e07b | 2016-05-17 21:38:13 +0000 | [diff] [blame] | 92 | #include "llvm/Transforms/Scalar/DeadStoreElimination.h" |
Chandler Carruth | e8c686a | 2015-02-01 10:51:23 +0000 | [diff] [blame] | 93 | #include "llvm/Transforms/Scalar/EarlyCSE.h" |
Michael Kuperstein | 83b753d | 2016-06-24 23:32:02 +0000 | [diff] [blame] | 94 | #include "llvm/Transforms/Scalar/Float2Int.h" |
Easwaran Raman | 019e0bf | 2016-06-03 22:54:26 +0000 | [diff] [blame] | 95 | #include "llvm/Transforms/Scalar/GVN.h" |
Davide Italiano | 89ab89d | 2016-06-14 00:49:23 +0000 | [diff] [blame] | 96 | #include "llvm/Transforms/Scalar/GuardWidening.h" |
Chandler Carruth | 3bab7e1 | 2017-01-11 09:43:56 +0000 | [diff] [blame^] | 97 | #include "llvm/Transforms/Scalar/IVUsersPrinter.h" |
Sanjoy Das | 4d4339d | 2016-06-05 18:01:19 +0000 | [diff] [blame] | 98 | #include "llvm/Transforms/Scalar/IndVarSimplify.h" |
Sean Silva | 46590d5 | 2016-06-14 00:51:09 +0000 | [diff] [blame] | 99 | #include "llvm/Transforms/Scalar/JumpThreading.h" |
Dehao Chen | f400a09 | 2016-07-12 22:42:24 +0000 | [diff] [blame] | 100 | #include "llvm/Transforms/Scalar/LICM.h" |
Chandler Carruth | 3bab7e1 | 2017-01-11 09:43:56 +0000 | [diff] [blame^] | 101 | #include "llvm/Transforms/Scalar/LoopAccessAnalysisPrinter.h" |
Teresa Johnson | 1eca6bc | 2016-08-13 04:11:27 +0000 | [diff] [blame] | 102 | #include "llvm/Transforms/Scalar/LoopDataPrefetch.h" |
Jun Bum Lim | c837af3 | 2016-07-14 18:28:29 +0000 | [diff] [blame] | 103 | #include "llvm/Transforms/Scalar/LoopDeletion.h" |
Adam Nemet | b2593f7 | 2016-07-18 16:29:27 +0000 | [diff] [blame] | 104 | #include "llvm/Transforms/Scalar/LoopDistribute.h" |
Dehao Chen | b9f8e29 | 2016-07-12 18:45:51 +0000 | [diff] [blame] | 105 | #include "llvm/Transforms/Scalar/LoopIdiomRecognize.h" |
Dehao Chen | dcafd5e | 2016-07-15 16:42:11 +0000 | [diff] [blame] | 106 | #include "llvm/Transforms/Scalar/LoopInstSimplify.h" |
Chandler Carruth | 3bab7e1 | 2017-01-11 09:43:56 +0000 | [diff] [blame^] | 107 | #include "llvm/Transforms/Scalar/LoopPassManager.h" |
Justin Bogner | d0d2341 | 2016-05-03 22:02:31 +0000 | [diff] [blame] | 108 | #include "llvm/Transforms/Scalar/LoopRotation.h" |
Justin Bogner | ab6a513 | 2016-05-03 21:47:32 +0000 | [diff] [blame] | 109 | #include "llvm/Transforms/Scalar/LoopSimplifyCFG.h" |
Dehao Chen | 6132ee8 | 2016-07-18 21:41:50 +0000 | [diff] [blame] | 110 | #include "llvm/Transforms/Scalar/LoopStrengthReduce.h" |
Sean Silva | e3c18a5 | 2016-07-19 23:54:23 +0000 | [diff] [blame] | 111 | #include "llvm/Transforms/Scalar/LoopUnrollPass.h" |
Davide Italiano | 9922344 | 2016-05-13 22:52:35 +0000 | [diff] [blame] | 112 | #include "llvm/Transforms/Scalar/LowerAtomic.h" |
Chandler Carruth | 43e590e | 2015-01-24 11:13:02 +0000 | [diff] [blame] | 113 | #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h" |
Michael Kuperstein | e45d4d9 | 2016-07-28 22:08:41 +0000 | [diff] [blame] | 114 | #include "llvm/Transforms/Scalar/LowerGuardIntrinsic.h" |
Sean Silva | 6347df0 | 2016-06-14 02:44:55 +0000 | [diff] [blame] | 115 | #include "llvm/Transforms/Scalar/MemCpyOptimizer.h" |
Davide Italiano | b49aa5c | 2016-06-17 19:10:09 +0000 | [diff] [blame] | 116 | #include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h" |
Wei Mi | 1cf58f8 | 2016-07-21 22:28:52 +0000 | [diff] [blame] | 117 | #include "llvm/Transforms/Scalar/NaryReassociate.h" |
Davide Italiano | e05e330 | 2016-12-22 16:35:02 +0000 | [diff] [blame] | 118 | #include "llvm/Transforms/Scalar/NewGVN.h" |
Davide Italiano | 1021c68 | 2016-05-25 23:38:53 +0000 | [diff] [blame] | 119 | #include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h" |
Justin Bogner | c2bf63d | 2016-04-26 23:39:29 +0000 | [diff] [blame] | 120 | #include "llvm/Transforms/Scalar/Reassociate.h" |
Davide Italiano | 98f7e0e | 2016-05-18 15:18:25 +0000 | [diff] [blame] | 121 | #include "llvm/Transforms/Scalar/SCCP.h" |
Chandler Carruth | 29a18a4 | 2015-09-12 09:09:14 +0000 | [diff] [blame] | 122 | #include "llvm/Transforms/Scalar/SROA.h" |
Chandler Carruth | f49f1a87 | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 123 | #include "llvm/Transforms/Scalar/SimplifyCFG.h" |
Justin Bogner | b939490 | 2016-04-22 19:54:10 +0000 | [diff] [blame] | 124 | #include "llvm/Transforms/Scalar/Sink.h" |
Michael Kuperstein | c406186 | 2016-08-01 21:48:33 +0000 | [diff] [blame] | 125 | #include "llvm/Transforms/Scalar/SpeculativeExecution.h" |
Sean Silva | 59fe82f | 2016-07-06 23:48:41 +0000 | [diff] [blame] | 126 | #include "llvm/Transforms/Scalar/TailRecursionElimination.h" |
Xinliang David Li | 1eaecef | 2016-06-15 21:51:30 +0000 | [diff] [blame] | 127 | #include "llvm/Transforms/Utils/AddDiscriminators.h" |
Wei Mi | e04d0ef | 2016-07-22 18:04:25 +0000 | [diff] [blame] | 128 | #include "llvm/Transforms/Utils/BreakCriticalEdges.h" |
Easwaran Raman | e12c487 | 2016-06-09 19:44:46 +0000 | [diff] [blame] | 129 | #include "llvm/Transforms/Utils/LCSSA.h" |
Rong Xu | 1c0e9b9 | 2016-10-18 21:36:27 +0000 | [diff] [blame] | 130 | #include "llvm/Transforms/Utils/LibCallsShrinkWrap.h" |
Davide Italiano | cd96cfd | 2016-07-09 03:03:01 +0000 | [diff] [blame] | 131 | #include "llvm/Transforms/Utils/LoopSimplify.h" |
Michael Kuperstein | 31b8399 | 2016-08-12 17:28:27 +0000 | [diff] [blame] | 132 | #include "llvm/Transforms/Utils/LowerInvoke.h" |
Davide Italiano | cccf4f0 | 2016-06-14 03:22:22 +0000 | [diff] [blame] | 133 | #include "llvm/Transforms/Utils/Mem2Reg.h" |
Geoff Berry | b96d3b2 | 2016-06-01 21:30:40 +0000 | [diff] [blame] | 134 | #include "llvm/Transforms/Utils/MemorySSA.h" |
Mehdi Amini | 27d2379 | 2016-09-16 16:56:30 +0000 | [diff] [blame] | 135 | #include "llvm/Transforms/Utils/NameAnonGlobals.h" |
Davide Italiano | 16284df | 2016-07-07 21:14:36 +0000 | [diff] [blame] | 136 | #include "llvm/Transforms/Utils/SimplifyInstructions.h" |
Michael Kuperstein | 39feb62 | 2016-07-25 20:52:00 +0000 | [diff] [blame] | 137 | #include "llvm/Transforms/Utils/SymbolRewriter.h" |
Sean Silva | db90d4d | 2016-07-09 22:56:50 +0000 | [diff] [blame] | 138 | #include "llvm/Transforms/Vectorize/LoopVectorize.h" |
Sean Silva | 0dacbd8 | 2016-07-09 03:11:29 +0000 | [diff] [blame] | 139 | #include "llvm/Transforms/Vectorize/SLPVectorizer.h" |
Davide Italiano | cccf4f0 | 2016-06-14 03:22:22 +0000 | [diff] [blame] | 140 | |
Chandler Carruth | 58dde8c | 2016-02-26 12:17:54 +0000 | [diff] [blame] | 141 | #include <type_traits> |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 142 | |
| 143 | using namespace llvm; |
| 144 | |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 145 | static Regex DefaultAliasRegex("^(default|lto-pre-link|lto)<(O[0123sz])>$"); |
| 146 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 147 | static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level) { |
| 148 | switch (Level) { |
| 149 | case PassBuilder::O0: |
| 150 | case PassBuilder::O1: |
| 151 | case PassBuilder::O2: |
| 152 | case PassBuilder::O3: |
| 153 | return false; |
| 154 | |
| 155 | case PassBuilder::Os: |
| 156 | case PassBuilder::Oz: |
| 157 | return true; |
| 158 | } |
| 159 | llvm_unreachable("Invalid optimization level!"); |
| 160 | } |
| 161 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 162 | namespace { |
| 163 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 164 | /// \brief No-op module pass which does nothing. |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 165 | struct NoOpModulePass { |
Sean Silva | fd03ac6 | 2016-08-09 00:28:38 +0000 | [diff] [blame] | 166 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &) { |
Chandler Carruth | 164a2aa6 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 167 | return PreservedAnalyses::all(); |
| 168 | } |
Chandler Carruth | a13f27c | 2014-01-11 11:52:05 +0000 | [diff] [blame] | 169 | static StringRef name() { return "NoOpModulePass"; } |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 170 | }; |
| 171 | |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 172 | /// \brief No-op module analysis. |
Chandler Carruth | 30a0730 | 2016-03-11 10:33:22 +0000 | [diff] [blame] | 173 | class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> { |
| 174 | friend AnalysisInfoMixin<NoOpModuleAnalysis>; |
Chandler Carruth | dab4eae | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 175 | static AnalysisKey Key; |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 176 | |
| 177 | public: |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 178 | struct Result {}; |
Sean Silva | fd03ac6 | 2016-08-09 00:28:38 +0000 | [diff] [blame] | 179 | Result run(Module &, ModuleAnalysisManager &) { return Result(); } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 180 | static StringRef name() { return "NoOpModuleAnalysis"; } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 181 | }; |
| 182 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 183 | /// \brief No-op CGSCC pass which does nothing. |
| 184 | struct NoOpCGSCCPass { |
Chandler Carruth | 8882346 | 2016-08-24 09:37:14 +0000 | [diff] [blame] | 185 | PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &, |
| 186 | LazyCallGraph &, CGSCCUpdateResult &UR) { |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 187 | return PreservedAnalyses::all(); |
| 188 | } |
| 189 | static StringRef name() { return "NoOpCGSCCPass"; } |
| 190 | }; |
| 191 | |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 192 | /// \brief No-op CGSCC analysis. |
Chandler Carruth | 30a0730 | 2016-03-11 10:33:22 +0000 | [diff] [blame] | 193 | class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> { |
| 194 | friend AnalysisInfoMixin<NoOpCGSCCAnalysis>; |
Chandler Carruth | dab4eae | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 195 | static AnalysisKey Key; |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 196 | |
| 197 | public: |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 198 | struct Result {}; |
Chandler Carruth | 8882346 | 2016-08-24 09:37:14 +0000 | [diff] [blame] | 199 | Result run(LazyCallGraph::SCC &, CGSCCAnalysisManager &, LazyCallGraph &G) { |
Chandler Carruth | 164a2aa6 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 200 | return Result(); |
| 201 | } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 202 | static StringRef name() { return "NoOpCGSCCAnalysis"; } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 203 | }; |
| 204 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 205 | /// \brief No-op function pass which does nothing. |
| 206 | struct NoOpFunctionPass { |
Sean Silva | 36e0d01 | 2016-08-09 00:28:15 +0000 | [diff] [blame] | 207 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &) { |
Chandler Carruth | 164a2aa6 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 208 | return PreservedAnalyses::all(); |
| 209 | } |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 210 | static StringRef name() { return "NoOpFunctionPass"; } |
| 211 | }; |
| 212 | |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 213 | /// \brief No-op function analysis. |
Chandler Carruth | 30a0730 | 2016-03-11 10:33:22 +0000 | [diff] [blame] | 214 | class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> { |
| 215 | friend AnalysisInfoMixin<NoOpFunctionAnalysis>; |
Chandler Carruth | dab4eae | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 216 | static AnalysisKey Key; |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 217 | |
| 218 | public: |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 219 | struct Result {}; |
Sean Silva | 36e0d01 | 2016-08-09 00:28:15 +0000 | [diff] [blame] | 220 | Result run(Function &, FunctionAnalysisManager &) { return Result(); } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 221 | static StringRef name() { return "NoOpFunctionAnalysis"; } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 222 | }; |
| 223 | |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 224 | /// \brief No-op loop pass which does nothing. |
| 225 | struct NoOpLoopPass { |
Chandler Carruth | 410eaeb | 2017-01-11 06:23:21 +0000 | [diff] [blame] | 226 | PreservedAnalyses run(Loop &L, LoopAnalysisManager &, |
| 227 | LoopStandardAnalysisResults &, LPMUpdater &) { |
Chandler Carruth | 164a2aa6 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 228 | return PreservedAnalyses::all(); |
| 229 | } |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 230 | static StringRef name() { return "NoOpLoopPass"; } |
| 231 | }; |
| 232 | |
| 233 | /// \brief No-op loop analysis. |
Chandler Carruth | 30a0730 | 2016-03-11 10:33:22 +0000 | [diff] [blame] | 234 | class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> { |
| 235 | friend AnalysisInfoMixin<NoOpLoopAnalysis>; |
Chandler Carruth | dab4eae | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 236 | static AnalysisKey Key; |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 237 | |
| 238 | public: |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 239 | struct Result {}; |
Chandler Carruth | 410eaeb | 2017-01-11 06:23:21 +0000 | [diff] [blame] | 240 | Result run(Loop &, LoopAnalysisManager &, LoopStandardAnalysisResults &) { |
| 241 | return Result(); |
| 242 | } |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 243 | static StringRef name() { return "NoOpLoopAnalysis"; } |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 244 | }; |
| 245 | |
Chandler Carruth | dab4eae | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 246 | AnalysisKey NoOpModuleAnalysis::Key; |
| 247 | AnalysisKey NoOpCGSCCAnalysis::Key; |
| 248 | AnalysisKey NoOpFunctionAnalysis::Key; |
| 249 | AnalysisKey NoOpLoopAnalysis::Key; |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 250 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 251 | } // End anonymous namespace. |
| 252 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 253 | void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) { |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 254 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 255 | MAM.registerPass([&] { return CREATE_PASS; }); |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 256 | #include "PassRegistry.def" |
| 257 | } |
| 258 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 259 | void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) { |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 260 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 261 | CGAM.registerPass([&] { return CREATE_PASS; }); |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 262 | #include "PassRegistry.def" |
| 263 | } |
| 264 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 265 | void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) { |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 266 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 267 | FAM.registerPass([&] { return CREATE_PASS; }); |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 268 | #include "PassRegistry.def" |
| 269 | } |
| 270 | |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 271 | void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) { |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 272 | #define LOOP_ANALYSIS(NAME, CREATE_PASS) \ |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 273 | LAM.registerPass([&] { return CREATE_PASS; }); |
| 274 | #include "PassRegistry.def" |
| 275 | } |
| 276 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 277 | FunctionPassManager |
| 278 | PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level, |
| 279 | bool DebugLogging) { |
| 280 | assert(Level != O0 && "Must request optimizations!"); |
| 281 | FunctionPassManager FPM(DebugLogging); |
| 282 | |
| 283 | // Form SSA out of local memory accesses after breaking apart aggregates into |
| 284 | // scalars. |
| 285 | FPM.addPass(SROA()); |
| 286 | |
| 287 | // Catch trivial redundancies |
| 288 | FPM.addPass(EarlyCSEPass()); |
| 289 | |
| 290 | // Speculative execution if the target has divergent branches; otherwise nop. |
| 291 | FPM.addPass(SpeculativeExecutionPass()); |
| 292 | |
| 293 | // Optimize based on known information about branches, and cleanup afterward. |
| 294 | FPM.addPass(JumpThreadingPass()); |
| 295 | FPM.addPass(CorrelatedValuePropagationPass()); |
| 296 | FPM.addPass(SimplifyCFGPass()); |
| 297 | FPM.addPass(InstCombinePass()); |
| 298 | |
| 299 | if (!isOptimizingForSize(Level)) |
| 300 | FPM.addPass(LibCallsShrinkWrapPass()); |
| 301 | |
| 302 | FPM.addPass(TailCallElimPass()); |
| 303 | FPM.addPass(SimplifyCFGPass()); |
| 304 | |
| 305 | // Form canonically associated expression trees, and simplify the trees using |
| 306 | // basic mathematical properties. For example, this will form (nearly) |
| 307 | // minimal multiplication trees. |
| 308 | FPM.addPass(ReassociatePass()); |
| 309 | |
| 310 | // Add the primary loop simplification pipeline. |
| 311 | // FIXME: Currently this is split into two loop pass pipelines because we run |
| 312 | // some function passes in between them. These can and should be replaced by |
| 313 | // loop pass equivalenst but those aren't ready yet. Specifically, |
| 314 | // `SimplifyCFGPass` and `InstCombinePass` are used. We have |
| 315 | // `LoopSimplifyCFGPass` which isn't yet powerful enough, and the closest to |
| 316 | // the other we have is `LoopInstSimplify`. |
| 317 | LoopPassManager LPM1(DebugLogging), LPM2(DebugLogging); |
| 318 | |
Chandler Carruth | 81c8eda | 2016-12-27 10:16:46 +0000 | [diff] [blame] | 319 | // FIXME: Enable these when the loop pass manager can support enforcing loop |
| 320 | // simplified and LCSSA form as well as updating the loop nest after |
| 321 | // transformations and we finsih porting the loop passes. |
| 322 | #if 0 |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 323 | // Rotate Loop - disable header duplication at -Oz |
| 324 | LPM1.addPass(LoopRotatePass(Level != Oz)); |
| 325 | LPM1.addPass(LICMPass()); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 326 | LPM1.addPass(LoopUnswitchPass(/* OptimizeForSize */ Level != O3)); |
| 327 | LPM2.addPass(IndVarSimplifyPass()); |
| 328 | LPM2.addPass(LoopIdiomPass()); |
| 329 | LPM2.addPass(LoopDeletionPass()); |
| 330 | LPM2.addPass(SimpleLoopUnrollPass()); |
| 331 | #endif |
| 332 | FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM1))); |
| 333 | FPM.addPass(SimplifyCFGPass()); |
| 334 | FPM.addPass(InstCombinePass()); |
| 335 | FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM2))); |
| 336 | |
| 337 | // Eliminate redundancies. |
| 338 | if (Level != O1) { |
| 339 | // These passes add substantial compile time so skip them at O1. |
| 340 | FPM.addPass(MergedLoadStoreMotionPass()); |
| 341 | FPM.addPass(GVN()); |
| 342 | } |
| 343 | |
| 344 | // Specially optimize memory movement as it doesn't look like dataflow in SSA. |
| 345 | FPM.addPass(MemCpyOptPass()); |
| 346 | |
| 347 | // Sparse conditional constant propagation. |
| 348 | // FIXME: It isn't clear why we do this *after* loop passes rather than |
| 349 | // before... |
| 350 | FPM.addPass(SCCPPass()); |
| 351 | |
| 352 | // Delete dead bit computations (instcombine runs after to fold away the dead |
| 353 | // computations, and then ADCE will run later to exploit any new DCE |
| 354 | // opportunities that creates). |
| 355 | FPM.addPass(BDCEPass()); |
| 356 | |
| 357 | // Run instcombine after redundancy and dead bit elimination to exploit |
| 358 | // opportunities opened up by them. |
| 359 | FPM.addPass(InstCombinePass()); |
| 360 | |
| 361 | // Re-consider control flow based optimizations after redundancy elimination, |
| 362 | // redo DCE, etc. |
| 363 | FPM.addPass(JumpThreadingPass()); |
| 364 | FPM.addPass(CorrelatedValuePropagationPass()); |
| 365 | FPM.addPass(DSEPass()); |
Chandler Carruth | 81c8eda | 2016-12-27 10:16:46 +0000 | [diff] [blame] | 366 | // FIXME: Enable this when the loop pass manager can support enforcing loop |
| 367 | // simplified and LCSSA form as well as updating the loop nest after |
| 368 | // transformations and we finsih porting the loop passes. |
| 369 | #if 0 |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 370 | FPM.addPass(createFunctionToLoopPassAdaptor(LICMPass())); |
Chandler Carruth | 81c8eda | 2016-12-27 10:16:46 +0000 | [diff] [blame] | 371 | #endif |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 372 | |
| 373 | // Finally, do an expensive DCE pass to catch all the dead code exposed by |
| 374 | // the simplifications and basic cleanup after all the simplifications. |
| 375 | FPM.addPass(ADCEPass()); |
| 376 | FPM.addPass(SimplifyCFGPass()); |
| 377 | FPM.addPass(InstCombinePass()); |
| 378 | |
| 379 | return FPM; |
| 380 | } |
| 381 | |
| 382 | ModulePassManager |
| 383 | PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level, |
| 384 | bool DebugLogging) { |
| 385 | assert(Level != O0 && "Must request optimizations for the default pipeline!"); |
| 386 | ModulePassManager MPM(DebugLogging); |
| 387 | |
| 388 | // Force any function attributes we want the rest of the pipeline te observe. |
| 389 | MPM.addPass(ForceFunctionAttrsPass()); |
| 390 | |
| 391 | // Do basic inference of function attributes from known properties of system |
| 392 | // libraries and other oracles. |
| 393 | MPM.addPass(InferFunctionAttrsPass()); |
| 394 | |
| 395 | // Create an early function pass manager to cleanup the output of the |
| 396 | // frontend. |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 397 | FunctionPassManager EarlyFPM(DebugLogging); |
| 398 | EarlyFPM.addPass(SimplifyCFGPass()); |
| 399 | EarlyFPM.addPass(SROA()); |
| 400 | EarlyFPM.addPass(EarlyCSEPass()); |
| 401 | EarlyFPM.addPass(LowerExpectIntrinsicPass()); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 402 | EarlyFPM.addPass(GVNHoistPass()); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 403 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM))); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 404 | |
| 405 | // Interprocedural constant propagation now that basic cleanup has occured |
| 406 | // and prior to optimizing globals. |
| 407 | // FIXME: This position in the pipeline hasn't been carefully considered in |
| 408 | // years, it should be re-analyzed. |
| 409 | MPM.addPass(IPSCCPPass()); |
| 410 | |
| 411 | // Optimize globals to try and fold them into constants. |
| 412 | MPM.addPass(GlobalOptPass()); |
| 413 | |
| 414 | // Promote any localized globals to SSA registers. |
| 415 | // FIXME: Should this instead by a run of SROA? |
| 416 | // FIXME: We should probably run instcombine and simplify-cfg afterward to |
| 417 | // delete control flows that are dead once globals have been folded to |
| 418 | // constants. |
| 419 | MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass())); |
| 420 | |
| 421 | // Remove any dead arguments exposed by cleanups and constand folding |
| 422 | // globals. |
| 423 | MPM.addPass(DeadArgumentEliminationPass()); |
| 424 | |
| 425 | // Create a small function pass pipeline to cleanup after all the global |
| 426 | // optimizations. |
| 427 | FunctionPassManager GlobalCleanupPM(DebugLogging); |
| 428 | GlobalCleanupPM.addPass(InstCombinePass()); |
| 429 | GlobalCleanupPM.addPass(SimplifyCFGPass()); |
| 430 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM))); |
| 431 | |
| 432 | // FIXME: Enable this when cross-IR-unit analysis invalidation is working. |
| 433 | #if 0 |
| 434 | MPM.addPass(RequireAnalysisPass<GlobalsAA>()); |
| 435 | #endif |
| 436 | |
| 437 | // Now begin the main postorder CGSCC pipeline. |
| 438 | // FIXME: The current CGSCC pipeline has its origins in the legacy pass |
| 439 | // manager and trying to emulate its precise behavior. Much of this doesn't |
| 440 | // make a lot of sense and we should revisit the core CGSCC structure. |
| 441 | CGSCCPassManager MainCGPipeline(DebugLogging); |
| 442 | |
| 443 | // Note: historically, the PruneEH pass was run first to deduce nounwind and |
| 444 | // generally clean up exception handling overhead. It isn't clear this is |
| 445 | // valuable as the inliner doesn't currently care whether it is inlining an |
| 446 | // invoke or a call. |
| 447 | |
| 448 | // Run the inliner first. The theory is that we are walking bottom-up and so |
| 449 | // the callees have already been fully optimized, and we want to inline them |
| 450 | // into the callers so that our optimizations can reflect that. |
| 451 | // FIXME; Customize the threshold based on optimization level. |
| 452 | MainCGPipeline.addPass(InlinerPass()); |
| 453 | |
| 454 | // Now deduce any function attributes based in the current code. |
| 455 | MainCGPipeline.addPass(PostOrderFunctionAttrsPass()); |
| 456 | |
| 457 | // Lastly, add the core function simplification pipeline nested inside the |
| 458 | // CGSCC walk. |
| 459 | MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor( |
| 460 | buildFunctionSimplificationPipeline(Level, DebugLogging))); |
| 461 | |
| 462 | MPM.addPass( |
| 463 | createModuleToPostOrderCGSCCPassAdaptor(std::move(MainCGPipeline))); |
| 464 | |
| 465 | // This ends the canonicalization and simplification phase of the pipeline. |
| 466 | // At this point, we expect to have canonical and simple IR which we begin |
| 467 | // *optimizing* for efficient execution going forward. |
| 468 | |
| 469 | // Eliminate externally available functions now that inlining is over -- we |
| 470 | // won't emit these anyways. |
| 471 | MPM.addPass(EliminateAvailableExternallyPass()); |
| 472 | |
| 473 | // Do RPO function attribute inference across the module to forward-propagate |
| 474 | // attributes where applicable. |
| 475 | // FIXME: Is this really an optimization rather than a canonicalization? |
| 476 | MPM.addPass(ReversePostOrderFunctionAttrsPass()); |
| 477 | |
| 478 | // Recompute GloblasAA here prior to function passes. This is particularly |
| 479 | // useful as the above will have inlined, DCE'ed, and function-attr |
| 480 | // propagated everything. We should at this point have a reasonably minimal |
| 481 | // and richly annotated call graph. By computing aliasing and mod/ref |
| 482 | // information for all local globals here, the late loop passes and notably |
| 483 | // the vectorizer will be able to use them to help recognize vectorizable |
| 484 | // memory operations. |
| 485 | // FIXME: Enable this once analysis invalidation is fully supported. |
| 486 | #if 0 |
| 487 | MPM.addPass(Require<GlobalsAA>()); |
| 488 | #endif |
| 489 | |
| 490 | FunctionPassManager OptimizePM(DebugLogging); |
| 491 | OptimizePM.addPass(Float2IntPass()); |
| 492 | // FIXME: We need to run some loop optimizations to re-rotate loops after |
| 493 | // simplify-cfg and others undo their rotation. |
| 494 | |
| 495 | // Optimize the loop execution. These passes operate on entire loop nests |
| 496 | // rather than on each loop in an inside-out manner, and so they are actually |
| 497 | // function passes. |
| 498 | OptimizePM.addPass(LoopDistributePass()); |
Chandler Carruth | e635289 | 2016-12-28 02:24:55 +0000 | [diff] [blame] | 499 | #if 0 |
| 500 | // FIXME: LoopVectorize relies on "requiring" LCSSA which isn't supported in |
| 501 | // the new PM. |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 502 | OptimizePM.addPass(LoopVectorizePass()); |
Chandler Carruth | e635289 | 2016-12-28 02:24:55 +0000 | [diff] [blame] | 503 | #endif |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 504 | // FIXME: Need to port Loop Load Elimination and add it here. |
| 505 | OptimizePM.addPass(InstCombinePass()); |
| 506 | |
| 507 | // Optimize parallel scalar instruction chains into SIMD instructions. |
| 508 | OptimizePM.addPass(SLPVectorizerPass()); |
| 509 | |
| 510 | // Cleanup after vectorizers. |
| 511 | OptimizePM.addPass(SimplifyCFGPass()); |
| 512 | OptimizePM.addPass(InstCombinePass()); |
| 513 | |
| 514 | // Unroll small loops to hide loop backedge latency and saturate any parallel |
| 515 | // execution resources of an out-of-order processor. |
| 516 | // FIXME: Need to add once loop pass pipeline is available. |
| 517 | |
| 518 | // FIXME: Add the loop sink pass when ported. |
| 519 | |
| 520 | // FIXME: Add cleanup from the loop pass manager when we're forming LCSSA |
| 521 | // here. |
| 522 | |
| 523 | // Now that we've vectorized and unrolled loops, we may have more refined |
| 524 | // alignment information, try to re-derive it here. |
| 525 | OptimizePM.addPass(AlignmentFromAssumptionsPass()); |
| 526 | |
| 527 | // ADd the core optimizing pipeline. |
| 528 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM))); |
| 529 | |
| 530 | // Now we need to do some global optimization transforms. |
| 531 | // FIXME: It would seem like these should come first in the optimization |
| 532 | // pipeline and maybe be the bottom of the canonicalization pipeline? Weird |
| 533 | // ordering here. |
| 534 | MPM.addPass(GlobalDCEPass()); |
| 535 | MPM.addPass(ConstantMergePass()); |
| 536 | |
| 537 | return MPM; |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 538 | } |
| 539 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 540 | ModulePassManager |
| 541 | PassBuilder::buildLTOPreLinkDefaultPipeline(OptimizationLevel Level, |
| 542 | bool DebugLogging) { |
| 543 | assert(Level != O0 && "Must request optimizations for the default pipeline!"); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 544 | // FIXME: We should use a customized pre-link pipeline! |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 545 | return buildPerModuleDefaultPipeline(Level, DebugLogging); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 548 | ModulePassManager PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level, |
| 549 | bool DebugLogging) { |
| 550 | assert(Level != O0 && "Must request optimizations for the default pipeline!"); |
| 551 | ModulePassManager MPM(DebugLogging); |
| 552 | |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 553 | // FIXME: Finish fleshing this out to match the legacy LTO pipelines. |
| 554 | FunctionPassManager LateFPM(DebugLogging); |
| 555 | LateFPM.addPass(InstCombinePass()); |
| 556 | LateFPM.addPass(SimplifyCFGPass()); |
| 557 | |
| 558 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(LateFPM))); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 559 | |
| 560 | return MPM; |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 561 | } |
| 562 | |
Chandler Carruth | 060ad61 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 563 | AAManager PassBuilder::buildDefaultAAPipeline() { |
| 564 | AAManager AA; |
| 565 | |
| 566 | // The order in which these are registered determines their priority when |
| 567 | // being queried. |
| 568 | |
| 569 | // First we register the basic alias analysis that provides the majority of |
| 570 | // per-function local AA logic. This is a stateless, on-demand local set of |
| 571 | // AA techniques. |
| 572 | AA.registerFunctionAnalysis<BasicAA>(); |
| 573 | |
| 574 | // Next we query fast, specialized alias analyses that wrap IR-embedded |
| 575 | // information about aliasing. |
| 576 | AA.registerFunctionAnalysis<ScopedNoAliasAA>(); |
| 577 | AA.registerFunctionAnalysis<TypeBasedAA>(); |
| 578 | |
| 579 | // Add support for querying global aliasing information when available. |
Chandler Carruth | 534d644 | 2016-12-24 05:11:17 +0000 | [diff] [blame] | 580 | // Because the `AAManager` is a function analysis and `GlobalsAA` is a module |
| 581 | // analysis, all that the `AAManager` can do is query for any *cached* |
| 582 | // results from `GlobalsAA` through a readonly proxy.. |
Chandler Carruth | 060ad61 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 583 | #if 0 |
Chandler Carruth | 534d644 | 2016-12-24 05:11:17 +0000 | [diff] [blame] | 584 | // FIXME: Enable once the invalidation logic supports this. Currently, the |
| 585 | // `AAManager` will hold stale references to the module analyses. |
Chandler Carruth | 060ad61 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 586 | AA.registerModuleAnalysis<GlobalsAA>(); |
| 587 | #endif |
| 588 | |
| 589 | return AA; |
| 590 | } |
| 591 | |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 592 | static Optional<int> parseRepeatPassName(StringRef Name) { |
| 593 | if (!Name.consume_front("repeat<") || !Name.consume_back(">")) |
| 594 | return None; |
| 595 | int Count; |
| 596 | if (Name.getAsInteger(0, Count) || Count <= 0) |
| 597 | return None; |
| 598 | return Count; |
| 599 | } |
| 600 | |
Chandler Carruth | 05ca5ac | 2016-12-28 11:07:33 +0000 | [diff] [blame] | 601 | static Optional<int> parseDevirtPassName(StringRef Name) { |
| 602 | if (!Name.consume_front("devirt<") || !Name.consume_back(">")) |
| 603 | return None; |
| 604 | int Count; |
| 605 | if (Name.getAsInteger(0, Count) || Count <= 0) |
| 606 | return None; |
| 607 | return Count; |
| 608 | } |
| 609 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 610 | static bool isModulePassName(StringRef Name) { |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 611 | // Manually handle aliases for pre-configured pipeline fragments. |
| 612 | if (Name.startswith("default") || Name.startswith("lto")) |
| 613 | return DefaultAliasRegex.match(Name); |
| 614 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 615 | // Explicitly handle pass manager names. |
| 616 | if (Name == "module") |
| 617 | return true; |
| 618 | if (Name == "cgscc") |
| 619 | return true; |
| 620 | if (Name == "function") |
| 621 | return true; |
| 622 | |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 623 | // Explicitly handle custom-parsed pass names. |
| 624 | if (parseRepeatPassName(Name)) |
| 625 | return true; |
| 626 | |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 627 | #define MODULE_PASS(NAME, CREATE_PASS) \ |
| 628 | if (Name == NAME) \ |
| 629 | return true; |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 630 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 631 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 632 | return true; |
| 633 | #include "PassRegistry.def" |
| 634 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 635 | return false; |
| 636 | } |
| 637 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 638 | static bool isCGSCCPassName(StringRef Name) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 639 | // Explicitly handle pass manager names. |
| 640 | if (Name == "cgscc") |
| 641 | return true; |
| 642 | if (Name == "function") |
| 643 | return true; |
| 644 | |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 645 | // Explicitly handle custom-parsed pass names. |
| 646 | if (parseRepeatPassName(Name)) |
| 647 | return true; |
Chandler Carruth | 05ca5ac | 2016-12-28 11:07:33 +0000 | [diff] [blame] | 648 | if (parseDevirtPassName(Name)) |
| 649 | return true; |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 650 | |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 651 | #define CGSCC_PASS(NAME, CREATE_PASS) \ |
| 652 | if (Name == NAME) \ |
| 653 | return true; |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 654 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 655 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 656 | return true; |
| 657 | #include "PassRegistry.def" |
| 658 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 659 | return false; |
| 660 | } |
| 661 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 662 | static bool isFunctionPassName(StringRef Name) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 663 | // Explicitly handle pass manager names. |
| 664 | if (Name == "function") |
| 665 | return true; |
| 666 | if (Name == "loop") |
| 667 | return true; |
| 668 | |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 669 | // Explicitly handle custom-parsed pass names. |
| 670 | if (parseRepeatPassName(Name)) |
| 671 | return true; |
| 672 | |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 673 | #define FUNCTION_PASS(NAME, CREATE_PASS) \ |
| 674 | if (Name == NAME) \ |
| 675 | return true; |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 676 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 677 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 678 | return true; |
| 679 | #include "PassRegistry.def" |
| 680 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 681 | return false; |
| 682 | } |
| 683 | |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 684 | static bool isLoopPassName(StringRef Name) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 685 | // Explicitly handle pass manager names. |
| 686 | if (Name == "loop") |
| 687 | return true; |
| 688 | |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 689 | // Explicitly handle custom-parsed pass names. |
| 690 | if (parseRepeatPassName(Name)) |
| 691 | return true; |
| 692 | |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 693 | #define LOOP_PASS(NAME, CREATE_PASS) \ |
| 694 | if (Name == NAME) \ |
| 695 | return true; |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 696 | #define LOOP_ANALYSIS(NAME, CREATE_PASS) \ |
| 697 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
| 698 | return true; |
| 699 | #include "PassRegistry.def" |
| 700 | |
| 701 | return false; |
| 702 | } |
| 703 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 704 | Optional<std::vector<PassBuilder::PipelineElement>> |
| 705 | PassBuilder::parsePipelineText(StringRef Text) { |
| 706 | std::vector<PipelineElement> ResultPipeline; |
| 707 | |
| 708 | SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = { |
| 709 | &ResultPipeline}; |
| 710 | for (;;) { |
| 711 | std::vector<PipelineElement> &Pipeline = *PipelineStack.back(); |
| 712 | size_t Pos = Text.find_first_of(",()"); |
| 713 | Pipeline.push_back({Text.substr(0, Pos), {}}); |
| 714 | |
| 715 | // If we have a single terminating name, we're done. |
| 716 | if (Pos == Text.npos) |
| 717 | break; |
| 718 | |
| 719 | char Sep = Text[Pos]; |
| 720 | Text = Text.substr(Pos + 1); |
| 721 | if (Sep == ',') |
| 722 | // Just a name ending in a comma, continue. |
| 723 | continue; |
| 724 | |
| 725 | if (Sep == '(') { |
| 726 | // Push the inner pipeline onto the stack to continue processing. |
| 727 | PipelineStack.push_back(&Pipeline.back().InnerPipeline); |
| 728 | continue; |
| 729 | } |
| 730 | |
| 731 | assert(Sep == ')' && "Bogus separator!"); |
| 732 | // When handling the close parenthesis, we greedily consume them to avoid |
| 733 | // empty strings in the pipeline. |
| 734 | do { |
| 735 | // If we try to pop the outer pipeline we have unbalanced parentheses. |
| 736 | if (PipelineStack.size() == 1) |
| 737 | return None; |
| 738 | |
| 739 | PipelineStack.pop_back(); |
| 740 | } while (Text.consume_front(")")); |
| 741 | |
| 742 | // Check if we've finished parsing. |
| 743 | if (Text.empty()) |
| 744 | break; |
| 745 | |
| 746 | // Otherwise, the end of an inner pipeline always has to be followed by |
| 747 | // a comma, and then we can continue. |
| 748 | if (!Text.consume_front(",")) |
| 749 | return None; |
| 750 | } |
| 751 | |
| 752 | if (PipelineStack.size() > 1) |
| 753 | // Unbalanced paretheses. |
| 754 | return None; |
| 755 | |
| 756 | assert(PipelineStack.back() == &ResultPipeline && |
| 757 | "Wrong pipeline at the bottom of the stack!"); |
| 758 | return {std::move(ResultPipeline)}; |
| 759 | } |
| 760 | |
| 761 | bool PassBuilder::parseModulePass(ModulePassManager &MPM, |
| 762 | const PipelineElement &E, bool VerifyEachPass, |
| 763 | bool DebugLogging) { |
| 764 | auto &Name = E.Name; |
| 765 | auto &InnerPipeline = E.InnerPipeline; |
| 766 | |
| 767 | // First handle complex passes like the pass managers which carry pipelines. |
| 768 | if (!InnerPipeline.empty()) { |
| 769 | if (Name == "module") { |
| 770 | ModulePassManager NestedMPM(DebugLogging); |
| 771 | if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass, |
| 772 | DebugLogging)) |
| 773 | return false; |
| 774 | MPM.addPass(std::move(NestedMPM)); |
| 775 | return true; |
| 776 | } |
| 777 | if (Name == "cgscc") { |
| 778 | CGSCCPassManager CGPM(DebugLogging); |
| 779 | if (!parseCGSCCPassPipeline(CGPM, InnerPipeline, VerifyEachPass, |
| 780 | DebugLogging)) |
| 781 | return false; |
| 782 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM), |
| 783 | DebugLogging)); |
| 784 | return true; |
| 785 | } |
| 786 | if (Name == "function") { |
| 787 | FunctionPassManager FPM(DebugLogging); |
| 788 | if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass, |
| 789 | DebugLogging)) |
| 790 | return false; |
| 791 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
| 792 | return true; |
| 793 | } |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 794 | if (auto Count = parseRepeatPassName(Name)) { |
| 795 | ModulePassManager NestedMPM(DebugLogging); |
| 796 | if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass, |
| 797 | DebugLogging)) |
| 798 | return false; |
Chandler Carruth | a053a88 | 2016-08-04 03:52:53 +0000 | [diff] [blame] | 799 | MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM))); |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 800 | return true; |
| 801 | } |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 802 | // Normal passes can't have pipelines. |
| 803 | return false; |
| 804 | } |
| 805 | |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 806 | // Manually handle aliases for pre-configured pipeline fragments. |
| 807 | if (Name.startswith("default") || Name.startswith("lto")) { |
| 808 | SmallVector<StringRef, 3> Matches; |
| 809 | if (!DefaultAliasRegex.match(Name, &Matches)) |
| 810 | return false; |
| 811 | assert(Matches.size() == 3 && "Must capture two matched strings!"); |
| 812 | |
Jordan Rose | f85a95f | 2016-07-25 18:34:51 +0000 | [diff] [blame] | 813 | OptimizationLevel L = StringSwitch<OptimizationLevel>(Matches[2]) |
| 814 | .Case("O0", O0) |
| 815 | .Case("O1", O1) |
| 816 | .Case("O2", O2) |
| 817 | .Case("O3", O3) |
| 818 | .Case("Os", Os) |
| 819 | .Case("Oz", Oz); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 820 | if (L == O0) |
| 821 | // At O0 we do nothing at all! |
| 822 | return true; |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 823 | |
| 824 | if (Matches[1] == "default") { |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 825 | MPM.addPass(buildPerModuleDefaultPipeline(L, DebugLogging)); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 826 | } else if (Matches[1] == "lto-pre-link") { |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 827 | MPM.addPass(buildLTOPreLinkDefaultPipeline(L, DebugLogging)); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 828 | } else { |
| 829 | assert(Matches[1] == "lto" && "Not one of the matched options!"); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 830 | MPM.addPass(buildLTODefaultPipeline(L, DebugLogging)); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 831 | } |
| 832 | return true; |
| 833 | } |
| 834 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 835 | // Finally expand the basic registered passes from the .inc file. |
Chandler Carruth | 5894418 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 836 | #define MODULE_PASS(NAME, CREATE_PASS) \ |
| 837 | if (Name == NAME) { \ |
| 838 | MPM.addPass(CREATE_PASS); \ |
| 839 | return true; \ |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 840 | } |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 841 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
| 842 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | 9b35e6d | 2016-08-19 18:36:06 +0000 | [diff] [blame] | 843 | MPM.addPass( \ |
| 844 | RequireAnalysisPass< \ |
| 845 | std::remove_reference<decltype(CREATE_PASS)>::type, Module>()); \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 846 | return true; \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 847 | } \ |
| 848 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 849 | MPM.addPass(InvalidateAnalysisPass< \ |
| 850 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 851 | return true; \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 852 | } |
| 853 | #include "PassRegistry.def" |
| 854 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 855 | return false; |
| 856 | } |
| 857 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 858 | bool PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM, |
| 859 | const PipelineElement &E, bool VerifyEachPass, |
| 860 | bool DebugLogging) { |
| 861 | auto &Name = E.Name; |
| 862 | auto &InnerPipeline = E.InnerPipeline; |
| 863 | |
| 864 | // First handle complex passes like the pass managers which carry pipelines. |
| 865 | if (!InnerPipeline.empty()) { |
| 866 | if (Name == "cgscc") { |
| 867 | CGSCCPassManager NestedCGPM(DebugLogging); |
| 868 | if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass, |
| 869 | DebugLogging)) |
| 870 | return false; |
| 871 | // Add the nested pass manager with the appropriate adaptor. |
| 872 | CGPM.addPass(std::move(NestedCGPM)); |
| 873 | return true; |
| 874 | } |
| 875 | if (Name == "function") { |
| 876 | FunctionPassManager FPM(DebugLogging); |
| 877 | if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass, |
| 878 | DebugLogging)) |
| 879 | return false; |
| 880 | // Add the nested pass manager with the appropriate adaptor. |
| 881 | CGPM.addPass( |
| 882 | createCGSCCToFunctionPassAdaptor(std::move(FPM), DebugLogging)); |
| 883 | return true; |
| 884 | } |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 885 | if (auto Count = parseRepeatPassName(Name)) { |
| 886 | CGSCCPassManager NestedCGPM(DebugLogging); |
| 887 | if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass, |
| 888 | DebugLogging)) |
| 889 | return false; |
Chandler Carruth | a053a88 | 2016-08-04 03:52:53 +0000 | [diff] [blame] | 890 | CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM))); |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 891 | return true; |
| 892 | } |
Chandler Carruth | 05ca5ac | 2016-12-28 11:07:33 +0000 | [diff] [blame] | 893 | if (auto MaxRepetitions = parseDevirtPassName(Name)) { |
| 894 | CGSCCPassManager NestedCGPM(DebugLogging); |
| 895 | if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass, |
| 896 | DebugLogging)) |
| 897 | return false; |
| 898 | CGPM.addPass(createDevirtSCCRepeatedPass(std::move(NestedCGPM), |
| 899 | *MaxRepetitions, DebugLogging)); |
| 900 | return true; |
| 901 | } |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 902 | // Normal passes can't have pipelines. |
| 903 | return false; |
| 904 | } |
| 905 | |
| 906 | // Now expand the basic registered passes from the .inc file. |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 907 | #define CGSCC_PASS(NAME, CREATE_PASS) \ |
| 908 | if (Name == NAME) { \ |
| 909 | CGPM.addPass(CREATE_PASS); \ |
| 910 | return true; \ |
| 911 | } |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 912 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
| 913 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 914 | CGPM.addPass(RequireAnalysisPass< \ |
Chandler Carruth | 9b35e6d | 2016-08-19 18:36:06 +0000 | [diff] [blame] | 915 | std::remove_reference<decltype(CREATE_PASS)>::type, \ |
Chandler Carruth | 8882346 | 2016-08-24 09:37:14 +0000 | [diff] [blame] | 916 | LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \ |
| 917 | CGSCCUpdateResult &>()); \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 918 | return true; \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 919 | } \ |
| 920 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 921 | CGPM.addPass(InvalidateAnalysisPass< \ |
| 922 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 923 | return true; \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 924 | } |
| 925 | #include "PassRegistry.def" |
| 926 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 927 | return false; |
| 928 | } |
| 929 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 930 | bool PassBuilder::parseFunctionPass(FunctionPassManager &FPM, |
| 931 | const PipelineElement &E, |
| 932 | bool VerifyEachPass, bool DebugLogging) { |
| 933 | auto &Name = E.Name; |
| 934 | auto &InnerPipeline = E.InnerPipeline; |
| 935 | |
| 936 | // First handle complex passes like the pass managers which carry pipelines. |
| 937 | if (!InnerPipeline.empty()) { |
| 938 | if (Name == "function") { |
| 939 | FunctionPassManager NestedFPM(DebugLogging); |
| 940 | if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass, |
| 941 | DebugLogging)) |
| 942 | return false; |
| 943 | // Add the nested pass manager with the appropriate adaptor. |
| 944 | FPM.addPass(std::move(NestedFPM)); |
| 945 | return true; |
| 946 | } |
| 947 | if (Name == "loop") { |
| 948 | LoopPassManager LPM(DebugLogging); |
| 949 | if (!parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass, |
| 950 | DebugLogging)) |
| 951 | return false; |
| 952 | // Add the nested pass manager with the appropriate adaptor. |
| 953 | FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM))); |
| 954 | return true; |
| 955 | } |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 956 | if (auto Count = parseRepeatPassName(Name)) { |
| 957 | FunctionPassManager NestedFPM(DebugLogging); |
| 958 | if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass, |
| 959 | DebugLogging)) |
| 960 | return false; |
Chandler Carruth | a053a88 | 2016-08-04 03:52:53 +0000 | [diff] [blame] | 961 | FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM))); |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 962 | return true; |
| 963 | } |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 964 | // Normal passes can't have pipelines. |
| 965 | return false; |
| 966 | } |
| 967 | |
| 968 | // Now expand the basic registered passes from the .inc file. |
Chandler Carruth | 5894418 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 969 | #define FUNCTION_PASS(NAME, CREATE_PASS) \ |
| 970 | if (Name == NAME) { \ |
| 971 | FPM.addPass(CREATE_PASS); \ |
| 972 | return true; \ |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 973 | } |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 974 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
| 975 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | 9b35e6d | 2016-08-19 18:36:06 +0000 | [diff] [blame] | 976 | FPM.addPass( \ |
| 977 | RequireAnalysisPass< \ |
| 978 | std::remove_reference<decltype(CREATE_PASS)>::type, Function>()); \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 979 | return true; \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 980 | } \ |
| 981 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 982 | FPM.addPass(InvalidateAnalysisPass< \ |
| 983 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 984 | return true; \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 985 | } |
| 986 | #include "PassRegistry.def" |
| 987 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 988 | return false; |
| 989 | } |
| 990 | |
Chandler Carruth | fdc6ba1 | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 991 | bool PassBuilder::parseLoopPass(LoopPassManager &LPM, const PipelineElement &E, |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 992 | bool VerifyEachPass, bool DebugLogging) { |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 993 | StringRef Name = E.Name; |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 994 | auto &InnerPipeline = E.InnerPipeline; |
| 995 | |
| 996 | // First handle complex passes like the pass managers which carry pipelines. |
| 997 | if (!InnerPipeline.empty()) { |
| 998 | if (Name == "loop") { |
| 999 | LoopPassManager NestedLPM(DebugLogging); |
| 1000 | if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass, |
| 1001 | DebugLogging)) |
| 1002 | return false; |
| 1003 | // Add the nested pass manager with the appropriate adaptor. |
Chandler Carruth | fdc6ba1 | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 1004 | LPM.addPass(std::move(NestedLPM)); |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1005 | return true; |
| 1006 | } |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1007 | if (auto Count = parseRepeatPassName(Name)) { |
| 1008 | LoopPassManager NestedLPM(DebugLogging); |
| 1009 | if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass, |
| 1010 | DebugLogging)) |
| 1011 | return false; |
Chandler Carruth | a053a88 | 2016-08-04 03:52:53 +0000 | [diff] [blame] | 1012 | LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM))); |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1013 | return true; |
| 1014 | } |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1015 | // Normal passes can't have pipelines. |
| 1016 | return false; |
| 1017 | } |
| 1018 | |
| 1019 | // Now expand the basic registered passes from the .inc file. |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1020 | #define LOOP_PASS(NAME, CREATE_PASS) \ |
| 1021 | if (Name == NAME) { \ |
Chandler Carruth | fdc6ba1 | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 1022 | LPM.addPass(CREATE_PASS); \ |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1023 | return true; \ |
| 1024 | } |
| 1025 | #define LOOP_ANALYSIS(NAME, CREATE_PASS) \ |
| 1026 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | fdc6ba1 | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 1027 | LPM.addPass(RequireAnalysisPass< \ |
Chandler Carruth | 410eaeb | 2017-01-11 06:23:21 +0000 | [diff] [blame] | 1028 | std::remove_reference<decltype(CREATE_PASS)>::type, Loop, \ |
| 1029 | LoopAnalysisManager, LoopStandardAnalysisResults &, \ |
| 1030 | LPMUpdater &>()); \ |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1031 | return true; \ |
| 1032 | } \ |
| 1033 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | fdc6ba1 | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 1034 | LPM.addPass(InvalidateAnalysisPass< \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 1035 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1036 | return true; \ |
| 1037 | } |
| 1038 | #include "PassRegistry.def" |
| 1039 | |
| 1040 | return false; |
| 1041 | } |
| 1042 | |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 1043 | bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) { |
Chandler Carruth | 45a9c20 | 2016-03-11 09:15:11 +0000 | [diff] [blame] | 1044 | #define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \ |
| 1045 | if (Name == NAME) { \ |
| 1046 | AA.registerModuleAnalysis< \ |
| 1047 | std::remove_reference<decltype(CREATE_PASS)>::type>(); \ |
| 1048 | return true; \ |
| 1049 | } |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 1050 | #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \ |
| 1051 | if (Name == NAME) { \ |
Chandler Carruth | 58dde8c | 2016-02-26 12:17:54 +0000 | [diff] [blame] | 1052 | AA.registerFunctionAnalysis< \ |
| 1053 | std::remove_reference<decltype(CREATE_PASS)>::type>(); \ |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 1054 | return true; \ |
| 1055 | } |
| 1056 | #include "PassRegistry.def" |
| 1057 | |
| 1058 | return false; |
| 1059 | } |
| 1060 | |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1061 | bool PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM, |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1062 | ArrayRef<PipelineElement> Pipeline, |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1063 | bool VerifyEachPass, |
| 1064 | bool DebugLogging) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1065 | for (const auto &Element : Pipeline) { |
| 1066 | if (!parseLoopPass(LPM, Element, VerifyEachPass, DebugLogging)) |
| 1067 | return false; |
| 1068 | // FIXME: No verifier support for Loop passes! |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1069 | } |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1070 | return true; |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 1073 | bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM, |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1074 | ArrayRef<PipelineElement> Pipeline, |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 1075 | bool VerifyEachPass, |
| 1076 | bool DebugLogging) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1077 | for (const auto &Element : Pipeline) { |
| 1078 | if (!parseFunctionPass(FPM, Element, VerifyEachPass, DebugLogging)) |
| 1079 | return false; |
| 1080 | if (VerifyEachPass) |
| 1081 | FPM.addPass(VerifierPass()); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 1082 | } |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1083 | return true; |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 1086 | bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM, |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1087 | ArrayRef<PipelineElement> Pipeline, |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 1088 | bool VerifyEachPass, |
| 1089 | bool DebugLogging) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1090 | for (const auto &Element : Pipeline) { |
| 1091 | if (!parseCGSCCPass(CGPM, Element, VerifyEachPass, DebugLogging)) |
| 1092 | return false; |
| 1093 | // FIXME: No verifier support for CGSCC passes! |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1094 | } |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1095 | return true; |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
NAKAMURA Takumi | a42f528 | 2016-05-16 10:13:37 +0000 | [diff] [blame] | 1098 | void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM, |
| 1099 | FunctionAnalysisManager &FAM, |
| 1100 | CGSCCAnalysisManager &CGAM, |
| 1101 | ModuleAnalysisManager &MAM) { |
| 1102 | MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); }); |
| 1103 | MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); }); |
NAKAMURA Takumi | a42f528 | 2016-05-16 10:13:37 +0000 | [diff] [blame] | 1104 | CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); }); |
| 1105 | FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); }); |
| 1106 | FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); }); |
| 1107 | FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); }); |
| 1108 | LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); }); |
| 1109 | } |
| 1110 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 1111 | bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM, |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1112 | ArrayRef<PipelineElement> Pipeline, |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 1113 | bool VerifyEachPass, |
| 1114 | bool DebugLogging) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1115 | for (const auto &Element : Pipeline) { |
| 1116 | if (!parseModulePass(MPM, Element, VerifyEachPass, DebugLogging)) |
| 1117 | return false; |
| 1118 | if (VerifyEachPass) |
| 1119 | MPM.addPass(VerifierPass()); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1120 | } |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1121 | return true; |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | // Primary pass pipeline description parsing routine. |
| 1125 | // FIXME: Should this routine accept a TargetMachine or require the caller to |
| 1126 | // pre-populate the analysis managers with target-specific stuff? |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 1127 | bool PassBuilder::parsePassPipeline(ModulePassManager &MPM, |
| 1128 | StringRef PipelineText, bool VerifyEachPass, |
| 1129 | bool DebugLogging) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1130 | auto Pipeline = parsePipelineText(PipelineText); |
| 1131 | if (!Pipeline || Pipeline->empty()) |
| 1132 | return false; |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1133 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1134 | // If the first name isn't at the module layer, wrap the pipeline up |
| 1135 | // automatically. |
| 1136 | StringRef FirstName = Pipeline->front().Name; |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1137 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1138 | if (!isModulePassName(FirstName)) { |
| 1139 | if (isCGSCCPassName(FirstName)) |
| 1140 | Pipeline = {{"cgscc", std::move(*Pipeline)}}; |
| 1141 | else if (isFunctionPassName(FirstName)) |
| 1142 | Pipeline = {{"function", std::move(*Pipeline)}}; |
| 1143 | else if (isLoopPassName(FirstName)) |
| 1144 | Pipeline = {{"function", {{"loop", std::move(*Pipeline)}}}}; |
| 1145 | else |
| 1146 | // Unknown pass name! |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1147 | return false; |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1150 | return parseModulePassPipeline(MPM, *Pipeline, VerifyEachPass, DebugLogging); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1151 | } |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 1152 | |
| 1153 | bool PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) { |
Chandler Carruth | 060ad61 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 1154 | // If the pipeline just consists of the word 'default' just replace the AA |
| 1155 | // manager with our default one. |
| 1156 | if (PipelineText == "default") { |
| 1157 | AA = buildDefaultAAPipeline(); |
| 1158 | return true; |
| 1159 | } |
| 1160 | |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 1161 | while (!PipelineText.empty()) { |
| 1162 | StringRef Name; |
| 1163 | std::tie(Name, PipelineText) = PipelineText.split(','); |
| 1164 | if (!parseAAPassName(AA, Name)) |
| 1165 | return false; |
| 1166 | } |
| 1167 | |
| 1168 | return true; |
| 1169 | } |