1 //===-- Scalar.cpp --------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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.
13 //===----------------------------------------------------------------------===//
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"
33 /// initializeScalarOptsPasses - Initialize all passes linked into the
34 /// ScalarOpts library.
35 void llvm::initializeScalarOpts(PassRegistry
&Registry
) {
36 initializeADCELegacyPassPass(Registry
);
37 initializeBDCELegacyPassPass(Registry
);
38 initializeAlignmentFromAssumptionsPass(Registry
);
39 initializeCallSiteSplittingLegacyPassPass(Registry
);
40 initializeConstantHoistingLegacyPassPass(Registry
);
41 initializeConstantPropagationPass(Registry
);
42 initializeCorrelatedValuePropagationPass(Registry
);
43 initializeDCELegacyPassPass(Registry
);
44 initializeDeadInstEliminationPass(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 initializeLoopInterchangePass(Registry
);
71 initializeLoopPredicationLegacyPassPass(Registry
);
72 initializeLoopRotateLegacyPassPass(Registry
);
73 initializeLoopStrengthReducePass(Registry
);
74 initializeLoopRerollPass(Registry
);
75 initializeLoopUnrollPass(Registry
);
76 initializeLoopUnrollAndJamPass(Registry
);
77 initializeLoopUnswitchPass(Registry
);
78 initializeWarnMissedTransformationsLegacyPass(Registry
);
79 initializeLoopVersioningLICMPass(Registry
);
80 initializeLoopIdiomRecognizeLegacyPassPass(Registry
);
81 initializeLowerAtomicLegacyPassPass(Registry
);
82 initializeLowerConstantIntrinsicsPass(Registry
);
83 initializeLowerExpectIntrinsicPass(Registry
);
84 initializeLowerGuardIntrinsicLegacyPassPass(Registry
);
85 initializeLowerWidenableConditionLegacyPassPass(Registry
);
86 initializeMemCpyOptLegacyPassPass(Registry
);
87 initializeMergeICmpsLegacyPassPass(Registry
);
88 initializeMergedLoadStoreMotionLegacyPassPass(Registry
);
89 initializeNaryReassociateLegacyPassPass(Registry
);
90 initializePartiallyInlineLibCallsLegacyPassPass(Registry
);
91 initializeReassociateLegacyPassPass(Registry
);
92 initializeRegToMemPass(Registry
);
93 initializeRewriteStatepointsForGCLegacyPassPass(Registry
);
94 initializeSCCPLegacyPassPass(Registry
);
95 initializeSROALegacyPassPass(Registry
);
96 initializeCFGSimplifyPassPass(Registry
);
97 initializeStructurizeCFGPass(Registry
);
98 initializeSimpleLoopUnswitchLegacyPassPass(Registry
);
99 initializeSinkingLegacyPassPass(Registry
);
100 initializeTailCallElimPass(Registry
);
101 initializeSeparateConstOffsetFromGEPPass(Registry
);
102 initializeSpeculativeExecutionLegacyPassPass(Registry
);
103 initializeStraightLineStrengthReducePass(Registry
);
104 initializePlaceBackedgeSafepointsImplPass(Registry
);
105 initializePlaceSafepointsPass(Registry
);
106 initializeFloat2IntLegacyPassPass(Registry
);
107 initializeLoopDistributeLegacyPass(Registry
);
108 initializeLoopLoadEliminationPass(Registry
);
109 initializeLoopSimplifyCFGLegacyPassPass(Registry
);
110 initializeLoopVersioningPassPass(Registry
);
111 initializeEntryExitInstrumenterPass(Registry
);
112 initializePostInlineEntryExitInstrumenterPass(Registry
);
115 void LLVMAddLoopSimplifyCFGPass(LLVMPassManagerRef PM
) {
116 unwrap(PM
)->add(createLoopSimplifyCFGPass());
119 void LLVMInitializeScalarOpts(LLVMPassRegistryRef R
) {
120 initializeScalarOpts(*unwrap(R
));
123 void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM
) {
124 unwrap(PM
)->add(createAggressiveDCEPass());
127 void LLVMAddDCEPass(LLVMPassManagerRef PM
) {
128 unwrap(PM
)->add(createDeadCodeEliminationPass());
131 void LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM
) {
132 unwrap(PM
)->add(createBitTrackingDCEPass());
135 void LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM
) {
136 unwrap(PM
)->add(createAlignmentFromAssumptionsPass());
139 void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM
) {
140 unwrap(PM
)->add(createCFGSimplificationPass(1, false, false, true));
143 void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM
) {
144 unwrap(PM
)->add(createDeadStoreEliminationPass());
147 void LLVMAddScalarizerPass(LLVMPassManagerRef PM
) {
148 unwrap(PM
)->add(createScalarizerPass());
151 void LLVMAddGVNPass(LLVMPassManagerRef PM
) {
152 unwrap(PM
)->add(createGVNPass());
155 void LLVMAddNewGVNPass(LLVMPassManagerRef PM
) {
156 unwrap(PM
)->add(createNewGVNPass());
159 void LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM
) {
160 unwrap(PM
)->add(createMergedLoadStoreMotionPass());
163 void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM
) {
164 unwrap(PM
)->add(createIndVarSimplifyPass());
167 void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM
) {
168 unwrap(PM
)->add(createJumpThreadingPass());
171 void LLVMAddLoopSinkPass(LLVMPassManagerRef PM
) {
172 unwrap(PM
)->add(createLoopSinkPass());
175 void LLVMAddLICMPass(LLVMPassManagerRef PM
) {
176 unwrap(PM
)->add(createLICMPass());
179 void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM
) {
180 unwrap(PM
)->add(createLoopDeletionPass());
183 void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM
) {
184 unwrap(PM
)->add(createLoopIdiomPass());
187 void LLVMAddLoopRotatePass(LLVMPassManagerRef PM
) {
188 unwrap(PM
)->add(createLoopRotatePass());
191 void LLVMAddLoopRerollPass(LLVMPassManagerRef PM
) {
192 unwrap(PM
)->add(createLoopRerollPass());
195 void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM
) {
196 unwrap(PM
)->add(createLoopUnrollPass());
199 void LLVMAddLoopUnrollAndJamPass(LLVMPassManagerRef PM
) {
200 unwrap(PM
)->add(createLoopUnrollAndJamPass());
203 void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM
) {
204 unwrap(PM
)->add(createLoopUnswitchPass());
207 void LLVMAddLowerAtomicPass(LLVMPassManagerRef PM
) {
208 unwrap(PM
)->add(createLowerAtomicPass());
211 void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM
) {
212 unwrap(PM
)->add(createMemCpyOptPass());
215 void LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM
) {
216 unwrap(PM
)->add(createPartiallyInlineLibCallsPass());
219 void LLVMAddReassociatePass(LLVMPassManagerRef PM
) {
220 unwrap(PM
)->add(createReassociatePass());
223 void LLVMAddSCCPPass(LLVMPassManagerRef PM
) {
224 unwrap(PM
)->add(createSCCPPass());
227 void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM
) {
228 unwrap(PM
)->add(createSROAPass());
231 void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM
) {
232 unwrap(PM
)->add(createSROAPass());
235 void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM
,
237 unwrap(PM
)->add(createSROAPass());
240 void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM
) {
241 // NOTE: The simplify-libcalls pass has been removed.
244 void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM
) {
245 unwrap(PM
)->add(createTailCallEliminationPass());
248 void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM
) {
249 unwrap(PM
)->add(createConstantPropagationPass());
252 void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM
) {
253 unwrap(PM
)->add(createDemoteRegisterToMemoryPass());
256 void LLVMAddVerifierPass(LLVMPassManagerRef PM
) {
257 unwrap(PM
)->add(createVerifierPass());
260 void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM
) {
261 unwrap(PM
)->add(createCorrelatedValuePropagationPass());
264 void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM
) {
265 unwrap(PM
)->add(createEarlyCSEPass(false/*=UseMemorySSA*/));
268 void LLVMAddEarlyCSEMemSSAPass(LLVMPassManagerRef PM
) {
269 unwrap(PM
)->add(createEarlyCSEPass(true/*=UseMemorySSA*/));
272 void LLVMAddGVNHoistLegacyPass(LLVMPassManagerRef PM
) {
273 unwrap(PM
)->add(createGVNHoistPass());
276 void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM
) {
277 unwrap(PM
)->add(createTypeBasedAAWrapperPass());
280 void LLVMAddScopedNoAliasAAPass(LLVMPassManagerRef PM
) {
281 unwrap(PM
)->add(createScopedNoAliasAAWrapperPass());
284 void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM
) {
285 unwrap(PM
)->add(createBasicAAWrapperPass());
288 void LLVMAddLowerConstantIntrinsicsPass(LLVMPassManagerRef PM
) {
289 unwrap(PM
)->add(createLowerConstantIntrinsicsPass());
292 void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM
) {
293 unwrap(PM
)->add(createLowerExpectIntrinsicPass());
296 void LLVMAddUnifyFunctionExitNodesPass(LLVMPassManagerRef PM
) {
297 unwrap(PM
)->add(createUnifyFunctionExitNodesPass());