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"
18 #include "llvm-c/Transforms/Scalar.h"
19 #include "llvm/Analysis/Passes.h"
20 #include "llvm/IR/DataLayout.h"
21 #include "llvm/IR/Verifier.h"
22 #include "llvm/InitializePasses.h"
23 #include "llvm/IR/LegacyPassManager.h"
24 
25 using namespace llvm;
26 
27 /// initializeScalarOptsPasses - Initialize all passes linked into the
28 /// ScalarOpts library.
initializeScalarOpts(PassRegistry & Registry)29 void llvm::initializeScalarOpts(PassRegistry &Registry) {
30   initializeADCEPass(Registry);
31   initializeBDCEPass(Registry);
32   initializeAlignmentFromAssumptionsPass(Registry);
33   initializeSampleProfileLoaderPass(Registry);
34   initializeConstantHoistingPass(Registry);
35   initializeConstantPropagationPass(Registry);
36   initializeCorrelatedValuePropagationPass(Registry);
37   initializeDCEPass(Registry);
38   initializeDeadInstEliminationPass(Registry);
39   initializeScalarizerPass(Registry);
40   initializeDSEPass(Registry);
41   initializeGVNPass(Registry);
42   initializeEarlyCSELegacyPassPass(Registry);
43   initializeFlattenCFGPassPass(Registry);
44   initializeInductiveRangeCheckEliminationPass(Registry);
45   initializeIndVarSimplifyPass(Registry);
46   initializeJumpThreadingPass(Registry);
47   initializeLICMPass(Registry);
48   initializeLoopDeletionPass(Registry);
49   initializeLoopAccessAnalysisPass(Registry);
50   initializeLoopInstSimplifyPass(Registry);
51   initializeLoopInterchangePass(Registry);
52   initializeLoopRotatePass(Registry);
53   initializeLoopStrengthReducePass(Registry);
54   initializeLoopRerollPass(Registry);
55   initializeLoopUnrollPass(Registry);
56   initializeLoopUnswitchPass(Registry);
57   initializeLoopIdiomRecognizePass(Registry);
58   initializeLowerAtomicPass(Registry);
59   initializeLowerExpectIntrinsicPass(Registry);
60   initializeMemCpyOptPass(Registry);
61   initializeMergedLoadStoreMotionPass(Registry);
62   initializeNaryReassociatePass(Registry);
63   initializePartiallyInlineLibCallsPass(Registry);
64   initializeReassociatePass(Registry);
65   initializeRegToMemPass(Registry);
66   initializeRewriteStatepointsForGCPass(Registry);
67   initializeSCCPPass(Registry);
68   initializeIPSCCPPass(Registry);
69   initializeSROAPass(Registry);
70   initializeSROA_DTPass(Registry);
71   initializeSROA_SSAUpPass(Registry);
72   initializeCFGSimplifyPassPass(Registry);
73   initializeStructurizeCFGPass(Registry);
74   initializeSinkingPass(Registry);
75   initializeTailCallElimPass(Registry);
76   initializeSeparateConstOffsetFromGEPPass(Registry);
77   initializeStraightLineStrengthReducePass(Registry);
78   initializeLoadCombinePass(Registry);
79   initializePlaceBackedgeSafepointsImplPass(Registry);
80   initializePlaceSafepointsPass(Registry);
81   initializeFloat2IntPass(Registry);
82 }
83 
LLVMInitializeScalarOpts(LLVMPassRegistryRef R)84 void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) {
85   initializeScalarOpts(*unwrap(R));
86 }
87 
LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM)88 void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) {
89   unwrap(PM)->add(createAggressiveDCEPass());
90 }
91 
LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM)92 void LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM) {
93   unwrap(PM)->add(createBitTrackingDCEPass());
94 }
95 
LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM)96 void LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM) {
97   unwrap(PM)->add(createAlignmentFromAssumptionsPass());
98 }
99 
LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM)100 void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) {
101   unwrap(PM)->add(createCFGSimplificationPass());
102 }
103 
LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM)104 void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) {
105   unwrap(PM)->add(createDeadStoreEliminationPass());
106 }
107 
LLVMAddScalarizerPass(LLVMPassManagerRef PM)108 void LLVMAddScalarizerPass(LLVMPassManagerRef PM) {
109   unwrap(PM)->add(createScalarizerPass());
110 }
111 
LLVMAddGVNPass(LLVMPassManagerRef PM)112 void LLVMAddGVNPass(LLVMPassManagerRef PM) {
113   unwrap(PM)->add(createGVNPass());
114 }
115 
LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM)116 void LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM) {
117   unwrap(PM)->add(createMergedLoadStoreMotionPass());
118 }
119 
LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM)120 void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM) {
121   unwrap(PM)->add(createIndVarSimplifyPass());
122 }
123 
LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM)124 void LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM) {
125   unwrap(PM)->add(createInstructionCombiningPass());
126 }
127 
LLVMAddJumpThreadingPass(LLVMPassManagerRef PM)128 void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM) {
129   unwrap(PM)->add(createJumpThreadingPass());
130 }
131 
LLVMAddLICMPass(LLVMPassManagerRef PM)132 void LLVMAddLICMPass(LLVMPassManagerRef PM) {
133   unwrap(PM)->add(createLICMPass());
134 }
135 
LLVMAddLoopDeletionPass(LLVMPassManagerRef PM)136 void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM) {
137   unwrap(PM)->add(createLoopDeletionPass());
138 }
139 
LLVMAddLoopIdiomPass(LLVMPassManagerRef PM)140 void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM) {
141   unwrap(PM)->add(createLoopIdiomPass());
142 }
143 
LLVMAddLoopRotatePass(LLVMPassManagerRef PM)144 void LLVMAddLoopRotatePass(LLVMPassManagerRef PM) {
145   unwrap(PM)->add(createLoopRotatePass());
146 }
147 
LLVMAddLoopRerollPass(LLVMPassManagerRef PM)148 void LLVMAddLoopRerollPass(LLVMPassManagerRef PM) {
149   unwrap(PM)->add(createLoopRerollPass());
150 }
151 
LLVMAddLoopUnrollPass(LLVMPassManagerRef PM)152 void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM) {
153   unwrap(PM)->add(createLoopUnrollPass());
154 }
155 
LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM)156 void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM) {
157   unwrap(PM)->add(createLoopUnswitchPass());
158 }
159 
LLVMAddMemCpyOptPass(LLVMPassManagerRef PM)160 void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM) {
161   unwrap(PM)->add(createMemCpyOptPass());
162 }
163 
LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM)164 void LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM) {
165   unwrap(PM)->add(createPartiallyInlineLibCallsPass());
166 }
167 
LLVMAddLowerSwitchPass(LLVMPassManagerRef PM)168 void LLVMAddLowerSwitchPass(LLVMPassManagerRef PM) {
169   unwrap(PM)->add(createLowerSwitchPass());
170 }
171 
LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM)172 void LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM) {
173   unwrap(PM)->add(createPromoteMemoryToRegisterPass());
174 }
175 
LLVMAddReassociatePass(LLVMPassManagerRef PM)176 void LLVMAddReassociatePass(LLVMPassManagerRef PM) {
177   unwrap(PM)->add(createReassociatePass());
178 }
179 
LLVMAddSCCPPass(LLVMPassManagerRef PM)180 void LLVMAddSCCPPass(LLVMPassManagerRef PM) {
181   unwrap(PM)->add(createSCCPPass());
182 }
183 
LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM)184 void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM) {
185   unwrap(PM)->add(createScalarReplAggregatesPass());
186 }
187 
LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM)188 void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM) {
189   unwrap(PM)->add(createScalarReplAggregatesPass(-1, false));
190 }
191 
LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM,int Threshold)192 void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM,
193                                                   int Threshold) {
194   unwrap(PM)->add(createScalarReplAggregatesPass(Threshold));
195 }
196 
LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM)197 void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM) {
198   // NOTE: The simplify-libcalls pass has been removed.
199 }
200 
LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM)201 void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) {
202   unwrap(PM)->add(createTailCallEliminationPass());
203 }
204 
LLVMAddConstantPropagationPass(LLVMPassManagerRef PM)205 void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM) {
206   unwrap(PM)->add(createConstantPropagationPass());
207 }
208 
LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM)209 void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) {
210   unwrap(PM)->add(createDemoteRegisterToMemoryPass());
211 }
212 
LLVMAddVerifierPass(LLVMPassManagerRef PM)213 void LLVMAddVerifierPass(LLVMPassManagerRef PM) {
214   unwrap(PM)->add(createVerifierPass());
215 }
216 
LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM)217 void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM) {
218   unwrap(PM)->add(createCorrelatedValuePropagationPass());
219 }
220 
LLVMAddEarlyCSEPass(LLVMPassManagerRef PM)221 void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM) {
222   unwrap(PM)->add(createEarlyCSEPass());
223 }
224 
LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM)225 void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM) {
226   unwrap(PM)->add(createTypeBasedAliasAnalysisPass());
227 }
228 
LLVMAddScopedNoAliasAAPass(LLVMPassManagerRef PM)229 void LLVMAddScopedNoAliasAAPass(LLVMPassManagerRef PM) {
230   unwrap(PM)->add(createScopedNoAliasAAPass());
231 }
232 
LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM)233 void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM) {
234   unwrap(PM)->add(createBasicAliasAnalysisPass());
235 }
236 
LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM)237 void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM) {
238   unwrap(PM)->add(createLowerExpectIntrinsicPass());
239 }
240