• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/LegacyPassManager.h"
25 #include "llvm/IR/Verifier.h"
26 #include "llvm/InitializePasses.h"
27 #include "llvm/Transforms/Scalar/GVN.h"
28 #include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h"
29 
30 using namespace llvm;
31 
32 /// initializeScalarOptsPasses - Initialize all passes linked into the
33 /// ScalarOpts library.
initializeScalarOpts(PassRegistry & Registry)34 void llvm::initializeScalarOpts(PassRegistry &Registry) {
35   initializeADCELegacyPassPass(Registry);
36   initializeBDCELegacyPassPass(Registry);
37   initializeAlignmentFromAssumptionsPass(Registry);
38   initializeCallSiteSplittingLegacyPassPass(Registry);
39   initializeConstantHoistingLegacyPassPass(Registry);
40   initializeConstantPropagationPass(Registry);
41   initializeCorrelatedValuePropagationPass(Registry);
42   initializeDCELegacyPassPass(Registry);
43   initializeDeadInstEliminationPass(Registry);
44   initializeDivRemPairsLegacyPassPass(Registry);
45   initializeScalarizerPass(Registry);
46   initializeDSELegacyPassPass(Registry);
47   initializeGuardWideningLegacyPassPass(Registry);
48   initializeLoopGuardWideningLegacyPassPass(Registry);
49   initializeGVNLegacyPassPass(Registry);
50   initializeNewGVNLegacyPassPass(Registry);
51   initializeEarlyCSELegacyPassPass(Registry);
52   initializeEarlyCSEMemSSALegacyPassPass(Registry);
53   initializeGVNHoistLegacyPassPass(Registry);
54   initializeGVNSinkLegacyPassPass(Registry);
55   initializeFlattenCFGPassPass(Registry);
56   initializeIRCELegacyPassPass(Registry);
57   initializeIndVarSimplifyLegacyPassPass(Registry);
58   initializeInferAddressSpacesPass(Registry);
59   initializeInstSimplifyLegacyPassPass(Registry);
60   initializeJumpThreadingPass(Registry);
61   initializeLegacyLICMPassPass(Registry);
62   initializeLegacyLoopSinkPassPass(Registry);
63   initializeLoopDataPrefetchLegacyPassPass(Registry);
64   initializeLoopDeletionLegacyPassPass(Registry);
65   initializeLoopAccessLegacyAnalysisPass(Registry);
66   initializeLoopInstSimplifyLegacyPassPass(Registry);
67   initializeLoopInterchangePass(Registry);
68   initializeLoopPredicationLegacyPassPass(Registry);
69   initializeLoopRotateLegacyPassPass(Registry);
70   initializeLoopStrengthReducePass(Registry);
71   initializeLoopRerollPass(Registry);
72   initializeLoopUnrollPass(Registry);
73   initializeLoopUnrollAndJamPass(Registry);
74   initializeLoopUnswitchPass(Registry);
75   initializeLoopVersioningLICMPass(Registry);
76   initializeLoopIdiomRecognizeLegacyPassPass(Registry);
77   initializeLowerAtomicLegacyPassPass(Registry);
78   initializeLowerExpectIntrinsicPass(Registry);
79   initializeLowerGuardIntrinsicLegacyPassPass(Registry);
80   initializeMemCpyOptLegacyPassPass(Registry);
81   initializeMergeICmpsPass(Registry);
82   initializeMergedLoadStoreMotionLegacyPassPass(Registry);
83   initializeNaryReassociateLegacyPassPass(Registry);
84   initializePartiallyInlineLibCallsLegacyPassPass(Registry);
85   initializeReassociateLegacyPassPass(Registry);
86   initializeRegToMemPass(Registry);
87   initializeRewriteStatepointsForGCLegacyPassPass(Registry);
88   initializeSCCPLegacyPassPass(Registry);
89   initializeSROALegacyPassPass(Registry);
90   initializeCFGSimplifyPassPass(Registry);
91   initializeStructurizeCFGPass(Registry);
92   initializeSimpleLoopUnswitchLegacyPassPass(Registry);
93   initializeSinkingLegacyPassPass(Registry);
94   initializeTailCallElimPass(Registry);
95   initializeSeparateConstOffsetFromGEPPass(Registry);
96   initializeSpeculativeExecutionLegacyPassPass(Registry);
97   initializeStraightLineStrengthReducePass(Registry);
98   initializePlaceBackedgeSafepointsImplPass(Registry);
99   initializePlaceSafepointsPass(Registry);
100   initializeFloat2IntLegacyPassPass(Registry);
101   initializeLoopDistributeLegacyPass(Registry);
102   initializeLoopLoadEliminationPass(Registry);
103   initializeLoopSimplifyCFGLegacyPassPass(Registry);
104   initializeLoopVersioningPassPass(Registry);
105   initializeEntryExitInstrumenterPass(Registry);
106   initializePostInlineEntryExitInstrumenterPass(Registry);
107 }
108 
LLVMAddLoopSimplifyCFGPass(LLVMPassManagerRef PM)109 void LLVMAddLoopSimplifyCFGPass(LLVMPassManagerRef PM) {
110   unwrap(PM)->add(createLoopSimplifyCFGPass());
111 }
112 
LLVMInitializeScalarOpts(LLVMPassRegistryRef R)113 void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) {
114   initializeScalarOpts(*unwrap(R));
115 }
116 
LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM)117 void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) {
118   unwrap(PM)->add(createAggressiveDCEPass());
119 }
120 
LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM)121 void LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM) {
122   unwrap(PM)->add(createBitTrackingDCEPass());
123 }
124 
LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM)125 void LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM) {
126   unwrap(PM)->add(createAlignmentFromAssumptionsPass());
127 }
128 
LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM)129 void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) {
130   unwrap(PM)->add(createCFGSimplificationPass(1, false, false, true));
131 }
132 
LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM)133 void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) {
134   unwrap(PM)->add(createDeadStoreEliminationPass());
135 }
136 
LLVMAddScalarizerPass(LLVMPassManagerRef PM)137 void LLVMAddScalarizerPass(LLVMPassManagerRef PM) {
138   unwrap(PM)->add(createScalarizerPass());
139 }
140 
LLVMAddGVNPass(LLVMPassManagerRef PM)141 void LLVMAddGVNPass(LLVMPassManagerRef PM) {
142   unwrap(PM)->add(createGVNPass());
143 }
144 
LLVMAddNewGVNPass(LLVMPassManagerRef PM)145 void LLVMAddNewGVNPass(LLVMPassManagerRef PM) {
146   unwrap(PM)->add(createNewGVNPass());
147 }
148 
LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM)149 void LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM) {
150   unwrap(PM)->add(createMergedLoadStoreMotionPass());
151 }
152 
LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM)153 void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM) {
154   unwrap(PM)->add(createIndVarSimplifyPass());
155 }
156 
LLVMAddJumpThreadingPass(LLVMPassManagerRef PM)157 void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM) {
158   unwrap(PM)->add(createJumpThreadingPass());
159 }
160 
LLVMAddLoopSinkPass(LLVMPassManagerRef PM)161 void LLVMAddLoopSinkPass(LLVMPassManagerRef PM) {
162   unwrap(PM)->add(createLoopSinkPass());
163 }
164 
LLVMAddLICMPass(LLVMPassManagerRef PM)165 void LLVMAddLICMPass(LLVMPassManagerRef PM) {
166   unwrap(PM)->add(createLICMPass());
167 }
168 
LLVMAddLoopDeletionPass(LLVMPassManagerRef PM)169 void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM) {
170   unwrap(PM)->add(createLoopDeletionPass());
171 }
172 
LLVMAddLoopIdiomPass(LLVMPassManagerRef PM)173 void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM) {
174   unwrap(PM)->add(createLoopIdiomPass());
175 }
176 
LLVMAddLoopRotatePass(LLVMPassManagerRef PM)177 void LLVMAddLoopRotatePass(LLVMPassManagerRef PM) {
178   unwrap(PM)->add(createLoopRotatePass());
179 }
180 
LLVMAddLoopRerollPass(LLVMPassManagerRef PM)181 void LLVMAddLoopRerollPass(LLVMPassManagerRef PM) {
182   unwrap(PM)->add(createLoopRerollPass());
183 }
184 
LLVMAddLoopUnrollPass(LLVMPassManagerRef PM)185 void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM) {
186   unwrap(PM)->add(createLoopUnrollPass());
187 }
188 
LLVMAddLoopUnrollAndJamPass(LLVMPassManagerRef PM)189 void LLVMAddLoopUnrollAndJamPass(LLVMPassManagerRef PM) {
190   unwrap(PM)->add(createLoopUnrollAndJamPass());
191 }
192 
LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM)193 void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM) {
194   unwrap(PM)->add(createLoopUnswitchPass());
195 }
196 
LLVMAddMemCpyOptPass(LLVMPassManagerRef PM)197 void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM) {
198   unwrap(PM)->add(createMemCpyOptPass());
199 }
200 
LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM)201 void LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM) {
202   unwrap(PM)->add(createPartiallyInlineLibCallsPass());
203 }
204 
LLVMAddReassociatePass(LLVMPassManagerRef PM)205 void LLVMAddReassociatePass(LLVMPassManagerRef PM) {
206   unwrap(PM)->add(createReassociatePass());
207 }
208 
LLVMAddSCCPPass(LLVMPassManagerRef PM)209 void LLVMAddSCCPPass(LLVMPassManagerRef PM) {
210   unwrap(PM)->add(createSCCPPass());
211 }
212 
LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM)213 void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM) {
214   unwrap(PM)->add(createSROAPass());
215 }
216 
LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM)217 void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM) {
218   unwrap(PM)->add(createSROAPass());
219 }
220 
LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM,int Threshold)221 void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM,
222                                                   int Threshold) {
223   unwrap(PM)->add(createSROAPass());
224 }
225 
LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM)226 void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM) {
227   // NOTE: The simplify-libcalls pass has been removed.
228 }
229 
LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM)230 void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) {
231   unwrap(PM)->add(createTailCallEliminationPass());
232 }
233 
LLVMAddConstantPropagationPass(LLVMPassManagerRef PM)234 void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM) {
235   unwrap(PM)->add(createConstantPropagationPass());
236 }
237 
LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM)238 void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) {
239   unwrap(PM)->add(createDemoteRegisterToMemoryPass());
240 }
241 
LLVMAddVerifierPass(LLVMPassManagerRef PM)242 void LLVMAddVerifierPass(LLVMPassManagerRef PM) {
243   unwrap(PM)->add(createVerifierPass());
244 }
245 
LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM)246 void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM) {
247   unwrap(PM)->add(createCorrelatedValuePropagationPass());
248 }
249 
LLVMAddEarlyCSEPass(LLVMPassManagerRef PM)250 void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM) {
251   unwrap(PM)->add(createEarlyCSEPass(false/*=UseMemorySSA*/));
252 }
253 
LLVMAddEarlyCSEMemSSAPass(LLVMPassManagerRef PM)254 void LLVMAddEarlyCSEMemSSAPass(LLVMPassManagerRef PM) {
255   unwrap(PM)->add(createEarlyCSEPass(true/*=UseMemorySSA*/));
256 }
257 
LLVMAddGVNHoistLegacyPass(LLVMPassManagerRef PM)258 void LLVMAddGVNHoistLegacyPass(LLVMPassManagerRef PM) {
259   unwrap(PM)->add(createGVNHoistPass());
260 }
261 
LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM)262 void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM) {
263   unwrap(PM)->add(createTypeBasedAAWrapperPass());
264 }
265 
LLVMAddScopedNoAliasAAPass(LLVMPassManagerRef PM)266 void LLVMAddScopedNoAliasAAPass(LLVMPassManagerRef PM) {
267   unwrap(PM)->add(createScopedNoAliasAAWrapperPass());
268 }
269 
LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM)270 void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM) {
271   unwrap(PM)->add(createBasicAAWrapperPass());
272 }
273 
LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM)274 void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM) {
275   unwrap(PM)->add(createLowerExpectIntrinsicPass());
276 }
277