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