LLVM  9.0.0svn
Scalar.cpp
Go to the documentation of this file.
1 //===-- Scalar.cpp --------------------------------------------------------===//
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 //
9 // This file implements common infrastructure for libLLVMScalarOpts.a, which
10 // implements several scalar transformations over the LLVM intermediate
11 // representation, including the C bindings for that library.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm/Transforms/Scalar.h"
16 #include "llvm-c/Initialization.h"
19 #include "llvm/Analysis/Passes.h"
22 #include "llvm/IR/DataLayout.h"
24 #include "llvm/IR/Verifier.h"
25 #include "llvm/InitializePasses.h"
30 
31 using namespace llvm;
32 
33 /// initializeScalarOptsPasses - Initialize all passes linked into the
34 /// ScalarOpts library.
74  initializeLoopRerollPass(Registry);
75  initializeLoopUnrollPass(Registry);
86  initializeMergeICmpsPass(Registry);
91  initializeRegToMemPass(Registry);
112 }
113 
115  unwrap(PM)->add(createLoopSimplifyCFGPass());
116 }
117 
120 }
121 
123  unwrap(PM)->add(createAggressiveDCEPass());
124 }
125 
127  unwrap(PM)->add(createBitTrackingDCEPass());
128 }
129 
132 }
133 
135  unwrap(PM)->add(createCFGSimplificationPass(1, false, false, true));
136 }
137 
140 }
141 
143  unwrap(PM)->add(createScalarizerPass());
144 }
145 
147  unwrap(PM)->add(createGVNPass());
148 }
149 
151  unwrap(PM)->add(createNewGVNPass());
152 }
153 
156 }
157 
159  unwrap(PM)->add(createIndVarSimplifyPass());
160 }
161 
163  unwrap(PM)->add(createJumpThreadingPass());
164 }
165 
167  unwrap(PM)->add(createLoopSinkPass());
168 }
169 
171  unwrap(PM)->add(createLICMPass());
172 }
173 
175  unwrap(PM)->add(createLoopDeletionPass());
176 }
177 
179  unwrap(PM)->add(createLoopIdiomPass());
180 }
181 
183  unwrap(PM)->add(createLoopRotatePass());
184 }
185 
187  unwrap(PM)->add(createLoopRerollPass());
188 }
189 
191  unwrap(PM)->add(createLoopUnrollPass());
192 }
193 
196 }
197 
199  unwrap(PM)->add(createLoopUnswitchPass());
200 }
201 
203  unwrap(PM)->add(createLowerAtomicPass());
204 }
205 
207  unwrap(PM)->add(createMemCpyOptPass());
208 }
209 
212 }
213 
215  unwrap(PM)->add(createReassociatePass());
216 }
217 
219  unwrap(PM)->add(createSCCPPass());
220 }
221 
223  unwrap(PM)->add(createSROAPass());
224 }
225 
227  unwrap(PM)->add(createSROAPass());
228 }
229 
231  int Threshold) {
232  unwrap(PM)->add(createSROAPass());
233 }
234 
236  // NOTE: The simplify-libcalls pass has been removed.
237 }
238 
241 }
242 
245 }
246 
249 }
250 
252  unwrap(PM)->add(createVerifierPass());
253 }
254 
257 }
258 
260  unwrap(PM)->add(createEarlyCSEPass(false/*=UseMemorySSA*/));
261 }
262 
264  unwrap(PM)->add(createEarlyCSEPass(true/*=UseMemorySSA*/));
265 }
266 
268  unwrap(PM)->add(createGVNHoistPass());
269 }
270 
273 }
274 
277 }
278 
280  unwrap(PM)->add(createBasicAAWrapperPass());
281 }
282 
285 }
286 
289 }
void initializeEntryExitInstrumenterPass(PassRegistry &)
void initializeNewGVNLegacyPassPass(PassRegistry &)
void initializeEarlyCSELegacyPassPass(PassRegistry &)
void initializeDCELegacyPassPass(PassRegistry &)
void initializeLoopFuseLegacyPass(PassRegistry &)
FunctionPass * createGVNPass(bool NoLoads=false)
Create a legacy GVN pass.
Definition: GVN.cpp:2591
void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM)
See llvm::createJumpThreadingPass function.
Definition: Scalar.cpp:162
void initializeLoopUnswitchPass(PassRegistry &)
void LLVMAddGVNPass(LLVMPassManagerRef PM)
See llvm::createGVNPass function.
Definition: Scalar.cpp:146
Pass * createLoopRerollPass()
void initializeBDCELegacyPassPass(PassRegistry &)
void initializeLoopAccessLegacyAnalysisPass(PassRegistry &)
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void initializeConstantHoistingLegacyPassPass(PassRegistry &)
void initializeJumpThreadingPass(PassRegistry &)
void LLVMAddLICMPass(LLVMPassManagerRef PM)
See llvm::createLICMPass function.
Definition: Scalar.cpp:170
void initializeDSELegacyPassPass(PassRegistry &)
void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM)
See llvm::createSimplifyLibCallsPass function.
Definition: Scalar.cpp:235
void initializeLoopDeletionLegacyPassPass(PassRegistry &)
void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM)
See llvm::createTypeBasedAliasAnalysisPass function.
Definition: Scalar.cpp:271
void initializeGuardWideningLegacyPassPass(PassRegistry &)
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:44
This is the interface for a metadata-based scoped no-alias analysis.
FunctionPass * createVerifierPass(bool FatalErrors=true)
Definition: Verifier.cpp:5376
void LLVMAddEarlyCSEMemSSAPass(LLVMPassManagerRef PM)
See llvm::createEarlyCSEPass function.
Definition: Scalar.cpp:263
void LLVMAddReassociatePass(LLVMPassManagerRef PM)
See llvm::createReassociatePass function.
Definition: Scalar.cpp:214
void initializeScalarOpts(PassRegistry &)
Initialize all passes linked into the ScalarOpts library.
Definition: Scalar.cpp:35
void initializeLoopStrengthReducePass(PassRegistry &)
void initializePlaceSafepointsPass(PassRegistry &)
void initializeDivRemPairsLegacyPassPass(PassRegistry &)
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
Definition: Types.h:131
void initializeLoopRerollPass(PassRegistry &)
FunctionPass * createGVNHoistPass()
Definition: GVNHoist.cpp:1206
void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM)
See llvm::createConstantPropagationPass function.
Definition: Scalar.cpp:243
FunctionPass * createDemoteRegisterToMemoryPass()
Definition: Reg2Mem.cpp:126
void LLVMAddNewGVNPass(LLVMPassManagerRef PM)
See llvm::createGVNPass function.
Definition: Scalar.cpp:150
void LLVMAddLoopSinkPass(LLVMPassManagerRef PM)
Definition: Scalar.cpp:166
ImmutablePass * createScopedNoAliasAAWrapperPass()
FunctionPass * createAlignmentFromAssumptionsPass()
FunctionPass * createJumpThreadingPass(int Threshold=-1)
void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM)
See llvm::createLoopUnrollPass function.
Definition: Scalar.cpp:190
FunctionPass * createCFGSimplificationPass(unsigned Threshold=1, bool ForwardSwitchCond=false, bool ConvertSwitch=false, bool KeepLoops=true, bool SinkCommon=false, std::function< bool(const Function &)> Ftor=nullptr)
void initializeSimpleLoopUnswitchLegacyPassPass(PassRegistry &)
void initializeADCELegacyPassPass(PassRegistry &)
void LLVMAddScalarizerPass(LLVMPassManagerRef PM)
See llvm::createScalarizerPass function.
Definition: Scalar.cpp:142
void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM)
See llvm::createSROAPass function.
Definition: Scalar.cpp:226
void initializeScalarizerLegacyPassPass(PassRegistry &)
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:194
void initializeSCCPLegacyPassPass(PassRegistry &)
void LLVMAddUnifyFunctionExitNodesPass(LLVMPassManagerRef PM)
See llvm::createUnifyFunctionExitNodesPass function.
Definition: Scalar.cpp:287
FunctionPass * createConstantPropagationPass()
FunctionPass * createReassociatePass()
void initializeCallSiteSplittingLegacyPassPass(PassRegistry &)
FunctionPass * createSCCPPass()
Definition: SCCP.cpp:1883
void initializeLowerWidenableConditionLegacyPassPass(PassRegistry &)
void initializeRewriteStatepointsForGCLegacyPassPass(PassRegistry &)
void initializeStraightLineStrengthReducePass(PassRegistry &)
FunctionPass * createPartiallyInlineLibCallsPass()
void LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM)
See llvm::createMergedLoadStoreMotionPass function.
Definition: Scalar.cpp:154
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:275
void LLVMAddLoopRerollPass(LLVMPassManagerRef PM)
See llvm::createLoopRerollPass function.
Definition: Scalar.cpp:186
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:114
Pass * createCorrelatedValuePropagationPass()
void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM)
See llvm::createDeadStoreEliminationPass function.
Definition: Scalar.cpp:138
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:130
Pass * createLICMPass()
Definition: LICM.cpp:311
FunctionPass * createDeadStoreEliminationPass()
void initializeLowerAtomicLegacyPassPass(PassRegistry &)
void LLVMAddLoopRotatePass(LLVMPassManagerRef PM)
See llvm::createLoopRotatePass function.
Definition: Scalar.cpp:182
void initializeSROALegacyPassPass(PassRegistry &)
void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM, int Threshold)
See llvm::createSROAPass function.
Definition: Scalar.cpp:230
FunctionPass * createMemCpyOptPass()
The public interface to this file...
FunctionPass * createBitTrackingDCEPass()
Definition: BDCE.cpp:183
void initializeSinkingLegacyPassPass(PassRegistry &)
void initializeMakeGuardsExplicitLegacyPassPass(PassRegistry &)
void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM)
See llvm::createLoopDeletionPass function.
Definition: Scalar.cpp:174
Pass * createLoopSinkPass()
void initializeInferAddressSpacesPass(PassRegistry &)
void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM)
See llvm::createEarlyCSEPass function.
Definition: Scalar.cpp:259
void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM)
See llvm::createSROAPass function.
Definition: Scalar.cpp:222
void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM)
See llvm::createLoopIdiomPass function.
Definition: Scalar.cpp:178
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:218
void LLVMInitializeScalarOpts(LLVMPassRegistryRef R)
Definition: Scalar.cpp:118
void LLVMAddVerifierPass(LLVMPassManagerRef PM)
See llvm::createVerifierPass function.
Definition: Scalar.cpp:251
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:247
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:194
void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM)
See llvm::createBasicAliasAnalysisPass function.
Definition: Scalar.cpp:279
void LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM)
See llvm::createBitTrackingDCEPass function.
Definition: Scalar.cpp:126
void initializeLoopSimplifyCFGLegacyPassPass(PassRegistry &)
Pass * createLoopIdiomPass()
void initializeLoopVersioningPassPass(PassRegistry &)
void initializeInstSimplifyLegacyPassPass(PassRegistry &)
void LLVMAddLowerAtomicPass(LLVMPassManagerRef PM)
See llvm::createLowerAtomicPass function.
Definition: Scalar.cpp:202
void initializeGVNHoistLegacyPassPass(PassRegistry &)
void initializeGVNSinkLegacyPassPass(PassRegistry &)
void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM)
See llvm::createCorrelatedValuePropagationPass function.
Definition: Scalar.cpp:255
void initializeAlignmentFromAssumptionsPass(PassRegistry &)
void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM)
See llvm::createLowerExpectIntrinsicPass function.
Definition: Scalar.cpp:283
FunctionPass * createSROAPass()
Definition: SROA.cpp:4596
void initializeNaryReassociateLegacyPassPass(PassRegistry &)
void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM)
See llvm::createIndVarSimplifyPass function.
Definition: Scalar.cpp:158
void initializeWarnMissedTransformationsLegacyPass(PassRegistry &)
void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM)
See llvm::createTailCallEliminationPass function.
Definition: Scalar.cpp:239
ImmutablePass * createTypeBasedAAWrapperPass()
void initializeIRCELegacyPassPass(PassRegistry &)
Pass * createLoopUnrollPass(int OptLevel=2, bool OnlyWhenForced=false, bool ForgetAllSCEV=false, int Threshold=-1, int Count=-1, int AllowPartial=-1, int Runtime=-1, int UpperBound=-1, int AllowPeeling=-1)
void LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM)
See llvm::createPartiallyInlineLibCallsPass function.
Definition: Scalar.cpp:210
void initializeCFGSimplifyPassPass(PassRegistry &)
void initializeLoopPredicationLegacyPassPass(PassRegistry &)
void initializeLegacyLoopSinkPassPass(PassRegistry &)
void initializeReassociateLegacyPassPass(PassRegistry &)
void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM)
See llvm::createLoopUnswitchPass function.
Definition: Scalar.cpp:198
void initializeEarlyCSEMemSSALegacyPassPass(PassRegistry &)
void initializeLegacyLICMPassPass(PassRegistry &)
FunctionPass * createEarlyCSEPass(bool UseMemorySSA=false)
Definition: EarlyCSE.cpp:1358
void initializeLoopUnrollAndJamPass(PassRegistry &)
FunctionPass * createScalarizerPass()
Create a legacy pass manager instance of the Scalarizer pass.
Definition: Scalarizer.cpp:296
FunctionPass * createNewGVNPass()
Definition: NewGVN.cpp:4222
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:38
void initializePartiallyInlineLibCallsLegacyPassPass(PassRegistry &)
void initializeMergeICmpsPass(PassRegistry &)
void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM)
See llvm::createCFGSimplificationPass function.
Definition: Scalar.cpp:134
void initializePostInlineEntryExitInstrumenterPass(PassRegistry &)
void initializeMergedLoadStoreMotionLegacyPassPass(PassRegistry &)
void LLVMAddGVNHoistLegacyPass(LLVMPassManagerRef PM)
Definition: Scalar.cpp:267
void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM)
See llvm::createMemCpyOptPass function.
Definition: Scalar.cpp:206
void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM)
See llvm::createAggressiveDCEPass function.
Definition: Scalar.cpp:122
void initializeLowerGuardIntrinsicLegacyPassPass(PassRegistry &)
Pass * createLoopRotatePass(int MaxHeaderSize=-1)
Pass * createIndVarSimplifyPass()
FunctionPass * createAggressiveDCEPass()
Definition: ADCE.cpp:733
FunctionPass * createLowerExpectIntrinsicPass()
void initializeDeadInstEliminationPass(PassRegistry &)
void initializeFlattenCFGPassPass(PassRegistry &)