LLVM  6.0.0svn
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"
29 
30 using namespace llvm;
31 
32 /// initializeScalarOptsPasses - Initialize all passes linked into the
33 /// ScalarOpts library.
45  initializeScalarizerPass(Registry);
69  initializeLoopRerollPass(Registry);
70  initializeLoopUnrollPass(Registry);
78  initializeMergeICmpsPass(Registry);
83  initializeRegToMemPass(Registry);
105 }
106 
109 }
110 
112  unwrap(PM)->add(createAggressiveDCEPass());
113 }
114 
116  unwrap(PM)->add(createBitTrackingDCEPass());
117 }
118 
121 }
122 
124  unwrap(PM)->add(createCFGSimplificationPass(1, false, false, true));
125 }
126 
129 }
130 
132  unwrap(PM)->add(createScalarizerPass());
133 }
134 
136  unwrap(PM)->add(createGVNPass());
137 }
138 
140  unwrap(PM)->add(createNewGVNPass());
141 }
142 
145 }
146 
148  unwrap(PM)->add(createIndVarSimplifyPass());
149 }
150 
153 }
154 
156  unwrap(PM)->add(createJumpThreadingPass());
157 }
158 
160  unwrap(PM)->add(createLoopSinkPass());
161 }
162 
164  unwrap(PM)->add(createLICMPass());
165 }
166 
168  unwrap(PM)->add(createLoopDeletionPass());
169 }
170 
172  unwrap(PM)->add(createLoopIdiomPass());
173 }
174 
176  unwrap(PM)->add(createLoopRotatePass());
177 }
178 
180  unwrap(PM)->add(createLoopRerollPass());
181 }
182 
184  unwrap(PM)->add(createLoopSimplifyCFGPass());
185 }
186 
188  unwrap(PM)->add(createLoopUnrollPass());
189 }
190 
192  unwrap(PM)->add(createLoopUnswitchPass());
193 }
194 
196  unwrap(PM)->add(createMemCpyOptPass());
197 }
198 
201 }
202 
204  unwrap(PM)->add(createLowerSwitchPass());
205 }
206 
209 }
210 
212  unwrap(PM)->add(createReassociatePass());
213 }
214 
216  unwrap(PM)->add(createSCCPPass());
217 }
218 
220  unwrap(PM)->add(createSROAPass());
221 }
222 
224  unwrap(PM)->add(createSROAPass());
225 }
226 
228  int Threshold) {
229  unwrap(PM)->add(createSROAPass());
230 }
231 
233  // NOTE: The simplify-libcalls pass has been removed.
234 }
235 
238 }
239 
242 }
243 
246 }
247 
249  unwrap(PM)->add(createVerifierPass());
250 }
251 
254 }
255 
257  unwrap(PM)->add(createEarlyCSEPass(false/*=UseMemorySSA*/));
258 }
259 
261  unwrap(PM)->add(createEarlyCSEPass(true/*=UseMemorySSA*/));
262 }
263 
265  unwrap(PM)->add(createGVNHoistPass());
266 }
267 
270 }
271 
274 }
275 
277  unwrap(PM)->add(createBasicAAWrapperPass());
278 }
279 
282 }
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:2665
void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM)
See llvm::createJumpThreadingPass function.
Definition: Scalar.cpp:155
void initializeLoopUnswitchPass(PassRegistry &)
void LLVMAddGVNPass(LLVMPassManagerRef PM)
See llvm::createGVNPass function.
Definition: Scalar.cpp:135
Pass * createLoopRerollPass()
void initializeBDCELegacyPassPass(PassRegistry &)
void initializeLoopAccessLegacyAnalysisPass(PassRegistry &)
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
FunctionPass * createLowerSwitchPass()
void initializeConstantHoistingLegacyPassPass(PassRegistry &)
void initializeJumpThreadingPass(PassRegistry &)
void LLVMAddLICMPass(LLVMPassManagerRef PM)
See llvm::createLICMPass function.
Definition: Scalar.cpp:163
void initializeDSELegacyPassPass(PassRegistry &)
Pass * createLoopUnrollPass(int OptLevel=2, int Threshold=-1, int Count=-1, int AllowPartial=-1, int Runtime=-1, int UpperBound=-1, int AllowPeeling=-1)
void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM)
See llvm::createSimplifyLibCallsPass function.
Definition: Scalar.cpp:232
void initializeLoopDeletionLegacyPassPass(PassRegistry &)
void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM)
See llvm::createTypeBasedAliasAnalysisPass function.
Definition: Scalar.cpp:268
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:4958
void LLVMAddEarlyCSEMemSSAPass(LLVMPassManagerRef PM)
See llvm::createEarlyCSEPass function.
Definition: Scalar.cpp:260
void LLVMAddReassociatePass(LLVMPassManagerRef PM)
See llvm::createReassociatePass function.
Definition: Scalar.cpp:211
void initializeScalarOpts(PassRegistry &)
Initialize all passes linked into the ScalarOpts library.
Definition: Scalar.cpp:34
void LLVMAddLowerSwitchPass(LLVMPassManagerRef PM)
See llvm::createLowerSwitchPass function.
Definition: Scalar.cpp:203
void initializeLoopStrengthReducePass(PassRegistry &)
void initializePlaceSafepointsPass(PassRegistry &)
void initializeDivRemPairsLegacyPassPass(PassRegistry &)
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
Definition: Types.h:117
void initializeLoopRerollPass(PassRegistry &)
FunctionPass * createGVNHoistPass()
Definition: GVNHoist.cpp:1207
void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM)
See llvm::createConstantPropagationPass function.
Definition: Scalar.cpp:240
FunctionPass * createDemoteRegisterToMemoryPass()
Definition: Reg2Mem.cpp:126
void LLVMAddNewGVNPass(LLVMPassManagerRef PM)
See llvm::createGVNPass function.
Definition: Scalar.cpp:139
void LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM)
See llvm::createPromoteMemoryToRegisterPass function.
Definition: Scalar.cpp:207
void LLVMAddLoopSinkPass(LLVMPassManagerRef PM)
Definition: Scalar.cpp:159
ImmutablePass * createScopedNoAliasAAWrapperPass()
FunctionPass * createAlignmentFromAssumptionsPass()
FunctionPass * createJumpThreadingPass(int Threshold=-1)
void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM)
See llvm::createLoopUnrollPass function.
Definition: Scalar.cpp:187
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:131
void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM)
See llvm::createSROAPass function.
Definition: Scalar.cpp:223
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:195
void initializeSCCPLegacyPassPass(PassRegistry &)
FunctionPass * createConstantPropagationPass()
FunctionPass * createReassociatePass()
void initializeCallSiteSplittingLegacyPassPass(PassRegistry &)
FunctionPass * createSCCPPass()
Definition: SCCP.cpp:1798
void initializeRewriteStatepointsForGCLegacyPassPass(PassRegistry &)
void initializeStraightLineStrengthReducePass(PassRegistry &)
FunctionPass * createPartiallyInlineLibCallsPass()
void LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM)
See llvm::createMergedLoadStoreMotionPass function.
Definition: Scalar.cpp:143
void initializeConstantPropagationPass(PassRegistry &)
void initializeLoopLoadEliminationPass(PassRegistry &)
void initializeLoopIdiomRecognizeLegacyPassPass(PassRegistry &)
void initializeSpeculativeExecutionLegacyPassPass(PassRegistry &)
void initializeLoopUnrollPass(PassRegistry &)
FunctionPass * createInstructionCombiningPass(bool ExpensiveCombines=true)
void LLVMAddScopedNoAliasAAPass(LLVMPassManagerRef PM)
See llvm::createScopedNoAliasAAPass function.
Definition: Scalar.cpp:272
void LLVMAddLoopRerollPass(LLVMPassManagerRef PM)
See llvm::createLoopRerollPass function.
Definition: Scalar.cpp:179
void initializeSeparateConstOffsetFromGEPPass(PassRegistry &)
void initializeGVNLegacyPassPass(PassRegistry &)
void initializeLoopDataPrefetchLegacyPassPass(PassRegistry &)
void initializePlaceBackedgeSafepointsImplPass(PassRegistry &)
void initializeIndVarSimplifyLegacyPassPass(PassRegistry &)
void LLVMAddLoopSimplifyCFGPass(LLVMPassManagerRef PM)
Definition: Scalar.cpp:183
Pass * createCorrelatedValuePropagationPass()
void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM)
See llvm::createDeadStoreEliminationPass function.
Definition: Scalar.cpp:127
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 initializeInductiveRangeCheckEliminationPass(PassRegistry &)
FunctionPass * createPromoteMemoryToRegisterPass()
Definition: Mem2Reg.cpp:114
void LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM)
See llvm::createAlignmentFromAssumptionsPass function.
Definition: Scalar.cpp:119
Pass * createLICMPass()
Definition: LICM.cpp:237
FunctionPass * createDeadStoreEliminationPass()
void initializeLowerAtomicLegacyPassPass(PassRegistry &)
void LLVMAddLoopRotatePass(LLVMPassManagerRef PM)
See llvm::createLoopRotatePass function.
Definition: Scalar.cpp:175
void initializeSROALegacyPassPass(PassRegistry &)
void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM, int Threshold)
See llvm::createSROAPass function.
Definition: Scalar.cpp:227
FunctionPass * createMemCpyOptPass()
The public interface to this file...
FunctionPass * createBitTrackingDCEPass()
Definition: BDCE.cpp:170
void initializeSinkingLegacyPassPass(PassRegistry &)
void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM)
See llvm::createLoopDeletionPass function.
Definition: Scalar.cpp:167
Pass * createLoopSinkPass()
void initializeInferAddressSpacesPass(PassRegistry &)
void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM)
See llvm::createEarlyCSEPass function.
Definition: Scalar.cpp:256
void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM)
See llvm::createSROAPass function.
Definition: Scalar.cpp:219
void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM)
See llvm::createLoopIdiomPass function.
Definition: Scalar.cpp:171
void initializeFloat2IntLegacyPassPass(PassRegistry &)
void LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM)
See llvm::createInstructionCombiningPass function.
Definition: Scalar.cpp:151
void initializeLoopRotateLegacyPassPass(PassRegistry &)
void initializeStructurizeCFGPass(PassRegistry &)
void initializeMemCpyOptLegacyPassPass(PassRegistry &)
void initializeLoopInterchangePass(PassRegistry &)
void initializeRegToMemPass(PassRegistry &)
void initializeLoopVersioningLICMPass(PassRegistry &)
void initializeCorrelatedValuePropagationPass(PassRegistry &)
void LLVMAddSCCPPass(LLVMPassManagerRef PM)
See llvm::createSCCPPass function.
Definition: Scalar.cpp:215
void LLVMInitializeScalarOpts(LLVMPassRegistryRef R)
Definition: Scalar.cpp:107
void LLVMAddVerifierPass(LLVMPassManagerRef PM)
See llvm::createVerifierPass function.
Definition: Scalar.cpp:248
void initializeLoopDistributeLegacyPass(PassRegistry &)
void initializeScalarizerPass(PassRegistry &)
Pass * createLoopSimplifyCFGPass()
FunctionPass * createMergedLoadStoreMotionPass()
createMergedLoadStoreMotionPass - The public interface to this file.
struct LLVMOpaquePassManager * LLVMPassManagerRef
Definition: Types.h:114
void initializeTailCallElimPass(PassRegistry &)
Pass * createLoopDeletionPass()
void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM)
See llvm::demotePromoteMemoryToRegisterPass function.
Definition: Scalar.cpp:244
FunctionPass * createBasicAAWrapperPass()
Pass * createLoopUnswitchPass(bool OptimizeForSize=false, bool hasBranchDivergence=false)
void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM)
See llvm::createBasicAliasAnalysisPass function.
Definition: Scalar.cpp:276
void LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM)
See llvm::createBitTrackingDCEPass function.
Definition: Scalar.cpp:115
void initializeLoopSimplifyCFGLegacyPassPass(PassRegistry &)
Pass * createLoopIdiomPass()
void initializeLoopVersioningPassPass(PassRegistry &)
void initializeGVNHoistLegacyPassPass(PassRegistry &)
void initializeIPSCCPLegacyPassPass(PassRegistry &)
void initializeGVNSinkLegacyPassPass(PassRegistry &)
void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM)
See llvm::createCorrelatedValuePropagationPass function.
Definition: Scalar.cpp:252
void initializeAlignmentFromAssumptionsPass(PassRegistry &)
void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM)
See llvm::createLowerExpectIntrinsicPass function.
Definition: Scalar.cpp:280
FunctionPass * createSROAPass()
Definition: SROA.cpp:4440
void initializeNaryReassociateLegacyPassPass(PassRegistry &)
void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM)
See llvm::createIndVarSimplifyPass function.
Definition: Scalar.cpp:147
void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM)
See llvm::createTailCallEliminationPass function.
Definition: Scalar.cpp:236
ImmutablePass * createTypeBasedAAWrapperPass()
void LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM)
See llvm::createPartiallyInlineLibCallsPass function.
Definition: Scalar.cpp:199
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
void initializeCFGSimplifyPassPass(PassRegistry &)
void initializeLoopPredicationLegacyPassPass(PassRegistry &)
void initializeLegacyLoopSinkPassPass(PassRegistry &)
void initializeReassociateLegacyPassPass(PassRegistry &)
void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM)
See llvm::createLoopUnswitchPass function.
Definition: Scalar.cpp:191
void initializeEarlyCSEMemSSALegacyPassPass(PassRegistry &)
void initializeLegacyLICMPassPass(PassRegistry &)
FunctionPass * createEarlyCSEPass(bool UseMemorySSA=false)
Definition: EarlyCSE.cpp:1170
FunctionPass * createScalarizerPass()
Definition: Scalarizer.cpp:800
FunctionPass * createNewGVNPass()
Definition: NewGVN.cpp:4232
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:123
void initializePostInlineEntryExitInstrumenterPass(PassRegistry &)
void initializeMergedLoadStoreMotionLegacyPassPass(PassRegistry &)
void LLVMAddGVNHoistLegacyPass(LLVMPassManagerRef PM)
Definition: Scalar.cpp:264
void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM)
See llvm::createMemCpyOptPass function.
Definition: Scalar.cpp:195
void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM)
See llvm::createAggressiveDCEPass function.
Definition: Scalar.cpp:111
void initializeLowerGuardIntrinsicLegacyPassPass(PassRegistry &)
Pass * createLoopRotatePass(int MaxHeaderSize=-1)
Pass * createIndVarSimplifyPass()
FunctionPass * createAggressiveDCEPass()
Definition: ADCE.cpp:730
FunctionPass * createLowerExpectIntrinsicPass()
void initializeDeadInstEliminationPass(PassRegistry &)
void initializeFlattenCFGPassPass(PassRegistry &)