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