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