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 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// \file |
| 9 | /// |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 10 | /// This file provides the implementation of the PassBuilder based on our |
| 11 | /// static pass registry as well as related functionality. It also provides |
| 12 | /// helpers to aid in analyzing, debugging, and testing passes and pass |
| 13 | /// pipelines. |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 14 | /// |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 17 | #include "llvm/Passes/PassBuilder.h" |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringSwitch.h" |
Chandler Carruth | 6f5770b10 | 2016-02-13 23:32:00 +0000 | [diff] [blame] | 19 | #include "llvm/Analysis/AliasAnalysis.h" |
Chandler Carruth | 4f846a5 | 2016-02-20 03:46:03 +0000 | [diff] [blame] | 20 | #include "llvm/Analysis/AliasAnalysisEvaluator.h" |
Daniel Jasper | aec2fa3 | 2016-12-19 08:22:17 +0000 | [diff] [blame] | 21 | #include "llvm/Analysis/AssumptionCache.h" |
Chandler Carruth | bece8d5 | 2016-02-13 23:46:24 +0000 | [diff] [blame] | 22 | #include "llvm/Analysis/BasicAliasAnalysis.h" |
Xinliang David Li | 28a9327 | 2016-05-05 21:13:27 +0000 | [diff] [blame] | 23 | #include "llvm/Analysis/BlockFrequencyInfo.h" |
Xinliang David Li | 6e5dd41 | 2016-05-05 02:59:57 +0000 | [diff] [blame] | 24 | #include "llvm/Analysis/BranchProbabilityInfo.h" |
Mehdi Amini | 27d2379 | 2016-09-16 16:56:30 +0000 | [diff] [blame] | 25 | #include "llvm/Analysis/CFGPrinter.h" |
George Burgess IV | bfa401e | 2016-07-06 00:26:41 +0000 | [diff] [blame] | 26 | #include "llvm/Analysis/CFLAndersAliasAnalysis.h" |
| 27 | #include "llvm/Analysis/CFLSteensAliasAnalysis.h" |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 28 | #include "llvm/Analysis/CGSCCPassManager.h" |
Chandler Carruth | 4c660f7 | 2016-03-10 11:24:11 +0000 | [diff] [blame] | 29 | #include "llvm/Analysis/CallGraph.h" |
Bardia Mahjour | db800c2 | 2019-09-18 17:43:45 +0000 | [diff] [blame] | 30 | #include "llvm/Analysis/DDG.h" |
Michael Kuperstein | de16b44 | 2016-04-18 23:55:01 +0000 | [diff] [blame] | 31 | #include "llvm/Analysis/DemandedBits.h" |
Chandler Carruth | 49c2219 | 2016-05-12 22:19:39 +0000 | [diff] [blame] | 32 | #include "llvm/Analysis/DependenceAnalysis.h" |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 33 | #include "llvm/Analysis/DominanceFrontier.h" |
Chandler Carruth | 45a9c20 | 2016-03-11 09:15:11 +0000 | [diff] [blame] | 34 | #include "llvm/Analysis/GlobalsModRef.h" |
Dehao Chen | 1a44452 | 2016-07-16 22:51:33 +0000 | [diff] [blame] | 35 | #include "llvm/Analysis/IVUsers.h" |
Chandler Carruth | bf71a34 | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 36 | #include "llvm/Analysis/LazyCallGraph.h" |
Sean Silva | 687019f | 2016-06-13 22:01:25 +0000 | [diff] [blame] | 37 | #include "llvm/Analysis/LazyValueInfo.h" |
Xinliang David Li | 8a02131 | 2016-07-02 21:18:40 +0000 | [diff] [blame] | 38 | #include "llvm/Analysis/LoopAccessAnalysis.h" |
Whitney Tsang | dd3b649 | 2019-08-09 13:56:29 +0000 | [diff] [blame] | 39 | #include "llvm/Analysis/LoopCacheAnalysis.h" |
Chandler Carruth | aaf0b4c | 2015-01-20 10:58:50 +0000 | [diff] [blame] | 40 | #include "llvm/Analysis/LoopInfo.h" |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 41 | #include "llvm/Analysis/MemoryDependenceAnalysis.h" |
Daniel Berlin | 554dcd8 | 2017-04-11 20:06:36 +0000 | [diff] [blame] | 42 | #include "llvm/Analysis/MemorySSA.h" |
Teresa Johnson | f93b246 | 2016-08-12 13:53:02 +0000 | [diff] [blame] | 43 | #include "llvm/Analysis/ModuleSummaryAnalysis.h" |
Adam Nemet | 0965da2 | 2017-10-09 23:19:02 +0000 | [diff] [blame] | 44 | #include "llvm/Analysis/OptimizationRemarkEmitter.h" |
John Brawn | bdbbd83 | 2018-06-28 14:13:06 +0000 | [diff] [blame] | 45 | #include "llvm/Analysis/PhiValues.h" |
Hongbin Zheng | 3f97840 | 2016-02-25 17:54:07 +0000 | [diff] [blame] | 46 | #include "llvm/Analysis/PostDominators.h" |
Easwaran Raman | 019e0bf | 2016-06-03 22:54:26 +0000 | [diff] [blame] | 47 | #include "llvm/Analysis/ProfileSummaryInfo.h" |
Hongbin Zheng | bc53977 | 2016-02-25 17:54:25 +0000 | [diff] [blame] | 48 | #include "llvm/Analysis/RegionInfo.h" |
Chandler Carruth | 2f1fd16 | 2015-08-17 02:08:17 +0000 | [diff] [blame] | 49 | #include "llvm/Analysis/ScalarEvolution.h" |
Chandler Carruth | 2b3d044 | 2016-02-20 04:01:45 +0000 | [diff] [blame] | 50 | #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" |
Chandler Carruth | d6091a0 | 2016-02-20 04:03:06 +0000 | [diff] [blame] | 51 | #include "llvm/Analysis/ScopedNoAliasAA.h" |
Vitaly Buka | 4493fe1 | 2018-11-26 21:57:47 +0000 | [diff] [blame] | 52 | #include "llvm/Analysis/StackSafetyAnalysis.h" |
Chandler Carruth | 8ca4322 | 2015-01-15 11:39:46 +0000 | [diff] [blame] | 53 | #include "llvm/Analysis/TargetLibraryInfo.h" |
Chandler Carruth | e038552 | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 54 | #include "llvm/Analysis/TargetTransformInfo.h" |
Chandler Carruth | c1dc384 | 2016-02-20 04:04:52 +0000 | [diff] [blame] | 55 | #include "llvm/Analysis/TypeBasedAliasAnalysis.h" |
Yuanfang Chen | cc382cf | 2019-09-30 17:54:50 +0000 | [diff] [blame] | 56 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Michael Kuperstein | 82d5da5 | 2016-06-24 20:13:42 +0000 | [diff] [blame] | 57 | #include "llvm/CodeGen/PreISelIntrinsicLowering.h" |
Wei Mi | 90d195a | 2016-07-08 03:32:49 +0000 | [diff] [blame] | 58 | #include "llvm/CodeGen/UnreachableBlockElim.h" |
Chandler Carruth | 64764b4 | 2015-01-14 10:19:28 +0000 | [diff] [blame] | 59 | #include "llvm/IR/Dominators.h" |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 60 | #include "llvm/IR/IRPrintingPasses.h" |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 61 | #include "llvm/IR/PassManager.h" |
Fedor Sergeev | a2ed448 | 2019-03-31 10:15:39 +0000 | [diff] [blame] | 62 | #include "llvm/IR/SafepointIRVerifier.h" |
Chandler Carruth | 4d35631 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 63 | #include "llvm/IR/Verifier.h" |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 64 | #include "llvm/Support/Debug.h" |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 65 | #include "llvm/Support/FormatVariadic.h" |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 66 | #include "llvm/Support/Regex.h" |
Chandler Carruth | e038552 | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 67 | #include "llvm/Target/TargetMachine.h" |
Amjad Aboud | f1f57a3 | 2018-01-25 12:06:32 +0000 | [diff] [blame] | 68 | #include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h" |
Chandler Carruth | 67fc52f | 2016-08-17 02:56:20 +0000 | [diff] [blame] | 69 | #include "llvm/Transforms/IPO/AlwaysInliner.h" |
Chandler Carruth | addcda4 | 2017-02-09 23:46:27 +0000 | [diff] [blame] | 70 | #include "llvm/Transforms/IPO/ArgumentPromotion.h" |
Johannes Doerfert | aade782 | 2019-06-05 03:02:24 +0000 | [diff] [blame] | 71 | #include "llvm/Transforms/IPO/Attributor.h" |
Matthew Simpson | cb58558 | 2017-10-25 13:40:08 +0000 | [diff] [blame] | 72 | #include "llvm/Transforms/IPO/CalledValuePropagation.h" |
Davide Italiano | 164b9bc | 2016-05-05 00:51:09 +0000 | [diff] [blame] | 73 | #include "llvm/Transforms/IPO/ConstantMerge.h" |
Davide Italiano | 92b933a | 2016-07-09 03:25:35 +0000 | [diff] [blame] | 74 | #include "llvm/Transforms/IPO/CrossDSOCFI.h" |
Sean Silva | e3bb457 | 2016-06-12 09:16:39 +0000 | [diff] [blame] | 75 | #include "llvm/Transforms/IPO/DeadArgumentElimination.h" |
Davide Italiano | 344e838 | 2016-05-05 02:37:32 +0000 | [diff] [blame] | 76 | #include "llvm/Transforms/IPO/ElimAvailExtern.h" |
Chandler Carruth | f49f1a87 | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 77 | #include "llvm/Transforms/IPO/ForceFunctionAttrs.h" |
Chandler Carruth | 9c4ed17 | 2016-02-18 11:03:11 +0000 | [diff] [blame] | 78 | #include "llvm/Transforms/IPO/FunctionAttrs.h" |
Teresa Johnson | 2124157 | 2016-07-18 21:22:24 +0000 | [diff] [blame] | 79 | #include "llvm/Transforms/IPO/FunctionImport.h" |
Davide Italiano | 66228c4 | 2016-05-03 19:39:15 +0000 | [diff] [blame] | 80 | #include "llvm/Transforms/IPO/GlobalDCE.h" |
Justin Bogner | 1a07501 | 2016-04-26 00:28:01 +0000 | [diff] [blame] | 81 | #include "llvm/Transforms/IPO/GlobalOpt.h" |
Davide Italiano | 2ae76dd | 2016-11-21 00:28:23 +0000 | [diff] [blame] | 82 | #include "llvm/Transforms/IPO/GlobalSplit.h" |
Aditya Kumar | 9e20ade | 2018-10-03 05:55:20 +0000 | [diff] [blame] | 83 | #include "llvm/Transforms/IPO/HotColdSplitting.h" |
Chandler Carruth | 3a040e6 | 2015-12-27 08:41:34 +0000 | [diff] [blame] | 84 | #include "llvm/Transforms/IPO/InferFunctionAttrs.h" |
Chandler Carruth | 1d96311 | 2016-12-20 03:15:32 +0000 | [diff] [blame] | 85 | #include "llvm/Transforms/IPO/Inliner.h" |
Justin Bogner | 4563a06 | 2016-04-26 20:15:52 +0000 | [diff] [blame] | 86 | #include "llvm/Transforms/IPO/Internalize.h" |
Davide Italiano | e8ae0b5 | 2016-07-11 18:10:06 +0000 | [diff] [blame] | 87 | #include "llvm/Transforms/IPO/LowerTypeTests.h" |
Easwaran Raman | 1832bf6 | 2016-06-27 16:50:18 +0000 | [diff] [blame] | 88 | #include "llvm/Transforms/IPO/PartialInlining.h" |
Davide Italiano | f54f2f0 | 2016-05-05 21:05:36 +0000 | [diff] [blame] | 89 | #include "llvm/Transforms/IPO/SCCP.h" |
David Blaikie | 301627f | 2018-03-22 22:42:44 +0000 | [diff] [blame] | 90 | #include "llvm/Transforms/IPO/SampleProfile.h" |
Justin Bogner | 21e1537 | 2015-10-30 23:28:12 +0000 | [diff] [blame] | 91 | #include "llvm/Transforms/IPO/StripDeadPrototypes.h" |
Easwaran Raman | bdf2026 | 2018-01-09 19:39:35 +0000 | [diff] [blame] | 92 | #include "llvm/Transforms/IPO/SyntheticCountsPropagation.h" |
Davide Italiano | d737dd2 | 2016-06-14 21:44:19 +0000 | [diff] [blame] | 93 | #include "llvm/Transforms/IPO/WholeProgramDevirt.h" |
Chandler Carruth | f49f1a87 | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 94 | #include "llvm/Transforms/InstCombine/InstCombine.h" |
Philip Pfaffe | b39a97c | 2019-01-03 13:42:44 +0000 | [diff] [blame] | 95 | #include "llvm/Transforms/Instrumentation.h" |
Leonard Chan | 436fb2b | 2019-02-13 22:22:48 +0000 | [diff] [blame] | 96 | #include "llvm/Transforms/Instrumentation/AddressSanitizer.h" |
Chandler Carruth | 00a301d | 2017-11-14 01:30:04 +0000 | [diff] [blame] | 97 | #include "llvm/Transforms/Instrumentation/BoundsChecking.h" |
Vitaly Buka | 4493fe1 | 2018-11-26 21:57:47 +0000 | [diff] [blame] | 98 | #include "llvm/Transforms/Instrumentation/CGProfile.h" |
Hiroshi Yamauchi | 9775a62 | 2018-09-04 17:19:13 +0000 | [diff] [blame] | 99 | #include "llvm/Transforms/Instrumentation/ControlHeightReduction.h" |
Chandler Carruth | 7c557f8 | 2018-06-29 23:36:03 +0000 | [diff] [blame] | 100 | #include "llvm/Transforms/Instrumentation/GCOVProfiler.h" |
Leonard Chan | 0cdd3b1 | 2019-05-14 21:17:21 +0000 | [diff] [blame] | 101 | #include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h" |
Manman Ren | 1829512 | 2019-02-28 20:13:38 +0000 | [diff] [blame] | 102 | #include "llvm/Transforms/Instrumentation/InstrOrderFile.h" |
Chandler Carruth | 7c557f8 | 2018-06-29 23:36:03 +0000 | [diff] [blame] | 103 | #include "llvm/Transforms/Instrumentation/InstrProfiling.h" |
Philip Pfaffe | b39a97c | 2019-01-03 13:42:44 +0000 | [diff] [blame] | 104 | #include "llvm/Transforms/Instrumentation/MemorySanitizer.h" |
David Blaikie | 4fe1fe1 | 2018-03-23 22:11:06 +0000 | [diff] [blame] | 105 | #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h" |
Philip Reames | f47a313 | 2019-07-09 18:49:29 +0000 | [diff] [blame] | 106 | #include "llvm/Transforms/Instrumentation/PoisonChecking.h" |
Leonard Chan | 007f674 | 2019-07-25 20:53:15 +0000 | [diff] [blame] | 107 | #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h" |
Leonard Chan | 436fb2b | 2019-02-13 22:22:48 +0000 | [diff] [blame] | 108 | #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h" |
Justin Bogner | 19b6799 | 2015-10-30 23:13:18 +0000 | [diff] [blame] | 109 | #include "llvm/Transforms/Scalar/ADCE.h" |
Sean Silva | a4c2d15 | 2016-06-15 06:18:01 +0000 | [diff] [blame] | 110 | #include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h" |
Davide Italiano | 655a145 | 2016-05-25 01:57:04 +0000 | [diff] [blame] | 111 | #include "llvm/Transforms/Scalar/BDCE.h" |
Jun Bum Lim | 0c99007 | 2017-11-03 20:41:16 +0000 | [diff] [blame] | 112 | #include "llvm/Transforms/Scalar/CallSiteSplitting.h" |
Adam Nemet | 3beef41 | 2016-07-18 16:29:17 +0000 | [diff] [blame] | 113 | #include "llvm/Transforms/Scalar/ConstantHoisting.h" |
Sean Silva | b025d37 | 2016-07-06 23:26:29 +0000 | [diff] [blame] | 114 | #include "llvm/Transforms/Scalar/CorrelatedValuePropagation.h" |
Justin Bogner | 395c212 | 2016-04-22 19:40:41 +0000 | [diff] [blame] | 115 | #include "llvm/Transforms/Scalar/DCE.h" |
Justin Bogner | 594e07b | 2016-05-17 21:38:13 +0000 | [diff] [blame] | 116 | #include "llvm/Transforms/Scalar/DeadStoreElimination.h" |
Sanjay Patel | 6fd4391 | 2017-09-09 13:38:18 +0000 | [diff] [blame] | 117 | #include "llvm/Transforms/Scalar/DivRemPairs.h" |
Chandler Carruth | e8c686a | 2015-02-01 10:51:23 +0000 | [diff] [blame] | 118 | #include "llvm/Transforms/Scalar/EarlyCSE.h" |
Michael Kuperstein | 83b753d | 2016-06-24 23:32:02 +0000 | [diff] [blame] | 119 | #include "llvm/Transforms/Scalar/Float2Int.h" |
Easwaran Raman | 019e0bf | 2016-06-03 22:54:26 +0000 | [diff] [blame] | 120 | #include "llvm/Transforms/Scalar/GVN.h" |
Davide Italiano | 89ab89d | 2016-06-14 00:49:23 +0000 | [diff] [blame] | 121 | #include "llvm/Transforms/Scalar/GuardWidening.h" |
Chandler Carruth | 3bab7e1 | 2017-01-11 09:43:56 +0000 | [diff] [blame] | 122 | #include "llvm/Transforms/Scalar/IVUsersPrinter.h" |
Sanjoy Das | 4d4339d | 2016-06-05 18:01:19 +0000 | [diff] [blame] | 123 | #include "llvm/Transforms/Scalar/IndVarSimplify.h" |
Fedor Sergeev | 194a407 | 2018-03-15 11:01:19 +0000 | [diff] [blame] | 124 | #include "llvm/Transforms/Scalar/InductiveRangeCheckElimination.h" |
Chandler Carruth | 7c557f8 | 2018-06-29 23:36:03 +0000 | [diff] [blame] | 125 | #include "llvm/Transforms/Scalar/InstSimplifyPass.h" |
Sean Silva | 46590d5 | 2016-06-14 00:51:09 +0000 | [diff] [blame] | 126 | #include "llvm/Transforms/Scalar/JumpThreading.h" |
Dehao Chen | f400a09 | 2016-07-12 22:42:24 +0000 | [diff] [blame] | 127 | #include "llvm/Transforms/Scalar/LICM.h" |
Chandler Carruth | 3bab7e1 | 2017-01-11 09:43:56 +0000 | [diff] [blame] | 128 | #include "llvm/Transforms/Scalar/LoopAccessAnalysisPrinter.h" |
Teresa Johnson | 1eca6bc | 2016-08-13 04:11:27 +0000 | [diff] [blame] | 129 | #include "llvm/Transforms/Scalar/LoopDataPrefetch.h" |
Jun Bum Lim | c837af3 | 2016-07-14 18:28:29 +0000 | [diff] [blame] | 130 | #include "llvm/Transforms/Scalar/LoopDeletion.h" |
Adam Nemet | b2593f7 | 2016-07-18 16:29:27 +0000 | [diff] [blame] | 131 | #include "llvm/Transforms/Scalar/LoopDistribute.h" |
Kit Barton | 3cdf879 | 2019-04-17 18:53:27 +0000 | [diff] [blame] | 132 | #include "llvm/Transforms/Scalar/LoopFuse.h" |
Dehao Chen | b9f8e29 | 2016-07-12 18:45:51 +0000 | [diff] [blame] | 133 | #include "llvm/Transforms/Scalar/LoopIdiomRecognize.h" |
Chandler Carruth | e6c30fd | 2018-05-25 01:32:36 +0000 | [diff] [blame] | 134 | #include "llvm/Transforms/Scalar/LoopInstSimplify.h" |
Chandler Carruth | baabda9 | 2017-01-27 01:32:26 +0000 | [diff] [blame] | 135 | #include "llvm/Transforms/Scalar/LoopLoadElimination.h" |
Chandler Carruth | 3bab7e1 | 2017-01-11 09:43:56 +0000 | [diff] [blame] | 136 | #include "llvm/Transforms/Scalar/LoopPassManager.h" |
Artur Pilipenko | 8fb3d57 | 2017-01-25 16:00:44 +0000 | [diff] [blame] | 137 | #include "llvm/Transforms/Scalar/LoopPredication.h" |
Justin Bogner | d0d2341 | 2016-05-03 22:02:31 +0000 | [diff] [blame] | 138 | #include "llvm/Transforms/Scalar/LoopRotation.h" |
Justin Bogner | ab6a513 | 2016-05-03 21:47:32 +0000 | [diff] [blame] | 139 | #include "llvm/Transforms/Scalar/LoopSimplifyCFG.h" |
Chandler Carruth | e9b18e3 | 2017-01-20 08:42:19 +0000 | [diff] [blame] | 140 | #include "llvm/Transforms/Scalar/LoopSink.h" |
Dehao Chen | 6132ee8 | 2016-07-18 21:41:50 +0000 | [diff] [blame] | 141 | #include "llvm/Transforms/Scalar/LoopStrengthReduce.h" |
David Green | 963401d | 2018-07-01 12:47:30 +0000 | [diff] [blame] | 142 | #include "llvm/Transforms/Scalar/LoopUnrollAndJamPass.h" |
Sean Silva | e3c18a5 | 2016-07-19 23:54:23 +0000 | [diff] [blame] | 143 | #include "llvm/Transforms/Scalar/LoopUnrollPass.h" |
Davide Italiano | 9922344 | 2016-05-13 22:52:35 +0000 | [diff] [blame] | 144 | #include "llvm/Transforms/Scalar/LowerAtomic.h" |
Joerg Sonnenberger | 9681ea9 | 2019-10-14 16:15:14 +0000 | [diff] [blame] | 145 | #include "llvm/Transforms/Scalar/LowerConstantIntrinsics.h" |
Chandler Carruth | 43e590e | 2015-01-24 11:13:02 +0000 | [diff] [blame] | 146 | #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h" |
Michael Kuperstein | e45d4d9 | 2016-07-28 22:08:41 +0000 | [diff] [blame] | 147 | #include "llvm/Transforms/Scalar/LowerGuardIntrinsic.h" |
Max Kazantsev | f392bc8 | 2019-01-31 09:10:17 +0000 | [diff] [blame] | 148 | #include "llvm/Transforms/Scalar/LowerWidenableCondition.h" |
Max Kazantsev | b9e65cb | 2018-12-07 14:39:46 +0000 | [diff] [blame] | 149 | #include "llvm/Transforms/Scalar/MakeGuardsExplicit.h" |
Sean Silva | 6347df0 | 2016-06-14 02:44:55 +0000 | [diff] [blame] | 150 | #include "llvm/Transforms/Scalar/MemCpyOptimizer.h" |
Leonard Chan | bb147aa | 2019-07-15 23:18:31 +0000 | [diff] [blame] | 151 | #include "llvm/Transforms/Scalar/MergeICmps.h" |
Leonard Chan | 007f674 | 2019-07-25 20:53:15 +0000 | [diff] [blame] | 152 | #include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h" |
Wei Mi | 1cf58f8 | 2016-07-21 22:28:52 +0000 | [diff] [blame] | 153 | #include "llvm/Transforms/Scalar/NaryReassociate.h" |
Davide Italiano | e05e330 | 2016-12-22 16:35:02 +0000 | [diff] [blame] | 154 | #include "llvm/Transforms/Scalar/NewGVN.h" |
Davide Italiano | 1021c68 | 2016-05-25 23:38:53 +0000 | [diff] [blame] | 155 | #include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h" |
Justin Bogner | c2bf63d | 2016-04-26 23:39:29 +0000 | [diff] [blame] | 156 | #include "llvm/Transforms/Scalar/Reassociate.h" |
Fedor Sergeev | 4b86d79 | 2017-12-15 09:32:11 +0000 | [diff] [blame] | 157 | #include "llvm/Transforms/Scalar/RewriteStatepointsForGC.h" |
Davide Italiano | 98f7e0e | 2016-05-18 15:18:25 +0000 | [diff] [blame] | 158 | #include "llvm/Transforms/Scalar/SCCP.h" |
Chandler Carruth | 29a18a4 | 2015-09-12 09:09:14 +0000 | [diff] [blame] | 159 | #include "llvm/Transforms/Scalar/SROA.h" |
Mikael Holmen | b6f7600 | 2018-11-21 14:00:17 +0000 | [diff] [blame] | 160 | #include "llvm/Transforms/Scalar/Scalarizer.h" |
Chandler Carruth | 1353f9a | 2017-04-27 18:45:20 +0000 | [diff] [blame] | 161 | #include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h" |
Chandler Carruth | f49f1a87 | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 162 | #include "llvm/Transforms/Scalar/SimplifyCFG.h" |
Justin Bogner | b939490 | 2016-04-22 19:54:10 +0000 | [diff] [blame] | 163 | #include "llvm/Transforms/Scalar/Sink.h" |
Chandler Carruth | c34f789 | 2017-11-28 11:32:31 +0000 | [diff] [blame] | 164 | #include "llvm/Transforms/Scalar/SpeculateAroundPHIs.h" |
Michael Kuperstein | c406186 | 2016-08-01 21:48:33 +0000 | [diff] [blame] | 165 | #include "llvm/Transforms/Scalar/SpeculativeExecution.h" |
Sean Silva | 59fe82f | 2016-07-06 23:48:41 +0000 | [diff] [blame] | 166 | #include "llvm/Transforms/Scalar/TailRecursionElimination.h" |
Michael Kruse | 7244852 | 2018-12-12 17:32:52 +0000 | [diff] [blame] | 167 | #include "llvm/Transforms/Scalar/WarnMissedTransforms.h" |
Xinliang David Li | 1eaecef | 2016-06-15 21:51:30 +0000 | [diff] [blame] | 168 | #include "llvm/Transforms/Utils/AddDiscriminators.h" |
Wei Mi | e04d0ef | 2016-07-22 18:04:25 +0000 | [diff] [blame] | 169 | #include "llvm/Transforms/Utils/BreakCriticalEdges.h" |
Teresa Johnson | 853b962 | 2019-01-04 19:04:54 +0000 | [diff] [blame] | 170 | #include "llvm/Transforms/Utils/CanonicalizeAliases.h" |
Hans Wennborg | e1ecd61 | 2017-11-14 21:09:45 +0000 | [diff] [blame] | 171 | #include "llvm/Transforms/Utils/EntryExitInstrumenter.h" |
Easwaran Raman | e12c487 | 2016-06-09 19:44:46 +0000 | [diff] [blame] | 172 | #include "llvm/Transforms/Utils/LCSSA.h" |
Rong Xu | 1c0e9b9 | 2016-10-18 21:36:27 +0000 | [diff] [blame] | 173 | #include "llvm/Transforms/Utils/LibCallsShrinkWrap.h" |
Davide Italiano | cd96cfd | 2016-07-09 03:03:01 +0000 | [diff] [blame] | 174 | #include "llvm/Transforms/Utils/LoopSimplify.h" |
Michael Kuperstein | 31b8399 | 2016-08-12 17:28:27 +0000 | [diff] [blame] | 175 | #include "llvm/Transforms/Utils/LowerInvoke.h" |
Davide Italiano | cccf4f0 | 2016-06-14 03:22:22 +0000 | [diff] [blame] | 176 | #include "llvm/Transforms/Utils/Mem2Reg.h" |
Mehdi Amini | 27d2379 | 2016-09-16 16:56:30 +0000 | [diff] [blame] | 177 | #include "llvm/Transforms/Utils/NameAnonGlobals.h" |
Michael Kuperstein | 39feb62 | 2016-07-25 20:52:00 +0000 | [diff] [blame] | 178 | #include "llvm/Transforms/Utils/SymbolRewriter.h" |
Markus Lavin | 4dc4ebd | 2018-12-07 08:23:37 +0000 | [diff] [blame] | 179 | #include "llvm/Transforms/Vectorize/LoadStoreVectorizer.h" |
Sean Silva | db90d4d | 2016-07-09 22:56:50 +0000 | [diff] [blame] | 180 | #include "llvm/Transforms/Vectorize/LoopVectorize.h" |
Sean Silva | 0dacbd8 | 2016-07-09 03:11:29 +0000 | [diff] [blame] | 181 | #include "llvm/Transforms/Vectorize/SLPVectorizer.h" |
Davide Italiano | cccf4f0 | 2016-06-14 03:22:22 +0000 | [diff] [blame] | 182 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 183 | using namespace llvm; |
| 184 | |
Chandler Carruth | 719ffe1 | 2017-02-12 05:38:04 +0000 | [diff] [blame] | 185 | static cl::opt<unsigned> MaxDevirtIterations("pm-max-devirt-iterations", |
| 186 | cl::ReallyHidden, cl::init(4)); |
Xinliang David Li | 126157c | 2017-05-22 16:41:57 +0000 | [diff] [blame] | 187 | static cl::opt<bool> |
| 188 | RunPartialInlining("enable-npm-partial-inlining", cl::init(false), |
| 189 | cl::Hidden, cl::ZeroOrMore, |
| 190 | cl::desc("Run Partial inlinining pass")); |
Chandler Carruth | 719ffe1 | 2017-02-12 05:38:04 +0000 | [diff] [blame] | 191 | |
Davide Italiano | 8a09b8e | 2017-05-22 23:41:40 +0000 | [diff] [blame] | 192 | static cl::opt<bool> |
Davide Italiano | 8e7d11a | 2017-05-22 23:47:11 +0000 | [diff] [blame] | 193 | RunNewGVN("enable-npm-newgvn", cl::init(false), |
Davide Italiano | 8a09b8e | 2017-05-22 23:41:40 +0000 | [diff] [blame] | 194 | cl::Hidden, cl::ZeroOrMore, |
| 195 | cl::desc("Run NewGVN instead of GVN")); |
| 196 | |
Chandler Carruth | c246a4c | 2017-04-27 00:28:03 +0000 | [diff] [blame] | 197 | static cl::opt<bool> EnableGVNHoist( |
Eric Christopher | dcf1d97 | 2018-10-01 18:57:08 +0000 | [diff] [blame] | 198 | "enable-npm-gvn-hoist", cl::init(false), cl::Hidden, |
| 199 | cl::desc("Enable the GVN hoisting pass for the new PM (default = off)")); |
Chandler Carruth | c246a4c | 2017-04-27 00:28:03 +0000 | [diff] [blame] | 200 | |
Davide Italiano | be1b6a9 | 2017-06-03 23:18:29 +0000 | [diff] [blame] | 201 | static cl::opt<bool> EnableGVNSink( |
| 202 | "enable-npm-gvn-sink", cl::init(false), cl::Hidden, |
| 203 | cl::desc("Enable the GVN hoisting pass for the new PM (default = off)")); |
| 204 | |
David Green | 963401d | 2018-07-01 12:47:30 +0000 | [diff] [blame] | 205 | static cl::opt<bool> EnableUnrollAndJam( |
| 206 | "enable-npm-unroll-and-jam", cl::init(false), cl::Hidden, |
| 207 | cl::desc("Enable the Unroll and Jam pass for the new PM (default = off)")); |
| 208 | |
Easwaran Raman | bdf2026 | 2018-01-09 19:39:35 +0000 | [diff] [blame] | 209 | static cl::opt<bool> EnableSyntheticCounts( |
| 210 | "enable-npm-synthetic-counts", cl::init(false), cl::Hidden, cl::ZeroOrMore, |
| 211 | cl::desc("Run synthetic function entry count generation " |
| 212 | "pass")); |
| 213 | |
Thomas Preud'homme | 5f73894 | 2019-09-24 14:42:36 +0000 | [diff] [blame] | 214 | static const Regex DefaultAliasRegex( |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 215 | "^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$"); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 216 | |
Eric Christopher | eff3b6f | 2019-04-18 06:17:40 +0000 | [diff] [blame] | 217 | // This option is used in simplifying testing SampleFDO optimizations for |
| 218 | // profile loading. |
Hiroshi Yamauchi | 9775a62 | 2018-09-04 17:19:13 +0000 | [diff] [blame] | 219 | static cl::opt<bool> |
| 220 | EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden, |
| 221 | cl::desc("Enable control height reduction optimization (CHR)")); |
| 222 | |
Alina Sbirlea | 0499a2f | 2019-04-19 16:11:59 +0000 | [diff] [blame] | 223 | PipelineTuningOptions::PipelineTuningOptions() { |
| 224 | LoopInterleaving = EnableLoopInterleaving; |
| 225 | LoopVectorization = EnableLoopVectorization; |
Alina Sbirlea | 458c733 | 2019-05-08 17:58:35 +0000 | [diff] [blame] | 226 | SLPVectorization = RunSLPVectorization; |
Alina Sbirlea | e4b2786 | 2019-05-23 19:35:40 +0000 | [diff] [blame] | 227 | LoopUnrolling = true; |
Alina Sbirlea | d82ddfa | 2019-05-23 21:52:59 +0000 | [diff] [blame] | 228 | ForgetAllSCEVInLoopUnroll = ForgetSCEVInLoopUnroll; |
Alina Sbirlea | 43709f7 | 2019-04-19 17:46:50 +0000 | [diff] [blame] | 229 | LicmMssaOptCap = SetLicmMssaOptCap; |
| 230 | LicmMssaNoAccForPromotionCap = SetLicmMssaNoAccForPromotionCap; |
Alina Sbirlea | 0499a2f | 2019-04-19 16:11:59 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Aditya Kumar | 9e20ade | 2018-10-03 05:55:20 +0000 | [diff] [blame] | 233 | extern cl::opt<bool> EnableHotColdSplit; |
Manman Ren | 1829512 | 2019-02-28 20:13:38 +0000 | [diff] [blame] | 234 | extern cl::opt<bool> EnableOrderFileInstrumentation; |
Aditya Kumar | 9e20ade | 2018-10-03 05:55:20 +0000 | [diff] [blame] | 235 | |
Wei Mi | 3bcccdf | 2019-01-17 20:48:34 +0000 | [diff] [blame] | 236 | extern cl::opt<bool> FlattenedProfileUsed; |
| 237 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 238 | static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level) { |
| 239 | switch (Level) { |
| 240 | case PassBuilder::O0: |
| 241 | case PassBuilder::O1: |
| 242 | case PassBuilder::O2: |
| 243 | case PassBuilder::O3: |
| 244 | return false; |
| 245 | |
| 246 | case PassBuilder::Os: |
| 247 | case PassBuilder::Oz: |
| 248 | return true; |
| 249 | } |
| 250 | llvm_unreachable("Invalid optimization level!"); |
| 251 | } |
| 252 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 253 | namespace { |
| 254 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 255 | /// No-op module pass which does nothing. |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 256 | struct NoOpModulePass { |
Sean Silva | fd03ac6 | 2016-08-09 00:28:38 +0000 | [diff] [blame] | 257 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &) { |
Chandler Carruth | 164a2aa6 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 258 | return PreservedAnalyses::all(); |
| 259 | } |
Chandler Carruth | a13f27c | 2014-01-11 11:52:05 +0000 | [diff] [blame] | 260 | static StringRef name() { return "NoOpModulePass"; } |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 261 | }; |
| 262 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 263 | /// No-op module analysis. |
Chandler Carruth | 30a0730 | 2016-03-11 10:33:22 +0000 | [diff] [blame] | 264 | class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> { |
| 265 | friend AnalysisInfoMixin<NoOpModuleAnalysis>; |
Chandler Carruth | dab4eae | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 266 | static AnalysisKey Key; |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 267 | |
| 268 | public: |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 269 | struct Result {}; |
Sean Silva | fd03ac6 | 2016-08-09 00:28:38 +0000 | [diff] [blame] | 270 | Result run(Module &, ModuleAnalysisManager &) { return Result(); } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 271 | static StringRef name() { return "NoOpModuleAnalysis"; } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 272 | }; |
| 273 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 274 | /// No-op CGSCC pass which does nothing. |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 275 | struct NoOpCGSCCPass { |
Chandler Carruth | 8882346 | 2016-08-24 09:37:14 +0000 | [diff] [blame] | 276 | PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &, |
| 277 | LazyCallGraph &, CGSCCUpdateResult &UR) { |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 278 | return PreservedAnalyses::all(); |
| 279 | } |
| 280 | static StringRef name() { return "NoOpCGSCCPass"; } |
| 281 | }; |
| 282 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 283 | /// No-op CGSCC analysis. |
Chandler Carruth | 30a0730 | 2016-03-11 10:33:22 +0000 | [diff] [blame] | 284 | class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> { |
| 285 | friend AnalysisInfoMixin<NoOpCGSCCAnalysis>; |
Chandler Carruth | dab4eae | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 286 | static AnalysisKey Key; |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 287 | |
| 288 | public: |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 289 | struct Result {}; |
Chandler Carruth | 8882346 | 2016-08-24 09:37:14 +0000 | [diff] [blame] | 290 | Result run(LazyCallGraph::SCC &, CGSCCAnalysisManager &, LazyCallGraph &G) { |
Chandler Carruth | 164a2aa6 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 291 | return Result(); |
| 292 | } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 293 | static StringRef name() { return "NoOpCGSCCAnalysis"; } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 294 | }; |
| 295 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 296 | /// No-op function pass which does nothing. |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 297 | struct NoOpFunctionPass { |
Sean Silva | 36e0d01 | 2016-08-09 00:28:15 +0000 | [diff] [blame] | 298 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &) { |
Chandler Carruth | 164a2aa6 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 299 | return PreservedAnalyses::all(); |
| 300 | } |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 301 | static StringRef name() { return "NoOpFunctionPass"; } |
| 302 | }; |
| 303 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 304 | /// No-op function analysis. |
Chandler Carruth | 30a0730 | 2016-03-11 10:33:22 +0000 | [diff] [blame] | 305 | class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> { |
| 306 | friend AnalysisInfoMixin<NoOpFunctionAnalysis>; |
Chandler Carruth | dab4eae | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 307 | static AnalysisKey Key; |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 308 | |
| 309 | public: |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 310 | struct Result {}; |
Sean Silva | 36e0d01 | 2016-08-09 00:28:15 +0000 | [diff] [blame] | 311 | Result run(Function &, FunctionAnalysisManager &) { return Result(); } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 312 | static StringRef name() { return "NoOpFunctionAnalysis"; } |
Chandler Carruth | 0b576b3 | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 313 | }; |
| 314 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 315 | /// No-op loop pass which does nothing. |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 316 | struct NoOpLoopPass { |
Chandler Carruth | 410eaeb | 2017-01-11 06:23:21 +0000 | [diff] [blame] | 317 | PreservedAnalyses run(Loop &L, LoopAnalysisManager &, |
| 318 | LoopStandardAnalysisResults &, LPMUpdater &) { |
Chandler Carruth | 164a2aa6 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 319 | return PreservedAnalyses::all(); |
| 320 | } |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 321 | static StringRef name() { return "NoOpLoopPass"; } |
| 322 | }; |
| 323 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 324 | /// No-op loop analysis. |
Chandler Carruth | 30a0730 | 2016-03-11 10:33:22 +0000 | [diff] [blame] | 325 | class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> { |
| 326 | friend AnalysisInfoMixin<NoOpLoopAnalysis>; |
Chandler Carruth | dab4eae | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 327 | static AnalysisKey Key; |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 328 | |
| 329 | public: |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 330 | struct Result {}; |
Chandler Carruth | 410eaeb | 2017-01-11 06:23:21 +0000 | [diff] [blame] | 331 | Result run(Loop &, LoopAnalysisManager &, LoopStandardAnalysisResults &) { |
| 332 | return Result(); |
| 333 | } |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 334 | static StringRef name() { return "NoOpLoopAnalysis"; } |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 335 | }; |
| 336 | |
Chandler Carruth | dab4eae | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 337 | AnalysisKey NoOpModuleAnalysis::Key; |
| 338 | AnalysisKey NoOpCGSCCAnalysis::Key; |
| 339 | AnalysisKey NoOpFunctionAnalysis::Key; |
| 340 | AnalysisKey NoOpLoopAnalysis::Key; |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 341 | |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 342 | } // End anonymous namespace. |
| 343 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 344 | void PassBuilder::invokePeepholeEPCallbacks( |
| 345 | FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) { |
| 346 | for (auto &C : PeepholeEPCallbacks) |
| 347 | C(FPM, Level); |
| 348 | } |
| 349 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 350 | void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) { |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 351 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 352 | MAM.registerPass([&] { return CREATE_PASS; }); |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 353 | #include "PassRegistry.def" |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 354 | |
| 355 | for (auto &C : ModuleAnalysisRegistrationCallbacks) |
| 356 | C(MAM); |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 359 | void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) { |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 360 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 361 | CGAM.registerPass([&] { return CREATE_PASS; }); |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 362 | #include "PassRegistry.def" |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 363 | |
| 364 | for (auto &C : CGSCCAnalysisRegistrationCallbacks) |
| 365 | C(CGAM); |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 368 | void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) { |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 369 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 370 | FAM.registerPass([&] { return CREATE_PASS; }); |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 371 | #include "PassRegistry.def" |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 372 | |
| 373 | for (auto &C : FunctionAnalysisRegistrationCallbacks) |
| 374 | C(FAM); |
Chandler Carruth | b70f673 | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 377 | void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) { |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 378 | #define LOOP_ANALYSIS(NAME, CREATE_PASS) \ |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 379 | LAM.registerPass([&] { return CREATE_PASS; }); |
| 380 | #include "PassRegistry.def" |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 381 | |
| 382 | for (auto &C : LoopAnalysisRegistrationCallbacks) |
| 383 | C(LAM); |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 384 | } |
| 385 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 386 | FunctionPassManager |
| 387 | PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level, |
Dehao Chen | 95f0030 | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 388 | ThinLTOPhase Phase, |
| 389 | bool DebugLogging) { |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 390 | assert(Level != O0 && "Must request optimizations!"); |
| 391 | FunctionPassManager FPM(DebugLogging); |
| 392 | |
| 393 | // Form SSA out of local memory accesses after breaking apart aggregates into |
| 394 | // scalars. |
| 395 | FPM.addPass(SROA()); |
| 396 | |
| 397 | // Catch trivial redundancies |
Eric Christopher | dfebd84 | 2019-04-19 22:18:53 +0000 | [diff] [blame] | 398 | FPM.addPass(EarlyCSEPass(true /* Enable mem-ssa. */)); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 399 | |
Davide Italiano | c368831 | 2017-06-01 23:08:14 +0000 | [diff] [blame] | 400 | // Hoisting of scalars and load expressions. |
| 401 | if (EnableGVNHoist) |
| 402 | FPM.addPass(GVNHoistPass()); |
| 403 | |
Davide Italiano | be1b6a9 | 2017-06-03 23:18:29 +0000 | [diff] [blame] | 404 | // Global value numbering based sinking. |
| 405 | if (EnableGVNSink) { |
| 406 | FPM.addPass(GVNSinkPass()); |
| 407 | FPM.addPass(SimplifyCFGPass()); |
| 408 | } |
| 409 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 410 | // Speculative execution if the target has divergent branches; otherwise nop. |
| 411 | FPM.addPass(SpeculativeExecutionPass()); |
| 412 | |
| 413 | // Optimize based on known information about branches, and cleanup afterward. |
| 414 | FPM.addPass(JumpThreadingPass()); |
| 415 | FPM.addPass(CorrelatedValuePropagationPass()); |
| 416 | FPM.addPass(SimplifyCFGPass()); |
Amjad Aboud | f1f57a3 | 2018-01-25 12:06:32 +0000 | [diff] [blame] | 417 | if (Level == O3) |
| 418 | FPM.addPass(AggressiveInstCombinePass()); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 419 | FPM.addPass(InstCombinePass()); |
| 420 | |
| 421 | if (!isOptimizingForSize(Level)) |
| 422 | FPM.addPass(LibCallsShrinkWrapPass()); |
| 423 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 424 | invokePeepholeEPCallbacks(FPM, Level); |
| 425 | |
Rong Xu | e1f4245 | 2017-10-23 22:21:29 +0000 | [diff] [blame] | 426 | // For PGO use pipeline, try to optimize memory intrinsics such as memcpy |
| 427 | // using the size value profile. Don't perform this when optimizing for size. |
Rong Xu | db29a3a | 2019-03-04 20:21:27 +0000 | [diff] [blame] | 428 | if (PGOOpt && PGOOpt->Action == PGOOptions::IRUse && |
Rong Xu | e1f4245 | 2017-10-23 22:21:29 +0000 | [diff] [blame] | 429 | !isOptimizingForSize(Level)) |
| 430 | FPM.addPass(PGOMemOPSizeOpt()); |
| 431 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 432 | FPM.addPass(TailCallElimPass()); |
| 433 | FPM.addPass(SimplifyCFGPass()); |
| 434 | |
| 435 | // Form canonically associated expression trees, and simplify the trees using |
| 436 | // basic mathematical properties. For example, this will form (nearly) |
| 437 | // minimal multiplication trees. |
| 438 | FPM.addPass(ReassociatePass()); |
| 439 | |
| 440 | // Add the primary loop simplification pipeline. |
| 441 | // FIXME: Currently this is split into two loop pass pipelines because we run |
Chandler Carruth | 71fd270 | 2018-05-30 02:46:45 +0000 | [diff] [blame] | 442 | // some function passes in between them. These can and should be removed |
| 443 | // and/or replaced by scheduling the loop pass equivalents in the correct |
| 444 | // positions. But those equivalent passes aren't powerful enough yet. |
| 445 | // Specifically, `SimplifyCFGPass` and `InstCombinePass` are currently still |
| 446 | // used. We have `LoopSimplifyCFGPass` which isn't yet powerful enough yet to |
| 447 | // fully replace `SimplifyCFGPass`, and the closest to the other we have is |
| 448 | // `LoopInstSimplify`. |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 449 | LoopPassManager LPM1(DebugLogging), LPM2(DebugLogging); |
| 450 | |
Chandler Carruth | 71fd270 | 2018-05-30 02:46:45 +0000 | [diff] [blame] | 451 | // Simplify the loop body. We do this initially to clean up after other loop |
| 452 | // passes run, either when iterating on a loop or on inner loops with |
| 453 | // implications on the outer loop. |
| 454 | LPM1.addPass(LoopInstSimplifyPass()); |
| 455 | LPM1.addPass(LoopSimplifyCFGPass()); |
| 456 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 457 | // Rotate Loop - disable header duplication at -Oz |
| 458 | LPM1.addPass(LoopRotatePass(Level != Oz)); |
Alina Sbirlea | 43709f7 | 2019-04-19 17:46:50 +0000 | [diff] [blame] | 459 | LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap)); |
Chandler Carruth | 86248d5 | 2017-05-26 01:24:11 +0000 | [diff] [blame] | 460 | LPM1.addPass(SimpleLoopUnswitchPass()); |
Chandler Carruth | 79b733b | 2017-01-26 23:21:17 +0000 | [diff] [blame] | 461 | LPM2.addPass(IndVarSimplifyPass()); |
| 462 | LPM2.addPass(LoopIdiomRecognizePass()); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 463 | |
| 464 | for (auto &C : LateLoopOptimizationsEPCallbacks) |
| 465 | C(LPM2, Level); |
| 466 | |
Chandler Carruth | 79b733b | 2017-01-26 23:21:17 +0000 | [diff] [blame] | 467 | LPM2.addPass(LoopDeletionPass()); |
Dehao Chen | 95f0030 | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 468 | // Do not enable unrolling in PreLinkThinLTO phase during sample PGO |
Dehao Chen | 3a986142 | 2017-07-07 20:53:10 +0000 | [diff] [blame] | 469 | // because it changes IR to makes profile annotation in back compile |
| 470 | // inaccurate. |
Alina Sbirlea | e4b2786 | 2019-05-23 19:35:40 +0000 | [diff] [blame] | 471 | if ((Phase != ThinLTOPhase::PreLink || !PGOOpt || |
| 472 | PGOOpt->Action != PGOOptions::SampleUse) && |
| 473 | PTO.LoopUnrolling) |
Eric Christopher | c3649a0 | 2019-10-14 22:56:07 +0000 | [diff] [blame] | 474 | LPM2.addPass(LoopFullUnrollPass(Level, /*OnlyWhenForced=*/false, |
| 475 | PTO.ForgetAllSCEVInLoopUnroll)); |
Chandler Carruth | 79b733b | 2017-01-26 23:21:17 +0000 | [diff] [blame] | 476 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 477 | for (auto &C : LoopOptimizerEndEPCallbacks) |
| 478 | C(LPM2, Level); |
| 479 | |
Chandler Carruth | 0ede22e | 2017-02-09 23:54:57 +0000 | [diff] [blame] | 480 | // We provide the opt remark emitter pass for LICM to use. We only need to do |
| 481 | // this once as it is immutable. |
| 482 | FPM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>()); |
Alina Sbirlea | 7425179 | 2019-08-21 17:00:57 +0000 | [diff] [blame] | 483 | FPM.addPass(createFunctionToLoopPassAdaptor( |
| 484 | std::move(LPM1), EnableMSSALoopDependency, DebugLogging)); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 485 | FPM.addPass(SimplifyCFGPass()); |
| 486 | FPM.addPass(InstCombinePass()); |
Alina Sbirlea | 7425179 | 2019-08-21 17:00:57 +0000 | [diff] [blame] | 487 | // The loop passes in LPM2 (IndVarSimplifyPass, LoopIdiomRecognizePass, |
| 488 | // LoopDeletionPass and LoopFullUnrollPass) do not preserve MemorySSA. |
| 489 | // *All* loop passes must preserve it, in order to be able to use it. |
| 490 | FPM.addPass(createFunctionToLoopPassAdaptor( |
| 491 | std::move(LPM2), /*UseMemorySSA=*/false, DebugLogging)); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 492 | |
| 493 | // Eliminate redundancies. |
| 494 | if (Level != O1) { |
| 495 | // These passes add substantial compile time so skip them at O1. |
| 496 | FPM.addPass(MergedLoadStoreMotionPass()); |
Davide Italiano | 8a09b8e | 2017-05-22 23:41:40 +0000 | [diff] [blame] | 497 | if (RunNewGVN) |
| 498 | FPM.addPass(NewGVNPass()); |
| 499 | else |
| 500 | FPM.addPass(GVN()); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | // Specially optimize memory movement as it doesn't look like dataflow in SSA. |
| 504 | FPM.addPass(MemCpyOptPass()); |
| 505 | |
| 506 | // Sparse conditional constant propagation. |
| 507 | // FIXME: It isn't clear why we do this *after* loop passes rather than |
| 508 | // before... |
| 509 | FPM.addPass(SCCPPass()); |
| 510 | |
| 511 | // Delete dead bit computations (instcombine runs after to fold away the dead |
| 512 | // computations, and then ADCE will run later to exploit any new DCE |
| 513 | // opportunities that creates). |
| 514 | FPM.addPass(BDCEPass()); |
| 515 | |
| 516 | // Run instcombine after redundancy and dead bit elimination to exploit |
| 517 | // opportunities opened up by them. |
| 518 | FPM.addPass(InstCombinePass()); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 519 | invokePeepholeEPCallbacks(FPM, Level); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 520 | |
| 521 | // Re-consider control flow based optimizations after redundancy elimination, |
| 522 | // redo DCE, etc. |
| 523 | FPM.addPass(JumpThreadingPass()); |
| 524 | FPM.addPass(CorrelatedValuePropagationPass()); |
| 525 | FPM.addPass(DSEPass()); |
Alina Sbirlea | 43709f7 | 2019-04-19 17:46:50 +0000 | [diff] [blame] | 526 | FPM.addPass(createFunctionToLoopPassAdaptor( |
| 527 | LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap), |
Alina Sbirlea | 7425179 | 2019-08-21 17:00:57 +0000 | [diff] [blame] | 528 | EnableMSSALoopDependency, DebugLogging)); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 529 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 530 | for (auto &C : ScalarOptimizerLateEPCallbacks) |
| 531 | C(FPM, Level); |
| 532 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 533 | // Finally, do an expensive DCE pass to catch all the dead code exposed by |
| 534 | // the simplifications and basic cleanup after all the simplifications. |
| 535 | FPM.addPass(ADCEPass()); |
| 536 | FPM.addPass(SimplifyCFGPass()); |
| 537 | FPM.addPass(InstCombinePass()); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 538 | invokePeepholeEPCallbacks(FPM, Level); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 539 | |
Hiroshi Yamauchi | 9775a62 | 2018-09-04 17:19:13 +0000 | [diff] [blame] | 540 | if (EnableCHR && Level == O3 && PGOOpt && |
Rong Xu | db29a3a | 2019-03-04 20:21:27 +0000 | [diff] [blame] | 541 | (PGOOpt->Action == PGOOptions::IRUse || |
| 542 | PGOOpt->Action == PGOOptions::SampleUse)) |
Hiroshi Yamauchi | 9775a62 | 2018-09-04 17:19:13 +0000 | [diff] [blame] | 543 | FPM.addPass(ControlHeightReductionPass()); |
| 544 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 545 | return FPM; |
| 546 | } |
| 547 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 548 | void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging, |
| 549 | PassBuilder::OptimizationLevel Level, |
Rong Xu | db29a3a | 2019-03-04 20:21:27 +0000 | [diff] [blame] | 550 | bool RunProfileGen, bool IsCS, |
| 551 | std::string ProfileFile, |
Richard Smith | 6c67662 | 2018-10-10 23:13:47 +0000 | [diff] [blame] | 552 | std::string ProfileRemappingFile) { |
Rong Xu | ca161fa | 2019-08-01 22:36:34 +0000 | [diff] [blame] | 553 | assert(Level != O0 && "Not expecting O0 here!"); |
Davide Italiano | 513dfaa | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 554 | // Generally running simplification passes and the inliner with an high |
| 555 | // threshold results in smaller executables, but there may be cases where |
| 556 | // the size grows, so let's be conservative here and skip this simplification |
Rong Xu | db29a3a | 2019-03-04 20:21:27 +0000 | [diff] [blame] | 557 | // at -Os/Oz. We will not do this inline for context sensistive PGO (when |
| 558 | // IsCS is true). |
| 559 | if (!isOptimizingForSize(Level) && !IsCS) { |
Davide Italiano | 513dfaa | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 560 | InlineParams IP; |
| 561 | |
| 562 | // In the old pass manager, this is a cl::opt. Should still this be one? |
| 563 | IP.DefaultThreshold = 75; |
| 564 | |
| 565 | // FIXME: The hint threshold has the same value used by the regular inliner. |
| 566 | // This should probably be lowered after performance testing. |
| 567 | // FIXME: this comment is cargo culted from the old pass manager, revisit). |
| 568 | IP.HintThreshold = 325; |
| 569 | |
| 570 | CGSCCPassManager CGPipeline(DebugLogging); |
| 571 | |
| 572 | CGPipeline.addPass(InlinerPass(IP)); |
| 573 | |
| 574 | FunctionPassManager FPM; |
| 575 | FPM.addPass(SROA()); |
| 576 | FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies. |
| 577 | FPM.addPass(SimplifyCFGPass()); // Merge & remove basic blocks. |
| 578 | FPM.addPass(InstCombinePass()); // Combine silly sequences. |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 579 | invokePeepholeEPCallbacks(FPM, Level); |
Davide Italiano | 513dfaa | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 580 | |
Davide Italiano | 513dfaa | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 581 | CGPipeline.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM))); |
| 582 | |
| 583 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPipeline))); |
Rong Xu | ca161fa | 2019-08-01 22:36:34 +0000 | [diff] [blame] | 584 | |
| 585 | // Delete anything that is now dead to make sure that we don't instrument |
| 586 | // dead code. Instrumentation can end up keeping dead code around and |
| 587 | // dramatically increase code size. |
| 588 | MPM.addPass(GlobalDCEPass()); |
Davide Italiano | 513dfaa | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 589 | } |
| 590 | |
Rong Xu | ca161fa | 2019-08-01 22:36:34 +0000 | [diff] [blame] | 591 | if (!RunProfileGen) { |
| 592 | assert(!ProfileFile.empty() && "Profile use expecting a profile file!"); |
Rong Xu | db29a3a | 2019-03-04 20:21:27 +0000 | [diff] [blame] | 593 | MPM.addPass(PGOInstrumentationUse(ProfileFile, ProfileRemappingFile, IsCS)); |
Hiroshi Yamauchi | 09e539f | 2019-04-15 16:49:00 +0000 | [diff] [blame] | 594 | // Cache ProfileSummaryAnalysis once to avoid the potential need to insert |
| 595 | // RequireAnalysisPass for PSI before subsequent non-module passes. |
| 596 | MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>()); |
Rong Xu | ca161fa | 2019-08-01 22:36:34 +0000 | [diff] [blame] | 597 | return; |
Hiroshi Yamauchi | 09e539f | 2019-04-15 16:49:00 +0000 | [diff] [blame] | 598 | } |
Rong Xu | ca161fa | 2019-08-01 22:36:34 +0000 | [diff] [blame] | 599 | |
| 600 | // Perform PGO instrumentation. |
| 601 | MPM.addPass(PGOInstrumentationGen(IsCS)); |
| 602 | |
| 603 | FunctionPassManager FPM; |
Alina Sbirlea | 7425179 | 2019-08-21 17:00:57 +0000 | [diff] [blame] | 604 | FPM.addPass(createFunctionToLoopPassAdaptor( |
| 605 | LoopRotatePass(), EnableMSSALoopDependency, DebugLogging)); |
Rong Xu | ca161fa | 2019-08-01 22:36:34 +0000 | [diff] [blame] | 606 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
| 607 | |
| 608 | // Add the profile lowering pass. |
| 609 | InstrProfOptions Options; |
| 610 | if (!ProfileFile.empty()) |
| 611 | Options.InstrProfileOutput = ProfileFile; |
| 612 | // Do counter promotion at Level greater than O0. |
| 613 | Options.DoCounterPromotion = true; |
| 614 | Options.UseBFIInPromotion = IsCS; |
| 615 | MPM.addPass(InstrProfiling(Options, IsCS)); |
| 616 | } |
| 617 | |
| 618 | void PassBuilder::addPGOInstrPassesForO0(ModulePassManager &MPM, |
| 619 | bool DebugLogging, bool RunProfileGen, |
| 620 | bool IsCS, std::string ProfileFile, |
| 621 | std::string ProfileRemappingFile) { |
| 622 | if (!RunProfileGen) { |
| 623 | assert(!ProfileFile.empty() && "Profile use expecting a profile file!"); |
| 624 | MPM.addPass(PGOInstrumentationUse(ProfileFile, ProfileRemappingFile, IsCS)); |
| 625 | // Cache ProfileSummaryAnalysis once to avoid the potential need to insert |
| 626 | // RequireAnalysisPass for PSI before subsequent non-module passes. |
| 627 | MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>()); |
| 628 | return; |
| 629 | } |
| 630 | |
| 631 | // Perform PGO instrumentation. |
| 632 | MPM.addPass(PGOInstrumentationGen(IsCS)); |
| 633 | // Add the profile lowering pass. |
| 634 | InstrProfOptions Options; |
| 635 | if (!ProfileFile.empty()) |
| 636 | Options.InstrProfileOutput = ProfileFile; |
| 637 | // Do not do counter promotion at O0. |
| 638 | Options.DoCounterPromotion = false; |
| 639 | Options.UseBFIInPromotion = IsCS; |
| 640 | MPM.addPass(InstrProfiling(Options, IsCS)); |
Davide Italiano | 513dfaa | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 641 | } |
| 642 | |
Easwaran Raman | 8249fac | 2017-06-28 13:33:49 +0000 | [diff] [blame] | 643 | static InlineParams |
| 644 | getInlineParamsFromOptLevel(PassBuilder::OptimizationLevel Level) { |
| 645 | auto O3 = PassBuilder::O3; |
| 646 | unsigned OptLevel = Level > O3 ? 2 : Level; |
| 647 | unsigned SizeLevel = Level > O3 ? Level - O3 : 0; |
| 648 | return getInlineParams(OptLevel, SizeLevel); |
| 649 | } |
| 650 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 651 | ModulePassManager |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 652 | PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, |
Dehao Chen | 95f0030 | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 653 | ThinLTOPhase Phase, |
| 654 | bool DebugLogging) { |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 655 | ModulePassManager MPM(DebugLogging); |
| 656 | |
Rong Xu | db29a3a | 2019-03-04 20:21:27 +0000 | [diff] [blame] | 657 | bool HasSampleProfile = PGOOpt && (PGOOpt->Action == PGOOptions::SampleUse); |
Teresa Johnson | b0bf530 | 2019-02-05 04:09:19 +0000 | [diff] [blame] | 658 | |
| 659 | // In ThinLTO mode, when flattened profile is used, all the available |
| 660 | // profile information will be annotated in PreLink phase so there is |
| 661 | // no need to load the profile again in PostLink. |
| 662 | bool LoadSampleProfile = |
| 663 | HasSampleProfile && |
| 664 | !(FlattenedProfileUsed && Phase == ThinLTOPhase::PostLink); |
| 665 | |
| 666 | // During the ThinLTO backend phase we perform early indirect call promotion |
| 667 | // here, before globalopt. Otherwise imported available_externally functions |
| 668 | // look unreferenced and are removed. If we are going to load the sample |
| 669 | // profile then defer until later. |
| 670 | // TODO: See if we can move later and consolidate with the location where |
| 671 | // we perform ICP when we are loading a sample profile. |
| 672 | // TODO: We pass HasSampleProfile (whether there was a sample profile file |
| 673 | // passed to the compile) to the SamplePGO flag of ICP. This is used to |
| 674 | // determine whether the new direct calls are annotated with prof metadata. |
| 675 | // Ideally this should be determined from whether the IR is annotated with |
| 676 | // sample profile, and not whether the a sample profile was provided on the |
| 677 | // command line. E.g. for flattened profiles where we will not be reloading |
| 678 | // the sample profile in the ThinLTO backend, we ideally shouldn't have to |
| 679 | // provide the sample profile file. |
| 680 | if (Phase == ThinLTOPhase::PostLink && !LoadSampleProfile) |
| 681 | MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */, HasSampleProfile)); |
| 682 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 683 | // Do basic inference of function attributes from known properties of system |
| 684 | // libraries and other oracles. |
| 685 | MPM.addPass(InferFunctionAttrsPass()); |
| 686 | |
| 687 | // Create an early function pass manager to cleanup the output of the |
| 688 | // frontend. |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 689 | FunctionPassManager EarlyFPM(DebugLogging); |
| 690 | EarlyFPM.addPass(SimplifyCFGPass()); |
| 691 | EarlyFPM.addPass(SROA()); |
| 692 | EarlyFPM.addPass(EarlyCSEPass()); |
| 693 | EarlyFPM.addPass(LowerExpectIntrinsicPass()); |
Jun Bum Lim | 0c99007 | 2017-11-03 20:41:16 +0000 | [diff] [blame] | 694 | if (Level == O3) |
| 695 | EarlyFPM.addPass(CallSiteSplittingPass()); |
| 696 | |
Dehao Chen | 08f8831 | 2017-08-07 20:23:20 +0000 | [diff] [blame] | 697 | // In SamplePGO ThinLTO backend, we need instcombine before profile annotation |
| 698 | // to convert bitcast to direct calls so that they can be inlined during the |
| 699 | // profile annotation prepration step. |
| 700 | // More details about SamplePGO design can be found in: |
| 701 | // https://research.google.com/pubs/pub45290.html |
| 702 | // FIXME: revisit how SampleProfileLoad/Inliner/ICP is structured. |
Teresa Johnson | b0bf530 | 2019-02-05 04:09:19 +0000 | [diff] [blame] | 703 | if (LoadSampleProfile) |
Dehao Chen | 08f8831 | 2017-08-07 20:23:20 +0000 | [diff] [blame] | 704 | EarlyFPM.addPass(InstCombinePass()); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 705 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM))); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 706 | |
Teresa Johnson | b0bf530 | 2019-02-05 04:09:19 +0000 | [diff] [blame] | 707 | if (LoadSampleProfile) { |
Dehao Chen | 08f8831 | 2017-08-07 20:23:20 +0000 | [diff] [blame] | 708 | // Annotate sample profile right after early FPM to ensure freshness of |
| 709 | // the debug info. |
Rong Xu | db29a3a | 2019-03-04 20:21:27 +0000 | [diff] [blame] | 710 | MPM.addPass(SampleProfileLoaderPass(PGOOpt->ProfileFile, |
Teresa Johnson | b0bf530 | 2019-02-05 04:09:19 +0000 | [diff] [blame] | 711 | PGOOpt->ProfileRemappingFile, |
| 712 | Phase == ThinLTOPhase::PreLink)); |
Hiroshi Yamauchi | 09e539f | 2019-04-15 16:49:00 +0000 | [diff] [blame] | 713 | // Cache ProfileSummaryAnalysis once to avoid the potential need to insert |
| 714 | // RequireAnalysisPass for PSI before subsequent non-module passes. |
| 715 | MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>()); |
Dehao Chen | 08f8831 | 2017-08-07 20:23:20 +0000 | [diff] [blame] | 716 | // Do not invoke ICP in the ThinLTOPrelink phase as it makes it hard |
| 717 | // for the profile annotation to be accurate in the ThinLTO backend. |
| 718 | if (Phase != ThinLTOPhase::PreLink) |
| 719 | // We perform early indirect call promotion here, before globalopt. |
| 720 | // This is important for the ThinLTO backend phase because otherwise |
| 721 | // imported available_externally functions look unreferenced and are |
| 722 | // removed. |
| 723 | MPM.addPass(PGOIndirectCallPromotion(Phase == ThinLTOPhase::PostLink, |
Teresa Johnson | b0bf530 | 2019-02-05 04:09:19 +0000 | [diff] [blame] | 724 | true /* SamplePGO */)); |
Dehao Chen | 08f8831 | 2017-08-07 20:23:20 +0000 | [diff] [blame] | 725 | } |
| 726 | |
Malcolm Parsons | 21e545d | 2018-01-24 10:33:39 +0000 | [diff] [blame] | 727 | // Interprocedural constant propagation now that basic cleanup has occurred |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 728 | // and prior to optimizing globals. |
| 729 | // FIXME: This position in the pipeline hasn't been carefully considered in |
| 730 | // years, it should be re-analyzed. |
| 731 | MPM.addPass(IPSCCPPass()); |
| 732 | |
Matthew Simpson | cb58558 | 2017-10-25 13:40:08 +0000 | [diff] [blame] | 733 | // Attach metadata to indirect call sites indicating the set of functions |
| 734 | // they may target at run-time. This should follow IPSCCP. |
| 735 | MPM.addPass(CalledValuePropagationPass()); |
| 736 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 737 | // Optimize globals to try and fold them into constants. |
| 738 | MPM.addPass(GlobalOptPass()); |
| 739 | |
| 740 | // Promote any localized globals to SSA registers. |
| 741 | // FIXME: Should this instead by a run of SROA? |
| 742 | // FIXME: We should probably run instcombine and simplify-cfg afterward to |
| 743 | // delete control flows that are dead once globals have been folded to |
| 744 | // constants. |
| 745 | MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass())); |
| 746 | |
| 747 | // Remove any dead arguments exposed by cleanups and constand folding |
| 748 | // globals. |
| 749 | MPM.addPass(DeadArgumentEliminationPass()); |
| 750 | |
| 751 | // Create a small function pass pipeline to cleanup after all the global |
| 752 | // optimizations. |
| 753 | FunctionPassManager GlobalCleanupPM(DebugLogging); |
| 754 | GlobalCleanupPM.addPass(InstCombinePass()); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 755 | invokePeepholeEPCallbacks(GlobalCleanupPM, Level); |
| 756 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 757 | GlobalCleanupPM.addPass(SimplifyCFGPass()); |
| 758 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM))); |
| 759 | |
Dehao Chen | 89d3226 | 2017-08-02 01:28:31 +0000 | [diff] [blame] | 760 | // Add all the requested passes for instrumentation PGO, if requested. |
| 761 | if (PGOOpt && Phase != ThinLTOPhase::PostLink && |
Rong Xu | db29a3a | 2019-03-04 20:21:27 +0000 | [diff] [blame] | 762 | (PGOOpt->Action == PGOOptions::IRInstr || |
| 763 | PGOOpt->Action == PGOOptions::IRUse)) { |
| 764 | addPGOInstrPasses(MPM, DebugLogging, Level, |
| 765 | /* RunProfileGen */ PGOOpt->Action == PGOOptions::IRInstr, |
| 766 | /* IsCS */ false, PGOOpt->ProfileFile, |
Richard Smith | 6c67662 | 2018-10-10 23:13:47 +0000 | [diff] [blame] | 767 | PGOOpt->ProfileRemappingFile); |
Dehao Chen | 89d3226 | 2017-08-02 01:28:31 +0000 | [diff] [blame] | 768 | MPM.addPass(PGOIndirectCallPromotion(false, false)); |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 769 | } |
Rong Xu | db29a3a | 2019-03-04 20:21:27 +0000 | [diff] [blame] | 770 | if (PGOOpt && Phase != ThinLTOPhase::PostLink && |
| 771 | PGOOpt->CSAction == PGOOptions::CSIRInstr) |
| 772 | MPM.addPass(PGOInstrumentationGenCreateVar(PGOOpt->CSProfileGenFile)); |
Davide Italiano | 513dfaa | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 773 | |
Easwaran Raman | bdf2026 | 2018-01-09 19:39:35 +0000 | [diff] [blame] | 774 | // Synthesize function entry counts for non-PGO compilation. |
| 775 | if (EnableSyntheticCounts && !PGOOpt) |
| 776 | MPM.addPass(SyntheticCountsPropagation()); |
| 777 | |
Chandler Carruth | e87fc8c | 2017-02-12 05:34:04 +0000 | [diff] [blame] | 778 | // Require the GlobalsAA analysis for the module so we can query it within |
| 779 | // the CGSCC pipeline. |
| 780 | MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>()); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 781 | |
Easwaran Raman | 5e6f9bd | 2017-05-04 16:58:45 +0000 | [diff] [blame] | 782 | // Require the ProfileSummaryAnalysis for the module so we can query it within |
| 783 | // the inliner pass. |
| 784 | MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>()); |
| 785 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 786 | // Now begin the main postorder CGSCC pipeline. |
| 787 | // FIXME: The current CGSCC pipeline has its origins in the legacy pass |
| 788 | // manager and trying to emulate its precise behavior. Much of this doesn't |
| 789 | // make a lot of sense and we should revisit the core CGSCC structure. |
| 790 | CGSCCPassManager MainCGPipeline(DebugLogging); |
| 791 | |
| 792 | // Note: historically, the PruneEH pass was run first to deduce nounwind and |
| 793 | // generally clean up exception handling overhead. It isn't clear this is |
| 794 | // valuable as the inliner doesn't currently care whether it is inlining an |
| 795 | // invoke or a call. |
| 796 | |
| 797 | // Run the inliner first. The theory is that we are walking bottom-up and so |
| 798 | // the callees have already been fully optimized, and we want to inline them |
| 799 | // into the callers so that our optimizations can reflect that. |
Dehao Chen | 95f0030 | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 800 | // For PreLinkThinLTO pass, we disable hot-caller heuristic for sample PGO |
Dehao Chen | 3a986142 | 2017-07-07 20:53:10 +0000 | [diff] [blame] | 801 | // because it makes profile annotation in the backend inaccurate. |
| 802 | InlineParams IP = getInlineParamsFromOptLevel(Level); |
Rong Xu | db29a3a | 2019-03-04 20:21:27 +0000 | [diff] [blame] | 803 | if (Phase == ThinLTOPhase::PreLink && PGOOpt && |
| 804 | PGOOpt->Action == PGOOptions::SampleUse) |
Dehao Chen | 3a986142 | 2017-07-07 20:53:10 +0000 | [diff] [blame] | 805 | IP.HotCallSiteThreshold = 0; |
| 806 | MainCGPipeline.addPass(InlinerPass(IP)); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 807 | |
| 808 | // Now deduce any function attributes based in the current code. |
| 809 | MainCGPipeline.addPass(PostOrderFunctionAttrsPass()); |
| 810 | |
Chandler Carruth | 0ede22e | 2017-02-09 23:54:57 +0000 | [diff] [blame] | 811 | // When at O3 add argument promotion to the pass pipeline. |
| 812 | // FIXME: It isn't at all clear why this should be limited to O3. |
| 813 | if (Level == O3) |
| 814 | MainCGPipeline.addPass(ArgumentPromotionPass()); |
| 815 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 816 | // Lastly, add the core function simplification pipeline nested inside the |
| 817 | // CGSCC walk. |
| 818 | MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor( |
Dehao Chen | 95f0030 | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 819 | buildFunctionSimplificationPipeline(Level, Phase, DebugLogging))); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 820 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 821 | for (auto &C : CGSCCOptimizerLateEPCallbacks) |
| 822 | C(MainCGPipeline, Level); |
| 823 | |
Chandler Carruth | 719ffe1 | 2017-02-12 05:38:04 +0000 | [diff] [blame] | 824 | // We wrap the CGSCC pipeline in a devirtualization repeater. This will try |
| 825 | // to detect when we devirtualize indirect calls and iterate the SCC passes |
| 826 | // in that case to try and catch knock-on inlining or function attrs |
| 827 | // opportunities. Then we add it to the module pipeline by walking the SCCs |
| 828 | // in postorder (or bottom-up). |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 829 | MPM.addPass( |
Chandler Carruth | 719ffe1 | 2017-02-12 05:38:04 +0000 | [diff] [blame] | 830 | createModuleToPostOrderCGSCCPassAdaptor(createDevirtSCCRepeatedPass( |
Chandler Carruth | 19913b2 | 2017-08-11 05:47:13 +0000 | [diff] [blame] | 831 | std::move(MainCGPipeline), MaxDevirtIterations))); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 832 | |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 833 | return MPM; |
| 834 | } |
| 835 | |
Vedant Kumar | 47a0c9b | 2019-02-15 18:46:44 +0000 | [diff] [blame] | 836 | ModulePassManager PassBuilder::buildModuleOptimizationPipeline( |
| 837 | OptimizationLevel Level, bool DebugLogging, bool LTOPreLink) { |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 838 | ModulePassManager MPM(DebugLogging); |
| 839 | |
| 840 | // Optimize globals now that the module is fully simplified. |
| 841 | MPM.addPass(GlobalOptPass()); |
Davide Italiano | e070721 | 2017-10-05 18:36:01 +0000 | [diff] [blame] | 842 | MPM.addPass(GlobalDCEPass()); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 843 | |
Xinliang David Li | 126157c | 2017-05-22 16:41:57 +0000 | [diff] [blame] | 844 | // Run partial inlining pass to partially inline functions that have |
| 845 | // large bodies. |
| 846 | if (RunPartialInlining) |
| 847 | MPM.addPass(PartialInlinerPass()); |
| 848 | |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 849 | // Remove avail extern fns and globals definitions since we aren't compiling |
| 850 | // an object file for later LTO. For LTO we want to preserve these so they |
| 851 | // are eligible for inlining at link-time. Note if they are unreferenced they |
| 852 | // will be removed by GlobalDCE later, so this only impacts referenced |
| 853 | // available externally globals. Eventually they will be suppressed during |
| 854 | // codegen, but eliminating here enables more opportunity for GlobalDCE as it |
| 855 | // may make globals referenced by available external functions dead and saves |
Leonard Chan | 97dc622 | 2019-06-20 19:44:51 +0000 | [diff] [blame] | 856 | // running remaining passes on the eliminated functions. These should be |
| 857 | // preserved during prelinking for link-time inlining decisions. |
| 858 | if (!LTOPreLink) |
| 859 | MPM.addPass(EliminateAvailableExternallyPass()); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 860 | |
Manman Ren | 1829512 | 2019-02-28 20:13:38 +0000 | [diff] [blame] | 861 | if (EnableOrderFileInstrumentation) |
| 862 | MPM.addPass(InstrOrderFilePass()); |
| 863 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 864 | // Do RPO function attribute inference across the module to forward-propagate |
| 865 | // attributes where applicable. |
| 866 | // FIXME: Is this really an optimization rather than a canonicalization? |
| 867 | MPM.addPass(ReversePostOrderFunctionAttrsPass()); |
| 868 | |
Rong Xu | db29a3a | 2019-03-04 20:21:27 +0000 | [diff] [blame] | 869 | // Do a post inline PGO instrumentation and use pass. This is a context |
| 870 | // sensitive PGO pass. We don't want to do this in LTOPreLink phrase as |
| 871 | // cross-module inline has not been done yet. The context sensitive |
| 872 | // instrumentation is after all the inlines are done. |
| 873 | if (!LTOPreLink && PGOOpt) { |
| 874 | if (PGOOpt->CSAction == PGOOptions::CSIRInstr) |
| 875 | addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ true, |
| 876 | /* IsCS */ true, PGOOpt->CSProfileGenFile, |
| 877 | PGOOpt->ProfileRemappingFile); |
| 878 | else if (PGOOpt->CSAction == PGOOptions::CSIRUse) |
| 879 | addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ false, |
| 880 | /* IsCS */ true, PGOOpt->ProfileFile, |
| 881 | PGOOpt->ProfileRemappingFile); |
| 882 | } |
| 883 | |
Chandler Carruth | e87fc8c | 2017-02-12 05:34:04 +0000 | [diff] [blame] | 884 | // Re-require GloblasAA here prior to function passes. This is particularly |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 885 | // useful as the above will have inlined, DCE'ed, and function-attr |
| 886 | // propagated everything. We should at this point have a reasonably minimal |
| 887 | // and richly annotated call graph. By computing aliasing and mod/ref |
| 888 | // information for all local globals here, the late loop passes and notably |
| 889 | // the vectorizer will be able to use them to help recognize vectorizable |
| 890 | // memory operations. |
Chandler Carruth | e87fc8c | 2017-02-12 05:34:04 +0000 | [diff] [blame] | 891 | MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>()); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 892 | |
| 893 | FunctionPassManager OptimizePM(DebugLogging); |
| 894 | OptimizePM.addPass(Float2IntPass()); |
Joerg Sonnenberger | 9681ea9 | 2019-10-14 16:15:14 +0000 | [diff] [blame] | 895 | OptimizePM.addPass(LowerConstantIntrinsicsPass()); |
| 896 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 897 | // FIXME: We need to run some loop optimizations to re-rotate loops after |
| 898 | // simplify-cfg and others undo their rotation. |
| 899 | |
| 900 | // Optimize the loop execution. These passes operate on entire loop nests |
| 901 | // rather than on each loop in an inside-out manner, and so they are actually |
| 902 | // function passes. |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 903 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 904 | for (auto &C : VectorizerStartEPCallbacks) |
| 905 | C(OptimizePM, Level); |
| 906 | |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 907 | // First rotate loops that may have been un-rotated by prior passes. |
Alina Sbirlea | 7425179 | 2019-08-21 17:00:57 +0000 | [diff] [blame] | 908 | OptimizePM.addPass(createFunctionToLoopPassAdaptor( |
| 909 | LoopRotatePass(), EnableMSSALoopDependency, DebugLogging)); |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 910 | |
| 911 | // Distribute loops to allow partial vectorization. I.e. isolate dependences |
| 912 | // into separate loop that would otherwise inhibit vectorization. This is |
| 913 | // currently only performed for loops marked with the metadata |
| 914 | // llvm.loop.distribute=true or when -enable-loop-distribute is specified. |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 915 | OptimizePM.addPass(LoopDistributePass()); |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 916 | |
| 917 | // Now run the core loop vectorizer. |
Alina Sbirlea | 0499a2f | 2019-04-19 16:11:59 +0000 | [diff] [blame] | 918 | OptimizePM.addPass(LoopVectorizePass( |
| 919 | LoopVectorizeOptions(!PTO.LoopInterleaving, !PTO.LoopVectorization))); |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 920 | |
Chandler Carruth | baabda9 | 2017-01-27 01:32:26 +0000 | [diff] [blame] | 921 | // Eliminate loads by forwarding stores from the previous iteration to loads |
| 922 | // of the current iteration. |
| 923 | OptimizePM.addPass(LoopLoadEliminationPass()); |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 924 | |
| 925 | // Cleanup after the loop optimization passes. |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 926 | OptimizePM.addPass(InstCombinePass()); |
| 927 | |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 928 | // Now that we've formed fast to execute loop structures, we do further |
| 929 | // optimizations. These are run afterward as they might block doing complex |
| 930 | // analyses and transforms such as what are needed for loop vectorization. |
| 931 | |
Sanjay Patel | 0ab0c1a | 2017-12-14 22:05:20 +0000 | [diff] [blame] | 932 | // Cleanup after loop vectorization, etc. Simplification passes like CVP and |
| 933 | // GVN, loop transforms, and others have already run, so it's now better to |
| 934 | // convert to more optimized IR using more aggressive simplify CFG options. |
| 935 | // The extra sinking transform can create larger basic blocks, so do this |
| 936 | // before SLP vectorization. |
| 937 | OptimizePM.addPass(SimplifyCFGPass(SimplifyCFGOptions(). |
| 938 | forwardSwitchCondToPhi(true). |
| 939 | convertSwitchToLookupTable(true). |
| 940 | needCanonicalLoops(false). |
| 941 | sinkCommonInsts(true))); |
| 942 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 943 | // Optimize parallel scalar instruction chains into SIMD instructions. |
Alina Sbirlea | 458c733 | 2019-05-08 17:58:35 +0000 | [diff] [blame] | 944 | if (PTO.SLPVectorization) |
| 945 | OptimizePM.addPass(SLPVectorizerPass()); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 946 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 947 | OptimizePM.addPass(InstCombinePass()); |
| 948 | |
| 949 | // Unroll small loops to hide loop backedge latency and saturate any parallel |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 950 | // execution resources of an out-of-order processor. We also then need to |
| 951 | // clean up redundancies and loop invariant code. |
| 952 | // FIXME: It would be really good to use a loop-integrated instruction |
| 953 | // combiner for cleanup here so that the unrolling and LICM can be pipelined |
| 954 | // across the loop nests. |
David Green | 963401d | 2018-07-01 12:47:30 +0000 | [diff] [blame] | 955 | // We do UnrollAndJam in a separate LPM to ensure it happens before unroll |
Eric Christopher | c3649a0 | 2019-10-14 22:56:07 +0000 | [diff] [blame] | 956 | if (EnableUnrollAndJam && PTO.LoopUnrolling) { |
David Green | 963401d | 2018-07-01 12:47:30 +0000 | [diff] [blame] | 957 | OptimizePM.addPass( |
| 958 | createFunctionToLoopPassAdaptor(LoopUnrollAndJamPass(Level))); |
| 959 | } |
Eric Christopher | c3649a0 | 2019-10-14 22:56:07 +0000 | [diff] [blame] | 960 | OptimizePM.addPass(LoopUnrollPass( |
| 961 | LoopUnrollOptions(Level, /*OnlyWhenForced=*/!PTO.LoopUnrolling, |
| 962 | PTO.ForgetAllSCEVInLoopUnroll))); |
Michael Kruse | 7244852 | 2018-12-12 17:32:52 +0000 | [diff] [blame] | 963 | OptimizePM.addPass(WarnMissedTransformationsPass()); |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 964 | OptimizePM.addPass(InstCombinePass()); |
Chandler Carruth | 0ede22e | 2017-02-09 23:54:57 +0000 | [diff] [blame] | 965 | OptimizePM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>()); |
Alina Sbirlea | 43709f7 | 2019-04-19 17:46:50 +0000 | [diff] [blame] | 966 | OptimizePM.addPass(createFunctionToLoopPassAdaptor( |
| 967 | LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap), |
Alina Sbirlea | 7425179 | 2019-08-21 17:00:57 +0000 | [diff] [blame] | 968 | EnableMSSALoopDependency, DebugLogging)); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 969 | |
| 970 | // Now that we've vectorized and unrolled loops, we may have more refined |
| 971 | // alignment information, try to re-derive it here. |
| 972 | OptimizePM.addPass(AlignmentFromAssumptionsPass()); |
| 973 | |
Vedant Kumar | 47a0c9b | 2019-02-15 18:46:44 +0000 | [diff] [blame] | 974 | // Split out cold code. Splitting is done late to avoid hiding context from |
| 975 | // other optimizations and inadvertently regressing performance. The tradeoff |
| 976 | // is that this has a higher code size cost than splitting early. |
| 977 | if (EnableHotColdSplit && !LTOPreLink) |
| 978 | MPM.addPass(HotColdSplittingPass()); |
| 979 | |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 980 | // LoopSink pass sinks instructions hoisted by LICM, which serves as a |
| 981 | // canonicalization pass that enables other optimizations. As a result, |
| 982 | // LoopSink pass needs to be a very late IR pass to avoid undoing LICM |
| 983 | // result too early. |
| 984 | OptimizePM.addPass(LoopSinkPass()); |
| 985 | |
| 986 | // And finally clean up LCSSA form before generating code. |
Chandler Carruth | 7c557f8 | 2018-06-29 23:36:03 +0000 | [diff] [blame] | 987 | OptimizePM.addPass(InstSimplifyPass()); |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 988 | |
Sanjay Patel | 6fd4391 | 2017-09-09 13:38:18 +0000 | [diff] [blame] | 989 | // This hoists/decomposes div/rem ops. It should run after other sink/hoist |
| 990 | // passes to avoid re-sinking, but before SimplifyCFG because it can allow |
| 991 | // flattening of blocks. |
| 992 | OptimizePM.addPass(DivRemPairsPass()); |
| 993 | |
Filipe Cabecinhas | 92dc348 | 2017-04-26 12:02:41 +0000 | [diff] [blame] | 994 | // LoopSink (and other loop passes since the last simplifyCFG) might have |
| 995 | // resulted in single-entry-single-exit or empty blocks. Clean up the CFG. |
| 996 | OptimizePM.addPass(SimplifyCFGPass()); |
| 997 | |
Chandler Carruth | c34f789 | 2017-11-28 11:32:31 +0000 | [diff] [blame] | 998 | // Optimize PHIs by speculating around them when profitable. Note that this |
| 999 | // pass needs to be run after any PRE or similar pass as it is essentially |
Joerg Sonnenberger | ec6ee79 | 2019-05-16 18:01:57 +0000 | [diff] [blame] | 1000 | // inserting redundancies into the program. This even includes SimplifyCFG. |
Chandler Carruth | c34f789 | 2017-11-28 11:32:31 +0000 | [diff] [blame] | 1001 | OptimizePM.addPass(SpeculateAroundPHIsPass()); |
| 1002 | |
Philip Pfaffe | 2d4effb | 2018-11-12 11:17:07 +0000 | [diff] [blame] | 1003 | for (auto &C : OptimizerLastEPCallbacks) |
| 1004 | C(OptimizePM, Level); |
| 1005 | |
Chandler Carruth | a95ff38 | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 1006 | // Add the core optimizing pipeline. |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1007 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM))); |
| 1008 | |
Michael J. Spencer | 7bb2767 | 2018-07-16 00:28:24 +0000 | [diff] [blame] | 1009 | MPM.addPass(CGProfilePass()); |
| 1010 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1011 | // Now we need to do some global optimization transforms. |
| 1012 | // FIXME: It would seem like these should come first in the optimization |
| 1013 | // pipeline and maybe be the bottom of the canonicalization pipeline? Weird |
| 1014 | // ordering here. |
| 1015 | MPM.addPass(GlobalDCEPass()); |
| 1016 | MPM.addPass(ConstantMergePass()); |
| 1017 | |
| 1018 | return MPM; |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1021 | ModulePassManager |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1022 | PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level, |
Vedant Kumar | 47a0c9b | 2019-02-15 18:46:44 +0000 | [diff] [blame] | 1023 | bool DebugLogging, bool LTOPreLink) { |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1024 | assert(Level != O0 && "Must request optimizations for the default pipeline!"); |
| 1025 | |
| 1026 | ModulePassManager MPM(DebugLogging); |
| 1027 | |
| 1028 | // Force any function attributes we want the rest of the pipeline to observe. |
| 1029 | MPM.addPass(ForceFunctionAttrsPass()); |
| 1030 | |
David Blaikie | 0c64f5a | 2018-01-23 01:25:20 +0000 | [diff] [blame] | 1031 | // Apply module pipeline start EP callback. |
| 1032 | for (auto &C : PipelineStartEPCallbacks) |
| 1033 | C(MPM); |
| 1034 | |
Dehao Chen | 08f8831 | 2017-08-07 20:23:20 +0000 | [diff] [blame] | 1035 | if (PGOOpt && PGOOpt->SamplePGOSupport) |
Dehao Chen | ce0842c | 2017-07-29 04:10:24 +0000 | [diff] [blame] | 1036 | MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass())); |
| 1037 | |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1038 | // Add the core simplification pipeline. |
Dehao Chen | 95f0030 | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 1039 | MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::None, |
| 1040 | DebugLogging)); |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1041 | |
| 1042 | // Now add the optimization pipeline. |
Vedant Kumar | 47a0c9b | 2019-02-15 18:46:44 +0000 | [diff] [blame] | 1043 | MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging, LTOPreLink)); |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1044 | |
| 1045 | return MPM; |
| 1046 | } |
| 1047 | |
| 1048 | ModulePassManager |
| 1049 | PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level, |
| 1050 | bool DebugLogging) { |
| 1051 | assert(Level != O0 && "Must request optimizations for the default pipeline!"); |
| 1052 | |
| 1053 | ModulePassManager MPM(DebugLogging); |
| 1054 | |
| 1055 | // Force any function attributes we want the rest of the pipeline to observe. |
| 1056 | MPM.addPass(ForceFunctionAttrsPass()); |
| 1057 | |
Dehao Chen | 08f8831 | 2017-08-07 20:23:20 +0000 | [diff] [blame] | 1058 | if (PGOOpt && PGOOpt->SamplePGOSupport) |
Dehao Chen | ce0842c | 2017-07-29 04:10:24 +0000 | [diff] [blame] | 1059 | MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass())); |
| 1060 | |
David Blaikie | 0c64f5a | 2018-01-23 01:25:20 +0000 | [diff] [blame] | 1061 | // Apply module pipeline start EP callback. |
| 1062 | for (auto &C : PipelineStartEPCallbacks) |
| 1063 | C(MPM); |
| 1064 | |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1065 | // If we are planning to perform ThinLTO later, we don't bloat the code with |
| 1066 | // unrolling/vectorization/... now. Just simplify the module as much as we |
| 1067 | // can. |
Dehao Chen | 95f0030 | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 1068 | MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PreLink, |
| 1069 | DebugLogging)); |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1070 | |
| 1071 | // Run partial inlining pass to partially inline functions that have |
| 1072 | // large bodies. |
| 1073 | // FIXME: It isn't clear whether this is really the right place to run this |
| 1074 | // in ThinLTO. Because there is another canonicalization and simplification |
| 1075 | // phase that will run after the thin link, running this here ends up with |
| 1076 | // less information than will be available later and it may grow functions in |
| 1077 | // ways that aren't beneficial. |
| 1078 | if (RunPartialInlining) |
| 1079 | MPM.addPass(PartialInlinerPass()); |
| 1080 | |
| 1081 | // Reduce the size of the IR as much as possible. |
| 1082 | MPM.addPass(GlobalOptPass()); |
| 1083 | |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1084 | return MPM; |
| 1085 | } |
| 1086 | |
Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1087 | ModulePassManager PassBuilder::buildThinLTODefaultPipeline( |
| 1088 | OptimizationLevel Level, bool DebugLogging, |
| 1089 | const ModuleSummaryIndex *ImportSummary) { |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1090 | ModulePassManager MPM(DebugLogging); |
| 1091 | |
Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1092 | if (ImportSummary) { |
| 1093 | // These passes import type identifier resolutions for whole-program |
| 1094 | // devirtualization and CFI. They must run early because other passes may |
| 1095 | // disturb the specific instruction patterns that these passes look for, |
| 1096 | // creating dependencies on resolutions that may not appear in the summary. |
| 1097 | // |
| 1098 | // For example, GVN may transform the pattern assume(type.test) appearing in |
| 1099 | // two basic blocks into assume(phi(type.test, type.test)), which would |
| 1100 | // transform a dependency on a WPD resolution into a dependency on a type |
| 1101 | // identifier resolution for CFI. |
| 1102 | // |
| 1103 | // Also, WPD has access to more precise information than ICP and can |
| 1104 | // devirtualize more effectively, so it should operate on the IR first. |
Teresa Johnson | 867bc39 | 2019-04-23 18:56:19 +0000 | [diff] [blame] | 1105 | // |
| 1106 | // The WPD and LowerTypeTest passes need to run at -O0 to lower type |
| 1107 | // metadata and intrinsics. |
Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1108 | MPM.addPass(WholeProgramDevirtPass(nullptr, ImportSummary)); |
| 1109 | MPM.addPass(LowerTypeTestsPass(nullptr, ImportSummary)); |
| 1110 | } |
| 1111 | |
Teresa Johnson | 867bc39 | 2019-04-23 18:56:19 +0000 | [diff] [blame] | 1112 | if (Level == O0) |
| 1113 | return MPM; |
| 1114 | |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1115 | // Force any function attributes we want the rest of the pipeline to observe. |
| 1116 | MPM.addPass(ForceFunctionAttrsPass()); |
| 1117 | |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1118 | // Add the core simplification pipeline. |
Dehao Chen | 95f0030 | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 1119 | MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PostLink, |
| 1120 | DebugLogging)); |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1121 | |
| 1122 | // Now add the optimization pipeline. |
| 1123 | MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging)); |
| 1124 | |
| 1125 | return MPM; |
| 1126 | } |
| 1127 | |
| 1128 | ModulePassManager |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1129 | PassBuilder::buildLTOPreLinkDefaultPipeline(OptimizationLevel Level, |
| 1130 | bool DebugLogging) { |
| 1131 | assert(Level != O0 && "Must request optimizations for the default pipeline!"); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1132 | // FIXME: We should use a customized pre-link pipeline! |
Vedant Kumar | 47a0c9b | 2019-02-15 18:46:44 +0000 | [diff] [blame] | 1133 | return buildPerModuleDefaultPipeline(Level, DebugLogging, |
Rong Xu | db29a3a | 2019-03-04 20:21:27 +0000 | [diff] [blame] | 1134 | /* LTOPreLink */true); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1135 | } |
| 1136 | |
Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1137 | ModulePassManager |
| 1138 | PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level, bool DebugLogging, |
| 1139 | ModuleSummaryIndex *ExportSummary) { |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1140 | ModulePassManager MPM(DebugLogging); |
| 1141 | |
Teresa Johnson | 867bc39 | 2019-04-23 18:56:19 +0000 | [diff] [blame] | 1142 | if (Level == O0) { |
| 1143 | // The WPD and LowerTypeTest passes need to run at -O0 to lower type |
| 1144 | // metadata and intrinsics. |
| 1145 | MPM.addPass(WholeProgramDevirtPass(ExportSummary, nullptr)); |
| 1146 | MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr)); |
| 1147 | return MPM; |
| 1148 | } |
| 1149 | |
Rong Xu | db29a3a | 2019-03-04 20:21:27 +0000 | [diff] [blame] | 1150 | if (PGOOpt && PGOOpt->Action == PGOOptions::SampleUse) { |
Xin Tong | 642c8d3 | 2018-11-15 18:06:42 +0000 | [diff] [blame] | 1151 | // Load sample profile before running the LTO optimization pipeline. |
Rong Xu | db29a3a | 2019-03-04 20:21:27 +0000 | [diff] [blame] | 1152 | MPM.addPass(SampleProfileLoaderPass(PGOOpt->ProfileFile, |
Xin Tong | 642c8d3 | 2018-11-15 18:06:42 +0000 | [diff] [blame] | 1153 | PGOOpt->ProfileRemappingFile, |
| 1154 | false /* ThinLTOPhase::PreLink */)); |
Hiroshi Yamauchi | 09e539f | 2019-04-15 16:49:00 +0000 | [diff] [blame] | 1155 | // Cache ProfileSummaryAnalysis once to avoid the potential need to insert |
| 1156 | // RequireAnalysisPass for PSI before subsequent non-module passes. |
| 1157 | MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>()); |
Xin Tong | 642c8d3 | 2018-11-15 18:06:42 +0000 | [diff] [blame] | 1158 | } |
| 1159 | |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1160 | // Remove unused virtual tables to improve the quality of code generated by |
| 1161 | // whole-program devirtualization and bitset lowering. |
| 1162 | MPM.addPass(GlobalDCEPass()); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1163 | |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1164 | // Force any function attributes we want the rest of the pipeline to observe. |
| 1165 | MPM.addPass(ForceFunctionAttrsPass()); |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1166 | |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1167 | // Do basic inference of function attributes from known properties of system |
| 1168 | // libraries and other oracles. |
| 1169 | MPM.addPass(InferFunctionAttrsPass()); |
| 1170 | |
| 1171 | if (Level > 1) { |
Jun Bum Lim | 0c99007 | 2017-11-03 20:41:16 +0000 | [diff] [blame] | 1172 | FunctionPassManager EarlyFPM(DebugLogging); |
| 1173 | EarlyFPM.addPass(CallSiteSplittingPass()); |
| 1174 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM))); |
| 1175 | |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1176 | // Indirect call promotion. This should promote all the targets that are |
| 1177 | // left by the earlier promotion pass that promotes intra-module targets. |
| 1178 | // This two-step promotion is to save the compile time. For LTO, it should |
| 1179 | // produce the same result as if we only do promotion here. |
Dehao Chen | 2f31d0d | 2017-06-29 23:33:05 +0000 | [diff] [blame] | 1180 | MPM.addPass(PGOIndirectCallPromotion( |
Rong Xu | db29a3a | 2019-03-04 20:21:27 +0000 | [diff] [blame] | 1181 | true /* InLTO */, PGOOpt && PGOOpt->Action == PGOOptions::SampleUse)); |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1182 | // Propagate constants at call sites into the functions they call. This |
| 1183 | // opens opportunities for globalopt (and inlining) by substituting function |
| 1184 | // pointers passed as arguments to direct uses of functions. |
| 1185 | MPM.addPass(IPSCCPPass()); |
Matthew Simpson | cb58558 | 2017-10-25 13:40:08 +0000 | [diff] [blame] | 1186 | |
| 1187 | // Attach metadata to indirect call sites indicating the set of functions |
| 1188 | // they may target at run-time. This should follow IPSCCP. |
| 1189 | MPM.addPass(CalledValuePropagationPass()); |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | // Now deduce any function attributes based in the current code. |
| 1193 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor( |
| 1194 | PostOrderFunctionAttrsPass())); |
| 1195 | |
| 1196 | // Do RPO function attribute inference across the module to forward-propagate |
| 1197 | // attributes where applicable. |
| 1198 | // FIXME: Is this really an optimization rather than a canonicalization? |
| 1199 | MPM.addPass(ReversePostOrderFunctionAttrsPass()); |
| 1200 | |
Eric Christopher | 721eaef | 2019-02-26 20:33:22 +0000 | [diff] [blame] | 1201 | // Use in-range annotations on GEP indices to split globals where beneficial. |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1202 | MPM.addPass(GlobalSplitPass()); |
| 1203 | |
| 1204 | // Run whole program optimization of virtual call when the list of callees |
| 1205 | // is fixed. |
Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1206 | MPM.addPass(WholeProgramDevirtPass(ExportSummary, nullptr)); |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1207 | |
| 1208 | // Stop here at -O1. |
Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1209 | if (Level == 1) { |
| 1210 | // The LowerTypeTestsPass needs to run to lower type metadata and the |
| 1211 | // type.test intrinsics. The pass does nothing if CFI is disabled. |
| 1212 | MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr)); |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1213 | return MPM; |
Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1214 | } |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1215 | |
| 1216 | // Optimize globals to try and fold them into constants. |
| 1217 | MPM.addPass(GlobalOptPass()); |
| 1218 | |
| 1219 | // Promote any localized globals to SSA registers. |
| 1220 | MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass())); |
| 1221 | |
| 1222 | // Linking modules together can lead to duplicate global constant, only |
| 1223 | // keep one copy of each constant. |
| 1224 | MPM.addPass(ConstantMergePass()); |
| 1225 | |
| 1226 | // Remove unused arguments from functions. |
| 1227 | MPM.addPass(DeadArgumentEliminationPass()); |
| 1228 | |
| 1229 | // Reduce the code after globalopt and ipsccp. Both can open up significant |
| 1230 | // simplification opportunities, and both can propagate functions through |
| 1231 | // function pointers. When this happens, we often have to resolve varargs |
| 1232 | // calls, etc, so let instcombine do this. |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1233 | FunctionPassManager PeepholeFPM(DebugLogging); |
Amjad Aboud | f1f57a3 | 2018-01-25 12:06:32 +0000 | [diff] [blame] | 1234 | if (Level == O3) |
| 1235 | PeepholeFPM.addPass(AggressiveInstCombinePass()); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1236 | PeepholeFPM.addPass(InstCombinePass()); |
| 1237 | invokePeepholeEPCallbacks(PeepholeFPM, Level); |
| 1238 | |
| 1239 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(PeepholeFPM))); |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1240 | |
| 1241 | // Note: historically, the PruneEH pass was run first to deduce nounwind and |
| 1242 | // generally clean up exception handling overhead. It isn't clear this is |
| 1243 | // valuable as the inliner doesn't currently care whether it is inlining an |
| 1244 | // invoke or a call. |
| 1245 | // Run the inliner now. |
Easwaran Raman | 8249fac | 2017-06-28 13:33:49 +0000 | [diff] [blame] | 1246 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor( |
| 1247 | InlinerPass(getInlineParamsFromOptLevel(Level)))); |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1248 | |
| 1249 | // Optimize globals again after we ran the inliner. |
| 1250 | MPM.addPass(GlobalOptPass()); |
| 1251 | |
| 1252 | // Garbage collect dead functions. |
| 1253 | // FIXME: Add ArgumentPromotion pass after once it's ported. |
| 1254 | MPM.addPass(GlobalDCEPass()); |
| 1255 | |
| 1256 | FunctionPassManager FPM(DebugLogging); |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1257 | // The IPO Passes may leave cruft around. Clean up after them. |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1258 | FPM.addPass(InstCombinePass()); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1259 | invokePeepholeEPCallbacks(FPM, Level); |
| 1260 | |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1261 | FPM.addPass(JumpThreadingPass()); |
| 1262 | |
Rong Xu | db29a3a | 2019-03-04 20:21:27 +0000 | [diff] [blame] | 1263 | // Do a post inline PGO instrumentation and use pass. This is a context |
| 1264 | // sensitive PGO pass. |
| 1265 | if (PGOOpt) { |
| 1266 | if (PGOOpt->CSAction == PGOOptions::CSIRInstr) |
| 1267 | addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ true, |
| 1268 | /* IsCS */ true, PGOOpt->CSProfileGenFile, |
| 1269 | PGOOpt->ProfileRemappingFile); |
| 1270 | else if (PGOOpt->CSAction == PGOOptions::CSIRUse) |
| 1271 | addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ false, |
| 1272 | /* IsCS */ true, PGOOpt->ProfileFile, |
| 1273 | PGOOpt->ProfileRemappingFile); |
| 1274 | } |
| 1275 | |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1276 | // Break up allocas |
| 1277 | FPM.addPass(SROA()); |
| 1278 | |
Robert Lougher | f2158a8 | 2019-03-20 19:08:18 +0000 | [diff] [blame] | 1279 | // LTO provides additional opportunities for tailcall elimination due to |
| 1280 | // link-time inlining, and visibility of nocapture attribute. |
| 1281 | FPM.addPass(TailCallElimPass()); |
| 1282 | |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1283 | // Run a few AA driver optimizations here and now to cleanup the code. |
| 1284 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
| 1285 | |
| 1286 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor( |
| 1287 | PostOrderFunctionAttrsPass())); |
| 1288 | // FIXME: here we run IP alias analysis in the legacy PM. |
| 1289 | |
| 1290 | FunctionPassManager MainFPM; |
| 1291 | |
| 1292 | // FIXME: once we fix LoopPass Manager, add LICM here. |
| 1293 | // FIXME: once we provide support for enabling MLSM, add it here. |
Davide Italiano | 8a09b8e | 2017-05-22 23:41:40 +0000 | [diff] [blame] | 1294 | if (RunNewGVN) |
| 1295 | MainFPM.addPass(NewGVNPass()); |
| 1296 | else |
| 1297 | MainFPM.addPass(GVN()); |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1298 | |
| 1299 | // Remove dead memcpy()'s. |
| 1300 | MainFPM.addPass(MemCpyOptPass()); |
| 1301 | |
| 1302 | // Nuke dead stores. |
| 1303 | MainFPM.addPass(DSEPass()); |
| 1304 | |
| 1305 | // FIXME: at this point, we run a bunch of loop passes: |
Eric Christopher | 86e2f16 | 2019-05-03 00:15:23 +0000 | [diff] [blame] | 1306 | // indVarSimplify, loopDeletion, loopInterchange, loopUnroll, |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1307 | // loopVectorize. Enable them once the remaining issue with LPM |
| 1308 | // are sorted out. |
| 1309 | |
| 1310 | MainFPM.addPass(InstCombinePass()); |
| 1311 | MainFPM.addPass(SimplifyCFGPass()); |
| 1312 | MainFPM.addPass(SCCPPass()); |
| 1313 | MainFPM.addPass(InstCombinePass()); |
| 1314 | MainFPM.addPass(BDCEPass()); |
| 1315 | |
| 1316 | // FIXME: We may want to run SLPVectorizer here. |
| 1317 | // After vectorization, assume intrinsics may tell us more |
| 1318 | // about pointer alignments. |
| 1319 | #if 0 |
| 1320 | MainFPM.add(AlignmentFromAssumptionsPass()); |
| 1321 | #endif |
| 1322 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1323 | // FIXME: Conditionally run LoadCombine here, after it's ported |
| 1324 | // (in case we still have this pass, given its questionable usefulness). |
| 1325 | |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1326 | MainFPM.addPass(InstCombinePass()); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1327 | invokePeepholeEPCallbacks(MainFPM, Level); |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1328 | MainFPM.addPass(JumpThreadingPass()); |
| 1329 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(MainFPM))); |
| 1330 | |
| 1331 | // Create a function that performs CFI checks for cross-DSO calls with |
| 1332 | // targets in the current module. |
| 1333 | MPM.addPass(CrossDSOCFIPass()); |
| 1334 | |
| 1335 | // Lower type metadata and the type.test intrinsic. This pass supports |
| 1336 | // clang's control flow integrity mechanisms (-fsanitize=cfi*) and needs |
| 1337 | // to be run at link time if CFI is enabled. This pass does nothing if |
| 1338 | // CFI is disabled. |
Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1339 | MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr)); |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1340 | |
Vedant Kumar | 47a0c9b | 2019-02-15 18:46:44 +0000 | [diff] [blame] | 1341 | // Enable splitting late in the FullLTO post-link pipeline. This is done in |
| 1342 | // the same stage in the old pass manager (\ref addLateLTOOptimizationPasses). |
| 1343 | if (EnableHotColdSplit) |
| 1344 | MPM.addPass(HotColdSplittingPass()); |
| 1345 | |
Davide Italiano | 089a912 | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1346 | // Add late LTO optimization passes. |
| 1347 | // Delete basic blocks, which optimization passes may have killed. |
| 1348 | MPM.addPass(createModuleToFunctionPassAdaptor(SimplifyCFGPass())); |
| 1349 | |
| 1350 | // Drop bodies of available eternally objects to improve GlobalDCE. |
| 1351 | MPM.addPass(EliminateAvailableExternallyPass()); |
| 1352 | |
| 1353 | // Now that we have optimized the program, discard unreachable functions. |
| 1354 | MPM.addPass(GlobalDCEPass()); |
| 1355 | |
Eric Christopher | 86e2f16 | 2019-05-03 00:15:23 +0000 | [diff] [blame] | 1356 | // FIXME: Maybe enable MergeFuncs conditionally after it's ported. |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1357 | return MPM; |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1358 | } |
| 1359 | |
Chandler Carruth | 060ad61 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 1360 | AAManager PassBuilder::buildDefaultAAPipeline() { |
| 1361 | AAManager AA; |
| 1362 | |
| 1363 | // The order in which these are registered determines their priority when |
| 1364 | // being queried. |
| 1365 | |
| 1366 | // First we register the basic alias analysis that provides the majority of |
| 1367 | // per-function local AA logic. This is a stateless, on-demand local set of |
| 1368 | // AA techniques. |
| 1369 | AA.registerFunctionAnalysis<BasicAA>(); |
| 1370 | |
| 1371 | // Next we query fast, specialized alias analyses that wrap IR-embedded |
| 1372 | // information about aliasing. |
| 1373 | AA.registerFunctionAnalysis<ScopedNoAliasAA>(); |
| 1374 | AA.registerFunctionAnalysis<TypeBasedAA>(); |
| 1375 | |
| 1376 | // Add support for querying global aliasing information when available. |
Chandler Carruth | 534d644 | 2016-12-24 05:11:17 +0000 | [diff] [blame] | 1377 | // Because the `AAManager` is a function analysis and `GlobalsAA` is a module |
| 1378 | // analysis, all that the `AAManager` can do is query for any *cached* |
Chandler Carruth | e87fc8c | 2017-02-12 05:34:04 +0000 | [diff] [blame] | 1379 | // results from `GlobalsAA` through a readonly proxy. |
Chandler Carruth | 060ad61 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 1380 | AA.registerModuleAnalysis<GlobalsAA>(); |
Chandler Carruth | 060ad61 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 1381 | |
| 1382 | return AA; |
| 1383 | } |
| 1384 | |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1385 | static Optional<int> parseRepeatPassName(StringRef Name) { |
| 1386 | if (!Name.consume_front("repeat<") || !Name.consume_back(">")) |
| 1387 | return None; |
| 1388 | int Count; |
| 1389 | if (Name.getAsInteger(0, Count) || Count <= 0) |
| 1390 | return None; |
| 1391 | return Count; |
| 1392 | } |
| 1393 | |
Chandler Carruth | 05ca5ac | 2016-12-28 11:07:33 +0000 | [diff] [blame] | 1394 | static Optional<int> parseDevirtPassName(StringRef Name) { |
| 1395 | if (!Name.consume_front("devirt<") || !Name.consume_back(">")) |
| 1396 | return None; |
| 1397 | int Count; |
| 1398 | if (Name.getAsInteger(0, Count) || Count <= 0) |
| 1399 | return None; |
| 1400 | return Count; |
| 1401 | } |
| 1402 | |
Fedor Sergeev | b787140 | 2019-01-10 10:01:53 +0000 | [diff] [blame] | 1403 | static bool checkParametrizedPassName(StringRef Name, StringRef PassName) { |
| 1404 | if (!Name.consume_front(PassName)) |
| 1405 | return false; |
| 1406 | // normal pass name w/o parameters == default parameters |
| 1407 | if (Name.empty()) |
| 1408 | return true; |
| 1409 | return Name.startswith("<") && Name.endswith(">"); |
| 1410 | } |
| 1411 | |
| 1412 | namespace { |
| 1413 | |
| 1414 | /// This performs customized parsing of pass name with parameters. |
| 1415 | /// |
| 1416 | /// We do not need parametrization of passes in textual pipeline very often, |
| 1417 | /// yet on a rare occasion ability to specify parameters right there can be |
| 1418 | /// useful. |
| 1419 | /// |
| 1420 | /// \p Name - parameterized specification of a pass from a textual pipeline |
| 1421 | /// is a string in a form of : |
| 1422 | /// PassName '<' parameter-list '>' |
| 1423 | /// |
| 1424 | /// Parameter list is being parsed by the parser callable argument, \p Parser, |
| 1425 | /// It takes a string-ref of parameters and returns either StringError or a |
| 1426 | /// parameter list in a form of a custom parameters type, all wrapped into |
| 1427 | /// Expected<> template class. |
| 1428 | /// |
| 1429 | template <typename ParametersParseCallableT> |
| 1430 | auto parsePassParameters(ParametersParseCallableT &&Parser, StringRef Name, |
| 1431 | StringRef PassName) -> decltype(Parser(StringRef{})) { |
| 1432 | using ParametersT = typename decltype(Parser(StringRef{}))::value_type; |
| 1433 | |
| 1434 | StringRef Params = Name; |
| 1435 | if (!Params.consume_front(PassName)) { |
| 1436 | assert(false && |
| 1437 | "unable to strip pass name from parametrized pass specification"); |
| 1438 | } |
| 1439 | if (Params.empty()) |
| 1440 | return ParametersT{}; |
| 1441 | if (!Params.consume_front("<") || !Params.consume_back(">")) { |
| 1442 | assert(false && "invalid format for parametrized pass name"); |
| 1443 | } |
| 1444 | |
| 1445 | Expected<ParametersT> Result = Parser(Params); |
| 1446 | assert((Result || Result.template errorIsA<StringError>()) && |
| 1447 | "Pass parameter parser can only return StringErrors."); |
Saleem Abdulrasool | 418d1ea | 2019-10-27 18:29:58 -0400 | [diff] [blame] | 1448 | return Result; |
Fedor Sergeev | b787140 | 2019-01-10 10:01:53 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | /// Parser of parameters for LoopUnroll pass. |
| 1452 | Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) { |
| 1453 | LoopUnrollOptions UnrollOpts; |
| 1454 | while (!Params.empty()) { |
| 1455 | StringRef ParamName; |
| 1456 | std::tie(ParamName, Params) = Params.split(';'); |
| 1457 | int OptLevel = StringSwitch<int>(ParamName) |
| 1458 | .Case("O0", 0) |
| 1459 | .Case("O1", 1) |
| 1460 | .Case("O2", 2) |
| 1461 | .Case("O3", 3) |
| 1462 | .Default(-1); |
| 1463 | if (OptLevel >= 0) { |
| 1464 | UnrollOpts.setOptLevel(OptLevel); |
| 1465 | continue; |
| 1466 | } |
Serguei Katkov | a447688 | 2019-09-19 06:57:29 +0000 | [diff] [blame] | 1467 | if (ParamName.consume_front("full-unroll-max=")) { |
| 1468 | int Count; |
| 1469 | if (ParamName.getAsInteger(0, Count)) |
| 1470 | return make_error<StringError>( |
| 1471 | formatv("invalid LoopUnrollPass parameter '{0}' ", ParamName).str(), |
| 1472 | inconvertibleErrorCode()); |
| 1473 | UnrollOpts.setFullUnrollMaxCount(Count); |
| 1474 | continue; |
| 1475 | } |
Fedor Sergeev | b787140 | 2019-01-10 10:01:53 +0000 | [diff] [blame] | 1476 | |
| 1477 | bool Enable = !ParamName.consume_front("no-"); |
| 1478 | if (ParamName == "partial") { |
| 1479 | UnrollOpts.setPartial(Enable); |
| 1480 | } else if (ParamName == "peeling") { |
| 1481 | UnrollOpts.setPeeling(Enable); |
Serguei Katkov | de67aff | 2019-08-02 09:32:52 +0000 | [diff] [blame] | 1482 | } else if (ParamName == "profile-peeling") { |
| 1483 | UnrollOpts.setProfileBasedPeeling(Enable); |
Fedor Sergeev | b787140 | 2019-01-10 10:01:53 +0000 | [diff] [blame] | 1484 | } else if (ParamName == "runtime") { |
| 1485 | UnrollOpts.setRuntime(Enable); |
| 1486 | } else if (ParamName == "upperbound") { |
| 1487 | UnrollOpts.setUpperBound(Enable); |
| 1488 | } else { |
| 1489 | return make_error<StringError>( |
| 1490 | formatv("invalid LoopUnrollPass parameter '{0}' ", ParamName).str(), |
| 1491 | inconvertibleErrorCode()); |
| 1492 | } |
| 1493 | } |
| 1494 | return UnrollOpts; |
| 1495 | } |
| 1496 | |
Philip Pfaffe | 0ee6a93 | 2019-02-04 21:02:49 +0000 | [diff] [blame] | 1497 | Expected<MemorySanitizerOptions> parseMSanPassOptions(StringRef Params) { |
| 1498 | MemorySanitizerOptions Result; |
| 1499 | while (!Params.empty()) { |
| 1500 | StringRef ParamName; |
| 1501 | std::tie(ParamName, Params) = Params.split(';'); |
| 1502 | |
| 1503 | if (ParamName == "recover") { |
| 1504 | Result.Recover = true; |
| 1505 | } else if (ParamName == "kernel") { |
| 1506 | Result.Kernel = true; |
| 1507 | } else if (ParamName.consume_front("track-origins=")) { |
| 1508 | if (ParamName.getAsInteger(0, Result.TrackOrigins)) |
| 1509 | return make_error<StringError>( |
| 1510 | formatv("invalid argument to MemorySanitizer pass track-origins " |
| 1511 | "parameter: '{0}' ", |
| 1512 | ParamName) |
| 1513 | .str(), |
| 1514 | inconvertibleErrorCode()); |
| 1515 | } else { |
| 1516 | return make_error<StringError>( |
| 1517 | formatv("invalid MemorySanitizer pass parameter '{0}' ", ParamName) |
| 1518 | .str(), |
| 1519 | inconvertibleErrorCode()); |
| 1520 | } |
| 1521 | } |
| 1522 | return Result; |
| 1523 | } |
| 1524 | |
Serguei Katkov | f543283 | 2019-04-15 08:57:53 +0000 | [diff] [blame] | 1525 | /// Parser of parameters for SimplifyCFG pass. |
| 1526 | Expected<SimplifyCFGOptions> parseSimplifyCFGOptions(StringRef Params) { |
| 1527 | SimplifyCFGOptions Result; |
| 1528 | while (!Params.empty()) { |
| 1529 | StringRef ParamName; |
| 1530 | std::tie(ParamName, Params) = Params.split(';'); |
| 1531 | |
| 1532 | bool Enable = !ParamName.consume_front("no-"); |
| 1533 | if (ParamName == "forward-switch-cond") { |
| 1534 | Result.forwardSwitchCondToPhi(Enable); |
| 1535 | } else if (ParamName == "switch-to-lookup") { |
| 1536 | Result.convertSwitchToLookupTable(Enable); |
| 1537 | } else if (ParamName == "keep-loops") { |
| 1538 | Result.needCanonicalLoops(Enable); |
| 1539 | } else if (ParamName == "sink-common-insts") { |
| 1540 | Result.sinkCommonInsts(Enable); |
| 1541 | } else if (Enable && ParamName.consume_front("bonus-inst-threshold=")) { |
| 1542 | APInt BonusInstThreshold; |
| 1543 | if (ParamName.getAsInteger(0, BonusInstThreshold)) |
| 1544 | return make_error<StringError>( |
| 1545 | formatv("invalid argument to SimplifyCFG pass bonus-threshold " |
| 1546 | "parameter: '{0}' ", |
| 1547 | ParamName).str(), |
| 1548 | inconvertibleErrorCode()); |
| 1549 | Result.bonusInstThreshold(BonusInstThreshold.getSExtValue()); |
| 1550 | } else { |
| 1551 | return make_error<StringError>( |
| 1552 | formatv("invalid SimplifyCFG pass parameter '{0}' ", ParamName).str(), |
| 1553 | inconvertibleErrorCode()); |
| 1554 | } |
| 1555 | } |
| 1556 | return Result; |
| 1557 | } |
| 1558 | |
Serguei Katkov | ca6c03a | 2019-04-18 08:46:11 +0000 | [diff] [blame] | 1559 | /// Parser of parameters for LoopVectorize pass. |
| 1560 | Expected<LoopVectorizeOptions> parseLoopVectorizeOptions(StringRef Params) { |
| 1561 | LoopVectorizeOptions Opts; |
| 1562 | while (!Params.empty()) { |
| 1563 | StringRef ParamName; |
| 1564 | std::tie(ParamName, Params) = Params.split(';'); |
| 1565 | |
| 1566 | bool Enable = !ParamName.consume_front("no-"); |
| 1567 | if (ParamName == "interleave-forced-only") { |
| 1568 | Opts.setInterleaveOnlyWhenForced(Enable); |
| 1569 | } else if (ParamName == "vectorize-forced-only") { |
| 1570 | Opts.setVectorizeOnlyWhenForced(Enable); |
| 1571 | } else { |
| 1572 | return make_error<StringError>( |
| 1573 | formatv("invalid LoopVectorize parameter '{0}' ", ParamName).str(), |
| 1574 | inconvertibleErrorCode()); |
| 1575 | } |
| 1576 | } |
| 1577 | return Opts; |
| 1578 | } |
| 1579 | |
Serguei Katkov | 40a3b96 | 2019-04-22 10:35:07 +0000 | [diff] [blame] | 1580 | Expected<bool> parseLoopUnswitchOptions(StringRef Params) { |
| 1581 | bool Result = false; |
| 1582 | while (!Params.empty()) { |
| 1583 | StringRef ParamName; |
| 1584 | std::tie(ParamName, Params) = Params.split(';'); |
| 1585 | |
| 1586 | bool Enable = !ParamName.consume_front("no-"); |
| 1587 | if (ParamName == "nontrivial") { |
| 1588 | Result = Enable; |
| 1589 | } else { |
| 1590 | return make_error<StringError>( |
| 1591 | formatv("invalid LoopUnswitch pass parameter '{0}' ", ParamName) |
| 1592 | .str(), |
| 1593 | inconvertibleErrorCode()); |
| 1594 | } |
| 1595 | } |
| 1596 | return Result; |
| 1597 | } |
Denis Bakhvalov | 58f172f | 2019-09-05 17:00:32 +0000 | [diff] [blame] | 1598 | |
| 1599 | Expected<bool> parseMergedLoadStoreMotionOptions(StringRef Params) { |
| 1600 | bool Result = false; |
| 1601 | while (!Params.empty()) { |
| 1602 | StringRef ParamName; |
| 1603 | std::tie(ParamName, Params) = Params.split(';'); |
| 1604 | |
| 1605 | bool Enable = !ParamName.consume_front("no-"); |
| 1606 | if (ParamName == "split-footer-bb") { |
| 1607 | Result = Enable; |
| 1608 | } else { |
| 1609 | return make_error<StringError>( |
| 1610 | formatv("invalid MergedLoadStoreMotion pass parameter '{0}' ", |
| 1611 | ParamName) |
| 1612 | .str(), |
| 1613 | inconvertibleErrorCode()); |
| 1614 | } |
| 1615 | } |
| 1616 | return Result; |
| 1617 | } |
Fedor Sergeev | b787140 | 2019-01-10 10:01:53 +0000 | [diff] [blame] | 1618 | } // namespace |
| 1619 | |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1620 | /// Tests whether a pass name starts with a valid prefix for a default pipeline |
| 1621 | /// alias. |
| 1622 | static bool startsWithDefaultPipelineAliasPrefix(StringRef Name) { |
| 1623 | return Name.startswith("default") || Name.startswith("thinlto") || |
| 1624 | Name.startswith("lto"); |
| 1625 | } |
| 1626 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1627 | /// Tests whether registered callbacks will accept a given pass name. |
| 1628 | /// |
| 1629 | /// When parsing a pipeline text, the type of the outermost pipeline may be |
| 1630 | /// omitted, in which case the type is automatically determined from the first |
| 1631 | /// pass name in the text. This may be a name that is handled through one of the |
| 1632 | /// callbacks. We check this through the oridinary parsing callbacks by setting |
| 1633 | /// up a dummy PassManager in order to not force the client to also handle this |
| 1634 | /// type of query. |
| 1635 | template <typename PassManagerT, typename CallbacksT> |
| 1636 | static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) { |
| 1637 | if (!Callbacks.empty()) { |
| 1638 | PassManagerT DummyPM; |
| 1639 | for (auto &CB : Callbacks) |
| 1640 | if (CB(Name, DummyPM, {})) |
| 1641 | return true; |
| 1642 | } |
| 1643 | return false; |
| 1644 | } |
| 1645 | |
| 1646 | template <typename CallbacksT> |
| 1647 | static bool isModulePassName(StringRef Name, CallbacksT &Callbacks) { |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1648 | // Manually handle aliases for pre-configured pipeline fragments. |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1649 | if (startsWithDefaultPipelineAliasPrefix(Name)) |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1650 | return DefaultAliasRegex.match(Name); |
| 1651 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1652 | // Explicitly handle pass manager names. |
| 1653 | if (Name == "module") |
| 1654 | return true; |
| 1655 | if (Name == "cgscc") |
| 1656 | return true; |
| 1657 | if (Name == "function") |
| 1658 | return true; |
| 1659 | |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1660 | // Explicitly handle custom-parsed pass names. |
| 1661 | if (parseRepeatPassName(Name)) |
| 1662 | return true; |
| 1663 | |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 1664 | #define MODULE_PASS(NAME, CREATE_PASS) \ |
| 1665 | if (Name == NAME) \ |
| 1666 | return true; |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1667 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 1668 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1669 | return true; |
| 1670 | #include "PassRegistry.def" |
| 1671 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1672 | return callbacksAcceptPassName<ModulePassManager>(Name, Callbacks); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1675 | template <typename CallbacksT> |
| 1676 | static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1677 | // Explicitly handle pass manager names. |
| 1678 | if (Name == "cgscc") |
| 1679 | return true; |
| 1680 | if (Name == "function") |
| 1681 | return true; |
| 1682 | |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1683 | // Explicitly handle custom-parsed pass names. |
| 1684 | if (parseRepeatPassName(Name)) |
| 1685 | return true; |
Chandler Carruth | 05ca5ac | 2016-12-28 11:07:33 +0000 | [diff] [blame] | 1686 | if (parseDevirtPassName(Name)) |
| 1687 | return true; |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1688 | |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 1689 | #define CGSCC_PASS(NAME, CREATE_PASS) \ |
| 1690 | if (Name == NAME) \ |
| 1691 | return true; |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1692 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 1693 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1694 | return true; |
| 1695 | #include "PassRegistry.def" |
| 1696 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1697 | return callbacksAcceptPassName<CGSCCPassManager>(Name, Callbacks); |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1698 | } |
| 1699 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1700 | template <typename CallbacksT> |
| 1701 | static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1702 | // Explicitly handle pass manager names. |
| 1703 | if (Name == "function") |
| 1704 | return true; |
Alina Sbirlea | 7425179 | 2019-08-21 17:00:57 +0000 | [diff] [blame] | 1705 | if (Name == "loop" || Name == "loop-mssa") |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1706 | return true; |
| 1707 | |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1708 | // Explicitly handle custom-parsed pass names. |
| 1709 | if (parseRepeatPassName(Name)) |
| 1710 | return true; |
| 1711 | |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 1712 | #define FUNCTION_PASS(NAME, CREATE_PASS) \ |
| 1713 | if (Name == NAME) \ |
| 1714 | return true; |
Fedor Sergeev | b787140 | 2019-01-10 10:01:53 +0000 | [diff] [blame] | 1715 | #define FUNCTION_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \ |
| 1716 | if (checkParametrizedPassName(Name, NAME)) \ |
| 1717 | return true; |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1718 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 1719 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1720 | return true; |
| 1721 | #include "PassRegistry.def" |
| 1722 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1723 | return callbacksAcceptPassName<FunctionPassManager>(Name, Callbacks); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1726 | template <typename CallbacksT> |
| 1727 | static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1728 | // Explicitly handle pass manager names. |
Alina Sbirlea | 7425179 | 2019-08-21 17:00:57 +0000 | [diff] [blame] | 1729 | if (Name == "loop" || Name == "loop-mssa") |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1730 | return true; |
| 1731 | |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1732 | // Explicitly handle custom-parsed pass names. |
| 1733 | if (parseRepeatPassName(Name)) |
| 1734 | return true; |
| 1735 | |
Chandler Carruth | 74a8a22 | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 1736 | #define LOOP_PASS(NAME, CREATE_PASS) \ |
| 1737 | if (Name == NAME) \ |
| 1738 | return true; |
Serguei Katkov | 40a3b96 | 2019-04-22 10:35:07 +0000 | [diff] [blame] | 1739 | #define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \ |
| 1740 | if (checkParametrizedPassName(Name, NAME)) \ |
| 1741 | return true; |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1742 | #define LOOP_ANALYSIS(NAME, CREATE_PASS) \ |
| 1743 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
| 1744 | return true; |
| 1745 | #include "PassRegistry.def" |
| 1746 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1747 | return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks); |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1748 | } |
| 1749 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1750 | Optional<std::vector<PassBuilder::PipelineElement>> |
| 1751 | PassBuilder::parsePipelineText(StringRef Text) { |
| 1752 | std::vector<PipelineElement> ResultPipeline; |
| 1753 | |
| 1754 | SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = { |
| 1755 | &ResultPipeline}; |
| 1756 | for (;;) { |
| 1757 | std::vector<PipelineElement> &Pipeline = *PipelineStack.back(); |
| 1758 | size_t Pos = Text.find_first_of(",()"); |
| 1759 | Pipeline.push_back({Text.substr(0, Pos), {}}); |
| 1760 | |
| 1761 | // If we have a single terminating name, we're done. |
| 1762 | if (Pos == Text.npos) |
| 1763 | break; |
| 1764 | |
| 1765 | char Sep = Text[Pos]; |
| 1766 | Text = Text.substr(Pos + 1); |
| 1767 | if (Sep == ',') |
| 1768 | // Just a name ending in a comma, continue. |
| 1769 | continue; |
| 1770 | |
| 1771 | if (Sep == '(') { |
| 1772 | // Push the inner pipeline onto the stack to continue processing. |
| 1773 | PipelineStack.push_back(&Pipeline.back().InnerPipeline); |
| 1774 | continue; |
| 1775 | } |
| 1776 | |
| 1777 | assert(Sep == ')' && "Bogus separator!"); |
| 1778 | // When handling the close parenthesis, we greedily consume them to avoid |
| 1779 | // empty strings in the pipeline. |
| 1780 | do { |
| 1781 | // If we try to pop the outer pipeline we have unbalanced parentheses. |
| 1782 | if (PipelineStack.size() == 1) |
| 1783 | return None; |
| 1784 | |
| 1785 | PipelineStack.pop_back(); |
| 1786 | } while (Text.consume_front(")")); |
| 1787 | |
| 1788 | // Check if we've finished parsing. |
| 1789 | if (Text.empty()) |
| 1790 | break; |
| 1791 | |
| 1792 | // Otherwise, the end of an inner pipeline always has to be followed by |
| 1793 | // a comma, and then we can continue. |
| 1794 | if (!Text.consume_front(",")) |
| 1795 | return None; |
| 1796 | } |
| 1797 | |
| 1798 | if (PipelineStack.size() > 1) |
| 1799 | // Unbalanced paretheses. |
| 1800 | return None; |
| 1801 | |
| 1802 | assert(PipelineStack.back() == &ResultPipeline && |
| 1803 | "Wrong pipeline at the bottom of the stack!"); |
| 1804 | return {std::move(ResultPipeline)}; |
| 1805 | } |
| 1806 | |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1807 | Error PassBuilder::parseModulePass(ModulePassManager &MPM, |
| 1808 | const PipelineElement &E, |
| 1809 | bool VerifyEachPass, bool DebugLogging) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1810 | auto &Name = E.Name; |
| 1811 | auto &InnerPipeline = E.InnerPipeline; |
| 1812 | |
| 1813 | // First handle complex passes like the pass managers which carry pipelines. |
| 1814 | if (!InnerPipeline.empty()) { |
| 1815 | if (Name == "module") { |
| 1816 | ModulePassManager NestedMPM(DebugLogging); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1817 | if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline, |
| 1818 | VerifyEachPass, DebugLogging)) |
| 1819 | return Err; |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1820 | MPM.addPass(std::move(NestedMPM)); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1821 | return Error::success(); |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1822 | } |
| 1823 | if (Name == "cgscc") { |
| 1824 | CGSCCPassManager CGPM(DebugLogging); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1825 | if (auto Err = parseCGSCCPassPipeline(CGPM, InnerPipeline, VerifyEachPass, |
| 1826 | DebugLogging)) |
| 1827 | return Err; |
Chandler Carruth | 19913b2 | 2017-08-11 05:47:13 +0000 | [diff] [blame] | 1828 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM))); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1829 | return Error::success(); |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1830 | } |
| 1831 | if (Name == "function") { |
| 1832 | FunctionPassManager FPM(DebugLogging); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1833 | if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline, |
| 1834 | VerifyEachPass, DebugLogging)) |
| 1835 | return Err; |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1836 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1837 | return Error::success(); |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1838 | } |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1839 | if (auto Count = parseRepeatPassName(Name)) { |
| 1840 | ModulePassManager NestedMPM(DebugLogging); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1841 | if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline, |
| 1842 | VerifyEachPass, DebugLogging)) |
| 1843 | return Err; |
Chandler Carruth | a053a88 | 2016-08-04 03:52:53 +0000 | [diff] [blame] | 1844 | MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM))); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1845 | return Error::success(); |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1846 | } |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1847 | |
| 1848 | for (auto &C : ModulePipelineParsingCallbacks) |
| 1849 | if (C(Name, MPM, InnerPipeline)) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1850 | return Error::success(); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1851 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1852 | // Normal passes can't have pipelines. |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1853 | return make_error<StringError>( |
| 1854 | formatv("invalid use of '{0}' pass as module pipeline", Name).str(), |
| 1855 | inconvertibleErrorCode()); |
| 1856 | ; |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1857 | } |
| 1858 | |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1859 | // Manually handle aliases for pre-configured pipeline fragments. |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1860 | if (startsWithDefaultPipelineAliasPrefix(Name)) { |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1861 | SmallVector<StringRef, 3> Matches; |
| 1862 | if (!DefaultAliasRegex.match(Name, &Matches)) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1863 | return make_error<StringError>( |
| 1864 | formatv("unknown default pipeline alias '{0}'", Name).str(), |
| 1865 | inconvertibleErrorCode()); |
| 1866 | |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1867 | assert(Matches.size() == 3 && "Must capture two matched strings!"); |
| 1868 | |
Jordan Rose | f85a95f | 2016-07-25 18:34:51 +0000 | [diff] [blame] | 1869 | OptimizationLevel L = StringSwitch<OptimizationLevel>(Matches[2]) |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1870 | .Case("O0", O0) |
| 1871 | .Case("O1", O1) |
| 1872 | .Case("O2", O2) |
| 1873 | .Case("O3", O3) |
| 1874 | .Case("Os", Os) |
| 1875 | .Case("Oz", Oz); |
Rong Xu | ca161fa | 2019-08-01 22:36:34 +0000 | [diff] [blame] | 1876 | if (L == O0) { |
| 1877 | // Add instrumentation PGO passes -- at O0 we can still do PGO. |
| 1878 | if (PGOOpt && Matches[1] != "thinlto" && |
| 1879 | (PGOOpt->Action == PGOOptions::IRInstr || |
| 1880 | PGOOpt->Action == PGOOptions::IRUse)) |
| 1881 | addPGOInstrPassesForO0( |
| 1882 | MPM, DebugLogging, |
| 1883 | /* RunProfileGen */ (PGOOpt->Action == PGOOptions::IRInstr), |
| 1884 | /* IsCS */ false, PGOOpt->ProfileFile, |
| 1885 | PGOOpt->ProfileRemappingFile); |
| 1886 | // Do nothing else at all! |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1887 | return Error::success(); |
Rong Xu | ca161fa | 2019-08-01 22:36:34 +0000 | [diff] [blame] | 1888 | } |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1889 | |
| 1890 | if (Matches[1] == "default") { |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1891 | MPM.addPass(buildPerModuleDefaultPipeline(L, DebugLogging)); |
Chandler Carruth | 8b3be4e | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1892 | } else if (Matches[1] == "thinlto-pre-link") { |
| 1893 | MPM.addPass(buildThinLTOPreLinkDefaultPipeline(L, DebugLogging)); |
| 1894 | } else if (Matches[1] == "thinlto") { |
Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1895 | MPM.addPass(buildThinLTODefaultPipeline(L, DebugLogging, nullptr)); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1896 | } else if (Matches[1] == "lto-pre-link") { |
Chandler Carruth | e3f5064 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1897 | MPM.addPass(buildLTOPreLinkDefaultPipeline(L, DebugLogging)); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1898 | } else { |
| 1899 | assert(Matches[1] == "lto" && "Not one of the matched options!"); |
Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1900 | MPM.addPass(buildLTODefaultPipeline(L, DebugLogging, nullptr)); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1901 | } |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1902 | return Error::success(); |
Chandler Carruth | 8b5a7419 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1903 | } |
| 1904 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1905 | // Finally expand the basic registered passes from the .inc file. |
Chandler Carruth | 5894418 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 1906 | #define MODULE_PASS(NAME, CREATE_PASS) \ |
| 1907 | if (Name == NAME) { \ |
| 1908 | MPM.addPass(CREATE_PASS); \ |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1909 | return Error::success(); \ |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 1910 | } |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1911 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
| 1912 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | 9b35e6d | 2016-08-19 18:36:06 +0000 | [diff] [blame] | 1913 | MPM.addPass( \ |
| 1914 | RequireAnalysisPass< \ |
| 1915 | std::remove_reference<decltype(CREATE_PASS)>::type, Module>()); \ |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1916 | return Error::success(); \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 1917 | } \ |
| 1918 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 1919 | MPM.addPass(InvalidateAnalysisPass< \ |
| 1920 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1921 | return Error::success(); \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1922 | } |
| 1923 | #include "PassRegistry.def" |
| 1924 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1925 | for (auto &C : ModulePipelineParsingCallbacks) |
| 1926 | if (C(Name, MPM, InnerPipeline)) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1927 | return Error::success(); |
| 1928 | return make_error<StringError>( |
| 1929 | formatv("unknown module pass '{0}'", Name).str(), |
| 1930 | inconvertibleErrorCode()); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1931 | } |
| 1932 | |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1933 | Error PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM, |
| 1934 | const PipelineElement &E, bool VerifyEachPass, |
| 1935 | bool DebugLogging) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1936 | auto &Name = E.Name; |
| 1937 | auto &InnerPipeline = E.InnerPipeline; |
| 1938 | |
| 1939 | // First handle complex passes like the pass managers which carry pipelines. |
| 1940 | if (!InnerPipeline.empty()) { |
| 1941 | if (Name == "cgscc") { |
| 1942 | CGSCCPassManager NestedCGPM(DebugLogging); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1943 | if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, |
| 1944 | VerifyEachPass, DebugLogging)) |
| 1945 | return Err; |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1946 | // Add the nested pass manager with the appropriate adaptor. |
| 1947 | CGPM.addPass(std::move(NestedCGPM)); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1948 | return Error::success(); |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1949 | } |
| 1950 | if (Name == "function") { |
| 1951 | FunctionPassManager FPM(DebugLogging); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1952 | if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline, |
| 1953 | VerifyEachPass, DebugLogging)) |
| 1954 | return Err; |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1955 | // Add the nested pass manager with the appropriate adaptor. |
Chandler Carruth | 19913b2 | 2017-08-11 05:47:13 +0000 | [diff] [blame] | 1956 | CGPM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM))); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1957 | return Error::success(); |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1958 | } |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1959 | if (auto Count = parseRepeatPassName(Name)) { |
| 1960 | CGSCCPassManager NestedCGPM(DebugLogging); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1961 | if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, |
| 1962 | VerifyEachPass, DebugLogging)) |
| 1963 | return Err; |
Chandler Carruth | a053a88 | 2016-08-04 03:52:53 +0000 | [diff] [blame] | 1964 | CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM))); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1965 | return Error::success(); |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1966 | } |
Chandler Carruth | 05ca5ac | 2016-12-28 11:07:33 +0000 | [diff] [blame] | 1967 | if (auto MaxRepetitions = parseDevirtPassName(Name)) { |
| 1968 | CGSCCPassManager NestedCGPM(DebugLogging); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1969 | if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, |
| 1970 | VerifyEachPass, DebugLogging)) |
| 1971 | return Err; |
Chandler Carruth | 19913b2 | 2017-08-11 05:47:13 +0000 | [diff] [blame] | 1972 | CGPM.addPass( |
| 1973 | createDevirtSCCRepeatedPass(std::move(NestedCGPM), *MaxRepetitions)); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1974 | return Error::success(); |
Chandler Carruth | 05ca5ac | 2016-12-28 11:07:33 +0000 | [diff] [blame] | 1975 | } |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1976 | |
| 1977 | for (auto &C : CGSCCPipelineParsingCallbacks) |
| 1978 | if (C(Name, CGPM, InnerPipeline)) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1979 | return Error::success(); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1980 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1981 | // Normal passes can't have pipelines. |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1982 | return make_error<StringError>( |
| 1983 | formatv("invalid use of '{0}' pass as cgscc pipeline", Name).str(), |
| 1984 | inconvertibleErrorCode()); |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1985 | } |
| 1986 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1987 | // Now expand the basic registered passes from the .inc file. |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1988 | #define CGSCC_PASS(NAME, CREATE_PASS) \ |
| 1989 | if (Name == NAME) { \ |
| 1990 | CGPM.addPass(CREATE_PASS); \ |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1991 | return Error::success(); \ |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1992 | } |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1993 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
| 1994 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 1995 | CGPM.addPass(RequireAnalysisPass< \ |
Chandler Carruth | 9b35e6d | 2016-08-19 18:36:06 +0000 | [diff] [blame] | 1996 | std::remove_reference<decltype(CREATE_PASS)>::type, \ |
Chandler Carruth | 8882346 | 2016-08-24 09:37:14 +0000 | [diff] [blame] | 1997 | LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \ |
| 1998 | CGSCCUpdateResult &>()); \ |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1999 | return Error::success(); \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 2000 | } \ |
| 2001 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 2002 | CGPM.addPass(InvalidateAnalysisPass< \ |
| 2003 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2004 | return Error::success(); \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 2005 | } |
| 2006 | #include "PassRegistry.def" |
| 2007 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2008 | for (auto &C : CGSCCPipelineParsingCallbacks) |
| 2009 | if (C(Name, CGPM, InnerPipeline)) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2010 | return Error::success(); |
| 2011 | return make_error<StringError>( |
| 2012 | formatv("unknown cgscc pass '{0}'", Name).str(), |
| 2013 | inconvertibleErrorCode()); |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2016 | Error PassBuilder::parseFunctionPass(FunctionPassManager &FPM, |
| 2017 | const PipelineElement &E, |
| 2018 | bool VerifyEachPass, bool DebugLogging) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2019 | auto &Name = E.Name; |
| 2020 | auto &InnerPipeline = E.InnerPipeline; |
| 2021 | |
| 2022 | // First handle complex passes like the pass managers which carry pipelines. |
| 2023 | if (!InnerPipeline.empty()) { |
| 2024 | if (Name == "function") { |
| 2025 | FunctionPassManager NestedFPM(DebugLogging); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2026 | if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline, |
| 2027 | VerifyEachPass, DebugLogging)) |
| 2028 | return Err; |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2029 | // Add the nested pass manager with the appropriate adaptor. |
| 2030 | FPM.addPass(std::move(NestedFPM)); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2031 | return Error::success(); |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2032 | } |
Alina Sbirlea | 7425179 | 2019-08-21 17:00:57 +0000 | [diff] [blame] | 2033 | if (Name == "loop" || Name == "loop-mssa") { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2034 | LoopPassManager LPM(DebugLogging); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2035 | if (auto Err = parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass, |
| 2036 | DebugLogging)) |
| 2037 | return Err; |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2038 | // Add the nested pass manager with the appropriate adaptor. |
Alina Sbirlea | 7425179 | 2019-08-21 17:00:57 +0000 | [diff] [blame] | 2039 | bool UseMemorySSA = (Name == "loop-mssa"); |
| 2040 | FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM), UseMemorySSA, |
| 2041 | DebugLogging)); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2042 | return Error::success(); |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2043 | } |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 2044 | if (auto Count = parseRepeatPassName(Name)) { |
| 2045 | FunctionPassManager NestedFPM(DebugLogging); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2046 | if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline, |
| 2047 | VerifyEachPass, DebugLogging)) |
| 2048 | return Err; |
Chandler Carruth | a053a88 | 2016-08-04 03:52:53 +0000 | [diff] [blame] | 2049 | FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM))); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2050 | return Error::success(); |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 2051 | } |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2052 | |
| 2053 | for (auto &C : FunctionPipelineParsingCallbacks) |
| 2054 | if (C(Name, FPM, InnerPipeline)) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2055 | return Error::success(); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2056 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2057 | // Normal passes can't have pipelines. |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2058 | return make_error<StringError>( |
| 2059 | formatv("invalid use of '{0}' pass as function pipeline", Name).str(), |
| 2060 | inconvertibleErrorCode()); |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2063 | // Now expand the basic registered passes from the .inc file. |
Chandler Carruth | 5894418 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 2064 | #define FUNCTION_PASS(NAME, CREATE_PASS) \ |
| 2065 | if (Name == NAME) { \ |
| 2066 | FPM.addPass(CREATE_PASS); \ |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2067 | return Error::success(); \ |
Chandler Carruth | 52eef88 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 2068 | } |
Fedor Sergeev | b787140 | 2019-01-10 10:01:53 +0000 | [diff] [blame] | 2069 | #define FUNCTION_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \ |
| 2070 | if (checkParametrizedPassName(Name, NAME)) { \ |
| 2071 | auto Params = parsePassParameters(PARSER, Name, NAME); \ |
| 2072 | if (!Params) \ |
| 2073 | return Params.takeError(); \ |
| 2074 | FPM.addPass(CREATE_PASS(Params.get())); \ |
| 2075 | return Error::success(); \ |
| 2076 | } |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 2077 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
| 2078 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | 9b35e6d | 2016-08-19 18:36:06 +0000 | [diff] [blame] | 2079 | FPM.addPass( \ |
| 2080 | RequireAnalysisPass< \ |
| 2081 | std::remove_reference<decltype(CREATE_PASS)>::type, Function>()); \ |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2082 | return Error::success(); \ |
Chandler Carruth | 3472ffb | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 2083 | } \ |
| 2084 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 2085 | FPM.addPass(InvalidateAnalysisPass< \ |
| 2086 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2087 | return Error::success(); \ |
Chandler Carruth | 628503e | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 2088 | } |
| 2089 | #include "PassRegistry.def" |
| 2090 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2091 | for (auto &C : FunctionPipelineParsingCallbacks) |
| 2092 | if (C(Name, FPM, InnerPipeline)) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2093 | return Error::success(); |
| 2094 | return make_error<StringError>( |
| 2095 | formatv("unknown function pass '{0}'", Name).str(), |
| 2096 | inconvertibleErrorCode()); |
Chandler Carruth | d833098 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 2097 | } |
| 2098 | |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2099 | Error PassBuilder::parseLoopPass(LoopPassManager &LPM, const PipelineElement &E, |
| 2100 | bool VerifyEachPass, bool DebugLogging) { |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 2101 | StringRef Name = E.Name; |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2102 | auto &InnerPipeline = E.InnerPipeline; |
| 2103 | |
| 2104 | // First handle complex passes like the pass managers which carry pipelines. |
| 2105 | if (!InnerPipeline.empty()) { |
| 2106 | if (Name == "loop") { |
| 2107 | LoopPassManager NestedLPM(DebugLogging); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2108 | if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline, |
| 2109 | VerifyEachPass, DebugLogging)) |
| 2110 | return Err; |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2111 | // Add the nested pass manager with the appropriate adaptor. |
Chandler Carruth | fdc6ba1 | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 2112 | LPM.addPass(std::move(NestedLPM)); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2113 | return Error::success(); |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2114 | } |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 2115 | if (auto Count = parseRepeatPassName(Name)) { |
| 2116 | LoopPassManager NestedLPM(DebugLogging); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2117 | if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline, |
| 2118 | VerifyEachPass, DebugLogging)) |
| 2119 | return Err; |
Chandler Carruth | a053a88 | 2016-08-04 03:52:53 +0000 | [diff] [blame] | 2120 | LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM))); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2121 | return Error::success(); |
Chandler Carruth | 241bf24 | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 2122 | } |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2123 | |
| 2124 | for (auto &C : LoopPipelineParsingCallbacks) |
| 2125 | if (C(Name, LPM, InnerPipeline)) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2126 | return Error::success(); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2127 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2128 | // Normal passes can't have pipelines. |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2129 | return make_error<StringError>( |
| 2130 | formatv("invalid use of '{0}' pass as loop pipeline", Name).str(), |
| 2131 | inconvertibleErrorCode()); |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2132 | } |
| 2133 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2134 | // Now expand the basic registered passes from the .inc file. |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 2135 | #define LOOP_PASS(NAME, CREATE_PASS) \ |
| 2136 | if (Name == NAME) { \ |
Chandler Carruth | fdc6ba1 | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 2137 | LPM.addPass(CREATE_PASS); \ |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2138 | return Error::success(); \ |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 2139 | } |
Serguei Katkov | 40a3b96 | 2019-04-22 10:35:07 +0000 | [diff] [blame] | 2140 | #define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \ |
| 2141 | if (checkParametrizedPassName(Name, NAME)) { \ |
| 2142 | auto Params = parsePassParameters(PARSER, Name, NAME); \ |
| 2143 | if (!Params) \ |
| 2144 | return Params.takeError(); \ |
| 2145 | LPM.addPass(CREATE_PASS(Params.get())); \ |
| 2146 | return Error::success(); \ |
| 2147 | } |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 2148 | #define LOOP_ANALYSIS(NAME, CREATE_PASS) \ |
| 2149 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | fdc6ba1 | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 2150 | LPM.addPass(RequireAnalysisPass< \ |
Chandler Carruth | 410eaeb | 2017-01-11 06:23:21 +0000 | [diff] [blame] | 2151 | std::remove_reference<decltype(CREATE_PASS)>::type, Loop, \ |
| 2152 | LoopAnalysisManager, LoopStandardAnalysisResults &, \ |
| 2153 | LPMUpdater &>()); \ |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2154 | return Error::success(); \ |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 2155 | } \ |
| 2156 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | fdc6ba1 | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 2157 | LPM.addPass(InvalidateAnalysisPass< \ |
Chandler Carruth | 470734b | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 2158 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2159 | return Error::success(); \ |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 2160 | } |
| 2161 | #include "PassRegistry.def" |
| 2162 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2163 | for (auto &C : LoopPipelineParsingCallbacks) |
| 2164 | if (C(Name, LPM, InnerPipeline)) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2165 | return Error::success(); |
| 2166 | return make_error<StringError>(formatv("unknown loop pass '{0}'", Name).str(), |
| 2167 | inconvertibleErrorCode()); |
Justin Bogner | eecc3c8 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 2168 | } |
| 2169 | |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 2170 | bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) { |
Chandler Carruth | 45a9c20 | 2016-03-11 09:15:11 +0000 | [diff] [blame] | 2171 | #define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \ |
| 2172 | if (Name == NAME) { \ |
| 2173 | AA.registerModuleAnalysis< \ |
| 2174 | std::remove_reference<decltype(CREATE_PASS)>::type>(); \ |
| 2175 | return true; \ |
| 2176 | } |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 2177 | #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \ |
| 2178 | if (Name == NAME) { \ |
Chandler Carruth | 58dde8c | 2016-02-26 12:17:54 +0000 | [diff] [blame] | 2179 | AA.registerFunctionAnalysis< \ |
| 2180 | std::remove_reference<decltype(CREATE_PASS)>::type>(); \ |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 2181 | return true; \ |
| 2182 | } |
| 2183 | #include "PassRegistry.def" |
| 2184 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2185 | for (auto &C : AAParsingCallbacks) |
| 2186 | if (C(Name, AA)) |
| 2187 | return true; |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 2188 | return false; |
| 2189 | } |
| 2190 | |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2191 | Error PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM, |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2192 | ArrayRef<PipelineElement> Pipeline, |
Chandler Carruth | 1ff7724 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 2193 | bool VerifyEachPass, |
| 2194 | bool DebugLogging) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2195 | for (const auto &Element : Pipeline) { |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2196 | if (auto Err = parseLoopPass(LPM, Element, VerifyEachPass, DebugLogging)) |
| 2197 | return Err; |
| 2198 | // FIXME: No verifier support for Loop passes! |
| 2199 | } |
| 2200 | return Error::success(); |
| 2201 | } |
| 2202 | |
| 2203 | Error PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM, |
| 2204 | ArrayRef<PipelineElement> Pipeline, |
| 2205 | bool VerifyEachPass, |
| 2206 | bool DebugLogging) { |
| 2207 | for (const auto &Element : Pipeline) { |
| 2208 | if (auto Err = |
| 2209 | parseFunctionPass(FPM, Element, VerifyEachPass, DebugLogging)) |
| 2210 | return Err; |
| 2211 | if (VerifyEachPass) |
| 2212 | FPM.addPass(VerifierPass()); |
| 2213 | } |
| 2214 | return Error::success(); |
| 2215 | } |
| 2216 | |
| 2217 | Error PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM, |
| 2218 | ArrayRef<PipelineElement> Pipeline, |
| 2219 | bool VerifyEachPass, |
| 2220 | bool DebugLogging) { |
| 2221 | for (const auto &Element : Pipeline) { |
| 2222 | if (auto Err = parseCGSCCPass(CGPM, Element, VerifyEachPass, DebugLogging)) |
| 2223 | return Err; |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2224 | // FIXME: No verifier support for CGSCC passes! |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 2225 | } |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2226 | return Error::success(); |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 2227 | } |
| 2228 | |
NAKAMURA Takumi | a42f528 | 2016-05-16 10:13:37 +0000 | [diff] [blame] | 2229 | void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM, |
| 2230 | FunctionAnalysisManager &FAM, |
| 2231 | CGSCCAnalysisManager &CGAM, |
| 2232 | ModuleAnalysisManager &MAM) { |
| 2233 | MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); }); |
| 2234 | MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); }); |
NAKAMURA Takumi | a42f528 | 2016-05-16 10:13:37 +0000 | [diff] [blame] | 2235 | CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); }); |
| 2236 | FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); }); |
| 2237 | FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); }); |
| 2238 | FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); }); |
| 2239 | LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); }); |
| 2240 | } |
| 2241 | |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2242 | Error PassBuilder::parseModulePassPipeline(ModulePassManager &MPM, |
| 2243 | ArrayRef<PipelineElement> Pipeline, |
| 2244 | bool VerifyEachPass, |
| 2245 | bool DebugLogging) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2246 | for (const auto &Element : Pipeline) { |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2247 | if (auto Err = parseModulePass(MPM, Element, VerifyEachPass, DebugLogging)) |
| 2248 | return Err; |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2249 | if (VerifyEachPass) |
| 2250 | MPM.addPass(VerifierPass()); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 2251 | } |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2252 | return Error::success(); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 2253 | } |
| 2254 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2255 | // Primary pass pipeline description parsing routine for a \c ModulePassManager |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 2256 | // FIXME: Should this routine accept a TargetMachine or require the caller to |
| 2257 | // pre-populate the analysis managers with target-specific stuff? |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2258 | Error PassBuilder::parsePassPipeline(ModulePassManager &MPM, |
| 2259 | StringRef PipelineText, |
| 2260 | bool VerifyEachPass, bool DebugLogging) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2261 | auto Pipeline = parsePipelineText(PipelineText); |
| 2262 | if (!Pipeline || Pipeline->empty()) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2263 | return make_error<StringError>( |
| 2264 | formatv("invalid pipeline '{0}'", PipelineText).str(), |
| 2265 | inconvertibleErrorCode()); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 2266 | |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2267 | // If the first name isn't at the module layer, wrap the pipeline up |
| 2268 | // automatically. |
| 2269 | StringRef FirstName = Pipeline->front().Name; |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 2270 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2271 | if (!isModulePassName(FirstName, ModulePipelineParsingCallbacks)) { |
| 2272 | if (isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks)) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2273 | Pipeline = {{"cgscc", std::move(*Pipeline)}}; |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2274 | } else if (isFunctionPassName(FirstName, |
| 2275 | FunctionPipelineParsingCallbacks)) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2276 | Pipeline = {{"function", std::move(*Pipeline)}}; |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2277 | } else if (isLoopPassName(FirstName, LoopPipelineParsingCallbacks)) { |
Chandler Carruth | 6cb2ab2 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 2278 | Pipeline = {{"function", {{"loop", std::move(*Pipeline)}}}}; |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2279 | } else { |
| 2280 | for (auto &C : TopLevelPipelineParsingCallbacks) |
| 2281 | if (C(MPM, *Pipeline, VerifyEachPass, DebugLogging)) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2282 | return Error::success(); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2283 | |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2284 | // Unknown pass or pipeline name! |
| 2285 | auto &InnerPipeline = Pipeline->front().InnerPipeline; |
| 2286 | return make_error<StringError>( |
| 2287 | formatv("unknown {0} name '{1}'", |
| 2288 | (InnerPipeline.empty() ? "pass" : "pipeline"), FirstName) |
| 2289 | .str(), |
| 2290 | inconvertibleErrorCode()); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2291 | } |
Chandler Carruth | 572e340 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 2292 | } |
| 2293 | |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2294 | if (auto Err = |
| 2295 | parseModulePassPipeline(MPM, *Pipeline, VerifyEachPass, DebugLogging)) |
| 2296 | return Err; |
| 2297 | return Error::success(); |
Chandler Carruth | 6644538 | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 2298 | } |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 2299 | |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2300 | // Primary pass pipeline description parsing routine for a \c CGSCCPassManager |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2301 | Error PassBuilder::parsePassPipeline(CGSCCPassManager &CGPM, |
| 2302 | StringRef PipelineText, |
| 2303 | bool VerifyEachPass, bool DebugLogging) { |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2304 | auto Pipeline = parsePipelineText(PipelineText); |
| 2305 | if (!Pipeline || Pipeline->empty()) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2306 | return make_error<StringError>( |
| 2307 | formatv("invalid pipeline '{0}'", PipelineText).str(), |
| 2308 | inconvertibleErrorCode()); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2309 | |
| 2310 | StringRef FirstName = Pipeline->front().Name; |
| 2311 | if (!isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks)) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2312 | return make_error<StringError>( |
| 2313 | formatv("unknown cgscc pass '{0}' in pipeline '{1}'", FirstName, |
| 2314 | PipelineText) |
| 2315 | .str(), |
| 2316 | inconvertibleErrorCode()); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2317 | |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2318 | if (auto Err = |
| 2319 | parseCGSCCPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging)) |
| 2320 | return Err; |
| 2321 | return Error::success(); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2322 | } |
| 2323 | |
| 2324 | // Primary pass pipeline description parsing routine for a \c |
| 2325 | // FunctionPassManager |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2326 | Error PassBuilder::parsePassPipeline(FunctionPassManager &FPM, |
| 2327 | StringRef PipelineText, |
| 2328 | bool VerifyEachPass, bool DebugLogging) { |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2329 | auto Pipeline = parsePipelineText(PipelineText); |
| 2330 | if (!Pipeline || Pipeline->empty()) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2331 | return make_error<StringError>( |
| 2332 | formatv("invalid pipeline '{0}'", PipelineText).str(), |
| 2333 | inconvertibleErrorCode()); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2334 | |
| 2335 | StringRef FirstName = Pipeline->front().Name; |
| 2336 | if (!isFunctionPassName(FirstName, FunctionPipelineParsingCallbacks)) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2337 | return make_error<StringError>( |
| 2338 | formatv("unknown function pass '{0}' in pipeline '{1}'", FirstName, |
| 2339 | PipelineText) |
| 2340 | .str(), |
| 2341 | inconvertibleErrorCode()); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2342 | |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2343 | if (auto Err = parseFunctionPassPipeline(FPM, *Pipeline, VerifyEachPass, |
| 2344 | DebugLogging)) |
| 2345 | return Err; |
| 2346 | return Error::success(); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | // Primary pass pipeline description parsing routine for a \c LoopPassManager |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2350 | Error PassBuilder::parsePassPipeline(LoopPassManager &CGPM, |
| 2351 | StringRef PipelineText, |
| 2352 | bool VerifyEachPass, bool DebugLogging) { |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2353 | auto Pipeline = parsePipelineText(PipelineText); |
| 2354 | if (!Pipeline || Pipeline->empty()) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2355 | return make_error<StringError>( |
| 2356 | formatv("invalid pipeline '{0}'", PipelineText).str(), |
| 2357 | inconvertibleErrorCode()); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2358 | |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2359 | if (auto Err = |
| 2360 | parseLoopPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging)) |
| 2361 | return Err; |
| 2362 | |
| 2363 | return Error::success(); |
Philip Pfaffe | 730f2f9 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2364 | } |
| 2365 | |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2366 | Error PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) { |
Chandler Carruth | 060ad61 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 2367 | // If the pipeline just consists of the word 'default' just replace the AA |
| 2368 | // manager with our default one. |
| 2369 | if (PipelineText == "default") { |
| 2370 | AA = buildDefaultAAPipeline(); |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2371 | return Error::success(); |
Chandler Carruth | 060ad61 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 2372 | } |
| 2373 | |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 2374 | while (!PipelineText.empty()) { |
| 2375 | StringRef Name; |
| 2376 | std::tie(Name, PipelineText) = PipelineText.split(','); |
| 2377 | if (!parseAAPassName(AA, Name)) |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2378 | return make_error<StringError>( |
| 2379 | formatv("unknown alias analysis name '{0}'", Name).str(), |
| 2380 | inconvertibleErrorCode()); |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 2381 | } |
| 2382 | |
Fedor Sergeev | bd6b213 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2383 | return Error::success(); |
Chandler Carruth | edf5996 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 2384 | } |