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" |
Daniel Berlin | 554dcd8 | 2017-04-11 20:06:36 +0000 | [diff] [blame] | 42 | #include "llvm/Analysis/MemorySSA.h" |
Teresa Johnson | f93b246 | 2016-08-12 13:53:02 +0000 | [diff] [blame] | 43 | #include "llvm/Analysis/ModuleSummaryAnalysis.h" |
Adam Nemet | 79ac42a | 2016-07-18 16:29:21 +0000 | [diff] [blame] | 44 | #include "llvm/Analysis/OptimizationDiagnosticInfo.h" |
Hongbin Zheng | 3f97840 | 2016-02-25 17:54:07 +0000 | [diff] [blame] | 45 | #include "llvm/Analysis/PostDominators.h" |
Easwaran Raman | 019e0bf | 2016-06-03 22:54:26 +0000 | [diff] [blame] | 46 | #include "llvm/Analysis/ProfileSummaryInfo.h" |
Hongbin Zheng | bc53977 | 2016-02-25 17:54:25 +0000 | [diff] [blame] | 47 | #include "llvm/Analysis/RegionInfo.h" |
Chandler Carruth | 2f1fd16 | 2015-08-17 02:08:17 +0000 | [diff] [blame] | 48 | #include "llvm/Analysis/ScalarEvolution.h" |
Chandler Carruth | 2b3d044 | 2016-02-20 04:01:45 +0000 | [diff] [blame] | 49 | #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" |
Chandler Carruth | d6091a0 | 2016-02-20 04:03:06 +0000 | [diff] [blame] | 50 | #include "llvm/Analysis/ScopedNoAliasAA.h" |
Chandler Carruth | 8ca4322 | 2015-01-15 11:39:46 +0000 | [diff] [blame] | 51 | #include "llvm/Analysis/TargetLibraryInfo.h" |
Chandler Carruth | e038552 | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 52 | #include "llvm/Analysis/TargetTransformInfo.h" |
Chandler Carruth | c1dc384 | 2016-02-20 04:04:52 +0000 | [diff] [blame] | 53 | #include "llvm/Analysis/TypeBasedAliasAnalysis.h" |
Michael Kuperstein | 82d5da5 | 2016-06-24 20:13:42 +0000 | [diff] [blame] | 54 | #include "llvm/CodeGen/PreISelIntrinsicLowering.h" |
Wei Mi | 90d195a | 2016-07-08 03:32:49 +0000 | [diff] [blame] | 55 | #include "llvm/CodeGen/UnreachableBlockElim.h" |
Chandler Carruth | 64764b4 | 2015-01-14 10:19:28 +0000 | [diff] [blame] | 56 | #include "llvm/IR/Dominators.h" |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 57 | #include "llvm/IR/IRPrintingPasses.h" |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 58 | #include "llvm/IR/PassManager.h" |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 59 | #include "llvm/IR/Verifier.h" |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 60 | #include "llvm/Support/Debug.h" |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 61 | #include "llvm/Support/Regex.h" |
Chandler Carruth | e038552 | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 62 | #include "llvm/Target/TargetMachine.h" |
Xinliang David Li | 64dbb29 | 2016-06-05 05:12:23 +0000 | [diff] [blame] | 63 | #include "llvm/Transforms/GCOVProfiler.h" |
Chandler Carruth | 67fc52f | 2016-08-17 02:56:20 +0000 | [diff] [blame] | 64 | #include "llvm/Transforms/IPO/AlwaysInliner.h" |
Chandler Carruth | addcda4 | 2017-02-09 23:46:27 +0000 | [diff] [blame] | 65 | #include "llvm/Transforms/IPO/ArgumentPromotion.h" |
Davide Italiano | 164b9bc | 2016-05-05 00:51:09 +0000 | [diff] [blame] | 66 | #include "llvm/Transforms/IPO/ConstantMerge.h" |
Davide Italiano | 92b933a | 2016-07-09 03:25:35 +0000 | [diff] [blame] | 67 | #include "llvm/Transforms/IPO/CrossDSOCFI.h" |
Sean Silva | e3bb457 | 2016-06-12 09:16:39 +0000 | [diff] [blame] | 68 | #include "llvm/Transforms/IPO/DeadArgumentElimination.h" |
Davide Italiano | 344e838 | 2016-05-05 02:37:32 +0000 | [diff] [blame] | 69 | #include "llvm/Transforms/IPO/ElimAvailExtern.h" |
Chandler Carruth | f49f1a87 | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 70 | #include "llvm/Transforms/IPO/ForceFunctionAttrs.h" |
Chandler Carruth | 9c4ed17 | 2016-02-18 11:03:11 +0000 | [diff] [blame] | 71 | #include "llvm/Transforms/IPO/FunctionAttrs.h" |
Teresa Johnson | 2124157 | 2016-07-18 21:22:24 +0000 | [diff] [blame] | 72 | #include "llvm/Transforms/IPO/FunctionImport.h" |
Davide Italiano | 66228c4 | 2016-05-03 19:39:15 +0000 | [diff] [blame] | 73 | #include "llvm/Transforms/IPO/GlobalDCE.h" |
Justin Bogner | 1a07501 | 2016-04-26 00:28:01 +0000 | [diff] [blame] | 74 | #include "llvm/Transforms/IPO/GlobalOpt.h" |
Davide Italiano | 2ae76dd | 2016-11-21 00:28:23 +0000 | [diff] [blame] | 75 | #include "llvm/Transforms/IPO/GlobalSplit.h" |
Chandler Carruth | 3a040e6 | 2015-12-27 08:41:34 +0000 | [diff] [blame] | 76 | #include "llvm/Transforms/IPO/InferFunctionAttrs.h" |
Chandler Carruth | 1d96311 | 2016-12-20 03:15:32 +0000 | [diff] [blame] | 77 | #include "llvm/Transforms/IPO/Inliner.h" |
Justin Bogner | 4563a06 | 2016-04-26 20:15:52 +0000 | [diff] [blame] | 78 | #include "llvm/Transforms/IPO/Internalize.h" |
Davide Italiano | e8ae0b5 | 2016-07-11 18:10:06 +0000 | [diff] [blame] | 79 | #include "llvm/Transforms/IPO/LowerTypeTests.h" |
Easwaran Raman | 1832bf6 | 2016-06-27 16:50:18 +0000 | [diff] [blame] | 80 | #include "llvm/Transforms/IPO/PartialInlining.h" |
Davide Italiano | f54f2f0 | 2016-05-05 21:05:36 +0000 | [diff] [blame] | 81 | #include "llvm/Transforms/IPO/SCCP.h" |
Justin Bogner | 21e1537 | 2015-10-30 23:28:12 +0000 | [diff] [blame] | 82 | #include "llvm/Transforms/IPO/StripDeadPrototypes.h" |
Davide Italiano | d737dd2 | 2016-06-14 21:44:19 +0000 | [diff] [blame] | 83 | #include "llvm/Transforms/IPO/WholeProgramDevirt.h" |
Chandler Carruth | f49f1a87 | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 84 | #include "llvm/Transforms/InstCombine/InstCombine.h" |
Xinliang David Li | e6b8929 | 2016-04-18 17:47:38 +0000 | [diff] [blame] | 85 | #include "llvm/Transforms/InstrProfiling.h" |
Xinliang David Li | 8aebf44 | 2016-05-06 05:49:19 +0000 | [diff] [blame] | 86 | #include "llvm/Transforms/PGOInstrumentation.h" |
Xinliang David Li | d38392e | 2016-05-27 23:20:16 +0000 | [diff] [blame] | 87 | #include "llvm/Transforms/SampleProfile.h" |
Justin Bogner | 19b6799 | 2015-10-30 23:13:18 +0000 | [diff] [blame] | 88 | #include "llvm/Transforms/Scalar/ADCE.h" |
Sean Silva | a4c2d15 | 2016-06-15 06:18:01 +0000 | [diff] [blame] | 89 | #include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h" |
Davide Italiano | 655a145 | 2016-05-25 01:57:04 +0000 | [diff] [blame] | 90 | #include "llvm/Transforms/Scalar/BDCE.h" |
Adam Nemet | 3beef41 | 2016-07-18 16:29:17 +0000 | [diff] [blame] | 91 | #include "llvm/Transforms/Scalar/ConstantHoisting.h" |
Sean Silva | b025d37 | 2016-07-06 23:26:29 +0000 | [diff] [blame] | 92 | #include "llvm/Transforms/Scalar/CorrelatedValuePropagation.h" |
Justin Bogner | 395c212 | 2016-04-22 19:40:41 +0000 | [diff] [blame] | 93 | #include "llvm/Transforms/Scalar/DCE.h" |
Justin Bogner | 594e07b | 2016-05-17 21:38:13 +0000 | [diff] [blame] | 94 | #include "llvm/Transforms/Scalar/DeadStoreElimination.h" |
Chandler Carruth | e8c686a | 2015-02-01 10:51:23 +0000 | [diff] [blame] | 95 | #include "llvm/Transforms/Scalar/EarlyCSE.h" |
Michael Kuperstein | 83b753d | 2016-06-24 23:32:02 +0000 | [diff] [blame] | 96 | #include "llvm/Transforms/Scalar/Float2Int.h" |
Easwaran Raman | 019e0bf | 2016-06-03 22:54:26 +0000 | [diff] [blame] | 97 | #include "llvm/Transforms/Scalar/GVN.h" |
Davide Italiano | 89ab89d | 2016-06-14 00:49:23 +0000 | [diff] [blame] | 98 | #include "llvm/Transforms/Scalar/GuardWidening.h" |
Chandler Carruth | 3bab7e1 | 2017-01-11 09:43:56 +0000 | [diff] [blame] | 99 | #include "llvm/Transforms/Scalar/IVUsersPrinter.h" |
Sanjoy Das | 4d4339d | 2016-06-05 18:01:19 +0000 | [diff] [blame] | 100 | #include "llvm/Transforms/Scalar/IndVarSimplify.h" |
Sean Silva | 46590d5 | 2016-06-14 00:51:09 +0000 | [diff] [blame] | 101 | #include "llvm/Transforms/Scalar/JumpThreading.h" |
Dehao Chen | f400a09 | 2016-07-12 22:42:24 +0000 | [diff] [blame] | 102 | #include "llvm/Transforms/Scalar/LICM.h" |
Chandler Carruth | 3bab7e1 | 2017-01-11 09:43:56 +0000 | [diff] [blame] | 103 | #include "llvm/Transforms/Scalar/LoopAccessAnalysisPrinter.h" |
Teresa Johnson | 1eca6bc | 2016-08-13 04:11:27 +0000 | [diff] [blame] | 104 | #include "llvm/Transforms/Scalar/LoopDataPrefetch.h" |
Jun Bum Lim | c837af3 | 2016-07-14 18:28:29 +0000 | [diff] [blame] | 105 | #include "llvm/Transforms/Scalar/LoopDeletion.h" |
Adam Nemet | b2593f7 | 2016-07-18 16:29:27 +0000 | [diff] [blame] | 106 | #include "llvm/Transforms/Scalar/LoopDistribute.h" |
Dehao Chen | b9f8e29 | 2016-07-12 18:45:51 +0000 | [diff] [blame] | 107 | #include "llvm/Transforms/Scalar/LoopIdiomRecognize.h" |
Dehao Chen | dcafd5e | 2016-07-15 16:42:11 +0000 | [diff] [blame] | 108 | #include "llvm/Transforms/Scalar/LoopInstSimplify.h" |
Chandler Carruth | baabda9 | 2017-01-27 01:32:26 +0000 | [diff] [blame] | 109 | #include "llvm/Transforms/Scalar/LoopLoadElimination.h" |
Chandler Carruth | 3bab7e1 | 2017-01-11 09:43:56 +0000 | [diff] [blame] | 110 | #include "llvm/Transforms/Scalar/LoopPassManager.h" |
Artur Pilipenko | 8fb3d57 | 2017-01-25 16:00:44 +0000 | [diff] [blame] | 111 | #include "llvm/Transforms/Scalar/LoopPredication.h" |
Justin Bogner | d0d2341 | 2016-05-03 22:02:31 +0000 | [diff] [blame] | 112 | #include "llvm/Transforms/Scalar/LoopRotation.h" |
Justin Bogner | ab6a513 | 2016-05-03 21:47:32 +0000 | [diff] [blame] | 113 | #include "llvm/Transforms/Scalar/LoopSimplifyCFG.h" |
Chandler Carruth | e9b18e3 | 2017-01-20 08:42:19 +0000 | [diff] [blame] | 114 | #include "llvm/Transforms/Scalar/LoopSink.h" |
Dehao Chen | 6132ee8 | 2016-07-18 21:41:50 +0000 | [diff] [blame] | 115 | #include "llvm/Transforms/Scalar/LoopStrengthReduce.h" |
Sean Silva | e3c18a5 | 2016-07-19 23:54:23 +0000 | [diff] [blame] | 116 | #include "llvm/Transforms/Scalar/LoopUnrollPass.h" |
Davide Italiano | 9922344 | 2016-05-13 22:52:35 +0000 | [diff] [blame] | 117 | #include "llvm/Transforms/Scalar/LowerAtomic.h" |
Chandler Carruth | 43e590e | 2015-01-24 11:13:02 +0000 | [diff] [blame] | 118 | #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h" |
Michael Kuperstein | e45d4d9 | 2016-07-28 22:08:41 +0000 | [diff] [blame] | 119 | #include "llvm/Transforms/Scalar/LowerGuardIntrinsic.h" |
Sean Silva | 6347df0 | 2016-06-14 02:44:55 +0000 | [diff] [blame] | 120 | #include "llvm/Transforms/Scalar/MemCpyOptimizer.h" |
Davide Italiano | b49aa5c | 2016-06-17 19:10:09 +0000 | [diff] [blame] | 121 | #include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h" |
Wei Mi | 1cf58f8 | 2016-07-21 22:28:52 +0000 | [diff] [blame] | 122 | #include "llvm/Transforms/Scalar/NaryReassociate.h" |
Davide Italiano | e05e330 | 2016-12-22 16:35:02 +0000 | [diff] [blame] | 123 | #include "llvm/Transforms/Scalar/NewGVN.h" |
Davide Italiano | 1021c68 | 2016-05-25 23:38:53 +0000 | [diff] [blame] | 124 | #include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h" |
Justin Bogner | c2bf63d | 2016-04-26 23:39:29 +0000 | [diff] [blame] | 125 | #include "llvm/Transforms/Scalar/Reassociate.h" |
Davide Italiano | 98f7e0e | 2016-05-18 15:18:25 +0000 | [diff] [blame] | 126 | #include "llvm/Transforms/Scalar/SCCP.h" |
Chandler Carruth | 29a18a4 | 2015-09-12 09:09:14 +0000 | [diff] [blame] | 127 | #include "llvm/Transforms/Scalar/SROA.h" |
Chandler Carruth | 1353f9a | 2017-04-27 18:45:20 +0000 | [diff] [blame] | 128 | #include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h" |
Chandler Carruth | f49f1a87 | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 129 | #include "llvm/Transforms/Scalar/SimplifyCFG.h" |
Justin Bogner | b939490 | 2016-04-22 19:54:10 +0000 | [diff] [blame] | 130 | #include "llvm/Transforms/Scalar/Sink.h" |
Michael Kuperstein | c406186 | 2016-08-01 21:48:33 +0000 | [diff] [blame] | 131 | #include "llvm/Transforms/Scalar/SpeculativeExecution.h" |
Sean Silva | 59fe82f | 2016-07-06 23:48:41 +0000 | [diff] [blame] | 132 | #include "llvm/Transforms/Scalar/TailRecursionElimination.h" |
Xinliang David Li | 1eaecef | 2016-06-15 21:51:30 +0000 | [diff] [blame] | 133 | #include "llvm/Transforms/Utils/AddDiscriminators.h" |
Wei Mi | e04d0ef | 2016-07-22 18:04:25 +0000 | [diff] [blame] | 134 | #include "llvm/Transforms/Utils/BreakCriticalEdges.h" |
Easwaran Raman | e12c487 | 2016-06-09 19:44:46 +0000 | [diff] [blame] | 135 | #include "llvm/Transforms/Utils/LCSSA.h" |
Rong Xu | 1c0e9b9 | 2016-10-18 21:36:27 +0000 | [diff] [blame] | 136 | #include "llvm/Transforms/Utils/LibCallsShrinkWrap.h" |
Davide Italiano | cd96cfd | 2016-07-09 03:03:01 +0000 | [diff] [blame] | 137 | #include "llvm/Transforms/Utils/LoopSimplify.h" |
Michael Kuperstein | 31b8399 | 2016-08-12 17:28:27 +0000 | [diff] [blame] | 138 | #include "llvm/Transforms/Utils/LowerInvoke.h" |
Davide Italiano | cccf4f0 | 2016-06-14 03:22:22 +0000 | [diff] [blame] | 139 | #include "llvm/Transforms/Utils/Mem2Reg.h" |
Mehdi Amini | 27d2379 | 2016-09-16 16:56:30 +0000 | [diff] [blame] | 140 | #include "llvm/Transforms/Utils/NameAnonGlobals.h" |
Daniel Berlin | 439042b | 2017-02-07 21:10:46 +0000 | [diff] [blame] | 141 | #include "llvm/Transforms/Utils/PredicateInfo.h" |
Davide Italiano | 16284df | 2016-07-07 21:14:36 +0000 | [diff] [blame] | 142 | #include "llvm/Transforms/Utils/SimplifyInstructions.h" |
Michael Kuperstein | 39feb62 | 2016-07-25 20:52:00 +0000 | [diff] [blame] | 143 | #include "llvm/Transforms/Utils/SymbolRewriter.h" |
Sean Silva | db90d4d | 2016-07-09 22:56:50 +0000 | [diff] [blame] | 144 | #include "llvm/Transforms/Vectorize/LoopVectorize.h" |
Sean Silva | 0dacbd8 | 2016-07-09 03:11:29 +0000 | [diff] [blame] | 145 | #include "llvm/Transforms/Vectorize/SLPVectorizer.h" |
Davide Italiano | cccf4f0 | 2016-06-14 03:22:22 +0000 | [diff] [blame] | 146 | |
Chandler Carruth | 58dde8c | 2016-02-26 12:17:54 +0000 | [diff] [blame] | 147 | #include <type_traits> |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 148 | |
| 149 | using namespace llvm; |
| 150 | |
Chandler Carruth | 719ffe1 | 2017-02-12 05:38:04 +0000 | [diff] [blame] | 151 | static cl::opt<unsigned> MaxDevirtIterations("pm-max-devirt-iterations", |
| 152 | cl::ReallyHidden, cl::init(4)); |
| 153 | |
Chandler Carruth | c246a4c | 2017-04-27 00:28:03 +0000 | [diff] [blame] | 154 | static cl::opt<bool> EnableGVNHoist( |
| 155 | "enable-npm-gvn-hoist", cl::init(false), cl::Hidden, |
| 156 | cl::desc("Enable the GVN hoisting pass for the new PM (default = off)")); |
| 157 | |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 158 | static Regex DefaultAliasRegex("^(default|lto-pre-link|lto)<(O[0123sz])>$"); |
| 159 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 160 | static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level) { |
| 161 | switch (Level) { |
| 162 | case PassBuilder::O0: |
| 163 | case PassBuilder::O1: |
| 164 | case PassBuilder::O2: |
| 165 | case PassBuilder::O3: |
| 166 | return false; |
| 167 | |
| 168 | case PassBuilder::Os: |
| 169 | case PassBuilder::Oz: |
| 170 | return true; |
| 171 | } |
| 172 | llvm_unreachable("Invalid optimization level!"); |
| 173 | } |
| 174 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 175 | namespace { |
| 176 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 177 | /// \brief No-op module pass which does nothing. |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 178 | struct NoOpModulePass { |
Sean Silva | fd03ac6 | 2016-08-09 00:28:38 +0000 | [diff] [blame] | 179 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &) { |
Chandler Carruth | 164a2aa6 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 180 | return PreservedAnalyses::all(); |
| 181 | } |
Chandler Carruth | a13f27c | 2014-01-11 11:52:05 +0000 | [diff] [blame] | 182 | static StringRef name() { return "NoOpModulePass"; } |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 183 | }; |
| 184 | |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 185 | /// \brief No-op module analysis. |
Chandler Carruth | 30a0730 | 2016-03-11 10:33:22 +0000 | [diff] [blame] | 186 | class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> { |
| 187 | friend AnalysisInfoMixin<NoOpModuleAnalysis>; |
Chandler Carruth | dab4eae | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 188 | static AnalysisKey Key; |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 189 | |
| 190 | public: |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 191 | struct Result {}; |
Sean Silva | fd03ac6 | 2016-08-09 00:28:38 +0000 | [diff] [blame] | 192 | Result run(Module &, ModuleAnalysisManager &) { return Result(); } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 193 | static StringRef name() { return "NoOpModuleAnalysis"; } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 194 | }; |
| 195 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 196 | /// \brief No-op CGSCC pass which does nothing. |
| 197 | struct NoOpCGSCCPass { |
Chandler Carruth | 8882346 | 2016-08-24 09:37:14 +0000 | [diff] [blame] | 198 | PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &, |
| 199 | LazyCallGraph &, CGSCCUpdateResult &UR) { |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 200 | return PreservedAnalyses::all(); |
| 201 | } |
| 202 | static StringRef name() { return "NoOpCGSCCPass"; } |
| 203 | }; |
| 204 | |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 205 | /// \brief No-op CGSCC analysis. |
Chandler Carruth | 30a0730 | 2016-03-11 10:33:22 +0000 | [diff] [blame] | 206 | class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> { |
| 207 | friend AnalysisInfoMixin<NoOpCGSCCAnalysis>; |
Chandler Carruth | dab4eae | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 208 | static AnalysisKey Key; |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 209 | |
| 210 | public: |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 211 | struct Result {}; |
Chandler Carruth | 8882346 | 2016-08-24 09:37:14 +0000 | [diff] [blame] | 212 | Result run(LazyCallGraph::SCC &, CGSCCAnalysisManager &, LazyCallGraph &G) { |
Chandler Carruth | 164a2aa6 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 213 | return Result(); |
| 214 | } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 215 | static StringRef name() { return "NoOpCGSCCAnalysis"; } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 216 | }; |
| 217 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 218 | /// \brief No-op function pass which does nothing. |
| 219 | struct NoOpFunctionPass { |
Sean Silva | 36e0d01 | 2016-08-09 00:28:15 +0000 | [diff] [blame] | 220 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &) { |
Chandler Carruth | 164a2aa6 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 221 | return PreservedAnalyses::all(); |
| 222 | } |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 223 | static StringRef name() { return "NoOpFunctionPass"; } |
| 224 | }; |
| 225 | |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 226 | /// \brief No-op function analysis. |
Chandler Carruth | 30a0730 | 2016-03-11 10:33:22 +0000 | [diff] [blame] | 227 | class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> { |
| 228 | friend AnalysisInfoMixin<NoOpFunctionAnalysis>; |
Chandler Carruth | dab4eae | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 229 | static AnalysisKey Key; |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 230 | |
| 231 | public: |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 232 | struct Result {}; |
Sean Silva | 36e0d01 | 2016-08-09 00:28:15 +0000 | [diff] [blame] | 233 | Result run(Function &, FunctionAnalysisManager &) { return Result(); } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 234 | static StringRef name() { return "NoOpFunctionAnalysis"; } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 235 | }; |
| 236 | |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 237 | /// \brief No-op loop pass which does nothing. |
| 238 | struct NoOpLoopPass { |
Chandler Carruth | 410eaeb | 2017-01-11 06:23:21 +0000 | [diff] [blame] | 239 | PreservedAnalyses run(Loop &L, LoopAnalysisManager &, |
| 240 | LoopStandardAnalysisResults &, LPMUpdater &) { |
Chandler Carruth | 164a2aa6 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 241 | return PreservedAnalyses::all(); |
| 242 | } |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 243 | static StringRef name() { return "NoOpLoopPass"; } |
| 244 | }; |
| 245 | |
| 246 | /// \brief No-op loop analysis. |
Chandler Carruth | 30a0730 | 2016-03-11 10:33:22 +0000 | [diff] [blame] | 247 | class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> { |
| 248 | friend AnalysisInfoMixin<NoOpLoopAnalysis>; |
Chandler Carruth | dab4eae | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 249 | static AnalysisKey Key; |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 250 | |
| 251 | public: |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 252 | struct Result {}; |
Chandler Carruth | 410eaeb | 2017-01-11 06:23:21 +0000 | [diff] [blame] | 253 | Result run(Loop &, LoopAnalysisManager &, LoopStandardAnalysisResults &) { |
| 254 | return Result(); |
| 255 | } |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 256 | static StringRef name() { return "NoOpLoopAnalysis"; } |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 257 | }; |
| 258 | |
Chandler Carruth | dab4eae | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 259 | AnalysisKey NoOpModuleAnalysis::Key; |
| 260 | AnalysisKey NoOpCGSCCAnalysis::Key; |
| 261 | AnalysisKey NoOpFunctionAnalysis::Key; |
| 262 | AnalysisKey NoOpLoopAnalysis::Key; |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 263 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 264 | } // End anonymous namespace. |
| 265 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 266 | void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) { |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 267 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 268 | MAM.registerPass([&] { return CREATE_PASS; }); |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 269 | #include "PassRegistry.def" |
| 270 | } |
| 271 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 272 | void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) { |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 273 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 274 | CGAM.registerPass([&] { return CREATE_PASS; }); |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 275 | #include "PassRegistry.def" |
| 276 | } |
| 277 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 278 | void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) { |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 279 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 280 | FAM.registerPass([&] { return CREATE_PASS; }); |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 281 | #include "PassRegistry.def" |
| 282 | } |
| 283 | |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 284 | void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) { |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 285 | #define LOOP_ANALYSIS(NAME, CREATE_PASS) \ |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 286 | LAM.registerPass([&] { return CREATE_PASS; }); |
| 287 | #include "PassRegistry.def" |
| 288 | } |
| 289 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 290 | FunctionPassManager |
| 291 | PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level, |
| 292 | bool DebugLogging) { |
| 293 | assert(Level != O0 && "Must request optimizations!"); |
| 294 | FunctionPassManager FPM(DebugLogging); |
| 295 | |
| 296 | // Form SSA out of local memory accesses after breaking apart aggregates into |
| 297 | // scalars. |
| 298 | FPM.addPass(SROA()); |
| 299 | |
| 300 | // Catch trivial redundancies |
| 301 | FPM.addPass(EarlyCSEPass()); |
| 302 | |
| 303 | // Speculative execution if the target has divergent branches; otherwise nop. |
| 304 | FPM.addPass(SpeculativeExecutionPass()); |
| 305 | |
| 306 | // Optimize based on known information about branches, and cleanup afterward. |
| 307 | FPM.addPass(JumpThreadingPass()); |
| 308 | FPM.addPass(CorrelatedValuePropagationPass()); |
| 309 | FPM.addPass(SimplifyCFGPass()); |
| 310 | FPM.addPass(InstCombinePass()); |
| 311 | |
| 312 | if (!isOptimizingForSize(Level)) |
| 313 | FPM.addPass(LibCallsShrinkWrapPass()); |
| 314 | |
| 315 | FPM.addPass(TailCallElimPass()); |
| 316 | FPM.addPass(SimplifyCFGPass()); |
| 317 | |
| 318 | // Form canonically associated expression trees, and simplify the trees using |
| 319 | // basic mathematical properties. For example, this will form (nearly) |
| 320 | // minimal multiplication trees. |
| 321 | FPM.addPass(ReassociatePass()); |
| 322 | |
| 323 | // Add the primary loop simplification pipeline. |
| 324 | // FIXME: Currently this is split into two loop pass pipelines because we run |
| 325 | // some function passes in between them. These can and should be replaced by |
| 326 | // loop pass equivalenst but those aren't ready yet. Specifically, |
| 327 | // `SimplifyCFGPass` and `InstCombinePass` are used. We have |
| 328 | // `LoopSimplifyCFGPass` which isn't yet powerful enough, and the closest to |
| 329 | // the other we have is `LoopInstSimplify`. |
| 330 | LoopPassManager LPM1(DebugLogging), LPM2(DebugLogging); |
| 331 | |
| 332 | // Rotate Loop - disable header duplication at -Oz |
| 333 | LPM1.addPass(LoopRotatePass(Level != Oz)); |
| 334 | LPM1.addPass(LICMPass()); |
Chandler Carruth | 79b733b | 2017-01-26 23:21:17 +0000 | [diff] [blame] | 335 | #if 0 |
| 336 | // The LoopUnswitch pass isn't yet ported to the new pass manager. |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 337 | LPM1.addPass(LoopUnswitchPass(/* OptimizeForSize */ Level != O3)); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 338 | #endif |
Chandler Carruth | 79b733b | 2017-01-26 23:21:17 +0000 | [diff] [blame] | 339 | LPM2.addPass(IndVarSimplifyPass()); |
| 340 | LPM2.addPass(LoopIdiomRecognizePass()); |
| 341 | LPM2.addPass(LoopDeletionPass()); |
Dehao Chen | 7d23032 | 2017-02-18 03:46:51 +0000 | [diff] [blame] | 342 | LPM2.addPass(LoopUnrollPass::createFull(Level)); |
Chandler Carruth | 79b733b | 2017-01-26 23:21:17 +0000 | [diff] [blame] | 343 | |
Chandler Carruth | 0ede22e | 2017-02-09 23:54:57 +0000 | [diff] [blame] | 344 | // We provide the opt remark emitter pass for LICM to use. We only need to do |
| 345 | // this once as it is immutable. |
| 346 | FPM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>()); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 347 | FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM1))); |
| 348 | FPM.addPass(SimplifyCFGPass()); |
| 349 | FPM.addPass(InstCombinePass()); |
| 350 | FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM2))); |
| 351 | |
| 352 | // Eliminate redundancies. |
| 353 | if (Level != O1) { |
| 354 | // These passes add substantial compile time so skip them at O1. |
| 355 | FPM.addPass(MergedLoadStoreMotionPass()); |
| 356 | FPM.addPass(GVN()); |
| 357 | } |
| 358 | |
| 359 | // Specially optimize memory movement as it doesn't look like dataflow in SSA. |
| 360 | FPM.addPass(MemCpyOptPass()); |
| 361 | |
| 362 | // Sparse conditional constant propagation. |
| 363 | // FIXME: It isn't clear why we do this *after* loop passes rather than |
| 364 | // before... |
| 365 | FPM.addPass(SCCPPass()); |
| 366 | |
| 367 | // Delete dead bit computations (instcombine runs after to fold away the dead |
| 368 | // computations, and then ADCE will run later to exploit any new DCE |
| 369 | // opportunities that creates). |
| 370 | FPM.addPass(BDCEPass()); |
| 371 | |
| 372 | // Run instcombine after redundancy and dead bit elimination to exploit |
| 373 | // opportunities opened up by them. |
| 374 | FPM.addPass(InstCombinePass()); |
| 375 | |
| 376 | // Re-consider control flow based optimizations after redundancy elimination, |
| 377 | // redo DCE, etc. |
| 378 | FPM.addPass(JumpThreadingPass()); |
| 379 | FPM.addPass(CorrelatedValuePropagationPass()); |
| 380 | FPM.addPass(DSEPass()); |
| 381 | FPM.addPass(createFunctionToLoopPassAdaptor(LICMPass())); |
| 382 | |
| 383 | // Finally, do an expensive DCE pass to catch all the dead code exposed by |
| 384 | // the simplifications and basic cleanup after all the simplifications. |
| 385 | FPM.addPass(ADCEPass()); |
| 386 | FPM.addPass(SimplifyCFGPass()); |
| 387 | FPM.addPass(InstCombinePass()); |
| 388 | |
| 389 | return FPM; |
| 390 | } |
| 391 | |
Davide Italiano | 513dfaa | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 392 | static void addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging, |
| 393 | PassBuilder::OptimizationLevel Level, |
| 394 | bool RunProfileGen, std::string ProfileGenFile, |
| 395 | std::string ProfileUseFile) { |
| 396 | // Generally running simplification passes and the inliner with an high |
| 397 | // threshold results in smaller executables, but there may be cases where |
| 398 | // the size grows, so let's be conservative here and skip this simplification |
| 399 | // at -Os/Oz. |
| 400 | if (!isOptimizingForSize(Level)) { |
| 401 | InlineParams IP; |
| 402 | |
| 403 | // In the old pass manager, this is a cl::opt. Should still this be one? |
| 404 | IP.DefaultThreshold = 75; |
| 405 | |
| 406 | // FIXME: The hint threshold has the same value used by the regular inliner. |
| 407 | // This should probably be lowered after performance testing. |
| 408 | // FIXME: this comment is cargo culted from the old pass manager, revisit). |
| 409 | IP.HintThreshold = 325; |
| 410 | |
| 411 | CGSCCPassManager CGPipeline(DebugLogging); |
| 412 | |
| 413 | CGPipeline.addPass(InlinerPass(IP)); |
| 414 | |
| 415 | FunctionPassManager FPM; |
| 416 | FPM.addPass(SROA()); |
| 417 | FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies. |
| 418 | FPM.addPass(SimplifyCFGPass()); // Merge & remove basic blocks. |
| 419 | FPM.addPass(InstCombinePass()); // Combine silly sequences. |
| 420 | |
| 421 | // FIXME: Here the old pass manager inserts peephole extensions. |
| 422 | // Add them when they're supported. |
| 423 | CGPipeline.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM))); |
| 424 | |
| 425 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPipeline))); |
| 426 | } |
| 427 | |
| 428 | if (RunProfileGen) { |
| 429 | MPM.addPass(PGOInstrumentationGen()); |
| 430 | |
| 431 | // Add the profile lowering pass. |
| 432 | InstrProfOptions Options; |
| 433 | if (!ProfileGenFile.empty()) |
| 434 | Options.InstrProfileOutput = ProfileGenFile; |
| 435 | MPM.addPass(InstrProfiling(Options)); |
| 436 | } |
| 437 | |
| 438 | if (!ProfileUseFile.empty()) |
| 439 | MPM.addPass(PGOInstrumentationUse(ProfileUseFile)); |
| 440 | } |
| 441 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 442 | ModulePassManager |
| 443 | PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level, |
| 444 | bool DebugLogging) { |
| 445 | assert(Level != O0 && "Must request optimizations for the default pipeline!"); |
| 446 | ModulePassManager MPM(DebugLogging); |
| 447 | |
| 448 | // Force any function attributes we want the rest of the pipeline te observe. |
| 449 | MPM.addPass(ForceFunctionAttrsPass()); |
| 450 | |
| 451 | // Do basic inference of function attributes from known properties of system |
| 452 | // libraries and other oracles. |
| 453 | MPM.addPass(InferFunctionAttrsPass()); |
| 454 | |
| 455 | // Create an early function pass manager to cleanup the output of the |
| 456 | // frontend. |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 457 | FunctionPassManager EarlyFPM(DebugLogging); |
| 458 | EarlyFPM.addPass(SimplifyCFGPass()); |
| 459 | EarlyFPM.addPass(SROA()); |
| 460 | EarlyFPM.addPass(EarlyCSEPass()); |
| 461 | EarlyFPM.addPass(LowerExpectIntrinsicPass()); |
Chandler Carruth | c246a4c | 2017-04-27 00:28:03 +0000 | [diff] [blame] | 462 | if (EnableGVNHoist) |
| 463 | EarlyFPM.addPass(GVNHoistPass()); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 464 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM))); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 465 | |
| 466 | // Interprocedural constant propagation now that basic cleanup has occured |
| 467 | // and prior to optimizing globals. |
| 468 | // FIXME: This position in the pipeline hasn't been carefully considered in |
| 469 | // years, it should be re-analyzed. |
| 470 | MPM.addPass(IPSCCPPass()); |
| 471 | |
| 472 | // Optimize globals to try and fold them into constants. |
| 473 | MPM.addPass(GlobalOptPass()); |
| 474 | |
| 475 | // Promote any localized globals to SSA registers. |
| 476 | // FIXME: Should this instead by a run of SROA? |
| 477 | // FIXME: We should probably run instcombine and simplify-cfg afterward to |
| 478 | // delete control flows that are dead once globals have been folded to |
| 479 | // constants. |
| 480 | MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass())); |
| 481 | |
| 482 | // Remove any dead arguments exposed by cleanups and constand folding |
| 483 | // globals. |
| 484 | MPM.addPass(DeadArgumentEliminationPass()); |
| 485 | |
| 486 | // Create a small function pass pipeline to cleanup after all the global |
| 487 | // optimizations. |
| 488 | FunctionPassManager GlobalCleanupPM(DebugLogging); |
| 489 | GlobalCleanupPM.addPass(InstCombinePass()); |
| 490 | GlobalCleanupPM.addPass(SimplifyCFGPass()); |
| 491 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM))); |
| 492 | |
Davide Italiano | 513dfaa | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 493 | // Add all the requested passes for PGO Instrumentation, if requested. |
| 494 | if (PGOOpt) { |
Dehao Chen | cc75d24 | 2017-02-23 22:15:18 +0000 | [diff] [blame] | 495 | assert(PGOOpt->RunProfileGen || PGOOpt->SamplePGO || |
| 496 | !PGOOpt->ProfileUseFile.empty()); |
Davide Italiano | 513dfaa | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 497 | addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen, |
| 498 | PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile); |
| 499 | } |
| 500 | |
| 501 | // Indirect call promotion that promotes intra-module targes only. |
Dehao Chen | cc75d24 | 2017-02-23 22:15:18 +0000 | [diff] [blame] | 502 | MPM.addPass(PGOIndirectCallPromotion(false, PGOOpt && PGOOpt->SamplePGO)); |
Davide Italiano | 513dfaa | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 503 | |
Chandler Carruth | e87fc8c | 2017-02-12 05:34:04 +0000 | [diff] [blame] | 504 | // Require the GlobalsAA analysis for the module so we can query it within |
| 505 | // the CGSCC pipeline. |
| 506 | MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>()); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 507 | |
Easwaran Raman | 5e6f9bd | 2017-05-04 16:58:45 +0000 | [diff] [blame^] | 508 | // Require the ProfileSummaryAnalysis for the module so we can query it within |
| 509 | // the inliner pass. |
| 510 | MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>()); |
| 511 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 512 | // Now begin the main postorder CGSCC pipeline. |
| 513 | // FIXME: The current CGSCC pipeline has its origins in the legacy pass |
| 514 | // manager and trying to emulate its precise behavior. Much of this doesn't |
| 515 | // make a lot of sense and we should revisit the core CGSCC structure. |
| 516 | CGSCCPassManager MainCGPipeline(DebugLogging); |
| 517 | |
| 518 | // Note: historically, the PruneEH pass was run first to deduce nounwind and |
| 519 | // generally clean up exception handling overhead. It isn't clear this is |
| 520 | // valuable as the inliner doesn't currently care whether it is inlining an |
| 521 | // invoke or a call. |
| 522 | |
| 523 | // Run the inliner first. The theory is that we are walking bottom-up and so |
| 524 | // the callees have already been fully optimized, and we want to inline them |
| 525 | // into the callers so that our optimizations can reflect that. |
| 526 | // FIXME; Customize the threshold based on optimization level. |
| 527 | MainCGPipeline.addPass(InlinerPass()); |
| 528 | |
| 529 | // Now deduce any function attributes based in the current code. |
| 530 | MainCGPipeline.addPass(PostOrderFunctionAttrsPass()); |
| 531 | |
Chandler Carruth | 0ede22e | 2017-02-09 23:54:57 +0000 | [diff] [blame] | 532 | // When at O3 add argument promotion to the pass pipeline. |
| 533 | // FIXME: It isn't at all clear why this should be limited to O3. |
| 534 | if (Level == O3) |
| 535 | MainCGPipeline.addPass(ArgumentPromotionPass()); |
| 536 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 537 | // Lastly, add the core function simplification pipeline nested inside the |
| 538 | // CGSCC walk. |
| 539 | MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor( |
| 540 | buildFunctionSimplificationPipeline(Level, DebugLogging))); |
| 541 | |
Chandler Carruth | 719ffe1 | 2017-02-12 05:38:04 +0000 | [diff] [blame] | 542 | // We wrap the CGSCC pipeline in a devirtualization repeater. This will try |
| 543 | // to detect when we devirtualize indirect calls and iterate the SCC passes |
| 544 | // in that case to try and catch knock-on inlining or function attrs |
| 545 | // opportunities. Then we add it to the module pipeline by walking the SCCs |
| 546 | // in postorder (or bottom-up). |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 547 | MPM.addPass( |
Chandler Carruth | 719ffe1 | 2017-02-12 05:38:04 +0000 | [diff] [blame] | 548 | createModuleToPostOrderCGSCCPassAdaptor(createDevirtSCCRepeatedPass( |
| 549 | std::move(MainCGPipeline), MaxDevirtIterations, DebugLogging))); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 550 | |
| 551 | // This ends the canonicalization and simplification phase of the pipeline. |
| 552 | // At this point, we expect to have canonical and simple IR which we begin |
| 553 | // *optimizing* for efficient execution going forward. |
| 554 | |
| 555 | // Eliminate externally available functions now that inlining is over -- we |
| 556 | // won't emit these anyways. |
| 557 | MPM.addPass(EliminateAvailableExternallyPass()); |
| 558 | |
| 559 | // Do RPO function attribute inference across the module to forward-propagate |
| 560 | // attributes where applicable. |
| 561 | // FIXME: Is this really an optimization rather than a canonicalization? |
| 562 | MPM.addPass(ReversePostOrderFunctionAttrsPass()); |
| 563 | |
Chandler Carruth | e87fc8c | 2017-02-12 05:34:04 +0000 | [diff] [blame] | 564 | // Re-require GloblasAA here prior to function passes. This is particularly |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 565 | // useful as the above will have inlined, DCE'ed, and function-attr |
| 566 | // propagated everything. We should at this point have a reasonably minimal |
| 567 | // and richly annotated call graph. By computing aliasing and mod/ref |
| 568 | // information for all local globals here, the late loop passes and notably |
| 569 | // the vectorizer will be able to use them to help recognize vectorizable |
| 570 | // memory operations. |
Chandler Carruth | e87fc8c | 2017-02-12 05:34:04 +0000 | [diff] [blame] | 571 | MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>()); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 572 | |
| 573 | FunctionPassManager OptimizePM(DebugLogging); |
| 574 | OptimizePM.addPass(Float2IntPass()); |
| 575 | // FIXME: We need to run some loop optimizations to re-rotate loops after |
| 576 | // simplify-cfg and others undo their rotation. |
| 577 | |
| 578 | // Optimize the loop execution. These passes operate on entire loop nests |
| 579 | // rather than on each loop in an inside-out manner, and so they are actually |
| 580 | // function passes. |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 581 | |
| 582 | // First rotate loops that may have been un-rotated by prior passes. |
| 583 | OptimizePM.addPass(createFunctionToLoopPassAdaptor(LoopRotatePass())); |
| 584 | |
| 585 | // Distribute loops to allow partial vectorization. I.e. isolate dependences |
| 586 | // into separate loop that would otherwise inhibit vectorization. This is |
| 587 | // currently only performed for loops marked with the metadata |
| 588 | // llvm.loop.distribute=true or when -enable-loop-distribute is specified. |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 589 | OptimizePM.addPass(LoopDistributePass()); |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 590 | |
| 591 | // Now run the core loop vectorizer. |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 592 | OptimizePM.addPass(LoopVectorizePass()); |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 593 | |
Chandler Carruth | baabda9 | 2017-01-27 01:32:26 +0000 | [diff] [blame] | 594 | // Eliminate loads by forwarding stores from the previous iteration to loads |
| 595 | // of the current iteration. |
| 596 | OptimizePM.addPass(LoopLoadEliminationPass()); |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 597 | |
| 598 | // Cleanup after the loop optimization passes. |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 599 | OptimizePM.addPass(InstCombinePass()); |
| 600 | |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 601 | |
| 602 | // Now that we've formed fast to execute loop structures, we do further |
| 603 | // optimizations. These are run afterward as they might block doing complex |
| 604 | // analyses and transforms such as what are needed for loop vectorization. |
| 605 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 606 | // Optimize parallel scalar instruction chains into SIMD instructions. |
| 607 | OptimizePM.addPass(SLPVectorizerPass()); |
| 608 | |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 609 | // Cleanup after all of the vectorizers. |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 610 | OptimizePM.addPass(SimplifyCFGPass()); |
| 611 | OptimizePM.addPass(InstCombinePass()); |
| 612 | |
| 613 | // Unroll small loops to hide loop backedge latency and saturate any parallel |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 614 | // execution resources of an out-of-order processor. We also then need to |
| 615 | // clean up redundancies and loop invariant code. |
| 616 | // FIXME: It would be really good to use a loop-integrated instruction |
| 617 | // combiner for cleanup here so that the unrolling and LICM can be pipelined |
| 618 | // across the loop nests. |
Dehao Chen | 7d23032 | 2017-02-18 03:46:51 +0000 | [diff] [blame] | 619 | OptimizePM.addPass(createFunctionToLoopPassAdaptor(LoopUnrollPass::create(Level))); |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 620 | OptimizePM.addPass(InstCombinePass()); |
Chandler Carruth | 0ede22e | 2017-02-09 23:54:57 +0000 | [diff] [blame] | 621 | OptimizePM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>()); |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 622 | OptimizePM.addPass(createFunctionToLoopPassAdaptor(LICMPass())); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 623 | |
| 624 | // Now that we've vectorized and unrolled loops, we may have more refined |
| 625 | // alignment information, try to re-derive it here. |
| 626 | OptimizePM.addPass(AlignmentFromAssumptionsPass()); |
| 627 | |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 628 | // LoopSink pass sinks instructions hoisted by LICM, which serves as a |
| 629 | // canonicalization pass that enables other optimizations. As a result, |
| 630 | // LoopSink pass needs to be a very late IR pass to avoid undoing LICM |
| 631 | // result too early. |
| 632 | OptimizePM.addPass(LoopSinkPass()); |
| 633 | |
| 634 | // And finally clean up LCSSA form before generating code. |
| 635 | OptimizePM.addPass(InstSimplifierPass()); |
| 636 | |
Filipe Cabecinhas | 92dc348 | 2017-04-26 12:02:41 +0000 | [diff] [blame] | 637 | // LoopSink (and other loop passes since the last simplifyCFG) might have |
| 638 | // resulted in single-entry-single-exit or empty blocks. Clean up the CFG. |
| 639 | OptimizePM.addPass(SimplifyCFGPass()); |
| 640 | |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 641 | // Add the core optimizing pipeline. |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 642 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM))); |
| 643 | |
| 644 | // Now we need to do some global optimization transforms. |
| 645 | // FIXME: It would seem like these should come first in the optimization |
| 646 | // pipeline and maybe be the bottom of the canonicalization pipeline? Weird |
| 647 | // ordering here. |
| 648 | MPM.addPass(GlobalDCEPass()); |
| 649 | MPM.addPass(ConstantMergePass()); |
| 650 | |
| 651 | return MPM; |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 652 | } |
| 653 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 654 | ModulePassManager |
| 655 | PassBuilder::buildLTOPreLinkDefaultPipeline(OptimizationLevel Level, |
| 656 | bool DebugLogging) { |
| 657 | assert(Level != O0 && "Must request optimizations for the default pipeline!"); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 658 | // FIXME: We should use a customized pre-link pipeline! |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 659 | return buildPerModuleDefaultPipeline(Level, DebugLogging); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 660 | } |
| 661 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 662 | ModulePassManager PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level, |
| 663 | bool DebugLogging) { |
| 664 | assert(Level != O0 && "Must request optimizations for the default pipeline!"); |
| 665 | ModulePassManager MPM(DebugLogging); |
| 666 | |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 667 | // Remove unused virtual tables to improve the quality of code generated by |
| 668 | // whole-program devirtualization and bitset lowering. |
| 669 | MPM.addPass(GlobalDCEPass()); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 670 | |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 671 | // Force any function attributes we want the rest of the pipeline to observe. |
| 672 | MPM.addPass(ForceFunctionAttrsPass()); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 673 | |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 674 | // Do basic inference of function attributes from known properties of system |
| 675 | // libraries and other oracles. |
| 676 | MPM.addPass(InferFunctionAttrsPass()); |
| 677 | |
| 678 | if (Level > 1) { |
| 679 | // Indirect call promotion. This should promote all the targets that are |
| 680 | // left by the earlier promotion pass that promotes intra-module targets. |
| 681 | // This two-step promotion is to save the compile time. For LTO, it should |
| 682 | // produce the same result as if we only do promotion here. |
Dehao Chen | cc75d24 | 2017-02-23 22:15:18 +0000 | [diff] [blame] | 683 | MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */, |
| 684 | PGOOpt && PGOOpt->SamplePGO)); |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 685 | |
| 686 | // Propagate constants at call sites into the functions they call. This |
| 687 | // opens opportunities for globalopt (and inlining) by substituting function |
| 688 | // pointers passed as arguments to direct uses of functions. |
| 689 | MPM.addPass(IPSCCPPass()); |
| 690 | } |
| 691 | |
| 692 | // Now deduce any function attributes based in the current code. |
| 693 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor( |
| 694 | PostOrderFunctionAttrsPass())); |
| 695 | |
| 696 | // Do RPO function attribute inference across the module to forward-propagate |
| 697 | // attributes where applicable. |
| 698 | // FIXME: Is this really an optimization rather than a canonicalization? |
| 699 | MPM.addPass(ReversePostOrderFunctionAttrsPass()); |
| 700 | |
| 701 | // Use inragne annotations on GEP indices to split globals where beneficial. |
| 702 | MPM.addPass(GlobalSplitPass()); |
| 703 | |
| 704 | // Run whole program optimization of virtual call when the list of callees |
| 705 | // is fixed. |
| 706 | MPM.addPass(WholeProgramDevirtPass()); |
| 707 | |
| 708 | // Stop here at -O1. |
| 709 | if (Level == 1) |
| 710 | return MPM; |
| 711 | |
| 712 | // Optimize globals to try and fold them into constants. |
| 713 | MPM.addPass(GlobalOptPass()); |
| 714 | |
| 715 | // Promote any localized globals to SSA registers. |
| 716 | MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass())); |
| 717 | |
| 718 | // Linking modules together can lead to duplicate global constant, only |
| 719 | // keep one copy of each constant. |
| 720 | MPM.addPass(ConstantMergePass()); |
| 721 | |
| 722 | // Remove unused arguments from functions. |
| 723 | MPM.addPass(DeadArgumentEliminationPass()); |
| 724 | |
| 725 | // Reduce the code after globalopt and ipsccp. Both can open up significant |
| 726 | // simplification opportunities, and both can propagate functions through |
| 727 | // function pointers. When this happens, we often have to resolve varargs |
| 728 | // calls, etc, so let instcombine do this. |
| 729 | // FIXME: add peephole extensions here as the legacy PM does. |
| 730 | MPM.addPass(createModuleToFunctionPassAdaptor(InstCombinePass())); |
| 731 | |
| 732 | // Note: historically, the PruneEH pass was run first to deduce nounwind and |
| 733 | // generally clean up exception handling overhead. It isn't clear this is |
| 734 | // valuable as the inliner doesn't currently care whether it is inlining an |
| 735 | // invoke or a call. |
| 736 | // Run the inliner now. |
| 737 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(InlinerPass())); |
| 738 | |
| 739 | // Optimize globals again after we ran the inliner. |
| 740 | MPM.addPass(GlobalOptPass()); |
| 741 | |
| 742 | // Garbage collect dead functions. |
| 743 | // FIXME: Add ArgumentPromotion pass after once it's ported. |
| 744 | MPM.addPass(GlobalDCEPass()); |
| 745 | |
| 746 | FunctionPassManager FPM(DebugLogging); |
| 747 | |
| 748 | // The IPO Passes may leave cruft around. Clean up after them. |
| 749 | // FIXME: add peephole extensions here as the legacy PM does. |
| 750 | FPM.addPass(InstCombinePass()); |
| 751 | FPM.addPass(JumpThreadingPass()); |
| 752 | |
| 753 | // Break up allocas |
| 754 | FPM.addPass(SROA()); |
| 755 | |
| 756 | // Run a few AA driver optimizations here and now to cleanup the code. |
| 757 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
| 758 | |
| 759 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor( |
| 760 | PostOrderFunctionAttrsPass())); |
| 761 | // FIXME: here we run IP alias analysis in the legacy PM. |
| 762 | |
| 763 | FunctionPassManager MainFPM; |
| 764 | |
| 765 | // FIXME: once we fix LoopPass Manager, add LICM here. |
| 766 | // FIXME: once we provide support for enabling MLSM, add it here. |
| 767 | // FIXME: once we provide support for enabling NewGVN, add it here. |
| 768 | MainFPM.addPass(GVN()); |
| 769 | |
| 770 | // Remove dead memcpy()'s. |
| 771 | MainFPM.addPass(MemCpyOptPass()); |
| 772 | |
| 773 | // Nuke dead stores. |
| 774 | MainFPM.addPass(DSEPass()); |
| 775 | |
| 776 | // FIXME: at this point, we run a bunch of loop passes: |
| 777 | // indVarSimplify, loopDeletion, loopInterchange, loopUnrool, |
| 778 | // loopVectorize. Enable them once the remaining issue with LPM |
| 779 | // are sorted out. |
| 780 | |
| 781 | MainFPM.addPass(InstCombinePass()); |
| 782 | MainFPM.addPass(SimplifyCFGPass()); |
| 783 | MainFPM.addPass(SCCPPass()); |
| 784 | MainFPM.addPass(InstCombinePass()); |
| 785 | MainFPM.addPass(BDCEPass()); |
| 786 | |
| 787 | // FIXME: We may want to run SLPVectorizer here. |
| 788 | // After vectorization, assume intrinsics may tell us more |
| 789 | // about pointer alignments. |
| 790 | #if 0 |
| 791 | MainFPM.add(AlignmentFromAssumptionsPass()); |
| 792 | #endif |
| 793 | |
| 794 | // FIXME: Conditionally run LoadCombine here, after it's ported |
| 795 | // (in case we still have this pass, given its questionable usefulness). |
| 796 | |
| 797 | // FIXME: add peephole extensions to the PM here. |
| 798 | MainFPM.addPass(InstCombinePass()); |
| 799 | MainFPM.addPass(JumpThreadingPass()); |
| 800 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(MainFPM))); |
| 801 | |
| 802 | // Create a function that performs CFI checks for cross-DSO calls with |
| 803 | // targets in the current module. |
| 804 | MPM.addPass(CrossDSOCFIPass()); |
| 805 | |
| 806 | // Lower type metadata and the type.test intrinsic. This pass supports |
| 807 | // clang's control flow integrity mechanisms (-fsanitize=cfi*) and needs |
| 808 | // to be run at link time if CFI is enabled. This pass does nothing if |
| 809 | // CFI is disabled. |
| 810 | // Enable once we add support for the summary in the new PM. |
| 811 | #if 0 |
Peter Collingbourne | 857aba4 | 2017-02-09 21:45:01 +0000 | [diff] [blame] | 812 | MPM.addPass(LowerTypeTestsPass(Summary ? PassSummaryAction::Export : |
| 813 | PassSummaryAction::None, |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 814 | Summary)); |
| 815 | #endif |
| 816 | |
| 817 | // Add late LTO optimization passes. |
| 818 | // Delete basic blocks, which optimization passes may have killed. |
| 819 | MPM.addPass(createModuleToFunctionPassAdaptor(SimplifyCFGPass())); |
| 820 | |
| 821 | // Drop bodies of available eternally objects to improve GlobalDCE. |
| 822 | MPM.addPass(EliminateAvailableExternallyPass()); |
| 823 | |
| 824 | // Now that we have optimized the program, discard unreachable functions. |
| 825 | MPM.addPass(GlobalDCEPass()); |
| 826 | |
| 827 | // FIXME: Enable MergeFuncs, conditionally, after ported, maybe. |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 828 | return MPM; |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Chandler Carruth | 060ad61 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 831 | AAManager PassBuilder::buildDefaultAAPipeline() { |
| 832 | AAManager AA; |
| 833 | |
| 834 | // The order in which these are registered determines their priority when |
| 835 | // being queried. |
| 836 | |
| 837 | // First we register the basic alias analysis that provides the majority of |
| 838 | // per-function local AA logic. This is a stateless, on-demand local set of |
| 839 | // AA techniques. |
| 840 | AA.registerFunctionAnalysis<BasicAA>(); |
| 841 | |
| 842 | // Next we query fast, specialized alias analyses that wrap IR-embedded |
| 843 | // information about aliasing. |
| 844 | AA.registerFunctionAnalysis<ScopedNoAliasAA>(); |
| 845 | AA.registerFunctionAnalysis<TypeBasedAA>(); |
| 846 | |
| 847 | // Add support for querying global aliasing information when available. |
Chandler Carruth | 534d644 | 2016-12-24 05:11:17 +0000 | [diff] [blame] | 848 | // Because the `AAManager` is a function analysis and `GlobalsAA` is a module |
| 849 | // analysis, all that the `AAManager` can do is query for any *cached* |
Chandler Carruth | e87fc8c | 2017-02-12 05:34:04 +0000 | [diff] [blame] | 850 | // results from `GlobalsAA` through a readonly proxy. |
Chandler Carruth | 060ad61 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 851 | AA.registerModuleAnalysis<GlobalsAA>(); |
Chandler Carruth | 060ad61 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 852 | |
| 853 | return AA; |
| 854 | } |
| 855 | |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 856 | static Optional<int> parseRepeatPassName(StringRef Name) { |
| 857 | if (!Name.consume_front("repeat<") || !Name.consume_back(">")) |
| 858 | return None; |
| 859 | int Count; |
| 860 | if (Name.getAsInteger(0, Count) || Count <= 0) |
| 861 | return None; |
| 862 | return Count; |
| 863 | } |
| 864 | |
Chandler Carruth | 05ca5ac | 2016-12-28 11:07:33 +0000 | [diff] [blame] | 865 | static Optional<int> parseDevirtPassName(StringRef Name) { |
| 866 | if (!Name.consume_front("devirt<") || !Name.consume_back(">")) |
| 867 | return None; |
| 868 | int Count; |
| 869 | if (Name.getAsInteger(0, Count) || Count <= 0) |
| 870 | return None; |
| 871 | return Count; |
| 872 | } |
| 873 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 874 | static bool isModulePassName(StringRef Name) { |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 875 | // Manually handle aliases for pre-configured pipeline fragments. |
| 876 | if (Name.startswith("default") || Name.startswith("lto")) |
| 877 | return DefaultAliasRegex.match(Name); |
| 878 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 879 | // Explicitly handle pass manager names. |
| 880 | if (Name == "module") |
| 881 | return true; |
| 882 | if (Name == "cgscc") |
| 883 | return true; |
| 884 | if (Name == "function") |
| 885 | return true; |
| 886 | |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 887 | // Explicitly handle custom-parsed pass names. |
| 888 | if (parseRepeatPassName(Name)) |
| 889 | return true; |
| 890 | |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 891 | #define MODULE_PASS(NAME, CREATE_PASS) \ |
| 892 | if (Name == NAME) \ |
| 893 | return true; |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 894 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 895 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 896 | return true; |
| 897 | #include "PassRegistry.def" |
| 898 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 899 | return false; |
| 900 | } |
| 901 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 902 | static bool isCGSCCPassName(StringRef Name) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 903 | // Explicitly handle pass manager names. |
| 904 | if (Name == "cgscc") |
| 905 | return true; |
| 906 | if (Name == "function") |
| 907 | return true; |
| 908 | |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 909 | // Explicitly handle custom-parsed pass names. |
| 910 | if (parseRepeatPassName(Name)) |
| 911 | return true; |
Chandler Carruth | 05ca5ac | 2016-12-28 11:07:33 +0000 | [diff] [blame] | 912 | if (parseDevirtPassName(Name)) |
| 913 | return true; |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 914 | |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 915 | #define CGSCC_PASS(NAME, CREATE_PASS) \ |
| 916 | if (Name == NAME) \ |
| 917 | return true; |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 918 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 919 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 920 | return true; |
| 921 | #include "PassRegistry.def" |
| 922 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 923 | return false; |
| 924 | } |
| 925 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 926 | static bool isFunctionPassName(StringRef Name) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 927 | // Explicitly handle pass manager names. |
| 928 | if (Name == "function") |
| 929 | return true; |
| 930 | if (Name == "loop") |
| 931 | return true; |
| 932 | |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 933 | // Explicitly handle custom-parsed pass names. |
| 934 | if (parseRepeatPassName(Name)) |
| 935 | return true; |
| 936 | |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 937 | #define FUNCTION_PASS(NAME, CREATE_PASS) \ |
| 938 | if (Name == NAME) \ |
| 939 | return true; |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 940 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 941 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 942 | return true; |
| 943 | #include "PassRegistry.def" |
| 944 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 945 | return false; |
| 946 | } |
| 947 | |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 948 | static bool isLoopPassName(StringRef Name) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 949 | // Explicitly handle pass manager names. |
| 950 | if (Name == "loop") |
| 951 | return true; |
| 952 | |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 953 | // Explicitly handle custom-parsed pass names. |
| 954 | if (parseRepeatPassName(Name)) |
| 955 | return true; |
| 956 | |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 957 | #define LOOP_PASS(NAME, CREATE_PASS) \ |
| 958 | if (Name == NAME) \ |
| 959 | return true; |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 960 | #define LOOP_ANALYSIS(NAME, CREATE_PASS) \ |
| 961 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
| 962 | return true; |
| 963 | #include "PassRegistry.def" |
| 964 | |
| 965 | return false; |
| 966 | } |
| 967 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 968 | Optional<std::vector<PassBuilder::PipelineElement>> |
| 969 | PassBuilder::parsePipelineText(StringRef Text) { |
| 970 | std::vector<PipelineElement> ResultPipeline; |
| 971 | |
| 972 | SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = { |
| 973 | &ResultPipeline}; |
| 974 | for (;;) { |
| 975 | std::vector<PipelineElement> &Pipeline = *PipelineStack.back(); |
| 976 | size_t Pos = Text.find_first_of(",()"); |
| 977 | Pipeline.push_back({Text.substr(0, Pos), {}}); |
| 978 | |
| 979 | // If we have a single terminating name, we're done. |
| 980 | if (Pos == Text.npos) |
| 981 | break; |
| 982 | |
| 983 | char Sep = Text[Pos]; |
| 984 | Text = Text.substr(Pos + 1); |
| 985 | if (Sep == ',') |
| 986 | // Just a name ending in a comma, continue. |
| 987 | continue; |
| 988 | |
| 989 | if (Sep == '(') { |
| 990 | // Push the inner pipeline onto the stack to continue processing. |
| 991 | PipelineStack.push_back(&Pipeline.back().InnerPipeline); |
| 992 | continue; |
| 993 | } |
| 994 | |
| 995 | assert(Sep == ')' && "Bogus separator!"); |
| 996 | // When handling the close parenthesis, we greedily consume them to avoid |
| 997 | // empty strings in the pipeline. |
| 998 | do { |
| 999 | // If we try to pop the outer pipeline we have unbalanced parentheses. |
| 1000 | if (PipelineStack.size() == 1) |
| 1001 | return None; |
| 1002 | |
| 1003 | PipelineStack.pop_back(); |
| 1004 | } while (Text.consume_front(")")); |
| 1005 | |
| 1006 | // Check if we've finished parsing. |
| 1007 | if (Text.empty()) |
| 1008 | break; |
| 1009 | |
| 1010 | // Otherwise, the end of an inner pipeline always has to be followed by |
| 1011 | // a comma, and then we can continue. |
| 1012 | if (!Text.consume_front(",")) |
| 1013 | return None; |
| 1014 | } |
| 1015 | |
| 1016 | if (PipelineStack.size() > 1) |
| 1017 | // Unbalanced paretheses. |
| 1018 | return None; |
| 1019 | |
| 1020 | assert(PipelineStack.back() == &ResultPipeline && |
| 1021 | "Wrong pipeline at the bottom of the stack!"); |
| 1022 | return {std::move(ResultPipeline)}; |
| 1023 | } |
| 1024 | |
| 1025 | bool PassBuilder::parseModulePass(ModulePassManager &MPM, |
| 1026 | const PipelineElement &E, bool VerifyEachPass, |
| 1027 | bool DebugLogging) { |
| 1028 | auto &Name = E.Name; |
| 1029 | auto &InnerPipeline = E.InnerPipeline; |
| 1030 | |
| 1031 | // First handle complex passes like the pass managers which carry pipelines. |
| 1032 | if (!InnerPipeline.empty()) { |
| 1033 | if (Name == "module") { |
| 1034 | ModulePassManager NestedMPM(DebugLogging); |
| 1035 | if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass, |
| 1036 | DebugLogging)) |
| 1037 | return false; |
| 1038 | MPM.addPass(std::move(NestedMPM)); |
| 1039 | return true; |
| 1040 | } |
| 1041 | if (Name == "cgscc") { |
| 1042 | CGSCCPassManager CGPM(DebugLogging); |
| 1043 | if (!parseCGSCCPassPipeline(CGPM, InnerPipeline, VerifyEachPass, |
| 1044 | DebugLogging)) |
| 1045 | return false; |
| 1046 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM), |
| 1047 | DebugLogging)); |
| 1048 | return true; |
| 1049 | } |
| 1050 | if (Name == "function") { |
| 1051 | FunctionPassManager FPM(DebugLogging); |
| 1052 | if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass, |
| 1053 | DebugLogging)) |
| 1054 | return false; |
| 1055 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
| 1056 | return true; |
| 1057 | } |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1058 | if (auto Count = parseRepeatPassName(Name)) { |
| 1059 | ModulePassManager NestedMPM(DebugLogging); |
| 1060 | if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass, |
| 1061 | DebugLogging)) |
| 1062 | return false; |
Chandler Carruth | a053a88 | 2016-08-04 03:52:53 +0000 | [diff] [blame] | 1063 | MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM))); |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1064 | return true; |
| 1065 | } |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1066 | // Normal passes can't have pipelines. |
| 1067 | return false; |
| 1068 | } |
| 1069 | |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1070 | // Manually handle aliases for pre-configured pipeline fragments. |
| 1071 | if (Name.startswith("default") || Name.startswith("lto")) { |
| 1072 | SmallVector<StringRef, 3> Matches; |
| 1073 | if (!DefaultAliasRegex.match(Name, &Matches)) |
| 1074 | return false; |
| 1075 | assert(Matches.size() == 3 && "Must capture two matched strings!"); |
| 1076 | |
Jordan Rose | f85a95f | 2016-07-25 18:34:51 +0000 | [diff] [blame] | 1077 | OptimizationLevel L = StringSwitch<OptimizationLevel>(Matches[2]) |
| 1078 | .Case("O0", O0) |
| 1079 | .Case("O1", O1) |
| 1080 | .Case("O2", O2) |
| 1081 | .Case("O3", O3) |
| 1082 | .Case("Os", Os) |
| 1083 | .Case("Oz", Oz); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1084 | if (L == O0) |
| 1085 | // At O0 we do nothing at all! |
| 1086 | return true; |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1087 | |
| 1088 | if (Matches[1] == "default") { |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1089 | MPM.addPass(buildPerModuleDefaultPipeline(L, DebugLogging)); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1090 | } else if (Matches[1] == "lto-pre-link") { |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1091 | MPM.addPass(buildLTOPreLinkDefaultPipeline(L, DebugLogging)); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1092 | } else { |
| 1093 | assert(Matches[1] == "lto" && "Not one of the matched options!"); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1094 | MPM.addPass(buildLTODefaultPipeline(L, DebugLogging)); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1095 | } |
| 1096 | return true; |
| 1097 | } |
| 1098 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1099 | // Finally expand the basic registered passes from the .inc file. |
Chandler Carruth | 5894418 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 1100 | #define MODULE_PASS(NAME, CREATE_PASS) \ |
| 1101 | if (Name == NAME) { \ |
| 1102 | MPM.addPass(CREATE_PASS); \ |
| 1103 | return true; \ |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 1104 | } |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1105 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
| 1106 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | 9b35e6d | 2016-08-19 18:36:06 +0000 | [diff] [blame] | 1107 | MPM.addPass( \ |
| 1108 | RequireAnalysisPass< \ |
| 1109 | std::remove_reference<decltype(CREATE_PASS)>::type, Module>()); \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1110 | return true; \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 1111 | } \ |
| 1112 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 1113 | MPM.addPass(InvalidateAnalysisPass< \ |
| 1114 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 1115 | return true; \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1116 | } |
| 1117 | #include "PassRegistry.def" |
| 1118 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1119 | return false; |
| 1120 | } |
| 1121 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1122 | bool PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM, |
| 1123 | const PipelineElement &E, bool VerifyEachPass, |
| 1124 | bool DebugLogging) { |
| 1125 | auto &Name = E.Name; |
| 1126 | auto &InnerPipeline = E.InnerPipeline; |
| 1127 | |
| 1128 | // First handle complex passes like the pass managers which carry pipelines. |
| 1129 | if (!InnerPipeline.empty()) { |
| 1130 | if (Name == "cgscc") { |
| 1131 | CGSCCPassManager NestedCGPM(DebugLogging); |
| 1132 | if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass, |
| 1133 | DebugLogging)) |
| 1134 | return false; |
| 1135 | // Add the nested pass manager with the appropriate adaptor. |
| 1136 | CGPM.addPass(std::move(NestedCGPM)); |
| 1137 | return true; |
| 1138 | } |
| 1139 | if (Name == "function") { |
| 1140 | FunctionPassManager FPM(DebugLogging); |
| 1141 | if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass, |
| 1142 | DebugLogging)) |
| 1143 | return false; |
| 1144 | // Add the nested pass manager with the appropriate adaptor. |
| 1145 | CGPM.addPass( |
| 1146 | createCGSCCToFunctionPassAdaptor(std::move(FPM), DebugLogging)); |
| 1147 | return true; |
| 1148 | } |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1149 | if (auto Count = parseRepeatPassName(Name)) { |
| 1150 | CGSCCPassManager NestedCGPM(DebugLogging); |
| 1151 | if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass, |
| 1152 | DebugLogging)) |
| 1153 | return false; |
Chandler Carruth | a053a88 | 2016-08-04 03:52:53 +0000 | [diff] [blame] | 1154 | CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM))); |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1155 | return true; |
| 1156 | } |
Chandler Carruth | 05ca5ac | 2016-12-28 11:07:33 +0000 | [diff] [blame] | 1157 | if (auto MaxRepetitions = parseDevirtPassName(Name)) { |
| 1158 | CGSCCPassManager NestedCGPM(DebugLogging); |
| 1159 | if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass, |
| 1160 | DebugLogging)) |
| 1161 | return false; |
| 1162 | CGPM.addPass(createDevirtSCCRepeatedPass(std::move(NestedCGPM), |
| 1163 | *MaxRepetitions, DebugLogging)); |
| 1164 | return true; |
| 1165 | } |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1166 | // Normal passes can't have pipelines. |
| 1167 | return false; |
| 1168 | } |
| 1169 | |
| 1170 | // Now expand the basic registered passes from the .inc file. |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1171 | #define CGSCC_PASS(NAME, CREATE_PASS) \ |
| 1172 | if (Name == NAME) { \ |
| 1173 | CGPM.addPass(CREATE_PASS); \ |
| 1174 | return true; \ |
| 1175 | } |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1176 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
| 1177 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 1178 | CGPM.addPass(RequireAnalysisPass< \ |
Chandler Carruth | 9b35e6d | 2016-08-19 18:36:06 +0000 | [diff] [blame] | 1179 | std::remove_reference<decltype(CREATE_PASS)>::type, \ |
Chandler Carruth | 8882346 | 2016-08-24 09:37:14 +0000 | [diff] [blame] | 1180 | LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \ |
| 1181 | CGSCCUpdateResult &>()); \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1182 | return true; \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 1183 | } \ |
| 1184 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 1185 | CGPM.addPass(InvalidateAnalysisPass< \ |
| 1186 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 1187 | return true; \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1188 | } |
| 1189 | #include "PassRegistry.def" |
| 1190 | |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1191 | return false; |
| 1192 | } |
| 1193 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1194 | bool PassBuilder::parseFunctionPass(FunctionPassManager &FPM, |
| 1195 | const PipelineElement &E, |
| 1196 | bool VerifyEachPass, bool DebugLogging) { |
| 1197 | auto &Name = E.Name; |
| 1198 | auto &InnerPipeline = E.InnerPipeline; |
| 1199 | |
| 1200 | // First handle complex passes like the pass managers which carry pipelines. |
| 1201 | if (!InnerPipeline.empty()) { |
| 1202 | if (Name == "function") { |
| 1203 | FunctionPassManager NestedFPM(DebugLogging); |
| 1204 | if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass, |
| 1205 | DebugLogging)) |
| 1206 | return false; |
| 1207 | // Add the nested pass manager with the appropriate adaptor. |
| 1208 | FPM.addPass(std::move(NestedFPM)); |
| 1209 | return true; |
| 1210 | } |
| 1211 | if (Name == "loop") { |
| 1212 | LoopPassManager LPM(DebugLogging); |
| 1213 | if (!parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass, |
| 1214 | DebugLogging)) |
| 1215 | return false; |
| 1216 | // Add the nested pass manager with the appropriate adaptor. |
| 1217 | FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM))); |
| 1218 | return true; |
| 1219 | } |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1220 | if (auto Count = parseRepeatPassName(Name)) { |
| 1221 | FunctionPassManager NestedFPM(DebugLogging); |
| 1222 | if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass, |
| 1223 | DebugLogging)) |
| 1224 | return false; |
Chandler Carruth | a053a88 | 2016-08-04 03:52:53 +0000 | [diff] [blame] | 1225 | FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM))); |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1226 | return true; |
| 1227 | } |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1228 | // Normal passes can't have pipelines. |
| 1229 | return false; |
| 1230 | } |
| 1231 | |
| 1232 | // Now expand the basic registered passes from the .inc file. |
Chandler Carruth | 5894418 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 1233 | #define FUNCTION_PASS(NAME, CREATE_PASS) \ |
| 1234 | if (Name == NAME) { \ |
| 1235 | FPM.addPass(CREATE_PASS); \ |
| 1236 | return true; \ |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 1237 | } |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1238 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
| 1239 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | 9b35e6d | 2016-08-19 18:36:06 +0000 | [diff] [blame] | 1240 | FPM.addPass( \ |
| 1241 | RequireAnalysisPass< \ |
| 1242 | std::remove_reference<decltype(CREATE_PASS)>::type, Function>()); \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1243 | return true; \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 1244 | } \ |
| 1245 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 1246 | FPM.addPass(InvalidateAnalysisPass< \ |
| 1247 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 1248 | return true; \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1249 | } |
| 1250 | #include "PassRegistry.def" |
| 1251 | |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 1252 | return false; |
| 1253 | } |
| 1254 | |
Chandler Carruth | fdc6ba1 | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 1255 | bool PassBuilder::parseLoopPass(LoopPassManager &LPM, const PipelineElement &E, |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1256 | bool VerifyEachPass, bool DebugLogging) { |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1257 | StringRef Name = E.Name; |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1258 | auto &InnerPipeline = E.InnerPipeline; |
| 1259 | |
| 1260 | // First handle complex passes like the pass managers which carry pipelines. |
| 1261 | if (!InnerPipeline.empty()) { |
| 1262 | if (Name == "loop") { |
| 1263 | LoopPassManager NestedLPM(DebugLogging); |
| 1264 | if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass, |
| 1265 | DebugLogging)) |
| 1266 | return false; |
| 1267 | // Add the nested pass manager with the appropriate adaptor. |
Chandler Carruth | fdc6ba1 | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 1268 | LPM.addPass(std::move(NestedLPM)); |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1269 | return true; |
| 1270 | } |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1271 | if (auto Count = parseRepeatPassName(Name)) { |
| 1272 | LoopPassManager NestedLPM(DebugLogging); |
| 1273 | if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass, |
| 1274 | DebugLogging)) |
| 1275 | return false; |
Chandler Carruth | a053a88 | 2016-08-04 03:52:53 +0000 | [diff] [blame] | 1276 | LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM))); |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1277 | return true; |
| 1278 | } |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1279 | // Normal passes can't have pipelines. |
| 1280 | return false; |
| 1281 | } |
| 1282 | |
| 1283 | // Now expand the basic registered passes from the .inc file. |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1284 | #define LOOP_PASS(NAME, CREATE_PASS) \ |
| 1285 | if (Name == NAME) { \ |
Chandler Carruth | fdc6ba1 | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 1286 | LPM.addPass(CREATE_PASS); \ |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1287 | return true; \ |
| 1288 | } |
| 1289 | #define LOOP_ANALYSIS(NAME, CREATE_PASS) \ |
| 1290 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | fdc6ba1 | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 1291 | LPM.addPass(RequireAnalysisPass< \ |
Chandler Carruth | 410eaeb | 2017-01-11 06:23:21 +0000 | [diff] [blame] | 1292 | std::remove_reference<decltype(CREATE_PASS)>::type, Loop, \ |
| 1293 | LoopAnalysisManager, LoopStandardAnalysisResults &, \ |
| 1294 | LPMUpdater &>()); \ |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1295 | return true; \ |
| 1296 | } \ |
| 1297 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | fdc6ba1 | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 1298 | LPM.addPass(InvalidateAnalysisPass< \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 1299 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1300 | return true; \ |
| 1301 | } |
| 1302 | #include "PassRegistry.def" |
| 1303 | |
| 1304 | return false; |
| 1305 | } |
| 1306 | |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 1307 | bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) { |
Chandler Carruth | 45a9c20 | 2016-03-11 09:15:11 +0000 | [diff] [blame] | 1308 | #define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \ |
| 1309 | if (Name == NAME) { \ |
| 1310 | AA.registerModuleAnalysis< \ |
| 1311 | std::remove_reference<decltype(CREATE_PASS)>::type>(); \ |
| 1312 | return true; \ |
| 1313 | } |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 1314 | #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \ |
| 1315 | if (Name == NAME) { \ |
Chandler Carruth | 58dde8c | 2016-02-26 12:17:54 +0000 | [diff] [blame] | 1316 | AA.registerFunctionAnalysis< \ |
| 1317 | std::remove_reference<decltype(CREATE_PASS)>::type>(); \ |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 1318 | return true; \ |
| 1319 | } |
| 1320 | #include "PassRegistry.def" |
| 1321 | |
| 1322 | return false; |
| 1323 | } |
| 1324 | |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1325 | bool PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM, |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1326 | ArrayRef<PipelineElement> Pipeline, |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1327 | bool VerifyEachPass, |
| 1328 | bool DebugLogging) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1329 | for (const auto &Element : Pipeline) { |
| 1330 | if (!parseLoopPass(LPM, Element, VerifyEachPass, DebugLogging)) |
| 1331 | return false; |
| 1332 | // FIXME: No verifier support for Loop passes! |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1333 | } |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1334 | return true; |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1335 | } |
| 1336 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 1337 | bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM, |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1338 | ArrayRef<PipelineElement> Pipeline, |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 1339 | bool VerifyEachPass, |
| 1340 | bool DebugLogging) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1341 | for (const auto &Element : Pipeline) { |
| 1342 | if (!parseFunctionPass(FPM, Element, VerifyEachPass, DebugLogging)) |
| 1343 | return false; |
| 1344 | if (VerifyEachPass) |
| 1345 | FPM.addPass(VerifierPass()); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 1346 | } |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1347 | return true; |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 1350 | bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM, |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1351 | ArrayRef<PipelineElement> Pipeline, |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 1352 | bool VerifyEachPass, |
| 1353 | bool DebugLogging) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1354 | for (const auto &Element : Pipeline) { |
| 1355 | if (!parseCGSCCPass(CGPM, Element, VerifyEachPass, DebugLogging)) |
| 1356 | return false; |
| 1357 | // FIXME: No verifier support for CGSCC passes! |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1358 | } |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1359 | return true; |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
NAKAMURA Takumi | a42f528 | 2016-05-16 10:13:37 +0000 | [diff] [blame] | 1362 | void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM, |
| 1363 | FunctionAnalysisManager &FAM, |
| 1364 | CGSCCAnalysisManager &CGAM, |
| 1365 | ModuleAnalysisManager &MAM) { |
| 1366 | MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); }); |
| 1367 | MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); }); |
NAKAMURA Takumi | a42f528 | 2016-05-16 10:13:37 +0000 | [diff] [blame] | 1368 | CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); }); |
| 1369 | FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); }); |
| 1370 | FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); }); |
| 1371 | FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); }); |
| 1372 | LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); }); |
| 1373 | } |
| 1374 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 1375 | bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM, |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1376 | ArrayRef<PipelineElement> Pipeline, |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 1377 | bool VerifyEachPass, |
| 1378 | bool DebugLogging) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1379 | for (const auto &Element : Pipeline) { |
| 1380 | if (!parseModulePass(MPM, Element, VerifyEachPass, DebugLogging)) |
| 1381 | return false; |
| 1382 | if (VerifyEachPass) |
| 1383 | MPM.addPass(VerifierPass()); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1384 | } |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1385 | return true; |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | // Primary pass pipeline description parsing routine. |
| 1389 | // FIXME: Should this routine accept a TargetMachine or require the caller to |
| 1390 | // pre-populate the analysis managers with target-specific stuff? |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 1391 | bool PassBuilder::parsePassPipeline(ModulePassManager &MPM, |
| 1392 | StringRef PipelineText, bool VerifyEachPass, |
| 1393 | bool DebugLogging) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1394 | auto Pipeline = parsePipelineText(PipelineText); |
| 1395 | if (!Pipeline || Pipeline->empty()) |
| 1396 | return false; |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1397 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1398 | // If the first name isn't at the module layer, wrap the pipeline up |
| 1399 | // automatically. |
| 1400 | StringRef FirstName = Pipeline->front().Name; |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1401 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1402 | if (!isModulePassName(FirstName)) { |
| 1403 | if (isCGSCCPassName(FirstName)) |
| 1404 | Pipeline = {{"cgscc", std::move(*Pipeline)}}; |
| 1405 | else if (isFunctionPassName(FirstName)) |
| 1406 | Pipeline = {{"function", std::move(*Pipeline)}}; |
| 1407 | else if (isLoopPassName(FirstName)) |
| 1408 | Pipeline = {{"function", {{"loop", std::move(*Pipeline)}}}}; |
| 1409 | else |
| 1410 | // Unknown pass name! |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1411 | return false; |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1412 | } |
| 1413 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1414 | return parseModulePassPipeline(MPM, *Pipeline, VerifyEachPass, DebugLogging); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1415 | } |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 1416 | |
| 1417 | bool PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) { |
Chandler Carruth | 060ad61 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 1418 | // If the pipeline just consists of the word 'default' just replace the AA |
| 1419 | // manager with our default one. |
| 1420 | if (PipelineText == "default") { |
| 1421 | AA = buildDefaultAAPipeline(); |
| 1422 | return true; |
| 1423 | } |
| 1424 | |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 1425 | while (!PipelineText.empty()) { |
| 1426 | StringRef Name; |
| 1427 | std::tie(Name, PipelineText) = PipelineText.split(','); |
| 1428 | if (!parseAAPassName(AA, Name)) |
| 1429 | return false; |
| 1430 | } |
| 1431 | |
| 1432 | return true; |
| 1433 | } |