LLVM 17.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
15#include "llvm/IR/Verifier.h"
19
20using namespace llvm;
21
22namespace llvm {
23/// Helper struct for holding a set of builder options for LLVMRunPasses. This
24/// structure is used to keep LLVMRunPasses backwards compatible with future
25/// versions in case we modify the options the new Pass Manager utilizes.
27public:
29 bool DebugLogging = false, bool VerifyEach = false,
32
36};
37} // namespace llvm
38
40 return reinterpret_cast<TargetMachine *>(P);
41}
42
45
49 TargetMachine *Machine = unwrap(TM);
53
56 PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC);
57
67
69 SI.registerCallbacks(PIC, &FAM);
73 }
74 if (auto Err = PB.parsePassPipeline(MPM, Passes)) {
75 return wrap(std::move(Err));
76 }
77
78 MPM.run(*Mod, MAM);
80}
81
83 return wrap(new LLVMPassBuilderOptions());
84}
85
88 unwrap(Options)->VerifyEach = VerifyEach;
89}
90
92 LLVMBool DebugLogging) {
93 unwrap(Options)->DebugLogging = DebugLogging;
94}
95
97 LLVMPassBuilderOptionsRef Options, LLVMBool LoopInterleaving) {
98 unwrap(Options)->PTO.LoopInterleaving = LoopInterleaving;
99}
100
102 LLVMPassBuilderOptionsRef Options, LLVMBool LoopVectorization) {
103 unwrap(Options)->PTO.LoopVectorization = LoopVectorization;
104}
105
107 LLVMPassBuilderOptionsRef Options, LLVMBool SLPVectorization) {
108 unwrap(Options)->PTO.SLPVectorization = SLPVectorization;
109}
110
112 LLVMBool LoopUnrolling) {
113 unwrap(Options)->PTO.LoopUnrolling = LoopUnrolling;
114}
115
117 LLVMPassBuilderOptionsRef Options, LLVMBool ForgetAllSCEVInLoopUnroll) {
118 unwrap(Options)->PTO.ForgetAllSCEVInLoopUnroll = ForgetAllSCEVInLoopUnroll;
119}
120
122 unsigned LicmMssaOptCap) {
123 unwrap(Options)->PTO.LicmMssaOptCap = LicmMssaOptCap;
124}
125
127 LLVMPassBuilderOptionsRef Options, unsigned LicmMssaNoAccForPromotionCap) {
128 unwrap(Options)->PTO.LicmMssaNoAccForPromotionCap =
129 LicmMssaNoAccForPromotionCap;
130}
131
133 LLVMPassBuilderOptionsRef Options, LLVMBool CallGraphProfile) {
134 unwrap(Options)->PTO.CallGraphProfile = CallGraphProfile;
135}
136
138 LLVMBool MergeFunctions) {
139 unwrap(Options)->PTO.MergeFunctions = MergeFunctions;
140}
141
143 delete unwrap(Options);
144}
aarch64 promote const
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
#define P(N)
CGSCCAnalysisManager CGAM
static TargetMachine * unwrap(LLVMTargetMachineRef P)
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
ModulePassManager MPM
LLVMPassBuilderOptions * PassOpts
Module * Mod
LoopAnalysisManager LAM
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
return LLVMErrorSuccess
const char LLVMTargetMachineRef TM
bool Debug
bool VerifyEach
PassInstrumentationCallbacks PIC
const char * Passes
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)
@ SI
This header defines a class that provides bookkeeping for all standard (i.e in-tree) pass instrumenta...
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:620
Helper struct for holding a set of builder options for LLVMRunPasses.
LLVMPassBuilderOptions(bool DebugLogging=false, bool VerifyEach=false, PipelineTuningOptions PTO=PipelineTuningOptions())
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:262
This class provides access to building LLVM's passes.
Definition: PassBuilder.h:100
void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
void crossRegisterProxies(LoopAnalysisManager &LAM, FunctionAnalysisManager &FAM, CGSCCAnalysisManager &CGAM, ModuleAnalysisManager &MAM)
Cross register the analysis managers through their proxies.
Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText)
Parse a textual pass pipeline description into a ModulePassManager.
void registerModuleAnalyses(ModuleAnalysisManager &MAM)
Registers all available module analysis passes.
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis 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< PassT, PassManager >::value > addPass(PassT &&Pass)
Definition: PassManager.h:544
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
Definition: PassManager.h:498
Tunable parameters for passes in the default pipelines.
Definition: PassBuilder.h:41
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.
Definition: TargetMachine.h:78
Create a verifier pass.
Definition: Verifier.h:132
void LLVMPassBuilderOptionsSetMergeFunctions(LLVMPassBuilderOptionsRef Options, LLVMBool MergeFunctions)
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 LLVMPassBuilderOptionsSetVerifyEach(LLVMPassBuilderOptionsRef Options, LLVMBool VerifyEach)
Toggle adding the VerifierPass for the PassBuilder, ensuring all functions inside the module is valid...
void LLVMPassBuilderOptionsSetLicmMssaOptCap(LLVMPassBuilderOptionsRef Options, unsigned LicmMssaOptCap)
void LLVMDisposePassBuilderOptions(LLVMPassBuilderOptionsRef Options)
Dispose of a heap-allocated PassBuilderOptions instance.
void LLVMPassBuilderOptionsSetLicmMssaNoAccForPromotionCap(LLVMPassBuilderOptionsRef Options, unsigned LicmMssaNoAccForPromotionCap)
void LLVMPassBuilderOptionsSetSLPVectorization(LLVMPassBuilderOptionsRef Options, LLVMBool SLPVectorization)
void LLVMPassBuilderOptionsSetCallGraphProfile(LLVMPassBuilderOptionsRef Options, LLVMBool CallGraphProfile)
void LLVMPassBuilderOptionsSetLoopVectorization(LLVMPassBuilderOptionsRef Options, LLVMBool LoopVectorization)
void LLVMPassBuilderOptionsSetLoopUnrolling(LLVMPassBuilderOptionsRef Options, LLVMBool LoopUnrolling)
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:38
void LLVMPassBuilderOptionsSetForgetAllSCEVInLoopUnroll(LLVMPassBuilderOptionsRef Options, LLVMBool ForgetAllSCEVInLoopUnroll)
void LLVMPassBuilderOptionsSetLoopInterleaving(LLVMPassBuilderOptionsRef Options, LLVMBool LoopInterleaving)
LLVMErrorRef LLVMRunPasses(LLVMModuleRef M, const char *Passes, LLVMTargetMachineRef TM, LLVMPassBuilderOptionsRef Options)
Construct and run a set of passes over a module.
struct LLVMOpaqueError * LLVMErrorRef
Opaque reference to an error instance.
Definition: Error.h:33
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
Definition: TargetMachine.h:34
Interfaces for registering analysis passes, producing common pass manager configurations,...
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:280