LLVM  10.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);
92  initializeRegToMemPass(Registry);
100  initializeTailCallElimPass(Registry);
113 }
114 
116  unwrap(PM)->add(createLoopSimplifyCFGPass());
117 }
118 
121 }
122 
124  unwrap(PM)->add(createAggressiveDCEPass());
125 }
126 
129 }
130 
132  unwrap(PM)->add(createBitTrackingDCEPass());
133 }
134 
137 }
138 
140  unwrap(PM)->add(createCFGSimplificationPass(1, false, false, true));
141 }
142 
145 }
146 
148  unwrap(PM)->add(createScalarizerPass());
149 }
150 
152  unwrap(PM)->add(createGVNPass());
153 }
154 
156  unwrap(PM)->add(createNewGVNPass());
157 }
158 
161 }
162 
164  unwrap(PM)->add(createIndVarSimplifyPass());
165 }
166 
168  unwrap(PM)->add(createJumpThreadingPass());
169 }
170 
172  unwrap(PM)->add(createLoopSinkPass());
173 }
174 
176  unwrap(PM)->add(createLICMPass());
177 }
178 
180  unwrap(PM)->add(createLoopDeletionPass());
181 }
182 
184  unwrap(PM)->add(createLoopIdiomPass());
185 }
186 
188  unwrap(PM)->add(createLoopRotatePass());
189 }
190 
192  unwrap(PM)->add(createLoopRerollPass());
193 }
194 
196  unwrap(PM)->add(createLoopUnrollPass());
197 }
198 
201 }
202 
204  unwrap(PM)->add(createLoopUnswitchPass());
205 }
206 
208  unwrap(PM)->add(createLowerAtomicPass());
209 }
210 
212  unwrap(PM)->add(createMemCpyOptPass());
213 }
214 
217 }
218 
220  unwrap(PM)->add(createReassociatePass());
221 }
222 
224  unwrap(PM)->add(createSCCPPass());
225 }
226 
228  unwrap(PM)->add(createSROAPass());
229 }
230 
232  unwrap(PM)->add(createSROAPass());
233 }
234 
236  int Threshold) {
237  unwrap(PM)->add(createSROAPass());
238 }
239 
241  // NOTE: The simplify-libcalls pass has been removed.
242 }
243 
246 }
247 
250 }
251 
254 }
255 
257  unwrap(PM)->add(createVerifierPass());
258 }
259 
262 }
263 
265  unwrap(PM)->add(createEarlyCSEPass(false/*=UseMemorySSA*/));
266 }
267 
269  unwrap(PM)->add(createEarlyCSEPass(true/*=UseMemorySSA*/));
270 }
271 
273  unwrap(PM)->add(createGVNHoistPass());
274 }
275 
278 }
279 
282 }
283 
285  unwrap(PM)->add(createBasicAAWrapperPass());
286 }
287 
290 }
291 
294 }
295 
298 }
void initializeEntryExitInstrumenterPass(PassRegistry &)
void initializeNewGVNLegacyPassPass(PassRegistry &)
void initializeEarlyCSELegacyPassPass(PassRegistry &)
void initializeDCELegacyPassPass(PassRegistry &)
void initializeLoopFuseLegacyPass(PassRegistry &)
void LLVMAddLowerConstantIntrinsicsPass(LLVMPassManagerRef PM)
See llvm::createLowerConstantIntrinsicsPass function.
Definition: Scalar.cpp:288
FunctionPass * createGVNPass(bool NoLoads=false)
Create a legacy GVN pass.
Definition: GVN.cpp:2712
void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM)
See llvm::createJumpThreadingPass function.
Definition: Scalar.cpp:167
void initializeLoopUnswitchPass(PassRegistry &)
void LLVMAddGVNPass(LLVMPassManagerRef PM)
See llvm::createGVNPass function.
Definition: Scalar.cpp:151
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:175
void initializeDSELegacyPassPass(PassRegistry &)
void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM)
See llvm::createSimplifyLibCallsPass function.
Definition: Scalar.cpp:240
void initializeLoopDeletionLegacyPassPass(PassRegistry &)
void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM)
See llvm::createTypeBasedAliasAnalysisPass function.
Definition: Scalar.cpp:276
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:5530
void LLVMAddEarlyCSEMemSSAPass(LLVMPassManagerRef PM)
See llvm::createEarlyCSEPass function.
Definition: Scalar.cpp:268
void LLVMAddReassociatePass(LLVMPassManagerRef PM)
See llvm::createReassociatePass function.
Definition: Scalar.cpp:219
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:1205
void initializeMergeICmpsLegacyPassPass(PassRegistry &)
void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM)
See llvm::createConstantPropagationPass function.
Definition: Scalar.cpp:248
FunctionPass * createDemoteRegisterToMemoryPass()
Definition: Reg2Mem.cpp:126
void LLVMAddNewGVNPass(LLVMPassManagerRef PM)
See llvm::createGVNPass function.
Definition: Scalar.cpp:155
void LLVMAddLoopSinkPass(LLVMPassManagerRef PM)
Definition: Scalar.cpp:171
ImmutablePass * createScopedNoAliasAAWrapperPass()
FunctionPass * createAlignmentFromAssumptionsPass()
FunctionPass * createJumpThreadingPass(int Threshold=-1)
void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM)
See llvm::createLoopUnrollPass function.
Definition: Scalar.cpp:195
void initializeLowerConstantIntrinsicsPass(PassRegistry &)
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 &)
FunctionPass * createMergedLoadStoreMotionPass(bool SplitFooterBB=false)
createMergedLoadStoreMotionPass - The public interface to this file.
void LLVMAddScalarizerPass(LLVMPassManagerRef PM)
See llvm::createScalarizerPass function.
Definition: Scalar.cpp:147
void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM)
See llvm::createSROAPass function.
Definition: Scalar.cpp:231
void initializeScalarizerLegacyPassPass(PassRegistry &)
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:204
void initializeSCCPLegacyPassPass(PassRegistry &)
void LLVMAddUnifyFunctionExitNodesPass(LLVMPassManagerRef PM)
See llvm::createUnifyFunctionExitNodesPass function.
Definition: Scalar.cpp:296
FunctionPass * createConstantPropagationPass()
FunctionPass * createReassociatePass()
void initializeCallSiteSplittingLegacyPassPass(PassRegistry &)
FunctionPass * createSCCPPass()
Definition: SCCP.cpp:1917
void initializeLowerWidenableConditionLegacyPassPass(PassRegistry &)
void initializeRewriteStatepointsForGCLegacyPassPass(PassRegistry &)
void initializeStraightLineStrengthReducePass(PassRegistry &)
FunctionPass * createPartiallyInlineLibCallsPass()
FunctionPass * createDeadCodeEliminationPass()
Definition: DCE.cpp:174
void LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM)
See llvm::createMergedLoadStoreMotionPass function.
Definition: Scalar.cpp:159
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:280
void LLVMAddLoopRerollPass(LLVMPassManagerRef PM)
See llvm::createLoopRerollPass function.
Definition: Scalar.cpp:191
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:115
Pass * createCorrelatedValuePropagationPass()
void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM)
See llvm::createDeadStoreEliminationPass function.
Definition: Scalar.cpp:143
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:135
Pass * createLICMPass()
Definition: LICM.cpp:314
FunctionPass * createDeadStoreEliminationPass()
void initializeLowerAtomicLegacyPassPass(PassRegistry &)
void LLVMAddLoopRotatePass(LLVMPassManagerRef PM)
See llvm::createLoopRotatePass function.
Definition: Scalar.cpp:187
void initializeSROALegacyPassPass(PassRegistry &)
void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM, int Threshold)
See llvm::createSROAPass function.
Definition: Scalar.cpp:235
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:179
Pass * createLoopSinkPass()
void initializeInferAddressSpacesPass(PassRegistry &)
void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM)
See llvm::createEarlyCSEPass function.
Definition: Scalar.cpp:264
void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM)
See llvm::createSROAPass function.
Definition: Scalar.cpp:227
void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM)
See llvm::createLoopIdiomPass function.
Definition: Scalar.cpp:183
void initializeFloat2IntLegacyPassPass(PassRegistry &)
void initializeLoopRotateLegacyPassPass(PassRegistry &)
void initializeStructurizeCFGPass(PassRegistry &)
void initializeMemCpyOptLegacyPassPass(PassRegistry &)
void initializeLoopInterchangePass(PassRegistry &)
void initializeRegToMemPass(PassRegistry &)
void initializeLoopVersioningLICMPass(PassRegistry &)
void LLVMAddDCEPass(LLVMPassManagerRef PM)
See llvm::createDeadCodeEliminationPass function.
Definition: Scalar.cpp:127
void initializeLoopGuardWideningLegacyPassPass(PassRegistry &)
void initializeCorrelatedValuePropagationPass(PassRegistry &)
void LLVMAddSCCPPass(LLVMPassManagerRef PM)
See llvm::createSCCPPass function.
Definition: Scalar.cpp:223
void LLVMInitializeScalarOpts(LLVMPassRegistryRef R)
Definition: Scalar.cpp:119
void LLVMAddVerifierPass(LLVMPassManagerRef PM)
See llvm::createVerifierPass function.
Definition: Scalar.cpp:256
void initializeLoopDistributeLegacyPass(PassRegistry &)
FunctionPass * createLowerConstantIntrinsicsPass()
Pass * createLoopSimplifyCFGPass()
Pass * createLowerAtomicPass()
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:252
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:199
void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM)
See llvm::createBasicAliasAnalysisPass function.
Definition: Scalar.cpp:284
void LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM)
See llvm::createBitTrackingDCEPass function.
Definition: Scalar.cpp:131
void initializeLoopSimplifyCFGLegacyPassPass(PassRegistry &)
Pass * createLoopIdiomPass()
void initializeLoopVersioningPassPass(PassRegistry &)
void initializeInstSimplifyLegacyPassPass(PassRegistry &)
void LLVMAddLowerAtomicPass(LLVMPassManagerRef PM)
See llvm::createLowerAtomicPass function.
Definition: Scalar.cpp:207
void initializeGVNHoistLegacyPassPass(PassRegistry &)
void initializeGVNSinkLegacyPassPass(PassRegistry &)
void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM)
See llvm::createCorrelatedValuePropagationPass function.
Definition: Scalar.cpp:260
void initializeAlignmentFromAssumptionsPass(PassRegistry &)
void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM)
See llvm::createLowerExpectIntrinsicPass function.
Definition: Scalar.cpp:292
FunctionPass * createSROAPass()
Definition: SROA.cpp:4651
void initializeNaryReassociateLegacyPassPass(PassRegistry &)
void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM)
See llvm::createIndVarSimplifyPass function.
Definition: Scalar.cpp:163
void initializeWarnMissedTransformationsLegacyPass(PassRegistry &)
void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM)
See llvm::createTailCallEliminationPass function.
Definition: Scalar.cpp:244
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:215
void initializeCFGSimplifyPassPass(PassRegistry &)
void initializeLoopPredicationLegacyPassPass(PassRegistry &)
void initializeLegacyLoopSinkPassPass(PassRegistry &)
void initializeReassociateLegacyPassPass(PassRegistry &)
void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM)
See llvm::createLoopUnswitchPass function.
Definition: Scalar.cpp:203
void initializeEarlyCSEMemSSALegacyPassPass(PassRegistry &)
void initializeLegacyLICMPassPass(PassRegistry &)
FunctionPass * createEarlyCSEPass(bool UseMemorySSA=false)
Definition: EarlyCSE.cpp:1411
void initializeLoopUnrollAndJamPass(PassRegistry &)
FunctionPass * createScalarizerPass()
Create a legacy pass manager instance of the Scalarizer pass.
Definition: Scalarizer.cpp:310
FunctionPass * createNewGVNPass()
Definition: NewGVN.cpp:4223
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 LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM)
See llvm::createCFGSimplificationPass function.
Definition: Scalar.cpp:139
void initializePostInlineEntryExitInstrumenterPass(PassRegistry &)
void initializeMergedLoadStoreMotionLegacyPassPass(PassRegistry &)
void LLVMAddGVNHoistLegacyPass(LLVMPassManagerRef PM)
Definition: Scalar.cpp:272
void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM)
See llvm::createMemCpyOptPass function.
Definition: Scalar.cpp:211
void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM)
See llvm::createAggressiveDCEPass function.
Definition: Scalar.cpp:123
void initializeLowerGuardIntrinsicLegacyPassPass(PassRegistry &)
Pass * createLoopRotatePass(int MaxHeaderSize=-1)
Pass * createIndVarSimplifyPass()
FunctionPass * createAggressiveDCEPass()
Definition: ADCE.cpp:738
FunctionPass * createLowerExpectIntrinsicPass()
void initializeDeadInstEliminationPass(PassRegistry &)
void initializeFlattenCFGPassPass(PassRegistry &)