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