[Alignment] fix dubious min function alignment
[llvm-complete.git] / lib / Transforms / Scalar / Scalar.cpp
blob869cf00e0a89cfdcd2947661a2a2c89c6f451fb2
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.
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"
31 using namespace llvm;
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 initializeLowerExpectIntrinsicPass(Registry);
83 initializeLowerGuardIntrinsicLegacyPassPass(Registry);
84 initializeLowerWidenableConditionLegacyPassPass(Registry);
85 initializeMemCpyOptLegacyPassPass(Registry);
86 initializeMergeICmpsLegacyPassPass(Registry);
87 initializeMergedLoadStoreMotionLegacyPassPass(Registry);
88 initializeNaryReassociateLegacyPassPass(Registry);
89 initializePartiallyInlineLibCallsLegacyPassPass(Registry);
90 initializeReassociateLegacyPassPass(Registry);
91 initializeRegToMemPass(Registry);
92 initializeRewriteStatepointsForGCLegacyPassPass(Registry);
93 initializeSCCPLegacyPassPass(Registry);
94 initializeSROALegacyPassPass(Registry);
95 initializeCFGSimplifyPassPass(Registry);
96 initializeStructurizeCFGPass(Registry);
97 initializeSimpleLoopUnswitchLegacyPassPass(Registry);
98 initializeSinkingLegacyPassPass(Registry);
99 initializeTailCallElimPass(Registry);
100 initializeSeparateConstOffsetFromGEPPass(Registry);
101 initializeSpeculativeExecutionLegacyPassPass(Registry);
102 initializeStraightLineStrengthReducePass(Registry);
103 initializePlaceBackedgeSafepointsImplPass(Registry);
104 initializePlaceSafepointsPass(Registry);
105 initializeFloat2IntLegacyPassPass(Registry);
106 initializeLoopDistributeLegacyPass(Registry);
107 initializeLoopLoadEliminationPass(Registry);
108 initializeLoopSimplifyCFGLegacyPassPass(Registry);
109 initializeLoopVersioningPassPass(Registry);
110 initializeEntryExitInstrumenterPass(Registry);
111 initializePostInlineEntryExitInstrumenterPass(Registry);
114 void LLVMAddLoopSimplifyCFGPass(LLVMPassManagerRef PM) {
115 unwrap(PM)->add(createLoopSimplifyCFGPass());
118 void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) {
119 initializeScalarOpts(*unwrap(R));
122 void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) {
123 unwrap(PM)->add(createAggressiveDCEPass());
126 void LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM) {
127 unwrap(PM)->add(createBitTrackingDCEPass());
130 void LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM) {
131 unwrap(PM)->add(createAlignmentFromAssumptionsPass());
134 void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) {
135 unwrap(PM)->add(createCFGSimplificationPass(1, false, false, true));
138 void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) {
139 unwrap(PM)->add(createDeadStoreEliminationPass());
142 void LLVMAddScalarizerPass(LLVMPassManagerRef PM) {
143 unwrap(PM)->add(createScalarizerPass());
146 void LLVMAddGVNPass(LLVMPassManagerRef PM) {
147 unwrap(PM)->add(createGVNPass());
150 void LLVMAddNewGVNPass(LLVMPassManagerRef PM) {
151 unwrap(PM)->add(createNewGVNPass());
154 void LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM) {
155 unwrap(PM)->add(createMergedLoadStoreMotionPass());
158 void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM) {
159 unwrap(PM)->add(createIndVarSimplifyPass());
162 void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM) {
163 unwrap(PM)->add(createJumpThreadingPass());
166 void LLVMAddLoopSinkPass(LLVMPassManagerRef PM) {
167 unwrap(PM)->add(createLoopSinkPass());
170 void LLVMAddLICMPass(LLVMPassManagerRef PM) {
171 unwrap(PM)->add(createLICMPass());
174 void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM) {
175 unwrap(PM)->add(createLoopDeletionPass());
178 void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM) {
179 unwrap(PM)->add(createLoopIdiomPass());
182 void LLVMAddLoopRotatePass(LLVMPassManagerRef PM) {
183 unwrap(PM)->add(createLoopRotatePass());
186 void LLVMAddLoopRerollPass(LLVMPassManagerRef PM) {
187 unwrap(PM)->add(createLoopRerollPass());
190 void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM) {
191 unwrap(PM)->add(createLoopUnrollPass());
194 void LLVMAddLoopUnrollAndJamPass(LLVMPassManagerRef PM) {
195 unwrap(PM)->add(createLoopUnrollAndJamPass());
198 void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM) {
199 unwrap(PM)->add(createLoopUnswitchPass());
202 void LLVMAddLowerAtomicPass(LLVMPassManagerRef PM) {
203 unwrap(PM)->add(createLowerAtomicPass());
206 void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM) {
207 unwrap(PM)->add(createMemCpyOptPass());
210 void LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM) {
211 unwrap(PM)->add(createPartiallyInlineLibCallsPass());
214 void LLVMAddReassociatePass(LLVMPassManagerRef PM) {
215 unwrap(PM)->add(createReassociatePass());
218 void LLVMAddSCCPPass(LLVMPassManagerRef PM) {
219 unwrap(PM)->add(createSCCPPass());
222 void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM) {
223 unwrap(PM)->add(createSROAPass());
226 void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM) {
227 unwrap(PM)->add(createSROAPass());
230 void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM,
231 int Threshold) {
232 unwrap(PM)->add(createSROAPass());
235 void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM) {
236 // NOTE: The simplify-libcalls pass has been removed.
239 void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) {
240 unwrap(PM)->add(createTailCallEliminationPass());
243 void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM) {
244 unwrap(PM)->add(createConstantPropagationPass());
247 void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) {
248 unwrap(PM)->add(createDemoteRegisterToMemoryPass());
251 void LLVMAddVerifierPass(LLVMPassManagerRef PM) {
252 unwrap(PM)->add(createVerifierPass());
255 void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM) {
256 unwrap(PM)->add(createCorrelatedValuePropagationPass());
259 void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM) {
260 unwrap(PM)->add(createEarlyCSEPass(false/*=UseMemorySSA*/));
263 void LLVMAddEarlyCSEMemSSAPass(LLVMPassManagerRef PM) {
264 unwrap(PM)->add(createEarlyCSEPass(true/*=UseMemorySSA*/));
267 void LLVMAddGVNHoistLegacyPass(LLVMPassManagerRef PM) {
268 unwrap(PM)->add(createGVNHoistPass());
271 void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM) {
272 unwrap(PM)->add(createTypeBasedAAWrapperPass());
275 void LLVMAddScopedNoAliasAAPass(LLVMPassManagerRef PM) {
276 unwrap(PM)->add(createScopedNoAliasAAWrapperPass());
279 void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM) {
280 unwrap(PM)->add(createBasicAAWrapperPass());
283 void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM) {
284 unwrap(PM)->add(createLowerExpectIntrinsicPass());
287 void LLVMAddUnifyFunctionExitNodesPass(LLVMPassManagerRef PM) {
288 unwrap(PM)->add(createUnifyFunctionExitNodesPass());