LLVM  8.0.1
Scalar.cpp
Go to the documentation of this file.
1 //===-- Scalar.cpp --------------------------------------------------------===//
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 //
10 // This file implements common infrastructure for libLLVMScalarOpts.a, which
11 // implements several scalar transformations over the LLVM intermediate
12 // representation, including the C bindings for that library.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #include "llvm/Transforms/Scalar.h"
17 #include "llvm-c/Initialization.h"
20 #include "llvm/Analysis/Passes.h"
23 #include "llvm/IR/DataLayout.h"
25 #include "llvm/IR/Verifier.h"
26 #include "llvm/InitializePasses.h"
31 
32 using namespace llvm;
33 
34 /// initializeScalarOptsPasses - Initialize all passes linked into the
35 /// ScalarOpts library.
74  initializeLoopRerollPass(Registry);
75  initializeLoopUnrollPass(Registry);
85  initializeMergeICmpsPass(Registry);
90  initializeRegToMemPass(Registry);
111 }
112 
114  unwrap(PM)->add(createLoopSimplifyCFGPass());
115 }
116 
119 }
120 
122  unwrap(PM)->add(createAggressiveDCEPass());
123 }
124 
126  unwrap(PM)->add(createBitTrackingDCEPass());
127 }
128 
131 }
132 
134  unwrap(PM)->add(createCFGSimplificationPass(1, false, false, true));
135 }
136 
139 }
140 
142  unwrap(PM)->add(createScalarizerPass());
143 }
144 
146  unwrap(PM)->add(createGVNPass());
147 }
148 
150  unwrap(PM)->add(createNewGVNPass());
151 }
152 
155 }
156 
158  unwrap(PM)->add(createIndVarSimplifyPass());
159 }
160 
162  unwrap(PM)->add(createJumpThreadingPass());
163 }
164 
166  unwrap(PM)->add(createLoopSinkPass());
167 }
168 
170  unwrap(PM)->add(createLICMPass());
171 }
172 
174  unwrap(PM)->add(createLoopDeletionPass());
175 }
176 
178  unwrap(PM)->add(createLoopIdiomPass());
179 }
180 
182  unwrap(PM)->add(createLoopRotatePass());
183 }
184 
186  unwrap(PM)->add(createLoopRerollPass());
187 }
188 
190  unwrap(PM)->add(createLoopUnrollPass());
191 }
192 
195 }
196 
198  unwrap(PM)->add(createLoopUnswitchPass());
199 }
200 
202  unwrap(PM)->add(createLowerAtomicPass());
203 }
204 
206  unwrap(PM)->add(createMemCpyOptPass());
207 }
208 
211 }
212 
214  unwrap(PM)->add(createReassociatePass());
215 }
216 
218  unwrap(PM)->add(createSCCPPass());
219 }
220 
222  unwrap(PM)->add(createSROAPass());
223 }
224 
226  unwrap(PM)->add(createSROAPass());
227 }
228 
230  int Threshold) {
231  unwrap(PM)->add(createSROAPass());
232 }
233 
235  // NOTE: The simplify-libcalls pass has been removed.
236 }
237 
240 }
241 
244 }
245 
248 }
249 
251  unwrap(PM)->add(createVerifierPass());
252 }
253 
256 }
257 
259  unwrap(PM)->add(createEarlyCSEPass(false/*=UseMemorySSA*/));
260 }
261 
263  unwrap(PM)->add(createEarlyCSEPass(true/*=UseMemorySSA*/));
264 }
265 
267  unwrap(PM)->add(createGVNHoistPass());
268 }
269 
272 }
273 
276 }
277 
279  unwrap(PM)->add(createBasicAAWrapperPass());
280 }
281 
284 }
285 
288 }
void initializeEntryExitInstrumenterPass(PassRegistry &)
void initializeNewGVNLegacyPassPass(PassRegistry &)
void initializeEarlyCSELegacyPassPass(PassRegistry &)
void initializeDCELegacyPassPass(PassRegistry &)
FunctionPass * createGVNPass(bool NoLoads=false)
Create a legacy GVN pass.
Definition: GVN.cpp:2599
void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM)
See llvm::createJumpThreadingPass function.
Definition: Scalar.cpp:161
void initializeLoopUnswitchPass(PassRegistry &)
void LLVMAddGVNPass(LLVMPassManagerRef PM)
See llvm::createGVNPass function.
Definition: Scalar.cpp:145
Pass * createLoopRerollPass()
void initializeBDCELegacyPassPass(PassRegistry &)
void initializeLoopAccessLegacyAnalysisPass(PassRegistry &)
This class represents lattice values for constants.
Definition: AllocatorList.h:24
void initializeConstantHoistingLegacyPassPass(PassRegistry &)
void initializeJumpThreadingPass(PassRegistry &)
void LLVMAddLICMPass(LLVMPassManagerRef PM)
See llvm::createLICMPass function.
Definition: Scalar.cpp:169
void initializeDSELegacyPassPass(PassRegistry &)
void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM)
See llvm::createSimplifyLibCallsPass function.
Definition: Scalar.cpp:234
void initializeLoopDeletionLegacyPassPass(PassRegistry &)
void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM)
See llvm::createTypeBasedAliasAnalysisPass function.
Definition: Scalar.cpp:270
void initializeGuardWideningLegacyPassPass(PassRegistry &)
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:45
This is the interface for a metadata-based scoped no-alias analysis.
FunctionPass * createVerifierPass(bool FatalErrors=true)
Definition: Verifier.cpp:5236
void LLVMAddEarlyCSEMemSSAPass(LLVMPassManagerRef PM)
See llvm::createEarlyCSEPass function.
Definition: Scalar.cpp:262
void LLVMAddReassociatePass(LLVMPassManagerRef PM)
See llvm::createReassociatePass function.
Definition: Scalar.cpp:213
void initializeScalarOpts(PassRegistry &)
Initialize all passes linked into the ScalarOpts library.
Definition: Scalar.cpp:36
void initializeLoopStrengthReducePass(PassRegistry &)
void initializePlaceSafepointsPass(PassRegistry &)
void initializeDivRemPairsLegacyPassPass(PassRegistry &)
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
Definition: Types.h:131
void initializeLoopRerollPass(PassRegistry &)
FunctionPass * createGVNHoistPass()
Definition: GVNHoist.cpp:1207
void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM)
See llvm::createConstantPropagationPass function.
Definition: Scalar.cpp:242
FunctionPass * createDemoteRegisterToMemoryPass()
Definition: Reg2Mem.cpp:127
void LLVMAddNewGVNPass(LLVMPassManagerRef PM)
See llvm::createGVNPass function.
Definition: Scalar.cpp:149
void LLVMAddLoopSinkPass(LLVMPassManagerRef PM)
Definition: Scalar.cpp:165
ImmutablePass * createScopedNoAliasAAWrapperPass()
FunctionPass * createAlignmentFromAssumptionsPass()
FunctionPass * createJumpThreadingPass(int Threshold=-1)
void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM)
See llvm::createLoopUnrollPass function.
Definition: Scalar.cpp:189
FunctionPass * createCFGSimplificationPass(unsigned Threshold=1, bool ForwardSwitchCond=false, bool ConvertSwitch=false, bool KeepLoops=true, bool SinkCommon=false, std::function< bool(const Function &)> Ftor=nullptr)
Pass * createLoopUnrollPass(int OptLevel=2, bool OnlyWhenForced=false, int Threshold=-1, int Count=-1, int AllowPartial=-1, int Runtime=-1, int UpperBound=-1, int AllowPeeling=-1)
void initializeSimpleLoopUnswitchLegacyPassPass(PassRegistry &)
void initializeADCELegacyPassPass(PassRegistry &)
void LLVMAddScalarizerPass(LLVMPassManagerRef PM)
See llvm::createScalarizerPass function.
Definition: Scalar.cpp:141
void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM)
See llvm::createSROAPass function.
Definition: Scalar.cpp:225
void initializeScalarizerLegacyPassPass(PassRegistry &)
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:195
void initializeSCCPLegacyPassPass(PassRegistry &)
void LLVMAddUnifyFunctionExitNodesPass(LLVMPassManagerRef PM)
See llvm::createUnifyFunctionExitNodesPass function.
Definition: Scalar.cpp:286
FunctionPass * createConstantPropagationPass()
FunctionPass * createReassociatePass()
void initializeCallSiteSplittingLegacyPassPass(PassRegistry &)
FunctionPass * createSCCPPass()
Definition: SCCP.cpp:1870
void initializeRewriteStatepointsForGCLegacyPassPass(PassRegistry &)
void initializeStraightLineStrengthReducePass(PassRegistry &)
FunctionPass * createPartiallyInlineLibCallsPass()
void LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM)
See llvm::createMergedLoadStoreMotionPass function.
Definition: Scalar.cpp:153
void initializeConstantPropagationPass(PassRegistry &)
void initializeLoopLoadEliminationPass(PassRegistry &)
void initializeLoopIdiomRecognizeLegacyPassPass(PassRegistry &)
Pass * createUnifyFunctionExitNodesPass()
void initializeSpeculativeExecutionLegacyPassPass(PassRegistry &)
void initializeLoopUnrollPass(PassRegistry &)
void LLVMAddScopedNoAliasAAPass(LLVMPassManagerRef PM)
See llvm::createScopedNoAliasAAPass function.
Definition: Scalar.cpp:274
void LLVMAddLoopRerollPass(LLVMPassManagerRef PM)
See llvm::createLoopRerollPass function.
Definition: Scalar.cpp:185
void initializeSeparateConstOffsetFromGEPPass(PassRegistry &)
Pass * createLoopUnrollAndJamPass(int OptLevel=2)
void initializeGVNLegacyPassPass(PassRegistry &)
void initializeLoopDataPrefetchLegacyPassPass(PassRegistry &)
void initializePlaceBackedgeSafepointsImplPass(PassRegistry &)
void initializeIndVarSimplifyLegacyPassPass(PassRegistry &)
void LLVMAddLoopSimplifyCFGPass(LLVMPassManagerRef PM)
Definition: Scalar.cpp:113
Pass * createCorrelatedValuePropagationPass()
void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM)
See llvm::createDeadStoreEliminationPass function.
Definition: Scalar.cpp:137
void initializeLoopInstSimplifyLegacyPassPass(PassRegistry &)
void initializeLowerExpectIntrinsicPass(PassRegistry &)
This is the interface for a metadata-based TBAA.
FunctionPass * createTailCallEliminationPass()
This file provides the interface for LLVM&#39;s Global Value Numbering pass which eliminates fully redund...
void LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM)
See llvm::createAlignmentFromAssumptionsPass function.
Definition: Scalar.cpp:129
Pass * createLICMPass()
Definition: LICM.cpp:278
FunctionPass * createDeadStoreEliminationPass()
void initializeLowerAtomicLegacyPassPass(PassRegistry &)
void LLVMAddLoopRotatePass(LLVMPassManagerRef PM)
See llvm::createLoopRotatePass function.
Definition: Scalar.cpp:181
void initializeSROALegacyPassPass(PassRegistry &)
void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM, int Threshold)
See llvm::createSROAPass function.
Definition: Scalar.cpp:229
FunctionPass * createMemCpyOptPass()
The public interface to this file...
FunctionPass * createBitTrackingDCEPass()
Definition: BDCE.cpp:184
void initializeSinkingLegacyPassPass(PassRegistry &)
void initializeMakeGuardsExplicitLegacyPassPass(PassRegistry &)
void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM)
See llvm::createLoopDeletionPass function.
Definition: Scalar.cpp:173
Pass * createLoopSinkPass()
void initializeInferAddressSpacesPass(PassRegistry &)
void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM)
See llvm::createEarlyCSEPass function.
Definition: Scalar.cpp:258
void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM)
See llvm::createSROAPass function.
Definition: Scalar.cpp:221
void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM)
See llvm::createLoopIdiomPass function.
Definition: Scalar.cpp:177
void initializeFloat2IntLegacyPassPass(PassRegistry &)
void initializeLoopRotateLegacyPassPass(PassRegistry &)
void initializeStructurizeCFGPass(PassRegistry &)
void initializeMemCpyOptLegacyPassPass(PassRegistry &)
void initializeLoopInterchangePass(PassRegistry &)
void initializeRegToMemPass(PassRegistry &)
void initializeLoopVersioningLICMPass(PassRegistry &)
void initializeLoopGuardWideningLegacyPassPass(PassRegistry &)
void initializeCorrelatedValuePropagationPass(PassRegistry &)
void LLVMAddSCCPPass(LLVMPassManagerRef PM)
See llvm::createSCCPPass function.
Definition: Scalar.cpp:217
void LLVMInitializeScalarOpts(LLVMPassRegistryRef R)
Definition: Scalar.cpp:117
void LLVMAddVerifierPass(LLVMPassManagerRef PM)
See llvm::createVerifierPass function.
Definition: Scalar.cpp:250
void initializeLoopDistributeLegacyPass(PassRegistry &)
Pass * createLoopSimplifyCFGPass()
Pass * createLowerAtomicPass()
FunctionPass * createMergedLoadStoreMotionPass()
createMergedLoadStoreMotionPass - The public interface to this file.
struct LLVMOpaquePassManager * LLVMPassManagerRef
Definition: Types.h:128
void initializeTailCallElimPass(PassRegistry &)
This pass converts vector operations into scalar operations, in order to expose optimization opportun...
Pass * createLoopDeletionPass()
void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM)
See llvm::demotePromoteMemoryToRegisterPass function.
Definition: Scalar.cpp:246
FunctionPass * createBasicAAWrapperPass()
Pass * createLoopUnswitchPass(bool OptimizeForSize=false, bool hasBranchDivergence=false)
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
void LLVMAddLoopUnrollAndJamPass(LLVMPassManagerRef PM)
See llvm::createLoopUnrollAndJamPass function.
Definition: Scalar.cpp:193
void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM)
See llvm::createBasicAliasAnalysisPass function.
Definition: Scalar.cpp:278
void LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM)
See llvm::createBitTrackingDCEPass function.
Definition: Scalar.cpp:125
void initializeLoopSimplifyCFGLegacyPassPass(PassRegistry &)
Pass * createLoopIdiomPass()
void initializeLoopVersioningPassPass(PassRegistry &)
void initializeInstSimplifyLegacyPassPass(PassRegistry &)
void LLVMAddLowerAtomicPass(LLVMPassManagerRef PM)
See llvm::createLowerAtomicPass function.
Definition: Scalar.cpp:201
void initializeGVNHoistLegacyPassPass(PassRegistry &)
void initializeGVNSinkLegacyPassPass(PassRegistry &)
void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM)
See llvm::createCorrelatedValuePropagationPass function.
Definition: Scalar.cpp:254
void initializeAlignmentFromAssumptionsPass(PassRegistry &)
void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM)
See llvm::createLowerExpectIntrinsicPass function.
Definition: Scalar.cpp:282
FunctionPass * createSROAPass()
Definition: SROA.cpp:4585
void initializeNaryReassociateLegacyPassPass(PassRegistry &)
void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM)
See llvm::createIndVarSimplifyPass function.
Definition: Scalar.cpp:157
void initializeWarnMissedTransformationsLegacyPass(PassRegistry &)
void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM)
See llvm::createTailCallEliminationPass function.
Definition: Scalar.cpp:238
ImmutablePass * createTypeBasedAAWrapperPass()
void initializeIRCELegacyPassPass(PassRegistry &)
void LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM)
See llvm::createPartiallyInlineLibCallsPass function.
Definition: Scalar.cpp:209
void initializeCFGSimplifyPassPass(PassRegistry &)
void initializeLoopPredicationLegacyPassPass(PassRegistry &)
void initializeLegacyLoopSinkPassPass(PassRegistry &)
void initializeReassociateLegacyPassPass(PassRegistry &)
void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM)
See llvm::createLoopUnswitchPass function.
Definition: Scalar.cpp:197
void initializeEarlyCSEMemSSALegacyPassPass(PassRegistry &)
void initializeLegacyLICMPassPass(PassRegistry &)
FunctionPass * createEarlyCSEPass(bool UseMemorySSA=false)
Definition: EarlyCSE.cpp:1320
void initializeLoopUnrollAndJamPass(PassRegistry &)
FunctionPass * createScalarizerPass()
Create a legacy pass manager instance of the Scalarizer pass.
Definition: Scalarizer.cpp:298
FunctionPass * createNewGVNPass()
Definition: NewGVN.cpp:4249
This is the interface for LLVM&#39;s primary stateless and local alias analysis.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:39
void initializePartiallyInlineLibCallsLegacyPassPass(PassRegistry &)
void initializeMergeICmpsPass(PassRegistry &)
void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM)
See llvm::createCFGSimplificationPass function.
Definition: Scalar.cpp:133
void initializePostInlineEntryExitInstrumenterPass(PassRegistry &)
void initializeMergedLoadStoreMotionLegacyPassPass(PassRegistry &)
void LLVMAddGVNHoistLegacyPass(LLVMPassManagerRef PM)
Definition: Scalar.cpp:266
void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM)
See llvm::createMemCpyOptPass function.
Definition: Scalar.cpp:205
void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM)
See llvm::createAggressiveDCEPass function.
Definition: Scalar.cpp:121
void initializeLowerGuardIntrinsicLegacyPassPass(PassRegistry &)
Pass * createLoopRotatePass(int MaxHeaderSize=-1)
Pass * createIndVarSimplifyPass()
FunctionPass * createAggressiveDCEPass()
Definition: ADCE.cpp:734
FunctionPass * createLowerExpectIntrinsicPass()
void initializeDeadInstEliminationPass(PassRegistry &)
void initializeFlattenCFGPassPass(PassRegistry &)