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