Chandler Carruth | 2349136 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 1 | //===- Parsing, selection, and construction of pass pipelines -------------===// |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// |
Chandler Carruth | 2349136 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 11 | /// This file provides the implementation of the PassBuilder based on our |
| 12 | /// static pass registry as well as related functionality. It also provides |
| 13 | /// helpers to aid in analyzing, debugging, and testing passes and pass |
| 14 | /// pipelines. |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 15 | /// |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
Chandler Carruth | 2349136 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 18 | #include "llvm/Passes/PassBuilder.h" |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringSwitch.h" |
Chandler Carruth | 26bf6ea | 2016-02-13 23:32:00 +0000 | [diff] [blame] | 20 | #include "llvm/Analysis/AliasAnalysis.h" |
Chandler Carruth | 89a08aa | 2016-02-20 03:46:03 +0000 | [diff] [blame] | 21 | #include "llvm/Analysis/AliasAnalysisEvaluator.h" |
Daniel Jasper | 8de3a54 | 2016-12-19 08:22:17 +0000 | [diff] [blame] | 22 | #include "llvm/Analysis/AssumptionCache.h" |
Chandler Carruth | 6f603ac | 2016-02-13 23:46:24 +0000 | [diff] [blame] | 23 | #include "llvm/Analysis/BasicAliasAnalysis.h" |
Xinliang David Li | da713ca | 2016-05-05 21:13:27 +0000 | [diff] [blame] | 24 | #include "llvm/Analysis/BlockFrequencyInfo.h" |
Xinliang David Li | 454f7fa | 2016-05-05 02:59:57 +0000 | [diff] [blame] | 25 | #include "llvm/Analysis/BranchProbabilityInfo.h" |
Mehdi Amini | 8dff0d8 | 2016-09-16 16:56:30 +0000 | [diff] [blame] | 26 | #include "llvm/Analysis/CFGPrinter.h" |
George Burgess IV | 3b5b98a | 2016-07-06 00:26:41 +0000 | [diff] [blame] | 27 | #include "llvm/Analysis/CFLAndersAliasAnalysis.h" |
| 28 | #include "llvm/Analysis/CFLSteensAliasAnalysis.h" |
Chandler Carruth | 57418d8 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 29 | #include "llvm/Analysis/CGSCCPassManager.h" |
Chandler Carruth | f1b2c7b | 2016-03-10 11:24:11 +0000 | [diff] [blame] | 30 | #include "llvm/Analysis/CallGraph.h" |
Michael Kuperstein | 3445cc7 | 2016-04-18 23:55:01 +0000 | [diff] [blame] | 31 | #include "llvm/Analysis/DemandedBits.h" |
Chandler Carruth | b6b8f76 | 2016-05-12 22:19:39 +0000 | [diff] [blame] | 32 | #include "llvm/Analysis/DependenceAnalysis.h" |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 33 | #include "llvm/Analysis/DominanceFrontier.h" |
Chandler Carruth | f51faf0 | 2016-03-11 09:15:11 +0000 | [diff] [blame] | 34 | #include "llvm/Analysis/GlobalsModRef.h" |
Dehao Chen | 78ee4b6 | 2016-07-16 22:51:33 +0000 | [diff] [blame] | 35 | #include "llvm/Analysis/IVUsers.h" |
Chandler Carruth | 57732bf | 2014-02-06 04:37:03 +0000 | [diff] [blame] | 36 | #include "llvm/Analysis/LazyCallGraph.h" |
Sean Silva | 9ce41c3 | 2016-06-13 22:01:25 +0000 | [diff] [blame] | 37 | #include "llvm/Analysis/LazyValueInfo.h" |
Xinliang David Li | 10b22c8 | 2016-07-02 21:18:40 +0000 | [diff] [blame] | 38 | #include "llvm/Analysis/LoopAccessAnalysis.h" |
Chandler Carruth | a375120 | 2015-01-20 10:58:50 +0000 | [diff] [blame] | 39 | #include "llvm/Analysis/LoopInfo.h" |
Chandler Carruth | c5266b5 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 40 | #include "llvm/Analysis/MemoryDependenceAnalysis.h" |
Daniel Berlin | e0f5ddb | 2017-04-11 20:06:36 +0000 | [diff] [blame] | 41 | #include "llvm/Analysis/MemorySSA.h" |
Teresa Johnson | 3143f33 | 2016-08-12 13:53:02 +0000 | [diff] [blame] | 42 | #include "llvm/Analysis/ModuleSummaryAnalysis.h" |
Adam Nemet | 3b8950a | 2017-10-09 23:19:02 +0000 | [diff] [blame] | 43 | #include "llvm/Analysis/OptimizationRemarkEmitter.h" |
John Brawn | 106ffb9 | 2018-06-28 14:13:06 +0000 | [diff] [blame] | 44 | #include "llvm/Analysis/PhiValues.h" |
Hongbin Zheng | 5d7472e | 2016-02-25 17:54:07 +0000 | [diff] [blame] | 45 | #include "llvm/Analysis/PostDominators.h" |
Easwaran Raman | 7ef349f | 2016-06-03 22:54:26 +0000 | [diff] [blame] | 46 | #include "llvm/Analysis/ProfileSummaryInfo.h" |
Hongbin Zheng | edc89ca | 2016-02-25 17:54:25 +0000 | [diff] [blame] | 47 | #include "llvm/Analysis/RegionInfo.h" |
Chandler Carruth | bfe1f1c | 2015-08-17 02:08:17 +0000 | [diff] [blame] | 48 | #include "llvm/Analysis/ScalarEvolution.h" |
Chandler Carruth | 10ab5d9 | 2016-02-20 04:01:45 +0000 | [diff] [blame] | 49 | #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" |
Chandler Carruth | 580e466 | 2016-02-20 04:03:06 +0000 | [diff] [blame] | 50 | #include "llvm/Analysis/ScopedNoAliasAA.h" |
Vitaly Buka | c29e36f | 2018-11-26 21:57:47 +0000 | [diff] [blame] | 51 | #include "llvm/Analysis/StackSafetyAnalysis.h" |
Chandler Carruth | e2ffd02 | 2015-01-15 11:39:46 +0000 | [diff] [blame] | 52 | #include "llvm/Analysis/TargetLibraryInfo.h" |
Chandler Carruth | 7724e8e | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 53 | #include "llvm/Analysis/TargetTransformInfo.h" |
Chandler Carruth | 3b19409 | 2016-02-20 04:04:52 +0000 | [diff] [blame] | 54 | #include "llvm/Analysis/TypeBasedAliasAnalysis.h" |
Michael Kuperstein | f3f8fc6 | 2016-06-24 20:13:42 +0000 | [diff] [blame] | 55 | #include "llvm/CodeGen/PreISelIntrinsicLowering.h" |
Wei Mi | 302c35d | 2016-07-08 03:32:49 +0000 | [diff] [blame] | 56 | #include "llvm/CodeGen/UnreachableBlockElim.h" |
Chandler Carruth | 8c3a02f | 2015-01-14 10:19:28 +0000 | [diff] [blame] | 57 | #include "llvm/IR/Dominators.h" |
Chandler Carruth | a595257 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 58 | #include "llvm/IR/IRPrintingPasses.h" |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 59 | #include "llvm/IR/PassManager.h" |
Chandler Carruth | 1d9ab25 | 2014-01-20 11:34:08 +0000 | [diff] [blame] | 60 | #include "llvm/IR/Verifier.h" |
Chandler Carruth | a595257 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 61 | #include "llvm/Support/Debug.h" |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 62 | #include "llvm/Support/FormatVariadic.h" |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 63 | #include "llvm/Support/Regex.h" |
Chandler Carruth | 7724e8e | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 64 | #include "llvm/Target/TargetMachine.h" |
Amjad Aboud | c6483fb | 2018-01-25 12:06:32 +0000 | [diff] [blame] | 65 | #include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h" |
Chandler Carruth | b699f7b | 2016-08-17 02:56:20 +0000 | [diff] [blame] | 66 | #include "llvm/Transforms/IPO/AlwaysInliner.h" |
Chandler Carruth | 1648cea | 2017-02-09 23:46:27 +0000 | [diff] [blame] | 67 | #include "llvm/Transforms/IPO/ArgumentPromotion.h" |
Matthew Simpson | 7d6a3b6 | 2017-10-25 13:40:08 +0000 | [diff] [blame] | 68 | #include "llvm/Transforms/IPO/CalledValuePropagation.h" |
Davide Italiano | 0a51771 | 2016-05-05 00:51:09 +0000 | [diff] [blame] | 69 | #include "llvm/Transforms/IPO/ConstantMerge.h" |
Davide Italiano | 0dd611b | 2016-07-09 03:25:35 +0000 | [diff] [blame] | 70 | #include "llvm/Transforms/IPO/CrossDSOCFI.h" |
Sean Silva | 466d0a3 | 2016-06-12 09:16:39 +0000 | [diff] [blame] | 71 | #include "llvm/Transforms/IPO/DeadArgumentElimination.h" |
Davide Italiano | e44aed7 | 2016-05-05 02:37:32 +0000 | [diff] [blame] | 72 | #include "llvm/Transforms/IPO/ElimAvailExtern.h" |
Chandler Carruth | 6a1ce8e | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 73 | #include "llvm/Transforms/IPO/ForceFunctionAttrs.h" |
Chandler Carruth | e9afeb0 | 2016-02-18 11:03:11 +0000 | [diff] [blame] | 74 | #include "llvm/Transforms/IPO/FunctionAttrs.h" |
Teresa Johnson | 385d706 | 2016-07-18 21:22:24 +0000 | [diff] [blame] | 75 | #include "llvm/Transforms/IPO/FunctionImport.h" |
Davide Italiano | 82cad6f | 2016-05-03 19:39:15 +0000 | [diff] [blame] | 76 | #include "llvm/Transforms/IPO/GlobalDCE.h" |
Justin Bogner | 1a9ed30 | 2016-04-26 00:28:01 +0000 | [diff] [blame] | 77 | #include "llvm/Transforms/IPO/GlobalOpt.h" |
Davide Italiano | 02ca2cb | 2016-11-21 00:28:23 +0000 | [diff] [blame] | 78 | #include "llvm/Transforms/IPO/GlobalSplit.h" |
Aditya Kumar | f7ae0df | 2018-10-03 05:55:20 +0000 | [diff] [blame] | 79 | #include "llvm/Transforms/IPO/HotColdSplitting.h" |
Chandler Carruth | d979642 | 2015-12-27 08:41:34 +0000 | [diff] [blame] | 80 | #include "llvm/Transforms/IPO/InferFunctionAttrs.h" |
Chandler Carruth | 54cffa1 | 2016-12-20 03:15:32 +0000 | [diff] [blame] | 81 | #include "llvm/Transforms/IPO/Inliner.h" |
Justin Bogner | c3ce5d9 | 2016-04-26 20:15:52 +0000 | [diff] [blame] | 82 | #include "llvm/Transforms/IPO/Internalize.h" |
Davide Italiano | eb06640 | 2016-07-11 18:10:06 +0000 | [diff] [blame] | 83 | #include "llvm/Transforms/IPO/LowerTypeTests.h" |
Easwaran Raman | 78b1ab7 | 2016-06-27 16:50:18 +0000 | [diff] [blame] | 84 | #include "llvm/Transforms/IPO/PartialInlining.h" |
Davide Italiano | 2d1483c | 2016-05-05 21:05:36 +0000 | [diff] [blame] | 85 | #include "llvm/Transforms/IPO/SCCP.h" |
David Blaikie | d140aea | 2018-03-22 22:42:44 +0000 | [diff] [blame] | 86 | #include "llvm/Transforms/IPO/SampleProfile.h" |
Justin Bogner | e39e3a4 | 2015-10-30 23:28:12 +0000 | [diff] [blame] | 87 | #include "llvm/Transforms/IPO/StripDeadPrototypes.h" |
Easwaran Raman | 283d978 | 2018-01-09 19:39:35 +0000 | [diff] [blame] | 88 | #include "llvm/Transforms/IPO/SyntheticCountsPropagation.h" |
Davide Italiano | 7c79872 | 2016-06-14 21:44:19 +0000 | [diff] [blame] | 89 | #include "llvm/Transforms/IPO/WholeProgramDevirt.h" |
Chandler Carruth | 6a1ce8e | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 90 | #include "llvm/Transforms/InstCombine/InstCombine.h" |
Philip Pfaffe | 4956e30 | 2019-01-03 13:42:44 +0000 | [diff] [blame] | 91 | #include "llvm/Transforms/Instrumentation.h" |
Chandler Carruth | 8dd352a | 2017-11-14 01:30:04 +0000 | [diff] [blame] | 92 | #include "llvm/Transforms/Instrumentation/BoundsChecking.h" |
Vitaly Buka | c29e36f | 2018-11-26 21:57:47 +0000 | [diff] [blame] | 93 | #include "llvm/Transforms/Instrumentation/CGProfile.h" |
Hiroshi Yamauchi | c38c850 | 2018-09-04 17:19:13 +0000 | [diff] [blame] | 94 | #include "llvm/Transforms/Instrumentation/ControlHeightReduction.h" |
Chandler Carruth | b2b950d | 2018-06-29 23:36:03 +0000 | [diff] [blame] | 95 | #include "llvm/Transforms/Instrumentation/GCOVProfiler.h" |
| 96 | #include "llvm/Transforms/Instrumentation/InstrProfiling.h" |
Philip Pfaffe | 4956e30 | 2019-01-03 13:42:44 +0000 | [diff] [blame] | 97 | #include "llvm/Transforms/Instrumentation/MemorySanitizer.h" |
Philip Pfaffe | 6dbe225 | 2019-01-16 09:28:01 +0000 | [diff] [blame] | 98 | #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h" |
David Blaikie | a10309c | 2018-03-23 22:11:06 +0000 | [diff] [blame] | 99 | #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h" |
Justin Bogner | af01998 | 2015-10-30 23:13:18 +0000 | [diff] [blame] | 100 | #include "llvm/Transforms/Scalar/ADCE.h" |
Sean Silva | 570b29d | 2016-06-15 06:18:01 +0000 | [diff] [blame] | 101 | #include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h" |
Davide Italiano | abf016e | 2016-05-25 01:57:04 +0000 | [diff] [blame] | 102 | #include "llvm/Transforms/Scalar/BDCE.h" |
Jun Bum Lim | f4beb75 | 2017-11-03 20:41:16 +0000 | [diff] [blame] | 103 | #include "llvm/Transforms/Scalar/CallSiteSplitting.h" |
Adam Nemet | c476e17 | 2016-07-18 16:29:17 +0000 | [diff] [blame] | 104 | #include "llvm/Transforms/Scalar/ConstantHoisting.h" |
Sean Silva | 9afbd6f | 2016-07-06 23:26:29 +0000 | [diff] [blame] | 105 | #include "llvm/Transforms/Scalar/CorrelatedValuePropagation.h" |
Justin Bogner | 04d2814 | 2016-04-22 19:40:41 +0000 | [diff] [blame] | 106 | #include "llvm/Transforms/Scalar/DCE.h" |
Justin Bogner | 9c81a3f | 2016-05-17 21:38:13 +0000 | [diff] [blame] | 107 | #include "llvm/Transforms/Scalar/DeadStoreElimination.h" |
Sanjay Patel | 193e898 | 2017-09-09 13:38:18 +0000 | [diff] [blame] | 108 | #include "llvm/Transforms/Scalar/DivRemPairs.h" |
Chandler Carruth | 80c55f2 | 2015-02-01 10:51:23 +0000 | [diff] [blame] | 109 | #include "llvm/Transforms/Scalar/EarlyCSE.h" |
Michael Kuperstein | 840a0dd | 2016-06-24 23:32:02 +0000 | [diff] [blame] | 110 | #include "llvm/Transforms/Scalar/Float2Int.h" |
Easwaran Raman | 7ef349f | 2016-06-03 22:54:26 +0000 | [diff] [blame] | 111 | #include "llvm/Transforms/Scalar/GVN.h" |
Davide Italiano | d4b40fa | 2016-06-14 00:49:23 +0000 | [diff] [blame] | 112 | #include "llvm/Transforms/Scalar/GuardWidening.h" |
Chandler Carruth | c68d25f | 2017-01-11 09:43:56 +0000 | [diff] [blame] | 113 | #include "llvm/Transforms/Scalar/IVUsersPrinter.h" |
Sanjoy Das | a55495a | 2016-06-05 18:01:19 +0000 | [diff] [blame] | 114 | #include "llvm/Transforms/Scalar/IndVarSimplify.h" |
Fedor Sergeev | 116f1ad | 2018-03-15 11:01:19 +0000 | [diff] [blame] | 115 | #include "llvm/Transforms/Scalar/InductiveRangeCheckElimination.h" |
Chandler Carruth | b2b950d | 2018-06-29 23:36:03 +0000 | [diff] [blame] | 116 | #include "llvm/Transforms/Scalar/InstSimplifyPass.h" |
Sean Silva | 9897e75 | 2016-06-14 00:51:09 +0000 | [diff] [blame] | 117 | #include "llvm/Transforms/Scalar/JumpThreading.h" |
Dehao Chen | e06fe02 | 2016-07-12 22:42:24 +0000 | [diff] [blame] | 118 | #include "llvm/Transforms/Scalar/LICM.h" |
Chandler Carruth | c68d25f | 2017-01-11 09:43:56 +0000 | [diff] [blame] | 119 | #include "llvm/Transforms/Scalar/LoopAccessAnalysisPrinter.h" |
Teresa Johnson | f970c6e | 2016-08-13 04:11:27 +0000 | [diff] [blame] | 120 | #include "llvm/Transforms/Scalar/LoopDataPrefetch.h" |
Jun Bum Lim | fa907d3 | 2016-07-14 18:28:29 +0000 | [diff] [blame] | 121 | #include "llvm/Transforms/Scalar/LoopDeletion.h" |
Adam Nemet | 9b7ecbe | 2016-07-18 16:29:27 +0000 | [diff] [blame] | 122 | #include "llvm/Transforms/Scalar/LoopDistribute.h" |
Dehao Chen | 2ba4d7a | 2016-07-12 18:45:51 +0000 | [diff] [blame] | 123 | #include "llvm/Transforms/Scalar/LoopIdiomRecognize.h" |
Chandler Carruth | 7781850 | 2018-05-25 01:32:36 +0000 | [diff] [blame] | 124 | #include "llvm/Transforms/Scalar/LoopInstSimplify.h" |
Chandler Carruth | 90fe7e7 | 2017-01-27 01:32:26 +0000 | [diff] [blame] | 125 | #include "llvm/Transforms/Scalar/LoopLoadElimination.h" |
Chandler Carruth | c68d25f | 2017-01-11 09:43:56 +0000 | [diff] [blame] | 126 | #include "llvm/Transforms/Scalar/LoopPassManager.h" |
Artur Pilipenko | 1dd101b | 2017-01-25 16:00:44 +0000 | [diff] [blame] | 127 | #include "llvm/Transforms/Scalar/LoopPredication.h" |
Justin Bogner | 0b059c1 | 2016-05-03 22:02:31 +0000 | [diff] [blame] | 128 | #include "llvm/Transforms/Scalar/LoopRotation.h" |
Justin Bogner | cc5bcb5 | 2016-05-03 21:47:32 +0000 | [diff] [blame] | 129 | #include "llvm/Transforms/Scalar/LoopSimplifyCFG.h" |
Chandler Carruth | 017c62c | 2017-01-20 08:42:19 +0000 | [diff] [blame] | 130 | #include "llvm/Transforms/Scalar/LoopSink.h" |
Dehao Chen | e7eb2d5 | 2016-07-18 21:41:50 +0000 | [diff] [blame] | 131 | #include "llvm/Transforms/Scalar/LoopStrengthReduce.h" |
David Green | e101271 | 2018-07-01 12:47:30 +0000 | [diff] [blame] | 132 | #include "llvm/Transforms/Scalar/LoopUnrollAndJamPass.h" |
Sean Silva | d8c90ea | 2016-07-19 23:54:23 +0000 | [diff] [blame] | 133 | #include "llvm/Transforms/Scalar/LoopUnrollPass.h" |
Davide Italiano | 7430989 | 2016-05-13 22:52:35 +0000 | [diff] [blame] | 134 | #include "llvm/Transforms/Scalar/LowerAtomic.h" |
Chandler Carruth | d4f6d11 | 2015-01-24 11:13:02 +0000 | [diff] [blame] | 135 | #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h" |
Michael Kuperstein | 093715a | 2016-07-28 22:08:41 +0000 | [diff] [blame] | 136 | #include "llvm/Transforms/Scalar/LowerGuardIntrinsic.h" |
Max Kazantsev | c05ba54 | 2018-12-07 14:39:46 +0000 | [diff] [blame] | 137 | #include "llvm/Transforms/Scalar/MakeGuardsExplicit.h" |
Sean Silva | cf989e5 | 2016-06-14 02:44:55 +0000 | [diff] [blame] | 138 | #include "llvm/Transforms/Scalar/MemCpyOptimizer.h" |
Davide Italiano | e92bed3 | 2016-06-17 19:10:09 +0000 | [diff] [blame] | 139 | #include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h" |
Wei Mi | 3a4fa31 | 2016-07-21 22:28:52 +0000 | [diff] [blame] | 140 | #include "llvm/Transforms/Scalar/NaryReassociate.h" |
Davide Italiano | ee1439d | 2016-12-22 16:35:02 +0000 | [diff] [blame] | 141 | #include "llvm/Transforms/Scalar/NewGVN.h" |
Davide Italiano | 613d807 | 2016-05-25 23:38:53 +0000 | [diff] [blame] | 142 | #include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h" |
Justin Bogner | c943cfa | 2016-04-26 23:39:29 +0000 | [diff] [blame] | 143 | #include "llvm/Transforms/Scalar/Reassociate.h" |
Fedor Sergeev | f1b0fdf | 2017-12-15 09:32:11 +0000 | [diff] [blame] | 144 | #include "llvm/Transforms/Scalar/RewriteStatepointsForGC.h" |
Davide Italiano | d77d4c0 | 2016-05-18 15:18:25 +0000 | [diff] [blame] | 145 | #include "llvm/Transforms/Scalar/SCCP.h" |
Chandler Carruth | e73e5b4 | 2015-09-12 09:09:14 +0000 | [diff] [blame] | 146 | #include "llvm/Transforms/Scalar/SROA.h" |
Mikael Holmen | cdf701a | 2018-11-21 14:00:17 +0000 | [diff] [blame] | 147 | #include "llvm/Transforms/Scalar/Scalarizer.h" |
Chandler Carruth | 1d4cf6e | 2017-04-27 18:45:20 +0000 | [diff] [blame] | 148 | #include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h" |
Chandler Carruth | 6a1ce8e | 2015-12-27 08:13:45 +0000 | [diff] [blame] | 149 | #include "llvm/Transforms/Scalar/SimplifyCFG.h" |
Justin Bogner | 9d0b7e9 | 2016-04-22 19:54:10 +0000 | [diff] [blame] | 150 | #include "llvm/Transforms/Scalar/Sink.h" |
Chandler Carruth | 6efdd0f | 2017-11-28 11:32:31 +0000 | [diff] [blame] | 151 | #include "llvm/Transforms/Scalar/SpeculateAroundPHIs.h" |
Michael Kuperstein | 3a6d437 | 2016-08-01 21:48:33 +0000 | [diff] [blame] | 152 | #include "llvm/Transforms/Scalar/SpeculativeExecution.h" |
Sean Silva | f79d978 | 2016-07-06 23:48:41 +0000 | [diff] [blame] | 153 | #include "llvm/Transforms/Scalar/TailRecursionElimination.h" |
Michael Kruse | 9a395de | 2018-12-12 17:32:52 +0000 | [diff] [blame] | 154 | #include "llvm/Transforms/Scalar/WarnMissedTransforms.h" |
Xinliang David Li | 438355c | 2016-06-15 21:51:30 +0000 | [diff] [blame] | 155 | #include "llvm/Transforms/Utils/AddDiscriminators.h" |
Wei Mi | a6c7a03 | 2016-07-22 18:04:25 +0000 | [diff] [blame] | 156 | #include "llvm/Transforms/Utils/BreakCriticalEdges.h" |
Teresa Johnson | 1f63024 | 2019-01-04 19:04:54 +0000 | [diff] [blame] | 157 | #include "llvm/Transforms/Utils/CanonicalizeAliases.h" |
Hans Wennborg | 5765d84 | 2017-11-14 21:09:45 +0000 | [diff] [blame] | 158 | #include "llvm/Transforms/Utils/EntryExitInstrumenter.h" |
Easwaran Raman | 33933df | 2016-06-09 19:44:46 +0000 | [diff] [blame] | 159 | #include "llvm/Transforms/Utils/LCSSA.h" |
Rong Xu | fe89a6b | 2016-10-18 21:36:27 +0000 | [diff] [blame] | 160 | #include "llvm/Transforms/Utils/LibCallsShrinkWrap.h" |
Davide Italiano | fff81b2 | 2016-07-09 03:03:01 +0000 | [diff] [blame] | 161 | #include "llvm/Transforms/Utils/LoopSimplify.h" |
Michael Kuperstein | 69f0407 | 2016-08-12 17:28:27 +0000 | [diff] [blame] | 162 | #include "llvm/Transforms/Utils/LowerInvoke.h" |
Davide Italiano | 84645e0 | 2016-06-14 03:22:22 +0000 | [diff] [blame] | 163 | #include "llvm/Transforms/Utils/Mem2Reg.h" |
Mehdi Amini | 8dff0d8 | 2016-09-16 16:56:30 +0000 | [diff] [blame] | 164 | #include "llvm/Transforms/Utils/NameAnonGlobals.h" |
Michael Kuperstein | b339184 | 2016-07-25 20:52:00 +0000 | [diff] [blame] | 165 | #include "llvm/Transforms/Utils/SymbolRewriter.h" |
Markus Lavin | b2bc0c5 | 2018-12-07 08:23:37 +0000 | [diff] [blame] | 166 | #include "llvm/Transforms/Vectorize/LoadStoreVectorizer.h" |
Sean Silva | 89419a6 | 2016-07-09 22:56:50 +0000 | [diff] [blame] | 167 | #include "llvm/Transforms/Vectorize/LoopVectorize.h" |
Sean Silva | eb2d425 | 2016-07-09 03:11:29 +0000 | [diff] [blame] | 168 | #include "llvm/Transforms/Vectorize/SLPVectorizer.h" |
Davide Italiano | 84645e0 | 2016-06-14 03:22:22 +0000 | [diff] [blame] | 169 | |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 170 | using namespace llvm; |
| 171 | |
Chandler Carruth | 1f7ef68 | 2017-02-12 05:38:04 +0000 | [diff] [blame] | 172 | static cl::opt<unsigned> MaxDevirtIterations("pm-max-devirt-iterations", |
| 173 | cl::ReallyHidden, cl::init(4)); |
Xinliang David Li | b9e0915 | 2017-05-22 16:41:57 +0000 | [diff] [blame] | 174 | static cl::opt<bool> |
| 175 | RunPartialInlining("enable-npm-partial-inlining", cl::init(false), |
| 176 | cl::Hidden, cl::ZeroOrMore, |
| 177 | cl::desc("Run Partial inlinining pass")); |
Chandler Carruth | 1f7ef68 | 2017-02-12 05:38:04 +0000 | [diff] [blame] | 178 | |
Davide Italiano | efb6b10 | 2017-05-22 23:41:40 +0000 | [diff] [blame] | 179 | static cl::opt<bool> |
Davide Italiano | d88c7f0 | 2017-05-22 23:47:11 +0000 | [diff] [blame] | 180 | RunNewGVN("enable-npm-newgvn", cl::init(false), |
Davide Italiano | efb6b10 | 2017-05-22 23:41:40 +0000 | [diff] [blame] | 181 | cl::Hidden, cl::ZeroOrMore, |
| 182 | cl::desc("Run NewGVN instead of GVN")); |
| 183 | |
Geoff Berry | 47e2355 | 2017-06-10 15:20:03 +0000 | [diff] [blame] | 184 | static cl::opt<bool> EnableEarlyCSEMemSSA( |
Geoff Berry | 607969f | 2017-06-27 22:25:02 +0000 | [diff] [blame] | 185 | "enable-npm-earlycse-memssa", cl::init(true), cl::Hidden, |
| 186 | cl::desc("Enable the EarlyCSE w/ MemorySSA pass for the new PM (default = on)")); |
Geoff Berry | 47e2355 | 2017-06-10 15:20:03 +0000 | [diff] [blame] | 187 | |
Chandler Carruth | bde56a9 | 2017-04-27 00:28:03 +0000 | [diff] [blame] | 188 | static cl::opt<bool> EnableGVNHoist( |
Eric Christopher | 2f73099 | 2018-10-01 18:57:08 +0000 | [diff] [blame] | 189 | "enable-npm-gvn-hoist", cl::init(false), cl::Hidden, |
| 190 | cl::desc("Enable the GVN hoisting pass for the new PM (default = off)")); |
Chandler Carruth | bde56a9 | 2017-04-27 00:28:03 +0000 | [diff] [blame] | 191 | |
Davide Italiano | 653044e | 2017-06-03 23:18:29 +0000 | [diff] [blame] | 192 | static cl::opt<bool> EnableGVNSink( |
| 193 | "enable-npm-gvn-sink", cl::init(false), cl::Hidden, |
| 194 | cl::desc("Enable the GVN hoisting pass for the new PM (default = off)")); |
| 195 | |
David Green | e101271 | 2018-07-01 12:47:30 +0000 | [diff] [blame] | 196 | static cl::opt<bool> EnableUnrollAndJam( |
| 197 | "enable-npm-unroll-and-jam", cl::init(false), cl::Hidden, |
| 198 | cl::desc("Enable the Unroll and Jam pass for the new PM (default = off)")); |
| 199 | |
Easwaran Raman | 283d978 | 2018-01-09 19:39:35 +0000 | [diff] [blame] | 200 | static cl::opt<bool> EnableSyntheticCounts( |
| 201 | "enable-npm-synthetic-counts", cl::init(false), cl::Hidden, cl::ZeroOrMore, |
| 202 | cl::desc("Run synthetic function entry count generation " |
| 203 | "pass")); |
| 204 | |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 205 | static Regex DefaultAliasRegex( |
| 206 | "^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$"); |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 207 | |
Hiroshi Yamauchi | c38c850 | 2018-09-04 17:19:13 +0000 | [diff] [blame] | 208 | static cl::opt<bool> |
| 209 | EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden, |
| 210 | cl::desc("Enable control height reduction optimization (CHR)")); |
| 211 | |
Aditya Kumar | f7ae0df | 2018-10-03 05:55:20 +0000 | [diff] [blame] | 212 | extern cl::opt<bool> EnableHotColdSplit; |
| 213 | |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 214 | static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level) { |
| 215 | switch (Level) { |
| 216 | case PassBuilder::O0: |
| 217 | case PassBuilder::O1: |
| 218 | case PassBuilder::O2: |
| 219 | case PassBuilder::O3: |
| 220 | return false; |
| 221 | |
| 222 | case PassBuilder::Os: |
| 223 | case PassBuilder::Oz: |
| 224 | return true; |
| 225 | } |
| 226 | llvm_unreachable("Invalid optimization level!"); |
| 227 | } |
| 228 | |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 229 | namespace { |
| 230 | |
Adrian Prantl | 26b584c | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 231 | /// No-op module pass which does nothing. |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 232 | struct NoOpModulePass { |
Sean Silva | 2fb9a98 | 2016-08-09 00:28:38 +0000 | [diff] [blame] | 233 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &) { |
Chandler Carruth | 04d0fe9 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 234 | return PreservedAnalyses::all(); |
| 235 | } |
Chandler Carruth | b56749c | 2014-01-11 11:52:05 +0000 | [diff] [blame] | 236 | static StringRef name() { return "NoOpModulePass"; } |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 237 | }; |
| 238 | |
Adrian Prantl | 26b584c | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 239 | /// No-op module analysis. |
Chandler Carruth | 18e9a2b | 2016-03-11 10:33:22 +0000 | [diff] [blame] | 240 | class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> { |
| 241 | friend AnalysisInfoMixin<NoOpModuleAnalysis>; |
Chandler Carruth | 33d5681 | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 242 | static AnalysisKey Key; |
Chandler Carruth | e95015f | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 243 | |
| 244 | public: |
Chandler Carruth | 5b12a2f | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 245 | struct Result {}; |
Sean Silva | 2fb9a98 | 2016-08-09 00:28:38 +0000 | [diff] [blame] | 246 | Result run(Module &, ModuleAnalysisManager &) { return Result(); } |
Chandler Carruth | 5b12a2f | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 247 | static StringRef name() { return "NoOpModuleAnalysis"; } |
Chandler Carruth | 5b12a2f | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 248 | }; |
| 249 | |
Adrian Prantl | 26b584c | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 250 | /// No-op CGSCC pass which does nothing. |
Chandler Carruth | 57418d8 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 251 | struct NoOpCGSCCPass { |
Chandler Carruth | 377af8d | 2016-08-24 09:37:14 +0000 | [diff] [blame] | 252 | PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &, |
| 253 | LazyCallGraph &, CGSCCUpdateResult &UR) { |
Chandler Carruth | 57418d8 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 254 | return PreservedAnalyses::all(); |
| 255 | } |
| 256 | static StringRef name() { return "NoOpCGSCCPass"; } |
| 257 | }; |
| 258 | |
Adrian Prantl | 26b584c | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 259 | /// No-op CGSCC analysis. |
Chandler Carruth | 18e9a2b | 2016-03-11 10:33:22 +0000 | [diff] [blame] | 260 | class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> { |
| 261 | friend AnalysisInfoMixin<NoOpCGSCCAnalysis>; |
Chandler Carruth | 33d5681 | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 262 | static AnalysisKey Key; |
Chandler Carruth | e95015f | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 263 | |
| 264 | public: |
Chandler Carruth | 5b12a2f | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 265 | struct Result {}; |
Chandler Carruth | 377af8d | 2016-08-24 09:37:14 +0000 | [diff] [blame] | 266 | Result run(LazyCallGraph::SCC &, CGSCCAnalysisManager &, LazyCallGraph &G) { |
Chandler Carruth | 04d0fe9 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 267 | return Result(); |
| 268 | } |
Chandler Carruth | 5b12a2f | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 269 | static StringRef name() { return "NoOpCGSCCAnalysis"; } |
Chandler Carruth | 5b12a2f | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 270 | }; |
| 271 | |
Adrian Prantl | 26b584c | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 272 | /// No-op function pass which does nothing. |
Chandler Carruth | e768765 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 273 | struct NoOpFunctionPass { |
Sean Silva | 20b343c | 2016-08-09 00:28:15 +0000 | [diff] [blame] | 274 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &) { |
Chandler Carruth | 04d0fe9 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 275 | return PreservedAnalyses::all(); |
| 276 | } |
Chandler Carruth | e768765 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 277 | static StringRef name() { return "NoOpFunctionPass"; } |
| 278 | }; |
| 279 | |
Adrian Prantl | 26b584c | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 280 | /// No-op function analysis. |
Chandler Carruth | 18e9a2b | 2016-03-11 10:33:22 +0000 | [diff] [blame] | 281 | class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> { |
| 282 | friend AnalysisInfoMixin<NoOpFunctionAnalysis>; |
Chandler Carruth | 33d5681 | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 283 | static AnalysisKey Key; |
Chandler Carruth | e95015f | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 284 | |
| 285 | public: |
Chandler Carruth | 5b12a2f | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 286 | struct Result {}; |
Sean Silva | 20b343c | 2016-08-09 00:28:15 +0000 | [diff] [blame] | 287 | Result run(Function &, FunctionAnalysisManager &) { return Result(); } |
Chandler Carruth | 5b12a2f | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 288 | static StringRef name() { return "NoOpFunctionAnalysis"; } |
Chandler Carruth | 5b12a2f | 2015-01-06 02:50:06 +0000 | [diff] [blame] | 289 | }; |
| 290 | |
Adrian Prantl | 26b584c | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 291 | /// No-op loop pass which does nothing. |
Justin Bogner | da5e924 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 292 | struct NoOpLoopPass { |
Chandler Carruth | d27a39a | 2017-01-11 06:23:21 +0000 | [diff] [blame] | 293 | PreservedAnalyses run(Loop &L, LoopAnalysisManager &, |
| 294 | LoopStandardAnalysisResults &, LPMUpdater &) { |
Chandler Carruth | 04d0fe9 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 295 | return PreservedAnalyses::all(); |
| 296 | } |
Justin Bogner | da5e924 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 297 | static StringRef name() { return "NoOpLoopPass"; } |
| 298 | }; |
| 299 | |
Adrian Prantl | 26b584c | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 300 | /// No-op loop analysis. |
Chandler Carruth | 18e9a2b | 2016-03-11 10:33:22 +0000 | [diff] [blame] | 301 | class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> { |
| 302 | friend AnalysisInfoMixin<NoOpLoopAnalysis>; |
Chandler Carruth | 33d5681 | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 303 | static AnalysisKey Key; |
Chandler Carruth | e95015f | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 304 | |
| 305 | public: |
Justin Bogner | da5e924 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 306 | struct Result {}; |
Chandler Carruth | d27a39a | 2017-01-11 06:23:21 +0000 | [diff] [blame] | 307 | Result run(Loop &, LoopAnalysisManager &, LoopStandardAnalysisResults &) { |
| 308 | return Result(); |
| 309 | } |
Justin Bogner | da5e924 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 310 | static StringRef name() { return "NoOpLoopAnalysis"; } |
Justin Bogner | da5e924 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 311 | }; |
| 312 | |
Chandler Carruth | 33d5681 | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 313 | AnalysisKey NoOpModuleAnalysis::Key; |
| 314 | AnalysisKey NoOpCGSCCAnalysis::Key; |
| 315 | AnalysisKey NoOpFunctionAnalysis::Key; |
| 316 | AnalysisKey NoOpLoopAnalysis::Key; |
Chandler Carruth | e95015f | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 317 | |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 318 | } // End anonymous namespace. |
| 319 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 320 | void PassBuilder::invokePeepholeEPCallbacks( |
| 321 | FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) { |
| 322 | for (auto &C : PeepholeEPCallbacks) |
| 323 | C(FPM, Level); |
| 324 | } |
| 325 | |
Chandler Carruth | 2349136 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 326 | void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) { |
Chandler Carruth | bd6882c | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 327 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 67a41f0 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 328 | MAM.registerPass([&] { return CREATE_PASS; }); |
Chandler Carruth | 2bbc5ab | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 329 | #include "PassRegistry.def" |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 330 | |
| 331 | for (auto &C : ModuleAnalysisRegistrationCallbacks) |
| 332 | C(MAM); |
Chandler Carruth | 2bbc5ab | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Chandler Carruth | 2349136 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 335 | void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) { |
Chandler Carruth | bd6882c | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 336 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 67a41f0 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 337 | CGAM.registerPass([&] { return CREATE_PASS; }); |
Chandler Carruth | 2bbc5ab | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 338 | #include "PassRegistry.def" |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 339 | |
| 340 | for (auto &C : CGSCCAnalysisRegistrationCallbacks) |
| 341 | C(CGAM); |
Chandler Carruth | 2bbc5ab | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Chandler Carruth | 2349136 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 344 | void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) { |
Chandler Carruth | bd6882c | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 345 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 67a41f0 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 346 | FAM.registerPass([&] { return CREATE_PASS; }); |
Chandler Carruth | 2bbc5ab | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 347 | #include "PassRegistry.def" |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 348 | |
| 349 | for (auto &C : FunctionAnalysisRegistrationCallbacks) |
| 350 | C(FAM); |
Chandler Carruth | 2bbc5ab | 2015-01-06 02:21:37 +0000 | [diff] [blame] | 351 | } |
| 352 | |
Justin Bogner | da5e924 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 353 | void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) { |
Chandler Carruth | bd6882c | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 354 | #define LOOP_ANALYSIS(NAME, CREATE_PASS) \ |
Justin Bogner | da5e924 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 355 | LAM.registerPass([&] { return CREATE_PASS; }); |
| 356 | #include "PassRegistry.def" |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 357 | |
| 358 | for (auto &C : LoopAnalysisRegistrationCallbacks) |
| 359 | C(LAM); |
Justin Bogner | da5e924 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 362 | FunctionPassManager |
| 363 | PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level, |
Dehao Chen | 7b5ab7f | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 364 | ThinLTOPhase Phase, |
| 365 | bool DebugLogging) { |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 366 | assert(Level != O0 && "Must request optimizations!"); |
| 367 | FunctionPassManager FPM(DebugLogging); |
| 368 | |
| 369 | // Form SSA out of local memory accesses after breaking apart aggregates into |
| 370 | // scalars. |
| 371 | FPM.addPass(SROA()); |
| 372 | |
| 373 | // Catch trivial redundancies |
Geoff Berry | 47e2355 | 2017-06-10 15:20:03 +0000 | [diff] [blame] | 374 | FPM.addPass(EarlyCSEPass(EnableEarlyCSEMemSSA)); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 375 | |
Davide Italiano | 9cd1e1f8 | 2017-06-01 23:08:14 +0000 | [diff] [blame] | 376 | // Hoisting of scalars and load expressions. |
| 377 | if (EnableGVNHoist) |
| 378 | FPM.addPass(GVNHoistPass()); |
| 379 | |
Davide Italiano | 653044e | 2017-06-03 23:18:29 +0000 | [diff] [blame] | 380 | // Global value numbering based sinking. |
| 381 | if (EnableGVNSink) { |
| 382 | FPM.addPass(GVNSinkPass()); |
| 383 | FPM.addPass(SimplifyCFGPass()); |
| 384 | } |
| 385 | |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 386 | // Speculative execution if the target has divergent branches; otherwise nop. |
| 387 | FPM.addPass(SpeculativeExecutionPass()); |
| 388 | |
| 389 | // Optimize based on known information about branches, and cleanup afterward. |
| 390 | FPM.addPass(JumpThreadingPass()); |
| 391 | FPM.addPass(CorrelatedValuePropagationPass()); |
| 392 | FPM.addPass(SimplifyCFGPass()); |
Amjad Aboud | c6483fb | 2018-01-25 12:06:32 +0000 | [diff] [blame] | 393 | if (Level == O3) |
| 394 | FPM.addPass(AggressiveInstCombinePass()); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 395 | FPM.addPass(InstCombinePass()); |
| 396 | |
| 397 | if (!isOptimizingForSize(Level)) |
| 398 | FPM.addPass(LibCallsShrinkWrapPass()); |
| 399 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 400 | invokePeepholeEPCallbacks(FPM, Level); |
| 401 | |
Rong Xu | 2a01593 | 2017-10-23 22:21:29 +0000 | [diff] [blame] | 402 | // For PGO use pipeline, try to optimize memory intrinsics such as memcpy |
| 403 | // using the size value profile. Don't perform this when optimizing for size. |
| 404 | if (PGOOpt && !PGOOpt->ProfileUseFile.empty() && |
| 405 | !isOptimizingForSize(Level)) |
| 406 | FPM.addPass(PGOMemOPSizeOpt()); |
| 407 | |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 408 | FPM.addPass(TailCallElimPass()); |
| 409 | FPM.addPass(SimplifyCFGPass()); |
| 410 | |
| 411 | // Form canonically associated expression trees, and simplify the trees using |
| 412 | // basic mathematical properties. For example, this will form (nearly) |
| 413 | // minimal multiplication trees. |
| 414 | FPM.addPass(ReassociatePass()); |
| 415 | |
| 416 | // Add the primary loop simplification pipeline. |
| 417 | // FIXME: Currently this is split into two loop pass pipelines because we run |
Chandler Carruth | c96b7cb | 2018-05-30 02:46:45 +0000 | [diff] [blame] | 418 | // some function passes in between them. These can and should be removed |
| 419 | // and/or replaced by scheduling the loop pass equivalents in the correct |
| 420 | // positions. But those equivalent passes aren't powerful enough yet. |
| 421 | // Specifically, `SimplifyCFGPass` and `InstCombinePass` are currently still |
| 422 | // used. We have `LoopSimplifyCFGPass` which isn't yet powerful enough yet to |
| 423 | // fully replace `SimplifyCFGPass`, and the closest to the other we have is |
| 424 | // `LoopInstSimplify`. |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 425 | LoopPassManager LPM1(DebugLogging), LPM2(DebugLogging); |
| 426 | |
Chandler Carruth | c96b7cb | 2018-05-30 02:46:45 +0000 | [diff] [blame] | 427 | // Simplify the loop body. We do this initially to clean up after other loop |
| 428 | // passes run, either when iterating on a loop or on inner loops with |
| 429 | // implications on the outer loop. |
| 430 | LPM1.addPass(LoopInstSimplifyPass()); |
| 431 | LPM1.addPass(LoopSimplifyCFGPass()); |
| 432 | |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 433 | // Rotate Loop - disable header duplication at -Oz |
| 434 | LPM1.addPass(LoopRotatePass(Level != Oz)); |
| 435 | LPM1.addPass(LICMPass()); |
Chandler Carruth | 8800120 | 2017-05-26 01:24:11 +0000 | [diff] [blame] | 436 | LPM1.addPass(SimpleLoopUnswitchPass()); |
Chandler Carruth | e1c01cc | 2017-01-26 23:21:17 +0000 | [diff] [blame] | 437 | LPM2.addPass(IndVarSimplifyPass()); |
| 438 | LPM2.addPass(LoopIdiomRecognizePass()); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 439 | |
| 440 | for (auto &C : LateLoopOptimizationsEPCallbacks) |
| 441 | C(LPM2, Level); |
| 442 | |
Chandler Carruth | e1c01cc | 2017-01-26 23:21:17 +0000 | [diff] [blame] | 443 | LPM2.addPass(LoopDeletionPass()); |
Dehao Chen | 7b5ab7f | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 444 | // Do not enable unrolling in PreLinkThinLTO phase during sample PGO |
Dehao Chen | 59bf0ba | 2017-07-07 20:53:10 +0000 | [diff] [blame] | 445 | // because it changes IR to makes profile annotation in back compile |
| 446 | // inaccurate. |
Dehao Chen | 7b5ab7f | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 447 | if (Phase != ThinLTOPhase::PreLink || |
| 448 | !PGOOpt || PGOOpt->SampleProfileFile.empty()) |
Teresa Johnson | 99dd11f | 2017-08-02 20:35:29 +0000 | [diff] [blame] | 449 | LPM2.addPass(LoopFullUnrollPass(Level)); |
Chandler Carruth | e1c01cc | 2017-01-26 23:21:17 +0000 | [diff] [blame] | 450 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 451 | for (auto &C : LoopOptimizerEndEPCallbacks) |
| 452 | C(LPM2, Level); |
| 453 | |
Chandler Carruth | 88c0fa9 | 2017-02-09 23:54:57 +0000 | [diff] [blame] | 454 | // We provide the opt remark emitter pass for LICM to use. We only need to do |
| 455 | // this once as it is immutable. |
| 456 | FPM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>()); |
Fedor Sergeev | ffbb3d0 | 2017-12-29 08:16:06 +0000 | [diff] [blame] | 457 | FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM1), DebugLogging)); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 458 | FPM.addPass(SimplifyCFGPass()); |
| 459 | FPM.addPass(InstCombinePass()); |
Fedor Sergeev | ffbb3d0 | 2017-12-29 08:16:06 +0000 | [diff] [blame] | 460 | FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM2), DebugLogging)); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 461 | |
| 462 | // Eliminate redundancies. |
| 463 | if (Level != O1) { |
| 464 | // These passes add substantial compile time so skip them at O1. |
| 465 | FPM.addPass(MergedLoadStoreMotionPass()); |
Davide Italiano | efb6b10 | 2017-05-22 23:41:40 +0000 | [diff] [blame] | 466 | if (RunNewGVN) |
| 467 | FPM.addPass(NewGVNPass()); |
| 468 | else |
| 469 | FPM.addPass(GVN()); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | // Specially optimize memory movement as it doesn't look like dataflow in SSA. |
| 473 | FPM.addPass(MemCpyOptPass()); |
| 474 | |
| 475 | // Sparse conditional constant propagation. |
| 476 | // FIXME: It isn't clear why we do this *after* loop passes rather than |
| 477 | // before... |
| 478 | FPM.addPass(SCCPPass()); |
| 479 | |
| 480 | // Delete dead bit computations (instcombine runs after to fold away the dead |
| 481 | // computations, and then ADCE will run later to exploit any new DCE |
| 482 | // opportunities that creates). |
| 483 | FPM.addPass(BDCEPass()); |
| 484 | |
| 485 | // Run instcombine after redundancy and dead bit elimination to exploit |
| 486 | // opportunities opened up by them. |
| 487 | FPM.addPass(InstCombinePass()); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 488 | invokePeepholeEPCallbacks(FPM, Level); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 489 | |
| 490 | // Re-consider control flow based optimizations after redundancy elimination, |
| 491 | // redo DCE, etc. |
| 492 | FPM.addPass(JumpThreadingPass()); |
| 493 | FPM.addPass(CorrelatedValuePropagationPass()); |
| 494 | FPM.addPass(DSEPass()); |
Fedor Sergeev | ffbb3d0 | 2017-12-29 08:16:06 +0000 | [diff] [blame] | 495 | FPM.addPass(createFunctionToLoopPassAdaptor(LICMPass(), DebugLogging)); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 496 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 497 | for (auto &C : ScalarOptimizerLateEPCallbacks) |
| 498 | C(FPM, Level); |
| 499 | |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 500 | // Finally, do an expensive DCE pass to catch all the dead code exposed by |
| 501 | // the simplifications and basic cleanup after all the simplifications. |
| 502 | FPM.addPass(ADCEPass()); |
| 503 | FPM.addPass(SimplifyCFGPass()); |
| 504 | FPM.addPass(InstCombinePass()); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 505 | invokePeepholeEPCallbacks(FPM, Level); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 506 | |
Hiroshi Yamauchi | c38c850 | 2018-09-04 17:19:13 +0000 | [diff] [blame] | 507 | if (EnableCHR && Level == O3 && PGOOpt && |
| 508 | (!PGOOpt->ProfileUseFile.empty() || !PGOOpt->SampleProfileFile.empty())) |
| 509 | FPM.addPass(ControlHeightReductionPass()); |
| 510 | |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 511 | return FPM; |
| 512 | } |
| 513 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 514 | void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging, |
| 515 | PassBuilder::OptimizationLevel Level, |
| 516 | bool RunProfileGen, |
| 517 | std::string ProfileGenFile, |
Richard Smith | 63ec256 | 2018-10-10 23:13:47 +0000 | [diff] [blame] | 518 | std::string ProfileUseFile, |
| 519 | std::string ProfileRemappingFile) { |
Davide Italiano | 0125c63 | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 520 | // Generally running simplification passes and the inliner with an high |
| 521 | // threshold results in smaller executables, but there may be cases where |
| 522 | // the size grows, so let's be conservative here and skip this simplification |
| 523 | // at -Os/Oz. |
| 524 | if (!isOptimizingForSize(Level)) { |
| 525 | InlineParams IP; |
| 526 | |
| 527 | // In the old pass manager, this is a cl::opt. Should still this be one? |
| 528 | IP.DefaultThreshold = 75; |
| 529 | |
| 530 | // FIXME: The hint threshold has the same value used by the regular inliner. |
| 531 | // This should probably be lowered after performance testing. |
| 532 | // FIXME: this comment is cargo culted from the old pass manager, revisit). |
| 533 | IP.HintThreshold = 325; |
| 534 | |
| 535 | CGSCCPassManager CGPipeline(DebugLogging); |
| 536 | |
| 537 | CGPipeline.addPass(InlinerPass(IP)); |
| 538 | |
| 539 | FunctionPassManager FPM; |
| 540 | FPM.addPass(SROA()); |
| 541 | FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies. |
| 542 | FPM.addPass(SimplifyCFGPass()); // Merge & remove basic blocks. |
| 543 | FPM.addPass(InstCombinePass()); // Combine silly sequences. |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 544 | invokePeepholeEPCallbacks(FPM, Level); |
Davide Italiano | 0125c63 | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 545 | |
Davide Italiano | 0125c63 | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 546 | CGPipeline.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM))); |
| 547 | |
| 548 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPipeline))); |
| 549 | } |
| 550 | |
Chandler Carruth | 4fde77f | 2017-05-25 07:15:09 +0000 | [diff] [blame] | 551 | // Delete anything that is now dead to make sure that we don't instrument |
| 552 | // dead code. Instrumentation can end up keeping dead code around and |
| 553 | // dramatically increase code size. |
| 554 | MPM.addPass(GlobalDCEPass()); |
| 555 | |
Davide Italiano | 0125c63 | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 556 | if (RunProfileGen) { |
| 557 | MPM.addPass(PGOInstrumentationGen()); |
| 558 | |
Xinliang David Li | 0a14fbb | 2017-06-25 00:26:43 +0000 | [diff] [blame] | 559 | FunctionPassManager FPM; |
Fedor Sergeev | ffbb3d0 | 2017-12-29 08:16:06 +0000 | [diff] [blame] | 560 | FPM.addPass( |
| 561 | createFunctionToLoopPassAdaptor(LoopRotatePass(), DebugLogging)); |
Xinliang David Li | 0a14fbb | 2017-06-25 00:26:43 +0000 | [diff] [blame] | 562 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
| 563 | |
Davide Italiano | 0125c63 | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 564 | // Add the profile lowering pass. |
| 565 | InstrProfOptions Options; |
| 566 | if (!ProfileGenFile.empty()) |
| 567 | Options.InstrProfileOutput = ProfileGenFile; |
Xinliang David Li | 0a14fbb | 2017-06-25 00:26:43 +0000 | [diff] [blame] | 568 | Options.DoCounterPromotion = true; |
Davide Italiano | 0125c63 | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 569 | MPM.addPass(InstrProfiling(Options)); |
| 570 | } |
| 571 | |
| 572 | if (!ProfileUseFile.empty()) |
Richard Smith | 63ec256 | 2018-10-10 23:13:47 +0000 | [diff] [blame] | 573 | MPM.addPass(PGOInstrumentationUse(ProfileUseFile, ProfileRemappingFile)); |
Davide Italiano | 0125c63 | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 574 | } |
| 575 | |
Easwaran Raman | 4459676 | 2017-06-28 13:33:49 +0000 | [diff] [blame] | 576 | static InlineParams |
| 577 | getInlineParamsFromOptLevel(PassBuilder::OptimizationLevel Level) { |
| 578 | auto O3 = PassBuilder::O3; |
| 579 | unsigned OptLevel = Level > O3 ? 2 : Level; |
| 580 | unsigned SizeLevel = Level > O3 ? Level - O3 : 0; |
| 581 | return getInlineParams(OptLevel, SizeLevel); |
| 582 | } |
| 583 | |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 584 | ModulePassManager |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 585 | PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, |
Dehao Chen | 7b5ab7f | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 586 | ThinLTOPhase Phase, |
| 587 | bool DebugLogging) { |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 588 | ModulePassManager MPM(DebugLogging); |
| 589 | |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 590 | // Do basic inference of function attributes from known properties of system |
| 591 | // libraries and other oracles. |
| 592 | MPM.addPass(InferFunctionAttrsPass()); |
| 593 | |
| 594 | // Create an early function pass manager to cleanup the output of the |
| 595 | // frontend. |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 596 | FunctionPassManager EarlyFPM(DebugLogging); |
| 597 | EarlyFPM.addPass(SimplifyCFGPass()); |
| 598 | EarlyFPM.addPass(SROA()); |
| 599 | EarlyFPM.addPass(EarlyCSEPass()); |
| 600 | EarlyFPM.addPass(LowerExpectIntrinsicPass()); |
Jun Bum Lim | f4beb75 | 2017-11-03 20:41:16 +0000 | [diff] [blame] | 601 | if (Level == O3) |
| 602 | EarlyFPM.addPass(CallSiteSplittingPass()); |
| 603 | |
Dehao Chen | 6858db5 | 2017-08-07 20:23:20 +0000 | [diff] [blame] | 604 | // In SamplePGO ThinLTO backend, we need instcombine before profile annotation |
| 605 | // to convert bitcast to direct calls so that they can be inlined during the |
| 606 | // profile annotation prepration step. |
| 607 | // More details about SamplePGO design can be found in: |
| 608 | // https://research.google.com/pubs/pub45290.html |
| 609 | // FIXME: revisit how SampleProfileLoad/Inliner/ICP is structured. |
| 610 | if (PGOOpt && !PGOOpt->SampleProfileFile.empty() && |
| 611 | Phase == ThinLTOPhase::PostLink) |
| 612 | EarlyFPM.addPass(InstCombinePass()); |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 613 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM))); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 614 | |
Dehao Chen | 6858db5 | 2017-08-07 20:23:20 +0000 | [diff] [blame] | 615 | if (PGOOpt && !PGOOpt->SampleProfileFile.empty()) { |
| 616 | // Annotate sample profile right after early FPM to ensure freshness of |
| 617 | // the debug info. |
Dehao Chen | 61b7046 | 2017-10-01 05:24:51 +0000 | [diff] [blame] | 618 | MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile, |
Richard Smith | 63ec256 | 2018-10-10 23:13:47 +0000 | [diff] [blame] | 619 | PGOOpt->ProfileRemappingFile, |
Dehao Chen | 61b7046 | 2017-10-01 05:24:51 +0000 | [diff] [blame] | 620 | Phase == ThinLTOPhase::PreLink)); |
Dehao Chen | 6858db5 | 2017-08-07 20:23:20 +0000 | [diff] [blame] | 621 | // Do not invoke ICP in the ThinLTOPrelink phase as it makes it hard |
| 622 | // for the profile annotation to be accurate in the ThinLTO backend. |
| 623 | if (Phase != ThinLTOPhase::PreLink) |
| 624 | // We perform early indirect call promotion here, before globalopt. |
| 625 | // This is important for the ThinLTO backend phase because otherwise |
| 626 | // imported available_externally functions look unreferenced and are |
| 627 | // removed. |
| 628 | MPM.addPass(PGOIndirectCallPromotion(Phase == ThinLTOPhase::PostLink, |
| 629 | true)); |
| 630 | } |
| 631 | |
Malcolm Parsons | 5fc9628 | 2018-01-24 10:33:39 +0000 | [diff] [blame] | 632 | // Interprocedural constant propagation now that basic cleanup has occurred |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 633 | // and prior to optimizing globals. |
| 634 | // FIXME: This position in the pipeline hasn't been carefully considered in |
| 635 | // years, it should be re-analyzed. |
| 636 | MPM.addPass(IPSCCPPass()); |
| 637 | |
Matthew Simpson | 7d6a3b6 | 2017-10-25 13:40:08 +0000 | [diff] [blame] | 638 | // Attach metadata to indirect call sites indicating the set of functions |
| 639 | // they may target at run-time. This should follow IPSCCP. |
| 640 | MPM.addPass(CalledValuePropagationPass()); |
| 641 | |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 642 | // Optimize globals to try and fold them into constants. |
| 643 | MPM.addPass(GlobalOptPass()); |
| 644 | |
| 645 | // Promote any localized globals to SSA registers. |
| 646 | // FIXME: Should this instead by a run of SROA? |
| 647 | // FIXME: We should probably run instcombine and simplify-cfg afterward to |
| 648 | // delete control flows that are dead once globals have been folded to |
| 649 | // constants. |
| 650 | MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass())); |
| 651 | |
| 652 | // Remove any dead arguments exposed by cleanups and constand folding |
| 653 | // globals. |
| 654 | MPM.addPass(DeadArgumentEliminationPass()); |
| 655 | |
| 656 | // Create a small function pass pipeline to cleanup after all the global |
| 657 | // optimizations. |
| 658 | FunctionPassManager GlobalCleanupPM(DebugLogging); |
| 659 | GlobalCleanupPM.addPass(InstCombinePass()); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 660 | invokePeepholeEPCallbacks(GlobalCleanupPM, Level); |
| 661 | |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 662 | GlobalCleanupPM.addPass(SimplifyCFGPass()); |
| 663 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM))); |
| 664 | |
Dehao Chen | cbd2841 | 2017-08-02 01:28:31 +0000 | [diff] [blame] | 665 | // Add all the requested passes for instrumentation PGO, if requested. |
| 666 | if (PGOOpt && Phase != ThinLTOPhase::PostLink && |
| 667 | (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty())) { |
| 668 | addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen, |
Richard Smith | 63ec256 | 2018-10-10 23:13:47 +0000 | [diff] [blame] | 669 | PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile, |
| 670 | PGOOpt->ProfileRemappingFile); |
Dehao Chen | cbd2841 | 2017-08-02 01:28:31 +0000 | [diff] [blame] | 671 | MPM.addPass(PGOIndirectCallPromotion(false, false)); |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 672 | } |
Davide Italiano | 0125c63 | 2017-02-13 15:26:22 +0000 | [diff] [blame] | 673 | |
Easwaran Raman | 283d978 | 2018-01-09 19:39:35 +0000 | [diff] [blame] | 674 | // Synthesize function entry counts for non-PGO compilation. |
| 675 | if (EnableSyntheticCounts && !PGOOpt) |
| 676 | MPM.addPass(SyntheticCountsPropagation()); |
| 677 | |
Chandler Carruth | 9c24109 | 2017-02-12 05:34:04 +0000 | [diff] [blame] | 678 | // Require the GlobalsAA analysis for the module so we can query it within |
| 679 | // the CGSCC pipeline. |
| 680 | MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>()); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 681 | |
Easwaran Raman | de37aad | 2017-05-04 16:58:45 +0000 | [diff] [blame] | 682 | // Require the ProfileSummaryAnalysis for the module so we can query it within |
| 683 | // the inliner pass. |
| 684 | MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>()); |
| 685 | |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 686 | // Now begin the main postorder CGSCC pipeline. |
| 687 | // FIXME: The current CGSCC pipeline has its origins in the legacy pass |
| 688 | // manager and trying to emulate its precise behavior. Much of this doesn't |
| 689 | // make a lot of sense and we should revisit the core CGSCC structure. |
| 690 | CGSCCPassManager MainCGPipeline(DebugLogging); |
| 691 | |
| 692 | // Note: historically, the PruneEH pass was run first to deduce nounwind and |
| 693 | // generally clean up exception handling overhead. It isn't clear this is |
| 694 | // valuable as the inliner doesn't currently care whether it is inlining an |
| 695 | // invoke or a call. |
| 696 | |
| 697 | // Run the inliner first. The theory is that we are walking bottom-up and so |
| 698 | // the callees have already been fully optimized, and we want to inline them |
| 699 | // into the callers so that our optimizations can reflect that. |
Dehao Chen | 7b5ab7f | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 700 | // For PreLinkThinLTO pass, we disable hot-caller heuristic for sample PGO |
Dehao Chen | 59bf0ba | 2017-07-07 20:53:10 +0000 | [diff] [blame] | 701 | // because it makes profile annotation in the backend inaccurate. |
| 702 | InlineParams IP = getInlineParamsFromOptLevel(Level); |
Dehao Chen | 7b5ab7f | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 703 | if (Phase == ThinLTOPhase::PreLink && |
| 704 | PGOOpt && !PGOOpt->SampleProfileFile.empty()) |
Dehao Chen | 59bf0ba | 2017-07-07 20:53:10 +0000 | [diff] [blame] | 705 | IP.HotCallSiteThreshold = 0; |
| 706 | MainCGPipeline.addPass(InlinerPass(IP)); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 707 | |
| 708 | // Now deduce any function attributes based in the current code. |
| 709 | MainCGPipeline.addPass(PostOrderFunctionAttrsPass()); |
| 710 | |
Chandler Carruth | 88c0fa9 | 2017-02-09 23:54:57 +0000 | [diff] [blame] | 711 | // When at O3 add argument promotion to the pass pipeline. |
| 712 | // FIXME: It isn't at all clear why this should be limited to O3. |
| 713 | if (Level == O3) |
| 714 | MainCGPipeline.addPass(ArgumentPromotionPass()); |
| 715 | |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 716 | // Lastly, add the core function simplification pipeline nested inside the |
| 717 | // CGSCC walk. |
| 718 | MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor( |
Dehao Chen | 7b5ab7f | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 719 | buildFunctionSimplificationPipeline(Level, Phase, DebugLogging))); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 720 | |
Teresa Johnson | 70fc21b | 2018-10-23 22:57:40 +0000 | [diff] [blame] | 721 | // We only want to do hot cold splitting once for ThinLTO, during the |
| 722 | // post-link ThinLTO. |
| 723 | if (EnableHotColdSplit && Phase != ThinLTOPhase::PreLink) |
Aditya Kumar | 0ee7db4 | 2018-10-21 18:11:56 +0000 | [diff] [blame] | 724 | MPM.addPass(HotColdSplittingPass()); |
| 725 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 726 | for (auto &C : CGSCCOptimizerLateEPCallbacks) |
| 727 | C(MainCGPipeline, Level); |
| 728 | |
Chandler Carruth | 1f7ef68 | 2017-02-12 05:38:04 +0000 | [diff] [blame] | 729 | // We wrap the CGSCC pipeline in a devirtualization repeater. This will try |
| 730 | // to detect when we devirtualize indirect calls and iterate the SCC passes |
| 731 | // in that case to try and catch knock-on inlining or function attrs |
| 732 | // opportunities. Then we add it to the module pipeline by walking the SCCs |
| 733 | // in postorder (or bottom-up). |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 734 | MPM.addPass( |
Chandler Carruth | 1f7ef68 | 2017-02-12 05:38:04 +0000 | [diff] [blame] | 735 | createModuleToPostOrderCGSCCPassAdaptor(createDevirtSCCRepeatedPass( |
Chandler Carruth | 83bfb55 | 2017-08-11 05:47:13 +0000 | [diff] [blame] | 736 | std::move(MainCGPipeline), MaxDevirtIterations))); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 737 | |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 738 | return MPM; |
| 739 | } |
| 740 | |
| 741 | ModulePassManager |
| 742 | PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level, |
| 743 | bool DebugLogging) { |
| 744 | ModulePassManager MPM(DebugLogging); |
| 745 | |
| 746 | // Optimize globals now that the module is fully simplified. |
| 747 | MPM.addPass(GlobalOptPass()); |
Davide Italiano | 6bfe1d9 | 2017-10-05 18:36:01 +0000 | [diff] [blame] | 748 | MPM.addPass(GlobalDCEPass()); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 749 | |
Xinliang David Li | b9e0915 | 2017-05-22 16:41:57 +0000 | [diff] [blame] | 750 | // Run partial inlining pass to partially inline functions that have |
| 751 | // large bodies. |
| 752 | if (RunPartialInlining) |
| 753 | MPM.addPass(PartialInlinerPass()); |
| 754 | |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 755 | // Remove avail extern fns and globals definitions since we aren't compiling |
| 756 | // an object file for later LTO. For LTO we want to preserve these so they |
| 757 | // are eligible for inlining at link-time. Note if they are unreferenced they |
| 758 | // will be removed by GlobalDCE later, so this only impacts referenced |
| 759 | // available externally globals. Eventually they will be suppressed during |
| 760 | // codegen, but eliminating here enables more opportunity for GlobalDCE as it |
| 761 | // may make globals referenced by available external functions dead and saves |
| 762 | // running remaining passes on the eliminated functions. |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 763 | MPM.addPass(EliminateAvailableExternallyPass()); |
| 764 | |
| 765 | // Do RPO function attribute inference across the module to forward-propagate |
| 766 | // attributes where applicable. |
| 767 | // FIXME: Is this really an optimization rather than a canonicalization? |
| 768 | MPM.addPass(ReversePostOrderFunctionAttrsPass()); |
| 769 | |
Chandler Carruth | 9c24109 | 2017-02-12 05:34:04 +0000 | [diff] [blame] | 770 | // Re-require GloblasAA here prior to function passes. This is particularly |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 771 | // useful as the above will have inlined, DCE'ed, and function-attr |
| 772 | // propagated everything. We should at this point have a reasonably minimal |
| 773 | // and richly annotated call graph. By computing aliasing and mod/ref |
| 774 | // information for all local globals here, the late loop passes and notably |
| 775 | // the vectorizer will be able to use them to help recognize vectorizable |
| 776 | // memory operations. |
Chandler Carruth | 9c24109 | 2017-02-12 05:34:04 +0000 | [diff] [blame] | 777 | MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>()); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 778 | |
| 779 | FunctionPassManager OptimizePM(DebugLogging); |
| 780 | OptimizePM.addPass(Float2IntPass()); |
| 781 | // FIXME: We need to run some loop optimizations to re-rotate loops after |
| 782 | // simplify-cfg and others undo their rotation. |
| 783 | |
| 784 | // Optimize the loop execution. These passes operate on entire loop nests |
| 785 | // rather than on each loop in an inside-out manner, and so they are actually |
| 786 | // function passes. |
Chandler Carruth | f8e4cd6c | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 787 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 788 | for (auto &C : VectorizerStartEPCallbacks) |
| 789 | C(OptimizePM, Level); |
| 790 | |
Chandler Carruth | f8e4cd6c | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 791 | // First rotate loops that may have been un-rotated by prior passes. |
Fedor Sergeev | ffbb3d0 | 2017-12-29 08:16:06 +0000 | [diff] [blame] | 792 | OptimizePM.addPass( |
| 793 | createFunctionToLoopPassAdaptor(LoopRotatePass(), DebugLogging)); |
Chandler Carruth | f8e4cd6c | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 794 | |
| 795 | // Distribute loops to allow partial vectorization. I.e. isolate dependences |
| 796 | // into separate loop that would otherwise inhibit vectorization. This is |
| 797 | // currently only performed for loops marked with the metadata |
| 798 | // llvm.loop.distribute=true or when -enable-loop-distribute is specified. |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 799 | OptimizePM.addPass(LoopDistributePass()); |
Chandler Carruth | f8e4cd6c | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 800 | |
| 801 | // Now run the core loop vectorizer. |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 802 | OptimizePM.addPass(LoopVectorizePass()); |
Chandler Carruth | f8e4cd6c | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 803 | |
Chandler Carruth | 90fe7e7 | 2017-01-27 01:32:26 +0000 | [diff] [blame] | 804 | // Eliminate loads by forwarding stores from the previous iteration to loads |
| 805 | // of the current iteration. |
| 806 | OptimizePM.addPass(LoopLoadEliminationPass()); |
Chandler Carruth | f8e4cd6c | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 807 | |
| 808 | // Cleanup after the loop optimization passes. |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 809 | OptimizePM.addPass(InstCombinePass()); |
| 810 | |
Chandler Carruth | f8e4cd6c | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 811 | // Now that we've formed fast to execute loop structures, we do further |
| 812 | // optimizations. These are run afterward as they might block doing complex |
| 813 | // analyses and transforms such as what are needed for loop vectorization. |
| 814 | |
Sanjay Patel | 7034870 | 2017-12-14 22:05:20 +0000 | [diff] [blame] | 815 | // Cleanup after loop vectorization, etc. Simplification passes like CVP and |
| 816 | // GVN, loop transforms, and others have already run, so it's now better to |
| 817 | // convert to more optimized IR using more aggressive simplify CFG options. |
| 818 | // The extra sinking transform can create larger basic blocks, so do this |
| 819 | // before SLP vectorization. |
| 820 | OptimizePM.addPass(SimplifyCFGPass(SimplifyCFGOptions(). |
| 821 | forwardSwitchCondToPhi(true). |
| 822 | convertSwitchToLookupTable(true). |
| 823 | needCanonicalLoops(false). |
| 824 | sinkCommonInsts(true))); |
| 825 | |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 826 | // Optimize parallel scalar instruction chains into SIMD instructions. |
| 827 | OptimizePM.addPass(SLPVectorizerPass()); |
| 828 | |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 829 | OptimizePM.addPass(InstCombinePass()); |
| 830 | |
| 831 | // Unroll small loops to hide loop backedge latency and saturate any parallel |
Chandler Carruth | f8e4cd6c | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 832 | // execution resources of an out-of-order processor. We also then need to |
| 833 | // clean up redundancies and loop invariant code. |
| 834 | // FIXME: It would be really good to use a loop-integrated instruction |
| 835 | // combiner for cleanup here so that the unrolling and LICM can be pipelined |
| 836 | // across the loop nests. |
David Green | e101271 | 2018-07-01 12:47:30 +0000 | [diff] [blame] | 837 | // We do UnrollAndJam in a separate LPM to ensure it happens before unroll |
| 838 | if (EnableUnrollAndJam) { |
| 839 | OptimizePM.addPass( |
| 840 | createFunctionToLoopPassAdaptor(LoopUnrollAndJamPass(Level))); |
| 841 | } |
Fedor Sergeev | 2f9c8a0 | 2018-10-31 14:33:14 +0000 | [diff] [blame] | 842 | OptimizePM.addPass(LoopUnrollPass(LoopUnrollOptions(Level))); |
Michael Kruse | 9a395de | 2018-12-12 17:32:52 +0000 | [diff] [blame] | 843 | OptimizePM.addPass(WarnMissedTransformationsPass()); |
Chandler Carruth | f8e4cd6c | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 844 | OptimizePM.addPass(InstCombinePass()); |
Chandler Carruth | 88c0fa9 | 2017-02-09 23:54:57 +0000 | [diff] [blame] | 845 | OptimizePM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>()); |
Fedor Sergeev | ffbb3d0 | 2017-12-29 08:16:06 +0000 | [diff] [blame] | 846 | OptimizePM.addPass(createFunctionToLoopPassAdaptor(LICMPass(), DebugLogging)); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 847 | |
| 848 | // Now that we've vectorized and unrolled loops, we may have more refined |
| 849 | // alignment information, try to re-derive it here. |
| 850 | OptimizePM.addPass(AlignmentFromAssumptionsPass()); |
| 851 | |
Chandler Carruth | f8e4cd6c | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 852 | // LoopSink pass sinks instructions hoisted by LICM, which serves as a |
| 853 | // canonicalization pass that enables other optimizations. As a result, |
| 854 | // LoopSink pass needs to be a very late IR pass to avoid undoing LICM |
| 855 | // result too early. |
| 856 | OptimizePM.addPass(LoopSinkPass()); |
| 857 | |
| 858 | // And finally clean up LCSSA form before generating code. |
Chandler Carruth | b2b950d | 2018-06-29 23:36:03 +0000 | [diff] [blame] | 859 | OptimizePM.addPass(InstSimplifyPass()); |
Chandler Carruth | f8e4cd6c | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 860 | |
Sanjay Patel | 193e898 | 2017-09-09 13:38:18 +0000 | [diff] [blame] | 861 | // This hoists/decomposes div/rem ops. It should run after other sink/hoist |
| 862 | // passes to avoid re-sinking, but before SimplifyCFG because it can allow |
| 863 | // flattening of blocks. |
| 864 | OptimizePM.addPass(DivRemPairsPass()); |
| 865 | |
Filipe Cabecinhas | 70c9b6a | 2017-04-26 12:02:41 +0000 | [diff] [blame] | 866 | // LoopSink (and other loop passes since the last simplifyCFG) might have |
| 867 | // resulted in single-entry-single-exit or empty blocks. Clean up the CFG. |
| 868 | OptimizePM.addPass(SimplifyCFGPass()); |
| 869 | |
Chandler Carruth | 6efdd0f | 2017-11-28 11:32:31 +0000 | [diff] [blame] | 870 | // Optimize PHIs by speculating around them when profitable. Note that this |
| 871 | // pass needs to be run after any PRE or similar pass as it is essentially |
| 872 | // inserting redudnancies into the progrem. This even includes SimplifyCFG. |
| 873 | OptimizePM.addPass(SpeculateAroundPHIsPass()); |
| 874 | |
Philip Pfaffe | 0c20a4d | 2018-11-12 11:17:07 +0000 | [diff] [blame] | 875 | for (auto &C : OptimizerLastEPCallbacks) |
| 876 | C(OptimizePM, Level); |
| 877 | |
Chandler Carruth | f8e4cd6c | 2017-01-27 00:50:21 +0000 | [diff] [blame] | 878 | // Add the core optimizing pipeline. |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 879 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM))); |
| 880 | |
Michael J. Spencer | 3da6ce5 | 2018-07-16 00:28:24 +0000 | [diff] [blame] | 881 | MPM.addPass(CGProfilePass()); |
| 882 | |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 883 | // Now we need to do some global optimization transforms. |
| 884 | // FIXME: It would seem like these should come first in the optimization |
| 885 | // pipeline and maybe be the bottom of the canonicalization pipeline? Weird |
| 886 | // ordering here. |
| 887 | MPM.addPass(GlobalDCEPass()); |
| 888 | MPM.addPass(ConstantMergePass()); |
| 889 | |
| 890 | return MPM; |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 891 | } |
| 892 | |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 893 | ModulePassManager |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 894 | PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level, |
| 895 | bool DebugLogging) { |
| 896 | assert(Level != O0 && "Must request optimizations for the default pipeline!"); |
| 897 | |
| 898 | ModulePassManager MPM(DebugLogging); |
| 899 | |
| 900 | // Force any function attributes we want the rest of the pipeline to observe. |
| 901 | MPM.addPass(ForceFunctionAttrsPass()); |
| 902 | |
David Blaikie | 0ac8747 | 2018-01-23 01:25:20 +0000 | [diff] [blame] | 903 | // Apply module pipeline start EP callback. |
| 904 | for (auto &C : PipelineStartEPCallbacks) |
| 905 | C(MPM); |
| 906 | |
Dehao Chen | 6858db5 | 2017-08-07 20:23:20 +0000 | [diff] [blame] | 907 | if (PGOOpt && PGOOpt->SamplePGOSupport) |
Dehao Chen | 04fe17a | 2017-07-29 04:10:24 +0000 | [diff] [blame] | 908 | MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass())); |
| 909 | |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 910 | // Add the core simplification pipeline. |
Dehao Chen | 7b5ab7f | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 911 | MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::None, |
| 912 | DebugLogging)); |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 913 | |
| 914 | // Now add the optimization pipeline. |
| 915 | MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging)); |
| 916 | |
| 917 | return MPM; |
| 918 | } |
| 919 | |
| 920 | ModulePassManager |
| 921 | PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level, |
| 922 | bool DebugLogging) { |
| 923 | assert(Level != O0 && "Must request optimizations for the default pipeline!"); |
| 924 | |
| 925 | ModulePassManager MPM(DebugLogging); |
| 926 | |
| 927 | // Force any function attributes we want the rest of the pipeline to observe. |
| 928 | MPM.addPass(ForceFunctionAttrsPass()); |
| 929 | |
Dehao Chen | 6858db5 | 2017-08-07 20:23:20 +0000 | [diff] [blame] | 930 | if (PGOOpt && PGOOpt->SamplePGOSupport) |
Dehao Chen | 04fe17a | 2017-07-29 04:10:24 +0000 | [diff] [blame] | 931 | MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass())); |
| 932 | |
David Blaikie | 0ac8747 | 2018-01-23 01:25:20 +0000 | [diff] [blame] | 933 | // Apply module pipeline start EP callback. |
| 934 | for (auto &C : PipelineStartEPCallbacks) |
| 935 | C(MPM); |
| 936 | |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 937 | // If we are planning to perform ThinLTO later, we don't bloat the code with |
| 938 | // unrolling/vectorization/... now. Just simplify the module as much as we |
| 939 | // can. |
Dehao Chen | 7b5ab7f | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 940 | MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PreLink, |
| 941 | DebugLogging)); |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 942 | |
| 943 | // Run partial inlining pass to partially inline functions that have |
| 944 | // large bodies. |
| 945 | // FIXME: It isn't clear whether this is really the right place to run this |
| 946 | // in ThinLTO. Because there is another canonicalization and simplification |
| 947 | // phase that will run after the thin link, running this here ends up with |
| 948 | // less information than will be available later and it may grow functions in |
| 949 | // ways that aren't beneficial. |
| 950 | if (RunPartialInlining) |
| 951 | MPM.addPass(PartialInlinerPass()); |
| 952 | |
| 953 | // Reduce the size of the IR as much as possible. |
| 954 | MPM.addPass(GlobalOptPass()); |
| 955 | |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 956 | return MPM; |
| 957 | } |
| 958 | |
Teresa Johnson | 2a478d4 | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 959 | ModulePassManager PassBuilder::buildThinLTODefaultPipeline( |
| 960 | OptimizationLevel Level, bool DebugLogging, |
| 961 | const ModuleSummaryIndex *ImportSummary) { |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 962 | ModulePassManager MPM(DebugLogging); |
| 963 | |
Teresa Johnson | 2a478d4 | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 964 | if (ImportSummary) { |
| 965 | // These passes import type identifier resolutions for whole-program |
| 966 | // devirtualization and CFI. They must run early because other passes may |
| 967 | // disturb the specific instruction patterns that these passes look for, |
| 968 | // creating dependencies on resolutions that may not appear in the summary. |
| 969 | // |
| 970 | // For example, GVN may transform the pattern assume(type.test) appearing in |
| 971 | // two basic blocks into assume(phi(type.test, type.test)), which would |
| 972 | // transform a dependency on a WPD resolution into a dependency on a type |
| 973 | // identifier resolution for CFI. |
| 974 | // |
| 975 | // Also, WPD has access to more precise information than ICP and can |
| 976 | // devirtualize more effectively, so it should operate on the IR first. |
| 977 | MPM.addPass(WholeProgramDevirtPass(nullptr, ImportSummary)); |
| 978 | MPM.addPass(LowerTypeTestsPass(nullptr, ImportSummary)); |
| 979 | } |
| 980 | |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 981 | // Force any function attributes we want the rest of the pipeline to observe. |
| 982 | MPM.addPass(ForceFunctionAttrsPass()); |
| 983 | |
| 984 | // During the ThinLTO backend phase we perform early indirect call promotion |
| 985 | // here, before globalopt. Otherwise imported available_externally functions |
| 986 | // look unreferenced and are removed. |
Dehao Chen | 6858db5 | 2017-08-07 20:23:20 +0000 | [diff] [blame] | 987 | // FIXME: move this into buildModuleSimplificationPipeline to merge the logic |
| 988 | // with SamplePGO. |
Dehao Chen | a3b8ce3 | 2017-08-10 05:10:32 +0000 | [diff] [blame] | 989 | if (!PGOOpt || PGOOpt->SampleProfileFile.empty()) |
Dehao Chen | 6858db5 | 2017-08-07 20:23:20 +0000 | [diff] [blame] | 990 | MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */, |
| 991 | false /* SamplePGO */)); |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 992 | |
| 993 | // Add the core simplification pipeline. |
Dehao Chen | 7b5ab7f | 2017-07-30 04:55:39 +0000 | [diff] [blame] | 994 | MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PostLink, |
| 995 | DebugLogging)); |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 996 | |
| 997 | // Now add the optimization pipeline. |
| 998 | MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging)); |
| 999 | |
| 1000 | return MPM; |
| 1001 | } |
| 1002 | |
| 1003 | ModulePassManager |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1004 | PassBuilder::buildLTOPreLinkDefaultPipeline(OptimizationLevel Level, |
| 1005 | bool DebugLogging) { |
| 1006 | assert(Level != O0 && "Must request optimizations for the default pipeline!"); |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1007 | // FIXME: We should use a customized pre-link pipeline! |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1008 | return buildPerModuleDefaultPipeline(Level, DebugLogging); |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
Teresa Johnson | 2a478d4 | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1011 | ModulePassManager |
| 1012 | PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level, bool DebugLogging, |
| 1013 | ModuleSummaryIndex *ExportSummary) { |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1014 | assert(Level != O0 && "Must request optimizations for the default pipeline!"); |
| 1015 | ModulePassManager MPM(DebugLogging); |
| 1016 | |
Xin Tong | eb1caa7 | 2018-11-15 18:06:42 +0000 | [diff] [blame] | 1017 | if (PGOOpt && !PGOOpt->SampleProfileFile.empty()) { |
| 1018 | // Load sample profile before running the LTO optimization pipeline. |
| 1019 | MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile, |
| 1020 | PGOOpt->ProfileRemappingFile, |
| 1021 | false /* ThinLTOPhase::PreLink */)); |
| 1022 | } |
| 1023 | |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1024 | // Remove unused virtual tables to improve the quality of code generated by |
| 1025 | // whole-program devirtualization and bitset lowering. |
| 1026 | MPM.addPass(GlobalDCEPass()); |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1027 | |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1028 | // Force any function attributes we want the rest of the pipeline to observe. |
| 1029 | MPM.addPass(ForceFunctionAttrsPass()); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1030 | |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1031 | // Do basic inference of function attributes from known properties of system |
| 1032 | // libraries and other oracles. |
| 1033 | MPM.addPass(InferFunctionAttrsPass()); |
| 1034 | |
| 1035 | if (Level > 1) { |
Jun Bum Lim | f4beb75 | 2017-11-03 20:41:16 +0000 | [diff] [blame] | 1036 | FunctionPassManager EarlyFPM(DebugLogging); |
| 1037 | EarlyFPM.addPass(CallSiteSplittingPass()); |
| 1038 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM))); |
| 1039 | |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1040 | // Indirect call promotion. This should promote all the targets that are |
| 1041 | // left by the earlier promotion pass that promotes intra-module targets. |
| 1042 | // This two-step promotion is to save the compile time. For LTO, it should |
| 1043 | // produce the same result as if we only do promotion here. |
Dehao Chen | ade8407 | 2017-06-29 23:33:05 +0000 | [diff] [blame] | 1044 | MPM.addPass(PGOIndirectCallPromotion( |
| 1045 | true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty())); |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1046 | // Propagate constants at call sites into the functions they call. This |
| 1047 | // opens opportunities for globalopt (and inlining) by substituting function |
| 1048 | // pointers passed as arguments to direct uses of functions. |
| 1049 | MPM.addPass(IPSCCPPass()); |
Matthew Simpson | 7d6a3b6 | 2017-10-25 13:40:08 +0000 | [diff] [blame] | 1050 | |
| 1051 | // Attach metadata to indirect call sites indicating the set of functions |
| 1052 | // they may target at run-time. This should follow IPSCCP. |
| 1053 | MPM.addPass(CalledValuePropagationPass()); |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | // Now deduce any function attributes based in the current code. |
| 1057 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor( |
| 1058 | PostOrderFunctionAttrsPass())); |
| 1059 | |
| 1060 | // Do RPO function attribute inference across the module to forward-propagate |
| 1061 | // attributes where applicable. |
| 1062 | // FIXME: Is this really an optimization rather than a canonicalization? |
| 1063 | MPM.addPass(ReversePostOrderFunctionAttrsPass()); |
| 1064 | |
| 1065 | // Use inragne annotations on GEP indices to split globals where beneficial. |
| 1066 | MPM.addPass(GlobalSplitPass()); |
| 1067 | |
| 1068 | // Run whole program optimization of virtual call when the list of callees |
| 1069 | // is fixed. |
Teresa Johnson | 2a478d4 | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1070 | MPM.addPass(WholeProgramDevirtPass(ExportSummary, nullptr)); |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1071 | |
| 1072 | // Stop here at -O1. |
Teresa Johnson | 2a478d4 | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1073 | if (Level == 1) { |
| 1074 | // The LowerTypeTestsPass needs to run to lower type metadata and the |
| 1075 | // type.test intrinsics. The pass does nothing if CFI is disabled. |
| 1076 | MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr)); |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1077 | return MPM; |
Teresa Johnson | 2a478d4 | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1078 | } |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1079 | |
| 1080 | // Optimize globals to try and fold them into constants. |
| 1081 | MPM.addPass(GlobalOptPass()); |
| 1082 | |
| 1083 | // Promote any localized globals to SSA registers. |
| 1084 | MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass())); |
| 1085 | |
| 1086 | // Linking modules together can lead to duplicate global constant, only |
| 1087 | // keep one copy of each constant. |
| 1088 | MPM.addPass(ConstantMergePass()); |
| 1089 | |
| 1090 | // Remove unused arguments from functions. |
| 1091 | MPM.addPass(DeadArgumentEliminationPass()); |
| 1092 | |
| 1093 | // Reduce the code after globalopt and ipsccp. Both can open up significant |
| 1094 | // simplification opportunities, and both can propagate functions through |
| 1095 | // function pointers. When this happens, we often have to resolve varargs |
| 1096 | // calls, etc, so let instcombine do this. |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1097 | FunctionPassManager PeepholeFPM(DebugLogging); |
Amjad Aboud | c6483fb | 2018-01-25 12:06:32 +0000 | [diff] [blame] | 1098 | if (Level == O3) |
| 1099 | PeepholeFPM.addPass(AggressiveInstCombinePass()); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1100 | PeepholeFPM.addPass(InstCombinePass()); |
| 1101 | invokePeepholeEPCallbacks(PeepholeFPM, Level); |
| 1102 | |
| 1103 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(PeepholeFPM))); |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1104 | |
| 1105 | // Note: historically, the PruneEH pass was run first to deduce nounwind and |
| 1106 | // generally clean up exception handling overhead. It isn't clear this is |
| 1107 | // valuable as the inliner doesn't currently care whether it is inlining an |
| 1108 | // invoke or a call. |
| 1109 | // Run the inliner now. |
Easwaran Raman | 4459676 | 2017-06-28 13:33:49 +0000 | [diff] [blame] | 1110 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor( |
| 1111 | InlinerPass(getInlineParamsFromOptLevel(Level)))); |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1112 | |
| 1113 | // Optimize globals again after we ran the inliner. |
| 1114 | MPM.addPass(GlobalOptPass()); |
| 1115 | |
| 1116 | // Garbage collect dead functions. |
| 1117 | // FIXME: Add ArgumentPromotion pass after once it's ported. |
| 1118 | MPM.addPass(GlobalDCEPass()); |
| 1119 | |
| 1120 | FunctionPassManager FPM(DebugLogging); |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1121 | // The IPO Passes may leave cruft around. Clean up after them. |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1122 | FPM.addPass(InstCombinePass()); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1123 | invokePeepholeEPCallbacks(FPM, Level); |
| 1124 | |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1125 | FPM.addPass(JumpThreadingPass()); |
| 1126 | |
| 1127 | // Break up allocas |
| 1128 | FPM.addPass(SROA()); |
| 1129 | |
| 1130 | // Run a few AA driver optimizations here and now to cleanup the code. |
| 1131 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
| 1132 | |
| 1133 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor( |
| 1134 | PostOrderFunctionAttrsPass())); |
| 1135 | // FIXME: here we run IP alias analysis in the legacy PM. |
| 1136 | |
| 1137 | FunctionPassManager MainFPM; |
| 1138 | |
| 1139 | // FIXME: once we fix LoopPass Manager, add LICM here. |
| 1140 | // FIXME: once we provide support for enabling MLSM, add it here. |
| 1141 | // FIXME: once we provide support for enabling NewGVN, add it here. |
Davide Italiano | efb6b10 | 2017-05-22 23:41:40 +0000 | [diff] [blame] | 1142 | if (RunNewGVN) |
| 1143 | MainFPM.addPass(NewGVNPass()); |
| 1144 | else |
| 1145 | MainFPM.addPass(GVN()); |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1146 | |
| 1147 | // Remove dead memcpy()'s. |
| 1148 | MainFPM.addPass(MemCpyOptPass()); |
| 1149 | |
| 1150 | // Nuke dead stores. |
| 1151 | MainFPM.addPass(DSEPass()); |
| 1152 | |
| 1153 | // FIXME: at this point, we run a bunch of loop passes: |
| 1154 | // indVarSimplify, loopDeletion, loopInterchange, loopUnrool, |
| 1155 | // loopVectorize. Enable them once the remaining issue with LPM |
| 1156 | // are sorted out. |
| 1157 | |
| 1158 | MainFPM.addPass(InstCombinePass()); |
| 1159 | MainFPM.addPass(SimplifyCFGPass()); |
| 1160 | MainFPM.addPass(SCCPPass()); |
| 1161 | MainFPM.addPass(InstCombinePass()); |
| 1162 | MainFPM.addPass(BDCEPass()); |
| 1163 | |
| 1164 | // FIXME: We may want to run SLPVectorizer here. |
| 1165 | // After vectorization, assume intrinsics may tell us more |
| 1166 | // about pointer alignments. |
| 1167 | #if 0 |
| 1168 | MainFPM.add(AlignmentFromAssumptionsPass()); |
| 1169 | #endif |
| 1170 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1171 | // FIXME: Conditionally run LoadCombine here, after it's ported |
| 1172 | // (in case we still have this pass, given its questionable usefulness). |
| 1173 | |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1174 | MainFPM.addPass(InstCombinePass()); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1175 | invokePeepholeEPCallbacks(MainFPM, Level); |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1176 | MainFPM.addPass(JumpThreadingPass()); |
| 1177 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(MainFPM))); |
| 1178 | |
| 1179 | // Create a function that performs CFI checks for cross-DSO calls with |
| 1180 | // targets in the current module. |
| 1181 | MPM.addPass(CrossDSOCFIPass()); |
| 1182 | |
| 1183 | // Lower type metadata and the type.test intrinsic. This pass supports |
| 1184 | // clang's control flow integrity mechanisms (-fsanitize=cfi*) and needs |
| 1185 | // to be run at link time if CFI is enabled. This pass does nothing if |
| 1186 | // CFI is disabled. |
Teresa Johnson | 2a478d4 | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1187 | MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr)); |
Davide Italiano | 6fe089f | 2017-01-24 00:57:39 +0000 | [diff] [blame] | 1188 | |
| 1189 | // Add late LTO optimization passes. |
| 1190 | // Delete basic blocks, which optimization passes may have killed. |
| 1191 | MPM.addPass(createModuleToFunctionPassAdaptor(SimplifyCFGPass())); |
| 1192 | |
| 1193 | // Drop bodies of available eternally objects to improve GlobalDCE. |
| 1194 | MPM.addPass(EliminateAvailableExternallyPass()); |
| 1195 | |
| 1196 | // Now that we have optimized the program, discard unreachable functions. |
| 1197 | MPM.addPass(GlobalDCEPass()); |
| 1198 | |
| 1199 | // FIXME: Enable MergeFuncs, conditionally, after ported, maybe. |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1200 | return MPM; |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
Chandler Carruth | 759dd39 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 1203 | AAManager PassBuilder::buildDefaultAAPipeline() { |
| 1204 | AAManager AA; |
| 1205 | |
| 1206 | // The order in which these are registered determines their priority when |
| 1207 | // being queried. |
| 1208 | |
| 1209 | // First we register the basic alias analysis that provides the majority of |
| 1210 | // per-function local AA logic. This is a stateless, on-demand local set of |
| 1211 | // AA techniques. |
| 1212 | AA.registerFunctionAnalysis<BasicAA>(); |
| 1213 | |
| 1214 | // Next we query fast, specialized alias analyses that wrap IR-embedded |
| 1215 | // information about aliasing. |
| 1216 | AA.registerFunctionAnalysis<ScopedNoAliasAA>(); |
| 1217 | AA.registerFunctionAnalysis<TypeBasedAA>(); |
| 1218 | |
| 1219 | // Add support for querying global aliasing information when available. |
Chandler Carruth | 356e45b | 2016-12-24 05:11:17 +0000 | [diff] [blame] | 1220 | // Because the `AAManager` is a function analysis and `GlobalsAA` is a module |
| 1221 | // analysis, all that the `AAManager` can do is query for any *cached* |
Chandler Carruth | 9c24109 | 2017-02-12 05:34:04 +0000 | [diff] [blame] | 1222 | // results from `GlobalsAA` through a readonly proxy. |
Chandler Carruth | 759dd39 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 1223 | AA.registerModuleAnalysis<GlobalsAA>(); |
Chandler Carruth | 759dd39 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 1224 | |
| 1225 | return AA; |
| 1226 | } |
| 1227 | |
Chandler Carruth | 91b6bfa | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1228 | static Optional<int> parseRepeatPassName(StringRef Name) { |
| 1229 | if (!Name.consume_front("repeat<") || !Name.consume_back(">")) |
| 1230 | return None; |
| 1231 | int Count; |
| 1232 | if (Name.getAsInteger(0, Count) || Count <= 0) |
| 1233 | return None; |
| 1234 | return Count; |
| 1235 | } |
| 1236 | |
Chandler Carruth | 86d5365 | 2016-12-28 11:07:33 +0000 | [diff] [blame] | 1237 | static Optional<int> parseDevirtPassName(StringRef Name) { |
| 1238 | if (!Name.consume_front("devirt<") || !Name.consume_back(">")) |
| 1239 | return None; |
| 1240 | int Count; |
| 1241 | if (Name.getAsInteger(0, Count) || Count <= 0) |
| 1242 | return None; |
| 1243 | return Count; |
| 1244 | } |
| 1245 | |
Fedor Sergeev | 4f41c19 | 2019-01-10 10:01:53 +0000 | [diff] [blame] | 1246 | static bool checkParametrizedPassName(StringRef Name, StringRef PassName) { |
| 1247 | if (!Name.consume_front(PassName)) |
| 1248 | return false; |
| 1249 | // normal pass name w/o parameters == default parameters |
| 1250 | if (Name.empty()) |
| 1251 | return true; |
| 1252 | return Name.startswith("<") && Name.endswith(">"); |
| 1253 | } |
| 1254 | |
| 1255 | namespace { |
| 1256 | |
| 1257 | /// This performs customized parsing of pass name with parameters. |
| 1258 | /// |
| 1259 | /// We do not need parametrization of passes in textual pipeline very often, |
| 1260 | /// yet on a rare occasion ability to specify parameters right there can be |
| 1261 | /// useful. |
| 1262 | /// |
| 1263 | /// \p Name - parameterized specification of a pass from a textual pipeline |
| 1264 | /// is a string in a form of : |
| 1265 | /// PassName '<' parameter-list '>' |
| 1266 | /// |
| 1267 | /// Parameter list is being parsed by the parser callable argument, \p Parser, |
| 1268 | /// It takes a string-ref of parameters and returns either StringError or a |
| 1269 | /// parameter list in a form of a custom parameters type, all wrapped into |
| 1270 | /// Expected<> template class. |
| 1271 | /// |
| 1272 | template <typename ParametersParseCallableT> |
| 1273 | auto parsePassParameters(ParametersParseCallableT &&Parser, StringRef Name, |
| 1274 | StringRef PassName) -> decltype(Parser(StringRef{})) { |
| 1275 | using ParametersT = typename decltype(Parser(StringRef{}))::value_type; |
| 1276 | |
| 1277 | StringRef Params = Name; |
| 1278 | if (!Params.consume_front(PassName)) { |
| 1279 | assert(false && |
| 1280 | "unable to strip pass name from parametrized pass specification"); |
| 1281 | } |
| 1282 | if (Params.empty()) |
| 1283 | return ParametersT{}; |
| 1284 | if (!Params.consume_front("<") || !Params.consume_back(">")) { |
| 1285 | assert(false && "invalid format for parametrized pass name"); |
| 1286 | } |
| 1287 | |
| 1288 | Expected<ParametersT> Result = Parser(Params); |
| 1289 | assert((Result || Result.template errorIsA<StringError>()) && |
| 1290 | "Pass parameter parser can only return StringErrors."); |
| 1291 | return std::move(Result); |
| 1292 | } |
| 1293 | |
| 1294 | /// Parser of parameters for LoopUnroll pass. |
| 1295 | Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) { |
| 1296 | LoopUnrollOptions UnrollOpts; |
| 1297 | while (!Params.empty()) { |
| 1298 | StringRef ParamName; |
| 1299 | std::tie(ParamName, Params) = Params.split(';'); |
| 1300 | int OptLevel = StringSwitch<int>(ParamName) |
| 1301 | .Case("O0", 0) |
| 1302 | .Case("O1", 1) |
| 1303 | .Case("O2", 2) |
| 1304 | .Case("O3", 3) |
| 1305 | .Default(-1); |
| 1306 | if (OptLevel >= 0) { |
| 1307 | UnrollOpts.setOptLevel(OptLevel); |
| 1308 | continue; |
| 1309 | } |
| 1310 | |
| 1311 | bool Enable = !ParamName.consume_front("no-"); |
| 1312 | if (ParamName == "partial") { |
| 1313 | UnrollOpts.setPartial(Enable); |
| 1314 | } else if (ParamName == "peeling") { |
| 1315 | UnrollOpts.setPeeling(Enable); |
| 1316 | } else if (ParamName == "runtime") { |
| 1317 | UnrollOpts.setRuntime(Enable); |
| 1318 | } else if (ParamName == "upperbound") { |
| 1319 | UnrollOpts.setUpperBound(Enable); |
| 1320 | } else { |
| 1321 | return make_error<StringError>( |
| 1322 | formatv("invalid LoopUnrollPass parameter '{0}' ", ParamName).str(), |
| 1323 | inconvertibleErrorCode()); |
| 1324 | } |
| 1325 | } |
| 1326 | return UnrollOpts; |
| 1327 | } |
| 1328 | |
| 1329 | } // namespace |
| 1330 | |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1331 | /// Tests whether a pass name starts with a valid prefix for a default pipeline |
| 1332 | /// alias. |
| 1333 | static bool startsWithDefaultPipelineAliasPrefix(StringRef Name) { |
| 1334 | return Name.startswith("default") || Name.startswith("thinlto") || |
| 1335 | Name.startswith("lto"); |
| 1336 | } |
| 1337 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1338 | /// Tests whether registered callbacks will accept a given pass name. |
| 1339 | /// |
| 1340 | /// When parsing a pipeline text, the type of the outermost pipeline may be |
| 1341 | /// omitted, in which case the type is automatically determined from the first |
| 1342 | /// pass name in the text. This may be a name that is handled through one of the |
| 1343 | /// callbacks. We check this through the oridinary parsing callbacks by setting |
| 1344 | /// up a dummy PassManager in order to not force the client to also handle this |
| 1345 | /// type of query. |
| 1346 | template <typename PassManagerT, typename CallbacksT> |
| 1347 | static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) { |
| 1348 | if (!Callbacks.empty()) { |
| 1349 | PassManagerT DummyPM; |
| 1350 | for (auto &CB : Callbacks) |
| 1351 | if (CB(Name, DummyPM, {})) |
| 1352 | return true; |
| 1353 | } |
| 1354 | return false; |
| 1355 | } |
| 1356 | |
| 1357 | template <typename CallbacksT> |
| 1358 | static bool isModulePassName(StringRef Name, CallbacksT &Callbacks) { |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1359 | // Manually handle aliases for pre-configured pipeline fragments. |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1360 | if (startsWithDefaultPipelineAliasPrefix(Name)) |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1361 | return DefaultAliasRegex.match(Name); |
| 1362 | |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1363 | // Explicitly handle pass manager names. |
| 1364 | if (Name == "module") |
| 1365 | return true; |
| 1366 | if (Name == "cgscc") |
| 1367 | return true; |
| 1368 | if (Name == "function") |
| 1369 | return true; |
| 1370 | |
Chandler Carruth | 91b6bfa | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1371 | // Explicitly handle custom-parsed pass names. |
| 1372 | if (parseRepeatPassName(Name)) |
| 1373 | return true; |
| 1374 | |
Chandler Carruth | bd6882c | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 1375 | #define MODULE_PASS(NAME, CREATE_PASS) \ |
| 1376 | if (Name == NAME) \ |
| 1377 | return true; |
Chandler Carruth | a3376d2 | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1378 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 17395fa | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 1379 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
Chandler Carruth | a3376d2 | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1380 | return true; |
| 1381 | #include "PassRegistry.def" |
| 1382 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1383 | return callbacksAcceptPassName<ModulePassManager>(Name, Callbacks); |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1386 | template <typename CallbacksT> |
| 1387 | static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks) { |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1388 | // Explicitly handle pass manager names. |
| 1389 | if (Name == "cgscc") |
| 1390 | return true; |
| 1391 | if (Name == "function") |
| 1392 | return true; |
| 1393 | |
Chandler Carruth | 91b6bfa | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1394 | // Explicitly handle custom-parsed pass names. |
| 1395 | if (parseRepeatPassName(Name)) |
| 1396 | return true; |
Chandler Carruth | 86d5365 | 2016-12-28 11:07:33 +0000 | [diff] [blame] | 1397 | if (parseDevirtPassName(Name)) |
| 1398 | return true; |
Chandler Carruth | 91b6bfa | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1399 | |
Chandler Carruth | bd6882c | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 1400 | #define CGSCC_PASS(NAME, CREATE_PASS) \ |
| 1401 | if (Name == NAME) \ |
| 1402 | return true; |
Chandler Carruth | a3376d2 | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1403 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 17395fa | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 1404 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
Chandler Carruth | a3376d2 | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1405 | return true; |
| 1406 | #include "PassRegistry.def" |
| 1407 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1408 | return callbacksAcceptPassName<CGSCCPassManager>(Name, Callbacks); |
Chandler Carruth | 57418d8 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1411 | template <typename CallbacksT> |
| 1412 | static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks) { |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1413 | // Explicitly handle pass manager names. |
| 1414 | if (Name == "function") |
| 1415 | return true; |
| 1416 | if (Name == "loop") |
| 1417 | return true; |
| 1418 | |
Chandler Carruth | 91b6bfa | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1419 | // Explicitly handle custom-parsed pass names. |
| 1420 | if (parseRepeatPassName(Name)) |
| 1421 | return true; |
| 1422 | |
Chandler Carruth | bd6882c | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 1423 | #define FUNCTION_PASS(NAME, CREATE_PASS) \ |
| 1424 | if (Name == NAME) \ |
| 1425 | return true; |
Fedor Sergeev | 4f41c19 | 2019-01-10 10:01:53 +0000 | [diff] [blame] | 1426 | #define FUNCTION_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \ |
| 1427 | if (checkParametrizedPassName(Name, NAME)) \ |
| 1428 | return true; |
Chandler Carruth | a3376d2 | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1429 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
Chandler Carruth | 17395fa | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 1430 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
Chandler Carruth | a3376d2 | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1431 | return true; |
| 1432 | #include "PassRegistry.def" |
| 1433 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1434 | return callbacksAcceptPassName<FunctionPassManager>(Name, Callbacks); |
Chandler Carruth | e768765 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 1435 | } |
| 1436 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1437 | template <typename CallbacksT> |
| 1438 | static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks) { |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1439 | // Explicitly handle pass manager names. |
| 1440 | if (Name == "loop") |
| 1441 | return true; |
| 1442 | |
Chandler Carruth | 91b6bfa | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1443 | // Explicitly handle custom-parsed pass names. |
| 1444 | if (parseRepeatPassName(Name)) |
| 1445 | return true; |
| 1446 | |
Chandler Carruth | bd6882c | 2016-06-17 07:15:29 +0000 | [diff] [blame] | 1447 | #define LOOP_PASS(NAME, CREATE_PASS) \ |
| 1448 | if (Name == NAME) \ |
| 1449 | return true; |
Justin Bogner | da5e924 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1450 | #define LOOP_ANALYSIS(NAME, CREATE_PASS) \ |
| 1451 | if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ |
| 1452 | return true; |
| 1453 | #include "PassRegistry.def" |
| 1454 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1455 | return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks); |
Justin Bogner | da5e924 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1458 | Optional<std::vector<PassBuilder::PipelineElement>> |
| 1459 | PassBuilder::parsePipelineText(StringRef Text) { |
| 1460 | std::vector<PipelineElement> ResultPipeline; |
| 1461 | |
| 1462 | SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = { |
| 1463 | &ResultPipeline}; |
| 1464 | for (;;) { |
| 1465 | std::vector<PipelineElement> &Pipeline = *PipelineStack.back(); |
| 1466 | size_t Pos = Text.find_first_of(",()"); |
| 1467 | Pipeline.push_back({Text.substr(0, Pos), {}}); |
| 1468 | |
| 1469 | // If we have a single terminating name, we're done. |
| 1470 | if (Pos == Text.npos) |
| 1471 | break; |
| 1472 | |
| 1473 | char Sep = Text[Pos]; |
| 1474 | Text = Text.substr(Pos + 1); |
| 1475 | if (Sep == ',') |
| 1476 | // Just a name ending in a comma, continue. |
| 1477 | continue; |
| 1478 | |
| 1479 | if (Sep == '(') { |
| 1480 | // Push the inner pipeline onto the stack to continue processing. |
| 1481 | PipelineStack.push_back(&Pipeline.back().InnerPipeline); |
| 1482 | continue; |
| 1483 | } |
| 1484 | |
| 1485 | assert(Sep == ')' && "Bogus separator!"); |
| 1486 | // When handling the close parenthesis, we greedily consume them to avoid |
| 1487 | // empty strings in the pipeline. |
| 1488 | do { |
| 1489 | // If we try to pop the outer pipeline we have unbalanced parentheses. |
| 1490 | if (PipelineStack.size() == 1) |
| 1491 | return None; |
| 1492 | |
| 1493 | PipelineStack.pop_back(); |
| 1494 | } while (Text.consume_front(")")); |
| 1495 | |
| 1496 | // Check if we've finished parsing. |
| 1497 | if (Text.empty()) |
| 1498 | break; |
| 1499 | |
| 1500 | // Otherwise, the end of an inner pipeline always has to be followed by |
| 1501 | // a comma, and then we can continue. |
| 1502 | if (!Text.consume_front(",")) |
| 1503 | return None; |
| 1504 | } |
| 1505 | |
| 1506 | if (PipelineStack.size() > 1) |
| 1507 | // Unbalanced paretheses. |
| 1508 | return None; |
| 1509 | |
| 1510 | assert(PipelineStack.back() == &ResultPipeline && |
| 1511 | "Wrong pipeline at the bottom of the stack!"); |
| 1512 | return {std::move(ResultPipeline)}; |
| 1513 | } |
| 1514 | |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1515 | Error PassBuilder::parseModulePass(ModulePassManager &MPM, |
| 1516 | const PipelineElement &E, |
| 1517 | bool VerifyEachPass, bool DebugLogging) { |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1518 | auto &Name = E.Name; |
| 1519 | auto &InnerPipeline = E.InnerPipeline; |
| 1520 | |
| 1521 | // First handle complex passes like the pass managers which carry pipelines. |
| 1522 | if (!InnerPipeline.empty()) { |
| 1523 | if (Name == "module") { |
| 1524 | ModulePassManager NestedMPM(DebugLogging); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1525 | if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline, |
| 1526 | VerifyEachPass, DebugLogging)) |
| 1527 | return Err; |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1528 | MPM.addPass(std::move(NestedMPM)); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1529 | return Error::success(); |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1530 | } |
| 1531 | if (Name == "cgscc") { |
| 1532 | CGSCCPassManager CGPM(DebugLogging); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1533 | if (auto Err = parseCGSCCPassPipeline(CGPM, InnerPipeline, VerifyEachPass, |
| 1534 | DebugLogging)) |
| 1535 | return Err; |
Chandler Carruth | 83bfb55 | 2017-08-11 05:47:13 +0000 | [diff] [blame] | 1536 | MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM))); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1537 | return Error::success(); |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1538 | } |
| 1539 | if (Name == "function") { |
| 1540 | FunctionPassManager FPM(DebugLogging); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1541 | if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline, |
| 1542 | VerifyEachPass, DebugLogging)) |
| 1543 | return Err; |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1544 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1545 | return Error::success(); |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1546 | } |
Chandler Carruth | 91b6bfa | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1547 | if (auto Count = parseRepeatPassName(Name)) { |
| 1548 | ModulePassManager NestedMPM(DebugLogging); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1549 | if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline, |
| 1550 | VerifyEachPass, DebugLogging)) |
| 1551 | return Err; |
Chandler Carruth | 411e616 | 2016-08-04 03:52:53 +0000 | [diff] [blame] | 1552 | MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM))); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1553 | return Error::success(); |
Chandler Carruth | 91b6bfa | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1554 | } |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1555 | |
| 1556 | for (auto &C : ModulePipelineParsingCallbacks) |
| 1557 | if (C(Name, MPM, InnerPipeline)) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1558 | return Error::success(); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1559 | |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1560 | // Normal passes can't have pipelines. |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1561 | return make_error<StringError>( |
| 1562 | formatv("invalid use of '{0}' pass as module pipeline", Name).str(), |
| 1563 | inconvertibleErrorCode()); |
| 1564 | ; |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1567 | // Manually handle aliases for pre-configured pipeline fragments. |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1568 | if (startsWithDefaultPipelineAliasPrefix(Name)) { |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1569 | SmallVector<StringRef, 3> Matches; |
| 1570 | if (!DefaultAliasRegex.match(Name, &Matches)) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1571 | return make_error<StringError>( |
| 1572 | formatv("unknown default pipeline alias '{0}'", Name).str(), |
| 1573 | inconvertibleErrorCode()); |
| 1574 | |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1575 | assert(Matches.size() == 3 && "Must capture two matched strings!"); |
| 1576 | |
Jordan Rose | 569213a | 2016-07-25 18:34:51 +0000 | [diff] [blame] | 1577 | OptimizationLevel L = StringSwitch<OptimizationLevel>(Matches[2]) |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1578 | .Case("O0", O0) |
| 1579 | .Case("O1", O1) |
| 1580 | .Case("O2", O2) |
| 1581 | .Case("O3", O3) |
| 1582 | .Case("Os", Os) |
| 1583 | .Case("Oz", Oz); |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1584 | if (L == O0) |
| 1585 | // At O0 we do nothing at all! |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1586 | return Error::success(); |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1587 | |
| 1588 | if (Matches[1] == "default") { |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1589 | MPM.addPass(buildPerModuleDefaultPipeline(L, DebugLogging)); |
Chandler Carruth | df1cbec | 2017-06-01 11:39:39 +0000 | [diff] [blame] | 1590 | } else if (Matches[1] == "thinlto-pre-link") { |
| 1591 | MPM.addPass(buildThinLTOPreLinkDefaultPipeline(L, DebugLogging)); |
| 1592 | } else if (Matches[1] == "thinlto") { |
Teresa Johnson | 2a478d4 | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1593 | MPM.addPass(buildThinLTODefaultPipeline(L, DebugLogging, nullptr)); |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1594 | } else if (Matches[1] == "lto-pre-link") { |
Chandler Carruth | 2ffea51 | 2016-12-22 06:59:15 +0000 | [diff] [blame] | 1595 | MPM.addPass(buildLTOPreLinkDefaultPipeline(L, DebugLogging)); |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1596 | } else { |
| 1597 | assert(Matches[1] == "lto" && "Not one of the matched options!"); |
Teresa Johnson | 2a478d4 | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1598 | MPM.addPass(buildLTODefaultPipeline(L, DebugLogging, nullptr)); |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1599 | } |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1600 | return Error::success(); |
Chandler Carruth | f7ae2f5 | 2016-02-28 22:16:03 +0000 | [diff] [blame] | 1601 | } |
| 1602 | |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1603 | // Finally expand the basic registered passes from the .inc file. |
Chandler Carruth | a21cd04 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 1604 | #define MODULE_PASS(NAME, CREATE_PASS) \ |
| 1605 | if (Name == NAME) { \ |
| 1606 | MPM.addPass(CREATE_PASS); \ |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1607 | return Error::success(); \ |
Chandler Carruth | a595257 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 1608 | } |
Chandler Carruth | a3376d2 | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1609 | #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ |
| 1610 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | 8c28aa1 | 2016-08-19 18:36:06 +0000 | [diff] [blame] | 1611 | MPM.addPass( \ |
| 1612 | RequireAnalysisPass< \ |
| 1613 | std::remove_reference<decltype(CREATE_PASS)>::type, Module>()); \ |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1614 | return Error::success(); \ |
Chandler Carruth | 17395fa | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 1615 | } \ |
| 1616 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | 7b1b31d | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 1617 | MPM.addPass(InvalidateAnalysisPass< \ |
| 1618 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1619 | return Error::success(); \ |
Chandler Carruth | a3376d2 | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1620 | } |
| 1621 | #include "PassRegistry.def" |
| 1622 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1623 | for (auto &C : ModulePipelineParsingCallbacks) |
| 1624 | if (C(Name, MPM, InnerPipeline)) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1625 | return Error::success(); |
| 1626 | return make_error<StringError>( |
| 1627 | formatv("unknown module pass '{0}'", Name).str(), |
| 1628 | inconvertibleErrorCode()); |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1629 | } |
| 1630 | |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1631 | Error PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM, |
| 1632 | const PipelineElement &E, bool VerifyEachPass, |
| 1633 | bool DebugLogging) { |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1634 | auto &Name = E.Name; |
| 1635 | auto &InnerPipeline = E.InnerPipeline; |
| 1636 | |
| 1637 | // First handle complex passes like the pass managers which carry pipelines. |
| 1638 | if (!InnerPipeline.empty()) { |
| 1639 | if (Name == "cgscc") { |
| 1640 | CGSCCPassManager NestedCGPM(DebugLogging); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1641 | if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, |
| 1642 | VerifyEachPass, DebugLogging)) |
| 1643 | return Err; |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1644 | // Add the nested pass manager with the appropriate adaptor. |
| 1645 | CGPM.addPass(std::move(NestedCGPM)); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1646 | return Error::success(); |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1647 | } |
| 1648 | if (Name == "function") { |
| 1649 | FunctionPassManager FPM(DebugLogging); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1650 | if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline, |
| 1651 | VerifyEachPass, DebugLogging)) |
| 1652 | return Err; |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1653 | // Add the nested pass manager with the appropriate adaptor. |
Chandler Carruth | 83bfb55 | 2017-08-11 05:47:13 +0000 | [diff] [blame] | 1654 | CGPM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM))); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1655 | return Error::success(); |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1656 | } |
Chandler Carruth | 91b6bfa | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1657 | if (auto Count = parseRepeatPassName(Name)) { |
| 1658 | CGSCCPassManager NestedCGPM(DebugLogging); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1659 | if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, |
| 1660 | VerifyEachPass, DebugLogging)) |
| 1661 | return Err; |
Chandler Carruth | 411e616 | 2016-08-04 03:52:53 +0000 | [diff] [blame] | 1662 | CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM))); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1663 | return Error::success(); |
Chandler Carruth | 91b6bfa | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1664 | } |
Chandler Carruth | 86d5365 | 2016-12-28 11:07:33 +0000 | [diff] [blame] | 1665 | if (auto MaxRepetitions = parseDevirtPassName(Name)) { |
| 1666 | CGSCCPassManager NestedCGPM(DebugLogging); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1667 | if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, |
| 1668 | VerifyEachPass, DebugLogging)) |
| 1669 | return Err; |
Chandler Carruth | 83bfb55 | 2017-08-11 05:47:13 +0000 | [diff] [blame] | 1670 | CGPM.addPass( |
| 1671 | createDevirtSCCRepeatedPass(std::move(NestedCGPM), *MaxRepetitions)); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1672 | return Error::success(); |
Chandler Carruth | 86d5365 | 2016-12-28 11:07:33 +0000 | [diff] [blame] | 1673 | } |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1674 | |
| 1675 | for (auto &C : CGSCCPipelineParsingCallbacks) |
| 1676 | if (C(Name, CGPM, InnerPipeline)) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1677 | return Error::success(); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1678 | |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1679 | // Normal passes can't have pipelines. |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1680 | return make_error<StringError>( |
| 1681 | formatv("invalid use of '{0}' pass as cgscc pipeline", Name).str(), |
| 1682 | inconvertibleErrorCode()); |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1685 | // Now expand the basic registered passes from the .inc file. |
Chandler Carruth | 57418d8 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1686 | #define CGSCC_PASS(NAME, CREATE_PASS) \ |
| 1687 | if (Name == NAME) { \ |
| 1688 | CGPM.addPass(CREATE_PASS); \ |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1689 | return Error::success(); \ |
Chandler Carruth | 57418d8 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1690 | } |
Chandler Carruth | a3376d2 | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1691 | #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ |
| 1692 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | 7b1b31d | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 1693 | CGPM.addPass(RequireAnalysisPass< \ |
Chandler Carruth | 8c28aa1 | 2016-08-19 18:36:06 +0000 | [diff] [blame] | 1694 | std::remove_reference<decltype(CREATE_PASS)>::type, \ |
Chandler Carruth | 377af8d | 2016-08-24 09:37:14 +0000 | [diff] [blame] | 1695 | LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \ |
| 1696 | CGSCCUpdateResult &>()); \ |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1697 | return Error::success(); \ |
Chandler Carruth | 17395fa | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 1698 | } \ |
| 1699 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | 7b1b31d | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 1700 | CGPM.addPass(InvalidateAnalysisPass< \ |
| 1701 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1702 | return Error::success(); \ |
Chandler Carruth | a3376d2 | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1703 | } |
| 1704 | #include "PassRegistry.def" |
| 1705 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1706 | for (auto &C : CGSCCPipelineParsingCallbacks) |
| 1707 | if (C(Name, CGPM, InnerPipeline)) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1708 | return Error::success(); |
| 1709 | return make_error<StringError>( |
| 1710 | formatv("unknown cgscc pass '{0}'", Name).str(), |
| 1711 | inconvertibleErrorCode()); |
Chandler Carruth | 57418d8 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1712 | } |
| 1713 | |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1714 | Error PassBuilder::parseFunctionPass(FunctionPassManager &FPM, |
| 1715 | const PipelineElement &E, |
| 1716 | bool VerifyEachPass, bool DebugLogging) { |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1717 | auto &Name = E.Name; |
| 1718 | auto &InnerPipeline = E.InnerPipeline; |
| 1719 | |
| 1720 | // First handle complex passes like the pass managers which carry pipelines. |
| 1721 | if (!InnerPipeline.empty()) { |
| 1722 | if (Name == "function") { |
| 1723 | FunctionPassManager NestedFPM(DebugLogging); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1724 | if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline, |
| 1725 | VerifyEachPass, DebugLogging)) |
| 1726 | return Err; |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1727 | // Add the nested pass manager with the appropriate adaptor. |
| 1728 | FPM.addPass(std::move(NestedFPM)); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1729 | return Error::success(); |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1730 | } |
| 1731 | if (Name == "loop") { |
| 1732 | LoopPassManager LPM(DebugLogging); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1733 | if (auto Err = parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass, |
| 1734 | DebugLogging)) |
| 1735 | return Err; |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1736 | // Add the nested pass manager with the appropriate adaptor. |
Fedor Sergeev | ffbb3d0 | 2017-12-29 08:16:06 +0000 | [diff] [blame] | 1737 | FPM.addPass( |
| 1738 | createFunctionToLoopPassAdaptor(std::move(LPM), DebugLogging)); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1739 | return Error::success(); |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1740 | } |
Chandler Carruth | 91b6bfa | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1741 | if (auto Count = parseRepeatPassName(Name)) { |
| 1742 | FunctionPassManager NestedFPM(DebugLogging); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1743 | if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline, |
| 1744 | VerifyEachPass, DebugLogging)) |
| 1745 | return Err; |
Chandler Carruth | 411e616 | 2016-08-04 03:52:53 +0000 | [diff] [blame] | 1746 | FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM))); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1747 | return Error::success(); |
Chandler Carruth | 91b6bfa | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1748 | } |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1749 | |
| 1750 | for (auto &C : FunctionPipelineParsingCallbacks) |
| 1751 | if (C(Name, FPM, InnerPipeline)) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1752 | return Error::success(); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1753 | |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1754 | // Normal passes can't have pipelines. |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1755 | return make_error<StringError>( |
| 1756 | formatv("invalid use of '{0}' pass as function pipeline", Name).str(), |
| 1757 | inconvertibleErrorCode()); |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1760 | // Now expand the basic registered passes from the .inc file. |
Chandler Carruth | a21cd04 | 2014-04-21 08:08:50 +0000 | [diff] [blame] | 1761 | #define FUNCTION_PASS(NAME, CREATE_PASS) \ |
| 1762 | if (Name == NAME) { \ |
| 1763 | FPM.addPass(CREATE_PASS); \ |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1764 | return Error::success(); \ |
Chandler Carruth | a595257 | 2014-01-12 12:15:39 +0000 | [diff] [blame] | 1765 | } |
Fedor Sergeev | 4f41c19 | 2019-01-10 10:01:53 +0000 | [diff] [blame] | 1766 | #define FUNCTION_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \ |
| 1767 | if (checkParametrizedPassName(Name, NAME)) { \ |
| 1768 | auto Params = parsePassParameters(PARSER, Name, NAME); \ |
| 1769 | if (!Params) \ |
| 1770 | return Params.takeError(); \ |
| 1771 | FPM.addPass(CREATE_PASS(Params.get())); \ |
| 1772 | return Error::success(); \ |
| 1773 | } |
Chandler Carruth | a3376d2 | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1774 | #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ |
| 1775 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | 8c28aa1 | 2016-08-19 18:36:06 +0000 | [diff] [blame] | 1776 | FPM.addPass( \ |
| 1777 | RequireAnalysisPass< \ |
| 1778 | std::remove_reference<decltype(CREATE_PASS)>::type, Function>()); \ |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1779 | return Error::success(); \ |
Chandler Carruth | 17395fa | 2015-01-06 04:49:44 +0000 | [diff] [blame] | 1780 | } \ |
| 1781 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | 7b1b31d | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 1782 | FPM.addPass(InvalidateAnalysisPass< \ |
| 1783 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1784 | return Error::success(); \ |
Chandler Carruth | a3376d2 | 2015-01-06 02:10:51 +0000 | [diff] [blame] | 1785 | } |
| 1786 | #include "PassRegistry.def" |
| 1787 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1788 | for (auto &C : FunctionPipelineParsingCallbacks) |
| 1789 | if (C(Name, FPM, InnerPipeline)) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1790 | return Error::success(); |
| 1791 | return make_error<StringError>( |
| 1792 | formatv("unknown function pass '{0}'", Name).str(), |
| 1793 | inconvertibleErrorCode()); |
Chandler Carruth | e768765 | 2014-01-12 09:34:22 +0000 | [diff] [blame] | 1794 | } |
| 1795 | |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1796 | Error PassBuilder::parseLoopPass(LoopPassManager &LPM, const PipelineElement &E, |
| 1797 | bool VerifyEachPass, bool DebugLogging) { |
Chandler Carruth | 91b6bfa | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1798 | StringRef Name = E.Name; |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1799 | auto &InnerPipeline = E.InnerPipeline; |
| 1800 | |
| 1801 | // First handle complex passes like the pass managers which carry pipelines. |
| 1802 | if (!InnerPipeline.empty()) { |
| 1803 | if (Name == "loop") { |
| 1804 | LoopPassManager NestedLPM(DebugLogging); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1805 | if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline, |
| 1806 | VerifyEachPass, DebugLogging)) |
| 1807 | return Err; |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1808 | // Add the nested pass manager with the appropriate adaptor. |
Chandler Carruth | d4bcc6c | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 1809 | LPM.addPass(std::move(NestedLPM)); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1810 | return Error::success(); |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1811 | } |
Chandler Carruth | 91b6bfa | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1812 | if (auto Count = parseRepeatPassName(Name)) { |
| 1813 | LoopPassManager NestedLPM(DebugLogging); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1814 | if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline, |
| 1815 | VerifyEachPass, DebugLogging)) |
| 1816 | return Err; |
Chandler Carruth | 411e616 | 2016-08-04 03:52:53 +0000 | [diff] [blame] | 1817 | LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM))); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1818 | return Error::success(); |
Chandler Carruth | 91b6bfa | 2016-08-03 07:44:48 +0000 | [diff] [blame] | 1819 | } |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1820 | |
| 1821 | for (auto &C : LoopPipelineParsingCallbacks) |
| 1822 | if (C(Name, LPM, InnerPipeline)) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1823 | return Error::success(); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1824 | |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1825 | // Normal passes can't have pipelines. |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1826 | return make_error<StringError>( |
| 1827 | formatv("invalid use of '{0}' pass as loop pipeline", Name).str(), |
| 1828 | inconvertibleErrorCode()); |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1831 | // Now expand the basic registered passes from the .inc file. |
Justin Bogner | da5e924 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1832 | #define LOOP_PASS(NAME, CREATE_PASS) \ |
| 1833 | if (Name == NAME) { \ |
Chandler Carruth | d4bcc6c | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 1834 | LPM.addPass(CREATE_PASS); \ |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1835 | return Error::success(); \ |
Justin Bogner | da5e924 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1836 | } |
| 1837 | #define LOOP_ANALYSIS(NAME, CREATE_PASS) \ |
| 1838 | if (Name == "require<" NAME ">") { \ |
Chandler Carruth | d4bcc6c | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 1839 | LPM.addPass(RequireAnalysisPass< \ |
Chandler Carruth | d27a39a | 2017-01-11 06:23:21 +0000 | [diff] [blame] | 1840 | std::remove_reference<decltype(CREATE_PASS)>::type, Loop, \ |
| 1841 | LoopAnalysisManager, LoopStandardAnalysisResults &, \ |
| 1842 | LPMUpdater &>()); \ |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1843 | return Error::success(); \ |
Justin Bogner | da5e924 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1844 | } \ |
| 1845 | if (Name == "invalidate<" NAME ">") { \ |
Chandler Carruth | d4bcc6c | 2016-08-03 09:14:03 +0000 | [diff] [blame] | 1846 | LPM.addPass(InvalidateAnalysisPass< \ |
Chandler Carruth | 7b1b31d | 2016-02-26 12:30:18 +0000 | [diff] [blame] | 1847 | std::remove_reference<decltype(CREATE_PASS)>::type>()); \ |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1848 | return Error::success(); \ |
Justin Bogner | da5e924 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1849 | } |
| 1850 | #include "PassRegistry.def" |
| 1851 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1852 | for (auto &C : LoopPipelineParsingCallbacks) |
| 1853 | if (C(Name, LPM, InnerPipeline)) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1854 | return Error::success(); |
| 1855 | return make_error<StringError>(formatv("unknown loop pass '{0}'", Name).str(), |
| 1856 | inconvertibleErrorCode()); |
Justin Bogner | da5e924 | 2016-02-25 07:23:08 +0000 | [diff] [blame] | 1857 | } |
| 1858 | |
Chandler Carruth | 67a41f0 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 1859 | bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) { |
Chandler Carruth | f51faf0 | 2016-03-11 09:15:11 +0000 | [diff] [blame] | 1860 | #define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \ |
| 1861 | if (Name == NAME) { \ |
| 1862 | AA.registerModuleAnalysis< \ |
| 1863 | std::remove_reference<decltype(CREATE_PASS)>::type>(); \ |
| 1864 | return true; \ |
| 1865 | } |
Chandler Carruth | 67a41f0 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 1866 | #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \ |
| 1867 | if (Name == NAME) { \ |
Chandler Carruth | 1ce194e | 2016-02-26 12:17:54 +0000 | [diff] [blame] | 1868 | AA.registerFunctionAnalysis< \ |
| 1869 | std::remove_reference<decltype(CREATE_PASS)>::type>(); \ |
Chandler Carruth | 67a41f0 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 1870 | return true; \ |
| 1871 | } |
| 1872 | #include "PassRegistry.def" |
| 1873 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1874 | for (auto &C : AAParsingCallbacks) |
| 1875 | if (C(Name, AA)) |
| 1876 | return true; |
Chandler Carruth | 67a41f0 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 1877 | return false; |
| 1878 | } |
| 1879 | |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1880 | Error PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM, |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1881 | ArrayRef<PipelineElement> Pipeline, |
Chandler Carruth | 2349136 | 2015-03-07 09:02:36 +0000 | [diff] [blame] | 1882 | bool VerifyEachPass, |
| 1883 | bool DebugLogging) { |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1884 | for (const auto &Element : Pipeline) { |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1885 | if (auto Err = parseLoopPass(LPM, Element, VerifyEachPass, DebugLogging)) |
| 1886 | return Err; |
| 1887 | // FIXME: No verifier support for Loop passes! |
| 1888 | } |
| 1889 | return Error::success(); |
| 1890 | } |
| 1891 | |
| 1892 | Error PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM, |
| 1893 | ArrayRef<PipelineElement> Pipeline, |
| 1894 | bool VerifyEachPass, |
| 1895 | bool DebugLogging) { |
| 1896 | for (const auto &Element : Pipeline) { |
| 1897 | if (auto Err = |
| 1898 | parseFunctionPass(FPM, Element, VerifyEachPass, DebugLogging)) |
| 1899 | return Err; |
| 1900 | if (VerifyEachPass) |
| 1901 | FPM.addPass(VerifierPass()); |
| 1902 | } |
| 1903 | return Error::success(); |
| 1904 | } |
| 1905 | |
| 1906 | Error PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM, |
| 1907 | ArrayRef<PipelineElement> Pipeline, |
| 1908 | bool VerifyEachPass, |
| 1909 | bool DebugLogging) { |
| 1910 | for (const auto &Element : Pipeline) { |
| 1911 | if (auto Err = parseCGSCCPass(CGPM, Element, VerifyEachPass, DebugLogging)) |
| 1912 | return Err; |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1913 | // FIXME: No verifier support for CGSCC passes! |
Chandler Carruth | 57418d8 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1914 | } |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1915 | return Error::success(); |
Chandler Carruth | 57418d8 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1916 | } |
| 1917 | |
NAKAMURA Takumi | 0d8f8a0 | 2016-05-16 10:13:37 +0000 | [diff] [blame] | 1918 | void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM, |
| 1919 | FunctionAnalysisManager &FAM, |
| 1920 | CGSCCAnalysisManager &CGAM, |
| 1921 | ModuleAnalysisManager &MAM) { |
| 1922 | MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); }); |
| 1923 | MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); }); |
NAKAMURA Takumi | 0d8f8a0 | 2016-05-16 10:13:37 +0000 | [diff] [blame] | 1924 | CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); }); |
| 1925 | FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); }); |
| 1926 | FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); }); |
| 1927 | FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); }); |
| 1928 | LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); }); |
| 1929 | } |
| 1930 | |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1931 | Error PassBuilder::parseModulePassPipeline(ModulePassManager &MPM, |
| 1932 | ArrayRef<PipelineElement> Pipeline, |
| 1933 | bool VerifyEachPass, |
| 1934 | bool DebugLogging) { |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1935 | for (const auto &Element : Pipeline) { |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1936 | if (auto Err = parseModulePass(MPM, Element, VerifyEachPass, DebugLogging)) |
| 1937 | return Err; |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1938 | if (VerifyEachPass) |
| 1939 | MPM.addPass(VerifierPass()); |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1940 | } |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1941 | return Error::success(); |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1942 | } |
| 1943 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1944 | // Primary pass pipeline description parsing routine for a \c ModulePassManager |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1945 | // FIXME: Should this routine accept a TargetMachine or require the caller to |
| 1946 | // pre-populate the analysis managers with target-specific stuff? |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1947 | Error PassBuilder::parsePassPipeline(ModulePassManager &MPM, |
| 1948 | StringRef PipelineText, |
| 1949 | bool VerifyEachPass, bool DebugLogging) { |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1950 | auto Pipeline = parsePipelineText(PipelineText); |
| 1951 | if (!Pipeline || Pipeline->empty()) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1952 | return make_error<StringError>( |
| 1953 | formatv("invalid pipeline '{0}'", PipelineText).str(), |
| 1954 | inconvertibleErrorCode()); |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1955 | |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1956 | // If the first name isn't at the module layer, wrap the pipeline up |
| 1957 | // automatically. |
| 1958 | StringRef FirstName = Pipeline->front().Name; |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1959 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1960 | if (!isModulePassName(FirstName, ModulePipelineParsingCallbacks)) { |
| 1961 | if (isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks)) { |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1962 | Pipeline = {{"cgscc", std::move(*Pipeline)}}; |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1963 | } else if (isFunctionPassName(FirstName, |
| 1964 | FunctionPipelineParsingCallbacks)) { |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1965 | Pipeline = {{"function", std::move(*Pipeline)}}; |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1966 | } else if (isLoopPassName(FirstName, LoopPipelineParsingCallbacks)) { |
Chandler Carruth | 3d1a470 | 2016-08-03 03:21:41 +0000 | [diff] [blame] | 1967 | Pipeline = {{"function", {{"loop", std::move(*Pipeline)}}}}; |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1968 | } else { |
| 1969 | for (auto &C : TopLevelPipelineParsingCallbacks) |
| 1970 | if (C(MPM, *Pipeline, VerifyEachPass, DebugLogging)) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1971 | return Error::success(); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1972 | |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1973 | // Unknown pass or pipeline name! |
| 1974 | auto &InnerPipeline = Pipeline->front().InnerPipeline; |
| 1975 | return make_error<StringError>( |
| 1976 | formatv("unknown {0} name '{1}'", |
| 1977 | (InnerPipeline.empty() ? "pass" : "pipeline"), FirstName) |
| 1978 | .str(), |
| 1979 | inconvertibleErrorCode()); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1980 | } |
Chandler Carruth | 57418d8 | 2014-04-21 11:12:00 +0000 | [diff] [blame] | 1981 | } |
| 1982 | |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1983 | if (auto Err = |
| 1984 | parseModulePassPipeline(MPM, *Pipeline, VerifyEachPass, DebugLogging)) |
| 1985 | return Err; |
| 1986 | return Error::success(); |
Chandler Carruth | 4e728be | 2014-01-11 08:16:35 +0000 | [diff] [blame] | 1987 | } |
Chandler Carruth | 67a41f0 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 1988 | |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1989 | // Primary pass pipeline description parsing routine for a \c CGSCCPassManager |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1990 | Error PassBuilder::parsePassPipeline(CGSCCPassManager &CGPM, |
| 1991 | StringRef PipelineText, |
| 1992 | bool VerifyEachPass, bool DebugLogging) { |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1993 | auto Pipeline = parsePipelineText(PipelineText); |
| 1994 | if (!Pipeline || Pipeline->empty()) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 1995 | return make_error<StringError>( |
| 1996 | formatv("invalid pipeline '{0}'", PipelineText).str(), |
| 1997 | inconvertibleErrorCode()); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 1998 | |
| 1999 | StringRef FirstName = Pipeline->front().Name; |
| 2000 | if (!isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks)) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2001 | return make_error<StringError>( |
| 2002 | formatv("unknown cgscc pass '{0}' in pipeline '{1}'", FirstName, |
| 2003 | PipelineText) |
| 2004 | .str(), |
| 2005 | inconvertibleErrorCode()); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2006 | |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2007 | if (auto Err = |
| 2008 | parseCGSCCPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging)) |
| 2009 | return Err; |
| 2010 | return Error::success(); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | // Primary pass pipeline description parsing routine for a \c |
| 2014 | // FunctionPassManager |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2015 | Error PassBuilder::parsePassPipeline(FunctionPassManager &FPM, |
| 2016 | StringRef PipelineText, |
| 2017 | bool VerifyEachPass, bool DebugLogging) { |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2018 | auto Pipeline = parsePipelineText(PipelineText); |
| 2019 | if (!Pipeline || Pipeline->empty()) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2020 | return make_error<StringError>( |
| 2021 | formatv("invalid pipeline '{0}'", PipelineText).str(), |
| 2022 | inconvertibleErrorCode()); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2023 | |
| 2024 | StringRef FirstName = Pipeline->front().Name; |
| 2025 | if (!isFunctionPassName(FirstName, FunctionPipelineParsingCallbacks)) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2026 | return make_error<StringError>( |
| 2027 | formatv("unknown function pass '{0}' in pipeline '{1}'", FirstName, |
| 2028 | PipelineText) |
| 2029 | .str(), |
| 2030 | inconvertibleErrorCode()); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2031 | |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2032 | if (auto Err = parseFunctionPassPipeline(FPM, *Pipeline, VerifyEachPass, |
| 2033 | DebugLogging)) |
| 2034 | return Err; |
| 2035 | return Error::success(); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | // Primary pass pipeline description parsing routine for a \c LoopPassManager |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2039 | Error PassBuilder::parsePassPipeline(LoopPassManager &CGPM, |
| 2040 | StringRef PipelineText, |
| 2041 | bool VerifyEachPass, bool DebugLogging) { |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2042 | auto Pipeline = parsePipelineText(PipelineText); |
| 2043 | if (!Pipeline || Pipeline->empty()) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2044 | return make_error<StringError>( |
| 2045 | formatv("invalid pipeline '{0}'", PipelineText).str(), |
| 2046 | inconvertibleErrorCode()); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2047 | |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2048 | if (auto Err = |
| 2049 | parseLoopPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging)) |
| 2050 | return Err; |
| 2051 | |
| 2052 | return Error::success(); |
Philip Pfaffe | 1904561 | 2017-07-10 10:57:55 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2055 | Error PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) { |
Chandler Carruth | 759dd39 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 2056 | // If the pipeline just consists of the word 'default' just replace the AA |
| 2057 | // manager with our default one. |
| 2058 | if (PipelineText == "default") { |
| 2059 | AA = buildDefaultAAPipeline(); |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2060 | return Error::success(); |
Chandler Carruth | 759dd39 | 2016-12-23 20:38:19 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
Chandler Carruth | 67a41f0 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 2063 | while (!PipelineText.empty()) { |
| 2064 | StringRef Name; |
| 2065 | std::tie(Name, PipelineText) = PipelineText.split(','); |
| 2066 | if (!parseAAPassName(AA, Name)) |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2067 | return make_error<StringError>( |
| 2068 | formatv("unknown alias analysis name '{0}'", Name).str(), |
| 2069 | inconvertibleErrorCode()); |
Chandler Carruth | 67a41f0 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
Fedor Sergeev | ff88649 | 2018-10-17 10:36:23 +0000 | [diff] [blame] | 2072 | return Error::success(); |
Chandler Carruth | 67a41f0 | 2016-02-18 09:45:17 +0000 | [diff] [blame] | 2073 | } |