141 #include <type_traits>
143 using namespace llvm;
165 struct NoOpModulePass {
184 struct NoOpCGSCCPass {
206 struct NoOpFunctionPass {
225 struct NoOpLoopPass {
254 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
255 MAM.registerPass([&] { return CREATE_PASS; });
256 #include "PassRegistry.def"
260 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
261 CGAM.registerPass([&] { return CREATE_PASS; });
262 #include "PassRegistry.def"
266 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
267 FAM.registerPass([&] { return CREATE_PASS; });
268 #include "PassRegistry.def"
272 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
273 LAM.registerPass([&] { return CREATE_PASS; });
274 #include "PassRegistry.def"
280 assert(Level !=
O0 &&
"Must request optimizations!");
326 LPM1.addPass(LoopUnswitchPass( Level !=
O3));
330 LPM2.
addPass(SimpleLoopUnrollPass());
385 assert(Level !=
O0 &&
"Must request optimizations for the default pipeline!");
487 MPM.
addPass(Require<GlobalsAA>());
543 assert(Level !=
O0 &&
"Must request optimizations for the default pipeline!");
550 assert(Level !=
O0 &&
"Must request optimizations for the default pipeline!");
616 if (Name ==
"module")
620 if (Name ==
"function")
627 #define MODULE_PASS(NAME, CREATE_PASS) \
630 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
631 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
633 #include "PassRegistry.def"
642 if (Name ==
"function")
651 #define CGSCC_PASS(NAME, CREATE_PASS) \
654 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
655 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
657 #include "PassRegistry.def"
664 if (Name ==
"function")
673 #define FUNCTION_PASS(NAME, CREATE_PASS) \
676 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
677 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
679 #include "PassRegistry.def"
693 #define LOOP_PASS(NAME, CREATE_PASS) \
696 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
697 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
699 #include "PassRegistry.def"
705 PassBuilder::parsePipelineText(
StringRef Text) {
706 std::vector<PipelineElement> ResultPipeline;
711 std::vector<PipelineElement> &Pipeline = *PipelineStack.
back();
713 Pipeline.push_back({Text.
substr(0, Pos), {}});
716 if (Pos == Text.
npos)
719 char Sep = Text[Pos];
720 Text = Text.
substr(Pos + 1);
727 PipelineStack.
push_back(&Pipeline.back().InnerPipeline);
731 assert(Sep ==
')' &&
"Bogus separator!");
736 if (PipelineStack.
size() == 1)
752 if (PipelineStack.
size() > 1)
756 assert(PipelineStack.
back() == &ResultPipeline &&
757 "Wrong pipeline at the bottom of the stack!");
758 return {std::move(ResultPipeline)};
762 const PipelineElement &
E,
bool VerifyEachPass,
765 auto &InnerPipeline = E.InnerPipeline;
768 if (!InnerPipeline.empty()) {
769 if (
Name ==
"module") {
771 if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
774 MPM.
addPass(std::move(NestedMPM));
777 if (
Name ==
"cgscc") {
779 if (!parseCGSCCPassPipeline(CGPM, InnerPipeline, VerifyEachPass,
786 if (
Name ==
"function") {
788 if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
796 if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
807 if (
Name.startswith(
"default") ||
Name.startswith(
"lto")) {
811 assert(Matches.
size() == 3 &&
"Must capture two matched strings!");
824 if (Matches[1] ==
"default") {
826 }
else if (Matches[1] ==
"lto-pre-link") {
829 assert(Matches[1] ==
"lto" &&
"Not one of the matched options!");
836 #define MODULE_PASS(NAME, CREATE_PASS) \
837 if (Name == NAME) { \
838 MPM.addPass(CREATE_PASS); \
841 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
842 if (Name == "require<" NAME ">") { \
844 RequireAnalysisPass< \
845 std::remove_reference<decltype(CREATE_PASS)>::type, Module>()); \
848 if (Name == "invalidate<" NAME ">") { \
849 MPM.addPass(InvalidateAnalysisPass< \
850 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
853 #include "PassRegistry.def"
859 const PipelineElement &E,
bool VerifyEachPass,
862 auto &InnerPipeline = E.InnerPipeline;
865 if (!InnerPipeline.empty()) {
866 if (
Name ==
"cgscc") {
868 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
872 CGPM.
addPass(std::move(NestedCGPM));
875 if (
Name ==
"function") {
877 if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
887 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
895 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
899 *MaxRepetitions, DebugLogging));
907 #define CGSCC_PASS(NAME, CREATE_PASS) \
908 if (Name == NAME) { \
909 CGPM.addPass(CREATE_PASS); \
912 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
913 if (Name == "require<" NAME ">") { \
914 CGPM.addPass(RequireAnalysisPass< \
915 std::remove_reference<decltype(CREATE_PASS)>::type, \
916 LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \
917 CGSCCUpdateResult &>()); \
920 if (Name == "invalidate<" NAME ">") { \
921 CGPM.addPass(InvalidateAnalysisPass< \
922 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
925 #include "PassRegistry.def"
931 const PipelineElement &E,
932 bool VerifyEachPass,
bool DebugLogging) {
934 auto &InnerPipeline = E.InnerPipeline;
937 if (!InnerPipeline.empty()) {
938 if (
Name ==
"function") {
940 if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
944 FPM.
addPass(std::move(NestedFPM));
947 if (
Name ==
"loop") {
949 if (!parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass,
958 if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
969 #define FUNCTION_PASS(NAME, CREATE_PASS) \
970 if (Name == NAME) { \
971 FPM.addPass(CREATE_PASS); \
974 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
975 if (Name == "require<" NAME ">") { \
977 RequireAnalysisPass< \
978 std::remove_reference<decltype(CREATE_PASS)>::type, Function>()); \
981 if (Name == "invalidate<" NAME ">") { \
982 FPM.addPass(InvalidateAnalysisPass< \
983 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
986 #include "PassRegistry.def"
991 bool PassBuilder::parseLoopPass(
LoopPassManager &LPM,
const PipelineElement &E,
992 bool VerifyEachPass,
bool DebugLogging) {
994 auto &InnerPipeline = E.InnerPipeline;
997 if (!InnerPipeline.empty()) {
998 if (Name ==
"loop") {
1000 if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
1004 LPM.
addPass(std::move(NestedLPM));
1009 if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
1020 #define LOOP_PASS(NAME, CREATE_PASS) \
1021 if (Name == NAME) { \
1022 LPM.addPass(CREATE_PASS); \
1025 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1026 if (Name == "require<" NAME ">") { \
1027 LPM.addPass(RequireAnalysisPass< \
1028 std::remove_reference<decltype(CREATE_PASS)>::type, Loop, \
1029 LoopAnalysisManager, LoopStandardAnalysisResults &, \
1033 if (Name == "invalidate<" NAME ">") { \
1034 LPM.addPass(InvalidateAnalysisPass< \
1035 std::remove_reference<decltype(CREATE_PASS)>::type>()); \
1038 #include "PassRegistry.def"
1044 #define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1045 if (Name == NAME) { \
1046 AA.registerModuleAnalysis< \
1047 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
1050 #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1051 if (Name == NAME) { \
1052 AA.registerFunctionAnalysis< \
1053 std::remove_reference<decltype(CREATE_PASS)>::type>(); \
1056 #include "PassRegistry.def"
1063 bool VerifyEachPass,
1064 bool DebugLogging) {
1065 for (
const auto &Element : Pipeline) {
1066 if (!parseLoopPass(LPM, Element, VerifyEachPass, DebugLogging))
1075 bool VerifyEachPass,
1076 bool DebugLogging) {
1077 for (
const auto &Element : Pipeline) {
1078 if (!parseFunctionPass(FPM, Element, VerifyEachPass, DebugLogging))
1088 bool VerifyEachPass,
1089 bool DebugLogging) {
1090 for (
const auto &Element : Pipeline) {
1091 if (!parseCGSCCPass(CGPM, Element, VerifyEachPass, DebugLogging))
1113 bool VerifyEachPass,
1114 bool DebugLogging) {
1115 for (
const auto &Element : Pipeline) {
1116 if (!parseModulePass(MPM, Element, VerifyEachPass, DebugLogging))
1128 StringRef PipelineText,
bool VerifyEachPass,
1129 bool DebugLogging) {
1130 auto Pipeline = parsePipelineText(PipelineText);
1131 if (!Pipeline || Pipeline->empty())
1140 Pipeline = {{
"cgscc", std::move(*Pipeline)}};
1142 Pipeline = {{
"function", std::move(*Pipeline)}};
1144 Pipeline = {{
"function", {{
"loop", std::move(*Pipeline)}}}};
1150 return parseModulePassPipeline(MPM, *Pipeline, VerifyEachPass, DebugLogging);
1156 if (PipelineText ==
"default") {
1161 while (!PipelineText.
empty()) {
1163 std::tie(Name, PipelineText) = PipelineText.
split(
',');
1164 if (!parseAAPassName(AA, Name))
Super simple passes to force specific function attrs from the commandline into the IR for debugging p...
This file provides the interface for the pass responsible for both simplifying and canonicalizing the...
Analysis pass providing a never-invalidated alias analysis result.
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Computes function attributes in post-order over the call graph.
A simple loop rotation transformation.
A simple and fast domtree-based CSE pass.
void push_back(const T &Elt)
Interfaces for registering analysis passes, producing common pass manager configurations, and parsing of pass pipelines.
AAManager buildDefaultAAPipeline()
Build the default AAManager with the default alias analysis pipeline registered.
Eliminate dead arguments (and return values) from functions.
This is the interface for LLVM's inclusion-based alias analysis implemented with CFL graph reachabili...
DevirtSCCRepeatedPass< PassT > createDevirtSCCRepeatedPass(PassT Pass, int MaxIterations, bool DebugLogging=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
static Optional< int > parseRepeatPassName(StringRef Name)
This header provides classes for managing a pipeline of passes over loops in LLVM IR...
This is the interface for a simple mod/ref and alias analysis over globals.
A Module instance is used to store all the information related to an LLVM module. ...
This file provides the primary interface to the instcombine pass.
This is the interface to build a ModuleSummaryIndex for a module.
InnerAnalysisManagerProxy< LoopAnalysisManager, Function > LoopAnalysisManagerFunctionProxy
A proxy from a LoopAnalysisManager to a Function.
This file provides the interface for LLVM's Scalar Replacement of Aggregates pass.
This file implements a simple N^2 alias analysis accuracy evaluator.
Implements a lazy call graph analysis and related passes for the new pass manager.
RepeatedPass< PassT > createRepeatedPass(int Count, PassT P)
void registerModuleAnalyses(ModuleAnalysisManager &MAM)
Registers all available module analysis passes.
This is the interface for a metadata-based scoped no-alias analysis.
void registerModuleAnalysis()
Register a specific AA result.
OuterAnalysisManagerProxy< CGSCCAnalysisManager, Function > CGSCCAnalysisManagerFunctionProxy
A proxy from a CGSCCAnalysisManager to a Function.
OptimizationLevel
LLVM-provided high-level optimization levels.
This file provides the interface for LLVM's PGO Instrumentation lowering pass.
OuterAnalysisManagerProxy< FunctionAnalysisManager, Loop, LoopStandardAnalysisResults & > FunctionAnalysisManagerLoopProxy
A proxy from a FunctionAnalysisManager to a Loop.
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
A DCE pass that assumes instructions are dead until proven otherwise.
A utility pass template to force an analysis result to be available.
Reassociate commutative expressions.
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
OuterAnalysisManagerProxy< ModuleAnalysisManager, LazyCallGraph::SCC, LazyCallGraph & > ModuleAnalysisManagerCGSCCProxy
A proxy from a ModuleAnalysisManager to an SCC.
A pass that transforms external global definitions into declarations.
A simple and fast domtree-based GVN pass to hoist common expressions from sibling branches...
This is the interface for a SCEV-based alias analysis.
A pass to do RPO deduction and propagation of function attributes.
bool parseAAPipeline(AAManager &AA, StringRef PipelineText)
Parse a textual alias analysis pipeline into the provided AA manager.
LLVM_ATTRIBUTE_ALWAYS_INLINE bool consume_back(StringRef Suffix)
Returns true if this StringRef has the given suffix and removes that suffix.
Similar to O2 but tries to optimize for small code size instead of fast execution without triggering ...
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level, bool DebugLogging=false)
Build an LTO default optimization pipeline to a pass manager.
void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
A very specialized mode that will optimize for code size at any and all costs.
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(const char(&S)[N], const T &Value)
This file provides the interface for IR based instrumentation passes ( (profile-gen, and profile-use).
LLVM_ATTRIBUTE_ALWAYS_INLINE bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
This file provides the interface for a simple, fast CSE pass.
This file provides the interface for the GCOV style profiler pass.
Performs Loop Invariant Code Motion Pass.
The core GVN pass object.
void crossRegisterProxies(LoopAnalysisManager &LAM, FunctionAnalysisManager &FAM, CGSCCAnalysisManager &CGAM, ModuleAnalysisManager &MAM)
Cross register the analysis managers through their proxies.
Pass to remove unused function declarations.
A lazily constructed view of the call graph of a module.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void registerFunctionAnalysis()
Register a specific AA result.
This class implements a trivial dead store elimination.
LLVM_NODISCARD char front() const
front - Get the first character in the string.
Pass to perform interprocedural constant propagation.
A pass which infers function attributes from the names and signatures of function declarations in a m...
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
static bool isFunctionPassName(StringRef Name)
A switch()-like statement whose cases are string literals.
This is the interface for LLVM's unification-based alias analysis implemented with CFL graph reachabi...
static bool isLoopPassName(StringRef Name)
static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level)
A set of analyses that are preserved following a run of a transformation pass.
This is the interface for a metadata-based TBAA.
ModuleToFunctionPassAdaptor< FunctionPassT > createModuleToFunctionPassAdaptor(FunctionPassT Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
CGSCCToFunctionPassAdaptor< FunctionPassT > createCGSCCToFunctionPassAdaptor(FunctionPassT Pass, bool DebugLogging=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
This file provides the interface for LLVM's Global Value Numbering pass which eliminates fully redund...
Disable as many optimizations as possible.
A manager for alias analyses.
ModulePassManager buildLTOPreLinkDefaultPipeline(OptimizationLevel Level, bool DebugLogging=false)
Build a pre-link, LTO-targeting default optimization pipeline to a pass manager.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
A CRTP mix-in that provides informational APIs needed for analysis passes.
The inliner pass for the new pass manager.
void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis passes.
Analysis pass providing a never-invalidated alias analysis result.
This file provides the interface for LLVM's Global Value Numbering pass.
Optimize for fast execution as much as possible.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
FunctionPassManager buildFunctionSimplificationPipeline(OptimizationLevel Level, bool DebugLogging=false)
Construct the core LLVM function canonicalization and simplification pipeline.
This file provides the interface for LLVM's Loop Data Prefetching Pass.
Provides passes to inlining "always_inline" functions.
FunctionToLoopPassAdaptor< LoopPassT > createFunctionToLoopPassAdaptor(LoopPassT Pass)
A function to deduce a loop pass type and wrap it in the templated adaptor.
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
static bool isModulePassName(StringRef Name)
static Optional< int > parseDevirtPassName(StringRef Name)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Optimize for fast execution as much as possible without triggering significant incremental compile ti...
This pass performs 'jump threading', which looks at blocks that have multiple predecessors and multip...
bool parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText, bool VerifyEachPass=true, bool DebugLogging=false)
Parse a textual pass pipeline description into a ModulePassManager.
A pass to simplify and canonicalize the CFG of a function.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
A pass that merges duplicate global constants into a single constant.
Analysis pass providing a never-invalidated alias analysis result.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
This pass performs merges of loads and stores on both sides of a.
Interfaces for passes which infer implicit function attributes from the name and signature of functio...
Analysis pass providing a never-invalidated alias analysis result.
Manages a sequence of passes over a particular unit of IR.
Represents a single loop in the control flow graph.
static bool isCGSCCPassName(StringRef Name)
Pass which forces specific function attributes into the IR, primarily as a debugging tool...
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
The header file for the LowerExpectIntrinsic pass as used by the new pass manager.
Provides passes for computing function attributes based on interprocedural analyses.
This header provides classes for managing passes over SCCs of the call graph.
This file defines passes to print out IR in various granularities.
ModuleToPostOrderCGSCCPassAdaptor< CGSCCPassT > createModuleToPostOrderCGSCCPassAdaptor(CGSCCPassT Pass, bool DebugLogging=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
LLVM_NODISCARD size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Optimize quickly without destroying debuggability.
See the comments on JumpThreadingPass.
An SCC of the call graph.
static Regex DefaultAliasRegex("^(default|lto-pre-link|lto)<(O[0123sz])>$")
bool match(StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr)
matches - Match the regex against a given String.
An optimization pass providing Scalar Replacement of Aggregates.
StringRef - Represent a constant reference to a string, i.e.
This is the interface for LLVM's primary stateless and local alias analysis.
ModulePassManager buildPerModuleDefaultPipeline(OptimizationLevel Level, bool DebugLogging=false)
Build a per-module default optimization pipeline.
A container for analyses that lazily runs them and caches their results.
This pass performs function-level constant propagation and merging.
This header defines various interfaces for pass management in LLVM.
InnerAnalysisManagerProxy< CGSCCAnalysisManager, Module > CGSCCAnalysisManagerModuleProxy
A proxy from a CGSCCAnalysisManager to a Module.
A special type used by analysis passes to provide an address that identifies that particular analysis...
This file provides the interface for the sampled PGO loader pass.
Optimize globals that never have their address taken.