LLVM  14.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 
20 using namespace llvm;
21 
22 namespace 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.
27 public:
29  bool DebugLogging = false, bool VerifyEach = false,
32 
34  bool VerifyEach;
36 };
37 } // namespace llvm
38 
40  return reinterpret_cast<TargetMachine *>(P);
41 }
42 
45 
53 
54  Module *Mod = unwrap(M);
57 
67 
71  if (VerifyEach) {
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 }
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
PassBuilder.h
LLVMPassBuilderOptionsSetMergeFunctions
void LLVMPassBuilderOptionsSetMergeFunctions(LLVMPassBuilderOptionsRef Options, LLVMBool MergeFunctions)
Definition: PassBuilderBindings.cpp:137
llvm::PassManager::addPass
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same< PassT, PassManager >::value > addPass(PassT &&Pass)
Definition: PassManager.h:553
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
LLVMPassBuilderOptionsSetLoopUnrolling
void LLVMPassBuilderOptionsSetLoopUnrolling(LLVMPassBuilderOptionsRef Options, LLVMBool LoopUnrolling)
Definition: PassBuilderBindings.cpp:111
LLVMPassBuilderOptionsSetSLPVectorization
void LLVMPassBuilderOptionsSetSLPVectorization(LLVMPassBuilderOptionsRef Options, LLVMBool SLPVectorization)
Definition: PassBuilderBindings.cpp:106
llvm::StandardInstrumentations::registerCallbacks
void registerCallbacks(PassInstrumentationCallbacks &PIC, FunctionAnalysisManager *FAM=nullptr)
Definition: StandardInstrumentations.cpp:1216
LLVMPassBuilderOptionsSetLoopVectorization
void LLVMPassBuilderOptionsSetLoopVectorization(LLVMPassBuilderOptionsRef Options, LLVMBool LoopVectorization)
Definition: PassBuilderBindings.cpp:101
LLVMPassBuilderOptionsSetLoopInterleaving
void LLVMPassBuilderOptionsSetLoopInterleaving(LLVMPassBuilderOptionsRef Options, LLVMBool LoopInterleaving)
Definition: PassBuilderBindings.cpp:96
llvm::PipelineTuningOptions
Tunable parameters for passes in the default pipelines.
Definition: PassBuilder.h:37
llvm::VerifierPass
Create a verifier pass.
Definition: Verifier.h:137
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
Passes
const char * Passes
Definition: PassBuilderBindings.cpp:46
LLVMErrorSuccess
return LLVMErrorSuccess
Definition: PassBuilderBindings.cpp:79
PIC
PassInstrumentationCallbacks PIC
Definition: PassBuilderBindings.cpp:55
CBindingWrapping.h
LLVMCreatePassBuilderOptions
LLVMPassBuilderOptionsRef LLVMCreatePassBuilderOptions()
Create a new set of options for a PassBuilder.
Definition: PassBuilderBindings.cpp:82
llvm::PassBuilder::parsePassPipeline
Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText)
Parse a textual pass pipeline description into a ModulePassManager.
Definition: PassBuilder.cpp:1526
PassBuilder.h
llvm::LLVMPassBuilderOptions::VerifyEach
bool VerifyEach
Definition: PassBuilderBindings.cpp:34
LLVMPassBuilderOptionsSetCallGraphProfile
void LLVMPassBuilderOptionsSetCallGraphProfile(LLVMPassBuilderOptionsRef Options, LLVMBool CallGraphProfile)
Definition: PassBuilderBindings.cpp:132
PassOpts
LLVMPassBuilderOptions * PassOpts
Definition: PassBuilderBindings.cpp:50
MAM
ModuleAnalysisManager MAM
Definition: PassBuilderBindings.cpp:61
llvm::PassBuilder
This class provides access to building LLVM's passes.
Definition: PassBuilder.h:84
llvm::LLVMPassBuilderOptions::LLVMPassBuilderOptions
LLVMPassBuilderOptions(bool DebugLogging=false, bool VerifyEach=false, PipelineTuningOptions PTO=PipelineTuningOptions())
Definition: PassBuilderBindings.cpp:28
LLVMPassBuilderOptionsSetVerifyEach
void LLVMPassBuilderOptionsSetVerifyEach(LLVMPassBuilderOptionsRef Options, LLVMBool VerifyEach)
Toggle adding the VerifierPass for the PassBuilder, ensuring all functions inside the module is valid...
Definition: PassBuilderBindings.cpp:86
llvm::unwrap
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:257
Options
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
Definition: PassBuilderBindings.cpp:48
LLVMPassBuilderOptionsRef
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:31
llvm::None
const NoneType None
Definition: None.h:23
LLVMRunPasses
LLVMErrorRef LLVMRunPasses(LLVMModuleRef M, const char *Passes, LLVMTargetMachineRef TM, LLVMPassBuilderOptionsRef Options)
Construct and run a set of passes over a module.
PB
PassBuilder PB(Machine, PassOpts->PTO, None, &PIC)
llvm::PassBuilder::registerFunctionAnalyses
void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis passes.
Definition: PassBuilder.cpp:415
llvm::StandardInstrumentations
This class provides an interface to register all the standard pass instrumentations and manages their...
Definition: StandardInstrumentations.h:413
const
aarch64 promote const
Definition: AArch64PromoteConstant.cpp:232
LLVMTargetMachineRef
typedefLLVM_C_EXTERN_C_BEGIN struct LLVMOpaqueTargetMachine * LLVMTargetMachineRef
Definition: TargetMachine.h:28
llvm::PassBuilder::registerModuleAnalyses
void registerModuleAnalyses(ModuleAnalysisManager &MAM)
Registers all available module analysis passes.
Definition: PassBuilder.cpp:397
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
Debug
bool Debug
Definition: PassBuilderBindings.cpp:51
LLVMDisposePassBuilderOptions
void LLVMDisposePassBuilderOptions(LLVMPassBuilderOptionsRef Options)
Dispose of a heap-allocated PassBuilderOptions instance.
Definition: PassBuilderBindings.cpp:142
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:79
SI
StandardInstrumentations SI(Debug, VerifyEach)
llvm::LLVMPassBuilderOptions
Helper struct for holding a set of builder options for LLVMRunPasses.
Definition: PassBuilderBindings.cpp:26
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::wrap
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:252
DEFINE_SIMPLE_CONVERSION_FUNCTIONS
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMPassBuilderOptions, LLVMPassBuilderOptionsRef) LLVMErrorRef LLVMRunPasses(LLVMModuleRef M
VerifyEach
bool VerifyEach
Definition: PassBuilderBindings.cpp:52
LAM
LoopAnalysisManager LAM
Definition: PassBuilderBindings.cpp:58
llvm::PassManager< Module >
llvm::PassBuilder::registerLoopAnalyses
void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
Definition: PassBuilder.cpp:424
LLVMPassBuilderOptionsSetForgetAllSCEVInLoopUnroll
void LLVMPassBuilderOptionsSetForgetAllSCEVInLoopUnroll(LLVMPassBuilderOptionsRef Options, LLVMBool ForgetAllSCEVInLoopUnroll)
Definition: PassBuilderBindings.cpp:116
Verifier.h
LLVMBool
int LLVMBool
Definition: Types.h:28
LLVMErrorRef
struct LLVMOpaqueError * LLVMErrorRef
Opaque reference to an error instance.
Definition: Error.h:26
llvm::PassBuilder::registerCGSCCAnalyses
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
Definition: PassBuilder.cpp:406
llvm::PassManager::run
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:501
Machine
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:366
llvm::LLVMPassBuilderOptions::DebugLogging
bool DebugLogging
Definition: PassBuilderBindings.cpp:33
llvm::PassInstrumentationCallbacks
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
Definition: PassInstrumentation.h:66
LLVMPassBuilderOptionsSetLicmMssaOptCap
void LLVMPassBuilderOptionsSetLicmMssaOptCap(LLVMPassBuilderOptionsRef Options, unsigned LicmMssaOptCap)
Definition: PassBuilderBindings.cpp:121
llvm::PassBuilder::crossRegisterProxies
void crossRegisterProxies(LoopAnalysisManager &LAM, FunctionAnalysisManager &FAM, CGSCCAnalysisManager &CGAM, ModuleAnalysisManager &MAM)
Cross register the analysis managers through their proxies.
Definition: PassBuilder.cpp:1501
LLVMPassBuilderOptionsSetDebugLogging
void LLVMPassBuilderOptionsSetDebugLogging(LLVMPassBuilderOptionsRef Options, LLVMBool DebugLogging)
Toggle debug logging when running the PassBuilder.
Definition: PassBuilderBindings.cpp:91
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::LLVMPassBuilderOptions::PTO
PipelineTuningOptions PTO
Definition: PassBuilderBindings.cpp:35
Mod
Module * Mod
Definition: PassBuilderBindings.cpp:54
MPM
ModulePassManager MPM
Definition: PassBuilderBindings.cpp:70
CGAM
CGSCCAnalysisManager CGAM
Definition: PassBuilderBindings.cpp:60
LLVMPassBuilderOptionsSetLicmMssaNoAccForPromotionCap
void LLVMPassBuilderOptionsSetLicmMssaNoAccForPromotionCap(LLVMPassBuilderOptionsRef Options, unsigned LicmMssaNoAccForPromotionCap)
Definition: PassBuilderBindings.cpp:126
StandardInstrumentations.h
LLVMModuleRef
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:61