LLVM 22.0.0git
PassBuilderBindings.cpp
Go to the documentation of this file.
1//===-------------- PassBuilder bindings for LLVM-C -----------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9///
10/// This file defines the C bindings to the new pass manager
11///
12//===----------------------------------------------------------------------===//
13
16#include "llvm/IR/Module.h"
17#include "llvm/IR/Verifier.h"
21
22using namespace llvm;
23
24namespace llvm {
25/// Helper struct for holding a set of builder options for LLVMRunPasses. This
26/// structure is used to keep LLVMRunPasses backwards compatible with future
27/// versions in case we modify the options the new Pass Manager utilizes.
42} // namespace llvm
43
45 return reinterpret_cast<TargetMachine *>(P);
46}
47
50
51static LLVMErrorRef runPasses(Module *Mod, Function *Fun, const char *Passes,
54 bool Debug = PassOpts->DebugLogging;
55 bool VerifyEach = PassOpts->VerifyEach;
56
58 PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC);
59
64 if (PassOpts->AAPipeline) {
65 // If we have a custom AA pipeline, we need to register it _before_ calling
66 // registerFunctionAnalyses, or the default alias analysis pipeline is used.
68 if (auto Err = PB.parseAAPipeline(AA, PassOpts->AAPipeline))
69 return wrap(std::move(Err));
70 FAM.registerPass([&] { return std::move(AA); });
71 }
72 PB.registerLoopAnalyses(LAM);
73 PB.registerFunctionAnalyses(FAM);
74 PB.registerCGSCCAnalyses(CGAM);
75 PB.registerModuleAnalyses(MAM);
76 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
77
79 SI.registerCallbacks(PIC, &MAM);
80
81 // Run the pipeline.
82 if (Fun) {
84 if (VerifyEach)
85 FPM.addPass(VerifierPass());
86 if (auto Err = PB.parsePassPipeline(FPM, Passes))
87 return wrap(std::move(Err));
88 FPM.run(*Fun, FAM);
89 } else {
92 MPM.addPass(VerifierPass());
93 if (auto Err = PB.parsePassPipeline(MPM, Passes))
94 return wrap(std::move(Err));
95 MPM.run(*Mod, MAM);
96 }
97
99}
100
109
118
122
127
129 LLVMBool DebugLogging) {
130 unwrap(Options)->DebugLogging = DebugLogging;
131}
132
134 const char *AAPipeline) {
135 unwrap(Options)->AAPipeline = AAPipeline;
136}
137
139 LLVMPassBuilderOptionsRef Options, LLVMBool LoopInterleaving) {
140 unwrap(Options)->PTO.LoopInterleaving = LoopInterleaving;
141}
142
144 LLVMPassBuilderOptionsRef Options, LLVMBool LoopVectorization) {
145 unwrap(Options)->PTO.LoopVectorization = LoopVectorization;
146}
147
149 LLVMPassBuilderOptionsRef Options, LLVMBool SLPVectorization) {
150 unwrap(Options)->PTO.SLPVectorization = SLPVectorization;
151}
152
154 LLVMBool LoopUnrolling) {
155 unwrap(Options)->PTO.LoopUnrolling = LoopUnrolling;
156}
157
159 LLVMPassBuilderOptionsRef Options, LLVMBool ForgetAllSCEVInLoopUnroll) {
160 unwrap(Options)->PTO.ForgetAllSCEVInLoopUnroll = ForgetAllSCEVInLoopUnroll;
161}
162
164 unsigned LicmMssaOptCap) {
165 unwrap(Options)->PTO.LicmMssaOptCap = LicmMssaOptCap;
166}
167
169 LLVMPassBuilderOptionsRef Options, unsigned LicmMssaNoAccForPromotionCap) {
170 unwrap(Options)->PTO.LicmMssaNoAccForPromotionCap =
171 LicmMssaNoAccForPromotionCap;
172}
173
175 LLVMPassBuilderOptionsRef Options, LLVMBool CallGraphProfile) {
176 unwrap(Options)->PTO.CallGraphProfile = CallGraphProfile;
177}
178
180 LLVMBool MergeFunctions) {
181 unwrap(Options)->PTO.MergeFunctions = MergeFunctions;
182}
183
185 LLVMPassBuilderOptionsRef Options, int Threshold) {
186 unwrap(Options)->PTO.InlinerThreshold = Threshold;
187}
188
aarch64 promote const
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
static ManagedStatic< cl::opt< bool, true >, CreateDebug > Debug
Definition Debug.cpp:147
Module.h This file contains the declarations for the Module class.
static LVOptions Options
Definition LVOptions.cpp:25
#define F(x, y, z)
Definition MD5.cpp:55
#define P(N)
CGSCCAnalysisManager CGAM
Function const char TargetMachine * Machine
Function const char * Passes
if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * Mod
LoopAnalysisManager LAM
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
bool VerifyEach
PassInstrumentationCallbacks PIC
Function const char TargetMachine LLVMPassBuilderOptions * PassOpts
Function * Fun
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)
This header defines a class that provides bookkeeping for all standard (i.e in-tree) pass instrumenta...
A manager for alias analyses.
Helper struct for holding a set of builder options for LLVMRunPasses.
LLVMPassBuilderOptions(bool DebugLogging=false, bool VerifyEach=false, const char *AAPipeline=nullptr, PipelineTuningOptions PTO=PipelineTuningOptions())
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
This class provides access to building LLVM's passes.
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same_v< PassT, PassManager > > addPass(PassT &&Pass)
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
Tunable parameters for passes in the default pipelines.
Definition PassBuilder.h:44
This class provides an interface to register all the standard pass instrumentations and manages their...
Primary interface to the complete machine description for the target machine.
Create a verifier pass.
Definition Verifier.h:133
void LLVMPassBuilderOptionsSetSLPVectorization(LLVMPassBuilderOptionsRef Options, LLVMBool SLPVectorization)
void LLVMPassBuilderOptionsSetAAPipeline(LLVMPassBuilderOptionsRef Options, const char *AAPipeline)
Specify a custom alias analysis pipeline for the PassBuilder to be used instead of the default one.
void LLVMPassBuilderOptionsSetLoopVectorization(LLVMPassBuilderOptionsRef Options, LLVMBool LoopVectorization)
void LLVMPassBuilderOptionsSetDebugLogging(LLVMPassBuilderOptionsRef Options, LLVMBool DebugLogging)
Toggle debug logging when running the PassBuilder.
LLVMPassBuilderOptionsRef LLVMCreatePassBuilderOptions()
Create a new set of options for a PassBuilder.
void LLVMDisposePassBuilderOptions(LLVMPassBuilderOptionsRef Options)
Dispose of a heap-allocated PassBuilderOptions instance.
void LLVMPassBuilderOptionsSetVerifyEach(LLVMPassBuilderOptionsRef Options, LLVMBool VerifyEach)
Toggle adding the VerifierPass for the PassBuilder, ensuring all functions inside the module is valid...
void LLVMPassBuilderOptionsSetForgetAllSCEVInLoopUnroll(LLVMPassBuilderOptionsRef Options, LLVMBool ForgetAllSCEVInLoopUnroll)
void LLVMPassBuilderOptionsSetMergeFunctions(LLVMPassBuilderOptionsRef Options, LLVMBool MergeFunctions)
void LLVMPassBuilderOptionsSetLoopInterleaving(LLVMPassBuilderOptionsRef Options, LLVMBool LoopInterleaving)
void LLVMPassBuilderOptionsSetLicmMssaOptCap(LLVMPassBuilderOptionsRef Options, unsigned LicmMssaOptCap)
typedefLLVM_C_EXTERN_C_BEGIN struct LLVMOpaquePassBuilderOptions * LLVMPassBuilderOptionsRef
A set of options passed which are attached to the Pass Manager upon run.
Definition PassBuilder.h:39
LLVMErrorRef LLVMRunPassesOnFunction(LLVMValueRef F, const char *Passes, LLVMTargetMachineRef TM, LLVMPassBuilderOptionsRef Options)
Construct and run a set of passes over a function.
void LLVMPassBuilderOptionsSetCallGraphProfile(LLVMPassBuilderOptionsRef Options, LLVMBool CallGraphProfile)
void LLVMPassBuilderOptionsSetLoopUnrolling(LLVMPassBuilderOptionsRef Options, LLVMBool LoopUnrolling)
void LLVMPassBuilderOptionsSetLicmMssaNoAccForPromotionCap(LLVMPassBuilderOptionsRef Options, unsigned LicmMssaNoAccForPromotionCap)
void LLVMPassBuilderOptionsSetInlinerThreshold(LLVMPassBuilderOptionsRef Options, int Threshold)
LLVMErrorRef LLVMRunPasses(LLVMModuleRef M, const char *Passes, LLVMTargetMachineRef TM, LLVMPassBuilderOptionsRef Options)
Construct and run a set of passes over a module.
#define LLVMErrorSuccess
Definition Error.h:29
struct LLVMOpaqueError * LLVMErrorRef
Opaque reference to an error instance.
Definition Error.h:34
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition Types.h:75
int LLVMBool
Definition Types.h:28
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition Types.h:61
struct LLVMOpaqueTargetMachine * LLVMTargetMachineRef
Interfaces for registering analysis passes, producing common pass manager configurations,...
Abstract Attribute helper functions.
Definition Attributor.h:165
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< LazyCallGraph::SCC, LazyCallGraph & > CGSCCAnalysisManager
The CGSCC analysis manager.
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
PassManager< Module > ModulePassManager
Convenience typedef for a pass manager over modules.
Attribute unwrap(LLVMAttributeRef Attr)
Definition Attributes.h:351
PassManager< Function > FunctionPassManager
Convenience typedef for a pass manager over functions.
LLVMAttributeRef wrap(Attribute Attr)
Definition Attributes.h:346
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39